PHP code example of zarulizham / laravel-fpx

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

    

zarulizham / laravel-fpx example snippets


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=

'certificates' => [
	'uat' => [
		'disk' => 'local', // S3 or Local. Don't put your certificate in public disk
		'dir' => '/paynet/fpx/uat',
	],
	'production' => [
		'disk' => 'local', // S3 or Local. Don't put your certificate in public disk
		'dir' => '/paynet/fpx/prod',
	]
],

use Illuminate\Foundation\Configuration\Middleware;

->withMiddleware(function (Middleware $middleware): void {
	$middleware->validateCsrfTokens(except: [
		'fpx/direct',
	]);
})

$schedule->command('fpx:banks')->daily();

 <x-fpx-payment
		: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"
		:class="css class name for styling button">

 <x-fpx-payment
		: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"
		:class="css class name for styling button"
		test-mode>


	/**
	 * This will be called after the user approve the payment
	 * on the bank side
	 */
	public function direct(Request $request) {
		$response = $request->handle();

		// Update your order status
		return 'OK';
	}

	/**
	 * This will handle any browser redirect from FPX
	 */
	public function indirect(Request $request) {
		$response = $request->handle();

		// Update your order status
		return redirect('some/url');
	}


use ZarulIzham/Fpx/Fpx;

/**
 * Returns status of transaction
 * 
 * @param string $reference_id reference order id
 * @return array
 */
$status = Fpx::getTransactionStatus($reference_id);


/**
 * returns collection of bank_id and name 
 * 
 * @param bool $getLatest (optional) pass true to get latest banks 
 * @return \Illuminate\Support\Collection
 */
$banks = Fpx::getBankList(true);


use ZarulIzham\Fpx\Fpx;

public function boot(): void
{
	Fpx::auth(function ($request) {
		return $request->user()
			&& $request->user()->role('Programmer');
	});
}

{
  "response": {
    "status": "succeeded/failed/pending",
    "message": "Payment is successful",
    "transaction_id": "",
    "reference_id": "",
    "amount": "",
    "transaction_timestamp": "",
    "buyer_bank_name": "",
    "response_format": "JSON",
    "additional_params": "type=123"
  },
  "fpx_response": {
    "fpx_debitAuthCode": "",
    "fpx_debitAuthNo": "",
    "fpx_sellerExId": "",
    "fpx_creditAuthNo": "",
    "fpx_buyerName": "",
    "fpx_buyerId": null,
    "fpx_sellerTxnTime": "",
    "fpx_sellerExOrderNo": "",
    "fpx_makerName": "",
    "fpx_buyerBankBranch": "",
    "fpx_buyerBankId": "",
    "fpx_msgToken": "",
    "fpx_creditAuthCode": "",
    "fpx_sellerId": "",
    "fpx_fpxTxnTime": "",
    "fpx_buyerIban": null,
    "fpx_sellerOrderNo": "",
    "fpx_txnAmount": "",
    "fpx_fpxTxnId": "",
    "fpx_checkSum": "",
    "fpx_msgType": "",
    "fpx_txnCurrency": "",
  }
}
bash
php artisan fpx:publish
bash
php artisan vendor:publish --provider="ZarulIzham\\Fpx\\FpxServiceProvider" --tag="fpx-migrations"
bash
php artisan migrate
bash
php artisan fpx:banks
bash
php artisan fpx:payment-status
bash
php artisan fpx:payment-status reference_id1,reference_id2,reference_id3