IAP

Use this integration to handle in app purchases.

Introduction

The In App Purchase (IAP) integration allows you to sell digital products within your app. This supports both non-consuming and consuming products. Non-consuming products are products that the user buys once and then has access to forever. Consuming products are products that the user can buy multiple times.

Integration name: startiapp.Iap

Getting started

The IAP integration uses the In App Purchase service on Android and the StoreKit service on iOS. But through starti.app you do not have to worry about the differences between the two platforms. The integration is the same on both platforms.

Methods

purchaseProduct

purchaseProduct(productId: string, purchaseType: IapPurchaseType): Promise<IapResponse<IapPurchaseProductResponse>>

Initiates the purchase flow for a specific product. productId specifies the identifier of the product to purchase, purchaseType indicates whether the product is consumable or non-consumable. Returns a promise that resolves to an IapResponse object containing the transaction details.

The purchase of a product is always automatically finalized


getProduct

getProduct(productId: string, purchaseType: IapPurchaseType): Promise<IapResponse<IapGetProductResponse>>

Retrieves the details of a specific product. The productId specifies the identifier of the product to retrieve, and purchaseType indicates whether the product is consumable or non-consumable. Returns a promise that resolves to an IapResponse object containing the product details.


Types

IapResponse

type IapResponse<
    T extends
    | IapPurchaseProductResponse
    | IapGetProductResponse
> = {
    success: boolean;
    errorMessage?: string;
    value: null | T;
}

A generic response type for IAP operations. Contains a success flag, an optional errorMessage, and a value that can be one of the specific response types depending on the operation.

IapPurchaseProductResponse

type IapPurchaseProductResponse = {
    transactionIdentifier: string;
}

Response type for product purchase operations. Contains a transactionIdentifier for the purchase transaction.

IapGetProductResponse

type IapGetProductResponse = {
    name: string;
    description: string;
    localizedPrice: string;
    currencyCode: string;
}

Response type for retrieving product details. Contains information about the product, including its name, description, localized price, and currency code.

IapPurchaseType

type IapPurchaseType = "nonconsumable" | "consumable";

Indicates the type of purchase: nonconsumable for products that are bought once and do not expire, and consumable for products that can be purchased multiple times.