> ## Documentation Index
> Fetch the complete documentation index at: https://firmly.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Complete PayPal Order

> Finalizes the order using the PayPal token and payer id

## Overview

Completes the checkout by placing the order with the merchant using the PayPal authorization. This is the final step in the PayPal checkout flow. The endpoint validates the PayPal token and payer id, places the order, and returns the order confirmation with the merchant's order number.

> [!NOTE]
>
> If the [Authorize](https://firmly.mintlify.site/api-reference/payment/express-checkout/authorize-paypal.md) step was skipped, this endpoint calls authorize automatically before completing the order, as long as `paypal_token` and `payer_id` are provided (here or from the session).

## Authentication

**x-firmly-authorization** `string` *required*

Device authentication token from Browser Session

## Path Parameters

**domain** `string` *required*

The merchant domain (e.g., "merchant.example.com")

## Request Body

**attributes** `object` *required*

PayPal payment attributes

**Attributes**

**paypal\_token** `string` *required*

The PayPal Express Checkout token. Also accepted as `paypalToken`. Falls back to the token stored in the session if the authorize step already ran.

**payer\_id** `string` *required*

The PayPal payer id. Also accepted as `payerId`. Falls back to the payer id stored in the session.

## Response

Returns the order confirmation object.

**cart\_id** `string`

Unique identifier for the cart

**platform\_order\_number** `string`

The order number from the merchant platform

**cart\_status** `string`

Status of the cart (e.g., "submitted")

**submitted\_at** `string`

ISO timestamp when the order was submitted

**urls** `object`

Relevant URLs for the order

**URLs**

**thank\_you\_page** `string`

URL to the merchant's order confirmation page

**line\_items** `array`

Array of items in the order

**shipping\_info** `object`

Delivery address details

**billing\_info** `object`

Billing address details

**payment\_summary** `object`

Summary of the PayPal payment

**Payment Summary**

**payment\_type** `string`

`"PayPal"` for this gateway

**total** `object`

Grand total including all costs

## Code Example

```javascript JavaScript theme={null}
const response = await fetch(
  'https://api.firmly.work/api/v1/domains/merchant.example.com/express/paypal/complete-order',
  {
    method: 'POST',
    headers: {
      'x-firmly-authorization': authToken,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      attributes: {
        paypal_token: 'EC-25M07043P9951254S',
        payer_id: 'QYR5Z8XZ5JX6N'
      }
    })
  }
);

const order = await response.json();
console.log('Order number:', order.platform_order_number);

if (order.urls?.thank_you_page) {
  window.location.href = order.urls.thank_you_page;
}
```

```python Python theme={null}
import requests

response = requests.post(
    'https://api.firmly.work/api/v1/domains/merchant.example.com/express/paypal/complete-order',
    headers={
        'x-firmly-authorization': auth_token,
        'Content-Type': 'application/json'
    },
    json={
        'attributes': {
            'paypal_token': 'EC-25M07043P9951254S',
            'payer_id': 'QYR5Z8XZ5JX6N'
        }
    }
)

order = response.json()
print(f"Order placed: {order['platform_order_number']}")
```

```bash cURL theme={null}
curl -X POST https://api.firmly.work/api/v1/domains/merchant.example.com/express/paypal/complete-order \
  -H "x-firmly-authorization: YOUR_AUTH_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"attributes": {"paypal_token": "EC-25M07043P9951254S", "payer_id": "QYR5Z8XZ5JX6N"}}'
```

## Response Example

```json theme={null}
{
  "cart_id": "9cf76530-1344-420f-9ca6-c7a96fb6db45",
  "platform_order_number": "6800018416",
  "cart_status": "submitted",
  "submitted_at": "2024-07-22T18:58:25.000Z",
  "urls": {
    "thank_you_page": "https://merchant.example.com/checkout/onepage/success/"
  },
  "line_items": [
    {
      "line_item_id": "3e66bef5-43f5-4a80-8957-91c5c8233163",
      "sku": "MT12",
      "quantity": 1,
      "description": "Cassius Sparring Tank",
      "price": { "currency": "USD", "value": 18, "number": 1800, "symbol": "$" }
    }
  ],
  "shipping_info": {
    "first_name": "John",
    "last_name": "Smith",
    "address1": "123 Main St",
    "city": "Seattle",
    "state_or_province": "WA",
    "country": "US",
    "postal_code": "98101"
  },
  "billing_info": {
    "first_name": "John",
    "last_name": "Smith",
    "address1": "123 Main St",
    "city": "Seattle",
    "state_or_province": "WA",
    "country": "US",
    "postal_code": "98101"
  },
  "payment_summary": {
    "payment_type": "PayPal"
  },
  "total": { "currency": "USD", "value": 30, "number": 3000, "symbol": "$" }
}
```

## Error Responses

| Code | Description |
| - | - |
| `ErrorCartNotFound` | No active cart for this domain |
| `ErrorBadRequest` | Missing PayPal token or payer id |
| `ErrorGatewayNotFound` | PayPal is not enabled for this merchant |
| `ErrorPaymentMethodNotAvailable` | PayPal is not available for this cart |
| `ErrorMissingShippingMethod` | No shipping method selected |
| `ErrorMissingTaxSync` | Tax has not been calculated |
| `ErrorCheckout` | Checkout failed at the merchant |
| `ErrorRateLimited` | Too many requests |

## Related Endpoints

* [Start PayPal Checkout](https://firmly.mintlify.site/api-reference/payment/express-checkout/start-paypal.md) - Create the PayPal order
* [Authorize PayPal Checkout](https://firmly.mintlify.site/api-reference/payment/express-checkout/authorize-paypal.md) - Confirm authorization


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.