一旦我 select 在 STPAddCardViewController() 上完成,应用程序就会加载并且不会停止加载
Once I select done on the STPAddCardViewController() the app loads and doesn't stop loading
我使用本教程将支付集成到我的应用程序中:
https://www.raywenderlich.com/182-accepting-credit-cards-in-your-ios-app-using-stripe#
但是当我 select 在 STPAddCardViewController()
上完成时,应用程序加载并且不会停止加载。我将打印语句添加到教程中显示的扩展中,希望它能告诉我代码在哪里停止,但显示了 none 的打印语句。如下所示:
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)
}
}
}
}
您使用的是什么版本的 iOS SDK?
如果是v16.0.0之后的版本,需要实现didCreatePaymentMethod
函数来取回一个PaymentMethod对象,didCreateToken
方法已废弃
您还必须实施 PaymentIntents,因为 PaymentMethods 只能与 PaymentIntents 一起使用,这是推荐的集成。
这里有一个关于如何在您的 iOS 应用中开始使用 PaymentMethods 和 PaymentIntents 的教程:https://youtu.be/s5Ml41bZidw?t=57
我使用本教程将支付集成到我的应用程序中:
https://www.raywenderlich.com/182-accepting-credit-cards-in-your-ios-app-using-stripe#
但是当我 select 在 STPAddCardViewController()
上完成时,应用程序加载并且不会停止加载。我将打印语句添加到教程中显示的扩展中,希望它能告诉我代码在哪里停止,但显示了 none 的打印语句。如下所示:
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)
}
}
}
}
您使用的是什么版本的 iOS SDK?
如果是v16.0.0之后的版本,需要实现didCreatePaymentMethod
函数来取回一个PaymentMethod对象,didCreateToken
方法已废弃
您还必须实施 PaymentIntents,因为 PaymentMethods 只能与 PaymentIntents 一起使用,这是推荐的集成。
这里有一个关于如何在您的 iOS 应用中开始使用 PaymentMethods 和 PaymentIntents 的教程:https://youtu.be/s5Ml41bZidw?t=57