Integration
Technical integration of iOS UPI SDK with the app
Cocoapods integration
Add the following lines into your Podfile
Swift Package Manager Integration
You can integrate PayUIndia-UPIKit, PayUIndia-UPICoreKit with your app or SDK in two ways:
Via Xcode - Go to File-> Add Package-> https://github.com/payu-intrepos/payu-upi-ios-sdk
Via Package.Swift - Add below line in Package.swift dependencies
.package(name: "PayUIndia-UPI", url: "https://github.com/payu-intrepos/payu-upi-ios-sdk", from: "6.1.0")
UPICore
You can integrate UPI Collet and UPIIntent with your own UI using UPICore
Cocoapods integration
Add the following lines into your Podfile
Swift Package Manager Integration
You can integrate PayUIndia-UPIKit, PayUIndia-UPICoreKit with your app or SDK in two ways:
Via Xcode - Go to File-> Add Package-> https://github.com/payu-intrepos/payu-upi-ios-sdk
Via Package.Swift - Add below line in Package.swift dependencies
.package(name: "PayUIndia-UPICore", url: "https://github.com/payu-intrepos/payu-upi-ios-sdk", from: "6.1.0")
Make UPI Payments
Set environment to test or production. You can also set debugging level to get logs from the SDK
Set mandatory payment parameters required for the payment, please import PayUParamsKit
Set callbacks to receive actionable events from SDK
paymentCompletion
- You receive the payment response here.backPressed
- If user has not yet initiated the transaction and she presses back button from the UPI payment options page, this callback is triggered. You can dismiss SDK's UI screen here.onEnteringVPA
- For validating the VPA entered by the user, we need to hit PayU's validate VPA api. This api needs hash. In this callback, you will get the vpa entered by the user. Use this value to generate required hash. When the hash is received from your server, send us the updated post params with the new hash.
Fetch hashes and save them in
paymentParams
objectYou need to set
hashes
property inpaymentParams
. Hashes authenticates that API request originates from the original source and not from any Man in the middle. Propertyhashes
is of typePPKHashes
PPKHashes
has 3 properties. Each of these 3 is used for a distinct API call. These 3 properties are defined below:paymentOptionsHash
: This is required to get available upi payment options from which payment can be made.paymentHash
: This is required to create transaction at PayU's end.validateVPAHash
: This is required by validateVPA API in upi collect flow to check if provided VPA is registered with a bank account and is active or not. Not required in intent transactions.
You need to provide first 2 hashes before asking SDK to initiate the payment. Hashes must be generated only on your server as it needs a secret key (also known as salt). Your app must never contain salt.
Please see this documentation to generate hashes on your server.
Command and var1 values for generating
paymentRelatedDetailsForMobileSDKHash
&validateVPAHash
are given belowHash for param
Command
var1
paymentOptionsHash
payment_related_details_for_mobile_sdk
value of
userCredentials
(You have set it inpaymentParams
)validateVPAHash
validateVPA
vpa string of your user
After setting value of hashes in
paymentParams
, call following method of classPayUAPI
to get all available payment options to the you, "Merchant" :You will get a response of type
Result
with the value of typePayUUPIPaymentOptions
in response's success param. Sample code shown belowWith the
PayUUPIPaymentOptions
object received above, you can populate relevant UPI options on your checkout screen. As stated at the beginning of this document, you have three options to make payment 1. Intent 2. UPI Collect 3. Fallback for Google PayInside
intent
key ofPayUUPIPaymentOptions
object, you get array of objects of typePayUSupportedIntentApp
. These are essentially the apps which are supported by the SDK for intent payments. You can now query the SDK for payment options available for the "Current User" based on factors like if Bank/Payment-Service-Provider(PSP) apps are installed on the current user's device or not.Based on your priority and availability of payment options for the current user, you can order the payment options on your checkout page. Note:
canUseGpayOmni
andcanUseGpayCollect
methods give you fallback options of Google Pay intent app which have approx 10% more success rate than general UPI collect payments . This means, if your user does not have Google Pay app installed, you can still show Google Pay option on your checkout and we will display these two fallback options upon Google pay selection by the user. Google Pay omni payment option takes user's phone number for UPI collect payment.If user selects intent app option, you need to create an instance of
PayUIntentPaymentVC
and following data to it.If user selects upi collect option or Google Pay fallback option, you need to create an instance of
PayCollectPaymentVC
by following code convenience methodThen, you should pass following information for payment processing
After the payment is done, you should get the resonse in your payment completion callback defined above
PayUUPICore.shared.paymentCompletion
Add the query schemes in info.plist
Make payment through UPICore:
i) UPI Collect Flow:
Validate vpa with paymentparam, it will give you a callback once it has verified vpa in the completion block.
PayUAPI.validateVPA(withPaymentParams: <PayUPaymentParam>, completion: <(Result<PayUValidateVPAModel, PayUError>) -> ()>)
Begin payment after validating your VPA. Set up PayUPaymentResponseHandler when the payment is successfully initiated and handle the response after the payment is completed.
PayUAPI.getDataForUPICollectPayment(withPaymentParams: <PayUPaymentParam>, completion: <(Result<PayUPureS2SModel, PayUError>) -> ()>)
ii) UPI Intent Flow:
First check which intent app are in current device(Gpay, Paytm, Phonepe). Then initiate payment
a) Gpay Intent Flow:
First get data using below function
PayUAPI.getDataForGpayIntentPayment(withPaymentParams: <PayUPaymentParam>, completion: <(Result<PayUPureS2SModel, PayUError>) -> ()>)
then make payment using below function and wait for response.
PayUThirdPartyManager.makePayment(withApp: <PayUSupportedIntentApp>, withIntentModel: <PayUPureS2SModel>, appSwitchingStatus: <((Bool) -> ())((Bool) -> ())(Bool) -> ()>)
b) Other Intent Flow:
First get data using below function
PayUAPI.getDataForIntentPayment(withPaymentParams: <PayUPaymentParam>, completion: <(Result<PayUPureS2SModel, PayUError>) -> ()>)
then make payment using below function and wait for response.
PayUThirdPartyManager.makePayment(withApp: <PayUSupportedIntentApp>, withIntentModel: <PayUPureS2SModel>, appSwitchingStatus: <((Bool) -> ())((Bool) -> ())(Bool) -> ()>)
You will get Socket model using PayUPersistentStore.getSocketConnectionModel().
Last updated