59 lines
2.3 KiB
JavaScript
59 lines
2.3 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 {
|
|
var $token_id = $(':input[name="token_id"]', $stripeForm);
|
|
var $token_email = $(':input[name="token_email"]', $stripeForm);
|
|
$token_id.val(token.id);
|
|
$token_email.val(token.email);
|
|
$stripeForm.get(0).submit();
|
|
}
|
|
catch(err) {
|
|
//console.log([err]);
|
|
alert(err);
|
|
}
|
|
|
|
// Use the token to create the charge with a server-side script.
|
|
// You can access the token ID with `token.id`
|
|
//if (currentForm === undefined)
|
|
// return;
|
|
//currentForm.find('input[name="token_id"]').val(token.id);
|
|
//currentForm.find('input[name="token_email"]').val(token.email);
|
|
//currentForm.submit();
|
|
}
|
|
});
|
|
//var currentForm = undefined;
|
|
|
|
$('.form-submit').click(function (e) {
|
|
//currentForm = $(this).closest('form');
|
|
//if (currentForm === undefined)
|
|
// return;
|
|
var settings = Drupal.settings.booking_stripe;
|
|
var $stripeForm = $("#" + settings.form_selector);
|
|
alert($(':input[name="description"]', $stripeForm));
|
|
handler.open({
|
|
name: settings.name,
|
|
//description: currentForm.find('input[name="description"]').val(),
|
|
description: $(':input[name="description"]', $stripeForm),
|
|
//email: currentForm.find('input[name="email"]').val(),
|
|
email: $(':input[name="email"]', $stripeForm),
|
|
currency: "aud",
|
|
//amount: currentForm.find('input[name="amount"]').val() * 100,
|
|
amount: $(':input[name="amount"]', $stripeForm),
|
|
zipCode: true,
|
|
closed: function() {
|
|
//document.getElementById("booking_stripe_form").submit();
|
|
}
|
|
});
|
|
e.preventDefault();
|
|
});
|
|
// Close Checkout on page navigation
|
|
//$(window).on('popstate', function() {
|
|
// handler.close();
|
|
//});
|
|
}); |