Integrate with iOS
The React Native Core SDK integration with iOS involves the following steps:
Step 1: Installation
React Native SDK for PayU’s Core PG is offered through Node Package Manager (NPM). Run the following command to install PayU Core PG SDK for React:
npm i payu-core-pg-react
Setup Command
git clone https://github.com/payu-intrepos/payu-core-pg-react.git payuSdkExample
cd payuSdkExample
npm i
cd example
npm i
react-native start
react-native run-android
Step 2: Generate payment hash
Generate the payment hash and pass the hash in the JSON payUPaymentParams.hashes.payment parameter as shown below:
{
payUPaymentParams: {
hashes:{
payment: <String>, // hash for payment sha512(key|txnid|amount|productinfo|firstname|email|udf1|udf2|udf3|udf4|udf5||||||salt)
}
}
}
To learn more about sash generation, see Hash Generation.
RememberAlways generate the hashes on your server. Do not generate the hashes locally in your app, as it will compromise the security of the transactions.
Step 3: Build the payment parameters
To initiate a payment, your app needs to send Transactional Information to the Custom Browser SDK. Build the payUPaymentParams object with the mandatory parameters as shown in the following code snippet:
var payUPaymentParams = {
payUPaymentParams: {
key: <String>, //merchant key
transaction_id: new Date().getTime().toString(),
amount: <String>, // amount in Double format
product_info: <String>,
first_name: <String>,
email: <String>,
phone: <phoneNumber>,
ios_surl: <String>,
ios_furl: <String>,
android_surl: <String>,
android_furl: <String>,
environment: <String>, // "1" for Stage, "0" for production
user_credentials: <String>, // "user:password"
hashes: {
payment: <String>, // generated hash for payment
},
additional_param:{
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",
merchantAccessKey:"", //This is for lookup API, optional
sourceId:"", //Sodexo source ID, optional
},
}
}
}
Build parameters for different payment methods:
Set Net Banking params for payment
To build the mandatory parameters to integrate Net Banking as a payment Method in JSON, use the following code snippet:
var params={
payUPaymentParams: {
bankcode:<String>, // ex: ICIB,AXIB
}
Set Card payment parameters
To build the mandatory parameters to integrate Cards as a payment Method in JSON, use the following code snippet:
var params={
payUPaymentParams: {
bankcode:"CC",
card_number:<String>,
cvv: <String>,
expiry_year: <String>,
expiry_month: <String>,
name_on_card: <String>,
shouldSaveCard: <boolean>, //(true | false)
user_credentials: <String>, // "user:password"
}
Set Wallet payment parameters
To build the mandatory parameters to integrate wallets as a payment Method in JSON, use the following code snippet:
var params={
payUPaymentParams: {
bankcode: <String>, // Payu provide Wallet Id (ex: AMON)
}
Step 4: Make payment
Use the following code snippet to start a payment:
CBWrapper.startPayment(
params,
Payment Mode <String> , // CC(CARD), CASH(WALLET), NB (NET BANKING)
(error) => {
console.log("-----------Error Callback---------");
console.log(error);
console.log("------------------------------------");
},
(payuResponse) => {
console.log("-----------Success Callback---------");
console.log(payuResponse);
console.log("--------------------------------------");
}
);
Step 5: Register listeners
Register event listener (DeviceEventEmitter for this SDK)to capture the response of the transaction from Custom Browser SDK. Use the following code snippet to register the listener:
DeviceEventEmitter.addListener("CBListener",(event)=>{
})
Step 6: Check the response
This is what a sample response from the Custom Browser SDK looks like:
{
"eveneType": <String>, (onPaymentFailure | onPaymentTerminate | onPaymentTerminate | onCBErrorReceived | onBackButton | onBackApprove | onBackDismiss)
"payuResult": <String>, //conditional
"merchantResponse": <String>, //conditional
"errorMessage":<String>,
errorCode: <String>, //conditional
}
Testing and Go-live
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.
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.
Test wallets
You can use the following wallets and their corresponding credentials to test wallet integration.
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 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 about 11 hours ago