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

Provide a more detailed error object to the consumer #398

Open
1 task done
shiv19 opened this issue Oct 25, 2024 · 9 comments
Open
1 task done

Provide a more detailed error object to the consumer #398

shiv19 opened this issue Oct 25, 2024 · 9 comments
Assignees

Comments

@shiv19
Copy link

shiv19 commented Oct 25, 2024

Is your feature request related to a problem? Please describe.
Currently most of the failure handlers are rejecting the call with the localizedErrorMessage from the exception.
Sometimes we might need to use a different message based on the Stripe ApiError code, or a Stripe Decline Code.

Describe the solution you'd like
Instead of call.reject, we should call.resolve with error: true and then additional info about the error such as error code, decline code, error message, etc.
This will provide a more rich error handling experience.

Usage Product
We're currently integrating this plugin into a Capacitor mobile app where field service technicians can take payments using Stripe terminal or Stripe tap to pay.

Additional Context
If there is interest to take the project in this direction, I'm happy to contribute to this.

Using Function:

  • Terminal(@capacitor-community/stripe-terminal)
@rdlabo
Copy link
Member

rdlabo commented Oct 25, 2024

Thanks for the idea. For example, what about passing an exception object to call.reject, I feel it's not a good design to handle errors with resolve.

call.reject(exception.getLocalizedMessage(), null, exception);

Would this solve your problem?

@shiv19
Copy link
Author

shiv19 commented Oct 25, 2024

@rdlabo Ah, I didn't realize call.reject is overloaded. I assumed it only takes a string "message".
Yeah that could work. Let me experiment with that and see what capacitor side receives when we reject like this.
image

@shiv19
Copy link
Author

shiv19 commented Oct 25, 2024

I'm mainly looking to get the decline code that is listed in this table when something fails
https://docs.stripe.com/declines/codes

The failure can happen either on Collect Payment Method, or on Confirm Payment Intent

If the failure occurs during Collect Payment Method,
then the decline code is the Stripe API error code

If the failure occurs during Confirm Payment Intent,
then the decline code is present in exception -> payment intent -> last payment error -> decline_code

The reason why I'm after this code is because my product team wants to use custom error message based on certain decline codes from that table above and present the user with up to 2 follow up actions.

For now I've just ended up extracting the correct code and sending it in the message field of call.reject,
https://github.com/simPRO-Software/stripe/commits/simpro/

I'd rather work towards something that can fit well with the capacitor-community implementation so that I don't have to maintain a fork.

@shiv19
Copy link
Author

shiv19 commented Oct 25, 2024

Here's what I tried

confirmPaymentIntentCall.reject(exception.getLocalizedMessage(), errorCode, exception);

With that, when I console.dir the error, I just get the message and the code, not the full exception object.
image

Since all I'm interested in is the code, perhaps we can add this back to the @capacitor-community/stripe-terminal plugin?

@shiv19
Copy link
Author

shiv19 commented Oct 25, 2024

@shiv19
Copy link
Author

shiv19 commented Oct 25, 2024

@rdlabo Bingo, yeah that works, thanks for pointing me in the right direction.
image

Guess it would be great to add code and declineCode into the exception data.
If you are happy with this change, I can work on this issue.

@rdlabo
Copy link
Member

rdlabo commented Oct 25, 2024

@shiv19 Good!! Good! Just a little too busy this week to do this work. Can I get a pull request if you can? I will try to get time for a review somewhere.

@shiv19
Copy link
Author

shiv19 commented Oct 25, 2024

@rdlabo I might also only get to work on this on Tuesday. It is a long weekend in NZ.
But please leave this to me. I'll assign this issue to me now.

@shiv19 shiv19 self-assigned this Oct 25, 2024
@rdlabo
Copy link
Member

rdlabo commented Oct 26, 2024

@shiv19 A LONG weekend is a wonderful thing! Unfortunately I am spending my weekend working. LOL!

I eagerly await your pull requests!

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

No branches or pull requests

2 participants