55 lines
2.4 KiB
JavaScript
55 lines
2.4 KiB
JavaScript
jQuery(document).ready(function($) {
|
|
var $settings = Drupal.settings.booking_stripe;
|
|
var $stripeForm = $("#" + $settings.form_selector);
|
|
var handler = StripeCheckout.configure({
|
|
key: $settings.pubkey,
|
|
image: $settings.image,
|
|
locale: 'auto',
|
|
token: function(token) {
|
|
try {
|
|
//store the returned token into hidden form elements
|
|
$(':input[name="token_id"]', $stripeForm).val(token.id);
|
|
$(':input[name="token_email"]', $stripeForm).val(token.email);
|
|
$(':input[name="token_client_ip"]', $stripeForm).val(token.client_ip);
|
|
$(':input[name="card_brand"]', $stripeForm).val(token.card.brand);
|
|
$(':input[name="card_cvc_check"]', $stripeForm).val(token.card.cvc_check);
|
|
$(':input[name="card_address_zip_check"]', $stripeForm).val(token.card.address_zip_check);
|
|
$stripeForm.get(0).submit();
|
|
}
|
|
catch(err) {
|
|
console.log([err]);
|
|
alert(err.message);
|
|
}
|
|
}
|
|
});
|
|
|
|
$('.form-submit').click(function (e) {
|
|
//currentForm = $(this).closest('form');
|
|
//if (currentForm === undefined)
|
|
// return;
|
|
var $settings = Drupal.settings.booking_stripe;
|
|
var $stripeForm = $("#" + $settings.form_selector);
|
|
//$description = $(':input[name="description"]', $stripeForm).val();
|
|
//console.log([$description]);
|
|
//description: currentForm.find('input[name="description"]').val(),
|
|
//email: currentForm.find('input[name="email"]').val(),
|
|
//amount: currentForm.find('input[name="amount"]').val() * 100,
|
|
//alert($(':input[name="description"]', $stripeForm));
|
|
handler.open({
|
|
name: $settings.name,
|
|
currency: "aud",
|
|
description: $(':input[name="description"]', $stripeForm).val(),
|
|
email: $(':input[name="email"]', $stripeForm).val(),
|
|
amount: $(':input[name="amount"]', $stripeForm).val() * 100,
|
|
zipCode: true,
|
|
closed: function() {
|
|
//document.getElementById("booking_stripe_form").submit();
|
|
}
|
|
});
|
|
e.preventDefault();
|
|
});
|
|
// Close Checkout on page navigation
|
|
//$(window).on('popstate', function() {
|
|
// handler.close();
|
|
//});
|
|
}); |