HollaEx®
⚙️ DashboardStart →
  • HollaEx® — The Crypto Exchange Solution
  • ☁️Cloud Operators
    • Launching the Exchange
    • Setting Domain for Cloud Exchanges
    • Easy SMTP for Cloud Exchanges
    • SEO Settings for Cloud Exchanges
      • SEO Advanced Settings
  • ⚙️Operating Your Exchange
    • Operator Control Panel
      • General
      • Users
      • User Profile
      • Assets
      • Markets
      • Stakes
      • Sessions
      • Plugins Apps
      • Trading Fees & Account Tiers
      • Roles
      • Chat
      • Billing
    • Customize Exchange
      • Browser Tools
        • Enter Edit Mode
        • Operator Controls (Visuals)
        • Console
      • Plugins
      • Forked Repo
    • Fiat Controls
      • Initial Setup
      • Setting Up Fiat On/ Off Ramp
      • Editing Deposit & Withdrawal Fees
      • Users Making Fiat Deposit
      • Users Trading With Fiat
      • User Making Fiat Withdrawal
    • Staking
    • OTC Broker
    • P2P
      • P2P Overview
      • P2P Setup
      • P2P Troubleshooting
      • P2P Vendor Flow
    • Smart Chain Trading
    • Assets & Trading Pairs
      • Add New Assets & Trading Pairs
      • Configure Pair Parameters
    • Set up the SMTP Email
      • Set up SMTP with AWS SES
      • Set up SMTP with Mailgun
      • Set up SMTP with SendGrid
      • Test the SMTP with Gmail
    • Enabling reCAPTCHA
    • Email Customization & Audit
    • DeFi Asset Staking Process
  • 🧩Plugins
    • HollaEx Plugins
      • Announcements
      • Bank
      • AWS SNS (Text Messages - SMS)
      • KYC
      • Automatic KYC
      • Messente
      • Advanced Referral
      • CoinMarketCap
      • Guardarian
    • Install Plugins
    • Developing Plugins
      • Development Walkthrough: Hello-Plugin
        • Initialization
        • Configuration
        • Scripting
        • Web View
        • The Final Product & Installation
      • Advanced
        • Initialization
        • Config
        • Server Script
        • Plugin Libraries
        • Web View
        • Final Plugin Product
        • Advanced Tutorial: Using the user meta field
        • Advanced Tutorial: Adding a new database table column
        • Advanced Tutorial: Creating a new database table
      • Simple Wallet Example
      • Web View Development
        • Overview
        • External dependencies
        • Getting started
        • Basic Tutorial: Hello Exchange Plugin web view
        • Advanced Tutorial: KYC Plugin web views
    • Bank Integration
      • Handling Deposits
      • Handling Withdrawals
  • 👷Developers
    • API Guide
      • API Example Scripts
    • Run Dev Mode
    • Build a New Front-end Interface
  • 🧰On-Premise Operators (Advanced Only)
    • On-Premise Exchange Setup
      • Getting Started — Requirements
      • Installation
      • Server Setup
      • Web Setup
      • Production
    • CLI How-Tos
      • Start Exchange
      • Stop Exchange
      • Upgrade Exchange
        • Build and Apply the Code Changes
      • Get Exchange Logs
      • Get a Backup and Restore
      • Exchange Migration
      • Command List
    • Run Exchange on Kubernetes
    • Troubleshooting Guide
  • 🚀Advanced
    • SEO Optimization
    • Nginx
    • Rate Limits
    • Database
      • Upgrade Database
    • Dependencies
    • Contents Delivery Network
      • Cloudflare CDN for HollaEx
      • CloudFront CDN for HollaEx
    • Load Balancer
      • AWS ELB
      • DigitalOcean LB
    • Customize Kubenretes Ingress
    • Exchange Keys
      • Exchange API Keys Troubleshoot
    • HollaEx on non-Linux
      • HollaEx on Windows
      • HollaEx on macOS
    • The Network Tool Library
      • Accessing the Network Tool Library
      • Functions
        • WebSocket
      • Simple Example: Creating a User and Wallet
      • Getting More Interesting: Orders with the Tools
        • Setup: Using the transferAsset function
        • Creating and Monitoring a Sell Order
        • Settling Fees
      • Private HollaEx Network
    • Docker Content Trust (DCT)
    • Revenue Sharing
  • 📦Releases
    • Release Notes
    • Side Notes
  • ➡️External Links
  • Blogs
  • Forum
  • Videos
  • Twitter X
  • Telegram
  • Interactive Demo
  • Discord Community
  • API Documentation
  • Tools Library Documentation
  • Node Library Documentation
  • Plugins Documentation
Powered by GitBook
On this page
  • Phase 1: Receiving Withdrawal Request from a User
  • Phase 2: Payment service attempts withdrawal to user's bank account
  • Phase 3: Server updates status of pending burn
  • Code Example
  • Advanced
  1. Plugins
  2. Bank Integration

Handling Withdrawals

PreviousHandling DepositsNextAPI Guide

Last updated 4 years ago

Phase 1: Receiving Withdrawal Request from a User

Step 1

The user should send a withdrawal request to the server. The withdrawal request should have the currency and amount being transferred.

