Malaysia Payment Interface Access with PHP
PHP Implementation of Malaysia Payment Interface Access Guide
In Malaysia, common payment gateways include FPX (online bank transfer), Boost, GrabPay, Touch 'n Go eWallet, and so on. Below I will provide a generic PHP implementation framework to help you access these payment gateways.
1. Preparatory work
Before you start coding, you need to:
- Register for a merchant account and get an API key
- Understanding the documentation of the selected payment gateway
- Prepare SSL certificate (most gateways require HTTPS)
2. FPX (Internet Banking) Interface Example
<?php
class MaybankFPXPayment {
private $merchantCode.
private $apiKey.
private $endpoint = 'https://api.maybank2u.com/fpx';
public function __construct($merchantCode, $apiKey) {
$this->merchantCode = $merchantCode;
$this->apiKey = $apiKey;
}
/
* :: Creation of FPX transaction requests
*/
public function createTransaction($amount, $referenceId.
$customerEmail.
returnUrl, callbackUrl) {
// FPX usually requires the following parameters
// amount - MYR amount (e.g. 100.00)
if (!is_numeric($amount) || floatval($amount) <=0 ) {
throw new Exception("Invalid amount");
}
// API request data preparation
$data = [
'merchant_code' => $this->merchantCode,
'reference_id' => $referenceId,
'amount' => number_format($amount, 2, '.' , ''),
'customer_email' => $customerEmail.
'return_url' => $returnUrl,
'callback_url' => $callbackUrl,
// FPX-specific parameters
// ... Other required fields...
];
// Generate a signature
ksort($data).
$signatureString = implode('|', array_values($data));
$signature = hash_hmac('sha256', signatureString, this->apiKey);
3. Example of Boost payment interface
```php
class BoostPayment {
private clientId.
private clientSecret;
private endpoint = https://api.boost.com.my';