PHP code example of paychangu / laravel

1. Go to this page and download the library: Download paychangu/laravel library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

paychangu / laravel example snippets


return [
    /*
    |--------------------------------------------------------------------------
    | PayChangu API Private Key
    |--------------------------------------------------------------------------
    |
    | This is the private key used to authenticate with the PayChangu API.
    |
    */
    'private_key' => env('PAYCHANGU_API_PRIVATE_KEY'),

    /*
    |--------------------------------------------------------------------------
    | PayChangu API Base URL
    |--------------------------------------------------------------------------
    |
    | This is the root URL for the PayChangu API.
    | Specific endpoints (checkout, mobile-money) will be constructed from this.
    |
    */
    'api_base_url' => env('PAYCHANGU_API_BASE_URL', 'https://api.paychangu.com/'),
];

use Paychangu\Laravel\Facades\Paychangu;

$response = Paychangu::create_checkout_link([
    'amount' => 5000,
    'currency' => 'MWK',
    'return_url' => 'https://yoursite.com/success',
    'callback_url' => 'https://yoursite.com/callback',
    'email' => '[email protected]',
    'first_name' => 'John',
    'last_name' => 'Doe',
    'meta' => ['order_id' => '123']
]);

if ($response['success']) {
    return redirect($response['data']['checkout_url']);
}

$verification = Paychangu::verify_checkout('TXN_1234567890');

$operators = Paychangu::mobile_money_operators();

$response = Paychangu::create_mobile_money_payment([
    'mobile' => '0999123456', // Phone number in format 265... or 099...
    'mobile_money_operator_ref_id' => 'mpamba_ref_id', // Get from mobile_money_operators()
    'amount' => 1000,
    'charge_id' => 'unique_charge_id_123', // Must be unique for every transaction
]);

$verification = Paychangu::verify_mobile_money_payment('unique_charge_id_123');

$details = Paychangu::get_mobile_money_payment_details('unique_charge_id_123');

$response = Paychangu::create_direct_charge_payment([
    'currency' => 'MWK', // Currency code (e.g., 'MWK', 'USD')
    'amount' => 50000,
    'payment_method' => 'mobile_bank_transfer',
    'charge_id' => 'bank_charge_001', // Must be unique for every transaction
]);

$details = Paychangu::get_direct_charge_details('bank_charge_001');

$response = Paychangu::create_card_payment([
    'card_number' => '4000123456789010',
    'expiry' => '12/25', // Format: MM/YY
    'cvv' => '123',
    'cardholder_name' => 'John Doe',
    'amount' => 5000,
    'currency' => 'MWK',
    'charge_id' => 'card_charge_001', // Must be unique for every transaction
    'redirect_url' => 'https://yoursite.com/card-callback', // URL to redirect after payment
]);

$verification = Paychangu::verify_card_payment('card_charge_001');

$refund = Paychangu::refund_card_payment('card_charge_001');

$operators = Paychangu::mobile_money_payout_operators();

$response = Paychangu::create_mobile_money_payout([
    'mobile' => '0888123456', // Phone number in format 265... or 088...
    'mobile_money_operator_ref_id' => 'airtel_money_ref_id', // Get from mobile_money_payout_operators()
    'amount' => 2000,
    'charge_id' => 'payout_001', // Must be unique for every transaction
    // Optional fields:
    // 'email' => '[email protected]',
    // 'first_name' => 'John',
    // 'last_name' => 'Doe',
]);

$details = Paychangu::get_mobile_money_payout_details('payout_001');

$banks = Paychangu::get_supported_banks_for_payout('MWK');

$response = Paychangu::create_bank_payout([
    'bank_uuid' => 'bank_uuid_here', // Get from get_supported_banks_for_payout()
    'amount' => 100000,
    'charge_id' => 'bank_payout_001', // Must be unique
    'bank_account_name' => 'Jane Doe',
    'bank_account_number' => '100200300',
    // Optional fields:
    // 'payout_method' => 'bank_transfer', // Defaults to 'bank_transfer' if not provided
    // 'email' => '[email protected]',
    // 'first_name' => 'Jane',
    // 'last_name' => 'Doe',
]);

$details = Paychangu::get_bank_payout_details('bank_payout_001');

$allPayouts = Paychangu::get_all_bank_payouts();

$billers = Paychangu::get_billers();

$billerDetails = Paychangu::get_biller_details('ESCOM');

$validation = Paychangu::validate_bill([
    'biller' => 'ESCOM',
    'account' => '123456789',
]);

$payment = Paychangu::pay_bill([
    'biller' => 'ESCOM',
    'account' => '123456789',
    'amount' => 5000,
    'reference' => 'bill_payment_001',
]);

$details = Paychangu::get_bill_transaction('bill_payment_001');

$stats = Paychangu::get_bill_statistics();

$airtime = Paychangu::buy_airtime([
    'phone' => '0888123456',
    'amount' => 1000,
    'reference' => 'airtime_ref_001',
]);

$customer = Paychangu::create_virtual_account_customer([
    'email' => '[email protected]',
    'first_name' => 'John',
    'last_name' => 'Banda',
]);

$customers = Paychangu::get_virtual_account_customers([
    'page' => 1,
    'per_page' => 20,
]);

$customer = Paychangu::get_virtual_account_customer('customer_id_here');

$updated = Paychangu::update_virtual_account_customer('customer_id_here', [
    'email' => '[email protected]',
]);

$deleted = Paychangu::delete_virtual_account_customer('customer_id_here');

$account = Paychangu::create_us_account('customer_id_here');

$deactivated = Paychangu::deactivate_us_account('customer_id_here');
$reactivated = Paychangu::reactivate_us_account('customer_id_here');

$activity = Paychangu::us_account_activity('customer_id_here');
bash
php artisan vendor:publish --tag="paychangu-config"