vant / vant-laravel
A Laravel package for Vant API integration
Requires
- php: >=8.0
- guzzlehttp/guzzle: ^7.0
- illuminate/support: ^9.0|^10.0|^11.0
README
Introduction
Vant Laravel API is a Laravel package for interacting with the Vant API, providing a simple interface for handling payments, transfers, and transactions within a Laravel application.
Features
- Retrieve banks list
- Verify transfer recipients
- Initiate transfers
- Create wallets
- Fetch transaction history
- Verify transactions
- Handle webhooks securely
Installation
Step 1: Install via Composer
Run the following command to install the package:
composer require vant/vant-laravel
Step 2: Publish Configuration
After installation, publish the package configuration file:
php artisan vendor:publish --tag=config
This will create a config/vant.php
file where you can configure API settings.
Step 3: Set Up Environment Variables
Update your .env
file with your API credentials:
VANT_API_BASE_URL=https://dev.vantapp.com/api/partner/ VANT_API_KEY=your-api-key VANT_API_SIGNATURE=your-signature
Usage
Using Dependency Injection
You can inject the VantApi
service into your controllers or services:
use Vant\VantLaravel\Services\VantApi; class BankController { protected $vantApi; public function __construct(VantApi $vantApi) { $this->vantApi = $vantApi; } public function listBanks() { return $this->vantApi->getBanks(); } }
Using the Facade
Alternatively, you can use the provided Vant
facade:
use Vant\VantLaravel\Facades\Vant; $banks = Vant::getBanks();
API Methods
1. Get List of Banks
Vant::getBanks();
2. Verify Transfer Recipient
$data = [ 'account_number' => '1234567890', 'bank_code' => '044', ]; Vant::verifyTransferRecipient($data);
3. Initiate Transfer
$data = [ 'recipient' => 'recipient_code', 'amount' => 5000, 'currency' => 'NGN', ]; Vant::initiateTransfer($data);
4. Create Wallet
$data = [ 'user_id' => 12345, 'currency' => 'NGN', ]; Vant::createWallet($data);
5. Get All Transactions
Vant::allTransactions();
6. Get Transaction by Reference
Vant::getTransaction('txn_ABC123');
7. Checkout
$data = [ 'amount' => 10000, 'currency' => 'NGN', 'customer' => [ 'email' => 'customer@example.com', ], ]; Vant::checkout($data);
8. Verify Webhook Signature
if (Vant::verifyWebhook()) { // Process webhook }
Exception Handling
All API requests handle exceptions gracefully and return error messages in case of failure.
Contributing
Feel free to contribute by submitting a pull request or reporting issues.
License
This package is licensed under the MIT License.