To Implement the WebGL SDK, include the following callback methods:
Method | Description | Parameter | Type |
---|---|---|---|
OnInitialized | Triggered when checkout initialization is successful, after calling CheckoutController.Instance.Init(...) . | ||
OnInitializeFailed | Triggered when checkout initialization fails, after calling CheckoutController.Instance.Init(...) . | ||
OnPricePointsSuccess | Triggered when price points are successfully retrieved, after calling GetPricePoints . | pricePoints | |
OnPricePointsFail | Triggered when price points can't be retrieved or are unavailable, after calling GetPricePoints . | error | |
OnPurchaseSuccess | Triggered when a purchase is successful. | order | |
OnPurchaseFailed | Triggered when the checkout window is closed or if an error occurs during the purchasing process, displaying an error message. | error | |
OnGetNonConsumeOrdersSuccess | Triggered when a list of unconsumed orders is retrieved, after calling GetNonConsumedList . | nonConsumedOrders | List |
OnGetNonConsumeOrdersFail | Triggered when a list of unconsumed orders is retrieved, after calling GetNonConsumedList . | error | |
OnPurchaseConsumed | Triggered when a purchase is consumed, after calling ConsumePurchase . The consumed argument indicates whether it was successful. | consumed | Boolean |
Note: The interface includes three callback methods for purchase consumption, but their implementation is not relevant and therefore not applicable in this context.
Example code
Below is the example code for the implementation:
public class PurchaseHandler : ICheckoutPurchase
{
public void OnInitialized()
{
// Initialization was successful. You can now call GetPricePoints().
Debug.Log("Initialization successful.");
}
public void OnInitializeFailed(ErrorMessage error)
{
Debug.Log(string.Format("Code: {0}\nMessage: {1}\nDetails: {2}", error.code, error.message, error.data));
}
public void OnPricePointsSuccess(PricePointsModel pricePoints)
{
// You can now display the localized pricing in the webstore.
Debug.Log(string.Format("Total Found: {0}", pricePoints.pricingPoints.Length));
}
public void OnPricePointsFail(ErrorMessage error)
{
Debug.Log(string.Format("Code: {0}\nMessage: {1}\nDetails: {2}", error.code, error.message, error.data));
}
public void OnPurchaseSuccess(OrderResponseModel order)
{
// Purchase was successful.
Debug.Log(string.Format("Purchase Success:\nOrderId: {0}\nPayment Method: {1}", order.orderId, order.paymentMethodName));
}
public void OnPurchaseFailed(ErrorMessage error)
{
Debug.Log(string.Format("Code: {0}\nMessage: {1}\nDetails: {2}", error.code, error.message, error.data));
}
public void OnGetNonConsumeOrdersSuccess(List<string> nonConsumedOrders)
{
Debug.Log("OnGetNonConsumeOrdersSuccess:");
foreach (string order in nonConsumedOrders)
{
Debug.Log(order);
}
}
public void OnGetNonConsumeOrdersFail(ErrorMessage error)
{
Debug.Log("OnGetNonConsumeOrdersFailed: " + error.message);
}
public void OnPurchaseConsumed(bool consumed)
{
Debug.Log(consumed ? "Purchase consumed." : "Failed to consume purchase.");
}
}