> For the complete documentation index, see [llms.txt](https://developers-apps-in-toss.toss.im/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers-apps-in-toss.toss.im/documentation/api-and-sdk-en/sdk/domains-api/iap/iap.createsubscriptionpurchaseorder.md).

# IAP.createSubscriptionPurchaseOrder

### Feature description

It goes to the subscription in-app purchase order page. Like a one-time payment `options` / `onEvent` / `onError` It is event-style.

* `options.sku`: This is the subscription product ID.
* `options.offerId`: This is the offer ID to apply. If there isn't one, the default price is applied.
* `options.processProductGrant`: Called when the product is granted after order creation. `{ orderId, subscriptionId? }`is received.

The returned cleanup function must be called when you're done with the feature.

Toss app Android `5.248.0`, iOS `5.249.0` It can be used in versions at or above this one. If called in an unsupported version, `UNSUPPORTED_APP_VERSION` an error occurs.

### Type

```ts
IAP.createSubscriptionPurchaseOrder(params: CreateSubscriptionPurchaseOrderOptions): () => void;
```

**Params**

```ts
interface CreateSubscriptionPurchaseOrderOptions {
  options: {
    sku: string;
    offerId?: string | null;
    processProductGrant: (params: {
      orderId: string;
      subscriptionId?: string;
    }) => boolean | Promise<boolean>;
  };
  onEvent: (event: {
    type: "success";
    data: IapCreateSubscriptionPurchaseOrderResult;
  }) => void | Promise<void>;
  onError: (error: unknown) => void | Promise<void>;
}

type IapCreateSubscriptionPurchaseOrderResult =
  IapCreateOneTimePurchaseOrderResult;
```

**Response**

Returns a cleanup function (() => void) to call and release resources when the payment flow ends.`() => void`) to release resources.

### Error

The error code is `onError`can be received or the `try/catch`error caught in `error.code` value.

| Code                      | Description                                                                                                                                                                                                                                               |
| ------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `UNSUPPORTED_APP_VERSION` | If the running Toss app version does not support this feature, it occurs immediately upon calling. `IAP.createSubscriptionPurchaseOrder.isSupported()`Check in advance with, and if it occurs `error.message`show the user the (update guidance message). |

### Example code

```js
import { IAP } from "@apps-in-toss/web-framework";

const button = document.querySelector("#subscribe-button");
let cleanup;

button.addEventListener("click", () => {
  try {
    cleanup = IAP.createSubscriptionPurchaseOrder({
      options: {
        sku: "premium_monthly",
        offerId: null,
        processProductGrant: ({ orderId, subscriptionId }) => {
          console.log(orderId, subscriptionId);
          return true;
        },
      },
      onEvent: (event) => {
        console.log(event);
      },
      onError: (error) => {
        console.error(error);
      },
    });
  } catch (error) {
    console.error(error);
  }
});

// cleanup?.() when leaving the screen
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://developers-apps-in-toss.toss.im/documentation/api-and-sdk-en/sdk/domains-api/iap/iap.createsubscriptionpurchaseorder.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
