Skip to content

Commit 8e9db7f

Browse files
Payment plugin v1
Fully functional payment plugin
2 parents 47d3f3c + d3861ad commit 8e9db7f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+2757
-118
lines changed

.travis.yml

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
language: php
2+
3+
addons:
4+
postgresql: "9.6"
5+
6+
services:
7+
- mysql
8+
9+
cache:
10+
directories:
11+
- $HOME/.composer/cache
12+
- $HOME/.npm
13+
14+
dist: xenial
15+
16+
matrix:
17+
include:
18+
- php: 7.0
19+
env: DB=mysqli MOODLE_BRANCH=MOODLE_35_STABLE
20+
- php: 7.0
21+
env: DB=pgsql MOODLE_BRANCH=MOODLE_35_STABLE
22+
- php: 7.1
23+
env: DB=mysqli MOODLE_BRANCH=MOODLE_35_STABLE
24+
- php: 7.1
25+
env: DB=pgsql MOODLE_BRANCH=MOODLE_35_STABLE
26+
- php: 7.1
27+
env: DB=mysqli MOODLE_BRANCH=MOODLE_36_STABLE
28+
- php: 7.1
29+
env: DB=pgsql MOODLE_BRANCH=MOODLE_36_STABLE
30+
- php: 7.2
31+
env: DB=mysqli MOODLE_BRANCH=MOODLE_37_STABLE
32+
- php: 7.2
33+
env: DB=pgsql MOODLE_BRANCH=MOODLE_37_STABLE
34+
- php: 7.2
35+
env: DB=mysqli MOODLE_BRANCH=MOODLE_38_STABLE
36+
- php: 7.2
37+
env: DB=pgsql MOODLE_BRANCH=MOODLE_38_STABLE
38+
- php: 7.2
39+
env: DB=mysqli MOODLE_BRANCH=MOODLE_39_STABLE
40+
- php: 7.2
41+
env: DB=pgsql MOODLE_BRANCH=MOODLE_39_STABLE
42+
- php: 7.2
43+
env: DB=mysqli MOODLE_BRANCH=master
44+
- php: 7.2
45+
env: DB=pgsql MOODLE_BRANCH=master
46+
47+
before_install:
48+
- phpenv config-rm xdebug.ini
49+
- cd ../..
50+
- composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^3
51+
- export PATH="$(cd ci/bin; pwd):$(cd ci/vendor/bin; pwd):$PATH"
52+
53+
install:
54+
- moodle-plugin-ci add-plugin Peterburnett/QUTCapstone2020-enrol
55+
- moodle-plugin-ci install -vvv
56+
57+
script:
58+
- moodle-plugin-ci phplint
59+
- moodle-plugin-ci codechecker
60+
- moodle-plugin-ci validate
61+
- moodle-plugin-ci savepoints
62+
- moodle-plugin-ci mustache
63+
# Grunt task disabled due to bugs
64+
# - moodle-plugin-ci grunt
65+
- moodle-plugin-ci phpunit -vvv
66+
- moodle-plugin-ci behat

README.md

