PayPal 智能支付按钮 - 替代支付方式 - 400 错误请求

时间:2021-06-16 21:06:14

标签: paypal

我在我的网站上使用 PayPal 智能支付按钮来获取付款。

订单是通过 PHP 的 PayPal-checkout-sdk 在服务器端创建的。

 $request = new OrdersCreateRequest();
 $request->prefer('return=representation');
 $request->body = self::buildRequestBody($paymentAC);
 // 3. Call PayPal to set up a transaction
 $client = PayPalClient::client();
 $response = $client->execute($request);

请求正文如下所示:

return array(
        'intent' => 'CAPTURE',
        'commit' => true,
        'application_context' =>
            array(
                'brand_name' => 'EXAMPLE INC',
                'locale' => 'de-DE'
                'shipping_preference' => 'NO_SHIPPING'
            ),

        'purchase_units' =>
            array(
                0 =>
                    array(
                        'reference_id' => $rId,
                        'description' => 'Ihr kauf bei EXAMPLE INC',
                        'invoice_id' => $paymentAC,
                        'amount' =>
                            array(
                                'currency_code' => $currency, #EUR
                                'value' => $price,
                                'breakdown' =>
                                    array(
                                        'item_total' =>
                                            array(
                                                'currency_code' => $currency,
                                                'value' => $itemTotal,
                                            ),
                                        'tax_total' =>
                                            array(
                                                'currency_code' => $currency,
                                                'value' => 0,
                                            ),
                                    ),
                            ),
                        'items' => $items,
                    ),
            ),
    );

请求工作正常并创建了一个订单。该脚本返回一个 JSON 对象,其中“id”键设置为所创建订单的 ID。

{"id": "PAYMENTID"}

支付按钮调用脚本如下:

paypal.Buttons({
                                    createOrder: function() {
                                        return fetch('./CreateOrder.php', {
                                            method: 'post',
                                            headers: {
                                                'content-type': 'application/json'
                                            },
                                            body: '{"payment_ac": "<?php echo $_GET['code'] ?>"}'
                                        }).then(function(res) {
                                            console.log(res);
                                            return res.json();
                                        }).then(function(data) {
                                            return data.id; // Use the key sent by your server's response, ex. 'id' or 'token'
                                        });
                                    },
                                    onError: (err) => {
                                        console.error('error from the onError callback', err);
                                    },
                                    onApprove: function(data, actions) {
                                        // This function captures the funds from the transaction.

                                        $("#loadMe").modal({
                                            backdrop: "static", //remove ability to close modal with click
                                            keyboard: false, //remove option to close with keyboard
                                            show: true //Display loader!
                                        });

                                        return actions.order.capture().then(function(details) {
                                            // This function shows a transaction success message to your buyer.
                                            console.log(details);
                                            //window.location.href = "verify.php?id=" + data.orderID + "&ac=<?php echo $internalID ?>";
                                            $.get({
                                                url: "/payment/verify.php?id=" + data.orderID + "&ac=<?php echo $internalID ?>",
                                                success: function (respdata) {
                                                    if (respdata['payment'] === "completed") {
                                                        window.location.href = '/success/<?php echo $internalID?>&cid=' + respdata['cid'];
                                                    } else {
                                                        alert(respdata);
                                                    }
                                                }
                                            })
                                        });
                                    },
                                    onCancel: function (data) {
                                        console.log(data);
                                        alert(data);
                                        // Show a cancel page, or return to cart
                                        window.location.href = "/payment/cancelled.php?ac=<?php echo $internalID ?>&oid=" + data.orderID;
                                    },
                                    style: {
                                        color:   'black',
                                        label:   'pay',
                                        layout: 'vertical'
                                    }
                                }).render('#paypal-button-container');

付款按钮可以成功打开结帐窗口。

当我使用沙箱凭据时,一切正常。 (PayPal、模拟替代支付和信用卡支付)

当我切换到实时凭证时,似乎只有 PayPal 付款有效。您在 https://www.paypal.com/latinumcheckout/error/generic-error

输入详细信息后,每种替代付款方式都会重定向到 https://www.paypal.com/latinumcheckout/change-userinfo

当在开发者控制台有错误输出时:

the server responded with a status of 400 () app.bundle.js:41:140543

信用卡支付似乎也失败了。

我一无所知,我花了很长时间阅读文档,但没有找到解决方案。

0 个答案:

没有答案