Rede_Pay - Version 1.3.0.0

Version Notes

Possibilidade de configurar carrinho abandonado, código de rastreio e desconto integrando as funcionalidades com o Rede Pay.

Download this release

Release Info

Developer Tiago Sampaio
Extension Rede_Pay
Version 1.3.0.0
Comparing to
See all releases


Code changes from version 1.2.2.0 to 1.3.0.0

Files changed (76) hide show
  1. app/code/community/Rede/Pay/Block/Adminhtml/System/Config/Field/Url.php +42 -0
  2. app/code/community/Rede/Pay/Block/Adminhtml/System/Config/Fieldset/Group.php +41 -0
  3. app/code/community/Rede/Pay/Block/Checkout/Abstract.php +178 -0
  4. app/code/community/Rede/Pay/Block/Checkout/Denied.php +25 -0
  5. app/code/community/Rede/Pay/Block/Checkout/Error.php +16 -0
  6. app/code/community/Rede/Pay/Block/Checkout/Payment.php +16 -0
  7. app/code/community/Rede/Pay/Block/Checkout/Pending.php +16 -0
  8. app/code/community/Rede/Pay/Block/Checkout/State.php +16 -0
  9. app/code/community/Rede/Pay/Block/Checkout/Success.php +16 -0
  10. app/code/community/Rede/Pay/Block/Form/Method/Standard.php +44 -0
  11. app/code/community/Rede/Pay/Block/Info/Method/Standard.php +175 -0
  12. app/code/community/Rede/Pay/Block/Logo.php +62 -0
  13. app/code/community/Rede/Pay/Controller/Adminhtml/Action.php +38 -0
  14. app/code/community/Rede/Pay/Controller/Front/Action.php +248 -0
  15. app/code/community/Rede/Pay/Helper/Attributes.php +350 -0
  16. app/code/community/Rede/Pay/Helper/Data.php +396 -0
  17. app/code/community/Rede/Pay/Model/Abstract.php +28 -0
  18. app/code/community/Rede/Pay/Model/Api.php +552 -0
  19. app/code/community/Rede/Pay/Model/Logger.php +318 -0
  20. app/code/community/Rede/Pay/Model/Method/Standard.php +319 -0
  21. app/code/community/Rede/Pay/Model/Observer.php +239 -0
  22. app/code/community/Rede/Pay/Model/Params/Abstract.php +205 -0
  23. app/code/community/Rede/Pay/Model/Params/Consult.php +21 -0
  24. app/code/community/Rede/Pay/Model/Params/Order.php +322 -0
  25. app/code/community/Rede/Pay/Model/Params/Refund.php +30 -0
  26. app/code/community/Rede/Pay/Model/Params/Shipping/Tracking.php +30 -0
  27. app/code/community/Rede/Pay/Model/Params/Shipping/Tracking/Delete.php +26 -0
  28. app/code/community/Rede/Pay/Model/Payments.php +181 -0
  29. app/code/community/Rede/Pay/Model/Processor.php +250 -0
  30. app/code/community/Rede/Pay/Model/Processor/Order.php +346 -0
  31. app/code/community/Rede/Pay/Model/Resource/Payments.php +75 -0
  32. app/code/community/Rede/Pay/Model/Resource/Payments/Collection.php +18 -0
  33. app/code/community/Rede/Pay/Model/Session.php +79 -0
  34. app/code/community/Rede/Pay/Model/System/Config/Source/Attributes/Customer.php +50 -0
  35. app/code/community/Rede/Pay/Model/System/Config/Source/Attributes/Customer/Address.php +61 -0
  36. app/code/community/Rede/Pay/Model/System/Config/Source/Installments.php +32 -0
  37. app/code/community/Rede/Pay/Model/Validator/Cpf.php +55 -0
  38. app/code/community/Rede/Pay/Model/Validator/Shipping/Tracking.php +35 -0
  39. app/code/community/Rede/Pay/Trait/Config.php +54 -0
  40. app/code/community/Rede/Pay/Trait/Data.php +154 -0
  41. app/code/community/Rede/Pay/controllers/Adminhtml/Sales/OrderController.php +55 -0
  42. app/code/community/Rede/Pay/controllers/CheckoutController.php +115 -0
  43. app/code/community/Rede/Pay/controllers/NotificationController.php +487 -0
  44. app/code/community/Rede/Pay/data/rede_pay_setup/data-install-1.0.0.0.php +67 -0
  45. app/code/community/Rede/Pay/data/rede_pay_setup/data-upgrade-1.0.1.0-1.0.1.1.php +61 -0
  46. app/code/community/Rede/Pay/etc/adminhtml.xml +24 -0
  47. app/code/community/Rede/Pay/etc/config.xml +212 -0
  48. app/code/community/Rede/Pay/etc/system.xml +403 -0
  49. app/code/community/Rede/Pay/sql/rede_pay_setup/install-1.0.0.0.php +60 -0
  50. app/code/community/Rede/Pay/sql/rede_pay_setup/upgrade-1.0.0.0-1.0.1.0.php +23 -0
  51. app/code/community/Rede/Pay/sql/rede_pay_setup/upgrade-1.0.1.1-1.0.2.0.php +24 -0
  52. app/code/community/Rede/Pay/sql/rede_pay_setup/upgrade-1.0.2.0-1.0.2.1.php +25 -0
  53. app/code/community/Rede/Pay/sql/rede_pay_setup/upgrade-1.0.2.1-1.0.2.2.php +19 -0
  54. app/design/adminhtml/default/default/template/rede/pay/form/method/standard.phtml +14 -0
  55. app/design/adminhtml/default/default/template/rede/pay/info/method/standard.phtml +51 -0
  56. app/design/adminhtml/default/default/template/rede/pay/logo.phtml +8 -0
  57. app/design/frontend/base/default/layout/rede/pay.xml +59 -0
  58. app/etc/modules/Rede_Pay.xml +14 -0
  59. app/locale/pt_BR/Rede/Pay.csv +128 -0
  60. package.xml +10 -10
  61. skin/adminhtml/default/default/rede/pay/css/adminhtml.css +37 -0
  62. skin/adminhtml/default/default/rede/pay/images/bt_cadastro.png +0 -0
  63. skin/adminhtml/default/default/rede/pay/images/bt_magento_configurar.png +0 -0
  64. skin/adminhtml/default/default/rede/pay/images/bt_magento_fechar.png +0 -0
  65. skin/adminhtml/default/default/rede/pay/images/clickpag_rede.png +0 -0
  66. skin/adminhtml/default/default/rede/pay/images/rede-logo-282x100.png +0 -0
  67. skin/adminhtml/default/default/rede/pay/images/rede-logo.png +0 -0
  68. skin/adminhtml/default/default/rede/pay/images/redepay.png +0 -0
  69. skin/frontend/base/default/rede/pay/css/styles.css +30 -0
  70. skin/frontend/base/default/rede/pay/images/bt_magento_configurar.png +0 -0
  71. skin/frontend/base/default/rede/pay/images/bt_magento_fechar.png +0 -0
  72. skin/frontend/base/default/rede/pay/images/clickpag_rede.png +0 -0
  73. skin/frontend/base/default/rede/pay/images/rede-logo-282x100.png +0 -0
  74. skin/frontend/base/default/rede/pay/images/rede-logo.png +0 -0
  75. skin/frontend/base/default/rede/pay/images/redepay.png +0 -0
  76. skin/frontend/default/default/rede/pay/css/styles.css +28 -0
