Class TInAppPurchases

DescriptionHierarchyFieldsMethodsProperties

Unit

Declaration

type TInAppPurchases = class(TComponent)

Description

Manage in-app purchases in your game.

Usage: simply construct an instance of this class (or a subclass – it is useful to override some methods of this class for a particular game). Call SetAvailableProducts to get the prices and ownership information about items. Use various methods to query information about the products and to buy products (Purchase).

To include the necessary integration code in your Android project, declare your Android project type as "integrated" with the "google_in_app_purchases" component inside CastleEngineManifest.xml. See https://github.com/castle-engine/castle-engine/wiki/Android-Project-Services-Integrated-with-Castle-Game-Engine .

You have to create the products to purchase, and their prices in various currencies, in the Google Developer Console. The names of products you provide to SetAvailableProducts or Product methods should correspond to product names you set in the Google Developer Console.

Hierarchy

  • TComponent
  • TInAppPurchases

Overview

Methods

Protected procedure KnownCompletely; virtual;
Protected procedure SuccessfullyConsumed(const AProduct: TInAppProduct); virtual;
Protected procedure Owns(const AProduct: TInAppProduct); virtual;
Public constructor Create(AOwner: TComponent); override;
Public destructor Destroy; override;
Public procedure SetAvailableProducts(const Names: array of string);
Public procedure SetAvailableProducts(const Products: array of TAvailableProduct);
Public procedure Purchase(const AProduct: TInAppProduct);
Public procedure Consume(const AProduct: TInAppProduct);
Public function Product(const ProductName: string): TInAppProduct;

Properties

Public property DebugMockupBuying: boolean read FDebugMockupBuying write FDebugMockupBuying default false;

Description

Methods

Protected procedure KnownCompletely; virtual;

Called when the knowledge about what do we own is complete.

Protected procedure SuccessfullyConsumed(const AProduct: TInAppProduct); virtual;

Called when the product is successfully consumed, in response to the Consume call.

In this class, this simply sets Product.SuccessfullyConsumed flag to True, and waits for some other code (maybe overridden SuccessfullyConsumed implementation, maybe something else) will handle it and reset the Product.SuccessfullyConsumed flag to False.

Protected procedure Owns(const AProduct: TInAppProduct); virtual;

Called when we know the product is owned, in particular when it's successfully bought.

If the product is a consumable, which means it has a one-time use (and should disappear afterwards, until user will buy it again), then:

  1. Call the Consume method once you know the item is owned. You can call Consume directly from the overridden implementation of Owns, this is often the simplest approach.

  2. Actually perform the consumption (bump the player gold, grant extra life and so on) only when the item is successfully consumed. You are notified about this by the SuccessfullyConsumed call (you can override it), or you can watch if the TInAppProduct.SuccessfullyConsumed flag is set.

    Do not give any one-time gain as a response to the Owns call. Always wait for SuccessfullyConsumed call.

    This protects you from the scenario when you're notified that you own the item multiple times (which may happen, since purchases may be resumed asynchronously while other code is executing), and you call Consume twice. The SuccessfullyConsumed will only fire once, if user bought item once.

Public constructor Create(AOwner: TComponent); override;
 
Public destructor Destroy; override;
 
Public procedure SetAvailableProducts(const Names: array of string);

Initialize a list of products for which to query prices from server. The overloaded version with TAvailableProduct allows to provide additional information to the in-app payment system, see TAvailableProduct docs.

Public procedure SetAvailableProducts(const Products: array of TAvailableProduct);
 
Public procedure Purchase(const AProduct: TInAppProduct);

Initiate a purchase of given item.

Public procedure Consume(const AProduct: TInAppProduct);

Initiate a consumption of a consumable item. You should listen on a "successful consumption" (override SuccessfullyConsumed method and/or watch TInAppProduct.SuccessfullyConsumed) until you actually act on the consumption (increase player gold or such).

Public function Product(const ProductName: string): TInAppProduct;

Find product with given name.

Creates and adds new product, if not found (useful in case you asked for a product before information about it arrived from the net, or before you even called SetAvailableProducts with it).

Properties

Public property DebugMockupBuying: boolean read FDebugMockupBuying write FDebugMockupBuying default false;

Purely for debug purposes, mockup buying (pretend that all purchases succeed).


Generated by PasDoc 0.14.0.