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
Field | Type | Description |
---|---|---|
token | string | A 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). |
data | object | Relevant data for the flow type (Apply/Checkout). See Returned data in the Apply Completion Callback and the Checkout Completion Callback below. |
status | object | In 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 messageIf 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. |
context | object | Indicates 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:
Field | Type | Description |
---|---|---|
sku | string | The sku of the widget item that originated the flow. |
price | string | The price of the widget item that originated the flow. |
category | string | The category of the widget item that originated the flow. |
tag | string | The tag for the widget item that originated the flow. |
Object Response in the Context Argument
The context
object response returns the following:
source
-APPLY
orCHECKOUT
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
Field | Type | Description |
---|---|---|
data | object | Relevant data for the flow type. See Returned data below. |
status | object | In 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 statusmessage : a human-readable messageSee 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:
Field | Type | Description |
---|---|---|
availableCredit | object | Details about the credit that was accepted during the apply flow, see AvailableCredit. |
lender | Lender | The lender object containing data of the lender, see Lender. |
account | object | For a successful Apply flow, the full account details will be returned. See account Object (in the 200 response). |
Relevant status codes
Code | Description | Type of action causing the status |
---|---|---|
CREATE_CHECKOUT_FAILED | Checkout creation or merchant settings fetch failed | Merchant-driven |
BACK_TO_STORE | Consumer clicked the Back to Store button | Consumer-driven |
CONSUMER_CANCELLED | Consumer intentionally closed the Apply UI | Consumer-driven |
PENDING | Application is pending consumer input (e.g. Driving License) or the lender may need to contact the financing provider | Consumer-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
Field | Type | Description |
---|---|---|
token | string | A 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). |
data | object | Relevant data for the flow type. See Returned data below. |
status | object | In 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 statusmessage : a human-readable messageSee 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:
Field | Type | Description |
---|---|---|
lender | Lender | The lender object containing data of the lender, see Lender. |
offer | accountOffer | The detailed offer accepted by the consumer. See AccountOffer. |
shippingAmount | number | The shipping amount. |
taxAmount | number | The tax amount. |
totalAmount | number | The total amount including shipping, tax, and discounts. |
ineligibilities | Array (of IneligibilityData objects) | Contains ineligibility errors retuned by lenders during the flow. See IneligibilityData. |
Relevant status codes
Code | Description | Type of action causing the status |
---|---|---|
CREATE_CHECKOUT_FAILED | Checkout creation or merchant settings fetch failed. | Merchant-driven |
BILLING_SHIPPING_MISMATCH | Billing and shipping address must be the same. | Merchant-driven |
TOTAL_AMOUNT_MISMATCH | When the totalAmount received by ChargeAfter does not match the cart calculation. | Merchant-driven |
MISSING_CHECKOUT_DATA | Occurs when the onDataUpdate is not provided and ChargeAfter is missing some Checkout information. | Merchant-driven |
ILLEGAL_CHAR_PROVIDED | One of the submitted fields contains characters that are not supported. | Merchant-driven |
BACK_TO_STORE | Consumer clicked the Back to Store button. | Consumer-driven |
CONSUMER_CANCELLED | Consumer intentionally closed the Checkout UI. | Consumer-driven |
PENDING | Application 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:
Field | Type | Description |
---|---|---|
consumerDetails | object | Details of the consumer. See consumerDetails object. |
consumerId | string (optional) | The internal id of the consumer. |
applicationId | string (optional) | The application id the consumer. |
continuationToken | string (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. |
lendersStatus | Array (of LenderStatus objects) | Array of LenderStatus objects that were part of the Apply/Checkout process, and their responses. |
Data objects
AccountOffer
Field | Type | Description |
---|---|---|
code | string (optional) | Unique identifier of the offer promotion |
defaultCode | string (optional) | Used to identify the offer promotion if the code parameter is not provided |
financialProductType | string | LineOfCredit | Installments | LeaseToOwn | MerchantSelfFinancing |
defaultAPR | number | Offer APR |
amount | number | Maximum amount of the offer |
promoSettings | object (optional) | Promotion settings |
metadata | object (optional) | Can be used to pass additional data for offer |
expirationDate | string (optional) | Date at which offer expires |
checkoutMinimumAmount | object (optional) | Value to validate checkout cart total amount |
description | string (optional) | Description of the offer as provided by the lender |
eligibility | object | Eligibility of the offer |
tags | object (optional) | Merchant-provided promotion metadata |
Lender
Field | Type | Description |
---|---|---|
id | string | Unique identifier of the lender |
name | string | Human-readable name of the lender |
For expected values, see Lender IDs and Name Mapping.
AvailableCredit
Field | Type | Description |
---|---|---|
lender | Lender | The lender that provided the credit |
creditAmount | number | Amount of credit available |
financialProductType | string | LineOfCredit | Installments | LeaseToOwn | MerchantSelfFinancing |
minimumAmount | number | The minimum cart amount required to use this offer |
tags | object | Tags associated with the offer |
IneligibilityData
Field | Type | Description |
---|---|---|
lenderName | Lender | Human-readable name of the lender |
lenderId | number | Unique identifier of the lender |
ineligibilityDetails | Array (of IneligibilityDetails objects) | Contains ineligibility details for corresponding lender |
IneligibilityDetails
Field | Type | Description |
---|---|---|
reason | string | cart | product |
description | string | Human-readable description |
subReason | string | minAmount | maxAmount | warranty | leasable | state |
Updated about 1 month ago