bourax webmaster bourax webmaster - 1 year ago 111
Javascript Question

set language for customised Stripe form

I have a Stripe payment form in a multilanguages site. With the simple form I can set the language by : data-locale="" (which is 2 letters ; EN or DE,...) in :

<script src="" class="stripe-button"
data-image="images/home/cart.png" // your company Logo
data-email="<?= $loggedInUser->email ?>"
data-locale="<?= $language ?>"

but when I use the customised form, I don't know how and where to set the language value :
here is my script :

<form action="" method="POST" id="payment-form">
<span class="payment-errors"></span>
<input type="text" size="20" data-stripe="number">
<input type="text" size="2" data-stripe="exp_month">
<input type="text" size="2" data-stripe="exp_year">
<input type="text" size="4" data-stripe="cvc">
<input type="text" size="6" data-stripe="address_zip">
<input type="submit" class="submit" value="Submit Payment">

<script type="text/javascript" src=""></script>
<script type="text/javascript">
$(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;

Answer Source

You can use a message array :

 var errorMessages = {
            incorrect_number: "<?= $language['incorrect_number'] ?>",
            invalid_number: "<?= $language['invalid_number'] ?>.",
            invalid_expiry_month: "<?= $language['invalid_expiry_month'] ?>",
            invalid_expiry_year: "<?= $language['invalid_expiry_year'] ?>",
            invalid_cvc: "<?= $language['invalid_cvc'] ?>",
            expired_card: "<?= $language['expired_card'] ?>",
            incorrect_cvc: "<?= $language['incorrect_cvc'] ?>",
            incorrect_zip: "<?= $language['incorrect_zip'] ?>",
            card_declined: "<?= $language['card_declined'] ?>",
            missing: "<?= $language['missing'] ?>",
            processing_error: "<?= $language['processing_error'] ?>",
            rate_limit:  "<?= $language['rate_limit'] ?>"
        if (response.error) {
            $form.find('.payment-errors').text(errorMessages[ response.error.code ] );

See all the errors here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download