Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403]

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: 399 lines (15 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
param: string $paymentarea
param: int $itemid
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 itemid belongs to
param: string $paymentarea
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

param: string $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 itemid belongs to
param: string $paymentarea
param: int $itemid An internal identifier that is used by the component
return: local\entities\payable

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
param: string $paymentarea
param: int $itemid
param: string $gatewayname
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 itemid belongs to
param: string $paymentarea
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 itemid belongs to
param: string $paymentarea
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