97 lines
4.0 KiB
PHP
97 lines
4.0 KiB
PHP
<?php
|
|
/**
|
|
* Dolipesa - M-Pesa Payment Module Setup Page
|
|
* Author: NESTICT INFOTECH
|
|
* Version: 1.0.1
|
|
* License: GNU General Public License v3.0
|
|
*/
|
|
|
|
require '../../main.inc.php';
|
|
require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php';
|
|
require_once DOL_DOCUMENT_ROOT . '/core/class/html.form.class.php';
|
|
|
|
$langs->load('adminross('admin');
|
|
$langs->load('dolipesa@dolipesa');
|
|
|
|
if (!$user->admin) accessforbidden();
|
|
|
|
$action = GETPOST('action', 'alpha');
|
|
|
|
// Save settings
|
|
if ($action === 'save') {
|
|
$consumer_key = GETPOST('MPESAPAY_CONSUMER_KEY', 'alpha');
|
|
$consumer_secret = GETPOST('MPESAPAY_CONSUMER_SECRET', 'alpha');
|
|
$shortcode = GETPOST('MPESAPAY_SHORTCODE', 'alpha');
|
|
$passkey = GETPOST('MPESAPAY_PASSKEY', 'alpha');
|
|
$callback_url = GETPOST('MPESAPAY_CALLBACK_URL', 'alpha');
|
|
|
|
// Validate required fields
|
|
if (empty($shortcode) || empty($passkey) || empty($consumer_key) || empty($consumer_secret)) {
|
|
setEventMessages($langs->trans('ErrorFieldRequired'), null, 'errors');
|
|
} else {
|
|
// Store settings in Dolibarr configuration (encrypted for sensitive data)
|
|
dolibarr_set_const($db, 'MPESAPAY_CONSUMER_KEY', $consumer_key, 'chaine', 0, '', $conf->entity);
|
|
dolibarr_set_const($db, 'MPESAPAY_CONSUMER_SECRET', dol_encrypt($consumer_secret), 'chaine', 0, '', $conf->entity);
|
|
dolibarr_set_const($db, 'MPESAPAY_SHORTCODE', $shortcode, 'chaine', 0, '', $conf->entity);
|
|
dolibarr_set_const($db, 'MPESAPAY_PASSKEY', dol_encrypt($passkey), 'chaine', 0, '', $conf->entity);
|
|
dolibarr_set_const($db, 'MPESAPAY_CALLBACK_URL', $callback_url, 'chaine', 0, '', $conf->entity);
|
|
|
|
setEventMessages($langs->trans('SettingsSaved'), null, 'mesgs');
|
|
}
|
|
}
|
|
|
|
// Page title
|
|
print load_fiche_titre($langs->trans('MpesaPaymentModuleConfig'));
|
|
|
|
// Configuration form
|
|
print '<form method="POST" action="' . $_SERVER['PHP_SELF'] . '">';
|
|
print '<input type="hidden" name="action" value="save">';
|
|
|
|
print '<table class="noborder centpercent">';
|
|
print '<tr class="liste_titre">';
|
|
print '<th>' . $langs->trans('Parameter') . '</th>';
|
|
print '<th>' . $langs->trans('Value') . '</th>';
|
|
print '</tr>';
|
|
|
|
// Consumer Key
|
|
print '<tr class="oddeven">';
|
|
print '<td><label for="consumer_key">' . $langs->trans('MpesaConsumerKey') . '</label></td>';
|
|
print '<td><input type="text" name="MPESAPAY_CONSUMER_KEY" id="consumer_key" value="' . dolibarr_get_const($db, 'MPESAPAY_CONSUMER_KEY') . '" size="40"></td>';
|
|
print '</tr>';
|
|
|
|
// Consumer Secret (decrypted for display)
|
|
print '<tr class="oddeven">';
|
|
print '<td><label for="consumer_secret">' . $langs->trans('MpesaConsumerSecret') . '</label></td>';
|
|
print '<td><input type="text" name="MPESAPAY_CONSUMER_SECRET" id="consumer_secret" value="' . dol_decrypt(dolibarr_get_const($db, 'MPESAPAY_CONSUMER_SECRET')) . '" size="40"></td>';
|
|
print '</tr>';
|
|
|
|
// Shortcode (Business Till/Paybill Number)
|
|
print '<tr class="oddeven">';
|
|
print '<td><label for="shortcode">' . $langs->trans('MpesaShortcode') . '</label></td>';
|
|
print '<td><input type="text" name="MPESAPAY_SHORTCODE" id="shortcode" value="' . dolibarr_get_const($db, 'MPESAPAY_SHORTCODE') . '" size="20"></td>';
|
|
print '</tr>';
|
|
|
|
// Passkey (decrypted for display)
|
|
print '<tr class="oddeven">';
|
|
print '<td><label for="passkey">' . $langs->trans('MpesaPasskey') . '</label></td>';
|
|
print '<td><input type="text" name="MPESAPAY_PASSKEY" id="passkey" value="' . dol_decrypt(dolibarr_get_const($db, 'MPESAPAY_PASSKEY')) . '" size="40"></td>';
|
|
print '</tr>';
|
|
|
|
// Callback URL
|
|
print '<tr class="oddeven">';
|
|
print '<td><label for="callback_url">' . $langs->trans('MpesaCallbackURL') . '</label></td>';
|
|
print '<td><input type="text" name="MPESAPAY_CALLBACK_URL" id="callback_url" value="' . dolibarr_get_const($db, 'MPESAPAY_CALLBACK_URL') . '" size="60"></td>';
|
|
print '</tr>';
|
|
|
|
print '</table>';
|
|
|
|
print '<div class="center" style="margin-top: 20px;">';
|
|
print '<input type="submit" class="button" value="' . $langs->trans('Save') . '">';
|
|
print '</div>';
|
|
|
|
print '</form>';
|
|
|
|
// Footer
|
|
llxFooter();
|
|
$db->close();
|
|
?>
|