Perfecto CMS - Content management system
  • Русский язык
  • English version
Sign in
Create an account
PerfectoCMS Documentation
PerfectoCMS Documentation
You can find best practices on all major configuration procedures that will help you plan better your resources and environment.

Universal payment gateway

7,301 views / 16 Jan 2015 edited
UPG (Universal Payment Gateway) - module that manages payment acceptance through web site.
This document provides instructions for using UPG module for accepting payments on your website.

Foreword

Module idea - posses universal code and famous payment systems may be connected to it, they can be used with various web site modules, in order to organize payment acceptance. This module integrated in Perfecto CMS Basic and Perfecto CMS Maxi.

By default module integrated payment systems:
 
Robokassa
Interkassa
 
For site owners
The following module allows you to know beforehand that your system possesses generic system. This system helps to turn on additional payment systems with minor PHP programming skills.
For developers
You almost have fundamentally successful API. If you are interested in expanding payment acceptance list or you have your own payment system that meets all popular services standards, please contact us.
 

API

The module consists of 2 parts: some functions, templates and module global class, which will be improved and expanded.
Module name is: payment
Class name is: payment

UPG Structure
# module folder - contains the payment module and processing systems
./modules/frontend/payment/
# UPG module has a standard structure and functionality
./modules/frontend/payment/module.php
# module configs, is a standard XML file
# when you integrate a new module in the file must specify name of product id variable, which will receive from payment system from $ _POST request.
# example: when connecting WebMoney Merchant must specify: < webmoney >LMI_PAYMENT_NO< / webmoney >

./modules/frontend/payment/config.xml
# this folder contains processing centers modules
# the name of the configuration file and the module file must be identical. Example: paypal.xml and paypal.php

./modules/frontend/payment/method/
# icons for payment systems that will be displayed to end user
# create any name of the file and write it into the config file (XML)

./modules/frontend/payment/method/icons/
# processing system: Robokassa
./modules/frontend/payment/method/robokassa.php
# configs for processing system: Robokassa
./modules/frontend/payment/method/robokassa.xml
# processing system: Interkassa
./modules/frontend/payment/method/interkassa.php
# configs for processing system: Interkassa
./modules/frontend/payment/method/interkassa.xml

It's easy and affordable — to start accepting payments online

Let's look at an example of the structure of the Robokassa processing center.
First look the function getConfig($core);, which receives the processing configs from XML.
You can use an identical function in your modules for new processing centers.
	function getConfig($core) {

# Gateway file name and the config file name must be the same
$conf_file = str_replace(".php",".xml",__FILE__);

# Get configuration from XML
$gateway_config = $core->xml2array(file_get_contents($conf_file));

# Set `payment_config`
$payment_config = $gateway_config['gateway'];

# If test mode on, change payment URL
if ($payment_config['test_mode'] == 1) { $payment_config['url'] = $payment_config['testurl']; }

# Get user ID, for not logged ID = 0
$payment_config['payer_login'] = isset($_SESSION['logged_id']) ? $_SESSION['logged_id'] : 0;

return $payment_config;
}
As you can see, name of the module settings formed(presumably) the name of the payment system module. After that is done start parsing the config file.

What is the payment module itself?
New payment system is necessary to create a total of 4 main functions with names process(), success(), result(), fail()
UPG based for receive data from these 4 callback functions. Consider the example Robokassa.

FUNCTION: PROCESS()
This function is designed to form creation, that will send data to the payment gateway and control the order on the site.

Example
	function process($core, $db, $payDate, $STATUS) {

# receiving configurations
$config = getConfig($core);

# additional data
$config['out_summ'] = $payDate['sum'];
$config['desc'] = $payDate['description'];
$config['inv_id'] = $payDate['ID'];

# change sum by rate
$config['out_summ'] = $config['out_summ']*$config['rate'];

# create checksum
$config['crc'] = md5($config['login'].":".$config['out_summ'].":".$config['inv_id'].":".$config['mrh_pass1'].":Shp_item=".$config['shp_item']);

# create payment form
$result['form'] = '< form action='.$config['url'].' method='.$config['method'].'>
< input type=hidden name=MrchLogin value="'.$config['login'].'">
< input type=hidden name=OutSum value="'.$config['out_summ'].'">
< input type=hidden name=InvId value="'.$config['inv_id'].'">
< input type=hidden name=Desc value="'.$config['desc'].'">
< input type=hidden name=SignatureValue value="'.$config['crc'].'">
< input type=hidden name=Shp_item value="'.$config['shp_item'].'">
< input type=hidden name=IncCurrLabel value="'.$config['in_curr'].'">
< input type=hidden name=Culture value="'.$config['culture'].'">
< input type=submit value="'.$payDate['btn_value'].'" class="btn">
< /form>';

$result['desc'] = $config['desc'];
$result['sum'] = $config['out_summ']/$config['rate'];
$result['id'] = $config['inv_id'];

if (intval($config['inv_id']) > 0) {
return $result;
}
else {
$result['error'] = 2;
return $result;
}
}
  Incoming data
