ios – Unable to course of stripe fee utilizing Apple pay. The fee technique kind apple_pay is invalid

0
67


I’m making an attempt so as to add stripe fee processor to my apple swiftui code. When I’m making an attempt to make the fee I preserve getting the next error in my console.

Server facet error:

Obtained information: {'quantity': 1000, 'forex': 'jpy'}
Creating PaymentIntent with quantity: 1000 and forex: jpy
Error occurred: Request req_1i6XdalbzHAek8: The fee technique kind "apple_pay" is invalid. Please make sure the supplied kind is activated in your dashboard (https://dashboard.stripe.com/account/funds/settings) and your account is enabled for any preview options that you're making an attempt to make use of.

Server facet code (python):

@app.route('/create-payment-intent', strategies=['POST'])
def create_payment_intent():
    attempt:
        information = request.get_json()
        print("Obtained information:", information)  # Print the acquired information for debugging

        quantity = information.get('quantity')  # Quantity in cents
        forex = information.get('forex', 'jpy')  # Default to JPY if not supplied

        print(f"Creating PaymentIntent with quantity: {quantity} and forex: {forex}")

        # Create a PaymentIntent with the order quantity and forex
        intent = stripe.PaymentIntent.create(
            quantity=quantity,
            forex=forex,
            payment_method_types=["card", "apple_pay"],
        )

        print("PaymentIntent created efficiently:", intent)

        return jsonify({
            'clientSecret': intent['client_secret']
        })
    besides Exception as e:
        print("Error occurred:", e)  # Print the error message
        return jsonify({'error': str(e)}), 403

I’ve verified that Apple pay is activated in my account. I’ve tried recreating the certificates and service provider id.
That is my fee handler:

import Basis
import PassKit
import Firebase
import FirebaseFirestore
import Stripe

typealias PaymentCompletionHandler = (Bool) -> Void

class PaymentHandler: NSObject {
    
    var paymentController: PKPaymentAuthorizationController?
    var paymentSummaryItems = [PKPaymentSummaryItem]()
    var paymentStatus = PKPaymentAuthorizationStatus.failure
    var completionHandler: PaymentCompletionHandler?
    var userInfo: [String: String] = [:]
    
    static let supportedNetworks: [PKPaymentNetwork] = [
        .visa,
        .masterCard,
        .amex
    ]
    
    class func applePayStatus() -> (canMakePayments: Bool, canSetupCards: Bool) {
        return (PKPaymentAuthorizationController.canMakePayments(),
                PKPaymentAuthorizationController.canMakePayments(usingNetworks: supportedNetworks))
    }
    
    func startPayment(userInfo: [String: String], completion: @escaping PaymentCompletionHandler) {
        self.userInfo = userInfo
        completionHandler = completion
        
        paymentStatus = .failure
        paymentSummaryItems = []
        
        let complete = PKPaymentSummaryItem(label: "Report", quantity: NSDecimalNumber(string: RemoteConfigManager.worth(forKey: RCKey.reportCost)), kind: .remaining)
        paymentSummaryItems.append(complete)
        
        let paymentRequest = StripeAPI.paymentRequest(withMerchantIdentifier: "service provider.my.service provider.id", nation: "JP", forex: "JPY")
        paymentRequest.paymentSummaryItems = paymentSummaryItems
        paymentRequest.supportedNetworks = PaymentHandler.supportedNetworks

        if StripeAPI.canSubmitPaymentRequest(paymentRequest) {
            paymentController = PKPaymentAuthorizationController(paymentRequest: paymentRequest)
            paymentController?.delegate = self
            paymentController?.current(completion: { (offered: Bool) in
                if offered {
                    debugPrint("Introduced fee controller")
                } else {
                    debugPrint("Did not current fee controller")
                    completion(false)
                }
            })
        } else {
            debugPrint("Can't submit fee request")
            completion(false)
        }
    }
}

extension PaymentHandler: PKPaymentAuthorizationControllerDelegate {
    func paymentAuthorizationController(_ controller: PKPaymentAuthorizationController, didAuthorizePayment fee: PKPayment, handler completion: @escaping (PKPaymentAuthorizationResult) -> Void) {
        let url = URL(string: "https://my_website.com/create-payment-intent")!
        var request = URLRequest(url: url)
        request.httpMethod = "POST"
        request.setValue("software/json", forHTTPHeaderField: "Content material-Kind")

        let physique: [String: Any] = [
            "amount": 1000,  // Amount in cents
            "currency": "jpy"
        ]
        request.httpBody = attempt? JSONSerialization.information(withJSONObject: physique, choices: [])

        let activity = URLSession.shared.dataTask(with: request) { information, response, error in
            guard let information = information, error == nil else {
                debugPrint("Community request failed: (String(describing: error))")
                completion(PKPaymentAuthorizationResult(standing: .failure, errors: nil))
                return
            }

            do {
                // Print the acquired JSON for debugging
                if let jsonString = String(information: information, encoding: .utf8) {
                    debugPrint("Obtained JSON response: (jsonString)")
                }

                if let json = attempt JSONSerialization.jsonObject(with: information, choices: []) as? [String: Any],
                   let clientSecret = json["clientSecret"] as? String {
                    
                    // Create a PaymentMethod from the PKPayment
                    STPAPIClient.shared.createPaymentMethod(with: fee) { paymentMethod, error in
                        if let error = error {
                            debugPrint("Did not create fee technique: (error)")
                            completion(PKPaymentAuthorizationResult(standing: .failure, errors: [error]))
                            return
                        }

                        guard let paymentMethod = paymentMethod else {
                            debugPrint("Cost technique is nil")
                            completion(PKPaymentAuthorizationResult(standing: .failure, errors: nil))
                            return
                        }

                        // Affirm the PaymentIntent
                        let paymentIntentParams = STPPaymentIntentParams(clientSecret: clientSecret)
                        paymentIntentParams.paymentMethodId = paymentMethod.stripeId

                        STPAPIClient.shared.confirmPaymentIntent(with: paymentIntentParams) { paymentIntent, error in
                            if let error = error {
                                debugPrint("Failed to verify fee intent: (error)")
                                completion(PKPaymentAuthorizationResult(standing: .failure, errors: [error]))
                            } else {
                                completion(PKPaymentAuthorizationResult(standing: .success, errors: nil))
                            }
                        }
                    }
                } else {
                    debugPrint("Invalid JSON response")
                    completion(PKPaymentAuthorizationResult(standing: .failure, errors: nil))
                }
            } catch {
                debugPrint("JSON parsing error: (error)")
                completion(PKPaymentAuthorizationResult(standing: .failure, errors: [error]))
            }
        }
        activity.resume()
    }

    func paymentAuthorizationControllerDidFinish(_ controller: PKPaymentAuthorizationController) {
        controller.dismiss {
            DispatchQueue.predominant.async {
                if self.paymentStatus == .success {
                    self.completionHandler?(true)
                } else {
                    self.completionHandler?(false)
                }
            }
        }
    }
}

Stripe Dashboard confirming Apple Pay is energetic:
enter image description here
enter image description here

Might you inform me tips on how to debug? I’m clueless what extra can I do.