PluginProbe
ووسلام – همگام سازی ووکامرس و باسلام / 1.10.19
ووسلام – همگام سازی ووکامرس و باسلام v1.10.19
1.10.19 1.10.20 1.10.18 1.10.17 1.10.15 1.10.14 1.10.13 1.10.12 1.10.10 1.10.9 1.10.8 1.10.7 1.10.6 1.10.5 1.10.4 1.10.3 1.10.2 1.10.1 1.10.0 1.9.2 1.9.1 1.9.0 1.8.8 1.8.5 1.8.6 All 53 releases
sync-basalam / includes / Admin / FinancialManagement / BalanceSettlement.php

BalanceSettlement.php in ووسلام – همگام سازی ووکامرس و باسلام 1.10.19, at includes/Admin/FinancialManagement/BalanceSettlement.php

95 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace SyncBasalam\Admin\FinancialManagement;
4
5 use SyncBasalam\Services\FinancialManagementService;
6
7 defined('ABSPATH') || exit;
8
9 class BalanceSettlement
10 {
11 public const AJAX_ACTION = 'sync_basalam_balance_settlement';
12 public const AJAX_ACTION_BANK_ACCOUNTS = 'sync_basalam_bank_accounts';
13
14 public static function register(): void
15 {
16 add_action('wp_ajax_' . self::AJAX_ACTION, [__CLASS__, 'handleAjax']);
17 add_action('wp_ajax_' . self::AJAX_ACTION_BANK_ACCOUNTS, [__CLASS__, 'handleBankAccountsAjax']);
18 }
19
20 public static function handleAjax(): void
21 {
22 if (!current_user_can('manage_options')) {
23 wp_send_json_error([
24 'message' => 'ش�
25 ا به این بخش دسترسی ندارید.',
26 ], 403);
27 }
28
29 check_ajax_referer(self::AJAX_ACTION, 'nonce');
30
31 $amount = isset($_POST['amount']) ? (int) $_POST['amount'] : 0;
32 $method = isset($_POST['method']) ? (int) $_POST['method'] : 0;
33
34 if ($amount <= 0) {
35 wp_send_json_error([
36 'message' => '�
37 بلغ وارد شده �
38 عتبر نیست.',
39 ], 400);
40 }
41
42 if ($method <= 0) {
43 wp_send_json_error([
44 'message' => 'روش تسویه �
45 شخص نشده است.',
46 ], 400);
47 }
48
49 $investmentOptionId = isset($_POST['investment_option_id']) && $_POST['investment_option_id'] !== '' ? (int) $_POST['investment_option_id'] : null;
50 $bankAccountId = isset($_POST['bank_account_id']) && $_POST['bank_account_id'] !== '' ? (int) $_POST['bank_account_id'] : null;
51
52 $service = new FinancialManagementService();
53 $result = $service->createSettlement($amount, $method, $investmentOptionId, $bankAccountId);
54
55 if (empty($result['success'])) {
56 wp_send_json_error([
57 'message' => $result['message'] ?? 'خطا در ثبت درخواست تسویه.',
58 ], $result['status_code'] ?? 500);
59 }
60
61 wp_send_json_success([
62 'message' => 'درخواست تسویه با �
63 وفقیت ثبت شد.',
64 'data' => $result['data'],
65 ]);
66 }
67
68 public static function handleBankAccountsAjax(): void
69 {
70 if (!current_user_can('manage_options')) {
71 wp_send_json_error([
72 'message' => 'ش�
73 ا به این بخش دسترسی ندارید.',
74 ], 403);
75 }
76
77 check_ajax_referer(self::AJAX_ACTION, 'nonce');
78
79 $service = new FinancialManagementService();
80 $result = $service->getBankAccounts();
81
82 if (empty($result['success'])) {
83 wp_send_json_error([
84 'message' => $result['message'] ?? 'خطا در دریافت لیست حساب‌های بانکی.',
85 ], $result['status_code'] ?? 500);
86 }
87
88 $accounts = isset($result['data']['data']) && is_array($result['data']['data']) ? $result['data']['data'] : [];
89
90 wp_send_json_success([
91 'accounts' => $accounts,
92 ]);
93 }
94 }
95