Skip to content

Commit

Permalink
Merge pull request #33 from Snickser/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Snickser authored May 9, 2024
2 parents c947799 + b0ac5fa commit 49a027a
Show file tree
Hide file tree
Showing 7 changed files with 191 additions and 44 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# PayAnyWay payment gateway plugin for Moodle.

Version 0.7
Version 0.8

https://payanyway.ru

Expand All @@ -12,6 +12,16 @@ https://payanyway.ru

[![Build Status](https://github.com/Snickser/moodle-paygw_payanyway/actions/workflows/moodle-ci.yml/badge.svg)](https://github.com/Snickser/moodle-paygw_payanyway/actions/workflows/moodle-ci.yml)

## Возможности

+ Можно использовать пароль или кнопку для обхода платежа.
+ Сохраняет в базе номер курса и название группы студента.
+ Можно указать рекомендуемую цену.
+ Можно ограничить максимальную цену.
+ Отображение продолжительности обучения (для enrol_fee и mod_gwpaymets), если она установлена.
+ Оповещение пользователя при успешном платеже.


## Рекомендации

+ Moodle 4.3+
Expand Down
12 changes: 11 additions & 1 deletion callback.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@
*/

use core_payment\helper;
use paygw_payanyway\notifications;

require("../../../config.php");

global $CFG, $USER, $DB;

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

$transactionid = required_param('MNT_TRANSACTION_ID', PARAM_TEXT);
$transactionid = required_param('MNT_TRANSACTION_ID', PARAM_INT);
$operationid = required_param('MNT_OPERATION_ID', PARAM_TEXT);
$subscriberid = required_param('MNT_SUBSCRIBER_ID', PARAM_TEXT);
$signature = required_param('MNT_SIGNATURE', PARAM_TEXT);
Expand Down Expand Up @@ -66,6 +67,15 @@
// Deliver.
helper::deliver_order($component, $paymentarea, $itemid, $paymentid, $userid);

// Notify user.
notifications::notify(
$userid,
$payment->amount,
$payment->currency,
$paymentid,
'Success completed'
);

// Check test-mode.
if ($config->mnttestmode) {
$payanywaytx->success = 3;
Expand Down
92 changes: 92 additions & 0 deletions classes/notifications.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/** Notifications for paygw_payanyway.
*
* @package paygw_payanyway
* @copyright 2024 Alex Orlov <snickser@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace paygw_payanyway;

/** Notifications class.
*
* Handle notifications for users about their transactions.
*
* @package paygw_payanyway
* @copyright 2024 Alex Orlov <snickser@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class notifications {
/**
* Function that handle the notifications about transactions using payanyway payment gateway
* and all kinds of responses.
*
* this function sending the message to the user and return the id of the message if needed
* or false in case of error.
*
* @param int $userid
* @param float $fee
* @param string $currency
* @param int $orderid
* @param string $type
* @return int|false
*/
public static function notify($userid, $fee, $currency, $orderid, $type = '') {
global $DB;

// Get the user object for messaging and fullname.
$user = \core_user::get_user($userid);
if (empty($user) || isguestuser($user) || !empty($user->deleted)) {
return false;
}

// Set the object wiht all informations to notify the user.
$a = (object)[
'fee' => $fee, // The original cost.
'currency' => $currency,
'orderid' => $orderid,
'fullname' => fullname($user),
'firstname' => $user->firstname,
];

$message = new \core\message\message();
$message->component = 'paygw_payanyway';
$message->name = 'payment_receipt'; // The notification name from message.php.
$message->userfrom = \core_user::get_noreply_user(); // If the message is 'from' a specific user you can set them here.
$message->userto = $user;
$message->subject = get_string('messagesubject', 'paygw_payanyway', $type);
switch ($type) {
case 'Success completed':
$messagebody = get_string('message_success_completed', 'paygw_payanyway', $a);
break;
}

$message->fullmessage = $messagebody;
$message->fullmessageformat = FORMAT_MARKDOWN;
$message->fullmessagehtml = "<p>$messagebody</p>";
$message->notification = 1; // Because this is a notification generated from Moodle, not a user-to-user message.
$message->contexturl = ''; // A relevant URL for the notification.
$message->contexturlname = ''; // Link title explaining where users get to for the contexturl.
$content = ['*' => ['header' => '', 'footer' => '']]; // Extra content for specific processor.
$message->set_additional_content('email', $content);

// Actually send the message.
$messageid = message_send($message);

return $messageid;
}
}
29 changes: 29 additions & 0 deletions db/messages.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Defines message providers for payanyway payment gateway.
*
* @package paygw_payanyway
* @copyright 2024 Alex Orlov <snickser@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

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

$messageproviders = [
'payment_receipt' => [],
];
42 changes: 24 additions & 18 deletions lang/en/paygw_payanyway.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,37 +21,37 @@
* @copyright 2024 Alex Orlov <snickser@gmail.com>
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['pluginname'] = 'PayAnyWay payment';
$string['pluginname_desc'] = 'The PayAnyWay plugin allows you to receive payments via PayAnyWay.';
$string['abouttopay'] = 'You are about to pay for';
$string['callback'] = 'Callback URL:';
$string['callback_help'] = 'Copy this and put it in callback URLs at your PayAnyWay account.';
$string['fixdesc'] = 'Fixed payment comment';
$string['fixdesc_help'] = 'This setting sets a fixed comment for all payments.';
$string['gatewaydescription'] = 'PayAnyWay is an authorised payment gateway provider for processing credit card transactions.';
$string['gatewayname'] = 'PayAnyWay';
$string['mntid'] = 'Account number';
$string['maxcost'] = 'Maximium cost';
$string['mntdataintegritycode'] = 'Code of data integrity verification';
$string['mntid'] = 'Account number';
$string['mnttestmode'] = 'Test mode';
$string['paymentserver'] = 'Payment server URL';
$string['callback'] = 'Callback URL:';
$string['callback_help'] = 'Copy this and put it in callback URLs at your PayAnyWay account.';
$string['paymore'] = 'If you want to donate more, simply enter your amount instead of the indicated amount.';
$string['sendpaymentbutton'] = 'Send payment via PayAnyWay';
$string['abouttopay'] = 'You are about to pay for';
$string['payment'] = 'Donation';
$string['password'] = 'Password';
$string['passwordmode'] = 'Password';
$string['password_error'] = 'Invalid payment password';
$string['password_help'] = 'Using this password you can bypass the payback process. It can be useful when it is not possible to make a payment.';
$string['password_success'] = 'Payment password accepted';
$string['password_text'] = 'If you are unable to make a payment, then ask your curator for a password and enter it.';
$string['payment_success'] = 'Payment Successful';
$string['passwordmode'] = 'Password';
$string['payment'] = 'Donation';
$string['payment_error'] = 'Payment Error';
$string['password_success'] = 'Payment password accepted';
$string['password_error'] = 'Invalid payment password';
$string['payment_success'] = 'Payment Successful';
$string['paymentserver'] = 'Payment server URL';
$string['paymore'] = 'If you want to donate more, simply enter your amount instead of the indicated amount.';
$string['pluginname'] = 'PayAnyWay payment';
$string['pluginname_desc'] = 'The PayAnyWay plugin allows you to receive payments via PayAnyWay.';
$string['sendpaymentbutton'] = 'Send payment via PayAnyWay';
$string['paymore'] = 'If you want to donate more, simply enter your amount instead of the indicated amount.';
$string['suggest'] = 'Suggested cost';
$string['maxcost'] = 'Maximium cost';
$string['skipmode'] = 'Can skip payment';
$string['skipmode_help'] = 'This setting allows a payment bypass button, which can be useful in public courses with optional payment.';
$string['skipmode_text'] = 'If you are not able to make a donation through the payment system, you can click on this button.';
$string['skippaymentbutton'] = 'Skip payment :(';
$string['fixdesc'] = 'Fixed payment comment';
$string['fixdesc_help'] = 'This setting sets a fixed comment for all payments.';
$string['suggest'] = 'Suggested cost';
$string['usedetails'] = 'Make it collapsible';
$string['usedetails_help'] = 'Display a button or password in a collapsed block.';
$string['usedetails_text'] = 'Click here if you are unable to donate.';
Expand Down Expand Up @@ -99,3 +99,9 @@
$string['privacy:metadata:paygw_payanyway:courceid'] = 'Cource id';
$string['privacy:metadata:paygw_payanyway:groupnames'] = 'Group names';
$string['privacy:metadata:paygw_payanyway:success'] = 'Status';

$string['messagesubject'] = 'Payment notification';
$string['message_success_completed'] = 'Hello {$a->firstname},
You transaction of payment id {$a->orderid} with cost of {$a->fee} {$a->currency} is successfully completed.
If the item is not accessable please contact the administrator.';
$string['messageprovider:payment_receipt'] = 'Payment receipt';
44 changes: 22 additions & 22 deletions lang/ru/paygw_payanyway.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,37 +24,37 @@

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

$string['sendpaymentbutton'] = 'Пожертвовать!';
$string['paymore'] = 'Если вы хотите пожертвовать больше, то просто впишите свою сумму вместо указанной.';
$string['payment'] = 'Пожертвование';
$string['abouttopay'] = 'Вы собираетесь пожертвовать на';
$string['pluginname'] = 'Платежи PayAnyWay';
$string['pluginname_desc'] = 'Плагин PayAnyWay позволяет получать платежи через PayAnyWay.';
$string['gatewaydescription'] = 'PayAnyWay — авторизованный платежный шлюз для обработки транзакций по кредитным картам.';
$string['cost'] = 'Стоимость записи';
$string['currency'] = 'Валюта';
$string['callback'] = 'Callback URL:';
$string['callback_help'] = 'Copy this and put it in callback URLs at your PayAnyWay account.';
$string['paymentserver'] = 'URL сервера оплаты';
$string['mntid'] = 'Номер счета';
$string['cost'] = 'Стоимость записи';
$string['currency'] = 'Валюта';
$string['fixdesc'] = 'Фиксированный комментарий платежа';
$string['fixdesc_help'] = 'Эта настройка устанавливает фиксированный комментарий для всех платежей, и отключает отображение описания комментария на странице платежа.';
$string['gatewaydescription'] = 'PayAnyWay — авторизованный платежный шлюз для обработки транзакций по кредитным картам.';
$string['maxcost'] = 'Максимальная цена';
$string['mntdataintegritycode'] = 'Код проверки целостности данных';
$string['payment_success'] = 'Оплата успешно произведена';
$string['payment_error'] = 'Ошибка оплаты';
$string['suggest'] = 'Рекомендуемая цена';
$string['password_success'] = 'Платёжный пароль принят';
$string['mntid'] = 'Номер счета';
$string['mnttestmode'] = 'Тестовый режим';
$string['password'] = 'Резервный пароль';
$string['password_error'] = 'Введён неверный платёжный пароль';
$string['maxcost'] = 'Максимальная цена';
$string['password_help'] = 'С помощью этого пароля можно обойти процесс отплаты. Может быть полезен когда нет возможности произвести оплату.';
$string['password_success'] = 'Платёжный пароль принят';
$string['password_text'] = 'Если у вас нет возможности сделать пожертвование, то попросите у вашего куратора пароль и введите его.';
$string['passwordmode'] = 'Разрешить ввод резервного пароля';
$string['payment'] = 'Пожертвование';
$string['payment_error'] = 'Ошибка оплаты';
$string['payment_success'] = 'Оплата успешно произведена';
$string['paymentserver'] = 'URL сервера оплаты';
$string['paymore'] = 'Если вы хотите пожертвовать больше, то просто впишите свою сумму вместо указанной.';
$string['pluginname'] = 'Платежи PayAnyWay';
$string['pluginname_desc'] = 'Плагин PayAnyWay позволяет получать платежи через PayAnyWay.';
$string['sendpaymentbutton'] = 'Пожертвовать!';
$string['skipmode'] = 'Показать кнопку обхода платежа';
$string['skipmode_help'] = 'Эта настройка разрешает кнопку обхода платежа, может быть полезна в публичных курсах с необязательной оплатой.';
$string['skipmode_text'] = 'Если вы не имеете возможности совершить пожертвование через платёжную систему то можете нажать на эту кнопку.';
$string['skippaymentbutton'] = 'Не имею :(';
$string['mnttestmode'] = 'Тестовый режим';
$string['password'] = 'Резервный пароль';
$string['passwordmode'] = 'Разрешить ввод резервного пароля';
$string['password_help'] = 'С помощью этого пароля можно обойти процесс отплаты. Может быть полезен когда нет возможности произвести оплату.';
$string['password_text'] = 'Если у вас нет возможности сделать пожертвование, то попросите у вашего куратора пароль и введите его.';
$string['fixdesc'] = 'Фиксированный комментарий платежа';
$string['fixdesc_help'] = 'Эта настройка устанавливает фиксированный комментарий для всех платежей, и отключает отображение описания комментария на странице платежа.';
$string['suggest'] = 'Рекомендуемая цена';
$string['usedetails'] = 'Показывать свёрнутым';
$string['usedetails_help'] = 'Прячет кнопку или пароль под сворачиваемый блок, если они включены.';
$string['usedetails_text'] = 'Нажмите тут если у вас нет возможности совершить пожертвование';
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 = 2024050300;
$plugin->version = 2024050900;
$plugin->requires = 2023100900;
$plugin->component = 'paygw_payanyway';
$plugin->release = '0.7';
$plugin->release = '0.8';
$plugin->maturity = MATURITY_STABLE;

0 comments on commit 49a027a

Please sign in to comment.