@@ -27,7 +27,7 @@ |
||
| 27 | 27 | |
| 28 | 28 | defined('MOODLE_INTERNAL') || die(); |
| 29 | 29 | |
| 30 | -$plugin->version = 2016022900; // The current plugin version (Date: YYYYMMDDXX) |
|
| 31 | -$plugin->requires = 2011112901; // Requires this Moodle version |
|
| 30 | +$plugin->version = 2016022900; // The current plugin version (Date: YYYYMMDDXX) |
|
| 31 | +$plugin->requires = 2011112901; // Requires this Moodle version |
|
| 32 | 32 | $plugin->release = '2'; |
| 33 | -$plugin->component = 'enrol_pagseguro'; // Full name of the plugin (used for diagnostics) |
|
| 33 | +$plugin->component = 'enrol_pagseguro'; // Full name of the plugin (used for diagnostics) |
|
@@ -43,18 +43,18 @@ discard block |
||
| 43 | 43 | define('COMMERCE_PAGSEGURO_STATUS_REFUNDED', 6); |
| 44 | 44 | define('COMMERCE_PAGSEGURO_STATUS_CANCELED', 7); |
| 45 | 45 | define('COMMERCE_PAYMENT_STATUS_SUCCESS', 'success'); |
| 46 | -define('COMMERCE_PAYMENT_STATUS_FAILURE', 'failure') ; |
|
| 46 | +define('COMMERCE_PAYMENT_STATUS_FAILURE', 'failure'); |
|
| 47 | 47 | define('COMMERCE_PAYMENT_STATUS_PENDING', 'pending'); |
| 48 | 48 | |
| 49 | -$userid = $USER->id; |
|
| 50 | -$plugin = enrol_get_plugin('pagseguro'); |
|
| 51 | -$email = $plugin->get_config('pagsegurobusiness'); |
|
| 52 | -$token = $plugin->get_config('pagsegurotoken'); |
|
| 49 | +$userid = $USER->id; |
|
| 50 | +$plugin = enrol_get_plugin('pagseguro'); |
|
| 51 | +$email = $plugin->get_config('pagsegurobusiness'); |
|
| 52 | +$token = $plugin->get_config('pagsegurotoken'); |
|
| 53 | 53 | |
| 54 | 54 | $error_returnurl = $CFG->wwwroot.'/enrol/pagseguro/return.php'; |
| 55 | 55 | $success_returnurl = $CFG->wwwroot.'/enrol/pagseguro/return.php'; |
| 56 | 56 | |
| 57 | -$instanceid = optional_param('instanceid', 0, PARAM_INT); |
|
| 57 | +$instanceid = optional_param('instanceid', 0, PARAM_INT); |
|
| 58 | 58 | |
| 59 | 59 | $plugin_instance = $DB->get_record("enrol", array("id" => $instanceid, "status" => 0)); |
| 60 | 60 | $courseid = $plugin_instance->courseid; |
@@ -62,14 +62,14 @@ discard block |
||
| 62 | 62 | $currency = $plugin->get_config('currency'); |
| 63 | 63 | $encoding = 'UTF-8'; |
| 64 | 64 | $item_id = $courseid; |
| 65 | -$item_desc = empty($course->fullname) ? null: $course->fullname; |
|
| 66 | -$item_qty = (int)1; |
|
| 65 | +$item_desc = empty($course->fullname) ? null : $course->fullname; |
|
| 66 | +$item_qty = (int) 1; |
|
| 67 | 67 | $item_cost = empty($plugin_instance->cost) ? 0.00 : number_format($plugin_instance->cost, 2); |
| 68 | 68 | $item_cost = str_replace(',', '', $item_cost); |
| 69 | 69 | $item_amount = $item_cost; |
| 70 | 70 | |
| 71 | -$redirect_url = $CFG->wwwroot.'/enrol/pagseguro/process.php?instanceid='.$instanceid; |
|
| 72 | -$submitValue = get_string("sendpaymentbutton", "enrol_pagseguro"); |
|
| 71 | +$redirect_url = $CFG->wwwroot.'/enrol/pagseguro/process.php?instanceid='.$instanceid; |
|
| 72 | +$submitValue = get_string("sendpaymentbutton", "enrol_pagseguro"); |
|
| 73 | 73 | |
| 74 | 74 | $submited = optional_param('usersubmited', 0, PARAM_INT); |
| 75 | 75 | |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | $transactionid = optional_param('transaction_id', '', PARAM_RAW); |
| 80 | 80 | |
| 81 | 81 | if ($submited) { |
| 82 | - $url = "https://ws.pagseguro.uol.com.br/v2/checkout/?email=" . urlencode($email) . "&token=" . $token; |
|
| 82 | + $url = "https://ws.pagseguro.uol.com.br/v2/checkout/?email=".urlencode($email)."&token=".$token; |
|
| 83 | 83 | |
| 84 | 84 | $xml = "<?xml version=\"1.0\" encoding=\"$encoding\" standalone=\"yes\"?> |
| 85 | 85 | <checkout> |
@@ -132,13 +132,13 @@ discard block |
||
| 132 | 132 | $transaction = curl_exec($curl); |
| 133 | 133 | curl_close($curl); |
| 134 | 134 | |
| 135 | - if ($transaction == 'Unauthorized'){ |
|
| 135 | + if ($transaction == 'Unauthorized') { |
|
| 136 | 136 | // Error=1 Não autorizado. |
| 137 | 137 | $error_returnurl .= "?id={$courseid}&error=1"; |
| 138 | 138 | header("Location: $error_returnurl"); |
| 139 | - exit;//Mantenha essa linha |
|
| 139 | + exit; //Mantenha essa linha |
|
| 140 | 140 | } else { |
| 141 | - $transaction_data = serialize(trim($transaction)); |
|
| 141 | + $transaction_data = serialize(trim($transaction)); |
|
| 142 | 142 | process_moodle($transaction_data, $instanceid, $courseid); |
| 143 | 143 | } |
| 144 | 144 | |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | if (!empty($notificationCode)) { |
| 149 | 149 | $transaction = null; |
| 150 | 150 | // Sets the web service URL. |
| 151 | - $url = "https://ws.pagseguro.uol.com.br/v2/transactions/notifications/" . $notificationCode . "?email=".$email."&token=".$token; |
|
| 151 | + $url = "https://ws.pagseguro.uol.com.br/v2/transactions/notifications/".$notificationCode."?email=".$email."&token=".$token; |
|
| 152 | 152 | |
| 153 | 153 | $curl = curl_init($url); |
| 154 | 154 | curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); |
@@ -156,19 +156,19 @@ discard block |
||
| 156 | 156 | $transaction = curl_exec($curl); |
| 157 | 157 | curl_close($curl); |
| 158 | 158 | |
| 159 | - if ($transaction == 'Unauthorized'){ |
|
| 159 | + if ($transaction == 'Unauthorized') { |
|
| 160 | 160 | // Error=1 Não autorizado. |
| 161 | 161 | $error_returnurl .= "?id={$courseid}&error=1"; |
| 162 | 162 | header("Location: $error_returnurl"); |
| 163 | - exit;//Mantenha essa linha |
|
| 163 | + exit; //Mantenha essa linha |
|
| 164 | 164 | } else { |
| 165 | - $transaction_data = serialize(trim($transaction)); |
|
| 165 | + $transaction_data = serialize(trim($transaction)); |
|
| 166 | 166 | process_moodle($transaction_data, $instanceid, $courseid); |
| 167 | 167 | } |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | function process_moodle($transaction_data, $instanceid, $cid) { |
| 171 | - global $CFG,$USER,$DB,$course; |
|
| 171 | + global $CFG, $USER, $DB, $course; |
|
| 172 | 172 | |
| 173 | 173 | /// Read all the data from pagseguro and get it ready for later; |
| 174 | 174 | /// we expect only valid UTF-8 encoding, it is the responsibility |
@@ -188,16 +188,16 @@ discard block |
||
| 188 | 188 | $transaction_xml = unserialize($transaction_data); |
| 189 | 189 | $transaction = json_decode(json_encode(simplexml_load_string($transaction_xml))); |
| 190 | 190 | |
| 191 | - if($transaction) { |
|
| 191 | + if ($transaction) { |
|
| 192 | 192 | foreach ($transaction as $trans_key => $trans_value) { |
| 193 | 193 | $trans_key = strtolower($trans_key); |
| 194 | - if(!is_object($trans_value)) { |
|
| 194 | + if (!is_object($trans_value)) { |
|
| 195 | 195 | $data->$trans_key = $trans_value; |
| 196 | 196 | } else { |
| 197 | - foreach($trans_value as $key => $value) { |
|
| 197 | + foreach ($trans_value as $key => $value) { |
|
| 198 | 198 | $key = strtolower($key); |
| 199 | - if(is_object($value)) { |
|
| 200 | - foreach($value as $k => $v) { |
|
| 199 | + if (is_object($value)) { |
|
| 200 | + foreach ($value as $k => $v) { |
|
| 201 | 201 | $k = strtolower($k); |
| 202 | 202 | $k = $trans_key.'_'.$key.'_'.$k; |
| 203 | 203 | $data->$k = $v; |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | $data->instanceid = $instanceid; |
| 222 | 222 | $data->timeupdated = time(); |
| 223 | 223 | |
| 224 | - if(!isset($data->reference) && empty($data->reference)) { |
|
| 224 | + if (!isset($data->reference) && empty($data->reference)) { |
|
| 225 | 225 | $data->reference = $plugin->get_config('pagsegurobusiness'); |
| 226 | 226 | } |
| 227 | 227 | |
@@ -297,7 +297,7 @@ discard block |
||
| 297 | 297 | $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); |
| 298 | 298 | |
| 299 | 299 | // Check that amount paid is the correct amount |
| 300 | - if ( (float) $plugin_instance->cost <= 0 ) { |
|
| 300 | + if ((float) $plugin_instance->cost <= 0) { |
|
| 301 | 301 | $cost = (float) $plugin->get_config('cost'); |
| 302 | 302 | } else { |
| 303 | 303 | $cost = (float) $plugin_instance->cost; |