question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Throw error with Stripe error code key in Android

See original GitHub issue

First of all, thanks for an awesome library. This is so helpful to work with.

in iOS, I can localize error messages by checking an error code key error.userInfo['com.stripe.lib:StripeErrorCodeKey] and mapping it to a localized error message. but in Android, It seems that thrown errors do not have the key.

mapping message to localized message seems fragile, so I think it’s very nice if StripeErrorCodeKey is thrown on Android as same as iOS.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
tsugittacommented, Oct 10, 2017

@isnifer thanks for your reply.

I use something like below. this works only for iOS and not for Android.

const errorMessages = {
  incorrect_number: "The card number is incorrect.",
  invalid_number: "The card number is not a valid credit card number.",
  invalid_expiry_month: "The card's expiration month is invalid.",
  invalid_expiry_year: "The card's expiration year is invalid.",
  invalid_cvc: "The card's security code is invalid.",
  expired_card: "The card has expired.",
  incorrect_cvc: "The card's security code is incorrect.",
  incorrect_zip: "The card's zip code failed validation.",
  card_declined: "The card was declined.",
  missing: "There is no card on a customer that is being charged.",
  processing_error: "An error occurred while processing the card.",
  rate_limit:  "An error occurred due to requests hitting the API too quickly. Please let us know if you're consistently running into this error."
};

Stripe.createTokenWithCard(params)
  .then(res => {
    //
  })
  .catch(err => {
    // in iOS, this works, but in Android, an error does not seem to have any errorCodeKey info
    const stripeErrorType = error.userInfo['com.stripe.lib:StripeErrorCodeKey']
   
    const localizedErrorMessage = errorMessages[stripeErrorType];
    Alert.alert(localizedErrorMessage)
  })
0reactions
jojonartecommented, Sep 19, 2018

Any progress on this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error codes | Stripe Documentation
Some Errors include an error code—a short string with a brief explanation. These codes play a role in our recommended error handling techniques....
Read more >
Handle errors | Stripe Documentation
Catch and respond to declines, invalid data, network problems, and more. Stripe offers many kinds of errors. They can reflect external events, like...
Read more >
Handle errors | Stripe Documentation
Catch and respond to declines, invalid data, network problems, and more. Stripe offers many kinds of errors. They can reflect external events, ...
Read more >
Stripe API reference – Errors – curl
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries....
Read more >
Low-level error handling | Stripe Documentation
They return an HTTP response with a 4xx response code. For example, the API servers might return a 401 if you provided an...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found