After researching and implementing a new payment gateway for your site, this tutorial will help you show the new payment gateway on your site along with existing gateways like: Paypal and 2Checkout.

In order to integrate new gateway, you must follow these steps:

  1. Render payment button
  2. Setup payment
  3. Process payment

The first step is rendering payment button for a new payment gateway. In this tutorial, we name the button “custom-payment”

To render payment button in your theme, you may add a filter in functions.php to your child theme. In case you haven’t known how to activate child theme, check out here: http://support.enginethemes.com/customer/portal/articles/897324-how-to-get-and-use-child-theme-to-customize-your-site

add_action('after_payment_list', 'ae_stripe_render_button');
function ae_stripe_render_button() {
?>
<li>
<span class="title-plan stripe-payment" data-type="stripe">
<?php
_e("Custom payment", ET_DOMAIN); ?>
<span><?php
_e("Send your payment to our custom payment", ET_DOMAIN); ?></span>
</span>
<a href="#" class="btn btn-submit-price-plan select-payment" data-type="custom-payment"><?php
_e("Select", ET_DOMAIN); ?></a>
</li>
<?php
}

Noted: “data-type” is the name of payment gateway

When users select a payment gateway, an Ajax request includes payment gateway name and billing details will be sent to server. Data sent to server is:

// post id
 ID: this.model.id,
 // author
 author: this.model.get('post_author'),
 // package sku id
 packageID: this.model.get('et_payment_package'),
 // payment gateway 
 paymentType: paymentType,
 // send coupon code if exist
 coupon_code: view.$('#coupon_code').val()
 },

Then, server will catch the Ajax request and process it. Ajax callback locates at includes/aecore/payments.php line 166, in function setup_payment.

To integrate new payment gateway, you need to use filter ae_setup_payment. This filter need to return a response:

//Success: true/false
//Data: include received data and the most important is URL 
//(URL will direct user to payment page, it should contain your custom payment required parameter such as: return url, price, item ... )
//Payment type: name of payment gateway

add_filter('ae_setup_payment', 'ae_custom_setup_payment', 10, 3);
function ae_custom_setup_payment($response, $paymentType, $order) {
if( $paymentType == 'custom-payment') { 
// your payment setup code
}
return $response;
}

The response will be send back to user client and process user to payment gateway.

Note: The transaction is executed at template page-process-payment.php, you can get the URL of the page with function et_get_page_link(‘process-payment’, array(‘paymentType’ => ‘custom-payment’)); . You should setup the return url parameter for your custom gateway is process payment page url.

After the transaction is successful, the page is going to be re-directed to a process payment page. Here you can use hook ae_process_payment to analyze received data.

add_filter( 'ae_process_payment', 'ae_stripe_process_payment', 10 ,2 );
 function ae_stripe_process_payment ( $payment_return, $data) {
 $payment_type = $data['payment_type'];
 $order = $data['order'];
 if( $payment_type == 'custom-payment') {
 // your payment process code
 }
 return $payment_return;
 }

$payment_return is an array including parameters:

ACK: true/false
 Payment_status: pending/completed
 Payment: ‘custom-payment"
10 Comments
  • José Alexandre Alex
    Jan  14TH,  2015

    Can you please do a video tutorial of that, for a better understanding how to execute that. Thanks!

    • An
      Jan  28TH,  2015

      Hi,

      Thanks for your suggestion. We’ll consider adding some video for these tutorials.

      In the meantime, if there are something you don’t understand, please feel free to ask us.

      Regards,

      • Africa Solutions
        Jan  29TH,  2015

        can you please put the file modifed here because many thing i have not understand where to put them.
        exemple if i have a url for payment where to put it ?

        • nhunq
          Jan  30TH,  2015

          Hi,

          Thanks for your feedback!

          Our tutorial instructs you the way to show your new payment in your site only so you have to research how to develop by its API carefully.

          We have listed the exact files where you should change if we don’t provide the filter. With all filters, you can add them on functions.php of child theme, it is very convenient to update new version later.

          Hope this helps.

          • Africa Solutions
            Jan  30TH,  2015

            say me please all code need be putted in fonction.php of child theme ?

          • nhunq
            Feb  02ND,  2015

            With all filters, you can put them on functions.php of child theme.

            With other codes, you should put them on the exact files as our instruction.

            E.g: includes/aecore/payments.php.

            Please check our instruction carefully!

            Also, we have provided the Ticket System on ET Forums (https://www.enginethemes.com/forums/), it is very convenient to contact our support staffs as well.

            Thanks for using our product!

  • Sadiq Okocha
    May  17TH,  2016

    These instructions are not very clear.

    I’ve added the filter in my child theme’s function.php.

    Then you say, “To integrate new payment gateway, you need to use filter ae_setup_payment. This filter need to return a response:”

    Where am I supposed to use the filter: ae_setup_payment ?

    • Uyen Tran
      May  18TH,  2016

      Hello Sadiq,

      Thanks for posting in.
      Regarding this issue, would you mind moving to our forum and submit a ticket?
      forum.enginethemes.com
      We know that it’ll be a little bit inconvenient but our technical supporters work mainly on the forum. Moreover, the ticket system also keeps your private information safe and you will be reached within 24 hours or a bit late at weekends.

      All the best,

  • bardia
    Jun  23RD,  2016

    thank you for your time
    i have a question,
    i got a custom gateway plugin,
    to use it i should just use this shortcode ]wp_cart:PRODUCT-NAME:price:PRODUCT-PRICE:end[
    now, my freelanceengine theme uses what variables to carry this information? like product-price
    is there anything written in plugin like $price or how can i write this?

  • Chau
    Jun  23RD,  2016

    Hello bardia,

    Regarding this, please go to http://forum.enginethemes.com/ to post about the problem you’ve encountered. Our TS will be glad to assist you as much as they can.

    Many thanks.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.