PayPal api trying to find the fee amount deducted from the payment

ripper664
Contributor
Contributor

I'm trying to find the PayPal "fee" deduction attribute of a payment submitted. I don't see this value provided in the response I get from creating the payment. The payment is properly accepted by PayPal, I can see that payment in my account. What I can't find is the "fee" value that's withdrawn from a payment on the response.

I'm using this PayPalButtons React component from "@paypal/react-paypal-js"  to submit those payments (This opens a window to a "https://www.paypal.com/checkoutnow" url) This properly work and processes the provided payment; but the response I receive has no "fee" in the body to say what was taken out from PayPal. I'm super unclear if this is a paypal problem with the response or an issue with this repo not providing that value on said response. I've looked at the payload in the first "then" on the debugger from creating the payment in PayPal; all I can assure anyone is I don't see a fee value there (at the very least obviously).

I'm not trying to grip about on how this is working; I'm just confused about where to pull that necessary info from to store what we actually gained in funds in our system.

Login to Me Too
1 ACCEPTED SOLUTION

Accepted Solutions
Solved

mhelmntrs
Contributor
Contributor
When working with the PayPal REST API and creating payments, the fee information is not typically returned in the response payload directly after creating the payment. The fees associated with a transaction are often available in the transaction details or payment details after the transaction is completed. After you have successfully created a payment using the PayPal REST API, you will receive a response that includes an `id` for the payment. To retrieve detailed information about the payment, including the fees, you will usually need to make a subsequent call to the PayPal API, specifically the "Get Payment Details" endpoint. Here's an example using the PayPal REST API in Javascript: ```javascript const paypal = require('@paypal/checkout-server-sdk'); const clientId = 'your-client-id'; const clientSecret = 'your-client-secret'; const environment = new paypal.core.SandboxEnvironment(clientId, clientSecret); const client = new paypal.core.PayPalHttpClient(environment); const paymentId = 'your-payment-id'; // Replace with the actual payment ID async function getPaymentDetails() { const request = new paypal.orders.OrdersGetRequest(paymentId); try { const response = await client.execute(request); console.log(response.result); } catch (error) { console.error(error); } } getPaymentDetails(); ``` In the response result, you should find information about the fees associated with the transaction. Look for details like `seller_receivable_breakdown` or `seller_receivable_amount`, as these often include information about the transaction amount, fees, and net amount received. Remember to replace `'your-client-id'`, `'your-client-secret'`, and `'your-payment-id'` with your actual PayPal credentials and the payment ID you received after creating the payment. Always refer to the latest PayPal API documentation for the most accurate and up-to-date information on retrieving transaction details, fees, and other relevant information.

View solution in original post

Login to Me Too
2 REPLIES 2
Solved

mhelmntrs
Contributor
Contributor
When working with the PayPal REST API and creating payments, the fee information is not typically returned in the response payload directly after creating the payment. The fees associated with a transaction are often available in the transaction details or payment details after the transaction is completed. After you have successfully created a payment using the PayPal REST API, you will receive a response that includes an `id` for the payment. To retrieve detailed information about the payment, including the fees, you will usually need to make a subsequent call to the PayPal API, specifically the "Get Payment Details" endpoint. Here's an example using the PayPal REST API in Javascript: ```javascript const paypal = require('@paypal/checkout-server-sdk'); const clientId = 'your-client-id'; const clientSecret = 'your-client-secret'; const environment = new paypal.core.SandboxEnvironment(clientId, clientSecret); const client = new paypal.core.PayPalHttpClient(environment); const paymentId = 'your-payment-id'; // Replace with the actual payment ID async function getPaymentDetails() { const request = new paypal.orders.OrdersGetRequest(paymentId); try { const response = await client.execute(request); console.log(response.result); } catch (error) { console.error(error); } } getPaymentDetails(); ``` In the response result, you should find information about the fees associated with the transaction. Look for details like `seller_receivable_breakdown` or `seller_receivable_amount`, as these often include information about the transaction amount, fees, and net amount received. Remember to replace `'your-client-id'`, `'your-client-secret'`, and `'your-payment-id'` with your actual PayPal credentials and the payment ID you received after creating the payment. Always refer to the latest PayPal API documentation for the most accurate and up-to-date information on retrieving transaction details, fees, and other relevant information.
Login to Me Too

ripper664
Contributor
Contributor

Was unaware a subsequent request was needed to PayPal's backend for these details. Was able to add in this second fetch to PayPal's service to load my payment, this response does have the captures field with the payment breakdown!

 

Much Thanks!!

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.