codeigniter 上的贝宝支付

PayPal Payment on codeigniter

使用 PayPal 付款成功。但是,我发现很难 return 交易 ID 以及支付给我的控制器的金额。

这是我的贝宝代码。

<script>
        // Render the PayPal button into #paypal-button-container
        paypal.Buttons({
    // Configure environment
            env: 'sandbox',
                client: {
                    sandbox: 'AZE8rjV6EqzKFAcEx6f7L7ZZwDsSLR5bBQOQN5pj3gAwghAivl0VUt-e0SkETWrcoesYXGbxO292vYZ3',
                    production: 'AUO3T8Mto5rojZl9Ff6nuYw1cLFjgF-4TPh6v1FhXyNdQsjxvdLTACn3xlv3EqwvPLJmmozl4_1pufFl'
                },

                // Set up the transaction
                createOrder: function(data, actions) {
                    var amount = $("#amount").val();
                    var name = '<?php echo($email); ?>';

                        return actions.order.create({
              redirect_urls:{
                   return_url:'http://localhost/escort/success'
              },
                                purchase_units: [{
                                        amount: {
                                                value: amount,
                                                currency: 'USD'
                                        }
                                }]
                        });
                },

                // Finalize the transaction
                onApprove: function(data, actions) {

                    return actions.request.post('Home/AddPayment/', {
                    paymentID: data.paymentID,
                    payerID:   data.payerID,
                    email: email,
                    amount: amount
                        })
                        .then(function(response) {
          // 3. Show the buyer a confirmation message.
                    if (response.error == 'false') {
                        console.log('Payment Completed');
                    }
                    else{
                        console.log('Error');
                    }
        });
                }                       

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

我的问题很简单。我需要想办法在确认付款后将交易 ID 和金额发送给控制器。

在 onApprove 函数中这样做。您似乎已经发布了付款 ID 和金额,但如果您想先获取,则需要 actions.order.capture()。请参阅 https://developer.paypal.com/demo/checkout/#/pattern/client

处的演示模式

更好的服务器端设计是让 onApprove 函数调用服务器端点,该端点执行服务器端 API 调用以捕获事务。请参阅 https://developer.paypal.com/demo/checkout/#/pattern/server

处的演示模式