24 KiB
Orders
Use the /orders resource to create, update, retrieve, authorize, capture and track orders.
$ordersController = $client->getOrdersController();
Class Name
OrdersController
Methods
- Orders Create
- Orders Get
- Orders Patch
- Orders Confirm
- Orders Authorize
- Orders Capture
- Orders Track Create
- Orders Trackers Patch
Orders Create
Creates an order. Merchants and partners can add Level 2 and 3 data to payments to reduce risk and payment processing costs. For more information about processing payments, see checkout or multiparty checkout.
Note: For error handling and troubleshooting, see Orders v2 errors.
function ordersCreate(array $options): ApiResponse
Parameters
| Parameter | Type | Tags | Description |
|---|---|---|---|
body |
OrderRequest |
Body, Required | - |
payPalRequestId |
?string |
Header, Optional | The server stores keys for 6 hours. The API callers can request the times to up to 72 hours by speaking to their Account Manager. Constraints: Minimum Length: 1, Maximum Length: 108 |
payPalPartnerAttributionId |
?string |
Header, Optional | Constraints: Minimum Length: 1, Maximum Length: 36 |
payPalClientMetadataId |
?string |
Header, Optional | Constraints: Minimum Length: 1, Maximum Length: 36 |
prefer |
?string |
Header, Optional | The preferred server response upon successful completion of the request. Value is:
Default: 'return=minimal'Constraints: Minimum Length: 1, Maximum Length: 25, Pattern: ^[a-zA-Z=,-]*$ |
Response Type
This method returns a PaypalServerSdkLib\Utils\ApiResponse instance. The getResult() method on this instance returns the response data which is of type Order.
Example Usage
$collect = [
'body' => OrderRequestBuilder::init(
CheckoutPaymentIntent::CAPTURE,
[
PurchaseUnitRequestBuilder::init(
AmountWithBreakdownBuilder::init(
'currency_code6',
'value0'
)->build()
)->build()
]
)->build(),
'prefer' => 'return=minimal'
];
$apiResponse = $ordersController->ordersCreate($collect);
Errors
| HTTP Status Code | Error Description | Exception Class |
|---|---|---|
| 400 | Request is not well-formed, syntactically incorrect, or violates schema. | ErrorException |
| 401 | Authentication failed due to missing authorization header, or invalid authentication credentials. | ErrorException |
| 422 | The requested action could not be performed, semantically incorrect, or failed business validation. | ErrorException |
| Default | The error response. | ErrorException |
Orders Get
Shows details for an order, by ID.
Note: For error handling and troubleshooting, see Orders v2 errors.
function ordersGet(array $options): ApiResponse
Parameters
| Parameter | Type | Tags | Description |
|---|---|---|---|
id |
string |
Template, Required | The ID of the order for which to show details. Constraints: Minimum Length: 1, Maximum Length: 36, Pattern: ^[A-Z0-9]+$ |
fields |
?string |
Query, Optional | A comma-separated list of fields that should be returned for the order. Valid filter field is payment_source.Constraints: Pattern: ^[a-z_]*$ |
Response Type
This method returns a PaypalServerSdkLib\Utils\ApiResponse instance. The getResult() method on this instance returns the response data which is of type Order.
Example Usage
$collect = [
'id' => 'id0'
];
$apiResponse = $ordersController->ordersGet($collect);
Errors
| HTTP Status Code | Error Description | Exception Class |
|---|---|---|
| 401 | Authentication failed due to missing authorization header, or invalid authentication credentials. | ErrorException |
| 404 | The specified resource does not exist. | ErrorException |
| Default | The error response. | ErrorException |
Orders Patch
Updates an order with a CREATED or APPROVED status. You cannot update an order with the COMPLETED status.
To make an update, you must provide a reference_id. If you omit this value with an order that contains only one purchase unit, PayPal sets the value to default which enables you to use the path: "/purchase_units/@reference_id=='default'/{attribute-or-object}". Merchants and partners can add Level 2 and 3 data to payments to reduce risk and payment processing costs. For more information about processing payments, see checkout or multiparty checkout.
Note: For error handling and troubleshooting, see Orders v2 errors.Patchable attributes or objects:
| Attribute | Op | Notes |
|---|---|---|
intent | replace | |
payer | replace, add | Using replace op for payer will replace the whole payer object with the value sent in request. |
purchase_units | replace, add | |
purchase_units[].custom_id | replace, add, remove | |
purchase_units[].description | replace, add, remove | |
purchase_units[].payee.email | replace | |
purchase_units[].shipping.name | replace, add | |
purchase_units[].shipping.email_address | replace, add | |
purchase_units[].shipping.phone_number | replace, add | |
purchase_units[].shipping.options | replace, add | |
purchase_units[].shipping.address | replace, add | |
purchase_units[].shipping.type | replace, add | |
purchase_units[].soft_descriptor | replace, remove | |
purchase_units[].amount | replace | |
purchase_units[].items | replace, add, remove | |
purchase_units[].invoice_id | replace, add, remove | |
purchase_units[].payment_instruction | replace | |
purchase_units[].payment_instruction.disbursement_mode | replace | By default, disbursement_mode is INSTANT. |
purchase_units[].payment_instruction.payee_receivable_fx_rate_id | replace, add, remove | |
purchase_units[].payment_instruction.platform_fees | replace, add, remove | |
purchase_units[].supplementary_data.airline | replace, add, remove | |
purchase_units[].supplementary_data.card | replace, add, remove | |
application_context.client_configuration | replace, add |
function ordersPatch(array $options): ApiResponse
Parameters
| Parameter | Type | Tags | Description |
|---|---|---|---|
id |
string |
Template, Required | The ID of the order to update. Constraints: Minimum Length: 1, Maximum Length: 36, Pattern: ^[A-Z0-9]+$ |
body |
?(Patch[]) |
Body, Optional | - |
Response Type
This method returns a PaypalServerSdkLib\Utils\ApiResponse instance.
Example Usage
$collect = [
'id' => 'id0',
'body' => [
PatchBuilder::init(
PatchOp::ADD
)->build()
]
];
$apiResponse = $ordersController->ordersPatch($collect);
Errors
| HTTP Status Code | Error Description | Exception Class |
|---|---|---|
| 400 | Request is not well-formed, syntactically incorrect, or violates schema. | ErrorException |
| 401 | Authentication failed due to missing authorization header, or invalid authentication credentials. | ErrorException |
| 404 | The specified resource does not exist. | ErrorException |
| 422 | The requested action could not be performed, semantically incorrect, or failed business validation. | ErrorException |
| Default | The error response. | ErrorException |
Orders Confirm
Payer confirms their intent to pay for the the Order with the given payment source.
function ordersConfirm(array $options): ApiResponse
Parameters
| Parameter | Type | Tags | Description |
|---|---|---|---|
id |
string |
Template, Required | The ID of the order for which the payer confirms their intent to pay. Constraints: Minimum Length: 1, Maximum Length: 36, Pattern: ^[A-Z0-9]+$ |
payPalClientMetadataId |
?string |
Header, Optional | Constraints: Minimum Length: 1, Maximum Length: 36 |
prefer |
?string |
Header, Optional | The preferred server response upon successful completion of the request. Value is:
Default: 'return=minimal'Constraints: Minimum Length: 1, Maximum Length: 25, Pattern: ^[a-zA-Z=]*$ |
body |
?ConfirmOrderRequest |
Body, Optional | - |
Response Type
This method returns a PaypalServerSdkLib\Utils\ApiResponse instance. The getResult() method on this instance returns the response data which is of type Order.
Example Usage
$collect = [
'id' => 'id0',
'prefer' => 'return=minimal',
'body' => ConfirmOrderRequestBuilder::init(
PaymentSourceBuilder::init()->build()
)
->processingInstruction(ProcessingInstruction::NO_INSTRUCTION)
->build()
];
$apiResponse = $ordersController->ordersConfirm($collect);
Errors
| HTTP Status Code | Error Description | Exception Class |
|---|---|---|
| 400 | Request is not well-formed, syntactically incorrect, or violates schema. | ErrorException |
| 403 | Authorization failed due to insufficient permissions. | ErrorException |
| 422 | The requested action could not be performed, semantically incorrect, or failed business validation. | ErrorException |
| 500 | An internal server error has occurred. | ErrorException |
| Default | The error response. | ErrorException |
Orders Authorize
Authorizes payment for an order. To successfully authorize payment for an order, the buyer must first approve the order or a valid payment_source must be provided in the request. A buyer can approve the order upon being redirected to the rel:approve URL that was returned in the HATEOAS links in the create order response.
Note: For error handling and troubleshooting, see Orders v2 errors.
function ordersAuthorize(array $options): ApiResponse
Parameters
| Parameter | Type | Tags | Description |
|---|---|---|---|
id |
string |
Template, Required | The ID of the order for which to authorize. Constraints: Minimum Length: 1, Maximum Length: 36, Pattern: ^[A-Z0-9]+$ |
payPalRequestId |
?string |
Header, Optional | The server stores keys for 6 hours. The API callers can request the times to up to 72 hours by speaking to their Account Manager. Constraints: Minimum Length: 1, Maximum Length: 108 |
prefer |
?string |
Header, Optional | The preferred server response upon successful completion of the request. Value is:
Default: 'return=minimal'Constraints: Minimum Length: 1, Maximum Length: 25, Pattern: ^[a-zA-Z=,-]*$ |
payPalClientMetadataId |
?string |
Header, Optional | Constraints: Minimum Length: 1, Maximum Length: 36 |
payPalAuthAssertion |
?string |
Header, Optional | An API-caller-provided JSON Web Token (JWT) assertion that identifies the merchant. For details, see PayPal-Auth-Assertion. |
body |
?OrderAuthorizeRequest |
Body, Optional | - |
Response Type
This method returns a PaypalServerSdkLib\Utils\ApiResponse instance. The getResult() method on this instance returns the response data which is of type OrderAuthorizeResponse.
Example Usage
$collect = [
'id' => 'id0',
'prefer' => 'return=minimal'
];
$apiResponse = $ordersController->ordersAuthorize($collect);
Errors
| HTTP Status Code | Error Description | Exception Class |
|---|---|---|
| 400 | Request is not well-formed, syntactically incorrect, or violates schema. | ErrorException |
| 401 | Authentication failed due to missing authorization header, or invalid authentication credentials. | ErrorException |
| 403 | The authorized payment failed due to insufficient permissions. | ErrorException |
| 404 | The specified resource does not exist. | ErrorException |
| 422 | The requested action could not be performed, semantically incorrect, or failed business validation. | ErrorException |
| 500 | An internal server error has occurred. | ErrorException |
| Default | The error response. | ErrorException |
Orders Capture
Captures payment for an order. To successfully capture payment for an order, the buyer must first approve the order or a valid payment_source must be provided in the request. A buyer can approve the order upon being redirected to the rel:approve URL that was returned in the HATEOAS links in the create order response.
Note: For error handling and troubleshooting, see Orders v2 errors.
function ordersCapture(array $options): ApiResponse
Parameters
| Parameter | Type | Tags | Description |
|---|---|---|---|
id |
string |
Template, Required | The ID of the order for which to capture a payment. Constraints: Minimum Length: 1, Maximum Length: 36, Pattern: ^[A-Z0-9]+$ |
payPalRequestId |
?string |
Header, Optional | The server stores keys for 6 hours. The API callers can request the times to up to 72 hours by speaking to their Account Manager. Constraints: Minimum Length: 1, Maximum Length: 108 |
prefer |
?string |
Header, Optional | The preferred server response upon successful completion of the request. Value is:
Default: 'return=minimal'Constraints: Minimum Length: 1, Maximum Length: 25, Pattern: ^[a-zA-Z=,-]*$ |
payPalClientMetadataId |
?string |
Header, Optional | Constraints: Minimum Length: 1, Maximum Length: 36 |
payPalAuthAssertion |
?string |
Header, Optional | An API-caller-provided JSON Web Token (JWT) assertion that identifies the merchant. For details, see PayPal-Auth-Assertion. |
body |
?OrderCaptureRequest |
Body, Optional | - |
Response Type
This method returns a PaypalServerSdkLib\Utils\ApiResponse instance. The getResult() method on this instance returns the response data which is of type Order.
Example Usage
$collect = [
'id' => 'id0',
'prefer' => 'return=minimal'
];
$apiResponse = $ordersController->ordersCapture($collect);
Errors
| HTTP Status Code | Error Description | Exception Class |
|---|---|---|
| 400 | Request is not well-formed, syntactically incorrect, or violates schema. | ErrorException |
| 401 | Authentication failed due to missing authorization header, or invalid authentication credentials. | ErrorException |
| 403 | The authorized payment failed due to insufficient permissions. | ErrorException |
| 404 | The specified resource does not exist. | ErrorException |
| 422 | The requested action could not be performed, semantically incorrect, or failed business validation. | ErrorException |
| 500 | An internal server error has occurred. | ErrorException |
| Default | The error response. | ErrorException |
Orders Track Create
Adds tracking information for an Order.
function ordersTrackCreate(array $options): ApiResponse
Parameters
| Parameter | Type | Tags | Description |
|---|---|---|---|
id |
string |
Template, Required | The ID of the order that the tracking information is associated with. Constraints: Minimum Length: 1, Maximum Length: 36, Pattern: ^[A-Z0-9]+$ |
body |
OrderTrackerRequest |
Body, Required | - |
payPalAuthAssertion |
?string |
Header, Optional | An API-caller-provided JSON Web Token (JWT) assertion that identifies the merchant. For details, see PayPal-Auth-Assertion. |
Response Type
This method returns a PaypalServerSdkLib\Utils\ApiResponse instance. The getResult() method on this instance returns the response data which is of type Order.
Example Usage
$collect = [
'id' => 'id0',
'body' => OrderTrackerRequestBuilder::init(
'capture_id8'
)
->notifyPayer(false)
->build()
];
$apiResponse = $ordersController->ordersTrackCreate($collect);
Errors
| HTTP Status Code | Error Description | Exception Class |
|---|---|---|
| 400 | Request is not well-formed, syntactically incorrect, or violates schema. | ErrorException |
| 403 | Authorization failed due to insufficient permissions. | ErrorException |
| 404 | The specified resource does not exist. | ErrorException |
| 422 | The requested action could not be performed, semantically incorrect, or failed business validation. | ErrorException |
| 500 | An internal server error has occurred. | ErrorException |
| Default | The error response. | ErrorException |
Orders Trackers Patch
Updates or cancels the tracking information for a PayPal order, by ID. Updatable attributes or objects:
| Attribute | Op | Notes |
|---|---|---|
items | replace | Using replace op for items will replace the entire items object with the value sent in request. |
notify_payer | replace, add | |
status | replace | Only patching status to CANCELLED is currently supported. |
function ordersTrackersPatch(array $options): ApiResponse
Parameters
| Parameter | Type | Tags | Description |
|---|---|---|---|
id |
string |
Template, Required | The ID of the order that the tracking information is associated with. Constraints: Minimum Length: 1, Maximum Length: 36, Pattern: ^[A-Z0-9]+$ |
trackerId |
string |
Template, Required | The order tracking ID. Constraints: Minimum Length: 1, Maximum Length: 36, Pattern: ^[A-Z0-9]+$ |
body |
?(Patch[]) |
Body, Optional | - |
Response Type
This method returns a PaypalServerSdkLib\Utils\ApiResponse instance.
Example Usage
$collect = [
'id' => 'id0',
'trackerId' => 'tracker_id2',
'body' => [
PatchBuilder::init(
PatchOp::ADD
)->build()
]
];
$apiResponse = $ordersController->ordersTrackersPatch($collect);
Errors
| HTTP Status Code | Error Description | Exception Class |
|---|---|---|
| 400 | Request is not well-formed, syntactically incorrect, or violates schema. | ErrorException |
| 403 | Authorization failed due to insufficient permissions. | ErrorException |
| 404 | The specified resource does not exist. | ErrorException |
| 422 | The requested action could not be performed, semantically incorrect, or failed business validation. | ErrorException |
| 500 | An internal server error has occurred. | ErrorException |
| Default | The error response. | ErrorException |