通过PayPal智能付款按钮完成付款后如何获取orderid

时间:2020-04-29 06:39:27

标签: php codeigniter paypal payment-gateway

我在网站上集成了PayPal Smart付款按钮。我的网站是在PHP codeigniter框架中构建的。 我想知道在成功交易后我是否能得到订单号。

<head>
    <!-- Add meta tags for mobile and IE -->
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
</head>

<body>
    <!-- Set up a container element for the button -->
    <div id="paypal-button-container"></div>

    <!-- Include the PayPal JavaScript SDK -->
    <script src="https://www.paypal.com/sdk/js?client-id=sb&currency=USD"></script>

    <script>
        // Render the PayPal button into #paypal-button-container
        paypal.Buttons({

            // Set up the transaction
            createOrder: function(data, actions) {
                return actions.order.create({
                    purchase_units: [{
                        amount: {
                            value: '0.01'
                        }
                    }]
                });
            },

            // Finalize the transaction
            onApprove: function(data, actions) {
                return actions.order.capture().then(function(details) {
                    // Show a success message to the buyer
                    alert('Transaction completed by ' + details.payer.name.given_name + '!');
                });
            }


        }).render('#paypal-button-container');
    </script>
</body>
`

1 个答案:

答案 0 :(得分:0)

onApprove: function(data, actions) {
                return actions.order.capture().then(function(details) {
                    // Show a success message to the buyer
                    alert('Transaction completed by ' + details.payer.name.given_name + '!');
                });
            }

在此处添加console.log(details);

订单编号在捕获后没有实际实用价值。它仅用于付款批准/捕获过程,之后绝对没有会计价值。

从捕获中得到的付款ID是与PayPal交易相对应的。