npm.io
1.0.3 • Published 8 years ago

react-native-alipay-ex

Licence
ISC
Version
1.0.3
Deps
0
Size
52.5 MB
Vulns
0
Weekly
0

react-native-alipay-ex

Download

A alipay API for react-native . Works on iOS and Android.

Content

Installation

First step(Download):

Run npm i react-native-alipay-ex --save

Second step(Plugin Installation):
Automatic installation(Use auto or manual)

react-native link react-native-alipay-ex or rnpm link react-native-alipay-ex

Manual installation(Use auto or manual)

Android:

  1. In your android/settings.gradle file, make the following additions:
include ':react-native-alipay-ex'
project(':react-native-alipay-ex').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-alipay-ex/android')
  1. In your android/app/build.gradle file, add the :react-native-alipay-ex project as a compile-time dependency:
...
dependencies {
    ...
    compile project(':react-native-alipay-ex')
}
  1. Update the MainApplication.java file to use react-native-alipay-ex via the following changes:
import com.cd.plugins.alipay.AliPayReactPackage;

public class MainApplication extends Application implements ReactApplication {

    private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
        ...

        @Override
        protected List<ReactPackage> getPackages() {
            return Arrays.<ReactPackage>asList(
                    new MainReactPackage(),
                    new AliPayReactPackage()  //here
            );
        }
    };

    ...
}

iOS:

  1. In XCode, in the project navigator, right click Libraries ➜ Add Files to [your project's name]

  2. Go to node_modules ➜ react-native-alipay-ex and add SplashScreen.xcodeproj

  3. In XCode, in the project navigator, select your project. Add libAliPayEx.a to your project's Build Phases ➜ Link Binary With Libraries

  4. To fix 'SplashScreen.h' file not found, you have to select your project → Build Settings → Search Paths → Header Search Paths to add:

    $(SRCROOT)/../node_modules/react-native-alipay-ex/ios
    recursive

  5. If have this bug, copy AliPayEx/alipay/libs/ALipaySDK.framework to your project, and add it to Linked Frameworks and libraries

"_OBJC_CLASS_$_AlipaySDK", referenced from:
      objc-class-ref in AliPaySDK(AliPayModule.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Third step(Plugin Configuration):

iOS:

Update AppDelegate.m with the following additions:
Ensure enter handleOpenURL callback after alipay finished


#import "AlipayModule.h"  // here

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation {
  
  [AliPayModule handleOpenURL:url];     // here
 
  return YES;
}

// NOTE: 9.0以后使用新API接口
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString*, id> *)options
{

  [AliPayModule handleOpenURL:url];     // here

  return YES;
}

Usage

Use like so:

import AliPay from 'react-native-alipay-ex'

export default class WelcomePage extends Component {
    onPressPay = () => {
        AliPay.pay(res.data, (ret) => {
            if (ret && !ret.code) {
                this.paySucceed()
            } else {
                this.payFailed()
            }
        })
    }
}

API

Method Type Optional Description
pay() function false Alipay (Native Method )

Base alipay config

MIT Licensed

Keywords