aimensasi / fpx
A laravel implementation for FPX payment service
Requires
- php: ^7.4|^8.0
- illuminate/support: ^8.0
Requires (Dev)
- orchestra/testbench: ^6.0
- phpunit/phpunit: ^9.3.3
This package is auto-updated.
Last update: 2024-06-16 13:24:50 UTC
README
Very short description of the package
This package provides laravel implementations for Paynet FPX services.
Installation
You can install the package via composer:
composer require aimensasi/fpx
Then run the publish command to publish the config files and support controller
php artisan vendor:publish --provider="Aimensasi\FPX\FPXServiceProvider"
This will generate the following files
- The config file with default setup for you to override
fpx.php
- The controller that will receive payment response and any host-to-host events
Http/Controllers/FPX/Controller.php
Setups
- Add your redirect urls and your Seller and Exchange Id to the
.env
file.
FPX_INDIRECT_URL=https://app.test/payments/fpx/callback FPX_INDIRECT_PATH=payments/fpx/callback FPX_DIRECT_URL=https://app.test/payments/fpx/direct-callback FPX_DIRECT_PATH=payments/fpx/direct-callback FPX_EXCHANGE_ID= FPX_SELLER_ID=
- After generating your certificates add them to your app. By default, we look for the certificates inside the following directives.
'certificates' => [ 'uat' => [ 'disk' => 'local', // S3 or Local. Don't put your certificate in public disk 'dir' => '/certificates/uat', ], 'production' => [ 'disk' => 'local', // S3 or Local. Don't put your certificate in public disk 'dir' => '/certificates/prod', ] ],
You can override the defaults by updating the config file.
- Run migration to add the banks table
php artisan migrate
Usage
- First run the following commands to seed the banks list.
php artisan fpx:banks
you should schedule the fpx:banks Artisan command to run daily:
$schedule->command('fpx:banks')->daily();
- Add one the
x-fpx-pay
component with the following attributes
<x-fpx-pay :reference-id="$invoice->id" :datetime="$invoice->created_at->format('Ymdhms')" :amount="$invoice->total" :customer-name="$company->name" :customer-email="$company->owner->email" product-description="Salary Invoice">
During testing, you can use the test-mode
attribute to override the provided amount to 'MYR 1.00'
<x-fpx-pay :reference-id="$invoice->id" :datetime="$invoice->created_at->format('Ymdhms')" :amount="$invoice->total" :customer-name="$company->name" :customer-email="$company->owner->email" product-description="Salary Invoice" test-mode>
- Handle the payment response in
Http/Controllers/FPX/Controller.php
/** * This will be called after the user approve the payment * on the bank side * * @param Request $request * @return Response */ public function callback(Request $request) { $response = $request->handle(); // Update your order status } /** * This will handle any direct call from FPX * * @param Request $request * @return string */ public function webhook(Request $request) { $response = $request->handle(); // Update your order status return 'OK'; }
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email aimensasi@icloud.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
Laravel Package Boilerplate
This package was generated using the Laravel Package Boilerplate.