## Blocks: Coupon

block_coupon
Maintained by Sebsoft Plugins, Rogier van Dongen
The Sebsoft Coupon Plugin offers you the possibility to create coupons for various levels of course access. Using a coupon code, users will be enrolled into courses that are attached to the coupon.
534 sites
79 fans

SEBSOFT COUPON PLUGIN

The Sebsoft Coupon Plugin offers you the possibility to create coupons for various levels

of course access. Using a coupon code, users will be enrolled into courses that are attached to the coupon. That way, you can use the coupon system as voucher or vouchering system for your course(s).

There are a few different ways of generating coupons:

- Course level: this means one or more course(s) need to be selected for which the coupon is valid.

Once the coupon code is entered by a user, he or she will be enroled in every course the coupon

is attached to.

A nice extra feature is, when groups are configured for a certain course, you can configure which

course group the coupon is for. When a user claims the coupon, he or she will be added to that specific

group in the course. This makes it possible to separate coupon users from regular users.

You could also make specific course groups every time you generate a batch of new coupons, so there's

some way of matching a batch of coupons to a group of users. The possibilities are numerous.

- Cohort level: this means one or more cohort(s) need to be selected for which the coupon is valid.

Once the coupon code is entered by a user, he or she will be added as a cohort member for every

cohort the coupon is attached to.

NOTE: When generating cohort level coupons, there is a possibility to "connect" extra courses to

a given cohort. One MUST know that upon doing this, the courses will at that point be added to

the cohort enrolment sync. Without knowing this little fact, it could be "unexpected" behavior,

even though it's a logical step.

Furthermore, coupons can be generated on two "access" levels:

- Personalized. The base of this, is either a CSV is uploaded, or a CSV is given directly in a textbox.

The needed user information for every coupon to be generated will be the user's name, email address

and gender.

These coupons will then be generated and sent off to the appropriate users using a background task.

- Bulk: The base of this is simple: you generate a certain amount of access coupons, which will then

be emailed to the pre-configured recipient or (if allowed) to an emailaddress that can be freely entered.

- WARNING:

Wherever possible, please use PNG images.

Also, whenever possible, do NOT use images that have an alpha channel.

This will MASSIVELY slow down processing time, due to internal conversion of images by TCPDF.

On our tests, for a 300 DPI image on A4 format (2480 x 3508 pixels) with an alpha channel,

rendering a single PDF took around 25 seconds. Taking the alpha channel out of the image,

rendering a single PDF was reduced to around 3 seconds.

This means the PNG images should _always_ be stored as 24-bit true colour images.

_Do not use 32-bit_ (true colour + transparency)!

Furthermore, whenever possible, have the coupon generator create a single PDF with all

coupons (this is only applicable when generating coupons in "bulk" mode). The process of

generating coupons has been optimized to only "use" the image 1 time when creating any amount

of coupons in a single PDF. If you choose the option to create a seperate PDF for every coupon,

the image will have to be rendered for each and every PDF.

This has 2 major downfalls:

1. Every PDF will roughly have a slightly bigger size than the image size (in our tests, 350 - 400 kB per PDF)

2. Every PDF takes the full amount of time to render.

Effectively, this means the following (using fictitious sizes):

10 coupons, single PDF -> result is around 400 kB, rendering takes around 3-4 seconds.

10 coupons, seperate PDFs -> result is around 4 MB, rendering takes around 35-40 seconds.

INSTALLATION INSTRUCTIONS

- Copy the coupon folder to your blocks directory.

- Go to the moodle admin pages (you will probably be confronted with it anyway) and install the plugin

- Configure the main settings for the plugin.

- We're set up for usage!

PLACEMENT OF THE PLUGIN

There are only two pages you can add the coupon block on. This is the site's frontpage

or the user dashboard (my) page. The main reason for this is because the block is the

"frontend" for users to enter their coupon or voucher code.

Administrators and users with the correct capabilities will also see the links to

the coupon administration pages and the coupon generator page.

GENERAL CONSIDERATIONS

There's two main configurations to consider when generating coupons.

For course type coupons, this plugin attempts to enrol a user through use of Moodle's

internal function "enrol_try_internal_enrol".

The Moodle documentation shows it will attempt to enrol you using manual enrolment.

For this reason manual enrolment MUST be enabled for these courses.

For cohort type coupons, a user is made a member of a cohort. That's all there is to it.

Surprise though, if you want to actually make a user have access to a course, you

probably want to configure cohort enrolment for the course.

For those paying attention, creating cohort type coupons thus enables a simple

way of enrolling users into multiple courses at once just by configuring the right

cohort enrolments in multiple courses.

That's still not to say course coupons can't be used in a similar way (using meta courses).

### Contributors

Sebsoft Plugins (Lead maintainer)
Rogier van Dongen
Please login to view contributors details and/or to contact them

### Awards

• Thu, Nov 19, 2020, 2:33 PM
Please accept my apology if this has already been considered and replied to.
Is there a way I can create a custom coupon string instead of the random string generated by this plugin? I would be better to know what a coupon code is when creating & sending them out.
• Wed, Nov 25, 2020, 8:12 PM
I'm facing a real big problem here in my installation...

1.Coupons are generated correctly (checked on moodledata dir)
2.Coupons files are not included in the email sent
3. When visualizing the coupons download page, it doesn't show the download link. It shows a {$a} instead (look like a variable or parameter that should render the link. On this page, if add, at the end of the address the parameter dl=1, download starts and then works. It was used to work fine in the past versions. I'm using 3.8 moodle. Help please. 👊🏻 😉 Felipe Garbin • Thu, Nov 26, 2020, 12:55 PM Still about the above trouble... The notification received: "The coupon(s) you requested have been generated You should have received an e-mail containing the link to download the generated coupons. You can also choose to download your coupons directly by clicking {$a}"
• Fri, Dec 11, 2020, 9:25 AM
Hello.
I have some questions.

Question 1
When I issue an extension coupon in the "Home / My courses / Course name" settings menu under "Enrolment extension coupons", the coupon code was issued, but no email was sent to the account.
We have not checked the "Use alternative email" box.
When I checked the "Use alternative email" box, the email was sent to the specified email address.
Can you tell me why?

Question 2
When I activate the extension voucher in the login environment of my account, the extension seems to be successful, but when I check "Home / My courses / Course name / Participants", the status is still "Suspended".
I think it should change to "Active". Is this the correct behaviour?
• Mon, Dec 14, 2020, 5:38 PM
@Felipe: Please message me directly (you can find the email in virtually every file). I cannot reproduce this issue. I suspect your language strings may be faulty. Since this is the very first time this has ever been reported, I suspect your language strings are faulty.

@Bhevan: at the moment it's not possible to define your own coupon/voucher codes in any way.

@Hiro: Regarding question 1: there can be many reasons a coupon is seemingly not sent but actually is and got dropped by either Moodle or the mail provider. Actually, we've changed the whole process and added the batch downloads explicitly because of gmail, for example, not accepting the emails due to the included PDFs. We've also introduced the maillog tab as a first indication that the email might not have been sent. Is there any entry on the mail log? If not, it is likely that the email has actually been sent.
Regarding question 2: You're actually right. We've never really considered a suspended/inactive enrolment should be set to Active again. It's fixed in the repository, so the next rollout on moodle.org will actually do this. In the meantime you _could_ use the code from the repository on github.
Furthermore; regarding your question from oct 27th about the notifications, could you send me a private message (or email me)? I will need some extra information on specifics. Thanks in advance.

Cheers!
• Tue, Dec 22, 2020, 2:44 PM
Hello Rogier,

Regarding question 1:
There were no entries in the mail log. Is it only recorded in the mail log if the sending process did not finish successfully?
I tried to send to several email addresses, but none of them received any mail.

Is there any other way to check the log for sending mails?

Best regards,
• Tue, Jan 12, 2021, 12:08 AM
Hi Rogier,
Is there any way that you can programmatically redeem a coupon without a user having to submit the code?

Regards
• Tue, Jan 12, 2021, 1:00 AM

@Brendan McNamara,
If you have the capability to log in as a different account, you can redeem the coupon using his profile. Follow the steps:
1. Go to the user's profile page
2. Under the administration category, click on Log in as
3. Go to the Dashboard page and redeem the coupon code for him.
4. Log out to exit the user's account.

• Tue, Jan 12, 2021, 6:45 PM
Thank you Thodoris, however I really need something that automates redeeming a coupon. If anyone knows a way to do this I'd be grateful.
Also, does anyone know whether it is possible to create a coupon which will allow access to Moodle between two dates, so a start and end date.
• Thu, Jan 28, 2021, 5:29 AM
Cannot see how to implement on moodlecloud. Any help?
• Tue, Feb 2, 2021, 1:18 AM
Does the Coupon module provide any type of REST API? It would be great if I could automate the generation of coupons. It would allow a nice integration with other systems we use.
• Tue, Feb 9, 2021, 10:05 PM
@Mike There _is_ an API, exposed through Moodle's webservices, that should enable you to get started with your question.
In any case, if you have more specific questions, please do not hesitate to send me an email (look in the source code for the correct email address).

@Brendan: automating the redemption of a coupon is not possible as such. One big reason for not allowing this is because the couponcode/vouchercode claimed will be attached/linked to the user that was logged in when redeeming the coupon. Automated redemption would mean that information is missing and, at least at this moment, is not supported by the database model.
ALso, can you specifiy a little more about that start- and enddate? The normal flow of possibilities at this moment is to have an enrolperiod, but please note this is applicable _from the time of redemptio_ onwards. Specifying a start- and enddate was deliberately not taken into account when first developing this plugin, due to the fact this could mean you're unenrolled from a course within a very short timespan (say; with startdate Dec 01 202 and enddate Jan 15 2020. Now if someone redeems on Jan 14th; they WILL be unenrolled the next day).

@David: MoodleCloud only provides core plugins and a small subset of extra plugins. There's no option to install your own at all, so Moodlecloud maybe isn't the correct solution if the coupon plugin is critical to your business case. If anything you _could_ ask if they would install the coupon plugin, but I seriously doubt this will be honoured. This is all explicitly stated on the Moodle cloud website, on the frontpage, under "Can I install my own plugins?".
• Tue, Feb 9, 2021, 10:17 PM
@Hiro: this really looks like something is wrong with your installation. Also please note some of the actions _require_ a cron job running on the background (or, alternativaly, running it from your browser using /admin/cron.php).
If you still keep running into issues, take a look at the mailtest plugin (local_mailtest). This could possibly provide some insights as to why email isn't received or sent.
It's hard to say anything about why emails may or may not be received without extensive extra information or at least take as many steps as possible to exclude all other (core) processes from being erroneous. Then still it can be hard to say anything about any realistic cause.
The only "other" way that we've been able to tackle _any_ problems at all came from a subsystem that actually logged the communication with the receiving mailserver, but keep in mind this is regarded as an extra communication layer/tier and most likely not applicable to you. _If_ you do not connect to an external SMTP, but rather use the internal sendmail() functionality, you may also be able to get more information from there provided any communication is actually logged. However, once you venture there, keep in mind this is no longer within the scope of the plugin.
• Wed, Feb 24, 2021, 9:30 PM
Hi everybody,
Awesome plugin. Thank you I have used it for years!
One question regarding coupon generation using APIs: is there any plan to add parameters such as the enrollment period for example? or trigger an email with the default options?
Thanks a bunch!
• Thu, Feb 25, 2021, 4:47 PM
@Hugh: thank you for noticing. The services are quite often "forgotten". Please be aware you can also add issues on the github repository.
I will take this into account with the next release and added an issue to the github issue tracker
Cheers,
Rogier