Completion Callback

Chargeafter's SDK offers several ways to interact with the application/checkout process, by exposing callbacks that are triggered in various stages throughout the application flow:

These callbacks are fired when user's interaction with the ChargeAfter UI is completed and the modal closes.

The callbacks contain the following properties:

token - a confirmation token that can be used to commit a charge. This parameter will be null if the user was not able to checkout successfully (in case of a decline or error).

data - relevant data for the flow type (apply/checkout) see relevant sections below.

error - in case of error during the flow, or uncompleted flow for whatever reason, this property will contain two properties:

  • message human readable message
  • code a status code indicating what went wrong - further details in relevant section below.

In case of successful checkout/apply the error property will be null.

context - this property will only be sent on SDK completion callback, and will contain the origination of the flow.

Returned data

All callbacks return the following data properties, plus additional ones detailed below according to flow:

FieldTypeDescription
consumerDetailsobjectDetails of the consumer see link
consumerIdstring (optional)The internal id of the consumer
applicationIdstring (Optional)The application id the consumer.
continuationTokenstring (Optional)a token that can be used to continue the checkout flow from the place it stoped before, will be sent based on some condition in the system, for example pending status.
lendersStatusLenderStatus[]Array of lender objects that were part of the application/checkout process, and their responses.

SDK Completion Callback

This callback will always fire when a flow completes, apply or checkout, from widget or from button.

the context argument contains the origination of the flow, including promotion if the flow originated from a promotional widget.

<html>
<body>
    <script>
        const config = {
            apiKey: 'public-api-key',
            onComplete: function(token, data, error, context) {
              const source = context.source;
              const promotion = context.promotion;
            }
        }
    </script>
</body>
</html>

When to use:

  • When there is general functionality that happens regardless of flow source
  • When there is functionality that's required to happen after widget flow - when users finish apply originating from widget, this callback will trigger.

Notice this callback will be triggered even when a specific apply/checkout callback is provided.

Returned data

context

  • source - 'APPLY' | 'CHECKOUT'
  • promotion - returned in case of apply flow
FieldTypeDescription
skustringThe sku of the widget item that originated the flow
pricestringThe price of the widget item that originated the flow
categorystring
tagstring

the rest of callback arguments depend on the flow type, see below sections:

Apply Completion Callback

Will fire whenever an apply flow completes successfully or not.

relevant status codes:

CodeDescription
CONSUMER_CANCELLEDConsumer intentionally closed the Apply UI
CREATE_CHECKOUT_FAILEDApplication creation or merchant settings fetch failed
PENDINGApplication is pending on consumer input (e.g. Driving License)
BACK_TO_STOREConsumer clicked the “Back to Store” button

Usage example:

ChargeAfter.apply.present(
    // This callback allows you to process the result of the application process
    callback: function(data, error) {    
    },
});

Returned data

Data returned in checkout callback will include the following properties, as well as

FieldTypeDescription
availableCreditobjectDetails about the credit that was accepted during the apply flow, see AvailableCredit
lenderLenderThe lender object containing data of the lender, see Lender
accountobjectOn successful application, the full account details will be returned. see Account

Checkout Completion Callback

Will fire whenever a checkout flow completes.

relevant status codes:

CodeDescription
CONSUMER_CANCELLEDConsumer intentionally closed the Checkout UI
CREATE_CHECKOUT_FAILEDCheckout creation or merchant settings fetch failed
GENERALSome general error occurred (message should provide more information)
BILLING_SHIPPING_MISMATCHBilling and shipping address must be the same
BACK_TO_STOREConsumer clicked the “Back to Store” button

Usage example:

// Present the checkout modal box and pass it an options object
ChargeAfter.checkout.present({
    callback: function(token, data, error) {
      
    },
});

Returned data

Data returned in checkout callback will include the following properties, as well as

FieldTypeDescription
lenderLenderThe lender object containing data of the lender, see Lender
offeraccountOfferThe detailed offer accepted by the consumer. See Offer
shippingAmountnumber
taxAmountnumber
totalAmountnumber
ineligibilitiesIneligibilityData[]Contains ineligibility errors retuned by lenders during the flow

Data objects

AccountOffer

FieldTypeDescription
codestring (optional)Unique identifier of the offer
defaultCodestring(optional)
financialProductTypestringLineOfCredit | Installments | LeaseToOwn | MerchantSelfFinancing
defaultAPRnumberOffer APR
amountnumberMaximum amount of the offer
promoSettingsobject (optional)Promotion settings
metadataobject (optional)Can be used to pass additional data for offer
expirationDatestring (optional)Date at which offer expires
checkoutMinimumAmountobject (optional)Optional value to validate checkout cart total amount
descriptionstring (optional)Optional description of the offer as provided by the lender
eligibilityobjectEligibility of the offer
tagsobject (optional)Merchant provided Promotion metadata

Detailed object definitions can be found here: https://docs.chargeafter.com/reference/get_v3-session-accounts

Lender

FieldTypeDescription
idstringUnique identifier of the lender
namestringhuman-readable name of the lender

Expected values can be found here: https://docs.chargeafter.com/reference/lenders

AvailableCredit

FieldTypeDescription
lenderLenderthe lender that provided the credit
creditAmountnumberamount of credit available
financialProductTypestringLineOfCredit | Installments | LeaseToOwn | MerchantSelfFinancing
minimumAmountnumberthe min cart amount required to use this offer
tagsDict<string, string>tags associated with the offer

IneligibilityData

FieldTypeDescription
lenderNameLenderhuman-readable name of the lender
lenderIdnumberUnique identifier of the lender
ineligibilityDetailsIneligibilityDetails[]Contains ineligibility details for corresponding lender

IneligibilityDetails

FieldTypeDescription
reason'cart' | 'product'
descriptionstringhuman-readable description
subReason'minAmount' | 'maxAmount' | 'warranty' | 'leasable' | 'state'