Payment API
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:
<button
data-action="core_payment/triggerPayment"
data-component="enrol_fee"
data-paymentarea="fee"
data-itemid="{{itemid}}"
data-cost="{{coststring}}"
data-description="{{description}}"
>
{{# str }} sendpaymentbutton, enrol_fee {{/ str }}
</button>
{{#js}}
require(['core_payment/gateways_modal'], function(modal) {
modal.init();
});
{{/js}}
The service_provider class
All components that want to use the payment API have to implement the \core_payment\local\callback\service_provider interface.
get_payable
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.
deliver_order
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
- User documentation Payment gateways