1
0
Files
PayPal-PHP-Server-SDK/doc/controllers/orders.md
2024-09-06 15:38:17 +05:00

23 KiB

Orders

Use the /orders resource to create, update, retrieve, authorize, capture and track orders.

$ordersController = $client->getOrdersController();

Class Name

OrdersController

Methods

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.
payPalPartnerAttributionId ?string Header, Optional -
payPalClientMetadataId ?string Header, Optional -
prefer ?string Header, Optional The preferred server response upon successful completion of the request. Value is:
  • return=minimal. The server returns a minimal response to optimize communication between the API caller and the server. A minimal response includes the id, status and HATEOAS links.
  • return=representation. The server returns a complete resource representation, including the current state of the resource.

Response Type

This method returns a PayPalRESTAPIsLib\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(
                    'USD',
                    '100.00'
                )->build()
            )
                ->referenceId('d9f80740-38f0-11e8-b467-0ed5f89f718b')
                ->build()
        ]
    )->build(),
    'payPalRequestId' => 'PayPal-Request-Id',
    'payPalClientMetadataId' => 'PayPal-Client-Metadata-Id',
    '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.
fields ?string Query, Optional A comma-separated list of fields that should be returned for the order. Valid filter field is payment_source.

Response Type

This method returns a PayPalRESTAPIsLib\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 <a href="/api/rest/reference/orders/v2/errors/#patch-order">Orders v2 errors.
Patchable attributes or objects:

AttributeOpNotes
intentreplace
payerreplace, addUsing replace op for payer will replace the whole payer object with the value sent in request.
purchase_unitsreplace, add
purchase_units[].custom_idreplace, add, remove
purchase_units[].descriptionreplace, add, remove
purchase_units[].payee.emailreplace
purchase_units[].shipping.namereplace, add
purchase_units[].shipping.email_addressreplace, add
purchase_units[].shipping.phone_numberreplace, add
purchase_units[].shipping.optionsreplace, add
purchase_units[].shipping.addressreplace, add
purchase_units[].shipping.typereplace, add
purchase_units[].soft_descriptorreplace, remove
purchase_units[].amountreplace
purchase_units[].itemsreplace, add, remove
purchase_units[].invoice_idreplace, add, remove
purchase_units[].payment_instructionreplace
purchase_units[].payment_instruction.disbursement_modereplaceBy default, disbursement_mode is INSTANT.
purchase_units[].payment_instruction.payee_receivable_fx_rate_idreplace, add, remove
purchase_units[].payment_instruction.platform_feesreplace, add, remove
purchase_units[].supplementary_data.airlinereplace, add, remove
purchase_units[].supplementary_data.cardreplace, add, remove
application_context.client_configurationreplace, add

function ordersPatch(array $options): ApiResponse

Parameters

Parameter Type Tags Description
id string Template, Required The ID of the order to update.
body ?(Patch[]) Body, Optional -

Response Type

This method returns a PayPalRESTAPIsLib\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.
payPalClientMetadataId ?string Header, Optional -
prefer ?string Header, Optional The preferred server response upon successful completion of the request. Value is:
  • return=minimal. The server returns a minimal response to optimize communication between the API caller and the server. A minimal response includes the id, status and HATEOAS links.
  • return=representation. The server returns a complete resource representation, including the current state of the resource.
body ?ConfirmOrderRequest Body, Optional -

Response Type

This method returns a PayPalRESTAPIsLib\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.
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.
prefer ?string Header, Optional The preferred server response upon successful completion of the request. Value is:
  • return=minimal. The server returns a minimal response to optimize communication between the API caller and the server. A minimal response includes the id, status and HATEOAS links.
  • return=representation. The server returns a complete resource representation, including the current state of the resource.
payPalClientMetadataId ?string Header, Optional -
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 PayPalRESTAPIsLib\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.
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.
prefer ?string Header, Optional The preferred server response upon successful completion of the request. Value is:
  • return=minimal. The server returns a minimal response to optimize communication between the API caller and the server. A minimal response includes the id, status and HATEOAS links.
  • return=representation. The server returns a complete resource representation, including the current state of the resource.
payPalClientMetadataId ?string Header, Optional -
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 PayPalRESTAPIsLib\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.
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 PayPalRESTAPIsLib\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:

AttributeOpNotes
itemsreplaceUsing replace op for items will replace the entire items object with the value sent in request.
notify_payerreplace, add
statusreplaceOnly 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.
trackerId string Template, Required The order tracking ID.
body ?(Patch[]) Body, Optional -

Response Type

This method returns a PayPalRESTAPIsLib\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