PayUMoney Integration in Swift 5
import PlugNPlay
import CommonCrypto
func continueWithCardPayment() {
let paymentParam = PUMTxnParam()
paymentParam.key = "asdas" // change here for merchant key
paymentParam.merchantid = "123324" // Change merchant id
paymentParam.txnID = "12"
paymentParam.phone = "" // add mobile number here
paymentParam.amount = "20" // change amount here
paymentParam.productInfo = ""
paymentParam.surl = "https://www.payumoney.com/mobileapp/payumoney/success.php"
paymentParam.furl = "https://www.payumoney.com/mobileapp/payumoney/failure.php"
paymentParam.firstname = "Dilip"
paymentParam.email = "" // add here email id
paymentParam.environment = PUMEnvironment.production // Change here for test
paymentParam.udf1 = "udf1"
paymentParam.udf2 = "udf2"
paymentParam.udf3 = "udf3"
paymentParam.udf4 = "udf4"
paymentParam.udf5 = "udf5"
paymentParam.udf6 = ""
paymentParam.udf7 = ""
paymentParam.udf8 = ""
paymentParam.udf9 = ""
paymentParam.udf10 = ""
paymentParam.hashValue = self.getHashForPaymentParams(paymentParam)
// paymentParam.offerKey = ""
// paymentParam.userCredentials = ""
PlugNPlay.presentPaymentViewController(withTxnParams: paymentParam, on: self) { (dict, error, value) in
print(dict as Any, error as Any, value as Any)
print("Error : \(error as Any)")
print(error?.localizedDescription ?? "")
if error == nil {
print("error is nil")
self.paymentStatusFailed(orderID: orderId, paymentStatus: "0")
}else if error != nil {
print("error is nil")
}
}
}
than add this two function of generating hash & SHA512
func sha512(_ str: String) -> String {
let data = str.data(using:.utf8)!
var digest = [UInt8](repeating: 0, count: Int(CC_SHA512_DIGEST_LENGTH))
data.withUnsafeBytes({
_ = CC_SHA512($0, CC_LONG(data.count), &digest)
})
return digest.map({ String(format: "%02hhx", $0) }).joined(separator: "")
}
func getHashForPaymentParams(_ txnParam: PUMTxnParam?) -> String? {
let salt = "40OLIKYEb7"
var hashSequence: String? = nil
if let key = txnParam?.key, let txnID = txnParam?.txnID, let amount = txnParam?.amount, let productInfo = txnParam?.productInfo, let firstname = txnParam?.firstname, let email = txnParam?.email, let udf1 = txnParam?.udf1, let udf2 = txnParam?.udf2, let udf3 = txnParam?.udf3, let udf4 = txnParam?.udf4, let udf5 = txnParam?.udf5, let udf6 = txnParam?.udf6, let udf7 = txnParam?.udf7, let udf8 = txnParam?.udf8, let udf9 = txnParam?.udf9, let udf10 = txnParam?.udf10 {
hashSequence = "\(key)|\(txnID)|\(amount)|\(productInfo)|\(firstname)|\(email)|\(udf1)|\(udf2)|\(udf3)|\(udf4)|\(udf5)|\(udf6)|\(udf7)|\(udf8)|\(udf9)|\(udf10)|\(salt)"
}
let hash = self.sha512(hashSequence!).description.replacingOccurrences(of: "<", with: "").replacingOccurrences(of: ">", with: "").replacingOccurrences(of: " ", with: "")
return hash
}
Comments
Post a Comment