Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 310 and 311]

Contains helper class for the payment subsystem.

Copyright: 2019 Shamim Rezaie <shamim@moodle.com>
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 416 lines (16 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: helper  - X-Ref

Helper class for the payment subsystem.

get_supported_currencies()   X-Ref
Returns an accumulated list of supported currencies by all payment gateways.

return: string[] An array of the currency codes in the three-character ISO-4217 format

get_available_gateways(string $component, string $paymentarea, int $itemid)   X-Ref
Returns the list of gateways that can process payments in the given currency.

param: string $component Name of the component that the paymentarea and itemid belong to
param: string $paymentarea Payment area
param: int $itemid An identifier that is known to the component
return: string[]

get_rounded_cost(float $amount, string $currency, float $surcharge = 0)   X-Ref
Rounds the cost based on the currency fractional digits, can also apply surcharge

param: float $amount amount in the currency units
param: string $currency currency, used for calculating the number of fractional digits
param: float $surcharge surcharge in percents
return: float

get_cost_as_string(float $amount, string $currency, float $surcharge = 0)   X-Ref
Returns human-readable amount with correct number of fractional digits and currency indicator, can also apply surcharge

param: float $amount amount in the currency units
param: string $currency The currency
param: float $surcharge surcharge in percents
return: string

get_gateway_surcharge(string $gateway)   X-Ref
Returns the percentage of surcharge that is applied when using a gateway

param: string $gateway Name of the gateway
return: float

gateways_modal_link_params(string $component, string $paymentarea, int $itemid,string $description)   X-Ref
Returns the attributes to place on a pay button.

param: string $component Name of the component that the paymentarea and itemid belong to
param: string $paymentarea Payment area
param: int $itemid An internal identifier that is used by the component
param: string $description Description of the payment
return: array

get_service_provider_classname(string $component)   X-Ref
Get the name of the service provider class

param: string $component The component
return: string

get_payable(string $component, string $paymentarea, int $itemid)   X-Ref
Asks the payable from the related component.

param: string $component Name of the component that the paymentarea and itemid belong to
param: string $paymentarea Payment area
param: int $itemid An internal identifier that is used by the component
return: local\entities\payable

get_success_url(string $component, string $paymentarea, int $itemid)   X-Ref
Fetches the URL of the page the user should be redirected to from the related component

param: string $component Name of the component that the paymentarea and itemid belong to
param: string $paymentarea Payment area
param: int $itemid An identifier that is known to the component
return: \moodle_url

get_gateway_configuration(string $component, string $paymentarea, int $itemid,string $gatewayname)   X-Ref
Returns the gateway configuration for given component and gateway

param: string $component Name of the component that the paymentarea and itemid belong to
param: string $paymentarea Payment area
param: int $itemid An identifier that is known to the component
param: string $gatewayname The gateway name
return: array

deliver_order(string $component, string $paymentarea, int $itemid, int $paymentid, int $userid)   X-Ref
Delivers what the user paid for.

param: string $component Name of the component that the paymentarea and itemid belong to
param: string $paymentarea Payment area
param: int $itemid An internal identifier that is used by the component
param: int $paymentid payment id as inserted into the 'payments' table, if needed for reference
param: int $userid The userid the order is going to deliver to
return: bool Whether successful or not

save_payment(int $accountid, string $component, string $paymentarea, int $itemid, int $userid,float $amount, string $currency, string $gateway)   X-Ref
Stores essential information about the payment and returns the "id" field of the payment record in DB.
Each payment gateway may then store the additional information their way.

param: int $accountid Account id
param: string $component Name of the component that the paymentarea and itemid belong to
param: string $paymentarea Payment area
param: int $itemid 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
param: string $currency Currency of payment
param: string $gateway The gateway that is used for the payment
return: int

add_common_gateway_settings(\admin_settingpage $settings, string $gateway)   X-Ref
This functions adds the settings that are common for all payment gateways.

param: \admin_settingpage $settings The settings object
param: string $gateway The gateway name prefixed with paygw_

save_payment_account(\stdClass $data)   X-Ref
Save a new or edited payment account (used in management interface)

param: \stdClass $data
return: account

delete_payment_account(account $account)   X-Ref
Delete a payment account (used in management interface)

param: account $account

restore_payment_account(account $account)   X-Ref
Restore archived payment account (used in management interface)

param: account $account

save_payment_gateway(\stdClass $data)   X-Ref
Save a payment gateway linked to an existing account (used in management interface)

param: \stdClass $data
return: account_gateway

get_payment_accounts_to_manage(\context $context, bool $showarchived = false)   X-Ref
Returns the list of payment accounts in the given context (used in management interface)

param: \context $context
return: account[]

get_payment_accounts_menu(\context $context)   X-Ref
Get list of accounts available in the given context

param: \context $context
return: array