2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * This is the external API for this component.
20 * @package core_payment
21 * @copyright 2019 Shamim Rezaie <shamim@moodle.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 namespace core_payment\external;
28 use external_function_parameters;
30 use external_single_structure;
31 use external_multiple_structure;
33 defined('MOODLE_INTERNAL') || die();
35 require_once($CFG->libdir . '/externallib.php');
37 class get_gateways_for_currency extends external_api {
40 * Returns description of method parameters.
42 * @return external_function_parameters
44 public static function execute_parameters(): external_function_parameters {
45 return new external_function_parameters(
46 ['currency' => new external_value(PARAM_ALPHA, 'Currency code')]
51 * Returns the list of gateways that can process payments in the given currency.
53 * @param string $currency The currency in the three-character ISO-4217 format.
56 public static function execute(string $currency): array {
58 $params = external_api::validate_parameters(self::execute_parameters(), [
59 'currency' => $currency,
63 $gateways = \core_payment\helper::get_gateways_for_currency($params['currency']);
65 foreach ($gateways as $gateway) {
67 'shortname' => $gateway,
68 'name' => get_string('gatewayname', 'pg_' . $gateway),
69 'description' => get_string('gatewaydescription', 'pg_' . $gateway),
77 * Returns description of method result value.
79 * @return external_multiple_structure
81 public static function execute_returns(): external_multiple_structure {
82 return new external_multiple_structure(
83 new external_single_structure([
84 'shortname' => new external_value(PARAM_PLUGIN, 'Name of the plugin'),
85 'name' => new external_value(PARAM_TEXT, 'Human readable name of the gateway'),
86 'description' => new external_value(PARAM_TEXT, 'description of the gateway'),