问题
UPDATE: Issue applies to both TEST and LIVE API Requests
At first I thought this was a Test Environment bug but I've confirms it applies to production as well. It's critical to know Fees Charged By PayPal
.
Is there a way to get the Paypal Test environment (developer.paypal.com) to respond with fees charged by PayPal? Neither a Sale
or a Sale Lookup
seem to return the Paypal Fee
seen in live transactions. Are we forced to test with live transactions (not a best practice)? Without the same fee values you see in the live environment, its hard to unit test our accounting system in development.
Request - Credit Card Charge ($43) with Stored Card
$cardToken = new CreditCardToken();
$cardToken->setCredit_card_id( $cc->getRefid() );
$fi = new FundingInstrument();
$fi->setCredit_card_token( $cardToken );
$payer = new Payer();
$payer->setPayment_method('credit_card');
$payer->setFunding_instruments(array($fi));
$amount = new Amount();
$amount->setCurrency('USD');
$amount->setTotal('43.00');
$transaction = new Transaction();
$transaction->setAmount($amount);
$transaction->setDescription($note);
$payment = new Payment();
$payment->setIntent('sale');
$payment->setPayer($payer);
$payment->setTransactions(array($transaction));
$response = $payment->create();
Response - Approved (full response)
PayPal\Api\Transaction Object
(
[_propMap:PPModel:private] => Array
(
[amount] => PayPal\Api\Amount Object
(
[_propMap:PPModel:private] => Array
(
[total] => 43.00
[currency] => USD
[details] => PayPal\Api\AmountDetails Object
(
[_propMap:PPModel:private] => Array
(
[subtotal] => 43.00
)
)
)
)
Documentation - Fee Charged By PayPal
(Below Image) - details object from the documentation showing a (string) fee charged by PayPal
- Which doesn't seem to expose itself in the test environment.

回答1:
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.
回答2:
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.
回答3:
Looks like it's known bug that will be fixed. Don't have the date yet.
来源:https://stackoverflow.com/questions/16347904/paypal-rest-api-bug-fee-charged-by-paypal-not-set-in-response