MDL-69166 core_payment: Add paymentarea to the payment subsystem
authorShamim Rezaie <shamim@moodle.com>
Fri, 2 Oct 2020 10:23:53 +0000 (20:23 +1000)
committerShamim Rezaie <shamim@moodle.com>
Tue, 27 Oct 2020 03:40:49 +0000 (14:40 +1100)
23 files changed:
enrol/fee/classes/payment/provider.php
enrol/fee/templates/payment_region.mustache
lib/db/install.xml
lib/db/upgrade.php
payment/amd/build/gateways_modal.min.js
payment/amd/build/gateways_modal.min.js.map
payment/amd/build/repository.min.js
payment/amd/build/repository.min.js.map
payment/amd/src/gateways_modal.js
payment/amd/src/repository.js
payment/classes/external/get_gateways_for_currency.php
payment/classes/helper.php
payment/classes/local/callback/provider.php
payment/gateway/paypal/amd/build/gateways_modal.min.js
payment/gateway/paypal/amd/build/gateways_modal.min.js.map
payment/gateway/paypal/amd/build/repository.min.js
payment/gateway/paypal/amd/build/repository.min.js.map
payment/gateway/paypal/amd/src/gateways_modal.js
payment/gateway/paypal/amd/src/repository.js
payment/gateway/paypal/classes/external/get_config_for_js.php
payment/gateway/paypal/classes/external/transaction_complete.php
payment/tests/accounts_test.php
payment/tests/generator/lib.php

