Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Getting 'No such PaymentMethod' error when presenting payment sheet. #4222

Open
HiteshPrajapati95 opened this issue Nov 5, 2024 · 5 comments
Labels

Comments

@HiteshPrajapati95
Copy link

HiteshPrajapati95 commented Nov 5, 2024

Summary

I am using same setup as reference link : https://docs.stripe.com/payments/finalize-payments-on-the-server?platform=ios
Getting success when making payment with new card (in case no card has saved with customer) but for the second time when trying to present payment sheet, it immediately closes payment sheet automatically with error 'No such PaymentMethod'.

Code to reproduce

func presentPaymentSheet(from vc: UIViewController, amount: Int, currency: String) {
STPAPIClient.shared.publishableKey = stripePublishableKey

    let intentConfig = PaymentSheet.IntentConfiguration(
        mode: .payment(amount: amount, currency: currency, captureMethod: .manual)
    ) { [weak self] paymentMethod, shouldSavePaymentMethod, intentCreationCallback in
        self?.handleConfirm(paymentMethod, shouldSavePaymentMethod, intentCreationCallback)
    }

    var configuration = PaymentSheet.Configuration()
    configuration.customer = .init(id: stripeCustomerCode, ephemeralKeySecret: ephemeralKeySecret)
    configuration.returnURL = “AppName://stripe-redirect"
    configuration.merchantDisplayName = AppName
    configuration.applePay = .init(merchantId: appleMerchantID, merchantCountryCode: countryCode)
    configuration.allowsDelayedPaymentMethods = true
    
    let paymentSheet = PaymentSheet(intentConfiguration: intentConfig, configuration: configuration)
    
    paymentSheet.present(from: vc) { result in
        switch result {
        case .completed:
            // Payment completed - show a confirmation screen.
        case .failed(let error):
            // PaymentSheet encountered an unrecoverable error. 
            print("paymentSheet result: Error", error)
        case .canceled:
            // Customer canceled payment
        }
    }

}

iOS version

16.7.10

Installation method

Using cocoapods

SDK version

24.0.0

Other information

Related concern is how SDK is trying to use payment method when payment sheet is not being presented and also user has not selected any payment method to start payment process yet.

@seanzhang-stripe
Copy link

@HiteshPrajapati95 Can you put some logs in your code to check if stripePublishableKey is changed before your code presents the PaymentSheet at the second time?

@HiteshPrajapati95
Copy link
Author

Hi @seanzhang-stripe, I've checked for the same, and there is no change in stripePublishableKey. It always remains the same.

@HiteshPrajapati95
Copy link
Author

@seanzhang-stripe, The issue is that when SDK fetches payment method from platform, it retrieves the wrong payment method. Somehow SDK gets the payment method from the Connect account, and when it loads the payment sheet UI, it considers it a platform. I think this is why it returns error as No such payment method.

@seanzhang-stripe
Copy link

@HiteshPrajapati95 Did you clone the platform payment method to the connected account, and use the cloned payment method to create a Direct Charge? Can you share with me the relevant PaymentIntent ID?

@HiteshPrajapati95
Copy link
Author

When users do not have any saved cards, at that time users enter card details, and that card gets cloned in to connect account through backend setup. After that, using the cloned payment method, payment gets success through intent.

Now for the second time, when the user tries to make payment with the saved payment method at that time (when presenting the payment sheet), SDK returns an error by fetching the previously used payment method and closes the payment sheet instantly.

For the second time, the payment method clone steps don't perform because of getting a payment sheet error while presenting the payment sheet.

Here is the request_id for the same case: req_KUbLmRiDahouB9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants