Building a Checkout for Crypto Payments
This guide outlines the process for incorporating crypto payments into your workflow with Layer1 via API, allowing for the customization of your own payments page as desired.
Lets jump in by first understanding the payment flow.
Payment In Sequence Diagram
The happy path will be discussed, with exception scenarios discussed later on in the guide:
- The end user will request to make a deposit on your system, where you will need to collect the amount for the deposit, the cryptocurrency they want to pay with, and protocol if applicable.
- This information will then be forward onto us in the form of a Create Payment request.
- The Create Payment endpoint will return a crypto address matching the blockchain selected, along with other useful data in the API response. End user can then be shown this address, as well as the total amount of crypto required to complete the payment.
- The end user makes a payment to this address, which will then cause multiple related webhooks to be sent to your webhook listener as the payment goes through its lifecycle.
- Once you receive the final
COMPLETE
webhook you can poll the Get Payment endpoint to confirm the status and final paid amount, or take the information from the webhook. - Update the end users account accordingly with the confirmed payment amount.
Payment Lifecycle
A payment undergoes several status changes throughout its lifecycle, detailed as follows:
Status | Immutable? | Description |
---|---|---|
Pending | No | The initial status of your payment. It remains in this state until the payment either expires or a transaction linked to this payment is detected on the blockchain. |
Processing | No | This status indicates that the customer's payment has been detected on the blockchain. The payment remains in this state until funds are credited to your wallet. Note: Payments can still expire in this state if the transaction lacks sufficient gas or if the blockchain does not confirm the transaction within the expiry time. |
Complete | Yes | This status means that the funds have been received and credited to the merchant account in the chosen currency. |
Underpaid | Yes | Indicates that the funds have been received and credited to the merchant account in the chosen currency, but the amount sent by the customer was less than the requested amount. |
Expired | Yes | The payment expired before the customer sent the funds. |
Steps to Follow
This guide covers the integration of payment links into your platform to accept crypto payments, detailing the following steps:
- Initiating a payment request and handling the response.
- Guiding the end user to complete the payment.
- Setting up a webhook listener for payment notifications.
- Managing payment exceptions and errors.
Updated 2 months ago