首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Swift中集成Paytm支付网关

如何在Swift中集成Paytm支付网关
EN

Stack Overflow用户
提问于 2018-03-07 17:03:34
回答 3查看 5.8K关注 0票数 1

我已经检查了所有的教程,也做了很多关于网关集成的研发。但是没有找到集成paytm支付网关的方法。

代码语言:javascript
复制
func paymentConfiguration()
{
    var orderDict = [AnyHashable: Any]()
    orderDict["MID"] = "WorldP64425807474247"
    orderDict["CHANNEL_ID"] = "WAP"
    orderDict["INDUSTRY_TYPE_ID"] = "Retail"
    orderDict["WEBSITE"] = "worldpressplg"
    orderDict["TXN_AMOUNT"] = "1"
    orderDict["ORDER_ID"] = ViewController.generateOrderID(withPrefix: "")
    orderDict["CALLBACK_URL"] = "https://securegw.paytm.in/theia/paytmCallback?ORDER_ID=<ORDER_ID>"
    orderDict["CHECKSUMHASH"] = "w2QDRMgp1/BNdEnJEAPCIOmNgQvsi+BhpqijfM9KvFfRiPmGSt3Ddzw+oTaGCLneJwxFFq5mqTMwJXdQE2EzK4px2xruDqKZjHupz9yXev4="
    orderDict["REQUEST_TYPE"] = "DEFAULT"
    orderDict["CUST_ID"] = "1234567890"
    var order = PGOrder(params: orderDict)
}



func openPaytmController()
{
    PGServerEnvironment.selectServerDialog(view, completionHandler: {(_ type: ServerType) -> Void in
        var txnController = PGTransactionViewController.initTransaction(forOrder: order)
        if type != eServerTypeNone {
            txnController.serverType = type
            txnController.merchant = mc
            txnController.delegate = self
            self.show(txnController)
        }
    })
}

任何帮助都将不胜感激。提前感谢

EN

回答 3

Stack Overflow用户

发布于 2018-11-27 14:50:53

**

PayTM与swift with detail

的集成

**

##Download paytm sdk## https://github.com/Paytm-Payments/Paytm_iOS_App_Kit确保动态库和systemConfiguration.framwork已添加到“链接的二进制文件和框架”中

将桥接头文件添加到项目中

代码语言:javascript
复制
        #import "PaymentsSDK.h"

您必须为交易目的生成CheckSumHash key - PayTm唯一密钥

传入以下参数生成checkSumHash

代码语言:javascript
复制
 let params:[String: Any] = [
            "CUST_ID”:<Your Customer ID>,  // you have to generate unique customer ID (Generate random string - less than 50 length count )
            "TXN_AMOUNT":"10.00", // sample amount
              “MID": <Your merchant ID>, 
             "ORDER_ID”:<Your Order ID>, // you have to generate unique order ID  (Generate random string - less than 50 length count )
             "INDUSTRY_TYPE_ID":"Retail",   //Staging Environment  
              "CHANNEL_ID":"WAP", //Staging Environment  
              "WEBSITE":"APPSTAGING",  //Staging Environment  - Mobile
             "CALLBACK_URL":"https://securegw-stage.paytm.in/theia/paytmCallback?ORDER_ID=\(<Your Order ID>)” // This should be important one and make sure the correct order ID. 
  ]

在您的服务器中,您必须根据给定的参数和商家密钥(存储在文件中;不要在您的应用程序内部使用) setUp生成CheckSumHash密钥的文件。这应该是您的校验和URL以及上面提到的参数。最后,我们在响应中获得CheckSumHash

