diff --git a/enrol/paypal/edit.php b/enrol/paypal/edit.php index 8955cb7d812..6175b3bc440 100644 --- a/enrol/paypal/edit.php +++ b/enrol/paypal/edit.php @@ -47,6 +47,7 @@ $plugin = enrol_get_plugin('paypal'); if ($instanceid) { $instance = $DB->get_record('enrol', array('courseid'=>$course->id, 'enrol'=>'paypal', 'id'=>$instanceid), '*', MUST_EXIST); + $instance->cost = format_float($instance->cost, 2, true); } else { require_capability('moodle/course:enrolconfig', $context); // no instance yet, we have to add new instance diff --git a/enrol/paypal/edit_form.php b/enrol/paypal/edit_form.php index 9943a4c38e8..857cc2ceecc 100644 --- a/enrol/paypal/edit_form.php +++ b/enrol/paypal/edit_form.php @@ -46,7 +46,7 @@ class enrol_paypal_edit_form extends moodleform { $mform->addElement('text', 'cost', get_string('cost', 'enrol_paypal'), array('size'=>4)); $mform->setType('cost', PARAM_RAW); // Use unformat_float to get real value. - $mform->setDefault('cost', $plugin->get_config('cost')); + $mform->setDefault('cost', format_float($plugin->get_config('cost'), 2, true)); $paypalcurrencies = $plugin->get_currencies(); $mform->addElement('select', 'currency', get_string('currency', 'enrol_paypal'), $paypalcurrencies); @@ -90,15 +90,13 @@ class enrol_paypal_edit_form extends moodleform { list($instance, $plugin, $context) = $this->_customdata; - if ($data['status'] == ENROL_INSTANCE_ENABLED) { - if (!empty($data['enrolenddate']) and $data['enrolenddate'] < $data['enrolstartdate']) { - $errors['enrolenddate'] = get_string('enrolenddaterror', 'enrol_paypal'); - } + if (!empty($data['enrolenddate']) and $data['enrolenddate'] < $data['enrolstartdate']) { + $errors['enrolenddate'] = get_string('enrolenddaterror', 'enrol_paypal'); + } - if (!is_numeric($data['cost'])) { - $errors['cost'] = get_string('costerror', 'enrol_paypal'); - - } + $cost = str_replace(get_string('decsep', 'langconfig'), '.', $data['cost']); + if (!is_numeric($cost)) { + $errors['cost'] = get_string('costerror', 'enrol_paypal'); } return $errors; diff --git a/enrol/paypal/enrol.html b/enrol/paypal/enrol.html index 875e3ac8cea..c9d5865f404 100644 --- a/enrol/paypal/enrol.html +++ b/enrol/paypal/enrol.html @@ -2,7 +2,7 @@
-
currency} {$cost}"; ?>
+currency} {$localisedcost}"; ?>

'.get_string('nocost', 'enrol_paypal').'
'; } else { + // Calculate localised and "." cost, make sure we send PayPal the same value, + // please note PayPal expects amount with 2 decimal places and "." separator. + $localisedcost = format_float($cost, 2, true); + $cost = format_float($cost, 2, false); + if (isguestuser()) { // force login only for guest user, not real users with guest role if (empty($CFG->loginhttps)) { $wwwroot = $CFG->wwwroot; @@ -199,7 +204,7 @@ class enrol_paypal_plugin extends enrol_plugin { $wwwroot = str_replace("http://", "https://", $CFG->wwwroot); } echo ''.get_string('paymentrequired').'
'; - echo ''.get_string('cost').": $instance->currency $cost".'
'; + echo ''.get_string('cost').": $instance->currency $localisedcost".'
'; echo ''; echo '