Integration

Integration with the Native OTP Assist mobile SDK in 4 steps:

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

The Native OTP SDK is offered via CocoaPods. To add the SDK to your app project, include the SDK framework in your podfile.
1
// make sure to add below-mentioned line to use dynamic frameworksuse_frameworks!​
2
// Add this to include our SDK
3
pod 'PayUIndia-NativeOtpAssist'
Copied!
Install dependency using pod installcommand in terminal
Next, add the following imports in the class where you need to initiate a payment
Swift
Objective-C
1
import PayUNativeOtpAssist
Copied!
1
#import <PayUNativeOtpAssist/PayUNativeOtpAssist.h>
Copied!
Test Merchant key/salt for the production environment: ol4Spy/J0ZXw2z9
Test Merchant key/salt for the test environment: gtKFFx/eCwWELxi
Compatibility
Min iOS Version: 11
Please set "Excluded Architectures" to "arm64" in the Build Settings of your project to run in Simulator.
CrashReporter
In order to receive all the crashes related to our SDKs, add the below-mentioned line your AppDelegate's didFinishLaunchingWithOptions.
Swift
Objective-C
1
PayUOtpAssist.start()
Copied!
1
[PayUOtpAssist start];
Copied!

2. Set up the payment hashes (Mandatory Step)

A detailed document is present here.
You need to implement a payment hash.
Every transaction (payment or non-payment) needs a hash by the merchant before sending the transaction details to PayU. This is required for PayU to validate the authenticity of the transaction. This should be done on your server.

Payment Post Data

