【问题标题】:How to integrate payment gate way in swift 3如何在swift 3中集成支付网关
【发布时间】:2017-05-03 07:09:38
【问题描述】:

我目前正在为那个应用程序做一个应用程序我需要集成支付网关方式但不知道如何在我的应用程序中实现 payu money,从两天开始我只是在阅读教程但仍然没有得到任何解决方案我是 swift 新手,如果有任何帮助,那就太棒了。

【问题讨论】:

标签: ios iphone swift


【解决方案1】:

https://www.payumoney.com/payment-gateway-integration-guide.html 检查这个,他们为 Swift 和目标 c 添加了 iOS sdk in payU money 我希望它对你有帮助。

【讨论】:

    【解决方案2】:

    https://codeload.github.com/payu-intrepos/PayUMoney-IOS-SDK/zip/master有PayU为swift提供的SDK和示例

    如果你想集成payU那么你必须做桥才能使用SDK。

    https://developer.apple.com/library/content/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html

    这是我对 Swift 2.3 的回答:https://stackoverflow.com/a/41256507/3548469

    您将能够轻松地在 swift 3.0 中进行转换。

    【讨论】:

    • 嗨,开发者,我的朋友说使用 Stripe 框架更好地集成,这是更好的实现方式
    • 嗨 Sam,您可以使用 stripe ,与集成相比,stripe 使用起来更简单方便。如果您不是强制性的,那么您应该选择条纹。
    • 如果支付你不是强制性的,那么你可以完全由你自己决定。
    • 你问你尝试过整合支付你的钱,所以回答了解决方案。
    • 支付你是我的应用程序的强制性
    【解决方案3】:

    这对我有帮助

     import UIKit
    
    var merchantKey = "your live merchant key"
    var salt = "your live merchant salt"
    var PayUBaseUrl = "https://secure.payu.in"
    
    class PaymentScreen: UIViewController,UIWebViewDelegate {
    
      @IBOutlet weak var myWebView: UIWebView!
    
      override func viewDidLoad() {
        super.viewDidLoad()
        self.payPayment()
      }
    
      func payPayment() {
    
        var i = arc4random()
    
        let amount = "1"
        let productInfo = "product"
        let firstName = "SampleName"
        let email = "xxx@gmail.com"
        let phone = "9876543210"
        let sUrl = "https://www.google.com"
        let fUrl = "https://www.bing.com"
        let service_provider = "payu_paisa"
    
        let strHash:String = self.sha1(String.localizedStringWithFormat("%d%@", i, NSDate()))
    
        let rangeOfHello = Range(start: strHash.startIndex,
                                 end: strHash.startIndex.advancedBy(20))
        let txnid1 = strHash.substringWithRange(rangeOfHello)
    
        let hashValue = String.localizedStringWithFormat("%@|%@|%@|%@|%@|%@|||||||||||%@",merchantKey,txnid1,amount,productInfo,firstName,email,salt)
    
        let hash=self.sha1(hashValue)
    
        let postStr = "txnid="+txnid1+"&key="+merchantKey+"&amount="+amount+"&productinfo="+productInfo+"&firstname="+firstName+"&email="+email+"&phone="+phone+"&surl="+sUrl+"&furl="+fUrl+"&hash="+hash+"&service_provider="+service_provider
    
        let url = NSURL(string: String.localizedStringWithFormat("%@/_payment", PayUBaseUrl))
    
        print("check my url", url, postStr)
    
        let request = NSMutableURLRequest(URL: url!)
    
        do {
    
          let postLength = String.localizedStringWithFormat("%lu",postStr.characters.count)
            request.HTTPMethod = "POST"
            request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Current-Type")
            request.setValue(postLength, forHTTPHeaderField: "Content-Length")
            request.HTTPBody = postStr.dataUsingEncoding(NSUTF8StringEncoding)
            myWebView.loadRequest(request)
        } catch {
    
        }
    
      }
    
      func webViewDidStartLoad(webView: UIWebView) {
    
      }
    
      func webViewDidFinishLoad(webView: UIWebView) {
    
        let requestURL = self.myWebView.request?.URL
        let requestString:String = (requestURL?.absoluteString)!
    
        if requestString.containsString("https://www.google.com") {
            print("success payment done")
        }
        else if requestString.containsString("https://www.bing.com") {    
            print("payment failure")
        }
      }
    
      func webView(webView: UIWebView, didFailLoadWithError error: NSError?) {
        print("double failure")
      }
    
      func sha1(toEncrypt:String) -> String {
        let data = toEncrypt.dataUsingEncoding(NSUTF8StringEncoding)!
        var digest = [UInt8](count:Int(CC_SHA512_DIGEST_LENGTH), repeatedValue: 0)
        CC_SHA512(data.bytes, CC_LONG(data.length), &digest)
        let hexBytes = digest.map { String(format: "%02x", $0) }
        return hexBytes.joinWithSeparator("")
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2018-08-15
      • 2017-06-10
      • 1970-01-01
      • 1970-01-01
      • 2020-06-22
      • 2017-01-01
      • 2016-04-09
      • 1970-01-01
      • 2020-04-14
      相关资源
      最近更新 更多