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:
Field | Type | Description |
---|---|---|
consumerDetails | object | Details of the consumer see link |
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 place it stoped before, will be sent based on some condition in the system, for example pending status. |
lendersStatus | LenderStatus[] | 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
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 | |
tag | string |
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:
Code | Description |
---|---|
CONSUMER_CANCELLED | Consumer intentionally closed the Apply UI |
CREATE_CHECKOUT_FAILED | Application creation or merchant settings fetch failed |
PENDING | Application is pending on consumer input (e.g. Driving License) |
BACK_TO_STORE | Consumer 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
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 | On successful application, the full account details will be returned. see Account |
Checkout Completion Callback
Will fire whenever a checkout flow completes.
relevant status codes:
Code | Description |
---|---|
CONSUMER_CANCELLED | Consumer intentionally closed the Checkout UI |
CREATE_CHECKOUT_FAILED | Checkout creation or merchant settings fetch failed |
GENERAL | Some general error occurred (message should provide more information) |
BILLING_SHIPPING_MISMATCH | Billing and shipping address must be the same |
BACK_TO_STORE | Consumer 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
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 Offer |
shippingAmount | number | |
taxAmount | number | |
totalAmount | number | |
ineligibilities | IneligibilityData[] | Contains ineligibility errors retuned by lenders during the flow |
Data objects
AccountOffer
Field | Type | Description |
---|---|---|
code | string (optional) | Unique identifier of the offer |
defaultCode | string(optional) | |
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) | Optional value to validate checkout cart total amount |
description | string (optional) | Optional description of the offer as provided by the lender |
eligibility | object | Eligibility of the offer |
tags | object (optional) | Merchant provided Promotion metadata |
Detailed object definitions can be found here: https://docs.chargeafter.com/reference/get_v3-session-accounts
Lender
Field | Type | Description |
---|---|---|
id | string | Unique identifier of the lender |
name | string | human-readable name of the lender |
Expected values can be found here: https://docs.chargeafter.com/reference/lenders
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 min cart amount required to use this offer |
tags | Dict<string, string> | 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 | IneligibilityDetails[] | Contains ineligibility details for corresponding lender |
IneligibilityDetails
Field | Type | Description |
---|---|---|
reason | 'cart' | 'product' | |
description | string | human-readable description |
subReason | 'minAmount' | 'maxAmount' | 'warranty' | 'leasable' | 'state' |
Updated 3 months ago