Im currently implementing the Paypal SDK.
The weird thing is that I copied a paypal request from the docs, looking like:
purchase_units: [
{
"amount": {
"currency": "EUR",
"details": {"subtotal": "1.09", "shipping": "0.02", "tax": "0.33"},
"total": "1.44"
},
"items": [
{
"name": "NeoPhone",
"sku": "sku03",
"price": "0.54",
"currency": "EUR",
"quantity": "1"
},
{
"name": "Fitness Watch",
"sku": "sku04",
"price": "0.55",
"currency": "EUR",
"quantity": "1"
}
],
"shipping_address": {
"line1": "2211 N First Street",
"line2": "Building 17",
"city": "San Jose",
"country_code": "US",
"postal_code": "95131",
"state": "CA",
"phone": "(123) 456-7890"
},
"shipping_method": "United Postal Service",
"invoice_number": "invoice_number_2388",
}
]
The problem is that this JSON triggers three errors, all complaining about Missing required parameters.
{"field":"/purchase_units/@reference_id=='default'/amount/value","value":"","location":"body","issue":"MISSING_REQUIRED_PARAMETER","description":"A required field / parameter is missing."},
{"field":"/purchase_units/@reference_id=='default'/items/0/unit_amount","value":"","location":"body","issue":"MISSING_REQUIRED_PARAMETER","description":"A required field / parameter is missing."},
{"field":"/purchase_units/@reference_id=='default'/items/1/unit_amount","value":"","location":"body","issue":"MISSING_REQUIRED_PARAMETER","description":"A required field / parameter is missing."}
I thought after those errors that he wants me to add a "value"
property to the JSON in item 0,
item 1
& in amount
; but I cant figure out for what it would want this value
attribute. On top Im a little bit confused about the errors hence I copied the code from the PayPal doku.
Does anybody understand my mistake?
That sample is from v1 orders, which was barely ever used and not by the JS SDK, which uses v2 orders. Here's the correct API reference: https://developer.paypal.com/docs/api/orders/v2/#orders_create
You can also start with a simple one from the Integrate Checkout guide:
{
"purchase_units": [{
"amount": {
"currency_code": "USD",
"value": "100",
"breakdown": {
"item_total": { /* Required when including the items array */
"currency_code": "USD",
"value": "100"
}
}
},
"items": [
{
"name": "First Product Name", /* Shows within upper-right dropdown during payment approval */
"description": "Optional descriptive text..", /* Item details will also be in the completed paypal.com transaction view */
"unit_amount": {
"currency_code": "USD",
"value": "50"
},
"quantity": "2"
},
]
}]
}