0
我正在使用條帶和API中的「自定義窗體」。以下代碼在英文中出現錯誤時會拋出錯誤,但我想將一些錯誤消息翻譯成挪威語,以便讓我的客戶更加友好。例如當前爲英文的「invalid_expiry_year」和「invalid_expiry_month」。使用JavaScript自定義條帶錯誤消息
是否有可能實現,如果有,如何實現?
<script type="text/javascript" src="https://js.stripe.com/v2/"></script>
<script type="text/javascript">
Stripe.setPublishableKey('pk_test_2iA9ERjj5lVuUgvOS9W5fNtV');
$(function() {
var $form = $('#payment-form');
$form.submit(function(event) {
// Disable the submit button to prevent repeated clicks:
$form.find('.submit').prop('disabled', true);
// Request a token from Stripe:
Stripe.card.createToken($form, stripeResponseHandler);
// Prevent the form from being submitted:
return false;
});
});
function stripeResponseHandler(status, response) {
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)
}
}
// Grab the form:
var $form = $('#payment-form');
if (response.error) { // Problem
// Show the errors on the form:
$form.find('.payment-errors').text(response.error.message);
$form.find('.submit').prop('disabled', false); // Re-enable submission
} else { // Token was created!
// Get the token ID:
var token = response.id;
// Insert the token ID into the form so it gets submitted to the server:
$form.append($('<input type="hidden" name="stripeToken">').val(token));
// Submit the form:
$form.get(0).submit();
}
};
</script>