当我在条带中添加费用时显示错误

时间:2019-03-01 12:03:31

标签: stripe-payments

我正在处理数据条,并且在我收取金额时出现错误 我正在使用的代码是

 <button id="customButton" class="submit_btn">Make Appointment</button>
                    <script src="https://checkout.stripe.com/checkout.js"></script>
                    <input type="hidden" id="stripeToken" name="stripeToken" />
                    <script>
                       var handler = StripeCheckout.configure({
                            key: 'TOKEN',
                            image: 'https://stripe.com/img/documentation/checkout/marketplace.png',
                            locale: 'auto',
                            token: function(token) {
                                jQuery(function ($) {
                                    console.log("testing12");
                                   var value =  $('#stripeToken').val(token.id);
                                   console.log(value);

                                });
                            }
                        });
                        jQuery(function ($) {
                            document.getElementById('customButton').addEventListener('click', function (e) {
                                var amount =  0;
                                $('input:checkbox:checked').each(function(){
                                    amount  += isNaN(parseInt($(this).val())) ? 0 : parseInt($(this).val());
                                    $('#total').text(amount);
                                });
                                handler.open({
                                    name: 'Sports Solution',
                                    description: '',
                                    amount: amount
                                });
                                e.preventDefault();
                            });
                            <?php
                            \Stripe\Stripe::setApiKey("sk_test TOTEN");
                                $token = $_POST['stripeToken'];
                                var_dump($token);
                            $charge = \Stripe\Charge::create([
                                'amount' => 999,
                                'currency' => 'usd',
                                'description' => 'Example charge',
                                'source' => $token,
                            ]);
                            ?>
                        });
                        // Close Checkout on page navigation:
                        window.addEventListener('popstate', function() {
                            handler.close();
                        });
                    </script>

错误正在变得越来越像这样显示在条纹上 {   “错误”:{     “ code”:“ parameter_missing”,     “ doc_url”:“ https://stripe.com/docs/error-codes/parameter-missing”,     “ message”:“必须提供来源或客户。”,     “ type”:“ invalid_request_error”   } }

1 个答案:

答案 0 :(得分:0)

创建费用之前,您必须先添加客户

$token = $_POST['stripeToken'];

$customer = \Stripe\Customer::create([
"email" => $email,
"source" => $token,
]);


$charge = \Stripe\Charge::create([
"amount" => 500,
"currency" => "usd",
'description'=> '5',
"customer" => $customer->id,
]);