【问题标题】:Grab transaction ID back from PayPal SDK从 PayPal SDK 获取交易 ID
【发布时间】:2020-10-14 10:24:46
【问题描述】:

我试图弄清楚如何获取使用 PayPal SDK 进行的付款的交易 ID。这是我的 JS 中的内容:

paypal.Buttons({

  createOrder: function(data, actions) {

    return actions.order.create({
        purchase_units: [{
            amount: {
                    value:    parseFloat( window.my_config.amount ),
                    currency: 'USD',
            },
            description: window.my_config.description
        }],
        commit: true
      });
  },


  onApprove: function(data, actions) {

    console.dir({ data: data, actions:actions });

    return actions.order.capture().then(function(details) {

        console.log({ details: details });

        // This function shows a transaction success message to your buyer.
        alert('Transaction completed by ' + details.payer.name.given_name);

      });

    $('#AJAXloadingWrapper').show();

  }


}).render('#paypalWrapper');

这是我的调试返回的结果:

我在任何地方都看不到交易 ID。应该是 7CA44490MT363621L(通过我的 PayPal 帐户中的 transid)

如何获得它?在我以前使用的旧系统中:

curl https://api.paypal.com/v1/payments/payment/L8EM97CXSYBJ2 -H "Content-Type: application/json" -H "Authorization: Bearer tokenstring"

但这不起作用。我尝试将其更改为 v2:

curl https://api.paypal.com/v2/payments/payment/L8EM97CXSYBJ2 -H "Content-Type: application/json" -H "Authorization: Bearer xxxx"

...但我得到的回应是什么都没有(没有错误,但没有输出)

我尝试过一些基于:

https://developer.paypal.com/docs/checkout/reference/server-integration/get-transaction/#on-the-server

sub get_proper_trans_id {
    my $token = encode_base64(qq|$config->{$config->{mode}}->{system_client_id}:$config->{$config->{mode}}->system_secret}|);
       $token =~ s/\n//g;
    my $trans_id = '50D311011N3466050';

    print qq|curl https://$config->{$config->{mode}}->{transaction_endpoint}/v2/payments/payment/$trans_id -H "Content-Type: application/json" -H "Authorization: Bearer $token"\n|;

    my $results = `curl https://$config->{$config->{mode}}->{transaction_endpoint}/v2/payments/payment/$trans_id -H "Content-Type: application/json" -H "Authorization: Bearer $token"`;
    my $json_vals = decode_json($results);

    use Data::Dumper;
    print Dumper($json_vals);
}

什么都不输出(也没有错误)

更新: 正如建议的那样,我正在尝试使用输出结果中的purchase_units -> payments -> captures -> id。问题是这似乎是错误的/与我所期望的不同。当我登录我的 PayPal 时,我得到:

0NP90326GE709501L

然而返回数据中的值是:

891170207E054363D

为什么这些不同? FWIW 我正在我的个人 PayPal 帐户(而不是它发送到的企业)中查看这个。不过,商家和客户的 trans ID 应该是相同的吧?

更新 2: 毕竟,我发现一个帖子说 PayPal 故意为买家和卖家提供不同的交易 ID。什么皮塔饼。所以另一种方法是传入一个自定义的 invoice_id,我们可以与之交叉引用。一切都好——除了我似乎也做不到!

我试过了:

    return actions.order.create({
        purchase_units: [{
            amount: {
                    value:    parseFloat( window.my_config.amount ),
                    currency: 'USD',
            },
            description: window.my_config.description,
        }],
        invoice_id: invoice_id,
        commit: true
      });
  },

还有:

    return actions.order.create({
        purchase_units: [{
            amount: {
                    value:    parseFloat( window.my_config.amount ),
                    currency: 'USD',
            },
            description: window.my_config.description,
            invoice_id: invoice_id
        }],
        commit: true
      });
  },

但是当他们完成付款的过程时,它会返回:

Error: Order could not be captured

..当尝试运行return actions.order.capture().then(function(details) {

更新 3:

我仍然无法让它工作。这是您传递 custom_id 的方式吗?

    return actions.order.create({
        purchase_units: [{
            amount: {
                    value:    parseFloat( window.my_config.amount ),
                    currency: 'USD',
                    custom_id: invoice_id
            },
            description: window.my_config.description
        }],
        commit: true
      });

我在那里试过了,也如下 commit: true,但还是不行:((确认付款后“订单无法被捕获”)

【问题讨论】:

    标签: paypal paypal-rest-sdk


    【解决方案1】:

    它在 purchase_units -> 付款 -> 捕获 -> id

    https://developer.paypal.com/docs/api/orders/v2/#orders-capture-response查看示例回复


    一旦知道了 id,就没有理由需要对相同的数据执行单独的 GET 请求,但如果您这样做了,API 调用将是:

    https://developer.paypal.com/docs/api/payments/v2/#captures_get

    【讨论】:

    • 谢谢。在我的测试中给了我 9TE07281A3828142S,但是当我在 PayPal 上查看它时,transid 是:paypal.com/activity/payment/7CA44490MT363621L
    • 我在上面添加了更多细节。反式 ID 似乎仍然与我的预期不符。商家和客户应该都有相同的交易ID,不是吗?
    • 哦,有趣,我刚刚发现:stackoverflow.com/questions/18711131/…。因此,事实证明 PayPal 故意为买家和卖家提供不同的 ID。什么皮塔饼!为什么我们不能只获取买家 ID?我想将此包含在我给客户的电子邮件中以进行购买:/
    • 我看过了,似乎唯一的解决方法是包含自定义发票 ID。问题是,当我尝试传递 invoice_id / custom_id 时,我收到“无法捕获订单”错误:(
    • invoice_id 必须是唯一的,以前从未在收款帐户上使用过。 custom_id 可以是任何东西
    猜你喜欢
    • 2014-05-11
    • 2014-11-09
    • 1970-01-01
    • 2019-12-21
    • 2018-12-20
    • 2015-11-06
    • 2012-01-26
    • 2014-04-29
    • 2021-05-30
    相关资源
    最近更新 更多