【问题标题】:when i add charge in stripe it show error当我在条纹中添加费用时,它显示错误
【发布时间】:2019-03-01 12:03:30
【问题描述】:

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

 <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>

出现的错误在条纹上可见,就像它显示的那样 { “错误”: { “代码”:“参数缺失”, "doc_url": "https://stripe.com/docs/error-codes/parameter-missing", "message": "必须提供来源或客户。", “类型”:“invalid_request_error” } }

【问题讨论】:

  • 'source' =&gt; $token, 传入的值应该是以tok_ 开头的字符串。您能否检查以确认您在那里获得了正确的 $token 值?

标签: stripe-payments


【解决方案1】:

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

$token = $_POST['stripeToken'];

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


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

【讨论】:

  • 它向我显示此错误 { "error": { "code": "missing", "doc_url": "stripe.com/docs/error-codes/missing", "message": "无法向没有活动的客户收费卡”,“参数”:“卡”,“类型”:“卡错误”}}
  • 你使用什么凭证,在测试账户中你可以使用 4242424242424242 作为卡号和 cvv 123
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-12-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-19
相关资源
最近更新 更多