Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何在swift 3中集成支付网关方式_Ios_Iphone_Swift - Fatal编程技术网

Ios 如何在swift 3中集成支付网关方式

Ios 如何在swift 3中集成支付网关方式,ios,iphone,swift,Ios,Iphone,Swift,我目前正在为该应用程序开发一个应用程序,我需要以集成支付门的方式,但不知道如何在我的应用程序中实现payu money,从两天开始,我只是在阅读教程,但仍然没有得到任何解决方案。我对swift是新手,如果有任何帮助,那将非常棒。在 如果你想集成payU,那么你必须建立一个桥来使用SDK 以下是我对Swift 2.3的回答: 您将能够轻松地在swift 3.0中进行转换。 检查这一个,他们在payU money中为Swift和objective c添加了iOS sdk,我希望这对你有帮助。这对我

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

如果你想集成payU,那么你必须建立一个桥来使用SDK

以下是我对Swift 2.3的回答:

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

检查这一个,他们在payU money中为Swift和objective c添加了iOS sdk,我希望这对你有帮助。

这对我有帮助

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

您希望集成哪个支付网关?请向您介绍一些代码和解释。请参考此答案,将iOS中的PayU与Swift集成。Hi-dev我的朋友说使用Stripe框架更好地集成是实现Hi-Sam的更好方法,您可以使用Stripe,与集成相比,Stripe使用起来简单方便。如果您的payu不是强制性的,那么您应该选择条带。如果payu不是强制性的,那么您可以完全按照自己的意愿选择条带。您要求您尝试集成payu money,因此回答了解决方案。payu是我的应用程序的强制性的