Payment API

From MoodleDocs

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 }}

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