duanhuo0577 2014-05-19 00:59
浏览 56

Stripe.js不会收取AJAX提交

I have been scratching my head over this. My Stripe won't charge. I have tried running the PHP on the server using station variables and they worked; the problem seems to be between the server and my ajax.

Here is my HTML and JavaScript code:

<!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>';
?>
  • 写回答

1条回答 默认 最新

  • dongtuo2373 2014-05-20 22:54
    关注

    I suspect that url:'http://www.webdrumbeat.com/snoopcaller/stripe/charg.php', should be url:'http://www.webdrumbeat.com/snoopcaller/stripe/charge.php', its missing the 'e'.

    评论

报告相同问题?

悬赏问题

  • ¥20 关于php中URL传递GET全局变量的问题
  • ¥15 怎么改成循环输入删除(语言-c语言)
  • ¥15 安卓C读取/dev/fastpipe屏幕像素数据
  • ¥15 pyqt5tools安装失败
  • ¥15 mmdetection
  • ¥15 nginx代理报502的错误
  • ¥100 当AWR1843发送完设置的固定帧后,如何使其再发送第一次的帧
  • ¥15 图示五个参数的模型校正是用什么方法做出来的。如何建立其他模型
  • ¥100 描述一下元器件的基本功能,pcba板的基本原理
  • ¥15 STM32无法向设备写入固件