-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Snickser/dev
Dev
- Loading branch information
Showing
23 changed files
with
1,456 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
name: Moodle Plugin CI | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-22.04 | ||
|
||
services: | ||
postgres: | ||
image: postgres:13 | ||
env: | ||
POSTGRES_USER: 'postgres' | ||
POSTGRES_HOST_AUTH_METHOD: 'trust' | ||
ports: | ||
- 5432:5432 | ||
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 3 | ||
|
||
mariadb: | ||
image: mariadb:10 | ||
env: | ||
MYSQL_USER: 'root' | ||
MYSQL_ALLOW_EMPTY_PASSWORD: "true" | ||
MYSQL_CHARACTER_SET_SERVER: "utf8mb4" | ||
MYSQL_COLLATION_SERVER: "utf8mb4_unicode_ci" | ||
ports: | ||
- 3306:3306 | ||
options: --health-cmd="mysqladmin ping" --health-interval 10s --health-timeout 5s --health-retries 3 | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
php: ['8.0', '8.1'] | ||
moodle-branch: ['MOODLE_403_STABLE'] | ||
database: [pgsql, mariadb] | ||
|
||
steps: | ||
- name: Check out repository code | ||
uses: actions/checkout@v4 | ||
with: | ||
path: plugin | ||
|
||
- name: Setup PHP ${{ matrix.php }} | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php }} | ||
extensions: ${{ matrix.extensions }} | ||
ini-values: max_input_vars=5000 | ||
# If you are not using code coverage, keep "none". Otherwise, use "pcov" (Moodle 3.10 and up) or "xdebug". | ||
# If you try to use code coverage with "none", it will fallback to phpdbg (which has known problems). | ||
coverage: none | ||
|
||
- name: Initialise moodle-plugin-ci | ||
run: | | ||
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^4 | ||
echo $(cd ci/bin; pwd) >> $GITHUB_PATH | ||
echo $(cd ci/vendor/bin; pwd) >> $GITHUB_PATH | ||
sudo locale-gen en_AU.UTF-8 | ||
echo "NVM_DIR=$HOME/.nvm" >> $GITHUB_ENV | ||
- name: Install moodle-plugin-ci | ||
run: moodle-plugin-ci install --plugin ./plugin --db-host=127.0.0.1 | ||
env: | ||
DB: ${{ matrix.database }} | ||
MOODLE_BRANCH: ${{ matrix.moodle-branch }} | ||
# Uncomment this to run Behat tests using the Moodle App. | ||
# MOODLE_APP: 'true' | ||
|
||
- name: PHP Lint | ||
if: ${{ !cancelled() }} | ||
run: moodle-plugin-ci phplint | ||
|
||
- name: PHP Mess Detector | ||
continue-on-error: true # This step will show errors but will not fail | ||
if: ${{ !cancelled() }} | ||
run: moodle-plugin-ci phpmd | ||
|
||
- name: Moodle Code Checker | ||
if: ${{ !cancelled() }} | ||
run: moodle-plugin-ci phpcs --max-warnings 1 | ||
|
||
- name: Moodle PHPDoc Checker | ||
if: ${{ !cancelled() }} | ||
run: moodle-plugin-ci phpdoc --max-warnings 0 | ||
|
||
- name: Validating | ||
if: ${{ !cancelled() }} | ||
run: moodle-plugin-ci validate | ||
|
||
- name: Check upgrade savepoints | ||
if: ${{ !cancelled() }} | ||
run: moodle-plugin-ci savepoints | ||
|
||
- name: Mustache Lint | ||
if: ${{ !cancelled() }} | ||
run: moodle-plugin-ci mustache | ||
|
||
- name: Grunt | ||
if: ${{ !cancelled() }} | ||
run: moodle-plugin-ci grunt --max-lint-warnings 0 | ||
|
||
- name: PHPUnit tests | ||
if: ${{ !cancelled() }} | ||
run: moodle-plugin-ci phpunit --fail-on-warning | ||
|
||
- name: Behat features | ||
id: behat | ||
if: ${{ !cancelled() }} | ||
run: moodle-plugin-ci behat --profile chrome | ||
|
||
- name: Upload Behat Faildump | ||
if: ${{ failure() && steps.behat.outcome == 'failure' }} | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: Behat Faildump (${{ join(matrix.*, ', ') }}) | ||
path: ${{ github.workspace }}/moodledata/behat_dump | ||
retention-days: 7 | ||
if-no-files-found: ignore | ||
|
||
- name: Mark cancelled jobs as failed. | ||
if: ${{ cancelled() }} | ||
run: exit 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,46 @@ | ||
# moodle-paygw_payeer | ||
[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://paypal.me/snickser) support me with a donation. | ||
|
||
# Payeer payment gateway plugin for Moodle. | ||
|
||
Version 0.1 | ||
|
||
https://payeer.com | ||
|
||
![alt text](https://raw.githubusercontent.com/Snickser/moodle-paygw_payeer/pix/img.svg) | ||
|
||
## Status | ||
|
||
[![Build Status](https://github.com/Snickser/moodle-paygw_payeer/actions/workflows/moodle-ci.yml/badge.svg)](https://github.com/Snickser/moodle-paygw_payeer/actions/workflows/moodle-ci.yml) | ||
|
||
## Возможности | ||
|
||
+ Можно использовать пароль или кнопку для обхода платежа. | ||
+ Сохраняет в базе номер курса и название группы студента. | ||
+ Можно указать рекомендуемую цену. | ||
+ Можно ограничить максимальную цену. | ||
+ Отображение продолжительности обучения (для enrol_fee и mod_gwpaymets), если она установлена. | ||
+ Поддержка пароля из модуля курса (mod_gwpaymets). | ||
+ Оповещение пользователя при успешном платеже. | ||
|
||
|
||
## Рекомендации | ||
|
||
+ Moodle 4.3+ | ||
+ Для записи в курс подходит стандарный плагин "Зачисление за оплату" (enrol_fee). | ||
+ Для контрольного задания используйте модуль "[Gateway Payments](https://moodle.org/plugins/mod_gwpayments)" (мои правки [mod_gwpayments](https://github.com/Snickser/moodle-mod_gwpayments/tree/dev)), он правда глючный, но других пока нет. | ||
+ Для ограничения доступности используйте модуль "[PaymentS availability condition for paid access](https://moodle.org/plugins/availability_gwpayments)" (мои правки [availability_gwpayments](https://github.com/Snickser/moodle-availability_gwpayments/tree/dev)). | ||
|
||
|
||
## INSTALLATION | ||
|
||
Download the latest **paygw_payeer.zip** and unzip the contents into the **/payment/gateway** directory. Or upload it from Moodle plugins adminnistration interface.<br> | ||
|
||
1. Install the plugin | ||
2. Enable the payeer payment gateway | ||
3. Create a new payment account | ||
4. Configure the payment account against the payeer gateway using your pay ID | ||
5. Enable the 'Enrolment on Payment' enrolment method | ||
6. Add the 'Enrolment on Payment' method to your chosen course | ||
7. Set the payment account, enrolment fee, and currency | ||
|
||
This plugin supports only basic functionality, but everything changes someday... |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// 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/>. | ||
|
||
/** | ||
* This module is responsible for PayNL content in the gateways modal. | ||
* | ||
* @module paygw_payeer/gateways_modal | ||
* @copyright 2024 Alex Orlov <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
import Templates from 'core/templates'; | ||
import Modal from 'core/modal'; | ||
|
||
/** | ||
* Show modal with the PayNL placeholder. | ||
* | ||
* @returns {Promise} | ||
*/ | ||
|
||
const showModalWithPlaceholder = async() => { | ||
const modal = await Modal.create({ | ||
body: await Templates.render('paygw_payeer/button_placeholder', {}), | ||
show: true, | ||
removeOnClose: true, | ||
}); | ||
modal.destroy(); | ||
}; | ||
|
||
|
||
/** | ||
* Process. | ||
* | ||
* @param {String} component | ||
* @param {String} paymentArea | ||
* @param {String} itemId | ||
* @param {String} description | ||
* @returns {Promise<>} | ||
*/ | ||
export const process = (component, paymentArea, itemId, description) => { | ||
return showModalWithPlaceholder() | ||
.then(() => { | ||
location.href = M.cfg.wwwroot + '/payment/gateway/payeer/method.php?' + | ||
'sesskey=' + M.cfg.sesskey + | ||
'&component=' + component + | ||
'&paymentarea=' + paymentArea + | ||
'&itemid=' + itemId + | ||
'&description=' + description; | ||
return new Promise(() => null); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?php | ||
// This file is part of Moodle - https://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 <https://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* Plugin administration pages are defined here. | ||
* | ||
* @package paygw_payeer | ||
* @copyright 2024 Alex Orlov <[email protected]> | ||
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
use core_payment\helper; | ||
use paygw_payeer\notifications; | ||
|
||
require("../../../config.php"); | ||
global $CFG, $USER, $DB; | ||
|
||
require_once($CFG->libdir . '/filelib.php'); | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
$status = required_param('m_status', PARAM_TEXT); | ||
$amount = required_param('m_amount', PARAM_FLOAT); | ||
$currency = required_param('m_curr', PARAM_TEXT); | ||
$orderid = required_param('m_orderid', PARAM_INT); | ||
$signature = required_param('m_sign', PARAM_TEXT); | ||
|
||
$arhash = [ | ||
$_POST['m_operation_id'], | ||
$_POST['m_operation_ps'], | ||
$_POST['m_operation_date'], | ||
$_POST['m_operation_pay_date'], | ||
$_POST['m_shop'], | ||
$orderid, | ||
$amount, | ||
$currency, | ||
$_POST['m_desc'], | ||
$status, | ||
]; | ||
|
||
if ($status !== 'success') { | ||
die('FAIL. Payment not successed.'); | ||
} | ||
|
||
if (!$payeertx = $DB->get_record('paygw_payeer', [ 'paymentid' => $orderid ])) { | ||
die('FAIL. Not a valid transaction.'); | ||
} | ||
|
||
if (!$payment = $DB->get_record('payments', ['id' => $payeertx->paymentid])) { | ||
die('FAIL. Not a valid payment.'); | ||
} | ||
$component = $payment->component; | ||
$paymentarea = $payment->paymentarea; | ||
$itemid = $payment->itemid; | ||
$paymentid = $payment->id; | ||
$userid = $payment->userid; | ||
|
||
// Get apikey and secretkey. | ||
$config = (object) helper::get_gateway_configuration($component, $paymentarea, $itemid, 'payeer'); | ||
|
||
$arhash[] = $config->apikey; | ||
|
||
$signhash = strtoupper(hash('sha256', implode(':', $arhash))); | ||
|
||
if ($signature !== $signhash) { | ||
die('FAIL. Signature error.'); | ||
} | ||
|
||
// Update payment. | ||
$payment->amount = $amount; | ||
$DB->update_record('payments', $payment); | ||
|
||
// Deliver order. | ||
helper::deliver_order($component, $paymentarea, $itemid, $paymentid, $userid); | ||
|
||
// Notify user. | ||
notifications::notify( | ||
$userid, | ||
$payment->amount, | ||
$payment->currency, | ||
$paymentid, | ||
'Success completed' | ||
); | ||
|
||
// Update paygw. | ||
$payeertx->success = 1; | ||
if (!$DB->update_record('paygw_payeer', $payeertx)) { | ||
die('FAIL. Update db error.'); | ||
} else { | ||
die($paymentid . '|success'); | ||
} |
Oops, something went wrong.