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 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程