PHP code example of vp-trading / chapa-laravel

1. Go to this page and download the library: Download vp-trading/chapa-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/ */

    

vp-trading / chapa-laravel example snippets


use Vptrading\ChapaLaravel\Facades\Chapa;
use VpTrading\ChapaLaravel\ValueObjects\User;
use VpTrading\ChapaLaravel\ValueObjects\Customization;
use Money\Money;

$response = Chapa::acceptPayment([
    Money::ETB(10000),
    new User(
        firstName: 'John',
        lastName: 'Doe',
        email: '[email protected]',
        phoneNumber: '0912345678'
    ),
    route('return-url'),
    new Customization(
        title: 'VP Solutions',
        description: 'This package is working like a charm.',
        logo: 'https://vptrading.et/wp-content/uploads/2023/08/cropped-VP-Logo-Symbol-White.png'
    )
]);

// Redirect user to payment page
return redirect($response->checkout_url);

use Vptrading\ChapaLaravel\Facades\Chapa;

$tx_ref = 'unique-tx-ref-123';
$verification = Chapa::verify($tx_ref);

if ($verification->data['status'] === 'success') {
    // Payment was successful
}

use Vptrading\ChapaLaravel\Facades\Chapa;
use Money\Money;

$chapaRef = "APfxLoHHsl1eD";
Chapa::refund($chapaRef, Money::ETB(10000), 'Client Requested Refund');

class WebhookController extends ChapaWebhookController
{
    public function __invoke(Request $request)
    {
        parent::__invoke($request);

        // Handle your custom logic here.
    }
}
bash
    php artisan vendor:publish --provider="Vptrading\ChapaLaravel\ChapaServiceProvider"
    
bash
    php artisan migrate
    
bash
    CHAPA_SECRET_KEY=your_chapa_secret_key_here
    CHAPA_API_VERSION=v1
    CHAPA_CALLBACK_URL=/vp/chapa/webhook
    CHAPA_WEBHOOK_SECRET=54LZzhZbPs7yreuS6bAw74zS0KE7P4Mt1fiqRx7wOL8OdjUQHjBqsIpkpT2rm43S
    CHAPA_REF_PREFIX=vp_chapa_