khidirdotid / flashmobile-laravel
A Flash Mobile Wrapper for Laravel
Fund package maintenance!
Saweria
v1.0.1
2024-12-10 09:12 UTC
Requires
- php: ^8.1
- illuminate/support: ^10.0|^11.0
Requires (Dev)
- nunomaduro/collision: ^8.0
- pestphp/pest: ^3.0
- pestphp/pest-plugin-laravel: ^3.0
README
A Flash Mobile Wrapper for Laravel
Installation
-
Install the package
composer require khidirdotid/flashmobile-laravel
-
Publish the config file
php artisan vendor:publish --provider="KhidirDotID\FlashMobile\Providers\FlashMobileServiceProvider"
-
Add the Facade to your
config/app.php
intoaliases
section'FlashMobile' => KhidirDotID\FlashMobile\Facades\FlashMobile::class,
-
Add ENV data
FLASH_CLIENT_ID= FLASH_SECRET_KEY= FLASH_ENVIRONMENT=sandbox
or you can set it through the controller
\FlashMobile::setClientId('FLASH_CLIENT_ID'); \FlashMobile::setSecretKey('FLASH_SECRET_KEY'); \FlashMobile::setProduction(false);
Usage
Create QR Payment
- Get Payment QR String
$data = [ 'terminal_id' => 'INV-' . time(), 'external_id' => 'INV-' . time(), 'amount' => 10000, 'session_time' => 1, // in minutes 'fullname' => '', 'email' => '', 'phone_number' => '' ]; try { // Get QR String $payment = \FlashMobile::createQRPayment($data); // Combine with QR Generator Package. e.g: simplesoftwareio/simple-qrcode $qrCode = \SimpleSoftwareIO\QrCode\Facades\QrCode::generate($payment['qr_string']); echo '<img src="data:image/svg+xml;base64,{{ base64_encode($qrCode) }}">'; } catch (\Throwable $th) { throw $th; }
Handle HTTP Notification
- Create route to handle notifications
Route::match(['GET', 'POST'], 'flash.ipn', [PaymentController::class, 'flashIpn'])->name('flash.ipn');
- Create method in controller
public function paymentIpn(Request $request) { try { $response = \FlashMobile::getPaymentStatus($request->transaction_id); if (strtolower($response['status']) == 'success') { // TODO: Set payment status in merchant's database to 'success' } } catch (\Throwable $th) { throw $th; } }
- Except verify CSRF token in
app/Http/Middleware/VerifyCsrfToken.php
protected $except = [ 'flash/ipn' ];