-3

I'm currently doing one app for that app I need to integrate payment gate way but don't know how to implement payu money in my app, from two days i'm just reading tutorials but still didn't get any solution I'm new to swift if any help it would be Awesome.

sam
  • 87
  • 1
  • 9

3 Answers3

2

https://www.payumoney.com/payment-gateway-integration-guide.html check this one, they added iOS sdk for Swift and objective c in payU money I hope its helpful for u.

santoshi
  • 380
  • 2
  • 13
1

There is SDK and Example provided by PayU for swift at https://codeload.github.com/payu-intrepos/PayUMoney-IOS-SDK/zip/master

If you want to integrate payU then you have to make bridge to use the SDK.

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

Here is my answer for Swift 2.3, : https://stackoverflow.com/a/41256507/3548469

You will easily able to convert in swift 3.0.

Community
  • 1
  • 1
Devang Tandel
  • 2,988
  • 1
  • 21
  • 43
1

This is helped me

 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("")
  }
}
Anurag Mishra
  • 109
  • 1
  • 9