Home > Enterprise >  PHP Paypal Checkout SDK V2 -- what are the possible values for "purchase_units"?
PHP Paypal Checkout SDK V2 -- what are the possible values for "purchase_units"?

Time:12-14

We are building a Paypal PHP V2 checkout and the documentation on the github doesn't show what the possible expected data is for the purchase_units. Paypal in their wisdom have also turned off issue tracking.

Github: https://github.com/paypal/Checkout-PHP-SDK

Code exampled by Paypal:

Creating an Order

// Construct a request object and set desired parameters
// Here, OrdersCreateRequest() creates a POST request to /v2/checkout/orders
use PayPalCheckoutSdk\Orders\OrdersCreateRequest;
$request = new OrdersCreateRequest();
$request->prefer('return=representation');
$request->body = [
                     "intent" => "CAPTURE",
                     "purchase_units" => [[
                         "reference_id" => "test_ref_id1",
                         "amount" => [
                             "value" => "100.00",
                             "currency_code" => "USD"
                         ]
                     ]],
                     "application_context" => [
                          "cancel_url" => "https://example.com/cancel",
                          "return_url" => "https://example.com/return"
                     ] 
                 ];

This is fine, but we can't find any documentation as to what values can or should be given in "purchase_units" (or any other fields in this data set) array.

Paypal's own documentation itself for "purchase_units" links to here: https://developer.paypal.com/docs/api/orders/v2/#definition-model-update_purchase_unit_request

which states:

model-update_purchase_unit_request

reference_id string required

The API caller-provided external ID for the purchase unit.

Minimum length: 1. Maximum length: 256.

payments object required

The comprehensive summary of payments for the purchase unit.

Which is either incomplete or referencing something else (there is no payments object on the exampled code).

We are looking to establish what other fields can be given in purchase_units and if the reference_id is a Paypal reference or something on our servers we generate (such as a database order row, etc.) . I would assume the reference_id is something we generate ourselves but as there's so little documentation from Paypal this doesn't appear to be actually clarified anywhere.

Questions:

  1. What fields can we use in the "purchase_units" request body

  2. How can we add shipping on to this order creation?

And as a bonus, where is there any reliable and unarchived Paypal documentation on this?

Thank you.

CodePudding user response:

I would assume the reference_id is something we generate ourselves

Yes, that appears to be the case.

If you look under https://developer.paypal.com/docs/api/orders/v2/#definition-purchase_unit, there it says,

reference_id - string - The API caller-provided external ID for the purchase unit.

So you, as the caller of the API, have to provide this ID.

  • Related