我正在尝试使条码结帐的成功更好一些,然后div
说“谢谢您的提交”。我正在尝试添加一个模式,将包含此谢谢消息。但是我是PHP的新手,并且我一直在破坏Stripe令牌。我不确定该怎么做。我已经看到了使用AJAX的自定义提交按钮,但是不确定是否需要这样做。提前致谢!
这是我的HTML:
<?php if (isset($_POST['cart_errors'])) : ?>
<div class="thank-you"><?=$_POST['cart_errors']?></div>
<?php endif // errors ?>
这是JS
var stripeResponseHandler = function(status, response) {
var $form = $('#cart-payment-form');
console.log(response);
if (response.error) {
// Show the errors on the form
$form.find('.payment-errors').text(response.error.message);
$form.find('button').prop('disabled', false);
} else {
// token contains id, last4, and card type
var token = response.id;
// Insert the token into the form so it gets submitted to the server
$form.append($('<input type="hidden" name="stripeToken" />').val(token));
// and submit
$form.get(0).submit();
}
};
$('#cart-payment-form').submit(function(event) {
var $form = $(this);
// Disable the submit button to prevent repeated clicks
$form.find('button').prop('disabled', true);
Stripe.card.createToken($form, stripeResponseHandler);
// Prevent the form from submitting with the default action
return false;
});
$('#thank-you').dialog({
height: 140,
modal: true
});
这是我的PHP:
$cart_stripe_secret_key = get_option("cart_stripe_secret_key");
Stripe::setApiKey($cart_stripe_secret_key);
$token = $_POST['stripeToken'];
try
{
$charge = Stripe_Charge::create(array(
"amount" => $totalCharge*100, // amount in cents, again
"currency" => "usd",
"card" => $token,
"description" => $_POST['surgecart_email']
));
}
catch(Stripe_CardError $e)
{
$_POST['cart_errors'] = "Whoops! There was a problem with your card. Try again?";
return FALSE;
}
$_POST['cart_errors'] = "Thank you for your order!";
我强烈建议使用使用模式和Ajax地址查找的Stripe Checkout。为了获得成功的回报,您可以使用引导程序模式http://getbootstrap.com/javascript/。
在成功完成交易后您重定向到的任何页面中,都包含模式代码,但将自动弹出窗口保留在php中如果在正确的情况下回显了“激活模式” js。像这样:
<?php
if($stripe_response()){
echo "<script type='text/javascript'>
$(window).load(function(){
$('#myModal').modal({
show: true});
});
</script>";
}
?>
此外,您可以在if()中添加成功或拒绝的消息传递。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句