I am using Stripe as my payment processor, and have implemented a custom button. However, I realized that I also need to check if the user has entered shipping info before I allow them to pay (I realize that I could just have it on a separate page, but I'd prefer if they didn't have to jump to a new page).
However, when I attempted to add an IF to the Stripe form, I ran into issues. Here is the JSFiddle: http://jsfiddle.net/K843E/1/
<form method="post" action="stripeprocess.php" id="cartform2">
<button id="customButton2" type="button">With Check</button>
<script>
var check = false;
if(check) {
$('#customButton2').click(
function() {
var token = function(res) {
var $input = $('<input type=hidden name=stripeToken />').val(res.id);
$('#cartform2').append($input).submit();
};
StripeCheckout.open({
address: true,
amount: 1000,
currency: 'usd',
name: 'Test',
description: 'Item Description',
panelLabel: 'Checkout',
token: token
}
}
);
return false;
});
The top button shows how it should work if the IF statement returns true, the bottom button is my attempt at the IF.
You have a lot of syntax error in that code i fixed it here, now it works with true or false on check.
var check = false;
if(check) {
$('#customButton2').click(
function() {
var token = function(res) {
var $input = $('<input type=hidden name=stripeToken />').val(res.id);
$('#cartform2').append($input).submit();
};
StripeCheckout.open({
address: true,
amount: 1000,
currency: 'usd',
name: 'Test',
description: 'Item Description',
panelLabel: 'Checkout',
token: token
} );
return false;
});
}
Working DEMO
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.