Javascript 条纹付款赢得';行不通

Javascript 条纹付款赢得';行不通,javascript,php,html,payment,stripe-payments,Javascript,Php,Html,Payment,Stripe Payments,在过去的两周里,我尝试使用Stripe制作一个定制的支付表单,它允许用户自己选择价格,然后在支付后向他们的卡收费。制作“代币”的表单有效,并显示在Stripe仪表板下的我的日志中,但问题是客户信用卡的费用不起作用。我正在通过将脚本上传到一个托管面板来测试脚本,我正在为另一个网站使用脚本,但是在这样做时,我得到了如下错误“InternalServerError”,如下图所示 我不知道错误是什么,我知道错误很可能发生在为卡收费的.php脚本中,因为从html/javascript表单获取“令牌”没

在过去的两周里,我尝试使用Stripe制作一个定制的支付表单,它允许用户自己选择价格,然后在支付后向他们的卡收费。制作“代币”的表单有效,并显示在Stripe仪表板下的我的日志中,但问题是客户信用卡的费用不起作用。我正在通过将脚本上传到一个托管面板来测试脚本,我正在为另一个网站使用脚本,但是在这样做时,我得到了如下错误“InternalServerError”,如下图所示

我不知道错误是什么,我知道错误很可能发生在为卡收费的.php脚本中,因为从html/javascript表单获取“令牌”没有问题

我的脚本html和javascript:

    <!DOCTYPE html>
<html>

<head>

    <!-- STRIPE PAYMENT JAVASCRIPT FUNCTIONS START -->

    <script src="https://checkout.stripe.com/checkout.js"></script>
    <script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
    <script type="text/javascript">
    $(document).ready(function() {    

    var handler = StripeCheckout.configure({
        key: 'REMOVED FOR SAFETY BUT IS THERE IN THE REAL SCRIPT',
        image: '/square-image.png',
        token: function(token) {
            // get the payment form
            var $form = $('#payment-form');

            // Use the token to create the charge with a server-side script.
            // You can access the token ID with `token.id`

            // Insert the token into the form so it gets submitted to the server
            $form.append($('<input type="hidden" name="stripeToken" />').val(token.id));
            // and re-submit
            $form.get(0).submit();
        }
    });

    $('#customButton').on('click', function(e) {

        // get the amount from #amount, round to avoid funny issues
        var amount = Math.round($("#amount").val()*100);

        // Open Checkout with further options
        handler.open({
        name: 'Payment',
        description: 'Payment',
        amount: amount
        });
        e.preventDefault();
    });

      // Close Checkout on page navigation
    $(window).on('popstate', function() {
        handler.close();
    });
    });
    </script>

    <!-- STRIPE PAYMENT JAVASCRIPT FUNCTIONS ENDING -->

</head>

<body>

                <!-- FORM FOR STRIPE PAYMENT START-->

                    <form id="payment-form" action="chargeCard.php" method="POST">
                    <input onkeypress="return isNumberKey(event)" type="text" name="amount" id="amount" />
                    <input type="image"  src="BidButton1.png" id="customButton" value="pay" alt="button"/>
                    </form>

                    <script type="text/javascript">
                        function isNumberKey(evt)
                    {
                    var charCode = (evt.which) ? evt.which : event.keyCode
                    if (charCode > 31 && (charCode < 48 || charCode > 57))
                    return false;

                    return true;
                    }
                    </script>

                 <!--FORM FOR STRIPE PAYMENT ENDING-->


</body>

</html>

