Entry class of the plugin.

Constructors

Properties

applicationUsername?: string | (() => undefined | string)

Return the identifier of the user for your application.

This value is obfuscated according to Store.obfuscator before being sent to the native platform API. The default obfuscator ('legacy') hashes or formats the value so the original username is never transmitted in cleartext.

For Apple's App Store, the obfuscated value is used as appAccountToken (which must be a valid UUID when using StoreKit 2).

You can also pass it per-transaction via additionalData.applicationUsername in store.order() or store.requestPayment(), which takes priority.

Type declaration

    • (): undefined | string
    • Returns undefined | string

log: Logger = ...

Logger

minTimeBetweenUpdates: number = 600000

Avoid invoking store.update() if the most recent call occurred within this specific number of milliseconds.

obfuscator?: Obfuscator

Obfuscation strategy for the application username.

Controls how applicationUsername is transformed before being sent to each platform's native API. 'uuid' is the recommended setting for new integrations; the default 'legacy' exists only for backward compatibility with server-side modules that already correlate against the raw 32-hex MD5 value.

Default

'legacy'

See

Obfuscator

validator: undefined | string | Function | Target

URL or implementation of the receipt validation service

Example

Define the validator as a string

CdvPurchase.store.validator = "https://validator.iaptic.com/v1/validate?appName=test"

Example

Define the validator as a function

CdvPurchase.store.validator = (receipt, callback) => {
callback({
ok: true,
data: {
// see CdvPurchase.Validator.Response.Payload for details
}
})
}

See

CdvPurchase.Validator.Response.Payload

validator_privacy_policy: undefined | PrivacyPolicyItem | PrivacyPolicyItem[]

When adding information to receipt validation requests, those can serve different functions:

  • handling support requests
  • fraud detection
  • analytics
  • tracking

Make sure the value your select is in line with your application's privacy policy and your users' tracking preference.

Example

CdvPurchase.store.validator_privacy_policy = [
'fraud', 'support', 'analytics', 'tracking'
]
verbosity: LogLevel = LogLevel.ERROR

Verbosity level used by the plugin logger

Set to:

  • LogLevel.QUIET or 0 to disable all logging (default)
  • LogLevel.ERROR or 1 to show only error messages
  • LogLevel.WARNING or 2 to show warnings and errors
  • LogLevel.INFO or 3 to also show information messages
  • LogLevel.DEBUG or 4 to enable internal debugging messages.
version: string = PLUGIN_VERSION

Version of the plugin currently installed.

Accessors

  • get isReady(): boolean
  • true if the plugin is initialized and ready

    Returns boolean

  • get products(): Product[]
  • List of all active products.

    Products are active if their details have been successfully loaded from the store.

    Returns Product[]

  • get verifiedReceipts(): VerifiedReceipt[]
  • List of receipts verified with the receipt validation service.

    Those receipt contains more information and are generally more up-to-date than the local ones.

    Returns VerifiedReceipt[]

