stripe / stripe-ios

Stripe iOS SDK
https://stripe.com
MIT License
2.13k stars 982 forks source link

[BUG] StripePayments/STPAPIClient+Payments.swift:542: Assertion failed: `secret` format does not match expected client secret formatting. #2639

Closed shaileshe2logy closed 1 year ago

shaileshe2logy commented 1 year ago

Summary

-- Getting below error while running PaymentSheet.FlowController.create and We have confirmed that the client secret is correct. -- The same client secret is working fine with the payment sheet. (Reference)

Screenshot 2023-06-08 at 6 56 12 PM

Code to reproduce

` func setUpStripePayment(merchantName: String?,publishableKey:String?, clientSecret:String?) {

    guard let strPublishableKey = publishableKey, strPublishableKey.count > 0,
          let strClientSecret = clientSecret, strClientSecret.count > 0 else { return }

    //Set Publishable Key
    StripeAPI.defaultPublishableKey = strPublishableKey
    STPAPIClient.shared.publishableKey = strPublishableKey

    var configuration = PaymentSheet.Configuration()

    //Apple Pay
    configuration.applePay = .init( merchantId: "XXXXX.XXXX.XXXXX.XXX", merchantCountryCode: "SG" )

    configuration.returnURL = "App-Bundle://stripe-redirect"

    //Update Primary color
    var appearance = PaymentSheet.Appearance()
    appearance.colors.primary = Constant.Colors.MRed
    configuration.appearance = appearance

    configuration.merchantDisplayName = merchantName ?? ""
    configuration.allowsDelayedPaymentMethods = true
    configuration.savePaymentMethodOptInBehavior = .automatic

    PaymentSheet.FlowController.create(setupIntentClientSecret: strClientSecret, configuration: configuration) { [weak self] result in
        //FIXME:  Mitul | Remove progress

        guard let self = self else { return }

        switch result {
          case .failure(let error):
            debugPrint("Payment failed | \(error.localizedDescription)")

          case .success(let paymentSheetFlowController):
            self.paymentSheetFlowController = paymentSheetFlowController
            self.paymentSheetFlowController?.presentPaymentOptions(from: self) {}

            self.paymentSheetFlowController?.confirm(from: self) { [weak self] paymentResult in
                guard let selfNew = self else { return }
                switch paymentResult {
                case .completed:
                    debugPrint("Payment complete")
                case .canceled:
                    debugPrint("Payment canceled")
                case .failed(let error):
                    debugPrint("Payment failed | \(error.localizedDescription)")
                }
            }
          }
    }
}`

iOS version

iOS Version: 16.3

Installation method

SDK version

StripeApplePay (23.6.1):

Other information

wooj-stripe commented 1 year ago

Hi @shaileshe2logy

Thanks for reaching out. In looking at your code, it looks like you are attempting to use this integration for paying (not setting up a payment method):

                case .completed:
                    debugPrint("Payment complete")
                case .canceled:
                    debugPrint("Payment canceled")

However, I'm seeing that you are using:

PaymentSheet.FlowController.create(setupIntentClientSecret:...)

Perhaps you have created a payment intent, and have passed the payment intent client secret to this function rather than a setup Intent client secret?

Payment Intent client secrets have a pattern of: "^pi_[^_]+_secret_[^_]+$" where, SetupIntent client secrets have a pattern of: ^seti_[^_]+_secret_[^_]+$

Can you verify which you are trying to use? PaymentIntent or SetupIntent?

porter-stripe commented 1 year ago

Closing as it appears this may have been resolved with the above comment from the 👍!