Adding a new payment gateway
Notes
-
We assume that you are using JoomBri Freelance v2.1 Stable & above.
-
The below document is explained for the gateway Hello.
Download
Download the skeleton or the prototype of the Hello payment gateway to quickly get started.
Files Structure
-
files_hello
-
forms
-
hello.xml
-
-
images
-
hello.png
-
-
language
-
en-GB
-
en-GB.files_hello.sys
-
-
-
class.hello.php
-
index.html
-
install.sql
-
script.php
-
The explanation of the above file structures is given below.
1: forms → hello.xml
Create an XML file which stores the settings specific for each payment gateway like account ID, merchant ID, etc. The name of the file should be [gatewaycode].xml (for example, paypal.xml). The gateway code is assumed in Step 1. A sample XML file is given below.
<?xml version="1.0" encoding="UTF-8"?>
<form>
<fieldset name="settings">
<field type="text" name="publisherKey" label="Publisher Key" description="You can get the key from Dashboard -> Account -> API Keys" default="" class="required input-large" />
<field type="text" name="secretKey" label="Secret Key" description="You can get the key from Dashboard -> Account -> API Keys" default="" class="required input-large" />
<field type="text" name="currencyCode" default="USD" label="Currency" description="Currency supported by Stripe" class="required input-mini" />
</fieldset>
</form>
2: images → hello.png
3: language → en-GB → en-GB.files_hello.sys
A sample of language file is given below.
; JoomBri Freelance
; Copyright (C) 2012 - 2020 BriTech Solutions. All rights reserved.
; License GNU General Public License version 2 or later
; Note : All ini files need to be saved as UTF-8 - No BOM
FILES_HELLO="JoomBri - Hello Payment"
FILES_HELLO_DESC="Hello payment gateway integration with JoomBri Freelance."
4: class.hello.php
This step is very important which creates the payment form, process the payment, etc. Create a PHP file in the name class.[gatewaycode].php (for example, class.paypal.php).
Explanation of PHP File
The explanation of the file is given above each function name. You need appropriate integration guide of payment gateway to find how the payment form is submitted and payment is validated.
<?php
/**
* @company : BriTech Solutions
* @created by : JoomBri Team
* @contact : www.joombri.in, This email address is being protected from spambots. You need JavaScript enabled to view it.
* @created on : 24 May 2020
* @file name : gateways/class.hello.php
* @copyright : Copyright (C) 2012 - 2016 BriTech Solutions. All rights reserved.
* @license : GNU General Public License version 2 or later
* @author : JoomBri Support
* @description : Payment processing gateway for Hello (jblance)
*/
defined('_JEXEC') or die('Restricted access');
class hello_class {
var $fields = array();
var $payconfig = array();
var $details = array();
/**
* Constructor function which initiates certain variable.
*/
function hello_class($payconfig, $details){
$this->payconfig = $payconfig;
$this->details = $details;
}
/**
* This function is called before making the payment.
* It creates the payment form which is submitted to the payment gateway.
*
* Note: Submission of payment form will vary from one gateway to other.
*/
function helloPayment(){
// The following variables will vary depending on the variable used in hello.xml.
$payconfig = $this->payconfig;
$publisherKey = $payconfig->publisherKey;
$secretKey = $payconfig->secretKey;
$currencyCode = $payconfig->currencyCode;
$details = $this->details;
$amount = $details['amount'];
$taxrate = $details['taxrate'];
$orderid = $details['orderid'];
$itemname = $details['itemname'];
$item_num = $details['item_num'];
$invoiceNo = $details['invoiceNo'];
$link_status = JURI::base().'index.php?option=com_jblance&task=membership.returnafterpayment&gateway=hello';
$link_cancel = JRoute::_(JURI::base().'index.php?option=com_jblance&view=membership&layout=thankpayment&type=cancel');
//CREATE THE PAYMENT FORM FOLLOWING THE INTEGRATION DOCUMENT SPECIFIC TO THE GATEWAY
$this->submit_hello_post(); // auto submit the fields to hello
?>
<script>
document.hello_form.submit();
</script>
<?php
}
/**
* This function is called after the payment from the gateway.
* It return true and invoice number if the payment is successful
*/
function helloReturn($data){
$return = array();
if($this->validate_ipn($data)){
// get the invoice number from the POST variable. Getting the invoice will be different for gateways.
$invoice_num = array_key_exists('invoice', $data) ? $data['invoice'] : '';
$return['success'] = true;
$return['invoice_num'] = $invoice_num;
}
else
$return['success'] = false;
return $return;
}
/**
* This function validates the payment.
* It returns true if the payment verification is successful
* Otherwise, returns false
*/
function validate_ipn($data){
// validate the payment here
}
}
?>
5: hello.xml
<?xml version="1.0" encoding="utf-8"?>
<extension version="3.9" type="file" method="upgrade">
<name>files_hello</name>
<creationDate>24 May 2020</creationDate>
<author>JoomBri Team</author>
<copyright>Copyright (C) 2012 - 2020 BriTech Solutions. All rights reserved.</copyright>
<license>http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL</license>
<authorEmail>This email address is being protected from spambots. You need JavaScript enabled to view it. </authorEmail>
<authorUrl>www.joombri.in</authorUrl>
<version>1.0</version>
<description>FILES_HELLO_DESC</description>
<scriptfile>script.php</scriptfile>
<install>
<sql>
<file driver="mysql" charset="utf8">install.sql</file>
</sql>
</install>
<fileset>
<files target="components/com_jblance/gateways">
<filename>class.hello.php</filename>
</files>
<files folder="forms" target="components/com_jblance/gateways/forms">
<filename>hello.xml</filename>
</files>
<files folder="images" target="components/com_jblance/gateways/images">
<filename>hello.png</filename>
</files>
<files target="administrator/manifests/files/hello">
<filename>index.html</filename>
<filename>install.sql</filename>
</files>
</fileset>
<languages>
<language tag="en-GB">language/en-GB/en-GB.files_hello.sys.ini</language>
</languages>
</extension>
6: install.sql
Replace the following SQL script with the payment gateway you want to integrate.
INSERT INTO `#__jblance_paymode` (gateway_name, published, ordering, shortcode, gwcode, is_withdraw, withdrawFeeFixed, withdrawDesc, depositfeeFixed, depositfeePerc, params, withdrawFeePerc, is_subscription, is_deposit) VALUES ('Hello', TRUE, 5, 'HLO', 'hello', FALSE, 0.0, 'Withdraw funds to your Hello account.', 0.3, 2.9, '{}', 0.0, TRUE, TRUE);
7: script.php
This file is reserved for the future user and it can be empty.