In This Blog, I Will show you how to implement moneris payment gateway.Integrating Moneris Payment Gateway into your PHP-based e-commerce platform enables secure and seamless online transactions. Moneris, a trusted leader in payment processing, offers a robust API and SDK for developers to incorporate payment functionality into their applications. By leveraging Moneris, businesses can provide customers with a convenient and reliable payment experience, enhancing trust and driving sales. In this guide, we'll walk through the steps to implement Moneris Payment Gateway using PHP, empowering you to accept payments efficiently and securely on your platform.
Create a Moneris Account:
First, you need to sign up for a Moneris account and get your API credentials (store ID and API token).
Create mpgClasses.php
mpgClasses.php typically refers to a file that contains classes required for interacting with the Moneris Payment Gateway (MPG) using PHP. These classes encapsulate various functionalities such as making API requests, parsing responses, handling transactions, and more.
The structure of mpgClasses.php may vary depending on the specific implementation and requirements of the integration. Generally
Link : https://github.com/Moneris/eCommerce-Unified-API-PHP/blob/master/mpgClasses.php
Link : https://github.com/Moneris/eCommerce-Unified-API-PHP/blob/master/mpgClasses.php
Implementation Using PHP
<?php
require "mpgClasses.php";
/**************************** Request Variables *******************************/
$store_id = 'store5';
$api_token = 'yesguy';
/************************* Transactional Variables ****************************/
$type = "purchase";
$cust_id = $_POST["cust_id"];
$order_id = $_POST["order_id"];
$amount = $_POST["amount"];
$pan = $_POST["pan"];
$expiry_date = $_POST['$expiry_date'];
$crypt = "7";
$dynamic_descriptor = "123";
$status_check = "false";
/*********************** Transactional Associative Array **********************/
$txnArray = ["type" => $type, "order_id" => $order_id, "cust_id" => $cust_id, "amount" => $amount, "pan" => $pan, "expdate" => $expiry_date, "crypt_type" => $crypt, "dynamic_descriptor" => $dynamic_descriptor,
//,'wallet_indicator' => '' //Refer to documentation for details
//,'cm_id' => '8nAK8712sGaAkls56' //set only for usage with Offlinx - Unique max 50 alphanumeric characters transaction id generated by merchant
];
$avsArray = ["avs_street_number" => 123, "avs_street_name" => "Main St", "avs_zip_code" => "12345", ];
/**************************** Transaction Object *****************************/
$mpgTxn = new mpgTransaction($txnArray);
/******************* Credential on File **********************************/
$cof = new CofInfo();
$cof->setPaymentIndicator("U");
$cof->setPaymentInformation("2");
$cof->setIssuerId($_POST["issue_id"]);
$mpgTxn->setCofInfo($cof);
//$mpgTxn->setAvsInfo($avsArray);
$mpgCustInfo = new mpgCustInfo();
$shipping = ["address" => $_POST["billing_street_number"], "city" => $_POST["billing_street_name"],
// 'province' => 'Canada',
"postal_code" => $_POST["billing_zipcode"], ];
$mpgCustInfo->setShipping($shipping);
$mpgTxn->setCustInfo($mpgCustInfo);
/****************************** Request Object *******************************/
$mpgRequest = new mpgRequest($mpgTxn);
$mpgRequest->setProcCountryCode("CA"); //"US" for sending transaction to US environment
$mpgRequest->setTestMode(false); //false or comment out this line for production transactions
/***************************** HTTPS Post Object *****************************/
/* Status Check Example
$mpgHttpPost =new mpgHttpsPostStatus($store_id,$api_token,$status_check,$mpgRequest);
*/
$mpgHttpPost = new mpgHttpsPost($store_id, $api_token, $mpgRequest);
/******************************* Response ************************************/
$mpgResponse = $mpgHttpPost->getMpgResponse();
//echo '<pre>';print_r($mpgResponse->getResponseCode());die;
print_r(json_encode($mpgResponse->responseData));
Testing:
Test your integration in a sandbox or testing environment provided by Moneris before deploying it to production
Make sure to test your integration thoroughly in Moneris' test environment before going live. Also, ensure that you handle errors and exceptions gracefully in your production code.
This is a basic example and might need adjustments based on your specific requirements and the features provided by the Moneris API. Make sure to consult the Moneris API documentation for detailed information on available methods and parameters. Additionally, always remember to handle user input securely to prevent security vulnerabilities such as SQL injection or cross-site scripting (XSS) attacks.