react-native-junxiang-2c2p-v9

0.2.0 • Public • Published

react-native-junxiang-2c2p-v9

2c2p library

Usage

Set API test/live URLs in src/Junxiang2c2p.tsx.
Set APIEnvironment.Sandbox or APIEnvironment.Production in android/src/main/Junxiang2c2pV9Module.java or ios/Junxiang2c2pV9.swift for iOS.

To Call Payment Method

import { getPaymentToken } from 'react-native-junxiang-2c2p-v9';
const { Junxiang2c2pV9 } = NativeModules; 

const testPayload = {
  merchantID: merchantID,
  invoiceNo: invoiceNo,
  description: description,
  amount: amount,
  isProduction: false, 
  currencyCode: currencyCode,
  cardNo: cardNo,
  nonceStr: nonceStr,
  expiryMonth: expiryMonth,
  expiryYear: expiryYear,
  securityCode: securityCode,
  securityKey: securityKey,
  paymentChannel: paymentChannel,
  request3DS: request3DS
};

getPaymentToken(testPayload, false).then(async (result:any) => {
  let paymentTokenEncoded = JSON.parse(result).payload;
  let paymentTokenDecoded:any = await decodeJWT(paymentTokenEncoded);
  let paymentParams:any  = JSON.parse(JSON.parse(paymentTokenDecoded).decoded);
  let paymentToken:string = paymentParams.paymentToken;
  let webUrl:string = paymentParams.webPaymentUrl;   

  try {
    const result = await Junxiang2c2pV9.proceed2C2PTransaction(testPayload, paymentToken);
    
    if (result.status === 'redirect') { 
      let urlToOpenInWebview = result.url;
      // open url in webview
    }
    // android returns only url while ios (above) returns json.
    else if (result.startsWith("https://")) {
      let urlToOpenInWebview = result;
      // open url in webview 
    }
  } catch (error) {
    console.error("Payment failed:", error);
  }
});

Package Sidebar

Install

npm i react-native-junxiang-2c2p-v9

Weekly Downloads

122

Version

0.2.0

License

MIT

Unpacked Size

73 kB

Total Files

52

Last publish

Collaborators

  • larisoft