Callback methods
To implement the Unity Payment Links SDK, include the following callback methods:| Method | Description | Argument | Type |
|---|---|---|---|
OnInitialized | Triggered when SDK initialization was successful. | ||
OnInitializeFailed | Triggered when SDK initialization failed. | error | ErrorMessage |
OnPricePointsSuccess | Triggered when price points are successfully retrieved, after calling GetPricePoints. Not triggered on WebGL, however, your implementation must include this method as it is part of the required interface. | pricePoints | PricePointsModel |
OnPricePointsFail | Triggered when price points can’t be retrieved or are unavailable, after calling GetPricePoints. GetPricePoints isn’t supported on WebGL. If you need price points data for WebGL, you can retrieve it independently via the Price Points API. | error | ErrorMessage |
OnPurchaseSuccess | Triggered when a purchase was successful. | order | OrderResponseModel |
OnPurchaseFailed | Triggered when the checkout window closed or if a server-to-server error occurred during the purchasing process. Returns an error code, message, JSON, and order details. | error, order | ErrorMessage, OrderResponseModel |
OrderResponseModel properties
TheOrderResponseModel argument type contains the following properties:
| Property Name | Type | Description | Example |
|---|---|---|---|
date | Int | Unix timestamp of the order. | 1718182312 |
sessionToken | String | Unique token for the current session. | "xxxxXXXXxxxxXXXXxxxx" |
offerName | String | Name of the purchased offer. | "Starter Pack" |
offerSku | String | SKU identifier for the offer. | "starter_pack_001" |
items | [Item] | List of items included in the purchase. | [{ name: "Gems", sku: "gem_01", quantity: "100" }] |
items.name | String | Display name of the item. | "Gems" |
items.sku | String | Unique SKU code for the item. | "gem_01" |
items.quantity | String | Quantity of the item included. | "100" |
price | Int | Price of the order in minor units. For example, cents for USD. | 499 |
currency | String | ISO 4217 currency code | "USD" |
customerId | String | ID of the player who made the purchase. | "cust_98765" |
customerCountry | String | Country code of the player in ISO 3166-1 alpha-2 format. | "US" |
paymentMethodName | String | Payment method. | "Visa" |
orderId | String | Order ID. | "1234567890" |
purchaseId | String | A unique ID to track the transaction. | "pr_xxxxxx" |
ErrorMessage properties
TheErrorMessage argument type contains the following properties:
| Property Name | Type | Description | Example |
|---|---|---|---|
code | Int | Error code identifying the failure. | 3002 |
message | String | Detailed message describing the failure. | "Purchase canceled because the user closed the checkout interface." |
Example code
using Appcharge.PaymentLinks.Models;
using Appcharge.PaymentLinks.Interfaces;
using UnityEngine;
public class AppchargeCallbackImpl : ICheckoutPurchase
{
public void OnInitialized()
{
Debug.Log("SDK initialization was successful.");
}
public void OnInitializeFailed(ErrorMessage error)
{
Debug.Log("SDK initialization failed.");
}
public void OnPricePointsSuccess(PricePointsModel pricePoints)
{
Debug.Log("Price points retrived.");
}
public void OnPricePointsFail(ErrorMessage error)
{
Debug.Log("Failed to retrieve price points.");
}
public void OnPurchaseSuccess(OrderResponseModel order)
{
Debug.Log("Purchase was successful: " + order.orderId);
}
public void OnPurchaseFailed(ErrorMessage error, OrderResponseModel order)
{
Debug.Log("Purchase failed: " + (order != null ? order.orderId : "no order found"));
}
}
