Implement the WebGL SDK Callbacks

To Implement the WebGL SDK, include the following callback methods:

MethodDescriptionParameterType
OnInitializedTriggered when checkout initialization is successful, after calling CheckoutController.Instance.Init(...).
OnInitializeFailedTriggered when checkout initialization fails, after calling CheckoutController.Instance.Init(...).
OnPricePointsSuccessTriggered when price points are successfully retrieved, after calling GetPricePoints.pricePoints
OnPricePointsFailTriggered when price points can't be retrieved or are unavailable, after calling GetPricePoints.error
OnPurchaseSuccessTriggered when a purchase is successful.order
OnPurchaseFailedTriggered when the checkout window is closed or if an error occurs during the purchasing process, displaying an error message.error
OnGetNonConsumeOrdersSuccessTriggered when a list of unconsumed orders is retrieved, after calling GetNonConsumedList.nonConsumedOrdersList
OnGetNonConsumeOrdersFailTriggered when a list of unconsumed orders is retrieved, after calling GetNonConsumedList.error
OnPurchaseConsumedTriggered when a purchase is consumed, after calling ConsumePurchase. The consumed argument indicates whether it was successful.consumedBoolean

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.");
    }
}