Skip to content
Browse files

Merge branch 'w22_MDL-38408_m25_paypalcost' of git://github.com/skoda…

…k/moodle into MOODLE_25_STABLE
  • Loading branch information...
2 parents 7291b02 + 7fa470d commit 191e70c2e2b71830030d3695318b4d5dc71620d8 @danpoltawski danpoltawski committed May 27, 2013
Showing with 18 additions and 12 deletions.
  1. +1 −0 enrol/paypal/edit.php
  2. +7 −9 enrol/paypal/edit_form.php
  3. +1 −1 enrol/paypal/enrol.html
  4. +3 −1 enrol/paypal/ipn.php
  5. +6 −1 enrol/paypal/lib.php
View
1 enrol/paypal/edit.php
@@ -47,6 +47,7 @@
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
View
16 enrol/paypal/edit_form.php
@@ -46,7 +46,7 @@ function definition() {
$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 @@ function validation($data, $files) {
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 (!is_numeric($data['cost'])) {
- $errors['cost'] = get_string('costerror', 'enrol_paypal');
+ if (!empty($data['enrolenddate']) and $data['enrolenddate'] < $data['enrolstartdate']) {
+ $errors['enrolenddate'] = get_string('enrolenddaterror', 'enrol_paypal');
+ }
- }
+ $cost = str_replace(get_string('decsep', 'langconfig'), '.', $data['cost']);
+ if (!is_numeric($cost)) {
+ $errors['cost'] = get_string('costerror', 'enrol_paypal');
}
return $errors;
View
2 enrol/paypal/enrol.html
@@ -2,7 +2,7 @@
<p><?php print_string("paymentrequired") ?></p>
<p><b><?php echo $instancename; ?></b></p>
-<p><b><?php echo get_string("cost").": {$instance->currency} {$cost}"; ?></b></p>
+<p><b><?php echo get_string("cost").": {$instance->currency} {$localisedcost}"; ?></b></p>
<p><img alt="<?php print_string('paypalaccepted', 'enrol_paypal') ?>" src="https://www.paypal.com/en_US/i/logo/PayPal_mark_60x38.gif" /></p>
<p><?php print_string("paymentinstant") ?></p>
<?php
View
4 enrol/paypal/ipn.php
@@ -197,8 +197,10 @@
$cost = (float) $plugin_instance->cost;
}
+ // Use the same rounding of floats as on the enrol form.
+ $cost = format_float($cost, 2, false);
+
if ($data->payment_gross < $cost) {
- $cost = format_float($cost, 2);
message_paypal_error_to_admin("Amount paid is not enough ($data->payment_gross < $cost))", $data);
die;
View
7 enrol/paypal/lib.php
@@ -190,6 +190,11 @@ function enrol_page_hook(stdClass $instance) {
echo '<p>'.get_string('nocost', 'enrol_paypal').'</p>';
} 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 @@ function enrol_page_hook(stdClass $instance) {
$wwwroot = str_replace("http://", "https://", $CFG->wwwroot);
}
echo '<div class="mdl-align"><p>'.get_string('paymentrequired').'</p>';
- echo '<p><b>'.get_string('cost').": $instance->currency $cost".'</b></p>';
+ echo '<p><b>'.get_string('cost').": $instance->currency $localisedcost".'</b></p>';
echo '<p><a href="'.$wwwroot.'/login/">'.get_string('loginsite').'</a></p>';
echo '</div>';
} else {

0 comments on commit 191e70c

Please sign in to comment.
Something went wrong with that request. Please try again.