User Tools

Site Tools


how_to_create_a_payment_module

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
how_to_create_a_payment_module [2020/01/31 02:35]
admin [Callbacks]
how_to_create_a_payment_module [2020/09/24 23:57] (current)
tim [Return URLs]
Line 6: Line 6:
  
 <code php /includes/modules/payment/pm_mymodule.inc.php> <code php /includes/modules/payment/pm_mymodule.inc.php>
-class pm_module {+class pm_mymodule {
   public $id = __CLASS__;   public $id = __CLASS__;
-  public $name = 'My Vendor Module';+  public $name = 'My Module';
   public $description = 'Lorem ipsum dolor';   public $description = 'Lorem ipsum dolor';
   public $author = 'ACME Corp.';   public $author = 'ACME Corp.';
Line 21: Line 21:
         array(         array(
           'id' => 'method1',           'id' => 'method1',
-          'icon' => $this->settings['icon'],+          'icon' => 'images/payment/mymodule-method1.png',
           'name' => 'Method 1',           'name' => 'Method 1',
           'description' => 'Select this option for method 1.',           'description' => 'Select this option for method 1.',
Line 59: Line 59:
       array(       array(
         'key' => 'icon',         'key' => 'icon',
-        'default_value' => 'images/payment/vendor.png',+        'default_value' => 'images/payment/'.__CLASS__.'.png',
         'title' => 'Icon',         'title' => 'Icon',
         'description' => 'Web path of the icon to be displayed.',         'description' => 'Web path of the icon to be displayed.',
Line 172: Line 172:
       'action' => 'http://www.paymentgateway.com/form_process.ext',       'action' => 'http://www.paymentgateway.com/form_process.ext',
       'fields' => array(       'fields' => array(
-        'foo' => 'bar', +                    'foo' => 'bar', 
-        'this' => 'that', +                    'this' => 'that', 
-      ),+                  ),
     );     );
   }   }
Line 301: Line 301:
     try {     try {
          
-      //$order->save(); // Save session order to database before transaction creates an $order->data['id']. Not recommended+      //$order->save(); // Save session order to database before transaction creates an $order->data['id']
          
       $fields = array(       $fields = array(
Line 351: Line 351:
     return array(     return array(
       'order_status_id' => $this->settings['order_status_id'],       'order_status_id' => $this->settings['order_status_id'],
-      'payment_transaction_id' => '123456789',+      'transaction_id' => '123456789',
       'comments' => 'This is an order comment',       'comments' => 'This is an order comment',
     );     );
Line 367: Line 367:
 ===== settings() ===== ===== settings() =====
  
-This method sets up the payment module with a settings structure. The return is an array of the structure.  The functions supported are listed in func_form.inc.php form_draw_function().+This method sets up the payment module with a settings structure. The return is an array of the structure.
  
 <code php> <code php>
Line 435: Line 435:
 ===== Callbacks ===== ===== Callbacks =====
  
-Some payment service providers offers machine-to-machine data exchange during the transaction. In such cases you might need a listener for callbacks. Here is an example of an external script that will call a method inside the module called callback().+Some payment service providers offers machine-to-machine data exchange during the transaction takes part. In such cases you will need a callback function. Here is an example of an external script that will call a method inside the module called callback().
  
 <code php /ext/provider/callback.php> <code php /ext/provider/callback.php>
 <?php <?php
 +  require_once('../../includes/app_header.inc.php');
  
   try {   try {
-    define('REQUIRE_POST_TOKEN', false); // Allow unsigned external incoming POST data +
-    require_once('../../includes/app_header.inc.php'); +
-    +
   // Make sure callback comes from a trusted IP address   // Make sure callback comes from a trusted IP address
     if (!in_array($_SERVER['REMOTE_ADDR'], array('123.456.789.0', '123.456.789.1', '123.456.789.2'))) {     if (!in_array($_SERVER['REMOTE_ADDR'], array('123.456.789.0', '123.456.789.1', '123.456.789.2'))) {
-      error_log('Unauthorized access by '. $_SERVER['REMOTE_ADDR'] .' to file '. __FILE__); 
       throw new Exception('Access Denied', 403);       throw new Exception('Access Denied', 403);
     }     }
-    +
   // Make sure we have a ID   // Make sure we have a ID
     if (empty($_GET['order_id'])) {     if (empty($_GET['order_id'])) {
Line 455: Line 453:
     }     }
  
-  // Get Order From Database (In this example using ID) +  // Get order from the database (In this example using ID)
-  // To be able to find the order in the database, the order must previously have been saved.+
     $orders_query = database::query(     $orders_query = database::query(
       "select id from ". DB_TABLE_ORDERS ."       "select id from ". DB_TABLE_ORDERS ."
Line 462: Line 459:
       limit 1;"       limit 1;"
     );     );
-    +
     if (!$order = database::fetch($orders_query)) {     if (!$order = database::fetch($orders_query)) {
       throw new Exception('File Not Found', 404);       throw new Exception('File Not Found', 404);
     }     }
-    +
   // Initiate $order as the order object   // Initiate $order as the order object
     //$order = new ctrl_order('load', $order['id']); // LiteCart 1.0     //$order = new ctrl_order('load', $order['id']); // LiteCart 1.0
Line 482: Line 479:
     // Define the funtion by: public function callback($order) {}     // Define the funtion by: public function callback($order) {}
  
-  } catch (Exception $e) {+  } catch(Exception $e) {
     http_response_code($e->getCode());     http_response_code($e->getCode());
-    die($e->getMessage());+    die($e->getMessage);
   }   }
- 
 </code> </code>
  
 We suggest storing the transaction details in the callback and verify them later in the method verify(). We suggest storing the transaction details in the callback and verify them later in the method verify().
how_to_create_a_payment_module.1580434520.txt.gz · Last modified: 2020/01/31 02:35 by admin