If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Payment API

From MoodleDocs
Revision as of 02:43, 3 June 2022 by Rajneel Totaram (talk | contribs) (Minor correction and adding some missing info.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Moodle 3.10

Payment API allows Moodle components to have financial interactions with users.

Trigger the payment modal

In order to trigger the payment modal, all you need to do is to place an HTML element with data-action attribute equal to core_payment/triggerPayment in the page. You can use a mustache template with a content similar to the following:

    {{# str }} sendpaymentbutton, enrol_fee {{/ str }}

    require(['core_payment/gateways_modal'], function(modal) {

The service_provider class

All components that want to use the payment API have to implement the \core_payment\local\callback\service_provider interface.


public static function get_payable(string $paymentarea, int $itemid): \core_payment\local\entities\payable;

This is the function that the payment subsystem calls to retrieve the amount and currency of what is being sold, along with the accountid that payments should be paid to.


public static function deliver_order(string $paymentarea, int $itemid, int $paymentid, int $userid): bool;

This is the function that the payment subsystem calls when a user makes a successful payment. This function should give what the user paid for to them.

See also