1.1.1 How to add a custom payment gateway

Discussion in 'Commonly Asked Questions and Their Solutions' started by renlok, Feb 17, 2014.

  1. renlok

    renlok Administrator Staff Member

    Joined:
    Oct 20, 2008
    Messages:
    2,858
    Likes Received:
    330
    WARNING: Doing this requires a reasonable amount of programming knowledge and an understanding about how the particular payment gateways API works

    Throughout these instructions I am going to refer to an imaginary payment gateway mypaymentgateway, when doing it yourself change mypaymentgateway to the name of the gateway

    SQL:
    - Add payment gateway username or email as a column in the webid_users table and add the gateway to the webid_gateways table

    Step 1:
    Open includes/class_fees.php and add a function to the fees class called mypaymentgateway_validate this is how webid validates the payment, this will be different for every gateway so just look at their API documentation (look at the existing functions for help as to how we have done it)

    Step 2:
    Open validate.php and add
    PHP:
    if (isset($_GET['mypaymentgateway']))
    {
        
    $fees->mypaymentgateway_validate();
    }
    before ?>

    Step 3:
    Open pay.php a few things you need to add in here
    First add
    PHP:
    $mpg_paytoemail $gateway_data['mypaymentgateway_address'];
    after all 6 cases of
    PHP:
    $mb_paytoemail $gateway_data['moneybookers_address'];
    then you need to pull the user data about the gateway from the query found after
    PHP:
    case 2// pay for an item
    add
    PHP:
    $mpg_paytoemail = (in_array('mypaymentgateway'$payment)) ? $data['mypaymentgateway_email'] : '';
    after
    PHP:
    $mb_paytoemail = (in_array('moneybookers'$payment)) ? $data['moneybookers_email'] : '';
    add
    PHP:
    'B_ENMYPAYMENTGATEWAY' => ($gateway_data['mypaymentgateway_active'] == && !empty($mpg_paytoemail)),
    after
    PHP:
    'B_ENMONEYBOOKERS' => ($gateway_data['moneybookers_active'] == && !empty($mb_paytoemail)),
    add
    PHP:
    'MPG_PAYTOEMAIL' => $mpg_paytoemail,
    after
    PHP:
    'MB_PAYTOEMAIL' => $mb_paytoemail,
    Note: If you didn't notice about the variables mpg is just the initials of the payment gateway (i.e. pp = paypal)

    Step 4:
    Open includes/functions_sell.php
    add
    PHP:
    if ($gateway == 'mypaymentgateway' && !empty($user->user_data['mypaymentgateway_email']))
            return 
    true;
    after
    PHP:
    if ($gateway == 'moneybookers' && !empty($user->user_data['moneybookers_email']))
            return 
    true;
    Step 5:
    Open includes/functions_global.php
    Add
    PHP:
    'mypaymentgateway' => 'My Payment Gateway',
    after
    PHP:
    'moneybookers' => 'Moneybookers',
    Then you need to edit the following edit:
    pay.tpl <-- add references to the new gateway
    edit_data.tpl & edit_data.php <-- so users can add their payment details for this new gateway
    register.tpl & register.php <-- so users can add their payment details for this new gateway


    I wrote this pretty quickly so might be missing something PM if something amiss
     
    Alo likes this.

Share This Page