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

Error with localization #77

Closed
hannahswain opened this issue Oct 6, 2016 · 5 comments
Closed

Error with localization #77

hannahswain opened this issue Oct 6, 2016 · 5 comments
Assignees
Labels
type: bug The issue is a confirmed bug.
Milestone

Comments

@hannahswain
Copy link
Contributor

Wrong object returned from stripe is being used, causing localised error messages to not display.

stripe.js l:93

Broken:

if ( wc_stripe_params.hasOwnProperty( responseObject.response.error.code ) ) {
message = wc_stripe_params[ responseObject.response.error.code ];
}

Fixed:

if ( wc_stripe_params.hasOwnProperty( responseObject.response.error.type ) ) {
message = wc_stripe_params[ responseObject.response.error.type ];
}

Source: https://wordpress.org/support/topic/error-message-localization-broken/

@roykho roykho self-assigned this Oct 6, 2016
@roykho
Copy link
Member

roykho commented Oct 6, 2016

code should be correct per Stripe's reference docs seen here https://stripe.com/docs/api#errors

@peakdigitaljp
Copy link

I'm the original poster on the WP support area. - I've investigated this a little more. It ends up this only occurs on empty form submission.

If you submit an empty form to stripe, it returns an error message without a code.

Empty form response:
{
"error": {
"type": "invalid_request_error",
"message": "Could not find payment information"
}
}

If the form has any data it will return with a code

Example response:
{
"error": {
"message": "Your card's expiration year is invalid.",
"type": "card_error",
"param": "exp_year",
"code": "invalid_expiry_year"
}
}

The problem being it's not currently possible to localise the empty form error response.

@samuelaguilera
Copy link

@roykho you have added messages only for card_error type and assumed that any responseObject will have a code, but as you can see in the results pasted by @netplus and also in the Stripe docs, there also additional error types and not all types have a code, some of them only have a type and message. From the Stripe.com docs linked above:

The type of error returned. Can be: api_connection_error, api_error, authentication_error, card_error, invalid_request_error, or rate_limit_error.

The appropriate solution would be check responseObject.response.error.type to determine what data contains the responseObject (e.g. it has a code or not?) and proceed accordingly. That is basically what Stripe.com is recommending with this:

Handling errors
Our API libraries raise exceptions for many reasons, such as a failed charge, invalid parameters, authentication errors, and network unavailability. We recommend writing code that gracefully handles all possible API exceptions.

@roykho
Copy link
Member

roykho commented Oct 20, 2016

@samuelaguilera - this has already been flagged a bug so it is known and will be fixed by next release.

@samuelaguilera
Copy link

@roykho great! just commented because of your comment after flagging it as a bug and also seeing that it was labeled as "needs author reply" days after that. Just wanted to add some light here :)

@roykho roykho added this to the 3.1.0 milestone Oct 21, 2016
@roykho roykho closed this as completed in a0c4647 Oct 21, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug The issue is a confirmed bug.
Projects
None yet
Development

No branches or pull requests

3 participants