如何使用Stripe PHP API向关联的Stripe帐户收费

时间:2019-11-06 11:45:53

标签: php stripe-payments

我正在尝试学习和实现条纹连接的过程

我已经成功实现了有效的目的地转移

Intent.php

$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]);

现在我正在尝试像这样在此关联帐户中直接进行借记费用

Intent.php

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

$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]);

这样做,我会收到此错误

  

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

这是我在此实现中也正在使用的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>

请问我在尝试直接从已关联的帐户中扣款时可能在做错什么

0 个答案:

没有答案