kerongon / enrol_payment

A Moodle enrolment plugin with Stripe and PayPal backends

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

enrol_payment

This Moodle plugin is a superset of Moodle's enrol_paypal functionality.

Features

  • Use Stripe or PayPal payment backend
  • Define discount codes with percentage-based or amount-based discounts
  • Define custom tax rules (see Adding a Province/State Field, below)
  • Allow users to enrol other users (see Multiple Enrolment, below)

Adding a Province/State Field

Since Moodle does not natively collect province/state info, the instructions below are hacks to core files to enable the insertion of a province/state code in the “msn” field in the user table. This value is use by the plugin to calculate tax.

STEP 1: Customize the following language strings in the core moodle.php

msnid: Province/state state: Select province/state missingreqreason: Missing province/state (NB: needed to make “msn” [a.k.a. the state/province field] a required field)

STEP 2: Create the states file

Name your state/province file states.php and upload it in the folder /lang/en. This file needs to begin with <?PHP and end with ?> and have as many entries in the format: $string['Code'] = 'State'; as required. For example:

<?PHP
$string['AB'] = 'Alberta';
.
.
.
$string['WY'] = 'Wyoming';
?>

STEP 3: Add function get_list_of_states()

In /lib/classes/string_manager_standard.php, just above the get_list_of_countries() function, insert:

    /**
     * Returns a localised list of all state names, sorted by localised name.
     * @return array two-letter state code => translated name.
     */
    public function get_list_of_states($returnall = false, $lang = NULL) {
        global $CFG;
        if ($lang === NULL) {
            $lang = current_language();
        }
        $states = $this->load_component_strings('core_states', $lang);
        if (!$returnall and !empty($CFG->allstatecodes)) {
            $enabled = explode(',', $CFG->allstatecodes);
            $return = array();
            foreach ($enabled as $c) {
                if (isset($states[$c])) {
                    $return[$c] = $states[$c];
                }
            }
            return $return;
        }
        return $states;
    }

In /lib/classes/string_manager.php, just above the get_list_of_countries() function, insert:

     /**
     * Returns a localised list of all state names, sorted by localised name.
     * @return array two-letter state code => translated name.
     */
    public function get_list_of_states($returnall = false, $lang = null);

STEP 4: Modify the signup form

In login/signup_form.php, above the country code insert:

$state = get_string_manager()->get_list_of_states();
$default_state[''] = get_string('state');
$state = array_merge($default_state, $state);
$mform->addElement('select', 'msn', get_string('msnid'), $state);
$mform->addRule('msn', get_string('missingreqreason'), 'required', null, 'server');

STEP 5: Modify the edit profile form

In user/editlib.php, above this line: $choices = get_string_manager()->get_list_of_countries(); insert:

$choices = get_string_manager()->get_list_of_states();
$choices= array(''=>get_string('state') . '...') + $choices;
$mform->addElement('select', 'msn', get_string('msnid'), $choices);
$mform->addRule('msn', get_string('missingreqreason'), 'required', null, 'server');

Ensure to comment out the “msn” field from the moodle optional fields.

About

A Moodle enrolment plugin with Stripe and PayPal backends

License:GNU General Public License v3.0


Languages

Language:PHP 85.7%Language:JavaScript 10.5%Language:HTML 3.0%Language:CSS 0.9%