Created
July 21, 2018 13:30
-
-
Save nazan/0de171204a62f8f070a5f7e39b6cc856 to your computer and use it in GitHub Desktop.
BML Payment Gateway How To
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once __DIR__.'/vendor/autoload.php'; | |
use aharen\Pay\Gateway; | |
use aharen\Pay\Exceptions\SignatureMissmatchException; | |
$gateway = new Gateway('MPG'); | |
$txnId = $this_should_be_your_order_id.'_'.date("ymd"); // date suffix is not required. | |
$callbackUrl = $this_should_be_your_callback_url; // replace here with your actual callback url. | |
$callbackUrl = str_replace('https:', 'http:', $callbackUrl); | |
if(strpos($callbackUrl, '?') !== false) { | |
$callbackUrl .= '&'; | |
} else { | |
$callbackUrl .= '?'; | |
} | |
$callbackUrl = $callbackUrl . "orer_id=$this_should_be_your_order_id&txn_id=$txnId"; | |
$paymentGatewayUrl = "https://pay.mv"; | |
$config = [ | |
'Version' => '1.1', | |
'Host' => $paymentGatewayUrl, | |
'MerRespURL' => $callbackUrl, | |
'AcqID' => $your_acquirer_id, | |
'MerID' => $your_merchant_id, | |
'MerPassword' => $your_merchant_password | |
]; | |
$gateway->config($config); | |
$gateway->transaction($this_should_be_your_txn_total_money_amount, $txnId); | |
// Below call returns an associtive array. | |
// keys of array are HTTP POST parameters. | |
// values of array are HTTP POST parameter values. | |
$post_body_as_associative_array = $gateway->get(); | |
// use following code to generate your view. | |
$input_fields = array(); | |
foreach($post_body_as_associative_array as $key => $value){ | |
$input_fields[] = "<input type='hidden' name='$key' value='$value'/>"; | |
} | |
$postFormAsString = '<form action="'.$paymentGatewayUrl.'" method="post"> | |
' . implode('', $input_fields) . ' | |
<input type="submit" value="Pay via BML Payment Gateway" /> | |
</form>'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once __DIR__.'/vendor/autoload.php'; | |
use aharen\Pay\Gateway; | |
use aharen\Pay\Exceptions\SignatureMissmatchException; | |
$txnId = $this_should_be_your_order_id.'_'.date("ymd"); // date suffix is not required. | |
$callbackUrl = $this_should_be_your_callback_url; // replace here with your actual callback url. | |
$callbackUrl = str_replace('https:', 'http:', $callbackUrl); | |
if(strpos($callbackUrl, '?') !== false) { | |
$callbackUrl .= '&'; | |
} else { | |
$callbackUrl .= '?'; | |
} | |
$callbackUrl = $callbackUrl . "orer_id=$this_should_be_your_order_id&txn_id=$txnId"; | |
$paymentGatewayUrl = "https://pay.mv"; | |
// this initiates MPG | |
$config = [ | |
'Host' => $paymentGatewayUrl, | |
'MerRespURL' => $callbackUrl, | |
'AcqID' => $your_acquirer_id, | |
'MerID' => $your_merchant_id, | |
'MerPassword' => $your_merchant_password | |
]; | |
$gateway = new Gateway('MPG'); | |
try { | |
$r = $gateway->config($config)->callback($_POST, $txnId); | |
return "If you reach here then payment is completed successfully."; | |
} catch(SignatureMissmatchException $excp) { | |
return array(0, 'Signature mismatch: ' . $excp->getMessage()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment