To create an Afterpay transaction, set the method to afterpay and the redirect_url to the endpoint of your application that can handle the customer returning once they’ve completed approving the transaction on the Afterpay website.See the POST /transactions API endpoint for more details.
Copy
var transaction = await _client.Transactions.CreateAsync( transactionCreate: new TransactionCreate() { Amount = 1299, Currency = "AUD", Country = "AU", PaymentMethod = TransactionCreatePaymentMethod.CreateCheckoutSessionWithUrlPaymentMethodCreate( new RedirectPaymentMethodCreate() { Method = "afterpay", RedirectUrl = "https://example.com/callback", } ), });
If successful, the response of this transaction will include a status set to buyer_approval_pending as well as a payment_method.approval_url.
Your application will need to redirect your customer to Afterpay where they will be required to approve the payment. To do so, redirect the customer to the payment_method.approval_url. After they’ve authenticated themselves, the customer will be redirected back to the redirect_url that you set when creating the transaction.
If the customer abandons the checkout or somehow experiences network
connection issues, the transaction state can get out of sync between your
application and ours. We recommend the following best
practices in handling these situations.
When the customer is redirected back to your app, the transaction status is not known. Your application will therefore need to call our API to get the latest transaction status. To do this, your redirect_url will be appended with the transaction_id.
Although we also provide the transaction_status in this callback, it’s
recommended to also fetch the latest status via the API, as the status may
have changed since.
After you’ve handled the redirect, you can display a message to your customer letting them know the result of the transaction.
Finally, after the transaction has been created your application can get the
latest details and status using the transaction ID received via the callback to
the redirect URL, or on direct callback from the API.
Copy
curl -i -X GET "https://api.example.gr4vy.app/transactions/fe26475d-ec3e-4884-9553-f7356683f7f9" \ -H "Authorization: Bearer [JWT_TOKEN]"
The transaction includes details about the payment method used and the status
of the transaction.