Optile_Payment_Connector - Version 1.0.1

Version Notes

Optile Magento Connector v1.0.1

Download this release

Release Info

Developer i-Ways
Extension Optile_Payment_Connector
Version 1.0.1
Comparing to
See all releases


Code changes from version 1.0.0 to 1.0.1

Files changed (104) hide show
  1. app/code/community/Optile/Payment/Block/Adminhtml/Notification.php +31 -0
  2. app/code/community/Optile/Payment/Block/Adminhtml/Notification/Grid.php +163 -0
  3. app/code/community/Optile/Payment/Block/Adminhtml/Notification/View.php +14 -0
  4. app/code/community/Optile/Payment/Block/Adminhtml/Order.php +31 -0
  5. app/code/community/Optile/Payment/Block/Adminhtml/Order/Creditmemo/Create/Items.php +83 -0
  6. app/code/community/Optile/Payment/Block/Adminhtml/Order/Grid.php +219 -0
  7. app/code/community/Optile/Payment/Block/Adminhtml/Order/View.php +31 -0
  8. app/code/community/Optile/Payment/Block/Adminhtml/System/Config/Frontend/Instructions.php +39 -0
  9. app/code/community/Optile/Payment/Block/Adminhtml/System/Config/Frontend/Instructions/Textarea.php +24 -0
  10. app/code/community/Optile/Payment/Block/Adminhtml/System/Config/Frontend/Noactivemethods.php +50 -0
  11. app/code/community/Optile/Payment/Block/Adminhtml/Widget/Grid/Column/Renderer/Url.php +59 -0
  12. app/code/community/Optile/Payment/Block/Info.php +65 -0
  13. app/code/community/Optile/Payment/Block/List.php +67 -58
  14. app/code/community/Optile/Payment/COPYING +0 -675
  15. app/code/community/Optile/Payment/Helper/Cache.php +29 -0
  16. app/code/community/Optile/Payment/Helper/Data.php +69 -17
  17. app/code/community/Optile/Payment/Model/Checkout.php +250 -167
  18. app/code/community/Optile/Payment/Model/Mysql4/Notification.php +25 -0
  19. app/code/community/Optile/Payment/Model/Mysql4/Notification/Collection.php +29 -0
  20. app/code/community/Optile/Payment/Model/Mysql4/Quote.php +27 -0
  21. app/code/community/Optile/Payment/Model/Mysql4/Quote/Collection.php +29 -0
  22. app/code/community/Optile/Payment/Model/Notification.php +692 -270
  23. app/code/community/Optile/Payment/Model/Observer.php +231 -0
  24. app/code/community/Optile/Payment/Model/Order/Payment.php +88 -0
  25. app/code/community/Optile/Payment/Model/PaymentMethod.php +410 -101
  26. app/code/community/Optile/Payment/Model/Quote.php +28 -0
  27. app/code/community/Optile/Payment/Model/System/Config/Backend/Disablemethods.php +24 -0
  28. app/code/community/Optile/Payment/Model/System/Config/Backend/Enabledmethods/Bool.php +29 -0
  29. app/code/community/Optile/Payment/Model/System/Config/Backend/Enabledmethods/Select.php +30 -0
  30. app/code/community/Optile/Payment/Model/System/Config/Backend/Instructions.php +14 -0
  31. app/code/community/Optile/Payment/Model/System/Config/Source/Deferral.php +32 -0
  32. app/code/community/Optile/Payment/Model/System/Config/Source/Enabledmethods.php +46 -0
  33. app/code/community/Optile/Payment/Model/System/Config/Source/Loglevel.php +51 -0
  34. app/code/community/Optile/Payment/controllers/Adminhtml/Optile/NotificationController.php +155 -0
  35. app/code/community/Optile/Payment/controllers/Adminhtml/Optile/OrderController.php +128 -0
  36. app/code/community/Optile/Payment/controllers/NotificationController.php +42 -20
  37. app/code/community/Optile/Payment/controllers/PaymentController.php +67 -54
  38. app/code/community/Optile/Payment/etc/adminhtml.xml +58 -0
  39. app/code/community/Optile/Payment/etc/config.xml +170 -63
  40. app/code/community/Optile/Payment/etc/system.xml +323 -114
  41. app/code/community/Optile/Payment/sql/optile_setup/mysql4-install-1.0.0.php +58 -0
  42. app/code/community/Optile/Payment/sql/optile_setup/mysql4-upgrade-1.0.0-1.0.1.php +38 -0
  43. app/code/community/Optile/Payment/sql/optile_setup/mysql4-upgrade-1.0.1-1.0.2.php +34 -0
  44. app/code/community/Optile/Payment/sql/optile_setup/mysql4-upgrade-1.0.2-1.0.3.php +47 -0
  45. app/design/adminhtml/default/default/template/optile/info.phtml +38 -0
  46. app/design/adminhtml/default/default/template/optile/notification_view.phtml +23 -0
  47. app/design/frontend/base/default/layout/optile/payment.xml +20 -0
  48. app/design/frontend/base/default/template/optile/info.phtml +27 -0
  49. app/design/frontend/base/default/template/optile/list.phtml +105 -65
  50. app/design/frontend/base/default/template/optile/list_error.phtml +17 -0
  51. app/etc/modules/Optile_Payment.xml +13 -16
  52. js/optile/checkout.js +563 -415
  53. js/optile/jquery.noconflict.js +13 -16
  54. js/optile/optilevalidation.js +71 -49
  55. lib/Optile/Client/optilevalidation.js +0 -185
  56. lib/Optile/Request/Account.php +42 -0
  57. lib/Optile/Request/Cache.php +50 -0
  58. lib/Optile/Request/Callback.php +42 -0
  59. lib/Optile/Request/CancelRequest.php +63 -0
  60. lib/Optile/Request/ChargeRequest.php +51 -0
  61. lib/Optile/Request/ClientInfo.php +37 -0
  62. lib/Optile/Request/CloseRequest.php +85 -0
  63. lib/Optile/Request/Component.php +159 -0
  64. lib/Optile/Request/Customer.php +121 -0
  65. lib/Optile/Request/Exception.php +46 -0
  66. lib/Optile/Request/ListRequest.php +138 -0
  67. lib/Optile/Request/Logger.php +51 -0
  68. lib/Optile/Request/Payment.php +42 -0
  69. lib/Optile/Request/PayoutRequest.php +58 -0
  70. lib/Optile/Request/Preselection.php +45 -0
  71. lib/Optile/Request/Product.php +59 -0
  72. lib/Optile/Request/ReloadListRequest.php +49 -0
  73. lib/Optile/Request/Request.php +211 -0
  74. lib/Optile/Request/RequestFactory.php +145 -0
  75. lib/Optile/Request/SimpleRequest.php +38 -0
  76. lib/Optile/Response/Entity.php +28 -0
  77. lib/Optile/{Server/Response/OptileInteraction.php → Response/Interaction.php} +39 -25
  78. lib/Optile/Response/Network.php +83 -0
  79. lib/Optile/{Server/Response/OptileNetworkLink.php → Response/NetworkLink.php} +50 -43
  80. lib/Optile/{Server/Response/OptileRedirect.php → Response/Redirect.php} +47 -36
  81. lib/Optile/Response/Response.php +88 -0
  82. lib/Optile/Response/ResponseFactory.php +157 -0
  83. lib/Optile/Server/Request/Entity.php +0 -23
  84. lib/Optile/Server/Request/OptileAccount.php +0 -157
  85. lib/Optile/Server/Request/OptileCallback.php +0 -59
  86. lib/Optile/Server/Request/OptileChargeRequest.php +0 -81
  87. lib/Optile/Server/Request/OptileConnection.php +0 -120
  88. lib/Optile/Server/Request/OptileCustomer.php +0 -51
  89. lib/Optile/Server/Request/OptileListRequest.php +0 -125
  90. lib/Optile/Server/Request/OptilePayment.php +0 -61
  91. lib/Optile/Server/Request/OptileProduct.php +0 -69
  92. lib/Optile/Server/Request/OptileReloadListRequest.php +0 -53
  93. lib/Optile/Server/Request/OptileRequest.php +0 -173
  94. lib/Optile/Server/Request/OptileUrlException.php +0 -23
  95. lib/Optile/Server/Request/RequestException.php +0 -33
  96. lib/Optile/Server/Request/Validator.php +0 -46
  97. lib/Optile/Server/Response/OptileNetwork.php +0 -78
  98. lib/Optile/Server/Response/OptileResponse.php +0 -83
  99. lib/Optile/Server/Response/OptileResponseEntity.php +0 -25
  100. lib/Optile/Server/Response/OptileResponseFactory.php +0 -108
  101. lib/Optile/Server/ValidationService.php +0 -59
  102. lib/Optile/Server/optile.sdk.lib.inc.php +0 -46
  103. package.xml +19 -1
  104. skin/frontend/base/default/optile/css/style.css +132 -0
app/code/community/Optile/Payment/Block/Adminhtml/Notification.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
14
+ *
15
+ * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
+ */
19
+
20
+ class Optile_Payment_Block_Adminhtml_Notification extends Mage_Adminhtml_Block_Widget_Grid_Container
21
+ {
22
+ public function __construct()
23
+ {
24
+ $this->_blockGroup = 'optile';
25
+ $this->_controller = 'adminhtml_notification';
26
+ $this->_headerText = Mage::helper('optile')->__('optile IPNs');
27
+ parent::__construct();
28
+ $this->_removeButton('add');
29
+ }
30
+
31
+ }
app/code/community/Optile/Payment/Block/Adminhtml/Notification/Grid.php ADDED
@@ -0,0 +1,163 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
14
+ *
15
+ * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
+ */
19
+
20
+ class Optile_Payment_Block_Adminhtml_Notification_Grid extends Mage_Adminhtml_Block_Widget_Grid
21
+ {
22
+
23
+ public function __construct()
24
+ {
25
+ parent::__construct();
26
+ $this->setId('optile_notification_grid');
27
+ $this->setUseAjax(true);
28
+ $this->setDefaultSort('id');
29
+ $this->setDefaultDir('DESC');
30
+ $this->setSaveParametersInSession(true);
31
+ }
32
+
33
+ protected function _prepareCollection()
34
+ {
35
+ $collection = Mage::getResourceModel('optile/notification_collection');
36
+ /* @var $collection Mage_Sales_Model_Resource_Order_Grid_Collection */
37
+
38
+ $collection->getSelect()
39
+ ->joinLeft(
40
+ array('oo' => $collection->getTable('optile/quote')),
41
+ 'oo.transaction_id = main_table.transaction_id',
42
+ array('monitor_link')
43
+ );
44
+
45
+ $this->setCollection($collection);
46
+ return parent::_prepareCollection();
47
+ }
48
+
49
+ protected function _prepareColumns()
50
+ {
51
+ $this->addColumn('id', array(
52
+ 'header'=> Mage::helper('sales')->__('Notification #'),
53
+ 'width' => '80px',
54
+ 'type' => 'text',
55
+ 'index' => 'id'
56
+ ));
57
+
58
+ $this->addColumn('transaction_id', array(
59
+ 'header'=> Mage::helper('sales')->__('Transaction #'),
60
+ 'width' => '80px',
61
+ 'type' => 'text',
62
+ 'index' => 'transaction_id',
63
+ 'filter_index' => 'main_table.transaction_id'
64
+ ));
65
+
66
+ $this->addColumn('date', array(
67
+ 'header' => Mage::helper('sales')->__('Date received'),
68
+ 'index' => 'date',
69
+ 'type' => 'datetime',
70
+ 'width' => '160px',
71
+ ));
72
+
73
+ $this->addColumn('long_id', array(
74
+ 'header' => Mage::helper('optile')->__('Optile Long Id'),
75
+ 'renderer' => 'optile/adminhtml_widget_grid_column_renderer_url',
76
+ 'index' => 'long_id',
77
+ 'filter_index' => 'main_table.long_id',
78
+ 'url_index' => 'monitor_link',
79
+ 'attributes' => array(
80
+ 'title' => 'View in optile Monitor',
81
+ 'target' => '_blank',
82
+ ),
83
+ ));
84
+
85
+ // $this->addColumn('network', array(
86
+ // 'header' => Mage::helper('sales')->__('Payment network'),
87
+ // 'index' => 'network'
88
+ // ));
89
+
90
+ // $this->addColumn('currency', array(
91
+ // 'header' => Mage::helper('sales')->__('Currency'),
92
+ // 'index' => 'currency'
93
+ // ));
94
+
95
+ // $this->addColumn('amount', array(
96
+ // 'header' => Mage::helper('sales')->__('Amount'),
97
+ // 'type' => 'number',
98
+ // 'index' => 'amount',
99
+ // ));
100
+
101
+
102
+ $this->addColumn('return_code', array(
103
+ 'header' => Mage::helper('sales')->__('Return code'),
104
+ 'index' => 'return_code',
105
+ ));
106
+ $this->addColumn('interaction_code', array(
107
+ 'header' => Mage::helper('sales')->__('Interaction code'),
108
+ 'index' => 'interaction_code',
109
+ ));
110
+ $this->addColumn('reason_code', array(
111
+ 'header' => Mage::helper('sales')->__('Reason code'),
112
+ 'index' => 'reason_code',
113
+ ));
114
+ $this->addColumn('result_info', array(
115
+ 'header' => Mage::helper('sales')->__('Result info'),
116
+ 'index' => 'result_info',
117
+ ));
118
+
119
+ $this->addColumn('status', array(
120
+ 'header' => Mage::helper('sales')->__('Status code returned to Optile'),
121
+ 'type' => 'number',
122
+ 'index' => 'status',
123
+ ));
124
+
125
+
126
+ $this->addColumn('action', array(
127
+ 'header' => Mage::helper('optile')->__('IPN Process again'),
128
+ 'width' => '50px',
129
+ 'type' => 'action',
130
+ 'getter' => 'getId',
131
+ 'actions' => array(
132
+ array(
133
+ 'caption' => Mage::helper('optile')->__('Process IPN again'),
134
+ 'url' =>
135
+ array(
136
+ 'base' => '*/*/reprocess',
137
+ ),
138
+ 'field' => 'id'
139
+ ),
140
+ ),
141
+ 'filter' => false,
142
+ 'sortable' => false,
143
+ ));
144
+
145
+
146
+
147
+ $this->addExportType('*/*/exportCsv', Mage::helper('sales')->__('CSV'));
148
+ $this->addExportType('*/*/exportExcel', Mage::helper('sales')->__('Excel XML'));
149
+
150
+ return parent::_prepareColumns();
151
+ }
152
+
153
+ public function getRowUrl($row)
154
+ {
155
+ return $this->getUrl('*/*/view', array('notification_id' => $row->getId()));
156
+ }
157
+
158
+ public function getGridUrl()
159
+ {
160
+ return $this->getUrl('*/*/grid', array('_current'=>true));
161
+ }
162
+
163
+ }
app/code/community/Optile/Payment/Block/Adminhtml/Notification/View.php ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Optile_Payment_Block_Adminhtml_Notification_View extends Mage_Core_Block_Template {
3
+
4
+
5
+ private $notification = null;
6
+
7
+ public function getNotification(){
8
+ if($this->notification == null){
9
+ $this->notification = Mage::getModel('optile/notification')->load($this->getNotificationId());
10
+ }
11
+ return $this->notification;
12
+ }
13
+
14
+ }
app/code/community/Optile/Payment/Block/Adminhtml/Order.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
14
+ *
15
+ * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
+ */
19
+
20
+ class Optile_Payment_Block_Adminhtml_Order extends Mage_Adminhtml_Block_Widget_Grid_Container
21
+ {
22
+ public function __construct()
23
+ {
24
+ $this->_blockGroup = 'optile';
25
+ $this->_controller = 'adminhtml_order';
26
+ $this->_headerText = Mage::helper('optile')->__('optile Orders');
27
+ parent::__construct();
28
+ $this->_removeButton('add');
29
+ }
30
+
31
+ }
app/code/community/Optile/Payment/Block/Adminhtml/Order/Creditmemo/Create/Items.php ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
14
+ *
15
+ * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
+ */
19
+
20
+ class Optile_Payment_Block_Adminhtml_Order_Creditmemo_Create_Items extends Mage_Adminhtml_Block_Sales_Order_Creditmemo_Create_Items
21
+ {
22
+
23
+ /**
24
+ * Prepare child blocks
25
+ *
26
+ * @return Mage_Adminhtml_Block_Sales_Order_Creditmemo_Create_Items
27
+ */
28
+ protected function _prepareLayout()
29
+ {
30
+ if($this->getOrder()->getPayment()->getMethodInstance()->getCode() !== 'optile') return parent::_prepareLayout();
31
+
32
+ $layout = parent::_prepareLayout();
33
+
34
+ $onclick = "submitAndReloadArea($('creditmemo_item_container'),'".$this->getUpdateUrl()."')";
35
+ $this->setChild(
36
+ 'update_button',
37
+ $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array(
38
+ 'label' => Mage::helper('sales')->__('Update Qty\'s'),
39
+ 'class' => 'update-button',
40
+ 'onclick' => $onclick,
41
+ ))
42
+ );
43
+
44
+ if ($this->getCreditmemo()->canRefund()) {
45
+ if ($this->getCreditmemo()->getInvoice() && $this->getCreditmemo()->getInvoice()->getTransactionId()) {
46
+ if(Mage::getStoreConfig('payment/optile/refund_enabled')) {
47
+ $this->setChild(
48
+ 'submit_button',
49
+ $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array(
50
+ 'label' => Mage::helper('sales')->__('Refund Online via Optile'),
51
+ 'class' => 'save submit-button',
52
+ 'onclick' => 'disableElements(\'submit-button\');submitCreditMemo()',
53
+ ))
54
+ );
55
+ } else {
56
+ $this->unsetChild('submit_button');
57
+ }
58
+ }
59
+ $this->setChild(
60
+ 'submit_offline',
61
+ $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array(
62
+ 'label' => Mage::helper('sales')->__('Refund Offline'),
63
+ 'class' => 'save submit-button back',
64
+ 'onclick' => 'disableElements(\'submit-button\');submitCreditMemoOffline()',
65
+ ))
66
+ );
67
+
68
+ }
69
+ else {
70
+ $this->setChild(
71
+ 'submit_button',
72
+ $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array(
73
+ 'label' => Mage::helper('sales')->__('Refund Offline'),
74
+ 'class' => 'save submit-button back',
75
+ 'onclick' => 'disableElements(\'submit-button\');submitCreditMemoOffline()',
76
+ ))
77
+ );
78
+ }
79
+
80
+ return $layout;
81
+ }
82
+
83
+ }
app/code/community/Optile/Payment/Block/Adminhtml/Order/Grid.php ADDED
@@ -0,0 +1,219 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
14
+ *
15
+ * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
+ */
19
+
20
+ class Optile_Payment_Block_Adminhtml_Order_Grid extends Mage_Adminhtml_Block_Widget_Grid
21
+ {
22
+
23
+ public function __construct()
24
+ {
25
+ parent::__construct();
26
+ $this->setId('optile_order_grid');
27
+ $this->setUseAjax(true);
28
+ $this->setDefaultSort('created_at');
29
+ $this->setDefaultDir('DESC');
30
+ $this->setSaveParametersInSession(true);
31
+ }
32
+
33
+ protected function _prepareCollection()
34
+ {
35
+ $collection = Mage::getResourceModel('sales/order_grid_collection');
36
+ /* @var $collection Mage_Sales_Model_Resource_Order_Grid_Collection */
37
+
38
+ // Hardcoding fields here, so as not to be wasteful with memory.
39
+ $collection->getSelect()
40
+ ->reset(Varien_Db_Select::COLUMNS)
41
+ ->columns(array(
42
+ 'entity_id',
43
+ 'increment_id',
44
+ 'created_at',
45
+ 'grand_total',
46
+ 'order_currency_code',
47
+ 'status',
48
+ 'billing_name',
49
+ ))
50
+ ->join(
51
+ array('sfo' => $collection->getTable('sales/order')),
52
+ 'sfo.entity_id = main_table.entity_id',
53
+ array()
54
+ )
55
+ ->join(
56
+ array('oq' => $collection->getTable('optile/quote')),
57
+ 'oq.transaction_id = sfo.quote_id',
58
+ array('transaction_id', 'long_id', 'monitor_link', 'payment_network')
59
+ )
60
+ ->join(
61
+ array('pmt' => $collection->getTable('sales/order_payment')),
62
+ 'pmt.parent_id = main_table.entity_id',
63
+ array()
64
+ )
65
+ ->where('pmt.method = "optile"')
66
+ ;
67
+ $this->setCollection($collection);
68
+ return parent::_prepareCollection();
69
+ }
70
+
71
+ protected function _prepareColumns()
72
+ {
73
+ $this->addColumn('increment_id', array(
74
+ 'header'=> Mage::helper('sales')->__('Order #'),
75
+ 'width' => '80px',
76
+ 'type' => 'text',
77
+ 'index' => 'increment_id',
78
+ 'filter_index' => 'main_table.increment_id',
79
+ ));
80
+
81
+ $this->addColumn('transaction_id', array(
82
+ 'header'=> Mage::helper('optile')->__('Transaction #'),
83
+ 'width' => '80px',
84
+ 'type' => 'text',
85
+ 'index' => 'transaction_id',
86
+ 'filter_index' => 'oq.transaction_id',
87
+ ));
88
+
89
+ $this->addColumn('long_id', array(
90
+ 'header' => Mage::helper('optile')->__('optile Long Id'),
91
+ 'renderer' => 'optile/adminhtml_widget_grid_column_renderer_url',
92
+ 'index' => 'long_id',
93
+ 'filter_index' => 'oq.long_id',
94
+ 'url_index' => 'monitor_link',
95
+ 'attributes' => array(
96
+ 'title' => 'View in optile Monitor',
97
+ 'target' => '_blank',
98
+ ),
99
+ ));
100
+
101
+ $this->addColumn('created_at', array(
102
+ 'header' => Mage::helper('sales')->__('Purchased On'),
103
+ 'index' => 'created_at',
104
+ 'filter_index' => 'main_table.created_at',
105
+ 'type' => 'datetime',
106
+ 'width' => '160px',
107
+ ));
108
+
109
+ $this->addColumn('billing_name', array(
110
+ 'header' => Mage::helper('sales')->__('Bill to Name'),
111
+ 'index' => 'billing_name',
112
+ 'filter_index' => 'main_table.billing_name',
113
+ ));
114
+
115
+ $this->addColumn('grand_total', array(
116
+ 'header' => Mage::helper('sales')->__('G.T. (Purchased)'),
117
+ 'index' => 'grand_total',
118
+ 'filter_index' => 'main_table.grand_total',
119
+ 'type' => 'currency',
120
+ 'currency' => 'order_currency_code',
121
+ ));
122
+
123
+ $this->addColumn('status', array(
124
+ 'header' => Mage::helper('sales')->__('Status'),
125
+ 'index' => 'status',
126
+ 'filter_index' => 'main_table.status',
127
+ 'type' => 'options',
128
+ 'width' => '100px',
129
+ 'options' => Mage::getSingleton('sales/order_config')->getStatuses(),
130
+ ));
131
+
132
+ $this->addColumn('payment_network', array(
133
+ 'header' => Mage::helper('optile')->__('Payment Network'),
134
+ 'index' => 'payment_network',
135
+ 'filter_index' => 'oq.payment_network',
136
+ 'width' => '70px',
137
+ ));
138
+ if(Mage::getIsDeveloperMode()){
139
+ $this->addDeveloperColumns();
140
+ }
141
+
142
+ $this->addExportType('*/*/exportCsv', Mage::helper('sales')->__('CSV'));
143
+ $this->addExportType('*/*/exportExcel', Mage::helper('sales')->__('Excel XML'));
144
+
145
+ return parent::_prepareColumns();
146
+ }
147
+
148
+ public function getRowUrl($row)
149
+ {
150
+ if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/view')) {
151
+ return $this->getUrl('*/sales_order/view', array('order_id' => $row->getId()));
152
+ }
153
+ return false;
154
+ }
155
+
156
+ public function getGridUrl()
157
+ {
158
+ return $this->getUrl('*/*/grid', array('_current'=>true));
159
+ }
160
+
161
+ private function addDeveloperColumns(){
162
+ $this->addColumn('action', array(
163
+ 'header' => Mage::helper('optile')->__('IPN Simulate Action'),
164
+ 'width' => '50px',
165
+ 'type' => 'action',
166
+ 'getter' => 'getTransactionId',
167
+ 'actions' => array(
168
+ array(
169
+ 'caption' => Mage::helper('optile')->__('Simulate preauthorization canceled'),
170
+ 'url' =>
171
+ array(
172
+ 'base' => '*/*/simulate',
173
+ 'params' => array('status_code'=>'canceled', 'reason_code'=>'preauthorization_canceled')
174
+ ),
175
+ 'field' => 'transaction_id'
176
+ ),
177
+ array(
178
+ 'caption' => Mage::helper('optile')->__('Simulate preauthorization expired'),
179
+ 'url' =>
180
+ array(
181
+ 'base' => '*/*/simulate',
182
+ 'params' => array('status_code'=>'expired', 'reason_code'=>'preauthorization_expired')
183
+ ),
184
+ 'field' => 'transaction_id'
185
+ ),
186
+ array(
187
+ 'caption' => Mage::helper('optile')->__('Simulate preauthorization declined'),
188
+ 'url' =>
189
+ array(
190
+ 'base' => '*/*/simulate',
191
+ 'params' => array('status_code'=>'declined', 'reason_code'=>'preauthorization_declined')
192
+ ),
193
+ 'field' => 'transaction_id'
194
+ ),
195
+ array(
196
+ 'caption' => Mage::helper('optile')->__('Simulate preauthorization failed'),
197
+ 'url' =>
198
+ array(
199
+ 'base' => '*/*/simulate',
200
+ 'params' => array('status_code'=>'failed', 'reason_code'=>'preauthorization_failed')
201
+ ),
202
+ 'field' => 'transaction_id'
203
+ ),
204
+ array(
205
+ 'caption' => Mage::helper('optile')->__('Simulate preauthorized VISA'),
206
+ 'url' =>
207
+ array(
208
+ 'base' => '*/*/simulate',
209
+ 'params' => array('status_code'=>'preauthorized', 'reason_code'=>'preauthorized', 'network'=>'VISA')
210
+ ),
211
+ 'field' => 'transaction_id'
212
+ ),
213
+ ),
214
+ 'filter' => false,
215
+ 'sortable' => false,
216
+ ));
217
+ }
218
+
219
+ }
app/code/community/Optile/Payment/Block/Adminhtml/Order/View.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
14
+ *
15
+ * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
+ */
19
+
20
+ class Optile_Payment_Block_Adminhtml_Order_View extends Mage_Adminhtml_Block_Sales_Order_View
21
+ {
22
+
23
+ public function __construct() {
24
+ parent::__construct();
25
+
26
+ if($this->getOrder()->getPayment()->getMethodInstance()->getCode() !== 'optile') return;
27
+
28
+ $this->_removeButton('order_creditmemo');
29
+ }
30
+
31
+ }
app/code/community/Optile/Payment/Block/Adminhtml/System/Config/Frontend/Instructions.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ //error_reporting(E_ALL | E_STRICT);
4
+ //Mage::setIsDeveloperMode(true);
5
+ //ini_set('display_errors', 1);
6
+
7
+ /**
8
+ * @author frans
9
+ */
10
+ class Optile_Payment_Block_Adminhtml_System_Config_Frontend_Instructions
11
+ extends Mage_Adminhtml_Block_System_Config_Form_Field_Array_Abstract
12
+ {
13
+ protected $_textareaRenderer;
14
+
15
+ protected function _prepareToRender() {
16
+ $this->addColumn('payment_method', array(
17
+ 'label' => Mage::helper('adminhtml')->__('Payment Method'),
18
+ 'style' => 'width:120px',
19
+ ));
20
+ $this->addColumn('value', array(
21
+ 'label' => Mage::helper('adminhtml')->__('Instructions'),
22
+ 'renderer' => $this->_getTextareaRenderer(),
23
+ ));
24
+ $this->_addAfter = false;
25
+ $this->_addButtonLabel = Mage::helper('adminhtml')->__('Add instructions');
26
+ }
27
+
28
+ protected function _getTextareaRenderer() {
29
+ if ($this->_textareaRenderer === null) {
30
+ $this->_textareaRenderer = $this->getLayout()->createBlock(
31
+ 'optile/adminhtml_system_config_frontend_instructions_textarea'
32
+ );
33
+ // $this->_textareaRenderer->setClass('input-textarea');
34
+ // $this->_textareaRenderer->setExtraParams('style="width:120px"');
35
+ }
36
+
37
+ return $this->_textareaRenderer;
38
+ }
39
+ }
app/code/community/Optile/Payment/Block/Adminhtml/System/Config/Frontend/Instructions/Textarea.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ //error_reporting(E_ALL | E_STRICT);
4
+ //Mage::setIsDeveloperMode(true);
5
+ //ini_set('display_errors', 1);
6
+
7
+ /**
8
+ * @author frans
9
+ */
10
+ class Optile_Payment_Block_Adminhtml_System_Config_Frontend_Instructions_TextArea
11
+ extends Mage_Core_Block_Abstract
12
+ {
13
+ protected function _toHtml() {
14
+ $inputName = $this->getInputName();
15
+ $columnName = $this->getColumnName();
16
+ $column = $this->getColumn();
17
+
18
+ return '<textarea name="'. $inputName .'"'.
19
+ ($column['size'] ? 'size="'. $column['size'] .'"' : '') .' class="'.
20
+ (isset($column['class']) ? $column['class'] : 'input-textarea') .'"'.
21
+ (isset($column['style']) ? ' style="'. $column['style'] .'"' : '') .'>'.
22
+ '#{'. $columnName .'}</textarea>';
23
+ }
24
+ }
app/code/community/Optile/Payment/Block/Adminhtml/System/Config/Frontend/Noactivemethods.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
14
+ *
15
+ * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
+ */
19
+
20
+ /**
21
+ * Custom rendering to remove some of the clutter on what should be just a label.
22
+ */
23
+ class Optile_Payment_Block_Adminhtml_System_Config_Frontend_Noactivemethods
24
+ extends Mage_Adminhtml_Block_System_Config_Form_Field
25
+ {
26
+ public function render(Varien_Data_Form_Element_Abstract $element)
27
+ {
28
+ $id = $element->getHtmlId();
29
+
30
+ $html = '<td class="label"><label for="'.$id.'">'.$element->getLabel().'</label></td>';
31
+
32
+ if ($element->getTooltip()) {
33
+ $html .= '<td class="value with-tooltip">';
34
+ $html .= $this->_getElementHtml($element);
35
+ $html .= '<div class="field-tooltip"><div>' . $element->getTooltip() . '</div></div>';
36
+ } else {
37
+ $html .= '<td class="value">';
38
+ $html .= $this->_getElementHtml($element);
39
+ };
40
+ if ($element->getComment()) {
41
+ $html.= '<p class="note"><span>'.$element->getComment().'</span></p>';
42
+ }
43
+ $html.= '</td>';
44
+
45
+ $html.= '<td class="" />';
46
+ $html.= '<td class="" />';
47
+
48
+ return $this->_decorateRowHtml($element, $html);
49
+ }
50
+ }
app/code/community/Optile/Payment/Block/Adminhtml/Widget/Grid/Column/Renderer/Url.php ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
14
+ *
15
+ * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
+ */
19
+
20
+ class Optile_Payment_Block_Adminhtml_Widget_Grid_Column_Renderer_Url
21
+ extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
22
+ {
23
+ /**
24
+ * Renders grid column - a URL, a bit like Action. This one allows external
25
+ * locations though.
26
+ *
27
+ * @param Varien_Object $row
28
+ * @return string
29
+ */
30
+ public function render(Varien_Object $row) {
31
+ $actionAttributes = new Varien_Object();
32
+ $attr = (array)$this->getColumn()->getAttributes();
33
+
34
+ $value = $this->_getValue($row);
35
+
36
+ if ($this->getColumn()->hasUrlFormat()) {
37
+ $attr['href'] = sprintf($this->getColumn()->getUrlFormat(), $value);
38
+ }
39
+ elseif ($this->getColumn()->hasUrlIndex()) {
40
+ $attr['href'] = $row->getData($this->getColumn()->getUrlIndex());
41
+ }
42
+
43
+ if (!isset($attr['href']) || !$attr['href']) {
44
+ return $value;
45
+ }
46
+
47
+ if ($this->getColumn()->getPopup()) {
48
+ $attr['onclick'] =
49
+ 'popWin(this.href,\'_blank\',\'width=800,height=700,resizable=1,scrollbars=1\');return false;';
50
+ }
51
+
52
+
53
+ $actionAttributes->setData($attr);
54
+ $html = '<a ' . $actionAttributes->serialize() . '>' . $value . '</a>';
55
+
56
+ return $html;
57
+ }
58
+
59
+ }
app/code/community/Optile/Payment/Block/Info.php ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
14
+ *
15
+ * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
+ */
19
+
20
+ class Optile_Payment_Block_Info extends Mage_Payment_Block_Info
21
+ {
22
+
23
+ protected function _construct()
24
+ {
25
+ parent::_construct();
26
+ $this->setTemplate('optile/info.phtml');
27
+ }
28
+
29
+ /**
30
+ * Get some specific information in format of array($label => $value)
31
+ *
32
+ * @return array
33
+ */
34
+ public function getSpecificInformation() {
35
+ $info = (array)parent::getSpecificInformation();
36
+
37
+ $order = $this->getInfo()->getOrder();
38
+
39
+ if ($order !== null) {
40
+ $quoteId = $order->getQuoteId();
41
+ $store_id = $order->getStoreId();
42
+ } else {
43
+ $quoteId = $this->getInfo()->getQuote()->getId();
44
+ $store_id = $this->getInfo()->getQuote()->getStoreId();
45
+ }
46
+
47
+ $optileQuote = Mage::getModel('optile/quote')->load($quoteId);
48
+ $network = $optileQuote->getPaymentNetwork();
49
+ $instructions = unserialize(Mage::getStoreConfig('payment/optile/instructions', $store_id));
50
+
51
+ if (is_array($instructions)) {
52
+ foreach ($instructions as $instruction) {
53
+ if (strtolower($instruction['payment_method']) == strtolower($network)) {
54
+ $this->setInstructions($instruction['value']);
55
+ break;
56
+ }
57
+ }
58
+ }
59
+
60
+ $info['Payment Network'] = $network;
61
+ $info['Optile Long Id'] = $optileQuote->getLongId();
62
+
63
+ return $info;
64
+ }
65
+ }
app/code/community/Optile/Payment/Block/List.php CHANGED
@@ -1,23 +1,20 @@
1
  <?php
2
  /**
3
- * This file is part of the Optile Payment Connector extension.
4
- *
5
- * Optile Payment Connector is free software: you can redistribute it and/or
6
- * modify it under the terms of the GNU General Public License as published
7
- * by the Free Software Foundation, either version 3 of the License, or
8
- * (at your option) any later version.
9
- *
10
- * Optile Payment Connector is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License along with
16
- * Optile Payment Connector. If not, see <http://www.gnu.org/licenses/>.
17
  *
18
  * @author i-Ways <dev@i-ways.hr>
19
- * @copyright Copyright (c) 2013 Optile. (http://www.optile.de)
20
- * @license http://www.gnu.org/licenses/gpl.txt
21
  */
22
 
23
  /**
@@ -25,17 +22,13 @@
25
  *
26
  */
27
  class Optile_Payment_Block_List extends Mage_Payment_Block_Form {
28
-
29
  /**
30
  * payment method code
31
  */
32
  protected $_methodCode = 'optile';
33
-
34
- /**
35
- * Logging filename
36
- */
37
- protected $_logFileName = 'optile.log';
38
-
39
  /**
40
  * Block constructor
41
  */
@@ -43,24 +36,25 @@ class Optile_Payment_Block_List extends Mage_Payment_Block_Form {
43
  $this->setTemplate ( 'optile/list.phtml' );
44
  parent::__construct ();
45
  }
46
-
47
- /**
48
- * Returns whether logging is enabled
49
- */
50
- private function isLogEnabled() {
51
- return Mage::getStoreConfig ( 'payment/optile/log_enabled', Mage::app ()->getStore () );
52
- }
53
-
54
- /**
55
- * Logging helper
56
- * @param unknown $what thing to log
57
- * @param string $level log level
58
- */
59
- public function log($what, $level = null) {
60
- if ($this->isLogEnabled ())
61
- Mage::log ( $what, $level, $file = $this->_logFileName, true );
62
- }
63
-
 
64
  /**
65
  * Adds optilevalidation.js into <script> when block is shown
66
  */
@@ -69,31 +63,36 @@ class Optile_Payment_Block_List extends Mage_Payment_Block_Form {
69
  // $this->getLayout ()->getBlock ( 'head' )->addJs ( 'optile/optilevalidation.js' );
70
  // $this->getLayout ()->getBlock ( 'head' )->addJs ( 'optile/checkout.js' );
71
  }
72
-
73
  return parent::_prepareLayout ();
74
  }
75
 
 
 
 
 
 
 
 
 
76
  /**
77
  * Returns available networks to render in html
78
- *
79
  * ----
80
  * If optile charge request responds with RETRY/TRY_OTHER_ACCOUNT/TRY_OTHER_NETWORK,
81
  * existing list request will be refreshed through listRequestSelfLink sent
82
  * by AJAX in checkout.js
83
  */
84
- public function getListResponse() {
85
- $listRequestSelfLink = Mage::app ()->getRequest ()->getParam ( 'listRequestSelfLink', null );
86
-
87
- $quote = Mage::getSingleton ( 'checkout/type_onepage' )->getQuote ();
88
- $optile = Mage::getModel ( 'optile/checkout', array (
89
- 'quote' => $quote,
90
- 'listRequestSelfLink' => $listRequestSelfLink
91
- ) );
92
- $response = $optile->requestAvailableNetworks ();
93
-
94
  return $response;
95
  }
96
-
97
  /**
98
  * Prepares optile payment network form, replaces ${formId} with our form id
99
  * @param unknown $form
@@ -101,19 +100,29 @@ class Optile_Payment_Block_List extends Mage_Payment_Block_Form {
101
  * @return mixed
102
  */
103
  public function renderFormHtml($form, $form_id) {
104
- return str_replace ( '${formId}', $form_id, $form );
 
 
 
 
 
 
 
 
 
 
105
  }
106
 
107
  /**
108
  * Returns form id for network code
109
- *
110
  * E.g. if networkcode is 'VISA', return 'optile-VISA'
111
- *
112
  * @param unknown $networkCode
113
  * @return string
114
  */
115
  public function getFormId($networkCode) {
116
- return $this->getMethodCode () . '-' . $networkCode;
117
  }
118
 
119
  }
1
  <?php
2
  /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
 
 
 
14
  *
15
  * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
  */
19
 
20
  /**
22
  *
23
  */
24
  class Optile_Payment_Block_List extends Mage_Payment_Block_Form {
25
+
26
  /**
27
  * payment method code
28
  */
29
  protected $_methodCode = 'optile';
30
+ protected $_listResponse = null;
31
+
 
 
 
 
32
  /**
33
  * Block constructor
34
  */
36
  $this->setTemplate ( 'optile/list.phtml' );
37
  parent::__construct ();
38
  }
39
+
40
+ public function _toHtml() {
41
+ Mage::helper('optile')->log("Doing _toHTML method");
42
+ // check if there is sufficient data to execute List request
43
+
44
+ try{
45
+ $response = $this->getListResponse();
46
+
47
+ if($response->getInteraction()->getCode() != "PROCEED"){
48
+ $this->setTemplate ( 'optile/list_error.phtml' );
49
+ }
50
+ }catch (Exception $e){
51
+ Mage::helper("optile")->log("Exception during LIST:");
52
+ Mage::helper("optile")->log($e->getMessage());
53
+ $this->setTemplate ( 'optile/list_error.phtml' );
54
+ }
55
+ return parent::_toHtml();
56
+ }
57
+
58
  /**
59
  * Adds optilevalidation.js into <script> when block is shown
60
  */
63
  // $this->getLayout ()->getBlock ( 'head' )->addJs ( 'optile/optilevalidation.js' );
64
  // $this->getLayout ()->getBlock ( 'head' )->addJs ( 'optile/checkout.js' );
65
  }
66
+
67
  return parent::_prepareLayout ();
68
  }
69
 
70
+ public function getListResponse(){
71
+ if($this->_listResponse === null){
72
+ $this->_listResponse = $this->_getListResponse();
73
+ }
74
+
75
+ return $this->_listResponse;
76
+ }
77
+
78
  /**
79
  * Returns available networks to render in html
80
+ *
81
  * ----
82
  * If optile charge request responds with RETRY/TRY_OTHER_ACCOUNT/TRY_OTHER_NETWORK,
83
  * existing list request will be refreshed through listRequestSelfLink sent
84
  * by AJAX in checkout.js
85
  */
86
+ public function _getListResponse() {
87
+
88
+ $listRequestSelfLink = Mage::app()->getRequest()->getParam('listRequestSelfLink');
89
+
90
+ $optile = Mage::getModel('optile/checkout');
91
+ $response = $optile->requestAvailableNetworks($listRequestSelfLink);
92
+
 
 
 
93
  return $response;
94
  }
95
+
96
  /**
97
  * Prepares optile payment network form, replaces ${formId} with our form id
98
  * @param unknown $form
100
  * @return mixed
101
  */
102
  public function renderFormHtml($form, $form_id) {
103
+
104
+ return str_replace (
105
+ array(
106
+ 'function ${formId}_WhatIsPayPal()', //T: temporary fix to avoid AJAX issues with Prototype
107
+ '${formId}',
108
+ ),
109
+ array(
110
+ '${formId}_WhatIsPayPal = function()', //T: temporary fix to avoid AJAX issues with Prototype
111
+ $form_id,
112
+ ),
113
+ $form );
114
  }
115
 
116
  /**
117
  * Returns form id for network code
118
+ *
119
  * E.g. if networkcode is 'VISA', return 'optile-VISA'
120
+ *
121
  * @param unknown $networkCode
122
  * @return string
123
  */
124
  public function getFormId($networkCode) {
125
+ return $this->getMethodCode () . '_' . $networkCode;
126
  }
127
 
128
  }
app/code/community/Optile/Payment/COPYING DELETED
@@ -1,675 +0,0 @@
1
-
2
- GNU GENERAL PUBLIC LICENSE
3
- Version 3, 29 June 2007
4
-
5
- Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
6
- Everyone is permitted to copy and distribute verbatim copies
7
- of this license document, but changing it is not allowed.
8
-
9
- Preamble
10
-
11
- The GNU General Public License is a free, copyleft license for
12
- software and other kinds of works.
13
-
14
- The licenses for most software and other practical works are designed
15
- to take away your freedom to share and change the works. By contrast,
16
- the GNU General Public License is intended to guarantee your freedom to
17
- share and change all versions of a program--to make sure it remains free
18
- software for all its users. We, the Free Software Foundation, use the
19
- GNU General Public License for most of our software; it applies also to
20
- any other work released this way by its authors. You can apply it to
21
- your programs, too.
22
-
23
- When we speak of free software, we are referring to freedom, not
24
- price. Our General Public Licenses are designed to make sure that you
25
- have the freedom to distribute copies of free software (and charge for
26
- them if you wish), that you receive source code or can get it if you
27
- want it, that you can change the software or use pieces of it in new
28
- free programs, and that you know you can do these things.
29
-
30
- To protect your rights, we need to prevent others from denying you
31
- these rights or asking you to surrender the rights. Therefore, you have
32
- certain responsibilities if you distribute copies of the software, or if
33
- you modify it: responsibilities to respect the freedom of others.
34
-
35
- For example, if you distribute copies of such a program, whether
36
- gratis or for a fee, you must pass on to the recipients the same
37
- freedoms that you received. You must make sure that they, too, receive
38
- or can get the source code. And you must show them these terms so they
39
- know their rights.
40
-
41
- Developers that use the GNU GPL protect your rights with two steps:
42
- (1) assert copyright on the software, and (2) offer you this License
43
- giving you legal permission to copy, distribute and/or modify it.
44
-
45
- For the developers' and authors' protection, the GPL clearly explains
46
- that there is no warranty for this free software. For both users' and
47
- authors' sake, the GPL requires that modified versions be marked as
48
- changed, so that their problems will not be attributed erroneously to
49
- authors of previous versions.
50
-
51
- Some devices are designed to deny users access to install or run
52
- modified versions of the software inside them, although the manufacturer
53
- can do so. This is fundamentally incompatible with the aim of
54
- protecting users' freedom to change the software. The systematic
55
- pattern of such abuse occurs in the area of products for individuals to
56
- use, which is precisely where it is most unacceptable. Therefore, we
57
- have designed this version of the GPL to prohibit the practice for those
58
- products. If such problems arise substantially in other domains, we
59
- stand ready to extend this provision to those domains in future versions
60
- of the GPL, as needed to protect the freedom of users.
61
-
62
- Finally, every program is threatened constantly by software patents.
63
- States should not allow patents to restrict development and use of
64
- software on general-purpose computers, but in those that do, we wish to
65
- avoid the special danger that patents applied to a free program could
66
- make it effectively proprietary. To prevent this, the GPL assures that
67
- patents cannot be used to render the program non-free.
68
-
69
- The precise terms and conditions for copying, distribution and
70
- modification follow.
71
-
72
- TERMS AND CONDITIONS
73
-
74
- 0. Definitions.
75
-
76
- "This License" refers to version 3 of the GNU General Public License.
77
-
78
- "Copyright" also means copyright-like laws that apply to other kinds of
79
- works, such as semiconductor masks.
80
-
81
- "The Program" refers to any copyrightable work licensed under this
82
- License. Each licensee is addressed as "you". "Licensees" and
83
- "recipients" may be individuals or organizations.
84
-
85
- To "modify" a work means to copy from or adapt all or part of the work
86
- in a fashion requiring copyright permission, other than the making of an
87
- exact copy. The resulting work is called a "modified version" of the
88
- earlier work or a work "based on" the earlier work.
89
-
90
- A "covered work" means either the unmodified Program or a work based
91
- on the Program.
92
-
93
- To "propagate" a work means to do anything with it that, without
94
- permission, would make you directly or secondarily liable for
95
- infringement under applicable copyright law, except executing it on a
96
- computer or modifying a private copy. Propagation includes copying,
97
- distribution (with or without modification), making available to the
98
- public, and in some countries other activities as well.
99
-
100
- To "convey" a work means any kind of propagation that enables other
101
- parties to make or receive copies. Mere interaction with a user through
102
- a computer network, with no transfer of a copy, is not conveying.
103
-
104
- An interactive user interface displays "Appropriate Legal Notices"
105
- to the extent that it includes a convenient and prominently visible
106
- feature that (1) displays an appropriate copyright notice, and (2)
107
- tells the user that there is no warranty for the work (except to the
108
- extent that warranties are provided), that licensees may convey the
109
- work under this License, and how to view a copy of this License. If
110
- the interface presents a list of user commands or options, such as a
111
- menu, a prominent item in the list meets this criterion.
112
-
113
- 1. Source Code.
114
-
115
- The "source code" for a work means the preferred form of the work
116
- for making modifications to it. "Object code" means any non-source
117
- form of a work.
118
-
119
- A "Standard Interface" means an interface that either is an official
120
- standard defined by a recognized standards body, or, in the case of
121
- interfaces specified for a particular programming language, one that
122
- is widely used among developers working in that language.
123
-
124
- The "System Libraries" of an executable work include anything, other
125
- than the work as a whole, that (a) is included in the normal form of
126
- packaging a Major Component, but which is not part of that Major
127
- Component, and (b) serves only to enable use of the work with that
128
- Major Component, or to implement a Standard Interface for which an
129
- implementation is available to the public in source code form. A
130
- "Major Component", in this context, means a major essential component
131
- (kernel, window system, and so on) of the specific operating system
132
- (if any) on which the executable work runs, or a compiler used to
133
- produce the work, or an object code interpreter used to run it.
134
-
135
- The "Corresponding Source" for a work in object code form means all
136
- the source code needed to generate, install, and (for an executable
137
- work) run the object code and to modify the work, including scripts to
138
- control those activities. However, it does not include the work's
139
- System Libraries, or general-purpose tools or generally available free
140
- programs which are used unmodified in performing those activities but
141
- which are not part of the work. For example, Corresponding Source
142
- includes interface definition files associated with source files for
143
- the work, and the source code for shared libraries and dynamically
144
- linked subprograms that the work is specifically designed to require,
145
- such as by intimate data communication or control flow between those
146
- subprograms and other parts of the work.
147
-
148
- The Corresponding Source need not include anything that users
149
- can regenerate automatically from other parts of the Corresponding
150
- Source.
151
-
152
- The Corresponding Source for a work in source code form is that
153
- same work.
154
-
155
- 2. Basic Permissions.
156
-
157
- All rights granted under this License are granted for the term of
158
- copyright on the Program, and are irrevocable provided the stated
159
- conditions are met. This License explicitly affirms your unlimited
160
- permission to run the unmodified Program. The output from running a
161
- covered work is covered by this License only if the output, given its
162
- content, constitutes a covered work. This License acknowledges your
163
- rights of fair use or other equivalent, as provided by copyright law.
164
-
165
- You may make, run and propagate covered works that you do not
166
- convey, without conditions so long as your license otherwise remains
167
- in force. You may convey covered works to others for the sole purpose
168
- of having them make modifications exclusively for you, or provide you
169
- with facilities for running those works, provided that you comply with
170
- the terms of this License in conveying all material for which you do
171
- not control copyright. Those thus making or running the covered works
172
- for you must do so exclusively on your behalf, under your direction
173
- and control, on terms that prohibit them from making any copies of
174
- your copyrighted material outside their relationship with you.
175
-
176
- Conveying under any other circumstances is permitted solely under
177
- the conditions stated below. Sublicensing is not allowed; section 10
178
- makes it unnecessary.
179
-
180
- 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
181
-
182
- No covered work shall be deemed part of an effective technological
183
- measure under any applicable law fulfilling obligations under article
184
- 11 of the WIPO copyright treaty adopted on 20 December 1996, or
185
- similar laws prohibiting or restricting circumvention of such
186
- measures.
187
-
188
- When you convey a covered work, you waive any legal power to forbid
189
- circumvention of technological measures to the extent such circumvention
190
- is effected by exercising rights under this License with respect to
191
- the covered work, and you disclaim any intention to limit operation or
192
- modification of the work as a means of enforcing, against the work's
193
- users, your or third parties' legal rights to forbid circumvention of
194
- technological measures.
195
-
196
- 4. Conveying Verbatim Copies.
197
-
198
- You may convey verbatim copies of the Program's source code as you
199
- receive it, in any medium, provided that you conspicuously and
200
- appropriately publish on each copy an appropriate copyright notice;
201
- keep intact all notices stating that this License and any
202
- non-permissive terms added in accord with section 7 apply to the code;
203
- keep intact all notices of the absence of any warranty; and give all
204
- recipients a copy of this License along with the Program.
205
-
206
- You may charge any price or no price for each copy that you convey,
207
- and you may offer support or warranty protection for a fee.
208
-
209
- 5. Conveying Modified Source Versions.
210
-
211
- You may convey a work based on the Program, or the modifications to
212
- produce it from the Program, in the form of source code under the
213
- terms of section 4, provided that you also meet all of these conditions:
214
-
215
- a) The work must carry prominent notices stating that you modified
216
- it, and giving a relevant date.
217
-
218
- b) The work must carry prominent notices stating that it is
219
- released under this License and any conditions added under section
220
- 7. This requirement modifies the requirement in section 4 to
221
- "keep intact all notices".
222
-
223
- c) You must license the entire work, as a whole, under this
224
- License to anyone who comes into possession of a copy. This
225
- License will therefore apply, along with any applicable section 7
226
- additional terms, to the whole of the work, and all its parts,
227
- regardless of how they are packaged. This License gives no
228
- permission to license the work in any other way, but it does not
229
- invalidate such permission if you have separately received it.
230
-
231
- d) If the work has interactive user interfaces, each must display
232
- Appropriate Legal Notices; however, if the Program has interactive
233
- interfaces that do not display Appropriate Legal Notices, your
234
- work need not make them do so.
235
-
236
- A compilation of a covered work with other separate and independent
237
- works, which are not by their nature extensions of the covered work,
238
- and which are not combined with it such as to form a larger program,
239
- in or on a volume of a storage or distribution medium, is called an
240
- "aggregate" if the compilation and its resulting copyright are not
241
- used to limit the access or legal rights of the compilation's users
242
- beyond what the individual works permit. Inclusion of a covered work
243
- in an aggregate does not cause this License to apply to the other
244
- parts of the aggregate.
245
-
246
- 6. Conveying Non-Source Forms.
247
-
248
- You may convey a covered work in object code form under the terms
249
- of sections 4 and 5, provided that you also convey the
250
- machine-readable Corresponding Source under the terms of this License,
251
- in one of these ways:
252
-
253
- a) Convey the object code in, or embodied in, a physical product
254
- (including a physical distribution medium), accompanied by the
255
- Corresponding Source fixed on a durable physical medium
256
- customarily used for software interchange.
257
-
258
- b) Convey the object code in, or embodied in, a physical product
259
- (including a physical distribution medium), accompanied by a
260
- written offer, valid for at least three years and valid for as
261
- long as you offer spare parts or customer support for that product
262
- model, to give anyone who possesses the object code either (1) a
263
- copy of the Corresponding Source for all the software in the
264
- product that is covered by this License, on a durable physical
265
- medium customarily used for software interchange, for a price no
266
- more than your reasonable cost of physically performing this
267
- conveying of source, or (2) access to copy the
268
- Corresponding Source from a network server at no charge.
269
-
270
- c) Convey individual copies of the object code with a copy of the
271
- written offer to provide the Corresponding Source. This
272
- alternative is allowed only occasionally and noncommercially, and
273
- only if you received the object code with such an offer, in accord
274
- with subsection 6b.
275
-
276
- d) Convey the object code by offering access from a designated
277
- place (gratis or for a charge), and offer equivalent access to the
278
- Corresponding Source in the same way through the same place at no
279
- further charge. You need not require recipients to copy the
280
- Corresponding Source along with the object code. If the place to
281
- copy the object code is a network server, the Corresponding Source
282
- may be on a different server (operated by you or a third party)
283
- that supports equivalent copying facilities, provided you maintain
284
- clear directions next to the object code saying where to find the
285
- Corresponding Source. Regardless of what server hosts the
286
- Corresponding Source, you remain obligated to ensure that it is
287
- available for as long as needed to satisfy these requirements.
288
-
289
- e) Convey the object code using peer-to-peer transmission, provided
290
- you inform other peers where the object code and Corresponding
291
- Source of the work are being offered to the general public at no
292
- charge under subsection 6d.
293
-
294
- A separable portion of the object code, whose source code is excluded
295
- from the Corresponding Source as a System Library, need not be
296
- included in conveying the object code work.
297
-
298
- A "User Product" is either (1) a "consumer product", which means any
299
- tangible personal property which is normally used for personal, family,
300
- or household purposes, or (2) anything designed or sold for incorporation
301
- into a dwelling. In determining whether a product is a consumer product,
302
- doubtful cases shall be resolved in favor of coverage. For a particular
303
- product received by a particular user, "normally used" refers to a
304
- typical or common use of that class of product, regardless of the status
305
- of the particular user or of the way in which the particular user
306
- actually uses, or expects or is expected to use, the product. A product
307
- is a consumer product regardless of whether the product has substantial
308
- commercial, industrial or non-consumer uses, unless such uses represent
309
- the only significant mode of use of the product.
310
-
311
- "Installation Information" for a User Product means any methods,
312
- procedures, authorization keys, or other information required to install
313
- and execute modified versions of a covered work in that User Product from
314
- a modified version of its Corresponding Source. The information must
315
- suffice to ensure that the continued functioning of the modified object
316
- code is in no case prevented or interfered with solely because
317
- modification has been made.
318
-
319
- If you convey an object code work under this section in, or with, or
320
- specifically for use in, a User Product, and the conveying occurs as
321
- part of a transaction in which the right of possession and use of the
322
- User Product is transferred to the recipient in perpetuity or for a
323
- fixed term (regardless of how the transaction is characterized), the
324
- Corresponding Source conveyed under this section must be accompanied
325
- by the Installation Information. But this requirement does not apply
326
- if neither you nor any third party retains the ability to install
327
- modified object code on the User Product (for example, the work has
328
- been installed in ROM).
329
-
330
- The requirement to provide Installation Information does not include a
331
- requirement to continue to provide support service, warranty, or updates
332
- for a work that has been modified or installed by the recipient, or for
333
- the User Product in which it has been modified or installed. Access to a
334
- network may be denied when the modification itself materially and
335
- adversely affects the operation of the network or violates the rules and
336
- protocols for communication across the network.
337
-
338
- Corresponding Source conveyed, and Installation Information provided,
339
- in accord with this section must be in a format that is publicly
340
- documented (and with an implementation available to the public in
341
- source code form), and must require no special password or key for
342
- unpacking, reading or copying.
343
-
344
- 7. Additional Terms.
345
-
346
- "Additional permissions" are terms that supplement the terms of this
347
- License by making exceptions from one or more of its conditions.
348
- Additional permissions that are applicable to the entire Program shall
349
- be treated as though they were included in this License, to the extent
350
- that they are valid under applicable law. If additional permissions
351
- apply only to part of the Program, that part may be used separately
352
- under those permissions, but the entire Program remains governed by
353
- this License without regard to the additional permissions.
354
-
355
- When you convey a copy of a covered work, you may at your option
356
- remove any additional permissions from that copy, or from any part of
357
- it. (Additional permissions may be written to require their own
358
- removal in certain cases when you modify the work.) You may place
359
- additional permissions on material, added by you to a covered work,
360
- for which you have or can give appropriate copyright permission.
361
-
362
- Notwithstanding any other provision of this License, for material you
363
- add to a covered work, you may (if authorized by the copyright holders of
364
- that material) supplement the terms of this License with terms:
365
-
366
- a) Disclaiming warranty or limiting liability differently from the
367
- terms of sections 15 and 16 of this License; or
368
-
369
- b) Requiring preservation of specified reasonable legal notices or
370
- author attributions in that material or in the Appropriate Legal
371
- Notices displayed by works containing it; or
372
-
373
- c) Prohibiting misrepresentation of the origin of that material, or
374
- requiring that modified versions of such material be marked in
375
- reasonable ways as different from the original version; or
376
-
377
- d) Limiting the use for publicity purposes of names of licensors or
378
- authors of the material; or
379
-
380
- e) Declining to grant rights under trademark law for use of some
381
- trade names, trademarks, or service marks; or
382
-
383
- f) Requiring indemnification of licensors and authors of that
384
- material by anyone who conveys the material (or modified versions of
385
- it) with contractual assumptions of liability to the recipient, for
386
- any liability that these contractual assumptions directly impose on
387
- those licensors and authors.
388
-
389
- All other non-permissive additional terms are considered "further
390
- restrictions" within the meaning of section 10. If the Program as you
391
- received it, or any part of it, contains a notice stating that it is
392
- governed by this License along with a term that is a further
393
- restriction, you may remove that term. If a license document contains
394
- a further restriction but permits relicensing or conveying under this
395
- License, you may add to a covered work material governed by the terms
396
- of that license document, provided that the further restriction does
397
- not survive such relicensing or conveying.
398
-
399
- If you add terms to a covered work in accord with this section, you
400
- must place, in the relevant source files, a statement of the
401
- additional terms that apply to those files, or a notice indicating
402
- where to find the applicable terms.
403
-
404
- Additional terms, permissive or non-permissive, may be stated in the
405
- form of a separately written license, or stated as exceptions;
406
- the above requirements apply either way.
407
-
408
- 8. Termination.
409
-
410
- You may not propagate or modify a covered work except as expressly
411
- provided under this License. Any attempt otherwise to propagate or
412
- modify it is void, and will automatically terminate your rights under
413
- this License (including any patent licenses granted under the third
414
- paragraph of section 11).
415
-
416
- However, if you cease all violation of this License, then your
417
- license from a particular copyright holder is reinstated (a)
418
- provisionally, unless and until the copyright holder explicitly and
419
- finally terminates your license, and (b) permanently, if the copyright
420
- holder fails to notify you of the violation by some reasonable means
421
- prior to 60 days after the cessation.
422
-
423
- Moreover, your license from a particular copyright holder is
424
- reinstated permanently if the copyright holder notifies you of the
425
- violation by some reasonable means, this is the first time you have
426
- received notice of violation of this License (for any work) from that
427
- copyright holder, and you cure the violation prior to 30 days after
428
- your receipt of the notice.
429
-
430
- Termination of your rights under this section does not terminate the
431
- licenses of parties who have received copies or rights from you under
432
- this License. If your rights have been terminated and not permanently
433
- reinstated, you do not qualify to receive new licenses for the same
434
- material under section 10.
435
-
436
- 9. Acceptance Not Required for Having Copies.
437
-
438
- You are not required to accept this License in order to receive or
439
- run a copy of the Program. Ancillary propagation of a covered work
440
- occurring solely as a consequence of using peer-to-peer transmission
441
- to receive a copy likewise does not require acceptance. However,
442
- nothing other than this License grants you permission to propagate or
443
- modify any covered work. These actions infringe copyright if you do
444
- not accept this License. Therefore, by modifying or propagating a
445
- covered work, you indicate your acceptance of this License to do so.
446
-
447
- 10. Automatic Licensing of Downstream Recipients.
448
-
449
- Each time you convey a covered work, the recipient automatically
450
- receives a license from the original licensors, to run, modify and
451
- propagate that work, subject to this License. You are not responsible
452
- for enforcing compliance by third parties with this License.
453
-
454
- An "entity transaction" is a transaction transferring control of an
455
- organization, or substantially all assets of one, or subdividing an
456
- organization, or merging organizations. If propagation of a covered
457
- work results from an entity transaction, each party to that
458
- transaction who receives a copy of the work also receives whatever
459
- licenses to the work the party's predecessor in interest had or could
460
- give under the previous paragraph, plus a right to possession of the
461
- Corresponding Source of the work from the predecessor in interest, if
462
- the predecessor has it or can get it with reasonable efforts.
463
-
464
- You may not impose any further restrictions on the exercise of the
465
- rights granted or affirmed under this License. For example, you may
466
- not impose a license fee, royalty, or other charge for exercise of
467
- rights granted under this License, and you may not initiate litigation
468
- (including a cross-claim or counterclaim in a lawsuit) alleging that
469
- any patent claim is infringed by making, using, selling, offering for
470
- sale, or importing the Program or any portion of it.
471
-
472
- 11. Patents.
473
-
474
- A "contributor" is a copyright holder who authorizes use under this
475
- License of the Program or a work on which the Program is based. The
476
- work thus licensed is called the contributor's "contributor version".
477
-
478
- A contributor's "essential patent claims" are all patent claims
479
- owned or controlled by the contributor, whether already acquired or
480
- hereafter acquired, that would be infringed by some manner, permitted
481
- by this License, of making, using, or selling its contributor version,
482
- but do not include claims that would be infringed only as a
483
- consequence of further modification of the contributor version. For
484
- purposes of this definition, "control" includes the right to grant
485
- patent sublicenses in a manner consistent with the requirements of
486
- this License.
487
-
488
- Each contributor grants you a non-exclusive, worldwide, royalty-free
489
- patent license under the contributor's essential patent claims, to
490
- make, use, sell, offer for sale, import and otherwise run, modify and
491
- propagate the contents of its contributor version.
492
-
493
- In the following three paragraphs, a "patent license" is any express
494
- agreement or commitment, however denominated, not to enforce a patent
495
- (such as an express permission to practice a patent or covenant not to
496
- sue for patent infringement). To "grant" such a patent license to a
497
- party means to make such an agreement or commitment not to enforce a
498
- patent against the party.
499
-
500
- If you convey a covered work, knowingly relying on a patent license,
501
- and the Corresponding Source of the work is not available for anyone
502
- to copy, free of charge and under the terms of this License, through a
503
- publicly available network server or other readily accessible means,
504
- then you must either (1) cause the Corresponding Source to be so
505
- available, or (2) arrange to deprive yourself of the benefit of the
506
- patent license for this particular work, or (3) arrange, in a manner
507
- consistent with the requirements of this License, to extend the patent
508
- license to downstream recipients. "Knowingly relying" means you have
509
- actual knowledge that, but for the patent license, your conveying the
510
- covered work in a country, or your recipient's use of the covered work
511
- in a country, would infringe one or more identifiable patents in that
512
- country that you have reason to believe are valid.
513
-
514
- If, pursuant to or in connection with a single transaction or
515
- arrangement, you convey, or propagate by procuring conveyance of, a
516
- covered work, and grant a patent license to some of the parties
517
- receiving the covered work authorizing them to use, propagate, modify
518
- or convey a specific copy of the covered work, then the patent license
519
- you grant is automatically extended to all recipients of the covered
520
- work and works based on it.
521
-
522
- A patent license is "discriminatory" if it does not include within
523
- the scope of its coverage, prohibits the exercise of, or is
524
- conditioned on the non-exercise of one or more of the rights that are
525
- specifically granted under this License. You may not convey a covered
526
- work if you are a party to an arrangement with a third party that is
527
- in the business of distributing software, under which you make payment
528
- to the third party based on the extent of your activity of conveying
529
- the work, and under which the third party grants, to any of the
530
- parties who would receive the covered work from you, a discriminatory
531
- patent license (a) in connection with copies of the covered work
532
- conveyed by you (or copies made from those copies), or (b) primarily
533
- for and in connection with specific products or compilations that
534
- contain the covered work, unless you entered into that arrangement,
535
- or that patent license was granted, prior to 28 March 2007.
536
-
537
- Nothing in this License shall be construed as excluding or limiting
538
- any implied license or other defenses to infringement that may
539
- otherwise be available to you under applicable patent law.
540
-
541
- 12. No Surrender of Others' Freedom.
542
-
543
- If conditions are imposed on you (whether by court order, agreement or
544
- otherwise) that contradict the conditions of this License, they do not
545
- excuse you from the conditions of this License. If you cannot convey a
546
- covered work so as to satisfy simultaneously your obligations under this
547
- License and any other pertinent obligations, then as a consequence you may
548
- not convey it at all. For example, if you agree to terms that obligate you
549
- to collect a royalty for further conveying from those to whom you convey
550
- the Program, the only way you could satisfy both those terms and this
551
- License would be to refrain entirely from conveying the Program.
552
-
553
- 13. Use with the GNU Affero General Public License.
554
-
555
- Notwithstanding any other provision of this License, you have
556
- permission to link or combine any covered work with a work licensed
557
- under version 3 of the GNU Affero General Public License into a single
558
- combined work, and to convey the resulting work. The terms of this
559
- License will continue to apply to the part which is the covered work,
560
- but the special requirements of the GNU Affero General Public License,
561
- section 13, concerning interaction through a network will apply to the
562
- combination as such.
563
-
564
- 14. Revised Versions of this License.
565
-
566
- The Free Software Foundation may publish revised and/or new versions of
567
- the GNU General Public License from time to time. Such new versions will
568
- be similar in spirit to the present version, but may differ in detail to
569
- address new problems or concerns.
570
-
571
- Each version is given a distinguishing version number. If the
572
- Program specifies that a certain numbered version of the GNU General
573
- Public License "or any later version" applies to it, you have the
574
- option of following the terms and conditions either of that numbered
575
- version or of any later version published by the Free Software
576
- Foundation. If the Program does not specify a version number of the
577
- GNU General Public License, you may choose any version ever published
578
- by the Free Software Foundation.
579
-
580
- If the Program specifies that a proxy can decide which future
581
- versions of the GNU General Public License can be used, that proxy's
582
- public statement of acceptance of a version permanently authorizes you
583
- to choose that version for the Program.
584
-
585
- Later license versions may give you additional or different
586
- permissions. However, no additional obligations are imposed on any
587
- author or copyright holder as a result of your choosing to follow a
588
- later version.
589
-
590
- 15. Disclaimer of Warranty.
591
-
592
- THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
593
- APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
594
- HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
595
- OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
596
- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
597
- PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
598
- IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
599
- ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
600
-
601
- 16. Limitation of Liability.
602
-
603
- IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
604
- WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
605
- THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
606
- GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
607
- USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
608
- DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
609
- PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
610
- EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
611
- SUCH DAMAGES.
612
-
613
- 17. Interpretation of Sections 15 and 16.
614
-
615
- If the disclaimer of warranty and limitation of liability provided
616
- above cannot be given local legal effect according to their terms,
617
- reviewing courts shall apply local law that most closely approximates
618
- an absolute waiver of all civil liability in connection with the
619
- Program, unless a warranty or assumption of liability accompanies a
620
- copy of the Program in return for a fee.
621
-
622
- END OF TERMS AND CONDITIONS
623
-
624
- How to Apply These Terms to Your New Programs
625
-
626
- If you develop a new program, and you want it to be of the greatest
627
- possible use to the public, the best way to achieve this is to make it
628
- free software which everyone can redistribute and change under these terms.
629
-
630
- To do so, attach the following notices to the program. It is safest
631
- to attach them to the start of each source file to most effectively
632
- state the exclusion of warranty; and each file should have at least
633
- the "copyright" line and a pointer to where the full notice is found.
634
-
635
- <one line to give the program's name and a brief idea of what it does.>
636
- Copyright (C) <year> <name of author>
637
-
638
- This program is free software: you can redistribute it and/or modify
639
- it under the terms of the GNU General Public License as published by
640
- the Free Software Foundation, either version 3 of the License, or
641
- (at your option) any later version.
642
-
643
- This program is distributed in the hope that it will be useful,
644
- but WITHOUT ANY WARRANTY; without even the implied warranty of
645
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
646
- GNU General Public License for more details.
647
-
648
- You should have received a copy of the GNU General Public License
649
- along with this program. If not, see <http://www.gnu.org/licenses/>.
650
-
651
- Also add information on how to contact you by electronic and paper mail.
652
-
653
- If the program does terminal interaction, make it output a short
654
- notice like this when it starts in an interactive mode:
655
-
656
- <program> Copyright (C) <year> <name of author>
657
- This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
658
- This is free software, and you are welcome to redistribute it
659
- under certain conditions; type `show c' for details.
660
-
661
- The hypothetical commands `show w' and `show c' should show the appropriate
662
- parts of the General Public License. Of course, your program's commands
663
- might be different; for a GUI interface, you would use an "about box".
664
-
665
- You should also get your employer (if you work as a programmer) or school,
666
- if any, to sign a "copyright disclaimer" for the program, if necessary.
667
- For more information on this, and how to apply and follow the GNU GPL, see
668
- <http://www.gnu.org/licenses/>.
669
-
670
- The GNU General Public License does not permit incorporating your program
671
- into proprietary programs. If your program is a subroutine library, you
672
- may consider it more useful to permit linking proprietary applications with
673
- the library. If this is what you want to do, use the GNU Lesser General
674
- Public License instead of this License. But first, please read
675
- <http://www.gnu.org/philosophy/why-not-lgpl.html>.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Optile/Payment/Helper/Cache.php ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
14
+ *
15
+ * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
+ */
19
+
20
+ class Optile_Payment_Helper_Cache extends Mage_Core_Helper_Abstract {
21
+
22
+ public function load($key){
23
+ return Mage::app()->getCache()->load($key);
24
+ }
25
+
26
+ public function save($key, $data="", $lifeTime=3600 ){
27
+ return Mage::app()->getCache()->save($data, $key, array(Mage_Core_Model_Config::CACHE_TAG), $lifeTime);
28
+ }
29
+ }
app/code/community/Optile/Payment/Helper/Data.php CHANGED
@@ -1,25 +1,77 @@
1
  <?php
2
  /**
3
- * This file is part of the Optile Payment Connector extension.
4
- *
5
- * Optile Payment Connector is free software: you can redistribute it and/or
6
- * modify it under the terms of the GNU General Public License as published
7
- * by the Free Software Foundation, either version 3 of the License, or
8
- * (at your option) any later version.
9
- *
10
- * Optile Payment Connector is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License along with
16
- * Optile Payment Connector. If not, see <http://www.gnu.org/licenses/>.
17
  *
18
  * @author i-Ways <dev@i-ways.hr>
19
- * @copyright Copyright (c) 2013 Optile. (http://www.optile.de)
20
- * @license http://www.gnu.org/licenses/gpl.txt
21
  */
22
 
23
  class Optile_Payment_Helper_Data extends Mage_Core_Helper_Abstract {
24
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  }
1
  <?php
2
  /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
 
 
 
14
  *
15
  * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
  */
19
 
20
  class Optile_Payment_Helper_Data extends Mage_Core_Helper_Abstract {
21
+
22
+ /**
23
+ * Logging filename
24
+ */
25
+ protected $_logFileName = 'optile.log';
26
+
27
+ /**
28
+ * Log helper
29
+ */
30
+ public function log( $message, $level = Zend_log::DEBUG ) {
31
+
32
+ if($this->isLogEnabled() && $level <= $this->getLogLevel()){
33
+ Mage::log( $message, $level, $this->_logFileName, true );
34
+ }
35
+ }
36
+
37
+ public function getQuotePrefix(){
38
+ return Mage::getStoreConfig('payment/optile/quote_prefix');
39
+ }
40
+
41
+ public function formatQuoteId($quote_id){
42
+ return $this->getQuotePrefix().$quote_id;
43
+ }
44
+
45
+ /**
46
+ * Returns whether logging is enabled
47
+ */
48
+ protected function isLogEnabled() {
49
+ return Mage::getStoreConfig('payment/optile/log_enabled');
50
+ }
51
+ protected function getLogLevel() {
52
+ return Mage::getStoreConfig('payment/optile/log_level');
53
+ }
54
+
55
+ /**
56
+ * Returns payment info/instructions for payment method.
57
+ * @param string $network
58
+ * @param int $store_id
59
+ * @return string
60
+ */
61
+ public function getPaymentInstructions($network, $store_id=null) {
62
+ $address = sprintf('payment/optile/instructions');
63
+
64
+ $instructions = Mage::getStoreConfig($address, $store_id);
65
+
66
+ $instructions = unserialize($instructions);
67
+ if (!is_array($instructions)) {
68
+ return;
69
+ }
70
+
71
+ foreach ($instructions as $instruction) {
72
+ if (strtolower($instruction['payment_method']) == strtolower($network)) {
73
+ return $instruction['value'];
74
+ }
75
+ }
76
+ }
77
  }
app/code/community/Optile/Payment/Model/Checkout.php CHANGED
@@ -1,41 +1,37 @@
1
  <?php
2
  /**
3
- * This file is part of the Optile Payment Connector extension.
4
- *
5
- * Optile Payment Connector is free software: you can redistribute it and/or
6
- * modify it under the terms of the GNU General Public License as published
7
- * by the Free Software Foundation, either version 3 of the License, or
8
- * (at your option) any later version.
9
- *
10
- * Optile Payment Connector is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License along with
16
- * Optile Payment Connector. If not, see <http://www.gnu.org/licenses/>.
17
  *
18
  * @author i-Ways <dev@i-ways.hr>
19
- * @copyright Copyright (c) 2013 Optile. (http://www.optile.de)
20
- * @license http://www.gnu.org/licenses/gpl.txt
21
  */
22
 
23
- include_once Mage::getBaseDir('lib').DS.'Optile'.DS.'Server'.DS.'optile.sdk.lib.inc.php';
 
24
 
25
  /**
26
- * optile payment method checkout model
27
- *
28
- * Requires quote instance and handles all calls to the optile sdk, like
29
- * for new LIST request.
30
  *
 
31
  */
32
  class Optile_Payment_Model_Checkout {
33
-
34
  /**
35
  * Logging filename
36
  */
37
- protected $_logFileName = 'optile.log';
38
-
39
  /**
40
  * Quote instance
41
  * @var Mage_Sales_Model_Quote
@@ -47,182 +43,269 @@ class Optile_Payment_Model_Checkout {
47
  * @var Mage_Paypal_Model_Config
48
  */
49
  protected $_config = null;
50
-
51
- /**
52
- * Stores existing list request instance (self link)
53
- */
54
- protected $_listRequestSelfLink = null;
55
-
56
- /**
57
- * Set quote and listRequestSelfLink instances
58
- * @param array $params
59
- */
60
- public function __construct($params = array())
61
- {
62
- if (isset($params['quote']) && $params['quote'] instanceof Mage_Sales_Model_Quote) {
63
- $this->_quote = $params['quote'];
64
- } else {
65
- throw new Exception('Quote instance is required.');
66
- }
67
- if (isset($params['listRequestSelfLink'])) {
68
- $this->_listRequestSelfLink = $params['listRequestSelfLink'];
69
- }
70
- }
71
-
72
  /**
73
  * Returns merchant_code setting
74
  */
75
- private function getMerchantCode() {
76
- return Mage::getStoreConfig(
77
- 'payment/optile/merchant_code',
78
- Mage::app()->getStore()
79
- );
80
  }
81
-
82
  /**
83
  * Returns merchant_token setting
84
  */
85
- private function getMerchantToken() {
86
- return Mage::getStoreConfig(
87
- 'payment/optile/merchant_token',
88
- Mage::app()->getStore()
89
- );
90
- }
91
-
92
- /**
93
- * Returns store current currency code
94
- */
95
- private function getCurrencyCode() {
96
- return Mage::app()->getStore()->getCurrentCurrencyCode();
97
  }
98
-
99
- /**
100
- * Returns store country
101
- */
102
- private function getCountry() {
103
- return Mage::getStoreConfig('general/country/default');
104
- }
105
-
106
- /**
107
- * Returns optile api base url based on test_mode setting
108
- *
109
- * If the test mode is on, returns sandbox url,
110
- * otherwise, live url
111
- *
112
- * @return string
113
- */
114
- private function getBaseUrl() {
115
- $test_mode = Mage::getStoreConfig(
116
- 'payment/optile/test',
117
- Mage::app()->getStore()
118
- );
119
-
120
- $base_url = $test_mode ? "https://sandbox.oscato.com" : "https://oscato.com";
121
- return $base_url;
122
- }
123
-
124
  /**
125
- * Returns whether logging is enabled
126
  */
127
- private function isLogEnabled() {
128
- return Mage::getStoreConfig(
129
- 'payment/optile/log_enabled',
130
- Mage::app()->getStore()
131
- );
132
  }
133
-
134
  /**
135
- * Logging helper
136
- * @param unknown $what array() or string to log
137
  */
138
- public function log($what, $level = null) {
139
- if($this->isLogEnabled())
140
- Mage::log( $what, $level, $file = $this->_logFileName, true );
141
  }
142
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
143
  /**
144
  * Returns checkout cancel url
145
  */
146
- private function getCancelUrl() {
147
- return Mage::getUrl('optile/payment/cancel');
148
  }
149
-
150
  /**
151
  * Returns notification url that handles status notification updates
152
  * like successful charge
153
  */
154
- private function getNotificationUrl() {
155
- return Mage::getUrl('optile/notification/index');
156
  }
157
-
158
  /**
159
  * Returns checkout success url
160
  */
161
- private function getReturnUrl() {
162
- return Mage::getUrl('checkout/onepage/success');
163
  }
164
-
165
  /**
166
- * Returns available payment networks
167
- * If there's no existing list request available, it will make new LIST
168
- * request to optile, otherwise it will refresh existing list request
169
  */
170
- public function requestAvailableNetworks() {
171
- if($this->_listRequestSelfLink) {
172
- $this->log("Repeating existing LIST request... ".$this->_listRequestSelfLink);
173
- $listRequest = new OptileReloadListRequest();
174
- $listRequest->setMerchantCode($this->getMerchantCode());
175
- $listRequest->setMerchantToken($this->getMerchantToken());
176
-
177
- $result = $listRequest->GetResponse($this->_listRequestSelfLink);
178
-
179
- return $result;
180
  } else {
181
- $this->log("Making new LIST request...");
182
- return $this->newListRequest();
 
183
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
184
  }
185
-
186
  /**
187
- * Makes new LIST request to optile and returns its response
188
- */
189
- private function newListRequest() {
190
- $quote = $this->_quote;
191
- $quote->collectTotals()->save();
192
-
193
- $request = new OptileListRequest();
194
- $request->setMerchantCode($this->getMerchantCode());
195
- $request->setMerchantToken($this->getMerchantToken());
196
- $request->setCountry($this->getCountry());
197
- $request->setTransactionId($quote->getId());
198
-
199
  $billingAddress = $quote->getBillingAddress();
200
-
201
- $customer = new OptileCustomer();
202
- $customer->setEmail($billingAddress->getEmail());
203
- $customer->setNumber("None");
204
-
205
- $request->setCustomer($customer);
206
-
207
- $callBack = new OptileCallback();
208
- $callBack->setCancelUrl($this->getCancelUrl());
209
- $callBack->setNotificationUrl($this->getNotificationUrl());
210
- $callBack->setReturnUrl($this->getReturnUrl());
211
-
212
- $request->setCallback($callBack);
213
-
214
- $payment = new OptilePayment();
215
- $payment->setAmount($quote->getGrandTotal());
216
- $payment->setCurrency($this->getCurrencyCode());
217
- $payment->setReference($quote->getId());
218
-
219
- $request->setPayment($payment);
220
-
221
- $this->log("Grand total: ".$quote->getGrandTotal());
222
-
223
- $result = $request->GetResponse($this->getBaseUrl());
224
-
225
- return $result;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
226
  }
227
- }
228
 
 
1
  <?php
2
  /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
 
 
 
14
  *
15
  * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
  */
19
 
20
+ require_once implode(DS, array(Mage::getBaseDir('lib'), 'Optile', 'Request', 'RequestFactory.php'));
21
+ use \Optile\Request\RequestFactory;
22
 
23
  /**
24
+ * Optile payment method checkout model
 
 
 
25
  *
26
+ * Handles all calls to the Optile SDK, like for new LIST request.
27
  */
28
  class Optile_Payment_Model_Checkout {
29
+
30
  /**
31
  * Logging filename
32
  */
33
+ protected $_logFileName = 'optile.log';
34
+
35
  /**
36
  * Quote instance
37
  * @var Mage_Sales_Model_Quote
43
  * @var Mage_Paypal_Model_Config
44
  */
45
  protected $_config = null;
46
+
47
+ public function __construct() {
48
+ RequestFactory::setLogger(Mage::helper('optile'));
49
+ RequestFactory::setCacher(Mage::helper('optile/cache'));
50
+ }
51
+
52
+ protected function getQuote() {
53
+ if (!isset($this->_quote)) {
54
+ $this->_quote = Mage::getSingleton('checkout/session')->getQuote();
55
+ $this->_quote
56
+ ->collectTotals()
57
+ ->save();
58
+ }
59
+ return $this->_quote;
60
+ }
61
+
 
 
 
 
 
 
62
  /**
63
  * Returns merchant_code setting
64
  */
65
+ protected function getMerchantCode() {
66
+ return Mage::getStoreConfig('payment/optile/merchant_code');
 
 
 
67
  }
68
+
69
  /**
70
  * Returns merchant_token setting
71
  */
72
+ protected function getMerchantToken() {
73
+ return Mage::getStoreConfig('payment/optile/merchant_token');
 
 
 
 
 
 
 
 
 
 
74
  }
75
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
  /**
77
+ * Returns preselection_deferral setting
78
  */
79
+ protected function getPreselectionDeferral() {
80
+ return Mage::getStoreConfig('payment/optile/preselection_deferral');
 
 
 
81
  }
82
+
83
  /**
84
+ * Returns customer's billing address country
 
85
  */
86
+ protected function getCountry() {
87
+ return $this->getQuote()->getBillingAddress()->getCountryId();
 
88
  }
89
+
90
+ /**
91
+ * Returns display name for current Magento store
92
+ */
93
+ protected function getStoreName() {
94
+ return Mage::getStoreConfig('general/store_information/name');
95
+ }
96
+
97
+ /**
98
+ * Returns API URL from config.
99
+ */
100
+ protected function getApiUrl() {
101
+ return Mage::getStoreConfig('payment/optile/api_url');
102
+ }
103
+
104
  /**
105
  * Returns checkout cancel url
106
  */
107
+ protected function getCancelUrl() {
108
+ return Mage::getUrl('optile/payment/cancel', array('_secure' => 1));
109
  }
110
+
111
  /**
112
  * Returns notification url that handles status notification updates
113
  * like successful charge
114
  */
115
+ protected function getNotificationUrl() {
116
+ return Mage::getUrl('optile/notification/index', array('_secure' => 1));
117
  }
118
+
119
  /**
120
  * Returns checkout success url
121
  */
122
+ protected function getReturnUrl() {
123
+ return Mage::getUrl('checkout/onepage/success', array('_secure' => 1));
124
  }
125
+
126
  /**
127
+ * Refreshes an existing LIST request, or makes a new LIST request if no
128
+ * existing LIST request is available.
129
+ * @return \Optile\Response\Response Available payment networks
130
  */
131
+ public function requestAvailableNetworks($listRequestSelfLink = null) {
132
+
133
+ if ($listRequestSelfLink) {
134
+ Mage::helper('optile')->log("Repeating existing LIST request... ".$listRequestSelfLink);
135
+ $request = RequestFactory::getReloadListRequest($listRequestSelfLink);
 
 
 
 
 
136
  } else {
137
+ Mage::helper('optile')->log("Making new LIST request...");
138
+ $request = RequestFactory::getListRequest($this->getApiUrl());
139
+ $this->newListRequest($request);
140
  }
141
+
142
+ // Authentication
143
+ $request
144
+ ->setMerchantCode($this->getMerchantCode())
145
+ ->setMerchantToken($this->getMerchantToken());
146
+
147
+ $response = $request->send();
148
+ /* @var $response Response */
149
+ if(!$response){
150
+ Mage::helper("optile")->log("Error while executing LIST request:");
151
+ Mage::helper("optile")->log("Info: ".$response);
152
+ throw new Exception("Error while fetching response from Optile");
153
+ }
154
+ if($response->getInteraction()->getCode() != "PROCEED"){
155
+ Mage::helper("optile")->log("Error while executing LIST request:");
156
+ Mage::helper("optile")->log("Info: ".$response->getInfo());
157
+ Mage::helper("optile")->log("Code: ".$response->getInteraction()->getCode());
158
+ Mage::helper("optile")->log("Reason: ".$response->getInteraction()->getReason());
159
+ // throw new Exception($response->getInfo());
160
+ }
161
+
162
+ // Mage::helper('optile')->log("LIST response:");
163
+ // Mage::helper('optile')->log($result);
164
+ return $response;
165
  }
166
+
167
  /**
168
+ * Sets request data on new LIST request object.
169
+ * @param \Optile\Request\ListRequest $request
170
+ */
171
+ protected function newListRequest(\Optile\Request\ListRequest $request) {
172
+ $quote = $this->getQuote();
173
+ $totals = $quote->getTotals();
 
 
 
 
 
 
174
  $billingAddress = $quote->getBillingAddress();
175
+ $shippingAddress = $quote->getShippingAddress();
176
+
177
+ // Root request data
178
+ $request
179
+ ->setTransactionId(Mage::helper('optile')->formatQuoteId($quote->getId()))
180
+ ->setCountry($this->getCountry())
181
+ ;
182
+
183
+
184
+ $reference = Mage::helper('checkout')->__('Quote #%s, %s order', Mage::helper('optile')->formatQuoteId($quote->getId()), $this->getStoreName());
185
+
186
+ // Payment
187
+ $request->addPayment()
188
+ ->setAmount($quote->getGrandTotal())
189
+ ->setCurrency($quote->getQuoteCurrencyCode())
190
+ ->setReference($reference)
191
+ ;
192
+
193
+ // Products
194
+ foreach ($quote->getAllVisibleItems() as $quoteItem) {
195
+ /* @var $quoteItem Mage_Sales_Model_Quote_Item */
196
+ $request->addProduct()
197
+ ->setCode($quoteItem->getSku())
198
+ ->setName($quoteItem->getName())
199
+ ->setQuantity($quoteItem->getQty())
200
+ ->setAmount($quoteItem->getRowTotalInclTax())
201
+ ;
202
+ }
203
+
204
+ if ($shippingAddress->getShippingAmount()) {
205
+ // Add shipping as an additional product, to complete the total.
206
+ $request->addProduct()
207
+ ->setCode($shippingAddress->getShippingMethod())
208
+ ->setName(Mage::helper('optile')->__("Shipping costs").': '.$shippingAddress->getShippingDescription())
209
+ ->setQuantity(1)
210
+ ->setAmount($shippingAddress->getShippingAmount())
211
+ ;
212
+ }
213
+ if (isset($totals['discount']) && $totals['discount']->getValue()) {
214
+ $discount = $totals['discount']->getValue();
215
+
216
+ // Add shipping as an additional product, to complete the total.
217
+ $request->addProduct()
218
+ ->setCode("discount")
219
+ ->setName(Mage::helper('optile')->__("Discount"))
220
+ ->setQuantity(1)
221
+ ->setAmount($discount)
222
+ ;
223
+ }
224
+
225
+ //T: This feature is not yet ready for production. TODO: validate
226
+ // additional payment charge before charge request to Optile.
227
+ // if($quote->getGrandTotal() > $quote->getSubtotal()){
228
+ //
229
+ // $payment_charge = $quote->getGrandTotal() - $quote->getSubtotal();
230
+ // $request->addProduct()
231
+ // ->setCode("payment_charge")
232
+ // ->setName(Mage::helper('optile')->__("Payment charge"))
233
+ // ->setQuantity(1)
234
+ // ->setAmount($payment_charge)
235
+ // ;
236
+ // }
237
+
238
+ // Customer
239
+
240
+ $email =
241
+ $billingAddress->getEmail() ?
242
+ $billingAddress->getEmail() :
243
+ $quote->getCustomerEmail();
244
+
245
+ $customerId =
246
+ $quote->getCustomerId() ?
247
+ $quote->getCustomerId() :
248
+ 'Guest';
249
+
250
+ $reqCustomer = $request->addCustomer();
251
+ $reqCustomer
252
+ ->setEmail($email)
253
+ ->setNumber($customerId);
254
+
255
+ if ($quote->hasCustomerDob()) {
256
+ $dob = date('Y-m-d', strtotime($quote->getCustomerDob()));
257
+ $reqCustomer->setBirthday($dob .'T00:00:00.000Z');
258
+ }
259
+
260
+ $reqCustomer->addName()
261
+ ->setTitle($quote->getCustomerPrefix())
262
+ ->setFirstName($quote->getCustomerFirstname())
263
+ ->setMiddleName($quote->getCustomerMiddlename())
264
+ ->setLastName($quote->getCustomerLastname())
265
+ ;
266
+
267
+ $reqCustomer->addAddress(\Optile\Request\CustomerAddress::TYPE_BILLING)
268
+ ->setCity($billingAddress->getCity())
269
+ ->setCountry($billingAddress->getCountry())
270
+ ->setState($billingAddress->getRegionCode())
271
+ ->setStreet($billingAddress->getStreetFull())
272
+ ->setZip($billingAddress->getPostcode())
273
+ ->addName()
274
+ ->setTitle($billingAddress->getPrefix())
275
+ ->setFirstName($billingAddress->getFirstname())
276
+ ->setMiddleName($billingAddress->getMiddlename())
277
+ ->setLastName($billingAddress->getLastname())
278
+ ;
279
+
280
+ $reqCustomer->addAddress(\Optile\Request\CustomerAddress::TYPE_SHIPPING)
281
+ ->setCity($shippingAddress->getCity())
282
+ ->setCountry($shippingAddress->getCountry())
283
+ ->setState($shippingAddress->getRegionCode())
284
+ ->setStreet($shippingAddress->getStreetFull())
285
+ ->setZip($shippingAddress->getPostcode())
286
+ ->addName()
287
+ ->setTitle($shippingAddress->getPrefix())
288
+ ->setFirstName($shippingAddress->getFirstname())
289
+ ->setMiddleName($shippingAddress->getMiddlename())
290
+ ->setLastName($shippingAddress->getLastname())
291
+ ;
292
+
293
+ $reqCustomer->addPhone(\Optile\Request\CustomerPhone::TYPE_OTHER)
294
+ ->setUnstructuredNumber($billingAddress->getTelephone());
295
+
296
+ // Callback
297
+ $request->addCallback()
298
+ ->setReturnUrl($this->getReturnUrl())
299
+ ->setCancelUrl($this->getCancelUrl())
300
+ ->setNotificationUrl($this->getNotificationUrl())
301
+ ;
302
+
303
+ // Deferred payments support
304
+ $request->addPreselection()
305
+ ->setDeferral($this->getPreselectionDeferral())
306
+ ;
307
+
308
+ Mage::helper('optile')->log("Grand total: ".$quote->getGrandTotal());
309
  }
 
310
 
311
+ }
app/code/community/Optile/Payment/Model/Mysql4/Notification.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
14
+ *
15
+ * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
+ */
19
+
20
+ class Optile_Payment_Model_Mysql4_Notification extends Mage_Core_Model_Mysql4_Abstract
21
+ {
22
+ protected function _construct() {
23
+ $this->_init('optile/notification', 'id');
24
+ }
25
+ }
app/code/community/Optile/Payment/Model/Mysql4/Notification/Collection.php ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
14
+ *
15
+ * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
+ */
19
+
20
+ class Optile_Payment_Model_Mysql4_Notification_Collection
21
+ extends Mage_Core_Model_Mysql4_Collection_Abstract
22
+ {
23
+
24
+ protected function _construct()
25
+ {
26
+ $this->_init('optile/notification');
27
+ }
28
+
29
+ }
app/code/community/Optile/Payment/Model/Mysql4/Quote.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
14
+ *
15
+ * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
+ */
19
+
20
+ class Optile_Payment_Model_Mysql4_Quote extends Mage_Core_Model_Mysql4_Abstract
21
+ {
22
+ protected $_isPkAutoIncrement = false;
23
+
24
+ protected function _construct() {
25
+ $this->_init('optile/quote', 'transaction_id');
26
+ }
27
+ }
app/code/community/Optile/Payment/Model/Mysql4/Quote/Collection.php ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
14
+ *
15
+ * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
+ */
19
+
20
+ class Optile_Payment_Model_Mysql4_Quote_Collection
21
+ extends Mage_Core_Model_Mysql4_Collection_Abstract
22
+ {
23
+
24
+ protected function _construct()
25
+ {
26
+ $this->_init('optile/quote');
27
+ }
28
+
29
+ }
app/code/community/Optile/Payment/Model/Notification.php CHANGED
@@ -1,354 +1,776 @@
1
  <?php
2
  /**
3
- * This file is part of the Optile Payment Connector extension.
4
- *
5
- * Optile Payment Connector is free software: you can redistribute it and/or
6
- * modify it under the terms of the GNU General Public License as published
7
- * by the Free Software Foundation, either version 3 of the License, or
8
- * (at your option) any later version.
9
- *
10
- * Optile Payment Connector is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License along with
16
- * Optile Payment Connector. If not, see <http://www.gnu.org/licenses/>.
17
  *
18
  * @author i-Ways <dev@i-ways.hr>
19
- * @copyright Copyright (c) 2013 Optile. (http://www.optile.de)
20
- * @license http://www.gnu.org/licenses/gpl.txt
21
  */
22
 
23
  /**
24
  * Optile notification handler model
25
  *
26
  */
27
- class Optile_Payment_Model_Notification {
28
-
29
- /**
30
- * Logging filename
31
- */
32
- protected $_logFileName = 'optile.log';
33
-
34
- /**
35
- * Log helper
36
- */
37
- protected function log( $message, $level = null ) {
38
- if($this->isLogEnabled())
39
- Mage::log( $message, $level, $file = $this->_logFileName, true );
40
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
 
42
- /**
43
- * Returns whether logging is enabled
44
- */
45
- protected function isLogEnabled() {
46
- return Mage::getStoreConfig(
47
- 'payment/optile/log_enabled',
48
- Mage::app()->getStore()
49
- );
50
- }
51
-
52
- /**
53
- * Magento request instance
54
- * @var unknown
55
- */
56
- protected $_request;
57
-
58
  /**
59
  * Magento request params instance
60
  */
61
  protected $_params;
62
-
63
  /**
64
- * Returns optile notification IPs.
65
  * Other IPs are blacklisted for notifications
66
- *
67
- * Test server (sandbox.oscato.com) => 78.46.61.206
68
  * Production server (oscato.com) => 213.155.71.162
69
- *
70
  * @return string
71
  */
72
  private function getAllowedIP() {
73
- $test_mode = Mage::getStoreConfig(
74
- 'payment/optile/test',
75
- Mage::app()->getStore()
76
- );
77
-
78
- return $test_mode ? '78.46.61.206' : '213.155.71.162';
79
  }
80
-
81
  /**
82
  * Process status notification
83
- *
84
  * @param Magento Request $request
85
  */
86
  public function processNotification($request) {
87
- $this->request = $request;
88
-
89
- $params = $this->_params = $request->getParams();
90
-
91
- $this->log($params);
92
-
 
 
 
 
 
 
 
 
 
 
 
93
  $allowed_ip = $this->getAllowedIP();
94
- $remote = array(
95
- isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '',
96
- isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : '',
97
- );
98
- if ( !in_array($allowed_ip, $remote) ) {
99
- $this->log(__METHOD__ .' UNAUTHORIZED ACCESS FROM: '. $_SERVER['REMOTE_ADDR'], Zend_Log::ALERT);
100
- header($_SERVER['SERVER_PROTOCOL'] .' 403 Forbidden', true, 403);
101
- die('<h1>Access denied</h1>');
 
 
 
102
  }
103
-
104
- $quote = Mage::getModel('sales/quote')->load($params['transactionId']);
105
- if(!$quote->getId()) {
106
- $msg = 'Quote with ID '. $params['transactionId'] .' not found.';
107
- $this->log($msg, Zend_Log::ERR);
108
- header($_SERVER['SERVER_PROTOCOL'] .' 500 Internal Error', true, 500);
109
- die('ERROR:'. $msg);
110
- }
111
-
112
- if(!$quote->getReservedOrderId()) {
113
- $msg = 'Quote with ID '. $params['transactionId'] .' found, but orderID not set yet.';
114
- $this->log($msg, Zend_Log::ERR);
115
- header($_SERVER['SERVER_PROTOCOL'] .' 500 Internal Error', true, 500);
116
- die('ERROR:'. $msg);
117
  }
118
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119
  $orderIncrementId = $quote->getReservedOrderId();
120
  $order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
121
-
122
  switch($params['statusCode']) {
123
  case 'charged':
124
  $this->handleCharged($order);
125
  break;
126
- case 'registered':
127
- // @TODO: handle 'registered'?
128
- die("registered?");
 
 
 
 
 
 
 
 
129
  case 'failed':
130
  case 'declined':
131
  case 'aborted':
132
  case 'canceled':
133
- $this->handleFailed($order);
134
- break;
135
  case 'expired':
136
- $this->handleExpired($order);
137
  break;
138
  case 'pending':
139
  $this->handlePending($order);
140
  break;
 
 
 
141
  default:
142
  $msg = "Not handling ".$params['statusCode'];
143
- Mage::log($msg, Zend_Log::NOTICE);
144
- die($msg);
145
  }
146
-
147
  }
148
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
149
  /**
150
  * Process optile status notification with statusCode 'charged'
151
  * @param Mage_Sales_Model_Order $order
152
  */
153
  private function handleCharged($order) {
154
- $payment = $order->getPayment();
155
-
156
- // Match amount.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
157
  $orderSum = (float) $order->getGrandTotal();
158
  $paramSum = (float) $this->_params['amount'];
159
  if ($orderSum !== $paramSum) {
160
- $msg = ' Authorized amount ('. $paramSum .') does not match order amount ('. $orderSum .')';
161
- $this->log(__METHOD__ . $msg, Zend_Log::ERR);
162
-
163
  $payment->registerCaptureNotification($paramSum);
164
  $order->save();
165
-
166
- header($_SERVER['SERVER_PROTOCOL'] .' 500 Internal Error', true, 500);
167
- die('ERROR:'. $msg);
168
- }
169
-
170
- // Check current order status.
171
- if (!$order->isPaymentReview() || $order->getStatus() == Mage_Sales_Model_Order::STATUS_FRAUD) {
172
- $comment = 'Rejected payment notification because order status is: ';
173
- $comment .= $order->getStatusLabel();
174
- $order->addStatusHistoryComment($comment)->save();
175
-
176
- $state = $order->getState();
177
- $status = $order->getStatus();
178
- $msg = sprintf(' Current order state does not allow payments (%s / %s)', $state, $status);
179
- $this->log(__METHOD__ . $msg, Zend_Log::ERR);
180
-
181
- header($_SERVER['SERVER_PROTOCOL'] .' 500 Internal Error', true, 500);
182
- die('ERROR:'. $msg);
183
  }
184
-
185
  // Update payment.
186
- $this->log(__METHOD__ .' Updating payment...');
187
-
 
188
  $payment->registerCaptureNotification($paramSum);
189
- $order->save();
190
-
191
- $this->log(__METHOD__ .' DONE');
192
-
193
- die('OK');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
194
  }
195
-
196
  /**
197
- * Process optile status notification with statusCode 'failed', 'declined', 'aborted', 'canceled'
198
  * @param Mage_Sales_Model_Order $order
199
  */
200
  private function handleFailed($order) {
201
- $request = $this->_request;
202
  $params = $this->_params;
203
-
204
- // Only handle failures regarding payments.
205
- if ($params['entity'] != 'payment') {
206
- $msg = ' Not handling '. $params['entity'] .' status: "'. $params['statusCode'] .'"';
207
- $this->log(__METHOD__ . $msg, Zend_Log::NOTICE);
208
- die('NOTICE:'. $msg);
209
- }
210
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
211
  // Security overkill.
212
- if (!$order->canCancel()) {
213
- // If order is already canceled this is OK.
214
- if ($order->getStatus() == 'canceled') {
215
- $this->log(__METHOD__ .' Order already canceled.', Zend_Log::NOTICE);
216
- die('OK');
217
- }
218
- $msg = ' Order cannot be canceled! Current status: '. $order->getStatus();
219
- $this->log(__METHOD__ . $msg, Zend_Log::ERR);
220
- header($_SERVER['SERVER_PROTOCOL'] .' 500 Internal Error', true, 500);
221
- die('ERROR:'. $msg);
 
 
222
  }
223
-
224
  // Update order status.
225
- switch ($params['statusCode']) {
226
- case 'failed':
227
- $comment = 'Operation failed due to technical reasons';
228
- break;
229
- case 'declined':
230
- $comment = 'Operation declined by institution';
231
- break;
232
- case 'aborted':
233
- $comment = 'Operation aborted by customer';
234
- break;
235
- case 'canceled':
236
- $comment = 'Operation canceled';
237
- break;
238
- }
239
-
240
- if ($params['resultInfo']) {
241
- $comment .= ' ('. $params['resultInfo'] .')';
242
- }
243
-
244
- $this->log(__METHOD__ .' Updating order status...');
245
-
246
- $order
247
- ->getPayment()
248
- ->cancel();
249
-
250
- $order
251
- ->registerCancellation($comment)
252
- ->save();
253
-
254
- $this->log(__METHOD__ .' DONE');
255
-
256
- die('OK');
257
- }
258
-
259
- /**
260
- * Process optile status notification with statusCode 'expired'
261
- * @param Mage_Sales_Model_Order $order
262
- */
263
- private function handleExpired($order) {
264
- $request = $this->_request;
265
- $params = $this->_params;
266
-
267
- // "expired" notifications should reference entity types "session" or "payment".
268
- if (!in_array($params['entity'], array('session', 'payment'))) {
269
- $msg = ' Not handling '. $params['entity'] .' status: "'. $params['statusCode'] .'"';
270
- $this->log(__METHOD__ . $msg, Zend_Log::NOTICE);
271
- die('NOTICE:'. $msg);
272
- }
273
-
274
- $orderId = (int)$order->getId();
275
- // Security overkill.
276
- if (!$order->canCancel()) {
277
- $msg = ' Order cannot be canceled! Current status: '. $order->getStatus();
278
- $this->log(__METHOD__ . $msg, Zend_Log::ERR);
279
- header($_SERVER['SERVER_PROTOCOL'] .' 500 Internal Error', true, 500);
280
- die('ERROR:'. $msg);
281
- }
282
-
283
- $comment = 'Payment session timed out';
284
-
285
- if ($params['resultInfo']) {
286
- $comment .= ' ('. $params['resultInfo'] .')';
287
- }
288
-
289
- $this->log(__METHOD__ .' Updating order status...');
290
-
291
- $order
292
- ->getPayment()
293
- ->cancel();
294
-
295
  $order
296
- ->registerCancellation($comment)
297
- ->save();
298
-
299
- $this->log(__METHOD__ .' DONE');
300
-
301
- die('OK');
302
-
 
 
 
 
 
303
  }
304
-
305
  /**
306
  * Process optile status notification with statusCode 'charged_back'
307
  * @param Mage_Sales_Model_Order $order
308
- */
309
  private function handleChargedBack($order) {
310
- $request = $this->_request;
311
-
312
- // @TODO: how to handle?
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
313
  }
314
-
315
  /**
316
- * Process optile status notification with statusCode 'pending' - pending payments (eg 3D Secure).
317
- *
 
318
  * @param Mage_Sales_Model_Order $order
319
- */
320
  private function handlePending($order) {
321
- $request = $this->_request;
322
  $payment = $order->getPayment();
323
  $params = $this->_params;
324
-
325
- // Only handle pending payments (we're here to verify the amount).
326
- if ($params['entity'] != 'payment') {
327
- $msg = ' Not handling '. $params['entity'] .' status: "'. $params['statusCode'] .'"';
328
- $this->log(__METHOD__ . $msg, Zend_Log::NOTICE);
329
- die('NOTICE:'. $msg);
330
- }
331
-
332
- // Match amount if there is one in the message.
333
- $orderSum = (float) $order->getGrandTotal();
334
- $paramSum = (float) $params['amount'];
335
- if (strlen($params['amount']) && $orderSum !== $paramSum) {
336
- $msg = ' Authorized amount ('. $paramSum .') does not match order amount ('. $orderSum .')';
337
- $this->log(__METHOD__ . $msg, Zend_Log::ERR);
338
-
339
- $payment->registerCaptureNotification($paramSum);
340
- $order->save();
341
-
342
- header($_SERVER['SERVER_PROTOCOL'] .' 500 Internal Error', true, 500);
343
- die('ERROR:'. $msg);
344
- }
345
-
346
- $comment = 'Payment is pending (3D Secure authentication)';
347
- $order->addStatusHistoryComment($comment)->save();
348
-
349
- $this->log(__METHOD__ .' DONE');
350
-
351
- die('OK');
352
-
 
 
 
 
 
 
 
 
 
 
353
  }
354
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  <?php
2
  /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
 
 
 
14
  *
15
  * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
  */
19
 
20
  /**
21
  * Optile notification handler model
22
  *
23
  */
24
+ class Optile_Payment_Model_Notification extends Mage_Core_Model_Abstract {
25
+
26
+ const STATUS_UNEXPECTED = 'unexpected_notification';
27
+
28
+ private $reason_codes = array(
29
+ 'charged' => array(
30
+ 'debited' => 'Charge completed',
31
+ 'debited_partial' => 'Debited partially', //2016-03-10 NEW
32
+ 'payment_received' => 'Charge completed',
33
+ ),
34
+ 'paid_out' => array(
35
+ 'refund_credited' => 'Payout completed',
36
+ 'credited' => 'Payout completed',
37
+ ),
38
+ 'preauthorized' => array(
39
+ // Deferred payment notification codes
40
+ 'preauthorized' => 'Preauthorization OK',
41
+ 'debited_partial' => 'A successfull Deferred Charge has been partially closed',
42
+ ),
43
+
44
+ 'pending' => array(
45
+ 'debit_requested' => 'Operation pending. Please wait for further notification',
46
+ 'refund_requested' => 'Operation pending',
47
+ 'payment_demand_requested' => 'Operation pending',
48
+ 'payment_demanded' => 'Operation pending',
49
+ 'credit_requested' => 'Operation pending',
50
+ 'retry_scheduled' => 'Payment retry scheduled', //2016-03-10 NEW
51
+ // Deferred payment notification codes
52
+ 'preauthorization_requested' => 'Operation pending',
53
+ 'preorder_issued' => 'Operation pending',
54
+ 'preorder_requested' => 'Operation pending',
55
+ 'cancelation_requested' => 'Operation pending',
56
+ ),
57
+ 'failed' => array(
58
+ 'debit_failed' => 'Operation failed due to the technical reasons',
59
+ 'refund_failed' => 'Operation failed due to the technical reasons',
60
+ 'payment_demand_failed' => 'Operation failed due to the technical reasons',
61
+ 'credit_failed' => 'Operation failed due to the technical reasons',
62
+ // Deferred payment notification codes
63
+ 'preauthorization_failed' => 'Preauthorization failed due to the technical reasons',
64
+ 'preorder_failed' => 'Preorder failed due to the technical reasons',
65
+ ),
66
+ 'declined' => array(
67
+ 'debit_declined' => 'Operation declined by institution for business reasons',
68
+ 'refund_declined' => 'Operation declined by institution for business reasons',
69
+ 'payment_demand_declined' => 'Operation declined by institution for business reasons',
70
+ 'credit_declined' => 'Operation declined by institution for business reasons',
71
+ // Deferred payment notification codes
72
+ 'preauthorization_declined' => 'Operation declined by institution for business reasons',
73
+ 'preorder_declined' => 'Operation declined by institution for business reasons',
74
+ ),
75
+ 'aborted' => array(
76
+ 'debit_aborted' => 'Operation aborted by customer',
77
+ 'payment_demand_aborted' => 'Operation aborted by customer',
78
+ // Deferred payment notification codes
79
+ 'preauthorization_aborted' => 'Operation aborted by customer',
80
+ ),
81
+ 'expired' => array(
82
+ // Deferred payment notification codes
83
+ 'preauthorization_expired' => 'Preauthorization reference has expired',
84
+ 'request_expired' => 'Request operation has expired',
85
+ ),
86
+ 'depleated' => array(
87
+ // Deferred payment notification codes
88
+ 'preauthorization_depleted' => 'Authorized amount has been debited',
89
+ ),
90
+ 'charged_back' => array(
91
+ 'charged_back' => 'Amount charged back form merchant account due to customer complaint or dispute',
92
+ ),
93
+ 'information_requested' => array(
94
+ 'information_requested' => 'Charge disputed by customer',
95
+ ),
96
+ 'dispute_closed' => array(
97
+ 'dispute_closed' => 'Dispute closed',
98
+ 'chargeback_canceled' => 'Chargeback canceled',
99
+ ),
100
+ 'canceled' => array(
101
+ 'debit_canceled' => 'Operation canceled by merchant',
102
+ 'refund_canceled ' => 'Operation canceled by merchant',
103
+ 'payment_demand_canceled ' => 'Operation canceled by merchant',
104
+ 'receipt_canceled ' => 'Operation canceled by merchant',
105
+ 'credit_canceled ' => 'Operation canceled by merchant',
106
+ // Deferred payment notification codes
107
+ 'preorder_canceled' => 'Preorder canceled',
108
+ 'preauthorization_canceled' => 'Preauthorization canceled',
109
+ ),
110
+ );
111
+
112
+ protected function _construct() {
113
+ $this->_init('optile/notification', 'id');
114
+ }
115
+
116
+ protected function isInvoiceNotificationEnabled(){
117
+ return Mage::getStoreConfig('payment/optile/invoice_notification');
118
+ }
119
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120
  /**
121
  * Magento request params instance
122
  */
123
  protected $_params;
124
+
125
  /**
126
+ * Returns optile notification IPs (configured in admin).
127
  * Other IPs are blacklisted for notifications
128
+ *
129
+ * Test server (sandbox.oscato.com) => 144.76.239.125
130
  * Production server (oscato.com) => 213.155.71.162
131
+ *
132
  * @return string
133
  */
134
  private function getAllowedIP() {
135
+ return Mage::getStoreConfig('payment/optile/remote_ip');
 
 
 
 
 
136
  }
137
+
138
  /**
139
  * Process status notification
140
+ *
141
  * @param Magento Request $request
142
  */
143
  public function processNotification($request) {
144
+
145
+ Mage::register('optile_ipn', true);
146
+ $params = $request->getParams();
147
+ if(isset($params['transactionId'])){
148
+ //Stripping the quote prefix
149
+ $params['transactionId'] = str_replace(Mage::helper('optile')->getQuotePrefix(), "", $params['transactionId']);
150
+ }
151
+ $this->_params = $params;
152
+
153
+ $this->setDate(date('Y-m-d H:i:s'));
154
+ $this->setReceivedData($params);
155
+ $this->save();
156
+
157
+ Mage::helper('optile')->log(__METHOD__ .' INCOMING IPN from: '.$_SERVER['REMOTE_ADDR'], Zend_Log::INFO);
158
+ Mage::helper('optile')->log($params, Zend_Log::INFO);
159
+
160
+ // Authenticity check by verifying IP address.
161
  $allowed_ip = $this->getAllowedIP();
162
+ $proxy_ip = Mage::getStoreConfig('payment/optile/proxy_ip');
163
+
164
+ if (!Mage::getIsDeveloperMode() && $proxy_ip && ($_SERVER['REMOTE_ADDR'] != $proxy_ip || !isset($_SERVER['HTTP_X_FORWARDED_FOR']))) {
165
+ // Configured proxy / load balancer IP address does not match.
166
+ Mage::helper('optile')->log(__METHOD__ .' Bad configuration value for proxy / load balancer', Zend_Log::ERR);
167
+ if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
168
+ Mage::helper('optile')->log(__METHOD__ .' Suggested configuration: '. $_SERVER['REMOTE_ADDR'], Zend_Log::ERR);
169
+ } else {
170
+ Mage::helper('optile')->log(__METHOD__ .' No proxy detected!', Zend_Log::ERR);
171
+ }
172
+ $this->exitWithMsg("Access denied", 403);
173
  }
174
+ if (!Mage::getIsDeveloperMode() && $allowed_ip != ($proxy_ip ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'])) {
175
+ Mage::helper('optile')->log(__METHOD__ .' UNAUTHORIZED ACCESS FROM: '. $_SERVER['REMOTE_ADDR'], Zend_Log::ALERT);
176
+ $this->exitWithMsg("Access denied", 403);
177
+ }
178
+
179
+ // Only handle failures regarding payments.
180
+ if ($params['entity'] != 'payment') {
181
+ $msg = ' Not handling '. $params['entity'] .' status: "'. $params['statusCode'] .'"';
182
+ Mage::helper('optile')->log(__METHOD__ . $msg, Zend_Log::NOTICE);
183
+ $this->exitWithMsg('NOTICE:'. $msg);
 
 
 
 
184
  }
185
+
186
+ $i = 0;
187
+ $quote_has_reserved_id = false;
188
+ // Try a few times, Magento is slow.
189
+ while($i < 3 && !$quote_has_reserved_id){
190
+ $quote = Mage::getModel('sales/quote')->load($params['transactionId']);
191
+ if(!$quote->getId()) {
192
+ // MVR_NAT_SC2 - If order/quote ID is not found, accept the notification and do nothing.
193
+ $msg = 'Quote with ID '. $params['transactionId'] .' not found.';
194
+ Mage::helper('optile')->log($msg, Zend_Log::NOTICE);
195
+ $this->exitWithMsg($msg);
196
+ }
197
+ $quote_has_reserved_id = $quote->getReservedOrderId();
198
+ if($quote_has_reserved_id){
199
+ Mage::helper('optile')->log('Reserved orderID found. Not Sleeping anymore.');
200
+ break; // no need to sleep
201
+ }
202
+ Mage::helper('optile')->log('Reserved orderID not set yet. Sleeping: '.($i+1).' time(s).');
203
+ sleep(2);
204
+ $i++;
205
+ }
206
+
207
+ if(!$quote->getReservedOrderId()) {
208
+ //2016-03-10: T: What if order will never exist, because payment failed?
209
+ //Check if the statusCode is failed/aborted/canceled/expired first. If so, it is ok to return status 200
210
+ if(in_array($params['statusCode'], ['declined', 'aborted', 'expired', 'failed'])){
211
+ $this->exitWithMsg("Transaction #".Mage::helper('optile')->getQuotePrefix().$params['transactionId']." has failed. Returning status 200");
212
+ }
213
+
214
+ $msg = 'Quote with ID '. $params['transactionId'] .' found, but orderID not set yet.';
215
+ Mage::helper('optile')->log($msg, Zend_Log::NOTICE);
216
+ $this->exitWithMsg($msg, 500);
217
+ }
218
+
219
  $orderIncrementId = $quote->getReservedOrderId();
220
  $order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
221
+
222
  switch($params['statusCode']) {
223
  case 'charged':
224
  $this->handleCharged($order);
225
  break;
226
+ case 'charged_back':
227
+ $this->handleChargedBack($order);
228
+ break;
229
+ case 'information_requested':
230
+ $this->handleInfoRequested($order);
231
+ break;
232
+ case 'dispute_closed':
233
+ $this->handleDisputeClosed($order);
234
+ break;
235
+ // case 'registered':
236
+ // // @TODO
237
  case 'failed':
238
  case 'declined':
239
  case 'aborted':
240
  case 'canceled':
 
 
241
  case 'expired':
242
+ $this->handleFailed($order);
243
  break;
244
  case 'pending':
245
  $this->handlePending($order);
246
  break;
247
+ case 'preauthorized':
248
+ $this->handlePreauthorized($order);
249
+ break;
250
  default:
251
  $msg = "Not handling ".$params['statusCode'];
252
+ Mage::helper('optile')->log($msg, Zend_Log::NOTICE);
253
+ $this->exitWithMsg($msg);
254
  }
255
+
256
  }
257
+
258
+ private function handlePreauthorized($order){
259
+
260
+ $payment = $order->getPayment();
261
+ /* @var $payment Mage_Sales_Model_Order_Payment */
262
+
263
+ $params = $this->_params;
264
+ $reason_code = isset($this->_params['reasonCode']) ? $this->_params['reasonCode'] : "";
265
+ $interaction_code = isset($this->_params['interactionCode']) ? $this->_params['interactionCode'] : "";
266
+
267
+ Mage::helper('optile')->log(__METHOD__ .' Registering preauthorized notification...');
268
+ Mage::helper('optile')->log(__METHOD__.': Loading OptileQuote #'.$order->getQuoteId(), Zend_log::INFO);
269
+ // Update our own table with some useful data.
270
+ $optileQuote = Mage::getModel('optile/quote')
271
+ ->load($order->getQuoteId());
272
+
273
+ // 'debited_partial' IPN come after a partial invoice.
274
+ if($reason_code == 'debited_partial') {
275
+ $this->exitWithMsg("Received 'debited_partial' IPN, accepting.");
276
+ }
277
+
278
+ Mage::helper('optile')->log(__METHOD__ .' Order is in payment review: '. ($order->isPaymentReview() ? 'YES' : 'NO'), Zend_Log::INFO);
279
+ if ($order->isPaymentReview()) {
280
+ if ($optileQuote->hasLongId()) {
281
+ $comment = 'Payment has been preauthorized, status will be updated later';
282
+ } else {
283
+ $comment = 'Payment has been preauthorized. Updating longId to '. $this->_params['longId'].'. In order to preform payment Capture, please create an Invoice now.';
284
+ }
285
+
286
+ $comment .= " (optile reason code: {$reason_code}, interaction code: {$interaction_code})";
287
+ Mage::helper('optile')->log(__METHOD__.': '.$comment, Zend_log::INFO);
288
+ $order->addStatusHistoryComment($comment); //->save();
289
+ } else {
290
+ // MVR_NAT_SC2 5.3 Unexpected notification, accept and change status.
291
+ $msg = 'Order is no longer pending!';
292
+ $comment = 'Received notification "'. $params['statusCode'] .'" but the order is already paid or canceled.';
293
+ $comment .= ' Details: '. $params['resultInfo'];
294
+
295
+ $comment .= " (optile reason code: {$reason_code}, interaction code: {$interaction_code})";
296
+ Mage::helper('optile')->log(__METHOD__.': '.$comment, Zend_log::INFO);
297
+ $this->exitUnexpectedNotification($order, $msg, $comment);
298
+ }
299
+
300
+ $optileQuote
301
+ ->setLongId($this->_params['longId'])
302
+ ->setPaymentNetwork($this->_params['network'])
303
+ ->setMonitorLink($this->generateMonitorLink($order))
304
+ ->setDeferredMode(Optile_Payment_Model_Quote::DEFERRED)
305
+ ->save();
306
+ ;
307
+
308
+ Mage::helper('optile')->log(__METHOD__.'Accepting payment', Zend_Log::INFO);
309
+ $payment->accept();
310
+ $order->save();
311
+ // $order->getPayment()->accept();
312
+ try {
313
+ $order->sendNewOrderEmail();
314
+ } catch (Exception $e) {
315
+ Mage::helper('optile')->log($e->getMessage(), Zend_log::WARN);
316
+ Mage::logException($e);
317
+ }
318
+ $order->save();
319
+
320
+ Mage::helper('optile')->log(__METHOD__ .' DONE');
321
+ $this->exitWithMsg('OK');
322
+ }
323
+
324
+ /**
325
+ * Internal helper method for generating a monitor link.
326
+ * @param Mage_Sales_Model_Order $order
327
+ */
328
+ private function generateMonitorLink($order){
329
+ // Base URL for viewing transactions in Optile Monitor.
330
+ $viewUrl = rtrim(Mage::getStoreConfig('payment/optile/api_url', $order->getStore()), '/');
331
+ $viewUrl .= '/monitor/transactions/%s';
332
+ return sprintf($viewUrl, $this->_params['longId']);
333
+ }
334
+
335
  /**
336
  * Process optile status notification with statusCode 'charged'
337
  * @param Mage_Sales_Model_Order $order
338
  */
339
  private function handleCharged($order) {
340
+
341
+ $reason_code = isset($this->_params['reasonCode']) ? $this->_params['reasonCode'] : "";
342
+ $interaction_code = isset($this->_params['interactionCode']) ? $this->_params['interactionCode'] : "";
343
+ $payment = $order->getPayment(); /* @var $payment Mage_Sales_Model_Order_Payment */
344
+
345
+ $optileQuote = Mage::getModel('optile/quote')
346
+ ->load($order->getQuoteId()); /* @var $optileQuote Optile_Payment_Model_Quote */
347
+
348
+ // If order is in deferred mode, just accept the notification.
349
+ if($optileQuote->getDeferredMode() == Optile_Payment_Model_Quote::DEFERRED){
350
+
351
+ // TODO: Should we check everything again, just in case?
352
+ $this->exitWithMsg("Deferred CHARGE accepted.");
353
+ }
354
+
355
+ // 'debited_partial' IPN comes unexpectedly after a partial refund. Refund is actually handled in PaymentMethod.php.
356
+ if($reason_code == 'debited_partial') {
357
+ $this->exitWithMsg("Received 'debited_partial' IPN, accepting.");
358
+ }
359
+
360
+ // Check current order status.
361
+ if (!$order->isPaymentReview() || $order->getStatus() == Mage_Sales_Model_Order::STATUS_FRAUD) {
362
+ // Prepare response to Optile.
363
+ $state = $order->getState();
364
+ $status = $order->getStatus();
365
+ $msg = sprintf('Current order state does not allow payments (%s / %s)', $state, $status);
366
+
367
+ // Prepare order status history comment.
368
+ $comment = 'Rejected payment notification because order status is: ';
369
+ $comment .= $order->getStatusLabel();
370
+ $comment .= " (optile reason code: {$reason_code}, interaction code: {$interaction_code})";
371
+
372
+ // Send messages and end execution.
373
+ $this->exitUnexpectedNotification($order, $msg, $comment);
374
+ }
375
+
376
+ // Match amount. TODO: refactor this!
377
  $orderSum = (float) $order->getGrandTotal();
378
  $paramSum = (float) $this->_params['amount'];
379
  if ($orderSum !== $paramSum) {
380
+ $msg = 'Authorized amount ('. $paramSum .') does not match order amount ('. $orderSum .')';
381
+
 
382
  $payment->registerCaptureNotification($paramSum);
383
  $order->save();
384
+
385
+ Mage::helper('optile')->log($msg, Zend_Log::ERR);
386
+ $this->exitWithMsg($msg);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
387
  }
388
+
389
  // Update payment.
390
+ Mage::helper('optile')->log(__METHOD__ .' Updating payment...');
391
+
392
+
393
  $payment->registerCaptureNotification($paramSum);
394
+ $invoice = $payment->getCreatedInvoice();
395
+ /* @var $invoice Mage_Sales_Model_Order_Invoice */
396
+
397
+ if ($invoice) {
398
+ try{
399
+ $invoice->setTransactionId($this->_params['longId']);
400
+ $invoice->save(); // Saving invoice to get the Increment ID
401
+ $message = Mage::helper('optile')->__('Notified customer about invoice #%s.', $invoice->getIncrementId());
402
+ $message .= " (optile reason code: {$reason_code}, interaction code: {$interaction_code})";
403
+
404
+ Mage::helper('optile')->log(__METHOD__ .' Sending invoice email.');
405
+ $invoice->sendEmail(true);
406
+ $order->addStatusHistoryComment($message)
407
+ ->setIsCustomerNotified(true);
408
+
409
+ } catch (Exception $e){
410
+ Mage::helper('optile')->log(__METHOD__ .' Sending invoice email failed:', Zend_Log::ERR);
411
+ Mage::helper('optile')->log($e->getMessage(), Zend_Log::ERR);
412
+ }
413
+ }
414
+
415
+ $order->save(); // Fix for Magento 1.8.1 because $order->sendNewOrderEmail now reloads the order
416
+ try {
417
+ $order->sendNewOrderEmail();
418
+ } catch (Exception $e) {
419
+ Mage::helper('optile')->log($e->getMessage(), Zend_log::ERR);
420
+ Mage::logException($e);
421
+ }
422
+ $order->save();
423
+
424
+ Mage::helper('optile')->log(__METHOD__ .' Updating Optile quote data..');
425
+
426
+ $optileQuote
427
+ ->setLongId($this->_params['longId'])
428
+ ->setPaymentNetwork($this->_params['network'])
429
+ ->setMonitorLink($this->generateMonitorLink($order))
430
+ ->save();
431
+ ;
432
+
433
+ Mage::helper('optile')->log(__METHOD__ .' DONE');
434
+ $this->exitWithMsg("OK");
435
  }
436
+
437
  /**
438
+ * Process optile status notification with statusCode 'failed', 'declined', 'aborted', 'canceled', 'expired'
439
  * @param Mage_Sales_Model_Order $order
440
  */
441
  private function handleFailed($order) {
 
442
  $params = $this->_params;
443
+ $reason_code = isset($this->_params['reasonCode']) ? $this->_params['reasonCode'] : "";
444
+ $interaction_code = isset($this->_params['interactionCode']) ? $this->_params['interactionCode'] : "";
445
+
446
+ Mage::helper('optile')->log(__METHOD__ .' Handling payment failure...', Zend_Log::INFO);
447
+ Mage::helper('optile')->log(__METHOD__ .' Loading Quote...');
448
+ // Match Long Id on the quote.
449
+ $optileQuote = Mage::getModel('optile/quote')
450
+ ->load($order->getQuoteId());
451
+
452
+ if (!$optileQuote->hasLongId()) {
453
+ // LongId not set on quote yet. It's not possible to determine the
454
+ // relevance of this IPN at this moment. Try again later.
455
+ $msg = 'Long ID could not be verified yet; try again later.';
456
+ $this->exitWithMsg($msg, 500);
457
+ }
458
+
459
+ if ($optileQuote->getLongId() != $this->_params['longId']) {
460
+ // LongId is of a different LIST request. In this context that
461
+ // should be rather strange.
462
+ $msg = "Could not match LongId: {$this->_params['longId']} to Magento quote: {$optileQuote->getTransactionId()}. Ignoring this notification.";
463
+ Mage::helper('optile')->log(__METHOD__ . $msg, Zend_Log::WARN);
464
+ $this->exitWithMsg('OK');
465
+ }
466
+
467
+ Mage::helper('optile')->log('Current order status: '.$order->getStatus(), Zend_Log::INFO);
468
+
469
+ // If order is already canceled this is OK.
470
+ if ($order->isCanceled()) {
471
+ Mage::helper('optile')->log(__METHOD__ .' Order already canceled.', Zend_Log::INFO);
472
+ $this->exitWithMsg('OK');
473
+ }
474
+
475
+ if($order->isPaymentReview()){
476
+ Mage::helper('optile')->log(__METHOD__ .' Registering payment review denial...', Zend_Log::INFO);
477
+ $order->getPayment()->deny();
478
+ }
479
+
480
  // Security overkill.
481
+ if ($optileQuote->getDeferredMode() == Optile_Payment_Model_Quote::NON_DEFERRED
482
+ && !$order->isCanceled()
483
+ && !$order->canCancel()) {
484
+
485
+ // MVR_NAT_SC2 5.3 Unexpected notification, accept and change status.
486
+ $msg = 'Order cannot be canceled! Current status: '. $order->getStatus();
487
+ $comment = 'Received notification "'. $params['statusCode'] .'" but order cannot be canceled!';
488
+ $comment .= ' Details: '. $params['resultInfo'];
489
+ $comment .= " (optile reason code: {$reason_code}, interaction code: {$interaction_code})";
490
+
491
+ Mage::helper('optile')->log($msg, Zend_log::ERR);
492
+ $this->exitUnexpectedNotification($order, $msg, $comment);
493
  }
494
+
495
  // Update order status.
496
+ if(isset($this->reason_codes[$params['statusCode']]) && isset($this->reason_codes[$params['statusCode']][$params['reasonCode']])){
497
+ $comment = $this->reason_codes[$params['statusCode']][$params['reasonCode']];
498
+ }else{
499
+ $comment = 'Received IPN notification: '.$params['statusCode'].' - '.$params['reasonCode'];
500
+ Mage::helper('optile')->log('Unknown IPN received: '.$comment, Zend_log::WARN);
501
+ }
502
+
503
+ // if (isset($params['resultInfo']) && strlen($params['resultInfo']) > 0 ) {
504
+ // $comment .= ' ('. $params['resultInfo'] .')';
505
+ // }
506
+ $comment .= " (optile reason code: {$reason_code}, interaction code: {$interaction_code})";
507
+
508
+ Mage::helper('optile')->log(__METHOD__ .' Cancelling order and adding comment: '.$comment, Zend_Log::INFO);
509
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
510
  $order
511
+ ->cancel()
512
+ ->addStatusToHistory(FALSE, $comment, (int)$order->getEmailSent())
513
+ ->setOptileStatusCode($this->_params['statusCode'])
514
+ ->save()
515
+ ;
516
+
517
+ Mage::helper('optile')->log(__METHOD__ .' Dispatching optile_notification_failed event.', Zend_Log::INFO);
518
+ Mage::dispatchEvent('optile_notification_failed', array('order' => $order));
519
+
520
+
521
+ Mage::helper('optile')->log(__METHOD__ .' DONE');
522
+ $this->exitWithMsg('OK');
523
  }
524
+
525
  /**
526
  * Process optile status notification with statusCode 'charged_back'
527
  * @param Mage_Sales_Model_Order $order
528
+ */
529
  private function handleChargedBack($order) {
530
+ // Create creditmemo and set order status to Closed.
531
+ $payment = $order->getPayment();
532
+ $params = $this->_params;
533
+ $reason_code = isset($this->_params['reasonCode']) ? $this->_params['reasonCode'] : "";
534
+ $interaction_code = isset($this->_params['interactionCode']) ? $this->_params['interactionCode'] : "";
535
+
536
+ Mage::helper('optile')->log(__METHOD__ .' Registering incoming chargeback notification...', Zend_Log::INFO);
537
+
538
+ // This notification is "unexpected" if order not invoiced.
539
+ $comment = 'Registered notification about refunded amount of '. $params['amount'];
540
+ $comment .= " (optile reason code: {$reason_code}, interaction code: {$interaction_code})";
541
+
542
+ if ($order->canCreditmemo()) {
543
+ $order->addStatusHistoryComment($comment);
544
+ } else {
545
+ $order->addStatusToHistory(self::STATUS_UNEXPECTED, $comment);
546
+ }
547
+ $order->save();
548
+
549
+ // On top of this in-context notification, notify the customer more intrusively.
550
+ $inbox = Mage::getModel('adminnotification/inbox');
551
+ /* @var $inbox Mage_AdminNotification_Model_Inbox */
552
+ $inbox->add(
553
+ Mage_AdminNotification_Model_Inbox::SEVERITY_MAJOR,
554
+ 'A Chargeback notification has been received from Optile. Please go to Order '. $order->getIncrementId() .' and review it.',
555
+ 'To review the order that has been charged back, go to Sales -> Orders, find the order with ID '. $order->getIncrementId() .' and open it.'
556
+ );
557
+
558
+ Mage::helper('optile')->log(__METHOD__ .' DONE');
559
+ $this->exitWithMsg('OK');
560
+
561
+ // The following causes serious problems if multiple partial charge backs
562
+ // are received, so we're just setting status history comment for now.
563
+
564
+ try {
565
+ $payment->registerRefundNotification(abs($params['amount']));
566
+ $order->save();
567
+ } catch (Exception $e) {
568
+ $msg = $e->getMessage();
569
+ $this->exitWithMsg($msg);
570
+ }
571
+
572
+ Mage::helper('optile')->log(__METHOD__ .' DONE');
573
+ $this->exitWithMsg('OK');
574
  }
575
+
576
  /**
577
+ * Process optile status notification with statusCode 'pending'
578
+ * - pending payments (eg 3D Secure, Paypal).
579
+ *
580
  * @param Mage_Sales_Model_Order $order
581
+ */
582
  private function handlePending($order) {
 
583
  $payment = $order->getPayment();
584
  $params = $this->_params;
585
+ $reason_code = isset($this->_params['reasonCode']) ? $this->_params['reasonCode'] : "";
586
+ $interaction_code = isset($this->_params['interactionCode']) ? $this->_params['interactionCode'] : "";
587
+
588
+
589
+ Mage::helper('optile')->log(__METHOD__ .' Registering pending notification...', Zend_Log::INFO);
590
+ Mage::helper('optile')->log(__METHOD__.': Loading OptileQuote #'.$order->getQuoteId(), Zend_Log::INFO);
591
+ // Update our own table with some useful data.
592
+ $optileQuote = Mage::getModel('optile/quote')
593
+ ->load($order->getQuoteId());
594
+
595
+ if ($order->isPaymentReview()) {
596
+ if ($optileQuote->hasLongId()) {
597
+ $comment = 'Payment is pending, status will be updated later';
598
+ } else {
599
+ $comment = 'Payment is pending. Updating longId to '. $this->_params['longId'];
600
+ }
601
+ $comment .= " (optile reason code: {$reason_code}, interaction code: {$interaction_code})";
602
+ Mage::helper('optile')->log(__METHOD__.': '.$comment, Zend_log::INFO);
603
+ $order->addStatusHistoryComment($comment)->save();
604
+ } else {
605
+ // MVR_NAT_SC2 5.3 Unexpected notification, accept and change status.
606
+ $msg = 'Order is no longer pending!';
607
+ $comment = 'Received notification "'. $params['statusCode'] .'" but the order is already paid or canceled.';
608
+ $comment .= ' Details: '. $params['resultInfo'];
609
+ $comment .= " (optile reason code: {$reason_code}, interaction code: {$interaction_code})";
610
+
611
+ Mage::helper('optile')->log(__METHOD__.': '.$comment, Zend_log::NOTICE);
612
+ // $this->exitUnexpectedNotification($order, $msg, $comment);
613
+ }
614
+
615
+ $optileQuote
616
+ ->setLongId($this->_params['longId'])
617
+ ->setPaymentNetwork($this->_params['network'])
618
+ ->setMonitorLink($this->generateMonitorLink($order))
619
+ ->save();
620
+ ;
621
+
622
+ Mage::helper('optile')->log(__METHOD__ .' DONE');
623
+ $this->exitWithMsg('OK');
624
  }
625
+
626
+ /**
627
+ * Process optile status notification with statusCode 'information_requested'
628
+ * - customers opening disputes through their payment network.
629
+ *
630
+ * @param Mage_Sales_Model_Order $order
631
+ */
632
+ private function handleInfoRequested($order) {
633
+ $reason_code = isset($this->_params['reasonCode']) ? $this->_params['reasonCode'] : "";
634
+ $interaction_code = isset($this->_params['interactionCode']) ? $this->_params['interactionCode'] : "";
635
+ $comment = 'Charge disputed by customer; provide more information.';
636
+ $comment .= " (optile reason code: {$reason_code}, interaction code: {$interaction_code})";
637
+
638
+ if ($order->canCreditmemo()) {
639
+ $order->addStatusHistoryComment($comment);
640
+ } else {
641
+ $order->addStatusToHistory(self::STATUS_UNEXPECTED, $comment);
642
+ }
643
+ $order->save();
644
+
645
+ // On top of this in-context notification, notify the customer more intrusively.
646
+ $inbox = Mage::getModel('adminnotification/inbox');
647
+ /* @var $inbox Mage_AdminNotification_Model_Inbox */
648
+ $inbox->add(
649
+ Mage_AdminNotification_Model_Inbox::SEVERITY_MAJOR,
650
+ 'A dispute notification has been received from Optile. Please go to Order '. $order->getIncrementId() .' and review it.',
651
+ 'Information has been requested about a charge. To review the order in question, go to Sales -> Orders, find the order with ID '. $order->getIncrementId() .' and open it.'
652
+ );
653
+
654
+ $this->exitWithMsg('OK');
655
+ }
656
+
657
+ /**
658
+ * Process optile status notification with statusCode 'dispute_closed'
659
+ * - payment network / provider closing disputes.
660
+ *
661
+ * @param Mage_Sales_Model_Order $order
662
+ */
663
+ private function handleDisputeClosed($order) {
664
+ $params = $this->_params;
665
+ $reason_code = isset($this->_params['reasonCode']) ? $this->_params['reasonCode'] : "";
666
+ $interaction_code = isset($this->_params['interactionCode']) ? $this->_params['interactionCode'] : "";
667
+ $comment = 'Dispute closed.';
668
+
669
+ if ($params['reasonCode'] == 'chargeback_canceled') {
670
+ $comment .= ' Chargeback canceled.';
671
+ }
672
+
673
+ $comment .= " (optile reason code: {$reason_code}, interaction code: {$interaction_code})";
674
+ $order->addStatusHistoryComment($comment)->save();
675
+
676
+ // On top of this in-context notification, notify the customer more intrusively.
677
+ $inbox = Mage::getModel('adminnotification/inbox');
678
+ /* @var $inbox Mage_AdminNotification_Model_Inbox */
679
+ $inbox->add(
680
+ Mage_AdminNotification_Model_Inbox::SEVERITY_NOTICE,
681
+ 'The charge dispute on Order '. $order->getIncrementId() .' has been closed.',
682
+ 'No further action is required.'
683
+ );
684
+
685
+ $this->exitWithMsg('OK');
686
+ }
687
+
688
+ /**
689
+ * Handles unexpected notification by adding a critical message to the
690
+ * notification inbox, adding a comment to the order history, logging a
691
+ * message to the log file, and giving the log message as a response to
692
+ * Optile. Other than that this will accept the message normally.
693
+ * Calling this method ends code execution.
694
+ *
695
+ * @param Mage_Sales_Model_Order $order
696
+ * @param string $responseMsg
697
+ * @param string $adminMsg
698
+ */
699
+ private function exitUnexpectedNotification($order, $responseMsg, $adminMsg) {
700
+
701
+ // Change status to "Unexpected Optile notification" and add message.
702
+ $order->addStatusToHistory(self::STATUS_UNEXPECTED, $adminMsg)->save();
703
+
704
+ // Additionally raise a system-wide alert.
705
+ // Encourage merchant to report bugs.
706
+ $email = 'support@optile.zendesk.com';
707
+ $subject = urlencode('Optile Magento extension: unexpected notification');
708
+ $body = urlencode('Dear supportdesk,
709
+
710
+ The following unexpected notification was encountered in my Magento store:
711
+
712
+ statusCode: '. $this->_params['statusCode']. '
713
+ interactionCode: '. $this->_params['interactionCode'].'
714
+ longId: '. $this->_params['longId']. '
715
+
716
+ Order state and status: '. $order->getState() .' / '. $order->getStatus() .'
717
+ My merchant code is: '. Mage::getStoreConfig('payment/optile/merchant_code') .'
718
+ ');
719
+ $adminMsg .= "<br/>Please report this to Optile: <a href='mailto:$email?subject=$subject&body=$body'>$email</a>";
720
+
721
+ $inbox = Mage::getModel('adminnotification/inbox');
722
+ /* @var $inbox Mage_AdminNotification_Model_Inbox */
723
+ $inbox->add(
724
+ Mage_AdminNotification_Model_Inbox::SEVERITY_CRITICAL,
725
+ 'Optile Payment Extension: unexpected notification received for order # '. $order->getRealOrderId(),
726
+ $adminMsg
727
+ );
728
+
729
+ // Respond with an error and exit.
730
+ $this->exitWithMsg($responseMsg);
731
+ }
732
+
733
+ /**
734
+ * Send response to Optile and exit. Also logs response in the log file.
735
+ *
736
+ * @param string $responseMsg Message to be logged and sent to Optile
737
+ * @param int $responseCode HTTP response code
738
+ */
739
+ private function exitWithMsg($responseMsg, $responseCode=200) {
740
+ // Log our response to Optile in the log file.
741
+ Mage::helper('optile')->log(__CLASS__.": ".$responseCode.", Message: ".$responseMsg, Zend_Log::INFO);
742
+ $this->setStatus($responseCode);
743
+ $this->save(); // Saving the request data before exiting.
744
+
745
+ throw new Exception($responseMsg, $responseCode);
746
+ }
747
+
748
+ /**
749
+ * Sets the data to serialized field. Also fills in searchable data to
750
+ * their respectable fields: longId, network, currency, amount
751
+ * @param array $params
752
+ * @return Optile_Payment_Model_Notification
753
+ */
754
+ public function setReceivedData($params){
755
+
756
+ if(isset($params['longId'])) { $this->setData('long_id', $params['longId']); }
757
+ // if(isset($params['network'])) { $this->setData('network', $params['network']); }
758
+ // if(isset($params['currency'])) { $this->setData('currency', $params['currency']); }
759
+ // if(isset($params['amount'])) { $this->setData('amount', $params['amount']); }
760
+
761
+ // T: Saving only interesting dataset
762
+ if(isset($params['returnCode'])) { $this->setData('return_code', $params['returnCode']); }
763
+ if(isset($params['interactionCode'])) { $this->setData('interaction_code', $params['interactionCode']); }
764
+ if(isset($params['reasonCode'])) { $this->setData('reason_code', $params['reasonCode']); }
765
+ if(isset($params['resultInfo'])) { $this->setData('result_info', $params['resultInfo']); }
766
+
767
+ if(isset($params['transactionId'])){ $this->setData('transaction_id', $params['transactionId']); }
768
+
769
+ return $this->setData('received_data', json_encode($params));
770
+ }
771
+
772
+ public function getReceivedData(){
773
+ return json_decode($this->getData('received_data'));
774
+ }
775
+
776
+ }
app/code/community/Optile/Payment/Model/Observer.php ADDED
@@ -0,0 +1,231 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
14
+ *
15
+ * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
+ */
19
+
20
+ class Optile_Payment_Model_Observer
21
+ {
22
+ const XML_PATH_CANCEL_EMAIL_TEMPLATE = 'sales_email/order_cancel/template';
23
+ const XML_PATH_CANCEL_EMAIL_GUEST_TEMPLATE = 'sales_email/order_cancel/guest_template';
24
+ const XML_PATH_CANCEL_EMAIL_IDENTITY = 'sales_email/order_cancel/identity';
25
+ const XML_PATH_CANCEL_EMAIL_COPY_TO = 'sales_email/order_cancel/copy_to';
26
+ const XML_PATH_CANCEL_EMAIL_COPY_METHOD = 'sales_email/order_cancel/copy_method';
27
+ const XML_PATH_CANCEL_EMAIL_ENABLED = 'sales_email/order_cancel/enabled';
28
+
29
+ public function disableOtherPaymentMethods($observer)
30
+ {
31
+ if ($observer->getSection() != 'payment') {
32
+ return;
33
+ }
34
+
35
+ if ($observer->getStore()) {
36
+ $scope = 'stores';
37
+ $scopeId = (int)Mage::getConfig()->getNode('stores/'. $observer->getStore() .'/system/store/id');
38
+ } elseif ($observer->getWebsite()) {
39
+ $scope = 'websites';
40
+ $scopeId = (int)Mage::getConfig()->getNode('websites/'. $observer->getWebsite() .'/system/website/id');
41
+ } else {
42
+ $scope = 'default';
43
+ $scopeId = 0;
44
+ }
45
+
46
+ // Get previously instantiated config data.
47
+ $configData = Mage::getSingleton('adminhtml/config_data');
48
+
49
+ $disable = (bool)$configData->getData('groups/optile/fields/disable_methods/value');
50
+ $methods = (array)$configData->getData('groups/optile/fields/methods_to_disable/value');
51
+
52
+ // Disable selected payment methods, if that is what the admin requested.
53
+ if ($disable) {
54
+ foreach ($methods as $methodCode) {
55
+ Mage::getConfig()->saveConfig('payment/'.$methodCode.'/active', 0, $scope, $scopeId);
56
+ }
57
+
58
+ // Mark the notification (install script) as read.
59
+ $inbox = Mage::getModel('adminnotification/inbox')
60
+ ->load('Optile Payment Extension: Please disable other payment methods', 'title')
61
+ ;
62
+ if ($inbox->getId() && !$inbox->getIsRead()) {
63
+ $inbox
64
+ ->setIsRead(1)
65
+ ->save()
66
+ ;
67
+ }
68
+ }
69
+
70
+ // Delete these config values, they're not real configuration.
71
+ Mage::getConfig()
72
+ ->deleteConfig('payment/optile/active_methods_found', $scope, $scopeId)
73
+ ->deleteConfig('payment/optile/disable_methods', $scope, $scopeId)
74
+ ->deleteConfig('payment/optile/methods_to_disable', $scope, $scopeId)
75
+ ->reinit()
76
+ ;
77
+ }
78
+
79
+ // order_cancel_after
80
+ public function sendOrderCancelEmail($observer)
81
+ {
82
+ Mage::helper('optile')->log(__METHOD__.': Event triggered.');
83
+ $storeId = Mage::app()->getStore()->getId();
84
+ $order = $observer->getOrder();
85
+ /* @var $order Mage_Sales_Model_Order */
86
+
87
+ if (!Mage::getStoreConfigFlag(self::XML_PATH_CANCEL_EMAIL_ENABLED, $storeId)) {
88
+ Mage::helper('optile')->log(__METHOD__.': Cancel email is not enabled. Will not send.');
89
+ return;
90
+ }
91
+
92
+ // Send these cancel emails only for Optile orders.
93
+ if ($order->getPayment()->getMethod() != 'optile') {
94
+ Mage::helper('optile')->log(__METHOD__.': Payment method is not Optile. Will not send.');
95
+ return;
96
+ }
97
+
98
+ // Do not send emails for the following status codes...
99
+ $removed_statuses = array('debit_failed', 'debit_declined', 'debit_aborted');
100
+ Mage::helper('optile')->log(__METHOD__.': '.$order->getOptileStatusCode());
101
+ if(in_array($order->getOptileStatusCode(), $removed_statuses)){
102
+ return;
103
+ }
104
+
105
+ // Get the destination email addresses to send copies to
106
+ $copyToData = (string)Mage::getStoreConfig(self::XML_PATH_CANCEL_EMAIL_COPY_TO, $storeId);
107
+ $copyTo = $copyToData ? explode(',', $copyToData) : array();
108
+ $copyMethod = Mage::getStoreConfig(self::XML_PATH_CANCEL_EMAIL_COPY_METHOD, $storeId);
109
+
110
+ // Start store emulation process
111
+ $appEmulation = Mage::getSingleton('core/app_emulation');
112
+ $initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($storeId);
113
+
114
+ try {
115
+ // Retrieve specified view block from appropriate design package (depends on emulated store)
116
+ $paymentBlock = Mage::helper('payment')->getInfoBlock($order->getPayment())
117
+ ->setIsSecureMode(true);
118
+ $paymentBlock->getMethod()->setStore($storeId);
119
+ $paymentBlockHtml = $paymentBlock->toHtml();
120
+ } catch (Exception $exception) {
121
+ // Stop store emulation process
122
+ $appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
123
+ throw $exception;
124
+ }
125
+
126
+ // Stop store emulation process
127
+ $appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
128
+
129
+ // Retrieve corresponding email template id and customer name
130
+ if ($order->getCustomerIsGuest()) {
131
+ $templateId = Mage::getStoreConfig(self::XML_PATH_CANCEL_EMAIL_GUEST_TEMPLATE, $storeId);
132
+ $customerName = $order->getBillingAddress()->getName();
133
+ } else {
134
+ $templateId = Mage::getStoreConfig(self::XML_PATH_CANCEL_EMAIL_TEMPLATE, $storeId);
135
+ $customerName = $order->getCustomerName();
136
+ }
137
+
138
+ $mailer = Mage::getModel('core/email_template_mailer');
139
+ /* @var $mailer Mage_Core_Model_Email_Template_Mailer */
140
+ $emailInfo = Mage::getModel('core/email_info');
141
+ /* @var $emailInfo Mage_Core_Model_Email_Info */
142
+
143
+ Mage::helper('optile')->log(__METHOD__.': mail recipient: '.$order->getCustomerEmail());
144
+ $emailInfo->addTo($order->getCustomerEmail(), $customerName);
145
+ $mailer->addEmailInfo($emailInfo);
146
+
147
+ if ($copyTo) {
148
+ if ($copyMethod == 'bcc') {
149
+ // Add bcc to customer email
150
+ $emailInfo = Mage::getModel('core/email_info');
151
+
152
+ foreach ($copyTo as $email) {
153
+ $emailInfo->addBcc($email);
154
+ }
155
+ $mailer->addEmailInfo($emailInfo);
156
+ }
157
+
158
+ if ($copyMethod == 'copy') {
159
+ // Email copies are sent as separated emails if their copy method is 'copy'
160
+ foreach ($copyTo as $email) {
161
+ $emailInfo = Mage::getModel('core/email_info');
162
+ $emailInfo->addTo($email);
163
+ $mailer->addEmailInfo($emailInfo);
164
+ }
165
+ }
166
+ }
167
+
168
+ Mage::helper('optile')->log(__METHOD__.': Sending Cancellation email');
169
+ // Set all required params and send emails
170
+ $mailer
171
+ ->setSender(Mage::getStoreConfig(self::XML_PATH_CANCEL_EMAIL_IDENTITY, $storeId))
172
+ ->setStoreId($storeId)
173
+ ->setTemplateId($templateId)
174
+ ->setTemplateParams(array(
175
+ 'order' => $order,
176
+ 'billing' => $order->getBillingAddress(),
177
+ 'payment_html' => $paymentBlockHtml,
178
+ ))
179
+ ->send()
180
+ ;
181
+ Mage::helper('optile')->log(__METHOD__.': Cancellation email sent');
182
+
183
+ $order->setEmailSent(true);
184
+ }
185
+
186
+ public function updateOptileQuote($observer)
187
+ {
188
+ $payment = $observer->getPayment();
189
+ /* @var $payment Mage_Payment_Model_Info */
190
+
191
+ if ($payment->getMethod() != 'optile' || !$payment->hasNetwork()) {
192
+ return;
193
+ }
194
+
195
+ $quoteId = $payment->getQuoteId();
196
+ $optileQuote = Mage::getModel('optile/quote')->load($quoteId);
197
+
198
+ if (!$optileQuote->getId()) {
199
+ $optileQuote->setTransactionId($quoteId);
200
+ }
201
+
202
+ $optileQuote
203
+ ->setPaymentNetwork($payment->getNetwork())
204
+ ->save()
205
+ ;
206
+ }
207
+
208
+ // sales_order_payment_cancel
209
+ public function cancelDeferredPayment($observer){
210
+
211
+ $payment = $observer->getPayment();
212
+ /* @var $payment Mage_Sales_Model_Order_Payment */
213
+
214
+ // Fix for error when cancelling orders that weren't made using Optile
215
+ if($payment->getMethod() !== 'optile') return;
216
+
217
+ // Fix for Magento 1.7.x - Not cancelling orders that are in payment review.
218
+ if($payment->getOrder()->isPaymentReview()){
219
+ Mage::helper('optile')->log(__METHOD__.": Order is in payment review, throwing an exception");
220
+ throw new Exception("Order cannot be cancelled when in payment review.");
221
+ }
222
+
223
+ // Check if this is being triggered by Admin or IPN. Do not execute if triggered by IPN.
224
+ if(Mage::registry('optile_ipn') == true){
225
+ Mage::helper('optile')->log("Not triggering method instance::cancelDeferred");
226
+ return $this;
227
+ }
228
+ $payment->getMethodInstance()->cancelDeferred($payment);
229
+ }
230
+
231
+ }
app/code/community/Optile/Payment/Model/Order/Payment.php ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
14
+ *
15
+ * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
+ */
19
+
20
+ class Optile_Payment_Model_Order_Payment extends Mage_Sales_Model_Order_Payment
21
+ {
22
+ // public function refund($creditmemo)
23
+ // {
24
+ // $gateway = $this->getMethodInstance();
25
+ // if($gateway->getCode() !== 'optile') return parent::refund($creditmemo);
26
+ //
27
+ // $baseAmountToRefund = $this->_formatAmount($creditmemo->getBaseGrandTotal());
28
+ // $order = $this->getOrder();
29
+ //
30
+ // $this->_generateTransactionId(Mage_Sales_Model_Order_Payment_Transaction::TYPE_REFUND);
31
+ //
32
+ // // call refund from gateway if required
33
+ // $isOnline = false;
34
+ // $invoice = null;
35
+ // if ($gateway->canRefund() && $creditmemo->getDoTransaction()) {
36
+ // $this->setCreditmemo($creditmemo);
37
+ // // $invoice = $creditmemo->getInvoice();
38
+ // // if ($invoice) {
39
+ // $isOnline = true;
40
+ // // $captureTxn = $this->_lookupTransaction($invoice->getTransactionId());
41
+ // // if ($captureTxn) {
42
+ // // $this->setParentTransactionId($captureTxn->getTxnId());
43
+ // // }
44
+ // // $this->setShouldCloseParentTransaction(true); // TODO: implement multiple refunds per capture
45
+ // try {
46
+ // $gateway->setStore($this->getOrder()->getStoreId())
47
+ // ->processBeforeRefund($invoice, $this)
48
+ // ->refund($this, $baseAmountToRefund)
49
+ // ->processCreditmemo($creditmemo, $this)
50
+ // ;
51
+ // } catch (Mage_Core_Exception $e) {
52
+ // if (!$captureTxn) {
53
+ // $e->setMessage(' ' . Mage::helper('sales')->__('If the invoice was created offline, try creating an offline creditmemo.'), true);
54
+ // }
55
+ // throw $e;
56
+ // }
57
+ // // }
58
+ // }
59
+ //
60
+ // // update self totals from creditmemo
61
+ // $this->_updateTotals(array(
62
+ // 'amount_refunded' => $creditmemo->getGrandTotal(),
63
+ // 'base_amount_refunded' => $baseAmountToRefund,
64
+ // 'base_amount_refunded_online' => $isOnline ? $baseAmountToRefund : null,
65
+ // 'shipping_refunded' => $creditmemo->getShippingAmount(),
66
+ // 'base_shipping_refunded' => $creditmemo->getBaseShippingAmount(),
67
+ // ));
68
+ //
69
+ // // update transactions and order state
70
+ // $transaction = $this->_addTransaction(
71
+ // Mage_Sales_Model_Order_Payment_Transaction::TYPE_REFUND,
72
+ // $creditmemo,
73
+ // $isOnline
74
+ // );
75
+ // if ($invoice) {
76
+ // $message = Mage::helper('sales')->__('Refunded amount of %s online.', $this->_formatPrice($baseAmountToRefund));
77
+ // } else {
78
+ // $message = $this->hasMessage() ? $this->getMessage()
79
+ // : Mage::helper('sales')->__('Refunded amount of %s offline.', $this->_formatPrice($baseAmountToRefund));
80
+ // }
81
+ // $message = $message = $this->_prependMessage($message);
82
+ // $message = $this->_appendTransactionToMessage($transaction, $message);
83
+ // $order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true, $message);
84
+ //
85
+ // Mage::dispatchEvent('sales_order_payment_refund', array('payment' => $this, 'creditmemo' => $creditmemo));
86
+ // return $this;
87
+ // }
88
+ }
app/code/community/Optile/Payment/Model/PaymentMethod.php CHANGED
@@ -1,113 +1,422 @@
1
  <?php
2
  /**
3
- * This file is part of the Optile Payment Connector extension.
4
- *
5
- * Optile Payment Connector is free software: you can redistribute it and/or
6
- * modify it under the terms of the GNU General Public License as published
7
- * by the Free Software Foundation, either version 3 of the License, or
8
- * (at your option) any later version.
9
- *
10
- * Optile Payment Connector is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License along with
16
- * Optile Payment Connector. If not, see <http://www.gnu.org/licenses/>.
17
  *
18
  * @author i-Ways <dev@i-ways.hr>
19
- * @copyright Copyright (c) 2013 Optile. (http://www.optile.de)
20
- * @license http://www.gnu.org/licenses/gpl.txt
21
  */
22
 
23
  /**
24
  * Optile payment method model
25
  *
26
  */
 
 
 
27
  class Optile_Payment_Model_PaymentMethod extends Mage_Payment_Model_Method_Abstract {
28
 
29
- /**
30
- * Payment method identifier
31
- */
32
- protected $_code = 'optile';
33
-
34
- /**
35
- * Payment method block rendered in checkout
36
- */
37
- protected $_formBlockType = 'optile/list';
38
-
39
- /**
40
- * Is the payment method gateway?
41
- * @var unknown
42
- */
43
- protected $_isGateway = true;
44
-
45
- /**
46
- * Can the payment method authorize?
47
- * @var unknown
48
- */
49
- protected $_canAuthorize = true;
50
-
51
- /**
52
- * Can the payment method capture?
53
- * @var unknown
54
- */
55
- protected $_canCapture = true;
56
-
57
- /**
58
- * Can the payment method capture partial amount?
59
- * @var unknown
60
- */
61
- protected $_canCapturePartial = false;
62
-
63
- /**
64
- * Can the payment method refund?
65
- * @var unknown
66
- */
67
- protected $_canRefund = false;
68
-
69
- /**
70
- * Can the method be used in backend?
71
- */
72
- protected $_canUseInternal = true;
73
-
74
- /**
75
- * Show this method on the checkout page
76
- */
77
- protected $_canUseCheckout = true;
78
-
79
- /**
80
- * Available for multi-shipping checkouts?
81
- */
82
- protected $_canUseForMultishipping = true;
83
-
84
- /**
85
- * Checks whether method can be used.
86
- * Disables the payment method if the email is not available (required
87
- * in optile sdk)
88
- *
89
- * @param Mage_Sales_Model_Quote $quote
90
- * @return boolean
91
- */
92
- public function isAvailable($quote = null) {
93
- $available = parent::isAvailable($quote);
94
- if(!$available) return false;
95
-
96
- $email = $quote->getBillingAddress()->getEmail();
97
- if(strlen($email) == 0) return false;
98
-
99
- return true;
100
- }
101
-
102
- /**
103
- * Called after 'Place Order' action in checkout, sets order status to
104
- * 'Payment Processing'
105
- *
106
- * @param Varien_Object $payment
107
- * @param unknown $amount
108
- */
109
- public function authorize(Varien_Object $payment, $amount) {
110
- $payment->setIsTransactionPending(true);
111
- }
112
-
113
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  <?php
2
  /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
 
 
 
14
  *
15
  * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
  */
19
 
20
  /**
21
  * Optile payment method model
22
  *
23
  */
24
+ require_once implode(DS, array(Mage::getBaseDir('lib'), 'Optile', 'Request', 'RequestFactory.php'));
25
+ use \Optile\Request\RequestFactory;
26
+
27
  class Optile_Payment_Model_PaymentMethod extends Mage_Payment_Model_Method_Abstract {
28
 
29
+ /**
30
+ * Payment method identifier
31
+ */
32
+ protected $_code = 'optile';
33
+
34
+
35
+ protected $_isGateway = false; // true
36
+ protected $_canOrder = false;
37
+ protected $_canAuthorize = true; // true
38
+ protected $_canCapture = true; // true
39
+ protected $_canCapturePartial = true; // false
40
+ protected $_canRefund = true;
41
+ protected $_canRefundInvoicePartial = true;
42
+ protected $_canVoid = false;
43
+ protected $_canUseInternal = true; // true
44
+ protected $_canUseCheckout = true; // true
45
+ protected $_canUseForMultishipping = true; // true
46
+ protected $_isInitializeNeeded = false;
47
+ protected $_canFetchTransactionInfo = false;
48
+ protected $_canReviewPayment = false; //false
49
+ protected $_canCreateBillingAgreement = false;
50
+ protected $_canManageRecurringProfiles = true;
51
+ /**
52
+ * TODO: whether a captured transaction may be voided by this gateway
53
+ * This may happen when amount is captured, but not settled
54
+ * @var bool
55
+ */
56
+ protected $_canCancelInvoice = false;
57
+
58
+ // protected $_isGateway = true;
59
+ // protected $_canAuthorize = true;
60
+ // protected $_canCapture = true;
61
+ // protected $_canCapturePartial = false;
62
+ // protected $_canRefund = false;
63
+ // protected $_canUseInternal = true;
64
+ // protected $_canUseCheckout = true;
65
+ // protected $_canUseForMultishipping = true;
66
+
67
+
68
+
69
+ /**
70
+ * Payment method block rendered in checkout
71
+ */
72
+ protected $_formBlockType = 'optile/list';
73
+
74
+ /**
75
+ * Info block rendered in sales order view
76
+ */
77
+ protected $_infoBlockType = 'optile/info';
78
+
79
+ /**
80
+ * Checks whether method can be used.
81
+ * Disables the payment method if the email is not available (required
82
+ * in optile sdk)
83
+ *
84
+ * @param Mage_Sales_Model_Quote $quote
85
+ * @return boolean
86
+ */
87
+ public function isAvailable($quote = null) {
88
+ $available = parent::isAvailable($quote);
89
+ if(!$available) return false;
90
+
91
+ //T: Email checking will now be done before LIST request.
92
+ return true;
93
+
94
+
95
+ $email = $quote->getBillingAddress()->getEmail();
96
+
97
+ if (strlen($email) == 0) {
98
+ $email = $quote->getCustomerEmail();
99
+ }
100
+
101
+ if(strlen($email) == 0) return false;
102
+
103
+ return true;
104
+ }
105
+
106
+ /**
107
+ * Called after 'Place Order' action in checkout, sets order status to
108
+ * 'Payment Processing'
109
+ *
110
+ * @param Varien_Object $payment
111
+ * @param unknown $amount
112
+ */
113
+ public function authorize(Varien_Object $payment, $amount) {
114
+
115
+ Mage::helper('optile')->log('Executing Authorize method');
116
+ /* @var $payment Mage_Sales_Model_Order_Payment */
117
+ $payment->getOrder()->setCanSendNewEmailFlag(false);
118
+ $payment->setIsTransactionPending(true);
119
+ }
120
+
121
+ public function capture(Varien_Object $payment, $amount) {
122
+ parent::capture($payment, $amount);
123
+ /* @var $payment Mage_Sales_Model_Order_Payment */
124
+ Mage::helper('optile')->log('Executing Capture method');
125
+
126
+ return $this;
127
+
128
+ }
129
+
130
+ public function refund(Varien_Object $payment, $amount) {
131
+ try {
132
+ /* @var $payment Mage_Sales_Model_Order_Payment */
133
+ $longId = $payment->getRefundTransactionId();
134
+ $url = rtrim(Mage::getStoreConfig('payment/optile/api_url'), '/') . "/api/charges/{$longId}/payout";
135
+
136
+ RequestFactory::setLogger(Mage::helper('optile'));
137
+ $request = RequestFactory::getPayoutRequest($url);
138
+
139
+ $reference = Mage::helper('checkout')->__('Quote #%s, Order from %s, ', $payment->getOrder()->getQuoteId(), $this->getStoreName());
140
+
141
+ // Payment
142
+ $request->addPayment()
143
+ ->setAmount($amount)
144
+ ->setCurrency($payment->getOrder()->getOrderCurrencyCode())
145
+ ->setReference($reference);
146
+
147
+ $request
148
+ ->setMerchantCode($this->getMerchantCode())
149
+ ->setMerchantToken($this->getMerchantToken());
150
+
151
+ // execute Close request
152
+ $response = $request->send();
153
+ /* @var $response Response */
154
+
155
+ // Check response for Close confirmation
156
+ Mage::helper('optile')->log($response);
157
+
158
+ if ($response->getInteraction()->getCode() != \Optile\Response\InteractionCode::PROCEED) {
159
+ $msg = "Received interaction code: " . $response->getInteraction()->getCode() . ', ' . $response->getInfo() . '. Unable to proceed with refund.';
160
+ Mage::helper('optile')->log($msg, Zend_Log::ERR);
161
+ $order = $payment->getOrder();
162
+ /* @var $order Mage_Sales_Model_Order */
163
+ $order->addStatusHistoryComment($msg)->save();
164
+ Mage::getSingleton('core/session')->addError($msg);
165
+
166
+ throw new Exception($msg);
167
+ }
168
+
169
+ return $this;
170
+ } catch(Exception $e){
171
+ Mage::helper('optile')->log($e->getMessage(), Zend_log::ERR);
172
+ Mage::helper('optile')->log($e->getTraceAsString());
173
+ throw $e;
174
+ }
175
+ }
176
+
177
+ public function processInvoice($invoice, $payment)
178
+ {
179
+ /* @var $invoice Mage_Sales_Model_Order_Invoice */
180
+ /* @var $payment Mage_Sales_Model_Order_Payment */
181
+ try{
182
+ $optileQuote = Mage::getModel('optile/quote')
183
+ ->load($payment->getOrder()->getQuoteId());
184
+ /* @var $optileQuote Optile_Payment_Model_Quote */
185
+
186
+ // Making sure that the order is in deferred mode
187
+ if($optileQuote->getDeferredMode() != Optile_Payment_Model_Quote::DEFERRED){
188
+ // TODO: test this with non_deferred payments. We should just exit gracefully.
189
+ throw new Exception("Order is not in deferred mode, cannot continue with Capture.");
190
+ }
191
+
192
+ $longId = $optileQuote->getLongId();
193
+ $url = rtrim(Mage::getStoreConfig('payment/optile/api_url'), '/')."/api/charges/{$longId}/closing";
194
+
195
+ RequestFactory::setLogger(Mage::helper('optile')); // TODO: refactor the logger setter?
196
+ $request = RequestFactory::getCloseRequest($url);
197
+
198
+ $reference = Mage::helper('checkout')->__('Quote #%s, Order from %s, ', $payment->getOrder()->getQuoteId(), $this->getStoreName());
199
+
200
+ // Payment
201
+ $request->addPayment()
202
+ ->setAmount($invoice->getGrandTotal())
203
+ ->setCurrency($invoice->getOrderCurrencyCode())
204
+ ->setReference($reference)
205
+ ;
206
+
207
+ $request
208
+ ->setMerchantCode($this->getMerchantCode())
209
+ ->setMerchantToken($this->getMerchantToken());
210
+
211
+ // Optional Request data:
212
+
213
+ // Invoice items
214
+ foreach($invoice->getAllItems() as $item){
215
+
216
+ if($item->getRowTotal()){ // Workaround for mysterious Invoice item...
217
+
218
+ if($item->getQty() > 1){
219
+ $name = (int)$item->getQty()."x ".$item->getName();
220
+ }else{
221
+ $name = $item->getName();
222
+ }
223
+
224
+ $request->addProduct()
225
+ ->setCode($item->getSku())
226
+ ->setName($name)
227
+ ->setAmount($item->getRowTotalInclTax())
228
+ ;
229
+ }
230
+ }
231
+
232
+ // Shipping
233
+ if($invoice->getShippingInclTax() > 0){
234
+ $request->addProduct()
235
+ ->setCode('shipping')
236
+ ->setName(Mage::helper('optile')->__("Shipping costs").': '.$invoice->getShippingAddress()->getShippingDescription())
237
+ ->setAmount($invoice->getShippingInclTax()) // TODO: with or without tax?
238
+ ;
239
+ }
240
+
241
+ // Discount
242
+ if ($invoice->getDiscountAmount()) {
243
+
244
+ $discount_amount = $invoice->getDiscountAmount();
245
+ // Magento 1.7 fix
246
+ if($discount_amount > 0){
247
+ Mage::helper('optile')->log("Detected positive discount amount: ". $discount_amount);
248
+ $discount_amount = $discount_amount * (-1);
249
+ Mage::helper('optile')->log("Discount amount set to: ". $discount_amount);
250
+ }
251
+
252
+ // Add shipping as an additional product, to complete the total.
253
+ $request->addProduct()
254
+ ->setCode("discount")
255
+ ->setName(Mage::helper('optile')->__("Discount"))
256
+ ->setQuantity(1)
257
+ ->setAmount($discount_amount)
258
+ ;
259
+ }
260
+
261
+ // End of optional Request data.
262
+
263
+ // execute Close request
264
+ $response = $request->send();
265
+ /* @var $response Response */
266
+
267
+ // Check response for Close confirmation
268
+ Mage::helper('optile')->log($response);
269
+
270
+ if($response->getInteraction()->getCode() != \Optile\Response\InteractionCode::PROCEED){
271
+ $msg = "Received interaction code: ".$response->getInteraction()->getCode().', '.$response->getInfo().'. Unable to proceed with creation of invoice.';
272
+ Mage::helper('optile')->log($msg, Zend_Log::ERR);
273
+ $order = $payment->getOrder();
274
+ /* @var $order Mage_Sales_Model_Order */
275
+ $order->addStatusHistoryComment($msg)->save();
276
+ Mage::getSingleton('core/session')->addError($msg);
277
+
278
+ throw new Exception($msg);
279
+ }
280
+
281
+ Mage::helper('optile')->log(__METHOD__ .' Sending invoice email.');
282
+ $invoice->sendEmail(true);
283
+
284
+ $links = $response->getLinks();
285
+ $selfLink = $links['self'];
286
+ $closingId = ltrim($selfLink, rtrim(Mage::getStoreConfig('payment/optile/api_url'), '/').'/api/charges/');
287
+ $invoice->setTransactionId($closingId);
288
+ $invoice->save();
289
+ return $this;
290
+
291
+ }catch(Exception $e){
292
+ Mage::helper('optile')->log($e->getMessage(), Zend_log::ERR);
293
+ Mage::helper('optile')->log($e->getTraceAsString());
294
+ throw $e;
295
+ }
296
+ }
297
+
298
+ /**
299
+ * Method for cancelling deferred payment.
300
+ * @param Varien_Object $payment
301
+ * @return Optile_Payment_Model_PaymentMethod
302
+ */
303
+ public function cancelDeferred(Varien_Object $payment)
304
+ {
305
+ /* @var $payment Mage_Sales_Model_Order_Payment */
306
+ Mage::helper('optile')->log('Handling cancellation of deferred payment');
307
+
308
+ // Get the order info, find out if the order is made in deferred mode.
309
+ $optileQuote = Mage::getModel('optile/quote')
310
+ ->load($payment->getOrder()->getQuoteId());
311
+ /* @var $optileQuote Optile_Payment_Model_Quote */
312
+
313
+ // Making sure that the order is in deferred mode
314
+ if($optileQuote->getDeferredMode() != Optile_Payment_Model_Quote::DEFERRED){
315
+ Mage::helper('optile')->log('Quote not in deferred mode, not sending cancel request to Optile.', Zend_log::INFO);
316
+ return $this;
317
+ }
318
+
319
+ // Will send a cancel request only if cancelling entire order. TODO: how to handle partial cancellations?
320
+ // Answered by Sebastian: Whenever there is something to cancel, it is ok to execute.
321
+ // if($payment->getAmountPaid() > 0){
322
+ // Mage::helper('optile')->log('Quote already paid, not sending cancel request to Optile.', Zend_log::INFO);
323
+ // return $this;
324
+ // }
325
+
326
+ // Create Cancel request and send to Optile
327
+ $longId = $optileQuote->getLongId();
328
+ $url = rtrim(Mage::getStoreConfig('payment/optile/api_url'), '/')."/api/charges/{$longId}";
329
+
330
+ RequestFactory::setLogger(Mage::helper('optile')); // TODO: refactor the logger setter?
331
+ $request = RequestFactory::getCancelRequest($url)
332
+ ->setMerchantCode($this->getMerchantCode())
333
+ ->setMerchantToken($this->getMerchantToken());
334
+
335
+ $response = $request->send();
336
+ /* @var $response Response */
337
+
338
+ // Check response for Close confirmation
339
+ Mage::helper('optile')->log($response);
340
+
341
+ if($response->getInteraction()->getCode() != \Optile\Response\InteractionCode::PROCEED){
342
+ $msg = "Received interaction code: ".$response->getInteraction()->getCode().', '.$response->getInfo().'. Unable to proceed with order cancellation.';
343
+ $order = $payment->getOrder();
344
+ /* @var $order Mage_Sales_Model_Order */
345
+ $order->addStatusHistoryComment($msg)->save();
346
+ Mage::getSingleton('core/session')->addError($msg);
347
+ Mage::helper('optile')->log($msg, Zend_Log::ERR);
348
+ throw new Exception($msg);
349
+
350
+ }
351
+
352
+ return $this;
353
+ }
354
+
355
+ public function getOrderPlaceRedirectUrl() {
356
+ // Mage::helper('optile')->log('Getting redirect URL');
357
+ // try{
358
+ // throw new Exception();
359
+ // }catch(Exception $e){
360
+ // Mage::helper('optile')->log($e->getTraceAsString());
361
+ // }
362
+ // return "http://www.google.com";
363
+ }
364
+
365
+ /**
366
+ * Attempt to accept a payment that us under review
367
+ *
368
+ * @param Mage_Payment_Model_Info $payment
369
+ * @return bool
370
+ * @throws Mage_Core_Exception
371
+ */
372
+ public function acceptPayment(Mage_Payment_Model_Info $payment)
373
+ {
374
+ // parent::acceptPayment($payment);
375
+ //Note: $_canReviewPayment is set to false, but we are overriding
376
+ // the parent method that checks for this property.
377
+ // This is because we do not want to give a Merchant possibility
378
+ // to manually accept or deny payment in Magento admin - order page.
379
+ return true; // Will make the payment model approve the payment.
380
+ }
381
+
382
+ public function denyPayment(Mage_Payment_Model_Info $payment) {
383
+ //parent::denyPayment($payment);
384
+
385
+ //Note: $_canReviewPayment is set to false, but we are overriding
386
+ // the parent method that checks for this property.
387
+ // This is because we do not want to give a Merchant possibility
388
+ // to manually accept or deny payment in Magento admin - order page.
389
+
390
+ return true; // Will make the payment model deny the payment.
391
+ }
392
+
393
+ // /**
394
+ // * Refund support for order "Credit Memo" view
395
+ // **/
396
+ // public function processBeforeRefund($invoice, $payment)
397
+ // {
398
+ // // $payment->setRefundTransactionId($invoice->getTransactionId());
399
+ // return $this;
400
+ // }
401
+
402
+ /**
403
+ * Returns merchant_code setting
404
+ */
405
+ protected function getMerchantCode() {
406
+ return Mage::getStoreConfig('payment/optile/merchant_code');
407
+ }
408
+
409
+ /**
410
+ * Returns merchant_token setting
411
+ */
412
+ protected function getMerchantToken() {
413
+ return Mage::getStoreConfig('payment/optile/merchant_token');
414
+ }
415
+
416
+ /**
417
+ * Returns display name for current Magento store
418
+ */
419
+ protected function getStoreName() {
420
+ return Mage::getStoreConfig('general/store_information/name');
421
+ }
422
+ }
app/code/community/Optile/Payment/Model/Quote.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
14
+ *
15
+ * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
+ */
19
+
20
+ class Optile_Payment_Model_Quote extends Mage_Core_Model_Abstract
21
+ {
22
+ const NON_DEFERRED = 0; // default
23
+ const DEFERRED = 1;
24
+
25
+ protected function _construct() {
26
+ $this->_init('optile/quote', 'transaction_id');
27
+ }
28
+ }
app/code/community/Optile/Payment/Model/System/Config/Backend/Disablemethods.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
14
+ *
15
+ * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
+ */
19
+
20
+ class Optile_Payment_Model_System_Config_Backend_Disablemethods
21
+ extends Mage_Core_Model_Config_Data
22
+ {
23
+
24
+ }
app/code/community/Optile/Payment/Model/System/Config/Backend/Enabledmethods/Bool.php ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
14
+ *
15
+ * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
+ */
19
+
20
+ class Optile_Payment_Model_System_Config_Backend_Enabledmethods_Bool
21
+ extends Mage_Core_Model_Config_Data
22
+ {
23
+ public function getValue() {
24
+ $source = Mage::getSingleton('optile/system_config_source_enabledmethods')
25
+ ->toOptionArray();
26
+
27
+ return (int)!empty($source);
28
+ }
29
+ }
app/code/community/Optile/Payment/Model/System/Config/Backend/Enabledmethods/Select.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
14
+ *
15
+ * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
+ */
19
+
20
+ class Optile_Payment_Model_System_Config_Backend_Enabledmethods_Select
21
+ extends Mage_Core_Model_Config_Data
22
+ {
23
+ public function getValue() {
24
+ // Multiselect should have all values selected by default.
25
+ $source = Mage::getSingleton('optile/system_config_source_enabledmethods')
26
+ ->toOptionArray();
27
+
28
+ return array_keys($source);
29
+ }
30
+ }
app/code/community/Optile/Payment/Model/System/Config/Backend/Instructions.php ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ //error_reporting(E_ALL | E_STRICT);
4
+ //Mage::setIsDeveloperMode(true);
5
+ //ini_set('display_errors', 1);
6
+
7
+ /**
8
+ * @author frans
9
+ */
10
+ class Optile_Payment_Model_System_Config_Backend_Instructions
11
+ extends Mage_Adminhtml_Model_System_Config_Backend_Serialized_Array
12
+ {
13
+ protected $_eventPrefix = 'optile_config_backend_instructions';
14
+ }
app/code/community/Optile/Payment/Model/System/Config/Source/Deferral.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
14
+ *
15
+ * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
+ */
19
+
20
+ class Optile_Payment_Model_System_Config_Source_Deferral
21
+ {
22
+ protected $_result = array(
23
+ 'DEFERRED' => array('label' => 'Deferred', 'value' => 'DEFERRED'),
24
+ 'NON_DEFERRED' => array('label' => 'Non Deferred', 'value' => 'NON_DEFERRED'),
25
+ 'ANY' => array('label' => 'Any', 'value' => 'ANY'),
26
+ );
27
+
28
+ public function toOptionArray($isMultiSelect=false)
29
+ {
30
+ return $this->_result;
31
+ }
32
+ }
app/code/community/Optile/Payment/Model/System/Config/Source/Enabledmethods.php ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
14
+ *
15
+ * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
+ */
19
+
20
+ class Optile_Payment_Model_System_Config_Source_Enabledmethods
21
+ {
22
+ protected $_result;
23
+ public function toOptionArray($isMultiSelect=false)
24
+ {
25
+ if (isset($this->_result)) {
26
+ return $this->_result;
27
+ }
28
+
29
+ $this->_result = array();
30
+ foreach (Mage::getStoreConfig('payment') as $methodCode => $methodData) {
31
+ if (!isset($methodData['active']) || !$methodData['active']) {
32
+ continue;
33
+ }
34
+ // Don't offer to disable the following payment methods:
35
+ if (in_array($methodCode, array('free', 'cashondelivery', 'optile'))) {
36
+ continue;
37
+ }
38
+
39
+ $this->_result[$methodCode] = array(
40
+ 'label' => isset($methodData['title']) ? $methodData['title'] : $methodCode,
41
+ 'value' => $methodCode,
42
+ );
43
+ }
44
+ return $this->_result;
45
+ }
46
+ }
app/code/community/Optile/Payment/Model/System/Config/Source/Loglevel.php ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Optile_Payment_Model_System_Config_Source_Loglevel extends Mage_Eav_Model_Entity_Attribute_Source_Abstract{
3
+
4
+ public function getAllOptions()
5
+ {
6
+ if (is_null($this->_options)) {
7
+
8
+ $methods = array(
9
+ Zend_log::EMERG => array(
10
+ 'label' => Zend_log::EMERG.' - Emergency',
11
+ 'value' => Zend_log::EMERG
12
+ ),
13
+ Zend_log::ALERT => array(
14
+ 'label' => Zend_log::ALERT.' - Alert',
15
+ 'value' => Zend_log::ALERT
16
+ ),
17
+ Zend_log::CRIT => array(
18
+ 'label' => Zend_log::CRIT.' - Critical',
19
+ 'value' => Zend_log::CRIT
20
+ ),
21
+ Zend_log::ERR => array(
22
+ 'label' => Zend_log::ERR.' - Error',
23
+ 'value' => Zend_log::ERR
24
+ ),
25
+ Zend_log::WARN => array(
26
+ 'label' => Zend_log::WARN.' - Warning',
27
+ 'value' => Zend_log::WARN
28
+ ),
29
+ Zend_log::NOTICE => array(
30
+ 'label' => Zend_log::NOTICE.' - Notice',
31
+ 'value' => Zend_log::NOTICE
32
+ ),
33
+ Zend_log::INFO => array(
34
+ 'label' => Zend_log::INFO.' - Info',
35
+ 'value' => Zend_log::INFO
36
+ ),
37
+ Zend_log::DEBUG => array(
38
+ 'label' => Zend_log::DEBUG.' - Debug',
39
+ 'value' => Zend_log::DEBUG
40
+ ),
41
+ );
42
+
43
+ $this->_options = $methods;
44
+ }
45
+ return $this->_options;
46
+ }
47
+
48
+ public function toOptionArray(){
49
+ return $this->getAllOptions();
50
+ }
51
+ }
app/code/community/Optile/Payment/controllers/Adminhtml/Optile/NotificationController.php ADDED
@@ -0,0 +1,155 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
14
+ *
15
+ * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
+ */
19
+
20
+ class Optile_Payment_Adminhtml_Optile_NotificationController extends Mage_Adminhtml_Controller_Action
21
+ {
22
+
23
+ /**
24
+ * Init layout, menu and breadcrumb
25
+ *
26
+ * @return Mage_Adminhtml_Sales_OrderController
27
+ */
28
+ protected function _initAction()
29
+ {
30
+ $this->loadLayout()
31
+ ->_setActiveMenu('sales/optile_order')
32
+ ->_addBreadcrumb($this->__('Sales'), $this->__('Sales'))
33
+ ->_addBreadcrumb($this->__('optile IPNs'), $this->__('optile IPNs'));
34
+ return $this;
35
+ }
36
+
37
+ /**
38
+ * Orders grid
39
+ */
40
+ public function indexAction()
41
+ {
42
+ $this->_title($this->__('Sales'))->_title($this->__('optile IPNs'));
43
+
44
+ $this->_initAction();
45
+ $this->_addContent(
46
+ $this->getLayout()->createBlock('optile/adminhtml_notification')
47
+ );
48
+ $this->renderLayout();
49
+ }
50
+
51
+ /**
52
+ * Order grid
53
+ */
54
+ public function gridAction()
55
+ {
56
+ $this->loadLayout(false);
57
+ $this->getResponse()->setBody(
58
+ $this->getLayout()->createBlock('optile/adminhtml_notification_grid')->toHtml()
59
+ );
60
+ }
61
+
62
+ public function reprocessAction(){
63
+
64
+ $request = $this->getRequest();
65
+
66
+ $ipn_id = $request->getParam("id");
67
+ $ipn = Mage::getModel('optile/notification')->load($ipn_id);
68
+
69
+
70
+ foreach($ipn->getReceivedData() as $k=>$v){
71
+ $request->setParam($k, $v);
72
+ }
73
+
74
+
75
+ $params = $request->getParams();
76
+
77
+ $quote = Mage::getModel('sales/quote')->getCollection()
78
+ ->addFieldToFilter("entity_id", $params['transactionId'])
79
+ ->getFirstItem();
80
+
81
+ $session = Mage::getSingleton('core/session');
82
+
83
+ $appEmulation = Mage::getSingleton('core/app_emulation');
84
+ //Start environment emulation of the specified store
85
+ $initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($quote->getStoreId());
86
+
87
+ //to skip IP checks
88
+ Mage::setIsDeveloperMode(true);
89
+ try{
90
+ Mage::helper('optile')->log(__METHOD__.' - REPROCESS - Reprocessing IPN #'.$ipn_id);
91
+ Mage::getModel('optile/notification')->processNotification($request);
92
+ }
93
+ catch(Exception $e){
94
+ Mage::helper('optile')->log(__METHOD__.' - REPROCESS - Exception caught: '.$e->getMessage(), Zend_Log::ERR);
95
+ Mage::helper('optile')->log(__METHOD__.' - REPROCESS - Trace: '.$e->getTraceAsString(), Zend_Log::ERR);
96
+
97
+ $headerTexts = array(
98
+ 500 => $_SERVER['SERVER_PROTOCOL'] .' 500 Internal Error', // Response code 500; effectively this makes Optile resend the message later.
99
+ 403 => $_SERVER['SERVER_PROTOCOL'] .' 403 Forbidden'
100
+ );
101
+ $responseMsg = $e->getMessage();
102
+ $responseCode = $e->getCode();
103
+
104
+ // Notify Optile of the error.
105
+ if ($responseCode != 200) {
106
+
107
+ $responseMsg = 'ERROR: '.$responseMsg;
108
+ $session->addError("REPROCESS: ".$responseMsg);
109
+ }
110
+ $session->addNotice("REPROCESS: ".$responseMsg);
111
+ }
112
+ $appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
113
+ $this->_redirect("/*/index");
114
+ }
115
+
116
+ /**
117
+ * Order grid
118
+ */
119
+ public function viewAction()
120
+ {
121
+ $this->loadLayout();
122
+
123
+ $block = $this->getLayout()
124
+ ->createBlock('optile/adminhtml_notification_view')
125
+ ->setTemplate('optile/notification_view.phtml')
126
+ ->setNotificationId($this->getRequest()->getParam('notification_id'))
127
+ ;
128
+
129
+ $this->getLayout()->getBlock('content')->append($block);
130
+
131
+ $this->renderLayout();
132
+ }
133
+
134
+ /**
135
+ * Export order grid to CSV format
136
+ */
137
+ public function exportCsvAction()
138
+ {
139
+ $now = date('Ymd_Hi');
140
+ $fileName = "optile_ipns_${now}.csv";
141
+ $grid = $this->getLayout()->createBlock('optile/adminhtml_notification_grid');
142
+ $this->_prepareDownloadResponse($fileName, $grid->getCsvFile());
143
+ }
144
+
145
+ /**
146
+ * Export order grid to Excel XML format
147
+ */
148
+ public function exportExcelAction()
149
+ {
150
+ $now = date('Ymd_Hi');
151
+ $fileName = "optile_orders_${now}.xml";
152
+ $grid = $this->getLayout()->createBlock('optile/adminhtml_notification_grid');
153
+ $this->_prepareDownloadResponse($fileName, $grid->getExcelFile($fileName));
154
+ }
155
+ }
app/code/community/Optile/Payment/controllers/Adminhtml/Optile/OrderController.php ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
14
+ *
15
+ * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
+ */
19
+ require_once implode(DS, array(Mage::getBaseDir('lib'), 'Optile', 'Request', 'RequestFactory.php'));
20
+ use \Optile\Request\RequestFactory;
21
+
22
+ class Optile_Payment_Adminhtml_Optile_OrderController extends Mage_Adminhtml_Controller_Action
23
+ {
24
+
25
+ /**
26
+ * Init layout, menu and breadcrumb
27
+ *
28
+ * @return Mage_Adminhtml_Sales_OrderController
29
+ */
30
+ protected function _initAction()
31
+ {
32
+ $this->loadLayout()
33
+ ->_setActiveMenu('sales/optile_order')
34
+ ->_addBreadcrumb($this->__('Sales'), $this->__('Sales'))
35
+ ->_addBreadcrumb($this->__('optile Orders'), $this->__('optile Orders'));
36
+ return $this;
37
+ }
38
+
39
+ /**
40
+ * pass on params to IPN testing script to simulate IPN action
41
+ */
42
+ public function simulateAction(){
43
+
44
+ $transaction_id = $this->getRequest()->getParam("transaction_id");
45
+ $status_code = $this->getRequest()->getParam("status_code");
46
+ $reason_code = $this->getRequest()->getParam("reason_code");
47
+ $optile_quote = Mage::getModel('optile/quote')->load($transaction_id);
48
+ $long_id = $optile_quote->getLongId();
49
+
50
+
51
+ RequestFactory::setLogger(Mage::helper('optile'));
52
+ $request = RequestFactory::getSimpleRequest(Mage::getUrl('optile/notification'));
53
+ /* @var $request SimpleRequest */
54
+
55
+ $request->setinteractionCode('IPN_TEST');
56
+ $request->setreturnCode('IPN_TEST');
57
+ $request->settransactionId($transaction_id);
58
+ $request->setinteractionReason('EXPIRED');
59
+ $request->setentity('payment');
60
+ $request->setlongId($long_id);
61
+ $request->setreferenceId($long_id);
62
+ $request->setreasonCode($reason_code);
63
+ if($this->getRequest()->has('network')){
64
+ $request->setnetwork($this->getRequest()->getParam('network'));
65
+ }
66
+ $request->setresultInfo('IPN test script');
67
+ $request->setstatusCode($status_code);
68
+ $request->settimestamp(date("Y-m-d H:i:s"));
69
+ $request->setnotificationId('IPNTest123');
70
+ $request->setshortId('IPNTest123');
71
+ $request->setresultCode('IPNTest123');
72
+
73
+ $response = $request->send();
74
+
75
+ $session = Mage::getSingleton('core/session');
76
+
77
+ $session->addNotice("IPN responded: ".$response);
78
+
79
+ $this->_redirect('*/*/');
80
+ }
81
+
82
+ /**
83
+ * Orders grid
84
+ */
85
+ public function indexAction()
86
+ {
87
+ $this->_title($this->__('Sales'))->_title($this->__('optile Orders'));
88
+
89
+ $this->_initAction();
90
+ $this->_addContent(
91
+ $this->getLayout()->createBlock('optile/adminhtml_order')
92
+ );
93
+ $this->renderLayout();
94
+ }
95
+
96
+ /**
97
+ * Order grid
98
+ */
99
+ public function gridAction()
100
+ {
101
+ $this->loadLayout(false);
102
+ $this->getResponse()->setBody(
103
+ $this->getLayout()->createBlock('optile/adminhtml_order_grid')->toHtml()
104
+ );
105
+ }
106
+
107
+ /**
108
+ * Export order grid to CSV format
109
+ */
110
+ public function exportCsvAction()
111
+ {
112
+ $now = date('Ymd_Hi');
113
+ $fileName = "optile_orders_${now}.csv";
114
+ $grid = $this->getLayout()->createBlock('optile/adminhtml_order_grid');
115
+ $this->_prepareDownloadResponse($fileName, $grid->getCsvFile());
116
+ }
117
+
118
+ /**
119
+ * Export order grid to Excel XML format
120
+ */
121
+ public function exportExcelAction()
122
+ {
123
+ $now = date('Ymd_Hi');
124
+ $fileName = "optile_orders_${now}.xml";
125
+ $grid = $this->getLayout()->createBlock('optile/adminhtml_order_grid');
126
+ $this->_prepareDownloadResponse($fileName, $grid->getExcelFile($fileName));
127
+ }
128
+ }
app/code/community/Optile/Payment/controllers/NotificationController.php CHANGED
@@ -1,36 +1,33 @@
1
  <?php
2
  /**
3
- * This file is part of the Optile Payment Connector extension.
4
- *
5
- * Optile Payment Connector is free software: you can redistribute it and/or
6
- * modify it under the terms of the GNU General Public License as published
7
- * by the Free Software Foundation, either version 3 of the License, or
8
- * (at your option) any later version.
9
- *
10
- * Optile Payment Connector is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License along with
16
- * Optile Payment Connector. If not, see <http://www.gnu.org/licenses/>.
17
  *
18
  * @author i-Ways <dev@i-ways.hr>
19
- * @copyright Copyright (c) 2013 Optile. (http://www.optile.de)
20
- * @license http://www.gnu.org/licenses/gpl.txt
21
  */
22
 
23
  /**
24
  * Processes Optile payment status notification
25
  * Each time the status of a transaction changes, a back-channel notification is sent to the <notificationUrl> with additional parameters.
26
- *
27
  * Note: notifications are sent in a clear way without any additional security.
28
  * HTTPS protocol should always be used in a production environment.
29
  * To allow notifications from Optile open payments servers to reach a merchant
30
  * system that is protected by firewall, the firewall has to be configured to
31
  * accept requests from Optile servers IP addresses.
32
  * In this case the following IPs should be used:
33
- * Test server (sandbox.oscato.com) => 78.46.61.206
34
  * Production server (oscato.com) => 213.155.71.162
35
  */
36
  class Optile_Payment_NotificationController extends Mage_Core_Controller_Front_Action
@@ -39,7 +36,32 @@ class Optile_Payment_NotificationController extends Mage_Core_Controller_Front_A
39
  {
40
  $request = $this->getRequest();
41
 
42
- Mage::getModel('optile/notification')->processNotification($request);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
 
44
  }
45
- }
1
  <?php
2
  /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
 
 
 
14
  *
15
  * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
  */
19
 
20
  /**
21
  * Processes Optile payment status notification
22
  * Each time the status of a transaction changes, a back-channel notification is sent to the <notificationUrl> with additional parameters.
23
+ *
24
  * Note: notifications are sent in a clear way without any additional security.
25
  * HTTPS protocol should always be used in a production environment.
26
  * To allow notifications from Optile open payments servers to reach a merchant
27
  * system that is protected by firewall, the firewall has to be configured to
28
  * accept requests from Optile servers IP addresses.
29
  * In this case the following IPs should be used:
30
+ * Test server (sandbox.oscato.com) => 144.76.239.125
31
  * Production server (oscato.com) => 213.155.71.162
32
  */
33
  class Optile_Payment_NotificationController extends Mage_Core_Controller_Front_Action
36
  {
37
  $request = $this->getRequest();
38
 
39
+ try{
40
+ Mage::getModel('optile/notification')->processNotification($request);
41
+ }
42
+ catch(Exception $e){
43
+ Mage::helper('optile')->log(__METHOD__.' - Exception caught: '.$e->getMessage(), Zend_Log::DEBUG);
44
+ Mage::helper('optile')->log(__METHOD__.' - Trace: '.$e->getTraceAsString(), Zend_Log::DEBUG);
45
+
46
+ $headerTexts = array(
47
+ 500 => $_SERVER['SERVER_PROTOCOL'] .' 500 Internal Error', // Response code 500; effectively this makes Optile resend the message later.
48
+ 403 => $_SERVER['SERVER_PROTOCOL'] .' 403 Forbidden'
49
+ );
50
+ $responseMsg = $e->getMessage();
51
+ $responseCode = $e->getCode();
52
+
53
+ // Notify Optile of the error.
54
+ if ($responseCode != 200) {
55
+
56
+ if(!isset($headerTexts[$responseCode])){
57
+ $headerTexts[$responseCode] = $_SERVER['SERVER_PROTOCOL'] .' '.$responseCode. ' Error';
58
+ }
59
+
60
+ header($headerTexts[$responseCode], true, $responseCode);
61
+ $responseMsg = 'ERROR: '.$responseMsg;
62
+ }
63
+ die($responseMsg);
64
+ }
65
 
66
  }
67
+ }
app/code/community/Optile/Payment/controllers/PaymentController.php CHANGED
@@ -1,63 +1,76 @@
1
  <?php
2
  /**
3
- * This file is part of the Optile Payment Connector extension.
4
- *
5
- * Optile Payment Connector is free software: you can redistribute it and/or
6
- * modify it under the terms of the GNU General Public License as published
7
- * by the Free Software Foundation, either version 3 of the License, or
8
- * (at your option) any later version.
9
- *
10
- * Optile Payment Connector is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License along with
16
- * Optile Payment Connector. If not, see <http://www.gnu.org/licenses/>.
17
  *
18
  * @author i-Ways <dev@i-ways.hr>
19
- * @copyright Copyright (c) 2013 Optile. (http://www.optile.de)
20
- * @license http://www.gnu.org/licenses/gpl.txt
21
  */
22
 
23
  class Optile_Payment_PaymentController extends Mage_Core_Controller_Front_Action
24
  {
25
- public function cancelAction()
26
- {
27
- try {
28
- // TODO verify if this logic of order cancelation is deprecated
29
- // if there is an order - cancel it
30
- $orderId = $this->_getCheckoutSession()->getLastOrderId();
31
- $order = ($orderId) ? Mage::getModel('sales/order')->load($orderId) : false;
32
- if ($order && $order->getId() && $order->getQuoteId() == $this->_getCheckoutSession()->getQuoteId()) {
33
- $order->cancel()->save();
34
- $this->_getCheckoutSession()
35
- ->unsLastQuoteId()
36
- ->unsLastSuccessQuoteId()
37
- ->unsLastOrderId()
38
- ->unsLastRealOrderId()
39
- ->addSuccess($this->__('Checkout and order has been canceled.'))
40
- ;
41
- } else {
42
- $this->_getCheckoutSession()->addSuccess($this->__('Checkout has been canceled.'));
43
- }
44
- } catch (Mage_Core_Exception $e) {
45
- $this->_getCheckoutSession()->addError($e->getMessage());
46
- } catch (Exception $e) {
47
- $this->_getCheckoutSession()->addError($this->__('Unable to cancel checkout.'));
48
- Mage::logException($e);
49
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
 
51
- $this->_redirect('checkout/cart');
52
- }
53
-
54
- /**
55
- * Return checkout session object
56
- *
57
- * @return Mage_Checkout_Model_Session
58
- */
59
- private function _getCheckoutSession()
60
- {
61
- return Mage::getSingleton('checkout/session');
62
- }
63
- }
1
  <?php
2
  /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
 
 
 
14
  *
15
  * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
  */
19
 
20
  class Optile_Payment_PaymentController extends Mage_Core_Controller_Front_Action
21
  {
22
+ public function cancelAction()
23
+ {
24
+ try {
25
+ // TODO verify if this logic of order cancelation is deprecated
26
+ // if there is an order - cancel it
27
+ $orderId = $this->_getCheckoutSession()->getLastOrderId();
28
+ $order = ($orderId) ? Mage::getModel('sales/order')->load($orderId) : false;
29
+
30
+ Mage::helper('optile')->log("Customer landed on order cancellation page");
31
+ Mage::helper('optile')->log("Order #".$order->getIncrementId()." ". ($order->canCancel() ? "can" : "cannot")." be cancelled.");
32
+ if ($order && $order->getId() && $order->getQuoteId() == $this->_getCheckoutSession()->getQuoteId()) {
33
+ // Mage::helper('optile')->log("Denying the payment...");
34
+ // $order->getPayment()->deny();
35
+ // Mage::helper('optile')->log("Payment denied, proceeding to cancel the order");
36
+ // $order->cancel()->save(); // Payment deny() method already canceles the order.
37
+ $this->_getCheckoutSession()
38
+ // ->unsLastQuoteId()
39
+ // ->unsLastSuccessQuoteId()
40
+ // ->unsLastOrderId()
41
+ // ->unsLastRealOrderId()
42
+ ->addSuccess($this->__('Checkout and order has been canceled.'))
43
+ ;
44
+ // if($order->isCanceled()){
45
+ // Mage::helper('optile')->log("Order #".$order->getIncrementId()." has been canceled.", Zend_log::INFO);
46
+ // }else{
47
+ // Mage::helper('optile')->log("Order #".$order->getIncrementId()." has NOT been canceled.", Zend_log::INFO);
48
+ // }
49
+ } else {
50
+ $this->_getCheckoutSession()->addSuccess($this->__('Checkout has been canceled.'));
51
+ }
52
+ } catch (Mage_Core_Exception $e) {
53
+ $this->_getCheckoutSession()->addError($e->getMessage());
54
+ Mage::helper('optile')->log(__METHOD__.": ".$e->getMessage());
55
+ } catch (Exception $e) {
56
+ $this->_getCheckoutSession()->addError($this->__('Unable to cancel checkout.'));
57
+ Mage::logException($e);
58
+ Mage::helper('optile')->log(__METHOD__.": ".$e->getMessage());
59
+ }
60
+
61
+ $this->_redirect('checkout/cart');
62
+ }
63
+
64
+ /**
65
+ * Return checkout session object
66
+ *
67
+ * @return Mage_Checkout_Model_Session
68
+ */
69
+ private function _getCheckoutSession()
70
+ {
71
+ return Mage::getSingleton('checkout/session');
72
+ }
73
+
74
+
75
 
76
+ }
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Optile/Payment/etc/adminhtml.xml ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Copyright optile GmbH 2013
5
+ * Licensed under the Software License Agreement in effect between optile and
6
+ * Licensee/user (the "License"); you may not use this file except in compliance
7
+ * with the License. You may obtain a copy of the License at
8
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
9
+ * copy has been provided to you for your records. Unless required by applicable
10
+ * law or agreed to in writing or otherwise stipulated in the License, software
11
+ * distributed under the License is distributed on an "as is" basis without
12
+ * warranties or conditions of any kind, either express or implied. See the
13
+ * License for the specific language governing permissions and limitations under
14
+ * the License.
15
+ *
16
+ * @author i-Ways <dev@i-ways.hr>
17
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
18
+ * @license http://www.optile.de/software-license-agreement
19
+ */
20
+ -->
21
+ <config>
22
+ <menu>
23
+ <sales>
24
+ <children>
25
+ <optile_order translate="title" module="optile">
26
+ <title>optile Orders</title>
27
+ <action>adminhtml/optile_order</action>
28
+ <sort_order>15</sort_order>
29
+ </optile_order>
30
+ <optile_notification translate="title" module="optile">
31
+ <title>optile IPNs</title>
32
+ <action>adminhtml/optile_notification</action>
33
+ <sort_order>16</sort_order>
34
+ </optile_notification>
35
+ </children>
36
+ </sales>
37
+ </menu>
38
+ <acl>
39
+ <resources>
40
+ <admin>
41
+ <children>
42
+ <sales>
43
+ <children>
44
+ <optile_order translate="title">
45
+ <title>optile Orders Grid</title>
46
+ <sort_order>15</sort_order>
47
+ </optile_order>
48
+ <optile_notification translate="title">
49
+ <title>optile IPNs Grid</title>
50
+ <sort_order>15</sort_order>
51
+ </optile_notification>
52
+ </children>
53
+ </sales>
54
+ </children>
55
+ </admin>
56
+ </resources>
57
+ </acl>
58
+ </config>
app/code/community/Optile/Payment/etc/config.xml CHANGED
@@ -1,61 +1,118 @@
1
  <?xml version="1.0"?>
2
  <!--
3
  /**
4
- * This file is part of the Optile Payment Connector extension.
5
- *
6
- * Optile Payment Connector is free software: you can redistribute it and/or
7
- * modify it under the terms of the GNU General Public License as published
8
- * by the Free Software Foundation, either version 3 of the License, or
9
- * (at your option) any later version.
10
- *
11
- * Optile Payment Connector is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- * GNU General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU General Public License along with
17
- * Optile Payment Connector. If not, see <http://www.gnu.org/licenses/>.
18
  *
19
  * @author i-Ways <dev@i-ways.hr>
20
- * @copyright Copyright (c) 2013 Optile. (http://www.optile.de)
21
- * @license http://www.gnu.org/licenses/gpl.txt
22
  */
23
  -->
24
  <config>
25
- <modules>
26
- <Optile_Payment>
27
- <version>1.0.0</version>
28
- </Optile_Payment>
29
- </modules>
30
 
31
- <global>
32
- <models>
33
- <optile>
34
- <class>Optile_Payment_Model</class>
35
- </optile>
36
- </models>
37
- <blocks>
38
- <optile>
39
- <class>Optile_Payment_Block</class>
40
- </optile>
41
- </blocks>
42
- <helpers>
43
- <optile>
44
- <class>Optile_Payment_Helper</class>
45
- </optile>
46
- </helpers>
47
- </global>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
 
49
- <frontend>
50
- <routers>
51
- <optile>
52
- <use>standard</use>
53
- <args>
54
- <module>Optile_Payment</module>
55
- <frontName>optile</frontName>
56
- </args>
57
- </optile>
58
- </routers>
59
  <layout>
60
  <updates>
61
  <optile>
@@ -63,19 +120,69 @@
63
  </optile>
64
  </updates>
65
  </layout>
66
- </frontend>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
 
68
- <default>
69
- <payment>
70
- <optile>
71
- <model>optile/paymentMethod</model>
72
- <payment_action>authorize</payment_action>
73
- <active>0</active>
74
- <merchant_token backend_model="adminhtml/system_config_backend_encrypted" />
75
- <title>Optile</title>
76
- <test>1</test>
77
- <log_enabled>0</log_enabled>
78
- </optile>
79
- </payment>
80
- </default>
81
- </config>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  <?xml version="1.0"?>
2
  <!--
3
  /**
4
+ * Copyright optile GmbH 2013
5
+ * Licensed under the Software License Agreement in effect between optile and
6
+ * Licensee/user (the "License"); you may not use this file except in compliance
7
+ * with the License. You may obtain a copy of the License at
8
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
9
+ * copy has been provided to you for your records. Unless required by applicable
10
+ * law or agreed to in writing or otherwise stipulated in the License, software
11
+ * distributed under the License is distributed on an "as is" basis without
12
+ * warranties or conditions of any kind, either express or implied. See the
13
+ * License for the specific language governing permissions and limitations under
14
+ * the License.
 
 
 
15
  *
16
  * @author i-Ways <dev@i-ways.hr>
17
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
18
+ * @license http://www.optile.de/software-license-agreement
19
  */
20
  -->
21
  <config>
22
+ <modules>
23
+ <Optile_Payment>
24
+ <version>1.0.3</version>
25
+ </Optile_Payment>
26
+ </modules>
27
 
28
+ <global>
29
+ <models>
30
+ <optile>
31
+ <class>Optile_Payment_Model</class>
32
+ <resourceModel>optile_mysql4</resourceModel>
33
+ </optile>
34
+ <optile_mysql4>
35
+ <class>Optile_Payment_Model_Mysql4</class>
36
+ <entities>
37
+ <order>
38
+ <table>optile_order</table>
39
+ </order>
40
+ <quote>
41
+ <table>optile_quote</table>
42
+ </quote>
43
+ <notification>
44
+ <table>optile_notification</table>
45
+ </notification>
46
+ </entities>
47
+ </optile_mysql4>
48
+ </models>
49
+ <blocks>
50
+ <adminhtml>
51
+ <rewrite>
52
+ <sales_order_creditmemo_create_items>Optile_Payment_Block_Adminhtml_Order_Creditmemo_Create_Items</sales_order_creditmemo_create_items>
53
+ <sales_order_view>Optile_Payment_Block_Adminhtml_Order_View</sales_order_view>
54
+ </rewrite>
55
+ </adminhtml>
56
+ <optile>
57
+ <class>Optile_Payment_Block</class>
58
+ </optile>
59
+ </blocks>
60
+ <helpers>
61
+ <optile>
62
+ <class>Optile_Payment_Helper</class>
63
+ </optile>
64
+ </helpers>
65
+ <resources>
66
+ <optile_setup>
67
+ <setup>
68
+ <module>Optile_Payment</module>
69
+ </setup>
70
+ </optile_setup>
71
+ </resources>
72
+ <template>
73
+ <email>
74
+ <sales_email_order_cancel_template translate="label" module="sales">
75
+ <label>Order Cancelled</label>
76
+ <file>optile/order_cancel.html</file>
77
+ <type>html</type>
78
+ </sales_email_order_cancel_template>
79
+ <sales_email_order_cancel_guest_template translate="label" module="sales">
80
+ <label>Order Cancelled for Guest</label>
81
+ <file>optile/order_cancel_guest.html</file>
82
+ <type>html</type>
83
+ </sales_email_order_cancel_guest_template>
84
+ </email>
85
+ </template>
86
+ <events>
87
+ <sales_order_payment_cancel>
88
+ <observers>
89
+ <optile>
90
+ <class>optile/observer</class>
91
+ <method>cancelDeferredPayment</method>
92
+ </optile>
93
+ </observers>
94
+ </sales_order_payment_cancel>
95
+ <optile_notification_failed>
96
+ <observers>
97
+ <optile>
98
+ <class>optile/observer</class>
99
+ <method>sendOrderCancelEmail</method>
100
+ </optile>
101
+ </observers>
102
+ </optile_notification_failed>
103
+ </events>
104
+ </global>
105
 
106
+ <frontend>
107
+ <routers>
108
+ <optile>
109
+ <use>standard</use>
110
+ <args>
111
+ <module>Optile_Payment</module>
112
+ <frontName>optile</frontName>
113
+ </args>
114
+ </optile>
115
+ </routers>
116
  <layout>
117
  <updates>
118
  <optile>
120
  </optile>
121
  </updates>
122
  </layout>
123
+ <events>
124
+ <sales_quote_payment_save_commit_after>
125
+ <observers>
126
+ <optile>
127
+ <class>optile/observer</class>
128
+ <method>updateOptileQuote</method>
129
+ </optile>
130
+ </observers>
131
+ </sales_quote_payment_save_commit_after>
132
+ </events>
133
+ </frontend>
134
+
135
+ <adminhtml>
136
+ <events>
137
+ <admin_system_config_section_save_after>
138
+ <observers>
139
+ <optile>
140
+ <class>optile/observer</class>
141
+ <method>disableOtherPaymentMethods</method>
142
+ </optile>
143
+ </observers>
144
+ </admin_system_config_section_save_after>
145
+ </events>
146
+ </adminhtml>
147
+
148
+ <admin>
149
+ <routers>
150
+ <adminhtml>
151
+ <args>
152
+ <modules>
153
+ <Optile_Payment after="Mage_Adminhtml">Optile_Payment_Adminhtml</Optile_Payment>
154
+ </modules>
155
+ </args>
156
+ </adminhtml>
157
+ </routers>
158
+ </admin>
159
 
160
+ <default>
161
+ <payment>
162
+ <optile>
163
+ <model>optile/paymentMethod</model>
164
+ <payment_action>authorize</payment_action>
165
+ <active>0</active>
166
+ <merchant_token backend_model="adminhtml/system_config_backend_encrypted" />
167
+ <title>optile</title>
168
+ <api_url>https://api.sandbox.oscato.com</api_url>
169
+ <remote_ip>213.95.26.76</remote_ip>
170
+ <quote_prefix></quote_prefix>
171
+ <log_enabled>0</log_enabled>
172
+ <log_level>3</log_level>
173
+ <disable_methods>0</disable_methods>
174
+ <preselection_deferral>NON_DEFERRED</preselection_deferral>
175
+ <refund_enabled>1</refund_enabled>
176
+ </optile>
177
+ </payment>
178
+ <sales_email>
179
+ <order_cancel>
180
+ <enabled>1</enabled>
181
+ <template>sales_email_order_cancel_template</template>
182
+ <guest_template>sales_email_order_cancel_guest_template</guest_template>
183
+ <identity>sales</identity>
184
+ <copy_method>bcc</copy_method>
185
+ </order_cancel>
186
+ </sales_email>
187
+ </default>
188
+ </config>
app/code/community/Optile/Payment/etc/system.xml CHANGED
@@ -1,122 +1,331 @@
1
  <?xml version="1.0"?>
2
  <!--
3
  /**
4
- * This file is part of the Optile Payment Connector extension.
5
- *
6
- * Optile Payment Connector is free software: you can redistribute it and/or
7
- * modify it under the terms of the GNU General Public License as published
8
- * by the Free Software Foundation, either version 3 of the License, or
9
- * (at your option) any later version.
10
- *
11
- * Optile Payment Connector is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- * GNU General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU General Public License along with
17
- * Optile Payment Connector. If not, see <http://www.gnu.org/licenses/>.
18
  *
19
  * @author i-Ways <dev@i-ways.hr>
20
- * @copyright Copyright (c) 2013 Optile. (http://www.optile.de)
21
- * @license http://www.gnu.org/licenses/gpl.txt
22
  */
23
  -->
24
  <config>
25
- <sections>
26
- <payment>
27
- <groups>
28
- <optile translate="label" module="optile">
29
- <label>Optile</label>
30
- <sort_order>10</sort_order>
31
- <show_in_default>1</show_in_default>
32
- <show_in_website>1</show_in_website>
33
- <show_in_store>0</show_in_store>
34
- <fields>
35
- <active translate="label">
36
- <label>Enabled</label>
37
- <frontend_type>select</frontend_type>
38
- <source_model>adminhtml/system_config_source_yesno</source_model>
39
- <sort_order>1</sort_order>
40
- <show_in_default>1</show_in_default>
41
- <show_in_website>1</show_in_website>
42
- <show_in_store>0</show_in_store>
43
- </active>
44
- <title translate="label">
45
- <label>Title</label>
46
- <frontend_type>text</frontend_type>
47
- <sort_order>2</sort_order>
48
- <show_in_default>1</show_in_default>
49
- <show_in_website>1</show_in_website>
50
- <show_in_store>0</show_in_store>
51
- </title>
52
- <merchant_code translate="label">
53
- <label>Merchant Code</label>
54
- <frontend_type>text</frontend_type>
55
- <sort_order>15</sort_order>
56
- <show_in_default>1</show_in_default>
57
- <show_in_website>1</show_in_website>
58
- <show_in_store>0</show_in_store>
59
- </merchant_code>
60
- <merchant_token translate="label">
61
- <label>Merchant Token</label>
62
- <frontend_type>obscure</frontend_type>
63
- <backend_model>adminhtml/system_config_backend_encrypted
64
- </backend_model>
65
- <sort_order>20</sort_order>
66
- <show_in_default>1</show_in_default>
67
- <show_in_website>1</show_in_website>
68
- <show_in_store>0</show_in_store>
69
- </merchant_token>
70
- <test translate="label">
71
- <label>Test Mode</label>
72
- <frontend_type>select</frontend_type>
73
- <source_model>adminhtml/system_config_source_yesno</source_model>
74
- <sort_order>80</sort_order>
75
- <show_in_default>1</show_in_default>
76
- <show_in_website>1</show_in_website>
77
- <show_in_store>0</show_in_store>
78
- </test>
79
- <log_enabled translate="label">
80
- <label>Logging enabled?</label>
81
- <frontend_type>select</frontend_type>
82
- <source_model>adminhtml/system_config_source_yesno</source_model>
83
- <sort_order>80</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
- </log_enabled>
88
- <allowspecific translate="label">
89
- <label>Payment from Applicable Countries</label>
90
- <frontend_type>allowspecific</frontend_type>
91
- <sort_order>160</sort_order>
92
- <source_model>adminhtml/system_config_source_payment_allspecificcountries
93
- </source_model>
94
- <show_in_default>1</show_in_default>
95
- <show_in_website>1</show_in_website>
96
- <show_in_store>0</show_in_store>
97
- </allowspecific>
98
- <specificcountry translate="label">
99
- <label>Payment from Specific Countries</label>
100
- <frontend_type>multiselect</frontend_type>
101
- <sort_order>170</sort_order>
102
- <source_model>adminhtml/system_config_source_country
103
- </source_model>
104
- <show_in_default>1</show_in_default>
105
- <show_in_website>1</show_in_website>
106
- <show_in_store>0</show_in_store>
107
- </specificcountry>
108
- <sort_order translate="label">
109
- <label>Sort Order</label>
110
- <frontend_type>text</frontend_type>
111
- <sort_order>200</sort_order>
112
- <show_in_default>1</show_in_default>
113
- <show_in_website>1</show_in_website>
114
- <show_in_store>0</show_in_store>
115
- <frontend_class>validate-number</frontend_class>
116
- </sort_order>
117
- </fields>
118
- </optile>
119
- </groups>
120
- </payment>
121
- </sections>
122
- </config>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  <?xml version="1.0"?>
2
  <!--
3
  /**
4
+ * Copyright optile GmbH 2013
5
+ * Licensed under the Software License Agreement in effect between optile and
6
+ * Licensee/user (the "License"); you may not use this file except in compliance
7
+ * with the License. You may obtain a copy of the License at
8
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
9
+ * copy has been provided to you for your records. Unless required by applicable
10
+ * law or agreed to in writing or otherwise stipulated in the License, software
11
+ * distributed under the License is distributed on an "as is" basis without
12
+ * warranties or conditions of any kind, either express or implied. See the
13
+ * License for the specific language governing permissions and limitations under
14
+ * the License.
 
 
 
15
  *
16
  * @author i-Ways <dev@i-ways.hr>
17
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
18
+ * @license http://www.optile.de/software-license-agreement
19
  */
20
  -->
21
  <config>
22
+ <sections>
23
+ <payment>
24
+ <groups>
25
+ <optile translate="label" module="optile">
26
+ <label>optile</label>
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>1</show_in_store>
31
+ <expanded>1</expanded>
32
+ <comment><![CDATA[
33
+ <table style="width: 100%">
34
+ <tr>
35
+ <td style="width: 50%"><strong>Links:</strong></td>
36
+ <td style="width: 50%"><strong>Contact:</strong></td>
37
+ </tr>
38
+ <tr>
39
+ <td><a href="https://www.optile.net" target="_blank">About optile</a></td>
40
+ <td><a href="https://optile.zendesk.com/">Support Center</a></td>
41
+ </tr>
42
+ <tr>
43
+ <td><a href="https://www.optile.io/de/optile-magento-plug-in-doc" target="_blank">Magento Plugin Documentation</a></td>
44
+ <td>&nbsp;</td>
45
+ </tr>
46
+ <tr>
47
+ <td><a href="https://portal.optile.net/" target="_blank">optile Dashboard for Configuration and Transaction Monitoring</a></td>
48
+ <td>&nbsp;</td>
49
+ </tr>
50
+ </table>
51
+ <br/>
52
+ ]]></comment>
53
+ <fields>
54
+ <active translate="label">
55
+ <label>Enabled</label>
56
+ <frontend_type>select</frontend_type>
57
+ <source_model>adminhtml/system_config_source_yesno</source_model>
58
+ <sort_order>1</sort_order>
59
+ <show_in_default>1</show_in_default>
60
+ <show_in_website>1</show_in_website>
61
+ <show_in_store>0</show_in_store>
62
+ </active>
63
+ <title translate="label">
64
+ <label>Title</label>
65
+ <frontend_type>text</frontend_type>
66
+ <sort_order>2</sort_order>
67
+ <show_in_default>1</show_in_default>
68
+ <show_in_website>1</show_in_website>
69
+ <show_in_store>0</show_in_store>
70
+ </title>
71
+ <merchant_code translate="label">
72
+ <label>Merchant Code</label>
73
+ <frontend_type>text</frontend_type>
74
+ <sort_order>10</sort_order>
75
+ <show_in_default>1</show_in_default>
76
+ <show_in_website>1</show_in_website>
77
+ <show_in_store>0</show_in_store>
78
+ </merchant_code>
79
+ <merchant_token translate="label">
80
+ <label>Merchant Token</label>
81
+ <frontend_type>obscure</frontend_type>
82
+ <backend_model>adminhtml/system_config_backend_encrypted
83
+ </backend_model>
84
+ <sort_order>20</sort_order>
85
+ <show_in_default>1</show_in_default>
86
+ <show_in_website>1</show_in_website>
87
+ <show_in_store>0</show_in_store>
88
+ </merchant_token>
89
+ <api_url translate="label">
90
+ <label>optile API URL</label>
91
+ <frontend_type>text</frontend_type>
92
+ <comment></comment>
93
+ <sort_order>30</sort_order>
94
+ <show_in_default>1</show_in_default>
95
+ <show_in_website>1</show_in_website>
96
+ <show_in_store>0</show_in_store>
97
+ </api_url>
98
+ <remote_ip translate="label">
99
+ <label>optile Notification IP</label>
100
+ <frontend_type>text</frontend_type>
101
+ <comment>optile IP that sends payment notifications. Notifications will be accepted only from this IP address.</comment>
102
+ <sort_order>40</sort_order>
103
+ <show_in_default>1</show_in_default>
104
+ <show_in_website>1</show_in_website>
105
+ <show_in_store>0</show_in_store>
106
+ </remote_ip>
107
+ <quote_prefix translate="label">
108
+ <label>Transaction ID prefix</label>
109
+ <frontend_type>text</frontend_type>
110
+ <comment>Prefix that will be used for all transactions</comment>
111
+ <sort_order>40</sort_order>
112
+ <show_in_default>1</show_in_default>
113
+ <show_in_website>1</show_in_website>
114
+ <show_in_store>0</show_in_store>
115
+ </quote_prefix>
116
+ <proxy_ip translate="label">
117
+ <label>Proxy / Load balancer IP address</label>
118
+ <comment>If your server is behind a load balancer or proxy, fill in its IP address here. This should be a trusted IP that belongs to you.</comment>
119
+ <sort_order>50</sort_order>
120
+ <show_in_default>1</show_in_default>
121
+ <show_in_website>1</show_in_website>
122
+ <show_in_store>0</show_in_store>
123
+ </proxy_ip>
124
+ <log_enabled translate="label">
125
+ <label>Logging enabled?</label>
126
+ <frontend_type>select</frontend_type>
127
+ <source_model>adminhtml/system_config_source_yesno</source_model>
128
+ <sort_order>60</sort_order>
129
+ <show_in_default>1</show_in_default>
130
+ <show_in_website>1</show_in_website>
131
+ <show_in_store>0</show_in_store>
132
+ </log_enabled>
133
+ <log_level translate="label">
134
+ <label>Logging level</label>
135
+ <frontend_type>select</frontend_type>
136
+ <source_model>optile/system_config_source_loglevel</source_model>
137
+ <sort_order>65</sort_order>
138
+ <show_in_default>1</show_in_default>
139
+ <show_in_website>1</show_in_website>
140
+ <show_in_store>0</show_in_store>
141
+ <comment><![CDATA[Determines the minimum log level that will be written to log files.]]></comment>
142
+ </log_level>
143
+ <allowspecific translate="label">
144
+ <label>Payment from Applicable Countries</label>
145
+ <frontend_type>allowspecific</frontend_type>
146
+ <sort_order>160</sort_order>
147
+ <source_model>adminhtml/system_config_source_payment_allspecificcountries
148
+ </source_model>
149
+ <show_in_default>1</show_in_default>
150
+ <show_in_website>1</show_in_website>
151
+ <show_in_store>0</show_in_store>
152
+ </allowspecific>
153
+ <specificcountry translate="label">
154
+ <label>Payment from Specific Countries</label>
155
+ <frontend_type>multiselect</frontend_type>
156
+ <sort_order>170</sort_order>
157
+ <source_model>adminhtml/system_config_source_country
158
+ </source_model>
159
+ <show_in_default>1</show_in_default>
160
+ <show_in_website>1</show_in_website>
161
+ <show_in_store>0</show_in_store>
162
+ </specificcountry>
163
+ <instructions>
164
+ <label>Payment instructions</label>
165
+ <frontend_model>optile/adminhtml_system_config_frontend_instructions</frontend_model>
166
+ <backend_model>optile/system_config_backend_instructions</backend_model>
167
+ <sort_order>180</sort_order>
168
+ <show_in_default>1</show_in_default>
169
+ <show_in_website>1</show_in_website>
170
+ <show_in_store>1</show_in_store>
171
+ <comment>Payment instructions per payment method.</comment>
172
+ </instructions>
173
+ <sort_order translate="label">
174
+ <label>Sort Order</label>
175
+ <frontend_type>text</frontend_type>
176
+ <sort_order>200</sort_order>
177
+ <show_in_default>1</show_in_default>
178
+ <show_in_website>1</show_in_website>
179
+ <show_in_store>0</show_in_store>
180
+ <frontend_class>validate-number</frontend_class>
181
+ </sort_order>
182
+ <preselection_deferral translate="label">
183
+ <label>Deferred mode:</label>
184
+ <frontend_type>select</frontend_type>
185
+ <source_model>optile/system_config_source_deferral</source_model>
186
+ <sort_order>210</sort_order>
187
+ <show_in_default>1</show_in_default>
188
+ <show_in_website>1</show_in_website>
189
+ <show_in_store>0</show_in_store>
190
+ <comment><![CDATA[
191
+ <b>Deferred</b>: Only networks which support deferred payments are listed. They are in deferred mode for subsequent charges<br/>
192
+ <b>NON_DEFERRED</b> (default): All networks which support immediate payment collection are listed. They are in non-deferred mode when a charge request hits them.<br/>
193
+ <b>ANY</b>: All networks are returned. If they support both modes, they are returned in deferred mode.
194
+ ]]></comment>
195
+ </preselection_deferral>
196
+ <refund_enabled translate="label">
197
+ <label>Refunds enabled?</label>
198
+ <frontend_type>select</frontend_type>
199
+ <source_model>adminhtml/system_config_source_yesno</source_model>
200
+ <sort_order>220</sort_order>
201
+ <show_in_default>1</show_in_default>
202
+ <show_in_website>1</show_in_website>
203
+ <show_in_store>0</show_in_store>
204
+ </refund_enabled>
205
+ <active_methods_found>
206
+ <label>Active methods found</label>
207
+ <frontend_type>hidden</frontend_type>
208
+ <backend_model>optile/system_config_backend_enabledmethods_bool</backend_model>
209
+ <sort_order>900</sort_order>
210
+ <show_in_default>1</show_in_default>
211
+ <show_in_website>1</show_in_website>
212
+ <show_in_store>0</show_in_store>
213
+ <!-- hide this field -->
214
+ <depends>
215
+ <non_existent>1</non_existent>
216
+ </depends>
217
+ </active_methods_found>
218
+ <no_active_methods_found>
219
+ <label><![CDATA[<span style="color:green">All other payment methods are disabled</span>]]></label>
220
+ <frontend_type>hidden</frontend_type>
221
+ <frontend_model>optile/adminhtml_system_config_frontend_noactivemethods</frontend_model>
222
+ <sort_order>905</sort_order>
223
+ <show_in_default>1</show_in_default>
224
+ <show_in_website>1</show_in_website>
225
+ <show_in_store>0</show_in_store>
226
+ <depends>
227
+ <active_methods_found>0</active_methods_found>
228
+ </depends>
229
+ </no_active_methods_found>
230
+ <disable_methods translate="label">
231
+ <label>Disable other payment methods</label>
232
+ <frontend_type>select</frontend_type>
233
+ <source_model>adminhtml/system_config_source_yesno</source_model>
234
+ <backend_model>optile/system_config_backend_disablemethods</backend_model>
235
+ <comment><![CDATA[<span style="color:red">Other methods are still enabled</span>]]></comment>
236
+ <sort_order>910</sort_order>
237
+ <show_in_default>1</show_in_default>
238
+ <show_in_website>1</show_in_website>
239
+ <show_in_store>0</show_in_store>
240
+ <depends>
241
+ <active_methods_found>1</active_methods_found>
242
+ </depends>
243
+ </disable_methods>
244
+ <methods_to_disable>
245
+ <label>Payment methods to disable</label>
246
+ <frontend_type>multiselect</frontend_type>
247
+ <source_model>optile/system_config_source_enabledmethods</source_model>
248
+ <backend_model>optile/system_config_backend_enabledmethods_select</backend_model>
249
+ <can_be_empty>0</can_be_empty>
250
+ <sort_order>920</sort_order>
251
+ <show_in_default>1</show_in_default>
252
+ <show_in_website>1</show_in_website>
253
+ <show_in_store>0</show_in_store>
254
+ <depends>
255
+ <disable_methods>1</disable_methods>
256
+ </depends>
257
+ </methods_to_disable>
258
+ </fields>
259
+ </optile>
260
+ </groups>
261
+ </payment>
262
+ <sales_email>
263
+ <groups>
264
+ <order_cancel translate="label">
265
+ <label>Order Cancellation</label>
266
+ <frontend_type>text</frontend_type>
267
+ <sort_order>11</sort_order>
268
+ <show_in_default>1</show_in_default>
269
+ <show_in_website>1</show_in_website>
270
+ <show_in_store>1</show_in_store>
271
+ <fields>
272
+ <enabled translate="label">
273
+ <label>Enabled</label>
274
+ <frontend_type>select</frontend_type>
275
+ <source_model>adminhtml/system_config_source_yesno</source_model>
276
+ <sort_order>0</sort_order>
277
+ <show_in_default>1</show_in_default>
278
+ <show_in_website>1</show_in_website>
279
+ <show_in_store>1</show_in_store>
280
+ </enabled>
281
+ <identity translate="label">
282
+ <label>Order Cancellation Email Sender</label>
283
+ <frontend_type>select</frontend_type>
284
+ <source_model>adminhtml/system_config_source_email_identity</source_model>
285
+ <sort_order>1</sort_order>
286
+ <show_in_default>1</show_in_default>
287
+ <show_in_website>1</show_in_website>
288
+ <show_in_store>1</show_in_store>
289
+ </identity>
290
+ <template translate="label">
291
+ <label>Order Cancellation Template</label>
292
+ <frontend_type>select</frontend_type>
293
+ <source_model>adminhtml/system_config_source_email_template</source_model>
294
+ <sort_order>2</sort_order>
295
+ <show_in_default>1</show_in_default>
296
+ <show_in_website>1</show_in_website>
297
+ <show_in_store>1</show_in_store>
298
+ </template>
299
+ <guest_template translate="label">
300
+ <label>Order Cancellation Template for Guest</label>
301
+ <frontend_type>select</frontend_type>
302
+ <source_model>adminhtml/system_config_source_email_template</source_model>
303
+ <sort_order>3</sort_order>
304
+ <show_in_default>1</show_in_default>
305
+ <show_in_website>1</show_in_website>
306
+ <show_in_store>1</show_in_store>
307
+ </guest_template>
308
+ <copy_to translate="label comment">
309
+ <label>Send Cancellation Email Copy To</label>
310
+ <frontend_type>text</frontend_type>
311
+ <sort_order>4</sort_order>
312
+ <show_in_default>1</show_in_default>
313
+ <show_in_website>1</show_in_website>
314
+ <show_in_store>1</show_in_store>
315
+ <comment>Comma-separated.</comment>
316
+ </copy_to>
317
+ <copy_method translate="label">
318
+ <label>Send Cancellation Email Copy Method</label>
319
+ <frontend_type>select</frontend_type>
320
+ <source_model>adminhtml/system_config_source_email_method</source_model>
321
+ <sort_order>5</sort_order>
322
+ <show_in_default>1</show_in_default>
323
+ <show_in_website>1</show_in_website>
324
+ <show_in_store>1</show_in_store>
325
+ </copy_method>
326
+ </fields>
327
+ </order_cancel>
328
+ </groups>
329
+ </sales_email>
330
+ </sections>
331
+ </config>
app/code/community/Optile/Payment/sql/optile_setup/mysql4-install-1.0.0.php ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
14
+ *
15
+ * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
+ */
19
+
20
+ $installer = $this;
21
+ /* @var $installer Mage_Core_Model_Resource_Setup */
22
+
23
+ $installer->startSetup();
24
+
25
+ // Create Optile table
26
+ $table = new Varien_Db_Ddl_Table;
27
+ $table
28
+ ->setName($this->getTable('optile/quote'))
29
+ ->setOption('type', 'InnoDB')
30
+ ->setOption('charset', 'utf8')
31
+ ->addColumn('transaction_id', Varien_Db_Ddl_Table::TYPE_INTEGER, 10, array(
32
+ 'unsigned' => true,
33
+ 'nullable' => false,
34
+ 'primary' => true,
35
+ ))
36
+ ->addColumn('long_id', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255)
37
+ ->addColumn('payment_network', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255)
38
+ ->addForeignKey(
39
+ 'FK_OPTILE_QUOTE_TRANSACTION_ID',
40
+ 'transaction_id',
41
+ 'sales_flat_quote',
42
+ 'entity_id',
43
+ Varien_Db_Ddl_Table::ACTION_CASCADE,
44
+ Varien_Db_Ddl_Table::ACTION_CASCADE
45
+ )
46
+ ;
47
+ $installer->getConnection()->createTable($table);
48
+
49
+ // Installation successful: notify admin to configure the module.
50
+ $inbox = Mage::getModel('adminnotification/inbox');
51
+ /* @var $inbox Mage_AdminNotification_Model_Inbox */
52
+ $inbox->add(
53
+ Mage_AdminNotification_Model_Inbox::SEVERITY_MAJOR,
54
+ 'Optile Payment Extension: Please disable other payment methods',
55
+ 'Some payment methods other than Optile are still enabled. Please go to System Configuration to disable them by configuring the Optile Payment Extension.'
56
+ );
57
+
58
+ $installer->endSetup();
app/code/community/Optile/Payment/sql/optile_setup/mysql4-upgrade-1.0.0-1.0.1.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
14
+ *
15
+ * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
+ */
19
+
20
+ $installer = $this;
21
+ /* @var $installer Mage_Core_Model_Resource_Setup */
22
+
23
+ $installer->startSetup();
24
+
25
+ $table = $installer->getTable('optile/quote');
26
+ $conn = $installer->getConnection();
27
+ /* @var $conn Varien_Db_Adapter_Pdo_Mysql */
28
+
29
+ $conn->addColumn($table, 'monitor_link', 'varchar(255)');
30
+
31
+ // Base URL for viewing transactions in Optile Monitor.
32
+ $viewUrl = 'https://sandbox.oscato.com/monitor/transactions/';
33
+
34
+ $conn->update($table, array(
35
+ 'monitor_link' => new Zend_Db_Expr("concat('$viewUrl', long_id)"),
36
+ ));
37
+
38
+ $installer->endSetup();
app/code/community/Optile/Payment/sql/optile_setup/mysql4-upgrade-1.0.1-1.0.2.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
14
+ *
15
+ * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
+ */
19
+
20
+ $installer = $this;
21
+ /* @var $installer Mage_Core_Model_Resource_Setup */
22
+
23
+ $installer->startSetup();
24
+
25
+ $newStatus = Mage::getModel('sales/order_status');
26
+ /* @var $newStatus Mage_Sales_Model_Order_Status */
27
+
28
+ $newStatus
29
+ ->setStatus('unexpected_notification')
30
+ ->setLabel('Unexpected Optile Notification')
31
+ ->save()
32
+ ;
33
+
34
+ $installer->endSetup();
app/code/community/Optile/Payment/sql/optile_setup/mysql4-upgrade-1.0.2-1.0.3.php ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
14
+ *
15
+ * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
+ */
19
+
20
+ $installer = $this;
21
+ /* @var $installer Mage_Core_Model_Resource_Setup */
22
+
23
+ $installer->startSetup();
24
+
25
+ // Create a table for keeping record of Optile IPNs
26
+ $installer->run("
27
+ CREATE TABLE IF NOT EXISTS {$this->getTable('optile/notification')} (
28
+ `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
29
+ `transaction_id` int(10) unsigned NOT NULL,
30
+ `date` datetime NOT NULL COMMENT 'Date and time when notification was received',
31
+ `received_data` text NOT NULL COMMENT 'Received data',
32
+ `long_id` varchar(100) NOT NULL,
33
+ `return_code` varchar(100) NOT NULL,
34
+ `interaction_code` varchar(100) NOT NULL,
35
+ `reason_code` varchar(100) NOT NULL,
36
+ `result_info` varchar(100) NOT NULL,
37
+ `status` int(11) NOT NULL COMMENT 'Notification status',
38
+ PRIMARY KEY (`id`),
39
+ KEY `long_id` (`long_id`),
40
+ KEY `transaction_id` (`transaction_id`)
41
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
42
+ ");
43
+ $installer->run("
44
+ ALTER TABLE {$this->getTable('optile/quote')} ADD `deferred_mode` TINYINT NOT NULL DEFAULT '0'
45
+ ");
46
+
47
+ $installer->endSetup();
app/design/adminhtml/default/default/template/optile/info.phtml ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
14
+ *
15
+ * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
+ */
19
+
20
+ /**
21
+ * @var $this Optile_Payment_Block_Info
22
+ */
23
+ ?>
24
+ <?php echo $this->htmlEscape($this->getMethod()->getTitle()) ?>
25
+
26
+ <?php if ($_specificInfo = $this->getSpecificInformation()):?>
27
+ <table>
28
+ <?php foreach ($_specificInfo as $_label => $_value):?>
29
+ <?php if (empty($_value)) continue; ?>
30
+ <tr>
31
+ <td><?php echo $this->escapeHtml($_label)?>:</td>
32
+ <td><?php echo nl2br(implode($this->getValueAsArray($_value, true), "\n"))?></td>
33
+ </tr>
34
+ <?php endforeach; ?>
35
+ </table>
36
+ <?php endif;?>
37
+
38
+ <?php echo $this->getChildHtml()?>
app/design/adminhtml/default/default/template/optile/notification_view.phtml ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php $data = $this->getNotification()->getReceivedData() ?>
2
+
3
+ <div class="content-header">
4
+ <table cellspacing="0">
5
+ <tbody><tr>
6
+ <td style="width:50%;"><h3 class="icon-head head-adminhtml-notification"><?php echo $this->__("IPN details") ?></h3></td>
7
+ <td class="form-buttons">
8
+ <button style="" onclick="setLocation('<?php echo Mage::helper('adminhtml')->getUrl('*/*/index') ?>')" class="scalable back" type="button" title="<?php echo $this->__('Back') ?>" id="back"><span><span><span><?php echo $this->__('Back') ?></span></span></span></button>
9
+ </td>
10
+ </tr>
11
+ </tbody></table>
12
+ </div>
13
+
14
+ <table>
15
+
16
+ <?php foreach ($data as $k => $v): ?>
17
+ <tr>
18
+ <th><?php echo $k ?></th>
19
+ <td><?php echo $v ?></td>
20
+ </tr>
21
+
22
+ <?php endforeach; ?>
23
+ </table>
app/design/frontend/base/default/layout/optile/payment.xml CHANGED
@@ -1,7 +1,27 @@
1
  <?xml version="1.0"?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  <layout version="0.1.0">
3
  <checkout_onepage_index>
4
  <reference name="head">
 
5
  <action method="addJs"><script>optile/jquery.2.0.3.min.js</script></action>
6
  <action method="addJs"><script>optile/jquery.noconflict.js</script></action>
7
  <action method="addJs"><script>optile/optilevalidation.js</script></action>
1
  <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Copyright optile GmbH 2013
5
+ * Licensed under the Software License Agreement in effect between optile and
6
+ * Licensee/user (the "License"); you may not use this file except in compliance
7
+ * with the License. You may obtain a copy of the License at
8
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
9
+ * copy has been provided to you for your records. Unless required by applicable
10
+ * law or agreed to in writing or otherwise stipulated in the License, software
11
+ * distributed under the License is distributed on an "as is" basis without
12
+ * warranties or conditions of any kind, either express or implied. See the
13
+ * License for the specific language governing permissions and limitations under
14
+ * the License.
15
+ *
16
+ * @author i-Ways <dev@i-ways.hr>
17
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
18
+ * @license http://www.optile.de/software-license-agreement
19
+ */
20
+ -->
21
  <layout version="0.1.0">
22
  <checkout_onepage_index>
23
  <reference name="head">
24
+ <action method="addCss"><stylesheet>optile/css/style.css</stylesheet></action>
25
  <action method="addJs"><script>optile/jquery.2.0.3.min.js</script></action>
26
  <action method="addJs"><script>optile/jquery.noconflict.js</script></action>
27
  <action method="addJs"><script>optile/optilevalidation.js</script></action>
app/design/frontend/base/default/template/optile/info.phtml ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
14
+ *
15
+ * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
+ */
19
+
20
+ /**
21
+ * @var $this Optile_Payment_Block_Info
22
+ */
23
+ $_specificInfo = $this->getSpecificInformation();
24
+ ?>
25
+ <p><strong><?php echo $_specificInfo['Payment Network'] ?></strong></p>
26
+
27
+ <?php echo $this->getChildHtml()?>
app/design/frontend/base/default/template/optile/list.phtml CHANGED
@@ -1,82 +1,122 @@
1
  <?php
2
  /**
3
- * This file is part of the Optile Payment Connector extension.
4
- *
5
- * Optile Payment Connector is free software: you can redistribute it and/or
6
- * modify it under the terms of the GNU General Public License as published
7
- * by the Free Software Foundation, either version 3 of the License, or
8
- * (at your option) any later version.
9
- *
10
- * Optile Payment Connector is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License along with
16
- * Optile Payment Connector. If not, see <http://www.gnu.org/licenses/>.
17
  *
18
  * @author i-Ways <dev@i-ways.hr>
19
- * @copyright Copyright (c) 2013 Optile. (http://www.optile.de)
20
- * @license http://www.gnu.org/licenses/gpl.txt
21
  */
22
-
23
  /* @var $this Optile_Payment_Block_List */
24
  ?>
25
  <?php $response = $this->getListResponse() ?>
26
  <?php $networkGroups = $response->getNetworks() ?>
27
  <script type="text/javascript">
28
  //<![CDATA[
29
- var self = this;
30
- var controller;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
 
32
- jQuery(function() {
33
- var forms = Array();
34
- <?php foreach($networkGroups as $networkGroupCode => $networks): ?>
35
- <?php foreach($networks as $network): ?>
36
- forms.push(new ValidationForm('<?php echo $this->getFormId($network->getCode()) ?>', '<?php echo $network->getLinks()->getValidationLink() ?>'));
37
- <?php endforeach ?>
38
- <?php endforeach ?>
39
-
40
- self.controller = new ValidationController(
41
- jQuery('#payment_form_optile'),
42
- forms,
43
- jQuery('#payment-buttons-container > button')
44
- );
45
- self.controller.Init();
46
- });
 
 
 
 
 
 
 
 
 
 
47
 
48
  //]]>
49
  </script>
50
- <style>
51
- .optile-error-msg { color: red; }
52
- </style>
53
 
54
- <div id="payment_form_optile" style="display:none;">
55
- <input type="hidden" name="optile-list-self" id="optile-list-self" value="<?php $links = $response->getLinks(); echo $links['self']; ?>">
56
- <?php $first = true ?>
57
- <ul style="padding-left: 20px">
58
- <?php foreach($networkGroups as $networkGroupCode => $networks): ?>
59
- <div id="optile-group-<?php echo $networkGroupCode ?>">
60
- <?php foreach($networks as $network): ?>
61
- <li>
62
- <input type="hidden" id="optile-<?php echo $network->getCode() ?>-operation" name="operation" value="<?php echo $network->getLinks()->getOperation() ?>">
63
- <input type="radio" name="optile-selected-network" onclick="optileForm.switchMethod('optile-<?php echo $network->getCode() ?>')" value="optile-<?php echo $network->getCode() ?>" <?php if($first): echo "checked"; $first = false; endif ?>>
64
- <img src="<?php echo $network->getLinks()->getLogoLink() ?>" />
65
- <div id="optile-<?php echo $network->getCode() ?>-network" style="display:none;">
66
- <?php echo $this->renderFormHtml($network->getLinks()->getLocalizedFormHtml(), $this->getFormId($network->getCode())) ?>
67
- </div>
68
- </li>
69
- <?php endforeach ?>
70
- </div>
71
- <?php endforeach ?>
72
- </ul>
73
- </div>
74
 
75
- <script type="text/javascript">
76
- //<![CDATA[
77
- jQuery(function() {
78
- window.optileForm = new OptileForm('co-payment-form');
79
- optileForm.init();
80
- });
81
- //]]>
82
- </script>
 
 
 
 
 
 
 
 
 
1
  <?php
2
  /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
 
 
 
14
  *
15
  * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
  */
 
19
  /* @var $this Optile_Payment_Block_List */
20
  ?>
21
  <?php $response = $this->getListResponse() ?>
22
  <?php $networkGroups = $response->getNetworks() ?>
23
  <script type="text/javascript">
24
  //<![CDATA[
25
+ var self = this;
26
+ var controller;
27
+ var terms_and_conditions_error_text = "<?php echo $this->__("Please agree to all the terms and conditions before placing the order."); ?>";
28
+
29
+ jQuery(function() {
30
+ console.log("List request executed");
31
+ window.cartPageUrl = '<?php echo $this->getUrl('checkout/cart') ?>'; //T: Moved here because of Magento 1.8 update - loads this block only on AJAX call
32
+ var forms = Array();
33
+ <?php foreach ($networkGroups as $networkGroupCode => $networks): ?>
34
+ <?php foreach ($networks as $network): ?>
35
+ forms.push(new ValidationForm('<?php echo $this->getFormId($network->getCode()) ?>', '<?php echo $network->getLinks()->getValidationLink() ?>', '<?php echo $network->getLinks()->getOperation() ?>', '<?php echo $network->getCode() ?>'));
36
+ <?php endforeach ?>
37
+ <?php endforeach ?>
38
+
39
+ if (typeof (window.optileListLoadCounter) == "undefined") {
40
+ window.optileListLoadCounter = 0;
41
+ }
42
+ window.optileListLoadCounter++;
43
+ console.log("Optile list load counter: " + window.optileListLoadCounter);
44
+ self.controller = new ValidationController(
45
+ jQuery('#payment_form_optile'),
46
+ forms,
47
+ jQuery('#payment-buttons-container > button'),
48
+ 'input[name="optile-selected-network"]:checked'
49
+ );
50
+ self.controller.Init();
51
+
52
+ // OptileForm handles optile payment network radios and show/hide of the forms
53
+ window.optileForm = new OptileForm('co-payment-form');
54
+ window.optileForm.init();
55
+
56
+ jQuery('#payment_form_optile .verificationCode').parent().append('<span class="after">?</span>')
57
+
58
+ jQuery('#payment_form_optile .row3 .col2 .after').hover(
59
+ function() {
60
+ jQuery('#payment_form_optile .hint').show();
61
+ }, function() {
62
+ jQuery('#payment_form_optile .hint').hide();
63
+ }
64
+ );
65
 
66
+ if (window.optileListLoadCounter === 1) {
67
+ jQuery('#p_method_optile').click(); // optile method has to be preselected
68
+ }
69
+ jQuery('#p_method_optile').hide();
70
+ jQuery('label[for=p_method_optile]').hide();
71
+
72
+ // this is saved in the CHARGE on RETRY/TRY_OTHER_ACCOUNT handler
73
+ if (window.savedOptileData) {
74
+ console.log("filling in saved Optile data");
75
+ var form = self.controller.FindFormByFormId(window.savedOptileNetworkCode);
76
+ form.BindValues(window.savedOptileData);
77
+ window.optileForm.switchMethod(window.savedOptileNetworkCode);
78
+ jQuery('#optile-selected-network-' + form.networkCode).click();
79
+
80
+ delete window.savedOptileNetworkCode;
81
+ delete window.savedOptileData;
82
+ } else {
83
+ console.log("No saved Optile Data found.");
84
+ }
85
+
86
+ // OneStep checkout and design specific:
87
+ if (window.optileListLoadCounter > 1) {
88
+ jQuery('.checkout-onepage-index #p_method_optile').parent().hide();
89
+ }
90
+ });
91
 
92
  //]]>
93
  </script>
 
 
 
94
 
95
+ <div id="payment_form_optile">
96
+ <input type="hidden" name="optile-list-self" id="optile-list-self" value="<?php
97
+ $links = $response->getLinks();
98
+ echo $links['self'];
99
+ ?>">
100
+ <?php $first = true ?>
101
+ <ul>
102
+ <?php if (count($networkGroups) == 0): ?>
103
+ <li><div class="optile-error-msg"><?php echo $response->getInfo() ?></div></li>
104
+ <?php endif ?>
 
 
 
 
 
 
 
 
 
 
105
 
106
+ <?php foreach ($networkGroups as $networkGroupCode => $networks): ?>
107
+ <div id="optile-group-<?php echo $networkGroupCode ?>">
108
+ <?php foreach ($networks as $network): ?>
109
+ <li>
110
+ <input type="hidden" id="optile_<?php echo $network->getCode() ?>-operation" name="operation" value="<?php echo $network->getLinks()->getOperation() ?>">
111
+ <input type="radio" name="optile-selected-network" id="optile-selected-network-<?php echo $network->getCode() ?>" onclick="optileForm.switchMethod('optile_<?php echo $network->getCode() ?>')" value="optile_<?php echo $network->getCode() ?>" <?php if($first): echo "checked"; $first = false; endif ?>>
112
+ <label for="optile-selected-network-<?php echo $network->getCode() ?>"><img src="<?php echo $network->getLinks()->getLogoLink() ?>" /></label>
113
+ <div><?php echo Mage::helper('optile')->getPaymentInstructions($network->getCode(), Mage::app()->getStore()->getId()); ?></div>
114
+ <div id="optile_<?php echo $network->getCode() ?>-network" style="display:none;">
115
+ <?php echo $this->renderFormHtml($network->getLinks()->getLocalizedFormHtml(), $this->getFormId($network->getCode())) ?>
116
+ </div>
117
+ </li>
118
+ <?php endforeach ?>
119
+ </div>
120
+ <?php endforeach ?>
121
+ </ul>
122
+ </div>
app/design/frontend/base/default/template/optile/list_error.phtml ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script type="text/javascript">
2
+ jQuery("#p_method_optile").parent().hide();
3
+
4
+ //TODO: refactor this
5
+ if( typeof(window.optileListLoadCounter) == "undefined"){
6
+ window.optileListLoadCounter = 1;
7
+ }
8
+ window.optileListLoadCounter++;
9
+
10
+ // OneStep checkout and design specific:
11
+ if(window.optileListLoadCounter > 1){
12
+ jQuery('.checkout-onepage-index #p_method_optile').parent().hide();
13
+ restylePaymentCheck();
14
+ restyleSelect();
15
+ }
16
+ </script>
17
+ <p><?php echo $this->__("Unable to display available payment networks, please check if you entered all required fields and try again"); ?></p>
app/etc/modules/Optile_Payment.xml CHANGED
@@ -1,24 +1,21 @@
1
  <?xml version="1.0"?>
2
  <!--
3
  /**
4
- * This file is part of the Optile Payment Connector extension.
5
- *
6
- * Optile Payment Connector is free software: you can redistribute it and/or
7
- * modify it under the terms of the GNU General Public License as published
8
- * by the Free Software Foundation, either version 3 of the License, or
9
- * (at your option) any later version.
10
- *
11
- * Optile Payment Connector is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- * GNU General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU General Public License along with
17
- * Optile Payment Connector. If not, see <http://www.gnu.org/licenses/>.
18
  *
19
  * @author i-Ways <dev@i-ways.hr>
20
- * @copyright Copyright (c) 2013 Optile. (http://www.optile.de)
21
- * @license http://www.gnu.org/licenses/gpl.txt
22
  */
23
  -->
24
  <config>
1
  <?xml version="1.0"?>
2
  <!--
3
  /**
4
+ * Copyright optile GmbH 2013
5
+ * Licensed under the Software License Agreement in effect between optile and
6
+ * Licensee/user (the "License"); you may not use this file except in compliance
7
+ * with the License. You may obtain a copy of the License at
8
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
9
+ * copy has been provided to you for your records. Unless required by applicable
10
+ * law or agreed to in writing or otherwise stipulated in the License, software
11
+ * distributed under the License is distributed on an "as is" basis without
12
+ * warranties or conditions of any kind, either express or implied. See the
13
+ * License for the specific language governing permissions and limitations under
14
+ * the License.
 
 
 
15
  *
16
  * @author i-Ways <dev@i-ways.hr>
17
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
18
+ * @license http://www.optile.de/software-license-agreement
19
  */
20
  -->
21
  <config>
js/optile/checkout.js CHANGED
@@ -1,427 +1,575 @@
1
  /**
2
- * This file is part of the Optile Payment Connector extension.
3
- *
4
- * Optile Payment Connector is free software: you can redistribute it and/or
5
- * modify it under the terms of the GNU General Public License as published
6
- * by the Free Software Foundation, either version 3 of the License, or
7
- * (at your option) any later version.
8
- *
9
- * Optile Payment Connector is distributed in the hope that it will be useful,
10
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
- * GNU General Public License for more details.
13
- *
14
- * You should have received a copy of the GNU General Public License along with
15
- * Optile Payment Connector. If not, see <http://www.gnu.org/licenses/>.
16
  *
17
  * @author i-Ways <dev@i-ways.hr>
18
- * @copyright Copyright (c) 2013 Optile. (http://www.optile.de)
19
- * @license http://www.gnu.org/licenses/gpl.txt
20
  */
 
 
 
21
 
22
  jQuery(function() {
23
- // overrides optilevalidation.js so it doesn't require 'submit' button instance
24
- ValidationController.prototype.Init = function() {
25
- var self = this;
26
- this.forms.forEach(function(item) {
27
- item.Build(self.widget);
28
- });
29
- };
30
-
31
- ValidationController.prototype.Validate = function(event) {
32
- var self = this;
33
- var network = this.widget.find("input[name=\"optile-selected-network\"]:checked").val();
34
- var form = this.FindFormByFormId(network);
35
- var data = form.ToJSON();
36
- var url = form.validationUrl;
37
- var ok = false;
38
-
39
- jQuery.post(url, data, function(resultData, resultStatus, xhr) {
40
- ok = resultData.valid;
41
- self.ValidationResult.call(self, resultData, response.status);
42
- if(ok) {
 
 
 
 
 
 
 
 
 
43
  checkout.setLoadWaiting('payment');
44
- var request = new Ajax.Request(
45
- payment.saveUrl,
46
- {
47
- method:'post',
48
  onComplete: payment.onComplete,
49
  onSuccess: payment.onSave,
50
- onFailure: checkout.ajaxFailure.bind(checkout),
51
- parameters: jQuery.param({payment:{method:'optile'}})
52
- }
53
- );
54
- };
55
- }, "json");
56
-
57
- return ok;
58
- };
59
-
60
-
61
- ValidationController.prototype.ValidationResult = function(resultData, resultStatus, xhr) {
62
- var network = this.widget.find("input[name=\"optile-selected-network\"]:checked").val();
63
- var form = this.FindFormByFormId(network);
64
- form.BindMessages(resultData.messages);
65
- };
66
-
67
- if(payment) {
68
-
69
- /**
70
- * overrides opcheckout.js payment.save() so it doesn't call magento for
71
- * validation, instead calls optile javascript api from ValidationController
72
- */
73
- payment.save = payment.save.wrap(function(parentMethod) {
74
- if(payment.currentMethod == 'optile') {
75
- if (checkout.loadWaiting!=false) return;
76
- var validator = new Validation(this.form);
77
- if (validator.validate()) {
78
- self.controller.Validate();
79
- }
80
- } else {
81
- parentMethod();
82
- }
83
-
84
- });
85
-
86
- payment.validate = payment.validate.wrap(function(parentMethod) {
87
- if(payment.currentMethod == 'optile') {
88
- self.controller.Validate(null, parentMethod);
89
- return false;
90
- } else {
91
- return parentMethod();
92
- }
93
- });
94
-
95
- }
96
-
97
- if(Review) {
98
-
99
- Review.prototype.nextStep = Review.prototype.nextStep.wrap(function(parentMethod, transport) {
100
- if(payment.currentMethod == 'optile') {
101
- console.log("onSave");
102
- } else {
103
- parentMethod(transport);
104
- }
105
- });
106
-
107
- /**
108
- * Overrides Review.save() for optile. All <input> tags for payment
109
- * methods in one-page checkout are set in payment[] array. optile renders
110
- * its html forms differently so we have to make sure proper data is
111
- * collected before we call charge request
112
- *
113
- */
114
- Review.prototype.save = Review.prototype.save.wrap(function(parentMethod){
115
- if(payment.currentMethod == 'optile') {
116
- if (checkout.loadWaiting!=false) return;
117
- checkout.setLoadWaiting('review');
118
-
119
- var params;
120
- var network = jQuery('#payment_form_optile').find("input[name=\"optile-selected-network\"]:checked").val();
121
- var data = {
122
- };
123
-
124
- var block = network + '-network';
125
- element = $(block);
126
- if (element) {
127
- element.select('input', 'select', 'textarea', 'button').each(function(field) {
128
- if(field.name == 'optile-selected-network') return;
129
- if(field.name == 'operation') return;
130
- if(field.name == 'optile-list-self') return;
131
- data[field.name] = field.value;
132
- });
133
- }
134
-
135
- params = jQuery.param(data);
136
-
137
- var operationUrl = jQuery('#' + network + '-operation').val();
138
- var listRequestSelfLink = jQuery('#optile-list-self').val();
139
- var self = this;
140
-
141
- jQuery.post(operationUrl, params, function(response) {
142
- var paymentResponse = new OptilePaymentResponseFactory().newOptilePaymentResponse(response);
143
- var handler;
144
- switch(paymentResponse.interaction.code) {
145
- case OptileInteractionCode.PROCEED:
146
- handler = new OptileInteractionCodeHandlerPROCEED(paymentResponse, listRequestSelfLink);
147
- break;
148
- case OptileInteractionCode.RETRY:
149
- handler = new OptileInteractionCodeHandlerRETRY(paymentResponse, listRequestSelfLink);
150
- break;
151
- case OptileInteractionCode.TRY_OTHER_ACCOUNT:
152
- handler = new OptileInteractionCodeHandlerTRY_OTHER_ACCOUNT(paymentResponse, listRequestSelfLink);
153
- break;
154
- case OptileInteractionCode.TRY_OTHER_NETWORK:
155
- handler = new OptileInteractionCodeHandlerTRY_OTHER_NETWORK(paymentResponse, listRequestSelfLink);
156
- break;
157
- case OptileInteractionCode.ABORT:
158
- handler = new OptileInteractionCodeHandlerABORT(paymentResponse, listRequestSelfLink);
159
- break;
160
- default:
161
- console.log("ERROR! can't find interaction code handler");
162
- break;
163
- }
164
- if(handler) {
165
- handler.handle(self);
166
- }
167
-
168
- });
169
-
170
- } else {
171
- parentMethod();
172
- }
173
- });
174
- }
175
-
176
- if(ShippingMethod) {
177
- /**
178
- * Overrides shippingMethod.save() call for the case where we want to refresh
179
- * payment method list without sending another LIST request to optile
180
- * (required for TRY_OTHER_ACCOUNT, TRY_OTHER_NETWORK response codes).
181
- * If there's existing list request, it will reuse it.
182
- */
183
- ShippingMethod.prototype.save = ShippingMethod.prototype.save.wrap(function(parentMethod, listRequestSelfLink) {
184
- if(listRequestSelfLink) {
185
- if (checkout.loadWaiting!=false) return;
186
- if (this.validate()) {
187
- checkout.setLoadWaiting('shipping-method');
188
- var request = new Ajax.Request(
189
- this.saveUrl,
190
- {
191
- method:'post',
192
- onComplete: this.onComplete,
193
- onSuccess: this.onSave,
194
- onFailure: checkout.ajaxFailure.bind(checkout),
195
- parameters: Form.serialize(this.form) + '&listRequestSelfLink=' + encodeURIComponent(listRequestSelfLink)
196
- }
197
- );
198
- }
199
- } else {
200
- parentMethod();
201
- }
202
- });
203
- }
204
-
205
- var OptileInteractionCodeHandler = Class.create();
206
- OptileInteractionCodeHandler.prototype = {
207
- initialize: function(paymentResponse, listRequestSelfLink) {
208
- this.paymentResponse = paymentResponse;
209
- this.listRequestSelfLink = listRequestSelfLink;
210
- }
211
- }
212
-
213
- /**
214
- * Handles PROCEED optile payment response
215
- */
216
- var OptileInteractionCodeHandlerPROCEED = Class.create(OptileInteractionCodeHandler, {
217
- handle: function(context) {
218
-
219
- var request = new Ajax.Request(
220
- context.saveUrl,
221
- {
222
- method:'post',
223
- parameters: jQuery.param({payment:{method:'optile'}}),
224
- onComplete: context.onComplete,
225
- onSuccess: this.redirect.bindAsEventListener(this),
226
- onFailure: checkout.ajaxFailure.bind(checkout)
227
- }
228
- );
229
-
230
- },
231
-
232
- redirect: function(transport) {
233
- if (transport && transport.responseText) {
234
- try{
235
- response = eval('(' + transport.responseText + ')');
236
- }
237
- catch (e) {
238
- response = {};
239
- }
240
- if (response.redirect) {
241
- location.href = response.redirect;
242
- return;
243
- }
244
- if (response.success) {
245
- var redirect = this.paymentResponse.redirect;
246
- switch(redirect.method) {
247
- case "GET":
248
- window.location.href = redirect.url;
249
- break;
250
- case "POST":
251
- // hacky way to do a POST redirect in javascript from stackoverflow
252
- var form = jQuery('<form action="' + redirect.url + '" method="post" style="display:none;">' +
253
- // '<input type="text" name="api_url" value="' + Return_URL + '" />' +
254
- '</form>');
255
- jQuery('body').append(form);
256
- form.submit();
257
- break;
258
- }
259
- }
260
- else{
261
- var msg = response.error_messages;
262
- if (typeof(msg)=='object') {
263
- msg = msg.join("\n");
264
- }
265
- if (msg) {
266
- alert(msg);
267
- }
268
- }
269
-
270
- if (response.update_section) {
271
- $('checkout-'+response.update_section.name+'-load').update(response.update_section.html);
272
- }
273
-
274
- if (response.goto_section) {
275
- checkout.gotoSection(response.goto_section);
276
- }
277
- }
278
-
279
- }
280
- });
281
-
282
- var OptileErrorHandler = {
283
- error: function(msg) {
284
- alert(msg);
285
- }
286
- }
287
-
288
- /**
289
- * Handles RETRY response code
290
- */
291
- var OptileInteractionCodeHandlerRETRY = Class.create(OptileInteractionCodeHandler, {
292
- handle: function(context) {
293
-
294
- OptileErrorHandler.error(Translator.translate("Error processing payment. Please retry. (Reason: " +
295
- this.paymentResponse.interaction.reason + ")"));
296
-
297
- // simulate shipping method save so it reloads payment section
298
- checkout.setLoadWaiting(false);
299
- shippingMethod.save(this.listRequestSelfLink);
300
- }
301
- });
302
-
303
- /**
304
- * Handles TRY_OTHER_ACCOUNT response code
305
- */
306
- var OptileInteractionCodeHandlerTRY_OTHER_ACCOUNT = Class.create(OptileInteractionCodeHandler, {
307
- handle: function(context) {
308
-
309
- OptileErrorHandler.error(Translator.translate("Error processing payment. Please retry with different network. (Reason: " +
310
- this.paymentResponse.interaction.reason + ")"));
311
-
312
- // simulate shipping method save so it reloads payment section
313
- checkout.setLoadWaiting(false);
314
- shippingMethod.save(this.listRequestSelfLink);
315
- }
316
- });
317
-
318
- /**
319
- * Handles TYR_OTHER_NETWORK response code - same as TRY_OTHER_ACCOUNT
320
- */
321
- var OptileInteractionCodeHandlerTRY_OTHER_NETWORK = Class.create(OptileInteractionCodeHandlerTRY_OTHER_ACCOUNT);
322
-
323
- var OptileInteractionCodeHandlerABORT = Class.create(OptileInteractionCodeHandler, {
324
- handle: function(context) {
325
- var redirect = this.paymentResponse.redirect;
326
- switch(redirect.method) {
327
- case "GET":
328
- window.location.href = redirect.url;
329
- break;
330
- case "POST":
331
- // hacky way to do a POST redirect in javascript from stackoverflow
332
- var form = jQuery('<form action="' + redirect.url + '" method="post" style="display:none;">' +
333
- // '<input type="text" name="api_url" value="' + Return_URL + '" />' +
334
- '</form>');
335
- jQuery('body').append(form);
336
- form.submit();
337
- break;
338
- }
339
-
340
- }
341
- });
342
-
343
- var OptilePaymentResponseFactory = Class.create();
344
- OptilePaymentResponseFactory.prototype = {
345
- initialize: function() { },
346
- newOptilePaymentResponse: function(responseData) {
347
- return new OptilePaymentResponse(responseData.links, responseData.info, responseData.interaction, responseData.redirect);
348
- }
349
- }
350
-
351
- var OptilePaymentResponse = Class.create();
352
- OptilePaymentResponse.prototype = {
353
- initialize: function(links, info, interaction, redirect) {
354
- this.links = links;
355
- this.info = info;
356
- this.interaction = interaction;
357
- this.redirect = redirect;
358
- }
359
- }
360
-
361
- var OptileInteractionCode = {
362
- PROCEED: 'PROCEED',
363
- RETRY: 'RETRY',
364
- TRY_OTHER_ACCOUNT: 'TRY_OTHER_ACCOUNT',
365
- TRY_OTHER_NETWORK: 'TRY_OTHER_NETWORK',
366
- ABORT: 'ABORT'
367
- };
368
-
369
- window.OptileForm = Class.create();
370
- OptileForm.prototype = {
371
- beforeInitFunc:$H({}),
372
- afterInitFunc:$H({}),
373
- beforeValidateFunc:$H({}),
374
- afterValidateFunc:$H({}),
375
-
376
- initialize: function(form) {
377
- this.form = form;
378
- },
379
-
380
- init : function () {
381
- var elements = Form.getElements(this.form);
382
- var method = null;
383
- for (var i=0; i<elements.length; i++) {
384
- if (elements[i].name=='optile-selected-network') {
385
- if (elements[i].checked) {
386
- method = elements[i].value;
387
- }
388
- }
389
- }
390
- if (method) this.switchMethod(method);
391
- },
392
-
393
- switchMethod: function(method){
394
- if (this.currentMethod && $(this.currentMethod + '-network')) {
395
- this.changeVisible(this.currentMethod, true);
396
- $(this.currentMethod + '-network').fire('optile-network:switched-off', {network_code : this.currentMethod});
397
- }
398
- if ($(method + '-network')){
399
- this.changeVisible(method, false);
400
- $(method + '-network').fire('optile-network:switched', {network_code : method});
401
- } else {
402
- //Event fix for payment methods without form like "Check / Money order"
403
- document.body.fire('optile-network:switched', {network_code : method});
404
- }
405
- if (method) {
406
- this.lastUsedMethod = method;
407
- }
408
- this.currentMethod = method;
409
- },
410
-
411
- changeVisible: function(method, mode) {
412
- var block = method + '-network';
413
- [block + '_before', block, block + '_after'].each(function(el) {
414
- element = $(el);
415
- if (element) {
416
- element.style.display = (mode) ? 'none' : '';
417
- element.select('input', 'select', 'textarea', 'button').each(function(field) {
418
- field.disabled = mode;
419
- });
420
- }
421
- });
422
- },
423
-
424
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
425
  });
426
 
427
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  /**
2
+ * Copyright optile GmbH 2013
3
+ * Licensed under the Software License Agreement in effect between optile and
4
+ * Licensee/user (the "License"); you may not use this file except in compliance
5
+ * with the License. You may obtain a copy of the License at
6
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
7
+ * copy has been provided to you for your records. Unless required by applicable
8
+ * law or agreed to in writing or otherwise stipulated in the License, software
9
+ * distributed under the License is distributed on an "as is” basis without
10
+ * warranties or conditions of any kind, either express or implied. See the
11
+ * License for the specific language governing permissions and limitations under
12
+ * the License.
 
 
 
13
  *
14
  * @author i-Ways <dev@i-ways.hr>
15
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
16
+ * @license http://www.optile.de/software-license-agreement
17
  */
18
+ //// Disable console.log
19
+ //window['console']['log'] = function() {
20
+ //};
21
 
22
  jQuery(function() {
23
+
24
+ Checkout.prototype.setLoadWaiting = function(step, keepDisabled) {
25
+ return false;
26
+ }
27
+
28
+ ValidationController.prototype.Validate = function(event) {
29
+ var self = this;
30
+ var network = this.widget.find("input[name=\"optile-selected-network\"]:checked").val();
31
+ var form = this.FindFormByFormId(network);
32
+ var data = form.ToJSON();
33
+ var url = form.validationUrl;
34
+ var ok = false;
35
+
36
+ //T: Converted this to .ajax(), in order to utilize async:false option
37
+ // This was done in order to be able to return success true/false
38
+ jQuery.ajax({
39
+ type: 'POST',
40
+ url: url,
41
+ data: JSON.stringify(data),
42
+ dataType: 'json',
43
+ async: false,
44
+ success: function(resultData, resultStatus, xhr) {
45
+ ok = resultData.valid;
46
+ console.log("resultData.valid: " + ok);
47
+ if (typeof (response) == "undefined") {
48
+ response = {};
49
+ }
50
+ self.ValidationResult.call(self, resultData, true);
51
+ if (ok) {
52
  checkout.setLoadWaiting('payment');
53
+ var request = new Ajax.Request(
54
+ payment.saveUrl,
55
+ {
56
+ method: 'post',
57
  onComplete: payment.onComplete,
58
  onSuccess: payment.onSave,
59
+ onFailure: checkout.ajaxFailure.bind(checkout),
60
+ parameters: jQuery.param({
61
+ payment: {
62
+ method: 'optile',
63
+ network: form.networkCode
64
+ }
65
+ })
66
+ }
67
+ );
68
+ }
69
+ ;
70
+ }
71
+
72
+ });
73
+
74
+
75
+ // jQuery.post(url, data, function... , "json");
76
+ return ok;
77
+ };
78
+
79
+ if (payment) {
80
+
81
+ /**
82
+ * overrides opcheckout.js payment.save() so it doesn't call magento for
83
+ * validation, instead calls optile javascript api from ValidationController
84
+ */
85
+ payment.save = payment.save.wrap(function(parentMethod) {
86
+ if (payment.currentMethod == 'optile') {
87
+ if (checkout.loadWaiting != false)
88
+ return;
89
+
90
+ var validator = new Validation(this.form);
91
+ if (validator.validate()) {
92
+ var selectedNetworkWidget = self.controller.widget.find("input[name=\"optile-selected-network\"]:checked");
93
+ if (selectedNetworkWidget.length === 0) {
94
+ OptileErrorHandler.error(Translator.translate('Error, no payment network is selected'));
95
+ return;
96
+ }
97
+
98
+ self.controller.Validate();
99
+ }
100
+ } else {
101
+ parentMethod();
102
+ }
103
+
104
+ });
105
+
106
+ /**
107
+ * this method is overriden from the default so that optile payment method
108
+ * section doesn't get disabled/hidden when we select other Magento payment methods
109
+ */
110
+ payment.switchMethod = payment.switchMethod.wrap(function(parentMethod, method) {
111
+ console.log("Firing payment.switchMethod. Selected method: " + method);
112
+
113
+ if(typeof(self.controller) == "undefined") {
114
+ return;
115
+ }
116
+ if (this.currentMethod && $('payment_form_' + this.currentMethod)) {
117
+ if (this.currentMethod === 'optile' && method !== 'optile') {
118
+ // unselects and hides the inner optile payment method if we're switching
119
+ // to other Magento payment method
120
+ var selectedOptileNetworkWidget = self.controller.widget.find("input[name=\"optile-selected-network\"]:checked");
121
+ if (selectedOptileNetworkWidget) {
122
+ selectedOptileNetworkWidget.prop('checked', false);
123
+ window.optileForm.changeVisible(window.optileForm.currentMethod, true);
124
+ }
125
+ } else {
126
+ this.changeVisible(this.currentMethod, true);
127
+ $('payment_form_' + this.currentMethod).fire('payment-method:switched-off', {method_code: this.currentMethod});
128
+ }
129
+ }
130
+ if ($('payment_form_' + method)) {
131
+ this.changeVisible(method, false);
132
+ $('payment_form_' + method).fire('payment-method:switched', {method_code: method});
133
+ } else {
134
+
135
+ //Event fix for payment methods without form like "Check / Money order"
136
+ document.body.fire('payment-method:switched', {method_code: method});
137
+ }
138
+ if (method) {
139
+ this.lastUsedMethod = method;
140
+ }
141
+ this.currentMethod = method;
142
+ });
143
+
144
+ console.log("payment.validate wrap");
145
+ payment.validate = payment.validate.wrap(function(parentMethod) {
146
+ console.log("payment.validate");
147
+ if (payment.currentMethod == 'optile') {
148
+ var isValid = self.controller.Validate(null, parentMethod);
149
+ console.log("isValid ", isValid);
150
+ // return false;
151
+ } else {
152
+ return parentMethod();
153
+ }
154
+ });
155
+
156
+ }
157
+
158
+ if (Review) {
159
+
160
+ Review.prototype.nextStep = Review.prototype.nextStep.wrap(function(parentMethod, transport) {
161
+ console.log("Review.prototype.nextStep");
162
+ if (payment.currentMethod == 'optile') {
163
+ console.log("onSave");
164
+ } else {
165
+ parentMethod(transport);
166
+ }
167
+ });
168
+
169
+ /**
170
+ * Overrides Review.save() for optile. All <input> tags for payment
171
+ * methods in one-page checkout are set in payment[] array. optile renders
172
+ * its html forms differently so we have to make sure proper data is
173
+ * collected before we call charge request
174
+ *
175
+ */
176
+ Review.prototype.save = Review.prototype.save.wrap(function(parentMethod) {
177
+ if (payment.currentMethod == 'optile') {
178
+ if (checkout.loadWaiting != false)
179
+ return;
180
+ checkout.setLoadWaiting('review');
181
+
182
+ // Handle terms and conditions
183
+ agreements = true;
184
+ jQuery(".checkout-agreements .checkbox").each(function(index){
185
+ if(!jQuery(this).is(":checked")){
186
+ agreements = false;
187
+ };
188
+ });
189
+ console.log("checkout agreements:");
190
+ console.log(agreements);
191
+ if(agreements == false){
192
+ if(typeof(terms_and_conditions_error_text) === 'undefined'){
193
+ terms_and_conditions_error_text = "Please agree to all the terms and conditions before placing the order."
194
+ }
195
+ alert(terms_and_conditions_error_text);
196
+ review.resetLoadWaiting();
197
+ return;
198
+ }
199
+
200
+ var params;
201
+ var network = jQuery('#payment_form_optile').find("input[name=\"optile-selected-network\"]:checked").val();
202
+ var data = {
203
+ };
204
+
205
+ var block = network + '-network';
206
+ element = $(block);
207
+ if (element) {
208
+ element.select('input', 'select', 'textarea', 'button').each(function(field) {
209
+ if (field.name == 'optile-selected-network')
210
+ return;
211
+ if (field.name == 'operation')
212
+ return;
213
+ if (field.name == 'optile-list-self')
214
+ return;
215
+ data[field.name] = field.value;
216
+ });
217
+ }
218
+
219
+ params = jQuery.param(data);
220
+
221
+ var operationUrl = jQuery('#' + network + '-operation').val();
222
+ var listRequestSelfLink = jQuery('#optile-list-self').val();
223
+ var self = this;
224
+
225
+ // F: converted to .ajax() in order to utilize async:false
226
+ // so we can handle possible failure of charge request.
227
+ jQuery.ajax({
228
+ type: 'POST',
229
+ url: operationUrl,
230
+ data: JSON.stringify(data),
231
+ dataType: 'json',
232
+ async: false,
233
+ success: function(resultData, resultStatus, xhr) {
234
+ var paymentResponse = new OptilePaymentResponseFactory().newOptilePaymentResponse(resultData);
235
+ var handler;
236
+ switch (paymentResponse.interaction.code) {
237
+ case OptileInteractionCode.PROCEED:
238
+ handler = new OptileInteractionCodeHandlerPROCEED(paymentResponse, listRequestSelfLink);
239
+ break;
240
+ case OptileInteractionCode.RETRY:
241
+ handler = new OptileInteractionCodeHandlerRETRY(paymentResponse, listRequestSelfLink);
242
+ break;
243
+ case OptileInteractionCode.TRY_OTHER_ACCOUNT:
244
+ handler = new OptileInteractionCodeHandlerTRY_OTHER_ACCOUNT(paymentResponse, listRequestSelfLink);
245
+ break;
246
+ case OptileInteractionCode.TRY_OTHER_NETWORK:
247
+ handler = new OptileInteractionCodeHandlerTRY_OTHER_NETWORK(paymentResponse, listRequestSelfLink);
248
+ break;
249
+ case OptileInteractionCode.ABORT:
250
+ handler = new OptileInteractionCodeHandlerABORT(paymentResponse, listRequestSelfLink);
251
+ break;
252
+ default:
253
+ console.log("ERROR! Can't find interaction code handler");
254
+ break;
255
+ }
256
+ if (handler) {
257
+ handler.handle(self);
258
+ }
259
+
260
+ if (paymentResponse.interaction.code != OptileInteractionCode.PROCEED) {
261
+ self.optile_error = 1;
262
+ }
263
+ }
264
+ });
265
+
266
+ } else {
267
+ console.log("review.prototype.save: doing parent method");
268
+ parentMethod();
269
+ }
270
+ });
271
+ }
272
+
273
+ if (ShippingMethod) {
274
+ /**
275
+ * Overrides shippingMethod.save() call for the case where we want to refresh
276
+ * payment method list without sending another LIST request to optile
277
+ * (required for TRY_OTHER_ACCOUNT, TRY_OTHER_NETWORK response codes).
278
+ * If there's existing list request, it will reuse it.
279
+ */
280
+ ShippingMethod.prototype.save = ShippingMethod.prototype.save.wrap(function(parentMethod, listRequestSelfLink) {
281
+ if (listRequestSelfLink) {
282
+ if (checkout.loadWaiting != false)
283
+ return;
284
+ if (this.validate()) {
285
+ checkout.setLoadWaiting('shipping-method');
286
+ var request = new Ajax.Request(
287
+ this.saveUrl,
288
+ {
289
+ method: 'post',
290
+ onComplete: this.onComplete,
291
+ onSuccess: this.onSave,
292
+ onFailure: checkout.ajaxFailure.bind(checkout),
293
+ parameters: Form.serialize(this.form) + '&listRequestSelfLink=' + encodeURIComponent(listRequestSelfLink)
294
+ }
295
+ );
296
+ }
297
+ } else {
298
+ parentMethod();
299
+ }
300
+ });
301
+ }
302
+
303
+ var OptileInteractionCodeHandler = Class.create();
304
+ OptileInteractionCodeHandler.prototype = {
305
+ initialize: function(paymentResponse, listRequestSelfLink) {
306
+ this.paymentResponse = paymentResponse;
307
+ this.listRequestSelfLink = listRequestSelfLink;
308
+ }
309
+ }
310
+
311
+ /**
312
+ * Handles PROCEED optile payment response
313
+ */
314
+ var OptileInteractionCodeHandlerPROCEED = Class.create(OptileInteractionCodeHandler, {
315
+ handle: function(context) {
316
+ console.log("PROCEED handler: context:");
317
+ console.log(context);
318
+ console.log("PROCEED handler: doing AJAX to:" + context.saveUrl);
319
+ var network = jQuery('#payment_form_optile').find("input[name=\"optile-selected-network\"]:checked").val();
320
+ var form = self.controller.FindFormByFormId(network);
321
+ var params = "";
322
+
323
+ if (review.agreementsForm) {
324
+ console.log("Agreements form detected, serializing it.")
325
+ params += '&'+Form.serialize(review.agreementsForm);
326
+ }
327
+
328
+ params += '&'+jQuery.param({
329
+ payment: {
330
+ method: 'optile',
331
+ network: form.networkCode
332
+ }});
333
+
334
+
335
+ var request = new Ajax.Request(
336
+ context.saveUrl,
337
+ {
338
+ method: 'post',
339
+ parameters: params,
340
+ onComplete: context.onComplete,
341
+ onSuccess: this.redirect.bindAsEventListener(this),
342
+ onFailure: checkout.ajaxFailure.bind(checkout)
343
+ }
344
+ );
345
+
346
+ },
347
+ redirect: function(transport) {
348
+ console.log("PROCEED handler: redirect");
349
+ if (transport && transport.responseText) {
350
+ console.log("transport:");
351
+ console.log(transport);
352
+ try {
353
+ response = eval('(' + transport.responseText + ')');
354
+ }
355
+ catch (e) {
356
+ response = {};
357
+ }
358
+ console.log("response");
359
+ console.log(response);
360
+ if (response.redirect) {
361
+ location.href = response.redirect;
362
+ return;
363
+ }
364
+ if (response.success) {
365
+ var redirect = this.paymentResponse.redirect;
366
+ console.log("PROCEED handler: redirect to: " + redirect.url);
367
+ switch (redirect.method) {
368
+ case "GET":
369
+ window.location.href = redirect.url;
370
+ break;
371
+ case "POST":
372
+ // hacky way to do a POST redirect in javascript from stackoverflow
373
+ var form = jQuery('<form action="' + redirect.url + '" method="post" style="display:none;">' +
374
+ // '<input type="text" name="api_url" value="' + Return_URL + '" />' +
375
+ '</form>');
376
+ jQuery('body').append(form);
377
+ form.submit();
378
+ break;
379
+ }
380
+ }
381
+ else {
382
+ var msg = response.error_messages;
383
+ if (typeof (msg) == 'object') {
384
+ msg = msg.join("\n");
385
+ }
386
+ if (msg) {
387
+ alert('Error: ' + msg);
388
+ }
389
+ }
390
+
391
+ if (response.update_section) {
392
+ $('checkout-' + response.update_section.name + '-load').update(response.update_section.html);
393
+ }
394
+
395
+ if (response.goto_section) {
396
+ checkout.gotoSection(response.goto_section);
397
+ }
398
+ }
399
+
400
+ }
401
+ });
402
+
403
+ var OptileErrorHandler = {
404
+ error: function(msg) {
405
+ if (msg) {
406
+ alert('Error: ' + msg);
407
+ }
408
+ }
409
+ }
410
+
411
+ /**
412
+ * Handles RETRY response code
413
+ */
414
+ var OptileInteractionCodeHandlerRETRY = Class.create(OptileInteractionCodeHandler, {
415
+ handle: function(context) {
416
+
417
+ OptileErrorHandler.error(this.paymentResponse.resultInfo);
418
+
419
+ // save data before reloading payment section
420
+ saveOptileData();
421
+
422
+ // simulate shipping method save so it reloads payment section
423
+ checkout.setLoadWaiting(false);
424
+ shippingMethod.save(this.listRequestSelfLink);
425
+ }
426
+ });
427
+
428
+ /**
429
+ * Handles TRY_OTHER_ACCOUNT response code
430
+ */
431
+ var OptileInteractionCodeHandlerTRY_OTHER_ACCOUNT = Class.create(OptileInteractionCodeHandler, {
432
+ handle: function(context) {
433
+
434
+ OptileErrorHandler.error(this.paymentResponse.resultInfo);
435
+
436
+ // save data before reloading payment section
437
+ saveOptileData();
438
+
439
+ // simulate shipping method save so it reloads payment section
440
+ checkout.setLoadWaiting(false);
441
+ shippingMethod.save(this.listRequestSelfLink);
442
+ }
443
+ });
444
+
445
+ /**
446
+ * Handles TYR_OTHER_NETWORK response code - same as TRY_OTHER_ACCOUNT
447
+ */
448
+ var OptileInteractionCodeHandlerTRY_OTHER_NETWORK = Class.create(OptileInteractionCodeHandler, {
449
+ handle: function(context) {
450
+
451
+ OptileErrorHandler.error(this.paymentResponse.resultInfo);
452
+
453
+ // simulate shipping method save so it reloads payment section
454
+ checkout.setLoadWaiting(false);
455
+ shippingMethod.save(this.listRequestSelfLink);
456
+ }
457
+ });
458
+
459
+ var OptileInteractionCodeHandlerABORT = Class.create(OptileInteractionCodeHandler, {
460
+ handle: function(context) {
461
+ checkout.setLoadWaiting(false);
462
+
463
+ OptileErrorHandler.error(this.paymentResponse.resultInfo);
464
+ window.location.href = window.cartPageUrl;
465
+ // shippingMethod.save();
466
+ }
467
+ });
468
+
469
+ var OptilePaymentResponseFactory = Class.create();
470
+ OptilePaymentResponseFactory.prototype = {
471
+ initialize: function() {
472
+ },
473
+ newOptilePaymentResponse: function(responseData) {
474
+ return new OptilePaymentResponse(responseData.links, responseData.info, responseData.interaction, responseData.redirect, responseData.resultInfo);
475
+ }
476
+ }
477
+
478
+ var OptilePaymentResponse = Class.create();
479
+ OptilePaymentResponse.prototype = {
480
+ initialize: function(links, info, interaction, redirect, resultInfo) {
481
+ this.links = links;
482
+ this.info = info;
483
+ this.interaction = interaction;
484
+ this.redirect = redirect;
485
+ this.resultInfo = resultInfo;
486
+ }
487
+ }
488
+
489
+ var OptileInteractionCode = {
490
+ PROCEED: 'PROCEED',
491
+ RETRY: 'RETRY',
492
+ TRY_OTHER_ACCOUNT: 'TRY_OTHER_ACCOUNT',
493
+ TRY_OTHER_NETWORK: 'TRY_OTHER_NETWORK',
494
+ ABORT: 'ABORT'
495
+ };
496
+
497
+ window.OptileForm = Class.create();
498
+ OptileForm.prototype = {
499
+ beforeInitFunc: $H({}),
500
+ afterInitFunc: $H({}),
501
+ beforeValidateFunc: $H({}),
502
+ afterValidateFunc: $H({}),
503
+ initialize: function(form) {
504
+ this.form = form;
505
+ },
506
+ init: function() {
507
+ var elements = Form.getElements(this.form);
508
+ var method = null;
509
+ for (var i = 0; i < elements.length; i++) {
510
+ if (elements[i].name == 'optile-selected-network') {
511
+ if (elements[i].checked) {
512
+ method = elements[i].value;
513
+ }
514
+ }
515
+ }
516
+ if (method)
517
+ this.switchMethod(method);
518
+ },
519
+ // we hide the global 'Optile' payment method label so we're going
520
+ // to select it by javascript when we select any Optile payment form
521
+ switchMethod: function(method) {
522
+ jQuery('#p_method_optile').prop('checked', true);
523
+ payment.switchMethod('optile');
524
+
525
+ if (this.currentMethod && $(this.currentMethod + '-network')) {
526
+ this.changeVisible(this.currentMethod, true);
527
+ $(this.currentMethod + '-network').fire('optile-network:switched-off', {network_code: this.currentMethod});
528
+ }
529
+ if ($(method + '-network')) {
530
+ this.changeVisible(method, false);
531
+ $(method + '-network').fire('optile-network:switched', {network_code: method});
532
+ } else {
533
+ //Event fix for payment methods without form like "Check / Money order"
534
+ document.body.fire('optile-network:switched', {network_code: method});
535
+ }
536
+ if (method) {
537
+ this.lastUsedMethod = method;
538
+ }
539
+ this.currentMethod = method;
540
+ },
541
+ changeVisible: function(method, mode) {
542
+ var block = method + '-network';
543
+ [block + '_before', block, block + '_after'].each(function(el) {
544
+ element = $(el);
545
+ if (element) {
546
+ element.style.display = (mode) ? 'none' : '';
547
+ element.select('input', 'select', 'textarea', 'button').each(function(field) {
548
+ field.disabled = mode;
549
+ });
550
+ }
551
+ });
552
+ },
553
+ }
554
  });
555
 
556
 
557
+ function saveOptileData() {
558
+
559
+ if (typeof (self.controller) == "undefined") {
560
+ return;
561
+ }
562
+ console.log("Saving Optile data");
563
+ var network = jQuery('#payment_form_optile').find("input[name=\"optile-selected-network\"]:checked").val();
564
+ var form = self.controller.FindFormByFormId(network);
565
+ if (form) {
566
+ var data = form.ToJSON();
567
+ if (data.hasOwnProperty('verificationCode')) {
568
+ delete data['verificationCode'];
569
+ }
570
+
571
+ window.savedOptileNetworkCode = network;
572
+ window.savedOptileData = data;
573
+ }
574
+
575
+ }
js/optile/jquery.noconflict.js CHANGED
@@ -1,22 +1,19 @@
1
  /**
2
- * This file is part of the Optile Payment Connector extension.
3
- *
4
- * Optile Payment Connector is free software: you can redistribute it and/or
5
- * modify it under the terms of the GNU General Public License as published
6
- * by the Free Software Foundation, either version 3 of the License, or
7
- * (at your option) any later version.
8
- *
9
- * Optile Payment Connector is distributed in the hope that it will be useful,
10
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
- * GNU General Public License for more details.
13
- *
14
- * You should have received a copy of the GNU General Public License along with
15
- * Optile Payment Connector. If not, see <http://www.gnu.org/licenses/>.
16
  *
17
  * @author i-Ways <dev@i-ways.hr>
18
- * @copyright Copyright (c) 2013 Optile. (http://www.optile.de)
19
- * @license http://www.gnu.org/licenses/gpl.txt
20
  */
21
 
22
  jQuery.noConflict();
1
  /**
2
+ * Copyright optile GmbH 2013
3
+ * Licensed under the Software License Agreement in effect between optile and
4
+ * Licensee/user (the "License"); you may not use this file except in compliance
5
+ * with the License. You may obtain a copy of the License at
6
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
7
+ * copy has been provided to you for your records. Unless required by applicable
8
+ * law or agreed to in writing or otherwise stipulated in the License, software
9
+ * distributed under the License is distributed on an "as is” basis without
10
+ * warranties or conditions of any kind, either express or implied. See the
11
+ * License for the specific language governing permissions and limitations under
12
+ * the License.
 
 
 
13
  *
14
  * @author i-Ways <dev@i-ways.hr>
15
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
16
+ * @license http://www.optile.de/software-license-agreement
17
  */
18
 
19
  jQuery.noConflict();
js/optile/optilevalidation.js CHANGED
@@ -1,27 +1,25 @@
1
  /**
2
- * This file is part of the Optile Payment Connector extension.
3
- *
4
- * Optile Payment Connector is free software: you can redistribute it and/or
5
- * modify it under the terms of the GNU General Public License as published
6
- * by the Free Software Foundation, either version 3 of the License, or
7
- * (at your option) any later version.
8
- *
9
- * Optile Payment Connector is distributed in the hope that it will be useful,
10
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
- * GNU General Public License for more details.
13
- *
14
- * You should have received a copy of the GNU General Public License along with
15
- * Optile Payment Connector. If not, see <http://www.gnu.org/licenses/>.
16
  *
17
  * @author i-Ways <dev@i-ways.hr>
18
- * @copyright Copyright (c) 2013 Optile. (http://www.optile.de)
19
- * @license http://www.gnu.org/licenses/gpl.txt
20
  */
21
-
22
- function ValidationForm(formId, validationUrl) {
23
  this.formId = formId;
24
  this.validationUrl = validationUrl;
 
 
25
  this.widget = null;
26
  this.holderName = null;
27
  this.holderNameMessage = null;
@@ -53,7 +51,7 @@ function ValidationForm(formId, validationUrl) {
53
  this.passwordMessage = null;
54
  }
55
 
56
- ValidationForm.prototype.Build = function(parentWidget) {
57
  this.holderName = parentWidget.find("#" + this.formId + "-holderName").first();
58
  this.holderNameMessage = parentWidget.find("#" + this.formId + "-holderName-message").first();
59
  this.number = parentWidget.find("#" + this.formId + "-number").first();
@@ -84,7 +82,7 @@ ValidationForm.prototype.Build = function(parentWidget) {
84
  this.passwordMessage = parentWidget.find("#" + this.formId + "-password-message").first();
85
  };
86
 
87
- ValidationForm.prototype.ToJSON = function() {
88
  var data = {};
89
  if(this.holderName.length > 0) data.holderName = this.holderName.val();
90
  if(this.number.length > 0) data.number = this.number.val();
@@ -99,35 +97,68 @@ ValidationForm.prototype.ToJSON = function() {
99
  if(this.country.length > 0) data.country = this.country.val();
100
  if(this.city.length > 0) data.city = this.city.val();
101
  if(this.login.length > 0) data.login = this.login.val();
102
- if(this.password.length > 0) data.password = this.password.val();
103
 
104
  return data;
105
  };
106
 
107
- ValidationForm.prototype.BindMessages = function(messages) {
 
 
 
 
 
 
 
 
 
 
 
 
108
  for(item in messages) {
109
- if(messages[item] === null) continue;
110
-
111
  if(this.hasOwnProperty(item) && this.hasOwnProperty(item + "Message")) {
112
- var widget = this[item + "Message"];
113
-
114
- widget.removeClass('optile-error-msg');
115
-
116
- switch(messages[item].type) {
117
- case 'ERROR':
118
- widget.addClass('optile-error-msg');
119
- break;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120
  }
121
-
122
- widget.html(messages[item].message);
123
  }
124
  }
125
  };
126
 
127
- function ValidationController(widget, forms, submit) {
 
 
 
 
 
 
128
  this.widget = widget;
129
  this.forms = forms;
130
  this.submit = submit;
 
131
  }
132
 
133
  ValidationController.prototype.Init = function() {
@@ -135,10 +166,6 @@ ValidationController.prototype.Init = function() {
135
  this.forms.forEach(function(item) {
136
  item.Build(self.widget);
137
  });
138
- this.submit.click(function(event) {
139
- event.preventDefault();
140
- self.Validate(event);
141
- });
142
  };
143
 
144
  ValidationController.prototype.FindFormByFormId = function(formId) {
@@ -148,29 +175,24 @@ ValidationController.prototype.FindFormByFormId = function(formId) {
148
  result = this.forms[i];
149
  }
150
  }
151
-
152
  return result;
153
  };
154
 
155
  ValidationController.prototype.Validate = function(event) {
156
  var self = this;
157
- var network = this.widget.find("input[name=\"optile-selected-network\"]:checked").val();
158
  var form = this.FindFormByFormId(network);
159
  var data = form.ToJSON();
160
  var url = form.validationUrl;
161
-
162
  jQuery.post(url, data, function(resultData, resultStatus, xhr) {
163
  self.ValidationResult.call(self, resultData, resultStatus, xhr);
164
  }, "json");
165
  };
166
 
167
  ValidationController.prototype.ValidationResult = function(resultData, resultStatus, xhr) {
168
- var network = this.widget.find("input[name=\"optile-selected-network\"]:checked").val();
169
  var form = this.FindFormByFormId(network);
170
  form.BindMessages(resultData.messages);
171
-
172
- if(resultData.valid === true) {
173
- this.submit.off("click");
174
- this.submit.click();
175
- }
176
- };
1
  /**
2
+ * Copyright optile GmbH 2013
3
+ * Licensed under the Software License Agreement in effect between optile and
4
+ * Licensee/user (the "License"); you may not use this file except in compliance
5
+ * with the License. You may obtain a copy of the License at
6
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
7
+ * copy has been provided to you for your records. Unless required by applicable
8
+ * law or agreed to in writing or otherwise stipulated in the License, software
9
+ * distributed under the License is distributed on an "as is" basis without
10
+ * warranties or conditions of any kind, either express or implied. See the
11
+ * License for the specific language governing permissions and limitations under
12
+ * the License.
 
 
 
13
  *
14
  * @author i-Ways <dev@i-ways.hr>
15
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
16
+ * @license http://www.optile.de/software-license-agreement
17
  */
18
+ function OptilePaymentNetworkForm(formId, validationUrl, operationUrl, networkCode) {
 
19
  this.formId = formId;
20
  this.validationUrl = validationUrl;
21
+ this.operationUrl = operationUrl;
22
+ this.networkCode = networkCode;
23
  this.widget = null;
24
  this.holderName = null;
25
  this.holderNameMessage = null;
51
  this.passwordMessage = null;
52
  }
53
 
54
+ OptilePaymentNetworkForm.prototype.Build = function(parentWidget) {
55
  this.holderName = parentWidget.find("#" + this.formId + "-holderName").first();
56
  this.holderNameMessage = parentWidget.find("#" + this.formId + "-holderName-message").first();
57
  this.number = parentWidget.find("#" + this.formId + "-number").first();
82
  this.passwordMessage = parentWidget.find("#" + this.formId + "-password-message").first();
83
  };
84
 
85
+ OptilePaymentNetworkForm.prototype.ToJSON = function() {
86
  var data = {};
87
  if(this.holderName.length > 0) data.holderName = this.holderName.val();
88
  if(this.number.length > 0) data.number = this.number.val();
97
  if(this.country.length > 0) data.country = this.country.val();
98
  if(this.city.length > 0) data.city = this.city.val();
99
  if(this.login.length > 0) data.login = this.login.val();
100
+ if(this.password.length > 0) data.password = this.password.val();
101
 
102
  return data;
103
  };
104
 
105
+ OptilePaymentNetworkForm.prototype.BindValues = function(data) {
106
+ for(item in data) {
107
+ if(this.hasOwnProperty(item) && this.hasOwnProperty(item + "Message")) {
108
+ var itemWidget = this[item];
109
+
110
+ if(data[item] !== null) {
111
+ itemWidget.val(data[item]);
112
+ }
113
+ }
114
+ }
115
+ };
116
+
117
+ OptilePaymentNetworkForm.prototype.BindMessages = function(messages) {
118
  for(item in messages) {
 
 
119
  if(this.hasOwnProperty(item) && this.hasOwnProperty(item + "Message")) {
120
+ var messageWidget = this[item + "Message"];
121
+ var itemWidget = this[item];
122
+
123
+ // reset message
124
+ messageWidget.html("");
125
+ messageWidget.removeClass('optile-error-msg');
126
+ messageWidget.removeClass('optile-info-msg');
127
+ itemWidget.removeClass('input-text validation-passed');
128
+ itemWidget.removeClass('input-text validation-failed');
129
+
130
+ if(messages[item] !== null) {
131
+ switch(messages[item].type) {
132
+ case 'ERROR':
133
+ messageWidget.addClass('optile-error-msg');
134
+ if(!itemWidget.is('select')) {
135
+ itemWidget.addClass('input-text');
136
+ }
137
+ itemWidget.addClass('validation-failed');
138
+ break;
139
+ case 'INFO':
140
+ messageWidget.addClass('optile-info-msg');
141
+ itemWidget.addClass('input-text validation-passed');
142
+ break;
143
+ }
144
+
145
+ messageWidget.html(messages[item].message);
146
  }
 
 
147
  }
148
  }
149
  };
150
 
151
+ // alias new OptilePaymentNetworkForm to old ValidationForm
152
+ function ValidationForm() {
153
+ OptilePaymentNetworkForm.apply(this, arguments);
154
+ }
155
+ ValidationForm.prototype = new OptilePaymentNetworkForm();
156
+
157
+ function ValidationController(widget, forms, submit, selectedNetworkSelector) {
158
  this.widget = widget;
159
  this.forms = forms;
160
  this.submit = submit;
161
+ this.selectedNetworkSelector = selectedNetworkSelector;
162
  }
163
 
164
  ValidationController.prototype.Init = function() {
166
  this.forms.forEach(function(item) {
167
  item.Build(self.widget);
168
  });
 
 
 
 
169
  };
170
 
171
  ValidationController.prototype.FindFormByFormId = function(formId) {
175
  result = this.forms[i];
176
  }
177
  }
178
+
179
  return result;
180
  };
181
 
182
  ValidationController.prototype.Validate = function(event) {
183
  var self = this;
184
+ var network = this.widget.find(this.selectedNetworkSelector).val();
185
  var form = this.FindFormByFormId(network);
186
  var data = form.ToJSON();
187
  var url = form.validationUrl;
188
+
189
  jQuery.post(url, data, function(resultData, resultStatus, xhr) {
190
  self.ValidationResult.call(self, resultData, resultStatus, xhr);
191
  }, "json");
192
  };
193
 
194
  ValidationController.prototype.ValidationResult = function(resultData, resultStatus, xhr) {
195
+ var network = this.widget.find(this.selectedNetworkSelector).val();
196
  var form = this.FindFormByFormId(network);
197
  form.BindMessages(resultData.messages);
198
+ };
 
 
 
 
 
lib/Optile/Client/optilevalidation.js DELETED
@@ -1,185 +0,0 @@
1
- /**
2
- * This file is part of the Optile Payment Connector extension.
3
- *
4
- * Optile Payment Connector is free software: you can redistribute it and/or
5
- * modify it under the terms of the GNU General Public License as published
6
- * by the Free Software Foundation, either version 3 of the License, or
7
- * (at your option) any later version.
8
- *
9
- * Optile Payment Connector is distributed in the hope that it will be useful,
10
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
- * GNU General Public License for more details.
13
- *
14
- * You should have received a copy of the GNU General Public License along with
15
- * Optile Payment Connector. If not, see <http://www.gnu.org/licenses/>.
16
- *
17
- * @author i-Ways <dev@i-ways.hr>
18
- * @copyright Copyright (c) 2013 Optile. (http://www.optile.de)
19
- * @license http://www.gnu.org/licenses/gpl.txt
20
- */
21
-
22
- function OptilePaymentNetworkForm(formId, validationUrl, operationUrl) {
23
- this.formId = formId;
24
- this.validationUrl = validationUrl;
25
- this.operationUrl = operationUrl;
26
- this.widget = null;
27
- this.holderName = null;
28
- this.holderNameMessage = null;
29
- this.number = null;
30
- this.numberMessage = null;
31
- this.expiryMonth = null;
32
- this.expiryMonthMessage = null;
33
- this.expiryYear = null;
34
- this.expiryYearMessage = null;
35
- this.verificationCode = null;
36
- this.verificationCodeMessage = null;
37
- this.bankCode = null;
38
- this.bankCodeMessage = null;
39
- this.bankName = null;
40
- this.bankNameMessage = null;
41
- this.bic = null;
42
- this.bicMessage = null;
43
- this.iban = null;
44
- this.ibanMessage = null;
45
- this.branch = null;
46
- this.branchMessage = null;
47
- this.country = null;
48
- this.countryMessage = null;
49
- this.city = null;
50
- this.cityMessage = null;
51
- this.login = null;
52
- this.loginMessage = null;
53
- this.password = null;
54
- this.passwordMessage = null;
55
- }
56
-
57
- OptilePaymentNetworkForm.prototype.Build = function(parentWidget) {
58
- this.holderName = parentWidget.find("#" + this.formId + "-holderName").first();
59
- this.holderNameMessage = parentWidget.find("#" + this.formId + "-holderName-message").first();
60
- this.number = parentWidget.find("#" + this.formId + "-number").first();
61
- this.numberMessage = parentWidget.find("#" + this.formId + "-number-message").first();
62
- this.expiryMonth = parentWidget.find("#" + this.formId + "-expiryMonth").first();
63
- this.expiryMonthMessage = parentWidget.find("#" + this.formId + "-expiryMonth-message").first();
64
- this.expiryYear = parentWidget.find("#" + this.formId + "-expiryYear").first();
65
- this.expiryYearMessage = parentWidget.find("#" + this.formId + "-expiryYear-message").first();
66
- this.verificationCode = parentWidget.find("#" + this.formId + "-verificationCode").first();
67
- this.verificationCodeMessage = parentWidget.find("#" + this.formId + "-verificationCode-message").first();
68
- this.bankCode = parentWidget.find("#" + this.formId + "-bankCode").first();
69
- this.bankCodeMessage = parentWidget.find("#" + this.formId + "-bankCode-message").first();
70
- this.bankName = parentWidget.find("#" + this.formId + "-bankName").first();
71
- this.bankNameMessage = parentWidget.find("#" + this.formId + "-bankName-message").first();
72
- this.bic = parentWidget.find("#" + this.formId + "-bic").first();
73
- this.bicMessage = parentWidget.find("#" + this.formId + "-bic-message").first();
74
- this.iban = parentWidget.find("#" + this.formId + "-iban").first();
75
- this.ibanMessage = parentWidget.find("#" + this.formId + "-iban-message").first();
76
- this.branch = parentWidget.find("#" + this.formId + "-branch").first();
77
- this.branchMessage = parentWidget.find("#" + this.formId + "-branch-message").first();
78
- this.country = parentWidget.find("#" + this.formId + "-country").first();
79
- this.countryMessage = parentWidget.find("#" + this.formId + "-country-message").first();
80
- this.city = parentWidget.find("#" + this.formId + "-city").first();
81
- this.cityMessage = parentWidget.find("#" + this.formId + "-city-message").first();
82
- this.login = parentWidget.find("#" + this.formId + "-login").first();
83
- this.loginMessage = parentWidget.find("#" + this.formId + "-login-message").first();
84
- this.password = parentWidget.find("#" + this.formId + "-password").first();
85
- this.passwordMessage = parentWidget.find("#" + this.formId + "-password-message").first();
86
- };
87
-
88
- OptilePaymentNetworkForm.prototype.ToJSON = function() {
89
- var data = {};
90
- if(this.holderName.length > 0) data.holderName = this.holderName.val();
91
- if(this.number.length > 0) data.number = this.number.val();
92
- if(this.expiryMonth.length > 0) data.expiryMonth = this.expiryMonth.val();
93
- if(this.expiryYear.length > 0) data.expiryYear = this.expiryYear.val();
94
- if(this.verificationCode.length > 0) data.verificationCode = this.verificationCode.val();
95
- if(this.bankCode.length > 0) data.bankCode = this.bankCode.val();
96
- if(this.bankName.length > 0) data.bankName = this.bankName.val();
97
- if(this.bic.length > 0) data.bic = this.bic.val();
98
- if(this.iban.length > 0) data.iban = this.iban.val();
99
- if(this.branch.length > 0) data.branch = this.branch.val();
100
- if(this.country.length > 0) data.country = this.country.val();
101
- if(this.city.length > 0) data.city = this.city.val();
102
- if(this.login.length > 0) data.login = this.login.val();
103
- if(this.password.length > 0) data.password = this.password.val();
104
-
105
- return data;
106
- };
107
-
108
- OptilePaymentNetworkForm.prototype.BindMessages = function(messages) {
109
- for(item in messages) {
110
- if(messages[item] === null) continue;
111
-
112
- if(this.hasOwnProperty(item) && this.hasOwnProperty(item + "Message")) {
113
- var widget = this[item + "Message"];
114
-
115
- widget.removeClass('optile-error-msg');
116
-
117
- switch(messages[item].type) {
118
- case 'ERROR':
119
- widget.addClass('optile-error-msg');
120
- break;
121
- }
122
-
123
- widget.html(messages[item].message);
124
- }
125
- }
126
- };
127
-
128
- // alias new OptilePaymentNetworkForm to old ValidationForm
129
- function ValidationForm() {
130
- OptilePaymentNetworkForm.apply(this, arguments);
131
- }
132
- ValidationForm.prototype = new OptilePaymentNetworkForm();
133
-
134
- function ValidationController(widget, forms, submit, selectedNetworkSelector) {
135
- this.widget = widget;
136
- this.forms = forms;
137
- this.submit = submit;
138
- this.selectedNetworkSelector = selectedNetworkSelector;
139
- }
140
-
141
- ValidationController.prototype.Init = function() {
142
- var self = this;
143
- this.forms.forEach(function(item) {
144
- item.Build(self.widget);
145
- });
146
-
147
- // this.submit.click(function(event) {
148
- // event.preventDefault();
149
- // self.Validate(event);
150
- // });
151
- };
152
-
153
- ValidationController.prototype.FindFormByFormId = function(formId) {
154
- var result = null;
155
- for(var i = 0; i < this.forms.length; ++i) {
156
- if(this.forms[i].formId == formId) {
157
- result = this.forms[i];
158
- }
159
- }
160
-
161
- return result;
162
- };
163
-
164
- ValidationController.prototype.Validate = function(event) {
165
- var self = this;
166
- var network = this.widget.find(this.selectedNetworkSelector).val();
167
- var form = this.FindFormByFormId(network);
168
- var data = form.ToJSON();
169
- var url = form.validationUrl;
170
-
171
- jQuery.post(url, data, function(resultData, resultStatus, xhr) {
172
- self.ValidationResult.call(self, resultData, resultStatus, xhr);
173
- }, "json");
174
- };
175
-
176
- ValidationController.prototype.ValidationResult = function(resultData, resultStatus, xhr) {
177
- var network = this.widget.find(this.selectedNetworkSelector).val();
178
- var form = this.FindFormByFormId(network);
179
- form.BindMessages(resultData.messages);
180
-
181
- // if(resultData.valid === true) {
182
- // this.submit.off("click");
183
- // this.submit.click();
184
- // }
185
- };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/Optile/Request/Account.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
14
+ *
15
+ * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
+ */
19
+
20
+ namespace Optile\Request;
21
+
22
+ /**
23
+ * @todo: this class is not in use yet.
24
+ *
25
+ * @method Account setHolderName(string $value)
26
+ * @method Account setNumber(int $value)
27
+ * @method Account setBankCode($value)
28
+ * @method Account setBankName(string $value)
29
+ * @method Account setCity(string $value)
30
+ * @method Account setBic($value)
31
+ * @method Account setBranch(string $value)
32
+ * @method Account setExpiryMonth($value)
33
+ * @method Account setExpiryYear($value)
34
+ * @method Account setIban($value)
35
+ * @method Account setLogin($value)
36
+ * @method Account setOptIn($value)
37
+ * @method Account setPassword($value)
38
+ * @method Account setVerificationCode($value)
39
+ */
40
+ class Account extends Component {
41
+
42
+ }
lib/Optile/Request/Cache.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
14
+ *
15
+ * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
+ */
19
+
20
+ namespace Optile\Request;
21
+ /**
22
+ * class Cache
23
+ *
24
+ * Allows the development team to pass on cache instance from eCommerce
25
+ * platform to the SDK.
26
+ *
27
+ **/
28
+ class Cache{
29
+
30
+ static $cacher = null;
31
+
32
+ public static function setCacher($cacher){
33
+ self::$cacher = $cacher;
34
+ }
35
+
36
+ static function save($key, $data=null, $lifeTime=3600){
37
+ if(self::$cacher === null){
38
+ Logger::log("NO cacher found");
39
+ return false;
40
+ }
41
+ return self::$cacher->save($key, $data, $lifeTime);
42
+ }
43
+ static function load($key){
44
+ if(self::$cacher === null){
45
+ Logger::log("NO cacher found");
46
+ return false;
47
+ }
48
+ return self::$cacher->load($key);
49
+ }
50
+ }
lib/Optile/Request/Callback.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
14
+ *
15
+ * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
+ */
19
+
20
+ namespace Optile\Request;
21
+
22
+ require_once 'Component.php';
23
+
24
+ /**
25
+ * Callback
26
+ *
27
+ * Defines data structure for callback request object.
28
+ * See class Request (and/or all of it's subclass) for implementation specifics.
29
+ *
30
+ * @method Callback setReturnUrl(string $value)
31
+ * @method Callback setCancelUrl(string $value)
32
+ * @method Callback setNotificationUrl(string $value)
33
+ */
34
+ class Callback extends Component {
35
+
36
+ protected function validation() {
37
+ $this->validateRequired('returnUrl', "Return URL");
38
+ $this->validateRequired('cancelUrl', "Cancel URL");
39
+ $this->validateRequired('notificationUrl', "Notification URL");
40
+ }
41
+
42
+ }
lib/Optile/Request/CancelRequest.php ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
14
+ *
15
+ * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
+ */
19
+
20
+ namespace Optile\Request;
21
+
22
+ require_once __DIR__.'/../Response/ResponseFactory.php';
23
+
24
+ /**
25
+ * CancelRequest
26
+ *
27
+ * Used for cancelling deferred payment transaction. Should be triggered when
28
+ * a merchant or eCommerce system realizes that the payment will not be made.
29
+ * This will result in release of customer's funds.
30
+ *
31
+ * @method ListRequest setChannel(string $value)
32
+ * @method ListRequest setCountry(string $value)
33
+ * @method ListRequest setTransactionId(string $value)
34
+ */
35
+ class CancelRequest extends Request {
36
+
37
+ public function __construct($apiUrl) {
38
+ parent::__construct($apiUrl);
39
+
40
+ $this->urlSuffix = '';
41
+
42
+ // $this->setChannel(OptileChannel::WEB_ORDER);
43
+ }
44
+
45
+ protected function validation() {
46
+
47
+ }
48
+
49
+ /**
50
+ * Send Cancel request to Optile and parse response.
51
+ * @return \Optile\Response\Response|null
52
+ */
53
+ public function send($method = self::METHOD_DELETE) {
54
+ $result = parent::send($method);
55
+
56
+ if ($result) {
57
+ $responseFactory = new \Optile\Response\ResponseFactory();
58
+ $optileResponse = $responseFactory->BuildOptileResponse($result);
59
+
60
+ return $optileResponse;
61
+ }
62
+ }
63
+ }
lib/Optile/Request/ChargeRequest.php ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
14
+ *
15
+ * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
+ */
19
+
20
+ namespace Optile\Request;
21
+
22
+ /**
23
+ * ChargeRequest
24
+ *
25
+ * Used to execute the payment transaction on Optile.
26
+ *
27
+ * NOTE: This SDK currently supports only NATIVE_WITHOUT_PCI implementation, so
28
+ * charge request is not being handled through the merchant's system.
29
+ * For reference, use Optile's documentation:
30
+ * https://docs.optile.de/archive/PIN/CHARGE%20Request.html
31
+ **/
32
+ class ChargeRequest extends Request {
33
+
34
+ protected function validation() {
35
+ $this->validateRequired('account', 'Account data');
36
+ }
37
+
38
+ public function send($method = self::METHOD_POST) {
39
+ return parent::send($method);
40
+ }
41
+
42
+ /**
43
+ * @return OptileAccount
44
+ */
45
+ public function addAccount() {
46
+ $component = RequestFactory::getComponent('account');
47
+ $this->setData('account', $component);
48
+ return $component;
49
+ }
50
+
51
+ }
lib/Optile/Request/ClientInfo.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
14
+ *
15
+ * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
+ */
19
+
20
+ namespace Optile\Request;
21
+
22
+ require_once 'Component.php';
23
+
24
+ /**
25
+ * ClientInfo
26
+ *
27
+ * Used for adding additional API client info to the list request.
28
+ * @todo: not yet in use
29
+ *
30
+ * @method ClientInfo setIp(string $value)
31
+ * @method ClientInfo setIpv6(string $value)
32
+ * @method ClientInfo setUserAgent(string $value)
33
+ * @method ClientInfo setAcceptHeader(string $value)
34
+ */
35
+ class ClientInfo extends Component {
36
+
37
+ }
lib/Optile/Request/CloseRequest.php ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
14
+ *
15
+ * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
+ */
19
+
20
+ namespace Optile\Request;
21
+
22
+ require_once __DIR__.'/../Response/ResponseFactory.php';
23
+
24
+ /**
25
+ * CloseRequest
26
+ *
27
+ * Used for closing deferred payment transaction. Should be triggered when
28
+ * Merchant wants to capture the reserved funds from Customer. It can be executed
29
+ * without setting the payment and product parameters. In this case entire
30
+ * order amount will be captured, however it is recommended to specify the
31
+ * payment and product paramaters.
32
+ *
33
+ * @method ListRequest setChannel(string $value)
34
+ * @method ListRequest setCountry(string $value)
35
+ * @method ListRequest setTransactionId(string $value)
36
+ */
37
+ class CloseRequest extends Request {
38
+
39
+ public function __construct($apiUrl) {
40
+ parent::__construct($apiUrl);
41
+
42
+ $this->urlSuffix = '';
43
+
44
+ // $this->setChannel(OptileChannel::WEB_ORDER);
45
+ }
46
+
47
+ protected function validation() {
48
+
49
+ }
50
+
51
+ /**
52
+ * Send CLOSE request to Optile and parse response.
53
+ * @return \Optile\Response\Response|null
54
+ */
55
+ public function send($method = self::METHOD_POST) {
56
+ $result = parent::send($method);
57
+ Logger::log(__METHOD__.': '.$result);
58
+ if ($result) {
59
+ $responseFactory = new \Optile\Response\ResponseFactory();
60
+ $optileResponse = $responseFactory->BuildOptileResponse($result);
61
+
62
+ return $optileResponse;
63
+ }
64
+ }
65
+
66
+
67
+ /**
68
+ * @return Payment
69
+ */
70
+ public function addPayment() {
71
+ $component = RequestFactory::getComponent('payment');
72
+ $this->setData('payment', $component);
73
+ return $component;
74
+ }
75
+
76
+ /**
77
+ * @return Product
78
+ */
79
+ public function addProduct() {
80
+ $component = RequestFactory::getComponent('product');
81
+ $this->addData('products', $component);
82
+ return $component;
83
+ }
84
+
85
+ }
lib/Optile/Request/Component.php ADDED
@@ -0,0 +1,159 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
14
+ *
15
+ * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
+ */
19
+
20
+ namespace Optile\Request;
21
+
22
+ require_once 'RequestFactory.php';
23
+
24
+ /**
25
+ * abstract class Component:
26
+ *
27
+ * Contains validation methods and magic getter/setter method
28
+ *
29
+ **/
30
+ abstract class Component {
31
+
32
+ private $_data = array();
33
+
34
+ /**
35
+ * Validation error messages: array(fieldName => errorMessage)
36
+ * @var array
37
+ */
38
+ protected $validationResult;
39
+
40
+ /**
41
+ * Validates the current object; generates error messages if appropriate.
42
+ */
43
+ protected function validation() {
44
+ }
45
+
46
+ private function validate() {
47
+ $this->validationResult = array();
48
+
49
+ $this->validation();
50
+
51
+ if (!empty($this->validationResult)) {
52
+ $e = RequestFactory::getException('request', $this->validationResult);
53
+ throw $e;
54
+ }
55
+ }
56
+
57
+ /**
58
+ * Checks if a field is required and generates an error message.
59
+ * @param string $field
60
+ * @param string $title
61
+ */
62
+ protected function validateRequired($field, $title) {
63
+ $value = $this->getData($field);
64
+ if (empty($value)) {
65
+ $this->validationResult[$title] = "$title is required";
66
+ }
67
+ }
68
+
69
+ /**
70
+ * Get request data from this object recursively.
71
+ * RequestExceptions from invoked validate() passes through.
72
+ * @return array
73
+ */
74
+ public function getValidatedData() {
75
+ $this->validate();
76
+
77
+ $data = array();
78
+
79
+ foreach ($this->_data as $field => $component) {
80
+ if ($component instanceof Component) {
81
+ $data[$field] = $component->getValidatedData();
82
+ }
83
+ elseif (is_array($component)) {
84
+ // @TODO: Some code duplication here, suggests further abstraction
85
+ foreach ($component as $key => $value) {
86
+ if ($value instanceof Component) {
87
+ $data[$field][$key] = $value->getValidatedData();
88
+ } else {
89
+ $data[$field][$key] = $value;
90
+ }
91
+ }
92
+ }
93
+ else {
94
+ $data[$field] = $component;
95
+ }
96
+ }
97
+
98
+ return $data;
99
+ }
100
+
101
+ public function __call($method, $args) {
102
+ switch (substr($method, 0, 3)) {
103
+ case 'set':
104
+ $key = lcfirst(substr($method, 3));
105
+ $value = (string) $args[0];
106
+ $result = $this->setData($key, $value);
107
+ return $result;
108
+ case 'get':
109
+ $key = lcfirst(substr($method, 3));
110
+ $result = $this->getData($key);
111
+ return $result;
112
+ }
113
+ throw new Exception("Invalid method ".get_class($this)."::".$method."(".print_r($args,1).")");
114
+ }
115
+
116
+ /**
117
+ * Set simple request data; only string values allowed from public interface.
118
+ * @param string $key
119
+ * @param mixed $value
120
+ * @return Component
121
+ */
122
+ protected function setData($key, $value) {
123
+ $this->_data[$key] = $value;
124
+ return $this;
125
+ }
126
+
127
+ /**
128
+ * Get single request value.
129
+ * @param string $key
130
+ * @return string|null
131
+ */
132
+ protected function getData($key) {
133
+ if (isset($this->_data[$key])) {
134
+ return $this->_data[$key];
135
+ }
136
+ }
137
+
138
+ /**
139
+ * Add a value to an array. Creates the array if this is the first value.
140
+ * @param string $key
141
+ * @param mixed $value
142
+ * @param string $value
143
+ * @return Component
144
+ */
145
+ protected function addData($key, $value, $index=null) {
146
+ if (!isset($this->_data[$key])) {
147
+ $this->_data[$key] = array();
148
+ }
149
+
150
+ if (strlen($index)) {
151
+ $this->_data[$key][$index] = $value;
152
+ } else {
153
+ $this->_data[$key][] = $value;
154
+ }
155
+
156
+ return $this;
157
+ }
158
+
159
+ }
lib/Optile/Request/Customer.php ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
14
+ *
15
+ * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
+ */
19
+
20
+ namespace Optile\Request;
21
+
22
+ require_once 'Component.php';
23
+
24
+ /**
25
+ * Customer
26
+ *
27
+ * Used for define a customer when doing LIST request. Allows for adding
28
+ * additional customer data as child entities.
29
+ * See classes CustomerName, CustomerAddress, CustomerPhone below
30
+ *
31
+ * @method Customer setEmail(string $value)
32
+ * @method Customer setNumber(string $value)
33
+ * @method Customer setBirthday(string $value) Format: ISO 8601. Use date('c', $timestamp) in PHP.
34
+ */
35
+ class Customer extends Component {
36
+
37
+ protected function validation() {
38
+ $this->validateRequired('number', 'Customer number');
39
+ $this->validateRequired('email', 'Customer e-mail');
40
+ }
41
+
42
+ /**
43
+ * @return CustomerName
44
+ */
45
+ public function addName() {
46
+ $component = new CustomerName();
47
+ $this->setData('name', $component);
48
+ return $component;
49
+ }
50
+
51
+ /**
52
+ * @param type $type
53
+ * @return CustomerAddress
54
+ */
55
+ public function addAddress($type) {
56
+ $component = new CustomerAddress();
57
+ $this->addData('addresses', $component, $type);
58
+ return $component;
59
+ }
60
+
61
+ /**
62
+ * @param type $type
63
+ * @return CustomerPhone
64
+ */
65
+ public function addPhone($type) {
66
+ $component = new CustomerPhone();
67
+ $this->addData('phones', $component, $type);
68
+ return $component;
69
+ }
70
+
71
+ }
72
+
73
+ /**
74
+ * @method CustomerName setTitle(string $value)
75
+ * @method CustomerName setFirstName(string $value)
76
+ * @method CustomerName setMiddleName(string $value)
77
+ * @method CustomerName setLastName(string $value)
78
+ * @method CustomerName setMaidenName(string $value)
79
+ */
80
+ class CustomerName extends Component {
81
+
82
+ }
83
+
84
+ /**
85
+ * @method CustomerAddress setStreet(string $value)
86
+ * @method CustomerAddress setHouseNumber(string $value)
87
+ * @method CustomerAddress setZip(string $value)
88
+ * @method CustomerAddress setCity(string $value)
89
+ * @method CustomerAddress setState(string $value)
90
+ * @method CustomerAddress setCountry(string $value)
91
+ */
92
+ class CustomerAddress extends Component {
93
+
94
+ const TYPE_BILLING = 'billing';
95
+ const TYPE_SHIPPING = 'shipping';
96
+
97
+ public function addName() {
98
+ $component = new CustomerName();
99
+ $this->setData('name', $component);
100
+ return $component;
101
+ }
102
+
103
+ }
104
+
105
+ /**
106
+ * @method CustomerPhone setCountryCode(int $value)
107
+ * @method CustomerPhone setAreaCode(int $value)
108
+ * @method CustomerPhone setSubscriberNumber(int $value)
109
+ * @method CustomerPhone setUnstructuredNumber(string $value)
110
+ */
111
+ class CustomerPhone extends Component {
112
+
113
+ const TYPE_WORK = 'work';
114
+ const TYPE_COMPANY = 'company';
115
+ const TYPE_HOME = 'home';
116
+ const TYPE_OTHER = 'other';
117
+ const TYPE_MOBILE = 'mobile';
118
+ const TYPE_MOBILE_SECONDARY = 'mobileSecondary';
119
+ const TYPE_FAX = 'fax';
120
+
121
+ }
lib/Optile/Request/Exception.php ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
14
+ *
15
+ * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
+ */
19
+
20
+ namespace Optile\Request;
21
+ /**
22
+ * Exception
23
+ *
24
+ * Extending Exception to handle array type of message for development purposes.
25
+ * Not used in live environment.
26
+ *
27
+ */
28
+ class Exception extends \Exception {
29
+ public function __construct($fields, $code=null, $previous=null) {
30
+ $message = '';
31
+
32
+ if(is_array($fields)){
33
+ foreach ($fields as $value) {
34
+ $message .= $value."\n\r";
35
+ }
36
+ }else{
37
+ $message = $fields;
38
+ }
39
+
40
+ parent::__construct($message, $code, $previous);
41
+ }
42
+ }
43
+
44
+ class UrlException extends \Exception {
45
+
46
+ }
lib/Optile/Request/ListRequest.php ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
14
+ *
15
+ * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
+ */
19
+
20
+ namespace Optile\Request;
21
+
22
+ require_once __DIR__.'/../Response/ResponseFactory.php';
23
+
24
+ /**
25
+ * ListRequest
26
+ *
27
+ * Used for getting the payment network list on checkout.
28
+ * For list of required fields see validation() method.
29
+ *
30
+ *
31
+ * @method ListRequest setChannel(string $value)
32
+ * @method ListRequest setCountry(string $value)
33
+ * @method ListRequest setTransactionId(string $value)
34
+ */
35
+ class ListRequest extends Request {
36
+
37
+ public function __construct($apiUrl) {
38
+ parent::__construct($apiUrl);
39
+
40
+ $this->urlSuffix = '/api/lists';
41
+
42
+ $this->setChannel(OptileChannel::WEB_ORDER);
43
+ }
44
+
45
+ protected function validation() {
46
+ $this->validateRequired('transactionId', 'Transaction ID');
47
+ $this->validateRequired('channel', 'Channel');
48
+ $this->validateRequired('country', 'Country');
49
+ $this->validateRequired('callback', 'Callback data');
50
+ $this->validateRequired('customer', 'Customer data');
51
+ }
52
+
53
+ /**
54
+ * Send LIST request to Optile and parse response.
55
+ * @return \Optile\Response\Response|null
56
+ */
57
+ public function send($method = self::METHOD_POST) {
58
+ $result = parent::send($method);
59
+
60
+ if ($result) {
61
+ $responseFactory = new \Optile\Response\ResponseFactory();
62
+ $optileResponse = $responseFactory->BuildOptileResponse($result);
63
+
64
+ return $optileResponse;
65
+ }else{
66
+ return $result;
67
+ }
68
+ }
69
+
70
+ /**
71
+ * @return Callback
72
+ */
73
+ public function addCallback() {
74
+ $component = RequestFactory::getComponent('callback');
75
+ $this->setData('callback', $component);
76
+ return $component;
77
+ }
78
+
79
+ /**
80
+ * @return Customer
81
+ */
82
+ public function addCustomer() {
83
+ $component = RequestFactory::getComponent('customer');
84
+ $this->setData('customer', $component);
85
+ return $component;
86
+ }
87
+
88
+ /**
89
+ * @return Payment
90
+ */
91
+ public function addPayment() {
92
+ $component = RequestFactory::getComponent('payment');
93
+ $this->setData('payment', $component);
94
+ return $component;
95
+ }
96
+
97
+ /**
98
+ * @return Product
99
+ */
100
+ public function addProduct() {
101
+ $component = RequestFactory::getComponent('product');
102
+ $this->addData('products', $component);
103
+ return $component;
104
+ }
105
+
106
+ /**
107
+ * @return ClientInfo
108
+ */
109
+ public function addClientInfo() {
110
+ $component = RequestFactory::getComponent('clientInfo');
111
+ $this->setData('clientInfo', $component);
112
+ return $component;
113
+ }
114
+
115
+ public function addPreselection(){
116
+ $component = RequestFactory::getComponent('preselection');
117
+ $this->setData('preselection', $component);
118
+ return $component;
119
+ }
120
+
121
+ }
122
+
123
+ class OptileChannel {
124
+
125
+ const WEB_ORDER = "WEB_ORDER";
126
+ const MOBILE_ORDER = "MOBILE_ORDER";
127
+ const EMAIL_ORDER = "EMAIL_ORDER";
128
+ const CALLCENTER_ORDER = "CALLCENTER_ORDER";
129
+ const MAIL_ORDER = "MAIL_ORDER";
130
+ const TERMINAL_ORDER = "TERMINAL_ORDER";
131
+ const CUSTOMER_SUPPORT = "CUSTOMER_SUPPORT";
132
+ const CUSTOMER_SELF_SERVICE = "CUSTOMER_SELF_SERVICE";
133
+ const RECURRING = "RECURRING";
134
+ const FULFILLMENT = "FULFILLMENT";
135
+ const DUNNING = "DUNNING";
136
+ const IMPORT = "IMPORT";
137
+
138
+ }
lib/Optile/Request/Logger.php ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
14
+ *
15
+ * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
+ */
19
+
20
+ namespace Optile\Request;
21
+ /**
22
+ * class Logger
23
+ *
24
+ * Allows the development team to pass on logger instance from eCommerce
25
+ * platform to the SDK.
26
+ *
27
+ **/
28
+ class Logger{
29
+
30
+ const EMERG = 0; // Emergency: system is unusable
31
+ const ALERT = 1; // Alert: action must be taken immediately
32
+ const CRIT = 2; // Critical: critical conditions
33
+ const ERR = 3; // Error: error conditions
34
+ const WARN = 4; // Warning: warning conditions
35
+ const NOTICE = 5; // Notice: normal but significant condition
36
+ const INFO = 6; // Informational: informational messages
37
+ const DEBUG = 7; // Debug: debug messages
38
+
39
+ static $logger = null;
40
+
41
+ public static function setLogger($logger){
42
+ self::$logger = $logger;
43
+ }
44
+
45
+ static function log($msg, $level=self::DEBUG){
46
+ if(self::$logger === null){
47
+ return false;
48
+ }
49
+ self::$logger->log($msg, $level);
50
+ }
51
+ }
lib/Optile/Request/Payment.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
14
+ *
15
+ * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
+ */
19
+
20
+ namespace Optile\Request;
21
+
22
+ require_once 'Component.php';
23
+
24
+ /**
25
+ * Payment
26
+ *
27
+ * Used for describing Payment entity in the List request.
28
+ * See ListRequest class for more info.
29
+ *
30
+ * @method Payment setAmount(float $value)
31
+ * @method Payment setCurrency(string $value)
32
+ * @method Payment setReference(string $value)
33
+ */
34
+ class Payment extends Component {
35
+
36
+ protected function validation() {
37
+ $this->validateRequired('amount', 'Payment amount');
38
+ $this->validateRequired('currency', 'Payment currency');
39
+ $this->validateRequired('reference', 'Payment reference');
40
+ }
41
+
42
+ }
lib/Optile/Request/PayoutRequest.php ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
14
+ *
15
+ * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
+ */
19
+
20
+ namespace Optile\Request;
21
+
22
+ require_once __DIR__.'/../Response/ResponseFactory.php';
23
+
24
+ /**
25
+ * PayoutRequest
26
+ *
27
+ * Used to execute the refund transaction on Optile.
28
+ *
29
+ * For reference, use Optile's documentation:
30
+ * https://docs.optile.de/archive/PIN/6.%20Refunds.html#6.Refunds-CHARGERequest
31
+ **/
32
+ class PayoutRequest extends Request {
33
+
34
+ protected function validation() {
35
+ $this->validateRequired('payment', 'Payment data');
36
+ }
37
+
38
+ public function send($method = self::METHOD_POST) {
39
+ $result = parent::send($method);
40
+
41
+ if ($result) {
42
+ $responseFactory = new \Optile\Response\ResponseFactory();
43
+ $optileResponse = $responseFactory->BuildOptileResponse($result);
44
+
45
+ return $optileResponse;
46
+ }
47
+ }
48
+
49
+ /**
50
+ * @return Payment
51
+ */
52
+ public function addPayment() {
53
+ $component = RequestFactory::getComponent('payment');
54
+ $this->setData('payment', $component);
55
+ return $component;
56
+ }
57
+
58
+ }
lib/Optile/Request/Preselection.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
14
+ *
15
+ * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
+ */
19
+
20
+ namespace Optile\Request;
21
+
22
+ require_once 'Component.php';
23
+
24
+ /**
25
+ * Preselection
26
+ *
27
+ * Used for describing Preselection entity in the List request. Preselect
28
+ * entity determines the preferred deferral mode for the upcoming transaction.
29
+ * For possible deferral values, use constants. For more information,
30
+ * refer to Optile documentation:
31
+ * https://docs.optile.de/archive/PIN/Deferred%20Payments.html
32
+ *
33
+ * @method Product setDeferral(string $value)
34
+ */
35
+ class Preselection extends Component {
36
+
37
+ const TYPE_DEFERRED = 'DEFERRED';
38
+ const TYPE_NON_DEFERRED = 'NON_DEFERRED';
39
+ const TYPE_ANY = 'ANY';
40
+
41
+ protected function validation() {
42
+ $this->validateRequired('deferral', 'Deferral mode');
43
+
44
+ }
45
+ }
lib/Optile/Request/Product.php ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
14
+ *
15
+ * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
+ */
19
+
20
+ namespace Optile\Request;
21
+
22
+ require_once 'Component.php';
23
+
24
+ /**
25
+ * Product
26
+ *
27
+ * Used to describe the Product entity in the List request. Implements a workaround
28
+ * to avoid Amount rounding issue. This workaround is in place for PayPal.
29
+ * For more details, refer to validation() method.
30
+ *
31
+ * @method Product setCode(string $value)
32
+ * @method Product setName(string $value)
33
+ * @method Product setQuantity(int $value)
34
+ * @method Product setCurrency(string $value)
35
+ * @method Product setAmount(float $value)
36
+ */
37
+ class Product extends Component {
38
+
39
+ protected function validation() {
40
+ $this->validateRequired('code', 'Product code');
41
+ $this->validateRequired('name', 'Product name');
42
+
43
+ // Tackle PayPal issue with rounded amounts per product.
44
+ $qty = $this->getQuantity();
45
+ $amount = $this->getAmount();
46
+
47
+ if ($qty > 1) {
48
+ $single = (float) number_format($amount / $qty, 2, '.', '');
49
+ $total = $single * $qty;
50
+ if ($total != $amount) {
51
+ // Rounding issue, rowtotal isn't evenly divisible by qty.
52
+ // Change all product qty to 1 and add qty to descriptions.
53
+ $this->setQuantity(1);
54
+ $this->setName($qty .'x '. $this->getName());
55
+ }
56
+ }
57
+
58
+ }
59
+ }
lib/Optile/Request/ReloadListRequest.php ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
14
+ *
15
+ * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
+ */
19
+
20
+ namespace Optile\Request;
21
+
22
+ require_once __DIR__.'/../Response/ResponseFactory.php';
23
+
24
+ /**
25
+ * ReloadListRequest
26
+ *
27
+ * Used for reusing/updating of existing List request.
28
+ * Example usecase: if some payment networks becomes unavailable (Optile error
29
+ * or Customer Credit card gets rejected, ...), List will be reloaded and some
30
+ * payment networks will no longer be rendered.
31
+ * For more detailed instructions, please refer to Optile documentation:
32
+ * https://docs.optile.de/archive/PIN/LIST%20Request.html#Update
33
+ *
34
+ **/
35
+ class ReloadListRequest extends SimpleRequest {
36
+
37
+ /**
38
+ * Request "self" link from Optile and parse response.
39
+ * @return OptileResponse|null
40
+ */
41
+ public function send($method = self::METHOD_GET) {
42
+ $result = parent::send($method);
43
+
44
+ $responseFactory = new \Optile\Response\ResponseFactory();
45
+ $optileResponse = $responseFactory->BuildOptileResponse($result);
46
+
47
+ return $optileResponse;
48
+ }
49
+ }
lib/Optile/Request/Request.php ADDED
@@ -0,0 +1,211 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
14
+ *
15
+ * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
+ */
19
+
20
+ namespace Optile\Request;
21
+ require_once("Logger.php");
22
+
23
+ /**
24
+ * Request
25
+ *
26
+ * Abstract class that defines how the request is being executed to the Optile.
27
+ * It's subclasses should implement send() method and handle the response.
28
+ * For more info, refer to the ListRequest, ChargeRequest, CloseRequest, ... clases
29
+ */
30
+ abstract class Request extends Component {
31
+
32
+ const METHOD_POST = 'post';
33
+ const METHOD_GET = 'get';
34
+ const METHOD_DELETE = 'delete';
35
+
36
+ protected $url;
37
+ protected $urlSuffix = '';
38
+ protected $merchantCode;
39
+ protected $merchantToken;
40
+ protected $use_cache = false;
41
+ protected $cache_lifetime = 3600;
42
+
43
+ /**
44
+ * @param string $url
45
+ */
46
+ public function __construct($url) {
47
+ $this->url = (string) $url;
48
+ }
49
+
50
+ public function setUseCache($use_cache){
51
+ $this->use_cache = $use_cache;
52
+ return $this;
53
+ }
54
+ public function setCacheLifetime($cache_lifetime){
55
+ $this->cache_lifetime = $cache_lifetime;
56
+ return $this;
57
+ }
58
+
59
+ public function setMerchantCode($merchantCode){
60
+ $this->merchantCode = $merchantCode;
61
+ return $this;
62
+ }
63
+
64
+ public function setMerchantToken($merchantToken){
65
+ $this->merchantToken = $merchantToken;
66
+ return $this;
67
+ }
68
+
69
+ // @TODO: this should probably not be part of the generic Request object.
70
+ public function setUrl($value) {
71
+ $this->url = rtrim($value, '/');
72
+ return $this;
73
+ }
74
+
75
+
76
+ public function send($method){
77
+ if (!isset($this->url) || !strlen($this->url)) {
78
+ $e = RequestFactory::getException('url', 'URL must be set');
79
+ throw $e;
80
+ }
81
+
82
+ if($this->use_cache == true){
83
+ //Try to get from cache
84
+ Logger::log(__METHOD__.": Retrieving from cache");
85
+ $cache_key = md5($this->url);
86
+ $result = Cache::load($cache_key);
87
+
88
+ if($result === false){
89
+ Logger::log(__METHOD__.": No cached version found, doing a cURL call");
90
+ $result = $this->_send($method);
91
+ $success = Cache::save($cache_key, $result, $this->cache_lifetime);
92
+ Logger::log(__METHOD__.": Caching success: ".($success ? "YES" : "NO"));
93
+ }
94
+
95
+ return $result;
96
+ } else {
97
+ Logger::log(__METHOD__.": Sending request");
98
+ return $this->_send($method);
99
+ }
100
+
101
+ }
102
+
103
+ /**
104
+ * Send request to Optile and return response.
105
+ * @param string $method post|get
106
+ * @return string
107
+ * @throws @static.mtd:OptileRequestFactory.getException
108
+ */
109
+ public function _send($method) {
110
+
111
+ $url = rtrim($this->url, '/') . $this->urlSuffix;
112
+ $data = $this->getValidatedData();
113
+ $message = $this->serialize($data, $method);
114
+
115
+ $curlOpts = array(
116
+ CURLOPT_RETURNTRANSFER => 1,
117
+ CURLOPT_SSL_VERIFYPEER => 0,
118
+ CURLOPT_TIMEOUT => 30
119
+ );
120
+
121
+ if ($method == self::METHOD_POST) {
122
+ $curlOpts += array(
123
+ CURLOPT_POST => 1,
124
+ CURLOPT_POSTFIELDS => $message,
125
+ CURLOPT_HEADER => 1,
126
+ CURLOPT_VERBOSE => 0,
127
+ CURLOPT_HTTPHEADER => array(
128
+ 'Content-length:'. strlen($message),
129
+ 'Accept:application/vnd.optile.payment.enterprise-v1-extensible+json', //T: should we change this to simple-v1-extensible ?
130
+ 'Content-type:application/vnd.optile.payment.enterprise-v1-extensible+json',
131
+ ),
132
+ );
133
+ } elseif ($method == self::METHOD_DELETE){
134
+
135
+ $curlOpts += array(
136
+ CURLOPT_HTTPHEADER => array(
137
+ 'Accept:application/vnd.optile.payment.enterprise-v1-extensible+json', //T: should we change this to simple-v1-extensible ?
138
+ 'Content-type:application/vnd.optile.payment.enterprise-v1-extensible+json',
139
+ ),
140
+ CURLOPT_CUSTOMREQUEST => 'DELETE',
141
+ CURLOPT_HEADER => false,
142
+ CURLOPT_RETURNTRANSFER => true,
143
+ );
144
+ } else {
145
+ $url .= $message;
146
+ }
147
+
148
+ Logger::log(__METHOD__.': URL: '.$url);
149
+ Logger::log(__METHOD__.': Request: '.$message);
150
+
151
+ if(isset($this->merchantCode, $this->merchantToken)) {
152
+ $curlOpts[CURLOPT_USERPWD] = $this->merchantCode.'/'.$this->merchantToken;
153
+ }
154
+
155
+ $ch = curl_init($url);
156
+ curl_setopt_array($ch, $curlOpts);
157
+
158
+ $response = (string) curl_exec($ch);
159
+ $response_info = curl_getinfo($ch);
160
+ $response_error = curl_error($ch);
161
+
162
+ Logger::log(__METHOD__.': Response: '.$response. ', Response error: ' . $response_error);
163
+ Logger::log(__METHOD__.': Auth: '. $curlOpts[CURLOPT_USERPWD] = $this->merchantCode.'/'.$this->merchantToken);
164
+
165
+
166
+ curl_close($ch);
167
+
168
+ if($response_info['http_code'] >= 500){
169
+ // return null;
170
+ Logger::log(__METHOD__.': Response info: ');
171
+ Logger::log($response_info);
172
+ throw new \Exception("Optile server error");
173
+ }
174
+ $parts = explode("\r\n", $response);
175
+ $result = array_pop($parts);
176
+
177
+ return $result;
178
+ }
179
+
180
+ protected function serialize(array $data, $method) {
181
+ switch ($method) {
182
+ case self::METHOD_GET:
183
+ return $this->serializeForGet($data);
184
+
185
+ case self::METHOD_POST:
186
+ return $this->serializeForPost($data);
187
+
188
+ case self::METHOD_DELETE:
189
+ return $this->serializeForPost($data);
190
+ }
191
+ }
192
+
193
+ protected function serializeForPost(array $data) {
194
+ return json_encode($data, JSON_NUMERIC_CHECK);
195
+ }
196
+
197
+ protected function serializeForGet(array $data) {
198
+ if (empty($data))
199
+ return '';
200
+
201
+ $kvPairs = array();
202
+ foreach ($data as $key => $value) {
203
+ $kvPairs[] = $key .'='. urlencode($value);
204
+ }
205
+
206
+ $query = '?'. implode('&', $kvPairs);
207
+
208
+ return $query;
209
+ }
210
+
211
+ }
lib/Optile/Request/RequestFactory.php ADDED
@@ -0,0 +1,145 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
14
+ *
15
+ * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
+ */
19
+
20
+ namespace Optile\Request;
21
+
22
+ require_once 'Component.php';
23
+ require_once 'Request.php';
24
+ /**
25
+ * RequestFactory
26
+ *
27
+ * Factory class for various Optile Request handlers. This should be a starting
28
+ * point when generating a request to Optile API.
29
+ * For more iformation, see methods below.
30
+ */
31
+ class RequestFactory {
32
+
33
+ /**
34
+ * @param string $apiUrl URL (domain) to use as base for request URL.
35
+ * @return \Optile\Request\ListRequest
36
+ */
37
+ public static function getListRequest($apiUrl) {
38
+ require_once 'ListRequest.php';
39
+ $url = rtrim($apiUrl, '/');
40
+ return new ListRequest($url);
41
+ }
42
+
43
+ /**
44
+ * @param string $url URL to request.
45
+ * @return \Optile\Request\ReloadListRequest
46
+ */
47
+ public static function getReloadListRequest($url) {
48
+ require_once 'SimpleRequest.php';
49
+ require_once 'ReloadListRequest.php';
50
+ return new ReloadListRequest($url);
51
+ }
52
+
53
+ /**
54
+ * @param string $apiUrl URL (domain) to use as base for request URL.
55
+ * @return \Optile\Request\ChargeRequest
56
+ */
57
+ public static function getChargeRequest($apiUrl) {
58
+ require_once 'ChargeRequest.php';
59
+ $url = rtrim($apiUrl, '/');
60
+ return new ChargeRequest($url);
61
+ }
62
+
63
+ /**
64
+ * @param string $apiUrl URL (domain) to use as base for request URL.
65
+ * @return \Optile\Request\ListRequest
66
+ */
67
+ public static function getCloseRequest($apiUrl) {
68
+ require_once 'CloseRequest.php';
69
+ $url = rtrim($apiUrl, '/');
70
+ return new CloseRequest($url);
71
+ }
72
+
73
+ /**
74
+ * @param string $apiUrl URL (domain) to use as base for request URL.
75
+ * @return \Optile\Request\ListRequest
76
+ */
77
+ public static function getCancelRequest($apiUrl) {
78
+ require_once 'CancelRequest.php';
79
+ $url = rtrim($apiUrl, '/');
80
+ return new CancelRequest($url);
81
+ }
82
+
83
+ /**
84
+ * @param string $apiUrl URL (domain) to use as base for request URL.
85
+ * @return \Optile\Request\PayoutRequest
86
+ */
87
+ public static function getPayoutRequest($apiUrl) {
88
+ require_once 'PayoutRequest.php';
89
+ $url = rtrim($apiUrl, '/');
90
+ return new PayoutRequest($url);
91
+ }
92
+
93
+ /**
94
+ * @param string $url
95
+ * @return \Optile\Request\SimpleRequest
96
+ */
97
+ public static function getSimpleRequest($url) {
98
+ require_once 'SimpleRequest.php';
99
+ return new SimpleRequest($url);
100
+ }
101
+
102
+ /**
103
+ * @param string $component
104
+ * @param string $subcomponent
105
+ * @return \Optile\Request\class
106
+ */
107
+ public static function getComponent($component, $subcomponent='') {
108
+ $filename = ucfirst($component).'.php';
109
+ $class = '\Optile\Request\\'.ucfirst($component) . ucfirst($subcomponent);
110
+
111
+ require_once $filename;
112
+ return new $class();
113
+ }
114
+
115
+ /**
116
+ * @param string $name
117
+ * @param mixed $message
118
+ * @param int $code [optional]
119
+ * @param \Exception $previous [optional]
120
+ * @return \Exception
121
+ */
122
+ public static function getException($name, $message, $code=null, $previous=null) {
123
+ $filename = 'Exception.php';
124
+ $class = '\Optile\Request\\'.ucfirst($name) .'Exception';
125
+
126
+ require_once $filename;
127
+ // if(class_exists($class)){
128
+ // return new $class($message, $code, $previous);
129
+ // }
130
+ // else{
131
+ return new Exception($message, $code, $previous);
132
+ // }
133
+
134
+ }
135
+
136
+ public static function setLogger($logger){
137
+ require_once 'Logger.php';
138
+ Logger::setLogger($logger);
139
+ }
140
+ public static function setCacher($cacher){
141
+ require_once 'Cache.php';
142
+ Cache::setCacher($cacher);
143
+ }
144
+
145
+ }
lib/Optile/Request/SimpleRequest.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
14
+ *
15
+ * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
+ */
19
+
20
+ namespace Optile\Request;
21
+ /**
22
+ * SimpleRequest
23
+ *
24
+ * Generic and most simple request class.
25
+ * In practice used for internal and development purposes (simulating Optile
26
+ * IPN, etc...)
27
+ */
28
+ class SimpleRequest extends Request {
29
+
30
+ /**
31
+ * Do a simple GET request on a URL.
32
+ * @return string Response body
33
+ */
34
+ public function send($method = self::METHOD_GET) {
35
+ return parent::send($method);
36
+ }
37
+
38
+ }
lib/Optile/Response/Entity.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
14
+ *
15
+ * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
+ */
19
+
20
+ namespace Optile\Response;
21
+ /**
22
+ * Entity
23
+ *
24
+ * Preparation for more advanced response entity handling
25
+ */
26
+ abstract class Entity{
27
+
28
+ }
lib/Optile/{Server/Response/OptileInteraction.php → Response/Interaction.php} RENAMED
@@ -1,34 +1,43 @@
1
  <?php
2
  /**
3
- * This file is part of the Optile Payment Connector extension.
4
- *
5
- * Optile Payment Connector is free software: you can redistribute it and/or
6
- * modify it under the terms of the GNU General Public License as published
7
- * by the Free Software Foundation, either version 3 of the License, or
8
- * (at your option) any later version.
9
- *
10
- * Optile Payment Connector is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License along with
16
- * Optile Payment Connector. If not, see <http://www.gnu.org/licenses/>.
17
  *
18
  * @author i-Ways <dev@i-ways.hr>
19
- * @copyright Copyright (c) 2013 Optile. (http://www.optile.de)
20
- * @license http://www.gnu.org/licenses/gpl.txt
21
  */
22
 
23
- class OptileInteractionCode {
 
 
 
 
 
 
 
 
24
  const PROCEED = "PROCEED";
25
  const ABORT = "ABORT";
26
  const TRY_OTHER_NETWORK = "TRY_OTHER_NETWORK";
27
  const TRY_OTHER_ACCOUNT = "TRY_OTHER_ACCOUNT";
28
  const RETRY = "RETRY";
29
  }
30
-
31
- class OptileInteractionReason{
 
 
 
 
32
  const OK = "OK";
33
  const PENDING = "PENDING";
34
  const FRAUD = "FRAUD";
@@ -47,26 +56,31 @@ class OptileInteractionReason{
47
  const TEMPORARY_FAILURE = "TEMPORARY_FAILURE";
48
  }
49
 
50
- class OptileInteraction extends OptileResponseEntity{
 
 
 
 
 
51
  private $code;
52
  private $reason;
53
-
54
  public function getCode(){
55
  return $this->code;
56
  }
57
-
58
  public function setCode($code){
59
  $this->code = $code;
60
  }
61
-
62
  public function getReason(){
63
  return $this->reason;
64
  }
65
-
66
  public function setReason($reason){
67
  $this->reason = $reason;
68
  }
69
-
70
  public function __construct($code, $reason){
71
  $this->code = $code;
72
  $this->reason = $reason;
1
  <?php
2
  /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
 
 
 
14
  *
15
  * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
  */
19
 
20
+ namespace Optile\Response;
21
+
22
+ require_once 'Entity.php';
23
+ /**
24
+ * InteractionCode
25
+ *
26
+ * Wrapper for managing interaction codes internally.
27
+ */
28
+ class InteractionCode {
29
  const PROCEED = "PROCEED";
30
  const ABORT = "ABORT";
31
  const TRY_OTHER_NETWORK = "TRY_OTHER_NETWORK";
32
  const TRY_OTHER_ACCOUNT = "TRY_OTHER_ACCOUNT";
33
  const RETRY = "RETRY";
34
  }
35
+ /**
36
+ * InteractionReason
37
+ *
38
+ * Wrapper for managing interaction reason codes internally.
39
+ */
40
+ class InteractionReason{
41
  const OK = "OK";
42
  const PENDING = "PENDING";
43
  const FRAUD = "FRAUD";
56
  const TEMPORARY_FAILURE = "TEMPORARY_FAILURE";
57
  }
58
 
59
+ /**
60
+ * Interaction
61
+ *
62
+ * Simple class that defines Interaction response from Optile
63
+ */
64
+ class Interaction extends Entity{
65
  private $code;
66
  private $reason;
67
+
68
  public function getCode(){
69
  return $this->code;
70
  }
71
+
72
  public function setCode($code){
73
  $this->code = $code;
74
  }
75
+
76
  public function getReason(){
77
  return $this->reason;
78
  }
79
+
80
  public function setReason($reason){
81
  $this->reason = $reason;
82
  }
83
+
84
  public function __construct($code, $reason){
85
  $this->code = $code;
86
  $this->reason = $reason;
lib/Optile/Response/Network.php ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
14
+ *
15
+ * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
+ */
19
+
20
+ namespace Optile\Response;
21
+
22
+ require_once 'Entity.php';
23
+ /**
24
+ * Network
25
+ *
26
+ * Simple class that defines Network response from Optile
27
+ */
28
+ class Network extends Entity{
29
+ private $code;
30
+ private $method;
31
+ private $registration;
32
+ private $recurrence;
33
+ private $links;
34
+ private $label;
35
+
36
+ public function getCode(){
37
+ return $this->code;
38
+ }
39
+
40
+ public function setCode($code){
41
+ $this->code = $code;
42
+ }
43
+
44
+ public function getMethod(){
45
+ return $this->method;
46
+ }
47
+
48
+ public function setMethod($method){
49
+ $this->method = $method;
50
+ }
51
+
52
+ public function getRegistration(){
53
+ return $this->registration;
54
+ }
55
+
56
+ public function setRegistration($registration){
57
+ $this->registration = $registration;
58
+ }
59
+
60
+ public function getRecurrence(){
61
+ return $this->recurrence;
62
+ }
63
+
64
+ public function setRecurrence($recurrence){
65
+ $this->recurrence = $recurrence;
66
+ }
67
+
68
+ public function getLinks(){
69
+ return $this->links;
70
+ }
71
+
72
+ public function setLinks($links){
73
+ $this->links = $links;
74
+ }
75
+
76
+ public function getLabel(){
77
+ return $this->label;
78
+ }
79
+
80
+ public function setLabel($label){
81
+ $this->label = $label;
82
+ }
83
+ }
lib/Optile/{Server/Response/OptileNetworkLink.php → Response/NetworkLink.php} RENAMED
@@ -1,26 +1,32 @@
1
  <?php
2
  /**
3
- * This file is part of the Optile Payment Connector extension.
4
- *
5
- * Optile Payment Connector is free software: you can redistribute it and/or
6
- * modify it under the terms of the GNU General Public License as published
7
- * by the Free Software Foundation, either version 3 of the License, or
8
- * (at your option) any later version.
9
- *
10
- * Optile Payment Connector is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License along with
16
- * Optile Payment Connector. If not, see <http://www.gnu.org/licenses/>.
17
  *
18
  * @author i-Ways <dev@i-ways.hr>
19
- * @copyright Copyright (c) 2013 Optile. (http://www.optile.de)
20
- * @license http://www.gnu.org/licenses/gpl.txt
21
  */
22
 
23
- class OptileNetworkLink extends OptileResponseEntity{
 
 
 
 
 
 
 
 
 
24
  private $operation;
25
  private $formLink;
26
  private $logoLink;
@@ -31,83 +37,83 @@ class OptileNetworkLink extends OptileResponseEntity{
31
  private $formHtml;
32
  private $langProperties;
33
  private $localizedFormHtml;
34
-
35
  public function getValidationLink(){
36
  return $this->validationLink;
37
  }
38
-
39
  public function setValidationLink($validationLink){
40
  $this->validationLink = $validationLink;
41
  }
42
-
43
  public function getOperation(){
44
  return $this->operation;
45
  }
46
-
47
  public function setOperation($operation){
48
  $this->operation = $operation;
49
  }
50
-
51
  public function getFormLink(){
52
  return $this->formLink;
53
  }
54
-
55
  public function setFormLink($formLink){
56
  $this->formLink = $formLink;
57
  }
58
-
59
  public function getLogoLink(){
60
  return $this->logoLink;
61
  }
62
-
63
  public function setLogoLink($logoLink){
64
  $this->logoLink = $logoLink;
65
  }
66
-
67
  public function getLangLink(){
68
  return $this->langLink;
69
  }
70
-
71
  public function setLangLink($langLink){
72
  $this->langLink = $langLink;
73
  }
74
-
75
  public function getLocalizedFormLink(){
76
  return $this->localizedFormLink;
77
  }
78
-
79
  public function setLocalizedFormLink($localizedFormLink){
80
  $this->localizedFormLink = $localizedFormLink;
81
  }
82
-
83
  public function getFormHtml(){
84
  return $this->formHtml;
85
  }
86
-
87
  public function setFormHtml($formHtml){
88
  $this->formHtml = $formHtml;
89
  }
90
-
91
  public function getLangProperties(){
92
  return $this->langProperties;
93
  }
94
-
95
  public function setLangProperties($langProperties){
96
  $this->langProperties = $langProperties;
97
  }
98
-
99
  public function getLocalizedFormHtml(){
100
  return $this->localizedFormHtml;
101
  }
102
-
103
  public function setLocalizedFormHtml($localizedFormHtml){
104
  $this->localizedFormHtml = $localizedFormHtml;
105
  }
106
-
107
- public function __construct($operation,
108
  $formLink,
109
- $logoLink,
110
- $langLink,
111
  $localizedFormLink,
112
  $validationLink,
113
  $operationLink){
@@ -118,15 +124,16 @@ class OptileNetworkLink extends OptileResponseEntity{
118
  $this->localizedFormLink = $localizedFormLink;
119
  $this->validationLink = $validationLink;
120
  $this->operationLink = $operationLink;
121
-
122
  $this->formHtml = $this->getContent($this->formLink);
123
  $this->langProperties = $this->getContent($this->langLink);
124
  $this->localizedFormHtml = $this->getContent($this->localizedFormLink);
125
  }
126
-
127
  private function getContent($url){
128
- $request = new OptileConnection();
129
- $response = $request->Get($url);
 
130
  return $response;
131
  }
132
  }
1
  <?php
2
  /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
 
 
 
14
  *
15
  * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
  */
19
 
20
+ namespace Optile\Response;
21
+
22
+ require_once 'Entity.php';
23
+ require_once __DIR__.'/../Request/RequestFactory.php';
24
+ /**
25
+ * NetworkLink
26
+ *
27
+ * Simple class that defines NetworkLink response from Optile
28
+ */
29
+ class NetworkLink extends Entity{
30
  private $operation;
31
  private $formLink;
32
  private $logoLink;
37
  private $formHtml;
38
  private $langProperties;
39
  private $localizedFormHtml;
40
+
41
  public function getValidationLink(){
42
  return $this->validationLink;
43
  }
44
+
45
  public function setValidationLink($validationLink){
46
  $this->validationLink = $validationLink;
47
  }
48
+
49
  public function getOperation(){
50
  return $this->operation;
51
  }
52
+
53
  public function setOperation($operation){
54
  $this->operation = $operation;
55
  }
56
+
57
  public function getFormLink(){
58
  return $this->formLink;
59
  }
60
+
61
  public function setFormLink($formLink){
62
  $this->formLink = $formLink;
63
  }
64
+
65
  public function getLogoLink(){
66
  return $this->logoLink;
67
  }
68
+
69
  public function setLogoLink($logoLink){
70
  $this->logoLink = $logoLink;
71
  }
72
+
73
  public function getLangLink(){
74
  return $this->langLink;
75
  }
76
+
77
  public function setLangLink($langLink){
78
  $this->langLink = $langLink;
79
  }
80
+
81
  public function getLocalizedFormLink(){
82
  return $this->localizedFormLink;
83
  }
84
+
85
  public function setLocalizedFormLink($localizedFormLink){
86
  $this->localizedFormLink = $localizedFormLink;
87
  }
88
+
89
  public function getFormHtml(){
90
  return $this->formHtml;
91
  }
92
+
93
  public function setFormHtml($formHtml){
94
  $this->formHtml = $formHtml;
95
  }
96
+
97
  public function getLangProperties(){
98
  return $this->langProperties;
99
  }
100
+
101
  public function setLangProperties($langProperties){
102
  $this->langProperties = $langProperties;
103
  }
104
+
105
  public function getLocalizedFormHtml(){
106
  return $this->localizedFormHtml;
107
  }
108
+
109
  public function setLocalizedFormHtml($localizedFormHtml){
110
  $this->localizedFormHtml = $localizedFormHtml;
111
  }
112
+
113
+ public function __construct($operation,
114
  $formLink,
115
+ $logoLink,
116
+ $langLink,
117
  $localizedFormLink,
118
  $validationLink,
119
  $operationLink){
124
  $this->localizedFormLink = $localizedFormLink;
125
  $this->validationLink = $validationLink;
126
  $this->operationLink = $operationLink;
127
+
128
  $this->formHtml = $this->getContent($this->formLink);
129
  $this->langProperties = $this->getContent($this->langLink);
130
  $this->localizedFormHtml = $this->getContent($this->localizedFormLink);
131
  }
132
+
133
  private function getContent($url){
134
+ $request = \Optile\Request\RequestFactory::getSimpleRequest($url);
135
+ $request->setUseCache(true);
136
+ $response = $request->send();
137
  return $response;
138
  }
139
  }
lib/Optile/{Server/Response/OptileRedirect.php → Response/Redirect.php} RENAMED
@@ -1,97 +1,108 @@
1
  <?php
2
  /**
3
- * This file is part of the Optile Payment Connector extension.
4
- *
5
- * Optile Payment Connector is free software: you can redistribute it and/or
6
- * modify it under the terms of the GNU General Public License as published
7
- * by the Free Software Foundation, either version 3 of the License, or
8
- * (at your option) any later version.
9
- *
10
- * Optile Payment Connector is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License along with
16
- * Optile Payment Connector. If not, see <http://www.gnu.org/licenses/>.
17
  *
18
  * @author i-Ways <dev@i-ways.hr>
19
- * @copyright Copyright (c) 2013 Optile. (http://www.optile.de)
20
- * @license http://www.gnu.org/licenses/gpl.txt
21
  */
22
 
23
- class OptileRedirectMethod {
 
 
 
 
 
 
 
 
 
24
  const GET = "GET";
25
  const POST = "POST";
26
  }
27
 
28
- class OptileRedirect extends OptileResponseEntity {
 
 
 
 
 
29
  private $url;
30
  private $method;
31
  private $parameters;
32
  private $suppressIFrame;
33
-
34
  public function getUrl(){
35
  return $this->url;
36
  }
37
-
38
  public function setUrl($url){
39
  $this->url = $url;
40
  }
41
-
42
  public function getMethod(){
43
  return $this->method;
44
  }
45
-
46
  public function setMethod($method){
47
  $this->method = $method;
48
  }
49
-
50
  public function getParameters(){
51
  return $this->parameters;
52
  }
53
-
54
  public function setParameters($parameters){
55
  $this->parameters = $parameters;
56
  }
57
-
58
  public function getSuppressIFrame(){
59
  return $this->suppressIFrame;
60
  }
61
-
62
  public function setSuppressIFrame($suppressIFrame){
63
  $this->suppressIFrame = $suppressIFrame;
64
  }
65
-
66
  public function __construct($url, $method, $parameters = array(),$suppressIFrame = false){
67
  $this->url = $url;
68
  $this->method = $method;
69
  $this->parameters = $parameters;
70
  $this->suppressIFrame = $suppressIFrame;
71
  }
72
-
73
  public function Redirect(){
74
-
75
  $url = $this->url;
76
  $parameters = $this->parameters;
77
-
78
  $parameters = array_map(function($item){
79
  return urlencode($item);
80
  }, $parameters);
81
-
82
  if ($parameters!=array()){
83
  $query = array();
84
-
85
  foreach($parameters as $key => $value){
86
  $query="$key=$value";
87
  }
88
-
89
  $query= implode('&', $query);
90
-
91
  $url.='?'.$query;
92
-
93
  }
94
-
95
  header('Location:'.$url);
96
  exit;
97
  }
1
  <?php
2
  /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
 
 
 
14
  *
15
  * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
  */
19
 
20
+ namespace Optile\Response;
21
+
22
+ require_once 'Entity.php';
23
+
24
+ /**
25
+ * RedirectMethod
26
+ *
27
+ * Simple wrapper class for handling RedirectMethod internally
28
+ */
29
+ class RedirectMethod {
30
  const GET = "GET";
31
  const POST = "POST";
32
  }
33
 
34
+ /**
35
+ * Redirect
36
+ *
37
+ * Simple class that defines Redirect response from Optile
38
+ */
39
+ class Redirect extends Entity {
40
  private $url;
41
  private $method;
42
  private $parameters;
43
  private $suppressIFrame;
44
+
45
  public function getUrl(){
46
  return $this->url;
47
  }
48
+
49
  public function setUrl($url){
50
  $this->url = $url;
51
  }
52
+
53
  public function getMethod(){
54
  return $this->method;
55
  }
56
+
57
  public function setMethod($method){
58
  $this->method = $method;
59
  }
60
+
61
  public function getParameters(){
62
  return $this->parameters;
63
  }
64
+
65
  public function setParameters($parameters){
66
  $this->parameters = $parameters;
67
  }
68
+
69
  public function getSuppressIFrame(){
70
  return $this->suppressIFrame;
71
  }
72
+
73
  public function setSuppressIFrame($suppressIFrame){
74
  $this->suppressIFrame = $suppressIFrame;
75
  }
76
+
77
  public function __construct($url, $method, $parameters = array(),$suppressIFrame = false){
78
  $this->url = $url;
79
  $this->method = $method;
80
  $this->parameters = $parameters;
81
  $this->suppressIFrame = $suppressIFrame;
82
  }
83
+
84
  public function Redirect(){
85
+
86
  $url = $this->url;
87
  $parameters = $this->parameters;
88
+
89
  $parameters = array_map(function($item){
90
  return urlencode($item);
91
  }, $parameters);
92
+
93
  if ($parameters!=array()){
94
  $query = array();
95
+
96
  foreach($parameters as $key => $value){
97
  $query="$key=$value";
98
  }
99
+
100
  $query= implode('&', $query);
101
+
102
  $url.='?'.$query;
103
+
104
  }
105
+
106
  header('Location:'.$url);
107
  exit;
108
  }
lib/Optile/Response/Response.php ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
14
+ *
15
+ * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
+ */
19
+
20
+ namespace Optile\Response;
21
+
22
+ require_once 'Entity.php';
23
+
24
+ /**
25
+ * Response
26
+ *
27
+ * Defines standard Optile response structure.
28
+ */
29
+ class Response extends Entity{
30
+
31
+ private $info;
32
+ private $interaction;
33
+ private $links;
34
+ private $networks;
35
+ private $redirect;
36
+
37
+ public function __construct($info,
38
+ $interaction,
39
+ $links = array(),
40
+ $networks = array(),
41
+ $redirect=null){
42
+ $this->setInfo($info);
43
+ $this->setInteraction($interaction);
44
+ $this->setLinks($links);
45
+ $this->setNetworks($networks);
46
+ $this->setRedirect($redirect);
47
+ }
48
+
49
+ public function getInfo(){
50
+ return $this->info;
51
+ }
52
+
53
+ public function setInfo($info){
54
+ $this->info = $info;
55
+ }
56
+
57
+ public function getInteraction(){
58
+ return $this->interaction;
59
+ }
60
+
61
+ public function setInteraction($interaction){
62
+ $this->interaction = $interaction;
63
+ }
64
+
65
+ public function getLinks(){
66
+ return $this->links;
67
+ }
68
+
69
+ public function setLinks($links){
70
+ $this->links = $links;
71
+ }
72
+
73
+ public function getNetworks(){
74
+ return $this->networks;
75
+ }
76
+
77
+ public function setNetworks($networks){
78
+ $this->networks = $networks;
79
+ }
80
+
81
+ public function getRedirect(){
82
+ return $this->redirect;
83
+ }
84
+
85
+ public function setRedirect($redirect){
86
+ $this->redirect = $redirect;
87
+ }
88
+ }
lib/Optile/Response/ResponseFactory.php ADDED
@@ -0,0 +1,157 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright optile GmbH 2013
4
+ * Licensed under the Software License Agreement in effect between optile and
5
+ * Licensee/user (the "License"); you may not use this file except in compliance
6
+ * with the License. You may obtain a copy of the License at
7
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
8
+ * copy has been provided to you for your records. Unless required by applicable
9
+ * law or agreed to in writing or otherwise stipulated in the License, software
10
+ * distributed under the License is distributed on an "as is” basis without
11
+ * warranties or conditions of any kind, either express or implied. See the
12
+ * License for the specific language governing permissions and limitations under
13
+ * the License.
14
+ *
15
+ * @author i-Ways <dev@i-ways.hr>
16
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
17
+ * @license http://www.optile.de/software-license-agreement
18
+ */
19
+
20
+ namespace Optile\Response;
21
+
22
+ require_once 'Interaction.php';
23
+ require_once 'Network.php';
24
+ require_once 'NetworkLink.php';
25
+ require_once 'Redirect.php';
26
+ require_once 'Response.php';
27
+
28
+ /**
29
+ * ResponseFactory
30
+ *
31
+ * Factory class that is being used to instantiate response objects. For usage
32
+ * example, please refer to ListRequest::send() method.
33
+ */
34
+ class ResponseFactory {
35
+
36
+ /**
37
+ * Receives json encoded data and maps the response as object instances.
38
+ *
39
+ * @param string $data
40
+ * @return Response
41
+ */
42
+ public function BuildOptileResponse($data) {
43
+ $structure = json_decode($data,true);
44
+
45
+ $interaction = $this->buildInteraction($structure);
46
+ $networks = $this->buildNetworks($structure);
47
+ $redirect = $this->buildRedirect($structure);
48
+
49
+ $links = array_key_exists('links', $structure) ? $structure['links'] : array();
50
+
51
+ $response = new Response($structure['resultInfo'],
52
+ $interaction,
53
+ $links,
54
+ $networks,
55
+ $redirect
56
+ );
57
+
58
+ return $response;
59
+ }
60
+
61
+ /**
62
+ * Maps the Interaction response to Interaction object
63
+ *
64
+ * @param array $structure
65
+ * @return Interaction
66
+ */
67
+ private function buildInteraction($structure) {
68
+ $interaction = new Interaction($structure['interaction']['code'],
69
+ $structure['interaction']['reason']);
70
+ return $interaction;
71
+ }
72
+
73
+ /**
74
+ * Maps the Networks response to Newtork object
75
+ *
76
+ * @param array $structure
77
+ * @return Network
78
+ */
79
+ private function buildNetworks($structure) {
80
+ if(!is_array($structure)){
81
+ return array();
82
+ }
83
+ if (!array_key_exists('networks', $structure))
84
+ return array();
85
+
86
+ if (!array_key_exists('applicable', $structure['networks']))
87
+ return array();
88
+
89
+ $applicable = $structure['networks']['applicable'];
90
+
91
+ $networks = array();
92
+
93
+ foreach($applicable as $network){
94
+
95
+
96
+ $optileNetwork = new Network();
97
+ if(isset($network['code'])) {
98
+ $optileNetwork->setCode($network['code']);
99
+ }
100
+ if(isset($network['method'])) {
101
+ $optileNetwork->setMethod($network['method']);
102
+ }
103
+ if(isset($network['label'])) {
104
+ $optileNetwork->setLabel($network['label']);
105
+ }
106
+ if(isset($network['registration'])) {
107
+ $optileNetwork->setRegistration($network['registration']);
108
+ }
109
+ if(isset($network['recurrence'])) {
110
+ $optileNetwork->setRecurrence($network['recurrence']);
111
+ }
112
+
113
+ $optileLink = new NetworkLink($network['links']['operation'],
114
+ $network['links']['form'],
115
+ $network['links']['logo'],
116
+ $network['links']['lang'],
117
+ $network['links']['localizedForm'],
118
+ $network['links']['validation'],
119
+ $network['links']['operation']);
120
+
121
+ $optileNetwork->setLinks($optileLink);
122
+
123
+ $networks[$optileNetwork->getMethod()][]= $optileNetwork;
124
+
125
+ }
126
+
127
+ return $networks;
128
+ }
129
+
130
+ /**
131
+ * Maps the Redirect response to Redirect object
132
+ *
133
+ * @param type $structure
134
+ * @return Redirect
135
+ */
136
+ private function buildRedirect($structure) {
137
+ if (!array_key_exists('redirect', $structure))
138
+ return null;
139
+
140
+
141
+ $parameters = array();
142
+
143
+ if (array_key_exists('parameters',$structure['redirect']) && $structure['redirect']['parameters']!=array()){
144
+ foreach ($structure['redirect']['parameters'] as $name => $value)
145
+ $parameters[$name]=$value;
146
+ }
147
+
148
+ $redirect = new Redirect($structure['redirect']['url'],
149
+ $structure['redirect']['method'],
150
+ $parameters,
151
+ $structure['redirect']['suppressIFrame']
152
+ );
153
+
154
+ return $redirect;
155
+ }
156
+
157
+ }
lib/Optile/Server/Request/Entity.php DELETED
@@ -1,23 +0,0 @@
1
- <?php
2
- /**
3
- * This file is part of the Optile Payment Connector extension.
4
- *
5
- * Optile Payment Connector is free software: you can redistribute it and/or
6
- * modify it under the terms of the GNU General Public License as published
7
- * by the Free Software Foundation, either version 3 of the License, or
8
- * (at your option) any later version.
9
- *
10
- * Optile Payment Connector is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License along with
16
- * Optile Payment Connector. If not, see <http://www.gnu.org/licenses/>.
17
- *
18
- * @author i-Ways <dev@i-ways.hr>
19
- * @copyright Copyright (c) 2013 Optile. (http://www.optile.de)
20
- * @license http://www.gnu.org/licenses/gpl.txt
21
- */
22
-
23
- abstract class Entity extends Validator {}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/Optile/Server/Request/OptileAccount.php DELETED
@@ -1,157 +0,0 @@
1
- <?php
2
- /**
3
- * This file is part of the Optile Payment Connector extension.
4
- *
5
- * Optile Payment Connector is free software: you can redistribute it and/or
6
- * modify it under the terms of the GNU General Public License as published
7
- * by the Free Software Foundation, either version 3 of the License, or
8
- * (at your option) any later version.
9
- *
10
- * Optile Payment Connector is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License along with
16
- * Optile Payment Connector. If not, see <http://www.gnu.org/licenses/>.
17
- *
18
- * @author i-Ways <dev@i-ways.hr>
19
- * @copyright Copyright (c) 2013 Optile. (http://www.optile.de)
20
- * @license http://www.gnu.org/licenses/gpl.txt
21
- */
22
-
23
- class OptileAccount extends Entity {
24
-
25
- private $holderName;
26
- private $number;
27
- private $bankCode;
28
- private $bankName;
29
- private $city;
30
- private $bic;
31
- private $branch;
32
- private $expiryMonth;
33
- private $expiryYear;
34
- private $iban;
35
- private $login;
36
- private $optIn;
37
- private $password;
38
- private $verificationCode;
39
-
40
- public function getHolderName(){
41
- return $this->holderName;
42
- }
43
-
44
- public function setHolderName($holderName){
45
- $this->holderName = $holderName;
46
- }
47
-
48
- public function getNumber(){
49
- return $this->number;
50
- }
51
-
52
- public function setNumber($number){
53
- $this->number = $number;
54
- }
55
-
56
- public function getBankCode(){
57
- return $this->bankCode;
58
- }
59
-
60
- public function setBankCode($bankCode){
61
- $this->bankCode = $bankCode;
62
- }
63
-
64
- public function getBankName(){
65
- return $this->bankName;
66
- }
67
-
68
- public function setBankName($bankName){
69
- $this->bankName = $bankName;
70
- }
71
-
72
- public function getCity(){
73
- return $this->city;
74
- }
75
-
76
- public function setCity($city){
77
- $this->city = $city;
78
- }
79
-
80
- public function getBic(){
81
- return $this->bic;
82
- }
83
-
84
- public function setBic($bic){
85
- $this->bic = $bic;
86
- }
87
-
88
- public function getBranch(){
89
- return $this->branch;
90
- }
91
-
92
- public function setBranch($branch){
93
- $this->branch = $branch;
94
- }
95
-
96
- public function getExpiryMonth(){
97
- return $this->expiryMonth;
98
- }
99
-
100
- public function setExpiryMonth($expiryMonth){
101
- $this->expiryMonth = $expiryMonth;
102
- }
103
-
104
- public function getExpiryYear(){
105
- return $this->expiryYear;
106
- }
107
-
108
- public function setExpiryYear($expiryYear){
109
- $this->expiryYear = $expiryYear;
110
- }
111
-
112
- public function getIban(){
113
- return $this->iban;
114
- }
115
-
116
- public function setIban($iban){
117
- $this->iban = $iban;
118
- }
119
-
120
- public function getLogin(){
121
- return $this->login;
122
- }
123
-
124
- public function setLogin($login){
125
- $this->login = $login;
126
- }
127
-
128
- public function getOptIn(){
129
- return $this->optIn;
130
- }
131
-
132
- public function setOptIn($optIn){
133
- $this->optIn = $optIn;
134
- }
135
-
136
- public function getPassword(){
137
- return $this->password;
138
- }
139
-
140
- public function setPassword($password){
141
- $this->password = $password;
142
- }
143
-
144
- public function getVerificationCode(){
145
- return $this->verificationCode;
146
- }
147
-
148
- public function setVerificationCode($verificationCode){
149
- $this->verificationCode = $verificationCode;
150
- }
151
-
152
- public function Validate(){
153
- return array();
154
- }
155
-
156
-
157
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/Optile/Server/Request/OptileCallback.php DELETED
@@ -1,59 +0,0 @@
1
- <?php
2
- /**
3
- * This file is part of the Optile Payment Connector extension.
4
- *
5
- * Optile Payment Connector is free software: you can redistribute it and/or
6
- * modify it under the terms of the GNU General Public License as published
7
- * by the Free Software Foundation, either version 3 of the License, or
8
- * (at your option) any later version.
9
- *
10
- * Optile Payment Connector is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License along with
16
- * Optile Payment Connector. If not, see <http://www.gnu.org/licenses/>.
17
- *
18
- * @author i-Ways <dev@i-ways.hr>
19
- * @copyright Copyright (c) 2013 Optile. (http://www.optile.de)
20
- * @license http://www.gnu.org/licenses/gpl.txt
21
- */
22
-
23
- class OptileCallback extends Entity {
24
- private $returnUrl = "";
25
- private $cancelUrl = "";
26
- private $notificationUrl = "";
27
-
28
- public function getReturnUrl(){
29
- return $this->returnUrl;
30
- }
31
-
32
- public function setReturnUrl($returnUrl){
33
- $this->returnUrl = $returnUrl;
34
- }
35
-
36
- public function getCancelUrl(){
37
- return $this->cancelUrl;
38
- }
39
-
40
- public function setCancelUrl($cancelUrl){
41
- $this->cancelUrl = $cancelUrl;
42
- }
43
-
44
- public function getNotificationUrl(){
45
- return $this->notificationUrl;
46
- }
47
-
48
- public function setNotificationUrl($notificationUrl){
49
- $this->notificationUrl = $notificationUrl;
50
- }
51
-
52
- public function Validate(){
53
- $result = array();
54
- $this->validateRequired($this->getReturnUrl(), "ReturnURL", $result);
55
- $this->validateRequired($this->getCancelUrl(), "CancelURL", $result);
56
- $this->validateRequired($this->getNotificationUrl(), "NotificationURL", $result);
57
- return $result;
58
- }
59
- };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/Optile/Server/Request/OptileChargeRequest.php DELETED
@@ -1,81 +0,0 @@
1
- <?php
2
- /**
3
- * This file is part of the Optile Payment Connector extension.
4
- *
5
- * Optile Payment Connector is free software: you can redistribute it and/or
6
- * modify it under the terms of the GNU General Public License as published
7
- * by the Free Software Foundation, either version 3 of the License, or
8
- * (at your option) any later version.
9
- *
10
- * Optile Payment Connector is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License along with
16
- * Optile Payment Connector. If not, see <http://www.gnu.org/licenses/>.
17
- *
18
- * @author i-Ways <dev@i-ways.hr>
19
- * @copyright Copyright (c) 2013 Optile. (http://www.optile.de)
20
- * @license http://www.gnu.org/licenses/gpl.txt
21
- */
22
-
23
- class OptileChargeRequest extends OptileRequest {
24
- protected function buildPOSTRequest(){
25
- $result = array();
26
-
27
- $account = $this->getAccount();
28
-
29
- if (strlen("".$account->getBankCode())!=0)
30
- $result['account.bankCode'] = $account->getBankCode();
31
-
32
- if (strlen("".$account->getBankName())!=0)
33
- $result['account.bankName'] = $account->getBankName();
34
-
35
- if (strlen("".$account->getBic())!=0)
36
- $result['account.bic'] = $account->getBic();
37
-
38
- if (strlen("".$account->getBranch())!=0)
39
- $result['account.branch'] = $account->getBranch();
40
-
41
- if (strlen("".$account->getCity())!=0)
42
- $result['account.city'] = $account->getCity();
43
-
44
- if (strlen("".$account->getExpiryMonth())!=0)
45
- $result['account.expiryMonth'] = $account->getExpiryMonth();
46
-
47
- if (strlen("".$account->getExpiryYear())!=0)
48
- $result['account.expiryYear'] = $account->getExpiryYear();
49
-
50
- if (strlen("".$account->getHolderName())!=0)
51
- $result['account.holderName'] = $account->getHolderName();
52
-
53
- if (strlen("".$account->getLogin())!=0)
54
- $result['account.login'] = $account->getLogin();
55
-
56
- if (strlen("".$account->getNumber())!=0)
57
- $result['account.number'] = $account->getNumber();
58
-
59
- if (strlen("".$account->getOptIn())!=0)
60
- $result['account.optIn'] = $account->getOptIn();
61
-
62
- if (strlen("".$account->getPassword())!=0)
63
- $result['account.password'] = $account->getPassword();
64
-
65
- if (strlen("".$account->getVerificationCode())!=0)
66
- $result['account.verificationCode'] = $account->getVerificationCode();
67
-
68
-
69
- return $result;
70
-
71
-
72
- }
73
-
74
- public function Validate(){
75
- $result = array();
76
-
77
- $this->validateRequired($this->getAccount(), "Account", $result);
78
-
79
- return $result;
80
- }
81
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/Optile/Server/Request/OptileConnection.php DELETED
@@ -1,120 +0,0 @@
1
- <?php
2
- /**
3
- * This file is part of the Optile Payment Connector extension.
4
- *
5
- * Optile Payment Connector is free software: you can redistribute it and/or
6
- * modify it under the terms of the GNU General Public License as published
7
- * by the Free Software Foundation, either version 3 of the License, or
8
- * (at your option) any later version.
9
- *
10
- * Optile Payment Connector is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License along with
16
- * Optile Payment Connector. If not, see <http://www.gnu.org/licenses/>.
17
- *
18
- * @author i-Ways <dev@i-ways.hr>
19
- * @copyright Copyright (c) 2013 Optile. (http://www.optile.de)
20
- * @license http://www.gnu.org/licenses/gpl.txt
21
- */
22
-
23
- class OptileConnection{
24
- public function Get($url,$parameters = array(), $merchantCode = null, $merchantToken = null){
25
-
26
- $parameters = array_map(function($item){
27
- return urlencode($item);
28
- }, $parameters);
29
-
30
- $ch = curl_init();
31
-
32
- if ($parameters!=array()){
33
- $query = array();
34
-
35
- foreach($parameters as $key => $value){
36
- $query[]="$key=$value";
37
- }
38
-
39
- $query= implode('&', $query);
40
-
41
- $url.='?'.$query;
42
-
43
- }
44
-
45
- curl_setopt($ch, CURLOPT_URL, $url);
46
- curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
47
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
48
-
49
- if(isset($merchantCode, $merchantToken))
50
- curl_setopt($ch, CURLOPT_USERPWD, $merchantCode.'/'.$merchantToken);
51
-
52
- $result = curl_exec($ch);
53
-
54
- curl_close($ch);
55
-
56
- if (strlen($result)==0)
57
- return "";
58
-
59
- $parts = explode("\r\n", $result);
60
- $result = $parts[(count($parts)-1)];
61
-
62
- return $result;
63
- }
64
-
65
- public function GetResponse($url, $fields, $merchantCode = null, $merchantToken = null){
66
- $fieldsEncoded = array();
67
-
68
- foreach($fields as $key => $value){
69
- if (!is_array($value)){
70
- $fieldsEncoded[]=$key."=".urlencode($value);
71
- continue;
72
- }
73
-
74
-
75
- $this->encodeFieldsArray($key, $value, $fieldsEncoded);
76
- }
77
-
78
- $serializedFields = implode('&', $fieldsEncoded);
79
-
80
- $ch = curl_init();
81
- curl_setopt($ch, CURLOPT_URL, $url);
82
- curl_setopt($ch, CURLOPT_POST, 1);
83
- curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
84
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
85
- curl_setopt($ch, CURLOPT_POSTFIELDS, $serializedFields);
86
- curl_setopt($ch, CURLOPT_HEADER, 1);
87
- curl_setopt($ch, CURLOPT_VERBOSE,0);
88
- curl_setopt($ch, CURLOPT_HTTPHEADER, array(
89
- 'Content-length:'.strlen($serializedFields),
90
- 'Accept:application/vnd.optile.payment.simple-v1+json',
91
- 'Content-type:application/x-www-form-urlencoded'
92
- ));
93
-
94
- if(isset($merchantCode, $merchantToken))
95
- curl_setopt($ch, CURLOPT_USERPWD, $merchantCode.'/'.$merchantToken);
96
-
97
- $result = curl_exec($ch);
98
-
99
- curl_close($ch);
100
-
101
- if (strlen($result)==0)
102
- return "";
103
-
104
- $parts = explode("\r\n", $result);
105
- $result = $parts[(count($parts)-1)];
106
-
107
- return $result;
108
- }
109
-
110
- private function encodeFieldsArray($key, $value, &$fieldsEncoded){
111
- $i = 0;
112
- foreach ($value as $item){
113
-
114
- foreach($item as $fieldName => $fieldValue){
115
- $fieldsEncoded[]=$key."[$i].$fieldName=".urlencode($fieldValue);
116
- }
117
- $i++;
118
- }
119
- }
120
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/Optile/Server/Request/OptileCustomer.php DELETED
@@ -1,51 +0,0 @@
1
- <?php
2
- /**
3
- * This file is part of the Optile Payment Connector extension.
4
- *
5
- * Optile Payment Connector is free software: you can redistribute it and/or
6
- * modify it under the terms of the GNU General Public License as published
7
- * by the Free Software Foundation, either version 3 of the License, or
8
- * (at your option) any later version.
9
- *
10
- * Optile Payment Connector is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License along with
16
- * Optile Payment Connector. If not, see <http://www.gnu.org/licenses/>.
17
- *
18
- * @author i-Ways <dev@i-ways.hr>
19
- * @copyright Copyright (c) 2013 Optile. (http://www.optile.de)
20
- * @license http://www.gnu.org/licenses/gpl.txt
21
- */
22
-
23
- class OptileCustomer extends Entity {
24
- private $number;
25
- private $email;
26
-
27
- public function getNumber(){
28
- return $this->number;
29
- }
30
-
31
- public function setNumber($number){
32
- $this->number = $number;
33
- }
34
-
35
- public function getEmail(){
36
- return $this->email;
37
- }
38
-
39
- public function setEmail($email){
40
- $this->email = $email;
41
- }
42
-
43
- public function Validate(){
44
- $result = array();
45
-
46
- $this->validateRequired($this->getNumber(), "Number", $result);
47
- $this->validateRequired($this->getEmail(), "Email", $result);
48
-
49
- return $result;
50
- }
51
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/Optile/Server/Request/OptileListRequest.php DELETED
@@ -1,125 +0,0 @@
1
- <?php
2
- /**
3
- * This file is part of the Optile Payment Connector extension.
4
- *
5
- * Optile Payment Connector is free software: you can redistribute it and/or
6
- * modify it under the terms of the GNU General Public License as published
7
- * by the Free Software Foundation, either version 3 of the License, or
8
- * (at your option) any later version.
9
- *
10
- * Optile Payment Connector is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License along with
16
- * Optile Payment Connector. If not, see <http://www.gnu.org/licenses/>.
17
- *
18
- * @author i-Ways <dev@i-ways.hr>
19
- * @copyright Copyright (c) 2013 Optile. (http://www.optile.de)
20
- * @license http://www.gnu.org/licenses/gpl.txt
21
- */
22
-
23
- class OptileListRequest extends OptileRequest{
24
-
25
- public function __construct(){
26
- $this->urlSuffix = '/api/lists';
27
- }
28
-
29
- public function Validate(){
30
- $result = array();
31
-
32
- $this->validateRequired($this->getTransactionId(), "TransactionId", $result);
33
- $this->validateRequired($this->getChannel(), "Channel", $result);
34
- $this->validateRequired($this->getCountry(), "Country", $result);
35
- $this->validateRequired($this->getCallback(), "Callback", $result);
36
- $this->validateRequired($this->getCustomer(), "Customer", $result);
37
-
38
- if ($result!=array())
39
- return $result;
40
-
41
- $callBack = $this->getCallback();
42
- $customer = $this->getCustomer();
43
- $payment = $this->getPayment();
44
- $products = $this->getProducts();
45
-
46
- $items = array($callBack,$customer,$payment);
47
-
48
- foreach($items as $item){
49
- if ($item == null)
50
- continue;
51
-
52
- $tempResult = $item->Validate();
53
- $result = array_merge($result,$tempResult);
54
-
55
- }
56
-
57
- foreach($products as $item){
58
- if ($item == null)
59
- continue;
60
-
61
- $tempResult = $item->Validate();
62
- $result = array_merge($result,$tempResult);
63
- }
64
-
65
- return $result;
66
- }
67
-
68
- protected function buildPOSTRequest(){
69
- $result = array();
70
- $result['transactionId']=$this->getTransactionId();
71
- $result['country']=$this->getCountry();
72
- $result['channel']=$this->getChannel();
73
-
74
- $callback = $this->getCallback();
75
-
76
- if ($callback!=null){
77
-
78
- $result['callback.returnUrl']=$callback->getReturnUrl();
79
- $result['callback.cancelUrl']=$callback->getCancelUrl();
80
- $result['callback.notificationUrl'] = $callback->getNotificationUrl();
81
- }
82
-
83
- $customer = $this->getCustomer();
84
-
85
- if ($customer != null){
86
- $result['customer.number'] = $customer->getNumber();
87
- $result['customer.email'] = $customer->getEmail();
88
- }
89
-
90
- $payment = $this->getPayment();
91
-
92
- if ($payment != null){
93
- $result['payment.reference'] = $payment->getReference();
94
- $result['payment.amount'] = $payment->getAmount();
95
- $result['payment.currency'] = $payment->getCurrency();
96
- }
97
-
98
- $products = $this->getProducts();
99
-
100
- if ($products != array()){
101
- $this->buildProductsPOSTRequest($products, $result);
102
- }
103
-
104
-
105
- return $result;
106
-
107
- }
108
-
109
- private function buildProductsPOSTRequest($products, &$result){
110
- foreach($products as $product){
111
- if ($product == null)
112
- continue;
113
-
114
- $result['products'][]= array(
115
- 'code' => $product->getCode(),
116
- 'name' => $product->getName(),
117
- 'amount' => $product->getAmount(),
118
- 'currency'=> $product->getCurrency()
119
- );
120
- }
121
-
122
-
123
-
124
- }
125
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/Optile/Server/Request/OptilePayment.php DELETED
@@ -1,61 +0,0 @@
1
- <?php
2
- /**
3
- * This file is part of the Optile Payment Connector extension.
4
- *
5
- * Optile Payment Connector is free software: you can redistribute it and/or
6
- * modify it under the terms of the GNU General Public License as published
7
- * by the Free Software Foundation, either version 3 of the License, or
8
- * (at your option) any later version.
9
- *
10
- * Optile Payment Connector is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License along with
16
- * Optile Payment Connector. If not, see <http://www.gnu.org/licenses/>.
17
- *
18
- * @author i-Ways <dev@i-ways.hr>
19
- * @copyright Copyright (c) 2013 Optile. (http://www.optile.de)
20
- * @license http://www.gnu.org/licenses/gpl.txt
21
- */
22
-
23
- class OptilePayment extends Entity {
24
- private $reference;
25
- private $amount;
26
- private $currency;
27
-
28
- public function getReference(){
29
- return $this->reference;
30
- }
31
-
32
- public function setReference($reference){
33
- $this->reference = $reference;
34
- }
35
-
36
- public function getAmount(){
37
- return $this->amount;
38
- }
39
-
40
- public function setAmount($amount){
41
- $this->amount = $amount;
42
- }
43
-
44
- public function getCurrency(){
45
- return $this->currency;
46
- }
47
-
48
- public function setCurrency($currency){
49
- $this->currency = $currency;
50
- }
51
-
52
- public function Validate(){
53
- $result = array();
54
-
55
- $this->validateRequired($this->getAmount(), "Amount", $result);
56
- $this->validateRequired($this->getCurrency(), "Currency", $result);
57
- $this->validateRequired($this->getReference(), "Reference", $result);
58
-
59
- return $result;
60
- }
61
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/Optile/Server/Request/OptileProduct.php DELETED
@@ -1,69 +0,0 @@
1
- <?php
2
- /**
3
- * This file is part of the Optile Payment Connector extension.
4
- *
5
- * Optile Payment Connector is free software: you can redistribute it and/or
6
- * modify it under the terms of the GNU General Public License as published
7
- * by the Free Software Foundation, either version 3 of the License, or
8
- * (at your option) any later version.
9
- *
10
- * Optile Payment Connector is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License along with
16
- * Optile Payment Connector. If not, see <http://www.gnu.org/licenses/>.
17
- *
18
- * @author i-Ways <dev@i-ways.hr>
19
- * @copyright Copyright (c) 2013 Optile. (http://www.optile.de)
20
- * @license http://www.gnu.org/licenses/gpl.txt
21
- */
22
-
23
- class OptileProduct extends Entity {
24
- private $code;
25
- private $name;
26
- private $amount;
27
- private $currency;
28
-
29
- public function getCode(){
30
- return $this->code;
31
- }
32
-
33
- public function setCode($code){
34
- $this->code = $code;
35
- }
36
-
37
- public function getName(){
38
- return $this->name;
39
- }
40
-
41
- public function setName($name){
42
- $this->name = $name;
43
- }
44
-
45
- public function getAmount(){
46
- return $this->amount;
47
- }
48
-
49
- public function setAmount($amount){
50
- $this->amount = $amount;
51
- }
52
-
53
- public function getCurrency(){
54
- return $this->currency;
55
- }
56
-
57
- public function setCurrency($currency){
58
- $this->currency = $currency;
59
- }
60
-
61
- public function Validate(){
62
- $result = array();
63
-
64
- $this->validateRequired($this->getCode(), "Code", $result);
65
- $this->validateRequired($this->getName(), "Name", $result);
66
-
67
- return $result;
68
- }
69
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/Optile/Server/Request/OptileReloadListRequest.php DELETED
@@ -1,53 +0,0 @@
1
- <?php
2
- /**
3
- * This file is part of the Optile Payment Connector extension.
4
- *
5
- * Optile Payment Connector is free software: you can redistribute it and/or
6
- * modify it under the terms of the GNU General Public License as published
7
- * by the Free Software Foundation, either version 3 of the License, or
8
- * (at your option) any later version.
9
- *
10
- * Optile Payment Connector is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License along with
16
- * Optile Payment Connector. If not, see <http://www.gnu.org/licenses/>.
17
- *
18
- * @author i-Ways <dev@i-ways.hr>
19
- * @copyright Copyright (c) 2013 Optile. (http://www.optile.de)
20
- * @license http://www.gnu.org/licenses/gpl.txt
21
- */
22
-
23
- class OptileReloadListRequest extends OptileRequest{
24
-
25
- public function Validate(){
26
- $result = array();
27
- return $result;
28
- }
29
-
30
- public function GetResponse($self) {
31
- if (!$self)
32
- throw new OptileUrlException("Url must be set");
33
- if (strlen($self)==0)
34
- throw new OptileUrlException("Url must be set");
35
-
36
- $url = rtrim($self,"/");
37
-
38
- $connection = new OptileConnection();
39
- $result = $connection->Get($url, array(),
40
- $this->getMerchantCode(),
41
- $this->getMerchantToken());
42
-
43
- if (strlen("".$result)==0)
44
- return null;
45
-
46
- $responseFactory = new OptileResponseFactory();
47
- $response = $responseFactory->BuildOptileResponse($result);
48
-
49
- return $response;
50
- }
51
-
52
- protected function buildPOSTRequest(){ }
53
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/Optile/Server/Request/OptileRequest.php DELETED
@@ -1,173 +0,0 @@
1
- <?php
2
- /**
3
- * This file is part of the Optile Payment Connector extension.
4
- *
5
- * Optile Payment Connector is free software: you can redistribute it and/or
6
- * modify it under the terms of the GNU General Public License as published
7
- * by the Free Software Foundation, either version 3 of the License, or
8
- * (at your option) any later version.
9
- *
10
- * Optile Payment Connector is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License along with
16
- * Optile Payment Connector. If not, see <http://www.gnu.org/licenses/>.
17
- *
18
- * @author i-Ways <dev@i-ways.hr>
19
- * @copyright Copyright (c) 2013 Optile. (http://www.optile.de)
20
- * @license http://www.gnu.org/licenses/gpl.txt
21
- */
22
-
23
- class OptileChannel {
24
- const WEB_ORDER = "WEB_ORDER";
25
- const MOBILE_ORDER = "MOBILE_ORDER";
26
- const EMAIL_ORDER = "EMAIL_ORDER";
27
- const CALLCENTER_ORDER = "CALLCENTER_ORDER";
28
- const MAIL_ORDER = "MAIL_ORDER";
29
- const TERMINAL_ORDER = "TERMINAL_ORDER";
30
- const CUSTOMER_SUPPORT = "CUSTOMER_SUPPORT";
31
- const CUSTOMER_SELF_SERVICE = "CUSTOMER_SELF_SERVICE";
32
- const RECURRING = "RECURRING";
33
- const FULFILLMENT = "FULFILLMENT";
34
- const DUNNING = "DUNNING";
35
- const IMPORT = "IMPORT";
36
- }
37
-
38
- abstract class OptileRequest extends Entity{
39
- private $merchantCode = "";
40
- private $merchantToken = "";
41
- private $transactionId = "";
42
- private $country = "";
43
- private $channel = OptileChannel::WEB_ORDER;
44
- private $callback = null;
45
- private $customer = null;
46
- private $payment = null;
47
- private $products = array();
48
- private $account = null;
49
-
50
- protected $urlSuffix = "";
51
-
52
- public function getAccount() {
53
- return $this->account;
54
- }
55
-
56
- public function setAccount($account){
57
- $this->account = $account;
58
- }
59
-
60
-
61
- public function getMerchantCode(){
62
- return $this->merchantCode;
63
- }
64
-
65
- public function setMerchantCode($merchantCode){
66
- $this->merchantCode = $merchantCode;
67
- }
68
-
69
- public function getMerchantToken(){
70
- return $this->merchantToken;
71
- }
72
-
73
- public function setMerchantToken($merchantToken){
74
- $this->merchantToken = $merchantToken;
75
- }
76
-
77
- public function getTransactionId(){
78
- return $this->transactionId;
79
- }
80
-
81
- public function setTransactionId($transactionId){
82
- $this->transactionId = $transactionId;
83
- }
84
-
85
- public function getCountry(){
86
- return $this->country;
87
- }
88
-
89
- public function setCountry($country){
90
- $this->country = $country;
91
- }
92
-
93
- public function getChannel(){
94
- return $this->channel;
95
- }
96
-
97
- public function setChannel($channel){
98
- $this->channel = $channel;
99
- }
100
-
101
- public function getCallback(){
102
- return $this->callback;
103
- }
104
-
105
- public function setCallback($callback){
106
- $this->callback = $callback;
107
- }
108
-
109
- public function getCustomer(){
110
- return $this->customer;
111
- }
112
-
113
- public function setCustomer($customer){
114
- $this->customer = $customer;
115
- }
116
-
117
- public function getPayment(){
118
- return $this->payment;
119
- }
120
-
121
- public function setPayment($payment){
122
- $this->payment = $payment;
123
- }
124
-
125
- public function getProducts(){
126
- return $this->products;
127
- }
128
-
129
- public function setProducts($products){
130
- $this->products = $products;
131
- }
132
-
133
- public function addProduct(OptileProduct $product){
134
- $this->products[] = $product;
135
- }
136
-
137
-
138
- public function GetResponse($url) {
139
- if (!$url)
140
- throw new OptileUrlException("Url must be set");
141
- if (strlen($url)==0)
142
- throw new OptileUrlException("Url must be set");
143
-
144
- $url = rtrim($url,"/");
145
- $url.=$this->urlSuffix;
146
-
147
-
148
- $validationResult = $this->Validate();
149
-
150
- if ($validationResult != array()){
151
- throw new RequestException($validationResult);
152
- }
153
-
154
- $fields = $this->buildPOSTRequest();
155
-
156
- $connection = new OptileConnection();
157
- $result = $connection->GetResponse($url, $fields,
158
- $this->getMerchantCode(),
159
- $this->getMerchantToken());
160
-
161
-
162
- if (strlen("".$result)==0)
163
- return null;
164
-
165
- $responseFactory = new OptileResponseFactory();
166
- $response = $responseFactory->BuildOptileResponse($result);
167
-
168
- return $response;
169
- }
170
-
171
- protected abstract function buildPOSTRequest();
172
-
173
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/Optile/Server/Request/OptileUrlException.php DELETED
@@ -1,23 +0,0 @@
1
- <?php
2
- /**
3
- * This file is part of the Optile Payment Connector extension.
4
- *
5
- * Optile Payment Connector is free software: you can redistribute it and/or
6
- * modify it under the terms of the GNU General Public License as published
7
- * by the Free Software Foundation, either version 3 of the License, or
8
- * (at your option) any later version.
9
- *
10
- * Optile Payment Connector is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License along with
16
- * Optile Payment Connector. If not, see <http://www.gnu.org/licenses/>.
17
- *
18
- * @author i-Ways <dev@i-ways.hr>
19
- * @copyright Copyright (c) 2013 Optile. (http://www.optile.de)
20
- * @license http://www.gnu.org/licenses/gpl.txt
21
- */
22
-
23
- class OptileUrlException extends Exception{}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/Optile/Server/Request/RequestException.php DELETED
@@ -1,33 +0,0 @@
1
- <?php
2
- /**
3
- * This file is part of the Optile Payment Connector extension.
4
- *
5
- * Optile Payment Connector is free software: you can redistribute it and/or
6
- * modify it under the terms of the GNU General Public License as published
7
- * by the Free Software Foundation, either version 3 of the License, or
8
- * (at your option) any later version.
9
- *
10
- * Optile Payment Connector is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License along with
16
- * Optile Payment Connector. If not, see <http://www.gnu.org/licenses/>.
17
- *
18
- * @author i-Ways <dev@i-ways.hr>
19
- * @copyright Copyright (c) 2013 Optile. (http://www.optile.de)
20
- * @license http://www.gnu.org/licenses/gpl.txt
21
- */
22
-
23
- class RequestException extends Exception{
24
- public function __construct($fields){
25
- $message = "";
26
-
27
- foreach($fields as $name => $value){
28
- $message.=$value."\n\r";
29
- }
30
-
31
- parent::__construct($message);
32
- }
33
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/Optile/Server/Request/Validator.php DELETED
@@ -1,46 +0,0 @@
1
- <?php
2
- /**
3
- * This file is part of the Optile Payment Connector extension.
4
- *
5
- * Optile Payment Connector is free software: you can redistribute it and/or
6
- * modify it under the terms of the GNU General Public License as published
7
- * by the Free Software Foundation, either version 3 of the License, or
8
- * (at your option) any later version.
9
- *
10
- * Optile Payment Connector is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License along with
16
- * Optile Payment Connector. If not, see <http://www.gnu.org/licenses/>.
17
- *
18
- * @author i-Ways <dev@i-ways.hr>
19
- * @copyright Copyright (c) 2013 Optile. (http://www.optile.de)
20
- * @license http://www.gnu.org/licenses/gpl.txt
21
- */
22
-
23
- abstract class Validator{
24
-
25
- /**
26
- * Validates the current object
27
- * @returns array : key - invalid field name,
28
- * value - invalid field name message
29
- */
30
- abstract public function Validate();
31
-
32
- /**
33
- * Checks if a field is required and generates an error message
34
- * @param unknown $value
35
- * @param unknown $name
36
- * @param array $result array
37
- */
38
- protected function validateRequired($value, $name, &$result){
39
- $className = get_class($this);
40
-
41
- if ($value)
42
- return;
43
-
44
- $result[$name]= "$name is Required";
45
- }
46
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/Optile/Server/Response/OptileNetwork.php DELETED
@@ -1,78 +0,0 @@
1
- <?php
2
- /**
3
- * This file is part of the Optile Payment Connector extension.
4
- *
5
- * Optile Payment Connector is free software: you can redistribute it and/or
6
- * modify it under the terms of the GNU General Public License as published
7
- * by the Free Software Foundation, either version 3 of the License, or
8
- * (at your option) any later version.
9
- *
10
- * Optile Payment Connector is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License along with
16
- * Optile Payment Connector. If not, see <http://www.gnu.org/licenses/>.
17
- *
18
- * @author i-Ways <dev@i-ways.hr>
19
- * @copyright Copyright (c) 2013 Optile. (http://www.optile.de)
20
- * @license http://www.gnu.org/licenses/gpl.txt
21
- */
22
-
23
- class OptileNetwork extends OptileResponseEntity{
24
- private $code;
25
- private $method;
26
- private $registration;
27
- private $recurrence;
28
- private $links;
29
- private $label;
30
-
31
- public function getCode(){
32
- return $this->code;
33
- }
34
-
35
- public function setCode($code){
36
- $this->code = $code;
37
- }
38
-
39
- public function getMethod(){
40
- return $this->method;
41
- }
42
-
43
- public function setMethod($method){
44
- $this->method = $method;
45
- }
46
-
47
- public function getRegistration(){
48
- return $this->registration;
49
- }
50
-
51
- public function setRegistration($registration){
52
- $this->registration = $registration;
53
- }
54
-
55
- public function getRecurrence(){
56
- return $this->recurrence;
57
- }
58
-
59
- public function setRecurrence($recurrence){
60
- $this->recurrence = $recurrence;
61
- }
62
-
63
- public function getLinks(){
64
- return $this->links;
65
- }
66
-
67
- public function setLinks($links){
68
- $this->links = $links;
69
- }
70
-
71
- public function getLabel(){
72
- return $this->label;
73
- }
74
-
75
- public function setLabel($label){
76
- $this->label = $label;
77
- }
78
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/Optile/Server/Response/OptileResponse.php DELETED
@@ -1,83 +0,0 @@
1
- <?php
2
- /**
3
- * This file is part of the Optile Payment Connector extension.
4
- *
5
- * Optile Payment Connector is free software: you can redistribute it and/or
6
- * modify it under the terms of the GNU General Public License as published
7
- * by the Free Software Foundation, either version 3 of the License, or
8
- * (at your option) any later version.
9
- *
10
- * Optile Payment Connector is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License along with
16
- * Optile Payment Connector. If not, see <http://www.gnu.org/licenses/>.
17
- *
18
- * @author i-Ways <dev@i-ways.hr>
19
- * @copyright Copyright (c) 2013 Optile. (http://www.optile.de)
20
- * @license http://www.gnu.org/licenses/gpl.txt
21
- */
22
-
23
- class OptileResponse extends OptileResponseEntity{
24
-
25
-
26
- private $info;
27
- private $interaction;
28
- private $links;
29
- private $networks;
30
- private $redirect;
31
-
32
- public function __construct($info,
33
- $interaction,
34
- $links = array(),
35
- $networks = array(),
36
- $redirect=null){
37
- $this->setInfo($info);
38
- $this->setInteraction($interaction);
39
- $this->setLinks($links);
40
- $this->setNetworks($networks);
41
- $this->setRedirect($redirect);
42
- }
43
-
44
- public function getInfo(){
45
- return $this->info;
46
- }
47
-
48
- public function setInfo($info){
49
- $this->info = $info;
50
- }
51
-
52
- public function getInteraction(){
53
- return $this->interaction;
54
- }
55
-
56
- public function setInteraction($interaction){
57
- $this->interaction = $interaction;
58
- }
59
-
60
- public function getLinks(){
61
- return $this->links;
62
- }
63
-
64
- public function setLinks($links){
65
- $this->links = $links;
66
- }
67
-
68
- public function getNetworks(){
69
- return $this->networks;
70
- }
71
-
72
- public function setNetworks($networks){
73
- $this->networks = $networks;
74
- }
75
-
76
- public function getRedirect(){
77
- return $this->redirect;
78
- }
79
-
80
- public function setRedirect($redirect){
81
- $this->redirect = $redirect;
82
- }
83
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/Optile/Server/Response/OptileResponseEntity.php DELETED
@@ -1,25 +0,0 @@
1
- <?php
2
- /**
3
- * This file is part of the Optile Payment Connector extension.
4
- *
5
- * Optile Payment Connector is free software: you can redistribute it and/or
6
- * modify it under the terms of the GNU General Public License as published
7
- * by the Free Software Foundation, either version 3 of the License, or
8
- * (at your option) any later version.
9
- *
10
- * Optile Payment Connector is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License along with
16
- * Optile Payment Connector. If not, see <http://www.gnu.org/licenses/>.
17
- *
18
- * @author i-Ways <dev@i-ways.hr>
19
- * @copyright Copyright (c) 2013 Optile. (http://www.optile.de)
20
- * @license http://www.gnu.org/licenses/gpl.txt
21
- */
22
-
23
- abstract class OptileResponseEntity{
24
-
25
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/Optile/Server/Response/OptileResponseFactory.php DELETED
@@ -1,108 +0,0 @@
1
- <?php
2
- /**
3
- * This file is part of the Optile Payment Connector extension.
4
- *
5
- * Optile Payment Connector is free software: you can redistribute it and/or
6
- * modify it under the terms of the GNU General Public License as published
7
- * by the Free Software Foundation, either version 3 of the License, or
8
- * (at your option) any later version.
9
- *
10
- * Optile Payment Connector is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License along with
16
- * Optile Payment Connector. If not, see <http://www.gnu.org/licenses/>.
17
- *
18
- * @author i-Ways <dev@i-ways.hr>
19
- * @copyright Copyright (c) 2013 Optile. (http://www.optile.de)
20
- * @license http://www.gnu.org/licenses/gpl.txt
21
- */
22
-
23
- class OptileResponseFactory {
24
- public function BuildOptileResponse($data){
25
- $structure = json_decode($data,true);
26
-
27
- $interaction = $this->buildInteraction($structure);
28
- $networks = $this->buildNetworks($structure);
29
- $redirect = $this->buildRedirect($structure);
30
-
31
- $links = array_key_exists('links', $structure) ? $structure['links'] : array();
32
-
33
- $response = new OptileResponse($structure['resultInfo'],
34
- $interaction,
35
- $links,
36
- $networks,
37
- $redirect
38
- );
39
-
40
- return $response;
41
- }
42
-
43
- private function buildInteraction($structure){
44
- $interaction = new OptileInteraction($structure['interaction']['code'],
45
- $structure['interaction']['reason']);
46
- return $interaction;
47
- }
48
-
49
- private function buildNetworks($structure){
50
- if (!array_key_exists('networks', $structure))
51
- return array();
52
-
53
- if (!array_key_exists('applicable', $structure['networks']))
54
- return array();
55
-
56
- $applicable = $structure['networks']['applicable'];
57
-
58
- $networks = array();
59
-
60
- foreach($applicable as $network){
61
-
62
-
63
- $optileNetwork = new OptileNetwork();
64
- $optileNetwork->setCode($network['code']);
65
- $optileNetwork->setMethod($network['method']);
66
- $optileNetwork->setLabel($network['label']);
67
- $optileNetwork->setRegistration($network['registration']);
68
- $optileNetwork->setRecurrence($network['recurrence']);
69
-
70
-
71
- $optileLink = new OptileNetworkLink($network['links']['operation'],
72
- $network['links']['form'],
73
- $network['links']['logo'],
74
- $network['links']['lang'],
75
- $network['links']['localizedForm'],
76
- $network['links']['validation'],
77
- $network['links']['operation']);
78
-
79
- $optileNetwork->setLinks($optileLink);
80
-
81
- $networks[$optileNetwork->getMethod()][]= $optileNetwork;
82
-
83
- }
84
-
85
- return $networks;
86
- }
87
-
88
- private function buildRedirect($structure){
89
- if (!array_key_exists('redirect', $structure))
90
- return null;
91
-
92
-
93
- $parameters = array();
94
-
95
- if (array_key_exists('parameters',$structure['redirect']) && $structure['redirect']['parameters']!=array()){
96
- foreach ($structure['redirect']['parameters'] as $name => $value)
97
- $parameters[$name]=$value;
98
- }
99
-
100
- $redirect = new OptileRedirect($structure['redirect']['url'],
101
- $structure['redirect']['method'],
102
- $parameters,
103
- $structure['redirect']['suppressIFrame']
104
- );
105
-
106
- return $redirect;
107
- }
108
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/Optile/Server/ValidationService.php DELETED
@@ -1,59 +0,0 @@
1
- <?php
2
- /**
3
- * This file is part of the Optile Payment Connector extension.
4
- *
5
- * Optile Payment Connector is free software: you can redistribute it and/or
6
- * modify it under the terms of the GNU General Public License as published
7
- * by the Free Software Foundation, either version 3 of the License, or
8
- * (at your option) any later version.
9
- *
10
- * Optile Payment Connector is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License along with
16
- * Optile Payment Connector. If not, see <http://www.gnu.org/licenses/>.
17
- *
18
- * @author i-Ways <dev@i-ways.hr>
19
- * @copyright Copyright (c) 2013 Optile. (http://www.optile.de)
20
- * @license http://www.gnu.org/licenses/gpl.txt
21
- */
22
-
23
- class ValidationService {
24
- private static $allowed_fields = array(
25
- 'holderName',
26
- 'number',
27
- 'expiryMonth',
28
- 'expiryYear',
29
- 'verificationCode',
30
- 'bankCode',
31
- 'bankName',
32
- 'bic',
33
- 'iban',
34
- 'branch',
35
- 'country',
36
- 'city',
37
- 'login',
38
- 'password'
39
- );
40
-
41
- public static function GetResponse($url, $params = array()) {
42
- if (!$url)
43
- throw new OptileUrlException("Url must be set");
44
- if (strlen($url)==0)
45
- throw new OptileUrlException("Url must be set");
46
-
47
- $fields = array();
48
- foreach($params as $key => $value) {
49
- if(in_array($key, self::$allowed_fields)) {
50
- $fields[$key] = $value;
51
- }
52
- }
53
-
54
- $connection = new OptileConnection();
55
- $result = $connection->GetResponse($url, $fields);
56
-
57
- return $result;
58
- }
59
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/Optile/Server/optile.sdk.lib.inc.php DELETED
@@ -1,46 +0,0 @@
1
- <?php
2
- /**
3
- * This file is part of the Optile Payment Connector extension.
4
- *
5
- * Optile Payment Connector is free software: you can redistribute it and/or
6
- * modify it under the terms of the GNU General Public License as published
7
- * by the Free Software Foundation, either version 3 of the License, or
8
- * (at your option) any later version.
9
- *
10
- * Optile Payment Connector is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License along with
16
- * Optile Payment Connector. If not, see <http://www.gnu.org/licenses/>.
17
- *
18
- * @author i-Ways <dev@i-ways.hr>
19
- * @copyright Copyright (c) 2013 Optile. (http://www.optile.de)
20
- * @license http://www.gnu.org/licenses/gpl.txt
21
- */
22
-
23
- $rootFolder = dirname(__FILE__).'/';
24
-
25
- include_once $rootFolder.'ValidationService.php';
26
- include_once $rootFolder.'Request/Validator.php';
27
- include_once $rootFolder.'Request/Entity.php';
28
- include_once $rootFolder.'Request/OptileAccount.php';
29
- include_once $rootFolder.'Request/OptileUrlException.php';
30
- include_once $rootFolder.'Request/RequestException.php';
31
- include_once $rootFolder.'Request/OptileRequest.php';
32
- include_once $rootFolder.'Request/OptileProduct.php';
33
- include_once $rootFolder.'Request/OptilePayment.php';
34
- include_once $rootFolder.'Request/OptileCustomer.php';
35
- include_once $rootFolder.'Request/OptileCallback.php';
36
- include_once $rootFolder.'Request/OptileConnection.php';
37
- include_once $rootFolder.'Request/OptileListRequest.php';
38
- include_once $rootFolder.'Request/OptileChargeRequest.php';
39
- include_once $rootFolder.'Request/OptileReloadListRequest.php';
40
- include_once $rootFolder.'Response/OptileResponseEntity.php';
41
- include_once $rootFolder.'Response/OptileInteraction.php';
42
- include_once $rootFolder.'Response/OptileNetwork.php';
43
- include_once $rootFolder.'Response/OptileNetworkLink.php';
44
- include_once $rootFolder.'Response/OptileRedirect.php';
45
- include_once $rootFolder.'Response/OptileResponse.php';
46
- include_once $rootFolder.'Response/OptileResponseFactory.php';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
package.xml CHANGED
@@ -1,2 +1,20 @@
1
  <?xml version="1.0"?>
2
- <package><name>Optile_Payment_Connector</name><version>1.0.0</version><stability>stable</stability><license>GPL</license><channel>community</channel><extends></extends><summary>Add the Optile Payment Gateway as a payment method to your Magento store.</summary><description>This extension connects the Optile Payment Gateway (OPG) libraries to Magento, adding OPG as a payment option to the checkout.</description><notes>Release</notes><authors><author><name>Optile</name><user>optile</user><email>tomislav.santek@optile.de</email></author></authors><date>2013-10-03</date><time>14:44:58</time><compatible></compatible><dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies><contents><target name="mage"><dir name="js"><dir name="optile"><file name="checkout.js" hash="f70a41e67e2b59bda9216c3b7bb3b53b"/><file name="jquery.2.0.3.min.js" hash="ccd0edd113b78697e04fb5c1b519a5cd"/><file name="jquery.noconflict.js" hash="09e1d104bcf65bc08906b1a26ad5457f"/><file name="optilevalidation.js" hash="0d314a8934fbe4920fff988596e133ea"/></dir></dir><dir name="app"><dir name="etc"><dir name="modules"><file name="Optile_Payment.xml" hash="571a2fe9c13c22b724d47a2294233a36"/></dir></dir><dir name="code"><dir name="community"><dir name="Optile"><dir name="Payment"><file name="COPYING" hash="8006d9c814277c1bfc4ca22af94b59ee"/><dir name="etc"><file name="config.xml" hash="8529d2b6bce68ab473e29ecbbcfd3d6c"/><file name="system.xml" hash="d450de7961560c229addb511fe937ee0"/></dir><dir name="Model"><file name="Checkout.php" hash="b63efbdff42bce504b260fd4110bf335"/><file name="Notification.php" hash="ea7f2aa4a5845390fedb681d03533ede"/><file name="PaymentMethod.php" hash="bf60ed71473e0758d34f06f07ac46567"/></dir><dir name="Helper"><file name="Data.php" hash="2970adb4ea317e8f6c9e83999ac87497"/></dir><dir name="Block"><file name="List.php" hash="ff596aa0a227d335c69d58f77fcd0c5b"/></dir><dir name="controllers"><file name="NotificationController.php" hash="65f6b7340faa7586299fa5ccca70ea19"/><file name="PaymentController.php" hash="c6851636915a96345aed47ced4c490b1"/></dir></dir></dir></dir></dir><dir name="design"><dir name="frontend"><dir name="base"><dir name="default"><dir name="template"><dir name="optile"><file name="list.phtml" hash="b4a9f18bff209de7d395118636bfc676"/></dir></dir><dir name="layout"><dir name="optile"><file name="payment.xml" hash="fa044565d80889a534a7f0374a4c70e3"/></dir></dir></dir></dir></dir></dir></dir><dir name="lib"><dir name="Optile"><dir name="Server"><file name="ValidationService.php" hash="169cc10de6b542e3aed5c0ee488c6ff9"/><file name="optile.sdk.lib.inc.php" hash="04065b89f98230cef00de7da2abc0680"/><dir name="Request"><file name="Entity.php" hash="bf63639d833946cf80b8d08d363803d7"/><file name="OptileAccount.php" hash="a525f53fdbb5ce997d8c76954b4517a7"/><file name="OptileCallback.php" hash="9048d48664301bd2f022a2deac52e798"/><file name="OptileChargeRequest.php" hash="3a0796b43abc8956c7b275b2c1ed9fb4"/><file name="OptileConnection.php" hash="e5017bd9a6640ab9dc161322f5afd247"/><file name="OptileCustomer.php" hash="fd585b5f23edecf29c08ca73aceb1a9a"/><file name="OptileListRequest.php" hash="ef70360921a6ece23a8c269d27c9df71"/><file name="OptilePayment.php" hash="efe9c1e116c76821845d6f05ee3aaa7f"/><file name="OptileProduct.php" hash="79e6aebc008503e917f7d67820c71bb8"/><file name="OptileReloadListRequest.php" hash="d14bf25e9f961d4487c396c9f4bde711"/><file name="OptileRequest.php" hash="db13bb37525a2de4389491c30fc0865c"/><file name="OptileUrlException.php" hash="30a147e926f2b3991c6cdb516a12a9e3"/><file name="RequestException.php" hash="5b5b267ba179e0e4a4fa2b7f1c429e30"/><file name="Validator.php" hash="460b0fab3276b9fe99f8cd9c9b43dec3"/></dir><dir name="Response"><file name="OptileInteraction.php" hash="484dd407b7177663bbbb6ef375728840"/><file name="OptileNetwork.php" hash="02123757e0e8990f85003d0edcfad38b"/><file name="OptileNetworkLink.php" hash="6e07c865a511599d374e879481e24e3c"/><file name="OptileRedirect.php" hash="420566a92909092095ba5d19a96e81c0"/><file name="OptileResponse.php" hash="3ad2020d0588649c7f6252e3b1a0c916"/><file name="OptileResponseEntity.php" hash="e0447e412dc10a5cedb4e00c43d64662"/><file name="OptileResponseFactory.php" hash="1ed2ae3dfc92b017a3fb3dfc19ef796d"/></dir></dir><dir name="Client"><file name="optilevalidation.js" hash="f4cd570d28ed81f6d608f45fed308dd0"/></dir></dir></dir></target></contents></package>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  <?xml version="1.0"?>
2
+ <package>
3
+ <name>Optile_Payment_Connector</name>
4
+ <version>1.0.1</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://www.opensource.org/licenses/gpl-license.php">GNU General Public License</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Adds the Optile Payment Gateway as a payment method to your Magento store.</summary>
10
+ <description>A new way to think payments: any method, any provider, one system. Optile is about keeping resources low that you have to allocate to the implementation and administration of payments. You implement a global payments framework only once, and subsequently scale it as your business grows. Combine state-of-the-art, control &amp; optimisation on-line business processes with best-of-breed payment partners and tools. We have introduced an open, scalable and easy-to-use Payments &amp; BI platform to take your business to the next level.&#xD;
11
+ &#xD;
12
+ By installing this extension you add the Optile Payment Gateway as a payment method to your Magento store.</description>
13
+ <notes>Optile Magento Connector v1.0.1</notes>
14
+ <authors><author><name>i-Ways</name><user>extensions</user><email>extensions@i-ways.hr</email></author></authors>
15
+ <date>2016-04-21</date>
16
+ <time>14:34:18</time>
17
+ <contents><target name="magecommunity"><dir name="Optile"><dir name="Payment"><dir name="Block"><dir name="Adminhtml"><dir name="Notification"><file name="Grid.php" hash="d67c674aede171ef0a61c7fc0995cd5a"/><file name="View.php" hash="4ad4ea53598b14df536a55dde40eb594"/></dir><file name="Notification.php" hash="62bdb1f2608294e62e62188f75b9fe61"/><dir name="Order"><dir name="Creditmemo"><dir name="Create"><file name="Items.php" hash="46a03f043c07021cc98d24b4ad329b17"/></dir></dir><file name="Grid.php" hash="7f5629a24c8866ab157b60ee0e9b3210"/><file name="View.php" hash="ffc38b853c95929951185f1c6ee4c486"/></dir><file name="Order.php" hash="0ce3fd8bdd886a4ba47c8b3fe8ee492c"/><dir name="System"><dir name="Config"><dir name="Frontend"><dir name="Instructions"><file name="Textarea.php" hash="b6359101623d6ccc13981f317510be2f"/></dir><file name="Instructions.php" hash="c981f937a4ab755007ac58ecd497cda1"/><file name="Noactivemethods.php" hash="cca3bb02113e7b5142f33f4111ba937b"/></dir></dir></dir><dir name="Widget"><dir name="Grid"><dir name="Column"><dir name="Renderer"><file name="Url.php" hash="3bb467fe31f3569ce47ec1ec6ba3427a"/></dir></dir></dir></dir></dir><file name="Info.php" hash="3be2571f6d1cfb02b1a31a37f7c316a4"/><file name="List.php" hash="bc3880520190460e5a16260b9d7e3884"/></dir><dir name="Helper"><file name="Cache.php" hash="a1a7163f3612219e2077b2e0bd7f54a8"/><file name="Data.php" hash="6820e3f8a31538e0dd2b6f6248b838b8"/></dir><dir name="Model"><file name="Checkout.php" hash="90c895b1529afd04389e43489d1bffae"/><dir name="Mysql4"><dir name="Notification"><file name="Collection.php" hash="0f8e5d5cab6a2542869592fb678888b6"/></dir><file name="Notification.php" hash="25e312f5b10ffb01beb8aab5317926c8"/><dir name="Quote"><file name="Collection.php" hash="78ab441b7f76cfc6a745c49dc26116ba"/></dir><file name="Quote.php" hash="59ff7145b4bf7c688ac4be40e4f239b9"/></dir><file name="Notification.php" hash="be307f2b110b817de1b750dcad14273c"/><file name="Observer.php" hash="2fb2bec273714988d4ee89b2f4e9dfbf"/><dir name="Order"><file name="Payment.php" hash="9695f43762d4c1e9f9f87d259149fa68"/></dir><file name="PaymentMethod.php" hash="08c4836ca857e95ac34a0e9549c89507"/><file name="Quote.php" hash="8df0af8da9b80908292c59695d055407"/><dir name="System"><dir name="Config"><dir name="Backend"><file name="Disablemethods.php" hash="d505987b818685afb89e36789bedb120"/><dir name="Enabledmethods"><file name="Bool.php" hash="4e83bd68c221a4f2cbf3f19cbffc2062"/><file name="Select.php" hash="755653e250f67219e1a6af9f57e24f74"/></dir><file name="Instructions.php" hash="bcb5f6bf1729b8a5e4bc9488ebf2d0bb"/></dir><dir name="Source"><file name="Deferral.php" hash="e011625c18a74d2935f0aa8a5c3ba1f9"/><file name="Enabledmethods.php" hash="582d51bdd816c4ff58b98dc40fcdf029"/><file name="Loglevel.php" hash="e72713cf3e982f44e9c9f17f5969e5d7"/></dir></dir></dir></dir><dir name="controllers"><dir name="Adminhtml"><dir name="Optile"><file name="NotificationController.php" hash="15be1515d72beadf878fde398c11b5aa"/><file name="OrderController.php" hash="7a48e0243e3ea6ac97dc631a5afefc77"/></dir></dir><file name="NotificationController.php" hash="ac5a6aa89a3580b1b4928e9c8efeec31"/><file name="PaymentController.php" hash="952e20c1287b482e60d5c09f87c55b03"/></dir><dir name="etc"><file name="adminhtml.xml" hash="2cfb43269cc4fda040236a36fd79f7ae"/><file name="config.xml" hash="80c1950b643712062d53b26f051c5958"/><file name="system.xml" hash="0df5fdf2a9ea82d7793ea87e1ef1523f"/></dir><dir name="sql"><dir name="optile_setup"><file name="mysql4-install-1.0.0.php" hash="50ae0b0067556158f05f1ce6c72b3ca9"/><file name="mysql4-upgrade-1.0.0-1.0.1.php" hash="9a59f0c042dc2f43ea0b1a3d146a2aa8"/><file name="mysql4-upgrade-1.0.1-1.0.2.php" hash="99a265fe1b4b3f7fa2e2af28cd1a44bc"/><file name="mysql4-upgrade-1.0.2-1.0.3.php" hash="55599e5e356613299803242de2273941"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Optile_Payment.xml" hash="c7dc2f4c13a7f726a6634b4c9c8d8b0d"/></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="optile"><file name="info.phtml" hash="63ebc67d374969660580a65f3cf22085"/><file name="notification_view.phtml" hash="05a85b98e23063f14ed111da7dbae2fa"/></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><dir name="optile"><file name="payment.xml" hash="ca6e8c391734887dd1e3f07335e2092d"/></dir></dir><dir name="template"><dir name="optile"><file name="info.phtml" hash="f5b641ce59755f6fb5bf0d602938b6f8"/><file name="list.phtml" hash="0e2bb973f45362b0722f27e2d9c4e57a"/><file name="list_error.phtml" hash="ef327facb3c4ab7b9adbe18593ece348"/></dir></dir></dir></dir></dir></target><target name="mage"><dir name="js"><dir name="optile"><file name="checkout.js" hash="b763652b273db776d938049b9b875296"/><file name="jquery.2.0.3.min.js" hash="ccd0edd113b78697e04fb5c1b519a5cd"/><file name="jquery.noconflict.js" hash="8abb80eb8acc7fb599a9a9be6e1f3aa2"/><file name="optilevalidation.js" hash="6d97ac3ff142966b3e096894b1e6d2d9"/></dir></dir><dir name="lib"><dir name="Optile"><dir name="Request"><file name="Account.php" hash="58a4ad2c590e0b8749d0bf85038fa738"/><file name="Cache.php" hash="c9850c7b9c8dcebb13dfc887ec864fdf"/><file name="Callback.php" hash="6771c9874bba21aab2edd83810845f8f"/><file name="CancelRequest.php" hash="7bc3e0d6c57a42e1498eebbcea5ff99e"/><file name="ChargeRequest.php" hash="28deed42afdcb21bd811b44748f81222"/><file name="ClientInfo.php" hash="877848a94cdc202f1cf1b03528c57fa5"/><file name="CloseRequest.php" hash="0b8f39879c370563ad43c07ba1db74d2"/><file name="Component.php" hash="603bf2d504f1578ea952e397f5719f95"/><file name="Customer.php" hash="2e66e741b2b7ba857ec32b778a736704"/><file name="Exception.php" hash="1ceed951284b5db8d0f0afd59cd46308"/><file name="ListRequest.php" hash="5e1d843165cb2be6900504e999b0ae4a"/><file name="Logger.php" hash="11f427866d679baa67c20eb82528368c"/><file name="Payment.php" hash="90a204eb27808ca08a0b2aa2fc947b1c"/><file name="PayoutRequest.php" hash="d40c951d20fecf56bf84cb827c0a24c8"/><file name="Preselection.php" hash="b95f03f22e6a62fb179894de98a52d86"/><file name="Product.php" hash="147b2f0297d7f8514c6316e90306e9a7"/><file name="ReloadListRequest.php" hash="1b180a57eabf20b004e32913a14b308e"/><file name="Request.php" hash="0646dee1963a208129cb0e364e58a3e7"/><file name="RequestFactory.php" hash="5983c30e32fbd703b3d601425aabb1cd"/><file name="SimpleRequest.php" hash="c88448b762984d36f0390fe8439ddc52"/></dir><dir name="Response"><file name="Entity.php" hash="30ae19ad1411951efb4ff32a4ec30041"/><file name="Interaction.php" hash="87fee62693b10828c2aa1dd24491b13b"/><file name="Network.php" hash="3423c5d3a47be0bff16839ce9f1a34b2"/><file name="NetworkLink.php" hash="edc01e441207697e31d0eadb7d77e72a"/><file name="Redirect.php" hash="cf0019cd1503abfba0e45ab4759d6b84"/><file name="Response.php" hash="770b8f28adb3d07de84b00660fad3f97"/><file name="ResponseFactory.php" hash="5f3f1126006b6348b390944e1cdf5087"/></dir></dir></dir></target><target name="mageskin"><dir name="frontend"><dir name="base"><dir name="default"><dir name="optile"><dir name="css"><file name="style.css" hash="99aff3792a76f1a366aa8c13e5914bb2"/></dir></dir></dir></dir></dir></target></contents>
18
+ <compatible/>
19
+ <dependencies><required><php><min>5.2.0</min><max>7.0.0</max></php></required></dependencies>
20
+ </package>
skin/frontend/base/default/optile/css/style.css ADDED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * Copyright optile GmbH 2013
3
+ * Licensed under the Software License Agreement in effect between optile and
4
+ * Licensee/user (the "License"); you may not use this file except in compliance
5
+ * with the License. You may obtain a copy of the License at
6
+ * http://www.optile.de/software-license-agreement; in addition, a countersigned
7
+ * copy has been provided to you for your records. Unless required by applicable
8
+ * law or agreed to in writing or otherwise stipulated in the License, software
9
+ * distributed under the License is distributed on an "as is” basis without
10
+ * warranties or conditions of any kind, either express or implied. See the
11
+ * License for the specific language governing permissions and limitations under
12
+ * the License.
13
+ *
14
+ * @author i-Ways <dev@i-ways.hr>
15
+ * @copyright Copyright (c) 2013 optile GmbH. (http://www.optile.de)
16
+ * @license http://www.optile.de/software-license-agreement
17
+ */
18
+ /* Margins for payment form rows */
19
+ #payment_form_optile .row {
20
+ position: relative;
21
+ margin: 10px 35px;
22
+ }
23
+
24
+ #payment_form_optile .row:before,
25
+ #payment_form_optile .row:after {
26
+ content: " "; /* 1 */
27
+ display: table; /* 2 */
28
+ }
29
+ #payment_form_optile .row:after {
30
+ clear: both;
31
+ }
32
+ #payment_form_optile .row .col {
33
+ float: left;
34
+ width: 30%;
35
+ }
36
+ #payment_form_optile .row .col1 {
37
+ float: left;
38
+ width: 25%;
39
+ }
40
+ #payment_form_optile .row .col3 {
41
+ float: left;
42
+ width: 35%;
43
+ margin-left: 10px;
44
+ }
45
+ #payment_form_optile .verificationCode {
46
+ width: 50px;
47
+ }
48
+ #payment_form_optile .row3 .col2 {
49
+ position: relative;
50
+ }
51
+ #payment_form_optile .row3 .col2 .after {
52
+ cursor: pointer;
53
+ background-color: #dbdbdb;
54
+ border: 1px solid #3d3d3d;
55
+ border-radius: 30px 30px 30px 30px;
56
+ color: #3d3d3d;
57
+ display: block;
58
+ font-size: 14px;
59
+ font-weight: bold;
60
+ height: 15px;
61
+ left: 60px;
62
+ line-height: 1;
63
+ padding: 2px;
64
+ position: absolute;
65
+ text-align: center;
66
+ top: 6px;
67
+ width: 15px;
68
+ }
69
+ #payment_form_optile .hint {
70
+ display: none;
71
+ background-color: #ffffff;
72
+ border: 1px solid #cccccc;
73
+ position: absolute;
74
+ -webkit-border-radius: 5px;
75
+ border-radius: 5px;
76
+ padding: 10px;
77
+ top: 31px;
78
+ left: 30%;
79
+ z-index: 10;
80
+ }
81
+ #payment_form_optile .hint:before {
82
+ content: "";
83
+ height: 0;
84
+ position: absolute;
85
+ width: 0;
86
+ border-style: solid;
87
+ border-width: 10px;
88
+ border-color: transparent transparent #dbdbdb transparent;
89
+ top: -20px;
90
+ left: 50px;
91
+ }
92
+ #payment_form_optile .hint:after {
93
+ content: "";
94
+ height: 0;
95
+ position: absolute;
96
+ width: 0;
97
+ border-style: solid;
98
+ border-width: 10px;
99
+ border-color: transparent transparent #ffffff transparent;
100
+ top: -18px;
101
+ left: 50px;
102
+ }
103
+ .optile-error-msg { color: red; display: block;}
104
+ .optile-info-msg { display: none; }
105
+
106
+ /* spacing around optile payment method radio buttons */
107
+ input[id*='optile-selected-network-'] {
108
+ margin: 10px 10px 10px 0px;
109
+ }
110
+
111
+
112
+ /* Vertical spacing between payment methods */
113
+ #payment_form_optile li {
114
+ margin: 0 0 10px 0;
115
+ }
116
+
117
+ /* horizontal spacing between selects */
118
+ #payment_form_optile .select {
119
+ margin: 0 10px 0 0;
120
+ width: auto;
121
+ }
122
+
123
+
124
+ /* spacing around Magento payment method's radio buttons */
125
+ input[id*='p_method_'] {
126
+ margin: 10px 10px 10px 0px;
127
+ }
128
+
129
+ /* bottom margin of the whole Magento payment section */
130
+ dl#checkout-payment-method-load {
131
+ margin: 0 0 15px 0;
132
+ }