# Interface: PurchaseNamespace

Defined in: [types.ts:721](https://github.com/alleyinteractive/allegro/blob/6aebbf1d5d34ded3d128c093d7d30abd96d938be/packages/allegro-platform/resources/js/sdk/types.ts#L721)

Methods for initiating and completing purchases.

Access this namespace via `allegro.purchase`.

## Example[​](#example "Direct link to Example")

```ts
window.allegro.push((allegro) => {
  allegro.purchase.initiate('term-uuid-here');
});

```

## Methods[​](#methods "Direct link to Methods")

### exchangeToken()[​](#exchangetoken "Direct link to exchangeToken()")

> **exchangeToken**(`token`): `Promise`<[`PurchaseTokenExchangeResponse`](/developer/api-reference/interfaces/PurchaseTokenExchangeResponse.md)>

Defined in: [types.ts:736](https://github.com/alleyinteractive/allegro/blob/6aebbf1d5d34ded3d128c093d7d30abd96d938be/packages/allegro-platform/resources/js/sdk/types.ts#L736)

Exchange an `allegro_purchase_token` query param for a JWT + entitlement.

Called automatically on page load when the param is detected.

#### Parameters[​](#parameters "Direct link to Parameters")

| Parameter | Type     |
| --------- | -------- |
| `token`   | `string` |

#### Returns[​](#returns "Direct link to Returns")

`Promise`<[`PurchaseTokenExchangeResponse`](/developer/api-reference/interfaces/PurchaseTokenExchangeResponse.md)>

***

### initiate()[​](#initiate "Direct link to initiate()")

> **initiate**(`termId`, `returnUrl?`): `Promise`<`void`>

Defined in: [types.ts:729](https://github.com/alleyinteractive/allegro/blob/6aebbf1d5d34ded3d128c093d7d30abd96d938be/packages/allegro-platform/resources/js/sdk/types.ts#L729)

Initiate a purchase for a term.

Calls the backend to create a hosted checkout session, then redirects the browser to the provider's checkout page. If `returnUrl` is omitted, the current page URL is used.

#### Parameters[​](#parameters-1 "Direct link to Parameters")

| Parameter    | Type     |
| ------------ | -------- |
| `termId`     | `string` |
| `returnUrl?` | `string` |

#### Returns[​](#returns-1 "Direct link to Returns")

`Promise`<`void`>

## Properties[​](#properties "Direct link to Properties")

| Property         | Type                                  | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          | Defined in                                                                                                                                                         |
| ---------------- | ------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| []()`validation` | `"failed"` \| `"completed"` \| `null` | The result of purchase token validation on this page load. - `'completed'` — purchase was verified and entitlement created - `'failed'` — payment failed or was cancelled - `null` — no purchase token present on this page load **Async timing note:** This value may still be `null` when `allegro:ready` fires, because token exchange is asynchronous. Do not read `validation` at ready time. Instead, listen for the `allegro:purchase:completed` or `allegro:purchase:failed` events to react to the outcome. | [types.ts:750](https://github.com/alleyinteractive/allegro/blob/6aebbf1d5d34ded3d128c093d7d30abd96d938be/packages/allegro-platform/resources/js/sdk/types.ts#L750) |
