MDL-69166 pg_paypal: WS and AMD to return some settings to be used in js
authorShamim Rezaie <shamim@moodle.com>
Tue, 29 Sep 2020 11:21:33 +0000 (21:21 +1000)
committerShamim Rezaie <shamim@moodle.com>
Mon, 26 Oct 2020 21:37:08 +0000 (08:37 +1100)
payment/gateway/paypal/amd/build/repository.min.js [new file with mode: 0644]
payment/gateway/paypal/amd/build/repository.min.js.map [new file with mode: 0644]
payment/gateway/paypal/amd/src/repository.js [new file with mode: 0644]
payment/gateway/paypal/classes/external/get_config_for_js.php [new file with mode: 0644]
payment/gateway/paypal/db/services.php [new file with mode: 0644]
payment/gateway/paypal/lang/en/pg_paypal.php
payment/gateway/paypal/settings.php

diff --git a/payment/gateway/paypal/amd/build/repository.min.js b/payment/gateway/paypal/amd/build/repository.min.js
new file mode 100644 (file)
index 0000000..16eb7ec
Binary files /dev/null and b/payment/gateway/paypal/amd/build/repository.min.js differ
diff --git a/payment/gateway/paypal/amd/build/repository.min.js.map b/payment/gateway/paypal/amd/build/repository.min.js.map
new file mode 100644 (file)
index 0000000..ac239cd
Binary files /dev/null and b/payment/gateway/paypal/amd/build/repository.min.js.map differ
diff --git a/payment/gateway/paypal/amd/src/repository.js b/payment/gateway/paypal/amd/src/repository.js
new file mode 100644 (file)
index 0000000..5310b9d
--- /dev/null
@@ -0,0 +1,39 @@
+// 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/>.
+
+/**
+ * PayPal repository module to encapsulate all of the AJAX requests that can be sent for PayPal.
+ *
+ * @module     pg_paypal/repository
+ * @package    pg_paypal
+ * @copyright  2020 Shamim Rezaie <shamim@moodle.com>
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+import Ajax from 'core/ajax';
+
+/**
+ * Return the PayPal JavaScript SDK URL.
+ *
+ * @returns {Promise<{clientid: String, brandname: String}>}
+ */
+export const getConfigForJs = () => {
+    const request = {
+        methodname: 'pg_paypal_get_config_for_js',
+        args: {},
+    };
+
+    return Ajax.call([request])[0];
+};
diff --git a/payment/gateway/paypal/classes/external/get_config_for_js.php b/payment/gateway/paypal/classes/external/get_config_for_js.php
new file mode 100644 (file)
index 0000000..a1300aa
--- /dev/null
@@ -0,0 +1,74 @@
+<?php
+// 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 class contains a list of webservice functions related to the PayPal payment gateway.
+ *
+ * @package    pg_paypal
+ * @copyright  2020 Shamim Rezaie <shamim@moodle.com>
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+declare(strict_types=1);
+
+namespace pg_paypal\external;
+
+use external_api;
+use external_function_parameters;
+use external_value;
+use external_single_structure;
+
+defined('MOODLE_INTERNAL') || die();
+
+require_once($CFG->libdir . '/externallib.php');
+
+class get_config_for_js extends external_api {
+
+    /**
+     * Returns description of method parameters.
+     *
+     * @return external_function_parameters
+     */
+    public static function execute_parameters(): external_function_parameters {
+        return new external_function_parameters([]);
+    }
+
+    /**
+     * Returns the full URL of the PayPal JavaScript SDK.
+     *
+     * @return string[]
+     */
+    public static function execute(): array {
+        $config = get_config('pg_paypal');
+
+        return [
+            'clientid' => $config->clientid,
+            'brandname' => $config->brandname,
+        ];
+    }
+
+    /**
+     * Returns description of method result value.
+     *
+     * @return external_single_structure
+     */
+    public static function execute_returns(): external_single_structure {
+        return new external_single_structure([
+            'clientid' => new external_value(PARAM_TEXT, 'PayPal client ID'),
+            'brandname' => new external_value(PARAM_TEXT, 'Brand name'),
+        ]);
+    }
+}
diff --git a/payment/gateway/paypal/db/services.php b/payment/gateway/paypal/db/services.php
new file mode 100644 (file)
index 0000000..dd66832
--- /dev/null
@@ -0,0 +1,36 @@
+<?php
+// 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/>.
+
+/**
+ * External functions and service definitions for the PayPal payment gateway plugin.
+ *
+ * @package    pg_paypal
+ * @copyright  2020 Shamim Rezaie <shamim@moodle.com>
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+$functions = [
+    'pg_paypal_get_config_for_js' => [
+        'classname'   => 'pg_paypal\external\get_config_for_js',
+        'methodname'  => 'execute',
+        'classpath'   => '',
+        'description' => 'Returns the configuration settings to be used in js',
+        'type'        => 'read',
+        'ajax'        => true,
+    ],
+];
index f64015e..0739395 100644 (file)
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
+$string['brandname'] = 'Brand name';
+$string['brandname_desc'] = 'The optional label that overrides the business name in the PayPal account on the PayPal site.';
+$string['clientid'] = 'Client ID';
+$string['clientid_desc'] = 'The client ID that PayPal generated for your application.';
 $string['gatewaydescription'] = 'PayPal is an authorised payment gateway provider for processing credit card transactions.';
 $string['gatewayname'] = 'PayPal';
 $string['pluginname'] = 'PayPal';
index 0c07be1..d417def 100644 (file)
@@ -27,4 +27,8 @@ defined('MOODLE_INTERNAL') || die();
 if ($ADMIN->fulltree) {
     $settings->add(new admin_setting_heading('pg_paypal_settings', '', get_string('pluginname_desc', 'pg_paypal')));
 
+    $settings->add(new admin_setting_configtext('pg_paypal/brandname', get_string('brandname', 'pg_paypal'),
+            get_string('brandname', 'pg_paypal'), '', PARAM_TEXT));
+    $settings->add(new admin_setting_configtext('pg_paypal/clientid', get_string('clientid', 'pg_paypal'),
+            get_string('clientid_desc', 'pg_paypal'), '', PARAM_TEXT));
 }