How do I get the paypal_fee from the transaction?

JohnnyBurbank
Contributor
Contributor

I'll start by admitting I'm no coding wizard at this stuff, but I'm using the Javascript SDK with Smart Buttons.  In theory should be easy.  After weeks of messing with values I eventually got everything to work exactly as I wanted and have had multiple successful sales go through my Paypal setup. 

 

But NOW I find out that I was calculating the Paypal fees on my side because I read somewhere that said that Paypal fees are an easy calculation and don't change.  This understanding was false, particularly for International sales.  So I think "Ok, I'll just have Paypal return the actual Paypal fee value to me" so I can record it and use it in our calculations for payouts rather than manually calculating them.  Ok, in the documentation I see an object called "seller_receivable_breakdown" that within it has a "paypal_fee" object.  I run through a sale on my site and look at the objects, "payments" great!  "captures" great!  Array 0 entry great! Where's "seller_receivable_breakdown"?  Nowhere to be found...brilliant!

 

Digging a little deeper I see a thing that says some data won't show unless you change the header "Prefer" from the default of "return=minimal" to "return=representation".  Not even sure if this will actually help, but I haven't the first clue where this thing goes.  I've googled for hours and can't find anything remotely close to using this variable with the Javascript Smart Button setup. 

 

There's a reference near the top of my code where I src the javascript code like "https://www.paypal.com/sdk/js".  Is that where I do this?

 

Later, I'm using 

paypal.Buttons({
style: { 

Does it go somewhere around here?

 

Does it go near the  onClick: function(data, actions) {

Near the createOrder area?

createOrder: function(data, actions) {
console.log( "create order" );
return actions.order.create({

 

Near the order.capture?

onApprove: function(data, actions) {
// Capture the funds from the transaction
return actions.order.capture().then(function(details) {

 

Any helpful ideas would be greatly appreciated.  Thanks!

 

Login to Me Too
2 REPLIES 2

GrizzT
Contributor
Contributor

Same here. This post has been up 17 days and no replies from tech support? I mean a YEAR and 17 days!

Login to Me Too

mattinreallife
Contributor
Contributor

You'll need to make a separate request to /v2/checkout/orders/ORDER-ID and then in the response you'll be able to access the fee:

 

purchase_units[0]->payments->captures[0]->seller_receivable_breakdown->paypal_fee->value

Login to Me Too

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.