<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://docs.moodle.org/dev/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Rjnl</id>
	<title>MoodleDocs - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://docs.moodle.org/dev/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Rjnl"/>
	<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/Special:Contributions/Rjnl"/>
	<updated>2026-11-21T02:58:32Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Payment_API&amp;diff=63280</id>
		<title>Payment API</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Payment_API&amp;diff=63280"/>
		<updated>2022-06-03T02:43:20Z</updated>

		<summary type="html">&lt;p&gt;Rjnl: Minor correction and adding some missing info.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Moodle 3.10}}&lt;br /&gt;
&lt;br /&gt;
Payment API allows Moodle components to have financial interactions with users.&lt;br /&gt;
=== Trigger the payment modal ===&lt;br /&gt;
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:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;button&lt;br /&gt;
    data-action=&amp;quot;core_payment/triggerPayment&amp;quot;&lt;br /&gt;
    data-component=&amp;quot;enrol_fee&amp;quot;&lt;br /&gt;
    data-paymentarea=&amp;quot;fee&amp;quot;&lt;br /&gt;
    data-itemid=&amp;quot;{{itemid}}&amp;quot;&lt;br /&gt;
    data-cost=&amp;quot;{{coststring}}&amp;quot;&lt;br /&gt;
    data-description=&amp;quot;{{description}}&amp;quot;&lt;br /&gt;
&amp;gt;&lt;br /&gt;
    {{# str }} sendpaymentbutton, enrol_fee {{/ str }}&lt;br /&gt;
&amp;lt;/button&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{#js}}&lt;br /&gt;
    require([&#039;core_payment/gateways_modal&#039;], function(modal) {&lt;br /&gt;
        modal.init();&lt;br /&gt;
    });&lt;br /&gt;
{{/js}}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== The service_provider class ===&lt;br /&gt;
All components that want to use the payment API have to implement the \core_payment\local\callback\service_provider interface.&lt;br /&gt;
==== get_payable ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
public static function get_payable(string $paymentarea, int $itemid): \core_payment\local\entities\payable;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
==== deliver_order ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
public static function deliver_order(string $paymentarea, int $itemid, int $paymentid, int $userid): bool;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
==See also==&lt;br /&gt;
* User documentation [[:en:Payment gateways|Payment gateways]]&lt;/div&gt;</summary>
		<author><name>Rjnl</name></author>
	</entry>
</feed>