Skip to content

Commit

Permalink
add
Browse files Browse the repository at this point in the history
  • Loading branch information
Snickser committed Jul 15, 2024
1 parent 854f0ae commit e56f4b1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
18 changes: 16 additions & 2 deletions classes/gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,23 @@ public static function add_configuration_to_gateway_form(\core_payment\form\acco
$mform->setType('recurrent', PARAM_INT);
$mform->addHelpButton('recurrent', 'recurrent', 'paygw_yookassa');

$mform->addElement('duration', 'recurrentperiod', get_string('recurrentperiod', 'paygw_yookassa'));
$options = [0 => get_string('disable')];
for ($i = 1; $i <= 28; $i++) {
$options[] = $i;
}
$mform->addElement(
'select',
'recurrentday',
get_string('recurrentday', 'paygw_yookassa'),
$options,
);
$mform->setDefault('recurrentday', 1);
$mform->hideIf('recurrentday', 'recurrent', "neq", 1);

$mform->addElement('duration', 'recurrentperiod', get_string('recurrentperiod', 'paygw_yookassa'), ['optional' => false]);
$mform->setType('recurrentperiod', PARAM_INT);
$mform->hideIf('recurrentperiod', 'recurrent', "neq", 1);
$mform->hideIf('recurrentperiod', 'recurrentday', "neq", 0);

$options = [
'last' => get_string('recurrentcost1', 'paygw_yookassa'),
Expand Down Expand Up @@ -257,7 +271,7 @@ public static function validate_gateway_form(
if (!$data->suggest && $data->recurrentcost == 'suggest' && $data->recurrent) {
$errors['suggest'] = get_string('suggesterror', 'paygw_yookassa');
}
if (!$data->recurrentperiod && $data->recurrent) {
if (!$data->recurrentperiod && $data->recurrent && !$data->recurrentday) {
$errors['recurrentperiod'] = get_string('recurrentperioderror', 'paygw_yookassa');
}
}
Expand Down
6 changes: 6 additions & 0 deletions classes/task/recurrent_payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public function execute() {

// Stage Two.
$ctime = strtotime("+1hour");

$yookassatx = $DB->get_records_sql('SELECT * FROM {paygw_yookassa} WHERE (success=1 OR success=3) ' .
'AND recurrent>0 AND recurrent < ?', [ $ctime ]);

Expand All @@ -129,6 +130,11 @@ public function execute() {
$payable = helper::get_payable($component, $paymentarea, $itemid);
$surcharge = helper::get_gateway_surcharge('yookassa');// In case user uses surcharge.

if (date('d') != $config->recurrentday && $config->recurrentday > 0) {
mtrace("$data->paymentid too early");
continue;
}

switch ($config->recurrentcost) {
case 'suggest':
$cost = $config->suggest;
Expand Down
1 change: 1 addition & 0 deletions lang/en/paygw_yookassa.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
$string['recurrent_help'] = 'Enable recurring payments';
$string['recurrentperiod'] = 'Recurring payment frequency';
$string['recurrentperioderror'] = 'Specify the frequency. More than once a day - only for tests!';
$string['recurrentday'] = 'Day of payments';

$string['recurrentcost'] = 'Recurring payment cost';
$string['recurrentcost_help'] = 'Specify what price to charge when making a recurring payment:<br>
Expand Down
1 change: 1 addition & 0 deletions lang/ru/paygw_yookassa.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
$string['recurrent_help'] = 'Регулярные (рекуррентные) платежи исполняются по таймеру без участия студента, данные первого платежа сохраняются на стороне банка и используются повторно, с некоторой периодичностью.';
$string['recurrentperiod'] = 'Периодичность регулярного платежа';
$string['recurrentperioderror'] = 'Укажите периодичность. Чаще чем раз в день - только для тестов!';
$string['recurrentday'] = 'День ежемесячного платежа';

$string['recurrentcost'] = 'Стоимость регулярного платежа';
$string['recurrentcost_help'] = 'Указывает какую цену брать при проведении регулярного платежа:<br>
Expand Down

0 comments on commit e56f4b1

Please sign in to comment.