rn-ipay88-sdk

react-native ipay88

react-native-i-pay88

Getting started

$ npm install rn-ipay88-sdk --save

Mostly automatic installation

$ react-native link rn-ipay88-sdk

Manual installation

iOS

  1. In XCode, in the project navigator, right click LibrariesAdd Files to [your project's name]
  2. Go to node_modulesreact-native-i-pay88 and add RNIPay88.xcodeproj
  3. In XCode, in the project navigator, select your project. Add libRNIPay88.a to your project's Build PhasesLink Binary With Libraries
  4. Run your project (Cmd+R)<

Android

  1. Open up android/app/src/main/java/[...]/MainApplication.java
  • Add import tech.newtons.rnipay88module.RNIPay88Package; to the imports at the top of the file
  • Add new RNIPay88Package() to the list returned by the getPackages() method
  1. Append the following lines to android/settings.gradle:
    include ':react-native-i-pay88'
    project(':react-native-i-pay88').projectDir = new File(rootProject.projectDir,     '../node_modules/react-native-i-pay88/android')
  2. Insert the following lines inside the dependencies block in android/app/build.gradle:
    compile project(':react-native-i-pay88')

Usage

create data object and use Pay()

import { Pay } from 'rn-ipay88-sdk';
...
const data = {};
data.paymentId = '55';
data.merchantKey = YOUR_MECHANT_KEY;
data.merchantCode = YOUR_MECHANT_CODE;
data.referenceNo = ANY_UUID;
data.amount = AMOUNT;
data.currency = 'MYR';
data.productDescription = PRODUCT_DESCRIPTION;
data.userName = CUSTOMER_NAME;
data.userEmail = CUSTOMER_EMAIL;
data.userContact = CUSTOMER_CONTACT_NUMBER;
data.remark = ANY_EXTRA_REQUIREMENT;
data.utfLang = 'UTF-8';
data.country = YOUR_COUNTRY;
data.backendUrl = YOUR_SERVER_URL;
data.actionType = 'BT';
data.tokenId = '';
data.xfield1 = '';
const errs = Pay(data);
if (Object.keys(errs).length > 0) {
  console.log(errs);
}

add listener to listen iPay88 return state

componentDidMount() {
  if (Platform.OS === 'android') {
    DeviceEventEmitter.addListener('ipay88:success', data => this.onSuccess(data));
    DeviceEventEmitter.addListener('ipay88:failed', data => this.onFailed(data));
    DeviceEventEmitter.addListener('ipay88:canceled', data => this.onCanceled(data));
  }
}

onSuccess = (data) => {
  console.log(data);
};

onCanceled = (data) => {
  console.log(data);
};

onFailed = (data) => {
  console.log(data);
};

Repository

https://github.com/HJ29/react-native-ipay88.git


相关推荐