简体   繁体   English

标准 PayPal 支付集成不起作用

[英]Standard PayPal payment integration does not work

I am trying to implement on a website standard payment with PayPal and I have some issues when paying with the credit card.我正在尝试使用 PayPal 在网站标准付款上实施,但在使用信用卡付款时遇到了一些问题。 More exactly, after paying, my transaction does not reach the database and my payment does not complete.更准确地说,付款后,我的交易没有到达数据库,我的付款也没有完成。

My code is below:我的代码如下:

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);
                    }
                })
            });

The problem is that, when debugging, my code does not get to the capture() function.问题是,在调试时,我的代码没有到达 capture() function。 So, I manage to add the card details, but when I am paying, nothing happens.所以,我设法添加了卡的详细信息,但是当我付款时,什么也没有发生。 What could be wrong with my code?我的代码可能有什么问题? Can anyone help me with this?谁能帮我这个?

Do not capture on the client side and then send the result to a server.不要在客户端捕获然后将结果发送到服务器。 Switch to a proper server-side integration.切换到适当的服务器端集成。

Create two routes, one for 'Create Order' and one for 'Capture Order', documented here.创建两条路线,一条用于“创建订单”,一条用于“捕获订单”, 记录在此处。 These routes should return/output only JSON data (no HTML or text).这些路由应仅返回/输出 JSON 数据(无 HTML 或文本)。

Pair those two routes with the following approval flow: https://developer.paypal.com/demo/checkout/#/pattern/server将这两条路线与以下批准流程配对: https://developer.paypal.com/demo/checkout/#/pattern/server

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM