API / Webhooks / REST - Where to get started?

API / Webhooks / REST - Where to get started?

by Mike North -
Number of replies: 9

Hi All,

I'm trying to connect up Stripe subscriptions with Moodle.

I have a Stripe account and have created subscription plans to collect monthly payments from customers.

Stripe has an extensive library of API / Webhooks and there is a moodle plugin which can accept a single payment and then enrol students in a course automatically, but I can't find any free plugins (can't afford paid at the moment) or instructions on how to allow access to a course whilst monthly subscription payments are being received and un-enroll a student if they cancel or pause their subscription.

So I am now trying to figure out how to connect Stripe and Moodle through API / Webhooks but having no previous experience in this area I can't figure out where to even start.

Currently I can't afford a developer to do this for me so I was wondering if anyone can point me to any resource which can help me get started with the basics, or let me know if there is a simple way to set up my moodle to receive API / Webhooks from Stripe, and send webhooks to Stripe (e.g. if student wants to pause / un-enroll from a course).

Any input or guidance would be much appreciated as I've been stuck on this for a really long time!

Thanks.



Average of ratings: -
In reply to Mike North

Re: API / Webhooks / REST - Where to get started?

by Justin Hunt -
Picture of Particularly helpful Moodlers Picture of Plugin developers
Hi Mike

There might be a Stripe subscriptions integration, I seem to recall someone talking about that here on the forums on a previous occasion. But it's more common for students to purchase access to a course in a single transaction. And the course enrolment period can be set to expire after a period of time. This is the stripe enrolment plugin which works like that;
https://moodle.org/plugins/enrol_stripepayment

If you are not able to pay developers/ plugins or able to develop yourself then I think its best if you just follow the common workflow.
Average of ratings: Useful (1)
In reply to Justin Hunt

Re: API / Webhooks / REST - Where to get started?

by Mike North -
Hi Justin,

Yes - single transaction is definitely simpler. Was hoping there was a straightforward approach for subscriptions but there doesn't currently seem to be. Thanks for your advice.
In reply to Mike North

Re: API / Webhooks / REST - Where to get started?

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
This is not a place to start if you have no development experience. I don't mean to be patronising but you have to learn PHP to some level, the HTTP stuff in PHP (no fun) and then suffer the potential evil of getting a remote API to speak to you - which is usually mired in frustration and needs quite a bit of debugging experience.
Average of ratings: Useful (1)
In reply to Howard Miller

Re: API / Webhooks / REST - Where to get started?

by Mike North -
Hi Howard,

Not patronising at all. You're right - having read through web services / API documentation it's clear that someone needs development experience to be able to make this work. Thought I could figure it out with some research / self study but evidently not!
In reply to Mike North

Re: API / Webhooks / REST - Where to get started?

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
You *can* but you'll need to be patient and tenacious wink
In reply to Howard Miller

Re: API / Webhooks / REST - Where to get started?

by Mike North -
Ok so I've made some progress - I've set up moodle web services but wondering can I send webhooks directly to moodle? Or does it need to go to some intermediary site / service to then give moodle specific instructions?

So let's say I want moodle to enroll "Student A" in "Course X" when "Product Y" is purchased online - I can point a webhook to an endpoint on moodle to tell it that "Product Y" has been purchased, but how does moodle then know how to identify the payer and which course to enroll them in?

Is there a way to assign that within webservices functions or does that need to be processed by some intermediary service between stripe and moodle in order for moodle to be given a specific instruction such as "enroll student A in course X" ?

Can anyone tell me if there is such a service (or plugin)? Thanks!
In reply to Mike North

Re: API / Webhooks / REST - Where to get started?

by Justin Hunt -
Picture of Particularly helpful Moodlers Picture of Plugin developers
Moodle can already do this for you. You seem determined to use a webhook, but I feel you are making it harder than it needs to be.
Earlier I posted a link sot Stripe Enrolment plugin, but actually times have moved on and I realised there are now payment gateways and enrol on payment plugins. If you are getting started you should use those:

Payment Gateways
https://docs.moodle.org/400/en/Payment_gateways

Enrolment on payment
https://docs.moodle.org/400/en/Enrolment_on_payment
Average of ratings: Useful (1)
In reply to Justin Hunt

Re: API / Webhooks / REST - Where to get started?

by Mike North -
Thanks. I need to upgrade to 3.10+ to test those out (currently on 3.9) but they seem promising.

Just out of interest, when you said "Moodle can already do this for you", where would I find documentation on that? Or which section in site administration do I use to process webhooks?

Even if I don't end up doing it this way I've learned a lot about web services recently so would be good to know for future.
In reply to Mike North

Re: API / Webhooks / REST - Where to get started?

by Justin Hunt -
Picture of Particularly helpful Moodlers Picture of Plugin developers
I was referring to Moodle can already handle Stripe payments for you. Via the Stripe Enrolments plugin (link posted earlier in this thread) or Enrol on Payments plugins (link posted earlier in this thread).

As for webhooks, for calling webhooks in response to Moodle events, there are a number of plugins. For responding to web service calls from outside moodle, I am not aware of anything. I wrote a Zapier integration for Moodle that would do things like create users and enrol users in response to Stripe events. Probably the kind of thing you are looking for. But that sits on Zapier, and in the end I just needed more than what I could do with such a loose connection. So I wrote a plugin.