Paypal REST API Bug - Fee Charged By PayPal NOT SET in Response

99封情书 提交于 2019-12-03 17:34:22

Use the NVP API (GetTransactionDetails request) to return more accurate details in place of or along side the standard REST Responses. If you're interested I can post a PHP Example.

The REST API allows you to do things like manage a Credit Card vault.. so you can store a card and charge a card with the REST .. but when I charge it, I return the NVP API GetTransactionDetails response which includes Fees Charged By Paypal and everything else you need to know about the transaction that was charged via REST. It maybe be a hack and involve an extra API call but it works really well.

This is now available on the REST api. Specifically, via the transaction_fee on the sale object.

You can also access transaction_fee from a payment object by drilling down. Here's a (slightly redacted) example response:

{
  "id": "PAY-5YK922393D847794YKER7MUI",
  "state": "approved",
  "intent": "sale",
  "payer": {...},
  "transactions": [
    {
      "related_resources": [
        {
          "sale": {
            "id": "36C38912MN9658832",
            "state": "completed",
            "amount": {
              "total": "7.47",
              "currency": "USD"
            },
            "transaction_fee": {
              "value": "1.75",
              "currency": "USD"
            }
          }
        }
      ]
    }
  ]
}

For those following along at home, you can get the value of the transaction fee on this payment with the following simple and intuitive line of code:

payment.transactions[0].related_resources[0].sale.transaction_fee.value

See? Easy. Oh, but just remember - the sale object will not exist until after the payment has been executed.

Here's a massive ticket on the Ruby SDK about how this feature was added, if you want some light reading.

Looks like it's known bug that will be fixed. Don't have the date yet.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!