i’m creating app that integrates Angular 8 and NodeJS as orderer for paypal. I’m wondering how to get all items that i send to transaction. For example this is my createOrder object:
request.requestBody({
intent: 'CAPTURE',
purchase_units: [{
amount: {
value: '7',
currency_code: 'USD',
breakdown: {
item_total: {value: '7', currency_code: 'USD'}
}
},
invoice_id: 'muesli_invoice_id',
items: [{
name: 'Hafer',
unit_amount: {value: '3', currency_code: 'USD'},
quantity: '1',
sku: 'haf001'
}, {
name: 'Discount',
unit_amount: {value: '4', currency_code: 'USD'},
quantity: '1',
sku: 'dsc002'
}]
}]
});
But when i’m trying to capture this transaction on my server:
const paymentId = req.body['paymentID'];
const request = new paypal.orders.OrdersCaptureRequest(paymentId);
request.requestBody({});
// Call API with your client and get a response for your call
let response = await payPalClient.execute(request);
res.send(response);
I’m not getting items list, just this basic informations from paypal (shipping address etc.)
What is the problem here? What have I got to change when i want to get this items list back?
EDIT:
statusCode: 201
headers:
cache-control: "max-age=0, no-cache, no-store, must-revalidate"
content-length: "1500"
content-type: "application/json"
date: "Mon, 16 Mar 2020 12:10:51 GMT"
paypal-debug-id: "c82e286689b67"
connection: "close"
__proto__: Object
result:
id: "64L22722PN8615907"
purchase_units: Array(1)
0:
reference_id: "default"
shipping:
name:
full_name: "John Doe"
__proto__: Object
address:
address_line_1: "Bajkowa 2 / 5"
address_line_2: "Case postale 12"
admin_area_2: "Warszawa"
admin_area_1: "PL_zip = 00800"
postal_code: "00800"
country_code: "PL"
__proto__: Object
__proto__: Object
payments:
captures: Array(1)
0:
id: "1XE85118J8824304V"
status: "COMPLETED"
amount:
currency_code: "USD"
value: "7.00"
__proto__: Object
final_capture: true
seller_protection:
status: "ELIGIBLE"
dispute_categories: (2) ["ITEM_NOT_RECEIVED", "UNAUTHORIZED_TRANSACTION"]
__proto__: Object
seller_receivable_breakdown:
gross_amount: {currency_code: "USD", value: "7.00"}
paypal_fee: {currency_code: "USD", value: "0.50"}
net_amount: {currency_code: "USD", value: "6.50"}
__proto__: Object
invoice_id: "muesli_invoice_id"
links: (3) [{…}, {…}, {…}]
create_time: "2020-03-16T12:10:50Z"
update_time: "2020-03-16T12:10:50Z"
__proto__: Object
length: 1
__proto__: Array(0)
__proto__: Object
__proto__: Object
length: 1
__proto__: Array(0)
payer:
name:
given_name: "John"
surname: "Doe"
__proto__: Object
email_address: "[email protected]"
payer_id: "Z95Z7FJLRFVBS"
address: {country_code: "PL"}
__proto__: Object
links: Array(1)
0:
href: "https://api.sandbox.paypal.com/v2/checkout/orders/64L22722PN8615907"
rel: "self"
method: "GET"
__proto__: Object
length: 1
__proto__: Array(0)
status: "COMPLETED"
Here is my whole response in json format
2
Answers
Ok, solution is simple. Server capture route should look like this:
We should use
let requestDetails = new paypal.orders.OrdersGetRequest(paymentId);
instead ofconst request = new paypal.orders.OrdersCaptureRequest(paymentId);
Remember to capture request after seing all its details. Whole request should look like this :
There isn’t a way. The capture response does not include the line item details.
From what I can tell, using the v2/payments API to get the details of the captured payment (1XE85118J8824304V in your example) may also not return the line item details — although you can test and confirm.
Unless, maybe, you send the line item details in your capture API call close to where you are actually trying to get them back in your question. That is to say, add and send them in again here at capture time:
Then, maybe, it would be possible to get them back in a later payment details call.
But basically you need to keep track of this information yourself.
On an unrelated note,
The value of invoice_id should always be a uniquely generated value, never before used on that account for a successfully-captured payment. Here it seems you’re re-using the same string, which is a no-no.