Issues (1369)

metamatter.php (7 issues)

1
<?php
2
3
// Придумать какой статус должен быть у глобальных ответов, что бы не перекрывать статусы платежных систем
4
// Может добавить спецстатус "Ответ системы платежа" и парсить дальше getMessage
5
// см constants.php
6
7
use Payment\PaymentMethods;
8
9
global $debug;
10
global $template_result;
11
global $config;
12
13
/** @noinspection PhpIncludeInspection */
14
require_once('common.' . substr(strrchr(__FILE__, '.'), 1));
15
16
if (!SN::$gc->modules->countModulesInGroup('payment')) {
17
  sys_redirect('dark_matter.php');
18
  die();
19
}
20
21
lng_include('payment');
22
lng_include('infos');
23
24
$template = SnTemplate::gettemplate('metamatter', true);
0 ignored issues
show
true of type true is incompatible with the type null|template expected by parameter $template of SnTemplate::gettemplate(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

24
$template = SnTemplate::gettemplate('metamatter', /** @scrutinizer ignore-type */ true);
Loading history...
25
26
// $player_currency_default = player_load_option($user, PLAYER_OPTION_CURRENCY_DEFAULT);
27
$player_currency_default = SN::$user_options[PLAYER_OPTION_CURRENCY_DEFAULT];
28
$player_currency         = sys_get_param_str('player_currency', $player_currency_default);
29
empty(SN::$lang['pay_currency_list'][$player_currency]) ? ($player_currency = $player_currency_default ? $player_currency_default : SN::$config->payment_currency_default) : false;
30
// $player_currency_default != $player_currency ? player_save_option($user, PLAYER_OPTION_CURRENCY_DEFAULT, $player_currency) : false;
31
$player_currency_default != $player_currency ? SN::$user_options[PLAYER_OPTION_CURRENCY_DEFAULT] = $player_currency : false;
32
33
// Таблица скидок
34
$prev_discount = 0;
35
if (isset(sn_module_payment::$bonus_table) && is_array(sn_module_payment::$bonus_table)) {
36
  foreach (sn_module_payment::$bonus_table as $sum => $discount) {
37
    if ($discount && $discount != $prev_discount) {
38
      $template->assign_block_vars('discount', array(
39
        'SUM'          => $sum,
40
        'DISCOUNT'     => $discount * 100,
41
        'DISCOUNT_ONE' => 1 + $discount,
42
        'TEXT'         => sprintf(SN::$lang['pay_mm_bonus_each'], HelperString::numberFloorAndFormat($sum), round($discount * 100)),
43
      ));
44
      $prev_discount = $discount;
45
    }
46
  }
47
}
48
49
// Результат платежа
50
if (
51
  ($payment_id = sys_get_param_id('payment_id'))
52
  ||
53
  ($payment_id = sys_get_param_id('ik_pm_no'))
54
) {
55
  /** @noinspection PhpDeprecationInspection */
56
  $payment = doquery("SELECT * FROM {{payment}} WHERE `payment_id` = {$payment_id} LIMIT 1;", true);
0 ignored issues
show
true of type true is incompatible with the type string expected by parameter $table of doquery(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

56
  $payment = doquery("SELECT * FROM {{payment}} WHERE `payment_id` = {$payment_id} LIMIT 1;", /** @scrutinizer ignore-type */ true);
Loading history...
Deprecated Code introduced by
The function doquery() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

56
  $payment = /** @scrutinizer ignore-deprecated */ doquery("SELECT * FROM {{payment}} WHERE `payment_id` = {$payment_id} LIMIT 1;", true);
Loading history...
57
  if ($payment && $payment['payment_user_id'] == $user['id']) {
58
    if ($payment['payment_status'] == PAYMENT_STATUS_COMPLETE) {
59
      $template->assign_block_vars('result', array('MESSAGE' => sprintf(SN::$lang['pay_msg_mm_purchase_complete'], $payment['payment_dark_matter_paid'], $payment['payment_module_name'], $payment['payment_dark_matter_gained'])));
60
    }
61
    if ($payment['payment_status'] == PAYMENT_STATUS_NONE) {
62
      $template->assign_block_vars('result', array(
63
        'MESSAGE' => sprintf(SN::$lang['pay_msg_mm_purchase_incomplete'], $payment['payment_dark_matter_paid'], $payment['payment_module_name']),
64
        'STATUS'  => 1,
65
      ));
66
    }
67
    if ($payment['payment_test']) {
68
      $template->assign_block_vars('result', array(
69
        'MESSAGE' => sprintf(SN::$lang['pay_msg_mm_purchase_test']),
70
        'STATUS'  => -1,
71
      ));
72
    }
73
  }
74
}
75
76
$unit_available_amount_list = &sn_module_payment::$bonus_table;
77
78
$request = array(
79
  'metamatter' => sys_get_param_float('metamatter'),
80
);
81
82
if (!$request['metamatter']) {
83
  unset($_POST);
84
}
85
86
$payment_module_request  = sys_get_param_str('payment_module');
87
//$payment_type_selected   = sys_get_param_int('payment_type');
88
$payment_method_selected = sys_get_param_int('payment_method');
89
90
//pdump($payment_module_request, '$payment_module_request');
91
//pdump($payment_type_selected, '$payment_type_selected');
92
//pdump($payment_method_selected, '$payment_method_selected');
93
94
list($payment_module_request, $payment_method_selected) = PaymentMethods::getActiveMethods()->processInputParams($payment_module_request, $payment_method_selected);
95
96
//pdump($payment_module_request, '$payment_module_request');
97
//pdump($payment_type_selected, '$payment_type_selected');
98
//pdump($payment_method_selected, '$payment_method_selected');
99
100
//die();
101
102
if (!$payment_module_request && $payment_method_selected) {
103
  $template_result['.']['payment_module'] = PaymentMethods::renderModulesForMethod($payment_method_selected, $player_currency, $request);
104
} elseif (!$payment_module_request || !$payment_method_selected) {
105
  $template_result['.']['payment'] = PaymentMethods::renderPaymentMethodList();
106
}
107
108
foreach (SN::$lang['pay_currency_list'] as $key => $value) {
109
  $course = get_exchange_rate($key);
110
  if (!$course) {
111
    continue;
112
  }
113
  $template->assign_block_vars('exchange', array(
114
    'SYMBOL'          => $key,
115
    'TEXT'            => $value,
116
    'COURSE_DIRECT'   => HelperString::numberFormat($course, 4),
117
    'COURSE_REVERSE'  => HelperString::numberFormat(1 / $course, 4),
118
    'MM_PER_CURRENCY' => HelperString::numberFormat(sn_module_payment::currency_convert(1, $key, 'MM_'), 2),
119
    'LOT_PRICE'       => sn_module_payment::currency_convert(get_mm_cost(), 'MM_', $key),
120
    'DEFAULT'         => $key == SN::$config->payment_currency_default,
121
  ));
122
}
123
124
if ($request['metamatter'] && $payment_module_request && $payment_method_selected) {
125
  try {
126
    $paymentModuleReal = SN::$gc->modules->getModule($payment_module_request);
127
    if (!is_object($paymentModuleReal)) {
128
      throw new Exception('{ Менеджер модулей вернул null вместо платёжного модуля для }' . $payment_module_request, ERR_ERROR);
129
    }
130
131
    /**
132
     * @var sn_module_payment $paymentModuleReal
133
     */
134
    // Any possible errors about generating paylink should be raised in module!
135
    $pay_link = $paymentModuleReal->compile_request($request, $payment_method_selected);
0 ignored issues
show
Are you sure the assignment to $pay_link is correct as $paymentModuleReal->comp...ayment_method_selected) targeting sn_module_payment::compile_request() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
136
137
    // Поддержка дополнительной информации
138
    if (is_array($pay_link['RENDER'])) {
139
      foreach ($pay_link['RENDER'] as $html_data) {
140
        $template->assign_block_vars('render', $html_data);
141
        if (isset($html_data['VALUE']) && is_array($html_data['VALUE'])) {
142
          foreach ($html_data['VALUE'] as $value_id => $value_value) {
143
            $template->assign_block_vars('render.value', array(
144
              'FIELD' => $value_id,
145
              'VALUE' => $value_value,
146
            ));
147
          }
148
        }
149
      }
150
    }
151
152
    // Поддержка передачи данных для многошаговых платежных систем
153
    if (is_array($pay_link['DATA'])) {
154
      foreach ($pay_link['DATA'] as $key => $value) {
155
        $template->assign_block_vars('pay_link_data', array(
156
          'FIELD' => $key,
157
          'VALUE' => $value,
158
        ));
159
      }
160
    }
161
162
    if (is_array($pay_link) && in_array($pay_link['PAY_LINK_METHOD'], array('POST', 'GET', 'LINK', 'STEP', 'REDIRECT'))) {
0 ignored issues
show
The condition is_array($pay_link) is always false.
Loading history...
163
      if($pay_link['PAY_LINK_METHOD'] == 'REDIRECT') {
164
        sys_redirect($pay_link['PAY_LINK_URL']);
165
      }
166
167
      // TODO Переделать это под assign_vars_recursive и возвращать пустые строки если нет платежного метода - для унификации формы в темплейте
168
      $template->assign_vars(array(
169
        'PAY_LINK_METHOD' => $pay_link['PAY_LINK_METHOD'],
170
        'PAY_LINK_URL'    => $pay_link['PAY_LINK_URL'],
171
      ));
172
    } else {
173
      throw new exception(SN::$lang['pay_msg_request_paylink_unsupported'], ERR_ERROR);
174
    }
175
  } catch (exception $e) {
176
    $template->assign_block_vars('result', $response = array(
177
      'STATUS'  => $e->getCode(),
178
      'MESSAGE' => $e->getMessage(),
179
    ));
180
    $debug->warning('Результат операции: код ' . $e->getCode() . ' сообщение "' . $e->getMessage() . '"', 'Ошибка платежа', LOG_INFO_PAYMENT);
181
  }
182
}
183
184
// Прегенерированные пакеты
185
foreach ($unit_available_amount_list as $unit_amount => $discount) {
186
  $temp = sn_module_payment::currency_convert($unit_amount, 'MM_', $player_currency);
187
  $template->assign_block_vars('mm_amount', array(
188
    'VALUE'            => $unit_amount,
189
    // 'PRICE' => $temp,
190
    'PRICE_TEXT'       => HelperString::numberFormat($temp, 2),
191
    'CURRENCY'         => $player_currency,
192
    'DISCOUNT'         => $discount,
193
    'DISCOUNT_PERCENT' => $discount * 100,
194
    'DISCOUNTED'       => $unit_amount * (1 + $discount),
195
    'TEXT'             => HelperString::numberFloorAndFormat($unit_amount),
196
    'TEXT_DISCOUNTED'  => HelperString::numberFloorAndFormat($unit_amount * (1 + $discount)),
197
  ));
198
}
199
200
$currency               = PaymentMethods::getCurrencyFromMethod($payment_module_request, $payment_method_selected);
201
$bonus_percent          = round(sn_module_payment::bonus_calculate($request['metamatter'], true, true) * 100);
202
$income_metamatter_text = prettyNumberStyledDefault(sn_module_payment::bonus_calculate($request['metamatter']));
203
204
$approxCost = '';
205
if (!empty($payment_module_request) && !empty($payment_method_selected)) {
206
  $mod = SN::$gc->modules->getModule($payment_module_request);
207
208
  /**
209
   * @var sn_module_payment $mod
210
   */
211
  $tPrice = $mod->getPrice($payment_method_selected, $player_currency, $request['metamatter']);
0 ignored issues
show
$request['metamatter'] of type double is incompatible with the type integer expected by parameter $metamatter of sn_module_payment::getPrice(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

211
  $tPrice = $mod->getPrice($payment_method_selected, $player_currency, /** @scrutinizer ignore-type */ $request['metamatter']);
Loading history...
212
  if (!empty($tPrice) && is_array($tPrice)) {
213
    $approxCost = sprintf(
214
      SN::$lang['pay_mm_buy_approximate_cost'],
215
      HelperString::numberFormat($tPrice[$mod::FIELD_SUM], 2),
216
      $tPrice[$mod::FIELD_CURRENCY]
217
    );
218
  }
219
}
220
221
222
$template->assign_vars([
223
  'PAGE_HEADER' => SN::$lang['sys_metamatter'],
224
225
  'URL_PURCHASE' => SN::$config->url_purchase_metamatter,
226
227
  'PAYMENT_METHOD'      => $payment_method_selected,
228
  'PAYMENT_METHOD_NAME' => SN::$lang['pay_methods'][$payment_method_selected],
229
230
  'PAYMENT_MODULE'             => $payment_module_request,
231
  'PAYMENT_MODULE_NAME'        => SN::$lang["module_{$payment_module_request}_name"],
232
  'PAYMENT_MODULE_DESCRIPTION' => SN::$lang["module_{$payment_module_request}_description"],
233
234
  'PLAYER_CURRENCY'              => $player_currency,
235
  'PLAYER_CURRENCY_PRICE_PER_MM' => sn_module_payment::currency_convert(1, $player_currency, 'MM_', 10),
236
237
  'UNIT_AMOUNT'                 => (float)$request['metamatter'],
238
  'UNIT_AMOUNT_TEXT'            => HelperString::numberFloorAndFormat($request['metamatter']),
239
  'UNIT_AMOUNT_BONUS_PERCENT'   => $bonus_percent,
240
  'UNIT_AMOUNT_TEXT_DISCOUNTED' => $income_metamatter_text,
241
  'UNIT_AMOUNT_TEXT_COST_BASE'  => HelperString::numberFormat(sn_module_payment::currency_convert($request['metamatter'], 'MM_', $player_currency), 2),
242
243
  'PAYMENT_CURRENCY_EXCHANGE_DEFAULT' => prettyNumberStyledDefault(get_mm_cost()),
244
  'PAYMENT_CURRENCY_DEFAULT_TEXT'     => SN::$lang['pay_currency_list'][SN::$config->payment_currency_default],
245
246
  'METAMATTER' => mrc_get_level($user, '', RES_METAMATTER),
0 ignored issues
show
'' of type string is incompatible with the type array expected by parameter $planet of mrc_get_level(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

246
  'METAMATTER' => mrc_get_level($user, /** @scrutinizer ignore-type */ '', RES_METAMATTER),
Loading history...
247
248
  'METAMATTER_COST_TEXT'       => sprintf(SN::$lang['pay_mm_buy_conversion_cost'],
249
    prettyNumberStyledDefault($request['metamatter']),
250
    number_format($mmWish = sn_module_payment::currency_convert($request['metamatter'], 'MM_', $currency), 2, ',', '.'),
251
    $currency,
252
    prettyNumberGetClass($mmWish, true)),
253
  'METAMATTER_COST_BONUS_TEXT' => $bonus_percent
254
    ? sprintf(SN::$lang['pay_mm_buy_real_income'], prettyNumberStyledDefault($bonus_percent), $income_metamatter_text)
255
    : '',
256
257
  'METAMATTER_COST_ON_PAYMENT' => $approxCost,
258
259
  'DARK_MATTER_DESCRIPTION' => SN::$lang['info'][RES_DARK_MATTER]['description'],
260
261
  'PAYMENT_AVAILABLE' => SN::$gc->modules->countModulesInGroup('payment') && !SN_GOOGLE,
262
263
]);
264
265
$template->assign_recursive($template_result);
266
267
SnTemplate::display($template, SN::$lang['sys_metamatter']);
268