PHP code example of lahza / payment-gateway
1. Go to this page and download the library: Download lahza/payment-gateway 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/ */
lahza / payment-gateway example snippets
use Lahza\Facades\Lahza;
try {
use Lahza\Facades\Lahza;
$transaction = Lahza::initializeTransaction([
'email' => '[email protected] ',
'amount' => 100.50, // Automatically converted to cents
'currency' => 'USD'
]);
return redirect()->away($transaction->authorizationUrl);
} catch (\Lahza\PaymentGateway\Exceptions\PaymentException $e) {
// Handle error
}
$verified = Lahza::verifyTransaction('TXN_12345');
echo $verified->amount; // Returns decimal value
// Get supported currencies
$currencies = config('lahza.currencies');
// Get default currency
$default = Lahza::getDefaultCurrency();
Route::post('/lahza/webhook', function (Request $request) {
// Handle webhook
})->middleware('lahza.webhook');
'webhook' => [
'enabled' => true,
'secret' => env('LAHZA_WEBHOOK_SECRET'),
'middleware' => ['api']
]
try {
$transaction = Lahza::initializeTransaction(...);
} catch (\Lahza\PaymentGateway\Exceptions\PaymentValidationException $e) {
foreach ($e->getErrors() as $field => $messages) {
// Handle validation errors
}
} catch (\Lahza\PaymentGateway\Exceptions\PaymentException $e) {
logger()->error('Payment failed: ' . $e->getMessage(), [
'context' => $e->getContext()
]);
}
Lahza::fake();
// Mock specific endpoints
Lahza::fake([
'/transaction/initialize' => [
'status' => true,
'data' => [
'authorization_url' => 'https://checkout.lahza.io/fake',
'reference' => 'TEST_123'
]
]
]);****