Integrate with Android
To integrate React Native Code SDK on Android, follow these steps:
SDK Integration 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](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 similar to the following code snippet:
{
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.
Note: Always 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>,
store_card: <String>, // 0,1 (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
Step 1: Installation
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. |
Updated 3 days ago