为Stripe Checkout创建模式成功通知

特恩茨

我正在尝试使条码结帐的成功更好一些,然后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] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

为Stripe创建Mock还是在Stripe对象上使用存根?

来自分类Dev

为变量中的模式创建模式规则?

来自分类Dev

如何使用Vue Stripe Checkout库为信用卡信息创建离散输入?

来自分类Dev

为 Stripe::Error 创建 Error 对象(Ruby on rails)

来自分类Dev

Rails with Stripe Checkout:如何为我的数据库注入样本费用,并使用Stripe Checkout为每次费用生成令牌?

来自分类Dev

git - 为删除的文件创建模式 100644

来自分类Dev

Stripe Checkout 和客户创建

来自分类Dev

创建模式为顺序模式时,ZooKeeper中的监视程序不会触发事件

来自分类Dev

Stripe Connect - 为多个目的地费用创建多个代币

来自分类Dev

为必须以 3 个字母开头的数字创建模式,例如 (IKA111111)

来自分类Dev

DataGrid 编辑/创建模式下的下拉框为空

来自分类Dev

为全局创建模拟

来自分类Dev

将 SQL 模式建模为 DynamoDB

来自分类Dev

如何在MATLAB中创建模式为[1 2 5 6 9 10 13 14 17 18 ....]的向量?

来自分类Dev

Java创建模式

来自分类Dev

Poltergeist Stripe checkout.js

来自分类Dev

完全卡在Stripe Checkout中

来自分类Dev

使用Stripe Checkout添加参数

来自分类Dev

Stripe 订阅成功,卡无效

来自分类Dev

卡未为Stripe客户保存

来自分类Dev

Foreach视频创建模式

来自分类Dev

从数字列表创建模式

来自分类Dev

JS:从 Stripe Checkout 切换到 Stripe Elements

来自分类常见问题

为单元测试创建模拟-改造

来自分类Dev

IntelliJ 13不提示为新项目创建模块

来自分类Dev

如何重新为多个图像创建模态?

来自分类Dev

Bash脚本为新脚本创建模板

来自分类Dev

使用Mockito为扩展通用类的类创建模拟

来自分类Dev

没有为 Django 迁移创建模型表

Related 相关文章

热门标签

归档