Skip to content

Commit ab5a0a1

Browse files
committed
fixed refund and chargeback callbacks
1 parent 3b6098b commit ab5a0a1

File tree

3 files changed

+131
-134
lines changed

3 files changed

+131
-134
lines changed

hooks.php

Lines changed: 85 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,100 @@
11
<?php
22
/**
3-
* Функция add_payneteasy_gateway
4-
*
5-
* Добавляет платёжный метод "WC_Payneteasy" в список доступных платёжных методов WooCommerce.
6-
*
7-
* @param array $methods - Список доступных платёжных методов
8-
* @return array - Модифицированный список платёжных методов с добавлением WC_Payneteasy
9-
*/
10-
function add_payneteasy_gateway(array $methods): array
11-
{
12-
$methods[] = 'WC_Payneteasy';
13-
global $wpdb;
14-
15-
$charset_collate = $wpdb->get_charset_collate();
16-
17-
$sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}payneteasy_payments (
18-
`id` int(11) NOT NULL AUTO_INCREMENT,
19-
`paynet_order_id` int(11) NOT NULL,
20-
`merchant_order_id` int(11) NOT NULL,
21-
PRIMARY KEY (id)
22-
) $charset_collate;";
23-
24-
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
25-
dbDelta( $sql );
26-
27-
return $methods;
3+
* Функция add_payneteasy_gateway
4+
*
5+
* Добавляет платёжный метод "WC_Payneteasy" в список доступных платёжных методов WooCommerce.
6+
*
7+
* @param array $methods - Список доступных платёжных методов
8+
* @return array - Модифицированный список платёжных методов с добавлением WC_Payneteasy */
9+
function add_payneteasy_gateway(array $methods): array {
10+
$methods[] = 'WC_Payneteasy';
11+
global $wpdb;
12+
13+
$charset_collate = $wpdb->get_charset_collate();
14+
15+
$sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}payneteasy_payments (
16+
`id` int(11) NOT NULL AUTO_INCREMENT,
17+
`paynet_order_id` int(11) NOT NULL,
18+
`merchant_order_id` int(11) NOT NULL,
19+
PRIMARY KEY (id)
20+
) $charset_collate";
21+
22+
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
23+
dbDelta( $sql );
24+
25+
return $methods;
2826
}
29-
add_filter('woocommerce_payment_gateways', 'add_payneteasy_gateway');
3027

28+
add_filter('woocommerce_payment_gateways', 'add_payneteasy_gateway');
3129

3230
/**
33-
* Функция load_payneteasy_textdomain
34-
*
35-
* Загружает локализацию (текстовый перевод) для плагина WC_Payneteasy.
36-
*/
31+
* Функция load_payneteasy_textdomain
32+
*
33+
* Загружает локализацию (текстовый перевод) для плагина WC_Payneteasy. */
3734
function load_payneteasy_textdomain(): void
38-
{
39-
load_plugin_textdomain('wc-payneteasy', false, dirname(plugin_basename(__FILE__)) . '/languages');
40-
}
35+
{ load_plugin_textdomain('wc-payneteasy', false, dirname(plugin_basename(__FILE__)) . '/languages'); }
36+
4137
add_action('plugins_loaded', 'load_payneteasy_textdomain');
4238