// Express post endpoint to receive deposit requests
app.post(
    '/plugins/bank/withdrawal',
    toolsLib.security.verifyBearerTokenExpressMiddleware(['user']),
    (req, res) => {
        ...
    }
);

Step 2

The server creates a pending burn transaction for this specific withdrawal. This will lock the amount being withdrawn in the user's balance. This ensures that this amount will not be used during this withdrawal process. The transaction_id of the pending burn is required for phase 3 of this process.

const amount, currency, BANK_ACCOUNT = // withdrawal data from request
const user_id = // ID of user making request

// Create a pending burn and save response
const pendingBurn = await toolsLib.wallet.burnAssetByKitId(
    user_id, // User kit id
    currency, // currency
    amount, // amount
    {
        status: false, // status false will make this burn pending
        description: 'Bank Deposit', // description
        transactionId: transaction_id // transaction id
    }
);

Phase 2: Payment service attempts withdrawal to user's bank account

Step 1

The server makes a withdrawal request using the payment service.

This step will differ based on which payment service is used.

const library = PAYMENT_SERVICE_SDK_LIBRARY; // Payment service sdk
const amount, currency = // withdrawal data from request
BANK_ACCOUNT; // user's bank account to withdrawal to

// Withdrawal method for payment service sdk
library.withdrawal(amount, currency, BANK_ACCOUNT);

Step 2

Payment service attempts to make the withdrawal to the user's bank account.

Step 3

Payment service responds to server with the withdrawal's status.

// Withdrawal method for payment service sdk
library.withdrawal(amount, currency, USER_BANK_ACCOUNT)
    .then((data) => {
        // data contains status of the withdrawal
    })
    .catch((err) => {
        // withdrawal request failed
    });

Phase 3: Server updates status of pending burn

Step 1

The server updates the status of the pending burn created in phase 2 based on response from payment service.

// Withdrawal method for payment service sdk
library.withdrawal(amount, currency, USER_BANK_ACCOUNT)
    .then((data) => {
        if (data.successful) {
            // If the withdrawal was successful
            toolsLib.wallet.updatePendingBurn(
                pendingBurn.transaction_id, // transaction_id saved from phase 1
                {
                    status: true,
                    // Optional: Update burn's transaction id to match 
                    // payment service withdrawal's transaction id
                    updatedTransactionId: data.transaction_id
                }
            );
        } else if (data.failed) {
            // If the withdrawal failed
            toolsLib.wallet.updatePendingBurn(
                pendingBurn.transaction_id, // transaction_id saved from phase 1
                {
                    rejected: true
                }
            );
        }
    })
    .catch((err) => {
        // withdrawal request failed
        toolsLib.wallet.updatePendingBurn(
            pendingBurn.transaction_id, // transaction_id saved from phase 1
            {
                rejected: true
            }
        );
    });

Step 2

Once the pending burn's status is updated, the locked amount on the user's balance will be unlocked. If the withdrawal was successful, the user's locked amount will be removed entirely from the total balance. If the withdrawal was unsuccessful, the locked amount will return to the user's total balance.

Code Example

For this example, we are using a placeholder payment service sdk called PAYMENT_SERVICE_SDK_LIBRARY. The withdrawal step will differ based on the payment service used. Regardless, the overall flow of this process should be relatively the same.

app.post(
    '/plugins/bank/withdrawal',
    toolsLib.security.verifyBearerTokenExpressMiddleware(['user']),
    async (req, res) => {
        const { currency, amount, bank_account } = req.body;
        const user_id = req.auth.sub.id;
        
        const pendingBurn = await toolsLib.wallet.burnAssetByKitId(
            user_id, // User kit id
            currency, // currency
            amount, // amount
            {
                status: false, // status false will make this burn pending
                description: 'Bank Withdrawal', // description
                transactionId: transaction_id // transaction id
            }
        );

        const library = PAYMENT_SERVICE_SDK_LIBRARY; // Payment service sdk
        const amount, currency = // withdrawal data from request

        // Withdrawal method for payment service sdk
        await library.withdrawal(amount, currency, bank_account)
            .then((data) => {
                if (data.successful) {
                    // If the withdrawal was successful
                    return toolsLib.wallet.updatePendingBurn(
                        pendingBurn.transaction_id, // transaction_id saved from phase 1
                        {
                            status: true,
                            // Optional: Update burn's transaction id to match 
                            // payment service withdrawal's transaction id
                            updatedTransactionId: data.transaction_id
                        }
                    );
                } else if (data.failed) {
                    // If the withdrawal failed
                    return toolsLib.wallet.updatePendingBurn(
                        pendingBurn.transaction_id, // transaction_id saved from phase 1
                        { rejected: true }
                    );
                }
            })
            .catch((err) => {
                // withdrawal request failed
                return toolsLib.wallet.updatePendingBurn(
                    pendingBurn.transaction_id, // transaction_id saved from phase 1
                    { rejected: true }
                );
            });
});

Advanced

Although bank withdrawals can be handled one by one like above, we generally recommend withdrawals to be batched in intervals. You can do this by using a cron job that runs every five minutes or so. Every time the job runs, it will query all pending burns in the database, batch them by currency, and make a single withdrawal per currency to the payment service. This will lower the amount of calls being made.

🧩