Mundipagg_Integracao - Version 2.7.1

Version Notes

Multi creditcards fix;

Installments fix.

Download this release

Release Info

Developer MundiPagg
Extension Mundipagg_Integracao
Version 2.7.1
Comparing to
See all releases


Code changes from version 2.7.0 to 2.7.1

app/code/community/Uecommerce/Mundipagg/Helper/Installments.php CHANGED
@@ -27,310 +27,318 @@
27
* @package Uecommerce_Mundipagg
28
* @author Uecommerce Dev Team
29
*/
30
31
- class Uecommerce_Mundipagg_Helper_Installments extends Mage_Core_Helper_Abstract
32
- {
33
-
34
- public $displayTotal = true;
35
- protected function _fixQty($qty)
36
- {
37
- return (!empty($qty) ? (float)$qty : null);
38
- }
39
-
40
- public function getInstallments($store = null, $ccType = "installments")
41
- {
42
- $value = Mage::getStoreConfig("payment/mundipagg_standard/".$ccType, $store);
43
- $value = $this->_unserializeValue($value);
44
-
45
- return $value;
46
- }
47
-
48
- protected function _unserializeValue($value)
49
- {
50
- if (is_string($value) && !empty($value)) {
51
- return unserialize($value);
52
- } else {
53
- return array();
54
- }
55
- }
56
-
57
- protected function _isEncodedArrayFieldValue($value)
58
- {
59
- if (!is_array($value)) {
60
- return false;
61
- }
62
-
63
- unset($value['__empty']);
64
-
65
- foreach ($value as $_id => $row) {
66
- if (!is_array($row) || !array_key_exists('installment_boundary', $row) || !array_key_exists('installment_frequency', $row ) || !array_key_exists('installment_interest', $row )) {
67
- return false;
68
- }
69
- }
70
-
71
- return true;
72
- }
73
-
74
- protected function _decodeArrayFieldValue(array $value)
75
- {
76
- $result = array();
77
- unset($value['__empty']);
78
-
79
- foreach ($value as $_id => $row) {
80
- if (!is_array($row) || !array_key_exists('installment_boundary', $row) || !array_key_exists('installment_frequency', $row) || !array_key_exists('installment_interest', $row)) {
81
- continue;
82
- }
83
-
84
- $boundary = $row['installment_boundary'];
85
- $frequency = $row['installment_frequency'];
86
- $interest = $row['installment_interest'];
87
- $result[] = array($boundary,$frequency,$interest);
88
- }
89
-
90
- return $result;
91
- }
92
-
93
- protected function _encodeArrayFieldValue(array $value)
94
- {
95
- $result = array();
96
-
97
- foreach ($value as $triplet) {
98
- $boundary = (isset($triplet[0])) ? $triplet[0] : "";
99
- $frequency = (isset($triplet[1])) ? $triplet[1] : "";
100
- $interest = (isset($triplet[2])) ? $triplet[2] : "";
101
-
102
- $_id = Mage::helper('core')->uniqHash('_');
103
-
104
- $result[$_id] = array(
105
- 'installment_boundary' => $boundary,
106
- 'installment_frequency' => $frequency,
107
- 'installment_interest' => $interest
108
- );
109
- }
110
-
111
- return $result;
112
- }
113
-
114
- protected function _serializeValue($value)
115
- {
116
- return serialize($value);
117
- }
118
-
119
- public function makeArrayFieldValue($value)
120
- {
121
- $value = $this->_unserializeValue($value);
122
-
123
- if (!$this->_isEncodedArrayFieldValue($value)) {
124
- $value = $this->_encodeArrayFieldValue($value);
125
- }
126
-
127
- return $value;
128
- }
129
-
130
- public function makeStorableArrayFieldValue($value)
131
- {
132
- if ($this->_isEncodedArrayFieldValue($value)) {
133
- $value = $this->_decodeArrayFieldValue($value);
134
- }
135
-
136
- $value = $this->_serializeValue($value);
137
-
138
- return $value;
139
- }
140
-
141
- public function getConfigValue($amount, $store = null, $ccType = "installments")
142
- {
143
- $value = $this->getInstallments($store, $ccType);
144
-
145
- if ($this->_isEncodedArrayFieldValue($value)) {
146
- $value = $this->_decodeArrayFieldValue($value);
147
- }
148
-
149
- $cur_minimal_boundary = -1;
150
- $resulting_freq = 1;
151
-
152
- foreach ($value as $row) {
153
- list($boundary,$frequency) = $row;
154
-
155
- if($amount <= $boundary && ($boundary <= $cur_minimal_boundary || $cur_minimal_boundary == -1) ) {
156
- $cur_minimal_boundary = $boundary;
157
- $resulting_freq = $frequency;
158
- }
159
- if($boundary == "" && $cur_minimal_boundary == -1){
160
- $resulting_freq = $frequency;
161
- }
162
- }
163
-
164
- return $resulting_freq;
165
- }
166
-
167
- public function isInstallmentsEnabled($store = null)
168
- {
169
- $value = Mage::getStoreConfig("payment/mundipagg_standard/enable_installments", $store);
170
-
171
- return $value;
172
- }
173
-
174
- public function getMaxInstallments($ccType = null,$amount = null)
175
- {
176
- $session = Mage::getSingleton('admin/session');
177
-
178
- if ($session->isLoggedIn()) {
179
- $quote = Mage::getSingleton('adminhtml/session_quote')->getQuote();
180
- } else {
181
- $quote = (Mage::getModel('checkout/type_onepage') !== false)? Mage::getModel('checkout/type_onepage')->getQuote(): Mage::getModel('checkout/session')->getQuote();;
182
- }
183
-
184
- if(!$amount) {
185
- // Get pre-authorized amount
186
- $authorizedAmount = Mage::getSingleton('checkout/session')->getAuthorizedAmount();
187
-
188
- $amount = (double)$quote->getGrandTotal()-$quote->getMundipaggInterest()-$authorizedAmount;
189
- }
190
-
191
- $amount = str_replace(',','.',$amount);
192
- $ccTypeInstallments = "installments_".$ccType;
193
-
194
- $all_installments = $this->getInstallments(null, $ccTypeInstallments);
195
-
196
- if(empty($all_installments)) {
197
- $ccTypeInstallments = null;
198
- } else {
199
- $max_installments = $this->getConfigValue($amount, null, $ccTypeInstallments);
200
- }
201
-
202
- if($ccTypeInstallments == null) {
203
- $max_installments = $this->getConfigValue($amount, null);
204
- $all_installments = $this->getInstallments();
205
- }
206
-
207
- if(!$max_installments){
208
- $max_installments = 1;
209
- }
210
-
211
- return $max_installments;
212
- }
213
-
214
- public function getInstallmentForCreditCardType($ccType = null,$amount = null)
215
- {
216
- $session = Mage::getSingleton('admin/session');
217
-
218
- if ($session->isLoggedIn()) {
219
- $quote = Mage::getSingleton('adminhtml/session_quote')->getQuote();
220
- } else {
221
- $quote = (Mage::getModel('checkout/type_onepage') !== false)? Mage::getModel('checkout/type_onepage')->getQuote(): Mage::getModel('checkout/session')->getQuote();
222
- }
223
-
224
- if(!$amount) {
225
- // Get pre-authorized amount
226
- $authorizedAmount = Mage::getSingleton('checkout/session')->getAuthorizedAmount();
227
-
228
- $amount = (double)$quote->getGrandTotal()-$quote->getMundipaggInterest()-$authorizedAmount;
229
- }
230
-
231
- $result = array();
232
- $result[1] = "1x ".Mage::helper('core')->formatPrice($amount, false);
233
-
234
- $amount = str_replace(',','.',$amount);
235
- $ccTypeInstallments = "installments_".$ccType;
236
-
237
- $all_installments = $this->getInstallments(null, $ccTypeInstallments);
238
-
239
- if(empty($all_installments)) {
240
- $ccTypeInstallments = null;
241
- } else {
242
- $max_installments = $this->getConfigValue($amount, null, $ccTypeInstallments);
243
- }
244
-
245
- // Fallback to the default installments if creditcard type has no one configured
246
- if($ccTypeInstallments == null) {
247
- $max_installments = $this->getConfigValue($amount, null);
248
- $all_installments = $this->getInstallments();
249
- }
250
- $displayTotal = Mage::getStoreConfig('payment/mundipagg_standard/display_total');
251
- if(!$max_installments){
252
- $max_installments = 0;
253
- }
254
- // result array here
255
- for($i=1;$i<=$max_installments;$i++) {
256
- // check if installment has extra interest
257
- $key = $i-1;
258
- if(!array_key_exists($key,$all_installments)){
259
- $all_installments[$key] = array();
260
- }
261
- $installment = $all_installments[$key];
262
- if(isset($installment[2]) && $installment[2] > 0) {
263
- $total_amount_with_interest = $amount + ($amount * ($installment[2] / 100));
264
- $message = ' '.$this->__('with interest');
265
- if($displayTotal && $this->displayTotal){
266
- $message .= ' (Total: '.Mage::helper('core')->formatPrice(round((($total_amount_with_interest)/$i),2) * $i,false).')';
267
- }
268
- } else {
269
- $total_amount_with_interest = $amount;
270
- $message = ' '.$this->__('without interest');
271
- }
272
-
273
- $partial_amount = ((double)$total_amount_with_interest)/$i;
274
- $result[(string)$i] = $i."x ".Mage::helper('core')->formatPrice($partial_amount, false).$message;
275
- }
276
-
277
-
278
-
279
- return $result;
280
- }
281
-
282
- public function getInterestForCard($installments = 1 , $ccType = null,$grandTotal = null)
283
- {
284
- $session = Mage::getSingleton('admin/session');
285
-
286
- if ($session->isLoggedIn()) {
287
- $quote = Mage::getSingleton('adminhtml/session_quote')->getQuote();
288
- } else {
289
- $quote = Mage::getSingleton('checkout/session')->getQuote();
290
- }
291
-
292
- if($installments > 0) {
293
- $ccTypeInstallments = "installments_".$ccType;
294
//Mage::log( 'ccTypeInstallments' );
295
//Mage::log( print_r($ccTypeInstallments,1) );
296
- $all_installments = $this->getInstallments(null, $ccTypeInstallments);
297
//Mage::log( 'all_installments' );
298
//Mage::log( print_r($all_installments,1) );
299
- if(empty($all_installments)) {
300
- $all_installments = $this->getInstallments();
301
- }
302
303
//Mage::log( 'if empty all_installments' );
304
//Mage::log( print_r($all_installments,1) );
305
306
- $installmentKey = $installments - 1;
307
308
- if(!$installmentKey){
309
- return 0;
310
- }
311
- $installment = $all_installments[$installmentKey];
312
313
- if($installment != null && is_array($installment)) {
314
- // check if interest rate is filled in
315
- if(isset($installment[2]) && $installment[2] > 0) {
316
- $interestRate = $installment[2];
317
318
- if(!$grandTotal) {
319
- $grandTotal = $quote->getGrandTotal();
320
- }
321
- $grandTotal = str_replace(',','.',$grandTotal);
322
323
- $grandTotalInterest = $grandTotal + ($grandTotal * ($interestRate / 100));
324
325
- $fee = (round(($grandTotalInterest/$installments),2) * $installments) - $grandTotal;
326
327
- $balance = round($fee,2);
328
329
- return $balance;
330
- }
331
- }
332
- }
333
334
- return 0;
335
- }
336
}
27
* @package Uecommerce_Mundipagg
28
* @author Uecommerce Dev Team
29
*/
30
+ class Uecommerce_Mundipagg_Helper_Installments extends Mage_Core_Helper_Abstract {
31
32
+ public $displayTotal = true;
33
+
34
+ protected function _fixQty($qty) {
35
+ return (!empty($qty) ? (float)$qty : null);
36
+ }
37
+
38
+ public function getInstallments($store = null, $ccType = "installments") {
39
+ $value = Mage::getStoreConfig("payment/mundipagg_standard/" . $ccType, $store);
40
+ $value = $this->_unserializeValue($value);
41
+
42
+ return $value;
43
+ }
44
+
45
+ protected function _unserializeValue($value) {
46
+ if (is_string($value) && !empty($value)) {
47
+ return unserialize($value);
48
+ } else {
49
+ return array();
50
+ }
51
+ }
52
+
53
+ protected function _isEncodedArrayFieldValue($value) {
54
+ if (!is_array($value)) {
55
+ return false;
56
+ }
57
+
58
+ unset($value['__empty']);
59
+
60
+ foreach ($value as $_id => $row) {
61
+ if (!is_array($row) || !array_key_exists('installment_boundary', $row) || !array_key_exists('installment_frequency', $row) || !array_key_exists('installment_interest', $row)) {
62
+ return false;
63
+ }
64
+ }
65
+
66
+ return true;
67
+ }
68
+
69
+ protected function _decodeArrayFieldValue(array $value) {
70
+ $result = array();
71
+ unset($value['__empty']);
72
+
73
+ foreach ($value as $_id => $row) {
74
+ if (!is_array($row) || !array_key_exists('installment_boundary', $row) || !array_key_exists('installment_frequency', $row) || !array_key_exists('installment_interest', $row)) {
75
+ continue;
76
+ }
77
+
78
+ $boundary = $row['installment_boundary'];
79
+ $frequency = $row['installment_frequency'];
80
+ $interest = $row['installment_interest'];
81
+ $result[] = array($boundary, $frequency, $interest);
82
+ }
83
+
84
+ return $result;
85
+ }
86
+
87
+ protected function _encodeArrayFieldValue(array $value) {
88
+ $result = array();
89
+
90
+ foreach ($value as $triplet) {
91
+ $boundary = (isset($triplet[0])) ? $triplet[0] : "";
92
+ $frequency = (isset($triplet[1])) ? $triplet[1] : "";
93
+ $interest = (isset($triplet[2])) ? $triplet[2] : "";
94
+
95
+ $_id = Mage::helper('core')->uniqHash('_');
96
+
97
+ $result[$_id] = array(
98
+ 'installment_boundary' => $boundary,
99
+ 'installment_frequency' => $frequency,
100
+ 'installment_interest' => $interest
101
+ );
102
+ }
103
+
104
+ return $result;
105
+ }
106
+
107
+ protected function _serializeValue($value) {
108
+ return serialize($value);
109
+ }
110
+
111
+ public function makeArrayFieldValue($value) {
112
+ $value = $this->_unserializeValue($value);
113
+
114
+ if (!$this->_isEncodedArrayFieldValue($value)) {
115
+ $value = $this->_encodeArrayFieldValue($value);
116
+ }
117
+
118
+ return $value;
119
+ }
120
+
121
+ public function makeStorableArrayFieldValue($value) {
122
+ if ($this->_isEncodedArrayFieldValue($value)) {
123
+ $value = $this->_decodeArrayFieldValue($value);
124
+ }
125
+
126
+ $value = $this->_serializeValue($value);
127
+
128
+ return $value;
129
+ }
130
+
131
+ public function getConfigValue($amount, $store = null, $ccType = "installments") {
132
+ $value = $this->getInstallments($store, $ccType);
133
+
134
+ if ($this->_isEncodedArrayFieldValue($value)) {
135
+ $value = $this->_decodeArrayFieldValue($value);
136
+ }
137
+
138
+ $cur_minimal_boundary = -1;
139
+ $resulting_freq = 1;
140
+
141
+ foreach ($value as $row) {
142
+ list($boundary, $frequency) = $row;
143
+
144
+ if ($amount <= $boundary && ($boundary <= $cur_minimal_boundary || $cur_minimal_boundary == -1)) {
145
+ $cur_minimal_boundary = $boundary;
146
+ $resulting_freq = $frequency;
147
+ }
148
+ if ($boundary == "" && $cur_minimal_boundary == -1) {
149
+ $resulting_freq = $frequency;
150
+ }
151
+ }
152
+
153
+ return $resulting_freq;
154
+ }
155
+
156
+ public function isInstallmentsEnabled($store = null) {
157
+ $value = Mage::getStoreConfig("payment/mundipagg_standard/enable_installments", $store);
158
+
159
+ return $value;
160
+ }
161
+
162
+ public function getMaxInstallments($ccType = null, $amount = null) {
163
+ $session = Mage::getSingleton('admin/session');
164
+
165
+ if ($session->isLoggedIn()) {
166
+ $quote = Mage::getSingleton('adminhtml/session_quote')->getQuote();
167
+ } else {
168
+ $quote = (Mage::getModel('checkout/type_onepage') !== false) ? Mage::getModel('checkout/type_onepage')->getQuote() : Mage::getModel('checkout/session')->getQuote();;
169
+ }
170
+
171
+ if (!$amount) {
172
+ // Get pre-authorized amount
173
+ $authorizedAmount = Mage::getSingleton('checkout/session')->getAuthorizedAmount();
174
+
175
+ $amount = (double)$quote->getGrandTotal() - $quote->getMundipaggInterest() - $authorizedAmount;
176
+ }
177
+
178
+ $amount = str_replace(',', '.', $amount);
179
+ $ccTypeInstallments = "installments_" . $ccType;
180
+
181
+ $all_installments = $this->getInstallments(null, $ccTypeInstallments);
182
+
183
+ if (empty($all_installments)) {
184
+ $ccTypeInstallments = null;
185
+ } else {
186
+ $max_installments = $this->getConfigValue($amount, null, $ccTypeInstallments);
187
+ }
188
+
189
+ if ($ccTypeInstallments == null) {
190
+ $max_installments = $this->getConfigValue($amount, null);
191
+ $all_installments = $this->getInstallments();
192
+ }
193
+
194
+ if (!$max_installments) {
195
+ $max_installments = 1;
196
+ }
197
+
198
+ return $max_installments;
199
+ }
200
+
201
+ public function getInstallmentForCreditCardType($ccType = null, $amount = null) {
202
+ $session = Mage::getSingleton('admin/session');
203
+
204
+ if ($session->isLoggedIn()) {
205
+ $quote = Mage::getSingleton('adminhtml/session_quote')->getQuote();
206
+ } else {
207
+ $quote = (Mage::getModel('checkout/type_onepage') !== false) ? Mage::getModel('checkout/type_onepage')->getQuote() : Mage::getModel('checkout/session')->getQuote();
208
+ }
209
+
210
+ if (!$amount) {
211
+ // Get pre-authorized amount
212
+ $authorizedAmount = Mage::getSingleton('checkout/session')->getAuthorizedAmount();
213
+ $amount = (double)$quote->getGrandTotal() - $quote->getMundipaggInterest() - $authorizedAmount;
214
+ }
215
+
216
+ $result = array();
217
+ $amount = str_replace(',', '.', $amount);
218
+ $ccTypeInstallments = "installments_" . $ccType;
219
+
220
+ $all_installments = $this->getInstallments(null, $ccTypeInstallments);
221
+
222
+ if (empty($all_installments)) {
223
+ $ccTypeInstallments = null;
224
+ } else {
225
+ $max_installments = $this->getConfigValue($amount, null, $ccTypeInstallments);
226
+ }
227
+
228
+ // Fallback to the default installments if creditcard type has no one configured
229
+ if ($ccTypeInstallments == null) {
230
+ $max_installments = $this->getConfigValue($amount, null);
231
+ $all_installments = $this->getInstallments();
232
+ }
233
+
234
+ if (!$max_installments) {
235
+ $max_installments = 0;
236
+ }
237
+
238
+ // result array here
239
+ for ($i = 1; $i <= $max_installments; $i++) {
240
+ // check if installment has extra interest
241
+ $key = $i - 1;
242
+
243
+ if (!array_key_exists($key, $all_installments)) {
244
+ $all_installments[$key] = array();
245
+ }
246
+
247
+ $installment = $all_installments[$key];
248
+
249
+ if (isset($installment[2]) && $installment[2] > 0) {
250
+ $total_amount_with_interest = $this->priceFormatter($amount + ($amount * ($installment[2] / 100)));
251
+ $message = $this->__('with interest');
252
+
253
+ // if ($displayTotal && $this->displayTotal) {
254
+ // $message .= ' (Total: ' . Mage::helper('core')->formatPrice(round((($total_amount_with_interest) / $i), 2) * $i, false) . ')';
255
+ // }
256
+
257
+ } else {
258
+ $total_amount_with_interest = $amount;
259
+ $message = $this->__('without interest');
260
+ }
261
+
262
+ // $coreHelper = Mage::helper('core');
263
+ // $partial_amount = $this->priceFormatter($total_amount_with_interest / $i);
264
+
265
+ $accurPriceWithInterest = $this->priceFormatter($total_amount_with_interest);
266
+ $accurInstallmentAmount = $this->priceFormatter($accurPriceWithInterest / $i);
267
+ $accurParcelsTotals = $this->priceFormatter($accurInstallmentAmount * $i);
268
+ $accuDifference = $this->priceFormatter($accurPriceWithInterest - $accurParcelsTotals);
269
+
270
+ $accurParcelsTotals += $accuDifference;
271
+
272
+ $currencyCode = Mage::app()->getStore()->getCurrentCurrencyCode();
273
+ $currencySymbol = Mage::app()->getLocale()->currency($currencyCode)->getSymbol();
274
+
275
+ $accurInstallmentAmount = number_format($accurInstallmentAmount, 2, ',', '');
276
+ $accurParcelsTotals = number_format($accurParcelsTotals, 2, ',', '');
277
+
278
+ $message = "{$i} x {$currencySymbol} {$accurInstallmentAmount} {$message} ";
279
+ $message .= "(Total: {$accurParcelsTotals})";
280
+
281
+ $result[$i] = $message;
282
+ }
283
+
284
+ return $result;
285
+ }
286
+
287
+ private function priceFormatter($number) {
288
+ return round($number, 2, PHP_ROUND_HALF_DOWN);
289
+ }
290
+
291
+ public function getInterestForCard($installments = 1, $ccType = null, $grandTotal = null) {
292
+ $session = Mage::getSingleton('admin/session');
293
+
294
+ if ($session->isLoggedIn()) {
295
+ $quote = Mage::getSingleton('adminhtml/session_quote')->getQuote();
296
+ } else {
297
+ $quote = Mage::getSingleton('checkout/session')->getQuote();
298
+ }
299
+
300
+ if ($installments > 0) {
301
+ $ccTypeInstallments = "installments_" . $ccType;
302
//Mage::log( 'ccTypeInstallments' );
303
//Mage::log( print_r($ccTypeInstallments,1) );
304
+ $all_installments = $this->getInstallments(null, $ccTypeInstallments);
305
//Mage::log( 'all_installments' );
306
//Mage::log( print_r($all_installments,1) );
307
+ if (empty($all_installments)) {
308
+ $all_installments = $this->getInstallments();
309
+ }
310
311
//Mage::log( 'if empty all_installments' );
312
//Mage::log( print_r($all_installments,1) );
313
314
+ $installmentKey = $installments - 1;
315
316
+ if (!$installmentKey) {
317
+ return 0;
318
+ }
319
+ $installment = $all_installments[$installmentKey];
320
321
+ if ($installment != null && is_array($installment)) {
322
+ // check if interest rate is filled in
323
+ if (isset($installment[2]) && $installment[2] > 0) {
324
+ $interestRate = $installment[2];
325
326
+ if (!$grandTotal) {
327
+ $grandTotal = $quote->getGrandTotal();
328
+ }
329
+ $grandTotal = str_replace(',', '.', $grandTotal);
330
331
+ $grandTotalInterest = $grandTotal + ($grandTotal * ($interestRate / 100));
332
333
+ $fee = (round(($grandTotalInterest / $installments), 2) * $installments) - $grandTotal;
334
335
+ $balance = round($fee, 2);
336
337
+ return $balance;
338
+ }
339
+ }
340
+ }
341
342
+ return 0;
343
+ }
344
}
app/code/community/Uecommerce/Mundipagg/Helper/Log.php CHANGED
@@ -20,6 +20,10 @@ class Uecommerce_Mundipagg_Helper_Log extends Mage_Core_Helper_Abstract {
20
$this->logLabel = $logLabel;
21
}
22
23
public function info($msg) {
24
$this->level = Zend_Log::INFO;
25
$this->write($msg);
20
$this->logLabel = $logLabel;
21
}
22
23
+ public function getLogLabel() {
24
+ return $this->logLabel;
25
+ }
26
+
27
public function info($msg) {
28
$this->level = Zend_Log::INFO;
29
$this->write($msg);
app/code/community/Uecommerce/Mundipagg/Model/Api.php CHANGED
@@ -29,6 +29,10 @@
29
*/
30
class Uecommerce_Mundipagg_Model_Api extends Uecommerce_Mundipagg_Model_Standard {
31
32
private $helperUtil;
33
private $modelStandard;
34
private $debugEnabled;
@@ -1121,18 +1125,17 @@ class Uecommerce_Mundipagg_Model_Api extends Uecommerce_Mundipagg_Model_Standard
1121
1122
try {
1123
// Get Webservice URL
1124
- $url = $standard->getURL() . '/' . $data['ManageOrderOperationEnum'];
1125
1126
unset($data['ManageOrderOperationEnum']);
1127
1128
// Get store key
1129
$key = $standard->getMerchantKey();
1130
-
1131
$dataToPost = json_encode($data);
1132
1133
if ($standard->getDebug() == 1) {
1134
- $helperUtil = new Uecommerce_Mundipagg_Helper_Util();
1135
-
1136
$helperLog->debug("Request:\n{$helperUtil->jsonEncodePretty($data)}\n");
1137
}
1138
@@ -1144,27 +1147,19 @@ class Uecommerce_Mundipagg_Model_Api extends Uecommerce_Mundipagg_Model_Standard
1144
1145
// Set the url, number of POST vars, POST data
1146
curl_setopt($ch, CURLOPT_URL, $url);
1147
-
1148
curl_setopt($ch, CURLOPT_POSTFIELDS, $dataToPost);
1149
-
1150
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
1151
1152
// Execute post
1153
$_response = curl_exec($ch);
1154
1155
// Close connection
1156
curl_close($ch);
1157
1158
if ($standard->getDebug() == 1) {
1159
- $xml = simplexml_load_string($_response);
1160
- $domXml = new DOMDocument('1.0');
1161
-
1162
- $domXml->formatOutput = true;
1163
- $domXml->loadXML($xml->asXML());
1164
-
1165
- $xml = $domXml->saveXML();
1166
-
1167
- $helperLog->debug("Response:\n{$xml}\n");
1168
}
1169
1170
// Return
@@ -1267,6 +1262,7 @@ class Uecommerce_Mundipagg_Model_Api extends Uecommerce_Mundipagg_Model_Standard
1267
$returnMessage = "OK | {$returnMessageLabel} | Order already canceled.";
1268
1269
$helperLog->info($returnMessage);
1270
return $returnMessage;
1271
}
1272
@@ -1325,6 +1321,59 @@ class Uecommerce_Mundipagg_Model_Api extends Uecommerce_Mundipagg_Model_Standard
1325
1326
switch ($lowerStatus) {
1327
case 'captured':
1328
case 'paid':
1329
case 'overpaid':
1330
if ($order->canUnhold()) {
@@ -1566,88 +1615,89 @@ class Uecommerce_Mundipagg_Model_Api extends Uecommerce_Mundipagg_Model_Standard
1566
}
1567
1568
/**
1569
- * Status reference:
1570
- * http://docs.mundipagg.com/docs/enumera%C3%A7%C3%B5es
1571
- *
1572
- * @param array $postData
1573
- * @TODO refatorar o tratamento das transacoes com este metodo
1574
*/
1575
- private function processCreditCardTransactionNotification($postData) {
1576
- $status = $postData['CreditCardTransaction']['CreditCardTransactionStatus'];
1577
- $transactionKey = $postData['CreditCardTransaction']['TransactionKey'];
1578
- $capturedAmountInCents = $postData['CreditCardTransaction']['CapturedAmountInCents'];
1579
- $ccTransactionEnum = new Uecommerce_Mundipagg_Model_Enum_CreditCardTransactionStatusEnum();
1580
- $helperLog = new Uecommerce_Mundipagg_Helper_Log(__METHOD__);
1581
1582
- switch ($status) {
1583
- case $ccTransactionEnum::AUTHORIZED_PENDING_CAPTURE:
1584
- break;
1585
1586
- case $ccTransactionEnum::CAPTURED:
1587
- break;
1588
1589
- case $ccTransactionEnum::PARTIAL_CAPTURE:
1590
- break;
1591
1592
- case $ccTransactionEnum::NOT_AUTHORIZED:
1593
- break;
1594
1595
- case $ccTransactionEnum::VOIDED:
1596
- break;
1597
1598
- case $ccTransactionEnum::PENDING_VOID:
1599
break;
1600
1601
- case $ccTransactionEnum::PARTIAL_VOID:
1602
- break;
1603
1604
- case $ccTransactionEnum::REFUNDED:
1605
- break;
1606
1607
- case $ccTransactionEnum::PENDING_REFUND:
1608
- break;
1609
1610
- case $ccTransactionEnum::PARTIAL_REFUNDED:
1611
- break;
1612
1613
- case $ccTransactionEnum::WITH_ERROR:
1614
- break;
1615
1616
- case $ccTransactionEnum::NOT_FOUND_ACQUIRER:
1617
- break;
1618
1619
- case $ccTransactionEnum::PENDING_AUTHORIZE:
1620
- break;
1621
1622
- case $ccTransactionEnum::INVALID:
1623
- break;
1624
- }
1625
- }
1626
1627
- /**
1628
- * @author Ruan Azevedo
1629
- * @since 2016-07-20
1630
- * Status reference:
1631
- * http://docs.mundipagg.com/docs/enumera%C3%A7%C3%B5es
1632
- * @TODO refatorar o tratamento das transacoes de boleto com este metodo
1633
- */
1634
- private function processBoletoTransactionNotification() {
1635
- $status = '';
1636
- $boletoTransactionEnum = new Uecommerce_Mundipagg_Model_Enum_BoletoTransactionStatusEnum();
1637
1638
- switch ($status) {
1639
- case $boletoTransactionEnum::GENERATED:
1640
- break;
1641
1642
- case $boletoTransactionEnum::PAID:
1643
- break;
1644
1645
- case $boletoTransactionEnum::UNDERPAID:
1646
- break;
1647
1648
- case $boletoTransactionEnum::OVERPAID:
1649
- break;
1650
- }
1651
}
1652
1653
/**
@@ -1778,6 +1828,91 @@ class Uecommerce_Mundipagg_Model_Api extends Uecommerce_Mundipagg_Model_Standard
1778
return array('result' => simplexml_load_string($_response));
1779
}
1780
1781
/**
1782
* Mail error to Mage::getStoreConfig('trans_email/ident_custom1/email')
1783
*
@@ -1921,7 +2056,7 @@ class Uecommerce_Mundipagg_Model_Api extends Uecommerce_Mundipagg_Model_Standard
1921
$requestRawJson = json_encode($dataToPost);
1922
$requestJSON = $this->helperUtil->jsonEncodePretty($_logRequest);
1923
1924
- $helperLog->debug("Request: {$requestJSON}\n");
1925
}
1926
1927
$ch = curl_init();
@@ -1945,7 +2080,7 @@ class Uecommerce_Mundipagg_Model_Api extends Uecommerce_Mundipagg_Model_Standard
1945
$responseArray = json_decode($responseJSON, true);
1946
1947
if ($debug) {
1948
- $helperLog->debug("Response: {$responseJSON} \n");
1949
}
1950
1951
$responseData = array(
29
*/
30
class Uecommerce_Mundipagg_Model_Api extends Uecommerce_Mundipagg_Model_Standard {
31
32
+ const TRANSACTION_NOT_FOUND = "Transaction not found";
33
+ const TRANSACTION_ALREADY_CAPTURED = "Transaction already captured";
34
+ const TRANSACTION_CAPTURED = "Transaction captured";
35
+
36
private $helperUtil;
37
private $modelStandard;
38
private $debugEnabled;
1125
1126
try {
1127
// Get Webservice URL
1128
+ $url = "{$standard->getURL()}{$data['ManageOrderOperationEnum']}";
1129
1130
unset($data['ManageOrderOperationEnum']);
1131
1132
// Get store key
1133
$key = $standard->getMerchantKey();
1134
$dataToPost = json_encode($data);
1135
+ $helperUtil = new Uecommerce_Mundipagg_Helper_Util();
1136
1137
if ($standard->getDebug() == 1) {
1138
+ $helperLog->debug("Url: {$url}");
1139
$helperLog->debug("Request:\n{$helperUtil->jsonEncodePretty($data)}\n");
1140
}
1141
1147
1148
// Set the url, number of POST vars, POST data
1149
curl_setopt($ch, CURLOPT_URL, $url);
1150
curl_setopt($ch, CURLOPT_POSTFIELDS, $dataToPost);
1151
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
1152
1153
// Execute post
1154
$_response = curl_exec($ch);
1155
+ $xml = simplexml_load_string($_response);
1156
+ $json = $helperUtil->jsonEncodePretty($xml);
1157
1158
// Close connection
1159
curl_close($ch);
1160
1161
if ($standard->getDebug() == 1) {
1162
+ $helperLog->debug("Response:\n{$json}\n");
1163
}
1164
1165
// Return
1262
$returnMessage = "OK | {$returnMessageLabel} | Order already canceled.";
1263
1264
$helperLog->info($returnMessage);
1265
+
1266
return $returnMessage;
1267
}
1268
1321
1322
switch ($lowerStatus) {
1323
case 'captured':
1324
+ $amountToCapture = $capturedAmountInCents * 0.01;
1325
+
1326
+ try {
1327
+ $return = $this->captureTransaction($order, $amountToCapture, $transactionKey);
1328
+
1329
+ } catch (Exception $e) {
1330
+ $orderPayment = new Uecommerce_Mundipagg_Model_Order_Payment();
1331
+ $error = $e->getMessage();
1332
+
1333
+ $helperLog->setLogLabel("#{$orderReference} | {$transactionKey}");
1334
+
1335
+ switch ($error) {
1336
+ case $orderPayment::ERR_CANNOT_CREATE_INVOICE:
1337
+ $error = "Can't created invoice";
1338
+ $helperLog->error($error);
1339
+ break;
1340
+
1341
+ case $orderPayment::ERR_CANNOT_CREATE_INVOICE_WITHOUT_PRODUCTS:
1342
+ $error = "Can't create invoice without products";
1343
+ $helperLog->error($error);
1344
+ break;
1345
+
1346
+ default:
1347
+ $error = "Can't create invoice, unexpected error: {$error}";
1348
+ $helperLog->error($error);
1349
+ }
1350
+
1351
+ $returnMessage = "KO | #{$orderReference} | Can't capture transaction {$transactionKey} | {$error}";
1352
+
1353
+ $helperLog->setLogLabel("");
1354
+ $helperLog->info($returnMessage);
1355
+
1356
+ return $returnMessage;
1357
+ }
1358
+
1359
+ switch ($return) {
1360
+ case self::TRANSACTION_ALREADY_CAPTURED:
1361
+ $returnMessage = "OK | #{$orderReference} | {$transactionKey} | " . self::TRANSACTION_ALREADY_CAPTURED;
1362
+ $helperLog->info($returnMessage);
1363
+
1364
+ return $returnMessage;
1365
+ break;
1366
+
1367
+ case self::TRANSACTION_CAPTURED:
1368
+ $returnMessage = "OK | #{$orderReference} | {$transactionKey} | " . self::TRANSACTION_CAPTURED;
1369
+ $helperLog->info($returnMessage);
1370
+
1371
+ return $returnMessage;
1372
+ break;
1373
+ }
1374
+
1375
+ break;
1376
+
1377
case 'paid':
1378
case 'overpaid':
1379
if ($order->canUnhold()) {
1615
}
1616
1617
/**
1618
+ * @param Mage_Sales_Model_Order $order
1619
+ * @param $amountToCapture
1620
+ * @param $transactionKey
1621
+ * @throws RuntimeException
1622
+ * @return string
1623
*/
1624
+ private function captureTransaction(Mage_Sales_Model_Order $order, $amountToCapture, $transactionKey) {
1625
+ $log = new Uecommerce_Mundipagg_Helper_Log(__METHOD__);
1626
+ $log->setLogLabel("#{$order->getIncrementId()} | {$transactionKey}");
1627
1628
+ $totalPaid = $order->getTotalPaid();
1629
+ $grandTotal = $order->getGrandTotal();
1630
+ $createInvoice = false;
1631
+ $transaction = null;
1632
1633
+ if (is_null($totalPaid)) {
1634
+ $totalPaid = 0;
1635
+ }
1636
1637
+ $totalPaid += $amountToCapture;
1638
1639
+ $transactions = Mage::getModel('sales/order_payment_transaction')
1640
+ ->getCollection()
1641
+ ->addAttributeToFilter('order_id', array('eq' => $order->getEntityId()));
1642
1643
+ foreach ($transactions as $i) {
1644
+ $orderTransactionKey = $i->getAdditionalInformation('TransactionKey');
1645
1646
+ // transactionKey found
1647
+ if ($orderTransactionKey == $transactionKey) {
1648
+ $transaction = $i;
1649
break;
1650
+ }
1651
+ }
1652
1653
+ if (is_null($transaction)) {
1654
+ Mage::throwException(self::TRANSACTION_NOT_FOUND);
1655
+ }
1656
1657
+ if ($transaction->getIsClosed() == '1') {
1658
+ return self::TRANSACTION_ALREADY_CAPTURED;
1659
+ }
1660
1661
+ if ($totalPaid < $grandTotal) {
1662
+ $order->setStatus('underpaid');
1663
+ } elseif ($totalPaid > $grandTotal) {
1664
+ $order->setStatus('overpaid');
1665
+ }
1666
1667
+ if ($totalPaid == $grandTotal) {
1668
+ // reset total paid, preparing to invoice
1669
+ $createInvoice = true;
1670
+ }
1671
1672
+ $orderPayment = new Uecommerce_Mundipagg_Model_Order_Payment();
1673
1674
+ try {
1675
+ if($createInvoice){
1676
+ $invoice = $orderPayment->createInvoice($order);
1677
+ $log->info("Invoice {$invoice->getIncrementId()} created");
1678
+ }
1679
1680
+ $resource = Mage::getSingleton('core/resource');
1681
+ $conn = $resource->getConnection('core_write');
1682
+ $query = "UPDATE sales_payment_transaction SET is_closed = TRUE WHERE transaction_id={$transaction->getId()}";
1683
1684
+ $conn->query($query);
1685
+ $log->info("Magento payment transaction closed");
1686
1687
+ $order->setTotalPaid($totalPaid);
1688
+ $order->save();
1689
1690
+ } catch (Exception $e) {
1691
+ throw new RuntimeException($e->getMessage());
1692
+ }
1693
1694
+ $log->info("Captured amount: {$amountToCapture}");
1695
1696
+ return self::TRANSACTION_CAPTURED;
1697
+ }
1698
+
1699
+ private function queryTransactions() {
1700
1701
}
1702
1703
/**
1828
return array('result' => simplexml_load_string($_response));
1829
}
1830
1831
+ /**
1832
+ * Status reference:
1833
+ * http://docs.mundipagg.com/docs/enumera%C3%A7%C3%B5es
1834
+ *
1835
+ * @param array $postData
1836
+ * @TODO refatorar o tratamento das transacoes com este metodo
1837
+ */
1838
+ private function processCreditCardTransactionNotification($postData) {
1839
+ $status = $postData['CreditCardTransaction']['CreditCardTransactionStatus'];
1840
+ $transactionKey = $postData['CreditCardTransaction']['TransactionKey'];
1841
+ $capturedAmountInCents = $postData['CreditCardTransaction']['CapturedAmountInCents'];
1842
+ $ccTransactionEnum = new Uecommerce_Mundipagg_Model_Enum_CreditCardTransactionStatusEnum();
1843
+ $helperLog = new Uecommerce_Mundipagg_Helper_Log(__METHOD__);
1844
+
1845
+ switch ($status) {
1846
+ case $ccTransactionEnum::AUTHORIZED_PENDING_CAPTURE:
1847
+ break;
1848
+
1849
+ case $ccTransactionEnum::CAPTURED:
1850
+ break;
1851
+
1852
+ case $ccTransactionEnum::PARTIAL_CAPTURE:
1853
+ break;
1854
+
1855
+ case $ccTransactionEnum::NOT_AUTHORIZED:
1856
+ break;
1857
+
1858
+ case $ccTransactionEnum::VOIDED:
1859
+ break;
1860
+
1861
+ case $ccTransactionEnum::PENDING_VOID:
1862
+ break;
1863
+
1864
+ case $ccTransactionEnum::PARTIAL_VOID:
1865
+ break;
1866
+
1867
+ case $ccTransactionEnum::REFUNDED:
1868
+ break;
1869
+
1870
+ case $ccTransactionEnum::PENDING_REFUND:
1871
+ break;
1872
+
1873
+ case $ccTransactionEnum::PARTIAL_REFUNDED:
1874
+ break;
1875
+
1876
+ case $ccTransactionEnum::WITH_ERROR:
1877
+ break;
1878
+
1879
+ case $ccTransactionEnum::NOT_FOUND_ACQUIRER:
1880
+ break;
1881
+
1882
+ case $ccTransactionEnum::PENDING_AUTHORIZE:
1883
+ break;
1884
+
1885
+ case $ccTransactionEnum::INVALID:
1886
+ break;
1887
+ }
1888
+ }
1889
+
1890
+ /**
1891
+ * @author Ruan Azevedo
1892
+ * @since 2016-07-20
1893
+ * Status reference:
1894
+ * http://docs.mundipagg.com/docs/enumera%C3%A7%C3%B5es
1895
+ * @TODO refatorar o tratamento das transacoes de boleto com este metodo
1896
+ */
1897
+ private function processBoletoTransactionNotification() {
1898
+ $status = '';
1899
+ $boletoTransactionEnum = new Uecommerce_Mundipagg_Model_Enum_BoletoTransactionStatusEnum();
1900
+
1901
+ switch ($status) {
1902
+ case $boletoTransactionEnum::GENERATED:
1903
+ break;
1904
+
1905
+ case $boletoTransactionEnum::PAID:
1906
+ break;
1907
+
1908
+ case $boletoTransactionEnum::UNDERPAID:
1909
+ break;
1910
+
1911
+ case $boletoTransactionEnum::OVERPAID:
1912
+ break;
1913
+ }
1914
+ }
1915
+
1916
/**
1917
* Mail error to Mage::getStoreConfig('trans_email/ident_custom1/email')
1918
*
2056
$requestRawJson = json_encode($dataToPost);
2057
$requestJSON = $this->helperUtil->jsonEncodePretty($_logRequest);
2058
2059
+ $helperLog->debug("Request:\n{$requestJSON}\n");
2060
}
2061
2062
$ch = curl_init();
2080
$responseArray = json_decode($responseJSON, true);
2081
2082
if ($debug) {
2083
+ $helperLog->debug("Response:\n{$responseJSON} \n");
2084
}
2085
2086
$responseData = array(
app/code/community/Uecommerce/Mundipagg/Model/Observer.php CHANGED
@@ -64,24 +64,22 @@ class Uecommerce_Mundipagg_Model_Observer extends Uecommerce_Mundipagg_Model_Sta
64
$incrementId = $order->getIncrementId();
65
$offlineRetry = $model->loadByIncrementId($incrementId);
66
67
- if (empty($offlineRetry->getData())) {
68
- return;
69
- }
70
-
71
- $helperLog = new Uecommerce_Mundipagg_Helper_Log(__METHOD__);
72
- $helperLog->setLogLabel("Order #{$incrementId} canceled");
73
74
- try {
75
- $offlineRetry->delete();
76
- $helperLog->info("Offline retry data deleted successfully.");
77
78
- } catch (Exception $e) {
79
- $helperLog->info("Offline retry data cannot be deleted: {$e}");
80
}
81
}
82
83
$this->cancelOrderViaApi($order);
84
-
85
}
86
}
87
@@ -106,11 +104,15 @@ class Uecommerce_Mundipagg_Model_Observer extends Uecommerce_Mundipagg_Model_Sta
106
$url = "{$this->getUrl()}/Cancel";
107
108
$incrementId = $order->getIncrementId();
109
- $orderKey = $payment->getAdditionalInformation('OrderKey');
110
- $data = array('OrderKey' => $orderKey);
111
112
- $logHelper->info("Order #{$incrementId} | Order canceled. Cancel via MundiPagg Api...");
113
- $api->sendRequest($data, $url);
114
}
115
116
/**
64
$incrementId = $order->getIncrementId();
65
$offlineRetry = $model->loadByIncrementId($incrementId);
66
67
+ if (!empty($offlineRetry->getData())) {
68
+ $helperLog = new Uecommerce_Mundipagg_Helper_Log(__METHOD__);
69
+ $helperLog->setLogLabel("Order #{$incrementId} canceled");
70
71
+ try {
72
+ $offlineRetry->delete();
73
+ $helperLog->info("Offline retry data deleted successfully.");
74
75
+ } catch (Exception $e) {
76
+ $helperLog->info("Offline retry data cannot be deleted: {$e}");
77
+ }
78
}
79
}
80
81
+ //cancel Mundi transactions via API
82
$this->cancelOrderViaApi($order);
83
}
84
}
85
104
$url = "{$this->getUrl()}/Cancel";
105
106
$incrementId = $order->getIncrementId();
107
+ $orderKeys = (array)$payment->getAdditionalInformation('OrderKey');
108
+
109
+ foreach ($orderKeys as $orderKey) {
110
+ $data = array('OrderKey' => $orderKey);
111
+
112
+ $logHelper->info("Order #{$incrementId} | Order canceled. Cancel via MundiPagg Api...");
113
+ $api->sendRequest($data, $url);
114
+ }
115
116
}
117
118
/**
app/code/community/Uecommerce/Mundipagg/Model/Order/Payment.php ADDED
@@ -0,0 +1,47 @@
1
+ <?php
2
+
3
+ class Uecommerce_Mundipagg_Model_Order_Payment {
4
+
5
+ const ERR_CANNOT_CREATE_INVOICE = 1;
6
+ const ERR_CANNOT_CREATE_INVOICE_WITHOUT_PRODUCTS = 2;
7
+
8
+ /**
9
+ * @param Mage_Sales_Model_Order $order
10
+ * @throws Exception
11
+ * @return Mage_Sales_Model_Order_Invoice
12
+ */
13
+ public function createInvoice(Mage_Sales_Model_Order $order) {
14
+
15
+ if (!$order->canInvoice()) {
16
+ Mage::throwException(self::ERR_CANNOT_CREATE_INVOICE);
17
+ }
18
+
19
+ $invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
20
+
21
+ if (!$invoice->getTotalQty()) {
22
+ Mage::throwException(self::ERR_CANNOT_CREATE_INVOICE_WITHOUT_PRODUCTS);
23
+ }
24
+
25
+ $invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_OFFLINE);
26
+ $invoice->register();
27
+ $invoice->getOrder()->setCustomerNoteNotify(true);
28
+ $invoice->getOrder()->setIsInProcess(true);
29
+ $invoice->setCanVoidFlag(true);
30
+ $invoice->pay();
31
+
32
+ try {
33
+ $transactionSave = Mage::getModel('core/resource_transaction')
34
+ ->addObject($invoice)
35
+ ->addObject($invoice->getOrder());
36
+
37
+ $transactionSave->save();
38
+
39
+ } catch (Exception $e) {
40
+ Mage::throwException($e->getMessage());
41
+ }
42
+
43
+ return $invoice;
44
+
45
+ }
46
+
47
+ }
app/code/community/Uecommerce/Mundipagg/Model/Standard.php CHANGED
@@ -219,15 +219,12 @@ class Uecommerce_Mundipagg_Model_Standard extends Mage_Payment_Model_Method_Abst
219
}
220
221
$info = $this->getInfoInstance();
222
-
223
$mundipagg = array();
224
$helper = Mage::helper('mundipagg');
225
226
foreach ($data->getData() as $id => $value) {
227
$mundipagg[$id] = $value;
228
229
- //Mage::log($id.' '.$value, null, 'Uecommerce_Mundipagg.log');
230
-
231
// We verify if a CPF OR CNPJ is valid
232
$posTaxvat = strpos($id, 'taxvat');
233
@@ -356,30 +353,25 @@ class Uecommerce_Mundipagg_Model_Standard extends Mage_Payment_Model_Method_Abst
356
// Total Installments from token and Credit Card
357
(float)$totalInstallments = $totalInstallmentsToken + $totalInstallmentsNew;
358
359
- //Mage::log('totalInstallmentsToken: '. $totalInstallmentsToken, null, 'Uecommerce_Mundipagg.log');
360
- //Mage::log('totalInstallmentsNew: '. $totalInstallmentsNew, null, 'Uecommerce_Mundipagg.log');
361
-
362
// If an amount has already been authorized
363
if (isset($mundipagg['multi']) && Mage::getSingleton('checkout/session')->getAuthorizedAmount()) {
364
- //Mage::log('multi already authorized', null, 'Uecommerce_Mundipagg.log');
365
-
366
(float)$totalInstallments += (float)Mage::getSingleton('checkout/session')->getAuthorizedAmount();
367
368
// Unset session
369
Mage::getSingleton('checkout/session')->setAuthorizedAmount();
370
}
371
372
- // Mage::log('grandTotal: '.$grandTotal, null, 'Uecommerce_Mundipagg.log');
373
- // Mage::log('totalInstallments: '.$totalInstallments, null, 'Uecommerce_Mundipagg.log');
374
- // Mage::log('getPaymentInterest: '. $info->getPaymentInterest());
375
- // Mage::log('cal: '. abs($grandTotal-$totalInstallments-$info->getPaymentInterest()), null, 'Uecommerce_Mundipagg.log');
376
-
377
-
378
$epsilon = 0.00001;
379
380
- if ($totalInstallments > 0 && ($grandTotal - $totalInstallments - $info->getPaymentInterest()) > $epsilon) {
381
- Mage::throwException(Mage::helper('payment')->__('Installments does not match with quote.'));
382
- }
383
}
384
} else {
385
if (isset($mundipagg['method'])) {
@@ -642,7 +634,8 @@ class Uecommerce_Mundipagg_Model_Standard extends Mage_Payment_Model_Method_Abst
642
if (
643
count($creditCardTransactionResultCollection) > 1 &&
644
$this->getAntiFraud() == 0 &&
645
- $this->getPaymentAction() == 'order'
646
) {
647
$this->captureAndcreateInvoice($payment);
648
}
@@ -650,6 +643,7 @@ class Uecommerce_Mundipagg_Model_Standard extends Mage_Payment_Model_Method_Abst
650
}
651
652
return $this;
653
} catch (Exception $e) {
654
Mage::logException($e);
655
}
@@ -695,48 +689,52 @@ class Uecommerce_Mundipagg_Model_Standard extends Mage_Payment_Model_Method_Abst
695
$TransactionReference = $transaction->getAdditionalInformation('TransactionReference');
696
}
697
698
- $data['CreditCardTransactionCollection']['AmountInCents'] = $payment->getOrder()->getBaseGrandTotal() * 100;
699
- $data['CreditCardTransactionCollection']['TransactionKey'] = $TransactionKey;
700
- $data['CreditCardTransactionCollection']['TransactionReference'] = $TransactionReference;
701
- $data['OrderKey'] = $payment->getAdditionalInformation('OrderKey');
702
- $data['ManageOrderOperationEnum'] = 'Capture';
703
704
- //Call Gateway Api
705
- $api = Mage::getModel('mundipagg/api');
706
707
- $capture = $api->manageOrderRequest($data, $this);
708
709
- // Xml
710
- $xml = $capture['result'];
711
- $json = json_encode($xml);
712
713
- $capture['result'] = array();
714
- $capture['result'] = json_decode($json, true);
715
716
- // Save transactions
717
- if (isset($capture['result']['CreditCardTransactionResultCollection']['CreditCardTransactionResult'])) {
718
- if (count($xml->CreditCardTransactionResultCollection->CreditCardTransactionResult) == 1) {
719
- $trans = $capture['result']['CreditCardTransactionResultCollection']['CreditCardTransactionResult'];
720
721
- $this->_addTransaction($payment, $trans['TransactionKey'], Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE, $trans);
722
- } else {
723
- $CapturedAmountInCents = 0;
724
725
- foreach ($capture['result']['CreditCardTransactionResultCollection']['CreditCardTransactionResult'] as $key => $trans) {
726
- $TransactionKey = $trans['TransactionKey'];
727
- $CapturedAmountInCents += $trans['CapturedAmountInCents'];
728
- }
729
730
- $trans = array();
731
- $trans['CapturedAmountInCents'] = $CapturedAmountInCents;
732
- $trans['Success'] = true;
733
734
- $this->_addTransaction($payment, $TransactionKey, Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE, $trans);
735
- }
736
- } else {
737
- Mage::getSingleton('checkout/session')->setApprovalRequestSuccess('cancel');
738
739
- return false;
740
}
741
} else {
742
Mage::throwException(Mage::helper('mundipagg')->__('No OrderKey found.'));
@@ -1006,7 +1004,6 @@ class Uecommerce_Mundipagg_Model_Standard extends Mage_Payment_Model_Method_Abst
1006
1007
if ($customerId) {
1008
$customer = Mage::getModel('customer/customer')->load($customerId);
1009
-
1010
$taxvat = $customer->getTaxvat();
1011
}
1012
@@ -1021,15 +1018,12 @@ class Uecommerce_Mundipagg_Model_Standard extends Mage_Payment_Model_Method_Abst
1021
$data['customer_id'] = $order->getCustomerId();
1022
$data['address_id'] = $order->getBillingAddress()->getCustomerAddressId();
1023
$data['payment_method'] = isset($postData['payment']['method']) ? $postData['payment']['method'] : $mundipaggData['method'];
1024
-
1025
$type = $data['payment_method'];
1026
1027
// 1 or more Credit Cards Payment
1028
if ($data['payment_method'] != 'mundipagg_boleto' && $data['payment_method'] != 'mundipagg_debit') {
1029
$helper = Mage::helper('mundipagg');
1030
-
1031
$num = $helper->getCreditCardsNumber($type);
1032
-
1033
$method = $helper->getPaymentMethod($num);
1034
1035
if ($num == 0) {
@@ -1069,6 +1063,7 @@ class Uecommerce_Mundipagg_Model_Standard extends Mage_Payment_Model_Method_Abst
1069
}
1070
1071
$data['payment'][$i]['TaxDocumentNumber'] = isset($postData['payment'][$method . '_cc_taxvat_' . $num . '_' . $i]) ? $postData['payment'][$method . '_cc_taxvat_' . $num . '_' . $i] : $taxvat;
1072
} else { // Token
1073
$data['payment'][$i]['card_on_file_id'] = isset($postData['payment'][$method . '_token_' . $num . '_' . $i]) ? $postData['payment'][$method . '_token_' . $num . '_' . $i] : $mundipaggData[$method . '_token_' . $num . '_' . $i];
1074
$data['payment'][$i]['InstallmentCount'] = isset($postData['payment'][$method . '_credito_parcelamento_' . $num . '_' . $i]) ? $postData['payment'][$method . '_credito_parcelamento_' . $num . '_' . $i] : 1;
@@ -1152,6 +1147,7 @@ class Uecommerce_Mundipagg_Model_Standard extends Mage_Payment_Model_Method_Abst
1152
1153
// Api
1154
$api = Mage::getModel('mundipagg/api');
1155
1156
// Get approval request from gateway
1157
switch ($type) {
@@ -1170,14 +1166,20 @@ class Uecommerce_Mundipagg_Model_Standard extends Mage_Payment_Model_Method_Abst
1170
1171
// Set some data from Mundipagg
1172
$payment = $this->setPaymentAdditionalInformation($approvalRequest, $payment);
1173
1174
// Payment gateway error
1175
if (isset($approvalRequest['error'])) {
1176
// Partial payment
1177
if (isset($approvalRequest['ErrorCode']) && $approvalRequest['ErrorCode'] == 'multi') {
1178
- // We set authorized amount in session
1179
$orderGrandTotal = $order->getGrandTotal();
1180
- $authorizedAmount = 0;
1181
1182
foreach ($approvalRequest['result']->CreditCardTransactionResultCollection->CreditCardTransactionResult as $key => $result) {
1183
if ($result->Success == true) {
@@ -1197,136 +1199,171 @@ class Uecommerce_Mundipagg_Model_Standard extends Mage_Payment_Model_Method_Abst
1197
Mage::getSingleton('checkout/session')->setApprovalRequestSuccess('partial');
1198
Mage::getSingleton('checkout/session')->setAuthorizedAmount($authorizedAmount);
1199
}
1200
} else {
1201
Mage::getSingleton('checkout/session')->setApprovalRequestSuccess('cancel');
1202
}
1203
} else {
1204
$this->offlineRetryCancelOrSuccessOrder($order->getIncrementId());
1205
}
1206
- } else {
1207
- switch ($approvalRequest['message']) {
1208
- // BoletoBancario
1209
- case 0:
1210
- Mage::getSingleton('checkout/session')->setApprovalRequestSuccess('success');
1211
- break;
1212
1213
- // 1CreditCards
1214
- case 1: // AuthAndCapture
1215
- case 2: // AuthOnly
1216
- case 3: // AuthAndCaptureWithDelay
1217
- // We set authorized amount in session
1218
- $orderGrandTotal = $order->getGrandTotal();
1219
- $authorizedAmount = 0;
1220
1221
- $xml = $approvalRequest['result'];
1222
1223
- if (count($xml->CreditCardTransactionResultCollection->CreditCardTransactionResult) == 1) {
1224
- $result = $xml->CreditCardTransactionResultCollection->CreditCardTransactionResult;
1225
1226
if ($result->Success == true) {
1227
$authorizedAmount += $result->AuthorizedAmountInCents * 0.01;
1228
}
1229
- } else {
1230
- foreach ($xml->CreditCardTransactionResultCollection->CreditCardTransactionResult as $key => $result) {
1231
- if ($result->Success == true) {
1232
- $authorizedAmount += $result->AuthorizedAmountInCents * 0.01;
1233
}
1234
}
1235
}
1236
1237
- // If authorized amount is the same as order grand total we can show success page
1238
- $epsilon = 0.1;
1239
-
1240
- if (($orderGrandTotal - $authorizedAmount) <= $epsilon) {
1241
- Mage::getSingleton('checkout/session')->setApprovalRequestSuccess('success');
1242
- Mage::getSingleton('checkout/session')->setAuthorizedAmount();
1243
1244
- if ($orderGrandTotal < $authorizedAmount) {
1245
$interestInformation = $payment->getAdditionalInformation('mundipagg_interest_information');
1246
$newInterestInformation = array();
1247
if (count($interestInformation)) {
1248
- $newInterest = 0;
1249
foreach ($interestInformation as $key => $ii) {
1250
- if (strpos($key, 'partial') !== false) {
1251
- if ($ii->hasValue()) {
1252
- $newInterest += (float)($ii->getInterest());
1253
- }
1254
- }
1255
1256
- }
1257
- // Mage::log('newInterest: '.$newInterest);
1258
- // Mage::log('grandTodal: '.$orderGrandTotal);
1259
- // Mage::log('authorizeAmount: '.$authorizedAmount);
1260
- }
1261
- $this->addInterestToOrder($order, $newInterest);
1262
- }
1263
- } else {
1264
- if ($authorizedAmount != 0) {
1265
- if (($orderGrandTotal - $authorizedAmount) >= $epsilon) {
1266
-
1267
- Mage::getSingleton('checkout/session')->setApprovalRequestSuccess('partial');
1268
- Mage::getSingleton('checkout/session')->setAuthorizedAmount($authorizedAmount);
1269
- $interestInformation = $payment->getAdditionalInformation('mundipagg_interest_information');
1270
- $unauthorizedAmount = (float)($orderGrandTotal - $authorizedAmount);
1271
- $newInterestInformation = array();
1272
- if (count($interestInformation)) {
1273
- foreach ($interestInformation as $key => $ii) {
1274
-
1275
- if ($ii->hasValue()) {
1276
- if ((float)($ii->getValue() + $ii->getInterest()) == (float)trim($unauthorizedAmount)) {
1277
- $this->removeInterestToOrder($order, $ii->getInterest());
1278
- } else {
1279
- $newInterestInformation[$key] = $ii;
1280
- }
1281
} else {
1282
- if (($order->getGrandTotal() + $order->getMundipaggInterest()) == $unauthorizedAmount) {
1283
- $this->removeInterestToOrder($order, $ii->getInterest());
1284
- } else {
1285
- $newInterestInformation[$key] = $ii;
1286
- }
1287
}
1288
}
1289
-
1290
- $payment->setAdditionalInformation('mundipagg_interest_information', $newInterestInformation);
1291
}
1292
}
1293
- } else {
1294
- $this->offlineRetryCancelOrSuccessOrder($order->getIncrementId());
1295
}
1296
}
1297
1298
- // Session
1299
- $xml = simplexml_load_string($approvalRequest['result']);
1300
- $json = json_encode($xml);
1301
- $dataR = array();
1302
- $dataR = json_decode($json, true);
1303
-
1304
- // Transaction
1305
- $transactionKey = isset($dataR['CreditCardTransactionResultCollection']['CreditCardTransactionResult']['TransactionKey']) ? $dataR['CreditCardTransactionResultCollection']['CreditCardTransactionResult']['TransactionKey'] : null;
1306
- $creditCardTransactionStatusEnum = isset($dataR['CreditCardTransactionResultCollection']['CreditCardTransactionResult']['CreditCardTransactionStatus']) ? $dataR['CreditCardTransactionResultCollection']['CreditCardTransactionResult']['CreditCardTransactionStatus'] : null;
1307
1308
- try {
1309
- if ($transactionKey != null) {
1310
- $this->_transactionId = $transactionKey;
1311
1312
- $payment->setTransactionId($this->_transactionId);
1313
1314
- $payment->save();
1315
- }
1316
- } catch (Exception $e) {
1317
- continue;
1318
}
1319
- break;
1320
1321
- // Debit
1322
- case 4:
1323
- Mage::getSingleton('checkout/session')->setApprovalRequestSuccess('debit');
1324
- Mage::getSingleton('checkout/session')->setBankRedirectUrl($approvalRequest['result']['BankRedirectUrl']);
1325
- break;
1326
}
1327
}
1328
1329
return $approvalRequest;
1330
} catch (Exception $e) {
1331
//Api
1332
$api = Mage::getModel('mundipagg/api');
@@ -1438,62 +1475,76 @@ class Uecommerce_Mundipagg_Model_Standard extends Mage_Payment_Model_Method_Abst
1438
$TransactionReference = $transaction->getAdditionalInformation('TransactionReference');
1439
}
1440
1441
- $data['CreditCardTransactionCollection']['AmountInCents'] = $payment->getOrder()->getBaseGrandTotal() * 100;
1442
- $data['CreditCardTransactionCollection']['TransactionKey'] = $TransactionKey;
1443
- $data['CreditCardTransactionCollection']['TransactionReference'] = $TransactionReference;
1444
- $data['OrderKey'] = $payment->getAdditionalInformation('OrderKey');
1445
- $data['ManageOrderOperationEnum'] = 'Cancel';
1446
1447
- //Call Gateway Api
1448
- $api = Mage::getModel('mundipagg/api');
1449
1450
- $void = $api->manageOrderRequest($data, $this);
1451
1452
- // Xml
1453
- $xml = $void['result'];
1454
- $json = json_encode($xml);
1455
1456
- $void['result'] = array();
1457
- $void['result'] = json_decode($json, true);
1458
1459
- // We record transaction(s)
1460
- if (count($void['result']['CreditCardTransactionResultCollection']) > 0) {
1461
- if (count($xml->CreditCardTransactionResultCollection->CreditCardTransactionResult) == 1) {
1462
- $trans = $void['result']['CreditCardTransactionResultCollection']['CreditCardTransactionResult'];
1463
1464
- $this->_addTransaction($payment, $trans['TransactionKey'], 'void', $trans);
1465
- } else {
1466
- foreach ($void['result']['CreditCardTransactionResultCollection']['CreditCardTransactionResult'] as $key => $trans) {
1467
- $this->_addTransaction($payment, $trans['TransactionKey'], 'void', $trans, $key);
1468
}
1469
}
1470
- }
1471
1472
- if (isset($void['result']['CreditCardTransactionResultCollection']['CreditCardTransactionResult'])) {
1473
- $order = $payment->getOrder();
1474
- $order->setBaseDiscountRefunded($order->getBaseDiscountInvoiced());
1475
- $order->setBaseShippingRefunded($order->getBaseShippingAmount());
1476
- $order->setBaseShippingTaxRefunded($order->getBaseShippingTaxInvoiced());
1477
- $order->setBaseSubtotalRefunded($order->getBaseSubtotalInvoiced());
1478
- $order->setBaseTaxRefunded($order->getBaseTaxInvoiced());
1479
- $order->setBaseTotalOnlineRefunded($order->getBaseGrandTotal());
1480
- $order->setDiscountRefunded($order->getDiscountInvoiced());
1481
- $order->setShippinRefunded($order->getShippingInvoiced());
1482
- $order->setShippinTaxRefunded($order->getShippingTaxAmount());
1483
- $order->setSubtotalRefunded($order->getSubtotalInvoiced());
1484
- $order->setTaxRefunded($order->getTaxInvoiced());
1485
- $order->setTotalOnlineRefunded($order->getBaseGrandTotal());
1486
- $order->setTotalRefunded($order->getBaseGrandTotal());
1487
- $order->save();
1488
1489
- return $this;
1490
- } else {
1491
- $error = Mage::helper('mundipagg')->__('Unable to void order.');
1492
1493
- //Log error
1494
- Mage::log($error, null, 'Uecommerce_Mundipagg.log');
1495
1496
- Mage::throwException($error);
1497
}
1498
} else {
1499
Mage::throwException(Mage::helper('mundipagg')->__('No OrderKey found.'));
@@ -1622,7 +1673,7 @@ class Uecommerce_Mundipagg_Model_Standard extends Mage_Payment_Model_Method_Abst
1622
1623
$info = $this->getInfoInstance();
1624
1625
- $errorMsg = false;
1626
1627
// Check if we are dealing with a new Credit Card
1628
$isToken = $info->getAdditionalInformation('mundipagg_creditcard_token_1_1');
@@ -1632,33 +1683,43 @@ class Uecommerce_Mundipagg_Model_Standard extends Mage_Payment_Model_Method_Abst
1632
1633
$ccNumber = $info->getCcNumber();
1634
1635
// remove credit card number delimiters such as "-" and space
1636
$ccNumber = preg_replace('/[\-\s]+/', '', $ccNumber);
1637
$info->setCcNumber($ccNumber);
1638
1639
if (in_array($info->getCcType(), $availableTypes)) {
1640
if (!Mage::helper('mundipagg')->validateCcNum($ccNumber) && $info->getCcType() != 'HI') {
1641
- $errorMsg = Mage::helper('payment')->__('Invalid Credit Card Number');
1642
}
1643
} else {
1644
- $errorMsg = Mage::helper('payment')->__('Credit card type is not allowed for this payment method.');
1645
}
1646
1647
if (!$info->getCcType()) {
1648
- $errorMsg = Mage::helper('payment')->__('Please select your credit card type.');
1649
}
1650
1651
if (!$info->getCcOwner()) {
1652
- $errorMsg = Mage::helper('payment')->__('Please enter your credit card holder name.');
1653
}
1654
1655
if ($info->getCcType() && $info->getCcType() != 'SS' && !Mage::helper('mundipagg')->validateExpDate('20' . $info->getCcExpYear(), $info->getCcExpMonth())) {
1656
- $errorMsg = Mage::helper('payment')->__('Incorrect credit card expiration date.');
1657
}
1658
}
1659
1660
if ($errorMsg) {
1661
- Mage::throwException($errorMsg);
1662
}
1663
1664
return $this;
@@ -1844,15 +1905,17 @@ class Uecommerce_Mundipagg_Model_Standard extends Mage_Payment_Model_Method_Abst
1844
*/
1845
private function offlineRetryCancelOrSuccessOrder($orderIncrementId) {
1846
$offlineRetryIsEnabled = Uecommerce_Mundipagg_Model_Offlineretry::offlineRetryIsEnabled();
1847
1848
- if($offlineRetryIsEnabled == false){
1849
Mage::getSingleton('checkout/session')->setApprovalRequestSuccess('cancel');
1850
return;
1851
}
1852
1853
$api = new Uecommerce_Mundipagg_Model_Api();
1854
- $helperLog = new Uecommerce_Mundipagg_Helper_Log(__METHOD__);
1855
- $logLabel = "Order #{$orderIncrementId}";
1856
1857
if ($api->orderIsInOfflineRetry($orderIncrementId)) {
1858
$message = "{$logLabel} | payment not authorized but order is in offline retry yet, not cancel.";
@@ -1860,10 +1923,10 @@ class Uecommerce_Mundipagg_Model_Standard extends Mage_Payment_Model_Method_Abst
1860
$helperLog->info($message);
1861
Mage::getSingleton('checkout/session')->setApprovalRequestSuccess('success');
1862
1863
- } else {
1864
- $helperLog->info("{$logLabel} | Payment not authorized and store don't have offline retry, order will be canceled.");
1865
Mage::getSingleton('checkout/session')->setApprovalRequestSuccess('cancel');
1866
- }
1867
}
1868
1869
}
219
}
220
221
$info = $this->getInfoInstance();
222
$mundipagg = array();
223
$helper = Mage::helper('mundipagg');
224
225
foreach ($data->getData() as $id => $value) {
226
$mundipagg[$id] = $value;
227
228
// We verify if a CPF OR CNPJ is valid
229
$posTaxvat = strpos($id, 'taxvat');
230
353
// Total Installments from token and Credit Card
354
(float)$totalInstallments = $totalInstallmentsToken + $totalInstallmentsNew;
355
356
// If an amount has already been authorized
357
if (isset($mundipagg['multi']) && Mage::getSingleton('checkout/session')->getAuthorizedAmount()) {
358
(float)$totalInstallments += (float)Mage::getSingleton('checkout/session')->getAuthorizedAmount();
359
360
// Unset session
361
Mage::getSingleton('checkout/session')->setAuthorizedAmount();
362
}
363
364
$epsilon = 0.00001;
365
366
+ // $helperLog = new Uecommerce_Mundipagg_Helper_Log(__METHOD__);
367
+ // $helperLog->info("totalInstallments: {$totalInstallments}");
368
+ // $helperLog->info("grandTotal: {$grandTotal}");
369
+ // $helperLog->info("getPaymentInterest: {$info->getPaymentInterest()}");
370
+ // $helperLog->info("epsilon: {$epsilon}");
371
+
372
+ // if ($totalInstallments > 0 && ($grandTotal - $totalInstallments - $info->getPaymentInterest())) {
373
+ // Mage::throwException(Mage::helper('payment')->__('Installments does not match with quote.'));
374
+ // }
375
}
376
} else {
377
if (isset($mundipagg['method'])) {
634
if (
635
count($creditCardTransactionResultCollection) > 1 &&
636
$this->getAntiFraud() == 0 &&
637
+ $this->getPaymentAction() == 'order' &&
638
+ $order->getPaymentAuthorizationAmount() == $order->getGrandTotal()
639
) {
640
$this->captureAndcreateInvoice($payment);
641
}
643
}
644
645
return $this;
646
+
647
} catch (Exception $e) {
648
Mage::logException($e);
649
}
689
$TransactionReference = $transaction->getAdditionalInformation('TransactionReference');
690
}
691
692
+ // $data['CreditCardTransactionCollection']['AmountInCents'] = $payment->getOrder()->getBaseGrandTotal() * 100;
693
+ // $data['CreditCardTransactionCollection']['TransactionKey'] = $TransactionKey;
694
+ // $data['CreditCardTransactionCollection']['TransactionReference'] = $TransactionReference;
695
+ $orderkeys = (array) $payment->getAdditionalInformation('OrderKey');
696
697
+ foreach ($orderkeys as $orderkey) {
698
+ $data['OrderKey'] = $orderkey;
699
+ $data['ManageOrderOperationEnum'] = 'Capture';
700
701
+ //Call Gateway Api
702
+ $api = Mage::getModel('mundipagg/api');
703
704
+ $capture = $api->manageOrderRequest($data, $this);
705
706
+ // Xml
707
+ $xml = $capture['result'];
708
+ $json = json_encode($xml);
709
710
+ $capture['result'] = array();
711
+ $capture['result'] = json_decode($json, true);
712
713
+ // Save transactions
714
+ if (isset($capture['result']['CreditCardTransactionResultCollection']['CreditCardTransactionResult'])) {
715
+ if (count($xml->CreditCardTransactionResultCollection->CreditCardTransactionResult) == 1) {
716
+ $trans = $capture['result']['CreditCardTransactionResultCollection']['CreditCardTransactionResult'];
717
718
+ $this->_addTransaction($payment, $trans['TransactionKey'], Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE, $trans);
719
+ } else {
720
+ $CapturedAmountInCents = 0;
721
722
+ foreach ($capture['result']['CreditCardTransactionResultCollection']['CreditCardTransactionResult'] as $key => $trans) {
723
+ $TransactionKey = $trans['TransactionKey'];
724
+ $CapturedAmountInCents += $trans['CapturedAmountInCents'];
725
+ }
726
727
+ $trans = array();
728
+ $trans['CapturedAmountInCents'] = $CapturedAmountInCents;
729
+ $trans['Success'] = true;
730
+
731
+ $this->_addTransaction($payment, $TransactionKey, Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE, $trans);
732
+ }
733
+ } else {
734
+ Mage::getSingleton('checkout/session')->setApprovalRequestSuccess('cancel');
735
736
+ return false;
737
+ }
738
}
739
} else {
740
Mage::throwException(Mage::helper('mundipagg')->__('No OrderKey found.'));
1004
1005
if ($customerId) {
1006
$customer = Mage::getModel('customer/customer')->load($customerId);
1007
$taxvat = $customer->getTaxvat();
1008
}
1009
1018
$data['customer_id'] = $order->getCustomerId();
1019
$data['address_id'] = $order->getBillingAddress()->getCustomerAddressId();
1020
$data['payment_method'] = isset($postData['payment']['method']) ? $postData['payment']['method'] : $mundipaggData['method'];
1021
$type = $data['payment_method'];
1022
1023
// 1 or more Credit Cards Payment
1024
if ($data['payment_method'] != 'mundipagg_boleto' && $data['payment_method'] != 'mundipagg_debit') {
1025
$helper = Mage::helper('mundipagg');
1026
$num = $helper->getCreditCardsNumber($type);
1027
$method = $helper->getPaymentMethod($num);
1028
1029
if ($num == 0) {
1063
}
1064
1065
$data['payment'][$i]['TaxDocumentNumber'] = isset($postData['payment'][$method . '_cc_taxvat_' . $num . '_' . $i]) ? $postData['payment'][$method . '_cc_taxvat_' . $num . '_' . $i] : $taxvat;
1066
+
1067
} else { // Token
1068
$data['payment'][$i]['card_on_file_id'] = isset($postData['payment'][$method . '_token_' . $num . '_' . $i]) ? $postData['payment'][$method . '_token_' . $num . '_' . $i] : $mundipaggData[$method . '_token_' . $num . '_' . $i];
1069
$data['payment'][$i]['InstallmentCount'] = isset($postData['payment'][$method . '_credito_parcelamento_' . $num . '_' . $i]) ? $postData['payment'][$method . '_credito_parcelamento_' . $num . '_' . $i] : 1;
1147
1148
// Api
1149
$api = Mage::getModel('mundipagg/api');
1150
+ $helperLog = new Uecommerce_Mundipagg_Helper_Log(__METHOD__);
1151
1152
// Get approval request from gateway
1153
switch ($type) {
1166
1167
// Set some data from Mundipagg
1168
$payment = $this->setPaymentAdditionalInformation($approvalRequest, $payment);
1169
+ $authorizedAmount = $order->getPaymentAuthorizationAmount();
1170
+
1171
+ if (is_null($authorizedAmount)) {
1172
+ $authorizedAmount = 0;
1173
+ }
1174
1175
// Payment gateway error
1176
if (isset($approvalRequest['error'])) {
1177
+
1178
// Partial payment
1179
if (isset($approvalRequest['ErrorCode']) && $approvalRequest['ErrorCode'] == 'multi') {
1180
+
1181
+ // We set authorized amount
1182
$orderGrandTotal = $order->getGrandTotal();
1183
1184
foreach ($approvalRequest['result']->CreditCardTransactionResultCollection->CreditCardTransactionResult as $key => $result) {
1185
if ($result->Success == true) {
1199
Mage::getSingleton('checkout/session')->setApprovalRequestSuccess('partial');
1200
Mage::getSingleton('checkout/session')->setAuthorizedAmount($authorizedAmount);
1201
}
1202
+
1203
+ $order->setPaymentAuthorizationAmount($authorizedAmount);
1204
+ $order->save();
1205
+
1206
} else {
1207
+ $helperLog->info("TESTE1: cancel");
1208
Mage::getSingleton('checkout/session')->setApprovalRequestSuccess('cancel');
1209
}
1210
} else {
1211
$this->offlineRetryCancelOrSuccessOrder($order->getIncrementId());
1212
}
1213
1214
+ return $approvalRequest;
1215
+ }
1216
1217
+ switch ($approvalRequest['message']) {
1218
+ // BoletoBancario
1219
+ case 0:
1220
+ Mage::getSingleton('checkout/session')->setApprovalRequestSuccess('success');
1221
+ break;
1222
1223
+ // 1CreditCards
1224
+ case 1: // AuthAndCapture
1225
+ case 2: // AuthOnly
1226
+ case 3: // AuthAndCaptureWithDelay
1227
+ // We set authorized amount in session
1228
+ $orderGrandTotal = $order->getGrandTotal();
1229
+ $xml = $approvalRequest['result'];
1230
+
1231
+ if (isset($xml->OrderResult)) {
1232
+ $orderResult = $xml->OrderResult;
1233
+ }
1234
+
1235
+ if (count($xml->CreditCardTransactionResultCollection->CreditCardTransactionResult) == 1) {
1236
+ $result = $xml->CreditCardTransactionResultCollection->CreditCardTransactionResult;
1237
1238
+ if ($result->Success == true) {
1239
+ $authorizedAmount += $result->AuthorizedAmountInCents * 0.01;
1240
+ }
1241
+ } else {
1242
+ foreach ($xml->CreditCardTransactionResultCollection->CreditCardTransactionResult as $key => $result) {
1243
if ($result->Success == true) {
1244
$authorizedAmount += $result->AuthorizedAmountInCents * 0.01;
1245
}
1246
+ }
1247
+ }
1248
+
1249
+ // If authorized amount is the same as order grand total we can show success page
1250
+ $epsilon = 0.1;
1251
+
1252
+ if (($orderGrandTotal - $authorizedAmount) <= $epsilon) {
1253
+ Mage::getSingleton('checkout/session')->setApprovalRequestSuccess('success');
1254
+ Mage::getSingleton('checkout/session')->setAuthorizedAmount();
1255
+
1256
+ if ($orderGrandTotal < $authorizedAmount) {
1257
+ $interestInformation = $payment->getAdditionalInformation('mundipagg_interest_information');
1258
+ $newInterestInformation = array();
1259
+
1260
+ if (count($interestInformation)) {
1261
+ $newInterest = 0;
1262
+
1263
+ foreach ($interestInformation as $key => $ii) {
1264
+ if (strpos($key, 'partial') !== false) {
1265
+ if ($ii->hasValue()) {
1266
+ $newInterest += (float)($ii->getInterest());
1267
+ }
1268
+ }
1269
+
1270
}
1271
}
1272
+ $this->addInterestToOrder($order, $newInterest);
1273
}
1274
1275
+ } else {
1276
+ if ($authorizedAmount != 0) {
1277
+ if (($orderGrandTotal - $authorizedAmount) >= $epsilon) {
1278
+ Mage::getSingleton('checkout/session')->setApprovalRequestSuccess('partial');
1279
+ Mage::getSingleton('checkout/session')->setAuthorizedAmount($authorizedAmount);
1280
1281
$interestInformation = $payment->getAdditionalInformation('mundipagg_interest_information');
1282
+ $unauthorizedAmount = (float)($orderGrandTotal - $authorizedAmount);
1283
$newInterestInformation = array();
1284
+
1285
if (count($interestInformation)) {
1286
foreach ($interestInformation as $key => $ii) {
1287
1288
+ if ($ii->hasValue()) {
1289
+ if ((float)($ii->getValue() + $ii->getInterest()) == (float)trim($unauthorizedAmount)) {
1290
+ $this->removeInterestToOrder($order, $ii->getInterest());
1291
+ } else {
1292
+ $newInterestInformation[$key] = $ii;
1293
+ }
1294
+ } else {
1295
+ if (($order->getGrandTotal() + $order->getMundipaggInterest()) == $unauthorizedAmount) {
1296
+ $this->removeInterestToOrder($order, $ii->getInterest());
1297
} else {
1298
+ $newInterestInformation[$key] = $ii;
1299
}
1300
}
1301
}
1302
+
1303
+ $payment->setAdditionalInformation('mundipagg_interest_information', $newInterestInformation);
1304
}
1305
}
1306
+ } else {
1307
+ $this->offlineRetryCancelOrSuccessOrder($order->getIncrementId());
1308
}
1309
+ }
1310
1311
+ // Session
1312
+ $xml = simplexml_load_string($approvalRequest['result']);
1313
+ $json = json_encode($xml);
1314
+ $dataR = array();
1315
+ $dataR = json_decode($json, true);
1316
1317
+ // Transaction
1318
+ $transactionKey = isset($dataR['CreditCardTransactionResultCollection']['CreditCardTransactionResult']['TransactionKey']) ? $dataR['CreditCardTransactionResultCollection']['CreditCardTransactionResult']['TransactionKey'] : null;
1319
+ $creditCardTransactionStatusEnum = isset($dataR['CreditCardTransactionResultCollection']['CreditCardTransactionResult']['CreditCardTransactionStatus']) ? $dataR['CreditCardTransactionResultCollection']['CreditCardTransactionResult']['CreditCardTransactionStatus'] : null;
1320
1321
+ try {
1322
+ if ($transactionKey != null) {
1323
+ $this->_transactionId = $transactionKey;
1324
1325
+ $payment->setTransactionId($this->_transactionId);
1326
+ $payment->save();
1327
}
1328
+ } catch (Exception $e) {
1329
+ $helperLog->error($e->getMessage());
1330
+ continue;
1331
+ }
1332
+ break;
1333
1334
+ // Debit
1335
+ case 4:
1336
+ Mage::getSingleton('checkout/session')->setApprovalRequestSuccess('debit');
1337
+ Mage::getSingleton('checkout/session')->setBankRedirectUrl($approvalRequest['result']['BankRedirectUrl']);
1338
+ break;
1339
+ }
1340
+
1341
+ if (isset($orderResult)) {
1342
+ $newOrderKey = (string)$orderResult->OrderKey;
1343
+ $orderPayment = $order->getPayment();
1344
+ $orderKeys = (array)$orderPayment->getAdditionalInformation('OrderKey');
1345
+
1346
+ if (is_null($orderKeys) || !is_array($orderKeys)) {
1347
+ $orderKeys = array();
1348
+ }
1349
+
1350
+ if (!in_array($newOrderKey, $orderKeys)) {
1351
+ $orderKeys[] = $newOrderKey;
1352
}
1353
+
1354
+ $orderPayment->setAdditionalInformation('OrderKey', $orderKeys);
1355
+ $orderPayment->save();
1356
+ }
1357
+
1358
+ $order->setPaymentAuthorizationAmount($authorizedAmount);
1359
+ $order->save();
1360
+
1361
+ if ($authorizedAmount == $order->getGrandTotal()) {
1362
+ Mage::getSingleton('checkout/session')->setApprovalRequestSuccess('success');
1363
}
1364
1365
return $approvalRequest;
1366
+
1367
} catch (Exception $e) {
1368
//Api
1369
$api = Mage::getModel('mundipagg/api');
1475
$TransactionReference = $transaction->getAdditionalInformation('TransactionReference');
1476
}
1477
1478
+ // $data['CreditCardTransactionCollection']['AmountInCents'] = $payment->getOrder()->getBaseGrandTotal() * 100;
1479
+ // $data['CreditCardTransactionCollection']['TransactionKey'] = $TransactionKey;
1480
+ // $data['CreditCardTransactionCollection']['TransactionReference'] = $TransactionReference;
1481
+ // $data['OrderKey'] = $payment->getAdditionalInformation('OrderKey');
1482
+ $orderkeys = $payment->getAdditionalInformation('OrderKey');
1483
+
1484
+ if (!is_array($orderkeys)) {
1485
+ // $errMsg = "Impossible to capture: orderkeys must be an array";
1486
+ // $helperLog = new Uecommerce_Mundipagg_Helper_Log(__METHOD__);
1487
+ //
1488
+ // $helperLog->error($errMsg);
1489
+ // Mage::throwException($errMsg);
1490
+ $orderkeys = array($orderkeys);
1491
+ }
1492
1493
+ foreach ($orderkeys as $orderkey) {
1494
+ $data['ManageOrderOperationEnum'] = 'Cancel';
1495
+ $data['OrderKey'] = $orderkey;
1496
1497
+ //Call Gateway Api
1498
+ $api = Mage::getModel('mundipagg/api');
1499
1500
+ $void = $api->manageOrderRequest($data, $this);
1501
1502
+ // Xml
1503
+ $xml = $void['result'];
1504
+ $json = json_encode($xml);
1505
1506
+ $void['result'] = array();
1507
+ $void['result'] = json_decode($json, true);
1508
1509
+ // We record transaction(s)
1510
+ if (count($void['result']['CreditCardTransactionResultCollection']) > 0) {
1511
+ if (count($xml->CreditCardTransactionResultCollection->CreditCardTransactionResult) == 1) {
1512
+ $trans = $void['result']['CreditCardTransactionResultCollection']['CreditCardTransactionResult'];
1513
+
1514
+ $this->_addTransaction($payment, $trans['TransactionKey'], 'void', $trans);
1515
+ } else {
1516
+ foreach ($void['result']['CreditCardTransactionResultCollection']['CreditCardTransactionResult'] as $key => $trans) {
1517
+ $this->_addTransaction($payment, $trans['TransactionKey'], 'void', $trans, $key);
1518
+ }
1519
}
1520
}
1521
1522
+ if (isset($void['result']['CreditCardTransactionResultCollection']['CreditCardTransactionResult'])) {
1523
+ $order = $payment->getOrder();
1524
+ $order->setBaseDiscountRefunded($order->getBaseDiscountInvoiced());
1525
+ $order->setBaseShippingRefunded($order->getBaseShippingAmount());
1526
+ $order->setBaseShippingTaxRefunded($order->getBaseShippingTaxInvoiced());
1527
+ $order->setBaseSubtotalRefunded($order->getBaseSubtotalInvoiced());
1528
+ $order->setBaseTaxRefunded($order->getBaseTaxInvoiced());
1529
+ $order->setBaseTotalOnlineRefunded($order->getBaseGrandTotal());
1530
+ $order->setDiscountRefunded($order->getDiscountInvoiced());
1531
+ $order->setShippinRefunded($order->getShippingInvoiced());
1532
+ $order->setShippinTaxRefunded($order->getShippingTaxAmount());
1533
+ $order->setSubtotalRefunded($order->getSubtotalInvoiced());
1534
+ $order->setTaxRefunded($order->getTaxInvoiced());
1535
+ $order->setTotalOnlineRefunded($order->getBaseGrandTotal());
1536
+ $order->setTotalRefunded($order->getBaseGrandTotal());
1537
+ $order->save();
1538
1539
+ return $this;
1540
+ } else {
1541
+ $error = Mage::helper('mundipagg')->__('Unable to void order.');
1542
1543
+ //Log error
1544
+ Mage::log($error, null, 'Uecommerce_Mundipagg.log');
1545
1546
+ Mage::throwException($error);
1547
+ }
1548
}
1549
} else {
1550
Mage::throwException(Mage::helper('mundipagg')->__('No OrderKey found.'));
1673
1674
$info = $this->getInfoInstance();
1675
1676
+ $errorMsg = array();
1677
1678
// Check if we are dealing with a new Credit Card
1679
$isToken = $info->getAdditionalInformation('mundipagg_creditcard_token_1_1');
1683
1684
$ccNumber = $info->getCcNumber();
1685
1686
+ // refresh quote to remove promotions from others payment methods
1687
+ try {
1688
+ $this->getQuote()->save();
1689
+
1690
+ } catch (Exception $e) {
1691
+ $errorMsg[] = $e->getMessage();
1692
+
1693
+ }
1694
+
1695
// remove credit card number delimiters such as "-" and space
1696
$ccNumber = preg_replace('/[\-\s]+/', '', $ccNumber);
1697
$info->setCcNumber($ccNumber);
1698
1699
if (in_array($info->getCcType(), $availableTypes)) {
1700
if (!Mage::helper('mundipagg')->validateCcNum($ccNumber) && $info->getCcType() != 'HI') {
1701
+ $errorMsg[] = Mage::helper('payment')->__('Invalid Credit Card Number');
1702
}
1703
} else {
1704
+ $errorMsg[] = Mage::helper('payment')->__('Credit card type is not allowed for this payment method.');
1705
}
1706
1707
if (!$info->getCcType()) {
1708
+ $errorMsg[] = Mage::helper('payment')->__('Please select your credit card type.');
1709
}
1710
1711
if (!$info->getCcOwner()) {
1712
+ $errorMsg[] = Mage::helper('payment')->__('Please enter your credit card holder name.');
1713
}
1714
1715
if ($info->getCcType() && $info->getCcType() != 'SS' && !Mage::helper('mundipagg')->validateExpDate('20' . $info->getCcExpYear(), $info->getCcExpMonth())) {
1716
+ $errorMsg[] = Mage::helper('payment')->__('Incorrect credit card expiration date.');
1717
}
1718
}
1719
1720
if ($errorMsg) {
1721
+ $json = json_encode($errorMsg);
1722
+ Mage::throwException($json);
1723
}
1724
1725
return $this;
1905
*/
1906
private function offlineRetryCancelOrSuccessOrder($orderIncrementId) {
1907
$offlineRetryIsEnabled = Uecommerce_Mundipagg_Model_Offlineretry::offlineRetryIsEnabled();
1908
+ $helperLog = new Uecommerce_Mundipagg_Helper_Log(__METHOD__);
1909
+ $logLabel = "Order #{$orderIncrementId}";
1910
1911
+ if ($offlineRetryIsEnabled == false) {
1912
+ $helperLog->info("{$logLabel} | Payment not authorized and store don't have offline retry, order will be canceled.");
1913
Mage::getSingleton('checkout/session')->setApprovalRequestSuccess('cancel');
1914
+
1915
return;
1916
}
1917
1918
$api = new Uecommerce_Mundipagg_Model_Api();
1919
1920
if ($api->orderIsInOfflineRetry($orderIncrementId)) {
1921
$message = "{$logLabel} | payment not authorized but order is in offline retry yet, not cancel.";
1923
$helperLog->info($message);
1924
Mage::getSingleton('checkout/session')->setApprovalRequestSuccess('success');
1925
1926
+ }/* else {
1927
+ $helperLog->info("{$logLabel} | Payment not authorized and order is not on offline retry.");
1928
Mage::getSingleton('checkout/session')->setApprovalRequestSuccess('cancel');
1929
+ }*/
1930
}
1931
1932
}
app/code/community/Uecommerce/Mundipagg/Model/Urlvalidation.php CHANGED
@@ -8,7 +8,7 @@ class Uecommerce_Mundipagg_Model_Urlvalidation extends Mage_Core_Model_Config_Da
8
$path = null;
9
10
if (isset($parsedUrl['path'])) {
11
- $path = substr_replace('/', $parsedUrl['path']);
12
}
13
14
if (is_null($path) || strtolower($path) != 'sale') {
8
$path = null;
9
10
if (isset($parsedUrl['path'])) {
11
+ $path = str_replace("/","", $parsedUrl['path']);
12
}
13
14
if (is_null($path) || strtolower($path) != 'sale') {
app/code/community/Uecommerce/Mundipagg/controllers/StandardController.php CHANGED
@@ -180,9 +180,10 @@ class Uecommerce_Mundipagg_StandardController extends Mage_Core_Controller_Front
180
endswitch;
181
182
$resultPayment = $onepage->doPayment($payment, $order);
183
184
// Send new order email when not in admin and payment is success
185
- if (Mage::getSingleton('checkout/session')->getApprovalRequestSuccess() == 'success') {
186
if (Mage::app()->getStore()->getCode() != 'admin') {
187
$order->sendNewOrderEmail();
188
}
@@ -199,6 +200,7 @@ class Uecommerce_Mundipagg_StandardController extends Mage_Core_Controller_Front
199
$trans = $dataR['CreditCardTransactionResultCollection']['CreditCardTransactionResult'];
200
201
$onepage->_addTransaction($order->getPayment(), $trans['TransactionKey'], Mage_Sales_Model_Order_Payment_Transaction::TYPE_AUTH, $trans);
202
} else {
203
$transactions = $dataR['CreditCardTransactionResultCollection']['CreditCardTransactionResult'];
204
@@ -218,12 +220,29 @@ class Uecommerce_Mundipagg_StandardController extends Mage_Core_Controller_Front
218
}
219
}
220
221
- // Redirect
222
- if (Mage::getSingleton('checkout/session')->getApprovalRequestSuccess() == 'success') {
223
- $this->_redirect('mundipagg/standard/success');
224
- } else {
225
- $this->_redirect('mundipagg/standard/partial');
226
}
227
}
228
}
229
} catch (Exception $e) {
@@ -335,10 +354,12 @@ class Uecommerce_Mundipagg_StandardController extends Mage_Core_Controller_Front
335
// Redirect to homepage
336
$this->_redirect('');
337
}
338
} else {
339
// Get posted data
340
$postData = $this->getRequest()->getPost();
341
-
342
$api = Mage::getModel('mundipagg/api');
343
344
// Process order
180
endswitch;
181
182
$resultPayment = $onepage->doPayment($payment, $order);
183
+ $approvalRequestSuccess = Mage::getSingleton('checkout/session')->getApprovalRequestSuccess();
184
185
// Send new order email when not in admin and payment is success
186
+ if ($approvalRequestSuccess == 'success') {
187
if (Mage::app()->getStore()->getCode() != 'admin') {
188
$order->sendNewOrderEmail();
189
}
200
$trans = $dataR['CreditCardTransactionResultCollection']['CreditCardTransactionResult'];
201
202
$onepage->_addTransaction($order->getPayment(), $trans['TransactionKey'], Mage_Sales_Model_Order_Payment_Transaction::TYPE_AUTH, $trans);
203
+
204
} else {
205
$transactions = $dataR['CreditCardTransactionResultCollection']['CreditCardTransactionResult'];
206
220
}
221
}
222
223
+ switch ($approvalRequestSuccess) {
224
+ case 'success':
225
+ $this->_redirect('mundipagg/standard/success');
226
+ break;
227
+
228
+ case 'partial':
229
+ $this->_redirect('mundipagg/standard/partial');
230
+ break;
231
+
232
+ case 'cancel':
233
+ $this->_redirect('mundipagg/standard/cancel');
234
+ break;
235
+
236
+ default:
237
+ Mage::throwException("Unexpected approvalRequestSuccess: {$approvalRequestSuccess}");
238
}
239
+
240
+ // // Redirect
241
+ // if ($approvalRequestSuccess == 'success') {
242
+ // $this->_redirect('mundipagg/standard/success');
243
+ // } else {
244
+ // $this->_redirect('mundipagg/standard/partial');
245
+ // }
246
}
247
}
248
} catch (Exception $e) {
354
// Redirect to homepage
355
$this->_redirect('');
356
}
357
+ } else if ($approvalRequestSuccess == 'cancel') {
358
+ $this->_redirect('mundipagg/standard/cancel');
359
+
360
} else {
361
// Get posted data
362
$postData = $this->getRequest()->getPost();
363
$api = Mage::getModel('mundipagg/api');
364
365
// Process order
app/code/community/Uecommerce/Mundipagg/controllers/TestController.php ADDED
@@ -0,0 +1,139 @@
1
+ <?php
2
+
3
+ class Uecommerce_Mundipagg_TestController extends Uecommerce_Mundipagg_Controller_Abstract {
4
+
5
+ public function indexAction() {
6
+ $model = Mage::getModel('customer/customer');
7
+
8
+ foreach ($model->getCollection() as $i) {
9
+ $customer = $model->load($i->getId());
10
+
11
+ var_dump($customer->getData());
12
+ }
13
+ }
14
+
15
+ public function createCustomerAction() {
16
+ $customer = Mage::getModel('customer/customer');
17
+
18
+ $customer->setWebsiteId(1)
19
+ ->setGroupId(1)
20
+ ->setEmail('teste@teste.com')
21
+ ->setGender(1)
22
+ ->setFirstname('Teste')
23
+ ->setLastname('Testelastname')
24
+ ->setTaxvat('74769331258')
25
+ ->setPassword('Teste@123');
26
+
27
+ try {
28
+ $customer->save();
29
+
30
+ echo '<p>customer created</p>';
31
+
32
+ } catch (Exception $e) {
33
+ echo $e->getTraceAsString();
34
+ }
35
+
36
+ $address = Mage::getModel('customer/address');
37
+
38
+ $address->setCustomerId($customer->getId())
39
+ ->setFirstname($customer->getFirstname())
40
+ ->setLastnmae($customer->getLastname())
41
+ ->setCountryId('BR')
42
+ ->setPostcode('20021130')
43
+ ->setCity('Rio de Janeiro')
44
+ ->setTelephone('21988880000')
45
+ ->setStreet('Av General Justo 375')
46
+ ->setRegionId('RJ')
47
+ ->setVatId($customer->getTaxvat())
48
+ ->setIsDefaultBilling(1)
49
+ ->setIsDefaultShipping(1)
50
+ ->setSaveInAddressBook(1);
51
+
52
+ try {
53
+ $address->save();
54
+ echo '<p>address created</p>';
55
+
56
+ } catch (Exception $e) {
57
+ echo $e->getTraceAsString();
58
+ }
59
+
60
+ }
61
+
62
+ public function createProductAction() {
63
+ Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
64
+
65
+ $product = Mage::getModel('catalog/product');
66
+
67
+ $product->setAttributeSetId(4)
68
+ ->setTypeId('simple')
69
+ ->setSku('000005')
70
+ ->setName('Produto de teste do script')
71
+ ->setWeight(10)
72
+ ->setStatus(1)
73
+ ->setTaxClassId(0)//tax class (0 - none, 1 - default, 2 - taxable, 4 - shipping)
74
+ ->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH)
75
+ ->setPrice(10.00)
76
+ ->setDescription('Produto de teste')
77
+ ->setShortDescription('Produto de teste');
78
+
79
+ // ->setStockData(array(
80
+ // 'manage_stock' => 0,
81
+ // 'use_config_manage_stock' => 0,
82
+ // 'use_config_min_sale_qty' => 1,
83
+ // 'use_config_max_sale_qty' => 1,
84
+ // 'use_config_enable_qty_increments' => 1,
85
+ //// 'low_stock_date' => strtotime('now')
86
+ // 'low_stock_date' => '2016-08-11 21:11:38'
87
+ // ));
88
+
89
+ // $stock->setLowStockDate(now())
90
+ // ->setManageStock(0)
91
+ // ->setUseConfigManageStock(0)
92
+ // ->setUseConfigMinSaleQty(1)
93
+ // ->setUseConfigMaxSaleQty(1)
94
+ // ->setUseConfigEnableQtyIncrements(1);
95
+ //
96
+ // $product->setStockData($stock);
97
+
98
+ try {
99
+ $product->save();
100
+ echo '<p>Produto criado</p>';
101
+
102
+ } catch (Exception $e) {
103
+ echo "<p>{$e->getMessage()}</p>";
104
+ echo "<p>{$e->getTraceAsString()}</p>";
105
+ }
106
+ }
107
+
108
+ public function testeProductAction() {
109
+ $id = Mage::getModel('catalog/product')->getCollection()->getLastItem()->getId();
110
+ $product = Mage::getModel('catalog/product')->load($id);
111
+ $stock = $product->getStockItem();
112
+
113
+ var_dump(get_class($stock));
114
+
115
+
116
+ // var_dump($product->getData());
117
+ // var_dump(get_class($stock));
118
+ var_dump($stock->getData());
119
+ }
120
+
121
+ public function authorizeAmountAction() {
122
+ $amount = 1;
123
+ $orderId = 100000068;
124
+
125
+ $order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
126
+
127
+ try{
128
+ $order->setPaymentAuthorizationAmount($amount);
129
+ $order->save();
130
+
131
+ echo 'success';
132
+
133
+ } catch (Exception $e){
134
+ echo "Error {$e->getMessage()}";
135
+ }
136
+
137
+ }
138
+
139
+ }
app/code/community/Uecommerce/Mundipagg/controllers/TesteController.php CHANGED
@@ -25,12 +25,20 @@ class Uecommerce_Mundipagg_TesteController extends Uecommerce_Mundipagg_Controll
25
}
26
27
public function transactionsAction() {
28
- $transactions = Mage::getModel('sales/order_payment_transaction')
29
- ->getCollection()
30
- ->addAttributeToFilter('order_id', '1');
31
32
- foreach ($transactions as $transaction) {
33
- var_dump($transaction->getData());
34
}
35
}
36
@@ -51,7 +59,58 @@ class Uecommerce_Mundipagg_TesteController extends Uecommerce_Mundipagg_Controll
51
// }
52
}
53
54
- public function checkoutAction() {
55
56
}
57
25
}
26
27
public function transactionsAction() {
28
+ $resource = Mage::getSingleton('core/resource');
29
+ $conn = $resource->getConnection('core_write');
30
+ $query = '
31
+ UPDATE sales_payment_transaction
32
+ SET is_closed = 0
33
+ WHERE transaction_id = 75
34
+ ';
35
+
36
+ try {
37
+ $conn->query($query);
38
+ echo 'success';
39
40
+ } catch (Exception $e) {
41
+ echo "Error: " . $e->getMessage();
42
}
43
}
44
59
// }
60
}
61
62
+ public function notificationsAction() {
63
+ $model = Mage::getModel('adminnotification/inbox')
64
+ ->getCollection()
65
+ ->addFilter('url', 'https://www.magentocommerce.com/magento-connect/mundipagg-payment-gateway.html')
66
+ ->setOrder('date_added', 'desc')
67
+ ->getLastItem();
68
+
69
+ var_dump($model->getData());
70
+
71
+ // foreach ($model->getCollection() as $item) {
72
+ // var_dump($item->getData());
73
+ // }
74
+
75
+ }
76
+
77
+ public function lastNotifAction() {
78
+ $model = new Uecommerce_Mundipagg_Model_Admin_Notification();
79
+ $data = $model->getLastSavedNotification();
80
+
81
+ var_dump($data->getData());
82
+
83
+ }
84
+
85
+ public function testeRedirectAction() {
86
+ $this->_redirect('mundipagg/standard/cancel');
87
+ }
88
+
89
+ public function attributeAction() {
90
+ $attributeCodes = array('mundipagg_frequency_enum', 'mundipagg_recurrences');
91
+
92
+ foreach ($attributeCodes as $attributeCode) {
93
+ try {
94
+ $attribute = new Mage_Eav_Model_Entity_Attribute();
95
+ $attribute->loadByCode(Mage_Catalog_Model_Product::ENTITY, $attributeCode);
96
+
97
+ $attribute->setIsRequired(false);
98
+ $attribute->save();
99
+
100
+ var_dump($attribute->getData());
101
+
102
+ } catch (Exception $e) {
103
+ echo $e->getMessage();
104
+
105
+ return;
106
+ }
107
+ }
108
+ }
109
+
110
+ public function invoiceAction() {
111
+ $invoice = Mage::getModel('sales/order_invoice')->loadByIncrementId(100000003);
112
+
113
+ var_dump($invoice->getData());
114
115
}
116
app/code/community/Uecommerce/Mundipagg/etc/config.xml CHANGED
@@ -32,7 +32,7 @@
32
<config>
33
<modules>
34
<Uecommerce_Mundipagg>
35
- <version>2.7.0</version>
36
</Uecommerce_Mundipagg>
37
</modules>
38
32
<config>
33
<modules>
34
<Uecommerce_Mundipagg>
35
+ <version>2.7.1</version>
36
</Uecommerce_Mundipagg>
37
</modules>
38
app/design/adminhtml/default/default/template/mundipagg/payment/info/mundipagg.phtml CHANGED
@@ -30,22 +30,22 @@
30
31
$helper = Mage::helper('mundipagg');
32
33
- if(Mage::registry('current_order')):
34
- $_order = $this->getOrder();
35
endif;
36
37
- if(Mage::registry('current_invoice')):
38
- $_order = $this->getInvoice()->getOrder();
39
endif;
40
41
- if(Mage::registry('current_shipment')):
42
- $_order = $this->getShipment()->getOrder();
43
endif;
44
45
- if(Mage::registry('current_creditmemo')):
46
- $data = Mage::registry('current_creditmemo')->getData();
47
-
48
- $_order = Mage::getModel('sales/order')->load($data['order_id']);
49
endif;
50
51
$standard = Mage::getModel('mundipagg/standard');
@@ -53,182 +53,194 @@ $standard = Mage::getModel('mundipagg/standard');
53
$paymentAction = $standard->getPaymentAction();
54
55
if ($paymentAction == 'authorize') {
56
- $paymentAction = 'authorization';
57
}
58
?>
59
<div>
60
- <p>
61
- <?php
62
- $PaymentMethod = $_order->getPayment()->getAdditionalInformation('PaymentMethod');
63
-
64
- echo $helper->__('Method').': '.$helper->__($PaymentMethod).'<br/>';
65
-
66
- if($orderKey = $_order->getPayment()->getAdditionalInformation('OrderKey')):
67
- echo $helper->__('OrderKey').': '.$orderKey.'<br/>';
68
- endif;
69
-
70
- if($OrderReference = $_order->getPayment()->getAdditionalInformation('OrderReference')):
71
- echo $helper->__('OrderReference').': '.$OrderReference.'<br/>';
72
- endif;
73
-
74
- // Informations about transaction
75
- $transaction = Mage::getModel('sales/order_payment_transaction')->getCollection()
76
- ->addAttributeToFilter('order_id', array('eq' => $_order->getEntityId()))
77
- ->addAttributeToFilter('txn_type', array('eq' => $paymentAction));
78
- $authCode = '';
79
- $tid = '';
80
- $ccNumber = '';
81
- $message = '';
82
-
83
- foreach ($transaction as $t) :
84
- $t = $t->getData();
85
- $txDetail = $t['additional_information'];
86
-
87
- if (!empty($txDetail)):
88
- $authCode = isset($txDetail['AuthorizationCode']) ? $txDetail['AuthorizationCode'] : null;
89
- $tid = isset($txDetail['TransactionIdentifier']) ? $txDetail['TransactionIdentifier'] : null;
90
- $ccNumber = isset($txDetail['MaskedCreditCardNumber']) ? $txDetail['MaskedCreditCardNumber'] : null;
91
-
92
- if(isset($txDetail['CreditCardNumber'])) {
93
- $ccNumber = $txDetail['CreditCardNumber'];
94
- }
95
-
96
- $message = isset($txDetail['AcquirerMessage']) ? $txDetail['AcquirerMessage'] : null;
97
- endif;
98
- endforeach;
99
-
100
- if($PaymentMethod == '1CreditCards' || $PaymentMethod == 'mundipagg_creditcard'):
101
- // Token
102
- $token = $this->getInfo()->getAdditionalInformation('mundipagg_creditcard_token_1_1');
103
-
104
- if($token && $token != 'new'):
105
- echo $helper->__('Credit Card Issuer').': ';
106
- echo $this->getInfo()->getAdditionalInformation('CreditCardBrandEnum_mundipagg_creditcard_token_1_1');
107
- echo '<br/>';
108
- if ($ccNumber) echo 'Numeração: '.$ccNumber.'<br>';
109
-
110
- if ($this->getInfo()->getAdditionalInformation('mundipagg_creditcard_credito_parcelamento_1_1')):
111
- echo $helper->__('InstallmentsCount').': ';
112
- echo $this->getInfo()->getAdditionalInformation('mundipagg_creditcard_credito_parcelamento_1_1');
113
- echo 'x<br/>';
114
- endif;
115
- else:
116
- echo $helper->__('Credit Card Issuer').': ';
117
- echo $this->getInfo()->getAdditionalInformation('mundipagg_creditcard_1_1_cc_type');
118
- echo '<br/>';
119
- if ($ccNumber) echo 'Numeração: '.$ccNumber.'<br>';
120
-
121
- if ($this->getInfo()->getAdditionalInformation('mundipagg_cre