> 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.createonetimepurchaseorder.md).

# IAP.createOneTimePurchaseOrder

### Feature description

Go to the single in-app purchase order page. The payment/product delivery flow is `options` / `onEvent` / `onError` Handle it with event style options.

* `options.sku`: The ID of the product to order. (`productId`is deprecated)
* `options.processProductGrant`: Called when granting the product after the order is created. Whether the grant succeeded `true`/`false`(or Promise).
* `onEvent`: When payment succeeds `type: 'success'`and the result data.
* `onError`: Called if an error occurs during payment.

The returned cleanup function must be called when the in-app purchase feature ends to release resources.

Toss app Android/iOS `5.219.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.createOneTimePurchaseOrder(params: IapCreateOneTimePurchaseOrderOptions): () => void;
```

**Params**

```ts
interface IapCreateOneTimePurchaseOrderOptions {
  options: {
    sku: string;
    /** @deprecated use sku */
    productId?: string;
    processProductGrant: (params: {
      orderId: string;
    }) => boolean | Promise<boolean>;
  };
  onEvent: (event: {
    type: "success";
    data: IapCreateOneTimePurchaseOrderResult;
  }) => void | Promise<void>;
  onError: (error: unknown) => void | Promise<void>;
}

interface IapCreateOneTimePurchaseOrderResult {
  orderId: string;
  displayName: string;
  displayAmount: string;
  amount: number;
  currency: string;
  fraction: number;
  miniAppIconUrl: string | null;
}
```

**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                                                                                                                                                                                                                                          |
| --------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `INVALID_PRODUCT_ID`              | The product ID is invalid or the product does not exist.                                                                                                                                                                                             |
| `PAYMENT_PENDING`                 | Payment is still awaiting approval.                                                                                                                                                                                                                  |
| `NETWORK_ERROR`                   | The request cannot be processed due to a network/server issue.                                                                                                                                                                                       |
| `INVALID_USER_ENVIRONMENT`        | The product cannot be purchased on certain devices, accounts, or settings.                                                                                                                                                                           |
| `ITEM_ALREADY_OWNED`              | Trying to purchase a product that has already been purchased.                                                                                                                                                                                        |
| `APP_MARKET_VERIFICATION_FAILED`  | Payment succeeded, but app store verification failed.                                                                                                                                                                                                |
| `TOSS_SERVER_VERIFICATION_FAILED` | Payment succeeded, but sending/storing on the server failed.                                                                                                                                                                                         |
| `INTERNAL_ERROR`                  | The request cannot be processed due to an internal server issue.                                                                                                                                                                                     |
| `KOREAN_ACCOUNT_ONLY`             | On iOS, when the account is not a Korean account.                                                                                                                                                                                                    |
| `USER_CANCELED`                   | The user left the order page.                                                                                                                                                                                                                        |
| `PRODUCT_NOT_GRANTED_BY_PARTNER`  | The partner's product grant failed.                                                                                                                                                                                                                  |
| `UNSUPPORTED_APP_VERSION`         | If the running Toss app version does not support this feature, it occurs immediately upon calling. `IAP.createOneTimePurchaseOrder.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("#buy-button");
let cleanup;

button.addEventListener("click", () => {
  try {
    cleanup = IAP.createOneTimePurchaseOrder({
      options: {
        sku: "coin_100",
        processProductGrant: ({ orderId }) => {
          // Write product grant logic
          console.log("Grant processing:", orderId);
          return true;
        },
      },
      onEvent: (event) => {
        console.log(event.type, event.data);
      },
      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.createonetimepurchaseorder.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.
