iOS Integration
To integrate with the CheckoutPro mobile SDK for React Native:
SDK Integration Steps
Step 1: Include the SDK in your app project
CheckoutPro is a dynamic framework. If you are not using 'use_frameworks!', add the following entries at the end of your podfile
:
$dynamic_framework = ['PayUAssetLibraryKit', 'PayUBizCoreKit', 'PayUCheckoutProBaseKit', 'PayUCheckoutProKit', 'PayUCustomBrowser', 'PayULoggerKit', 'PayUNetworkingKit', 'PayUUPICoreKit', 'Socket.IO-Client-Swift', 'Starscream']
$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 the command.
pod install
Step 2: Set up Payment hashes
This step describes how to pass the static and dynamic hashes. For detailed information, refer to Hash Generation.
Pass Static Hashes
To pass static hashes during integration, use the following code snippet:
var payUPaymentParams = {
key: "Merchant key",
...
...
...
additionalParam: {
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"
}
}
Passing dynamic hashes
To pass dynamic hashes, the merchant will receive a call on the generateHash method. In the method parameter, you will receive a dictionary or hashMap, then extract the value of hashString from that. Pass that value to the server to append the Salt at the end and generate the sha512 hash over it. The server gives that hash back to your app, and the app will pass that hash to PayU through a callback mechanism. For passing dynamic hashes during integration, use the following code snippet:
generateHash = (e) => {
console.log(e.hashName);
console.log(e.hashString);
var hashStringWithoutSalt = e.hashString;
var hashName = e.hashName;
var postSalt = e.postSalt; // compulsory for Additional Charges and Split Payment
// Pass hashStringWithoutSalt to server
// Server will append salt at the end and generate sha512 hash over it
// "<create SHA -512 hash of 'hashString+salt+postSalt'>"
var hashValue = "<Set hash here which is fetched from server>";
var result = { [hashName]: hashValue };
PayUBizSdk.hashGenerated(result);
}
Step 3: Build the payment parameters
To initiate a payment, your app needs to send transactional information to the Checkout Pro SDK.
Parameter | Description |
---|---|
Key
|
|
transactionId
|
|
Amount
|
|
productInfo
|
|
firstName
|
|
Email
|
|
Phone
|
|
ios_surl
|
|
ios_furl
|
|
android_surl
|
|
Environment
|
|
User Credential
|
|
additionalCharges | String This parameter is required if merchant want to take additional charge from user, should be string with PG:Amount or IBIBOCode:Amount Sample : CC:10,NB:20,SBIB:15 |
percentageAdditionalCharges | String This parameter is required if merchant want to take percentage of TDR as additional charge from user for this feature dynamicConvFeeMerchant flag must be enable, should be string with PG:Amount or IBIBOCode:Amount Sample : CC:100,NB:50,SBIB:25 |
For details on Standing Instructions parameters, refer to PayU Standing Instruction Parameters.
Additional parameters
The additional parameters (optional) that can be passed to SDK are udf
parameters, static hashes, and other parameters. For more details on Static Hash generation and passing them, refer to Generate Hashes. The following is a list of parameters that can be passed in additional parameters:
Parameter | Description |
---|---|
PayUCheckoutProConstants.CP_UDF1 | String User-defined field, Merchant can store their customer id, etc. |
PayUCheckoutProConstants.CP_UDF2 | String User-defined field, Merchant can store their customer id, etc. |
PayUCheckoutProConstants.CP_UDF3 | String User-defined field, Merchant can store their customer id, etc. |
PayUCheckoutProConstants.CP_UDF4 | String User-defined field, Merchant can store their customer id, etc. |
PayUCheckoutProConstants.CP_UDF5 | String User-defined field, Merchant can store their customer id, etc. |
Static hashes | String The static hashes are specified in this parameter. For more information, refer to the Generate Hash. |
PayUCheckoutProConstants.SODEX_OSOURC_EID | String Sodexo Source ID, Merchant can store it from the third field of the PayU response. |
PaymentParamConstant.walletUrn | String Pass this parameter if closed loop wallet (clw) payment mode is enabled for your account. |
The payment parameters and additional parameters can be passed using the following code snippet:
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",
additionalCharges:"CC:10,NB:20,SBIB:15", //Optional, Only use if want to take addional charges from user
percentageAdditionalCharges:"CC:10,NB:20,SBIB:15", //Optional, Only use if want to take addional charges dynamically from user
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",
walletUrn: "<walletUrn>"
},
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'
}
}
Step 4: Initiate the payment
Initialize and launch the Checkout Pro SDK by calling the following code snippet:
var paymentObject = {
payUPaymentParams: payUPaymentParams,
// payUCheckoutProConfig is optional
// Detail can be found in latter section
payUCheckoutProConfig: payUCheckoutProConfig
}
PayUBizSdk.openCheckoutScreen(paymentObject);
Step 5: Handle the payment completion
To get the callbacks for payment-related statuses, create a NativeEventEmitter object 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;
var postSalt = e.postSalt; // compulsory for Additional Charges and Split Payment
// Pass hashStringWithoutSalt to server
// Server will append salt at the end and generate sha512 hash over it
// "<create SHA -512 hash of 'hashString+salt+postSalt'>"
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();
}
Step 6: Customization (optional)
For UPI Intent
Currently, PayU supports only PhonePe and GooglePay through Intent. Add the query schemes in info.plist
.
<key>LSApplicationQueriesSchemes</key>
<array>
<string>phonepe</string>
<string>tez</string>
<string>paytm</string>
<string>bhim</string>
<string>credpay</string>
</array>
Distributing your app (App Store / Ad-hoc)
What you get by default is a fat framework that allows you to test your app seamlessly on the device and simulator. But before archiving your app, you need to remove simulator slices from the framework. For detailed information on archiving your app with PayUChekoutPro, refer to Releasing the app.
Test the Integration
After the integration is complete, you must test the integration before you go live and start collecting payment. You can start accepting actual payments from your customers once the test is successful.
You can make test payments using one of the payment methods configured at the Checkout.
Testing checklistThings to remember while testing an integration:
- To test the integration make sure that you are making a transaction call to the test endpoint.
- Use your test key and salt for the transaction requests. For more information, refer to Access Test Key and Salt.
- Set the value of the
environment
parameters to1
.
Test cards only for Test environmentThese test cards, UPI, and Wallet credentials must only be used in the sandbox environment. Using these test cards in production environment may cause validation error.
Test credentials for supported payment methods
Following are the payment methods supported in PayU Test mode.
Test credentials for Net Banking
Use the following credentials to test the Net Banking integration:
- user name: payu
- password: payu
- OTP: 123456
Test VPA for UPI
CalloutThe UPI in-app and UPI intent flow is not available in the Test mode.
You can use either of the following VPAs to test your UPI-related integration:
For Testing the UPI Collect flow, Please follow the below steps:-
- Once you enter the VPA click on the verify button and proceed to pay.
- In NPCI page timer will start, Don't "CLICK" on click text. Please wait on the NPCI page.
- The below link opens in the browser Paste the transaction ID at the end of the URL then click on the success/failure simulator page. After that, your app will redirect to your app with the transaction response.
https://pgsim01.payu.in/UPI-test-transaction/confirm/ <Txn_id>
For Android
You can add the below metadata under the application tag in the manifest file to test the UPI Collect flow on test env:-
Ensure to remove the code from the manifest file before going live.
<application>
<meta-data android:name="payu_debug_mode_enabled" android:value="true" /> <!-- set the value to false for production environment -->
<meta-data android:name="payu_web_service_url" android:value="https://test.payu.in" /> <!-- Comment in case of Production -->
<meta-data android:name="payu_post_url" android:value="https://test.payu.in"/> <!-- Comment in case of Production -->
</application>
Test cards for EMI
You can use the following Debit and Credit cards to test EMI integration.
Bank/Card Type | Card Details |
---|---|
Kotak DC EMI |
|
AXIS DC EMI |
|
HDFC CC EMI |
|
ICICI CC EMI |
|
Test wallets
You can use the following wallets and their corresponding credentials to test wallet integration.
Wallet | Mobile Number | OTP |
---|---|---|
PayTM | 7777777777 | 888888 |
PhonePe | Use the Phonepe Pre-Prod app for testing purposes as described in the following PhonePe doc. location: [https://developer.phonepe.com/v1/docs/setting-up-test-account](https://developer.phonepe.com/v1/docs/setting-up-test-account) Download the app and register your mobile number and follow the instructions as described in the above PhonePe docs. | NA |
AmazonPay | You can test using your original Amazon account details. |
Go-live Checklist
Ensure these steps before you deploy the integration in a live environment.
Collect Live Payments
After testing the integration end-to-end, once you are confident that the integration is working as expected, you can switch to live mode to start accepting payments from your customers.
Watch Out!Ensure that you are using the production merchant key and salt generated in the live mode.
Checklist 1: Update Production Key and Salt
To generate the live merchant key and salt:
- Log in to the PayU Dashboard and switch to Live Mode on the menu.
- Navigate to Developers → API Keys tab.
- Copy the key and salt using the copy button.
- Replace the Test key and salt with the Production key and salt in the payment integration code and start accepting actual payments.
Checklist 2: Configure environment() parameter
Set the value of the environment()
to 0
in the payment integration code. This enables the integration to accept live payments.
Checklist 4:- Remove/comment meta -data code from manifest file :-
For Android
You must be comment/remove the below metadata code from the manifest file to use the UPI Collect flow on Production env:-
<application>
<meta-data android:name="payu_debug_mode_enabled" android:value="true" /> // set the value to false for production environment
<meta-data android:name="payu_web_service_url" android:value="https://test.payu.in" /> //Comment in case of Production-->
<meta-data android:name="payu_post_url" android:value="https://test.payu.in"/> //Comment in case of Production-->
</appliction>
Checklist 5: Configure verify payment method
Configure the Verify payment method to fetch the payment status. We strongly recommend that you use this as a back up method to handle scenarios where the payment callback is failed due to technical error.
Checklist 6: Configure Webhook
We recommend that you configure Webhook to receive payment responses on your server. For more information, refer to Webhooks.
Updated 6 days ago