Sefam
Sefam

Reputation: 1773

Required Field Missing. PHP Paypal REST API

I'm currently trying to use the PHP PayPal REST API. However, it seems I am unable to pass a list of items through a transaction because "required field(s) are missing".

$item = new Item();
$item->setQuantity("1");
$item->setName("stuff");
$item->setPrice("305.00");
$item->setCurrency("USD");

$amount = new Amount();
$amount->setCurrency("USD");
$amount->setTotal("305.00");

$item_list = new ItemList();
$item_list->setItems(array($item));

$transaction = new Transaction();
$transaction->setAmount($amount);
$transaction->setDescription("This is incredibly awesome.");
$transaction->setItem_list($item_list);

I've filled all the fields that Paypal's documentation deems as "required" as per "Common Objects" in the documentation (https://developer.paypal.com/webapps/developer/docs/api/#common-objects). But I am being thrown this error when I try to redirect to Paypal to start the transaction:

Exception: Got Http response code 400 when accessing https://api.sandbox.paypal.com/v1/payments/payment. string(269) "{"name":"VALIDATION_ERROR","details":[{"field":"transactions[0].item_list.items[0].sku","issue":"Required field missing"}],"message":"Invalid request - see details","information_link":"https://developer.paypal.com/docs/api/#VALIDATION_ERROR","debug_id":"9e292fc3a312d"}"

When I comment out $transaction->setItem_list($item_list);, it works properly. So it's obvious that something is missing in the item list or the item. But I can't see what.

Any ideas?

Upvotes: 2

Views: 3323

Answers (1)

Fabio
Fabio

Reputation: 23480

the error point you to this:

transactions[0].item_list.items[0].sku

This filed seems to be required i think it just need to put sku in item array so let's do it: try to add:

$item->setSKU("CODEHERE");

after

$item->setCurrency("USD");

Upvotes: 5

Related Questions