dongxiqian2787 2017-02-09 11:09
浏览 74
已采纳

Express Checkout Payment即使在成功执行后也会返回空的相关资源

EDIT:

As @bluepnume stated probably this is a bug and would be fixed later.

In my case I did the same thing (create payment / execute payment) but on server side with the REST API without using checkout.js and now everything works fine.

The only difference is that I'm redirecting the client to PayPal (with $payment->getApprovalLink()) instead of using the on-site lightbox generated by checkout.js.

Original question:

I integrated PayPal Express Checkout with a Basic Client Integration.

Everything seems fine. The payment completes smoothly and I can view the payment as completed/approved from both Rest API request and Seller's Account (Sandbox).

However the payment is not completed even after successful Execute. I try to make a refund from the API after order cancellation but after reading Payment data successfully I can't receive and Related Resources in payment's transactions.

JS code (works fine):

paypal.Button.render({
    env: $form.find('[name="env"]').val(),
    client: {
        sandbox:    $form.find('[name="client_id"]').val(),
        production: $form.find('[name="client_id"]').val()
    },
    locale: 'it_IT',
    commit: true, // Optional: show a 'Pay Now' button in the checkout flow
    payment: function() {
        var env    = this.props.env;
        var client = this.props.client;
        return paypal.rest.payment.create(env, client, {
            transactions: [
                {
                    custom: $form.find('[name="custom"]').val(),
                    amount: {
                        total: $form.find('[name="subtotal"]').val(),
                        currency: $form.find('[name="currency_code"]').val()
                    },
                    description: $form.find('[name="item_name"]').val(),
                }
            ],
            redirect_urls: {
                "return_url": $form.find('[name="return"]').val(),
                "cancel_url": $form.find('[name="notify_url"]').val()
            }
        });
    },
    onAuthorize: function(data, actions) {
        return actions.payment.execute().then(function() {
            actions.payment.get().then(function(data) {
                pjQ.$.post($form.find('[name="notify_url"]').val(), data).done(function (data) {
                    return actions.redirect();
                });
            });
        });
    },
    onCancel: function(data, actions) {
        return actions.redirect();
    }
}, '#paypal-button');

PHP code:

$payment = \PayPal\Api\Payment::get($paymentId, $apiContext); // It's ok
$transactions = $payment->getTransactions(); // It's ok
$relatedResources = $transactions[0]->getRelatedResources(); // Empty...

// I can't use the code below as $relatedResources is empty
$sale = $relatedResources[0]->getSale();
$saleId = $sale->getId();

$sale = new \PayPal\Api\Sale();
$sale->setId($saleId);

$refundedSale = $sale->refundSale($refundRequest, $apiContext);

Any ideas?

  • 写回答

1条回答 默认 最新

  • doufuxi7093 2017-02-09 17:47
    关注

    That's a known issue, and a fix is going out soon. See https://github.com/paypal/paypal-checkout/issues/143.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 删除虚拟显示器驱动 删除所有 Xorg 配置文件 删除显示器缓存文件 重启系统 可是依旧无法退出虚拟显示器
  • ¥15 vscode程序一直报同样的错,如何解决?
  • ¥15 关于使用unity中遇到的问题
  • ¥15 开放世界如何写线性关卡的用例(类似原神)
  • ¥15 关于并联谐振电磁感应加热
  • ¥60 请查询全国几个煤炭大省近十年的煤炭铁路及公路的货物周转量
  • ¥15 请帮我看看我这道c语言题到底漏了哪种情况吧!
  • ¥66 如何制作支付宝扫码跳转到发红包界面
  • ¥15 pnpm 下载element-plus
  • ¥15 解决编写PyDracula时遇到的问题