A laravel implementation for FPX payment service

1.0.3-beta 2021-06-16 06:32 UTC

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

  1. 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=
  1. 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.

  1. Run migration to add the banks table
php artisan migrate

Usage

  1. 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();
  1. 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>
  1. 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.