Test Adapter used for local testing with mock products.

This adapter simulates a payment platform that supports both In-App Products and Payment Requests.

The list of supported In-App Products

See

Test.TEST_PRODUCTS

Implements

Constructors

Properties

id: Platform = Platform.TEST

Platform identifier

name: string = 'Test'

Nice name for the adapter

products: Product[] = []

List of products managed by the adapter.

ready: boolean = false

true after the platform has been successfully initialized.

The value is set by the "Adapters" class (which is responsible for initializing adapters).

receipts: CdvPurchase.Receipt[] = []

List of purchase receipts.

supportsParallelLoading: boolean = true

Set to true if receipts and products can be loaded in parallel

Accessors

  • get isSupported(): boolean
  • Returns true is the adapter is supported on this device.

    Returns boolean

Methods

  • Finish a transaction.

    For non-consumables, this will acknowledge the purchase. For consumable, this will acknowledge and consume the purchase.

    Parameters

    Returns Promise<undefined | IError>

  • Initializes a platform adapter.

    Will resolve when initialization is complete.

    Will fail with an IError in case of an unrecoverable error.

    In other case of a potentially recoverable error, the adapter will keep retrying to initialize forever.

    Returns Promise<undefined | IError>

  • Open the platforms' billing management interface.

    Returns Promise<undefined | IError>

  • Initializes an order.

    Parameters

    Returns Promise<undefined | IError>

  • This function simulates a payment process by prompting the user to confirm the payment.

    It creates a Receipt and Transaction object and returns the Transaction object if the user enters "Y" in the prompt.

    Parameters

    Returns Promise<undefined | IError | CdvPurchase.Transaction>

    A promise that resolves to either an error object (if the user enters "E" in the prompt), a Transaction object (if the user confirms the payment), or undefined (if the user does not confirm the payment).

    Example

    const paymentRequest = {
    amountMicros: 1000000,
    currency: "USD",
    items: [{ id: "product-1" }, { id: "product-2" }]
    };
    const result = await requestPayment(paymentRequest);
    if (result?.isError) {
    console.error(`Error: ${result.message}`);
    } else if (result) {
    console.log(`Transaction approved: ${result.transactionId}`);
    } else {
    console.log("Payment cancelled by user");
    }
  • Replay the queue of transactions.

    Might ask the user to login.

    Returns Promise<undefined | IError>