Ogone_ePayments - Version 15.06.08

Version Notes

Download this release

Release Info

Developer Michael Lühr
Extension Ogone_ePayments
Version 15.06.08
Comparing to
See all releases


Version 15.06.08

Files changed (215) hide show
  1. app/code/community/Netresearch/OPS/Block/Adminhtml/Customer/Edit/Tab/Alias.php +170 -0
  2. app/code/community/Netresearch/OPS/Block/Adminhtml/Customer/Renderer/State.php +21 -0
  3. app/code/community/Netresearch/OPS/Block/Adminhtml/Kwixo/Shipping/Edit.php +83 -0
  4. app/code/community/Netresearch/OPS/Block/Adminhtml/Kwixocategory/CategoryTree.php +105 -0
  5. app/code/community/Netresearch/OPS/Block/Adminhtml/Kwixocategory/Edit.php +58 -0
  6. app/code/community/Netresearch/OPS/Block/Adminhtml/Kwixocategory/Edit/Form.php +58 -0
  7. app/code/community/Netresearch/OPS/Block/Adminhtml/Sales/Order/Creditmemo/ClosedTransaction/Warning.php +33 -0
  8. app/code/community/Netresearch/OPS/Block/Adminhtml/Sales/Order/Creditmemo/Totals/Checkbox.php +33 -0
  9. app/code/community/Netresearch/OPS/Block/Adminhtml/Sales/Order/Creditmemo/Warning/OpenInvoiceNl.php +13 -0
  10. app/code/community/Netresearch/OPS/Block/Adminhtml/Sales/Order/Invoice/Warning/OpenInvoice.php +15 -0
  11. app/code/community/Netresearch/OPS/Block/Alias/List.php +66 -0
  12. app/code/community/Netresearch/OPS/Block/Form.php +394 -0
  13. app/code/community/Netresearch/OPS/Block/Form/Alias.php +55 -0
  14. app/code/community/Netresearch/OPS/Block/Form/Cc.php +38 -0
  15. app/code/community/Netresearch/OPS/Block/Form/DirectDebit.php +231 -0
  16. app/code/community/Netresearch/OPS/Block/Form/Ideal.php +33 -0
  17. app/code/community/Netresearch/OPS/Block/Form/Kwixo/ApresReception.php +26 -0
  18. app/code/community/Netresearch/OPS/Block/Form/Kwixo/Comptant.php +29 -0
  19. app/code/community/Netresearch/OPS/Block/Form/Kwixo/Credit.php +27 -0
  20. app/code/community/Netresearch/OPS/Block/Form/OpsId.php +17 -0
  21. app/code/community/Netresearch/OPS/Block/Form/Other.php +23 -0
  22. app/code/community/Netresearch/OPS/Block/Frauddetection.php +72 -0
  23. app/code/community/Netresearch/OPS/Block/Info/Alias.php +31 -0
  24. app/code/community/Netresearch/OPS/Block/Info/Cc.php +42 -0
  25. app/code/community/Netresearch/OPS/Block/Info/OpsId.php +42 -0
  26. app/code/community/Netresearch/OPS/Block/Info/Redirect.php +41 -0
  27. app/code/community/Netresearch/OPS/Block/Paypage.php +41 -0
  28. app/code/community/Netresearch/OPS/Block/Placeform.php +150 -0
  29. app/code/community/Netresearch/OPS/Block/Placeform3dsecure.php +42 -0
  30. app/code/community/Netresearch/OPS/Block/RetryPayment.php +49 -0
  31. app/code/community/Netresearch/OPS/Block/System/Config/Form/Field/Brand.php +49 -0
  32. app/code/community/Netresearch/OPS/Block/System/Config/Kwixoconfiguration.php +35 -0
  33. app/code/community/Netresearch/OPS/Block/System/Config/Mode.php +31 -0
  34. app/code/community/Netresearch/OPS/Block/System/Config/Support.php +168 -0
  35. app/code/community/Netresearch/OPS/Controller/Abstract.php +127 -0
  36. app/code/community/Netresearch/OPS/Helper/Alias.php +518 -0
  37. app/code/community/Netresearch/OPS/Helper/Api.php +122 -0
  38. app/code/community/Netresearch/OPS/Helper/Creditcard.php +74 -0
  39. app/code/community/Netresearch/OPS/Helper/Data.php +163 -0
  40. app/code/community/Netresearch/OPS/Helper/DirectDebit.php +317 -0
  41. app/code/community/Netresearch/OPS/Helper/Directlink.php +446 -0
  42. app/code/community/Netresearch/OPS/Helper/Kwixo.php +173 -0
  43. app/code/community/Netresearch/OPS/Helper/Order.php +198 -0
  44. app/code/community/Netresearch/OPS/Helper/Order/Abstract.php +84 -0
  45. app/code/community/Netresearch/OPS/Helper/Order/Capture.php +184 -0
  46. app/code/community/Netresearch/OPS/Helper/Order/Refund.php +305 -0
  47. app/code/community/Netresearch/OPS/Helper/Order/Void.php +52 -0
  48. app/code/community/Netresearch/OPS/Helper/Payment.php +1115 -0
  49. app/code/community/Netresearch/OPS/Helper/Payment/DirectLink/Request.php +329 -0
  50. app/code/community/Netresearch/OPS/Helper/Payment/DirectLink/RequestInterface.php +115 -0
  51. app/code/community/Netresearch/OPS/Helper/Payment/Request.php +574 -0
  52. app/code/community/Netresearch/OPS/Helper/Quote.php +162 -0
  53. app/code/community/Netresearch/OPS/Helper/Validation/Checkout/Step.php +77 -0
  54. app/code/community/Netresearch/OPS/Helper/Validation/Result.php +210 -0
  55. app/code/community/Netresearch/OPS/Helper/Version.php +66 -0
  56. app/code/community/Netresearch/OPS/Model/Alias.php +64 -0
  57. app/code/community/Netresearch/OPS/Model/Alias/State.php +34 -0
  58. app/code/community/Netresearch/OPS/Model/Api/Directlink.php +197 -0
  59. app/code/community/Netresearch/OPS/Model/Backend/Operation/Capture/Additional/OpenInvoiceNl.php +15 -0
  60. app/code/community/Netresearch/OPS/Model/Backend/Operation/Capture/Parameter.php +39 -0
  61. app/code/community/Netresearch/OPS/Model/Backend/Operation/Parameter.php +70 -0
  62. app/code/community/Netresearch/OPS/Model/Backend/Operation/Parameter/Abstract.php +125 -0
  63. app/code/community/Netresearch/OPS/Model/Backend/Operation/Parameter/Additional/Interface.php +11 -0
  64. app/code/community/Netresearch/OPS/Model/Backend/Operation/Parameter/Additional/OpenInvoiceNlAbstract.php +144 -0
  65. app/code/community/Netresearch/OPS/Model/Backend/Operation/Parameter/Interface.php +18 -0
  66. app/code/community/Netresearch/OPS/Model/Backend/Operation/Refund/Additional/OpenInvoiceNl.php +141 -0
  67. app/code/community/Netresearch/OPS/Model/Backend/Operation/Refund/Parameter.php +53 -0
  68. app/code/community/Netresearch/OPS/Model/Config.php +692 -0
  69. app/code/community/Netresearch/OPS/Model/Eci/Values.php +35 -0
  70. app/code/community/Netresearch/OPS/Model/File/Download.php +61 -0
  71. app/code/community/Netresearch/OPS/Model/Kwixo/Category/Mapping.php +56 -0
  72. app/code/community/Netresearch/OPS/Model/Kwixo/Shipping/Setting.php +25 -0
  73. app/code/community/Netresearch/OPS/Model/Mysql4/Alias.php +33 -0
  74. app/code/community/Netresearch/OPS/Model/Mysql4/Alias/Collection.php +29 -0
  75. app/code/community/Netresearch/OPS/Model/Mysql4/Kwixo/Category/Mapping.php +32 -0
  76. app/code/community/Netresearch/OPS/Model/Mysql4/Kwixo/Category/Mapping/Collection.php +28 -0
  77. app/code/community/Netresearch/OPS/Model/Mysql4/Kwixo/Shipping/Setting.php +21 -0
  78. app/code/community/Netresearch/OPS/Model/Mysql4/Kwixo/Shipping/Setting/Collection.php +21 -0
  79. app/code/community/Netresearch/OPS/Model/Observer.php +567 -0
  80. app/code/community/Netresearch/OPS/Model/Payment/Abstract.php +1069 -0
  81. app/code/community/Netresearch/OPS/Model/Payment/Backend/OpsId.php +36 -0
  82. app/code/community/Netresearch/OPS/Model/Payment/BankTransfer.php +46 -0
  83. app/code/community/Netresearch/OPS/Model/Payment/BelfiusDirectNet.php +28 -0
  84. app/code/community/Netresearch/OPS/Model/Payment/CashU.php +22 -0
  85. app/code/community/Netresearch/OPS/Model/Payment/CbcOnline.php +28 -0
  86. app/code/community/Netresearch/OPS/Model/Payment/Cc.php +271 -0
  87. app/code/community/Netresearch/OPS/Model/Payment/ChinaUnionPay.php +70 -0
  88. app/code/community/Netresearch/OPS/Model/Payment/Cod.php +27 -0
  89. app/code/community/Netresearch/OPS/Model/Payment/DirectDebit.php +60 -0
  90. app/code/community/Netresearch/OPS/Model/Payment/DirectEbanking.php +74 -0
  91. app/code/community/Netresearch/OPS/Model/Payment/DirectLink.php +366 -0
  92. app/code/community/Netresearch/OPS/Model/Payment/EDankort.php +28 -0
  93. app/code/community/Netresearch/OPS/Model/Payment/Eps.php +28 -0
  94. app/code/community/Netresearch/OPS/Model/Payment/Features/PaymentEmail.php +101 -0
  95. app/code/community/Netresearch/OPS/Model/Payment/Features/ZeroAmountAuth.php +39 -0
  96. app/code/community/Netresearch/OPS/Model/Payment/FortisPayButton.php +28 -0
  97. app/code/community/Netresearch/OPS/Model/Payment/GiroPay.php +27 -0
  98. app/code/community/Netresearch/OPS/Model/Payment/IDeal.php +85 -0
  99. app/code/community/Netresearch/OPS/Model/Payment/IngHomePay.php +28 -0
  100. app/code/community/Netresearch/OPS/Model/Payment/InterSolve.php +71 -0
  101. app/code/community/Netresearch/OPS/Model/Payment/KbcOnline.php +28 -0
  102. app/code/community/Netresearch/OPS/Model/Payment/Kwixo/Abstract.php +613 -0
  103. app/code/community/Netresearch/OPS/Model/Payment/KwixoApresReception.php +40 -0
  104. app/code/community/Netresearch/OPS/Model/Payment/KwixoComptant.php +41 -0
  105. app/code/community/Netresearch/OPS/Model/Payment/KwixoCredit.php +41 -0
  106. app/code/community/Netresearch/OPS/Model/Payment/MiniTix.php +22 -0
  107. app/code/community/Netresearch/OPS/Model/Payment/Mpass.php +28 -0
  108. app/code/community/Netresearch/OPS/Model/Payment/OpenInvoice/Abstract.php +57 -0
  109. app/code/community/Netresearch/OPS/Model/Payment/OpenInvoiceDe.php +99 -0
  110. app/code/community/Netresearch/OPS/Model/Payment/OpenInvoiceNl.php +150 -0
  111. app/code/community/Netresearch/OPS/Model/Payment/Other.php +32 -0
  112. app/code/community/Netresearch/OPS/Model/Payment/Paypal.php +27 -0
  113. app/code/community/Netresearch/OPS/Model/Payment/Paysafecard.php +22 -0
  114. app/code/community/Netresearch/OPS/Model/Payment/PingPing.php +27 -0
  115. app/code/community/Netresearch/OPS/Model/Payment/PostFinanceEFinance.php +28 -0
  116. app/code/community/Netresearch/OPS/Model/Payment/Tunz.php +27 -0
  117. app/code/community/Netresearch/OPS/Model/Payment/Wallie.php +27 -0
  118. app/code/community/Netresearch/OPS/Model/Source/BankTransfer/Countries.php +61 -0
  119. app/code/community/Netresearch/OPS/Model/Source/Cc/AliasInterfaceEnabledTypes.php +62 -0
  120. app/code/community/Netresearch/OPS/Model/Source/Cc/Types.php +52 -0
  121. app/code/community/Netresearch/OPS/Model/Source/DirectDebit/Countries.php +59 -0
  122. app/code/community/Netresearch/OPS/Model/Source/DirectEbanking/Brands.php +67 -0
  123. app/code/community/Netresearch/OPS/Model/Source/Kwixo/ProductCategories.php +127 -0
  124. app/code/community/Netresearch/OPS/Model/Source/Kwixo/ShipMethodType.php +94 -0
  125. app/code/community/Netresearch/OPS/Model/Source/Mode.php +29 -0
  126. app/code/community/Netresearch/OPS/Model/Source/OrderReference.php +44 -0
  127. app/code/community/Netresearch/OPS/Model/Source/PaymentAction.php +44 -0
  128. app/code/community/Netresearch/OPS/Model/Source/Pmlist.php +45 -0
  129. app/code/community/Netresearch/OPS/Model/Source/Template.php +44 -0
  130. app/code/community/Netresearch/OPS/Model/Status/Feedback.php +33 -0
  131. app/code/community/Netresearch/OPS/Model/Status/Mapping.php +171 -0
  132. app/code/community/Netresearch/OPS/Model/Status/Transition.php +567 -0
  133. app/code/community/Netresearch/OPS/Model/Status/Update.php +338 -0
  134. app/code/community/Netresearch/OPS/Model/System/Config/Backend/Intersolve/Brands.php +60 -0
  135. app/code/community/Netresearch/OPS/Model/Validator/CompositeInterface.php +12 -0
  136. app/code/community/Netresearch/OPS/Model/Validator/Kwixo/Shipping/Setting.php +95 -0
  137. app/code/community/Netresearch/OPS/Model/Validator/Parameter/Factory.php +58 -0
  138. app/code/community/Netresearch/OPS/Model/Validator/Parameter/Length.php +90 -0
  139. app/code/community/Netresearch/OPS/Model/Validator/Parameter/Validator.php +56 -0
  140. app/code/community/Netresearch/OPS/Model/Validator/Payment/DirectDebit.php +250 -0
  141. app/code/community/Netresearch/OPS/Test/Block/Adminhtml/Customer/Renderer/StateTest.php +23 -0
  142. app/code/community/Netresearch/OPS/Test/Block/Adminhtml/Kwixo/Shipping/EditTest.php +81 -0
  143. app/code/community/Netresearch/OPS/Test/Block/Adminhtml/Sales/Order/Creditmemo/Totals/CheckboxTest.php +11 -0
  144. app/code/community/Netresearch/OPS/Test/Block/Adminhtml/Sales/Order/Invoice/Warning/OpenInvoiceTest.php +19 -0
  145. app/code/community/Netresearch/OPS/Test/Block/Alias/ListTest.php +77 -0
  146. app/code/community/Netresearch/OPS/Test/Block/Form/CcTest.php +48 -0
  147. app/code/community/Netresearch/OPS/Test/Block/Form/DirectDebitTest.php +332 -0
  148. app/code/community/Netresearch/OPS/Test/Block/Form/Ideal.php +12 -0
  149. app/code/community/Netresearch/OPS/Test/Block/Form/Kwixo/ApresReceptionTest.php +29 -0
  150. app/code/community/Netresearch/OPS/Test/Block/Form/Kwixo/ComptantTest.php +30 -0
  151. app/code/community/Netresearch/OPS/Test/Block/Form/Kwixo/CreditTest.php +34 -0
  152. app/code/community/Netresearch/OPS/Test/Block/FormTest.php +504 -0
  153. app/code/community/Netresearch/OPS/Test/Block/FormTest/fixtures/.gitkeep +0 -0
  154. app/code/community/Netresearch/OPS/Test/Block/FrauddetectionTest.php +40 -0
  155. app/code/community/Netresearch/OPS/Test/Block/PlaceFormShaTest.php +81 -0
  156. app/code/community/Netresearch/OPS/Test/Block/PlaceformTest.php +74 -0
  157. app/code/community/Netresearch/OPS/Test/Block/System/Config/KwixoconfigurationTest.php +24 -0
  158. app/code/community/Netresearch/OPS/Test/Block/System/Config/ModeTest.php +20 -0
  159. app/code/community/Netresearch/OPS/Test/Controller/Adminhtml/AdminControllerTest.php +80 -0
  160. app/code/community/Netresearch/OPS/Test/Controller/Adminhtml/KwixocategoryControllerTest.php +23 -0
  161. app/code/community/Netresearch/OPS/Test/Controller/Adminhtml/KwixocategoryControllerTest/fixtures/category_mapping.yaml +11 -0
  162. app/code/community/Netresearch/OPS/Test/Controller/Adminhtml/KwixoshippingControllerTest.php +142 -0
  163. app/code/community/Netresearch/OPS/Test/Controller/Adminhtml/KwixoshippingControllerTest/fixtures/shipping_settings.yaml +7 -0
  164. app/code/community/Netresearch/OPS/Test/Controller/Adminhtml/OpsstatusControllerTest.php +71 -0
  165. app/code/community/Netresearch/OPS/Test/Controller/ApiControllerTest.php +165 -0
  166. app/code/community/Netresearch/OPS/Test/Controller/PaymentControllerTest.php +512 -0
  167. app/code/community/Netresearch/OPS/Test/Controller/PaymentControllerTest/fixtures/.gitkeep +0 -0
  168. app/code/community/Netresearch/OPS/Test/Helper/AliasTest.php +700 -0
  169. app/code/community/Netresearch/OPS/Test/Helper/AliasTest/fixtures/.gitkeep +0 -0
  170. app/code/community/Netresearch/OPS/Test/Helper/ApiTest.php +52 -0
  171. app/code/community/Netresearch/OPS/Test/Helper/DataTest.php +91 -0
  172. app/code/community/Netresearch/OPS/Test/Helper/DirectDebitTest.php +500 -0
  173. app/code/community/Netresearch/OPS/Test/Helper/DirectDebitTest/fixtures/.gitkeep +0 -0
  174. app/code/community/Netresearch/OPS/Test/Helper/DirectLinkTest.php +529 -0
  175. app/code/community/Netresearch/OPS/Test/Helper/DirectLinkTest/fixtures/.gitkeep +0 -0
  176. app/code/community/Netresearch/OPS/Test/Helper/KwixoTest.php +132 -0
  177. app/code/community/Netresearch/OPS/Test/Helper/KwixoTest/fixtures/category_mapping.yaml +11 -0
  178. app/code/community/Netresearch/OPS/Test/Helper/Order/CaptureTest.php +82 -0
  179. app/code/community/Netresearch/OPS/Test/Helper/Order/CaptureTest/fixtures/.gitkeep +0 -0
  180. app/code/community/Netresearch/OPS/Test/Helper/Order/RefundTest.php +141 -0
  181. app/code/community/Netresearch/OPS/Test/Helper/Order/RefundTest/fixtures/.gitkeep +0 -0
  182. app/code/community/Netresearch/OPS/Test/Helper/Order/VoidTest.php +24 -0
  183. app/code/community/Netresearch/OPS/Test/Helper/Order/VoidTest/fixtures/.gitkeep +0 -0
  184. app/code/community/Netresearch/OPS/Test/Helper/OrderTest.php +168 -0
  185. app/code/community/Netresearch/OPS/Test/Helper/OrderTest/fixtures/order.yaml +42 -0
  186. app/code/community/Netresearch/OPS/Test/Helper/Payment/DirectLink/RequestTest.php +88 -0
  187. app/code/community/Netresearch/OPS/Test/Helper/Payment/DirectLink/RequestTest/fixtures/.gitkeep +0 -0
  188. app/code/community/Netresearch/OPS/Test/Helper/Payment/RequestTest.php +274 -0
  189. app/code/community/Netresearch/OPS/Test/Helper/PaymentTest.php +815 -0
  190. app/code/community/Netresearch/OPS/Test/Helper/PaymentTest/fixtures/.gitkeep +0 -0
  191. app/code/community/Netresearch/OPS/Test/Helper/QuoteTest.php +185 -0
  192. app/code/community/Netresearch/OPS/Test/Helper/QuoteTest/fixtures/.gitkeep +1 -0
  193. app/code/community/Netresearch/OPS/Test/Helper/Validation/Checkout/StepTest.php +44 -0
  194. app/code/community/Netresearch/OPS/Test/Helper/Validation/ResultTest.php +94 -0
  195. app/code/community/Netresearch/OPS/Test/Helper/Validation/ResultTest/fixtures/quotes.yaml +42 -0
  196. app/code/community/Netresearch/OPS/Test/Helper/VersionTest.php +92 -0
  197. app/code/community/Netresearch/OPS/Test/Model/AliasTest/fixtures/.gitkeep +0 -0
  198. app/code/community/Netresearch/OPS/Test/Model/Api/DirectLinkShaTest.php +44 -0
  199. app/code/community/Netresearch/OPS/Test/Model/Api/DirectLinkTest.php +253 -0
  200. app/code/community/Netresearch/OPS/Test/Model/Backend/Operation/Capture/Additional/OpenInvoiceNlTest.php +305 -0
  201. app/code/community/Netresearch/OPS/Test/Model/Backend/Operation/Capture/ParameterTest.php +56 -0
  202. app/code/community/Netresearch/OPS/Test/Model/Backend/Operation/ParameterTest.php +44 -0
  203. app/code/community/Netresearch/OPS/Test/Model/Backend/Operation/Refund/Additional/OpenInvoiceNlTest.php +232 -0
  204. app/code/community/Netresearch/OPS/Test/Model/Backend/Operation/Refund/ParameterTest.php +84 -0
  205. app/code/community/Netresearch/OPS/Test/Model/ConfigTest.php +522 -0
  206. app/code/community/Netresearch/OPS/Test/Model/File/Download.php +36 -0
  207. app/code/community/Netresearch/OPS/Test/Model/Kwixo/Category/MappingTest.php +28 -0
  208. app/code/community/Netresearch/OPS/Test/Model/Kwixo/Category/MappingTest/fixtures/category_mapping.yaml +11 -0
  209. app/code/community/Netresearch/OPS/Test/Model/Mysql4/Alias/AliasTest.php +8 -0
  210. app/code/community/Netresearch/OPS/Test/Model/Mysql4/AliasTest.php +11 -0
  211. app/code/community/Netresearch/OPS/Test/Model/ObserverTest.php +915 -0
  212. app/code/community/Netresearch/OPS/Test/Model/ObserverTest/fixtures/.gitkeep +0 -0
  213. app/code/community/Netresearch/OPS/Test/Model/Payment/AbstractCaptureTest.php +274 -0
  214. app/code/community/Netresearch/OPS/Test/Model/Payment/AbstractRefundTest.php +221 -0
  215. app/code/community/Netresearch/OPS/Test/Model/Payment/AbstractTest.php +787 -0
app/code/community/Netresearch/OPS/Block/Adminhtml/Customer/Edit/Tab/Alias.php ADDED
@@ -0,0 +1,170 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category OPS
4
+ * @package Netresearch_OPS
5
+ * @author Thomas Birke <thomas.birke@netresearch.de>
6
+ * @author Michael Lühr <michael.luehr@netresearch.de>
7
+ * @copyright Copyright (c) 2012 Netresearch GmbH & Co. KG
8
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
9
+ */
10
+
11
+ /**
12
+ * Netresearch_OPS_Block_Adminhtml_Customer_Edit_Tab_Alias
13
+ *
14
+ * @author Thomas Birke <thomas.birke@netresearch.de>
15
+ * @author Michael Lühr <michael.luehr@netresearch.de>
16
+ * @copyright Copyright (c) 2012 Netresearch GmbH & Co. KG
17
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
+ */
19
+ class Netresearch_OPS_Block_Adminhtml_Customer_Edit_Tab_Alias
20
+ extends Mage_Adminhtml_Block_Widget_Grid
21
+ implements Mage_Adminhtml_Block_Widget_Tab_Interface
22
+ {
23
+ public function _construct()
24
+ {
25
+ parent::_construct();
26
+ $this->setId('customer_edit_tab_ops_alias');
27
+ $this->setUseAjax(true);
28
+ }
29
+
30
+ /**
31
+ * Return Tab label
32
+ *
33
+ * @return string
34
+ */
35
+ public function getTabLabel()
36
+ {
37
+ return $this->__('Payment Information');
38
+ }
39
+
40
+ /**
41
+ * Return Tab label
42
+ *
43
+ * @return string
44
+ */
45
+ public function getTabTitle()
46
+ {
47
+ return $this->__('Payment Information');
48
+ }
49
+
50
+ /**
51
+ * Can show tab in tabs
52
+ *
53
+ * @return boolean
54
+ */
55
+ public function canShowTab()
56
+ {
57
+ $customer = Mage::registry('current_customer');
58
+ return (bool)$customer->getId();
59
+ }
60
+
61
+ /**
62
+ * Tab is hidden
63
+ *
64
+ * @return boolean
65
+ */
66
+ public function isHidden()
67
+ {
68
+ return false;
69
+ }
70
+
71
+ /**
72
+ * Defines after which tab, this tab should be rendered
73
+ *
74
+ * @return string
75
+ */
76
+ public function getAfter()
77
+ {
78
+ return 'orders';
79
+ }
80
+
81
+ /*
82
+ * Retrieves Grid Url
83
+ *
84
+ * @return string
85
+ */
86
+ public function getGridUrl()
87
+ {
88
+ //return $this->getUrl('*/ops/customer', array('_current'=>true));
89
+ }
90
+
91
+ protected function _prepareCollection()
92
+ {
93
+ $customer = Mage::registry('current_customer');
94
+
95
+ $collection = Mage::getModel('ops/alias')
96
+ ->getCollection()
97
+ ->addFieldToFilter('customer_id', $customer->getId());
98
+
99
+ $this->setCollection($collection);
100
+ return parent::_prepareCollection();
101
+ }
102
+
103
+ protected function _prepareColumns()
104
+ {
105
+ $this->addColumn('alias', array(
106
+ 'header' => Mage::helper('ops')->__('Alias'),
107
+ 'align' => 'right',
108
+ 'index' => 'alias',
109
+ ));
110
+
111
+ /*
112
+ $this->addColumn('payment_method', array(
113
+ 'header' => Mage::helper('ops')->__('Brand'),
114
+ 'index' => 'payment_method',
115
+ ));
116
+ */
117
+
118
+ $this->addColumn('brand', array(
119
+ 'header' => Mage::helper('ops')->__('Credit Card Type'),
120
+ 'index' => 'brand',
121
+ ));
122
+
123
+ $this->addColumn('pseudo_account_or_cc_no', array(
124
+ 'header' => Mage::helper('ops')->__('Card Number/Account Number'),
125
+ 'index' => 'pseudo_account_or_cc_no',
126
+ ));
127
+
128
+ $this->addColumn('expiration_date', array(
129
+ 'header' => Mage::helper('ops')->__('Expiration Date'),
130
+ 'index' => 'expiration_date',
131
+ ));
132
+
133
+ $this->addColumn('card_holder', array(
134
+ 'header' => Mage::helper('ops')->__('Card Holder'),
135
+ 'index' => 'card_holder',
136
+ ));
137
+
138
+ $this->addColumn('state', array(
139
+ 'header' => Mage::helper('ops')->__('State'),
140
+ 'index' => 'state',
141
+ 'renderer' => 'Netresearch_OPS_Block_Adminhtml_Customer_Renderer_State',
142
+ ));
143
+
144
+ $this->addColumn('action',
145
+ array(
146
+ 'header' => Mage::helper('ops')->__('Action'),
147
+ 'width' => '100',
148
+ 'type' => 'action',
149
+ 'getter' => 'getId',
150
+ 'actions' => array(
151
+ array(
152
+ 'caption' => Mage::helper('ops')->__('Delete'),
153
+ 'url' => array('base' => 'ops/adminhtml_alias/delete'),
154
+ 'field' => 'id'
155
+ )
156
+ ),
157
+ 'filter' => false,
158
+ 'sortable' => false,
159
+ 'index' => 'stores',
160
+ 'is_system' => true,
161
+ ));
162
+
163
+ return parent::_prepareColumns();
164
+ }
165
+
166
+ public function getRowUrl($row)
167
+ {
168
+ //return $this->getUrl('*/customer/edit', array('id' => $row->getId()));
169
+ }
170
+ }
app/code/community/Netresearch/OPS/Block/Adminhtml/Customer/Renderer/State.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * To change this template, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+
7
+ /**
8
+ * Description of State
9
+ *
10
+ * @author sebastian
11
+ */
12
+ class Netresearch_OPS_Block_Adminhtml_Customer_Renderer_State extends
13
+ Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
14
+ {
15
+
16
+ public function render(Varien_Object $row)
17
+ {
18
+ $value = $row->getData($this->getColumn()->getIndex());
19
+ return Mage::helper('ops')->__($value);
20
+ }
21
+ }
app/code/community/Netresearch/OPS/Block/Adminhtml/Kwixo/Shipping/Edit.php ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Michael Lühr <michael.luehr@netresearch.de>
4
+ * @category Netresearch
5
+ * @package Netresearch_OPS
6
+ * @copyright Copyright (c) 2013 Netresearch GmbH & Co. KG (http://www.netresearch.de)
7
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
8
+ */
9
+
10
+
11
+ class Netresearch_OPS_Block_Adminhtml_Kwixo_Shipping_Edit
12
+ extends Mage_Adminhtml_Block_Widget_Form_Container
13
+ {
14
+
15
+
16
+ private $kwixoShippingModel = null;
17
+
18
+ /**
19
+ * gets the form action url
20
+ *
21
+ * @return string
22
+ */
23
+ public function getFormActionUrl()
24
+ {
25
+ return $this->getUrl('adminhtml/kwixoshipping/save');
26
+ }
27
+
28
+ /**
29
+ * gets the shipping types
30
+ *
31
+ * @return array
32
+ */
33
+ public function getShippingMethods()
34
+ {
35
+ $methods = Mage::getSingleton('shipping/config')->getAllCarriers();
36
+ $options = array();
37
+
38
+ foreach ($methods as $carrierCode => $carrier) {
39
+ if (!$title = Mage::getStoreConfig("carriers/$carrierCode/title")) {
40
+ $title = $carrierCode;
41
+ }
42
+ $values = $this->getValues($carrierCode);
43
+ $options[] = array('code' => $carrierCode, 'label' => $title, 'values' => $values);
44
+ }
45
+
46
+ return $options;
47
+ }
48
+
49
+ /**
50
+ * returns the corresponding shipping method types
51
+ *
52
+ * @return array - the kwxixo Shipping method types
53
+ */
54
+ public function getKwixoShippingTypes()
55
+ {
56
+ return Mage::getModel('ops/source_kwixo_shipMethodType')->toOptionArray();
57
+ }
58
+
59
+ public function getKwixoShippingSettingModel()
60
+ {
61
+ if (null === $this->kwxioShippingModel) {
62
+ $this->kwixoShippingModel = Mage::getModel('ops/kwixo_shipping_setting');
63
+ }
64
+ return $this->kwixoShippingModel;
65
+ }
66
+
67
+
68
+ private function getValues($carrierCode)
69
+ {
70
+ $values = array(
71
+ 'kwixo_shipping_type' => '',
72
+ 'kwixo_shipping_speed' => '',
73
+ 'kwixo_shipping_details' => ''
74
+ );
75
+ if ($this->hasData('postData') && array_key_exists($carrierCode, $this->getData('postData'))) {
76
+ $errorData = $this->getData('postData');
77
+ $values = $errorData[$carrierCode];
78
+ } else {
79
+ $values = $this->getKwixoShippingSettingModel()->load($carrierCode, 'shipping_code')->getData();
80
+ }
81
+ return $values;
82
+ }
83
+ }
app/code/community/Netresearch/OPS/Block/Adminhtml/Kwixocategory/CategoryTree.php ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ <?php
3
+ /**
4
+ * Magento
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * @category Mage
23
+ * @package Netresearch_OPS
24
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
25
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
26
+ */
27
+
28
+ class Netresearch_OPS_Block_Adminhtml_Kwixocategory_CategoryTree
29
+ extends Mage_Adminhtml_Block_Catalog_Category_Tree
30
+ {
31
+
32
+ public function __construct()
33
+ {
34
+ parent::__construct();
35
+ $this->setTemplate('ops/categoriestree.phtml');
36
+ $this->setUseAjax(true);
37
+ $this->_withProductCount = false;
38
+ }
39
+
40
+ public function getSwitchTreeUrl()
41
+ {
42
+ return $this->getUrl("*/*/tree", array('_current' => true, 'store' => null, '_query' => false, 'id' => null, 'parent' => null));
43
+ }
44
+
45
+ public function getNodesUrl()
46
+ {
47
+ return $this->getUrl('adminhtml/catalog_category/jsonTree');
48
+ }
49
+
50
+ public function getEditUrl()
51
+ {
52
+ return $this->getUrl('*/*/edit', array('_current' => true, '_query' => false, 'id' => null, 'parent' => null));
53
+ }
54
+
55
+ protected function _getNodeJson($node, $level = 0)
56
+ {
57
+ $item = array();
58
+ $item['text'] = $this->buildNodeName($node);
59
+ //$rootForStores = in_array($node->getEntityId(), $this->getRootIds());
60
+
61
+ $item['id'] = $node->getId();
62
+ $item['cls'] = 'folder ' . ($node->getIsActive() ? 'active-category' : 'no-active-category');
63
+ $item['store'] = (int) $this->getStore()->getId();
64
+ $item['path'] = $node->getData('path');
65
+ $item['allowDrop'] = false;
66
+ $item['allowDrag'] = false;
67
+ if ((int) $node->getChildrenCount() > 0) {
68
+ $item['children'] = array();
69
+ }
70
+ $isParent = $this->_isParentSelectedCategory($node);
71
+ if ($node->hasChildren()) {
72
+ $item['children'] = array();
73
+ if (!($this->getUseAjax() && $node->getLevel() > 1 && !$isParent)) {
74
+ foreach ($node->getChildren() as $child) {
75
+ $item['children'][] = $this->_getNodeJson($child, $level + 1);
76
+ }
77
+ }
78
+ }
79
+
80
+ if ($isParent || $node->getLevel() < 2) {
81
+ $item['expanded'] = true;
82
+ }
83
+ return $item;
84
+ }
85
+
86
+ protected function _getProductTypeLabel($productTypeId)
87
+ {
88
+ $res = '';
89
+ $types = Mage::getModel('ops/source_kwixo_productCategories')->toOptionArray();
90
+ foreach ($types as $data) {
91
+ if ($data['value'] == $productTypeId) {
92
+ $res = $data['label'];
93
+ break;
94
+ }
95
+ }
96
+ return $res;
97
+ }
98
+
99
+ public function buildNodeName($node)
100
+ {
101
+ $result = $this->htmlEscape($node->getName());
102
+ return $result;
103
+ }
104
+
105
+ }
app/code/community/Netresearch/OPS/Block/Adminhtml/Kwixocategory/Edit.php ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Netresearch_OPS
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ class Netresearch_OPS_Block_Adminhtml_Kwixocategory_Edit
28
+ extends Mage_Adminhtml_Block_Widget_Form_Container
29
+ {
30
+
31
+ public function __construct()
32
+ {
33
+ parent::__construct();
34
+ $this->_objectId = 'id';
35
+ $this->_controller = 'adminhtml_kwixocategory';
36
+ $this->_blockGroup = 'ops';
37
+ $this->_mode = 'edit';
38
+ $this->_updateButton('save', 'label', $this->__('Save'));
39
+ $this->_updateButton('save', 'url', $this->getUrl('*/*/save'));
40
+
41
+ }
42
+
43
+ public function getHeaderText()
44
+ {
45
+ $categoryId = (int) $this->getRequest()->getParam('id');
46
+
47
+ if ($categoryId <= 0) {
48
+ return Mage::helper('ops/data')->__('Categories configuration');
49
+ }
50
+ $category = Mage::getModel('catalog/category')->load($categoryId);
51
+ return Mage::helper('ops/data')->__("Categorie's %s configuration", $category->getName());
52
+ }
53
+
54
+ public function getFormActionUrl()
55
+ {
56
+ return $this->getUrl('*/*/save');
57
+ }
58
+ }
app/code/community/Netresearch/OPS/Block/Adminhtml/Kwixocategory/Edit/Form.php ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Netresearch_OPS_Block_Adminhtml_Kwixocategory_Edit_Form
3
+ extends Mage_Adminhtml_Block_Widget_Form
4
+ {
5
+ protected function _prepareForm()
6
+ {
7
+ $form = new Varien_Data_Form(array(
8
+ 'id' => 'edit_form',
9
+ 'action' => $this->getUrl('*/*/save'),
10
+ 'method' => 'post',
11
+ 'enctype' => 'multipart/form-data'
12
+ ));
13
+
14
+ $categoryId = (int) $this->getRequest()->getParam('id');
15
+ if ($categoryId <= 0) {
16
+ return parent::_prepareForm();
17
+ }
18
+ $kwixoCategoryMapping = Mage::getModel('ops/kwixo_category_mapping')->loadByCategoryId($categoryId);
19
+ $storeId = (int) $this->getRequest()->getParam('store');
20
+
21
+ $fieldset = $form->addFieldset('ops_form', array('legend' => Mage::helper('ops/data')->__('Categories configuration')));
22
+
23
+ $fieldset->addField('storeId', 'hidden', array(
24
+ 'required' => true,
25
+ 'name' => 'storeId',
26
+ 'value' => $storeId,
27
+ ));
28
+
29
+ $fieldset->addField('id', 'hidden', array(
30
+ 'required' => false,
31
+ 'name' => 'id',
32
+ 'value' => $kwixoCategoryMapping->getId(),
33
+ ));
34
+ $fieldset->addField('category_id', 'hidden', array(
35
+ 'required' => true,
36
+ 'name' => 'category_id',
37
+ 'value' => $categoryId,
38
+ ));
39
+
40
+ $fieldset->addField('kwixoCategory_id', 'select', array(
41
+ 'label' => Mage::Helper('ops/data')->__('Kwixo category'),
42
+ 'class' => 'required-entry',
43
+ 'required' => true,
44
+ 'name' => 'kwixoCategory_id',
45
+ 'value' => $kwixoCategoryMapping->getKwixoCategoryId(),
46
+ 'values' => Mage::getModel('ops/source_kwixo_productCategories')->toOptionArray()
47
+ ));
48
+
49
+ $fieldset->addField('applysubcat', 'checkbox', array(
50
+ 'label' => Mage::Helper('ops/data')->__('Apply to sub-categories'),
51
+ 'name' => 'applysubcat'
52
+ ));
53
+
54
+ $form->setUseContainer(true);
55
+ $this->setForm($form);
56
+ return parent::_prepareForm();
57
+ }
58
+ }
app/code/community/Netresearch/OPS/Block/Adminhtml/Sales/Order/Creditmemo/ClosedTransaction/Warning.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category OPS
4
+ * @package Netresearch_OPS
5
+ * @author Michael Lühr <michael.luehr@netresearch.de>
6
+ * @copyright Copyright (c) 2013 Netresearch GmbH & Co. KG
7
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
8
+ */
9
+
10
+ /**
11
+ * Netresearch_OPS_Block_Adminhtml_Sales_Order_Creditmemo_Create_Adjustments_Checkbox
12
+ *
13
+ * @author Michael Lühr <michael.luehr@netresearch.de>
14
+ * @copyright Copyright (c) 2012 Netresearch GmbH & Co. KG
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ class Netresearch_OPS_Block_Adminhtml_Sales_Order_Creditmemo_ClosedTransaction_Warning
19
+ extends Mage_Core_Block_Template
20
+ {
21
+
22
+ /**
23
+ * Internal constructor, that is called from real constructor.
24
+ *
25
+ *
26
+ */
27
+ protected function _construct()
28
+ {
29
+ parent::_construct();
30
+ $this->setTemplate('ops/sales/order/creditmemo/closed-transaction/warning.phtml');
31
+ }
32
+
33
+ }
app/code/community/Netresearch/OPS/Block/Adminhtml/Sales/Order/Creditmemo/Totals/Checkbox.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category OPS
4
+ * @package Netresearch_OPS
5
+ * @author Michael Lühr <michael.luehr@netresearch.de>
6
+ * @copyright Copyright (c) 2013 Netresearch GmbH & Co. KG
7
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
8
+ */
9
+
10
+ /**
11
+ * Netresearch_OPS_Block_Adminhtml_Sales_Order_Creditmemo_Create_Adjustments_Checkbox
12
+ *
13
+ * @author Michael Lühr <michael.luehr@netresearch.de>
14
+ * @copyright Copyright (c) 2012 Netresearch GmbH & Co. KG
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ class Netresearch_OPS_Block_Adminhtml_Sales_Order_Creditmemo_Totals_Checkbox
19
+ extends Mage_Core_Block_Template
20
+ {
21
+
22
+ /**
23
+ * Internal constructor, that is called from real constructor.
24
+ *
25
+ *
26
+ */
27
+ protected function _construct()
28
+ {
29
+ parent::_construct();
30
+ $this->setTemplate('ops/sales/order/creditmemo/totals/checkbox.phtml');
31
+ }
32
+
33
+ }
app/code/community/Netresearch/OPS/Block/Adminhtml/Sales/Order/Creditmemo/Warning/OpenInvoiceNl.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created by PhpStorm.
4
+ * User: paul.siedler
5
+ * Date: 25.09.2014
6
+ * Time: 10:13
7
+ */
8
+
9
+ class Netresearch_OPS_Block_Adminhtml_Sales_Order_Creditmemo_Warning_OpenInvoiceNl
10
+ extends Mage_Core_Block_Template
11
+ {
12
+ protected $_template = 'ops/sales/order/creditmemo/warning/openinvoicenl.phtml';
13
+ }
app/code/community/Netresearch/OPS/Block/Adminhtml/Sales/Order/Invoice/Warning/OpenInvoice.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Michael Lühr <michael.luehr@netresearch.de>
4
+ * @category Netresearch
5
+ * @copyright Copyright (c) 2014 Netresearch GmbH & Co. KG (http://www.netresearch.de)
6
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
7
+ */
8
+
9
+
10
+ class Netresearch_OPS_Block_Adminhtml_Sales_Order_Invoice_Warning_OpenInvoice extends Mage_Core_Block_Template
11
+ {
12
+
13
+ protected $_template = 'ops/sales/order/invoice/warning/open-invoice.phtml';
14
+
15
+ }
app/code/community/Netresearch/OPS/Block/Alias/List.php ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category OPS
4
+ * @package Netresearch_OPS
5
+ * @author Thomas Birke <thomas.birke@netresearch.de>
6
+ * @author Michael Lühr <michael.luehr@netresearch.de>
7
+ * @copyright Copyright (c) 2012 Netresearch GmbH & Co. KG
8
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
9
+ */
10
+
11
+ /**
12
+ * Netresearch_OPS_Block_Alias_List
13
+ *
14
+ * @author Thomas Birke <thomas.birke@netresearch.de>
15
+ * @author Michael Lühr <michael.luehr@netresearch.de>
16
+ * @copyright Copyright (c) 2012 Netresearch GmbH & Co. KG
17
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
+ */
19
+ class Netresearch_OPS_Block_Alias_List
20
+ extends Mage_Core_Block_Template
21
+ {
22
+ public function getAliases()
23
+ {
24
+ $aliases = array();
25
+ $customer = Mage::helper('customer')->getCustomer();
26
+ if (0 < $customer->getId()) {
27
+ $aliasesCollection = Mage::helper('ops/alias')->getAliasesForCustomer($customer->getId());
28
+ foreach ($aliasesCollection as $alias) {
29
+ $aliases[] = $alias;
30
+ }
31
+ }
32
+ return $aliases;
33
+ }
34
+
35
+ /**
36
+ * get human readable name of payment method
37
+ *
38
+ * @param string $methodCode Code of payment method
39
+ * @return string Name of payment method
40
+ */
41
+ public function getMethodName($methodCode)
42
+ {
43
+ $instance = Mage::helper('payment')->getMethodInstance($methodCode);
44
+ if ($instance) {
45
+ return $instance->getTitle();
46
+ }
47
+ }
48
+
49
+ /**
50
+ * retrieves the url for deletion the alias
51
+ *
52
+ * @param $aliasId - the id of the alias
53
+ *
54
+ * @return string - the url for deleting the alias with the given id
55
+ */
56
+ public function getAliasDeleteUrl($aliasId)
57
+ {
58
+ return Mage::getUrl(
59
+ 'ops/customer/deleteAlias/',
60
+ array(
61
+ 'id' => $aliasId,
62
+ '_secure' => Mage::app()->getFrontController()->getRequest()->isSecure()
63
+ )
64
+ );
65
+ }
66
+ }
app/code/community/Netresearch/OPS/Block/Form.php ADDED
@@ -0,0 +1,394 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Netresearch_OPS
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ class Netresearch_OPS_Block_Form extends Mage_Payment_Block_Form_Cc
28
+ {
29
+
30
+ private $aliasDataForCustomer = null;
31
+
32
+ protected $pmLogo = null;
33
+
34
+ protected $fieldMapping = array();
35
+
36
+ protected $config = null;
37
+
38
+ /**
39
+ * Frontend Payment Template
40
+ */
41
+ const FRONTEND_TEMPLATE = 'ops/form.phtml';
42
+
43
+ /**
44
+ * Init OPS payment form
45
+ *
46
+ */
47
+ protected function _construct()
48
+ {
49
+ parent::_construct();
50
+ $this->setTemplate(self::FRONTEND_TEMPLATE);
51
+ }
52
+
53
+ /**
54
+ * get OPS config
55
+ *
56
+ * @return Netresearch_Ops_Model_Config
57
+ */
58
+ public function getConfig()
59
+ {
60
+ if (null === $this->config) {
61
+ $this->config = Mage::getSingleton('ops/config');
62
+ }
63
+
64
+ return $this->config;
65
+ }
66
+
67
+ public function setConfig(Netresearch_OPS_Model_Config $config)
68
+ {
69
+ $this->config = $config;
70
+
71
+ return $this;
72
+ }
73
+
74
+ public function getQuote()
75
+ {
76
+ return Mage::getSingleton('checkout/session')->getQuote();
77
+ }
78
+
79
+ public function getCcBrands()
80
+ {
81
+ return explode(',', $this->getConfig()->getAcceptedCcTypes());
82
+ }
83
+
84
+ public function getDirectDebitCountryIds()
85
+ {
86
+ return explode(',', $this->getConfig()->getDirectDebitCountryIds());
87
+ }
88
+
89
+ public function getBankTransferCountryIds()
90
+ {
91
+ return explode(',', $this->getConfig()->getBankTransferCountryIds());
92
+ }
93
+
94
+ public function getPSPID($storeId = null)
95
+ {
96
+ return Mage::getModel('ops/config')->getPSPID($storeId);
97
+ }
98
+
99
+ public function getAliasAcceptUrl($storeId = null, $admin = false)
100
+ {
101
+ return Mage::getModel('ops/config')->getAliasAcceptUrl($storeId, $admin);
102
+ }
103
+
104
+ public function getAliasExceptionUrl($storeId = null, $admin = false)
105
+ {
106
+ return Mage::getModel('ops/config')->getAliasExceptionUrl($storeId, $admin);
107
+ }
108
+
109
+ public function getAliasGatewayUrl($storeId = null)
110
+ {
111
+ return Mage::getModel('ops/config')->getAliasGatewayUrl($storeId);
112
+ }
113
+
114
+ public function getSaveCcBrandUrl()
115
+ {
116
+ return Mage::getModel('ops/config')->getSaveCcBrandUrl();
117
+ }
118
+
119
+ public function getGenerateHashUrl($storeId = null, $admin = false)
120
+ {
121
+ return Mage::getModel('ops/config')->getGenerateHashUrl($storeId, $admin);
122
+ }
123
+
124
+ public function getCcSaveAliasUrl($storeId = null, $admin = false)
125
+ {
126
+ return Mage::getModel('ops/config')->getCcSaveAliasUrl($storeId, $admin);
127
+ }
128
+
129
+ public function getRegisterDirectDebitPaymentUrl()
130
+ {
131
+ return Mage::getModel('ops/config')->getRegisterDirectDebitPaymentUrl();
132
+ }
133
+
134
+ public function getValidationUrl()
135
+ {
136
+ return Mage::getModel('ops/config')->getValidationUrl();
137
+ }
138
+
139
+ public function getDirectEbankingBrands()
140
+ {
141
+
142
+ return explode(',', $this->getConfig()->getDirectEbankingBrands());
143
+ }
144
+
145
+ /**
146
+ * checks if the 'alias' payment method (!) is available
147
+ * no check for customer has aliases here
148
+ * just a passthrough of the isAvailable of Netresearch_OPS_Model_Payment_Abstract::isAvailable
149
+ *
150
+ * @return boolean
151
+ */
152
+ public function isAliasPMEnabled()
153
+ {
154
+ return Mage::getModel('ops/config')->isAliasManagerEnabled();
155
+ }
156
+
157
+ /**
158
+ *
159
+ * @return array empty or intersolve Vouchers
160
+ */
161
+ public function getInterSolveBrands()
162
+ {
163
+ $brands = array();
164
+ if ($this->getMethodCode() == 'ops_interSolve') {
165
+ $brands = Mage::getModel('ops/config')->getIntersolveBrands();
166
+ }
167
+ return $brands;
168
+ }
169
+
170
+ /**
171
+ * retrieves the alias data for the logged in customer
172
+ *
173
+ * @return array | null - array the alias data or null if the customer
174
+ * is not logged in
175
+ */
176
+ protected function getStoredAliasForCustomer()
177
+ {
178
+ if (Mage::helper('customer/data')->isLoggedIn()
179
+ && Mage::getModel('ops/config')->isAliasManagerEnabled()) {
180
+ $quote = $this->getQuote();
181
+ $alias = Mage::helper('ops/alias')->getAliasesForAddresses(
182
+ $quote->getCustomer()->getId(), $quote->getBillingAddress(),
183
+ $quote->getShippingAddress(), $quote->getStoreId()
184
+ )
185
+ ->addFieldToFilter('state', Netresearch_OPS_Model_Alias_State::ACTIVE)
186
+ ->setOrder('created_at', Varien_Data_Collection::SORT_ORDER_DESC)
187
+ ->getFirstItem();
188
+ $this->aliasDataForCustomer = $alias->getData();
189
+ }
190
+ return $this->aliasDataForCustomer;
191
+ }
192
+
193
+
194
+ /**
195
+ * retrieves single values to given keys from the alias data
196
+ *
197
+ * @param $key - string the key for the alias data
198
+ *
199
+ * @return null | string - null if key is not set in the alias data, otherwise
200
+ * the value for the given key from the alias data
201
+ *
202
+ */
203
+ protected function getStoredAliasDataForCustomer($key)
204
+ {
205
+ $returnValue = null;
206
+ $aliasData = null;
207
+ if (is_null($this->aliasData)) {
208
+ $aliasData = $this->getStoredAliasForCustomer();
209
+ }
210
+ if (is_array($aliasData) && array_key_exists($key, $aliasData)) {
211
+ $returnValue = $aliasData[$key];
212
+ }
213
+ return $returnValue;
214
+ }
215
+
216
+ /**
217
+ * retrieves the given path (month or year) from stored expiration date
218
+ *
219
+ * @param $key - the requested path
220
+ *
221
+ * @return null | string the extracted part of the date
222
+ */
223
+ public function getExpirationDatePart($key)
224
+ {
225
+ $returnValue = null;
226
+ $expirationDate = $this->getStoredAliasDataForCustomer('expiration_date');
227
+ // set expiration date to actual date if no stored Alias is used
228
+ if ($expirationDate === null) {
229
+ $expirationDate = date('my');
230
+ }
231
+
232
+ if (0 < strlen(trim($expirationDate))
233
+ ) {
234
+ $expirationDateValues = str_split($expirationDate, 2);
235
+
236
+ if ($key == 'month') {
237
+ $returnValue = $expirationDateValues[0];
238
+ }
239
+ if ($key == 'year') {
240
+ $returnValue = $expirationDateValues[1];
241
+ }
242
+ }
243
+ return $returnValue;
244
+
245
+ }
246
+
247
+ /**
248
+ * retrieves the masked alias card number and formats it in a card specific format
249
+ *
250
+ * @return null|string - null if no alias data were found,
251
+ * otherwise the formatted card number
252
+ */
253
+ public function getAliasCardNumber()
254
+ {
255
+ $aliasCardNumber = $this->getStoredAliasDataForCustomer('pseudo_account_or_cc_no');
256
+ if (0 < strlen(trim($aliasCardNumber))) {
257
+ $aliasCardNumber = Mage::helper('ops/alias')->formatAliasCardNo(
258
+ $this->getStoredAliasDataForCustomer('brand'), $aliasCardNumber
259
+ );
260
+ }
261
+ return $aliasCardNumber;
262
+ }
263
+
264
+ /**
265
+ * @return null|string - the card holder either from alias data or
266
+ * the name from the the user who is logged in, null otherwise
267
+ */
268
+ public function getCardHolderName()
269
+ {
270
+ $cardHolderName = $this->getStoredAliasDataForCustomer('card_holder');
271
+ $customerHelper = Mage::helper('customer/data');
272
+ if ((is_null($cardHolderName) || 0 === strlen(trim($cardHolderName)))
273
+ && (!is_null($this->getStoredAlias('alias')))
274
+ && $customerHelper->isLoggedIn()
275
+ && Mage::getModel('ops/config')->isAliasManagerEnabled()
276
+ ) {
277
+ $cardHolderName = $customerHelper->getCustomerName();
278
+ }
279
+ return $cardHolderName;
280
+ }
281
+
282
+ /**
283
+ * the brand of the stored card data
284
+ *
285
+ * @return null|string - string if stored card data were found, null otherwise
286
+ */
287
+ public function getStoredAliasBrand()
288
+ {
289
+ $storedBrand = $this->getStoredAliasDataForCustomer('brand');
290
+ if (in_array($storedBrand, Mage::getModel('ops/config')->getInlinePaymentCcTypes())) {
291
+ return $storedBrand;
292
+ }
293
+ return '';
294
+ }
295
+
296
+ /**
297
+ * retrieves an old alias for re-usage or updating it
298
+ *
299
+ * @return null|string - string the stored alias for re-usage or
300
+ * null if no alias data were stored
301
+ */
302
+ public function getStoredAlias()
303
+ {
304
+ return $this->getStoredAliasDataForCustomer('alias');
305
+ }
306
+
307
+ /**
308
+ * wrapper for Netresearch_OPS_Helper_Data::checkIfUserRegistering
309
+ *
310
+ * @return type bool
311
+ */
312
+ public function isUserRegistering()
313
+ {
314
+ return Mage::Helper('ops/data')->checkIfUserIsRegistering();
315
+ }
316
+
317
+ /**
318
+ * wrapper for Netresearch_OPS_Helper_Data::checkIfUserRegistering
319
+ *
320
+ * @return type bool
321
+ */
322
+ public function isUserNotRegistering()
323
+ {
324
+ return Mage::Helper('ops/data')->checkIfUserIsNotRegistering();
325
+ }
326
+
327
+ /**
328
+ * determines whether the hint is shown to guests or not
329
+ *
330
+ * @return bool true if alias feature is enabled and display the hint to
331
+ * guests is enabled
332
+ */
333
+ public function isAliasInfoBlockEnabled()
334
+ {
335
+ return ($this->isAliasPMEnabled()
336
+ && Mage::getModel('ops/config')->isAliasInfoBlockEnabled());
337
+ }
338
+
339
+ /**
340
+ * @return string
341
+ */
342
+ public function getPmLogo()
343
+ {
344
+ return $this->pmLogo;
345
+ }
346
+
347
+
348
+ protected function getFieldMapping()
349
+ {
350
+ return $this->getConfig()->getFrontendFieldMapping();
351
+ }
352
+
353
+ /**
354
+ * returns the corresponding fields for frontend validation if needed
355
+ *
356
+ * @return string - the json encoded fields
357
+ */
358
+ public function getFrontendValidators()
359
+ {
360
+ $frontendFields = array();
361
+ if ($this->getConfig()->canSubmitExtraParameter($this->getQuote()->getStoreId())) {
362
+ $fieldsToValidate = $this->getConfig()->getParameterLengths();
363
+ $mappedFields = $this->getFieldMapping();
364
+ foreach ($fieldsToValidate as $key => $value) {
365
+ if (array_key_exists($key, $mappedFields)) {
366
+ $frontendFields = $this->getFrontendValidationFields($mappedFields, $key, $value, $frontendFields);
367
+ }
368
+ }
369
+ }
370
+
371
+ return Mage::helper('core/data')->jsonEncode($frontendFields);
372
+ }
373
+
374
+ /**
375
+ * @param $mappedFields
376
+ * @param $key
377
+ * @param $value
378
+ * @param $frontendFields
379
+ *
380
+ * @return mixed
381
+ */
382
+ public function getFrontendValidationFields($mappedFields, $key, $value, $frontendFields)
383
+ {
384
+ if (!is_array($mappedFields[$key])) {
385
+ $frontendFields[$mappedFields[$key]] = $value;
386
+ } else {
387
+ foreach ($mappedFields[$key] as $mKey) {
388
+ $frontendFields[$mKey] = $value;
389
+ }
390
+ }
391
+
392
+ return $frontendFields;
393
+ }
394
+ }
app/code/community/Netresearch/OPS/Block/Form/Alias.php ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category OPS
4
+ * @package Netresearch_OPS
5
+ * @author Thomas Birke <thomas.birke@netresearch.de>
6
+ * @author Michael Lühr <michael.luehr@netresearch.de>
7
+ * @copyright Copyright (c) 2012 Netresearch GmbH & Co. KG
8
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
9
+ */
10
+
11
+ /**
12
+ * Netresearch_OPS_Block_Form_Alias
13
+ *
14
+ * @author Thomas Birke <thomas.birke@netresearch.de>
15
+ * @author Michael Lühr <michael.luehr@netresearch.de>
16
+ * @copyright Copyright (c) 2012 Netresearch GmbH & Co. KG
17
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
+ */
19
+ class Netresearch_OPS_Block_Form_Alias extends Netresearch_OPS_Block_Form
20
+ {
21
+ protected function _construct()
22
+ {
23
+ parent::_construct();
24
+ $this->setTemplate('ops/form/alias.phtml');
25
+ }
26
+
27
+ /**
28
+ * get available aliases for current customer
29
+ * will return empty array if there is no current user
30
+ *
31
+ * @return array|Netresearch_OPS_Model_Mysql4_Alias_Collection
32
+ */
33
+ public function getAvailableAliases()
34
+ {
35
+ $customer = Mage::helper('customer')->getCustomer();
36
+ if (0 < $customer->getId()) {
37
+ $quote = Mage::helper('ops/payment')->getQuote();
38
+ return Mage::helper('ops/payment')->getAliasesForCustomer($customer->getId(), $quote);
39
+ }
40
+ return array();
41
+ }
42
+
43
+ /**
44
+ *
45
+ * @param String $alias- the human readable alias
46
+ */
47
+ protected function getHumanReadableAlias($alias)
48
+ {
49
+ $helper = Mage::helper('ops');
50
+ $aliasString = $helper->__('Credit Card Type') . ' ' . $helper->__($alias->getBrand());
51
+ $aliasString .= ' ' . $helper->__('AccountNo') . ' ' . $helper->__($alias->getPseudoAccountOrCCNo());
52
+ $aliasString .= ' ' . $helper->__('Expiration Date') . ' ' . $alias->getExpirationDate();
53
+ return $aliasString;
54
+ }
55
+ }
app/code/community/Netresearch/OPS/Block/Form/Cc.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Netresearch_OPS_Block_Form_OpsId
5
+ *
6
+ * @package OPS
7
+ * @copyright 2012 Netresearch App Factory AG <http://www.netresearch.de>
8
+ * @author Thomas Birke <thomas.birke@netresearch.de>
9
+ * @license OSL 3.0
10
+ */
11
+ class Netresearch_OPS_Block_Form_Cc extends Netresearch_OPS_Block_Form
12
+ {
13
+ /**
14
+ * Backend Payment Template
15
+ */
16
+ const BACKEND_TEMPLATE = 'ops/form/cc.phtml';
17
+
18
+ protected function _construct()
19
+ {
20
+ parent::_construct();
21
+
22
+ //Only in case that the form is loaded in the backend, use a special template
23
+ if (false === Mage::getModel("ops/config")->isFrontendEnvironment()) {
24
+ $this->setTemplate(self::BACKEND_TEMPLATE);
25
+ }
26
+ }
27
+
28
+ /**
29
+ * gets all Alias CC brands
30
+ *
31
+ * @return array
32
+ */
33
+ public function getAliasBrands()
34
+ {
35
+ return Mage::getModel('ops/source_cc_aliasInterfaceEnabledTypes')
36
+ ->getAliasInterfaceCompatibleTypes();
37
+ }
38
+ }
app/code/community/Netresearch/OPS/Block/Form/DirectDebit.php ADDED
@@ -0,0 +1,231 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Netresearch_OPS_Block_Form_DirectDebit
4
+ *
5
+ * @package OPS
6
+ * @copyright 2012 Netresearch App Factory AG <http://www.netresearch.de>
7
+ * @author Thomas Birke <thomas.birke@netresearch.de>
8
+ * @license OSL 3.0
9
+ */
10
+ class Netresearch_OPS_Block_Form_DirectDebit extends Netresearch_OPS_Block_Form
11
+ {
12
+
13
+ protected $previousParams = array();
14
+
15
+ /**
16
+ * Backend Payment Template
17
+ */
18
+ const BACKEND_TEMPLATE = 'ops/form/directDebit.phtml';
19
+
20
+ protected function _construct()
21
+ {
22
+ parent::_construct();
23
+
24
+ //Only in case that the form is loaded in the backend, use a special template
25
+ if (false === Mage::getModel("ops/config")->isFrontendEnvironment()) {
26
+ $this->setTemplate(self::BACKEND_TEMPLATE);
27
+ }
28
+ }
29
+
30
+ /**
31
+ * get ids of supported countries
32
+ *
33
+ * @return array
34
+ */
35
+ public function getDirectDebitCountryIds()
36
+ {
37
+ return explode(',', $this->getConfig()->getDirectDebitCountryIds());
38
+ }
39
+
40
+ /**
41
+ * get previously entred params for displaying them again in the backend
42
+ *
43
+ * @return array - the previously entred params
44
+ */
45
+ public function getParams()
46
+ {
47
+ $params = Mage::getModel('adminhtml/session')->getData(
48
+ 'ops_direct_debit_params'
49
+ );
50
+
51
+ Mage::getModel('adminhtml/session')->unsetData(
52
+ 'ops_direct_debit_params'
53
+ );
54
+ if (!is_array($params)) {
55
+ $params = array(
56
+ 'country' => '',
57
+ 'CN' => '',
58
+ 'iban' => '',
59
+ 'bic' => '',
60
+ 'account' => '',
61
+ 'bankcode' => ''
62
+ );
63
+ }
64
+ $this->previousParams = $params;
65
+
66
+ return $this->previousParams;
67
+ }
68
+
69
+ /**
70
+ * checks if the iban field is required
71
+ *
72
+ * @return bool - true if so, false otherwise
73
+ */
74
+ public function isIbanFieldRequired()
75
+ {
76
+ return (count($this->previousParams) == 0
77
+ || (array_key_exists(
78
+ 'iban', $this->previousParams
79
+ )
80
+ && 0 < strlen('iban')
81
+ || array_key_exists('account', $this->previousParams)
82
+ && 0 == strlen($this->previousParams['account'])));
83
+ }
84
+
85
+ /**
86
+ * checks if the account field is required
87
+ *
88
+ * @return bool - true if so, false otherwise
89
+ */
90
+ public function isAccountFieldRequired()
91
+ {
92
+ return (count($this->previousParams) == 0
93
+ || (array_key_exists(
94
+ 'account', $this->previousParams
95
+ )
96
+ && (!array_key_exists('iban', $this->previousParams)
97
+ || 0 == strlen($this->previousParams['iban']))));
98
+ }
99
+
100
+
101
+
102
+ /**
103
+ * checks if the bankcode field is required
104
+ *
105
+ * @return bool - true if so, false otherwise
106
+ */
107
+ public function isBankCodeFieldRequired()
108
+ {
109
+ return $this->isAccountFieldRequired()
110
+ && array_key_exists(
111
+ 'country', $this->previousParams
112
+ )
113
+ && ('DE' == strtoupper(
114
+ $this->getCountry())
115
+ || 'AT' == strtoupper($this->getCountry())
116
+
117
+ );
118
+ }
119
+
120
+ /**
121
+ * checks if the bankcode field is visible
122
+ *
123
+ * @return bool - true if so, false otherwise
124
+ */
125
+ public function isBankCodeFieldVisible()
126
+ {
127
+ return array_key_exists('country', $this->previousParams)
128
+ && ('DE' == strtoupper($this->getCountry())
129
+ || 'AT' == strtoupper($this->getCountry()));
130
+ }
131
+
132
+ /**
133
+ * checks if the bic field is visible
134
+ *
135
+ * @return bool - true if so, false otherwise
136
+ */
137
+ public function isBicFieldVisible()
138
+ {
139
+ return ('NL' == strtoupper($this->getCountry()));
140
+ }
141
+
142
+ /**
143
+ * gets the previously entered country (if any)
144
+ *
145
+ * @return string - empty string if no country is given, otherwise the country
146
+ */
147
+ public function getCountry()
148
+ {
149
+ $country = '';
150
+ if (array_key_exists('country', $this->previousParams)) {
151
+ $country = $this->previousParams['country'];
152
+ }
153
+
154
+ return $country;
155
+ }
156
+
157
+ /**
158
+ * gets the previously entered iban (if any)
159
+ *
160
+ * @return string - empty string if no iban is given, otherwise the iban
161
+ */
162
+ public function getIban()
163
+ {
164
+ $iban = '';
165
+ if (array_key_exists('iban', $this->previousParams)) {
166
+ $iban = $this->previousParams['iban'];
167
+ }
168
+
169
+ return $iban;
170
+ }
171
+
172
+ /**
173
+ * gets the previously entered bic (if any)
174
+ *
175
+ * @return string - empty string if no bic is given, otherwise the bic
176
+ */
177
+ public function getBic()
178
+ {
179
+ $bic = '';
180
+ if (array_key_exists('bic', $this->previousParams)) {
181
+ $bic = $this->previousParams['bic'];
182
+ }
183
+
184
+ return $bic;
185
+ }
186
+
187
+ /**
188
+ * gets the previously entered account (if any)
189
+ *
190
+ * @return string - empty string if no account is given, otherwise the account
191
+ */
192
+ public function getAccount()
193
+ {
194
+ $account = '';
195
+ if (array_key_exists('account', $this->previousParams)) {
196
+ $account = $this->previousParams['account'];
197
+ }
198
+
199
+ return $account;
200
+ }
201
+
202
+ /**
203
+ * gets the previously entered bankcode (if any)
204
+ *
205
+ * @return string - empty string if no bankcode is given, otherwise the bankcode
206
+ */
207
+ public function getBankcode()
208
+ {
209
+ $bankcode = '';
210
+ if (array_key_exists('bankcode', $this->previousParams)) {
211
+ $bankcode = $this->previousParams['bankcode'];
212
+ }
213
+
214
+ return $bankcode;
215
+ }
216
+
217
+ /**
218
+ * gets the previously entered card holder (if any)
219
+ *
220
+ * @return string - empty string if no card holder is given, otherwise the card holder
221
+ */
222
+ public function getCardholderName()
223
+ {
224
+ $cardholder = '';
225
+ if (array_key_exists('CN', $this->previousParams)) {
226
+ $cardholder = $this->previousParams['CN'];
227
+ }
228
+
229
+ return $cardholder;
230
+ }
231
+ }
app/code/community/Netresearch/OPS/Block/Form/Ideal.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Michael Lühr <michael.luehr@netresearch.de>
4
+ * @category Netresearch
5
+ * @copyright Copyright (c) 2014 Netresearch GmbH & Co. KG (http://www.netresearch.de)
6
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
7
+ */
8
+
9
+
10
+ class Netresearch_OPS_Block_Form_Ideal
11
+ extends Mage_Payment_Block_Form
12
+ {
13
+
14
+ /**
15
+ * Init OPS payment form
16
+ *
17
+ */
18
+ protected function _construct()
19
+ {
20
+ parent::_construct();
21
+ $this->setTemplate('ops/form/ideal.phtml');
22
+ }
23
+
24
+ /**
25
+ * return the ideal issuers
26
+ *
27
+ * @return array
28
+ */
29
+ public function getIssuers()
30
+ {
31
+ return Mage::getModel('ops/payment_iDeal')->getIDealIssuers();
32
+ }
33
+ }
app/code/community/Netresearch/OPS/Block/Form/Kwixo/ApresReception.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Michael Lühr <michael.luehr@netresearch.de>
4
+ * @category Netresearch
5
+ * @package Netresearch_OPS
6
+ * @copyright Copyright (c) 2013 Netresearch GmbH & Co. KG (http://www.netresearch.de)
7
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
8
+ */
9
+
10
+
11
+ class Netresearch_OPS_Block_Form_Kwixo_ApresReception extends Netresearch_OPS_Block_Form
12
+ {
13
+ const FRONTEND_TEMPLATE = 'ops/form/kwixo/apres_reception.phtml';
14
+
15
+ protected $pmLogo = 'images/ops/kwixo/apres_reception.jpg';
16
+
17
+ /**
18
+ * Init OPS payment form
19
+ *
20
+ */
21
+ protected function _construct()
22
+ {
23
+ parent::_construct();
24
+ $this->setTemplate(self::FRONTEND_TEMPLATE);
25
+ }
26
+ }
app/code/community/Netresearch/OPS/Block/Form/Kwixo/Comptant.php ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Michael Lühr <michael.luehr@netresearch.de>
4
+ * @category Netresearch
5
+ * @package Netresearch_OPS
6
+ * @copyright Copyright (c) 2013 Netresearch GmbH & Co. KG (http://www.netresearch.de)
7
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
8
+ */
9
+
10
+
11
+
12
+ class Netresearch_OPS_Block_Form_Kwixo_Comptant extends Netresearch_OPS_Block_Form
13
+ {
14
+ const FRONTEND_TEMPLATE = 'ops/form/kwixo/comptant.phtml';
15
+
16
+ protected $pmLogo = 'images/ops/kwixo/comptant.jpg';
17
+
18
+ /**
19
+ * Init OPS payment form
20
+ *
21
+ */
22
+ protected function _construct()
23
+ {
24
+ parent::_construct();
25
+ $this->setTemplate(self::FRONTEND_TEMPLATE);
26
+ }
27
+
28
+
29
+ }
app/code/community/Netresearch/OPS/Block/Form/Kwixo/Credit.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Michael Lühr <michael.luehr@netresearch.de>
4
+ * @category Netresearch
5
+ * @package Netresearch_OPS
6
+ * @copyright Copyright (c) 2013 Netresearch GmbH & Co. KG (http://www.netresearch.de)
7
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
8
+ */
9
+
10
+
11
+
12
+ class Netresearch_OPS_Block_Form_Kwixo_Credit extends Netresearch_OPS_Block_Form
13
+ {
14
+ const FRONTEND_TEMPLATE = 'ops/form/kwixo/credit.phtml';
15
+
16
+ protected $pmLogo = 'images/ops/kwixo/credit.jpg';
17
+
18
+ /**
19
+ * Init OPS payment form
20
+ *
21
+ */
22
+ protected function _construct()
23
+ {
24
+ parent::_construct();
25
+ $this->setTemplate(self::FRONTEND_TEMPLATE);
26
+ }
27
+ }
app/code/community/Netresearch/OPS/Block/Form/OpsId.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Netresearch_OPS_Block_Form_OpsId
4
+ *
5
+ * @package OPS
6
+ * @copyright 2012 Netresearch App Factory AG <http://www.netresearch.de>
7
+ * @author Thomas Birke <thomas.birke@netresearch.de>
8
+ * @license OSL 3.0
9
+ */
10
+ class Netresearch_OPS_Block_Form_OpsId extends Mage_Payment_Block_Form
11
+ {
12
+ protected function _construct()
13
+ {
14
+ parent::_construct();
15
+ $this->setTemplate('ops/form/opsId.phtml');
16
+ }
17
+ }
app/code/community/Netresearch/OPS/Block/Form/Other.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Michael Lühr <michael.luehr@netresearch.de>
4
+ * @category Netresearch
5
+ * @copyright Copyright (c) 2014 Netresearch GmbH & Co. KG (http://www.netresearch.de)
6
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
7
+ */
8
+
9
+
10
+ class Netresearch_OPS_Block_Form_Other
11
+ extends Mage_Payment_Block_Form
12
+ {
13
+
14
+ /**
15
+ * Init OPS payment form
16
+ *
17
+ */
18
+ protected function _construct()
19
+ {
20
+ parent::_construct();
21
+ $this->setTemplate('ops/form/other.phtml');
22
+ }
23
+ }
app/code/community/Netresearch/OPS/Block/Frauddetection.php ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Netresearch_OPS
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ class Netresearch_OPS_Block_Frauddetection
28
+ extends Mage_Core_Block_Template
29
+ {
30
+ protected $_template = "ops/frauddetection.phtml";
31
+
32
+ const TRACKING_CODE_APPLICATION_ID = "10376";
33
+
34
+ /**
35
+ * renders the additional fraud detection js
36
+ * @return string
37
+ */
38
+ protected function _toHtml()
39
+ {
40
+ $html = null;
41
+ $storeId = Mage::helper('core/data')->getStoreId();
42
+ if (true === Mage::getModel('ops/config')->isTrackingCodeActivated(
43
+ $storeId
44
+ )
45
+ ) {
46
+ $html = parent::_toHtml();
47
+ }
48
+ return $html;
49
+ }
50
+
51
+ /**
52
+ * get the tracking code application id from config
53
+ *
54
+ * @return string
55
+ */
56
+ public function getTrackingCodeAid()
57
+ {
58
+ return self::TRACKING_CODE_APPLICATION_ID;
59
+ }
60
+
61
+
62
+ /**
63
+ * build md5 hash from customer session ID
64
+ *
65
+ * @return string
66
+ */
67
+ public function getTrackingSid()
68
+ {
69
+ return md5(Mage::getSingleton("customer/session")->getSessionId());
70
+ }
71
+
72
+ }
app/code/community/Netresearch/OPS/Block/Info/Alias.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category OPS
4
+ * @package Netresearch_OPS
5
+ * @author Thomas Birke <thomas.birke@netresearch.de>
6
+ * @author Michael Lühr <michael.luehr@netresearch.de>
7
+ * @copyright Copyright (c) 2012 Netresearch GmbH & Co. KG
8
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
9
+ */
10
+
11
+ /**
12
+ * Netresearch_OPS_Block_Info_Alias
13
+ *
14
+ * @author Thomas Birke <thomas.birke@netresearch.de>
15
+ * @author Michael Lühr <michael.luehr@netresearch.de>
16
+ * @copyright Copyright (c) 2012 Netresearch GmbH & Co. KG
17
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
+ */
19
+ class Netresearch_OPS_Block_Info_Alias extends Netresearch_OPS_Block_Info_Redirect
20
+ {
21
+ /**
22
+ * Init ops payment information block
23
+ *
24
+ */
25
+ protected function _construct()
26
+ {
27
+ parent::_construct();
28
+ $this->setTemplate('ops/info/cc.phtml');
29
+ }
30
+ }
31
+
app/code/community/Netresearch/OPS/Block/Info/Cc.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Netresearch_OPS
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * OPS payment information block
29
+ */
30
+ class Netresearch_OPS_Block_Info_Cc extends Netresearch_OPS_Block_Info_Redirect
31
+ {
32
+ /**
33
+ * Init ops payment information block
34
+ *
35
+ */
36
+ protected function _construct()
37
+ {
38
+ parent::_construct();
39
+ $this->setTemplate('ops/info/cc.phtml');
40
+ }
41
+ }
42
+
app/code/community/Netresearch/OPS/Block/Info/OpsId.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Netresearch_OPS
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * OPS payment information block
29
+ */
30
+ class Netresearch_OPS_Block_Info_OpsId extends Mage_Payment_Block_Info
31
+ {
32
+ /**
33
+ * Init ops payment information block
34
+ *
35
+ */
36
+ protected function _construct()
37
+ {
38
+ parent::_construct();
39
+ $this->setTemplate('ops/info/opsId.phtml');
40
+ }
41
+ }
42
+
app/code/community/Netresearch/OPS/Block/Info/Redirect.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Netresearch_OPS
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * OPS payment information block
29
+ */
30
+ class Netresearch_OPS_Block_Info_Redirect extends Mage_Payment_Block_Info
31
+ {
32
+ /**
33
+ * Init ops payment information block
34
+ *
35
+ */
36
+ protected function _construct()
37
+ {
38
+ parent::_construct();
39
+ $this->setTemplate('ops/info/redirect.phtml');
40
+ }
41
+ }
app/code/community/Netresearch/OPS/Block/Paypage.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Netresearch_OPS
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+
28
+ class Netresearch_OPS_Block_Paypage extends Mage_Core_Block_Template
29
+ {
30
+ /**
31
+ * Init pay page block
32
+ *
33
+ * @return Netresearch_OPS_Block_Paypage
34
+ */
35
+ protected function _construct()
36
+ {
37
+ parent::_construct();
38
+ $this->setTemplate('ops/paypage.phtml');
39
+ return $this;
40
+ }
41
+ }
app/code/community/Netresearch/OPS/Block/Placeform.php ADDED
@@ -0,0 +1,150 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Magento
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * @category Mage
23
+ * @package Netresearch_OPS
24
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
25
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
26
+ */
27
+ class Netresearch_OPS_Block_Placeform extends Mage_Core_Block_Template
28
+ {
29
+ protected $hasMissingParams;
30
+ protected $missingFormFields;
31
+ protected $formFields;
32
+ protected $question;
33
+
34
+ public function __construct()
35
+ {
36
+
37
+ }
38
+
39
+ public function getConfig()
40
+ {
41
+ return Mage::getModel('ops/config');
42
+ }
43
+
44
+ /**
45
+ * Get checkout session namespace
46
+ *
47
+ * @return Mage_Checkout_Model_Session
48
+ */
49
+ public function getCheckout()
50
+ {
51
+ return Mage::getSingleton('checkout/session');
52
+ }
53
+
54
+ /**
55
+ * OPS payment APi instance
56
+ *
57
+ * @return Netresearch_OPS_Model_Payment_Abstract
58
+ */
59
+ protected function _getApi()
60
+ {
61
+ $order = Mage::getModel('sales/order')->loadByIncrementId($this->getCheckout()->getLastRealOrderId());
62
+ if ($order && !is_null($order->getId())) {
63
+ return $order->getPayment()->getMethodInstance();
64
+ }
65
+ }
66
+
67
+ /**
68
+ * Return order instance with loaded information by increment id
69
+ *
70
+ * @return Mage_Sales_Model_Order
71
+ */
72
+ protected function _getOrder()
73
+ {
74
+ if ($this->getOrder()) {
75
+ $order = $this->getOrder();
76
+ } else if ($this->getCheckout()->getLastRealOrderId()) {
77
+ $order = Mage::getModel('sales/order')->loadByIncrementId($this->getCheckout()->getLastRealOrderId());
78
+ } else {
79
+ return null;
80
+ }
81
+ return $order;
82
+ }
83
+
84
+ /**
85
+ * check if payment method is q kwixo one
86
+ *
87
+ * @return boolean
88
+ */
89
+ public function isKwixoPaymentMethod()
90
+ {
91
+ $isKwixoPayment = false;
92
+ $methodInstance = $this->_getOrder()->getPayment()->getMethodInstance();
93
+ if ($methodInstance instanceof Netresearch_OPS_Model_Payment_Kwixo_Abstract) {
94
+ $isKwixoPayment= true;
95
+ }
96
+ return $isKwixoPayment;
97
+ }
98
+ /**
99
+ * Get Form data by using ops payment api
100
+ *
101
+ * @return array
102
+ */
103
+ public function getFormData()
104
+ {
105
+ if (is_null($this->formFields) && $this->_getOrder() && !is_null($this->_getOrder()->getId())) {
106
+ $this->formFields = $this->_getApi()->getFormFields($this->_getOrder(), $this->getRequest()->getParams());
107
+ }
108
+ return $this->formFields;
109
+ }
110
+
111
+ /**
112
+ * Getting gateway url
113
+ *
114
+ * @return string
115
+ */
116
+ public function getFormAction()
117
+ {
118
+ return $this->getRequest()->isPost() || is_null($this->getQuestion()) ? $this->getConfig()->getFrontendGatewayPath() :
119
+ Mage::getUrl('*/*/*', array('_secure' => Mage::app()->getFrontController()->getRequest()->isSecure()));
120
+ }
121
+
122
+ public function hasMissingParams()
123
+ {
124
+ if (is_null($this->_getOrder())) {
125
+ return null;
126
+ }
127
+ if (is_null($this->hasMissingParams)) {
128
+ $this->hasMissingParams = $this->_getApi()->hasFormMissingParams($this->_getOrder(), $this->getRequest()->getParams(), $this->getFormData());
129
+ }
130
+ return $this->hasMissingParams;
131
+ }
132
+
133
+ public function getQuestion()
134
+ {
135
+ if (is_null($this->question) && $this->_getOrder() && !is_null($this->_getOrder()->getId())) {
136
+ $this->question = $this->_getApi()->getQuestion($this->_getOrder(), $this->getRequest()->getParams());
137
+ }
138
+ return $this->question;
139
+ }
140
+
141
+ public function getQuestionedFormFields()
142
+ {
143
+ if (is_null($this->missingFormFields) && $this->_getOrder() && !is_null($this->_getOrder()->getId())) {
144
+ $this->missingFormFields = $this->_getApi()->getQuestionedFormFields($this->_getOrder(), $this->getRequest()->getParams());
145
+ }
146
+ return $this->missingFormFields;
147
+ }
148
+
149
+
150
+ }
app/code/community/Netresearch/OPS/Block/Placeform3dsecure.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Netresearch_OPS
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+
28
+ class Netresearch_OPS_Block_Placeform3dsecure extends Netresearch_OPS_Block_Placeform
29
+ {
30
+ /**
31
+ * Get Form data of 3D Secure
32
+ *
33
+ * @return string
34
+ */
35
+ public function getFormData()
36
+ {
37
+ if (!is_null($this->_getOrder())) {
38
+ return base64_decode($this->_getOrder()->getPayment()->getAdditionalInformation('HTML_ANSWER'));
39
+ }
40
+ return null;
41
+ }
42
+ }
app/code/community/Netresearch/OPS/Block/RetryPayment.php ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * ${PACKAGE}
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ * DISCLAIMER
13
+ *
14
+ * Do not edit or add to this file if you wish to upgrade this extension to
15
+ * newer versions in the future.
16
+ *
17
+ * @copyright Copyright (c) 2015 Netresearch GmbH & Co. KG (http://www.netresearch.de/)
18
+ * @license Open Software License (OSL 3.0)
19
+ * @link http://opensource.org/licenses/osl-3.0.php
20
+ */
21
+
22
+ /**
23
+ * RetryPayment.php
24
+ *
25
+ * @category ${CATEGORY}
26
+ * @package ${PACKAGE}
27
+ * @author Paul Siedler <paul.siedler@netresearch.de>
28
+ */
29
+
30
+ class Netresearch_OPS_Block_RetryPayment extends Netresearch_OPS_Block_Placeform {
31
+
32
+ protected $order = null;
33
+
34
+ protected function _getApi()
35
+ {
36
+ return $this->_getOrder()->getPayment()->getMethodInstance();
37
+ }
38
+
39
+ protected function _getOrder()
40
+ {
41
+ if(is_null($this->order)){
42
+ $opsOrderId = $this->getRequest()->getParam('orderID');
43
+ $this->order = Mage::helper('ops/order')->getOrder($opsOrderId);
44
+ }
45
+ return $this->order;
46
+ }
47
+
48
+
49
+ }
app/code/community/Netresearch/OPS/Block/System/Config/Form/Field/Brand.php ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Netresearch OPS
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ *
13
+ * DISCLAIMER
14
+ *
15
+ * Do not edit or add to this file if you wish to upgrade this extension to
16
+ * newer versions in the future.
17
+ *
18
+ * @category Netresearch
19
+ * @package Netresearch_OPS
20
+ * @copyright Copyright (c) 2012 Netresearch GmbH & Co. KG (http://www.netresearch.de/)
21
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
22
+ */
23
+
24
+ /**
25
+ * Netresearch
26
+ *
27
+ * @category Netresearch
28
+ * @package Netresearch_OPS
29
+ * @author Michael Lühr <michael.luehr@netresearch.de>
30
+ */
31
+
32
+ class Netresearch_OPS_Block_System_Config_Form_Field_Brand
33
+ extends Mage_Adminhtml_Block_System_Config_Form_Field_Array_Abstract
34
+ {
35
+ public function __construct()
36
+ {
37
+ $this->addColumn('brand', array(
38
+ 'label' => Mage::helper('ops')->__('Brand'),
39
+ 'style' => 'width:120px',
40
+ ));
41
+ $this->addColumn('value', array(
42
+ 'label' => Mage::helper('ops')->__('Title'),
43
+ 'style' => 'width:120px',
44
+ ));
45
+ $this->_addAfter = false;
46
+ $this->_addButtonLabel = Mage::helper('ops')->__('Add Brand');
47
+ parent::__construct();
48
+ }
49
+ }
app/code/community/Netresearch/OPS/Block/System/Config/Kwixoconfiguration.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created by JetBrains PhpStorm.
4
+ * User: michael
5
+ * Date: 23.07.13
6
+ * Time: 09:04
7
+ * To change this template use File | Settings | File Templates.
8
+ */
9
+
10
+ class Netresearch_OPS_Block_System_Config_Kwixoconfiguration
11
+ extends Mage_Adminhtml_Block_Abstract
12
+ implements Varien_Data_Form_Element_Renderer_Interface
13
+ {
14
+
15
+ protected $_template = 'ops/system/config/kwixoconfiglinks.phtml';
16
+
17
+ /**
18
+ * Render fieldset html
19
+ *
20
+ * @param Varien_Data_Form_Element_Abstract $fieldset
21
+ *
22
+ * @return string
23
+ */
24
+ public function render(Varien_Data_Form_Element_Abstract $fieldset)
25
+ {
26
+ $this->addData(
27
+ array(
28
+ 'fieldset_label' => $fieldset->getLegend(),
29
+ )
30
+ );
31
+
32
+ return $this->toHtml();
33
+ }
34
+
35
+ }
app/code/community/Netresearch/OPS/Block/System/Config/Mode.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mode.php
4
+ * @author paul.siedler@netresearch.de
5
+ * @copyright Copyright (c) 2015 Netresearch GmbH & Co. KG
6
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License
7
+ */
8
+
9
+ class Netresearch_OPS_Block_System_Config_Mode extends Mage_Adminhtml_Block_System_Config_Form_Field {
10
+
11
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
12
+ {
13
+ $html = parent::_getElementHtml($element);
14
+
15
+ $javascript = "
16
+ <script type=\"text/javascript\">
17
+ element = $('".$element->getHtmlId()."');
18
+ Event.observe(element, 'change', function(){
19
+ if(element.selectedOptions[0].value != '".$element->getValue()."'){
20
+ $('ops_mode_comment').style.display = 'block';
21
+ } else {
22
+ $('ops_mode_comment').style.display = 'none';
23
+ }
24
+ });
25
+ </script>";
26
+
27
+ return $html.$javascript;
28
+ }
29
+
30
+
31
+ }
app/code/community/Netresearch/OPS/Block/System/Config/Support.php ADDED
@@ -0,0 +1,168 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Netresearch_OPS_Block_System_Config_Support extends Mage_Adminhtml_Block_Abstract
4
+ implements Varien_Data_Form_Element_Renderer_Interface
5
+ {
6
+ protected $_template = 'ops/system/config/support.phtml';
7
+ protected $_downloadLogPath = 'ops/adminhtml_admin/downloadlog';
8
+
9
+ protected function getConfig()
10
+ {
11
+ return Mage::getModel('ops/config');
12
+ }
13
+
14
+ /**
15
+ * Render fieldset html
16
+ *
17
+ * @param Varien_Data_Form_Element_Abstract $fieldset
18
+ * @return string
19
+ */
20
+ public function render(Varien_Data_Form_Element_Abstract $fieldset)
21
+ {
22
+ $originalData = $fieldset->getOriginalData();
23
+ $this->addData(array(
24
+ 'fieldset_label' => $fieldset->getLegend(),
25
+ ));
26
+ return $this->toHtml();
27
+ }
28
+
29
+ /**
30
+ * get extension version
31
+ *
32
+ * @return string
33
+ */
34
+ public function getExtensionVersion()
35
+ {
36
+ return (string)Mage::getConfig()->getNode('modules')->children()->Netresearch_OPS->version;
37
+ }
38
+
39
+ /**
40
+ * get Magento version
41
+ *
42
+ * @return string
43
+ */
44
+ public function getMageVersion()
45
+ {
46
+ $mageVersion = Mage::getVersion();
47
+ if (is_callable('Mage::getEdition')) {
48
+ $mageVersion = Mage::getEdition() . ' ' . $mageVersion;
49
+ }
50
+ return $mageVersion;
51
+ }
52
+
53
+ /**
54
+ * get support mail address
55
+ *
56
+ * @return string
57
+ */
58
+ public function getSupportMail()
59
+ {
60
+ $mail = $this->getConfig()->getConfigData('support_mail');
61
+ if (0 < strpos($mail, '@')) {
62
+ return $mail;
63
+ }
64
+ }
65
+
66
+ /**
67
+ * if we have a link to documentation
68
+ *
69
+ * @return int
70
+ */
71
+ public function hasDocumentation()
72
+ {
73
+ return strlen($this->getDocLinkDe() . $this->getDocLinkEn());
74
+ }
75
+
76
+ /**
77
+ * get URL of German documentation
78
+ *
79
+ * @return string
80
+ */
81
+ public function getDocLinkDe()
82
+ {
83
+ $link = $this->getConfig()->getConfigData('doc_link_de');
84
+ if (0 < strpos($link, '://')) {
85
+ return $link;
86
+ }
87
+ }
88
+
89
+ /**
90
+ * get URL of English documentation
91
+ *
92
+ * @return string
93
+ */
94
+ public function getDocLinkEn()
95
+ {
96
+ $link = $this->getConfig()->getConfigData('doc_link_en');
97
+ if (0 < strpos($link, '://')) {
98
+ return $link;
99
+ }
100
+ }
101
+
102
+ /**
103
+ * if we have link to a FAQ
104
+ *
105
+ * @return int
106
+ */
107
+ public function hasFaq()
108
+ {
109
+ return strlen($this->getFaqLinkDe() . $this->getFaqLinkEn());
110
+ }
111
+ /**
112
+ * get URL of German FAQ
113
+ *
114
+ * @return string
115
+ */
116
+ public function getFaqLinkDe()
117
+ {
118
+ $link = $this->getConfig()->getConfigData('faq_link_de');
119
+ if (0 < strpos($link, '://')) {
120
+ return $link;
121
+ }
122
+
123
+ }
124
+
125
+ /**
126
+ * get URL of English FAQ
127
+ *
128
+ * @return string
129
+ */
130
+ public function getFaqLinkEn()
131
+ {
132
+ $link = $this->getConfig()->getConfigData('faq_link_en');
133
+ if (0 < strpos($link, '://')) {
134
+ return $link;
135
+ }
136
+ }
137
+
138
+ /**
139
+ * if we use a prefix for parameter ORDERID
140
+ *
141
+ * @return bool
142
+ */
143
+ public function hasDevPrefix()
144
+ {
145
+ return 0 < strlen($this->getDevPrefix());
146
+ }
147
+
148
+ /**
149
+ * get prefix for parameter ORDERID
150
+ *
151
+ * @return string
152
+ */
153
+ public function getDevPrefix()
154
+ {
155
+ return $this->getConfig()->getConfigData('devprefix');
156
+ }
157
+
158
+ /**
159
+ * get link for ops.log download action
160
+ *
161
+ * @return string
162
+ */
163
+ public function getLogDownloadLink()
164
+ {
165
+ return $this->getUrl($this->_downloadLogPath);
166
+ }
167
+ }
168
+
app/code/community/Netresearch/OPS/Controller/Abstract.php ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Netresearch_OPS_Controller_Abstract
4
+ *
5
+ * @package
6
+ * @copyright 2011 Netresearch
7
+ * @author Thomas Kappel <thomas.kappel@netresearch.de>
8
+ * @author André Herrn <andre.herrn@netresearch.de>
9
+ * @license OSL 3.0
10
+ */
11
+ class Netresearch_OPS_Controller_Abstract extends Mage_Core_Controller_Front_Action
12
+ {
13
+ protected function getQuote()
14
+ {
15
+ return $this->_getCheckout()->getQuote();
16
+ }
17
+
18
+ /**
19
+ * Get checkout session namespace
20
+ *
21
+ * @return Mage_Checkout_Model_Session
22
+ */
23
+ protected function _getCheckout()
24
+ {
25
+ return Mage::getSingleton('checkout/session');
26
+ }
27
+
28
+ protected function getConfig()
29
+ {
30
+ return Mage::getModel('ops/config');
31
+ }
32
+
33
+ /**
34
+ * Return order instance loaded by increment id'
35
+ *
36
+ * @return Mage_Sales_Model_Order
37
+ */
38
+
39
+ /**
40
+ * Return order instance loaded by increment id'
41
+ *
42
+ * @return Mage_Sales_Model_Order
43
+ */
44
+
45
+ protected function _getOrder($opsOrderId=null)
46
+ {
47
+ if (empty($this->_order)) {
48
+ if (is_null($opsOrderId)) {
49
+ $opsOrderId = $this->getRequest()->getParam('orderID');
50
+ }
51
+ $this->_order = Mage::helper('ops/order')->getOrder($opsOrderId);
52
+ }
53
+ return $this->_order;
54
+ }
55
+
56
+ /**
57
+ * Get singleton with Checkout by OPS Api
58
+ *
59
+ * @return Netresearch_OPS_Model_Payment_Abstract
60
+ */
61
+ protected function _getApi()
62
+ {
63
+ if (!is_null($this->getRequest()->getParam('orderID'))):
64
+ return $this->_getOrder()->getPayment()->getMethodInstance();
65
+ else:
66
+ return Mage::getSingleton('checkout/session')->getQuote()->getPayment()->getMethodInstance();
67
+ endif;
68
+ }
69
+
70
+ /**
71
+ * get payment helper
72
+ *
73
+ * @return Netresearch_OPS_Helper_Payment
74
+ */
75
+ protected function getPaymentHelper()
76
+ {
77
+ return Mage::helper('ops/payment');
78
+ }
79
+
80
+ /**
81
+ * get direct link helper
82
+ *
83
+ * @return Netresearch_OPS_Helper_Directlink
84
+ */
85
+ protected function getDirectlinkHelper()
86
+ {
87
+ return Mage::helper('ops/directlink');
88
+ }
89
+
90
+ /**
91
+ * Validation of incoming OPS data
92
+ *
93
+ * @return bool
94
+ */
95
+ protected function _validateOPSData()
96
+ {
97
+ $params = $this->getRequest()->getParams();
98
+ $order = $this->_getOrder();
99
+ if (!$order->getId()) {
100
+ $this->_getCheckout()->addError($this->__('Order is not valid'));
101
+ return false;
102
+ }
103
+ $secureKey = $this->_getApi()->getConfig()->getShaInCode($order->getStoreId());
104
+ $secureSet = $this->getPaymentHelper()->getSHAInSet($params, $secureKey);
105
+
106
+ $helper = Mage::helper('ops');
107
+ $helper->log($helper->__("Incoming Ingenico Payment Services Feedback\n\nRequest Path: %s\nParams: %s\n",
108
+ $this->getRequest()->getPathInfo(),
109
+ serialize($this->getRequest()->getParams())
110
+ ));
111
+
112
+ if (Mage::helper('ops/payment')->shaCryptValidation($secureSet, $params['SHASIGN']) !== true) {
113
+ $this->_getCheckout()->addError($this->__('Hash is not valid'));
114
+ return false;
115
+ }
116
+
117
+ return true;
118
+ }
119
+
120
+ public function isJsonRequested($params)
121
+ {
122
+ if (array_key_exists('RESPONSEFORMAT', $params) && $params['RESPONSEFORMAT'] == 'JSON') {
123
+ return true;
124
+ }
125
+ return false;
126
+ }
127
+ }
app/code/community/Netresearch/OPS/Helper/Alias.php ADDED
@@ -0,0 +1,518 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Magento
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * @category Mage
23
+ * @package Netresearch_OPS
24
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
25
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
26
+ */
27
+ class Netresearch_OPS_Helper_Alias extends Mage_Core_Helper_Abstract
28
+ {
29
+
30
+ public function getAdminSession()
31
+ {
32
+ return Mage::getSingleton('admin/session');
33
+ }
34
+
35
+ public function isAdminSession()
36
+ {
37
+ if ($this->getAdminSession()->getUser()) {
38
+ return 0 < $this->getAdminSession()->getUser()->getUserId();
39
+ }
40
+ return false;
41
+ }
42
+
43
+ /**
44
+ * PM value is not used for payments with Alias Manager
45
+ *
46
+ * @param Mage_Sales_Model_Quote_Payment|null Payment
47
+ *
48
+ * @return null
49
+ */
50
+ public function getOpsCode($payment = null)
51
+ {
52
+ return $payment;
53
+ }
54
+
55
+ /**
56
+ * BRAND value is not used for payments with Alias Manager
57
+ *
58
+ * @param Mage_Sales_Model_Quote_Payment|null Payment
59
+ *
60
+ * @return null
61
+ */
62
+ public function getOpsBrand($payment = null)
63
+ {
64
+ return $payment;
65
+ }
66
+
67
+ /**
68
+ * get alias or generate a new one
69
+ *
70
+ * alias has length 16 and consists of quote creation date, a separator,
71
+ * and the quote id to make sure we have the full quote id we shorten
72
+ * the creation date accordingly
73
+ *
74
+ * @param Mage_Sales_Model_Quote $quote
75
+ *
76
+ * @return string
77
+ */
78
+ public function getAlias($quote)
79
+ {
80
+
81
+ $alias = $quote->getPayment()->getAdditionalInformation('alias');
82
+ if (0 == strlen($alias)) {
83
+ /* turn createdAt into format MMDDHHii */
84
+ $createdAt = substr(
85
+ str_replace(array(':', '-', ' '), '', $quote->getCreatedAt()),
86
+ 4,
87
+ -2
88
+ );
89
+ $quoteId = $quote->getId();
90
+ /* shorten createdAt, if we would exceed maximum length */
91
+ $maxAliasLength = 16;
92
+ $separator = '99';
93
+ $maxCreatedAtLength
94
+ = $maxAliasLength - strlen($quoteId) - strlen($separator);
95
+ $alias = substr($createdAt, 0, $maxCreatedAtLength) . $separator
96
+ . $quoteId;
97
+ }
98
+
99
+ if ($this->isAdminSession() && !strpos($alias,'BE')) {
100
+ $alias = $alias.'BE';
101
+ }
102
+ return $alias;
103
+ }
104
+
105
+ /**
106
+ * saves the alias if customer is logged in (and want to create an alias)
107
+ *
108
+ * @param $aliasData
109
+ * @param Mage_Sales_Model_Quote $quote
110
+ *
111
+ * @return Netresearch_OPS_Model_Alias | null
112
+ */
113
+ public function saveAlias($aliasData)
114
+ {
115
+ $quote = null;
116
+ $aliasModel = null;
117
+ Mage::helper('ops')->log('aliasData ' . Zend_Json::encode(Mage::helper('ops/data')->clearMsg($aliasData)));
118
+ if (array_key_exists('OrderID', $aliasData) && is_numeric($aliasData['OrderID'])) {
119
+ $quote = Mage::getModel('sales/quote')->load($aliasData['OrderID']);
120
+ }
121
+
122
+ $aliasModel = null;
123
+ if ($quote instanceof Mage_Sales_Model_Quote
124
+ && $quote->getPayment()
125
+ && (1 == $quote->getPayment()->getAdditionalInformation('saveOpsAlias'))
126
+ ) {
127
+ $customerId = $quote->getCustomer()->getId();
128
+ $billingAddressHash = $this->generateAddressHash(
129
+ $quote->getBillingAddress()
130
+ );
131
+ $shippingAddressHash = $this->generateAddressHash(
132
+ $quote->getShippingAddress()
133
+ );
134
+
135
+ // first: check if alias exists
136
+ $oldAlias = Mage::getModel('ops/alias')->getCollection()
137
+ ->addFieldToFilter('customer_id', $customerId)
138
+ ->addFieldToFilter('billing_address_hash', $billingAddressHash)
139
+ ->addFieldToFilter('shipping_address_hash', $shippingAddressHash)
140
+ ->addFieldToFilter('state', Netresearch_OPS_Model_Alias_State::ACTIVE)
141
+ ->addFieldToFilter('store_id', array(
142
+ array('attribute' => 'store_id', 'eq' => $quote->getStoreId()),
143
+ array('attribute' => 'store_id', 'null' => true)
144
+ ))
145
+ ->getFirstItem();
146
+ // and if so update this alias with alias data from alias gateway
147
+ if (is_numeric($oldAlias->getAlias())) {
148
+ $oldAlias->setCardHolder($aliasData['CN']);
149
+ $oldAlias->setBrand($aliasData['Brand']);
150
+ $oldAlias->setExpirationDate($aliasData['ED']);
151
+ $oldAlias->setPseudoAccountOrCCNo($aliasData['CardNo']);
152
+ $oldAlias->setStoreId($quote->getStoreId());
153
+ $oldAlias->save();
154
+ $aliasModel = $oldAlias;
155
+ } else {
156
+ // alias does not exist -> create a new one if requested
157
+ if (!is_null($quote) && $quote->getPayment()
158
+ && $quote->getPayment()->getAdditionalInformation('saveOpsAlias')
159
+ ) {
160
+ if (!is_null($quote->getCustomer()->getId())) {
161
+ $this->deleteAlias($quote, $aliasData);
162
+ }
163
+ // create new alias
164
+ $aliasModel = $this->saveNewAlias($quote, $aliasData);
165
+ $quote->getPayment()->setAdditionalInformation(
166
+ 'opsAliasId', $aliasModel->getId()
167
+ );
168
+ $quote->getPayment()->save();
169
+ }
170
+ }
171
+ }
172
+ return $aliasModel;
173
+ }
174
+
175
+ /**
176
+ *
177
+ * @param Mage_Sales_Model_Quote $quote
178
+ */
179
+ protected function deleteAlias(Mage_Sales_Model_Quote $quote)
180
+ {
181
+ $customerId = $quote->getCustomer()->getId();
182
+ $billingAddressHash = $this->generateAddressHash(
183
+ $quote->getBillingAddress()
184
+ );
185
+ $shippingAddressHash = $this->generateAddressHash(
186
+ $quote->getShippingAddress()
187
+ );
188
+ $aliasModel = Mage::getModel('ops/alias');
189
+ $aliasCollection = $aliasModel->getCollection()
190
+ ->addFieldToFilter('customer_id', $customerId)
191
+ ->addFieldToFilter('billing_address_hash', $billingAddressHash)
192
+ ->addFieldToFilter('shipping_address_hash', $shippingAddressHash)
193
+ ->addFieldToFilter('state', Netresearch_OPS_Model_Alias_State::PENDING)
194
+ ->addFieldToFilter('store_id', array(array('eq' => $quote->getStoreId()), array('null' => true)))
195
+ ->setOrder('created_at', 'DESC')
196
+ ->setPageSize(1);
197
+ $aliasCollection->load();
198
+ foreach ($aliasCollection as $alias) {
199
+ $alias->delete();
200
+ }
201
+ }
202
+
203
+ protected function saveNewAlias(Mage_Sales_Model_Quote $quote, $aliasData)
204
+ {
205
+ $customerId = $quote->getCustomer()->getId();
206
+ $billingAddressHash = $this->generateAddressHash(
207
+ $quote->getBillingAddress()
208
+ );
209
+ $shippingAddressHash = $this->generateAddressHash(
210
+ $quote->getShippingAddress()
211
+ );
212
+
213
+ $aliasModel = Mage::getModel('ops/alias');
214
+ $aliasModel->setCustomerId($customerId);
215
+ $aliasModel->setAlias($aliasData['Alias']);
216
+ $aliasModel->setExpirationDate($aliasData['ED']);
217
+ $aliasModel->setBillingAddressHash($billingAddressHash);
218
+ $aliasModel->setShippingAddressHash($shippingAddressHash);
219
+ $aliasModel->setBrand($aliasData['Brand']);
220
+ $aliasModel->setPaymentMethod($quote->getPayment()->getMethod());
221
+ $aliasModel->setPseudoAccountOrCCNo($aliasData['CardNo']);
222
+ $aliasModel->setState(Netresearch_OPS_Model_Alias_State::PENDING);
223
+ $aliasModel->setStoreId($quote->getStoreId());
224
+ if (array_key_exists('CN', $aliasData)) {
225
+ $aliasModel->setCardHolder($aliasData['CN']);
226
+ }
227
+ Mage::helper('ops')->log(
228
+ 'saving alias' . Zend_Json::encode($aliasModel->getData())
229
+ );
230
+ $aliasModel->save();
231
+
232
+ return $aliasModel;
233
+ }
234
+
235
+ /**
236
+ * generates hash from address data
237
+ *
238
+ * @param Mage_Sales_Model_Quote_Address $address the address data to hash
239
+ *
240
+ * @returns sha1 hash of address
241
+ */
242
+ public function generateAddressHash(
243
+ Mage_Customer_Model_Address_Abstract $address
244
+ )
245
+ {
246
+ $addressString = $address->getFirstname();
247
+ $addressString .= $address->getMiddlename();
248
+ $addressString .= $address->getLastname();
249
+ $addressString .= $address->getCompany();
250
+ $street = $address->getStreetFull();
251
+ if (is_array($street)) {
252
+ $street = implode('', $street);
253
+ }
254
+ $addressString .= $street;
255
+ $addressString .= $address->getPostcode();
256
+ $addressString .= $address->getCity();
257
+ $addressString .= $address->getCountryId();
258
+
259
+ return sha1($addressString);
260
+ }
261
+
262
+ /**
263
+ * retrieves the aliases for a given customer
264
+ *
265
+ * @param int $customerId
266
+ * @param Mage_Sales_Model_Quote
267
+ *
268
+ * @return Netresearch_OPS_Model_Mysql4_Alias_Collection - collection
269
+ * of aliases for the given customer
270
+ */
271
+ public function getAliasesForCustomer(
272
+ $customerId, Mage_Sales_Model_Quote $quote = null
273
+ )
274
+ {
275
+ $billingAddressHash = null;
276
+ $shippingAddressHash = null;
277
+ $storeId = null;
278
+ if (!is_null($quote)) {
279
+ $billingAddressHash = $this->generateAddressHash(
280
+ $quote->getBillingAddress()
281
+ );
282
+ $shippingAddressHash = $this->generateAddressHash(
283
+ $quote->getShippingAddress()
284
+ );
285
+ $storeId = $quote->getStoreId();
286
+ }
287
+ return Mage::getModel('ops/alias')
288
+ ->getAliasesForCustomer(
289
+ $customerId, $billingAddressHash, $shippingAddressHash, $storeId
290
+ );
291
+ }
292
+
293
+ /**
294
+ * if alias is valid for address
295
+ *
296
+ * @param int $customerId
297
+ * @param string $alias
298
+ * @param Mage_Sales_Model_Quote_Address $billingAddress
299
+ * @param Mage_Sales_Model_Quote_Address $shippingAddress
300
+ *
301
+ * @return boolean
302
+ */
303
+ public function isAliasValidForAddresses(
304
+ $customerId, $alias, $billingAddress, $shippingAddress, $storeId = null
305
+ )
306
+ {
307
+ $aliasCollection = $this->getAliasesForAddresses(
308
+ $customerId, $billingAddress, $shippingAddress, $storeId
309
+ )
310
+ ->addFieldToFilter('alias', $alias)
311
+ ->setPageSize(1);
312
+ return (1 == $aliasCollection->count());
313
+ }
314
+
315
+ /**
316
+ * get aliases that are allowed for customer with given addresses
317
+ *
318
+ * @param int $customerId Id of customer
319
+ * @param Mage_Sales_Model_Quote_Address $billingAddress billing address
320
+ * @param Mage_Sales_Model_Quote_Address $shippingAddress shipping address
321
+ *
322
+ * @return Netresearch_OPS_Model_Mysql4_Alias_Collection
323
+ */
324
+ public function getAliasesForAddresses(
325
+ $customerId, $billingAddress, $shippingAddress, $storeId = null
326
+ )
327
+ {
328
+ $billingAddressHash = $this->generateAddressHash($billingAddress);
329
+ $shippingAddressHash = $this->generateAddressHash($shippingAddress);
330
+ return Mage::getModel('ops/alias')->getCollection()
331
+ ->addFieldToFilter('customer_id', $customerId)
332
+ ->addFieldToFilter('billing_address_hash', $billingAddressHash)
333
+ ->addFieldToFilter('shipping_address_hash', $shippingAddressHash)
334
+ ->addFieldToFilter('store_id', array(array('eq' => $storeId), array('null' => true)));
335
+ }
336
+
337
+ /**
338
+ * formats the pseudo cc number in a brand specific format
339
+ * supported brand (so far):
340
+ * - MasterCard
341
+ * - Visa
342
+ * - American Express
343
+ * - Diners Club
344
+ *
345
+ * @param $brand - the cc brand we need to format the pseudo cc number
346
+ * @param $aliasCcNo - the pseudo cc number itself
347
+ *
348
+ * @return string - the formatted pseudo cc number
349
+ */
350
+ public function formatAliasCardNo($brand, $aliasCcNo)
351
+ {
352
+
353
+ if (in_array(strtolower($brand), array('visa', 'mastercard'))) {
354
+ $aliasCcNo = implode(' ', str_split($aliasCcNo, 4));
355
+ }
356
+ if (in_array(strtolower($brand), array('american express', 'diners club', 'maestrouk'))) {
357
+ $aliasCcNo = str_replace('-', ' ', $aliasCcNo);
358
+ }
359
+
360
+ return strtoupper($aliasCcNo);
361
+ }
362
+
363
+ /**
364
+ * saves the alias and if given the cvc to the payment information
365
+ *
366
+ * @param Mage_Payment_Model_Info $payment - the payment which should be updated
367
+ * @param array $aliasData - the data we will update
368
+ * @param boolean $userIsRegistering - is registering method in checkout
369
+ * @param boolean $paymentSave - is it necessary to save the payment afterwards
370
+ */
371
+ public function setAliasToPayment(Mage_Payment_Model_Info $payment, array $aliasData, $userIsRegistering = false, $paymentSave = false)
372
+ {
373
+ if (array_key_exists('alias', $aliasData) && 0 < strlen(trim($aliasData['alias']))) {
374
+ $payment->setAdditionalInformation('alias', trim($aliasData['alias']));
375
+ $payment->setAdditionalInformation('userIsRegistering', $userIsRegistering);
376
+ if (array_key_exists('CVC', $aliasData)) {
377
+ $payment->setAdditionalInformation('cvc', $aliasData['CVC']);
378
+ $this->setCardHolderToAlias($payment->getQuote(), $aliasData);
379
+ }
380
+ $payment->setDataChanges(true);
381
+ if($paymentSave === true){
382
+ $payment->save();
383
+ }
384
+ } else {
385
+ Mage::helper('ops/data')->log('did not save alias due to empty alias');
386
+ Mage::helper('ops/data')->log($aliasData);
387
+ }
388
+ }
389
+
390
+ protected function setCardHolderToAlias($quote, $aliasData)
391
+ {
392
+ $customerId = $quote->getCustomerId();
393
+ $billingAddressHash = $this->generateAddressHash($quote->getBillingAddress());
394
+ $shippingAddressHash = $this->generateAddressHash($quote->getShippingAddress());
395
+ $oldAlias = Mage::getModel('ops/alias')->getCollection()
396
+ ->addFieldToFilter('customer_id', $customerId)
397
+ ->addFieldToFilter('billing_address_hash', $billingAddressHash)
398
+ ->addFieldToFilter('shipping_address_hash', $shippingAddressHash)
399
+ ->addFieldToFilter('state', Netresearch_OPS_Model_Alias_State::ACTIVE)
400
+ ->addFieldToFilter('store_id', array(array('eq' => $quote->getStoreId()), array('null' => true)))
401
+ ->getFirstItem();
402
+ // and if so update this alias with alias data from alias gateway
403
+ if (is_numeric($oldAlias->getId()) && is_null($oldAlias->getCardHolder()) && array_key_exists('CN', $aliasData)
404
+ ) {
405
+ $oldAlias->setCardHolder($aliasData['CN']);
406
+ $oldAlias->save();
407
+ }
408
+ }
409
+
410
+ /**
411
+ * set the last pending alias to active and remove other aliases for customer based on address
412
+ *
413
+ * @param Mage_Sales_Model_Quote $quote
414
+ */
415
+ public function setAliasActive(
416
+ Mage_Sales_Model_Quote $quote,
417
+ Mage_Sales_Model_Order $order = null,
418
+ $saveSalesObjects = false
419
+ ) {
420
+ if (is_null($quote->getPayment()->getAdditionalInformation('userIsRegistering'))
421
+ || false === $quote->getPayment()->getAdditionalInformation('userIsRegistering')
422
+ ) {
423
+ $aliasesToDelete = Mage::helper('ops/alias')->getAliasesForAddresses(
424
+ $quote->getCustomer()->getId(), $quote->getBillingAddress(), $quote->getShippingAddress()
425
+ )
426
+ ->addFieldToFilter('state', Netresearch_OPS_Model_Alias_State::ACTIVE);
427
+ $lastPendingAlias = Mage::helper('ops/alias')->getAliasesForAddresses(
428
+ $quote->getCustomer()->getId(),
429
+ $quote->getBillingAddress(),
430
+ $quote->getShippingAddress(),
431
+ $quote->getStoreId()
432
+ )
433
+ ->addFieldToFilter('alias', $quote->getPayment()->getAdditionalInformation('alias'))
434
+ ->addFieldToFilter('state', Netresearch_OPS_Model_Alias_State::PENDING)
435
+ ->setOrder('created_at', Varien_Data_Collection::SORT_ORDER_DESC)
436
+ ->getFirstItem();
437
+ if (0 < $lastPendingAlias->getId()) {
438
+ foreach ($aliasesToDelete as $alias) {
439
+ $alias->delete();
440
+ }
441
+ $lastPendingAlias->setState(Netresearch_OPS_Model_Alias_State::ACTIVE);
442
+ $lastPendingAlias->save();
443
+ }
444
+ } else {
445
+ $this->setAliasToActiveAfterUserRegisters($order, $quote);
446
+ }
447
+ $this->cleanUpAdditionalInformation($order->getPayment(), false, $saveSalesObjects);
448
+ $this->cleanUpAdditionalInformation($quote->getPayment(), false, $saveSalesObjects);
449
+ }
450
+
451
+ public function setAliasToActiveAfterUserRegisters(
452
+ Mage_Sales_Model_Order $order, Mage_Sales_Model_Quote $quote
453
+ )
454
+ {
455
+ if (true === $quote->getPayment()->getAdditionalInformation('userIsRegistering')
456
+ ) {
457
+ $customerId = $order->getCustomerId();
458
+ $billingAddressHash = $this->generateAddressHash(
459
+ $quote->getBillingAddress()
460
+ );
461
+ $shippingAddressHash = $this->generateAddressHash(
462
+ $quote->getShippingAddress()
463
+ );
464
+ $aliasId = $quote->getPayment()->getAdditionalInformation(
465
+ 'opsAliasId'
466
+ );
467
+ if (is_numeric($aliasId) && 0 < $aliasId) {
468
+ $alias = Mage::getModel('ops/alias')->getCollection()
469
+ ->addFieldToFilter(
470
+ 'alias', $quote->getPayment()->getAdditionalInformation('alias')
471
+ )
472
+ ->addFieldToFilter(
473
+ 'billing_address_hash', $billingAddressHash
474
+ )
475
+ ->addFieldToFilter(
476
+ 'shipping_address_hash', $shippingAddressHash
477
+ )
478
+ ->addFieldToFilter('store_id', array('eq' => $quote->getStoreId()))
479
+ ->getFirstItem();
480
+ if ($alias->getState() === Netresearch_OPS_Model_Alias_State::PENDING
481
+ ) {
482
+ $alias->setState(Netresearch_OPS_Model_Alias_State::ACTIVE);
483
+ $alias->setCustomerId($customerId);
484
+ $alias->save();
485
+ }
486
+ }
487
+ }
488
+ }
489
+
490
+ /**
491
+ * cleans up the stored cvc and storedOPSId
492
+ *
493
+ * @param Mage_Sales_Model_Quote_Payment || Mage_Sales_Model_Order_Payment $payment
494
+ * @param bool $cvcOnly
495
+ * @param bool $savePayment
496
+ *
497
+ */
498
+ public function cleanUpAdditionalInformation($payment, $cvcOnly = false, $savePayment = false)
499
+ {
500
+ if (is_array($payment->getAdditionalInformation())
501
+ && array_key_exists('cvc', $payment->getAdditionalInformation())
502
+ ) {
503
+ $payment->unsAdditionalInformation('cvc');
504
+ }
505
+
506
+ if ($cvcOnly === false && is_array($payment->getAdditionalInformation())
507
+ && array_key_exists('storedOPSId', $payment->getAdditionalInformation())
508
+ ) {
509
+ $payment->unsAdditionalInformation('storedOPSId');
510
+ }
511
+
512
+ /* OGNH-7: seems not to needed anymore since payment and quote is saved after this call,
513
+ otherwise admin payments will fail */
514
+ if ($savePayment) {
515
+ $payment->save();
516
+ }
517
+ }
518
+ }
app/code/community/Netresearch/OPS/Helper/Api.php ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Netresearch_OPS_Helper_Api
4
+ *
5
+ * @package
6
+ * @copyright 2013 Netresearch
7
+ * @author Michael Lühr <michael.luehr@netresearch.de>
8
+ * @author Sebastian Ertner <sebastian.ertner@netresearch.de>
9
+ * @license OSL 3.0
10
+ */
11
+ class Netresearch_OPS_Helper_Api extends Mage_Core_Helper_Abstract
12
+ {
13
+
14
+ private $configModel = null;
15
+
16
+
17
+ /**
18
+ * @param $status - one of the fedd back status
19
+ *
20
+ * @throws Mage_Core_Exception - in case the status is not known
21
+ * @return string - the route for redirect
22
+ */
23
+ public function getRedirectRouteFromStatus($status)
24
+ {
25
+ $route = null;
26
+ $configModel = $this->getConfigModel();
27
+ if ($this->isAcceptStatus($status)) {
28
+ $route = $configModel->getAcceptRedirectRoute();
29
+ }
30
+ if ($this->isCancelStatus($status)) {
31
+ $route = $configModel->getCancelRedirectRoute();
32
+ }
33
+ if ($this->isDeclineStatus($status)) {
34
+ $route = $configModel->getDeclineRedirectRoute();
35
+ }
36
+ if ($this->isExceptionStatus($status)) {
37
+ $route = $configModel->getExceptionRedirectRoute();
38
+ }
39
+
40
+ // in case none of the cases above match then the status is not known
41
+ if (is_null($route)) {
42
+ Mage::throwException('invalid status provided');
43
+ }
44
+
45
+ return $route;
46
+ }
47
+
48
+
49
+ /**
50
+ * config getter
51
+ *
52
+ * @return Netresearch_OPS_Model_Config
53
+ */
54
+ private function getConfigModel()
55
+ {
56
+ if (is_null($this->configModel)) {
57
+ $this->configModel = Mage::getModel('ops/config');
58
+ }
59
+ return $this->configModel;
60
+ }
61
+
62
+ /**
63
+ * determine if the status is known as accepted status
64
+ *
65
+ * @param $status - the status
66
+ *
67
+ * @return bool - true if the status is known as accept status, false otherwise
68
+ */
69
+ private function isAcceptStatus($status)
70
+ {
71
+ return in_array($status, array(
72
+ Netresearch_OPS_Model_Status_Feedback::OPS_ORDER_FEEDBACK_STATUS_ACCEPT
73
+ )
74
+ );
75
+ }
76
+
77
+ /**
78
+ * determine if the status is known as canceled status
79
+ *
80
+ * @param $status - the status
81
+ *
82
+ * @return bool - true if the status is known as canceled status, false otherwise
83
+ */
84
+ private function isCancelStatus($status)
85
+ {
86
+ return in_array($status, array(
87
+ Netresearch_OPS_Model_Status_Feedback::OPS_ORDER_FEEDBACK_STATUS_CANCEL
88
+ )
89
+ );
90
+ }
91
+
92
+ /**
93
+ * determine if the status is known as declined status
94
+ *
95
+ * @param $status - the status
96
+ *
97
+ * @return bool - true if the status is known as declined status, false otherwise
98
+ */
99
+ private function isDeclineStatus($status)
100
+ {
101
+ return in_array($status, array(
102
+ Netresearch_OPS_Model_Status_Feedback::OPS_ORDER_FEEDBACK_STATUS_DECLINE
103
+ )
104
+ );
105
+ }
106
+
107
+ /**
108
+ * determine if the status is known as exception status
109
+ *
110
+ * @param $status - the status
111
+ *
112
+ * @return bool - true if the status is known as exception status, false otherwise
113
+ */
114
+ private function isExceptionStatus($status)
115
+ {
116
+ return in_array($status, array(
117
+ Netresearch_OPS_Model_Status_Feedback::OPS_ORDER_FEEDBACK_STATUS_EXCEPTION
118
+ )
119
+ );
120
+ }
121
+
122
+ }
app/code/community/Netresearch/OPS/Helper/Creditcard.php ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Michael Lühr <michael.luehr@netresearch.de>
4
+ * @category Netresearch
5
+ * @package ${MODULENAME}
6
+ * @copyright Copyright (c) 2013 Netresearch GmbH & Co. KG (http://www.netresearch.de)
7
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
8
+ */
9
+
10
+
11
+ class Netresearch_OPS_Helper_Creditcard extends Netresearch_OPS_Helper_Payment_DirectLink_Request
12
+ {
13
+
14
+ protected $aliasHelper = null;
15
+
16
+ /**
17
+ * @param null $aliasHelper
18
+ */
19
+ public function setAliasHelper($aliasHelper)
20
+ {
21
+ $this->aliasHelper = $aliasHelper;
22
+ }
23
+
24
+ /**
25
+ * @return null
26
+ */
27
+ public function getAliasHelper()
28
+ {
29
+ if (null === $this->aliasHelper) {
30
+ $this->aliasHelper = Mage::helper('ops/alias');
31
+ }
32
+ return $this->aliasHelper;
33
+ }
34
+
35
+
36
+
37
+ /**
38
+ * @param $quote
39
+ * @param $requestParams
40
+ */
41
+ public function handleAdminPayment(Mage_Sales_Model_Quote $quote, $requestParams)
42
+ {
43
+ return $this;
44
+ }
45
+
46
+ protected function getPaymentSpecificParams(Mage_Sales_Model_Quote $quote)
47
+ {
48
+ $alias = $quote->getPayment()->getAdditionalInformation('alias');
49
+ if (is_null($alias) && $this->getDataHelper()->isAdminSession()) {
50
+ $alias = $this->getAliasHelper()->getAlias($quote);
51
+ }
52
+ $params = array (
53
+ 'ALIAS' => $alias,
54
+ );
55
+ if (is_numeric($quote->getPayment()->getAdditionalInformation('cvc'))) {
56
+ $params['CVC'] = $quote->getPayment()->getAdditionalInformation('cvc');
57
+ }
58
+ $requestParams3ds = array();
59
+ if ($this->getConfig()->get3dSecureIsActive() && false == $this->getDataHelper()->isAdminSession()) {
60
+ $requestParams3ds = array(
61
+ 'FLAG3D' => 'Y',
62
+ 'WIN3DS' => Netresearch_OPS_Model_Payment_Abstract::OPS_DIRECTLINK_WIN3DS,
63
+ 'LANGUAGE' => Mage::app()->getLocale()->getLocaleCode(),
64
+ 'HTTP_ACCEPT' => '*/*',
65
+ 'HTTP_USER_AGENT' => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)',
66
+ 'ACCEPTURL' => $this->getConfig()->getAcceptUrl(),
67
+ 'DECLINEURL' => $this->getConfig()->getDeclineUrl(),
68
+ 'EXCEPTIONURL' => $this->getConfig()->getExceptionUrl(),
69
+ );
70
+ }
71
+ $params = array_merge($params, $requestParams3ds);
72
+ return $params;
73
+ }
74
+ }
app/code/community/Netresearch/OPS/Helper/Data.php ADDED
@@ -0,0 +1,163 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Netresearch_OPS_Helper_Data
4
+ *
5
+ * @package
6
+ * @copyright 2011 Netresearch
7
+ * @author Thomas Kappel <thomas.kappel@netresearch.de>
8
+ * @author André Herrn <andre.herrn@netresearch.de>
9
+ * @license OSL 3.0
10
+ */
11
+ class Netresearch_OPS_Helper_Data extends Mage_Core_Helper_Abstract
12
+ {
13
+ const LOG_FILE_NAME = 'ops.log';
14
+
15
+ /**
16
+ * Returns config model
17
+ *
18
+ * @return Netresearch_OPS_Model_Config
19
+ */
20
+ public function getConfig()
21
+ {
22
+ return Mage::getSingleton('ops/config');
23
+ }
24
+
25
+ public function getModuleVersionString()
26
+ {
27
+ $version = Mage::getConfig()->getNode('modules/Netresearch_OPS/version');
28
+ $plainversion = str_replace('.', '', $version);
29
+ return 'IGmg' . $plainversion;
30
+ }
31
+
32
+ /**
33
+ * Checks if logging is enabled and if yes, logs given message to logfile
34
+ *
35
+ * @param string $message
36
+ * @param int $level
37
+ */
38
+ public function log($message, $level = null)
39
+ {
40
+ $separator = "\n"."===================================================================";
41
+ $message = $this->clearMsg($message);
42
+ if ($this->getConfig()->shouldLogRequests()) {
43
+ Mage::log($message.$separator, $level, self::LOG_FILE_NAME);
44
+ }
45
+ }
46
+
47
+ /**
48
+ * Returns full path to ops.log
49
+ */
50
+ public function getLogPath()
51
+ {
52
+ return Mage::getBaseDir('log'). DIRECTORY_SEPARATOR . self::LOG_FILE_NAME;
53
+ }
54
+
55
+
56
+ /**
57
+ * deletes certain keys from the message which is going to logged
58
+ *
59
+ * @param $message - the message
60
+ *
61
+ * @return array - the cleared message
62
+ */
63
+ public function clearMsg($message)
64
+ {
65
+ if (is_array($message)) {
66
+ $keysToBeDeleted = array('cvc', 'CVC');
67
+ foreach ($keysToBeDeleted as $keyToDelete) {
68
+ if (array_key_exists($keyToDelete, $message)) {
69
+ unset($message[$keyToDelete]);
70
+ }
71
+ }
72
+ }
73
+ if (is_string($message)) {
74
+ $message = preg_replace('/"CVC":".*"(,)/i','',$message);
75
+ $message = preg_replace('/"CVC":".*"/i','',$message);
76
+ $message = preg_replace('/"CVC".*"[A-Z]*";/','',$message);
77
+ $message = preg_replace('/"CVC":".*"(})/i','}',$message);
78
+ }
79
+ return $message;
80
+ }
81
+
82
+ public function redirect($url)
83
+ {
84
+ Mage::app()->getResponse()->setRedirect($url);
85
+ Mage::app()->getResponse()->sendResponse();
86
+ exit();
87
+ }
88
+
89
+ /**
90
+ * Redirects to the given order and prints some notice output
91
+ *
92
+ * @param int $orderId
93
+ * @param string $message
94
+ * @return void
95
+ */
96
+ public function redirectNoticed($orderId, $message)
97
+ {
98
+ Mage::getSingleton('core/session')->addNotice($message);
99
+ $this->redirect(
100
+ Mage::getUrl('*/sales_order/view', array('order_id' => $orderId))
101
+ );
102
+ }
103
+
104
+ public function getStatusText($statusCode)
105
+ {
106
+ $translationOrigin = "STATUS_".$statusCode;
107
+ $translationResult = $this->__($translationOrigin);
108
+ if ($translationOrigin != $translationResult):
109
+ return $translationResult. " ($statusCode)";
110
+ else:
111
+ return $statusCode;
112
+ endif;
113
+ }
114
+
115
+ public function getAmount($amount)
116
+ {
117
+ return round($amount * 100);
118
+ }
119
+
120
+ public function getAdminSession()
121
+ {
122
+ return Mage::getSingleton('admin/session');
123
+ }
124
+
125
+ public function isAdminSession()
126
+ {
127
+ if ($this->getAdminSession()->getUser()) {
128
+ return 0 < $this->getAdminSession()->getUser()->getUserId();
129
+ }
130
+ return false;
131
+ }
132
+
133
+ /*
134
+ * check if user is registering or not
135
+ */
136
+ public function checkIfUserIsRegistering()
137
+ {
138
+ $isRegistering = false;
139
+ $checkoutMethod = Mage::getSingleton('checkout/session')->getQuote()->getCheckoutMethod();
140
+ if ($checkoutMethod === Mage_Sales_Model_Quote::CHECKOUT_METHOD_REGISTER
141
+ || $checkoutMethod === Mage_Sales_Model_Quote::CHECKOUT_METHOD_LOGIN_IN
142
+ ) {
143
+ $isRegistering = true;
144
+ }
145
+ return $isRegistering;
146
+
147
+ }
148
+
149
+ /*
150
+ * check if user is registering or not
151
+ */
152
+ public function checkIfUserIsNotRegistering()
153
+ {
154
+ $isRegistering = false;
155
+ $checkoutMethod = Mage::getSingleton('checkout/session')->getQuote()->getCheckoutMethod();
156
+ if ($checkoutMethod === Mage_Sales_Model_Quote::CHECKOUT_METHOD_REGISTER) {
157
+ $isRegistering = true;
158
+ }
159
+ return $isRegistering;
160
+
161
+ }
162
+
163
+ }
app/code/community/Netresearch/OPS/Helper/DirectDebit.php ADDED
@@ -0,0 +1,317 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @author Michael Lühr <michael.luehr@netresearch.de>
5
+ * @category Netresearch
6
+ * @package Netresearch_OPS
7
+ * @copyright Copyright (c) 2013 Netresearch GmbH & Co. KG
8
+ * (http://www.netresearch.de)
9
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
10
+ */
11
+ class Netresearch_OPS_Helper_DirectDebit extends Netresearch_OPS_Helper_Payment_DirectLink_Request
12
+ {
13
+
14
+ protected $dataHelper = null;
15
+
16
+ protected $quoteHelper = null;
17
+
18
+ protected $orderHelper = null;
19
+
20
+ protected $customerHelper = null;
21
+
22
+ protected $validator = null;
23
+
24
+
25
+
26
+
27
+ /**
28
+ * sets the data helper
29
+ *
30
+ * @param Netresearch_OPS_Helper_Data $dataHelper
31
+ */
32
+ public function setDataHelper(Netresearch_OPS_Helper_Data $dataHelper)
33
+ {
34
+ $this->dataHelper = $dataHelper;
35
+ }
36
+
37
+ /**
38
+ * gets the data helper
39
+ *
40
+ * @return Mage_Core_Helper_Abstract
41
+ */
42
+ public function getDataHelper()
43
+ {
44
+ if (null === $this->dataHelper) {
45
+ $this->dataHelper = Mage::helper('ops/data');
46
+ }
47
+
48
+ return $this->dataHelper;
49
+ }
50
+
51
+ /**
52
+ * sets the quote helper
53
+ *
54
+ * @param Netresearch_OPS_Helper_Quote $quoteHelper
55
+ */
56
+ public function setQuoteHelper(Netresearch_OPS_Helper_Quote $quoteHelper)
57
+ {
58
+ $this->quoteHelper = $quoteHelper;
59
+ }
60
+
61
+ /**
62
+ * gets the quote helper
63
+ *
64
+ * @return Mage_Core_Helper_Abstract
65
+ */
66
+ public function getQuoteHelper()
67
+ {
68
+ if (null === $this->quoteHelper) {
69
+ $this->quoteHelper = Mage::helper('ops/quote');
70
+ }
71
+
72
+ return $this->quoteHelper;
73
+ }
74
+
75
+ /**
76
+ * sets the order helper
77
+ *
78
+ * @param Netresearch_OPS_Helper_Order $orderHelper
79
+ */
80
+ public function setOrderHelper(Netresearch_OPS_Helper_Order $orderHelper)
81
+ {
82
+ $this->orderHelper = $orderHelper;
83
+ }
84
+
85
+ /**
86
+ * gets the order helper
87
+ *
88
+ * @return Mage_Core_Helper_Abstract
89
+ */
90
+ public function getOrderHelper()
91
+ {
92
+ if (null === $this->orderHelper) {
93
+ $this->orderHelper = Mage::helper('ops/order');
94
+ }
95
+
96
+ return $this->orderHelper;
97
+ }
98
+
99
+ /**
100
+ * sets the customer helper
101
+ *
102
+ * @param Mage_Core_Helper_Abstract $customerHelper
103
+ */
104
+ public function setCustomerHelper(Mage_Core_Helper_Abstract $customerHelper)
105
+ {
106
+ $this->customerHelper = $customerHelper;
107
+ }
108
+
109
+ /**
110
+ * gets the customer helper
111
+ *
112
+ * @return Mage_Core_Helper_Abstract
113
+ */
114
+ public function getCustomerHelper()
115
+ {
116
+ if (null === $this->customerHelper) {
117
+ $this->customerHelper = Mage::helper('customer/data');
118
+ }
119
+
120
+ return $this->customerHelper;
121
+ }
122
+
123
+
124
+ /**
125
+ * sets the validator
126
+ *
127
+ * @param Netresearch_OPS_Model_Validator_Payment_DirectDebit $validator
128
+ */
129
+ public function setValidator(
130
+ Netresearch_OPS_Model_Validator_Payment_DirectDebit $validator
131
+ )
132
+ {
133
+ $this->validator = $validator;
134
+ }
135
+
136
+ /**
137
+ * gets the validator
138
+ *
139
+ * @return Netresearch_OPS_Model_Validator_Payment_DirectDebit
140
+ */
141
+ public function getValidator()
142
+ {
143
+ if (null === $this->validator) {
144
+ $this->validator = Mage::getModel(
145
+ 'ops/validator_payment_directDebit'
146
+ );
147
+ }
148
+
149
+ return $this->validator;
150
+ }
151
+
152
+ /**
153
+ * gets the country from a given array
154
+ *
155
+ * @param array $params
156
+ *
157
+ * @return string - the country in uppercase, empty string if no country
158
+ * was provided
159
+ */
160
+ public function getCountry(array $params)
161
+ {
162
+ $country = '';
163
+ if (array_key_exists('country', $params)) {
164
+ $country = strtoupper($params['country']);
165
+ }
166
+
167
+ return $country;
168
+ }
169
+
170
+ /**
171
+ * checks whether the given data has an iban field or not
172
+ *
173
+ * @param array $accountData
174
+ *
175
+ * @return bool - true if iban field is present and filled, false otherwise
176
+ */
177
+ public function hasIban(array $accountData)
178
+ {
179
+ return array_key_exists('iban', $accountData)
180
+ && 0 < strlen(trim($accountData['iban']));
181
+ }
182
+
183
+ /**
184
+ * sets the direct debit data to given payment
185
+ *
186
+ * @param Mage_Sales_Model_Quote_Payment $payment - the payment which
187
+ * should contain the
188
+ * additional data
189
+ * @param array $params -
190
+ *
191
+ * @return Mage_Sales_Model_Quote_Payment
192
+ */
193
+ public function setDirectDebitDataToPayment(
194
+ Mage_Sales_Model_Quote_Payment $payment, array $params
195
+ )
196
+ {
197
+ $payment->setAdditionalInformation(
198
+ 'PM', 'Direct Debits ' . $this->getCountry($params)
199
+ );
200
+ $this->setAccountHolder($payment, $params);
201
+ $this->setAccountData($payment, $params);
202
+
203
+ return $payment;
204
+ }
205
+
206
+ /**
207
+ * sets the account holder to given payment
208
+ *
209
+ * @param Mage_Sales_Model_Quote_Payment $payment
210
+ * @param array $params
211
+ */
212
+ protected function setAccountHolder(
213
+ Mage_Sales_Model_Quote_Payment $payment, array $params
214
+ )
215
+ {
216
+ if (array_key_exists('CN', $params)
217
+ && 0 < strlen(trim($params['CN']))
218
+ ) {
219
+ $payment->setAdditionalInformation('CN', trim($params['CN']));
220
+ }
221
+ }
222
+
223
+ /**
224
+ * set the account data to given payment
225
+ *
226
+ * @param Mage_Sales_Model_Quote_Payment $payment
227
+ * @param array $params
228
+ */
229
+ protected function setAccountData(
230
+ Mage_Sales_Model_Quote_Payment $payment, array $params
231
+ )
232
+ {
233
+ $country = $this->getCountry($params);
234
+
235
+ if ('DE' == $country || 'AT' == $country) {
236
+ if ($this->hasIban($params) && 'DE' == $country) {
237
+ $payment->setAdditionalInformation(
238
+ 'CARDNO', trim($params['iban'])
239
+ );
240
+ } else {
241
+ $payment->setAdditionalInformation(
242
+ 'CARDNO',
243
+ trim($params['account']) . 'BLZ' . trim($params['bankcode'])
244
+ );
245
+ }
246
+
247
+
248
+ }
249
+ if ('NL' == $country) {
250
+ if ($this->hasIban($params)) {
251
+ $payment->setAdditionalInformation(
252
+ 'CARDNO', trim($params['iban'])
253
+ );
254
+ $payment->setAdditionalInformation('BIC', trim($params['bic']));
255
+ } else {
256
+ $payment->setAdditionalInformation(
257
+ 'CARDNO', str_pad($params['account'], '0', STR_PAD_LEFT)
258
+ );
259
+ }
260
+ }
261
+ }
262
+
263
+ /**
264
+ * validates direct debit payment from the backend
265
+ *
266
+ * @param $requestParams - the params passed on order submission
267
+ * @throws Mage_Core_Exception - if the data is not valid
268
+ * @return boolean - true if data were valid
269
+ */
270
+ protected function validateAdminDirectDebit($requestParams)
271
+ {
272
+ $validator = $this->getValidator();
273
+ if (false === $validator->isValid($requestParams)) {
274
+ Mage::getModel('adminhtml/session')->setData('ops_direct_debit_params', $requestParams);
275
+ Mage::throwException(
276
+ implode('<br />', $validator->getMessages())
277
+ );
278
+ }
279
+ return true;
280
+ }
281
+
282
+ /**
283
+ * @param Mage_Sales_Model_Quote $quote
284
+ * @param array $requestParams
285
+ * @return Netresearch_OPS_Helper_DirectDebit
286
+ */
287
+ public function handleAdminPayment(Mage_Sales_Model_Quote $quote, $requestParams)
288
+ {
289
+ if ($this->getDataHelper()->isAdminSession() && is_array($requestParams)) {
290
+ $this->validateAdminDirectDebit($requestParams);
291
+ $this->setDirectDebitDataToPayment($quote->getPayment(), $requestParams);
292
+ $quote->getPayment()->save();
293
+ }
294
+
295
+ return $this;
296
+ }
297
+
298
+ protected function getPaymentSpecificParams(Mage_Sales_Model_Quote $quote)
299
+ {
300
+ $cardHolderName = $quote->getPayment()->getAdditionalInformation('CN');
301
+ $params = array(
302
+ 'CARDNO' => $quote->getPayment()->getAdditionalInformation('CARDNO'),
303
+ 'CN' => utf8_decode($cardHolderName),
304
+ // Always the same on direct debit
305
+ 'ED' => '9999',
306
+ 'PM' => $quote->getPayment()->getAdditionalInformation('PM'),
307
+ );
308
+ if (0 < strlen(trim($quote->getPayment()->getAdditionalInformation('BIC')))) {
309
+ $bic = $quote->getPayment()->getAdditionalInformation('BIC');
310
+ $params['BIC'] = $bic;
311
+ }
312
+ $params['BRAND'] = $params['PM'];
313
+
314
+ return $params;
315
+ }
316
+ }
317
+
app/code/community/Netresearch/OPS/Helper/Directlink.php ADDED
@@ -0,0 +1,446 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Netresearch_OPS_Helper_DirectLink
4
+ *
5
+ * @package
6
+ * @copyright 2011 Netresearch
7
+ * @author André Herrn <andre.herrn@netresearch.de>
8
+ * @license OSL 3.0
9
+ */
10
+ class Netresearch_OPS_Helper_Directlink extends Mage_Core_Helper_Abstract
11
+ {
12
+ /**
13
+ * Creates Transactions for directlink activities
14
+ *
15
+ * @param Mage_Sales_Model_Order $order
16
+ * @param int $transactionID - persistent transaction id
17
+ * @param int $subPayID - identifier for each transaction
18
+ * @param array $arrInformation - add dynamic data
19
+ * @param string $typename - name for the transaction exp.: refund
20
+ * @param string $comment - order comment
21
+ *
22
+ * @return Netresearch_OPS_Helper_Directlink $this
23
+ */
24
+ public function directLinkTransact($order,$transactionID, $subPayID,
25
+ $arrInformation = array(), $typename, $comment, $closed = 0)
26
+ {
27
+ $payment = $order->getPayment();
28
+ $payment->setTransactionId($transactionID."/".$subPayID);
29
+ $transaction = $payment->addTransaction($typename, null, false, $comment);
30
+ $transaction->setParentTxnId($transactionID);
31
+ $transaction->setIsClosed($closed);
32
+ $transaction->setAdditionalInformation("arrInfo", serialize($arrInformation));
33
+ $transaction->save();
34
+ $order->save();
35
+ return $this;
36
+ }
37
+
38
+ /**
39
+ * Checks if there is an active transaction for a special order for special
40
+ * type
41
+ *
42
+ * @param string $type - refund, capture etc.
43
+ * @param int $orderID
44
+ * @return bol success
45
+ */
46
+ public function checkExistingTransact($type, $orderID)
47
+ {
48
+ $transaction = Mage::getModel('sales/order_payment_transaction')
49
+ ->getCollection()
50
+ ->addAttributeToFilter('order_id', $orderID)
51
+ ->addAttributeToFilter('txn_type', $type)
52
+ ->addAttributeToFilter('is_closed', 0)
53
+ ->getLastItem();
54
+
55
+ return ($transaction->getTxnId()) ? true : false;
56
+ }
57
+
58
+ /**
59
+ * get transaction type for given OPS status
60
+ *
61
+ * @param string $status
62
+ *
63
+ * @return string
64
+ */
65
+ public function getTypeForStatus($status)
66
+ {
67
+ switch ($status) {
68
+ case Netresearch_OPS_Model_Payment_Abstract::OPS_REFUNDED :
69
+ case Netresearch_OPS_Model_Payment_Abstract::OPS_REFUND_WAITING:
70
+ case Netresearch_OPS_Model_Payment_Abstract::OPS_REFUND_UNCERTAIN_STATUS :
71
+ case Netresearch_OPS_Model_Payment_Abstract::OPS_REFUND_REFUSED :
72
+ case Netresearch_OPS_Model_Payment_Abstract::OPS_REFUND_DECLINED_ACQUIRER :
73
+ return Netresearch_OPS_Model_Payment_Abstract::OPS_REFUND_TRANSACTION_TYPE;
74
+ case Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_REQUESTED :
75
+ case Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_PROCESSED_MERCHANT :
76
+ case Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_PROCESSING:
77
+ case Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_UNCERTAIN:
78
+ case Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_IN_PROGRESS:
79
+ case Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_REFUSED:
80
+ case Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_DECLINED_ACQUIRER:
81
+ return Netresearch_OPS_Model_Payment_Abstract::OPS_CAPTURE_TRANSACTION_TYPE;
82
+ case Netresearch_OPS_Model_Payment_Abstract::OPS_VOIDED: //Void finished
83
+ case Netresearch_OPS_Model_Payment_Abstract::OPS_VOIDED_ACCEPTED:
84
+ case Netresearch_OPS_Model_Payment_Abstract::OPS_VOID_WAITING:
85
+ case Netresearch_OPS_Model_Payment_Abstract::OPS_VOID_UNCERTAIN:
86
+ case Netresearch_OPS_Model_Payment_Abstract::OPS_VOID_REFUSED:
87
+ return Netresearch_OPS_Model_Payment_Abstract::OPS_VOID_TRANSACTION_TYPE;
88
+ case Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_DELETED:
89
+ case Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_DELETED_WAITING:
90
+ case Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_DELETED_UNCERTAIN:
91
+ case Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_DELETED_REFUSED:
92
+ case Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_DELETED_OK:
93
+ case Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_DELETED_PROCESSED_MERCHANT:
94
+ return Netresearch_OPS_Model_Payment_Abstract::OPS_DELETE_TRANSACTION_TYPE;
95
+ }
96
+ }
97
+
98
+ /**
99
+ * Process Direct Link Feedback to do: Capture, De-Capture and Refund
100
+ *
101
+ * @param Mage_Sales_Model_Order $order Order
102
+ * @param array $params Request params
103
+ *
104
+ * @return void
105
+ */
106
+ public function processFeedback($order, $params)
107
+ {
108
+ $transaction = null;
109
+ if ($params['STATUS'] < 50 || $params['STATUS'] >= 60) {
110
+ try {
111
+ $transaction = $this->getPaymentTransaction($order, null, $this->getTypeForStatus($params['STATUS']));
112
+ } catch (Mage_Core_Exception $e) {
113
+ $transaction = null;
114
+ }
115
+ }
116
+ if (false == $this->isValidOpsRequest($transaction, $order, $params)) {
117
+ $order->addStatusHistoryComment(
118
+ Mage::helper('ops')->__(
119
+ 'Could not perform actions for Ingenico Payment Services status: %s.',
120
+ Mage::helper('ops')->getStatusText($params['STATUS'])
121
+ )
122
+ )->save();
123
+ throw new Mage_Core_Exception('invalid Ingenico Payment Services request');
124
+ }
125
+
126
+ Mage::helper('ops/payment')->saveOpsStatusToPayment($order->getPayment(), $params);
127
+ switch ($params['STATUS']) {
128
+ case Netresearch_OPS_Model_Payment_Abstract::OPS_INVALID :
129
+ break;
130
+
131
+ /*
132
+ * Refund Actions
133
+ */
134
+ case Netresearch_OPS_Model_Payment_Abstract::OPS_REFUNDED :
135
+ case Netresearch_OPS_Model_Payment_Abstract::OPS_REFUND_PROCESSED_MERCHANT :
136
+ Mage::helper('ops/order_refund')->createRefund($order, $params);
137
+ break;
138
+ case Netresearch_OPS_Model_Payment_Abstract::OPS_REFUND_WAITING:
139
+ case Netresearch_OPS_Model_Payment_Abstract::OPS_REFUND_UNCERTAIN_STATUS :
140
+ $order->addStatusHistoryComment(
141
+ Mage::helper('ops')->__(
142
+ 'Refund is waiting or uncertain. Ingenico Payment Services status: %s.',
143
+ Mage::helper('ops')->getStatusText($params['STATUS'])
144
+ )
145
+ );
146
+ $order->save();
147
+ break;
148
+ case Netresearch_OPS_Model_Payment_Abstract::OPS_REFUND_REFUSED :
149
+ case Netresearch_OPS_Model_Payment_Abstract::OPS_REFUND_DECLINED_ACQUIRER :
150
+ $this->closePaymentTransaction(
151
+ $order,
152
+ $params,
153
+ Netresearch_OPS_Model_Payment_Abstract::OPS_REFUND_TRANSACTION_TYPE,
154
+ Mage::helper('ops')->__(
155
+ 'Refund was refused. Automatic creation failed. Ingenico Payment Services status: %s.',
156
+ Mage::helper('ops')->getStatusText($params['STATUS'])
157
+ )
158
+ );
159
+ break;
160
+
161
+ /*
162
+ * Capture Actions
163
+ */
164
+ case Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_REQUESTED :
165
+ case Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_PROCESSED_MERCHANT :
166
+ Mage::helper("ops/order_capture")->acceptCapture($order, $params);
167
+ break;
168
+ case Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_PROCESSING:
169
+ case Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_UNCERTAIN:
170
+ case Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_IN_PROGRESS:
171
+ $order->addStatusHistoryComment(
172
+ Mage::helper('ops')->__(
173
+ 'Capture is waiting or uncertain. Ingenico Payment Services status: %s.',
174
+ Mage::helper('ops')->getStatusText($params['STATUS'])
175
+ )
176
+ );
177
+ $order->save();
178
+ break;
179
+ case Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_REFUSED:
180
+ case Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_DECLINED_ACQUIRER:
181
+ case Netresearch_OPS_Model_Payment_Abstract::OPS_AUTH_REFUSED :
182
+ $this->closePaymentTransaction(
183
+ $order,
184
+ $params,
185
+ Netresearch_OPS_Model_Payment_Abstract::OPS_CAPTURE_TRANSACTION_TYPE,
186
+ Mage::helper('ops')->__(
187
+ 'Capture was refused. Automatic creation failed. Ingenico Payment Services status: %s.',
188
+ Mage::helper('ops')->getStatusText($params['STATUS'])
189
+ )
190
+ );
191
+ break;
192
+
193
+ /*
194
+ * Void Actions
195
+ */
196
+ case Netresearch_OPS_Model_Payment_Abstract::OPS_VOIDED: //Void finished
197
+ case Netresearch_OPS_Model_Payment_Abstract::OPS_VOIDED_ACCEPTED:
198
+ Mage::helper("ops/order_void")->acceptVoid($order, $params);
199
+ break;
200
+ case Netresearch_OPS_Model_Payment_Abstract::OPS_VOID_WAITING:
201
+ case Netresearch_OPS_Model_Payment_Abstract::OPS_VOID_UNCERTAIN:
202
+ $order->addStatusHistoryComment(
203
+ Mage::helper('ops')->__(
204
+ 'Void is waiting or uncertain. Ingenico Payment Services status: %s.',
205
+ Mage::helper('ops')->getStatusText($params['STATUS'])
206
+ )
207
+ );
208
+ $order->save();
209
+ break;
210
+ case Netresearch_OPS_Model_Payment_Abstract::OPS_VOID_REFUSED:
211
+ $this->closePaymentTransaction(
212
+ $order,
213
+ $params,
214
+ Netresearch_OPS_Model_Payment_Abstract::OPS_VOID_TRANSACTION_TYPE,
215
+ Mage::helper('ops')->__(
216
+ 'Void was refused. Automatic creation failed. Ingenico Payment Services status: %s.',
217
+ Mage::helper('ops')->getStatusText($params['STATUS'])
218
+ )
219
+ );
220
+ break;
221
+
222
+ /*
223
+ * Authorize Actions
224
+ */
225
+ case Netresearch_OPS_Model_Payment_Abstract::OPS_AUTHORIZED:
226
+ case Netresearch_OPS_Model_Payment_Abstract::OPS_AUTHORIZED_WAITING:
227
+ case Netresearch_OPS_Model_Payment_Abstract::OPS_AUTHORIZED_UNKNOWN:
228
+ case Netresearch_OPS_Model_Payment_Abstract::OPS_AUTHORIZED_TO_GET_MANUALLY:
229
+ case Netresearch_OPS_Model_Payment_Abstract::OPS_AUTHORIZED_KWIXO:
230
+ if ($params['STATUS'] == Netresearch_OPS_Model_Payment_Abstract::OPS_AUTHORIZED
231
+ && $order->getPayment()->getMethodInstance() instanceof Netresearch_OPS_Model_Payment_Kwixo_Abstract) {
232
+ Mage::helper('ops/data')->log('acceptOrder in directLink helper');
233
+ Mage::helper('ops/payment')->acceptOrder($order, $params);
234
+ $comment = Mage::helper('ops')->__('Authorization status changed. Current Ingenico Payment Services status is: %s.', Mage::helper('ops')->getStatusText($params['STATUS']));
235
+ // $this->closePaymentTransaction($order, null, 'authorization', "", false);
236
+ } else {
237
+ $order->addStatusHistoryComment(Mage::helper('ops')->__('Authorization status changed. Current Ingenico Payment Services status is: %s.', Mage::helper('ops')->getStatusText($params['STATUS'])));
238
+ $order->save();
239
+ }
240
+ break;
241
+ default:
242
+ $order->addStatusHistoryComment(
243
+ Mage::helper('ops')->__('Unknown Ingenico Payment Services status: %s.', Mage::helper('ops')->getStatusText($params['STATUS']))
244
+ );
245
+ $order->save();
246
+ Mage::helper("ops")->log("Unknown status code:".$params['STATUS']);
247
+ break;
248
+ }
249
+ }
250
+
251
+ /**
252
+ * Get the payment transaction by PAYID and Operation
253
+ *
254
+ * @param Mage_Sales_Model_Order $order
255
+ * @param int $payid
256
+ * @param string $authorization
257
+ *
258
+ * @return Mage_Sales_Model_Order_Payment_Transaction
259
+ */
260
+ public function getPaymentTransaction($order, $payid, $operation)
261
+ {
262
+ $helper = Mage::helper('ops');
263
+ $transactionCollection = Mage::getModel('sales/order_payment_transaction')
264
+ ->getCollection()
265
+ ->addAttributeToFilter('txn_type', $operation)
266
+ ->addAttributeToFilter('is_closed', 0)
267
+ ->addAttributeToFilter('order_id', $order->getId());
268
+ if ($payid != '') {
269
+ $transactionCollection->addAttributeToFilter('parent_txn_id', $payid);
270
+ }
271
+
272
+ if ($transactionCollection->count()>1 || $transactionCollection->count() == 0) {
273
+ $errorMsq = $helper->__(
274
+ 'Warning, transaction count is %s instead of 1 for the Payid "%s", order "%s" and Operation "%s".',
275
+ $transactionCollection->count(),
276
+ $payid,
277
+ $order->getId(),
278
+ $operation
279
+ );
280
+ $helper->log($errorMsq);
281
+ throw new Mage_Core_Exception($errorMsq);
282
+ }
283
+
284
+ if ($transactionCollection->count() == 1) {
285
+ $transaction = $transactionCollection->getLastItem();
286
+ $transaction->setOrderPaymentObject($order->getPayment());
287
+ return $transaction;
288
+ }
289
+ }
290
+
291
+
292
+ /**
293
+ * Check if there are payment transactions for an order and an operation
294
+ *
295
+ * @param Mage_Sales_Model_Order $order
296
+ * @param string $authorization
297
+ *
298
+ * @return boolean
299
+ */
300
+ public function hasPaymentTransactions($order, $operation)
301
+ {
302
+ $transactionCollection = Mage::getModel('sales/order_payment_transaction')
303
+ ->getCollection()
304
+ ->addAttributeToFilter('txn_type', $operation)
305
+ ->addAttributeToFilter('is_closed', 0)
306
+ ->addAttributeToFilter('order_id', $order->getId());
307
+
308
+ return (0 < $transactionCollection->count());
309
+ }
310
+
311
+ /**
312
+ * validate incoming and internal amount value format and convert it to float
313
+ *
314
+ * @param string
315
+ * @return float
316
+ */
317
+ public function formatAmount($amount)
318
+ {
319
+ // Avoid quotes added somewhere unknown
320
+ if (preg_match("/^[\"']([0-9-\..,-]+)[\"']$/i", $amount, $matches)) {
321
+ Mage::helper('ops')->log("Warning in formatAmount: Found quotes around amount in '" . var_export($amount, true) . "'");
322
+ $amount = $matches[1];
323
+ }
324
+
325
+ return number_format($amount, 2);
326
+ }
327
+
328
+ /**
329
+ * determine if the current OPS request is valid
330
+ *
331
+ * @param array $transactions Iteratable of Mage_Sales_Model_Order_Payment_Transaction
332
+ * @param Mage_Sales_Model_Order $order
333
+ * @param array $opsRequestParams
334
+ *
335
+ * @return boolean
336
+ */
337
+ public function isValidOpsRequest($openTransaction, Mage_Sales_Model_Order $order, $opsRequestParams)
338
+ {
339
+ if ($this->getTypeForStatus($opsRequestParams['STATUS']) == Netresearch_OPS_Model_Payment_Abstract::OPS_DELETE_TRANSACTION_TYPE) {
340
+ return false;
341
+ }
342
+
343
+ $requestedAmount = null;
344
+ if (array_key_exists('amount', $opsRequestParams)) {
345
+ $requestedAmount = $this->formatAmount($opsRequestParams['amount']);
346
+ }
347
+
348
+ /* find expected amount */
349
+ $expectedAmount = null;
350
+ if (false === is_null($openTransaction)) {
351
+ $transactionInfo = unserialize($openTransaction->getAdditionalInformation('arrInfo'));
352
+ if (array_key_exists('amount', $transactionInfo)) {
353
+ if (
354
+ is_null($expectedAmount)
355
+ || $transactionInfo['amount'] == $requestedAmount
356
+ ) {
357
+ $expectedAmount = $this->formatAmount($transactionInfo['amount']);
358
+ }
359
+ }
360
+ }
361
+
362
+ if ($this->getTypeForStatus($opsRequestParams['STATUS']) == Netresearch_OPS_Model_Payment_Abstract::OPS_REFUND_TRANSACTION_TYPE
363
+ || $this->getTypeForStatus($opsRequestParams['STATUS']) == Netresearch_OPS_Model_Payment_Abstract::OPS_VOID_TRANSACTION_TYPE
364
+ ) {
365
+ if (is_null($requestedAmount)
366
+ || 0 == count($openTransaction)
367
+ || $requestedAmount != $expectedAmount
368
+ ) {
369
+ return false;
370
+ }
371
+ }
372
+
373
+ if ($this->getTypeForStatus($opsRequestParams['STATUS']) == Netresearch_OPS_Model_Payment_Abstract::OPS_CAPTURE_TRANSACTION_TYPE) {
374
+ if (is_null($requestedAmount)) {
375
+ Mage::helper('ops')->log('Please configure Ingenico Payment Services to submit amount');
376
+ return false;
377
+ }
378
+ $grandTotal = $this->formatAmount(Mage::helper('ops/payment')->getBaseGrandTotalFromSalesObject($order));
379
+ if ($grandTotal != $requestedAmount) {
380
+ if (is_null($openTransaction)
381
+ || $expectedAmount != $requestedAmount
382
+ ) {
383
+ return false;
384
+ }
385
+ }
386
+ }
387
+ return true;
388
+ }
389
+
390
+ /**
391
+ * Close a payment transaction
392
+ *
393
+ * @param Mage_Sales_Model_Order $order
394
+ * @param array $params
395
+ *
396
+ * @return Mage_Sales_Model_Order_Payment_Transaction
397
+ */
398
+ public function closePaymentTransaction($order, $params, $type, $comment = "", $isCustomerNotified = false)
399
+ {
400
+ try {
401
+ $transaction = Mage::helper('ops/directlink')->getPaymentTransaction(
402
+ $order,
403
+ $params['PAYID'],
404
+ $type
405
+ );
406
+
407
+ if (1 !== $transaction->getIsClosed()) {
408
+ $transaction->setIsClosed(1);
409
+ $transaction->save();
410
+ }
411
+
412
+ $transactionId = $transaction->getTxnId();
413
+ if ($comment) {
414
+ $comment .= ' Transaction ID: '.'"'.$transactionId.'"';
415
+ $order
416
+ ->addStatusHistoryComment($comment)
417
+ ->setIsCustomerNotified($isCustomerNotified);
418
+ }
419
+
420
+ } catch (Exception $e) {
421
+ if (array_key_exists('STATUS', $params) && in_array($params['STATUS'], array(Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_REFUSED,
422
+ Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_DECLINED_ACQUIRER))) {
423
+ Mage::helper('ops/payment')->declineOrder($order, $params);
424
+ }
425
+
426
+ }
427
+
428
+ $order->save();
429
+ }
430
+
431
+ public function performDirectLinkRequest($quote, $params, $storeId = null)
432
+ {
433
+ $url = Mage::getModel('ops/config')->getDirectLinkGatewayOrderPath($storeId);
434
+ $response = Mage::getSingleton('ops/api_directlink')->performRequest($params, $url, $storeId);
435
+ /**
436
+ * allow null as valid state for creating the order with status 'pending'
437
+ */
438
+ if (!is_null($response['STATUS'])
439
+ && Mage::helper('ops/payment')->isPaymentFailed($response['STATUS'])
440
+ ) {
441
+ Mage::getSingleton('checkout/type_onepage')->getCheckout()->setGotoSection('payment');
442
+ throw new Mage_Core_Exception(Mage::helper('ops/data')->__('Ingenico Payment Services Payment failed'));
443
+ }
444
+ return $response;
445
+ }
446
+ }
app/code/community/Netresearch/OPS/Helper/Kwixo.php ADDED
@@ -0,0 +1,173 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Netresearch_OPS_Helper_Kwixo
5
+ *
6
+ * @package
7
+ * @copyright 2013 Netresearch
8
+ * @author Michael Lühr <michael.luehr@netresearch.de>
9
+ * @license OSL 3.0
10
+ */
11
+ class Netresearch_OPS_Helper_Kwixo extends Mage_Core_Helper_Abstract
12
+ {
13
+
14
+ private $helper = null;
15
+
16
+ protected function getHelper()
17
+ {
18
+ if (null === $this->helper) {
19
+ $this->helper = Mage::helper('ops/data');
20
+ }
21
+
22
+ return $this->helper;
23
+ }
24
+
25
+ /**
26
+ * validates the kwixoConfiguration data
27
+ *
28
+ * @param array $postData the data to validate
29
+ *
30
+ * @throws Mage_Core_Exception on errors
31
+ *
32
+ */
33
+ public function validateKwixoconfigurationMapping(array $postData)
34
+ {
35
+ $this->validateKwixoConfigurationData($postData);
36
+ $this->validateKwixoMappingExist($postData);
37
+ $this->validateCategoryExist($postData);
38
+ }
39
+
40
+ /**
41
+ * saves the KwixoConfigurationMapping
42
+ *
43
+ * @param array $postData
44
+ */
45
+ public function saveKwixoconfigurationMapping(array $postData)
46
+ {
47
+ $this->validateKwixoconfigurationMapping($postData);
48
+ $kwixoCatMapModel = Mage::getModel(
49
+ 'ops/kwixo_category_mapping'
50
+ )->load($postData['id']);
51
+ $kwixoCatMapModel->setCategoryId($postData['category_id']);
52
+ $kwixoCatMapModel->setKwixoCategoryId(
53
+ $postData['kwixoCategory_id']
54
+ );
55
+ $kwixoCatMapModel->save();
56
+ if (array_key_exists('applysubcat', $postData)) {
57
+ $category = Mage::getModel('catalog/category')->load(
58
+ $postData['category_id']
59
+ );
60
+ $subcategories = $category->getAllChildren(true);
61
+ foreach ($subcategories as $subcategory) {
62
+ $kwixoCatMapModel = Mage::getModel(
63
+ 'ops/kwixo_category_mapping'
64
+ )->loadByCategoryId($subcategory);
65
+ $kwixoCatMapModel->setCategoryId($subcategory);
66
+ $kwixoCatMapModel->setKwixoCategoryId(
67
+ $postData['kwixoCategory_id']
68
+ );
69
+ $kwixoCatMapModel->save();
70
+ }
71
+ }
72
+ Mage::getSingleton('adminhtml/session')->addSuccess(
73
+ Mage::helper('ops/data')->__(
74
+ 'Successfully added Kwixo category mapping'
75
+ )
76
+ );
77
+ }
78
+
79
+
80
+ /**
81
+ * validates if the structure of a given array does match the expected kwixo
82
+ * setting configuration
83
+ *
84
+ * @param array $postData - the array to inspect
85
+ *
86
+ * @throws Mage_Core_Exception - if the structure does not match
87
+ */
88
+ private function validateKwixoConfigurationData(array $postData)
89
+ {
90
+ $helper = $this->getHelper();
91
+ $isValid = true;
92
+ $message = '';
93
+ if (0 === count($postData)) {
94
+ $message = $helper->__('Invalid form data provided');
95
+ $isValid = false;
96
+ }
97
+
98
+ if ($isValid && !array_key_exists('id', $postData)) {
99
+ $message = $helper->__('Invalid form data provided');
100
+ $isValid = false;
101
+ }
102
+
103
+ if ($isValid && 0 < strlen($postData['id'])
104
+ && (!is_numeric($postData['id'])
105
+ || $postData['id'] < 0)
106
+ ) {
107
+ $message = $helper->__('Invalid id provided');
108
+ $isValid = false;
109
+ }
110
+ if (false === $isValid) {
111
+ Mage::throwException($message);
112
+ }
113
+ }
114
+
115
+ /**
116
+ * validates if the given array contains the neccessary information for
117
+ * a proper kwixo category setting
118
+ *
119
+ * @param array $postData - the array to inspect
120
+ *
121
+ * @throws Mage_Core_Exception - if the array does not contain the needed
122
+ * information
123
+ *
124
+ */
125
+ private function validateKwixoMappingExist(array $postData)
126
+ {
127
+ $helper = $this->getHelper();
128
+ $kwixoCategories = Mage::getModel('ops/source_kwixo_productCategories')
129
+ ->getValidKwixoCategoryIds();
130
+ if (!array_key_exists('kwixoCategory_id', $postData)
131
+ || !in_array(
132
+ $postData['kwixoCategory_id'], $kwixoCategories
133
+ )
134
+ ) {
135
+ Mage::throwException(
136
+ $helper->__('Invalid kwixo category provided')
137
+ );
138
+ }
139
+ }
140
+
141
+ /**
142
+ * validates if the given array contains a proper category setting
143
+ *
144
+ * @param array $postData - the array to inspect
145
+ *
146
+ * @throws Mage_Core_Exception - if an invalid setting is given
147
+ */
148
+ private function validateCategoryExist(array $postData)
149
+ {
150
+ $helper = $this->getHelper();
151
+ $isValid = true;
152
+ $message = '';
153
+ if (!array_key_exists('category_id', $postData)) {
154
+ $isValid = false;
155
+ $message = $helper->__('Invalid category provided');
156
+
157
+ }
158
+ if ($isValid
159
+ && (!is_numeric($postData['category_id'])
160
+ || is_null(
161
+ Mage::getModel('catalog/category')->load(
162
+ $postData['category_id']
163
+ )->getId()
164
+ ))
165
+ ) {
166
+ $isValid = false;
167
+ $message = $helper->__('Invalid category provided');
168
+ }
169
+ if (false === $isValid) {
170
+ Mage::throwException($message);
171
+ }
172
+ }
173
+ }
app/code/community/Netresearch/OPS/Helper/Order.php ADDED
@@ -0,0 +1,198 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Netresearch_OPS_Helper_Order
5
+ *
6
+ * @package
7
+ * @copyright 2013 Netresearch
8
+ * @author Michael Lühr <michael.luehr@netresearch.de>
9
+ * @license OSL 3.0
10
+ */
11
+ class Netresearch_OPS_Helper_Order extends Mage_Core_Helper_Abstract
12
+ {
13
+
14
+ const DELIMITER = '#';
15
+
16
+ /** @var $config Netresearch_OPS_Model_Config */
17
+ private $config = null;
18
+
19
+ protected $statusMappingModel = null;
20
+
21
+ /**
22
+ * @param Netresearch_OPS_Helper_Data $dataHelper
23
+ */
24
+ public function setDataHelper(Netresearch_OPS_Helper_Data $dataHelper)
25
+ {
26
+ $this->dataHelper = $dataHelper;
27
+ }
28
+
29
+ /**
30
+ * @return Netresearch_OPS_Helper_Data
31
+ */
32
+ public function getDataHelper()
33
+ {
34
+ if (null === $this->dataHelper) {
35
+ $this->dataHelper = Mage::helper('ops/data');
36
+ }
37
+
38
+ return $this->dataHelper;
39
+ }
40
+
41
+ /**
42
+ * @param null $statusMappingModel
43
+ */
44
+ public function setStatusMappingModel(Netresearch_OPS_Model_Status_Mapping $statusMappingModel)
45
+ {
46
+ $this->statusMappingModel = $statusMappingModel;
47
+ }
48
+
49
+ /**
50
+ * @return null
51
+ */
52
+ public function getStatusMappingModel()
53
+ {
54
+ if (null == $this->statusMappingModel) {
55
+ $this->statusMappingModel = Mage::getModel('ops/status_mapping');
56
+ }
57
+
58
+ return $this->statusMappingModel;
59
+ }
60
+
61
+ protected $dataHelper = null;
62
+
63
+
64
+ /**
65
+ * return the config model
66
+ *
67
+ * @return Netresearch_OPS_Model_Config
68
+ */
69
+ protected function getConfig()
70
+ {
71
+ if (is_null($this->config)) {
72
+ $this->config = Mage::getModel('ops/config');
73
+ }
74
+
75
+ return $this->config;
76
+ }
77
+
78
+ /**
79
+ * generates the OPS order id in dependency to the config
80
+ *
81
+ * @param Mage_Sales_Order $order
82
+ * @param $useOrderIdIfPossible if false forces the usage of quoteid (for Kwixo pm etc.)
83
+ *
84
+ * @return string
85
+ */
86
+ public function getOpsOrderId($order, $useOrderIdIfPossible = true)
87
+ {
88
+ $config = $this->getConfig();
89
+ $devPrefix = $config->getConfigData('devprefix');
90
+ $orderRef = $order->getQuoteId();
91
+ if ($config->getOrderReference($order->getStoreId())
92
+ == Netresearch_OPS_Model_Payment_Abstract::REFERENCE_ORDER_ID
93
+ && $useOrderIdIfPossible === true
94
+ ) {
95
+ $orderRef = self::DELIMITER . $order->getIncrementId();
96
+ }
97
+
98
+ return $devPrefix . $orderRef;
99
+ }
100
+
101
+ /**
102
+ * getting the order from opsOrderId which can either the quote id or the order increment id
103
+ * in both cases the dev prefix is stripped, if neccessary
104
+ *
105
+ * @param $opsOrderId
106
+ *
107
+ * @return Mage_Sales_Model_Order
108
+ */
109
+ public function getOrder($opsOrderId)
110
+ {
111
+ $order = null;
112
+ $fieldToFilter = 'quote_id';
113
+ $devPrefix = $this->getConfig()->getConfigData('devprefix');
114
+ if ($devPrefix == substr($opsOrderId, 0, strlen($devPrefix))) {
115
+ $opsOrderId = substr($opsOrderId, strlen($devPrefix));
116
+ }
117
+ // opsOrderId was created from order increment id, use increment id for filtering
118
+ if (0 === strpos($opsOrderId, self::DELIMITER)) {
119
+ $opsOrderId = substr($opsOrderId, strlen(self::DELIMITER));
120
+ $fieldToFilter = 'increment_id';
121
+ }
122
+ /* @var $order Mage_Sales_Model_Resource_Order_Collection */
123
+ $order = Mage::getModel('sales/order')->getCollection()
124
+ ->addFieldToFilter($fieldToFilter, $opsOrderId)
125
+ // filter for OPS payment methods
126
+ ->join(array('payment' => 'sales/order_payment'), 'main_table.entity_id=parent_id', 'method')
127
+ ->addFieldToFilter('method', array(array('like' => 'ops_%')))
128
+ // sort by increment_id of order to get only the latest (relevant for quote id search)
129
+ ->addOrder('main_table.increment_id');
130
+
131
+ return $order->getFirstItem();
132
+ }
133
+
134
+ /**
135
+ * load and return the quote via the quoteId
136
+ *
137
+ * @param string $quoteId
138
+ *
139
+ * @return Mage_Model_Sales_Quote
140
+ */
141
+ public function getQuote($quoteId)
142
+ {
143
+ return Mage::getModel('sales/quote')->load($quoteId);
144
+ }
145
+
146
+ /**
147
+ * check if billing is same as shipping address
148
+ *
149
+ * @param Mage_Model_Sales_Order $order
150
+ *
151
+ * @return int
152
+ */
153
+ public function checkIfAddressesAreSame(Mage_Sales_Model_Order $order)
154
+ {
155
+ $addMatch = 0;
156
+ $billingAddressHash = null;
157
+ $shippingAddressHash = null;
158
+ if ($order->getBillingAddress() instanceof Mage_Customer_Model_Address_Abstract) {
159
+ $billingAddressHash = Mage::helper('ops/alias')->generateAddressHash(
160
+ $order->getBillingAddress()
161
+ );
162
+ }
163
+ if ($order->getShippingAddress() instanceof Mage_Customer_Model_Address_Abstract) {
164
+ $shippingAddressHash = Mage::helper('ops/alias')->generateAddressHash(
165
+ $order->getShippingAddress()
166
+ );
167
+ }
168
+
169
+ if ($billingAddressHash === $shippingAddressHash) {
170
+ $addMatch = 1;
171
+ }
172
+
173
+ return $addMatch;
174
+ }
175
+
176
+ /**
177
+ * checks if the order's state is valid for the according Ingenico Payment Services's status. If not the order's state is reset
178
+ * to it's previous state
179
+ *
180
+ * @param Mage_Sales_Model_Order $order
181
+ *
182
+ * @return $this
183
+ */
184
+ public function checkForOpsStateOnStatusUpdate(Mage_Sales_Model_Order $order)
185
+ {
186
+ $opsStatus = $order->getPayment()->getAdditionalInformation('status');
187
+ $opsOrderStates = $this->getStatusMappingModel()->getStatusForOpsStatus($opsStatus);
188
+ $origData = $order->getOrigData();
189
+ if (0 < count($opsOrderStates) && !in_array($order->getStatus(), $opsOrderStates)) {
190
+ $comment = $this->getDataHelper()->__(
191
+ 'revert state update to it\'s original one because of Ingenico Payment Services\'s state restriction'
192
+ );
193
+ $order->addStatusHistoryComment($comment, $origData['status']);
194
+ }
195
+
196
+ return $this;
197
+ }
198
+ }
app/code/community/Netresearch/OPS/Helper/Order/Abstract.php ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Created by PhpStorm.
5
+ * User: paul.siedler
6
+ * Date: 18.09.2014
7
+ * Time: 13:48
8
+ */
9
+ abstract class Netresearch_OPS_Helper_Order_Abstract extends Mage_Core_Helper_Abstract
10
+ {
11
+ /**
12
+ * Return partial operation code for transaction type
13
+ *
14
+ * @return string Operation code defined in Netresearch_OPS_Model_Payment_Abstract
15
+ */
16
+ protected abstract function getPartialOperationCode();
17
+
18
+ /**
19
+ * Return full operation code for transaction type
20
+ *
21
+ * @return string Operation code defined in Netresearch_OPS_Model_Payment_Abstract
22
+ */
23
+ protected abstract function getFullOperationCode();
24
+
25
+
26
+ /**
27
+ * Checks if partial capture and returns 'full' or 'partial'
28
+ *
29
+ * @param Mage_Sales_Order_Payment $payment
30
+ * @param float $amount
31
+ * @return string 'partial' if type is partial, else 'full'
32
+ */
33
+ public function determineType($payment, $amount)
34
+ {
35
+ $orderTotalAmount = round(
36
+ (Mage::helper('ops/payment')->getBaseGrandTotalFromSalesObject($payment->getOrder())) * 100,
37
+ 0
38
+ );
39
+ $amount = round(($amount * 100), 0);
40
+
41
+ if (abs($orderTotalAmount - $amount) <= 1) {
42
+ return 'full';
43
+ } else {
44
+ return 'partial';
45
+ }
46
+ }
47
+
48
+
49
+ /**
50
+ * checks if the amount captured/refunded is equal to the amount of the full order
51
+ * and returns the operation code accordingly
52
+ *
53
+ * @param Mage_Sales_Order_Payment $payment
54
+ * @param float $amount
55
+ * @return string operation code for the requested amount
56
+ * @see getPartialOperationCode() and getFullOperationCode() *
57
+ */
58
+ public function determineOperationCode($payment, $amount)
59
+ {
60
+ $orderTotalAmount = round(
61
+ (Mage::helper('ops/payment')->getBaseGrandTotalFromSalesObject($payment->getOrder())) * 100,
62
+ 0
63
+ );
64
+ $totalProcessedAmount = round((($this->getPreviouslyProcessedAmount($payment) + $amount) * 100), 0);
65
+
66
+ if (abs($orderTotalAmount - $totalProcessedAmount) <= 1 ) {
67
+ return $this->getFullOperationCode();
68
+ } else {
69
+ return $this->getPartialOperationCode();
70
+ }
71
+
72
+ }
73
+
74
+ /**
75
+ * Returns the Amount already processed for this kind of operation
76
+ * eg. getBaseAmountPaidOnline and getRefundedAmount
77
+ *
78
+ * @param Mage_Sales_Order_Payment $payment
79
+ * @return float amount already processed for this kind of operation
80
+ */
81
+ protected abstract function getPreviouslyProcessedAmount($payment);
82
+
83
+
84
+ }
app/code/community/Netresearch/OPS/Helper/Order/Capture.php ADDED
@@ -0,0 +1,184 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Netresearch_OPS_Helper_Order_Capture
5
+ *
6
+ * @package
7
+ * @copyright 2011 Netresearch
8
+ * @author André Herrn <andre.herrn@netresearch.de>
9
+ * @license OSL 3.0
10
+ */
11
+ class Netresearch_OPS_Helper_Order_Capture extends Netresearch_OPS_Helper_Order_Abstract
12
+ {
13
+ protected function getFullOperationCode()
14
+ {
15
+ return Netresearch_OPS_Model_Payment_Abstract::OPS_CAPTURE_FULL;
16
+ }
17
+
18
+ protected function getPartialOperationCode()
19
+ {
20
+ return Netresearch_OPS_Model_Payment_Abstract::OPS_CAPTURE_PARTIAL;
21
+ }
22
+
23
+ protected function getPreviouslyProcessedAmount($payment)
24
+ {
25
+ return $payment->getBaseAmountPaidOnline();
26
+ }
27
+
28
+
29
+ /**
30
+ * Prepare capture informations
31
+ *
32
+ * @param Mage_Sales_Order_Payment $payment
33
+ * @param float $amount
34
+ * @return array
35
+ */
36
+ public function prepareOperation($payment, $amount)
37
+ {
38
+ $params = Mage::app()->getRequest()->getParams();
39
+ if (array_key_exists('invoice', $params)) {
40
+ $arrInfo = $params['invoice'];
41
+ $arrInfo['amount'] = $amount;
42
+ }
43
+ $arrInfo['type'] = $this->determineType($payment, $amount);
44
+ $arrInfo['operation'] = $this->determineOperationCode($payment, $amount);
45
+
46
+ return $arrInfo;
47
+ }
48
+
49
+ /**
50
+ * Creates the Invoice for the appropriate capture
51
+ *
52
+ *
53
+ * @param array $params
54
+ */
55
+ public function acceptCapture($order, $params)
56
+ {
57
+ $arrInfo = array();
58
+ Mage::register('ops_auto_capture', true);
59
+ $forceFullInvoice = false;
60
+ $payId = $params['PAYID'];
61
+ try {
62
+ if ($payId) {
63
+ $transaction = Mage::helper("ops/directlink")->getPaymentTransaction(
64
+ $order,
65
+ $payId,
66
+ Netresearch_OPS_Model_Payment_Abstract::OPS_CAPTURE_TRANSACTION_TYPE
67
+ );
68
+ if ($transaction) {
69
+ $arrInfoSerialized = $transaction->getAdditionalInformation();
70
+ $arrInfo = unserialize($arrInfoSerialized['arrInfo']);
71
+ if (array_key_exists('type', $arrInfo) && $arrInfo['type'] == 'full') {
72
+ $forceFullInvoice = true;
73
+ }
74
+ }
75
+ }
76
+ } catch (Mage_Core_Exception $e) {
77
+ //If no transaction was found create a full invoice if possible
78
+ $forceFullInvoice = true;
79
+ $transaction = null;
80
+ }
81
+
82
+ if ($forceFullInvoice === true) {
83
+ if (!$order->getInvoiceCollection()->getSize()) {
84
+ $invoice = $order->prepareInvoice();
85
+ $invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE);
86
+ $comment = Mage::helper("ops")->__("Capture process complete");
87
+ } else {
88
+ Mage::throwException(
89
+ Mage::helper('ops')->__('The capture has already been invoiced.')
90
+ );
91
+ }
92
+ } else {
93
+ $invoice = Mage::getModel('sales/service_order', $order)
94
+ ->prepareInvoice($arrInfo['items']);
95
+ if (!$invoice->getTotalQty()) {
96
+ Mage::throwException(
97
+ Mage::helper('ops')->__('Cannot create an invoice without products.')
98
+ );
99
+ }
100
+ $invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE);
101
+ $comment = Mage::helper("ops")->__("Capture process complete");
102
+ }
103
+
104
+ if (is_object($invoice)) {
105
+ $invoice->register();
106
+ $transactionSave = Mage::getModel('core/resource_transaction')
107
+ ->addObject($invoice)
108
+ ->addObject($invoice->getOrder());
109
+ $shipment = false;
110
+ if (isset($transaction)
111
+ && array_key_exists('do_shipment', $arrInfo)
112
+ && $arrInfo['do_shipment']
113
+ ) {
114
+ $shipment = $this->_prepareShipment($invoice, $arrInfo);
115
+ if ($shipment) {
116
+ $shipment->setEmailSent($invoice->getEmailSent());
117
+ $transactionSave->addObject($shipment);
118
+ }
119
+ }
120
+
121
+ $transactionSave->save();
122
+
123
+ //Send E-Mail and Comment
124
+ $sendEMail = false;
125
+ $sendEMailWithComment = false;
126
+ if (isset($arrInfo['send_email'])) $sendEMail = true;
127
+ if (isset($arrInfo['comment_customer_notify'])) $sendEMailWithComment = true;
128
+ $comment = array_key_exists('comment_text', $arrInfo) ? $arrInfo['comment_text'] : '';
129
+
130
+ $invoice->addComment($comment, $sendEMailWithComment);
131
+ if ($sendEMail) {
132
+ $invoice->sendEmail(true, $comment);
133
+ $invoice->setEmailSent(true);
134
+ }
135
+
136
+ Mage::helper("ops/directlink")->closePaymentTransaction(
137
+ $order,
138
+ $params,
139
+ Netresearch_OPS_Model_Payment_Abstract::OPS_CAPTURE_TRANSACTION_TYPE,
140
+ Mage::helper('ops')->__(
141
+ 'Invoice "%s" was created automatically. Ingenico Payment Services Status: %s.',
142
+ $invoice->getIncrementId(),
143
+ Mage::helper('ops')->getStatusText($params['STATUS'])
144
+ ),
145
+ $sendEMail
146
+ );
147
+ Mage::helper('ops')->log(sprintf("Invoice created for order: %s", $order->getIncrementId()));
148
+ }
149
+ $order->save();
150
+ $eventData = array('data_object' => $order, 'order' => $order);
151
+ Mage::dispatchEvent('ops_sales_order_save_commit_after', $eventData);
152
+ }
153
+
154
+ /**
155
+ * Prepare shipment
156
+ *
157
+ * @param Mage_Sales_Model_Order_Invoice $invoice New invoice
158
+ * @param array $additionalData Array containing additional transaction data
159
+ *
160
+ * @return Mage_Sales_Model_Order_Shipment
161
+ */
162
+ protected function _prepareShipment($invoice, $additionalData)
163
+ {
164
+ $savedQtys = $additionalData['items'];
165
+ $shipment = Mage::getModel('sales/service_order', $invoice->getOrder())
166
+ ->prepareShipment($savedQtys);
167
+ if (!$shipment->getTotalQty()) {
168
+ return false;
169
+ }
170
+
171
+ $shipment->register();
172
+ if (array_key_exists('tracking', $additionalData)
173
+ && $additionalData['tracking']
174
+ ) {
175
+ foreach ($additionalData['tracking'] as $data) {
176
+ $track = Mage::getModel('sales/order_shipment_track')
177
+ ->addData($data);
178
+ $shipment->addTrack($track);
179
+ }
180
+ }
181
+
182
+ return $shipment;
183
+ }
184
+ }
app/code/community/Netresearch/OPS/Helper/Order/Refund.php ADDED
@@ -0,0 +1,305 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Netresearch_OPS_Helper_Order_Refund
5
+ *
6
+ * @package
7
+ * @copyright 2011 Netresearch
8
+ * @author André Herrn <andre.herrn@netresearch.de>
9
+ * @license OSL 3.0
10
+ */
11
+ class Netresearch_OPS_Helper_Order_Refund extends Netresearch_OPS_Helper_Order_Abstract
12
+ {
13
+ protected $payment;
14
+ protected $amount;
15
+ protected $params;
16
+
17
+ protected function getFullOperationCode()
18
+ {
19
+ return Netresearch_OPS_Model_Payment_Abstract::OPS_REFUND_FULL;
20
+ }
21
+
22
+ protected function getPartialOperationCode()
23
+ {
24
+ return Netresearch_OPS_Model_Payment_Abstract::OPS_REFUND_PARTIAL;
25
+ }
26
+
27
+ protected function getPreviouslyProcessedAmount($payment)
28
+ {
29
+ return $payment->getBaseAmountRefundedOnline();
30
+ }
31
+
32
+
33
+ /**
34
+ * @param Varien_Object $payment
35
+ */
36
+ public function setPayment(Varien_Object $payment)
37
+ {
38
+ $this->payment = $payment;
39
+
40
+ return $this;
41
+ }
42
+
43
+ /**
44
+ * @param float $amount
45
+ */
46
+ public function setAmount($amount)
47
+ {
48
+ $this->amount = $amount;
49
+
50
+ return $this;
51
+ }
52
+
53
+ /**
54
+ * @param array $params
55
+ * @return $this
56
+ */
57
+ public function setCreditMemoRequestParams($params)
58
+ {
59
+ $this->params = $params;
60
+
61
+ return $this;
62
+ }
63
+
64
+ /**
65
+ * @return array params
66
+ */
67
+ public function getCreditMemoRequestParams()
68
+ {
69
+ if (!is_array($this->params)) {
70
+ $this->setCreditMemoRequestParams(Mage::app()->getRequest()->getParams());
71
+ }
72
+
73
+ return $this->params;
74
+ }
75
+
76
+ public function getInvoiceFromCreditMemoRequest()
77
+ {
78
+ $params = $this->getCreditMemoRequestParams();
79
+ if (array_key_exists('invoice_id', $params)) {
80
+ return Mage::getModel('sales/order_invoice')->load($params['invoice_id']);
81
+ }
82
+
83
+ return null;
84
+ }
85
+
86
+ public function getCreditMemoFromRequest()
87
+ {
88
+ $params = $this->getCreditMemoRequestParams();
89
+ if (array_key_exists('creditmemo', $params)) {
90
+ return $params['creditmemo'];
91
+ }
92
+
93
+ return array();
94
+ }
95
+
96
+ /**
97
+ * @param Mage_Sales_Model_Order_Payment $payment
98
+ * @param float $amount
99
+ */
100
+ public function prepareOperation($payment, $amount)
101
+ {
102
+ $params = $this->getCreditMemoRequestParams();
103
+
104
+ if (array_key_exists('creditmemo', $params)) {
105
+ $arrInfo = $params['creditmemo'];
106
+ $arrInfo['amount'] = $amount;
107
+ }
108
+ $arrInfo['type'] = $this->determineType($payment, $amount);
109
+ $arrInfo['operation'] = $this->determineOperationCode($payment, $amount);
110
+
111
+ if($arrInfo['type'] == 'full'){
112
+ // hard overwrite operation code for last transaction
113
+ $arrInfo['operation'] = $this->getFullOperationCode();
114
+ }
115
+
116
+
117
+ return $arrInfo;
118
+ }
119
+
120
+
121
+ /**
122
+ * Create a new payment transaction for the refund
123
+ *
124
+ * @param array $response
125
+ * @param int $closed
126
+ *
127
+ * @return void
128
+ */
129
+ public function createRefundTransaction($response, $closed = 0)
130
+ {
131
+ $transactionParams = array(
132
+ 'creditmemo_request' => $this->getCreditMemoRequestParams(),
133
+ 'response' => $response,
134
+ 'amount' => $this->amount
135
+ );
136
+
137
+ Mage::helper('ops/directlink')->directLinkTransact(
138
+ Mage::getModel('sales/order')->load($this->payment->getOrder()->getId()),
139
+ $response['PAYID'],
140
+ $response['PAYIDSUB'],
141
+ $transactionParams,
142
+ Netresearch_OPS_Model_Payment_Abstract::OPS_REFUND_TRANSACTION_TYPE,
143
+ Mage::helper('ops')->__('Start Ingenico Payment Services refund request'),
144
+ $closed
145
+ );
146
+
147
+ $order = Mage::getModel('sales/order')->load($this->payment->getOrder()->getId());
148
+ $order->addStatusHistoryComment(
149
+ Mage::helper('ops')->__(
150
+ 'Creditmemo will be created automatically as soon as Ingenico Payment Services sends an acknowledgement. Ingenico Payment Services Status: %s.',
151
+ Mage::helper('ops')->getStatusText($response['STATUS'])
152
+ )
153
+ );
154
+ $order->save();
155
+ }
156
+
157
+ /**
158
+ * Create a new refund
159
+ *
160
+ * @param Mage_Sales_Model_Order $order
161
+ * @param array $params
162
+ * @param bool $setPaymentRefundDisallowed
163
+ *
164
+ */
165
+ public function createRefund(Mage_Sales_Model_Order $order, $params, $setPaymentRefundDisallowed = true)
166
+ {
167
+ $transactionParams = array();
168
+ try {
169
+ $refundTransaction = Mage::helper('ops/directlink')->getPaymentTransaction(
170
+ $order,
171
+ $params['PAYID'],
172
+ Netresearch_OPS_Model_Payment_Abstract::OPS_REFUND_TRANSACTION_TYPE
173
+ );
174
+ $transactionParams = $refundTransaction->getAdditionalInformation();
175
+ } catch (Mage_Core_Exception $e) {
176
+
177
+ }
178
+ try {
179
+
180
+ if (array_key_exists('arrInfo', $transactionParams)) {
181
+ $transactionParams = unserialize($transactionParams['arrInfo']);
182
+ $invoice = Mage::getModel('sales/order_invoice')
183
+ ->load($transactionParams['creditmemo_request']['invoice_id'])
184
+ ->setOrder($order);
185
+ } elseif ($order->getInvoiceCollection()->count() === 1) {
186
+ $invoice = $order->getInvoiceCollection()->getFirstItem();
187
+ }
188
+ //Start to create the creditmemo
189
+ Mage::register('ops_auto_creditmemo', true);
190
+ $service = Mage::getModel('sales/service_order', $order);
191
+
192
+ $data = $this->prepareCreditMemoData($transactionParams);
193
+ $creditmemo = $service->prepareInvoiceCreditmemo($invoice, $data);
194
+
195
+ /**
196
+ * Process back to stock flags
197
+ */
198
+ $backToStock = array();
199
+ if (array_key_exists('backToStock', $data)) {
200
+ $backToStock = $data['backToStock'];
201
+ }
202
+ foreach ($creditmemo->getAllItems() as $creditmemoItem) {
203
+ $orderItem = $creditmemoItem->getOrderItem();
204
+ $parentId = $orderItem->getParentItemId();
205
+ if (isset($backToStock[$orderItem->getId()])) {
206
+ $creditmemoItem->setBackToStock(true);
207
+ } elseif ($orderItem->getParentItem() && isset($backToStock[$parentId]) && $backToStock[$parentId]) {
208
+ $creditmemoItem->setBackToStock(true);
209
+ } elseif (empty($savedData)) {
210
+ $creditmemoItem->setBackToStock(Mage::helper('cataloginventory')->isAutoReturnEnabled());
211
+ } else {
212
+ $creditmemoItem->setBackToStock(false);
213
+ }
214
+ }
215
+
216
+ //Send E-Mail and Comment
217
+ $comment = '';
218
+ $sendEmail = false;
219
+ $sendEMailWithComment = false;
220
+ if (isset($data['send_email']) && $data['send_email'] == 1) {
221
+ $sendEmail = true;
222
+ }
223
+ if (isset($data['comment_customer_notify'])) {
224
+ $sendEMailWithComment = true;
225
+ }
226
+
227
+ if (!empty($data['comment_text'])):
228
+ $creditmemo->addComment($data['comment_text'], $sendEMailWithComment);
229
+ if ($sendEMailWithComment):
230
+ $comment = $data['comment_text'];
231
+ endif;
232
+ endif;
233
+
234
+ $creditmemo->setPaymentRefundDisallowed($setPaymentRefundDisallowed);
235
+ $creditmemo->setRefundRequested(true);
236
+ $creditmemo->setOfflineRequested(false);
237
+ $creditmemo->register();
238
+ if ($sendEmail):
239
+ $creditmemo->setEmailSent(true);
240
+ endif;
241
+ $creditmemo->getOrder()->setCustomerNoteNotify($sendEMailWithComment);
242
+
243
+ $transactionSave = Mage::getModel('core/resource_transaction')
244
+ ->addObject($creditmemo)
245
+ ->addObject($creditmemo->getOrder());
246
+ if ($creditmemo->getInvoice()):
247
+ $transactionSave->addObject($creditmemo->getInvoice());
248
+ endif;
249
+ $transactionSave->save();
250
+ $creditmemo->sendEmail($sendEmail, $comment);
251
+
252
+
253
+ //End of create creditmemo
254
+
255
+ //close refund payment transaction
256
+ Mage::helper('ops/directlink')->closePaymentTransaction(
257
+ $order,
258
+ $params,
259
+ Netresearch_OPS_Model_Payment_Abstract::OPS_REFUND_TRANSACTION_TYPE,
260
+ Mage::helper('ops')->__(
261
+ 'Creditmemo "%s" was created automatically. Ingenico Payment Services Status: %s.',
262
+ $creditmemo->getIncrementId(),
263
+ Mage::helper('ops')->getStatusText($params['STATUS'])
264
+ ),
265
+ $sendEmail
266
+ );
267
+ Mage::helper('ops/payment')->setCanRefundToPayment($order->getPayment());
268
+ } catch (Exception $e) {
269
+ Mage::logException($e);
270
+ Mage::throwException('Error in Creditmemo creation process: ' . $e->getMessage());
271
+ }
272
+
273
+ }
274
+
275
+ /**
276
+ * Get requested items qtys
277
+ */
278
+ protected function prepareCreditMemoData($transactionParams)
279
+ {
280
+ if (!array_key_exists('creditmemo_request', $transactionParams)
281
+ || !array_key_exists('creditmemo', $transactionParams['creditmemo_request'])
282
+ ) {
283
+ return array();
284
+ }
285
+ $data = $transactionParams['creditmemo_request']['creditmemo'];
286
+ $qtys = array();
287
+ $backToStock = array();
288
+
289
+ if (array_key_exists('items', $data)) {
290
+ foreach ($data['items'] as $orderItemId => $itemData):
291
+ if (isset($itemData['qty'])):
292
+ $qtys[$orderItemId] = $itemData['qty'];
293
+ else:
294
+ if (isset($itemData['back_to_stock'])):
295
+ $backToStock[$orderItemId] = true;
296
+ endif;
297
+ endif;
298
+ endforeach;
299
+ }
300
+ $data['qtys'] = $qtys;
301
+ $data['backToStock'] = $backToStock;
302
+
303
+ return $data;
304
+ }
305
+ }
app/code/community/Netresearch/OPS/Helper/Order/Void.php ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Netresearch_OPS_Helper_Order_Void
4
+ *
5
+ * @package
6
+ * @copyright 2011 Netresearch
7
+ * @author André Herrn <andre.herrn@netresearch.de>
8
+ * @license OSL 3.0
9
+ */
10
+ class Netresearch_OPS_Helper_Order_Void extends Mage_Core_Helper_Abstract
11
+ {
12
+ /**
13
+ * Cancels the appropriate order and closes the transaction
14
+ *
15
+ * @param array $params
16
+ */
17
+ public function acceptVoid($order, $params)
18
+ {
19
+ Mage::register('ops_auto_void', true);
20
+ $order->cancel();
21
+ $order->save();
22
+ Mage::helper("ops/directlink")->closePaymentTransaction(
23
+ $order,
24
+ $params,
25
+ Netresearch_OPS_Model_Payment_Abstract::OPS_VOID_TRANSACTION_TYPE
26
+ );
27
+ Mage::helper('ops')->log("order voided: ".$params['orderID']);
28
+ }
29
+
30
+ public function getCapturedAmount($order)
31
+ {
32
+ $sumAmount = 0;
33
+ $transactionCollection = Mage::getModel('sales/order_payment_transaction')
34
+ ->getCollection()
35
+ ->addAttributeToFilter('txn_type', Netresearch_OPS_Model_Payment_Abstract::OPS_CAPTURE_TRANSACTION_TYPE)
36
+ ->addAttributeToFilter('order_id', $order->getId())
37
+ ->addAttributeToFilter('is_closed', 1);
38
+
39
+ foreach ($transactionCollection as $transaction) {
40
+ $arrInfo = null;
41
+ $arrInfoRough = $transaction->getAdditionalInformation();
42
+ if (isset($arrInfoRough['arrInfo'])) {
43
+ $arrInfo = unserialize($arrInfoRough['arrInfo']);
44
+ }
45
+
46
+ if (isset($arrInfo['amount'])) {
47
+ $sumAmount += $arrInfo['amount'];
48
+ }
49
+ }
50
+ return $sumAmount;
51
+ }
52
+ }
app/code/community/Netresearch/OPS/Helper/Payment.php ADDED
@@ -0,0 +1,1115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Netresearch_OPS_Helper_Payment
5
+ *
6
+ * @package
7
+ * @copyright 2011 Netresearch
8
+ * @author Thomas Kappel <thomas.kappel@netresearch.de>
9
+ * @author André Herrn <andre.herrn@netresearch.de>
10
+ * @license OSL 3.0
11
+ */
12
+ class Netresearch_OPS_Helper_Payment extends Mage_Core_Helper_Abstract
13
+ {
14
+ const HASH_ALGO = 'sha1';
15
+
16
+ /**
17
+ * Get checkout session namespace
18
+ *
19
+ * @return Mage_Checkout_Model_Session
20
+ */
21
+ protected function _getCheckout()
22
+ {
23
+ return Mage::getSingleton('checkout/session');
24
+ }
25
+
26
+ /**
27
+ * Get checkout session namespace
28
+ *
29
+ * @return Mage_Checkout_Model_Session
30
+ */
31
+ protected function getConfig()
32
+ {
33
+ return Mage::getSingleton('ops/config');
34
+ }
35
+
36
+ /**
37
+ * Crypt Data by SHA1 ctypting algorithm by secret key
38
+ *
39
+ * @param array $data
40
+ * @param string $key
41
+ *
42
+ * @return hash
43
+ */
44
+ public function shaCrypt($data, $key = '')
45
+ {
46
+ if (is_array($data)) {
47
+ return hash(self::HASH_ALGO, implode("", $data));
48
+ }
49
+ if (is_string($data)) {
50
+ return hash(self::HASH_ALGO, $data);
51
+ } else {
52
+ return "";
53
+ }
54
+ }
55
+
56
+ /**
57
+ * Check hash crypted by SHA1 with existing data
58
+ *
59
+ * @param array $data
60
+ * @param string $hash
61
+ * @param string $key
62
+ *
63
+ * @return bool
64
+ */
65
+ public function shaCryptValidation($data, $hashFromOPS, $key = '')
66
+ {
67
+ if (is_array($data)) {
68
+ $data = implode("", $data);
69
+ }
70
+
71
+ $hashUtf8 = strtoupper(hash(self::HASH_ALGO, $data));
72
+ $hashNonUtf8 = strtoupper(hash(self::HASH_ALGO, utf8_encode($data)));
73
+
74
+ $helper = Mage::helper('ops');
75
+ $helper->log($helper->__("Module Secureset: %s", $data));
76
+
77
+ if ($this->compareHashes($hashFromOPS, $hashUtf8)) {
78
+ return true;
79
+ } else {
80
+ $helper->log($helper->__("Trying again with non-utf8 secureset"));
81
+
82
+ return $this->compareHashes($hashFromOPS, $hashNonUtf8);
83
+ }
84
+ }
85
+
86
+ private function compareHashes($hashFromOPS, $actual)
87
+ {
88
+ $helper = Mage::helper('ops');
89
+ $helper->log(
90
+ $helper->__(
91
+ "Checking hashes\nHashed String by Magento: %s\nHashed String by Ingenico Payment Services: %s",
92
+ $actual,
93
+ $hashFromOPS
94
+ )
95
+ );
96
+
97
+ if ($hashFromOPS == $actual) {
98
+ Mage::helper('ops')->log("Successful validation");
99
+
100
+ return true;
101
+ }
102
+
103
+ return false;
104
+ }
105
+
106
+ /**
107
+ * Return set of data which is ready for SHA crypt
108
+ *
109
+ * @param array $data
110
+ * @param string $key
111
+ *
112
+ * @return string
113
+ */
114
+ public function getSHAInSet($params, $SHAkey)
115
+ {
116
+ $params = $this->prepareParamsAndSort($params);
117
+ $plainHashString = "";
118
+ foreach ($params as $paramSet):
119
+ if ($paramSet['value'] == '' || $paramSet['key'] == 'SHASIGN') {
120
+ continue;
121
+ }
122
+ $plainHashString .= strtoupper($paramSet['key']) . "=" . $paramSet['value'] . $SHAkey;
123
+ endforeach;
124
+
125
+ return $plainHashString;
126
+ }
127
+
128
+ /**
129
+ * Return prepared and sorted array for SHA Signature Validation
130
+ *
131
+ * @param array $params
132
+ *
133
+ * @return string
134
+ */
135
+ public function prepareParamsAndSort($params)
136
+ {
137
+ unset($params['CardNo']);
138
+ unset($params['Brand']);
139
+ unset($params['SHASign']);
140
+
141
+ $params = array_change_key_case($params, CASE_UPPER);
142
+
143
+ //PHP ksort takes care about "_", OPS not
144
+ $sortedParams = array();
145
+ foreach ($params as $key => $value):
146
+ $sortedParams[str_replace("_", "", $key)] = array('key' => $key, 'value' => $value);
147
+ endforeach;
148
+ ksort($sortedParams);
149
+
150
+ return $sortedParams;
151
+ }
152
+
153
+ /*
154
+ * Get SHA-1-IN hash for ops-authentification
155
+ *
156
+ * All Parameters have to be alphabetically, UPPERCASE
157
+ * Empty Parameters shouldn't appear in the secure string
158
+ *
159
+ * @param array $formFields
160
+ * @param string $shaCode
161
+ *
162
+ * @return string
163
+ */
164
+ public function getSHASign($formFields, $shaCode = null, $storeId = null)
165
+ {
166
+ if (is_null($shaCode)) {
167
+ $shaCode = Mage::getModel('ops/config')->getShaOutCode($storeId);
168
+ }
169
+ $formFields = array_change_key_case($formFields, CASE_UPPER);
170
+ uksort($formFields, 'strnatcasecmp');
171
+ $plainHashString = '';
172
+ foreach ($formFields as $formKey => $formVal) {
173
+ if (is_null($formVal) || '' === $formVal || $formKey == 'SHASIGN') {
174
+ continue;
175
+ }
176
+ $plainHashString .= strtoupper($formKey) . '=' . $formVal . $shaCode;
177
+ }
178
+
179
+ return $plainHashString;
180
+ }
181
+
182
+ /**
183
+ * We get some CC info from ops, so we must save it
184
+ *
185
+ * @param Mage_Sales_Model_Order $order
186
+ * @param array $ccInfo
187
+ *
188
+ * @return Netresearch_OPS_ApiController
189
+ */
190
+ public function _prepareCCInfo($order, $ccInfo)
191
+ {
192
+ if (isset($ccInfo['CN'])) {
193
+ $order->getPayment()->setCcOwner($ccInfo['CN']);
194
+ }
195
+
196
+ if (isset($ccInfo['CARDNO'])) {
197
+ $order->getPayment()->setCcNumberEnc($ccInfo['CARDNO']);
198
+ $order->getPayment()->setCcLast4(substr($ccInfo['CARDNO'], -4));
199
+ }
200
+
201
+ if (isset($ccInfo['ED'])) {
202
+ $order->getPayment()->setCcExpMonth(substr($ccInfo['ED'], 0, 2));
203
+ $order->getPayment()->setCcExpYear(substr($ccInfo['ED'], 2, 2));
204
+ }
205
+
206
+ return $this;
207
+ }
208
+
209
+ public function isPaymentAccepted($status)
210
+ {
211
+ return in_array(
212
+ $status, array(
213
+ Netresearch_OPS_Model_Payment_Abstract::OPS_AUTHORIZED,
214
+ Netresearch_OPS_Model_Payment_Abstract::OPS_AUTHORIZED_WAITING,
215
+ Netresearch_OPS_Model_Payment_Abstract::OPS_AUTHORIZED_UNKNOWN,
216
+ Netresearch_OPS_Model_Payment_Abstract::OPS_AWAIT_CUSTOMER_PAYMENT,
217
+ Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_REQUESTED,
218
+ Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_PROCESSING,
219
+ Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_UNCERTAIN,
220
+ Netresearch_OPS_Model_Payment_Abstract::OPS_WAITING_FOR_IDENTIFICATION
221
+ )
222
+ );
223
+ }
224
+
225
+ public function isPaymentAuthorizeType($status)
226
+ {
227
+ return in_array(
228
+ $status, array(
229
+ Netresearch_OPS_Model_Payment_Abstract::OPS_AUTHORIZED,
230
+ Netresearch_OPS_Model_Payment_Abstract::OPS_AUTHORIZED_WAITING,
231
+ Netresearch_OPS_Model_Payment_Abstract::OPS_AUTHORIZED_UNKNOWN,
232
+ Netresearch_OPS_Model_Payment_Abstract::OPS_AWAIT_CUSTOMER_PAYMENT
233
+ )
234
+ );
235
+ }
236
+
237
+ public function isPaymentCaptureType($status)
238
+ {
239
+ return in_array(
240
+ $status, array(
241
+ Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_REQUESTED,
242
+ Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_PROCESSING,
243
+ Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_UNCERTAIN
244
+ )
245
+ );
246
+ }
247
+
248
+ public function isPaymentFailed($status)
249
+ {
250
+ return false == $this->isPaymentAccepted($status);
251
+ }
252
+
253
+ /**
254
+ * apply ops state for order
255
+ *
256
+ * @param Mage_Sales_Model_Order $order Order
257
+ * @param array $params Request params
258
+ *
259
+ * @return void
260
+ */
261
+ public function applyStateForOrder($order, $params)
262
+ {
263
+ /**
264
+ * OpenInvoiceDe should always have status code 41, which is a final state in this case
265
+ */
266
+ if ($order->getPayment()->getMethodInstance()->getCode() == 'ops_openInvoiceDe'
267
+ && $params['STATUS'] == Netresearch_OPS_Model_Payment_Abstract::OPS_AWAIT_CUSTOMER_PAYMENT
268
+ ) {
269
+ $params['STATUS'] = Netresearch_OPS_Model_Payment_Abstract::OPS_OPEN_INVOICE_DE_PROCESSED;
270
+ }
271
+
272
+ $feedbackStatus = '';
273
+
274
+ switch ($params['STATUS']) {
275
+ case Netresearch_OPS_Model_Payment_Abstract::OPS_WAITING_FOR_IDENTIFICATION : //3D-Secure
276
+ $this->waitOrder($order, $params);
277
+ $feedbackStatus = Netresearch_OPS_Model_Status_Feedback::OPS_ORDER_FEEDBACK_STATUS_ACCEPT;
278
+ break;
279
+
280
+ case Netresearch_OPS_Model_Payment_Abstract::OPS_AUTHORIZED:
281
+ case Netresearch_OPS_Model_Payment_Abstract::OPS_AUTHORIZED_KWIXO:
282
+ case Netresearch_OPS_Model_Payment_Abstract::OPS_AUTHORIZED_WAITING:
283
+ case Netresearch_OPS_Model_Payment_Abstract::OPS_AUTHORIZED_UNKNOWN:
284
+ case Netresearch_OPS_Model_Payment_Abstract::OPS_AWAIT_CUSTOMER_PAYMENT:
285
+ $this->acceptOrder($order, $params);
286
+ $feedbackStatus = Netresearch_OPS_Model_Status_Feedback::OPS_ORDER_FEEDBACK_STATUS_ACCEPT;
287
+ break;
288
+ case Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_REQUESTED:
289
+ case Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_PROCESSING:
290
+ case Netresearch_OPS_Model_Payment_Abstract::OPS_OPEN_INVOICE_DE_PROCESSED:
291
+ case Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_PROCESSED_MERCHANT:
292
+ $this->acceptOrder($order, $params, 1);
293
+ $feedbackStatus = Netresearch_OPS_Model_Status_Feedback::OPS_ORDER_FEEDBACK_STATUS_ACCEPT;
294
+ break;
295
+ case Netresearch_OPS_Model_Payment_Abstract::OPS_AUTH_REFUSED:
296
+ case Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_REFUSED:
297
+ $this->declineOrder($order, $params);
298
+ $feedbackStatus = Netresearch_OPS_Model_Status_Feedback::OPS_ORDER_FEEDBACK_STATUS_DECLINE;
299
+ break;
300
+ case Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_CANCELED_BY_CUSTOMER:
301
+ $this->cancelOrder($order, $params, Mage_Sales_Model_Order::STATE_CANCELED,
302
+ Mage::helper('ops')->__(
303
+ 'Order canceled on Ingenico Payment Services side. Status: %s, Payment ID: %s.',
304
+ Mage::helper('ops')->getStatusText($params['STATUS']),
305
+ $params['PAYID']));
306
+ $feedbackStatus = Netresearch_OPS_Model_Status_Feedback::OPS_ORDER_FEEDBACK_STATUS_CANCEL;
307
+ break;
308
+ default:
309
+ //all unknown transaction will accept as exceptional
310
+ $this->handleException($order, $params);
311
+ $feedbackStatus = Netresearch_OPS_Model_Status_Feedback::OPS_ORDER_FEEDBACK_STATUS_EXCEPTION;
312
+ }
313
+
314
+ return $feedbackStatus;
315
+ }
316
+
317
+ /**
318
+ * Process success action by accept url
319
+ *
320
+ * @param Mage_Sales_Model_Order $order Order
321
+ * @param array $params Request params
322
+ */
323
+ public function acceptOrder($order, $params, $instantCapture = 0)
324
+ {
325
+ $this->_getCheckout()->setLastSuccessQuoteId($order->getQuoteId());
326
+ $this->_prepareCCInfo($order, $params);
327
+ $this->setPaymentTransactionInformation($order->getPayment(), $params, 'accept');
328
+ $this->setFraudDetectionParameters($order->getPayment(), $params);
329
+
330
+ if ($transaction = Mage::helper('ops/payment')->getTransactionByTransactionId($order->getQuoteId())) {
331
+ $transaction->setTxnId($params['PAYID'])->save();
332
+ }
333
+
334
+ try {
335
+ if (false === $this->forceAuthorize($order) &&
336
+ ($this->getConfig()->getConfigData('payment_action')
337
+ == Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE_CAPTURE
338
+ || $instantCapture)
339
+ && $params['STATUS'] != Netresearch_OPS_Model_Payment_Abstract::OPS_AWAIT_CUSTOMER_PAYMENT
340
+ ) {
341
+ $this->_processDirectSale($order, $params, $instantCapture);
342
+ } else {
343
+ $this->_processAuthorize($order, $params);
344
+ }
345
+ } catch (Exception $e) {
346
+ $this->_getCheckout()->addError(Mage::helper('ops')->__('Order can not be saved.'));
347
+ throw $e;
348
+ }
349
+ }
350
+
351
+ /**
352
+ * Set Payment Transaction Information
353
+ *
354
+ * @param Mage_Sales_Model_Order_Payment $payment Sales Payment Model
355
+ * @param array $params Request params
356
+ * @param string $action Action (accept|cancel|decline|wait|exception)
357
+ */
358
+ protected function setPaymentTransactionInformation(Mage_Sales_Model_Order_Payment $payment, $params, $action)
359
+ {
360
+ $payment->setTransactionId($params['PAYID']);
361
+ $code = $payment->getMethodInstance()->getCode();
362
+
363
+ $isInline = false;
364
+
365
+ /* In authorize mode we still have no authorization transaction for CC and DirectDebit payments,
366
+ * so capture or cancel won't work. So we need to create a new authorization transaction for them
367
+ * when a payment was accepted by Ingenico Payment Services
368
+ *
369
+ * In exception-case we create the authorization-transaction too because some exception-cases can turn into accepted
370
+ */
371
+ if (('accept' === $action || 'exception' === $action)
372
+ && in_array($code, array('ops_cc', 'ops_directDebit'))
373
+ ) {
374
+ $payment->setIsTransactionClosed(false);
375
+ $isInline = $this->isInlinePayment($payment);
376
+ /* create authorization transaction for non-inline pms */
377
+ if (false === $isInline || (array_key_exists('HTML_ANSWER', $params) || 0 < strlen($payment->getAdditionalInformation('HTML_ANSWER')))) {
378
+ $payment->addTransaction("authorization", null, true, $this->__("Process outgoing transaction"));
379
+ }
380
+ $payment->setLastTransId($params['PAYID']);
381
+ }
382
+
383
+ /* Ingenico Payment Services sends parameter HTML_ANSWER to trigger 3D secure redirection */
384
+ if (isset($params['HTML_ANSWER']) && ('ops_cc' == $code)) {
385
+ $payment->setAdditionalInformation('HTML_ANSWER', $params['HTML_ANSWER']);
386
+ $payment->setIsTransactionPending(true);
387
+ }
388
+
389
+ $payment->setAdditionalInformation('paymentId', $params['PAYID']);
390
+ $payment->setAdditionalInformation('status', $params['STATUS']);
391
+ if (array_key_exists('ACCEPTANCE', $params) && 0 < strlen(trim($params['ACCEPTANCE']))) {
392
+ $payment->setAdditionalInformation('acceptance', $params['ACCEPTANCE']);
393
+ }
394
+ if (array_key_exists('BRAND', $params) && ('ops_cc' == $code) && 0 < strlen(trim($params['BRAND']))) {
395
+ $payment->setAdditionalInformation('CC_BRAND', $params['BRAND']);
396
+ }
397
+ if (false === $isInline || array_key_exists('HTML_ANSWER', $params)) {
398
+ $payment->setIsTransactionClosed(true);
399
+ }
400
+ $payment->setDataChanges(true);
401
+ $payment->save();
402
+ }
403
+
404
+ /**
405
+ * add fraud detection of Ingenico Payment Services to additional payment data
406
+ *
407
+ * @param Mage_Sales_Model_Order_Payment $payment
408
+ * @param array $params
409
+ */
410
+ protected function setFraudDetectionParameters($payment, $params)
411
+ {
412
+ $params = array_change_key_case($params, CASE_UPPER);
413
+ if (array_key_exists('SCORING', $params)) {
414
+ $payment->setAdditionalInformation('scoring', $params['SCORING']);
415
+ }
416
+ if (array_key_exists('SCO_CATEGORY', $params)) {
417
+ $payment->setAdditionalInformation('scoringCategory', $params['SCO_CATEGORY']);
418
+ }
419
+ $additionalScoringData = array();
420
+ foreach ($this->getConfig()->getAdditionalScoringKeys() as $key) {
421
+ if (array_key_exists($key, $params)) {
422
+ if (false === mb_detect_encoding($params[$key], 'UTF-8', true)) {
423
+ $additionalScoringData[$key] = utf8_encode($params[$key]);
424
+ } else {
425
+ $additionalScoringData[$key] = $params[$key];
426
+ }
427
+ }
428
+ }
429
+ $payment->setAdditionalInformation('additionalScoringData', $additionalScoringData);
430
+ }
431
+
432
+ /**
433
+ * Process cancel action by cancel url
434
+ *
435
+ * @param Mage_Sales_Model_Order $order Order
436
+ * @param array $params Request params
437
+ * @param string $status Order status
438
+ * @param string $comment Order comment
439
+ */
440
+ public function cancelOrder($order, $params, $status, $comment)
441
+ {
442
+ try {
443
+ Mage::register('ops_auto_void', true); //Set this session value to true to allow cancel
444
+
445
+ $order->cancel();
446
+ $order->setState(Mage_Sales_Model_Order::STATE_CANCELED, $status, $comment);
447
+ $order->save();
448
+ $this->cancelInvoices($order);
449
+ try {
450
+ $this->setPaymentTransactionInformation($order->getPayment(), $params, 'cancel');
451
+ } catch (Exception $e) {
452
+ // just ignore that
453
+ Mage::helper('ops')->log(
454
+ 'Catched exception while saving payment transaction information of a canceled order: '
455
+ . $e->getMessage()
456
+ );
457
+ }
458
+ } catch (Exception $e) {
459
+ $this->_getCheckout()->addError(Mage::helper('ops')->__('Order can not be canceled for system reason.'));
460
+ throw $e;
461
+ }
462
+ }
463
+
464
+ /**
465
+ * Process decline action by ops decline url
466
+ *
467
+ * @param Mage_Sales_Model_Order $order Order
468
+ * @param array $params Request params
469
+ */
470
+ public function declineOrder($order, $params)
471
+ {
472
+ try {
473
+ Mage::register('ops_auto_void', true); //Set this session value to true to allow cancel
474
+ $order->cancel();
475
+ $order->setState(
476
+ Mage_Sales_Model_Order::STATE_CANCELED,
477
+ Mage_Sales_Model_Order::STATE_CANCELED,
478
+ Mage::helper('ops')->__(
479
+ 'Order declined on ops side. Ingenico Payment Services status: %s, Payment ID: %s.',
480
+ Mage::helper('ops')->getStatusText($params['STATUS']),
481
+ $params['PAYID']
482
+ )
483
+ );
484
+ $order->save();
485
+ $this->cancelInvoices($order);
486
+ $this->setPaymentTransactionInformation($order->getPayment(), $params, 'decline');
487
+ } catch (Exception $e) {
488
+ $this->_getCheckout()->addError(Mage::helper('ops')->__('Order can not be canceled for system reason.'));
489
+ throw $e;
490
+ }
491
+ }
492
+
493
+ /**
494
+ * Wait for 3D secure confirmation
495
+ *
496
+ * @param Mage_Sales_Model_Order $order Order
497
+ * @param array $params Request params
498
+ */
499
+ public function waitOrder($order, $params)
500
+ {
501
+ try {
502
+ $order->setState(
503
+ Mage_Sales_Model_Order::STATE_PAYMENT_REVIEW,
504
+ Mage_Sales_Model_Order::STATE_PAYMENT_REVIEW,
505
+ Mage::helper('ops')->__(
506
+ 'Order is waiting for Ingenico Payment Services confirmation of 3D-Secure. Ingenico Payment Services status: %s, Payment ID: %s.',
507
+ Mage::helper('ops')->getStatusText($params['STATUS']),
508
+ $params['PAYID']
509
+ )
510
+ );
511
+ $order->save();
512
+ $this->setPaymentTransactionInformation($order->getPayment(), $params, 'wait');
513
+ } catch (Exception $e) {
514
+ $this->_getCheckout()->addError(
515
+ Mage::helper('ops')->__('Error during 3D-Secure processing of Ingenico Payment Services. Error: %s', $e->getMessage())
516
+ );
517
+ throw $e;
518
+ }
519
+ }
520
+
521
+ /**
522
+ * Process exception action by ops exception url
523
+ *
524
+ * @param Mage_Sales_Model_Order $order Order
525
+ * @param array $params Request params
526
+ */
527
+ public function handleException($order, $params)
528
+ {
529
+ $exceptionMessage = $this->getPaymentExceptionMessage($params['STATUS']);
530
+
531
+ if (!empty($exceptionMessage)) {
532
+ try {
533
+ $this->_getCheckout()->setLastSuccessQuoteId($order->getQuoteId());
534
+ $this->_prepareCCInfo($order, $params);
535
+ $order->getPayment()->setLastTransId($params['PAYID']);
536
+ //to send new order email only when state is pending payment
537
+ if ($order->getState() == Mage_Sales_Model_Order::STATE_PENDING_PAYMENT) {
538
+ $order->sendNewOrderEmail();
539
+
540
+ }
541
+ $order->addStatusHistoryComment($exceptionMessage);
542
+ $order->save();
543
+ $this->setPaymentTransactionInformation($order->getPayment(), $params, 'exception');
544
+ } catch (Exception $e) {
545
+ $this->_getCheckout()->addError(Mage::helper('ops')->__('Order can not be saved for system reason.'));
546
+ }
547
+ } else {
548
+ $this->_getCheckout()->addError(Mage::helper('ops')->__('An unknown exception occured.'));
549
+ }
550
+ }
551
+
552
+ /**
553
+ * Get Payment Exception Message
554
+ *
555
+ * @param int $ops_status Request OPS Status
556
+ */
557
+ protected function getPaymentExceptionMessage($ops_status)
558
+ {
559
+ $exceptionMessage = '';
560
+ switch ($ops_status) {
561
+ case Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_UNCERTAIN :
562
+ $exceptionMessage = Mage::helper('ops')->__(
563
+ 'A technical problem arose during payment process, giving unpredictable result. Ingenico Payment Services status: %s.',
564
+ Mage::helper('ops')->getStatusText($ops_status)
565
+ );
566
+ break;
567
+ default:
568
+ $exceptionMessage = Mage::helper('ops')->__(
569
+ 'An unknown exception was thrown in the payment process. Ingenico Payment Services status: %s.',
570
+ Mage::helper('ops')->getStatusText($ops_status)
571
+ );
572
+ }
573
+
574
+ return $exceptionMessage;
575
+ }
576
+
577
+ /**
578
+ * Process Configured Payment Action: Direct Sale, create invoice if state is Pending
579
+ *
580
+ * @param Mage_Sales_Model_Order $order Order
581
+ * @param array $params Request params
582
+ */
583
+ protected function _processDirectSale($order, $params, $instantCapture = 0)
584
+ {
585
+ Mage::register('ops_auto_capture', true);
586
+ $status = $params['STATUS'];
587
+ if ($status == Netresearch_OPS_Model_Payment_Abstract::OPS_AWAIT_CUSTOMER_PAYMENT) {
588
+ $order->setState(
589
+ Mage_Sales_Model_Order::STATE_PROCESSING,
590
+ Mage_Sales_Model_Order::STATE_PENDING_PAYMENT,
591
+ Mage::helper('ops')->__('Waiting for the payment of the customer')
592
+ );
593
+
594
+ // send new order mail for bank transfer, since it is 'successfully' authorized at this point
595
+ if ($order->getPayment()->getMethodInstance() instanceof Netresearch_OPS_Model_Payment_BankTransfer
596
+ && $order->getEmailSent() != 1
597
+ ) {
598
+ $order->sendNewOrderEmail();
599
+ }
600
+
601
+ $order->save();
602
+ } elseif ($status == Netresearch_OPS_Model_Payment_Abstract::OPS_AUTHORIZED_WAITING) {
603
+ $order->setState(
604
+ Mage_Sales_Model_Order::STATE_PROCESSING,
605
+ Mage_Sales_Model_Order::STATE_PENDING_PAYMENT,
606
+ Mage::helper('ops')->__('Authorization waiting from Ingenico Payment Services')
607
+ );
608
+ $order->save();
609
+ } elseif ($order->getState() == Mage_Sales_Model_Order::STATE_PENDING_PAYMENT
610
+ || $instantCapture
611
+ ) {
612
+ if ($status == Netresearch_OPS_Model_Payment_Abstract::OPS_AUTHORIZED) {
613
+ if ($order->getStatus() != Mage_Sales_Model_Order::STATE_PENDING_PAYMENT) {
614
+ $order->setState(
615
+ Mage_Sales_Model_Order::STATE_PROCESSING,
616
+ Mage_Sales_Model_Order::STATE_PROCESSING,
617
+ Mage::helper('ops')->__('Processed by Ingenico Payment Services')
618
+ );
619
+
620
+ }
621
+ } else {
622
+ $order->setState(
623
+ Mage_Sales_Model_Order::STATE_PROCESSING,
624
+ true,
625
+ Mage::helper('ops')->__('Processed by Ingenico Payment Services')
626
+ );
627
+ $order->save();
628
+ }
629
+ if (!$order->getInvoiceCollection()->getSize()
630
+ && $order->getState() == Mage_Sales_Model_Order::STATE_PROCESSING
631
+ && $order->canInvoice()
632
+ ) {
633
+ $invoice = $order->prepareInvoice();
634
+ $invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE);
635
+ $invoice->register();
636
+ $invoice->setState(Mage_Sales_Model_Order_Invoice::STATE_PAID);
637
+ $invoice->getOrder()->setIsInProcess(true);
638
+ $invoice->save();
639
+ $this->sendInvoiceToCustomer($invoice);
640
+
641
+ $transactionSave = Mage::getModel('core/resource_transaction')
642
+ ->addObject($invoice)
643
+ ->addObject($invoice->getOrder())
644
+ ->save();
645
+
646
+ /*
647
+ * If the payment method is a redirect-payment-method send the email
648
+ * In any other case Magento sends an email automatically in Mage_Checkout_Model_Type_Onepage::saveOrder
649
+ */
650
+ if ($this->isRedirectPaymentMethod($order) === true
651
+ && $order->getEmailSent() != 1
652
+ ) {
653
+ $order->sendNewOrderEmail();
654
+ }
655
+ $eventData = array('data_object' => $order, 'order' => $order);
656
+ Mage::dispatchEvent('ops_sales_order_save_commit_after', $eventData);
657
+ }
658
+
659
+ if ($this->isInlinePayment($order->getPayment())
660
+ && 0 < strlen(trim($order->getPayment()->getAdditionalInformation('HTML_ANSWER')))
661
+ && $order->getPayment()->getAdditionalInformation('status') == Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_REQUESTED
662
+ ) {
663
+ $order->getPayment()->setIsTransactionApproved(true)->registerPaymentReviewAction(Mage_Sales_Model_Order_Payment::REVIEW_ACTION_UPDATE, true)->save();
664
+ $this->setInvoicesToPaid($order);
665
+ $order->getPayment()->getAuthorizationTransaction()->setIsClosed(true)->save();
666
+ $order->getPayment()->addTransaction(Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE, $order->getPayment())->setIsClosed(true)->save();
667
+ $order->sendNewOrderEmail();
668
+ $order->save();
669
+ }
670
+ if ($this->isInlinePayment($order->getPayment()) && Mage::getModel('ops/config')->getSendInvoice() && Mage::getModel('ops/config')->getPaymentAction($order->getStoreId()) === Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE_CAPTURE) {
671
+ foreach ($order->getInvoiceCollection() as $invoice) {
672
+ $this->sendInvoiceToCustomer($invoice);
673
+ }
674
+ }
675
+ } else {
676
+ $order->save();
677
+ }
678
+ }
679
+
680
+ /**
681
+ * send invoice to customer if that was configured by the merchant
682
+ *
683
+ * @param Mage_Sales_Model_Order_Invoice $invoice Invoice to be sent
684
+ *
685
+ * @return void
686
+ */
687
+ public function sendInvoiceToCustomer(Mage_Sales_Model_Order_Invoice $invoice)
688
+ {
689
+ if (false == $invoice->getEmailSent()
690
+ && $this->getConfig()->getSendInvoice()
691
+ ) {
692
+ $invoice->sendEmail($notifyCustomer = true);
693
+ }
694
+ }
695
+
696
+ /**
697
+ * Process Configured Payment Actions: Authorized, Default operation
698
+ * just place order
699
+ *
700
+ * @param Mage_Sales_Model_Order $order Order
701
+ * @param array $params Request params
702
+ */
703
+ protected function _processAuthorize($order, $params)
704
+ {
705
+ $status = $params['STATUS'];
706
+ if ($status == Netresearch_OPS_Model_Payment_Abstract::OPS_AWAIT_CUSTOMER_PAYMENT) {
707
+ $order->setState(
708
+ Mage_Sales_Model_Order::STATE_PROCESSING,
709
+ Mage_Sales_Model_Order::STATE_PENDING_PAYMENT,
710
+ Mage::helper('ops')->__(
711
+ 'Waiting for payment. Ingenico Payment Services status: %s.', Mage::helper('ops')->getStatusText($status)
712
+ )
713
+ );
714
+
715
+ // send new order mail for bank transfer, since it is 'successfully' authorized at this point
716
+ if ($order->getPayment()->getMethodInstance() instanceof Netresearch_OPS_Model_Payment_BankTransfer
717
+ && $order->getEmailSent() != 1
718
+ ) {
719
+ $order->sendNewOrderEmail();
720
+ }
721
+ } elseif ($status == Netresearch_OPS_Model_Payment_Abstract::OPS_AUTHORIZED_WAITING) {
722
+ $order->setState(
723
+ Mage_Sales_Model_Order::STATE_PROCESSING,
724
+ Mage_Sales_Model_Order::STATE_PENDING_PAYMENT,
725
+ Mage::helper('ops')->__(
726
+ 'Authorization uncertain. Ingenico Payment Services status: %s.', Mage::helper('ops')->getStatusText($status)
727
+ )
728
+ );
729
+ } else {
730
+ // for 3DS payments the order has to be retrieved from the payment review step
731
+ if ($this->isInlinePayment($order->getPayment())
732
+ && 0 < strlen(trim($order->getPayment()->getAdditionalInformation('HTML_ANSWER')))
733
+ && $order->getPayment()->getAdditionalInformation('status') == Netresearch_OPS_Model_Payment_Abstract::OPS_AUTHORIZED
734
+ ) {
735
+
736
+ $order->getPayment()->setIsTransactionApproved(true)->registerPaymentReviewAction(Mage_Sales_Model_Order_Payment::REVIEW_ACTION_UPDATE, true)->save();
737
+ }
738
+ if ($this->isRedirectPaymentMethod($order) === true
739
+ && $order->getEmailSent() != 1
740
+ ) {
741
+ $order->sendNewOrderEmail();
742
+ }
743
+
744
+
745
+
746
+ $payId = $params['PAYID'];
747
+ $order->setState(
748
+ Mage_Sales_Model_Order::STATE_PROCESSING,
749
+ Mage_Sales_Model_Order::STATE_PROCESSING,
750
+ Mage::helper('ops')->__(
751
+ 'Processed by Ingenico Payment Services. Payment ID: %s. Ingenico Payment Services status: %s.', $payId,
752
+ Mage::helper('ops')->getStatusText($status)
753
+ )
754
+ );
755
+ }
756
+ $order->save();
757
+ }
758
+
759
+ /**
760
+ * Fetches transaction with given transaction id
761
+ *
762
+ * @param string $txnId
763
+ *
764
+ * @return mixed Mage_Sales_Model_Order_Payment_Transaction | boolean
765
+ */
766
+ public function getTransactionByTransactionId($transactionId)
767
+ {
768
+ if (!$transactionId) {
769
+ return;
770
+ }
771
+ $transaction = Mage::getModel('sales/order_payment_transaction')
772
+ ->getCollection()
773
+ ->addAttributeToFilter('txn_id', $transactionId)
774
+ ->getLastItem();
775
+ if (is_null($transaction->getId())) {
776
+ return false;
777
+ }
778
+ $transaction->getOrderPaymentObject();
779
+
780
+ return $transaction;
781
+ }
782
+
783
+ /**
784
+ * refill cart
785
+ *
786
+ * @param Mage_Sales_Model_Order $order
787
+ *
788
+ * @return void
789
+ */
790
+ public function refillCart($order)
791
+ {
792
+ // add items
793
+ $cart = Mage::getSingleton('checkout/cart');
794
+
795
+ if (0 < $cart->getQuote()->getItemsCollection()->count()) {
796
+ //cart is not empty, so refilling it is not required
797
+ return;
798
+ }
799
+ foreach ($order->getItemsCollection() as $item) {
800
+ try {
801
+ $cart->addOrderItem($item);
802
+ } catch (Exception $e) {
803
+ Mage::logException($e);
804
+ }
805
+ }
806
+ $cart->save();
807
+
808
+ // add coupon code
809
+ $coupon = $order->getCouponCode();
810
+ $session = Mage::getSingleton('checkout/session');
811
+ if (false == is_null($coupon)) {
812
+ $session->getQuote()->setCouponCode($coupon)->save();
813
+ }
814
+ }
815
+
816
+ /**
817
+ * Save OPS Status to Payment
818
+ *
819
+ * @param Mage_Sales_Model_Order_Payment $payment
820
+ * @param array $params OPS-Response
821
+ *
822
+ * @return void
823
+ */
824
+ public function saveOpsStatusToPayment(Mage_Sales_Model_Order_Payment $payment, $params)
825
+ {
826
+ $payment
827
+ ->setAdditionalInformation('status', $params['STATUS'])
828
+ ->save();
829
+ }
830
+
831
+ /**
832
+ * Check is payment method is a redirect method
833
+ *
834
+ * @param Mage_Sales_Model_Order $order
835
+ */
836
+ protected function isRedirectPaymentMethod($order)
837
+ {
838
+ $method = $order->getPayment()->getMethodInstance();
839
+ if ($method
840
+ && $method->getOrderPlaceRedirectUrl() != '' //Magento returns ''
841
+ && $method->getOrderPlaceRedirectUrl() !== false
842
+ ) { //Ops return false
843
+ return true;
844
+ } else {
845
+ return false;
846
+ }
847
+ }
848
+
849
+ public function getQuote()
850
+ {
851
+ return $this->_getCheckout()->getQuote();
852
+ }
853
+
854
+ /**
855
+ * sets the state to pending payment if neccessary (order is in state new)
856
+ * and adds a comment to status history
857
+ *
858
+ * @param $order - the order
859
+ */
860
+ public function handleUnknownStatus($order)
861
+ {
862
+ if ($order instanceof Mage_Sales_Model_Order) {
863
+ $message = Mage::helper('ops')->__(
864
+ 'Unknown Ingenico Payment Services state for this order. Please check Ingenico Payment Services backend for this order.'
865
+ );
866
+ if ($order->getState() == Mage_Sales_Model_Order::STATE_NEW) {
867
+ $order->setState(
868
+ Mage_Sales_Model_Order::STATE_PENDING_PAYMENT,
869
+ Mage_Sales_Model_Order::STATE_PENDING_PAYMENT,
870
+ $message
871
+ );
872
+ } else {
873
+ $order->addStatusHistoryComment($message);
874
+ }
875
+ $order->save();
876
+ }
877
+ }
878
+
879
+ /**
880
+ * returns the base grand total from either a quote or an order
881
+ *
882
+ * @param $salesObject
883
+ *
884
+ * @return double the base amount of the order
885
+ * @throws Exception if $salesObject is not a quote or an order
886
+ */
887
+ public function getBaseGrandTotalFromSalesObject($salesObject)
888
+ {
889
+ if ($salesObject instanceof Mage_Sales_Model_Order or $salesObject instanceof Mage_Sales_Model_Quote) {
890
+ return $salesObject->getBaseGrandTotal();
891
+ } else {
892
+ Mage::throwException('$salesObject is not a quote or an order instance');
893
+ }
894
+ }
895
+
896
+
897
+ /**
898
+ * Save the last used refund operation code to payment
899
+ *
900
+ * @param Mage_Sales_Model_Order_Payment $payment
901
+ * @param string $operationCode
902
+ *
903
+ * @return void
904
+ */
905
+ public function saveOpsRefundOperationCodeToPayment(Mage_Sales_Model_Order_Payment $payment, $operationCode)
906
+ {
907
+ if (in_array(
908
+ strtoupper(trim($operationCode)),
909
+ array(
910
+ Netresearch_OPS_Model_Payment_Abstract::OPS_REFUND_FULL,
911
+ Netresearch_OPS_Model_Payment_Abstract::OPS_REFUND_PARTIAL
912
+ ))
913
+ ) {
914
+ Mage::helper('ops/data')->log(
915
+ sprintf("set last refund operation '%s' code to payment for order '%s'",
916
+ $operationCode,
917
+ $payment->getOrder()->getIncrementId()
918
+ )
919
+ );
920
+ $payment
921
+ ->setAdditionalInformation('lastRefundOperationCode', $operationCode)
922
+ ->save();
923
+ }
924
+ }
925
+
926
+ /**
927
+ * sets the canRefund information depending on the last refund operation code
928
+ *
929
+ * @param Mage_Sales_Model_Order_Payment $payment
930
+ */
931
+ public function setCanRefundToPayment(Mage_Sales_Model_Order_Payment $payment)
932
+ {
933
+ $refundOperationCode = $payment->getAdditionalInformation('lastRefundOperationCode');
934
+ if (in_array(
935
+ strtoupper(trim($refundOperationCode)),
936
+ array(
937
+ Netresearch_OPS_Model_Payment_Abstract::OPS_REFUND_FULL,
938
+ Netresearch_OPS_Model_Payment_Abstract::OPS_REFUND_PARTIAL
939
+ ))
940
+ ) {
941
+ /*
942
+ * a further refund is possible if the transaction remains open, that means either the merchant
943
+ * did not close the transaction or the refunded amount is less than the orders amount
944
+ */
945
+ $canRefund = ($refundOperationCode == Netresearch_OPS_Model_Payment_Abstract::OPS_REFUND_PARTIAL);
946
+ Mage::helper('ops/data')->log(
947
+ sprintf("set canRefund to '%s' for payment of order '%s'",
948
+ var_export($canRefund, true),
949
+ $payment->getOrder()->getIncrementId()
950
+ )
951
+ );
952
+ $payment
953
+ ->setAdditionalInformation('canRefund', $canRefund)
954
+ ->save();
955
+ }
956
+ }
957
+
958
+ /**
959
+ * determine whether the payment supports only authorize or not
960
+ * @param Mage_Sales_Model_Order $order
961
+ * @return true . if so, false otherwise
962
+ */
963
+ protected function forceAuthorize(Mage_Sales_Model_Order $order)
964
+ {
965
+ return ($order->getPayment()->getMethodInstance() instanceof Netresearch_OPS_Model_Payment_Kwixo_Abstract);
966
+ }
967
+
968
+
969
+ /**
970
+ * add ops_cc payment to checkout methods if quote total is zero and zero amount checkout is activated
971
+ *
972
+ * @param Mage_Payment_Block_Form_Container $block
973
+ *
974
+ * @return $this
975
+ */
976
+ public function addCCForZeroAmountCheckout(Mage_Payment_Block_Form_Container $block)
977
+ {
978
+ $methods = $block->getMethods();
979
+ if (false === $this->checkIfCCisInCheckoutMethods($methods)) {
980
+ $ccPayment = Mage::getModel('ops/payment_cc');
981
+ if ($ccPayment->getFeatureModel()->isCCAndZeroAmountAuthAllowed($ccPayment, $block->getQuote())) {
982
+ $ccPayment->setInfoInstance($block->getQuote()->getPayment());
983
+ $methods[] = $ccPayment;
984
+ $block->setData('methods', $methods);
985
+ }
986
+ }
987
+
988
+ return $this;
989
+ }
990
+
991
+
992
+ /**
993
+ * check if ops_cc is in payment methods array
994
+ *
995
+ * @param $methods
996
+ *
997
+ * @return array
998
+ */
999
+ protected function checkIfCCisInCheckoutMethods($methods)
1000
+ {
1001
+ $result = false;
1002
+ foreach ($methods as $method) {
1003
+ if ($method->getCode() == 'ops_cc') {
1004
+ $result = true;
1005
+ break;
1006
+ }
1007
+ }
1008
+
1009
+ return $result;
1010
+ }
1011
+
1012
+ /**
1013
+ * checks if the payment method can use order's increment id as merchant's reference
1014
+ *
1015
+ * @param Mage_Payment_Model_Info $payment
1016
+ *
1017
+ * @return bool
1018
+ */
1019
+ public function isInlinePaymentWithOrderId(Mage_Payment_Model_Info $payment)
1020
+ {
1021
+ return $this->isInlinePayment($payment) && (0 < strlen(trim($payment->getMethodInstance()->getConfigPaymentAction())));
1022
+ }
1023
+
1024
+ /**
1025
+ * checks if the payment method can pbe processed via direct link
1026
+ *
1027
+ * @param Mage_Payment_Model_Info $payment
1028
+ *
1029
+ * @return bool
1030
+ */
1031
+ public function isInlinePayment(Mage_Payment_Model_Info $payment)
1032
+ {
1033
+ $result = false;
1034
+ $methodInstance = $payment->getMethodInstance();
1035
+ if ($methodInstance instanceof Netresearch_OPS_Model_Payment_DirectDebit
1036
+ || ($methodInstance instanceof Netresearch_OPS_Model_Payment_Cc
1037
+ && ($methodInstance->hasBrandAliasInterfaceSupport($payment) || Mage::helper('ops/data')->isAdminSession()))
1038
+ ) {
1039
+ $result = true;
1040
+ }
1041
+
1042
+ return $result;
1043
+ }
1044
+
1045
+ /**
1046
+ * checks if the inline payment can use quote id as merchant's reference
1047
+ *
1048
+ * @param Mage_Payment_Model_Info $payment
1049
+ *
1050
+ * @return bool
1051
+ */
1052
+ public function isInlinePaymentWithQuoteId(Mage_Payment_Model_Info $payment)
1053
+ {
1054
+ return $this->isInlinePayment($payment) && (0 === strlen(trim($payment->getMethodInstance()->getConfigPaymentAction())));
1055
+ }
1056
+
1057
+ /**
1058
+ * sets the invoices of an order to paid
1059
+ *
1060
+ * @param Mage_Sales_Model_Order $order
1061
+ * @return Netresearch_OPS_Helper_Payment
1062
+ */
1063
+ public function setInvoicesToPaid($order)
1064
+ {
1065
+ /** @var $invoice Mage_Sales_Model_Order_Invoice */
1066
+ foreach ($order->getInvoiceCollection() as $invoice) {
1067
+ $invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE);
1068
+ $invoice->setState(Mage_Sales_Model_Order_Invoice::STATE_PAID);
1069
+ $invoice->save();
1070
+ }
1071
+
1072
+ return $this;
1073
+ }
1074
+
1075
+ /**
1076
+ * cancel all invoices for a given order
1077
+ *
1078
+ * @param $order
1079
+ *
1080
+ * @return Netresearch_OPS_Helper_Payment
1081
+ * @throws Exception
1082
+ */
1083
+ public function cancelInvoices($order)
1084
+ {
1085
+ /** @var $invoice Mage_Sales_Model_Order_Invoice */
1086
+ foreach ($order->getInvoiceCollection() as $invoice) {
1087
+ $invoice->setState(Mage_Sales_Model_Order_Invoice::STATE_CANCELED);
1088
+ $invoice->save();
1089
+ }
1090
+
1091
+ return $this;
1092
+ }
1093
+
1094
+ /**
1095
+ * Returns if the current payment status is an invalid one, namely if it is one of the following:
1096
+ * Netresearch_OPS_Model_Payment_Abstract::OPS_INVALID,
1097
+ * Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_CANCELED_BY_CUSTOMER,
1098
+ * Netresearch_OPS_Model_Payment_Abstract::OPS_AUTH_REFUSED,
1099
+ *
1100
+ * @param $status
1101
+ * @return bool
1102
+ */
1103
+ public function isPaymentInvalid($status)
1104
+ {
1105
+ return in_array(
1106
+ $status,
1107
+ array(
1108
+ Netresearch_OPS_Model_Payment_Abstract::OPS_INVALID,
1109
+ Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_CANCELED_BY_CUSTOMER,
1110
+ Netresearch_OPS_Model_Payment_Abstract::OPS_AUTH_REFUSED,
1111
+ )
1112
+ );
1113
+ }
1114
+
1115
+ }
app/code/community/Netresearch/OPS/Helper/Payment/DirectLink/Request.php ADDED
@@ -0,0 +1,329 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Michael Lühr <michael.luehr@netresearch.de>
4
+ * @category Netresearch
5
+ * @package Netresearch_OPS
6
+ * @copyright Copyright (c) 2013 Netresearch GmbH & Co. KG (http://www.netresearch.de)
7
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
8
+ */
9
+
10
+
11
+
12
+ abstract class Netresearch_OPS_Helper_Payment_DirectLink_Request
13
+ implements Netresearch_OPS_Helper_Payment_DirectLink_RequestInterface
14
+ {
15
+
16
+ protected $dataHelper = null;
17
+
18
+ protected $quoteHelper = null;
19
+
20
+ protected $orderHelper = null;
21
+
22
+ protected $customerHelper = null;
23
+
24
+ protected $validator = null;
25
+
26
+ protected $requestHelper = null;
27
+
28
+ protected $config = null;
29
+
30
+ /**
31
+ * @param null $config
32
+ */
33
+ public function setConfig($config)
34
+ {
35
+ $this->config = $config;
36
+ }
37
+
38
+ /**
39
+ * @return Netresearch_OPS_Model_Config
40
+ */
41
+ public function getConfig()
42
+ {
43
+ if (null === $this->config) {
44
+ $this->config = Mage::getModel('ops/config');
45
+ }
46
+ return $this->config;
47
+ }
48
+
49
+ public function setRequestHelper(Netresearch_OPS_Helper_Payment_Request $requestHelper)
50
+ {
51
+ $this->requestHelper = $requestHelper;
52
+ }
53
+
54
+ /**
55
+ * @return Netresearch_OPS_Helper_Payment_Request
56
+ */
57
+ public function getRequestHelper()
58
+ {
59
+ if (null === $this->requestHelper) {
60
+ $this->requestHelper = Mage::helper('ops/payment_request');
61
+ $this->requestHelper->setConfig($this->getConfig());
62
+ }
63
+
64
+ return $this->requestHelper;
65
+ }
66
+
67
+ /**
68
+ * sets the data helper
69
+ *
70
+ * @param Netresearch_OPS_Helper_Data $dataHelper
71
+ */
72
+ public function setDataHelper(Netresearch_OPS_Helper_Data $dataHelper)
73
+ {
74
+ $this->dataHelper = $dataHelper;
75
+ }
76
+
77
+ /**
78
+ * gets the data helper
79
+ *
80
+ * @return Mage_Core_Helper_Abstract
81
+ */
82
+ public function getDataHelper()
83
+ {
84
+ if (null === $this->dataHelper) {
85
+ $this->dataHelper = Mage::helper('ops/data');
86
+ }
87
+
88
+ return $this->dataHelper;
89
+ }
90
+
91
+ /**
92
+ * sets the quote helper
93
+ *
94
+ * @param Netresearch_OPS_Helper_Quote $quoteHelper
95
+ */
96
+ public function setQuoteHelper(Netresearch_OPS_Helper_Quote $quoteHelper)
97
+ {
98
+ $this->quoteHelper = $quoteHelper;
99
+ }
100
+
101
+ /**
102
+ * gets the quote helper
103
+ *
104
+ * @return Mage_Core_Helper_Abstract
105
+ */
106
+ public function getQuoteHelper()
107
+ {
108
+ if (null === $this->quoteHelper) {
109
+ $this->quoteHelper = Mage::helper('ops/quote');
110
+ }
111
+
112
+ return $this->quoteHelper;
113
+ }
114
+
115
+ /**
116
+ * sets the order helper
117
+ *
118
+ * @param Netresearch_OPS_Helper_Order $orderHelper
119
+ */
120
+ public function setOrderHelper(Netresearch_OPS_Helper_Order $orderHelper)
121
+ {
122
+ $this->orderHelper = $orderHelper;
123
+ }
124
+
125
+ /**
126
+ * gets the order helper
127
+ *
128
+ * @return Netresearch_OPS_Helper_Order
129
+ */
130
+ public function getOrderHelper()
131
+ {
132
+ if (null === $this->orderHelper) {
133
+ $this->orderHelper = Mage::helper('ops/order');
134
+ }
135
+
136
+ return $this->orderHelper;
137
+ }
138
+
139
+ /**
140
+ * sets the customer helper
141
+ *
142
+ * @param Mage_Customer_Helper_Data $customerHelper
143
+ */
144
+ public function setCustomerHelper(Mage_Core_Helper_Abstract $customerHelper)
145
+ {
146
+ $this->customerHelper = $customerHelper;
147
+ }
148
+
149
+ /**
150
+ * gets the customer helper
151
+ *
152
+ * @return Mage_Customer_Helper_Data
153
+ */
154
+ public function getCustomerHelper()
155
+ {
156
+ if (null === $this->customerHelper) {
157
+ $this->customerHelper = Mage::helper('customer/data');
158
+ }
159
+
160
+ return $this->customerHelper;
161
+ }
162
+
163
+
164
+ /**
165
+ * extracts the parameter for the direct link request from the quote, order and, optionally from existing request params
166
+ *
167
+ * @param Mage_Sales_Model_Quote $quote
168
+ * @param Mage_Sales_Model_Order $order
169
+ * @param array $requestParams
170
+ *
171
+ * @return array - the parameters for the direct link request
172
+ */
173
+ public function getDirectLinkRequestParams(Mage_Sales_Model_Quote $quote, Mage_Sales_Model_Order $order, $requestParams = array())
174
+ {
175
+ $billingAddress = $order->getBillingAddress();
176
+ $shippingAddress = $this->getShippingAddress($order, $billingAddress);
177
+ $requestParams = $this->getBaseRequestParams($quote, $order, $billingAddress);
178
+ $requestParams = array_merge($requestParams, $this->getPaymentSpecificParams($quote));
179
+
180
+ if ($this->getConfig()->canSubmitExtraParameter($quote->getStoreId())) {
181
+ $shipToParams = $this->getRequestHelper()->extractShipToParameters($shippingAddress, $quote);
182
+ $shipToParams = $this->decodeParamsForDirectLinkCall($shipToParams);
183
+ $requestParams = array_merge($requestParams, $shipToParams);
184
+ }
185
+
186
+ $requestParams = $this->addCustomerSpecificParams($requestParams);
187
+ $requestParams = $this->addParamsForAdminPayments($requestParams);
188
+
189
+ return $requestParams;
190
+ }
191
+
192
+ /**
193
+ * specail handling like validation and so on for admin payments
194
+ *
195
+ * @param Mage_Sales_Model_Quote $quote
196
+ * @param array $requestParams
197
+ *
198
+ * @return mixed
199
+ */
200
+ abstract public function handleAdminPayment(Mage_Sales_Model_Quote $quote, $requestParams);
201
+
202
+ /**
203
+ * extracts payment specific payment parameters
204
+ *
205
+ * @param Mage_Sales_Model_Quote $quote
206
+ *
207
+ * @return array
208
+ */
209
+ abstract protected function getPaymentSpecificParams(Mage_Sales_Model_Quote $quote);
210
+
211
+ /**
212
+ * gets the shipping address if there is one, otherwise the billing address is used as shipping address
213
+ *
214
+ * @param $order
215
+ * @param $billingAddress
216
+ *
217
+ * @return mixed
218
+ */
219
+ protected function getShippingAddress(Mage_Sales_Model_Order $order, $billingAddress)
220
+ {
221
+ $shippingAddress = $order->getShippingAddress();
222
+ if (null === $shippingAddress || false === $shippingAddress) {
223
+ $shippingAddress = $billingAddress;
224
+ }
225
+ return $shippingAddress;
226
+ }
227
+
228
+ /**
229
+ * utf8 decode for direct link calls
230
+ *
231
+ * @param array $requestParams
232
+ *
233
+ * @return array - the decoded array
234
+ */
235
+ protected function decodeParamsForDirectLinkCall(array $requestParams)
236
+ {
237
+ foreach ($requestParams as $key => $value) {
238
+ $requestParams[$key] = utf8_decode($value);
239
+ }
240
+ return $requestParams;
241
+ }
242
+
243
+ /**
244
+ * @param $requestParams
245
+ *
246
+ * @return mixed
247
+ */
248
+ protected function addCustomerSpecificParams($requestParams)
249
+ {
250
+ if ($this->getCustomerHelper()->isLoggedIn()) {
251
+ $requestParams['CUID'] = $this->getCustomerHelper()->getCustomer()->getId();
252
+ }
253
+ return $requestParams;
254
+ }
255
+
256
+ /**
257
+ * @param $requestParams
258
+ *
259
+ * @return mixed
260
+ */
261
+ protected function addParamsForAdminPayments($requestParams)
262
+ {
263
+ if ($this->getDataHelper()->isAdminSession()) {
264
+ $requestParams['ECI'] = Netresearch_OPS_Model_Eci_Values::MANUALLY_KEYED_FROM_MOTO;
265
+ $requestParams['REMOTE_ADDR'] = 'NONE';//$order->getRemoteIp();
266
+ }
267
+ return $requestParams;
268
+ }
269
+
270
+ /**
271
+ * @param $quote
272
+ * @param $order
273
+ * @param $billingAddress
274
+ *
275
+ * @return array
276
+ */
277
+ protected function getBaseRequestParams($quote, $order, $billingAddress)
278
+ {
279
+ $merchantRef = $this->getOrderHelper()->getOpsOrderId($order, $this->canUseOrderId($quote->getPayment()));
280
+ $requestParams = array(
281
+ 'AMOUNT' => $this->getDataHelper()->getAmount($quote->getBaseGrandTotal()),
282
+ 'CURRENCY' => $this->getQuoteHelper()->getQuoteCurrency($quote),
283
+ 'OPERATION' => $this->getQuoteHelper()->getPaymentAction($quote),
284
+ 'ORDERID' => $merchantRef,
285
+ 'ORIG' => $this->getDataHelper()->getModuleVersionString(),
286
+ 'EMAIL' => $order->getCustomerEmail(),
287
+ 'REMOTE_ADDR' => $quote->getRemoteIp(),
288
+ );
289
+
290
+ $ownerParams = $this->getOwnerParams($quote, $billingAddress, $requestParams);
291
+ $requestParams = array_merge($requestParams, $ownerParams);
292
+ $requestParams['ADDMATCH'] = $this->getOrderHelper()->checkIfAddressesAreSame($order);
293
+
294
+ return $requestParams;
295
+ }
296
+
297
+ /**
298
+ * @param $quote
299
+ * @param $billingAddress
300
+ * @param $requestParams
301
+ *
302
+ * @return array
303
+ */
304
+ protected function getOwnerParams($quote, $billingAddress, $requestParams)
305
+ {
306
+ $ownerParams = $this->getRequestHelper()->getOwnerParams($quote, $billingAddress);
307
+ if (array_key_exists('OWNERADDRESS', $ownerParams) && array_key_exists('OWNERTOWN', $ownerParams)) {
308
+ $ownerAddrParams = $this->decodeParamsForDirectLinkCall(
309
+ array('OWNERADDRESS' => $ownerParams['OWNERADDRESS'], 'OWNERTOWN' => $ownerParams['OWNERTOWN'])
310
+ );
311
+ $ownerParams = array_merge($ownerParams, $ownerAddrParams);
312
+ }
313
+
314
+ return $ownerParams;
315
+ }
316
+
317
+ /**
318
+ * @return bool
319
+ */
320
+ protected function canUseOrderId(Varien_Object $payment)
321
+ {
322
+ $methodInstance = $payment->getMethodInstance();
323
+ return
324
+ $this->getConfig()->getInlineOrderReference() == Netresearch_OPS_Model_Payment_Abstract::REFERENCE_ORDER_ID
325
+ && ($methodInstance instanceof Netresearch_OPS_Model_Payment_DirectLink && 0 < strlen(trim($methodInstance->getConfigPaymentAction())));
326
+ }
327
+
328
+
329
+ }
app/code/community/Netresearch/OPS/Helper/Payment/DirectLink/RequestInterface.php ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Michael Lühr <michael.luehr@netresearch.de>
4
+ * @category Netresearch
5
+ * @copyright Copyright (c) 2014 Netresearch GmbH & Co. KG (http://www.netresearch.de)
6
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
7
+ */
8
+
9
+ /**
10
+ * @author Michael Lühr <michael.luehr@netresearch.de>
11
+ * @category Netresearch
12
+ * @package Netresearch_OPS
13
+ * @copyright Copyright (c) 2013 Netresearch GmbH & Co. KG (http://www.netresearch.de)
14
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
15
+ */
16
+ interface Netresearch_OPS_Helper_Payment_DirectLink_RequestInterface
17
+ {
18
+ /**
19
+ * sets the data helper
20
+ *
21
+ * @param Netresearch_OPS_Helper_Data $dataHelper
22
+ */
23
+ public function setDataHelper(Netresearch_OPS_Helper_Data $dataHelper);
24
+
25
+ /**
26
+ * @return Netresearch_OPS_Model_Config
27
+ */
28
+ public function getConfig();
29
+
30
+ /**
31
+ * sets the quote helper
32
+ *
33
+ * @param Netresearch_OPS_Helper_Quote $quoteHelper
34
+ */
35
+ public function setQuoteHelper(Netresearch_OPS_Helper_Quote $quoteHelper);
36
+
37
+ /**
38
+ * extracts the parameter for the direct link request from the quote, order and, optionally from existing request params
39
+ *
40
+ * @param Mage_Sales_Model_Quote $quote
41
+ * @param Mage_Sales_Model_Order $order
42
+ * @param array $requestParams
43
+ *
44
+ * @return array - the parameters for the direct link request
45
+ */
46
+ public function getDirectLinkRequestParams(
47
+ Mage_Sales_Model_Quote $quote,
48
+ Mage_Sales_Model_Order $order,
49
+ $requestParams = array()
50
+ );
51
+
52
+ /**
53
+ * @param null $config
54
+ */
55
+ public function setConfig($config);
56
+
57
+ /**
58
+ * sets the order helper
59
+ *
60
+ * @param Netresearch_OPS_Helper_Order $orderHelper
61
+ */
62
+ public function setOrderHelper(Netresearch_OPS_Helper_Order $orderHelper);
63
+
64
+ /**
65
+ * sets the customer helper
66
+ *
67
+ * @param Mage_Core_Helper_Abstract $customerHelper
68
+ */
69
+ public function setCustomerHelper(Mage_Core_Helper_Abstract $customerHelper);
70
+
71
+ public function setRequestHelper(Netresearch_OPS_Helper_Payment_Request $requestHelper);
72
+
73
+ /**
74
+ * gets the customer helper
75
+ *
76
+ * @return Mage_Core_Helper_Abstract
77
+ */
78
+ public function getCustomerHelper();
79
+
80
+ /**
81
+ * gets the order helper
82
+ *
83
+ * @return Mage_Core_Helper_Abstract
84
+ */
85
+ public function getOrderHelper();
86
+
87
+ /**
88
+ * gets the data helper
89
+ *
90
+ * @return Mage_Core_Helper_Abstract
91
+ */
92
+ public function getDataHelper();
93
+
94
+ /**
95
+ * @return Netresearch_OPS_Helper_Payment_Request
96
+ */
97
+ public function getRequestHelper();
98
+
99
+ /**
100
+ * special handling like validation and so on for admin payments
101
+ *
102
+ * @param Mage_Sales_Model_Quote $quote
103
+ * @param $requestParams
104
+ *
105
+ * @return mixed
106
+ */
107
+ public function handleAdminPayment(Mage_Sales_Model_Quote $quote, $requestParams);
108
+
109
+ /**
110
+ * gets the quote helper
111
+ *
112
+ * @return Mage_Core_Helper_Abstract
113
+ */
114
+ public function getQuoteHelper();
115
+ }
app/code/community/Netresearch/OPS/Helper/Payment/Request.php ADDED
@@ -0,0 +1,574 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @author Michael Lühr <michael.luehr@netresearch.de>
5
+ * @category Netresearch
6
+ * @package Netresearch_OPS
7
+ * @copyright Copyright (c) 2014 Netresearch GmbH & Co. KG (http://www.netresearch.de)
8
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
9
+ */
10
+ class Netresearch_OPS_Helper_Payment_Request
11
+ {
12
+ protected $config = null;
13
+
14
+ /**
15
+ * @param null $config
16
+ */
17
+ public function setConfig($config)
18
+ {
19
+ $this->config = $config;
20
+ }
21
+
22
+ /**
23
+ * @return null
24
+ */
25
+ public function getConfig()
26
+ {
27
+ if ($this->config === null) {
28
+ $this->config = Mage::getModel('ops/config');
29
+ }
30
+
31
+ return $this->config;
32
+ }
33
+
34
+
35
+ /**
36
+ * extracts the ship to information from a given address
37
+ *
38
+ * @param Mage_Customer_Model_Address_Abstract $address
39
+ * @param Mage_Sales_Model_Quote $quote
40
+ *
41
+ * @return array - the parameters containing the ship to data
42
+ */
43
+ public function extractShipToParameters(
44
+ Mage_Customer_Model_Address_Abstract $address, $order=null
45
+ ) {
46
+ $paramValues = array();
47
+ $paramValues['ECOM_SHIPTO_POSTAL_NAME_FIRST'] = $address->getFirstname();
48
+ $paramValues['ECOM_SHIPTO_POSTAL_NAME_LAST'] = $address->getLastname();
49
+ $paramValues['ECOM_SHIPTO_POSTAL_STREET_LINE1'] = $address->getStreet(1);
50
+ $paramValues['ECOM_SHIPTO_POSTAL_STREET_LINE2'] = $address->getStreet(2);
51
+ $paramValues['ECOM_SHIPTO_POSTAL_COUNTRYCODE'] = $address->getCountry();
52
+ $paramValues['ECOM_SHIPTO_POSTAL_CITY'] = $address->getCity();
53
+ $paramValues['ECOM_SHIPTO_POSTAL_POSTALCODE'] = $address->getPostcode();
54
+ $paramValues['ECOM_SHIPTO_POSTAL_STATE'] = $this->getIsoRegionCode($address);
55
+
56
+ return $paramValues;
57
+ }
58
+
59
+ public function extractBillToParameters(
60
+ Mage_Customer_Model_Address_Abstract $address, $order=null
61
+ ) {
62
+ $paramValues = array();
63
+ $paramValues['ECOM_BILLTO_POSTAL_CITY'] = $address->getCity();
64
+ $paramValues['ECOM_BILLTO_POSTAL_COUNTRYCODE'] = $this->getCountry();
65
+ $paramValues['ECOM_BILLTO_POSTAL_NAME_FIRST'] = $address->getFirstname();
66
+ $paramValues['ECOM_BILLTO_POSTAL_NAME_LAST'] = $address->getLastname();
67
+ $paramValues['ECOM_BILLTO_POSTAL_POSTALCODE'] = $address->getPostcode();
68
+ $paramValues['ECOM_BILLTO_POSTAL_STREET_LINE1'] = $address->getStreet(1);
69
+ $paramValues['ECOM_BILLTO_POSTAL_STREET_LINE2'] = $address->getStreet(2);
70
+
71
+ return $paramValues;
72
+ }
73
+ /**
74
+ * extraxcts the according Ingenico Payment Services owner* parameter
75
+ *
76
+ * @param Mage_Sales_Model_Quote $quote
77
+ * @param Mage_Customer_Model_Address_Abstract $billingAddress
78
+ *
79
+ * @return array
80
+ */
81
+ public function getOwnerParams(Mage_Sales_Model_Quote $quote, Mage_Customer_Model_Address_Abstract $billingAddress)
82
+ {
83
+ $ownerParams = array();
84
+ if ($this->getConfig()->canSubmitExtraParameter($quote->getStoreId())) {
85
+ $ownerParams = array(
86
+ 'OWNERADDRESS' => str_replace("\n", ' ', $billingAddress->getStreet(1)),
87
+ 'OWNERTOWN' => $billingAddress->getCity(),
88
+ 'OWNERZIP' => $billingAddress->getPostcode(),
89
+ 'OWNERTELNO' => $billingAddress->getTelephone(),
90
+ 'OWNERCTY' => $billingAddress->getCountry(),
91
+
92
+ 'ECOM_BILLTO_POSTAL_POSTALCODE' => $billingAddress->getPostcode(),
93
+ );
94
+ }
95
+
96
+ return $ownerParams;
97
+ }
98
+
99
+ /**
100
+ * extracts the region code in iso format (if possible)
101
+ *
102
+ * @param Mage_Customer_Model_Address_Abstract $address
103
+ *
104
+ * @return string - the regin code in iso format
105
+ */
106
+ public function getIsoRegionCode(Mage_Customer_Model_Address_Abstract $address)
107
+ {
108
+ $regionCode = trim($address->getRegionCode());
109
+ $countryCode = $address->getCountry();
110
+ if ($this->isAlreadyIsoCode($regionCode, $countryCode)) {
111
+ return $regionCode;
112
+ }
113
+ if (0 === strpos($regionCode, $countryCode . '-')) {
114
+ return str_replace($countryCode . '-', '', $regionCode);
115
+ }
116
+
117
+ return $this->getRegionCodeFromMapping($countryCode, $regionCode);
118
+ }
119
+
120
+ /**
121
+ * checks if the given region code is already in iso format
122
+ *
123
+ * @param $regionCode
124
+ * @param $countryCode
125
+ *
126
+ * @return bool
127
+ */
128
+ protected function isAlreadyIsoCode($regionCode, $countryCode)
129
+ {
130
+ return ((strlen($regionCode) < 3 && !in_array($countryCode, array('AT')))
131
+ || (strlen($regionCode) === 3 && !in_array($countryCode, array('DE'))));
132
+ }
133
+
134
+ protected function getRegionCodeFromMapping($countryCode, $regionCode)
135
+ {
136
+ $countryRegionMapping = $this->getCountryRegionMapping($countryCode);
137
+ if (array_key_exists($regionCode, $countryRegionMapping)) {
138
+ return $countryRegionMapping[$regionCode];
139
+ }
140
+
141
+ return $countryCode;
142
+ }
143
+
144
+ /**
145
+ * retrieves country specific region mapping
146
+ *
147
+ * @param $countryCode
148
+ *
149
+ * @return array - the country specific region mapping or empty array if mapping could not be found
150
+ */
151
+ protected function getCountryRegionMapping($countryCode)
152
+ {
153
+ if (strtoupper($countryCode) === 'DE') {
154
+ return $this->getRegionMappingForGermany();
155
+ }
156
+ if (strtoupper($countryCode) === 'AT') {
157
+ return $this->getRegionMappingForAustria();
158
+ }
159
+ if (strtoupper($countryCode) === 'ES') {
160
+ return $this->getRegionMappingForSpain();
161
+ }
162
+ if (strtoupper($countryCode) === 'FI') {
163
+ return $this->getRegionsMappingForFinland();
164
+ }
165
+ if (strtoupper($countryCode) === 'LV') {
166
+ return $this->getRegionsMappingForLatvia();
167
+ }
168
+
169
+ return array();;
170
+ }
171
+
172
+ /**
173
+ * translates the Magento's region code for germany into ISO format
174
+ *
175
+ * @return array
176
+ */
177
+ protected function getRegionMappingForGermany()
178
+ {
179
+ return array(
180
+ 'NDS' => 'NI',
181
+ 'BAW' => 'BW',
182
+ 'BAY' => 'BY',
183
+ 'BER' => 'BE',
184
+ 'BRG' => 'BB',
185
+ 'BRE' => 'HB',
186
+ 'HAM' => 'HH',
187
+ 'HES' => 'HE',
188
+ 'MEC' => 'MV',
189
+ 'NRW' => 'NW',
190
+ 'RHE' => 'RP',
191
+ 'SAR' => 'SL',
192
+ 'SAS' => 'SN',
193
+ 'SAC' => 'ST',
194
+ 'SCN' => 'SH',
195
+ 'THE' => 'TH'
196
+ );
197
+ }
198
+
199
+ /**
200
+ * translates the Magento's region code for austria into ISO format
201
+ *
202
+ * @return array
203
+ */
204
+ protected function getRegionMappingForAustria()
205
+ {
206
+ return array(
207
+ 'WI' => '9',
208
+ 'NO' => '3',
209
+ 'OO' => '4',
210
+ 'SB' => '5',
211
+ 'KN' => '2',
212
+ 'ST' => '6',
213
+ 'TI' => '7',
214
+ 'BL' => '1',
215
+ 'VB' => '8'
216
+ );
217
+ }
218
+
219
+ /**
220
+ * translates the Magento's region code for spain into ISO format
221
+ *
222
+ * @return array
223
+ */
224
+ protected function getRegionMappingForSpain()
225
+ {
226
+ return array(
227
+ 'A Coruсa' => 'C',
228
+ 'Alava' => 'VI',
229
+ 'Albacete' => 'AB',
230
+ 'Alicante' => 'A',
231
+ 'Almeria' => 'AL',
232
+ 'Asturias' => 'O',
233
+ 'Avila' => 'AV',
234
+ 'Badajoz' => 'BA',
235
+ 'Baleares' => 'PM',
236
+ 'Barcelona' => 'B',
237
+ 'Caceres' => 'CC',
238
+ 'Cadiz' => 'CA',
239
+ 'Cantabria' => 'S',
240
+ 'Castellon' => 'CS',
241
+ 'Ceuta' => 'CE',
242
+ 'Ciudad Real' => 'CR',
243
+ 'Cordoba' => 'CO',
244
+ 'Cuenca' => 'CU',
245
+ 'Girona' => 'GI',
246
+ 'Granada' => 'GR',
247
+ 'Guadalajara' => 'GU',
248
+ 'Guipuzcoa' => 'SS',
249
+ 'Huelva' => 'H',
250
+ 'Huesca' => 'HU',
251
+ 'Jaen' => 'J',
252
+ 'La Rioja' => 'LO',
253
+ 'Las Palmas' => 'GC',
254
+ 'Leon' => 'LE',
255
+ 'Lleida' => 'L',
256
+ 'Lugo' => 'LU',
257
+ 'Madrid' => 'M',
258
+ 'Malaga' => 'MA',
259
+ 'Melilla' => 'ML',
260
+ 'Murcia' => 'MU',
261
+ 'Navarra' => 'NA',
262
+ 'Ourense' => 'OR',
263
+ 'Palencia' => 'P',
264
+ 'Pontevedra' => 'PO',
265
+ 'Salamanca' => 'SA',
266
+ 'Santa Cruz de Tenerife' => 'TF',
267
+ 'Segovia' => 'Z',
268
+ 'Sevilla' => 'SG',
269
+ 'Soria' => 'SE',
270
+ 'Tarragona' => 'SO',
271
+ 'Teruel' => 'T',
272
+ 'Toledo' => 'TE',
273
+ 'Valencia' => 'TO',
274
+ 'Valladolid' => 'V',
275
+ 'Vizcaya' => 'VA',
276
+ 'Zamora' => 'BI',
277
+ 'Zaragoza' => 'ZA',
278
+ );
279
+ }
280
+
281
+ /**
282
+ * translates the Magento's region code for finland into ISO format
283
+ *
284
+ * @return array
285
+ */
286
+ protected function getRegionsMappingForFinland()
287
+ {
288
+ return array(
289
+ 'Lappi' => '10',
290
+ 'Pohjois-Pohjanmaa' => '14',
291
+ 'Kainuu' => '05',
292
+ 'Pohjois-Karjala' => '13',
293
+ 'Pohjois-Savo' => '15',
294
+ 'Etelä-Savo' => '04',
295
+ 'Etelä-Pohjanmaa' => '03',
296
+ 'Pohjanmaa' => '12',
297
+ 'Pirkanmaa' => '11',
298
+ 'Satakunta' => '17',
299
+ 'Keski-Pohjanmaa' => '07',
300
+ 'Keski-Suomi' => '08',
301
+ 'Varsinais-Suomi' => '19',
302
+ 'Etelä-Karjala' => '02',
303
+ 'Päijät-Häme' => '16',
304
+ 'Kanta-Häme' => '06',
305
+ 'Uusimaa' => '18',
306
+ 'Itä-Uusimaa' => '19',
307
+ 'Kymenlaakso' => '09',
308
+ 'Ahvenanmaa' => '01'
309
+ );
310
+ }
311
+
312
+ /**
313
+ * translates the Magento's region code for latvia into ISO format
314
+ *
315
+ * @return array
316
+ */
317
+ protected function getRegionsMappingForLatvia()
318
+ {
319
+ return array(
320
+ 'Ādažu novads' => 'LV',
321
+ 'Aglonas novads' => '001',
322
+ 'Aizputes novads' => '003',
323
+ 'Aknīstes novads' => '004',
324
+ 'Alojas novads' => '005',
325
+ 'Alsungas novads' => '006',
326
+ 'Amatas novads' => '008',
327
+ 'Apes novads' => '009',
328
+ 'Auces novads' => '010',
329
+ 'Babītes novads' => '012',
330
+ 'Baldones novads' => '013',
331
+ 'Baltinavas novads' => '014',
332
+ 'Beverīnas novads' => '017',
333
+ 'Brocēnu novads' => '018',
334
+ 'Burtnieku novads' => '019',
335
+ 'Carnikavas novads' => '020',
336
+ 'Cesvaines novads' => '021',
337
+ 'Ciblas novads' => '023',
338
+ 'Dagdas novads' => '024',
339
+ 'Dundagas novads' => '027',
340
+ 'Durbes novads' => '028',
341
+ 'Engures novads' => '029',
342
+ 'Ērgļu novads' => 'LV',
343
+ 'Garkalnes novads' => '031',
344
+ 'Grobiņas novads' => '032',
345
+ 'Iecavas novads' => '034',
346
+ 'Ikšķiles novads' => '035',
347
+ 'Ilūkstes novads' => '036',
348
+ 'Inčukalna novads' => '037',
349
+ 'Jaunjelgavas novads' => '038',
350
+ 'Jaunpiebalgas novads' => '039',
351
+ 'Jaunpils novads' => '040',
352
+ 'Jēkabpils' => '042',
353
+ 'Kandavas novads' => '043',
354
+ 'Kārsavas novads' => 'LV',
355
+ 'Ķeguma novads' => 'LV',
356
+ 'Ķekavas novads' => 'LV',
357
+ 'Kokneses novads' => '046',
358
+ 'Krimuldas novads' => '048',
359
+ 'Krustpils novads' => '049',
360
+ 'Lielvārdes novads' => '053',
361
+ 'Līgatnes novads' => 'LV',
362
+ 'Līvānu novads' => '056',
363
+ 'Lubānas novads' => '057',
364
+ 'Mālpils novads' => '061',
365
+ 'Mārupes novads' => '062',
366
+ 'Mazsalacas novads' => '060',
367
+ 'Naukšēnu novads' => '064',
368
+ 'Neretas novads' => '065',
369
+ 'Nīcas novads' => '066',
370
+ 'Olaines novads' => '068',
371
+ 'Ozolnieku novads' => '069',
372
+ 'Pārgaujas novads' => 'LV',
373
+ 'Pāvilostas novads' => '070',
374
+ 'Pļaviņu novads' => '072',
375
+ 'Priekules novads' => '074',
376
+ 'Priekuļu novads' => '075',
377
+ 'Raunas novads' => '076',
378
+ 'Riebiņu novads' => '078',
379
+ 'Rojas novads' => '079',
380
+ 'Ropažu novads' => '080',
381
+ 'Rucavas novads' => '081',
382
+ 'Rugāju novads' => '082',
383
+ 'Rūjienas novads' => '084',
384
+ 'Rundāles novads' => '083',
385
+ 'Salacgrīvas novads' => '085',
386
+ 'Salas novads' => '086',
387
+ 'Salaspils novads' => '087',
388
+ 'Saulkrastu novads' => '089',
389
+ 'Sējas novads' => 'LV',
390
+ 'Siguldas novads' => '091',
391
+ 'Skrīveru novads' => '092',
392
+ 'Skrundas novads' => '093',
393
+ 'Smiltenes novads' => '094',
394
+ 'Stopiņu novads' => '095',
395
+ 'Strenču novads' => '096',
396
+ 'Tērvetes novads' => '098',
397
+ 'Vaiņodes novads' => '100',
398
+ 'Valmiera' => 'LV',
399
+ 'Varakļānu novads' => '102',
400
+ 'Vārkavas novads' => 'LV',
401
+ 'Vecpiebalgas novads' => '104',
402
+ 'Vecumnieku novads' => '105',
403
+ 'Viesītes novads' => '107',
404
+ 'Viļakas novads' => '108',
405
+ 'Viļānu novads' => '109',
406
+ 'Zilupes novads' => '110'
407
+ );
408
+ }
409
+
410
+ /**
411
+ * Returns the mandatory fields for requests to Ingenico Payment Services
412
+ *
413
+ * @param Mage_Sales_Model_Order $order
414
+ *
415
+ * @return array
416
+ */
417
+
418
+ public function getMandatoryRequestFields(Mage_Sales_Model_Order $order)
419
+ {
420
+ $payment = $order->getPayment()->getMethodInstance();
421
+ $formFields = array();
422
+ $formFields['PSPID'] = $this->getConfig()->getPSPID($order->getStoreId());
423
+ $formFields['AMOUNT'] = Mage::helper('ops')->getAmount($order->getBaseGrandTotal());
424
+ $formFields['CURRENCY'] = Mage::app()->getStore()->getBaseCurrencyCode();
425
+ $formFields['ORDERID'] = Mage::helper('ops/order')->getOpsOrderId($order);
426
+ $formFields['LANGUAGE'] = Mage::app()->getLocale()->getLocaleCode();
427
+ $formFields['PM'] = $payment->getOpsCode($order->getPayment());
428
+ $formFields['EMAIL'] = $order->getCustomerEmail();
429
+
430
+ $formFields['ACCEPTURL'] = $this->getConfig()->getAcceptUrl();
431
+ $formFields['DECLINEURL'] = $this->getConfig()->getDeclineUrl();
432
+ $formFields['EXCEPTIONURL'] = $this->getConfig()->getExceptionUrl();
433
+ $formFields['CANCELURL'] = $this->getConfig()->getCancelUrl();
434
+ $formFields['BACKURL'] = $this->getConfig()->getCancelUrl();
435
+
436
+ return $formFields;
437
+ }
438
+
439
+ /**
440
+ * Extracts the order item parameters and puts them in a array like
441
+ *
442
+ * @param Mage_Sales_Model_Order $order
443
+ *
444
+ * @return array
445
+ */
446
+ public function extractOrderItemParameters(Mage_Sales_Model_Order $order)
447
+ {
448
+ $formFields = array();
449
+
450
+ // add order items
451
+ $count = 1;
452
+ foreach ($order->getAllItems() as $item) {
453
+ if ($item->getParentItemId()
454
+ && $item->getParentItem()->getProductType() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE
455
+ || $item->getProductType() == Mage_Catalog_Model_Product_Type::TYPE_BUNDLE
456
+ ) {
457
+ continue;
458
+ }
459
+ $formFields = array_merge($formFields, $this->getItemFormFields($count, $item));
460
+ $count++;
461
+ }
462
+
463
+ // add discount item
464
+ $discountItemFormFields = $this->getDiscountItemFormFields($order, $count);
465
+ if (is_array($discountItemFormFields)) {
466
+ $formFields = array_merge($formFields, $discountItemFormFields);
467
+ $count++;
468
+ }
469
+
470
+ // add shipping item
471
+ $shippingItemFields = $this->getShippingItemFormFields($count, $order);
472
+ if (is_array($shippingItemFields)) {
473
+ $formFields = array_merge($formFields, $shippingItemFields);
474
+ }
475
+
476
+ return $formFields;
477
+ }
478
+
479
+ /**
480
+ * @param Mage_Sales_Model_Order $order
481
+ *
482
+ * @return float
483
+ */
484
+
485
+ public function getShippingTaxRate($order)
486
+ {
487
+ $store = $order->getStore();
488
+ $taxCalculation = Mage::getModel('tax/calculation');
489
+ $request = $taxCalculation->getRateRequest(null, null, null, $store);
490
+ $taxRateId = Mage::getStoreConfig('tax/classes/shipping_tax_class', $store);
491
+ //taxRateId is the same model id as product tax classes, so you can do this:
492
+ $percent = $taxCalculation->getRate($request->setProductClassId($taxRateId));
493
+
494
+ return $percent;
495
+ }
496
+
497
+ /**
498
+ * Genereates item array for shipping, returns false if order is virtual
499
+ *
500
+ * @param Mage_Sales_Model_Order $order
501
+ * @param $count
502
+ *
503
+ * @return array | false
504
+ */
505
+ protected function getShippingItemFormFields($count, $order)
506
+ {
507
+ if ($order->getIsNotVirtual()) {
508
+ /* add shipping item */
509
+ $formFields['ITEMID' . $count] = 'SHIPPING';
510
+ $formFields['ITEMNAME' . $count] = substr($order->getShippingDescription(), 0, 30);
511
+ $formFields['ITEMPRICE' . $count] = number_format($order->getBaseShippingInclTax(), 2, '.', '');
512
+ $formFields['ITEMQUANT' . $count] = 1;
513
+ $formFields['ITEMVATCODE' . $count]
514
+ = str_replace(',', '.', (string)(float)$this->getShippingTaxRate($order)) . '%';
515
+ $formFields['TAXINCLUDED' . $count] = 1;
516
+
517
+ return $formFields;
518
+ }
519
+
520
+ return false;
521
+ }
522
+
523
+ /**
524
+ * Returns item array for Ingenico Payment Services request for the specified item
525
+ *
526
+ * @param $count
527
+ * @param $item
528
+ *
529
+ * @return array
530
+ */
531
+ protected function getItemFormFields($count, $item)
532
+ {
533
+ $formFields = array();
534
+ $formFields['ITEMID' . $count] = $item->getItemId();
535
+ $formFields['ITEMNAME' . $count] = substr($item->getName(), 0, 40);
536
+ $formFields['ITEMPRICE' . $count] = number_format($item->getBasePriceInclTax(), 2, '.', '');
537
+ $formFields['ITEMQUANT' . $count] = (int)$item->getQtyOrdered();
538
+ $formFields['ITEMVATCODE' . $count] = str_replace(',', '.', (string)(float)$item->getTaxPercent()) . '%';
539
+ $formFields['TAXINCLUDED' . $count] = 1;
540
+
541
+ return $formFields;
542
+ }
543
+
544
+ /**
545
+ * Creates array
546
+ *
547
+ * @param Mage_Sales_Model_Order $order
548
+ * @param $count
549
+ *
550
+ * @return mixed
551
+ */
552
+ protected function getDiscountItemFormFields(Mage_Sales_Model_Order $order, $count)
553
+ {
554
+ $formFields = array();
555
+ /* add coupon item */
556
+ if ($order->getBaseDiscountAmount()) {
557
+ $couponAmount = $order->getBaseDiscountAmount();
558
+ $formFields['ITEMID' . $count] = 'DISCOUNT';
559
+ $couponRuleName = 'DISCOUNT';
560
+ if ($order->getCouponRuleName() && strlen(trim($order->getCouponRuleName())) > 0) {
561
+ $couponRuleName = substr(trim($order->getCouponRuleName()), 0, 30);
562
+ }
563
+ $formFields['ITEMNAME' . $count] = $couponRuleName;
564
+ $formFields['ITEMPRICE' . $count] = number_format($couponAmount, 2, '.', '');
565
+ $formFields['ITEMQUANT' . $count] = 1;
566
+ $formFields['ITEMVATCODE' . $count]
567
+ = str_replace(',', '.', (string)(float)$this->getShippingTaxRate($order)) . '%';
568
+ $formFields['TAXINCLUDED' . $count] = 1;
569
+ return $formFields;
570
+
571
+ }
572
+ return false;
573
+ }
574
+ }
app/code/community/Netresearch/OPS/Helper/Quote.php ADDED
@@ -0,0 +1,162 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Michael Lühr <michael.luehr@netresearch.de>
4
+ * @category Netresearch
5
+ * @package Netresearch_OPS
6
+ * @copyright Copyright (c) 2013 Netresearch GmbH & Co. KG (http://www.netresearch.de)
7
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
8
+ */
9
+
10
+
11
+ class Netresearch_OPS_Helper_Quote extends Mage_Core_Helper_Abstract
12
+ {
13
+
14
+ const PAGE_SIZE = 100;
15
+
16
+ const MINUTES_IN_PAST = 15;
17
+
18
+ protected $dataHelper = null;
19
+
20
+ /**
21
+ * cleans up old payment information (deletes cvc etc. from additional data)
22
+ */
23
+ public function cleanUpOldPaymentInformation()
24
+ {
25
+ $allowedTimestamp = new Zend_Db_Expr(sprintf(
26
+ 'NOW() - INTERVAL %d MINUTE', self::MINUTES_IN_PAST
27
+ ));
28
+ /*
29
+ * fetching possible affected information from the sales_quote_payment table
30
+ * criteria are:
31
+ * - ops_cc was used
32
+ * - the last update is more than 15 minutes ago
33
+ * - and CVC is included in the additional information
34
+ */
35
+ $paymentInformation = Mage::getModel('sales/quote_payment')
36
+ ->getCollection()
37
+ ->addFieldToFilter('method', array('eq' => 'ops_cc'))
38
+ ->addFieldToFilter('updated_at', array('lt' => $allowedTimestamp))
39
+ ->addFieldToFilter(
40
+ 'additional_information', array('like' => '%"cvc"%')
41
+ )
42
+ ->setOrder('created_at', 'DESC')
43
+ ->setPageSize(self::PAGE_SIZE);
44
+ foreach ($paymentInformation as $payment) {
45
+ if (!is_null($payment->getAdditionalInformation('cvc'))) {
46
+ // quote needs to be loaded, because saving the payment information would fail otherwise
47
+ $payment->setQuote(
48
+ Mage::getModel('sales/quote')->load($payment->getQuoteId())
49
+ );
50
+ Mage::helper('ops/alias')->cleanUpAdditionalInformation(
51
+ $payment, true
52
+ );
53
+ $payment->save();
54
+ }
55
+
56
+ }
57
+
58
+
59
+ }
60
+
61
+ /**
62
+ * returns the quote currency
63
+ *
64
+ * @param $quote
65
+ *
66
+ * @return string - the quotes currency
67
+ */
68
+ public function getQuoteCurrency(Mage_Sales_Model_Quote $quote)
69
+ {
70
+ if ($quote->hasForcedCurrency()) {
71
+ return $quote->getForcedCurrency()->getCode();
72
+ } else {
73
+ return Mage::app()->getStore($quote->getStoreId())
74
+ ->getBaseCurrencyCode();
75
+ }
76
+ }
77
+
78
+ /**
79
+ * get payment operation code
80
+ *
81
+ * @param Mage_Sales_Model_Order $order
82
+ *
83
+ * @return string
84
+ */
85
+ public function getPaymentAction($order)
86
+ {
87
+ $operation
88
+ = Netresearch_OPS_Model_Payment_Abstract::OPS_AUTHORIZE_ACTION;
89
+
90
+ // different capture operation name for direct debits
91
+ if ('Direct Debits DE' == $order->getPayment()
92
+ ->getAdditionalInformation('PM')
93
+ || 'Direct Debits AT' == $order->getPayment()
94
+ ->getAdditionalInformation('PM')
95
+ ) {
96
+ if ('authorize_capture' == Mage::getModel('ops/config')
97
+ ->getPaymentAction($order->getStoreId())
98
+ ) {
99
+ return Netresearch_OPS_Model_Payment_Abstract::OPS_AUTHORIZE_CAPTURE_ACTION;
100
+ }
101
+
102
+ return Netresearch_OPS_Model_Payment_Abstract::OPS_AUTHORIZE_ACTION;
103
+ }
104
+ // no RES for Direct Debits NL, so we'll do the final sale
105
+ if ('Direct Debits NL' == $order->getPayment()
106
+ ->getAdditionalInformation('PM')
107
+ ) {
108
+ if ('authorize_capture' == Mage::getModel('ops/config')
109
+ ->getPaymentAction($order->getStoreId())
110
+ ) {
111
+ return Netresearch_OPS_Model_Payment_Abstract::OPS_CAPTURE_DIRECTDEBIT_NL;
112
+ }
113
+
114
+ return Netresearch_OPS_Model_Payment_Abstract::OPS_AUTHORIZE_ACTION;
115
+ }
116
+
117
+ if ('authorize_capture' == Mage::getModel('ops/config')
118
+ ->getPaymentAction($order->getStoreId())
119
+ ) {
120
+ $operation
121
+ = Netresearch_OPS_Model_Payment_Abstract::OPS_AUTHORIZE_CAPTURE_ACTION;
122
+ }
123
+
124
+ return $operation;
125
+ }
126
+
127
+ /**
128
+ * @return Mage_Sales_Model_Quote
129
+ */
130
+ public function getQuote()
131
+ {
132
+ if ($this->getDataHelper()->isAdminSession()) {
133
+ return Mage::getSingleton('adminhtml/session_quote')->getQuote();
134
+ }
135
+
136
+ return Mage::getSingleton('checkout/session')->getQuote();
137
+ }
138
+
139
+ /**
140
+ * gets the data helper
141
+ *
142
+ * @return Netresearch_OPS_Helper_Data
143
+ */
144
+ public function getDataHelper()
145
+ {
146
+ if (null === $this->dataHelper) {
147
+ $this->dataHelper = Mage::helper('ops/data');
148
+ }
149
+
150
+ return $this->dataHelper;
151
+ }
152
+
153
+ /**
154
+ * sets the data helper
155
+ *
156
+ * @param Netresearch_OPS_Helper_Data $dataHelper
157
+ */
158
+ public function setDataHelper(Netresearch_OPS_Helper_Data $dataHelper)
159
+ {
160
+ $this->dataHelper = $dataHelper;
161
+ }
162
+ }
app/code/community/Netresearch/OPS/Helper/Validation/Checkout/Step.php ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @author Michael Lühr <michael.luehr@netresearch.de>
5
+ * @category Netresearch
6
+ * @copyright Copyright (c) 2014 Netresearch GmbH & Co. KG (http://www.netresearch.de)
7
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
8
+ */
9
+ class Netresearch_OPS_Helper_Validation_Checkout_Step
10
+ {
11
+
12
+ const BILLING_STEP = 'billing';
13
+
14
+ const SHIPPING_STEP = 'shipping';
15
+
16
+ /**
17
+ * retrieves the params for pushing back to the billing step
18
+ *
19
+ * @return array
20
+ */
21
+ protected function getBillingParams()
22
+ {
23
+ return array(
24
+ 'CN',
25
+ 'OWNERZIP',
26
+ 'OWNERTOWN',
27
+ 'OWNERTELNO',
28
+ 'OWNERADDRESS',
29
+ 'ECOM_BILLTO_POSTAL_POSTALCODE'
30
+ );
31
+ }
32
+
33
+ /**
34
+ * retrieves the params for pushing back to the billing step
35
+ *
36
+ * @return array
37
+ */
38
+ protected function getShippingParams()
39
+ {
40
+ return array(
41
+ 'ECOM_SHIPTO_POSTAL_NAME_FIRST',
42
+ 'ECOM_SHIPTO_POSTAL_NAME_LAST',
43
+ 'ECOM_SHIPTO_POSTAL_STREET1',
44
+ 'ECOM_SHIPTO_POSTAL_STREET2',
45
+ 'ECOM_SHIPTO_POSTAL_STREET3',
46
+ 'ECOM_SHIPTO_POSTAL_COUNTRYCODE',
47
+ 'ECOM_SHIPTO_POSTAL_COUNTY',
48
+ 'ECOM_SHIPTO_POSTAL_POSTALCODE',
49
+ 'ECOM_SHIPTO_POSTAL_CITY',
50
+ 'ECOM_SHIPTO_POSTAL_STREET_NUMBER',
51
+ 'ECOM_SHIPTO_POSTAL_STATE'
52
+ );
53
+ }
54
+
55
+ /**
56
+ * gets the corresponding checkout step for the erroneous fields
57
+ *
58
+ * @param array $erroneousFields
59
+ *
60
+ * @return string - the checkout step
61
+ */
62
+ public function getStep(array $erroneousFields)
63
+ {
64
+ $checkoutStep = '';
65
+ foreach ($erroneousFields as $erroneousField) {
66
+ if (in_array($erroneousField, $this->getBillingParams())) {
67
+ $checkoutStep = self::BILLING_STEP;
68
+ break;
69
+ }
70
+ if (in_array($erroneousField, $this->getShippingParams())) {
71
+ $checkoutStep = self::SHIPPING_STEP;
72
+ }
73
+ }
74
+
75
+ return $checkoutStep;
76
+ }
77
+ }
app/code/community/Netresearch/OPS/Helper/Validation/Result.php ADDED
@@ -0,0 +1,210 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Michael Lühr <michael.luehr@netresearch.de>
4
+ * @category Netresearch
5
+ * @copyright Copyright (c) 2014 Netresearch GmbH & Co. KG (http://www.netresearch.de)
6
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
7
+ */
8
+
9
+
10
+
11
+
12
+ class Netresearch_OPS_Helper_Validation_Result
13
+ {
14
+
15
+ protected $checkoutStepHelper = null;
16
+
17
+ protected $config = null;
18
+
19
+ protected $formBlock = null;
20
+
21
+ protected $dataHelper = null;
22
+
23
+ protected $result = array();
24
+
25
+ /**
26
+ * @param array $result
27
+ */
28
+ public function setResult(array $result)
29
+ {
30
+ $this->result = $result;
31
+ }
32
+
33
+ /**
34
+ * @return array
35
+ */
36
+ public function getResult()
37
+ {
38
+ return $this->result;
39
+ }
40
+
41
+ /**
42
+ * @param null $checkOutStepHelper
43
+ */
44
+ public function setCheckoutStepHelper($checkOutStepHelper)
45
+ {
46
+ $this->checkoutStepHelper = $checkOutStepHelper;
47
+ }
48
+
49
+ /**
50
+ * @return null
51
+ */
52
+ public function getCheckoutStepHelper()
53
+ {
54
+ if (null === $this->checkoutStepHelper) {
55
+ $this->checkoutStepHelper = Mage::helper('ops/validation_checkout_step');
56
+ }
57
+
58
+ return $this->checkoutStepHelper;
59
+ }
60
+
61
+ /**
62
+ * @param null $config
63
+ */
64
+ public function setConfig($config)
65
+ {
66
+ $this->config = $config;
67
+ }
68
+
69
+ /**
70
+ * @return null
71
+ */
72
+ public function getConfig()
73
+ {
74
+ if (null === $this->config) {
75
+ $this->config = Mage::getModel('ops/config');
76
+ }
77
+
78
+ return $this->config;
79
+ }
80
+
81
+ /**
82
+ * @param null $dataHelper
83
+ */
84
+ public function setDataHelper($dataHelper)
85
+ {
86
+ $this->dataHelper = $dataHelper;
87
+ }
88
+
89
+ /**
90
+ * @return null
91
+ */
92
+ public function getDataHelper()
93
+ {
94
+ if (null === $this->dataHelper) {
95
+ $this->dataHelper = Mage::helper('ops/data');
96
+ }
97
+
98
+ return $this->dataHelper;
99
+ }
100
+
101
+ /**
102
+ * @param null $formBlock
103
+ */
104
+ public function setFormBlock($formBlock)
105
+ {
106
+ $this->formBlock = $formBlock;
107
+ }
108
+
109
+ /**
110
+ * @return null
111
+ */
112
+ public function getFormBlock()
113
+ {
114
+ if (null === $this->formBlock) {
115
+ $this->formBlock = Mage::getBlockSingleton('ops/form');
116
+ }
117
+
118
+ return $this->formBlock;
119
+ }
120
+
121
+
122
+
123
+ /**
124
+ * @param array $messages
125
+ * @param Mage_Sales_Model_Quote $quote
126
+ *
127
+ * @return array
128
+ */
129
+ public function getValidationFailedResult($messages, $quote)
130
+ {
131
+ $gotoSection = $this->getCheckoutStepHelper()->getStep(array_keys($messages));
132
+ $this->setBaseErroneousFields($messages, $gotoSection);
133
+ $this->getFields($messages);
134
+ $this->addErrorToExistingAddress($quote, $gotoSection);
135
+ $this->cleanResult();
136
+
137
+ return $this->getResult();
138
+ }
139
+
140
+ /**
141
+ * @param $messages
142
+ * @param $result
143
+ *
144
+ * @return mixed
145
+ */
146
+ protected function getFields($messages)
147
+ {
148
+ $mappedFields = $this->getConfig()->getFrontendFieldMapping();
149
+ $frontendFields = array();
150
+ foreach ($messages as $key => $value) {
151
+ if (array_key_exists($key, $mappedFields)) {
152
+ $frontendFields = $this->getFormBlock()->getFrontendValidationFields(
153
+ $mappedFields,
154
+ $key,
155
+ $value,
156
+ $frontendFields
157
+ );
158
+ }
159
+ }
160
+ $this->result['fields'] = $frontendFields;
161
+
162
+ return $this;
163
+ }
164
+
165
+ /**
166
+ * @param $quote
167
+ * @param $gotoSection
168
+ */
169
+ protected function addErrorToExistingAddress($quote, $gotoSection)
170
+ {
171
+ if ($gotoSection == 'billing' && 0 < $quote->getBillingAddress()->getId()) {
172
+ $this->result['fields']['billing-address-select'] = $this->getDataHelper()->__(
173
+ 'Billing address contains invalid data'
174
+ );
175
+ }
176
+ if ($gotoSection == 'shipping' && 0 < $quote->getShippingAddress()->getId()) {
177
+ $this->result['fields']['shipping-address-select'] = $this->getDataHelper()->__(
178
+ 'Shipping address contains invalid data'
179
+ );
180
+ }
181
+
182
+ return $this;
183
+ }
184
+
185
+ /**
186
+ * @param $messages
187
+ * @param $result
188
+ * @param $gotoSection
189
+ *
190
+ * @return mixed
191
+ */
192
+ protected function setBaseErroneousFields($messages, $gotoSection)
193
+ {
194
+ $this->result['error'] = implode(',', array_values($messages));
195
+ $this->result['goto_section'] = $gotoSection;
196
+ $this->result['opsError'] = true;
197
+
198
+ return $this;
199
+ }
200
+
201
+ protected function cleanResult()
202
+ {
203
+ if (array_key_exists('update_section', $this->result)) {
204
+ unset($this->result['update_section']);
205
+ }
206
+
207
+ return $this;
208
+ }
209
+
210
+ }
app/code/community/Netresearch/OPS/Helper/Version.php ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Netresearch_OPS_Helper_Data
5
+ *
6
+ * @package
7
+ * @copyright 2014 Netresearch
8
+ * @author Sebastian Ertner <sebastian.ertner@netresearch.de>
9
+ * @license OSL 3.0
10
+ */
11
+ class Netresearch_OPS_Helper_Version extends Mage_Core_Helper_Abstract
12
+ {
13
+ const CAN_USE_APPLICABLE_FOR_QUOTE_EE_MINOR = 14;
14
+
15
+ const CAN_USE_APPLICABLE_FOR_QUOTE_CE_MINOR = 8;
16
+
17
+
18
+ /**
19
+ * checks if Version is above EE 1.13 or CE 1.7.0.2
20
+ * useApplicableForQuote was implemented in CE 1.8 / EE 1.14
21
+ *
22
+ * @param $edition
23
+ *
24
+ * @return bool
25
+ */
26
+ public function canUseApplicableForQuote($edition)
27
+ {
28
+ $result = false;
29
+ $versionInfo = $this->getVersionInfo();
30
+ if (array_key_exists('minor', $versionInfo)
31
+ && $versionInfo['minor'] >= $this->getVersionForEdition($edition)
32
+ ) {
33
+ $result = true;
34
+ }
35
+
36
+ return $result;
37
+ }
38
+
39
+ /**
40
+ * return allowed version
41
+ *
42
+ * @param $edition
43
+ *
44
+ * @return int
45
+ */
46
+ protected function getVersionForEdition($edition)
47
+ {
48
+ if (Mage::EDITION_ENTERPRISE == $edition) {
49
+ return self::CAN_USE_APPLICABLE_FOR_QUOTE_EE_MINOR;
50
+ }
51
+
52
+ return self::CAN_USE_APPLICABLE_FOR_QUOTE_CE_MINOR;
53
+ }
54
+
55
+ /**
56
+ * wraps Mage::getVersionInfo since Mage class is final and not testable
57
+ *
58
+ * @return array
59
+ */
60
+ protected function getVersionInfo()
61
+ {
62
+ return Mage::getVersionInfo();
63
+ }
64
+
65
+
66
+ }
app/code/community/Netresearch/OPS/Model/Alias.php ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category OPS
22
+ * @package Netresearch_OPS
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Alias model
29
+ */
30
+ class Netresearch_OPS_Model_Alias extends Mage_Core_Model_Abstract
31
+ {
32
+ /**
33
+ * Constructor
34
+ *
35
+ * @see lib/Varien/Varien_Object#_construct()
36
+ * @return Netresearch_OPS_Model_Alias
37
+ */
38
+ public function _construct()
39
+ {
40
+ $this->_init('ops/alias');
41
+ parent::_construct();
42
+ }
43
+
44
+ /**
45
+ * @param $customerId - the id of the customer
46
+ * @param $billingAddressHash - optional billing address hash
47
+ * @param $shippingAdressHash - optional shipping address hash
48
+ * @return Netresearch_OPS_Model_Mysql4_Alias_Collection - collection of aliases for given customer
49
+ */
50
+ public function getAliasesForCustomer($customerId, $billingAddressHash = null, $shippingAddressHash = null, $storeId = null)
51
+ {
52
+ $collection = $this->getCollection()
53
+ ->addFieldToFilter('customer_id', $customerId);
54
+ if (!is_null($billingAddressHash) && !is_null($shippingAddressHash)) {
55
+ $collection
56
+ ->addFieldToFilter('billing_address_hash', $billingAddressHash)
57
+ ->addFieldToFilter('shipping_address_hash', $shippingAddressHash)
58
+ ->addFieldToFilter('store_id', array('eq' => $storeId, 'null' => 'null'))
59
+ ;
60
+ }
61
+ return $collection->load();
62
+ }
63
+ }
64
+
app/code/community/Netresearch/OPS/Model/Alias/State.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category OPS
22
+ * @package Netresearch_OPS
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Alias state model
29
+ */
30
+ class Netresearch_OPS_Model_Alias_State
31
+ {
32
+ const ACTIVE = "active";
33
+ const PENDING = "pending";
34
+ }
app/code/community/Netresearch/OPS/Model/Api/Directlink.php ADDED
@@ -0,0 +1,197 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Netresearch_OPS
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * OPS payment DirectLink Model
29
+ */
30
+ class Netresearch_OPS_Model_Api_DirectLink extends Mage_Core_Model_Abstract
31
+ {
32
+
33
+ const MAX_RETRY_COUNT = 3;
34
+
35
+ /**
36
+ * Perform a CURL call and log request end response to logfile
37
+ *
38
+ * @param array $params
39
+ * @return mixed
40
+ */
41
+ public function call($params, $url)
42
+ {
43
+ try {
44
+ $http = new Varien_Http_Adapter_Curl();
45
+ $config = array('timeout' => 30);
46
+ $http->setConfig($config);
47
+ $http->write(Zend_Http_Client::POST, $url, '1.1', array(), http_build_query($params));
48
+ $response = $http->read();
49
+ $response = substr($response, strpos($response, "<?xml"), strlen($response));
50
+
51
+ return $response;
52
+ } catch (Exception $e) {
53
+ Mage::logException($e);
54
+ Mage::throwException(
55
+ Mage::helper('ops')->__('Ingenico Payment Services server is temporarily not available, please try again later.')
56
+ );
57
+ }
58
+ }
59
+
60
+ /**
61
+ * Performs a POST request to the Direct Link Gateway with the given
62
+ * parameters and returns the result parameters as array
63
+ *
64
+ * @param array $params
65
+ * @return array
66
+ */
67
+ public function performRequest($requestParams, $url, $storeId = 0)
68
+ {
69
+ $helper = Mage::helper('ops');
70
+ $params = $this->getEncodedParametersWithHash(
71
+ array_merge($requestParams,$this->buildAuthenticationParams($storeId)) //Merge Logic Operation Data with Authentication Data
72
+ , null, $storeId);
73
+ $responseParams = $this->getResponseParams($params, $url);
74
+ $helper->log($helper->__("Direct Link Request/Response in Ingenico Payment Services \n\nRequest: %s\nResponse: %s\nMagento-URL: %s\nAPI-URL: %s",
75
+ serialize($params),
76
+ serialize($responseParams),
77
+ Mage::helper('core/url')->getCurrentUrl(),
78
+ $url
79
+ ));
80
+
81
+ $this->checkResponse($responseParams);
82
+
83
+ return $responseParams;
84
+
85
+ }
86
+
87
+ public function getEncodedParametersWithHash($params, $shaCode=null, $storeId)
88
+ {
89
+ $params['SHASIGN'] = Mage::helper('ops/payment')->shaCrypt(iconv('iso-8859-1', 'utf-8', Mage::helper('ops/payment')->getSHASign($params, $shaCode, $storeId)));
90
+
91
+ return $params;
92
+ }
93
+
94
+
95
+ /**
96
+ *
97
+ * wraps the request and response handling and repeats request/response
98
+ * if there are errors
99
+ *
100
+ * @param array $params - request params
101
+ * @param string $url - the url for the request
102
+ * @param int $retryCount - current request count
103
+ * @return array | null - null if requests were not successful, array containing Ingenico Payment Services payment data otherwise
104
+ *
105
+ */
106
+ protected function getResponseParams($params, $url, $retryCount = 0)
107
+ {
108
+ $responseParams = null;
109
+ $responseXml = null;
110
+ if ($retryCount < self::MAX_RETRY_COUNT) {
111
+ try {
112
+ $responseXml = $this->call($params, $url);
113
+ $responseParams = $this->getParamArrFromXmlString($responseXml);
114
+ } catch (Exception $e) {
115
+ try {
116
+ $responseParams = $this->getParamArrFromXmlString(utf8_encode($responseXml));
117
+ } catch (Exception $e) {
118
+ $ref = '';
119
+ if (array_key_exists('ORDERID', $params)) {
120
+ $ref = $params['ORDERID'];
121
+ } elseif (array_key_exists('PAYID', $params)) {
122
+ $ref = $params['PAYID'];
123
+ }
124
+ Mage::helper('ops')->log('DirectLink::getResponseParams failed: ' .
125
+ $e->getMessage() . ' current retry count: ' . $retryCount . ' for quote ' . $ref
126
+ );
127
+ $responseParams = $this->getResponseParams($params, $url, ++$retryCount);
128
+ }
129
+ }
130
+ } else {
131
+ Mage::throwException(Mage::helper('ops')->__('An error occured during the Ingenico Payment Services request. Your action could not be executed.'));
132
+ }
133
+ return $responseParams;
134
+ }
135
+
136
+ /**
137
+ * Return Authentication Params for OPS Call
138
+ *
139
+ * @return array
140
+ */
141
+ protected function buildAuthenticationParams($storeId = 0)
142
+ {
143
+ return array(
144
+ 'PSPID' => Mage::getModel('ops/config')->getPSPID($storeId),
145
+ 'USERID' => Mage::getModel('ops/config')->getApiUserId($storeId),
146
+ 'PSWD' => Mage::getModel('ops/config')->getApiPswd($storeId),
147
+ );
148
+ }
149
+
150
+ /**
151
+ * Parses the XML-String to an array with the result data
152
+ *
153
+ * @param string xmlString
154
+ * @return array
155
+ */
156
+ public function getParamArrFromXmlString($xmlString)
157
+ {
158
+ try {
159
+ $xml = new SimpleXMLElement($xmlString);
160
+ foreach ($xml->attributes() as $key => $value) {
161
+ $arrAttr[$key] = (string)$value;
162
+ }
163
+ foreach ($xml->children() as $child) {
164
+ $arrAttr[$child->getName()] = (string) $child;
165
+ }
166
+ return $arrAttr;
167
+ } catch (Exception $e) {
168
+ Mage::log('Could not convert string to xml in ' . __FILE__ . '::' . __METHOD__ . ': ' . $xmlString);
169
+ Mage::logException($e);
170
+ throw $e;
171
+ }
172
+ }
173
+
174
+ /**
175
+ * Check if the Response from OPS reports Errors
176
+ *
177
+ * @param array $responseParams
178
+ * @return mixed
179
+ */
180
+ public function checkResponse($responseParams)
181
+ {
182
+ if (false === is_array($responseParams) || false === array_key_exists('NCERROR', $responseParams) || $responseParams['NCERROR'] > 0) {
183
+ if (empty($responseParams['NCERRORPLUS'])) {
184
+ $responseParams['NCERRORPLUS'] = Mage::helper('ops')->__('Invalid payment information')." Errorcode:".$responseParams['NCERROR'];
185
+ }
186
+
187
+ //avoid exception if STATUS is set with special values
188
+ if (isset($responseParams['STATUS']) && is_numeric($responseParams['STATUS'])) {
189
+ return;
190
+ }
191
+
192
+ Mage::throwException(
193
+ Mage::helper('ops')->__('An error occured during the Ingenico Payment Services request. Your action could not be executed. Message: "%s".',$responseParams['NCERRORPLUS'])
194
+ );
195
+ }
196
+ }
197
+ }
app/code/community/Netresearch/OPS/Model/Backend/Operation/Capture/Additional/OpenInvoiceNl.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @author Michael Lühr <michael.luehr@netresearch.de>
5
+ * @category Netresearch
6
+ * @copyright Copyright (c) 2013 Netresearch GmbH & Co. KG (http://www.netresearch.de)
7
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
8
+ */
9
+ class Netresearch_OPS_Model_Backend_Operation_Capture_Additional_OpenInvoiceNl
10
+ extends Netresearch_OPS_Model_Backend_Operation_Parameter_Additional_OpenInvoiceNlAbstract
11
+ {
12
+ /**
13
+ * @see Netresearch_OPS_Model_Backend_Operation_Parameter_Additional_OpenInvoiceNlAbstract
14
+ */
15
+ }
app/code/community/Netresearch/OPS/Model/Backend/Operation/Capture/Parameter.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @author Michael Lühr <michael.luehr@netresearch.de>
5
+ * @category Netresearch
6
+ * @copyright Copyright (c) 2014 Netresearch GmbH & Co. KG (http://www.netresearch.de)
7
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
8
+ */
9
+ class Netresearch_OPS_Model_Backend_Operation_Capture_Parameter
10
+ extends Netresearch_OPS_Model_Backend_Operation_Parameter_Abstract
11
+ {
12
+ /**
13
+ * checks whether we need to retrieve additional parameter for the capture request or not
14
+ *
15
+ * @param Netresearch_OPS_Model_Payment_Abstract $opsPaymentMethod
16
+ *
17
+ * @return bool - true if we need to retrieve any additional parameters, false otherwise
18
+ */
19
+ protected function isPmRequiringAdditionalParams(Netresearch_OPS_Model_Payment_Abstract $opsPaymentMethod)
20
+ {
21
+ $opsPaymentMethodClass = get_class($opsPaymentMethod);
22
+ $opsPmsRequiringSpecialParams = $this->getOpsConfig()
23
+ ->getMethodsRequiringAdditionalParametersFor(Netresearch_OPS_Model_Payment_Abstract::OPS_CAPTURE_TRANSACTION_TYPE);
24
+
25
+ return (in_array($opsPaymentMethodClass, array_values($opsPmsRequiringSpecialParams)));
26
+ }
27
+
28
+ /**
29
+ * sets the model which retrieves the additional params
30
+ *
31
+ * @param Netresearch_OPS_Model_Payment_Abstract $opsPaymentMethod
32
+ */
33
+ protected function setAdditionalParamsModelFor(Netresearch_OPS_Model_Payment_Abstract $opsPaymentMethod)
34
+ {
35
+ if ($opsPaymentMethod instanceof Netresearch_OPS_Model_Payment_OpenInvoiceNl) {
36
+ $this->additionalParamsModel = Mage::getModel('ops/backend_operation_capture_additional_openInvoiceNl');
37
+ }
38
+ }
39
+ }
app/code/community/Netresearch/OPS/Model/Backend/Operation/Parameter.php ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @author Michael Lühr <michael.luehr@netresearch.de>
5
+ * @category Netresearch
6
+ * @copyright Copyright (c) 2013 Netresearch GmbH & Co. KG (http://www.netresearch.de)
7
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
8
+ */
9
+ class Netresearch_OPS_Model_Backend_Operation_Parameter
10
+ {
11
+ protected $parameterModel = null;
12
+
13
+ protected $dataHelper = null;
14
+
15
+ /**
16
+ * retrieves the neccessary parameter for the given operation
17
+ *
18
+ * @param $operation
19
+ * @param Netresearch_OPS_Model_Payment_Abstract $opsPaymentMethod
20
+ * @param Varien_Object $payment
21
+ * @param $amount
22
+ * @param $arrInfo
23
+ *
24
+ * @return array
25
+ */
26
+ public function getParameterFor(
27
+ $operation,
28
+ Netresearch_OPS_Model_Payment_Abstract $opsPaymentMethod,
29
+ Varien_Object $payment,
30
+ $amount,
31
+ $arrInfo
32
+ ) {
33
+ return $this->getParameterModel($operation)->getRequestParams($opsPaymentMethod, $payment, $amount, $arrInfo);
34
+ }
35
+
36
+ /**
37
+ * retrieves the parameter model for the given operation
38
+ *
39
+ * @param $operation - the operation we need the parameters for
40
+ *
41
+ * @throws Mage_Core_Exception - in case the operation is not supported
42
+ * @return Netresearch_OPS_Model_Backend_Operation_Parameter_Interface - the model for the parameters of the
43
+ * operation
44
+ */
45
+ protected function getParameterModel($operation)
46
+ {
47
+ if ($operation === Netresearch_OPS_Model_Payment_Abstract::OPS_CAPTURE_TRANSACTION_TYPE) {
48
+ return Mage::getModel('ops/backend_operation_capture_parameter');
49
+ }
50
+ if ($operation === Netresearch_OPS_Model_Payment_Abstract::OPS_REFUND_TRANSACTION_TYPE){
51
+ return Mage::getModel('ops/backend_operation_refund_parameter');
52
+ }
53
+
54
+ Mage::throwException($this->getDataHelper()->__('operation %s not supported', $operation));
55
+ }
56
+
57
+ /**
58
+ * retrieves the data helper
59
+ *
60
+ * @return Netresearch_OPS_Helper_Data|null
61
+ */
62
+ protected function getDataHelper()
63
+ {
64
+ if (null == $this->dataHelper) {
65
+ $this->dataHelper = Mage::helper('ops/data');
66
+ }
67
+
68
+ return $this->dataHelper;
69
+ }
70
+ }
app/code/community/Netresearch/OPS/Model/Backend/Operation/Parameter/Abstract.php ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @author Paul Siedler <paul.siedler@netresearch.de>
5
+ * @category Netresearch
6
+ * @copyright Copyright (c) 2014 Netresearch GmbH & Co. KG (http://www.netresearch.de)
7
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
8
+ */
9
+
10
+ abstract class Netresearch_OPS_Model_Backend_Operation_Parameter_Abstract implements Netresearch_OPS_Model_Backend_Operation_Parameter_Interface
11
+ {
12
+ protected $requestParams = array();
13
+
14
+ protected $opsConfig = null;
15
+ protected $dataHelper = null;
16
+
17
+ protected $additionalParamsModel = null;
18
+
19
+ /**
20
+ * @param Netresearch_OPS_Model_Payment_Abstract $opsPaymentMethod
21
+ * @param $payment
22
+ * @param $amount
23
+ *
24
+ * @return array
25
+ */
26
+ public function getRequestParams(
27
+ Netresearch_OPS_Model_Payment_Abstract $opsPaymentMethod,
28
+ Varien_Object $payment,
29
+ $amount,
30
+ $arrInfo
31
+ )
32
+ {
33
+ $this->getBaseParams($opsPaymentMethod, $payment, $amount, $arrInfo);
34
+ $this->addPmSpecificParams($opsPaymentMethod, $payment, $amount);
35
+
36
+ return $this->requestParams;
37
+ }
38
+
39
+ /**
40
+ * retrieves the basic parameters for a capture call
41
+ *
42
+ * @param Netresearch_OPS_Model_Payment_Abstract $opsPaymentMethod
43
+ * @param Varien_Object $payment
44
+ * @param $amount
45
+ * @param $arrInfo
46
+ *
47
+ * @return $this
48
+ */
49
+ protected function getBaseParams(
50
+ Netresearch_OPS_Model_Payment_Abstract $opsPaymentMethod,
51
+ Varien_Object $payment,
52
+ $amount,
53
+ $arrInfo
54
+ )
55
+ {
56
+ $this->requestParams['AMOUNT'] = $this->getDataHelper()->getAmount($amount);
57
+ $this->requestParams['PAYID'] = $payment->getAdditionalInformation('paymentId');
58
+ $this->requestParams['OPERATION'] = $arrInfo['operation'];
59
+ $this->requestParams['CURRENCY'] = Mage::app()->getStore($payment->getOrder()->getStoreId())
60
+ ->getBaseCurrencyCode();
61
+
62
+ return $this;
63
+ }
64
+
65
+ /**
66
+ * retrieves ops config model
67
+ *
68
+ * @return Netresearch_OPS_Model_Config
69
+ */
70
+ protected function getOpsConfig()
71
+ {
72
+ if (null === $this->opsConfig) {
73
+ $this->opsConfig = Mage::getModel('ops/config');
74
+ }
75
+
76
+ return $this->opsConfig;
77
+ }
78
+
79
+ /**
80
+ * if we have to add payment specific paramters to our request, we'll set them here
81
+ *
82
+ * @param $opsPaymentMethod
83
+ * @param $payment
84
+ * @param $amount
85
+ *
86
+ * @return $this
87
+ */
88
+ protected function addPmSpecificParams(Netresearch_OPS_Model_Payment_Abstract $opsPaymentMethod, Varien_Object $payment, $amount)
89
+ {
90
+ if ($this->isPmRequiringAdditionalParams($opsPaymentMethod)) {
91
+ $this->setAdditionalParamsModelFor($opsPaymentMethod);
92
+ if ($this->additionalParamsModel instanceof Netresearch_OPS_Model_Backend_Operation_Parameter_Additional_Interface) {
93
+ $params = $this->additionalParamsModel->extractAdditionalParams($payment->getInvoice());
94
+ $this->requestParams = array_merge($this->requestParams, $params);
95
+ }
96
+ }
97
+
98
+ return $this;
99
+ }
100
+
101
+ protected function isPmRequiringAdditionalParams(Netresearch_OPS_Model_Payment_Abstract $opsPaymentMethod)
102
+ {
103
+ return false;
104
+ }
105
+
106
+ protected function setAdditionalParamsModelFor(Netresearch_OPS_Model_Payment_Abstract $opsPaymentMethod)
107
+ {
108
+ $this->additionalParamsModel = null;
109
+ }
110
+
111
+ /**
112
+ * retrieves the data helper
113
+ *
114
+ * @return Netresearch_OPS_Helper_Data|null
115
+ */
116
+ protected function getDataHelper()
117
+ {
118
+ if (null == $this->dataHelper) {
119
+ $this->dataHelper = Mage::helper('ops/data');
120
+ }
121
+
122
+ return $this->dataHelper;
123
+ }
124
+
125
+ }
app/code/community/Netresearch/OPS/Model/Backend/Operation/Parameter/Additional/Interface.php ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Michael Lühr <michael.luehr@netresearch.de>
4
+ * @category Netresearch
5
+ * @copyright Copyright (c) 2014 Netresearch GmbH & Co. KG (http://www.netresearch.de)
6
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
7
+ */
8
+ interface Netresearch_OPS_Model_Backend_Operation_Parameter_Additional_Interface
9
+ {
10
+ public function extractAdditionalParams(Mage_Sales_Model_Abstract $itemContainer);
11
+ }
app/code/community/Netresearch/OPS/Model/Backend/Operation/Parameter/Additional/OpenInvoiceNlAbstract.php ADDED
@@ -0,0 +1,144 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @author Paul Siedler <paul.siedler@netresearch.de>
5
+ * @category Netresearch
6
+ * @copyright Copyright (c) 2014 Netresearch GmbH & Co. KG (http://www.netresearch.de)
7
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
8
+ */
9
+
10
+ abstract class Netresearch_OPS_Model_Backend_Operation_Parameter_Additional_OpenInvoiceNlAbstract
11
+ implements Netresearch_OPS_Model_Backend_Operation_Parameter_Additional_Interface
12
+ {
13
+ protected $additionalParams = array();
14
+ protected $opsDataHelper = null;
15
+ protected $itemIdx = 1;
16
+
17
+
18
+ /**
19
+ * @param Mage_Sales_Model_Abstract $itemContainer
20
+ *
21
+ * @return array
22
+ */
23
+ public function extractAdditionalParams(Mage_Sales_Model_Abstract $itemContainer)
24
+ {
25
+ if ($itemContainer instanceof Mage_Sales_Model_Order_Invoice) {
26
+ $this->extractFromInvoiceItems($itemContainer);
27
+ $this->extractFromDiscountData($itemContainer);
28
+ $this->extractFromInvoicedShippingMethod($itemContainer);
29
+ }
30
+
31
+ return $this->additionalParams;
32
+ }
33
+
34
+ /**
35
+ * extracts all necessary data from the invoice items
36
+ *
37
+ * @param Mage_Sales_Model_Order_Invoice $invoice
38
+ */
39
+ protected function extractFromInvoiceItems(Mage_Sales_Model_Order_Invoice $invoice)
40
+ {
41
+ foreach ($invoice->getItemsCollection() as $item) {
42
+ /** @var $item Mage_Sales_Model_Order_Invoice_Item */
43
+ // filter out configurable products
44
+ if ($item->getParentItemId()
45
+ && $item->getParentItem()->getProductType() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE
46
+ || $item->getProductType() == Mage_Catalog_Model_Product_Type::TYPE_BUNDLE) {
47
+ continue;
48
+ }
49
+ $this->additionalParams['ITEMID' . $this->itemIdx] = substr($item->getOrderItemId(), 0, 15);
50
+ $this->additionalParams['ITEMNAME' . $this->itemIdx] = substr($item->getName(), 0, 30);
51
+ $this->additionalParams['ITEMPRICE' . $this->itemIdx] = $this->getOpsDataHelper()->getAmount(
52
+ $item->getBasePriceInclTax()
53
+ );
54
+ $this->additionalParams['ITEMQUANT' . $this->itemIdx] = $item->getQty();
55
+ $this->additionalParams['ITEMVATCODE' . $this->itemIdx]
56
+ =
57
+ str_replace(',', '.', (string)(float)$item->getTaxPercent()) . '%';
58
+ $this->additionalParams['TAXINCLUDED' . $this->itemIdx] = 1;
59
+ ++$this->itemIdx;
60
+ }
61
+
62
+ return $this;
63
+ }
64
+
65
+ /**
66
+ * extract the necessary data from the shipping data of the invoice
67
+ *
68
+ * @param Mage_Sales_Model_Order_Invoice $invoice
69
+ *
70
+ * @return $this
71
+ */
72
+ protected function extractFromInvoicedShippingMethod(Mage_Sales_Model_Order_Invoice $invoice)
73
+ {
74
+ $amount = $invoice->getBaseShippingInclTax();
75
+ if (0 < $amount) {
76
+ $this->additionalParams['ITEMID' . $this->itemIdx] = 'SHIPPING';
77
+ $this->additionalParams['ITEMNAME' . $this->itemIdx] =
78
+ substr($invoice->getOrder()->getShippingDescription(), 0, 30);
79
+ $this->additionalParams['ITEMPRICE' . $this->itemIdx] = $this->getOpsDataHelper()->getAmount($amount);
80
+ $this->additionalParams['ITEMQUANT' . $this->itemIdx] = 1;
81
+ $this->additionalParams['ITEMVATCODE' . $this->itemIdx] = $this->getShippingTaxRate($invoice) . '%';
82
+ $this->additionalParams['TAXINCLUDED' . $this->itemIdx] = 1;
83
+ ++$this->itemIdx;
84
+ }
85
+
86
+
87
+ return $this;
88
+ }
89
+
90
+ /**
91
+ * retrieves used shipping tax rate
92
+ *
93
+ * @param Mage_Sales_Model_Order_Invoice $invoice
94
+ *
95
+ * @return float
96
+ */
97
+ protected function getShippingTaxRate(Mage_Sales_Model_Order_Invoice $invoice)
98
+ {
99
+ $taxRate = 0.0;
100
+ $order = $invoice->getOrder();
101
+
102
+ $taxRate = (floatval(Mage::helper('ops/payment_request')->getShippingTaxRate($order)));
103
+
104
+ return $taxRate;
105
+ }
106
+
107
+
108
+ /**
109
+ * gets the ops data helper
110
+ *
111
+ * @return Netresearch_OPS_Helper_Data
112
+ */
113
+ protected function getOpsDataHelper()
114
+ {
115
+ if (null === $this->opsDataHelper) {
116
+ $this->opsDataHelper = Mage::helper('ops/data');
117
+ }
118
+
119
+ return $this->opsDataHelper;
120
+ }
121
+
122
+
123
+ /**
124
+ * @param $itemContainer
125
+ */
126
+ protected function extractFromDiscountData($invoice)
127
+ {
128
+ $amount = $invoice->getBaseDiscountAmount();
129
+ if (0 > $amount) {
130
+ $couponRuleName = 'DISCOUNT';
131
+ $order = $invoice->getOrder();
132
+ if ($order->getCouponRuleName() && strlen(trim($order->getCouponRuleName())) > 0) {
133
+ $couponRuleName = substr(trim($order->getCouponRuleName()), 0, 30);
134
+ }
135
+ $this->additionalParams['ITEMID' . $this->itemIdx] = 'DISCOUNT';
136
+ $this->additionalParams['ITEMNAME' . $this->itemIdx] = $couponRuleName;
137
+ $this->additionalParams['ITEMPRICE' . $this->itemIdx] = $this->getOpsDataHelper()->getAmount($amount);
138
+ $this->additionalParams['ITEMQUANT' . $this->itemIdx] = 1;
139
+ $this->additionalParams['ITEMVATCODE' . $this->itemIdx] = $this->getShippingTaxRate($invoice) . '%';
140
+ $this->additionalParams['TAXINCLUDED' . $this->itemIdx] = 1;
141
+ ++$this->itemIdx;
142
+ }
143
+ }
144
+ }
app/code/community/Netresearch/OPS/Model/Backend/Operation/Parameter/Interface.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @author Michael Lühr <michael.luehr@netresearch.de>
5
+ * @category Netresearch
6
+ * @copyright Copyright (c) 2014 Netresearch GmbH & Co. KG (http://www.netresearch.de)
7
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
8
+ */
9
+ interface Netresearch_OPS_Model_Backend_Operation_Parameter_Interface
10
+ {
11
+ public function getRequestParams(
12
+ Netresearch_OPS_Model_Payment_Abstract $opsPaymentMethod,
13
+ Varien_Object $payment,
14
+ $amount,
15
+ $arrInfo
16
+ );
17
+
18
+ }
app/code/community/Netresearch/OPS/Model/Backend/Operation/Refund/Additional/OpenInvoiceNl.php ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @author Paul Siedler <paul.siedler@netresearch.de>
5
+ * @category Netresearch
6
+ * @copyright Copyright (c) 2014 Netresearch GmbH & Co. KG (http://www.netresearch.de)
7
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
8
+ */
9
+
10
+ class Netresearch_OPS_Model_Backend_Operation_Refund_Additional_OpenInvoiceNl
11
+ extends Netresearch_OPS_Model_Backend_Operation_Parameter_Additional_OpenInvoiceNlAbstract
12
+ {
13
+ protected $creditmemo = array();
14
+ protected $amount = 0;
15
+ protected $refundHelper = null;
16
+
17
+ /**
18
+ * @param Mage_Sales_Model_Abstract $itemContainer
19
+ * @return array
20
+ */
21
+ public function extractAdditionalParams(Mage_Sales_Model_Abstract $itemContainer = null)
22
+ {
23
+ $invoice = null;
24
+ if ($itemContainer instanceof Mage_Sales_Model_Order_Invoice && $itemContainer) {
25
+ $invoice = $itemContainer;
26
+ } else if ($itemContainer instanceof Mage_Sales_Block_Order_Creditmemo && $itemContainer){
27
+ $invoice = Mage::getModel('sales/order_invoice')->load($itemContainer->getInvoiceId());
28
+ }
29
+
30
+ if($invoice == null){
31
+ // if invoice is not set we load id hard from the request params
32
+ $invoice = $this->getRefundHelper()->getInvoiceFromCreditMemoRequest();
33
+ }
34
+ $this->creditmemo = $this->getRefundHelper()->getCreditMemoFromRequest();
35
+
36
+ if ($invoice instanceof Mage_Sales_Model_Order_Invoice) {
37
+ $this->extractFromCreditMemoItems($invoice);
38
+ // We dont extract from discount data for the moment, because partial refunds are a problem
39
+ // $this->extractFromDiscountData($invoice);
40
+ $this->extractFromInvoicedShippingMethod($invoice);
41
+ $this->extractFromAdjustments($invoice);
42
+ // Overwrite amount to fix Magentos rounding problems (eg +1ct)
43
+ $this->additionalParams['AMOUNT'] = $this->amount;
44
+ }
45
+
46
+ return $this->additionalParams;
47
+ }
48
+
49
+ /**
50
+ * extracts all data from the invoice according to the credit memo items
51
+ *
52
+ * @param $itemContainer
53
+ */
54
+ protected function extractFromCreditMemoItems(Mage_Sales_Model_Order_Invoice $invoice)
55
+ {
56
+ foreach ($invoice->getItemsCollection() as $item) {
57
+ if (array_key_exists($item->getOrderItemId(), $this->creditmemo['items'])) {
58
+ if ($item->getParentItemId()
59
+ && $item->getParentItem()->getProductType() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE
60
+ || $item->getProductType() == Mage_Catalog_Model_Product_Type::TYPE_BUNDLE) {
61
+ continue;
62
+ }
63
+ $this->additionalParams['ITEMID' . $this->itemIdx] = substr($item->getOrderItemId(), 0, 15);
64
+ $this->additionalParams['ITEMNAME' . $this->itemIdx] = substr($item->getName(), 0, 30);
65
+ $this->additionalParams['ITEMPRICE' . $this->itemIdx] = $this->getOpsDataHelper()->getAmount(
66
+ $item->getBasePriceInclTax()
67
+ );
68
+ $this->amount += $this->getOpsDataHelper()->getAmount($item->getBasePriceInclTax()) * $this->creditmemo['items'][$item->getOrderItemId()]['qty'];
69
+ $this->additionalParams['ITEMQUANT' . $this->itemIdx] = $this->creditmemo['items'][$item->getOrderItemId()]['qty'];
70
+ $this->additionalParams['ITEMVATCODE' . $this->itemIdx]
71
+ =
72
+ str_replace(',', '.', (string)(float)$item->getTaxPercent()) . '%';
73
+ $this->additionalParams['TAXINCLUDED' . $this->itemIdx] = 1;
74
+ ++$this->itemIdx;
75
+ }
76
+ }
77
+
78
+ }
79
+
80
+
81
+ protected function extractFromInvoicedShippingMethod(Mage_Sales_Model_Order_Invoice $invoice)
82
+ {
83
+ if ($this->creditmemo['shipping_amount'] > 0) {
84
+ $this->additionalParams['ITEMID' . $this->itemIdx] = 'SHIPPING';
85
+ $this->additionalParams['ITEMNAME' . $this->itemIdx] =
86
+ substr($invoice->getOrder()->getShippingDescription(), 0, 30);
87
+ $this->additionalParams['ITEMPRICE' . $this->itemIdx] = $this->getOpsDataHelper()->getAmount($this->creditmemo['shipping_amount']);
88
+ $this->amount += $this->getOpsDataHelper()->getAmount($this->creditmemo['shipping_amount']);
89
+ $this->additionalParams['ITEMQUANT' . $this->itemIdx] = 1;
90
+ $this->additionalParams['ITEMVATCODE' . $this->itemIdx] = $this->getShippingTaxRate($invoice) . '%';
91
+ $this->additionalParams['TAXINCLUDED' . $this->itemIdx] = 1;
92
+ ++$this->itemIdx;
93
+ }
94
+
95
+ }
96
+
97
+ /**
98
+ * extracts all data from the adjustment fee/refund
99
+ *
100
+ * @param $invoice
101
+ */
102
+ protected function extractFromAdjustments(Mage_Sales_Model_Order_Invoice $invoice)
103
+ {
104
+
105
+ if ($this->creditmemo['adjustment_positive'] > 0) {
106
+ $this->additionalParams['ITEMID' . $this->itemIdx] = 'ADJUSTREFUND';
107
+ $this->additionalParams['ITEMNAME' . $this->itemIdx] = 'Adjustment Refund';
108
+ $this->additionalParams['ITEMPRICE' . $this->itemIdx] = $this->getOpsDataHelper()->getAmount($this->creditmemo['adjustment_positive']);
109
+ $this->amount += $this->getOpsDataHelper()->getAmount($this->creditmemo['adjustment_positive']);
110
+ $this->additionalParams['ITEMQUANT' . $this->itemIdx] = 1;
111
+ $this->additionalParams['ITEMVATCODE' . $this->itemIdx] = $this->getShippingTaxRate($invoice) . '%';
112
+ $this->additionalParams['TAXINCLUDED' . $this->itemIdx] = 1;
113
+ ++$this->itemIdx;
114
+
115
+ }
116
+ if ($this->creditmemo['adjustment_negative'] > 0) {
117
+ $this->additionalParams['ITEMID' . $this->itemIdx] = 'ADJUSTFEE';
118
+ $this->additionalParams['ITEMNAME' . $this->itemIdx] = 'Adjustment Fee';
119
+ $this->additionalParams['ITEMPRICE' . $this->itemIdx] = $this->getOpsDataHelper()->getAmount(-$this->creditmemo['adjustment_negative']);
120
+ $this->amount += $this->getOpsDataHelper()->getAmount(-$this->creditmemo['adjustment_negative']);
121
+ $this->additionalParams['ITEMQUANT' . $this->itemIdx] = 1;
122
+ $this->additionalParams['ITEMVATCODE' . $this->itemIdx] = $this->getShippingTaxRate($invoice) . '%';
123
+ $this->additionalParams['TAXINCLUDED' . $this->itemIdx] = 1;
124
+ ++$this->itemIdx;
125
+ }
126
+ }
127
+
128
+ /**
129
+ * gets the refund helper
130
+ *
131
+ * @return Netresearch_OPS_Helper_Order_Refund|null
132
+ */
133
+ protected function getRefundHelper()
134
+ {
135
+ if (null === $this->refundHelper) {
136
+ $this->refundHelper = Mage::helper('ops/order_refund');
137
+ }
138
+
139
+ return $this->refundHelper;
140
+ }
141
+ }
app/code/community/Netresearch/OPS/Model/Backend/Operation/Refund/Parameter.php ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @author Paul Siedler <paul.siedler@netresearch.de>
5
+ * @category Netresearch
6
+ * @copyright Copyright (c) 2014 Netresearch GmbH & Co. KG (http://www.netresearch.de)
7
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
8
+ */
9
+
10
+ class Netresearch_OPS_Model_Backend_Operation_Refund_Parameter
11
+ extends Netresearch_OPS_Model_Backend_Operation_Parameter_Abstract
12
+ {
13
+ /**
14
+ * checks whether we need to retrieve additional parameter for the refund request or not
15
+ *
16
+ * @param Netresearch_OPS_Model_Payment_Abstract $opsPaymentMethod
17
+ *
18
+ * @return bool - true if we need to retrieve any additional parameters, false otherwise
19
+ */
20
+ protected function isPmRequiringAdditionalParams(Netresearch_OPS_Model_Payment_Abstract $opsPaymentMethod)
21
+ {
22
+ $opsPaymentMethodClass = get_class($opsPaymentMethod);
23
+ $opsPmsRequiringSpecialParams = $this->getOpsConfig()
24
+ ->getMethodsRequiringAdditionalParametersFor(Netresearch_OPS_Model_Payment_Abstract::OPS_REFUND_TRANSACTION_TYPE);
25
+
26
+ return (in_array($opsPaymentMethodClass, array_values($opsPmsRequiringSpecialParams)));
27
+ }
28
+ /**
29
+ * sets the model which retrieves the additional params for the refund request
30
+ *
31
+ * @param Netresearch_OPS_Model_Payment_Abstract $opsPaymentMethod
32
+ */
33
+ protected function setAdditionalParamsModelFor(Netresearch_OPS_Model_Payment_Abstract $opsPaymentMethod)
34
+ {
35
+ if ($opsPaymentMethod instanceof Netresearch_OPS_Model_Payment_OpenInvoiceNl) {
36
+ $this->additionalParamsModel = Mage::getModel('ops/backend_operation_refund_additional_openInvoiceNl');
37
+ }
38
+ }
39
+
40
+ protected function addPmSpecificParams(Netresearch_OPS_Model_Payment_Abstract $opsPaymentMethod, Varien_Object $payment, $amount)
41
+ {
42
+ if ($this->isPmRequiringAdditionalParams($opsPaymentMethod)) {
43
+ $this->setAdditionalParamsModelFor($opsPaymentMethod);
44
+ if ($this->additionalParamsModel instanceof Netresearch_OPS_Model_Backend_Operation_Parameter_Additional_Interface) {
45
+ $params = $this->additionalParamsModel->extractAdditionalParams(Mage::registry('current_creditmemo'));
46
+ $this->requestParams = array_merge($this->requestParams, $params);
47
+ }
48
+ }
49
+
50
+ return $this;
51
+ }
52
+
53
+ }
app/code/community/Netresearch/OPS/Model/Config.php ADDED
@@ -0,0 +1,692 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Netresearch_OPS
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Config model
29
+ */
30
+ class Netresearch_OPS_Model_Config extends Mage_Payment_Model_Config
31
+ {
32
+ const OPS_PAYMENT_PATH = 'payment_services/ops/';
33
+ const OPS_CONTROLLER_ROUTE_API = 'ops/api/';
34
+ const OPS_CONTROLLER_ROUTE_PAYMENT = 'ops/payment/';
35
+
36
+ /**
37
+ * Return ops payment config information
38
+ *
39
+ * @param string $path
40
+ * @param int $storeId
41
+ *
42
+ * @return Simple_Xml
43
+ */
44
+ public function getConfigData($path, $storeId = null)
45
+ {
46
+ if (!empty($path)) {
47
+ return Mage::getStoreConfig(self::OPS_PAYMENT_PATH . $path, $storeId);
48
+ }
49
+ return false;
50
+ }
51
+
52
+ /**
53
+ * Return SHA1-in crypt key from config. Setup on admin place.
54
+ *
55
+ * @param int $storeId
56
+ *
57
+ * @return string
58
+ */
59
+ public function getShaInCode($storeId = null)
60
+ {
61
+ return Mage::helper('core')->decrypt($this->getConfigData('secret_key_in', $storeId));
62
+ }
63
+
64
+ /**
65
+ * Return SHA1-out crypt key from config. Setup on admin place.
66
+ *
67
+ * @param int $storeId
68
+ *
69
+ * @return string
70
+ */
71
+ public function getShaOutCode($storeId = null)
72
+ {
73
+ return Mage::helper('core')->decrypt($this->getConfigData('secret_key_out', $storeId));
74
+ }
75
+
76
+ /**
77
+ * Return frontend gateway path, get from config. Setup on admin place.
78
+ *
79
+ * @param int $storeId
80
+ *
81
+ * @return string
82
+ */
83
+ public function getFrontendGatewayPath($storeId = null)
84
+ {
85
+ return $this->determineOpsUrl('frontend_gateway', $storeId);
86
+ }
87
+
88
+ /**
89
+ * Return Direct Link Gateway path, get from config. Setup on admin place.
90
+ *
91
+ * @param int $storeId
92
+ *
93
+ * @return string
94
+ */
95
+ public function getDirectLinkGatewayPath($storeId = null)
96
+ {
97
+ return $this->determineOpsUrl('directlink_gateway', $storeId);
98
+ }
99
+
100
+ public function getDirectLinkGatewayOrderPath($storeId = null)
101
+ {
102
+ return $this->determineOpsUrl('directlink_gateway_order', $storeId);
103
+ }
104
+
105
+ /**
106
+ * Return API User, get from config. Setup on admin place.
107
+ *
108
+ * @param int $storeId
109
+ *
110
+ * @return string
111
+ */
112
+ public function getApiUserId($storeId = null)
113
+ {
114
+ return $this->getConfigData('api_userid', $storeId);
115
+ }
116
+
117
+ /**
118
+ * Return API Passwd, get from config. Setup on admin place.
119
+ *
120
+ * @param int $storeId
121
+ *
122
+ * @return string
123
+ */
124
+ public function getApiPswd($storeId = null)
125
+ {
126
+ return Mage::helper('core')->decrypt($this->getConfigData('api_pswd', $storeId));
127
+ }
128
+
129
+ /**
130
+ * Get PSPID, affiliation name in ops system
131
+ *
132
+ * @param int $storeId
133
+ *
134
+ * @return string
135
+ */
136
+ public function getPSPID($storeId = null)
137
+ {
138
+ return $this->getConfigData('pspid', $storeId);
139
+ }
140
+
141
+ public function getPaymentAction($storeId = null)
142
+ {
143
+ return $this->getConfigData('payment_action', $storeId);
144
+ }
145
+
146
+ /**
147
+ * Get paypage template for magento style templates using
148
+ *
149
+ * @return string
150
+ */
151
+ public function getPayPageTemplate()
152
+ {
153
+ return Mage::getUrl(self::OPS_CONTROLLER_ROUTE_PAYMENT . 'paypage',
154
+ array('_nosid' => true, '_secure' => $this->isCurrentlySecure()));
155
+ }
156
+
157
+ /**
158
+ * Return url which ops system will use as accept
159
+ *
160
+ * @return string
161
+ */
162
+ public function getAcceptUrl()
163
+ {
164
+ return Mage::getUrl(self::OPS_CONTROLLER_ROUTE_PAYMENT . 'accept',
165
+ array('_nosid' => true, '_secure' => $this->isCurrentlySecure()));
166
+ }
167
+
168
+ /**
169
+ * Return url which ops system will use as accept for alias generation
170
+ *
171
+ * @return string
172
+ */
173
+ public function getAliasAcceptUrl($storeId = null, $admin = false)
174
+ {
175
+ $params = array(
176
+ '_secure' => $this->isCurrentlySecure(),
177
+ '_nosid' => true
178
+ );
179
+ if (false === is_null($storeId)) {
180
+ $params['_store'] = $storeId;
181
+ }
182
+ $urlModelKey = $admin ? 'adminhtml/url' : 'core/url';
183
+ return Mage::getModel($urlModelKey)->getUrl(self::OPS_CONTROLLER_ROUTE_PAYMENT . 'acceptAlias', $params);
184
+ }
185
+
186
+ /**
187
+ * Return url which ops system will use as decline url
188
+ *
189
+ * @return string
190
+ */
191
+ public function getDeclineUrl()
192
+ {
193
+ return Mage::getUrl(self::OPS_CONTROLLER_ROUTE_PAYMENT . 'decline',
194
+ array('_nosid' => true, '_secure' => $this->isCurrentlySecure()));
195
+ }
196
+
197
+ /**
198
+ * Return url which ops system will use as exception url
199
+ *
200
+ * @return string
201
+ */
202
+ public function getExceptionUrl()
203
+ {
204
+ return Mage::getUrl(self::OPS_CONTROLLER_ROUTE_PAYMENT . 'exception',
205
+ array('_nosid' => true, '_secure' => $this->isCurrentlySecure()));
206
+ }
207
+
208
+ /**
209
+ * Return url which ops system will use as exception url for alias generation
210
+ *
211
+ * @return string
212
+ */
213
+ public function getAliasExceptionUrl($storeId = null, $admin = false)
214
+ {
215
+ $params = array(
216
+ '_secure' => $this->isCurrentlySecure(),
217
+ '_nosid' => true
218
+ );
219
+ if (false === is_null($storeId)) {
220
+ $params['_store'] = $storeId;
221
+ }
222
+ $urlModelKey = $admin ? 'adminhtml/url' : 'core/url';
223
+ return Mage::getModel($urlModelKey)->getUrl(self::OPS_CONTROLLER_ROUTE_PAYMENT . 'exceptionAlias', $params);
224
+ }
225
+
226
+ /**
227
+ * Return url which ops system will use as cancel url
228
+ *
229
+ * @return string
230
+ */
231
+ public function getCancelUrl()
232
+ {
233
+ return Mage::getUrl(self::OPS_CONTROLLER_ROUTE_PAYMENT . 'cancel',
234
+ array('_nosid' => true, '_secure' => $this->isCurrentlySecure()));
235
+ }
236
+
237
+ /**
238
+ * Return url which ops system will use as continue shopping url
239
+ *
240
+ * @param array $redirect
241
+ *
242
+ * @return string
243
+ */
244
+ public function getContinueUrl($redirect = array())
245
+ {
246
+ $urlParams = array('_nosid' => true, '_secure' => $this->isCurrentlySecure());
247
+ if (!empty($redirect)) $urlParams = array_merge($redirect, $urlParams);
248
+ return Mage::getUrl(self::OPS_CONTROLLER_ROUTE_PAYMENT . 'continue', $urlParams);
249
+ }
250
+
251
+ /**
252
+ * Return url to redirect after confirming the order
253
+ *
254
+ * @return string
255
+ */
256
+ public function getPaymentRedirectUrl()
257
+ {
258
+ return Mage::getUrl(self::OPS_CONTROLLER_ROUTE_PAYMENT . 'placeform',
259
+ array('_secure' => true, '_nosid' => true));
260
+ }
261
+
262
+ /**
263
+ * Return 3D Secure url to redirect after confirming the order
264
+ *
265
+ * @return string
266
+ */
267
+ public function get3dSecureRedirectUrl()
268
+ {
269
+ return Mage::getUrl(self::OPS_CONTROLLER_ROUTE_PAYMENT . 'placeform3dsecure',
270
+ array('_secure' => true, '_nosid' => true));
271
+ }
272
+
273
+ public function getSaveCcBrandUrl()
274
+ {
275
+ return Mage::getUrl(self::OPS_CONTROLLER_ROUTE_PAYMENT . 'saveCcBrand',
276
+ array('_secure' => $this->isCurrentlySecure(), '_nosid' => true));
277
+ }
278
+
279
+ public function getGenerateHashUrl($storeId = null, $admin = false)
280
+ {
281
+ $params = array(
282
+ '_secure' => $this->isCurrentlySecure(),
283
+ '_nosid' => true
284
+ );
285
+ if (false === is_null($storeId)) {
286
+ $params['_store'] = $storeId;
287
+ }
288
+ $urlModelKey = $admin ? 'adminhtml/url' : 'core/url';
289
+ return Mage::getModel($urlModelKey)->getUrl(self::OPS_CONTROLLER_ROUTE_PAYMENT . 'generatehash', $params);
290
+ }
291
+
292
+ public function getRegisterDirectDebitPaymentUrl()
293
+ {
294
+ return Mage::getUrl(self::OPS_CONTROLLER_ROUTE_PAYMENT . 'registerDirectDebitPayment',
295
+ array('_secure' => $this->isCurrentlySecure(), '_nosid' => true));
296
+ }
297
+
298
+ /**
299
+ * Checks if requests should be logged or not regarding configuration
300
+ *
301
+ * @return boolean
302
+ */
303
+ public function shouldLogRequests($storeId = null)
304
+ {
305
+ return $this->getConfigData('debug_flag', $storeId);
306
+ }
307
+
308
+ public function hasCatalogUrl()
309
+ {
310
+ return Mage::getStoreConfig('payment_services/ops/showcatalogbutton');
311
+ }
312
+
313
+ public function hasHomeUrl()
314
+ {
315
+ return Mage::getStoreConfig('payment_services/ops/showhomebutton');
316
+ }
317
+
318
+ public function getAcceptedCcTypes()
319
+ {
320
+ return Mage::getStoreConfig('payment/ops_cc/types');
321
+ }
322
+
323
+ public function getInlinePaymentCcTypes()
324
+ {
325
+ $redirectAll = (bool)(int)Mage::getStoreConfig('payment/ops_cc/redirect_all');
326
+ if ($redirectAll) {
327
+ return array();
328
+ }
329
+
330
+ $inlineTypes = Mage::getStoreConfig('payment/ops_cc/inline_types');
331
+ if (false == is_array($inlineTypes)) {
332
+ $inlineTypes = explode(',', $inlineTypes);
333
+ }
334
+ return $inlineTypes;
335
+ }
336
+
337
+ public function get3dSecureIsActive()
338
+ {
339
+ return Mage::getStoreConfig('payment/ops_cc/enabled_3dsecure');
340
+ }
341
+
342
+ public function getDirectDebitCountryIds()
343
+ {
344
+ return Mage::getStoreConfig('payment/ops_directDebit/countryIds');
345
+ }
346
+
347
+ public function getBankTransferCountryIds()
348
+ {
349
+ return Mage::getStoreConfig('payment/ops_bankTransfer/countryIds');
350
+ }
351
+
352
+ public function getDirectEbankingBrands()
353
+ {
354
+ return Mage::getStoreConfig('payment/ops_directEbanking/brands');
355
+ }
356
+
357
+ public function getAliasGatewayUrl($storeId = null)
358
+ {
359
+ return $this->determineOpsUrl('ops_alias_gateway', $storeId);
360
+ }
361
+
362
+ public function getCcSaveAliasUrl($storeId = null, $admin = false)
363
+ {
364
+ $params = array(
365
+ '_secure' => $this->isCurrentlySecure()
366
+ );
367
+ if (false === is_null($storeId)) {
368
+ $params['_store'] = $storeId;
369
+ }
370
+ if ($admin) {
371
+ return Mage::getModel('adminhtml/url')->getUrl('ops/admin/saveAlias', $params);
372
+ } else {
373
+ return Mage::getUrl('ops/payment/saveAlias', $params);
374
+ }
375
+ }
376
+
377
+ /**
378
+ * get deeplink to transaction view at Ingenico Payment Services
379
+ *
380
+ * @param Mage_Sales_Model_Order_Payment $payment
381
+ *
382
+ * @return string
383
+ */
384
+ public function getOpsAdminPaymentUrl($payment)
385
+ {
386
+ return '';
387
+ }
388
+
389
+ public function isCurrentlySecure()
390
+ {
391
+ return Mage::app()->getStore()->isCurrentlySecure();
392
+ }
393
+
394
+ public function getIntersolveBrands()
395
+ {
396
+ $result = array();
397
+ $brands = Mage::getStoreConfig('payment/ops_interSolve/brands');
398
+ if (!is_null($brands)) {
399
+ $result = unserialize($brands);
400
+ }
401
+ return $result;
402
+ }
403
+
404
+ public function getAllCcTypes()
405
+ {
406
+ return explode(',', Mage::getStoreConfig('payment/ops_cc/availableTypes'));
407
+ }
408
+
409
+ /**
410
+ * get keys of parameters to be shown in scoring information block
411
+ *
412
+ * @return array
413
+ */
414
+ public function getAdditionalScoringKeys()
415
+ {
416
+ return array(
417
+ 'AAVCHECK',
418
+ 'CVCCHECK',
419
+ 'CCCTY',
420
+ 'IPCTY',
421
+ 'NBREMAILUSAGE',
422
+ 'NBRIPUSAGE',
423
+ 'NBRIPUSAGE_ALLTX',
424
+ 'NBRUSAGE',
425
+ 'VC',
426
+ 'CARDNO',
427
+ 'ED',
428
+ 'CN'
429
+ );
430
+ }
431
+
432
+ public function getSendInvoice()
433
+ {
434
+ return (bool)(int)Mage::getStoreConfig('payment_services/ops/send_invoice');
435
+ }
436
+
437
+ /**
438
+ * if payment method with given code is enabled for backend payments
439
+ *
440
+ * @param string $code Payment method code
441
+ *
442
+ * @return bool
443
+ */
444
+ public function isEnabledForBackend($code, $storeId = 0)
445
+ {
446
+ return (bool)(int)Mage::getStoreConfig('payment/' . $code . '/backend_enabled', $storeId);
447
+ }
448
+
449
+ public function isAliasInfoBlockEnabled()
450
+ {
451
+ return (bool)(int)Mage::getStoreConfig('payment/ops_cc/show_alias_manager_info_for_guests');
452
+ }
453
+
454
+ /**
455
+ * return config value for Alias Manager enabled
456
+ *
457
+ * @return bool
458
+ */
459
+ public function isAliasManagerEnabled()
460
+ {
461
+ return (bool)Mage::getStoreConfig('payment/ops_cc/active_alias');
462
+ }
463
+
464
+ /**
465
+ * getter for usage of order reference
466
+ */
467
+ public function getOrderReference($storeId = null)
468
+ {
469
+ return $this->getConfigData('redirectOrderReference', $storeId);
470
+ }
471
+
472
+ /**
473
+ * @param int $storeId - the store id to use
474
+ *
475
+ * @return int whether the QuoteId should be shown in
476
+ * the order grid (1) or not (0)
477
+ */
478
+ public function getShowQuoteIdInOrderGrid($storeId = null)
479
+ {
480
+ return $this->getConfigData('showQuoteIdInOrderGrid', $storeId);
481
+ }
482
+
483
+ /**
484
+ * @param int $storeId - the store id to use
485
+ *
486
+ * @return bool whether the tracking code fro fraud detection
487
+ * is activated or not
488
+ */
489
+ public function isTrackingCodeActivated($storeId = null)
490
+ {
491
+ return (bool)$this->getConfigData('enableTrackingCode', $storeId);
492
+ }
493
+
494
+
495
+ /**
496
+ * Check if the current environment is frontend or backend
497
+ *
498
+ * @return boolean
499
+ */
500
+ public function isFrontendEnvironment()
501
+ {
502
+ return (false === Mage::app()->getStore()->isAdmin());
503
+ }
504
+
505
+ /**
506
+ * getter for the accept route for payments
507
+ *
508
+ * @return string
509
+ */
510
+ public function getAcceptRedirectRoute()
511
+ {
512
+ return self::OPS_CONTROLLER_ROUTE_PAYMENT . 'accept';
513
+ }
514
+
515
+ /**
516
+ * getter for the cancel route for payments
517
+ *
518
+ * @return string
519
+ */
520
+ public function getCancelRedirectRoute()
521
+ {
522
+ return self::OPS_CONTROLLER_ROUTE_PAYMENT . 'cancel';
523
+ }
524
+
525
+ /**
526
+ * getter for the decline route for payments
527
+ *
528
+ * @return string
529
+ */
530
+ public function getDeclineRedirectRoute()
531
+ {
532
+ return self::OPS_CONTROLLER_ROUTE_PAYMENT . 'decline';
533
+ }
534
+
535
+ /**
536
+ * getter for the decline route for payments
537
+ *
538
+ * @return string
539
+ */
540
+ public function getExceptionRedirectRoute()
541
+ {
542
+ return self::OPS_CONTROLLER_ROUTE_PAYMENT . 'exception';
543
+ }
544
+
545
+
546
+ public function getMethodsRequiringAdditionalParametersFor($operation)
547
+ {
548
+ return Mage::getStoreConfig('payment/additional_params_required/' . $operation);
549
+ }
550
+
551
+
552
+ /**
553
+ * returns the url for the maintenance api calls
554
+ *
555
+ * @param null $storeId
556
+ *
557
+ * @return string - the url for the maintenance api calls
558
+ */
559
+ public function getDirectLinkMaintenanceApiPath($storeId = null)
560
+ {
561
+ return $this->determineOpsUrl('directlink_maintenance_api', $storeId);
562
+ }
563
+
564
+ /**
565
+ * getter for the iDeal issuers
566
+ *
567
+ * @return array
568
+ */
569
+ public function getIDealIssuers()
570
+ {
571
+ return Mage::getStoreConfig('payment/ops_iDeal/issuer');
572
+ }
573
+
574
+ /**
575
+ * whether extra parameters needs to be passed to Ingenico Payment Services or not
576
+ *
577
+ * @param null $storeId
578
+ *
579
+ * @return bool - true if it's enabled, false otherwise
580
+ */
581
+ public function canSubmitExtraParameter($storeId = null)
582
+ {
583
+ return (bool)$this->getConfigData('submitExtraParameters', $storeId);
584
+ }
585
+
586
+ public function getParameterLengths()
587
+ {
588
+ return $this->getConfigData('paramLength');
589
+ }
590
+
591
+ public function getFrontendFieldMapping()
592
+ {
593
+ return $this->getConfigData('frontendFieldMapping');
594
+
595
+ }
596
+
597
+ public function getValidationUrl()
598
+ {
599
+ return Mage::getUrl(self::OPS_CONTROLLER_ROUTE_PAYMENT . 'validate',
600
+ array('_secure' => $this->isCurrentlySecure(), '_nosid' => true));
601
+ }
602
+
603
+ public function getInlineOrderReference($storeId = null)
604
+ {
605
+ return $this->getConfigData('inlineOrderReference', $storeId);
606
+ }
607
+
608
+ /**
609
+ * Returns the mode of the store
610
+ *
611
+ * @param null $storeId
612
+ *
613
+ * @return string | mode (custom, prod, test) for the store
614
+ * @see Netresearch_OPS_Model_Source_Mode
615
+ */
616
+ public function getMode($storeId = null)
617
+ {
618
+ return $this->getConfigData('mode', $storeId);
619
+ }
620
+
621
+ protected function getOpsUrl($path)
622
+ {
623
+ return $this->getConfigData('url/' . $path);
624
+ }
625
+
626
+ /**
627
+ * Will always return the base url (https://secure.domain.tld/ncol/)
628
+ *
629
+ * @return string
630
+ */
631
+ public function getOpsBaseUrl()
632
+ {
633
+ return $this->getOpsUrl('base');
634
+ }
635
+
636
+ /**
637
+ * Returns the default url for the given gateway, depending on the mode, that is set for the the given store
638
+ *
639
+ * @param string $path
640
+ * @param int $storeId
641
+ *
642
+ * @return string
643
+ */
644
+ public function getDefaultOpsUrl($path, $storeId = null)
645
+ {
646
+ return $this->getOpsBaseUrl() . $this->getMode($storeId) . $this->getOpsUrl($path);
647
+ }
648
+
649
+ /**
650
+ * Returns the url for the given gateway depending on the set mode for the given store
651
+ *
652
+ * @param $path
653
+ * @param null $storeId
654
+ *
655
+ * @return string
656
+ */
657
+ public function determineOpsUrl($path, $storeId = null)
658
+ {
659
+ if ($this->getMode($storeId) === Netresearch_OPS_Model_Source_Mode::CUSTOM) {
660
+ return $this->getConfigData($path, $storeId);
661
+ } else {
662
+ return $this->getDefaultOpsUrl($path, $storeId);
663
+ }
664
+ }
665
+
666
+ public function getTemplateIdentifier($storeId = null)
667
+ {
668
+ return $this->getConfigData('template_identifier', $storeId);
669
+ }
670
+
671
+ public function getResendPaymentInfoIdentity($storeId = null)
672
+ {
673
+ return $this->getConfigData('resendPaymentInfo_identity', $storeId);
674
+ }
675
+
676
+ public function getResendPaymentInfoTemplate($storeId = null)
677
+ {
678
+ return $this->getConfigData('resendPaymentInfo_template', $storeId);
679
+ }
680
+
681
+ public function getStateRestriction()
682
+ {
683
+ return $this->getConfigData('ops_state_restriction');
684
+ }
685
+
686
+ public function getPaymentRetryUrl($params)
687
+ {
688
+ return Mage::getUrl(self::OPS_CONTROLLER_ROUTE_PAYMENT . 'retry',
689
+ array('_secure' => true, '_nosid' => true, '_query' => $params));
690
+ }
691
+
692
+ }
app/code/community/Netresearch/OPS/Model/Eci/Values.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Netresearch_OPS
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * OPS payment DirectLink Model
29
+ */
30
+ class Netresearch_OPS_Model_Eci_Values extends Mage_Core_Model_Abstract
31
+ {
32
+ const ECOM_WITH_SSL_ENCRYPTION = 7;
33
+
34
+ const MANUALLY_KEYED_FROM_MOTO = 1;
35
+ }
app/code/community/Netresearch/OPS/Model/File/Download.php ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Netresearch_OPS_Model_File_Download
4
+ {
5
+
6
+ /**
7
+ * Number of bytes in one MB
8
+ */
9
+ const ONE_MEGABYTE = 1048576;
10
+
11
+ protected $_fileHandler;
12
+
13
+ protected $_filePath;
14
+
15
+ /**
16
+ * Takes a file name and a size threshold.
17
+ * If the file is bigger than the threshold, the last written lines, up to the size of the
18
+ * threshold are returned
19
+ *
20
+ * @param string $path Path to file on server
21
+ * @param int $threshold Max file size, default is 1MB
22
+ * @return string Path to file to offer to download
23
+ * @throws Mage_Core_Exception
24
+ */
25
+ public function getFile($path, $threshold = self::ONE_MEGABYTE)
26
+ {
27
+ $this->_filePath = $path;
28
+ if(!file_exists($this->_filePath) || !is_readable($this->_filePath)){
29
+ Mage::throwException('File '.$this->_filePath.' does not exist or is not readable.');
30
+ return '';
31
+ }
32
+ if(filesize($path) > $threshold){
33
+ return $this->_trimFileToThreshold($threshold);
34
+ } else {
35
+ return $this->_filePath;
36
+ }
37
+ }
38
+
39
+ /**
40
+ * Trims the current file to the given threshold and creates a temporary file
41
+ *
42
+ * @param $threshold Max file size
43
+ * @return string Path to the temporary file
44
+ * @throws Mage_Core_Exception
45
+ */
46
+ protected function _trimFileToThreshold($threshold)
47
+ {
48
+ $this->_fileHandler = fopen($this->_filePath, 'r');
49
+ if(0 > fseek($this->_fileHandler, filesize($this->_filePath)-$threshold, SEEK_SET)){
50
+ Mage::throwException('Function fseek on file '. $this->_filePath.' failed.');
51
+ }
52
+ $content = fread($this->_fileHandler, $threshold);
53
+ fclose($this->_fileHandler);
54
+ $tempFileName = tempnam(sys_get_temp_dir(), 'tempFile');
55
+ file_put_contents($tempFileName, $content);
56
+
57
+ return $tempFileName;
58
+ }
59
+
60
+
61
+ }
app/code/community/Netresearch/OPS/Model/Kwixo/Category/Mapping.php ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category OPS
22
+ * @package Netresearch_OPS
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Alias model
29
+ */
30
+
31
+ class Netresearch_OPS_Model_Kwixo_Category_Mapping
32
+ extends Mage_Core_Model_Abstract
33
+ {
34
+
35
+ /**
36
+ * Constructor
37
+ *
38
+ * @see lib/Varien/Varien_Object#_construct()
39
+ * @return Netresearch_OPS_Model_Kwixo_Category_Mapping
40
+ */
41
+ public function _construct()
42
+ {
43
+ $this->_init('ops/kwixo_category_mapping');
44
+ parent::_construct();
45
+ }
46
+
47
+
48
+ public function loadByCategoryId($categoryId)
49
+ {
50
+ $collection = $this->getCollection()
51
+ ->addFieldToFilter('category_id', $categoryId)
52
+ ->load();
53
+ return $collection->getFirstItem();
54
+ }
55
+
56
+ }
app/code/community/Netresearch/OPS/Model/Kwixo/Shipping/Setting.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Michael Lühr <michael.luehr@netresearch.de>
4
+ * @category Netresearch
5
+ * @package ${MODULENAME}
6
+ * @copyright Copyright (c) 2013 Netresearch GmbH & Co. KG (http://www.netresearch.de)
7
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
8
+ */
9
+
10
+
11
+ class Netresearch_OPS_Model_Kwixo_Shipping_Setting
12
+ extends Mage_Core_Model_Abstract
13
+ {
14
+ /**
15
+ * Constructor
16
+ *
17
+ * @see lib/Varien/Varien_Object#_construct()
18
+ * @return Netresearch_OPS_Model_Kwixo_Shipping_Setting
19
+ */
20
+ public function _construct()
21
+ {
22
+ $this->_init('ops/kwixo_shipping_setting');
23
+ parent::_construct();
24
+ }
25
+ }
app/code/community/Netresearch/OPS/Model/Mysql4/Alias.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category OPS
4
+ * @package Netresearch_OPS
5
+ * @author Thomas Birke <thomas.birke@netresearch.de>
6
+ * @author Michael Lühr <michael.luehr@netresearch.de>
7
+ * @copyright Copyright (c) 2012 Netresearch GmbH & Co. KG
8
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
9
+ */
10
+
11
+ /**
12
+ * Netresearch_OPS_Model_Mysql4_Alias
13
+ * Netresearch_OPS_Model_Mysql4_Alias
14
+ * @author Michael Lühr <michael.luehr@netresearch.de>
15
+ * @author Thomas Birke <thomas.birke@netresearch.de>
16
+ * @copyright Copyright (c) 2012 Netresearch GmbH & Co. KG
17
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
+ */
19
+
20
+ class Netresearch_OPS_Model_Mysql4_Alias
21
+ extends Mage_Core_Model_Mysql4_Abstract
22
+ {
23
+ /**
24
+ * Constructor
25
+ *
26
+ * @see lib/Varien/Varien_Object#_construct()
27
+ * @return Netresearch_OPS_Model_Mysql4_Alias
28
+ */
29
+ public function _construct()
30
+ {
31
+ $this->_init('ops/alias','id');
32
+ }
33
+ }
app/code/community/Netresearch/OPS/Model/Mysql4/Alias/Collection.php ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category OPS
4
+ * @package Netresearch_OPS
5
+ * @author Thomas Birke <thomas.birke@netresearch.de>
6
+ * @author Michael Lühr <michael.luehr@netresearch.de>
7
+ * @copyright Copyright (c) 2012 Netresearch GmbH & Co. KG
8
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
9
+ */
10
+
11
+ /**
12
+ * Netresearch_OPS_Model_Mysql4_Alias_Collection
13
+ * @author Thomas Birke <thomas.birke@netresearch.de>
14
+ * @author Michael Lühr <michael.luehr@netresearch.de>
15
+ * @copyright Copyright (c) 2012 Netresearch GmbH & Co. KG
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+
20
+ class Netresearch_OPS_Model_Mysql4_Alias_Collection extends
21
+ Mage_Core_Model_Mysql4_Collection_Abstract
22
+ {
23
+
24
+ protected function _construct()
25
+ {
26
+ parent::_construct();
27
+ $this->_init('ops/alias');
28
+ }
29
+ }
app/code/community/Netresearch/OPS/Model/Mysql4/Kwixo/Category/Mapping.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category OPS
4
+ * @package Netresearch_OPS
5
+ * @author Michael Lühr <michael.luehr@netresearch.de>
6
+ * @copyright Copyright (c) 2013 Netresearch GmbH & Co. KG
7
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
8
+ */
9
+
10
+ /**
11
+ * Netresearch_OPS_Model_Mysql4_Alias
12
+ * Netresearch_OPS_Model_Mysql4_Alias
13
+ * @author Michael Lühr <michael.luehr@netresearch.de>
14
+ * @copyright Copyright (c) 2013 Netresearch GmbH & Co. KG
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+ class Netresearch_OPS_Model_Mysql4_Kwixo_Category_Mapping
18
+ extends Mage_Core_Model_Mysql4_Abstract
19
+ {
20
+
21
+ /**
22
+ * Constructor
23
+ *
24
+ * @see lib/Varien/Varien_Object#_construct()
25
+ * @return Netresearch_OPS_Model_Mysql4_Kwixo_Category_Mapping
26
+ */
27
+ public function _construct()
28
+ {
29
+ $this->_init('ops/kwixo_category_mapping','id');
30
+ }
31
+
32
+ }
app/code/community/Netresearch/OPS/Model/Mysql4/Kwixo/Category/Mapping/Collection.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category OPS
5
+ * @package Netresearch_OPS
6
+ * @author Michael Lühr <michael.luehr@netresearch.de>
7
+ * @copyright Copyright (c) 2013 Netresearch GmbH & Co. KG
8
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
9
+ */
10
+
11
+ /**
12
+ * Netresearch_OPS_Model_Mysql4_Kwixo_Category_Mapping_Collection
13
+ * @author Michael Lühr <michael.luehr@netresearch.de>
14
+ * @copyright Copyright (c) 2013 Netresearch GmbH & Co. KG
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ class Netresearch_OPS_Model_Mysql4_Kwixo_Category_Mapping_Collection
19
+ extends Mage_Core_Model_Mysql4_Collection_Abstract
20
+ {
21
+
22
+ protected function _construct()
23
+ {
24
+ parent::_construct();
25
+ $this->_init('ops/kwixo_category_mapping');
26
+ }
27
+
28
+ }
app/code/community/Netresearch/OPS/Model/Mysql4/Kwixo/Shipping/Setting.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Michael Lühr <michael.luehr@netresearch.de>
4
+ * @category Netresearch
5
+ * @package Netresearch_OPS
6
+ * @copyright Copyright (c) 2013 Netresearch GmbH & Co. KG (http://www.netresearch.de)
7
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
8
+ */
9
+
10
+
11
+ class Netresearch_OPS_Model_Mysql4_Kwixo_Shipping_Setting
12
+ extends Mage_Core_Model_Mysql4_Abstract
13
+
14
+ {
15
+
16
+ public function _construct()
17
+ {
18
+ $this->_init('ops/kwixo_shipping_setting', 'id');
19
+ }
20
+
21
+ }
app/code/community/Netresearch/OPS/Model/Mysql4/Kwixo/Shipping/Setting/Collection.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Michael Lühr <michael.luehr@netresearch.de>
4
+ * @category Netresearch
5
+ * @package ${MODULENAME}
6
+ * @copyright Copyright (c) 2013 Netresearch GmbH & Co. KG (http://www.netresearch.de)
7
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
8
+ */
9
+
10
+
11
+ class Netresearch_OPS_Model_Mysql4_Kwixo_Shipping_Setting_Collection
12
+ extends Mage_Core_Model_Mysql4_Collection_Abstract
13
+ {
14
+
15
+ protected function _construct()
16
+ {
17
+ parent::_construct();
18
+ $this->_init('ops/kwixo_shipping_setting');
19
+ }
20
+
21
+ }
app/code/community/Netresearch/OPS/Model/Observer.php ADDED
@@ -0,0 +1,567 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category OPS
4
+ * @package Netresearch_OPS
5
+ * @author André Herrn <andre.herrn@netresearch.de>
6
+ * @copyright Copyright (c) 2013 Netresearch GmbH & Co. KG
7
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
8
+ */
9
+
10
+ /**
11
+ * Netresearch_OPS_Model_Observer
12
+ *
13
+ * @author André Herrn <andre.herrn@netresearch.de>
14
+ * @copyright Copyright (c) 2013 Netresearch GmbH & Co. KG
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ class Netresearch_OPS_Model_Observer
19
+ {
20
+
21
+ /**
22
+ * Get one page checkout model
23
+ *
24
+ * @return Mage_Checkout_Model_Type_Onepage
25
+ */
26
+ public function getOnepage()
27
+ {
28
+ return Mage::getSingleton('checkout/type_onepage');
29
+ }
30
+
31
+ public function getAdminSession()
32
+ {
33
+ return Mage::getSingleton('admin/session');
34
+ }
35
+
36
+ public function isAdminSession()
37
+ {
38
+
39
+ if ($this->getAdminSession()->getUser()) {
40
+ return 0 < $this->getAdminSession()->getUser()->getUserId();
41
+ }
42
+ return false;
43
+ }
44
+
45
+ public function getHelper($name=null)
46
+ {
47
+ if (is_null($name)) {
48
+ return Mage::helper('ops');
49
+ }
50
+ return Mage::helper('ops/' . $name);
51
+ }
52
+
53
+ /**
54
+ * @return Netresearch_OPS_Model_Config
55
+ */
56
+ public function getConfig()
57
+ {
58
+ return Mage::getModel('ops/config');
59
+ }
60
+
61
+ /**
62
+ * trigger ops payment
63
+ */
64
+ public function checkoutTypeOnepageSaveOrderBefore($observer)
65
+ {
66
+ $quote = $observer->getQuote();
67
+ $order = $observer->getOrder();
68
+ $code = $quote->getPayment()->getMethodInstance()->getCode();
69
+
70
+ try {
71
+ if ('ops_directDebit' == $code && Mage::helper('ops/payment')->isInlinePaymentWithQuoteId($quote->getPayment())) {
72
+ $this->confirmDdPayment($order, $quote, $observer);
73
+ } elseif ($quote->getPayment()->getMethodInstance() instanceof Netresearch_OPS_Model_Payment_Abstract) {
74
+ $requestParams = $quote->getPayment()->getMethodInstance()->getFormFields($order, array(), false);
75
+ $this->invokeRequestParamValidation($requestParams);
76
+ }
77
+ } catch (Exception $e) {
78
+ $quote->setIsActive(true);
79
+ $this->getOnepage()->getCheckout()->setGotoSection('payment');
80
+ throw new Mage_Core_Exception($e->getMessage());
81
+ }
82
+ }
83
+
84
+ public function salesModelServiceQuoteSubmitFailure($observer)
85
+ {
86
+ $quote = $observer->getQuote();
87
+ if (Mage::helper('ops/payment')->isInlinePaymentWithQuoteId($quote->getPayment())) {
88
+ $this->handleFailedCheckout(
89
+ $observer->getQuote(),
90
+ $observer->getOrder()
91
+ );
92
+ }
93
+ }
94
+
95
+ protected function getQuoteCurrency($quote)
96
+ {
97
+ if ($quote->hasForcedCurrency()) {
98
+ return $quote->getForcedCurrency()->getCode();
99
+ } else {
100
+ return Mage::app()->getStore($quote->getStoreId())->getBaseCurrencyCode();
101
+ }
102
+ }
103
+
104
+ public function confirmAliasPayment($order, $quote)
105
+ {
106
+ $requestParams = Mage::helper('ops/creditcard')->getDirectLinkRequestParams($quote, $order);
107
+ $this->invokeRequestParamValidation($requestParams);
108
+ Mage::helper('ops/alias')->cleanUpAdditionalInformation($quote->getPayment(), true);
109
+
110
+ return $this->performDirectLinkRequest($quote, $requestParams, $quote->getStoreId());
111
+
112
+ }
113
+
114
+ public function confirmDdPayment($order, $quote)
115
+ {
116
+ /** @var Netresearch_OPS_Helper_DirectDebit $directDebitHelper */
117
+ $directDebitHelper = Mage::helper('ops/directDebit');
118
+ $requestParams = Mage::app()->getRequest()->getParam('ops_directDebit');
119
+ $directDebitHelper->handleAdminPayment($quote, $requestParams);
120
+ $requestParams = $directDebitHelper->getDirectLinkRequestParams($quote, $order, $requestParams);
121
+ $this->invokeRequestParamValidation($requestParams);
122
+
123
+ return $this->performDirectLinkRequest($quote, $requestParams, $quote->getStoreId());
124
+ }
125
+
126
+ public function performDirectLinkRequest($quote, $params, $storeId = null)
127
+ {
128
+ $url = Mage::getModel('ops/config')->getDirectLinkGatewayOrderPath($storeId);
129
+ $response = Mage::getSingleton('ops/api_directlink')->performRequest($params, $url, $storeId);
130
+ /**
131
+ * allow null as valid state for creating the order with status 'pending'
132
+ */
133
+ if (!is_null($response['STATUS'])
134
+ && Mage::helper('ops/payment')->isPaymentFailed($response['STATUS'])
135
+ ) {
136
+ throw new Mage_Core_Exception($this->getHelper()->__('Ingenico Payment Services Payment failed'));
137
+ }
138
+ $quote->getPayment()->setAdditionalInformation('ops_response', $response)->save();
139
+
140
+ }
141
+
142
+
143
+ /**
144
+ * Check if checkout was made with OPS CreditCart or DirectDebit
145
+ *
146
+ * @return boolean
147
+ */
148
+ protected function isCheckoutWithExistingTxId($code)
149
+ {
150
+ if ('ops_opsid' == $code)
151
+ return true;
152
+ else
153
+ return false;
154
+ }
155
+
156
+ /**
157
+ * Replace order cancel comfirm message of Magento by a custom message from Ingenico Payment Services
158
+ *
159
+ * @event adminhtml_block_html_before
160
+ * @param Varien_Event_Observer $observer
161
+ * @return Netresearch_OPS_Model_Observer
162
+ */
163
+ public function updateOrderCancelButton(Varien_Event_Observer $observer)
164
+ {
165
+ /* @var $block Mage_Adminhtml_Block_Template */
166
+ $block = $observer->getEvent()->getBlock();
167
+
168
+ //Stop if block is not sales order view
169
+ if ($block->getType() != 'adminhtml/sales_order_view') {
170
+ return $this;
171
+ }
172
+
173
+ //If payment method is one of the Ingenico Payment Services-ones and order can be cancelled manually
174
+ if ($block->getOrder()->getPayment()->getMethodInstance() instanceof Netresearch_OPS_Model_Payment_Abstract
175
+ && true === $block->getOrder()->getPayment()->getMethodInstance()->canCancelManually($block->getOrder())) {
176
+ //Build message and update cancel button
177
+ $message = Mage::helper('ops')->__(
178
+ "Are you sure you want to cancel this order? Warning: Please check the payment status in the back-office of Ingenico Payment Services before. By cancelling this order you won\\'t be able to update the status in Magento anymore."
179
+ );
180
+ $block->updateButton(
181
+ 'order_cancel',
182
+ 'onclick',
183
+ 'deleteConfirm(\''.$message.'\', \'' . $block->getCancelUrl() . '\')'
184
+ );
185
+ }
186
+ return $this;
187
+ }
188
+
189
+ /**
190
+ *
191
+ * appends a checkbox for closing the transaction if it's a Ingenico Payment Services payment
192
+ *
193
+ * @event core_block_abstract_to_html_after
194
+ * @param Varien_Event_Observer $observer
195
+ * @return void
196
+ */
197
+ public function appendCheckBoxToRefundForm($observer)
198
+ {
199
+ $html = '';
200
+ /*
201
+ * show the checkbox only if the credit memo create page is displayed and
202
+ * the refund can be done online and the payment is done via Ingenico Payment Services
203
+ */
204
+ if ($observer->getBlock() instanceof Mage_Adminhtml_Block_Sales_Order_Creditmemo_Totals
205
+ && $observer->getBlock()->getParentBlock()
206
+ instanceof Mage_Adminhtml_Block_Sales_Order_Creditmemo_Create_Items
207
+ && $observer->getBlock()->getParentBlock()->getCreditmemo()->getOrder()->getPayment()
208
+ && $observer->getBlock()->getParentBlock()->getCreditmemo()->getOrder()->getPayment()->getMethodInstance()
209
+ instanceof Netresearch_OPS_Model_Payment_Abstract
210
+ && $observer->getBlock()->getParentBlock()->getCreditmemo()->canRefund()
211
+ && $observer->getBlock()->getParentBlock()->getCreditmemo()->getInvoice()
212
+ && $observer->getBlock()->getParentBlock()->getCreditmemo()->getInvoice()->getTransactionId()
213
+ ) {
214
+ $transport = $observer->getTransport();
215
+ $block = $observer->getBlock();
216
+ $layout = $block->getLayout();
217
+ $html = $transport->getHtml();
218
+ $checkBoxHtml = $layout->createBlock(
219
+ 'ops/adminhtml_sales_order_creditmemo_totals_checkbox',
220
+ 'ops_refund_checkbox'
221
+ )
222
+ ->setTemplate('ops/sales/order/creditmemo/totals/checkbox.phtml')
223
+ ->renderView();
224
+ $html = $html . $checkBoxHtml;
225
+ $transport->setHtml($html);
226
+ }
227
+ return $html;
228
+ }
229
+
230
+ /**
231
+ *
232
+ * fetch the creation of credit memo event and display warning message when
233
+ * - credit memo could be done online
234
+ * - payment is a Ingenico Payment Services payment
235
+ * - Ingenico Payment Services transaction is closed
236
+ *
237
+ * @event core_block_abstract_to_html_after
238
+ * @param Varien_Event_Observer $observer
239
+ * @return void
240
+ */
241
+ public function showWarningForClosedTransactions($observer)
242
+ {
243
+ $html = '';
244
+ /**
245
+ * - credit memo could be done online
246
+ * - payment is a Ingenico Payment Services payment
247
+ * - Ingenico Payment Services transaction is closed
248
+ */
249
+ if ($observer->getBlock() instanceof Mage_Adminhtml_Block_Sales_Order_Creditmemo_Create
250
+ && $observer->getBlock()->getCreditmemo()->getOrder()->getPayment()
251
+ && $observer->getBlock()->getCreditmemo()->getOrder()->getPayment()->getMethodInstance()
252
+ instanceof Netresearch_OPS_Model_Payment_Abstract
253
+ && $observer->getBlock()->getCreditmemo()->getInvoice()
254
+ && $observer->getBlock()->getCreditmemo()->getInvoice()->getTransactionId()
255
+ && false === $observer->getBlock()->getCreditmemo()->canRefund()
256
+ ) {
257
+ $transport = $observer->getTransport();
258
+ $block = $observer->getBlock();
259
+ $layout = $block->getLayout();
260
+ $html = $transport->getHtml();
261
+ $warningHtml = $layout->createBlock(
262
+ 'ops/adminhtml_sales_order_creditmemo_closedTransaction_warning',
263
+ 'ops_closed-transaction-warning'
264
+ )
265
+ ->renderView();
266
+ $html = $warningHtml . $html;
267
+ $transport->setHtml($html);
268
+ }
269
+ return $html;
270
+ }
271
+
272
+
273
+ /**
274
+ * triggered by cron for deleting old payment data from the additional payment information
275
+ * @param $observer
276
+ */
277
+ public function cleanUpOldPaymentData($observer)
278
+ {
279
+ Mage::helper('ops/quote')->cleanUpOldPaymentInformation();
280
+ }
281
+
282
+ /**
283
+ * in some cases the payment method is not set properly by Magento so we need to reset the
284
+ * payment method in the quote's payment before importing the data
285
+ *
286
+ * @event sales_quote_payment_import_data_before
287
+ * @param $observer
288
+ * @return $this
289
+ */
290
+ public function clearPaymentMethodFromQuote(Varien_Event_Observer $observer)
291
+ {
292
+ if ($observer->getEventName() == 'sales_quote_payment_import_data_before'
293
+ && $observer->getEvent()->getPayment() instanceof Mage_Sales_Model_Quote_Payment
294
+ ) {
295
+ $observer->getEvent()->getPayment()->setMethod(null);
296
+ }
297
+
298
+ return $this;
299
+ }
300
+
301
+ /**
302
+ * appends the status update button to the order's button in case it's an Ingenico Payment Services payment
303
+ *
304
+ * @event core_block_abstract_prepare_layout_before
305
+ * @param Varien_Event_Observer $observer
306
+ * @return $this
307
+ */
308
+ public function addStatusUpdateButtonToOrderView(Varien_Event_Observer $observer)
309
+ {
310
+ $block = $observer->getBlock();
311
+ if ($block instanceof Mage_Adminhtml_Block_Sales_Order_View) {
312
+ $paymentMethod = $block->getOrder()->getPayment()->getMethodInstance();
313
+ if ($paymentMethod instanceof Netresearch_OPS_Model_Payment_Abstract
314
+ && Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/invoice')) {
315
+ $block->addButton('ops_refresh', array(
316
+ 'label' => Mage::helper('ops/data')->__('Refresh payment status'),
317
+ 'onclick' => 'setLocation(\'' . $block->getUrl('adminhtml/opsstatus/update') . '\')'));
318
+ }
319
+ }
320
+
321
+ return $this;
322
+ }
323
+
324
+ /**
325
+ * @event core_block_abstract_prepare_layout_before
326
+ *
327
+ * @param Varien_Event_Observer $observer
328
+ * @return $this
329
+ */
330
+ public function addCcPaymentMethod(Varien_Event_Observer $observer)
331
+ {
332
+ /** @var $block Mage_Payment_Block_Form_Container */
333
+ $block = $observer->getEvent()->getBlock();
334
+ if ($block instanceof Mage_Payment_Block_Form_Container
335
+ && !Mage::helper('ops/version')->canUseApplicableForQuote(Mage::getEdition())
336
+ ) {
337
+ Mage::helper('ops/payment')->addCCForZeroAmountCheckout($block);
338
+ }
339
+
340
+ return $this;
341
+ }
342
+
343
+ /**
344
+ * @event core_block_abstract_prepare_layout_before
345
+ *
346
+ * @param Varien_Event_Observer $observer
347
+ *
348
+ * @return $this
349
+ */
350
+ public function disableCaptureForZeroAmountInvoice(Varien_Event_Observer $observer)
351
+ {
352
+ $block = $observer->getEvent()->getBlock();
353
+ if ($block instanceof Mage_Adminhtml_Block_Sales_Order_Invoice_Create_Items) {
354
+ $invoice = $block->getInvoice();
355
+ if ($invoice->getBaseGrandTotal() <= 0.01
356
+ && $invoice->getOrder()->getPayment()->getMethodInstance() instanceof
357
+ Netresearch_OPS_Model_Payment_Abstract
358
+ ) {
359
+ $invoice->getOrder()->getPayment()->getMethodInstance()->setCanCapture(false);
360
+ }
361
+ }
362
+
363
+ return $this;
364
+ }
365
+
366
+
367
+ /**
368
+ * @param $requestParams
369
+ *
370
+ * @throws Mage_Core_Exception
371
+ * @return Netresearch_OPS_Model_Observer
372
+ */
373
+ protected function invokeRequestParamValidation($requestParams)
374
+ {
375
+ $validator = Mage::getModel('ops/validator_parameter_factory')->getValidatorFor(
376
+ Netresearch_OPS_Model_Validator_Parameter_Factory::TYPE_REQUEST_PARAMS_VALIDATION
377
+ );
378
+ if (false == $validator->isValid($requestParams)) {
379
+ $this->getOnepage()->getCheckout()->setGotoSection('payment');
380
+ Mage::throwException(
381
+ $this->getHelper()->__('The data you have provided can not be processed by Ingenico Payment Services')
382
+ );
383
+ }
384
+
385
+ return $this;
386
+ }
387
+
388
+
389
+ /**
390
+ * @event sales_order_save_before
391
+ * @param Varien_Event_Observer $observer
392
+ * @return Netresearch_OPS_Model_Observer
393
+ */
394
+ public function checkForOpsStatus(Varien_Event_Observer $observer)
395
+ {
396
+ if ($this->getConfig()->getStateRestriction() == 1) {
397
+ $order = $observer->getOrder();
398
+ $origData = $order->getOrigData();
399
+ if (is_array($origData)
400
+ && array_key_exists('status', $origData)
401
+ && $order->getStatus() != $origData['status']
402
+ && $order->getPayment()->getMethodInstance() instanceof Netresearch_OPS_Model_Payment_Abstract
403
+ && Mage::helper('ops/data')->isAdminSession()
404
+ ) {
405
+ Mage::helper('ops/order')
406
+ ->checkForOpsStateOnStatusUpdate($order);
407
+ }
408
+ }
409
+ return $this;
410
+ }
411
+
412
+ /**
413
+ * validates the input fields after the payment step in OPC
414
+ *
415
+ * @event controller_action_postdispatch_checkout_onepage_savePayment
416
+ * @param Varien_Event_Observer $event
417
+ *
418
+ * @return $this
419
+ */
420
+ public function controllerActionCheckoutOnepagePostdispatch(Varien_Event_Observer $event)
421
+ {
422
+ $controller = $event->getControllerAction();
423
+ $quote = $this->getOnepage()->getQuote();
424
+ if ($quote->getPayment()->getMethodInstance() instanceof Netresearch_OPS_Model_Payment_Abstract) {
425
+ $paramHelper = Mage::helper('ops/payment_request');
426
+ $shippingParams = array();
427
+ $billingParams = $paramHelper->getOwnerParams($quote, $quote->getBillingAddress());
428
+ if ($quote->getShippingAddress()) {
429
+ $shippingParams = $paramHelper->extractShipToParameters($quote->getShippingAddress(), $quote);
430
+ }
431
+ $params = array_merge($billingParams, $shippingParams);
432
+ $validator = Mage::getModel('ops/validator_parameter_factory')->getValidatorFor(
433
+ Netresearch_OPS_Model_Validator_Parameter_Factory::TYPE_REQUEST_PARAMS_VALIDATION
434
+ );
435
+ if (false == $validator->isValid($params)) {
436
+ $result = Mage::helper('ops/validation_result')->getValidationFailedResult(
437
+ $validator->getMessages(),
438
+ $quote
439
+ );
440
+ $controller->getResponse()->setBody(Mage::helper('core/data')->jsonEncode($result));
441
+ }
442
+ }
443
+
444
+ return $this;
445
+ }
446
+
447
+
448
+ public function salesOrderPaymentCapture(Varien_Event_Observer $event)
449
+ {
450
+ /** @var $payment Mage_Sales_Model_Order_Payment */
451
+ $payment = $event->getPayment();
452
+ $invoice = $event->getInvoice();
453
+ if ($payment->getMethodInstance() instanceof Netresearch_OPS_Model_Payment_Abstract) {
454
+ $payment->setInvoice($invoice);
455
+ }
456
+
457
+
458
+ return $this;
459
+ }
460
+
461
+ /**
462
+ * @event core_block_abstract_to_html_after
463
+ * @param Varien_Event_Observer $event
464
+ * @return Netresearch_OPS_Model_Observer
465
+ */
466
+ public function appendPartialCaptureWarningForOpenInvoice(Varien_Event_Observer $event)
467
+ {
468
+ $block = $event->getBlock();
469
+ if ($block instanceof Mage_Adminhtml_Block_Sales_Order_Invoice_Totals
470
+ && $block->getInvoice()->getOrder()->getPayment()->getMethodInstance() instanceof Netresearch_OPS_Model_Payment_OpenInvoice_Abstract
471
+ && $block->getInvoice()->getOrder()->getPayment()->getMethodInstance()->canCapturePartial() === true
472
+ ) {
473
+ $transport = $event->getTransport();
474
+ $layout = $block->getLayout();
475
+ $html = $transport->getHtml();
476
+ $warningHtml = $layout->createBlock(
477
+ 'ops/adminhtml_sales_order_invoice_warning_openInvoice',
478
+ 'ops_invoice-openInvoice-warning'
479
+ )
480
+ ->renderView();
481
+ $html = $html . $warningHtml ;
482
+ $transport->setHtml($html);
483
+ }
484
+
485
+ return $this;
486
+ }
487
+
488
+ /**
489
+ * resets the order status back to pending payment in case of direct debits nl with order id as merchant ref
490
+ * @event sales_order_payment_place_end
491
+ * @param Varien_Event_Observer $event
492
+ */
493
+ public function setOrderStateForDirectDebitsNl(Varien_Event_Observer $event)
494
+ {
495
+ $payment = $event->getPayment();
496
+ if ($payment->getMethodInstance() instanceof Netresearch_OPS_Model_Payment_DirectDebit
497
+ && Mage::helper('ops/payment')->isInlinePaymentWithOrderId($payment)
498
+ && $payment->getAdditionalInformation('PM') == 'Direct Debits NL'
499
+ && $payment->getAdditionalInformation('STATUS') == Netresearch_OPS_Model_Payment_Abstract::OPS_AUTHORIZED_WAITING
500
+ ) {
501
+ $payment->getOrder()->setStatus(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT);
502
+ $payment->getOrder()->setState(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT);
503
+ }
504
+ }
505
+
506
+ /**
507
+ *
508
+ * @event core_block_abstract_to_html_after
509
+ * @param Varien_Event_Observer $event
510
+ * @return string
511
+ */
512
+ public function appendWarningToRefundFormForOpenInvoiceNl(Varien_Event_Observer $event)
513
+ {
514
+ $html = '';
515
+ if ($event->getBlock() instanceof Mage_Adminhtml_Block_Sales_Order_Creditmemo_Totals
516
+ && $event->getBlock()->getParentBlock()
517
+ instanceof Mage_Adminhtml_Block_Sales_Order_Creditmemo_Create_Items
518
+ && $event->getBlock()->getParentBlock()->getCreditmemo()->getOrder()->getPayment()
519
+ && $event->getBlock()->getParentBlock()->getCreditmemo()->getOrder()->getPayment()->getMethodInstance()
520
+ instanceof Netresearch_OPS_Model_Payment_OpenInvoiceNl
521
+ && $event->getBlock()->getParentBlock()->getCreditmemo()->canRefund()
522
+ && $event->getBlock()->getParentBlock()->getCreditmemo()->getInvoice()
523
+ && $event->getBlock()->getParentBlock()->getCreditmemo()->getInvoice()->getTransactionId()
524
+ ) {
525
+ $transport = $event->getTransport();
526
+ $block = $event->getBlock();
527
+ $layout = $block->getLayout();
528
+ $html = $transport->getHtml();
529
+ $warningHtml = $layout->createBlock(
530
+ 'ops/adminhtml_sales_order_creditmemo_warning_openInvoiceNl',
531
+ 'ops_openinvoice-warning'
532
+ )
533
+ ->renderView();
534
+ $html = $warningHtml . $html;
535
+ $transport->setHtml($html);
536
+ }
537
+ return $html;
538
+ }
539
+
540
+ /**
541
+ * appends the resend payment info button to the order's button in case it's an Ingenico Payment Services payment
542
+ * and the payment status is an authorize status
543
+ *
544
+ * @event core_block_abstract_prepare_layout_before
545
+ * @param Varien_Event_Observer $observer
546
+ * @return $this
547
+ */
548
+ public function addResendPaymentInfoButtonToOrderView(Varien_Event_Observer $observer)
549
+ {
550
+ $block = $observer->getBlock();
551
+ if ($block instanceof Mage_Adminhtml_Block_Sales_Order_View) {
552
+ $payment = $block->getOrder()->getPayment();
553
+ $paymentMethod = $payment->getMethodInstance();
554
+ if ($paymentMethod instanceof Netresearch_OPS_Model_Payment_Abstract
555
+ && Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/invoice')
556
+ && is_array($payment->getAdditionalInformation())
557
+ && array_key_exists('status', $payment->getAdditionalInformation())
558
+ && $this->getHelper('payment')->isPaymentFailed($payment->getAdditionalInformation('status'))) {
559
+ $block->addButton('ops_resend_info', array(
560
+ 'label' => Mage::helper('ops/data')->__('Resend payment information'),
561
+ 'onclick' => 'setLocation(\'' . $block->getUrl('adminhtml/admin/resendInfo') . '\')'));
562
+ }
563
+ }
564
+
565
+ return $this;
566
+ }
567
+ }
app/code/community/Netresearch/OPS/Model/Payment/Abstract.php ADDED
@@ -0,0 +1,1069 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Netresearch_OPS
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**OPS_PAYMENT_PROCESSING
28
+ * OPS payment method model
29
+ */
30
+ class Netresearch_OPS_Model_Payment_Abstract extends Mage_Payment_Model_Method_Abstract
31
+ {
32
+ protected $_code = 'ops';
33
+ protected $_formBlockType = 'ops/form';
34
+ protected $_infoBlockType = 'ops/info';
35
+ protected $_config = null;
36
+ protected $requestHelper = null;
37
+ protected $backendOperationParameterModel = null;
38
+
39
+ /**
40
+ * @param null $backendOperationParameterModel
41
+ */
42
+ public function setBackendOperationParameterModel($backendOperationParameterModel)
43
+ {
44
+ $this->backendOperationParameterModel = $backendOperationParameterModel;
45
+ }
46
+
47
+ /**
48
+ * @return Netresearch_OPS_Model_Backend_Operation_Parameter
49
+ */
50
+ public function getBackendOperationParameterModel()
51
+ {
52
+ if (null === $this->backendOperationParameterModel) {
53
+ $this->backendOperationParameterModel = Mage::getModel('ops/backend_operation_parameter');
54
+ }
55
+ return $this->backendOperationParameterModel;
56
+ }
57
+
58
+ /**
59
+ * Magento Payment Behaviour Settings
60
+ */
61
+ protected $_isGateway = false;
62
+ protected $_canAuthorize = true;
63
+ protected $_canCapture = true;
64
+ protected $_canCapturePartial = true;
65
+ protected $_canRefund = true;
66
+ protected $_canRefundInvoicePartial = true;
67
+ protected $_canVoid = true;
68
+ protected $_canUseInternal = false;
69
+ protected $_canUseCheckout = true;
70
+ protected $_canUseForMultishipping = false;
71
+ protected $_isInitializeNeeded = true;
72
+
73
+ /**
74
+ * OPS behaviour settings
75
+ */
76
+
77
+ protected $_needsCartDataForRequest = false;
78
+
79
+
80
+ protected $_needsShipToParams = true;
81
+
82
+ protected $_needsBillToParams = false;
83
+
84
+ /**
85
+ * OPS template modes
86
+ */
87
+ const TEMPLATE_OPS = 'ops';
88
+ const TEMPLATE_MAGENTO = 'magento';
89
+
90
+ /**
91
+ * redirect references
92
+ */
93
+
94
+ const REFERENCE_QUOTE_ID = 'quoteId';
95
+ const REFERENCE_ORDER_ID = 'orderId';
96
+
97
+ /**
98
+ * OPS response status
99
+ */
100
+ const OPS_INVALID = 0;
101
+ const OPS_PAYMENT_CANCELED_BY_CUSTOMER = 1;
102
+ const OPS_AUTH_REFUSED = 2;
103
+
104
+ const OPS_ORDER_SAVED = 4;
105
+ const OPS_AWAIT_CUSTOMER_PAYMENT = 41;
106
+ const OPS_OPEN_INVOICE_DE_PROCESSED = 41000001;
107
+ const OPS_WAITING_FOR_IDENTIFICATION = 46;
108
+
109
+ const OPS_AUTHORIZED = 5;
110
+ const OPS_AUTHORIZED_KWIXO = 50;
111
+ const OPS_AUTHORIZED_WAITING = 51;
112
+ const OPS_AUTHORIZED_UNKNOWN = 52;
113
+ const OPS_STAND_BY = 55;
114
+ const OPS_PAYMENTS_SCHEDULED = 56;
115
+ const OPS_AUTHORIZED_TO_GET_MANUALLY = 59;
116
+
117
+ const OPS_VOIDED = 6;
118
+ const OPS_VOID_WAITING = 61;
119
+ const OPS_VOID_UNCERTAIN = 62;
120
+ const OPS_VOID_REFUSED = 63;
121
+ const OPS_VOIDED_ACCEPTED = 64;
122
+
123
+ const OPS_PAYMENT_DELETED = 7;
124
+ const OPS_PAYMENT_DELETED_WAITING = 71;
125
+ const OPS_PAYMENT_DELETED_UNCERTAIN = 72;
126
+ const OPS_PAYMENT_DELETED_REFUSED = 73;
127
+ const OPS_PAYMENT_DELETED_OK = 74;
128
+ const OPS_PAYMENT_DELETED_PROCESSED_MERCHANT = 75;
129
+
130
+ const OPS_REFUNDED = 8;
131
+ const OPS_REFUND_WAITING = 81;
132
+ const OPS_REFUND_UNCERTAIN_STATUS = 82;
133
+ const OPS_REFUND_REFUSED = 83;
134
+ const OPS_REFUND_DECLINED_ACQUIRER = 84;
135
+ const OPS_REFUND_PROCESSED_MERCHANT = 85;
136
+
137
+ const OPS_PAYMENT_REQUESTED = 9;
138
+ const OPS_PAYMENT_PROCESSING = 91;
139
+ const OPS_PAYMENT_UNCERTAIN = 92;
140
+ const OPS_PAYMENT_REFUSED = 93;
141
+ const OPS_PAYMENT_DECLINED_ACQUIRER = 94;
142
+ const OPS_PAYMENT_PROCESSED_MERCHANT = 95;
143
+ const OPS_PAYMENT_IN_PROGRESS = 99;
144
+
145
+ /**
146
+ * Layout of the payment method
147
+ */
148
+ const PMLIST_HORIZONTAL_LEFT = 0;
149
+ const PMLIST_HORIZONTAL = 1;
150
+ const PMLIST_VERTICAL = 2;
151
+
152
+ /**
153
+ * OPS payment action constant
154
+ */
155
+ const OPS_AUTHORIZE_ACTION = 'RES';
156
+ const OPS_AUTHORIZE_CAPTURE_ACTION = 'SAL';
157
+ const OPS_CAPTURE_FULL = 'SAS';
158
+ const OPS_CAPTURE_PARTIAL = 'SAL';
159
+ const OPS_CAPTURE_DIRECTDEBIT_NL = 'VEN';
160
+ const OPS_DELETE_AUTHORIZE = 'DEL';
161
+ const OPS_DELETE_AUTHORIZE_AND_CLOSE = 'DES';
162
+ const OPS_REFUND_FULL = 'RFS';
163
+ const OPS_REFUND_PARTIAL = 'RFD';
164
+
165
+ /**
166
+ * 3D-Secure
167
+ */
168
+ const OPS_DIRECTLINK_WIN3DS = 'MAINW';
169
+
170
+ /**
171
+ * Module Transaction Type Codes
172
+ */
173
+ const OPS_CAPTURE_TRANSACTION_TYPE = 'capture';
174
+ const OPS_VOID_TRANSACTION_TYPE = 'void';
175
+ const OPS_REFUND_TRANSACTION_TYPE = 'refund';
176
+ const OPS_DELETE_TRANSACTION_TYPE = 'delete';
177
+
178
+ /**
179
+ * Return OPS Config
180
+ *
181
+ * @return Netresearch_OPS_Model_Config
182
+ */
183
+ public function getConfig()
184
+ {
185
+ if (is_null($this->_config)) {
186
+ $this->_config = Mage::getSingleton('ops/config');
187
+ }
188
+
189
+ return $this->_config;
190
+ }
191
+
192
+ /**
193
+ * return if shipment params are needed for request
194
+ *
195
+ * @return bool
196
+ */
197
+ public function getNeedsShipToParams()
198
+ {
199
+ return $this->_needsShipToParams;
200
+ }
201
+
202
+ /**
203
+ * return if billing params are needed for request
204
+ *
205
+ * @return bool
206
+ */
207
+ public function getNeedsBillToParams()
208
+ {
209
+ return $this->_needsBillToParams;
210
+ }
211
+
212
+ /**
213
+ * returns the request helper
214
+ *
215
+ * @return Netresearch_OPS_Helper_Payment_Request
216
+ */
217
+ public function getRequestHelper()
218
+ {
219
+ if (null === $this->requestHelper) {
220
+ $this->requestHelper = Mage::helper('ops/payment_request');
221
+ }
222
+
223
+ return $this->requestHelper;
224
+ }
225
+
226
+ /**
227
+ * if payment method is available
228
+ *
229
+ * @param Mage_Sales_Model_Quote $quote
230
+ * @return boolean
231
+ */
232
+ public function isAvailable($quote = null)
233
+ {
234
+
235
+ $storeId = 0;
236
+ // allow multi store/site for backend orders with disabled backend payment methods in default store
237
+ if (!is_null($quote) && !is_null($quote->getId())) {
238
+ $storeId = $quote->getStoreId();
239
+ }
240
+ if (Mage_Core_Model_App::ADMIN_STORE_ID == Mage::app()->getStore()->getId()
241
+ && false == $this->isEnabledForBackend($storeId)
242
+ ) {
243
+ return false;
244
+ }
245
+
246
+ return parent::isAvailable($quote);
247
+ }
248
+
249
+ /**
250
+ * if method is enabled for backend payments
251
+ *
252
+ * @return bool
253
+ */
254
+ public function isEnabledForBackend($storeId = 0)
255
+ {
256
+ return $this->getConfig()->isEnabledForBackend($this->_code, $storeId);
257
+ }
258
+
259
+ /**
260
+ * Redirect url to ops submit form
261
+ *
262
+ * @return string
263
+ */
264
+ public function getOrderPlaceRedirectUrl()
265
+ {
266
+ return $this->getConfig()->getPaymentRedirectUrl();
267
+ }
268
+
269
+ protected function getPayment()
270
+ {
271
+ $checkout = Mage::getSingleton('checkout/session');
272
+ $payment = $checkout->getQuote()->getPayment();
273
+ if (!$payment->getId()) {
274
+ $payment = Mage::getModel('sales/order')->loadByIncrementId($checkout->getLastRealOrderId())->getPayment();
275
+ }
276
+ return $payment;
277
+ }
278
+
279
+ public function getOpsBrand($payment=null)
280
+ {
281
+ if(is_null($payment)){
282
+ $payment = $this->getPayment();
283
+ }
284
+ return trim($payment->getAdditionalInformation('PM'));
285
+ }
286
+
287
+ public function getOpsCode($payment=null)
288
+ {
289
+ if(is_null($payment)){
290
+ $payment = $this->getPayment();
291
+ }
292
+ return trim($payment->getAdditionalInformation('BRAND'));
293
+ // return str_replace('ops_', '', $this->_code);
294
+ }
295
+
296
+ /**
297
+ * Return payment_action value from config area
298
+ *
299
+ * @return string
300
+ */
301
+ public function getPaymentAction()
302
+ {
303
+ return $this->getConfig()->getConfigData('payment_action');
304
+ }
305
+
306
+ public function getMethodDependendFormFields($order, $requestParams=null)
307
+ {
308
+ $billingAddress = $order->getBillingAddress();
309
+ $shippingAddress = $order->getShippingAddress();
310
+ if (null === $shippingAddress || false === $shippingAddress) {
311
+ $shippingAddress = $billingAddress;
312
+ }
313
+ $payment = $order->getPayment()->getMethodInstance();
314
+ $quote = Mage::helper('ops/order')->getQuote($order->getQuoteId());
315
+
316
+ $formFields = array();
317
+ $formFields['ORIG'] = Mage::helper("ops")->getModuleVersionString();
318
+ $formFields['BRAND'] = $payment->getOpsBrand($order->getPayment());
319
+ if ($this->getConfig()->canSubmitExtraParameter($order->getStoreId())) {
320
+ $formFields['CN'] = $billingAddress->getFirstname().' '.$billingAddress->getLastname();
321
+ $formFields['COM'] = $this->_getOrderDescription($order);
322
+ $formFields['ADDMATCH'] = Mage::helper('ops/order')->checkIfAddressesAreSame($order);
323
+ $ownerParams = $this->getRequestHelper()->getOwnerParams($quote, $billingAddress);
324
+ $formFields['ECOM_BILLTO_POSTAL_POSTALCODE'] = $billingAddress->getPostcode();
325
+ $formFields = array_merge($formFields, $ownerParams);
326
+ }
327
+
328
+ if (Mage::helper('customer/data')->isLoggedIn()) {
329
+ $formFields['CUID'] = Mage::helper('customer')->getCustomer()->getId();
330
+ }
331
+
332
+ return $formFields;
333
+ }
334
+
335
+ /**
336
+ * return ship to params if needed otherwise false
337
+ *
338
+ * @param $shippingAddress
339
+ *
340
+ * @return array|bool
341
+ */
342
+ public function getShipToParams($shippingAddress)
343
+ {
344
+ $shipToParams = false;
345
+ if ($this->getNeedsShipToParams() && $this->getConfig()->canSubmitExtraParameter()) {
346
+ $shipToParams = $this->getRequestHelper()->extractShipToParameters($shippingAddress);
347
+
348
+ }
349
+
350
+ return $shipToParams;
351
+ }
352
+
353
+ /**
354
+ * return ship to params if needed otherwise false
355
+ *
356
+ * @param $billingAddress
357
+ *
358
+ * @return array|bool
359
+ */
360
+ public function getBillToParams($billingAddress)
361
+ {
362
+ $billToParams = false;
363
+ if ($this->getNeedsBillToParams() && $this->getConfig()->canSubmitExtraParameter()) {
364
+ $billToParams = $this->getRequestHelper()->extractBillToParameters($billingAddress);
365
+
366
+ }
367
+
368
+ return $billToParams;
369
+ }
370
+
371
+ /**
372
+ * Prepare params array to send it to gateway page via POST
373
+ *
374
+ * @param Mage_Sales_Model_Order
375
+ * @param array
376
+ * @return array
377
+ */
378
+ public function getFormFields($order, $requestParams, $isRequest = true)
379
+ {
380
+ if (empty($order)) {
381
+ if (!($order = $this->getOrder())) {
382
+ return array();
383
+ }
384
+ }
385
+
386
+ // get mandatory parameters
387
+ $formFields = $this->getMandatoryFormFields($order);
388
+
389
+ // get method specific parameters
390
+ $methodDependendFields = $this->getMethodDependendFormFields($order, $requestParams);
391
+ if (is_array($methodDependendFields)) {
392
+ $formFields = array_merge($formFields, $methodDependendFields);
393
+ }
394
+
395
+ if ($this->getConfig()->getConfigData('template')=='ops') {
396
+ $formFields['TP']= '';
397
+ $formFields['PMLISTTYPE'] = $this->getConfig()->getConfigData('pmlist');
398
+ } else {
399
+ $formFields['TP']= $this->getConfig()->getPayPageTemplate();
400
+ }
401
+ $formFields['TITLE'] = $this->getConfig()->getConfigData('html_title');
402
+ $formFields['BGCOLOR'] = $this->getConfig()->getConfigData('bgcolor');
403
+ $formFields['TXTCOLOR'] = $this->getConfig()->getConfigData('txtcolor');
404
+ $formFields['TBLBGCOLOR'] = $this->getConfig()->getConfigData('tblbgcolor');
405
+ $formFields['TBLTXTCOLOR'] = $this->getConfig()->getConfigData('tbltxtcolor');
406
+ $formFields['BUTTONBGCOLOR'] = $this->getConfig()->getConfigData('buttonbgcolor');
407
+ $formFields['BUTTONTXTCOLOR'] = $this->getConfig()->getConfigData('buttontxtcolor');
408
+ $formFields['FONTTYPE'] = $this->getConfig()->getConfigData('fonttype');
409
+ $formFields['LOGO'] = $this->getConfig()->getConfigData('logo');
410
+ $formFields['HOMEURL'] = $this->getConfig()->hasHomeUrl() ? $this->getConfig()->getContinueUrl(array('redirect' => 'home')) : 'NONE';
411
+ $formFields['CATALOGURL'] = $this->getConfig()->hasCatalogUrl() ? $this->getConfig()->getContinueUrl(array('redirect' => 'catalog')) : '';
412
+ $formFields['ACCEPTURL'] = $this->getConfig()->getAcceptUrl();
413
+ $formFields['DECLINEURL'] = $this->getConfig()->getDeclineUrl();
414
+ $formFields['EXCEPTIONURL'] = $this->getConfig()->getExceptionUrl();
415
+ $formFields['CANCELURL'] = $this->getConfig()->getCancelUrl();
416
+ $formFields['BACKURL'] = $this->getConfig()->getCancelUrl();
417
+
418
+ /** @var $order Mage_Sales_Model_Order */
419
+ $shipToFormFields = $this->getShipToParams($order->getShippingAddress());
420
+ if (is_array($shipToFormFields)) {
421
+ $formFields = array_merge($formFields, $shipToFormFields);
422
+ }
423
+
424
+ $billToFormFields = $this->getBillToParams($order->getBillingAddress());
425
+ if (is_array($billToFormFields)) {
426
+ $formFields = array_merge($formFields, $billToFormFields);
427
+ }
428
+
429
+ $shaSign = Mage::helper('ops/payment')->shaCrypt(Mage::helper('ops/payment')->getSHASign($formFields, null, $order->getStoreId()));
430
+
431
+ if($isRequest){
432
+ $helper = Mage::helper('ops');
433
+ $helper->log($helper->__("Register Order %s in Ingenico Payment Services \n\nAll form fields: %s\nIngenico Payment Services String to hash: %s\nHash: %s",
434
+ $order->getIncrementId(),
435
+ serialize($formFields),
436
+ Mage::helper('ops/payment')->getSHASign($formFields, null, $order->getStoreId()),
437
+ $shaSign
438
+ ));
439
+ }
440
+
441
+ $formFields['SHASIGN'] = $shaSign;
442
+
443
+ return $formFields;
444
+ }
445
+
446
+ /**
447
+ * Get OPS Payment Action value
448
+ *
449
+ * @param string
450
+ * @return string
451
+ */
452
+ protected function _getOPSPaymentOperation()
453
+ {
454
+ $value = $this->getPaymentAction();
455
+ if ($value==Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE) {
456
+ $value = self::OPS_AUTHORIZE_ACTION;
457
+ } elseif ($value==Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE_CAPTURE) {
458
+ $value = self::OPS_AUTHORIZE_CAPTURE_ACTION;
459
+ }
460
+ return $value;
461
+ }
462
+
463
+
464
+ protected function convertToLatin1($StringToConvert)
465
+ {
466
+ $returnString = '';
467
+ $chars = str_split($StringToConvert);
468
+ foreach ($chars as $char) {
469
+ if (31 < ord($char) && ord($char) < 127) {
470
+ $returnString .= $char;
471
+ }
472
+ }
473
+ return $returnString;
474
+ }
475
+
476
+ /**
477
+ * get formated order description
478
+ *
479
+ * @param Mage_Sales_Model_Order
480
+ * @return string
481
+ */
482
+ public function _getOrderDescription($order)
483
+ {
484
+ $descriptionItems = array();
485
+ $description = '';
486
+ $lengs = 0;
487
+ foreach ($order->getAllItems() as $item) {
488
+ if ($item->getParentItem()) continue;
489
+ // we know that Ingenico Payment Services is not able to handle characters that are not available in iso-8859-1
490
+ // $descriptionItems[] = mb_ereg_replace("[^a-zA-Z0-9äáàéèíóöõúüûÄÁÀÉÍÓÖÕÚÜÛ_ ]" , "" , $item->getName());
491
+ $descriptionItems[] = $this->convertToLatin1($item->getName());
492
+ $description = Mage::helper('core/string')->substr(implode(', ', $descriptionItems), 0, 100);
493
+ //COM field is limited to 100 chars max
494
+ if (100 <= Mage::helper('core/string')->strlen($description)) {
495
+ break;
496
+ }
497
+ }
498
+ return $description;
499
+ }
500
+
501
+ /**
502
+ * Get Main OPS Helper
503
+ *
504
+ * @return Netresearch_OPS_Helper_Data
505
+ */
506
+ public function getHelper()
507
+ {
508
+ return Mage::helper('ops/data');
509
+ }
510
+
511
+ /**
512
+ * Determines if a capture will be processed
513
+ *
514
+ * @param Varien_Object $payment
515
+ * @param float $amount
516
+ * @throws Mage_Core_Exception
517
+ * @return \Mage_Payment_Model_Abstract|void
518
+ */
519
+ public function capture(Varien_Object $payment, $amount)
520
+ {
521
+ // disallow Ingenico Payment Services online capture if amount is zero
522
+ if ($amount < 0.01) {
523
+ return parent::capture($payment, $amount);
524
+ }
525
+
526
+ if (true === Mage::registry('ops_auto_capture')) {
527
+ Mage::unregister('ops_auto_capture');
528
+ return parent::capture($payment, $amount);
529
+ }
530
+
531
+ $orderId = $payment->getOrder()->getId();
532
+ $arrInfo = Mage::helper('ops/order_capture')->prepareOperation($payment, $amount);
533
+ $storeId = $payment->getOrder()->getStoreId();
534
+
535
+ if ($this->isRedirectNoticed($orderId)) {
536
+ return $this;
537
+ }
538
+ try {
539
+ $requestParams = $this->getBackendOperationParameterModel()->getParameterFor(
540
+ self::OPS_CAPTURE_TRANSACTION_TYPE,
541
+ $this,
542
+ $payment,
543
+ $amount,
544
+ $arrInfo
545
+ );
546
+ $response = Mage::getSingleton('ops/api_directlink')->performRequest(
547
+ $requestParams,
548
+ Mage::getModel('ops/config')->getDirectLinkGatewayPath($storeId),
549
+ $storeId
550
+ );
551
+ Mage::helper('ops/payment')->saveOpsStatusToPayment($payment, $response);
552
+
553
+ if ($response['STATUS'] == self::OPS_PAYMENT_PROCESSING ||
554
+ $response['STATUS'] == self::OPS_PAYMENT_UNCERTAIN ||
555
+ $response['STATUS'] == self::OPS_PAYMENT_IN_PROGRESS
556
+ ) {
557
+ Mage::helper('ops/directlink')->directLinkTransact(
558
+ Mage::getSingleton("sales/order")->loadByIncrementId($payment->getOrder()->getIncrementId()),
559
+ $response['PAYID'],
560
+ $response['PAYIDSUB'],
561
+ $arrInfo,
562
+ self::OPS_CAPTURE_TRANSACTION_TYPE,
563
+ $this->getHelper()->__('Start Ingenico Payment Services %s capture request',$arrInfo['type']));
564
+ $order = Mage::getModel('sales/order')->load($orderId); //Reload order to avoid wrong status
565
+ $order->addStatusHistoryComment(
566
+ Mage::helper('ops')->__(
567
+ 'Invoice will be created automatically as soon as Ingenico Payment Services sends an acknowledgement. Ingenico Payment Services status: %s.',
568
+ Mage::helper('ops')->getStatusText($response['STATUS'])
569
+ )
570
+ );
571
+ $order->save();
572
+ $this->getHelper()->redirectNoticed(
573
+ $orderId,
574
+ $this->getHelper()->__(
575
+ 'Invoice will be created automatically as soon as Ingenico Payment Services sends an acknowledgement. Ingenico Payment Services status: %s.',
576
+ Mage::helper('ops')->getStatusText($response['STATUS'])
577
+ )
578
+ );
579
+ return $this;
580
+ }
581
+ elseif ($response['STATUS'] == self::OPS_PAYMENT_PROCESSED_MERCHANT || $response['STATUS'] == self::OPS_PAYMENT_REQUESTED) {
582
+ return parent::capture($payment, $amount);
583
+ } else{
584
+ Mage::throwException(
585
+ $this->getHelper()->__(
586
+ 'The Invoice was not created. Ingenico Payment Services status: %s.',
587
+ Mage::helper('ops')->getStatusText($response['STATUS'])
588
+ )
589
+ );
590
+ }
591
+ }
592
+ catch (Exception $e){
593
+ Mage::getModel('ops/status_update')->updateStatusFor($payment->getOrder());
594
+ Mage::helper('ops')->log("Exception in capture request:".$e->getMessage());
595
+ throw new Mage_Core_Exception($e->getMessage());
596
+ }
597
+ }
598
+
599
+
600
+ /**
601
+ * Refund
602
+ *
603
+ * @param Varien_Object $payment
604
+ * @param float $amount
605
+ * @return \Mage_Payment_Model_Abstract|void
606
+ */
607
+ public function refund(Varien_Object $payment, $amount)
608
+ {
609
+ //If the refund will be created by OPS, Refund Create Method to nothing
610
+ if (true === Mage::registry('ops_auto_creditmemo')) {
611
+ Mage::unregister('ops_auto_creditmemo');
612
+ return parent::refund($payment, $amount);
613
+ }
614
+
615
+ $refundHelper = Mage::helper('ops/order_refund')->setAmount($amount)->setPayment($payment);
616
+ $arrInfo = $refundHelper->prepareOperation($payment, $amount);
617
+ $storeId = $payment->getOrder()->getStoreId();
618
+ $operation = $arrInfo['operation'];
619
+
620
+ try {
621
+ $requestParams = $this->getBackendOperationParameterModel()->getParameterFor(
622
+ self::OPS_REFUND_TRANSACTION_TYPE,
623
+ $this,
624
+ $payment,
625
+ $amount,
626
+ $arrInfo
627
+ );
628
+ $response = Mage::getSingleton('ops/api_directlink')->performRequest(
629
+ $requestParams,
630
+ Mage::getModel('ops/config')->getDirectLinkGatewayPath($storeId),
631
+ $storeId
632
+ );
633
+ Mage::helper('ops/payment')->saveOpsStatusToPayment($payment, $response);
634
+ if (($response['STATUS'] == self::OPS_REFUND_WAITING)
635
+ || ($response['STATUS'] == self::OPS_REFUND_UNCERTAIN_STATUS)) {
636
+ Mage::helper('ops/payment')->saveOpsRefundOperationCodeToPayment($payment, $operation);
637
+ $refundHelper->createRefundTransaction($response);
638
+
639
+ } elseif (($response['STATUS'] == self::OPS_REFUNDED)
640
+ || ($response['STATUS'] == self::OPS_REFUND_PROCESSED_MERCHANT)) {
641
+ //do refund directly if response is ok already
642
+ Mage::helper('ops/payment')->saveOpsRefundOperationCodeToPayment($payment, $operation);
643
+ $refundHelper->createRefundTransaction($response, 1);
644
+ return parent::refund($payment, $amount);
645
+ } else {
646
+ Mage::throwException($this->getHelper()->__('The CreditMemo was not created. Ingenico Payment Services status: %s.',$response['STATUS']));
647
+ }
648
+
649
+ Mage::getSingleton('core/session')->addNotice($this->getHelper()->__('The Creditmemo will be created automatically as soon as Ingenico Payment Services sends an acknowledgement.'));
650
+ $this->getHelper()->redirect(
651
+ Mage::getUrl('*/sales_order/view', array('order_id' => $payment->getOrder()->getId()))
652
+ );
653
+ }
654
+ catch (Exception $e) {
655
+ Mage::logException($e);
656
+ Mage::getModel('ops/status_update')->updateStatusFor($payment->getOrder());
657
+ Mage::throwException($e->getMessage());
658
+ }
659
+ }
660
+
661
+ /**
662
+ * Returns the mandatory fields for requests to Ingenico Payment Services
663
+ *
664
+ * @param Mage_Sales_Model_Order $order
665
+ * @return array
666
+ */
667
+ public function getMandatoryFormFields($order)
668
+ {
669
+ $formFields = Mage::helper('ops/payment_request')->getMandatoryRequestFields($order);
670
+ $paymentAction = $this->_getOPSPaymentOperation();
671
+ if ($paymentAction ) {
672
+ $formFields['OPERATION'] = $paymentAction;
673
+ }
674
+
675
+ return $formFields;
676
+ }
677
+
678
+ /**
679
+ * determines if the close transaction parameter is set in the credit memo data
680
+ *
681
+ * @param array $creditMemoData
682
+ *
683
+ * @return bool
684
+ */
685
+ protected function getCloseTransactionFromCreditMemoData($creditMemoData)
686
+ {
687
+ $closeTransaction = false;
688
+ if (array_key_exists('ops_close_transaction', $creditMemoData)
689
+ && strtolower(trim($creditMemoData['ops_close_transaction'])) == 'on') {
690
+ $closeTransaction = true;
691
+ }
692
+ return $closeTransaction;
693
+ }
694
+
695
+ /**
696
+ * Check refund availability
697
+ *
698
+ * @return bool
699
+ */
700
+ public function canRefund()
701
+ {
702
+ try {
703
+ $order = Mage::getModel('sales/order')->load(Mage::app()->getRequest()->getParam('order_id'));
704
+
705
+ // if Ingenico Payment Services transaction is closed then no online refund is possible
706
+ if ($order->getPayment()
707
+ && $order->getPayment()->getAdditionalInformation()
708
+ && array_key_exists('canRefund', $order->getPayment()->getAdditionalInformation())
709
+ && false === $order->getPayment()->getAdditionalInformation('canRefund')
710
+ ) {
711
+ return false;
712
+ }
713
+
714
+ if (false === Mage::helper('ops/directlink')->hasPaymentTransactions($order,self::OPS_REFUND_TRANSACTION_TYPE)) {
715
+ return $this->_canRefund;
716
+ } else {
717
+ //Add the notice if no exception was thrown, because in this case there is one creditmemo in the transaction queue
718
+ Mage::getSingleton('core/session')->addNotice(
719
+ $this->getHelper()->__('There is already one creditmemo in the queue. The Creditmemo will be created automatically as soon as Ingenico Payment Services sends an acknowledgement.')
720
+ );
721
+ $this->getHelper()->redirect(
722
+ Mage::getUrl('*/sales_order/view', array('order_id' => $order->getId()))
723
+ );
724
+ }
725
+ } catch (Exception $e) {
726
+ Mage::getSingleton('core/session')->addError($e->getMessage());
727
+ return $this->_canRefund;
728
+ }
729
+ }
730
+
731
+ /**
732
+ * Custom cancel behavior, deny cancel and force custom to use void instead
733
+ *
734
+ * @param Varien_Object $payment
735
+ * @return void
736
+ * @throws Mage_Core_Exception
737
+ */
738
+ public function cancel(Varien_Object $payment)
739
+ {
740
+ /*
741
+ * Important: If an order was voided successfully and the user clicks on cancel in order-view
742
+ * this method is not triggered anymore
743
+ */
744
+
745
+ //Proceed parent cancel method in case that regirstry value ops_auto_void is set
746
+ if (true === Mage::registry('ops_auto_void')):
747
+ Mage::unregister('ops_auto_void');
748
+ return parent::cancel($payment);
749
+ endif;
750
+
751
+ //If order has state 'pending_payment' and the payment has Ingenico Payment Services-status 0 or null (unknown) then cancel the order
752
+ if (true === $this->canCancelManually($payment->getOrder())) {
753
+ $payment->getOrder()->addStatusHistoryComment(
754
+ $this->getHelper()->__("The order was cancelled manually. The Ingenico Payment Services-state is 0 or null.")
755
+ );
756
+ return parent::cancel($payment);
757
+ }
758
+
759
+ //Abort cancel method by throwing a Mage_Core_Exception
760
+ throw new Mage_Core_Exception($this->getHelper()->__('Please use void to cancel the operation.'));
761
+ }
762
+
763
+ /**
764
+ * Custom void behavior, trigger Ingenico Payment Services cancel request
765
+ *
766
+ * @param Varien_Object $payment
767
+ * @return void
768
+ * @throws Mage_Core_Exception
769
+ */
770
+ public function void(Varien_Object $payment)
771
+ {
772
+ //Proceed parent void method in case that registry value ops_auto_void is set
773
+ if (true === Mage::registry('ops_auto_void')) {
774
+ Mage::unregister('ops_auto_void');
775
+ return parent::void($payment);
776
+ }
777
+
778
+ //Set initital params
779
+ $params = Mage::app()->getRequest()->getParams();
780
+ $orderID = $payment->getOrder()->getId();
781
+ $order = Mage::getModel("sales/order")->load($orderID);
782
+
783
+ //Calculate amount which has to be captured
784
+ $alreadyCaptured = Mage::helper('ops/order_void')->getCapturedAmount(
785
+ $order
786
+ );
787
+ $grandTotal = Mage::helper('ops/payment')
788
+ ->getBaseGrandTotalFromSalesObject($order);
789
+ $voidAmount = $grandTotal - $alreadyCaptured;
790
+ $storeId = $order->getStoreId();
791
+ //Build void directLink-Request-Params
792
+ $requestParams = array(
793
+ 'AMOUNT' => $this->getHelper()->getAmount($voidAmount),
794
+ 'PAYID' => $payment->getAdditionalInformation('paymentId'),
795
+ 'OPERATION' => self::OPS_DELETE_AUTHORIZE,
796
+ 'CURRENCY' => Mage::app()->getStore($storeId)->getBaseCurrencyCode()
797
+ );
798
+
799
+ //Check if there is already a waiting void transaction, if yes: redirect to order view
800
+ if (Mage::helper('ops/directlink')->checkExistingTransact(
801
+ self::OPS_VOID_TRANSACTION_TYPE, $orderID
802
+ )
803
+ ) {
804
+ $this->getHelper()->redirectNoticed(
805
+ $orderID, $this->getHelper()->__(
806
+ 'You already sent a void request. Please wait until the void request will be acknowledged.'
807
+ )
808
+ );
809
+ return;
810
+ }
811
+
812
+ //Check if there is already a waiting capture transaction, if yes: redirect to order view
813
+ if (Mage::helper('ops/directlink')->checkExistingTransact(
814
+ self::OPS_CAPTURE_TRANSACTION_TYPE, $orderID
815
+ )
816
+ ) {
817
+ $this->getHelper()->redirectNoticed(
818
+ $orderID, $this->getHelper()->__(
819
+ 'There is one capture request waiting. Please wait until this request is acknowledged.'
820
+ )
821
+ );
822
+ return;
823
+ }
824
+
825
+ try {
826
+ //perform ops cancel request
827
+ $response = Mage::getSingleton('ops/api_directlink')
828
+ ->performRequest(
829
+ $requestParams,
830
+ Mage::getModel('ops/config')->getDirectLinkGatewayPath($storeId),
831
+ $order->getStoreId()
832
+ );
833
+
834
+ //Save ops response to payment transaction
835
+ Mage::helper('ops/payment')->saveOpsStatusToPayment(
836
+ $payment, $response
837
+ );
838
+
839
+ /*
840
+ * If the ops response results in a waiting or uncertain state, create a void transaction which is waiting
841
+ * for an asynchron directLink-postback
842
+ */
843
+ if ($response['STATUS'] == self::OPS_VOID_WAITING
844
+ || $response['STATUS'] == self::OPS_VOID_UNCERTAIN
845
+ ) {
846
+ Mage::helper('ops/directlink')->directLinkTransact(
847
+ Mage::getSingleton("sales/order")->loadByIncrementId(
848
+ $payment->getOrder()->getIncrementId()
849
+ ),
850
+ // reload order to avoid canceling order before confirmation from ops
851
+ $response['PAYID'],
852
+ $response['PAYIDSUB'],
853
+ array(
854
+ 'amount' => $voidAmount,
855
+ 'void_request' => Mage::app()->getRequest()->getParams(
856
+ ),
857
+ 'response' => $response,
858
+ ),
859
+ self::OPS_VOID_TRANSACTION_TYPE,
860
+ Mage::helper('ops')->__(
861
+ 'Start Ingenico Payment Services void request. Ingenico Payment Services status: %s.',
862
+ $this->getHelper()->getStatusText($response['STATUS'])
863
+ )
864
+ );
865
+ $this->getHelper()->redirectNoticed(
866
+ $orderID, $this->getHelper()->__(
867
+ 'The void request is sent. Please wait until the void request will be accepted.'
868
+ )
869
+ );
870
+ /*
871
+ * If the ops response results directly in accepted state, create a void transaction and execute parent void method
872
+ */
873
+ } elseif ($response['STATUS'] == self::OPS_VOIDED
874
+ || $response['STATUS'] == self::OPS_VOIDED_ACCEPTED
875
+ ) {
876
+ Mage::helper('ops/directlink')->directLinkTransact(
877
+ Mage::getSingleton("sales/order")->loadByIncrementId(
878
+ $payment->getOrder()->getIncrementId()
879
+ ),
880
+ // reload order to avoid canceling order before confirmation from ops
881
+ $response['PAYID'],
882
+ $response['PAYIDSUB'],
883
+ array(),
884
+ self::OPS_VOID_TRANSACTION_TYPE,
885
+ $this->getHelper()->__(
886
+ 'Void order succeed. Ingenico Payment Services status: %s.',
887
+ $response['STATUS']
888
+ ),
889
+ 1
890
+ );
891
+ return parent::void($payment);
892
+ } else {
893
+ Mage::getModel('ops/status_update')->updateStatusFor($payment->getOrder());
894
+ Mage::throwException(
895
+ $this->getHelper()->__(
896
+ 'Void order failed. Ingenico Payment Services status: %s.',
897
+ $response['STATUS']
898
+ )
899
+ );
900
+ }
901
+ ;
902
+ } catch (Exception $e) {
903
+ Mage::getModel('ops/status_update')->updateStatusFor($payment->getOrder());
904
+ Mage::helper('ops')->log(
905
+ "Exception in void request:" . $e->getMessage()
906
+ );
907
+ throw new Mage_Core_Exception($e->getMessage());
908
+ }
909
+ }
910
+
911
+
912
+ /**
913
+ * get question for fields with disputable value
914
+ * users are asked to correct the values before redirect to Ingenico Payment Services
915
+ *
916
+ * @param Mage_Sales_Model_Order $order Current order
917
+ * @param array $requestParams Request parameters
918
+ * @return string
919
+ */
920
+ public function getQuestion($order, $requestParams)
921
+ {
922
+ }
923
+
924
+ /**
925
+ * get an array of fields with disputable value
926
+ * users are asked to correct the values before redirect to Ingenico Payment Services
927
+ *
928
+ * @param Mage_Sales_Model_Order $order Current order
929
+ * @param array $requestParams Request parameters
930
+ * @return array
931
+ */
932
+ public function getQuestionedFormFields($quote, $requestParams)
933
+ {
934
+ return array();
935
+ }
936
+
937
+ /**
938
+ * if we need some missing form params
939
+ * users are asked to correct the values before redirect to Ingenico Payment Services
940
+ *
941
+ * @param Mage_Sales_Model_Order $order
942
+ * @param array $requestParams Parameters sent in current request
943
+ * @param array $formFields Parameters to be sent to Ingenico Payment Services
944
+ * @return bool
945
+ */
946
+ public function hasFormMissingParams($order, $requestParams, $formFields=null)
947
+ {
948
+ if (false == is_array($requestParams)) {
949
+ $requestParams = array();
950
+ }
951
+ if (is_null($formFields)) {
952
+ $formFields = $this->getFormFields($order, $requestParams, false);
953
+ }
954
+ $availableParams = array_merge($requestParams, $formFields);
955
+ $requiredParams = $this->getQuestionedFormFields($order, $requestParams);
956
+ foreach ($requiredParams as $requiredParam) {
957
+ if (false == array_key_exists($requiredParam, $availableParams)
958
+ || 0 == strlen($availableParams[$requiredParam])
959
+ ) {
960
+ return true;
961
+ }
962
+ }
963
+ return false;
964
+ }
965
+
966
+
967
+ /**
968
+ * Check if order can be cancelled manually
969
+ *
970
+ * @param Mage_Sales_Model_Order $order
971
+ * @return bool
972
+ */
973
+ public function canCancelManually($order)
974
+ {
975
+ $payment = $order->getPayment();
976
+
977
+ //If order has state 'pending_payment' and the payment has Ingenico Payment Services-status 0 or null (unknown) then cancel the order
978
+ if ($order->getState() == Mage_Sales_Model_Order::STATE_PENDING_PAYMENT
979
+ && (true === is_null($payment->getAdditionalInformation('status')) || ($payment->getAdditionalInformation('status') == '0'))) {
980
+ return true;
981
+ } else {
982
+ return false;
983
+ }
984
+ }
985
+
986
+ public function getOpsHtmlAnswer($payment=null)
987
+ {
988
+ $returnValue = '';
989
+ if (is_null($payment)) {
990
+ $quoteId = Mage::getSingleton('checkout/session')->getQuote()->getId();
991
+ if (is_null($quoteId)) {
992
+ $orderIncrementId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
993
+ $order = Mage::getModel('sales/order')->loadByAttribute('increment_id', $orderIncrementId);
994
+ } else {
995
+ $order = Mage::getModel('sales/order')->loadByAttribute('quote_id', $quoteId);
996
+ }
997
+ if ($order instanceof Mage_Sales_Model_Order && 0 < $order->getId()) {
998
+ $payment = $order->getPayment();
999
+ $returnValue = $payment->getAdditionalInformation('HTML_ANSWER');
1000
+ }
1001
+ } elseif ($payment instanceof Mage_Payment_Model_Info) {
1002
+ $returnValue = $payment->getAdditionalInformation('HTML_ANSWER');
1003
+ }
1004
+ return $returnValue;
1005
+ }
1006
+
1007
+ public function getShippingTaxRate($order)
1008
+ {
1009
+ return $this->getRequestHelper()->getShippingTaxRate($order);
1010
+ }
1011
+
1012
+
1013
+ protected function isRedirectNoticed($orderId)
1014
+ {
1015
+ if (Mage::helper('ops/directlink')->checkExistingTransact(self::OPS_CAPTURE_TRANSACTION_TYPE, $orderId)) {
1016
+ $this->getHelper()->redirectNoticed(
1017
+ $orderId,
1018
+ $this->getHelper()->__(
1019
+ 'You already sent a capture request. Please wait until the capture request is acknowledged.'
1020
+ )
1021
+ );
1022
+
1023
+ return true;
1024
+ }
1025
+ if (Mage::helper('ops/directlink')->checkExistingTransact(self::OPS_VOID_TRANSACTION_TYPE, $orderId)) {
1026
+ $this->getHelper()->redirectNoticed(
1027
+ $orderId,
1028
+ $this->getHelper()->__(
1029
+ 'There is one void request waiting. Please wait until this request is acknowledged.'
1030
+ )
1031
+ );
1032
+
1033
+ return true;
1034
+ }
1035
+ return false;
1036
+ }
1037
+
1038
+ public function setConfig(Netresearch_OPS_Model_Config $config)
1039
+ {
1040
+ $this->_config = $config;
1041
+ }
1042
+
1043
+ /**
1044
+ * If cart Item information has to be transmittet to Ingenico Payment Services
1045
+ *
1046
+ * @return bool
1047
+ */
1048
+
1049
+ public function needsOrderItemDataForRequest()
1050
+ {
1051
+ return $this->_needsCartDataForRequest;
1052
+ }
1053
+
1054
+ /**
1055
+ * Returns array with the order item data formatted in Ingenico Payment Services fashion if payment method implementation
1056
+ * needs the data otherwise just returns false.
1057
+ *
1058
+ * @param Mage_Sales_Model_Order $order
1059
+ * @return array|false
1060
+ */
1061
+ public function getOrderItemData(Mage_Sales_Model_Order $order)
1062
+ {
1063
+ if(!$this->needsOrderItemDataForRequest()){
1064
+ return false;
1065
+ }
1066
+
1067
+ return Mage::helper('ops/payment_request')->extractOrderItemParameters($order);
1068
+ }
1069
+ }
app/code/community/Netresearch/OPS/Model/Payment/Backend/OpsId.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Netresearch_OPS_Model_Payment_Backend_OpsId
4
+ *
5
+ * @package OPS
6
+ * @copyright 2012 Netresearch App Factory AG <http://www.netresearch.de>
7
+ * @author Thomas Birke <thomas.birke@netresearch.de>
8
+ * @license OSL 3.0
9
+ */
10
+ class Netresearch_OPS_Model_Payment_Backend_OpsId
11
+ extends Mage_Payment_Model_Method_Abstract
12
+ {
13
+ /* allow usage in Magento backend */
14
+ protected $_canUseInternal = true;
15
+
16
+ /* deny usage in Magento frontend */
17
+ protected $_canUseCheckout = false;
18
+
19
+ protected $_canBackendDirectCapture = true;
20
+
21
+ protected $_isGateway = false;
22
+ protected $_canAuthorize = false;
23
+ protected $_canCapture = true;
24
+ protected $_canCapturePartial = true;
25
+ protected $_canRefund = true;
26
+ protected $_canRefundInvoicePartial = true;
27
+ protected $_canVoid = true;
28
+
29
+ /** payment code */
30
+ protected $_code = 'ops_opsid';
31
+
32
+ protected $_formBlockType = 'ops/form_opsId';
33
+
34
+ protected $_infoBlockType = 'ops/info_opsId';
35
+ }
36
+
app/code/community/Netresearch/OPS/Model/Payment/BankTransfer.php ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Netresearch_OPS_Model_Payment_BankTransfer
4
+ *
5
+ * @package
6
+ * @copyright 2011 Netresearch
7
+ * @author Thomas Kappel <thomas.kappel@netresearch.de>
8
+ * @license OSL 3.0
9
+ */
10
+ class Netresearch_OPS_Model_Payment_BankTransfer
11
+ extends Netresearch_OPS_Model_Payment_Abstract
12
+ {
13
+ /** Check if we can capture directly from the backend */
14
+ protected $_canBackendDirectCapture = true;
15
+
16
+ /** info source path */
17
+ protected $_infoBlockType = 'ops/info_redirect';
18
+
19
+ /** payment code */
20
+ protected $_code = 'ops_bankTransfer';
21
+
22
+
23
+ /**
24
+ * Assign data to info model instance
25
+ *
26
+ * @param mixed $data
27
+ * @return Mage_Payment_Model_Info
28
+ */
29
+ public function assignData($data)
30
+ {
31
+ $countryId = '';
32
+ if (is_object($data) && $data instanceof Varien_Object) {
33
+ $countryId = $data->getCountryId();
34
+ } elseif (is_array($data) && isset($data['country_id'])) {
35
+ $countryId = $data['country_id'];
36
+ }
37
+ $pm = $brand = trim('Bank transfer' . (('*' == $countryId) ? '' : ' ' . $countryId));
38
+
39
+ $payment = Mage::getSingleton('checkout/session')->getQuote()->getPayment();
40
+ $payment->setAdditionalInformation('PM', $pm);
41
+ $payment->setAdditionalInformation('BRAND', $brand);
42
+
43
+ parent::assignData($data);
44
+ return $this;
45
+ }
46
+ }
app/code/community/Netresearch/OPS/Model/Payment/BelfiusDirectNet.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Netresearch_OPS_Model_Payment_DexiaDirectNet
4
+ *
5
+ * @package
6
+ * @copyright 2011 Netresearch
7
+ * @author Thomas Kappel <thomas.kappel@netresearch.de>
8
+ * @license OSL 3.0
9
+ */
10
+ class Netresearch_OPS_Model_Payment_BelfiusDirectNet
11
+ extends Netresearch_OPS_Model_Payment_Abstract
12
+ {
13
+ /** Check if we can capture directly from the backend */
14
+ protected $_canBackendDirectCapture = true;
15
+
16
+ /** info source path */
17
+ protected $_infoBlockType = 'ops/info_redirect';
18
+
19
+ /** payment code */
20
+ protected $_code = 'ops_belfiusDirectNet';
21
+
22
+ /** ops payment code */
23
+ public function getOpsCode($payment=null)
24
+ {
25
+ return 'Belfius Direct Net';
26
+ }
27
+ }
28
+
app/code/community/Netresearch/OPS/Model/Payment/CashU.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Netresearch_OPS_Model_Payment_CashU
4
+ *
5
+ * @package OPS
6
+ * @copyright 2012 Netresearch App Factory AG <http://www.netresearch.de>
7
+ * @author Thomas Kappel <thomas.kappel@netresearch.de>
8
+ * @license OSL 3.0
9
+ */
10
+ class Netresearch_OPS_Model_Payment_CashU
11
+ extends Netresearch_OPS_Model_Payment_Abstract
12
+ {
13
+ /** Check if we can capture directly from the backend */
14
+ protected $_canBackendDirectCapture = true;
15
+
16
+ /** info source path */
17
+ protected $_infoBlockType = 'ops/info_redirect';
18
+
19
+ /** payment code */
20
+ protected $_code = 'ops_cashU';
21
+ }
22
+
app/code/community/Netresearch/OPS/Model/Payment/CbcOnline.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Netresearch_OPS_Model_Payment_CbcOnline
4
+ *
5
+ * @package
6
+ * @copyright 2011 Netresearch
7
+ * @author Thomas Kappel <thomas.kappel@netresearch.de>
8
+ * @license OSL 3.0
9
+ */
10
+ class Netresearch_OPS_Model_Payment_CbcOnline
11
+ extends Netresearch_OPS_Model_Payment_Abstract
12
+ {
13
+ /** Check if we can capture directly from the backend */
14
+ protected $_canBackendDirectCapture = true;
15
+
16
+ /** info source path */
17
+ protected $_infoBlockType = 'ops/info_redirect';
18
+
19
+ /** payment code */
20
+ protected $_code = 'ops_cbcOnline';
21
+
22
+ /** ops payment code */
23
+ public function getOpsCode($payment=null)
24
+ {
25
+ return 'CBC Online';
26
+ }
27
+ }
28
+
app/code/community/Netresearch/OPS/Model/Payment/Cc.php ADDED
@@ -0,0 +1,271 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Netresearch_OPS_Model_Payment_Cc
5
+ *
6
+ * @package
7
+ * @copyright 2011 Netresearch
8
+ * @author Thomas Kappel <thomas.kappel@netresearch.de>
9
+ * @license OSL 3.0
10
+ */
11
+ class Netresearch_OPS_Model_Payment_Cc extends Netresearch_OPS_Model_Payment_DirectLink
12
+ {
13
+ /** info source path */
14
+ protected $_infoBlockType = 'ops/info_cc';
15
+
16
+ /** @var string $_formBlockType define a specific form block */
17
+ protected $_formBlockType = 'ops/form_cc';
18
+
19
+ /** payment code */
20
+ protected $_code = 'ops_cc';
21
+
22
+ protected $featureModel = null;
23
+
24
+ /** ops payment code */
25
+ public function getOpsCode($payment = null)
26
+ {
27
+ $opsBrand = $this->getOpsBrand($payment);
28
+ if ('PostFinance card' == $opsBrand) {
29
+ return 'PostFinance Card';
30
+ }
31
+ if ('UNEUROCOM' == $this->getOpsBrand($payment)) {
32
+ return 'UNEUROCOM';
33
+ }
34
+ return 'CreditCard';
35
+ }
36
+
37
+ /**
38
+ * @param null $payment
39
+ * @return array|mixed|null
40
+ */
41
+ public function getOpsBrand($payment = null)
42
+ {
43
+ if (is_null($payment)) {
44
+ $payment = Mage::getSingleton('checkout/session')->getQuote()->getPayment();
45
+ }
46
+
47
+ return $payment->getAdditionalInformation('CC_BRAND');
48
+ }
49
+
50
+ public function getOrderPlaceRedirectUrl($payment = null)
51
+ {
52
+ if ($this->hasBrandAliasInterfaceSupport($payment)) {
53
+ if ('' == $this->getOpsHtmlAnswer($payment))
54
+ return false; // Prevent redirect on cc payment
55
+ else
56
+ return Mage::getModel('ops/config')->get3dSecureRedirectUrl();
57
+ }
58
+ return parent::getOrderPlaceRedirectUrl();
59
+ }
60
+
61
+ /**
62
+ * only some brands are supported to be integrated into onepage checkout
63
+ *
64
+ * @return array
65
+ */
66
+ public function getBrandsForAliasInterface()
67
+ {
68
+ $brands = Mage::getModel('ops/config')->getInlinePaymentCcTypes();
69
+ return $brands;
70
+ }
71
+
72
+ /**
73
+ * if cc brand supports ops alias interface
74
+ *
75
+ * @param Mage_Payment_Model_Info $payment
76
+ *
77
+ * @return void
78
+ */
79
+ public function hasBrandAliasInterfaceSupport($payment = null)
80
+ {
81
+ return in_array(
82
+ $this->getOpsBrand($payment),
83
+ $this->getBrandsForAliasInterface()
84
+ );
85
+ }
86
+
87
+ /**
88
+ * Validates alias for in quote provided addresses
89
+ * @param Mage_Sales_Model_Quote $quote
90
+ * @param Varien_Object $payment
91
+ * @throws Mage_Core_Exception
92
+ */
93
+ protected function validateAlias($quote, $payment)
94
+ {
95
+ $alias = $payment->getAdditionalInformation('alias');
96
+ if (0 < strlen(trim($alias))
97
+ && is_numeric($payment->getAdditionalInformation('cvc'))
98
+ && false === Mage::helper('ops/alias')->isAliasValidForAddresses(
99
+ $quote->getCustomerId(),
100
+ $alias,
101
+ $quote->getBillingAddress(),
102
+ $quote->getShippingAddress(),
103
+ $quote->getStoreId()
104
+ )
105
+ ) {
106
+ $this->getOnepage()->getCheckout()->setGotoSection('payment');
107
+ Mage::throwException(
108
+ $this->getHelper()->__('Invalid payment information provided!')
109
+ );
110
+ }
111
+ }
112
+
113
+ /**
114
+ * @return Netresearch_OPS_Helper_Creditcard
115
+ */
116
+ public function getRequestParamsHelper()
117
+ {
118
+ if (null === $this->requestParamsHelper) {
119
+ $this->requestParamsHelper = Mage::helper('ops/creditcard');
120
+ }
121
+
122
+ return $this->requestParamsHelper;
123
+ }
124
+
125
+
126
+ protected function performPreDirectLinkCallActions(Mage_Sales_Model_Quote $quote, Varien_Object $payment, $requestParams = array())
127
+ {
128
+ Mage::helper('ops/alias')->cleanUpAdditionalInformation($payment, true);
129
+ if (true === Mage::getModel('ops/config')->isAliasManagerEnabled()) {
130
+ $this->validateAlias($quote, $payment);
131
+ }
132
+
133
+ return $this;
134
+ }
135
+
136
+ protected function performPostDirectLinkCallAction(Mage_Sales_Model_Quote $quote, Mage_Sales_Model_Order $order)
137
+ {
138
+ Mage::helper('ops/alias')->setAliasActive($quote, $order);
139
+
140
+ return $this;
141
+ }
142
+
143
+ protected function handleAdminPayment(Mage_Sales_Model_Quote $quote)
144
+ {
145
+ return $this;
146
+ }
147
+
148
+
149
+ /**
150
+ * returns allow zero amount authorization
151
+ * only TRUE if configured payment action for the store is authorize
152
+ *
153
+ * @param mixed null|int $storeId
154
+ *
155
+ * @return bool
156
+ */
157
+ public function isZeroAmountAuthorizationAllowed($storeId = null)
158
+ {
159
+ $result = false;
160
+ if (
161
+ $this->getConfig()->getPaymentAction($storeId) == Netresearch_OPS_Model_Payment_Abstract::ACTION_AUTHORIZE
162
+ && true == Mage::getStoreConfig('payment/ops_cc/zero_amount_checkout', $storeId)
163
+ ) {
164
+ $result = true;
165
+ }
166
+
167
+ return $result;
168
+ }
169
+
170
+
171
+ /**
172
+ * method was implemented in CE 1.8 / EE 1.14
173
+ * if Version is CE 1.8 / EE 1.14 use parent method otherwise use our implementation
174
+ *
175
+ * @param Mage_Sales_Model_Quote $quote
176
+ * @param $checksBitMask
177
+ *
178
+ * @return bool
179
+ */
180
+ public function isApplicableToQuote($quote, $checksBitMask)
181
+ {
182
+ $result = true;
183
+ if (Mage::helper('ops/version')->canUseApplicableForQuote(Mage::getEdition())) {
184
+ $result = parent::isApplicableToQuote($quote, $checksBitMask);
185
+ }
186
+
187
+ if ($quote->getBaseGrandTotal() < 0.01 && $result === false) {
188
+ $result = $this->getFeatureModel()->isCCAndZeroAmountAuthAllowed($this, $quote);
189
+ }
190
+
191
+ return $result;
192
+ }
193
+
194
+ /**
195
+ * @return Netresearch_OPS_Model_Payment_Features_ZeroAmountAuth
196
+ */
197
+ public function getFeatureModel()
198
+ {
199
+ if (null === $this->featureModel) {
200
+ $this->featureModel = Mage::getModel('ops/payment_features_zeroAmountAuth');
201
+ }
202
+
203
+ return $this->featureModel;
204
+ }
205
+
206
+ /**
207
+ * setter for canCapture from outside, needed for zero amount order since we need to disable online capture
208
+ * but still need to be able to create a invoice
209
+ *
210
+ * @param $canCapture
211
+ */
212
+ public function setCanCapture($canCapture)
213
+ {
214
+ if ($this->_canCapture != $canCapture) {
215
+ $this->_canCapture = $canCapture;
216
+ }
217
+ }
218
+
219
+ /**
220
+ * Override the method instead of the _canReviewPayment parameter, because we will only allow it with Ingenico Payment Services status == 0
221
+ *
222
+ * @return bool
223
+ * @param Mage_Payment_Model_Info $payment
224
+ */
225
+ public function canReviewPayment(Mage_Payment_Model_Info $payment)
226
+ {
227
+ if ($payment->getAdditionalInformation('status') == Netresearch_OPS_Model_Payment_Abstract::OPS_INVALID) {
228
+
229
+ return true;
230
+ }
231
+
232
+ return false;
233
+
234
+ }
235
+
236
+ /**
237
+ * Enable payment deny when __VENDOR status == 0
238
+ *
239
+ * @param Mage_Payment_Model_Info $payment
240
+ * @return bool
241
+ */
242
+ public function denyPayment(Mage_Payment_Model_Info $payment)
243
+ {
244
+ if ($payment->getAdditionalInformation('status') == Netresearch_OPS_Model_Payment_Abstract::OPS_INVALID) {
245
+ // returning true will automatically invoke the payment cancellation process
246
+ return true;
247
+ }
248
+
249
+ return false;
250
+ }
251
+
252
+ /**
253
+ * Check wether payment method is available for quote
254
+ *
255
+ * @param Mage_Sales_Model_Quote $quote
256
+ *
257
+ * @return bool
258
+ */
259
+ public function isAvailable($quote = null)
260
+ {
261
+ if (!$quote->getItemsCount() > 0 && $this->getDataHelper()->isAdminSession()) {
262
+ /* Disable payment method in backend as long as there are no items in quote to
263
+ * avoid problems with alias creation in EE1.12 & EE1.13
264
+ */
265
+ return false;
266
+ } else {
267
+ return parent::isAvailable($quote);
268
+ }
269
+ }
270
+ }
271
+
app/code/community/Netresearch/OPS/Model/Payment/ChinaUnionPay.php ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Netresearch OPS
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ *
13
+ * DISCLAIMER
14
+ *
15
+ * Do not edit or add to this file if you wish to upgrade this extension to
16
+ * newer versions in the future.
17
+ *
18
+ * @copyright Copyright (c) 2015 Netresearch GmbH & Co. KG (http://www.netresearch.de/)
19
+ * @license Open Software License (OSL 3.0)
20
+ * @link http://opensource.org/licenses/osl-3.0.php
21
+ */
22
+
23
+ /**
24
+ * Netresearch_OPS_Model_Payment_ChinaUnionPay
25
+ *
26
+ * @category Ingenico
27
+ * @package Netresearch_OPS
28
+ * @author Sebastian Ertner <sebastian.ertner@netresearch.de>
29
+ */
30
+ class Netresearch_OPS_Model_Payment_ChinaUnionPay
31
+ extends Netresearch_OPS_Model_Payment_Abstract
32
+ {
33
+ const CODE = 'ops_chinaUnionPay';
34
+ const PM = 'PAYDOL_UPOP';
35
+ const BRAND = 'UnionPay';
36
+
37
+ /** Check if we can capture directly from the backend */
38
+ protected $_canBackendDirectCapture = true;
39
+
40
+ /** disable partial refund */
41
+ protected $_canRefundInvoicePartial = false;
42
+
43
+ /** disable partial capture */
44
+ protected $_canCapturePartial = false;
45
+
46
+ /** info source path */
47
+ protected $_infoBlockType = 'ops/info_redirect';
48
+
49
+ /** payment code */
50
+ protected $_code = self::CODE;
51
+
52
+ public function getOpsCode($payment = null)
53
+ {
54
+ return self::PM;
55
+ }
56
+
57
+ public function getOpsBrand($payment = null)
58
+ {
59
+ return self::BRAND;
60
+ }
61
+
62
+
63
+ public function getPaymentAction()
64
+ {
65
+ return Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE_CAPTURE;
66
+ }
67
+
68
+
69
+ }
70
+
app/code/community/Netresearch/OPS/Model/Payment/Cod.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Netresearch_OPS_Model_Payment_Cod
4
+ *
5
+ * @package
6
+ * @copyright 2011 Netresearch
7
+ * @author Thomas Kappel <thomas.kappel@netresearch.de>
8
+ * @license OSL 3.0
9
+ */
10
+ class Netresearch_OPS_Model_Payment_Cod
11
+ extends Netresearch_OPS_Model_Payment_Abstract
12
+ {
13
+ /** Check if we can capture directly from the backend */
14
+ protected $_canBackendDirectCapture = true;
15
+
16
+ /** info source path */
17
+ protected $_infoBlockType = 'ops/info_redirect';
18
+
19
+ /** payment code */
20
+ protected $_code = 'ops_cod';
21
+
22
+ public function getOpsCode($payment=null)
23
+ {
24
+ return 'Payment on Delivery';
25
+ }
26
+ }
27
+
app/code/community/Netresearch/OPS/Model/Payment/DirectDebit.php ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Netresearch_OPS_Model_Payment_DirectDebit
4
+ *
5
+ * @package
6
+ * @copyright 2011 Netresearch
7
+ * @author Thomas Kappel <thomas.kappel@netresearch.de>
8
+ * @license OSL 3.0
9
+ */
10
+ class Netresearch_OPS_Model_Payment_DirectDebit
11
+ extends Netresearch_OPS_Model_Payment_DirectLink
12
+ {
13
+ /** info source path */
14
+ protected $_infoBlockType = 'ops/info_redirect';
15
+
16
+ /* define a specific form block */
17
+ protected $_formBlockType = 'ops/form_directDebit';
18
+
19
+ /** payment code */
20
+ protected $_code = 'ops_directDebit';
21
+
22
+ public function getOrderPlaceRedirectUrl()
23
+ {
24
+ // Prevent redirect on direct debit payment
25
+ return false;
26
+ }
27
+
28
+
29
+ /**
30
+ * @return Netresearch_OPS_Helper_DirectDebit
31
+ */
32
+ public function getRequestParamsHelper()
33
+ {
34
+ if (null === $this->requestParamsHelper) {
35
+ $this->requestParamsHelper = Mage::helper('ops/directDebit');
36
+ }
37
+
38
+ return $this->requestParamsHelper;
39
+ }
40
+
41
+ protected function performPreDirectLinkCallActions(Mage_Sales_Model_Quote $quote, Varien_Object $payment, $requestParams = array())
42
+ {
43
+ return $this;
44
+ }
45
+
46
+ protected function performPostDirectLinkCallAction(Mage_Sales_Model_Quote $quote, Mage_Sales_Model_Order $order)
47
+ {
48
+ return $this;
49
+ }
50
+
51
+ protected function handleAdminPayment(Mage_Sales_Model_Quote $quote)
52
+ {
53
+ $directDebitHelper = Mage::helper('ops/directDebit');
54
+ $requestParams = Mage::app()->getRequest()->getParam('ops_directDebit');
55
+ $directDebitHelper->handleAdminPayment($quote, $requestParams);
56
+
57
+ return $this;
58
+ }
59
+ }
60
+
app/code/community/Netresearch/OPS/Model/Payment/DirectEbanking.php ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Netresearch_OPS_Model_Payment_DirectEbanking
4
+ *
5
+ * @package
6
+ * @copyright 2011 Netresearch
7
+ * @author Thomas Kappel <thomas.kappel@netresearch.de>
8
+ * @license OSL 3.0
9
+ */
10
+ class Netresearch_OPS_Model_Payment_DirectEbanking
11
+ extends Netresearch_OPS_Model_Payment_Abstract
12
+ {
13
+ /** Check if we can capture directly from the backend */
14
+ protected $_canBackendDirectCapture = true;
15
+
16
+ /** info source path */
17
+ protected $_infoBlockType = 'ops/info_redirect';
18
+
19
+ /** payment code */
20
+ protected $_code = 'ops_directEbanking';
21
+
22
+
23
+ protected function getPayment()
24
+ {
25
+ $checkout = Mage::getSingleton('checkout/session');
26
+ $payment = $checkout->getQuote()->getPayment();
27
+ if (!$payment->getId()) {
28
+ $payment = Mage::getModel('sales/order')->loadByIncrementId($checkout->getLastRealOrderId())->getPayment();
29
+ }
30
+ return $payment;
31
+ }
32
+
33
+ /**
34
+ * Assign data to info model instance
35
+ *
36
+ * @param mixed $data
37
+ * @return Mage_Payment_Model_Info
38
+ */
39
+ public function assignData($data)
40
+ {
41
+ $brand = '';
42
+
43
+ if (is_object($data) && $data instanceof Varien_Object) {
44
+ $brand = $data['directEbanking_brand'];
45
+ } elseif (is_array($data) && isset($data['directEbanking_brand'])) {
46
+
47
+ $brand = $data['directEbanking_brand'];
48
+ }
49
+
50
+ $brand = $this->fixSofortUberweisungBrand($brand);
51
+
52
+ $payment = $this->getPayment();
53
+ // brand == pm for all DirectEbanking methods
54
+ $payment->setAdditionalInformation('PM', $brand);
55
+ $payment->setAdditionalInformation('BRAND', $brand);
56
+ parent::assignData($data);
57
+ return $this;
58
+ }
59
+
60
+
61
+ /**
62
+ * Fixes legacy brand value of Sofort Uberweisung for DirectEbanking
63
+ *
64
+ * @param string $value
65
+ * @return string
66
+ */
67
+ protected function fixSofortUberweisungBrand($value){
68
+ if($value === 'Sofort Uberweisung'){
69
+ return 'DirectEbanking';
70
+ }
71
+ return $value;
72
+ }
73
+ }
74
+
app/code/community/Netresearch/OPS/Model/Payment/DirectLink.php ADDED
@@ -0,0 +1,366 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Michael Lühr <michael.luehr@netresearch.de>
4
+ * @category Netresearch
5
+ * @copyright Copyright (c) 2014 Netresearch GmbH & Co. KG (http://www.netresearch.de)
6
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
7
+ */
8
+
9
+
10
+ abstract class Netresearch_OPS_Model_Payment_DirectLink extends Netresearch_OPS_Model_Payment_Abstract
11
+ {
12
+ /** Check if we can capture directly from the backend */
13
+ protected $_canBackendDirectCapture = true;
14
+
15
+ /** Check if we can capture directly from the backend */
16
+ protected $_canUseInternal = true;
17
+
18
+ protected $config = null;
19
+
20
+ protected $directLinkHelper = null;
21
+
22
+ protected $paymentHelper = null;
23
+
24
+ protected $quoteHelper = null;
25
+
26
+ protected $requestParamsHelper = null;
27
+
28
+ protected $validationFactory = null;
29
+
30
+ protected $dataHelper = null;
31
+ /**
32
+ * @param Netresearch_OPS_Helper_Payment_DirectLink_RequestInterface $requestParamsHelper
33
+ */
34
+ public function setRequestParamsHelper($requestParamsHelper)
35
+ {
36
+ $this->requestParamsHelper = $requestParamsHelper;
37
+ }
38
+
39
+
40
+ /**
41
+ * sets the quote helper
42
+ *
43
+ * @param Netresearch_OPS_Helper_Quote $quoteHelper
44
+ */
45
+ public function setQuoteHelper(Netresearch_OPS_Helper_Quote $quoteHelper)
46
+ {
47
+ $this->quoteHelper = $quoteHelper;
48
+ }
49
+
50
+ /**
51
+ * gets the quote helper
52
+ *
53
+ * @return Netresearch_OPS_Helper_Quote
54
+ */
55
+ public function getQuoteHelper()
56
+ {
57
+ if (null === $this->quoteHelper) {
58
+ $this->quoteHelper = Mage::helper('ops/quote');
59
+ }
60
+
61
+ return $this->quoteHelper;
62
+ }
63
+
64
+
65
+
66
+ /**
67
+ * @param Netresearch_OPS_Helper_Directlink $directLinkHelper
68
+ */
69
+ public function setDirectLinkHelper($directLinkHelper)
70
+ {
71
+ $this->directLinkHelper = $directLinkHelper;
72
+ }
73
+
74
+ /**
75
+ * @return Netresearch_OPS_Helper_Directlink
76
+ */
77
+ public function getDirectLinkHelper()
78
+ {
79
+ if (null === $this->directLinkHelper) {
80
+ $this->directLinkHelper = MAge::helper('ops/directlink');
81
+ }
82
+ return $this->directLinkHelper;
83
+ }
84
+
85
+ /**
86
+ * @param Netresearch_OPS_Helper_Payment $paymentHelper
87
+ */
88
+ public function setPaymentHelper($paymentHelper)
89
+ {
90
+ $this->paymentHelper = $paymentHelper;
91
+ }
92
+
93
+ /**
94
+ * @return Netresearch_OPS_Helper_Payment
95
+ */
96
+ public function getPaymentHelper()
97
+ {
98
+ if (null === $this->paymentHelper) {
99
+ $this->paymentHelper = Mage::helper('ops/payment');
100
+ }
101
+
102
+ return $this->paymentHelper;
103
+ }
104
+
105
+
106
+
107
+
108
+ /**
109
+ * @param null $config
110
+ */
111
+ public function setConfig(Netresearch_OPS_Model_Config $config)
112
+ {
113
+ $this->config = $config;
114
+ }
115
+
116
+ /**
117
+ * @return Netresearch_OPS_Model_Config
118
+ */
119
+ public function getConfig()
120
+ {
121
+ if (null === $this->config) {
122
+ $this->config = Mage::getModel('ops/config');
123
+ }
124
+
125
+ return $this->config;
126
+ }
127
+
128
+
129
+
130
+
131
+ /**
132
+ * returns the payment action in dependency of the configuration quote id or order's increment id
133
+ *
134
+ * @return string
135
+ */
136
+ public function getConfigPaymentAction()
137
+ {
138
+ $paymentAction = '';
139
+
140
+ if ($this->getConfig()->getPaymentAction() == Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE
141
+ && ($this instanceof Netresearch_OPS_Model_Payment_DirectDebit ||
142
+ ($this instanceof Netresearch_OPS_Model_Payment_Cc && $this->hasBrandAliasInterfaceSupport($this->getInfoInstance())))
143
+ ) {
144
+ $paymentAction = Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE;
145
+ }
146
+
147
+ if ($this->getConfig()->getPaymentAction() == Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE_CAPTURE
148
+ && ($this instanceof Netresearch_OPS_Model_Payment_DirectDebit ||
149
+ ($this instanceof Netresearch_OPS_Model_Payment_Cc && $this->hasBrandAliasInterfaceSupport($this->getInfoInstance())))
150
+ ) {
151
+ $paymentAction = Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE_CAPTURE;
152
+ }
153
+
154
+ return $paymentAction;
155
+ }
156
+
157
+
158
+ public function isInitializeNeeded()
159
+ {
160
+ return false;
161
+ }
162
+
163
+ /**
164
+ * @param Varien_Object $payment
165
+ * @param float $amount
166
+ *
167
+ * @return Mage_Payment_Model_Abstract|void
168
+ */
169
+
170
+ public function authorize(Varien_Object $payment, $amount)
171
+ {
172
+ if ($this->isInlinePayment($payment)
173
+ && Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE == $this->getConfigPaymentAction()
174
+ ) {
175
+ $order = $payment->getOrder();
176
+ $quote = $this->getQuoteHelper()->getQuote();
177
+ $this->confirmPayment($order, $quote, $payment);
178
+ }
179
+ }
180
+
181
+ /**
182
+ * Saves the payment model and runs the request to Ingenico Payment Servicess webservice
183
+ *
184
+ * @param Mage_Sales_Model_Order $order
185
+ * @param Mage_Sales_Model_Quote $quote
186
+ * @param Varien_Object $payment
187
+ * @throws Mage_Core_Exception
188
+ */
189
+
190
+ protected function confirmPayment(Mage_Sales_Model_Order $order, Mage_Sales_Model_Quote $quote, Varien_Object $payment)
191
+ {
192
+ $this->handleAdminPayment($quote);
193
+ $requestParams = $this->getRequestParamsHelper()->getDirectLinkRequestParams($quote, $order, $payment);
194
+ $this->invokeRequestParamValidation($requestParams);
195
+ $this->performPreDirectLinkCallActions($quote, $order);
196
+ $response = $this->getDirectLinkHelper()->performDirectLinkRequest($quote, $requestParams, $quote->getStoreId());
197
+ if ($response) {
198
+ $this->getPaymentHelper()->applyStateForOrder($order, $response);
199
+ $this->performPostDirectLinkCallAction($quote, $order);
200
+
201
+ } else {
202
+ $this->getPaymentHelper()->handleUnknownStatus($order);
203
+ }
204
+ }
205
+
206
+ /**
207
+ * Handles backend payments on Magento side
208
+ *
209
+ * @param Mage_Sales_Model_Quote $quote
210
+ * @return Netresearch_OPS_Model_Payment_DirectLink
211
+ */
212
+ abstract protected function handleAdminPayment(Mage_Sales_Model_Quote $quote);
213
+
214
+ /**
215
+ * @return Netresearch_OPS_Helper_Payment_DirectLink_RequestInterface
216
+ */
217
+ abstract protected function getRequestParamsHelper();
218
+
219
+
220
+ /**
221
+ * Perform necessary preparation before request to Ingenico Payment Services is sent
222
+ *
223
+ * @param Mage_Sales_Model_Quote $quote
224
+ * @param Varien_Object $payment
225
+ * @param array $requestParams
226
+ * @return Netresearch_OPS_Model_Payment_DirectLink
227
+ */
228
+ abstract protected function performPreDirectLinkCallActions(Mage_Sales_Model_Quote $quote, Varien_Object $payment, $requestParams = array());
229
+
230
+ /**
231
+ * Perform necessary work after the Directlink Request was sent and an response was received and processed
232
+ *
233
+ * @param Mage_Sales_Model_Quote $quote
234
+ * @param Mage_Sales_Model_Order $order
235
+ * @return Netresearch_OPS_Model_Payment_DirectLink
236
+ */
237
+ abstract protected function performPostDirectLinkCallAction(Mage_Sales_Model_Quote $quote, Mage_Sales_Model_Order $order);
238
+
239
+
240
+ /**
241
+ * performs direct link request either for inline payments and direct sale mode or the normal maintenance call (invoice)
242
+ *
243
+ * @override
244
+ * @param Varien_Object $payment
245
+ * @param float $amount
246
+ *
247
+ * @return Mage_Payment_Model_Abstract|void
248
+ */
249
+ public function capture(Varien_Object $payment, $amount)
250
+ {
251
+ /**
252
+ * process direct sale inline payments (initial request)
253
+ */
254
+ if (Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE_CAPTURE == $this->getConfigPaymentAction()
255
+ && $this->getPaymentHelper()->isInlinePayment($payment)
256
+ ) {
257
+ $order = $payment->getOrder();
258
+ $quote = $this->getQuoteHelper()->getQuote();
259
+ $this->confirmPayment($order, $quote, $payment);
260
+ }
261
+ /**
262
+ * invoice request authorize mode if the payment was placed on Ingenico Payment Services side
263
+ */
264
+ elseif (0 < strlen(trim($payment->getAdditionalInformation('paymentId')))) {
265
+ parent::capture($payment, $amount);
266
+ }
267
+ }
268
+
269
+
270
+ /**
271
+ * checks if the selected payment supports inline mode
272
+ *
273
+ * @param $payment - the payment to check
274
+ *
275
+ * @return bool - true if it's support inline mode, false otherwise
276
+ */
277
+ protected function isInlinePayment($payment)
278
+ {
279
+ $result = false;
280
+ $code = $payment->getMethodInstance()->getCode();
281
+ if (($code == 'ops_cc'
282
+ && $payment->getMethodInstance()
283
+ ->hasBrandAliasInterfaceSupport(
284
+ $payment
285
+ ) || $this->getDataHelper()->isAdminSession()
286
+ ) || $code == 'ops_directDebit'
287
+ ) {
288
+ $result = true;
289
+ }
290
+ return $result;
291
+ }
292
+
293
+
294
+ /**
295
+ * Get one page checkout model
296
+ *
297
+ * @return Mage_Checkout_Model_Type_Onepage
298
+ */
299
+ public function getOnepage()
300
+ {
301
+ return Mage::getSingleton('checkout/type_onepage');
302
+ }
303
+
304
+ /**
305
+ * Validate checkout request parameters
306
+ *
307
+ * @param $requestParams
308
+ *
309
+ * @throws Mage_Core_Exception
310
+ * @return Netresearch_OPS_Model_Payment_DirectLink
311
+ */
312
+ protected function invokeRequestParamValidation($requestParams)
313
+ {
314
+ $validator = $this->getValidationFactory()->getValidatorFor(
315
+ Netresearch_OPS_Model_Validator_Parameter_Factory::TYPE_REQUEST_PARAMS_VALIDATION
316
+ );
317
+ if (false == $validator->isValid($requestParams)) {
318
+ $this->getOnepage()->getCheckout()->setGotoSection('payment');
319
+ Mage::throwException($this->getHelper()->__('The data you have provided can not be processed by Ingenico Payment Services'));
320
+ }
321
+
322
+ return $this;
323
+ }
324
+
325
+ /**
326
+ * @return Netresearch_OPS_Model_Validator_Parameter_Factory
327
+ */
328
+ public function getValidationFactory()
329
+ {
330
+ if (null === $this->validationFactory) {
331
+ $this->validationFactory = Mage::getModel('ops/validator_parameter_factory');
332
+ }
333
+
334
+ return $this->validationFactory;
335
+ }
336
+
337
+ /**
338
+ * sets the used validation factory
339
+ *
340
+ * @param Netresearch_OPS_Model_Validator_Parameter_Factory $validationFactory
341
+ */
342
+ public function setValidationFactory(Netresearch_OPS_Model_Validator_Parameter_Factory $validationFactory)
343
+ {
344
+ $this->validationFactory = $validationFactory;
345
+ }
346
+
347
+ /**
348
+ * @param Netresearch_OPS_Helper_Data $dataHelper
349
+ */
350
+ public function setDataHelper(Netresearch_OPS_Helper_Data $dataHelper)
351
+ {
352
+ $this->dataHelper = $dataHelper;
353
+ }
354
+
355
+ /**
356
+ * @return Netresearch_OPS_Helper_Data
357
+ */
358
+ public function getDataHelper()
359
+ {
360
+ if (null === $this->dataHelper) {
361
+ $this->dataHelper = Mage::helper('ops/data');
362
+ }
363
+ return $this->dataHelper;
364
+ }
365
+
366
+ }
app/code/community/Netresearch/OPS/Model/Payment/EDankort.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Netresearch_OPS_Model_Payment_EDankort
4
+ *
5
+ * @package
6
+ * @copyright 2011 Netresearch
7
+ * @author Thomas Kappel <thomas.kappel@netresearch.de>
8
+ * @license OSL 3.0
9
+ */
10
+ class Netresearch_OPS_Model_Payment_EDankort
11
+ extends Netresearch_OPS_Model_Payment_Abstract
12
+ {
13
+ /** Check if we can capture directly from the backend */
14
+ protected $_canBackendDirectCapture = true;
15
+
16
+ /** info source path */
17
+ protected $_infoBlockType = 'ops/info_redirect';
18
+
19
+ /** payment code */
20
+ protected $_code = 'ops_eDankort';
21
+
22
+ /** ops payment code */
23
+ public function getOpsCode($payment=null)
24
+ {
25
+ return 'eDankort';
26
+ }
27
+ }
28
+
app/code/community/Netresearch/OPS/Model/Payment/Eps.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Netresearch_OPS_Model_Payment_Eps
4
+ *
5
+ * @package
6
+ * @copyright 2011 Netresearch
7
+ * @author Thomas Kappel <thomas.kappel@netresearch.de>
8
+ * @license OSL 3.0
9
+ */
10
+ class Netresearch_OPS_Model_Payment_Eps
11
+ extends Netresearch_OPS_Model_Payment_Abstract
12
+ {
13
+ /** Check if we can capture directly from the backend */
14
+ protected $_canBackendDirectCapture = true;
15
+
16
+ /** info source path */
17
+ protected $_infoBlockType = 'ops/info_redirect';
18
+
19
+ /** payment code */
20
+ protected $_code = 'ops_eps';
21
+
22
+ /** ops payment code */
23
+ public function getOpsCode($payment=null)
24
+ {
25
+ return 'EPS';
26
+ }
27
+ }
28
+
app/code/community/Netresearch/OPS/Model/Payment/Features/PaymentEmail.php ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * PaymentEmail.php
5
+ * @author paul.siedler@netresearch.de
6
+ * @copyright Copyright (c) 2015 Netresearch GmbH & Co. KG
7
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License
8
+ */
9
+
10
+ /**
11
+ * Class Netresearch_OPS_Model_Payment_Features_PaymentEmail
12
+ */
13
+ class Netresearch_OPS_Model_Payment_Features_PaymentEmail
14
+ {
15
+
16
+ protected function getConfig()
17
+ {
18
+ return Mage::getModel('ops/config');
19
+ }
20
+
21
+ /**
22
+ * Check if payment email is available for order
23
+ *
24
+ * @param $order
25
+ * @return bool
26
+ */
27
+ public function isAvailableForOrder($order)
28
+ {
29
+ if($order instanceof Mage_Sales_Model_Order){
30
+ $status = $order->getPayment()->getAdditionalInformation('status');
31
+ return Mage::helper('ops/payment')->isPaymentInvalid($status);
32
+ }
33
+
34
+ return false;
35
+ }
36
+
37
+
38
+ /**
39
+ * Resends the payment information and returns true/false, depending if succeeded or not
40
+ *
41
+ * @param Mage_Sales_Model_Order $order
42
+ * @return boolean success state
43
+ */
44
+ public function resendPaymentInfo(Mage_Sales_Model_Order $order)
45
+ {
46
+
47
+ // reset payment method so the customer can choose freely from all available methods
48
+ $this->setPaymentMethodToGeneric($order);
49
+
50
+ $config = $this->getConfig();
51
+ $template = $config->getResendPaymentInfoTemplate($order->getStoreId());
52
+ $emailTemplate = Mage::getModel('core/email_template')->loadDefault($config->getResendPaymentInfoTemplate($order->getStoreId()));
53
+
54
+ $identity = $config->getResendPaymentInfoIdentity($order->getStoreId());
55
+ $emailTemplate->setSenderName(Mage::getStoreConfig('trans_email/ident_'.$identity.'/name'))
56
+ ->setSenderEmail(Mage::getStoreConfig('trans_email/ident_'.$identity.'/email'));
57
+
58
+ $parameters = array(
59
+ "order" => $order,
60
+ "paymentLink" => $this->generatePaymentLink($order)
61
+ );
62
+
63
+ return $emailTemplate->send($order->getCustomerEmail(), $order->getCustomerName(), $parameters);
64
+
65
+ }
66
+
67
+ /**
68
+ * Generates the payment url
69
+ *
70
+ * @param Mage_Sales_Model_Order $order
71
+ * @return string
72
+ */
73
+ protected function generatePaymentLink(Mage_Sales_Model_Order $order)
74
+ {
75
+ $opsOrderId = Mage::helper('ops/order')->getOpsOrderId($order);
76
+
77
+ $params = array(
78
+ 'orderID' => $opsOrderId
79
+ );
80
+
81
+ $secret = $this->getConfig()->getShaInCode($order->getStoreId());
82
+ $raw = Mage::helper('ops/payment')->getSHAInSet($params, $secret);
83
+
84
+ $params['SHASIGN'] = strtoupper(Mage::helper('ops/payment')->shaCrypt($raw));
85
+
86
+ $url = Mage::getModel('ops/config')->getPaymentRetryUrl($params);
87
+ return $url;
88
+ }
89
+
90
+ /**
91
+ * Set payment method to Netresearch_OPS_Model_Payment_Other
92
+ *
93
+ * @param Mage_Sales_Model_Order $order
94
+ * @throws Exception
95
+ */
96
+ protected function setPaymentMethodToGeneric(Mage_Sales_Model_Order $order)
97
+ {
98
+ $order->getPayment()->setMethod(Netresearch_OPS_Model_Payment_Other::CODE)->save();
99
+ }
100
+
101
+ }
app/code/community/Netresearch/OPS/Model/Payment/Features/ZeroAmountAuth.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Netresearch_OPS_Model_Payment_Features_ZeroAmountAuth
5
+ *
6
+ * @package
7
+ * @copyright 2014 Netresearch
8
+ * @author Sebastian Ertner <sebastian.ertner@netresearch.de>
9
+ * @license OSL 3.0
10
+ */
11
+ class Netresearch_OPS_Model_Payment_Features_ZeroAmountAuth
12
+ {
13
+
14
+ /**
15
+ * check if payment method is cc and zero amount authorization is enabled
16
+ *
17
+ * @param Netresearch_OPS_Model_Payment_Abstract $opsPaymentMethod
18
+ *
19
+ * @return bool
20
+ */
21
+ public function isCCAndZeroAmountAuthAllowed(
22
+ Netresearch_OPS_Model_Payment_Abstract $opsPaymentMethod,
23
+ Mage_Sales_Model_Quote $quote
24
+ ) {
25
+ $result = false;
26
+ $storeId = $quote->getStoreId();
27
+ if ($quote->getBaseGrandTotal() < 0.01
28
+ && $opsPaymentMethod instanceof Netresearch_OPS_Model_Payment_Cc
29
+ && $opsPaymentMethod->isZeroAmountAuthorizationAllowed($storeId)
30
+ && 0 < $quote->getItemsCount()
31
+
32
+ ) {
33
+ $result = true;
34
+ }
35
+
36
+ return $result;
37
+ }
38
+
39
+ }
app/code/community/Netresearch/OPS/Model/Payment/FortisPayButton.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Netresearch_OPS_Model_Payment_FortisPayButton
4
+ *
5
+ * @package
6
+ * @copyright 2011 Netresearch
7
+ * @author Thomas Kappel <thomas.kappel@netresearch.de>
8
+ * @license OSL 3.0
9
+ */
10
+ class Netresearch_OPS_Model_Payment_FortisPayButton
11
+ extends Netresearch_OPS_Model_Payment_Abstract
12
+ {
13
+ /** Check if we can capture directly from the backend */
14
+ protected $_canBackendDirectCapture = true;
15
+
16
+ /** info source path */
17
+ protected $_infoBlockType = 'ops/info_redirect';
18
+
19
+ /** payment code */
20
+ protected $_code = 'ops_fortisPayButton';
21
+
22
+ /** ops payment code */
23
+ public function getOpsCode($payment=null)
24
+ {
25
+ return 'Fortis Pay Button';
26
+ }
27
+ }
28
+
app/code/community/Netresearch/OPS/Model/Payment/GiroPay.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Netresearch_OPS_Model_Payment_GiroPay
4
+ *
5
+ * @package
6
+ * @copyright 2011 Netresearch
7
+ * @author Thomas Kappel <thomas.kappel@netresearch.de>
8
+ * @license OSL 3.0
9
+ */
10
+ class Netresearch_OPS_Model_Payment_GiroPay
11
+ extends Netresearch_OPS_Model_Payment_Abstract
12
+ {
13
+ /** Check if we can capture directly from the backend */
14
+ protected $_canBackendDirectCapture = true;
15
+
16
+ /** info source path */
17
+ protected $_infoBlockType = 'ops/info_redirect';
18
+
19
+ /** payment code */
20
+ protected $_code = 'ops_giroPay';
21
+
22
+ public function getOpsCode($payment=null)
23
+ {
24
+ return 'giropay';
25
+ }
26
+ }
27
+
app/code/community/Netresearch/OPS/Model/Payment/IDeal.php ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Netresearch_OPS_Model_Payment_IDeal
5
+ *
6
+ * @package
7
+ * @copyright 2011 Netresearch
8
+ * @author Thomas Kappel <thomas.kappel@netresearch.de>
9
+ * @license OSL 3.0
10
+ */
11
+ class Netresearch_OPS_Model_Payment_IDeal
12
+ extends Netresearch_OPS_Model_Payment_Abstract
13
+ {
14
+ /** Check if we can capture directly from the backend */
15
+ protected $_canBackendDirectCapture = true;
16
+
17
+ /** info source path */
18
+ protected $_infoBlockType = 'ops/info_redirect';
19
+
20
+ protected $_formBlockType = 'ops/form_ideal';
21
+
22
+ /** payment code */
23
+ protected $_code = 'ops_iDeal';
24
+
25
+ /** ops payment code */
26
+ public function getOpsCode($payment = null)
27
+ {
28
+ return 'iDEAL';
29
+ }
30
+
31
+ /**
32
+ * adds payment specific information to the payment
33
+ *
34
+ * @param mixed $data - data containing the issuer id which should be used
35
+ *
36
+ * @return Netresearch_OPS_Model_Payment_IDeal
37
+ */
38
+ public function assignData($data)
39
+ {
40
+ if ($data instanceof Varien_Object) {
41
+ $data = $data->getData();
42
+ }
43
+ if (array_key_exists('iDeal_issuer_id', $data)) {
44
+ $payment = Mage::getSingleton('checkout/session')
45
+ ->getQuote()
46
+ ->getPayment();
47
+ $payment
48
+ ->setAdditionalInformation('iDeal_issuer_id', $data['iDeal_issuer_id']);
49
+ }
50
+ parent::assignData($data);
51
+
52
+ return $this;
53
+ }
54
+
55
+ /**
56
+ * getter for the iDeal issuers
57
+ *
58
+ * @return array
59
+ */
60
+ public function getIDealIssuers()
61
+ {
62
+ return Mage::getStoreConfig('payment/ops_iDeal/issuer');
63
+ }
64
+
65
+ /**
66
+ * add iDeal issuer id to form fields
67
+ *
68
+ * @override Netresearch_OPS_Model_Payment_Abstract
69
+ *
70
+ * @param $order
71
+ * @param null $requestParams
72
+ *
73
+ * @return array
74
+ */
75
+ public function getMethodDependendFormFields($order, $requestParams = null)
76
+ {
77
+ $formFields = parent::getMethodDependendFormFields($order, $requestParams);
78
+ if ($order->getPayment()->getAdditionalInformation('iDeal_issuer_id')) {
79
+ $formFields['ISSUERID'] = $order->getPayment()->getAdditionalInformation('iDeal_issuer_id');
80
+ }
81
+
82
+ return $formFields;
83
+ }
84
+ }
85
+
app/code/community/Netresearch/OPS/Model/Payment/IngHomePay.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Netresearch_OPS_Model_Payment_IngHomePay
4
+ *
5
+ * @package
6
+ * @copyright 2011 Netresearch
7
+ * @author Thomas Kappel <thomas.kappel@netresearch.de>
8
+ * @license OSL 3.0
9
+ */
10
+ class Netresearch_OPS_Model_Payment_IngHomePay
11
+ extends Netresearch_OPS_Model_Payment_Abstract
12
+ {
13
+ /** Check if we can capture directly from the backend */
14
+ protected $_canBackendDirectCapture = true;
15
+
16
+ /** info source path */
17
+ protected $_infoBlockType = 'ops/info_redirect';
18
+
19
+ /** payment code */
20
+ protected $_code = 'ops_ingHomePay';
21
+
22
+ /** ops payment code */
23
+ public function getOpsCode($payment = null)
24
+ {
25
+ return 'ING HomePay';
26
+ }
27
+ }
28
+
app/code/community/Netresearch/OPS/Model/Payment/InterSolve.php ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Netresearch_OPS_Model_Payment_InterSolve
4
+ *
5
+ * @package
6
+ * @copyright 2011 Netresearch
7
+ * @author Thomas Kappel <thomas.kappel@netresearch.de>
8
+ * @license OSL 3.0
9
+ */
10
+ class Netresearch_OPS_Model_Payment_InterSolve
11
+ extends Netresearch_OPS_Model_Payment_Abstract
12
+ {
13
+ /** Check if we can capture directly from the backend */
14
+ protected $_canBackendDirectCapture = true;
15
+
16
+ /** info source path */
17
+ protected $_infoBlockType = 'ops/info_redirect';
18
+
19
+ /** payment code */
20
+ protected $_code = 'ops_interSolve';
21
+
22
+ protected function getPayment($payment=null)
23
+ {
24
+ if (is_null($payment)) {
25
+ $checkout = Mage::getSingleton('checkout/session');
26
+ $payment = $checkout->getQuote()->getPayment();
27
+ if (!$payment->getId()) {
28
+ $payment = Mage::getModel('sales/order')
29
+ ->loadByIncrementId($checkout->getLastRealOrderId())
30
+ ->getPayment();
31
+ }
32
+ }
33
+ return $payment;
34
+ }
35
+
36
+ public function getOpsCode($payment = null)
37
+ {
38
+ return 'InterSolve';
39
+ }
40
+
41
+ public function getOpsBrand($payment=null)
42
+ {
43
+ return trim($this->getPayment($payment)->getAdditionalInformation('BRAND'));
44
+ }
45
+
46
+ /**
47
+ * Assign data to info model instance
48
+ *
49
+ * @param mixed $data
50
+ * @return Mage_Payment_Model_Info
51
+ */
52
+ public function assignData($data)
53
+ {
54
+
55
+ $brand = '';
56
+ if (is_object($data) && $data instanceof Varien_Object) {
57
+ $brand = $data->getIntersolveBrand();
58
+ } elseif (is_array($data) && isset($data['intersolve_brand'])) {
59
+ $brand = $data['intersolve_brand'];
60
+ }
61
+ if (strlen(trim($brand)) === 0) {
62
+ $brand = 'InterSolve';
63
+ }
64
+ $payment = Mage::getSingleton('checkout/session')->getQuote()->getPayment();
65
+ $payment->setAdditionalInformation('BRAND', $brand);
66
+
67
+ parent::assignData($data);
68
+ return $this;
69
+ }
70
+ }
71
+
app/code/community/Netresearch/OPS/Model/Payment/KbcOnline.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Netresearch_OPS_Model_Payment_KbcOnline
4
+ *
5
+ * @package
6
+ * @copyright 2011 Netresearch
7
+ * @author Thomas Kappel <thomas.kappel@netresearch.de>
8
+ * @license OSL 3.0
9
+ */
10
+ class Netresearch_OPS_Model_Payment_KbcOnline
11
+ extends Netresearch_OPS_Model_Payment_Abstract
12
+ {
13
+ /** Check if we can capture directly from the backend */
14
+ protected $_canBackendDirectCapture = true;
15
+
16
+ /** info source path */
17
+ protected $_infoBlockType = 'ops/info_redirect';
18
+
19
+ /** payment code */
20
+ protected $_code = 'ops_kbcOnline';
21
+
22
+ /** ops payment code */
23
+ public function getOpsCode($payment=null)
24
+ {
25
+ return 'KBC Online';
26
+ }
27
+ }
28
+
app/code/community/Netresearch/OPS/Model/Payment/Kwixo/Abstract.php ADDED
@@ -0,0 +1,613 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Magento
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * @category Mage
23
+ * @package Netresearch_OPS
24
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc.
25
+ * DBA Varien (http://www.varien.com)
26
+ * @license http://opensource.org/licenses/osl-3.0.php
27
+ * Open Software License (OSL 3.0)
28
+ */
29
+ class Netresearch_OPS_Model_Payment_Kwixo_Abstract
30
+ extends Netresearch_OPS_Model_Payment_Abstract
31
+ {
32
+
33
+ private $kwixoShippingModel = null;
34
+
35
+ private $shippingSettings = null;
36
+
37
+ /**
38
+ *
39
+ * @param Mage_Sales_Model_Order $order
40
+ * @param array $requestParams
41
+ */
42
+ public function getMethodDependendFormFields($order, $requestParams = null)
43
+ {
44
+ $formFields = parent::getMethodDependendFormFields(
45
+ $order, $requestParams
46
+ );
47
+ unset($formFields['OWNERADDRESS']);
48
+ unset($formFields['OWNERTELNO']);
49
+ unset($formFields['ECOM_SHIPTO_POSTAL_STREET_LINE1']);
50
+ $shippingMethod = 'none';
51
+ $isVirtual = true;
52
+ if ($order->getShippingAddress()) {
53
+ $isVirtual = false;
54
+ $carrierCode = $order->getShippingCarrier()->getCarrierCode();
55
+ $this->loadShippingSettingForCarrierCode($carrierCode);
56
+ $shippingMethod = $carrierCode;
57
+ }
58
+
59
+ $formFields['ECOM_ESTIMATEDELIVERYDATE']
60
+ = $this->getEstimatedDeliveryDate(
61
+ $this->getCode(), $order->getStoreId()
62
+ );
63
+ $formFields['RNPOFFERT'] = $this->getRnpFee(
64
+ $this->getCode(), $order->getStoreId()
65
+ );
66
+ $formFields['ECOM_SHIPMETHODTYPE'] = $this->getShippingMethodType(
67
+ $this->getCode(), $order->getStoreId(), $isVirtual
68
+ );
69
+ $formFields['ECOM_SHIPMETHODSPEED'] = $this->getShippingMethodSpeed(
70
+ $this->getCode(), $order->getStoreId()
71
+ );
72
+ $shipMethodDetails = $this->getShippingMethodDetails(
73
+ $this->getCode(), $order->getStoreId()
74
+ );
75
+ if (0 < strlen(trim($shipMethodDetails))) {
76
+ $formFields['ECOM_SHIPMETHODDETAILS'] = $shipMethodDetails;
77
+ }
78
+ if (4 == $formFields['ECOM_SHIPMETHODTYPE']
79
+ && !array_key_exists(
80
+ 'ECOM_SHIPMETHODDETAILS', $formFields
81
+ )
82
+ ) {
83
+ $address = $order->getShippingAddress()
84
+ ? $order->getShippingAddress()->toString()
85
+ : $order->getBillingAddress()->toString();
86
+ $formFields['ECOM_SHIPMETHODDETAILS'] = substr($address, 0, 50);
87
+ }
88
+
89
+ $formFields['ORDERSHIPMETH'] = $shippingMethod;
90
+
91
+ $formFields['CIVILITY']
92
+ = $this->getGender($order) == 'Male' ? 'Mr' : 'Mrs';
93
+ $formFields = array_merge(
94
+ $formFields, $this->getKwixoBillToParams($order)
95
+ );
96
+ $formFields = array_merge(
97
+ $formFields, $this->getKwixoShipToParams($order)
98
+ );
99
+ $formFields = array_merge(
100
+ $formFields, $this->getItemParams($order)
101
+ );
102
+
103
+ $formFields['ORDERID'] = Mage::helper('ops/order')->getOpsOrderId(
104
+ $order, false
105
+ );
106
+ $formFields = $this->populateFromArray(
107
+ $formFields, $requestParams, $order
108
+ );
109
+
110
+ return $formFields;
111
+ }
112
+
113
+
114
+ protected function getKwixoCategoryFromOrderItem(
115
+ Mage_Sales_Model_Order_Item $item
116
+ )
117
+ {
118
+ $product = Mage::getModel('catalog/product')->load(
119
+ $item->getProductId()
120
+ );
121
+ $kwixoCategoryId = null;
122
+ foreach ($product->getCategoryIds() as $categoryId) {
123
+ $kwixoCategory = Mage::getModel('ops/kwixo_category_mapping')
124
+ ->loadByCategoryId($categoryId);
125
+ if (!is_null($kwixoCategory->getId())) {
126
+ $kwixoCategoryId = $kwixoCategory->getKwixoCategoryId();
127
+ break;
128
+ }
129
+ }
130
+
131
+ return $kwixoCategoryId;
132
+ }
133
+
134
+ /**
135
+ *
136
+ *
137
+ * @param Mage_Sales_Model_Order $order
138
+ * @param array $requestParams
139
+ *
140
+ * @return array
141
+ */
142
+ public function getKwixoBillToParams(Mage_Sales_Model_Order $order)
143
+ {
144
+ $formFields = array();
145
+ $billingAddress
146
+ = $order->getBillingAddress();
147
+ $splittedStreet = $this->splitHouseNumber(
148
+ $billingAddress->getStreet1()
149
+ );
150
+ $formFields['ECOM_BILLTO_POSTAL_NAME_FIRST']
151
+ = $billingAddress->getFirstname();
152
+ $formFields['ECOM_BILLTO_POSTAL_NAME_LAST']
153
+ = $billingAddress->getLastname();
154
+ $formFields['OWNERADDRESS'] = str_replace(
155
+ "\n", ' ', $billingAddress->getStreet1()
156
+ );
157
+ if (array_key_exists('street', $splittedStreet)) {
158
+ $formFields['OWNERADDRESS'] = trim($splittedStreet['street']);
159
+ }
160
+ $streetAppendix = trim($billingAddress->getStreet2());
161
+ if (0 < strlen($streetAppendix)) {
162
+ $formFields['OWNERADDRESS2'] = $streetAppendix;
163
+ }
164
+ $formFields['ECOM_BILLTO_POSTAL_STREET_NUMBER'] = '';
165
+ if (array_key_exists('housenumber', $splittedStreet)) {
166
+ $formFields['ECOM_BILLTO_POSTAL_STREET_NUMBER']
167
+ = $splittedStreet['housenumber'];
168
+ }
169
+ $formFields['OWNERTELNO'] = $billingAddress->getTelephone();
170
+
171
+ return $formFields;
172
+ }
173
+
174
+ /**
175
+ * return the shipping parameters as array based on shipping method type
176
+ *
177
+ * @param Mage_Sales_Model_Order $order
178
+ * @param array $requestParams
179
+ *
180
+ * @return array
181
+ */
182
+ public function getKwixoShipToParams(Mage_Sales_Model_Order $order)
183
+ {
184
+ $formFields = array();
185
+ $shippingAddress = $order->getShippingAddress();
186
+ if ($shippingAddress === false) {
187
+ $shippingAddress = $order->getBillingAddress();
188
+ }
189
+ $splittedStreet = $this->splitHouseNumber(
190
+ $shippingAddress->getStreet1()
191
+ );
192
+
193
+ $shippingMethodType = (int)$this->getShippingMethodType(
194
+ $this->getCode(), $order->getStoreId()
195
+ );
196
+
197
+ if (in_array(
198
+ $shippingMethodType, $this->getShippingMethodTypeValues()
199
+ )
200
+ ) {
201
+ if (4 === $shippingMethodType) {
202
+ $formFields['ECOM_SHIPTO_POSTAL_NAME_PREFIX']
203
+ = $shippingAddress->getPrefix();
204
+ }
205
+
206
+
207
+ $company = trim($shippingAddress->getCompany());
208
+ if (0 < strlen($company)) {
209
+ $formFields['ECOM_SHIPTO_COMPANY'] = $company;
210
+ }
211
+ $fax = trim($shippingAddress->getFax());
212
+ if (0 < strlen($fax)) {
213
+ $formFields['ECOM_SHIPTO_TELECOM_FAX_NUMBER'] = $fax;
214
+ }
215
+
216
+
217
+ $formFields['ECOM_SHIPTO_POSTAL_STREET_LINE1']
218
+ = $shippingAddress->getStreet1();
219
+ if (array_key_exists('street', $splittedStreet)) {
220
+ $formFields['ECOM_SHIPTO_POSTAL_STREET_LINE1']
221
+ = $splittedStreet['street'];
222
+ }
223
+ $streetAppendix = trim($shippingAddress->getStreet2());
224
+ if (0 < strlen($streetAppendix)) {
225
+ $formFields['ECOM_SHIPTO_POSTAL_STREET_LINE2']
226
+ = $streetAppendix;
227
+ }
228
+ $formFields['ECOM_SHIPTO_POSTAL_STREET_NUMBER'] = '';
229
+ if (array_key_exists('housenumber', $splittedStreet)) {
230
+ $formFields['ECOM_SHIPTO_POSTAL_STREET_NUMBER']
231
+ = $splittedStreet['housenumber'];
232
+ }
233
+ $formFields['ECOM_SHIPTO_POSTAL_POSTALCODE']
234
+ = $shippingAddress->getPostcode();
235
+ $formFields['ECOM_SHIPTO_POSTAL_CITY']
236
+ = $shippingAddress->getCity();
237
+ $formFields['ECOM_SHIPTO_POSTAL_COUNTRYCODE']
238
+ = $shippingAddress->getCountryId();
239
+ }
240
+ $formFields['ECOM_SHIPTO_POSTAL_NAME_FIRST']
241
+ = $shippingAddress->getFirstname();
242
+ $formFields['ECOM_SHIPTO_POSTAL_NAME_LAST']
243
+ = $shippingAddress->getLastname();
244
+ $formFields['ECOM_SHIPTO_TELECOM_PHONE_NUMBER']
245
+ = $shippingAddress->getTelephone();
246
+
247
+ return $formFields;
248
+ }
249
+
250
+ /**
251
+ * return item params for the order
252
+ * for each item a ascending number will be added to the parameter name
253
+ *
254
+ * @param Mage_Sales_Model_Order $order
255
+ *
256
+ * @return array
257
+ */
258
+ public function getItemParams(Mage_Sales_Model_Order $order)
259
+ {
260
+ $formFields = array();
261
+ $items = $order->getAllItems();
262
+ $subtotal = 0;
263
+ if (is_array($items)) {
264
+ $itemCounter = 1;
265
+ foreach ($items as $item) {
266
+ if ($item->getParentItemId()) {
267
+ continue;
268
+ }
269
+
270
+ $subtotal += $item->getBasePriceInclTax(
271
+ ) * $item->getQtyOrdered();
272
+ $formFields['ITEMFDMPRODUCTCATEG' . $itemCounter]
273
+ = $this->getKwixoCategoryFromOrderItem(
274
+ $item
275
+ );
276
+ $formFields['ITEMID' . $itemCounter] = $item->getItemId();
277
+ $formFields['ITEMNAME' . $itemCounter] = substr(
278
+ $item->getName(), 0, 40
279
+ );
280
+ $formFields['ITEMPRICE' . $itemCounter] = number_format(
281
+ $item->getBasePriceInclTax(), 2, '.', ''
282
+ );
283
+ $formFields['ITEMQUANT' . $itemCounter]
284
+ = (int)$item->getQtyOrdered(
285
+ );
286
+ $formFields['ITEMVAT' . $itemCounter] = str_replace(
287
+ ',', '.', (string)(float)$item->getBaseTaxAmount()
288
+ );
289
+ $formFields['TAXINCLUDED' . $itemCounter] = 1;
290
+ $itemCounter++;
291
+ }
292
+ $shippingPrice = $order->getBaseShippingAmount();
293
+ $shippingPriceInclTax = $order->getBaseShippingInclTax();
294
+ $subtotal += $shippingPriceInclTax;
295
+ $shippingTaxAmount = $shippingPriceInclTax - $shippingPrice;
296
+
297
+ $roundingError = $order->getBaseGrandTotal() - $subtotal;
298
+ $shippingPrice += $roundingError;
299
+ /* add shipping item */
300
+ $formFields['ITEMFDMPRODUCTCATEG' . $itemCounter] = 1;
301
+ $formFields['ITEMID' . $itemCounter] = 'SHIPPING';
302
+ $shippingDescription
303
+ =
304
+ 0 < strlen(trim($order->getShippingDescription()))
305
+ ? $order->getShippingDescription() : 'shipping';
306
+ $formFields['ITEMNAME' . $itemCounter] = substr(
307
+ $shippingDescription, 0, 30
308
+ );
309
+ $formFields['ITEMPRICE' . $itemCounter] = number_format(
310
+ $shippingPrice, 2, '.', ''
311
+ );
312
+ $formFields['ITEMQUANT' . $itemCounter] = 1;
313
+ $formFields['ITEMVAT' . $itemCounter] = number_format(
314
+ $shippingTaxAmount, 2, '.', ''
315
+ );
316
+ }
317
+
318
+ return $formFields;
319
+ }
320
+
321
+ /**
322
+ * splits house number and street for france addresses
323
+ *
324
+ * @param string $address
325
+ *
326
+ * @return array
327
+ */
328
+ public function splitHouseNumber($address)
329
+ {
330
+ $splittedStreet = array();
331
+ $street = str_replace("\n", ' ', $address);
332
+ $regexp = '/(?P<housenumber>[0-9]+)([,:\s])(?P<street>.+)/';
333
+ if (!preg_match($regexp, $street, $splittedStreet)) {
334
+ $splittedStreet[1] = $street;
335
+ $splittedStreet[2] = '';
336
+ }
337
+
338
+ return $splittedStreet;
339
+ }
340
+
341
+ /**
342
+ * returns the delivery date as date based on actual date and adding
343
+ * the configurated value as days to it
344
+ *
345
+ * @param string $code
346
+ * @param string $storeId
347
+ *
348
+ * @return bool|string
349
+ */
350
+ public function getEstimatedDeliveryDate($code, $storeId = null)
351
+ {
352
+ $dateNow = date("Y-m-d");
353
+ $dayValue = (string)Mage::getStoreConfig(
354
+ 'payment/' . $code . "/delivery_date", $storeId
355
+ );
356
+ $deliveryDate = strtotime($dateNow . "+" . $dayValue . "days");
357
+
358
+ return date("Y-m-d", $deliveryDate);
359
+ }
360
+
361
+ /**
362
+ * return the RNP Fee value
363
+ *
364
+ * @param string $code
365
+ * @param int $storeId
366
+ *
367
+ * @return boolean
368
+ */
369
+ public function getRnpFee($code, $storeId = null)
370
+ {
371
+ return (int)(bool)Mage::getStoreConfig(
372
+ "payment/" . $code . "/rnp_fee", $storeId
373
+ );
374
+ }
375
+
376
+ /**
377
+ * returns the Shipping Method Type configured in backend
378
+ *
379
+ * @param string $code
380
+ * @param int $storeId
381
+ *
382
+ * @return string
383
+ */
384
+ public function getShippingMethodType(
385
+ $code, $storeId = null, $isVirtual = false
386
+ )
387
+ {
388
+ // use download type for orders containing virtual products only
389
+ if ($isVirtual) {
390
+ return Netresearch_OPS_Model_Source_Kwixo_ShipMethodType::DOWNLOAD;
391
+ }
392
+ $shippingMethodType = $this->getKwixoShippingModel()
393
+ ->getKwixoShippingType();
394
+ if (null === $shippingMethodType) {
395
+ $shippingMethodType = Mage::getStoreConfig(
396
+ "payment/" . $code . "/ecom_shipMethodType", $storeId
397
+ );
398
+ }
399
+
400
+ return $shippingMethodType;
401
+ }
402
+
403
+ /**
404
+ * return the shipping method speed configured in backend
405
+ *
406
+ * @param string $code
407
+ * @param int $storeId
408
+ *
409
+ * @return int
410
+ */
411
+ public function getShippingMethodSpeed($code, $storeId = null)
412
+ {
413
+ $shippingMethodSpeed = $this->getKwixoShippingModel()
414
+ ->getKwixoShippingMethodSpeed();
415
+ if (null === $shippingMethodSpeed) {
416
+ $shippingMethodSpeed = Mage::getStoreConfig(
417
+ "payment/" . $code . "/ecom_shipMethodSpeed", $storeId
418
+ );
419
+ }
420
+
421
+ return (int)$shippingMethodSpeed;
422
+ }
423
+
424
+ /**
425
+ * return the item product categories configured in backend as array
426
+ *
427
+ * @param string $code
428
+ * @param int $storeId
429
+ *
430
+ * @return array
431
+ */
432
+ public function getItemFmdProductCateg($code, $storeId = null)
433
+ {
434
+ return explode(
435
+ ",", Mage::getStoreConfig(
436
+ "payment/" . $code . "/product_categories", $storeId
437
+ )
438
+ );
439
+ }
440
+
441
+ /**
442
+ * return the shipping method detail text
443
+ *
444
+ * @param string $code
445
+ * @param int $storeId
446
+ *
447
+ * @return string
448
+ */
449
+ public function getShippingMethodDetails($code, $storeId = null)
450
+ {
451
+ $shippingMethodDetails = $this->getKwixoShippingModel()
452
+ ->getKwixoShippingDetails();
453
+ if (null === $shippingMethodDetails) {
454
+ $shippingMethodDetails = Mage::getStoreConfig(
455
+ "payment/" . $code . "/shiping_method_details", $storeId
456
+ );
457
+ }
458
+
459
+ return $shippingMethodDetails;
460
+ }
461
+
462
+ /**
463
+ * get question for fields with disputable value
464
+ * users are asked to correct the values before redirect to Ingenico Payment Services
465
+ *
466
+ * @param Mage_Sales_Model_Order $order Current order
467
+ * @param array $requestParams Request parameters
468
+ *
469
+ * @return string
470
+ */
471
+ public function getQuestion($order, $requestParams)
472
+ {
473
+ return Mage::helper('ops/data')->__(
474
+ 'Please make sure that the displayed data is correct.'
475
+ );
476
+ }
477
+
478
+ /**
479
+ * get an array of fields with disputable value
480
+ * users are asked to correct the values before redirect to Ingenico Payment Services
481
+ *
482
+ * @param Mage_Sales_Model_Order $order Current order
483
+ * @param array $requestParams Request parameters
484
+ *
485
+ * @return array
486
+ */
487
+ public function getQuestionedFormFields($order, $requestParams)
488
+ {
489
+ $questionedFormFields = array(
490
+ 'CIVILITY',
491
+ 'OWNERADDRESS',
492
+ 'ECOM_BILLTO_POSTAL_STREET_NUMBER',
493
+
494
+ );
495
+ $storeId = null;
496
+ if ($order instanceof Mage_Sales_Model_Order) {
497
+ $storeId = $order->getStoreId();
498
+ }
499
+ $shippingMethodType = (int)$this->getShippingMethodType(
500
+ $this->getCode(), $storeId
501
+ );
502
+ if (in_array(
503
+ $shippingMethodType, $this->getShippingMethodTypeValues()
504
+ )
505
+ ) {
506
+ $questionedFormFields [] = 'ECOM_SHIPTO_POSTAL_STREET_NUMBER';
507
+ $questionedFormFields [] = 'ECOM_SHIPTO_POSTAL_STREET_LINE1';
508
+ }
509
+
510
+ if ($shippingMethodType === 4) {
511
+ $questionedFormFields [] = 'ECOM_SHIPTO_TELECOM_PHONE_NUMBER';
512
+ $questionedFormFields [] = 'ECOM_SHIPTO_POSTAL_NAME_PREFIX';
513
+ }
514
+
515
+ return $questionedFormFields;
516
+ }
517
+
518
+ /**
519
+ * return shipping method values except for the type download
520
+ *
521
+ * @return array
522
+ */
523
+ public function getShippingMethodTypeValues()
524
+ {
525
+ return array(1, 2, 3, 4);
526
+ }
527
+
528
+ /**
529
+ * populates an array with the values from another if the keys are matching
530
+ *
531
+ * @param array $formFields - the array to populate
532
+ * @param null $dataArray - the array containing the data
533
+ *
534
+ * @return array - the populated array
535
+ */
536
+ protected function populateFromArray(
537
+ array $formFields, $dataArray = null, $order
538
+ )
539
+ {
540
+ // copy some already known values, but only the ones from the questioned
541
+ // form fields
542
+ if (is_array($dataArray)) {
543
+ foreach ($dataArray as $key => $value) {
544
+ if (array_key_exists($key, $formFields)
545
+ && in_array(
546
+ $key,
547
+ $this->getQuestionedFormFields($order, $dataArray), true
548
+ )
549
+ || $key == 'CIVILITY'
550
+ ) {
551
+ $formFields[$key] = $value;
552
+ }
553
+ }
554
+ }
555
+
556
+ return $formFields;
557
+ }
558
+
559
+ /**
560
+ * get gender text for customer
561
+ *
562
+ * @param Mage_Sales_Model_Order $order
563
+ */
564
+ public function getGender(Mage_Sales_Model_Order $order)
565
+ {
566
+ $gender = Mage::getSingleton('eav/config')
567
+ ->getAttribute('customer', 'gender')
568
+ ->getSource()
569
+ ->getOptionText($order->getCustomerGender());
570
+
571
+ return $gender;
572
+ }
573
+
574
+ /**
575
+ * sets the kwixo shipping setting model
576
+ *
577
+ * @param Netresearch_OPS_Model_Kwixo_Shipping_Setting $kwixoShippingModel
578
+ */
579
+ public function setKwixoShippingModel(
580
+ Netresearch_OPS_Model_Kwixo_Shipping_Setting $kwixoShippingModel
581
+ )
582
+ {
583
+ $this->kwixoShippingModel = $kwixoShippingModel;
584
+ }
585
+
586
+ /**
587
+ * returns the kwixo shipping setting model
588
+ *
589
+ * @return Netresearch_OPS_Model_Kwixo_Shipping_Setting
590
+ */
591
+ public function getKwixoShippingModel()
592
+ {
593
+ if (null === $this->kwixoShippingModel) {
594
+ $this->kwixoShippingModel = Mage::getModel(
595
+ 'ops/kwixo_shipping_setting'
596
+ );
597
+ }
598
+
599
+ return $this->kwixoShippingModel;
600
+ }
601
+
602
+ /**
603
+ * @param $carrierCode
604
+ */
605
+ private function loadShippingSettingForCarrierCode($carrierCode)
606
+ {
607
+ $this->shippingSettings = $this->getKwixoShippingModel()->load(
608
+ $carrierCode, 'shipping_code'
609
+ );
610
+
611
+ return $this->shippingSettings;
612
+ }
613
+ }
app/code/community/Netresearch/OPS/Model/Payment/KwixoApresReception.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Netresearch_OPS_Model_Payment_ApresReception
4
+ *
5
+ * @package
6
+ * @copyright 2013 Netresearch
7
+ * @author Sebastian Ertner <sebastian.ertner@netresearch.de>
8
+ * @license OSL 3.0
9
+ */
10
+ class Netresearch_OPS_Model_Payment_KwixoApresReception extends Netresearch_OPS_Model_Payment_Kwixo_Abstract
11
+ {
12
+
13
+ const OPS_CODE = "KWIXO_RNP";
14
+
15
+ /** Check if we can capture directly from the backend */
16
+ protected $_canBackendDirectCapture = true;
17
+
18
+ protected $_formBlockType = 'ops/form_kwixo_apresReception';
19
+
20
+ /** info source path */
21
+ protected $_infoBlockType = 'ops/info_redirect';
22
+
23
+ /** payment code */
24
+ protected $_code = 'ops_kwixoApresReception';
25
+
26
+ public function getOpsCode($payment = null)
27
+ {
28
+ return self::OPS_CODE;
29
+ }
30
+
31
+ /**
32
+ * getter for _code
33
+ *
34
+ * @return string
35
+ */
36
+ public function getCode()
37
+ {
38
+ return $this->_code;
39
+ }
40
+ }
app/code/community/Netresearch/OPS/Model/Payment/KwixoComptant.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Netresearch_OPS_Model_Payment_ApresReception
4
+ *
5
+ * @package
6
+ * @copyright 2013 Netresearch
7
+ * @author Sebastian Ertner <sebastian.ertner@netresearch.de>
8
+ * @license OSL 3.0
9
+ */
10
+ class Netresearch_OPS_Model_Payment_KwixoComptant extends Netresearch_OPS_Model_Payment_Kwixo_Abstract
11
+ {
12
+
13
+ const OPS_CODE = "KWIXO_STANDARD";
14
+
15
+ /** Check if we can capture directly from the backend */
16
+ protected $_canBackendDirectCapture = true;
17
+
18
+ protected $_formBlockType = 'ops/form_kwixo_comptant';
19
+
20
+ /** info source path */
21
+ protected $_infoBlockType = 'ops/info_redirect';
22
+
23
+
24
+ /** payment code */
25
+ protected $_code = 'ops_kwixoComptant';
26
+
27
+ public function getOpsCode($payment = null)
28
+ {
29
+ return self::OPS_CODE;
30
+ }
31
+
32
+ /**
33
+ * getter for _code
34
+ *
35
+ * @return string
36
+ */
37
+ public function getCode()
38
+ {
39
+ return $this->_code;
40
+ }
41
+ }
app/code/community/Netresearch/OPS/Model/Payment/KwixoCredit.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Netresearch_OPS_Model_Payment_KwixoCredit
5
+ *
6
+ * @package
7
+ * @copyright 2013 Netresearch
8
+ * @author Sebastian Ertner <sebastian.ertner@netresearch.de>
9
+ * @license OSL 3.0
10
+ */
11
+ class Netresearch_OPS_Model_Payment_KwixoCredit extends Netresearch_OPS_Model_Payment_Kwixo_Abstract
12
+ {
13
+ const OPS_CODE = "KWIXO_CREDIT";
14
+
15
+ /** Check if we can capture directly from the backend */
16
+ protected $_canBackendDirectCapture = true;
17
+
18
+ /** info source path */
19
+ protected $_infoBlockType = 'ops/info_redirect';
20
+
21
+
22
+ protected $_formBlockType = 'ops/form_kwixo_credit';
23
+
24
+ /** payment code */
25
+ protected $_code = 'ops_kwixoCredit';
26
+
27
+ public function getOpsCode($payment = null)
28
+ {
29
+ return self::OPS_CODE;
30
+ }
31
+
32
+ /**
33
+ * getter for _code
34
+ *
35
+ * @return string
36
+ */
37
+ public function getCode()
38
+ {
39
+ return $this->_code;
40
+ }
41
+ }
app/code/community/Netresearch/OPS/Model/Payment/MiniTix.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Netresearch_OPS_Model_Payment_MiniTix
4
+ *
5
+ * @package
6
+ * @copyright 2011 Netresearch
7
+ * @author Thomas Kappel <thomas.kappel@netresearch.de>
8
+ * @license OSL 3.0
9
+ */
10
+ class Netresearch_OPS_Model_Payment_MiniTix
11
+ extends Netresearch_OPS_Model_Payment_Abstract
12
+ {
13
+ /** Check if we can capture directly from the backend */
14
+ protected $_canBackendDirectCapture = true;
15
+
16
+ /** info source path */
17
+ protected $_infoBlockType = 'ops/info_redirect';
18
+
19
+ /** payment code */
20
+ protected $_code = 'ops_miniTix';
21
+ }
22
+
app/code/community/Netresearch/OPS/Model/Payment/Mpass.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Netresearch_OPS_Model_Payment_Mpass
4
+ *
5
+ * @package
6
+ * @copyright 2011 Netresearch
7
+ * @author Thomas Kappel <thomas.kappel@netresearch.de>
8
+ * @license OSL 3.0
9
+ */
10
+ class Netresearch_OPS_Model_Payment_Mpass
11
+ extends Netresearch_OPS_Model_Payment_Abstract
12
+ {
13
+ /** Check if we can capture directly from the backend */
14
+ protected $_canBackendDirectCapture = true;
15
+
16
+ /** info source path */
17
+ protected $_infoBlockType = 'ops/info_redirect';
18
+
19
+ /** payment code */
20
+ protected $_code = 'ops_mpass';
21
+
22
+ /** ops payment code */
23
+ public function getOpsCode($payment=null)
24
+ {
25
+ return 'MPASS';
26
+ }
27
+ }
28
+
app/code/community/Netresearch/OPS/Model/Payment/OpenInvoice/Abstract.php ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Netresearch_OPS
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * open invoice payment via Ingenico Payment Services
29
+ */
30
+ class Netresearch_OPS_Model_Payment_OpenInvoice_Abstract extends Netresearch_OPS_Model_Payment_Abstract
31
+ {
32
+ const CODE = '';
33
+
34
+ protected $_needsCartDataForRequest = true;
35
+
36
+ public function getMethodDependendFormFields($order, $requestParams=null)
37
+ {
38
+ $formFields = array();
39
+ $billingAddress = $order->getBillingAddress();
40
+ $shippingAddress = $order->getShippingAddress();
41
+ $birthday = new DateTime($order->getCustomerDob());
42
+
43
+ //$formFields['ECOM_SHIPTO_POSTAL_NAME_PREFIX'] = $shippingAddress->getPrefix();
44
+ $formFields['ECOM_BILLTO_POSTAL_NAME_FIRST'] = substr($billingAddress->getFirstname(), 0, 50);
45
+ $formFields['ECOM_BILLTO_POSTAL_NAME_LAST'] = substr($billingAddress->getLastname(), 0, 50);
46
+ $formFields['ECOM_SHIPTO_DOB'] = $birthday->format('d/m/Y');
47
+
48
+ return $formFields;
49
+ }
50
+
51
+ public function getOpsCode($payment = null)
52
+ {
53
+ return self::CODE;
54
+ }
55
+
56
+
57
+ }
app/code/community/Netresearch/OPS/Model/Payment/OpenInvoiceDe.php ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Netresearch_OPS_Model_Payment_OpenInvoiceDe
4
+ *
5
+ * @package
6
+ * @copyright 2011 Netresearch
7
+ * @author Thomas Kappel <thomas.kappel@netresearch.de>
8
+ * @license OSL 3.0
9
+ */
10
+ class Netresearch_OPS_Model_Payment_OpenInvoiceDe
11
+ extends Netresearch_OPS_Model_Payment_OpenInvoice_Abstract
12
+ {
13
+ const CODE = 'Open Invoice DE';
14
+
15
+ /** if we can capture directly from the backend */
16
+ protected $_canBackendDirectCapture = false;
17
+
18
+ protected $_canCapturePartial = false;
19
+ protected $_canRefundInvoicePartial = false;
20
+
21
+ /** info source path */
22
+ protected $_infoBlockType = 'ops/info_redirect';
23
+
24
+ /** payment code */
25
+ protected $_code = 'ops_openInvoiceDe';
26
+
27
+ /**
28
+ * Open Invoice DE is not available if quote has a coupon
29
+ *
30
+ * @param Mage_Sales_Model_Quote $quote
31
+ * @return boolean
32
+ */
33
+ public function isAvailable($quote=null)
34
+ {
35
+ /* availability depends on quote */
36
+ if (false == $quote instanceof Mage_Sales_Model_Quote) {
37
+ return false;
38
+ }
39
+
40
+ /* not available if quote contains a coupon and allow_discounted_carts is disabled */
41
+ if (!$this->isAvailableForDiscountedCarts()
42
+ && $quote->getSubtotal() != $quote->getSubtotalWithDiscount()
43
+ ) {
44
+ return false;
45
+ }
46
+
47
+ /* not available if there is no gender or no birthday */
48
+ if (is_null($quote->getCustomerGender()) || is_null($quote->getCustomerDob())) {
49
+ return false;
50
+ }
51
+
52
+ return parent::isAvailable($quote);
53
+ }
54
+
55
+ public function getPaymentAction()
56
+ {
57
+ return Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE;
58
+ }
59
+
60
+ public function getMethodDependendFormFields($order, $requestParams=null)
61
+ {
62
+ $formFields = parent::getMethodDependendFormFields($order, $requestParams);
63
+
64
+ $shippingAddress = $order->getShippingAddress();
65
+ $birthday = new DateTime($order->getCustomerDob());
66
+
67
+ $gender = Mage::getSingleton('eav/config')
68
+ ->getAttribute('customer', 'gender')
69
+ ->getSource()
70
+ ->getOptionText($order->getCustomerGender());
71
+
72
+ $formFields['CIVILITY'] = $gender == 'Male' ? 'Herr' : 'Frau';
73
+ $formFields['ORDERSHIPCOST'] = round(100 * $order->getBaseShippingInclTax());
74
+
75
+ if (!$this->getConfig()->canSubmitExtraParameter($order->getStoreId())) {
76
+ // add the shipto parameters even if the submitOption is false, because they are required for OpenInvoice
77
+ $shipToParams = $this->getRequestHelper()->extractShipToParameters($shippingAddress, $order);
78
+ $formFields = array_merge($formFields, $shipToParams);
79
+ }
80
+
81
+ return $formFields;
82
+ }
83
+
84
+ /**
85
+ * getter for the allow_discounted_carts
86
+ *
87
+ * @return array
88
+ */
89
+ protected function isAvailableForDiscountedCarts()
90
+ {
91
+ return (bool) $this->getConfigData('allow_discounted_carts');
92
+ }
93
+
94
+ public function getOpsCode($payment = null)
95
+ {
96
+ return self::CODE;
97
+ }
98
+ }
99
+
app/code/community/Netresearch/OPS/Model/Payment/OpenInvoiceNl.php ADDED
@@ -0,0 +1,150 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Netresearch_OPS_Model_Payment_OpenInvoiceNl
4
+ *
5
+ * @package
6
+ * @copyright 2011 Netresearch
7
+ * @author Thomas Kappel <thomas.kappel@netresearch.de>
8
+ * @license OSL 3.0
9
+ */
10
+ class Netresearch_OPS_Model_Payment_OpenInvoiceNl
11
+ extends Netresearch_OPS_Model_Payment_OpenInvoice_Abstract
12
+ {
13
+ const CODE = 'Open Invoice NL';
14
+
15
+ /** if we can capture directly from the backend */
16
+ protected $_canBackendDirectCapture = false;
17
+
18
+
19
+ /** info source path */
20
+ protected $_infoBlockType = 'ops/info_redirect';
21
+
22
+ /** payment code */
23
+ protected $_code = 'ops_openInvoiceNl';
24
+
25
+
26
+ /**
27
+ * Open Invoice NL is not available if quote has a coupon
28
+ *
29
+ * @param Mage_Sales_Model_Quote $quote
30
+ * @return boolean
31
+ */
32
+ public function isAvailable($quote=null)
33
+ {
34
+ /* availability depends on quote */
35
+ if (false == $quote instanceof Mage_Sales_Model_Quote) {
36
+ return false;
37
+ }
38
+
39
+ /* not available if there is no gender or no birthday */
40
+ if (is_null($quote->getCustomerGender()) || is_null($quote->getCustomerDob())) {
41
+ return false;
42
+ }
43
+
44
+ return parent::isAvailable($quote);
45
+ }
46
+
47
+ /**
48
+ * get some method dependend form fields
49
+ *
50
+ * @param Mage_Sales_Model_Quote $order
51
+ * @return array
52
+ */
53
+ public function getMethodDependendFormFields($order, $requestParams=null)
54
+ {
55
+ $billingAddress = $order->getBillingAddress();
56
+ $shippingAddress = $order->getShippingAddress();
57
+ $street = str_replace("\n", ' ',$billingAddress->getStreet(-1));
58
+ $regexp = '/^([^0-9]*)([0-9].*)$/';
59
+ if (!preg_match($regexp, $street, $splittedStreet)) {
60
+ $splittedStreet[1] = $street;
61
+ $splittedStreet[2] = '';
62
+ }
63
+ $formFields = parent::getMethodDependendFormFields($order, $requestParams);
64
+
65
+ $gender = Mage::getSingleton('eav/config')
66
+ ->getAttribute('customer', 'gender')
67
+ ->getSource()
68
+ ->getOptionText($order->getCustomerGender());
69
+
70
+ $formFields['CIVILITY'] = $gender == 'Male' ? 'M' : 'V';
71
+ $formFields['OWNERADDRESS'] = trim($splittedStreet[1]);
72
+ $formFields['ECOM_BILLTO_POSTAL_STREET_NUMBER'] = trim($splittedStreet[2]);
73
+ $formFields['OWNERZIP'] = $billingAddress->getPostcode();
74
+ $formFields['OWNERTOWN'] = $billingAddress->getCity();
75
+ $formFields['OWNERCTY'] = $billingAddress->getCountry();
76
+ $formFields['OWNERTELNO'] = $billingAddress->getTelephone();
77
+
78
+ $street = str_replace("\n", ' ',$shippingAddress->getStreet(-1));
79
+ if (!preg_match($regexp, $street, $splittedStreet)) {
80
+ $splittedStreet[1] = $street;
81
+ $splittedStreet[2] = '';
82
+ }
83
+ $formFields['ECOM_SHIPTO_POSTAL_NAME_PREFIX'] = $shippingAddress->getPrefix();
84
+ $formFields['ECOM_SHIPTO_POSTAL_NAME_FIRST'] = $shippingAddress->getFirstname();
85
+ $formFields['ECOM_SHIPTO_POSTAL_NAME_LAST'] = $shippingAddress->getLastname();
86
+ $formFields['ECOM_SHIPTO_POSTAL_STREET_LINE1'] = trim($splittedStreet[1]);
87
+ $formFields['ECOM_SHIPTO_POSTAL_STREET_NUMBER'] = trim($splittedStreet[2]);
88
+ $formFields['ECOM_SHIPTO_POSTAL_POSTALCODE'] = $shippingAddress->getPostcode();
89
+ $formFields['ECOM_SHIPTO_POSTAL_CITY'] = $shippingAddress->getCity();
90
+ $formFields['ECOM_SHIPTO_POSTAL_COUNTRYCODE'] = $shippingAddress->getCountry();
91
+
92
+ // copy some already known values
93
+ $formFields['ECOM_SHIPTO_ONLINE_EMAIL'] = $order->getCustomerEmail();
94
+
95
+ if (is_array($requestParams)) {
96
+ if (array_key_exists('OWNERADDRESS', $requestParams)) {
97
+ $formFields['OWNERADDRESS'] = $requestParams['OWNERADDRESS'];
98
+ }
99
+ if (array_key_exists('ECOM_BILLTO_POSTAL_STREET_NUMBER', $requestParams)) {
100
+ $formFields['ECOM_BILLTO_POSTAL_STREET_NUMBER'] = $requestParams['ECOM_BILLTO_POSTAL_STREET_NUMBER'];
101
+ }
102
+ if (array_key_exists('ECOM_SHIPTO_POSTAL_STREET_LINE1', $requestParams)) {
103
+ $formFields['ECOM_SHIPTO_POSTAL_STREET_LINE1'] = $requestParams['ECOM_SHIPTO_POSTAL_STREET_LINE1'];
104
+ }
105
+ if (array_key_exists('ECOM_SHIPTO_POSTAL_STREET_NUMBER', $requestParams)) {
106
+ $formFields['ECOM_SHIPTO_POSTAL_STREET_NUMBER'] = $requestParams['ECOM_SHIPTO_POSTAL_STREET_NUMBER'];
107
+ }
108
+ }
109
+
110
+ return $formFields;
111
+ }
112
+
113
+ /**
114
+ * get question for fields with disputable value
115
+ * users are asked to correct the values before redirect to Ingenico Payment Services
116
+ *
117
+ * @param Mage_Sales_Model_Order $order Current order
118
+ * @param array $requestParams Request parameters
119
+ * @return string
120
+ */
121
+ public function getQuestion($order, $requestParams)
122
+ {
123
+ return Mage::helper('ops')->__('Please make sure that your street and house number are correct.');
124
+ }
125
+
126
+ /**
127
+ * get an array of fields with disputable value
128
+ * users are asked to correct the values before redirect to Ingenico Payment Services
129
+ *
130
+ * @param Mage_Sales_Model_Order $order Current order
131
+ * @param array $requestParams Request parameters
132
+ * @return array
133
+ */
134
+ public function getQuestionedFormFields($order, $requestParams)
135
+ {
136
+ return array(
137
+ 'OWNERADDRESS',
138
+ 'ECOM_BILLTO_POSTAL_STREET_NUMBER',
139
+ 'ECOM_SHIPTO_POSTAL_STREET_LINE1',
140
+ 'ECOM_SHIPTO_POSTAL_STREET_NUMBER',
141
+ );
142
+ }
143
+
144
+ public function getOpsCode($payment = null)
145
+ {
146
+ return self::CODE;
147
+ }
148
+
149
+
150
+ }
app/code/community/Netresearch/OPS/Model/Payment/Other.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Other.php
4
+ * @author paul.siedler@netresearch.de
5
+ * @copyright Copyright (c) 2015 Netresearch GmbH & Co. KG
6
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License
7
+ */
8
+
9
+ class Netresearch_OPS_Model_Payment_Other extends Netresearch_OPS_Model_Payment_Abstract {
10
+
11
+ const CODE = 'ops_other';
12
+
13
+ /** Check if we can capture directly from the backend */
14
+ protected $_canBackendDirectCapture = true;
15
+
16
+ /** info source path */
17
+ protected $_infoBlockType = 'ops/info_redirect';
18
+
19
+ protected $_formBlockType = 'ops/form_other';
20
+
21
+ /** payment code */
22
+ protected $_code = self::CODE;
23
+
24
+ protected $_needsCartDataForRequest = true;
25
+
26
+ public function getOpsCode($payment = null)
27
+ {
28
+ return '';
29
+ }
30
+
31
+
32
+ }
app/code/community/Netresearch/OPS/Model/Payment/Paypal.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Netresearch_OPS_Model_Payment_Paypal
4
+ *
5
+ * @package
6
+ * @copyright 2011 Netresearch
7
+ * @author Thomas Kappel <thomas.kappel@netresearch.de>
8
+ * @license OSL 3.0
9
+ */
10
+ class Netresearch_OPS_Model_Payment_Paypal
11
+ extends Netresearch_OPS_Model_Payment_Abstract
12
+ {
13
+ /** Check if we can capture directly from the backend */
14
+ protected $_canBackendDirectCapture = true;
15
+
16
+ /** info source path */
17
+ protected $_infoBlockType = 'ops/info_redirect';
18
+
19
+ /** payment code */
20
+ protected $_code = 'ops_paypal';
21
+
22
+ public function getOpsCode($payment = null)
23
+ {
24
+ return 'PAYPAL';
25
+ }
26
+ }
27
+
app/code/community/Netresearch/OPS/Model/Payment/Paysafecard.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Netresearch_OPS_Model_Payment_Paysafecard
4
+ *
5
+ * @package
6
+ * @copyright 2011 Netresearch
7
+ * @author Thomas Kappel <thomas.kappel@netresearch.de>
8
+ * @license OSL 3.0
9
+ */
10
+ class Netresearch_OPS_Model_Payment_Paysafecard
11
+ extends Netresearch_OPS_Model_Payment_Abstract
12
+ {
13
+ /** Check if we can capture directly from the backend */
14
+ protected $_canBackendDirectCapture = true;
15
+
16
+ /** info source path */
17
+ protected $_infoBlockType = 'ops/info_redirect';
18
+
19
+ /** payment code */
20
+ protected $_code = 'ops_paysafecard';
21
+ }
22
+
app/code/community/Netresearch/OPS/Model/Payment/PingPing.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Netresearch_OPS_Model_Payment_PingPing
4
+ *
5
+ * @package
6
+ * @copyright 2011 Netresearch
7
+ * @author Thomas Kappel <thomas.kappel@netresearch.de>
8
+ * @license OSL 3.0
9
+ */
10
+ class Netresearch_OPS_Model_Payment_PingPing
11
+ extends Netresearch_OPS_Model_Payment_Abstract
12
+ {
13
+ /** Check if we can capture directly from the backend */
14
+ protected $_canBackendDirectCapture = true;
15
+
16
+ /** info source path */
17
+ protected $_infoBlockType = 'ops/info_redirect';
18
+
19
+ /** payment code */
20
+ protected $_code = 'ops_pingPing';
21
+
22
+ public function getOpsCode($payment=null)
23
+ {
24
+ return 'PingPing';
25
+ }
26
+ }
27
+
app/code/community/Netresearch/OPS/Model/Payment/PostFinanceEFinance.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Netresearch_OPS_Model_Payment_PostFinanceEFinance
4
+ *
5
+ * @package
6
+ * @copyright 2011 Netresearch
7
+ * @author Thomas Kappel <thomas.kappel@netresearch.de>
8
+ * @license OSL 3.0
9
+ */
10
+ class Netresearch_OPS_Model_Payment_PostFinanceEFinance
11
+ extends Netresearch_OPS_Model_Payment_Abstract
12
+ {
13
+ /** Check if we can capture directly from the backend */
14
+ protected $_canBackendDirectCapture = true;
15
+
16
+ /** info source path */
17
+ protected $_infoBlockType = 'ops/info_redirect';
18
+
19
+ /** payment code */
20
+ protected $_code = 'ops_postFinanceEFinance';
21
+
22
+ /** ops payment code */
23
+ public function getOpsCode($payment=null)
24
+ {
25
+ return 'PostFinance e-finance';
26
+ }
27
+ }
28
+
app/code/community/Netresearch/OPS/Model/Payment/Tunz.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Netresearch_OPS_Model_Payment_Tunz
4
+ *
5
+ * @package
6
+ * @copyright 2011 Netresearch
7
+ * @author Thomas Kappel <thomas.kappel@netresearch.de>
8
+ * @license OSL 3.0
9
+ */
10
+ class Netresearch_OPS_Model_Payment_Tunz
11
+ extends Netresearch_OPS_Model_Payment_Abstract
12
+ {
13
+ /** Check if we can capture directly from the backend */
14
+ protected $_canBackendDirectCapture = true;
15
+
16
+ /** info source path */
17
+ protected $_infoBlockType = 'ops/info_redirect';
18
+
19
+ /** payment code */
20
+ protected $_code = 'ops_tunz';
21
+
22
+ public function getOpsCode($payment=null)
23
+ {
24
+ return 'TUNZ';
25
+ }
26
+ }
27
+
app/code/community/Netresearch/OPS/Model/Payment/Wallie.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Netresearch_OPS_Model_Payment_Wallie
4
+ *
5
+ * @package
6
+ * @copyright 2011 Netresearch
7
+ * @author Thomas Kappel <thomas.kappel@netresearch.de>
8
+ * @license OSL 3.0
9
+ */
10
+ class Netresearch_OPS_Model_Payment_Wallie
11
+ extends Netresearch_OPS_Model_Payment_Abstract
12
+ {
13
+ /** Check if we can capture directly from the backend */
14
+ protected $_canBackendDirectCapture = true;
15
+
16
+ /** info source path */
17
+ protected $_infoBlockType = 'ops/info_redirect';
18
+
19
+ /** payment code */
20
+ protected $_code = 'ops_wallie';
21
+
22
+ public function getOpsCode($payment = null)
23
+ {
24
+ return 'Wallie';
25
+ }
26
+ }
27
+
app/code/community/Netresearch/OPS/Model/Source/BankTransfer/Countries.php ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Netresearch_OPS
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * OPS bank transfer countries
29
+ */
30
+ class Netresearch_OPS_Model_Source_BankTransfer_Countries
31
+ {
32
+ protected $countries = array(
33
+ 'BE',
34
+ 'DE',
35
+ 'FR',
36
+ 'NL',
37
+ );
38
+
39
+ protected $options = array();
40
+
41
+ /**
42
+ * @return array
43
+ */
44
+ public function toOptionArray($isMultiselect=false)
45
+ {
46
+ if (!$this->options) {
47
+ $this->options = Mage::getResourceModel('directory/country_collection')->loadData()->toOptionArray(false);
48
+ if (!$isMultiselect) {
49
+ array_unshift($this->options, array('value'=>'', 'label'=> Mage::helper('adminhtml')->__('--Please Select--')));
50
+ }
51
+ foreach ($this->options as $offset=>$option) {
52
+ if (!in_array($option['value'], $this->countries)) {
53
+ unset($this->options[$offset]);
54
+ }
55
+ }
56
+ $this->options['*'] = array('value'=>'*', 'label'=> Mage::helper('adminhtml')->__(Mage::helper('ops')->__('Miscellaneous Countries')));
57
+ }
58
+
59
+ return $this->options;
60
+ }
61
+ }
app/code/community/Netresearch/OPS/Model/Source/Cc/AliasInterfaceEnabledTypes.php ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Netresearch_OPS
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * OPS credit card types
29
+ */
30
+ class Netresearch_OPS_Model_Source_Cc_AliasInterfaceEnabledTypes
31
+ {
32
+ /**
33
+ * @return array
34
+ */
35
+ public function toOptionArray()
36
+ {
37
+ $options = array();
38
+ $types = array_intersect(
39
+ Mage::getModel('ops/config')->getAllCcTypes(),
40
+ $this->getAliasInterfaceCompatibleTypes()
41
+ );
42
+ foreach ($types as $type) {
43
+ $options[] = array(
44
+ 'value' => $type,
45
+ 'label' => Mage::helper('ops')->__($type)
46
+ );
47
+ }
48
+ return $options;
49
+ }
50
+
51
+ public function getAliasInterfaceCompatibleTypes()
52
+ {
53
+ return array(
54
+ 'American Express',
55
+ 'Diners Club',
56
+ 'MaestroUK',
57
+ 'MasterCard',
58
+ 'VISA',
59
+ );
60
+ }
61
+
62
+ }
app/code/community/Netresearch/OPS/Model/Source/Cc/Types.php ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Netresearch_OPS
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * OPS credit card types
29
+ */
30
+ class Netresearch_OPS_Model_Source_Cc_Types
31
+ {
32
+ /**
33
+ * @return array
34
+ */
35
+ public function toOptionArray()
36
+ {
37
+ $options = array();
38
+ $types = Mage::getModel('ops/config')->getAllCcTypes();
39
+ $translatedTypes = array();
40
+ foreach ($types as $type) {
41
+ $translatedTypes[Mage::helper('ops')->__($type)] = $type;
42
+ }
43
+ ksort($translatedTypes);
44
+ foreach ($translatedTypes as $label=>$value) {
45
+ $options[] = array(
46
+ 'value' => $value,
47
+ 'label' => $label
48
+ );
49
+ }
50
+ return $options;
51
+ }
52
+ }
app/code/community/Netresearch/OPS/Model/Source/DirectDebit/Countries.php ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Netresearch_OPS
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * OPS direct debit countries
29
+ */
30
+ class Netresearch_OPS_Model_Source_DirectDebit_Countries
31
+ {
32
+ protected $countries = array(
33
+ 'DE',
34
+ 'AT',
35
+ 'NL',
36
+ );
37
+
38
+ protected $options = array();
39
+
40
+ /**
41
+ * @return array
42
+ */
43
+ public function toOptionArray($isMultiselect=false)
44
+ {
45
+ if (!$this->options) {
46
+ $this->options = Mage::getResourceModel('directory/country_collection')->loadData()->toOptionArray(false);
47
+ if (!$isMultiselect) {
48
+ array_unshift($this->options, array('value'=>'', 'label'=> Mage::helper('adminhtml')->__('--Please Select--')));
49
+ }
50
+ foreach ($this->options as $offset=>$option) {
51
+ if (!in_array($option['value'], $this->countries)) {
52
+ unset($this->options[$offset]);
53
+ }
54
+ }
55
+ }
56
+
57
+ return $this->options;
58
+ }
59
+ }
app/code/community/Netresearch/OPS/Model/Source/DirectEbanking/Brands.php ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Magento
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * @category Mage
23
+ * @package Netresearch_OPS
24
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
25
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
26
+ */
27
+ /**
28
+ * OPS direct ebanking countries
29
+ */
30
+ class Netresearch_OPS_Model_Source_DirectEbanking_Brands
31
+ {
32
+ protected $options = array(
33
+ array(
34
+ 'value' => 'DirectEbanking',
35
+ ),
36
+ array(
37
+ 'value' => 'DirectEbankingAT',
38
+ ),
39
+ array(
40
+ 'value' => 'DirectEbankingBE',
41
+ ),
42
+ array(
43
+ 'value' => 'DirectEbankingCH',
44
+ ),
45
+ array(
46
+ 'value' => 'DirectEbankingDE',
47
+ ),
48
+ array(
49
+ 'value' => 'DirectEbankingFR',
50
+ ),
51
+ array(
52
+ 'value' => 'DirectEbankingGB',
53
+ )
54
+ );
55
+
56
+ /**
57
+ * @return array
58
+ */
59
+ public function toOptionArray($isMultiselect = false)
60
+ {
61
+ foreach ($this->options as $key => $value) {
62
+ $this->options[$key]['label'] = Mage::helper('ops')->__($value['value']);
63
+ }
64
+ return $this->options;
65
+ }
66
+
67
+ }
app/code/community/Netresearch/OPS/Model/Source/Kwixo/ProductCategories.php ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Netresearch_OPS
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Source Model for ProductCategories
29
+ */
30
+ class Netresearch_OPS_Model_Source_Kwixo_ProductCategories
31
+ {
32
+ /**
33
+ * return the product categories as array
34
+ *
35
+ * @return array
36
+ */
37
+ public function toOptionArray()
38
+ {
39
+ return array(
40
+ array(
41
+ 'value' => 1,
42
+ 'label' => Mage::helper('ops/data')->__('Food & gastronomy')
43
+ ),
44
+ array(
45
+ 'value' => 2,
46
+ 'label' => Mage::helper('ops/data')->__('Car & Motorbike')
47
+ ),
48
+ array(
49
+ 'value' => 3,
50
+ 'label' => Mage::helper('ops/data')->__('Culture & leisure')
51
+ ),
52
+ array(
53
+ 'value' => 4,
54
+ 'label' => Mage::helper('ops/data')->__('Home & garden')
55
+ ),
56
+ array(
57
+ 'value' => 5,
58
+ 'label' => Mage::helper('ops/data')->__('Appliances')
59
+ ),
60
+ array(
61
+ 'value' => 6,
62
+ 'label' => Mage::helper('ops/data')->__('Auctions and bulk purchases')
63
+ ),
64
+ array(
65
+ 'value' => 7,
66
+ 'label' => Mage::helper('ops/data')->__('Flowers & gifts')
67
+ ),
68
+ array(
69
+ 'value' => 8,
70
+ 'label' => Mage::helper('ops/data')->__('Computer & software')
71
+ ),
72
+ array(
73
+ 'value' => 9,
74
+ 'label' => Mage::helper('ops/data')->__('Health & beauty')
75
+ ),
76
+ array(
77
+ 'value' => 10,
78
+ 'label' => Mage::helper('ops/data')->__('Services for individuals')
79
+ ),
80
+ array(
81
+ 'value' => 11,
82
+ 'label' => Mage::helper('ops/data')->__('Services for professionals')
83
+ ),
84
+ array(
85
+ 'value' => 12,
86
+ 'label' => Mage::helper('ops/data')->__('Sports')
87
+ ),
88
+ array(
89
+ 'value' => 13,
90
+ 'label' => Mage::helper('ops/data')->__('Clothing & accessories')
91
+ ),
92
+ array(
93
+ 'value' => 14,
94
+ 'label' => Mage::helper('ops/data')->__('Travel & tourism')
95
+ ),
96
+ array(
97
+ 'value' => 15,
98
+ 'label' => Mage::helper('ops/data')->__('Hifi, photo & video')
99
+ ),
100
+ array(
101
+ 'value' => 16,
102
+ 'label' => Mage::helper('ops/data')->__('Telephony & communication')
103
+ ),
104
+ array(
105
+ 'value' => 17,
106
+ 'label' => Mage::helper('ops/data')->__('Jewelry & precious metals')
107
+ ),
108
+ array(
109
+ 'value' => 18,
110
+ 'label' => Mage::helper('ops/data')->__('Baby articles and accessories')
111
+ ),
112
+ array(
113
+ 'value' => 19,
114
+ 'label' => Mage::helper('ops/data')->__('Sound & light')
115
+ )
116
+ );
117
+ }
118
+
119
+ public function getValidKwixoCategoryIds()
120
+ {
121
+ $kwixoValues = array();
122
+ foreach ($this->toOptionArray() as $option) {
123
+ $kwixoValues[] = $option['value'];
124
+ }
125
+ return $kwixoValues;
126
+ }
127
+ }
app/code/community/Netresearch/OPS/Model/Source/Kwixo/ShipMethodType.php ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Netresearch_OPS
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Source Model for ShipMethodTypes
29
+ */
30
+ class Netresearch_OPS_Model_Source_Kwixo_ShipMethodType
31
+ {
32
+
33
+ const PICK_UP_AT_MERCHANT = 1;
34
+
35
+ const COLLECTION_POINT = 2;
36
+
37
+ const COLLECT_AT_AIRPORT = 3;
38
+
39
+ const TRANSPORTER = 4;
40
+
41
+ const DOWNLOAD = 5;
42
+
43
+ /**
44
+ * return options as array
45
+ *
46
+ * @return array
47
+ */
48
+ public function toOptionArray()
49
+ {
50
+ return array(
51
+ array(
52
+ 'value' => "",
53
+ 'label' => Mage::helper('ops/data')->__('--Please select--')
54
+ ),
55
+ array(
56
+ 'value' => self::PICK_UP_AT_MERCHANT,
57
+ 'label' => Mage::helper('ops/data')->__('Pick up at merchant')
58
+ ),
59
+ array(
60
+ 'value' => self::COLLECTION_POINT,
61
+ 'label' => Mage::helper('ops/data')->__(
62
+ 'Collection point (Kiala...)'
63
+ )
64
+ ),
65
+ array(
66
+ 'value' => self::COLLECT_AT_AIRPORT,
67
+ 'label' => Mage::helper('ops/data')->__(
68
+ 'Collect at airport, train station or travel agency'
69
+ )
70
+ ),
71
+ array(
72
+ 'value' => self::TRANSPORTER,
73
+ 'label' => Mage::helper('ops/data')->__(
74
+ 'Transporter (La Poste, UPS...)'
75
+ )
76
+ ),
77
+ array(
78
+ 'value' => self::DOWNLOAD,
79
+ 'label' => Mage::helper('ops/data')->__('Download')
80
+ )
81
+ );
82
+ }
83
+
84
+ public function getValidValues()
85
+ {
86
+ return array(
87
+ self::PICK_UP_AT_MERCHANT,
88
+ self::COLLECTION_POINT,
89
+ self::COLLECT_AT_AIRPORT,
90
+ self::TRANSPORTER,
91
+ self::DOWNLOAD
92
+ );
93
+ }
94
+ }
app/code/community/Netresearch/OPS/Model/Source/Mode.php ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mode.php
4
+ * @author paul.siedler@netresearch.de
5
+ * @copyright Copyright (c) 2015 Netresearch GmbH & Co. KG
6
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License
7
+ */
8
+
9
+
10
+ class Netresearch_OPS_Model_Source_Mode {
11
+
12
+ const PROD = 'prod';
13
+ const TEST = 'test';
14
+ const CUSTOM = 'custom';
15
+
16
+ /**
17
+ *
18
+ *
19
+ * @return array
20
+ */
21
+ public function toOptionArray(){
22
+ return array(
23
+ array('value' => self::TEST, 'label' => Mage::helper('ops')->__(self::TEST)),
24
+ array('value' => self::PROD, 'label' => Mage::helper('ops')->__(self::PROD)),
25
+ array('value' => self::CUSTOM, 'label' => Mage::helper('ops')->__(self::CUSTOM)),
26
+ );
27
+ }
28
+
29
+ }
app/code/community/Netresearch/OPS/Model/Source/OrderReference.php ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Netresearch_OPS
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * OPS order reference action dropdown source
29
+ */
30
+ class Netresearch_OPS_Model_Source_OrderReference
31
+ {
32
+ /**
33
+ * Prepare ops template mode list as option array
34
+ *
35
+ * @return array
36
+ */
37
+ public function toOptionArray()
38
+ {
39
+ return array(
40
+ array('value' => Netresearch_OPS_Model_Payment_Abstract::REFERENCE_QUOTE_ID, 'label' => Mage::helper('ops')->__('quote id')),
41
+ array('value' => Netresearch_OPS_Model_Payment_Abstract::REFERENCE_ORDER_ID, 'label' => Mage::helper('ops')->__('order id')),
42
+ );
43
+ }
44
+ }
app/code/community/Netresearch/OPS/Model/Source/PaymentAction.php ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Netresearch_OPS
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * OPS Payment Action Dropdown source
29
+ */
30
+ class Netresearch_OPS_Model_Source_PaymentAction
31
+ {
32
+ /**
33
+ * Prepare payment action list as optional array
34
+ *
35
+ * @return array
36
+ */
37
+ public function toOptionArray()
38
+ {
39
+ return array(
40
+ array('value' => Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE, 'label' => Mage::helper('ops')->__('Authorization')),
41
+ array('value' => Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE_CAPTURE, 'label' => Mage::helper('ops')->__('Direct Sale')),
42
+ );
43
+ }
44
+ }
app/code/community/Netresearch/OPS/Model/Source/Pmlist.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Netresearch_OPS
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * OPS template Action Dropdown source
29
+ */
30
+ class Netresearch_OPS_Model_Source_Pmlist
31
+ {
32
+ /**
33
+ * Prepare ops payment block layout as option array
34
+ *
35
+ * @return array
36
+ */
37
+ public function toOptionArray()
38
+ {
39
+ return array(
40
+ array('value' => Netresearch_OPS_Model_Payment_Abstract::PMLIST_HORIZONTAL_LEFT, 'label' => Mage::helper('ops')->__('Horizontally grouped logo with group name on left')),
41
+ array('value' => Netresearch_OPS_Model_Payment_Abstract::PMLIST_HORIZONTAL, 'label' => Mage::helper('ops')->__('Horizontally grouped logo with no group name')),
42
+ array('value' => Netresearch_OPS_Model_Payment_Abstract::PMLIST_VERTICAL, 'label' => Mage::helper('ops')->__('Verical list')),
43
+ );
44
+ }
45
+ }
app/code/community/Netresearch/OPS/Model/Source/Template.php ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Netresearch_OPS
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * OPS template Action Dropdown source
29
+ */
30
+ class Netresearch_OPS_Model_Source_Template
31
+ {
32
+ /**
33
+ * Prepare ops template mode list as option array
34
+ *
35
+ * @return array
36
+ */
37
+ public function toOptionArray()
38
+ {
39
+ return array(
40
+ array('value' => Netresearch_OPS_Model_Payment_Abstract::TEMPLATE_OPS, 'label' => Mage::helper('ops')->__('Ingenico Payment Services')),
41
+ array('value' => Netresearch_OPS_Model_Payment_Abstract::TEMPLATE_MAGENTO, 'label' => Mage::helper('ops')->__('Magento')),
42
+ );
43
+ }
44
+ }
app/code/community/Netresearch/OPS/Model/Status/Feedback.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Netresearch_OPS
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ *
26
+ */
27
+ class Netresearch_OPS_Model_Status_Feedback
28
+ {
29
+ const OPS_ORDER_FEEDBACK_STATUS_ACCEPT = 'accept';
30
+ const OPS_ORDER_FEEDBACK_STATUS_DECLINE = 'decline';
31
+ const OPS_ORDER_FEEDBACK_STATUS_CANCEL = 'cancel';
32
+ const OPS_ORDER_FEEDBACK_STATUS_EXCEPTION = 'exception';
33
+ }
app/code/community/Netresearch/OPS/Model/Status/Mapping.php ADDED
@@ -0,0 +1,171 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @author Michael Lühr <michael.luehr@netresearch.de>
5
+ * @category Netresearch
6
+ * @copyright Copyright (c) 2014 Netresearch GmbH & Co. KG (http://www.netresearch.de)
7
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
8
+ */
9
+ class Netresearch_OPS_Model_Status_Mapping
10
+ {
11
+
12
+ protected $orderStatesForOpsState = array();
13
+
14
+ protected $transitionModel = null;
15
+
16
+ /**
17
+ * @param null $transitionModel
18
+ */
19
+ public function setTransitionModel($transitionModel)
20
+ {
21
+ $this->transitionModel = $transitionModel;
22
+ }
23
+
24
+ /**
25
+ * @return Netresearch_OPS_Model_Status_Transition
26
+ */
27
+ public function getTransitionModel()
28
+ {
29
+ if (null == $this->transitionModel) {
30
+ $this->transitionModel = Mage::getModel('ops/status_transition');
31
+ }
32
+
33
+ return $this->transitionModel;
34
+ }
35
+
36
+ /**
37
+ * retrieves the possible magento order's states for the according Ingenico Payment Services status
38
+ *
39
+ * @param $opsStatus - the Ingenico Payment Services status
40
+ *
41
+ * @return array - the order's states
42
+ */
43
+ public function getStatusForOpsStatus($opsStatus)
44
+ {
45
+ $this->getTransitionModel()->setOpsResponse(array('STATUS' => $opsStatus));
46
+ $this->handleRefundOperations();
47
+ $this->handleCaptureOperations();
48
+ $this->handleVoidOperations();
49
+ $this->handleAuthOperations($opsStatus);
50
+ $this->handleRefusedOperations($opsStatus);
51
+
52
+ return $this->orderStatesForOpsState;
53
+ }
54
+
55
+ /**
56
+ * retrieves Magento order's states for refund operations
57
+ *
58
+ * @return $this
59
+ */
60
+ protected function handleRefundOperations()
61
+ {
62
+ if ($this->getTransitionModel()->isRefundOperation()) {
63
+ $this->orderStatesForOpsState = array(
64
+ Mage_Sales_Model_Order::STATE_CLOSED,
65
+ Mage_Sales_Model_Order::STATE_PROCESSING
66
+ );
67
+ }
68
+
69
+ return $this;
70
+ }
71
+
72
+ /**
73
+ * retrieves Magento order's states for capture operations
74
+ *
75
+ * @return $this
76
+ */
77
+ protected function handleCaptureOperations()
78
+ {
79
+ if ($this->getTransitionModel()->isCaptureOperation()) {
80
+ $this->orderStatesForOpsState = array(
81
+ Mage_Sales_Model_Order::STATE_COMPLETE,
82
+ Mage_Sales_Model_Order::STATE_PROCESSING
83
+ );
84
+ }
85
+
86
+ return $this;
87
+ }
88
+
89
+ /**
90
+ * retrieves Magento order's states for void operations
91
+ *
92
+ * @return $this
93
+ */
94
+ protected function handleVoidOperations()
95
+ {
96
+ if ($this->getTransitionModel()->isVoidOperation()) {
97
+ $this->orderStatesForOpsState = array(
98
+ Mage_Sales_Model_Order::STATE_PROCESSING,
99
+ Mage_Sales_Model_Order::STATE_COMPLETE,
100
+ Mage_Sales_Model_Order::STATE_CANCELED
101
+ );
102
+ }
103
+
104
+ return $this;
105
+ }
106
+
107
+ /**
108
+ * retrieves Magento order's states for auth operations
109
+ *
110
+ * @param $opsStatus
111
+ *
112
+ * @return $this
113
+ */
114
+ protected function handleAuthOperations($opsStatus)
115
+ {
116
+ if ($this->isOpsAuthorizedStatus($opsStatus)
117
+ || 0 == strlen(trim($opsStatus))
118
+ || $opsStatus == Netresearch_OPS_Model_Payment_Abstract::OPS_ORDER_SAVED
119
+ ) {
120
+ $this->orderStatesForOpsState = array(Mage_Sales_Model_Order::STATE_PROCESSING);
121
+ if ($opsStatus == Netresearch_OPS_Model_Payment_Abstract::OPS_AWAIT_CUSTOMER_PAYMENT
122
+ || $opsStatus == Netresearch_OPS_Model_Payment_Abstract::OPS_AUTHORIZED_WAITING
123
+ ) {
124
+ $this->orderStatesForOpsState = array(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT);
125
+ }
126
+ }
127
+
128
+ return $this;
129
+ }
130
+
131
+ /**
132
+ * retrieves Magento order's states for refused operations
133
+ *
134
+ * @param $opsStatus
135
+ *
136
+ * @return $this
137
+ */
138
+ protected function handleRefusedOperations($opsStatus)
139
+ {
140
+ if ($this->isRefusedOpsStatus($opsStatus)) {
141
+ $this->orderStatesForOpsState = array(Mage_Sales_Model_Order::STATE_CANCELED);
142
+ }
143
+
144
+ return $this;
145
+ }
146
+
147
+ /**
148
+ * @param $opsStatus
149
+ *
150
+ * @return bool
151
+ */
152
+ protected function isOpsAuthorizedStatus($opsStatus)
153
+ {
154
+ return ($opsStatus >= Netresearch_OPS_Model_Payment_Abstract::OPS_AWAIT_CUSTOMER_PAYMENT
155
+ && $opsStatus <= Netresearch_OPS_Model_Payment_Abstract::OPS_AUTHORIZED_TO_GET_MANUALLY)
156
+ || $opsStatus == Netresearch_OPS_Model_Payment_Abstract::OPS_OPEN_INVOICE_DE_PROCESSED
157
+ || $opsStatus == Netresearch_OPS_Model_Payment_Abstract::OPS_AUTHORIZED;
158
+ }
159
+
160
+ /**
161
+ * @param $opsStatus
162
+ *
163
+ * @return bool
164
+ */
165
+ protected function isRefusedOpsStatus($opsStatus)
166
+ {
167
+ return $opsStatus == Netresearch_OPS_Model_Payment_Abstract::OPS_AUTH_REFUSED
168
+ || $opsStatus == Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_REFUSED
169
+ || $opsStatus == Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_CANCELED_BY_CUSTOMER;
170
+ }
171
+ }
app/code/community/Netresearch/OPS/Model/Status/Transition.php ADDED
@@ -0,0 +1,567 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @author Michael Lühr <michael.luehr@netresearch.de>
5
+ * @category Netresearch
6
+ * @copyright Copyright (c) 2014 Netresearch GmbH & Co. KG (http://www.netresearch.de)
7
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
8
+ */
9
+ class Netresearch_OPS_Model_Status_Transition
10
+ {
11
+
12
+ protected $order = null;
13
+
14
+ protected $opsResponse = array();
15
+
16
+ protected $infoArr = array();
17
+
18
+ protected $captureHelper = null;
19
+
20
+ protected $directLinkHelper = null;
21
+
22
+ protected $voidHelper = null;
23
+
24
+ protected $refundHelper = null;
25
+
26
+ protected $paymentHelper = null;
27
+
28
+ /**
29
+ * @param null $paymentHelper
30
+ */
31
+ public function setPaymentHelper($paymentHelper)
32
+ {
33
+ $this->paymentHelper = $paymentHelper;
34
+ }
35
+
36
+ /**
37
+ * @param null $refundHelper
38
+ */
39
+ public function setRefundHelper($refundHelper)
40
+ {
41
+ $this->refundHelper = $refundHelper;
42
+ }
43
+
44
+ /**
45
+ * @param null $voidHelper
46
+ */
47
+ public function setVoidHelper($voidHelper)
48
+ {
49
+ $this->voidHelper = $voidHelper;
50
+ }
51
+
52
+ /**
53
+ * @return null
54
+ */
55
+ public function getVoidHelper()
56
+ {
57
+ if (null == $this->voidHelper) {
58
+ $this->voidHelper = Mage::helper("ops/order_void");
59
+ }
60
+
61
+ return $this->voidHelper;
62
+ }
63
+
64
+ /**
65
+ * @param array $infoArr
66
+ */
67
+ public function setInfoArr($infoArr)
68
+ {
69
+ $this->infoArr = $infoArr;
70
+ }
71
+
72
+ /**
73
+ * @return array
74
+ */
75
+ public function getInfoArr()
76
+ {
77
+ return $this->infoArr;
78
+ }
79
+
80
+ /**
81
+ * @param array $opsResponse
82
+ */
83
+ public function setOpsResponse($opsResponse)
84
+ {
85
+ $this->opsResponse = $opsResponse;
86
+ }
87
+
88
+ /**
89
+ * @return array
90
+ */
91
+ public function getOpsResponse()
92
+ {
93
+ return $this->opsResponse;
94
+ }
95
+
96
+ /**
97
+ * @param null $order
98
+ */
99
+ public function setOrder($order)
100
+ {
101
+ $this->order = $order;
102
+ }
103
+
104
+ /**
105
+ * @return null
106
+ */
107
+ public function getOrder()
108
+ {
109
+ return $this->order;
110
+ }
111
+
112
+ /**
113
+ * processes the Ingenico Payment Services responses
114
+ *
115
+ * @param array $opsResponse
116
+ * @param Mage_Sales_Model_Order $order
117
+ *
118
+ * @return $this
119
+ */
120
+ public function processOpsResponse(array $opsResponse, Mage_Sales_Model_Order $order)
121
+ {
122
+ $this->opsResponse = $opsResponse;
123
+ $this->order = $order;
124
+ $this->processCaptureFeedback();
125
+ $this->processRefundFeedback();
126
+ $this->processVoidFeedback();
127
+
128
+ return $this;
129
+ }
130
+
131
+ /**
132
+ * process the feedback from Ingenico Payment Services for capture operations
133
+ *
134
+ * @return $this
135
+ */
136
+ public function processCaptureFeedback()
137
+ {
138
+ if ($this->isCaptureOperation()) {
139
+ // use direct link helper processFeedback, but need special handling for those status which are handled after setting up the direct link request
140
+ if ($this->isCaptureRequestResponse()) {
141
+ $this->infoArr = $this->getCaptureOperation();
142
+ $this->saveCaptureTxn();
143
+ //Reload order to avoid wrong status
144
+ $order = $this->reloadOrder();
145
+ $order->addStatusHistoryComment(
146
+ $this->getDataHelper()->__(
147
+ 'Invoice will be created automatically as soon as Ingenico Payment Services sends an acknowledgement. Ingenico Payment Services status: %s.',
148
+ $this->getDataHelper()->getStatusText($this->opsResponse['STATUS'])
149
+ )
150
+ );
151
+ $order->save();
152
+ $this->setOrder($order);
153
+ } else {
154
+ $this->processFeedback();
155
+ }
156
+ }
157
+
158
+ return $this;
159
+ }
160
+
161
+ /**
162
+ * processes the feedback from Ingenico Payment Services for void operations
163
+ *
164
+ * @return $this
165
+ */
166
+ public function processVoidFeedback()
167
+ {
168
+ if ($this->isVoidOperation()) {
169
+ if ($this->isOpsVoidWaitingOrUncertain()) {
170
+ $this->infoArr = array(
171
+ 'amount' => $this->opsResponse['AMOUNT'],
172
+ 'void_request' => Mage::app()->getRequest()->getParams(),
173
+ 'response' => $this->opsResponse,
174
+ );
175
+ $msg = $this->getDataHelper()->__(
176
+ 'Start Ingenico Payment Services void request. Ingenico Payment Services status: %s.',
177
+ $this->getDataHelper()->getStatusText($this->opsResponse['STATUS'])
178
+ );
179
+ $this->createVoidTxn($msg);
180
+
181
+ } /*
182
+ * If the ops response results directly in accepted state, create a void transaction
183
+ */
184
+ elseif ($this->isVoidAccepted()) {
185
+ $this->infoArr = array();
186
+ $msg = $this->getDataHelper()->__(
187
+ 'Void order succeed. Ingenico Payment Services status: %s.',
188
+ $this->opsResponse['STATUS']
189
+ );
190
+ $this->createVoidTxn($msg);
191
+ $this->getVoidHelper()->acceptVoid($this->getOrder(), $this->getOpsResponse());
192
+ } else {
193
+ $this->processFeedback();
194
+ }
195
+ }
196
+
197
+ return $this;
198
+ }
199
+
200
+ /**
201
+ * processes the feedback from Ingenico Payment Services for refund operations
202
+ *
203
+ * @return $this
204
+ */
205
+ public function processRefundFeedback()
206
+ {
207
+ if ($this->isRefundOperation()) {
208
+ $operation = $this->getRefundHelper()->determineOperationCode(
209
+ $this->getOrder()->getPayment(),
210
+ $this->opsResponse['AMOUNT']
211
+ );
212
+
213
+
214
+ if ($this->isRefundWaiting()) {
215
+ $this->getPaymentHelper()->saveOpsRefundOperationCodeToPayment(
216
+ $this->getOrder()->getPayment(),
217
+ $operation
218
+ );
219
+ $this->getRefundHelper()->setPayment($this->getOrder()->getPayment());
220
+ if (false == $this->getDirectlinkHelper()->hasPaymentTransactions($this->getOrder(), 'refund')) {
221
+ $this->getRefundHelper()->createRefundTransaction($this->opsResponse);
222
+ }
223
+
224
+ } elseif ($this->isRefundAccepted()
225
+ && $this->getOrder()->getPayment()->getAdditionalInformation('status')
226
+ != Netresearch_OPS_Model_Payment_Abstract::OPS_REFUND_WAITING
227
+ ) {
228
+ //do refund directly if response is ok already
229
+ $this->getPaymentHelper()->saveOpsRefundOperationCodeToPayment(
230
+ $this->getOrder()->getPayment(),
231
+ $operation
232
+ );
233
+ $this->getRefundHelper()->setPayment($this->getOrder()->getPayment());
234
+ try {
235
+ $this->getRefundHelper()->createRefund($this->getOrder(), $this->getOpsResponse(), true);
236
+ } catch (Mage_Core_Exception $e) {
237
+ Mage::logException($e);
238
+ }
239
+ } else {
240
+ $this->processFeedback();
241
+ }
242
+ }
243
+ return $this;
244
+ }
245
+
246
+ /**
247
+ * retrieves the Ingenico Payment Services status for the payment
248
+ *
249
+ * @return string | null the Ingenico Payment Services status for the payment
250
+ */
251
+ protected function getOpsStatus()
252
+ {
253
+ $status = null;
254
+ if (array_key_exists('STATUS', $this->opsResponse)) {
255
+ $status = $this->opsResponse['STATUS'];
256
+ }
257
+
258
+ return $status;
259
+ }
260
+
261
+ /**
262
+ * return the Ingenico Payment Services's payment identifier
263
+ *
264
+ * @return string | null the Ingenico Payment Services's payment identifier
265
+ */
266
+ protected function getOpsPayId()
267
+ {
268
+ $payId = null;
269
+ if (array_key_exists('PAYID', $this->opsResponse)) {
270
+ $payId = $this->opsResponse['PAYID'];
271
+ }
272
+
273
+ return $payId;
274
+ }
275
+
276
+ /**
277
+ * retrieves the sub payid from Ingenico Payment Services's response
278
+ *
279
+ * @return null| string the payment sub identifier from Ingenico Payment Services
280
+ */
281
+ protected function getOpsPayIdSub()
282
+ {
283
+ $payIdSub = null;
284
+ if (array_key_exists('PAYIDSUB', $this->opsResponse)) {
285
+ $payIdSub = $this->opsResponse['PAYIDSUB'];
286
+ }
287
+
288
+ return $payIdSub;
289
+ }
290
+
291
+ /**
292
+ * checks if the current status is valid for a capture operation
293
+ *
294
+ * @return bool
295
+ */
296
+ public function isCaptureOperation()
297
+ {
298
+ return in_array(
299
+ $this->getOpsStatus(),
300
+ array(
301
+ Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_REQUESTED,
302
+ Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_PROCESSING,
303
+ Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_UNCERTAIN,
304
+ Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_REFUSED,
305
+ Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_DECLINED_ACQUIRER,
306
+ Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_PROCESSED_MERCHANT,
307
+ Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_IN_PROGRESS,
308
+ )
309
+ );
310
+ }
311
+
312
+ /**
313
+ * checks if the current status is valid for a refund operation
314
+ *
315
+ * @return bool
316
+ */
317
+ public function isRefundOperation()
318
+ {
319
+ return in_array(
320
+ $this->getOpsStatus(),
321
+ array(
322
+ Netresearch_OPS_Model_Payment_Abstract::OPS_REFUNDED,
323
+ Netresearch_OPS_Model_Payment_Abstract::OPS_REFUND_WAITING,
324
+ Netresearch_OPS_Model_Payment_Abstract::OPS_REFUND_UNCERTAIN_STATUS,
325
+ Netresearch_OPS_Model_Payment_Abstract::OPS_REFUND_REFUSED,
326
+ Netresearch_OPS_Model_Payment_Abstract::OPS_REFUND_DECLINED_ACQUIRER,
327
+ Netresearch_OPS_Model_Payment_Abstract::OPS_REFUND_PROCESSED_MERCHANT,
328
+ )
329
+ );
330
+ }
331
+
332
+ /**
333
+ * checks if the current status is valid for a void operation
334
+ *
335
+ * @return bool
336
+ */
337
+ public function isVoidOperation()
338
+ {
339
+ return in_array(
340
+ $this->getOpsStatus(),
341
+ array(
342
+ Netresearch_OPS_Model_Payment_Abstract::OPS_VOIDED,
343
+ Netresearch_OPS_Model_Payment_Abstract::OPS_VOID_WAITING,
344
+ Netresearch_OPS_Model_Payment_Abstract::OPS_VOID_UNCERTAIN,
345
+ Netresearch_OPS_Model_Payment_Abstract::OPS_VOID_REFUSED,
346
+ Netresearch_OPS_Model_Payment_Abstract::OPS_VOIDED_ACCEPTED,
347
+ )
348
+ );
349
+ }
350
+
351
+
352
+ /**
353
+ * checks if the response is matching a previous capture request
354
+ *
355
+ * @return bool
356
+ */
357
+ public function isCaptureRequestResponse()
358
+ {
359
+ return in_array(
360
+ $this->getOpsStatus(),
361
+ array(
362
+ Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_PROCESSING,
363
+ Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_UNCERTAIN,
364
+ Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_IN_PROGRESS
365
+ )
366
+ );
367
+ }
368
+
369
+ /**
370
+ * retrieves the capture operation
371
+ *
372
+ * @return array
373
+ */
374
+ public function getCaptureOperation()
375
+ {
376
+ return $this->getCaptureHelper()->prepareOperation(
377
+ $this->getOrder()->getPayment(),
378
+ $this->opsResponse['AMOUNT']
379
+ );
380
+ }
381
+
382
+ /**
383
+ * @return Netresearch_OPS_Helper_Order_Capture
384
+ */
385
+ public function getCaptureHelper()
386
+ {
387
+ if (null == $this->captureHelper) {
388
+ $this->captureHelper = Mage::helper('ops/order_capture');
389
+ }
390
+
391
+ return $this->captureHelper;
392
+ }
393
+
394
+ public function setCaptureHelper(Netresearch_OPS_Helper_Order_Capture $captureHelper)
395
+ {
396
+ $this->captureHelper = $captureHelper;
397
+ }
398
+
399
+ /**
400
+ * creates a capture transaction
401
+ */
402
+ protected function saveCaptureTxn()
403
+ {
404
+ $this->getDirectlinkHelper()->directLinkTransact(
405
+ $this->reloadOrder(),
406
+ $this->getOpsPayId(),
407
+ $this->getOpsPayIdSub(),
408
+ $this->infoArr,
409
+ Netresearch_OPS_Model_Payment_Abstract::OPS_CAPTURE_TRANSACTION_TYPE,
410
+ $this->getDataHelper()->__('Start Ingenico Payment Services %s capture request', $this->infoArr['type'])
411
+ );
412
+ }
413
+
414
+ /**
415
+ * @return Netresearch_OPS_Helper_Directlink
416
+ */
417
+ public function getDirectlinkHelper()
418
+ {
419
+ if (null == $this->directLinkHelper) {
420
+ $this->directLinkHelper = Mage::helper('ops/directlink');
421
+ }
422
+
423
+ return $this->directLinkHelper;
424
+ }
425
+
426
+ public function setDirectlinkHelper(Netresearch_OPS_Helper_Directlink $directlinkHelper)
427
+ {
428
+ $this->directLinkHelper = $directlinkHelper;
429
+ }
430
+
431
+ /**
432
+ * @return Netresearch_OPS_Helper_Data
433
+ */
434
+ public function getDataHelper()
435
+ {
436
+ return Mage::helper('ops/data');
437
+ }
438
+
439
+ /**
440
+ * checks if the response is void in waiting or uncertain
441
+ *
442
+ * @return bool
443
+ */
444
+ protected function isOpsVoidWaitingOrUncertain()
445
+ {
446
+ return in_array(
447
+ $this->getOpsStatus(),
448
+ array(
449
+ Netresearch_OPS_Model_Payment_Abstract::OPS_VOID_WAITING,
450
+ Netresearch_OPS_Model_Payment_Abstract::OPS_VOID_UNCERTAIN
451
+ )
452
+ );
453
+ }
454
+
455
+ /**
456
+ * checks if the refund is accepted
457
+ *
458
+ * @return bool
459
+ */
460
+ protected function isRefundAccepted()
461
+ {
462
+ return in_array(
463
+ $this->getOpsStatus(),
464
+ array(
465
+ Netresearch_OPS_Model_Payment_Abstract::OPS_REFUNDED,
466
+ Netresearch_OPS_Model_Payment_Abstract::OPS_REFUND_PROCESSED_MERCHANT
467
+ )
468
+ );
469
+ }
470
+
471
+ /**
472
+ * checks if the void is accepted
473
+ *
474
+ * @return bool
475
+ */
476
+ protected function isVoidAccepted()
477
+ {
478
+ return in_array(
479
+ $this->getOpsStatus(),
480
+ array(
481
+ Netresearch_OPS_Model_Payment_Abstract::OPS_VOIDED,
482
+ Netresearch_OPS_Model_Payment_Abstract::OPS_VOIDED_ACCEPTED
483
+ )
484
+ );
485
+ }
486
+
487
+ /**
488
+ * @return Mage_Sales_Model_Order
489
+ */
490
+ protected function reloadOrder()
491
+ {
492
+ return Mage::getSingleton("sales/order")->loadByIncrementId(
493
+ $this->getOrder()->getIncrementId()
494
+ );
495
+ }
496
+
497
+ /**
498
+ * creates a void transaction
499
+ *
500
+ * @param $msg - message
501
+ * @param int $closed - whether it's closed or not
502
+ */
503
+ protected function createVoidTxn($msg, $closed = 0)
504
+ {
505
+ $this->getDirectlinkHelper()->directLinkTransact(
506
+ $this->reloadOrder(),
507
+ $this->getOpsPayId(),
508
+ $this->getOpsPayIdSub(),
509
+ $this->infoArr,
510
+ Netresearch_OPS_Model_Payment_Abstract::OPS_VOID_TRANSACTION_TYPE,
511
+ $msg,
512
+ $closed
513
+ );
514
+ }
515
+
516
+ /**
517
+ * checks if the refund is waiting or uncertain
518
+ *
519
+ * @return bool
520
+ */
521
+ protected function isRefundWaiting()
522
+ {
523
+ return in_array(
524
+ $this->getOpsStatus(),
525
+ array(
526
+ Netresearch_OPS_Model_Payment_Abstract::OPS_REFUND_WAITING,
527
+ Netresearch_OPS_Model_Payment_Abstract::OPS_REFUND_UNCERTAIN_STATUS
528
+ )
529
+ );
530
+ }
531
+
532
+ /**
533
+ * @return Netresearch_OPS_Helper_Payment
534
+ */
535
+ public function getPaymentHelper()
536
+ {
537
+ if (null == $this->paymentHelper) {
538
+ $this->paymentHelper = Mage::helper('ops/payment');
539
+ }
540
+
541
+ return $this->paymentHelper;
542
+ }
543
+
544
+ /**
545
+ * @return Netresearch_OPS_Helper_Order_Refund
546
+ */
547
+ public function getRefundHelper()
548
+ {
549
+ if (null == $this->refundHelper) {
550
+ $this->refundHelper = Mage::helper('ops/order_refund');
551
+ }
552
+
553
+ return $this->refundHelper;
554
+ }
555
+
556
+ /**
557
+ * processes the feedback from Ingenico Payment Services
558
+ */
559
+ protected function processFeedback()
560
+ {
561
+ try {
562
+ $this->getDirectlinkHelper()->processFeedback($this->getOrder(), $this->getOpsResponse());
563
+ } catch (Mage_Core_Exception $e) {
564
+ Mage::logException($e);
565
+ }
566
+ }
567
+ }
app/code/community/Netresearch/OPS/Model/Status/Update.php ADDED
@@ -0,0 +1,338 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Michael Lühr <michael.luehr@netresearch.de>
4
+ * @category Netresearch
5
+ * @copyright Copyright (c) 2014 Netresearch GmbH & Co. KG (http://www.netresearch.de)
6
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
7
+ */
8
+
9
+
10
+ class Netresearch_OPS_Model_Status_Update
11
+ {
12
+
13
+ /** @var Netresearch_OPS_Model_Api_DirectLink $directLinkApi */
14
+ protected $directLinkApi = null;
15
+
16
+ protected $order = null;
17
+
18
+ protected $requestParams = array();
19
+
20
+ /** @var Netresearch_OPS_Model_Config $opsConfig */
21
+ protected $opsConfig = null;
22
+
23
+ protected $opsResponse = array();
24
+
25
+ protected $transitionModel = null;
26
+
27
+ protected $paymentHelper = null;
28
+
29
+ protected $directLinkHelper = null;
30
+
31
+ protected $messageContainer = null;
32
+
33
+ protected $dataHelper = null;
34
+
35
+ /**
36
+ * @param null $dataHelper
37
+ */
38
+ public function setDataHelper($dataHelper)
39
+ {
40
+ $this->dataHelper = $dataHelper;
41
+ }
42
+
43
+ /**
44
+ * @return null
45
+ */
46
+ public function getDataHelper()
47
+ {
48
+ if (null == $this->dataHelper) {
49
+ $this->dataHelper = Mage::helper('ops/data');
50
+ }
51
+
52
+ return $this->dataHelper;
53
+ }
54
+ /**
55
+ * @param null $messageContainer
56
+ */
57
+ public function setMessageContainer(Mage_Core_Model_Session_Abstract $messageContainer)
58
+ {
59
+ $this->messageContainer = $messageContainer;
60
+ }
61
+
62
+ /**
63
+ * @return Mage_Core_Model_Session_Abstract
64
+ */
65
+ public function getMessageContainer()
66
+ {
67
+ if (null == $this->messageContainer) {
68
+ $this->messageContainer = Mage::getSingleton('adminhtml/session');
69
+ }
70
+ return $this->messageContainer;
71
+ }
72
+
73
+ /**
74
+ * @param Netresearch_OPS_Model_Config $opsConfig
75
+ */
76
+ public function setOpsConfig(Netresearch_OPS_Model_Config $opsConfig)
77
+ {
78
+ $this->opsConfig = $opsConfig;
79
+ }
80
+
81
+ /**
82
+ * @return Netresearch_OPS_Model_Config
83
+ */
84
+ public function getOpsConfig()
85
+ {
86
+ if (null === $this->opsConfig) {
87
+ $this->opsConfig = Mage::getModel('ops/config');
88
+ }
89
+ return $this->opsConfig;
90
+ }
91
+
92
+ /**
93
+ * @param array $requestParams
94
+ */
95
+ public function setRequestParams($requestParams)
96
+ {
97
+ $this->requestParams = $requestParams;
98
+ }
99
+
100
+ /**
101
+ * @return array
102
+ */
103
+ public function getRequestParams()
104
+ {
105
+ return $this->requestParams;
106
+ }
107
+
108
+ /**
109
+ * @param Netresearch_OPS_Helper_Order $orderHelper
110
+ */
111
+ public function setOrderHelper(Netresearch_OPS_Helper_Order $orderHelper)
112
+ {
113
+ $this->orderHelper = $orderHelper;
114
+ }
115
+
116
+ /**
117
+ * @return Netresearch_OPS_Helper_Order
118
+ */
119
+ public function getOrderHelper()
120
+ {
121
+ if (null == $this->orderHelper) {
122
+ $this->orderHelper = Mage::helper('ops/order');
123
+ }
124
+
125
+ return $this->orderHelper;
126
+ }
127
+
128
+ /**
129
+ * @param array $opsResponse
130
+ */
131
+ public function setOpsResponse($opsResponse)
132
+ {
133
+ $this->opsResponse = $opsResponse;
134
+ }
135
+
136
+ /**
137
+ * @return array
138
+ */
139
+ public function getOpsResponse()
140
+ {
141
+ return $this->opsResponse;
142
+ }
143
+
144
+ /** @var Netresearch_OPS_Helper_Order $orderHelper */
145
+ protected $orderHelper = null;
146
+
147
+ /**
148
+ * @param Netresearch_OPS_Model_Api_DirectLink $directLinkApi
149
+ */
150
+ public function setDirectLinkApi(Netresearch_OPS_Model_Api_DirectLink $directLinkApi)
151
+ {
152
+ $this->directLinkApi = $directLinkApi;
153
+ }
154
+
155
+ /**
156
+ * @return Netresearch_OPS_Model_Api_DirectLink
157
+ */
158
+ public function getDirectLinkApi()
159
+ {
160
+ if (null === $this->directLinkApi) {
161
+ $this->directLinkApi = Mage::getModel('ops/api_directlink');
162
+ }
163
+ return $this->directLinkApi;
164
+ }
165
+
166
+ /**
167
+ * @param Mage_Sales_Model_Order $order
168
+ */
169
+ public function setOrder(Mage_Sales_Model_Order $order)
170
+ {
171
+ $this->order = $order;
172
+ }
173
+
174
+ /**
175
+ * @return Mage_Sales_Model_Order
176
+ */
177
+ public function getOrder()
178
+ {
179
+ return $this->order;
180
+ }
181
+
182
+ public function updateStatusFor(Mage_Sales_Model_Order $order)
183
+ {
184
+ if (false === ($order->getPayment()->getMethodInstance() instanceof Netresearch_OPS_Model_Payment_Abstract)) {
185
+ return $this;
186
+ }
187
+ $this->setOrder($order);
188
+ $this->buildParams($order->getPayment());
189
+ $this->performRequest();
190
+ $this->updatePaymentStatus();
191
+
192
+ return $this;
193
+ }
194
+
195
+ protected function buildParams(Mage_Sales_Model_Order_Payment $payment)
196
+ {
197
+ // use PAYID if possible
198
+ if (0 < strlen(trim($payment->getAdditionalInformation('paymentId')))) {
199
+ $this->requestParams['PAYID'] = $payment->getAdditionalInformation('paymentId');
200
+
201
+ } else {
202
+ $useOrderId = true;
203
+ if ($this->canNotUseOrderId($payment)
204
+ ) {
205
+ $useOrderId = false;
206
+ }
207
+ $this->requestParams['ORDERID'] = $this->getOrderHelper()->getOpsOrderId($this->getOrder(), $useOrderId);
208
+ }
209
+ $this->addPayIdSub($payment);
210
+
211
+ return $this;
212
+ }
213
+
214
+ protected function performRequest()
215
+ {
216
+ $storeId = $this->getOrder()->getStoreId();
217
+ $url = $this->getOpsConfig()->getDirectLinkMaintenanceApiPath($storeId);
218
+ try {
219
+ $this->opsResponse = $this->getDirectLinkApi()->performRequest($this->getRequestParams(), $url, $storeId);
220
+ } catch (Mage_Core_Exception $e) {
221
+ $this->getMessageContainer()->addError($this->getDataHelper()->__($e->getMessage()));
222
+ return $this;
223
+ }
224
+ $this->opsResponse = array_change_key_case($this->opsResponse, CASE_UPPER);
225
+ // in further processing the amount is sometimes in upper and sometimes in lower case :(
226
+ if (array_key_exists('AMOUNT', $this->opsResponse)) {
227
+ $this->opsResponse['amount'] = $this->opsResponse['AMOUNT'];
228
+ }
229
+ return $this;
230
+ }
231
+
232
+ protected function updatePaymentStatus()
233
+ {
234
+ if (!array_key_exists('STATUS', $this->getOpsResponse())
235
+ || $this->opsResponse['STATUS'] == $this->getOrder()->getPayment()->getAdditionalInformation('status')
236
+ ) {
237
+ return $this;
238
+ }
239
+
240
+ $this->getPaymentHelper()->saveOpsStatusToPayment($this->getOrder()->getPayment(), $this->getOpsResponse());
241
+
242
+ if (0 < strlen(trim($this->getOrder()->getPayment()->getAdditionalInformation('paymentId')))) {
243
+ $this->getTransitionModel()->processOpsResponse($this->getOpsResponse(), $this->getOrder());
244
+
245
+ } else {
246
+ // simulate initial request
247
+ $this->getPaymentHelper()->applyStateForOrder($this->getOrder(), $this->getOpsResponse());
248
+ }
249
+ $this->getMessageContainer()->addSuccess($this->getDataHelper()->__('Ingenico Payment Services status successfully updated'));
250
+
251
+ return $this;
252
+ }
253
+
254
+ public function getTransitionModel()
255
+ {
256
+ if (null == $this->transitionModel) {
257
+ $this->transitionModel = Mage::getModel('ops/status_transition');
258
+ }
259
+
260
+ return $this->transitionModel;
261
+ }
262
+
263
+ public function setTransitionModel(Netresearch_OPS_Model_Status_Transition $transitionModel)
264
+ {
265
+ $this->transitionModel = $transitionModel;
266
+ }
267
+
268
+ public function getPaymentHelper()
269
+ {
270
+ if (null == $this->paymentHelper) {
271
+ $this->paymentHelper = Mage::helper('ops/payment');
272
+ }
273
+
274
+ return $this->paymentHelper;
275
+ }
276
+
277
+ public function setPaymentHelper(Netresearch_OPS_Helper_Payment $paymentHelper)
278
+ {
279
+ $this->paymentHelper = $paymentHelper;
280
+ }
281
+
282
+ public function getDirectLinkHelper()
283
+ {
284
+ if (null == $this->directLinkHelper) {
285
+ $this->directLinkHelper = Mage::helper('ops/directlink');
286
+ }
287
+
288
+ return $this->directLinkHelper;
289
+ }
290
+
291
+ public function setDirectLinkHelper(Netresearch_OPS_Helper_Directlink $directLinkHelper)
292
+ {
293
+ $this->directLinkHelper = $directLinkHelper;
294
+ }
295
+
296
+ /**
297
+ * @param Mage_Sales_Model_Order_Payment $payment
298
+ */
299
+ protected function addPayIdSub(Mage_Sales_Model_Order_Payment $payment)
300
+ {
301
+ $txType = null;
302
+ if ($payment->getAdditionalInformation('status')
303
+ == Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_PROCESSING
304
+ ) {
305
+ $txType = Netresearch_OPS_Model_Payment_Abstract::OPS_CAPTURE_TRANSACTION_TYPE;
306
+ }
307
+ if ($payment->getAdditionalInformation('status') == Netresearch_OPS_Model_Payment_Abstract::OPS_REFUND_WAITING
308
+ ) {
309
+ $txType = Netresearch_OPS_Model_Payment_Abstract::OPS_REFUND_TRANSACTION_TYPE;
310
+ }
311
+ if (null !== $txType) {
312
+ $transaction = $this->getDirectLinkHelper()->getPaymentTransaction(
313
+ $this->getOrder(),
314
+ $this->requestParams['PAYID'],
315
+ $txType
316
+ );
317
+ if (0 < $transaction->getTxnId()) {
318
+ $historyLevel = str_replace(
319
+ $transaction->getParentTxnId() . '/',
320
+ '',
321
+ $transaction->getTxnId()
322
+ );
323
+ $this->requestParams['PAYIDSUB'] = $historyLevel;
324
+ }
325
+ }
326
+ }
327
+
328
+ protected function canNotUseOrderId(Mage_Sales_Model_Order_Payment $payment)
329
+ {
330
+ $methodInstance = $payment->getMethodInstance();
331
+
332
+ return ($methodInstance instanceof Netresearch_OPS_Model_Payment_Kwixo_Abstract)
333
+ || ($methodInstance instanceof Netresearch_OPS_Model_Payment_DirectDebit)
334
+ || ($methodInstance instanceof Netresearch_OPS_Model_Payment_Cc
335
+ && $methodInstance->hasBrandAliasInterfaceSupport($payment));
336
+ }
337
+
338
+ }
app/code/community/Netresearch/OPS/Model/System/Config/Backend/Intersolve/Brands.php ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Netresearch OPS
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ * DISCLAIMER
13
+ *
14
+ * Do not edit or add to this file if you wish to upgrade this extension to
15
+ * newer versions in the future.
16
+ *
17
+ * @category Netresearch
18
+ * @package Netresearch_OPS
19
+ * @copyright Copyright (c) 2012 Netresearch GmbH & Co. KG (http://www.netresearch.de/)
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+
24
+ /**
25
+ *
26
+ *
27
+ * @category Netresearch
28
+ * @package Netresearch_OPS
29
+ * @author Michael Lühr <michael.luehr@netresearch.de>
30
+ */
31
+
32
+ class Netresearch_Ops_Model_System_Config_Backend_Intersolve_Brands
33
+ extends Mage_Adminhtml_Model_System_Config_Backend_Serialized_Array
34
+ {
35
+ protected $_eventPrefix = 'ops_config_backend_intersolve_brands';
36
+
37
+ /**
38
+ * additional validation for unique brands
39
+ *
40
+ * @override
41
+ * @throws Mage_Core_Exception if the brands are not unique -> validation failed
42
+ * @return Netresearch_Ops_Model_System_Config_Backend_Intersolve_Brands
43
+ */
44
+ public function save()
45
+ {
46
+ $brands = $this->getValue();
47
+ if (is_array($brands) && sizeof($brands) > 1) {
48
+ $alreadyProcessedBrands = array();
49
+ foreach ($brands as $brand) {
50
+ if (is_array($brand) && array_key_exists('brand', $brand)) {
51
+ if (in_array($brand['brand'], $alreadyProcessedBrands)) {
52
+ Mage::throwException("Brands must be unique");
53
+ }
54
+ $alreadyProcessedBrands[] = $brand['brand'];
55
+ }
56
+ }
57
+ }
58
+ return parent::save();
59
+ }
60
+ }
app/code/community/Netresearch/OPS/Model/Validator/CompositeInterface.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Michael Lühr <michael.luehr@netresearch.de>
4
+ * @category Netresearch
5
+ * @copyright Copyright (c) 2014 Netresearch GmbH & Co. KG (http://www.netresearch.de)
6
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
7
+ */
8
+ interface Netresearch_OPS_Model_Validator_CompositeInterface
9
+ {
10
+ public function addValidator(Zend_Validate_Interface $validator);
11
+
12
+ }
app/code/community/Netresearch/OPS/Model/Validator/Kwixo/Shipping/Setting.php ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Michael Lühr <michael.luehr@netresearch.de>
4
+ * @category Netresearch
5
+ * @package ${MODULENAME}
6
+ * @copyright Copyright (c) 2013 Netresearch GmbH & Co. KG (http://www.netresearch.de)
7
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
8
+ */
9
+
10
+
11
+ class Netresearch_OPS_Model_Validator_Kwixo_Shipping_Setting
12
+ {
13
+
14
+ private $messages = array();
15
+
16
+ public function isValid(array $data)
17
+ {
18
+ $result = false;
19
+ $methodCodes = array_keys(Mage::getSingleton('shipping/config')->getAllCarriers());
20
+ if (0 < count($data)) {
21
+ $result = true;
22
+ foreach ($data as $code => $row) {
23
+ if (!in_array($code, $methodCodes)) continue;
24
+ $result = $this->validateRow($code, $row) && $result;
25
+ }
26
+ }
27
+ return $result;
28
+ }
29
+
30
+ public function getMessages()
31
+ {
32
+ return $this->messages;
33
+ }
34
+
35
+ private function validateRow($code, $row)
36
+ {
37
+ $shippingTypeResult = $this->validateShippingType($code, $row);
38
+ $shippingSpeedResult = $this->validateShippingSpeed($code, $row);
39
+ $shippingDetailsResult = $this->validateShippingDetails($code, $row);
40
+ return $shippingTypeResult && $shippingSpeedResult && $shippingDetailsResult;
41
+ }
42
+
43
+ private function validateShippingType($code, $row)
44
+ {
45
+ $validValues = Mage::getModel('ops/source_kwixo_shipMethodType')
46
+ ->getValidValues();
47
+
48
+ if (array_key_exists('kwixo_shipping_type', $row)
49
+ && Zend_Validate::is(
50
+ $row['kwixo_shipping_type'], 'Digits'
51
+ )
52
+ && 0 < $row['kwixo_shipping_type']
53
+ && in_array((int)$row['kwixo_shipping_type'], $validValues)
54
+
55
+ ) {
56
+ return true;
57
+ }
58
+ $this->messages[$code]['kwixo_shipping_type_error']
59
+ = 'invalid shipping type provided';
60
+
61
+ return false;
62
+ }
63
+
64
+ private function validateShippingSpeed($code, $row)
65
+ {
66
+ if (array_key_exists('kwixo_shipping_speed', $row)
67
+ && Zend_Validate::is(
68
+ $row['kwixo_shipping_speed'], 'Digits'
69
+ )
70
+ && 0 < $row['kwixo_shipping_speed']
71
+ ) {
72
+ return true;
73
+ }
74
+ $this->messages[$code]['kwixo_shipping_speed_error']
75
+ = 'invalid shipping speed provided';
76
+
77
+ return false;
78
+ }
79
+
80
+ private function validateShippingDetails($code, $row)
81
+ {
82
+ if (array_key_exists('kwixo_shipping_details', $row)
83
+ && Zend_Validate::is(
84
+ $row['kwixo_shipping_details'], 'StringLength',
85
+ array('min' => 0, 'max' => 50)
86
+ )
87
+ ) {
88
+ return true;
89
+ }
90
+ $this->messages[$code]['kwixo_shipping_details_error']
91
+ = 'invalid shipping details provided';
92
+
93
+ return false;
94
+ }
95
+ }
app/code/community/Netresearch/OPS/Model/Validator/Parameter/Factory.php ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Michael Lühr <michael.luehr@netresearch.de>
4
+ * @category Netresearch
5
+ * @copyright Copyright (c) 2014 Netresearch GmbH & Co. KG (http://www.netresearch.de)
6
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
7
+ */
8
+
9
+
10
+ class Netresearch_OPS_Model_Validator_Parameter_Factory extends Mage_Core_Model_Abstract
11
+ {
12
+
13
+ const TYPE_REQUEST_PARAMS_VALIDATION = 'request_validation';
14
+
15
+ protected $validator = null;
16
+
17
+ protected $config = null;
18
+
19
+ /**
20
+ * sets the necessary dependencies for this class
21
+ */
22
+ public function _construct()
23
+ {
24
+ parent::_construct();
25
+ $this->validator = Mage::getModel('ops/validator_parameter_validator');
26
+ $this->config = Mage::getModel('ops/config');
27
+ }
28
+
29
+ /**
30
+ * creates validator for given type
31
+ *
32
+ * @param $type - the requested type
33
+ *
34
+ * @return Netresearch_OPS_Model_Validator_Parameter_Validator
35
+ */
36
+ public function getValidatorFor($type)
37
+ {
38
+ if ($type == self::TYPE_REQUEST_PARAMS_VALIDATION) {
39
+ $this->createRequestParamsValidator();
40
+ }
41
+
42
+ return $this->validator;
43
+ }
44
+
45
+ /**
46
+ * configures the validator for validation of the request parameter
47
+ *
48
+ * @return $this
49
+ */
50
+ protected function createRequestParamsValidator()
51
+ {
52
+ $validator = Mage::getModel('ops/validator_parameter_length');
53
+ $validator->setFieldLengths($this->config->getParameterLengths());
54
+ $this->validator->addValidator($validator);
55
+
56
+ return $this;
57
+ }
58
+ }
app/code/community/Netresearch/OPS/Model/Validator/Parameter/Length.php ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Michael Lühr <michael.luehr@netresearch.de>
4
+ * @category Netresearch
5
+ * @copyright Copyright (c) 2014 Netresearch GmbH & Co. KG (http://www.netresearch.de)
6
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
7
+ */
8
+
9
+
10
+ class Netresearch_OPS_Model_Validator_Parameter_Length implements Zend_Validate_Interface
11
+ {
12
+
13
+ protected $messages = array();
14
+
15
+ protected $fieldLengths = array();
16
+
17
+ /**
18
+ * @param array $fieldLengths - the fieldLengths which are assumed as valid
19
+ */
20
+ public function setFieldLengths(array $fieldLengths)
21
+ {
22
+ $this->fieldLengths = $fieldLengths;
23
+ }
24
+
25
+ /**
26
+ * gets the current configuration of the field lengths
27
+ *
28
+ * @return array
29
+ */
30
+ public function getFieldLengths()
31
+ {
32
+ return $this->fieldLengths;
33
+ }
34
+
35
+ /**
36
+ * checks if the given data matching the given string lengths
37
+ *
38
+ * @param mixed $dataToValidate
39
+ *
40
+ * @return bool
41
+ */
42
+ public function isValid($dataToValidate)
43
+ {
44
+ $validationResult = true;
45
+ if (is_array($dataToValidate) && 0 < count($dataToValidate)) {
46
+ foreach ($dataToValidate as $key => $value) {
47
+ $maxLength = $this->getFieldLengthFor($key);
48
+ if(is_null($value)){
49
+ $value = '';
50
+ }
51
+ if (0 < $maxLength) {
52
+ if (false == Zend_Validate::is(utf8_encode($value), 'StringLength', array('max' => $maxLength, 'encoding' => 'utf-8'))) {
53
+ $this->messages[$key] = Mage::helper('ops/data')->__('value exceeds %d characters', $maxLength);
54
+ $validationResult = false;
55
+ }
56
+ }
57
+ }
58
+ }
59
+
60
+ return $validationResult;
61
+ }
62
+
63
+ /**
64
+ * gets the messages
65
+ *
66
+ * @return array
67
+ */
68
+ public function getMessages()
69
+ {
70
+ return $this->messages;
71
+ }
72
+
73
+ /**
74
+ * gets the valid string length for a given value
75
+ *
76
+ * @param $paramName
77
+ *
78
+ * @return int -1 if not found, the corresponding value otherwise
79
+ */
80
+ protected function getFieldLengthFor($paramName)
81
+ {
82
+ $value = -1;
83
+ if (array_key_exists($paramName, $this->fieldLengths)) {
84
+ $value = $this->fieldLengths[$paramName];
85
+ }
86
+
87
+ return $value;
88
+ }
89
+
90
+ }
app/code/community/Netresearch/OPS/Model/Validator/Parameter/Validator.php ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Michael Lühr <michael.luehr@netresearch.de>
4
+ * @category Netresearch
5
+ * @copyright Copyright (c) 2014 Netresearch GmbH & Co. KG (http://www.netresearch.de)
6
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
7
+ */
8
+
9
+
10
+ class Netresearch_OPS_Model_Validator_Parameter_Validator
11
+ implements Netresearch_OPS_Model_Validator_CompositeInterface, Zend_Validate_Interface
12
+ {
13
+
14
+ protected $validators = array();
15
+
16
+ protected $messages = array();
17
+
18
+ /**
19
+ * adds a validator
20
+ *
21
+ * @param Zend_Validate_Interface $validator
22
+ */
23
+ public function addValidator(Zend_Validate_Interface $validator)
24
+ {
25
+ $this->validators[] = $validator;
26
+ }
27
+
28
+ /**
29
+ * @param $dataToValidate
30
+ *
31
+ * @return bool - indicates whether the data are valid or not
32
+ */
33
+ public function isValid($dataToValidate)
34
+ {
35
+ $isValid = true;
36
+ foreach ($this->validators as $validator) {
37
+ /** @var Zend_Validate_Interface $validator */
38
+ $isValid = $isValid && $validator->isValid($dataToValidate);
39
+ if (false === $validator->isValid($dataToValidate)) {
40
+ $this->messages = array_merge($this->messages, $validator->getMessages());
41
+ }
42
+ }
43
+
44
+ return $isValid;
45
+ }
46
+
47
+ public function getMessages()
48
+ {
49
+ return $this->messages;
50
+ }
51
+
52
+ public function getValidators()
53
+ {
54
+ return $this->validators;
55
+ }
56
+ }
app/code/community/Netresearch/OPS/Model/Validator/Payment/DirectDebit.php ADDED
@@ -0,0 +1,250 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Michael Lühr <michael.luehr@netresearch.de>
4
+ * @category Netresearch
5
+ * @package Netresearch_OPS
6
+ * @copyright Copyright (c) 2014 Netresearch GmbH & Co. KG (http://www.netresearch.de)
7
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
8
+ */
9
+
10
+
11
+ class Netresearch_OPS_Model_Validator_Payment_DirectDebit
12
+ {
13
+
14
+ protected $messages = array();
15
+
16
+ protected $dataHelper = null;
17
+
18
+ protected $directDebitHelper = null;
19
+
20
+ /**
21
+ * sets the data helper
22
+ *
23
+ * @param Mage_Core_Helper_Abstract $dataHelper
24
+ */
25
+ public function setDataHelper(Mage_Core_Helper_Abstract $dataHelper)
26
+ {
27
+ $this->dataHelper = $dataHelper;
28
+ }
29
+
30
+ /**
31
+ * gwets the data helper
32
+ *
33
+ * @return Mage_Core_Helper_Abstract|null
34
+ */
35
+ public function getDataHelper()
36
+ {
37
+ if (null == $this->dataHelper) {
38
+ $this->dataHelper = Mage::helper('ops/data');
39
+ }
40
+
41
+ return $this->dataHelper;
42
+ }
43
+
44
+ /**
45
+ * sets the direct debit helper
46
+ *
47
+ * @param Netresearch_OPS_Helper_DirectDebit $directDebitHelper
48
+ */
49
+ public function setDirectDebitHelper(Netresearch_OPS_Helper_DirectDebit $directDebitHelper)
50
+ {
51
+ $this->directDebitHelper = $directDebitHelper;
52
+ }
53
+
54
+ /**
55
+ * gets the direct debit helper
56
+ *
57
+ * @return Netresearch_OPS_Helper_DirectDebit
58
+ */
59
+ public function getDirectDebitHelper()
60
+ {
61
+ if (null === $this->directDebitHelper) {
62
+ $this->directDebitHelper = Mage::helper('ops/directDebit');
63
+ }
64
+ return $this->directDebitHelper;
65
+ }
66
+
67
+ /**
68
+ * validates the direct debit payment data
69
+ *
70
+ * @param array $directDebitData
71
+ *
72
+ * @return bool - true if the direct data are valid, false otherwise
73
+ */
74
+ public function isValid(array $directDebitData)
75
+ {
76
+ if (false === $this->checkPreconditions($directDebitData)) {
77
+ return false;
78
+ }
79
+
80
+ return $this->validateAccountData($directDebitData);
81
+ }
82
+
83
+ /**
84
+ * gets the validation messages
85
+ *
86
+ * @return array
87
+ */
88
+ public function getMessages()
89
+ {
90
+ return $this->messages;
91
+ }
92
+
93
+ /**
94
+ * checks if the neccesaary data are present
95
+ *
96
+ * @param array $accountData
97
+ *
98
+ * @return bool - true if the neccessary data are present, false otherwise
99
+ */
100
+ protected function checkPreconditions(array $accountData)
101
+ {
102
+ if (0 == count($accountData)
103
+ || !array_key_exists(
104
+ 'CN', $accountData
105
+ )
106
+ || !array_key_exists('country', $accountData)
107
+ || !array_key_exists('account', $accountData)
108
+ || !array_key_exists('iban', $accountData)
109
+ ) {
110
+ $this->messages[] = $this->getDataHelper()->__(
111
+ 'invalid data provided'
112
+ );
113
+
114
+ return false;
115
+ }
116
+
117
+ return true;
118
+ }
119
+
120
+ /**
121
+ * checks if the account data are valid
122
+ *
123
+ * @param array $accountData
124
+ *
125
+ * @return bool - true if the data are valid, false otherise
126
+ */
127
+ protected function validateAccountData(array $accountData)
128
+ {
129
+ $result = true;
130
+ if ($this->hasAccountHolder($accountData)) {
131
+ $this->messages[] = $this->getDataHelper()->__(
132
+ 'Account holder must be provided'
133
+ );
134
+ $result = false;
135
+ }
136
+
137
+ // check iban data
138
+ if ($this->hasIban($accountData)) {
139
+ $result = $this->validateIban(
140
+ $accountData['country'], $accountData['iban'],
141
+ (array_key_exists('bic', $accountData))? $accountData['bic'] : ''
142
+ );
143
+ }
144
+ // check bank account data
145
+ else {
146
+ $result = $this->validateBankAccount(
147
+ $accountData['country'], $accountData['account'],
148
+ (array_key_exists('bankcode', $accountData))
149
+ ? $accountData['bankcode'] : ''
150
+ );
151
+ }
152
+
153
+ return $result;
154
+ }
155
+
156
+
157
+ /**
158
+ * validates iban and (optional) bic data
159
+ *
160
+ * @param $country - the country for the iban
161
+ * @param $iban - the iban to validate
162
+ * @param $bic - the bic if given
163
+ *
164
+ * @return bool - true if the iban data are valid, false otherwise
165
+ */
166
+ protected function validateIban($country, $iban, $bic)
167
+ {
168
+ $country = strtoupper(trim($country));
169
+ $result = true;
170
+ if ('DE' != $country && 'NL' != $country) {
171
+ $result = false;
172
+ $this->messages[] = $this->getDataHelper()->__(
173
+ 'Country not supported for IBAN'
174
+ );
175
+ }
176
+ $validator = new Zend_Validate_Iban();
177
+
178
+ if (!$validator->isValid($iban)) {
179
+ $result = false;
180
+
181
+ $this->messages[] = $this->getDataHelper()->__('Invalid IBAN provided');
182
+ }
183
+ if ('NL' == $country
184
+ && (11 < strlen(trim($bic)))
185
+ ) {
186
+ $result = false;
187
+ $this->messages[] = $this->getDataHelper()->__(
188
+ 'invalid BIC provided'
189
+ );
190
+
191
+ }
192
+
193
+ return $result;
194
+ }
195
+
196
+ /**
197
+ * validates bank account data
198
+ *
199
+ * @param $country - the country for the bank account data
200
+ * @param $accountNo - the account number
201
+ * @param $bankCode - the bank code
202
+ *
203
+ * @return bool - true if the data are valid, false otherwise
204
+ */
205
+ protected function validateBankAccount($country, $accountNo, $bankCode)
206
+ {
207
+ $result = true;
208
+ if (!is_numeric($accountNo)) {
209
+ $this->messages[] = $this->getDataHelper()->__(
210
+ 'Account number must contain numbers only.'
211
+ );
212
+ $result = false;
213
+ }
214
+ $country = strtolower($country);
215
+ if (('de' == $country || 'at' == $country) && !is_numeric($bankCode)) {
216
+ $this->messages[] = $this->getDataHelper()->__(
217
+ 'Bank code must contain numbers only.'
218
+ );
219
+ $result = false;
220
+ }
221
+
222
+ return $result;
223
+ }
224
+
225
+ /**
226
+ * checks if account holder is provided in the given account data
227
+ *
228
+ * @param array $accountData
229
+ *
230
+ * @return bool - true if account holder is present, false otherwise
231
+ */
232
+ protected function hasAccountHolder(array $accountData)
233
+ {
234
+ return array_key_exists('CN', $accountData)
235
+ && 0 === strlen(trim($accountData['CN']));
236
+ }
237
+
238
+ /**
239
+ * checks if the account data has the ibna field
240
+ *
241
+ * @param array $accountData
242
+ *
243
+ * @return bool - true if the account data contain the iban
244
+ */
245
+ protected function hasIban(array $accountData)
246
+ {
247
+ return $this->getDirectDebitHelper()->hasIban($accountData);
248
+ }
249
+
250
+ }
app/code/community/Netresearch/OPS/Test/Block/Adminhtml/Customer/Renderer/StateTest.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Netresearch_OPS_Test_Block_Adminhtml_Customer_Renderer_StateTest
4
+ extends EcomDev_PHPUnit_Test_Case
5
+ {
6
+
7
+ public function testRender()
8
+ {
9
+ $column = new Varien_Object();
10
+ $column->setIndex('state');
11
+ $row = new Varien_Object();
12
+ $row->setData(array('state' => Netresearch_OPS_Model_Alias_State::ACTIVE));
13
+ $block = Mage::app()->getLayout()->getBlockSingleton(
14
+ 'ops/adminhtml_customer_renderer_state'
15
+ );
16
+ $block->setColumn($column);
17
+ $this->assertEquals(
18
+ Mage::helper('ops/data')->__(
19
+ Netresearch_OPS_Model_Alias_State::ACTIVE
20
+ ) , $block->render($row)
21
+ );
22
+ }
23
+ }
app/code/community/Netresearch/OPS/Test/Block/Adminhtml/Kwixo/Shipping/EditTest.php ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @author Michael Lühr <michael.luehr@netresearch.de>
5
+ * @category Netresearch
6
+ * @package Netresearch_OPS
7
+ * @copyright Copyright (c) 2013 Netresearch GmbH & Co. KG (http://www.netresearch.de)
8
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
9
+ */
10
+ class Netresearch_OPS_Test_Block_Adminhtml_Kwixo_Shipping_EditTest
11
+ extends EcomDev_PHPUnit_Test_Case
12
+ {
13
+
14
+ public function setUp()
15
+ {
16
+ $sessionMock = $this->getModelMock(
17
+ 'core/session', array('init', 'save', 'getSessionIdForHost')
18
+ );
19
+
20
+ $this->replaceByMock('model', 'core/session', $sessionMock);
21
+ }
22
+
23
+ public function testGetFormActionUrl()
24
+ {
25
+
26
+ $widgetContainer = new Mage_Adminhtml_Block_Widget_Form_Container();
27
+ $block
28
+ = new Netresearch_OPS_Block_Adminhtml_Kwixo_Shipping_Edit();
29
+ $this->assertEquals(
30
+ $widgetContainer->getUrl('adminhtml/kwixoshipping/save', array()),
31
+ $block->getFormActionUrl()
32
+ );
33
+ }
34
+
35
+ public function testGetShippingMethods()
36
+ {
37
+ $shippingConfigMock = $this->getModelMock(
38
+ 'shipping/config', array('getAllCarriers')
39
+ );
40
+ $shippingConfigMock->expects($this->any())
41
+ ->method('getAllCarriers')
42
+ ->will(
43
+ $this->returnValue(
44
+ array('dhl' => 'dhl', 'hermes' => 'hermes', 'ips' => 'ips')
45
+ )
46
+ );
47
+ $this->replaceByMock('model', 'shipping/config', $shippingConfigMock);
48
+
49
+ $block = new Netresearch_OPS_Block_Adminhtml_Kwixo_Shipping_Edit();
50
+ $result = $block->getShippingMethods();
51
+ $this->assertEquals(3, count($result));
52
+ $this->assertEquals($result[0]['code'], 'dhl');
53
+ $this->assertEquals($result[1]['code'], 'hermes');
54
+ $this->assertEquals($result[1]['label'], 'hermes');
55
+ $this->assertEquals($result[2]['code'], 'ips');
56
+ $this->assertEquals($result[2]['label'], 'ips');
57
+
58
+ $block->setData(
59
+ 'postData', array('dhl' => array('error' => 'sample error'))
60
+ );
61
+ $result = $block->getShippingMethods();
62
+ $this->assertEquals($result[0]['values']['error'], 'sample error');
63
+ }
64
+
65
+ public function testGetKwixoShippingTypes()
66
+ {
67
+ $block = new Netresearch_OPS_Block_Adminhtml_Kwixo_Shipping_Edit();
68
+ $expectedResult = Mage::getModel('ops/source_kwixo_shipMethodType')
69
+ ->toOptionArray();
70
+ $this->assertEquals($expectedResult, $block->getKwixoShippingTypes());
71
+ }
72
+
73
+
74
+ public function testGetFormKey()
75
+ {
76
+ $block = new Netresearch_OPS_Block_Adminhtml_Kwixo_Shipping_Edit();
77
+ $expectedResult = Mage::getSingleton('core/session')->getFormKey();
78
+ $this->assertEquals($expectedResult, $block->getFormKey());
79
+ }
80
+
81
+ }
app/code/community/Netresearch/OPS/Test/Block/Adminhtml/Sales/Order/Creditmemo/Totals/CheckboxTest.php ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Netresearch_OPS_Test_Block_Adminhtml_Sales_Order_Creditmemo_Totals_CheckboxTest extends EcomDev_PHPUnit_Test_Case
3
+ {
4
+
5
+ public function testGetTemplate()
6
+ {
7
+ $block = Mage::app()->getLayout()->getBlockSingleton('ops/adminhtml_sales_order_creditmemo_totals_checkbox');
8
+ $this->assertEquals('ops/sales/order/creditmemo/totals/checkbox.phtml', $block->getTemplate());
9
+ }
10
+
11
+ }
app/code/community/Netresearch/OPS/Test/Block/Adminhtml/Sales/Order/Invoice/Warning/OpenInvoiceTest.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Michael Lühr <michael.luehr@netresearch.de>
4
+ * @category Netresearch
5
+ * @copyright Copyright (c) 2014 Netresearch GmbH & Co. KG (http://www.netresearch.de)
6
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
7
+ */
8
+
9
+
10
+ class Netresearch_OPS_Test_Block_Adminhtml_Sales_Order_Invoice_Warning_OpenInvoiceTest extends EcomDev_PHPUnit_Test_Case
11
+ {
12
+
13
+ public function testGetTemplate()
14
+ {
15
+ $block = Mage::app()->getLayout()->getBlockSingleton('ops/adminhtml_sales_order_invoice_warning_openInvoice');
16
+ $this->assertEquals('ops/sales/order/invoice/warning/open-invoice.phtml', $block->getTemplate());
17
+ }
18
+
19
+ }
app/code/community/Netresearch/OPS/Test/Block/Alias/ListTest.php ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category OPS
4
+ * @package Netresearch_OPS
5
+ * @author Thomas Birke <thomas.birke@netresearch.de>
6
+ * @author Michael Lühr <michael.luehr@netresearch.de>
7
+ * @copyright Copyright (c) 2012 Netresearch GmbH & Co. KG
8
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
9
+ */
10
+
11
+ /**
12
+ * Netresearch_OPS_Test_Block_Alias_ListTest
13
+ *
14
+ * @author Thomas Birke <thomas.birke@netresearch.de>
15
+ * @author Michael Lühr <michael.luehr@netresearch.de>
16
+ * @copyright Copyright (c) 2012 Netresearch GmbH & Co. KG
17
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
+ */
19
+ class Netresearch_OPS_Test_Block_Alias_ListTest
20
+ extends EcomDev_PHPUnit_Test_Case
21
+ {
22
+ private $block;
23
+
24
+ public function setUp()
25
+ {
26
+ parent::setup();
27
+ $this->block = Mage::app()->getLayout()->getBlockSingleton('ops/alias_list');
28
+ }
29
+
30
+ public function testGetMethodName()
31
+ {
32
+ $this->assertNull($this->block->getMethodName('something_stupid'));
33
+
34
+ Mage::app()->getStore()->setConfig('payment/ops_cc/title', 'OPS Credit Card');
35
+ $this->assertEquals(
36
+ 'OPS Credit Card',
37
+ $this->block->getMethodName('ops_cc')
38
+ );
39
+ }
40
+
41
+ public function testGetAliasDeleteUrl()
42
+ {
43
+ // array('_secure' => Mage::app()->getFrontController()->getRequest()->isSecure());
44
+ $this->mockSessions();
45
+ $aliasId = 1;
46
+ // previous behaviour until OGNB-229: Mage::getUrl('ops/customer/deleteAlias/id/' . $aliasId)
47
+ $this->assertEquals(Mage::getUrl('ops/customer/deleteAlias/id/' . $aliasId), $this->block->getAliasDeleteUrl($aliasId));
48
+
49
+ // new since OGNB-229: passed aliasId as array param
50
+ $this->assertEquals(Mage::getUrl('ops/customer/deleteAlias/', array('id' => $aliasId)), $this->block->getAliasDeleteUrl($aliasId));
51
+
52
+ $_SERVER['HTTPS'] = 'on';
53
+ $this->assertEquals(
54
+ Mage::getUrl(
55
+ 'ops/customer/deleteAlias/',
56
+ array(
57
+ '_secure' => true,
58
+ 'id' => $aliasId)
59
+ ),
60
+ $this->block->getAliasDeleteUrl($aliasId)
61
+ );
62
+ }
63
+ protected function mockSessions()
64
+ {
65
+ $sessionMock = $this->getModelMockBuilder('checkout/session')
66
+ ->disableOriginalConstructor() // This one removes session_start and other methods usage
67
+ ->getMock();
68
+ $this->replaceByMock('singleton', 'core/session', $sessionMock);
69
+
70
+ $sessionMock = $this->getModelMockBuilder('customer/session')
71
+ ->disableOriginalConstructor() // This one removes session_start and other methods usage
72
+ ->getMock();
73
+ $this->replaceByMock('singleton', 'customer/session', $sessionMock);
74
+ }
75
+
76
+ }
77
+
app/code/community/Netresearch/OPS/Test/Block/Form/CcTest.php ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Netresearch_OPS_Test_Block_Form_CcTest extends EcomDev_PHPUnit_Test_Case
4
+ {
5
+
6
+ public function testGetAliasBrands()
7
+ {
8
+
9
+ $aliasBrands = array(
10
+ 'American Express',
11
+ 'Diners Club',
12
+ 'MaestroUK',
13
+ 'MasterCard',
14
+ 'VISA',
15
+ );
16
+
17
+ $ccAliasInterfaceEnabledTypesMock = $this->getModelMock('ops/source_cc_aliasInterfaceEnabledTypes', array('getAliasInterfaceCompatibleTypes'));
18
+ $ccAliasInterfaceEnabledTypesMock->expects($this->any())
19
+ ->method('getAliasInterfaceCompatibleTypes')
20
+ ->will($this->returnValue($aliasBrands));
21
+ $this->replaceByMock('model', 'ops/source_cc_aliasInterfaceEnabledTypes', $ccAliasInterfaceEnabledTypesMock);
22
+ $ccForm = Mage::app()->getLayout()->getBlockSingleton('ops/form_cc');
23
+ $ccAliases = $ccForm->getAliasBrands();
24
+ $this->assertEquals($aliasBrands, $ccAliases);
25
+ }
26
+
27
+
28
+ public function testTemplate()
29
+ {
30
+ //Frontend case
31
+ $modelMock = $this->getModelMock('ops/config', array('isFrontendEnvironment'));
32
+ $modelMock->expects($this->any())
33
+ ->method('isFrontendEnvironment')
34
+ ->will($this->returnValue(true));
35
+ $this->replaceByMock('model', 'ops/config', $modelMock);
36
+ $ccForm = new Netresearch_OPS_Block_Form_Cc();
37
+ $this->assertEquals(Netresearch_OPS_Block_Form::FRONTEND_TEMPLATE, $ccForm->getTemplate());
38
+
39
+ //Backend case
40
+ $modelMock = $this->getModelMock('ops/config', array('isFrontendEnvironment'));
41
+ $modelMock->expects($this->any())
42
+ ->method('isFrontendEnvironment')
43
+ ->will($this->returnValue(false));
44
+ $this->replaceByMock('model', 'ops/config', $modelMock);
45
+ $ccForm = new Netresearch_OPS_Block_Form_Cc();
46
+ $this->assertEquals(Netresearch_OPS_Block_Form_Cc::BACKEND_TEMPLATE, $ccForm->getTemplate());
47
+ }
48
+ }
app/code/community/Netresearch/OPS/Test/Block/Form/DirectDebitTest.php ADDED
@@ -0,0 +1,332 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Netresearch_OPS_Test_Block_Form_DirectDebitTest
4
+ extends EcomDev_PHPUnit_Test_Case
5
+ {
6
+ public function testTemplate()
7
+ {
8
+ //Frontend case
9
+ $modelMock = $this->getModelMock(
10
+ 'ops/config', array('isFrontendEnvironment')
11
+ );
12
+ $modelMock->expects($this->any())
13
+ ->method('isFrontendEnvironment')
14
+ ->will($this->returnValue(true));
15
+ $this->replaceByMock('model', 'ops/config', $modelMock);
16
+ $ccForm = new Netresearch_OPS_Block_Form_DirectDebit();
17
+ $this->assertEquals(
18
+ Netresearch_OPS_Block_Form::FRONTEND_TEMPLATE,
19
+ $ccForm->getTemplate()
20
+ );
21
+
22
+ //Backend case
23
+ $modelMock = $this->getModelMock(
24
+ 'ops/config', array('isFrontendEnvironment')
25
+ );
26
+ $modelMock->expects($this->any())
27
+ ->method('isFrontendEnvironment')
28
+ ->will($this->returnValue(false));
29
+ $this->replaceByMock('model', 'ops/config', $modelMock);
30
+ $ccForm = new Netresearch_OPS_Block_Form_DirectDebit();
31
+ $this->assertEquals(
32
+ Netresearch_OPS_Block_Form_DirectDebit::BACKEND_TEMPLATE,
33
+ $ccForm->getTemplate()
34
+ );
35
+ }
36
+
37
+ public function testDirectDebitCountryIds()
38
+ {
39
+ $fakeConfig = new Varien_Object();
40
+ $fakeConfig->setDirectDebitCountryIds("AT, DE, NL");
41
+ $blockMock = $this->getBlockMock(
42
+ 'ops/form_directDebit', array('getconfig')
43
+ );
44
+ $blockMock->expects($this->once())
45
+ ->method('getConfig')
46
+ ->will($this->returnValue($fakeConfig));
47
+ $this->assertEquals(
48
+ explode(',', 'AT, DE, NL'), $blockMock->getDirectDebitCountryIds()
49
+ );
50
+ }
51
+
52
+ public function testGetParams()
53
+ {
54
+ $sessionMock = $this->getModelMock(
55
+ 'adminhtml/session', array('init', 'save')
56
+ );
57
+ $this->replaceByMock('model', 'adminhtml/session', $sessionMock);
58
+ $block = new Netresearch_OPS_Block_Form_DirectDebit();
59
+ $expectedResult = array(
60
+ 'country' => '',
61
+ 'CN' => '',
62
+ 'iban' => '',
63
+ 'bic' => '',
64
+ 'account' => '',
65
+ 'bankcode' => ''
66
+ );
67
+ $this->assertEquals($expectedResult, $block->getParams());
68
+ $newParams = array('bla' => 'foo');
69
+ $sessionMock->setData(
70
+ 'ops_direct_debit_params', $newParams
71
+ );
72
+ $result = $block->getParams();
73
+ $this->assertFalse($sessionMock->hasData('ops_direct_debit_params'));
74
+ $this->assertEquals($newParams, $result);
75
+
76
+ }
77
+
78
+ public function testIsIbanFieldRequired()
79
+ {
80
+ $sessionMock = $this->getModelMock(
81
+ 'adminhtml/session', array('init', 'save')
82
+ );
83
+ $this->replaceByMock('model', 'adminhtml/session', $sessionMock);
84
+ $block = new Netresearch_OPS_Block_Form_DirectDebit();
85
+ $this->assertTrue($block->isIbanFieldRequired());
86
+ $newParams = array('iban' => 'foo');
87
+ $sessionMock->setData(
88
+ 'ops_direct_debit_params', $newParams
89
+ );
90
+ $block->getParams();
91
+ $this->assertTrue($block->isIbanFieldRequired());
92
+ $newParams = array('account' => '');
93
+ $sessionMock->setData(
94
+ 'ops_direct_debit_params', $newParams
95
+ );
96
+ $block->getParams();
97
+ $this->assertTrue($block->isIbanFieldRequired());
98
+
99
+ $newParams = array('account' => '123456');
100
+ $sessionMock->setData(
101
+ 'ops_direct_debit_params', $newParams
102
+ );
103
+ $block->getParams();
104
+ $this->assertFalse($block->isIbanFieldRequired());
105
+ }
106
+
107
+ public function testIsAccountFieldRequired()
108
+ {
109
+ $sessionMock = $this->getModelMock(
110
+ 'adminhtml/session', array('init', 'save')
111
+ );
112
+ $this->replaceByMock('model', 'adminhtml/session', $sessionMock);
113
+ $block = new Netresearch_OPS_Block_Form_DirectDebit();
114
+ $this->assertTrue($block->isAccountFieldRequired());
115
+ $newParams = array('account' => 'foo');
116
+ $sessionMock->setData(
117
+ 'ops_direct_debit_params', $newParams
118
+ );
119
+ $block->getParams();
120
+ $this->assertTrue($block->isAccountFieldRequired());
121
+ $newParams = array('account' => '');
122
+ $sessionMock->setData(
123
+ 'ops_direct_debit_params', $newParams
124
+ );
125
+ $block->getParams();
126
+ $this->assertTrue($block->isAccountFieldRequired());
127
+
128
+ $newParams = array('account' => '123456', 'iban' => '');
129
+ $sessionMock->setData(
130
+ 'ops_direct_debit_params', $newParams
131
+ );
132
+ $block->getParams();
133
+ $this->assertTrue($block->isAccountFieldRequired());
134
+
135
+ $newParams = array('account' => '123456', 'iban' => '123456');
136
+ $sessionMock->setData(
137
+ 'ops_direct_debit_params', $newParams
138
+ );
139
+ $block->getParams();
140
+ $this->assertFalse($block->isAccountFieldRequired());
141
+ }
142
+
143
+
144
+ public function testIsBankCodeFieldRequired()
145
+ {
146
+ $sessionMock = $this->getModelMock(
147
+ 'adminhtml/session', array('init', 'save')
148
+ );
149
+ $this->replaceByMock('model', 'adminhtml/session', $sessionMock);
150
+ $block = new Netresearch_OPS_Block_Form_DirectDebit();
151
+ $this->assertFalse($block->isBankCodeFieldRequired());
152
+
153
+ $newParams = array('account' => '12345');
154
+ $sessionMock->setData(
155
+ 'ops_direct_debit_params', $newParams
156
+ );
157
+ $block->getParams();
158
+ $this->assertFalse($block->isBankCodeFieldRequired());
159
+
160
+ $newParams = array('account' => '123456', 'country' => 'de');
161
+ $sessionMock->setData(
162
+ 'ops_direct_debit_params', $newParams
163
+ );
164
+ $block->getParams();
165
+ $this->assertTrue($block->isBankCodeFieldRequired());
166
+ }
167
+
168
+ public function testIsBankCodeFieldVisible()
169
+ {
170
+ $sessionMock = $this->getModelMock(
171
+ 'adminhtml/session', array('init', 'save')
172
+ );
173
+ $this->replaceByMock('model', 'adminhtml/session', $sessionMock);
174
+ $block = new Netresearch_OPS_Block_Form_DirectDebit();
175
+ $this->assertFalse($block->isBankCodeFieldVisible());
176
+ $newParams = array('country' => 'at');
177
+ $sessionMock->setData(
178
+ 'ops_direct_debit_params', $newParams
179
+ );
180
+ $block->getParams();
181
+ $this->assertTrue($block->isBankCodeFieldVisible());
182
+
183
+ $newParams = array('country' => 'de');
184
+ $sessionMock->setData(
185
+ 'ops_direct_debit_params', $newParams
186
+ );
187
+ $block->getParams();
188
+ $this->assertTrue($block->isBankCodeFieldVisible());
189
+
190
+ $newParams = array('country' => 'nl');
191
+ $sessionMock->setData(
192
+ 'ops_direct_debit_params', $newParams
193
+ );
194
+ $block->getParams();
195
+ $this->assertFalse($block->isBankCodeFieldVisible());
196
+ }
197
+
198
+ public function testIsBicFieldVisible()
199
+ {
200
+ $sessionMock = $this->getModelMock(
201
+ 'adminhtml/session', array('init', 'save')
202
+ );
203
+ $this->replaceByMock('model', 'adminhtml/session', $sessionMock);
204
+ $block = new Netresearch_OPS_Block_Form_DirectDebit();
205
+ $this->assertFalse($block->isBicFieldVisible());
206
+
207
+ $newParams = array('country' => 'de');
208
+ $sessionMock->setData(
209
+ 'ops_direct_debit_params', $newParams
210
+ );
211
+ $block->getParams();
212
+ $this->assertFalse($block->isBicFieldVisible());
213
+
214
+ $newParams = array('country' => 'at');
215
+ $sessionMock->setData(
216
+ 'ops_direct_debit_params', $newParams
217
+ );
218
+ $block->getParams();
219
+ $this->assertFalse($block->isBicFieldVisible());
220
+
221
+ $newParams = array('country' => 'nl');
222
+ $sessionMock->setData(
223
+ 'ops_direct_debit_params', $newParams
224
+ );
225
+ $block->getParams();
226
+ $this->assertTrue($block->isBicFieldVisible());
227
+ }
228
+
229
+ public function testGetCountry()
230
+ {
231
+ $sessionMock = $this->getModelMock(
232
+ 'adminhtml/session', array('init', 'save')
233
+ );
234
+ $this->replaceByMock('model', 'adminhtml/session', $sessionMock);
235
+ $block = new Netresearch_OPS_Block_Form_DirectDebit();
236
+ $this->assertEquals('', $block->getCountry());
237
+ $newParams = array('country' => 'de');
238
+ $sessionMock->setData(
239
+ 'ops_direct_debit_params', $newParams
240
+ );
241
+ $block->getParams();
242
+ $this->assertEquals('de', $block->getCountry());
243
+
244
+ }
245
+
246
+ public function testGetIban()
247
+ {
248
+ $sessionMock = $this->getModelMock(
249
+ 'adminhtml/session', array('init', 'save')
250
+ );
251
+ $this->replaceByMock('model', 'adminhtml/session', $sessionMock);
252
+ $block = new Netresearch_OPS_Block_Form_DirectDebit();
253
+ $this->assertEquals('', $block->getIban());
254
+ $newParams = array('iban' => '1234567');
255
+ $sessionMock->setData(
256
+ 'ops_direct_debit_params', $newParams
257
+ );
258
+ $block->getParams();
259
+ $this->assertEquals('1234567', $block->getIban());
260
+
261
+ }
262
+
263
+ public function testGetBic()
264
+ {
265
+ $sessionMock = $this->getModelMock(
266
+ 'adminhtml/session', array('init', 'save')
267
+ );
268
+ $this->replaceByMock('model', 'adminhtml/session', $sessionMock);
269
+ $block = new Netresearch_OPS_Block_Form_DirectDebit();
270
+ $this->assertEquals('', $block->getBic());
271
+ $newParams = array('bic' => '1234567');
272
+ $sessionMock->setData(
273
+ 'ops_direct_debit_params', $newParams
274
+ );
275
+ $block->getParams();
276
+ $this->assertEquals('1234567', $block->getBic());
277
+
278
+ }
279
+
280
+ public function testGetAccount()
281
+ {
282
+ $sessionMock = $this->getModelMock(
283
+ 'adminhtml/session', array('init', 'save')
284
+ );
285
+ $this->replaceByMock('model', 'adminhtml/session', $sessionMock);
286
+ $block = new Netresearch_OPS_Block_Form_DirectDebit();
287
+ $this->assertEquals('', $block->getAccount());
288
+ $newParams = array('account' => '1234567');
289
+ $sessionMock->setData(
290
+ 'ops_direct_debit_params', $newParams
291
+ );
292
+ $block->getParams();
293
+ $this->assertEquals('1234567', $block->getAccount());
294
+
295
+ }
296
+
297
+ public function testGetBankcode()
298
+ {
299
+ $sessionMock = $this->getModelMock(
300
+ 'adminhtml/session', array('init', 'save')
301
+ );
302
+ $this->replaceByMock('model', 'adminhtml/session', $sessionMock);
303
+ $block = new Netresearch_OPS_Block_Form_DirectDebit();
304
+ $this->assertEquals('', $block->getBankcode());
305
+ $newParams = array('bankcode' => '1234567');
306
+ $sessionMock->setData(
307
+ 'ops_direct_debit_params', $newParams
308
+ );
309
+ $block->getParams();
310
+ $this->assertEquals('1234567', $block->getBankcode());
311
+
312
+ }
313
+
314
+ public function testGetCardholderName()
315
+ {
316
+ $sessionMock = $this->getModelMock(
317
+ 'adminhtml/session', array('init', 'save')
318
+ );
319
+ $this->replaceByMock('model', 'adminhtml/session', $sessionMock);
320
+ $block = new Netresearch_OPS_Block_Form_DirectDebit();
321
+ $this->assertEquals('', $block->getCardholderName());
322
+ $newParams = array('CN' => 'Hans wurst');
323
+ $sessionMock->setData(
324
+ 'ops_direct_debit_params', $newParams
325
+ );
326
+ $block->getParams();
327
+ $this->assertEquals('Hans wurst', $block->getCardholderName());
328
+
329
+ }
330
+
331
+
332
+ }
app/code/community/Netresearch/OPS/Test/Block/Form/Ideal.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Netresearch_OPS_Test_Block_Form_Ideal extends EcomDev_PHPUnit_Test_Case
4
+ {
5
+ public function testGetIssuers()
6
+ {
7
+ $issuers = Mage::getModel('ops/payment_iDeal')->getIDealIssuers();
8
+ $block = Mage::app()->getLayout()->createBlock('ops/form_Ideal');
9
+ $this->assertEquals($issuers,$block->getIssuers());
10
+
11
+ }
12
+ }
app/code/community/Netresearch/OPS/Test/Block/Form/Kwixo/ApresReceptionTest.php ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Michael Lühr <michael.luehr@netresearch.de>
4
+ * @category Netresearch
5
+ * @package Netresearch_OPS
6
+ * @copyright Copyright (c) 2013 Netresearch GmbH & Co. KG (http://www.netresearch.de)
7
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
8
+ */
9
+
10
+ class Netresearch_OPS_Test_Block_Form_Kwixo_ApresReceptionTest extends EcomDev_PHPUnit_Test_Case
11
+ {
12
+
13
+ protected $block = null;
14
+
15
+ public function setUp()
16
+ {
17
+ $this->block = new Netresearch_OPS_Block_Form_Kwixo_ApresReception();
18
+ }
19
+
20
+ public function testGetTemplate()
21
+ {
22
+ $this->assertEquals('ops/form/kwixo/apres_reception.phtml', $this->block->getTemplate());
23
+ }
24
+
25
+ public function testGetPmLogo()
26
+ {
27
+ $this->assertEquals('images/ops/kwixo/apres_reception.jpg', $this->block->getPmLogo());
28
+ }
29
+ }
app/code/community/Netresearch/OPS/Test/Block/Form/Kwixo/ComptantTest.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Michael Lühr <michael.luehr@netresearch.de>
4
+ * @category Netresearch
5
+ * @package Netresearch_OPS
6
+ * @copyright Copyright (c) 2013 Netresearch GmbH & Co. KG (http://www.netresearch.de)
7
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
8
+ */
9
+
10
+
11
+ class Netresearch_OPS_Test_Block_Form_Kwixo_ComptantTest extends EcomDev_PHPUnit_Test_Case
12
+ {
13
+ protected $block = null;
14
+
15
+ public function setUp()
16
+ {
17
+ $this->block = new Netresearch_OPS_Block_Form_Kwixo_Comptant();
18
+ }
19
+
20
+ public function testGetTemplate()
21
+ {
22
+ $this->assertEquals('ops/form/kwixo/comptant.phtml', $this->block->getTemplate());
23
+ }
24
+
25
+ public function testGetPmLogo()
26
+ {
27
+ $this->assertEquals('images/ops/kwixo/comptant.jpg', $this->block->getPmLogo());
28
+ }
29
+
30
+ }
app/code/community/Netresearch/OPS/Test/Block/Form/Kwixo/CreditTest.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Michael Lühr <michael.luehr@netresearch.de>
4
+ * @category Netresearch
5
+ * @package Netresearch_OPS
6
+ * @copyright Copyright (c) 2013 Netresearch GmbH & Co. KG (http://www.netresearch.de)
7
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
8
+ */
9
+
10
+
11
+
12
+
13
+ class Netresearch_OPS_Test_Block_Form_Kwixo_CreditTest extends EcomDev_PHPUnit_Test_Case
14
+ {
15
+
16
+ protected $block = null;
17
+
18
+ public function setUp()
19
+ {
20
+ $this->block = new Netresearch_OPS_Block_Form_Kwixo_Credit();
21
+ }
22
+
23
+ public function testGetTemplate()
24
+ {
25
+ $block = new Netresearch_OPS_Block_Form_Kwixo_Credit();
26
+ $this->assertEquals('ops/form/kwixo/credit.phtml', $block->getTemplate());
27
+ }
28
+
29
+ public function testGetPmLogo()
30
+ {
31
+ $this->assertEquals('images/ops/kwixo/credit.jpg', $this->block->getPmLogo());
32
+ }
33
+
34
+ }
app/code/community/Netresearch/OPS/Test/Block/FormTest.php ADDED
@@ -0,0 +1,504 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Netresearch_OPS_Test_Block_FormTest
3
+ extends EcomDev_PHPUnit_Test_Case_Controller
4
+ {
5
+ private $_block;
6
+
7
+ public function setUp()
8
+ {
9
+ parent::setup();
10
+ $this->_block = Mage::app()->getLayout()->getBlockSingleton('ops/form');
11
+ }
12
+
13
+ public function testGetCcBrands()
14
+ {
15
+ $this->assertInternalType('array', $this->_block->getCcBrands());
16
+ }
17
+
18
+ public function testGetDirectDebitCountryIds()
19
+ {
20
+ $this->assertInternalType(
21
+ 'array', $this->_block->getDirectDebitCountryIds()
22
+ );
23
+ }
24
+
25
+ public function testIsAliasPMEnabled()
26
+ {
27
+ $model = Mage::getModel('ops/config');
28
+ $this->assertEquals(
29
+ $model->isAliasManagerEnabled(), $this->_block->isAliasPMEnabled()
30
+ );
31
+ }
32
+
33
+ public function testGetStoredAliasDataForCustomer()
34
+ {
35
+
36
+ $reflectionClass = new ReflectionClass(get_class($this->_block));
37
+ $method = $reflectionClass->getMethod("getStoredAliasDataForCustomer");
38
+ $method->setAccessible(true);
39
+ $this->assertNull($method->invoke($this->_block, 'bla'));
40
+
41
+ $blockMock = $this->getBlockMock(
42
+ 'ops/form', array('getStoredAliasForCustomer')
43
+ );
44
+ $blockMock->expects($this->once())
45
+ ->method('getStoredAliasForCustomer')
46
+ ->will($this->returnValue(array()));
47
+ $reflectionClass = new ReflectionClass(get_class($blockMock));
48
+ $method = $reflectionClass->getMethod("getStoredAliasDataForCustomer");
49
+ $method->setAccessible(true);
50
+ $this->assertNull($method->invoke($blockMock, 'bla'));
51
+
52
+
53
+ $blockMock = $this->getBlockMock(
54
+ 'ops/form', array('getStoredAliasForCustomer')
55
+ );
56
+ $blockMock->expects($this->once())
57
+ ->method('getStoredAliasForCustomer')
58
+ ->will($this->returnValue(array('bla' => 'foo')));
59
+ $reflectionClass = new ReflectionClass(get_class($blockMock));
60
+ $method = $reflectionClass->getMethod("getStoredAliasDataForCustomer");
61
+ $method->setAccessible(true);
62
+ $this->assertEquals(
63
+ 'foo', $method->invoke($blockMock, 'bla')
64
+ );
65
+
66
+ $blockMock = $this->getBlockMock(
67
+ 'ops/form', array('getStoredAliasForCustomer')
68
+ );
69
+ $blockMock->expects($this->once())
70
+ ->method('getStoredAliasForCustomer')
71
+ ->will($this->returnValue(array('bla' => 'foo')));
72
+ $reflectionClass = new ReflectionClass(get_class($blockMock));
73
+ $method = $reflectionClass->getMethod("getStoredAliasDataForCustomer");
74
+ $method->setAccessible(true);
75
+ $this->assertNull($method->invoke($blockMock, 'foo'));
76
+
77
+ }
78
+
79
+
80
+ public function testGetAliasCardNumber()
81
+ {
82
+ $blockMock = $this->getBlockMock(
83
+ 'ops/form', array('getStoredAliasForCustomer')
84
+ );
85
+ $blockMock->expects($this->any())
86
+ ->method('getStoredAliasForCustomer')
87
+ ->will(
88
+ $this->returnValue(
89
+ array(
90
+ 'pseudo_account_or_cc_no' => 'xxxxxxxxxxxx1111',
91
+ 'brand' => 'visa'
92
+ )
93
+ )
94
+ );
95
+ $this->assertEquals('XXXX XXXX XXXX 1111', $blockMock->getAliasCardNumber());
96
+ }
97
+
98
+ /**
99
+ * @loadFixture ../../../var/fixtures/aliases.yaml
100
+ */
101
+ public function testGetStoredAliasForCustomer()
102
+ {
103
+
104
+ $reflectionClass = new ReflectionClass(get_class($this->_block));
105
+ $method = $reflectionClass->getMethod("getStoredAliasForCustomer");
106
+ $method->setAccessible(true);
107
+ $this->assertNull($method->invoke($this->_block));
108
+
109
+
110
+ $configMock = $this->getModelMock('ops/config', array('isAliasManagerEnabled'));
111
+ $configMock->expects($this->any())
112
+ ->method('isAliasManagerEnabled')
113
+ ->will($this->returnValue(true));
114
+ $this->replaceByMock('model', 'ops/config', $configMock);
115
+
116
+ $aliases = Mage::getModel('ops/alias')
117
+ ->getCollection()
118
+ ->addFieldToFilter('customer_id', 1)
119
+ ->addFieldToFilter('state', Netresearch_OPS_Model_Alias_State::ACTIVE)
120
+ ->setOrder('created_at', Varien_Data_Collection::SORT_ORDER_DESC)
121
+ ;
122
+ $alias = $aliases->getFirstItem();
123
+ $aliasHelperMock = $this->getHelperMock('ops/alias', array('getAliasesForAddresses'));
124
+ $aliasHelperMock->expects($this->once())
125
+ ->method('getAliasesForAddresses')
126
+ ->will($this->returnValue($aliases));
127
+ $this->replaceByMock('helper', 'ops/alias', $aliasHelperMock);
128
+
129
+ $customerMock = $this->getHelperMock('customer/data', array('isLoggedIn'));
130
+ $customerMock->expects($this->once())
131
+ ->method('isLoggedIn')
132
+ ->will($this->returnValue(true));
133
+ $this->replaceByMock('helper', 'customer/data', $customerMock);
134
+
135
+ $fakeCustomer = new Varien_Object();
136
+ $fakeCustomer->setId(1);
137
+
138
+ $fakeQuote = new Varien_Object();
139
+ $fakeQuote->setCustomer($fakeCustomer);
140
+
141
+
142
+
143
+ $blockMock = $this->getBlockMock('ops/form', array('getQuote'));
144
+ $blockMock->expects($this->once())
145
+ ->method('getQuote')
146
+ ->will($this->returnValue($fakeQuote));
147
+ $this->replaceByMock('block', 'ops/form', $blockMock);
148
+
149
+ $reflectionClass = new ReflectionClass(get_class($blockMock));
150
+ $method = $reflectionClass->getMethod("getStoredAliasForCustomer");
151
+ $method->setAccessible(true);
152
+
153
+ $this->assertEquals($alias->getData(), $method->invoke($blockMock));
154
+
155
+ }
156
+
157
+
158
+ public function testGetExpirationDatePart()
159
+ {
160
+ $blockMock = $this->getBlockMock(
161
+ 'ops/form', array('getStoredAliasForCustomer')
162
+ );
163
+ $blockMock->expects($this->any())
164
+ ->method('getStoredAliasForCustomer')
165
+ ->will($this->returnValue(array('expiration_date' => '0416')));
166
+ $this->assertEquals('04', $blockMock->getExpirationDatePart('month'));
167
+ $this->assertEquals('16', $blockMock->getExpirationDatePart('year'));
168
+ }
169
+
170
+ public function testGetCardHolderName()
171
+ {
172
+ $configMock = $this->getModelMock('ops/config', array('isAliasManagerEnabled'));
173
+ $configMock->expects($this->any())
174
+ ->method('isAliasManagerEnabled')
175
+ ->will($this->returnValue(false));
176
+ $this->replaceByMock('model', 'ops/config', $configMock);
177
+
178
+ $this->assertNull($block = $this->_block->getCardHolderName());
179
+
180
+ $configMock = $this->getModelMock('ops/config', array('isAliasManagerEnabled'));
181
+ $configMock->expects($this->any())
182
+ ->method('isAliasManagerEnabled')
183
+ ->will($this->returnValue(true));
184
+ $this->replaceByMock('model', 'ops/config', $configMock);
185
+
186
+
187
+ $blockMock = $this->getBlockMock(
188
+ 'ops/form', array('getStoredAliasDataForCustomer', 'getStoredAlias')
189
+ );
190
+ $blockMock->expects($this->any())
191
+ ->method('getStoredAliasDataForCustomer')
192
+ ->will($this->returnValue('Hubertus von Fürstenberg'));
193
+
194
+ $blockMock->expects($this->any())
195
+ ->method('getStoredAlias')
196
+ ->will($this->returnValue('4711'));
197
+ $this->assertEquals('Hubertus von Fürstenberg', $blockMock->getCardHolderName());
198
+
199
+ $blockMock = $this->getBlockMock(
200
+ 'ops/form', array('getStoredAliasDataForCustomer', 'getStoredAlias')
201
+ );
202
+ $blockMock->expects($this->once())
203
+ ->method('getStoredAliasDataForCustomer')
204
+ ->will($this->returnValue(null));
205
+
206
+ $blockMock->expects($this->any())
207
+ ->method('getStoredAlias')
208
+ ->will($this->returnValue('4711'));
209
+
210
+ $customerHelperMock = $this->getHelperMock('customer/data', array('isLoggedIn', 'getCustomerName'));
211
+ $customerHelperMock->expects($this->any())
212
+ ->method('isLoggedIn')
213
+ ->will($this->returnValue(true));
214
+ $customerHelperMock->expects($this->any())
215
+ ->method('getCustomerName')
216
+ ->will($this->returnValue('Hubertus zu Fürstenberg'));
217
+ $this->replaceByMock('helper', 'customer/data', $customerHelperMock);
218
+
219
+ $this->assertEquals('Hubertus zu Fürstenberg', $blockMock->getCardHolderName());
220
+
221
+ $blockMock = $this->getBlockMock(
222
+ 'ops/form', array('getStoredAliasDataForCustomer', 'getStoredAlias')
223
+ );
224
+ $blockMock->expects($this->once())
225
+ ->method('getStoredAliasDataForCustomer')
226
+ ->will($this->returnValue(''));
227
+
228
+ $blockMock->expects($this->any())
229
+ ->method('getStoredAlias')
230
+ ->will($this->returnValue('4711'));
231
+
232
+ $this->assertEquals('Hubertus zu Fürstenberg', $blockMock->getCardHolderName());
233
+
234
+ $blockMock = $this->getBlockMock(
235
+ 'ops/form', array('getStoredAliasDataForCustomer', 'getStoredAlias')
236
+ );
237
+ $blockMock->expects($this->once())
238
+ ->method('getStoredAliasDataForCustomer')
239
+ ->will($this->returnValue(null));
240
+
241
+ $blockMock->expects($this->any())
242
+ ->method('getStoredAlias')
243
+ ->will($this->returnValue('4711'));
244
+
245
+ $customerHelperMock = $this->getHelperMock('customer/data', array('isLoggedIn'));
246
+ $customerHelperMock->expects($this->any())
247
+ ->method('isLoggedIn')
248
+ ->will($this->returnValue(false));
249
+ $this->replaceByMock('helper', 'customer/data', $customerHelperMock);
250
+
251
+ $this->assertNull($blockMock->getCardHolderName());
252
+
253
+
254
+ }
255
+
256
+ public function testGetStoredAliasBrandWithInlineBrand()
257
+ {
258
+ $blockMock = $this->getBlockMock(
259
+ 'ops/form', array('getStoredAliasForCustomer')
260
+ );
261
+ $blockMock->expects($this->any())
262
+ ->method('getStoredAliasForCustomer')
263
+ ->will(
264
+ $this->returnValue(
265
+ array(
266
+ 'pseudo_account_or_cc_no' => 'xxxxxxxxxxxx1111',
267
+ 'brand' => 'VISA'
268
+ )
269
+ )
270
+ );
271
+
272
+ $modelMock = $this->getModelMock(
273
+ 'ops/config', array('getInlinePaymentCcTypes')
274
+ );
275
+ $modelMock->expects($this->any())
276
+ ->method('getInlinePaymentCcTypes')
277
+ ->will(
278
+ $this->returnValue(
279
+ array(
280
+ 'VISA'
281
+ )
282
+ )
283
+ );
284
+
285
+ $this->assertEquals('VISA', $blockMock->getStoredAliasBrand());
286
+ }
287
+
288
+
289
+ public function testGetStoredAliasBrandWithNonInlineBrand()
290
+ {
291
+ $blockMock = $this->getBlockMock(
292
+ 'ops/form', array('getStoredAliasForCustomer')
293
+ );
294
+ $blockMock->expects($this->any())
295
+ ->method('getStoredAliasForCustomer')
296
+ ->will(
297
+ $this->returnValue(
298
+ array(
299
+ 'pseudo_account_or_cc_no' => 'xxxxxxxxxxxx1111',
300
+ 'brand' => 'VISA'
301
+ )
302
+ )
303
+ );
304
+
305
+ $modelMock = $this->getModelMock(
306
+ 'ops/config', array('getInlinePaymentCcTypes')
307
+ );
308
+ $modelMock->expects($this->any())
309
+ ->method('getInlinePaymentCcTypes')
310
+ ->will(
311
+ $this->returnValue(
312
+ array(
313
+ 'FOO'
314
+ )
315
+ )
316
+ );
317
+
318
+ $this->replaceByMock('model', 'ops/config', $modelMock);
319
+
320
+ $this->assertEquals('', $blockMock->getStoredAliasBrand());
321
+ }
322
+
323
+ public function testGetStoredAlias()
324
+ {
325
+ $blockMock = $this->getBlockMock(
326
+ 'ops/form', array('getStoredAliasForCustomer')
327
+ );
328
+ $blockMock->expects($this->once())
329
+ ->method('getStoredAliasForCustomer')
330
+ ->will(
331
+ $this->returnValue(
332
+ array(
333
+ 'alias' => '4711',
334
+ 'brand' => 'VISA'
335
+ )
336
+ )
337
+ );
338
+
339
+
340
+ $this->assertEquals('4711', $blockMock->getStoredAlias());
341
+ }
342
+
343
+ public function testIsUserRegistering()
344
+ {
345
+ $dataHelperMock = $this->getHelperMock('ops/data', array('checkIfUserIsRegistering'));
346
+ $dataHelperMock->expects($this->any())
347
+ ->method('checkIfUserIsRegistering')
348
+ ->will($this->returnValue(false));
349
+ $this->replaceByMock('helper', 'ops/data', $dataHelperMock);
350
+
351
+ $block = new Netresearch_OPS_Block_Form();
352
+ $this->assertFalse($block->isUserRegistering());
353
+ }
354
+
355
+
356
+ public function testIsUserNotRegistering()
357
+ {
358
+ $dataHelperMock = $this->getHelperMock('ops/data', array('checkIfUserIsNotRegistering'));
359
+ $dataHelperMock->expects($this->any())
360
+ ->method('checkIfUserIsNotRegistering')
361
+ ->will($this->returnValue(false));
362
+ $this->replaceByMock('helper', 'ops/data', $dataHelperMock);
363
+
364
+ $block = new Netresearch_OPS_Block_Form();
365
+ $this->assertFalse($block->isUserNotRegistering());
366
+ }
367
+
368
+ public function testIsAliasInfoBlockEnabled()
369
+ {
370
+ $configMock = $this->getModelMock('ops/config', array('isAliasPMEnabled', 'isAliasInfoBlockEnabled'));
371
+ $configMock->expects($this->any())
372
+ ->method('isAliasPMEnabled')
373
+ ->will($this->returnValue(false));
374
+ $configMock->expects($this->any())
375
+ ->method('isAliasInfoBlockEnabled')
376
+ ->will($this->returnValue(false));
377
+ $this->replaceByMock('model', 'ops/config', $configMock);
378
+
379
+ $this->assertFalse(Mage::app()->getLayout()->getBlockSingleton('ops/form')->isAliasInfoBlockEnabled());
380
+
381
+ $configMock = $this->getModelMock('ops/config', array('isAliasPMEnabled', 'isAliasInfoBlockEnabled'));
382
+ $configMock->expects($this->any())
383
+ ->method('isAliasPMEnabled')
384
+ ->will($this->returnValue(false));
385
+ $configMock->expects($this->any())
386
+ ->method('isAliasInfoBlockEnabled')
387
+ ->will($this->returnValue(true));
388
+ $this->replaceByMock('model', 'ops/config', $configMock);
389
+
390
+ $this->assertFalse(Mage::app()->getLayout()->getBlockSingleton('ops/form')->isAliasInfoBlockEnabled());
391
+
392
+ $configMock = $this->getModelMock('ops/config', array('isAliasPMEnabled', 'isAliasInfoBlockEnabled'));
393
+ $configMock->expects($this->any())
394
+ ->method('isAliasPMEnabled')
395
+ ->will($this->returnValue(true));
396
+ $configMock->expects($this->any())
397
+ ->method('isAliasInfoBlockEnabled')
398
+ ->will($this->returnValue(false));
399
+ $this->replaceByMock('model', 'ops/config', $configMock);
400
+
401
+ $this->assertFalse(Mage::app()->getLayout()->getBlockSingleton('ops/form')->isAliasInfoBlockEnabled());
402
+
403
+ $configMock = $this->getModelMock('ops/config', array('isAliasPMEnabled', 'isAliasInfoBlockEnabled'));
404
+ $configMock->expects($this->any())
405
+ ->method('isAliasPMEnabled')
406
+ ->will($this->returnValue(true));
407
+ $configMock->expects($this->any())
408
+ ->method('isAliasInfoBlockEnabled')
409
+ ->will($this->returnValue(true));
410
+ $this->replaceByMock('model', 'ops/config', $configMock);
411
+
412
+ $this->assertFalse(Mage::app()->getLayout()->getBlockSingleton('ops/form')->isAliasInfoBlockEnabled());
413
+ }
414
+
415
+ public function testGetPmLogo()
416
+ {
417
+ $this->assertEquals(null, $this->_block->getPmLogo());
418
+ }
419
+
420
+ public function testGetFrontendValidatorsAreEmtpyWhenNoExtraParamtersAreSubmitted()
421
+ {
422
+ $quoteMock = Mage::getModel('sales/quote');
423
+ $quoteMock->setStoreId(0);
424
+ $sessionMock = $this->getModelMockBuilder('checkout/session')
425
+ ->disableOriginalConstructor() // This one removes session_start and other methods usage
426
+ ->setMethods(array('getQuote'))
427
+ ->getMock();
428
+ $sessionMock->expects($this->any())
429
+ ->method('getQuote')
430
+ ->will($this->returnValue($quoteMock));
431
+ $this->replaceByMock('singleton', 'checkout/session', $sessionMock);
432
+
433
+ $configMock = $this->getModelMock('ops/config', array('canSubmitExtraParameter'));
434
+ $configMock->expects($this->once())
435
+ ->method('canSubmitExtraParameter')
436
+ ->will($this->returnValue(false));
437
+ $this->_block->setConfig($configMock);
438
+ $this->_block->setQuote($quoteMock);
439
+ $this->assertEquals(Mage::helper('core/data')->jsonEncode(array()), $this->_block->getFrontendValidators());
440
+ }
441
+
442
+ public function testGetFrontendValidatorsAreEmptyDueToEmptyValidators()
443
+ {
444
+ $configMock = $this->getModelMock('ops/config', array('canSubmitExtraParameter', 'getParameterLengths'));
445
+ $configMock->expects($this->once())
446
+ ->method('canSubmitExtraParameter')
447
+ ->will($this->returnValue(true));
448
+ $configMock->expects($this->once())
449
+ ->method('getParameterLengths')
450
+ ->will($this->returnValue(array()));
451
+
452
+ $quote = Mage::getModel('sales/quote');
453
+ $blockMock = $this->getBlockMock('ops/form', array('getQuote'));
454
+ $blockMock->expects($this->any())
455
+ ->method('getQuote')
456
+ ->will($this->returnValue($quote));
457
+ $blockMock->setConfig($configMock);
458
+ $this->assertEquals(Mage::helper('core/data')->jsonEncode(array()), $blockMock->getFrontendValidators());
459
+ }
460
+
461
+ public function testGetFrontendValidatorsAreEmptyDueToUnmappedValidators()
462
+ {
463
+ $configMock = $this->getModelMock('ops/config', array('canSubmitExtraParameter', 'getParameterLengths'));
464
+ $configMock->expects($this->once())
465
+ ->method('canSubmitExtraParameter')
466
+ ->will($this->returnValue(true));
467
+ $configMock->expects($this->once())
468
+ ->method('getParameterLengths')
469
+ ->will($this->returnValue(array('Foo' => 50)));
470
+
471
+ $quote = Mage::getModel('sales/quote');
472
+ $blockMock = $this->getBlockMock('ops/form', array('getQuote'));
473
+ $blockMock->expects($this->any())
474
+ ->method('getQuote')
475
+ ->will($this->returnValue($quote));
476
+ $blockMock->setConfig($configMock);
477
+ $this->assertEquals(Mage::helper('core/data')->jsonEncode(array()), $blockMock->getFrontendValidators());
478
+ }
479
+
480
+
481
+ public function testGetFrontendValidatorsAreNotEmpty()
482
+ {
483
+
484
+ $configValues = array('CN' => 50, 'ECOM_BILLTO_POSTAL_POSTALCODE' => 10, 'ECOM_SHIPTO_POSTAL_POSTALCODE' => 10);
485
+
486
+ $configMock = $this->getModelMock('ops/config', array('canSubmitExtraParameter', 'getParameterLengths'));
487
+ $configMock->expects($this->once())
488
+ ->method('canSubmitExtraParameter')
489
+ ->will($this->returnValue(true));
490
+ $configMock->expects($this->once())
491
+ ->method('getParameterLengths')
492
+ ->will($this->returnValue($configValues));
493
+
494
+ $quote = Mage::getModel('sales/quote');
495
+ $blockMock = $this->getBlockMock('ops/form', array('getQuote'));
496
+ $blockMock->expects($this->any())
497
+ ->method('getQuote')
498
+ ->will($this->returnValue($quote));
499
+ $blockMock->setConfig($configMock);
500
+ $this->assertEquals(Mage::helper('core/data')->jsonEncode(array(
501
+ 'billing:firstname' => 50, 'billing:lastname' => 50, 'billing:postcode' => 10, 'shipping:postcode' => 10
502
+ )), $blockMock->getFrontendValidators());
503
+ }
504
+ }
app/code/community/Netresearch/OPS/Test/Block/FormTest/fixtures/.gitkeep ADDED
File without changes
app/code/community/Netresearch/OPS/Test/Block/FrauddetectionTest.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Netresearch_OPS_Test_Block_FrauddetectionTest
4
+ extends EcomDev_PHPUnit_Test_Case_Controller
5
+ {
6
+
7
+ public function testToHtml()
8
+ {
9
+ $block = Mage::app()->getLayout()->getBlockSingleton('ops/frauddetection');
10
+ $this->assertEquals(null, $block->toHtml());
11
+
12
+ $modelMock = $this->getModelMock('ops/config', array('isTrackingCodeActivated'));
13
+ $modelMock->expects($this->once())
14
+ ->method('isTrackingCodeActivated')
15
+ ->will($this->returnValue(true));
16
+ $this->replaceByMock('model', 'ops/config', $modelMock);
17
+ // for some reason the html is not rendered in the tests
18
+ $this->assertNotNull($block->toHtml());
19
+ }
20
+
21
+
22
+ public function testGetTrackingCodeAid()
23
+ {
24
+ $block = Mage::app()->getLayout()->getBlockSingleton('ops/frauddetection');
25
+ $this->assertEquals('10376', $block->getTrackingCodeAid());
26
+ }
27
+
28
+
29
+ public function testGetTrackingSid()
30
+ {
31
+ $block = Mage::app()->getLayout()->getBlockSingleton('ops/frauddetection');
32
+ $modelMock = $this->getModelMock('customer/session', array('getSessionId'));
33
+ $modelMock->expects($this->once())
34
+ ->method('getSessionId')
35
+ ->will($this->returnValue('123456'));
36
+ $this->replaceByMock('model', 'customer/session', $modelMock);
37
+ $this->assertEquals(md5('123456'), $block->getTrackingSid());
38
+ }
39
+
40
+ }
app/code/community/Netresearch/OPS/Test/Block/PlaceFormShaTest.php ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Netresearch_OPS_Test_Block_PlaceformShaTest extends EcomDev_PHPUnit_Test_Case
3
+ {
4
+ private $_helper;
5
+ private $_shaKey;
6
+
7
+ public function setUp()
8
+ {
9
+ parent::setup();
10
+
11
+ $this->_helper = new Netresearch_OPS_Helper_Payment();
12
+ $this->_shaKey = 'qu4rkkuchen12345';
13
+ }
14
+
15
+ public function testShaGenerationWithTestData()
16
+ {
17
+ $params = array(
18
+ 'AMOUNT' => '2129',
19
+ 'CIVILITY' => 'Herr',
20
+ 'CURRENCY' => 'EUR',
21
+ 'ECOM_BILLTO_POSTAL_NAME_FIRST' => 'John',
22
+ 'ECOM_BILLTO_POSTAL_NAME_LAST' => 'Doe',
23
+ 'ECOM_SHIPTO_DOB' => '09/10/1940',
24
+ 'EMAIL' => 'john@doe.com',
25
+ 'ITEMID1' => 'article1',
26
+ 'ITEMNAME1' => 'coffee',
27
+ 'ITEMPRICE1' => '3.00',
28
+ 'ITEMQUANT1' => '4',
29
+ 'ITEMVAT1' => '0.57',
30
+ 'LANGUAGE' => 'de_DE',
31
+ 'ORDERID' => 'order123',
32
+ 'ORDERSHIPCOST' => '100',
33
+ 'ORDERSHIPTAX' => '6',
34
+ 'OWNERADDRESS' => 'test street',
35
+ 'OWNERCTY' => 'DE',
36
+ 'OWNERTELNO' => '+49 111 222 33 444',
37
+ 'OWNERTOWN' => 'Berlin',
38
+ 'OWNERZIP' => '10000',
39
+ 'PM' => 'Open Invoice DE',
40
+ 'PSPID' => 'NRMAGbillpay1',
41
+ );
42
+ $expected = '695103f8891dfc80ea46369203925b898a381334';
43
+ $shaSign = $this->_helper->getSHASign($params, $this->_shaKey, 0);
44
+ $result = $this->_helper->shaCrypt($shaSign);
45
+ $this->assertEquals($expected, $result);
46
+ }
47
+
48
+ public function testShaGenerationWithSpecialChars()
49
+ {
50
+ $params = array(
51
+ 'PSPID' => 'NRMAGbillpay1',
52
+ 'AMOUNT' => '560',
53
+ 'ORDERID' => 'TBI72',
54
+ 'CURRENCY' => 'EUR',
55
+ 'OWNERCTY' => 'DE',
56
+ 'ITEMVAT1' => '0.10',
57
+ 'LANGUAGE' => 'de_DE',
58
+ 'PM' => 'Open Invoice DE',
59
+ 'CIVILITY' => 'Herr',
60
+ 'EMAIL' => 'thomas.kappel@netresearch.de',
61
+ 'ORDERSHIPCOST' => '500',
62
+ 'ORDERSHIPTAX' => '0',
63
+ 'ECOM_BILLTO_POSTAL_NAME_FIRST' => 'Karla',
64
+ 'ECOM_BILLTO_POSTAL_NAME_LAST' => 'Kolumna',
65
+ 'OWNERTELNO' => '64065460',
66
+ 'ITEMPRICE1' => '0.60',
67
+ 'ECOM_SHIPTO_DOB' => '09/10/1940',
68
+ 'OWNERADDRESS' => 'Tierparkallee 2',
69
+ 'OWNERTOWN' => 'Leipzig',
70
+ 'ITEMID1' => '26',
71
+ 'ITEMNAME1' => 'Club Mate',
72
+ 'ITEMQUANT1' => '1',
73
+ 'OWNERZIP' => '04229',
74
+ );
75
+ $expected = 'baf6099446e3bf93ecf26e622032e7db2139839c';
76
+ $shaSign = $this->_helper->getSHASign($params, $this->_shaKey, 0);
77
+ $result = $this->_helper->shaCrypt($shaSign);
78
+ $this->assertEquals($expected, $result);
79
+ }
80
+ }
81
+
app/code/community/Netresearch/OPS/Test/Block/PlaceformTest.php ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Netresearch_OPS_Test_Block_PlaceformTest extends EcomDev_PHPUnit_Test_Case
3
+ {
4
+ public function testGetFormAction()
5
+ {
6
+ $this->mockSessions();
7
+ //$block = Mage::app()->getLayout()->getBlockSingleton('ops/placeform');
8
+ $blockMock = $this->getBlockMock('ops/placeform', array('getQuestion'));
9
+ $blockMock->expects($this->any())
10
+ ->method('getQuestion')
11
+ ->will($this->returnValue('How much is the fish?'));
12
+
13
+ $action = $blockMock->getFormAction();
14
+ $this->assertEquals(Mage::getUrl('*/*/*', array('_secure' => Mage::app()->getFrontController()->getRequest()->isSecure())), $action);
15
+
16
+ // check explicitly for https
17
+ $_SERVER['HTTPS'] = 'on';
18
+ $action = $blockMock->getFormAction();
19
+ $this->assertEquals(Mage::getUrl('*/*/*', array('_secure' =>true)), $action);
20
+
21
+ $blockMock = $this->getBlockMock('ops/placeform', array('getQuestion'));
22
+ $blockMock->expects($this->any())
23
+ ->method('getQuestion')
24
+ ->will($this->returnValue(null));
25
+
26
+ $action = $blockMock->getFormAction();
27
+ $this->assertEquals($blockMock->getConfig()->getFrontendGatewayPath(), $action);
28
+ }
29
+
30
+ public function testIsKwixoPaymentMethodTrue()
31
+ {
32
+ $order = Mage::getModel('sales/order');
33
+ $payment = Mage::getModel('sales/order_payment');
34
+ $payment->setMethod('ops_kwixoApresReception');
35
+ $order->setPayment($payment);
36
+
37
+ $blockMock = $this->getBlockMock('ops/placeform', array('_getOrder'));
38
+ $blockMock->expects($this->any())
39
+ ->method('_getOrder')
40
+ ->will($this->returnValue($order));
41
+
42
+ $this->assertTrue($blockMock->isKwixoPaymentMethod());
43
+
44
+ }
45
+
46
+ public function testIsKwixoPaymentMethodFalse()
47
+ {
48
+ $order = Mage::getModel('sales/order');
49
+ $payment = Mage::getModel('sales/order_payment');
50
+ $payment->setMethod('ops_cc');
51
+ $order->setPayment($payment);
52
+
53
+ $blockMock = $this->getBlockMock('ops/placeform', array('_getOrder'));
54
+ $blockMock->expects($this->any())
55
+ ->method('_getOrder')
56
+ ->will($this->returnValue($order));
57
+
58
+ $this->assertFalse($blockMock->isKwixoPaymentMethod());
59
+
60
+ }
61
+ protected function mockSessions()
62
+ {
63
+ $sessionMock = $this->getModelMockBuilder('checkout/session')
64
+ ->disableOriginalConstructor() // This one removes session_start and other methods usage
65
+ ->getMock();
66
+ $this->replaceByMock('singleton', 'core/session', $sessionMock);
67
+
68
+ $sessionMock = $this->getModelMockBuilder('customer/session')
69
+ ->disableOriginalConstructor() // This one removes session_start and other methods usage
70
+ ->getMock();
71
+ $this->replaceByMock('singleton', 'customer/session', $sessionMock);
72
+ }
73
+
74
+ }
app/code/community/Netresearch/OPS/Test/Block/System/Config/KwixoconfigurationTest.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Michael Lühr <michael.luehr@netresearch.de>
4
+ * @category Netresearch
5
+ * @package ${MODULENAME}
6
+ * @copyright Copyright (c) 2013 Netresearch GmbH & Co. KG (http://www.netresearch.de)
7
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
8
+ */
9
+
10
+
11
+ class Netresearch_OPS_Test_Block_System_Config_KwixoconfigurationTest
12
+ extends EcomDev_PHPUnit_Test_Case
13
+ {
14
+
15
+ public function testRender()
16
+ {
17
+ $element = new Varien_Data_Form_Element_Text();
18
+ $element->setLegend('I am legend');
19
+ $block = new Netresearch_OPS_Block_System_Config_Kwixoconfiguration();
20
+ $block->render($element);
21
+ $this->assertEquals('I am legend', $block->getData('fieldset_label'));
22
+ }
23
+
24
+ }
app/code/community/Netresearch/OPS/Test/Block/System/Config/ModeTest.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * ModeTest.php
4
+ * @author paul.siedler@netresearch.de
5
+ * @copyright Copyright (c) 2015 Netresearch GmbH & Co. KG
6
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License
7
+ */
8
+
9
+ class Netresearch_OPS_Test_Block_System_Config_ModeTest extends EcomDev_PHPUnit_Test_Case {
10
+
11
+ public function testGetElementHtmlContainsScriptTag()
12
+ {
13
+ $element = new Varien_Data_Form_Element_Select();
14
+ $element->setForm(new Varien_Object());
15
+ $block = new Netresearch_OPS_Block_System_Config_Mode();
16
+ $html = $block->render($element);
17
+ $this->assertTrue(preg_match('/<script/', $html) > 0);
18
+ }
19
+
20
+ }
app/code/community/Netresearch/OPS/Test/Controller/Adminhtml/AdminControllerTest.php ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * AdminControllerTest.php
5
+ * @author paul.siedler@netresearch.de
6
+ * @copyright Copyright (c) 2015 Netresearch GmbH & Co. KG
7
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License
8
+ */
9
+
10
+ class Netresearch_OPS_Test_Controller_Adminhtml_AdminControllerTest extends EcomDev_PHPUnit_Test_Case_Controller
11
+ {
12
+
13
+ public function setUp(){
14
+ parent::setUp();
15
+
16
+ $nodePath = "modules/Enterprise_AdminGws/active";
17
+ if (Mage::helper('core/data')->isModuleEnabled('Enterprise_AdminGws')) {
18
+ Mage::getConfig()->setNode($nodePath, 'false', true);
19
+ }
20
+
21
+ $this->fakeAdminUser();
22
+ }
23
+
24
+ public function testResendInfoActionWillSucceed()
25
+ {
26
+ $mailFeatureMock = $this->getModelMock('ops/payment_features_paymentEmail', array('resendPaymentInfo', 'isAvailableForOrder'));
27
+ $mailFeatureMock->expects($this->any())
28
+ ->method('isAvailableForOrder')
29
+ ->will($this->returnValue(true));
30
+ $mailFeatureMock->expects($this->once())
31
+ ->method('resendPaymentInfo')
32
+ ->will($this->returnValue(true));
33
+ $this->replaceByMock('model', 'ops/payment_features_paymentEmail', $mailFeatureMock);
34
+
35
+ $orderMock = $this->getModelMock('sales/order', array('load'));
36
+ $orderMock->expects($this->once())
37
+ ->method('load')
38
+ ->will($this->returnValue($orderMock));
39
+ $this->replaceByMock('model', 'sales/order', $orderMock);
40
+
41
+ $this->dispatch('adminhtml/admin/resendInfo', array('order_id' => 1));
42
+ }
43
+
44
+ public function testResendInfoActionWillFail()
45
+ {
46
+ $mailFeatureMock = $this->getModelMock('ops/payment_features_paymentEmail', array('resendPaymentInfo', 'isAvailableForOrder'));
47
+ $mailFeatureMock->expects($this->any())
48
+ ->method('isAvailableForOrder')
49
+ ->will($this->returnValue(true));
50
+ $mailFeatureMock->expects($this->once())
51
+ ->method('resendPaymentInfo')
52
+ ->will($this->returnValue(false));
53
+ $this->replaceByMock('model', 'ops/payment_features_paymentEmail', $mailFeatureMock);
54
+
55
+ $orderMock = $this->getModelMock('sales/order', array('load'));
56
+ $orderMock->expects($this->once())
57
+ ->method('load')
58
+ ->will($this->returnValue($orderMock));
59
+ $this->replaceByMock('model', 'sales/order', $orderMock);
60
+
61
+ $this->dispatch('adminhtml/admin/resendInfo', array('order_id' => 1));
62
+ }
63
+
64
+ protected function fakeAdminUser(){
65
+ $fakeUser = $this->getModelMock('admin/user', array('getId', 'getRole'));
66
+ $fakeUser->expects($this->any())
67
+ ->method('getId')
68
+ ->will($this->returnValue(1));
69
+
70
+ $adminSessionMock = $this->getModelMock('admin/session', array('isAllowed', 'init', 'save', 'getUser'));
71
+ $adminSessionMock->expects($this->any())
72
+ ->method('isAllowed')
73
+ ->will($this->returnValue(true));
74
+ $adminSessionMock->expects($this->any())
75
+ ->method('getUser')
76
+ ->will($this->returnValue($fakeUser));
77
+ $this->replaceByMock('model', 'admin/session', $adminSessionMock);
78
+ }
79
+
80
+ }
app/code/community/Netresearch/OPS/Test/Controller/Adminhtml/KwixocategoryControllerTest.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Netresearch_OPS_Test_Controller_Adminhtml_KwixocategoryControllerTest
3
+ extends EcomDev_PHPUnit_Test_Case_Controller
4
+ {
5
+
6
+ /**
7
+ * @loadFixture category_mapping
8
+ */
9
+ public function testDeleteAction()
10
+ {
11
+ $this->dispatch('adminhtml/kwixocategory/delete', array());
12
+ $model = Mage::getModel('ops/kwixo_category_mapping')->load(1);
13
+ $this->assertEquals(1, $model->getId());
14
+ $this->dispatch('adminhtml/kwixocategory/delete', array('id' => 666));
15
+ $model = Mage::getModel('ops/kwixo_category_mapping')->load(1);
16
+ $this->assertEquals(1, $model->getId());
17
+ $this->dispatch('adminhtml/kwixocategory/delete', array('id' => 10));
18
+ $model = Mage::getModel('ops/kwixo_category_mapping')->load(1);
19
+ $this->assertNull($model->getId());
20
+ Mage::getSingleton('adminhtml/session')->getMessages(true);
21
+ }
22
+
23
+ }
app/code/community/Netresearch/OPS/Test/Controller/Adminhtml/KwixocategoryControllerTest/fixtures/category_mapping.yaml ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ tables:
2
+ ops/kwixo_category_mapping:
3
+ - id: 1
4
+ kwixo_category_id: 10
5
+ category_id: 10
6
+ - id: 2
7
+ kwixo_category_id: 1
8
+ category_id: 11
9
+ - id: 3
10
+ kwixo_category_id: 2
11
+ category_id: 12
app/code/community/Netresearch/OPS/Test/Controller/Adminhtml/KwixoshippingControllerTest.php ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Michael Lühr <michael.luehr@netresearch.de>
4
+ * @category Netresearch
5
+ * @package Netresearch_OPS
6
+ * @copyright Copyright (c) 2013 Netresearch GmbH & Co. KG
7
+ * (http://www.netresearch.de)
8
+ * @license http://opensource.org/licenses/osl-3.0.php
9
+ * Open Software License (OSL 3.0)
10
+ */
11
+
12
+
13
+ class Netresearch_OPS_Test_Controller_Adminhtml_KwixoshippingControllerTest
14
+ extends EcomDev_PHPUnit_Test_Case_Controller
15
+ {
16
+
17
+ public function setUp()
18
+ {
19
+ parent::setUp();
20
+ $fakeUser = $this->getModelMock('admin/user', array('getId', 'getRole'));
21
+ $fakeUser->expects($this->any())
22
+ ->method('getId')
23
+ ->will($this->returnValue(1));
24
+
25
+ $sessionMock = $this->getModelMock(
26
+ 'admin/session', array('getUser', 'init', 'save')
27
+ );
28
+ $sessionMock->expects($this->any())
29
+ ->method('getUser')
30
+ ->will($this->returnValue($fakeUser));
31
+ $this->replaceByMock('model', 'admin/session', $sessionMock);
32
+
33
+
34
+ $nodePath = "modules/Enterprise_AdminGws/active";
35
+ if (Mage::helper('core/data')->isModuleEnabled('Enterprise_AdminGws')) {
36
+ Mage::getConfig()->setNode($nodePath, 'false', true);
37
+ }
38
+
39
+ }
40
+
41
+
42
+ public function testIndexAction()
43
+ {
44
+ $this->dispatch('adminhtml/kwixoshipping/index', array());
45
+ $this->assertRequestRoute('adminhtml/kwixoshipping/index');
46
+ $this->assertLayoutBlockCreated('kwixoshipping');
47
+ }
48
+
49
+ public function testSaveAction()
50
+ {
51
+ $this->dispatch('adminhtml/kwixoshipping/save', array());
52
+ $this->assertRequestRoute('adminhtml/kwixoshipping/save');
53
+ $this->assertRedirectTo('adminhtml/kwixoshipping/index');
54
+ }
55
+
56
+ public function testSaveActionWithPost()
57
+ {
58
+ $postData = array(
59
+ 'form_key' => '1234'
60
+ );
61
+ $this->getRequest()->setPost($postData);
62
+ $this->getRequest()->setMethod('POST');
63
+ $this->dispatch('adminhtml/kwixoshipping/save', array());
64
+ $this->assertRequestRoute('adminhtml/kwixoshipping/save');
65
+ $this->assertRedirectTo('adminhtml/kwixoshipping/index');
66
+ }
67
+
68
+ /**
69
+ * @loadFixture shipping_settings.yaml
70
+ */
71
+ public function testSaveActionWithRealPostData()
72
+ {
73
+ $postData = array(
74
+ 'form_key' => '1234',
75
+ 'flatrate' => array(
76
+ 'kwixo_shipping_type' => 1,
77
+ 'kwixo_shipping_speed' => 1,
78
+ 'kwixo_shipping_details' => 'foo'
79
+ )
80
+ );
81
+ $this->getRequest()->setPost($postData);
82
+ $this->getRequest()->setMethod('POST');
83
+ $this->dispatch('adminhtml/kwixoshipping/save', array());
84
+ $this->assertRequestRoute('adminhtml/kwixoshipping/save');
85
+ $this->assertRedirectTo('adminhtml/kwixoshipping/index');
86
+ $kwixoModel = Mage::getModel('ops/kwixo_shipping_setting')->load(1);
87
+
88
+ // assure that saving the data worked properly
89
+
90
+ $this->assertEquals('flatrate', $kwixoModel->getShippingCode());
91
+ $this->assertEquals(1, $kwixoModel->getKwixoShippingType());
92
+ $this->assertEquals(1, $kwixoModel->getKwixoShippingSpeed());
93
+ $this->assertEquals('foo', $kwixoModel->getKwixoShippingDetails());
94
+ }
95
+
96
+
97
+ /**
98
+ * @loadFixture shipping_settings.yaml
99
+ */
100
+ public function testSaveActionWithErrorneousPostData()
101
+ {
102
+ $postData = array(
103
+ 'form_key' => '1234',
104
+ 'flatrate' => array(
105
+ 'kwixo_shipping_type' => -1,
106
+ 'kwixo_shipping_speed' => 'abc',
107
+ 'kwixo_shipping_details' => 'foo'
108
+ )
109
+ );
110
+ $this->getRequest()->setPost($postData);
111
+ $this->getRequest()->setMethod('POST');
112
+ $this->dispatch('adminhtml/kwixoshipping/save', array());
113
+ $this->assertRequestRoute('adminhtml/kwixoshipping/save');
114
+ $this->assertRedirectTo('adminhtml/kwixoshipping/index');
115
+ $kwixoModel = Mage::getModel('ops/kwixo_shipping_setting')->load(1);
116
+
117
+ // assure that saving the data worked properly
118
+
119
+ $this->assertEquals('flatrate', $kwixoModel->getShippingCode());
120
+ $this->assertNotEquals(-1, $kwixoModel->getKwixoShippingType());
121
+ $this->assertNotEquals('abc', $kwixoModel->getKwixoShippingSpeed());
122
+ $this->assertNotEquals('foo', $kwixoModel->getKwixoShippingDetails());
123
+ }
124
+
125
+ public function testDeleteNotFoundAction()
126
+ {
127
+ $this->dispatch('adminhtml/kwixoshipping/delete', array());
128
+ $headers = $this->getResponse()->getHeaders();
129
+ $notFound = false;
130
+ foreach ($headers as $header) {
131
+ if ($header['name'] == 'Status'
132
+ && $header['value'] == '404 File not found'
133
+ ) {
134
+ $notFound = true;
135
+ break;
136
+ }
137
+ }
138
+ $this->assertTrue($notFound);
139
+
140
+ }
141
+
142
+ }
app/code/community/Netresearch/OPS/Test/Controller/Adminhtml/KwixoshippingControllerTest/fixtures/shipping_settings.yaml ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ tables:
2
+ ops/kwixo_shipping_setting:
3
+ - id: 1
4
+ shipping_code: flatrate
5
+ kwixo_shipping_type: ''
6
+ kwixo_shipping_speed: ''
7
+ kwixo_shipping_details: ''
app/code/community/Netresearch/OPS/Test/Controller/Adminhtml/OpsstatusControllerTest.php ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Michael Lühr <michael.luehr@netresearch.de>
4
+ * @category Netresearch
5
+ * @copyright Copyright (c) 2014 Netresearch GmbH & Co. KG (http://www.netresearch.de)
6
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
7
+ */
8
+
9
+
10
+ class Netresearch_OPS_Test_Controller_Adminhtml_OpsstatusControllerTest
11
+ extends EcomDev_PHPUnit_Test_Case_Controller
12
+ {
13
+
14
+ public function setUp()
15
+ {
16
+ parent::setUp();
17
+
18
+ $nodePath = "modules/Enterprise_AdminGws/active";
19
+ if (Mage::helper('core/data')->isModuleEnabled('Enterprise_AdminGws')) {
20
+ Mage::getConfig()->setNode($nodePath, 'false', true);
21
+ }
22
+
23
+ }
24
+
25
+ public function testUpdateActionWillRedirect()
26
+ {
27
+ $fakeUser = $this->getModelMock('admin/user', array('getId', 'getRole'));
28
+ $fakeUser->expects($this->any())
29
+ ->method('getId')
30
+ ->will($this->returnValue(1));
31
+
32
+ $adminSessionMock = $this->getModelMock('admin/session', array('isAllowed', 'init', 'save', 'getUser'));
33
+ $adminSessionMock->expects($this->any())
34
+ ->method('isAllowed')
35
+ ->will($this->returnValue(true));
36
+ $adminSessionMock->expects($this->any())
37
+ ->method('getUser')
38
+ ->will($this->returnValue($fakeUser));
39
+ $this->replaceByMock('model', 'admin/session', $adminSessionMock);
40
+
41
+ $statusUpdateMock = $this->getModelMock('ops/status_update', array('updateStatusFor'));
42
+ $this->replaceByMock('model', 'ops/status_update', $statusUpdateMock);
43
+
44
+ $this->dispatch('adminhtml/opsstatus/update', array('order_id' => 1));
45
+ $this->assertRedirectTo('adminhtml/sales_order/view', array('order_id' => 1));
46
+ }
47
+
48
+ public function testUpdateActionWillNotRedirect()
49
+ {
50
+ $fakeUser = $this->getModelMock('admin/user', array('getId', 'getRole'));
51
+ $fakeUser->expects($this->any())
52
+ ->method('getId')
53
+ ->will($this->returnValue(1));
54
+
55
+ $adminSessionMock = $this->getModelMock('admin/session', array('isAllowed', 'init', 'save', 'getUser'));
56
+ $adminSessionMock->expects($this->any())
57
+ ->method('isAllowed')
58
+ ->will($this->returnValue(false));
59
+ $adminSessionMock->expects($this->any())
60
+ ->method('getUser')
61
+ ->will($this->returnValue($fakeUser));
62
+ $this->replaceByMock('model', 'admin/session', $adminSessionMock);
63
+
64
+ $statusUpdateMock = $this->getModelMock('ops/status_update', array('updateStatusFor'));
65
+ $this->replaceByMock('model', 'ops/status_update', $statusUpdateMock);
66
+
67
+ $this->dispatch('adminhtml/opsstatus/update', array('order_id' => 1));
68
+ $this->assertEquals('403 Forbidden', $this->getResponse()->getSentHeader('Http/1.1'));
69
+ }
70
+
71
+ }
app/code/community/Netresearch/OPS/Test/Controller/ApiControllerTest.php ADDED
@@ -0,0 +1,165 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Netresearch_OPS_Test_Controller_ApiControllerTest
3
+ extends EcomDev_PHPUnit_Test_Case_Controller
4
+ {
5
+
6
+ private $oldSeoValue = null;
7
+
8
+ private function setUpHelperMock($returnStatus, $setStoreId = true)
9
+ {
10
+ $paymentHelperMock = $this->getHelperMock(
11
+ 'ops/payment', array('applyStateForOrder', 'shaCryptValidation')
12
+ );
13
+ $paymentHelperMock->expects($this->any())
14
+ ->method('applyStateForOrder')
15
+ ->will($this->returnValue($returnStatus));
16
+
17
+ $paymentHelperMock->expects($this->any())
18
+ ->method('shaCryptValidation')
19
+ ->will($this->returnValue(true));
20
+ $this->replaceByMock('helper', 'ops/payment', $paymentHelperMock);
21
+
22
+ $fakePayment = new Varien_Object();
23
+ $fakePayment->setMethodInstance(Mage::getModel('ops/payment_cc'));
24
+
25
+ $fakeOrder = new Varien_Object();
26
+ $fakeOrder->setPayment($fakePayment);
27
+ $fakeOrder->setId(1);
28
+ if ($setStoreId) {
29
+ $fakeOrder->setStoreId(1);
30
+ }
31
+ $orderHelperMock = $this->getHelperMock('ops/order', array('getOrder'));
32
+ $orderHelperMock->expects($this->any())
33
+ ->method('getOrder')
34
+ ->will($this->returnValue($fakeOrder));
35
+ $this->replaceByMock('helper', 'ops/order', $orderHelperMock);
36
+ }
37
+
38
+ private function getRequestParams()
39
+ {
40
+ return array(
41
+ 'orderID' => 1,
42
+ 'SHASIGN' => '12344',
43
+ );
44
+ }
45
+
46
+ public function testRedirectToSuccessRoute()
47
+ {
48
+ $this->setUpHelperMock(
49
+ Netresearch_OPS_Model_Status_Feedback::OPS_ORDER_FEEDBACK_STATUS_ACCEPT
50
+ );
51
+ $modelMock = $this->getModelMock('core/store', array('getId'));
52
+ $modelMock->expects($this->any())
53
+ ->method('getId()')
54
+ ->will($this->returnValue(null));
55
+ $this->replaceByMock('model', 'core/store', $modelMock);
56
+ $this->dispatch('ops/api/postBack', $this->getRequestParams());
57
+ $this->assertRedirectTo(
58
+ Mage::getModel('ops/config')->getAcceptRedirectRoute(),
59
+ array('_query' => $this->getRequestParams(), '_store' => 1)
60
+ );
61
+
62
+ }
63
+
64
+ public function testRedirectToSuccessRouteWithOrderId()
65
+ {
66
+ $this->setUpHelperMock(
67
+ Netresearch_OPS_Model_Status_Feedback::OPS_ORDER_FEEDBACK_STATUS_ACCEPT
68
+ );
69
+ $modelMock = $this->getModelMock('core/store', array('getId'));
70
+ $modelMock->expects($this->any())
71
+ ->method('getId()')
72
+ ->will($this->returnValue(null));
73
+ $requestParams = $this->getRequestParams();
74
+ $requestParams['orderID'] = '#1000001';
75
+ $this->dispatch('ops/api/postBack', $requestParams);
76
+ $this->assertRedirectTo(
77
+ Mage::getModel('ops/config')->getAcceptRedirectRoute(),
78
+ array('_query' => $requestParams, '_store' => 1)
79
+ );
80
+
81
+ }
82
+
83
+ public function testRedirectToCancelRoute()
84
+ {
85
+ $this->setUpHelperMock(
86
+ Netresearch_OPS_Model_Status_Feedback::OPS_ORDER_FEEDBACK_STATUS_CANCEL
87
+ );
88
+ $modelMock = $this->getModelMock('core/store', array('getId'));
89
+ $modelMock->expects($this->any())
90
+ ->method('getId()')
91
+ ->will($this->returnValue(null));
92
+ $this->dispatch('ops/api/postBack', $this->getRequestParams());
93
+ $this->assertRedirectTo(
94
+ Mage::getModel('ops/config')->getCancelRedirectRoute(),
95
+ array('_query' => $this->getRequestParams(), '_store' => 1)
96
+ );
97
+ }
98
+
99
+ public function testRedirectToDeclineRoute()
100
+ {
101
+ $this->setUpHelperMock(
102
+ Netresearch_OPS_Model_Status_Feedback::OPS_ORDER_FEEDBACK_STATUS_DECLINE
103
+ );
104
+ $modelMock = $this->getModelMock('core/store', array('getId'));
105
+ $modelMock->expects($this->any())
106
+ ->method('getId()')
107
+ ->will($this->returnValue(null));
108
+ $this->dispatch('ops/api/postBack', $this->getRequestParams());
109
+ $this->assertRedirectTo(
110
+ Mage::getModel('ops/config')->getDeclineRedirectRoute(),
111
+ array('_query' => $this->getRequestParams(), '_store' => 1)
112
+ );
113
+ }
114
+
115
+ public function testRedirectToExceptionRoute()
116
+ {
117
+ $this->setUpHelperMock(
118
+ Netresearch_OPS_Model_Status_Feedback::OPS_ORDER_FEEDBACK_STATUS_EXCEPTION
119
+ );
120
+ $modelMock = $this->getModelMock('core/store', array('getId'));
121
+ $modelMock->expects($this->any())
122
+ ->method('getId()')
123
+ ->will($this->returnValue(null));
124
+ $this->dispatch('ops/api/postBack', $this->getRequestParams());
125
+ $this->assertRedirectTo(
126
+ Mage::getModel('ops/config')->getExceptionRedirectRoute(),
127
+ array('_query' => $this->getRequestParams(), '_store' => 1)
128
+ );
129
+ }
130
+
131
+ public function testExceptionReturnsStatus500()
132
+ {
133
+ $this->setUpHelperMock(
134
+ 'INVALID_STATUS'
135
+ );
136
+ $modelMock = $this->getModelMock('core/store', array('getId'));
137
+ $modelMock->expects($this->any())
138
+ ->method('getId()')
139
+ ->will($this->returnValue(null));
140
+ $this->dispatch('ops/api/postBack', $this->getRequestParams());
141
+ $this->assertResponseHttpCode(500);
142
+ $this->getResponse();
143
+ }
144
+
145
+
146
+ public function testRedirectIfStoreIdDoesNotMatch()
147
+ {
148
+ $this->setUpHelperMock(
149
+ Netresearch_OPS_Model_Status_Feedback::OPS_ORDER_FEEDBACK_STATUS_ACCEPT,
150
+ false
151
+ );
152
+ $modelMock = $this->getModelMock('core/store', array('getId'));
153
+ $modelMock->expects($this->any())
154
+ ->method('getId()')
155
+ ->will($this->returnValue(9999));
156
+ $this->replaceByMock('model', 'core/store', $modelMock);
157
+ $this->dispatch('ops/api/postBack', $this->getRequestParams());
158
+ $this->assertRedirectTo(
159
+ 'ops/api/postBack', array('_query' => $this->getRequestParams(), '_store' => 1)
160
+ );
161
+
162
+
163
+ }
164
+
165
+ }
app/code/community/Netresearch/OPS/Test/Controller/PaymentControllerTest.php ADDED
@@ -0,0 +1,512 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Netresearch_OPS_Test_Controller_PaymentControllerTest
4
+ extends EcomDev_PHPUnit_Test_Case_Controller
5
+ {
6
+
7
+ public function setUp()
8
+ {
9
+ parent::setUp();
10
+ $helperMock = $this->getHelperMock('ops/payment', array(
11
+ 'shaCryptValidation',
12
+ 'cancelOrder',
13
+ 'declineOrder',
14
+ 'handleException',
15
+ 'getSHAInSet',
16
+ 'refillCart'
17
+ ));
18
+ $helperMock->expects($this->any())
19
+ ->method('shaCryptValidation')
20
+ ->will($this->returnValue(true));
21
+
22
+ $this->replaceByMock('helper', 'ops/payment', $helperMock);
23
+ }
24
+
25
+ /**
26
+ * @loadFixture ../../../var/fixtures/orders.yaml
27
+ */
28
+ public function testAcceptAction()
29
+ {
30
+ $params = array();
31
+ $this->dispatch('ops/payment/accept', $params);
32
+ $this->assertRedirect('checkout/cart');
33
+
34
+
35
+ $params = array(
36
+ 'orderID' => '#100000011'
37
+ );
38
+ $this->dispatch('ops/payment/accept', $params);
39
+ $this->assertRedirect('checkout/onepage/success');
40
+
41
+ $params = array(
42
+ 'orderID' => '23'
43
+ );
44
+ $this->dispatch('ops/payment/accept', $params);
45
+ $this->assertRedirect('checkout/onepage/success');
46
+
47
+ }
48
+
49
+ /**
50
+ * @loadFixture ../../../var/fixtures/orders.yaml
51
+ */
52
+ public function testExceptionAction()
53
+ {
54
+ $params = array();
55
+ $this->dispatch('ops/payment/exception', $params);
56
+ $this->assertRedirect('checkout/cart');
57
+
58
+ $params = array(
59
+ 'orderID' => '#100000011'
60
+ );
61
+ $this->dispatch('ops/payment/exception', $params);
62
+ $this->assertRedirect('checkout/onepage/success');
63
+
64
+ $params = array(
65
+ 'orderID' => '23'
66
+ );
67
+ $this->dispatch('ops/payment/exception', $params);
68
+ $this->assertRedirect('checkout/onepage/success');
69
+
70
+ }
71
+
72
+ /**
73
+ * @loadFixture ../../../var/fixtures/orders.yaml
74
+ */
75
+ public function testDeclineAction()
76
+ {
77
+ $routeToDispatch = 'ops/payment/decline';
78
+ $params = array();
79
+ $this->dispatch($routeToDispatch, $params);
80
+ $this->assertRedirect('checkout/onepage');
81
+
82
+
83
+ $params = array(
84
+ 'orderID' => '#100000011'
85
+ );
86
+ $this->dispatch($routeToDispatch, $params);
87
+ $this->assertRedirect('checkout/onepage');
88
+
89
+ $params = array(
90
+ 'orderID' => '23'
91
+ );
92
+ $this->dispatch($routeToDispatch, $params);
93
+ $this->assertRedirect('checkout/onepage');
94
+
95
+ }
96
+
97
+ /**
98
+ * @loadFixture ../../../var/fixtures/orders.yaml
99
+ */
100
+ public function testCancelAction()
101
+ {
102
+ $routeToDispatch = 'ops/payment/cancel';
103
+ $params = array();
104
+ $this->dispatch($routeToDispatch, $params);
105
+ $this->assertRedirect('checkout/onepage');
106
+
107
+ $params = array(
108
+ 'orderID' => '#100000011'
109
+ );
110
+ $this->dispatch($routeToDispatch, $params);
111
+ $this->assertRedirect('checkout/onepage');
112
+
113
+ $params = array(
114
+ 'orderID' => '23'
115
+ );
116
+ $this->dispatch($routeToDispatch, $params);
117
+ $this->assertRedirect('checkout/onepage');
118
+
119
+ }
120
+
121
+ /**
122
+ * @loadFixture ../../../var/fixtures/orders.yaml
123
+ */
124
+ public function testContinueAction()
125
+ {
126
+ $routeToDispatch = 'ops/payment/continue';
127
+ $params = array();
128
+ $this->dispatch($routeToDispatch, $params);
129
+ $this->assertRedirect('checkout/cart');
130
+
131
+
132
+ $params = array(
133
+ 'orderID' => '#100000011'
134
+ );
135
+ $this->dispatch($routeToDispatch, $params);
136
+ $this->assertRedirect('checkout/cart');
137
+
138
+ $params = array(
139
+ 'orderID' => '23'
140
+ );
141
+ $this->dispatch($routeToDispatch, $params);
142
+ $this->assertRedirect('checkout/cart');
143
+
144
+ $params = array(
145
+ 'orderID' => '#100000011',
146
+ 'redirect' => 'catalog'
147
+ );
148
+ $this->dispatch($routeToDispatch, $params);
149
+ $this->assertRedirect('/');
150
+
151
+ $params = array(
152
+ 'orderID' => '23',
153
+ 'redirect' => 'catalog'
154
+ );
155
+ $this->dispatch($routeToDispatch, $params);
156
+ $this->assertRedirect('/');
157
+
158
+
159
+ }
160
+
161
+
162
+ public function testAcceptAliasAction()
163
+ {
164
+ $quote = Mage::getModel('sales/quote');
165
+ $payment = Mage::getModel('sales/quote_payment');
166
+ $quote->setPayment($payment);
167
+ $checkoutMock = $this->getModelMock('checkout/session', array('getQuote'));
168
+ $checkoutMock->expects($this->any())
169
+ ->method('getQuote')
170
+ ->will($this->returnValue($quote));
171
+ $this->replaceByMock('singleton', 'checkout/session', $checkoutMock);
172
+ $aliasHelperMock = $this->getHelperMock('ops/alias', array('saveAlias', 'setAliasToPayment'));
173
+ $this->replaceByMock('helper', 'ops/alias', $aliasHelperMock);
174
+ $routeToDispatch = 'ops/payment/acceptAlias';
175
+ $params = array('Alias' => '4711');
176
+ $this->dispatch($routeToDispatch, $params);
177
+ $result = Mage::helper('core')->jsonDecode($this->getResponse()->getOutputBody());
178
+ $this->assertEquals('4711', $result['alias']);
179
+ $this->assertEquals('success', $result['result']);
180
+ $this->assertNull($result['CVC']);
181
+
182
+ $params = array('Alias' => '4711', 'CVC' => '123');
183
+ $this->dispatch($routeToDispatch, $params);
184
+ $result = Mage::helper('core')->jsonDecode($this->getResponse()->getOutputBody());
185
+ $this->assertEquals('4711', $result['alias']);
186
+ $this->assertEquals('success', $result['result']);
187
+ $this->assertEquals('123', $result['CVC']);
188
+ // $this->markTestIncomplete();
189
+ }
190
+
191
+ /**
192
+ * @loadFixture ../../../var/fixtures/orders.yaml
193
+ *
194
+ * due to difficulties with loading the quote from the fixtures
195
+ * this test is marked as incomplete
196
+ *
197
+ */
198
+ public function testSaveAliasAction()
199
+ {
200
+ // $paymentMock = $this->getModelMock('sales/quote_payment', array('save'));
201
+ // $quote = $this->getModelMock('sales/quote', array('getPayment','_beforeSave', 'save'));
202
+ // $quote->expects($this->any())
203
+ // ->method('getPayment')
204
+ // ->will($this->returnValue($paymentMock));
205
+ // $quote->setPayment($paymentMock);
206
+ // Mage::getSingleton('checkout/session')->setQuote($quote);
207
+ // $routeToDispatch = 'ops/payment/saveAlias';
208
+ // $params = array('alias' => '4711');
209
+ //
210
+ // $aliasHelperMock = $this->getHelperMock('ops/alias', array('setAliasToPayment'));
211
+ // $aliasHelperMock->expects($this->once())
212
+ // ->method('setAliasToPayment')
213
+ // ->with($paymentMock, $params, false);
214
+ // $this->replaceByMock('helper', 'ops/alias', $aliasHelperMock);
215
+ //
216
+ // $this->dispatch($routeToDispatch, $params);
217
+ $this->markTestIncomplete();
218
+ }
219
+
220
+ /**
221
+ * @loadFixture ../../../var/fixtures/orders.yaml
222
+ */
223
+ public function testGenerateHashAction()
224
+ {
225
+
226
+ $fakeQuote = Mage::getModel('sales/order')->load(11);
227
+ $quoteMock = $this->getModelMock('sales/quote', array('load', 'save'));
228
+ $quoteMock->expects($this->any())
229
+ ->method('load')
230
+ ->will($this->returnValue($fakeQuote));
231
+ $this->replaceByMock('model', 'sales/quote', $quoteMock);
232
+ $params = array(
233
+ 'alias' => 4711,
234
+ 'storeId' => 1
235
+ );
236
+
237
+ $configHelperMock = $this->getModelMock('ops/config', array('getAliasAcceptUrl', 'getAliasExceptionUrl'));
238
+ $configHelperMock->expects($this->any())
239
+ ->method('getAliasAcceptUrl')
240
+ ->with(1)
241
+ ->will($this->returnValue(1));
242
+ $configHelperMock->expects($this->any())
243
+ ->method('getAliasExceptionUrl')
244
+ ->with(1)
245
+ ->will($this->returnValue(1));
246
+ $this->replaceByMock('model', 'ops/config', $configHelperMock);
247
+
248
+ $this->dispatch('ops/payment/generateHash', $params);
249
+ $result = Mage::helper('core')->jsonDecode($this->getResponse()->getOutputBody());
250
+ $this->assertArrayHasKey('hash', $result);
251
+ $this->assertArrayHasKey('alias', $result);
252
+ $this->assertEquals('4711', $result['alias']);
253
+
254
+ $params = array(
255
+ 'alias' => 4712,
256
+ 'storeId' => 0
257
+ );
258
+
259
+ $configHelperMock = $this->getModelMock('ops/config', array('getAliasAcceptUrl', 'getAliasExceptionUrl'));
260
+ $configHelperMock->expects($this->any())
261
+ ->method('getAliasAcceptUrl')
262
+ ->with(0)
263
+ ->will($this->returnValue(1));
264
+ $configHelperMock->expects($this->any())
265
+ ->method('getAliasExceptionUrl')
266
+ ->with(0)
267
+ ->will($this->returnValue(1));
268
+ $this->replaceByMock('model', 'ops/config', $configHelperMock);
269
+
270
+ $this->dispatch('ops/payment/generateHash', $params);
271
+ $result = Mage::helper('core')->jsonDecode($this->getResponse()->getOutputBody());
272
+ $this->assertArrayHasKey('hash', $result);
273
+ $this->assertArrayHasKey('alias', $result);
274
+ $this->assertEquals('4712', $result['alias']);
275
+
276
+ $params = array(
277
+ 'alias' => 4713,
278
+ 'storeId' => 1,
279
+ 'isAdmin' => 1,
280
+ 'brand' => 'visa'
281
+ );
282
+
283
+ $configHelperMock = $this->getModelMock('ops/config', array('getAliasAcceptUrl', 'getAliasExecptionUrl'));
284
+ $configHelperMock->expects($this->any())
285
+ ->method('getAliasAcceptUrl')
286
+ ->with(0)
287
+ ->will($this->returnValue(1));
288
+ $configHelperMock->expects($this->any())
289
+ ->method('getAliasExceptionUrl')
290
+ ->with(0)
291
+ ->will($this->returnValue(1));
292
+ $this->replaceByMock('model', 'ops/config', $configHelperMock);
293
+
294
+ $this->dispatch('ops/payment/generateHash', $params);
295
+ $result = Mage::helper('core')->jsonDecode($this->getResponse()->getOutputBody());
296
+ $this->assertArrayHasKey('hash', $result);
297
+ $this->assertArrayHasKey('alias', $result);
298
+ $this->assertEquals('4713', $result['alias']);
299
+ }
300
+
301
+ /**
302
+ * @loadFixture ../../../var/fixtures/orders.yaml
303
+ */
304
+ public function testGenerateHashWithStoredAliasButNewAliasIsUsed()
305
+ {
306
+ $fakeQuote = Mage::getModel('sales/order')->load(11);
307
+ $quoteMock = $this->getModelMock('sales/quote', array('load', 'save'));
308
+ $quoteMock->expects($this->any())
309
+ ->method('load')
310
+ ->will($this->returnValue($fakeQuote));
311
+ $this->replaceByMock('model', 'sales/quote', $quoteMock);
312
+ $params = array(
313
+ 'alias' => 4711,
314
+ 'storeId' => 1,
315
+ 'storedAlias' => '0815',
316
+ );
317
+
318
+ $helperMock = $this->getHelperMock('ops/alias', array('isAliasValidForAddresses'));
319
+ $helperMock->expects($this->any())
320
+ ->method('isAliasValidForAddresses')
321
+ ->will($this->returnValue(true));
322
+ $this->replaceByMock('helper', 'ops/alias', $helperMock);
323
+ $this->dispatch('ops/payment/generateHash', $params);
324
+ $result = Mage::helper('core')->jsonDecode($this->getResponse()->getOutputBody());
325
+ $this->assertArrayHasKey('hash', $result);
326
+ $this->assertArrayHasKey('alias', $result);
327
+ $this->assertEquals('4711', $result['alias']);
328
+
329
+ $helperMock = $this->getHelperMock('ops/alias', array('isAliasValidForAddresses'));
330
+ $helperMock->expects($this->any())
331
+ ->method('isAliasValidForAddresses')
332
+ ->will($this->returnValue(false));
333
+ $this->replaceByMock('helper', 'ops/alias', $helperMock);
334
+ $this->dispatch('ops/payment/generateHash', $params);
335
+ $result = Mage::helper('core')->jsonDecode($this->getResponse()->getOutputBody());
336
+ $this->assertArrayHasKey('hash', $result);
337
+ $this->assertArrayHasKey('alias', $result);
338
+ $this->assertEquals('4711', $result['alias']);
339
+ }
340
+
341
+ public function testGenerateHashWithStoredAliasOldAliasIsUsed()
342
+ {
343
+ $fakeQuote = $this->getModelMock('sales/quote', array('save', 'getPayment'));
344
+ $fakeQuote->setId(1);
345
+ $fakeQuote->setStoreId(1);
346
+ $customer = $this->getModelMock('customer/customer', array('save'));
347
+ $customer->setId(1);
348
+ $billingAddress = new Varien_Object();
349
+ $shippingAddress = new Varien_Object();
350
+ $fakeQuote->setCustomer($customer);
351
+
352
+ $fakePayment = $this->getModelMock('sales/quote_payment', array('save'));
353
+ $fakePayment->expects($this->any())
354
+ ->method('settAdditionalInformation')
355
+ ->with('saveOpsAlias', 1);
356
+ $fakeQuote->expects($this->any())
357
+ ->method('getPayment')
358
+ ->will($this->returnValue($fakePayment));
359
+
360
+ $quoteMock = $this->getModelMock('sales/quote', array('load', 'save'));
361
+ $quoteMock->expects($this->any())
362
+ ->method('load')
363
+ ->will($this->returnValue($fakeQuote));
364
+ $this->replaceByMock('model', 'sales/quote', $quoteMock);
365
+ $params = array(
366
+ 'alias' => 4711,
367
+ 'storeId' => 1,
368
+ 'storedAlias' => '0815',
369
+ 'saveAlias' => 1
370
+ );
371
+
372
+ $helperMock = $this->getHelperMock('ops/alias', array('isAliasValidForAddresses'));
373
+ $helperMock->expects($this->any())
374
+ ->method('isAliasValidForAddresses')
375
+ ->will($this->returnValue(true));
376
+ $this->replaceByMock('helper', 'ops/alias', $helperMock);
377
+ $this->dispatch('ops/payment/generateHash', $params);
378
+ $result = Mage::helper('core')->jsonDecode($this->getResponse()->getOutputBody());
379
+ $this->assertArrayHasKey('hash', $result);
380
+ $this->assertArrayHasKey('alias', $result);
381
+ $this->assertEquals('0815', $result['alias']);
382
+
383
+ $helperMock = $this->getHelperMock('ops/alias', array('isAliasValidForAddresses'));
384
+ $helperMock->expects($this->any())
385
+ ->method('isAliasValidForAddresses')
386
+ ->will($this->returnValue(false));
387
+ $this->replaceByMock('helper', 'ops/alias', $helperMock);
388
+ $this->dispatch('ops/payment/generateHash', $params);
389
+ $result = Mage::helper('core')->jsonDecode($this->getResponse()->getOutputBody());
390
+ $this->assertArrayHasKey('hash', $result);
391
+ $this->assertArrayHasKey('alias', $result);
392
+ $this->assertEquals('4711', $result['alias']);
393
+ }
394
+
395
+ public function testGenerateHashActionWithSaveAlias()
396
+ {
397
+ $fakeQuote = $this->getModelMock('sales/quote', array('save', 'getPayment'));
398
+ $fakeQuote->setId(1);
399
+ $fakeQuote->setStoreId(1);
400
+ $customer = $this->getModelMock('customer/customer', array('save'));
401
+ $customer->setId(1);
402
+ $billingAddress = new Varien_Object();
403
+ $shippingAddress = new Varien_Object();
404
+ $fakeQuote->setCustomer($customer);
405
+ $fakePayment = $this->getModelMock('sales/quote_payment', array('save'));
406
+ $fakePayment->expects($this->any())
407
+ ->method('settAdditionalInformation')
408
+ ->with('saveOpsAlias', 1);
409
+ $fakeQuote->expects($this->any())
410
+ ->method('getPayment')
411
+ ->will($this->returnValue($fakePayment));
412
+
413
+ $quoteMock = $this->getModelMock('sales/quote', array('load', 'save'));
414
+ $quoteMock->expects($this->any())
415
+ ->method('load')
416
+ ->will($this->returnValue($fakeQuote));
417
+ $this->replaceByMock('model', 'sales/quote', $quoteMock);
418
+ $params = array(
419
+ 'alias' => 4711,
420
+ 'storeId' => 1,
421
+ 'saveAlias' => 1
422
+ );
423
+
424
+ $this->dispatch('ops/payment/generateHash', $params);
425
+ $result = Mage::helper('core')->jsonDecode($this->getResponse()->getOutputBody());
426
+ $this->assertArrayHasKey('hash', $result);
427
+ $this->assertArrayHasKey('alias', $result);
428
+ $this->assertEquals('4711', $result['alias']);
429
+ }
430
+
431
+ /**
432
+ * @loadFixture ../../../var/fixtures/orders.yaml
433
+ */
434
+ public function testRepayActionWithInvalidHash()
435
+ {
436
+ // test 1: hash not valid
437
+ $order = Mage::getModel('sales/order')->load(11);
438
+ $opsOrderId = Mage::helper('ops/order')->getOpsOrderId($order);
439
+
440
+ $paymentHelperMock = $this->getHelperMock('ops/payment', array('shaCryptValidation'));
441
+ $paymentHelperMock->expects($this->any())
442
+ ->method('shaCryptValidation')
443
+ ->will($this->returnValue(false));
444
+ $this->replaceByMock('helper', 'ops/payment', $paymentHelperMock);
445
+
446
+
447
+ $params = array('orderID' => $opsOrderId, 'SHASIGN' => 'foo');
448
+ $this->dispatch('ops/payment/retry', $params);
449
+ $this->assertRedirectTo('/');
450
+ $message = Mage::getSingleton('core/session')->getMessages()->getLastAddedMessage();
451
+ $this->assertNotNull($message);
452
+ $this->assertEquals($message->getText(), 'Hash not valid');
453
+
454
+ }
455
+
456
+ /**
457
+ * @loadFixture ../../../var/fixtures/orders.yaml
458
+ */
459
+ public function testRepayActionWithInvalidOrder()
460
+ {
461
+
462
+ // test 1: hash valid, order can not be retried
463
+ // orderID 100000011
464
+ $order = Mage::getModel('sales/order')->load(11);
465
+ $opsOrderId = Mage::helper('ops/order')->getOpsOrderId($order);
466
+
467
+ $paymentHelperMock = $this->getHelperMock('ops/payment', array('shaCryptValidation'));
468
+ $paymentHelperMock->expects($this->any())
469
+ ->method('shaCryptValidation')
470
+ ->will($this->returnValue(true));
471
+ $this->replaceByMock('helper', 'ops/payment', $paymentHelperMock);
472
+
473
+ $params = array(
474
+ 'orderID' => $opsOrderId,
475
+ 'SHASIGN' => 'foo'
476
+ );
477
+ $this->dispatch('ops/payment/retry', $params);
478
+ $this->assertRedirectTo('/');
479
+ $message = Mage::getSingleton('core/session')->getMessages()->getLastAddedMessage();
480
+ $this->assertNotNull($message);
481
+ $this->assertEquals($message->getText(), 'Not possible to reenter the payment details for order ' . $order->getIncrementId());
482
+
483
+ }
484
+
485
+ /**
486
+ * @loadFixture ../../../var/fixtures/orders.yaml
487
+ */
488
+ public function testRepayActionWithSuccess()
489
+ {
490
+ // test 3: order is fine
491
+ // orderID 100000013
492
+
493
+ $order = Mage::getModel('sales/order')->load(13);
494
+ $opsOrderId = Mage::helper('ops/order')->getOpsOrderId($order);
495
+
496
+ $paymentHelperMock = $this->getHelperMock('ops/payment', array('shaCryptValidation'));
497
+ $paymentHelperMock->expects($this->any())
498
+ ->method('shaCryptValidation')
499
+ ->will($this->returnValue(true));
500
+ $this->replaceByMock('helper', 'ops/payment', $paymentHelperMock);
501
+
502
+ $params = array(
503
+ 'orderID' => $opsOrderId,
504
+ 'SHASIGN' => 'foo'
505
+ );
506
+
507
+ $this->dispatch('ops/payment/retry', $params);
508
+ $this->assertLayoutLoaded();
509
+ $this->assertLayoutHandleLoaded('ops_payment_retry');
510
+
511
+ }
512
+ }
app/code/community/Netresearch/OPS/Test/Controller/PaymentControllerTest/fixtures/.gitkeep ADDED
File without changes
app/code/community/Netresearch/OPS/Test/Helper/AliasTest.php ADDED
@@ -0,0 +1,700 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * To change this template, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+
7
+ /**
8
+ * Description of AliasTest
9
+ *
10
+ * @author sebastian
11
+ */
12
+ class Netresearch_OPS_Test_Helper_AliasTest extends EcomDev_PHPUnit_Test_Case
13
+ {
14
+
15
+ private $_helper;
16
+ private $store;
17
+
18
+ public function setUp()
19
+ {
20
+ parent::setup();
21
+ $this->_helper = Mage::helper('ops/alias');
22
+ $this->store = Mage::app()->getStore(0)->load(0);
23
+ }
24
+
25
+ /**
26
+ * @loadFixture ../../../var/fixtures/orders.yaml
27
+ */
28
+ public function testgetAliasWithoutAdditionalInformation()
29
+ {
30
+ $aliasHelperMock = $this->getHelperMock('ops/alias', array('isAdminSession'));
31
+ $aliasHelperMock->expects($this->any())
32
+ ->method('isAdminSession')
33
+ ->will($this->returnValue(false));
34
+ $quote = Mage::getModel('sales/quote')->load(11);
35
+
36
+ $alias = $aliasHelperMock->getAlias($quote);
37
+
38
+ $this->assertTrue(
39
+ strlen($aliasHelperMock->getAlias($quote)) <= 16
40
+ );
41
+ $this->assertTrue(
42
+ strpos($aliasHelperMock->getAlias($quote), "99") != false
43
+ );
44
+ $this->assertEquals(
45
+ "051414459911", $aliasHelperMock->getAlias($quote)
46
+ );
47
+ }
48
+
49
+ public function testGetAliasWithAdditionalInformation()
50
+ {
51
+ $quote = new Varien_Object();
52
+ $payment = new Varien_Object();
53
+ $payment->setAdditionalInformation(array('alias' => 'testAlias'));
54
+ $quote->setPayment($payment);
55
+
56
+ $aliasHelperMock = $this->getHelperMock('ops/alias', array('isAdminSession'));
57
+ $aliasHelperMock->expects($this->any())
58
+ ->method('isAdminSession')
59
+ ->will($this->returnValue(false));
60
+
61
+ $this->assertEquals(
62
+ 'testAlias', $aliasHelperMock->getAlias($quote)
63
+ );
64
+
65
+ }
66
+
67
+
68
+ public function testGetOpsCode()
69
+ {
70
+ $this->assertEquals(null, Mage::helper('ops/alias')->getOpsCode());
71
+ }
72
+
73
+ public function testGetOpsBrand()
74
+ {
75
+ $this->assertEquals(null, Mage::helper('ops/alias')->getOpsBrand());
76
+ }
77
+
78
+ public function testSaveAliasIfCustomerIsNotLoggedIn()
79
+ {
80
+ $quote = Mage::getModel('sales/quote');
81
+ $this->assertEquals(
82
+ null, $this->_helper->saveAlias(array('OrderID' => 4711))
83
+ );
84
+ }
85
+
86
+ public function testSaveAliasIfCustomerIsLoggedIn()
87
+ {
88
+ $quote = $this->getModelMock('sales/quote', array('save'));
89
+ $this->replaceByMock('model', 'sales/quote', $quote);
90
+ $quote->setBillingAddress($this->getAddressData());
91
+ $quote->setShippingAddress($this->getAddressData());
92
+ $quote->setId(4711);
93
+ $customer = new Varien_Object();
94
+ $customer->setId(1);
95
+ $aliasData['OrderID'] = 4711;
96
+ $aliasData['Alias'] = 4711;
97
+ $aliasData['Brand'] = 'Visa';
98
+ $aliasData['CardNo'] = 'xxxx0815';
99
+ $aliasData['ED'] = '1212';
100
+ $aliasData['CN'] = 'Foo Baar';
101
+ $payment = $this->getModelMock('sales/quote_payment', array('save'));
102
+ $payment->setMethod('CreditCard');
103
+ $payment->setAdditionalInformation(array('saveOpsAlias' => '1'));
104
+ // $quote->setCustomer($customer);
105
+ $quote->setPayment($payment);
106
+
107
+ $quoteMock = $this->getModelMock(
108
+ 'sales/quote', array('load', 'getPayment', 'getCustomer')
109
+ );
110
+ $quoteMock->expects($this->any())
111
+ ->method('load')
112
+ ->will($this->returnValue($quoteMock));
113
+ $quoteMock->expects($this->any())
114
+ ->method('getPayment')
115
+ ->will($this->returnValue($payment));
116
+ $quoteMock->expects($this->any())
117
+ ->method('getCustomer')
118
+ ->will($this->returnValue($customer));
119
+ $this->replaceByMock('model', 'sales/quote', $quoteMock);
120
+ $alias = $this->_helper->saveAlias($aliasData);
121
+ $this->assertEquals('4711', $alias->getAlias());
122
+ $this->assertEquals('Visa', $alias->getBrand());
123
+ $this->assertEquals('xxxx0815', $alias->getPseudoAccountOrCcNo());
124
+ $this->assertEquals('1212', $alias->getExpirationDate());
125
+ $this->assertEquals(
126
+ 'da39a3ee5e6b4b0d3255bfef95601890afd80709',
127
+ $alias->getBillingAddressHash()
128
+ );
129
+ $this->assertEquals(
130
+ 'da39a3ee5e6b4b0d3255bfef95601890afd80709',
131
+ $alias->getShippingAddressHash()
132
+ );
133
+ $this->assertEquals('CreditCard', $alias->getPaymentMethod());
134
+ $this->assertEquals(1, $alias->getCustomerId());
135
+
136
+ $oldAliasId = $alias->getId();
137
+
138
+ $alias = $this->_helper->saveAlias($aliasData, $quote);
139
+ $this->assertGreaterThan($oldAliasId, $alias->getId());
140
+ }
141
+
142
+ /**
143
+ * @loadFixture ../../../var/fixtures/orders.yaml
144
+ */
145
+ public function testSaveAliasUpdate()
146
+ {
147
+ $quote = $this->getModelMock('sales/quote', array('save'));
148
+ $this->replaceByMock('model', 'sales/quote', $quote);
149
+ $quote->setBillingAddress($this->getAddressData());
150
+ $quote->setShippingAddress($this->getAddressData());
151
+ $quote->setId(4711);
152
+ $customer = new Varien_Object();
153
+ $customer->setId(1);
154
+ $aliasData['OrderID'] = 4711;
155
+ $aliasData['Alias'] = 4711;
156
+ $aliasData['Brand'] = 'Visa';
157
+ $aliasData['CardNo'] = 'xxxx0815';
158
+ $aliasData['ED'] = '1212';
159
+ $aliasData['CN'] = 'Foo Baar';
160
+ $payment = $this->getModelMock('sales/quote_payment', array('save'));
161
+ $payment->setMethod('CreditCard');
162
+ $payment->setAdditionalInformation(array('saveOpsAlias' => '1'));
163
+ // $quote->setCustomer($customer);
164
+ $quote->setPayment($payment);
165
+
166
+ $quoteMock = $this->getModelMock(
167
+ 'sales/quote', array('load', 'getPayment', 'getCustomer')
168
+ );
169
+ $quoteMock->expects($this->any())
170
+ ->method('load')
171
+ ->will($this->returnValue($quoteMock));
172
+ $quoteMock->expects($this->any())
173
+ ->method('getPayment')
174
+ ->will($this->returnValue($payment));
175
+ $quoteMock->expects($this->any())
176
+ ->method('getCustomer')
177
+ ->will($this->returnValue($customer));
178
+ $this->replaceByMock('model', 'sales/quote', $quoteMock);
179
+ $oldAlias = $this->_helper->saveAlias($aliasData);
180
+ $oldAlias->setState(Netresearch_OPS_Model_Alias_State::ACTIVE);
181
+ $oldAlias->save();
182
+
183
+ $aliasData['OrderID'] = 4811;
184
+ $aliasData['Alias'] = 4711;
185
+ $aliasData['Brand'] = 'Mastercard';
186
+ $aliasData['CardNo'] = 'xxxx01111';
187
+ $aliasData['ED'] = '1213';
188
+ $aliasData['CN'] = 'Max Power';
189
+
190
+ $updatedAlias = $this->_helper->saveAlias($aliasData);
191
+ $this->assertEquals(4711,$updatedAlias->getAlias());
192
+ $this->assertEquals('Mastercard',$updatedAlias->getBrand());
193
+ $this->assertEquals('xxxx01111',$updatedAlias->getPseudoAccountOrCcNo());
194
+ $this->assertEquals('1213',$updatedAlias->getExpirationDate());
195
+ $this->assertEquals('Max Power',$updatedAlias->getCardHolder());
196
+
197
+ }
198
+
199
+ /**
200
+ * @loadFixture ../../../var/fixtures/aliases.yaml
201
+ * @loadFixture ../../../var/fixtures/orders.yaml
202
+ */
203
+ public function testSaveNewAlias()
204
+ {
205
+ $reflection_class = new ReflectionClass("Netresearch_OPS_Helper_Alias");
206
+ $method = $reflection_class->getMethod("saveNewAlias");
207
+ $method->setAccessible(true);
208
+
209
+ $quote = Mage::getModel('sales/quote')->load(10);
210
+ $aliasData = array(
211
+ 'Alias' => 'TestAlias',
212
+ 'ED' => '12.12.0012',
213
+ 'Brand' => 'Visa',
214
+ 'CardNo' => '12345678',
215
+ 'CN' => 'Foo'
216
+ );
217
+ $aliasHelper = Mage::helper('ops/alias');
218
+ $alias = $method->invoke($aliasHelper, $quote, $aliasData);
219
+ $this->assertEquals('TestAlias', $alias->getAlias());
220
+ $this->assertEquals('12.12.0012', $alias->getExpirationDate());
221
+ $this->assertEquals('Foo', $alias->getCardHolder());
222
+ $this->assertEquals(Netresearch_OPS_Model_Alias_State::PENDING, $alias->getState());
223
+
224
+ $aliasData = array(
225
+ 'Alias' => 'TestAlias',
226
+ 'ED' => '12.12.0012',
227
+ 'Brand' => 'Visa',
228
+ 'CardNo' => '12345678'
229
+ );
230
+ $aliasHelper = Mage::helper('ops/alias');
231
+ $alias = $method->invoke($aliasHelper, $quote, $aliasData);
232
+ $this->assertEquals('TestAlias', $alias->getAlias());
233
+ $this->assertEquals('12.12.0012', $alias->getExpirationDate());
234
+ $this->assertNull($alias->getCardHolder());
235
+ $this->assertEquals(Netresearch_OPS_Model_Alias_State::PENDING, $alias->getState());
236
+
237
+ $aliasData = array(
238
+ 'Alias' => 'TestAlias',
239
+ 'ED' => '12.12.0012',
240
+ 'Brand' => 'Visa',
241
+ 'CardNo' => '12345678',
242
+ 'CN' => ''
243
+ );
244
+ $aliasHelper = Mage::helper('ops/alias');
245
+ $alias = $method->invoke($aliasHelper, $quote, $aliasData);
246
+ $this->assertEquals('TestAlias', $alias->getAlias());
247
+ $this->assertEquals('12.12.0012', $alias->getExpirationDate());
248
+ $this->assertEquals('', $alias->getCardHolder());
249
+ $this->assertEquals(Netresearch_OPS_Model_Alias_State::PENDING, $alias->getState());
250
+ }
251
+
252
+ /**
253
+ * @loadFixture ../../../var/fixtures/aliases.yaml
254
+ * @loadFixture ../../../var/fixtures/orders.yaml
255
+ */
256
+ public function testDeleteAlias()
257
+ {
258
+ $reflection_class = new ReflectionClass("Netresearch_OPS_Helper_Alias");
259
+ $method = $reflection_class->getMethod("deleteAlias");
260
+ $method->setAccessible(true);
261
+ $aliasModel = Mage::getModel('ops/alias');
262
+ $quote = Mage::getModel('sales/quote')->load(10);
263
+ $quote->setBillingAddress($this->getAddressData());
264
+ $quote->setShippingAddress($this->getAddressData());
265
+ $customer = Mage::getModel('customer/customer');
266
+ $customer->setId(1);
267
+
268
+ $quote->setCustomer($customer);
269
+
270
+ $customerId = $quote->getCustomer()->getId();
271
+ $aliasesForCustomer = $aliasCollection = $aliasModel->getCollection()
272
+ ->addFieldToFilter('customer_id', $customerId)
273
+ ->load();
274
+ $oldAliasSize = count($aliasesForCustomer);
275
+
276
+ $aliasData = array(
277
+ 'Alias' => '4711',
278
+ 'ED' => '0117',
279
+ 'Brand' => 'Visa',
280
+ 'CardNo' => 'xxxx1111'
281
+ );
282
+ $aliasHelper = Mage::helper('ops/alias');
283
+ $method->invoke($aliasHelper, $quote, $aliasData);
284
+ $newAliasForCustomer = $aliasCollection = $aliasModel->getCollection()
285
+ ->addFieldToFilter('customer_id', $customerId)
286
+ ->load();
287
+ $newAliasSize = count($newAliasForCustomer);
288
+ $this->assertGreaterThan($newAliasSize, $oldAliasSize);
289
+ }
290
+
291
+ /**
292
+ * @loadFixture ../../../var/fixtures/aliases.yaml
293
+ * @loadFixture ../../../var/fixtures/orders.yaml
294
+ */
295
+ public function testDeleteAliasDoesNotDeleteAliasIfAddressDoesNotMatch()
296
+ {
297
+ $reflection_class = new ReflectionClass("Netresearch_OPS_Helper_Alias");
298
+ $method = $reflection_class->getMethod("deleteAlias");
299
+ $method->setAccessible(true);
300
+ $aliasModel = Mage::getModel('ops/alias');
301
+ $quote = Mage::getModel('sales/quote')->load(10);
302
+ $customer = Mage::getModel('customer/customer');
303
+ $customer->setId(1);
304
+
305
+ $quote->setCustomer($customer);
306
+
307
+ $customerId = $quote->getCustomer()->getId();
308
+ $aliasesForCustomer = $aliasCollection = $aliasModel->getCollection()
309
+ ->addFieldToFilter('customer_id', $customerId)
310
+ ->load();
311
+ $oldAliasSize = count($aliasesForCustomer);
312
+
313
+ $aliasData = array(
314
+ 'Alias' => '4711',
315
+ 'ED' => '0117',
316
+ 'Brand' => 'Visa',
317
+ 'CardNo' => 'xxxx1111'
318
+ );
319
+ $aliasHelper = Mage::helper('ops/alias');
320
+ $method->invoke($aliasHelper, $quote, $aliasData);
321
+ $newAliasForCustomer = $aliasCollection = $aliasModel->getCollection()
322
+ ->addFieldToFilter('customer_id', $customerId)
323
+ ->load();
324
+ $newAliasSize = count($newAliasForCustomer);
325
+ $this->assertEquals($newAliasSize, $oldAliasSize);
326
+ }
327
+
328
+ /**
329
+ * @loadFixture ../../../var/fixtures/aliases.yaml
330
+ * @loadFixture ../../../var/fixtures/orders.yaml
331
+ */
332
+ public function testGetAliasesForCustomer()
333
+ {
334
+ $quote = Mage::getModel('sales/quote')->load(10);
335
+
336
+ $aliasesCollection = $this->_helper->getAliasesForCustomer(1);
337
+ $this->assertEquals(5, count($aliasesCollection));
338
+
339
+ $aliasesCollection = $this->_helper->getAliasesForCustomer(2);
340
+ $this->assertEquals(1, count($aliasesCollection));
341
+
342
+ $aliasesCollection = $this->_helper->getAliasesForCustomer(3);
343
+ $this->assertEquals(0, count($aliasesCollection));
344
+
345
+ $aliasesCollection = $this->_helper->getAliasesForCustomer(
346
+ null, $quote
347
+ );
348
+ $this->assertEquals(0, count($aliasesCollection));
349
+ }
350
+
351
+ /**
352
+ * @loadFixture ../../../var/fixtures/aliases.yaml
353
+ */
354
+ public function testIsAliasValidForAddresses()
355
+ {
356
+ $billingAddress = Mage::getModel('sales/quote_address');
357
+ $shippingAddress = Mage::getModel('sales/quote_address');
358
+ $this->assertFalse(
359
+ $this->_helper->isAliasValidForAddresses(
360
+ 1, '4711', $shippingAddress, $billingAddress
361
+ )
362
+ );
363
+
364
+ $billingAddress = $this->getAddressData();
365
+ $shippingAddress = $this->getAddressData();
366
+
367
+ $this->assertTrue(
368
+ $this->_helper->isAliasValidForAddresses(
369
+ 1, '4711', $shippingAddress, $billingAddress
370
+ )
371
+ );
372
+
373
+ $this->assertFalse(
374
+ $this->_helper->isAliasValidForAddresses(
375
+ 2, '4711', $shippingAddress, $billingAddress
376
+ )
377
+ );
378
+ }
379
+
380
+ protected function getAddressData()
381
+ {
382
+ $address = new Mage_Sales_Model_Quote_Address();
383
+ $address->setFirstname('foo');
384
+ $address->setLastname('bert');
385
+ $address->setStreet1('bla street 1');
386
+ $address->setZipcode('4711');
387
+ $address->setCity('Cologne');
388
+ $address->setCountry_id(1);
389
+ return $address;
390
+ }
391
+
392
+ public function testGenerateAddressHash()
393
+ {
394
+ $address = $this->getAddressData();
395
+ $this->assertEquals(
396
+ '1b9ecdf409e240717f04b7155712658ab09116bb',
397
+ $this->_helper->generateAddressHash($address)
398
+ );
399
+ $address->setData('street', array('wuseldusel', 'foo'));
400
+ $this->assertEquals(
401
+ '260a9287b2964d3674f49f589d5e5fd7143041cf',
402
+ $this->_helper->generateAddressHash($address)
403
+ );
404
+ }
405
+
406
+ public function testFormatAliasCardNo()
407
+ {
408
+ $helper = Mage::helper('ops/alias');
409
+ $cardNo = 'xxxxxxxxxxxx1111';
410
+ $cardType = 'VISA';
411
+ $this->assertEquals(
412
+ 'XXXX XXXX XXXX 1111',
413
+ $helper->formatAliasCardNo($cardType, $cardNo)
414
+ );
415
+
416
+ $cardNo = 'xxxxxxxxxxxx9999';
417
+ $cardType = 'MasterCard';
418
+ $this->assertEquals(
419
+ 'XXXX XXXX XXXX 9999',
420
+ $helper->formatAliasCardNo($cardType, $cardNo)
421
+ );
422
+
423
+ $cardNo = '3750-xxxxxx-03';
424
+ $cardType = 'american express';
425
+ $this->assertEquals(
426
+ '3750 XXXXXX 03', $helper->formatAliasCardNo($cardType, $cardNo)
427
+ );
428
+
429
+ $cardNo = '3750-xxxxxx-03';
430
+ $cardType = 'DINERS CLUB';
431
+ $this->assertEquals(
432
+ '3750 XXXXXX 03', $helper->formatAliasCardNo($cardType, $cardNo)
433
+ );
434
+
435
+
436
+ $cardNo = '675941-XXXXXXXX-08';
437
+ $cardType = 'MaestroUK';
438
+ $this->assertEquals(
439
+ '675941 XXXXXXXX 08', $helper->formatAliasCardNo($cardType, $cardNo)
440
+ );
441
+
442
+ $cardNo = '675956-XXXXXXXX-54';
443
+ $cardType = 'MaestroUK';
444
+ $this->assertEquals(
445
+ '675956 XXXXXXXX 54', $helper->formatAliasCardNo($cardType, $cardNo)
446
+ );
447
+
448
+ $cardNo = '564182-XXXXXXXX-69';
449
+ $cardType = 'MaestroUK';
450
+ $this->assertEquals(
451
+ '564182 XXXXXXXX 69', $helper->formatAliasCardNo($cardType, $cardNo)
452
+ );
453
+
454
+ $cardNo = '3750-xxxxxx-03';
455
+ $cardType = 'PostFinance Card';
456
+ $this->assertEquals(
457
+ '3750-XXXXXX-03', $helper->formatAliasCardNo($cardType, $cardNo)
458
+ );
459
+ }
460
+
461
+ /**
462
+ *
463
+ * @loadFixture ../../../var/fixtures/orders.yaml
464
+ * @loadFixture ../../../var/fixtures/aliases.yaml
465
+ */
466
+ public function testSetAliasToPayment()
467
+ {
468
+ $params = array();
469
+ $quote = Mage::getModel('sales/quote')->load(11);
470
+ $helper = Mage::helper('ops/alias');
471
+ $helper->setAliasToPayment($quote->getPayment(), $params);
472
+ $payment = $quote->getPayment();
473
+ $this->assertArrayNotHasKey('alias', $payment->getAdditionalInformation());
474
+ $this->assertArrayNotHasKey('cvc', $payment->getAdditionalInformation());
475
+
476
+ $params = array(
477
+ 'alias' => '4711'
478
+ );
479
+ $quote = Mage::getModel('sales/quote')->load(10);
480
+ $helper = Mage::helper('ops/alias');
481
+ $helper->setAliasToPayment($quote->getPayment(), $params);
482
+ $payment = $quote->getPayment();
483
+
484
+ $this->assertArrayHasKey('alias', $payment->getAdditionalInformation());
485
+ $this->assertEquals('4711', $payment->getAdditionalInformation('alias'));
486
+ $this->assertArrayNotHasKey('cvc', $payment->getAdditionalInformation());
487
+
488
+ $params = array(
489
+ 'alias' => '4712',
490
+ 'CVC' => '123'
491
+ );
492
+
493
+ $dataHelperMock = $this->getHelperMock('ops/data', array('isAdminSession'));
494
+ $dataHelperMock->expects($this->any())
495
+ ->method('isAdminSession')
496
+ ->will($this->returnValue(false));
497
+ $this->replaceByMock('helper', 'ops/data', $dataHelperMock);
498
+ $quote = Mage::getModel('sales/quote')->load(10);
499
+ $helper = Mage::helper('ops/alias');
500
+ $helper->setAliasToPayment($quote->getPayment(), $params);
501
+ $payment = $quote->getPayment();
502
+ $this->assertEquals('4712', $payment->getAdditionalInformation('alias'));
503
+ $this->assertArrayHasKey('cvc', $payment->getAdditionalInformation());
504
+ $this->assertEquals('123', $payment->getAdditionalInformation('cvc'));
505
+ }
506
+
507
+ /**
508
+ * @loadFixture ../../../var/fixtures/aliases.yaml
509
+ * @loadFixture ../../../var/fixtures/orders.yaml
510
+ */
511
+ public function testSetCardHolder()
512
+ {
513
+ $reflection_class = new ReflectionClass("Netresearch_OPS_Helper_Alias");
514
+ $method = $reflection_class->getMethod('setCardHolderToAlias');
515
+ $method->setAccessible(true);
516
+
517
+ $helperObject = Mage::helper('ops/alias');
518
+
519
+ $quote = Mage::getModel('sales/quote')->load(10);
520
+ $quote->setBillingAddress($this->getAddressData());
521
+ $quote->setShippingAddress($this->getAddressData());
522
+
523
+ $oldAlias = Mage::getModel('ops/alias')->load(7);
524
+ $aliasData = array(
525
+ 'alias' => '4712',
526
+ 'CVC' => '123',
527
+ 'CN' => 'Max Muster'
528
+ );
529
+
530
+ $method->invoke($helperObject, $quote,$aliasData);
531
+ $updatedAlias = Mage::getModel('ops/alias')->load(7);
532
+ $this->assertEquals($aliasData['CN'], $updatedAlias->getCardHolder());
533
+
534
+ }
535
+
536
+ /**
537
+ * @loadFixture ../../../var/fixtures/aliases.yaml
538
+ * @loadFixture ../../../var/fixtures/orders.yaml
539
+ */
540
+ public function testSetAliasActive()
541
+ {
542
+ $order = Mage::getModel('sales/order')->load(11);
543
+ $quote = Mage::getModel('sales/quote')->load(10);
544
+ $quote->setBillingAddress($this->getAddressData());
545
+ $quote->setShippingAddress($this->getAddressData());
546
+ $payment = $this->getModelMock('sales/quote_payment', array('save'));
547
+ $payment->setAdditionalInformation('alias', '4714');
548
+ $payment->setAdditionalInformation('userIsRegistering', false);
549
+ $orderPayment = $this->getModelMock('sales/order_payment', array('save'));
550
+ $orderPayment->setAdditionalInformation('alias', '4714');
551
+ $orderPayment->setAdditionalInformation('userIsRegistering', false);
552
+ $quote->setPayment($payment);
553
+ $order->setPayment($orderPayment);
554
+ $customer = Mage::getModel('customer/customer');
555
+ $customer->setId(1);
556
+ $quote->setCustomer($customer);
557
+ $billingAddressHash = Mage::helper('ops/alias')->generateAddressHash($quote->getBillingAddress());
558
+ $shippingAddressHash = Mage::helper('ops/alias')->generateAddressHash($quote->getShippingAddress());
559
+ $aliasesToDelete = Mage::getModel('ops/alias')
560
+ ->getCollection()
561
+ ->addFieldToFilter('customer_id', $quote->getCustomer()->getId())
562
+ ->addFieldToFilter('billing_address_hash', $billingAddressHash)
563
+ ->addFieldToFilter('shipping_address_hash', $shippingAddressHash)
564
+ ->addFieldToFilter('state', Netresearch_OPS_Model_Alias_State::ACTIVE);
565
+ $oldAlias = $aliasesToDelete->getFirstItem();
566
+ $helperMock = $this->getHelperMock('ops/alias', array('cleanUpAdditionalInformation'));
567
+ $helperMock->setAliasActive($quote, $order);
568
+ $aliasesToUpdate = Mage::getModel('ops/alias')
569
+ ->getCollection()
570
+ ->addFieldToFilter('customer_id', $quote->getCustomer()->getId())
571
+ ->addFieldToFilter('billing_address_hash', $billingAddressHash)
572
+ ->addFieldToFilter('shipping_address_hash', $shippingAddressHash)
573
+ ->addFieldToFilter('alias', '4714')
574
+ ->addFieldToFilter('state', Netresearch_OPS_Model_Alias_State::ACTIVE)
575
+ ->setOrder('created_at', Varien_Data_Collection::SORT_ORDER_DESC);
576
+ $newAlias = $aliasesToUpdate->getFirstItem();
577
+
578
+ $testAlias = Mage::getModel('ops/alias')->load($oldAlias->getId());
579
+ $this->assertEquals(null, $testAlias->getId());
580
+ $this->assertEquals('active', $newAlias->getState());
581
+ }
582
+
583
+ /**
584
+ * @loadFixture ../../../var/fixtures/aliases.yaml
585
+ * @loadFixture ../../../var/fixtures/orders.yaml
586
+ */
587
+ public function testSetAliasActiveWhenUserRegisters()
588
+ {
589
+ $order = $this->getModelMock('sales/order', array('getPayment'));
590
+ $quote = $this->getModelMock('sales/quote', array('getPayment'));
591
+ $quote->setBillingAddress($this->getAddressData());
592
+ $quote->setShippingAddress($this->getAddressData());
593
+ $payment = $this->getModelMock('sales/quote_payment', array('save'));
594
+ $payment->setAdditionalInformation('alias', '4714');
595
+ $payment->setAdditionalInformation('userIsRegistering', true);
596
+ $orderPayment = $this->getModelMock('sales/order_payment', array('save'));
597
+ $orderPayment->setAdditionalInformation('alias', '4714');
598
+ $orderPayment->setAdditionalInformation('userIsRegistering', true);
599
+ $quote->expects($this->any())
600
+ ->method('getPayment')
601
+ ->will($this->returnValue($payment));
602
+
603
+ $order->expects($this->any())
604
+ ->method('getPayment')
605
+ ->will($this->returnValue($orderPayment));
606
+ $customer = Mage::getModel('customer/customer');
607
+ $customer->setId(1);
608
+ $quote->setCustomer($customer);
609
+ $helperMock = $this->getHelperMock('ops/alias', array('cleanUpAdditionalInformation', 'setAliasToActiveAfterUserRegisters'));
610
+ $helperMock->expects($this->once())
611
+ ->method('setAliasToActiveAfterUserRegisters')
612
+ ->with($order, $quote);
613
+
614
+ $helperMock->setAliasActive($quote, $order);
615
+
616
+ }
617
+
618
+ /**
619
+ * @loadFixture ../../../var/fixtures/aliases.yaml
620
+ * @loadFixture ../../../var/fixtures/orders.yaml
621
+ */
622
+ public function testSetAliasToActiveAfterUserRegisters()
623
+ {
624
+ $order = Mage::getModel('sales/order')->load(11);
625
+ $order->setCustomerId(123);
626
+ $quote = Mage::getModel('sales/quote')->load(10);
627
+ $quote->setBillingAddress($this->getAddressData());
628
+ $quote->setShippingAddress($this->getAddressData());
629
+ $quote->getPayment()->setAdditionalInformation('alias', '4714');
630
+ $quote->getPayment()->setAdditionalInformation('opsAliasId','11111');
631
+ $quote->getPayment()->setAdditionalInformation('userIsRegistering',true);
632
+ $quote->setCheckoutMethod(Mage_Sales_Model_Quote::CHECKOUT_METHOD_REGISTER);
633
+ $quote->setStoreId(null);
634
+ $billingAddressHash = Mage::helper('ops/alias')->generateAddressHash($quote->getBillingAddress());
635
+ $shippingAddressHash = Mage::helper('ops/alias')->generateAddressHash($quote->getShippingAddress());
636
+
637
+ $oldAlias = Mage::getModel('ops/alias')->getCollection()
638
+ ->addFieldToFilter('alias', $quote->getPayment()->getAdditionalInformation('alias'))
639
+ ->addFieldToFilter('billing_address_hash', $billingAddressHash)
640
+ ->addFieldToFilter('shipping_address_hash', $shippingAddressHash)
641
+ ->getFirstItem();
642
+
643
+ Mage::helper('ops/alias')->setAliasToActiveAfterUserRegisters($order,$quote);
644
+ $testAlias = Mage::getModel('ops/alias')->load($oldAlias->getId());
645
+ $this->assertEquals(Netresearch_OPS_Model_Alias_State::ACTIVE, $testAlias->getState());
646
+ $this->assertEquals(123,$testAlias->getCustomerId());
647
+ }
648
+
649
+ /**
650
+ * @loadFixture ../../../var/fixtures/aliases.yaml
651
+ * @loadFixture ../../../var/fixtures/orders.yaml
652
+ */
653
+ public function testCleanUpAdditionalInformation()
654
+ {
655
+ $quote = Mage::getModel('sales/quote')->load(11);
656
+ $payment = $quote->getPayment();
657
+ $payment->setAdditionalInformation('cvc', 'cvctest');
658
+ $payment->setAdditionalInformation('storedOPSId', 'storedOPSIdTest');
659
+
660
+
661
+
662
+ $this->assertTrue(array_key_exists('cvc', $payment->getAdditionalInformation()));
663
+ $this->assertTrue(array_key_exists('storedOPSId', $payment->getAdditionalInformation()));
664
+
665
+ Mage::helper('ops/alias')->cleanUpAdditionalInformation($payment);
666
+
667
+ $this->assertTrue(is_array($payment->getAdditionalInformation()));
668
+ $this->assertFalse(array_key_exists('cvc' ,$payment->getAdditionalInformation()));
669
+ $this->assertFalse(array_key_exists('storedOPSId', $payment->getAdditionalInformation()));
670
+
671
+ $quote = Mage::getModel('sales/quote')->load(11);
672
+ $payment = $quote->getPayment();
673
+ $payment->setAdditionalInformation('cvc', 'cvctest');
674
+ $payment->setAdditionalInformation('storedOPSId', 'storedOPSIdTest');
675
+
676
+
677
+
678
+ $this->assertTrue(array_key_exists('cvc', $payment->getAdditionalInformation()));
679
+ $this->assertTrue(array_key_exists('storedOPSId', $payment->getAdditionalInformation()));
680
+
681
+ Mage::helper('ops/alias')->cleanUpAdditionalInformation($payment, true);
682
+
683
+ $this->assertTrue(is_array($payment->getAdditionalInformation()));
684
+ $this->assertFalse(array_key_exists('cvc' ,$payment->getAdditionalInformation()));
685
+ $this->assertTrue(array_key_exists('storedOPSId', $payment->getAdditionalInformation()));
686
+ }
687
+
688
+ /**
689
+ */
690
+ public function testCleanUpAdditionalInformationWithSave()
691
+ {
692
+ $payment = $this->getModelMock('sales/quote_payment', array('save'));
693
+ $payment->expects($this->once())
694
+ ->method('save')
695
+ ;
696
+
697
+ Mage::helper('ops/alias')->cleanUpAdditionalInformation($payment, true, true);
698
+
699
+ }
700
+ }
app/code/community/Netresearch/OPS/Test/Helper/AliasTest/fixtures/.gitkeep ADDED
File without changes
app/code/community/Netresearch/OPS/Test/Helper/ApiTest.php ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created by JetBrains PhpStorm.
4
+ * User: michael
5
+ * Date: 07.05.13
6
+ * Time: 16:55
7
+ * To change this template use File | Settings | File Templates.
8
+ */
9
+
10
+ class Netresearch_OPS_Test_Helper_ApiTest extends EcomDev_PHPUnit_Test_Case
11
+ {
12
+
13
+ public function testGetRedirectRouteFromStatus()
14
+ {
15
+ $helper = Mage::helper('ops/api');
16
+ $configModel = Mage::getModel('ops/config');
17
+ $successRoute = $configModel->getAcceptRedirectRoute();
18
+ $this->assertEquals(
19
+ $successRoute, $helper->getRedirectRouteFromStatus(
20
+ Netresearch_OPS_Model_Status_Feedback::OPS_ORDER_FEEDBACK_STATUS_ACCEPT
21
+ )
22
+ );
23
+
24
+ $cancelRoute = $configModel->getCancelRedirectRoute();
25
+ $this->assertEquals(
26
+ $cancelRoute, $helper->getRedirectRouteFromStatus(
27
+ Netresearch_OPS_Model_Status_Feedback::OPS_ORDER_FEEDBACK_STATUS_CANCEL
28
+ )
29
+ );
30
+
31
+ $declineRoute = $configModel->getDeclineRedirectRoute();
32
+ $this->assertEquals(
33
+ $declineRoute, $helper->getRedirectRouteFromStatus(
34
+ Netresearch_OPS_Model_Status_Feedback::OPS_ORDER_FEEDBACK_STATUS_DECLINE
35
+ )
36
+ );
37
+
38
+ $exceptionRoute = $configModel->getExceptionRedirectRoute();
39
+ $this->assertEquals(
40
+ $exceptionRoute, $helper->getRedirectRouteFromStatus(
41
+ Netresearch_OPS_Model_Status_Feedback::OPS_ORDER_FEEDBACK_STATUS_EXCEPTION
42
+ )
43
+ );
44
+
45
+ try {
46
+ $helper->getRedirectRouteFromStatus('');
47
+ } catch (Exception $e) {
48
+ $this->assertEquals('invalid status provided', $e->getMessage());
49
+ }
50
+ }
51
+
52
+ }
app/code/community/Netresearch/OPS/Test/Helper/DataTest.php ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Netresearch_OPS_Test_Helper_DataTest extends EcomDev_PHPUnit_Test_Case_Controller
3
+ {
4
+ protected $helper;
5
+ protected $store;
6
+
7
+ public function setUp()
8
+ {
9
+ parent::setup();
10
+ $this->helper = Mage::helper('ops');
11
+ $this->store = Mage::app()->getStore(0)->load(0);
12
+ }
13
+
14
+ /**
15
+ * @test
16
+ */
17
+ public function getModuleVersionString()
18
+ {
19
+ $path = 'modules/Netresearch_OPS/version';
20
+
21
+ Mage::getConfig()->setNode('modules/Netresearch_OPS/version', '120301');
22
+ $this->assertSame('OGmg120301', $this->helper->getModuleVersionString());
23
+
24
+ Mage::getConfig()->setNode('modules/Netresearch_OPS/version', '120612');
25
+ $this->assertSame('OGmg120612', $this->helper->getModuleVersionString());
26
+
27
+ $this->store->resetConfig();
28
+ }
29
+
30
+ public function testCheckIfUserIsRegistering()
31
+ {
32
+ $quote = new Varien_Object();
33
+ $quote->setCheckoutMethod(Mage_Sales_Model_Quote::CHECKOUT_METHOD_REGISTER);
34
+ $sessionMock = $this->getModelMock('checkout/session', array('getQuote'));
35
+ $sessionMock->expects($this->any())
36
+ ->method('getQuote')
37
+ ->will($this->returnValue($quote));
38
+ $this->replaceByMock('model', 'checkout/session', $sessionMock);
39
+
40
+
41
+ $this->assertTrue(Mage::helper('ops/data')->checkIfUserIsRegistering());
42
+
43
+ $quote->setCheckoutMethod(Mage_Sales_Model_Quote::CHECKOUT_METHOD_LOGIN_IN);
44
+ $this->assertTrue(Mage::helper('ops/data')->checkIfUserIsRegistering());
45
+
46
+ $quote->setCheckoutMethod(Mage_Sales_Model_Quote::CHECKOUT_METHOD_GUEST);
47
+ $this->assertFalse(Mage::helper('ops/data')->checkIfUserIsRegistering());
48
+
49
+ }
50
+
51
+ public function testCheckIfUserIsNotRegistering()
52
+ {
53
+ $quote = new Varien_Object();
54
+ $quote->setCheckoutMethod(Mage_Sales_Model_Quote::CHECKOUT_METHOD_REGISTER);
55
+ $sessionMock = $this->getModelMock('checkout/session', array('getQuote'));
56
+ $sessionMock->expects($this->any())
57
+ ->method('getQuote')
58
+ ->will($this->returnValue($quote));
59
+ $this->replaceByMock('model', 'checkout/session', $sessionMock);
60
+
61
+ $this->assertTrue(Mage::helper('ops/data')->checkIfUserIsNotRegistering());
62
+
63
+ $quote->setCheckoutMethod(Mage_Sales_Model_Quote::CHECKOUT_METHOD_LOGIN_IN);
64
+ $this->assertFalse(Mage::helper('ops/data')->checkIfUserIsNotRegistering());
65
+
66
+ $quote->setCheckoutMethod(Mage_Sales_Model_Quote::CHECKOUT_METHOD_GUEST);
67
+ $this->assertFalse(Mage::helper('ops/data')->checkIfUserIsNotRegistering());
68
+ }
69
+
70
+ public function testClearMsg()
71
+ {
72
+ $helper = Mage::helper('ops/data');
73
+ $testArray = array('cvc' => '1', 'CVC' => '2', 'test' => 'me');
74
+ $testArray = $helper->clearMsg($testArray);
75
+ $this->assertFalse(array_key_exists('cvc', $testArray));
76
+ $this->assertFalse(array_key_exists('CVC', $testArray));
77
+ $this->assertTrue(array_key_exists('test', $testArray));
78
+ $testString = '{"CVC":"123"}';
79
+ $this->assertFalse(strpos($helper->clearMsg($testString), 'CVC'));
80
+ $testString = '{"CVC":"123","CN":"Some Name"}';
81
+ $this->assertFalse(strpos($helper->clearMsg($testString), 'CVC'));
82
+ $testString = '{"cvc":"123","CN":"Some Name"}';
83
+ $this->assertFalse(strpos($helper->clearMsg($testString), 'cvc'));
84
+ $this->assertTrue(false !== strpos($helper->clearMsg($testString), 'CN'));
85
+
86
+ $testString = 'a:3:{s:5:"Alias";s:14:"10290855992990";s:3:"CVC";s:3:"777";s:2:"CN";s:13:"Homer Simpson";}';
87
+ $this->assertFalse(strpos($helper->clearMsg($testString), 'CVC'));
88
+ $this->assertTrue(false !== strpos($helper->clearMsg($testString), 'Homer'));
89
+ }
90
+ }
91
+
app/code/community/Netresearch/OPS/Test/Helper/DirectDebitTest.php ADDED
@@ -0,0 +1,500 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Michael Lühr <michael.luehr@netresearch.de>
4
+ * @category Netresearch
5
+ * @package Netresearch_OPS
6
+ * @copyright Copyright (c) 2013 Netresearch GmbH & Co. KG (http://www.netresearch.de)
7
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
8
+ */
9
+
10
+
11
+ class Netresearch_OPS_Test_Helper_DirectDebitTest
12
+ extends EcomDev_PHPUnit_Test_Case
13
+ {
14
+
15
+ protected function getDirectDebitHelper()
16
+ {
17
+ return Mage::helper('ops/directDebit');
18
+ }
19
+
20
+ public function testGetDataHelper()
21
+ {
22
+ $this->assertTrue(
23
+ $this->getDirectDebitHelper()->getDataHelper() instanceof
24
+ Netresearch_OPS_Helper_Data
25
+ );
26
+ }
27
+
28
+ public function testGetQuoteHelper()
29
+ {
30
+ $this->assertTrue(
31
+ $this->getDirectDebitHelper()->getQuoteHelper() instanceof
32
+ Netresearch_OPS_Helper_Quote
33
+ );
34
+ }
35
+
36
+ public function testGetOrderHelper()
37
+ {
38
+ $this->assertTrue(
39
+ $this->getDirectDebitHelper()->getOrderHelper() instanceof
40
+ Netresearch_OPS_Helper_Order
41
+ );
42
+ }
43
+
44
+ public function testGetCustomerHelper()
45
+ {
46
+ $this->assertTrue(
47
+ $this->getDirectDebitHelper()->getCustomerHelper() instanceof
48
+ Mage_Customer_Helper_Data
49
+ );
50
+ }
51
+
52
+ public function testGetValidator()
53
+ {
54
+ $this->assertTrue(
55
+ $this->getDirectDebitHelper()->getValidator() instanceof
56
+ Netresearch_OPS_Model_Validator_Payment_DirectDebit
57
+ );
58
+ }
59
+
60
+ public function testGetCountry()
61
+ {
62
+ $helper = $this->getDirectDebitHelper();
63
+ $params = array();
64
+ $this->assertEquals('', $helper->getCountry($params));
65
+ $params['country'] = 'de';
66
+ $this->assertEquals('DE', $helper->getCountry($params));
67
+ }
68
+
69
+ public function testHasIban()
70
+ {
71
+ $helper = $this->getDirectDebitHelper();
72
+ $params = array();
73
+ $this->assertFalse($helper->hasIban($params));
74
+ $params['iban'] = '';
75
+ $this->assertFalse($helper->hasIban($params));
76
+ $params['iban'] = ' ';
77
+ $this->assertFalse($helper->hasIban($params));
78
+ $params['iban'] = '123456789';
79
+ $this->assertTrue($helper->hasIban($params));
80
+ }
81
+
82
+ public function testSetDirectDebitDataToPayment()
83
+ {
84
+ $payment = Mage::getModel('sales/quote_payment');
85
+ $helper = $this->getDirectDebitHelper();
86
+ $params = array('country' => 'de', 'account' => '', 'bankcode' => '');
87
+ $helper->setDirectDebitDataToPayment($payment, $params);
88
+ $this->assertEquals(
89
+ 'Direct Debits DE', $payment->getAdditionalInformation('PM')
90
+ );
91
+
92
+ $params = array(
93
+ 'country' => 'de', 'CN' => 'Account Holder', 'account' => '',
94
+ 'bankcode' => ''
95
+ );
96
+ $helper->setDirectDebitDataToPayment($payment, $params);
97
+ $this->assertEquals(
98
+ 'Account Holder', $payment->getAdditionalInformation('CN')
99
+ );
100
+
101
+ $params = array(
102
+ 'country' => 'nl', 'CN' => 'Account Holder',
103
+ 'account' => '1234567', 'bankcode' => ''
104
+ );
105
+ $helper->setDirectDebitDataToPayment($payment, $params);
106
+ $this->assertEquals(
107
+ '1234567', $payment->getAdditionalInformation('CARDNO')
108
+ );
109
+
110
+ $params = array(
111
+ 'country' => 'at', 'CN' => 'Account Holder',
112
+ 'account' => '1234567', 'bankcode' => '1234567'
113
+ );
114
+ $helper->setDirectDebitDataToPayment($payment, $params);
115
+ $this->assertEquals(
116
+ '1234567BLZ1234567', $payment->getAdditionalInformation('CARDNO')
117
+ );
118
+
119
+ $params = array(
120
+ 'country' => 'de', 'CN' => 'Account Holder',
121
+ 'account' => '1234567', 'bankcode' => '1234567'
122
+ );
123
+ $helper->setDirectDebitDataToPayment($payment, $params);
124
+ $this->assertEquals(
125
+ '1234567BLZ1234567', $payment->getAdditionalInformation('CARDNO')
126
+ );
127
+
128
+ $params = array(
129
+ 'country' => 'de', 'CN' => 'Account Holder',
130
+ 'iban' => 'DE1234567890', 'account' => '1234567',
131
+ 'bankcode' => '1234567'
132
+ );
133
+ $helper->setDirectDebitDataToPayment($payment, $params);
134
+ $this->assertEquals(
135
+ 'DE1234567890', $payment->getAdditionalInformation('CARDNO')
136
+ );
137
+
138
+ $params = array(
139
+ 'country' => 'at', 'CN' => 'Account Holder',
140
+ 'iban' => 'DE1234567890', 'account' => '1234567',
141
+ 'bankcode' => '1234567'
142
+ );
143
+ $helper->setDirectDebitDataToPayment($payment, $params);
144
+ $this->assertEquals(
145
+ '1234567BLZ1234567', $payment->getAdditionalInformation('CARDNO')
146
+ );
147
+
148
+ $params = array(
149
+ 'country' => 'nl', 'CN' => 'Account Holder',
150
+ 'iban' => 'NL1234567890', 'bic' => '12345678',
151
+ 'account' => '1234567', 'bankcode' => '1234567'
152
+ );
153
+ $helper->setDirectDebitDataToPayment($payment, $params);
154
+ $this->assertEquals(
155
+ 'NL1234567890', $payment->getAdditionalInformation('CARDNO')
156
+ );
157
+ $this->assertEquals(
158
+ '12345678', $payment->getAdditionalInformation('BIC')
159
+ );
160
+ }
161
+
162
+ /**
163
+ * @loadFixture ../../../var/fixtures/orders.yaml
164
+ */
165
+ public function testGetDirectLinkRequestParams()
166
+ {
167
+
168
+ $store = Mage::app()->getStore(0)->load(0);
169
+ $store->resetConfig();
170
+
171
+ $store->setConfig(
172
+ 'payment_services/ops/inlineOrderReference',
173
+ Netresearch_OPS_Model_Payment_Abstract::REFERENCE_QUOTE_ID
174
+ );
175
+
176
+ $quote = Mage::getModel('sales/quote')->load(10);
177
+ $order = Mage::getModel('sales/order')->load(11);
178
+ $dataHelper = $this->getHelperMock('ops/data', array('isAdminSession'));
179
+ $dataHelper->expects($this->any())
180
+ ->method('isAdminSession')
181
+ ->will($this->returnValue(false));
182
+
183
+ $customerHelper = $this->getHelperMock(
184
+ 'customer/data', array('isLoggedIn')
185
+ );
186
+ $customerHelper->expects($this->any())
187
+ ->method('isLoggedIn')
188
+ ->will($this->returnValue(false));
189
+
190
+ $quoteHelper = $this->getHelperMock(
191
+ 'ops/quote', array('getPaymentAction', 'getQuoteCurrency')
192
+ );
193
+ $quoteHelper->expects($this->any())
194
+ ->method('getPaymentAction')
195
+ ->will($this->returnValue('RES'));
196
+ $quoteHelper->expects($this->any())
197
+ ->method('getQuoteCurrency')
198
+ ->will($this->returnValue('EUR'));
199
+
200
+ $orderHelper = $this->getHelperMock(
201
+ 'ops/order', array('checkIfAddressesAreSame')
202
+ );
203
+ $orderHelper->expects($this->any())
204
+ ->method('checkIfAddressesAreSame')
205
+ ->will($this->returnValue(1));
206
+
207
+ $helper = $this->getDirectDebitHelper();
208
+ $helper->setDataHelper($dataHelper);
209
+ $helper->setCustomerHelper($customerHelper);
210
+ $helper->setQuoteHelper($quoteHelper);
211
+ $helper->setOrderHelper($orderHelper);
212
+ $this->assertEquals(
213
+ $this->getExpectedResultOnFrontendRequest($order),
214
+ $helper->getDirectLinkRequestParams($quote, $order)
215
+ );
216
+ }
217
+
218
+ /**
219
+ * @loadFixture ../../../var/fixtures/orders.yaml
220
+ */
221
+ public function testGetDirectLinkRequestParamsWithNoShippingAddress()
222
+ {
223
+ $quote = Mage::getModel('sales/quote')->load(10);
224
+ $order = Mage::getModel('sales/order')->load(28);
225
+ $dataHelper = $this->getHelperMock('ops/data', array('isAdminSession'));
226
+ $dataHelper->expects($this->any())
227
+ ->method('isAdminSession')
228
+ ->will($this->returnValue(false));
229
+
230
+ $customerHelper = $this->getHelperMock(
231
+ 'customer/data', array('isLoggedIn')
232
+ );
233
+ $customerHelper->expects($this->any())
234
+ ->method('isLoggedIn')
235
+ ->will($this->returnValue(false));
236
+
237
+ $quoteHelper = $this->getHelperMock(
238
+ 'ops/quote', array('getPaymentAction', 'getQuoteCurrency')
239
+ );
240
+ $quoteHelper->expects($this->any())
241
+ ->method('getPaymentAction')
242
+ ->will($this->returnValue('RES'));
243
+ $quoteHelper->expects($this->any())
244
+ ->method('getQuoteCurrency')
245
+ ->will($this->returnValue('EUR'));
246
+
247
+ $configMock = $this->getModelMock('ops/config', array('canSubmitExtraParameter'));
248
+ $configMock->expects($this->any())
249
+ ->method('canSubmitExtraParameter')
250
+ ->will($this->returnValue(true));
251
+
252
+ $helper = $this->getDirectDebitHelper();
253
+ $helper->setConfig($configMock);
254
+ $helper->getRequestHelper()->setConfig($configMock);
255
+ $helper->setDataHelper($dataHelper);
256
+ $helper->setCustomerHelper($customerHelper);
257
+ $helper->setQuoteHelper($quoteHelper);
258
+
259
+ $result = $helper->getDirectLinkRequestParams($quote, $order);
260
+ $this->assertEquals(
261
+ '04227',
262
+ $result['ECOM_SHIPTO_POSTAL_POSTALCODE']
263
+ );
264
+ }
265
+
266
+ /**
267
+ * @loadFixture ../../../var/fixtures/orders.yaml
268
+ */
269
+ public function testGetDirectLinkRequestParamsWithLoggedInCustomer()
270
+ {
271
+ $quote = Mage::getModel('sales/quote')->load(10);
272
+ $order = Mage::getModel('sales/order')->load(28);
273
+ $dataHelper = $this->getHelperMock('ops/data', array('isAdminSession'));
274
+ $dataHelper->expects($this->any())
275
+ ->method('isAdminSession')
276
+ ->will($this->returnValue(false));
277
+
278
+ $fakeCustomer = new Varien_Object();
279
+ $fakeCustomer->setId(666);
280
+ $customerHelper = $this->getHelperMock(
281
+ 'customer/data', array('isLoggedIn', 'getCustomer')
282
+ );
283
+ $customerHelper->expects($this->any())
284
+ ->method('isLoggedIn')
285
+ ->will($this->returnValue(true));
286
+ $customerHelper->expects($this->any())
287
+ ->method('getCustomer')
288
+ ->will($this->returnValue($fakeCustomer));
289
+
290
+ $quoteHelper = $this->getHelperMock(
291
+ 'ops/quote', array('getPaymentAction', 'getQuoteCurrency')
292
+ );
293
+ $quoteHelper->expects($this->any())
294
+ ->method('getPaymentAction')
295
+ ->will($this->returnValue('RES'));
296
+ $quoteHelper->expects($this->any())
297
+ ->method('getQuoteCurrency')
298
+ ->will($this->returnValue('EUR'));
299
+ $configMock = $this->getModelMock('ops/config', array('canSubmitExtraParameter'));
300
+ $configMock->expects($this->any())
301
+ ->method('canSubmitExtraParameter')
302
+ ->will($this->returnValue(true));
303
+ $helper = $this->getDirectDebitHelper();
304
+ $helper->setConfig($configMock);
305
+ $helper->getRequestHelper()->setConfig($configMock);
306
+ $helper->setDataHelper($dataHelper);
307
+ $helper->setCustomerHelper($customerHelper);
308
+ $helper->setQuoteHelper($quoteHelper);
309
+
310
+ $result = $helper->getDirectLinkRequestParams($quote, $order);
311
+ $this->assertEquals(666, $result['CUID']);
312
+ }
313
+
314
+
315
+ /**
316
+ * @loadFixture ../../../var/fixtures/orders.yaml
317
+ */
318
+ public function testGetDirectLinkRequestParamsForBackendOrder()
319
+ {
320
+ $quote = Mage::getModel('sales/quote')->load(10);
321
+ $order = Mage::getModel('sales/order')->load(11);
322
+
323
+ $validator = $this->getModelMock(
324
+ 'ops/validator_payment_directDebit', array('isValid')
325
+ );
326
+ $validator->expects($this->any())
327
+ ->method('isValid')
328
+ ->will($this->returnValue(true));
329
+
330
+ $dataHelper = $this->getHelperMock('ops/data', array('isAdminSession'));
331
+ $dataHelper->expects($this->any())
332
+ ->method('isAdminSession')
333
+ ->will($this->returnValue(true));
334
+
335
+ $customerHelper = $this->getHelperMock(
336
+ 'customer/data', array('isLoggedIn')
337
+ );
338
+ $customerHelper->expects($this->any())
339
+ ->method('isLoggedIn')
340
+ ->will($this->returnValue(false));
341
+
342
+ $quoteHelper = $this->getHelperMock(
343
+ 'ops/quote', array('getPaymentAction', 'getQuoteCurrency')
344
+ );
345
+ $quoteHelper->expects($this->any())
346
+ ->method('getPaymentAction')
347
+ ->will($this->returnValue('RES'));
348
+ $quoteHelper->expects($this->any())
349
+ ->method('getQuoteCurrency')
350
+ ->will($this->returnValue('EUR'));
351
+
352
+ $orderHelper = $this->getHelperMock(
353
+ 'ops/order', array('checkIfAddressesAreSame')
354
+ );
355
+ $orderHelper->expects($this->any())
356
+ ->method('checkIfAddressesAreSame')
357
+ ->will($this->returnValue(1));
358
+
359
+ $helper = $this->getDirectDebitHelper();
360
+ $helper->setDataHelper($dataHelper);
361
+ $helper->setCustomerHelper($customerHelper);
362
+ $helper->setQuoteHelper($quoteHelper);
363
+ $helper->setOrderHelper($orderHelper);
364
+ $helper->setValidator($validator);
365
+
366
+ $params = array(
367
+ 'country' => 'DE', 'CN' => 'Hans Wurst', 'account' => '4711',
368
+ 'bankcode' => '0815'
369
+ );
370
+ $helper->handleAdminPayment($quote, $params);
371
+ $result = $helper->getDirectLinkRequestParams($quote, $order, $params);
372
+ $this->assertEquals('Direct Debits DE', $result['PM']);
373
+ $this->assertEquals('Hans Wurst', $result['CN']);
374
+ $this->assertEquals($result['PM'], $result['BRAND']);
375
+ $this->assertEquals('4711BLZ0815', $result['CARDNO']);
376
+ $this->assertEquals(1, $result['ECI']);
377
+
378
+ $params = array(
379
+ 'country' => 'DE', 'CN' => 'Hans Wurst', 'account' => '4711',
380
+ 'bankcode' => '0815', 'bic' => '4712', 'iban' => '0816'
381
+ );
382
+ $helper->handleAdminPayment($quote, $params);
383
+ $result = $helper->getDirectLinkRequestParams($quote, $order, $params);
384
+ $this->assertEquals('0816', $result['CARDNO']);
385
+ $this->assertArrayNotHasKey('BIC', $result);
386
+
387
+ $params = array(
388
+ 'country' => 'NL', 'CN' => 'Hans Wurst', 'account' => '4711',
389
+ 'bankcode' => '0815', 'bic' => '4712', 'iban' => '0816'
390
+ );
391
+ $helper->handleAdminPayment($quote, $params);
392
+ $result = $helper->getDirectLinkRequestParams($quote, $order, $params);
393
+ $this->assertEquals('0816', $result['CARDNO']);
394
+ $this->assertArrayHasKey('BIC', $result);
395
+ $this->assertEquals('4712', $result['BIC']);
396
+
397
+ $params = array(
398
+ 'country' => 'NL', 'CN' => 'Hans Wurst', 'account' => '4711',
399
+ 'bankcode' => '0815', 'bic' => '', 'iban' => '0816'
400
+ );
401
+ $quote->getPayment()->setAdditionalInformation('PM', 'Direct Debits NL');
402
+ $helper->handleAdminPayment($quote, $params);
403
+ $result = $helper->getDirectLinkRequestParams($quote, $order, $params);
404
+ $this->assertArrayNotHasKey('BIC', $result);
405
+
406
+ $params = array(
407
+ 'country' => 'DE', 'CN' => 'Hans Wurst', 'account' => '4711',
408
+ 'bankcode' => '0815', 'bic' => '', 'iban' => '0816'
409
+ );
410
+ $quote->getPayment()->setAdditionalInformation('PM', 'Direct Debits DE');
411
+ $helper->handleAdminPayment($quote, $params);
412
+ $result = $helper->getDirectLinkRequestParams($quote, $order, $params);
413
+ $this->assertArrayNotHasKey('BIC', $result);
414
+ }
415
+
416
+
417
+ /**
418
+ * @loadFixture ../../../var/fixtures/orders.yaml
419
+ */
420
+ public function testGetDirectLinkRequestParamsForBackendOrderThrowsException(
421
+ )
422
+ {
423
+ $sessionMock = $this->getModelMock(
424
+ 'adminhtml/session', array('init', 'save')
425
+ );
426
+ $this->replaceByMock('model', 'adminhtml/session', $sessionMock);
427
+
428
+ $quote = Mage::getModel('sales/quote')->load(10);
429
+ $order = Mage::getModel('sales/order')->load(11);
430
+
431
+ $validator = $this->getModelMock(
432
+ 'ops/validator_payment_directDebit', array('isValid', 'getMessages')
433
+ );
434
+ $validator->expects($this->any())
435
+ ->method('isValid')
436
+ ->will($this->returnValue(false));
437
+ $validator->expects($this->any())
438
+ ->method('getMessages')
439
+ ->will($this->returnValue(array('foo', 'bar')));
440
+
441
+ $dataHelper = $this->getHelperMock('ops/data', array('isAdminSession'));
442
+ $dataHelper->expects($this->any())
443
+ ->method('isAdminSession')
444
+ ->will($this->returnValue(true));
445
+
446
+ $helper = $this->getDirectDebitHelper();
447
+ $helper->setDataHelper($dataHelper);
448
+ $helper->setValidator($validator);
449
+
450
+ $params = array(
451
+ 'country' => 'DE', 'CN' => 'Hans Wurst', 'account' => '4711',
452
+ 'bankcode' => '0815'
453
+ );
454
+ try {
455
+ $helper->getDirectLinkRequestParams(
456
+ $quote, $order, $params
457
+ );
458
+ } catch (Exception $e) {
459
+
460
+ }
461
+ }
462
+
463
+ protected function getExpectedResultOnFrontendRequest($order)
464
+ {
465
+ return array(
466
+ 'AMOUNT' => 0.0,
467
+ 'CARDNO' => NULL,
468
+ 'CN' => utf8_decode(""),
469
+ 'CURRENCY' => "EUR",
470
+ 'ED' => "9999",
471
+ 'OPERATION' => "RES",
472
+ 'ORDERID' => Mage::getModel('ops/config')->getConfigData('devprefix') . $order->getQuoteId(),
473
+ 'PM' => NULL,
474
+ 'OWNERADDRESS' => utf8_decode(
475
+ "An der Tabaksmühle 3a"
476
+ ),
477
+ 'OWNERTOWN' => utf8_decode("Leipzig"),
478
+ 'OWNERZIP' => "04229",
479
+ 'OWNERTELNO' => NULL,
480
+ 'OWNERCTY' => "DE",
481
+ 'ADDMATCH' => 1,
482
+ 'ECOM_SHIPTO_POSTAL_POSTALCODE' => "04229",
483
+ 'ECOM_BILLTO_POSTAL_POSTALCODE' => "04229",
484
+ 'ORIG' => Mage::helper("ops")->getModuleVersionString(),
485
+ 'BRAND' => NULL,
486
+ 'ECOM_SHIPTO_POSTAL_NAME_FIRST' => 'Hubertus',
487
+ 'ECOM_SHIPTO_POSTAL_NAME_LAST' => utf8_decode('Fürstenberg'),
488
+ 'ECOM_SHIPTO_POSTAL_STREET_LINE1' => utf8_decode('An der Tabaksmühle 3a'),
489
+ 'ECOM_SHIPTO_POSTAL_STREET_LINE2' => '',
490
+ 'ECOM_SHIPTO_POSTAL_COUNTRYCODE' => 'DE',
491
+ 'ECOM_SHIPTO_POSTAL_CITY' => 'Leipzig',
492
+ 'EMAIL' => 'hubertus.von.fuerstenberg@trash-mail.com',
493
+ 'REMOTE_ADDR' => null,
494
+ 'ECOM_SHIPTO_POSTAL_STATE' => ''
495
+ );
496
+
497
+ }
498
+
499
+
500
+ }
app/code/community/Netresearch/OPS/Test/Helper/DirectDebitTest/fixtures/.gitkeep ADDED
File without changes
app/code/community/Netresearch/OPS/Test/Helper/DirectLinkTest.php ADDED
@@ -0,0 +1,529 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Netresearch_OPS_Test_Helper_DirectLinkTest extends EcomDev_PHPUnit_Test_Case
3
+ {
4
+ public function setUp()
5
+ {
6
+ parent::setup();
7
+ $this->_helper = Mage::helper('ops/directlink');
8
+ $transaction = Mage::getModel('sales/order_payment_transaction');
9
+ $transaction->setAdditionalInformation('arrInfo', serialize(array(
10
+ 'amount' => '184.90'
11
+ )));
12
+ $transaction->setIsClosed(0);
13
+ $this->_transaction = $transaction;
14
+ $this->_order = Mage::getModel('sales/order');
15
+ $this->_order->setGrandTotal('184.90');
16
+ $this->_order->setBaseGrandTotal('184.90');
17
+ }
18
+
19
+ public function testDeleteActions()
20
+ {
21
+ $this->assertFalse($this->_helper->isValidOpsRequest($this->_transaction, $this->_order, array('STATUS'=>Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_DELETED)));
22
+ $this->assertFalse($this->_helper->isValidOpsRequest($this->_transaction, $this->_order, array('STATUS'=>Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_DELETED_WAITING)));
23
+ $this->assertFalse($this->_helper->isValidOpsRequest($this->_transaction, $this->_order, array('STATUS'=>Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_DELETED_UNCERTAIN)));
24
+ $this->assertFalse($this->_helper->isValidOpsRequest($this->_transaction, $this->_order, array('STATUS'=>Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_DELETED_REFUSED)));
25
+ $this->assertFalse($this->_helper->isValidOpsRequest($this->_transaction, $this->_order, array('STATUS'=>Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_DELETED_OK)));
26
+ $this->assertFalse($this->_helper->isValidOpsRequest($this->_transaction, $this->_order, array('STATUS'=>Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_DELETED_PROCESSED_MERCHANT)));
27
+ }
28
+
29
+ public function testRefundActions()
30
+ {
31
+ $opsRequest = array(
32
+ 'STATUS' => Netresearch_OPS_Model_Payment_Abstract::OPS_REFUNDED,
33
+ 'amount' => '184.90'
34
+ );
35
+ $this->assertFalse($this->_helper->isValidOpsRequest(null, $this->_order, $opsRequest), 'Refund should not be possible without open transactions');
36
+ $this->assertTrue($this->_helper->isValidOpsRequest($this->_transaction, $this->_order, $opsRequest), 'Refund should be possible with open transactions');
37
+ $opsRequest['amount'] = '14.90';
38
+ $this->assertFalse($this->_helper->isValidOpsRequest($this->_transaction, $this->_order, $opsRequest), 'Refund should NOT be possible because of differing amount');
39
+ }
40
+
41
+ public function testCancelActions()
42
+ {
43
+ $opsRequest = array(
44
+ 'STATUS' => Netresearch_OPS_Model_Payment_Abstract::OPS_VOIDED,
45
+ 'amount' => '184.90'
46
+ );
47
+ $this->assertFalse($this->_helper->isValidOpsRequest(null, $this->_order, $opsRequest), 'Cancel should not be possible without open transactions');
48
+ $this->assertTrue($this->_helper->isValidOpsRequest($this->_transaction, $this->_order, $opsRequest), 'Cancel should be possible with open transactions');
49
+ $opsRequest['amount'] = '14.90';
50
+ $this->assertFalse($this->_helper->isValidOpsRequest($this->_transaction, $this->_order, $opsRequest), 'Cancel should NOT be possible because of differing amount');
51
+ }
52
+
53
+ public function testCaptureActions()
54
+ {
55
+ $opsRequest = array(
56
+ 'STATUS' => Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_REQUESTED,
57
+ 'amount' => '184.90'
58
+ );
59
+ $this->assertTrue($this->_helper->isValidOpsRequest(null, $this->_order, $opsRequest), 'Capture should be possible because of no open transactions and matching amount');
60
+ $opsRequest['amount'] = '14.90';
61
+ $this->assertFalse($this->_helper->isValidOpsRequest($this->_transaction, $this->_order, $opsRequest), 'Capture should NOT be possible because of differing amount');
62
+ }
63
+
64
+ public function testCleanupParameters()
65
+ {
66
+ $expected = 123.45;
67
+ $result = $this->_helper->formatAmount('123.45');
68
+ $this->assertEquals($expected, $result);
69
+
70
+ $result = $this->_helper->formatAmount('\'123.45\'');
71
+ $this->assertEquals($expected, $result);
72
+
73
+ $result = $this->_helper->formatAmount('"123.45"');
74
+ $this->assertEquals($expected, $result);
75
+
76
+ $expected = $this->_helper->formatAmount(0.3);
77
+ $result = $this->_helper->formatAmount(0.1 + 0.2);
78
+ $this->assertEquals($expected . '', $result . '');
79
+ $this->assertEquals((float) $expected, (float) $result);
80
+ }
81
+
82
+ /**
83
+ * @loadFixture ../../../var/fixtures/orders.yaml
84
+ */
85
+ public function testProcessFeedbackCaptureSuccess()
86
+ {
87
+
88
+ $order = Mage::getModel('sales/order')->load(11);
89
+ $directlinkHelperMock = $this->getHelperMock('ops/directlink', array('isValidOpsRequest'));
90
+ $directlinkHelperMock->expects($this->any())
91
+ ->method('isValidOpsRequest')
92
+ ->will($this->returnValue(true));
93
+
94
+ $closure = function ($order, $params = array()) {
95
+ $order->getPayment()->setAdditionalInformation('status', 9);
96
+ return $order->getPayment();
97
+ };
98
+
99
+ $captureHelper = $this->getHelperMock('ops/order_capture', array('acceptCapture'));
100
+ $captureHelper->expects($this->any())
101
+ ->method('acceptCapture')
102
+ ->will($this->returnCallback($closure));
103
+ $this->replaceByMock('helper', 'ops/order_capture', $captureHelper);
104
+ $params = array('STATUS' => Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_REQUESTED);
105
+ $directlinkHelperMock->processFeedback($order, $params);
106
+ $this->assertEquals(9, $order->getPayment()->getAdditionalInformation('status'));
107
+ }
108
+
109
+ /**
110
+ * @loadFixture ../../../var/fixtures/orders.yaml
111
+ */
112
+ public function testProcessFeedbackRefundSuccess()
113
+ {
114
+
115
+ $order = Mage::getModel('sales/order')->load(11);
116
+ $directlinkHelperMock = $this->getHelperMock('ops/directlink', array('isValidOpsRequest'));
117
+ $directlinkHelperMock->expects($this->any())
118
+ ->method('isValidOpsRequest')
119
+ ->will($this->returnValue(true));
120
+
121
+
122
+
123
+ $closure = function ($order, $params = array()) {
124
+ $order->getPayment()->setAdditionalInformation('status', 8);
125
+ return $order->getPayment();
126
+ };
127
+
128
+ $refundHelper = $this->getHelperMock('ops/order_refund', array('createRefund'));
129
+ $refundHelper->expects($this->any())
130
+ ->method('createRefund')
131
+ ->will($this->returnCallback($closure));
132
+ $this->replaceByMock('helper', 'ops/order_refund', $refundHelper);
133
+ $params = array('STATUS' => Netresearch_OPS_Model_Payment_Abstract::OPS_REFUNDED, 'PAYID' => '4711');
134
+ $directlinkHelperMock->processFeedback($order, $params);
135
+ $this->assertEquals($params['STATUS'], $order->getPayment()->getAdditionalInformation('status'));
136
+ }
137
+
138
+
139
+ /**
140
+ * @loadFixture ../../../var/fixtures/orders.yaml
141
+ */
142
+ public function testProcessFeedbackRefundWithStatusEightyFiveSuccess()
143
+ {
144
+ $order = Mage::getModel('sales/order')->load(11);
145
+ $directlinkHelperMock = $this->getHelperMock('ops/directlink', array('isValidOpsRequest'));
146
+ $directlinkHelperMock->expects($this->any())
147
+ ->method('isValidOpsRequest')
148
+ ->will($this->returnValue(true));
149
+
150
+
151
+
152
+ $closure = function ($order, $params = array()) {
153
+ $order->getPayment()->setAdditionalInformation('status', Netresearch_OPS_Model_Payment_Abstract::OPS_REFUND_PROCESSED_MERCHANT);
154
+ return $order->getPayment();
155
+ };
156
+
157
+ $refundHelper = $this->getHelperMock('ops/order_refund', array('createRefund'));
158
+ $refundHelper->expects($this->any())
159
+ ->method('createRefund')
160
+ ->will($this->returnCallback($closure));
161
+ $this->replaceByMock('helper', 'ops/order_refund', $refundHelper);
162
+ $params = array('STATUS' => Netresearch_OPS_Model_Payment_Abstract::OPS_REFUND_PROCESSED_MERCHANT, 'PAYID' => '4711');
163
+ $directlinkHelperMock->processFeedback($order, $params);
164
+ $this->assertEquals($params['STATUS'], $order->getPayment()->getAdditionalInformation('status'));
165
+ }
166
+
167
+ /**
168
+ * @loadFixture ../../../var/fixtures/orders.yaml
169
+ */
170
+ public function testProcessFeedbackPaymentWaiting()
171
+ {
172
+ /** @var Mage_Sales_Model_Order $order */
173
+ $order = Mage::getModel('sales/order')->load(11);
174
+ $directlinkHelperMock = $this->getHelperMock('ops/directlink', array('isValidOpsRequest'));
175
+ $directlinkHelperMock->expects($this->any())
176
+ ->method('isValidOpsRequest')
177
+ ->will($this->returnValue(true));
178
+
179
+ $cntBefore = $order->getStatusHistoryCollection()->count();
180
+
181
+
182
+ $closure = function ($order, $params = array()) {
183
+ $order->getPayment()->setAdditionalInformation('status', Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_PROCESSING);
184
+ return $order->getPayment();
185
+ };
186
+
187
+ $params = array('STATUS' => Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_PROCESSING, 'PAYID' => '4711');
188
+ $directlinkHelperMock->processFeedback($order, $params);
189
+ $cntAfter = $order->getStatusHistoryCollection()->count();
190
+ $this->assertTrue($cntBefore < $cntAfter);
191
+ }
192
+
193
+ /**
194
+ * @loadFixture ../../../var/fixtures/orders.yaml
195
+ */
196
+ public function testProcessFeedbackPaymentRefused()
197
+ {
198
+ /** @var Mage_Sales_Model_Order $order */
199
+ $order = Mage::getModel('sales/order')->load(11);
200
+ $directlinkHelperMock = $this->getHelperMock(
201
+ 'ops/directlink',
202
+ array('isValidOpsRequest', 'closePaymentTransaction')
203
+ );
204
+ $directlinkHelperMock->expects($this->any())
205
+ ->method('isValidOpsRequest')
206
+ ->will($this->returnValue(true));
207
+
208
+ $closure = function ($order, $params = array()) {
209
+ $order->getPayment()->setAdditionalInformation(
210
+ 'status',
211
+ Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_REFUSED
212
+ );
213
+ return $order->getPayment();
214
+ };
215
+
216
+ $params = array('STATUS' => Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_REFUSED, 'PAYID' => '4711');
217
+
218
+ $directlinkHelperMock->expects($this->once())
219
+ ->method('closePaymentTransaction')
220
+ ->with(
221
+ $order,
222
+ $params,
223
+ Netresearch_OPS_Model_Payment_Abstract::OPS_CAPTURE_TRANSACTION_TYPE,
224
+ Mage::helper('ops')->__(
225
+ 'Capture was refused. Automatic creation failed. Ingenico Payment Services status: %s.',
226
+ Mage::helper('ops')->getStatusText($params['STATUS'])
227
+ )
228
+ );
229
+
230
+ $directlinkHelperMock->processFeedback($order, $params);
231
+ }
232
+
233
+ /**
234
+ * @loadFixture ../../../var/fixtures/orders.yaml
235
+ */
236
+ public function testProcessFeedbackRefundWaiting()
237
+ {
238
+ /** @var Mage_Sales_Model_Order $order */
239
+ $order = Mage::getModel('sales/order')->load(11);
240
+ $directlinkHelperMock = $this->getHelperMock('ops/directlink', array('isValidOpsRequest'));
241
+ $directlinkHelperMock->expects($this->any())
242
+ ->method('isValidOpsRequest')
243
+ ->will($this->returnValue(true));
244
+
245
+ $cntBefore = $order->getStatusHistoryCollection()->count();
246
+
247
+
248
+ $closure = function ($order, $params = array()) {
249
+ $order->getPayment()->setAdditionalInformation('status', Netresearch_OPS_Model_Payment_Abstract::OPS_REFUND_WAITING);
250
+ return $order->getPayment();
251
+ };
252
+
253
+ $refundHelper = $this->getHelperMock('ops/order_refund', array('createRefund'));
254
+ $refundHelper->expects($this->any())
255
+ ->method('createRefund')
256
+ ->will($this->returnCallback($closure));
257
+ $this->replaceByMock('helper', 'ops/order_refund', $refundHelper);
258
+ $params = array('STATUS' => Netresearch_OPS_Model_Payment_Abstract::OPS_REFUND_WAITING, 'PAYID' => '4711');
259
+ $directlinkHelperMock->processFeedback($order, $params);
260
+ $cntAfter = $order->getStatusHistoryCollection()->count();
261
+ $this->assertTrue($cntBefore < $cntAfter);
262
+
263
+ }
264
+
265
+ /**
266
+ * @loadFixture ../../../var/fixtures/orders.yaml
267
+ */
268
+ public function testProcessFeedbackRefundRefused()
269
+ {
270
+ /** @var Mage_Sales_Model_Order $order */
271
+ $order = Mage::getModel('sales/order')->load(11);
272
+ $directlinkHelperMock = $this->getHelperMock(
273
+ 'ops/directlink',
274
+ array('isValidOpsRequest', 'closePaymentTransaction')
275
+ );
276
+ $directlinkHelperMock->expects($this->any())
277
+ ->method('isValidOpsRequest')
278
+ ->will($this->returnValue(true));
279
+
280
+ $closure = function ($order, $params = array()) {
281
+ $order->getPayment()->setAdditionalInformation(
282
+ 'status',
283
+ Netresearch_OPS_Model_Payment_Abstract::OPS_REFUND_WAITING
284
+ );
285
+ return $order->getPayment();
286
+ };
287
+
288
+ $refundHelper = $this->getHelperMock('ops/order_refund', array('createRefund'));
289
+ $refundHelper->expects($this->any())
290
+ ->method('createRefund')
291
+ ->will($this->returnCallback($closure));
292
+ $this->replaceByMock('helper', 'ops/order_refund', $refundHelper);
293
+ $params = array('STATUS' => Netresearch_OPS_Model_Payment_Abstract::OPS_REFUND_REFUSED, 'PAYID' => '4711');
294
+
295
+ $directlinkHelperMock->expects($this->once())
296
+ ->method('closePaymentTransaction')
297
+ ->with(
298
+ $order,
299
+ $params,
300
+ Netresearch_OPS_Model_Payment_Abstract::OPS_REFUND_TRANSACTION_TYPE,
301
+ Mage::helper('ops')->__(
302
+ 'Refund was refused. Automatic creation failed. Ingenico Payment Services status: %s.',
303
+ Mage::helper('ops')->getStatusText($params['STATUS'])
304
+ )
305
+ );
306
+
307
+ $directlinkHelperMock->processFeedback($order, $params);
308
+ }
309
+
310
+ /**
311
+ * @loadFixture ../../../var/fixtures/orders.yaml
312
+ */
313
+ public function testProcessFeedbackVoidSuccess()
314
+ {
315
+
316
+ $order = Mage::getModel('sales/order')->load(11);
317
+ $directlinkHelperMock = $this->getHelperMock('ops/directlink', array('isValidOpsRequest'));
318
+ $directlinkHelperMock->expects($this->any())
319
+ ->method('isValidOpsRequest')
320
+ ->will($this->returnValue(true));
321
+
322
+
323
+
324
+ $closure = function ($order, $params = array()) {
325
+ $order->getPayment()->setAdditionalInformation('status', 6);
326
+ return $order->getPayment();
327
+ };
328
+
329
+ $voidHelper = $this->getHelperMock('ops/order_void', array('acceptVoid'));
330
+ $voidHelper->expects($this->any())
331
+ ->method('acceptVoid')
332
+ ->will($this->returnCallback($closure));
333
+ $this->replaceByMock('helper', 'ops/order_void', $voidHelper);
334
+ $params = array('STATUS' => Netresearch_OPS_Model_Payment_Abstract::OPS_VOIDED, 'PAYID' => '4711');
335
+ $directlinkHelperMock->processFeedback($order, $params);
336
+ $this->assertEquals($params['STATUS'], $order->getPayment()->getAdditionalInformation('status'));
337
+ }
338
+
339
+ /**
340
+ * @loadFixture ../../../var/fixtures/orders.yaml
341
+ */
342
+ public function testProcessFeedbackVoidWaiting()
343
+ {
344
+ /** @var Mage_Sales_Model_Order $order */
345
+ $order = Mage::getModel('sales/order')->load(11);
346
+ $directlinkHelperMock = $this->getHelperMock('ops/directlink', array('isValidOpsRequest'));
347
+ $directlinkHelperMock->expects($this->any())
348
+ ->method('isValidOpsRequest')
349
+ ->will($this->returnValue(true));
350
+
351
+ $cntBefore = $order->getStatusHistoryCollection()->count();
352
+
353
+
354
+ $closure = function ($order, $params = array()) {
355
+ $order->getPayment()->setAdditionalInformation('status', Netresearch_OPS_Model_Payment_Abstract::OPS_VOID_WAITING);
356
+ return $order->getPayment();
357
+ };
358
+
359
+ $params = array('STATUS' => Netresearch_OPS_Model_Payment_Abstract::OPS_VOID_WAITING, 'PAYID' => '4711');
360
+ $directlinkHelperMock->processFeedback($order, $params);
361
+ $cntAfter = $order->getStatusHistoryCollection()->count();
362
+ $this->assertTrue($cntBefore < $cntAfter);
363
+
364
+ }
365
+
366
+ /**
367
+ * @loadFixture ../../../var/fixtures/orders.yaml
368
+ */
369
+ public function testProcessFeedbackVoidRefused()
370
+ {
371
+ /** @var Mage_Sales_Model_Order $order */
372
+ $order = Mage::getModel('sales/order')->load(11);
373
+ $directlinkHelperMock = $this->getHelperMock(
374
+ 'ops/directlink',
375
+ array('isValidOpsRequest', 'closePaymentTransaction')
376
+ );
377
+ $directlinkHelperMock->expects($this->any())
378
+ ->method('isValidOpsRequest')
379
+ ->will($this->returnValue(true));
380
+
381
+ $closure = function ($order, $params = array()) {
382
+ $order->getPayment()->setAdditionalInformation(
383
+ 'status',
384
+ Netresearch_OPS_Model_Payment_Abstract::OPS_VOID_REFUSED
385
+ );
386
+ return $order->getPayment();
387
+ };
388
+
389
+ $refundHelper = $this->getHelperMock('ops/order_void', array('acceptVoid'));
390
+ $refundHelper->expects($this->any())
391
+ ->method('acceptVoid')
392
+ ->will($this->returnCallback($closure));
393
+ $this->replaceByMock('helper', 'ops/order_void', $refundHelper);
394
+ $params = array('STATUS' => Netresearch_OPS_Model_Payment_Abstract::OPS_VOID_REFUSED, 'PAYID' => '4711');
395
+
396
+ $directlinkHelperMock->expects($this->once())
397
+ ->method('closePaymentTransaction')
398
+ ->with(
399
+ $order,
400
+ $params,
401
+ Netresearch_OPS_Model_Payment_Abstract::OPS_VOID_TRANSACTION_TYPE,
402
+ Mage::helper('ops')->__(
403
+ 'Void was refused. Automatic creation failed. Ingenico Payment Services status: %s.',
404
+ Mage::helper('ops')->getStatusText($params['STATUS'])
405
+ )
406
+ );
407
+
408
+ $directlinkHelperMock->processFeedback($order, $params);
409
+ }
410
+
411
+ /**
412
+ * @loadFixture ../../../var/fixtures/orders.yaml
413
+ */
414
+ public function testProcessFeedbackAuthorizeChanged()
415
+ {
416
+ /** @var Mage_Sales_Model_Order $order */
417
+ $order = Mage::getModel('sales/order')->load(11);
418
+ $directlinkHelperMock = $this->getHelperMock('ops/directlink', array('isValidOpsRequest'));
419
+ $directlinkHelperMock->expects($this->any())
420
+ ->method('isValidOpsRequest')
421
+ ->will($this->returnValue(true));
422
+
423
+ $cntBefore = $order->getStatusHistoryCollection()->count();
424
+
425
+ $params = array('STATUS' => Netresearch_OPS_Model_Payment_Abstract::OPS_AUTHORIZED, 'PAYID' => '4711');
426
+ $directlinkHelperMock->processFeedback($order, $params);
427
+ $cntAfter = $order->getStatusHistoryCollection()->count();
428
+ $this->assertTrue($cntBefore < $cntAfter);
429
+
430
+ }
431
+
432
+ /**
433
+ * @loadFixture ../../../var/fixtures/orders.yaml
434
+ */
435
+ public function testProcessFeedbackAuthorizeKwixoAccepted()
436
+ {
437
+ /** @var Mage_Sales_Model_Order $order */
438
+ $order = Mage::getModel('sales/order')->load(27);
439
+ $directlinkHelperMock = $this->getHelperMock('ops/directlink', array('isValidOpsRequest'));
440
+ $directlinkHelperMock->expects($this->any())
441
+ ->method('isValidOpsRequest')
442
+ ->will($this->returnValue(true));
443
+
444
+ $cntBefore = $order->getStatusHistoryCollection()->count();
445
+
446
+
447
+ $closure = function ($order, $params = array()) {
448
+ $order->getPayment()->setAdditionalInformation('status', Netresearch_OPS_Model_Payment_Abstract::OPS_AUTHORIZED);
449
+ return $order->getPayment();
450
+ };
451
+
452
+ $paymentHelper = $this->getHelperMock('ops/payment', array('acceptOrder'));
453
+ $paymentHelper->expects($this->any())
454
+ ->method('acceptOrder')
455
+ ->will($this->returnCallback($closure));
456
+ $this->replaceByMock('helper', 'ops/payment', $paymentHelper);
457
+
458
+ $params = array('STATUS' => Netresearch_OPS_Model_Payment_Abstract::OPS_AUTHORIZED, 'PAYID' => '4711');
459
+ $directlinkHelperMock->processFeedback($order, $params);
460
+ $this->assertEquals($params['STATUS'], $order->getPayment()->getAdditionalInformation('status'));
461
+ }
462
+
463
+ /**
464
+ * @loadFixture ../../../var/fixtures/orders.yaml
465
+ */
466
+ public function testProcessFeedbackUnknownStatus()
467
+ {
468
+ /** @var Mage_Sales_Model_Order $order */
469
+ $order = Mage::getModel('sales/order')->load(11);
470
+ $directlinkHelperMock = $this->getHelperMock('ops/directlink', array('isValidOpsRequest'));
471
+ $directlinkHelperMock->expects($this->any())
472
+ ->method('isValidOpsRequest')
473
+ ->will($this->returnValue(true));
474
+
475
+ $cntBefore = $order->getStatusHistoryCollection()->count();
476
+
477
+ $params = array('STATUS' => 4711, 'PAYID' => '4711');
478
+ $directlinkHelperMock->processFeedback($order, $params);
479
+ $cntAfter = $order->getStatusHistoryCollection()->count();
480
+ $this->assertTrue($cntBefore < $cntAfter);
481
+
482
+ }
483
+
484
+ /**
485
+ * @loadFixture ../../../var/fixtures/orders.yaml
486
+ */
487
+ public function testProcessFeedbackInvalidStatus()
488
+ {
489
+ /** @var Mage_Sales_Model_Order $order */
490
+ $order = Mage::getModel('sales/order')->load(11);
491
+ $directlinkHelperMock = $this->getHelperMock('ops/directlink', array('isValidOpsRequest'));
492
+ $directlinkHelperMock->expects($this->any())
493
+ ->method('isValidOpsRequest')
494
+ ->will($this->returnValue(true));
495
+
496
+ $cntBefore = $order->getStatusHistoryCollection()->count();
497
+
498
+ $params = array('STATUS' => Netresearch_OPS_Model_Payment_Abstract::OPS_INVALID, 'PAYID' => '4711');
499
+ $directlinkHelperMock->processFeedback($order, $params);
500
+ $cntAfter = $order->getStatusHistoryCollection()->count();
501
+ $this->assertTrue($cntBefore === $cntAfter);
502
+
503
+ }
504
+
505
+ /**
506
+ * @loadFixture ../../../var/fixtures/orders.yaml
507
+ */
508
+ public function testIsNoValidOpsRequestWillThrowException()
509
+ {
510
+ /** @var Mage_Sales_Model_Order $order */
511
+ $order = Mage::getModel('sales/order')->load(11);
512
+ $directlinkHelperMock = $this->getHelperMock('ops/directlink', array('isValidOpsRequest'));
513
+ $directlinkHelperMock->expects($this->any())
514
+ ->method('isValidOpsRequest')
515
+ ->will($this->returnValue(false));
516
+
517
+ $cntBefore = $order->getStatusHistoryCollection()->count();
518
+
519
+ $params = array('STATUS' => Netresearch_OPS_Model_Payment_Abstract::OPS_INVALID, 'PAYID' => '4711');
520
+ try {
521
+ $directlinkHelperMock->processFeedback($order, $params);
522
+ } catch (Mage_Core_Exception $e) {
523
+
524
+ }
525
+ $cntAfter = $order->getStatusHistoryCollection()->count();
526
+ $this->assertTrue($cntBefore < $cntAfter);
527
+ }
528
+ }
529
+
app/code/community/Netresearch/OPS/Test/Helper/DirectLinkTest/fixtures/.gitkeep ADDED
File without changes
app/code/community/Netresearch/OPS/Test/Helper/KwixoTest.php ADDED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Netresearch_OPS_Test_Helper_KwixoTest
4
+ extends EcomDev_PHPUnit_Test_Case_Controller
5
+ {
6
+
7
+ public function testValidateKwixoconfigurationMappingContainsNoData()
8
+ {
9
+
10
+ $this->helperMustThrowException(array());
11
+ }
12
+
13
+ public function testValidateKwixoconfigurationMappingContainsInvalidId()
14
+ {
15
+ $this->helperMustThrowException(array('od' => 1));
16
+ }
17
+
18
+ public function testValidateKwixoconfigurationMappingContainsEmptyId()
19
+ {
20
+ $this->helperMustThrowException(array('id' => ''));
21
+ }
22
+
23
+ public function testValidateKwixoconfigurationMappingContainsNonNumericId()
24
+ {
25
+ $this->helperMustThrowException(array('id' => 'abc'));
26
+ }
27
+
28
+ public function testValidateKwixoconfigurationMappingContainsNegativeId()
29
+ {
30
+ $this->helperMustThrowException(array('id' => -1));
31
+ }
32
+
33
+ public function testValidateKwixoconfigurationMappingContainsNoKwixoCategory(
34
+ )
35
+ {
36
+ $this->helperMustThrowException(array('id' => 1));
37
+ }
38
+
39
+ public function testValidateKwixoconfigurationMappingContainsInvalidKwixoCategory(
40
+ )
41
+ {
42
+ $this->helperMustThrowException(
43
+ array('id' => 1, 'kwixoCategory_id' => 666)
44
+ );
45
+ }
46
+
47
+ public function testValidateKwixoconfigurationMappingContainsNoCategory()
48
+ {
49
+ $this->helperMustThrowException(
50
+ array('id' => 1, 'kwixoCategory_id' => 1)
51
+ );
52
+ }
53
+
54
+ public function testValidateKwixoconfigurationMappingContainsNonNumericCategory(
55
+ )
56
+ {
57
+ $this->helperMustThrowException(
58
+ array('id' => 1, 'kwixoCategory_id' => 1, 'category_id' => 'abc')
59
+ );
60
+ }
61
+
62
+ public function testValidateKwixoconfigurationMappingContainsNegativeCategory(
63
+ )
64
+ {
65
+ $this->helperMustThrowException(
66
+ array('id' => 1, 'kwixoCategory_id' => 1, 'category_id' => -1)
67
+ );
68
+ }
69
+
70
+ public function testValidateKwixoconfigurationMappingContainsNegativeCategory2(
71
+ )
72
+ {
73
+ $helper = Mage::helper('ops/kwixo');
74
+ $helper->validateKwixoconfigurationMapping(
75
+ array('id' => 1, 'kwixoCategory_id' => 1, 'category_id' => 1)
76
+ );
77
+ }
78
+
79
+
80
+ protected function helperMustThrowException($invalidData)
81
+ {
82
+ $helper = Mage::helper('ops/kwixo');
83
+ $this->setExpectedException('Mage_Core_Exception');
84
+ $helper->validateKwixoconfigurationMapping($invalidData);
85
+ }
86
+
87
+ /**
88
+ * @loadFixture category_mapping
89
+ */
90
+ public function testSaveKwixoConfigurationMapping()
91
+ {
92
+ $helperMock = $this->getHelperMock(
93
+ 'ops/kwixo', array('validateKwixoconfigurationMapping')
94
+ );
95
+ $helperMock->saveKwixoconfigurationMapping(
96
+ array('id' => 1, 'category_id' => 666, 'kwixoCategory_id' => 777)
97
+ );
98
+ $model = Mage::getModel('ops/kwixo_category_mapping')->load(1);
99
+ $this->assertEquals(666, $model->getCategoryId());
100
+ $this->assertEquals(777, $model->getKwixoCategoryId());
101
+ }
102
+
103
+ /**
104
+ * @loadFixture category_mapping
105
+ */
106
+ public function testSaveKwixoConfigurationMappingForSubCategories()
107
+ {
108
+ $helperMock = $this->getHelperMock(
109
+ 'ops/kwixo', array('validateKwixoconfigurationMapping')
110
+ );
111
+
112
+ $categoryMock = $this->getModelMock('catalog/category', array('load', 'getAllChildren'));
113
+ $categoryMock->expects($this->any())
114
+ ->method('getAllChildren')
115
+ ->will($this->returnValue(array(11)));
116
+ $categoryMock->expects($this->any())
117
+ ->method('load')
118
+ ->will($this->returnValue($categoryMock));
119
+ $this->replaceByMock('model', 'catalog/category', $categoryMock);
120
+
121
+ $helperMock->saveKwixoconfigurationMapping(
122
+ array('id' => 1, 'category_id' => 666,
123
+ 'kwixoCategory_id' => 777, 'applysubcat' => true)
124
+ );
125
+
126
+ $model = Mage::getModel('ops/kwixo_category_mapping')->load(1);
127
+ $this->assertEquals(666, $model->getCategoryId());
128
+ $this->assertEquals(777, $model->getKwixoCategoryId());
129
+ $model = Mage::getModel('ops/kwixo_category_mapping')->load(2);
130
+ $this->assertEquals(777, $model->getKwixoCategoryId());
131
+ }
132
+ }
app/code/community/Netresearch/OPS/Test/Helper/KwixoTest/fixtures/category_mapping.yaml ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ tables:
2
+ ops/kwixo_category_mapping:
3
+ - id: 1
4
+ kwixo_category_id: 10
5
+ category_id: 10
6
+ - id: 2
7
+ kwixo_category_id: 1
8
+ category_id: 11
9
+ - id: 3
10
+ kwixo_category_id: 2
11
+ category_id: 11
app/code/community/Netresearch/OPS/Test/Helper/Order/CaptureTest.php ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Netresearch_OPS_Test_Helper_Order_CaptureTest extends EcomDev_PHPUnit_Test_Case
4
+ {
5
+
6
+ /**
7
+ * @loadFixture ../../../../var/fixtures/orders.yaml
8
+ */
9
+ public function testOperationPartialAndTypePartial()
10
+ {
11
+ $helper = Mage::helper('ops/order_capture');
12
+ $invoice = array("items" => "foo");
13
+ Mage::app()->getRequest()->setParam('invoice', $invoice);
14
+ $payment = new Varien_Object();
15
+ $order = Mage::getModel('sales/order')->load(11);
16
+ $payment->setOrder($order);
17
+ // order base_grand_total == grand_total == 119.00
18
+
19
+ $expected = array(
20
+ "items" => $invoice["items"],
21
+ "operation" => Netresearch_OPS_Model_Payment_Abstract::OPS_CAPTURE_PARTIAL,
22
+ "type" => "partial",
23
+ "amount" => 100.00
24
+ );
25
+
26
+ $payment->setBaseAmountPaidOnline(0.00);
27
+ $amount = 100.00;
28
+ $this->assertEquals($expected, $helper->prepareOperation($payment, $amount));
29
+
30
+ }
31
+
32
+
33
+ /**
34
+ * @loadFixture ../../../../var/fixtures/orders.yaml
35
+ */
36
+ public function testOperationFullAndTypePartial()
37
+ {
38
+ $helper = Mage::helper('ops/order_capture');
39
+ $invoice = array("items" => "foo");
40
+ Mage::app()->getRequest()->setParam('invoice', $invoice);
41
+ $payment = new Varien_Object();
42
+ $order = Mage::getModel('sales/order')->load(11);
43
+ $payment->setOrder($order);
44
+ // order base_grand_total == grand_total == 119.00
45
+
46
+ $expected = array(
47
+ "items" => $invoice["items"],
48
+ "operation" => Netresearch_OPS_Model_Payment_Abstract::OPS_CAPTURE_FULL,
49
+ "type" => "partial",
50
+ "amount" => 100.00
51
+ );
52
+
53
+ $payment->setBaseAmountPaidOnline(19.00);
54
+ $amount = 100.00;
55
+ $this->assertEquals($expected, $helper->prepareOperation($payment, $amount));
56
+ }
57
+
58
+ /**
59
+ * @loadFixture ../../../../var/fixtures/orders.yaml
60
+ */
61
+ public function testOperationFullAndTypeFull()
62
+ {
63
+ $helper = Mage::helper('ops/order_capture');
64
+ $invoice = array("items" => "foo");
65
+ Mage::app()->getRequest()->setParam('invoice', $invoice);
66
+ $payment = new Varien_Object();
67
+ $order = Mage::getModel('sales/order')->load(11);
68
+ $payment->setOrder($order);
69
+ // order base_grand_total == grand_total == 119.00
70
+
71
+ $expected = array(
72
+ "items" => $invoice["items"],
73
+ "operation" => Netresearch_OPS_Model_Payment_Abstract::OPS_CAPTURE_FULL,
74
+ "type" => "full",
75
+ "amount" => 119.00
76
+ );
77
+
78
+ $payment->setBaseAmountPaidOnline(0.00);
79
+ $amount = 119.00;
80
+ $this->assertEquals($expected, $helper->prepareOperation($payment, $amount));
81
+ }
82
+ }
app/code/community/Netresearch/OPS/Test/Helper/Order/CaptureTest/fixtures/.gitkeep ADDED
File without changes
app/code/community/Netresearch/OPS/Test/Helper/Order/RefundTest.php ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Netresearch_OPS_Test_Helper_Order_RefundTest extends EcomDev_PHPUnit_Test_Case
4
+ {
5
+
6
+ public function setUp()
7
+ {
8
+ Mage::unregister('_helper/ops/order_refund');
9
+ parent::setUp();
10
+ }
11
+ /**
12
+ * @loadFixture ../../../../var/fixtures/orders.yaml
13
+ */
14
+ public function testDetermineOperationCode()
15
+ {
16
+ /* @var $helper Netresearch_OPS_Helper_Order_Refund */
17
+ $helper = Mage::helper('ops/order_refund');
18
+ $payment = new Varien_Object();
19
+
20
+ // complete refund should lead to RFS
21
+ $order = Mage::getModel('sales/order')->load(11);
22
+ $payment->setOrder($order);
23
+ $payment->setBaseAmountRefundedOnline(0.00);
24
+ $amount = 119.00;
25
+ $this->assertEquals(Netresearch_OPS_Model_Payment_Abstract::OPS_REFUND_FULL, $helper->determineOperationCode($payment, $amount));
26
+
27
+ // complete refund should lead to RFS
28
+ $order = Mage::getModel('sales/order')->load(16);
29
+ $payment->setOrder($order);
30
+ $payment->setBaseAmountRefundedOnline(0.00);
31
+ $amount = 19.99;
32
+ $this->assertEquals(Netresearch_OPS_Model_Payment_Abstract::OPS_REFUND_FULL, $helper->determineOperationCode($payment, $amount));
33
+
34
+ // partial refund should lead to RFD
35
+ $order = Mage::getModel('sales/order')->load(11);
36
+ $payment->setOrder($order);
37
+ $payment->setBaseAmountRefundedOnline(0.00);
38
+ $amount = 100.00;
39
+ $this->assertEquals(Netresearch_OPS_Model_Payment_Abstract::OPS_REFUND_PARTIAL, $helper->determineOperationCode($payment, $amount));
40
+
41
+ // partial refund + new amount to refund should lead to RFS
42
+ $order = Mage::getModel('sales/order')->load(11);
43
+ $payment->setOrder($order);
44
+ $payment->setBaseAmountRefundedOnline(19.00);
45
+ $amount = 100.00;
46
+ $this->assertEquals(Netresearch_OPS_Model_Payment_Abstract::OPS_REFUND_FULL, $helper->determineOperationCode($payment, $amount));
47
+
48
+ // partial refund + new amount to refund should lead to RFS
49
+ $order = Mage::getModel('sales/order')->load(16);
50
+ $payment->setOrder($order);
51
+ $payment->setBaseAmountRefundedOnline(17.98);
52
+ $amount = 2.01;
53
+ $this->assertEquals(Netresearch_OPS_Model_Payment_Abstract::OPS_REFUND_FULL, $helper->determineOperationCode($payment, $amount));
54
+
55
+ // partial refund + new amount to refund should lead to RFS
56
+ $order = Mage::getModel('sales/order')->load(16);
57
+ $payment->setOrder($order);
58
+ $payment->setBaseAmountRefundedOnline(17.98);
59
+ $amount = 2.00;
60
+ $this->assertEquals(Netresearch_OPS_Model_Payment_Abstract::OPS_REFUND_FULL, $helper->determineOperationCode($payment, $amount));
61
+
62
+ }
63
+
64
+ /**
65
+ * @loadFixture ../../../../var/fixtures/orders.yaml
66
+ */
67
+ public function testOperationPartialAndTypePartial()
68
+ {
69
+ $helper = Mage::helper('ops/order_refund');
70
+ $creditmemo = array("creditmemo" => array("items" => "foo"));
71
+ $helper->setCreditMemoRequestParams($creditmemo);
72
+ $payment = new Varien_Object();
73
+ $order = Mage::getModel('sales/order')->load(11);
74
+ $payment->setOrder($order);
75
+ // order base_grand_total == grand_total == 119.00
76
+
77
+ $expected = array(
78
+ "items" => $creditmemo["creditmemo"]["items"],
79
+ "operation" => Netresearch_OPS_Model_Payment_Abstract::OPS_REFUND_PARTIAL,
80
+ "type" => "partial",
81
+ "amount" => 100.00
82
+ );
83
+
84
+ $payment->setBaseAmountRefundedOnline(0.00);
85
+ $amount = 100.00;
86
+ $this->assertEquals($expected, $helper->prepareOperation($payment, $amount));
87
+
88
+ }
89
+
90
+
91
+ /**
92
+ * @loadFixture ../../../../var/fixtures/orders.yaml
93
+ */
94
+ public function testOperationFullAndTypePartial()
95
+ {
96
+ $helper = Mage::helper('ops/order_refund');
97
+ $creditmemo = array("creditmemo" => array("items" => "foo"));
98
+ $helper->setCreditMemoRequestParams($creditmemo);
99
+ $payment = new Varien_Object();
100
+ $order = Mage::getModel('sales/order')->load(11);
101
+ $payment->setOrder($order);
102
+ // order base_grand_total == grand_total == 119.00
103
+
104
+ $expected = array(
105
+ "items" => $creditmemo["creditmemo"]["items"],
106
+ "operation" => Netresearch_OPS_Model_Payment_Abstract::OPS_REFUND_FULL,
107
+ "type" => "partial",
108
+ "amount" => 100.00
109
+ );
110
+
111
+ $payment->setBaseAmountRefundedOnline(19.00);
112
+ $amount = 100.00;
113
+ $this->assertEquals($expected, $helper->prepareOperation($payment, $amount));
114
+ }
115
+
116
+ /**
117
+ * @loadFixture ../../../../var/fixtures/orders.yaml
118
+ */
119
+ public function testOperationFullAndTypeFull()
120
+ {
121
+ $helper = Mage::helper('ops/order_refund');
122
+ $creditmemo = array("creditmemo" => array("items" => "foo"));
123
+ $helper->setCreditMemoRequestParams($creditmemo);
124
+ $payment = new Varien_Object();
125
+ $order = Mage::getModel('sales/order')->load(11);
126
+ $payment->setOrder($order);
127
+ // order base_grand_total == grand_total == 119.00
128
+
129
+ $expected = array(
130
+ "items" => $creditmemo["creditmemo"]["items"],
131
+ "operation" => Netresearch_OPS_Model_Payment_Abstract::OPS_REFUND_FULL,
132
+ "type" => "full",
133
+ "amount" => 119.00
134
+ );
135
+
136
+ $payment->setBaseAmountRefundedOnline(0.00);
137
+ $amount = 119.00;
138
+ $this->assertEquals($expected, $helper->prepareOperation($payment, $amount));
139
+ }
140
+
141
+ }
app/code/community/Netresearch/OPS/Test/Helper/Order/RefundTest/fixtures/.gitkeep ADDED
File without changes
app/code/community/Netresearch/OPS/Test/Helper/Order/VoidTest.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Netresearch_OPS_Test_Helper_Order_VoidTest
3
+ extends EcomDev_PHPUnit_Test_Case
4
+ {
5
+
6
+ /**
7
+ * @loadFixture ../../../../var/fixtures/orders.yaml
8
+ */
9
+ public function testVoidAccepted()
10
+ {
11
+ $paymentMock = $this->getModelMock('sales/order_payment', array('save'));
12
+ $this->replaceByMock('model', 'sales/order_payment', $paymentMock);
13
+
14
+ Mage::unregister('ops_auto_void');
15
+ $helper = Mage::helper('ops/order_void');
16
+ $order = Mage::getModel('sales/order')->load(11);
17
+ $directLinkHelper = $this->getHelperMock("ops/directlink", array('closePaymentTransaction'));
18
+ $this->replaceByMock('helper', 'ops/directlink', $directLinkHelper);
19
+ $helper->acceptVoid($order, array('orderID' => 11));
20
+ $this->assertTrue(Mage::registry('ops_auto_void'));
21
+ Mage::unregister('ops_auto_void');
22
+ }
23
+
24
+ }
app/code/community/Netresearch/OPS/Test/Helper/Order/VoidTest/fixtures/.gitkeep ADDED
File without changes
app/code/community/Netresearch/OPS/Test/Helper/OrderTest.php ADDED
@@ -0,0 +1,168 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Netresearch_OPS_Test_Helper_OrderTest extends EcomDev_PHPUnit_Test_Case
3
+ {
4
+
5
+ private $devPrefix = '';
6
+
7
+ public function setUp()
8
+ {
9
+ $this->devPrefix = Mage::getModel('ops/config')->getConfigData(
10
+ 'devprefix'
11
+ );
12
+ parent::setUp();
13
+ }
14
+
15
+
16
+ /**
17
+ * @loadFixture order.yaml
18
+ */
19
+ public function testGetOpsOrderId()
20
+ {
21
+ $store = Mage::app()->getStore(0)->load(0);
22
+ $store->resetConfig();
23
+ $helper = Mage::helper('ops/order');
24
+
25
+ $store->setConfig(
26
+ 'payment_services/ops/redirectOrderReference',
27
+ Netresearch_OPS_Model_Payment_Abstract::REFERENCE_QUOTE_ID
28
+ );
29
+
30
+ $order = Mage::getModel('sales/order')->load(1);
31
+ $delimiter = $helper::DELIMITER;
32
+ $this->assertEquals(
33
+ $this->devPrefix . $order->getQuoteId(),
34
+ $helper->getOpsOrderId($order)
35
+ );
36
+
37
+
38
+ $store->setConfig(
39
+ 'payment_services/ops/redirectOrderReference',
40
+ Netresearch_OPS_Model_Payment_Abstract::REFERENCE_ORDER_ID
41
+ );
42
+
43
+ $order = Mage::getModel('sales/order')->load(2);
44
+ $this->assertEquals(
45
+ $this->devPrefix . $delimiter . $order->getIncrementId(),
46
+ $helper->getOpsOrderId($order)
47
+ );
48
+
49
+ $store->setConfig(
50
+ 'payment_services/ops/redirectOrderReference',
51
+ Netresearch_OPS_Model_Payment_Abstract::REFERENCE_QUOTE_ID
52
+ );
53
+ $order = Mage::getModel('sales/order')->load(3);
54
+ $this->assertEquals(
55
+ $this->devPrefix . $order->getQuoteId(),
56
+ $helper->getOpsOrderId($order)
57
+ );
58
+
59
+ $store->setConfig(
60
+ 'payment_services/ops/redirectOrderReference',
61
+ Netresearch_OPS_Model_Payment_Abstract::REFERENCE_ORDER_ID
62
+ );
63
+ $order = Mage::getModel('sales/order')->load(3);
64
+ $this->assertEquals(
65
+ $this->devPrefix . $order->getQuoteId(),
66
+ $helper->getOpsOrderId($order, false)
67
+ );
68
+ }
69
+
70
+
71
+ /**
72
+ * @loadFixture order.yaml
73
+ */
74
+ public function testGetOrder()
75
+ {
76
+ $helper = Mage::helper('ops/order');
77
+ // old behaviour: load order from quote
78
+ $opsOrderId = $this->devPrefix . '5';
79
+ $order = $helper->getOrder($opsOrderId);
80
+ $this->assertEquals(4, $order->getId());
81
+
82
+ // new behaviour
83
+ $delimiter = $helper::DELIMITER;
84
+ $opsOrderId = $this->devPrefix . $delimiter . 2000;
85
+ $order = $helper->getOrder($opsOrderId);
86
+ $this->assertEquals(2, $order->getId());
87
+
88
+
89
+ }
90
+
91
+
92
+ /**
93
+ * @loadFixture order.yaml
94
+ */
95
+ public function testGetQuote()
96
+ {
97
+ $order = Mage::getModel('sales/order')->load(1);
98
+ $quote = Mage::helper('ops/order')->getQuote($order->getQuoteId());
99
+ $this->assertTrue($quote instanceof Mage_Sales_Model_Quote);
100
+ $this->assertEquals(1, $quote->getId());
101
+ }
102
+
103
+ /**
104
+ * @loadFixture ../../../var/fixtures/orders.yaml
105
+ */
106
+ public function testCheckIfAddressAreSameWithSameAddressData()
107
+ {
108
+ $order = Mage::getModel('sales/order')->load(11);
109
+ $this->assertTrue(
110
+ (bool)Mage::helper('ops/order')->checkIfAddressesAreSame($order)
111
+ );
112
+
113
+ $order = Mage::getModel('sales/order')->load(27);
114
+ $this->assertFalse(
115
+ (bool)Mage::helper('ops/order')->checkIfAddressesAreSame($order)
116
+ );
117
+ }
118
+
119
+ /**
120
+ * @loadFixture ../../../var/fixtures/orders.yaml
121
+ */
122
+ public function testCheckIfAddressAreSameWithDifferentAddressData()
123
+ {
124
+ $order = Mage::getModel('sales/order')->load(12);
125
+ $this->assertFalse(
126
+ (bool)Mage::helper('ops/order')->checkIfAddressesAreSame($order)
127
+ );
128
+ }
129
+
130
+ public function testCheckForOpsStateOnStatusUpdateWillPassStatusUpdate()
131
+ {
132
+ $payment = Mage::getModel('sales/order_payment');
133
+ $payment->setAdditionalInformation('status', 9);
134
+ $order = Mage::getModel('sales/order');
135
+ $order->setPayment($payment);
136
+ $order->setStatus(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT);
137
+ $order->setStatus(Mage_Sales_Model_Order::STATE_PROCESSING);
138
+ Mage::helper('ops/order')->checkForOpsStateOnStatusUpdate($order);
139
+ $this->assertEquals(Mage_Sales_Model_Order::STATE_PROCESSING, $order->getStatus());
140
+ }
141
+
142
+ public function testCheckForOpsStateOnStatusUpdateWillNotPassStatusUpdate()
143
+ {
144
+ $payment = Mage::getModel('sales/order_payment');
145
+ $payment->setAdditionalInformation('status', 9);
146
+ $order = Mage::getModel('sales/order');
147
+ $order->setPayment($payment);
148
+ $order->setStatus(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT);
149
+ Mage::helper('ops/order')->checkForOpsStateOnStatusUpdate($order);
150
+ $this->assertEquals(null, $order->getStatus());
151
+ }
152
+
153
+ public function testSetDataHelper()
154
+ {
155
+ $dataHelper = $this->getHelperMock('ops/data');
156
+ $helper = Mage::helper('ops/order');
157
+ $helper->setDataHelper($dataHelper);
158
+ $this->assertEquals($dataHelper, $helper->getDataHelper());
159
+ }
160
+
161
+ public function testSetStatusMappingModel()
162
+ {
163
+ $dataHelper = $this->getModelMock('ops/status_mapping');
164
+ $helper = Mage::helper('ops/order');
165
+ $helper->setStatusMappingModel($dataHelper);
166
+ $this->assertEquals($dataHelper, $helper->getStatusMappingModel());
167
+ }
168
+ }
app/code/community/Netresearch/OPS/Test/Helper/OrderTest/fixtures/order.yaml ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ tables:
2
+ sales/order:
3
+ - entity_id: 1
4
+ increment_id: 1000
5
+ quote_id: 1
6
+
7
+ - entity_id: 2
8
+ increment_id: 2000
9
+ quote_id: 2
10
+
11
+ - entity_id: 3
12
+ quote_id: 3
13
+
14
+ - id: 4
15
+ entity_id: 4
16
+ increment_id: 4000
17
+ quote_id: 5
18
+
19
+ - id: 5
20
+ entity_id: 5
21
+ increment_id: 1001
22
+ quote_id: 5
23
+
24
+
25
+ sales/quote:
26
+ - id: 1
27
+ entity_id: 1
28
+ parent_id: 1
29
+
30
+ - id: 5
31
+ entity_id: 5
32
+ parent_id: 1
33
+
34
+ sales/order_payment:
35
+ - parent_id: 4
36
+ method: 'ops_test'
37
+
38
+ - parent_id: 2
39
+ method: 'ops_test'
40
+
41
+ - parent_id: 5
42
+ method: 'ops_test'
app/code/community/Netresearch/OPS/Test/Helper/Payment/DirectLink/RequestTest.php ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @author Michael Lühr <michael.luehr@netresearch.de>
5
+ * @category Netresearch
6
+ * @copyright Copyright (c) 2014 Netresearch GmbH & Co. KG (http://www.netresearch.de)
7
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
8
+ */
9
+ class Netresearch_OPS_Test_Helper_Payment_DirectLink_RequestTest extends EcomDev_PHPUnit_Test_Case_Controller
10
+ {
11
+
12
+ /**
13
+ * @loadFixture ../../../../../var/fixtures/orders.yaml
14
+ */
15
+ public function testGetBaseParams()
16
+ {
17
+ $order = Mage::getModel('sales/order')->load(11);
18
+ $quote = Mage::getModel('sales/quote')->load($order->getQuoteId());
19
+ $quote->getPayment()->setMethod('ops_cc');
20
+ $configMock = $this->getModelMock('ops/config', array('canSubmitExtraParameter'));
21
+ $configMock->expects($this->any())
22
+ ->method('canSubmitExtraParameter')
23
+ ->will($this->returnValue(false));
24
+ $paramHelper = Mage::helper('ops/creditcard');
25
+ $paramHelper->setConfig($configMock);
26
+ $paramHelper->getRequestHelper()->setConfig($configMock);
27
+ $params = $paramHelper->getDirectLinkRequestParams($quote, $order);
28
+ foreach ($this->getOwnerParams() as $ownerParam) {
29
+ $this->assertArrayNotHasKey($ownerParam, $params);
30
+ }
31
+ foreach ($this->getShippingParams() as $shippingParam) {
32
+ $this->assertArrayNotHasKey($shippingParam, $params);
33
+ }
34
+
35
+ }
36
+
37
+ /**
38
+ * @loadFixture ../../../../../var/fixtures/orders.yaml
39
+ */
40
+ public function testGetExtraParams()
41
+ {
42
+ $order = Mage::getModel('sales/order')->load(11);
43
+ $quote = Mage::getModel('sales/quote');
44
+ $quote->getPayment()->setMethod('ops_cc');
45
+ $configMock = $this->getModelMock('ops/config', array('canSubmitExtraParameter'));
46
+ $configMock->expects($this->any())
47
+ ->method('canSubmitExtraParameter')
48
+ ->will($this->returnValue(true));
49
+ $paramHelper = Mage::helper('ops/creditcard');
50
+ $paramHelper->setConfig($configMock);
51
+ $paramHelper->getRequestHelper()->setConfig($configMock);
52
+ $params = $paramHelper->getDirectLinkRequestParams($quote, $order);
53
+ foreach ($this->getOwnerParams() as $ownerParam) {
54
+ $this->assertArrayHasKey($ownerParam, $params);
55
+ }
56
+ foreach ($this->getShippingParams() as $shippingParam) {
57
+ $this->assertArrayHasKey($shippingParam, $params);
58
+ }
59
+
60
+ }
61
+
62
+ protected function getOwnerParams()
63
+ {
64
+ return $ownerParams = array(
65
+ 'OWNERADDRESS',
66
+ 'OWNERTOWN',
67
+ 'OWNERZIP',
68
+ 'OWNERTELNO',
69
+ 'OWNERCTY',
70
+ 'ECOM_BILLTO_POSTAL_POSTALCODE',
71
+ );
72
+ }
73
+
74
+ protected function getShippingParams()
75
+ {
76
+ $paramValues = array(
77
+ 'ECOM_SHIPTO_POSTAL_NAME_FIRST',
78
+ 'ECOM_SHIPTO_POSTAL_NAME_LAST',
79
+ 'ECOM_SHIPTO_POSTAL_STREET_LINE1',
80
+ 'ECOM_SHIPTO_POSTAL_STREET_LINE2',
81
+ 'ECOM_SHIPTO_POSTAL_COUNTRYCODE',
82
+ 'ECOM_SHIPTO_POSTAL_CITY',
83
+ 'ECOM_SHIPTO_POSTAL_POSTALCODE'
84
+ );
85
+
86
+ return $paramValues;
87
+ }
88
+ }
app/code/community/Netresearch/OPS/Test/Helper/Payment/DirectLink/RequestTest/fixtures/.gitkeep ADDED
File without changes
app/code/community/Netresearch/OPS/Test/Helper/Payment/RequestTest.php ADDED
@@ -0,0 +1,274 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Netresearch_OPS_Test_Helper_Payment_RequestTest extends EcomDev_PHPUnit_Test_Case
4
+ {
5
+
6
+ /**
7
+ * @return Netresearch_OPS_Helper_Payment_RequestTest
8
+ */
9
+ protected function getRequestHelper()
10
+ {
11
+ return Mage::helper('ops/payment_request');
12
+ }
13
+
14
+ protected function getShipToArrayKeys()
15
+ {
16
+ return array(
17
+ 'ECOM_SHIPTO_POSTAL_NAME_FIRST',
18
+ 'ECOM_SHIPTO_POSTAL_NAME_LAST',
19
+ 'ECOM_SHIPTO_POSTAL_STREET_LINE1',
20
+ 'ECOM_SHIPTO_POSTAL_STREET_LINE2',
21
+ 'ECOM_SHIPTO_POSTAL_COUNTRYCODE',
22
+ 'ECOM_SHIPTO_POSTAL_CITY',
23
+ 'ECOM_SHIPTO_POSTAL_POSTALCODE',
24
+ 'ECOM_SHIPTO_POSTAL_STATE',
25
+ );
26
+ }
27
+
28
+ public function testExtractShipToParameters()
29
+ {
30
+ $address = Mage::getModel('sales/quote_address');
31
+ $helper = $this->getRequestHelper();
32
+ $configMock = $this->getModelMock('ops/config', array('canSubmitExtraParameter'));
33
+ $configMock->expects($this->any())
34
+ ->method('canSubmitExtraParameter')
35
+ ->will($this->returnValue(true));
36
+ $helper->setConfig($configMock);
37
+ $params = $helper->extractShipToParameters($address, Mage::getModel('sales/quote'));
38
+ $this->assertTrue(is_array($params));
39
+ foreach ($this->getShipToArrayKeys() as $key) {
40
+ $this->assertArrayHasKey($key, $params);
41
+ }
42
+
43
+ $address->setFirstname('Hans');
44
+ $address->setLastname('Wurst');
45
+ $address->setStreet('Nonnenstrasse 11d');
46
+ $address->setCountry('DE');
47
+ $address->setCity('Leipzig');
48
+ $address->setPostcode('04229');
49
+ $params = $this->getRequestHelper()->extractShipToParameters($address, Mage::getModel('sales/quote'));
50
+ $this->assertEquals('Hans', $params['ECOM_SHIPTO_POSTAL_NAME_FIRST']);
51
+ $this->assertEquals('Wurst', $params['ECOM_SHIPTO_POSTAL_NAME_LAST']);
52
+ $this->assertEquals('Nonnenstrasse 11d', $params['ECOM_SHIPTO_POSTAL_STREET_LINE1']);
53
+ $this->assertEquals('', $params['ECOM_SHIPTO_POSTAL_STREET_LINE2']);
54
+ $this->assertEquals('DE', $params['ECOM_SHIPTO_POSTAL_COUNTRYCODE']);
55
+ $this->assertEquals('Leipzig', $params['ECOM_SHIPTO_POSTAL_CITY']);
56
+ $this->assertEquals('04229', $params['ECOM_SHIPTO_POSTAL_POSTALCODE']);
57
+ }
58
+
59
+ public function testGetIsoRegionCodeWithIsoRegionCode()
60
+ {
61
+ $address = Mage::getModel('customer/address');
62
+ $address->setRegionCode('SN');
63
+ $address->setCountry('DE');
64
+ $this->assertEquals('SN', $this->getRequestHelper()->getIsoRegionCode($address));
65
+ }
66
+
67
+ public function testGetIsoRegionCodeWithIsoRegionCodeContainingTheCountryCode()
68
+ {
69
+ $address = Mage::getModel('customer/address');
70
+ $address->setRegionCode('ES-AB');
71
+ $address->setCountry('ES');
72
+ $this->assertEquals('AB', $this->getRequestHelper()->getIsoRegionCode($address));
73
+ }
74
+
75
+
76
+ public function testGetIsoRegionCodeWithGermanMageRegionCode()
77
+ {
78
+ $address = Mage::getModel('customer/address');
79
+ $address->setRegionCode('SAS');
80
+ $address->setCountry('DE');
81
+ $this->assertEquals('SN', $this->getRequestHelper()->getIsoRegionCode($address));
82
+ $address->setRegionCode('NDS');
83
+ $this->assertEquals('NI', $this->getRequestHelper()->getIsoRegionCode($address));
84
+ $address->setRegionCode('THE');
85
+ $this->assertEquals('TH', $this->getRequestHelper()->getIsoRegionCode($address));
86
+ }
87
+
88
+ public function testGetIsoRegionCodeWithAustrianMageRegionCode()
89
+ {
90
+ $address = Mage::getModel('customer/address');
91
+ $address->setRegionCode('WI');
92
+ $address->setCountry('AT');
93
+ $this->assertEquals('9', $this->getRequestHelper()->getIsoRegionCode($address));
94
+ $address->setRegionCode('NO');
95
+ $this->assertEquals('3', $this->getRequestHelper()->getIsoRegionCode($address));
96
+ $address->setRegionCode('VB');
97
+ $this->assertEquals('8', $this->getRequestHelper()->getIsoRegionCode($address));
98
+ }
99
+
100
+ public function testGetIsoRegionCodeWithSpanishMageRegionCode()
101
+ {
102
+ $address = Mage::getModel('customer/address');
103
+ $address->setRegionCode('A Coruсa');
104
+ $address->setCountry('ES');
105
+ $this->assertEquals('C', $this->getRequestHelper()->getIsoRegionCode($address));
106
+ $address->setRegionCode('Barcelona');
107
+ $this->assertEquals('B', $this->getRequestHelper()->getIsoRegionCode($address));
108
+ $address->setRegionCode('Madrid');
109
+ $this->assertEquals('M', $this->getRequestHelper()->getIsoRegionCode($address));
110
+ }
111
+
112
+ public function testGetIsoRegionCodeWithFinnishMageRegionCode()
113
+ {
114
+ $address = Mage::getModel('customer/address');
115
+ $address->setRegionCode('Lappi');
116
+ $address->setCountry('FI');
117
+ $this->assertEquals('10', $this->getRequestHelper()->getIsoRegionCode($address));
118
+ $address->setRegionCode('Etelä-Savo');
119
+ $this->assertEquals('04', $this->getRequestHelper()->getIsoRegionCode($address));
120
+ $address->setRegionCode('Itä-Uusimaa');
121
+ $this->assertEquals('19', $this->getRequestHelper()->getIsoRegionCode($address));
122
+ }
123
+
124
+ public function testGetIsoRegionCodeWithLatvianMageRegionCode()
125
+ {
126
+ $address = Mage::getModel('customer/address');
127
+ $address->setRegionCode('Ādažu novads');
128
+ $address->setCountry('LV');
129
+ $this->assertEquals('LV', $this->getRequestHelper()->getIsoRegionCode($address));
130
+ $address->setRegionCode('Engures novads');
131
+ $this->assertEquals('029', $this->getRequestHelper()->getIsoRegionCode($address));
132
+ $address->setRegionCode('Viļakas novads');
133
+ $this->assertEquals('108', $this->getRequestHelper()->getIsoRegionCode($address));
134
+ }
135
+
136
+ public function testGetIsoRegionCodeWithUnknownRegionCode()
137
+ {
138
+ $address = Mage::getModel('customer/address');
139
+ $address->setRegionCode('DEFG');
140
+ $address->setCountry('AB');
141
+ $this->assertEquals('AB', $this->getRequestHelper()->getIsoRegionCode($address));
142
+ $address->setRegionCode('DEF');
143
+ $this->assertEquals('DEF', $this->getRequestHelper()->getIsoRegionCode($address));
144
+ $address->setRegionCode('DF');
145
+ $this->assertEquals('DF', $this->getRequestHelper()->getIsoRegionCode($address));
146
+ }
147
+
148
+ public function testGetTemplateParamsTemplateMode()
149
+ {
150
+ $this->markTestIncomplete('Depends on PCI release');
151
+
152
+ $config = $this->getModelMock('ops/config', array('getConfigData'));
153
+ $config->expects($this->any())
154
+ ->method('getConfigData')
155
+ ->will($this->returnValue(Netresearch_OPS_Model_Payment_Abstract::TEMPLATE_OPS_TEMPLATE));
156
+ $helper = Mage::helper('ops/payment_request');
157
+ $helper->setConfig($config);
158
+
159
+ $params = $helper->getTemplateParams();
160
+ $this->assertArrayNotHasKey('PARAMPLUS', $params);
161
+ $this->assertArrayNotHasKey('TITLE', $params);
162
+ $this->assertArrayHasKey('TP', $params);
163
+
164
+ }
165
+
166
+ public function testGetTemplateParamsInternalTemplateMode()
167
+ {
168
+ $this->markTestIncomplete('Depends on PCI release');
169
+
170
+ $config = $this->getModelMock('ops/config', array('getConfigData'));
171
+ $config->expects($this->any())
172
+ ->method('getConfigData')
173
+ ->will($this->returnValue(Netresearch_OPS_Model_Payment_Abstract::TEMPLATE_MAGENTO_INTERNAL));
174
+ $helper = Mage::helper('ops/payment_request');
175
+ $helper->setConfig($config);
176
+
177
+ $params = $helper->getTemplateParams();
178
+ $this->assertArrayNotHasKey('PARAMPLUS', $params);
179
+ $this->assertArrayNotHasKey('TITLE', $params);
180
+ $this->assertArrayHasKey('TP', $params);
181
+ $this->assertEquals($config->getPayPageTemplate(), $params['TP']);
182
+
183
+ }
184
+
185
+ public function testGetTemplateParamsNoMode()
186
+ {
187
+ $this->markTestIncomplete('Depends on PCI release');
188
+
189
+ $config = $this->getModelMock('ops/config', array('getConfigData'));
190
+ $config->expects($this->any())
191
+ ->method('getConfigData')
192
+ ->will($this->returnValue(null));
193
+ $helper = Mage::helper('ops/payment_request');
194
+ $helper->setConfig($config);
195
+
196
+ $params = $helper->getTemplateParams();
197
+ $this->assertArrayNotHasKey('PARAMPLUS', $params);
198
+ $this->assertArrayNotHasKey('TITLE', $params);
199
+ $this->assertArrayNotHasKey('TP', $params);
200
+ $this->isEmpty($params);
201
+ }
202
+
203
+ public function testExtractOrderItemParametersWithAllItems()
204
+ {
205
+ $sessionMock = $this->getModelMockBuilder('customer/session')
206
+ ->disableOriginalConstructor()
207
+ ->setMethods(null)
208
+ ->getMock();
209
+ $this->replaceByMock('singleton', 'customer/session', $sessionMock);
210
+
211
+ // setup one item
212
+ $item = Mage::getModel('sales/order_item');
213
+ $item->setId(1);
214
+ $item->setName('Item');
215
+ $item->setBasePriceInclTax(10.00);
216
+ $item->setQtyOrdered(1);
217
+ $item->setTaxPercent(19.00);
218
+ $item->setProductType(Mage_Catalog_Model_Product_Type::TYPE_SIMPLE);
219
+
220
+ $order = $this->getModelMock('sales/order', array('getAllItems'));
221
+ $order->expects($this->once())
222
+ ->method('getAllItems')
223
+ ->will($this->returnValue(array($item)));
224
+
225
+ // prepare discount item
226
+ $order->setBaseDiscountAmount(1.00)
227
+ ->setCouponRuleName('DISCOUNT');
228
+
229
+ //prepare shipping Item
230
+ $order->setShippingDescription('SHIPPING')
231
+ ->setBaseShippingInclTax(5.00)
232
+ ->setIsVirtual(0);
233
+
234
+ $helper = Mage::helper('ops/payment_request');
235
+
236
+ $formFields = $helper->extractOrderItemParameters($order);
237
+
238
+ $this->assertArrayHasKey('ITEMID1', $formFields);
239
+ $this->assertArrayHasKey('ITEMID2', $formFields);
240
+ $this->assertArrayHasKey('ITEMID3', $formFields);
241
+ }
242
+
243
+ public function testExtractOrderItemParametersWithNoItems()
244
+ {
245
+ $sessionMock = $this->getModelMockBuilder('customer/session')
246
+ ->disableOriginalConstructor()
247
+ ->setMethods(null)
248
+ ->getMock();
249
+ $this->replaceByMock('singleton', 'customer/session', $sessionMock);
250
+
251
+ // setup one item
252
+ $item = Mage::getModel('sales/order_item');
253
+ $item->setProductType(Mage_Catalog_Model_Product_Type::TYPE_BUNDLE);
254
+
255
+ $order = $this->getModelMock('sales/order', array('getAllItems'));
256
+ $order->expects($this->once())
257
+ ->method('getAllItems')
258
+ ->will($this->returnValue(array($item)));
259
+
260
+ // prepare discount item
261
+ $order->setBaseDiscountAmount(0.00);
262
+
263
+ //prepare shipping Item
264
+ $order->setIsVirtual(true);
265
+
266
+ $helper = Mage::helper('ops/payment_request');
267
+
268
+ $formFields = $helper->extractOrderItemParameters($order);
269
+
270
+ $this->assertArrayNotHasKey('ITEMID1', $formFields);
271
+ $this->assertArrayNotHasKey('ITEMID2', $formFields);
272
+ $this->assertArrayNotHasKey('ITEMID3', $formFields);
273
+ }
274
+ }
app/code/community/Netresearch/OPS/Test/Helper/PaymentTest.php ADDED
@@ -0,0 +1,815 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Netresearch_OPS_Test_Helper_PaymentTest
3
+ extends EcomDev_PHPUnit_Test_Case
4
+ {
5
+ private $_helper;
6
+ private $store;
7
+
8
+ public function setUp()
9
+ {
10
+ parent::setup();
11
+ $this->_helper = Mage::helper('ops/payment');
12
+ $this->store = Mage::app()->getStore(0)->load(0);
13
+ $this->store->resetConfig();
14
+ }
15
+
16
+ public function testIsPaymentAuthorizeType()
17
+ {
18
+ $this->assertTrue(
19
+ $this->_helper->isPaymentAuthorizeType(
20
+ Netresearch_OPS_Model_Payment_Abstract::OPS_AUTHORIZED
21
+ )
22
+ );
23
+ $this->assertTrue(
24
+ $this->_helper->isPaymentAuthorizeType(
25
+ Netresearch_OPS_Model_Payment_Abstract::OPS_AUTHORIZED_WAITING
26
+ )
27
+ );
28
+ $this->assertTrue(
29
+ $this->_helper->isPaymentAuthorizeType(
30
+ Netresearch_OPS_Model_Payment_Abstract::OPS_AUTHORIZED_UNKNOWN
31
+ )
32
+ );
33
+ $this->assertTrue(
34
+ $this->_helper->isPaymentAuthorizeType(
35
+ Netresearch_OPS_Model_Payment_Abstract::OPS_AWAIT_CUSTOMER_PAYMENT
36
+ )
37
+ );
38
+ $this->assertFalse($this->_helper->isPaymentAuthorizeType(0));
39
+ }
40
+
41
+ public function testIsPaymentCaptureType()
42
+ {
43
+ $this->assertTrue(
44
+ $this->_helper->isPaymentCaptureType(
45
+ Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_REQUESTED
46
+ )
47
+ );
48
+ $this->assertTrue(
49
+ $this->_helper->isPaymentCaptureType(
50
+ Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_PROCESSING
51
+ )
52
+ );
53
+ $this->assertTrue(
54
+ $this->_helper->isPaymentCaptureType(
55
+ Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_UNCERTAIN
56
+ )
57
+ );
58
+ $this->assertFalse($this->_helper->isPaymentCaptureType(0));
59
+ }
60
+
61
+ /**
62
+ * send no invoice mail if it is denied by configuration
63
+ */
64
+ public function testSendNoInvoiceToCustomerIfDenied()
65
+ {
66
+ $this->store->setConfig('payment_services/ops/send_invoice', 0);
67
+ $this->assertFalse(Mage::getModel('ops/config')->getSendInvoice());
68
+ $sentInvoice = $this->getModelMock(
69
+ 'sales/order_invoice', array('getEmailSent', 'sendEmail')
70
+ );
71
+ $sentInvoice->expects($this->any())
72
+ ->method('getEmailSent')
73
+ ->will($this->returnValue(false));
74
+ $sentInvoice->expects($this->never())
75
+ ->method('sendEmail');
76
+ $this->_helper->sendInvoiceToCustomer($sentInvoice);
77
+ }
78
+
79
+ /**
80
+ * send no invoice mail if it was already sent
81
+ */
82
+ public function testSendNoInvoiceToCustomerIfAlreadySent()
83
+ {
84
+ $this->store->setConfig('payment_services/ops/send_invoice', 1);
85
+ $this->assertTrue(Mage::getModel('ops/config')->getSendInvoice());
86
+ $someInvoice = $this->getModelMock(
87
+ 'sales/order_invoice', array('getEmailSent', 'sendEmail')
88
+ );
89
+ $someInvoice->expects($this->any())
90
+ ->method('getEmailSent')
91
+ ->will($this->returnValue(true));
92
+ $someInvoice->expects($this->never())
93
+ ->method('sendEmail');
94
+ $this->_helper->sendInvoiceToCustomer($someInvoice);
95
+ }
96
+
97
+ /**
98
+ * send invoice mail
99
+ */
100
+ public function testSendInvoiceToCustomerIfEnabled()
101
+ {
102
+ $this->store->setConfig('payment_services/ops/send_invoice', 1);
103
+ $this->assertTrue(Mage::getModel('ops/config')->getSendInvoice());
104
+ $anotherInvoice = $this->getModelMock(
105
+ 'sales/order_invoice', array('getEmailSent', 'sendEmail')
106
+ );
107
+ $anotherInvoice->expects($this->any())
108
+ ->method('getEmailSent')
109
+ ->will($this->returnValue(false));
110
+ $anotherInvoice->expects($this->once())
111
+ ->method('sendEmail')
112
+ ->with($this->equalTo(true));
113
+ $this->_helper->sendInvoiceToCustomer($anotherInvoice);
114
+ }
115
+
116
+ public function testPrepareParamsAndSort()
117
+ {
118
+ $params = array(
119
+ 'CVC' => '123',
120
+ 'CARDNO' => '4111111111111111',
121
+ 'CN' => 'JohnSmith',
122
+ 'PSPID' => 'test1',
123
+ 'ED' => '1212',
124
+ 'ACCEPTURL' => 'https=//www.myshop.com/ok.html',
125
+ 'EXCEPTIONURL' => 'https=//www.myshop.com/nok.html',
126
+ 'BRAND' => 'VISA',
127
+ );
128
+ $sortedParams = array(
129
+ 'ACCEPTURL' => array('key' => 'ACCEPTURL',
130
+ 'value' => 'https=//www.myshop.com/ok.html'),
131
+ 'BRAND' => array('key' => 'BRAND', 'value' => 'VISA'),
132
+ 'CARDNO' => array('key' => 'CARDNO',
133
+ 'value' => '4111111111111111'),
134
+ 'CN' => array('key' => 'CN', 'value' => 'JohnSmith'),
135
+ 'CVC' => array('key' => 'CVC', 'value' => '123'),
136
+ 'ED' => array('key' => 'ED', 'value' => '1212'),
137
+ 'EXCEPTIONURL' => array('key' => 'EXCEPTIONURL',
138
+ 'value' => 'https=//www.myshop.com/nok.html'),
139
+ 'PSPID' => array('key' => 'PSPID', 'value' => 'test1'),
140
+ );
141
+ $secret = 'Mysecretsig1875!?';
142
+ $shaInSet
143
+ =
144
+ 'ACCEPTURL=https=//www.myshop.com/ok.htmlMysecretsig1875!?BRAND=VISAMysecretsig1875!?'
145
+ . 'CARDNO=4111111111111111Mysecretsig1875!?CN=JohnSmithMysecretsig1875!?CVC=123Mysecretsig1875!?'
146
+ . 'ED=1212Mysecretsig1875!?EXCEPTIONURL=https=//www.myshop.com/nok.htmlMysecretsig1875!?'
147
+ . 'PSPID=test1Mysecretsig1875!?';
148
+ $key = 'a28dc9fe69b63fe81da92471fefa80aca3f4851a';
149
+ $this->assertEquals(
150
+ $sortedParams, $this->_helper->prepareParamsAndSort($params)
151
+ );
152
+ $this->assertEquals(
153
+ $shaInSet, $this->_helper->getSHAInSet($params, $secret)
154
+ );
155
+ $this->assertEquals($key, $this->_helper->shaCrypt($shaInSet, $secret));
156
+ }
157
+
158
+ public function testHandleUnknownStatus()
159
+ {
160
+ $order = $this->getModelMock('sales/order', array('save'));
161
+ $order->expects($this->any())
162
+ ->method('save')
163
+ ->will($this->returnValue(true));
164
+ $order->setState(
165
+ Mage_Sales_Model_Order::STATE_NEW,
166
+ Mage_Sales_Model_Order::STATE_NEW
167
+ );
168
+ $statusHistoryCount = $order->getStatusHistoryCollection()->count();
169
+ Mage::helper('ops/payment')->handleUnknownStatus($order);
170
+ $this->assertEquals(
171
+ Mage_Sales_Model_Order::STATE_PENDING_PAYMENT, $order->getState()
172
+ );
173
+ $this->assertTrue(
174
+ $statusHistoryCount < $order->getStatusHistoryCollection()->count()
175
+ );
176
+ $statusHistoryCount = $order->getStatusHistoryCollection()->count();
177
+ $order->setState(
178
+ Mage_Sales_Model_Order::STATE_PROCESSING,
179
+ Mage_Sales_Model_Order::STATE_PROCESSING
180
+ );
181
+
182
+ Mage::helper('ops/payment')->handleUnknownStatus($order);
183
+ $this->assertEquals(
184
+ Mage_Sales_Model_Order::STATE_PROCESSING, $order->getState()
185
+ );
186
+ $this->assertTrue(
187
+ $statusHistoryCount < $order->getStatusHistoryCollection()->count()
188
+ );
189
+ }
190
+
191
+ /**
192
+ * @loadFixture ../../../var/fixtures/orders.yaml
193
+ */
194
+ public function testGetBaseGrandTotalFromSalesObject()
195
+ {
196
+ $helper = Mage::helper('ops/payment');
197
+ $order = Mage::getModel('sales/order')->load(14);
198
+ $amount = $helper->getBaseGrandTotalFromSalesObject($order);
199
+ $this->assertEquals($order->getBaseGrandTotal(), $amount);
200
+ $order = Mage::getModel('sales/order')->load(15);
201
+ $amount = $helper->getBaseGrandTotalFromSalesObject($order);
202
+ $this->assertEquals($order->getBaseGrandTotal(), $amount);
203
+ $quote = Mage::getModel('sales/quote')->load(1);
204
+ $amount = $helper->getBaseGrandTotalFromSalesObject($quote);
205
+ $this->assertEquals($quote->getBaseGrandTotal(), $amount);
206
+ $quote = Mage::getModel('sales/quote')->load(2);
207
+ $amount = $helper->getBaseGrandTotalFromSalesObject($quote);
208
+ $this->assertEquals($quote->getBaseGrandTotal(), $amount);
209
+ $someOtherObject = new Varien_Object();
210
+ $this->setExpectedException('Mage_Core_Exception');
211
+ $helper->getBaseGrandTotalFromSalesObject($someOtherObject);
212
+ }
213
+
214
+ /**
215
+ * @loadFixture ../../../var/fixtures/orders.yaml
216
+ */
217
+ public function testSaveOpsRefundOperationCodeToPayment()
218
+ {
219
+ $order = Mage::getModel('sales/order')->load(11);
220
+ $payment = $order->getPayment();
221
+ $helper = Mage::helper('ops/payment');
222
+
223
+ // no last refund operation code is set if an empty string is passed
224
+ $helper->saveOpsRefundOperationCodeToPayment($payment, '');
225
+ $this->assertFalse(
226
+ array_key_exists(
227
+ 'lastRefundOperationCode', $payment->getAdditionalInformation()
228
+ )
229
+ );
230
+
231
+ // no last refund operation code is set if it's no refund operation code
232
+ $helper->saveOpsRefundOperationCodeToPayment(
233
+ $payment, Netresearch_OPS_Model_Payment_Abstract::OPS_CAPTURE_FULL
234
+ );
235
+ $this->assertFalse(
236
+ array_key_exists(
237
+ 'lastRefundOperationCode', $payment->getAdditionalInformation()
238
+ )
239
+ );
240
+
241
+ // last ops refund code is present if a valid refund code is passed
242
+ $helper->saveOpsRefundOperationCodeToPayment(
243
+ $payment, Netresearch_OPS_Model_Payment_Abstract::OPS_REFUND_PARTIAL
244
+ );
245
+ $this->assertTrue(
246
+ array_key_exists(
247
+ 'lastRefundOperationCode', $payment->getAdditionalInformation()
248
+ )
249
+ );
250
+ $this->assertEquals(
251
+ Netresearch_OPS_Model_Payment_Abstract::OPS_REFUND_PARTIAL,
252
+ $payment->getAdditionalInformation('lastRefundOperationCode')
253
+ );
254
+
255
+ // last ops refund code is present if a valid refund code is passed and will override a previous one
256
+ $helper->saveOpsRefundOperationCodeToPayment(
257
+ $payment, Netresearch_OPS_Model_Payment_Abstract::OPS_REFUND_FULL
258
+ );
259
+ $this->assertTrue(
260
+ array_key_exists(
261
+ 'lastRefundOperationCode', $payment->getAdditionalInformation()
262
+ )
263
+ );
264
+ $this->assertEquals(
265
+ Netresearch_OPS_Model_Payment_Abstract::OPS_REFUND_FULL,
266
+ $payment->getAdditionalInformation('lastRefundOperationCode')
267
+ );
268
+ }
269
+
270
+ /**
271
+ * @loadFixture ../../../var/fixtures/orders.yaml
272
+ */
273
+ public function testSetCanRefundToPayment()
274
+ {
275
+
276
+ $helper = Mage::helper('ops/payment');
277
+ $order = Mage::getModel('sales/order')->load(11);
278
+ $payment = $order->getPayment();
279
+ $helper->setCanRefundToPayment($payment);
280
+ $this->assertFalse(
281
+ array_key_exists('canRefund', $payment->getAdditionalInformation())
282
+ );
283
+
284
+ $order = Mage::getModel('sales/order')->load(15);
285
+ $payment = $order->getPayment();
286
+ $helper->setCanRefundToPayment($payment);
287
+ $this->assertTrue($payment->getAdditionalInformation('canRefund'));
288
+
289
+ $order = Mage::getModel('sales/order')->load(16);
290
+ $payment = $order->getPayment();
291
+ $helper->setCanRefundToPayment($payment);
292
+ $this->assertFalse($payment->getAdditionalInformation('canRefund'));
293
+ }
294
+
295
+ /**
296
+ * @loadFixture ../../../var/fixtures/orders.yaml
297
+ *
298
+ */
299
+ public function testSetPaymentTransactionInformation()
300
+ {
301
+ $order = Mage::getModel('sales/order')->load(15);
302
+ $reflectionClass = new ReflectionClass(get_class(
303
+ Mage::helper('ops/payment')
304
+ ));
305
+ $method = $reflectionClass->getMethod(
306
+ 'setPaymentTransactionInformation'
307
+ );
308
+ $method->setAccessible(true);
309
+ $paymentHelper = Mage::helper('ops/payment');
310
+ $params = array(
311
+ 'PAYID' => '0815',
312
+ 'STATUS' => 9
313
+ );
314
+ $method->invoke(
315
+ $paymentHelper, $order->getPayment(), $params, 'accept'
316
+ );
317
+ $this->assertEquals(
318
+ '0815', $order->getPayment()->getAdditionalInformation('paymentId')
319
+ );
320
+ $this->assertEquals(
321
+ 9, $order->getPayment()->getAdditionalInformation('status')
322
+ );
323
+
324
+ $params = array(
325
+ 'PAYID' => '0815',
326
+ 'STATUS' => 9,
327
+ 'ACCEPTANCE' => ''
328
+ );
329
+ $method->invoke(
330
+ $paymentHelper, $order->getPayment(), $params, 'accept'
331
+ );
332
+ $this->assertEquals(
333
+ '0815', $order->getPayment()->getAdditionalInformation('paymentId')
334
+ );
335
+ $this->assertEquals(
336
+ '', $order->getPayment()->getAdditionalInformation('acceptance')
337
+ );
338
+
339
+ $params = array(
340
+ 'PAYID' => '0815',
341
+ 'STATUS' => 9,
342
+ 'ACCEPTANCE' => 'Akzeptanz'
343
+ );
344
+ $method->invoke(
345
+ $paymentHelper, $order->getPayment(), $params, 'accept'
346
+ );
347
+ $this->assertEquals(
348
+ '0815', $order->getPayment()->getAdditionalInformation('paymentId')
349
+ );
350
+ $this->assertEquals(
351
+ 'Akzeptanz',
352
+ $order->getPayment()->getAdditionalInformation('acceptance')
353
+ );
354
+
355
+ $params = array(
356
+ 'PAYID' => '0815',
357
+ 'STATUS' => 9,
358
+ 'ACCEPTANCE' => 'Akzeptanz',
359
+ 'HTML_ANSWER' => '3D Secure',
360
+ 'BRAND' => 'Brand'
361
+ );
362
+ $method->invoke(
363
+ $paymentHelper, $order->getPayment(), $params, 'accept'
364
+ );
365
+ $this->assertEquals(
366
+ '0815', $order->getPayment()->getAdditionalInformation('paymentId')
367
+ );
368
+ $this->assertEquals(
369
+ 'Akzeptanz',
370
+ $order->getPayment()->getAdditionalInformation('acceptance')
371
+ );
372
+ $this->assertEquals(
373
+ '3D Secure',
374
+ $order->getPayment()->getAdditionalInformation('HTML_ANSWER')
375
+ );
376
+ $this->assertEquals(
377
+ 'Brand',
378
+ $order->getPayment()->getAdditionalInformation('CC_BRAND')
379
+ );
380
+ }
381
+
382
+
383
+ /**
384
+ * @loadFixture ../../../var/fixtures/orders.yaml
385
+ *
386
+ */
387
+ public function testApplyStateForOrder()
388
+ {
389
+ $order = Mage::getModel('sales/order')->load(19);
390
+ $paymenthelperMock = $this->getHelperMock(
391
+ 'ops/payment', array(
392
+ 'acceptOrder',
393
+ 'waitOrder',
394
+ 'declineOrder',
395
+ 'cancelOrder',
396
+ 'handleException'
397
+ )
398
+ );
399
+
400
+ // assertion for OPS_OPEN_INVOICE_DE_PROCESSED = 41000001
401
+ $this->assertEquals(
402
+ 'accept', $paymenthelperMock->applyStateForOrder(
403
+ $order,
404
+ array('STATUS' => Netresearch_OPS_Model_Payment_Abstract::OPS_AWAIT_CUSTOMER_PAYMENT)
405
+ )
406
+ );
407
+
408
+ // assertion for OPS_WAITING_FOR_IDENTIFICATION = 46
409
+ $this->assertEquals(
410
+ 'accept', $paymenthelperMock->applyStateForOrder(
411
+ $order,
412
+ array('STATUS' => Netresearch_OPS_Model_Payment_Abstract::OPS_WAITING_FOR_IDENTIFICATION)
413
+ )
414
+ );
415
+
416
+ // assertion for OPS_AUTHORIZED = 5
417
+ $this->assertEquals(
418
+ 'accept', $paymenthelperMock->applyStateForOrder(
419
+ $order,
420
+ array('STATUS' => Netresearch_OPS_Model_Payment_Abstract::OPS_AUTHORIZED)
421
+ )
422
+ );
423
+ // assertion for OPS_AUTHORIZED_KWIXO = 50
424
+ $this->assertEquals(
425
+ 'accept', $paymenthelperMock->applyStateForOrder(
426
+ $order,
427
+ array('STATUS' => Netresearch_OPS_Model_Payment_Abstract::OPS_AUTHORIZED_KWIXO)
428
+ )
429
+ );
430
+
431
+ // assertion for OPS_AUTHORIZED_WAITING = 51
432
+ $this->assertEquals(
433
+ 'accept', $paymenthelperMock->applyStateForOrder(
434
+ $order,
435
+ array('STATUS' => Netresearch_OPS_Model_Payment_Abstract::OPS_AUTHORIZED_WAITING)
436
+ )
437
+ );
438
+
439
+ // assertion for OPS_AUTHORIZED_UNKNOWN = 52
440
+ $this->assertEquals(
441
+ 'accept', $paymenthelperMock->applyStateForOrder(
442
+ $order,
443
+ array('STATUS' => Netresearch_OPS_Model_Payment_Abstract::OPS_AUTHORIZED_UNKNOWN)
444
+ )
445
+ );
446
+
447
+ // assertion for OPS_AWAIT_CUSTOMER_PAYMENT = 41
448
+ $this->assertEquals(
449
+ 'accept', $paymenthelperMock->applyStateForOrder(
450
+ $order,
451
+ array('STATUS' => Netresearch_OPS_Model_Payment_Abstract::OPS_AWAIT_CUSTOMER_PAYMENT)
452
+ )
453
+ );
454
+
455
+ // assertion for OPS_PAYMENT_REQUESTED = 9
456
+ $this->assertEquals(
457
+ 'accept', $paymenthelperMock->applyStateForOrder(
458
+ $order,
459
+ array('STATUS' => Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_REQUESTED)
460
+ )
461
+ );
462
+ // assertion for OPS_PAYMENT_PROCESSING = 91
463
+ $this->assertEquals(
464
+ 'accept', $paymenthelperMock->applyStateForOrder(
465
+ $order,
466
+ array('STATUS' => Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_PROCESSING)
467
+ )
468
+ );
469
+ // assertion for OPS_OPEN_INVOICE_DE_PROCESSED = 41000001
470
+ $this->assertEquals(
471
+ 'accept', $paymenthelperMock->applyStateForOrder(
472
+ $order,
473
+ array('STATUS' => Netresearch_OPS_Model_Payment_Abstract::OPS_OPEN_INVOICE_DE_PROCESSED)
474
+ )
475
+ );
476
+ // assertion for OPS_AUTH_REFUSED = 2
477
+ $this->assertEquals(
478
+ 'decline', $paymenthelperMock->applyStateForOrder(
479
+ $order,
480
+ array('STATUS' => Netresearch_OPS_Model_Payment_Abstract::OPS_AUTH_REFUSED)
481
+ )
482
+ );
483
+ // assertion for OPS_PAYMENT_REFUSED = 93
484
+ $this->assertEquals(
485
+ 'decline', $paymenthelperMock->applyStateForOrder(
486
+ $order,
487
+ array('STATUS' => Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_REFUSED)
488
+ )
489
+ );
490
+ // assertion for OPS_PAYMENT_CANCELED_BY_CUSTOMER = 1
491
+ $this->assertEquals(
492
+ 'cancel', $paymenthelperMock->applyStateForOrder(
493
+ $order,
494
+ array(
495
+ 'STATUS' => Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_CANCELED_BY_CUSTOMER,
496
+ 'PAYID' => 4711
497
+ )
498
+ )
499
+ );
500
+ // assertion for exception case
501
+ $this->assertEquals(
502
+ 'exception', $paymenthelperMock->applyStateForOrder(
503
+ $order,
504
+ array('STATUS' => 'default')
505
+ )
506
+ );
507
+ }
508
+
509
+ /**
510
+ * @loadFixture ../../../var/fixtures/orders.yaml
511
+ */
512
+ public function testForceAuthorize()
513
+ {
514
+ $helper = Mage::helper('ops/payment');
515
+ $reflectionClass = new ReflectionClass(get_class($helper));
516
+ $method = $reflectionClass->getMethod("forceAuthorize");
517
+ $method->setAccessible(true);
518
+
519
+ $order = Mage::getModel('sales/order')->load(11);
520
+ $this->assertFalse($method->invoke($helper, $order));
521
+
522
+ $order = Mage::getModel('sales/order')->load(27);
523
+ $this->assertTrue($method->invoke($helper, $order));
524
+
525
+ $order = Mage::getModel('sales/order')->load(28);
526
+ $this->assertTrue($method->invoke($helper, $order));
527
+
528
+ // $order = Mage::getModel('sales/order')->load(29);
529
+ // $this->assertTrue($method->invoke($helper, $order));
530
+ }
531
+
532
+ public function testCheckIfCCisInCheckoutMethodsFalse()
533
+ {
534
+ $testMethod = $this->getProtectedMethod($this->_helper,'checkIfCCisInCheckoutMethods');
535
+ $paymentMethods = new Varien_Object();
536
+ $paymentMethods->setCode('ops_iDeal');
537
+ $this->assertFalse($testMethod->invoke($this->_helper, array($paymentMethods)));
538
+
539
+
540
+ }
541
+
542
+ public function testCheckIfCCisInCheckoutMethodsTrue()
543
+ {
544
+ $testMethod = $this->getProtectedMethod($this->_helper,'checkIfCCisInCheckoutMethods');
545
+ $paymentMethods = new Varien_Object();
546
+ $paymentMethods->setCode('ops_cc');
547
+ $this->assertTrue($testMethod->invoke($this->_helper, array($paymentMethods)));
548
+
549
+
550
+ }
551
+
552
+ public function testAddCCForZeroAmountCheckout()
553
+ {
554
+ $block = new Mage_Payment_Block_Form_Container();
555
+ $method = new Varien_Object();
556
+ $method->setCode('ops_ideal');
557
+ $block->setData('methods',array($method));
558
+ $quote = Mage::getModel('sales/quote');
559
+ $block->setQuote($quote);
560
+
561
+ $featureModelMock = $this->getModelMock('ops/payment_features_zeroAmountAuth', array('isCCAndZeroAmountAuthAllowed'));
562
+ $featureModelMock->expects($this->any())
563
+ ->method('isCCAndZeroAmountAuthAllowed')
564
+ ->will($this->returnValue(true));
565
+ $this->replaceByMock('model', 'ops/payment_features_zeroAmountAuth', $featureModelMock);
566
+
567
+ $this->_helper->addCCForZeroAmountCheckout($block);
568
+
569
+ $methods = $block->getMethods();
570
+ $this->assertTrue( $methods[1] instanceof Netresearch_OPS_Model_Payment_Cc);
571
+ $this->assertFalse( $methods[0] instanceof Netresearch_OPS_Model_Payment_Cc);
572
+
573
+ }
574
+
575
+
576
+ protected function getProtectedMethod($class, $method)
577
+ {
578
+ $reflection_class = new ReflectionClass(get_class($class));
579
+ $method = $reflection_class->getMethod($method);
580
+ $method->setAccessible(true);
581
+ return $method;
582
+ }
583
+
584
+
585
+ public function testIsInlinePaymentWithOrderIdIsTrueForInlineCcWithOrderId()
586
+ {
587
+ $ccMock = $this->getModelMock('ops/payment_cc', array('getConfigPaymentAction', 'hasBrandAliasInterfaceSupport'));
588
+ $ccMock->expects($this->once())
589
+ ->method('getConfigPaymentAction')
590
+ ->will($this->returnValue('authorize_capture'));
591
+ $ccMock->expects($this->once())
592
+ ->method('hasBrandAliasInterfaceSupport')
593
+ ->will($this->returnValue(true));
594
+
595
+
596
+ $payment = $this->getModelMock('payment/info', array('getMethodInstance'));
597
+ $payment->expects($this->any())
598
+ ->method('getMethodInstance')
599
+ ->will($this->returnValue($ccMock));
600
+
601
+ $this->assertTrue(Mage::helper('ops/payment')->isInlinePaymentWithOrderId($payment));
602
+ }
603
+
604
+ public function testIsInlinePaymentWithOrderIdIsFalseForRedirectCcWithOrderId()
605
+ {
606
+ $ccMock = $this->getModelMock('ops/payment_cc', array('getConfigPaymentAction', 'hasBrandAliasInterfaceSupport'));
607
+ $ccMock->expects($this->any())
608
+ ->method('getConfigPaymentAction')
609
+ ->will($this->returnValue('authorize'));
610
+ $ccMock->expects($this->once())
611
+ ->method('hasBrandAliasInterfaceSupport')
612
+ ->will($this->returnValue(false));
613
+
614
+
615
+ $payment = $this->getModelMock('payment/info', array('getMethodInstance'));
616
+ $payment->expects($this->any())
617
+ ->method('getMethodInstance')
618
+ ->will($this->returnValue($ccMock));
619
+
620
+ $this->assertFalse(Mage::helper('ops/payment')->isInlinePaymentWithOrderId($payment));
621
+ }
622
+
623
+ public function testIsInlinePaymentWithOrderIdIsFalseIfQuoteIdIsConfigured()
624
+ {
625
+ $ccMock = $this->getModelMock('ops/payment_cc', array('getConfigPaymentAction', 'hasBrandAliasInterfaceSupport'));
626
+ $ccMock->expects($this->once())
627
+ ->method('getConfigPaymentAction')
628
+ ->will($this->returnValue(''));
629
+ $ccMock->expects($this->once())
630
+ ->method('hasBrandAliasInterfaceSupport')
631
+ ->will($this->returnValue(true));
632
+
633
+ $payment = $this->getModelMock('payment/info', array('getMethodInstance'));
634
+ $payment->expects($this->any())
635
+ ->method('getMethodInstance')
636
+ ->will($this->returnValue($ccMock));
637
+
638
+ $this->assertFalse(Mage::helper('ops/payment')->isInlinePaymentWithOrderId($payment));
639
+ }
640
+
641
+ public function testIsInlinePaymentWithOrderIdIsFalseIfQuoteIdIsConfiguredForDirectDebit()
642
+ {
643
+ $directDebitMock = $this->getModelMock('ops/payment_directDebit', array('getConfigPaymentAction'));
644
+ $directDebitMock->expects($this->once())
645
+ ->method('getConfigPaymentAction')
646
+ ->will($this->returnValue(''));
647
+
648
+ $payment = $this->getModelMock('payment/info', array('getMethodInstance'));
649
+ $payment->expects($this->any())
650
+ ->method('getMethodInstance')
651
+ ->will($this->returnValue($directDebitMock));
652
+
653
+ $this->assertFalse(Mage::helper('ops/payment')->isInlinePaymentWithOrderId($payment));
654
+ }
655
+ public function testIsInlinePaymentWithOrderIdIsTrueIfOrderIdIsConfiguredForDirectDebit()
656
+ {
657
+ $directDebitMock = $this->getModelMock('ops/payment_directDebit', array('getConfigPaymentAction'));
658
+ $directDebitMock->expects($this->once())
659
+ ->method('getConfigPaymentAction')
660
+ ->will($this->returnValue('authorize'));
661
+
662
+ $payment = $this->getModelMock('payment/info', array('getMethodInstance'));
663
+ $payment->expects($this->any())
664
+ ->method('getMethodInstance')
665
+ ->will($this->returnValue($directDebitMock));
666
+
667
+ $this->assertTrue(Mage::helper('ops/payment')->isInlinePaymentWithOrderId($payment));
668
+ }
669
+
670
+ public function testIsInlinePaymentWithQuoteId()
671
+ {
672
+ $directDebitMock = $this->getModelMock('ops/payment_directDebit', array('getConfigPaymentAction'));
673
+ $directDebitMock->expects($this->once())
674
+ ->method('getConfigPaymentAction')
675
+ ->will($this->returnValue(''));
676
+
677
+ $payment = $this->getModelMock('payment/info', array('getMethodInstance'));
678
+ $payment->expects($this->any())
679
+ ->method('getMethodInstance')
680
+ ->will($this->returnValue($directDebitMock));
681
+
682
+ $this->assertTrue(Mage::helper('ops/payment')->isInlinePaymentWithQuoteId($payment));
683
+ }
684
+
685
+ public function testSetInvoicesToPaid()
686
+ {
687
+ $order = $this->getModelMock('sales/order', array('save', 'getInvoiceCollection'));
688
+ $order->expects($this->any())
689
+ ->method('getInvoiceCollection')
690
+ ->will($this->returnValue(array($this->getModelMock('sales/order_invoice', array('save')))));
691
+ Mage::helper('ops/payment')->setInvoicesToPaid($order);
692
+ foreach ($order->getInvoiceCollection() as $invoice) {
693
+ $this->assertEquals(Mage_Sales_Model_Order_Invoice::STATE_PAID, $invoice->getState());
694
+ }
695
+ }
696
+
697
+ public function testCancelOrder()
698
+ {
699
+ $params = array('status' => 2, 'payid' => 4711);
700
+ $status = Mage_Sales_Model_Order::STATE_CANCELED;
701
+ $comment = 'TestComment';
702
+
703
+ $order = $this->getModelMock('sales/order', array('save', 'cancel', 'setState'));
704
+ $order->expects($this->once())
705
+ ->method('save');
706
+ $order->expects($this->once())
707
+ ->method('cancel');
708
+ $order->expects($this->once())
709
+ ->method('setState')
710
+ ->with(Mage_Sales_Model_Order::STATE_CANCELED, $status, $comment)
711
+ ;
712
+
713
+
714
+ $paymentHelperMock = $this->getHelperMock('ops/payment', array('setPaymentTransactionInformation', '_getCheckout', 'cancelInvoices'));
715
+ $paymentHelperMock->expects($this->any())
716
+ ->method('setPaymentTransactionInformation');
717
+ $paymentHelperMock->expects($this->any())
718
+ ->method('_getCheckout')
719
+ ->will($this->returnValue($this->getModelMock('checkout/session', array('init', 'save'))))
720
+ ;
721
+
722
+ $paymentHelperMock->cancelOrder($order, $params, $status, $comment);
723
+ Mage::unregister('ops_auto_void');
724
+
725
+ }
726
+
727
+ /**
728
+ * @expectedException Mage_Core_Exception
729
+ */
730
+ public function testCancelOrderWithException()
731
+ {
732
+ $params = array('status' => 2, 'payid' => 4711);
733
+ $status = Mage_Sales_Model_Order::STATE_CANCELED;
734
+ $comment = 'TestComment';
735
+
736
+ $order = $this->getModelMock('sales/order', array('save', 'cancel', 'setState'));
737
+ $order->expects($this->any())
738
+ ->method('cancel')
739
+ ->will($this->throwException(new Mage_Core_Exception('cancel failed')));
740
+ ;
741
+
742
+ $paymentHelperMock = $this->getHelperMock('ops/payment', array('_getCheckout'));
743
+
744
+ $paymentHelperMock->expects($this->any())
745
+ ->method('_getCheckout')
746
+ ->will($this->returnValue($this->getModelMock('checkout/session', array('init', 'save'))))
747
+ ;
748
+
749
+ $paymentHelperMock->cancelOrder($order, $params, $status, $comment);
750
+ Mage::unregister('ops_auto_void');
751
+ }
752
+
753
+ public function testDeclineOrder()
754
+ {
755
+ Mage::unregister('ops_auto_void');
756
+ $params = array('STATUS' => 2, 'PAYID' => 4711);
757
+ $status = Mage_Sales_Model_Order::STATE_CANCELED;
758
+ $comment = 'TestComment';
759
+
760
+ $order = $this->getModelMock('sales/order', array('save', 'cancel', 'setState', 'getPayment'));
761
+ $order->expects($this->once())
762
+ ->method('cancel')
763
+ ;
764
+ $order->expects($this->once())
765
+ ->method('getPayment')
766
+ ->will($this->returnValue($this->getModelMock('sales/order_payment', array('save'))));
767
+ ;
768
+
769
+ $paymentHelperMock = $this->getHelperMock('ops/payment', array('setPaymentTransactionInformation', '_getCheckout', 'cancelInvoices'));
770
+ $paymentHelperMock->expects($this->once())
771
+ ->method('setPaymentTransactionInformation');
772
+ $paymentHelperMock->expects($this->once())
773
+ ->method('cancelInvoices');
774
+
775
+ $paymentHelperMock->expects($this->any())
776
+ ->method('_getCheckout')
777
+ ->will($this->returnValue($this->getModelMock('checkout/session', array('init', 'save'))))
778
+ ;
779
+
780
+ $paymentHelperMock->declineOrder($order, $params);
781
+
782
+ }
783
+
784
+ /**
785
+ * @expectedException Mage_Core_Exception
786
+ */
787
+ public function testDeclineOrderWithException()
788
+ {
789
+ Mage::unregister('ops_auto_void');
790
+ $params = array('STATUS' => 2, 'PAYID' => 4711);
791
+ $status = Mage_Sales_Model_Order::STATE_CANCELED;
792
+ $comment = 'TestComment';
793
+
794
+ $order = $this->getModelMock('sales/order', array('save', 'cancel', 'setState'));
795
+ $order->expects($this->once())
796
+ ->method('cancel')
797
+ ;
798
+
799
+
800
+ $paymentHelperMock = $this->getHelperMock('ops/payment', array('setPaymentTransactionInformation', '_getCheckout', 'cancelInvoices'));
801
+ $paymentHelperMock->expects($this->never())
802
+ ->method('setPaymentTransactionInformation');
803
+ $paymentHelperMock->expects($this->once())
804
+ ->method('cancelInvoices')
805
+ ->will($this->throwException(new Mage_Core_Exception('exceptional case')));
806
+
807
+ $paymentHelperMock->expects($this->any())
808
+ ->method('_getCheckout')
809
+ ->will($this->returnValue($this->getModelMock('checkout/session', array('init', 'save'))))
810
+ ;
811
+
812
+ $paymentHelperMock->declineOrder($order, $params);
813
+
814
+ }
815
+ }
app/code/community/Netresearch/OPS/Test/Helper/PaymentTest/fixtures/.gitkeep ADDED
File without changes
app/code/community/Netresearch/OPS/Test/Helper/QuoteTest.php ADDED
@@ -0,0 +1,185 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Michael Lühr <michael.luehr@netresearch.de>
4
+ * @category Netresearch
5
+ * @package Netresearch_OPS
6
+ * @copyright Copyright (c) 2013 Netresearch GmbH & Co. KG (http://www.netresearch.de)
7
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
8
+ */
9
+
10
+ class Netresearch_OPS_Test_Helper_QuoteTest extends EcomDev_PHPUnit_Test_Case
11
+ {
12
+
13
+ public function testGetDataHelper()
14
+ {
15
+ $this->assertTrue(Mage::helper('ops/quote')->getDataHelper() instanceof Netresearch_OPS_Helper_Data);
16
+ }
17
+
18
+ /**
19
+ * @loadFixture ../../../var/fixtures/orders.yaml
20
+ */
21
+ public function testCleanUpOldPaymentInformation()
22
+ {
23
+ $payment = Mage::getModel('sales/quote_payment')->load(3);
24
+ $this->assertArrayHasKey('cvc', $payment->getAdditionalInformation());
25
+ Mage::helper('ops/quote')->cleanUpOldPaymentInformation();
26
+ $payment = Mage::getModel('sales/quote_payment')->load(3);
27
+ $this->assertArrayNotHasKey(
28
+ 'cvc', $payment->getAdditionalInformation()
29
+ );
30
+ }
31
+
32
+ public function testGetQuoteCurrency()
33
+ {
34
+ $quote = Mage::getModel('sales/quote');
35
+ $this->assertEquals(
36
+ Mage::app()->getStore($quote->getStoreId())->getBaseCurrencyCode(),
37
+ Mage::helper('ops/quote')->getQuoteCurrency($quote)
38
+ );
39
+ $forcedCurrency = new Varien_Object();
40
+ $forcedCurrency->setCode('USD');
41
+ $quote->setForcedCurrency($forcedCurrency);
42
+ $this->assertEquals(
43
+ 'USD', Mage::helper('ops/quote')->getQuoteCurrency($quote)
44
+ );
45
+ }
46
+
47
+ public function testGetPaymentActionForAuthorize()
48
+ {
49
+ $order = Mage::getModel('sales/order');
50
+ $payment = Mage::getModel('sales/order_payment');
51
+ $order->setPayment($payment);
52
+ $modelMock = $this->getModelMock(
53
+ 'ops/config', array('getPaymentAction')
54
+ );
55
+ $modelMock->expects($this->any())
56
+ ->method('getPaymentAction')
57
+ ->will(
58
+ $this->returnValue(
59
+ 'Netresearch_OPS_Model_Payment_Abstract::OPS_AUTHORIZE_ACTION'
60
+ )
61
+ );
62
+ $this->replaceByMock('model', 'ops/config', $modelMock);
63
+ $helper = Mage::helper('ops/quote');
64
+ $this->assertEquals(
65
+ Netresearch_OPS_Model_Payment_Abstract::OPS_AUTHORIZE_ACTION,
66
+ $helper->getPaymentAction($order)
67
+ );
68
+ $order->getPayment()->setAdditionalInformation(
69
+ 'PM', 'Direct Debits DE'
70
+ );
71
+ $this->assertEquals(
72
+ Netresearch_OPS_Model_Payment_Abstract::OPS_AUTHORIZE_ACTION,
73
+ $helper->getPaymentAction($order)
74
+ );
75
+ $order->getPayment()->setAdditionalInformation(
76
+ 'PM', 'Direct Debits AT'
77
+ );
78
+ $this->assertEquals(
79
+ Netresearch_OPS_Model_Payment_Abstract::OPS_AUTHORIZE_ACTION,
80
+ $helper->getPaymentAction($order)
81
+ );
82
+ $order->getPayment()->setAdditionalInformation(
83
+ 'PM', 'Direct Debits NL'
84
+ );
85
+ $this->assertEquals(
86
+ Netresearch_OPS_Model_Payment_Abstract::OPS_AUTHORIZE_ACTION,
87
+ $helper->getPaymentAction($order)
88
+ );
89
+ }
90
+
91
+ public function testGetPaymentActionForAuthorizeCapture()
92
+ {
93
+ $order = Mage::getModel('sales/order');
94
+ $payment = Mage::getModel('sales/order_payment');
95
+ $order->setPayment($payment);
96
+ $modelMock = $this->getModelMock(
97
+ 'ops/config', array('getPaymentAction')
98
+ );
99
+ $modelMock->expects($this->any())
100
+ ->method('getPaymentAction')
101
+ ->will($this->returnValue('authorize_capture'));
102
+ $this->replaceByMock('model', 'ops/config', $modelMock);
103
+ $helper = Mage::helper('ops/quote');
104
+ $this->assertEquals(
105
+ Netresearch_OPS_Model_Payment_Abstract::OPS_AUTHORIZE_CAPTURE_ACTION,
106
+ $helper->getPaymentAction($order)
107
+ );
108
+ $order->getPayment()->setAdditionalInformation(
109
+ 'PM', 'Direct Debits DE'
110
+ );
111
+ $this->assertEquals(
112
+ Netresearch_OPS_Model_Payment_Abstract::OPS_AUTHORIZE_CAPTURE_ACTION,
113
+ $helper->getPaymentAction($order)
114
+ );
115
+ $order->getPayment()->setAdditionalInformation(
116
+ 'PM', 'Direct Debits AT'
117
+ );
118
+ $this->assertEquals(
119
+ Netresearch_OPS_Model_Payment_Abstract::OPS_AUTHORIZE_CAPTURE_ACTION,
120
+ $helper->getPaymentAction($order)
121
+ );
122
+ $order->getPayment()->setAdditionalInformation(
123
+ 'PM', 'Direct Debits NL'
124
+ );
125
+ $this->assertEquals(
126
+ Netresearch_OPS_Model_Payment_Abstract::OPS_CAPTURE_DIRECTDEBIT_NL,
127
+ $helper->getPaymentAction($order)
128
+ );
129
+ }
130
+
131
+
132
+ public function testGetQuoteWithAdminSession()
133
+ {
134
+ $dataHelperMock = $this->getHelperMock('ops/data', array('isAdminSession'));
135
+ $dataHelperMock->expects($this->once())
136
+ ->method('isAdminSession')
137
+ ->will($this->returnValue(true));
138
+
139
+ $fakeQuote = $this->getModelMock('sales/quote');
140
+ $this->replaceByMock('model', 'sales/quote', $fakeQuote);
141
+
142
+ $sessionMock = $this->getModelMockBuilder('adminhtml/session_quote')
143
+ ->disableOriginalConstructor() // This one removes session_start and other methods usage
144
+ ->setMethods(null) // Enables original methods usage, because by default it overrides all methods
145
+ ->getMock();
146
+ $sessionMock->setData('quote', $fakeQuote);
147
+ $this->replaceByMock('singleton', 'adminhtml/session_quote', $sessionMock);
148
+ $helper = Mage::helper('ops/quote');
149
+ $helper->setDataHelper($dataHelperMock);
150
+ $this->assertEquals($fakeQuote, $helper->getQuote());
151
+ }
152
+
153
+ public function testGetQuoteWithCheckoutSession()
154
+ {
155
+ $dataHelperMock = $this->getHelperMock('ops/data', array('isAdminSession'));
156
+ $dataHelperMock->expects($this->once())
157
+ ->method('isAdminSession')
158
+ ->will($this->returnValue(false));
159
+
160
+ $fakeQuote = $this->getModelMock('sales/quote', array('setStoreId'));
161
+ $fakeQuote->expects($this->any())
162
+ ->method('setStoreId')
163
+ ->will($this->returnValue($fakeQuote));
164
+ $this->replaceByMock('model', 'sales/quote', $fakeQuote);
165
+
166
+
167
+ $sessionMock = $this->getModelMockBuilder('customer/session')
168
+ ->disableOriginalConstructor()
169
+ ->setMethods(null)
170
+ ->getMock();
171
+ $this->replaceByMock('singleton', 'customer/session', $sessionMock);
172
+
173
+ $sessionMock = $this->getModelMockBuilder('checkout/session')
174
+ ->disableOriginalConstructor()
175
+ ->setMethods(null)
176
+ ->getMock();
177
+ $sessionMock->setData('quote', $fakeQuote);
178
+ $this->replaceByMock('singleton', 'checkout/session', $sessionMock);
179
+ $helper = Mage::helper('ops/quote');
180
+ $helper->setDataHelper($dataHelperMock);
181
+ $this->assertEquals($fakeQuote, $helper->getQuote());
182
+ }
183
+
184
+
185
+ }
app/code/community/Netresearch/OPS/Test/Helper/QuoteTest/fixtures/.gitkeep ADDED
@@ -0,0 +1 @@
 
1
+
app/code/community/Netresearch/OPS/Test/Helper/Validation/Checkout/StepTest.php ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Michael Lühr <michael.luehr@netresearch.de>
4
+ * @category Netresearch
5
+ * @copyright Copyright (c) 2014 Netresearch GmbH & Co. KG (http://www.netresearch.de)
6
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
7
+ */
8
+
9
+
10
+
11
+
12
+ class Netresearch_OPS_Test_Helper_Validation_Checkout_StepTest extends EcomDev_PHPUnit_Test_Case
13
+ {
14
+
15
+ protected $stepHelper = null;
16
+
17
+ public function setUp()
18
+ {
19
+ parent::setUp();
20
+ $this->stepHelper = Mage::helper('ops/validation_checkout_step');
21
+ }
22
+
23
+ public function testHelperReturnsNoStep()
24
+ {
25
+ $this->assertEquals('', $this->stepHelper->getStep(array()));
26
+ $this->assertEquals('', $this->stepHelper->getStep(array('SOME_OTHER_FIELD')));
27
+ }
28
+
29
+ public function testHelperReturnsBillingStep()
30
+ {
31
+ $expectedStep = Netresearch_OPS_Helper_Validation_Checkout_Step::BILLING_STEP;
32
+ $this->assertEquals($expectedStep, $this->stepHelper->getStep(array('OWNERADDRESS')));
33
+ $this->assertEquals($expectedStep, $this->stepHelper->getStep(array('OWNERADDRESS', 'SOME_OTHER_FIELD')));
34
+ $this->assertEquals($expectedStep, $this->stepHelper->getStep(array('ECOM_SHIPTO_POSTAL_STATE', 'SOME_OTHER_FIELD', 'CN')));
35
+ }
36
+
37
+ public function testHelperReturnsShippingStep()
38
+ {
39
+ $expectedStep = Netresearch_OPS_Helper_Validation_Checkout_Step::SHIPPING_STEP;
40
+ $this->assertEquals($expectedStep, $this->stepHelper->getStep(array('ECOM_SHIPTO_POSTAL_STATE')));
41
+ $this->assertEquals($expectedStep, $this->stepHelper->getStep(array('ECOM_SHIPTO_POSTAL_STATE', 'SOME_OTHER_FIELD')));
42
+ }
43
+
44
+ }
app/code/community/Netresearch/OPS/Test/Helper/Validation/ResultTest.php ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @author Michael Lühr <michael.luehr@netresearch.de>
5
+ * @category Netresearch
6
+ * @copyright Copyright (c) 2014 Netresearch GmbH & Co. KG (http://www.netresearch.de)
7
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
8
+ */
9
+ class Netresearch_OPS_Test_Helper_Validation_ResultTest extends EcomDev_PHPUnit_Test_Case
10
+ {
11
+
12
+ protected $validationResultHelper = null;
13
+
14
+ public function setUp()
15
+ {
16
+ parent::setUp();
17
+ Mage::unregister('_helper/ops/validation_result');
18
+ $this->validationResultHelper = Mage::helper('ops/validation_result');
19
+ }
20
+
21
+ public function testBaseErroneousFields()
22
+ {
23
+ $quote = Mage::getModel('sales/quote');
24
+ $messages = array('foo', 'bar');
25
+ $result = $this->validationResultHelper->getValidationFailedResult($messages, $quote);
26
+ $this->assertArrayHasKey('error', $result);
27
+ $this->assertArrayHasKey('goto_section', $result);
28
+ $this->assertArrayHasKey('opsError', $result);
29
+ $this->assertArrayHasKey('fields', $result);
30
+ }
31
+
32
+ public function testGetValidationFailedResultWithFieldMapping()
33
+ {
34
+ $quote = Mage::getModel('sales/quote');
35
+ $configMock = $this->getModelMock('ops/config', array('getFrontendFieldMapping'));
36
+ $configMock->expects($this->once())
37
+ ->method('getFrontendFieldMapping')
38
+ ->will($this->returnValue(array('foo' => 'bar')));
39
+ $this->validationResultHelper->setConfig($configMock);
40
+ $this->validationResultHelper->setFormBlock(Mage::app()->getLayout()->createBlock('ops/form'));
41
+ $messages = array('foo' => 'bar');
42
+ $result = $this->validationResultHelper->getValidationFailedResult($messages, $quote);
43
+ $this->assertArrayHasKey('fields', $result);
44
+ $this->assertArrayHasKey('bar', $result['fields']);
45
+ }
46
+
47
+ /**
48
+ * @loadFixture quotes
49
+ */
50
+ public function testGetValidationFailedResultWithExistingAddress()
51
+ {
52
+ $quote = Mage::getModel('sales/quote')->load(1);
53
+ $checkoutStepHelperMock = $this->getHelperMock('ops/validation_checkout_step', array('getStep'));
54
+ $checkoutStepHelperMock->expects($this->exactly(2))
55
+ ->method('getStep')
56
+ ->will($this->onConsecutiveCalls('billing', 'shipping'));
57
+
58
+ $configMock = $this->getModelMock('ops/config', array('getFrontendFieldMapping'));
59
+ $configMock->expects($this->exactly(2))
60
+ ->method('getFrontendFieldMapping')
61
+ ->will($this->returnValue(array('foo' => 'bar')));
62
+ $this->validationResultHelper->setConfig($configMock);
63
+
64
+ $messages = array('foo' => 'bar');
65
+ $this->validationResultHelper->setCheckoutStepHelper($checkoutStepHelperMock);
66
+ $this->validationResultHelper->setFormBlock(Mage::app()->getLayout()->createBlock('ops/form'));
67
+ $result = $this->validationResultHelper->getValidationFailedResult($messages, $quote);
68
+ $this->assertArrayHasKey('fields', $result);
69
+ $this->assertArrayHasKey('billing-address-select', $result['fields']);
70
+
71
+ $result = $this->validationResultHelper->getValidationFailedResult($messages, $quote);
72
+ $this->assertArrayHasKey('fields', $result);
73
+ $this->assertArrayHasKey('shipping-address-select', $result['fields']);
74
+ }
75
+
76
+ public function testCleanResult()
77
+ {
78
+ $quote = Mage::getModel('sales/quote');
79
+ $messages = array('foo' => 'bar');
80
+ $prevResult = array('update_section' => 'foo');
81
+
82
+ $configMock = $this->getModelMock('ops/config', array('getFrontendFieldMapping'));
83
+ $configMock->expects($this->once())
84
+ ->method('getFrontendFieldMapping')
85
+ ->will($this->returnValue(array('foo' => 'bar')));
86
+ $this->validationResultHelper->setConfig($configMock);
87
+ $this->validationResultHelper->setFormBlock(Mage::app()->getLayout()->createBlock('ops/form'));
88
+
89
+ $this->validationResultHelper->setResult($prevResult);
90
+ $result = $this->validationResultHelper->getValidationFailedResult($messages, $quote);
91
+ $this->assertArrayNotHasKey('update_section', $result);
92
+ }
93
+
94
+ }
app/code/community/Netresearch/OPS/Test/Helper/Validation/ResultTest/fixtures/quotes.yaml ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ tables:
2
+ sales/quote:
3
+ - entity_id: 1
4
+ increment_id: 100000001
5
+ base_grand_total: 119.00
6
+ grand_total: 119.00
7
+ currency: 'EUR'
8
+ customer_gender: 1
9
+ shipping_method: 'flatrate_flatrate'
10
+
11
+ sales/quote_address:
12
+ - entity_id: 42
13
+ quote_id: 1
14
+ address_type: 'billing'
15
+ firstname: 'Hubertus'
16
+ postcode: '04229'
17
+ lastname: 'Fürstenberg'
18
+ street: 'An der Tabaksmühle 3a'
19
+ city: 'Leipzig'
20
+ email: 'hubertus.von.fuerstenberg@trash-mail.com'
21
+ country_id: 'DE'
22
+ prefix: 'Prof. Dr.'
23
+ middlename: 'von'
24
+ suffix: 'MdL'
25
+ company: ''
26
+ fax: '12345678'
27
+
28
+ - entity_id: 43
29
+ quote_id: 1
30
+ address_type: 'shipping'
31
+ firstname: 'Hubertus'
32
+ postcode: '04229'
33
+ lastname: 'Fürstenberg'
34
+ street: 'An der Tabaksmühle 3a'
35
+ city: 'Leipzig'
36
+ email: 'hubertus.von.fuerstenberg@trash-mail.com'
37
+ country_id: 'DE'
38
+ prefix: 'Prof. Dr.'
39
+ middlename: 'von'
40
+ suffix: 'MdL'
41
+ company: ''
42
+ fax: '12345678'
app/code/community/Netresearch/OPS/Test/Helper/VersionTest.php ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Netresearch_OPS_Test_Helper_VersionTest extends EcomDev_PHPUnit_Test_Case
4
+ {
5
+ protected $helper;
6
+
7
+
8
+ public function setUp()
9
+ {
10
+ parent::setup();
11
+ $this->helper = Mage::helper('ops/version');
12
+ }
13
+
14
+ public function testGetVersionForEditionEE()
15
+ {
16
+ $helperMethod = $this->getProtectedMethod($this->helper, 'getVersionForEdition');
17
+ $this->assertEquals(
18
+ Netresearch_OPS_Helper_Version::CAN_USE_APPLICABLE_FOR_QUOTE_EE_MINOR,
19
+ $helperMethod->invoke($this->helper, 'Enterprise')
20
+ );
21
+ }
22
+
23
+ public function testGetVersionForEditionCE()
24
+ {
25
+ $helperMethod = $this->getProtectedMethod($this->helper, 'getVersionForEdition');
26
+ $this->assertEquals(
27
+ Netresearch_OPS_Helper_Version::CAN_USE_APPLICABLE_FOR_QUOTE_CE_MINOR,
28
+ $helperMethod->invoke($this->helper, 'Community')
29
+ );
30
+ }
31
+
32
+ public function testGetVersionForEditionDefaultCE()
33
+ {
34
+ $helperMethod = $this->getProtectedMethod($this->helper, 'getVersionForEdition');
35
+ $this->assertEquals(
36
+ Netresearch_OPS_Helper_Version::CAN_USE_APPLICABLE_FOR_QUOTE_CE_MINOR,
37
+ $helperMethod->invoke($this->helper, null)
38
+ );
39
+ }
40
+
41
+ public function testCanUseApplicableForQuoteForEE()
42
+ {
43
+ $helperMock = $this->getHelperMock('ops/version', array('getVersionInfo'));
44
+ $helperMock->expects($this->any())
45
+ ->method('getVersionInfo')
46
+ ->will($this->returnValue(array('minor' => '14')));
47
+
48
+ $this->assertTrue($helperMock->canUseApplicableForQuote('Enterprise'));
49
+
50
+ $helperMock = $this->getHelperMock('ops/version', array('getVersionInfo'));
51
+ $helperMock->expects($this->any())
52
+ ->method('getVersionInfo')
53
+ ->will($this->returnValue(array('minor' => '13')));
54
+
55
+ $this->assertFalse($helperMock->canUseApplicableForQuote('Enterprise'));
56
+ }
57
+
58
+ public function testCanUseApplicableForQuoteForCE()
59
+ {
60
+ $helperMock = $this->getHelperMock('ops/version', array('getVersionInfo'));
61
+ $helperMock->expects($this->any())
62
+ ->method('getVersionInfo')
63
+ ->will($this->returnValue(array('minor' => '8')));
64
+
65
+ $this->assertTrue($helperMock->canUseApplicableForQuote('Community'));
66
+
67
+ $helperMock = $this->getHelperMock('ops/version', array('getVersionInfo'));
68
+ $helperMock->expects($this->any())
69
+ ->method('getVersionInfo')
70
+ ->will($this->returnValue(array('minor' => '7')));
71
+
72
+ $this->assertFalse($helperMock->canUseApplicableForQuote('Community'));
73
+
74
+
75
+ }
76
+
77
+ public function testGetVersionInfo()
78
+ {
79
+ $helperMethod = $this->getProtectedMethod($this->helper, 'getVersionInfo');
80
+ $this->assertEquals(Mage::getVersionInfo(), $helperMethod->invoke($this->helper));
81
+
82
+ }
83
+
84
+ protected function getProtectedMethod($class, $method)
85
+ {
86
+ $reflection_class = new ReflectionClass(get_class($class));
87
+ $method = $reflection_class->getMethod($method);
88
+ $method->setAccessible(true);
89
+ return $method;
90
+ }
91
+ }
92
+
app/code/community/Netresearch/OPS/Test/Model/AliasTest/fixtures/.gitkeep ADDED
File without changes
app/code/community/Netresearch/OPS/Test/Model/Api/DirectLinkShaTest.php ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Netresearch_OPS_Test_Model_Api_DirectLinkShaTest extends EcomDev_PHPUnit_Test_Case
3
+ {
4
+ private $_model;
5
+ private $_shaKey;
6
+
7
+ public function setUp()
8
+ {
9
+ parent::setup();
10
+ $this->_model = Mage::getModel('ops/api_directlink');
11
+ $this->_shaKey = 'ksdf239sdnkvs2e9';
12
+ }
13
+
14
+ public function testShaGenerationWithoutSpecialChars()
15
+ {
16
+ $params = array(
17
+ 'ALIAS' => 'foo'
18
+ );
19
+ $expected = $params;
20
+ $expected['SHASIGN'] = '44194456a31b8ea1de461612b19f7255732438d5';
21
+ $this->assertEquals($expected, $this->_model->getEncodedParametersWithHash($params, $this->_shaKey, 0));
22
+ }
23
+
24
+ public function testShaGenerationWithSpecialChars()
25
+ {
26
+ $params = array(
27
+ 'AMOUNT' => '36980',
28
+ 'CARDNO' => '257354109BLZ86010090',
29
+ 'CN' => 'André Herrn',
30
+ 'CURRENCY' => 'EUR',
31
+ 'ED' => '9999',
32
+ 'OPERATION' => 'SAL',
33
+ 'ORDERID' => '20190',
34
+ 'PM' => 'Direct Debits DE',
35
+ 'PSPID' => 'NRMAGENTO',
36
+ 'PSWD' => 'magento1',
37
+ 'USERID' => 'NRMAGENTO1API',
38
+ );
39
+ $expected = $params;
40
+ $expected['SHASIGN'] = 'eb95f7d66879e9801fdbdf75095ce23147202c30';
41
+ $result = $this->_model->getEncodedParametersWithHash($params, $this->_shaKey, 0);
42
+ $this->assertEquals($expected, $result);
43
+ }
44
+ }
app/code/community/Netresearch/OPS/Test/Model/Api/DirectLinkTest.php ADDED
@@ -0,0 +1,253 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Netresearch_OPS_Test_Model_Api_DirectLinkTest extends EcomDev_PHPUnit_Test_Case_Controller
3
+ {
4
+ private $_model;
5
+
6
+ public function setUp()
7
+ {
8
+ parent::setup();
9
+ $this->_model = Mage::getModel('ops/api_directlink');
10
+ }
11
+
12
+ public function testCallInvalidUrl()
13
+ {
14
+ $response = $this->_model->call(array(), 'http://localhost');
15
+ $this->assertInternalType('string', $response);
16
+ }
17
+
18
+ public function testType()
19
+ {
20
+ $this->assertInstanceOf('Netresearch_OPS_Model_Api_DirectLink', $this->_model);
21
+ }
22
+
23
+ public function testXmlParser()
24
+ {
25
+ $xmlExample =
26
+ '<?xml version="1.0"?>
27
+ <ncresponse
28
+ orderID="1121212"
29
+ PAYID="232"
30
+ PAYIDSUB="0"
31
+ NCSTATUS="5"
32
+ NCERROR="50001111"
33
+ NCERRORPLUS="Some of the data entered is incorrect. Please retry."
34
+ ACCEPTANCE=""
35
+ STATUS="0"
36
+ amount=""
37
+ currency="">
38
+ </ncresponse>';
39
+ $arrParams = $this->_model->getParamArrFromXmlString($xmlExample);
40
+ $this->assertEquals("1121212", $arrParams['orderID']);
41
+ $this->assertEquals("232", $arrParams['PAYID']);
42
+ $this->assertEquals("0", $arrParams['PAYIDSUB']);
43
+ $this->assertEquals("5", $arrParams['NCSTATUS']);
44
+ $this->assertEquals("50001111", $arrParams['NCERROR']);
45
+ $this->assertEquals("Some of the data entered is incorrect. Please retry.", $arrParams['NCERRORPLUS']);
46
+ $this->assertEquals("", $arrParams['ACCEPTANCE']);
47
+ $this->assertEquals("0", $arrParams['STATUS']);
48
+ $this->assertEquals("", $arrParams['amount']);
49
+ $this->assertEquals("", $arrParams['currency']);
50
+ }
51
+
52
+ public function testXmlParserWithHtmlAnswer()
53
+ {
54
+ $xmlExample =
55
+ '<?xml version="1.0"?>
56
+ <ncresponse
57
+ orderID="1121212"
58
+ PAYID="232"
59
+ PAYIDSUB="0"
60
+ NCSTATUS="5"
61
+ NCERROR="50001111"
62
+ NCERRORPLUS="Some of the data entered is incorrect. Please retry."
63
+ ACCEPTANCE=""
64
+ STATUS="0"
65
+ amount=""
66
+ currency="">
67
+ <HTML_ANSWER>PGZvcm0gbmFtZT0iZG93bmxvYWRmb3JtM0QiIGFjdGlvbj0iaHR0cHM6Ly9zZWN1cmUub2dvbmUuY29tL25jb2wvdGVzdC9UZXN0XzNEX0FDUy5hc3AiIG1ldGhvZD0icG9zdCI+DQo8Tk9TQ1JJUFQ+DQpKYXZhU2NyaXB0IGlzIGN1cnJlbnRseSBkaXNhYmxlZCBvciBpcyBub3Qgc3VwcG9ydGVkIGJ5IHlvdXIgYnJvd3Nlci48YnI+DQpQbGVhc2UgY2xpY2sgb24gdGhlICZxdW90O0NvbnRpbnVlJnF1b3Q7IGJ1dHRvbiB0byBjb250aW51ZSB0aGUgcHJvY2Vzc2luZyBvZiB5b3VyIDMtRCBzZWN1cmUgdHJhbnNhY3Rpb24uPGJyPg0KPGlucHV0IGNsYXNzPSJuY29sIiB0eXBlPSJzdWJtaXQiIHZhbHVlPSJDb250aW51ZSIgaWQ9InN1Ym1pdDEiIG5hbWU9InN1Ym1pdDEiIC8+DQo8L05PU0NSSVBUPg0KPGlucHV0IHR5cGU9ImhpZGRlbiIgbmFtZT0iQ1NSRktFWSIgdmFsdWU9IjA0MzA0MzI4NkE0M0ZDM0YyRDhFMDFCOUM2MzYwRTA1Qzg5NkZEMzYiIC8+DQo8aW5wdXQgdHlwZT0iaGlkZGVuIiBuYW1lPSJDU1JGVFMiIHZhbHVlPSIyMDExMDkxMjE2MjQ1MCIgLz4NCjxpbnB1dCB0eXBlPSJoaWRkZW4iIG5hbWU9IkNTUkZTUCIgdmFsdWU9Ii9uY29sL3Rlc3Qvb3JkZXJkaXJlY3QuYXNwIiAvPg0KPGlucHV0IHR5cGU9ImhpZGRlbiIgbmFtZT0iUGFSZXEiIHZhbHVlPSI8P3htbCB2ZXJzaW9uPSZxdW90OzEuMCZxdW90Oz8+PFRocmVlRFNlY3VyZT48TWVzc2FnZSBpZD0mcXVvdDsxMjMmcXVvdDs+PFBBUmVxPjx2ZXJzaW9uPjEuMDI8L3ZlcnNpb24+PE1lcmNoYW50PjxtZXJJRD5OUk1BR0VOVE8zPC9tZXJJRD48bmFtZT5OZXRyZXNlYXJjaCBHbWJIICZhbXA7YW1wOyBDby5LRzwvbmFtZT48dXJsPmh0dHA6Ly93d3cubmV0cmVzZWFyY2guZGU8L3VybD48L01lcmNoYW50PjxQdXJjaGFzZT48eGlkPjExNjI4OTgzPC94aWQ+PGFtb3VudD4xMjY4Ljc1PC9hbW91bnQ+PHB1cmNoQW1vdW50PjEyNjguNzU8L3B1cmNoQW1vdW50PjxjdXJyZW5jeT5FVVI8L2N1cnJlbmN5PjwvUHVyY2hhc2U+PENIPjxhY2N0SUQ+NDAwMDAwWFhYWFhYMDAwMjwvYWNjdElEPjxleHBpcnk+MDExNjwvZXhwaXJ5PjxzZWxCcmFuZD48L3NlbEJyYW5kPjwvQ0g+PC9QQVJlcT48L01lc3NhZ2U+PC9UaHJlZURTZWN1cmU+DQoiIC8+DQo8aW5wdXQgdHlwZT0iaGlkZGVuIiBuYW1lPSJUZXJtVXJsIiB2YWx1ZT0iaHR0cHM6Ly9zZWN1cmUub2dvbmUuY29tL25jb2wvdGVzdC9vcmRlcl9BM0RTLmFzcCIgLz4NCjxpbnB1dCB0eXBlPSJoaWRkZW4iIG5hbWU9Ik1EIiB2YWx1ZT0iTUFJTldQVEVTVDAwMDAxMTYyODk4MzAxKjEwNzUyNjIiIC8+DQo8L2Zvcm0+DQo8Zm9ybSBtZXRob2Q9InBvc3QiIGFjdGlvbj0iaHR0cHM6Ly9zZWN1cmUub2dvbmUuY29tL25jb2wvdGVzdC9vcmRlcl9hZ3JlZS5hc3AiIG5hbWU9InVwbG9hZEZvcm0zRCI+DQo8aW5wdXQgdHlwZT0iaGlkZGVuIiBuYW1lPSJDU1JGS0VZIiB2YWx1ZT0iMDZGM0MzMUQ2RkI1MzIzODg4NjhFRjlGNTA5RUNGNzlBQzIwRDJGMyIgLz4NCjxpbnB1dCB0eXBlPSJoaWRkZW4iIG5hbWU9IkNTUkZUUyIgdmFsdWU9IjIwMTEwOTEyMTYyNDUwIiAvPg0KPGlucHV0IHR5cGU9ImhpZGRlbiIgbmFtZT0iQ1NSRlNQIiB2YWx1ZT0iL25jb2wvdGVzdC9vcmRlcmRpcmVjdC5hc3AiIC8+DQo8aW5wdXQgdHlwZT0iaGlkZGVuIiBuYW1lPSJicmFuZGluZyIgdmFsdWU9Ik9nb25lIiAvPg0KPGlucHV0IHR5cGU9ImhpZGRlbiIgbmFtZT0icGF5aWQiIHZhbHVlPSIxMTYyODk4MyIgLz4NCjxpbnB1dCB0eXBlPSJoaWRkZW4iIG5hbWU9InN0b3JlYWxpYXMiIHZhbHVlPSIiIC8+DQo8aW5wdXQgdHlwZT0iaGlkZGVuIiBuYW1lPSJoYXNoX3BhcmFtIiB2YWx1ZT0iOTFBMzA1MjFEMEI0QTA1MEFBRDkzRDM5RDY2RkEyM0Y5OEIzRDQ4RCIgLz4NCjxpbnB1dCB0eXBlPSJoaWRkZW4iIG5hbWU9InhpZF8zRCIgdmFsdWU9IiIgLz4NCjxpbnB1dCB0eXBlPSJoaWRkZW4iIG5hbWU9InN0YXR1c18zRCIgdmFsdWU9IlhYIiAvPg0KPGlucHV0IHR5cGU9ImhpZGRlbiIgbmFtZT0iZWNpXzNEIiB2YWx1ZT0iNyIgLz4NCjxpbnB1dCB0eXBlPSJoaWRkZW4iIG5hbWU9ImNhcmRudW1iZXIiIHZhbHVlPSIiIC8+DQo8aW5wdXQgdHlwZT0iaGlkZGVuIiBuYW1lPSJFY29tX1BheW1lbnRfQ2FyZF9WZXJpZmljYXRpb24iIHZhbHVlPSIqMTA3NTI2MiIgLz4NCjxpbnB1dCB0eXBlPSJoaWRkZW4iIG5hbWU9IkNWQ0ZsYWciIHZhbHVlPSIxIiAvPg0KPGlucHV0IHR5cGU9ImhpZGRlbiIgbmFtZT0iY2F2dl8zRCIgdmFsdWU9IiIgLz4NCjxpbnB1dCB0eXBlPSJoaWRkZW4iIG5hbWU9ImNhdnZhbGdvcml0aG1fM0QiIHZhbHVlPSIiIC8+DQo8aW5wdXQgdHlwZT0iaGlkZGVuIiBuYW1lPSJzaWduYXR1cmVPS18zRCIgdmFsdWU9IiIgLz4NCjxpbnB1dCB0eXBlPSJoaWRkZW4iIG5hbWU9Imhhc2hfcGFyYW1fM0QiIHZhbHVlPSIwMzAzREZDMkI1OTM0MjZCQTExRkQ5RjJBNkQ0NDk5ODEwN0JGN0YzIiAvPg0KPC9mb3JtPg0KPFNDUklQVCBMQU5HVUFHRT0iSmF2YXNjcmlwdCIgRk9SPSJ3aW5kb3ciIEVWRU5UPSJvbkxvYWQiPg0KdmFyIHBvcHVwV2luOw0KdmFyIHN1Ym1pdHBvcHVwV2luID0gMDsNCg0KZnVuY3Rpb24gTG9hZFBvcHVwKCkgew0KCWlmIChzZWxmLm5hbWUgPT0gbnVsbCkJew0KCQlzZWxmLm5hbWUgPSAib2dvbmVNYWluIjsNCgl9DQoJcG9wdXBXaW4gPSB3aW5kb3cub3BlbignYWJvdXQ6YmxhbmsnLCAncG9wdXBXaW4nLCAnaGVpZ2h0PTQwMCwgd2lkdGg9MzkwLCBzdGF0dXM9eWVzLCBkZXBlbmRlbnQ9bm8sIHNjcm9sbGJhcnM9eWVzLCByZXNpemFibGU9bm8nKTsNCglpZiAocG9wdXBXaW4gIT0gbnVsbCkgew0KCQlpZiAgKCFwb3B1cFdpbiB8fCBwb3B1cFdpbi5jbG9zZWQpIHsNCgkJCXJldHVybiAxOw0KCQl9IGVsc2Ugew0KCQkJaWYgKCFwb3B1cFdpbi5vcGVuZXIgfHwgcG9wdXBXaW4ub3BlbmVyID09IG51bGwpIHsNCgkJCQlwb3B1cFdpbi5vcGVuZXIgPSBzZWxmOw0KCQkJfQ0KCQkJc2VsZi5kb2N1bWVudC5mb3Jtcy5kb3dubG9hZGZvcm0zRC50YXJnZXQgPSAncG9wdXBXaW4nOw0KCQkJaWYgKHN1Ym1pdHBvcHVwV2luID09IDEpIHsNCgkJCQlzZWxmLmRvY3VtZW50LmZvcm1zLmRvd25sb2FkZm9ybTNELnN1Ym1pdCgpOw0KCQkJfQ0KCQkJcG9wdXBXaW4uZm9jdXMoKTsNCgkJCXJldHVybiAwOw0KCQl9DQoJfSBlbHNlIHsNCgkJcmV0dXJuIDE7DQoJfQ0KfQ0KCXNlbGYuZG9jdW1lbnQuZm9ybXMuZG93bmxvYWRmb3JtM0Quc3VibWl0KCk7DQovLy0tPg0KPC9TQ1JJUFQ+DQo=</HTML_ANSWER>
68
+ </ncresponse>';
69
+ $arrParams = $this->_model->getParamArrFromXmlString($xmlExample);
70
+ $this->assertEquals("1121212", $arrParams['orderID']);
71
+ $this->assertEquals("232", $arrParams['PAYID']);
72
+ $this->assertEquals("PGZvcm0gbmFtZT0iZG93bmxvYWRmb3JtM0QiIGFjdGlvbj0iaHR0cHM6Ly9zZWN1cmUub2dvbmUuY29tL25jb2wvdGVzdC9UZXN0XzNEX0FDUy5hc3AiIG1ldGhvZD0icG9zdCI+DQo8Tk9TQ1JJUFQ+DQpKYXZhU2NyaXB0IGlzIGN1cnJlbnRseSBkaXNhYmxlZCBvciBpcyBub3Qgc3VwcG9ydGVkIGJ5IHlvdXIgYnJvd3Nlci48YnI+DQpQbGVhc2UgY2xpY2sgb24gdGhlICZxdW90O0NvbnRpbnVlJnF1b3Q7IGJ1dHRvbiB0byBjb250aW51ZSB0aGUgcHJvY2Vzc2luZyBvZiB5b3VyIDMtRCBzZWN1cmUgdHJhbnNhY3Rpb24uPGJyPg0KPGlucHV0IGNsYXNzPSJuY29sIiB0eXBlPSJzdWJtaXQiIHZhbHVlPSJDb250aW51ZSIgaWQ9InN1Ym1pdDEiIG5hbWU9InN1Ym1pdDEiIC8+DQo8L05PU0NSSVBUPg0KPGlucHV0IHR5cGU9ImhpZGRlbiIgbmFtZT0iQ1NSRktFWSIgdmFsdWU9IjA0MzA0MzI4NkE0M0ZDM0YyRDhFMDFCOUM2MzYwRTA1Qzg5NkZEMzYiIC8+DQo8aW5wdXQgdHlwZT0iaGlkZGVuIiBuYW1lPSJDU1JGVFMiIHZhbHVlPSIyMDExMDkxMjE2MjQ1MCIgLz4NCjxpbnB1dCB0eXBlPSJoaWRkZW4iIG5hbWU9IkNTUkZTUCIgdmFsdWU9Ii9uY29sL3Rlc3Qvb3JkZXJkaXJlY3QuYXNwIiAvPg0KPGlucHV0IHR5cGU9ImhpZGRlbiIgbmFtZT0iUGFSZXEiIHZhbHVlPSI8P3htbCB2ZXJzaW9uPSZxdW90OzEuMCZxdW90Oz8+PFRocmVlRFNlY3VyZT48TWVzc2FnZSBpZD0mcXVvdDsxMjMmcXVvdDs+PFBBUmVxPjx2ZXJzaW9uPjEuMDI8L3ZlcnNpb24+PE1lcmNoYW50PjxtZXJJRD5OUk1BR0VOVE8zPC9tZXJJRD48bmFtZT5OZXRyZXNlYXJjaCBHbWJIICZhbXA7YW1wOyBDby5LRzwvbmFtZT48dXJsPmh0dHA6Ly93d3cubmV0cmVzZWFyY2guZGU8L3VybD48L01lcmNoYW50PjxQdXJjaGFzZT48eGlkPjExNjI4OTgzPC94aWQ+PGFtb3VudD4xMjY4Ljc1PC9hbW91bnQ+PHB1cmNoQW1vdW50PjEyNjguNzU8L3B1cmNoQW1vdW50PjxjdXJyZW5jeT5FVVI8L2N1cnJlbmN5PjwvUHVyY2hhc2U+PENIPjxhY2N0SUQ+NDAwMDAwWFhYWFhYMDAwMjwvYWNjdElEPjxleHBpcnk+MDExNjwvZXhwaXJ5PjxzZWxCcmFuZD48L3NlbEJyYW5kPjwvQ0g+PC9QQVJlcT48L01lc3NhZ2U+PC9UaHJlZURTZWN1cmU+DQoiIC8+DQo8aW5wdXQgdHlwZT0iaGlkZGVuIiBuYW1lPSJUZXJtVXJsIiB2YWx1ZT0iaHR0cHM6Ly9zZWN1cmUub2dvbmUuY29tL25jb2wvdGVzdC9vcmRlcl9BM0RTLmFzcCIgLz4NCjxpbnB1dCB0eXBlPSJoaWRkZW4iIG5hbWU9Ik1EIiB2YWx1ZT0iTUFJTldQVEVTVDAwMDAxMTYyODk4MzAxKjEwNzUyNjIiIC8+DQo8L2Zvcm0+DQo8Zm9ybSBtZXRob2Q9InBvc3QiIGFjdGlvbj0iaHR0cHM6Ly9zZWN1cmUub2dvbmUuY29tL25jb2wvdGVzdC9vcmRlcl9hZ3JlZS5hc3AiIG5hbWU9InVwbG9hZEZvcm0zRCI+DQo8aW5wdXQgdHlwZT0iaGlkZGVuIiBuYW1lPSJDU1JGS0VZIiB2YWx1ZT0iMDZGM0MzMUQ2RkI1MzIzODg4NjhFRjlGNTA5RUNGNzlBQzIwRDJGMyIgLz4NCjxpbnB1dCB0eXBlPSJoaWRkZW4iIG5hbWU9IkNTUkZUUyIgdmFsdWU9IjIwMTEwOTEyMTYyNDUwIiAvPg0KPGlucHV0IHR5cGU9ImhpZGRlbiIgbmFtZT0iQ1NSRlNQIiB2YWx1ZT0iL25jb2wvdGVzdC9vcmRlcmRpcmVjdC5hc3AiIC8+DQo8aW5wdXQgdHlwZT0iaGlkZGVuIiBuYW1lPSJicmFuZGluZyIgdmFsdWU9Ik9nb25lIiAvPg0KPGlucHV0IHR5cGU9ImhpZGRlbiIgbmFtZT0icGF5aWQiIHZhbHVlPSIxMTYyODk4MyIgLz4NCjxpbnB1dCB0eXBlPSJoaWRkZW4iIG5hbWU9InN0b3JlYWxpYXMiIHZhbHVlPSIiIC8+DQo8aW5wdXQgdHlwZT0iaGlkZGVuIiBuYW1lPSJoYXNoX3BhcmFtIiB2YWx1ZT0iOTFBMzA1MjFEMEI0QTA1MEFBRDkzRDM5RDY2RkEyM0Y5OEIzRDQ4RCIgLz4NCjxpbnB1dCB0eXBlPSJoaWRkZW4iIG5hbWU9InhpZF8zRCIgdmFsdWU9IiIgLz4NCjxpbnB1dCB0eXBlPSJoaWRkZW4iIG5hbWU9InN0YXR1c18zRCIgdmFsdWU9IlhYIiAvPg0KPGlucHV0IHR5cGU9ImhpZGRlbiIgbmFtZT0iZWNpXzNEIiB2YWx1ZT0iNyIgLz4NCjxpbnB1dCB0eXBlPSJoaWRkZW4iIG5hbWU9ImNhcmRudW1iZXIiIHZhbHVlPSIiIC8+DQo8aW5wdXQgdHlwZT0iaGlkZGVuIiBuYW1lPSJFY29tX1BheW1lbnRfQ2FyZF9WZXJpZmljYXRpb24iIHZhbHVlPSIqMTA3NTI2MiIgLz4NCjxpbnB1dCB0eXBlPSJoaWRkZW4iIG5hbWU9IkNWQ0ZsYWciIHZhbHVlPSIxIiAvPg0KPGlucHV0IHR5cGU9ImhpZGRlbiIgbmFtZT0iY2F2dl8zRCIgdmFsdWU9IiIgLz4NCjxpbnB1dCB0eXBlPSJoaWRkZW4iIG5hbWU9ImNhdnZhbGdvcml0aG1fM0QiIHZhbHVlPSIiIC8+DQo8aW5wdXQgdHlwZT0iaGlkZGVuIiBuYW1lPSJzaWduYXR1cmVPS18zRCIgdmFsdWU9IiIgLz4NCjxpbnB1dCB0eXBlPSJoaWRkZW4iIG5hbWU9Imhhc2hfcGFyYW1fM0QiIHZhbHVlPSIwMzAzREZDMkI1OTM0MjZCQTExRkQ5RjJBNkQ0NDk5ODEwN0JGN0YzIiAvPg0KPC9mb3JtPg0KPFNDUklQVCBMQU5HVUFHRT0iSmF2YXNjcmlwdCIgRk9SPSJ3aW5kb3ciIEVWRU5UPSJvbkxvYWQiPg0KdmFyIHBvcHVwV2luOw0KdmFyIHN1Ym1pdHBvcHVwV2luID0gMDsNCg0KZnVuY3Rpb24gTG9hZFBvcHVwKCkgew0KCWlmIChzZWxmLm5hbWUgPT0gbnVsbCkJew0KCQlzZWxmLm5hbWUgPSAib2dvbmVNYWluIjsNCgl9DQoJcG9wdXBXaW4gPSB3aW5kb3cub3BlbignYWJvdXQ6YmxhbmsnLCAncG9wdXBXaW4nLCAnaGVpZ2h0PTQwMCwgd2lkdGg9MzkwLCBzdGF0dXM9eWVzLCBkZXBlbmRlbnQ9bm8sIHNjcm9sbGJhcnM9eWVzLCByZXNpemFibGU9bm8nKTsNCglpZiAocG9wdXBXaW4gIT0gbnVsbCkgew0KCQlpZiAgKCFwb3B1cFdpbiB8fCBwb3B1cFdpbi5jbG9zZWQpIHsNCgkJCXJldHVybiAxOw0KCQl9IGVsc2Ugew0KCQkJaWYgKCFwb3B1cFdpbi5vcGVuZXIgfHwgcG9wdXBXaW4ub3BlbmVyID09IG51bGwpIHsNCgkJCQlwb3B1cFdpbi5vcGVuZXIgPSBzZWxmOw0KCQkJfQ0KCQkJc2VsZi5kb2N1bWVudC5mb3Jtcy5kb3dubG9hZGZvcm0zRC50YXJnZXQgPSAncG9wdXBXaW4nOw0KCQkJaWYgKHN1Ym1pdHBvcHVwV2luID09IDEpIHsNCgkJCQlzZWxmLmRvY3VtZW50LmZvcm1zLmRvd25sb2FkZm9ybTNELnN1Ym1pdCgpOw0KCQkJfQ0KCQkJcG9wdXBXaW4uZm9jdXMoKTsNCgkJCXJldHVybiAwOw0KCQl9DQoJfSBlbHNlIHsNCgkJcmV0dXJuIDE7DQoJfQ0KfQ0KCXNlbGYuZG9jdW1lbnQuZm9ybXMuZG93bmxvYWRmb3JtM0Quc3VibWl0KCk7DQovLy0tPg0KPC9TQ1JJUFQ+DQo=", $arrParams['HTML_ANSWER']);
73
+ }
74
+
75
+
76
+ public function testWithNoXmlResponse()
77
+ {
78
+ $xmlExample = '';
79
+ $this->assertTrue($this->setExpectedException('PHPUnit_Framework_ExpectationFailedException'));
80
+ $arrParams = $this->_model->getParamArrFromXmlString($xmlExample);
81
+ $xmlExample = 'N';
82
+ $arrParams = $this->_model->getParamArrFromXmlString($xmlExample);
83
+ }
84
+
85
+ /**
86
+ * @expectedException Mage_Core_Exception
87
+ */
88
+ public function testIsInvalidResponseWithEmptyData()
89
+ {
90
+ $this->_model->checkResponse(null);
91
+ }
92
+
93
+ public function testIsValidResponse()
94
+ {
95
+ $this->assertTrue(is_null($this->_model->checkResponse(array('NCERROR' => 0))));
96
+ }
97
+
98
+ public function testGetResponseParamsWithValidCallResponse()
99
+ {
100
+ $xmlExample =
101
+ '<?xml version="1.0"?>
102
+ <ncresponse
103
+ orderID="1121212"
104
+ PAYID="232"
105
+ PAYIDSUB="0"
106
+ NCSTATUS="5"
107
+ NCERROR="50001111"
108
+ NCERRORPLUS="Some of the data entered is incorrect. Please retry."
109
+ ACCEPTANCE=""
110
+ STATUS="0"
111
+ amount=""
112
+ currency="">
113
+ <HTML_ANSWER>PGZvcm0gbmFtZT0iZG93bmxvYWRmb3JtM0QiIGFjdGlvbj0iaHR0cHM6Ly9zZWN1cmUub2dvbmUuY29tL25jb2wvdGVzdC9UZXN0XzNEX0FDUy5hc3AiIG1ldGhvZD0icG9zdCI+DQo8Tk9TQ1JJUFQ+DQpKYXZhU2NyaXB0IGlzIGN1cnJlbnRseSBkaXNhYmxlZCBvciBpcyBub3Qgc3VwcG9ydGVkIGJ5IHlvdXIgYnJvd3Nlci48YnI+DQpQbGVhc2UgY2xpY2sgb24gdGhlICZxdW90O0NvbnRpbnVlJnF1b3Q7IGJ1dHRvbiB0byBjb250aW51ZSB0aGUgcHJvY2Vzc2luZyBvZiB5b3VyIDMtRCBzZWN1cmUgdHJhbnNhY3Rpb24uPGJyPg0KPGlucHV0IGNsYXNzPSJuY29sIiB0eXBlPSJzdWJtaXQiIHZhbHVlPSJDb250aW51ZSIgaWQ9InN1Ym1pdDEiIG5hbWU9InN1Ym1pdDEiIC8+DQo8L05PU0NSSVBUPg0KPGlucHV0IHR5cGU9ImhpZGRlbiIgbmFtZT0iQ1NSRktFWSIgdmFsdWU9IjA0MzA0MzI4NkE0M0ZDM0YyRDhFMDFCOUM2MzYwRTA1Qzg5NkZEMzYiIC8+DQo8aW5wdXQgdHlwZT0iaGlkZGVuIiBuYW1lPSJDU1JGVFMiIHZhbHVlPSIyMDExMDkxMjE2MjQ1MCIgLz4NCjxpbnB1dCB0eXBlPSJoaWRkZW4iIG5hbWU9IkNTUkZTUCIgdmFsdWU9Ii9uY29sL3Rlc3Qvb3JkZXJkaXJlY3QuYXNwIiAvPg0KPGlucHV0IHR5cGU9ImhpZGRlbiIgbmFtZT0iUGFSZXEiIHZhbHVlPSI8P3htbCB2ZXJzaW9uPSZxdW90OzEuMCZxdW90Oz8+PFRocmVlRFNlY3VyZT48TWVzc2FnZSBpZD0mcXVvdDsxMjMmcXVvdDs+PFBBUmVxPjx2ZXJzaW9uPjEuMDI8L3ZlcnNpb24+PE1lcmNoYW50PjxtZXJJRD5OUk1BR0VOVE8zPC9tZXJJRD48bmFtZT5OZXRyZXNlYXJjaCBHbWJIICZhbXA7YW1wOyBDby5LRzwvbmFtZT48dXJsPmh0dHA6Ly93d3cubmV0cmVzZWFyY2guZGU8L3VybD48L01lcmNoYW50PjxQdXJjaGFzZT48eGlkPjExNjI4OTgzPC94aWQ+PGFtb3VudD4xMjY4Ljc1PC9hbW91bnQ+PHB1cmNoQW1vdW50PjEyNjguNzU8L3B1cmNoQW1vdW50PjxjdXJyZW5jeT5FVVI8L2N1cnJlbmN5PjwvUHVyY2hhc2U+PENIPjxhY2N0SUQ+NDAwMDAwWFhYWFhYMDAwMjwvYWNjdElEPjxleHBpcnk+MDExNjwvZXhwaXJ5PjxzZWxCcmFuZD48L3NlbEJyYW5kPjwvQ0g+PC9QQVJlcT48L01lc3NhZ2U+PC9UaHJlZURTZWN1cmU+DQoiIC8+DQo8aW5wdXQgdHlwZT0iaGlkZGVuIiBuYW1lPSJUZXJtVXJsIiB2YWx1ZT0iaHR0cHM6Ly9zZWN1cmUub2dvbmUuY29tL25jb2wvdGVzdC9vcmRlcl9BM0RTLmFzcCIgLz4NCjxpbnB1dCB0eXBlPSJoaWRkZW4iIG5hbWU9Ik1EIiB2YWx1ZT0iTUFJTldQVEVTVDAwMDAxMTYyODk4MzAxKjEwNzUyNjIiIC8+DQo8L2Zvcm0+DQo8Zm9ybSBtZXRob2Q9InBvc3QiIGFjdGlvbj0iaHR0cHM6Ly9zZWN1cmUub2dvbmUuY29tL25jb2wvdGVzdC9vcmRlcl9hZ3JlZS5hc3AiIG5hbWU9InVwbG9hZEZvcm0zRCI+DQo8aW5wdXQgdHlwZT0iaGlkZGVuIiBuYW1lPSJDU1JGS0VZIiB2YWx1ZT0iMDZGM0MzMUQ2RkI1MzIzODg4NjhFRjlGNTA5RUNGNzlBQzIwRDJGMyIgLz4NCjxpbnB1dCB0eXBlPSJoaWRkZW4iIG5hbWU9IkNTUkZUUyIgdmFsdWU9IjIwMTEwOTEyMTYyNDUwIiAvPg0KPGlucHV0IHR5cGU9ImhpZGRlbiIgbmFtZT0iQ1NSRlNQIiB2YWx1ZT0iL25jb2wvdGVzdC9vcmRlcmRpcmVjdC5hc3AiIC8+DQo8aW5wdXQgdHlwZT0iaGlkZGVuIiBuYW1lPSJicmFuZGluZyIgdmFsdWU9Ik9nb25lIiAvPg0KPGlucHV0IHR5cGU9ImhpZGRlbiIgbmFtZT0icGF5aWQiIHZhbHVlPSIxMTYyODk4MyIgLz4NCjxpbnB1dCB0eXBlPSJoaWRkZW4iIG5hbWU9InN0b3JlYWxpYXMiIHZhbHVlPSIiIC8+DQo8aW5wdXQgdHlwZT0iaGlkZGVuIiBuYW1lPSJoYXNoX3BhcmFtIiB2YWx1ZT0iOTFBMzA1MjFEMEI0QTA1MEFBRDkzRDM5RDY2RkEyM0Y5OEIzRDQ4RCIgLz4NCjxpbnB1dCB0eXBlPSJoaWRkZW4iIG5hbWU9InhpZF8zRCIgdmFsdWU9IiIgLz4NCjxpbnB1dCB0eXBlPSJoaWRkZW4iIG5hbWU9InN0YXR1c18zRCIgdmFsdWU9IlhYIiAvPg0KPGlucHV0IHR5cGU9ImhpZGRlbiIgbmFtZT0iZWNpXzNEIiB2YWx1ZT0iNyIgLz4NCjxpbnB1dCB0eXBlPSJoaWRkZW4iIG5hbWU9ImNhcmRudW1iZXIiIHZhbHVlPSIiIC8+DQo8aW5wdXQgdHlwZT0iaGlkZGVuIiBuYW1lPSJFY29tX1BheW1lbnRfQ2FyZF9WZXJpZmljYXRpb24iIHZhbHVlPSIqMTA3NTI2MiIgLz4NCjxpbnB1dCB0eXBlPSJoaWRkZW4iIG5hbWU9IkNWQ0ZsYWciIHZhbHVlPSIxIiAvPg0KPGlucHV0IHR5cGU9ImhpZGRlbiIgbmFtZT0iY2F2dl8zRCIgdmFsdWU9IiIgLz4NCjxpbnB1dCB0eXBlPSJoaWRkZW4iIG5hbWU9ImNhdnZhbGdvcml0aG1fM0QiIHZhbHVlPSIiIC8+DQo8aW5wdXQgdHlwZT0iaGlkZGVuIiBuYW1lPSJzaWduYXR1cmVPS18zRCIgdmFsdWU9IiIgLz4NCjxpbnB1dCB0eXBlPSJoaWRkZW4iIG5hbWU9Imhhc2hfcGFyYW1fM0QiIHZhbHVlPSIwMzAzREZDMkI1OTM0MjZCQTExRkQ5RjJBNkQ0NDk5ODEwN0JGN0YzIiAvPg0KPC9mb3JtPg0KPFNDUklQVCBMQU5HVUFHRT0iSmF2YXNjcmlwdCIgRk9SPSJ3aW5kb3ciIEVWRU5UPSJvbkxvYWQiPg0KdmFyIHBvcHVwV2luOw0KdmFyIHN1Ym1pdHBvcHVwV2luID0gMDsNCg0KZnVuY3Rpb24gTG9hZFBvcHVwKCkgew0KCWlmIChzZWxmLm5hbWUgPT0gbnVsbCkJew0KCQlzZWxmLm5hbWUgPSAib2dvbmVNYWluIjsNCgl9DQoJcG9wdXBXaW4gPSB3aW5kb3cub3BlbignYWJvdXQ6YmxhbmsnLCAncG9wdXBXaW4nLCAnaGVpZ2h0PTQwMCwgd2lkdGg9MzkwLCBzdGF0dXM9eWVzLCBkZXBlbmRlbnQ9bm8sIHNjcm9sbGJhcnM9eWVzLCByZXNpemFibGU9bm8nKTsNCglpZiAocG9wdXBXaW4gIT0gbnVsbCkgew0KCQlpZiAgKCFwb3B1cFdpbiB8fCBwb3B1cFdpbi5jbG9zZWQpIHsNCgkJCXJldHVybiAxOw0KCQl9IGVsc2Ugew0KCQkJaWYgKCFwb3B1cFdpbi5vcGVuZXIgfHwgcG9wdXBXaW4ub3BlbmVyID09IG51bGwpIHsNCgkJCQlwb3B1cFdpbi5vcGVuZXIgPSBzZWxmOw0KCQkJfQ0KCQkJc2VsZi5kb2N1bWVudC5mb3Jtcy5kb3dubG9hZGZvcm0zRC50YXJnZXQgPSAncG9wdXBXaW4nOw0KCQkJaWYgKHN1Ym1pdHBvcHVwV2luID09IDEpIHsNCgkJCQlzZWxmLmRvY3VtZW50LmZvcm1zLmRvd25sb2FkZm9ybTNELnN1Ym1pdCgpOw0KCQkJfQ0KCQkJcG9wdXBXaW4uZm9jdXMoKTsNCgkJCXJldHVybiAwOw0KCQl9DQoJfSBlbHNlIHsNCgkJcmV0dXJuIDE7DQoJfQ0KfQ0KCXNlbGYuZG9jdW1lbnQuZm9ybXMuZG93bmxvYWRmb3JtM0Quc3VibWl0KCk7DQovLy0tPg0KPC9TQ1JJUFQ+DQo=</HTML_ANSWER>
114
+ </ncresponse>';
115
+ $directLinkMock = $this->getModelMock('ops/api_directlink', array('call'));
116
+ $directLinkMock->expects($this->any())
117
+ ->method('call')
118
+ ->will($this->returnValue($xmlExample));
119
+
120
+ $class = new ReflectionClass(get_class(Mage::getModel('ops/api_directlink')));
121
+ $method = $class->getMethod('getResponseParams');
122
+ $method->setAccessible(true);
123
+ $result = $method->invokeArgs($directLinkMock, array(array('foo' => '111', 'ORDERID' => 4711), 'bar'));
124
+ $this->assertTrue(is_array($result));
125
+ $this->assertTrue(array_key_exists('orderID', $result));
126
+ $this->assertTrue(array_key_exists('PAYID', $result));
127
+ $this->assertTrue(array_key_exists('PAYIDSUB', $result));
128
+ $this->assertTrue(array_key_exists('NCSTATUS', $result));
129
+ $this->assertTrue(array_key_exists('NCERROR', $result));
130
+ $this->assertTrue(array_key_exists('NCERROR', $result));
131
+ $this->assertTrue(array_key_exists('NCERRORPLUS', $result));
132
+ $this->assertTrue(array_key_exists('ACCEPTANCE', $result));
133
+ $this->assertTrue(array_key_exists('STATUS', $result));
134
+ $this->assertTrue(array_key_exists('amount', $result));
135
+ $this->assertTrue(array_key_exists('currency', $result));
136
+ $this->assertTrue(array_key_exists('HTML_ANSWER', $result));
137
+ }
138
+
139
+ public function testGetResponseParamsWithValidCallButWrongEncodedResponse()
140
+ {
141
+ $xmlExample =
142
+ '<?xml version="1.0"?>
143
+ <ncresponse
144
+ orderID="1121212"
145
+ PAYID="232"
146
+ PAYIDSUB="0"
147
+ NCSTATUS="5"
148
+ NCERROR="50001111"
149
+ NCERRORPLUS="Some of the data entered is incorrect. Please retry."
150
+ ACCEPTANCE=""
151
+ STATUS="0"
152
+ amount=""
153
+ currency=""
154
+ CN="Max Müller">
155
+ <HTML_ANSWER>PGZvcm0gbmFtZT0iZG93bmxvYWRmb3JtM0QiIGFjdGlvbj0iaHR0cHM6Ly9zZWN1cmUub2dvbmUuY29tL25jb2wvdGVzdC9UZXN0XzNEX0FDUy5hc3AiIG1ldGhvZD0icG9zdCI+DQo8Tk9TQ1JJUFQ+DQpKYXZhU2NyaXB0IGlzIGN1cnJlbnRseSBkaXNhYmxlZCBvciBpcyBub3Qgc3VwcG9ydGVkIGJ5IHlvdXIgYnJvd3Nlci48YnI+DQpQbGVhc2UgY2xpY2sgb24gdGhlICZxdW90O0NvbnRpbnVlJnF1b3Q7IGJ1dHRvbiB0byBjb250aW51ZSB0aGUgcHJvY2Vzc2luZyBvZiB5b3VyIDMtRCBzZWN1cmUgdHJhbnNhY3Rpb24uPGJyPg0KPGlucHV0IGNsYXNzPSJuY29sIiB0eXBlPSJzdWJtaXQiIHZhbHVlPSJDb250aW51ZSIgaWQ9InN1Ym1pdDEiIG5hbWU9InN1Ym1pdDEiIC8+DQo8L05PU0NSSVBUPg0KPGlucHV0IHR5cGU9ImhpZGRlbiIgbmFtZT0iQ1NSRktFWSIgdmFsdWU9IjA0MzA0MzI4NkE0M0ZDM0YyRDhFMDFCOUM2MzYwRTA1Qzg5NkZEMzYiIC8+DQo8aW5wdXQgdHlwZT0iaGlkZGVuIiBuYW1lPSJDU1JGVFMiIHZhbHVlPSIyMDExMDkxMjE2MjQ1MCIgLz4NCjxpbnB1dCB0eXBlPSJoaWRkZW4iIG5hbWU9IkNTUkZTUCIgdmFsdWU9Ii9uY29sL3Rlc3Qvb3JkZXJkaXJlY3QuYXNwIiAvPg0KPGlucHV0IHR5cGU9ImhpZGRlbiIgbmFtZT0iUGFSZXEiIHZhbHVlPSI8P3htbCB2ZXJzaW9uPSZxdW90OzEuMCZxdW90Oz8+PFRocmVlRFNlY3VyZT48TWVzc2FnZSBpZD0mcXVvdDsxMjMmcXVvdDs+PFBBUmVxPjx2ZXJzaW9uPjEuMDI8L3ZlcnNpb24+PE1lcmNoYW50PjxtZXJJRD5OUk1BR0VOVE8zPC9tZXJJRD48bmFtZT5OZXRyZXNlYXJjaCBHbWJIICZhbXA7YW1wOyBDby5LRzwvbmFtZT48dXJsPmh0dHA6Ly93d3cubmV0cmVzZWFyY2guZGU8L3VybD48L01lcmNoYW50PjxQdXJjaGFzZT48eGlkPjExNjI4OTgzPC94aWQ+PGFtb3VudD4xMjY4Ljc1PC9hbW91bnQ+PHB1cmNoQW1vdW50PjEyNjguNzU8L3B1cmNoQW1vdW50PjxjdXJyZW5jeT5FVVI8L2N1cnJlbmN5PjwvUHVyY2hhc2U+PENIPjxhY2N0SUQ+NDAwMDAwWFhYWFhYMDAwMjwvYWNjdElEPjxleHBpcnk+MDExNjwvZXhwaXJ5PjxzZWxCcmFuZD48L3NlbEJyYW5kPjwvQ0g+PC9QQVJlcT48L01lc3NhZ2U+PC9UaHJlZURTZWN1cmU+DQoiIC8+DQo8aW5wdXQgdHlwZT0iaGlkZGVuIiBuYW1lPSJUZXJtVXJsIiB2YWx1ZT0iaHR0cHM6Ly9zZWN1cmUub2dvbmUuY29tL25jb2wvdGVzdC9vcmRlcl9BM0RTLmFzcCIgLz4NCjxpbnB1dCB0eXBlPSJoaWRkZW4iIG5hbWU9Ik1EIiB2YWx1ZT0iTUFJTldQVEVTVDAwMDAxMTYyODk4MzAxKjEwNzUyNjIiIC8+DQo8L2Zvcm0+DQo8Zm9ybSBtZXRob2Q9InBvc3QiIGFjdGlvbj0iaHR0cHM6Ly9zZWN1cmUub2dvbmUuY29tL25jb2wvdGVzdC9vcmRlcl9hZ3JlZS5hc3AiIG5hbWU9InVwbG9hZEZvcm0zRCI+DQo8aW5wdXQgdHlwZT0iaGlkZGVuIiBuYW1lPSJDU1JGS0VZIiB2YWx1ZT0iMDZGM0MzMUQ2RkI1MzIzODg4NjhFRjlGNTA5RUNGNzlBQzIwRDJGMyIgLz4NCjxpbnB1dCB0eXBlPSJoaWRkZW4iIG5hbWU9IkNTUkZUUyIgdmFsdWU9IjIwMTEwOTEyMTYyNDUwIiAvPg0KPGlucHV0IHR5cGU9ImhpZGRlbiIgbmFtZT0iQ1NSRlNQIiB2YWx1ZT0iL25jb2wvdGVzdC9vcmRlcmRpcmVjdC5hc3AiIC8+DQo8aW5wdXQgdHlwZT0iaGlkZGVuIiBuYW1lPSJicmFuZGluZyIgdmFsdWU9Ik9nb25lIiAvPg0KPGlucHV0IHR5cGU9ImhpZGRlbiIgbmFtZT0icGF5aWQiIHZhbHVlPSIxMTYyODk4MyIgLz4NCjxpbnB1dCB0eXBlPSJoaWRkZW4iIG5hbWU9InN0b3JlYWxpYXMiIHZhbHVlPSIiIC8+DQo8aW5wdXQgdHlwZT0iaGlkZGVuIiBuYW1lPSJoYXNoX3BhcmFtIiB2YWx1ZT0iOTFBMzA1MjFEMEI0QTA1MEFBRDkzRDM5RDY2RkEyM0Y5OEIzRDQ4RCIgLz4NCjxpbnB1dCB0eXBlPSJoaWRkZW4iIG5hbWU9InhpZF8zRCIgdmFsdWU9IiIgLz4NCjxpbnB1dCB0eXBlPSJoaWRkZW4iIG5hbWU9InN0YXR1c18zRCIgdmFsdWU9IlhYIiAvPg0KPGlucHV0IHR5cGU9ImhpZGRlbiIgbmFtZT0iZWNpXzNEIiB2YWx1ZT0iNyIgLz4NCjxpbnB1dCB0eXBlPSJoaWRkZW4iIG5hbWU9ImNhcmRudW1iZXIiIHZhbHVlPSIiIC8+DQo8aW5wdXQgdHlwZT0iaGlkZGVuIiBuYW1lPSJFY29tX1BheW1lbnRfQ2FyZF9WZXJpZmljYXRpb24iIHZhbHVlPSIqMTA3NTI2MiIgLz4NCjxpbnB1dCB0eXBlPSJoaWRkZW4iIG5hbWU9IkNWQ0ZsYWciIHZhbHVlPSIxIiAvPg0KPGlucHV0IHR5cGU9ImhpZGRlbiIgbmFtZT0iY2F2dl8zRCIgdmFsdWU9IiIgLz4NCjxpbnB1dCB0eXBlPSJoaWRkZW4iIG5hbWU9ImNhdnZhbGdvcml0aG1fM0QiIHZhbHVlPSIiIC8+DQo8aW5wdXQgdHlwZT0iaGlkZGVuIiBuYW1lPSJzaWduYXR1cmVPS18zRCIgdmFsdWU9IiIgLz4NCjxpbnB1dCB0eXBlPSJoaWRkZW4iIG5hbWU9Imhhc2hfcGFyYW1fM0QiIHZhbHVlPSIwMzAzREZDMkI1OTM0MjZCQTExRkQ5RjJBNkQ0NDk5ODEwN0JGN0YzIiAvPg0KPC9mb3JtPg0KPFNDUklQVCBMQU5HVUFHRT0iSmF2YXNjcmlwdCIgRk9SPSJ3aW5kb3ciIEVWRU5UPSJvbkxvYWQiPg0KdmFyIHBvcHVwV2luOw0KdmFyIHN1Ym1pdHBvcHVwV2luID0gMDsNCg0KZnVuY3Rpb24gTG9hZFBvcHVwKCkgew0KCWlmIChzZWxmLm5hbWUgPT0gbnVsbCkJew0KCQlzZWxmLm5hbWUgPSAib2dvbmVNYWluIjsNCgl9DQoJcG9wdXBXaW4gPSB3aW5kb3cub3BlbignYWJvdXQ6YmxhbmsnLCAncG9wdXBXaW4nLCAnaGVpZ2h0PTQwMCwgd2lkdGg9MzkwLCBzdGF0dXM9eWVzLCBkZXBlbmRlbnQ9bm8sIHNjcm9sbGJhcnM9eWVzLCByZXNpemFibGU9bm8nKTsNCglpZiAocG9wdXBXaW4gIT0gbnVsbCkgew0KCQlpZiAgKCFwb3B1cFdpbiB8fCBwb3B1cFdpbi5jbG9zZWQpIHsNCgkJCXJldHVybiAxOw0KCQl9IGVsc2Ugew0KCQkJaWYgKCFwb3B1cFdpbi5vcGVuZXIgfHwgcG9wdXBXaW4ub3BlbmVyID09IG51bGwpIHsNCgkJCQlwb3B1cFdpbi5vcGVuZXIgPSBzZWxmOw0KCQkJfQ0KCQkJc2VsZi5kb2N1bWVudC5mb3Jtcy5kb3dubG9hZGZvcm0zRC50YXJnZXQgPSAncG9wdXBXaW4nOw0KCQkJaWYgKHN1Ym1pdHBvcHVwV2luID09IDEpIHsNCgkJCQlzZWxmLmRvY3VtZW50LmZvcm1zLmRvd25sb2FkZm9ybTNELnN1Ym1pdCgpOw0KCQkJfQ0KCQkJcG9wdXBXaW4uZm9jdXMoKTsNCgkJCXJldHVybiAwOw0KCQl9DQoJfSBlbHNlIHsNCgkJcmV0dXJuIDE7DQoJfQ0KfQ0KCXNlbGYuZG9jdW1lbnQuZm9ybXMuZG93bmxvYWRmb3JtM0Quc3VibWl0KCk7DQovLy0tPg0KPC9TQ1JJUFQ+DQo=</HTML_ANSWER>
156
+ </ncresponse>';
157
+ $xmlExample = utf8_decode($xmlExample);
158
+ $directLinkMock = $this->getModelMock('ops/api_directlink', array('call'));
159
+ $directLinkMock->expects($this->any())
160
+ ->method('call')
161
+ ->will($this->returnValue($xmlExample));
162
+
163
+ $class = new ReflectionClass(get_class(Mage::getModel('ops/api_directlink')));
164
+ $method = $class->getMethod('getResponseParams');
165
+ $method->setAccessible(true);
166
+ $result = $method->invokeArgs($directLinkMock, array(array('foo' => '111', 'ORDERID' => 4711), 'bar'));
167
+ $this->assertTrue(is_array($result));
168
+ $this->assertTrue(array_key_exists('orderID', $result));
169
+ $this->assertTrue(array_key_exists('PAYID', $result));
170
+ $this->assertTrue(array_key_exists('PAYIDSUB', $result));
171
+ $this->assertTrue(array_key_exists('NCSTATUS', $result));
172
+ $this->assertTrue(array_key_exists('NCERROR', $result));
173
+ $this->assertTrue(array_key_exists('NCERROR', $result));
174
+ $this->assertTrue(array_key_exists('NCERRORPLUS', $result));
175
+ $this->assertTrue(array_key_exists('ACCEPTANCE', $result));
176
+ $this->assertTrue(array_key_exists('STATUS', $result));
177
+ $this->assertTrue(array_key_exists('amount', $result));
178
+ $this->assertTrue(array_key_exists('currency', $result));
179
+ $this->assertTrue(array_key_exists('HTML_ANSWER', $result));
180
+ $this->assertTrue(array_key_exists('CN', $result));
181
+ $this->assertEquals('Max Müller', $result['CN']);
182
+ }
183
+
184
+ /**
185
+ * @expectedException Mage_Core_Exception
186
+ */
187
+ public function testGetResponseParamsWithRetryCountExceeded()
188
+ {
189
+ $maxAllowedRetryCount = Netresearch_OPS_Model_Api_DirectLink::MAX_RETRY_COUNT;
190
+ $class = new ReflectionClass(get_class(Mage::getModel('ops/api_directlink')));
191
+ $method = $class->getMethod('getResponseParams');
192
+ $method->setAccessible(true);
193
+ $result = $method->invokeArgs(Mage::getModel('ops/api_directlink'), array(array('foo' => '123', 'ORDERID' => '4711'), 'bar', ++$maxAllowedRetryCount));
194
+ }
195
+
196
+ /**
197
+ * @expectedException Mage_Core_Exception
198
+ */
199
+ public function testGetResponseParamsWithInvalidResponse()
200
+ {
201
+ $xmlExample = '';
202
+ $directLinkMock = $this->getModelMock('ops/api_directlink', array('call'));
203
+ $directLinkMock->expects($this->any())
204
+ ->method('call')
205
+ ->will($this->returnValue($xmlExample));
206
+
207
+ $class = new ReflectionClass(get_class(Mage::getModel('ops/api_directlink')));
208
+ $method = $class->getMethod('getResponseParams');
209
+ $method->setAccessible(true);
210
+ $result = $method->invokeArgs($directLinkMock, array(array('foo' => '12334', 'ORDERID' => 4711), 'bar'));
211
+ }
212
+
213
+ /**
214
+ * @expectedException Mage_Core_Exception
215
+ */
216
+ public function testCheckResponseNcErrorSet()
217
+ {
218
+ $responseParams = array('NCERROR' => '50001111');
219
+ $this->_model->checkResponse($responseParams);
220
+ }
221
+
222
+ /**
223
+ * @expectedException Mage_Core_Exception
224
+ */
225
+ public function testCheckResponseNcErrorEmpty()
226
+ {
227
+ $responseParams = array('NCERROR' => '1', 'NCERRORPLUS' => 'Error occured');
228
+ $this->_model->checkResponse($responseParams);
229
+ }
230
+
231
+ public function testCheckResponseNrErrorWithStatus()
232
+ {
233
+ $responseParams = array('NCERROR' => '1', 'STATUS' => 4);
234
+ try {
235
+ $this->_model->checkResponse($responseParams);
236
+ }
237
+ catch (Exception $e) {
238
+ $this->fail('An unexpected exception has been raised.');
239
+ }
240
+ }
241
+
242
+ public function testPerformRequest()
243
+ {
244
+ $result = array('NCERROR' => 0);
245
+ $directLinkMock = $this->getModelMock('ops/api_directlink', array('getResponseParams'));
246
+ $directLinkMock->expects($this->any())
247
+ ->method('getResponseParams')
248
+ ->will($this->returnValue($result));
249
+ $this->assertEquals($result, $directLinkMock->performRequest(array('foo'), 'bla'));
250
+
251
+ }
252
+ }
253
+
app/code/community/Netresearch/OPS/Test/Model/Backend/Operation/Capture/Additional/OpenInvoiceNlTest.php ADDED
@@ -0,0 +1,305 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Michael Lühr <michael.luehr@netresearch.de>
4
+ * @category Netresearch
5
+ * @copyright Copyright (c) 2014 Netresearch GmbH & Co. KG (http://www.netresearch.de)
6
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
7
+ */
8
+
9
+
10
+
11
+ class Netresearch_OPS_Test_Model_Backend_Operation_Capture_Additional_OpenInvoiceNlTest
12
+ extends EcomDev_PHPUnit_Test_Case
13
+ {
14
+
15
+ protected $openInvoiceNlModel = null;
16
+
17
+ public function setUp()
18
+ {
19
+ parent::setUp();
20
+ $this->openInvoiceNlModel = Mage::getModel('ops/backend_operation_capture_additional_openInvoiceNl');
21
+ $this->mockSessions();
22
+ }
23
+
24
+ public function testExtractAdditionalParamsWithoutShipping1()
25
+ {
26
+ $itemsContainer = Mage::getModel('sales/order_shipment');
27
+ $this->assertTrue(is_array($this->openInvoiceNlModel->extractAdditionalParams($itemsContainer)));
28
+ $this->assertEquals(0, count($this->openInvoiceNlModel->extractAdditionalParams($itemsContainer)));
29
+ $itemsContainer = Mage::getModel('sales/order_invoice');
30
+ $this->assertTrue(is_array($this->openInvoiceNlModel->extractAdditionalParams($itemsContainer)));
31
+ $this->assertEquals(0, count($this->openInvoiceNlModel->extractAdditionalParams($itemsContainer)));
32
+ $orderItem = Mage::getModel('sales/order_item');
33
+ $orderItem->setId(1);
34
+ $orderItem->setQtyOrdered(2);
35
+ $item = Mage::getModel('sales/order_invoice_item');
36
+ $item->setOrderItemId(1);
37
+ $item->setOrderItem($orderItem);
38
+ $item->setName('Item');
39
+ $item->setBasePriceInclTax(19.99);
40
+ $item->setQty(2);
41
+ $item->setTaxPercent(19);
42
+ $itemsContainer->addItem($item);
43
+ $result = $this->openInvoiceNlModel->extractAdditionalParams($itemsContainer);
44
+ $this->assertTrue(is_array($result));
45
+ $this->assertTrue(0 < count($result));
46
+ $this->assertArrayHasKey('ITEMID1', $result);
47
+ $this->assertEquals(1, $result['ITEMID1']);
48
+ $this->assertArrayHasKey('ITEMNAME1', $result);
49
+ $this->assertEquals('Item', $result['ITEMNAME1']);
50
+ $this->assertArrayHasKey('ITEMPRICE1', $result);
51
+ $this->assertEquals(1999, $result['ITEMPRICE1']);
52
+ $this->assertArrayHasKey('ITEMVATCODE1', $result);
53
+ $this->assertEquals('19%', $result['ITEMVATCODE1']);
54
+ $this->assertArrayHasKey('TAXINCLUDED1', $result);
55
+ $this->assertEquals(1, $result['TAXINCLUDED1']);
56
+ }
57
+
58
+ public function testExtractAdditionalParamsWithoutShippingButWithConfigurable()
59
+ {
60
+ $itemsContainer = Mage::getModel('sales/order_shipment');
61
+ $this->assertTrue(is_array($this->openInvoiceNlModel->extractAdditionalParams($itemsContainer)));
62
+ $this->assertEquals(0, count($this->openInvoiceNlModel->extractAdditionalParams($itemsContainer)));
63
+ $itemsContainer = Mage::getModel('sales/order_invoice');
64
+ $this->assertTrue(is_array($this->openInvoiceNlModel->extractAdditionalParams($itemsContainer)));
65
+ $this->assertEquals(0, count($this->openInvoiceNlModel->extractAdditionalParams($itemsContainer)));
66
+ $orderItem = Mage::getModel('sales/order_item');
67
+ $orderItem->setId(1);
68
+ $orderItem->setQtyOrdered(2);
69
+ $item = Mage::getModel('sales/order_invoice_item');
70
+ $item->setOrderItemId(1);
71
+ $item->setOrderItem($orderItem);
72
+ $item->setName('Item');
73
+ $item->setBasePriceInclTax(19.99);
74
+ $item->setQty(2);
75
+ $item->setTaxPercent(19);
76
+ $itemsContainer->addItem($item);
77
+ $item = Mage::getModel('sales/order_invoice_item');
78
+ $orderItem = Mage::getModel('sales/order_item');
79
+ $orderItem->setId(1);
80
+ $orderItem->setQtyOrdered(2);
81
+ $orderItem->setParentItemId(1);
82
+ $item->setOrderItemId(2);
83
+ $item->setOrderItem($orderItem);
84
+ $item->setName('Item');
85
+ $item->setBasePriceInclTax(19.99);
86
+ $item->setQty(2);
87
+ $item->setTaxPercent(19);
88
+ $itemsContainer->addItem($item);
89
+ $result = $this->openInvoiceNlModel->extractAdditionalParams($itemsContainer);
90
+ $this->assertTrue(is_array($result));
91
+ $this->assertTrue(0 < count($result));
92
+ $this->assertArrayHasKey('ITEMID1', $result);
93
+ $this->assertEquals(1, $result['ITEMID1']);
94
+ $this->assertArrayHasKey('ITEMNAME1', $result);
95
+ $this->assertEquals('Item', $result['ITEMNAME1']);
96
+ $this->assertArrayHasKey('ITEMPRICE1', $result);
97
+ $this->assertEquals(1999, $result['ITEMPRICE1']);
98
+ $this->assertArrayHasKey('ITEMVATCODE1', $result);
99
+ $this->assertEquals('19%', $result['ITEMVATCODE1']);
100
+ $this->assertArrayHasKey('TAXINCLUDED1', $result);
101
+ $this->assertEquals(1, $result['TAXINCLUDED1']);
102
+ }
103
+
104
+ public function testExtractAdditionalParamsWithoutShippingButWithTwoNormalInvoiceItems()
105
+ {
106
+ $itemsContainer = Mage::getModel('sales/order_shipment');
107
+ $this->assertTrue(is_array($this->openInvoiceNlModel->extractAdditionalParams($itemsContainer)));
108
+ $this->assertEquals(0, count($this->openInvoiceNlModel->extractAdditionalParams($itemsContainer)));
109
+ $itemsContainer = Mage::getModel('sales/order_invoice');
110
+ $this->assertTrue(is_array($this->openInvoiceNlModel->extractAdditionalParams($itemsContainer)));
111
+ $this->assertEquals(0, count($this->openInvoiceNlModel->extractAdditionalParams($itemsContainer)));
112
+ $orderItem = Mage::getModel('sales/order_item');
113
+ $orderItem->setId(1);
114
+ $orderItem->setQtyOrdered(2);
115
+ $item = Mage::getModel('sales/order_invoice_item');
116
+ $item->setOrderItemId(1);
117
+ $item->setOrderItem($orderItem);
118
+ $item->setName('Item');
119
+ $item->setBasePriceInclTax(19.99);
120
+ $item->setQty(2);
121
+ $item->setTaxPercent(19);
122
+ $itemsContainer->addItem($item);
123
+ $item = Mage::getModel('sales/order_invoice_item');
124
+ $orderItem = Mage::getModel('sales/order_item');
125
+ $orderItem->setId(1);
126
+ $orderItem->setQtyOrdered(2);
127
+ $item->setOrderItemId(2);
128
+ $item->setOrderItem($orderItem);
129
+ $item->setName('Item');
130
+ $item->setBasePriceInclTax(19.99);
131
+ $item->setQty(2);
132
+ $item->setTaxPercent(19);
133
+ $itemsContainer->addItem($item);
134
+ $result = $this->openInvoiceNlModel->extractAdditionalParams($itemsContainer);
135
+ $this->assertTrue(is_array($result));
136
+ $this->assertTrue(0 < count($result));
137
+ $this->assertArrayHasKey('ITEMID1', $result);
138
+ $this->assertEquals(1, $result['ITEMID1']);
139
+ $this->assertArrayHasKey('ITEMNAME1', $result);
140
+ $this->assertEquals('Item', $result['ITEMNAME1']);
141
+ $this->assertArrayHasKey('ITEMPRICE1', $result);
142
+ $this->assertEquals(1999, $result['ITEMPRICE1']);
143
+ $this->assertArrayHasKey('ITEMVATCODE1', $result);
144
+ $this->assertEquals('19%', $result['ITEMVATCODE1']);
145
+ $this->assertArrayHasKey('TAXINCLUDED1', $result);
146
+ $this->assertEquals(1, $result['TAXINCLUDED1']);
147
+
148
+ $this->assertArrayHasKey('ITEMID2', $result);
149
+ $this->assertEquals(1, $result['ITEMID2']);
150
+ $this->assertArrayHasKey('ITEMNAME2', $result);
151
+ $this->assertEquals('Item', $result['ITEMNAME2']);
152
+ $this->assertArrayHasKey('ITEMPRICE2', $result);
153
+ $this->assertEquals(1999, $result['ITEMPRICE2']);
154
+ $this->assertArrayHasKey('ITEMVATCODE2', $result);
155
+ $this->assertEquals('19%', $result['ITEMVATCODE2']);
156
+ $this->assertArrayHasKey('TAXINCLUDED2', $result);
157
+ $this->assertEquals(1, $result['TAXINCLUDED2']);
158
+ }
159
+
160
+ public function testExtractAdditionalParamsWithShipping()
161
+ {
162
+ $itemsContainer = Mage::getModel('sales/order_shipment');
163
+ $this->assertTrue(is_array($this->openInvoiceNlModel->extractAdditionalParams($itemsContainer)));
164
+ $this->assertEquals(0, count($this->openInvoiceNlModel->extractAdditionalParams($itemsContainer)));
165
+ $itemsContainer = Mage::getModel('sales/order_invoice');
166
+ $this->assertTrue(is_array($this->openInvoiceNlModel->extractAdditionalParams($itemsContainer)));
167
+ $this->assertEquals(0, count($this->openInvoiceNlModel->extractAdditionalParams($itemsContainer)));
168
+ $orderItem = Mage::getModel('sales/order_item');
169
+ $orderItem->setId(1);
170
+ $orderItem->setQtyOrdered(2);
171
+ $item = Mage::getModel('sales/order_invoice_item');
172
+ $item->setOrderItemId(1);
173
+ $item->setOrderItem($orderItem);
174
+ $item->setName('Item');
175
+ $item->setBasePriceInclTax(19.99);
176
+ $item->setQty(2);
177
+ $item->setTaxPercent(19);
178
+ $itemsContainer->addItem($item);
179
+ $itemsContainer->setBaseShippingInclTax(10.00);
180
+ $order = MAge::getModel('sales/order');
181
+ $order->setShippingDescription('foo');
182
+ $payment = Mage::getModel('sales/order_payment');
183
+ $payment->setMethod('ops_openInvoiceNl');
184
+ $order->setPayment($payment);
185
+ $itemsContainer->setOrder($order);
186
+ $result = $this->openInvoiceNlModel->extractAdditionalParams($itemsContainer);
187
+ $this->assertTrue(is_array($result));
188
+ $this->assertTrue(0 < count($result));
189
+ $this->assertArrayHasKey('ITEMID1', $result);
190
+ $this->assertEquals(1, $result['ITEMID1']);
191
+ $this->assertArrayHasKey('ITEMNAME1', $result);
192
+ $this->assertEquals('Item', $result['ITEMNAME1']);
193
+ $this->assertArrayHasKey('ITEMPRICE1', $result);
194
+ $this->assertEquals(1999, $result['ITEMPRICE1']);
195
+ $this->assertArrayHasKey('ITEMVATCODE1', $result);
196
+ $this->assertEquals('19%', $result['ITEMVATCODE1']);
197
+ $this->assertArrayHasKey('TAXINCLUDED1', $result);
198
+ $this->assertEquals(1, $result['TAXINCLUDED1']);
199
+ $this->assertArrayHasKey('ITEMID2', $result);
200
+ $this->assertEquals('SHIPPING', $result['ITEMID2']);
201
+ $this->assertArrayHasKey('ITEMNAME2', $result);
202
+ $this->assertEquals(substr($order->getShippingDescription(), 0, 30), $result['ITEMNAME2']);
203
+ $this->assertArrayHasKey('ITEMPRICE2', $result);
204
+ $this->assertEquals(Mage::helper('ops/data')->getAmount(10.00), $result['ITEMPRICE2']);
205
+ $this->assertArrayHasKey('ITEMQUANT2', $result);
206
+ $this->assertEquals(1, $result['ITEMQUANT2']);
207
+ $this->assertArrayHasKey('ITEMVATCODE2', $result);
208
+ $this->assertEquals(floatval($payment->getMethodInstance()->getShippingTaxRate($order)).'%', $result['ITEMVATCODE2']);
209
+ $this->assertArrayHasKey('TAXINCLUDED2', $result);
210
+ $this->assertEquals(1, $result['TAXINCLUDED2']);
211
+ }
212
+
213
+ public function testExtractAdditionalParamsWithShippingAndDiscount()
214
+ {
215
+ $itemsContainer = Mage::getModel('sales/order_shipment');
216
+ $this->assertTrue(is_array($this->openInvoiceNlModel->extractAdditionalParams($itemsContainer)));
217
+ $this->assertEquals(0, count($this->openInvoiceNlModel->extractAdditionalParams($itemsContainer)));
218
+ $itemsContainer = Mage::getModel('sales/order_invoice');
219
+ $this->assertTrue(is_array($this->openInvoiceNlModel->extractAdditionalParams($itemsContainer)));
220
+ $this->assertEquals(0, count($this->openInvoiceNlModel->extractAdditionalParams($itemsContainer)));
221
+ $orderItem = Mage::getModel('sales/order_item');
222
+ $orderItem->setId(1);
223
+ $orderItem->setQtyOrdered(2);
224
+ $item = Mage::getModel('sales/order_invoice_item');
225
+ $item->setOrderItemId(1);
226
+ $item->setOrderItem($orderItem);
227
+ $item->setName('Item');
228
+ $item->setBasePriceInclTax(19.99);
229
+ $item->setQty(2);
230
+ $item->setTaxPercent(19);
231
+ $itemsContainer->addItem($item);
232
+ $itemsContainer->setBaseShippingInclTax(10.00);
233
+ $itemsContainer->setBaseDiscountAmount(-10.00);
234
+ $order = Mage::getModel('sales/order');
235
+ $order->setShippingDescription('foo');
236
+ $order->setCouponRuleName('Foo');
237
+ $payment = Mage::getModel('sales/order_payment');
238
+ $payment->setMethod('ops_openInvoiceNl');
239
+ $order->setPayment($payment);
240
+ $itemsContainer->setOrder($order);
241
+ $result = $this->openInvoiceNlModel->extractAdditionalParams($itemsContainer);
242
+ $this->assertTrue(is_array($result));
243
+ $this->assertTrue(0 < count($result));
244
+ $this->assertArrayHasKey('ITEMID1', $result);
245
+ $this->assertEquals(1, $result['ITEMID1']);
246
+ $this->assertArrayHasKey('ITEMNAME1', $result);
247
+ $this->assertEquals('Item', $result['ITEMNAME1']);
248
+ $this->assertArrayHasKey('ITEMPRICE1', $result);
249
+ $this->assertEquals(1999, $result['ITEMPRICE1']);
250
+ $this->assertArrayHasKey('ITEMVATCODE1', $result);
251
+ $this->assertEquals('19%', $result['ITEMVATCODE1']);
252
+ $this->assertArrayHasKey('TAXINCLUDED1', $result);
253
+ $this->assertEquals(1, $result['TAXINCLUDED1']);
254
+
255
+ $this->assertArrayHasKey('ITEMID2', $result);
256
+ $this->assertEquals('DISCOUNT', $result['ITEMID2']);
257
+ $this->assertArrayHasKey('ITEMNAME2', $result);
258
+ $this->assertEquals('Foo', $result['ITEMNAME2']);
259
+ $this->assertArrayHasKey('ITEMPRICE2', $result);
260
+ $this->assertEquals(Mage::helper('ops/data')->getAmount(-10.00), $result['ITEMPRICE2']);
261
+ $this->assertArrayHasKey('ITEMQUANT2', $result);
262
+ $this->assertEquals(1, $result['ITEMQUANT2']);
263
+ $this->assertArrayHasKey('ITEMVATCODE2', $result);
264
+ $this->assertEquals(floatval($payment->getMethodInstance()->getShippingTaxRate($order)).'%', $result['ITEMVATCODE2']);
265
+ $this->assertArrayHasKey('TAXINCLUDED2', $result);
266
+ $this->assertEquals(1, $result['TAXINCLUDED2']);
267
+
268
+ $this->assertArrayHasKey('ITEMID3', $result);
269
+ $this->assertEquals('SHIPPING', $result['ITEMID3']);
270
+ $this->assertArrayHasKey('ITEMNAME3', $result);
271
+ $this->assertEquals(substr($order->getShippingDescription(), 0, 30), $result['ITEMNAME3']);
272
+ $this->assertArrayHasKey('ITEMPRICE3', $result);
273
+ $this->assertEquals(Mage::helper('ops/data')->getAmount(10.00), $result['ITEMPRICE3']);
274
+ $this->assertArrayHasKey('ITEMQUANT3', $result);
275
+ $this->assertEquals(1, $result['ITEMQUANT3']);
276
+ $this->assertArrayHasKey('ITEMVATCODE3', $result);
277
+ $this->assertEquals(floatval($payment->getMethodInstance()->getShippingTaxRate($order)).'%', $result['ITEMVATCODE3']);
278
+ $this->assertArrayHasKey('TAXINCLUDED3', $result);
279
+ $this->assertEquals(1, $result['TAXINCLUDED3']);
280
+ }
281
+
282
+ protected function mockSessions(){
283
+ $sessionMock = $this->getModelMockBuilder('checkout/session')
284
+ ->disableOriginalConstructor()
285
+ ->setMethods(null)
286
+ ->getMock();
287
+ $this->replaceByMock('singleton', 'checkout/session', $sessionMock);
288
+ $sessionMock = $this->getModelMockBuilder('adminhtml/session_quote')
289
+ ->disableOriginalConstructor()
290
+ ->setMethods(null)
291
+ ->getMock();
292
+ $this->replaceByMock('singleton', 'adminhtml/session_quote', $sessionMock);
293
+ $sessionMock = $this->getModelMockBuilder('customer/session')
294
+ ->disableOriginalConstructor()
295
+ ->setMethods(null)
296
+ ->getMock();
297
+ $this->replaceByMock('singleton', 'customer/session', $sessionMock);
298
+ }
299
+
300
+ public function tearDown()
301
+ {
302
+ parent::tearDown();
303
+ $this->openInvoiceNlModel = null;
304
+ }
305
+ }
app/code/community/Netresearch/OPS/Test/Model/Backend/Operation/Capture/ParameterTest.php ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Michael Lühr <michael.luehr@netresearch.de>
4
+ * @category Netresearch_OPS
5
+ * @copyright Copyright (c) 2014 Netresearch GmbH & Co. KG (http://www.netresearch.de)
6
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
7
+ */
8
+ class Netresearch_OPS_Test_Model_Backend_Operation_Capture_ParameterTest extends EcomDev_PHPUnit_Test_Case
9
+ {
10
+
11
+ public function testGetRequestParams()
12
+ {
13
+ $fakePayment = new Varien_Object();
14
+ $fakePayment->setOrder(new Varien_Object());
15
+ $fakePayment->setAdditionalInformation(array('paymentId' => '4711'));
16
+ $arrInfo = array('operation' => 'capture');
17
+ $amount = 10;
18
+ $opsPaymentMethod = Mage::getModel('ops/payment_abstract');
19
+
20
+ $captureParameterModel = Mage::getModel('ops/backend_operation_capture_parameter');
21
+ $requestParams = $captureParameterModel->getRequestParams($opsPaymentMethod, $fakePayment, $amount, $arrInfo);
22
+ $this->assertArrayHasKey('AMOUNT', $requestParams);
23
+ $this->assertArrayHasKey('PAYID', $requestParams);
24
+ $this->assertArrayHasKey('OPERATION', $requestParams);
25
+ $this->assertArrayHasKey('CURRENCY', $requestParams);
26
+
27
+ $this->assertEquals(1000, $requestParams['AMOUNT']);
28
+ $this->assertEquals(4711, $requestParams['PAYID']);
29
+ $this->assertEquals('capture', $requestParams['OPERATION']);
30
+ $this->assertEquals(Mage::app()->getStore($fakePayment->getOrder()->getStoreId())->getBaseCurrencyCode(), $requestParams['CURRENCY']);
31
+ }
32
+
33
+ public function testGetRequestParamsWithAdditionalParameters()
34
+ {
35
+ $fakePayment = Mage::getModel('sales/order_payment');
36
+ $fakePayment->setOrder(MAge::getModel('sales/order'));
37
+ $fakePayment->setAdditionalInformation(array('paymentId' => '4711'));
38
+ $fakeInvoice = Mage::getModel('sales/order_invoice');
39
+ $fakePayment->setInvoice($fakeInvoice);
40
+ $arrInfo = array('operation' => 'capture');
41
+ $amount = 10;
42
+ $opsPaymentMethod = Mage::getModel('ops/payment_openInvoiceNl');
43
+ $captureParameterModel = Mage::getModel('ops/backend_operation_capture_parameter');
44
+ $requestParams = $captureParameterModel->getRequestParams($opsPaymentMethod, $fakePayment, $amount, $arrInfo);
45
+ $this->assertArrayHasKey('AMOUNT', $requestParams);
46
+ $this->assertArrayHasKey('PAYID', $requestParams);
47
+ $this->assertArrayHasKey('OPERATION', $requestParams);
48
+ $this->assertArrayHasKey('CURRENCY', $requestParams);
49
+
50
+ $this->assertEquals(1000, $requestParams['AMOUNT']);
51
+ $this->assertEquals(4711, $requestParams['PAYID']);
52
+ $this->assertEquals('capture', $requestParams['OPERATION']);
53
+ $this->assertEquals(Mage::app()->getStore($fakePayment->getOrder()->getStoreId())->getBaseCurrencyCode(), $requestParams['CURRENCY']);
54
+ }
55
+
56
+ }
app/code/community/Netresearch/OPS/Test/Model/Backend/Operation/ParameterTest.php ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Michael Lühr <michael.luehr@netresearch.de>
4
+ * @category Netresearch_OPS
5
+ * @copyright Copyright (c) 2014 Netresearch GmbH & Co. KG (http://www.netresearch.de)
6
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
7
+ */
8
+
9
+ class Netresearch_OPS_Test_Model_Backend_Operation_ParameterTest extends EcomDev_PHPUnit_Test_Case
10
+ {
11
+
12
+ /**
13
+ * @expectedException Mage_Core_Exception
14
+ */
15
+ public function testGetParameterForWillThrowException()
16
+ {
17
+ $fakePayment = new Varien_Object();
18
+ $arrInfo = array();
19
+ $amount = 0;
20
+ $opsPaymentMethod = Mage::getModel('ops/payment_abstract');
21
+ Mage::getModel('ops/backend_operation_parameter')->getParameterFor('NOT SUPPORTED OPERATION TYPE', $opsPaymentMethod, $fakePayment, $amount, $arrInfo);
22
+ }
23
+
24
+ public function testGetParameterForCaptureWillReturnArray()
25
+ {
26
+ $fakePayment = new Varien_Object();
27
+ $fakePayment->setOrder(new Varien_Object());
28
+ $fakePayment->setAdditionalInformation(array('paymentId' => '4711'));
29
+ $arrInfo = array('operation' => 'capture');
30
+ $amount = 10;
31
+ $opsPaymentMethod = Mage::getModel('ops/payment_abstract');
32
+ $requestParams = Mage::getModel('ops/backend_operation_parameter')->getParameterFor(Netresearch_OPS_Model_Payment_Abstract::OPS_CAPTURE_TRANSACTION_TYPE, $opsPaymentMethod, $fakePayment, $amount, $arrInfo);
33
+ $this->assertArrayHasKey('AMOUNT', $requestParams);
34
+ $this->assertArrayHasKey('PAYID', $requestParams);
35
+ $this->assertArrayHasKey('OPERATION', $requestParams);
36
+ $this->assertArrayHasKey('CURRENCY', $requestParams);
37
+
38
+ $this->assertEquals(1000, $requestParams['AMOUNT']);
39
+ $this->assertEquals(4711, $requestParams['PAYID']);
40
+ $this->assertEquals('capture', $requestParams['OPERATION']);
41
+ $this->assertEquals(Mage::app()->getStore($fakePayment->getOrder()->getStoreId())->getBaseCurrencyCode(), $requestParams['CURRENCY']);
42
+ }
43
+
44
+ }
app/code/community/Netresearch/OPS/Test/Model/Backend/Operation/Refund/Additional/OpenInvoiceNlTest.php ADDED
@@ -0,0 +1,232 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Netresearch_OPS_Test_Model_Backend_Operation_Refund_Additional_OpenInvoiceNlTest extends EcomDev_PHPUnit_Test_Case
4
+ {
5
+ protected $openInvoiceNlModel = null;
6
+ protected $testInvoice = null;
7
+
8
+ public function setUp()
9
+ {
10
+ parent::setUp();
11
+ $this->openInvoiceNlModel = Mage::getModel('ops/backend_operation_refund_additional_openInvoiceNl');
12
+
13
+ $invoice = Mage::getModel('sales/order_invoice');
14
+ // add first item to invoice
15
+ $item = Mage::getModel('sales/order_invoice_item');
16
+ $orderItem = Mage::getModel('sales/order_item');
17
+ $orderItem->setId(1);
18
+ $orderItem->setQtyOrdered(2);
19
+ $item->setOrderItemId(1);
20
+ $item->setOrderItem($orderItem);
21
+ $item->setName('Item 1');
22
+ $item->setBasePriceInclTax(42.99);
23
+ $item->setQty(2);
24
+ $item->setTaxPercent(19);
25
+ $invoice->addItem($item);
26
+ // add second item to invoice
27
+ $orderItem = Mage::getModel('sales/order_item');
28
+ $orderItem->setId(2);
29
+ $orderItem->setQtyOrdered(2);
30
+ $item = Mage::getModel('sales/order_invoice_item');
31
+ $item->setOrderItemId(2);
32
+ $item->setOrderItem($orderItem);
33
+ $item->setName('Item 2');
34
+ $item->setBasePriceInclTax(19.99);
35
+ $item->setQty(2);
36
+ $item->setTaxPercent(7);
37
+ $invoice->addItem($item);
38
+ // add shipping and discount
39
+ $invoice->setBaseShippingInclTax(10.00);
40
+ $order = Mage::getModel('sales/order');
41
+ $order->setShippingDescription('SuperFunShipping');
42
+ $payment = Mage::getModel('sales/order_payment');
43
+ $payment->setMethod('ops_openInvoiceNl');
44
+ $order->setPayment($payment);
45
+ $invoice->setOrder($order);
46
+ $this->testInvoice = $invoice;
47
+
48
+ $sessionMock = $this->getModelMockBuilder('adminhtml/session_quote')
49
+ ->disableOriginalConstructor()
50
+ ->setMethods(null)
51
+ ->getMock();
52
+ $this->replaceByMock('singleton', 'adminhtml/session_quote', $sessionMock);
53
+ $sessionMock = $this->getModelMockBuilder('checkout/session')
54
+ ->disableOriginalConstructor()
55
+ ->setMethods(null)
56
+ ->getMock();
57
+ $this->replaceByMock('singleton', 'checkout/session', $sessionMock);
58
+ $sessionMock = $this->getModelMockBuilder('customer/session')
59
+ ->disableOriginalConstructor()
60
+ ->setMethods(null)
61
+ ->getMock();
62
+ $this->replaceByMock('singleton', 'customer/session', $sessionMock);
63
+ }
64
+
65
+
66
+ public function testExtractWithoutShippingAndAdjustments()
67
+ {
68
+ $params =
69
+ array(
70
+ 'creditmemo' => array(
71
+ 'items' => array(
72
+ 1 => array(
73
+ 'qty' => 2
74
+ ),
75
+ 2 => array(
76
+ 'qty' => 0
77
+ )
78
+ ),
79
+ 'shipping_amount' => 0,
80
+ 'adjustment_positive' => 0,
81
+ 'adjustment_negative' => 0
82
+
83
+ )
84
+ );
85
+
86
+ $this->mockRefundHelper($params);
87
+ $result = $this->openInvoiceNlModel->extractAdditionalParams($this->testInvoice);
88
+ // refunded item
89
+ $this->assertTrue(is_array($result));
90
+ $this->assertTrue(0 < count($result));
91
+ $this->assertArrayHasKey('ITEMID1', $result);
92
+ $this->assertEquals(1, $result['ITEMID1']);
93
+ $this->assertArrayHasKey('ITEMNAME1', $result);
94
+ $this->assertEquals('Item 1', $result['ITEMNAME1']);
95
+ $this->assertArrayHasKey('ITEMPRICE1', $result);
96
+ $this->assertEquals(4299, $result['ITEMPRICE1']);
97
+ $this->assertArrayHasKey('ITEMVATCODE1', $result);
98
+ $this->assertEquals('19%', $result['ITEMVATCODE1']);
99
+ $this->assertArrayHasKey('TAXINCLUDED1', $result);
100
+ $this->assertEquals(1, $result['TAXINCLUDED1']);
101
+ $this->assertArrayHasKey('ITEMQUANT1', $result);
102
+ $this->assertEquals(2, $result['ITEMQUANT1']);
103
+ // 'ignored item'
104
+ $this->assertArrayHasKey('ITEMID2', $result);
105
+ $this->assertEquals(2, $result['ITEMID2']);
106
+ $this->assertArrayHasKey('ITEMNAME2', $result);
107
+ $this->assertEquals('Item 2', $result['ITEMNAME2']);
108
+ $this->assertArrayHasKey('ITEMPRICE2', $result);
109
+ $this->assertEquals(1999, $result['ITEMPRICE2']);
110
+ $this->assertArrayHasKey('ITEMVATCODE2', $result);
111
+ $this->assertEquals('7%', $result['ITEMVATCODE2']);
112
+ $this->assertArrayHasKey('TAXINCLUDED2', $result);
113
+ $this->assertEquals(1, $result['TAXINCLUDED2']);
114
+ $this->assertArrayHasKey('ITEMQUANT2', $result);
115
+ $this->assertEquals(0, $result['ITEMQUANT2']);
116
+ // amount
117
+ $this->assertArrayHasKey('AMOUNT', $result);
118
+ $this->assertEquals(8598, $result['AMOUNT']);
119
+ }
120
+
121
+
122
+ public function testWithShippingAndAllAdjustments()
123
+ {
124
+ $params = array(
125
+ 'creditmemo' => array(
126
+ 'items' => array(
127
+ 1 => array(
128
+ 'qty' => 0
129
+ ),
130
+ 2 => array(
131
+ 'qty' => 0
132
+ )
133
+ ),
134
+ 'shipping_amount' => 5,
135
+ 'adjustment_positive' => 5,
136
+ 'adjustment_negative' => 10
137
+
138
+ )
139
+ );
140
+ $this->mockRefundHelper($params);
141
+ $result = $this->openInvoiceNlModel->extractAdditionalParams($this->testInvoice);
142
+ // Test our items
143
+ $this->assertTrue(is_array($result));
144
+ $this->assertTrue(0 < count($result));
145
+ $this->assertArrayHasKey('ITEMID1', $result);
146
+ $this->assertEquals(1, $result['ITEMID1']);
147
+ $this->assertArrayHasKey('ITEMNAME1', $result);
148
+ $this->assertEquals('Item 1', $result['ITEMNAME1']);
149
+ $this->assertArrayHasKey('ITEMPRICE1', $result);
150
+ $this->assertEquals(4299, $result['ITEMPRICE1']);
151
+ $this->assertArrayHasKey('ITEMVATCODE1', $result);
152
+ $this->assertEquals('19%', $result['ITEMVATCODE1']);
153
+ $this->assertArrayHasKey('TAXINCLUDED1', $result);
154
+ $this->assertEquals(1, $result['TAXINCLUDED1']);
155
+ $this->assertArrayHasKey('ITEMQUANT1', $result);
156
+ $this->assertEquals(0, $result['ITEMQUANT1']);
157
+ $this->assertArrayHasKey('ITEMID2', $result);
158
+ $this->assertEquals(2, $result['ITEMID2']);
159
+ $this->assertArrayHasKey('ITEMNAME2', $result);
160
+ $this->assertEquals('Item 2', $result['ITEMNAME2']);
161
+ $this->assertArrayHasKey('ITEMPRICE2', $result);
162
+ $this->assertEquals(1999, $result['ITEMPRICE2']);
163
+ $this->assertArrayHasKey('ITEMVATCODE2', $result);
164
+ $this->assertEquals('7%', $result['ITEMVATCODE2']);
165
+ $this->assertArrayHasKey('TAXINCLUDED2', $result);
166
+ $this->assertEquals(1, $result['TAXINCLUDED2']);
167
+ $this->assertArrayHasKey('ITEMQUANT2', $result);
168
+ $this->assertEquals(0, $result['ITEMQUANT2']);
169
+
170
+ // shipping
171
+ $this->assertArrayHasKey('ITEMID3', $result);
172
+ $this->assertEquals('SHIPPING', $result['ITEMID3']);
173
+ $this->assertArrayHasKey('ITEMNAME3', $result);
174
+ $this->assertEquals('SuperFunShipping', $result['ITEMNAME3']);
175
+ $this->assertArrayHasKey('ITEMPRICE3', $result);
176
+ // note, that this is the refunded amount, not the actual shipping cost of the invoice
177
+ $this->assertEquals(500, $result['ITEMPRICE3']);
178
+ $this->assertArrayHasKey('ITEMVATCODE3', $result);
179
+ $this->assertEquals('0%', $result['ITEMVATCODE3']);
180
+ $this->assertArrayHasKey('TAXINCLUDED3', $result);
181
+ $this->assertEquals(1, $result['TAXINCLUDED3']);
182
+ $this->assertArrayHasKey('ITEMQUANT3', $result);
183
+ $this->assertEquals(1, $result['ITEMQUANT3']);
184
+ // adjustment refund
185
+ $this->assertArrayHasKey('ITEMID4', $result);
186
+ $this->assertEquals('ADJUSTREFUND', $result['ITEMID4']);
187
+ $this->assertArrayHasKey('ITEMNAME3', $result);
188
+ $this->assertEquals('Adjustment Refund', $result['ITEMNAME4']);
189
+ $this->assertArrayHasKey('ITEMPRICE4', $result);
190
+ $this->assertEquals(500, $result['ITEMPRICE4']);
191
+ $this->assertArrayHasKey('ITEMVATCODE4', $result);
192
+ $this->assertEquals('0%', $result['ITEMVATCODE4']);
193
+ $this->assertArrayHasKey('TAXINCLUDED4', $result);
194
+ $this->assertEquals(1, $result['TAXINCLUDED4']);
195
+ $this->assertArrayHasKey('ITEMQUANT4', $result);
196
+ $this->assertEquals(1, $result['ITEMQUANT4']);
197
+ // adjustment fee
198
+ $this->assertArrayHasKey('ITEMID5', $result);
199
+ $this->assertEquals('ADJUSTFEE', $result['ITEMID5']);
200
+ $this->assertArrayHasKey('ITEMNAME5', $result);
201
+ $this->assertEquals('Adjustment Fee', $result['ITEMNAME5']);
202
+ $this->assertArrayHasKey('ITEMPRICE5', $result);
203
+ $this->assertEquals(-1000, $result['ITEMPRICE5']);
204
+ $this->assertArrayHasKey('ITEMVATCODE5', $result);
205
+ $this->assertEquals('0%', $result['ITEMVATCODE5']);
206
+ $this->assertArrayHasKey('TAXINCLUDED5', $result);
207
+ $this->assertEquals(1, $result['TAXINCLUDED5']);
208
+ $this->assertArrayHasKey('ITEMQUANT5', $result);
209
+ $this->assertEquals(1, $result['ITEMQUANT5']);
210
+ // amount: 5+5+(-10)
211
+ $this->assertArrayHasKey('AMOUNT', $result);
212
+ $this->assertEquals(0, $result['AMOUNT']);
213
+ }
214
+
215
+ protected function mockRefundHelper($params)
216
+ {
217
+ $helperMock = $this->getHelperMock('ops/order_refund', array('getCreditMemoRequestParams', 'createRefundTransaction'));
218
+ $helperMock->expects($this->any())
219
+ ->method('getCreditMemoRequestParams')
220
+ ->will($this->returnValue($params));
221
+ $this->replaceByMock('helper', 'ops/order_refund', $helperMock);
222
+ }
223
+
224
+
225
+ public function tearDown()
226
+ {
227
+ parent::tearDown();
228
+ $this->openInvoiceNlModel = null;
229
+ $this->testInvoice = null;
230
+ }
231
+ }
232
+
app/code/community/Netresearch/OPS/Test/Model/Backend/Operation/Refund/ParameterTest.php ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Netresearch_OPS_Test_Model_Backend_Operation_Refund_ParameterTest extends EcomDev_PHPUnit_Test_Case
4
+ {
5
+
6
+ public function testGetRequestParams()
7
+ {
8
+ $fakePayment = new Varien_Object();
9
+ $fakePayment->setOrder(new Varien_Object());
10
+ $fakePayment->setAdditionalInformation(array('paymentId' => '4711'));
11
+ $arrInfo = array(
12
+ 'operation' => 'refund',
13
+ 'invoice_id' => 2
14
+ );
15
+ $amount = 10;
16
+ $opsPaymentMethod = Mage::getModel('ops/payment_abstract');
17
+
18
+ $captureParameterModel = Mage::getModel('ops/backend_operation_refund_parameter');
19
+ $requestParams = $captureParameterModel->getRequestParams($opsPaymentMethod, $fakePayment, $amount, $arrInfo);
20
+ $this->assertArrayHasKey('AMOUNT', $requestParams);
21
+ $this->assertArrayHasKey('PAYID', $requestParams);
22
+ $this->assertArrayHasKey('OPERATION', $requestParams);
23
+ $this->assertArrayHasKey('CURRENCY', $requestParams);
24
+
25
+ $this->assertEquals(1000, $requestParams['AMOUNT']);
26
+ $this->assertEquals(4711, $requestParams['PAYID']);
27
+ $this->assertEquals('refund', $requestParams['OPERATION']);
28
+ $this->assertEquals(Mage::app()->getStore($fakePayment->getOrder()->getStoreId())->getBaseCurrencyCode(), $requestParams['CURRENCY']);
29
+ }
30
+
31
+ public function testGetRequestParamsWithAdditionalParameters()
32
+ {
33
+ $fakePayment = Mage::getModel('sales/order_payment');
34
+ $fakePayment->setOrder(Mage::getModel('sales/order'));
35
+ $fakePayment->setAdditionalInformation(array('paymentId' => '4711'));
36
+ $fakeInvoice = Mage::getModel('sales/order_invoice');
37
+ $fakePayment->setInvoice($fakeInvoice);
38
+ $arrInfo = array(
39
+ 'operation' => 'refund',
40
+ 'invoice_id' => 2
41
+ );
42
+ $amount = 10;
43
+ $opsPaymentMethod = Mage::getModel('ops/payment_openInvoiceNl');
44
+ $captureParameterModel = Mage::getModel('ops/backend_operation_refund_parameter');
45
+ $this->mockRefundHelper();
46
+ $requestParams = $captureParameterModel->getRequestParams($opsPaymentMethod, $fakePayment, $amount, $arrInfo);
47
+ $this->assertArrayHasKey('AMOUNT', $requestParams);
48
+ $this->assertArrayHasKey('PAYID', $requestParams);
49
+ $this->assertArrayHasKey('OPERATION', $requestParams);
50
+ $this->assertArrayHasKey('CURRENCY', $requestParams);
51
+
52
+ $this->assertEquals(1000, $requestParams['AMOUNT']);
53
+ $this->assertEquals(4711, $requestParams['PAYID']);
54
+ $this->assertEquals('refund', $requestParams['OPERATION']);
55
+ $this->assertEquals(Mage::app()->getStore($fakePayment->getOrder()->getStoreId())->getBaseCurrencyCode(), $requestParams['CURRENCY']);
56
+ }
57
+
58
+ protected function mockRefundHelper()
59
+ {
60
+ $helperMock = $this->getHelperMock('ops/order_refund', array('getCreditMemoRequestParams', 'createRefundTransaction'));
61
+ $params = array(
62
+ 'creditmemo' => array(
63
+ 'items' => array(
64
+ 1 => array(
65
+ 'qty' => 0
66
+ ),
67
+ 2 => array(
68
+ 'qty' => 0
69
+ )
70
+ ),
71
+ 'shipping_amount' => 0,
72
+ 'adjustment_positive' => 10,
73
+ 'adjustment_negative' => 0
74
+
75
+ )
76
+ );
77
+ $helperMock->expects($this->any())
78
+ ->method('getCreditMemoRequestParams')
79
+ ->will($this->returnValue($params));
80
+ $this->replaceByMock('helper', 'ops/order_refund', $helperMock);
81
+ }
82
+
83
+ }
84
+
app/code/community/Netresearch/OPS/Test/Model/ConfigTest.php ADDED
@@ -0,0 +1,522 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Netresearch_OPS_Test_Model_ConfigTest
4
+ extends EcomDev_PHPUnit_Test_Case_Config
5
+ {
6
+ /**
7
+ * @var $_model Netresearch_OPS_Model_Config
8
+ */
9
+ private $_model;
10
+
11
+ public function setUp()
12
+ {
13
+ parent::setup();
14
+ $this->_model = Mage::getModel('ops/config');
15
+ }
16
+
17
+ public function testType()
18
+ {
19
+ $this->assertInstanceOf('Netresearch_OPS_Model_Config', $this->_model);
20
+ }
21
+
22
+ public function testGetIntersolveBrands()
23
+ {
24
+ $this->assertTrue(is_array($this->_model->getIntersolveBrands(null)));
25
+ $this->assertEquals(
26
+ 0,
27
+ sizeof($this->_model->getIntersolveBrands(null))
28
+ );
29
+
30
+ $path = 'payment/ops_interSolve/brands';
31
+
32
+ $newVouchers = array(
33
+ array('brand' => '1234', 'value' => '1234'),
34
+ array('brand' => '5678', 'value' => '5678'),
35
+ array('brand' => '9012', 'value' => '9012'),
36
+ );
37
+
38
+ $store = Mage::app()->getStore(0)->load(0);
39
+ $store->setConfig($path, serialize($newVouchers));
40
+ $this->assertEquals(
41
+ sizeof($newVouchers),
42
+ sizeof($this->_model->getIntersolveBrands(null))
43
+ );
44
+ }
45
+
46
+ public function testGetInlinePaymentCcTypes()
47
+ {
48
+ $sourceModel = Mage::getModel(
49
+ 'ops/source_cc_aliasInterfaceEnabledTypes'
50
+ );
51
+
52
+ $pathRedirectAll = 'payment/ops_cc/redirect_all';
53
+ $pathSpecific = 'payment/ops_cc/inline_types';
54
+ $store = Mage::app()->getStore(0)->load(0);
55
+
56
+ $store->resetConfig();
57
+ $store->setConfig($pathRedirectAll, 0);
58
+ $store->setConfig($pathSpecific, 'MasterCard,VISA');
59
+ $this->assertEquals(
60
+ array('MasterCard', 'VISA'),
61
+ $this->_model->getInlinePaymentCcTypes()
62
+ );
63
+
64
+ $store->resetConfig();
65
+ $store->setConfig($pathRedirectAll, 1);
66
+ $store->setConfig($pathSpecific, 'MasterCard,VISA');
67
+ $this->assertEquals(array(), $this->_model->getInlinePaymentCcTypes());
68
+
69
+ $store->resetConfig();
70
+ }
71
+
72
+ public function testGetGenerateHashUrl()
73
+ {
74
+ $urlModel = $this->getModelMock('core/url', array('getUrl'));
75
+ $urlModel->expects($this->any())
76
+ ->method('getUrl')
77
+ ->with(
78
+ 'ops/payment/generatehash',
79
+ array('_secure' => false, '_nosid' => true)
80
+ );
81
+ $this->replaceByMock('model', 'core/url', $urlModel);
82
+ $this->_model->getGenerateHashUrl();
83
+
84
+ $urlModel = $this->getModelMock('core/url', array('getUrl'));
85
+ $urlModel->expects($this->any())
86
+ ->method('getUrl')
87
+ ->with(
88
+ 'ops/payment/generatehash',
89
+ array('_secure' => false, '_nosid' => true, '_store' => 1)
90
+ );
91
+ $this->replaceByMock('model', 'core/url', $urlModel);
92
+ $this->_model->getGenerateHashUrl(1);
93
+ }
94
+
95
+ public function testGetAliasAcceptUrl()
96
+ {
97
+ $urlModel = $this->getModelMock('core/url', array('getUrl'));
98
+ $urlModel->expects($this->any())
99
+ ->method('getUrl')
100
+ ->with(
101
+ 'ops/payment/acceptAlias',
102
+ array('_secure' => false, '_nosid' => true)
103
+ );
104
+ $this->replaceByMock('model', 'core/url', $urlModel);
105
+ $this->_model->getAliasAcceptUrl();
106
+
107
+ $urlModel = $this->getModelMock('core/url', array('getUrl'));
108
+ $urlModel->expects($this->any())
109
+ ->method('getUrl')
110
+ ->with(
111
+ 'ops/payment/acceptAlias',
112
+ array('_secure' => false, '_nosid' => true, '_store' => 1)
113
+ );
114
+ $this->replaceByMock('model', 'core/url', $urlModel);
115
+ $this->_model->getAliasAcceptUrl(1);
116
+ }
117
+
118
+ public function testGetAliasExceptionUrl()
119
+ {
120
+ $urlModel = $this->getModelMock('core/url', array('getUrl'));
121
+ $urlModel->expects($this->any())
122
+ ->method('getUrl')
123
+ ->with(
124
+ 'ops/payment/exceptionAlias',
125
+ array('_secure' => false, '_nosid' => true)
126
+ );
127
+ $this->replaceByMock('model', 'core/url', $urlModel);
128
+ $this->_model->getAliasExceptionUrl();
129
+
130
+ $urlModel = $this->getModelMock('core/url', array('getUrl'));
131
+ $urlModel->expects($this->any())
132
+ ->method('getUrl')
133
+ ->with(
134
+ 'ops/payment/exceptionAlias',
135
+ array('_secure' => false, '_nosid' => true, '_store' => 1)
136
+ );
137
+ $this->replaceByMock('model', 'core/url', $urlModel);
138
+ $this->_model->getAliasExceptionUrl(1);
139
+ }
140
+
141
+ public function testGetCcSaveAliasUrl()
142
+ {
143
+ $urlModel = $this->getModelMock('core/url', array('getUrl'));
144
+ $urlModel->expects($this->any())
145
+ ->method('getUrl')
146
+ ->with('ops/payment/saveAlias', array('_secure' => false));
147
+ $this->replaceByMock('model', 'core/url', $urlModel);
148
+ $this->_model->getCcSaveAliasUrl();
149
+
150
+ $urlModel = $this->getModelMock('core/url', array('getUrl'));
151
+ $urlModel->expects($this->any())
152
+ ->method('getUrl')
153
+ ->with(
154
+ 'ops/payment/saveAlias',
155
+ array('_secure' => false, '_store' => 1)
156
+ );
157
+ $this->replaceByMock('model', 'core/url', $urlModel);
158
+ $this->_model->getCcSaveAliasUrl(1);
159
+ }
160
+
161
+ public function testIsAliasInfoBlockEnabled()
162
+ {
163
+ $path = 'payment/ops_cc/show_alias_manager_info_for_guests';
164
+ $store = Mage::app()->getStore(0)->load(0);
165
+ $store->resetConfig();
166
+ $store->setConfig($path, 0);
167
+ $this->assertFalse($this->_model->isAliasInfoBlockEnabled());
168
+
169
+ $store->resetConfig();
170
+ $store->setConfig($path, 1);
171
+ $this->assertTrue($this->_model->isAliasInfoBlockEnabled());
172
+ }
173
+
174
+
175
+ public function testObserveCreditMemoCreation()
176
+ {
177
+ $this->assertEventObserverDefined(
178
+ 'adminhtml',
179
+ 'core_block_abstract_to_html_after',
180
+ 'ops/observer',
181
+ 'showWarningForClosedTransactions'
182
+ );
183
+ }
184
+
185
+ public function testAppendCheckboxToRefundForm()
186
+ {
187
+ $this->assertEventObserverDefined(
188
+ 'adminhtml',
189
+ 'core_block_abstract_to_html_after',
190
+ 'ops/observer',
191
+ 'appendCheckBoxToRefundForm'
192
+ );
193
+ }
194
+
195
+ public function testGetOrderReference()
196
+ {
197
+ $store = Mage::app()->getStore(0)->load(0);
198
+ $this->assertEquals(
199
+ Netresearch_OPS_Model_Payment_Abstract::REFERENCE_ORDER_ID,
200
+ $this->_model->getOrderReference()
201
+ );
202
+
203
+ $store->setConfig(
204
+ 'payment_services/ops/redirectOrderReference',
205
+ Netresearch_OPS_Model_Payment_Abstract::REFERENCE_QUOTE_ID
206
+ );
207
+ $this->assertEquals(
208
+ Netresearch_OPS_Model_Payment_Abstract::REFERENCE_QUOTE_ID,
209
+ $this->_model->getOrderReference()
210
+ );
211
+ }
212
+
213
+ public function testGetShowQuoteIdInOrderGrid()
214
+ {
215
+ $store = Mage::app()->getStore(0)->load(0);
216
+ $this->assertEquals(1, $this->_model->getShowQuoteIdInOrderGrid());
217
+
218
+ $store->setConfig('payment_services/ops/showQuoteIdInOrderGrid', 0);
219
+ $this->assertEquals(0, $this->_model->getShowQuoteIdInOrderGrid());
220
+ }
221
+
222
+
223
+ public function testIsTrackingCodeActivated()
224
+ {
225
+ $store = Mage::app()->getStore(0)->load(0);
226
+ $this->assertFalse($this->_model->isTrackingCodeActivated());
227
+
228
+ $store->setConfig('payment_services/ops/enableTrackingCode', 1);
229
+ $this->assertTrue($this->_model->isTrackingCodeActivated());
230
+ }
231
+
232
+
233
+ public function testIsAliasManagerEnabled()
234
+ {
235
+ $path = 'payment/ops_cc/active_alias';
236
+ $store = Mage::app()->getStore(0)->load(0);
237
+ $store->resetConfig();
238
+ $store->setConfig($path, 0);
239
+ $this->assertFalse($this->_model->isAliasManagerEnabled());
240
+
241
+ $store->resetConfig();
242
+ $store->setConfig($path, 1);
243
+ $this->assertTrue($this->_model->isAliasManagerEnabled());
244
+
245
+ }
246
+
247
+
248
+ public function testGetAcceptRedirectLocation()
249
+ {
250
+ $this->assertEquals(
251
+ Netresearch_OPS_Model_Config::OPS_CONTROLLER_ROUTE_PAYMENT
252
+ . 'accept',
253
+ $this->_model->getAcceptRedirectRoute()
254
+ );
255
+ }
256
+
257
+ public function testGetCancelRedirectLocation()
258
+ {
259
+ $this->assertEquals(
260
+ Netresearch_OPS_Model_Config::OPS_CONTROLLER_ROUTE_PAYMENT
261
+ . 'cancel',
262
+ $this->_model->getCancelRedirectRoute()
263
+ );
264
+ }
265
+
266
+ public function testGetDeclineRedirectLocation()
267
+ {
268
+ $this->assertEquals(
269
+ Netresearch_OPS_Model_Config::OPS_CONTROLLER_ROUTE_PAYMENT
270
+ . 'decline',
271
+ $this->_model->getDeclineRedirectRoute()
272
+ );
273
+ }
274
+
275
+ public function testGetExceptionRedirectLocation()
276
+ {
277
+ $this->assertEquals(
278
+ Netresearch_OPS_Model_Config::OPS_CONTROLLER_ROUTE_PAYMENT
279
+ . 'exception',
280
+ $this->_model->getExceptionRedirectRoute()
281
+ );
282
+ }
283
+
284
+ /**
285
+ * asserts that the event for clearing old data for the payment methods is set up properly
286
+ */
287
+ public function testClearMethodBeforeImportEventExists()
288
+ {
289
+ $this->assertEventObserverDefined(
290
+ 'global',
291
+ 'sales_quote_payment_import_data_before',
292
+ 'ops/observer',
293
+ 'clearPaymentMethodFromQuote'
294
+ );
295
+ }
296
+
297
+
298
+ /**
299
+ * asserts that the event for clearing old data for the payment methods is set up properly
300
+ */
301
+ public function testSalesOrderPaymentCapture()
302
+ {
303
+ $this->assertEventObserverDefined(
304
+ 'adminhtml',
305
+ 'sales_order_payment_capture',
306
+ 'ops/observer',
307
+ 'salesOrderPaymentCapture'
308
+ );
309
+ }
310
+
311
+ public function testGetMethodsRequiringAdditionalParametersFor()
312
+ {
313
+ $capturePms = Mage::getModel('ops/config')->getMethodsRequiringAdditionalParametersFor('capture');
314
+ $this->assertTrue(is_array($capturePms));
315
+ $this->assertTrue(0 < count($capturePms));
316
+ $this->assertTrue(array_key_exists('OpenInvoiceNl', $capturePms));
317
+ $this->assertTrue(array_key_exists('OpenInvoiceNl', $capturePms));
318
+ $this->assertEquals('Netresearch_OPS_Model_Payment_OpenInvoiceNl', $capturePms['OpenInvoiceNl']);
319
+ }
320
+
321
+ public function testDisableCaptureForZeroAmountInvoiceEventExists()
322
+ {
323
+ $this->assertEventObserverDefined(
324
+ 'adminhtml',
325
+ 'core_block_abstract_prepare_layout_before',
326
+ 'ops/observer',
327
+ 'disableCaptureForZeroAmountInvoice'
328
+ );
329
+ }
330
+
331
+ public function testGetIdealIssuers()
332
+ {
333
+ $issuers = $this->_model->getIDealIssuers();
334
+ $this->assertTrue(is_array($issuers));
335
+ $this->assertTrue(array_key_exists('ABNANL2A', $issuers));
336
+ $this->assertEquals('ABN AMRO', $issuers['ABNANL2A']);
337
+
338
+ $this->assertTrue(array_key_exists('RABONL2U', $issuers));
339
+ $this->assertEquals('Rabobank', $issuers['RABONL2U']);
340
+
341
+ $this->assertTrue(array_key_exists('INGBNL2A', $issuers));
342
+ $this->assertEquals('ING', $issuers['INGBNL2A']);
343
+
344
+ $this->assertTrue(array_key_exists('SNSBNL2A', $issuers));
345
+ $this->assertEquals('SNS Bank', $issuers['SNSBNL2A']);
346
+
347
+ $this->assertTrue(array_key_exists('RBRBNL21', $issuers));
348
+ $this->assertEquals('Regio Bank', $issuers['RBRBNL21']);
349
+
350
+ $this->assertTrue(array_key_exists('ASNBNL21', $issuers));
351
+ $this->assertEquals('ASN Bank', $issuers['ASNBNL21']);
352
+
353
+ $this->assertTrue(array_key_exists('TRIONL2U', $issuers));
354
+ $this->assertEquals('Triodos Bank', $issuers['TRIONL2U']);
355
+
356
+ $this->assertTrue(array_key_exists('FVLBNL22', $issuers));
357
+ $this->assertEquals('Van Lanschot Bankiers', $issuers['FVLBNL22']);
358
+
359
+ $this->assertTrue(array_key_exists('KNABNL2H', $issuers));
360
+ $this->assertEquals('Knab Bank', $issuers['KNABNL2H']);
361
+ }
362
+
363
+ public function testAddCcPaymentMethodEventExists()
364
+ {
365
+ $this->assertEventObserverDefined(
366
+ 'global',
367
+ 'core_block_abstract_prepare_layout_before',
368
+ 'ops/observer',
369
+ 'addCcPaymentMethod'
370
+ );
371
+ }
372
+
373
+
374
+ public function testCanSubmitExtraParameters()
375
+ {
376
+ $this->assertTrue($this->_model->canSubmitExtraParameter());
377
+ $path = 'payment_services/ops/submitExtraParameters';
378
+ $store = Mage::app()->getStore(0)->load(0);
379
+ $store->resetConfig();
380
+ $store->setConfig($path, 0);
381
+ $this->assertFalse($this->_model->isAliasManagerEnabled());
382
+ }
383
+
384
+
385
+ public function testGetParameterLengths()
386
+ {
387
+ $fieldLengths = $this->_model->getParameterLengths();
388
+ $this->assertEquals($this->validFieldLengths(), $fieldLengths);
389
+ }
390
+
391
+
392
+ protected function validFieldLengths()
393
+ {
394
+ return array(
395
+ 'ECOM_SHIPTO_POSTAL_NAME_FIRST' => 50,
396
+ 'ECOM_SHIPTO_POSTAL_NAME_LAST' => 50,
397
+ 'ECOM_SHIPTO_POSTAL_STREET_LINE1' => 35,
398
+ 'ECOM_SHIPTO_POSTAL_STREET_LINE2' => 35,
399
+ 'ECOM_SHIPTO_POSTAL_STREET_LINE3' => 35,
400
+ 'ECOM_SHIPTO_POSTAL_COUNTRYCODE' => 2,
401
+ 'ECOM_SHIPTO_POSTAL_COUNTY' => 25,
402
+ 'ECOM_SHIPTO_POSTAL_POSTALCODE' => 10,
403
+ 'ECOM_SHIPTO_POSTAL_CITY' => 25,
404
+ 'ECOM_SHIPTO_POSTAL_STREET_NUMBER' => 10,
405
+ 'CN' => 35,
406
+ 'OWNERZIP' => 10,
407
+ 'OWNERCTY' => 2,
408
+ 'OWNERTOWN' => 40,
409
+ 'OWNERTELNO' => 30,
410
+ 'OWNERADDRESS' => 35,
411
+ 'ECOM_BILLTO_POSTAL_POSTALCODE' => 10,
412
+ );
413
+
414
+ }
415
+
416
+ public function testCheckForOpsStatusEventExists()
417
+ {
418
+ $this->assertEventObserverDefined(
419
+ 'global',
420
+ 'sales_order_save_before',
421
+ 'ops/observer',
422
+ 'checkForOpsStatus'
423
+ );
424
+ }
425
+
426
+ public function testGetInlineOrderReference()
427
+ {
428
+ $store = Mage::app()->getStore(0)->load(0);
429
+ $this->assertEquals(
430
+ Netresearch_OPS_Model_Payment_Abstract::REFERENCE_ORDER_ID,
431
+ $this->_model->getInlineOrderReference()
432
+ );
433
+
434
+ $store->setConfig(
435
+ 'payment_services/ops/inlineOrderReference',
436
+ Netresearch_OPS_Model_Payment_Abstract::REFERENCE_QUOTE_ID
437
+ );
438
+ $this->assertEquals(
439
+ Netresearch_OPS_Model_Payment_Abstract::REFERENCE_QUOTE_ID,
440
+ $this->_model->getInlineOrderReference()
441
+ );
442
+ }
443
+
444
+ public function testSetOrderStateForDirectDebitsNlExists()
445
+ {
446
+ $this->assertEventObserverDefined(
447
+ 'global',
448
+ 'sales_order_payment_place_end',
449
+ 'ops/observer',
450
+ 'setOrderStateForDirectDebitsNl'
451
+ );
452
+ }
453
+
454
+ public function testGetFrontendGatewayPath()
455
+ {
456
+ $this->setMode(Netresearch_OPS_Model_Source_Mode::CUSTOM);
457
+ $expectedResult = Mage::getStoreConfig('payment_services/ops/frontend_gateway');
458
+ $this->assertEquals($expectedResult, $this->_model->getFrontendGatewayPath(0));
459
+ $this->setMode(Netresearch_OPS_Model_Source_Mode::TEST);
460
+ $this->assertContains('test', $this->_model->getFrontendGatewayPath(0));
461
+ }
462
+
463
+ public function testGetDirectLinkGatewayPath()
464
+ {
465
+ $this->setMode(Netresearch_OPS_Model_Source_Mode::CUSTOM);
466
+ $expectedResult = Mage::getStoreConfig('payment_services/ops/directlink_gateway');
467
+ $this->assertEquals($expectedResult, $this->_model->getDirectLinkGatewayPath(0));
468
+ $this->setMode(Netresearch_OPS_Model_Source_Mode::TEST);
469
+ $this->assertContains('test', $this->_model->getDirectLinkGatewayPath(0));
470
+ }
471
+
472
+ public function testGetDirectLinkGatewayOrderPath()
473
+ {
474
+ $this->setMode(Netresearch_OPS_Model_Source_Mode::CUSTOM);
475
+ $expectedResult = Mage::getStoreConfig('payment_services/ops/directlink_gateway_order');
476
+ $this->assertEquals($expectedResult, $this->_model->getDirectLinkGatewayOrderPath(0));
477
+ $this->setMode(Netresearch_OPS_Model_Source_Mode::TEST);
478
+ $this->assertContains('test', $this->_model->getDirectLinkGatewayOrderPath(0));
479
+ }
480
+
481
+ public function testGetAliasGatewayUrl()
482
+ {
483
+ $this->setMode(Netresearch_OPS_Model_Source_Mode::CUSTOM);
484
+ $expectedResult = Mage::getStoreConfig('payment_services/ops/ops_alias_gateway');
485
+ $this->assertEquals($expectedResult, $this->_model->getAliasGatewayUrl(0));
486
+ $this->setMode(Netresearch_OPS_Model_Source_Mode::TEST);
487
+ $this->assertContains('test', $this->_model->getAliasGatewayUrl(0));
488
+ }
489
+
490
+ public function testGetDirectLinkMaintenanceApiPath()
491
+ {
492
+ $this->setMode(Netresearch_OPS_Model_Source_Mode::CUSTOM);
493
+ $expectedResult = Mage::getStoreConfig('payment_services/ops/directlink_maintenance_api');
494
+ $this->assertEquals($expectedResult, $this->_model->getDirectLinkMaintenanceApiPath(0));
495
+ $this->setMode(Netresearch_OPS_Model_Source_Mode::TEST);
496
+ $this->assertContains('test', $this->_model->getDirectLinkMaintenanceApiPath(0));
497
+ }
498
+
499
+ public function testGetMode()
500
+ {
501
+ $this->setMode(Netresearch_OPS_Model_Source_Mode::CUSTOM);
502
+ $this->assertEquals($this->_model->getMode(0), Netresearch_OPS_Model_Source_Mode::CUSTOM);
503
+ }
504
+
505
+ protected function setMode($mode, $storeId = 0)
506
+ {
507
+ Mage::app()->getStore($storeId)->setConfig(Netresearch_OPS_Model_Config::OPS_PAYMENT_PATH . 'mode', $mode);
508
+ }
509
+
510
+ public function testGetResendPaymentInfoTemplate()
511
+ {
512
+ $config = Mage::getModel('ops/config');
513
+ $this->assertEquals($config->getResendPaymentInfoTemplate(), 'payment_services_ops_resendPaymentInfo_template');
514
+ }
515
+
516
+ public function testGetResendPaymentInfoIdentity()
517
+ {
518
+ $config = Mage::getModel('ops/config');
519
+ $this->assertEquals($config->getResendPaymentInfoIdentity(), 'sales');
520
+ }
521
+ }
522
+
app/code/community/Netresearch/OPS/Test/Model/File/Download.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Netresearch_OPS_Test_Model_File_Download extends EcomDev_PHPUnit_Test_Case
4
+ {
5
+ protected $testFile;
6
+ public function setUp()
7
+ {
8
+ $this->testFile = Mage::helper('ops/data')->getLogPath();
9
+ if(!file_exists($this->testFile)){
10
+ $file = fopen($this->testFile,'c');
11
+ fclose($file);
12
+ }
13
+
14
+ }
15
+ /**
16
+ * @expectedException Exception
17
+ */
18
+ public function testFailingGetFile()
19
+ {
20
+ $model = Mage::getModel('ops/file_download');
21
+ $path = 'abc';
22
+ $model->getFile($path);
23
+ }
24
+
25
+ public function testSuccessGetFile(){
26
+ $model = Mage::getModel('ops/file_download');
27
+ if(filesize($this->testFile) > $model::ONE_MEGABYTE){
28
+ $this->assertEquals(0, strpos(basename($model->getFile($this->testFile)),'tempFile'));
29
+ }else{
30
+ $this->assertEquals($model->getFile($this->testFile), $this->testFile);
31
+ }
32
+
33
+ }
34
+
35
+ }
36
+
app/code/community/Netresearch/OPS/Test/Model/Kwixo/Category/MappingTest.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Netresearch_OPS_Test_Model_Kwixo_Category_MappingTest
4
+ extends EcomDev_PHPUnit_Test_Case
5
+ {
6
+ /**
7
+ * @loadFixture category_mapping
8
+ */
9
+ public function testLoadByCategoryId()
10
+ {
11
+ $this->assertEquals(
12
+ 10,
13
+ Mage::getModel('ops/kwixo_category_mapping')->loadByCategoryId(10)
14
+ ->getKwixoCategoryId()
15
+ );
16
+ $this->assertEquals(
17
+ 1,
18
+ Mage::getModel('ops/kwixo_category_mapping')->loadByCategoryId(11)
19
+ ->getKwixoCategoryId()
20
+ );
21
+ $this->assertEquals(
22
+ null,
23
+ Mage::getModel('ops/kwixo_category_mapping')->loadByCategoryId(12)
24
+ ->getKwixoCategoryId()
25
+ );
26
+ }
27
+
28
+ }
app/code/community/Netresearch/OPS/Test/Model/Kwixo/Category/MappingTest/fixtures/category_mapping.yaml ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ tables:
2
+ ops/kwixo_category_mapping:
3
+ - id: 1
4
+ kwixo_category_id: 10
5
+ category_id: 10
6
+ - id: 2
7
+ kwixo_category_id: 1
8
+ category_id: 11
9
+ - id: 3
10
+ kwixo_category_id: 2
11
+ category_id: 11
app/code/community/Netresearch/OPS/Test/Model/Mysql4/Alias/AliasTest.php ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Netresearch_OPS_Test_Model_Mysql4_Alias_CollectionTest extends EcomDev_PHPUnit_Test_Case
3
+ {
4
+ public function testType()
5
+ {
6
+ $this->assertTypeOf('Netresearch_OPS_Model_Mysql4_Alias_Collection', Mage::getModel('ops/mysql4_alias')->getCollection());
7
+ }
8
+ }
app/code/community/Netresearch/OPS/Test/Model/Mysql4/AliasTest.php ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Netresearch_OPS_Test_Model_Mysql4_AliasTest extends EcomDev_PHPUnit_Test_Case
3
+ {
4
+ public function testType()
5
+ {
6
+ $this->assertInstanceOf(
7
+ 'Netresearch_OPS_Model_Mysql4_Alias',
8
+ Mage::getModel('ops/mysql4_alias')
9
+ );
10
+ }
11
+ }
app/code/community/Netresearch/OPS/Test/Model/ObserverTest.php ADDED
@@ -0,0 +1,915 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Netresearch_OPS_Test_Model_ObserverTest extends EcomDev_PHPUnit_Test_Case_Controller
4
+ {
5
+ private $_model;
6
+
7
+ public function setUp()
8
+ {
9
+ parent::setup();
10
+ $this->_model = Mage::getModel('ops/observer');
11
+ }
12
+
13
+ public function testType()
14
+ {
15
+ $this->assertInstanceOf('Netresearch_OPS_Model_Observer', $this->_model);
16
+ }
17
+
18
+ public function testPerformDirectLinkRequestWithUnknownResponse()
19
+ {
20
+ $quote = $this->getModelMock('sales/quote', array('save'));
21
+ $aliasHelperMock = $this->getHelperMock('ops/alias', array('setAliasActive'));
22
+ $this->replaceByMock('helper', 'ops/alias', $aliasHelperMock);
23
+ $payment = $this->getModelMock('sales/quote_payment', array('save'));
24
+ $payment->expects($this->any())
25
+ ->method('save')
26
+ ->will($this->returnValue(null));
27
+ $this->replaceByMock('model', 'sales/quote_payment', $payment);
28
+ $quote->setPayment($payment);
29
+ $response = null;
30
+ $directLinkMock = $this->getModelMock('ops/api_directlink', array('performRequest'));
31
+ $directLinkMock->expects($this->any())
32
+ ->method('performRequest')
33
+ ->will($this->returnValue($response));
34
+ $this->replaceByMock('model', 'ops/api_directlink', $directLinkMock);
35
+ $observer = Mage::getModel('ops/observer');
36
+ $observer->performDirectLinkRequest($quote, array());
37
+ $this->assertFalse($this->setExpectedException('PHPUnit_Framework_ExpectationFailedException'));
38
+ $this->assertTrue(array_key_exists('ops_response', $quote->getPayment()->getAdditionalInformation()));
39
+ }
40
+
41
+ public function testPerformDirectLinkRequestWithInvalidResponse()
42
+ {
43
+ $quote = new Varien_Object();
44
+ $aliasHelperMock = $this->getHelperMock('ops/alias', array('setAliasActive'));
45
+ $this->replaceByMock('helper', 'ops/alias', $aliasHelperMock);
46
+ $payment = $this->getModelMock('sales/quote_payment', array('save'));
47
+ $payment->expects($this->any())
48
+ ->method('save')
49
+ ->will($this->returnValue(null));
50
+ $this->replaceByMock('model', 'sales/quote_payment', $payment);
51
+ $quote->setPayment($payment);
52
+ $response = '';
53
+ $directLinkMock = $this->getModelMock('ops/api_directlink', array('performRequest'));
54
+ $directLinkMock->expects($this->any())
55
+ ->method('performRequest')
56
+ ->will($this->returnValue($response));
57
+ $this->replaceByMock('model', 'ops/api_directlink', $directLinkMock);
58
+ $observer = Mage::getModel('ops/observer');
59
+ $this->assertTrue($this->setExpectedException('PHPUnit_Framework_ExpectationFailedException'));
60
+ $observer->performDirectLinkRequest($quote, array());
61
+ $this->assertFalse(array_key_exists('ops_response', $quote->getPayment()->getAdditionalInformation()));
62
+ }
63
+
64
+ public function testPerformDirectLinkRequestWithValidResponse()
65
+ {
66
+ $quote = new Varien_Object();
67
+ $aliasHelperMock = $this->getHelperMock('ops/alias', array('setAliasActive'));
68
+ $this->replaceByMock('helper', 'ops/alias', $aliasHelperMock);
69
+ $payment = $this->getModelMock('sales/quote_payment', array('save'));
70
+ $payment->expects($this->any())
71
+ ->method('save')
72
+ ->will($this->returnValue(null));
73
+ $this->replaceByMock('model', 'sales/quote_payment', $payment);
74
+ $quote->setPayment($payment);
75
+ $response = array('STATUS' => Netresearch_OPS_Model_Payment_Abstract::OPS_AUTHORIZED);
76
+ $directLinkMock = $this->getModelMock('ops/api_directlink', array('performRequest'));
77
+ $directLinkMock->expects($this->any())
78
+ ->method('performRequest')
79
+ ->will($this->returnValue($response));
80
+ $this->replaceByMock('model', 'ops/api_directlink', $directLinkMock);
81
+ $observer = Mage::getModel('ops/observer');
82
+ $this->assertFalse($this->setExpectedException('PHPUnit_Framework_ExpectationFailedException'));
83
+ $observer->performDirectLinkRequest($quote, array());
84
+ $this->assertTrue(array_key_exists('ops_response', $quote->getPayment()->getAdditionalInformation()));
85
+ }
86
+
87
+ public function testPerformDirectLinkRequestWithValidResponseButInvalidStatus()
88
+ {
89
+ $quote = new Varien_Object();
90
+ $aliasHelperMock = $this->getHelperMock('ops/alias', array('setAliasActive'));
91
+ $this->replaceByMock('helper', 'ops/alias', $aliasHelperMock);
92
+ $payment = $this->getModelMock('sales/quote_payment', array('save'));
93
+ $payment->expects($this->any())
94
+ ->method('save')
95
+ ->will($this->returnValue(null));
96
+ $this->replaceByMock('model', 'sales/quote_payment', $payment);
97
+ $quote->setPayment($payment);
98
+ $response = array('STATUS' => Netresearch_OPS_Model_Payment_Abstract::OPS_AUTH_REFUSED);
99
+ $directLinkMock = $this->getModelMock('ops/api_directlink', array('performRequest'));
100
+ $directLinkMock->expects($this->any())
101
+ ->method('performRequest')
102
+ ->will($this->returnValue($response));
103
+ $this->replaceByMock('model', 'ops/api_directlink', $directLinkMock);
104
+ $observer = Mage::getModel('ops/observer');
105
+ $this->assertTrue($this->setExpectedException('PHPUnit_Framework_ExpectationFailedException'));
106
+ $observer->performDirectLinkRequest($quote, array());
107
+ $this->assertFalse(array_key_exists('ops_response', $quote->getPayment()->getAdditionalInformation()));
108
+ }
109
+
110
+ public function testAppendCheckBoxToRefundForm()
111
+ {
112
+ $sessionMock = $this->getModelMock('core/session', array('init', 'save'));
113
+ $this->replaceByMock('model', 'core/session', $sessionMock);
114
+
115
+ Mage::register('current_creditmemo', null, true);
116
+ $transport = new Varien_Object();
117
+ $transport->setHtml('Foo');
118
+ $observer = Mage::getModel('ops/observer');
119
+ $event = new Varien_Object();
120
+ $event->setBlock('');
121
+ $this->assertEquals('', $observer->appendCheckBoxToRefundForm($event));
122
+
123
+ $order = new Varien_Object();
124
+ $payment = new Varien_Object();
125
+ $methodInstance = Mage::getModel('ops/payment_cc');
126
+ $payment->setMethodInstance($methodInstance);
127
+ $order->setPayment($payment);
128
+ $invoice = new Varien_Object();
129
+ $invoice->setTransactionId(1);
130
+ $creditMemo = $this->getModelMock('sales/order_creditmemo', array('getOrder', 'getInvoice', 'canRefund', 'getOrderId'));
131
+ $creditMemo->expects($this->any())
132
+ ->method('getOrder')
133
+ ->will($this->returnValue($order));
134
+ $creditMemo->expects($this->any())
135
+ ->method('getInvoice')
136
+ ->will($this->returnValue($invoice));
137
+ $creditMemo->expects($this->any())
138
+ ->method('canRefund')
139
+ ->will($this->returnValue(true));
140
+ $creditMemo->expects($this->any())
141
+ ->method('getOrderId')
142
+ ->will($this->returnValue(1));
143
+ Mage::register('current_creditmemo', $creditMemo, true);
144
+ $block = Mage::app()->getLayout()->getBlockSingleton('adminhtml/sales_order_creditmemo_totals');
145
+ $parentBlock = Mage::app()->getLayout()->getBlockSingleton('adminhtml/sales_order_creditmemo_create_items');
146
+ $block->setParentBlock($parentBlock);
147
+
148
+ $blockMock = $this->getBlockMock('ops/adminhtml_sales_order_creditmemo_totals_checkbox', array('renderView'));
149
+ $blockMock->expects($this->once())
150
+ ->method('renderView')
151
+ ->will($this->returnValue('<b>checkbox</b>'));
152
+ $this->replaceByMock('block', 'ops/adminhtml_sales_order_creditmemo_totals_checkbox', $blockMock);
153
+ $event->setBlock($block);
154
+ $event->setTransport($transport);
155
+ $html = $observer->appendCheckBoxToRefundForm($event);
156
+ $this->assertEquals('Foo<b>checkbox</b>', $html);
157
+ $this->assertNotEquals('Bar<span>checkbox</span>', $html);
158
+
159
+ Mage::unregister('current_creditmemo');
160
+ }
161
+
162
+ public function testShowWarningForClosedTransactions()
163
+ {
164
+ Mage::register('current_creditmemo', null);
165
+ $transport = new Varien_Object();
166
+ $transport->setHtml('Foo');
167
+ $observer = Mage::getModel('ops/observer');
168
+ $event = new Varien_Object();
169
+ $event->setBlock('');
170
+ $this->assertEquals('', $observer->showWarningForClosedTransactions($event));
171
+
172
+ $order = new Varien_Object();
173
+ $payment = new Varien_Object();
174
+ $methodInstance = Mage::getModel('ops/payment_cc');
175
+ $payment->setMethodInstance($methodInstance);
176
+ $order->setPayment($payment);
177
+ $invoice = new Varien_Object();
178
+ $invoice->setTransactionId(1);
179
+ $creditMemo = $this->getModelMock('sales/order_creditmemo', array('getOrder', 'getInvoice', 'canRefund', 'getOrderId'));
180
+ $creditMemo->expects($this->any())
181
+ ->method('getOrder')
182
+ ->will($this->returnValue($order));
183
+ $creditMemo->expects($this->any())
184
+ ->method('getInvoice')
185
+ ->will($this->returnValue($invoice));
186
+ $creditMemo->expects($this->any())
187
+ ->method('canRefund')
188
+ ->will($this->returnValue(false));
189
+ $creditMemo->expects($this->any())
190
+ ->method('getOrderId')
191
+ ->will($this->returnValue(1));
192
+ Mage::register('current_creditmemo', $creditMemo);
193
+ $block = Mage::app()->getLayout()->getBlockSingleton('adminhtml/sales_order_creditmemo_create');
194
+
195
+ $blockMock = $this->getBlockMock('ops/adminhtml_sales_order_creditmemo_closedTransaction_warning', array('renderView'));
196
+ $blockMock->expects($this->once())
197
+ ->method('renderView')
198
+ ->will($this->returnValue('<b>warning</b>'));
199
+ $this->replaceByMock('block', 'ops/adminhtml_sales_order_creditmemo_closedTransaction_warning', $blockMock);
200
+ $event->setBlock($block);
201
+ $event->setTransport($transport);
202
+ $html = $observer->showWarningForClosedTransactions($event);
203
+ $this->assertEquals('<b>warning</b>Foo', $html);
204
+ $this->assertNotEquals('Bar<span>warning</span>', $html);
205
+
206
+ Mage::unregister('current_creditmemo');
207
+ }
208
+
209
+ /**
210
+ * @loadFixture ../../../var/fixtures/orders.yaml
211
+ */
212
+ public function testConfirmAliasPayment()
213
+ {
214
+ $quote = Mage::getModel('sales/quote')->load(23);
215
+ $order = Mage::getModel('sales/order')->load(11);
216
+ $payment = $quote->getPayment();
217
+ // $payment->expects($this->any())
218
+ // ->method('getMethodInstance')
219
+ // ->will($this->returnValue(Mage::getModel('ops/payment_cc')));
220
+ $payment->setAdditionalInformation(array('cvc' => '123', 'alias' => '99'));
221
+ $payment->setMethod('ops_cc');
222
+ $quote->setPayment($payment);
223
+ $requestParams = $this->getRequestParamsWithAlias($quote, $order);
224
+
225
+ $helperMock = $this->getHelperMock('ops/data', array('isAdminSession'));
226
+ $helperMock->expects($this->any())
227
+ ->method('isAdminSession')
228
+ ->will($this->returnValue(true));
229
+ $this->replaceByMock('helper', 'ops/data', $helperMock);
230
+
231
+ $quoteHelperMock = $this->getHelperMock('ops/quote', array('getQuoteCurrency'));
232
+ $quoteHelperMock->expects($this->any())
233
+ ->method('getQuoteCurrency')
234
+ ->will($this->returnValue('USD'));
235
+ $this->replaceByMock('helper', 'ops/quote', $quoteHelperMock);
236
+
237
+ $observerMock = $this->getModelMock('ops/observer', array('performDirectLinkRequest', 'invokeRequestParamValidation'));
238
+ $observerMock->expects($this->any())
239
+ ->method('performDirectLinkRequest')
240
+ ->with($quote, $requestParams, 1)
241
+ ->will($this->returnValue('WuselDusel'));
242
+
243
+ $orderHelperMock = $this->getHelperMock('ops/order', array('checkIfAddressesAreSame'));
244
+ $orderHelperMock->expects($this->any())
245
+ ->method('checkIfAddressesAreSame')
246
+ ->will($this->returnValue(1));
247
+ $this->replaceByMock('helper', 'ops/order', $orderHelperMock);
248
+
249
+ $customerSessionMock = $this->getModelMock('customer/session', array('isLoggedIn'));
250
+ $customerSessionMock->expects($this->any())
251
+ ->method('isLoggedIn')
252
+ ->will($this->returnValue(1));
253
+ $this->replaceByMock('model', 'customer/session', $customerSessionMock);
254
+
255
+ $configModelMock = $this->getModelMock('ops/config', array(
256
+ 'get3dSecureIsActive',
257
+ 'getAcceptUrl',
258
+ 'getDeclineUrl',
259
+ 'getExceptionUrl'
260
+ )
261
+ );
262
+
263
+ $configModelMock->expects($this->any())
264
+ ->method('get3dSecureIsActive')
265
+ ->will($this->returnValue(true));
266
+ $configModelMock->expects($this->any())
267
+ ->method('getAcceptUrl')
268
+ ->will($this->returnValue('www.abc.com'));
269
+ $configModelMock->expects($this->any())
270
+ ->method('getDeclineUrl')
271
+ ->will($this->returnValue('www.abcd.com'));
272
+ $configModelMock->expects($this->any())
273
+ ->method('getExceptionUrl')
274
+ ->will($this->returnValue('www.abcde.com'));
275
+ $this->replaceByMock('model', 'ops/config', $configModelMock);
276
+
277
+ $aliashelperMock = $this->getHelperMock('ops/alias', array('getAlias', 'cleanUpAdditionalInformation'));
278
+ $aliashelperMock->expects($this->any())
279
+ ->method('getAlias')
280
+ ->with($quote)
281
+ ->will($this->returnValue('99'));
282
+ $this->replaceByMock('helper', 'ops/alias', $aliashelperMock);
283
+ $this->assertEquals('WuselDusel', $observerMock->confirmAliasPayment($order, $quote));
284
+
285
+ $helperMock = $this->getHelperMock('ops/data', array('isAdminSession'));
286
+ $helperMock->expects($this->any())
287
+ ->method('isAdminSession')
288
+ ->will($this->returnValue(true));
289
+ $this->replaceByMock('helper', 'ops/data', $helperMock);
290
+
291
+ $observerMock = $this->getModelMock('ops/observer', array('performDirectLinkRequest', 'invokeRequestParamValidation'));
292
+
293
+ $requestParams = $this->getRequestParamsWithoutAlias($quote, $order);
294
+ $observerMock->expects($this->any())
295
+ ->method('performDirectLinkRequest')
296
+ ->with($quote, $requestParams, 1)
297
+ ->will($this->returnValue('wrong'));
298
+ $this->assertEquals('wrong', $observerMock->confirmAliasPayment($order, $quote));
299
+
300
+
301
+ $observerMock = $this->getModelMock('ops/observer', array('performDirectLinkRequest'));
302
+ $validatorMock = $this->getModelMock('ops/validator_parameter_validator', array('isValid'));
303
+ $validatorMock->expects($this->once())
304
+ ->method('isValid')
305
+ ->will($this->returnValue(false));
306
+ $validatorFactoryMock = $this->getModelMock('ops/validator_parameter_factory', array('getValidatorFor'));
307
+ $validatorFactoryMock->expects($this->once())
308
+ ->method('getValidatorFor')
309
+ ->will($this->returnValue($validatorMock));
310
+ $this->replaceByMock('model', 'ops/validator_parameter_factory', $validatorFactoryMock);
311
+ try {
312
+ $observerMock->confirmAliasPayment($order, $quote);
313
+ } catch (Exception $e) {
314
+ $this->assertTrue($e instanceof Mage_Core_Exception);
315
+ }
316
+ }
317
+
318
+
319
+ private function getRequestParamsWithAlias($quote, $order)
320
+ {
321
+ return array(
322
+ 'ALIAS' => '99',
323
+ 'AMOUNT' => 0.0,
324
+ 'CURRENCY' => 'USD',
325
+ 'OPERATION' => 'RES',
326
+ 'ORDERID' => Mage::getSingleton('ops/config')->getConfigData('devprefix') . $order->getQuoteId(),
327
+ 'EMAIL' => 'hubertus.von.fuerstenberg@trash-mail.com',
328
+ 'OWNERADDRESS' => utf8_decode('An der Tabaksmühle 3a'),
329
+ 'OWNERZIP' => '04229',
330
+ 'OWNERTELNO' => null,
331
+ 'OWNERCTY' => 'DE',
332
+ 'ADDMATCH' => 1,
333
+ 'ECOM_SHIPTO_POSTAL_POSTALCODE' => '04229',
334
+ 'ECOM_BILLTO_POSTAL_POSTALCODE' => '04229',
335
+ 'CVC' => '123',
336
+ 'REMOTE_ADDR' => 'NONE',
337
+ 'CUID' => null,
338
+ 'ECI' => Netresearch_OPS_Model_Eci_Values::MANUALLY_KEYED_FROM_MOTO,
339
+ 'OWNERTOWN' => 'Leipzig',
340
+ 'ORIG' => Mage::helper('ops/data')->getModuleVersionString(),
341
+ 'ECOM_SHIPTO_POSTAL_NAME_FIRST' => 'Hubertus',
342
+ 'ECOM_SHIPTO_POSTAL_NAME_LAST' => utf8_decode('Fürstenberg'),
343
+ 'ECOM_SHIPTO_POSTAL_STREET_LINE1' => utf8_decode('An der Tabaksmühle 3a'),
344
+ 'ECOM_SHIPTO_POSTAL_STREET_LINE2' => '',
345
+ 'ECOM_SHIPTO_POSTAL_COUNTRYCODE' => 'DE',
346
+ 'ECOM_SHIPTO_POSTAL_CITY' => 'Leipzig',
347
+ 'ECOM_SHIPTO_POSTAL_STATE' => '',
348
+ );
349
+ }
350
+
351
+ private function getRequestParamsWithoutAlias($quote, $order)
352
+ {
353
+ return array(
354
+ 'ALIAS' => '99',
355
+ 'AMOUNT' => 0.0,
356
+ 'CURRENCY' => 'USD',
357
+ 'OPERATION' => 'RES',
358
+ 'ORDERID' => Mage::getSingleton('ops/config')->getConfigData('devprefix') . $order->getQuoteId(),
359
+ 'EMAIL' => 'hubertus.von.fuerstenberg@trash-mail.com',
360
+ 'OWNERADDRESS' => utf8_decode('An der Tabaksmühle 3a'),
361
+ 'OWNERZIP' => '04229',
362
+ 'OWNERTELNO' => null,
363
+ 'OWNERCTY' => 'DE',
364
+ 'ADDMATCH' => 1,
365
+ 'ECOM_SHIPTO_POSTAL_POSTALCODE' => '04229',
366
+ 'ECOM_BILLTO_POSTAL_POSTALCODE' => '04229',
367
+ 'CVC' => '123',
368
+ 'REMOTE_ADDR' => 'NONE',
369
+ 'OWNERTOWN' => 'Leipzig',
370
+ 'ORIG' => Mage::helper('ops/data')->getModuleVersionString(),
371
+ 'ECOM_SHIPTO_POSTAL_NAME_FIRST' => 'Hubertus',
372
+ 'ECOM_SHIPTO_POSTAL_NAME_LAST' => utf8_decode('Fürstenberg'),
373
+ 'ECOM_SHIPTO_POSTAL_STREET_LINE1' => utf8_decode('An der Tabaksmühle 3a'),
374
+ 'ECOM_SHIPTO_POSTAL_STREET_LINE2' => '',
375
+ 'ECOM_SHIPTO_POSTAL_COUNTRYCODE' => 'DE',
376
+ 'ECOM_SHIPTO_POSTAL_CITY' => 'Leipzig',
377
+ 'ECI' => 1,
378
+ 'CUID' => null,
379
+ 'ECOM_SHIPTO_POSTAL_STATE' => '',
380
+ );
381
+ }
382
+
383
+ /**
384
+ * @loadFixture ../../../var/fixtures/orders.yaml
385
+ */
386
+ public function testConfirmDdPayment()
387
+ {
388
+ $quote = Mage::getModel('sales/quote')->load(10);
389
+ $order = Mage::getModel('sales/order')->load(11);
390
+
391
+ $observerMock = $this->getModelMock('ops/observer', array('performDirectLinkRequest', 'invokeRequestParamValidation'));
392
+
393
+ $requestParams = array(
394
+ 'AMOUNT' => 0.0,
395
+ 'CARDNO' => '12335BLZ12345566',
396
+ 'CN' => utf8_decode('Hubertus zu Fürstenberg'),
397
+ 'CURRENCY' => 'USD',
398
+ 'ED' => '9999',
399
+ 'OPERATION' => 'RES',
400
+ 'ORDERID' => Mage::getSingleton('ops/config')->getConfigData('devprefix') . $quote->getId(),
401
+ 'PM' => 'Direct Debits DE',
402
+ 'OWNERADDRESS' => utf8_decode('An der Tabaksmühle 3a'),
403
+ 'OWNERZIP' => '04229',
404
+ 'OWNERTELNO' => null,
405
+ 'OWNERCTY' => 'DE',
406
+ 'ADDMATCH' => 1,
407
+ 'ECOM_SHIPTO_POSTAL_POSTALCODE' => '04229',
408
+ 'ECOM_BILLTO_POSTAL_POSTALCODE' => '04229',
409
+ 'CUID' => null,
410
+ 'BRAND' => 'Direct Debits DE',
411
+ 'ECI' => Netresearch_OPS_Model_Eci_Values::MANUALLY_KEYED_FROM_MOTO,
412
+ 'OWNERTOWN' => 'Leipzig',
413
+ );
414
+
415
+ $directDebitHelperMock = $this->getHelperMock('ops/directDebit', array('getDirectLinkRequestParams'));
416
+ $directDebitHelperMock->expects($this->any())
417
+ ->method('getDirectLinkRequestParams')
418
+ ->will($this->returnValue($requestParams));
419
+ $this->replaceByMock('helper', 'ops/directDebit', $directDebitHelperMock);
420
+
421
+ $observerMock->expects($this->any())
422
+ ->method('performDirectLinkRequest')
423
+ ->with($quote, $requestParams, 1)
424
+ ->will($this->returnValue('MOTO'));
425
+ $this->assertEquals('MOTO', $observerMock->confirmDdPayment($order, $quote));
426
+ }
427
+
428
+ /**
429
+ * @loadFixture ../../../var/fixtures/orders.yaml
430
+ */
431
+ public function testConfirmDdPaymentWithNoECI()
432
+ {
433
+ $quote = Mage::getModel('sales/quote')->load(10);
434
+ $order = Mage::getModel('sales/order')->load(11);
435
+
436
+
437
+
438
+ $observerMock = $this->getModelMock('ops/observer', array('performDirectLinkRequest', 'invokeRequestParamValidation'));
439
+
440
+
441
+ $requestParams = array(
442
+ 'AMOUNT' => 0.0,
443
+ 'CARDNO' => '12335BLZ12345566',
444
+ 'CN' => utf8_decode('Hubertus zu Fürstenberg'),
445
+ 'CURRENCY' => 'USD',
446
+ 'ED' => '9999',
447
+ 'OPERATION' => 'RES',
448
+ 'ORDERID' => Mage::getSingleton('ops/config')->getConfigData('devprefix') . $quote->getId(),
449
+ 'PM' => 'Direct Debits DE',
450
+ 'OWNERADDRESS' => utf8_decode('An der Tabaksmühle 3a'),
451
+ 'OWNERZIP' => '04229',
452
+ 'OWNERTELNO' => null,
453
+ 'OWNERCTY' => 'DE',
454
+ 'ADDMATCH' => 1,
455
+ 'ECOM_SHIPTO_POSTAL_POSTALCODE' => '04229',
456
+ 'ECOM_BILLTO_POSTAL_POSTALCODE' => '04229',
457
+ 'CUID' => null,
458
+ 'OWNERTOWN' => 'Leipzig',
459
+ 'BRAND' => 'Direct Debits DE'
460
+ );
461
+
462
+ $directDebitHelperMock = $this->getHelperMock('ops/directDebit', array('getDirectLinkRequestParams'));
463
+ $directDebitHelperMock->expects($this->any())
464
+ ->method('getDirectLinkRequestParams')
465
+ ->will($this->returnValue($requestParams));
466
+ $this->replaceByMock('helper', 'ops/directDebit', $directDebitHelperMock);
467
+
468
+
469
+ $observerMock->expects($this->any())
470
+ ->method('performDirectLinkRequest')
471
+ ->with($quote, $requestParams, 1)
472
+ ->will($this->returnValue('ECOM'));
473
+
474
+ $this->assertEquals('ECOM', $observerMock->confirmDdPayment($order, $quote));
475
+ }
476
+
477
+ /**
478
+ * tests that the payment method is cleared before importing new data
479
+ * following conditions must be met in order to get the method gets cleared:
480
+ * 1. event must be sales_quote_payment_import_data_before
481
+ * 2. payment must be an instance of Mage_Sales_Quote_Payment
482
+ *
483
+ */
484
+ public function testClearPaymentMethodFromQuote()
485
+ {
486
+ $observer = Mage::getModel('ops/observer');
487
+ $event = new Varien_Event_Observer();
488
+ $payment = Mage::getModel('sales/quote_payment');
489
+ $payment->setMethod('not relevant');
490
+ $eventData = new Varien_Event();
491
+ $event->setEvent($eventData);
492
+ $event->getEvent()->setData('payment', $payment);
493
+
494
+ // method is not cleared because of wring event
495
+ $observer->clearPaymentMethodFromQuote($event);
496
+ $this->assertEquals('not relevant', $event->getEvent()->getPayment()->getMethod());
497
+
498
+ // method is cleared
499
+ $event->setEventName('sales_quote_payment_import_data_before');
500
+ $observer->clearPaymentMethodFromQuote($event);
501
+ $this->assertEquals(null, $event->getEvent()->getPayment()->getMethod());
502
+
503
+ // method is not cleared because the payment is not a Mage_Sales_Quote_Payment
504
+ $payment = new Varien_Object();
505
+ $payment->setMethod('not relevant');
506
+ $event->getEvent()->setData('payment', $payment);
507
+ $observer->clearPaymentMethodFromQuote($event);
508
+ $this->assertEquals('not relevant', $event->getEvent()->getPayment()->getMethod());
509
+ }
510
+
511
+ /**
512
+ * @loadFixture ../../../var/fixtures/orders.yaml
513
+ */
514
+ public function testaddStatusUpdateButtonToOrderView()
515
+ {
516
+ $adminSessionMock = $this->getModelMock('admin/session', array('isAllowed', 'init', 'save'));
517
+ $adminSessionMock->expects($this->any())
518
+ ->method('isAllowed')
519
+ ->will($this->returnValue(true));
520
+ $this->replaceByMock('model', 'admin/session', $adminSessionMock);
521
+
522
+ $order = Mage::getModel('sales/order')->load(11);
523
+ Mage::register('sales_order', $order);
524
+ $block = Mage::app()->getLayout()->getBlockSingleton('adminhtml/sales_order_view');
525
+ $event = new Varien_Event_Observer();
526
+ $event->setBlock($block);
527
+ $observer = Mage::getModel('ops/observer');
528
+ $observer->addStatusUpdateButtonToOrderView($event);
529
+ $buttons = $block->getButtonsHtml();
530
+ $this->assertContains(Mage::helper('ops/data')->__('Refresh payment status'), $buttons);
531
+ $this->assertContains('setLocation(\'' . $block->getUrl('adminhtml/opsstatus/update') . '\')', $buttons);
532
+ Mage::unregister('sales_order');
533
+ }
534
+
535
+ /**
536
+ * @loadFixture ../../../var/fixtures/orders.yaml
537
+ */
538
+ public function testAddStatusUpdateButtonToOrderViewWillNotAddButton()
539
+ {
540
+ $adminSessionMock = $this->getModelMock('admin/session', array('isAllowed', 'init', 'save'));
541
+ $adminSessionMock->expects($this->any())
542
+ ->method('isAllowed')
543
+ ->will($this->returnValue(false));
544
+ $this->replaceByMock('model', 'admin/session', $adminSessionMock);
545
+
546
+ $order = Mage::getModel('sales/order')->load(11);
547
+ Mage::register('sales_order', $order);
548
+ $block = Mage::app()->getLayout()->getBlockSingleton('adminhtml/sales_order_view');
549
+ $event = new Varien_Event_Observer();
550
+ $event->setBlock($block);
551
+ $observer = Mage::getModel('ops/observer');
552
+ $observer->addStatusUpdateButtonToOrderView($event);
553
+ $buttons = $block->getButtonsHtml();
554
+ $this->assertNotContains(Mage::helper('ops/data')->__('Refresh payment status'), $buttons);
555
+ $this->assertNotContains('setLocation(\'' . $block->getUrl('adminhtml/opsstatus/update') . '\')', $buttons);
556
+ Mage::unregister('sales_order');
557
+
558
+ $adminSessionMock = $this->getModelMock('admin/session', array('isAllowed', 'init', 'save'));
559
+ $adminSessionMock->expects($this->any())
560
+ ->method('isAllowed')
561
+ ->will($this->returnValue(true));
562
+ $this->replaceByMock('model', 'admin/session', $adminSessionMock);
563
+
564
+ $order = Mage::getModel('sales/order')->load(30);
565
+ Mage::register('sales_order', $order);
566
+ $block = Mage::app()->getLayout()->getBlockSingleton('adminhtml/sales_order_view');
567
+ $event = new Varien_Event_Observer();
568
+ $event->setBlock($block);
569
+ $observer = Mage::getModel('ops/observer');
570
+ $observer->addStatusUpdateButtonToOrderView($event);
571
+ $buttons = $block->getButtonsHtml();
572
+ $this->assertNotContains(Mage::helper('ops/data')->__('Refresh payment status'), $buttons);
573
+ $this->assertNotContains('setLocation(\'' . $block->getUrl('adminhtml/opsstatus/update') . '\')', $buttons);
574
+ Mage::unregister('sales_order');
575
+ }
576
+
577
+ public function testAddCcPaymentMethod()
578
+ {
579
+ $observer = Mage::getModel('ops/observer');
580
+ $event = new Varien_Event_Observer();
581
+ $block = new Mage_Payment_Block_Form_Container();
582
+ $quote = Mage::getModel('sales/quote');
583
+ $block->setQuote($quote);
584
+ $eventData = new Varien_Event();
585
+ $event->setEvent($eventData);
586
+ $event->getEvent()->setData('block', $block);
587
+
588
+ $versionHelperMock = $this->getHelperMock('ops/version', array('canUseApplicableForQuote'));
589
+ $versionHelperMock->expects($this->any())
590
+ ->method('canUseApplicableForQuote')
591
+ ->will($this->returnvalue(false));
592
+ $this->replaceByMock('helper', 'ops/version', $versionHelperMock);
593
+
594
+ $paymentHelperMock = $this->getHelperMock('ops/payment', array('addCCForZeroAmountCheckout'));
595
+ $paymentHelperMock->expects($this->once())
596
+ ->method('addCCForZeroAmountCheckout')
597
+ ->will($this->returnValue($paymentHelperMock));
598
+ $this->replaceByMock('helper', 'ops/payment', $paymentHelperMock);
599
+
600
+ $observer->addCcPaymentMethod($event);
601
+ }
602
+
603
+ public function testDisableCaptureForZeroAmountInvoice()
604
+ {
605
+ $ccPaymentObject = Mage::getModel('ops/payment_cc');
606
+ $block = new Mage_Adminhtml_Block_Sales_Order_Invoice_Create_Items();
607
+ $payment = Mage::getModel('sales/order_payment');
608
+ $payment->setMethodInstance($ccPaymentObject);
609
+ $order = Mage::getModel('sales/order');
610
+ $order->setPayment($payment);
611
+ $invoice = Mage::getModel('sales/order_invoice');
612
+ $invoice->setBaseGrandTotal(0.00);
613
+ $invoice->setOrder($order);
614
+ $observer = Mage::getModel('ops/observer');
615
+ $event = new Varien_Event_Observer();
616
+ Mage::register('current_invoice',$invoice,true);
617
+ $eventData = new Varien_Event();
618
+ $event->setEvent($eventData);
619
+ $event->getEvent()->setData('block', $block);
620
+
621
+ $this->assertTrue($ccPaymentObject->canCapture());
622
+ $observer->disableCaptureForZeroAmountInvoice($event);
623
+ $this->assertFalse($ccPaymentObject->canCapture());
624
+
625
+ // clean up invoice from registry after test
626
+ Mage::unregister('current_invoice');
627
+ }
628
+
629
+ /**
630
+ * @loadFixture ../../../var/fixtures/orders.yaml
631
+ */
632
+ public function testCheckoutTypeOnepageSaveOrderBefore()
633
+ {
634
+ $event = new Varien_Event_Observer();
635
+ $order = Mage::getModel('sales/order')->load(11);
636
+ $quotePayment = Mage::getModel('sales/quote_payment')->load(4);
637
+ $pmMock = $this->getModelMock('ops/payment_bankTransfer', array('getFormFields'));
638
+ $quotePayment->setMethodInstance($pmMock);
639
+ $quote = $this->getModelMock('sales/quote', array('getPayment'));
640
+ $quote->expects($this->any())
641
+ ->method('getPayment')
642
+ ->will($this->returnValue($quotePayment));
643
+
644
+ $quotePayment->setQuote($quote);
645
+ $quote->setPayment($quotePayment);
646
+ $this->replaceByMock('model', 'ops/payment_bankTransfer', $pmMock);
647
+ $event->setOrder($order);
648
+ $event->setQuote($quote);
649
+ $observerMock = $this->getModelMock('ops/observer', array('invokeRequestParamValidation'));
650
+ $observerMock->expects($this->once())
651
+ ->method('invokeRequestParamValidation');
652
+ $observerMock->checkoutTypeOnepageSaveOrderBefore($event);
653
+ }
654
+
655
+ /**
656
+ * @loadFixture ../../../var/fixtures/orders.yaml
657
+ */
658
+ public function testControllerActionCheckoutOnepagePostdispatch()
659
+ {
660
+ $fakeController = new Varien_Object();
661
+ $fakeResponse = new Varien_Object();
662
+ $quotePayment = Mage::getModel('sales/quote_payment')->load(4);
663
+ $pmMock = $this->getModelMock('ops/payment_bankTransfer', array('isAvailable'));
664
+ $pmMock->expects($this->any())
665
+ ->method('isAvailable')
666
+ ->will($this->returnValue(true));
667
+ $quote = $this->getModelMock('sales/quote', array('getPayment'));
668
+ $quote->expects($this->any())
669
+ ->method('getPayment')
670
+ ->will($this->returnValue($quotePayment));
671
+ $quotePayment->setQuote($quote);
672
+ $quote->setPayment($quotePayment);
673
+ $this->replaceByMock('model', 'ops/payment_bankTransfer', $pmMock);
674
+
675
+
676
+ $fakeOnePage = new Varien_Object();
677
+ $fakeOnePage->setQuote($quote);
678
+
679
+ $observerMock = $this->getModelMock('ops/observer', array('getOnepage'));
680
+ $observerMock->expects($this->once())
681
+ ->method('getOnepage')
682
+ ->will($this->returnValue($fakeOnePage))
683
+ ;
684
+ $helperMock = $this->getHelperMock('ops/payment_request', array('getOwnerParams', 'extractShipToParameters'));
685
+ $helperMock->expects($this->once())
686
+ ->method('getOwnerParams')
687
+ ->will($this->returnValue(array()));
688
+ $helperMock->expects($this->once())
689
+ ->method('extractShipToParameters')
690
+ ->will($this->returnValue(array()));
691
+ $this->replaceByMock('helper', 'ops/payment_request', $helperMock);
692
+ $validatorMock = $this->getModelMock('ops/validator_parameter_validator', array('isValid', 'getMessages'));
693
+ $validatorMock->expects($this->once())
694
+ ->method('isValid')
695
+ ->will($this->returnValue(false));
696
+ $validatorMock->expects($this->any())
697
+ ->method('getMessages')
698
+ ->will($this->returnValue(array('Foo' => 'Not Valid')));
699
+ $this->replaceByMock('model', 'ops/validator_parameter_validator', $validatorMock);
700
+ $fakeResponse->setBody(Mage::helper('core/data')->jsonEncode(array('error' => false, 'update_section' => 'foo')));
701
+ $fakeController->setResponse($fakeResponse);
702
+ $event = new Varien_Event_Observer();
703
+ $event->setControllerAction($fakeController);
704
+ $observerMock->controllerActionCheckoutOnepagePostdispatch($event);
705
+ $result = Mage::helper('core/data')->jsonDecode($fakeResponse->getBody());
706
+ $this->assertArrayHasKey('error', $result);
707
+ $this->assertArrayHasKey('goto_section', $result);
708
+ $this->assertArrayHasKey('fields', $result);
709
+ $this->assertArrayNotHasKey('update_section', $result);
710
+ }
711
+
712
+ public function testCheckForOpsStatus()
713
+ {
714
+ $helperMock = $this->getHelperMock('ops/data', array('isAdminSession'));
715
+ $helperMock->expects($this->any())
716
+ ->method('isAdminSession')
717
+ ->will($this->returnValue(true));
718
+ $this->replaceByMock('helper', 'ops/data', $helperMock);
719
+ $order = Mage::getModel('sales/order')->load(11);
720
+ $order->setStatus(Mage_Sales_Model_Order::STATE_PROCESSING);
721
+ $observer = new Varien_Event_Observer();
722
+ $observer->setOrder($order);
723
+ Mage::getModel('ops/observer')->checkForOpsStatus($observer);
724
+ $this->assertEquals(Mage_Sales_Model_Order::STATE_PROCESSING, $order->getStatus());
725
+ }
726
+
727
+
728
+ public function testSalesOrderPaymentCapture()
729
+ {
730
+ $opsObserver = Mage::getModel('ops/observer');
731
+ $event = new Varien_Event_Observer();
732
+ $fakePayment = Mage::getModel('sales/order_payment');
733
+ $fakePayment->setMethod('checkmo');
734
+ $invoice = Mage::getModel('sales/order_invoice');
735
+ $event->setPayment($fakePayment);
736
+ $event->setInvoice($invoice);
737
+ $opsObserver->salesOrderPaymentCapture($event);
738
+ $this->assertNull($fakePayment->getInvoice());
739
+
740
+ $fakePayment = Mage::getModel('sales/order_payment');
741
+ $fakePayment->setMethod('ops_cc');
742
+ $event->setPayment($fakePayment);
743
+ $event->setInvoice($invoice);
744
+ $opsObserver->salesOrderPaymentCapture($event);
745
+ $this->assertEquals($invoice, $fakePayment->getInvoice());
746
+
747
+ }
748
+
749
+ public function testShowWarningForOpenInvoicePayments()
750
+ {
751
+ $transport = new Varien_Object();
752
+ $transport->setHtml('Foo');
753
+ $observer = Mage::getModel('ops/observer');
754
+ $event = new Varien_Event_Observer();
755
+ $event->setBlock('');
756
+ $observer->appendPartialCaptureWarningForOpenInvoice($event);
757
+ $this->assertEquals('Foo', $transport->getHtml());
758
+
759
+ $order = new Varien_Object();
760
+ $payment = new Varien_Object();
761
+ $methodInstance = Mage::getModel('ops/payment_openInvoiceNl');
762
+ $payment->setMethodInstance($methodInstance);
763
+ $order->setPayment($payment);
764
+
765
+ $invoice = $this->getModelMock('sales/order_invoice', array('getOrder'));
766
+ $invoice->expects($this->any())
767
+ ->method('getOrder')
768
+ ->will($this->returnValue($order));
769
+
770
+ Mage::register('current_invoice', $invoice);
771
+ $block = Mage::app()->getLayout()->getBlockSingleton('adminhtml/sales_order_invoice_totals');
772
+
773
+ $blockMock = $this->getBlockMock('ops/adminhtml_sales_order_invoice_warning_openInvoice', array('renderView'));
774
+ $blockMock->expects($this->once())
775
+ ->method('renderView')
776
+ ->will($this->returnValue('<b>warning</b>'));
777
+ $this->replaceByMock('block', 'ops/adminhtml_sales_order_invoice_warning_openInvoice', $blockMock);
778
+ $event->setBlock($block);
779
+ $event->setTransport($transport);
780
+ $observer->appendPartialCaptureWarningForOpenInvoice($event);
781
+ $this->assertEquals('Foo<b>warning</b>', $transport->getHtml());
782
+ $this->assertNotEquals('Bar<span>warning</span>', $transport->getHtml());
783
+
784
+ Mage::unregister('current_invoice');
785
+ }
786
+
787
+ public function testSetOrderStateForDirectDebitsNlDoesNotChangeState()
788
+ {
789
+ $order = $this->getOrderForDirectDebitNlTest();
790
+ $event = $this->getEventForDirectDebitNlTests($order, 'payment/method_cc');
791
+ $observer = Mage::getModel('ops/observer');
792
+ $observer->setOrderStateForDirectDebitsNl($event);
793
+ $this->assertEquals(Mage_sales_Model_Order::STATE_PROCESSING, $order->getStatus());
794
+ $this->assertEquals(Mage_sales_Model_Order::STATE_PROCESSING, $order->getState());
795
+ }
796
+
797
+
798
+ public function testSetOrderStateForDirectDebitsNlDoesNotChangeStateDueToHelper()
799
+ {
800
+ $order = $this->getOrderForDirectDebitNlTest();
801
+ $event = $this->getEventForDirectDebitNlTests($order, 'ops/payment_directDebit');
802
+ $this->registerPaymentHelperMockForDirectDebitNlTests(false);
803
+ $observer = Mage::getModel('ops/observer');
804
+ $observer->setOrderStateForDirectDebitsNl($event);
805
+ $this->assertEquals(Mage_sales_Model_Order::STATE_PROCESSING, $order->getStatus());
806
+ $this->assertEquals(Mage_sales_Model_Order::STATE_PROCESSING, $order->getState());
807
+ }
808
+
809
+ public function testSetOrderStateForDirectDebitsNlDoesNotChangeStateDueToMissingInfos()
810
+ {
811
+ $order = $this->getOrderForDirectDebitNlTest();
812
+ $event = $this->getEventForDirectDebitNlTests($order, 'ops/payment_directDebit');
813
+ $this->registerPaymentHelperMockForDirectDebitNlTests(true);
814
+ $observer = Mage::getModel('ops/observer');
815
+ $observer->setOrderStateForDirectDebitsNl($event);
816
+ $this->assertEquals(Mage_sales_Model_Order::STATE_PROCESSING, $order->getStatus());
817
+ $this->assertEquals(Mage_sales_Model_Order::STATE_PROCESSING, $order->getState());
818
+ }
819
+
820
+ public function testSetOrderStateForDirectDebitsNlDoesNotChangeStateDueToMissingPm()
821
+ {
822
+ $order = $this->getOrderForDirectDebitNlTest();
823
+ $event = $this->getEventForDirectDebitNlTests($order, 'ops/payment_directDebit', array('STATUS' => 51));
824
+ $this->registerPaymentHelperMockForDirectDebitNlTests(true);
825
+ $observer = Mage::getModel('ops/observer');
826
+ $observer->setOrderStateForDirectDebitsNl($event);
827
+ $this->assertEquals(Mage_sales_Model_Order::STATE_PROCESSING, $order->getStatus());
828
+ $this->assertEquals(Mage_sales_Model_Order::STATE_PROCESSING, $order->getState());
829
+ }
830
+
831
+ public function testSetOrderStateForDirectDebitsNlDoesNotChangeStateDueToMissingStatus()
832
+ {
833
+ $order = $this->getOrderForDirectDebitNlTest();
834
+ $event = $this->getEventForDirectDebitNlTests($order, 'ops/payment_directDebit', array('PM' => 'Direct Debits NL'));
835
+ $this->registerPaymentHelperMockForDirectDebitNlTests(true);
836
+ $observer = Mage::getModel('ops/observer');
837
+ $observer->setOrderStateForDirectDebitsNl($event);
838
+ $this->assertEquals(Mage_sales_Model_Order::STATE_PROCESSING, $order->getStatus());
839
+ $this->assertEquals(Mage_sales_Model_Order::STATE_PROCESSING, $order->getState());
840
+ }
841
+
842
+ public function testSetOrderStateForDirectDebitsNlDoesNotChangeStateDueToWrongPm()
843
+ {
844
+ $order = $this->getOrderForDirectDebitNlTest();
845
+ $event = $this->getEventForDirectDebitNlTests($order, 'ops/payment_directDebit', array('PM' => 'Direct Debits DE', 'STATUS' => 51));
846
+ $this->registerPaymentHelperMockForDirectDebitNlTests(true);
847
+ $observer = Mage::getModel('ops/observer');
848
+ $observer->setOrderStateForDirectDebitsNl($event);
849
+ $this->assertEquals(Mage_sales_Model_Order::STATE_PROCESSING, $order->getStatus());
850
+ $this->assertEquals(Mage_sales_Model_Order::STATE_PROCESSING, $order->getState());
851
+ }
852
+
853
+ public function testSetOrderStateForDirectDebitsNlDoesNotChangeStateDueToWrongStatus()
854
+ {
855
+ $order = $this->getOrderForDirectDebitNlTest();
856
+ $event = $this->getEventForDirectDebitNlTests($order, 'ops/payment_directDebit', array('PM' => 'Direct Debits NL', 'STATUS' => 5));
857
+ $this->registerPaymentHelperMockForDirectDebitNlTests(true);
858
+ $observer = Mage::getModel('ops/observer');
859
+ $observer->setOrderStateForDirectDebitsNl($event);
860
+ $this->assertEquals(Mage_sales_Model_Order::STATE_PROCESSING, $order->getStatus());
861
+ $this->assertEquals(Mage_sales_Model_Order::STATE_PROCESSING, $order->getState());
862
+ }
863
+
864
+ public function testSetOrderStateForDirectDebitsNlDoesChangeState()
865
+ {
866
+ $order = $this->getOrderForDirectDebitNlTest();
867
+ $event = $this->getEventForDirectDebitNlTests($order, 'ops/payment_directDebit', array('PM' => 'Direct Debits NL', 'STATUS' => Netresearch_OPS_Model_Payment_Abstract::OPS_AUTHORIZED_WAITING));
868
+ $this->registerPaymentHelperMockForDirectDebitNlTests(true);
869
+ $observer = Mage::getModel('ops/observer');
870
+ $observer->setOrderStateForDirectDebitsNl($event);
871
+ $this->assertEquals(Mage_sales_Model_Order::STATE_PENDING_PAYMENT, $order->getStatus());
872
+ $this->assertEquals(Mage_sales_Model_Order::STATE_PENDING_PAYMENT, $order->getState());
873
+ }
874
+
875
+ /**
876
+ * @return array
877
+ */
878
+ protected function getEventForDirectDebitNlTests($order, $paymentMethod, array $addInfos = array())
879
+ {
880
+ $event = new Varien_Event_Observer();
881
+ $payment = $this->getModelMock('payment/info', array('getMethodInstance', 'getOrder'));
882
+ $payment->expects($this->any())
883
+ ->method('getMethodInstance')
884
+ ->will($this->returnValue(Mage::getModel($paymentMethod)));
885
+ $payment->expects($this->any())
886
+ ->method('getOrder')
887
+ ->will($this->returnValue($order));
888
+ $payment->setAdditionalInformation($addInfos);
889
+ $event->setPayment($payment);
890
+
891
+ return $event;
892
+ }
893
+
894
+ /**
895
+ * @return PHPUnit_Framework_MockObject_MockObject
896
+ */
897
+ protected function getOrderForDirectDebitNlTest()
898
+ {
899
+ $order = $this->getModelMock('sales/order', array('save',));
900
+ $order->setStatus(Mage_sales_Model_Order::STATE_PROCESSING);
901
+ $order->setState(Mage_sales_Model_Order::STATE_PROCESSING);
902
+
903
+ return $order;
904
+ }
905
+
906
+ protected function registerPaymentHelperMockForDirectDebitNlTests($isInlinePaymentWithOrderIdRetVal = true)
907
+ {
908
+ $paymentHelperMock = $this->getHelperMock('ops/payment', array('isInlinePaymentWithOrderId'));
909
+ $paymentHelperMock->expects($this->once())
910
+ ->method('isInlinePaymentWithOrderId')
911
+ ->will($this->returnValue($isInlinePaymentWithOrderIdRetVal));
912
+ $this->replaceByMock('helper', 'ops/payment', $paymentHelperMock);
913
+ }
914
+
915
+ }
app/code/community/Netresearch/OPS/Test/Model/ObserverTest/fixtures/.gitkeep ADDED
File without changes
app/code/community/Netresearch/OPS/Test/Model/Payment/AbstractCaptureTest.php ADDED
@@ -0,0 +1,274 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @author Michael Lühr <michael.luehr@netresearch.de>
5
+ * @category Netresearch
6
+ * @copyright Copyright (c) 2014 Netresearch GmbH & Co. KG (http://www.netresearch.de)
7
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
8
+ */
9
+ class Netresearch_OPS_Test_Model_Payment_AbstractCaptureTest
10
+ extends EcomDev_PHPUnit_Test_Case_Controller
11
+ {
12
+
13
+ protected $testObject = null;
14
+
15
+ /**
16
+ * set up a clean environment for the tests
17
+ */
18
+ public function setUp()
19
+ {
20
+ parent::setUp();
21
+ $this->testObject = Mage::getModel('ops/payment_abstract');
22
+ }
23
+
24
+ public function tearDown()
25
+ {
26
+ parent::tearDown();
27
+ Mage::unregister('ops_auto_capture');
28
+ }
29
+
30
+ public function testCaptureWithAutoCapture()
31
+ {
32
+ Mage::register('ops_auto_capture', true);
33
+ $payment = new Varien_Object();
34
+ $amount = null;
35
+ $this->testObject->capture($payment, $amount);
36
+ }
37
+
38
+ public function testCaptureWithPreviousCaptureRequestLeadToRedirect()
39
+ {
40
+ $testOrder = $this->getOrderMock();
41
+ $testPayment = $this->preparePayment($testOrder);
42
+ $amount = 1;
43
+ $captureHelperMock = $this->getHelperMock('ops/order_capture', array('prepareOperation'));
44
+ $this->replaceByMock('helper', 'ops/order_capture', $captureHelperMock);
45
+ $this->mockDirectlinkHelperCheckDirectLinkTransact(
46
+ $this->returnValue(true),
47
+ $this->equalTo(Netresearch_OPS_Model_Payment_Abstract::OPS_CAPTURE_TRANSACTION_TYPE),
48
+ $this->equalTo($testOrder->getId())
49
+ );
50
+
51
+ $message = Mage::helper('ops/data')->__(
52
+ 'You already sent a capture request. Please wait until the capture request is acknowledged.'
53
+ );
54
+ $this->mockDataHelperMockRedirectNoticed($testOrder->getId(), $message);
55
+
56
+ $this->testObject->capture($testPayment, $amount);
57
+ }
58
+
59
+ public function testCaptureWithPreviousVoidRequestLeadToRedirect()
60
+ {
61
+ $testOrder = $this->getOrderMock();
62
+ $testPayment = $this->preparePayment($testOrder);
63
+ $amount = 1;
64
+ $captureHelperMock = $this->getHelperMock('ops/order_capture', array('prepareOperation'));
65
+ $this->replaceByMock('helper', 'ops/order_capture', $captureHelperMock);
66
+ $this->mockDirectlinkHelperCheckDirectLinkTransact($this->onConsecutiveCalls(false, true));
67
+ $message = Mage::helper('ops/data')->__(
68
+ 'There is one void request waiting. Please wait until this request is acknowledged.'
69
+ );
70
+ $this->mockDataHelperMockRedirectNoticed($testOrder->getId(), $message);
71
+
72
+ $this->testObject->capture($testPayment, $amount);
73
+ }
74
+
75
+ public function testCaptureWillPerformRequest()
76
+ {
77
+ $testOrder = $this->getOrderMock();
78
+ $testPayment = $this->preparePayment($testOrder);
79
+ $testPayment->setAdditionalInformation('paymentId', 'payID');
80
+ $amount = 10;
81
+ $this->mockOrderCaptureHelper();
82
+ $requestParams = $this->getCaptureRequestParams($amount, $testPayment);
83
+ $testOpsResponse = $this->returnValue(
84
+ array('STATUS' => Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_PROCESSED_MERCHANT)
85
+ );
86
+ $this->mockApiDirectLink($requestParams, $testOpsResponse);
87
+ $paymentHelperMock = $this->getHelperMock('ops/payment', array('saveOpsStatusToPayment'));
88
+ $this->replaceByMock('helper', 'ops/payment', $paymentHelperMock);
89
+
90
+ $this->testObject->capture($testPayment, $amount);
91
+ }
92
+
93
+
94
+ public function testCaptureWillPerformRequestWithPaymentProcessing()
95
+ {
96
+ $testOrder = $this->getOrderMock();
97
+ $testPayment = $this->preparePayment($testOrder);
98
+ $amount = 10;
99
+ $this->mockDirectlinkHelperCheckDirectLinkTransact($this->returnValue(false));
100
+ $message = Mage::helper('ops/data')->__(
101
+ 'Invoice will be created automatically as soon as Ingenico Payment Services sends an acknowledgement. Ingenico Payment Services status: %s.',
102
+ Mage::helper('ops')->getStatusText(Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_PROCESSING)
103
+ );
104
+ $this->mockDataHelperMockRedirectNoticed($testOrder->getId(), $message);
105
+ $this->mockOrderCaptureHelper(array('operation' => 'SAS', 'type' => 'capture'));
106
+ $requestParams = $this->getCaptureRequestParams($amount, $testPayment);
107
+ $testOpsResponse = $this->returnValue(
108
+ array(
109
+ 'STATUS' => Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_PROCESSING,
110
+ 'PAYID' => 4711,
111
+ 'PAYIDSUB' => 1
112
+ )
113
+ );
114
+ $this->mockApiDirectLink($requestParams, $testOpsResponse);
115
+ $paymentHelperMock = $this->getHelperMock('ops/payment', array('saveOpsStatusToPayment'));
116
+ $this->replaceByMock('helper', 'ops/payment', $paymentHelperMock);
117
+
118
+ $this->testObject->capture($testPayment, $amount);
119
+ }
120
+
121
+ /**
122
+ * @expectedException Mage_Core_Exception
123
+ */
124
+ public function testCaptureWillPerformRequestWithInvalidResponseLeadToException()
125
+ {
126
+ $testOrder = $this->getOrderMock();
127
+ $testPayment = $this->preparePayment($testOrder);
128
+ $testPayment->setAdditionalInformation('paymentId', 'payID');
129
+ $amount = 10;
130
+ $this->mockOrderCaptureHelper();
131
+ $requestParams = $this->getCaptureRequestParams($amount, $testPayment);
132
+ $testOpsResponse = $this->returnValue(array('STATUS' => 0));
133
+ $this->mockApiDirectLink($requestParams, $testOpsResponse);
134
+ $paymentHelperMock = $this->getHelperMock('ops/payment', array('saveOpsStatusToPayment'));
135
+ $this->replaceByMock('helper', 'ops/payment', $paymentHelperMock);
136
+
137
+ $statusUpdateMock = $this->getModelMock('ops/status_update', array('updateStatusFor'));
138
+ $this->replaceByMock('model', 'ops/status_update', $statusUpdateMock);
139
+
140
+ $this->testObject->capture($testPayment, $amount);
141
+ }
142
+
143
+ /**
144
+ * @expectedException Mage_Core_Exception
145
+ */
146
+ public function testCaptureWillPerformRequestWithExceptionWillThrowException()
147
+ {
148
+ $testOrder = $this->getOrderMock();
149
+ $testPayment = $this->preparePayment($testOrder);
150
+ $amount = 10;
151
+ $this->mockOrderCaptureHelper();
152
+ $requestParams = $this->getCaptureRequestParams($amount, $testPayment);
153
+ $testOpsResponse = $this->throwException(new Exception('foo'));
154
+ $this->mockApiDirectLink($requestParams, $testOpsResponse);
155
+ $paymentHelperMock = $this->getHelperMock('ops/payment', array('saveOpsStatusToPayment'));
156
+ $this->replaceByMock('helper', 'ops/payment', $paymentHelperMock);
157
+ $statusUpdateMock = $this->getModelMock('ops/status_update', array('updateStatusFor'));
158
+ $this->replaceByMock('model', 'ops/status_update', $statusUpdateMock);
159
+
160
+
161
+ $this->testObject->capture($testPayment, $amount);
162
+ }
163
+
164
+ protected function mockOrderCaptureHelper($returnValue = array('operation' => 'SAS'))
165
+ {
166
+ $captureHelperMock = $this->getHelperMock('ops/order_capture', array('prepareOperation'));
167
+ $captureHelperMock->expects($this->once())
168
+ ->method('prepareOperation')
169
+ ->will($this->returnValue($returnValue));
170
+ $this->replaceByMock('helper', 'ops/order_capture', $captureHelperMock);
171
+ }
172
+
173
+ /**
174
+ * @param $firstArg
175
+ * @param $secondArg
176
+ */
177
+ protected function mockDataHelperMockRedirectNoticed($firstArg, $secondArg, $returnValue = true)
178
+ {
179
+ $dataHelperMock = $this->getHelperMock('ops/data', array('redirectNoticed'));
180
+ $dataHelperMock->expects($this->once())
181
+ ->method('redirectNoticed')
182
+ ->with($this->equalTo($firstArg), $this->equalTo($secondArg))
183
+ ->will($this->returnValue($returnValue));
184
+
185
+ $this->replaceByMock('helper', 'ops/data', $dataHelperMock);
186
+ }
187
+
188
+ /**
189
+ * @return array
190
+ */
191
+ protected function preparePayment($order)
192
+ {
193
+ $payment = Mage::getModel('sales/order_payment');
194
+ $payment->setOrder($order);
195
+ $payment->setAdditionalInformation('paymentId', 'payID');
196
+
197
+ return $payment;
198
+ }
199
+
200
+ /**
201
+ * @param $order
202
+ *
203
+ * @return PHPUnit_Framework_MockObject_MockObject
204
+ */
205
+ protected function getOrderMock()
206
+ {
207
+ $order = $this->getModelMock('sales/order', array('save', 'load', '_beforeSave'));
208
+ $order->expects($this->any())
209
+ ->method('load')
210
+ ->will($this->returnValue($order));
211
+ $order->setId(1);
212
+ $this->replaceByMock('model', 'sales/order', $order);
213
+
214
+ return $order;
215
+ }
216
+
217
+ /**
218
+ * @param $amount
219
+ * @param $testPayment
220
+ *
221
+ * @return array
222
+ */
223
+ protected function getCaptureRequestParams($amount, $testPayment)
224
+ {
225
+ $requestParams = array(
226
+ 'AMOUNT' => Mage::helper('ops/data')->getAmount($amount),
227
+ 'PAYID' => $testPayment->getAdditionalInformation('paymentId'),
228
+ 'OPERATION' => 'SAS',
229
+ 'CURRENCY' => Mage::app()->getStore()->getBaseCurrencyCode()
230
+ );
231
+
232
+ return $requestParams;
233
+ }
234
+
235
+ /**
236
+ * @param $requestParams
237
+ * @param $testOpsResponse
238
+ */
239
+ protected function mockApiDirectLink($requestParams, $testOpsResponse)
240
+ {
241
+ $apiDirectLinkMock = $this->getModelMock('ops/api_directlink', array('performRequest'));
242
+ $apiDirectLinkMock->expects($this->once())
243
+ ->method('performRequest')
244
+ ->with(
245
+ $this->equalTo($requestParams),
246
+ $this->equalTo(Mage::getModel('ops/config')->getDirectLinkGatewayPath()),
247
+ $this->equalTo(null)
248
+ )
249
+ ->will($testOpsResponse);
250
+ $this->replaceByMock('model', 'ops/api_directlink', $apiDirectLinkMock);
251
+ }
252
+
253
+ protected function mockDirectlinkHelperCheckDirectLinkTransact($will, $arg1 = null, $arg2 = null)
254
+ {
255
+
256
+ $helperMock = $this->getHelperMock('ops/directlink', array('checkExistingTransact', 'directLinkTransact'));
257
+ $helperMock->expects($this->any())
258
+ ->method('checkExistingTransact')
259
+ ->with($this->getConstraintForArg($arg1), $this->getConstraintForArg($arg2))
260
+ ->will($will);
261
+ $this->replaceByMock('helper', 'ops/directlink', $helperMock);
262
+ }
263
+
264
+ protected function getConstraintForArg($arg)
265
+ {
266
+ if (null === $arg) {
267
+ $arg = $this->anything();
268
+ }
269
+
270
+ return $arg;
271
+ }
272
+
273
+
274
+ }
app/code/community/Netresearch/OPS/Test/Model/Payment/AbstractRefundTest.php ADDED
@@ -0,0 +1,221 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ class Netresearch_OPS_Test_Model_Payment_AbstractRefundTest extends EcomDev_PHPUnit_Test_Case
5
+ {
6
+
7
+ protected $testObject = null;
8
+
9
+ /**
10
+ * Set up test enviroment
11
+ */
12
+ public function setUp()
13
+ {
14
+ parent::setUp();
15
+ $this->testObject = $this->getModelMock('ops/payment_abstract', array('canRefund'));
16
+ $this->testObject->expects($this->any())
17
+ ->method('canRefund')
18
+ ->will($this->returnValue(true));
19
+ $this->mockRefundHelper();
20
+ $this->mockDataHelper();
21
+ $this->mockPaymentHelper();
22
+ $sessionMock = $this->getModelMockBuilder('core/session')
23
+ ->disableOriginalConstructor()
24
+ ->setMethods(null)
25
+ ->getMock();
26
+ $this->replaceByMock('singleton', 'core/session', $sessionMock);
27
+ }
28
+
29
+ public function tearDown()
30
+ {
31
+ parent::tearDown();
32
+ Mage::unregister('ops_auto_creditmemo');
33
+ }
34
+
35
+ public function testRefundWithAutoCreditmemo()
36
+ {
37
+ Mage::register('ops_auto_creditmemo', true);
38
+ $payment = new Varien_Object();
39
+ $amount = null;
40
+ $this->testObject->refund($payment, $amount);
41
+ }
42
+
43
+ /**
44
+ *
45
+ */
46
+ public function testRefundWillPerformRequestWithRefundPending()
47
+ {
48
+ $testOrder = $this->getOrderMock();
49
+ $testPayment = $this->preparePayment($testOrder);
50
+ $testPayment->setAdditionalInformation('paymentId', 'payID');
51
+ $amount = 10;
52
+ $requestParams = $this->getRequestParams($amount, $testPayment);
53
+ $testOpsResponse = $this->returnValue(
54
+ array('STATUS' => Netresearch_OPS_Model_Payment_Abstract::OPS_REFUND_UNCERTAIN_STATUS)
55
+ );
56
+ $this->mockApiDirectLink($requestParams, $testOpsResponse);
57
+
58
+ $this->testObject->refund($testPayment, $amount);
59
+ }
60
+
61
+ /**
62
+ *
63
+ */
64
+ public function testRefundWillPerformRequestWithRefundProcessed()
65
+ {
66
+ $testOrder = $this->getOrderMock();
67
+ $testPayment = $this->preparePayment($testOrder);
68
+ $testPayment->setAdditionalInformation('paymentId', 'payID');
69
+ $amount = 10;
70
+ $requestParams = $this->getRequestParams($amount, $testPayment);
71
+ $testOpsResponse = $this->returnValue(
72
+ array('STATUS' => Netresearch_OPS_Model_Payment_Abstract::OPS_REFUND_PROCESSED_MERCHANT)
73
+ );
74
+ $this->mockApiDirectLink($requestParams, $testOpsResponse);
75
+
76
+ $this->testObject->refund($testPayment, $amount);
77
+
78
+ }
79
+
80
+ /**
81
+ * @expectedException Mage_Core_Exception
82
+ */
83
+ public function testRefundWillPerformRequestWithInvalidResponseLeadToException()
84
+ {
85
+ $testOrder = $this->getOrderMock();
86
+ $testPayment = $this->preparePayment($testOrder);
87
+ $testPayment->setAdditionalInformation('paymentId', 'payID');
88
+ $amount = 10;
89
+ $requestParams = $this->getRequestParams($amount, $testPayment);
90
+ $testOpsResponse = $this->returnValue(
91
+ array('STATUS' => Netresearch_OPS_Model_Payment_Abstract::OPS_PAYMENT_DELETED)
92
+ );
93
+ $this->mockApiDirectLink($requestParams, $testOpsResponse);
94
+
95
+ $statusUpdateMock = $this->getModelMock('ops/status_update', array('updateStatusFor'));
96
+ $this->replaceByMock('model', 'ops/status_update', $statusUpdateMock);
97
+
98
+ $this->testObject->refund($testPayment, $amount);
99
+ }
100
+
101
+ /**
102
+ * @expectedException Mage_Core_Exception
103
+ */
104
+ public function testCaptureWillPerformRequestWithExceptionWillThrowException()
105
+ {
106
+ $this->mockRefundHelper();
107
+ $testOrder = $this->getOrderMock();
108
+ $testPayment = $this->preparePayment($testOrder);
109
+ $testPayment->setAdditionalInformation('paymentId', 'payID');
110
+ $amount = 10;
111
+ $requestParams = $this->getRequestParams($amount, $testPayment);
112
+ $testOpsResponse = $this->throwException(new Exception('foo'));
113
+ $this->mockApiDirectLink($requestParams, $testOpsResponse);
114
+
115
+ $statusUpdateMock = $this->getModelMock('ops/status_update', array('updateStatusFor'));
116
+ $this->replaceByMock('model', 'ops/status_update', $statusUpdateMock);
117
+
118
+ $this->testObject->refund($testPayment, $amount);
119
+ }
120
+
121
+ /**
122
+ * @param $amount
123
+ * @param $testPayment
124
+ */
125
+ protected function getRequestParams($amount, $testPayment)
126
+ {
127
+ $requestParams = array(
128
+ 'AMOUNT' => Mage::helper('ops/data')->getAmount($amount),
129
+ 'PAYID' => $testPayment->getAdditionalInformation('paymentId'),
130
+ 'OPERATION' => Netresearch_OPS_Model_Payment_Abstract::OPS_REFUND_PARTIAL,
131
+ 'CURRENCY' => Mage::app()->getStore()->getBaseCurrencyCode()
132
+ );
133
+
134
+ return $requestParams;
135
+ }
136
+
137
+ /**
138
+ * @param $requestParams
139
+ * @param $testOpsResponse
140
+ */
141
+ protected function mockApiDirectLink($requestParams, $testOpsResponse)
142
+ {
143
+ $apiDirectLinkMock = $this->getModelMock('ops/api_directlink', array('performRequest'));
144
+ $apiDirectLinkMock->expects($this->once())
145
+ ->method('performRequest')
146
+ ->with(
147
+ $this->equalTo($requestParams),
148
+ $this->equalTo(Mage::getModel('ops/config')->getDirectLinkGatewayPath()),
149
+ $this->equalTo(null)
150
+ )
151
+ ->will($testOpsResponse);
152
+ $this->replaceByMock('model', 'ops/api_directlink', $apiDirectLinkMock);
153
+ }
154
+
155
+ /**
156
+ * @return array
157
+ */
158
+ protected function preparePayment($order)
159
+ {
160
+ $payment = Mage::getModel('sales/order_payment');
161
+ $payment->setOrder($order);
162
+ $payment->setAdditionalInformation('paymentId', 'payID');
163
+
164
+ return $payment;
165
+ }
166
+
167
+ /**
168
+ * @param $order
169
+ *
170
+ * @return PHPUnit_Framework_MockObject_MockObject
171
+ */
172
+ protected function getOrderMock()
173
+ {
174
+ $order = $this->getModelMock('sales/order', array('save', 'load', '_beforeSave'));
175
+ $order->expects($this->any())
176
+ ->method('load')
177
+ ->will($this->returnValue($order));
178
+ $order->setId(1);
179
+ $this->replaceByMock('model', 'sales/order', $order);
180
+
181
+ return $order;
182
+ }
183
+
184
+ protected function mockRefundHelper()
185
+ {
186
+ $helperMock = $this->getHelperMock('ops/order_refund', array('getCreditMemoRequestParams', 'createRefundTransaction'));
187
+ $params = array(
188
+ 'creditmemo' => array(
189
+ 'items' => array(
190
+ 1 => array(
191
+ 'qty' => 0
192
+ ),
193
+ 2 => array(
194
+ 'qty' => 0
195
+ )
196
+ ),
197
+ 'shipping_amount' => 0,
198
+ 'adjustment_positive' => 10,
199
+ 'adjustment_negative' => 0
200
+
201
+ )
202
+ );
203
+ $helperMock->expects($this->any())
204
+ ->method('getCreditMemoRequestParams')
205
+ ->will($this->returnValue($params));
206
+ $this->replaceByMock('helper', 'ops/order_refund', $helperMock);
207
+ }
208
+
209
+ protected function mockDataHelper()
210
+ {
211
+ $helperMock = $this->getHelperMock('ops/data', array('redirect'));
212
+ $this->replaceByMock('helper', 'ops/data', $helperMock);
213
+ }
214
+
215
+ protected function mockPaymentHelper()
216
+ {
217
+ $helperMock = $this->getHelperMock('ops/payment', array('saveOpsStatusToPayment', 'saveOpsRefundOperationCodeToPayment'));
218
+ $this->replaceByMock('helper', 'ops/payment', $helperMock);
219
+ }
220
+ }
221
+
app/code/community/Netresearch/OPS/Test/Model/Payment/AbstractTest.php ADDED
@@ -0,0 +1,973 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Netresearch_OPS_Test_Model_Payment_AbstractTest
3
+ extends EcomDev_PHPUnit_Test_Case_Controller
4
+ {
5
+ protected $model = null;
6
+
7
+
8
+ public function setUp()
9
+ {
10
+ parent::setUp();
11
+ $this->model = Mage::getModel('ops/payment_abstract');
12
+ }
13
+
14
+ public function testCaptureWithZeroAmount()
15
+ {
16
+ $paymentObject = new Varien_Object();
17
+ $directLinkHelperMock = $this->getModelMock('ops/api_directlink', array('performRequest'));
18
+ $directLinkHelperMock->expects($this->never())
19
+ ->method('performRequest');
20
+ $this->assertTrue($this->model->capture($paymentObject, 0.00) instanceof Netresearch_OPS_Model_Payment_Abstract);
21
+ }
22
+
23
+ /**
24
+ * @test
25
+ */
26
+ public function _getOrderDescriptionShorterThen100Chars()
27
+ {
28
+ $items = array(
29
+ new Varien_Object(array(
30
+ 'parent_item' => false,
31
+ 'name' => 'abc'
32
+ )),
33
+ new Varien_Object(array(
34
+ 'parent_item' => true,
35
+ 'name' => 'def'
36
+ )),
37
+ new Varien_Object(array(
38
+ 'parent_item' => false,
39
+ 'name' => 'ghi'
40
+ )),
41
+ new Varien_Object(array(
42
+ 'parent_item' => false,
43
+ 'name' => 'Dubbelwerkende cilinder Boring ø70 Stang ø40 3/8'
44
+ )),
45
+ new Varien_Object(array(
46
+ 'parent_item' => false,
47
+ 'name' => '0123456789012345678901234567890123456789012xxxxxx'
48
+ )),
49
+ );
50
+
51
+ $order = $this->getModelMock('sales/order', array('getAllItems'));
52
+ $order->expects($this->any())
53
+ ->method('getAllItems')
54
+ ->will($this->returnValue($items));
55
+
56
+ $result = Mage::getModel('ops/payment_abstract')->_getOrderDescription($order);
57
+ $this->assertEquals(
58
+ 'abc, ghi, Dubbelwerkende cilinder Boring 70 Stang 40 3/8, 012345678901234567890123456789012345678901',
59
+ $result
60
+ );
61
+ }
62
+
63
+ /**
64
+ * @test
65
+ */
66
+ public function _getOrderDescriptionLongerThen100Chars()
67
+ {
68
+ $items = array(
69
+ new Varien_Object(array(
70
+ 'parent_item' => false,
71
+ 'name' => '1bcdefghij abcdefghij abcdefghij abcdefghij abcdefghi1' //54 chars
72
+ )),
73
+ new Varien_Object(array(
74
+ 'parent_item' => false,
75
+ 'name' => '2bcdefghij abcdefghij abcdefghij abcdefghij abcdefghi2' //54 chars
76
+ ))
77
+ );
78
+
79
+ $order = $this->getModelMock('sales/order', array('getAllItems'));
80
+ $order->expects($this->any())
81
+ ->method('getAllItems')
82
+ ->will($this->returnValue($items));
83
+
84
+ $result = Mage::getModel('ops/payment_abstract')->_getOrderDescription($order);
85
+ $this->assertEquals(
86
+ '1bcdefghij abcdefghij abcdefghij abcdefghij abcdefghi1, 2bcdefghij abcdefghij abcdefghij abcdefghij ',
87
+ $result
88
+ );
89
+ }
90
+
91
+ /**
92
+ * @test
93
+ */
94
+ public function _getOrderDescriptionLongerThen100CharsOneItem()
95
+ {
96
+ $items = array(
97
+ new Varien_Object(array(
98
+ 'parent_item' => false,
99
+ 'name' => '1bcdefghij abcdefghij abcdefghij abcdefghij abcdefghi1 '.
100
+ '2bcdefghij abcdefghij abcdefghij abcdefghij abcdefghi2'
101
+ ))
102
+ );
103
+
104
+ $order = $this->getModelMock('sales/order', array('getAllItems'));
105
+ $order->expects($this->any())
106
+ ->method('getAllItems')
107
+ ->will($this->returnValue($items));
108
+
109
+ $result = Mage::getModel('ops/payment_abstract')->_getOrderDescription($order);
110
+ $this->assertEquals(
111
+ '1bcdefghij abcdefghij abcdefghij abcdefghij abcdefghi1 2bcdefghij abcdefghij abcdefghij abcdefghij a',
112
+ $result
113
+ );
114
+ }
115
+
116
+ /**
117
+ * check if payment method BankTransfer returns correct BRAND and PM values
118
+ *
119
+ * @loadExpectation paymentMethods
120
+ * @test
121
+ */
122
+ public function shouldReturnCorrectBrandAndPMValuesForBankTransfer()
123
+ {
124
+ $method = Mage::getModel('ops/payment_bankTransfer');
125
+
126
+ $payment = $this->getModelMock('sales/quote_payment', array('getId'));
127
+ $payment->expects($this->any())
128
+ ->method('getId')
129
+ ->will($this->returnValue('1'));
130
+ $this->replaceByMock('model', 'sales/quote_payment', $payment);
131
+ $quote = $this->getModelMock(
132
+ 'sales/quote', array('getPayment', 'getQuoteId')
133
+ );
134
+ $quote->expects($this->any())
135
+ ->method('getQuoteId')
136
+ ->will($this->returnValue('321'));
137
+ $quote->expects($this->any())
138
+ ->method('getPayment')
139
+ ->will($this->returnValue($payment));
140
+
141
+ $session = Mage::getSingleton(
142
+ 'checkout/session',
143
+ array(
144
+ 'last_real_order_id' => '123',
145
+ 'quote' => $quote
146
+ )
147
+ );
148
+
149
+ $method = Mage::getModel('ops/payment_bankTransfer');
150
+ try {
151
+ $method->assignData(array('country_id' => 'DE'));
152
+ } catch (Mage_Core_Exception $e) {
153
+ if ('Cannot retrieve the payment information object instance.'
154
+ != $e->getMessage()
155
+ ) {
156
+ throw $e;
157
+ }
158
+ }
159
+ $this->assertEquals(
160
+ $this->expected('ops_bankTransferDe')->getBrand(),
161
+ $method->getOpsBrand(null)
162
+ );
163
+ $reflectedMethod = new ReflectionMethod($method, 'getOpsCode');
164
+ $reflectedMethod->setAccessible(true);
165
+ $this->assertEquals(
166
+ $this->expected('ops_bankTransferDe')->getPm(),
167
+ $reflectedMethod->invoke($method)
168
+ );
169
+ }
170
+
171
+ /**
172
+ * @test
173
+ * @loadFixture ../../../../var/fixtures/orders.yaml
174
+ */
175
+ public function testCanCancelManually()
176
+ {
177
+ $opsAbstractPayment = new Netresearch_OPS_Model_Payment_Abstract();
178
+
179
+ //Check for successful can cancel (pending_payment and payment status 0)
180
+ $order = Mage::getModel("sales/order")->load(11);
181
+ $this->assertTrue($opsAbstractPayment->canCancelManually($order));
182
+
183
+ //Check for successful cancel (pending_payment and payment status null/not existing)
184
+ $order = Mage::getModel("sales/order")->load(14);
185
+ $this->assertTrue($opsAbstractPayment->canCancelManually($order));
186
+
187
+ //Check for denied can cancel (pending_payment and payment status 5)
188
+ $order = Mage::getModel("sales/order")->load(12);
189
+ $this->assertFalse($opsAbstractPayment->canCancelManually($order));
190
+
191
+ //Check for denied can cancel (processing and payment status 0)
192
+ $order = Mage::getModel("sales/order")->load(13);
193
+ $this->assertFalse($opsAbstractPayment->canCancelManually($order));
194
+ }
195
+
196
+
197
+ public function testGetCloseTransactionFromCreditMemoData()
198
+ {
199
+ $reflection_class
200
+ = new ReflectionClass("Netresearch_OPS_Model_Payment_Abstract");
201
+
202
+ //Then we need to get the method we wish to test and
203
+ //make it accessible
204
+ $method = $reflection_class->getMethod(
205
+ "getCloseTransactionFromCreditMemoData"
206
+ );
207
+ $method->setAccessible(true);
208
+
209
+ //We need to create an empty object to pass to
210
+ //ReflectionMethod invoke method followed by our
211
+ //test parameters
212
+ $paymentModel = new Netresearch_OPS_Model_Payment_Abstract(null);
213
+
214
+ $this->assertFalse($method->invoke($paymentModel, array()));
215
+ $this->assertFalse(
216
+ $method->invoke(
217
+ $paymentModel, array('ops_close_transaction' => 'OFF')
218
+ )
219
+ );
220
+ $this->assertFalse(
221
+ $method->invoke(
222
+ $paymentModel, array('ops_close_transaction' => 'off')
223
+ )
224
+ );
225
+ $this->assertFalse(
226
+ $method->invoke($paymentModel, array('ops_close_transaction' => ''))
227
+ );
228
+ $this->assertFalse(
229
+ $method->invoke($paymentModel, array('ops_close_transaction' => 1))
230
+ );
231
+
232
+ $this->assertTrue(
233
+ $method->invoke(
234
+ $paymentModel, array('ops_close_transaction' => 'on')
235
+ )
236
+ );
237
+ $this->assertTrue(
238
+ $method->invoke(
239
+ $paymentModel, array('ops_close_transaction' => 'ON')
240
+ )
241
+ );
242
+ }
243
+
244
+
245
+ /**
246
+ * @test
247
+ * @loadFixture ../../../../var/fixtures/orders.yaml
248
+ */
249
+ public function testCanRefund()
250
+ {
251
+ $paymentModel = Mage::getModel('ops/payment_abstract');
252
+ Mage::app()->getRequest()->setParam('order_id', 17);
253
+ $this->assertFalse($paymentModel->canRefund());
254
+
255
+ Mage::app()->getRequest()->setParam('order_id', 18);
256
+ $this->assertTrue($paymentModel->canRefund());
257
+
258
+ Mage::app()->getRequest()->setParam('order_id', 11);
259
+ $helperMock = $this->getHelperMock(
260
+ 'ops/directlink', array('hasPaymentTransactions')
261
+ );
262
+ $helperMock->expects($this->any())
263
+ ->method('hasPaymentTransactions')
264
+ ->will($this->returnValue(false));
265
+ $this->replaceByMock('helper', 'ops/directlink', $helperMock);
266
+
267
+ $this->assertTrue($paymentModel->canRefund());
268
+
269
+ $helperMock = $this->getHelperMock(
270
+ 'ops/directlink', array('hasPaymentTransactions')
271
+ );
272
+ $helperMock->expects($this->any())
273
+ ->method('hasPaymentTransactions')
274
+ ->will($this->returnValue(true));
275
+ $this->replaceByMock('helper', 'ops/directlink', $helperMock);
276
+
277
+ $helperMock = $this->getHelperMock('ops/data', array('redirect'));
278
+ $this->replaceByMock('helper', 'ops/data', $helperMock);
279
+
280
+ $paymentModel->canRefund();
281
+ $messages = Mage::getSingleton('core/session')->getMessages();
282
+ $messageItems = $messages->getItems();
283
+ $message = array_pop($messageItems);
284
+ $this->assertEquals(
285
+ Mage::helper('ops/data')->__(
286
+ 'There is already one creditmemo in the queue. The Creditmemo will be created automatically as soon as Ingenico Payment Services sends an acknowledgement.'
287
+ ), $message->getText()
288
+ );
289
+
290
+
291
+ $helperMock = $this->getHelperMock(
292
+ 'ops/directlink', array('hasPaymentTransactions')
293
+ );
294
+ $helperMock->expects($this->any())
295
+ ->method('hasPaymentTransactions')
296
+ ->will($this->throwException(new Exception('foo')));
297
+ $this->replaceByMock('helper', 'ops/directlink', $helperMock);
298
+ $this->assertTrue($paymentModel->canRefund());
299
+ }
300
+
301
+
302
+ /**
303
+ * @test
304
+ * @loadFixture ../../../../var/fixtures/orders.yaml
305
+ */
306
+ public function testGetMethodDependendFormFields()
307
+ {
308
+ $order = Mage::getModel('sales/order')->load(11);
309
+ $sessionMock = $this->getModelMock('checkout/session', array('getQuote'));
310
+ $sessionMock->expects($this->any())
311
+ ->method('getQuote')
312
+ ->will($this->returnValue($order));
313
+ $this->replaceByMock('model', 'checkout/session', $sessionMock);
314
+
315
+
316
+ $sessionMock = $this->getModelMock('customer/session', array('isLoggedIn'));
317
+ $sessionMock->expects($this->any())
318
+ ->method('isLoggedIn')
319
+ ->will($this->returnValue(1));
320
+ $this->replaceByMock('model', 'customer/session', $sessionMock);
321
+
322
+
323
+ $configMock = $this->getModelMock('ops/config', array('canSubmitExtraParameter'));
324
+ $configMock->expects($this->any())
325
+ ->method('canSubmitExtraParameter')
326
+ ->will($this->returnValue(true));
327
+ $paymentModel = Mage::getModel('ops/payment_abstract');
328
+ $paymentModel->setConfig($configMock);
329
+ $formFields = $paymentModel->getFormFields($order, array());
330
+
331
+ $this->assertTrue(array_key_exists('CN', $formFields));
332
+ $this->assertTrue(array_key_exists('OWNERZIP', $formFields));
333
+ $this->assertTrue(array_key_exists('OWNERCTY', $formFields));
334
+ $this->assertTrue(array_key_exists('OWNERTOWN', $formFields));
335
+ $this->assertTrue(array_key_exists('COM', $formFields));
336
+ $this->assertTrue(array_key_exists('OWNERTELNO', $formFields));
337
+ $this->assertTrue(array_key_exists('OWNERADDRESS', $formFields));
338
+ $this->assertTrue(array_key_exists('BRAND', $formFields));
339
+ $this->assertTrue(array_key_exists('ADDMATCH', $formFields));
340
+ $this->assertTrue(array_key_exists('ECOM_SHIPTO_POSTAL_POSTALCODE', $formFields));
341
+ $this->assertTrue(array_key_exists('ECOM_BILLTO_POSTAL_POSTALCODE', $formFields));
342
+ $this->assertTrue(array_key_exists('CUID', $formFields));
343
+
344
+ $order = Mage::getModel('sales/order')->load(27);
345
+
346
+ $formFields = $paymentModel->getFormFields($order, array());
347
+ $this->assertTrue(array_key_exists('ECOM_SHIPTO_POSTAL_POSTALCODE', $formFields));
348
+
349
+ $order = Mage::getModel('sales/order')->load(11);
350
+ $configMock = $this->getModelMock('ops/config', array('canSubmitExtraParameter'));
351
+ $configMock->expects($this->any())
352
+ ->method('canSubmitExtraParameter')
353
+ ->will($this->returnValue(false));
354
+ $paymentModel = Mage::getModel('ops/payment_abstract');
355
+ $paymentModel->setConfig($configMock);
356
+ $params = $paymentModel->getMethodDependendFormFields($order, array());
357
+ foreach ($this->getOwnerParams() as $ownerParam) {
358
+ if ($ownerParam == 'OWNERZIP') continue;
359
+ $this->assertArrayNotHasKey($ownerParam, $params);
360
+ }
361
+ foreach ($this->getShippingParams() as $shippingParam) {
362
+ $this->assertArrayNotHasKey($shippingParam, $params);
363
+ }
364
+
365
+ $order = Mage::getModel('sales/order')->load(19);
366
+
367
+ $configMock = $this->getModelMock('ops/config', array('canSubmitExtraParameter'));
368
+ $configMock->expects($this->any())
369
+ ->method('canSubmitExtraParameter')
370
+ ->will($this->returnValue(true));
371
+ $paymentModel = Mage::getModel('ops/payment_openInvoiceNl');
372
+ $paymentModel->setConfig($configMock);
373
+ $params = $paymentModel->getMethodDependendFormFields($order);
374
+ foreach ($this->getOwnerParams() as $ownerParam) {
375
+ if ($ownerParam == 'OWNERZIP' || $ownerParam == 'ADDMATCH' || $ownerParam == 'ECOM_BILLTO_POSTAL_POSTALCODE') continue;
376
+ $this->assertArrayHasKey($ownerParam, $params);
377
+ }
378
+ foreach ($this->getShippingParams() as $shippingParam) {
379
+ if ($shippingParam == 'ECOM_SHIPTO_POSTAL_STREET_LINE2') continue;
380
+ $this->assertArrayHasKey($shippingParam, $params);
381
+ }
382
+
383
+
384
+ }
385
+
386
+ public function testGetFormFieldsEmptyWithNonExistingOrder()
387
+ {
388
+ $paymentModel = Mage::getModel('ops/payment_abstract');
389
+ $this->assertTrue(
390
+ is_array($paymentModel->getFormFields(null, array()))
391
+ );
392
+ $this->assertEquals(
393
+ 0, count($paymentModel->getFormFields(null, array()))
394
+ );
395
+ }
396
+
397
+ /**
398
+ * @loadFixture ../../../../var/fixtures/orders.yaml
399
+ */
400
+ public function testGetFormFieldsWithEmptyOrderPassedButExistingOrder()
401
+ {
402
+ $order = Mage::getModel('sales/order')->load(11);
403
+ $payment = Mage::getModel('sales/order_payment');
404
+ $payment->setMethodInstance(Mage::getModel('ops/payment_cc'));
405
+ $order->setPayment($payment);
406
+ $paymentModel = $this->getModelMock(
407
+ 'ops/payment_abstract',
408
+ array('getMethodDependendFormFields', 'getOrder')
409
+ );
410
+ $paymentModel->expects($this->any())
411
+ ->method('getOrder')
412
+ ->will($this->returnValue($order));
413
+ $formFields = $paymentModel->getFormFields($order, array());
414
+ $this->assertArrayHasKey('PSPID', $formFields);
415
+ $this->assertArrayHasKey('SHASIGN', $formFields);
416
+ }
417
+
418
+ public function testGetFormFields()
419
+ {
420
+ $paymentModel = $this->getModelMock(
421
+ 'ops/payment_abstract', array('getMethodDependendFormFields')
422
+ );
423
+ $configMock = $this->getModelMock('ops/config', array('getPSPID'));
424
+ $configMock->expects($this->once())
425
+ ->method('getPSPID')
426
+ ->will($this->returnValue('NRMAGENTO'));
427
+ $this->replaceByMock('singleton', 'ops/config', $configMock);
428
+ $this->replaceByMock('model', 'ops/config', $configMock);
429
+ $helperMock = $this->getHelperMock('ops/payment', array('getShaSign'));
430
+ $helperMock->expects($this->any())
431
+ ->method('getSHASign')
432
+ ->with(
433
+ $this->anything(),
434
+ $this->anything(),
435
+ null
436
+ )
437
+ ->will($this->returnValue('SHA123'));
438
+ $this->replaceByMock('helper', 'ops/payment', $helperMock);
439
+ $requestMock = $this->getHelperMock('ops/payment_request', array('getConfig'));
440
+ $requestMock->expects($this->any())
441
+ ->method('getConfig')
442
+ ->will($this->returnValue($configMock));
443
+ $this->replaceByMock('helper', 'ops/payment_request', $requestMock);
444
+
445
+ $order = Mage::getModel('sales/order');
446
+ $address = Mage::getModel('sales/order_address');
447
+ $order->setBillingAddress($address);
448
+ $order->setShippingAddress($address);
449
+ $payment = Mage::getModel('sales/order_payment');
450
+ $payment->setMethodInstance(Mage::getModel('ops/payment_cc'));
451
+ $order->setPayment($payment);
452
+ $formFields = $paymentModel->getFormFields($order, array());
453
+ $this->assertArrayHasKey('PSPID', $formFields);
454
+ $this->assertArrayHasKey('SHASIGN', $formFields);
455
+ $this->assertArrayHasKey('ACCEPTURL', $formFields);
456
+ $this->assertArrayHasKey('DECLINEURL', $formFields);
457
+ $this->assertArrayHasKey('EXCEPTIONURL', $formFields);
458
+ $this->assertArrayHasKey('CANCELURL', $formFields);
459
+ $this->assertEquals('NRMAGENTO', $formFields['PSPID']);
460
+ $this->assertEquals(
461
+ '2d9f92d6f3955847ab2db427be75fe7eb0cde045', $formFields['SHASIGN']
462
+ );
463
+ }
464
+
465
+ public function testGetFormFieldsWithTPParam()
466
+ {
467
+ $this->markTestIncomplete('Depends on PCI release');
468
+
469
+ $paymentModel = $this->getModelMock(
470
+ 'ops/payment_abstract', array('getMethodDependendFormFields')
471
+ );
472
+ $configMock = $this->getModelMock(
473
+ 'ops/config', array('getPSPID', 'getconfigData')
474
+ );
475
+ $configMock->expects($this->once())
476
+ ->method('getPSPID')
477
+ ->with(null)
478
+ ->will($this->returnValue('NRMAGENTO'));
479
+ $configMock->expects($this->any())
480
+ ->method('getConfigData')
481
+ // ->with('template')
482
+ ->will($this->returnValue('spo'));
483
+ $this->replaceByMock('model', 'ops/config', $configMock);
484
+ $helperMock = $this->getHelperMock('ops/payment', array('getShaSign'));
485
+ $helperMock->expects($this->any())
486
+ ->method('getSHASign')
487
+ ->with(
488
+ $this->anything(),
489
+ $this->anything(),
490
+ null
491
+ )
492
+ ->will($this->returnValue('SHA123'));
493
+ $this->replaceByMock('helper', 'ops/payment', $helperMock);
494
+ $order = new Varien_Object();
495
+ $payment = new Varien_Object();
496
+ $payment->setMethodInstance(Mage::getModel('ops/payment_cc'));
497
+ $order->setPayment($payment);
498
+ $formFields = $paymentModel->getFormFields($order, array());
499
+ $this->assertArrayHasKey('PSPID', $formFields);
500
+ $this->assertArrayHasKey('SHASIGN', $formFields);
501
+ $this->assertArrayHasKey('TP', $formFields);
502
+ $this->assertEquals('NRMAGENTO', $formFields['PSPID']);
503
+ $this->assertEquals(
504
+ '2d9f92d6f3955847ab2db427be75fe7eb0cde045', $formFields['SHASIGN']
505
+ );
506
+ }
507
+ /**
508
+ * @loadFixture ../../../../var/fixtures/orders.yaml
509
+ */
510
+ public function testGetFormFieldsWithFormDependendFormFields()
511
+ {
512
+ $paymentModel = $this->getModelMock(
513
+ 'ops/payment_abstract', array('getMethodDependendFormFields')
514
+ );
515
+ $paymentModel->expects($this->any())
516
+ ->method('getMethodDependendFormFields')
517
+ ->will($this->returnValue(array('foo' => 'bla')));
518
+ $configMock = $this->getModelMock('ops/config', array('getPSPID'));
519
+ $configMock->expects($this->once())
520
+ ->method('getPSPID')
521
+ ->with(null)
522
+ ->will($this->returnValue('NRMAGENTO'));
523
+ $this->replaceByMock('model', 'ops/config', $configMock);
524
+ $helperMock = $this->getHelperMock('ops/payment', array('getShaSign'));
525
+ $helperMock->expects($this->any())
526
+ ->method('getSHASign')
527
+ ->with(
528
+ $this->anything(),
529
+ $this->anything(),
530
+ null
531
+ )
532
+ ->will($this->returnValue('SHA123'));
533
+ $this->replaceByMock('helper', 'ops/payment', $helperMock);
534
+ $requestMock = $this->getHelperMock('ops/payment_request', array('getConfig'));
535
+ $requestMock->expects($this->any())
536
+ ->method('getConfig')
537
+ ->will($this->returnValue($configMock));
538
+ $this->replaceByMock('helper', 'ops/payment_request', $requestMock);
539
+
540
+ $order = Mage::getModel('sales/order')->load(15);
541
+ $payment = Mage::getModel('sales/order_payment');
542
+ $payment->setMethodInstance(Mage::getModel('ops/payment_cc'));
543
+ $order->setPayment($payment);
544
+ $formFields = $paymentModel->getFormFields($order, array());
545
+ $this->assertArrayHasKey('PSPID', $formFields);
546
+ $this->assertArrayHasKey('SHASIGN', $formFields);
547
+ $this->assertArrayHasKey('foo', $formFields);
548
+ $this->assertEquals('NRMAGENTO', $formFields['PSPID']);
549
+ $this->assertEquals(
550
+ '2d9f92d6f3955847ab2db427be75fe7eb0cde045', $formFields['SHASIGN']
551
+ );
552
+ $this->assertEquals('bla', $formFields['foo']);
553
+ }
554
+
555
+ /**
556
+ * @loadFixture ../../../../var/fixtures/orders.yaml
557
+ */
558
+ public function testGetFormFieldsWithStoreId()
559
+ {
560
+ $paymentModel = $this->getModelMock(
561
+ 'ops/payment_abstract', array('getMethodDependendFormFields')
562
+ );
563
+ $configMock = $this->getModelMock(
564
+ 'ops/config', array('getPSPID', 'getSHASign')
565
+ );
566
+ $configMock->expects($this->once())
567
+ ->method('getPSPID')
568
+ ->with(1)
569
+ ->will($this->returnValue('NRMAGENTO5'));
570
+ $this->replaceByMock('model', 'ops/config', $configMock);
571
+
572
+ $helperMock = $this->getHelperMock('ops/payment', array('getShaSign'));
573
+
574
+ $helperMock->expects($this->any())
575
+ ->method('getSHASign')
576
+ ->with(
577
+ $this->anything(),
578
+ $this->anything(),
579
+ 1
580
+ )
581
+ ->will($this->returnValue('SHA987'));
582
+ $this->replaceByMock('helper', 'ops/payment', $helperMock);
583
+ $requestMock = $this->getHelperMock('ops/payment_request', array('getConfig'));
584
+ $requestMock->expects($this->any())
585
+ ->method('getConfig')
586
+ ->will($this->returnValue($configMock));
587
+ $this->replaceByMock('helper', 'ops/payment_request', $requestMock);
588
+
589
+ $order = Mage::getModel('sales/order')->load(15);
590
+ $payment = Mage::getModel('sales/order_payment');
591
+ $order->setStoreId(1);
592
+ $payment->setMethodInstance(Mage::getModel('ops/payment_cc'));
593
+ $order->setPayment($payment);
594
+ $formFields = $paymentModel->getFormFields($order, array());
595
+ $this->assertArrayHasKey('PSPID', $formFields);
596
+ $this->assertArrayHasKey('SHASIGN', $formFields);
597
+ $this->assertEquals('NRMAGENTO5', $formFields['PSPID']);
598
+ $this->assertEquals(
599
+ '0f119cdea2f8ddc0c852bab4765f12d3913982fc', $formFields['SHASIGN']
600
+ );
601
+ }
602
+
603
+ /**
604
+ * @loadFixture ../../../../var/fixtures/orders.yaml
605
+ */
606
+ public function testVoidWithOpsAutoVoid()
607
+ {
608
+ Mage::register('ops_auto_void', true);
609
+ $paymentModel = $this->getModelMock(
610
+ 'ops/payment_abstract',
611
+ array('canVoid')
612
+ );
613
+ $paymentModel->expects($this->any())
614
+ ->method('canVoid')
615
+ ->will($this->returnValue(true));
616
+ $payment = Mage::getModel('sales/order_payment');
617
+ $paymentModel->void($payment, 11.90);
618
+ $this->assertNull(Mage::registry('ops_auto_void'));
619
+ }
620
+
621
+ /**
622
+ * @loadFixture ../../../../var/fixtures/orders.yaml
623
+ */
624
+ public function testVoidWithExistingVoidTransactionLeadsToRedirect()
625
+ {
626
+ $helperMock = $this->getHelperMock('ops/directlink', array('checkExistingTransact'));
627
+ $helperMock
628
+ ->expects($this->any())
629
+ ->method('checkExistingTransact')
630
+ ->with(Netresearch_OPS_Model_Payment_Abstract::OPS_VOID_TRANSACTION_TYPE, 11)
631
+ ->will($this->returnValue(true));
632
+ $this->replaceByMock('helper', 'ops/directlink', $helperMock);
633
+ $order = Mage::getModel('sales/order')->load(11);
634
+
635
+ $paymentModel = $this->getModelMock(
636
+ 'ops/payment_abstract',
637
+ array('canVoid')
638
+ );
639
+ $paymentModel->expects($this->any())
640
+ ->method('canVoid')
641
+ ->will($this->returnValue(true));
642
+
643
+
644
+ $dataHelperMock = $this->getHelperMock('ops/data', array('redirect'));
645
+ $this->replaceByMock('helper', 'ops/data', $dataHelperMock);
646
+
647
+ Mage::getSingleton('core/session')->getMessages(true);
648
+ $noticeCountBefore = sizeof(
649
+ Mage::getSingleton('core/session')->getItemsByType('notice')
650
+ );
651
+ $paymentModel->void($order->getPayment());
652
+ $notices = Mage::getSingleton('core/session')->getMessages()->getItemsByType(
653
+ 'notice'
654
+ );
655
+ $noticeCountAfter = sizeof($notices);
656
+ $this->assertGreaterThan($noticeCountBefore, $noticeCountAfter);
657
+ $this->assertEquals(
658
+ $dataHelperMock->__('You already sent a void request. Please wait until the void request will be acknowledged.'),
659
+ current($notices)->getText()
660
+ );
661
+
662
+
663
+
664
+ }
665
+
666
+ /**
667
+ * @loadFixture ../../../../var/fixtures/orders.yaml
668
+ */
669
+ public function testVoidWithExistingCaptureLeadsToRedirect()
670
+ {
671
+
672
+ $paymentModel = $this->getModelMock(
673
+ 'ops/payment_abstract',
674
+ array('canVoid')
675
+ );
676
+ $paymentModel->expects($this->any())
677
+ ->method('canVoid')
678
+ ->will($this->returnValue(true));
679
+
680
+
681
+ $dataHelperMock = $this->getHelperMock('ops/data', array('redirect'));
682
+ $this->replaceByMock('helper', 'ops/data', $dataHelperMock);
683
+
684
+
685
+ $helperMock = $this->getHelperMock('ops/directlink', array('checkExistingTransact'));
686
+ $closure = function ($transactionType, $orderId) {
687
+ $result = false;
688
+ if ($transactionType == Netresearch_OPS_Model_Payment_Abstract::OPS_CAPTURE_TRANSACTION_TYPE) {
689
+ $result = true;
690
+ }
691
+ return $result;
692
+ };
693
+
694
+ $helperMock
695
+ ->expects($this->any())
696
+ ->method('checkExistingTransact')
697
+ ->will($this->returnCallback($closure));
698
+ $this->replaceByMock('helper', 'ops/directlink', $helperMock);
699
+
700
+ Mage::getSingleton('core/session')->getMessages(true);
701
+ $noticeCountBefore = sizeof(
702
+ Mage::getSingleton('core/session')->getItemsByType('notice')
703
+ );
704
+
705
+ $order = Mage::getModel('sales/order')->load(11);
706
+
707
+ $paymentModel->void($order->getPayment());
708
+ $notices = Mage::getSingleton('core/session')->getMessages()->getItemsByType(
709
+ 'notice'
710
+ );
711
+ $noticeCountAfter = sizeof($notices);
712
+ $this->assertGreaterThan($noticeCountBefore, $noticeCountAfter);
713
+ $this->assertEquals(
714
+ $dataHelperMock->__('There is one capture request waiting. Please wait until this request is acknowledged.'),
715
+ current($notices)->getText()
716
+ );
717
+ }
718
+
719
+ /**
720
+ * @loadFixture ../../../../var/fixtures/orders.yaml
721
+ */
722
+ public function testVoidFailsWhenRequestThrowsException()
723
+ {
724
+ $paymentModel = $this->getModelMock(
725
+ 'ops/payment_abstract',
726
+ array('canVoid')
727
+ );
728
+ $paymentModel->expects($this->any())
729
+ ->method('canVoid')
730
+ ->will($this->returnValue(true));
731
+ $helperMock = $this->getHelperMock('ops/directlink', array('checkExistingTransact'));
732
+ $helperMock
733
+ ->expects($this->any())
734
+ ->method('checkExistingTransact')
735
+ ->will($this->returnValue(false));
736
+ $this->replaceByMock('helper', 'ops/directlink', $helperMock);
737
+
738
+ $apiClientMock = $this->getModelMock(
739
+ 'ops/api_directlink', array('performRequest')
740
+ );
741
+ $exception = new Exception('Fake Request failed');
742
+ $apiClientMock->expects($this->any())
743
+ ->method('performRequest')
744
+ ->will(
745
+ $this->throwException($exception)
746
+ );
747
+ $this->replaceByMock('model', 'ops/api_directlink', $apiClientMock);
748
+ $order = Mage::getModel('sales/order')->load(11);
749
+ try {
750
+ $paymentModel->void($order->getPayment());
751
+ } catch (Exception $e) {
752
+ $this->assertEquals('Fake Request failed', $e->getMessage());
753
+ }
754
+ }
755
+
756
+ /**
757
+ * @loadFixture ../../../../var/fixtures/orders.yaml
758
+ */
759
+ public function testVoidFailsWhenStatusIsUnknown()
760
+ {
761
+ $paymentModel = $this->getModelMock(
762
+ 'ops/payment_abstract',
763
+ array('canVoid')
764
+ );
765
+ $paymentModel->expects($this->any())
766
+ ->method('canVoid')
767
+ ->will($this->returnValue(true));
768
+ $helperMock = $this->getHelperMock('ops/directlink', array('checkExistingTransact'));
769
+ $helperMock
770
+ ->expects($this->any())
771
+ ->method('checkExistingTransact')
772
+ ->will($this->returnValue(false));
773
+ $this->replaceByMock('helper', 'ops/directlink', $helperMock);
774
+
775
+ $apiClientMock = $this->getModelMock(
776
+ 'ops/api_directlink', array('performRequest')
777
+ );
778
+ $apiClientMock->expects($this->any())
779
+ ->method('performRequest')
780
+ ->will(
781
+ $this->returnValue(array(
782
+ 'STATUS' => 666
783
+ )));
784
+ $this->replaceByMock('model', 'ops/api_directlink', $apiClientMock);
785
+ $order = Mage::getModel('sales/order')->load(11);
786
+ try {
787
+ $pay