Skip to content
modkitv0.2

iap.h

#include <modkit/iap.h>10 functions · 3 structs · 2 enums · 9 typedefs

In-App Purchases - Cross-platform monetization API.

Provides a unified interface for in-app purchases across:iOS (StoreKit 2)Android (Google Play Billing Library)Steam (Steamworks ISteamMicroTxn - requires backend server)Web/Custom (extensible for Stripe, PayPal, etc.) Basic usage:

Functions

mk_iap_consumefunction

void mk_iap_consume(const char *product_id)

Consume a consumable product.

Must be called after granting the content for consumable products. This allows the product to be purchased again.

ParameterTypeDescription
product_idconst char *Product identifier to consume

mk_iap_fetch_productsfunction

void mk_iap_fetch_products(const char **product_ids, int count, mk_iap_products_fn callback, void *user_data)

Fetch product information from the store.

Product IDs should match those configured in App Store Connect, Google Play Console, or Steamworks.

ParameterTypeDescription
product_idsconst char **Array of product identifiers to fetch
countintNumber of product IDs
callbackmk_iap_products_fnCalled when fetch completes (required)
user_datavoid *User pointer passed to callback

mk_iap_get_backend_namefunction

const char * mk_iap_get_backend_name(void)

Get the current IAP backend name.

Returns Backend identifier ("ios", "android", "steam", "web", "stub")

mk_iap_initfunction

bool mk_iap_init(void)

Initialize the IAP system.

Must be called before any other IAP functions. On iOS/Android, this connects to the app store.

Returns true if initialization succeeded (or IAP is available)

mk_iap_is_availablefunction

bool mk_iap_is_available(void)

Check if in-app purchases are available.

May return false if:Parental controls block purchasesUser is not signed into an accountPlatform doesn't support IAPmk_iap_init() was not called

Returns true if purchases can be made

mk_iap_pollfunction

void mk_iap_poll(void)

Process pending IAP operations.

Call this every frame to process callbacks from async operations. If using mk_app_run(), this is called automatically.

mk_iap_purchasefunction

void mk_iap_purchase(const char *product_id, mk_iap_purchase_fn callback, void *user_data)

Initiate a purchase.

Opens the platform's purchase UI. The callback is called when the purchase completes, fails, or is cancelled by the user.

ParameterTypeDescription
product_idconst char *Product identifier to purchase
callbackmk_iap_purchase_fnCalled when purchase completes (required)
user_datavoid *User pointer passed to callback

mk_iap_restore_purchasesfunction

void mk_iap_restore_purchases(mk_iap_restore_fn callback, void *user_data)

Restore previous non-consumable and subscription purchases.

Used when users reinstall the app or switch devices. Only restores MK_IAP_NON_CONSUMABLE and MK_IAP_SUBSCRIPTION products.

ParameterTypeDescription
callbackmk_iap_restore_fnCalled when restore completes (required)
user_datavoid *User pointer passed to callback

mk_iap_shutdownfunction

void mk_iap_shutdown(void)

Shutdown the IAP system.

Releases all resources. Any pending operations are cancelled.

mk_iap_web_configurefunction

void mk_iap_web_configure(const mk_iap_web_config_t *config)

Configure the web/custom payment backend.

ParameterTypeDescription
configconst mk_iap_web_config_t *Web configuration

Structs

mk_iap_productstruct

Product information returned from the store.

All string pointers are valid until the next mk_iap_fetch_products() call or mk_iap_shutdown().

FieldTypeDescription
idconst char *Product identifier (SKU).
titleconst char *Localized product title.
descriptionconst char *Localized product description.
priceconst char *Formatted localized price (e.g., "$4.99").
currency_codeconst char *ISO 4217 currency code (e.g., "USD").
price_valuefloatNumeric price in local currency.
typemk_iap_product_type_tProduct type.
subscriptionstruct mk_iap_product::@310202220177241003145166305152321324312356322162The subscription.
subscription.periodmk_iap_subscription_period_tThe period.
subscription.intro_priceconst char *Introductory offer price (NULL if none).
subscription.intro_period_daysintIntro offer duration in days (0 if none).
subscription.has_free_trialboolTrue if free trial is available.
subscription.free_trial_daysintFree trial duration in days.

mk_iap_receiptstruct

Purchase receipt/transaction information.

