stripe.handleCardPayment意图秘密的值无效

我正在尝试实施直接付款的条纹付款方式

在文档页面上可以看到

https://stripe.com/docs/connect/direct-charges

我要做的是从GitHub提取一个现有代码,该代码实现了付款目的,但不直接收费。

请在这里查看

  https://github.com/fujahgabriel/stripepaymentintent/blob/master/index.html

JavaScript

<script>

        // Stripe API Key
        var stripe = Stripe('#############');
        // clientSecret to complete payment
        var clientSecret;

        // paymentIntent id --- using to update
        var paymentIntent;

        var amount = 10000; //i.e 20GBP

        // create initial payment intent,get client secret
        $.getJSON("intent.php",{
            "amount": amount
        },function(data) {
            clientSecret = data.client_secret;
            paymentIntent = data.id;
        });

        // set up stripe.js
        var elements = stripe.elements();
        // Custom Styling
        var style = {
            base: {
                color: '#32325d',lineHeight: '24px',fontFamily: '"Helvetica Neue",Helvetica,sans-serif',fontSmoothing: 'antialiased',fontSize: '16px','::placeholder': {
                    color: '#aab7c4'
                }
            },invalid: {
                color: '#fa755a',iconColor: '#fa755a'
            }
        };
        // Create an instance of the card Element
        var card = elements.create('card',{
            hidePostalCode: true,style: style
        });
        // Add an instance of the card Element into the `card-element` <div>
        card.mount('#card-element');
        // Handle real-time validation errors from the card Element.
        card.addEventListener('change',function(event) {
            var displayError = document.getElementById('card-errors');
            if (event.error) {
                displayError.textContent = event.error.message;
            } else {
                displayError.textContent = '';
            }
        });
        // on button click
        $("#cbutton").on('click',function(ev) {
            $(this).prop("disabled",true);
            $('#process').show();
            stripe.handleCardPayment(
                clientSecret,card).then(function(result) {
                if (result.error) {
                    // Display error.message in your UI.
                    $("#card-errors").text(result.error.message);
                    // Re-enable button
                    $('#process').hide();

                    $("#cbutton").removeAttr("disabled");
                    console.log(result.error);
                } else {
                    $('#process').hide();

                    alert('success');
                    location.reload();
                    // The payment has succeeded. Display a success message.
                    //console.log(result);
                }
            });
        });
    </script>

然后php,我尝试从

进行调整
$getIntent = \Stripe\PaymentIntent::create([
  "amount" =>$amount,"currency" => "eur","description" => "Test Payment",'payment_method_types' => ['card'],]);
$intent = \Stripe\PaymentIntent::retrieve($getIntent->id);
echo json_encode(["status"=>"ok","id"=>$intent->id,"client_secret"=>$intent->client_secret,"amount"=>$intent->amount,"currency"=>$intent->currency]);

TO

 $getIntent = \Stripe\PaymentIntent::create([
          'payment_method_types' => ['card'],"amount" =>$amount,],['stripe_account' => '#########']);

$intent = \Stripe\PaymentIntent::retrieve($getIntent->id);
echo json_encode(["status"=>"ok","currency"=>$intent->currency]);

但是现在我收到了这个错误

IntegrationError:stripe.handleCardPayment意向密钥的值无效:该值应为client_secret字符串。您指定了:未定义。

请问可能是什么原因,请留在这里

请注意,此解决方案适用于目的地费用,不适用于直接费用

zhangyeah19887 回答:stripe.handleCardPayment意图秘密的值无效

您还没有完成对PHP部分的复制:

getJSON()

(请参阅:https://github.com/fujahgabriel/stripepaymentintent/blob/master/payment_intent.php#L17

现在,您的data.client_secret呼叫未返回任何内容,因此undefined--limit。它没有返回任何内容,因为您从未像上面的代码片段那样回显JSON数据。

本文链接:https://www.f2er.com/3168929.html

大家都在问