【问题标题】:Stripe.js won't charge with AJAX SubmitStripe.js 不会对 AJAX 提交收费
【发布时间】:2014-07-06 20:39:42
【问题描述】:

我一直在为此挠头。我的 Stripe 不会收费。我尝试使用站变量在服务器上运行 PHP 并且它们有效;问题似乎出在服务器和我的 ajax 之间。

这是我的 HTML 和 JavaScript 代码:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, target-densitydpi=medium-dpi, user-scalable=0" />
<meta http-equiv="Access-Control-Allow-Origin" content="*">
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="https://checkout.stripe.com/checkout.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#sendPledgeBtn').click(function(){
      var token = function(res){
        var $input = $('<input type=hidden name=stripeToken />').val(res.id);
        var tokenId = $input.val();
        var email = res.email;

        setTimeout(function(){
          $.ajax({
            url:'http://www.webdrumbeat.com/snoopcaller/stripe/charg.php',
            cache: false,
            data:{ email : email, token:tokenId },
            type:'POST'
          })
          .done(function(data){
            // If Payment Success 
            $('#sendPledgeBtn').html('Thank You').addClass('disabled');
          })
          .error(function(){
            $('#sendPledgeBtn').html('Error, Unable to Process Payment').addClass('disabled');
          });
        },500);

        $('form:first-child').append($input).submit();
      };

      StripeCheckout.open({
        key:         'pk_test_X41GM5cT9TejICAXyx77Gviy', // Your Key
        address:     false,
        amount:      1000,
        currency:    'usd',
        name:        'Canted Pictures',
        description: 'Donation',
        panelLabel:  'Checkout',
        token:       token
      });
      return false;
});
});
</script>
</head>

<body>
<form action="" method="POST">
<button id="sendPledgeBtn">Buy</button>

</form>
</body>
</html>

PHP:

<?php
require_once(dirname(__FILE__) . '/config.php');

$token = $_POST['stripeToken'];
$email = $_POST['email'];

$customer = Stripe_Customer::create(array(
'email' => $email,
'card' => $token
));

$charge = Stripe_Charge::create(array(
'customer' => $customer->id,
'amount' => 5000,
'currency' => 'usd'
));

echo '<h1>Successfully charged $5!</h1>';
?>

【问题讨论】:

  • 5000 便士 = 50 美元而不是 5 美元

标签: php jquery ajax stripe-payments


【解决方案1】:

我怀疑url:'http://www.webdrumbeat.com/snoopcaller/stripe/charg.php', 应该是url:'http://www.webdrumbeat.com/snoopcaller/stripe/charge.php', 它缺少'e'。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-15
    • 1970-01-01
    • 2019-02-06
    • 1970-01-01
    • 2012-09-23
    • 2017-05-11
    • 2014-03-30
    • 2013-07-09
    相关资源
    最近更新 更多