Skip to content

Commit

Permalink
Merge pull request #50 from Snickser/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Snickser authored Jul 14, 2024
2 parents 6e2ced4 + 0f65fa0 commit 9e1d024
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# YooKassa payment gateway plugin for Moodle.

Version 1.0
Version 2.1

https://yookassa.ru

Expand Down
1 change: 1 addition & 0 deletions callback.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
$yookassatx->paymentid = $newpaymentid;
$yookassatx->timecreated = time();
$yookassatx->id = $DB->insert_record('paygw_yookassa', $yookassatx);
$reason = 'Success completed';
} else {
// Update payment.
$payment->amount = $outsumm;
Expand Down
22 changes: 22 additions & 0 deletions classes/gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,22 @@ public static function add_configuration_to_gateway_form(\core_payment\form\acco
$mform->setType('recurrentperiod', PARAM_TEXT);
$mform->hideIf('recurrentperiod', 'recurrent', "neq", 1);

$options = [
'last' => get_string('recurrentcost1', 'paygw_yookassa'),
'fee' => get_string('recurrentcost2', 'paygw_yookassa'),
'suggest' => get_string('recurrentcost3', 'paygw_yookassa'),
];
$mform->addElement(
'select',
'recurrentcost',
get_string('recurrentcost', 'paygw_yookassa'),
$options,
);
$mform->setType('recurrentcost', PARAM_TEXT);
$mform->addHelpButton('recurrentcost', 'recurrentcost', 'paygw_yookassa');
$mform->setDefault('recurrentcost', 'fee');
$mform->hideIf('recurrentcost', 'recurrent', "neq", 1);

$plugininfo = \core_plugin_manager::instance()->get_plugin_info('report_payments');
if ($plugininfo->versiondisk < 3024070800) {
$mform->addElement('static', 'noreport', null, get_string('noreportplugin', 'paygw_yookassa'));
Expand Down Expand Up @@ -235,5 +251,11 @@ public static function validate_gateway_form(
if ($data->enabled && empty($data->shopid)) {
$errors['enabled'] = get_string('gatewaycannotbeenabled', 'payment');
}
if ($data->maxcost && $data->maxcost < $data->suggest) {
$errors['maxcost'] = get_string('maxcosterror', 'paygw_yookassa');
}
if (!$data->suggest && $data->recurrentcost == 'suggest' && $data->recurrent) {
$errors['suggest'] = get_string('suggesterror', 'paygw_yookassa');
}
}
}
4 changes: 2 additions & 2 deletions classes/notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ public static function notify($userid, $fee, $currency, $orderid, $type = '', $n
case 'Success recurrent':
$messagebody = get_string('message_success_recurrent', 'paygw_yookassa', $a);
break;
case 'Recurrent completed':
$messagebody = get_string('message_recurrent_completed', 'paygw_yookassa', $a);
case 'Recurrent created':
$messagebody = get_string('message_recurrent_created', 'paygw_yookassa', $a);
break;
case 'Recurrent error':
$messagebody = get_string('message_recurrent_error', 'paygw_yookassa', $a);
Expand Down
18 changes: 14 additions & 4 deletions classes/task/recurrent_payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,21 @@ public function execute() {
$config = (object) helper::get_gateway_configuration($component, $paymentarea, $itemid, 'yookassa');
$payable = helper::get_payable($component, $paymentarea, $itemid);
$surcharge = helper::get_gateway_surcharge('yookassa');// In case user uses surcharge.
$cost = helper::get_rounded_cost($payable->get_amount(), $payable->get_currency(), $surcharge);

switch ($config->recurrentcost) {
case 'suggest':
$cost = $config->suggest;
break;
case 'last':
$cost = $payment->amount;
break;
default:
$cost = helper::get_rounded_cost($payable->get_amount(), $payable->get_currency(), $surcharge);
}

// Make invoice.
$invoice = new \stdClass();
$invoice->amount = [ "value" => $payment->amount, "currency" => $payment->currency ];
$invoice->amount = [ "value" => $cost, "currency" => $payment->currency ];
$invoice->capture = "true";
$invoice->payment_method_id = $data->invoiceid;
$invoice->description = "Recurrent payment " . $data->paymentid;
Expand All @@ -138,7 +148,7 @@ public function execute() {
"description" => $invoice->description,
"quantity" => 1,
"amount" => [
"value" => $payment->amount,
"value" => $cost,
"currency" => $payment->currency,
],
"vat_code" => $config->vatcode,
Expand Down Expand Up @@ -181,7 +191,7 @@ public function execute() {
$cost,
$payment->currency,
$data->paymentid,
'Recurrent completed'
'Recurrent created'
);
} else {
echo serialize($jsonresponse) . "\n";
Expand Down
12 changes: 11 additions & 1 deletion lang/en/paygw_yookassa.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
You transaction of payment id {$a->orderid} with cost of {$a->fee} {$a->currency} for "{$a->description}" is successfully completed.
If the item is not accessable please contact the administrator.';

$string['message_recurrent_completed'] = 'Hello, {$a->firstname}!
$string['message_recurrent_created'] = 'Hello, {$a->firstname}!
Regular payment No. {$a->orderid} at {$a->localizedcost} is ready for payment.
You can disable regular payments in the Reports (payment) section in your personal profile {$a->$url}/user/profile.php';

Expand Down Expand Up @@ -122,6 +122,16 @@
$string['recurrent_help'] = 'Enable recurring payments';
$string['recurrentperiod'] = 'Recurring payment frequency';

$string['recurrentcost'] = 'Recurring payment cost';
$string['recurrentcost_help'] = 'Specify what price to charge when making a recurring payment:<br>
Paid - the one that was specified by the user when creating a regular payment.<br>
Item cost - the one specified in the settings of the payment module or course.<br>
Recommended - taken from the settings of this interface.';
$string['recurrentcost1'] = 'Paid';
$string['recurrentcost2'] = 'Item cost';
$string['recurrentcost3'] = 'Recommended price';
$string['suggesterror'] = 'Suggested price must be for recurring payment enabled';

$string['sendlinkmsg'] = 'Send payment link by email';
$string['sendlinkmsg_help'] = 'If enabled, a link to the invoice for payment will be sent to the users email.';

Expand Down
16 changes: 13 additions & 3 deletions lang/ru/paygw_yookassa.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,17 @@
Если элемент курса недоступен, обратитесь в техподдержку сайта.';

$string['message_success_recurrent'] = 'Здравствуйте, {$a->firstname}!
Регулярная платёжная транзакция № {$a->orderid} на {$a->localizedcost} успешно создана. Спасибо за ваше пожертвование.
Регулярный платёж № {$a->orderid} на {$a->localizedcost} успешно создан и оплачен. Спасибо за ваше пожертвование.
Следующий автоматический платёж назначен на {$a->nextpay}.
Отключить регулярные платежи можно в разделе Отчёты (оплата) в личном профиле {$a->url}/user/profile.php';

$string['message_recurrent_completed'] = 'Здравствуйте, {$a->firstname}!
$string['message_recurrent_created'] = 'Здравствуйте, {$a->firstname}!
Регулярный платёж № {$a->orderid} на {$a->localizedcost} создан и передан в банк.
Отключить регулярные платежи можно в разделе Отчёты (оплата) в личном профиле {$a->url}/user/profile.php';

$string['message_recurrent_error'] = 'Здравствуйте, {$a->firstname}!
Регулярный платёж № {$a->orderid} на {$a->localizedcost} завершился с ошибкой.
Подписка была отключена, для возобновления подписки произведите новую оплату.';
Подписка будет отключена, для возобновления подписки произведите новую оплату.';

$string['message_recurrent_notify'] = 'Здравствуйте, {$a->firstname}!
Напоминаем о том, что приближается дата регулярного платежа № {$a->orderid} на {$a->localizedcost}.
Expand All @@ -115,6 +115,16 @@
$string['recurrent_help'] = 'Регулярные (рекуррентные) платежи исполняются по таймеру без участия студента, данные первого платежа сохраняются на стороне банка и используются повторно, с некоторой периодичностью.';
$string['recurrentperiod'] = 'Периодичность регулярного платежа';

$string['recurrentcost'] = 'Стоимость регулярного платежа';
$string['recurrentcost_help'] = 'Указыввае какую цену брать при проведении регулярного платежа:<br>
Уплаченная - та, что была указана пользователем при создании регулярного платежа.<br>
Стоимость элемента - та, которая указана в настройках платёжного модуля или курса.<br>
Рекумендуемая - берётся из настроек этого интерфейса.';
$string['recurrentcost1'] = 'Уплаченная';
$string['recurrentcost2'] = 'Стоимость элемента';
$string['recurrentcost3'] = 'Рекомендуемая цена';
$string['suggesterror'] = 'Рекомендуемая цена должна быть указана для включенного регулярного платежа';

$string['sendlinkmsg'] = 'Отправлять ссылку оплаты на почту';
$string['sendlinkmsg_help'] = 'Если включено, то ссылка на счёт для оплаты будет отправляться на почту пользователя.';

Expand Down
4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2024071300;
$plugin->version = 2024071400;
$plugin->requires = 2023100900;
$plugin->component = 'paygw_yookassa';
$plugin->release = '1.0';
$plugin->release = '2.1';
$plugin->maturity = MATURITY_STABLE;

0 comments on commit 9e1d024

Please sign in to comment.