Validating Purchases

Our Purchase Validator package is designed to work with Unity Purchasing v4 and v5.

Purchase Payload

A simple helper class is provided to extract and prepare all required validation data from Unity’s purchase response.

Unity Purchasing v4

var payload = PurchasePayloadHelper.Parse(product);

Unity Purchasing v5

var payload = PurchasePayloadHelper.Parse(product, order);

Validate

Once you have a valid payload, pass it into the validator:

var response = await PurchaseValidator.Validate(
    payload, 
    gameplayInfo, 
    onSuccess, 
    onFailure, 
    additionalData);

Payload

Pass the payload generated by PurchasePayloadHelper.

GameplayInfo

Used for analytics. Include the items and currency the player receives from the purchase.

Example:

var gameplayInfo = new IAPGameplayInfo(
    new List<Item>()
    {
        new Item("NoAds", 1),
        new Item("SpecialWeapon", 1),
    },
    new List<VirtualCurrency>()
    {
        new VirtualCurrency("coins", "normal", 10000),
        new VirtualCurrency("gems", "special", 10)
    },
    "shop"
);

OnSuccess

Called when the purchase is successfully validated. Grant rewards or handle post-purchase logic here.

OnFailure

Called when validation fails. The validation status is returned so you can handle the failure accordingly.

AdditionalData

Optional analytics data to include with the validation request.

Validation Response

The validation response is intentionally simple and contains the result of the validation request along with any relevant metadata.

public class ValidationResponse
{
    public ValidationStatus status;
    public string message;
    public long code;
    public bool sandbox;
    public string transactionId;
}

Status

Represents the outcome of the validation request.

Passed

The purchase passed validation successfully.

Skipped

No validation was performed for the purchase.

Failed

The purchase failed validation.

Error

An error occurred during validation.

Message

A message returned from the server. This may include additional details about validation failures, warnings, or other processing information.

Code

An internal response or error code returned by the server.

Sandbox

Indicates whether the purchase was processed in a sandbox environment. This is returned when that information is available from the server.

Transaction Id

The validated transaction identifier returned by the server.

Last updated

Was this helpful?