Register Callback Events
After adding the Coda SDK Prefab to your scene, you need to register to the callback events.
Event Listeners
Event Name
Description
OnPurchaseSuccess
Triggered when a payment completes successfully.
OnPurchaseFailed
Triggered when a payment fails, with error details.
OnPriceChanged
Triggered when price updates (e.g., tax adjustments).
Two ways to register listeners:
Inspector Method —
Create and attach your handler script to an empty GameObject, then link its methods to the events of PaymentSDK Script attached to the Coda prefab(Added to Hierarchy in the previous step) using the Inspector Tab. You can create the handler script similar to the following example script:
public class TestCodaSDKCallbacksHandler : MonoBehaviour
{
public void OnPurchaseSuccess(string orderId) {
Debug.Log("Success: " + orderId);
}
public void OnPurchaseFailed(string orderId, string error) {
Debug.Log("Failed: " + error);
}
public void OnPriceChanged(double updatedPrice) {
Debug.Log("Price Updated: " + updatedPrice);
}
}While registering event listeners via Inspector as shown in the video, choose OnPurchaseSuccess, OnPurchaseFailed, OnPriceChanged functions listed under Dynamic params to receive the data from response, not the one listed under static params.
Register event listeners for failure and price update events in the same way. Once registered, your Inspector window for the Coda prefab should look like this:

Programmatic Method — Create and attach your handler script to an empty GameObject, implement
Coda.IPaymentEventListener, and register the event listeners inside your handler script as shown in the following Example:For best practices,
AddListenershould be called in eitherStart()orAwake(), andRemoveListenershould be called inOnDestroy()AddListenershould be called only once to avoid an event listener getting called multiple times for a single event.
Last updated
Was this helpful?