External validation

Overview

If you have custom/external purchases validation service, you can bypass Magify's validation and send validated purchase data directly from your client or server-to-server. In this case, the responsibility for ensuring the integrity of the transactions lies on your side.

1. Sending from client

We call this type of purchase tracking "trusted purchases", which implies that you have already validated your purchases and we can trust the revenue data.

To track it you need to create a TrustedPurchaseRecord data model, that contains all the necessary information about valudated transaction. We highly recommend not to use constructors of this class, but instead use static constructor methods that cover all possible and necessary for Magify events related to trusted purchases.

In order to pass the trusted purchase data to Magify for further analytics processing and reporting, you need to pass the created record to PurchaseInfo which is usually created after a purchase is made, see IMinimalInAppStore or IInAppStore. Once the record value is set, you can continue processing PurchaseInfo and pass it on to Magify.

PurchaseProcessingResult IStoreListener.ProcessPurchase(PurchaseEventArgs e)
{
    var product = e.purchasedProduct;
    var purchaseInfo = new PurchaseInfo(product, LoadSubscriptionInfo(product.definition.id));
    // start your verification process
    return PurchaseProcessingResult.Pending;
}

public void HandleYOURVerificationFinished(PurchaseInfo purchaseInfo)
{
    // here you fill TrustedPurchaseRecord of exact kind with verified fields:
    purchaseInfo.TrustedPurchaseRecord = TrustedPurchaseRecord.CreateForConsumableInApp(productId, transactionId, timestamp, price, currency, storeFront, store);
    // in case it's subscription add following lines:
    // if (purchaseInfo.SubscriptionInfo != null)
    //    OnSubscriptionPurchaseFinished?.Invoke(productId, purchaseInfo);
    OnPurchaseFinished?.Invoke(productId, purchaseInfo);
}

TrustedPurchaseRecord.CreateForConsumableInApp(productId, transactionId, timestamp, price, currency, storeFront, store)

2. Server-to-Server

Since the current page covers only SDK (client) side work, it will not describe how to configure Server-to-server communication (you can learn more about this by contacting Magify manager). However, you should also keep in mind that on the client side you will need to make small tweaks to make the approach work correctly.

Although the purchase validity data will be sent directly to the server, the client side has to send some necessary analytics data itself, so even in this case you need to track purchases on the client side, but with a small peculiarity: after making a purchase, when creating an instance of PurchaseInfo (see IMinimalInAppStore or IInAppStore) you must set the SkipVerification flag to True.

PurchaseProcessingResult IStoreListener.ProcessPurchase(PurchaseEventArgs e)
{
    var product = e.purchasedProduct;
    var purchaseInfo = new PurchaseInfo(product, LoadSubscriptionInfo(product.definition.id), skipVerification: true);
    if (purchaseInfo.SubscriptionInfo != null)
        OnSubscriptionPurchaseFinished?.Invoke(product.definition.id, purchaseInfo);
    OnPurchaseFinished?.Invoke(product.definition.id, purchaseInfo);
    return PurchaseProcessingResult.Complete;
}

In this case Magify SDK will not request validation using Magify services. This completes the configuration of Server-to-server validation on the client side. Once the property value is set, you can continue processing PurchaseInfo and pass it on to Magify.

Related articles

PeriodType

Popups

API Collection

CrossPromoProduct

ICampaignWithProducts

Customization