Skip to main content

IAP.createOneTimePurchaseOrder

Navigates to the in-app purchase checkout page for a specific SKU. Call this when the user taps a buy button. The payment itself is processed on the checkout page; if an error occurs, the SDK routes the user to an appropriate error page.

Signature

createOneTimePurchaseOrder is a member of the IAP namespace object.

import { IAP } from '@apps-in-toss/web-framework';

declare const IAP: {
createOneTimePurchaseOrder(params: {
options: {
sku: string;
processProductGrant: (params: { orderId: string }) => boolean | Promise<boolean>;
};
onEvent: (event: { type: 'success'; data: IapCreateOneTimePurchaseOrderResult }) => void | Promise<void>;
onError: (error: unknown) => void | Promise<void>;
}): () => void;
// ...see overview
};

Parameters

NameTypeRequiredDescription
params.options.skustringUnique ID of the product to purchase.
params.options.processProductGrant(params: { orderId: string }) => boolean | Promise<boolean>Callback invoked after the order is created to fulfill the product on your server. Return true on success, false on failure.
params.onEvent(event: SuccessEvent) => void | Promise<void>Called on payment success. event.data contains IapCreateOneTimePurchaseOrderResult.
params.onError(error: unknown) => void | Promise<void>Called when an error occurs during payment.

IapCreateOneTimePurchaseOrderResult

FieldTypeDescription
orderIdstringPayment order ID.
displayNamestringProduct name for display.
displayAmountstringPrice with currency (e.g. ₩1,000).
amountnumberRaw numeric price (e.g. 1000).
currencystringISO 4217 currency code (e.g. KRW).
fractionnumberDecimal places for price display.
miniAppIconUrlstring | nullMini-app icon URL, or null if unset.

Returns

  • () => void — app-bridge cleanup function. Must be called when the payment flow ends to release resources.

Error codes

CodeDescription
INVALID_PRODUCT_IDInvalid product ID or product does not exist.
PAYMENT_PENDINGA payment for this order is already awaiting approval.
NETWORK_ERRORServer error prevented request processing.
INVALID_USER_ENVIRONMENTProduct cannot be purchased on this device/account/settings.
ITEM_ALREADY_OWNEDUser already owns this non-consumable product.
APP_MARKET_VERIFICATION_FAILEDPayment completed but app store user verification failed.
TOSS_SERVER_VERIFICATION_FAILEDPayment completed but server transmission failed.
INTERNAL_ERRORInternal server error.
KOREAN_ACCOUNT_ONLYiOS: account is not a Korean account.
USER_CANCELEDUser left the checkout page without completing payment.
PRODUCT_NOT_GRANTED_BY_PARTNERPartner's product fulfillment failed.

Permission

No permission required — the IAP namespace is not bound to a PermissionName.

Examples

Minimal

import { IAP } from '@apps-in-toss/web-framework';

const cleanup = IAP.createOneTimePurchaseOrder({
options: {
sku: 'item_coin_100',
processProductGrant: async ({ orderId }) => {
// Fulfill on server, then return true
return true;
},
},
onEvent: (event) => {
console.log('Purchase complete', event.data);
cleanup();
},
onError: (error) => {
console.error('Purchase error', error);
cleanup();
},
});

Realistic — React component

import { IAP } from '@apps-in-toss/web-framework';
import { useCallback, useRef } from 'react';

interface Props {
sku: string;
}

function PurchaseButton({ sku }: Props) {
const cleanupRef = useRef<(() => void) | null>(null);

const handleClick = useCallback(() => {
cleanupRef.current = IAP.createOneTimePurchaseOrder({
options: {
sku,
processProductGrant: async ({ orderId }) => {
try {
await fetch('/api/grant', {
method: 'POST',
body: JSON.stringify({ orderId }),
headers: { 'Content-Type': 'application/json' },
});
return true;
} catch {
return false;
}
},
},
onEvent: (event) => {
console.log('Purchase complete', event.data);
cleanupRef.current?.();
},
onError: (error) => {
console.error(error);
cleanupRef.current?.();
},
});
}, [sku]);

return (
<button type="button" onClick={handleClick}>
Buy now
</button>
);
}

Try it live

Run the one-time purchase flow on the IAP page in sdk-example.

Open in sdk-example
  • Guides — IAP payment flowprocessProductGrant/completeProductGrant sequencing, server fulfillment, and recovery patterns in one place.

External references