Skip to content

Commit

Permalink
MDL-69166 pg_paypal: WS and AMD to return some settings to be used in js
Browse files Browse the repository at this point in the history
  • Loading branch information
rezaies committed Oct 26, 2020
1 parent 8ef156b commit e75112a
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 0 deletions.
2 changes: 2 additions & 0 deletions payment/gateway/paypal/amd/build/repository.min.js

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

1 change: 1 addition & 0 deletions payment/gateway/paypal/amd/build/repository.min.js.map

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

39 changes: 39 additions & 0 deletions payment/gateway/paypal/amd/src/repository.js
@@ -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];
};
74 changes: 74 additions & 0 deletions payment/gateway/paypal/classes/external/get_config_for_js.php
@@ -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'),
]);
}
}
36 changes: 36 additions & 0 deletions payment/gateway/paypal/db/services.php
@@ -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,
],
];
4 changes: 4 additions & 0 deletions payment/gateway/paypal/lang/en/pg_paypal.php
Expand Up @@ -22,6 +22,10 @@
* @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';
Expand Down
4 changes: 4 additions & 0 deletions payment/gateway/paypal/settings.php
Expand Up @@ -27,4 +27,8 @@
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));
}

0 comments on commit e75112a

Please sign in to comment.