@@ -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); // It is passed to PagSeguro in redirect_url, so always exist. |
|
57 | +$instanceid = optional_param('instanceid', 0, PARAM_INT); // It is passed to PagSeguro in redirect_url, so always exist. |
|
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', 1, PARAM_INT); |
75 | 75 | |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | $notificationCode = optional_param('notificationCode', '', PARAM_RAW); |
78 | 78 | |
79 | 79 | if ($submited) { |
80 | - $url = "https://ws.pagseguro.uol.com.br/v2/checkout/?email=" . urlencode($email) . "&token=" . $token; |
|
80 | + $url = "https://ws.pagseguro.uol.com.br/v2/checkout/?email=".urlencode($email)."&token=".$token; |
|
81 | 81 | |
82 | 82 | $xml = "<?xml version=\"1.0\" encoding=\"$encoding\" standalone=\"yes\"?> |
83 | 83 | <checkout> |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | if (!empty($notificationCode)) { |
125 | 125 | $transaction = null; |
126 | 126 | // Sets the web service URL. |
127 | - $url = "https://pagseguro.uol.com.br/v2/transactions/notifications/" . $notificationCode . "?email=".$email."&token=".$token; |
|
127 | + $url = "https://pagseguro.uol.com.br/v2/transactions/notifications/".$notificationCode."?email=".$email."&token=".$token; |
|
128 | 128 | |
129 | 129 | $curl = curl_init($url); |
130 | 130 | curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); |
@@ -132,19 +132,19 @@ 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 | } |
145 | 145 | |
146 | 146 | function process_moodle($transaction_data, $instanceid, $cid) { |
147 | - global $CFG,$USER,$DB,$course; |
|
147 | + global $CFG, $USER, $DB, $course; |
|
148 | 148 | |
149 | 149 | /// Read all the data from pagseguro and get it ready for later; |
150 | 150 | /// we expect only valid UTF-8 encoding, it is the responsibility |
@@ -164,16 +164,16 @@ discard block |
||
164 | 164 | $transaction_xml = unserialize($transaction_data); |
165 | 165 | $transaction = json_decode(json_encode(simplexml_load_string($transaction_xml))); |
166 | 166 | |
167 | - if($transaction) { |
|
167 | + if ($transaction) { |
|
168 | 168 | foreach ($transaction as $trans_key => $trans_value) { |
169 | 169 | $trans_key = strtolower($trans_key); |
170 | - if(!is_object($trans_value)) { |
|
170 | + if (!is_object($trans_value)) { |
|
171 | 171 | $data->$trans_key = $trans_value; |
172 | 172 | } else { |
173 | - foreach($trans_value as $key => $value) { |
|
173 | + foreach ($trans_value as $key => $value) { |
|
174 | 174 | $key = strtolower($key); |
175 | - if(is_object($value)) { |
|
176 | - foreach($value as $k => $v) { |
|
175 | + if (is_object($value)) { |
|
176 | + foreach ($value as $k => $v) { |
|
177 | 177 | $k = strtolower($k); |
178 | 178 | $k = $trans_key.'_'.$key.'_'.$k; |
179 | 179 | $data->$k = $v; |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | $data->instanceid = $instanceid; |
198 | 198 | $data->timeupdated = time(); |
199 | 199 | |
200 | - if(!isset($data->reference) && empty($data->reference)) { |
|
200 | + if (!isset($data->reference) && empty($data->reference)) { |
|
201 | 201 | $data->reference = $plugin->get_config('pagsegurobusiness'); |
202 | 202 | } |
203 | 203 | |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); |
273 | 273 | |
274 | 274 | // Check that amount paid is the correct amount |
275 | - if ( (float) $plugin_instance->cost <= 0 ) { |
|
275 | + if ((float) $plugin_instance->cost <= 0) { |
|
276 | 276 | $cost = (float) $plugin->get_config('cost'); |
277 | 277 | } else { |
278 | 278 | $cost = (float) $plugin_instance->cost; |