4339
/**
44-
* Функция get_payneteasy_field_options
45-
*
46-
* Возвращает список доступных опций для полей настроек WC_Payneteasy на основе идентификатора поля.
47-
*
48-
* @param string $field_id - Идентификатор поля настроек
49-
* @return array - Список опций для поля
50-
*/
51-
function get_payneteasy_field_options($field_id): array
52-
{
53-
$options = [
54-
'-' => __('Select an option', 'wc-payneteasy')
55-
];
56-
// Определяет опции для конкретного поля
57-
switch ($field_id) {
58-
case 'payneteasy_payment_method':
59-
$options = array_merge($options, [
60-
'form' => __('Form', 'wc-payneteasy'),
61-
'direct' => __('Direct', 'wc-payneteasy')
62-
]);
63-
break;
64-
}
65-
66-
return $options;
40+
* Функция get_payneteasy_field_options
41+
*
42+
* Возвращает список доступных опций для полей настроек WC_Payneteasy на основе идентификатора поля.
43+
*
44+
* @param string $field_id - Идентификатор поля настроек
45+
* @return array - Список опций для поля */
46+
function get_payneteasy_field_options($field_id): array {
47+
$options = [ '-' => __('Select an option', 'wc-payneteasy') ];
48+
# Определяет опции для конкретного поля
49+
switch ($field_id) {
50+
case 'payneteasy_payment_method':
51+
$options = array_merge($options, [ 'form' => __('Form', 'wc-payneteasy'), 'direct' => __('Direct', 'wc-payneteasy') ]);
52+
break;
53+
}
54+
55+
return $options;
6756
}
6857

6958
/**
70-
* Функция adding_payneteasy_button_to_orders_page
71-
*
72-
* Добавляет скрипты и стили к странице заказов и настройкам WC_Payneteasy в административной части.
73-
*
74-
* @param string $hook - Идентификатор страницы в административной части WordPress
75-
*/
76-
function adding_payneteasy_button_to_orders_page($hook): void
77-
{
78-
// Проверяет наличие настроек WC_Payneteasy и условия для добавления скриптов и стилей
79-
$payneteasy_settings = get_option('woocommerce_wc_payneteasy_settings');
80-
global $post;
81-
82-
if (
83-
($hook == 'post-new.php' || $hook == 'post.php') &&
84-
!empty($post) && $post->post_type === 'shop_order'
85-
) {
86-
$order_id = $post->ID;
87-
$order = wc_get_order($order_id);
88-
$order_status = $order->get_status();
89-
$payment_method = $order->get_payment_method();
90-
91-
if (
92-
$order_status !== 'failed' &&
93-
$order_status !== 'refunded' &&
94-
$order_status !== 'cancelled' &&
95-
$payment_method === 'wc_payneteasy'
96-
) {
97-
// Подключает скрипт для работы с заказами WC_Payneteasy
98-
wp_enqueue_script('payneteasy-order-page-script', plugins_url('/assets/js/payneteasy-order-page-script.js', __FILE__), ['jquery'], '1.0', true);
99-
wp_localize_script(
100-
'payneteasy-order-page-script',
101-
'payneteasy_ajax_var', [
102-
'nonce' => wp_create_nonce('payneteasy-ajax-nonce'),
103-
'api_url' => home_url('/wc-api/wc_payneteasy_ajax')
104-
]);
105-
}
106-
}
59+
* Функция adding_payneteasy_button_to_orders_page
60+
*
61+
* Добавляет скрипты и стили к странице заказов и настройкам WC_Payneteasy в административной части.
62+
*
63+
* @param string $hook - Идентификатор страницы в административной части WordPress */
64+
function adding_payneteasy_button_to_orders_page($hook): void {
65+
# Проверяет наличие настроек WC_Payneteasy и условия для добавления скриптов и стилей
66+
$payneteasy_settings = get_option('woocommerce_wc_payneteasy_settings');
67+
global $post;
68+
69+
if (($hook == 'post-new.php' || $hook == 'post.php') && !empty($post) && $post->post_type === 'shop_order') {
70+
$order_id = $post->ID;
71+
$order = wc_get_order($order_id);
72+
$order_status = $order->get_status();
73+
$payment_method = $order->get_payment_method();
74+
75+
if ($payment_method == 'wc_payneteasy' && !in_array($order_status, ['failed','refunded','cancelled'])) {
76+
# Подключает скрипт для работы с заказами WC_Payneteasy
77+
wp_enqueue_script('payneteasy-order-page-script',
78+
plugins_url('/assets/js/payneteasy-order-page-script.js', __FILE__), ['jquery'], '1.0', true);
79+
80+
wp_localize_script(
81+
'payneteasy-order-page-script',
82+
'payneteasy_ajax_var', [ 'nonce' => wp_create_nonce('payneteasy-ajax-nonce'), 'api_url' => home_url('/wc-api/wc_payneteasy_ajax') ]);
83+
}
84+
}
10785
}
86+
10887
add_action('admin_enqueue_scripts', 'adding_payneteasy_button_to_orders_page');
88+
89+
function register_chargeback_status(array $statuses): array {
90+
return array_merge($statuses, [
91+
'wc-chargeback' => [
92+
'label' => _x('Chargeback', 'Order status', 'payneteasy'),
93+
'public' => false,
94+
'exclude_from_search' => false,
95+
'show_in_admin_all_list' => true,
96+
'show_in_admin_status_list' => true,
97+
'label_count' => _n_noop('Chargeback <span class="count">(%s)</span>', 'Chargeback <span class="count">(%s)</span>', 'payneteasy') ] ]);
98+
}
99+
100+
add_action('woocommerce_register_shop_order_post_statuses', 'register_chargeback_status');

src/Classes/Exception/PayneteasyException.php

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,14 @@
44

55
(defined('ABSPATH') || PHP_SAPI == 'cli') or die('Restricted access');
66

7-
class PayneteasyException extends \Exception
8-
{
9-
private array $context = [];
7+
class PayneteasyException extends \Exception {
8+
private array $context = [];
109

11-
public function __construct(
12-
string $message,
13-
array $context = [],
14-
int $code = 0,
15-
\Throwable $previous = null
16-
) {
17-
$this->context = $context;
18-
parent::__construct($message, $code, $previous);
19-
}
10+
public function __construct(string $message, array $context = [], int $code = 0, \Throwable $previous = null) {
11+
$this->context = $context;
12+
parent::__construct($message, $code, $previous);
13+
}
2014

21-
public function getContext(): array
22-
{
23-
return $this->context;
24-
}
15+
public function getContext(): array
16+
{ return $this->context; }
2517
}

0 commit comments

Comments
 (0)