Installation


Upgrades


DTC-Xen Installation


DTC-Xen / Dom0 Howtos

DTC-Xen / DomU Howtos

FAQ


DTC Howtos


Manuals


Features


Roadmap


Devel docs


Wiki - i18n


Wiki - Meta


Payment Gateway

This method described is the way to add a module in current dtc (stable and git), but I am designing another way to make payment modules with a form to make them easy and much more flexible, in an automated way, letting you personalize the module and adding multiple modules with parameters in the fly. This new module structure will be in git version. Now I am in design stage of this structure.

Explanation of current method of making modules:

1. files needed to make a new payment module

To make a new payment gateway plugin you have to create a folder with the name of the module in shared/securepay/modules/ and insitde that folder you have to create a file called main.php

   shared/securepay/modules/newmodulename/main.php

Then you have to edit this files:

   admin/dtc_db.php
   admin/inc/dtc_config.php
   shared/securepay/pay_functions.php
   Makefile

2. Database structure

After the design of your module you need to know which parameters should your module store in database. All the payment parameters are stored in a row in secpayconf table, the table has one field per parameter and is also a field to set if the module is enabled or not. For example the parameter to manage in this module could be fixed vat rate, percentaje vat rate and the user id of the payment site. In this example we will create a module with this 3 parameters, so we should edit the file admin/dtc_db.php adding a field to set if this module is enabled or disabled and the 3 fields mentioned above so when you install or upgrade dtc, it creates the table with this 4 fields added.

In this example we should edit the array corresponding to secpayconf table and add this fields:

   "use_newmodulename" => "enum('yes','no') NOT NULL default 'no'",
   "newmodulename_account" => "varchar(20) NOT NULL default ''",
   "newmodulename_fixedrate" => "float(6,2) NOT NULL default '0.00'",
   "newmodulename_percentrate" => "float(6,2) NOT NULL default '0.00"'

3. admin/inc/dtc_config.php

In this file you have a function called drawDTCpayConfig() that shows all the payment methods to display all the fields. You should add the configurations to your new payment module like this:

       $dsc = array(
               "title" => _("newmodulename:"),
               "action" => "newmodulename_gateway_newmodulename_edit",
               "forward" => array("rub","sousrub"),
               "cols" => array(
                       "use_newmodulename" => array(
                               "legend" => _("Use dineromail: "),
                               "type" => "radio",
                               "values" => array("yes","no"),
                               "display_replace" => array(_("Yes"),_("No"))),
                       "newmodulename_account" => array(
                               "legend" => _("Dineromail Account: "),
                               "type" => "text",
                               "size" => "20"),
                       "newmodulename_fixedrate" => array(
                               "legend" => _("Fixed charge fee: "),
                               "type" => "text",
                               "size" => "6"),
                       "newmodulename_percentrate" => array(
                               "legend" => _("Percentage fee: "),
                               "type" => "text",
                               "size" => "6"), ));
       $out .= configEditorTemplate ($dsc,"secpay");

4. shared/securepay/modules/modulename/main.php

The file main.php should have 3 sections:

  • A function to calculate the fee of the module
   function modulename_calculate_fee($amount){
  • A function to show the payment form
   dineromail_display_icon($product_id,$amount,$item_name,$return_url,$use_recurring = "no"){
  • and an array that specifies the name of the two functions mentioned

above and the account type.

In the fee function you have to call the configuration variables with global, then make the cafee calculation.

    // Should return a decimal with added gateway fees.
    function newmodulename_calculate_fee($amount){
         global $secpayconf_newmodulename_fixedrate;
         global $secpayconf_newmodulename_percentrate;
         $total = $amount + ($amount *
         $secpayconf_newmodulename_percentrate / 100) +
         $secpayconf_newmodulename_fixedrate;
         return $total;
    }

In the function to show the payment form you should make the form like this:

    // Display the payment link option
    function dineromail_display_icon($product_id,$amount,$item_name,$return_url,$use_recurring = "no"){
           global $secpayconf_newmodulename_account;
           $out = '<form action="http://paymentsite.com(approve sites)" method="post">';
           $out .= '<input type="hidden" name="ammount" value="'.$amount.'">';
           $out .= '<input type="hidden" name="account" value="'.$secpayconf_newmodulename_account.'">';
           $out .= '<input type="hidden" name="productid" value="'.$product_id.'">';
           $out .= '<input type="image" src="http://paymentsite/button.gif(approve sites)0" name="submit" alt="Pay">';
           $out .= '</form>';
           return $out;
   }

The last section has the name of the functions mentioned above and the payment type

    $secpay_modules[] = array(
           "display_icon" => "newmodulename_display_icon",
           "use_module" => $secpayconf_use_newmodulename,
           "calculate_fee" => "newmodulename_calculate_fee",
           "instant_account" => _("Yes")
    );

If instant_account is set to yes, the payment is automatically validated.

5. shared/securepay/pay_functions.php

In this file you have to put a global call to the module variable enable in function paynowButton function:

    function paynowButton($pay_id,$amount,$item_name,$return_url,$vat_rate=0,$use_recurring= "no"){
         .....
         global $secpayconf_use_enets;
         .....

6. Makefile

You should include the file main.php (adding the text shared/securepay/modules/newmodulename/main.php) in the PAYMENT_API_PHP_SCRIPT_FILES variable and you should ad the module folder creation (adding the text shared/securepay/modules/newmodulename) in the variable CREATE_DIRS

Page last modified on July 15, 2010, at 01:54 PM EST