PHP code example of sudiptpa / omnipay-mpgs
1. Go to this page and download the library: Download sudiptpa/omnipay-mpgs 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/ */
sudiptpa / omnipay-mpgs example snippets
$gateway = Omnipay::create('Mpgs_Hosted')
->setMerchantId(xxxxxxx)
->setApiPassword(xxxxxx)
->setApiUrlPrefix('https://na-gateway.mastercard.com');
try {
$response = $gateway->purchase([
'merchantName' => 'Test Merchant',
'amount' => 10,
'transactionId' => 1,
'transactionReference' => 1,
'currency' => 'AUD',
'card' => new CreditCard([
'billingFirstName' => 'First Name',
'billingLastName' => 'Last Name',
'email' => '[email protected] ',
'billingPhone' => '1234567890',
'billingAddress1' => 'Street',
'billingCity' => 'City',
'billingState' => 'State',
'billingPostcode' => '03444',
'billingCountry' => 'AUS',
]),
'cancelUrl' => 'https://example.com/checkout/1/cancel',
'returnUrl' => 'https://example.com/checkout/1/success',
'notifyUrl' => 'https://example.com/checkout/1/notify',
]);
} catch (Exception $e) {
// error
}
if ($response->isSuccessful()) {
// $response->getSessionId();
}
$response = $gateway->completePurchase([
'orderId' => 1,
]);
if ($response && $response->isSuccessful() && $response->isCaptured()) {
// successful
}
// handle error