As we are aware that with Tevolution plugin it is quite easy to accept online payments with the help of payment methods. By default, Tevolution provides you 2 payment methods “Paypal” and “Pre Bank Transfer” to accept online payments but if you want to custom code your own payment method  then here is the guideline for it,

you may also consider our 10 payment extensions to meet your payment requirement

To understand the steps better, let’s take an example of creating a new payment gateway say Stripe.

1) Create a folder for new payment gateway plugin Tevolution-stripe. (To use Tevolution as prefix with your plugin name is mandatory)

2) After creating folder create a plugin file for your plugin. ( Refer how to create plugin file)

3) Create necessary “includes” folder within plugin folder.

4) Now create necessary files in includes folder. The necessary files are:

  • install.php
  • PaymentGatewayName.php ( Here stripe.php )
  • PaymentGatewayName_response.php ( Here stripe_response.php )
  • PaymentGatewayName_success.php ( Here stripe_success.php ) [ We will discuss later about this files.  ]

5) Next, You have to create an array and save it into option table with “payment_method_stripe” name in option_name field.
( Here ‘payment_method_’ is common name and stripe is your payment gateway name.) array will help us create required form for payment gateway options at the back-end. To do so, create a function and call it on plugin activation hook and create an array to save required options in database. Here is an example,

To make stripe plugin working it required us these 5 options.

  • Mode of payment gateway Live/Sandbox
  • Live Secrete Key
  • Live Publishable Key
  • Test Secret Key
  • Test Publishable key.

Create an array like this,

<?php
$stripe_opts = array();
$stripe_opts [] = array(
"title"            =>  "Use Stripe in test mode?",
"fieldname"     =>  "stripe_mode",
"type"         =>   'checkbox',
"value"                     =>      "1",
"description"   =>  __('Check this if you want to use stripe in test mode.')      );

$stripe_opts [] = array(
“title”                       =>       “Live secret key”,
“fieldname”     =>              “live_secrete_key”,
“type”        =>  ‘text’,
“value”      =>       ”,
“description”   =>              __(‘Your Stripe live secret key’)
);

$stripe_opts [] = array(
“title”       =>       “Live publishable key”,
“fieldname”            =>       “live_publishable_key”,
“type”        =>  ‘text’,
“value”      =>       “”,
“description”   =>              __(‘Your Stripe live publishable key’),
);

$stripe_opts [] = array(
“title”                       =>       “Test secret key”,
“fieldname”            =>       “test_secrete_key”,
“type”        =>  ‘text’,
“value”      =>       “”,
“description”   =>              __(‘Your Stripe test secret key’)
);

$stripe_opts [] = array(
“title”                       =>       “Test publishable key”,
“fieldname”            =>       “test_publishable_key”,
“type”        =>  ‘text’,
“value”      =>       “”,
“description”   =>              __(‘Your Stripe test publishable key’),
);
?>

Note.: An array key must be same as describe in above array.

Here are the key and array described below:

  • title – The title of your field in back-end from.
  • fieldname  – The unique html field name that will be used when you submit form in backend.
  • type –  The type of the html element. If you left this field blank then text type is considered by default. Here we only support  text, checkbox, and radio for type field.
  • value –  The default value of your field.
  • description – The description of the field that will display beneath your new field.

6) After creating array for our new payment gateway, now we have to create a main array that will save above created array options with it.

For Example,

<?php
$stripe_method_info = array(
“name”                         =>  ‘stripe’,
“key”                             =>  “stripe”,
“isactive”                      =>  1,
“display_order”   =>  4,
“payOpts”                     =>  $stripe_opts,
);

update_option( “payment_method_stripe”, $stripe_method_info );
?>

 

Note: Herein array, array key must be same as describe in above array.

Here are the code described as below:

  • name  –  Title of your payment gateway to display at the front end
  • key –  The unique name of your payment gateway plugin.
  • isactive  –  Default status of plugin, activate/deactivate option. ( 1 = Active, 0 = Inactive )
  • display_order  – the sort order payment gateway should be displayed in both front end and back end
  • payOpts  –  Write our new payment gateway option’s array. ( The array that we created very first. )

Now, update an array into option table with payment_method_stripe option name.

7) Create a function and call it on plugin deactivation hook to delete our plugin data when we deactivate our newly created payment gateway.

To delete the payment gateway options from database we have to write following code on plugin deactivation hook as shown in below example,

<?php
delete_option(‘payment_method_stripe’);
?>

 

Note: Here “payment_method_” is static tevolution defined name and “stripe” is dynamic created payment gateway name.

Detailed information on each required files

