I used this tutorial to integrate payment into my app:
https://www.raywenderlich.com/182-accepting-credit-cards-in-your-ios-app-using-stripe#
But when I select done on the STPAddCardViewController()
the app loads and doesn't stop loading. I added print statements into the extension shown in the tutorial with the hopes that it would show me where the code was stalling, but none of the print statements were shown. This is shown below:
extension OrderDetialsViewController: STPAddCardViewControllerDelegate {
func addCardViewControllerDidCancel(_ addCardViewController: STPAddCardViewController) {
print("addCard")
navigationController?.popViewController(animated: true)
}
private func addCardViewController(_ addCardViewController: STPAddCardViewController,
didCreateToken token: STPToken,
completion: @escaping STPErrorBlock) {
print("addCard Created Token")
var totalCost = 0
for i in 0...localData.shoppingCart.itemSizeArray.count-1{
if localData.shoppingCart.itemSizeArray[i] == "hd"{
totalCost = totalCost+2000
}
else if localData.shoppingCart.itemSizeArray[i] == "d"{
totalCost = totalCost+4000
}
else if localData.shoppingCart.itemSizeArray[i] == "free"{
totalCost = totalCost + 0
}
else if localData.shoppingCart.itemSizeArray[i] == "home" {
totalCost = totalCost + 500
}
}
StripeClient.shared.completeCharge(with: token, amount: totalCost) { result in
print("StripeClient")
switch result {
case .success:
completion(nil)
let alertController = UIAlertController(title: "Congrats on your order",
message: "Your payment was successful! Check email for confirmation!",
preferredStyle: .alert)
let alertAction = UIAlertAction(title: "OK", style: .default, handler: { _ in
self.navigationController?.popViewController(animated: true)
})
alertController.addAction(alertAction)
self.present(alertController, animated: true)
self.createOrderEmailBody()
self.createCustomerOrderBody()
self.changeUserRewardsScore()
case .failure(let error):
print(error)
completion(error)
}
}
}
}
what version of the iOS SDK are you using?
If it is a version after v16.0.0, you need to implement the didCreatePaymentMethod
function to get back a PaymentMethod object, the didCreateToken
method is deprecated.
You would also have to implement PaymentIntents, as PaymentMethods can only be used with PaymentIntents, which are the recommended integration.
Here's a tutorial on how to get started with PaymentMethods and PaymentIntents in your iOS app: https://youtu.be/s5Ml41bZidw?t=57