Skip to main content

PURCHASE

Purchase flow

Purchasing flow is a multistage process, which involves payment collection, purchase validation and consumption.

Starting purchasing flow

Use one of the snippets below to launch a purchasing flow depending on whether you use Unity InApp Purchasing or not:

_storeController.InitiatePurchase(product);

// ...

public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs purchaseEvent)
{
// handle the purchased item here

return PurchaseProcessingResult.Complete;
}

Handling user cancellation

When a player cancels a purchase, handle it separately from actual errors.

public void OnPurchaseFailed(Product product, PurchaseFailureReason failureReason)
{
if (failureReason == PurchaseFailureReason.UserCancelled)
{
// User cancelled the purchase — don't show an error
return;
}

// Handle other failure reasons
}

// Or (newer API)
public void OnPurchaseFailed(Product product, PurchaseFailureDescription failureDescription)
{
if (failureDescription.reason == PurchaseFailureReason.UserCancelled)
{
// User cancelled the purchase — don't show an error
return;
}

// Handle other failure reasons
}
warning

Although validation is NOT a mandatory step, yet it's highly recommended to minimize the chance of fraud and any other malevolent intents.

For instructions on how to validate your purchases, see Purchase Validation guide.

Consuming purchased goods

The very final step in the chain of purchasing flow stages is to award the purchased goods to the user and mark these goods as "awarded". The process also known as purchase consumption.

Use the code below to do just that:

_storeController.InitiatePurchase(product);

// ....

public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs purchaseEvent)
{
// handle purchased item

return PurchaseProcessingResult.Pending;
}

// ....

_storeController.ConfirmPendingPurchase(product);
important

It's highly recommended to perform at least some form of validation before consuming the purchased goods.