标准的 PayPal 支付集成不起作用

Standard PayPal payment integration does not work

我正在尝试使用 PayPal 在网站上实施标准付款,但在使用信用卡付款时遇到了一些问题。更确切地说,付款后,我的交易没有到达数据库,我的付款也没有完成。

我的代码如下:

onApprove: function(data, actions) {
            return actions.order.capture().then(function(details) {
                let url = window.location.origin + '/paypal/payment-success';

                let data = {
                    payment_id: details.id,
                    plan_name: details.purchase_units[0].items[0].name,
                    amount: details.purchase_units[0].amount.value,
                    currency_code: details.purchase_units[0].amount.currency_code,
                    status: details.status,
                    payer_email: details.payer.email_address,
                    payer_name: details.payer.name.given_name + ' ' + details.payer.name.surname
                };

                $.ajax({
                    method: "POST",
                    url: url,
                    data: data,
                    dataType: 'JSON',
                    success: function (response) {
                        if(response.url) {
                            window.location.replace(response.url);
                        }
                    },
                    error: function (xhr, ajaxOptions, thrownError) {
                        alert(xhr.status);
                        alert(thrownError);
                    }
                })
            });

问题是,在调试时,我的代码没有到达 capture() 函数。 所以,我设法添加了卡的详细信息,但是当我付款时,没有任何反应。我的代码可能有什么问题? 谁能帮我解决这个问题?

不要在客户端捕获然后将结果发送到服务器。切换到适当的服务器端集成。

创建两条路由,一条用于'Create Order',一条用于'Capture Order',documented here.这些路由应该return/output只有JSON数据(没有HTML 或文字)。

将这两条路线与以下批准流程配对:https://developer.paypal.com/demo/checkout/#/pattern/server