> ## 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 Apple Pay Order

> Places the order using the Apple Pay payment token

## Overview

Completes the checkout in a single call after the buyer authorizes payment in the Apple Pay sheet. Apple Pay has no separate start or authorize step — once [merchant validation](https://firmly.mintlify.site/api-reference/payment/express-checkout/validate-merchant-apple-pay.md) succeeds and the buyer authorizes, the client submits the `PKPaymentToken` and contact details here, and Firmly authorizes and places the order.

> [!NOTE]
>
> Apple Pay is enabled per merchant. Check the cart's `payment_method_options` array for `{ "type": "ApplePay", "wallet": "apple_pay", "config": { ... } }` before offering Apple Pay; `config` carries `country_code`, `supported_networks` and `merchant_capabilities` for the `ApplePayPaymentRequest`. The merchant must be validated first via [Validate Apple Pay Merchant](https://firmly.mintlify.site/api-reference/payment/express-checkout/validate-merchant-apple-pay.md).

## 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*

Apple Pay payment attributes

**Attributes**

**apple\_pay\_token** `string` *required*

The Apple Pay `PKPaymentToken` as a JSON string (`JSON.stringify(token)` from the `onpaymentauthorized` event). Forwarded verbatim to the merchant for decryption.

**apple\_pay\_address** `object`

The Apple Pay sheet `shippingContact`. Used as the shipping address when the merchant checkout has no separate shipping form.

**apple\_pay\_billing\_address** `object`

The Apple Pay sheet `billingContact` (cardholder billing address). Can differ from the shipping address; some merchants require it for address verification.

**apple\_pay\_card\_network** `string`

The card network reported by Apple Pay (for example, `"visa"`).

## 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")

**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 Apple Pay payment

**Payment Summary**

**payment\_type** `string`

`"ApplePay"` for this gateway

**total** `object`

Grand total including all costs

## Code Example

```javascript JavaScript theme={null}
session.onpaymentauthorized = async (event) => {
  try {
    const response = await fetch(
      'https://api.firmly.work/api/v1/domains/merchant.example.com/express/apple-pay/complete-order',
      {
        method: 'POST',
        headers: {
          'x-firmly-authorization': authToken,
          'Content-Type': 'application/json'
        },
        body: JSON.stringify({
          attributes: {
            apple_pay_token: JSON.stringify(event.payment.token),
            apple_pay_address: event.payment.shippingContact,
            apple_pay_billing_address: event.payment.billingContact
          }
        })
      }
    );

    // A non-2xx response is an error object ({ description, ... }), not an order
    const order = await response.json();
    if (!response.ok) {
      session.completePayment(ApplePaySession.STATUS_FAILURE);
      return; // order.description carries the reason to show the buyer
    }

    session.completePayment(ApplePaySession.STATUS_SUCCESS);
    if (order.urls?.thank_you_page) {
      window.location.href = order.urls.thank_you_page;
    }
  } catch (error) {
    // Network failure or unparseable body: close the sheet with a failure, never a success
    session.completePayment(ApplePaySession.STATUS_FAILURE);
  }
};
```

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

response = requests.post(
    'https://api.firmly.work/api/v1/domains/merchant.example.com/express/apple-pay/complete-order',
    headers={
        'x-firmly-authorization': auth_token,
        'Content-Type': 'application/json'
    },
    json={
        'attributes': {
            'apple_pay_token': json.dumps(payment_token),
            'apple_pay_address': shipping_contact,
            'apple_pay_billing_address': billing_contact
        }
    }
)

response.raise_for_status()
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/apple-pay/complete-order \
  -H "x-firmly-authorization: YOUR_AUTH_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"attributes": {"apple_pay_token": "{\"paymentData\":{...}}", "apple_pay_card_network": "visa"}}'
```

## Response Example

```json theme={null}
{
  "cart_id": "9cf76530-1344-420f-9ca6-c7a96fb6db45",
  "platform_order_number": "6800018416",
  "cart_status": "submitted",
  "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": "ApplePay"
  },
  "total": { "currency": "USD", "value": 30, "number": 3000, "symbol": "$" }
}
```

## Error Responses

| Code | Description |
| - | - |
| `ErrorCartNotFound` | No active cart for this domain |
| `ErrorBadRequest` | Missing `apple_pay_token` |
| `ErrorGatewayNotFound` | Apple Pay is not enabled for this merchant |
| `ErrorPaymentMethodNotAvailable` | Apple Pay 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

* [Validate Apple Pay Merchant](https://firmly.mintlify.site/api-reference/payment/express-checkout/validate-merchant-apple-pay.md) - Required before completing the order
* [Complete Google Pay Order](https://firmly.mintlify.site/api-reference/payment/express-checkout/complete-order-google-pay.md) - Google Pay express flow


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