Payment Gateway API

From Dukapress 3.0, we allow you to create your own custom Payment Gateways.  You can integrate many types of Payment Gateways that redirect to an external page or load content in the current page.

Creating a basic Payment Gateway

You can download a sample gateway here

Payment gateways should be created as additional plugins that hook into DukaPress. Inside the plugin, you need to create a class after the payment gateways are loaded. Example:

add_action('dukapress_load_gateway_plugins','init_your_gateway_class');

Your gateway class should extend the DukaPress_Gateway class that should be in the dukapress\classes\ directory.

 

Required Methods

Most Methods are inherited from DukaPress_Gateway class but some need to be implemented in your custom gateway

on_create()

This function is used to instantiate your custom gateway with methods or functions to be called. The function is called within the __construct() method in the parent class. With this constructor, you should be able to define:

  • $this->plugin_name – Unique name of the plugin that will be visible to the admin side
  • $this->plugin_slug – Unique plugin identifier. Should be in lowercase and only separated by an underscore. E.g (my_custom_plugin);
  • $this->form_submit – Boolean value. Set to false the output form will not be submitted but instead the content will be displayed. Is set to true, the output form is submitted and the form action triggered. Useful when redirecting users to an external gateway

To access gateway options, use the global variable $dukapress . For example, to get a setting in our custom gateway, we may call $dukapress->get_setting('gateways->mygateway->username')

 

set_up_options($settings)

This function is used to create your Gateway Settings Page in the Admin section. The parameter $settings contains an array of your plugins settings. For example, the setting gotten via the function $dukapress->get_setting('gateways->mygateway->username')  is now gotten like $settings['gateways']['mygateway']['username'].  For Example:

function set_up_options($settings){

?>
<h3 class=’hndle’><span><?php _e(‘My Settings’,’dp-lang’); ?></span></h3>
<table class=”form-table”>
<tr>
<th scope=”row”><?php _e(‘Public Name’,’dp-lang’); ?></th>
<td>
<input value=”<?php echo $settings[‘gateways’][‘mygateway’][‘public’]; ?>” name=”dpsc[gateways][mygateway][public]” type=”text” />
</td>
</tr>
<tr>
<th scope=”row”><?php _e(‘Custom Message’,’dp-lang’) ?></th>
<td>
<textarea name=”dpsc[gateways][mygateway][message]” cols=”30″ rows=”5″><?php echo @$settings[‘gateways’][‘mygateway’][‘message’]; ?></textarea>
</td>
</tr>

</table>

<?php

}

 

process_payment_form($cart, $user_info, $shipping, $order_id,$total_shipping, $total_discount, $total_tax,$dpsc_total, $return_path)

 

This function is used after the payment form is submitted. Parameters are:

  • $cart – an array of the cart
  • $user_info – an array of the user info
  • $shipping_info – an array of the shipping info
  • $order_id – the unique invoice id
  • $total_shipping – total shipping cost
  • $total_discount – total discount cost
  • $total_tax – total tax
  • $dpsc_total – total amount
  • $return_path – return url from gateway

 

At the end of the function, the parent gateway method $this->send_gateway_output($output) is called to finalize the transaction. More on the functions can be seen in the demo gatway

 

update_payment($request)

This is used in the return url to update the payment status

 

process_ipn_return()

This is used for any IPN messages. The IPN url is in the format

SITEURL/payment-return/GATEWAYSLUG

 

© 2024 DukaPress. All rights reserved.
Design By Madoido.