mirrored from git://git.moodle.org/moodle.git
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-69166 pg_paypal: WS and AMD to return some settings to be used in js
- Loading branch information
Showing
7 changed files
with
160 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -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
74
payment/gateway/paypal/classes/external/get_config_for_js.php
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 |
---|---|---|
@@ -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'), | ||
]); | ||
} | ||
} |
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 |
---|---|---|
@@ -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, | ||
], | ||
]; |
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