onComplete

Chargeafter's SDK offers several ways to interact with the Apply/Checkout process by exposing callbacks that are triggered in various stages throughout the flow.

The following callbacks are fired when a user's interaction with the ChargeAfter UI is completed and the modal closes:

SDK Completion Callback

This global callback always fires when the Apply/Checkout flow completes, from a widget or button.

Note: This callback will be triggered even when a specific Apply/Checkout Completion callback is provided.

Code sample

ChargeAfter.init({
  // some other config
  onComplete: function(token, data, status, context){
    // some handling 
  },
})

Properties

FieldTypeDescription
tokenstringA confirmation token that can be used to commit a charge.
This parameter will be null for users in the Apply flow and for users that were not able to complete the Checkout flow successfully (due to decline or error).
dataobjectRelevant data for the flow type (Apply/Checkout). See Returned data in the Apply Completion Callback and the Checkout Completion Callback below.
statusobjectIn cases of an error during the flow, or an uncompleted flow for whatever reason, this object will contain two properties:
code: a status code indicating the status.
message: a human readable message
If the Apply/Checkout flow was successful, then the status object will be null or undefined. See Relevant status codes in the Apply Completion Callback and the Checkout Completion Callback below.
contextobjectIndicates the origination of the flow. See Context argument below.

Context argument

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, status, context) {
              const source = context.source;
              const promotion = context.promotion;
            }
        }
    </script>
</body>
</html>

The context argument should be used when:

  • General functionality is required to occur regardless of the flow source.
  • Functionality is required to occur after the widget flow. (When users finish the Apply flow originating from a widget, this callback will trigger.)

Returned data

The SDK Completion Callback returns the generic data listed here plus the following:

FieldTypeDescription
skustringThe sku of the widget item that originated the flow.
pricestringThe price of the widget item that originated the flow.
categorystringThe category of the widget item that originated the flow.
tagstringThe tag for the widget item that originated the flow.

Object Response in the Context Argument

The context object response returns the following:

  • source - APPLY or CHECKOUT
  • promotion - returned for the Apply flow

Apply Completion Callback

This callback fires whenever an Apply flow completes successfully or not.

Code sample

ChargeAfter.payments.present("apply", {
  // the callback allows you to process the result of the apply process
  // if onComplete function is provided on SDK init, both will fire
  // Optional but recommended to be provided
  callback: function (data, status) {
    //
  },
});

Properties

FieldTypeDescription
dataobjectRelevant data for the flow type. See Returned data below.
statusobjectIn cases of an error during the flow, or an uncompleted flow for whatever reason, this object will contain two properties:
code: a status code indicating the status
message: a human-readable message
See Relevant status codes below.
If the Apply flow was successful, then the status object will be null or undefined.

Returned data

The Apply Completion Callback returns the generic data listed here plus the following:

FieldTypeDescription
availableCreditobjectDetails about the credit that was accepted during the apply flow, see AvailableCredit.
lenderLenderThe lender object containing data of the lender, see Lender.
accountobjectFor a successful Apply flow, the full account details will be returned. See account Object (in the 200 response).

Relevant status codes

CodeDescriptionType of action causing the status
CREATE_CHECKOUT_FAILEDCheckout creation or merchant settings fetch failedMerchant-driven
BACK_TO_STOREConsumer clicked the Back to Store buttonConsumer-driven
CONSUMER_CANCELLEDConsumer intentionally closed the Apply UIConsumer-driven
PENDINGApplication is pending consumer input (e.g. Driving License) or the lender may need to contact the financing providerConsumer-driven or Lender-driven

Checkout Completion Callback

This callback fires whenever a Checkout flow completes successfully or not.

Code sample

ChargeAfter.payments.present("checkout", {
  // the callback allows you to process the result of the checkout process
  // if onComplete function is provided on SDK init, both will fire
  callback: function (token, data, status) {
    //
  },
});

Properties

FieldTypeDescription
tokenstringA confirmation token that can be used to commit a charge.
This parameter will be null for users that were not able to complete the Checkout flow successfully (due to decline or error).
dataobjectRelevant data for the flow type. See Returned data below.
statusobjectIn cases of an error during the flow, or an uncompleted flow for whatever reason, this object will contain two properties:
code: a status code indicating the status
message: a human-readable message
See Relevant status codes below.
If the Checkout flow was successful, then the status object will be null or undefined.

Returned data

The Checkout Completion Callback returns the generic data listed here plus the following:

FieldTypeDescription
lenderLenderThe lender object containing data of the lender, see Lender.
offeraccountOfferThe detailed offer accepted by the consumer. See AccountOffer.
shippingAmountnumberThe shipping amount.
taxAmountnumberThe tax amount.
totalAmountnumberThe total amount including shipping, tax, and discounts.
ineligibilitiesArray (of IneligibilityData objects)Contains ineligibility errors retuned by lenders during the flow.
See IneligibilityData.

Relevant status codes

CodeDescriptionType of action causing the status
CREATE_CHECKOUT_FAILEDCheckout creation or merchant settings fetch failed.Merchant-driven
BILLING_SHIPPING_MISMATCHBilling and shipping address must be the same.Merchant-driven
TOTAL_AMOUNT_MISMATCHWhen the totalAmount received by ChargeAfter does not match the cart calculation.Merchant-driven
MISSING_CHECKOUT_DATAOccurs when the onDataUpdate is not provided and ChargeAfter is missing some Checkout information.Merchant-driven
ILLEGAL_CHAR_PROVIDEDOne of the submitted fields contains characters that are not supported.Merchant-driven
BACK_TO_STOREConsumer clicked the Back to Store button.Consumer-driven
CONSUMER_CANCELLEDConsumer intentionally closed the Checkout UI.Consumer-driven
PENDINGApplication is pending consumer input (e.g. Driving License) or the lender may need to contact the financing provider.Consumer-driven or Lender-driven

Returned data for All Completion Callbacks

The SDK, Apply, and Checkout Completion callbacks all return the following:

FieldTypeDescription
consumerDetailsobjectDetails of the consumer. See consumerDetails object.
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 point at which it stopped before. The token is sent based on the condition in the system, for example a pending status.
lendersStatusArray (of LenderStatus objects)Array of LenderStatus objects that were part of the Apply/Checkout process, and their responses.

Data objects

AccountOffer

FieldTypeDescription
codestring (optional)Unique identifier of the offer promotion
defaultCodestring (optional)Used to identify the offer promotion if the code parameter is not provided
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)Value to validate checkout cart total amount
descriptionstring (optional)Description of the offer as provided by the lender
eligibilityobjectEligibility of the offer
tagsobject (optional)Merchant-provided promotion metadata

Lender

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

For expected values, see Lender IDs and Name Mapping.

AvailableCredit

FieldTypeDescription
lenderLenderThe lender that provided the credit
creditAmountnumberAmount of credit available
financialProductTypestringLineOfCredit | Installments | LeaseToOwn | MerchantSelfFinancing
minimumAmountnumberThe minimum cart amount required to use this offer
tagsobjectTags associated with the offer

IneligibilityData

FieldTypeDescription
lenderNameLenderHuman-readable name of the lender
lenderIdnumberUnique identifier of the lender
ineligibilityDetailsArray (of IneligibilityDetails objects)Contains ineligibility details for corresponding lender

IneligibilityDetails

FieldTypeDescription
reasonstringcart | product
descriptionstringHuman-readable description
subReasonstringminAmount | maxAmount | warranty | leasable | state