Skip to content

Commit

Permalink
MDL-69166 core_payment: Add paymentarea to the payment subsystem
Browse files Browse the repository at this point in the history
  • Loading branch information
rezaies committed Oct 27, 2020
1 parent 409857a commit 61766b3
Show file tree
Hide file tree
Showing 23 changed files with 158 additions and 73 deletions.
6 changes: 4 additions & 2 deletions enrol/fee/classes/payment/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ class provider implements \core_payment\local\callback\provider {
/**
* Callback function that returns the enrolment cost 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]
*/
public static function get_cost(int $instanceid): array {
public static function get_cost(string $paymentarea, int $instanceid): array {
global $DB;

$instance = $DB->get_record('enrol', ['enrol' => 'fee', 'id' => $instanceid], '*', MUST_EXIST);
Expand All @@ -54,11 +55,12 @@ public static function get_cost(int $instanceid): array {
/**
* Callback function that delivers what the user paid for to them.
*
* @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
* @return bool Whether successful or not
*/
public static function deliver_order(int $instanceid, int $paymentid): bool {
public static function deliver_order(string $paymentarea, int $instanceid, int $paymentid): bool {
global $DB, $USER;

$instance = $DB->get_record('enrol', ['enrol' => 'fee', 'id' => $instanceid], '*', MUST_EXIST);
Expand Down
2 changes: 2 additions & 0 deletions enrol/fee/templates/payment_region.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
Data attributes required for JS:
* data-component
* data-paymentarea
* data-componentid
* data-cost
* data-description
Expand Down Expand Up @@ -58,6 +59,7 @@
type="button"
id="gateways-modal-trigger-{{ uniqid }}"
data-component="enrol_fee"
data-paymentarea="fee"
data-componentid="{{instanceid}}"
data-cost="{{cost}}"
data-description={{# quote }}{{description}}{{/ quote }}
Expand Down
6 changes: 3 additions & 3 deletions lib/db/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4321,7 +4321,8 @@
<TABLE NAME="payments" COMMENT="Stores information about payments">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="component" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="component" TYPE="char" LENGTH="100" NOTNULL="true" SEQUENCE="false" COMMENT="The plugin this payment belongs to."/>
<FIELD NAME="paymentarea" TYPE="char" LENGTH="50" NOTNULL="true" SEQUENCE="false" COMMENT="The name of payable area"/>
<FIELD NAME="componentid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="amount" TYPE="char" LENGTH="20" NOTNULL="true" SEQUENCE="false"/>
Expand All @@ -4337,9 +4338,8 @@
<KEY NAME="accountid" TYPE="foreign" FIELDS="accountid" REFTABLE="payment_accounts" REFFIELDS="id"/>
</KEYS>
<INDEXES>
<INDEX NAME="component" UNIQUE="false" FIELDS="component"/>
<INDEX NAME="componentid" UNIQUE="false" FIELDS="componentid"/>
<INDEX NAME="gateway" UNIQUE="false" FIELDS="gateway"/>
<INDEX NAME="component-paymentarea-componentid" UNIQUE="false" FIELDS="component, paymentarea, componentid"/>
</INDEXES>
</TABLE>
<TABLE NAME="infected_files" COMMENT="Table to store infected file details.">
Expand Down
43 changes: 43 additions & 0 deletions lib/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2974,5 +2974,48 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2021052500.26);
}

if ($oldversion < 2021052500.27) {

// Define field paymentarea to be added to payments.
$table = new xmldb_table('payments');
$field = new xmldb_field('paymentarea', XMLDB_TYPE_CHAR, '50', null, XMLDB_NOTNULL, null, null, 'component');

// Conditionally launch add field paymentarea.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}

// Define index component (not unique) to be dropped form payments.
$table = new xmldb_table('payments');
$index = new xmldb_index('component', XMLDB_INDEX_NOTUNIQUE, ['component']);

// Conditionally launch drop index component.
if ($dbman->index_exists($table, $index)) {
$dbman->drop_index($table, $index);
}

// Define index componentid (not unique) to be dropped form payments.
$table = new xmldb_table('payments');
$index = new xmldb_index('componentid', XMLDB_INDEX_NOTUNIQUE, ['componentid']);

// Conditionally launch drop index componentid.
if ($dbman->index_exists($table, $index)) {
$dbman->drop_index($table, $index);
}

// Define index component-paymentarea-componentid (not unique) to be added to payments.
$table = new xmldb_table('payments');
$index = new xmldb_index('component-paymentarea-componentid', XMLDB_INDEX_NOTUNIQUE,
['component', 'paymentarea', 'componentid']);

// Conditionally launch add index component-paymentarea-componentid.
if (!$dbman->index_exists($table, $index)) {
$dbman->add_index($table, $index);
}

// Main savepoint reached.
upgrade_main_savepoint(true, 2021052500.27);
}

return true;
}
2 changes: 1 addition & 1 deletion payment/amd/build/gateways_modal.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 61766b3

Please sign in to comment.