如何快速整合PayU Money

时间:2016-11-30 10:14:21

标签: ios objective-c iphone swift

我是swift的新人可以帮助我快速整合PayU Money .... 我正在使用这个sdk:https://github.com/payu-intrepos/Documentations/wiki/8.1-NEW-iOS-Seamless-SDK-integration

3 个答案:

答案 0 :(得分:2)

这个答案来自PayU文档本身,我在这里回答是因为我花了几个小时来实施他们的文档。

您好我可以指导您进行非无缝集成。 https://github.com/payu-intrepos/Documentations/wiki/8.-iOS-SDK-integration#nonseamless

在非无缝集成中,PayU已经提供了用户界面,并将处理卡片类型和所有付款流程,最后您会收到有关交易状态的通知,如果失败并且有所有详细信息。

从此处下载SDK:https://github.com/payu-intrepos/iOS-SDK-Sample-App/archive/3.8.1.zip

来自“BusinessLayer”文件夹的示例代码复制文件。

所以我希望你现在拥有所有必需的文件,我们可以进一步整合。

您正在将PayU与swift集成,因为PayU团队不存在快速SDK,我们必须继续使用Objective-C。 你可以在这里找到:How to call Objective-C code from Swift

在构建设置中创建并配置头文件后,导入以下SDK标题

#import "PayU_iOS_CoreSDK.h"
#import <CommonCrypto/CommonHMAC.h>
#import "PUUIPaymentOptionVC.h"
#import "PUSAWSManager.h"
#import "PUSAWSManager.h"
#import "PUSAHelperClass.h"

现在我们已准备好将PayU SDK用于我们的环境/项目。

创建用于付款的3个主要对象的新实例 1)付款参数 2)哈希值 2)Helperclass //计算哈希值

将其粘贴到viewDidLoad()

上方
let paymentParam: PayUModelPaymentParams  = PayUModelPaymentParams()
var hashes :PayUModelHashes  = PayUModelHashes()
let PUSAhelper:PUSAHelperClass = PUSAHelperClass()

这是我为进一步处理而创建的功能

func continueWithCardPayment()  {

        paymentParam.key = "gtKFFx"
        paymentParam.transactionID = "umangtxn123"
        paymentParam.amount = "100.0"
        paymentParam.productInfo = "Nokia"
        paymentParam.SURL = "https://google.com/"
        paymentParam.FURL = "https://facebook.com/"
        paymentParam.firstName = "Umang"
        paymentParam.email = "umangarya336@gmail.com"
        paymentParam.environment = ENVIRONMENT_MOBILETEST
        paymentParam.udf1 = "udf1"
        paymentParam.udf2 = "udf2"
        paymentParam.udf3 = "udf3"
        paymentParam.udf4 = "udf4"
        paymentParam.udf5 = "udf5"
        paymentParam.offerKey = ""              // Set this property if you want to give offer:
        paymentParam.userCredentials = ""

        PUSAhelper.generateHashFromServer(self.paymentParam) { (hashes, errorString) in
            self.hashes = hashes
            self.paymentParam.hashes = hashes
            self.callPaymentGateway()
        }
    }

    func callPaymentGateway()  {

        let webServiceResponse :PayUWebServiceResponse = PayUWebServiceResponse()

        webServiceResponse.getPayUPaymentRelatedDetailForMobileSDK(paymentParam) { (paymentDetail, errString, extraParam) in

            if errString == nil {

                let payOptionVC: PUUIPaymentOptionVC = loadVC("PUUIMainStoryBoard", strVCId: VC_IDENTIFIER_PAYMENT_OPTION) as! PUUIPaymentOptionVC

                payOptionVC.paymentParam = self.paymentParam
                payOptionVC.paymentRelatedDetail = paymentDetail

                runOnMainThread({
                    NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(self.paymentResponseReceived(_:)), name: kPUUINotiPaymentResponse, object: nil)
                    self.navigationController?.pushViewController(payOptionVC, animated: true)
                })
            }
            else{
                print("Failed to proceed for payment : \(errString)")
            }
        }
    }

有一些我的自定义功能会在您身边出错时复制粘贴,我在这里提到它们。照顾好他们

1)loadVC(“PUUIMainStoryBoard”,strVCId:VC_IDENTIFIER_PAYMENT_OPTION) //我创建了Loadvc函数来加载视图控制器,你必须在调用视图控制器时更改它

2)runOnMainThread({ //此函数用于在主线程上运行代码。

我已经使用了PayU团队提供的所有测试凭据 您可以在他们的文档中找到更多内容:https://www.payumoney.com/pdf/PayUMoney-Technical-Integration-Document.pdf

NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(self.paymentResponseReceived(_:)), name: kPUUINotiPaymentResponse, object: nil)

//通过此行,我们将添加付款网关发送的通知,以通知我们付款流程的状态,让兑现通知。

func paymentResponseReceived(notify:NSNotification) {
print(notify)
}

您将在notify.object中获得响应。 您可以在其文档中找到更复杂的语言和方式:https://github.com/payu-intrepos/Documentations/wiki/8.-iOS-SDK-integration

希望这个答案可以帮到你。

答案 1 :(得分:0)

这是解决方案将正常工作的源代码,包括所有步骤

首先从此链接下载框架并遵循安装步骤

https://developer.payumoney.com/ios/

完成框架工作的安装步骤后,这里是代码

导入此框架

**

1)导入PlugNPlay  2)导入CommonCrypto

