PayU Mobile SDK - Ola Money (iOS)
PayU的Ola Money SDK是用于简便、高效和稳定地将Ola Money Postpaid + 钱包集成到您的应用程序中的框架。
Ola Money SDK 框架
PayU提供用于处理与Ola Money付款相关不同功能的SDK。
PayUOlaMoneySDK:它包含所有API、错误代码、请求构建器等。仅使用此SDK,您就可以创建Ola Money的postData。
所需依赖项(通过Cocoapods自动添加)
- PayU Networking:PayUOlaMoneySDK用它来处理网络请求。
- PayU Logger:PayUOlaMoneySDK用它来记录错误和详细信息。
集成
Cocapods集成
在您的Podfile中添加以下行
pod 'PayUIndia-OlaMoney'
手动集成
- 从这里下载框架文件。 https://github.com/payu-intrepos/payu-olamoney-ios/releases
- 链接到您的项目。
创建UPI支付
-
设置环境为测试或生产
PayUOMCore.shared.environment = .production
-
设置记录器级别为详细、错误或禁用
PayUOMCore.shared.logLevel = .verbose
-
设置支付所需的基本支付参数
do { paymentParams = try PayUOMPaymentParams( merchantKey: "smsplus", //Your merchant key for the environment set in step 1 transactionId: String.randomString(length: 10), //Your unique ID for this trasaction amount: "1", //Amount of transaction productInfo: "iPhone", // Description of the product firstName: "Ashish", lastName: "Jain", // First name of the user email: "[email protected]",// Email of the useer phoneNumber: phoneNumberTextField.text ?? "9717063173", // Phone of user //User defined parameters. //You can save additional details with each txn if you need them for your business logic. //You will get these details back in payment response and transaction verify API //Like, you can add SKUs for which payment is made. udf1: "SKU1|SKU2|SKU3", //You can keep all udf fields blank if you do not have any requirement to save txn specific data udf2: "asdf", udf3: "asdf", udf4: "asdf", udf5: "asdf") // Example userCredentials - "merchantKey:user'sUniqueIdentifier" paymentParams?.userCredentials = "smsplus:[email protected]" // Success URL. Not used but required due to mandatory check. paymentParams?.surl = "https://payu.herokuapp.com/ios_success" // Failure URL. Not used but required due to mandatory check. paymentParams?.furl = "https://payu.herokuapp.com/ios_failure" paymentParams?.offerKey = "cardnumber@8370,cardnumbers2@8380,for particular bins@8427,srioffer@8428,cc2@8429" } catch let error { //Helper.showAlert("Could not create post params due to: \(error.localizedDescription)", onController: self) }
-
获取哈希并将其保存到
paymentParams
对象中-
您需要在
paymentParams
中设置hashes
属性。哈希验证API请求来自原始来源而不是来自中间人。属性hashes
的类型为PayUOMHashes
-
PayUHashes
有2个属性。这三个中的每一个都用于不同的API调用。下面定义了这三个属性paymentHash
:这是在PayU端创建交易所必需的。eligibilityHash
:这是checkEligibility API在检查用户是否有资格使用Ola Money时所必需的。
-
在请求SDK发起支付和检查资格之前,您需要提供哈希。必须只在您的服务器上生成哈希,因为它需要一个秘密密钥(也称为盐)。您的应用程序决不应包含盐。
-
请参见[此处文档],在您的服务器上生成哈希。
- 查看第10页和第11页上的
paymentHash
生成公式。 - 查看第36页上的
paymentRelatedDetailsForMobileSDKHash
和validateVPAHash
生成公式。
- 查看第10页和第11页上的
-
生成
paymentRelatedDetailsForMobileSDKHash
和validateVPAHash
的Command和var1值如下参数的哈希值 命令 var1 eligibilityHash
get_eligible_payment_options {"amount":"1","txnid":""+txid+"","mobile_number":"12345678","first_name":"John","bankCode":"OLAM","email":"[email protected]","last_name":"Smith"}
-
-
在设置
paymentParams
中的哈希值后,调用类的以下方法以检查用户是否有资格通过Ola Money(分期付款+钱包)进行支付public func checkEligibility(params: PayUOMPaymentParams, completion:@escaping(_ status: Bool, _ response: PayUOMEligibilityModel?, _ error: Error?) -> Void)
您将在成功参数中获得类型为
PayUOMEligibilityModel
的Result
响应。以下为示例代码PayUOMCore.shared.checkEligibility(params: self.paymentParams!, completion: { [unowned self] status, response, error in DispatchQueue.main.async { self.makePaymentButton.isEnabled = status if (error != nil) { self.elegebilityLabel.text = error?.localizedDescription } else { self.elegebilityLabel.text = response?.msg } } })
-
使用上面接收到的
PayUOMEligibilityModel
对象,您可以在您的结账屏幕上填充相关的选项。 -
检查资格后,我们可以通过方法获取post参数。可以使用自定义浏览器或WKWebView加载URL和PostData。
public func getPostData(params: PayUOMPaymentParams) -> String
-
(可选)使用以下代码通过自定义浏览器加载数据。
let customBrowser = try? PUCBWebVC(postParam: postData, url: PayUOMSecureEndPoint.securePayment.baseURL, merchantKey: "smsplus") customBrowser?.cbWebVCDelegate = self let navVC = UINavigationController(rootViewController: customBrowser!) self.present(navVC, animated: true, completion: nil)