Handling Deposits
Phase 1: Receiving Deposit Request from a User

Step 1
The user should send the deposit request to the server. The deposit request should have the currency and amount being transferred.
Step 2
The server creates a unique key (UUID) for the deposit. This UUID will ensure that this transaction occurs only once.
After creating the UUID, the deposit data (amount, currency, user ID, UUID) should be stored on Redis. We recommend setting the UUID as the key. It's also a good idea to give the data an expiry time.
Step 3
After the deposit is given a UUID and is stored on Redis, the server should then forward the payment request to the payment service. The payment service should receive the amount, currency, and UUID of the requested deposit.
Step 4
Once the request from the server is received, the payment service will prompt the user to complete the payment. This can be handled by the server or by the payment service directly via a redirect.
This step will differ based on which service is used but will ultimately end up with the user being asked to complete the payment.
Phase 2: User completes deposit

Phase 3: Payment service notifies the server of completed deposit

Step 1
Once the user completes the payment, the service will notify the server of the completed payment. The way notifications are handled will depend on the payment service used. This notification should come with the amount and currency of the completed deposit. It should also provide the UUID the server created for this deposit in Phase 1.
Step 2
Once the server receives the notification, it should first check Redis to make sure the UUID is valid.
If no data is found on Redis with the received UUID, the deposit should be rejected.
If data is found with the UUID, that data should be deleted from Redis. After deletion, the server should verify that the amount and currency of the deposit received from the payment service matches the ones found on Redis.
If the user paid less than the required amount or used a different currency, the deposit should be rejected.
Step 3
Once everything is validated, the server should mint the asset to the user. This completes the deposit flow.
Code Example
For this example, we will use a redirect for prompting the user to complete the payment and receive a notification of the completed payment via a callback URL. The process for both may be different for some payment services but the overall flow should remain the same.
Last updated