-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsnippe-payment-gateway.php
More file actions
159 lines (139 loc) · 5.56 KB
/
snippe-payment-gateway.php
File metadata and controls
159 lines (139 loc) · 5.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<?php
/**
* Plugin Name: Snippe Payments for WooCommerce
* Plugin URI: https://snippe.sh
* Description: Accept payments via Snippe - Mobile Money, Card, and QR Code payments for WooCommerce
* Version: 1.2.0
* Author: Snippe
* Author URI: https://snippe.sh
* Text Domain: snippe-payment-gateway
* Domain Path: /languages
* Requires at least: 5.8
* Tested up to: 6.4
* WC requires at least: 6.0
* WC tested up to: 8.5
* License: GPL v3 or later
* License URI: https://www.gnu.org/licenses/gpl-3.0.html
*/
if (!defined('ABSPATH')) {
exit;
}
// Define plugin constants
define('SNIPPE_VERSION', '1.0.0');
define('SNIPPE_PLUGIN_FILE', __FILE__);
define('SNIPPE_PLUGIN_DIR', plugin_dir_path(__FILE__));
define('SNIPPE_PLUGIN_URL', plugin_dir_url(__FILE__));
define('SNIPPE_API_BASE_URL', 'https://api.snippe.sh');
/**
* Check if WooCommerce is active
*/
if (!in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')))) {
return;
}
/**
* Add the gateway to WooCommerce
*/
add_filter('woocommerce_payment_gateways', 'snippe_add_gateway_class');
function snippe_add_gateway_class($gateways) {
$gateways[] = 'WC_Gateway_Snippe';
return $gateways;
}
/**
* Initialize the gateway
*/
add_action('plugins_loaded', 'snippe_init_gateway_class');
function snippe_init_gateway_class() {
// Include required files
require_once SNIPPE_PLUGIN_DIR . 'includes/class-snippe-api.php';
require_once SNIPPE_PLUGIN_DIR . 'includes/class-snippe-gateway.php';
require_once SNIPPE_PLUGIN_DIR . 'includes/class-snippe-webhook.php';
require_once SNIPPE_PLUGIN_DIR . 'includes/class-snippe-logger.php';
// Initialize webhook handler
Snippe_Webhook::init();
}
/**
* Declare compatibility with WooCommerce features
*/
add_action('before_woocommerce_init', 'snippe_declare_compatibility');
function snippe_declare_compatibility() {
if (class_exists('\Automattic\WooCommerce\Utilities\FeaturesUtil')) {
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility('custom_order_tables', __FILE__, true);
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility('cart_checkout_blocks', __FILE__, true);
}
}
/**
* Register block checkout support
*/
add_action('woocommerce_blocks_loaded', 'snippe_register_block_support');
function snippe_register_block_support() {
if (class_exists('Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType')) {
require_once SNIPPE_PLUGIN_DIR . 'includes/class-snippe-blocks-support.php';
add_action(
'woocommerce_blocks_payment_method_type_registration',
function ($payment_method_registry) {
$payment_method_registry->register(new Snippe_Blocks_Support());
}
);
}
}
/**
* Add custom action links
*/
add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'snippe_plugin_action_links');
function snippe_plugin_action_links($links) {
$settings_link = '<a href="' . admin_url('admin.php?page=wc-settings&tab=checkout§ion=snippe') . '">' . __('Settings', 'snippe-payment-gateway') . '</a>';
array_unshift($links, $settings_link);
return $links;
}
/**
* Add order metadata display
*/
add_action('woocommerce_admin_order_data_after_billing_address', 'snippe_display_order_data_in_admin', 10, 1);
function snippe_display_order_data_in_admin($order) {
$payment_method = $order->get_payment_method();
if ($payment_method !== 'snippe') {
return;
}
$payment_reference = $order->get_meta('_snippe_payment_reference');
$payment_type = $order->get_meta('_snippe_payment_type');
$external_reference = $order->get_meta('_snippe_external_reference');
if ($payment_reference) {
echo '<div class="order_data_column">';
echo '<h3>' . __('Snippe Payment Details', 'snippe-payment-gateway') . '</h3>';
echo '<p><strong>' . __('Payment Reference:', 'snippe-payment-gateway') . '</strong> ' . esc_html($payment_reference) . '</p>';
if ($payment_type) {
echo '<p><strong>' . __('Payment Type:', 'snippe-payment-gateway') . '</strong> ' . esc_html(ucfirst($payment_type)) . '</p>';
}
if ($external_reference) {
echo '<p><strong>' . __('External Reference:', 'snippe-payment-gateway') . '</strong> ' . esc_html($external_reference) . '</p>';
}
echo '</div>';
}
}
/**
* Load plugin textdomain
*/
add_action('init', 'snippe_load_textdomain');
function snippe_load_textdomain() {
load_plugin_textdomain('snippe-payment-gateway', false, dirname(plugin_basename(__FILE__)) . '/languages');
}
/**
* Enqueue frontend scripts and styles
*/
add_action('wp_enqueue_scripts', 'snippe_enqueue_scripts');
function snippe_enqueue_scripts() {
if (is_checkout() || is_wc_endpoint_url('order-pay')) {
wp_enqueue_style('snippe-styles', SNIPPE_PLUGIN_URL . 'assets/css/snippe-styles.css', array(), SNIPPE_VERSION);
wp_enqueue_script('snippe-scripts', SNIPPE_PLUGIN_URL . 'assets/js/snippe-scripts.js', array('jquery'), SNIPPE_VERSION, true);
}
}
/**
* Enqueue admin scripts and styles
*/
add_action('admin_enqueue_scripts', 'snippe_enqueue_admin_scripts');
function snippe_enqueue_admin_scripts($hook) {
if ($hook === 'woocommerce_page_wc-settings') {
wp_enqueue_style('snippe-admin-styles', SNIPPE_PLUGIN_URL . 'assets/css/snippe-styles.css', array(), SNIPPE_VERSION);
wp_enqueue_script('snippe-admin-scripts', SNIPPE_PLUGIN_URL . 'assets/js/snippe-admin.js', array('jquery'), SNIPPE_VERSION, true);
}
}