Integration

You can integrate with the CheckoutPro mobile SDK in 5 steps:

1.Include the SDK in your app project (Mandatory Step)

The CheckoutPro SDK is offered via npm.

Use below step to include CheckoutPro SDK in your app:

npm install payu-non-seam-less-react --save
react-native link payu-non-seam-less-react 

Next, add the following imports in the class where you need to initiate a payment

import PayUBizSdk from 'payu-non-seam-less-react';

For iOS

Checkoutpro is a dynamic framework. If you are not using 'use_frameworks!', then please add the following line at the end of your podfile.

  $dynamic_framework = ['PayUAssetLibraryKit', 'PayUBizCoreKit', 'PayUCheckoutProBaseKit', 'PayUCheckoutProKit', 'PayUCustomBrowser', 'PayULoggerKit', 'PayUNetworkingKit', 'PayUUPICoreKit', 'Socket.IO-Client-Swift', 'Starscream','PayUParamsKit', 'PayUCrashReporter', 'PayUNetworkReachability']
  pre_install do |installer|
    Pod::Installer::Xcode::TargetValidator.send(:define_method, :verify_no_static_framework_transitive_dependencies) {}
    installer.pod_targets.each do |pod|
      if $dynamic_framework.include?(pod.name)
        def pod.build_type;
        Pod::BuildType.dynamic_framework
      end
    end
  end
end

After updating the podfile, install the pod using below command.

pod install

2. Set up the payment hashes (Mandatory Step)

Detailed document is present here.

3. Build the payment parameters (Mandatory Step)

To initiate a payment, your app will need to send transactional information to the Checkout Pro SDK.

Payment Params:

Refer here for help regarding SI Params.

Additional Params:

Additional params are optional params that can be passed to SDK like udf params, static hashes. More details on static hash generation and passing is mentioned in hash generation section. Below is list of params that can be passed in additional params -

Payment param and additional param can be passed as below:

var payUPaymentParams = {
    key: "Merchant key",
    transactionId: "Transaction Id",
    amount: "Transaction amount",
    productInfo: "product Info",
    firstName: "Customer firstName",
    email: "Customer email",
    phone: "Customer phone",
    ios_surl: "Success Url for iOS",
    ios_furl: "Failure Url for iOS",
    android_surl: "Success Url for Android",
    android_furl: "Failure Url for Android",
    environment: "0 or 1",//<0 for Production/1 for Staging>
    userCredential: "key:CustomerID",
    additionalParam: {
        udf1: "user defined value 1",
        udf2: "user defined value 2",
        udf3: "user defined value 3",
        udf4: "user defined value 4",
        udf5: "user defined value 5",
        payment_related_details_for_mobile_sdk: "payment_related_details_for_mobile_sdk hash",
        vas_for_mobile_sdk: "vas_for_mobile_sdk hash",
        payment: "Payment Hash"
    },
    payUSIParams: {
      isFreeTrial:true,
    	billingAmount:'10',
    	billingInterval:1,
    	paymentStartDate:'2023-04-20',
    	paymentEndDate:'2023-04-30',
    	billingCycle:'daily', //Can be any of 'daily','weekly','yearly','adhoc','once','monthly'
    	remarks:'Test SI transcaction',
    	billingCurrency:'INR'
    }
}

4. Initiate the payment (Mandatory Step)

Initialise and launch the Checkout Pro SDK by calling the following method

var paymentObject = {
    payUPaymentParams: payUPaymentParams,
    // payUCheckoutProConfig is optional
    // Detail can be found in latter section
    payUCheckoutProConfig: payUCheckoutProConfig
}
PayUBizSdk.openCheckoutScreen(paymentObject);

5.Handle the payment completion (Mandatory Step)

To get the callbacks for payment-related statuses create an object of NativeEventEmitter and subscribe to the below events.

import { NativeEventEmitter } from 'react-native';

//Register event emitters here.
componentDidMount() {
    const eventEmitter = new NativeEventEmitter(PayUBizSdk);
    this.paymentSuccess = eventEmitter.addListener('onPaymentSuccess', this.onPaymentSuccess);
    this.paymentFailure = eventEmitter.addListener('onPaymentFailure', this.onPaymentFailure);
    this.paymentCancel = eventEmitter.addListener('onPaymentCancel', this.onPaymentCancel);
    this.error = eventEmitter.addListener('onError', this.onError);
    this.generateHash = eventEmitter.addListener('generateHash', this.generateHash);
}
onPaymentSuccess = (e) => {
    console.log(e.merchantResponse);
    console.log(e.payuResponse);
}
onPaymentFailure = (e) => {
    console.log(e.merchantResponse);
    console.log(e.payuResponse);
}
onPaymentCancel = (e) => {
    console.log('onPaymentCancel isTxnInitiated -' + e);
}
onError = (e) => {
    console.log(e);
}
generateHash = (e) => {
    console.log(e.hashName);
    console.log(e.hashString);
    var hashStringWithoutSalt = e.hashString;
    var hashName = e.hashName;
    // Pass hashStringWithoutSalt to server
    // Server will append salt at the end and generate sha512 hash over it
    var hashValue = "<Set hash here which is fetched from server>";
    var result = { [hashName]: hashValue };
    PayUBizSdk.hashGenerated(result);
}

//Do remember to unregister eventEmitters here
componentWillUnmount() {
    this.paymentSuccess.remove();
    this.paymentFailure.remove();
    this.paymentCancel.remove();
    this.error.remove();
    this.generateHash.remove();
}

Native Changes For Android

Build.gradle

allprojects {
    repositories {
        maven {
            url "https://phonepe.mycloudrepo.io/public/repositories/phonepe-intentsdk-android"
        }
    }
}

AndroidManifest.xml

In order to Autofill OTP on bank pages SDK requires "RECEIVE_SMS" permission so kindly add the same in your AndroidManifest.xml like below.

<uses-permission android:name="android.permission.RECEIVE_SMS" />

Native Changes For iOS

For UPI Intent (Optional Step)

Currently we support only PhonePe and GooglePay via Intent. Add the query schemes in info.plist

<key>LSApplicationQueriesSchemes</key>
<array>
<string>phonepe</string>
<string>tez</string>
<string>paytm</string>
</array>

Distributing your app (App Store / Ad-hoc) (Mandatory Step)

What you get by default is a fat framework that allows you to test your app seamlessly on device as well as simulator. But before archiving your app, you need to remove simulator slices from the framework. Please see the doc which assists in archiving your app with PayUChekoutPro integrated.

Last updated