Payout systems are important for companies that have to make payment to vendors, service providers, workers, or clients. Sending rewards to users, processing salary payments, or managing payouts for a marketplace may all be automated with ease by integrating a payout API.
Are you want to get implementation help, or modify or extend the functionality of this script?
A Tutorialswebsite Expert can do it for you.
This article will walk you through integrating payout APIs with PHP, focusing on popular providers such as haodapay, SabPaisa, Cashfree, IndiConnect, Open.money, and BulkPE. Each of these platforms has dependable APIs that simplify the process of sending rewards. We’ll go over the essential processes for integrating them, highlighting major implementation strategies and considerations.
Step 1: Understand the Payout API.
Before you start writing code, you should get to know the payout provider’s API that you want to integrate.
A payout API allows you to automate and manage payments to multiple recipients from your system. It connects your application to payment service providers, enabling you to send funds directly to recipients’ bank accounts, wallets, or other payment methods.
Popular payout service providers like Haodapay, SabPaisa, Cashfree, IndiConnect, Open.money, and BulkPE offer payout APIs with different capabilities:
- Haodapay: Bank Account Payouts Accessible via RTGS, UPI, NEFT, and IMPS at all times, even on bank holidays.
- SabPaisa: Provides comprehensive payment solutions, including payouts to bank accounts, UPI, and wallets.
- Cashfree: Offers one of the most versatile payout APIs with support for bank transfers, UPI, and card payouts.
- IndiConnect: Focuses on seamless digital payments for a wide range of industries.
- Open.money: Known for its business banking solutions, including automated payouts for companies.
- BulkPE: Specializes in bulk payments, making it ideal for payroll, rewards, and other high-volume transactions.
Suggested Read: Integrate Cashfree Payment Gateway in PHP: A Step-by-Step Guide
Step-2: Understanding Common Payout API Workflow
Regardless of the payout provider, most APIs follow a similar workflow:
- Authentication: You need to authenticate your requests using an API key or token provided by the service.
- Initiating a Payout: A POST request is made to the API’s endpoint with recipient details (bank account, UPI ID, amount, etc.).
- Status Check: After initiating a payout, you can track the status (pending, success, failed) using another API call.
Each payout provider’s API has slight variations, but this general workflow will help you build a consistent payout system
Also Read: How to Integrate PhonePe Payment Gateway in PHP
Step 3: Create the Payout Integration Class
Using a class that abstracts the API interaction is a recommended approach. This makes it simple to reuse and maintain various components of your application.
Here i am going to use “Hodapay Payout API” to explain the process.
Create page PayoutIntegration.php and copy and paste below code.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
<?php class PayoutIntegration { private $client_id; private $client_secret; private $api_url; public function __construct($client_id, $client_secret,$api_url) { $this->client_id = $client_id; $this->client_secret = $client_secret; $this->api_url=$api_url; } // Method to process a payout public function processPayout($account_number, $account_ifsc, $bankname, $requesttype, $beneficiary_name, $amount, $narration) { $payload = [ 'account_number' => $account_number, 'account_ifsc' => $account_ifsc, 'bankname' => $bankname, 'requesttype' => $requesttype, 'beneficiary_name' => $beneficiary_name, 'amount' => $amount, 'narration'=> $narration ]; $response = $this->makeRequest('/payout', 'POST', $payload); return $response; } // Helper method for making HTTP requests private function makeRequest($endpoint, $method = 'POST', $data = []) { $url = $this->api_url . $endpoint; $curl = curl_init($url); $headers = [ 'x-client-id:' . $this->client_id, 'x-client-secret: ' . $this->client_secret, 'Content-Type':'Content-Type': 'application/json' ]; curl_setopt_array($curl, array( CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS =>json_encode($data), CURLOPT_HTTPHEADER => $headers, )); $response = curl_exec($curl); $http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE); curl_close($curl); if ($http_code !== 200) { return false; // Handle error, possibly log the error } return json_decode($response, true); } } |
Step 4: Initialize the Payout System
Once the class is ready, initialize it with your API credentials and make a payout request.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
// Include the PayoutIntegration class require_once 'PayoutIntegration.php'; // Initialize with your API credentials $client_id = 'x-client-id'; $client_secret = 'x-client-secret'; $api_url = 'https://api.haodapayments.com/api/v3/bank/'; $payout = new PayoutIntegration($client_id, $client_secret,$api_url); // Example: Processing a payout $account_number = '919999999999'; $account_ifsc = 'KKBK0000811'; $bankname = 'Paytm Payments Bank'; $requesttype = 'IMPS'; $beneficiary_name = 'TEST'; $amount = '10'; $narration = 'Test bank transaction'; $response = $payout->processPayout($account_number, $account_ifsc, $bankname, $requesttype, $beneficiary_name, $amount, $narration); if ($response) { echo "Payout processed successfully: " . print_r($response, true); } else { echo "Failed to process payout."; } // Example: Checking balance $balance = $payout->checkBalance(); if ($balance) { echo "Current balance: " . $balance['balance']; } else { echo "Failed to retrieve balance."; } |
Step 5: Error Handling and Logging
In real-world applications, you must handle errors gracefully, especially when dealing with external services. Update the makeRequest
method to include error handling.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
private function makeRequest($endpoint, $method = 'POST', $data = []) { $url = $this->api_url . $endpoint; $curl = curl_init($url); $headers = [ 'x-client-id:' . $this->client_id, 'x-client-secret: ' . $this->client_secret, 'Content-Type':'Content-Type': 'application/json' ]; curl_setopt_array($curl, array( CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS =>json_encode($data), CURLOPT_HTTPHEADER => $headers, )); $response = curl_exec($curl); $http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE); if (curl_errno($curl)) { $error_msg = curl_error($curl); // Log the error message error_log('CURL Error: ' . $error_msg); return false; } curl_close($curl); if ($http_code !== 200) { return false; // Handle error, possibly log the error } return json_decode($response, true); } } |
In the above code, the function checks for cURL errors and logs them. If the response from the API isn’t successful (HTTP code not 200), it also logs the failure. Use error_log()
to track issues that arise during API communication.
Are you want to get implementation help, or modify or extend the functionality of this script?
A Tutorialswebsite Expert can do it for you.
Step 6: Testing the Payout Integration
Testing is crucial when integrating a payout system. Here’s a checklist for testing your implementation
- API Key Validity: Ensure that the API key is correct and the request headers are properly configured.
- Payout Process: Simulate various payout scenarios with different amounts to ensure payouts are processed correctly.
- Error Handling: Test what happens when the payout API is down or when incorrect data is submitted.
After testing, you can deploy your payout integration to a live environment.
Do you want to get implementation help, or modify or extend the functionality of this script? Submit a paid service request
Conclusion
Integrating payout APIs like haodapay,SabPaisa, Cashfree, IndiConnect, Open.money, and BulkPE in your PHP application allows you to automate and scale financial operations efficiently. By following the steps outlined in this guide, you’ll be able to create a seamless payout solution that suits your business needs. Be sure to test thoroughly and follow best practices for secure and reliable integration.
Also Read: Integrating Razorpay Payment Gateway in PHP
FAQs
A Payout API is a method that allows companies to automate the process of sending payments to many beneficiaries. This can include vendors, service providers, employees, affiliations, and clients. Businesses can use a payout API to send payments straight to bank accounts, digital wallets, or other payment methods with little manual intervention.
Integrating a payout API in PHP offers several advantages:
Automation: Automatically send payments without manual input.
Scalability: Handle bulk payouts efficiently.
Security: Ensure secure transactions with encryption and token-based authentication.
Error Management: Track payment statuses and handle errors seamlessly.
Customization: Tailor the payout system to your specific business needs.
Yes, many payout APIs impose limits on the number of transactions you can process within a specific time frame (daily, monthly). These limits can vary based on your agreement with the payout provider. You should:
Check the API documentation for rate limits and transaction caps.
Contact your provider if you need to increase your payout limits.
Instant Payouts: Some payout providers offer instant payouts, which transfer money to recipients within minutes, typically for a higher fee.
Regular Payouts: Regular payouts can take anywhere from a few hours to several business days, depending on the provider and the recipient’s bank or payment method.
Pradeep Maurya is the Professional Web Developer & Designer and the Founder of “Tutorials website”. He lives in Delhi and loves to be a self-dependent person. As an owner, he is trying his best to improve this platform day by day. His passion, dedication and quick decision making ability to stand apart from others. He’s an avid blogger and writes on the publications like Dzone, e27.co