i did all the code regarding to the Stripe and i followed the documentation of the stripe in which i i am calling one api to get the secret key from the server n which is coming..and after that i am passing it ot the "STPPaymentHandler.shared()"..but i am getting the error STPPaymentHandlerActionStatus error Optional("No such setupintent: (null)") a..please help me if you know thank you in advance below the code which i did
i followed this documentation https://stripe.com/docs/payments/accept-a-payment
//method to get secrete key
func checkout() {
let apikey = UserDefaults.standard.value(forKey: keyParameter.apikey.rawValue) as! String
let dic = ["apikey":apikey,"amount":"5000"]
Webhelper.sharedInstance.apiPostRequest(apiUrl: GlobalConstant.stripe_token, parameter: dic, success: { (success) in
print("success from the server is \(success)")
do{
let responseResult = try Global.sharedInstance.decode(jwtToken: success)
let message = Global.sharedInstance.getStringValue(responseResult["Message"] as AnyObject)
if let status = responseResult["result"] as? NSNumber {
if status == 1{
let responseDic = responseResult["Secrate"] as! NSDictionary
self.setupIntentClientSecret = responseDic.value(forKey: "clientSecret") as! String
let apikey = responseDic.value(forKey: "publishableKey") as! String
Stripe.setDefaultPublishableKey(apikey)
print(" self.setupIntentClientSecret self.setupIntentClientSecret \(self.setupIntentClientSecret)")
}else if status == 0{
Global.sharedInstance.ShowMessagePopup(Viewobj: self, title: "", Message: message)
}
}
}catch{
print("cought error in the catch \(error.localizedDescription)")
}
}) { (error) in
print("error for the server is \(error.localizedDescription)")
}
}
///this is the method to complete the payment
@objc func pay() {
// Collect card details
let cardParams = self.paymentTextField.cardParams
// Collect the customer's email to know which customer the PaymentMethod belongs to.
let billingDetails = STPPaymentMethodBillingDetails()
billingDetails.email = "sunil@gmial.com"//emailTextField.text
// Create SetupIntent confirm parameters with the above
let paymentMethodParams = STPPaymentMethodParams(card: cardParams, billingDetails: billingDetails, metadata: nil)
print("setupIntentClientSecret inside method\(setupIntentClientSecret)")
let setupIntentParams = STPSetupIntentConfirmParams(clientSecret: setupIntentClientSecret)
setupIntentParams.paymentMethodParams = paymentMethodParams
print("secrete \(setupIntentClientSecret)")
// Complete the setup
let paymentHandler = STPPaymentHandler.shared()
paymentHandler.confirmSetupIntent(withParams: setupIntentParams, authenticationContext: self) { status, setupIntent, error in
print("success from the server is setupIntent\(setupIntent) status \(status) error \(error?.localizedDescription)")
switch (status) {
case .failed:
self.displayAlert(title: "Setup failed", message: error?.localizedDescription ?? "")
// print("\(error?.localizedDescription)")
break
case .canceled:
self.displayAlert(title: "Setup canceled", message: error?.localizedDescription ?? "")
break
case .succeeded:
self.displayAlert(title: "Setup succeeded", message: setupIntent?.description ?? "", restartDemo: true)
break
@unknown default:
fatalError()
break
}
}
}