Handle Fast Android SDK Events

The Fast SDK will send events that convey information about the user's shopping journey through the Fast checkout flow. The SDK will communicate with the seller app via callbacks as the user performs actions within the checkout flow.

Callbacks

As the user progresses through the Fast checkout experience, callbacks will notify your app about significant events. You can listen for these events by passing in a callback object. You will need to define the method in your activity / fragment to listen to callbacks.

Copy
Copied to Clipboard
private fun onFastCheckoutEvent(event: FastCheckoutEvent) {
    when (event) {
        is FastCheckoutEvent.OrderCanceled -> {
            Log.i(LOG_TAG, "Event: OrderCanceled: ${event.purchaseInfo}")
        }
        is FastCheckoutEvent.OrderCompleted -> {
            Log.i(LOG_TAG, "Event: OrderCompleted: ${event.purchaseInfo}")
        }
        is FastCheckoutEvent.OrderCreated -> {
            Log.i(LOG_TAG, "Event: OrderCreated: ${event.purchaseInfo}")
        }
        is FastCheckoutEvent.OrderFailed -> {
            Log.i(LOG_TAG, "Event: OrderFailed: ${event.throwable}")
        }
        is FastCheckoutEvent.OrderUpdated -> {
            Log.i(LOG_TAG, "Event: OrderUpdated: ${event.purchaseInfo}")
        }
        FastCheckoutEvent.SDKClosed -> {
            Log.i(LOG_TAG, "Event: SDKClosed: ${event.purchaseInfo}")
        }
        // Please keep this else clause. Fast may add more events in the future without updating the SDK's major version.
        else -> Log.i(LOG_TAG, "Event: Unhandled event: $event")
    }
}

FastCheckoutEvent

A FastCheckoutEvent is emitted by the SDK at key stages during the checkout flow. Your app can handle these via the onFastCheckoutEvent() function.

NameTypeDescription
FastCheckoutEventParcelable objectAdditional relevant data regarding the event.
FastCheckoutEvent.purchaseInfoPurchaseInfoAdditional relevant data regarding the event. Refer to PurchaseInfo Data Class Breakdown for more details.

FastCheckoutEvent Types

The FastCheckoutEvent contains these events and associated data payloads.

EventDescriptionAssociated Data
OrderCreatedEmitted when the order has been successfully submitted through Fast Checkout.PurchaseInfo
OrderUpdatedEmitted when Shopper updates order information like item quantity, removes an item, or adds a coupon.PurchaseInfo
OrderCompletedEmitted when order is finalized. This means that the batching window has ended and the user cannot update the order. If the user closes the SDK before batching window has ended, you won't get this event and instead get the SDKClosed event.PurchaseInfo
OrderCanceledEmitted when user cancels the order.PurchaseInfo
OrderFailedEmitted when checkout fails with an errorThrowable?
SDKClosedShopper has exited the Fast Android SDK. If Shopper exits post-purchase, PurchaseInfo will be sent with the event. If Shopper exits before clicking on CompletePurchase, null will be sent with the event.PurchaseInfo
Associated Data Returned by Non-Order Events

Please note that non-order events will have different associated data.

  • OrderFailed (indicating a checkout failure) emits a Throwable?, which is a nullable kotlin.Throwable object that wraps an error.
  • SDKClosed will usually emit no additional data, but can emit PurchaseInfo data if the SDK is closed following a successful order (similar to the OrderCompleted event).

PurchaseInfo Data Class Breakdown

PurchaseInfo is a data class that contains information about the Shopper's order.

NameTypeDescription
PurchaseInfodata classA representation of a Shopper's purchase in the seller's backend platform.
PurchaseInfo.platformIdStringThe ID of a purchase as represented in the seller's backend platform.
PurchaseInfo.revenueStringThe purchase total, including tax, shipping, and discounts.
PurchaseInfo.taxStringTotal taxes for this purchase.
PurchaseInfo.shippingStringCost of shipping for this purchase.
PurchaseInfo.currencyCodeString3-character ISO 4217 currency code.
PurchaseInfo.couponString(Optional) Coupon, if any, included with this purchase.
PurchaseInfo.checkoutTimeDateAn enum describing the event.
PurchaseInfo.itemsPurchaseItem ListAdditional relevant data regarding the event.
Copy
Copied to Clipboard
  data class PurchaseInfo(

    //The ID of a purchase as represented in the seller's backend platform.
    val platformId: String,

    // The purchase total, including tax, shipping, and discounts.
    val revenue: String,

    // Total taxes for this purchase.
    val tax: String,

    // Cost of shipping for this purchase.
    val shipping: String,

    // The 3-letter ISO 4217 currency code.
    val currencyCode: String?,

    // Coupon, if any, included in this purchase.
    val coupon: String?,

    // Time of checkout.
    val checkoutTime: Date?,

    // The products included in this purchase.
    val items: List<PurchaseItem>
)

PurchaseItem Data Class Breakdown

NameTypeDescription
PurchaseItemdata classObject describing a product that is part of a purchase.
PurchaseItem.platformIdStringThe ID of a product as represented in the seller's backend platform.
PurchaseItem.platformVariantIdStringThe ID of a product variant as represented in the seller's backend platform.
PurchaseItem.priceStringThe price of a product (excluding discounts, tax, etc.).
PurchaseItem.nameStringThe name of a product as displayed to the user.
PurchaseItem.countryCodeStringThe 3-character ISO 4217 currency code for the purchase.
PurchaseItem.quantityIntThe number / count for the specified item in a purchase.
PurchaseItem.couponString(Optional) Coupon, if any, included with this purchase.
Copy
Copied to Clipboard
data class PurchaseItem(
        // The ID of a product as represented in the seller's backend platform.
        val platformId: String,

        // The ID of a product variant as represented in the seller's backend platform.
        val platformVariantId: String?,

        //The name of a product as displayed to the user.
        val name: String,

        //The price of a product (not including discounts, tax, etc.).
        val price: String,

        // The number of this item that was included in a purchase.
        val quantity: Int,

        // Any discount applied to this product's price.
        val coupon: String?,
    )