v1.0.1
This commit is contained in:
220
bankily-bpay.php
Normal file
220
bankily-bpay.php
Normal file
@@ -0,0 +1,220 @@
|
||||
<?php
|
||||
/**
|
||||
* Plugin Name: B-PAY Bankily for WooCommerce
|
||||
* Plugin URI: https://yourwebsite.com
|
||||
* Description: Plugin de paiement mobile B-PAY Bankily pour WooCommerce avec gestion complète des transactions
|
||||
* Version: 1.0.1
|
||||
* Author: Votre Nom
|
||||
* License: GPL v2 or later
|
||||
* Text Domain: bankily-bpay
|
||||
* Domain Path: /languages
|
||||
*
|
||||
* Requires at least: 5.0
|
||||
* Tested up to: 6.3
|
||||
* WC requires at least: 4.0
|
||||
* WC tested up to: 8.0
|
||||
*
|
||||
* @package Bankily_BPay
|
||||
*/
|
||||
|
||||
// Empêcher l'accès direct
|
||||
if (!defined('ABSPATH')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
// Constantes du plugin
|
||||
define('BANKILY_BPAY_VERSION', '1.0.1');
|
||||
define('BANKILY_BPAY_PLUGIN_FILE', __FILE__);
|
||||
define('BANKILY_BPAY_PLUGIN_DIR', plugin_dir_path(__FILE__));
|
||||
define('BANKILY_BPAY_PLUGIN_URL', plugin_dir_url(__FILE__));
|
||||
|
||||
// Déclarer la compatibilité avec HPOS (High Performance Order Storage)
|
||||
add_action('before_woocommerce_init', function() {
|
||||
if (class_exists('\Automattic\WooCommerce\Utilities\FeaturesUtil')) {
|
||||
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility('custom_order_tables', __FILE__, true);
|
||||
}
|
||||
});
|
||||
|
||||
// Déclarer la compatibilité avec les blocs de checkout WooCommerce
|
||||
add_action('before_woocommerce_init', function() {
|
||||
if (class_exists('\Automattic\WooCommerce\Utilities\FeaturesUtil')) {
|
||||
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility('cart_checkout_blocks', __FILE__, true);
|
||||
}
|
||||
});
|
||||
|
||||
// Vérifier si WooCommerce est activé
|
||||
add_action('plugins_loaded', 'bankily_bpay_init', 11);
|
||||
|
||||
function bankily_bpay_init() {
|
||||
if (!class_exists('WC_Payment_Gateway')) {
|
||||
add_action('admin_notices', 'bankily_bpay_missing_wc_notice');
|
||||
return;
|
||||
}
|
||||
|
||||
// Charger les traductions
|
||||
load_plugin_textdomain('bankily-bpay', false, dirname(plugin_basename(__FILE__)) . '/languages');
|
||||
|
||||
// Inclure la classe de passerelle de paiement
|
||||
include_once('class-wc-bankily-bpay-gateway.php');
|
||||
|
||||
// Charger l'interface d'administration si en mode admin
|
||||
if (is_admin()) {
|
||||
$admin_file = BANKILY_BPAY_PLUGIN_DIR . 'class-bankily-admin.php';
|
||||
if (file_exists($admin_file)) {
|
||||
include_once($admin_file);
|
||||
}
|
||||
}
|
||||
|
||||
// Ajouter la passerelle aux passerelles WooCommerce
|
||||
add_filter('woocommerce_payment_gateways', 'add_bankily_bpay_gateway');
|
||||
}
|
||||
|
||||
function bankily_bpay_missing_wc_notice() {
|
||||
echo '<div class="error"><p><strong>' . sprintf(esc_html__('B-PAY Bankily nécessite WooCommerce pour fonctionner. Veuillez installer et activer %sWooCommerce%s.', 'bankily-bpay'), '<a href="http://www.woothemes.com/woocommerce/" target="_blank">', '</a>') . '</strong></p></div>';
|
||||
}
|
||||
|
||||
function add_bankily_bpay_gateway($gateways) {
|
||||
$gateways[] = 'WC_Bankily_BPay_Gateway';
|
||||
return $gateways;
|
||||
}
|
||||
|
||||
// Créer les tables personnalisées lors de l'activation
|
||||
register_activation_hook(__FILE__, 'bankily_bpay_create_tables');
|
||||
|
||||
function bankily_bpay_create_tables() {
|
||||
global $wpdb;
|
||||
|
||||
$table_name = $wpdb->prefix . 'bankily_transactions';
|
||||
|
||||
$charset_collate = $wpdb->get_charset_collate();
|
||||
|
||||
$sql = "CREATE TABLE $table_name (
|
||||
id mediumint(9) NOT NULL AUTO_INCREMENT,
|
||||
order_id bigint(20) NOT NULL,
|
||||
operation_id varchar(100) NOT NULL,
|
||||
transaction_id varchar(100) DEFAULT '',
|
||||
client_phone varchar(20) NOT NULL,
|
||||
amount decimal(10,2) NOT NULL,
|
||||
status varchar(10) DEFAULT 'TA',
|
||||
error_code varchar(10) DEFAULT '',
|
||||
error_message text DEFAULT '',
|
||||
created_at datetime DEFAULT CURRENT_TIMESTAMP,
|
||||
last_checked datetime DEFAULT CURRENT_TIMESTAMP,
|
||||
check_count int(11) DEFAULT 0,
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY operation_id (operation_id),
|
||||
KEY order_id (order_id),
|
||||
KEY status (status),
|
||||
KEY created_at (created_at),
|
||||
KEY status_created (status, created_at)
|
||||
) $charset_collate;";
|
||||
|
||||
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
|
||||
dbDelta($sql);
|
||||
|
||||
// Programmer les tâches cron
|
||||
if (!wp_next_scheduled('bankily_auto_check_transactions')) {
|
||||
wp_schedule_event(time(), 'fifteen_minutes', 'bankily_auto_check_transactions');
|
||||
}
|
||||
|
||||
if (!wp_next_scheduled('bankily_daily_report')) {
|
||||
wp_schedule_event(strtotime('tomorrow 8:00'), 'daily', 'bankily_daily_report');
|
||||
}
|
||||
}
|
||||
|
||||
// Actions à effectuer lors de l'activation
|
||||
function bankily_bpay_activate() {
|
||||
bankily_bpay_create_tables();
|
||||
flush_rewrite_rules();
|
||||
}
|
||||
|
||||
// Actions à effectuer lors de la désactivation
|
||||
function bankily_bpay_deactivate() {
|
||||
// Nettoyer les données temporaires
|
||||
delete_transient('bankily_bpay_access_token');
|
||||
delete_transient('bankily_bpay_refresh_token');
|
||||
|
||||
// Supprimer les tâches cron
|
||||
wp_clear_scheduled_hook('bankily_auto_check_transactions');
|
||||
wp_clear_scheduled_hook('bankily_daily_report');
|
||||
|
||||
flush_rewrite_rules();
|
||||
}
|
||||
|
||||
register_activation_hook(__FILE__, 'bankily_bpay_activate');
|
||||
register_deactivation_hook(__FILE__, 'bankily_bpay_deactivate');
|
||||
|
||||
// Ajouter un intervalle cron personnalisé pour 15 minutes
|
||||
add_filter('cron_schedules', 'bankily_add_cron_interval');
|
||||
|
||||
function bankily_add_cron_interval($schedules) {
|
||||
$schedules['fifteen_minutes'] = array(
|
||||
'interval' => 15 * 60, // 15 minutes en secondes
|
||||
'display' => __('Toutes les 15 minutes', 'bankily-bpay')
|
||||
);
|
||||
|
||||
return $schedules;
|
||||
}
|
||||
|
||||
// Ajouter un lien vers les paramètres dans la liste des plugins
|
||||
add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'bankily_bpay_action_links');
|
||||
|
||||
function bankily_bpay_action_links($links) {
|
||||
$plugin_links = array(
|
||||
'<a href="' . admin_url('admin.php?page=wc-settings&tab=checkout§ion=bankily_bpay') . '">' . __('Paramètres', 'bankily-bpay') . '</a>',
|
||||
);
|
||||
return array_merge($plugin_links, $links);
|
||||
}
|
||||
|
||||
// Afficher les détails B-PAY sur la page de commande client
|
||||
add_action('woocommerce_order_details_after_order_table', 'bankily_bpay_order_details');
|
||||
|
||||
function bankily_bpay_order_details($order) {
|
||||
if ($order->get_payment_method() == 'bankily_bpay') {
|
||||
global $wpdb;
|
||||
$table_name = $wpdb->prefix . 'bankily_transactions';
|
||||
|
||||
$transaction = $wpdb->get_row($wpdb->prepare(
|
||||
"SELECT * FROM $table_name WHERE order_id = %d ORDER BY created_at DESC LIMIT 1",
|
||||
$order->get_id()
|
||||
));
|
||||
|
||||
if ($transaction) {
|
||||
echo '<h2>' . __('Détails du paiement B-PAY', 'bankily-bpay') . '</h2>';
|
||||
echo '<table class="woocommerce-table woocommerce-table--bankily-details">';
|
||||
|
||||
if ($transaction->transaction_id) {
|
||||
echo '<tr><th>' . __('ID Transaction:', 'bankily-bpay') . '</th><td>' . esc_html($transaction->transaction_id) . '</td></tr>';
|
||||
}
|
||||
|
||||
echo '<tr><th>' . __('ID Opération:', 'bankily-bpay') . '</th><td>' . esc_html($transaction->operation_id) . '</td></tr>';
|
||||
echo '<tr><th>' . __('Statut:', 'bankily-bpay') . '</th><td>';
|
||||
|
||||
switch ($transaction->status) {
|
||||
case 'TS':
|
||||
echo '<span style="color: #28a745; font-weight: bold;">✓ ' . __('Confirmé', 'bankily-bpay') . '</span>';
|
||||
break;
|
||||
case 'TA':
|
||||
echo '<span style="color: #ffc107; font-weight: bold;">⏳ ' . __('En attente', 'bankily-bpay') . '</span>';
|
||||
break;
|
||||
case 'TF':
|
||||
echo '<span style="color: #dc3545; font-weight: bold;">✗ ' . __('Échoué', 'bankily-bpay') . '</span>';
|
||||
break;
|
||||
default:
|
||||
echo esc_html($transaction->status);
|
||||
}
|
||||
|
||||
echo '</td></tr>';
|
||||
echo '</table>';
|
||||
|
||||
if ($transaction->status == 'TA') {
|
||||
echo '<div style="background: #fff3cd; border: 1px solid #ffeaa7; padding: 15px; border-radius: 4px; margin-top: 15px;">';
|
||||
echo '<p style="margin: 0;"><strong>' . __('Transaction en attente', 'bankily-bpay') . '</strong></p>';
|
||||
echo '<p style="margin: 5px 0 0 0;">' . __('Votre paiement est en cours de vérification. Vous recevrez une confirmation par SMS une fois le paiement validé.', 'bankily-bpay') . '</p>';
|
||||
echo '</div>';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user