shaden alsubaiheen
shaden alsubaiheen

Reputation: 23

iOS and Payfort Integration Issue

I am developing an iOS application where it has a payment service. However, I have faced a problem in payfort integration.

I have been followed the documentation provided in their website.

In page number 21 they mentioned that the token_name is an optional parameter see picture. However, after I have finished the document and run my app I got this error:

Token name does not exist

Here is my code:

let payFort = PayFortController.init(enviroment: KPayFortEnviromentSandBox)

// Set Dictionary contain all keys and values for SDK
let request = NSMutableDictionary.init()
request.setValue("2", forKey: "amount")
request.setValue("PURCHASE", forKey: "command")
request.setValue("SAR", forKey: "currency")
request.setValue("********[email protected]", forKey: "customer_email")
request.setValue("en", forKey: "language")
request.setValue("XYZ92********", forKey: "merchant_reference")
request.setValue("8DEBDC6BBB84354***********" , forKey: "sdk_token")


// Call PayFort and response callback
payFort?.callPayFort(
    withRequest: request, currentViewController: self,
    success: { (requestDic, responeDic) in
        print("success")
    },canceled: { (requestDic, responeDic) in
        print("canceled")
    },
    faild: { (requestDic, responeDic, message) in
        print("faildddd")
    })

payFort?.callPayFort(
    withRequest: request, currentViewController: self,
    success: { (requestDic, responeDic) in
        print("success")
        print("responeDic=\(responeDic)")
        print("responeDic=\(responeDic)")
    },canceled: { (requestDic, responeDic) in
        print("canceled")
        print("requestDic=\(requestDic)")
        print("responeDic=\(responeDic)")
    },
    faild: { (requestDic, responeDic, message) in
        print("faiiild")
        print("requestDic=\(requestDic)")
        print("responeDic=\(responeDic)")
        print("message=\(message)")
    })
payFort!.isShowResponsePage = true
payFort!.hideLoading = true
    

Note: I have tried to add token_name parameter and choose a name randomly but it did not work

Upvotes: 0

Views: 1938

Answers (1)

kartik patel
kartik patel

Reputation: 536

try this

func connectPaymentGateway(token:String){

    let currentTime = Int64(Date().timeIntervalSince1970 * 1000)
    let merchant_reference = "12586" + "_" + String(format: "%0.2d", currentTime)

    let request = NSMutableDictionary.init()
    request.setValue(totalAmount * 100 , forKey: "amount")
    request.setValue("AUTHORIZATION", forKey: "command")
    request.setValue("AED", forKey: "currency")
    request.setValue("[email protected]", forKey: "customer_email")
    request.setValue("en", forKey: "language")
    request.setValue(merchant_reference, forKey: "merchant_reference")
    request.setValue(token , forKey: "sdk_token")
    request.setValue("8A70320AF209" , forKey: "token_name")
    request.setValue("VISA" , forKey: "payment_option")

    OperationQueue.main.addOperation {

        self.payFort?.callPayFort(withRequest: request, currentViewController: self,
                                  success: { (requestDic, responeDic) in

                                    print("success")
                                    print("responeDic=\(String(describing: responeDic))")

                                    let payResponse:PayfortResponse = self.getBookingByResponse(responeDic! as NSDictionary)
                                    print(payResponse)

                                    print(payResponse.response_message as Any)

                                    if payResponse.response_message == "Success" {

                                        print("Payment Success")



                                    }

        },canceled: { (requestDic, responeDic) in
            print("canceled")
            print("responeDic=\(String(describing: responeDic))")
            self.navigationController?.popToRootViewController(animated: true)
        },faild: { (requestDic, responeDic, message) in
            print("faild")
            print("responeDic=\(String(describing: responeDic))")
            print("message=\(String(describing: message))")
            var msgStr = "Please try again later"
            if let msgString = message {
                msgStr = "\(msgString)\n\(msgStr)"
            }
            let alert = UIAlertController(title: "Payment Failed", message: msgStr, preferredStyle: UIAlertController.Style.alert)
            alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: { action in

                self.navigationController?.popToRootViewController(animated: true)

            }))
            self.present(alert, animated: true, completion: nil)

        })
    }
}

Upvotes: 1

Related Questions