From 7a12e63eb3a3494c4027d48602a35c5451d50749 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 14 Jul 2024 07:25:38 +0300 Subject: [PATCH 1/4] add --- callback.php | 1 + classes/notifications.php | 4 ++-- classes/task/recurrent_payments.php | 6 +++--- lang/en/paygw_yookassa.php | 2 +- lang/ru/paygw_yookassa.php | 2 +- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/callback.php b/callback.php index e8f4528..a20ddec 100644 --- a/callback.php +++ b/callback.php @@ -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; diff --git a/classes/notifications.php b/classes/notifications.php index dde8510..e42ad09 100644 --- a/classes/notifications.php +++ b/classes/notifications.php @@ -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); diff --git a/classes/task/recurrent_payments.php b/classes/task/recurrent_payments.php index 1b29cdc..7124ba6 100644 --- a/classes/task/recurrent_payments.php +++ b/classes/task/recurrent_payments.php @@ -122,7 +122,7 @@ public function execute() { // 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; @@ -138,7 +138,7 @@ public function execute() { "description" => $invoice->description, "quantity" => 1, "amount" => [ - "value" => $payment->amount, + "value" => $cost, "currency" => $payment->currency, ], "vat_code" => $config->vatcode, @@ -181,7 +181,7 @@ public function execute() { $cost, $payment->currency, $data->paymentid, - 'Recurrent completed' + 'Recurrent created' ); } else { echo serialize($jsonresponse) . "\n"; diff --git a/lang/en/paygw_yookassa.php b/lang/en/paygw_yookassa.php index 4275fb8..e9c63bd 100644 --- a/lang/en/paygw_yookassa.php +++ b/lang/en/paygw_yookassa.php @@ -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'; diff --git a/lang/ru/paygw_yookassa.php b/lang/ru/paygw_yookassa.php index 28d59f9..c7e0e22 100644 --- a/lang/ru/paygw_yookassa.php +++ b/lang/ru/paygw_yookassa.php @@ -90,7 +90,7 @@ Следующий автоматический платёж назначен на {$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'; From 2612e0b009927dda49c132d8c6a8cede1dd7ceb9 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 14 Jul 2024 08:26:04 +0300 Subject: [PATCH 2/4] add --- classes/gateway.php | 21 +++++++++++++++++++++ lang/en/paygw_yookassa.php | 10 ++++++++++ lang/ru/paygw_yookassa.php | 14 ++++++++++++-- 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/classes/gateway.php b/classes/gateway.php index a0ad73e..e1e602e 100644 --- a/classes/gateway.php +++ b/classes/gateway.php @@ -118,6 +118,21 @@ public static function add_configuration_to_gateway_form(\core_payment\form\acco $mform->setType('recurrentperiod', PARAM_TEXT); $mform->hideIf('recurrentperiod', 'recurrent', "neq", 1); + $options = [ + 'fee' => get_string('recurrentcost1', 'paygw_yookassa'), + 'last' => 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->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')); @@ -235,5 +250,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'); + } } } diff --git a/lang/en/paygw_yookassa.php b/lang/en/paygw_yookassa.php index e9c63bd..4a6bf53 100644 --- a/lang/en/paygw_yookassa.php +++ b/lang/en/paygw_yookassa.php @@ -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:
+Paid - the one that was specified by the user when creating a regular payment.
+Item cost - the one specified in the settings of the payment module or course.
+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.'; diff --git a/lang/ru/paygw_yookassa.php b/lang/ru/paygw_yookassa.php index c7e0e22..e31e210 100644 --- a/lang/ru/paygw_yookassa.php +++ b/lang/ru/paygw_yookassa.php @@ -86,7 +86,7 @@ Если элемент курса недоступен, обратитесь в техподдержку сайта.'; $string['message_success_recurrent'] = 'Здравствуйте, {$a->firstname}! -Регулярная платёжная транзакция № {$a->orderid} на {$a->localizedcost} успешно создана. Спасибо за ваше пожертвование. +Регулярный платёж № {$a->orderid} на {$a->localizedcost} успешно создан и оплачен. Спасибо за ваше пожертвование. Следующий автоматический платёж назначен на {$a->nextpay}. Отключить регулярные платежи можно в разделе Отчёты (оплата) в личном профиле {$a->url}/user/profile.php'; @@ -96,7 +96,7 @@ $string['message_recurrent_error'] = 'Здравствуйте, {$a->firstname}! Регулярный платёж № {$a->orderid} на {$a->localizedcost} завершился с ошибкой. -Подписка была отключена, для возобновления подписки произведите новую оплату.'; +Подписка будет отключена, для возобновления подписки произведите новую оплату.'; $string['message_recurrent_notify'] = 'Здравствуйте, {$a->firstname}! Напоминаем о том, что приближается дата регулярного платежа № {$a->orderid} на {$a->localizedcost}. @@ -115,6 +115,16 @@ $string['recurrent_help'] = 'Регулярные (рекуррентные) платежи исполняются по таймеру без участия студента, данные первого платежа сохраняются на стороне банка и используются повторно, с некоторой периодичностью.'; $string['recurrentperiod'] = 'Периодичность регулярного платежа'; +$string['recurrentcost'] = 'Стоимость регулярного платежа'; +$string['recurrentcost_help'] = 'Указыввае какую цену брать при проведении регулярного платежа:
+Уплаченная - та, что была указана пользователем при создании регулярного платежа.
+Стоимость элемента - та, которая указана в настройках платёжного модуля или курса.
+Рекумендуемая - берётся из настроек этого интерфейса.'; +$string['recurrentcost1'] = 'Уплаченная'; +$string['recurrentcost2'] = 'Стоимость элемента'; +$string['recurrentcost3'] = 'Рекомендуемая цена'; +$string['suggesterror'] = 'Рекомендуемая цена должна быть указана для включенного регулярного платежа'; + $string['sendlinkmsg'] = 'Отправлять ссылку оплаты на почту'; $string['sendlinkmsg_help'] = 'Если включено, то ссылка на счёт для оплаты будет отправляться на почту пользователя.'; From a3ca91a0e5516b402fca6c09ea00b0e4b9e0fab1 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 14 Jul 2024 08:27:17 +0300 Subject: [PATCH 3/4] version --- README.md | 2 +- version.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3d58141..e90aadf 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ # YooKassa payment gateway plugin for Moodle. -Version 1.0 +Version 2.1 https://yookassa.ru diff --git a/version.php b/version.php index 4526a0f..bd3ce9f 100644 --- a/version.php +++ b/version.php @@ -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; From 0f65fa00ab057a9ded660eb10404b6b9f2e336d9 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 14 Jul 2024 08:46:06 +0300 Subject: [PATCH 4/4] add --- classes/gateway.php | 5 +++-- classes/task/recurrent_payments.php | 12 +++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/classes/gateway.php b/classes/gateway.php index e1e602e..2cb704c 100644 --- a/classes/gateway.php +++ b/classes/gateway.php @@ -119,8 +119,8 @@ public static function add_configuration_to_gateway_form(\core_payment\form\acco $mform->hideIf('recurrentperiod', 'recurrent', "neq", 1); $options = [ - 'fee' => get_string('recurrentcost1', 'paygw_yookassa'), - 'last' => get_string('recurrentcost2', 'paygw_yookassa'), + 'last' => get_string('recurrentcost1', 'paygw_yookassa'), + 'fee' => get_string('recurrentcost2', 'paygw_yookassa'), 'suggest' => get_string('recurrentcost3', 'paygw_yookassa'), ]; $mform->addElement( @@ -131,6 +131,7 @@ public static function add_configuration_to_gateway_form(\core_payment\form\acco ); $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'); diff --git a/classes/task/recurrent_payments.php b/classes/task/recurrent_payments.php index 7124ba6..441b96d 100644 --- a/classes/task/recurrent_payments.php +++ b/classes/task/recurrent_payments.php @@ -118,7 +118,17 @@ 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();