Custom Purchase Reporting

Report purchases that are made outside of the Beamable payment flow and validation [ECON-Stores-06]

Introduction

As a game maker you will find that in some cases you need to be able to report purchases from outside the Beamable store flow. Beamable provides you with a way to do this through a small configuration change in Portal and some client side tracking code.

Configuration

As shown in the above example, you will need to set a key in your Realm configuration to override purchase reporting to enable this functionality. Without this configuration change the API will error and not report anything.

Here we are setting the namespace to payments and then the key is client_audits and we will set the value to true.

❗️

Security Warning

This feature is not secure unless you track this from within a MicroService and validate the purchase. It is highly advisable to do so in order to not allow a customer to spoof or false track a purchase.

Implementation

Once your configuration has been setup to allow this API to function, then you can use the .Api.PaymentService.Track API to track the purchase. The various fields of the tracking request may be arbitrary strings of your choice, but for the sake of consistency you may want to match the patterns used by the Beamable Commerce Service.

PropertyDetails
purchaseIdThe identifier of the thing that was purchased; usually a listingscontent ID.
storeThe store ID through which the purchase was made; usually a stores content ID.
skuNameThe stock keeping unit (SKU); usually a skus content ID.
skuProductIdThe product ID referenced by the internal SKU; usually a provider-specific ID such as com.example.mygame.bundle10.
priceInLocalCurrencyPurchase amount, including decimals. For example 9.99 would represent $9.99 if the currency symbol is USD.
isoCurrencySymbolCurrency symbol such as "USD", "EUR", and so on.
obtainCurrency[Optional] Currency changes that were part of this purchase. This does NOT perform the fulfillment; it is merely a record.
obtainItem[Optional] Item grants that were part of this purchase. This does NOT perform the fulfillment; it is merely a record.

Code example:

private async Task TrackSomePurchase()
{
    var ctx = await BeamContext.Default.Instance;
    var random = new Random();

    var purchaseId = "listings.ten_bucks_for_some_coins";
    var skuName = "skus.ten_dollar_pack";
    var productId = "com.beamable.example.d10";
    var store = "stores.default";
    var price = 9.99;
    var isoCurrency = "USD";
    var obtainCurrencies = new List<ObtainCurrency>
    {
        new() { amount = random.Next(10), symbol = "currency.coins" }
    };
    var obtainItems = new List<ObtainItem>
    {
        new()
        {
            contentId = "items.diamond_1",
            properties = new List<ItemProperty> { new() { name = "color", value = "blue" } }
        }
    };
    var trackRequest = new TrackPurchaseRequest(
      purchaseId,
      skuName,
      productId,
      store,
      price,
      isoCurrency,
      obtainCurrencies,
      obtainItems
    );
    await ctx.Api.PaymentService.Track(trackRequest);
    Debug.Log("Request tracked.");
}

View Results

Once you do the above tracking, you can view the results by going to the Portal and clicking on *Real Money Transactions under the Monetization section. Within a few minutes at most, the tracking that was posted should appear there and you can view the details of your transactions.

In addition, the dashboards on the Realm should reflect the purchase as well.