要模拟PGTransactionViewCOntroller,必须给出上面提到的参数和checkSumHash (您得到的响应是:步骤3

代码语言:javascript
复制
       let params:[String: Any] = [
            "CUST_ID”:<Your Customer ID>,  // you have to generate unique customer ID (Generate random string - less than 50 length count )
            "TXN_AMOUNT":"10.00", // sample amount
              “MID": <Your merchant ID>, 
             "ORDER_ID”:<Your Order ID>, // you have to generate unique order ID  (Generate random string - less than 50 length count )
             "INDUSTRY_TYPE_ID":"Retail",   //Staging Environment  
              "CHANNEL_ID":"WAP", //Staging Environment  
              "WEBSITE":"APPSTAGING",  //Staging Environment  - Mobile
             "CALLBACK_URL":"https://securegw-stage.paytm.in/theia/paytmCallback?ORDER_ID=\(<Your Order ID>)”  // This should be important one and make sure the correct order ID. ,“CHECKSUMHASH”:<your geenrated CheckSumHash key> // which you got the response of generate CheckSumHash
]

  let order = PGOrder(params: params)

    let txnController = PGTransactionViewController(transactionFor: order)
    txnController?.serverType = eServerTypeStaging
    txnController?.merchant = PGMerchantConfiguration.default()
    txnController?.merchant.checksumGenerationURL = CheckSumGenerationURL
    txnController?.merchant.merchantID = "FlotaS90100524961231"
    txnController?.merchant.checksumValidationURL = CheckSumVerifyURL + orderID
    txnController?.loggingEnabled = true
    txnController?.merchant.website = "APPSTAGING"
    txnController?.merchant.industryID = "Retail"
    txnController?.serverType = eServerTypeStaging
    txnController?.delegate = self

    self.navigationController?.pushViewController(txnController!, animated: true)

PayTM委托处理响应

代码语言:javascript
复制
func didSucceedTransaction(controller: PGTransactionViewController, response: [NSObject : AnyObject]) {
        print(response)
    }

    func didFinishedResponse(_ controller: PGTransactionViewController!, response responseString: String!) {
        print(responseString) // Response will be in string 
         let data = responseString.data(using: .utf8)!
    let obj = JSON(data: data)
    if obj["STATUS"].stringValue != "TXN_SUCCESS" {
       //handle what you want             
    }
     }
    }
    func didFailTransaction(_ controller: PGTransactionViewController!, error: Error!, response: [AnyHashable : Any]!) {
        print(error)

    }

    func didCancelTrasaction(_ controller: PGTransactionViewController!) {
        print("User camcelled the trasaction")
        controller.navigationController?.popViewController(animated: true)
    }

    func errorMisssingParameter(_ controller: PGTransactionViewController!, error: Error!) {
        print(error.localizedDescription)
        controller.navigationController?.popViewController(animated: true)
    }
票数 2
EN

Stack Overflow用户

发布于 2018-03-21 16:03:08

尝试以下代码:

代码语言:javascript
复制
func showController(controller: PGTransactionViewController) {

    if self.navigationController != nil {
        self.navigationController?.pushViewController(controller, animated: true)
    } else {
        self.present(controller, animated: true, completion: nil)
    }
}

func removeController(controller: PGTransactionViewController) {

    if self.navigationController != nil {
        self.navigationController?.popViewController(animated: true)
    } else {
        controller.dismiss(animated: true, completion: nil)
    }
}

//Creat Payment----------------
func creatPayment(CheckSum: String) {

    let mc = PGMerchantConfiguration.default()!
    var orderDict = [String : Any]()
    orderDict["MID"] = "WorldP64425807474247";
    orderDict["ORDER_ID"] = ViewController.generateOrderID(withPrefix: "");
    orderDict["CUST_ID"] = "1234567890";
    orderDict["INDUSTRY_TYPE_ID"] = "Retail";
    orderDict["CHANNEL_ID"] = "WAP";
    orderDict["TXN_AMOUNT"] = self.FINAL_AMOUNT;
    orderDict["WEBSITE"] = "APP_STAGING";
    orderDict["CALLBACK_URL"] = "https://pguat.paytm.com/paytmchecksum/paytmCallback.jsp";
    orderDict["CHECKSUMHASH"] = CheckSum;

    let pgOrder = PGOrder(params: orderDict )
    let transaction = PGTransactionViewController.init(transactionFor: pgOrder)
    transaction!.serverType = eServerTypeStaging
    transaction!.merchant = mc
    transaction!.loggingEnabled = true
    transaction!.delegate = self
    self.showController(controller: transaction!)
}

func didFinishedResponse(_ controller: PGTransactionViewController!, response responseString: String!) {
    print(responseString)
 }

func didCancelTrasaction(_ controller: PGTransactionViewController!) {
    print("CANCELLED")
}

func errorMisssingParameter(_ controller: PGTransactionViewController!, error: Error!) {
    self.removeController(controller: controller)
    print(error)
}

你已经给出了校验和作为硬核,所以当paytm解码你的校验和并与你的参数进行比较时,比较将会失败。所以当你付款时,你需要提供一个新的校验和。

你需要注意的主要事情是,校验和生成和支付设置的给定参数应该是相同的。可以在后台通过paytm提供的校验和生成工具包生成校验和

在成功生成checksumApi时,您应该调用func creatPayment(CheckSum: String),并将校验和提供给函数中的参数

票数 1
EN

Stack Overflow用户

发布于 2020-06-16 22:13:33

Swift 5.0中的遵循以下步骤:-