To initiate a payment, your app will need to send transactional information to the Checkout Pro SDK. To pass this information, build a payment parameter object as
TransactionId can't have a special character and not more than 25 characters.
Swift
Objective-C
1
let paymentParam = PayUPaymentParam(key: <#T##String#>,
2
transactionId: <#T##String#>,
3
amount: <#T##String#>,
4
productInfo: <#T##String#>,
5
firstName: <#T##String#>,
6
email: <#T##String#>,
7
phone: <#T##String#>,
8
surl: <#T##String#>,
9
furl: <#T##String#>,
10
environment: <#T##Environment#> /*.production or .test*/)
11
12
paymentParam.hashes = PayUHashes()
13
paymentParam.hashes?.paymentHash = <#T##SHA512 HashString#>
14
let ccdc = CCDC()
15
ccdc.cardNumber = <#T##String#>
16
ccdc.expiryYear = <#T##String#>
17
ccdc.expiryMonth = <#T##String#>
18
ccdc.cvv = <#T##String#>
19
ccdc.txnS2SFlow = <#T##String#> //"4" for transactions on native otp assist
20
ccdc.nameOnCard = <#T##String#>
21
ccdc.shouldSaveCard = <#T##String#>
22
paymentParam.paymentOption = ccdc
23
paymentParam.userCredential = <#T##String#> // For saving and fetching user’s saved card
Copied!
1
PayUPaymentParam *paymentParam = [[PayUPaymentParam alloc] initWithKey:<#(NSString * _Nonnull)#>
2
transactionId:<#(NSString * _Nonnull)#>
3
amount:<#(NSString * _Nonnull)#>
4
productInfo:<#(NSString * _Nonnull)#>
5
firstName:<#(NSString * _Nonnull)#>
6
email:<#(NSString * _Nonnull)#>
7
phone:<#(NSString * _Nonnull)#>
8
surl:<#(NSString * _Nonnull)#>
9
furl:<#(NSString * _Nonnull)#>
10
environment:<#(enum Environment)#> /*EnvironmentProduction or EnvironmentTest*/];
11
paymentParam.hashes = [PayUHashes new];
12
paymentParam.hashes.paymentHash = <#T##SHA512 HashString#>;
13
CCDC *ccdc = [CCDC new];
14
ccdc.cardNumber = <#T##String#>;
15
ccdc.expiryYear = <#T##String#>;
16
ccdc.expiryMonth = <#T##String#>;
17
ccdc.cvv = <#T##String#>;
18
ccdc.txnS2SFlow = <#T##String#>; //"4" for transactions on native otp assist
19
ccdc.nameOnCard = <#T##String#>;
20
ccdc.shouldSaveCard = <#T##String#>;
21
paymentParam.paymentOption = ccdc;
22
paymentParam.userCredential = <#(NSString)#>; // For saving and fetching use saved
Copied!
Use Core Sdk library to generate payment postdata.
Check here for Payment parameter definitions.

3.Initiate Payment

Initialize the Native OTP Assist SDK by providing the PayUOtpAssistConfig object having postdata and reference to the PayUOtpAssistCallback to listen to the SDK events.
Swift
Objective C
1
PayUOtpAssist.open(
2
parentVC: self,
3
paymentParam: paymentParam,
4
config: <#T##PayUOtpAssistConfig?#>,
5
delegate: self
6
)
Copied!
1
[PayUCheckoutPro openOn:self paymentParam:paymentParam config:<#(PayUOtpAssistConfig * _Nullable)#> delegate:self];
2
Copied!
Initiate payment must be on Main Thread.

Callbacks

List of the callback function provided by PayUOtpAssistDelegate class:
  1. 1.
    func onPaymentSuccess(merchantResponse: String?, payUResponse: String?)- Called when payment succeeds.
  2. 2.
    func onPaymentFailure(merchantResponse: String?, payUResponse: String?)- Called when payment fails.
  3. 3.
    func onError(errorCode: String?, errorMessage: String?)- Called when we got some error where,
    • errorCode : Error Code
    • errorMessage : Error Description
  4. 4.
    func onPaymentCancel(isTxnInitiated: Bool)- called when user cancel the transaction.
  5. 5.
    func shouldHandleFallback(payUAcsRequest: PayUAcsRequest) -> Bool - It's an optional callback, override when you want to handle the Bank page redirection flow. You just need to change the return value to false. You can also open CustomeBrowser in fallback scenarios. Below is the code snippet to open the CustomBrowser.
1
func shouldHandleFallback(payUAcsRequest: PayUAcsRequest) -> Bool {
2
3
if shouldHandleFallback { // Return 'true', when merchant doesn't want to handle fallback scenarios
4
return true
5
}
6
7
// Set the merchantKey and transactionId
8
PUCBConfiguration.getSingletonInstance()?.merchantKey = key
9
PUCBConfiguration.getSingletonInstance()?.transactionId = payUAcsRequest.transactionId ?? ""
10
11
if let issuerUrl = payUAcsRequest.issuerUrl, let issuerPostData = payUAcsRequest.issuerPostData, !issuerUrl.isEmpty {
12
// Set the issuerUrl and issuerPostData to open in WebView
13
PUCBConfiguration.getSingletonInstance()?.paymentPostParam = issuerPostData
14
PUCBConfiguration.getSingletonInstance()?.paymentURL = issuerUrl
15
}
16
else
17
if let acsTemplate = payUAcsRequest.acsTemplate {
18
// Set the acsTemplate to open in WebView
19
PUCBConfiguration.getSingletonInstance()?.htmlData = acsTemplate
20
}
21
22
// Open CB
23
let webVC = try PUCBWebVC(
24
postParam: PUCBConfiguration.getSingletonInstance()?.paymentPostParam ?? "=",
25
url: URL(string: PUCBConfiguration.getSingletonInstance()?.paymentURL ?? "https://www.google.com"),
26
merchantKey: self.key
27
)
28
webVC.cbWebVCDelegate = self
29
self.navigationController?.setNavigationBarHidden(false, animated: false)
30
self.present(webVC, animated: true)
31
} catch let error {
32
self.onError(errorCode: "0", errorMessage: error.localizedDescription)
33
}
34
35
return false
36
}
Copied!
You will get PayUAcsRequest on shouldHandleFallback() callback. whether you will get issuerUrl and issuerPostData or acsTemplate on PayUAcsRequest acsTemplate is the Html string that you need to load to the Webview.
PayUAcsRequest field
Description
issuerUrl
It's the Bank/ACS page Url.
issuerPostData
You need to load issuerUrl to the Webview
along with this issuerPostdata string.
Ex: webView.postUrl(issuerUrl, issuerPostData.toByteArray())
acsTemplate
If issuerUrl is empty, you need to load acsTemplate to the Webview.
Ex: webView.loadData(acsTemplate, "text/html", "UTF-8");

Error codes and their description.

1
- ErrorCode: Description
2
3
- 1001 : No Internet
4
5
- 1002 : Network timeout, please verify with your server.
6
7
- 1003 : Gateway timeout, please verify with your server.
8
9
- 1005 : Something went wrong , please verify with your server.
10
11
- 1006 : Bank page timed out, please verify with your server.
Copied!

Verify the transaction

Once you get the response from SDK, make sure to confirm it with the PayU server. It is recommended to implement the PayU backend verify call from your backend.

Implementation of PayU verify API

Since you already have the txnID (Order ID generated at your end) value for such cases, you simply need to execute the verify_payment API with the necessary input parameters.
The output would return you the transaction status in "status" key and various other parameters also.
1
curl --location --request POST '{{Url}}' \
2
--header 'Content-Type: application/x-www-form-urlencoded' \
3
--data-urlencode 'key={merchantKey}' \
4
--data-urlencode 'command=verify_payment' \
5
--data-urlencode 'hash=c6febddfaaf6986dd8bd982d3769f856ab149e4de92dbad995c8df808ffcfbcb2c227a3fae38b69eb39ad7b6ce4e06e6b12289f70cc500cea5a2cda449c7dcba' \
6
--data-urlencode 'var1=Txn1234'
Copied!
var1:
Parameter
Description
Sample Value
var1
In this parameter, you can put all the txnid(Your transaction ID/order ID) values in a pipe-separated form.
100123|100124|100125
command
This parameter must have the name of the web service.
It must be verify_payment
key
It's the merchant key that PayU provided you.
hash
This parameter must contain the hash value to be calculated at your end. The string used for calculating the hash is mentioned below: sha512(key|command|var1|salt) sha512 is the encryption method used here.
c6febddfaaf6986dd8bd982d3769f856ab149e4de92dbad995c8df808ffcfbcb2c227a3fae38b69eb39ad7b6ce4e06e6b12289f70cc500cea5a2cda449c7dcba
Last modified 2mo ago