This repository was archived by the owner on Jun 6, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwoocommerce_tegro_plugin.php
More file actions
94 lines (82 loc) · 3.43 KB
/
Copy pathwoocommerce_tegro_plugin.php
File metadata and controls
94 lines (82 loc) · 3.43 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
<?php
/**
* Plugin Name: WooCommerce Tegro Plugin
* Description: Плагин для интеграции Tegro с WooCommerce.
* Version: 1.0
* Author: Коваленко Михаил
*/
// Регистрация метода оплаты в WooCommerce
add_filter('woocommerce_payment_gateways', 'add_tegro_payment_gateway');
function add_tegro_payment_gateway($gateways)
{
$gateways[] = 'WC_Tegro_Payment_Gateway';
return $gateways;
}
// Класс для обработки оплаты через Tegro
require_once( ABSPATH . 'wp-content/plugins/woocommerce/includes/abstracts/abstract-wc-payment-gateway.php' );
require_once( ABSPATH . 'wp-content/plugins/woocommerce/includes/abstracts/abstract-wc-settings-api.php');
class WC_Tegro_Payment_Gateway extends WC_Payment_Gateway
{
public function __construct()
{
$this->id = 'tegro_payment_gateway';
$this->method_title = 'Tegro Payment Gateway';
$this->method_description = 'Оплата через Tegro API';
$this->has_fields = false;
$this->init_form_fields();
$this->init_settings();
$this->title = $this->get_option('title');
$this->description = $this->get_option('description');
add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
}
public function init_form_fields()
{
$this->form_fields = array(
'enabled' => array(
'title' => 'Включить/Выключить',
'type' => 'checkbox',
'label' => 'Включить оплату через Tegro',
'default' => 'yes'
),
'title' => array(
'title' => 'Название',
'type' => 'text',
'description' => 'Название метода оплаты, отображаемое для покупателя',
'default' => 'Tegro Payment',
'desc_tip' => true
),
'description' => array(
'title' => 'Описание',
'type' => 'textarea',
'description' => 'Описание метода оплаты, отображаемое для покупателя',
'default' => 'Оплата через Tegro API'
)
);
}
public function process_payment($order_id){
$order = wc_get_order($order_id);
$shop_id = 'your shop_id'; //Замените на свой Shop_id
$amount = $order->get_total();
$currency = get_woocommerce_currency();
$order_id = $order->get_id();
$secret = 'your secret_key'; //замените на свой secret key
// Формируем данные для создания подписи
$data = array(
'shop_id' => $shop_id,
'amount' => $amount,
'currency' => $currency,
'order_id' => $order_id,
//'test'=> 1,
);
ksort($data);
$str = http_build_query($data);
$sign = md5($str . $secret);
// Формируем ссылку для оплаты
$payment_url = "https://tegro.money/pay?{$str}&sign={$sign}";
// Перенаправляем пользователя на страницу оплаты
return array(
'result' => 'success',
'redirect' => $payment_url,
);
}
}