Prometheus Computing
Development, Support, Consultancy

Retrieving, Authorizing & Capturing an Order

Laravel

Published: May 25, 2024

Author: Andrew Arscott

Much like Eloquent, we use the idea of Models to represent resources from PayPal. You can hydrate an Order model by providing its ID:

use Drewdan\Paypal\Orders\Models\Order;

$order = Order::retrieve('some-order-id');

Now we have a hydrated order, we can call methods on it to perform actions within PayPal. For example, we can authorize or capture the payment by calling the following methods:

$order->authorize();
$order->capture();

Additionally, we can get a Collection of purchase units and captures by calling the following methods:

$order->getPurchaseUnits();
$order->listCaptures();

The properies on the Order model are public, and the class is not final, so you are free to extend this class and add additional methods as you require. The Model can be turned into an array by calling the toArray() method as follows:

$order->toArray();

This will return an array representation of the order and remove any null values in the array.

Signature Of the Order Model

The following table details the properties available on the model.

Type Name Description
string create_time This represents the time the order was created
string update_time This represents the last time the order was updated
string id This represents the order ID which was used to lookup the order, or returned when the order builder was used.
string processing_instruction This string represents the processing instruction
PurchaseUnits purchase_units This returns a class which contains the purchase units. There is a helper on this model to get them directly.
Links links This returns all the links associated with this resource.
BuildsPaymentSource payment_source This returns an instance of the payment source, of which the most common type will be Paypal
string intent The payment intent associated with this order
array $payer An array of Payer data
OrderStatusEnum $status An enum value indicating the status of the order. Values are: CREATED, SAVED, APPROVED, VOIDED, COMPLETED, PAYER_ACTION_REQUIRED
Amount $gross_amount The Amount object which contains the amount and currency