index 2a6d43b..8edd405 100644 (file)
@@ -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);
@@ -54,11 +55,12 @@ class provider implements \core_payment\local\callback\provider {
     /**
      * 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);
index b1aa574..f39babe 100644 (file)
@@ -24,6 +24,7 @@
 
     Data attributes required for JS:
     * data-component
+    * data-paymentarea
     * data-componentid
     * data-cost
     * data-description
@@ -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 }}
index 187e8c7..5fbfe08 100755 (executable)
     <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"/>
         <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.">
index 20dc6ae..052e440 100644 (file)
@@ -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;
 }
index 2779809..ddfcd0e 100644 (file)
Binary files a/payment/amd/build/gateways_modal.min.js and b/payment/amd/build/gateways_modal.min.js differ
index 1a72198..a902861 100644 (file)
Binary files a/payment/amd/build/gateways_modal.min.js.map and b/payment/amd/build/gateways_modal.min.js.map differ
index 707571d..7e70376 100644 (file)
Binary files a/payment/amd/build/repository.min.js and b/payment/amd/build/repository.min.js differ
index 9995107..b764ceb 100644 (file)
Binary files a/payment/amd/build/repository.min.js.map and b/payment/amd/build/repository.min.js.map differ
index 8cb88ae..1dacc63 100644 (file)
@@ -94,6 +94,7 @@ const show = async(rootNode, {
             processPayment(
                 gateway,
                 rootNode.dataset.component,
+                rootNode.dataset.paymentarea,
                 rootNode.dataset.componentid,
                 rootNode.dataset.description,
                 ({success, message = ''}) => {
@@ -126,7 +127,8 @@ const show = async(rootNode, {
         }
     });
 
-    const gateways = await getGatewaysSupportingCurrency(rootNode.dataset.component, rootNode.dataset.componentid);
+    const gateways = await getGatewaysSupportingCurrency(rootNode.dataset.component, rootNode.dataset.paymentarea,
+        rootNode.dataset.componentid);
     const context = {
         gateways
     };
@@ -170,15 +172,16 @@ const updateCostRegion = async(root, defaultCost = '') => {
  * Process payment using the selected gateway.
  *
  * @param {string} gateway The gateway to be used for payment
- * @param {string} component Name of the component that the componentid belongs to
- * @param {number} componentid An internal identifier that is used by the component
+ * @param {string} component Name of the component that the componentId belongs to
+ * @param {string} paymentArea Name of the area in the component that the componentId belongs to
+ * @param {number} componentId An internal identifier that is used by the component
  * @param {string} description Description of the payment
  * @param {processPaymentCallback} callback The callback function to call when processing is finished
  * @returns {Promise<void>}
  */
-const processPayment = async(gateway, component, componentid, description, callback) => {
+const processPayment = async(gateway, component, paymentArea, componentId, description, callback) => {
     const paymentMethod = await import(`pg_${gateway}/gateways_modal`);
-    paymentMethod.process(component, componentid, description, callback);
+    paymentMethod.process(component, paymentArea, componentId, description, callback);
 };
 
 /**
index 5199c33..d81c79a 100644 (file)
@@ -27,16 +27,18 @@ import Ajax from 'core/ajax';
 /**
  * Returns the list of gateways that can process payments in the given currency.
  *
- * @param {String} component
- * @param {Integer} componentid
+ * @param {string} component
+ * @param {string} paymentArea
+ * @param {number} componentId
  * @returns {Promise<{shortname: string, name: string, description: String}[]>}
  */
-export const getGatewaysSupportingCurrency = (component, componentid) => {
+export const getGatewaysSupportingCurrency = (component, paymentArea, componentId) => {
     const request = {
         methodname: 'core_payment_get_gateways_for_currency',
         args: {
             component,
-            componentid
+            paymentarea: paymentArea,
+            componentid: componentId,
         }
     };
     return Ajax.call([request])[0];
index 30df0b9..6a3c822 100644 (file)
@@ -43,35 +43,38 @@ class get_gateways_for_currency extends external_api {
      * @return external_function_parameters
      */
     public static function execute_parameters(): external_function_parameters {
-        return new external_function_parameters(
-                ['component' => new external_value(PARAM_COMPONENT, 'Component'),
-                    'componentid' => new external_value(PARAM_INT, 'Component id')]
-        );
+        return new external_function_parameters([
+            'component' => new external_value(PARAM_COMPONENT, 'Component'),
+            'paymentarea' => new external_value(PARAM_AREA, 'Payment area in the component'),
+            'componentid' => new external_value(PARAM_INT, 'An identifier for payment area in the component')
+        ]);
     }
 
     /**
      * Returns the list of gateways that can process payments in the given currency.
      *
      * @param string $component
+     * @param string $paymentarea
      * @param int $componentid
      * @return \stdClass[]
      */
-    public static function execute(string $component, int $componentid): array {
+    public static function execute(string $component, string $paymentarea, int $componentid): array {
 
         $params = external_api::validate_parameters(self::execute_parameters(), [
             'component' => $component,
+            'paymentarea' => $paymentarea,
             'componentid' => $componentid,
         ]);
 
         $list = [];
-        $gateways = \core_payment\helper::get_gateways_for_currency($params['component'], $params['componentid']);
+        $gateways = helper::get_gateways_for_currency($params['component'], $params['paymentarea'], $params['componentid']);
         [
             'amount' => $amount,
             'currency' => $currency
-        ] = \core_payment\helper::get_cost($params['component'], $params['componentid']);
+        ] = helper::get_cost($params['component'], $params['paymentarea'], $params['componentid']);
 
         foreach ($gateways as $gateway) {
-            $surcharge = \core_payment\helper::get_gateway_surcharge($gateway);
+            $surcharge = helper::get_gateway_surcharge($gateway);
             $list[] = (object)[
                 'shortname' => $gateway,
                 'name' => get_string('gatewayname', 'pg_' . $gateway),
index 13fbe46..fe12f80 100644 (file)
@@ -63,17 +63,18 @@ class helper {
      * Returns the list of gateways that can process payments in the given currency.
      *
      * @param string $component
+     * @param string $paymentarea
      * @param int $componentid
      * @return string[]
      */
-    public static function get_gateways_for_currency(string $component, int $componentid): array {
+    public static function get_gateways_for_currency(string $component, string $paymentarea, int $componentid): array {
         $gateways = [];
 
         [
             'amount' => $amount,
             'currency' => $currency,
             'accountid' => $accountid,
-        ] = self::get_cost($component, $componentid);
+        ] = self::get_cost($component, $paymentarea, $componentid);
         $account = new account($accountid);
         if (!$account->get('id') || !$account->get('enabled')) {
             return $gateways;
@@ -141,20 +142,22 @@ class helper {
      * Returns the attributes to place on a pay button.
      *
      * @param string $component Name of the component that the componentid belongs to
+     * @param string $paymentarea
      * @param int $componentid An internal identifier that is used by the component
      * @param string $description Description of the payment
      * @return array
      */
-    public static function gateways_modal_link_params(string $component, int $componentid, string $description): array {
+    public static function gateways_modal_link_params(string $component, string $paymentarea, int $componentid, string $description): array {
         [
             'amount' => $amount,
             'currency' => $currency
-        ] = self::get_cost($component, $componentid);
+        ] = self::get_cost($component, $paymentarea, $componentid);
 
         return [
             'id' => 'gateways-modal-trigger',
             'role' => 'button',
             'data-component' => $component,
+            'data-paymentarea' => $paymentarea,
             'data-componentid' => $componentid,
             'data-cost' => self::get_cost_as_string($amount, $currency),
             'data-description' => $description,
@@ -165,12 +168,13 @@ class helper {
      * Asks the cost from the related component.
      *
      * @param string $component Name of the component that the componentid belongs to
+     * @param string $paymentarea
      * @param int $componentid An internal identifier that is used by the component
      * @return array['amount' => float, 'currency' => string, 'accountid' => int]
      * @throws \moodle_exception
      */
-    public static function get_cost(string $component, int $componentid): array {
-        $cost = component_class_callback("$component\\payment\\provider", 'get_cost', [$componentid]);
+    public static function get_cost(string $component, string $paymentarea, int $componentid): array {
+        $cost = component_class_callback("$component\\payment\\provider", 'get_cost', [$paymentarea, $componentid]);
 
         if ($cost === null || !is_array($cost) || !array_key_exists('amount', $cost)
                 || !array_key_exists('currency', $cost) || !array_key_exists('accountid', $cost) ) {
@@ -184,13 +188,15 @@ class helper {
      * Returns the gateway configuration for given component and gateway
      *
      * @param string $component
+     * @param string $paymentarea
      * @param int $componentid
      * @param string $gatewayname
      * @return array
      * @throws \moodle_exception
      */
-    public static function get_gateway_configuration(string $component, int $componentid, string $gatewayname): array {
-        $x = self::get_cost($component, $componentid);
+    public static function get_gateway_configuration(string $component, string $paymentarea, int $componentid,
+            string $gatewayname): array {
+        $x = self::get_cost($component, $paymentarea, $componentid);
         $gateway = null;
         $account = new account($x['accountid']);
         if ($account && $account->get('enabled')) {
@@ -208,12 +214,14 @@ class helper {
      * @uses \core_payment\local\callback\provider::deliver_order()
      *
      * @param string $component Name of the component that the componentid belongs to
+     * @param string $paymentarea
      * @param int $componentid An internal identifier that is used by the component
      * @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(string $component, int $componentid, int $paymentid): bool {
-        $result = component_class_callback("$component\\payment\\provider", 'deliver_order', [$componentid, $paymentid]);
+    public static function deliver_order(string $component, string $paymentarea, int $componentid, int $paymentid): bool {
+        $result = component_class_callback("$component\\payment\\provider", 'deliver_order',
+                [$paymentarea, $componentid, $paymentid]);
 
         if ($result === null) {
             throw new \moodle_exception('callbacknotimplemented', 'core_payment', '', $component);
@@ -228,6 +236,7 @@ class helper {
      *
      * @param int $accountid Account id
      * @param string $component Name of the component that the componentid belongs to
+     * @param string $paymentarea
      * @param int $componentid An internal identifier that is used by the component
      * @param int $userid Id of the user who is paying
      * @param float $amount Amount of payment
@@ -235,12 +244,13 @@ class helper {
      * @param string $gateway The gateway that is used for the payment
      * @return int
      */
-    public static function save_payment(int $accountid, string $component, int $componentid, int $userid, float $amount, string $currency,
-            string $gateway): int {
+    public static function save_payment(int $accountid, string $component, string $paymentarea, int $componentid, int $userid,
+            float $amount, string $currency, string $gateway): int {
         global $DB;
 
         $record = new \stdClass();
         $record->component = $component;
+        $record->paymentarea = $paymentarea;
         $record->componentid = $componentid;
         $record->userid = $userid;
         $record->amount = $amount;
index 1e247ce..e4c3b5a 100644 (file)
@@ -37,15 +37,17 @@ defined('MOODLE_INTERNAL') || die();
 interface provider {
 
     /**
-     * @param int $identifier An identifier that is known to the plugin
+     * @param string $paymentarea
+     * @param int $componentid An identifier that is known to the plugin
      * @return array['amount' => float, 'currency' => string, 'accountid' => int]
      */
-    public static function get_cost(int $identifier): array;
+    public static function get_cost(string $paymentarea, int $componentid): array;
 
     /**
+     * @param string $paymentarea
      * @param int $componentid An identifier that is known to the plugin
      * @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 $componentid, int $paymentid): bool;
+    public static function deliver_order(string $paymentarea, int $componentid, int $paymentid): bool;
 }
index 1993d1f..ddeb503 100644 (file)
Binary files a/payment/gateway/paypal/amd/build/gateways_modal.min.js and b/payment/gateway/paypal/amd/build/gateways_modal.min.js differ
index 4c8f59d..afd4b9d 100644 (file)
Binary files a/payment/gateway/paypal/amd/build/gateways_modal.min.js.map and b/payment/gateway/paypal/amd/build/gateways_modal.min.js.map differ
index b4dc13f..d0cc2e9 100644 (file)
Binary files a/payment/gateway/paypal/amd/build/repository.min.js and b/payment/gateway/paypal/amd/build/repository.min.js differ
index e5b95ef..0c7f8d1 100644 (file)
Binary files a/payment/gateway/paypal/amd/build/repository.min.js.map and b/payment/gateway/paypal/amd/build/repository.min.js.map differ
index eab6336..9858b63 100644 (file)
@@ -45,20 +45,21 @@ const showModalWithPlaceholder = async() => {
 /**
  * Process the payment.
  *
- * @param {string} component Name of the component that the componentid belongs to
- * @param {number} componentid An internal identifier that is used by the component
+ * @param {string} component Name of the component that the componentId belongs to
+ * @param {string} paymentArea The area of the component that the componentId belongs to
+ * @param {number} componentId An internal identifier that is used by the component
  * @param {string} description Description of the payment
  * @param {processCallback} callback The callback function to call when processing is finished
  * @returns {Promise<void>}
  */
-export const process = async(component, componentid, description, callback) => {
+export const process = async(component, paymentArea, componentId, description, callback) => {
 
     const [
         modal,
         paypalConfig,
     ] = await Promise.all([
         showModalWithPlaceholder(),
-        Repository.getConfigForJs(component, componentid),
+        Repository.getConfigForJs(component, paymentArea, componentId),
     ]);
     const currency = paypalConfig.currency;
     const amount = paypalConfig.cost; // Cost with surcharge.
@@ -104,7 +105,8 @@ export const process = async(component, componentid, description, callback) => {
                     methodname: 'pg_paypal_create_transaction_complete',
                     args: {
                         component,
-                        componentid,
+                        paymentarea: paymentArea,
+                        componentid: componentId,
                         orderid: data.orderID,
                     },
                 }])[0]
index fff839a..50cfc41 100644 (file)
@@ -27,12 +27,19 @@ import Ajax from 'core/ajax';
 /**
  * Return the PayPal JavaScript SDK URL.
  *
- * @returns {Promise<{clientid: String, brandname: String}>}
+ * @param {string} component Name of the component that the componentid belongs to
+ * @param {string} paymentArea The area of the component that the componentid belongs to
+ * @param {number} componentId An internal identifier that is used by the component
+ * @returns {Promise<{clientid: string, brandname: string}>}
  */
-export const getConfigForJs = (component, componentid) => {
+export const getConfigForJs = (component, paymentArea, componentId) => {
     const request = {
         methodname: 'pg_paypal_get_config_for_js',
-        args: {component, componentid},
+        args: {
+            component,
+            paymentarea: paymentArea,
+            componentid: componentId,
+        },
     };
 
     return Ajax.call([request])[0];
index 1347842..a467f92 100644 (file)
@@ -45,24 +45,29 @@ class get_config_for_js extends external_api {
      */
     public static function execute_parameters(): external_function_parameters {
         return new external_function_parameters([
-            'component' => new external_value(PARAM_COMPONENT, ''),
-            'componentid' => new external_value(PARAM_INT, ''),
+            'component' => new external_value(PARAM_COMPONENT, 'Component'),
+            'paymentarea' => new external_value(PARAM_AREA, 'Payment area in the component'),
+            'componentid' => new external_value(PARAM_INT, 'An identifier for payment area in the component'),
         ]);
     }
 
     /**
-     * Returns the full URL of the PayPal JavaScript SDK.
+     * Returns the config values required by the PayPal JavaScript SDK.
      *
+     * @param string $component
+     * @param string $paymentarea
+     * @param int $componentid
      * @return string[]
      */
-    public static function execute($component, $componentid): array {
+    public static function execute(string $component, string $paymentarea, int $componentid): array {
         self::validate_parameters(self::execute_parameters(), [
             'component' => $component,
+            'paymentarea' => $paymentarea,
             'componentid' => $componentid,
         ]);
 
-        $config = helper::get_gateway_configuration($component, $componentid, 'paypal');
-        $cost = helper::get_cost($component, $componentid);
+        $config = helper::get_gateway_configuration($component, $paymentarea, $componentid, 'paypal');
+        $cost = helper::get_cost($component, $paymentarea, $componentid);
         $surcharge = helper::get_gateway_surcharge('paypal');
 
         return [
index 56016a8..9186b6f 100644 (file)
@@ -47,7 +47,8 @@ class transaction_complete extends external_api {
     public static function execute_parameters() {
         return new external_function_parameters([
             'component' => new external_value(PARAM_COMPONENT, 'The component name'),
-            'componentid' => new external_value(PARAM_INT, 'The item id in the context of the component'),
+            'paymentarea' => new external_value(PARAM_AREA, 'Payment area in the component'),
+            'componentid' => new external_value(PARAM_INT, 'The item id in the context of the component area'),
             'orderid' => new external_value(PARAM_TEXT, 'The order id coming back from PayPal'),
         ]);
     }
@@ -57,27 +58,29 @@ class transaction_complete extends external_api {
      * This function does not take cost as a parameter as we cannot rely on any provided value.
      *
      * @param string $component Name of the component that the componentid belongs to
+     * @param string $paymentarea
      * @param int $componentid An internal identifier that is used by the component
      * @param string $orderid PayPal order ID
      * @return array
      */
-    public static function execute(string $component, int $componentid, string $orderid): array {
+    public static function execute(string $component, string $paymentarea, int $componentid, string $orderid): array {
         global $USER, $DB;
 
         self::validate_parameters(self::execute_parameters(), [
             'component' => $component,
+            'paymentarea' => $paymentarea,
             'componentid' => $componentid,
             'orderid' => $orderid,
         ]);
 
-        $config = (object)helper::get_gateway_configuration($component, $componentid, 'paypal');
+        $config = (object)helper::get_gateway_configuration($component, $paymentarea, $componentid, 'paypal');
         $sandbox = $config->environment == 'sandbox';
 
         [
             'amount' => $amount,
             'currency' => $currency,
             'accountid' => $accountid,
-        ] = payment_helper::get_cost($component, $componentid);
+        ] = payment_helper::get_cost($component, $paymentarea, $componentid);
 
         // Add surcharge if there is any.
         $surcharge = helper::get_gateway_surcharge('paypal');
@@ -99,8 +102,8 @@ class transaction_complete extends external_api {
                         $success = true;
                         // Everything is correct. Let's give them what they paid for.
                         try {
-                            $paymentid = payment_helper::save_payment((int)$accountid, $component, $componentid, (int) $USER->id,
-                                $amount, $currency, 'paypal');
+                            $paymentid = payment_helper::save_payment((int) $accountid, $component, $paymentarea, $componentid,
+                                (int) $USER->id, $amount, $currency, 'paypal');
 
                             // Store PayPal extra information.
                             $record = new \stdClass();
@@ -109,7 +112,7 @@ class transaction_complete extends external_api {
 
                             $DB->insert_record('pg_paypal', $record);
 
-                            payment_helper::deliver_order($component, $componentid, $paymentid);
+                            payment_helper::deliver_order($component, $paymentarea, $componentid, $paymentid);
                         } catch (\Exception $e) {
                             debugging('Exception while trying to process payment: ' . $e->getMessage(), DEBUG_DEVELOPER);
                             $success = false;
index 318850c..d273441 100644 (file)
@@ -118,8 +118,8 @@ class accounts_testcase extends advanced_testcase {
         // Delete account with payments - it will be archived.
         $this->setAdminUser();
         $account = helper::save_payment_account((object)['name' => 'Test 1', 'idnumber' => '']);
-        $DB->insert_record('payments', ['accountid' => $account->get('id'), 'component' => 'test', 'componentid' => 1,
-            'userid' => $USER->id]);
+        $DB->insert_record('payments', ['accountid' => $account->get('id'), 'component' => 'test', 'paymentarea' => 'test',
+            'componentid' => 1, 'userid' => $USER->id]);
         helper::delete_payment_account(account::get_record(['id' => $account->get('id')]));
         $this->assertEquals(1, $DB->get_field('payment_accounts', 'archived', ['id' => $account->get('id')]));
 
index 8048827..2cf19a1 100644 (file)
@@ -70,11 +70,12 @@ class core_payment_generator extends component_generator_base {
             $data['gateway'] = reset($gateways);
         }
 
-        $id = $DB->insert_record('payments', $data +
-            ['component' => 'testcomponent',
-                'componentarea' => 'teatarea',
-                'componentid' => 0,
-                'currency' => 'AUD']);
+        $id = $DB->insert_record('payments', $data + [
+            'component' => 'testcomponent',
+            'paymentarea' => 'teatarea',
+            'componentid' => 0,
+            'currency' => 'AUD'
+        ]);
         return $id;
     }