API de rappel de préadmissibilité
En savoir plus sur la réception des événements de préadmissibilité.
Aperçu
L'API Prequalification Callback permet d'enregistrer une fonction de rappel qui sera appelée lorsque les clients atteignent un résultat de décision sur la demande de préadmissibilité. Que le client ait été approuvé ou refusé pour la préadmissibilité, l'API permet à votre demande web de répondre aux événements en temps réel. Le guide fournit les étapes nécessaires pour commencer à recevoir des événements de préadmissibilité.
1. Intégrez Affirm.js et activez la préqualification
Consultez notre page de documentation sur l'intégration d'Affirm et la préadmissibilité pour plus de détails.
Incluez le script suivant dans la section d'en-tête de chaque page de votre site.
<script>
_affirm_config = {
public_api_key: "YOUR_PUBLIC_KEY",
script: "https://cdn1-sandbox.affirm.com/js/v2/affirm.js"
};
(function(m,g,n,d,a,e,h,c){var b=m[n]||{},k=document.createElement(e),p=document.getElementsByTagName(e)[0],l=function(a,b,c){return function(){a[b]._.push([c,arguments])}};b[d]=l(b,d,"set");var f=b[d];b[a]={};b[a]._=[];f._=[];b._=[];b[a][h]=l(b,a,h);b[c]=function(){b._.push([h,arguments])};a=0;for(c="set add save post open empty reset on off trigger ready setProduct".split(" ");a<c.length;a++)f[c[a]]=l(b,d,c[a]);a=0;for(c=["get","token","url","items"];a<c.length;a++)f[c[a]]=function(){};k.async=
!0;k.src=g[e];p.parentNode.insertBefore(k,p);delete g[e];f(g);m[n]=b})(window,_affirm_config,"affirm","checkout","ui","script","ready","jsReady");
</script>2. Enregistrer une fonction de rappel
Affirm offre actuellement deux options d'implémentation pour l'enregistrement d'une fonction de rappel. Nous recommandons d'enregistrer la fonction de rappel directement avec Affirm.js, bien que cela nécessite d'avoir accès à la portée globale du document parent. Si vous êtes un fournisseur tiers avec une balise <iframe> intégrée dans le document parent, il sera nécessaire d'écouter les messages diffusés par l'API postMessage pour recevoir les événements. Le tableau suivant présente la compatibilité entre les deux méthodes, compte tenu de la manière dont la demande cliente est intégrée dans le document parent :
| Méthode d'intégration | Intégré tag in parent document | Embedded <iframe> tag in parent document |
|---|---|---|
Affirm.js | ✅ | ❌ |
API | ✅ | ✅ |
You cannot register multiple callbacks with
Affirm.jsat this time. If multiple parties are looking to subscribe to prequalification events, you must use thepostMessage
Integrate with AffirmJS
If you're a merchant or a third party provider who have access to the same global scope embedded with Affirm.js, you may register a callback function which will be invoked after completing prequalification, regardless of the decision outcome.
function prequalCallback(event) {
console.log(event);
}
affirm.ui.ready(function() {
affirm.events.on("prequal:complete", function(data) {
prequalCallback(data)
})
});A sample output of the event data is provided below with specifics outlined in the Callback data object section:
Example event data
{
amount: 400000,
terms: [{
apr: "10.13",
created: "2015-08-12T23:57:25Z",
id: "sandbox_plan_3",
installment_amount: 135531,
installment_count: 3,
interest_amount: 6686,
prequal_amount: 400000
}, {
apr: "10.13",
created: "2015-08-12T23:57:25Z",
id: "sandbox_plan_6",
installment_amount: 68598,
installment_count: 6,
interest_amount: 11749,
prequal_amount: 400000
}, {
apr: "10.13",
created: "2015-08-12T23:57:25Z",
id: "sandbox_plan_12",
installment_amount: 35141,
installment_count: 12,
interest_amount: 22010,
prequal_amount: 400000
}]
}Take a look at the Security considerations section for more information on security when implementing this integration.
3. Enable prequalification events
Reach out to your Partner Engineering contact and request to enable prequalification events.
Callback data object
Refer to the table below for the schema of the event data:
| Parameter | Description |
|---|---|
| Only available when the value of status is approved. |
| The decision outcome of the user’s prequalification. May have the following values: |
| Only available when the value of status is approved. |
Financing term object
| Parameter | Description |
|---|---|
| A unique identifier representing the cart of the customer. A maximum of 500 characters. |
| The name of the cart. A maximum of 500 characters. |
| An Affirm-specific unique identifier for the financing program used. |
| The payment amount due per installment amount in the term. |
| The total number of installments in the term. |
| The total interest that would be charged over the duration of the term. |
| The amount the user was prequalified for. The value must be non‑negative and represented in minor units, such as cents instead of dollars |
Security considerations
By default, web browsers prevent pages in different domains from affecting each other via cross‑site scripting for security and privacy reasons. This is an important security feature, but it also prevents documents from different domains from communicating with each other, even if the pages aren't hostile.
In order to enable cross‑origin communication, modern browsers support the Window.postMessage() API which allows pages to communicate with each other regardless of their source domain, in a way designed to not enable cross‑site scripting attacks. We use this API to safely transmit data for Prequalification Callbacks.
Updated 8 months ago