PHP code example of sixersoft / eps

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

    

sixersoft / eps example snippets


use Sixersoft\Eps\Facades\EPS;

// 1. Initialize Payment
$result = EPS::initializePayment([
    'amount' => 150,                    // Can be in USD if conversion enabled
    'currency' => 'USD',                // Optional - triggers conversion if enabled
    'customer_name' => 'John Doe',
    'customer_email' => '[email protected]',
    'customer_phone' => '01911223344',
    'customer_address' => '123 Main St, Dhaka',
    'customer_city' => 'Dhaka',
    'customer_state' => 'Dhaka',
    'customer_postcode' => '1200',
    'success_url' => 'https://yoursite.com/payment/success',
    'fail_url' => 'https://yoursite.com/payment/fail',
    'cancel_url' => 'https://yoursite.com/payment/cancel',
    'product_name' => 'Premium T-Shirt',
    // 'products' => [...]              // Optional: full ProductList array
]);

if ($result['success']) {
    // Redirect user to EPS gateway
    return redirect()->away($result['redirect_url']);
}

return back()->with('error', $result['message']);

use Sixersoft\Eps\EPS;

public function pay(EPS $eps)
{
    $result = $eps->initializePayment([...]);
}

use Sixersoft\Eps\Facades\EPS;

public function success(Request $request)
{
    $merchantTxnId = $request->get('merchantTransactionId') 
        ?? session('eps_merchant_txn_id');

    $verification = EPS::verifyTransaction($merchantTxnId);

    if ($verification['success']) {
        // Update your order as PAID
        // Order::where('merchant_transaction_id', $merchantTxnId)->update(['status' => 'paid']);
        
        return view('payment.success', compact('verification'));
    }

    return view('payment.failed', compact('verification'));
}

$result = EPS::initializePayment([
    'amount' => 10,           // 10 USD
    'currency' => 'USD',
    // ... other fields
]);

// In response you will get:
// 'converted_amount_bdt' => 1180.00
// 'original_amount' => 10
// 'currency' => 'USD'

use Sixersoft\Eps\Facades\EPS;

$bdtAmount = EPS::convertToBDT(25, 'USD');   // 25 USD → BDT using current rate

// Or get the converter for advanced use
$converter = EPS::currency();
$converter->setRate('USD', 119.75);           // Update rate at runtime
$converter->setEnabled(true);

echo EPS::convertToBDT(5, 'EUR');

EPS::setConfig([
    'is_sandbox' => false,
    'merchant_id' => 'live-xxx',
]);

// routes/web.php
Route::get('/payment/success', [PaymentController::class, 'success']);
Route::get('/payment/fail', [PaymentController::class, 'fail']);
Route::get('/payment/cancel', [PaymentController::class, 'cancel']);
bash
php artisan vendor:publish --provider="Sixersoft\Eps\EpsServiceProvider" --tag="eps-config"
bash
php artisan config:clear