Create function: process($core, $db, $payDate, $STATUS).
$core and $db using a system standart classes: CORE and MYSQL.
Read more for this classes in «API documentation» page.
$payDate - create array with dataset:
[ID] => transaction id
[module] => store module name (example: catalog)
[item] => product identification (id)
[service] => payment system name (example: robokassa)
[user] => payer identification (user id)
[sum] => transaction sum
[date_create] => date of create transaction
[description] => product description
[status] => product status
[currency] => currency
[btn_value] => payment form button value
$STATUS - create array with statuses:
[PENDING] => pending payment
[COMPLETED] => payment complete successfully
[FAILED] => payment fail
[DENIED] => payment denied
[REFUNDED] => payment refunded
[CANCELED] => payment canceled by user
  Common Response Fields
You get array with dataset
[form] => HTML POST form
[desc] => product description
[sum] => product sum
[id] => product id
[error] => error number (if have an errors)


FUNCTION: SUCCESS()
This function is run after success payment

Example
	function success($core) {

$config = getConfig($core);
$crc = $_REQUEST["SignatureValue"];
$result['sum'] = number_format($_REQUEST["OutSum"], 2, '.', '');
$result['id'] = $_REQUEST["InvId"];

# signature
$crc = strtoupper($crc);
$my_crc = strtoupper(md5($_REQUEST["OutSum"] . ":" . $_REQUEST["InvId"] . ":" . $config['mrh_pass1'] . ":Shp_item=" .$_REQUEST["Shp_item"]));

# check signature
# and return to UPG module status 1 or 3 (1 - success payment, 3 - error)
if ($my_crc != $crc) {
$result['error'] = 3;
}
else {
$result['success'] = 1;
}
return $result;

}
  Incoming data
Create function success($core)
  Common Response Fields
You get array with dataset:
[id] => transaction id (into the store)
[sum] => transaction sum
[error] => error number (if it is set)
[success] => if payment is success, set value 1


FUNCTION: FAIL()
This function is run after fail payment

Example
	function fail($core) {

# return status and id for UPG module, to display error message
$result['fail'] = 4;
$result['id'] = intval($_REQUEST["InvId"]);

return $result;

}
  Incoming data
Create function fail($core)
  Common Response Fields
You get array with dataset:
[id] => transaction id (into the store)
[fail] => error number (4 - canceled by user)


FUNCTION: RESULT()
This function is run via processing center request

Example
	function result($core, $db, $STATUS) {

$config = getConfig($core);

$result['success'] = 1;
$result['OutSum'] = $_REQUEST["OutSum"];
$result['id'] = intval($_REQUEST["InvId"]);
$result['Shp_item'] = $_REQUEST["Shp_item"];
$result['time'] = time();
$crc = strtoupper($_REQUEST["SignatureValue"]);

# signature
$my_crc = strtoupper(md5($result['OutSum'].":".$result['id'].":".$config['mrh_pass2'].":Shp_item=".$result['Shp_item']));

# check signature
if ($crc != $my_crc) {
echo "bad signn";
exit();
}

/* your code here */

return $result;
}
  Incoming data
Create function result($core, $db, $STATUS)
  Common Response Fields
You get array with dataset:
[id] => transaction id (into the store)
[success] => has a value of 1 if the payment is made successfully
[OutSum] => transaction sum
[time] => transaction time: (example: time())
[fail] => error number


PROCESSING
After success payment take appropriate action, in writing, updating a transaction table in the database.

XML configuration file structure

Структура XML
Website design order
Unique offer for customers of Perfecto CMS.
If you want an original design let us know and we will contact you to discuss the details.
Please note
We appreciate your time and for save time, please download the blank of design order, complete it and send to our mailbox: Our email
Approximate price
600 USD

Your browser is out of date!

Please download the latest version of Internet Explorer
We recommend to use another modern browser!