2025-03-30 13:02:22 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2025-03-30 13:44:44 +02:00
|
|
|
* Dolibarr Module Descriptor for Dolipesa - M-Pesa Payment Module
|
2025-03-30 13:02:22 +02:00
|
|
|
* Author: NESTICT INFOTECH
|
2025-03-30 13:44:44 +02:00
|
|
|
* Version: 1.0.1
|
|
|
|
* License: GNU General Public License v3.0
|
2025-03-30 13:02:22 +02:00
|
|
|
*/
|
2025-03-30 13:06:09 +02:00
|
|
|
|
2025-03-30 13:44:44 +02:00
|
|
|
include_once DOL_DOCUMENT_ROOT . '/core/modules/DolibarrModules.class.php';
|
2025-03-30 13:02:22 +02:00
|
|
|
|
2025-03-30 13:44:44 +02:00
|
|
|
/**
|
|
|
|
* Class modDolipesa
|
|
|
|
* Module descriptor for Dolipesa M-Pesa payment integration
|
|
|
|
*/
|
|
|
|
class modDolipesa extends DolibarrModules
|
2025-03-30 13:02:22 +02:00
|
|
|
{
|
2025-03-30 13:44:44 +02:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* @param DoliDB $db Database handler
|
|
|
|
*/
|
|
|
|
public function __construct($db)
|
2025-03-30 13:02:22 +02:00
|
|
|
{
|
2025-03-30 13:06:09 +02:00
|
|
|
global $langs, $conf;
|
2025-03-30 13:44:44 +02:00
|
|
|
|
2025-03-30 13:02:22 +02:00
|
|
|
$this->db = $db;
|
2025-03-30 13:06:09 +02:00
|
|
|
|
2025-03-30 13:44:44 +02:00
|
|
|
// Module metadata
|
|
|
|
$this->numero = 104900; // Unique module ID
|
|
|
|
$this->rights_class = 'dolipesa';
|
|
|
|
$this->family = 'financial';
|
|
|
|
$this->module_position = '50';
|
|
|
|
$this->name = preg_replace('/^mod/i', '', get_class($this)); // Extracts "Dolipesa" from class name
|
|
|
|
$this->description = 'Enables M-Pesa payment acceptance within Dolibarr ERP/CRM.';
|
|
|
|
$this->descriptionlong = 'Integrates Safaricom M-Pesa STK Push for seamless invoice and order payments.';
|
|
|
|
$this->editor_name = 'NESTICT INFOTECH';
|
|
|
|
$this->editor_url = 'https://www.nestict.com';
|
|
|
|
$this->version = '1.0.1';
|
|
|
|
$this->langs = 'dolipesa@dolipesa'; // Language file
|
2025-03-30 13:06:09 +02:00
|
|
|
|
2025-03-30 13:44:44 +02:00
|
|
|
// Configuration constants
|
2025-03-30 13:06:09 +02:00
|
|
|
$this->const = array(
|
2025-03-30 13:44:44 +02:00
|
|
|
0 => array(
|
|
|
|
'name' => 'MPESAPAY_CONSUMER_KEY',
|
|
|
|
'type' => 'chaine',
|
|
|
|
'default' => '',
|
|
|
|
'desc' => 'M-Pesa Consumer Key from Safaricom Daraja API',
|
|
|
|
'visible' => 0,
|
|
|
|
'entity' => 'current',
|
|
|
|
'enabled' => 1
|
|
|
|
),
|
|
|
|
1 => array(
|
|
|
|
'name' => 'MPESAPAY_CONSUMER_SECRET',
|
|
|
|
'type' => 'chaine',
|
|
|
|
'default' => '',
|
|
|
|
'desc' => 'M-Pesa Consumer Secret from Safaricom Daraja API (encrypted)',
|
|
|
|
'visible' => 0,
|
|
|
|
'entity' => 'current',
|
|
|
|
'enabled' => 1
|
|
|
|
),
|
|
|
|
2 => array(
|
|
|
|
'name' => 'MPESAPAY_SHORTCODE',
|
|
|
|
'type' => 'chaine',
|
|
|
|
'default' => '',
|
|
|
|
'desc' => 'M-Pesa Business Shortcode (Paybill or Till Number)',
|
|
|
|
'visible' => 0,
|
|
|
|
'entity' => 'current',
|
|
|
|
'enabled' => 1
|
|
|
|
),
|
|
|
|
3 => array(
|
|
|
|
'name' => 'MPESAPAY_PASSKEY',
|
|
|
|
'type' => 'chaine',
|
|
|
|
'default' => '',
|
|
|
|
'desc' => 'M-Pesa Passkey for STK Push (encrypted)',
|
|
|
|
'visible' => 0,
|
|
|
|
'entity' => 'current',
|
|
|
|
'enabled' => 1
|
|
|
|
),
|
|
|
|
4 => array(
|
|
|
|
'name' => 'MPESAPAY_CALLBACK_URL',
|
|
|
|
'type' => 'chaine',
|
|
|
|
'default' => DOL_MAIN_URL_ROOT . '/custom/dolipesa/callback.php',
|
|
|
|
'desc' => 'Callback URL for M-Pesa transaction responses',
|
|
|
|
'visible' => 0,
|
|
|
|
'entity' => 'current',
|
|
|
|
'enabled' => 1
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
// Module parts
|
|
|
|
$this->module_parts = array(
|
|
|
|
'hooks' => array('invoicecard', 'paymentcard', 'newpayment'), // Hooks for UI and payment processing
|
|
|
|
'triggers' => 0,
|
|
|
|
'login' => 0,
|
|
|
|
'substitutions' => 0,
|
|
|
|
'menus' => 0,
|
|
|
|
'theme' => 0,
|
|
|
|
'css' => array(),
|
|
|
|
'js' => array(),
|
|
|
|
'models' => 0
|
2025-03-30 13:06:09 +02:00
|
|
|
);
|
|
|
|
|
2025-03-30 13:44:44 +02:00
|
|
|
// Config page
|
|
|
|
$this->config_page_url = array('mpesapay_setup.php@dolipesa'); // Path relative to module dir
|
|
|
|
|
|
|
|
// Data directories
|
|
|
|
$this->dirs = array('/dolipesa/temp');
|
|
|
|
|
|
|
|
// Icon
|
|
|
|
$this->picto = 'payment@payment'; // Use Dolibarr payment icon
|
|
|
|
|
|
|
|
// Dependencies
|
|
|
|
$this->depends = array('modFacture'); // Requires invoice module
|
|
|
|
$this->requiredby = array();
|
|
|
|
$this->phpmin = array(7, 4); // Minimum PHP version
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate a secure payment URL for an invoice
|
|
|
|
*
|
|
|
|
* @param int $invoiceId Invoice ID
|
|
|
|
* @return string Payment URL
|
|
|
|
*/
|
|
|
|
public function generatePaymentUrl($invoiceId)
|
|
|
|
{
|
|
|
|
global $conf;
|
|
|
|
|
|
|
|
// Generate a secure token using invoice ID and a salt
|
|
|
|
$token = hash_hmac('sha256', $invoiceId . time(), $conf->global->MAIN_SECURITY_SALT);
|
|
|
|
$url = DOL_MAIN_URL_ROOT . '/custom/dolipesa/payment.php';
|
|
|
|
$url .= '?invoice_id=' . urlencode($invoiceId) . '&token=' . urlencode($token);
|
|
|
|
|
|
|
|
return $url;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize the module (called during activation)
|
|
|
|
*
|
|
|
|
* @return int 1 on success, < 0 on error
|
|
|
|
*/
|
|
|
|
public function init()
|
|
|
|
{
|
|
|
|
// Create SQL tables if needed
|
|
|
|
$sql = array(
|
|
|
|
"CREATE TABLE IF NOT EXISTS " . MAIN_DB_PREFIX . "dolipesa_transactions (
|
|
|
|
id int AUTO_INCREMENT PRIMARY KEY,
|
|
|
|
checkout_request_id varchar(50) NOT NULL,
|
|
|
|
fk_invoice int NOT NULL,
|
|
|
|
transaction_id varchar(50) DEFAULT NULL,
|
|
|
|
result_code varchar(10) DEFAULT NULL,
|
|
|
|
result_desc varchar(255) DEFAULT NULL,
|
|
|
|
datec datetime NOT NULL,
|
|
|
|
INDEX idx_fk_invoice (fk_invoice),
|
|
|
|
INDEX idx_checkout_request_id (checkout_request_id)
|
|
|
|
) ENGINE=InnoDB;"
|
|
|
|
);
|
2025-03-30 13:06:09 +02:00
|
|
|
|
2025-03-30 13:44:44 +02:00
|
|
|
return $this->_init($sql);
|
2025-03-30 13:06:09 +02:00
|
|
|
}
|
|
|
|
|
2025-03-30 13:44:44 +02:00
|
|
|
/**
|
|
|
|
* Remove the module (called during deactivation)
|
|
|
|
*
|
|
|
|
* @return int 1 on success, < 0 on error
|
|
|
|
*/
|
|
|
|
public function remove()
|
2025-03-30 13:06:09 +02:00
|
|
|
{
|
2025-03-30 13:44:44 +02:00
|
|
|
$sql = array();
|
|
|
|
return $this->_remove($sql); // No table drop by default; customize if needed
|
2025-03-30 13:02:22 +02:00
|
|
|
}
|
|
|
|
}
|
2025-03-30 13:44:44 +02:00
|
|
|
?>
|