Gérer les transactions Split Capture
Découvrez comment gérer les états des transactions dans votre passerelle de paiement, y compris l'autorisation, la capture des transactions, et plus encore.
Aperçu
Les transactions représentent les prêts Affirm émis au consommateur. Vous pouvez interagir avec les transactions via l'API Transaction pour modifier l'état d'une transaction, mettre à jour les métadonnées ou récupérer des détails.
Autorisation
Authorization occurs after a user has successfully completed the Affirm checkout flow and returns back to the merchant site. Authorizing the transaction generates a transaction_id ex: (A1B2-C3D4), that you'll use to reference this loan moving forward.
The Authorize resource endpoint creates a loan and reserves the funds. When you authorize, Affirm will generate a transaction_id that you’ll use to reference the transaction moving forward. You must authorize a transaction to complete its creation.
Autorisation du prêtIf you don't authorize a charge, the loan will not become active. The user won't see the loan, and you won't be able to capture the funds. To avoid this, authorize the loan as soon as you receive a
checkout token.
curl https://sandbox.affirm.com/api/v1/transactions \
-X POST \
-u "<public_api_key>:<private_api_key>" \
-H "Content-Type: application/json" \
-d '{"transaction_id": "<checkout_token>","order_id": "JKLM4321"}'You should receive a response that looks like the example below with the transaction_id.
{
"amount": 6100,
"amount_refunded": 0,
"authorization_expiration": "2019-01-01T00:00:00Z",
"checkout_id": "A1B2C3D4E5F6G7H8",
"created": "2019-01-01T00:00:00Z",
"currency": "USD",
"id": "A1B2-C3D4",
"order_id": "JKLM4321",
"provider_id": 1,
"status": "authorized"
}After successfully authorizing a transaction and receiving the authorized amount, the user will be redirected to the user_confirmation_url page on your site, which will do the following:
- Validez que le montant autorisé correspond au total de la commande.
- Redirigez le client vers la page de confirmation de commande ou affichez un message de confirmation de commande.
- Store the
transaction_id. - Marquez le paiement de la commande comme étant en attente.
If the authorization fails, the user will be redirected to the user_cancel_url page, on your site, which will do the following:
- Rediriger le client vers la page d'erreur de commande ou indiquer que la commande est incomplète.
- Conserver potentiellement cette tentative de paiement, ce qui n'est pas obligatoire de notre côté.
Autoriser un prêt AffirmVous ne devez autoriser un prêt Affirm donné qu'une seule fois, pour le montant total de la
transaction d'achat en cours.
Gestion des transactions
You can integrate the Transaction endpoints into your back-end order management system, where you fulfill orders and process payments.
L'API Transaction vous permet de gérer la transaction à travers différents états tels que autorisée, capturée et annulée.
If you want to read or update loan information, you can use the read and update states.
Capturer une transaction
After fulfilling an order, you must send a Capture Transaction API request to Affirm in order to capture or settle the funds. You'll want to perform this activity from your secure back-end systems. To capture a previous authorization, you'll need the charge_id provided in the Authorization API response. There are no required fields that need to be stored from the capture response.
La capture des fonds est similaire à celle d'une transaction par carte de crédit. Après avoir capturé le prêt, nous procédons comme suit :
- Informer le client que le prêt a été saisi et que son premier paiement sera dû à l’avenir.
- Payer le commerçant dans 2 à 3 jours ouvrables.
For Split Captures, you may capture the loan in your desired increments by specifying the amount parameter for each unique capture request within the authorization window.
MontantIf you do not pass a specified amount in the
capturerequest, the entire amount will be captured.
Fenêtre d'autorisation
Toutes les captures doivent se produire dans la fenêtre d'autorisation définie. À l’expiration de la période d’autorisation, les montants non capturés seront remboursés au prêt du client et ne pourront plus être récupérés. Travaillez avec votre homologue technique pour vous assurer que la fenêtre d’autorisation est définie correctement selon vos délais d’expédition. La fenêtre d'authentification par défaut est par ailleurs fixée à 30 jours.
curl https://sandbox.affirm.com/api/v1/transactions/{transaction_id}/capture \
-X POST \
-u "{public_api_key}:{private_api_key}" \
-H "Content-Type: application/json" \
-d '{"amount":"50000", "order_id": "{order_id}", "shipping_carrier": "USPS", "shipping_confirmation": "1Z23223"}'Vous recevrez ensuite une réponse avec la confirmation.
{
"fee": 600,
"created": "2016-03-18T00:03:44Z",
"order_id": "JKLM4321",
"currency": "USD",
"amount": 50000,
"type": "capture",
"id": "O5DZHKL942503649",
"transaction_id": "6dH0LrrgUaMD7Llc"
}Captures, remboursements et annulations multiples
To capture funds in increments, send a Capture Transaction API request for the specified amount within the authorization window. For example, if your authorization window is 30 days, you can make a unique capture request for each item in the order within that 30 day period. You can also use the Void endpoint to void uncollected funds, and the Refund endpoint to process refunds for partially captured funds.
Exemples
Below are examples of common Split Capture use cases, where we guide you through submitting multiple capture requests. These examples follow a fictional business, Prometheus Furniture, that sells home furnishings and appliances. Due to the high demand of their furniture, they typically ship items for multiple orders at different times.
Exemple 1 : capturer tous les fonds
Prometheus Furniture vient de passer une commande pour un canapé de 400 dollars et un bureau d'ordinateur de 600 dollars, soit un total de 1 000 dollars. Dans l'exemple ci-dessous, le canapé est prêt à être expédié immédiatement, tandis que le bureau d'ordinateur prendra plus de temps.
Tout d'abord, il autorisera le prêt pour un montant total de 1000 $.
curl https://sandbox.affirm.com/api/v1/transactions \
-X POST \
-u "<public_api_key>:<private_api_key>" \
-H "Content-Type: application/json" \
-d '{"transaction_id": "<checkout_token>","order_id": "JKLM4321"}'Next, Prometheus Furniture sends a capture request specifying the amount for $400 on Day 1 of the loan.
#First capture for $400
curl https://sandbox.affirm.com/api/v1/transactions/{transaction_id}/capture \
-X POST \
-u "{public_api_key}:{private_api_key}" \
-H "Content-Type: application/json" \
-d '{"amount":40000, "order_id": "JKLM4321", "shipping_carrier": "USPS", "shipping_confirmation": "1Z23223"}'26 jours plus tard, lorsque le bureau d'ordinateur est prêt à être expédié, Prometheus Furniture soumet une autre requête de capture en précisant le montant restant de 600 dollars.
#Second capture for $600
curl https://sandbox.affirm.com/api/v1/transactions/{transaction_id}/capture \
-X POST \
-u "{public_api_key}:{private_api_key}" \
-H "Content-Type: application/json" \
-d '{"amount":60000, "order_id": "JKLM4321", "shipping_carrier": "USPS", "shipping_confirmation": "1Z23223"}'Exemple 2 : capturer une quantité inférieure à la totalité avec une annulation partielle
Sometimes, customers request a loan greater than the amount they end up spending due to a canceled item or tax adjustment. In the example below, a customer takes out a $1000 loan, but orders two bar stools for $300, and patio furniture for $500, and a chair for $200. After authorizing the full loan amount, Prometheus captures the funds for the bar stools specifying the amount of $300.
#First capture for $300
curl https://sandbox.affirm.com/api/v1/transactions/{transaction_id}/capture \
-X POST \
-u "{public_api_key}:{private_api_key}" \
-H "Content-Type: application/json" \
-d '{"amount":30000, "order_id": "JKLM4421", "shipping_carrier": "USPS", "shipping_confirmation": "1Z23223"}'Lorsque le meubles de patio est prêt à être expédié le 13 ème jour, le deuxième montant est prélevé pour le meuble de patio.
#Second capture for $500
curl https://sandbox.affirm.com/api/v1/transactions/{transaction_id}/capture \
-X POST \
-u "{public_api_key}:{private_api_key}" \
-H "Content-Type: application/json" \
-d '{"amount":50000, "order_id": "JKLM4421", "shipping_carrier": "USPS", "shipping_confirmation": "1Z23223"}'The chair that was initially ordered was canceled before being shipped. As a result, Prometheus Furniture wouldn't capture the $200, but rather they submit a Void request within the authorization window for the remaining amount.
#Void $200
curl https://sandbox.affirm.com/api/v1/transactions/{transaction_id}/void \
-X POST \
-H "Content-Type: application/json" \
-u "{public_api_key}:{private_api_key}" \
-d '{"amount":20000}'Exemple 3 : capturer tous les fonds avec un remboursement
Dans cet exemple, le client a décidé d'acheter un nouveau tapis pour 200 $ et un nouveau réfrigérateur pour 800 $. Après l'autorisation initiale, Prometheus Furniture envoie cette première requête de capture pour 200 $.
#First capture for $200
curl https://sandbox.affirm.com/api/v1/transactions/{transaction_id}/capture \
-X POST \
-u "{public_api_key}:{private_api_key}" \
-H "Content-Type: application/json" \
-d '{"amount":20000, "order_id": "JKLM5431", "shipping_carrier": "USPS", "shipping_confirmation": "1Z23223"}'Prometheus peut livrer le réfrigérateur au client un peu plus tôt que d’habitude et saisit le deuxième montant pour 800 $ le jour 4.
#Second capture for $800
curl https://sandbox.affirm.com/api/v1/transactions/{transaction_id}/capture \
-X POST \
-u "{public_api_key}:{private_api_key}" \
-H "Content-Type: application/json" \
-d '{"amount":80000, "order_id": "JKLM5431", "shipping_carrier": "USPS", "shipping_confirmation": "1Z23223"}'Le client était très excité d’obtenir ses articles rapidement, mais n’aimait pas vraiment le contraste entre le tapis et les couleurs de son salon. Heureusement, Prometheus Furniture a une excellente politique de remboursement et a initié un remboursement pour le client lorsqu'ils l'ont découvert. Cette fois, ils utiliseront l'API Refund pour créditer les 200 $ au client.
curl https://sandbox.affirm.com/api/v1/transactions/{transaction_id}/refund \
-X POST \
-H "Content-Type: application/json" \
-u "{public_api_key}:{private_api_key}" \
-d '{"amount": 20000}'Bien que Prometheus Furniture ait finalement capture la totalité du prêt, ils ont remboursé le montant demandé au client, qui sera appliqué à la fin du prêt.
Exemple 4 : le prêt partiellement capturé doit être annulé et remboursé
Pour cet exemple, un client a commandé une table de salle à manger pour 1000 $ et 6 chaises pour 1200 $. Prometheus furniture capture alors le premier montant de 1000 $ pour la table de salle à manger.
#First capture for $1000
curl https://sandbox.affirm.com/api/v1/transactions/{transaction_id}/capture \
-X POST \
-u "{public_api_key}:{private_api_key}" \
-H "Content-Type: application/json" \
-d '{"amount":100000, "order_id": "JKLM5555", "shipping_carrier": "USPS", "shipping_confirmation": "1Z23223"}'Lorsque la table arrive chez le client, celui-ci se rend compte qu'elle est beaucoup trop grande pour sa salle à manger et décide de la retourner. Maintenant que la table est retournée, les chaises de salle à manger ne sont plus nécessaires et le client demande l'annulation de la commande non exécutée. Pour annuler la commande, la première étape consiste à annuler le montant supplémentaire autorisé mais non capturé de 1 200 $.
#Voiding the authorized but uncaptured loan amount of $1200
curl https://sandbox.affirm.com/api/v1/transactions/{transaction_id}/void \
-X POST \
-H "Content-Type: application/json" \
-u "{public_api_key}:{private_api_key}" \
-d '{"amount":120000}Après avoir annulé le montant de la transaction autorisé mais non saisi de 1 200 $, l'étape suivante consiste à rembourser le montant du prêt capturé de 1 000 $ pour la table à manger.
#Refunding the captured loan amount of $1000
curl https://sandbox.affirm.com/api/v1/transactions/{transaction_id}/refund \
-X POST \
-H "Content-Type: application/json" \
-u "{public_api_key}:{private_api_key}" \
-d '{"amount": 100000}'Étant donné que le prêt a été partiellement capturé, mais que le client a décidé de retourner la table et d'annuler la commande des chaises, il était nécessaire d'annuler d'abord le montant de transaction autorisé mais non capturé de 1 200 $. Suivi d'un remboursement pour le montant du prêt partiellement capturé de 1 000 $.
Mis à jour il y a environ 8 heures
USA
Canada