For some reason the token isn’t getting set to my server. I get code 50 as a print error, but I can’t seem to narrow it down. Do any of you have any idea? Below you will see all the prints that I added to try to figure out where the problem is coming from. Basically the applePayContext(_:didCreatePaymentMethod:paymentInformation:completion:)
delegate method is not being called. Why that is I don’t know. All I have is error code 50. I checked merchant id in Xcode and on my developer account I have it all set up. In my class I have STPApplePayContextDelegate
and I have var paymentContext: STPApplePayContext?
@objc func applePayButtonTapped() {
print("Apple Pay button tapped")
let request = StripeAPI.paymentRequest(withMerchantIdentifier: "merchant.medical.daylike", country: "US", currency: "EUR")
request.paymentSummaryItems = [PKPaymentSummaryItem(label: "Script", amount: NSDecimalNumber(string: "1.00"))]
print("Payment request details: \(request)")
paymentContext = STPApplePayContext(paymentRequest: request, delegate: self)
print("Presenting Apple Pay sheet")
paymentContext?.presentApplePay()
print("yesue")
}
func applePayContext(_ context: STPApplePayContext, didCreatePaymentMethod paymentMethod: StripePayments.STPPaymentMethod, paymentInformation: PKPayment, completion: @escaping StripeApplePay.STPIntentClientSecretCompletionBlock) {
print("Apple Pay did create payment method")
let paymentMethodId = paymentMethod.stripeId
let amount = 100 // Example amount in cents (€10.00)
createPaymentIntent(paymentMethodId: paymentMethodId, amount: amount) { result in
switch result {
case .success(let clientSecret):
completion(clientSecret, nil)
case .failure(let error):
print("Error in creating payment intent: \(error.localizedDescription)")
completion(nil, error)
}
}
}
func applePayContext(_ context: STPApplePayContext, didFailToCreatePaymentMethodWithError error: Error) {
print("Failed to create payment method: \(error.localizedDescription)")
}
func applePayContext(_ context: STPApplePayContext, didCompleteWith status: StripePayments.STPPaymentStatus, error: Error?) {
print("Apple Pay process didCompleteWith status: \(status)")
if let error = error as NSError? {
print("Error in Apple Pay process: \(error.localizedDescription), Code: \(error.code)")
}
print("Apple Pay process completed with status: \(status)")
switch status {
case .success:
// Payment succeeded
break
case .error:
// Payment failed
break
case .userCancellation:
// User canceled the payment
break
@unknown default:
fatalError("Unknown Apple Pay status")
}
}
My prints
Payment request details: <PKPaymentRequest: 0x14bde0f80; APIType: PKPaymentRequestAPITypeInApp, requestType: PKPaymentRequestTypeApplePay, requestor: PKPaymentRequestorDefault, countryCode: DE, merchantCapabilities: 1, currencyCode: EUR, shippingType: SHIPPING, applePayLaterAvailability: enabledshouldUseMerchantSession: 0, suppressTotal: 0, paymentSummaryPinned: 0, supportedNetworks: (
AmEx,
MasterCard,
Maestro,
Visa,
Discover
), supportsCouponCode: 0, paymentSummaryItems: 1, requiredBillingContactFields: {(
post
)}, >
Presenting Apple Pay sheet
yesue
Apple Pay process didCompleteWith status: error
Error in Apple Pay process: There was an unexpected error -- try again in a few seconds, Code: 50
Apple Pay process completed with status: error