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] Calling intentCreationCallback(.success(clientSecret)) causes inconsistent behavior for manual payment confirmation on the server between card methods and Apple Pay #4609

Open
Ariandr opened this issue Feb 28, 2025 · 3 comments
Labels
kind:bug triaged Issue has been reviewed by Stripe and is being tracked internally

Comments

@Ariandr
Copy link

Ariandr commented Feb 28, 2025

Summary

We are migrating from Basic Integration and Connect payments to the Payment Element with manual payment confirmation on the server.
Payment methods are shared to the Connected accounts from the main Stripe account and payment intents are created on connected accounts as well.
More context here:
#4536

Problem description:
When we pay and payment succeeds, we execute this code.

STPAPIClient.shared.stripeAccount = connectedAccountId // We set the account id that was used for Payment Intent creation
self.intentCreationCallback?(.success(paymentIntentClientSecret)) // Returned from API after its creation/confirmation
STPAPIClient.shared.stripeAccount = nil // Remove it to use the main Stripe account header

Issue:
When we pay with a card method and the payment succeeds without next action required and we call self.intentCreationCallback?(.success(clientSecret)), it causes this error on the iOS side. Doesn't affect the real world payment of course, but probably not ideal.
Error Domain=com.stripe.lib Code=50 "There was an unexpected error -- try again in a few seconds" UserInfo={com.stripe.lib:ErrorParameterKey=intent, com.stripe.lib:StripeRequestIDKey=req_phphzDVNMVa14c, NSLocalizedDescription=There was an unexpected error -- try again in a few seconds, com.stripe.lib:StripeErrorCodeKey=resource_missing, com.stripe.lib:ErrorMessageKey=No such payment_intent: 'pi_3QxTM0GZhTdR0Vyo03xQZKka', com.stripe.lib:StripeErrorTypeKey=invalid_request_error, com.stripe.lib:hintKey=No matching PaymentIntent could be found. Ensure you are creating a PaymentIntent server side and using the same publishable key on both client and server. You can find more information at https://stripe.com/docs/api/payment_intents/create}

BUT:
If we pay with Apple Pay and the payment succeeds without next action required and we call self.intentCreationCallback?(.success(clientSecret)), it closes the system Apple payment popup with success and no issue is printed. If we don't call self.intentCreationCallback?(.success(clientSecret)), the system Apple Payment popup will collapse with an error.

Short Summary:

When using Apple Pay and the payment succeeds on the first attempt, we need to call self.intentCreationCallback?(.success(clientSecret)).
But when using a card payment method the payment succeeds on the first attempt, we do not need to call self.intentCreationCallback?(.success(clientSecret)) to not get the error.

Question:

Can it be handled in a proper way that we can call self.intentCreationCallback?(.success(clientSecret)) without needing to know if it was an Apple Pay method or a card method?

iOS version

Relevant to all, but tested on iOS 18

Installation method

Cocoapods

SDK version

23.29.2

@Ariandr
Copy link
Author

Ariandr commented Feb 28, 2025

Hi @yuki-stripe
Understanding the context, what thoughts do you have?
I guess that this behavior of SDK might have been overlooked because Payment Element wasn't tested a lot with the manual payment finalization flow on the server.

@yuki-stripe
Copy link
Collaborator

Hey @Ariandr,

I think this is happening because the SDK fetches the PaymentIntent after this line is called:
STPAPIClient.shared.stripeAccount = nil // Remove it to use the main Stripe account header

If you can delay un-setting that until after the call to FlowController.confirm calls its completion block, that might fix it.

@yuki-stripe yuki-stripe added the triaged Issue has been reviewed by Stripe and is being tracked internally label Mar 4, 2025
@Ariandr
Copy link
Author

Ariandr commented Mar 4, 2025

Hi @yuki-stripe
Okay, strange that for Apple Pay it works in any case. I will try and let you know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug triaged Issue has been reviewed by Stripe and is being tracked internally
Projects
None yet
Development

No branches or pull requests

2 participants