[ad_1]
Attempting to setup Stripe apple pay in my endeavor, nonetheless preserve working into “payment not completed” as seen proper right here: https://i.stack.imgur.com/JMIx6.png
The place I’m calling the payment model
if backendModel.paymentIntentParams != nil {
PaymentButton() {
applePayModel.pay(amount: cartCost, entire: totalCost, clientSecret: backendModel.paymentIntentParams?.clientSecret, pi: backendModel.paymentIntentParams?.stripeId)
}
.cornerRadius(25)
.padding([.horizontal, .bottom])
}
Apple Pay Model
func pay(amount: Double, entire: Double, clientSecret: String?, pi: String?) {
self.clientSecret = clientSecret
self.pi = pi
// Configure our Apple Pay payment request
let paymentRequest = StripeAPI.paymentRequest(withMerchantIdentifier: "service supplier.com.myapp", nation: "US", overseas cash: "usd")
paymentRequest.requiredBillingContactFields = [.postalAddress]
paymentRequest.requiredShippingContactFields = []
paymentRequest.paymentSummaryItems = [
PKPaymentSummaryItem(label: "Subtotal", amount: NSDecimalNumber(value: amount)),
PKPaymentSummaryItem(label: "Delivery Fee + Taxes", amount: NSDecimalNumber(value: 5.00)),
PKPaymentSummaryItem(label: "Total", amount: NSDecimalNumber(value: total))
]
// Present apple pay context
let applePayContext = STPApplePayContext(paymentRequest: paymentRequest, delegate: self)
applePayContext?.presentApplePay()
}
func applePayContext(_ context: STPApplePayContext, didCreatePaymentMethod paymentMethod: STPPaymentMethod, paymentInformation: PKPayment, completion: @escaping STPIntentClientSecretCompletionBlock) {
// payment methodology was created -> confirm PaymentIntent
if (self.clientSecret != nil) {
// title the completion block with the buyer secret
completion(clientSecret, nil)
} else {
completion(nil, NSError())
}
}
func applePayContext(_ context: STPApplePayContext, didCompleteWith standing: STPPaymentStatus, error: Error?) {
// get the payment standing or error
self.paymentStatus = standing
self.lastPaymentError = error
if standing == .success {
print("Payment success!")
}
}
[ad_2]