Methods

  • Returns true if a platform supports the requested functionality.

    Parameters

    Returns boolean

    Example

    store.checkSupport(Platform.APPLE_APPSTORE, 'requestPayment');
    // => false
  • The default payment platform to use depending on the OS.

    • on iOS: APPLE_APPSTORE
    • on Android: GOOGLE_PLAY

    Returns Platform

  • Register an error handler.

    Parameters

    • error: Callback<IError>

      An error callback that takes the error as an argument

    Returns void

    Example

    store.error(function(error) {
    console.error('CdvPurchase ERROR: ' + error.message);
    });
  • Find the last verified purchase for a given product, from those verified by the receipt validator.

    Parameters

    Returns undefined | VerifiedPurchase

  • Find a product from its id and platform

    Parameters

    • productId: string

      Product identifier on the platform.

    • Optional platform: Platform

      The product the product exists in. Can be omitted if you're only using a single payment platform.

    Returns undefined | Product

  • Get the application username as a string by either calling or returning Store.applicationUsername

    Returns undefined | string

  • Retrieve the billing country code from the platform's storefront.

    Returns a Storefront object with the platform and its ISO 3166-1 alpha-2 country code (e.g., "US", "FR"). The country code may be undefined if the underlying fetch has not yet completed or failed — the platform is still reported. Returns undefined only when no matching adapter is ready.

    The cache is populated before the storeReady event fires (with a best-effort timeout), and refreshed after orders and restorePurchases().

    Parameters

    • Optional platform: Platform

      Optional platform. If omitted, returns the first cached non-empty storefront, or a { platform, countryCode: undefined } object for the first ready adapter.

    Returns undefined | Storefront

    Example

    const storefront = store.getStorefront();
    if (storefront?.countryCode) {
    console.log(`Billing country: ${storefront.countryCode}`);
    }
  • Call to initialize the in-app purchase plugin.

    Parameters

    Returns Promise<IError[]>

  • Opens the billing methods page on AppStore, Play, Microsoft, ...

    From this page, the user can update their payment methods.

    If platform is not specified, the first available platform will be used.

    Parameters

    Returns Promise<undefined | IError>

    Example

    if (purchase.isBillingRetryPeriod)
    store.manageBilling(purchase.platform);
  • Open the subscription management interface for the selected platform.

    If platform is not specified, the first available platform will be used.

    Parameters

    Returns Promise<undefined | IError>

    Example

    const activeSubscription: Purchase = // ...
    store.manageSubscriptions(activeSubscription.platform);
  • Setup a function to be notified of changes to a transaction state.

    Parameters

    Returns TransactionMonitor

    A monitor which can be stopped with monitor.stop()

    Example

    const monitor = store.monitor(transaction, state => {
    console.log('new state: ' + state);
    if (state === TransactionState.FINISHED)
    monitor.stop();
    });
  • Remove a callback from any listener it might have been added to.

    Type Parameters

    • T

    Parameters

    Returns void

  • Return true if a product is owned

    Important: The value will be false when the app starts and will only become true after purchase receipts have been loaded and validated. Without receipt validation, it might remain false depending on the platform, make sure to store the ownership status of non-consumable products in some way.

    Parameters

    • product: string | {
          id: string;
          platform?: Platform;
      }

      The product object or identifier of the product.

    Returns boolean

  • Register a callback to be called when the plugin is ready.

    This happens when all the platforms are initialized and their products loaded.

    Parameters

    Returns void

  • Returns void

    Deprecated

    • use store.initialize(), store.update() or store.restorePurchases()
  • Register a product.

    Returns void

    Example

    store.register([{
    id: 'subscription1',
    type: ProductType.PAID_SUBSCRIPTION,
    platform: Platform.APPLE_APPSTORE,
    }, {
    id: 'subscription1',
    type: ProductType.PAID_SUBSCRIPTION,
    platform: Platform.GOOGLE_PLAY,
    }, {
    id: 'consumable1',
    type: ProductType.CONSUMABLE,
    platform: Platform.BRAINTREE,
    }]);

    // Can also be used in development to register test products
    store.register([{
    id: 'my-custom-product',
    type: CdvPurchase.ProductType.CONSUMABLE,
    platform: CdvPurchase.Platform.TEST,
    title: '...',
    description: 'A custom test consumable product',
    pricing: {
    price: '$2.99',
    currency: 'USD',
    priceMicros: 2990000
    }
    }]);
  • Replay the users transactions.

    This method exists to cover an Apple AppStore requirement.

    Returns Promise<undefined | IError>

  • Call to refresh the price of products and status of purchases.

    Returns Promise<void>

  • Register event callbacks.

    Events overview:

    • productUpdated: Called when product metadata is loaded from the store
    • receiptUpdated: Called when local receipt information changes (ownership status change, for example)
    • verified: Called after successful receipt validation (requires a receipt validator)

    Returns When

    Example

    // Monitor ownership with receipt validation
    store.when()
    .approved(transaction => transaction.verify())
    .verified(receipt => {
    if (store.owned("my-product")) {
    // Product is owned and verified
    }
    });

    Example

    // Monitor ownership without receipt validation
    store.when().receiptUpdated(receipt => {
    if (store.owned("my-product")) {
    // Product is owned according to local data
    }
    });