1:-按照以下步骤在项目中下载并导入库:-

  1. 下载地址:- https://github.com/Paytm-Payments/Paytm_iOS_App_Kit

在XCode中打开项目,然后从“文件”菜单中选择“将文件添加到项目”。

在刚刚解压缩的目录中选择Paytm.framework

确保选中‘根据需要复制项’,然后在项目设置的“生成阶段”选项卡中,单击“将二进制文件与库链接”下的“添加”,添加SystemConfiguration.framework

检查“将二进制文件与库链接”和“嵌入式二进制文件”中是否都添加了PaytmSDK.framework。如果没有,请单击加号图标进行添加。

将PaytmSDK导入到ViewController

代码语言:javascript
复制
 import PaymentSDK

生成ChecksumHash

安全参数,以避免篡改。使用Paytm提供的服务器端校验和实用程序生成。商家必须确保这总是在服务器上生成。可以使用生成校验和哈希的实用程序

在您的付款ViewController上添加代码以执行付款处理

代码语言:javascript
复制
     var txnController = PGTransactionViewController()
     var serv = PGServerEnvironment()
     var params = [String:String]()
     var order_ID:String?
     var cust_ID:String?


   func beginPayment() {
    serv = serv.createStagingEnvironment()
    let type :ServerType = .eServerTypeStaging
    let order = PGOrder(orderID: "", customerID: "", amount: "", eMail: "", mobile: "")
    order.params = ["MID": "rxazcv89315285244163",
        "ORDER_ID": "order1",
        "CUST_ID": "cust123",
        "MOBILE_NO": "7777777777",
        "EMAIL": "username@emailprovider.com",
        "CHANNEL_ID": "WAP",
        "WEBSITE": "WEBSTAGING",
        "TXN_AMOUNT": "100.12",
        "INDUSTRY_TYPE_ID": "Retail",
        "CHECKSUMHASH": "oCDBVF+hvVb68JvzbKI40TOtcxlNjMdixi9FnRSh80Ub7XfjvgNr9NrfrOCPLmt65UhStCkrDnlYkclz1qE0uBMOrmuKLGlybuErulbLYSQ=",
        "CALLBACK_URL": "https://securegw-stage.paytm.in/theia/paytmCallback?ORDER_ID=order1"]
    self.txnController =  self.txnController.initTransaction(for: order) as! PGTransactionViewController
    self.txnController.title = "Paytm Payments"
    self.txnController.setLoggingEnabled(true)
    if(type != ServerType.eServerTypeNone) {
        self.txnController.serverType = type;
    } else {
        return
    }
    self.txnController.merchant = PGMerchantConfiguration.defaultConfiguration()
    self.txnController.delegate = self
    self.navigationController?.pushViewController(self.txnController, animated: true)
 }

更改"CHECKSUMHASH":来自接口的参数中的值

代码语言:javascript
复制
    order.params["CHECKSUMHASH"] = checkSum // API checkSum value

确认‘PGTransactionDelegate’的协议委派以处理错误和成功响应

若要处理支付完成时的成功/错误,请实现PGTransactionDelegate的didFinishedResponse、didCancelTrasaction、errorMisssingParameter方法。下面提供了代码片段:

代码语言:javascript
复制
extension PaymentViewController : PGTransactionDelegate {
//this function triggers when transaction gets finished
func didFinishedResponse(_ controller: PGTransactionViewController, response responseString: String) {
    let msg : String = responseString
    var titlemsg : String = ""
    if let data = responseString.data(using: String.Encoding.utf8) {
        do {
            if let jsonresponse = try JSONSerialization.jsonObject(with: data, options: .mutableContainers) as? [String:Any] , jsonresponse.count > 0{
                titlemsg = jsonresponse["STATUS"] as? String ?? ""
            }
        } catch {
            debugLog("Something went wrong")
        }
    }
    let actionSheetController: UIAlertController = UIAlertController(title: titlemsg , message: msg, preferredStyle: .alert)
    let cancelAction : UIAlertAction = UIAlertAction(title: "OK", style: .cancel) {
        action -> Void in
        controller.navigationController?.popViewController(animated: true)
    }
    actionSheetController.addAction(cancelAction)
    self.present(actionSheetController, animated: true, completion: nil)
}
//this function triggers when transaction gets cancelled
func didCancelTrasaction(_ controller : PGTransactionViewController) {
    controller.navigationController?.popViewController(animated: true)
}
//Called when a required parameter is missing.
func errorMisssingParameter(_ controller : PGTransactionViewController, error : NSError?) {
    controller.navigationController?.popViewController(animated: true)
  }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49147837

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档