PHP code example of leesiongchan / omnipay-molpay

1. Go to this page and download the library: Download leesiongchan/omnipay-molpay 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/ */

    

leesiongchan / omnipay-molpay example snippets


$gateway = Omnipay::create('MOLPay');

$gateway->setCurrency('MYR');
$gateway->setEnableIPN(true); // Optional
$gateway->setLocale('en'); // Optional
$gateway->setMerchantId('test1234');
$gateway->setVerifyKey('abcdefg');

$options = [
    'amount' => '10.00',
    'card' => new CreditCard(array(
        'country' => 'MY',
        'email' => '[email protected]',
        'name' => 'Lee Siong Chan',
        'phone' => '0123456789',
    )),
    'description' => 'Test Payment',
    'transactionId' => '20160331082207680000',
    'paymentMethod' => 'credit', // Optional
];

$response = $gateway->purchase($options)->send();

// Get the MOLPay payment URL (https://www.onlinepayment.com.my/MOLPay/pay/...)
$redirectUrl = $response->getRedirectUrl();

$response = $gateway->completePurchase($options)->send();

if ($response->isSuccessful()) {
    // Do something
    echo $response->getTransactionReference();
} elseif ($response->isPending()) {
    // Do something
} else {
    // Error
}

$gateway = Omnipay::create('MOLPay');

$gateway->setMerchantId('your_merchant_id');
$gateway->setVerifyKey('your_verify_key');
$gateway->setSecretKey('your_secret_key');

$request = $gateway->void([
    'transactionReference' => '25248208'
]);
        
$response = $request->send();

if ($response->isSuccessful()) {
    // Update your data model
} else {
    echo $response->getMessage();
}

$gateway = Omnipay::create('MOLPay');

$gateway->setMerchantId('your_merchant_id');
$gateway->setVerifyKey('your_verify_key');
$gateway->setSecretKey('your_secret_key');

$request = $gateway->refund([
    'transactionReference'  => '25248208',
    'refId'                 => 'merchant_refund_red_id',
    'amount'                => '10.00',
    'channel'               => $transaction_channel, // data saved from $gateway->purchase() response, e.g FPX_MB2U
    'bankCode'              => $bank_code, // from user who request to refund
    'beneficiaryName'       => $beneficiary_name, // from user who request to refund
    'beneficiaryAccountNo'  => $beneficiary_account_no, // from user who request to refund
]);
        
$response = $request->send();

// The refund process will take about 7-14 days after the request sent
if ($response->isSuccessful() || $response->isPending() ) {
    // Update your data model
} else {
    echo $response->getMessage();
}