**

添加此函数并在需要的地方调用它,例如按钮或特定事件

func continueWithCardPayment()

    {
             var paymentParam = PUMTxnParam()
            paymentParam.key = "your merhcant key"
            paymentParam.merchantid = " merchant id"
            paymentParam.txnID = "xyz"
            paymentParam.phone = "982412345"
            paymentParam.amount = "500"
            paymentParam.productInfo = "Nokia"
            paymentParam.surl = "https://test.payumoney.com/mobileapp/payumoney/success.php"
            paymentParam.furl = "https://test.payumoney.com/mobileapp/payumoney/failure.php"
            paymentParam.firstname = "john"
            paymentParam.email = "john@john.com"
            paymentParam.environment = PUMEnvironment.test
            paymentParam.udf1 = "udf1"
            paymentParam.udf2 = "udf2"
            paymentParam.udf3 = "udf3"
            paymentParam.udf4 = "udf4"
            paymentParam.udf5 = "udf5"
            paymentParam.udf6 = ""
            paymentParam.udf7 = ""
            paymentParam.udf8 = ""
            paymentParam.udf9 = ""
            paymentParam.udf10 = ""
            paymentParam.hashValue = self.getHashForPaymentParams(paymentParam)
           // paymentParam.offerKey = ""              // Set this property if you want to give offer:
           // paymentParam.userCredentials = ""



                PlugNPlay.presentPaymentViewController(withTxnParams: paymentParam, on: self, withCompletionBlock: { paymentResponse, error, extraParam in
                    if error != nil {
                        UIUtility.toastMessage(onScreen: error?.localizedDescription)
                    } else {
                        var message = ""
                        if paymentResponse?["result"] != nil && (paymentResponse?["result"] is [AnyHashable : Any]) {
                            print(paymentResponse!)
                            message = "Hello Asad sucess"
                            //                    message = paymentResponse?["result"]?["error_Message"] as? String ?? ""
                            //                    if message.isEqual(NSNull()) || message.count == 0 || (message == "No Error") {
                            //                        message = paymentResponse?["result"]?["status"] as? String ?? ""
                            //                    }
                        } else {
                            message = paymentResponse?["status"] as? String ?? ""
                        }
                        UIUtility.toastMessage(onScreen: message)
                    }
                })

            //PlugNPlay.presentPaymentViewController(withTxnParams: paymentParam, on: self, withCompletionBlock: )
        }

没有添加生成哈希和SHA512的这两个功能

func sha512(_ str: String) -> String {

        let data = str.data(using:.utf8)!
        var digest = [UInt8](repeating: 0, count: Int(CC_SHA512_DIGEST_LENGTH))
        data.withUnsafeBytes({
            _ = CC_SHA512($0, CC_LONG(data.count), &digest)
        })
        return digest.map({ String(format: "%02hhx", $0) }).joined(separator: "")
    }
    func getHashForPaymentParams(_ txnParam: PUMTxnParam?) -> String? {
        let salt = "your salt key"
        var hashSequence: String? = nil
        if let key = txnParam?.key, let txnID = txnParam?.txnID, let amount = txnParam?.amount, let productInfo = txnParam?.productInfo, let firstname = txnParam?.firstname, let email = txnParam?.email, let udf1 = txnParam?.udf1, let udf2 = txnParam?.udf2, let udf3 = txnParam?.udf3, let udf4 = txnParam?.udf4, let udf5 = txnParam?.udf5, let udf6 = txnParam?.udf6, let udf7 = txnParam?.udf7, let udf8 = txnParam?.udf8, let udf9 = txnParam?.udf9, let udf10 = txnParam?.udf10 {
            hashSequence = "\(key)|\(txnID)|\(amount)|\(productInfo)|\(firstname)|\(email)|\(udf1)|\(udf2)|\(udf3)|\(udf4)|\(udf5)|\(udf6)|\(udf7)|\(udf8)|\(udf9)|\(udf10)|\(salt)"
        }



        let hash = self.sha512(hashSequence!).description.replacingOccurrences(of: "<", with: "").replacingOccurrences(of: ">", with: "").replacingOccurrences(of: " ", with: "")

        return hash
    }

立即运行代码

答案 2 :(得分:0)

@Asad Ali:-我使用了您的代码,但我只有用信用卡付款的选项。没有显示网上银行选项。我不明白我的代码做错了什么。enter image description here < / p>

我的付款屏幕