+87-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,87 @@
1-
# QUTCapstone2020
2-
Repository for the development of a payment gateway plugin for Moodle LMS.
1+
# QUTCapstone2020-Payment-Plugin
2+
3+
* [What is this?](#what-is-this)
4+
* [Why design a payment plugin?](#Why-design-a-payment-plugin)
5+
* [Repositories](#Repositories)
6+
* [Version requirement](#Version-requirement)
7+
* [Installation](#installation)
8+
* [How to use these plugins?](#How-to-use-these-plugins)
9+
* [PayPal payment gateway subplugin](#PayPal-payment-gateway-subplugin)
10+
* [Support](#Support)
11+
12+
## What is this?
13+
This is a moodle plugin which adds a Paypal/credit card payment gateway to your courses.
14+
15+
## Why design a payment plugin
16+
There are currently no easy to use payment plugins within the moodle plugin directory.
17+
Plugins that allow an admin to lock a course behind a payment already exist:
18+
19+
(Default moodle intergrated Paypal payment gateway) https://github.com/moodle/moodle/tree/master/enrol/paypal.
20+
21+
(Moodle payment software run through https://stripe.com) https://moodle.org/plugins/enrol_stripepayment.
22+
23+
However, the major difference between our software and the two examples listed above is the flexibility of our plugin.
24+
This plugin can accomodate for multiple payment gateways through the use of subplugins.
25+
26+
## Repositories
27+
There are currently two required repositories to make this plugin work.
28+
29+
The repository that is responsible for setting up the gate ways and managing all the data:
30+
31+
https://github.com/Peterburnett/QUTCapstone2020
32+
33+
The other repository responsible for displaying the website hook:
34+
35+
https://github.com/Peterburnett/QUTCapstone2020-enrol
36+
37+
## Version requirement
38+
39+
To run this plugin with the enrolment plugin (https://github.com/Peterburnett/QUTCapstone2020-enrol), the enrolement plugin need to be atleast at version 2020082600.
40+
The enrolment plugin requires a payment plugin version to be 2020042101+.
41+
42+
## Installation
43+
44+
Step 1: Installing the plugin
45+
-------------------------------
46+
Download the .zip file the from the `master` https://github.com/Peterburnett/QUTCapstone2020.
47+
48+
Extract this into /yourmoodle/admin/tool/paymentplugin/
49+
50+
Step 2: Installing the enrolment plugin
51+
-------------------------------
52+
Download the .zip file from the `master` https://github.com/Peterburnett/QUTCapstone2020-enrol.
53+
54+
Extract this into /yourmoodle/admin/enrol/payment
55+
56+
Step 3: Upgrading moodle
57+
-------------------------------
58+
Then run the moodle upgrade as normal.
59+
60+
https://docs.moodle.org/en/Installing_plugins
61+
62+
## How to use these plugins
63+
64+
1. Enable the enrolment plugin.
65+
2. Add an instance of the enrolment plugin to a course that will require payment.
66+
3. Set the course price from Course Administration -> Payment Settings.
67+
4. In the admin tool plugin settings, enable payment gateways that the students will be able to use.
68+
5. Change admin tool plugin settings and payment gateway subplugin settings as necessary.
69+
6. The course will now display a button to unenrolled students, redirecting them to a page where the course can be purchased through the payment gateways.
70+
71+
## PayPal payment gateway subplugin
72+
73+
The admin tool plugin comes with a PayPal subplugin pre-installed. This subplugin requires the admin to have a PayPal business account.
74+
75+
## Support
76+
77+
This plugin was developed by QUT MAHQ Developers as a Capstone project.
78+
Haruki Nakagawa - harukinn(at)icloud(dot)com
79+
Quyen Nguyen - qnguy29(at)gmail(dot)com
80+
Aaron Dang - aarondang(at)hotmail(dot)com
81+
Mitchell Halpin - mhalp1406 (at) gmail (dot) com
82+
83+
84+
With the support of Catalyst IT Australia:
85+
https://www.catalyst-au.net/
86+
87+
<img alt="Catalyst IT" src="https://cdn.rawgit.com/CatalystIT-AU/moodle-auth_saml2/master/pix/catalyst-logo.svg" width="400">

amd/build/purchase.min.js

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

amd/build/purchase.min.js.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

amd/src/purchase.js

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// This file is part of Moodle - http://moodle.org/
2+
//
3+
// Moodle is free software: you can redistribute it and/or modify
4+
// it under the terms of the GNU General Public License as published by
5+
// the Free Software Foundation, either version 3 of the License, or
6+
// (at your option) any later version.
7+
//
8+
// Moodle is distributed in the hope that it will be useful,
9+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
// GNU General Public License for more details.
12+
//
13+
// You should have received a copy of the GNU General Public License
14+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
15+
16+
/**
17+
* AJAX request for the purchase.php page.
18+
*
19+
* @package tool_paymentplugin
20+
* @module tool_paymentplugin/purchase
21+
* @author Haruki Nakagawa
22+
* @copyright 2020 MAHQ
23+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24+
*/
25+
26+
define(['core/ajax'], function(Ajax) {
27+
return {
28+
purchasecheck: function(courseid, userid, redirecturl) {
29+
var request = {
30+
methodname: 'tool_paymentplugin_check_enrolled',
31+
args: {
32+
courseid: courseid,
33+
userid: userid
34+
}
35+
};
36+
Ajax.call([request])[0].done(
37+
function(data) {
38+
if (data == true) {
39+
document.location = redirecturl;
40+
}
41+
}
42+
).fail();
43+
setInterval(this.purchasecheck, 10000, courseid, userid, redirecturl);
44+
}
45+
};
46+
});

classes/external/external.php

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php
2+
// This file is part of Moodle - http://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
17+
/**
18+
* External functions for tool_paymentplugin.
19+
*
20+
* @package tool_paymentplugin
21+
* @author Haruki Nakagawa
22+
* @copyright 2020 MAHQ
23+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24+
*/
25+
26+
namespace tool_paymentplugin\external;
27+
28+
defined('MOODLE_INTERNAL') || die();
29+
30+
use external_api;
31+
use external_function_parameters;
32+
use external_value;
33+
34+
require_once("$CFG->libdir/externallib.php");
35+
36+
class external extends external_api {
37+
38+
/**
39+
* Returns description of check_enrolled() parameters.
40+
* @return external_function_parameters
41+
*/
42+
public static function check_enrolled_parameters() {
43+
return new external_function_parameters(
44+
array(
45+
'courseid' => new external_value(PARAM_INT, 'id of course'),
46+
'userid' => new external_value(PARAM_INT, 'id of user')
47+
)
48+
);
49+
}
50+
51+
/**
52+
* Checks database to see if a user is enrolled in a course, and redirects the user if so.
53+
*
54+
* @param int $courseid
55+
* @param int $userid
56+
* @return bool
57+
*/
58+
public static function check_enrolled($courseid, $userid) {
59+
global $DB;
60+
61+
$params = self::validate_parameters(self::check_enrolled_parameters(), array(
62+
'courseid' => $courseid,
63+
'userid' => $userid
64+
));
65+
66+
$courseid = $params['courseid'];
67+
$userid = $params['userid'];
68+
69+
$query = "SELECT *
70+
FROM {user_enrolments}
71+
JOIN {enrol} ON {user_enrolments}.enrolid = {enrol}.id
72+
WHERE {enrol}.courseid = $courseid AND {user_enrolments}.userid = $userid";
73+
74+
$enrolled = $DB->record_exists_sql($query);
75+
return $enrolled;
76+
}
77+
78+
/**
79+
* Returns description of check_enrolled() return values.
80+
* @return external_value the value returned from the function.
81+
*/
82+
public static function check_enrolled_returns() {
83+
return new external_value(PARAM_BOOL, 'Whether the user is enrolled in the course.');
84+
}
85+
}

classes/form/course_settings.php

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
// This file is part of Moodle - http://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
17+
/**
18+
* Form for the course settings page.
19+
*
20+
* @package tool_paymentplugin
21+
* @author Mitchell Halpin
22+
* @author Haruki Nakagawa
23+
*
24+
* @copyright MAHQ
25+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26+
**/
27+
28+
namespace tool_paymentplugin\form;
29+
30+
defined('MOODLE_INTERNAL') || die();
31+
32+
require_once($CFG->libdir.'/formslib.php');
33+
34+
class course_settings extends \moodleform {
35+
36+
/**
37+
* Creates the form for course settings.
38+
*
39+
* @return void
40+
*/
41+
public function definition() {
42+
global $DB;
43+
44+
$mform = $this->_form;
45+
$courseid = $this->_customdata['id'];
46+
$mform->addElement('text', 'coursecost', 'Course Cost');
47+
$mform->setType('coursecost', PARAM_LOCALISEDFLOAT);
48+
$tablename = 'tool_paymentplugin_course';
49+
$cost = 0;
50+
51+
if ($DB->record_exists($tablename, ['courseid' => $courseid])) {
52+
$cost = $DB->get_field($tablename, 'cost', ['courseid' => $courseid]);
53+
}
54+
55+
$mform->setDefault('coursecost', $cost);
56+
$this->add_action_buttons(true);
57+
}
58+
59+
/**
60+
* Additional validation checks
61+
*
62+
* @return array of errors
63+
*/
64+
public function validation($data, $files) {
65+
$errors = parent::validation($data, $files);
66+
if ($data['coursecost'] < 0) {
67+
$errors['coursecost'] = get_string('errorcoursecost', 'tool_paymentplugin');
68+
}
69+
return $errors;
70+
}
71+
}

0 commit comments

Comments
 (0)