Contains platform-specific receipt data for server-side validation. String pointers are valid until the callback returns.

FieldTypeDescription
product_idconst char *Product identifier that was purchased.
transaction_idconst char *Unique transaction ID from the store.
receipt_dataconst char *Platform-specific receipt for validation.
purchase_timeuint64_tUnix timestamp (seconds since epoch).
needs_consumeboolTrue if this is a consumable needing consume().
platformunion mk_iap_receipt::@123051041370116350164142276237202274157364377073The platform.
platform.android.order_idconst char *Google Play order ID.
platform.android.purchase_tokenconst char *Token for server verification.
platform.android.purchase_stateint0=Purchased, 1=Pending, 2=Cancelled
platform.ios.app_account_tokenconst char *Optional UUID linking to your user.
platform.ios.environmentconst char *"Production" or "Sandbox"
platform.steam.steam_iduint64_tPurchaser's Steam ID.
platform.steam.order_iduint64_tSteam order ID.
platform.iosstruct mk_iap_receipt::@123051041370116350164142276237202274157364377073::@250212055016146206172342010127166272273147140034The ios.
platform.androidstruct mk_iap_receipt::@123051041370116350164142276237202274157364377073::@343311167355265025332326200240164021042263147320The android.
platform.steamstruct mk_iap_receipt::@123051041370116350164142276237202274157364377073::@223354340154320131303372041360050146242211062254The steam.

mk_iap_web_configstruct

Web/custom backend configuration.

For web builds or when integrating custom payment processors (Stripe, PayPal, etc.), configure the checkout flow here.

FieldTypeDescription
checkout_urlconst char *Base URL for checkout (e.g., "https://your-server.com/checkout").
on_resultmk_iap_web_result_fnCalled when payment window returns a result.
user_datavoid *User context.

Enums

mk_iap_product_typeenum

Product type classification.

ValueDescription
MK_IAP_CONSUMABLEOne-time use (coins, gems, lives).
MK_IAP_NON_CONSUMABLEPermanent unlock (remove ads, levels).
MK_IAP_SUBSCRIPTIONRecurring payment (premium access).

mk_iap_subscription_periodenum

Subscription period (for MK_IAP_SUBSCRIPTION products).

ValueDescription
MK_IAP_PERIOD_UNKNOWNSelects unknown.
MK_IAP_PERIOD_WEEKLYSelects weekly.
MK_IAP_PERIOD_MONTHLYSelects monthly.
MK_IAP_PERIOD_QUARTERLY3 months
MK_IAP_PERIOD_BIANNUAL6 months
MK_IAP_PERIOD_ANNUAL12 months

Typedefs

mk_iap_product_ttypedef

typedef struct mk_iap_product mk_iap_product_t

Product information returned from the store.

All string pointers are valid until the next mk_iap_fetch_products() call or mk_iap_shutdown().

mk_iap_product_type_ttypedef

typedef enum mk_iap_product_type mk_iap_product_type_t

Product type classification.

mk_iap_products_fntypedef

typedef void(*) mk_iap_products_fn(const mk_iap_product_t *products, int count, const char *error, void *user_data)

Callback for product information fetch completion.

mk_iap_purchase_fntypedef

typedef void(*) mk_iap_purchase_fn(const mk_iap_receipt_t *receipt, const char *error, void *user_data)

Callback for purchase completion.

mk_iap_receipt_ttypedef

typedef struct mk_iap_receipt mk_iap_receipt_t

Purchase receipt/transaction information.

Contains platform-specific receipt data for server-side validation. String pointers are valid until the callback returns.

mk_iap_restore_fntypedef

typedef void(*) mk_iap_restore_fn(const mk_iap_receipt_t *receipts, int count, const char *error, void *user_data)

Callback for restore purchases completion.

mk_iap_subscription_period_ttypedef

typedef enum mk_iap_subscription_period mk_iap_subscription_period_t

Subscription period (for MK_IAP_SUBSCRIPTION products).

mk_iap_web_config_ttypedef

typedef struct mk_iap_web_config mk_iap_web_config_t

Web/custom backend configuration.

For web builds or when integrating custom payment processors (Stripe, PayPal, etc.), configure the checkout flow here.

mk_iap_web_result_fntypedef

typedef void(*) mk_iap_web_result_fn(bool success, const char *receipt, void *user_data)

Custom payment result callback for web backends.