如何在swift项目中集成PayUMoney iOS SDK [英] How to integrate PayUMoney iOS SDK in swift project

查看:128
本文介绍了如何在swift项目中集成PayUMoney iOS SDK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从PayUMoney网站下载了PayUMoney iOS SDK。我现在无法将SDK与我的swift项目集成。

I've downloaded the PayUMoney iOS SDK from the PayUMoney website. I'm now unable to integrate the SDK with my swift project.

推荐答案

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

This answer is taken from PayU documentation itself, i am answering here just because it took me hours to implement with their documentation.

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

Hi i can guide you with NON seamless integration. https://github.com/payu-intrepos/Documentations/wiki/8.-iOS-SDK-integration#nonseamless

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

In non seamless integration PayU is already providing UI and will handle the card type and all payment process and at the end you will be notified for the status of your transaction with reason if failed and all details.

从此处下载SDK:< a href =https://github.com/payu-intrepos/iOS-SDK-Sample-App/archive/3.8.1.zip\"rel =noreferrer> https://github.com/payu-intrepos/ iOS-SDK-Sample-App / archive / 3.8.1.zip

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

From Sample code copy file from "BusinessLayer" folder.

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

So i hope you have all required files now we can go further with integration.

你正在将PayU与swift集成,因为那里PayU团队不存在快速SDK,我们必须继续使用Objective-C。
你可以在这里找到:如何从Swift调用Objective-C代码

You are integrating PayU with swift, as there is no swift SDK is not present from PayU team we have to proceed with Briding to Objective-C . You can find about this here:How to call Objective-C code from Swift

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

Once header file is created and configured in build setting, import the following Headers of SDK

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

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

Now we are ready to use PayU SDK into our environment/project.

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

Create new instance of 3 main object used for payment 1)Payment parameters 2)Hash Values 2)Helperclass// to calculate hash value

将其粘贴到viewDidLoad()上方

paste this above your viewDidLoad()

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

这是我为进一步处理而创建的函数

Here is function i have created for further processing

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)")
            }
        }
    }

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

There are some My custom function that will through error at your side you copy paste, i am mentioning them here. Do take care of them

1)loadVC(PUUIMainStoryBoard,strVCId:VC_IDENTIFIER_PAYMENT_OPTION)
//我创建的Loadvc函数加载视图控制器,你有在调用视图控制器时更改它

1)loadVC("PUUIMainStoryBoard", strVCId: VC_IDENTIFIER_PAYMENT_OPTION) //Loadvc function i have created to load view controller, you have to change it as you call your view controller

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

2)runOnMainThread({ // This function is for running code on main thread.

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

I have used all test credentials provided by PayU team you can find more in their doc :https://www.payumoney.com/pdf/PayUMoney-Technical-Integration-Document.pdf

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

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

//With this line we are adding notification sent by payment gateway to notify us regarding the status of the payment process, lets cash the notification.

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

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

You will get the response in notify.object. You can find more sophisticated language and way at their document:https://github.com/payu-intrepos/Documentations/wiki/8.-iOS-SDK-integration.

希望这个答案可能帮助你。

Hope this answer may help you.

这篇关于如何在swift项目中集成PayUMoney iOS SDK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