Dla dalszego odniesienia:
Chociaż nie można wykorzystywać ludzkich komunikatów o błędach paskiem być wyświetlane bezpośrednio na lokalnych stronach można wykorzystać response.error.code
dostarczyć własne tłumaczenia.
var 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."
};
function stripeHandler(status, response){
if (response.error && response.error.type == 'card_error'){
$('.errors').text(errorMessages[ response.error.code ]);
}
else {
// do other stuff (and handle api/request errors)
}
}
Wykaz kodów is documented here (obecnie prawej kolumnie w sekcji „Kody”).
Wielkie dzięki! Zaznaczę to jako odpowiedź :-) –
Działa idealnie –
Świetna odpowiedź! :) – facundofarias