app/code/community/Rede/Pay/Block/Adminhtml/System/Config/Field/Url.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Tiago Sampaio <tiago@tiagosampaio.com>
4
+ *
5
+ * Class Rede_Pay_Block_Adminhtml_System_Config_Field_Url
6
+ */
7
+ class Rede_Pay_Block_Adminhtml_System_Config_Field_Url extends Mage_Adminhtml_Block_System_Config_Form_Field
8
+ {
9
+
10
+ use Rede_Pay_Trait_Data;
11
+
12
+ /**
13
+ * Prepares the element's html.
14
+ *
15
+ * @param Varien_Data_Form_Element_Abstract $element
16
+ *
17
+ * @return string
18
+ */
19
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
20
+ {
21
+ /** @var Mage_Core_Model_Config_Element $configField */
22
+ $config = $element->getData('field_config');
23
+ $helperUrl = (string) $config->helper_url;
24
+
25
+ if (empty($helperUrl)) {
26
+ return parent::_getElementHtml($element);
27
+ }
28
+
29
+ list($model, $method) = explode('::', $helperUrl);
30
+
31
+ $helper = Mage::helper(implode('/', array('rede_pay', $model)));
32
+
33
+ if (!$helper || !method_exists($helper, $method)) {
34
+ return parent::_getElementHtml($element);
35
+ }
36
+
37
+ $element->setData('value', str_replace('/index.php', '', $helper->$method()));
38
+
39
+ return '<span class="red">' . parent::_getElementHtml($element) . '</span>';
40
+ }
41
+
42
+ }
app/code/community/Rede/Pay/Block/Adminhtml/System/Config/Fieldset/Group.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Tiago Sampaio <tiago@tiagosampaio.com>
4
+ *
5
+ * Class Rede_Pay_Block_Adminhtml_System_Config_Fieldset_Group
6
+ */
7
+ class Rede_Pay_Block_Adminhtml_System_Config_Fieldset_Group
8
+ extends Mage_Adminhtml_Block_System_Config_Form_Fieldset
9
+ {
10
+
11
+ use Rede_Pay_Trait_Data;
12
+
13
+ /**
14
+ * Return header comment part of html for fieldset
15
+ *
16
+ * @param Varien_Data_Form_Element_Abstract $element
17
+ * @return string
18
+ */
19
+ protected function _getHeaderCommentHtml($element)
20
+ {
21
+ $groupConfig = $this->getGroup($element)->asArray();
22
+
23
+ $url = $groupConfig['register_url'];
24
+ $imgSrc = $this->getSkinUrl('rede/pay/images/bt_cadastro.png');
25
+ $logoSrc = $this->getSkinUrl('rede/pay/images/redepay.png');
26
+
27
+ if (empty($url) || !$element->getComment()) {
28
+ return parent::_getHeaderCommentHtml($element);
29
+ }
30
+
31
+ $html = '<div class="comment">';
32
+ $html .= '<p><img src="'.$logoSrc.'" width="250"/><p/>';
33
+ $html .= '<p>' . $element->getComment() . '<p/>';
34
+ $html .= '<p><a target="_blank" href="'.$url.'"><img src="'.$imgSrc.'"/></a></p>';
35
+ $html .= '</div>';
36
+ $html .= '<br/>';
37
+
38
+ return $html;
39
+ }
40
+
41
+ }
app/code/community/Rede/Pay/Block/Checkout/Abstract.php ADDED
@@ -0,0 +1,178 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Tiago Sampaio <tiago@tiagosampaio.com>
4
+ *
5
+ * Class Rede_Pay_Block_Checkout_Abstract
6
+ */
7
+ abstract class Rede_Pay_Block_Checkout_Abstract extends Mage_Core_Block_Template
8
+ {
9
+
10
+ use Rede_Pay_Trait_Data,
11
+ Rede_Pay_Trait_Config;
12
+
13
+ /**
14
+ * @return null|string
15
+ */
16
+ public function getLastPaymentId()
17
+ {
18
+ if (!$this->hasData('payment_id')) {
19
+ /** @var Rede_Pay_Model_Payments $payments */
20
+ $payments = Mage::getModel('rede_pay/payments');
21
+ $payments->loadByOrderId($this->getOrder()->getId());
22
+
23
+ $this->setData('payment_id', $payments->getPaymentId());
24
+ }
25
+
26
+ return $this->getData('payment_id');
27
+ }
28
+
29
+
30
+ /**
31
+ * @return Mage_Sales_Model_Order
32
+ */
33
+ public function getOrder()
34
+ {
35
+ if (!$this->hasData('order')) {
36
+ if (!($order = $this->_getCurrentOrder())) {
37
+ $order = Mage::getModel('sales/order')->load($this->getOrderId());
38
+ }
39
+
40
+ $this->setData('order', $order);
41
+ }
42
+
43
+ return $this->getData('order');
44
+ }
45
+
46
+
47
+ /**
48
+ * @return mixed
49
+ */
50
+ public function getOrderId()
51
+ {
52
+ return $this->_getLastOrderId();
53
+ }
54
+
55
+
56
+ /**
57
+ * @return string
58
+ */
59
+ public function getRealOrderId()
60
+ {
61
+ return $this->getOrder()->getIncrementId();
62
+ }
63
+
64
+
65
+ /**
66
+ * @param int $width
67
+ *
68
+ * @return string
69
+ */
70
+ public function getLogoHtml($width = null)
71
+ {
72
+ return $this->_helper()->getLogoHtml($width);
73
+ }
74
+
75
+
76
+ /**
77
+ * @return Rede_Pay_Model_Session
78
+ */
79
+ public function getSession()
80
+ {
81
+ return $this->_getSession();
82
+ }
83
+
84
+
85
+ /**
86
+ * @return Mage_Checkout_Model_Session
87
+ */
88
+ public function getCheckoutSession()
89
+ {
90
+ return $this->_getCheckoutSession();
91
+ }
92
+
93
+
94
+ /**
95
+ * @return string
96
+ */
97
+ public function getPrintOrderUrl()
98
+ {
99
+ return $this->getUrl('sales/order/print', array('order_id'=> $this->getOrderId()));
100
+ }
101
+
102
+
103
+ /**
104
+ * @return bool
105
+ */
106
+ public function canReorder()
107
+ {
108
+ if ($this->getOrder()->getCustomerIsGuest()) {
109
+ return true;
110
+ }
111
+
112
+ return $this->getOrder()->canReorderIgnoreSalable();
113
+ }
114
+
115
+
116
+ /**
117
+ * @return string
118
+ */
119
+ public function getReorderUrl()
120
+ {
121
+ return $this->getUrl('*/*/reorder', array('order_id' => $this->getOrder()->getId()));
122
+ }
123
+
124
+
125
+ /**
126
+ * @return bool
127
+ */
128
+ public function canRetryPayment()
129
+ {
130
+ try {
131
+ /** @var Mage_Sales_Model_Order $order */
132
+ $order = $this->getOrder();
133
+
134
+ if (!$order || !$order->getId()) {
135
+ return (bool) false;
136
+ }
137
+
138
+ /**
139
+ * The order needs to be in one of the following states:
140
+ * - pending_payment
141
+ * - processing
142
+ * - new
143
+ */
144
+ $allowedStates = array (
145
+ Mage_Sales_Model_Order::STATE_NEW,
146
+ Mage_Sales_Model_Order::STATE_PROCESSING,
147
+ Mage_Sales_Model_Order::STATE_PENDING_PAYMENT
148
+ );
149
+
150
+ if (!in_array($order->getState(), $allowedStates)) {
151
+ return (bool) false;
152
+ }
153
+
154
+ /**
155
+ * If you cannot invoice the order (and unhold it as well) it can mean that it's already invoiced.
156
+ */
157
+ if (!$order->canInvoice() && ($order->getState() !== Mage_Sales_Model_Order::STATE_HOLDED)) {
158
+ return (bool) false;
159
+ }
160
+
161
+ return (bool) true;
162
+ } catch (Exception $e) {
163
+ Mage::logException($e);
164
+ }
165
+
166
+ return (bool) false;
167
+ }
168
+
169
+
170
+ /**
171
+ * @return Mage_Sales_Model_Order|null
172
+ */
173
+ protected function _getCurrentOrder()
174
+ {
175
+ return Mage::registry('current_order');
176
+ }
177
+
178
+ }
app/code/community/Rede/Pay/Block/Checkout/Denied.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Tiago Sampaio <tiago@tiagosampaio.com>
4
+ *
5
+ * Class Rede_Pay_Block_Checkout_Denied
6
+ */
7
+ class Rede_Pay_Block_Checkout_Denied extends Rede_Pay_Block_Checkout_Abstract
8
+ {
9
+
10
+ protected function _construct()
11
+ {
12
+ parent::_construct();
13
+ $this->setTemplate('rede/pay/checkout/denied.phtml');
14
+ }
15
+
16
+
17
+ /**
18
+ * @return bool
19
+ */
20
+ public function canRetryPayment()
21
+ {
22
+ return false;
23
+ }
24
+
25
+ }
app/code/community/Rede/Pay/Block/Checkout/Error.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Tiago Sampaio <tiago@tiagosampaio.com>
4
+ *
5
+ * Class Rede_Pay_Block_Checkout_Error
6
+ */
7
+ class Rede_Pay_Block_Checkout_Error extends Rede_Pay_Block_Checkout_Abstract
8
+ {
9
+
10
+ protected function _construct()
11
+ {
12
+ parent::_construct();
13
+ $this->setTemplate('rede/pay/checkout/error.phtml');
14
+ }
15
+
16
+ }
app/code/community/Rede/Pay/Block/Checkout/Payment.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Tiago Sampaio <tiago@tiagosampaio.com>
4
+ *
5
+ * Class Rede_Pay_Block_Checkout_Payment
6
+ */
7
+ class Rede_Pay_Block_Checkout_Payment extends Rede_Pay_Block_Checkout_Abstract
8
+ {
9
+
10
+ protected function _construct()
11
+ {
12
+ parent::_construct();
13
+ $this->setTemplate('rede/pay/checkout/payment.phtml');
14
+ }
15
+
16
+ }
app/code/community/Rede/Pay/Block/Checkout/Pending.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Tiago Sampaio <tiago@tiagosampaio.com>
4
+ *
5
+ * Class Rede_Pay_Block_Checkout_Pending
6
+ */
7
+ class Rede_Pay_Block_Checkout_Pending extends Rede_Pay_Block_Checkout_Success
8
+ {
9
+
10
+ protected function _construct()
11
+ {
12
+ parent::_construct();
13
+ $this->setTemplate('rede/pay/checkout/pending.phtml');
14
+ }
15
+
16
+ }
app/code/community/Rede/Pay/Block/Checkout/State.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Tiago Sampaio <tiago@tiagosampaio.com>
4
+ *
5
+ * Class Rede_Pay_Block_Checkout_State
6
+ */
7
+ class Rede_Pay_Block_Checkout_State extends Rede_Pay_Block_Checkout_Abstract
8
+ {
9
+
10
+ protected function _construct()
11
+ {
12
+ parent::_construct();
13
+ $this->setTemplate('rede/pay/checkout/state.phtml');
14
+ }
15
+
16
+ }
app/code/community/Rede/Pay/Block/Checkout/Success.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Tiago Sampaio <tiago@tiagosampaio.com>
4
+ *
5
+ * Class Rede_Pay_Block_Checkout_Success
6
+ */
7
+ class Rede_Pay_Block_Checkout_Success extends Rede_Pay_Block_Checkout_Abstract
8
+ {
9
+
10
+ protected function _construct()
11
+ {
12
+ parent::_construct();
13
+ $this->setTemplate('rede/pay/checkout/success.phtml');
14
+ }
15
+
16
+ }
app/code/community/Rede/Pay/Block/Form/Method/Standard.php ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Tiago Sampaio <tiago@tiagosampaio.com>
4
+ *
5
+ * Class Rede_Pay_Block_Form_Method_Standard
6
+ */
7
+ class Rede_Pay_Block_Form_Method_Standard extends Mage_Payment_Block_Form
8
+ {
9
+
10
+ use Rede_Pay_Trait_Data;
11
+
12
+ protected function _construct()
13
+ {
14
+ parent::_construct();
15
+ $this->setTemplate('rede/pay/form/method/standard.phtml');
16
+ }
17
+
18
+
19
+ /**
20
+ * @return string
21
+ */
22
+ public function getTextMessage()
23
+ {
24
+ $message = $this->_helper()->getConfigTextMessage();
25
+
26
+ if (empty($message)) {
27
+ $message = $this->__('You will proceed the payment right after the order placement.');
28
+ }
29
+
30
+ return $message;
31
+ }
32
+
33
+
34
+ /**
35
+ * @param int $width
36
+ *
37
+ * @return string
38
+ */
39
+ public function getLogoHtml($width = null)
40
+ {
41
+ return $this->_helper()->getLogoHtml($width);
42
+ }
43
+
44
+ }
app/code/community/Rede/Pay/Block/Info/Method/Standard.php ADDED
@@ -0,0 +1,175 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Tiago Sampaio <tiago@tiagosampaio.com>
4
+ *
5
+ * Class Rede_Pay_Block_Info_Method_Standard
6
+ */
7
+ class Rede_Pay_Block_Info_Method_Standard extends Mage_Payment_Block_Info
8
+ {
9
+
10
+ use Rede_Pay_Trait_Data,
11
+ Rede_Pay_Trait_Config;
12
+
13
+ /** @var Rede_Pay_Model_Payments */
14
+ protected $_payments = null;
15
+
16
+
17
+ protected function _construct()
18
+ {
19
+ parent::_construct();
20
+ $this->setTemplate('rede/pay/info/method/standard.phtml');
21
+ }
22
+
23
+
24
+ /**
25
+ * @param int $width
26
+ *
27
+ * @return string
28
+ */
29
+ public function getLogoHtml($width = null)
30
+ {
31
+ return $this->_helper()->getLogoHtml($width);
32
+ }
33
+
34
+
35
+ /**
36
+ * @return Rede_Pay_Model_Payments
37
+ */
38
+ public function getPayments()
39
+ {
40
+ return $this->_payments;
41
+ }
42
+
43
+
44
+ /**
45
+ * @return string
46
+ */
47
+ public function getPaymentId()
48
+ {
49
+ if ($this->_payments == null) {
50
+ $this->_initPaymentByOrder();
51
+ }
52
+
53
+ return $this->getPayments()->getPaymentId();
54
+ }
55
+
56
+
57
+ /**
58
+ * @return string
59
+ */
60
+ public function getTransactionId()
61
+ {
62
+ if ($this->_payments == null) {
63
+ $this->_initPaymentByOrder();
64
+ }
65
+
66
+ return $this->getPayments()->getTransactionId();
67
+ }
68
+
69
+
70
+ /**
71
+ * @return bool
72
+ */
73
+ public function canRetryPayment()
74
+ {
75
+ try {
76
+ /**
77
+ * Check is the allowed routes.
78
+ *
79
+ * @var Mage_Core_Controller_Front_Action $controller
80
+ */
81
+ $controller = Mage::app()->getFrontController()->getAction();
82
+ $actionName = $controller->getFullActionName('/');
83
+
84
+ $allowedActions = array(
85
+ 'sales/order/view',
86
+ 'redepay/checkout/state'
87
+ );
88
+
89
+ if (!in_array($actionName, $allowedActions)) {
90
+ return (bool) false;
91
+ }
92
+
93
+ // $enabled = (bool) Mage::getStoreConfig('payment/rede_pay/payment_retries_enabled');
94
+ // $maxTimes = (int) Mage::getStoreConfig('payment/rede_pay/max_payment_retries');
95
+
96
+ // if (!$enabled) {
97
+ // return (bool) false;
98
+ // }
99
+
100
+ /** @var Mage_Sales_Model_Order $order */
101
+ $order = $this->getInfo()->getOrder();
102
+ if (!$order || !$order->getId()) {
103
+ return (bool) false;
104
+ }
105
+
106
+ /** @var Rede_Pay_Model_Payments $payments */
107
+ // $payments = Mage::getModel('rede_pay/payments')->loadByOrderId($order->getId());
108
+
109
+ // if ($payments->getPaymentRetries() >= $maxTimes) {
110
+ // return (bool) false;
111
+ // }
112
+
113
+ /**
114
+ * The order needs to be in one of the following states:
115
+ * - pending_payment
116
+ * - processing
117
+ * - new
118
+ */
119
+ $allowedStates = array (
120
+ Mage_Sales_Model_Order::STATE_NEW,
121
+ Mage_Sales_Model_Order::STATE_PROCESSING,
122
+ Mage_Sales_Model_Order::STATE_PENDING_PAYMENT
123
+ );
124
+
125
+ if (!in_array($order->getState(), $allowedStates)) {
126
+ return (bool) false;
127
+ }
128
+
129
+ /**
130
+ * If you cannot invoice the order (and unhold it as well) it can mean that it's already invoiced.
131
+ */
132
+ if (!$order->canInvoice() && ($order->getState() !== Mage_Sales_Model_Order::STATE_HOLDED)) {
133
+ return (bool) false;
134
+ }
135
+
136
+ return (bool) true;
137
+ } catch (Exception $e) {
138
+ Mage::logException($e);
139
+ }
140
+
141
+ return (bool) false;
142
+ }
143
+
144
+
145
+ /**
146
+ * @return Mage_Sales_Model_Order
147
+ */
148
+ public function getOrder()
149
+ {
150
+ return $this->getInfo()->getOrder();
151
+ }
152
+
153
+
154
+ /**
155
+ * @param Mage_Sales_Model_Order|null $order
156
+ *
157
+ * @return $this
158
+ */
159
+ protected function _initPaymentByOrder(Mage_Sales_Model_Order $order = null)
160
+ {
161
+ if (empty($order)) {
162
+ $order = $this->getInfo()->getOrder();
163
+ }
164
+
165
+ if ($this->_payments) {
166
+ return $this;
167
+ }
168
+
169
+ $this->_payments = Mage::getModel('rede_pay/payments');
170
+ $this->_payments->loadByOrderId($order->getId());
171
+
172
+ return $this;
173
+ }
174
+
175
+ }
app/code/community/Rede/Pay/Block/Logo.php ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Tiago Sampaio <tiago@tiagosampaio.com>
4
+ *
5
+ * Class Rede_Pay_Block_Logo
6
+ *
7
+ * @method $this setWidth(int $width)
8
+ */
9
+ class Rede_Pay_Block_Logo extends Mage_Core_Block_Template
10
+ {
11
+
12
+ use Rede_Pay_Trait_Data;
13
+
14
+ const DEFAULT_LOGO_WIDTH = 180;
15
+
16
+ protected function _construct()
17
+ {
18
+ parent::_construct();
19
+ $this->setTemplate('rede/pay/logo.phtml');
20
+ }
21
+
22
+
23
+ /**
24
+ * @return string
25
+ */
26
+ public function getSrc()
27
+ {
28
+ return $this->getSkinUrl('rede/pay/images/redepay.png');
29
+ }
30
+
31
+
32
+ /**
33
+ * @return string
34
+ */
35
+ public function getTitle()
36
+ {
37
+ return $this->__('Rede Pay');
38
+ }
39
+
40
+
41
+ /**
42
+ * @return string
43
+ */
44
+ public function getAlt()
45
+ {
46
+ return $this->__('Rede Pay');
47
+ }
48
+
49
+
50
+ /**
51
+ * @return int
52
+ */
53
+ public function getWidth()
54
+ {
55
+ if (!$this->getData('width')) {
56
+ return self::DEFAULT_LOGO_WIDTH;
57
+ }
58
+
59
+ return $this->getData('width');
60
+ }
61
+
62
+ }
app/code/community/Rede/Pay/Controller/Adminhtml/Action.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Rede_Pay_Controller_Adminhtml_Action extends Mage_Adminhtml_Controller_Action
4
+ {
5
+
6
+ use Rede_Pay_Trait_Data;
7
+
8
+
9
+ /**
10
+ * @return Mage_Sales_Model_Order
11
+ */
12
+ protected function _initOrder($orderId = null)
13
+ {
14
+ if (empty($orderId)) {
15
+ $orderId = $this->getRequest()->getParam('order_id');
16
+ }
17
+
18
+ if (!$orderId) {
19
+ $this->_forward('noRoute');
20
+ return false;
21
+ }
22
+
23
+ /** @var Mage_Sales_Model_Order $order */
24
+ $order = Mage::getModel('sales/order')->load($orderId);
25
+
26
+ if (!$order->getId()) {
27
+ $this->_forward('noRoute');
28
+ return false;
29
+ }
30
+
31
+ if (!Mage::registry('current_order')) {
32
+ Mage::register('current_order', $order);
33
+ }
34
+
35
+ return $order;
36
+ }
37
+
38
+ }
app/code/community/Rede/Pay/Controller/Front/Action.php ADDED
@@ -0,0 +1,248 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Tiago Sampaio <tiago@tiagosampaio.com>
4
+ *
5
+ * Class Rede_Pay_Controller_Front_Action
6
+ */
7
+ class Rede_Pay_Controller_Front_Action extends Mage_Sales_Controller_Abstract
8
+ {
9
+
10
+ use Rede_Pay_Trait_Data;
11
+
12
+
13
+ /**
14
+ * @param bool|null|string $handles
15
+ * @param bool $generateBlocks
16
+ * @param bool $generateXml
17
+ *
18
+ * @return $this
19
+ */
20
+ protected function _initLayout($handles = null, $generateBlocks = true, $generateXml = true)
21
+ {
22
+ $this->loadLayout($handles, $generateBlocks, $generateXml);
23
+ $this->_title('Rede Pay');
24
+
25
+ return $this;
26
+ }
27
+
28
+
29
+ /**
30
+ * @param string $output
31
+ *
32
+ * @return $this
33
+ */
34
+ protected function _renderLayout($output = '')
35
+ {
36
+ $this->renderLayout($output);
37
+ return $this;
38
+ }
39
+
40
+
41
+ /**
42
+ * @return Mage_Sales_Model_Order
43
+ */
44
+ protected function _initOrder($orderId = null)
45
+ {
46
+ if (empty($orderId)) {
47
+ $orderId = $this->getRequest()->getParam('order_id');
48
+ }
49
+
50
+ if (empty($orderId)) {
51
+ $orderId = $this->_getCheckoutSession()->getLastOrderId();
52
+ }
53
+
54
+ if (!$orderId) {
55
+ $this->_forward('noRoute');
56
+ return false;
57
+ }
58
+
59
+ /** @var Mage_Sales_Model_Order $order */
60
+ $order = Mage::getModel('sales/order')->load($orderId);
61
+
62
+ if (!$order->getId()) {
63
+ $this->_forward('noRoute');
64
+ return false;
65
+ }
66
+
67
+ Mage::register('current_order', $order, true);
68
+
69
+ return $order;
70
+ }
71
+
72
+
73
+ /**
74
+ * @return bool
75
+ */
76
+ protected function _validateRequest($autoRedirect = true)
77
+ {
78
+ $result = true;
79
+
80
+ if (($autoRedirect == true) && ($result == false)) {
81
+ $this->_redirect('');
82
+ }
83
+
84
+ return (bool) $result;
85
+ }
86
+
87
+
88
+ /**
89
+ * @param Mage_Sales_Model_Order $order
90
+ *
91
+ * @return $this
92
+ */
93
+ protected function _redirectByOrder(Mage_Sales_Model_Order $order)
94
+ {
95
+ if (!$order->getId()) {
96
+ $this->_redirectCart();
97
+ return $this;
98
+ }
99
+
100
+ if ($order->isCanceled()) {
101
+ $this->_redirectPaymentError($order);
102
+ return $this;
103
+ }
104
+
105
+ switch ($order->getState()) {
106
+ case Mage_Sales_Model_Order::STATE_NEW:
107
+ $this->_redirectOrderPending($order);
108
+ break;
109
+ case Mage_Sales_Model_Order::STATE_CANCELED:
110
+ $this->_redirectPaymentError($order);
111
+ break;
112
+ case Mage_Sales_Model_Order::STATE_PROCESSING:
113
+ case Mage_Sales_Model_Order::STATE_COMPLETE:
114
+ case Mage_Sales_Model_Order::STATE_CLOSED:
115
+ case Mage_Sales_Model_Order::STATE_HOLDED:
116
+ case Mage_Sales_Model_Order::STATE_PAYMENT_REVIEW:
117
+ default:
118
+ $this->_redirectOrderState($order);
119
+ break;
120
+ }
121
+
122
+ return $this;
123
+ }
124
+
125
+
126
+ /**
127
+ * @return $this
128
+ */
129
+ protected function _redirectOrderState(Mage_Sales_Model_Order $order)
130
+ {
131
+ $this->_redirect('*/checkout/state', array('order_id' => $order->getId()));
132
+ return $this;
133
+ }
134
+
135
+
136
+ /**
137
+ * @return $this
138
+ */
139
+ protected function _redirectOrderPending(Mage_Sales_Model_Order $order)
140
+ {
141
+ $this->_redirect('*/checkout/pending', array('order_id' => $order->getId()));
142
+ return $this;
143
+ }
144
+
145
+
146
+ /**
147
+ * @return $this
148
+ */
149
+ protected function _redirectPaymentError(Mage_Sales_Model_Order $order)
150
+ {
151
+ $this->_redirect('*/checkout/error', array('order_id' => $order->getId()));
152
+ return $this;
153
+ }
154
+
155
+
156
+ /**
157
+ * @return $this
158
+ */
159
+ protected function _redirectCart()
160
+ {
161
+ $this->_redirect('checkout/cart');
162
+ return $this;
163
+ }
164
+
165
+
166
+ /**
167
+ * @return $this
168
+ */
169
+ protected function _clearSessions()
170
+ {
171
+ $this->_getSession()->clear();
172
+ $this->_getSession()->unsetData('last_transaction_info');
173
+
174
+ $this->_getCheckoutSession()->clear();
175
+ $this->_getCheckoutSession()->unsetData('last_order_id');
176
+ $this->_getCheckoutSession()->unsetData('last_quote_id');
177
+
178
+ return $this;
179
+ }
180
+
181
+
182
+ /**
183
+ * @return bool
184
+ */
185
+ protected function _isCustomerLoggedIn()
186
+ {
187
+ return $this->_getCustomerSession()->isLoggedIn();
188
+ }
189
+
190
+
191
+ /**
192
+ * @return int|null
193
+ */
194
+ protected function _getCustomerId()
195
+ {
196
+ return $this->_getCustomerSession()->getCustomerId();
197
+ }
198
+
199
+
200
+ /**
201
+ * @return Mage_Customer_Model_Session
202
+ */
203
+ protected function _getCustomerSession()
204
+ {
205
+ return Mage::getSingleton('customer/session');
206
+ }
207
+
208
+
209
+ /**
210
+ * Action used in most of the methods above.
211
+ */
212
+ protected function _common($clearSession = false)
213
+ {
214
+ $order = $this->_initOrder();
215
+
216
+ if (false === $order) {
217
+ return;
218
+ }
219
+
220
+ $this->_initLayout();
221
+ $this->_renderLayout();
222
+
223
+ if (true === $clearSession) {
224
+ $this->_clearSessions();
225
+ }
226
+ }
227
+
228
+
229
+ /**
230
+ * @return bool|int|mixed
231
+ */
232
+ protected function _initOrderId()
233
+ {
234
+ $orderId = $this->getRequest()->getParam('order_id', null);
235
+
236
+ if (empty($orderId)) {
237
+ $orderId = $this->_getLastOrderId();
238
+ }
239
+
240
+ if (empty($orderId)) {
241
+ $this->_redirectCart();
242
+ return false;
243
+ }
244
+
245
+ return $orderId;
246
+ }
247
+
248
+ }
app/code/community/Rede/Pay/Helper/Attributes.php ADDED
@@ -0,0 +1,350 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Tiago Sampaio <tiago@tiagosampaio.com>
4
+ *
5
+ * Class Rede_Pay_Helper_Attributes
6
+ */
7
+ class Rede_Pay_Helper_Attributes extends Rede_Pay_Helper_Data
8
+ {
9
+
10
+ /**
11
+ * @return string
12
+ */
13
+ public function getConfigAttributesTaxvat()
14
+ {
15
+ return $this->getPaymentConfig('attributes_taxvat');
16
+ }
17
+
18
+
19
+ /**
20
+ * @return string
21
+ */
22
+ public function getConfigAttributesTelephone()
23
+ {
24
+ return $this->getPaymentConfig('attributes_telephone');
25
+ }
26
+
27
+
28
+ /**
29
+ * @return string
30
+ */
31
+ public function getConfigAttributesCellphone()
32
+ {
33
+ return $this->getPaymentConfig('attributes_cellphone');
34
+ }
35
+
36
+
37
+ /**
38
+ * @return string
39
+ */
40
+ public function getConfigAttributesBusinessPhone()
41
+ {
42
+ return $this->getPaymentConfig('attributes_business_phone');
43
+ }
44
+
45
+
46
+ /**
47
+ * @return string
48
+ */
49
+ public function getConfigAttributesAddressStreet()
50
+ {
51
+ return $this->getPaymentConfig('attributes_street');
52
+ }
53
+
54
+
55
+ /**
56
+ * @return string
57
+ */
58
+ public function getConfigAttributesAddressNumber()
59
+ {
60
+ return $this->getPaymentConfig('attributes_number');
61
+ }
62
+
63
+
64
+ /**
65
+ * @return string
66
+ */
67
+ public function getConfigAttributesAddressComplement()
68
+ {
69
+ return $this->getPaymentConfig('attributes_complement');
70
+ }
71
+
72
+
73
+ /**
74
+ * @return string
75
+ */
76
+ public function getConfigAttributesAddressNeighborhood()
77
+ {
78
+ return $this->getPaymentConfig('attributes_neighborhood');
79
+ }
80
+
81
+
82
+ /**
83
+ * @param string $attributeCode
84
+ * @param Mage_Core_Model_Abstract $object
85
+ *
86
+ * @return null|string
87
+ */
88
+ public function extractEavAttributeValue($attributeCode = null, Mage_Core_Model_Abstract $object)
89
+ {
90
+ if (!empty($attributeCode) && $object->hasData($attributeCode)) {
91
+ return $object->getData($attributeCode);
92
+ }
93
+
94
+ return null;
95
+ }
96
+
97
+
98
+ /**
99
+ * @param Mage_Sales_Model_Order_Address $address
100
+ *
101
+ * @return null|string
102
+ */
103
+ public function getAddressStreet(Mage_Sales_Model_Order_Address $address)
104
+ {
105
+ /** @var string $code */
106
+ $code = $this->getConfigAttributesAddressStreet();
107
+
108
+ if (empty($code)) {
109
+ return null;
110
+ }
111
+
112
+ if ($data = $this->_getStreetLine($code, $address)) {
113
+ return $data;
114
+ }
115
+
116
+ return $this->extractEavAttributeValue($code, $address);
117
+ }
118
+
119
+
120
+ /**
121
+ * @param Mage_Sales_Model_Order_Address $address
122
+ *
123
+ * @return null|string
124
+ */
125
+ public function getAddressNumber(Mage_Sales_Model_Order_Address $address)
126
+ {
127
+ /** @var string $code */
128
+ $code = $this->getConfigAttributesAddressNumber();
129
+
130
+ if (empty($code)) {
131
+ return null;
132
+ }
133
+
134
+ if ($data = $this->_getStreetLine($code, $address)) {
135
+ return $data;
136
+ }
137
+
138
+ return $this->extractEavAttributeValue($code, $address);
139
+ }
140
+
141
+
142
+ /**
143
+ * @param Mage_Sales_Model_Order_Address $address
144
+ *
145
+ * @return null|string
146
+ */
147
+ public function getAddressComplement(Mage_Sales_Model_Order_Address $address)
148
+ {
149
+ /** @var string $code */
150
+ $code = $this->getConfigAttributesAddressComplement();
151
+
152
+ if (empty($code)) {
153
+ return null;
154
+ }
155
+
156
+ if ($data = $this->_getStreetLine($code, $address)) {
157
+ return $data;
158
+ }
159
+
160
+ return $this->extractEavAttributeValue($code, $address);
161
+ }
162
+
163
+
164
+ /**
165
+ * @param Mage_Sales_Model_Order_Address $address
166
+ *
167
+ * @return null|string
168
+ */
169
+ public function getAddressNeighborhood(Mage_Sales_Model_Order_Address $address)
170
+ {
171
+ /** @var string $code */
172
+ $code = $this->getConfigAttributesAddressNeighborhood();
173
+
174
+ if (empty($code)) {
175
+ return null;
176
+ }
177
+
178
+ if ($data = $this->_getStreetLine($code, $address)) {
179
+ return $data;
180
+ }
181
+
182
+ return $this->extractEavAttributeValue($code, $address);
183
+ }
184
+
185
+
186
+ /**
187
+ * @param Mage_Customer_Model_Customer $customer
188
+ * @param Mage_Sales_Model_Order_Address $address
189
+ *
190
+ * @return null|string
191
+ */
192
+ public function getTaxvat(Mage_Customer_Model_Customer $customer, Mage_Sales_Model_Order_Address $address)
193
+ {
194
+ $taxvat = $this->extractEavAttributeValue($this->getConfigAttributesTaxvat(), $customer);
195
+
196
+ if (empty($taxvat)) {
197
+ $taxvat = $this->extractEavAttributeValue($this->getConfigAttributesTaxvat(), $address);
198
+ }
199
+
200
+ if (empty($taxvat)) {
201
+ $taxvat = $address->getOrder()->getCustomerTaxvat();
202
+ }
203
+
204
+ $taxvat = $this->_removeNonNumbers($taxvat);
205
+
206
+ return $taxvat;
207
+ }
208
+
209
+
210
+ public function getPostcode(Mage_Sales_Model_Order_Address $address)
211
+ {
212
+ $postcode = $address->getPostcode();
213
+ return $this->_preparePostcode($postcode);
214
+ }
215
+
216
+
217
+ /**
218
+ * @param Mage_Sales_Model_Order_Address $address
219
+ *
220
+ * @return null|string
221
+ */
222
+ public function getTelephone(Mage_Sales_Model_Order_Address $address)
223
+ {
224
+ $number = $this->extractEavAttributeValue($this->getConfigAttributesTelephone(), $address);
225
+ return $this->_preparePhoneNumber($number);
226
+ }
227
+
228
+
229
+ /**
230
+ * @param Mage_Sales_Model_Order_Address $address
231
+ *
232
+ * @return null|string
233
+ */
234
+ public function getCellphone(Mage_Sales_Model_Order_Address $address)
235
+ {
236
+ $number = $this->extractEavAttributeValue($this->getConfigAttributesCellphone(), $address);
237
+ return $this->_preparePhoneNumber($number);
238
+ }
239
+
240
+
241
+ /**
242
+ * @param Mage_Sales_Model_Order_Address $address
243
+ *
244
+ * @return null|string
245
+ */
246
+ public function getBusinessPhone(Mage_Sales_Model_Order_Address $address)
247
+ {
248
+ $number = $this->extractEavAttributeValue($this->getConfigAttributesBusinessPhone(), $address);
249
+ return $this->_preparePhoneNumber($number);
250
+ }
251
+
252
+
253
+ /**
254
+ * @param string $number
255
+ *
256
+ * @return mixed|string
257
+ */
258
+ protected function _preparePhoneNumber(&$number = null)
259
+ {
260
+ $number = $this->_removeNonNumbers($number);
261
+
262
+ if (!$this->isValidPhoneNumber($number)) {
263
+ return null;
264
+ }
265
+
266
+ $startAt = max((strlen($number) - 11), 0);
267
+ $number = substr($number, $startAt, 11);
268
+
269
+ if (strlen($number) < 10) {
270
+ $number = str_pad($number, 10, '0', STR_PAD_LEFT);
271
+ }
272
+
273
+ return $number;
274
+ }
275
+
276
+
277
+ /**
278
+ * @param string $postcode
279
+ *
280
+ * @return mixed|string
281
+ */
282
+ protected function _preparePostcode(&$postcode = null)
283
+ {
284
+ $postcode = $this->_removeNonNumbers($postcode);
285
+
286
+ if (empty($postcode)) {
287
+ Mage::throwException($this->__('The postcode number cannot be empty. Please insert a correct value.'));
288
+ }
289
+
290
+ if (strlen($postcode) < 8) {
291
+ $postcode = str_pad($postcode, 8, '0', STR_PAD_LEFT);
292
+ }
293
+
294
+ return $postcode;
295
+ }
296
+
297
+
298
+ /**
299
+ * @param string $data
300
+ *
301
+ * @return int
302
+ */
303
+ protected function _removeNonNumbers(&$data = null)
304
+ {
305
+ $data = preg_replace('/[^0-9]/', null, $data);
306
+ return $data;
307
+ }
308
+
309
+
310
+ /**
311
+ * @param string $number
312
+ *
313
+ * @return bool
314
+ */
315
+ public function isValidPhoneNumber(&$number = null)
316
+ {
317
+ $result = true;
318
+
319
+ if (empty($number)) {
320
+ $result = false;
321
+ }
322
+
323
+ if (strlen($number) < 8) {
324
+ false;
325
+ }
326
+
327
+ return (bool) $result;
328
+ }
329
+
330
+
331
+ /**
332
+ * @param string $code
333
+ * @param Mage_Sales_Model_Order_Address $address
334
+ *
335
+ * @return null|string
336
+ */
337
+ protected function _getStreetLine($code, Mage_Sales_Model_Order_Address $address)
338
+ {
339
+ if (strpos($code, 'street_') !== false) {
340
+ $split = explode('_', $code);
341
+
342
+ if (isset($split[1])) {
343
+ return $address->getStreet((int) $split[1]);
344
+ }
345
+ }
346
+
347
+ return null;
348
+ }
349
+
350
+ }
app/code/community/Rede/Pay/Helper/Data.php ADDED
@@ -0,0 +1,396 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Tiago Sampaio <tiago@tiagosampaio.com>
4
+ *
5
+ * Class Rede_Pay_Helper_Data
6
+ */
7
+ class Rede_Pay_Helper_Data extends Mage_Core_Helper_Data
8
+ {
9
+
10
+ const DEFAULT_LIGHTBOX_DELAY_TIME = 5;
11
+
12
+
13
+ /**
14
+ * @param string $field
15
+ *
16
+ * @return string
17
+ */
18
+ public function getPaymentConfig($field)
19
+ {
20
+ return Mage::getStoreConfig(implode('/', array('payment', 'rede_pay', $field)));
21
+ }
22
+
23
+
24
+ /**
25
+ * @return int
26
+ */
27
+ public function getLightboxDelaySeconds()
28
+ {
29
+ $seconds = $this->getPaymentConfig('lightbox_delay_time');
30
+
31
+ if (is_null($seconds)) {
32
+ $seconds = self::DEFAULT_LIGHTBOX_DELAY_TIME;
33
+ }
34
+
35
+ return (int) $seconds;
36
+ }
37
+
38
+
39
+ /**
40
+ * @return int
41
+ */
42
+ public function getLightboxDelayMiliseconds()
43
+ {
44
+ return (int) ($this->getLightboxDelaySeconds() * 1000);
45
+ }
46
+
47
+
48
+ /**
49
+ * @return int
50
+ */
51
+ public function getConfigInstallmentsAmount()
52
+ {
53
+ return (int) $this->getPaymentConfig('installments_amount');
54
+ }
55
+
56
+
57
+ /**
58
+ * @return int
59
+ */
60
+ public function getConfigInstallmentsMinOrderValue()
61
+ {
62
+ return (int) $this->getPaymentConfig('installments_min_order_value');
63
+ }
64
+
65
+
66
+ /**
67
+ * @return int
68
+ */
69
+ public function getConfigInstallmentsMinParcelValue()
70
+ {
71
+ return (int) $this->getPaymentConfig('installments_min_parcel_value');
72
+ }
73
+
74
+
75
+ /**
76
+ * @return string
77
+ */
78
+ public function getConfigApiOrderUrl()
79
+ {
80
+ return $this->getPaymentConfig('api_order_url');
81
+ }
82
+
83
+
84
+ /**
85
+ * @param null $transactionId
86
+ *
87
+ * @return string
88
+ */
89
+ public function getConfigApiConsultUrl($transactionId = null)
90
+ {
91
+ $url = $this->getPaymentConfig('api_consult_url');
92
+
93
+ if (substr($url, -1) !== '/') {
94
+ $url .= '/';
95
+ }
96
+
97
+ if (!is_null($transactionId)) {
98
+ $url .= $transactionId;
99
+ }
100
+
101
+ return $url;
102
+ }
103
+
104
+
105
+ /**
106
+ * @param string $paymentId
107
+ *
108
+ * @return string
109
+ */
110
+ public function getConfigApiConsultOrderUrl($paymentId = null)
111
+ {
112
+ $url = $this->getPaymentConfig('api_consult_order_url');
113
+
114
+ if (substr($url, -1) !== '/') {
115
+ $url .= '/';
116
+ }
117
+
118
+ if (!is_null($paymentId)) {
119
+ $url .= $paymentId;
120
+ }
121
+
122
+ return $url;
123
+ }
124
+
125
+
126
+ /**
127
+ * @return string
128
+ */
129
+ public function getConfigApiRefundUrl($paymentId = null)
130
+ {
131
+ $url = $this->getPaymentConfig('api_refund_url');
132
+
133
+ if (substr($url, -1) !== '/') {
134
+ $url .= '/';
135
+ }
136
+
137
+ if (!is_null($paymentId)) {
138
+ $url .= $paymentId;
139
+ }
140
+
141
+ return $url;
142
+ }
143
+
144
+
145
+ /**
146
+ * @return string
147
+ */
148
+ public function getConfigApiShippingTrackingUrl($transactionId)
149
+ {
150
+ $url = $this->getPaymentConfig('api_shipping_tracking_url');
151
+
152
+ if (substr($url, -1) !== '/') {
153
+ $url .= '/';
154
+ }
155
+
156
+ $url .= $transactionId . '/trackings';
157
+
158
+ return $url;
159
+ }
160
+
161
+
162
+ /**
163
+ * @return string
164
+ */
165
+ public function getConfigRedePayScriptUrl()
166
+ {
167
+ return $this->getPaymentConfig('redepay_script_url');
168
+ }
169
+
170
+
171
+ /**
172
+ * @return string
173
+ */
174
+ public function getConfigSecretApiKey()
175
+ {
176
+ $key = 'secret_api_key';
177
+
178
+ if ($this->isTestMode()) {
179
+ $key .= '_test';
180
+ }
181
+
182
+ return $this->getPaymentConfig($key);
183
+ }
184
+
185
+
186
+ /**
187
+ * @return string
188
+ */
189
+ public function getConfigNotificationToken()
190
+ {
191
+ $key = 'notification_token';
192
+
193
+ if ($this->isTestMode()) {
194
+ $key .= '_test';
195
+ }
196
+
197
+ return $this->getPaymentConfig($key);
198
+ }
199
+
200
+
201
+ /**
202
+ * @return string
203
+ */
204
+ public function getConfigPublishableApiKey()
205
+ {
206
+ $key = 'publishable_api_key';
207
+
208
+ if ($this->isTestMode()) {
209
+ $key .= '_test';
210
+ }
211
+
212
+ return $this->getPaymentConfig($key);
213
+ }
214
+
215
+
216
+ /**
217
+ * @return bool
218
+ */
219
+ public function isTestMode()
220
+ {
221
+ return (bool) $this->getPaymentConfig('test');
222
+ }
223
+
224
+
225
+ /**
226
+ * @return string
227
+ */
228
+ public function getConfigTextMessage()
229
+ {
230
+ return (string) $this->getPaymentConfig('text_message');
231
+ }
232
+
233
+
234
+ /**
235
+ * @param int $orderId
236
+ *
237
+ * @return string
238
+ */
239
+ public function getNotificationUrl($orderId = null)
240
+ {
241
+ return $this->_prepareUrl('redepay/notification', $orderId);
242
+ }
243
+
244
+
245
+ /**
246
+ * @param int $orderId
247
+ *
248
+ * @return string
249
+ */
250
+ public function getRedirectUrl($orderId = null)
251
+ {
252
+ return $this->_prepareUrl('redepay/notification/redirect', $orderId);
253
+ }
254
+
255
+
256
+ /**
257
+ * @param int $orderId
258
+ *
259
+ * @return string
260
+ */
261
+ public function getCancelUrl($orderId = null)
262
+ {
263
+ return $this->_prepareUrl('redepay/notification/cancel', $orderId);
264
+ }
265
+
266
+
267
+ /**
268
+ * @param int $width
269
+ *
270
+ * @return Rede_Pay_Block_Logo
271
+ */
272
+ public function getLogoBlock($width = null)
273
+ {
274
+ return Mage::app()->getLayout()->createBlock('rede_pay/logo')->setWidth($width);
275
+ }
276
+
277
+
278
+ /**
279
+ * @param int $width
280
+ *
281
+ * @return string
282
+ */
283
+ public function getLogoHtml($width = null)
284
+ {
285
+ return $this->getLogoBlock($width)->toHtml();
286
+ }
287
+
288
+
289
+ /**
290
+ * @param Mage_Sales_Model_Order $order
291
+ * @param array $result
292
+ *
293
+ * @return string
294
+ */
295
+ public function processOrderConsultStatus(Mage_Sales_Model_Order $order, $status = null, $result = array(),
296
+ $processType = null)
297
+ {
298
+ return $this->getOrderProcessor()->processOrderConsultStatus($order, $status, $result, $processType);
299
+ }
300
+
301
+
302
+ /**
303
+ * @param Mage_Sales_Model_Order $order
304
+ * @param string $status
305
+ * @param string $process
306
+ *
307
+ * @return $this
308
+ *
309
+ * @throws Exception
310
+ * @throws bool
311
+ */
312
+ public function processOrderStatus(Mage_Sales_Model_Order $order, $status, $processType = null)
313
+ {
314
+ return $this->getOrderProcessor()->processOrderStatus($order, $status, $processType);
315
+ }
316
+
317
+
318
+ /**
319
+ * @return Rede_Pay_Model_Session
320
+ */
321
+ public function getSession()
322
+ {
323
+ return Mage::getSingleton('rede_pay/session');
324
+ }
325
+
326
+
327
+ /**
328
+ * @return Mage_Checkout_Model_Session
329
+ */
330
+ public function getCheckoutSession()
331
+ {
332
+ return Mage::getSingleton('checkout/session');
333
+ }
334
+
335
+
336
+ /**
337
+ * @return Mage_Adminhtml_Model_Session
338
+ */
339
+ public function getAdminSession()
340
+ {
341
+ return Mage::getSingleton('adminhtml/session');
342
+ }
343
+
344
+
345
+ /**
346
+ * @return Rede_Pay_Model_Logger
347
+ */
348
+ public function getLogger()
349
+ {
350
+ return Mage::getSingleton('rede_pay/logger');
351
+ }
352
+
353
+
354
+ /**
355
+ * @return Rede_Pay_Model_Processor_Order
356
+ */
357
+ public function getOrderProcessor()
358
+ {
359
+ return Mage::getSingleton('rede_pay/processor_order');
360
+ }
361
+
362
+
363
+ /**
364
+ * @return Rede_Pay_Model_Processor
365
+ */
366
+ public function getProcessor()
367
+ {
368
+ return Mage::getSingleton('rede_pay/processor');
369
+ }
370
+
371
+
372
+ /**
373
+ * @param string $route
374
+ * @param int $orderId
375
+ *
376
+ * @return string
377
+ */
378
+ protected function _prepareUrl($route, $orderId = null)
379
+ {
380
+ $parameters = array();
381
+
382
+ if ($orderId) {
383
+ $parameters['order_id'] = $orderId;
384
+ }
385
+
386
+ $base = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
387
+ $full = $base . $route;
388
+
389
+ foreach ($parameters as $key => $value) {
390
+ $full .= '/' . $key . '/' . $value;
391
+ }
392
+
393
+ return $full;
394
+ }
395
+
396
+ }
app/code/community/Rede/Pay/Model/Abstract.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Tiago Sampaio <tiago@tiagosampaio.com>
4
+ *
5
+ * Class Rede_Pay_Model_Abstract
6
+ */
7
+ abstract class Rede_Pay_Model_Abstract extends Mage_Core_Model_Abstract
8
+ {
9
+
10
+ use Rede_Pay_Trait_Data;
11
+
12
+ /**
13
+ * @return $this
14
+ */
15
+ protected function _beforeSave()
16
+ {
17
+ parent::_beforeSave();
18
+
19
+ if ($this->isObjectNew()) {
20
+ $this->setData('created_at', now());
21
+ } else {
22
+ $this->setData('updated_at', now());
23
+ }
24
+
25
+ return $this;
26
+ }
27
+
28
+ }
app/code/community/Rede/Pay/Model/Api.php ADDED
@@ -0,0 +1,552 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Tiago Sampaio <tiago@tiagosampaio.com>
4
+ *
5
+ * Class Rede_Pay_Model_Api
6
+ */
7
+ class Rede_Pay_Model_Api
8
+ {
9
+
10
+ use Rede_Pay_Trait_Data;
11
+
12
+ /** These two statuses were discontinued. */
13
+ const STATUS_APPROVED = 'APPROVED';
14
+ const STATUS_DENIED = 'DENIED';
15
+
16
+ /** These are the valid ones. */
17
+ const STATUS_OPEN = 'OPEN';
18
+ const STATUS_CANCELLED = 'CANCELLED';
19
+ const STATUS_COMPLETED = 'COMPLETED';
20
+ const STATUS_IN_DISPUTE = 'IN_DISPUTE';
21
+ const STATUS_REVERSED = 'REVERSED';
22
+ const STATUS_CHARGEBACK = 'CHARGEBACK';
23
+ const STATUS_IN_ANALYSIS = 'IN_ANALYSIS';
24
+
25
+
26
+ /** @var Zend_Http_Client */
27
+ protected $_client = null;
28
+
29
+ /** @var Zend_Http_Response */
30
+ protected $_result = null;
31
+
32
+ /** @var string */
33
+ protected $_rawBody = null;
34
+
35
+ /** @var array */
36
+ protected $_body = null;
37
+
38
+
39
+ /**
40
+ * @return $this
41
+ */
42
+ public function clean()
43
+ {
44
+ $this->_client = null;
45
+ $this->_result = null;
46
+ $this->_rawBody = null;
47
+ $this->_body = null;
48
+
49
+ return $this;
50
+ }
51
+
52
+
53
+ /**
54
+ * Return the allowed statuses for orders in API.
55
+ *
56
+ * @return array
57
+ */
58
+ public static function getAllowedStatuses()
59
+ {
60
+ return array(
61
+ self::STATUS_OPEN,
62
+ self::STATUS_APPROVED,
63
+ self::STATUS_REVERSED,
64
+ self::STATUS_IN_DISPUTE,
65
+ self::STATUS_CHARGEBACK,
66
+ self::STATUS_IN_ANALYSIS,
67
+ self::STATUS_DENIED,
68
+ self::STATUS_CANCELLED,
69
+ self::STATUS_COMPLETED
70
+ );
71
+ }
72
+
73
+
74
+ /**
75
+ * Return the approved statuses for orders in API.
76
+ *
77
+ * @return array
78
+ */
79
+ public static function getApprovedStatuses()
80
+ {
81
+ return array(
82
+ self::STATUS_APPROVED,
83
+ self::STATUS_COMPLETED
84
+ );
85
+ }
86
+
87
+
88
+ /**
89
+ * Return the approved statuses for orders in API.
90
+ *
91
+ * @return array
92
+ */
93
+ public static function getCancelledStatuses()
94
+ {
95
+ return array(
96
+ self::STATUS_DENIED,
97
+ self::STATUS_CANCELLED
98
+ );
99
+ }
100
+
101
+
102
+ /**
103
+ * Return the approved statuses for orders in API.
104
+ *
105
+ * @return array
106
+ */
107
+ public static function getOpenStatuses()
108
+ {
109
+ return array(
110
+ self::STATUS_OPEN,
111
+ );
112
+ }
113
+
114
+
115
+ /**
116
+ * Return the in analysis statuses for orders in API.
117
+ *
118
+ * @return array
119
+ */
120
+ public static function getInAnalysisStatuses()
121
+ {
122
+ return array(
123
+ self::STATUS_IN_ANALYSIS
124
+ );
125
+ }
126
+
127
+
128
+ /**
129
+ * Check if given status is approved.
130
+ *
131
+ * @param string $status
132
+ *
133
+ * @return bool
134
+ */
135
+ public function isStatusApproved($status)
136
+ {
137
+ return (bool) in_array($status, $this->getApprovedStatuses());
138
+ }
139
+
140
+
141
+ /**
142
+ * Check if given status is approved.
143
+ *
144
+ * @param string $status
145
+ *
146
+ * @return bool
147
+ */
148
+ public function isStatusInAnalysis($status)
149
+ {
150
+ return (bool) in_array($status, $this->getInAnalysisStatuses());
151
+ }
152
+
153
+
154
+ /**
155
+ * Check if given status is cancelled.
156
+ *
157
+ * @param string $status
158
+ *
159
+ * @return bool
160
+ */
161
+ public function isStatusCancelled($status)
162
+ {
163
+ return (bool) in_array($status, $this->getCancelledStatuses());
164
+ }
165
+
166
+
167
+ /**
168
+ * Check if given status is cancelled.
169
+ *
170
+ * @param string $status
171
+ *
172
+ * @return bool
173
+ */
174
+ public function isStatusOpen($status)
175
+ {
176
+ return (bool) in_array($status, $this->getOpenStatuses());
177
+ }
178
+
179
+
180
+ /**
181
+ * Check if given status is a valid one.
182
+ *
183
+ * @param string $status
184
+ *
185
+ * @return bool
186
+ */
187
+ public function isStatusAllowed($status)
188
+ {
189
+ return (bool) in_array($status, $this->getAllowedStatuses());
190
+ }
191
+
192
+
193
+ /**
194
+ * @return Zend_Http_Client
195
+ *
196
+ * @throws Zend_Http_Client_Exception
197
+ */
198
+ public function getClient()
199
+ {
200
+ if (!$this->_client) {
201
+ $secretKey = $this->_helper()->getConfigSecretApiKey();
202
+
203
+ $this->_client = new Zend_Http_Client();
204
+
205
+ $this->_client->setHeaders('access-token', $secretKey);
206
+ $this->_client->setHeaders('version' , 'v1');
207
+ $this->_client->setHeaders('Content-Type', 'application/json');
208
+ $this->_client->setHeaders('Accept' , 'application/json');
209
+
210
+ $this->_client->setMethod(Zend_Http_Client::POST);
211
+ }
212
+
213
+ return $this->_client;
214
+ }
215
+
216
+
217
+ /**
218
+ * @return $this
219
+ *
220
+ * @throws Zend_Http_Client_Exception
221
+ */
222
+ public function request($method = 'order')
223
+ {
224
+ if (method_exists($this, $method)) {
225
+ $this->$method();
226
+ } else {
227
+ Mage::throwException($this->_helper()->__("Method '%s' does not exist.", $method));
228
+ }
229
+
230
+ return $this;
231
+ }
232
+
233
+
234
+ /**
235
+ * Do the order request in API.
236
+ *
237
+ * @var Mage_Sales_Model_Order $order
238
+ *
239
+ * @return $this
240
+ *
241
+ * @throws Zend_Http_Client_Exception
242
+ */
243
+ public function order(Mage_Sales_Model_Order $order = null)
244
+ {
245
+ $this->clean();
246
+
247
+ if ($order && $order->getId()) {
248
+ $this->_processor()->setOrder($order);
249
+ }
250
+
251
+ $json = $this->_processor()->getOrderJson();
252
+
253
+ $this->getClient()->setRawData($json, 'application/json');
254
+ $this->getClient()->setUri($this->_helper()->getConfigApiOrderUrl());
255
+
256
+ $this->_logger()->startTransactionLog($this->getOrder()->getRealOrderId());
257
+ $this->_logger()->logHeaders($this->_client);
258
+ $this->_logger()->logMethod(Zend_Http_Client::POST);
259
+ $this->_logger()->log($this->_helper()->__('Transaction URL: %s.', $this->getClient()->getUri()));
260
+ $this->_logger()->log($this->_helper()->__('Order Request: %s.', $json), false);
261
+
262
+ $this->_result = $this->getClient()->request();
263
+ $this->_rawBody = $this->_result->getBody();
264
+ $this->_body = $this->_helper()->jsonDecode($this->_rawBody);
265
+
266
+ $this->_logger()->log($this->_helper()->__('Order Response: %s.', $this->_rawBody), false);
267
+
268
+ $this->_logger()->finishTransactionLog($this->getOrder()->getRealOrderId());
269
+
270
+ return $this;
271
+ }
272
+
273
+
274
+ /**
275
+ * Do refund request in the API.
276
+ *
277
+ * @var string $transactionId
278
+ * @var Mage_Sales_Model_Order $order
279
+ *
280
+ * @return $this
281
+ *
282
+ * @throws Zend_Http_Client_Exception
283
+ */
284
+ public function refund($transactionId = null, Mage_Sales_Model_Order $order = null)
285
+ {
286
+ $this->clean();
287
+
288
+ if ($order && $order->getId()) {
289
+ $this->_processor()->setOrder($order);
290
+ }
291
+
292
+ $json = $this->_processor()->getRefundJson();
293
+
294
+ $this->getClient()->setRawData($json, 'application/json');
295
+ $this->getClient()->setUri($this->_helper()->getConfigApiRefundUrl($transactionId));
296
+ $this->getClient()->setMethod(Zend_Http_Client::PUT);
297
+
298
+ $this->_logger()->startRefundLog($this->getOrder()->getRealOrderId());
299
+ $this->_logger()->logHeaders($this->_client);
300
+ $this->_logger()->logMethod(Zend_Http_Client::PUT);
301
+ $this->_logger()->log($this->_helper()->__('Refund URL: %s.', $this->getClient()->getUri()));
302
+ $this->_logger()->log($this->_helper()->__('Refund Request: %s.', $json), false);
303
+
304
+ $this->_result = $this->getClient()->request();
305
+ $this->_rawBody = $this->_result->getBody();
306
+ $this->_body = $this->_helper()->jsonDecode($this->_rawBody);
307
+
308
+ $this->_logger()->log($this->_helper()->__('Refund Response: %s.', $this->_rawBody), false);
309
+
310
+ $this->_logger()->finishRefundLog($this->getOrder()->getRealOrderId());
311
+
312
+ return $this;
313
+ }
314
+
315
+
316
+ /**
317
+ * Do consult request in the API.
318
+ *
319
+ * @var string $transactionId
320
+ * @var Mage_Sales_Model_Order $order
321
+ *
322
+ * @return $this
323
+ *
324
+ * @throws Zend_Http_Client_Exception
325
+ */
326
+ public function consult($transactionId = null, Mage_Sales_Model_Order $order = null)
327
+ {
328
+ $this->clean();
329
+
330
+ if ($order && $order->getId()) {
331
+ $this->_processor()->setOrder($order);
332
+ }
333
+
334
+ $json = $this->_processor()->getConsultJson();
335
+
336
+ $this->getClient()->setRawData($json, 'application/json');
337
+ $this->getClient()->setUri($this->_helper()->getConfigApiConsultUrl($transactionId));
338
+ $this->getClient()->setMethod(Zend_Http_Client::GET);
339
+
340
+ $this->_logger()->startConsultLog($this->getOrder()->getRealOrderId());
341
+ $this->_logger()->logHeaders($this->_client);
342
+ $this->_logger()->logMethod(Zend_Http_Client::GET);
343
+ $this->_logger()->log($this->_helper()->__('Consult URL: %s.', $this->getClient()->getUri()));
344
+ $this->_logger()->log($this->_helper()->__('Consult Request: %s.', $json), false);
345
+
346
+ try {
347
+ $this->_result = $this->getClient()->request();
348
+ $this->_rawBody = $this->_result->getBody();
349
+ $this->_body = $this->_helper()->jsonDecode($this->_rawBody);
350
+
351
+ $this->_logger()->log($this->_helper()->__('Consult Response: %s.', $this->_rawBody), false);
352
+ } catch (Exception $e) {
353
+ Mage::logException($e);
354
+ $this->_logger()->log('Exception: ' . $e->getMessage(), false);
355
+ }
356
+
357
+ $this->_logger()->finishConsultLog($this->getOrder()->getRealOrderId());
358
+
359
+ return $this;
360
+ }
361
+
362
+
363
+ /**
364
+ * Do consult order request in the API.
365
+ *
366
+ * @var string $paymentId
367
+ * @var Mage_Sales_Model_Order $order
368
+ *
369
+ * @return $this
370
+ *
371
+ * @throws Zend_Http_Client_Exception
372
+ */
373
+ public function consultOrder($paymentId = null, Mage_Sales_Model_Order $order = null)
374
+ {
375
+ $this->clean();
376
+
377
+ if ($order && $order->getId()) {
378
+ $this->_processor()->setOrder($order);
379
+ }
380
+
381
+ $json = $this->_processor()->getConsultJson();
382
+
383
+ $this->getClient()->setRawData($json, 'application/json');
384
+ $this->getClient()->setUri($this->_helper()->getConfigApiConsultOrderUrl($paymentId));
385
+ $this->getClient()->setMethod(Zend_Http_Client::GET);
386
+
387
+ $this->_logger()->startConsultLog($this->getOrder()->getRealOrderId());
388
+ $this->_logger()->logHeaders($this->_client);
389
+ $this->_logger()->logMethod(Zend_Http_Client::GET);
390
+ $this->_logger()->log($this->_helper()->__('Consult URL: %s.', $this->getClient()->getUri()));
391
+ $this->_logger()->log($this->_helper()->__('Consult Order Request: %s.', $json), false);
392
+
393
+ try {
394
+ $this->_result = $this->getClient()->request();
395
+ $this->_rawBody = $this->_result->getBody();
396
+ $this->_body = $this->_helper()->jsonDecode($this->_rawBody);
397
+
398
+ $this->_logger()->log($this->_helper()->__('Consult Order Response: %s.', $this->_rawBody), false);
399
+ } catch (Exception $e) {
400
+ Mage::logException($e);
401
+ $this->_logger()->log('Exception: ' . $e->getMessage(), false);
402
+ }
403
+
404
+ $this->_logger()->finishConsultLog($this->getOrder()->getRealOrderId());
405
+
406
+ return $this;
407
+ }
408
+
409
+
410
+ /**
411
+ * @param string $trackingNumber
412
+ * @param string $transactionId
413
+ * @param Mage_Sales_Model_Order $order
414
+ *
415
+ * @return $this
416
+ */
417
+ public function addShippingTracking($trackingNumber, $transactionId, Mage_Sales_Model_Order $order = null)
418
+ {
419
+ $this->clean();
420
+
421
+ if ($order && $order->getId()) {
422
+ $this->_processor()->setOrder($order);
423
+ }
424
+
425
+ $json = $this->_processor()->getShippingTrackingJson($trackingNumber);
426
+
427
+ $this->getClient()->setRawData($json, 'application/json');
428
+ $this->getClient()->setUri($this->_helper()->getConfigApiShippingTrackingUrl($transactionId));
429
+ $this->getClient()->setMethod(Zend_Http_Client::POST);
430
+
431
+ $this->_logger()->startShippingTrackingLog($this->getOrder()->getRealOrderId());
432
+ $this->_logger()->logHeaders($this->_client);
433
+ $this->_logger()->logMethod(Zend_Http_Client::POST);
434
+ $this->_logger()->log($this->_helper()->__('Add Shipping Tracking URL: %s.', $this->getClient()->getUri()));
435
+ $this->_logger()->log($this->_helper()->__('Add Shipping Tracking Request: %s.', $json), false);
436
+
437
+ try {
438
+
439
+ $this->_result = $this->getClient()->request();
440
+ $this->_rawBody = $this->_result->getBody();
441
+ $this->_body = $this->_helper()->jsonDecode($this->_rawBody);
442
+
443
+ $this->_logger()->log($this->_helper()->__('Add Shipping Tracking Response: %s.', $this->_rawBody), false);
444
+ } catch (Exception $e) {
445
+ Mage::logException($e);
446
+ $this->_logger()->log('Exception: ' . $e->getMessage(), false);
447
+ }
448
+
449
+ $this->_logger()->finishShippingTrackingLog($this->getOrder()->getRealOrderId());
450
+
451
+ return $this;
452
+ }
453
+
454
+
455
+ /**
456
+ * @param string $transactionId
457
+ * @param Mage_Sales_Model_Order $order
458
+ *
459
+ * @return $this
460
+ */
461
+ public function deleteShippingTracking($paymentId, Mage_Sales_Model_Order $order = null)
462
+ {
463
+ $this->clean();
464
+
465
+ if ($order && $order->getId()) {
466
+ $this->_processor()->setOrder($order);
467
+ }
468
+
469
+ $json = $this->_processor()->getShippingTrackingDeleteJson();
470
+
471
+ $this->getClient()->setRawData($json, 'application/json');
472
+ $this->getClient()->setUri($this->_helper()->getConfigApiShippingTrackingUrl($paymentId));
473
+ $this->getClient()->setMethod(Zend_Http_Client::DELETE);
474
+
475
+ $this->_logger()->startShippingTrackingLog($this->getOrder()->getRealOrderId());
476
+ $this->_logger()->logHeaders($this->_client);
477
+ $this->_logger()->logMethod(Zend_Http_Client::DELETE);
478
+ $this->_logger()->log($this->_helper()->__('Delete Shipping Tracking URL: %s.', $this->getClient()->getUri()));
479
+ $this->_logger()->log($this->_helper()->__('Delete Shipping Tracking Request: %s.', $json), false);
480
+
481
+ try {
482
+
483
+ $this->_result = $this->getClient()->request();
484
+ $this->_rawBody = $this->_result->getBody();
485
+ $this->_body = $this->_helper()->jsonDecode($this->_rawBody);
486
+
487
+ $this->_logger()->log($this->_helper()->__('Delete Shipping Tracking Response: %s.', $this->_rawBody), false);
488
+ } catch (Exception $e) {
489
+ Mage::logException($e);
490
+ $this->_logger()->log('Exception: ' . $e->getMessage(), false);
491
+ }
492
+
493
+ $this->_logger()->finishShippingTrackingLog($this->getOrder()->getRealOrderId());
494
+
495
+ return $this;
496
+ }
497
+
498
+
499
+ /**
500
+ * @return Zend_Http_Response
501
+ */
502
+ public function getResult()
503
+ {
504
+ return $this->_result;
505
+ }
506
+
507
+
508
+ /**
509
+ * @return string
510
+ */
511
+ public function getRawBody()
512
+ {
513
+ return $this->_rawBody;
514
+ }
515
+
516
+
517
+ /**
518
+ * @return array
519
+ */
520
+ public function getBody()
521
+ {
522
+ return $this->_body;
523
+ }
524
+
525
+
526
+ /**
527
+ * @return Mage_Sales_Model_Order
528
+ */
529
+ public function getOrder()
530
+ {
531
+ return $this->_processor()->getOrder();
532
+ }
533
+
534
+
535
+ /**
536
+ * @return bool
537
+ */
538
+ public function getIsOrderFound()
539
+ {
540
+ switch ($this->getResult()->getStatus()) {
541
+ case 200:
542
+ return true;
543
+ break;
544
+
545
+ case 404:
546
+ default:
547
+ return false;
548
+ break;
549
+ }
550
+ }
551
+
552
+ }
app/code/community/Rede/Pay/Model/Logger.php ADDED
@@ -0,0 +1,318 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Tiago Sampaio <tiago@tiagosampaio.com>
4
+ *
5
+ * Class Rede_Pay_Model_Logger
6
+ */
7
+ class Rede_Pay_Model_Logger
8
+ {
9
+
10
+ use Rede_Pay_Trait_Data;
11
+
12
+ const LOG_FILENAME_DEFAULT = 'Rede_Pay';
13
+ const LOG_FILENAME_NOTIFICATION = 'Rede_Pay-Notification';
14
+ const LOG_FILE_EXTENSION = 'log';
15
+
16
+ protected $_fileName = null;
17
+ protected $_fileExtension = null;
18
+
19
+
20
+ /**
21
+ * @param Zend_Http_Client $client
22
+ *
23
+ * @return $this
24
+ */
25
+ public function logHeaders(Zend_Http_Client $client)
26
+ {
27
+ if (!$client) {
28
+ return $this;
29
+ }
30
+
31
+ $parameters = array(
32
+ 'access-token',
33
+ 'version',
34
+ 'Content-Type',
35
+ 'Accept'
36
+ );
37
+
38
+ foreach ($parameters as $parameter) {
39
+ $this->log($this->_helper()->__('Param: %s = %s', $parameter, $client->getHeader($parameter)));
40
+ }
41
+
42
+ return $this;
43
+ }
44
+
45
+
46
+ public function logMethod($method = null)
47
+ {
48
+ if (!$method) {
49
+ return $this;
50
+ }
51
+
52
+ $methods = array(
53
+ Zend_Http_Client::GET,
54
+ Zend_Http_Client::POST,
55
+ Zend_Http_Client::PUT,
56
+ Zend_Http_Client::HEAD,
57
+ Zend_Http_Client::DELETE,
58
+ );
59
+
60
+ if (!in_array($method, $methods)) {
61
+ return $this;
62
+ }
63
+
64
+ $this->log($this->_helper()->__('Method: %s', $method));
65
+
66
+ return $this;
67
+ }
68
+
69
+
70
+ /**
71
+ * @param int $orderId
72
+ *
73
+ * @return $this
74
+ */
75
+ public function startTransactionLog($orderId = null)
76
+ {
77
+ if (empty($orderId)) {
78
+ return $this;
79
+ }
80
+
81
+ $this->transactionLog($this->_helper()->__('Starting payment for order #%s', $orderId));
82
+ $this->log($this->_helper()->__('Magento URL: %s.', $this->_getCurrentUrl()));
83
+
84
+ return $this;
85
+ }
86
+
87
+
88
+ /**
89
+ * @param int $orderId
90
+ *
91
+ * @return $this
92
+ */
93
+ public function startConsultLog($orderId = null)
94
+ {
95
+ if (empty($orderId)) {
96
+ return $this;
97
+ }
98
+
99
+ $this->transactionLog($this->_helper()->__('Starting consult for order #%s', $orderId));
100
+ $this->log($this->_helper()->__('Magento URL: %s.', $this->_getCurrentUrl()));
101
+
102
+ return $this;
103
+ }
104
+
105
+
106
+ /**
107
+ * @param int $orderId
108
+ *
109
+ * @return $this
110
+ */
111
+ public function startShippingTrackingLog($orderId = null)
112
+ {
113
+ if (empty($orderId)) {
114
+ return $this;
115
+ }
116
+
117
+ $this->transactionLog($this->_helper()->__('Starting shipping tracking for order #%s', $orderId));
118
+ $this->log($this->_helper()->__('Magento URL: %s.', $this->_getCurrentUrl()));
119
+
120
+ return $this;
121
+ }
122
+
123
+
124
+ /**
125
+ * @param int $orderId
126
+ *
127
+ * @return $this
128
+ */
129
+ public function startRefundLog($orderId = null)
130
+ {
131
+ if (empty($orderId)) {
132
+ return $this;
133
+ }
134
+
135
+ $this->transactionLog($this->_helper()->__('Starting refund for order #%s', $orderId));
136
+ $this->log($this->_helper()->__('Magento URL: %s.', $this->_getCurrentUrl()));
137
+
138
+ return $this;
139
+ }
140
+
141
+
142
+ /**
143
+ * @param int $orderId
144
+ *
145
+ * @return $this
146
+ */
147
+ public function finishTransactionLog($orderId = null)
148
+ {
149
+ if (empty($orderId)) {
150
+ return $this;
151
+ }
152
+
153
+ $this->transactionLog($this->_helper()->__('Finishing payment for order #%s', $orderId));
154
+ $this->log(PHP_EOL);
155
+
156
+ return $this;
157
+ }
158
+
159
+
160
+ /**
161
+ * @param int $orderId
162
+ *
163
+ * @return $this
164
+ */
165
+ public function finishConsultLog($orderId = null)
166
+ {
167
+ if (empty($orderId)) {
168
+ return $this;
169
+ }
170
+
171
+ $this->transactionLog($this->_helper()->__('Finishing consult for order #%s', $orderId));
172
+ $this->log(PHP_EOL);
173
+
174
+ return $this;
175
+ }
176
+
177
+
178
+ /**
179
+ * @param int $orderId
180
+ *
181
+ * @return $this
182
+ */
183
+ public function finishShippingTrackingLog($orderId = null)
184
+ {
185
+ if (empty($orderId)) {
186
+ return $this;
187
+ }
188
+
189
+ $this->transactionLog($this->_helper()->__('Finishing shipping tracking for order #%s', $orderId));
190
+ $this->log(PHP_EOL);
191
+
192
+ return $this;
193
+ }
194
+
195
+
196
+ /**
197
+ * @param int $orderId
198
+ *
199
+ * @return $this
200
+ */
201
+ public function finishRefundLog($orderId = null)
202
+ {
203
+ if (empty($orderId)) {
204
+ return $this;
205
+ }
206
+
207
+ $this->transactionLog($this->_helper()->__('Finishing refund for order #%s', $orderId));
208
+ $this->log(PHP_EOL);
209
+
210
+ return $this;
211
+ }
212
+
213
+
214
+ /**
215
+ * @param string $message
216
+ *
217
+ * @return $this
218
+ */
219
+ public function transactionLog($message = null)
220
+ {
221
+ $message = str_pad($message, $this->getSpacerLength(), '-', STR_PAD_RIGHT);
222
+
223
+ $this->log($message);
224
+
225
+ return $this;
226
+ }
227
+
228
+
229
+ /**
230
+ * @param string $message
231
+ *
232
+ * @return $this
233
+ */
234
+ public function notificationLog($params = array())
235
+ {
236
+ $this->setFilename(self::LOG_FILENAME_NOTIFICATION);
237
+ $this->log($params);
238
+ $this->setFilename(self::LOG_FILENAME_DEFAULT);
239
+
240
+ return $this;
241
+ }
242
+
243
+
244
+ /**
245
+ * @param string|array $message
246
+ * @param bool $translate
247
+ * @param bool $force
248
+ *
249
+ * @return $this
250
+ */
251
+ public function log($message, $translate = true, $force = false)
252
+ {
253
+ if (($translate == true) && is_string($message)) {
254
+ $message = $this->_helper()->__($message);
255
+ }
256
+
257
+ Mage::log($message, null, $this->getFilename(), $force);
258
+
259
+ return $this;
260
+ }
261
+
262
+
263
+ /**
264
+ * @return string
265
+ */
266
+ public function getFilename()
267
+ {
268
+ $fileName = empty($this->_fileName) ? self::LOG_FILENAME_DEFAULT : $this->_fileName;
269
+ $extension = empty($this->_fileExtension) ? self::LOG_FILE_EXTENSION : $this->_fileExtension;
270
+
271
+ return $fileName . '.' . $extension;
272
+ }
273
+
274
+
275
+ /**
276
+ * @param string $filename
277
+ *
278
+ * @return $this
279
+ */
280
+ public function setFilename($filename = self::LOG_FILENAME_DEFAULT)
281
+ {
282
+ $this->_fileName = $filename;
283
+ return $this;
284
+ }
285
+
286
+
287
+ /**
288
+ * @param string $extension
289
+ *
290
+ * @return $this
291
+ */
292
+ public function setFileExtension($extension = self::LOG_FILE_EXTENSION)
293
+ {
294
+ $extension = str_replace('.', null, $extension);
295
+
296
+ $this->_fileExtension = $extension;
297
+ return $this;
298
+ }
299
+
300
+
301
+ /**
302
+ * @return int
303
+ */
304
+ public function getSpacerLength()
305
+ {
306
+ return 120;
307
+ }
308
+
309
+
310
+ /**
311
+ * @return string
312
+ */
313
+ protected function _getCurrentUrl()
314
+ {
315
+ return Mage::app()->getRequest()->getRequestUri();
316
+ }
317
+
318
+ }
app/code/community/Rede/Pay/Model/Method/Standard.php ADDED
@@ -0,0 +1,319 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Tiago Sampaio <tiago@tiagosampaio.com>
4
+ *
5
+ * Class Rede_Pay_Model_Method_Standard
6
+ */
7
+ class Rede_Pay_Model_Method_Standard extends Mage_Payment_Model_Method_Abstract
8
+ {
9
+
10
+ use Rede_Pay_Trait_Data;
11
+
12
+ protected $_code = 'rede_pay';
13
+ protected $_formBlockType = 'rede_pay/form_method_standard';
14
+ protected $_infoBlockType = 'rede_pay/info_method_standard';
15
+
16
+ /**
17
+ * Availability options
18
+ */
19
+ protected $_isGateway = true;
20
+ protected $_canOrder = true;
21
+ protected $_canRefund = true;
22
+ protected $_canRefundInvoicePartial = true;
23
+ protected $_canUseInternal = false;
24
+
25
+
26
+ /**
27
+ * @return string
28
+ */
29
+ public function getOrderPlaceRedirectUrl()
30
+ {
31
+ return Mage::getUrl('redepay/checkout/payment');
32
+ }
33
+
34
+
35
+ /**
36
+ * @param Varien_Object $payment
37
+ * @param float $amount
38
+ *
39
+ * @return $this
40
+ */
41
+ public function order(Varien_Object $payment, $amount)
42
+ {
43
+ parent::order($payment, $amount);
44
+
45
+ /** @var Mage_Sales_Model_Order_Payment $payment */
46
+ $order = $payment->getOrder();
47
+
48
+ /** @var Rede_Pay_Model_Processor $processor */
49
+ $processor = $this->_processor();
50
+ $processor->setOrder($order);
51
+
52
+ $validation = $this->_validateOrderParameters($processor->getOrderParams());
53
+ if ($validation !== true) {
54
+ Mage::throwException($validation);
55
+ }
56
+
57
+ $this->getApi()->request();
58
+
59
+ $body = $this->getApi()->getBody();
60
+
61
+ if ($this->getApi()->getResult()->getStatus() !== 201) {
62
+ $errors = array();
63
+
64
+ if ($this->getApi()->getResult()->getStatus() === 401) {
65
+ $errors[] = $this->_helper()->__('Fail when trying to authenticate in service.');
66
+ }
67
+
68
+ foreach ($body as $error) {
69
+ $errors[] = $this->_helper()->__($error['message']);
70
+ }
71
+
72
+ Mage::throwException(implode("\n", $errors));
73
+ }
74
+
75
+ if (!isset($body['id']) || empty($body['id'])) {
76
+ Mage::throwException($this->_helper()->__('Some error has occurred when trying to process your payment.'));
77
+ }
78
+
79
+ $paymentId = (string) $body['id'];
80
+
81
+ /** @var Rede_Pay_Model_Payments $payments */
82
+ $payments = Mage::getModel('rede_pay/payments');
83
+
84
+ $payments->setOrderId($order->getId())
85
+ ->setOrderIncrementId($order->getIncrementId())
86
+ ->setPaymentId($paymentId);
87
+
88
+ try {
89
+ $payments->save();
90
+ $this->_getSession()->setLastTransaction($payments);
91
+ $this->_getCheckoutSession()->setData('payment_id', $paymentId);
92
+ } catch (Exception $e) {
93
+ Mage::logException($e);
94
+ $this->_logger()->finishTransactionLog($order->getRealOrderId());
95
+ Mage::throwException($this->_helper()->__('Some error occurred when trying to save the payment data.'));
96
+ }
97
+
98
+ return $this;
99
+ }
100
+
101
+
102
+ /**
103
+ * Refund specified amount for payment
104
+ *
105
+ * @param Mage_Sales_Model_Order_Payment $payment
106
+ * @param float $amount
107
+ *
108
+ * @return $this
109
+ */
110
+ public function refund(Varien_Object $payment, $amount)
111
+ {
112
+ parent::refund($payment, $amount);
113
+
114
+ /** @var Mage_Sales_Model_Order_Payment $payment */
115
+ $order = $payment->getOrder();
116
+
117
+ /** @var Rede_Pay_Model_Processor $processor */
118
+ $processor = $this->_processor();
119
+ $processor->setOrder($order);
120
+
121
+ $validation = $this->_validateRefundParameters($processor->getRefundParams());
122
+ if ($validation !== true) {
123
+ Mage::throwException($validation);
124
+ }
125
+
126
+ /** @var Rede_Pay_Model_Payments $payments */
127
+ $payments = Mage::getModel('rede_pay/payments')->loadByOrderId($order->getId());
128
+ $transactionId = $payments->getTransactionId();
129
+
130
+ if (!$transactionId) {
131
+ Mage::throwException($this->_helper()->__('Transaction ID is empty for this order.'), 'adminhtml/session');
132
+ return $this;
133
+ }
134
+
135
+ /** @var Rede_Pay_Model_Api $api */
136
+ $api = Mage::getModel('rede_pay/api');
137
+ $api->refund($transactionId);
138
+
139
+ $this->_validateRefundResult($api);
140
+
141
+ if (($api->getResult()->getStatus() === 202) && Mage::app()->getStore()->isAdmin()) {
142
+ $message = $this->_helper()->__('Your order was successfully refunded.');
143
+ $this->_getAdminSession()->addSuccess($message);
144
+ }
145
+
146
+ return $this;
147
+ }
148
+
149
+
150
+ /**
151
+ * @param Rede_Pay_Model_Api $api
152
+ *
153
+ * @return $this
154
+ */
155
+ protected function _validateRefundResult(Rede_Pay_Model_Api $api)
156
+ {
157
+ /**
158
+ * If request was not authorized in Rede Pay.
159
+ */
160
+ if ($api->getResult()->getStatus() === 401) {
161
+ $message = $this->_helper()->__('This request was Unauthorized by Rede Pay.');
162
+ Mage::throwException($message);
163
+ }
164
+
165
+ /**
166
+ * If order was not found in Rede Pay.
167
+ */
168
+ if ($api->getResult()->getStatus() === 404) {
169
+ $message = $this->_helper()->__('This order was not found in Rede Pay.');
170
+ Mage::throwException($message);
171
+ }
172
+
173
+ /**
174
+ * Any other error.
175
+ */
176
+ $status = (int) $api->getResult()->getStatus();
177
+ $okCodes = array(200, 201, 202, 204);
178
+ if (!in_array($status, $okCodes) && Mage::app()->getStore()->isAdmin()) {
179
+ $message = $this->_helper()->__('Some error has occurred when trying to refund the order.');
180
+
181
+ if (is_array($api->getBody())) {
182
+ foreach ($api->getBody() as $error) {
183
+ $this->_getAdminSession()->addError($error['message']);
184
+ }
185
+ }
186
+
187
+ Mage::throwException($message);
188
+ }
189
+
190
+ return $this;
191
+ }
192
+
193
+
194
+ /**
195
+ * @param array $parameters
196
+ *
197
+ * @return array|bool
198
+ */
199
+ protected function _validateRefundParameters($parameters = array())
200
+ {
201
+ $errors = array();
202
+
203
+ /**
204
+ * Status
205
+ */
206
+ if (!isset($parameters['status']) || !($parameters['status'] == Rede_Pay_Model_Api::STATUS_REVERSED)) {
207
+ $errors[] = $this->_helper()->__('Status parameter is incorrect for refund request.');
208
+ }
209
+
210
+ if (!empty($errors)) {
211
+ $errors = implode("\n", $errors);
212
+ }
213
+
214
+ return empty($errors) ? true : $errors;
215
+ }
216
+
217
+
218
+ /**
219
+ * @param array $parameters
220
+ *
221
+ * @return array|bool
222
+ */
223
+ protected function _validateOrderParameters($parameters = array())
224
+ {
225
+ $errors = array();
226
+
227
+ /**
228
+ * Documents
229
+ */
230
+ if (!isset($parameters['customer']['documents'][0]['number'])) {
231
+ $errors[] = $this->_helper()->__('Document number is necessary to proceed with order.');
232
+ }
233
+
234
+ $document = $parameters['customer']['documents'][0]['number'];
235
+ $validator = Mage::getModel('rede_pay/validator_cpf');
236
+ if (!$validator->isValid($document)) {
237
+ $errors[] = $this->_helper()->__('CPF number is not valid.');
238
+ }
239
+
240
+ /**
241
+ * Phone numbers
242
+ */
243
+ if (!isset($parameters['customer']['phones']) && !count($parameters['customer']['phones'])) {
244
+ $errors[] = $this->_helper()->__('At least cellphone is necessary to proceed with order.');
245
+ }
246
+
247
+ /**
248
+ * Order items
249
+ */
250
+ if (!isset($parameters['items']) && !count($parameters['items'])) {
251
+ $errors[] = $this->_helper()->__('At least one product is necessary to proceed with order.');
252
+ }
253
+
254
+ if (!empty($errors)) {
255
+ $errors = implode("\n", $errors);
256
+ }
257
+
258
+ return empty($errors) ? true : $errors;
259
+ }
260
+
261
+
262
+ /**
263
+ * Do not validate payment form using server methods
264
+ *
265
+ * @return bool
266
+ */
267
+ public function validate()
268
+ {
269
+ $isValid = true;
270
+
271
+ /** @var Mage_Sales_Model_Quote_Payment | Mage_Sales_Model_Order_Payment $infoInstance */
272
+ $infoInstance = $this->getInfoInstance();
273
+
274
+ /**
275
+ * Don't need to validate quote object, only the order.
276
+ */
277
+ if ($infoInstance instanceof Mage_Sales_Model_Quote_Payment) {
278
+ return parent::validate();
279
+ }
280
+
281
+ /** @var Mage_Sales_Model_Order $order */
282
+ $order = $infoInstance->getOrder();
283
+
284
+ if (!$order || !$order->getId()) {
285
+ $isValid = false;
286
+ }
287
+
288
+ /** @var array $parameters */
289
+ $parameters = $this->_processor()->getOrderParams($order);
290
+
291
+ $validation = $this->_validateOrderParameters($parameters);
292
+ if ($validation !== true) {
293
+ Mage::throwException($validation);
294
+ }
295
+
296
+ if ($isValid == false) {
297
+ Mage::throwException($this->_helper()->__('Something went wrong in the payment process.'));
298
+ }
299
+
300
+ $this->_validated = true;
301
+
302
+ return parent::validate();
303
+ }
304
+
305
+
306
+ /**
307
+ * @param Mage_Sales_Model_Order_Payment $payment
308
+ *
309
+ * @return $this
310
+ */
311
+ protected function _cancel(Varien_Object $payment)
312
+ {
313
+ // $payment->getOrder()->cancel();
314
+ // $payment->cancel();
315
+
316
+ return $this;
317
+ }
318
+
319
+ }
app/code/community/Rede/Pay/Model/Observer.php ADDED
@@ -0,0 +1,239 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Tiago Sampaio <tiago@tiagosampaio.com>
4
+ *
5
+ * Class Rede_Pay_Model_Observer
6
+ */
7
+ class Rede_Pay_Model_Observer
8
+ {
9
+
10
+ use Rede_Pay_Trait_Data;
11
+
12
+ /**
13
+ * @param Varien_Event_Observer $observer
14
+ */
15
+ public function appendPaymentsToOrderCollection(Varien_Event_Observer $observer)
16
+ {
17
+ /** @var Mage_Sales_Model_Resource_Order_Collection $collection */
18
+ $collection = $observer->getData('order_collection');
19
+
20
+ if (!$collection) {
21
+ $collection = $observer->getData('order_grid_collection');
22
+ }
23
+
24
+ if (!$collection || !($collection instanceof Mage_Sales_Model_Resource_Order_Collection)) {
25
+ return;
26
+ }
27
+
28
+ Mage::getResourceModel('rede_pay/payments')->appendPaymentInfoToOrderCollection($collection);
29
+ }
30
+
31
+
32
+ /**
33
+ * @param Varien_Event_Observer $observer
34
+ */
35
+ public function appendPaymentsToOrder(Varien_Event_Observer $observer)
36
+ {
37
+ /** @var Mage_Sales_Model_Order $order */
38
+ $order = $observer->getData('order');
39
+
40
+ if (!$order) {
41
+ return;
42
+ }
43
+
44
+ Mage::getResourceModel('rede_pay/payments')->appendPaymentInfoToOrder($order);
45
+ }
46
+
47
+
48
+ /**
49
+ * @param Varien_Event_Observer $observer
50
+ */
51
+ public function modifySalesOrderGrid(Varien_Event_Observer $observer)
52
+ {
53
+ /** @var Mage_Adminhtml_Block_Sales_Order_Grid $block */
54
+ $block = $observer->getData('block');
55
+
56
+ if (!($block instanceof Mage_Adminhtml_Block_Sales_Order_Grid)) {
57
+ return;
58
+ }
59
+
60
+ $block->addColumnAfter('rede_payment_id', array(
61
+ 'header' => Mage::helper('rede_pay')->__('Rede Payment ID'),
62
+ 'index' => 'rede_payment_id',
63
+ 'type' => 'text',
64
+ 'filter' => false,
65
+ 'sortable' => false,
66
+ 'width' => '250px',
67
+ ), 'real_order_id');
68
+
69
+ $block->sortColumnsByOrder();
70
+ }
71
+
72
+
73
+ /**
74
+ * @param Varien_Event_Observer $observer
75
+ */
76
+ public function addOrderConsultButton(Varien_Event_Observer $observer)
77
+ {
78
+ /** @var Mage_Adminhtml_Block_Sales_Order_View $block */
79
+ $block = $observer->getData('block');
80
+
81
+ if (!($block instanceof Mage_Adminhtml_Block_Sales_Order_View)) {
82
+ return;
83
+ }
84
+
85
+ /** @var Mage_Sales_Model_Order $order */
86
+ $order = Mage::registry('current_order');
87
+
88
+ if (empty($order)) {
89
+ $orderId = Mage::app()->getRequest()->getParam('order_id');
90
+ $order = Mage::getModel('sales/order')->load($orderId);
91
+ }
92
+
93
+ $statuses = array(
94
+ $order::STATE_CANCELED,
95
+ $order::STATE_CLOSED,
96
+ $order::STATE_COMPLETE,
97
+ );
98
+
99
+ if (!$order->canCancel() && !$order->canCreditmemo() || (in_array($order->getState(), $statuses))) {
100
+ return;
101
+ }
102
+
103
+ $params = array('order_id' => $order->getId());
104
+ $url = Mage::helper('adminhtml')->getUrl('*/*/consultOrder', $params);
105
+
106
+ $block->addButton('consult_button', array(
107
+ 'label' => $this->_helper()->__('Rede Pay Consult'),
108
+ 'onclick' => 'setLocation(\'' . $url .'\')',
109
+ 'class' => 'go',
110
+ ), 0, 100);
111
+ }
112
+
113
+
114
+ /**
115
+ * If the tracking code is valid then we need to treat it before saving it to shipment.
116
+ *
117
+ * @param Varien_Event_Observer $observer
118
+ */
119
+ public function prepareShipmentTrack(Varien_Event_Observer $observer)
120
+ {
121
+ /** @var Mage_Sales_Model_Order_Shipment_Track $track */
122
+ $track = $observer->getData('track');
123
+ $number = strtoupper(trim($track->getNumber()));
124
+
125
+ /** @var Rede_Pay_Model_Validator_Shipping_Tracking $validator */
126
+ $validator = Mage::getModel('rede_pay/validator_shipping_tracking');
127
+
128
+ if (true === $validator->isValid($number)) {
129
+ $track->setNumber($number);
130
+ }
131
+
132
+ if ($track->isObjectNew()) {
133
+ $track->setData('integrate_candidate', true);
134
+ }
135
+ }
136
+
137
+
138
+ /**
139
+ * @param Varien_Event_Observer $observer
140
+ */
141
+ public function deleteShipmentTrack(Varien_Event_Observer $observer)
142
+ {
143
+ /** @var Mage_Sales_Model_Order_Shipment_Track $track */
144
+ $track = $observer->getData('track');
145
+ $number = strtoupper(trim($track->getNumber()));
146
+
147
+ /** @var Rede_Pay_Model_Validator_Shipping_Tracking $validator */
148
+ $validator = Mage::getModel('rede_pay/validator_shipping_tracking');
149
+
150
+ if (!$validator->isValid($number)) {
151
+ return;
152
+ }
153
+
154
+ /** @var Rede_Pay_Model_Payments $payment */
155
+ $payment = Mage::getModel('rede_pay/payments')->loadByOrderId($track->getOrderId());
156
+
157
+ if (!$payment->getId() || !$payment->getTransactionId()) {
158
+ return;
159
+ }
160
+
161
+ /** @var Rede_Pay_Model_Api $api */
162
+ $api = Mage::getModel('rede_pay/api');
163
+
164
+ /** This API method returns a 200 (OK) when it's ok. */
165
+ $api->consult($payment->getTransactionId(), $track->getShipment()->getOrder());
166
+ $body = $api->getBody();
167
+
168
+ if (empty($body) || empty($body['trackingNumber'])) {
169
+ return;
170
+ }
171
+
172
+ $trackingNumber = (string) trim($body['trackingNumber']);
173
+
174
+ if ($trackingNumber === $number) {
175
+ /** This API method returns a 204 (No Content) when it's ok. */
176
+ $api->deleteShippingTracking($payment->getTransactionId(), $track->getShipment()->getOrder());
177
+ }
178
+ }
179
+
180
+
181
+ /**
182
+ * If tracking number is valid then we need to integrate it with the payment gateway.
183
+ *
184
+ * @param Varien_Event_Observer $observer
185
+ */
186
+ public function processShipmentTrack(Varien_Event_Observer $observer)
187
+ {
188
+ if (Mage::registry('shipment_track_processed') === true) {
189
+ return;
190
+ }
191
+
192
+ /** @var Mage_Sales_Model_Order_Shipment_Track $track */
193
+ $track = $observer->getData('track');
194
+ $number = strtoupper(trim($track->getNumber()));
195
+
196
+ if (true !== $track->getData('integrate_candidate')) {
197
+ return;
198
+ }
199
+
200
+ /** @var Rede_Pay_Model_Validator_Shipping_Tracking $validator */
201
+ $validator = Mage::getModel('rede_pay/validator_shipping_tracking');
202
+
203
+ if (!$validator->isValid($number)) {
204
+ return;
205
+ }
206
+
207
+ /** @var Rede_Pay_Model_Payments $payment */
208
+ $payment = Mage::getModel('rede_pay/payments')->loadByOrderId($track->getOrderId());
209
+
210
+ if (!$payment->getId() || !$payment->getTransactionId()) {
211
+ return;
212
+ }
213
+
214
+ /** @var Rede_Pay_Model_Api $api */
215
+ $api = Mage::getModel('rede_pay/api');
216
+
217
+ $api->consult($payment->getTransactionId(), $track->getShipment()->getOrder());
218
+ $body = (array) $api->getBody();
219
+
220
+ if (!empty($body) && !empty($body['trackingNumber'])) {
221
+ /** This API method returns a 204 (No Content) when it's ok. */
222
+ $api->deleteShippingTracking($payment->getTransactionId(), $track->getShipment()->getOrder());
223
+ }
224
+
225
+ /** This API method returns a 201 (Created) when it's ok. */
226
+ $api->addShippingTracking($number, $payment->getTransactionId(), $track->getShipment()->getOrder());
227
+ Mage::register('shipment_track_processed', true);
228
+ }
229
+
230
+
231
+ /**
232
+ * @return Mage_Admin_Model_Session
233
+ */
234
+ protected function getAdminhtmlSession()
235
+ {
236
+ return Mage::getSingleton('admin/session');
237
+ }
238
+
239
+ }
app/code/community/Rede/Pay/Model/Params/Abstract.php ADDED
@@ -0,0 +1,205 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Tiago Sampaio <tiago@tiagosampaio.com>
4
+ *
5
+ * Class Rede_Pay_Model_Params_Abstract
6
+ */
7
+ abstract class Rede_Pay_Model_Params_Abstract
8
+ {
9
+
10
+ use Rede_Pay_Trait_Data;
11
+
12
+ const MAX_INSTALLMENTS_AMOUNT = 12;
13
+
14
+ /** @var Mage_Sales_Model_Order */
15
+ protected $_order = null;
16
+
17
+ /** @var array */
18
+ protected $_data = array();
19
+
20
+ /** @var array */
21
+ protected $_parameters = array();
22
+
23
+ /** @var string */
24
+ protected $_parametersEncoded = null;
25
+
26
+ /** @var bool */
27
+ protected $_isPrepared = false;
28
+
29
+ /** @var bool */
30
+ protected $_requireData = true;
31
+
32
+
33
+ /**
34
+ * @param Mage_Sales_Model_Order $order
35
+ *
36
+ * @return $this
37
+ */
38
+ public function setOrder(Mage_Sales_Model_Order $order)
39
+ {
40
+ if (!$order || !$order->getId()) {
41
+ return $this;
42
+ }
43
+
44
+ $this->_order = $order;
45
+
46
+ return $this;
47
+ }
48
+
49
+
50
+ /**
51
+ * @param array $data
52
+ *
53
+ * @return $this
54
+ */
55
+ public function setData(array $data = [])
56
+ {
57
+ $this->_data = $data;
58
+
59
+ return $this;
60
+ }
61
+
62
+
63
+ /**
64
+ * @param string $key
65
+ * @param string $value
66
+ *
67
+ * @return $this
68
+ */
69
+ public function addData($key, $value)
70
+ {
71
+ $this->_data[$key] = $value;
72
+
73
+ return $this;
74
+ }
75
+
76
+
77
+ /**
78
+ * @return Mage_Sales_Model_Order
79
+ */
80
+ public function getOrder()
81
+ {
82
+ return $this->_order;
83
+ }
84
+
85
+
86
+ /**
87
+ * @return $this
88
+ */
89
+ public function resetOrder()
90
+ {
91
+ $this->_order = null;
92
+ return $this;
93
+ }
94
+
95
+
96
+ /**
97
+ * @return string
98
+ *
99
+ * @throws Mage_Core_Exception
100
+ */
101
+ public function getJson(Mage_Sales_Model_Order $order = null)
102
+ {
103
+ if ($order && !$this->_isPrepared) {
104
+ $this->prepareData($order);
105
+ }
106
+
107
+ if ($this->_requireData === false) {
108
+ return $this->_parametersEncoded;
109
+ }
110
+
111
+ if (empty($this->_parameters) && empty($this->_parametersEncoded)) {
112
+ Mage::throwException($this->_helper()->__('Incorrect parameters in processor.'));
113
+ }
114
+
115
+ if (empty($this->_parametersEncoded)) {
116
+ $this->_parametersEncoded = $this->_helper()->jsonEncode($this->_parameters);
117
+ }
118
+
119
+ return $this->_parametersEncoded;
120
+ }
121
+
122
+
123
+ /**
124
+ * @param Mage_Sales_Model_Order $order
125
+ *
126
+ * @return array
127
+ *
128
+ * @throws Mage_Core_Exception
129
+ */
130
+ public function getParameters(Mage_Sales_Model_Order $order = null)
131
+ {
132
+ if ($order && !$this->_isPrepared) {
133
+ $this->prepareData($order);
134
+ }
135
+
136
+ if (empty($this->_parameters)) {
137
+ Mage::throwException($this->_helper()->__('Incorrect parameters in processor.'));
138
+ }
139
+
140
+ return $this->_parameters;
141
+ }
142
+
143
+
144
+ /**
145
+ * @return Mage_Sales_Model_Order_Address
146
+ */
147
+ public function getAddress()
148
+ {
149
+ if ($this->getOrder()->getIsVirtual()) {
150
+ return $this->getOrder()->getBillingAddress();
151
+ }
152
+
153
+ return $this->getOrder()->getShippingAddress();
154
+ }
155
+
156
+
157
+ /**
158
+ * @param Mage_Sales_Model_Order $order
159
+ *
160
+ * @return $this
161
+ *
162
+ * @throws Mage_Core_Exception
163
+ */
164
+ public function prepareData(Mage_Sales_Model_Order $order = null)
165
+ {
166
+ if ($order) {
167
+ $this->setOrder($order);
168
+ }
169
+
170
+ if (!$this->_validateOrder()) {
171
+ Mage::throwException($this->_helper()->__('Order object is not set.'));
172
+ }
173
+
174
+ $this->_prepareData();
175
+
176
+ return $this;
177
+ }
178
+
179
+
180
+ /**
181
+ * @return $this
182
+ */
183
+ abstract protected function _prepareData($force = false);
184
+
185
+
186
+ /**
187
+ * @param Mage_Sales_Model_Order $order
188
+ *
189
+ * @return bool
190
+ */
191
+ protected function _validateOrder()
192
+ {
193
+ return (bool) ($this->getOrder() && $this->getOrder()->getId());
194
+ }
195
+
196
+
197
+ /**
198
+ * @return Rede_Pay_Helper_Attributes
199
+ */
200
+ protected function _attributesHelper()
201
+ {
202
+ return Mage::helper('rede_pay/attributes');
203
+ }
204
+
205
+ }
app/code/community/Rede/Pay/Model/Params/Consult.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Tiago Sampaio <tiago@tiagosampaio.com>
4
+ *
5
+ * Class Rede_Pay_Model_Params_Consult
6
+ */
7
+ class Rede_Pay_Model_Params_Consult extends Rede_Pay_Model_Params_Abstract
8
+ {
9
+
10
+ /** @var bool */
11
+ protected $_requireData = false;
12
+
13
+ /**
14
+ * @return $this
15
+ */
16
+ protected function _prepareData($force = false)
17
+ {
18
+ return $this;
19
+ }
20
+
21
+ }
app/code/community/Rede/Pay/Model/Params/Order.php ADDED
@@ -0,0 +1,322 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Tiago Sampaio <tiago@tiagosampaio.com>
4
+ *
5
+ * Class Rede_Pay_Model_Params_Order
6
+ */
7
+ class Rede_Pay_Model_Params_Order extends Rede_Pay_Model_Params_Abstract
8
+ {
9
+
10
+ /**
11
+ * @return $this
12
+ */
13
+ protected function _prepareData($force = false)
14
+ {
15
+ if (!$this->_validateOrder()) {
16
+ return $this;
17
+ }
18
+
19
+ if ($this->_isPrepared && !$force) {
20
+ return $this;
21
+ }
22
+
23
+ $this->_prepareReference()
24
+ ->_prepareSettings()
25
+ ->_prepareCustomer()
26
+ ->_prepareShipping()
27
+ ->_prepareItems()
28
+ ->_prepareUrls();
29
+
30
+ $this->_isPrepared = true;
31
+
32
+ return $this;
33
+ }
34
+
35
+
36
+ /**
37
+ * @return $this
38
+ */
39
+ protected function _prepareReference()
40
+ {
41
+ if (!$this->_validateOrder()) {
42
+ return $this;
43
+ }
44
+
45
+ $discount = $this->getOrder()->getDiscountAmount();
46
+ $discount = abs($discount) * 100;
47
+
48
+ $this->_parameters = array(
49
+ 'reference' => $this->getOrder()->getRealOrderId(),
50
+ 'discount' => $discount,
51
+ );
52
+
53
+ return $this;
54
+ }
55
+
56
+
57
+ /**
58
+ * @return $this
59
+ */
60
+ protected function _prepareSettings()
61
+ {
62
+ if (!$this->_validateOrder()) {
63
+ return $this;
64
+ }
65
+
66
+ $this->_parameters['settings'] = array(
67
+ 'expiresAt' => $this->_getExpirationDate(),
68
+ 'attempts' => $this->_getAttempts(),
69
+ 'maxInstallments' => $this->_getInstallments(),
70
+ );
71
+
72
+ return $this;
73
+ }
74
+
75
+
76
+ /**
77
+ * @return $this
78
+ */
79
+ protected function _prepareCustomer()
80
+ {
81
+ if (!$this->_validateOrder()) {
82
+ return $this;
83
+ }
84
+
85
+ /** @var Mage_Customer_Model_Customer $customer */
86
+ $customer = Mage::getModel('customer/customer')->load($this->getOrder()->getCustomerId());
87
+
88
+ /** @var Mage_Sales_Model_Order_Address $address */
89
+ $address = $this->getAddress();
90
+
91
+ if (!$customer) {
92
+ return $this;
93
+ }
94
+
95
+ $this->_parameters['customer'] = array(
96
+ 'name' => $this->getOrder()->getCustomerName(),
97
+ 'email' => $this->getOrder()->getCustomerEmail(),
98
+ );
99
+
100
+ $taxvat = $this->_attributesHelper()->getTaxvat($customer, $address);
101
+
102
+ if (!empty($taxvat)) {
103
+ $this->_parameters['customer']['documents'][] = array(
104
+ 'kind' => 'CPF',
105
+ 'number' => $taxvat
106
+ );
107
+ }
108
+
109
+ /**
110
+ * Telephone
111
+ */
112
+ $telephone = $this->_attributesHelper()->getTelephone($address);
113
+ if (!empty($telephone)) {
114
+ $this->_parameters['customer']['phones'][] = array(
115
+ 'kind' => 'home',
116
+ 'number' => $telephone,
117
+ );
118
+ }
119
+
120
+ /**
121
+ * Cellphone
122
+ */
123
+ $cellphone = $this->_attributesHelper()->getCellphone($address);
124
+ if (!empty($cellphone)) {
125
+ $this->_parameters['customer']['phones'][] = array(
126
+ 'kind' => 'cellphone',
127
+ 'number' => $cellphone,
128
+ );
129
+ }
130
+
131
+ /**
132
+ * Business Phone (The customer requested this to be omitted)
133
+ */
134
+ // $businessPhone = $this->_attributesHelper()->getBusinessPhone($address);
135
+ // if (!empty($businessPhone)) {
136
+ // $this->_parameters['customer']['phones'][] = array(
137
+ // 'kind' => 'business',
138
+ // 'number' => $businessPhone,
139
+ // );
140
+
141
+
142
+ return $this;
143
+ }
144
+
145
+
146
+ /**
147
+ * @return $this
148
+ */
149
+ protected function _prepareShipping()
150
+ {
151
+ if (!$this->_validateOrder()) {
152
+ return $this;
153
+ }
154
+
155
+ /** @var Mage_Sales_Model_Order_Address $address */
156
+ $address = $this->getAddress();
157
+
158
+ if (!$address->getId()) {
159
+ return $this;
160
+ }
161
+
162
+ $this->_parameters['shipping']['cost'] = (int) ($this->getOrder()->getShippingAmount() * 100);
163
+
164
+ $this->_parameters['shipping']['address'] = array(
165
+ 'street' => $this->_attributesHelper()->getAddressStreet($address),
166
+ 'number' => $this->_attributesHelper()->getAddressNumber($address),
167
+ 'complement' => $this->_attributesHelper()->getAddressComplement($address),
168
+ 'district' => $this->_attributesHelper()->getAddressNeighborhood($address),
169
+ 'postalCode' => $this->_attributesHelper()->getPostcode($address),
170
+ 'city' => $address->getCity(),
171
+ 'state' => $address->getRegionCode(),
172
+ );
173
+
174
+ return $this;
175
+ }
176
+
177
+
178
+ /**
179
+ * @return $this
180
+ */
181
+ protected function _prepareItems()
182
+ {
183
+ if (!$this->_validateOrder()) {
184
+ return $this;
185
+ }
186
+
187
+ $items = array();
188
+
189
+ foreach ($this->getOrder()->getAllVisibleItems() as $item) {
190
+ /** @var Mage_Sales_Model_Order_Item $item */
191
+
192
+ // $discountAmount = (float) $item->getDiscountAmount();
193
+ // $itemTotal = (float) $item->getPriceInclTax() - ($discountAmount / $item->getQtyOrdered());
194
+
195
+ /**
196
+ * Discount here is informed as zero because it's already informed in the settings node.
197
+ * Provide it here again would cause a duplicity and the wrong calculation of discounts to order.
198
+ */
199
+ $items[] = array(
200
+ 'id' => (string) $item->getSku(),
201
+ 'description' => (string) $item->getName(),
202
+ 'amount' => (int) ($item->getPriceInclTax() * 100),
203
+ 'quantity' => (int) $item->getQtyOrdered(),
204
+ 'freight' => (int) 0,
205
+ 'discount' => (int) 0,
206
+ );
207
+ }
208
+
209
+ $this->_parameters['items'] = $items;
210
+
211
+ return $this;
212
+ }
213
+
214
+
215
+ /**
216
+ * @return $this
217
+ */
218
+ protected function _prepareUrls()
219
+ {
220
+ if (!$this->_validateOrder()) {
221
+ return $this;
222
+ }
223
+
224
+ $this->_parameters['urls'] = array(
225
+ array(
226
+ 'kind' => 'notification',
227
+ 'url' => $this->_helper()->getNotificationUrl($this->getOrder()->getId()),
228
+ ),
229
+ array(
230
+ 'kind' => 'redirect',
231
+ 'url' => $this->_helper()->getRedirectUrl($this->getOrder()->getId()),
232
+ ),
233
+ array(
234
+ 'kind' => 'cancel',
235
+ 'url' => $this->_helper()->getCancelUrl($this->getOrder()->getId()),
236
+ ),
237
+ );
238
+
239
+ return $this;
240
+ }
241
+
242
+
243
+ /**
244
+ * Returns the minimum of 72 hours ahead.
245
+ *
246
+ * @return string
247
+ */
248
+ protected function _getExpirationDate($hours = null)
249
+ {
250
+ $format = 'Y-m-d\TH:i:s\+01:00';
251
+
252
+ $hours = max($hours, 72);
253
+
254
+ /** @var Mage_Core_Model_Date $dateObj */
255
+ $dateObj = Mage::getSingleton('core/date');
256
+
257
+ $timestamp = $dateObj->timestamp();
258
+ $timestamp += (60 * 60) * $hours;
259
+
260
+ $timestamp = date($format, $timestamp);
261
+
262
+ return $timestamp;
263
+ }
264
+
265
+
266
+ /**
267
+ * @return int
268
+ */
269
+ protected function _getAttempts()
270
+ {
271
+ return 1;
272
+ }
273
+
274
+
275
+ /**
276
+ * Returns the maximum installments amount for order.
277
+ *
278
+ * @return int
279
+ */
280
+ protected function _getInstallments()
281
+ {
282
+ $grandTotal = $this->getOrder()->getGrandTotal();
283
+ $installmentsMinOrderValue = (float) max($this->_helper()->getConfigInstallmentsMinOrderValue(), 0);
284
+
285
+ if ($installmentsMinOrderValue && ($grandTotal < $installmentsMinOrderValue)) {
286
+ return (int) 1;
287
+ }
288
+
289
+ /**
290
+ * Installments amount cannot be less than one (1).
291
+ */
292
+ $installmentsAmount = max($this->_helper()->getConfigInstallmentsAmount(), 1);
293
+ $installmentsMinValue = (float) max($this->_helper()->getConfigInstallmentsMinParcelValue(), 0);
294
+
295
+ /**
296
+ * Either, installments amount cannot be greater than 12.
297
+ */
298
+ $installmentsAmount = min(self::MAX_INSTALLMENTS_AMOUNT, $installmentsAmount);
299
+
300
+ /**
301
+ * If there's no configuration for minimum value for installments we return it.
302
+ */
303
+ if (!$installmentsMinValue) {
304
+ return (int) $installmentsAmount;
305
+ }
306
+
307
+ /**
308
+ * We need to check if current parcel value is lower than the minimum required.
309
+ */
310
+ $curParcelValue = (float) ($grandTotal / $installmentsAmount);
311
+
312
+ if ($curParcelValue < $installmentsMinValue) {
313
+ /**
314
+ * If so, the installments amount is updated to the maximum allowed for this purchase.
315
+ */
316
+ $installmentsAmount = (int) ($grandTotal / $installmentsMinValue);
317
+ }
318
+
319
+ return (int) max($installmentsAmount, 1);
320
+ }
321
+
322
+ }
app/code/community/Rede/Pay/Model/Params/Refund.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Tiago Sampaio <tiago@tiagosampaio.com>
4
+ *
5
+ * Class Rede_Pay_Model_Params_Refund
6
+ */
7
+ class Rede_Pay_Model_Params_Refund extends Rede_Pay_Model_Params_Abstract
8
+ {
9
+
10
+ /**
11
+ * @return $this
12
+ */
13
+ protected function _prepareData($force = false)
14
+ {
15
+ if (!$this->_validateOrder()) {
16
+ return $this;
17
+ }
18
+
19
+ if ($this->_isPrepared && !$force) {
20
+ return $this;
21
+ }
22
+
23
+ $this->_parameters['status'] = Rede_Pay_Model_Api::STATUS_REVERSED;
24
+
25
+ $this->_isPrepared = true;
26
+
27
+ return $this;
28
+ }
29
+
30
+ }
app/code/community/Rede/Pay/Model/Params/Shipping/Tracking.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Tiago Sampaio <tiago@tiagosampaio.com>
4
+ *
5
+ * Class Rede_Pay_Model_Params_Shipping_Tracking
6
+ */
7
+ class Rede_Pay_Model_Params_Shipping_Tracking extends Rede_Pay_Model_Params_Abstract
8
+ {
9
+
10
+ /**
11
+ * @return $this
12
+ */
13
+ protected function _prepareData($force = false)
14
+ {
15
+ if (empty($this->_data['tracking_number'])) {
16
+ return $this;
17
+ }
18
+
19
+ if ($this->_isPrepared && !$force) {
20
+ return $this;
21
+ }
22
+
23
+ $this->_parameters['trackingNumber'] = $this->_data['tracking_number'];
24
+
25
+ $this->_isPrepared = true;
26
+
27
+ return $this;
28
+ }
29
+
30
+ }
app/code/community/Rede/Pay/Model/Params/Shipping/Tracking/Delete.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Tiago Sampaio <tiago@tiagosampaio.com>
4
+ *
5
+ * Class Rede_Pay_Model_Params_Shipping_Tracking_Delete
6
+ */
7
+ class Rede_Pay_Model_Params_Shipping_Tracking_Delete extends Rede_Pay_Model_Params_Abstract
8
+ {
9
+
10
+ /**
11
+ * @return $this
12
+ */
13
+ protected function _prepareData($force = false)
14
+ {
15
+ if ($this->_isPrepared && !$force) {
16
+ return $this;
17
+ }
18
+
19
+ $this->_parameters['reason'] = 'BAD_TRACKING_NUMBER';
20
+
21
+ $this->_isPrepared = true;
22
+
23
+ return $this;
24
+ }
25
+
26
+ }
app/code/community/Rede/Pay/Model/Payments.php ADDED
@@ -0,0 +1,181 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Tiago Sampaio <tiago@tiagosampaio.com>
4
+ *
5
+ * Class Rede_Pay_Model_Payments
6
+ *
7
+ * @method string getPaymentId()
8
+ * @method string getTransactionId()
9
+ * @method int getOrderId()
10
+ * @method string getOrderIncrementId()
11
+ * @method array getAdditionalInformation()
12
+ * @method array getAdditionalInformationSerialized()
13
+ * @method int getPaymentRetries()
14
+ *
15
+ * @method $this setPaymentId(string $paymentId)
16
+ * @method $this setTransactionId(string $transactionId)
17
+ * @method $this setOrderId(int $orderId)
18
+ * @method $this setOrderIncrementId(int $orderIncrementId)
19
+ * @method $this setAdditionalInformation(array $additionalInformation)
20
+ * @method $this setAdditionalInformationSerialized(array $additionalInformation)
21
+ * @method $this setPaymentRetries(int $times)
22
+ */
23
+ class Rede_Pay_Model_Payments extends Rede_Pay_Model_Abstract
24
+ {
25
+
26
+ /** @var string */
27
+ protected $_eventObject = 'payments';
28
+
29
+ /** @var string */
30
+ protected $_eventPrefix = 'rede_pay_payments';
31
+
32
+
33
+ protected function _construct()
34
+ {
35
+ $this->_init('rede_pay/payments');
36
+ parent::_construct();
37
+ }
38
+
39
+
40
+ /**
41
+ * @param int $orderId
42
+ *
43
+ * @return $this
44
+ */
45
+ public function loadByOrderId($orderId)
46
+ {
47
+ return $this->load($orderId, 'order_id');
48
+ }
49
+
50
+
51
+ /**
52
+ * @param int $incrementId
53
+ *
54
+ * @return $this
55
+ */
56
+ public function loadByOrderIncrementId($incrementId)
57
+ {
58
+ return $this->load($incrementId, 'order_increment_id');
59
+ }
60
+
61
+
62
+ /**
63
+ * @param string $transactionId
64
+ *
65
+ * @return $this
66
+ */
67
+ public function loadByTransactionId($transactionId)
68
+ {
69
+ return $this->load($transactionId, 'transaction_id');
70
+ }
71
+
72
+
73
+ /**
74
+ * @param string $paymentId
75
+ *
76
+ * @return $this
77
+ */
78
+ public function loadByPaymentId($paymentId)
79
+ {
80
+ return $this->load($paymentId, 'payment_id');
81
+ }
82
+
83
+
84
+ /**
85
+ * @return string
86
+ */
87
+ public function getStatus()
88
+ {
89
+ return $this->getData('additional_information/status');
90
+ }
91
+
92
+
93
+ /**
94
+ * @return string
95
+ */
96
+ public function getCardBrand()
97
+ {
98
+ return $this->getData('additional_information/cardBrand');
99
+ }
100
+
101
+
102
+ /**
103
+ * @return string
104
+ */
105
+ public function getPaymentMethod()
106
+ {
107
+ return $this->getData('additional_information/paymentMethod');
108
+ }
109
+
110
+
111
+ /**
112
+ * @return string
113
+ */
114
+ public function getNsu()
115
+ {
116
+ return $this->getData('additional_information/nsu');
117
+ }
118
+
119
+
120
+ /**
121
+ * @return string
122
+ */
123
+ public function getTid()
124
+ {
125
+ return $this->getData('additional_information/tId');
126
+ }
127
+
128
+
129
+ /**
130
+ * @return int
131
+ */
132
+ public function getInstallments()
133
+ {
134
+ return $this->getData('additional_information/installments');
135
+ }
136
+
137
+
138
+ /**
139
+ * @return $this
140
+ */
141
+ public function incrementRetry()
142
+ {
143
+ $times = $this->getPaymentRetries();
144
+ $times++;
145
+
146
+ $this->setPaymentRetries($times);
147
+
148
+ return $this;
149
+ }
150
+
151
+
152
+ /**
153
+ * @return $this
154
+ */
155
+ protected function _beforeSave()
156
+ {
157
+ $additionalInformation = $this->getAdditionalInformation();
158
+
159
+ if (!empty($additionalInformation) && is_array($additionalInformation)) {
160
+ $this->setAdditionalInformationSerialized(serialize($additionalInformation));
161
+ }
162
+
163
+ return parent::_beforeSave();
164
+ }
165
+
166
+
167
+ /**
168
+ * @return Mage_Core_Model_Abstract
169
+ */
170
+ protected function _afterLoad()
171
+ {
172
+ $additionalInformation = $this->getAdditionalInformationSerialized();
173
+
174
+ if (!empty($additionalInformation) && is_string($additionalInformation)) {
175
+ $this->setAdditionalInformation(unserialize($additionalInformation));
176
+ }
177
+
178
+ return parent::_afterLoad();
179
+ }
180
+
181
+ }
app/code/community/Rede/Pay/Model/Processor.php ADDED
@@ -0,0 +1,250 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Tiago Sampaio <tiago@tiagosampaio.com>
4
+ *
5
+ * Class Rede_Pay_Model_Processor
6
+ */
7
+ class Rede_Pay_Model_Processor
8
+ {
9
+
10
+ use Rede_Pay_Trait_Data;
11
+
12
+ /** @var Mage_Sales_Model_Order */
13
+ protected $_order = null;
14
+
15
+ /** @var array */
16
+ protected $_cache = [];
17
+
18
+
19
+ /**
20
+ * @param Mage_Sales_Model_Order $order
21
+ *
22
+ * @return $this
23
+ */
24
+ public function setOrder(Mage_Sales_Model_Order $order)
25
+ {
26
+ if (!$order || !$order->getId()) {
27
+ return $this;
28
+ }
29
+
30
+ $this->_order = $order;
31
+
32
+ return $this;
33
+ }
34
+
35
+
36
+ /**
37
+ * @return Mage_Sales_Model_Order
38
+ */
39
+ public function getOrder()
40
+ {
41
+ return $this->_order;
42
+ }
43
+
44
+
45
+ /**
46
+ * @return $this
47
+ */
48
+ public function resetOrder()
49
+ {
50
+ $this->_order = null;
51
+
52
+ return $this;
53
+ }
54
+
55
+
56
+ /**
57
+ * @param Mage_Sales_Model_Order $order
58
+ *
59
+ * @return array
60
+ */
61
+ public function getOrderParams(Mage_Sales_Model_Order $order = null)
62
+ {
63
+ if ($order) {
64
+ $this->setOrder($order);
65
+ }
66
+
67
+ return $this->_getParams('order');
68
+ }
69
+
70
+
71
+ /**
72
+ * @param Mage_Sales_Model_Order $order
73
+ *
74
+ * @return array
75
+ */
76
+ public function getOrderJson(Mage_Sales_Model_Order $order = null)
77
+ {
78
+ if ($order) {
79
+ $this->setOrder($order);
80
+ }
81
+
82
+ return $this->_getJson('order');
83
+ }
84
+
85
+
86
+ /**
87
+ * @param Mage_Sales_Model_Order|null $order
88
+ *
89
+ * @return string
90
+ */
91
+ public function getRefundParams(Mage_Sales_Model_Order $order = null)
92
+ {
93
+ if ($order) {
94
+ $this->setOrder($order);
95
+ }
96
+
97
+ return $this->_getParams('refund');
98
+ }
99
+
100
+
101
+ /**
102
+ * @param Mage_Sales_Model_Order|null $order
103
+ *
104
+ * @return string
105
+ */
106
+ public function getRefundJson(Mage_Sales_Model_Order $order = null)
107
+ {
108
+ if ($order) {
109
+ $this->setOrder($order);
110
+ }
111
+
112
+ return $this->_getJson('refund');
113
+ }
114
+
115
+
116
+ /**
117
+ * @param Mage_Sales_Model_Order|null $order
118
+ *
119
+ * @return string
120
+ */
121
+ public function getConsultParams(Mage_Sales_Model_Order $order = null)
122
+ {
123
+ if ($order) {
124
+ $this->setOrder($order);
125
+ }
126
+
127
+ return $this->_getParams('consult');
128
+ }
129
+
130
+
131
+ /**
132
+ * @param Mage_Sales_Model_Order|null $order
133
+ *
134
+ * @return string
135
+ */
136
+ public function getConsultJson(Mage_Sales_Model_Order $order = null)
137
+ {
138
+ if ($order) {
139
+ $this->setOrder($order);
140
+ }
141
+
142
+ return $this->_getJson('consult');
143
+ }
144
+
145
+
146
+ /**
147
+ * @param Mage_Sales_Model_Order|null $order
148
+ *
149
+ * @return string
150
+ */
151
+ public function getShippingTrackingParams($trackingNumber, Mage_Sales_Model_Order $order = null)
152
+ {
153
+ if ($order) {
154
+ $this->setOrder($order);
155
+ }
156
+
157
+ return $this->_getParams('shipping_tracking', ['tracking_number' => $trackingNumber]);
158
+ }
159
+
160
+
161
+ /**
162
+ * @param Mage_Sales_Model_Order|null $order
163
+ *
164
+ * @return string
165
+ */
166
+ public function getShippingTrackingJson($trackingNumber, Mage_Sales_Model_Order $order = null)
167
+ {
168
+ if ($order) {
169
+ $this->setOrder($order);
170
+ }
171
+
172
+ return $this->_getJson('shipping_tracking', ['tracking_number' => $trackingNumber]);
173
+ }
174
+
175
+
176
+ /**
177
+ * @param Mage_Sales_Model_Order|null $order
178
+ *
179
+ * @return string
180
+ */
181
+ public function getShippingTrackingDeleteJson(Mage_Sales_Model_Order $order = null)
182
+ {
183
+ if ($order) {
184
+ $this->setOrder($order);
185
+ }
186
+
187
+ return $this->_getJson('shipping_tracking_delete');
188
+ }
189
+
190
+
191
+ /**
192
+ * @param string $type
193
+ *
194
+ * @return array|bool|string
195
+ */
196
+ protected function _getParams($type, $data = [])
197
+ {
198
+ return $this->_getData($type, 'parameters', $data);
199
+ }
200
+
201
+
202
+ /**
203
+ * @param string $type
204
+ * @param array $data
205
+ *
206
+ * @return array|bool|string
207
+ */
208
+ protected function _getJson($type, $data = [])
209
+ {
210
+ return $this->_getData($type, 'json', $data);
211
+ }
212
+
213
+
214
+ /**
215
+ * @param string $type
216
+ *
217
+ * @param string $method
218
+ *
219
+ * @return bool|array|string
220
+ */
221
+ protected function _getData($type, $method, $data = [])
222
+ {
223
+ $cacheKey = implode('_', [$type, $method, md5(serialize($data))]);
224
+
225
+ if (!empty($this->_cache[$cacheKey])) {
226
+ return $this->_cache[$cacheKey];
227
+ }
228
+
229
+ /** @var Rede_Pay_Model_Params_Abstract $parameters */
230
+ $parameters = Mage::getSingleton('rede_pay/params_' . strtolower($type));
231
+
232
+ if (!$parameters || (!$parameters instanceof Rede_Pay_Model_Params_Abstract)) {
233
+ return false;
234
+ }
235
+
236
+ $methodName = 'get'.ucfirst($method);
237
+
238
+ if (!method_exists($parameters, $methodName)) {
239
+ return false;
240
+ }
241
+
242
+ if (!empty($data)) {
243
+ $parameters->setData($data);
244
+ }
245
+
246
+ $this->_cache[$cacheKey] = $parameters->{$methodName}($this->getOrder());
247
+ return $this->_cache[$cacheKey];
248
+ }
249
+
250
+ }
app/code/community/Rede/Pay/Model/Processor/Order.php ADDED
@@ -0,0 +1,346 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Tiago Sampaio <tiago@tiagosampaio.com>
4
+ *
5
+ * Class Rede_Pay_Model_Processor_Order
6
+ */
7
+ class Rede_Pay_Model_Processor_Order
8
+ {
9
+
10
+ use Rede_Pay_Trait_Data;
11
+
12
+ const STATUS_ERROR = 'error';
13
+
14
+ const PROCESS_TYPE_CONSULT = 'consult';
15
+ const PROCESS_TYPE_NOTIFICATION = 'notification';
16
+
17
+ const REDIRECT_SUCCESS = 'success';
18
+ const REDIRECT_ERROR = 'error';
19
+ const REDIRECT_REVERSED = 'refunded';
20
+ const REDIRECT_DENIED = 'denied';
21
+ const REDIRECT_STATE = 'state';
22
+
23
+ /**
24
+ * @param Mage_Sales_Model_Order $order
25
+ * @param array $result
26
+ *
27
+ * @return string
28
+ */
29
+ public function processOrderConsultStatus(Mage_Sales_Model_Order $order, $status = null, $result = array(),
30
+ $processType = null)
31
+ {
32
+ $paymentId = isset($result['orderId']) ? $result['orderId'] : null;
33
+ $transactionId = isset($result['transactionId']) ? $result['transactionId'] : null;
34
+
35
+ if ($result && $paymentId && $order->getId()) {
36
+ /** @var Rede_Pay_Model_Payments $payments */
37
+ $payments = Mage::getModel('rede_pay/payments')->loadByOrderId($order->getId());
38
+ $payments->setAdditionalInformation($result);
39
+
40
+ if ($transactionId) {
41
+ $payments->setTransactionId($transactionId);
42
+ }
43
+
44
+ $payments->save();
45
+ }
46
+
47
+ if (empty($processType)) {
48
+ $processType = self::PROCESS_TYPE_CONSULT;
49
+ }
50
+
51
+ if (!empty($status)) {
52
+ return $this->processOrderStatus($order, $status, $transactionId, $processType);
53
+ }
54
+
55
+ return self::REDIRECT_STATE;
56
+ }
57
+
58
+
59
+ /**
60
+ * @param Mage_Sales_Model_Order $order
61
+ * @param string $status
62
+ *
63
+ * @return string
64
+ *
65
+ * @throws Exception
66
+ */
67
+ public function processOrderStatus(Mage_Sales_Model_Order $order, $status, $transactionId = null,
68
+ $processType = null)
69
+ {
70
+ if (empty($status)) {
71
+ /** @var Mage_Sales_Model_Order_Status_History $history */
72
+ $message = $this->_helper()->__('Status sent is empty and will bot be processed.');
73
+ $history = $order->addStatusHistoryComment($message);
74
+
75
+ $history->save();
76
+
77
+ return self::REDIRECT_STATE;
78
+ }
79
+
80
+ $processLabel = $this->_getProcessTypeLabel($processType);
81
+
82
+ /** @var Mage_Sales_Model_Order_Status_History $history */
83
+ $history = $order->addStatusHistoryComment(
84
+ $this->_helper()->__('Order Status Change by %s Process from Rede Pay: %s.', $processLabel, $status)
85
+ );
86
+
87
+ $history->save();
88
+
89
+ $result = null;
90
+
91
+ /**
92
+ * If order is held.
93
+ */
94
+ if ($order->canUnhold()) {
95
+ $order->unhold();
96
+ }
97
+
98
+ try {
99
+ switch ($status) {
100
+ case Rede_Pay_Model_Api::STATUS_APPROVED:
101
+ case Rede_Pay_Model_Api::STATUS_COMPLETED:
102
+ if (!$order->canInvoice()) {
103
+ return self::REDIRECT_STATE;
104
+ }
105
+
106
+ /** @var Mage_Sales_Model_Order_Invoice $invoice */
107
+ $invoice = $this->_initInvoice($order);
108
+ $message = $this->_helper()->__('Order Invoiced By %s Process From Rede Pay.', $processLabel);
109
+
110
+ if ($invoice) {
111
+ $invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_OFFLINE)
112
+ ->setTransactionId($transactionId)
113
+ ->addComment($message)
114
+ ->register()
115
+ ->sendEmail(true);
116
+ }
117
+
118
+ $order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true, $message)
119
+ ->setIsInProcess(true);
120
+
121
+ $transactionSave = Mage::getModel('core/resource_transaction')
122
+ ->addObject($invoice)
123
+ ->addObject($order);
124
+
125
+ $transactionSave->save();
126
+
127
+ $result = self::REDIRECT_SUCCESS;
128
+
129
+ break;
130
+ case Rede_Pay_Model_Api::STATUS_REVERSED:
131
+ /**
132
+ * Let's check if payment is first in analysis but cancelled afterwards by Rede then we need
133
+ * to cancel the oder.
134
+ */
135
+ if (!$order->hasInvoices() && $order->canCancel()) {
136
+ $message = $this->_helper()->__(
137
+ 'Payment was REVERSED but no invoices was created. %s Process From Rede Pay.',
138
+ $processLabel
139
+ );
140
+
141
+ $order->getPayment()->cancel();
142
+ $order->registerCancellation($message);
143
+
144
+ Mage::dispatchEvent('order_cancel_after', array('order' => $this));
145
+
146
+ $order->save();
147
+
148
+ $result = self::REDIRECT_REVERSED;
149
+ break;
150
+ }
151
+
152
+ /**
153
+ * If order has invoices but don't allow credit memo we can do nothing.
154
+ */
155
+ if (!$order->canCreditmemo()) {
156
+ /** @var Mage_Sales_Model_Order_Status_History $history */
157
+ $history = $order->addStatusHistoryComment($this->_helper()->__(
158
+ 'Order status is %s but credit memo cannot be created.', Rede_Pay_Model_Api::STATUS_REVERSED
159
+ ));
160
+
161
+ $history->save();
162
+
163
+ $result = self::REDIRECT_REVERSED;
164
+ break;
165
+ }
166
+
167
+ /**
168
+ * If order has invoices then we can proceed with credit memo.
169
+ */
170
+ $message = $this->_helper()->__('Order Refunded By %s Process From Rede Pay.', $processLabel);
171
+
172
+ /** @var Mage_Sales_Model_Resource_Order_Invoice_Collection $invoiceCollection */
173
+ $invoiceCollection = $order->getInvoiceCollection();
174
+
175
+ /** @var Mage_Sales_Model_Service_Order $service */
176
+ $service = Mage::getModel('sales/service_order', $order);
177
+
178
+ /** @var Mage_Core_Model_Resource_Transaction $transaction */
179
+ $transaction = Mage::getModel('core/resource_transaction');
180
+
181
+ foreach ($invoiceCollection as $invoice) {
182
+ $invoice->addComment($message);
183
+
184
+ /** @var Mage_Sales_Model_Order_Creditmemo $creditmemo */
185
+ $creditmemo = $service->prepareInvoiceCreditmemo($invoice);
186
+ $creditmemo->setOfflineRequested(true);
187
+ $creditmemo->setTransactionId($invoice->getTransactionId());
188
+ $creditmemo->addComment($message);
189
+ $creditmemo->register();
190
+
191
+ foreach ($creditmemo->getAllItems() as $creditmemoItems) {
192
+ /**
193
+ * @var $creditmemoItems
194
+ * @var $orderItem
195
+ */
196
+ $orderItem = $creditmemoItems->getOrderItem();
197
+
198
+ if (!$orderItem->getParentItemId()) {
199
+ $orderItem->setBackToStock(true);
200
+ }
201
+ }
202
+
203
+ $transaction->addObject($invoice);
204
+ $transaction->addObject($creditmemo);
205
+ }
206
+
207
+ /** @var Mage_Sales_Model_Order_Status_History $history */
208
+ $history = $order->addStatusHistoryComment($message);
209
+
210
+ $transaction->addObject($history);
211
+ $transaction->addObject($order);
212
+ $transaction->save();
213
+
214
+ $result = self::REDIRECT_REVERSED;
215
+
216
+ break;
217
+
218
+ case Rede_Pay_Model_Api::STATUS_DENIED:
219
+ case Rede_Pay_Model_Api::STATUS_CANCELLED:
220
+ if (!$order->canCancel()) {
221
+ return self::REDIRECT_DENIED;
222
+ }
223
+
224
+ $message = $this->_helper()->__('Order Canceled By %s Process From Rede Pay.', $processLabel);
225
+
226
+ $order->getPayment()->cancel();
227
+ $order->registerCancellation($message);
228
+
229
+ Mage::dispatchEvent('order_cancel_after', array('order' => $this));
230
+
231
+ $order->save();
232
+
233
+ $result = self::REDIRECT_DENIED;
234
+
235
+ break;
236
+ case Rede_Pay_Model_Api::STATUS_IN_ANALYSIS:
237
+ if ($order->canHold()) {
238
+ $order->hold();
239
+ }
240
+
241
+ $message = $this->_helper()
242
+ ->__('Order Is IN ANALYSIS By %s Process From Rede Pay.', $processLabel);
243
+
244
+ $history = $order->addStatusHistoryComment($message, true);
245
+
246
+ /** @var Mage_Core_Model_Resource_Transaction $transaction */
247
+ $transaction = Mage::getModel('core/resource_transaction');
248
+ $transaction->addObject($order)
249
+ ->addObject($history)
250
+ ->save();
251
+
252
+ $result = self::REDIRECT_STATE;
253
+
254
+ break;
255
+ case Rede_Pay_Model_Api::STATUS_OPEN:
256
+ case Rede_Pay_Model_Api::STATUS_IN_DISPUTE:
257
+ case Rede_Pay_Model_Api::STATUS_CHARGEBACK:
258
+
259
+ $result = self::REDIRECT_STATE;
260
+
261
+ break;
262
+ case self::STATUS_ERROR:
263
+ default:
264
+ if (!$order->canCancel()) {
265
+ $result = self::REDIRECT_STATE;
266
+ break;
267
+ }
268
+
269
+ $message = $this->_helper()->__('Canceling order. Error when trying to process the order payment.');
270
+ $order->getPayment()->cancel();
271
+ $order->registerCancellation($message);
272
+
273
+ Mage::dispatchEvent('order_cancel_after', array('order' => $this));
274
+
275
+ $order->save();
276
+
277
+ $result = self::REDIRECT_ERROR;
278
+ break;
279
+ }
280
+ } catch (Exception $e) {
281
+ Mage::logException($e);
282
+ $result = self::REDIRECT_STATE;
283
+ }
284
+
285
+ return $result;
286
+ }
287
+
288
+
289
+ /**
290
+ * @param string $processType
291
+ *
292
+ * @return null
293
+ */
294
+ protected function _getProcessTypeLabel($processType)
295
+ {
296
+ $typeLabels = array(
297
+ self::PROCESS_TYPE_NOTIFICATION => $this->_helper()->__('Notification'),
298
+ self::PROCESS_TYPE_CONSULT => $this->_helper()->__('Consult'),
299
+ );
300
+
301
+ return isset($typeLabels[$processType]) ? $typeLabels[$processType] : null;
302
+ }
303
+
304
+
305
+ /**
306
+ * @param Mage_Sales_Model_Order $order
307
+ *
308
+ * @return bool|Mage_Sales_Model_Order_Invoice
309
+ *
310
+ * @throws Mage_Core_Exception
311
+ */
312
+ protected function _initInvoice(Mage_Sales_Model_Order $order)
313
+ {
314
+ /**
315
+ * Check order existing
316
+ */
317
+ if (!$order->getId()) {
318
+ return false;
319
+ }
320
+
321
+ /**
322
+ * Check invoice create availability
323
+ */
324
+ if (!$order->canInvoice()) {
325
+ return false;
326
+ }
327
+
328
+ $qtys = array();
329
+
330
+ foreach ($order->getAllItems() as $item) {
331
+ /** @var Mage_Sales_Model_Order_Item $item */
332
+ $qtys[$item->getId()] = $item->getQtyOrdered();
333
+ }
334
+
335
+ /** @var Mage_Sales_Model_Order_Invoice $invoice */
336
+ $invoice = $order->prepareInvoice($qtys);
337
+
338
+ if (!$invoice->getTotalQty()) {
339
+ Mage::throwException($this->_helper()->__('Cannot create an invoice without products.'));
340
+ }
341
+
342
+ Mage::register('current_invoice', $invoice);
343
+ return $invoice;
344
+ }
345
+
346
+ }
app/code/community/Rede/Pay/Model/Resource/Payments.php ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Tiago Sampaio <tiago@tiagosampaio.com>
4
+ *
5
+ * Class Rede_Pay_Model_Resource_Payments
6
+ */
7
+ class Rede_Pay_Model_Resource_Payments extends Mage_Core_Model_Resource_Db_Abstract
8
+ {
9
+
10
+ use Rede_Pay_Trait_Data;
11
+
12
+ protected function _construct()
13
+ {
14
+ $this->_init('rede_pay/payments', 'id');
15
+ }
16
+
17
+
18
+ /**
19
+ * @param Mage_Sales_Model_Resource_Order_Collection $collection
20
+ *
21
+ * @return $this
22
+ */
23
+ public function appendPaymentInfoToOrderCollection(Mage_Sales_Model_Resource_Order_Collection &$collection)
24
+ {
25
+ $collection->getSelect()
26
+ ->joinLeft(
27
+ array('payments' => $this->getMainTable()),
28
+ 'payments.order_id = main_table.entity_id',
29
+ array(
30
+ 'rede_payment_id' => 'payment_id',
31
+ 'rede_transaction_id' => 'transaction_id'
32
+ )
33
+ );
34
+
35
+ return $this;
36
+ }
37
+
38
+
39
+ /**
40
+ * @param Mage_Sales_Model_Order $order
41
+ *
42
+ * @return $this
43
+ */
44
+ public function appendPaymentInfoToOrder(Mage_Sales_Model_Order &$order)
45
+ {
46
+ if (!$order->getId()) {
47
+ return $this;
48
+ }
49
+
50
+ $bind = array(
51
+ ':order_id' => $order->getId()
52
+ );
53
+
54
+ /** @var Magento_Db_Adapter_Pdo_Mysql $read */
55
+ $read = $this->_getReadAdapter();
56
+ $select = $read->select()
57
+ ->from($this->getMainTable(), array(
58
+ 'rede_payment_id' => 'payment_id',
59
+ 'rede_transaction_id' => 'transaction_id'
60
+ ))
61
+ ->where('order_id = :order_id');
62
+
63
+ $result = $read->fetchRow($select, $bind);
64
+
65
+ if (!$result) {
66
+ return $this;
67
+ }
68
+
69
+ $order->addData($result);
70
+
71
+ return $this;
72
+ }
73
+
74
+
75
+ }
app/code/community/Rede/Pay/Model/Resource/Payments/Collection.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Tiago Sampaio <tiago@tiagosampaio.com>
4
+ *
5
+ * Class Rede_Pay_Model_Resource_Payments_Collection
6
+ */
7
+ class Rede_Pay_Model_Resource_Payments_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
8
+ {
9
+
10
+ use Rede_Pay_Trait_Data;
11
+
12
+ protected function _construct()
13
+ {
14
+ $this->_init('rede_pay/payments');
15
+ parent::_construct();
16
+ }
17
+
18
+ }
app/code/community/Rede/Pay/Model/Session.php ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Tiago Sampaio <tiago@tiagosampaio.com>
4
+ *
5
+ * Class Rede_Pay_Model_Session
6
+ */
7
+ class Rede_Pay_Model_Session extends Mage_Core_Model_Session_Abstract
8
+ {
9
+
10
+ use Rede_Pay_Trait_Data;
11
+
12
+ /**
13
+ * Class constructor. Initialize Rede Pay session namespace
14
+ */
15
+ public function __construct()
16
+ {
17
+ parent::__construct();
18
+ $this->init('rede_pay');
19
+ }
20
+
21
+
22
+ /**
23
+ * @param Rede_Pay_Model_Payments $payments
24
+ *
25
+ * @return $this
26
+ */
27
+ public function setLastTransaction(Rede_Pay_Model_Payments $payments)
28
+ {
29
+ $this->setData('last_transaction_info', $payments->getData());
30
+ return $this;
31
+ }
32
+
33
+
34
+ /**
35
+ * @return mixed
36
+ */
37
+ public function getLastTransaction()
38
+ {
39
+ return $this->getData('last_transaction_info');
40
+ }
41
+
42
+
43
+ /**
44
+ * @return null|int
45
+ */
46
+ public function getLastOrderId()
47
+ {
48
+ return $this->getData('last_transaction_info/order_id');
49
+ }
50
+
51
+
52
+ /**
53
+ * @return null|string
54
+ */
55
+ public function getLastOrderIncrementId()
56
+ {
57
+ return $this->getData('last_transaction_info/order_increment_id');
58
+ }
59
+
60
+
61
+ /**
62
+ * @return null|string
63
+ */
64
+ public function getLastPaymentId()
65
+ {
66
+ return $this->getData('last_transaction_info/payment_id');
67
+ }
68
+
69
+
70
+ /**
71
+ * @return $this
72
+ */
73
+ public function clearLastTransaction()
74
+ {
75
+ $this->unsetData('last_transaction_info');
76
+ return $this;
77
+ }
78
+
79
+ }
app/code/community/Rede/Pay/Model/System/Config/Source/Attributes/Customer.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Tiago Sampaio <tiago@tiagosampaio.com>
4
+ *
5
+ * Class Rede_Pay_Model_System_Config_Source_Attributes_Customer
6
+ */
7
+ class Rede_Pay_Model_System_Config_Source_Attributes_Customer
8
+ {
9
+
10
+ use Rede_Pay_Trait_Data;
11
+
12
+ /** @var array */
13
+ protected $_options = array();
14
+
15
+ /**
16
+ * @return array
17
+ */
18
+ public function toOptionArray()
19
+ {
20
+ if (empty($this->_options)) {
21
+
22
+ /** @var array $attributes */
23
+ $attributes = Mage::getModel('customer/customer')->getAttributes();
24
+
25
+ $this->_options[] = array(
26
+ 'value' => null,
27
+ 'label' => $this->_helper()->__('Select an Option...'),
28
+ );
29
+
30
+ foreach ($attributes as $attribute) {
31
+ /** @var Mage_Customer_Model_Attribute $attribute */
32
+
33
+ $attributeCode = $attribute->getData('attribute_code');
34
+ $attributeLabel = $attribute->getData('frontend_label');
35
+
36
+ if (empty($attributeCode) || empty($attributeLabel)) {
37
+ continue;
38
+ }
39
+
40
+ $this->_options[] = array(
41
+ 'value' => $attributeCode,
42
+ 'label' => $attributeLabel,
43
+ );
44
+ }
45
+ }
46
+
47
+ return $this->_options;
48
+ }
49
+
50
+ }
app/code/community/Rede/Pay/Model/System/Config/Source/Attributes/Customer/Address.php ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Tiago Sampaio <tiago@tiagosampaio.com>
4
+ *
5
+ * Class Rede_Pay_Model_System_Config_Source_Attributes_Customer_Address
6
+ */
7
+ class Rede_Pay_Model_System_Config_Source_Attributes_Customer_Address
8
+ {
9
+
10
+ use Rede_Pay_Trait_Data;
11
+
12
+ /** @var array */
13
+ protected $_options = array();
14
+
15
+ /**
16
+ * @return array
17
+ */
18
+ public function toOptionArray()
19
+ {
20
+ if (empty($this->_options)) {
21
+
22
+ /** @var array $attributes */
23
+ $attributes = Mage::getModel('customer/address')->getAttributes();
24
+
25
+ $this->_options[] = array(
26
+ 'value' => null,
27
+ 'label' => $this->_helper()->__('Select an Option...'),
28
+ );
29
+
30
+ for ($y = 1; $y <= 4; $y++) {
31
+ $this->_options[] = array(
32
+ 'value' => 'street_' . $y,
33
+ 'label' => $this->_helper()->__('Street Address Line %d', $y),
34
+ );
35
+ }
36
+
37
+ foreach ($attributes as $attribute) {
38
+ /** @var Mage_Customer_Model_Attribute $attribute */
39
+
40
+ $attributeCode = $attribute->getData('attribute_code');
41
+ $attributeLabel = $attribute->getData('frontend_label');
42
+
43
+ if ($attributeCode == 'street') {
44
+ continue;
45
+ }
46
+
47
+ if (empty($attributeCode) || empty($attributeLabel)) {
48
+ continue;
49
+ }
50
+
51
+ $this->_options[] = array(
52
+ 'value' => $attributeCode,
53
+ 'label' => $attributeLabel,
54
+ );
55
+ }
56
+ }
57
+
58
+ return $this->_options;
59
+ }
60
+
61
+ }
app/code/community/Rede/Pay/Model/System/Config/Source/Installments.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Tiago Sampaio <tiago@tiagosampaio.com>
4
+ *
5
+ * Class Rede_Pay_Model_System_Config_Source_Installments
6
+ */
7
+ class Rede_Pay_Model_System_Config_Source_Installments
8
+ {
9
+
10
+ use Rede_Pay_Trait_Data;
11
+
12
+ /** @var array */
13
+ protected $_options = array();
14
+
15
+ /**
16
+ * @return array
17
+ */
18
+ public function toOptionArray()
19
+ {
20
+ if (empty($this->_options)) {
21
+ for ($y = 1; $y <= 12; $y++) {
22
+ $this->_options[] = array(
23
+ 'value' => $y,
24
+ 'label' => $y,
25
+ );
26
+ }
27
+ }
28
+
29
+ return $this->_options;
30
+ }
31
+
32
+ }
app/code/community/Rede/Pay/Model/Validator/Cpf.php ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Tiago Sampaio <tiago@tiagosampaio.com>
4
+ *
5
+ * Class Rede_Pay_Model_Validator_Cpf
6
+ */
7
+ class Rede_Pay_Model_Validator_Cpf extends Zend_Validate_Abstract
8
+ {
9
+
10
+ use Rede_Pay_Trait_Data;
11
+
12
+ /**
13
+ * @param string $data
14
+ *
15
+ * @return bool
16
+ */
17
+ public function isValid($cpf)
18
+ {
19
+ if (empty($cpf)) {
20
+ return false;
21
+ }
22
+
23
+ $cpf = preg_replace('[^0-9]', null, $cpf);
24
+ $cpf = str_pad($cpf, 11, '0', STR_PAD_LEFT);
25
+
26
+ if (strlen($cpf) != 11) {
27
+ return false;
28
+ }
29
+
30
+ if (
31
+ $cpf == '00000000000' || $cpf == '11111111111' || $cpf == '22222222222' || $cpf == '33333333333' ||
32
+ $cpf == '44444444444' || $cpf == '55555555555' || $cpf == '66666666666' || $cpf == '77777777777' ||
33
+ $cpf == '88888888888' || $cpf == '99999999999'
34
+ ) {
35
+ return false;
36
+
37
+ }
38
+
39
+ for ($t = 9; $t < 11; $t++) {
40
+
41
+ for ($d = 0, $c = 0; $c < $t; $c++) {
42
+ $d += $cpf{$c} * (($t + 1) - $c);
43
+ }
44
+
45
+ $d = ((10 * $d) % 11) % 10;
46
+
47
+ if ($cpf{$c} != $d) {
48
+ return false;
49
+ }
50
+ }
51
+
52
+ return true;
53
+ }
54
+
55
+ }
app/code/community/Rede/Pay/Model/Validator/Shipping/Tracking.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Tiago Sampaio <tiago@tiagosampaio.com>
4
+ *
5
+ * Class Rede_Pay_Model_Validator_Shipping_Tracking
6
+ */
7
+ class Rede_Pay_Model_Validator_Shipping_Tracking extends Zend_Validate_Abstract
8
+ {
9
+
10
+ use Rede_Pay_Trait_Data;
11
+
12
+
13
+ /**
14
+ * Validates if the tracking number is according to Correios tracking numbers format.
15
+ *
16
+ * @param string $trackingNumber
17
+ *
18
+ * @return bool
19
+ */
20
+ public function isValid($trackingNumber)
21
+ {
22
+ if (!$trackingNumber) {
23
+ return false;
24
+ }
25
+
26
+ $result = (bool) preg_match('/^[A-Z]{2}[0-9]{9}[A-Z]{2}$/', $trackingNumber);
27
+
28
+ if (true === $result) {
29
+ return true;
30
+ }
31
+
32
+ return false;
33
+ }
34
+
35
+ }
app/code/community/Rede/Pay/Trait/Config.php ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Tiago Sampaio <tiago@tiagosampaio.com>
4
+ *
5
+ * Class Rede_Pay_Trait_Data
6
+ */
7
+ trait Rede_Pay_Trait_Config
8
+ {
9
+
10
+ /**
11
+ * @return string
12
+ */
13
+ public function getSecretApiKey()
14
+ {
15
+ return $this->_helper()->getConfigSecretApiKey();
16
+ }
17
+
18
+
19
+ /**
20
+ * @return string
21
+ */
22
+ public function getPublishableApiKey()
23
+ {
24
+ return $this->_helper()->getConfigPublishableApiKey();
25
+ }
26
+
27
+
28
+ /**
29
+ * @return string
30
+ */
31
+ public function getRedePayScriptUrl()
32
+ {
33
+ return $this->_helper()->getConfigRedePayScriptUrl();
34
+ }
35
+
36
+
37
+ /**
38
+ * @return int
39
+ */
40
+ public function getLightboxDelaySeconds()
41
+ {
42
+ return (int) $this->_helper()->getLightboxDelaySeconds();
43
+ }
44
+
45
+
46
+ /**
47
+ * @return int
48
+ */
49
+ public function getLightboxDelayMiliseconds()
50
+ {
51
+ return (int) $this->_helper()->getLightboxDelayMiliseconds();
52
+ }
53
+
54
+ }
app/code/community/Rede/Pay/Trait/Data.php ADDED
@@ -0,0 +1,154 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Tiago Sampaio <tiago@tiagosampaio.com>
4
+ *
5
+ * Class Rede_Pay_Trait_Data
6
+ */
7
+ trait Rede_Pay_Trait_Data
8
+ {
9
+
10
+ private $_moduleName = null;
11
+
12
+ /**
13
+ * @return string
14
+ */
15
+ public function __()
16
+ {
17
+ $args = func_get_args();
18
+ $expr = new Mage_Core_Model_Translate_Expr(array_shift($args), 'Rede_Pay');
19
+ array_unshift($args, $expr);
20
+ return Mage::app()->getTranslator()->translate($args);
21
+ }
22
+
23
+
24
+ /**
25
+ * @param bool $singleton
26
+ *
27
+ * @return Rede_Pay_Model_Api
28
+ */
29
+ public function getApi($singleton = true)
30
+ {
31
+ if (false === $singleton) {
32
+ return Mage::getModel('rede_pay/api');
33
+ }
34
+
35
+ return Mage::getSingleton('rede_pay/api');
36
+ }
37
+
38
+
39
+ /**
40
+ * @return Mage_Checkout_Model_Session
41
+ */
42
+ protected function _getCheckoutSession()
43
+ {
44
+ return $this->_helper()->getCheckoutSession();
45
+ }
46
+
47
+
48
+ /**
49
+ * @return Mage_Adminhtml_Model_Session
50
+ */
51
+ protected function _getAdminSession()
52
+ {
53
+ return $this->_helper()->getAdminSession();
54
+ }
55
+
56
+
57
+ /**
58
+ * @return Rede_Pay_Model_Session
59
+ */
60
+ protected function _getSession()
61
+ {
62
+ return $this->_helper()->getSession();
63
+ }
64
+
65
+
66
+ /**
67
+ * @return int
68
+ */
69
+ protected function _getLastOrderId()
70
+ {
71
+ if ($this->_getCurrentOrder() && $this->_getCurrentOrder()->getId()) {
72
+ return (int) $this->_getCurrentOrder()->getId();
73
+ }
74
+
75
+ $lastOrderId = $this->_getCheckoutSession()->getLastOrderId();
76
+ if (empty($lastOrderId)) {
77
+ $lastOrderId = $this->_getSession()->getLastOrderId();
78
+ }
79
+
80
+ return (int) $lastOrderId;
81
+ }
82
+
83
+
84
+ /**
85
+ * @return null|Mage_Sales_Model_Order
86
+ */
87
+ protected function _getCurrentOrder()
88
+ {
89
+ return Mage::registry('current_order');
90
+ }
91
+
92
+
93
+ /**
94
+ * @return Rede_Pay_Model_Logger
95
+ */
96
+ protected function _logger()
97
+ {
98
+ return $this->_helper()->getLogger();
99
+ }
100
+
101
+
102
+ /**
103
+ * @return Rede_Pay_Model_Processor
104
+ */
105
+ protected function _processor()
106
+ {
107
+ return $this->_helper()->getProcessor();
108
+ }
109
+
110
+
111
+ /**
112
+ * @param string $model
113
+ *
114
+ * @return Rede_Pay_Helper_Data
115
+ */
116
+ protected function _helper($model = null)
117
+ {
118
+ $helperName = empty($model) ? 'rede_pay' : "rede_pay/{$model}";
119
+ return Mage::helper($helperName);
120
+ }
121
+
122
+
123
+ /**
124
+ * @param array $consultBody
125
+ *
126
+ * @return null|string
127
+ */
128
+ protected function _getFilteredTransactionId(&$consultBody = array())
129
+ {
130
+ $transactionId = null;
131
+
132
+ if (!empty($consultBody['transactionHistory'])) {
133
+ foreach ((array) $consultBody['transactionHistory'] as $transaction) {
134
+ $status = strtoupper(trim($transaction['status']));
135
+
136
+ if ($this->getApi()->isStatusApproved($status)) {
137
+ $transactionId = $transaction['id'];
138
+ }
139
+
140
+ if (!$transactionId && $this->getApi()->isStatusInAnalysis($status)) {
141
+ $consultBody['status'] = Rede_Pay_Model_Api::STATUS_IN_ANALYSIS;
142
+ $transactionId = $transaction['id'];
143
+ }
144
+
145
+ if (!empty($transactionId)) {
146
+ break;
147
+ }
148
+ }
149
+ }
150
+
151
+ return $transactionId;
152
+ }
153
+
154
+ }
app/code/community/Rede/Pay/controllers/Adminhtml/Sales/OrderController.php ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Tiago Sampaio <tiago@tiagosampaio.com>
4
+ *
5
+ * Class Rede_Pay_Adminhtml_Sales_OrderController
6
+ */
7
+ class Rede_Pay_Adminhtml_Sales_OrderController extends Rede_Pay_Controller_Adminhtml_Action
8
+ {
9
+
10
+ public function consultOrderAction()
11
+ {
12
+ /** @var Mage_Sales_Model_Order $order */
13
+ $order = $this->_initOrder();
14
+
15
+ if (!$order->getId()) {
16
+ $this->_getAdminSession()->addError($this->__('Order was not found.'));
17
+ $this->_redirectReferer();
18
+ return;
19
+ }
20
+
21
+ /** @var Rede_Pay_Model_Payments $payments */
22
+ $payments = Mage::getModel('rede_pay/payments')->loadByOrderId($order->getId());
23
+
24
+ if (empty($payments->getPaymentId())) {
25
+ $this->_getAdminSession()->addError($this->__('This order was not found in Rede Pay.'));
26
+ $this->_redirectReferer();
27
+ return;
28
+ }
29
+
30
+ /** @var Rede_Pay_Model_Processor $processor */
31
+ $this->_processor()->setOrder($order);
32
+
33
+ $this->getApi()->consultOrder($payments->getPaymentId());
34
+
35
+ $body = (array) $this->getApi()->getBody();
36
+
37
+ if (!empty($body) && isset($body['status']) && $this->getApi()->isStatusAllowed($body['status'])) {
38
+ $status = $body['status'];
39
+
40
+ $transactionId = $this->_getFilteredTransactionId($body);
41
+ $body['transactionId'] = $transactionId;
42
+
43
+ $this->_helper()->processOrderConsultStatus($order, $status, $body);
44
+ $this->_getAdminSession()->addSuccess($this->__('Order was found and update successfully.'));
45
+ } elseif ($this->getApi()->getResult()->getStatus() === 404) {
46
+ $this->_getAdminSession()->addError($this->__('This order was not found in the Gateway.'));
47
+ } else {
48
+ $this->_getAdminSession()
49
+ ->addError($this->__('Some error has occurred when trying to consult this order.'));
50
+ }
51
+
52
+ $this->_redirect('*/*/view', array('order_id' => $order->getId()));
53
+ }
54
+
55
+ }
app/code/community/Rede/Pay/controllers/CheckoutController.php ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Tiago Sampaio <tiago@tiagosampaio.com>
4
+ *
5
+ * Class Rede_Pay_CheckoutController
6
+ */
7
+ class Rede_Pay_CheckoutController extends Rede_Pay_Controller_Front_Action
8
+ {
9
+
10
+ /**
11
+ * Success action.
12
+ */
13
+ public function successAction()
14
+ {
15
+ $this->_initLayout();
16
+
17
+ $orderId = $this->_initOrderId();
18
+ if (false === $orderId) {
19
+ return;
20
+ }
21
+
22
+ Mage::dispatchEvent('checkout_onepage_controller_success_action', array('order_ids' => array($orderId)));
23
+
24
+ $this->_renderLayout();
25
+ $this->_clearSessions();
26
+ }
27
+
28
+
29
+ /**
30
+ * Pending action.
31
+ */
32
+ public function pendingAction()
33
+ {
34
+ $this->_common(true);
35
+ }
36
+
37
+
38
+ /**
39
+ * Pending action.
40
+ */
41
+ public function stateAction()
42
+ {
43
+ $this->_common(true);
44
+ }
45
+
46
+
47
+ /**
48
+ * Error action.
49
+ */
50
+ public function errorAction()
51
+ {
52
+ $this->_common(true);
53
+ }
54
+
55
+
56
+ /**
57
+ * Error action.
58
+ */
59
+ public function deniedAction()
60
+ {
61
+ $this->_common(true);
62
+ }
63
+
64
+
65
+ /**
66
+ * Payment Action
67
+ */
68
+ public function paymentAction()
69
+ {
70
+ $this->_common();
71
+ }
72
+
73
+
74
+ public function retryAction()
75
+ {
76
+ if (!$this->getRequest()->isPost()) {
77
+ return;
78
+ }
79
+
80
+ if (!$this->_isCustomerLoggedIn()) {
81
+ return;
82
+ }
83
+
84
+ /** @var Mage_Sales_Model_Order $order */
85
+ $order = Mage::getModel('sales/order');
86
+ $order->load($this->getRequest()->getPost('order_id', null));
87
+
88
+ if (!$order->getId()) {
89
+ return;
90
+ }
91
+
92
+ if (($order->getCustomerId() != $this->_getCustomerId())) {
93
+ return;
94
+ }
95
+
96
+ /** @var Rede_Pay_Model_Payments $payments */
97
+ $payments = Mage::getModel('rede_pay/payments');
98
+ $payments->loadByOrderId($order->getId());
99
+
100
+ if (!$payments->getId()) {
101
+ return;
102
+ }
103
+
104
+ $payments->incrementRetry()->save();
105
+
106
+ $result = array(
107
+ 'success' => true,
108
+ 'retries' => $payments->getPaymentRetries(),
109
+ );
110
+
111
+ $this->getResponse()->setHeader('Content-type', 'application/json', true);
112
+ $this->getResponse()->setBody(Zend_Json_Encoder::encode($result));
113
+ }
114
+
115
+ }
app/code/community/Rede/Pay/controllers/NotificationController.php ADDED
@@ -0,0 +1,487 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Tiago Sampaio <tiago@tiagosampaio.com>
4
+ *
5
+ * Class Rede_Pay_NotificationController
6
+ */
7
+ class Rede_Pay_NotificationController extends Rede_Pay_Controller_Front_Action
8
+ {
9
+
10
+
11
+ /**
12
+ * Notification action.
13
+ */
14
+ public function indexAction()
15
+ {
16
+ if (!$this->_validateRequest()) {
17
+ $this->_redirect('');
18
+ return;
19
+ }
20
+
21
+ $token = $this->getRequest()->getParam('token');
22
+ $reference = $this->getRequest()->getParam('reference');
23
+ $status = $this->getRequest()->getParam('status');
24
+ $amount = $this->getRequest()->getParam('amount');
25
+ $paymentId = $this->getRequest()->getParam('orderId');
26
+
27
+ $this->_logger()->notificationLog($this->getRequest()->getParams());
28
+
29
+ if (!$paymentId || !$status || !$reference || !$token) {
30
+ $this->_redirect('');
31
+ return;
32
+ }
33
+
34
+ $this->_logger()->setFilename('Rede_Pay_Notification_Params');
35
+ $this->_logger()->startTransactionLog($reference);
36
+ $this->_logger()->log($this->getRequest()->getParams());
37
+ $this->_logger()->finishTransactionLog($reference);
38
+
39
+ $configToken = $this->_helper()->getConfigNotificationToken();
40
+ if (($token != $configToken) || !$this->getApi()->isStatusAllowed($status)) {
41
+ $this->_redirect('');
42
+ return;
43
+ }
44
+
45
+ /** @var Mage_Sales_Model_Order $order */
46
+ $order = Mage::getModel('sales/order')->loadByIncrementId(trim($reference));
47
+
48
+ if (!$reference || !$order->getId()) {
49
+ $this->_redirect('');
50
+ return;
51
+ }
52
+
53
+ /**
54
+ * Let's make sure that the Payment ID is a valid one.
55
+ *
56
+ * @var Rede_Pay_Model_Payments $payments
57
+ */
58
+ $payments = Mage::getModel('rede_pay/payments')->loadByOrderId($order->getId());
59
+
60
+ if ($paymentId !== $payments->getPaymentId()) {
61
+ $this->_redirect('');
62
+ return;
63
+ }
64
+
65
+ $this->getApi()->consultOrder($payments->getPaymentId(), $order);
66
+
67
+ $body = (array) $this->getApi()->getBody();
68
+
69
+ $transactionId = $this->_getFilteredTransactionId($body);
70
+ $body['transactionId'] = $transactionId;
71
+ $status = $body['status'];
72
+
73
+ $payments->setTransactionId($transactionId)
74
+ ->setAdditionalInformation($body)
75
+ ->save();
76
+
77
+ $processType = Rede_Pay_Model_Processor_Order::PROCESS_TYPE_NOTIFICATION;
78
+
79
+ $this->_helper()->processOrderConsultStatus($order, $status, $body, $processType);
80
+ }
81
+
82
+
83
+ /**
84
+ * Redirect action.
85
+ */
86
+ public function redirectAction()
87
+ {
88
+ if (!$this->_validateRequest()) {
89
+ $this->_redirect('*/checkout/error');
90
+ return;
91
+ }
92
+
93
+ /** @var Mage_Sales_Model_Order $order */
94
+ $order = $this->_initOrder();
95
+
96
+ if ($order === false) {
97
+ return;
98
+ }
99
+
100
+ if (!$order || !$order->getId()) {
101
+ $this->_redirect('*/checkout/error');
102
+ return;
103
+ }
104
+
105
+ /** @var Rede_Pay_Model_Payments $payments */
106
+ $payments = Mage::getModel('rede_pay/payments')->loadByOrderId($order->getId());
107
+ $paymentId = $payments->getPaymentId();
108
+
109
+ if (empty($paymentId)) {
110
+ $this->_redirectByOrder($order);
111
+ return;
112
+ }
113
+
114
+ $redirectParams = array(
115
+ 'order_id' => $order->getId(),
116
+ );
117
+
118
+ if ($order->isCanceled() || ($payments->getStatus() == Rede_Pay_Model_Api::STATUS_DENIED)) {
119
+ $this->_redirect('*/checkout/denied', $redirectParams);
120
+ return;
121
+ }
122
+
123
+ $this->getApi()->consultOrder($paymentId, $order);
124
+
125
+ $body = (array) $this->getApi()->getBody();
126
+
127
+ /**
128
+ * Checks the status in the response.
129
+ *
130
+ * 200: OK
131
+ * 201: Created
132
+ * 204: No Content
133
+ * 304: Not Modified
134
+ * 400: Bad Request
135
+ * 401: Unauthorized
136
+ * 403: Forbidden
137
+ * 404: Not Found
138
+ * 405: Method Not Allowed
139
+ * 409: Conflict
140
+ * 500: Internal Server Error
141
+ */
142
+ if ($this->getApi()->getResult()->getStatus() !== 200) {
143
+ $this->_redirectByOrder($order);
144
+ return;
145
+ }
146
+
147
+ if (!isset($body['orderId'], $body['reference'], $body['status'])) {
148
+ $this->_redirectByOrder($order);
149
+ return;
150
+ }
151
+
152
+ $reference = $body['reference'];
153
+
154
+ if ($reference != $order->getRealOrderId()) {
155
+ $this->_redirectByOrder($order);
156
+ return;
157
+ }
158
+
159
+ $transactionId = $this->_getFilteredTransactionId($body);
160
+ $body['transactionId'] = $transactionId;
161
+
162
+ /**
163
+ * Proceed to status verification.
164
+ */
165
+ $status = isset($body['status']) ? $body['status'] : null;
166
+ $redirect = $this->_helper()->processOrderConsultStatus($order, $status, $body);
167
+
168
+ if ($redirect === Rede_Pay_Model_Processor_Order::REDIRECT_SUCCESS) {
169
+ $this->_redirect('*/checkout/success', $redirectParams);
170
+ return;
171
+ }
172
+
173
+ if ($redirect === Rede_Pay_Model_Processor_Order::REDIRECT_ERROR) {
174
+ $this->_redirect('*/checkout/error', $redirectParams);
175
+ return;
176
+ }
177
+
178
+ if ($redirect === Rede_Pay_Model_Processor_Order::REDIRECT_DENIED) {
179
+ $this->_redirect('*/checkout/denied', $redirectParams);
180
+ return;
181
+ }
182
+
183
+ if ($redirect === Rede_Pay_Model_Processor_Order::REDIRECT_STATE) {
184
+ $this->_redirectByOrder($order);
185
+ return;
186
+ }
187
+
188
+ $this->_redirectByOrder($order);
189
+ }
190
+
191
+
192
+ /**
193
+ * Cancel action.
194
+ */
195
+ public function cancelAction()
196
+ {
197
+ if (!$this->_validateRequest()) {
198
+ $this->_redirect('*/checkout/error');
199
+ return;
200
+ }
201
+
202
+ /**
203
+ * This method only occurs when customer is not logged in.
204
+ */
205
+ if (!$this->_isCustomerLoggedIn()) {
206
+ $this->_redirect('customer/account/login');
207
+ return;
208
+ }
209
+
210
+ $orderId = $this->getRequest()->getParam('order_id');
211
+
212
+ if (empty($orderId)) {
213
+ $orderId = $this->_getSession()->getLastOrderId();
214
+ }
215
+
216
+ /** @var Rede_Pay_Model_Payments $payments */
217
+ $payments = Mage::getModel('rede_pay/payments')->loadByOrderId($orderId);
218
+ $paymentId = $payments->getPaymentId();
219
+
220
+ if (empty($paymentId)) {
221
+ $paymentId = $this->_getSession()->getLastPaymentId();
222
+ }
223
+
224
+ if (!$paymentId || !$orderId) {
225
+ $this->_getCheckoutSession()->addError($this->__('Incorrect transaction reference.'));
226
+ $this->_redirectCart();
227
+ return;
228
+ }
229
+
230
+ /** @var Mage_Sales_Model_Order $order */
231
+ $order = Mage::getModel('sales/order')->load($orderId);
232
+
233
+ if (!$order->getId()) {
234
+ $this->_getCheckoutSession()->addError($this->__('Order ID does not exist anymore.'));
235
+ $this->_redirectCart();
236
+ return;
237
+ }
238
+
239
+ /**
240
+ * The logged in customer needs to be the owner of the order in order to cancel it.
241
+ */
242
+ if ($order->getCustomerId() != $this->_getCustomerId()) {
243
+ $this->_getCheckoutSession()->addError($this->__('You cannot cancel this order.'));
244
+ $this->_redirectCart();
245
+ return;
246
+ }
247
+
248
+ $this->_logger()->startTransactionLog($order->getRealOrderId());
249
+
250
+ $proceedWithCancellation = true;
251
+
252
+ try {
253
+ $this->getApi()->consultOrder($paymentId, $order);
254
+ $body = (array) $this->getApi()->getBody();
255
+
256
+ $payments->setAdditionalInformation($body)->save();
257
+
258
+ /**
259
+ * When order status is OPEN on Rede Pay the customer is able to try a new payment
260
+ * so we can't cancel the order.
261
+ */
262
+ if (empty($body) || (!empty($body['status']) && $this->getApi()->isStatusOpen($body['status']))) {
263
+ $proceedWithCancellation = false;
264
+ }
265
+
266
+ /**
267
+ * If order is not canceled.
268
+ */
269
+ if ((true === $proceedWithCancellation) && $order->canCancel()) {
270
+ $order->cancel()->save();
271
+
272
+ /** @var Mage_Sales_Model_Order_Status_History $history */
273
+ $history = $order->addStatusHistoryComment($this->__('Order canceled by Rede Pay.'));
274
+ $history->save();
275
+
276
+ $message = $this->__('Order #%s is canceled.', $order->getRealOrderId());
277
+ $this->_logger()->log($message, false);
278
+ }
279
+ } catch (Exception $e) {
280
+ $this->_getCheckoutSession()->addError($this->__('Some error occurred when trying to cancel the order.'));
281
+ Mage::logException($e);
282
+ $this->_logger()->log($e->getMessage(), false);
283
+ $this->_redirectCart();
284
+ return;
285
+ }
286
+
287
+ $this->_logger()->finishTransactionLog($order->getRealOrderId());
288
+
289
+ $params = array('order_id' => $order->getId());
290
+
291
+ if ($this->getApi()->isStatusCancelled($payments->getStatus())) {
292
+ $this->_redirect('*/checkout/denied', $params);
293
+ return;
294
+ }
295
+
296
+ if (false === $proceedWithCancellation) {
297
+ $this->_redirect('*/checkout/state', $params);
298
+ return;
299
+ }
300
+
301
+ $this->_redirect('*/checkout/error', $params);
302
+ }
303
+
304
+
305
+ /**
306
+ * Add Tracking from Rede Pay
307
+ */
308
+ public function addTrackingAction()
309
+ {
310
+ if (!$this->_validateRequest()) {
311
+ $this->_redirect('*/checkout/error');
312
+ return;
313
+ }
314
+
315
+ $transactionId = $this->getRequest()->getParam('transactionId');
316
+ $paymentId = $this->getRequest()->getParam('orderId');
317
+ $orderId = $this->getRequest()->getParam('reference');
318
+ $trackingNumber = $this->getRequest()->getParam('trackingNumber');
319
+
320
+ if (!$transactionId || !$paymentId || !$orderId || !$trackingNumber) {
321
+ return;
322
+ }
323
+
324
+ /** @var Rede_Pay_Model_Validator_Shipping_Tracking $validator */
325
+ $validator = Mage::getModel('rede_pay/validator_shipping_tracking');
326
+
327
+ if (!$validator->isValid($trackingNumber)) {
328
+ return;
329
+ }
330
+
331
+ /** @var Mage_Sales_Model_Order $order */
332
+ $order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
333
+
334
+ if (!$order->getId()) {
335
+ return;
336
+ }
337
+
338
+ /** @var Rede_Pay_Model_Payments $payment */
339
+ $payment = Mage::getModel('rede_pay/payments')->loadByOrderId($order->getId());
340
+
341
+ if ($payment->getPaymentId() != $paymentId) {
342
+ return;
343
+ }
344
+
345
+ $payment->setTransactionId($transactionId)->save();
346
+
347
+ /**
348
+ * @var Mage_Sales_Model_Resource_Order_Shipment_Collection $shipments
349
+ * @var Mage_Sales_Model_Order_Shipment $shipment
350
+ */
351
+ $shipments = $order->getShipmentsCollection();
352
+ $shipment = null;
353
+
354
+ if ($shipments->getSize()) {
355
+ $shipment = $shipments->getFirstItem();
356
+
357
+ $message = $this->__(
358
+ 'Tracking number %s added to order shipment by Rede Pay notification process.', $trackingNumber
359
+ );
360
+ } else {
361
+ if (!$order->canShip()) {
362
+ /** Order cannot be shipped. */
363
+ return;
364
+ }
365
+
366
+ $shipment = Mage::getModel('sales/service_order', $order)->prepareShipment();
367
+ $shipment->register();
368
+
369
+ $message = $this->__(
370
+ 'Order shipment created by Rede Pay notification process with tracking number %s.', $trackingNumber
371
+ );
372
+ }
373
+
374
+ if (!($shipment instanceof Mage_Sales_Model_Order_Shipment)) {
375
+ return;
376
+ }
377
+
378
+ /** @var Mage_Sales_Model_Order_Shipment_Track $shipmentTracks */
379
+ foreach ($shipment->getAllTracks() as $shipmentTracks) {
380
+ /**
381
+ * If tracking already exists, there's nothing to do.
382
+ */
383
+ if ($shipmentTracks->getNumber() == $trackingNumber) {
384
+ return;
385
+ }
386
+ }
387
+
388
+ /** @var Mage_Sales_Model_Order_Shipment_Track $track */
389
+ $track = Mage::getModel('sales/order_shipment_track')->setTitle('Correios')
390
+ ->setCarrierCode('custom')
391
+ ->setNumber($trackingNumber);
392
+
393
+ $order->setIsInProcess(true);
394
+ $shipment->addTrack($track)->addComment($message);
395
+
396
+ /** @var Mage_Sales_Model_Order_Status_History $history */
397
+ $history = $order->addStatusHistoryComment($message, true);
398
+
399
+ $this->getTransaction()
400
+ ->addObject($order)
401
+ ->addObject($shipment)
402
+ ->addObject($history)
403
+ ->save();
404
+ }
405
+
406
+
407
+ /**
408
+ * Remove Tracking from Rede Pay
409
+ */
410
+ public function removeTrackingAction()
411
+ {
412
+ if (!$this->_validateRequest()) {
413
+ $this->_redirect('*/checkout/error');
414
+ return;
415
+ }
416
+
417
+ $transactionId = $this->getRequest()->getParam('transactionId');
418
+ $paymentId = $this->getRequest()->getParam('orderId');
419
+ $orderId = $this->getRequest()->getParam('reference');
420
+ $trackingNumber = $this->getRequest()->getParam('trackingNumber');
421
+
422
+ if (!$transactionId || !$paymentId || !$orderId || !$trackingNumber) {
423
+ return;
424
+ }
425
+
426
+ /** @var Rede_Pay_Model_Validator_Shipping_Tracking $validator */
427
+ $validator = Mage::getModel('rede_pay/validator_shipping_tracking');
428
+
429
+ if (!$validator->isValid($trackingNumber)) {
430
+ return;
431
+ }
432
+
433
+ /** @var Mage_Sales_Model_Order $order */
434
+ $order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
435
+
436
+ if (!$order->getId()) {
437
+ return;
438
+ }
439
+
440
+ /** @var Rede_Pay_Model_Payments $payment */
441
+ $payment = Mage::getModel('rede_pay/payments')->loadByOrderId($order->getId());
442
+
443
+ if ($payment->getPaymentId() != $paymentId) {
444
+ return;
445
+ }
446
+
447
+ $payment->setTransactionId($transactionId)->save();
448
+
449
+ /** @var Mage_Sales_Model_Resource_Order_Shipment_Collection $shipments */
450
+ $shipments = $order->getShipmentsCollection();
451
+
452
+ /** @var Mage_Sales_Model_Order_Shipment $shipment */
453
+ foreach ($shipments as $shipment) {
454
+ /** @var Mage_Sales_Model_Order_Shipment_Track $shipmentTracks */
455
+ foreach ($shipment->getAllTracks() as $shipmentTracks) {
456
+ /**
457
+ * If tracking already exists, there's nothing to do.
458
+ */
459
+ if ($shipmentTracks->getNumber() == $trackingNumber) {
460
+ $shipmentTracks->delete();
461
+
462
+ $message = $this->__(
463
+ 'Tracking number %s removed by Rede Pay notification process.', $trackingNumber
464
+ );
465
+
466
+ $shipment->addComment($message);
467
+ $history = $order->addStatusHistoryComment($message, true);
468
+
469
+ $this->getTransaction()
470
+ ->addObject($shipment)
471
+ ->addObject($history)
472
+ ->save();
473
+ }
474
+ }
475
+ }
476
+ }
477
+
478
+
479
+ /**
480
+ * @return Mage_Core_Model_Resource_Transaction
481
+ */
482
+ protected function getTransaction()
483
+ {
484
+ return Mage::getResourceModel('core/transaction');
485
+ }
486
+
487
+ }
app/code/community/Rede/Pay/data/rede_pay_setup/data-install-1.0.0.0.php ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Tiago Sampaio <tiago@tiagosampaio.com>
4
+ *
5
+ * @var Mage_Core_Model_Resource_Setup $this
6
+ */
7
+ $installer = $this;
8
+
9
+ $regions = array(
10
+ array('BR', 'AC', 'Acre'),
11
+ array('BR', 'AL', 'Alagoas'),
12
+ array('BR', 'AP', 'Amapá'),
13
+ array('BR', 'AM', 'Amazonas'),
14
+ array('BR', 'BA', 'Bahia'),
15
+ array('BR', 'CE', 'Ceará'),
16
+ array('BR', 'DF', 'Distrito Federal'),
17
+ array('BR', 'ES', 'Espírito Santo'),
18
+ array('BR', 'GO', 'Goiás'),
19
+ array('BR', 'MA', 'Maranhão'),
20
+ array('BR', 'MT', 'Mato Grosso'),
21
+ array('BR', 'MS', 'Mato Grosso do Sul'),
22
+ array('BR', 'MG', 'Minas Gerais'),
23
+ array('BR', 'PA', 'Pará'),
24
+ array('BR', 'PB', 'Paraíba'),
25
+ array('BR', 'PR', 'Paraná'),
26
+ array('BR', 'PE', 'Pernambuco'),
27
+ array('BR', 'PI', 'Piauí'),
28
+ array('BR', 'RJ', 'Rio de Janeiro'),
29
+ array('BR', 'RN', 'Rio Grande do Norte'),
30
+ array('BR', 'RS', 'Rio Grande do Sul'),
31
+ array('BR', 'RO', 'Rondônia'),
32
+ array('BR', 'RR', 'Roraima'),
33
+ array('BR', 'SC', 'Santa Catarina'),
34
+ array('BR', 'SP', 'São Paulo'),
35
+ array('BR', 'SE', 'Sergipe'),
36
+ array('BR', 'TO', 'Tocantins'),
37
+ );
38
+
39
+ foreach ($regions as $row) {
40
+ $bind = array(
41
+ 'country_id' => $row[0],
42
+ 'code' => $row[1],
43
+ 'default_name' => $row[2],
44
+ );
45
+
46
+ /** @var Varien_Db_Select $select */
47
+ $select = $installer->getConnection()
48
+ ->select()
49
+ ->from($installer->getTable('directory/country_region'), 'region_id')
50
+ ->where("country_id = '{$row[0]}' AND code = '{$row[1]}'");
51
+ $result = $installer->getConnection()->fetchOne($select);
52
+
53
+ if (!empty($result)) {
54
+ continue;
55
+ }
56
+
57
+ $installer->getConnection()->insert($installer->getTable('directory/country_region'), $bind);
58
+ $regionId = $installer->getConnection()->lastInsertId($installer->getTable('directory/country_region'));
59
+
60
+ $bind = array(
61
+ 'locale' => 'pt_BR',
62
+ 'region_id' => $regionId,
63
+ 'name' => $row[2]
64
+ );
65
+
66
+ $installer->getConnection()->insert($installer->getTable('directory/country_region_name'), $bind);
67
+ }
app/code/community/Rede/Pay/data/rede_pay_setup/data-upgrade-1.0.1.0-1.0.1.1.php ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * To avoid problems with older orders we update the method in database from 'rede_clickpag' to 'rede_pay'.
4
+ *
5
+ * @author Tiago Sampaio <tiago@tiagosampaio.com>
6
+ *
7
+ * @var Mage_Core_Model_Resource_Setup $this
8
+ * @var Magento_Db_Adapter_Pdo_Mysql $connection
9
+ */
10
+ $installer = $this;
11
+ $connection = $installer->getConnection();
12
+
13
+ $bind = ['method' => 'rede_pay'];
14
+ $where = new Zend_Db_Expr("method = 'rede_clickpag'");
15
+
16
+ $connection->update($installer->getTable('sales/order_payment'), $bind, $where);
17
+
18
+ /**
19
+ * Now it's necessary to transfer all the data between the old and the new table.
20
+ */
21
+ $oldTable = $installer->getTable('rede_pay/payments_deprecated');
22
+ $newTable = $installer->getTable('rede_pay/payments');
23
+
24
+ /** If the table does not exits then we do not need to proceed with this operation */
25
+ if (!$connection->isTableExists($oldTable)) {
26
+ return;
27
+ }
28
+
29
+ /** @var Varien_Db_Select $select */
30
+ $fields = ['order_id', 'order_increment_id', 'payment_id', 'transaction_id', 'additional_information_serialized'];
31
+ $select = $connection->select()->from($oldTable, $fields);
32
+ $payments = $connection->fetchAll($select);
33
+
34
+ $amount = 100;
35
+ $size = ceil(count($payments) / $amount);
36
+
37
+ for ($y = 1; $y <= $size; $y++) {
38
+ try {
39
+ $rows = array_splice($payments, 0, $amount);
40
+ $connection->insertMultiple($newTable, $rows);
41
+ } catch (Exception $e) {
42
+ Mage::logException($e);
43
+ processSeparated($rows, $newTable, $connection);
44
+ }
45
+ }
46
+
47
+
48
+ /**
49
+ * In case of failure in the group insertion above we try to insert each one.
50
+ *
51
+ * @param array $rows
52
+ * @param string $table
53
+ * @param Magento_Db_Adapter_Pdo_Mysql $connection
54
+ *
55
+ * @throws Zend_Db_Adapter_Exception
56
+ */
57
+ function processSeparated($rows, $table, Magento_Db_Adapter_Pdo_Mysql $connection) {
58
+ foreach ($rows as $row) {
59
+ $connection->insertIgnore($table, $row);
60
+ }
61
+ }
app/code/community/Rede/Pay/etc/adminhtml.xml ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * @author Tiago Sampaio <tiago@tiagosampaio.com>
5
+ */
6
+ -->
7
+ <config>
8
+ <menu>
9
+ <rede_pay translate="title" module="rede_pay">
10
+ <title>Rede Pay</title>
11
+ <sort_order>90</sort_order>
12
+ <depends>
13
+ <module>Rede_Pay</module>
14
+ </depends>
15
+ <children>
16
+ <configuration translate="title">
17
+ <title>Configuration</title>
18
+ <sort_order>90</sort_order>
19
+ <action>adminhtml/system_config/edit/section/payment</action>
20
+ </configuration>
21
+ </children>
22
+ </rede_pay>
23
+ </menu>
24
+ </config>
app/code/community/Rede/Pay/etc/config.xml ADDED
@@ -0,0 +1,212 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * @author Tiago Sampaio <tiago@tiagosampaio.com>
5
+ */
6
+ -->
7
+ <config>
8
+ <modules>
9
+ <Rede_Pay>
10
+ <version>1.0.2.2</version>
11
+ </Rede_Pay>
12
+ </modules>
13
+ <global>
14
+ <models>
15
+ <rede_pay>
16
+ <class>Rede_Pay_Model</class>
17
+ <resourceModel>rede_pay_resource</resourceModel>
18
+ </rede_pay>
19
+ <rede_pay_resource>
20
+ <class>Rede_Pay_Model_Resource</class>
21
+ <entities>
22
+ <payments_deprecated>
23
+ <table>rede_clickpag_payments</table>
24
+ </payments_deprecated>
25
+ <payments>
26
+ <table>rede_pay_payments</table>
27
+ </payments>
28
+ </entities>
29
+ </rede_pay_resource>
30
+ </models>
31
+ <resources>
32
+ <rede_pay_setup>
33
+ <setup>
34
+ <module>Rede_Pay</module>
35
+ <class>Mage_Core_Model_Resource_Setup</class>
36
+ </setup>
37
+ </rede_pay_setup>
38
+ </resources>
39
+ <blocks>
40
+ <rede_pay>
41
+ <class>Rede_Pay_Block</class>
42
+ </rede_pay>
43
+ </blocks>
44
+ <helpers>
45
+ <rede_pay>
46
+ <class>Rede_Pay_Helper</class>
47
+ </rede_pay>
48
+ </helpers>
49
+ <events>
50
+ <sales_order_collection_load_before>
51
+ <observers>
52
+ <rede_pay_append_payments_to_order_collection>
53
+ <class>rede_pay/observer</class>
54
+ <method>appendPaymentsToOrderCollection</method>
55
+ </rede_pay_append_payments_to_order_collection>
56
+ </observers>
57
+ </sales_order_collection_load_before>
58
+ <sales_order_grid_collection_load_before>
59
+ <observers>
60
+ <rede_pay_append_payments_to_order_collection>
61
+ <class>rede_pay/observer</class>
62
+ <method>appendPaymentsToOrderCollection</method>
63
+ </rede_pay_append_payments_to_order_collection>
64
+ </observers>
65
+ </sales_order_grid_collection_load_before>
66
+ <sales_order_load_after>
67
+ <observers>
68
+ <rede_pay_append_payments_to_order>
69
+ <class>rede_pay/observer</class>
70
+ <method>appendPaymentsToOrder</method>
71
+ </rede_pay_append_payments_to_order>
72
+ </observers>
73
+ </sales_order_load_after>
74
+ <adminhtml_block_html_before>
75
+ <observers>
76
+ <rede_pay_modify_sales_order_grid>
77
+ <class>rede_pay/observer</class>
78
+ <method>modifySalesOrderGrid</method>
79
+ </rede_pay_modify_sales_order_grid>
80
+ </observers>
81
+ </adminhtml_block_html_before>
82
+ </events>
83
+ </global>
84
+ <frontend>
85
+ <routers>
86
+ <rede_pay>
87
+ <use>standard</use>
88
+ <args>
89
+ <module>Rede_Pay</module>
90
+ <frontName>redepay</frontName>
91
+ </args>
92
+ </rede_pay>
93
+ </routers>
94
+ <layout>
95
+ <updates>
96
+ <rede_pay>
97
+ <file>rede/pay.xml</file>
98
+ </rede_pay>
99
+ </updates>
100
+ </layout>
101
+ <translate>
102
+ <modules>
103
+ <rede_pay>
104
+ <files>
105
+ <default>Rede/Pay.csv</default>
106
+ </files>
107
+ </rede_pay>
108
+ </modules>
109
+ </translate>
110
+ </frontend>
111
+ <adminhtml>
112
+ <layout>
113
+ <updates>
114
+ <rede_pay>
115
+ <file>rede/pay.xml</file>
116
+ </rede_pay>
117
+ </updates>
118
+ </layout>
119
+ <translate>
120
+ <modules>
121
+ <rede_pay>
122
+ <files>
123
+ <default>Rede/Pay.csv</default>
124
+ </files>
125
+ </rede_pay>
126
+ </modules>
127
+ </translate>
128
+ <events>
129
+ <adminhtml_widget_container_html_before>
130
+ <observers>
131
+ <rede_pay_add_order_consult_button>
132
+ <class>rede_pay/observer</class>
133
+ <method>addOrderConsultButton</method>
134
+ </rede_pay_add_order_consult_button>
135
+ </observers>
136
+ </adminhtml_widget_container_html_before>
137
+ <sales_order_shipment_track_save_before>
138
+ <observers>
139
+ <rede_pay_prepare_shipment_tracking>
140
+ <class>rede_pay/observer</class>
141
+ <method>prepareShipmentTrack</method>
142
+ </rede_pay_prepare_shipment_tracking>
143
+ </observers>
144
+ </sales_order_shipment_track_save_before>
145
+ <sales_order_shipment_track_save_after>
146
+ <observers>
147
+ <rede_pay_process_shipment_tracking>
148
+ <class>rede_pay/observer</class>
149
+ <method>processShipmentTrack</method>
150
+ </rede_pay_process_shipment_tracking>
151
+ </observers>
152
+ </sales_order_shipment_track_save_after>
153
+ <sales_order_shipment_track_delete_after>
154
+ <observers>
155
+ <rede_pay_delete_shipment_tracking>
156
+ <class>rede_pay/observer</class>
157
+ <method>deleteShipmentTrack</method>
158
+ </rede_pay_delete_shipment_tracking>
159
+ </observers>
160
+ </sales_order_shipment_track_delete_after>
161
+ </events>
162
+ </adminhtml>
163
+ <admin>
164
+ <routers>
165
+ <adminhtml>
166
+ <args>
167
+ <modules>
168
+ <rede_pay before="Mage_Adminhtml">Rede_Pay_Adminhtml</rede_pay>
169
+ </modules>
170
+ </args>
171
+ </adminhtml>
172
+ </routers>
173
+ </admin>
174
+ <default>
175
+ <payment>
176
+ <rede_pay>
177
+ <active>1</active>
178
+ <title>Rede Pay</title>
179
+ <debug>0</debug>
180
+ <model>rede_pay/method_standard</model>
181
+ <order_status>pending</order_status>
182
+ <approved_order_status>processing</approved_order_status>
183
+ <payment_action>order</payment_action>
184
+ <test>1</test>
185
+ <api_order_url>https://api.useredepay.com.br/orders</api_order_url>
186
+ <api_consult_order_url>https://api.useredepay.com.br/orders</api_consult_order_url>
187
+ <api_consult_url>https://api.useredepay.com.br/transactions</api_consult_url>
188
+ <api_refund_url>https://api.useredepay.com.br/transactions</api_refund_url>
189
+ <api_shipping_tracking_url>https://api.useredepay.com.br/transactions</api_shipping_tracking_url>
190
+ <redepay_script_url>https://checkout.useredepay.com.br/checkout.js</redepay_script_url>
191
+ <text_message>Você prosseguirá com o pagamento logo após a conclusão do pedido.</text_message>
192
+ <allowspecific>0</allowspecific>
193
+ <currency>BRL</currency>
194
+ <sort_order>0</sort_order>
195
+ <installments_amount>6</installments_amount>
196
+ <installments_min_order_value>200.00</installments_min_order_value>
197
+ <installments_min_parcel_value>20.00</installments_min_parcel_value>
198
+ <lightbox_delay_time>1</lightbox_delay_time>
199
+ <attributes_taxvat>taxvat</attributes_taxvat>
200
+ <attributes_street>street_1</attributes_street>
201
+ <attributes_number>street_2</attributes_number>
202
+ <attributes_complement>street_3</attributes_complement>
203
+ <attributes_neighborhood>street_4</attributes_neighborhood>
204
+ <attributes_telephone>telephone</attributes_telephone>
205
+ <attributes_cellphone>fax</attributes_cellphone>
206
+ <attributes_business_phone>fax</attributes_business_phone>
207
+ <!--<payment_retries_enabled>1</payment_retries_enabled>-->
208
+ <!--<max_payment_retries>5</max_payment_retries>-->
209
+ </rede_pay>
210
+ </payment>
211
+ </default>
212
+ </config>
app/code/community/Rede/Pay/etc/system.xml ADDED
@@ -0,0 +1,403 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * @author Tiago Sampaio <tiago@tiagosampaio.com>
5
+ */
6
+ -->
7
+ <config>
8
+ <sections>
9
+ <payment>
10
+ <groups>
11
+ <rede_pay translate="label comment" module="rede_pay">
12
+ <label>Rede Pay</label>
13
+ <frontend_type>text</frontend_type>
14
+ <sort_order>100</sort_order>
15
+ <show_in_default>1</show_in_default>
16
+ <show_in_website>1</show_in_website>
17
+ <show_in_store>1</show_in_store>
18
+ <frontend_class>redepay complex</frontend_class>
19
+ <frontend_model>rede_pay/adminhtml_system_config_fieldset_group</frontend_model>
20
+ <register_url><![CDATA[https://portal.useredepay.com.br/credenciamento/#/]]></register_url>
21
+ <comment><![CDATA[Register with us now to get all the advantages.]]></comment>
22
+ <fields>
23
+ <active translate="label">
24
+ <label>Enabled</label>
25
+ <frontend_type>select</frontend_type>
26
+ <source_model>adminhtml/system_config_source_yesno</source_model>
27
+ <sort_order>10</sort_order>
28
+ <show_in_default>1</show_in_default>
29
+ <show_in_website>1</show_in_website>
30
+ <show_in_store>0</show_in_store>
31
+ </active>
32
+ <title translate="label">
33
+ <label>Title</label>
34
+ <frontend_type>label</frontend_type>
35
+ <sort_order>20</sort_order>
36
+ <show_in_default>1</show_in_default>
37
+ <show_in_website>1</show_in_website>
38
+ <show_in_store>1</show_in_store>
39
+ </title>
40
+ <text_message translate="label comment">
41
+ <label>Text Message</label>
42
+ <frontend_type>textarea</frontend_type>
43
+ <sort_order>30</sort_order>
44
+ <show_in_default>1</show_in_default>
45
+ <show_in_website>1</show_in_website>
46
+ <show_in_store>0</show_in_store>
47
+ <comment>This text will appear to customer on the payment section in checkout page.</comment>
48
+ </text_message>
49
+ <order_status translate="label comment">
50
+ <label>New Order Status</label>
51
+ <frontend_type>select</frontend_type>
52
+ <source_model>adminhtml/system_config_source_order_status_new</source_model>
53
+ <sort_order>100</sort_order>
54
+ <show_in_default>1</show_in_default>
55
+ <show_in_website>1</show_in_website>
56
+ <show_in_store>0</show_in_store>
57
+ <comment>The order status to new orders.</comment>
58
+ </order_status>
59
+ <approved_order_status translate="label comment">
60
+ <label>Approved Order Status</label>
61
+ <frontend_type>select</frontend_type>
62
+ <source_model>adminhtml/system_config_source_order_status_processing</source_model>
63
+ <sort_order>105</sort_order>
64
+ <show_in_default>1</show_in_default>
65
+ <show_in_website>1</show_in_website>
66
+ <show_in_store>0</show_in_store>
67
+ <comment>The order status when the order is approved by Payment Gateway.</comment>
68
+ </approved_order_status>
69
+ <debug translate="label comment">
70
+ <label>Debug</label>
71
+ <frontend_type>select</frontend_type>
72
+ <source_model>adminhtml/system_config_source_yesno</source_model>
73
+ <sort_order>120</sort_order>
74
+ <show_in_default>1</show_in_default>
75
+ <show_in_website>1</show_in_website>
76
+ <show_in_store>0</show_in_store>
77
+ <comment>Enables the debug mode for this payment method.</comment>
78
+ </debug>
79
+ <installments_amount translate="label comment">
80
+ <label>Installments Amount</label>
81
+ <frontend_type>select</frontend_type>
82
+ <source_model>rede_pay/system_config_source_installments</source_model>
83
+ <sort_order>130</sort_order>
84
+ <show_in_default>1</show_in_default>
85
+ <show_in_website>1</show_in_website>
86
+ <show_in_store>0</show_in_store>
87
+ <frontend_class>validate-number</frontend_class>
88
+ <validate>validate-number</validate>
89
+ <comment>Max quantity of installments that will be available to customers.</comment>
90
+ </installments_amount>
91
+ <installments_min_order_value translate="label comment">
92
+ <label>Installments Order Minimum Value</label>
93
+ <frontend_type>text</frontend_type>
94
+ <sort_order>135</sort_order>
95
+ <show_in_default>1</show_in_default>
96
+ <show_in_website>1</show_in_website>
97
+ <show_in_store>0</show_in_store>
98
+ <validate>validate-number required-entry</validate>
99
+ <comment>Defines the minimum value of the order to enable the installments.</comment>
100
+ </installments_min_order_value>
101
+ <installments_min_parcel_value translate="label comment">
102
+ <label>Installments Parcel Minimum Value</label>
103
+ <frontend_type>text</frontend_type>
104
+ <sort_order>140</sort_order>
105
+ <show_in_default>1</show_in_default>
106
+ <show_in_website>1</show_in_website>
107
+ <show_in_store>0</show_in_store>
108
+ <validate>validate-number required-entry</validate>
109
+ <comment>Defines the minimum value of each parcel according to the value inserted. The maximum quantity of parcels will be calculated automatically.</comment>
110
+ </installments_min_parcel_value>
111
+ <!--
112
+ <payment_retries_enabled translate="label comment">
113
+ <label>Enable Payment Retry</label>
114
+ <frontend_type>select</frontend_type>
115
+ <source_model>adminhtml/system_config_source_yesno</source_model>
116
+ <sort_order>150</sort_order>
117
+ <show_in_default>1</show_in_default>
118
+ <show_in_website>1</show_in_website>
119
+ <show_in_store>0</show_in_store>
120
+ <comment>Defines if the customer can retry to pay the order.</comment>
121
+ </payment_retries_enabled>
122
+ <max_payment_retries translate="label comment">
123
+ <label>Max Payment Retries</label>
124
+ <frontend_type>text</frontend_type>
125
+ <sort_order>160</sort_order>
126
+ <show_in_default>1</show_in_default>
127
+ <show_in_website>1</show_in_website>
128
+ <show_in_store>0</show_in_store>
129
+ <validate>validate-number required-entry</validate>
130
+ <comment>Defines the max times the customer can retry to pay the order.</comment>
131
+ <depends>
132
+ <payment_retries_enabled>1</payment_retries_enabled>
133
+ </depends>
134
+ </max_payment_retries>
135
+ -->
136
+ <api_configuration type="group" translate="label comment">
137
+ <group>api_configuration</group>
138
+ <label>API Configuration</label>
139
+ <frontend_type>text</frontend_type>
140
+ <show_in_default>1</show_in_default>
141
+ <show_in_website>1</show_in_website>
142
+ <show_in_store>1</show_in_store>
143
+ <sort_order>200</sort_order>
144
+ <frontend_model>paypal/adminhtml_system_config_fieldset_payment</frontend_model>
145
+ <frontend_class>complex</frontend_class>
146
+ <comment>Configure all the parameters needed to API communication.</comment>
147
+ <fields>
148
+ <test translate="label">
149
+ <label>Test Mode</label>
150
+ <frontend_type>select</frontend_type>
151
+ <source_model>adminhtml/system_config_source_yesno</source_model>
152
+ <sort_order>10</sort_order>
153
+ <show_in_default>1</show_in_default>
154
+ <show_in_website>1</show_in_website>
155
+ <show_in_store>0</show_in_store>
156
+ <config_path>payment/rede_pay/test</config_path>
157
+ </test>
158
+ <api_order_url translate="label comment">
159
+ <label>API Order URL</label>
160
+ <frontend_type>text</frontend_type>
161
+ <sort_order>20</sort_order>
162
+ <show_in_default>1</show_in_default>
163
+ <show_in_website>1</show_in_website>
164
+ <show_in_store>0</show_in_store>
165
+ <config_path>payment/rede_pay/api_order_url</config_path>
166
+ <validate>validate-url</validate>
167
+ <comment>Be careful on changing this parameter.</comment>
168
+ <depends>
169
+ <test>1</test>
170
+ </depends>
171
+ </api_order_url>
172
+ <api_consult_url translate="label comment">
173
+ <label>API Consult URL</label>
174
+ <frontend_type>text</frontend_type>
175
+ <sort_order>25</sort_order>
176
+ <show_in_default>1</show_in_default>
177
+ <show_in_website>1</show_in_website>
178
+ <show_in_store>0</show_in_store>
179
+ <config_path>payment/rede_pay/api_consult_url</config_path>
180
+ <validate>validate-url</validate>
181
+ <comment>Be careful on changing this parameter.</comment>
182
+ <depends>
183
+ <test>1</test>
184
+ </depends>
185
+ </api_consult_url>
186
+ <api_refund_url translate="label comment">
187
+ <label>API Refund URL</label>
188
+ <frontend_type>text</frontend_type>
189
+ <sort_order>30</sort_order>
190
+ <show_in_default>1</show_in_default>
191
+ <show_in_website>1</show_in_website>
192
+ <show_in_store>0</show_in_store>
193
+ <config_path>payment/rede_pay/api_refund_url</config_path>
194
+ <validate>validate-url</validate>
195
+ <comment>Be careful on changing this parameter.</comment>
196
+ <depends>
197
+ <test>1</test>
198
+ </depends>
199
+ </api_refund_url>
200
+ <redepay_script_url translate="label comment">
201
+ <label>Rede Pay Script URL</label>
202
+ <frontend_type>text</frontend_type>
203
+ <sort_order>35</sort_order>
204
+ <show_in_default>1</show_in_default>
205
+ <show_in_website>1</show_in_website>
206
+ <show_in_store>0</show_in_store>
207
+ <config_path>payment/rede_pay/redepay_script_url</config_path>
208
+ <validate>validate-url</validate>
209
+ <comment>Be careful on changing this parameter.</comment>
210
+ <depends>
211
+ <test>1</test>
212
+ </depends>
213
+ </redepay_script_url>
214
+ <!-- Production Mode -->
215
+ <secret_api_key>
216
+ <label>API Key</label>
217
+ <frontend_type>text</frontend_type>
218
+ <sort_order>40</sort_order>
219
+ <show_in_default>1</show_in_default>
220
+ <show_in_website>1</show_in_website>
221
+ <show_in_store>0</show_in_store>
222
+ <config_path>payment/rede_pay/secret_api_key</config_path>
223
+ <depends>
224
+ <test>0</test>
225
+ </depends>
226
+ </secret_api_key>
227
+ <notification_token>
228
+ <label>Token NIP</label>
229
+ <frontend_type>text</frontend_type>
230
+ <sort_order>50</sort_order>
231
+ <show_in_default>1</show_in_default>
232
+ <show_in_website>1</show_in_website>
233
+ <show_in_store>0</show_in_store>
234
+ <config_path>payment/rede_pay/notification_token</config_path>
235
+ <depends>
236
+ <test>0</test>
237
+ </depends>
238
+ </notification_token>
239
+ <publishable_api_key>
240
+ <label>Public Token</label>
241
+ <frontend_type>text</frontend_type>
242
+ <sort_order>60</sort_order>
243
+ <show_in_default>1</show_in_default>
244
+ <show_in_website>1</show_in_website>
245
+ <show_in_store>0</show_in_store>
246
+ <config_path>payment/rede_pay/publishable_api_key</config_path>
247
+ <depends>
248
+ <test>0</test>
249
+ </depends>
250
+ </publishable_api_key>
251
+ <!-- Test Mode -->
252
+ <secret_api_key_test>
253
+ <label>API Key (Test Mode)</label>
254
+ <frontend_type>text</frontend_type>
255
+ <sort_order>70</sort_order>
256
+ <show_in_default>1</show_in_default>
257
+ <show_in_website>1</show_in_website>
258
+ <show_in_store>0</show_in_store>
259
+ <config_path>payment/rede_pay/secret_api_key_test</config_path>
260
+ <depends>
261
+ <test>1</test>
262
+ </depends>
263
+ </secret_api_key_test>
264
+ <notification_token_test>
265
+ <label>Token NIP (Test Mode)</label>
266
+ <frontend_type>text</frontend_type>
267
+ <sort_order>80</sort_order>
268
+ <show_in_default>1</show_in_default>
269
+ <show_in_website>1</show_in_website>
270
+ <show_in_store>0</show_in_store>
271
+ <config_path>payment/rede_pay/notification_token_test</config_path>
272
+ <depends>
273
+ <test>1</test>
274
+ </depends>
275
+ </notification_token_test>
276
+ <publishable_api_key_test>
277
+ <label>Public Token (Test Mode)</label>
278
+ <frontend_type>text</frontend_type>
279
+ <sort_order>90</sort_order>
280
+ <show_in_default>1</show_in_default>
281
+ <show_in_website>1</show_in_website>
282
+ <show_in_store>0</show_in_store>
283
+ <config_path>payment/rede_pay/publishable_api_key_test</config_path>
284
+ <depends>
285
+ <test>1</test>
286
+ </depends>
287
+ </publishable_api_key_test>
288
+ <url_notifications>
289
+ <label>URL for Notification</label>
290
+ <frontend_model>rede_pay/adminhtml_system_config_field_url</frontend_model>
291
+ <frontend_type>link</frontend_type>
292
+ <sort_order>100</sort_order>
293
+ <show_in_default>1</show_in_default>
294
+ <show_in_website>1</show_in_website>
295
+ <show_in_store>0</show_in_store>
296
+ <helper_url>data::getNotificationUrl</helper_url>
297
+ <config_path>payment/rede_pay/url_notifications</config_path>
298
+ <comment>This URL must be set in your Payment Gateway panel for automatic notifications of order statuses.</comment>
299
+ </url_notifications>
300
+ <url_redirect>
301
+ <label>URL for Redirect</label>
302
+ <frontend_model>rede_pay/adminhtml_system_config_field_url</frontend_model>
303
+ <frontend_type>link</frontend_type>
304
+ <sort_order>110</sort_order>
305
+ <show_in_default>1</show_in_default>
306
+ <show_in_website>1</show_in_website>
307
+ <show_in_store>0</show_in_store>
308
+ <helper_url>data::getRedirectUrl</helper_url>
309
+ <config_path>payment/rede_pay/url_redirect</config_path>
310
+ <comment>This URL must be set in your Payment Gateway panel for automatic notifications of redirect.</comment>
311
+ </url_redirect>
312
+ </fields>
313
+ </api_configuration>
314
+ <attribute_configuration type="group" translate="label comment">
315
+ <group>attribute_configuration</group>
316
+ <label>Attribute Configuration</label>
317
+ <frontend_type>text</frontend_type>
318
+ <show_in_default>1</show_in_default>
319
+ <show_in_website>1</show_in_website>
320
+ <show_in_store>1</show_in_store>
321
+ <sort_order>300</sort_order>
322
+ <frontend_model>paypal/adminhtml_system_config_fieldset_payment</frontend_model>
323
+ <frontend_class>complex</frontend_class>
324
+ <comment>Configure all the attributes needed to correct checkout process.</comment>
325
+ <fields>
326
+ <taxvat translate="label">
327
+ <label>Taxvat</label>
328
+ <frontend_type>select</frontend_type>
329
+ <source_model>rede_pay/system_config_source_attributes_customer</source_model>
330
+ <sort_order>10</sort_order>
331
+ <config_path>payment/rede_pay/attributes_taxvat</config_path>
332
+ <show_in_default>1</show_in_default>
333
+ <show_in_website>1</show_in_website>
334
+ <show_in_store>0</show_in_store>
335
+ </taxvat>
336
+ <address_street translate="label">
337
+ <label>Address Street</label>
338
+ <frontend_type>select</frontend_type>
339
+ <source_model>rede_pay/system_config_source_attributes_customer_address</source_model>
340
+ <sort_order>20</sort_order>
341
+ <config_path>payment/rede_pay/attributes_street</config_path>
342
+ <show_in_default>1</show_in_default>
343
+ <show_in_website>1</show_in_website>
344
+ <show_in_store>0</show_in_store>
345
+ </address_street>
346
+ <address_number translate="label">
347
+ <label>Address Number</label>
348
+ <frontend_type>select</frontend_type>
349
+ <source_model>rede_pay/system_config_source_attributes_customer_address</source_model>
350
+ <sort_order>30</sort_order>
351
+ <config_path>payment/rede_pay/attributes_number</config_path>
352
+ <show_in_default>1</show_in_default>
353
+ <show_in_website>1</show_in_website>
354
+ <show_in_store>0</show_in_store>
355
+ </address_number>
356
+ <address_complement translate="label">
357
+ <label>Address Complement</label>
358
+ <frontend_type>select</frontend_type>
359
+ <source_model>rede_pay/system_config_source_attributes_customer_address</source_model>
360
+ <sort_order>40</sort_order>
361
+ <config_path>payment/rede_pay/attributes_complement</config_path>
362
+ <show_in_default>1</show_in_default>
363
+ <show_in_website>1</show_in_website>
364
+ <show_in_store>0</show_in_store>
365
+ </address_complement>
366
+ <address_neighborhood translate="label">
367
+ <label>Address Neighborhood</label>
368
+ <frontend_type>select</frontend_type>
369
+ <source_model>rede_pay/system_config_source_attributes_customer_address</source_model>
370
+ <sort_order>50</sort_order>
371
+ <config_path>payment/rede_pay/attributes_neighborhood</config_path>
372
+ <show_in_default>1</show_in_default>
373
+ <show_in_website>1</show_in_website>
374
+ <show_in_store>0</show_in_store>
375
+ </address_neighborhood>
376
+ <telephone translate="label">
377
+ <label>Phone Number</label>
378
+ <frontend_type>select</frontend_type>
379
+ <source_model>rede_pay/system_config_source_attributes_customer_address</source_model>
380
+ <sort_order>60</sort_order>
381
+ <config_path>payment/rede_pay/attributes_telephone</config_path>
382
+ <show_in_default>1</show_in_default>
383
+ <show_in_website>1</show_in_website>
384
+ <show_in_store>0</show_in_store>
385
+ </telephone>
386
+ <cellphone translate="label">
387
+ <label>Cellphone Number</label>
388
+ <frontend_type>select</frontend_type>
389
+ <source_model>rede_pay/system_config_source_attributes_customer_address</source_model>
390
+ <sort_order>70</sort_order>
391
+ <config_path>payment/rede_pay/attributes_cellphone</config_path>
392
+ <show_in_default>1</show_in_default>
393
+ <show_in_website>1</show_in_website>
394
+ <show_in_store>0</show_in_store>
395
+ </cellphone>
396
+ </fields>
397
+ </attribute_configuration>
398
+ </fields>
399
+ </rede_pay>
400
+ </groups>
401
+ </payment>
402
+ </sections>
403
+ </config>
app/code/community/Rede/Pay/sql/rede_pay_setup/install-1.0.0.0.php ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Tiago Sampaio <tiago@tiagosampaio.com>
4
+ *
5
+ * @var Mage_Core_Model_Resource_Setup $this
6
+ */
7
+ $installer = $this;
8
+ $installer->startSetup();
9
+
10
+ /** @var Magento_Db_Adapter_Pdo_Mysql $connection */
11
+ $connection = $installer->getConnection();
12
+
13
+ /**
14
+ * Create Table --------------------------------------------------------------------------------------------------------
15
+ */
16
+ $tableName = $installer->getTable('rede_pay/payments');
17
+
18
+ /** Tries to drop table before trying to create it. */
19
+ $connection->dropTable($tableName);
20
+
21
+ /** @var Varien_Db_Ddl_Table $table */
22
+ $table = $connection->newTable($tableName);
23
+ $table->addColumn('id', Varien_Db_Ddl_Table::TYPE_INTEGER, 10, array(
24
+ 'identity' => true,
25
+ 'primary' => true,
26
+ 'nullable' => false
27
+ ), 'Payment ID.')
28
+ ->addColumn('order_id', Varien_Db_Ddl_Table::TYPE_INTEGER, 10, array(
29
+ 'primary' => true,
30
+ 'nullable' => false,
31
+ ), 'Reference Order ID.')
32
+ ->addColumn('order_increment_id', Varien_Db_Ddl_Table::TYPE_VARCHAR, 50, array(
33
+ 'nullable' => false,
34
+ ), 'Reference Order Increment ID.')
35
+ ->addColumn('payment_id', Varien_Db_Ddl_Table::TYPE_VARCHAR, 100, array(
36
+ 'nullable' => false
37
+ ), 'Payment ID in Payment Gateway.')
38
+ ->addColumn('transaction_id', Varien_Db_Ddl_Table::TYPE_VARCHAR, 100, array(
39
+ 'nullable' => true
40
+ ), 'Transaction ID in Payment Gateway.');
41
+
42
+ /**
43
+ * Add Indexes ---------------------------------------------------------------------------------------------------------
44
+ */
45
+ $fields = array('payment_id', 'order_id');
46
+ $idxType = Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE;
47
+ $idxName = $installer->getIdxName($tableName, $fields, $idxType);
48
+ $table->addIndex($idxName, $fields, array('type' => $idxType));
49
+
50
+ /**
51
+ * Add Foreign Keys ----------------------------------------------------------------------------------------------------
52
+ */
53
+ $refTable = $installer->getTable('sales/order');
54
+ $fkName = $installer->getFkName($tableName, 'order_id', $refTable, 'entity_id');
55
+ $actCscd = Varien_Db_Ddl_Table::ACTION_CASCADE;
56
+ $table->addForeignKey($fkName, 'order_id', $refTable, 'entity_id', $actCscd, $actCscd);
57
+
58
+ $connection->createTable($table);
59
+
60
+ $installer->endSetup();
app/code/community/Rede/Pay/sql/rede_pay_setup/upgrade-1.0.0.0-1.0.1.0.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Tiago Sampaio <tiago@tiagosampaio.com>
4
+ *
5
+ * @var Mage_Core_Model_Resource_Setup $this
6
+ */
7
+ $installer = $this;
8
+ $installer->startSetup();
9
+
10
+ /** @var Magento_Db_Adapter_Pdo_Mysql $connection */
11
+ $connection = $installer->getConnection();
12
+
13
+ /**
14
+ * Add Additional Information column -----------------------------------------------------------------------------------
15
+ */
16
+ $table = $installer->getTable('rede_pay/payments');
17
+ $connection->addColumn($table, 'additional_information_serialized', array(
18
+ 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
19
+ 'comment' => 'Additional Information',
20
+ 'nullable' => true,
21
+ ));
22
+
23
+ $installer->endSetup();
app/code/community/Rede/Pay/sql/rede_pay_setup/upgrade-1.0.1.1-1.0.2.0.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Tiago Sampaio <tiago@tiagosampaio.com>
4
+ *
5
+ * @var Mage_Core_Model_Resource_Setup $this
6
+ */
7
+ $installer = $this;
8
+ $installer->startSetup();
9
+
10
+ /** @var Magento_Db_Adapter_Pdo_Mysql $connection */
11
+ $connection = $installer->getConnection();
12
+
13
+ /**
14
+ * Add Additional Information column -----------------------------------------------------------------------------------
15
+ */
16
+ $table = $installer->getTable('rede_pay/payments');
17
+ $connection->addColumn($table, 'payment_retries', array(
18
+ 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
19
+ 'default' => 0,
20
+ 'comment' => 'Payment Retries',
21
+ 'nullable' => false,
22
+ ));
23
+
24
+ $installer->endSetup();
app/code/community/Rede/Pay/sql/rede_pay_setup/upgrade-1.0.2.0-1.0.2.1.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Tiago Sampaio <tiago@tiagosampaio.com>
4
+ *
5
+ * @var Mage_Core_Model_Resource_Setup $this
6
+ */
7
+ $installer = $this;
8
+ $installer->startSetup();
9
+
10
+ /** @var Magento_Db_Adapter_Pdo_Mysql $connection */
11
+ $connection = $installer->getConnection();
12
+
13
+ /**
14
+ * Add Rede Pay Order ID column ----------------------------------------------------------------------------------------
15
+ */
16
+ $table = $installer->getTable('rede_pay/payments');
17
+ $connection->addColumn($table, 'rede_order_id', array(
18
+ 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
19
+ 'length' => 100,
20
+ 'comment' => 'Rede Pay Order ID.',
21
+ 'nullable' => true,
22
+ 'after' => 'payment_id'
23
+ ));
24
+
25
+ $installer->endSetup();
app/code/community/Rede/Pay/sql/rede_pay_setup/upgrade-1.0.2.1-1.0.2.2.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Tiago Sampaio <tiago@tiagosampaio.com>
4
+ *
5
+ * @var Mage_Core_Model_Resource_Setup $this
6
+ */
7
+ $installer = $this;
8
+ $installer->startSetup();
9
+
10
+ /** @var Magento_Db_Adapter_Pdo_Mysql $connection */
11
+ $connection = $installer->getConnection();
12
+
13
+ /**
14
+ * Drop Rede Pay Order ID column ----------------------------------------------------------------------------------------
15
+ */
16
+ $table = $installer->getTable('rede_pay/payments');
17
+ $connection->dropColumn($table, 'rede_order_id');
18
+
19
+ $installer->endSetup();
app/design/adminhtml/default/default/template/rede/pay/form/method/standard.phtml ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Tiago Sampaio <tiago@tiagosampaio.com>
4
+ *
5
+ * @var Rede_Pay_Block_Form_Method_Standard $this
6
+ */
7
+ ?>
8
+ <?php $_code = $this->getMethodCode() ?>
9
+ <ul id="payment_form_<?php echo $_code ?>" style="display:none">
10
+ <li>
11
+ <p><?php echo $this->getTextMessage() ?></p>
12
+ <img src="<?php echo $this->getSkinUrl('rede/pay/images/redepay.png') ?>" alt="<?php echo $this->__('Rede Pay') ?>"/>
13
+ </li>
14
+ </ul>
app/design/adminhtml/default/default/template/rede/pay/info/method/standard.phtml ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Tiago Sampaio <tiago@tiagosampaio.com>
4
+ *
5
+ * @var Rede_Pay_Block_Info_Method_Standard $this
6
+ */
7
+ ?>
8
+ <p>
9
+ <span><?php echo $this->__('Order paid with:') ?></span>
10
+ <br/>
11
+ <br/>
12
+ <?php echo $this->getLogoHtml() ?>
13
+ <br/>
14
+ <?php if ($this->getPaymentId()): ?>
15
+ <p id="payment-id"><strong><?php echo $this->__('Rede Order ID') ?>: </strong><?php echo $this->getPaymentId() ?></p>
16
+ <?php endif; ?>
17
+ <?php if ($this->getTransactionId()): ?>
18
+ <p id="transaction-id"><strong><?php echo $this->__('Transaction ID') ?>: </strong><?php echo $this->getTransactionId() ?></p>
19
+ <?php endif; ?>
20
+ <?php if ($this->getPayments()->getPaymentMethod()): ?>
21
+ <p id="payment-method"><strong><?php echo $this->__('Payment Method') ?>: </strong><?php echo $this->getPayments()->getPaymentMethod() ?></p>
22
+ <?php endif; ?>
23
+ <?php if ($this->getPayments()->getCardBrand()): ?>
24
+ <p id="card-brand"><strong><?php echo $this->__('Card Brand') ?>: </strong><?php echo $this->getPayments()->getCardBrand() ?></p>
25
+ <?php endif; ?>
26
+ <?php if ($this->getPayments()->getInstallments()): ?>
27
+ <p id="installments"><strong><?php echo $this->__('Instalments Amount') ?>: </strong><?php echo $this->getPayments()->getInstallments() ?></p>
28
+ <?php endif; ?>
29
+ <?php if ($this->getPayments()->getNsu()): ?>
30
+ <p id="nsu"><strong><?php echo $this->__('NSU') ?>: </strong><?php echo $this->getPayments()->getNsu() ?></p>
31
+ <?php endif; ?>
32
+ <?php if ($this->getPayments()->getTid()): ?>
33
+ <p id="tid"><strong><?php echo $this->__('TID') ?>: </strong><?php echo $this->getPayments()->getTid() ?></p>
34
+ <?php endif; ?>
35
+ </p>
36
+ <br/>
37
+ <?php if ($_specificInfo = $this->getSpecificInformation()):?>
38
+ <table>
39
+ <tbody>
40
+ <?php foreach ($_specificInfo as $_label => $_value):?>
41
+ <tr>
42
+ <th><strong><?php echo $this->escapeHtml($_label)?>:</strong></th>
43
+ </tr>
44
+ <tr>
45
+ <td><?php echo nl2br(implode($this->getValueAsArray($_value, true), "\n"))?></td>
46
+ </tr>
47
+ <?php endforeach; ?>
48
+ </tbody>
49
+ </table>
50
+ <?php endif;?>
51
+ <?php echo $this->getChildHtml()?>
app/design/adminhtml/default/default/template/rede/pay/logo.phtml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Tiago Sampaio <tiago@tiagosampaio.com>
4
+ *
5
+ * @var Rede_Pay_Block_Logo $this
6
+ */
7
+ ?>
8
+ <img src="<?php echo $this->getSrc() ?>" alt="<?php echo $this->escapeHtml($this->getAlt()) ?>" title="<?php echo $this->escapeHtml($this->getTitle()) ?>" width="<?php echo $this->getWidth() ?>" />
app/design/frontend/base/default/layout/rede/pay.xml ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * @author Tiago Sampaio <tiago@tiagosampaio.com>
5
+ */
6
+ -->
7
+ <layout version="0.1.0">
8
+
9
+ <rede_pay_checkout_success>
10
+ <update handle="INIT_LAYOUT"/>
11
+ <reference name="content">
12
+ <block type="rede_pay/checkout_success" name="redepay.checkout.success"/>
13
+ </reference>
14
+ </rede_pay_checkout_success>
15
+ <rede_pay_checkout_pending>
16
+ <update handle="INIT_LAYOUT"/>
17
+ <reference name="content">
18
+ <block type="rede_pay/checkout_pending" name="redepay.checkout.pending"/>
19
+ </reference>
20
+ </rede_pay_checkout_pending>
21
+ <rede_pay_checkout_state>
22
+ <update handle="INIT_LAYOUT"/>
23
+ <reference name="content">
24
+ <block type="rede_pay/checkout_state" name="redepay.checkout.state"/>
25
+ </reference>
26
+ </rede_pay_checkout_state>
27
+ <rede_pay_checkout_denied>
28
+ <update handle="INIT_LAYOUT"/>
29
+ <reference name="content">
30
+ <block type="rede_pay/checkout_denied" name="redepay.checkout.denied"/>
31
+ </reference>
32
+ </rede_pay_checkout_denied>
33
+ <rede_pay_checkout_error>
34
+ <update handle="INIT_LAYOUT"/>
35
+ <reference name="content">
36
+ <block type="rede_pay/checkout_error" name="redepay.checkout.error"/>
37
+ </reference>
38
+ </rede_pay_checkout_error>
39
+ <rede_pay_checkout_payment>
40
+ <update handle="INIT_LAYOUT"/>
41
+ <reference name="content">
42
+ <block type="rede_pay/checkout_payment" name="redepay.checkout.payment"/>
43
+ </reference>
44
+ </rede_pay_checkout_payment>
45
+
46
+ <INIT_LAYOUT>
47
+ <reference name="root">
48
+ <action method="setTemplate">
49
+ <template>page/1column.phtml</template>
50
+ </action>
51
+ </reference>
52
+ <reference name="head">
53
+ <action method="addCss">
54
+ <name>rede/pay/css/styles.css</name>
55
+ </action>
56
+ </reference>
57
+ </INIT_LAYOUT>
58
+
59
+ </layout>
app/etc/modules/Rede_Pay.xml ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * @author Tiago Sampaio <tiago@tiagosampaio.com>
5
+ */
6
+ -->
7
+ <config>
8
+ <modules>
9
+ <Rede_Pay>
10
+ <active>true</active>
11
+ <codePool>community</codePool>
12
+ </Rede_Pay>
13
+ </modules>
14
+ </config>
app/locale/pt_BR/Rede/Pay.csv ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "You are paying with","Você está pagando com"
2
+ "You will proceed the payment right after the order placement.","Você realizará o pagamento logo após a conclusão do pedido."
3
+ "Something went wrong in the payment process.","Algo de arrado aconteceu com o processo de pagamento."
4
+ "Incorrect transaction reference.","Referência de transação incorreta."
5
+ "Your order has been received.","Seu pedido foi recebido."
6
+ "You are paying you order with","Você está pagando seu pedido com"
7
+ "Your order # is: %s.","O número de seu pedido é %s."
8
+ "You will receive an order confirmation email with details of your order and a link to track its progress.","Você receberá um e-mail de confirmação de seu pedido com os detalhes do mesmo e um link para acompanhar o progresso do seu pedido."
9
+ "Your order is in finishing process, please wait a moment.","Seu pedido está em processo de finalização, por favor, aguarde um momento."
10
+ "If the payment page don not start automatically in %d seconds click in the button right bellow.","Se a página de pagamento não iniciar automaticamente em %d segundos, clique no botão logo abaixo."
11
+ "Register with us now to get all the advantages.","Cadastre-se conosco agora e tenha todas as vantagens."
12
+ "Enabled","Habilitado"
13
+ "Title","Título"
14
+ "Text Message","Mensagem de Texto"
15
+ "New Order Status","Status de Novos Pedidos"
16
+ "Approved Order Status","Status de Pedidos Aprovados"
17
+ "Debug","Modo Debug"
18
+ "Installments Amount","Quantidade de Parcelas"
19
+ "Sort Order","Ordenação"
20
+ "Lightbox Delay Time","Tempo de Demora para o Lighbox"
21
+ "API Configuration","Configuração de Comunicação com a API"
22
+ "Configure all the parameters needed to API communication.","Configure todos os parâmetros necessários para a comunicação com a API."
23
+ "Attribute Configuration","Configuração de Atributos"
24
+ "Configure all the attributes needed to correct checkout process.","Configure todos os atributos necessários para o processo correto no checkout."
25
+ "API Order URL","URL da API de Pedidos"
26
+ "Rede Pay Script URL","URL do Script Rede Pay"
27
+ "Test Mode","Modo Teste"
28
+ "API Key (Test Mode)","API Key (Modo Teste)"
29
+ "Public Token (Test Mode)","Public Token (Modo Teste)"
30
+ "Token NIP (Test Mode)","Token NIP (Modo Teste)"
31
+ "API Key","API Key"
32
+ "Public Token","Public Token"
33
+ "Token NIP","Token NIP"
34
+ "Taxvat","CPF/CNPJ"
35
+ "Address Street","Rua do Endereço"
36
+ "Address Number","Número do Endereço"
37
+ "Address Complement","Complemento do Endereço"
38
+ "Address Neighborhood","Bairro do Endereço"
39
+ "Phone Number","Número do Telefone"
40
+ "Cellphone Number","Número do Celular"
41
+ "Business Phone Number","Número do Telefone da Empresa"
42
+ "In seconds.","Em segundos."
43
+ "Max quantity of installments that will be available to customers.","Quantidade máxima de parcelas que estará disponível para os clientes."
44
+ "Enables the debug mode for this payment method.","Habilita o modo debug para este método de pagamento."
45
+ "The order status when the order is approved by Payment Gateway.","O status do pedido quando o mesmo for aprovado pelo Gateway de Pagamento."
46
+ "The order status to new orders.","O status de pedido para novos pedidos."
47
+ "This text will appear to customer on the payment section in checkout page.","Esta mensagem de texto aparecerá para o cliente na seção de pagamentos no página de checkout"
48
+ "Be careful on changing this parameter.","Seja cauteloso ao alterar este parâmetro."
49
+ "Configuration","Configuração"
50
+ "No","Não"
51
+ "Yes","Sim"
52
+ "Your order has been canceled.","Seu pedido foi cancelado."
53
+ "Unfortunately your order #%s was canceled.","Infelizmente seu pedido #%s foi cancelado."
54
+ "We are really sorry for this inconvenience.","Nós sentimos muito por qualquer inconveniência."
55
+ "This URL must be set in your Payment Gateway panel for automatic notifications of order statuses.","Esta URL deve ser configurada no seu portal de vendedor no Rede Pay para notificação automática de status de pedidos."
56
+ "This URL must be set in your Payment Gateway panel for automatic notifications of redirect.","Esta URL deve ser configurada no seu portal de vendedor no Rede Pay para o redirecionamento."
57
+ "This URL must be set in your Payment Gateway panel for automatic order canceling.","Esta URL deve ser configurada no seu portal de vendedor no Rede Pay para o cancelamento automático de pedido."
58
+ "URL for Notification","URL para Notificação"
59
+ "URL for Redirect","URL para Redirecionamento"
60
+ "URL for Canceling Orders","URL para Cancelamento de Pedidos"
61
+ "API Consult URL","URL da API de Consulta"
62
+ "Payment ID","ID do Pagamento"
63
+ "Transaction ID","ID da Transação"
64
+ "Order paid with:","Pedido realizado com:"
65
+ "Paid with","Pagamento realizado com"
66
+ "<a href=""%s"" onclick=""this.target=\'_blank\'"">Click here</a> to print a cop of your order confirmation.","<a href=""%s"" onclick=""this.target=\'_blank\'"">Clique aqui</a> para imprimir uma cópia da sua confirmação do pedido."
67
+ "The payment was not authorized. For more information please contact the card issuer.","O pagamento não foi autorizado. Para maiores informações entre em contato com o emissor do cartão."
68
+ "Your order #%s was approved.","Seu pedido #%s foi aprovado."
69
+ "Your order #%s in analysis.","Seu pedido #%s está em análise."
70
+ "Your order #%s was canceled.","Seu pedido #%s foi cancelado."
71
+ "Installments Parcel Minimum Value","Valor Mínimo de Cada Parcela"
72
+ "Installments Order Minimum Value","Valor Mínimo do Pedido para Parcelamento"
73
+ "Defines the minimum value of the order to enable the installments.","Define o valor mínimo do pedido para habilitar o parcelamento."
74
+ "Defines the minimum value of each parcel according to the value inserted. The maximum quantity of parcels will be calculated automatically.","Define o valor mínimo de cada parcela de acordo com o valor inserido. A quantidade máxima de parcelas será calculada automaticamente."
75
+ "Reorder","Re-comprar"
76
+ "Order was fund and update successfully.","O pedido foi encontrado e atualizado com sucesso."
77
+ "This order was not found in Rede Pay.","Este pedido não foi encontrado no Rede Pay."
78
+ "Some error has occurred when trying to consult this order.","Um erro ocorreu ao tentar consultar este pedido."
79
+ "Order ID does not exist anymore.","Este ID de pedido não existe."
80
+ "Order canceled by Rede Pay.","Pedido cancelado pela Rede Pay."
81
+ "Order #%s is canceled.","Pedido #%s cancelado."
82
+ "Some error occurred when trying to cancel the order.","Um erro ocorreu ao tentar cancelar o pedido."
83
+ "Order was not found.","Pedido não encontrado."
84
+ "Your order #%s is %s.","Seu pedido #%s está %s."
85
+ "To retry the payment for the order, please click in the link below:","Para realizar uma nova tentativa de pagamento do pedido, por favor, clique no link abaixo:"
86
+ "Your payment was not confirmed.","Seu pagamento não foi confirmado."
87
+ "Order Status Change by %s Process from Rede Pay: %s.","Status do Pedido Alterado pelo processo de %s da Rede Pay: %s."
88
+ "Status sent is empty and will bot be processed.","O status enviado está vazio e não será processado."
89
+ "Order Invoiced By %s Process From Rede Pay.","Pedido Faturado Pelo Processo de %s da Rede Pay."
90
+ "Order Canceled By %s Process From Rede Pay.","Pedido Cancelado Pelo Processo de %s da Rede Pay."
91
+ "Order Refunded By %s Process From Rede Pay.","Pedido Estornado Pelo Processo de %s da Rede Pay."
92
+ "Canceling order. Error when trying to process the order payment.","Cancelando o pedido. Um erro ocorreu ao tentar processar o pagamento do pedido."
93
+ "Cannot create an invoice without products.","Não é possível criar a invoice sem produtos."
94
+ "Notification","Notificação"
95
+ "Consult","Consulta"
96
+ "Click here to print a copy of your order confirmation.","Clique aqui para imprimir uma cópia da confirmação de seu pedido."
97
+ "Payment Method","Método de Pagamento"
98
+ "Card Brand","Bandeira do Cartão"
99
+ "Instalments Amount","Quantidade de Parcelas"
100
+ "NSU","NSU"
101
+ "TID","TID"
102
+ "Continue Shopping","Continuar Comprando"
103
+ "The postcode number cannot be empty. Please insert a correct value.","O CEP não pode estar vazio. Por favor, insira um CEP válido."
104
+ "Customers phone list must have at least one {1} phone kind.","Por favor, informe um número de celular."
105
+ "CPF number is not valid.","Por favor, informe um CPF válido."
106
+ "Required field shipping.address.district was not informed.","Por favor, informe o bairro do endereço."
107
+ "Required field shipping.address.number was not informed.","Por favor, informe o número do endereço."
108
+ "At least cellphone is necessary to proceed with order.","Ao menos um telefone deve ser informado para prosseguir com o pedido."
109
+ "Invalid field customer.phones[1].number pattern.","Por favor, informe o DDD (com 2 dígitos) dos telefones."
110
+ "Fail when trying to authenticate in service.","Falha ao tentar autenticar no serviço."
111
+ "Enable Payment Retry","Habilitar Re-tentativa de Pagamento"
112
+ "Defines if the customer can retry to pay the order.","Define se o cliente pode tentar pagar o pedido novamente."
113
+ "Max Payment Retries","Quantidade Máxima de Re-tenteativas de Pagamento"
114
+ "Defines the max times the customer can retry to pay the order.","Define a quantidade máxima de vezes que o cliente pode re-tentar pagar o mesmo pedido."
115
+ "Pay with Rede Pay","Pagar com Rede Pay"
116
+ "Order Is In Payment Review By %s Process From Rede Pay.","O pedido está em Revisão de Pagamento pelo processo de %s da Rede Pay."
117
+ "Tracking number %s removed by Rede Pay notification process.","Código de rastreio %s foi removido pelo processo de notificação da Rede Pay."
118
+ "Tracking number %s added to order shipment by Rede Pay notification process.","Código de rastreio %s adicionado á remessa de entrega do pedido pelo processo de notificação da Rede Pay."
119
+ "Order shipment created by Rede Pay notification process with tracking number %s.","Remessa de entrega criada pelo processo de notificação da Rede Pay com o código de rastreio %s."
120
+ "The postcode number cannot be empty. Please insert a correct value.","Número do CEP obrigatório / inválido."
121
+ "Required field shipping.address.number was not informed.","O número do endereço é obrigatório."
122
+ "Required field shipping.address.district was not informed.","O bairro do endereço é obrigatório."
123
+ "Customers phone list must have at least one {0} phone kind.","O número do telefone é obrigatório."
124
+ "Customers phone list must have at least one {1} phone kind.","O número do celular é obrigatório."
125
+ "Invalid field customer.phones[0].number pattern.","Número do telefone inválido. Favor preencher corretamente."
126
+ "Invalid field customer.phones[1].number pattern.","Número do celular inválido. Favor preencher corretamente."
127
+ "Document number is necessary to proceed with order. CPF number is not valid.","Número do CPF obrigatório / inválido."
128
+ "CPF number is not valid.","Número do CPF obrigatório / inválido."
package.xml CHANGED
@@ -1,18 +1,18 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Rede_Pay</name>
4
- <version>1.2.2.0</version>
5
  <stability>stable</stability>
6
- <license uri="http://opensource.org/licenses/osl-3.0.php">Open Software License</license>
7
  <channel>community</channel>
8
  <extends/>
9
- <summary>The ideal partner for your e-commerce. O parceiro ideal para o seu e-commerce.</summary>
10
- <description>A complete solution for online payment methods, which aims to facilitate purchases and payments in e-commerce. You and your company have many benefits at your disposal, from the simplicity to the integration process * with your online store, even with possibility of guarantee against chargeback *. The service is responsive, safe and accepts the main market banners, like Visa, MasterCard, Hiper, Hipercard and Diners.</description>
11
- <notes>Changes or URL</notes>
12
- <authors><author><name>Tiago Sampaio</name><user>tiagosampaio</user><email>tiago@tiagosampaio.com</email></author></authors>
13
- <date>2016-09-13</date>
14
- <time>18:20:40</time>
15
- <contents><target name="magelocal"><dir name="."><dir name="app"><dir name="design"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><dir name="rede"><file name="pay.xml" hash=""/></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><dir name="rede"><file name="pay.xml" hash=""/></dir></dir></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="."><dir name="app"><dir name="etc"><dir name="modules"><file name="Rede_Pay.xml" hash=""/></dir></dir></dir></dir></target><target name="magelocale"><dir name="."><dir name="app"><dir name="locale"><dir name="pt_BR"><dir name="Rede"><file name="Pay.csv" hash=""/></dir></dir></dir></dir></dir></target></contents>
16
  <compatible/>
17
- <dependencies><required><php><min>5.3.6</min><max>5.6.10</max></php></required></dependencies>
18
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Rede_Pay</name>
4
+ <version>1.3.0.0</version>
5
  <stability>stable</stability>
6
+ <license>OSL</license>
7
  <channel>community</channel>
8
  <extends/>
9
+ <summary>M&#xF3;dulo Rede Pay para plataforma Magento</summary>
10
+ <description>M&#xF3;dulo Rede Pay para plataforma Magento</description>
11
+ <notes>Possibilidade de configurar carrinho abandonado, c&#xF3;digo de rastreio e desconto integrando as funcionalidades com o Rede Pay.</notes>
12
+ <authors><author><name>Tiago Sampaio</name><user>TiagoSampaio</user><email>tiago@tiagosampaio.com</email></author></authors>
13
+ <date>2016-11-21</date>
14
+ <time>18:16:49</time>
15
+ <contents><target name="mageetc"><dir name="modules"><file name="Rede_Pay.xml" hash="988578655498e2cbcc87a2273f30ee67"/></dir></target><target name="magecommunity"><dir name="Rede"><dir name="Pay"><dir name="Block"><dir name="Adminhtml"><dir name="System"><dir name="Config"><dir name="Field"><file name="Url.php" hash="9f05035e1694fa7a3a18b78b548d041a"/></dir><dir name="Fieldset"><file name="Group.php" hash="fb37b394d0b07ec772d64cf5d44a7260"/></dir></dir></dir></dir><dir name="Checkout"><file name="Abstract.php" hash="b0611bcbecea7689704d5095eabe4a61"/><file name="Denied.php" hash="edf9453068343fa3a6c0f31331024fd9"/><file name="Error.php" hash="29d6546006d564ea2803b458b2384ff9"/><file name="Payment.php" hash="b73be86f9390fa5bfc456dac0fd19cdd"/><file name="Pending.php" hash="98865e53660c6d77aec2bcbf11a94023"/><file name="State.php" hash="caf70108eb0c4e3d815277849564107d"/><file name="Success.php" hash="979aa881135e09bd15e2983c20fc4f4d"/></dir><dir name="Form"><dir name="Method"><file name="Standard.php" hash="45d0c016398ab06f55acb51e337aa8cb"/></dir></dir><dir name="Info"><dir name="Method"><file name="Standard.php" hash="7b77a69f199dcd705cf5ccc557bbe326"/></dir></dir><file name="Logo.php" hash="144759b378a5d452b29a4c6c60c48f8f"/></dir><dir name="Controller"><dir name="Adminhtml"><file name="Action.php" hash="b22578183796cd14b4149e5a3eef677a"/></dir><dir name="Front"><file name="Action.php" hash="40ca3ce288246a17bdb843fb8898128e"/></dir></dir><dir name="Helper"><file name="Attributes.php" hash="3d2fabb512a8b847fc4e2fa489c87ac8"/><file name="Data.php" hash="9afef36eb43ae427e33ae4e196017c68"/></dir><dir name="Model"><file name="Abstract.php" hash="61ec57f3aed67cfc22c80e35a757bf49"/><file name="Api.php" hash="9074cd40e538a3adff2d7a78dec189b0"/><file name="Logger.php" hash="81233eefc7e387daca713de5fd02723b"/><dir name="Method"><file name="Standard.php" hash="dc74a8d34a86d1e83a5189f5056d2aea"/></dir><file name="Observer.php" hash="26bc0b7f1fa54bcbc00f9a419e4b023c"/><dir name="Params"><file name="Abstract.php" hash="e3668cd0a372f372b6493274803b3d55"/><file name="Consult.php" hash="f8b3a2df7e99ce5efd5aa4dc93a04856"/><file name="Order.php" hash="3970763556d28346ae995e96d2ce4373"/><file name="Refund.php" hash="47a6b84d5e39ab9c73c9f82693197aa5"/><dir name="Shipping"><dir name="Tracking"><file name="Delete.php" hash="03b22ffd8f6ef6581ee042561e470724"/></dir><file name="Tracking.php" hash="b1f6df2b517f6baca944de930249d20a"/></dir></dir><file name="Payments.php" hash="31e82f632e0c4cc8c0d81e290e3da789"/><dir name="Processor"><file name="Order.php" hash="0ced69a2ae8e109f002dfb7723302ce9"/></dir><file name="Processor.php" hash="4846725bcfad351d4ba2a765cb1bf75b"/><dir name="Resource"><dir name="Payments"><file name="Collection.php" hash="6fbcd1017f711cbebffe3768be0a61a0"/></dir><file name="Payments.php" hash="005e49130e846dd21f717dc9bbbeab75"/></dir><file name="Session.php" hash="b6a7de869c46178677f6670580bd3cb5"/><dir name="System"><dir name="Config"><dir name="Source"><dir name="Attributes"><dir name="Customer"><file name="Address.php" hash="6fccaad92feb38b6d11b5aac4e0d15d8"/></dir><file name="Customer.php" hash="28a1f2c83dec18a6096303c53006da10"/></dir><file name="Installments.php" hash="be37aff866d2548ea2b0c7d71ca015df"/></dir></dir></dir><dir name="Validator"><file name="Cpf.php" hash="dc6f661772d8ebbf84fed483ebc3003a"/><dir name="Shipping"><file name="Tracking.php" hash="e1d891b58dd218dda4f25e5893199c88"/></dir></dir></dir><dir name="Trait"><file name="Config.php" hash="8b332dfa8922fa955eca2623d8f8c69e"/><file name="Data.php" hash="e938b4929bcb101ed9cf1986f58d0729"/></dir><dir name="controllers"><dir name="Adminhtml"><dir name="Sales"><file name="OrderController.php" hash="3cf0f6cc9fe7f2d11d47d038a4c2785a"/></dir></dir><file name="CheckoutController.php" hash="2a864b38ee8606302f22cd5a066c0c20"/><file name="NotificationController.php" hash="0c4fbdf6446888dd6bd44791003de870"/></dir><dir name="data"><dir name="rede_pay_setup"><file name="data-install-1.0.0.0.php" hash="783634879a104748237abc4c7a83cbd3"/><file name="data-upgrade-1.0.1.0-1.0.1.1.php" hash="9d79857c9e0d6c0d9eed88b5f706b9d8"/></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="03c5e227dc611890995e4f3c1ce71c99"/><file name="config.xml" hash="e98128c31e4d6bd4f8528d00c1e9cbe1"/><file name="system.xml" hash="48df4333c3fb4bdf09205e7269ed4413"/></dir><dir name="sql"><dir name="rede_pay_setup"><file name="install-1.0.0.0.php" hash="e47129c2fbb492744ef0494b971b070c"/><file name="upgrade-1.0.0.0-1.0.1.0.php" hash="1e728f4328719ca77ffbde7699a123e2"/><file name="upgrade-1.0.1.1-1.0.2.0.php" hash="1f377d0dd1f2f199d03c5d8e05ff581b"/><file name="upgrade-1.0.2.0-1.0.2.1.php" hash="8ca921a968605aeebaaec164fff7eabf"/><file name="upgrade-1.0.2.1-1.0.2.2.php" hash="a76a7429ffa3e200040b97c1e2d7ae72"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="pay.xml" hash=""/></dir><dir name="template"><dir name="rede"><dir name="pay"><dir name="form"><dir name="method"><file name="standard.phtml" hash="75fb8c6d8a2fb9bbe9ae73188d825071"/></dir></dir><dir name="info"><dir name="method"><file name="standard.phtml" hash="91e3e035475d9d38747162a0b22aa266"/></dir></dir><file name="logo.phtml" hash="bdb5c5ee5467ce094e6fcd68a12a2731"/></dir></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><dir name="rede"><file name="pay.xml" hash="789d813c4fa7ecfdcdec86316e46e12d"/></dir></dir></dir></dir></dir></target><target name="magelocale"><dir name="pt_BR"><dir name="Rede"><file name="Pay.csv" hash="61357e7ff9a123c11c45d143951885a6"/></dir></dir></target><target name="mageskin"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="rede"><dir name="pay"><dir name="css"><file name="adminhtml.css" hash="9a52ba84af1f09c84e834decca70c8b1"/></dir><dir name="images"><file name="bt_cadastro.png" hash="9cdcc160fa88d45ad1010291462382dd"/><file name="bt_magento_configurar.png" hash="ad918a5459634e9750ab8ef6b5089790"/><file name="bt_magento_fechar.png" hash="a1287dece4ffd2ad92c46c7d45560bd9"/><file name="clickpag_rede.png" hash="ecc50aa7e77c82e02ed3cb5c7a6925af"/><file name="rede-logo-282x100.png" hash="0b02e48d5259f6a7db0e2356a353f429"/><file name="rede-logo.png" hash="e9173a51d7adb97923330059e9e1ad0a"/><file name="redepay.png" hash="ff9df8e1a2c4afd921cb1dfe4c172a37"/></dir></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="rede"><dir name="pay"><dir name="css"><file name="styles.css" hash="bdb358d433d0e30a1c14e96351597739"/></dir><dir name="images"><file name="bt_magento_configurar.png" hash="ad918a5459634e9750ab8ef6b5089790"/><file name="bt_magento_fechar.png" hash="a1287dece4ffd2ad92c46c7d45560bd9"/><file name="clickpag_rede.png" hash="ecc50aa7e77c82e02ed3cb5c7a6925af"/><file name="rede-logo-282x100.png" hash="0b02e48d5259f6a7db0e2356a353f429"/><file name="rede-logo.png" hash="e9173a51d7adb97923330059e9e1ad0a"/><file name="redepay.png" hash="ff9df8e1a2c4afd921cb1dfe4c172a37"/></dir></dir></dir></dir></dir><dir name="default"><dir name="default"><dir name="rede"><dir name="pay"><dir name="css"><file name="styles.css" hash="5e0b901588a94f09650041978a3f673e"/></dir></dir></dir></dir></dir></dir></target></contents>
16
  <compatible/>
17
+ <dependencies><required><php><min>5.3.0</min><max>5.6.1</max></php></required></dependencies>
18
  </package>
skin/adminhtml/default/default/rede/pay/css/adminhtml.css ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!--
2
+ /**
3
+ * @author Tiago Sampaio <tiago@tiagosampaio.com>
4
+ */
5
+ -->
6
+ .redepay {
7
+
8
+ }
9
+
10
+ .redepay .with-button .button-container {
11
+ /*
12
+ background-image: url('../images/redepay.png');
13
+ background-repeat: no-repeat;
14
+ width: 400px;
15
+ padding: 4px;
16
+ */
17
+ }
18
+
19
+ .redepay .button {
20
+ background: transparent !important;
21
+ border: none;
22
+ }
23
+
24
+ .redepay .button .state-closed,
25
+ .redepay .button .state-opened {
26
+ text-indent: -9999px;
27
+ width: 120px;
28
+ line-height: 32px;
29
+ }
30
+
31
+ .redepay .button .state-closed {
32
+ background-image: url('../images/bt_magento_configurar.png');
33
+ }
34
+
35
+ .redepay .button .state-opened {
36
+ background-image: url('../images/bt_magento_fechar.png');
37
+ }
skin/adminhtml/default/default/rede/pay/images/bt_cadastro.png ADDED
Binary file
skin/adminhtml/default/default/rede/pay/images/bt_magento_configurar.png ADDED
Binary file
skin/adminhtml/default/default/rede/pay/images/bt_magento_fechar.png ADDED
Binary file
skin/adminhtml/default/default/rede/pay/images/clickpag_rede.png ADDED
Binary file
skin/adminhtml/default/default/rede/pay/images/rede-logo-282x100.png ADDED
Binary file
skin/adminhtml/default/default/rede/pay/images/rede-logo.png ADDED
Binary file
skin/adminhtml/default/default/rede/pay/images/redepay.png ADDED
Binary file
skin/frontend/base/default/rede/pay/css/styles.css ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @author Tiago Sampaio <tiago@tiagosampaio.com>
3
+ */
4
+ .paid-with-info,
5
+ .paying-with-info {
6
+ display: block;
7
+ margin-top: 15px;
8
+ vertical-align: middle;
9
+ overflow: auto;
10
+ }
11
+
12
+ .paid-with-info span,
13
+ .paying-with-info span {
14
+ padding: 8px 8px 0 0;
15
+ float: left;
16
+ }
17
+
18
+ .paying-with-info span {
19
+ padding-top: 4px;
20
+ }
21
+
22
+ .paid-with-info img,
23
+ .paying-with-info img {
24
+ float: left;
25
+ }
26
+
27
+ .button-container {
28
+ display: block;
29
+ margin-top: 20px;
30
+ }
skin/frontend/base/default/rede/pay/images/bt_magento_configurar.png ADDED
Binary file
skin/frontend/base/default/rede/pay/images/bt_magento_fechar.png ADDED
Binary file
skin/frontend/base/default/rede/pay/images/clickpag_rede.png ADDED
Binary file
skin/frontend/base/default/rede/pay/images/rede-logo-282x100.png ADDED
Binary file
skin/frontend/base/default/rede/pay/images/rede-logo.png ADDED
Binary file
skin/frontend/base/default/rede/pay/images/redepay.png ADDED
Binary file
skin/frontend/default/default/rede/pay/css/styles.css ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @author Tiago Sampaio <tiago@tiagosampaio.com>
3
+ */
4
+ .paid-with-info,
5
+ .paying-with-info {
6
+ display: block;
7
+ padding-top: 0;
8
+ margin-top: 15px;
9
+ margin-bottom: 15px;
10
+ vertical-align: middle;
11
+ overflow: auto;
12
+ }
13
+
14
+ .paid-with-info span,
15
+ .paying-with-info span {
16
+ padding: 8px 8px 0 0;
17
+ float: left;
18
+ }
19
+
20
+ .paid-with-info img,
21
+ .paying-with-info img {
22
+ float: left;
23
+ }
24
+
25
+ .button-container {
26
+ display: block;
27
+ margin-top: 20px;
28
+ }