1) install.php

  • It is required to activate/deactivate our newly created payment gateway from front end payment options (instead of activating/deactive the whole plugin)
  • This activation link will be visible at the back-end in Tevolution’s Payment Gateways list under “Manage Payment Options” section at Tevolution -> Monetization -> Payment Gateways.
  • To activate this functionality create this file and put the same code in it as we created for plugin activation and deactivation hook function with the required condition.

For Example

<?php
$paymentmethodname = ‘stripe’;
if(strtolower($_REQUEST[‘install’])== strtolower($paymentmethodname)){
/* Same code as we created for plugin activation and deactivation hook function goes here*/
} elseif($_REQUEST[‘uninstall’]==$paymentmethodname){
/* Same code as we created for plugin activation and deactivation hook function goes here*/
}
?>

 

Note: $_REQUEST[‘install’] and $_REQUEST[‘uninstall’]  automatically get the value of our payment gateway’s unique name. ( Here it is for stripe)

2) PaymentGatewayName.php ( Here it’s stripe.php )

This file is necessary for displaying our payment gateway’s form on front end. The common structure in this file is:

<table id=”stripeoptions” style=”display:none”>
/*
Your html input elements and other codes goes here.
Note.: Don’t create <from> tag within this code. It’s already created in Tevolution plugin’s core files.
*/
</table>

Note: Here your table’s Id attribute must be XYZoptions  ( Here stripeoptions ) and it must be display none.

3) PaymentGatewayName_response.php  ( Here it’s stripe_response.php )

It contains all of your own payment gateway plugin’s functionality code. At the success redirection point we have to write some small bit of code to help Tevolution to perform its core functionality.

Note:  You can use some of Tevolution’s global variables in this file like,

  • $payable_amount  =  Total amount of submitted post.
  • $last_postid  =  Post id of submitted post.
  • $monetization =  The bunch of array for price package information.

For example,

<?php
global $last_postid;
$params = array(‘page’ => ‘stripe_success’, ‘paydeltype’ => ‘stripe’, ‘pid’ => $last_postid);
$redirect = add_query_arg($params);
wp_redirect($redirect);
?>

 

In above array page, paydeltype, pid is common and required to get our success page works as it should.

  •  page  = dynamic parameter that will need to call our success page. ( Here it’s “stripe_success” )
  • paydeltype  = our payment gateway name for internal use for Tevolution.( Here it’s “stripe”. )
  • pid = post id of submitted post. ( Here  it’s “$last_postid”. You will get last submitted post id with global variable.  )

A) For error redirection point need to write some code to help Tevolution to perform its core functionality.

For example,


<?php
$failureMessage = “Error Occurred.”;
$_SESSION['stripe_errors'] = $failureMessage;
$params = array('page' => 'preview', 'stripeerror' => 'yes', 'cur_post_type' => $_SESSION['custom_fields']['cur_post_type'] );
$redirect = add_query_arg($params);
wp_redirect($redirect);
?>

Meanings of things used,

  • page  = Parameter must be preview to get back to preview page.
  • stripeerror = Dynamic parameter to display our custom error message on preview page.( Here “yes”. )
  • ‘cur_post_type’  = This must be $_SESSION[‘custom_fields’][‘cur_post_type’] ( Current post type used for post submission ).

B) To display your plugin’s error message on preview page, you have to write some code in Tevolution\tmplconnector\monetize\templatic-custom_fields\submit_preview_buttons.php file.
For example,


<?php
if(isset($_REQUEST['stripeerror']) && $_REQUEST['stripeerror']=='yes'){
echo $_SESSION['stripe_errors'];
}
?>

 

4) PaymentGatewayName_success.php  ( Here it’s stripe_success.php )

It is only required if you want to display your custom success page instead of Tevolution’s or you want do something with your payment gateway’s callback actions or want to send other mails after payment success.
You have to keep the html structure same as Tevolution’s success page.

Note:  You can use some of Tevolution’s global variables in this file like,

  • $payable_amount = Total amount of submitted post.
  • $last_postid = Post id of submitted post.
  • $monetization = The bunch of array for price package information.

After creating this file, you have to add bit of code in the Tevolution\tmplconnector\monetize\templatic-custom_fields\install.php file at around line number 180 to call this file on success page.

For example,


<?php
if(isset($_REQUEST['page']) && $_REQUEST['page'] == "stripe_success")    {
include(ABSPATH . 'wp-content/plugins/Tevolution-stripe/includes/stripe_success.php');
exit;
}
?>

Here the argument stripe_success is that we defined in stripe_response.php file.

Any Queries? Contact us and we’ll help you out.