forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-69166 core_payment: Addressing various integration points
- Add help for 'payment account' field in the enrol instance form - Remove MOODLE_INTERNALs when not necessary - Add $userid to deliver_order - Check if provider classes implement the provider interface - Rename get_cost to get_payable - get_payable returns payable object - Improve registerEventListeners and added init - Rename payment\provider to payment\service_provider
- Loading branch information
Showing
16 changed files
with
174 additions
and
92 deletions.
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 |
---|---|---|
|
@@ -31,25 +31,22 @@ | |
* @copyright 2020 Shamim Rezaie <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class provider implements \core_payment\local\callback\provider { | ||
class service_provider implements \core_payment\local\callback\service_provider { | ||
|
||
/** | ||
* Callback function that returns the enrolment cost for the course that $instanceid enrolment instance belongs to. | ||
* Callback function that returns the enrolment cost and the accountid | ||
* for the course that $instanceid enrolment instance belongs to. | ||
* | ||
* @param string $paymentarea | ||
* @param int $instanceid The enrolment instance id | ||
* @return array['amount' => float, 'currency' => string, 'accountid' => int] | ||
* @return \core_payment\local\entities\payable | ||
*/ | ||
public static function get_cost(string $paymentarea, int $instanceid): array { | ||
public static function get_payable(string $paymentarea, int $instanceid): \core_payment\local\entities\payable { | ||
global $DB; | ||
|
||
$instance = $DB->get_record('enrol', ['enrol' => 'fee', 'id' => $instanceid], '*', MUST_EXIST); | ||
|
||
return [ | ||
'amount' => (float) $instance->cost, | ||
'currency' => $instance->currency, | ||
'accountid' => $instance->customint1, | ||
]; | ||
return new \core_payment\local\entities\payable($instance->cost, $instance->currency, $instance->customint1); | ||
} | ||
|
||
/** | ||
|
@@ -58,10 +55,11 @@ public static function get_cost(string $paymentarea, int $instanceid): array { | |
* @param string $paymentarea | ||
* @param int $instanceid The enrolment instance id | ||
* @param int $paymentid payment id as inserted into the 'payments' table, if needed for reference | ||
* @param int $userid The userid the order is going to deliver to | ||
* @return bool Whether successful or not | ||
*/ | ||
public static function deliver_order(string $paymentarea, int $instanceid, int $paymentid): bool { | ||
global $DB, $USER; | ||
public static function deliver_order(string $paymentarea, int $instanceid, int $paymentid, int $userid): bool { | ||
global $DB; | ||
|
||
$instance = $DB->get_record('enrol', ['enrol' => 'fee', 'id' => $instanceid], '*', MUST_EXIST); | ||
|
||
|
@@ -75,7 +73,7 @@ public static function deliver_order(string $paymentarea, int $instanceid, int $ | |
$timeend = 0; | ||
} | ||
|
||
$plugin->enrol_user($instance, $USER->id, $instance->roleid, $timestart, $timeend); | ||
$plugin->enrol_user($instance, $userid, $instance->roleid, $timestart, $timeend); | ||
|
||
return true; | ||
} | ||
|
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
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
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.