$(文档).ready(函数(){
var handler=StripeCheckout.configure({
关键:“出于安全考虑删除了,但在真实脚本中是否存在”,
图像:'/square image.png',
令牌:函数(令牌){
//拿到付款单
var$form=$(“#付款单”);
//使用令牌通过服务器端脚本创建费用。
//您可以使用`token.ID'访问令牌ID`
//将令牌插入表单,以便将其提交到服务器
$form.append($('').val(token.id));
//并重新提交
$form.get(0.submit();
}
});
$('#customButton')。在('单击')上,函数(e){
//从#amount,round中获取金额,以避免出现有趣的问题
var金额=数学整数($(“#金额”).val()*100);
//打开带有更多选项的签出
handler.open({
名称:'付款',
说明:'付款',
金额:金额
});
e、 预防默认值();
});
//关闭页面导航上的签出
$(窗口).on('popstate',function()){
handler.close();
});
});
函数isNumberKey(evt)
{
var charCode=(evt.which)?evt.which:event.keyCode
如果(字符码>31&(字符码<48 | |字符码>57))
返回false;
返回true;
}
我的脚本php称为chargeCard:

    <?php 

    require_once('./init.php');

    // Set your secret key: remember to change this to your live secret key in production
    // See your keys here https://dashboard.stripe.com/account
    \Stripe\Stripe::setApiKey("REMOVED FOR SAFETY");

    // Get the credit card details submitted by the form
    $token = $_POST['stripeToken'];

    // Create the charge on Stripe's servers - this will charge the user's card
    try {
    $charge = \Stripe\Charge::create(array(
    "amount" => $token, // amount in cents, again
    "currency" => "usd",
    "source" => $token,
    "description" => "payinguser@example.com"));

    echo '<script type="text/javascript">addOne();</script>"';

    } catch(\Stripe\Error\Card $e) {
    // The card has been declined
    }

?>

看起来您的
创建
函数和数组很混乱

try {
    $charge = \Stripe\Charge::create(array(
    "amount" => $amount, // amount in cents, again
    "currency" => "usd",
    "source" => $token,
    "description" => "payinguser@example.com"));

    echo '<script type="text/javascript">addOne();</script>';
} catch(\Stripe\Error\Card $e) {
    // The card has been declined
}
试试看{
$charge=\Stripe\charge::创建(数组)(
“amount”=>$amount,//还是以美分为单位的金额
“货币”=>“美元”,
“source”=>$token,
“说明”=>“payinguser@example.com"));
回显“addOne();”;
}捕获(\Stripe\Error\Card$e){
//这张卡被谢绝了
}
更新

这里有三个错误

  • 您的
    echo
    在您的
    Charge::create()中功能
  • 您在
    echo
  • (不是问题的原因)但您将
    文本/javascript的
    放错了位置

  • 您的
    Create
    函数和数组看起来很混乱

    try {
        $charge = \Stripe\Charge::create(array(
        "amount" => $amount, // amount in cents, again
        "currency" => "usd",
        "source" => $token,
        "description" => "payinguser@example.com"));
    
        echo '<script type="text/javascript">addOne();</script>';
    } catch(\Stripe\Error\Card $e) {
        // The card has been declined
    }
    
    试试看{
    $charge=\Stripe\charge::创建(数组)(
    “amount”=>$amount,//还是以美分为单位的金额
    “货币”=>“美元”,
    “source”=>$token,
    “说明”=>“payinguser@example.com"));
    回显“addOne();”;
    }捕获(\Stripe\Error\Card$e){
    //这张卡被谢绝了
    }
    
    更新

    这里有三个错误

  • 您的
    echo
    在您的
    Charge::create();
    函数中
  • 您在
    echo
  • (不是问题的原因)但您将
    文本/javascript的
    放错了位置

  • 您的
    Create
    函数和数组看起来很混乱

    try {
        $charge = \Stripe\Charge::create(array(
        "amount" => $amount, // amount in cents, again
        "currency" => "usd",
        "source" => $token,
        "description" => "payinguser@example.com"));
    
        echo '<script type="text/javascript">addOne();</script>';
    } catch(\Stripe\Error\Card $e) {
        // The card has been declined
    }
    
    试试看{
    $charge=\Stripe\charge::创建(数组)(
    “amount”=>$amount,//还是以美分为单位的金额
    “货币”=>“美元”,
    “source”=>$token,
    “说明”=>“payinguser@example.com"));
    回显“addOne();”;
    }捕获(\Stripe\Error\Card$e){
    //这张卡被谢绝了
    }
    
    更新

    这里有三个错误

  • 您的
    echo
    在您的
    Charge::create()中功能
  • 您在
    echo
  • (不是问题的原因)但您将
    文本/javascript的
    放错了位置

  • 您的
    Create
    函数和数组看起来很混乱

    try {
        $charge = \Stripe\Charge::create(array(
        "amount" => $amount, // amount in cents, again
        "currency" => "usd",
        "source" => $token,
        "description" => "payinguser@example.com"));
    
        echo '<script type="text/javascript">addOne();</script>';
    } catch(\Stripe\Error\Card $e) {
        // The card has been declined
    }
    
    试试看{
    $charge=\Stripe\charge::创建(数组)(
    “amount”=>$amount,//还是以美分为单位的金额
    “货币”=>“美元”,
    “source”=>$token,
    “说明”=>“payinguser@example.com"));
    回显“addOne();”;
    }捕获(\Stripe\Error\Card$e){
    //这张卡被谢绝了
    }
    
    更新

    这里有三个错误

  • 您的
    echo
    在您的
    Charge::create();
    函数中
  • 您在
    echo
  • (不是问题的原因)但您将
    文本/javascript的
    放错了位置

  • 您正在传递金额字段中的令牌!下面是您的代码

    $charge = \Stripe\Charge::create(array(
        "amount" => $token, // amount in cents, again
        "currency" => "usd",
        "source" => $token,
        "description" => "payinguser@example.com"));
    

    您正在传递金额字段中的令牌!下面是您的代码

    $charge = \Stripe\Charge::create(array(
        "amount" => $token, // amount in cents, again
        "currency" => "usd",
        "source" => $token,
        "description" => "payinguser@example.com"));
    

    您正在传递金额字段中的令牌!下面是您的代码

    $charge = \Stripe\Charge::create(array(
        "amount" => $token, // amount in cents, again
        "currency" => "usd",
        "source" => $token,
        "description" => "payinguser@example.com"));
    

    您正在传递金额字段中的令牌!下面是您的代码

    $charge = \Stripe\Charge::create(array(
        "amount" => $token, // amount in cents, again
        "currency" => "usd",
        "source" => $token,
        "description" => "payinguser@example.com"));
    

    您应该检查您的apache错误日志,因为它是500个内部错误。它将被记录下来(除非您有意使所有错误日志静音),不是吗
    formElement.submit()
    ?无需
    。获取(0)
    。您应该使用AJAX,否则页面将提交给您的
    ,因此我