Tigo_TigoMoney - Version 0.1.0

Version Notes

Initial version of the module

Download this release

Release Info

Developer Hugo Barrientos
Extension Tigo_TigoMoney
Version 0.1.0
Comparing to
See all releases


Version 0.1.0

Files changed (82) hide show
  1. app/code/community/Tigo/TigoMoney/Block/Payment/Redirect/Form.php +45 -0
  2. app/code/community/Tigo/TigoMoney/Block/Payment/Redirect/Info.php +102 -0
  3. app/code/community/Tigo/TigoMoney/Block/Rewrite/Checkout/Onepage/Failure.php +61 -0
  4. app/code/community/Tigo/TigoMoney/Block/Rewrite/Checkout/Onepage/Success.php +75 -0
  5. app/code/community/Tigo/TigoMoney/Helper/Data.php +229 -0
  6. app/code/community/Tigo/TigoMoney/Model/Adminhtml/ConfigComment.php +76 -0
  7. app/code/community/Tigo/TigoMoney/Model/Cron/SyncOldPendingOrders.php +98 -0
  8. app/code/community/Tigo/TigoMoney/Model/Cron/SyncRecentPendingOrders.php +106 -0
  9. app/code/community/Tigo/TigoMoney/Model/Debug.php +71 -0
  10. app/code/community/Tigo/TigoMoney/Model/Observer/AdminOrderView.php +106 -0
  11. app/code/community/Tigo/TigoMoney/Model/Payment/Redirect.php +366 -0
  12. app/code/community/Tigo/TigoMoney/Model/Payment/Redirect/Api.php +395 -0
  13. app/code/community/Tigo/TigoMoney/Model/Payment/Redirect/Api/AbstractResponse.php +92 -0
  14. app/code/community/Tigo/TigoMoney/Model/Payment/Redirect/Api/AuthorizationRequest.php +771 -0
  15. app/code/community/Tigo/TigoMoney/Model/Payment/Redirect/Api/AuthorizationResponse.php +56 -0
  16. app/code/community/Tigo/TigoMoney/Model/Payment/Redirect/Api/GenerateTokenRequest.php +109 -0
  17. app/code/community/Tigo/TigoMoney/Model/Payment/Redirect/Api/GenerateTokenResponse.php +32 -0
  18. app/code/community/Tigo/TigoMoney/Model/Payment/Redirect/Api/RequestBuilder.php +181 -0
  19. app/code/community/Tigo/TigoMoney/Model/Payment/Redirect/Api/RequestInterface.php +37 -0
  20. app/code/community/Tigo/TigoMoney/Model/Payment/Redirect/Api/ResponseInterface.php +47 -0
  21. app/code/community/Tigo/TigoMoney/Model/Payment/Redirect/Api/ReverseTransactionRequest.php +340 -0
  22. app/code/community/Tigo/TigoMoney/Model/Payment/Redirect/Api/ReverseTransactionResponse.php +248 -0
  23. app/code/community/Tigo/TigoMoney/Model/Payment/Redirect/Api/TransactionStatusRequest.php +160 -0
  24. app/code/community/Tigo/TigoMoney/Model/Payment/Redirect/Api/TransactionStatusResponse.php +681 -0
  25. app/code/community/Tigo/TigoMoney/Model/Payment/Redirect/Sync.php +484 -0
  26. app/code/community/Tigo/TigoMoney/controllers/Adminhtml/Tigomoney/OrderController.php +86 -0
  27. app/code/community/Tigo/TigoMoney/controllers/RedirectController.php +49 -0
  28. app/code/community/Tigo/TigoMoney/controllers/ReturnController.php +40 -0
  29. app/code/community/Tigo/TigoMoney/controllers/SyncController.php +35 -0
  30. app/code/community/Tigo/TigoMoney/etc/config.xml +122 -0
  31. app/code/community/Tigo/TigoMoney/etc/system.xml +149 -0
  32. app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Block/Payment/Redirect/FormTest.php +64 -0
  33. app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Block/Payment/Redirect/InfoTest.php +142 -0
  34. app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Block/Payment/Rewrite/Checkout/Onepage/FailureTest.php +173 -0
  35. app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Block/Payment/Rewrite/Checkout/Onepage/SuccessTest.php +188 -0
  36. app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/ConfigTest.php +213 -0
  37. app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Helper/DataTest.php +265 -0
  38. app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Helper/DataTest/fixtures/default.yaml +13 -0
  39. app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Helper/DataTest/fixtures/disabledModes.yaml +3 -0
  40. app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Model/Adminhtml/ConfigCommentTest.php +112 -0
  41. app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Model/Cron/SyncOldPendingOrdersTest.php +192 -0
  42. app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Model/Cron/SyncRecentPendingOrdersTest.php +193 -0
  43. app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Model/DebugTest.php +81 -0
  44. app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Model/DebugTest/fixtures/debugModeOff.yaml +2 -0
  45. app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Model/DebugTest/fixtures/debugModeOn.yaml +2 -0
  46. app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Model/Observer/AdminOrderViewTest.php +295 -0
  47. app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Model/Payment/Redirect/Api/AbstractResponseTest.php +79 -0
  48. app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Model/Payment/Redirect/Api/AuthorizationRequestTest.php +704 -0
  49. app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Model/Payment/Redirect/Api/AuthorizationResponseTest.php +58 -0
  50. app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Model/Payment/Redirect/Api/GenerateTokenRequestTest.php +136 -0
  51. app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Model/Payment/Redirect/Api/GenerateTokenResponseTest.php +46 -0
  52. app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Model/Payment/Redirect/Api/RequestBuilderTest.php +513 -0
  53. app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Model/Payment/Redirect/Api/RequestBuilderTest/fixtures/default.yaml +10 -0
  54. app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Model/Payment/Redirect/Api/ReverseTransactionRequestTest.php +336 -0
  55. app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Model/Payment/Redirect/Api/ReverseTransactionResponseTest.php +154 -0
  56. app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Model/Payment/Redirect/Api/TransactionStatusRequestTest.php +175 -0
  57. app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Model/Payment/Redirect/Api/TransactionStatusResponseTest.php +370 -0
  58. app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Model/Payment/Redirect/ApiTest.php +1012 -0
  59. app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Model/Payment/Redirect/ApiTest/fixtures/testModeOff.yaml +2 -0
  60. app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Model/Payment/Redirect/ApiTest/fixtures/testModeOn.yaml +2 -0
  61. app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Model/Payment/Redirect/SyncTest.php +1898 -0
  62. app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Model/Payment/RedirectTest.php +875 -0
  63. app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Model/Payment/RedirectTest/fixtures/authorize.yaml +10 -0
  64. app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Model/Payment/RedirectTest/fixtures/default.yaml +3 -0
  65. app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Model/Payment/RedirectTest/fixtures/refund.yaml +10 -0
  66. app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/controllers/Adminhtml/Tigomoney/OrderControllerTest.php +173 -0
  67. app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/controllers/Adminhtml/Tigomoney/OrderControllerTest/fixtures/default.yaml +2 -0
  68. app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/controllers/RedirectControllerTest.php +169 -0
  69. app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/controllers/RedirectControllerTest/fixtures/default.yaml +2 -0
  70. app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/controllers/ReturnControllerTest.php +151 -0
  71. app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/controllers/SyncControllerTest.php +106 -0
  72. app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/controllers/SyncControllerTest/fixtures/default.yaml +2 -0
  73. app/design/adminhtml/default/default/template/tigo_tigomoney/payment/redirect/info.phtml +14 -0
  74. app/design/frontend/base/default/template/tigo_tigomoney/payment/redirect/form.phtml +19 -0
  75. app/design/frontend/base/default/template/tigo_tigomoney/payment/redirect/info.phtml +14 -0
  76. app/etc/modules/Tigo_TigoMoney.xml +13 -0
  77. app/locale/es_ES/Tigo_TigoMoney.csv +15 -0
  78. package.xml +20 -0
  79. skin/adminhtml/default/default/tigo_tigomoney/.DS_Store +0 -0
  80. skin/adminhtml/default/default/tigo_tigomoney/images/logo.png +0 -0
  81. skin/frontend/base/default/tigo_tigomoney/images/logo.png +0 -0
  82. skin/frontend/base/default/tigo_tigomoney/images/phones.png +0 -0
app/code/community/Tigo/TigoMoney/Block/Payment/Redirect/Form.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Tigo_TigoMoney_Block_Payment_Redirect_Form
5
+ */
6
+ class Tigo_TigoMoney_Block_Payment_Redirect_Form extends Mage_Payment_Block_Form
7
+ {
8
+ /**
9
+ * Template Path for the info block
10
+ */
11
+ const TEMPLATE_PATH = 'tigo_tigomoney/payment/redirect/form.phtml';
12
+
13
+ /**
14
+ * Data Helper
15
+ * @var Tigo_TigoMoney_Helper_Data|null
16
+ */
17
+ protected $_dataHelper = null;
18
+
19
+ /**
20
+ * Template path
21
+ * @var string
22
+ */
23
+ protected $_template = self::TEMPLATE_PATH;
24
+
25
+ /**
26
+ * Data Helper Getter
27
+ * @return Tigo_TigoMoney_Helper_Data
28
+ */
29
+ protected function _getDataHelper()
30
+ {
31
+ if ($this->_dataHelper === null) {
32
+ $this->_dataHelper = Mage::helper('tigo_tigomoney/data');
33
+ }
34
+ return $this->_dataHelper;
35
+ }
36
+
37
+ /**
38
+ * Returns Description
39
+ * @return string
40
+ */
41
+ public function getDescription()
42
+ {
43
+ return $this->_getDataHelper()->getDescription();
44
+ }
45
+ }
app/code/community/Tigo/TigoMoney/Block/Payment/Redirect/Info.php ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Tigo_TigoMoney_Block_Payment_Redirect_Info
5
+ */
6
+ class Tigo_TigoMoney_Block_Payment_Redirect_Info extends Mage_Payment_Block_Info
7
+ {
8
+
9
+ /**
10
+ * Additional Info Return Key - Access Token Errors
11
+ */
12
+ const ADDITIONAL_INFO_RETURN_KEY_ACCESS_TOKEN_ERRORS = 'Access Token Generation Error(s)';
13
+
14
+ /**
15
+ * Additional Info Return Key - Auth Code
16
+ */
17
+ const ADDITIONAL_INFO_RETURN_KEY_AUTH_CODE = 'Auth Code';
18
+
19
+ /**
20
+ * Additional Info Return Key - Authorization Errors
21
+ */
22
+ const ADDITIONAL_INFO_RETURN_KEY_AUTHORIZATION_ERRORS = 'Authorization Error(s)';
23
+
24
+ /**
25
+ * Additional Info Return Key - MFS Transaction Id
26
+ */
27
+ const ADDITIONAL_INFO_RETURN_KEY_MFS_TRANSACTION_ID = 'MFS Transaction ID';
28
+
29
+ /**
30
+ * Additional Info Return Key - Transaction Code
31
+ */
32
+ const ADDITIONAL_INFO_RETURN_KEY_TRANSACTION_CODE = 'Transaction Code';
33
+
34
+ /**
35
+ * Template Path for the info block
36
+ */
37
+ const TEMPLATE_PATH = 'tigo_tigomoney/payment/redirect/info.phtml';
38
+
39
+ /**
40
+ * Sets new template path
41
+ * @return void
42
+ */
43
+ protected function _construct()
44
+ {
45
+ parent::_construct();
46
+ $this->setTemplate(self::TEMPLATE_PATH);
47
+ }
48
+
49
+ /**
50
+ * Adds transaction information to order view on the Admin page
51
+ * @return array
52
+ */
53
+ public function getSpecificInformation() {
54
+ $return = parent::getSpecificInformation();
55
+
56
+ if ($this->_isAdmin()) {
57
+ $info = $this->getInfo();
58
+
59
+ if ($value = $info->getAdditionalInformation(
60
+ Tigo_TigoMoney_Model_Payment_Redirect::ADDITIONAL_INFO_KEY_MFS_TRANSACTION_ID
61
+ )) {
62
+ $return[$this->__(self::ADDITIONAL_INFO_RETURN_KEY_MFS_TRANSACTION_ID)] = $value;
63
+ }
64
+
65
+ if ($value = $info->getAdditionalInformation(
66
+ Tigo_TigoMoney_Model_Payment_Redirect::ADDITIONAL_INFO_KEY_AUTH_CODE
67
+ )) {
68
+ $return[$this->__(self::ADDITIONAL_INFO_RETURN_KEY_AUTH_CODE)] = $value;
69
+ }
70
+
71
+ if ($value = $info->getAdditionalInformation(
72
+ Tigo_TigoMoney_Model_Payment_Redirect::ADDITIONAL_INFO_KEY_TRANSACTION_CODE
73
+ )) {
74
+ $return[$this->__(self::ADDITIONAL_INFO_RETURN_KEY_TRANSACTION_CODE)] = $value;
75
+ }
76
+
77
+ if ($value = $info->getAdditionalInformation(
78
+ Tigo_TigoMoney_Model_Payment_Redirect::ADDITIONAL_INFO_KEY_ACCESS_TOKEN_ERRORS
79
+ )) {
80
+ $return[$this->__(self::ADDITIONAL_INFO_RETURN_KEY_ACCESS_TOKEN_ERRORS)] = $value;
81
+ }
82
+
83
+ if ($value = $info->getAdditionalInformation(
84
+ Tigo_TigoMoney_Model_Payment_Redirect::ADDITIONAL_INFO_KEY_AUTHORIZATION_ERRORS
85
+ )) {
86
+ $return[$this->__(self::ADDITIONAL_INFO_RETURN_KEY_AUTHORIZATION_ERRORS)] = $value;
87
+ }
88
+
89
+ }
90
+
91
+ return $return;
92
+ }
93
+
94
+ /**
95
+ * Are we on the admin?
96
+ * @return bool
97
+ */
98
+ protected function _isAdmin()
99
+ {
100
+ return (bool) Mage::app()->getStore()->isAdmin();
101
+ }
102
+ }
app/code/community/Tigo/TigoMoney/Block/Rewrite/Checkout/Onepage/Failure.php ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Tigo_TigoMoney_Block_Rewrite_Checkout_Onepage_Failure
5
+ */
6
+ class Tigo_TigoMoney_Block_Rewrite_Checkout_Onepage_Failure extends Mage_Checkout_Block_Onepage_Failure
7
+ {
8
+ /**
9
+ * Data Helper
10
+ * @var Tigo_TigoMoney_Helper_Data|null
11
+ */
12
+ protected $_dataHelper = null;
13
+
14
+ /**
15
+ * Overriding Continue Shopping Url from failure page, to make it
16
+ * possible for the admin to configure a different page from the admin area
17
+ * @return string
18
+ */
19
+ public function getContinueShoppingUrl()
20
+ {
21
+ $return = parent::getContinueShoppingUrl();
22
+ if ($this->_isTigoMoneyOrder() && $this->_getDataHelper()->getFailureContinueShoppingUrl()) {
23
+ $return = $this->_getDataHelper()->getFailureContinueShoppingUrl();
24
+ }
25
+ return $return;
26
+ }
27
+
28
+ /**
29
+ * Data Helper Getter
30
+ * @return Mage_Core_Helper_Abstract|null|Tigo_TigoMoney_Helper_Data
31
+ */
32
+ protected function _getDataHelper()
33
+ {
34
+ if ($this->_dataHelper === null) {
35
+ $this->_dataHelper = Mage::helper('tigo_tigomoney/data');
36
+ }
37
+ return $this->_dataHelper;
38
+ }
39
+
40
+ /**
41
+ * Retrieves last order from checkout session
42
+ * @return Mage_Sales_Model_Order
43
+ */
44
+ protected function _getLastOrder()
45
+ {
46
+ $lastOrderId = $this->getRealOrderId();
47
+ /** @var Mage_Sales_Model_Order $order */
48
+ $order = Mage::getModel('sales/order');
49
+ return $order->loadByIncrementId($lastOrderId);
50
+ }
51
+
52
+ /**
53
+ * Checks whether the last order placed was placed using tigo money
54
+ * @return bool
55
+ */
56
+ protected function _isTigoMoneyOrder()
57
+ {
58
+ $lastOrder = $this->_getLastOrder();
59
+ return ($lastOrder->getPayment()->getMethod() == Tigo_TigoMoney_Model_Payment_Redirect::METHOD_CODE);
60
+ }
61
+ }
app/code/community/Tigo/TigoMoney/Block/Rewrite/Checkout/Onepage/Success.php ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Tigo_TigoMoney_Block_Rewrite_Checkout_Onepage_Success
5
+ */
6
+ class Tigo_TigoMoney_Block_Rewrite_Checkout_Onepage_Success extends Mage_Checkout_Block_Onepage_Success
7
+ {
8
+ /**
9
+ * Data Helper
10
+ * @var Tigo_TigoMoney_Helper_Data|null
11
+ */
12
+ protected $_dataHelper = null;
13
+
14
+ /**
15
+ * Overriding Continue Shopping Url from Success page, to make it
16
+ * possible for the admin to configure a different page from the admin area
17
+ * @param string $route
18
+ * @param array $params
19
+ * @return string
20
+ */
21
+ public function getUrl($route = '', $params = array())
22
+ {
23
+ $return = parent::getUrl($route, $params);
24
+ if ($this->_isTigoMoneyOrder() && $this->_getDataHelper()->getSuccessContinueShoppingUrl()) {
25
+ $return = $this->_getDataHelper()->getSuccessContinueShoppingUrl();
26
+ }
27
+ return $return;
28
+ }
29
+
30
+ /**
31
+ * Data Helper Getter
32
+ * @return Mage_Core_Helper_Abstract|null|Tigo_TigoMoney_Helper_Data
33
+ */
34
+ protected function _getDataHelper()
35
+ {
36
+ if ($this->_dataHelper === null) {
37
+ $this->_dataHelper = Mage::helper('tigo_tigomoney/data');
38
+ }
39
+ return $this->_dataHelper;
40
+ }
41
+
42
+ /**
43
+ * Retrieves last order from checkout session
44
+ * @return Mage_Sales_Model_Order
45
+ */
46
+ protected function _getLastOrder()
47
+ {
48
+ $lastOrderId = $this->_getLastOrderId();
49
+ /** @var Mage_Sales_Model_Order $order */
50
+ $order = Mage::getModel('sales/order');
51
+ $order->load($lastOrderId);
52
+ return $order;
53
+ }
54
+
55
+ /**
56
+ * Retrieves Last Order Id From Checkout Session
57
+ * @return int
58
+ */
59
+ protected function _getLastOrderId()
60
+ {
61
+ /** @var Mage_Checkout_Model_Session $session */
62
+ $session = Mage::getSingleton('checkout/session');
63
+ return $session->getLastOrderId();
64
+ }
65
+
66
+ /**
67
+ * Checks whether the last order placed was placed using tigo money
68
+ * @return bool
69
+ */
70
+ protected function _isTigoMoneyOrder()
71
+ {
72
+ $lastOrder = $this->_getLastOrder();
73
+ return ($lastOrder->getPayment()->getMethod() == Tigo_TigoMoney_Model_Payment_Redirect::METHOD_CODE);
74
+ }
75
+ }
app/code/community/Tigo/TigoMoney/Helper/Data.php ADDED
@@ -0,0 +1,229 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Tigo_TigoMoney_Helper_Data
5
+ */
6
+ class Tigo_TigoMoney_Helper_Data extends Mage_Core_Helper_Abstract
7
+ {
8
+ /**
9
+ * Config Path - Client Id
10
+ */
11
+ const CONFIG_PATH_CLIENT_ID = 'payment/tigo_tigomoney/client_id';
12
+
13
+ /**
14
+ * Config Path - Client Secret
15
+ */
16
+ const CONFIG_PATH_CLIENT_SECRET = 'payment/tigo_tigomoney/client_secret';
17
+
18
+ /**
19
+ * Config Path - Debug Mode
20
+ */
21
+ const CONFIG_PATH_DEBUG_MODE = 'payment/tigo_tigomoney/debug_mode';
22
+
23
+ /**
24
+ * Config Path - Description
25
+ */
26
+ const CONFIG_PATH_DESCRIPTION = 'payment/tigo_tigomoney/description';
27
+
28
+ /**
29
+ * Config Path - Failure Continue Shopping URL
30
+ */
31
+ const CONFIG_PATH_FAILURE_CONTINUE_SHOPPING_URL = 'payment/tigo_tigomoney/failure_continue_shopping_url';
32
+
33
+ /**
34
+ * Config Path - Merchant Account
35
+ */
36
+ const CONFIG_PATH_MERCHANT_ACCOUNT = 'payment/tigo_tigomoney/merchant_account';
37
+
38
+ /**
39
+ * Config Path - Merchant ID
40
+ */
41
+ const CONFIG_PATH_MERCHANT_ID = 'payment/tigo_tigomoney/merchant_id';
42
+
43
+ /**
44
+ * Config Path - Merchant Pin
45
+ */
46
+ const CONFIG_PATH_MERCHANT_PIN = 'payment/tigo_tigomoney/merchant_pin';
47
+
48
+ /**
49
+ * Config Path - Merchant Reference
50
+ */
51
+ const CONFIG_PATH_MERCHANT_REFERENCE = 'payment/tigo_tigomoney/merchant_reference';
52
+
53
+ /**
54
+ * Config Path - Success Continue Shopping URL
55
+ */
56
+ const CONFIG_PATH_SUCCESS_CONTINUE_SHOPPING_URL = 'payment/tigo_tigomoney/success_continue_shopping_url';
57
+
58
+ /**
59
+ * Config Path - Test Mode
60
+ */
61
+ const CONFIG_PATH_TEST_MODE = 'payment/tigo_tigomoney/test_mode';
62
+
63
+ /**
64
+ * Adminhtml Helper
65
+ * @var null|Mage_Adminhtml_Helper_Data
66
+ */
67
+ protected $_adminhtmlHelper = null;
68
+
69
+ /**
70
+ * Retrieves current order from registry
71
+ * @return Mage_Adminhtml_Helper_Data
72
+ */
73
+ protected function _getAdminhtmlHelper()
74
+ {
75
+ if ($this->_adminhtmlHelper === null) {
76
+ $this->_adminhtmlHelper = Mage::helper('adminhtml');
77
+ }
78
+ return $this->_adminhtmlHelper;
79
+ }
80
+
81
+ /**
82
+ * Returns module's Callback URI
83
+ * @return string
84
+ */
85
+ public function getCallbackUri()
86
+ {
87
+ return $this->_getUrl('tigomoney/sync');
88
+ }
89
+
90
+ /**
91
+ * Retrieves Client Id from configuration
92
+ * @return string
93
+ */
94
+ public function getClientId()
95
+ {
96
+ return (string) $this->_getStoreConfig(self::CONFIG_PATH_CLIENT_ID);
97
+ }
98
+
99
+ /**
100
+ * Retrieves Client Secret from configuration
101
+ * @return string
102
+ */
103
+ public function getClientSecret()
104
+ {
105
+ return (string) $this->_getStoreConfig(self::CONFIG_PATH_CLIENT_SECRET);
106
+ }
107
+
108
+ /**
109
+ * Retrieves Checkout Description from configuration
110
+ * @return string
111
+ */
112
+ public function getDescription()
113
+ {
114
+ return (string) $this->_getStoreConfig(self::CONFIG_PATH_DESCRIPTION);
115
+ }
116
+
117
+ /**
118
+ * Retrieves Checkout Failure Continue Shopping Url from configuration
119
+ * @return string
120
+ */
121
+ public function getFailureContinueShoppingUrl()
122
+ {
123
+ return trim($this->_getStoreConfig(self::CONFIG_PATH_FAILURE_CONTINUE_SHOPPING_URL));
124
+ }
125
+
126
+ /**
127
+ * Retrieves internal redirect url
128
+ * @return string
129
+ */
130
+ public function getInternalRedirectUri()
131
+ {
132
+ return $this->_getUrl('tigomoney/redirect/index', array('_secure' => true));
133
+ }
134
+
135
+ /**
136
+ * Retrieves Merchant Account from configuration
137
+ * @return string
138
+ */
139
+ public function getMerchantAccount()
140
+ {
141
+ return (string) $this->_getStoreConfig(self::CONFIG_PATH_MERCHANT_ACCOUNT);
142
+ }
143
+
144
+ /**
145
+ * Retrieves Merchant Id from configuration
146
+ * @return string
147
+ */
148
+ public function getMerchantId()
149
+ {
150
+ return (string) $this->_getStoreConfig(self::CONFIG_PATH_MERCHANT_ID);
151
+ }
152
+
153
+ /**
154
+ * Retrieves Merchant Pin from configuration
155
+ * @return string
156
+ */
157
+ public function getMerchantPin()
158
+ {
159
+ return (string) $this->_getStoreConfig(self::CONFIG_PATH_MERCHANT_PIN);
160
+ }
161
+
162
+ /**
163
+ * Retrieves Merchant Reference from configuration
164
+ * @return string
165
+ */
166
+ public function getMerchantReference()
167
+ {
168
+ return (string) $this->_getStoreConfig(self::CONFIG_PATH_MERCHANT_REFERENCE);
169
+ }
170
+
171
+ /**
172
+ * Returns module's Redirect URI
173
+ * @return string
174
+ */
175
+ public function getRedirectUri()
176
+ {
177
+ return $this->_getUrl('tigomoney/return');
178
+ }
179
+
180
+ /**
181
+ * Retrieves info from configuration
182
+ * @param $path string
183
+ * @param $storeId int
184
+ * @return mixed
185
+ */
186
+ protected function _getStoreConfig($path, $storeId = null) {
187
+ return Mage::getStoreConfig($path, $storeId);
188
+ }
189
+
190
+ /**
191
+ * Retrieves Checkout Success Continue Shopping Url from configuration
192
+ * @return string
193
+ */
194
+ public function getSuccessContinueShoppingUrl()
195
+ {
196
+ return trim($this->_getStoreConfig(self::CONFIG_PATH_SUCCESS_CONTINUE_SHOPPING_URL));
197
+ }
198
+
199
+ /**
200
+ * Returns Admin Sync Order Url
201
+ * @param Mage_Sales_Model_Order $order
202
+ * @return string
203
+ */
204
+ public function getSyncOrderUrl(Mage_Sales_Model_Order $order) {
205
+ $orderId = $order->getId();
206
+ return $this->_getAdminhtmlHelper()->getUrl(
207
+ 'adminhtml/tigomoney_order/sync',
208
+ array('order_id' => $orderId)
209
+ );
210
+ }
211
+
212
+ /**
213
+ * Is debug mode enabled?
214
+ * @return bool
215
+ */
216
+ public function isDebugModeEnabled()
217
+ {
218
+ return (bool) $this->_getStoreConfig(self::CONFIG_PATH_DEBUG_MODE);
219
+ }
220
+
221
+ /**
222
+ * Is test mode enabled?
223
+ * @return bool
224
+ */
225
+ public function isTestModeEnabled()
226
+ {
227
+ return (bool) $this->_getStoreConfig(self::CONFIG_PATH_TEST_MODE);
228
+ }
229
+ }
app/code/community/Tigo/TigoMoney/Model/Adminhtml/ConfigComment.php ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Tigo_TigoMoney_Model_Adminhtml_ConfigComment
4
+ {
5
+ /**
6
+ * @var Tigo_TigoMoney_Helper_Data|null
7
+ */
8
+ protected $_dataHelper = null;
9
+
10
+ /**
11
+ * As we are in the admin, the urls will always be rendered without url rewriting.
12
+ * This method will remove index.php from the URL if rewrites are enabled
13
+ * @param string $url
14
+ * @return string
15
+ */
16
+ protected function _fixRewrite($url)
17
+ {
18
+ $return = $url;
19
+ if ($this->_isUrlRewriteEnabled()) {
20
+ $return = preg_replace('/index\.php\//', '', $return);
21
+ }
22
+ return $return;
23
+ }
24
+
25
+ /**
26
+ * Returns callback URI
27
+ * @return string
28
+ */
29
+ protected function _getCallbackUrl()
30
+ {
31
+ return $this->_fixRewrite($this->_getDataHelper()->getCallbackUri());
32
+ }
33
+
34
+ /**
35
+ * Returns comment text for admin configuration page
36
+ * @return string
37
+ */
38
+ public function getCommentText()
39
+ {
40
+ $helper = Mage::helper('tigo_tigomoney');
41
+ return
42
+ $helper->__('Your store has two URIs which will be used by Tigo Payment Server. They are:') . '<br />' .
43
+ '<strong>Redirect URI:</strong> ' . $this->_getRedirectUri() . ' <br />' .
44
+ '<strong>Callback URI:</strong> ' . $this->_getCallbackUrl() . ' <br />';
45
+ }
46
+
47
+ /**
48
+ * Data Helper Getter
49
+ * @return Tigo_TigoMoney_Helper_Data
50
+ */
51
+ protected function _getDataHelper()
52
+ {
53
+ if ($this->_dataHelper === null) {
54
+ $this->_dataHelper = Mage::helper('tigo_tigomoney/data');
55
+ }
56
+ return $this->_dataHelper;
57
+ }
58
+
59
+ /**
60
+ * Returns redirect URI
61
+ * @return string
62
+ */
63
+ protected function _getRedirectUri()
64
+ {
65
+ return $this->_fixRewrite($this->_getDataHelper()->getRedirectUri());
66
+ }
67
+
68
+ /**
69
+ * Is url rewrite enabled?
70
+ * @return bool
71
+ */
72
+ protected function _isUrlRewriteEnabled()
73
+ {
74
+ return Mage::getStoreConfigFlag('web/seo/use_rewrites');
75
+ }
76
+ }
app/code/community/Tigo/TigoMoney/Model/Cron/SyncOldPendingOrders.php ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Tigo_TigoMoney_Model_Cron_SyncOldPendingOrders
4
+ {
5
+ /**
6
+ * @var Tigo_TigoMoney_Helper_Data|null
7
+ */
8
+ protected $_dataHelper = null;
9
+
10
+ /**
11
+ * @var Tigo_TigoMoney_Model_Debug|null
12
+ */
13
+ protected $_debug = null;
14
+
15
+ /**
16
+ * @var Tigo_TigoMoney_Model_Payment_Redirect_Sync|null
17
+ */
18
+ protected $_sync = null;
19
+
20
+ /**
21
+ * Data Helper getter
22
+ * @return Tigo_TigoMoney_Helper_Data
23
+ */
24
+ protected function _getDataHelper()
25
+ {
26
+ if ($this->_dataHelper === null) {
27
+ $this->_dataHelper = Mage::helper('tigo_tigomoney');
28
+ }
29
+ return $this->_dataHelper;
30
+ }
31
+
32
+ /**
33
+ * Debug Model getter
34
+ * @return Tigo_TigoMoney_Model_Debug
35
+ */
36
+ protected function _getDebug()
37
+ {
38
+ if ($this->_debug === null) {
39
+ $this->_debug = Mage::getModel('tigo_tigomoney/debug');
40
+ }
41
+ return $this->_debug;
42
+ }
43
+
44
+ /**
45
+ * Retrieves Pending Orders paid with Tigo Money payment method
46
+ * @return Mage_Sales_Model_Order[]
47
+ */
48
+ protected function _getPendingOrders()
49
+ {
50
+ /** @var Mage_Sales_Model_Entity_Order_Collection $orderCollection */
51
+ $orderCollection = Mage::getModel('sales/order')
52
+ ->getCollection()
53
+ ->join(
54
+ array('payment' => 'sales/order_payment'),
55
+ 'main_table.entity_id=payment.parent_id',
56
+ array('payment_method' => 'payment.method')
57
+ )
58
+ ->addAttributeToSelect('*')
59
+ ->addFieldToFilter('payment.method', array(array('like' => Tigo_TigoMoney_Model_Payment_Redirect::METHOD_CODE)))
60
+ ->addFieldToFilter('main_table.state', array(array('nin' => array('complete', 'closed', 'canceled'))));
61
+ return $orderCollection->getItems();
62
+ }
63
+
64
+ /**
65
+ * Sync model getter
66
+ * @return Tigo_TigoMoney_Model_Payment_Redirect_Sync
67
+ */
68
+ protected function _getSync()
69
+ {
70
+ if ($this->_sync === null) {
71
+ $this->_sync = Mage::getModel('tigo_tigomoney/payment_redirect_sync');
72
+ }
73
+ return $this->_sync;
74
+ }
75
+
76
+ /**
77
+ * Syncs orders which haven't yet been paid
78
+ * @return void
79
+ */
80
+ public function run()
81
+ {
82
+ foreach($this->_getPendingOrders() as $order)
83
+ {
84
+ if (!$order->hasInvoices() && !$order->isCanceled()) {
85
+ try {
86
+ $this->_getSync()->syncOrder($order);
87
+ } catch (Exception $e) {
88
+ $this->_getDebug()->debug(
89
+ $this->_getDataHelper()->__(
90
+ 'There was an error while trying to sync current order with Tigo Money. Order: ' .
91
+ $order->getIncrementId() . '. Error: ' . $e->getMessage()
92
+ )
93
+ );
94
+ }
95
+ }
96
+ }
97
+ }
98
+ }
app/code/community/Tigo/TigoMoney/Model/Cron/SyncRecentPendingOrders.php ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Tigo_TigoMoney_Model_Cron_SyncRecentPendingOrders
4
+ {
5
+ /**
6
+ * @var Tigo_TigoMoney_Helper_Data|null
7
+ */
8
+ protected $_dataHelper = null;
9
+
10
+ /**
11
+ * @var Tigo_TigoMoney_Model_Debug|null
12
+ */
13
+ protected $_debug = null;
14
+
15
+ /**
16
+ * @var Tigo_TigoMoney_Model_Payment_Redirect_Sync|null
17
+ */
18
+ protected $_sync = null;
19
+
20
+ /**
21
+ * Data Helper getter
22
+ * @return Tigo_TigoMoney_Helper_Data
23
+ */
24
+ protected function _getDataHelper()
25
+ {
26
+ if ($this->_dataHelper === null) {
27
+ $this->_dataHelper = Mage::helper('tigo_tigomoney');
28
+ }
29
+ return $this->_dataHelper;
30
+ }
31
+
32
+ /**
33
+ * Debug Model getter
34
+ * @return Tigo_TigoMoney_Model_Debug
35
+ */
36
+ protected function _getDebug()
37
+ {
38
+ if ($this->_debug === null) {
39
+ $this->_debug = Mage::getModel('tigo_tigomoney/debug');
40
+ }
41
+ return $this->_debug;
42
+ }
43
+
44
+ /**
45
+ * Retrieves Pending Orders paid with Tigo Money payment method
46
+ * @return Mage_Sales_Model_Order[]
47
+ */
48
+ protected function _getPendingOrders()
49
+ {
50
+ /** @var Mage_Core_Model_Date $date */
51
+ $date = Mage::getModel('core/date');
52
+ $format = 'Y-m-d H:i:s';
53
+ $offset = $date->getGmtOffset();
54
+ $dateStart = $date->date($format, strtotime('1 hour ago') - $offset);
55
+ $dateEnd = $date->date($format, time() - $offset);
56
+
57
+ /** @var Mage_Sales_Model_Entity_Order_Collection $orderCollection */
58
+ $orderCollection = Mage::getModel('sales/order')
59
+ ->getCollection()
60
+ ->join(
61
+ array('payment' => 'sales/order_payment'),
62
+ 'main_table.entity_id=payment.parent_id',
63
+ array('payment_method' => 'payment.method')
64
+ )
65
+ ->addAttributeToSelect('*')
66
+ ->addFieldToFilter('payment.method', array(array('like' => Tigo_TigoMoney_Model_Payment_Redirect::METHOD_CODE)))
67
+ ->addFieldToFilter('main_table.state', array(array('nin' => array('complete', 'closed', 'canceled'))))
68
+ ->addFieldToFilter('main_table.created_at', array('from' => $dateStart, 'to' => $dateEnd));
69
+ return $orderCollection->getItems();
70
+ }
71
+
72
+ /**
73
+ * Sync model getter
74
+ * @return Tigo_TigoMoney_Model_Payment_Redirect_Sync
75
+ */
76
+ protected function _getSync()
77
+ {
78
+ if ($this->_sync === null) {
79
+ $this->_sync = Mage::getModel('tigo_tigomoney/payment_redirect_sync');
80
+ }
81
+ return $this->_sync;
82
+ }
83
+
84
+ /**
85
+ * Syncs orders which haven't yet been paid
86
+ * @return void
87
+ */
88
+ public function run()
89
+ {
90
+ foreach($this->_getPendingOrders() as $order)
91
+ {
92
+ if (!$order->hasInvoices() && !$order->isCanceled()) {
93
+ try {
94
+ $this->_getSync()->syncOrder($order);
95
+ } catch (Exception $e) {
96
+ $this->_getDebug()->debug(
97
+ $this->_getDataHelper()->__(
98
+ 'There was an error while trying to sync current order with Tigo Money. Order: ' .
99
+ $order->getIncrementId() . '. Error: ' . $e->getMessage()
100
+ )
101
+ );
102
+ }
103
+ }
104
+ }
105
+ }
106
+ }
app/code/community/Tigo/TigoMoney/Model/Debug.php ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Tigo_TigoMoney_Model_Debug
5
+ */
6
+ class Tigo_TigoMoney_Model_Debug
7
+ {
8
+ /**
9
+ * Debug file name. Will be available in <magento_root>/var/log/tigomoney.log
10
+ */
11
+ const DEBUG_FILE_NAME = 'tigomoney.log';
12
+
13
+ /**
14
+ * Data Helper
15
+ * @var null|Tigo_TigoMoney_Helper_Data
16
+ */
17
+ protected $_dataHelper = null;
18
+
19
+ /**
20
+ * Debug Mode On?
21
+ * @var null|bool
22
+ */
23
+ protected $_debugMode= null;
24
+
25
+ /**
26
+ * Writes info to debug file
27
+ * @param string|array $value
28
+ */
29
+ public function debug($value) {
30
+ if ($this->_isDebugMode()) {
31
+ if (is_array($value)) {
32
+ $this->debug(print_r($value, true));
33
+ } else if (!is_object($value)) {
34
+ $this->_writeLog($value);
35
+ }
36
+ }
37
+ }
38
+
39
+ /**
40
+ * Data Helper Getter
41
+ * @return Tigo_TigoMoney_Helper_Data
42
+ */
43
+ protected function _getDataHelper()
44
+ {
45
+ if ($this->_dataHelper === null) {
46
+ $this->_dataHelper = Mage::helper('tigo_tigomoney');
47
+ }
48
+ return $this->_dataHelper;
49
+ }
50
+
51
+ /**
52
+ * Are we in debug mode?
53
+ * @return boolean
54
+ */
55
+ protected function _isDebugMode()
56
+ {
57
+ if ($this->_debugMode === null) {
58
+ $this->_debugMode = (bool) $this->_getDataHelper()->isDebugModeEnabled();
59
+ }
60
+ return $this->_debugMode;
61
+ }
62
+
63
+ /**
64
+ * Writes value to log
65
+ * @param $value
66
+ */
67
+ protected function _writeLog($value)
68
+ {
69
+ Mage::log((string) $value, null, self::DEBUG_FILE_NAME);
70
+ }
71
+ }
app/code/community/Tigo/TigoMoney/Model/Observer/AdminOrderView.php ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Tigo_TigoMoney_Model_Observer_AdminOrderView
5
+ */
6
+ class Tigo_TigoMoney_Model_Observer_AdminOrderView
7
+ {
8
+ /**
9
+ * Button Label
10
+ */
11
+ const BUTTON_CLASS = 'go';
12
+
13
+ /**
14
+ * Button Label
15
+ */
16
+ const BUTTON_LABEL = 'Sync With Tigo Money';
17
+
18
+ /**
19
+ * Current Order
20
+ * @var null|Mage_Sales_Model_Order
21
+ */
22
+ protected $_currentOrder = null;
23
+
24
+ /**
25
+ * Data Helper
26
+ * @var null|Tigo_TigoMoney_Helper_Data
27
+ */
28
+ protected $_dataHelper = null;
29
+
30
+ /**
31
+ * Adds a Sync With Tigo Money button to the order admin view
32
+ * @param $observer
33
+ * @return $this
34
+ */
35
+ public function addSyncButton($observer)
36
+ {
37
+ /** @var Mage_Adminhtml_Block_Sales_Order_View $block */
38
+ $block = $this->_getSalesOrderEditBlock();
39
+
40
+ if (!$block){
41
+ return $this;
42
+ }
43
+
44
+ $order = $this->_getCurrentOrder();
45
+
46
+ if ($this->_shouldShowButton($order)) {
47
+ $url = $this->_getDataHelper()->getSyncOrderUrl($order);
48
+
49
+ $block->addButton('tigo_tigomoney_sync', array(
50
+ 'label' => $this->_getDataHelper()->__(self::BUTTON_LABEL),
51
+ 'onclick' => 'setLocation(\'' . $url . '\')',
52
+ 'class' => self::BUTTON_CLASS
53
+ ));
54
+ }
55
+ return $this;
56
+ }
57
+
58
+ /**
59
+ * Retrieves current order from registry
60
+ * @return Mage_Sales_Model_Order
61
+ */
62
+ protected function _getCurrentOrder()
63
+ {
64
+ if ($this->_currentOrder === null) {
65
+ $this->_currentOrder = Mage::registry('current_order');
66
+ }
67
+ return $this->_currentOrder;
68
+ }
69
+
70
+ /**
71
+ * Retrieves current order from registry
72
+ * @return Tigo_TigoMoney_Helper_Data
73
+ */
74
+ protected function _getDataHelper()
75
+ {
76
+ if ($this->_dataHelper === null) {
77
+ $this->_dataHelper = Mage::helper('tigo_tigomoney');
78
+ }
79
+ return $this->_dataHelper;
80
+ }
81
+
82
+ /**
83
+ * Gets Sales Order Edit Block from Layout
84
+ * @return Mage_Adminhtml_Block_Sales_Order_View
85
+ */
86
+ protected function _getSalesOrderEditBlock()
87
+ {
88
+ return Mage::app()->getLayout()->getBlock('sales_order_edit');
89
+ }
90
+
91
+ /**
92
+ * Should we show the Sync Button?
93
+ * @param mixed $order
94
+ * @return bool
95
+ */
96
+ protected function _shouldShowButton($order)
97
+ {
98
+ return (
99
+ $order &&
100
+ $order instanceof Mage_Sales_Model_Order &&
101
+ $order->getId() &&
102
+ $order->getPayment()->getMethod() == Tigo_TigoMoney_Model_Payment_Redirect::METHOD_CODE &&
103
+ $order->getStatus() == 'pending'
104
+ );
105
+ }
106
+ }
app/code/community/Tigo/TigoMoney/Model/Payment/Redirect.php ADDED
@@ -0,0 +1,366 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Tigo_TigoMoney_Model_Payment_Redirect
5
+ */
6
+ class Tigo_TigoMoney_Model_Payment_Redirect extends Mage_Payment_Model_Method_Abstract
7
+ {
8
+ /**
9
+ * Additional Information Key - Access Token
10
+ */
11
+ const ADDITIONAL_INFO_KEY_ACCESS_TOKEN = 'tigomoney_redirect_access_token';
12
+ /**
13
+ * Additional Information Key - Access Token
14
+ */
15
+ const ADDITIONAL_INFO_KEY_ACCESS_TOKEN_ERRORS = 'tigomoney_redirect_access_token_errors';
16
+ /**
17
+ * Additional Information Key - Auth Code
18
+ */
19
+ const ADDITIONAL_INFO_KEY_AUTH_CODE = 'tigomoney_redirect_auth_code';
20
+ /**
21
+ * Additional Information Key - Authorization Errors
22
+ */
23
+ const ADDITIONAL_INFO_KEY_AUTHORIZATION_ERRORS = 'tigomoney_redirect_authorization_errors';
24
+
25
+ /**
26
+ * Additional Information Key - Redirect Uri
27
+ */
28
+ const ADDITIONAL_INFO_KEY_MFS_TRANSACTION_ID = 'tigomoney_mfs_transaction_id';
29
+
30
+ /**
31
+ * Additional Information Key - Tigo Phone Number
32
+ */
33
+ const ADDITIONAL_INFO_KEY_PHONE_NUMBER = 'tigomoney_phone_number';
34
+
35
+ /**
36
+ * Additional Information Key - Redirect Uri
37
+ */
38
+ const ADDITIONAL_INFO_KEY_REDIRECT_URI = 'tigomoney_redirect_uri';
39
+
40
+ /**
41
+ * Additional Information Key - Transaction Code
42
+ */
43
+ const ADDITIONAL_INFO_KEY_TRANSACTION_CODE = 'tigomoney_transaction_code';
44
+
45
+ /**
46
+ * Additional Information Key - Transaction Description
47
+ */
48
+ const ADDITIONAL_INFO_KEY_TRANSACTION_DESCRIPTION = 'tigomoney_transaction_description';
49
+
50
+ /**
51
+ * Additional Information Key - Transaction Status
52
+ */
53
+ const ADDITIONAL_INFO_KEY_TRANSACTION_STATUS = 'tigomoney_transaction_status';
54
+
55
+ /**
56
+ * Payment method code
57
+ */
58
+ const METHOD_CODE = 'tigo_tigomoney';
59
+
60
+ /**
61
+ * Can Authorize
62
+ * @var bool
63
+ */
64
+ protected $_canAuthorize = true;
65
+
66
+ /**
67
+ * Can Capture
68
+ * @var bool
69
+ */
70
+ protected $_canCapture = true;
71
+
72
+ /**
73
+ * This is not a recurring payment method
74
+ * @var bool
75
+ */
76
+ protected $_canManageRecurringProfiles = false;
77
+
78
+ /**
79
+ * Can order
80
+ * @var bool
81
+ */
82
+ protected $_canOrder = false;
83
+
84
+ /**
85
+ * Refund method is available
86
+ * @var bool
87
+ */
88
+ protected $_canRefund = true;
89
+
90
+ /**
91
+ * Can't Refund partial transactions, only full ones
92
+ * @var bool
93
+ */
94
+ protected $_canRefundInvoicePartial = false;
95
+
96
+ /**
97
+ * Can be used in frontend checkout
98
+ * @var bool
99
+ */
100
+ protected $_canUseCheckout = true;
101
+
102
+ /**
103
+ * This payment method depends on the user to access his account on Tigo, we
104
+ * won't need it in the admin
105
+ * @var bool
106
+ */
107
+ protected $_canUseInternal = false;
108
+
109
+ /**
110
+ * Payment method code
111
+ * @var string
112
+ */
113
+ protected $_code = self::METHOD_CODE;
114
+
115
+ /**
116
+ * Data Helper
117
+ * @var null|Tigo_TigoMoney_Helper_Data
118
+ */
119
+ protected $_dataHelper = null;
120
+
121
+ /**
122
+ * Payment Method Form Block
123
+ * @var string
124
+ */
125
+ protected $_infoBlockType = 'tigo_tigomoney/payment_redirect_info';
126
+
127
+ /**
128
+ * Payment Method Form Block
129
+ * @var string
130
+ */
131
+ protected $_formBlockType = 'tigo_tigomoney/payment_redirect_form';
132
+
133
+ /**
134
+ * Is this payment method a payment gateway?
135
+ * @var bool
136
+ */
137
+ protected $_isGateway = true;
138
+
139
+ /**
140
+ * Redirect Api
141
+ * @var null|Tigo_TigoMoney_Model_Payment_Redirect_Api
142
+ */
143
+ protected $_redirectApi = null;
144
+
145
+ /**
146
+ * Request Builder
147
+ * @var null|Tigo_TigoMoney_Model_Payment_Redirect_Api_RequestBuilder
148
+ */
149
+ protected $_requestBuilder= null;
150
+
151
+
152
+ /**
153
+ * Assigns form data to payment info
154
+ * @param mixed $data
155
+ * @return $this
156
+ */
157
+ public function assignData($data)
158
+ {
159
+ parent::assignData($data);
160
+
161
+ if (!($data instanceof Varien_Object)) {
162
+ $data = new Varien_Object($data);
163
+ }
164
+
165
+ if ($data->getMethod() != self::METHOD_CODE) {
166
+ return $this;
167
+ }
168
+
169
+ $phoneNumber = $data->getData(self::METHOD_CODE . '_phone_number');
170
+ $this
171
+ ->getInfoInstance()
172
+ ->setAdditionalInformation(self::ADDITIONAL_INFO_KEY_PHONE_NUMBER, $phoneNumber);
173
+
174
+ return $this;
175
+ }
176
+
177
+ /**
178
+ * Payment authorization, gets redirect URL from API
179
+ * @param Varien_Object $payment
180
+ * @param float $amount
181
+ * @return $this
182
+ * @throws Mage_Core_Exception
183
+ */
184
+ public function authorize(Varien_Object $payment, $amount)
185
+ {
186
+ /** @var Mage_Sales_Model_Order_Payment $payment */
187
+ $order = $payment->getOrder();
188
+
189
+ $accessTokenRequest = $this->_getRequestBuilder()->buildGenerateAccessTokenRequest();
190
+ $accessTokenResponse = $this->_getRedirectApi()->getAccessToken($accessTokenRequest);
191
+
192
+ if ($accessTokenResponse->isSuccess()) {
193
+ $authorizationRequest = $this->_getRequestBuilder()->buildAuthorizationRequest(
194
+ $accessTokenResponse->getAccessToken(),
195
+ $order
196
+ );
197
+ $authorizationResponse = $this->_getRedirectApi()->getRedirectUri($authorizationRequest);
198
+
199
+ if ($authorizationResponse->isSuccess()) {
200
+ $payment
201
+ ->setAmount($amount)
202
+ ->setStatus(self::STATUS_APPROVED)
203
+ ->setIsTransactionPending(false)
204
+ ->setIsTransactionClosed(false)
205
+ ->setTransactionId($authorizationResponse->getAuthCode())
206
+ ->setAdditionalInformation(
207
+ self::ADDITIONAL_INFO_KEY_ACCESS_TOKEN,
208
+ $accessTokenResponse->getAccessToken()
209
+ )
210
+ ->setAdditionalInformation(
211
+ self::ADDITIONAL_INFO_KEY_REDIRECT_URI,
212
+ $authorizationResponse->getRedirectUri()
213
+ )
214
+ ->setAdditionalInformation(
215
+ self::ADDITIONAL_INFO_KEY_AUTH_CODE,
216
+ $authorizationResponse->getAuthCode()
217
+ )
218
+ ->save();
219
+ } else {
220
+ $payment
221
+ ->setAdditionalInformation(
222
+ self::ADDITIONAL_INFO_KEY_AUTHORIZATION_ERRORS,
223
+ implode('\n', $authorizationResponse->getErrors())
224
+ )
225
+ ->save();
226
+ Mage::throwException(
227
+ $this->_getDataHelper()->__('There was an error while trying to complete your payment')
228
+ );
229
+ }
230
+ } else {
231
+ $payment
232
+ ->setAdditionalInformation(
233
+ self::ADDITIONAL_INFO_KEY_ACCESS_TOKEN_ERRORS,
234
+ implode('\n', $accessTokenResponse->getErrors())
235
+ )
236
+ ->save();
237
+ Mage::throwException(
238
+ $this->_getDataHelper()->__('There was an error while trying to complete your payment')
239
+ );
240
+ }
241
+
242
+ return $this;
243
+ }
244
+
245
+ /**
246
+ * Capture payment, necessary for refund operation to be available
247
+ * @param Varien_Object $payment
248
+ * @param float $amount
249
+ * @return bool
250
+ */
251
+ public function capture(Varien_Object $payment, $amount)
252
+ {
253
+ /** @var Mage_Sales_Model_Order_Payment $payment */
254
+ $payment
255
+ ->setAmount($amount)
256
+ ->setStatus(self::STATUS_SUCCESS)
257
+ ->setTransactionId($payment->getTransactionId())
258
+ ->setIsTransactionClosed(true)
259
+ ->save();
260
+ return true;
261
+ }
262
+
263
+ /**
264
+ * Data Helper Getter
265
+ * @return Tigo_TigoMoney_Helper_Data
266
+ */
267
+ protected function _getDataHelper()
268
+ {
269
+ if ($this->_dataHelper === null) {
270
+ $this->_dataHelper = Mage::helper('tigo_tigomoney');
271
+ }
272
+ return $this->_dataHelper;
273
+ }
274
+
275
+ /**
276
+ * Url to redirect the user after checkout is finished
277
+ * This route will be responsible for forwarding the customer to the Tigo Money Payment Server
278
+ * @return string
279
+ */
280
+ public function getOrderPlaceRedirectUrl()
281
+ {
282
+ return $this->_getDataHelper()->getInternalRedirectUri();
283
+ }
284
+
285
+ /**
286
+ * Returns Redirect Api Instance
287
+ * @return Tigo_TigoMoney_Model_Payment_Redirect_Api
288
+ */
289
+ protected function _getRedirectApi()
290
+ {
291
+ if ($this->_redirectApi === null) {
292
+ $this->_redirectApi = Mage::getModel('tigo_tigomoney/payment_redirect_api');
293
+ }
294
+ return $this->_redirectApi;
295
+ }
296
+
297
+ /**
298
+ * Returns Request Builder Instance
299
+ * @return Tigo_TigoMoney_Model_Payment_Redirect_Api_RequestBuilder
300
+ */
301
+ protected function _getRequestBuilder()
302
+ {
303
+ if ($this->_requestBuilder === null) {
304
+ $this->_requestBuilder = Mage::getModel('tigo_tigomoney/payment_redirect_api_requestBuilder');
305
+ }
306
+ return $this->_requestBuilder;
307
+ }
308
+
309
+ /**
310
+ * Is method available?
311
+ * @param null $quote
312
+ * @return bool
313
+ */
314
+ public function isAvailable($quote = null)
315
+ {
316
+ $isAvailable = parent::isAvailable($quote);
317
+
318
+ if ($isAvailable) {
319
+ if ($this->_getDataHelper()->getClientId() && $this->_getDataHelper()->getClientSecret() &&
320
+ $this->_getDataHelper()->getMerchantAccount() && $this->_getDataHelper()->getMerchantPin()
321
+ ) {
322
+ $isAvailable = true;
323
+ } else {
324
+ $isAvailable = false;
325
+ }
326
+ }
327
+
328
+ return $isAvailable;
329
+ }
330
+
331
+ /**
332
+ * Refunds order, calling the Payment Server API and reversing the transaction
333
+ * @param Varien_Object $payment
334
+ * @param float $amount
335
+ * @return $this
336
+ */
337
+ public function refund(Varien_Object $payment, $amount)
338
+ {
339
+ /** @var Mage_Sales_Model_Order_Payment $payment */
340
+ $order = $payment->getOrder();
341
+ $accessTokenRequest = $this->_getRequestBuilder()->buildGenerateAccessTokenRequest();
342
+ $accessTokenResponse = $this->_getRedirectApi()->getAccessToken($accessTokenRequest);
343
+
344
+ if ($accessTokenResponse->isSuccess()) {
345
+ $reverseRequest = $this->_getRequestBuilder()->buildReverseTransactionRequest(
346
+ $accessTokenResponse->getAccessToken(),
347
+ $order
348
+ );
349
+ $reverseResponse = $this->_getRedirectApi()->reverseTransaction($reverseRequest);
350
+ if ($reverseResponse->isSuccess()) {
351
+ $payment->setTransactionId($reverseResponse->getTransactionMfsReverseTransactionId());
352
+ $payment->addTransaction(Mage_Sales_Model_Order_Payment_Transaction::TYPE_REFUND);
353
+ } else {
354
+ Mage::throwException(
355
+ $this->_getDataHelper()->__('There was an error while trying to refund this order')
356
+ );
357
+ }
358
+ } else {
359
+ Mage::throwException(
360
+ $this->_getDataHelper()->__('There was an error while trying to refund this order')
361
+ );
362
+ }
363
+
364
+ return $this;
365
+ }
366
+ }
app/code/community/Tigo/TigoMoney/Model/Payment/Redirect/Api.php ADDED
@@ -0,0 +1,395 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Tigo_TigoMoney_Model_Payment_Redirect_Api
5
+ */
6
+ class Tigo_TigoMoney_Model_Payment_Redirect_Api
7
+ {
8
+ /**
9
+ * Tigo Payment Server Endpoint URL - Production
10
+ */
11
+ const PROD_ENVIRONMENT_DOMAIN = 'https://prod.api.tigo.com/';
12
+
13
+ /**
14
+ * Tigo Payment Server Endpoint URL - Test
15
+ */
16
+ const TEST_ENVIRONMENT_DOMAIN = 'https://securesandbox.tigo.com/';
17
+
18
+ /**
19
+ * Core Helper
20
+ * @var null|Mage_Core_Helper_Data
21
+ */
22
+ protected $_coreHelper = null;
23
+
24
+ /**
25
+ * Data Helper
26
+ * @var null|Tigo_TigoMoney_Helper_Data
27
+ */
28
+ protected $_dataHelper = null;
29
+
30
+ /**
31
+ * Debug Model
32
+ * @var null|Tigo_TigoMoney_Helper_Data
33
+ */
34
+ protected $_debug = null;
35
+
36
+ /**
37
+ * Writes info to debug file
38
+ * @param string $value
39
+ */
40
+ protected function _debug($value)
41
+ {
42
+ $this->_getDebug()->debug($value);
43
+ }
44
+
45
+ /**
46
+ * Fetches a value from given array, checking for its' existence
47
+ * @param array $array
48
+ * @param string $key
49
+ * @param string|null $subKey
50
+ * @return mixed
51
+ */
52
+ protected function _fetchResponseValue($array, $key, $subKey = null)
53
+ {
54
+ $return = null;
55
+
56
+ if (array_key_exists($key, $array)) {
57
+ $return = $array[$key];
58
+ if ($subKey !== null) {
59
+ if (array_key_exists($subKey, $return)) {
60
+ $return = $return[$subKey];
61
+ } else {
62
+ $return = null;
63
+ }
64
+ }
65
+ }
66
+
67
+ return $return;
68
+ }
69
+
70
+ /**
71
+ * Queries the Tigo Money Payment Server for an Access Token
72
+ * @param Tigo_TigoMoney_Model_Payment_Redirect_Api_GenerateTokenRequest $request
73
+ * @return Tigo_TigoMoney_Model_Payment_Redirect_Api_GenerateTokenResponse
74
+ */
75
+ public function getAccessToken(Tigo_TigoMoney_Model_Payment_Redirect_Api_GenerateTokenRequest $request)
76
+ {
77
+ $return = $this->_getGenerateTokenResponseInstance();
78
+
79
+ if (!$request->validate()) {
80
+ Mage::throwException($this->_getDataHelper()->__('Invalid Parameters Sent to Generate Token Request.'));
81
+ }
82
+
83
+ $httpResponse = $this->_makeRequest(
84
+ $this->_getEndpointUrl($request),
85
+ $request->getMethod(),
86
+ $request->getHeaders(),
87
+ $request->getBody()
88
+ );
89
+ $httpResponseArray = (array) $this->_getCoreHelper()->jsonDecode($httpResponse->getBody());
90
+
91
+ if ($httpResponse->getStatus() == 200) {
92
+ $return->setAccessToken((string) $this->_fetchResponseValue($httpResponseArray, 'accessToken'));
93
+ } else {
94
+ $return->addError((string) $this->_fetchResponseValue($httpResponseArray, 'error_description'));
95
+ }
96
+ return $return;
97
+ }
98
+
99
+ /**
100
+ * Instantiates a new Authorization response object
101
+ * @return Tigo_TigoMoney_Model_Payment_Redirect_Api_AuthorizationResponse
102
+ */
103
+ protected function _getAuthorizationResponseInstance()
104
+ {
105
+ return Mage::getModel(
106
+ 'tigo_tigomoney/payment_redirect_api_authorizationResponse',
107
+ new Varien_Object()
108
+ );
109
+ }
110
+
111
+ /**
112
+ * Core Helper Getter
113
+ * @return Mage_Core_Helper_Data
114
+ */
115
+ protected function _getCoreHelper()
116
+ {
117
+ if ($this->_coreHelper === null) {
118
+ $this->_coreHelper = Mage::helper('core');
119
+ }
120
+ return $this->_coreHelper;
121
+ }
122
+
123
+ /**
124
+ * Data Helper Getter
125
+ * @return Tigo_TigoMoney_Helper_Data
126
+ */
127
+ protected function _getDataHelper()
128
+ {
129
+ if ($this->_dataHelper === null) {
130
+ $this->_dataHelper = Mage::helper('tigo_tigomoney');
131
+ }
132
+ return $this->_dataHelper;
133
+ }
134
+
135
+ /**
136
+ * Debug Model Getter
137
+ * @return Tigo_TigoMoney_Model_Debug
138
+ */
139
+ protected function _getDebug()
140
+ {
141
+ if ($this->_debug === null) {
142
+ $this->_debug = Mage::getModel('tigo_tigomoney/debug');
143
+ }
144
+ return $this->_debug;
145
+ }
146
+
147
+ /**
148
+ * Returns URL for the access token endpoint
149
+ * @param Tigo_TigoMoney_Model_Payment_Redirect_Api_RequestInterface $request
150
+ * @return string
151
+ */
152
+ protected function _getEndpointUrl(Tigo_TigoMoney_Model_Payment_Redirect_Api_RequestInterface $request)
153
+ {
154
+ return $this->_getEndpointDomain() . $request->getEndpointPath();
155
+ }
156
+
157
+ /**
158
+ * Returns domain for the endpoint to be used, based on test mode being
159
+ * enabled or not
160
+ * @return string
161
+ */
162
+ protected function _getEndpointDomain()
163
+ {
164
+ if ($this->isTestMode()) {
165
+ $return = self::TEST_ENVIRONMENT_DOMAIN;
166
+ } else {
167
+ $return = self::PROD_ENVIRONMENT_DOMAIN;
168
+ }
169
+ return $return;
170
+ }
171
+
172
+ /**
173
+ * Instantiates a new Generate Token response object
174
+ * @return Tigo_TigoMoney_Model_Payment_Redirect_Api_GenerateTokenResponse
175
+ */
176
+ protected function _getGenerateTokenResponseInstance()
177
+ {
178
+ return Mage::getModel(
179
+ 'tigo_tigomoney/payment_redirect_api_generateTokenResponse',
180
+ new Varien_Object()
181
+ );
182
+ }
183
+
184
+ /**
185
+ * Returns a new HTTP client instance
186
+ * @return Zend_Http_Client
187
+ */
188
+ protected function _getHttpClient()
189
+ {
190
+ return new Zend_Http_Client(null, array('timeout'=> 30));
191
+ }
192
+
193
+ /**
194
+ * Connects to API and retrieves redirect payment url for given order
195
+ * @param Tigo_TigoMoney_Model_Payment_Redirect_Api_AuthorizationRequest $request
196
+ * @return Tigo_TigoMoney_Model_Payment_Redirect_Api_AuthorizationResponse
197
+ * @throws Mage_Core_Exception
198
+ */
199
+ public function getRedirectUri(Tigo_TigoMoney_Model_Payment_Redirect_Api_AuthorizationRequest $request)
200
+ {
201
+ $return = $this->_getAuthorizationResponseInstance();
202
+
203
+ if (!$request->validate()) {
204
+ Mage::throwException($this->_getDataHelper()->__('Invalid Parameters Sent to Authorization Request.'));
205
+ }
206
+
207
+ $httpResponse = $this->_makeRequest(
208
+ $this->_getEndpointUrl($request),
209
+ $request->getMethod(),
210
+ $request->getHeaders(),
211
+ $request->getBody()
212
+ );
213
+
214
+ $httpResponseArray = (array) $this->_getCoreHelper()->jsonDecode($httpResponse->getBody());
215
+
216
+ if ($httpResponse->getStatus() == 200) {
217
+ $return
218
+ ->setAuthCode((string) $this->_fetchResponseValue($httpResponseArray, 'authCode'))
219
+ ->setRedirectUri((string) $this->_fetchResponseValue($httpResponseArray, 'redirectUrl'));
220
+ } else {
221
+ $return->addError((string) $this->_fetchResponseValue($httpResponseArray, 'error_description'));
222
+ }
223
+
224
+ return $return;
225
+ }
226
+
227
+ /**
228
+ * Instantiates a new Reverse Transaction response object
229
+ * @return Tigo_TigoMoney_Model_Payment_Redirect_Api_ReverseTransactionResponse
230
+ */
231
+ protected function _getReverseTransactionResponseInstance()
232
+ {
233
+ return Mage::getModel(
234
+ 'tigo_tigomoney/payment_redirect_api_reverseTransactionResponse',
235
+ new Varien_Object()
236
+ );
237
+ }
238
+
239
+ /**
240
+ * Queries the Tigo Money Payment Server for a transaction status
241
+ * @param Tigo_TigoMoney_Model_Payment_Redirect_Api_TransactionStatusRequest $request
242
+ * @return Tigo_TigoMoney_Model_Payment_Redirect_Api_TransactionStatusResponse
243
+ */
244
+ public function getTransactionStatus(Tigo_TigoMoney_Model_Payment_Redirect_Api_TransactionStatusRequest $request)
245
+ {
246
+ $return = $this->_getTransactionStatusResponseInstance();
247
+
248
+ if (!$request->validate()) {
249
+ Mage::throwException($this->_getDataHelper()->__('Invalid Parameters Sent to Transaction Status Request.'));
250
+ }
251
+
252
+ $httpResponse = $this->_makeRequest(
253
+ $this->_getEndpointUrl($request),
254
+ $request->getMethod(),
255
+ $request->getHeaders(),
256
+ $request->getBody()
257
+ );
258
+ $httpResponseArray = (array) $this->_getCoreHelper()->jsonDecode($httpResponse->getBody());
259
+
260
+ if ($httpResponse->getStatus() == 200) {
261
+ $return->setTransactionMerchantTransactionId($this->_fetchResponseValue($httpResponseArray, 'Transaction', 'merchantTransactionId'));
262
+ $return->setTransactionMfsTransactionId($this->_fetchResponseValue($httpResponseArray, 'Transaction', 'mfsTransactionId'));
263
+ $return->setTransactionCreatedOn($this->_fetchResponseValue($httpResponseArray, 'Transaction', 'createdOn'));
264
+ $return->setTransactionStatus($this->_fetchResponseValue($httpResponseArray, 'Transaction', 'status'));
265
+ $return->setTransactionCompletedOn($this->_fetchResponseValue($httpResponseArray, 'Transaction', 'completedOn'));
266
+ $return->setMasterMerchantAccount($this->_fetchResponseValue($httpResponseArray, 'MasterMerchant', 'account'));
267
+ $return->setMasterMerchantId($this->_fetchResponseValue($httpResponseArray, 'MasterMerchant', 'id'));
268
+ $return->setMerchantReference($this->_fetchResponseValue($httpResponseArray, 'Merchant', 'reference'));
269
+ $return->setMerchantFee($this->_fetchResponseValue($httpResponseArray, 'Merchant', 'fee'));
270
+ $return->setMerchantCurrencyCode($this->_fetchResponseValue($httpResponseArray, 'Merchant', 'currencyCode'));
271
+ $return->setSubscriberAccount($this->_fetchResponseValue($httpResponseArray, 'Subscriber', 'account'));
272
+ $return->setSubscriberCountryCode($this->_fetchResponseValue($httpResponseArray, 'Subscriber', 'countryCode'));
273
+ $return->setSubscriberCountry($this->_fetchResponseValue($httpResponseArray, 'Subscriber', 'country'));
274
+ $return->setSubscriberFirstName($this->_fetchResponseValue($httpResponseArray, 'Subscriber', 'firstName'));
275
+ $return->setSubscriberLastName($this->_fetchResponseValue($httpResponseArray, 'Subscriber', 'lastName'));
276
+ $return->setSubscriberEmail($this->_fetchResponseValue($httpResponseArray, 'Subscriber', 'emailId'));
277
+ $return->setRedirectUri($this->_fetchResponseValue($httpResponseArray, 'redirectUri'));
278
+ $return->setCallbackUri($this->_fetchResponseValue($httpResponseArray, 'callbackUri'));
279
+ $return->setLanguage($this->_fetchResponseValue($httpResponseArray, 'language'));
280
+ $return->setTerminalId($this->_fetchResponseValue($httpResponseArray, 'terminalId'));
281
+ $return->setExchangeRate($this->_fetchResponseValue($httpResponseArray, 'exchangeRate'));
282
+ $return->setOriginPaymentAmount($this->_fetchResponseValue($httpResponseArray, 'OriginPayment', 'amount'));
283
+ $return->setOriginPaymentCurrencyCode($this->_fetchResponseValue($httpResponseArray, 'OriginPayment', 'currencyCode'));
284
+ $return->setOriginPaymentTax($this->_fetchResponseValue($httpResponseArray, 'OriginPayment', 'tax'));
285
+ $return->setOriginPaymentFee($this->_fetchResponseValue($httpResponseArray, 'OriginPayment', 'fee'));
286
+ $return->setLocalPaymentAmount($this->_fetchResponseValue($httpResponseArray, 'LocalPayment', 'amount'));
287
+ $return->setLocalPaymentCurrencyCode($this->_fetchResponseValue($httpResponseArray, 'LocalPayment', 'currencyCode'));
288
+ } else {
289
+ $return->addError((string) $this->_fetchResponseValue($httpResponseArray, 'error_description'));
290
+ }
291
+ return $return;
292
+ }
293
+
294
+ /**
295
+ * Instantiates a new Transaction Status response object
296
+ * @return Tigo_TigoMoney_Model_Payment_Redirect_Api_TransactionStatusResponse
297
+ */
298
+ protected function _getTransactionStatusResponseInstance()
299
+ {
300
+ return Mage::getModel(
301
+ 'tigo_tigomoney/payment_redirect_api_transactionStatusResponse',
302
+ new Varien_Object()
303
+ );
304
+ }
305
+
306
+ /**
307
+ * Are we in test mode?
308
+ * @return boolean
309
+ */
310
+ public function isTestMode()
311
+ {
312
+ return $this->_getDataHelper()->isTestModeEnabled();
313
+ }
314
+
315
+ /**
316
+ * Makes a HTTP request, returns the response as a string
317
+ * @param string $url
318
+ * @param string $method
319
+ * @param array $headers
320
+ * @param string $body
321
+ * @return Zend_Http_Response
322
+ */
323
+ protected function _makeRequest($url, $method, $headers, $body)
324
+ {
325
+ $this->_debug('---- Request ---');
326
+ $this->_debug('Url: ' . $url);
327
+ $this->_debug('Method: ' . $method);
328
+ $this->_debug('Headers: ' . var_export($headers, true));
329
+ $this->_debug('Body: ' . $body);
330
+
331
+ $client = $this->_getHttpClient();
332
+ $client
333
+ ->setUri($url)
334
+ ->setHeaders($headers)
335
+ ->setRawData($body)
336
+ ->setMethod($method);
337
+
338
+ $response = $client->request();
339
+
340
+ $this->_debug('---- Response ---');
341
+ $this->_debug('Status: ' . $response->getStatus());
342
+ $this->_debug('Body: ' . $response->getBody());
343
+
344
+ return $response;
345
+ }
346
+
347
+ /**
348
+ * Connects to API and reverses transaction for given order
349
+ * @param Tigo_TigoMoney_Model_Payment_Redirect_Api_ReverseTransactionRequest $request
350
+ * @return Tigo_TigoMoney_Model_Payment_Redirect_Api_ReverseTransactionResponse
351
+ * @throws Mage_Core_Exception
352
+ */
353
+ public function reverseTransaction(Tigo_TigoMoney_Model_Payment_Redirect_Api_ReverseTransactionRequest $request)
354
+ {
355
+ $return = $this->_getReverseTransactionResponseInstance();
356
+
357
+ if (!$request->validate()) {
358
+ Mage::throwException($this->_getDataHelper()->__('Invalid Parameters Sent to Reverse Request.'));
359
+ }
360
+
361
+ $httpResponse = $this->_makeRequest(
362
+ $this->_getEndpointUrl($request),
363
+ $request->getMethod(),
364
+ $request->getHeaders(),
365
+ $request->getBody()
366
+ );
367
+
368
+ $httpResponseArray = (array) $this->_getCoreHelper()->jsonDecode($httpResponse->getBody());
369
+
370
+ if ($httpResponse->getStatus() == 200) {
371
+ $return
372
+ ->setStatus((string) $this->_fetchResponseValue($httpResponseArray, 'status'))
373
+ ->setTransactionMerchantTransactionId((string) $this->_fetchResponseValue($httpResponseArray, 'Transaction', 'merchantTransactionId'))
374
+ ->setTransactionCorrelationId((string) $this->_fetchResponseValue($httpResponseArray, 'Transaction', 'correlationId'))
375
+ ->setTransactionMfsTransactionId((string) $this->_fetchResponseValue($httpResponseArray, 'Transaction', 'mfsTransactionId'))
376
+ ->setTransactionMfsReverseTransactionId((string) $this->_fetchResponseValue($httpResponseArray, 'Transaction', 'mfsReverseTransactionId'))
377
+ ->setTransactionStatus((string) $this->_fetchResponseValue($httpResponseArray, 'Transaction', 'status'))
378
+ ->setTransactionMessage((string) $this->_fetchResponseValue($httpResponseArray, 'Transaction', 'message'));
379
+ } else {
380
+ $return
381
+ ->setStatus((string) $this->_fetchResponseValue($httpResponseArray, 'status'))
382
+ ->setTransactionMerchantTransactionId((string) $this->_fetchResponseValue($httpResponseArray, 'Transaction', 'merchantTransactionId'))
383
+ ->setTransactionCorrelationId((string) $this->_fetchResponseValue($httpResponseArray, 'Transaction', 'correlationId'))
384
+ ->setTransactionMfsTransactionId((string) $this->_fetchResponseValue($httpResponseArray, 'Transaction', 'mfsTransactionId'))
385
+ ->setTransactionStatus((string) $this->_fetchResponseValue($httpResponseArray, 'Transaction', 'status'))
386
+ ->setTransactionMessage((string) $this->_fetchResponseValue($httpResponseArray, 'Transaction', 'message'))
387
+ ->setError((string) $this->_fetchResponseValue($httpResponseArray, 'error'))
388
+ ->setErrorType((string) $this->_fetchResponseValue($httpResponseArray, 'error_type'))
389
+ ->setErrorDescription((string) $this->_fetchResponseValue($httpResponseArray, 'error_description'));
390
+ $return->addError((string) $this->_fetchResponseValue($httpResponseArray, 'error_description'));
391
+ }
392
+
393
+ return $return;
394
+ }
395
+ }
app/code/community/Tigo/TigoMoney/Model/Payment/Redirect/Api/AbstractResponse.php ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Tigo_TigoMoney_Model_Payment_Redirect_Api_AbstractResponse
5
+ */
6
+ abstract class Tigo_TigoMoney_Model_Payment_Redirect_Api_AbstractResponse implements
7
+ Tigo_TigoMoney_Model_Payment_Redirect_Api_ResponseInterface
8
+ {
9
+ /**
10
+ * Errors that happened during the request
11
+ * @var array
12
+ */
13
+ protected $_errors = array();
14
+
15
+ /**
16
+ * Was there an error in the request?
17
+ * @var bool
18
+ */
19
+ protected $_isError = false;
20
+
21
+ /**
22
+ * Was the transaction successful?
23
+ * @var bool
24
+ */
25
+ protected $_isSuccess = true;
26
+
27
+ /**
28
+ * Response data
29
+ * @var Varien_Object
30
+ */
31
+ protected $_responseData = true;
32
+
33
+ /**
34
+ * Tigo_TigoMoney_Model_Payment_Redirect_Api_Response constructor.
35
+ * @param Varien_Object $responseData
36
+ */
37
+ public function __construct(
38
+ Varien_Object $responseData
39
+ ) {
40
+ $this->_responseData = $responseData;
41
+ }
42
+
43
+ /**
44
+ * @inheritdoc
45
+ */
46
+ public function addError($error)
47
+ {
48
+ $this->_errors[] = trim($error);
49
+ $this->_isSuccess = false;
50
+ $this->_isError = true;
51
+ }
52
+
53
+ /**
54
+ * @inheritdoc
55
+ */
56
+ public function addResponseData($key, $data)
57
+ {
58
+ return $this->_responseData->setData($key, $data);
59
+ }
60
+
61
+ /**
62
+ * @inheritdoc
63
+ */
64
+ public function isError()
65
+ {
66
+ return $this->_isError;
67
+ }
68
+
69
+ /**
70
+ * @inheritdoc
71
+ */
72
+ public function isSuccess()
73
+ {
74
+ return $this->_isSuccess;
75
+ }
76
+
77
+ /**
78
+ * @inheritdoc
79
+ */
80
+ public function getErrors()
81
+ {
82
+ return array_values(array_unique($this->_errors));
83
+ }
84
+
85
+ /**
86
+ * @inheritdoc
87
+ */
88
+ public function getResponseData($key)
89
+ {
90
+ return $this->_responseData->getData($key);
91
+ }
92
+ }
app/code/community/Tigo/TigoMoney/Model/Payment/Redirect/Api/AuthorizationRequest.php ADDED
@@ -0,0 +1,771 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Tigo_TigoMoney_Model_Payment_Redirect_Api_AuthorizationRequest
5
+ */
6
+ class Tigo_TigoMoney_Model_Payment_Redirect_Api_AuthorizationRequest
7
+ implements Tigo_TigoMoney_Model_Payment_Redirect_Api_RequestInterface
8
+ {
9
+ /**
10
+ * Content Type Json for Request Header
11
+ */
12
+ const CONTENT_TYPE_JSON = 'application/json';
13
+
14
+ /**
15
+ * Country Code - El Salvador
16
+ */
17
+ const COUNTRY_CODE = 'SLV';
18
+
19
+ /**
20
+ * Country Dial Code - El Salvador
21
+ */
22
+ const COUNTRY_DIAL_CODE = '503';
23
+
24
+ /**
25
+ * Currency Code - US Dollars
26
+ */
27
+ const CURRENCY_CODE_USD = 'USD';
28
+
29
+ /**
30
+ * Generate Token Enpoint Path
31
+ */
32
+ const ENDPOINT_PATH = 'v2/tigo/mfs/payments/authorizations';
33
+
34
+ /**
35
+ * Language Code - Spanish
36
+ */
37
+ const LANGUAGE_CODE_SPANISH = 'spa';
38
+
39
+ /**
40
+ * Terminal Id - Should be hardcoded to 1
41
+ */
42
+ const TERMINAL_ID = 'Magento';
43
+
44
+ /**
45
+ * Access Token
46
+ * @var null|string
47
+ */
48
+ protected $_accessToken = null;
49
+
50
+ /**
51
+ * Callback Uri
52
+ * @var null|string
53
+ */
54
+ protected $_callbackUri = null;
55
+
56
+ /**
57
+ * Exchange Rate
58
+ * @var null|float
59
+ */
60
+ protected $_exchangeRate = null;
61
+
62
+ /**
63
+ * Language
64
+ * @var null|string
65
+ */
66
+ protected $_language = null;
67
+
68
+ /**
69
+ * Local Payment - Amount
70
+ * @var null|float
71
+ */
72
+ protected $_localPaymentAmount = null;
73
+
74
+ /**
75
+ * Local Payment - Currency Code
76
+ * @var null|string
77
+ */
78
+ protected $_localPaymentCurrencyCode = null;
79
+
80
+ /**
81
+ * Master Merchant - Account
82
+ * @var null|string
83
+ */
84
+ protected $_masterMerchantAccount = null;
85
+
86
+ /**
87
+ * Master Merchant - Pin
88
+ * @var null|string
89
+ */
90
+ protected $_masterMerchantPin = null;
91
+
92
+ /**
93
+ * Master Merchant - Id
94
+ * @var null|string
95
+ */
96
+ protected $_masterMerchantId = null;
97
+
98
+ /**
99
+ * Merchant - Reference
100
+ * @var null|string
101
+ */
102
+ protected $_merchantReference = null;
103
+
104
+ /**
105
+ * Merchant - Transaction Id
106
+ * @var null|string
107
+ */
108
+ protected $_merchantTransactionId = null;
109
+
110
+ /**
111
+ * Merchant - Fee
112
+ * @var null|float
113
+ */
114
+ protected $_merchantFee = null;
115
+
116
+ /**
117
+ * Merchant - Currency Code
118
+ * @var null|string
119
+ */
120
+ protected $_merchantCurrencyCode = null;
121
+
122
+ /**
123
+ * Origin Payment - Amount
124
+ * @var null|float
125
+ */
126
+ protected $_originPaymentAmount = null;
127
+
128
+ /**
129
+ * Origin Payment - Currency Code
130
+ * @var null|string
131
+ */
132
+ protected $_originPaymentCurrencyCode = null;
133
+
134
+ /**
135
+ * Origin Payment - Payment Tax
136
+ * @var null|float
137
+ */
138
+ protected $_originPaymentTax = null;
139
+
140
+ /**
141
+ * Origin Payment - Fee
142
+ * @var null|float
143
+ */
144
+ protected $_originPaymentFee = null;
145
+
146
+ /**
147
+ * Redirect URI
148
+ * @var null|string
149
+ */
150
+ protected $_redirectUri = null;
151
+
152
+ /**
153
+ * Subscriber - Account
154
+ * @var null|string
155
+ */
156
+ protected $_subscriberAccount = null;
157
+
158
+ /**
159
+ * Subscriber - Country Code
160
+ * @var null|string
161
+ */
162
+ protected $_subscriberCountryCode = null;
163
+
164
+ /**
165
+ * Subscriber - Country
166
+ * @var null|string
167
+ */
168
+ protected $_subscriberCountry = null;
169
+
170
+ /**
171
+ * Subscriber - First Name
172
+ * @var null|string
173
+ */
174
+ protected $_subscriberFirstName = null;
175
+
176
+ /**
177
+ * Subscriber - Last Name
178
+ * @var null|string
179
+ */
180
+ protected $_subscriberLastName = null;
181
+
182
+ /**
183
+ * Subscriber - Email
184
+ * @var null|string
185
+ */
186
+ protected $_subscriberEmail = null;
187
+
188
+ /**
189
+ * Terminal Id
190
+ * @var null|string
191
+ */
192
+ protected $_terminalId = null;
193
+
194
+ /**
195
+ * Sets a float to the correct format used by the Tigo Api
196
+ * @param float $value
197
+ * @return string
198
+ */
199
+ protected function _formatFloat($value) {
200
+ return number_format($value, 2, '.', '');
201
+ }
202
+
203
+ /**
204
+ * Access Token - Getter
205
+ * @return null|string
206
+ */
207
+ public function getAccessToken()
208
+ {
209
+ return $this->_accessToken;
210
+ }
211
+
212
+ /**
213
+ * Notice: parameters that are commented out exist in the API but will
214
+ * not be used by this module
215
+ * @inheritdoc
216
+ */
217
+ public function getBody()
218
+ {
219
+ $return = array();
220
+
221
+ $return['MasterMerchant'] = array();
222
+ $return['MasterMerchant']['account'] = $this->getMasterMerchantAccount();
223
+ $return['MasterMerchant']['pin'] = $this->getMasterMerchantPin();
224
+ $return['MasterMerchant']['id'] = $this->getMasterMerchantId();
225
+
226
+ if ($this->_shouldSendMerchantInfo()) {
227
+ $return['Merchant'] = array();
228
+ $return['Merchant']['reference'] = $this->getMerchantReference();
229
+ $return['Merchant']['fee'] = $this->_formatFloat($this->getMerchantFee());
230
+ $return['Merchant']['currencyCode'] = $this->getMerchantCurrencyCode();
231
+ }
232
+
233
+ $return['Subscriber'] = array();
234
+ $return['Subscriber']['account'] = $this->getSubscriberAccount();
235
+ $return['Subscriber']['countryCode'] = $this->getSubscriberCountryCode();
236
+ $return['Subscriber']['country'] = $this->getSubscriberCountry();
237
+ $return['Subscriber']['firstName'] = $this->getSubscriberFirstName();
238
+ $return['Subscriber']['lastName'] = $this->getSubscriberLastName();
239
+ $return['Subscriber']['emailId'] = $this->getSubscriberEmail();
240
+
241
+ $return['OriginPayment'] = array();
242
+ $return['OriginPayment']['amount'] = $this->_formatFloat($this->getOriginPaymentAmount());
243
+ $return['OriginPayment']['currencyCode'] = $this->getOriginPaymentCurrencyCode();
244
+ $return['OriginPayment']['tax'] = $this->_formatFloat($this->getOriginPaymentTax());
245
+ $return['OriginPayment']['fee'] = $this->_formatFloat($this->getOriginPaymentFee());
246
+
247
+ $return['LocalPayment'] = array();
248
+ $return['LocalPayment']['amount'] = $this->_formatFloat($this->getLocalPaymentAmount());
249
+ $return['LocalPayment']['currencyCode'] = $this->getLocalPaymentCurrencyCode();
250
+
251
+ # The URL is deemed invalid by Tigo Payment Server API if it contains a trailing slash.
252
+ # Preg_replace's below removes this slash if present
253
+ $return['redirectUri'] = preg_replace('/\/$/', '', $this->getRedirectUri());
254
+ $return['callbackUri'] = preg_replace('/\/$/', '', $this->getCallbackUri());
255
+
256
+ $return['language'] = $this->getLanguage();
257
+ $return['terminalId'] = $this->getTerminalId();
258
+ $return['exchangeRate'] = $this->_formatFloat($this->getExchangeRate());
259
+ $return['merchantTransactionId'] = $this->getMerchantTransactionId();
260
+
261
+ return json_encode($return, JSON_UNESCAPED_SLASHES);
262
+ }
263
+
264
+ /**
265
+ * Callback URL - Getter
266
+ * @return null|string
267
+ */
268
+ public function getCallbackUri()
269
+ {
270
+ return $this->_callbackUri;
271
+ }
272
+
273
+ /**
274
+ * @inheritdoc
275
+ */
276
+ public function getEndpointPath()
277
+ {
278
+ return self::ENDPOINT_PATH;
279
+ }
280
+
281
+ /**
282
+ * Exchange Rate - Getter
283
+ * @return null|string
284
+ */
285
+ public function getExchangeRate()
286
+ {
287
+ return $this->_exchangeRate;
288
+ }
289
+
290
+ /**
291
+ * @inheritdoc
292
+ */
293
+ public function getHeaders()
294
+ {
295
+ return array(
296
+ Varien_Http_Client::CONTENT_TYPE => self::CONTENT_TYPE_JSON,
297
+ 'Authorization' => 'Bearer ' . $this->getAccessToken()
298
+ );
299
+ }
300
+
301
+ /**
302
+ * Language - Getter
303
+ * @return null|string
304
+ */
305
+ public function getLanguage()
306
+ {
307
+ return $this->_language;
308
+ }
309
+
310
+ /**
311
+ * Local Payment Account - Getter
312
+ * @return null|string
313
+ */
314
+ public function getLocalPaymentAmount()
315
+ {
316
+ return $this->_localPaymentAmount;
317
+ }
318
+
319
+ /**
320
+ * Local Payment Currency Code - Getter
321
+ * @return null|string
322
+ */
323
+ public function getLocalPaymentCurrencyCode()
324
+ {
325
+ return $this->_localPaymentCurrencyCode;
326
+ }
327
+
328
+ /**
329
+ * Master Merchant Account - Getter
330
+ * @return null|string
331
+ */
332
+ public function getMasterMerchantAccount()
333
+ {
334
+ return $this->_masterMerchantAccount;
335
+ }
336
+
337
+ /**
338
+ * Master Merchant Pin - Getter
339
+ * @return null|string
340
+ */
341
+ public function getMasterMerchantPin()
342
+ {
343
+ return $this->_masterMerchantPin;
344
+ }
345
+
346
+ /**
347
+ * Master Merchant Id - Getter
348
+ * @return null|string
349
+ */
350
+ public function getMasterMerchantId()
351
+ {
352
+ return $this->_masterMerchantId;
353
+ }
354
+
355
+ /**
356
+ * Master Merchant Reference - Getter
357
+ * @return null|string
358
+ */
359
+ public function getMerchantReference()
360
+ {
361
+ return $this->_merchantReference;
362
+ }
363
+
364
+ /**
365
+ * Merchant Transaction Id - Getter
366
+ * @return null|string
367
+ */
368
+ public function getMerchantTransactionId()
369
+ {
370
+ return $this->_merchantTransactionId;
371
+ }
372
+
373
+ /**
374
+ * Merchant Fee - Getter
375
+ * @return null|string
376
+ */
377
+ public function getMerchantFee()
378
+ {
379
+ return $this->_merchantFee;
380
+ }
381
+
382
+ /**
383
+ * Merchant Currency Code - Getter
384
+ * @return null|string
385
+ */
386
+ public function getMerchantCurrencyCode()
387
+ {
388
+ return $this->_merchantCurrencyCode;
389
+ }
390
+
391
+ /**
392
+ * @inheritdoc
393
+ */
394
+ public function getMethod()
395
+ {
396
+ return Varien_Http_Client::POST;
397
+ }
398
+
399
+ /**
400
+ * Origin Payment Amount - Getter
401
+ * @return null|string
402
+ */
403
+ public function getOriginPaymentAmount()
404
+ {
405
+ return $this->_originPaymentAmount;
406
+ }
407
+
408
+ /**
409
+ * Origin Payment Currency Code - Getter
410
+ * @return null|string
411
+ */
412
+ public function getOriginPaymentCurrencyCode()
413
+ {
414
+ return $this->_originPaymentCurrencyCode;
415
+ }
416
+
417
+ /**
418
+ * Origin Payment Tax - Getter
419
+ * @return null|string
420
+ */
421
+ public function getOriginPaymentTax()
422
+ {
423
+ return $this->_originPaymentTax;
424
+ }
425
+
426
+ /**
427
+ * Origin Payment Fee - Getter
428
+ * @return null|string
429
+ */
430
+ public function getOriginPaymentFee()
431
+ {
432
+ return $this->_originPaymentFee;
433
+ }
434
+
435
+ /**
436
+ * Redirect Uri - Getter
437
+ * @return null|string
438
+ */
439
+ public function getRedirectUri()
440
+ {
441
+ return $this->_redirectUri;
442
+ }
443
+
444
+ /**
445
+ * Subscriber Account - Getter
446
+ * @return null|string
447
+ */
448
+ public function getSubscriberAccount()
449
+ {
450
+ return $this->_subscriberAccount;
451
+ }
452
+
453
+ /**
454
+ * Subscriber Country Code - Getter
455
+ * @return null|string
456
+ */
457
+ public function getSubscriberCountryCode()
458
+ {
459
+ return $this->_subscriberCountryCode;
460
+ }
461
+
462
+ /**
463
+ * Subscriber Country - Getter
464
+ * @return null|string
465
+ */
466
+ public function getSubscriberCountry()
467
+ {
468
+ return $this->_subscriberCountry;
469
+ }
470
+
471
+ /**
472
+ * Subscriber First Name - Getter
473
+ * @return null|string
474
+ */
475
+ public function getSubscriberFirstName()
476
+ {
477
+ return $this->_subscriberFirstName;
478
+ }
479
+
480
+ /**
481
+ * Subscriber Last Name - Getter
482
+ * @return null|string
483
+ */
484
+ public function getSubscriberLastName()
485
+ {
486
+ return $this->_subscriberLastName;
487
+ }
488
+
489
+ /**
490
+ * Subscriber Email - Getter
491
+ * @return null|string
492
+ */
493
+ public function getSubscriberEmail()
494
+ {
495
+ return $this->_subscriberEmail;
496
+ }
497
+
498
+ /**
499
+ * Terminal Id - Getter
500
+ * @return null|string
501
+ */
502
+ public function getTerminalId()
503
+ {
504
+ return $this->_terminalId;
505
+ }
506
+
507
+ /**
508
+ * Access Token - Setter
509
+ * @param mixed $accessToken
510
+ */
511
+ public function setAccessToken($accessToken)
512
+ {
513
+ $this->_accessToken = trim($accessToken);
514
+ }
515
+
516
+ /**
517
+ * Callback URI - Setter
518
+ * @param mixed $callbackUri
519
+ */
520
+ public function setCallbackUri($callbackUri)
521
+ {
522
+ $this->_callbackUri = trim($callbackUri);
523
+ }
524
+
525
+ /**
526
+ * Exchange Rate - Setter
527
+ * @param mixed $exchangeRate
528
+ */
529
+ public function setExchangeRate($exchangeRate)
530
+ {
531
+ $this->_exchangeRate = (float) $exchangeRate;
532
+ }
533
+
534
+ /**
535
+ * Language - Setter
536
+ * @param mixed $language
537
+ */
538
+ public function setLanguage($language)
539
+ {
540
+ $this->_language = substr(trim($language), 0, 3);
541
+ }
542
+
543
+ /**
544
+ * Local Payment Amount - Setter
545
+ * @param mixed $localPaymentAmount
546
+ */
547
+ public function setLocalPaymentAmount($localPaymentAmount)
548
+ {
549
+ $this->_localPaymentAmount = (float) $localPaymentAmount;
550
+ }
551
+
552
+ /**
553
+ * Local Payment Currency Code - Setter
554
+ * @param mixed $localPaymentCurrencyCode
555
+ */
556
+ public function setLocalPaymentCurrencyCode($localPaymentCurrencyCode)
557
+ {
558
+ $this->_localPaymentCurrencyCode = substr(trim($localPaymentCurrencyCode), 0, 3);
559
+ }
560
+
561
+ /**
562
+ * Master Merchant Account - Setter
563
+ * @param mixed $masterMerchantAccount
564
+ */
565
+ public function setMasterMerchantAccount($masterMerchantAccount)
566
+ {
567
+ $this->_masterMerchantAccount = trim($masterMerchantAccount);
568
+ }
569
+
570
+ /**
571
+ * Master Merchant Pin - Setter
572
+ * @param mixed $masterMerchantPin
573
+ */
574
+ public function setMasterMerchantPin($masterMerchantPin)
575
+ {
576
+ $this->_masterMerchantPin = trim($masterMerchantPin);
577
+ }
578
+
579
+ /**
580
+ * Master Merchant Id - Setter
581
+ * @param mixed $masterMerchantId
582
+ */
583
+ public function setMasterMerchantId($masterMerchantId)
584
+ {
585
+ $this->_masterMerchantId = trim($masterMerchantId);
586
+ }
587
+
588
+ /**
589
+ * Merchant Reference - Setter
590
+ * @param mixed $merchantReference
591
+ */
592
+ public function setMerchantReference($merchantReference)
593
+ {
594
+ $this->_merchantReference = trim($merchantReference);
595
+ }
596
+
597
+ /**
598
+ * Merchant Transaction Id - Setter
599
+ * @param mixed $merchantTransactionId
600
+ */
601
+ public function setMerchantTransactionId($merchantTransactionId)
602
+ {
603
+ $this->_merchantTransactionId = trim($merchantTransactionId);
604
+ }
605
+
606
+ /**
607
+ * Merchant Fee - Setter
608
+ * @param mixed $merchantFee
609
+ */
610
+ public function setMerchantFee($merchantFee)
611
+ {
612
+ $this->_merchantFee = (float) $merchantFee;
613
+ }
614
+
615
+ /**
616
+ * Merchant Currency Code - Setter
617
+ * @param mixed $merchantCurrencyCode
618
+ */
619
+ public function setMerchantCurrencyCode($merchantCurrencyCode)
620
+ {
621
+ $this->_merchantCurrencyCode = substr(trim($merchantCurrencyCode), 0, 3);
622
+ }
623
+
624
+ /**
625
+ * Origin Payment Amount - Setter
626
+ * @param mixed $originPaymentAmount
627
+ */
628
+ public function setOriginPaymentAmount($originPaymentAmount)
629
+ {
630
+ $this->_originPaymentAmount = (float) $originPaymentAmount;
631
+ }
632
+
633
+ /**
634
+ * Origin Payment Currency Code - Setter
635
+ * @param mixed $originPaymentCurrencyCode
636
+ */
637
+ public function setOriginPaymentCurrencyCode($originPaymentCurrencyCode)
638
+ {
639
+ $this->_originPaymentCurrencyCode = substr(trim($originPaymentCurrencyCode), 0, 3);
640
+ }
641
+
642
+ /**
643
+ * Origin Payment Tax - Setter
644
+ * @param mixed $originPaymentTax
645
+ */
646
+ public function setOriginPaymentTax($originPaymentTax)
647
+ {
648
+ $this->_originPaymentTax = (float) $originPaymentTax;
649
+ }
650
+
651
+ /**
652
+ * Origin Payment Fee - Setter
653
+ * @param mixed $originPaymentFee
654
+ */
655
+ public function setOriginPaymentFee($originPaymentFee)
656
+ {
657
+ $this->_originPaymentFee = (float) $originPaymentFee;
658
+ }
659
+
660
+ /**
661
+ * Redirect URI - Setter
662
+ * @param mixed $redirectUri
663
+ */
664
+ public function setRedirectUri($redirectUri)
665
+ {
666
+ $this->_redirectUri = trim($redirectUri);
667
+ }
668
+
669
+ /**
670
+ * Subscriber Account - Setter
671
+ * @param mixed $subscriberAccount
672
+ */
673
+ public function setSubscriberAccount($subscriberAccount)
674
+ {
675
+ $this->_subscriberAccount = trim($subscriberAccount);
676
+ }
677
+
678
+ /**
679
+ * Subscriber Country Code - Setter
680
+ * @param mixed $subscriberCountryCode
681
+ */
682
+ public function setSubscriberCountryCode($subscriberCountryCode)
683
+ {
684
+ $this->_subscriberCountryCode = substr(trim($subscriberCountryCode), 0, 3);
685
+ }
686
+
687
+ /**
688
+ * Subscriber Country - Setter
689
+ * @param mixed $subscriberCountry
690
+ */
691
+ public function setSubscriberCountry($subscriberCountry)
692
+ {
693
+ $this->_subscriberCountry = substr(trim($subscriberCountry), 0, 3);
694
+ }
695
+
696
+ /**
697
+ * Subscriber First Name - Setter
698
+ * @param mixed $subscriberFirstName
699
+ */
700
+ public function setSubscriberFirstName($subscriberFirstName)
701
+ {
702
+ $this->_subscriberFirstName = trim($subscriberFirstName);
703
+ }
704
+
705
+ /**
706
+ * Subscriber Last Name - Setter
707
+ * @param mixed $subscriberLastName
708
+ */
709
+ public function setSubscriberLastName($subscriberLastName)
710
+ {
711
+ $this->_subscriberLastName = trim($subscriberLastName);
712
+ }
713
+
714
+ /**
715
+ * Subscriber Email - Setter
716
+ * @param mixed $subscriberEmail
717
+ */
718
+ public function setSubscriberEmail($subscriberEmail)
719
+ {
720
+ $this->_subscriberEmail = trim($subscriberEmail);
721
+ }
722
+
723
+ /**
724
+ * Should we send merchant info in this request?
725
+ * @return bool
726
+ */
727
+ protected function _shouldSendMerchantInfo()
728
+ {
729
+ return (bool) ($this->getMerchantReference());
730
+ }
731
+
732
+ /**
733
+ * Terminal Id - Setter
734
+ * @param mixed $terminalId
735
+ */
736
+ public function setTerminalId($terminalId)
737
+ {
738
+ $this->_terminalId = trim($terminalId);
739
+ }
740
+
741
+ /**
742
+ * @inheritdoc
743
+ */
744
+ public function validate()
745
+ {
746
+ if (
747
+ !$this->getAccessToken() ||
748
+ !$this->getMasterMerchantAccount() ||
749
+ !$this->getMasterMerchantPin() ||
750
+ !$this->getMasterMerchantId() ||
751
+ !$this->getSubscriberAccount() ||
752
+ !$this->getSubscriberCountry() ||
753
+ !$this->getSubscriberCountryCode() ||
754
+ !$this->getSubscriberFirstName() ||
755
+ !$this->getSubscriberLastName() ||
756
+ !$this->getSubscriberEmail() ||
757
+ !$this->getLocalPaymentAmount() ||
758
+ !$this->getLocalPaymentCurrencyCode() ||
759
+ !$this->getRedirectUri() ||
760
+ !$this->getCallbackUri() ||
761
+ !$this->getLanguage() ||
762
+ !$this->getMerchantTransactionId()
763
+ ) {
764
+ $return = false;
765
+ } else {
766
+ $return = true;
767
+ }
768
+
769
+ return $return;
770
+ }
771
+ }
app/code/community/Tigo/TigoMoney/Model/Payment/Redirect/Api/AuthorizationResponse.php ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Tigo_TigoMoney_Model_Payment_Redirect_Api_AuthorizationResponse
5
+ */
6
+ class Tigo_TigoMoney_Model_Payment_Redirect_Api_AuthorizationResponse extends
7
+ Tigo_TigoMoney_Model_Payment_Redirect_Api_AbstractResponse
8
+ {
9
+ /**
10
+ * Response data key - Redirect Uri
11
+ */
12
+ const RESPONSE_DATA_KEY_AUTH_CODE = 'auth_code';
13
+
14
+ /**
15
+ * Response data key - Redirect Uri
16
+ */
17
+ const RESPONSE_DATA_KEY_REDIRECT_URI = 'redirect_uri';
18
+
19
+ /**
20
+ * Gets Auth Code from response data
21
+ * @return string
22
+ */
23
+ public function getAuthCode()
24
+ {
25
+ return $this->getResponseData(self::RESPONSE_DATA_KEY_AUTH_CODE);
26
+ }
27
+
28
+ /**
29
+ * Gets Redirect URI from response data
30
+ * @return string
31
+ */
32
+ public function getRedirectUri()
33
+ {
34
+ return $this->getResponseData(self::RESPONSE_DATA_KEY_REDIRECT_URI);
35
+ }
36
+
37
+ /**
38
+ * Sets Auth Code to response data
39
+ * @param string $authCode
40
+ * @return $this
41
+ */
42
+ public function setAuthCode($authCode)
43
+ {
44
+ return $this->addResponseData(self::RESPONSE_DATA_KEY_AUTH_CODE, (string) $authCode);
45
+ }
46
+
47
+ /**
48
+ * Sets Redirect URI to response data
49
+ * @param string $uri
50
+ * @return $this
51
+ */
52
+ public function setRedirectUri($uri)
53
+ {
54
+ return $this->addResponseData(self::RESPONSE_DATA_KEY_REDIRECT_URI, (string) $uri);
55
+ }
56
+ }
app/code/community/Tigo/TigoMoney/Model/Payment/Redirect/Api/GenerateTokenRequest.php ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Tigo_TigoMoney_Model_Payment_Redirect_Api_GenerateTokenRequest
5
+ */
6
+ class Tigo_TigoMoney_Model_Payment_Redirect_Api_GenerateTokenRequest
7
+ implements Tigo_TigoMoney_Model_Payment_Redirect_Api_RequestInterface
8
+ {
9
+ /**
10
+ * Generate Token Enpoint Path
11
+ */
12
+ const ENDPOINT_PATH = 'v1/oauth/mfs/payments/tokens';
13
+
14
+ /**
15
+ * Body contents for generate token request
16
+ */
17
+ const REQUEST_BODY = 'grant_type=client_credentials';
18
+
19
+ /**
20
+ * Client Id
21
+ * @var null|string
22
+ */
23
+ protected $_clientId = null;
24
+
25
+ /**
26
+ * Client Secret
27
+ * @var null
28
+ */
29
+ protected $_clientSecret = null;
30
+
31
+ /**
32
+ * @inheritdoc
33
+ */
34
+ public function getBody()
35
+ {
36
+ return self::REQUEST_BODY;
37
+ }
38
+
39
+ /**
40
+ * Client ID Getter
41
+ * @return null|string
42
+ */
43
+ public function getClientId()
44
+ {
45
+ return $this->_clientId;
46
+ }
47
+
48
+ /**
49
+ * Client Secret Getter
50
+ * @return null
51
+ */
52
+ public function getClientSecret()
53
+ {
54
+ return $this->_clientSecret;
55
+ }
56
+
57
+ /**
58
+ * @inheritdoc
59
+ */
60
+ public function getEndpointPath()
61
+ {
62
+ return self::ENDPOINT_PATH;
63
+ }
64
+
65
+ /**
66
+ * @inheritdoc
67
+ */
68
+ public function getHeaders()
69
+ {
70
+ return array(
71
+ Varien_Http_Client::CONTENT_TYPE => Varien_Http_Client::ENC_URLENCODED,
72
+ 'Authorization' => 'Basic ' . base64_encode($this->getClientId() . ':' . $this->getClientSecret())
73
+ );
74
+ }
75
+
76
+ /**
77
+ * @inheritdoc
78
+ */
79
+ public function getMethod()
80
+ {
81
+ return Varien_Http_Client::POST;
82
+ }
83
+
84
+ /**
85
+ * Client ID Setter
86
+ * @param null|string $clientId
87
+ */
88
+ public function setClientId($clientId)
89
+ {
90
+ $this->_clientId = trim((string) $clientId);
91
+ }
92
+
93
+ /**
94
+ * Client Secret Setter
95
+ * @param null $clientSecret
96
+ */
97
+ public function setClientSecret($clientSecret)
98
+ {
99
+ $this->_clientSecret = trim((string) $clientSecret);
100
+ }
101
+
102
+ /**
103
+ * @inheritdoc
104
+ */
105
+ public function validate()
106
+ {
107
+ return ($this->getBody() && $this->getClientId() && $this->getClientSecret());
108
+ }
109
+ }
app/code/community/Tigo/TigoMoney/Model/Payment/Redirect/Api/GenerateTokenResponse.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Tigo_TigoMoney_Model_Payment_Redirect_Api_GenerateTokenResponse
5
+ */
6
+ class Tigo_TigoMoney_Model_Payment_Redirect_Api_GenerateTokenResponse extends
7
+ Tigo_TigoMoney_Model_Payment_Redirect_Api_AbstractResponse
8
+ {
9
+ /**
10
+ * Response data key - Access Token
11
+ */
12
+ const RESPONSE_DATA_KEY_ACCESS_TOKEN = 'access_token';
13
+
14
+ /**
15
+ * Gets Access Token from response data
16
+ * @return string
17
+ */
18
+ public function getAccessToken()
19
+ {
20
+ return $this->getResponseData(self::RESPONSE_DATA_KEY_ACCESS_TOKEN);
21
+ }
22
+
23
+ /**
24
+ * Sets Access Token to response data
25
+ * @param $token
26
+ * @return $this
27
+ */
28
+ public function setAccessToken($token)
29
+ {
30
+ return $this->addResponseData(self::RESPONSE_DATA_KEY_ACCESS_TOKEN, (string) $token);
31
+ }
32
+ }
app/code/community/Tigo/TigoMoney/Model/Payment/Redirect/Api/RequestBuilder.php ADDED
@@ -0,0 +1,181 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Tigo_TigoMoney_Model_Payment_Redirect_Api_RequestBuilder
5
+ */
6
+ class Tigo_TigoMoney_Model_Payment_Redirect_Api_RequestBuilder
7
+ {
8
+ /**
9
+ * Data Helper
10
+ * @var null|Tigo_TigoMoney_Helper_Data
11
+ */
12
+ protected $_dataHelper = null;
13
+
14
+ /**
15
+ * Builds a new authorization request object
16
+ * @param string $accessToken
17
+ * @param Mage_Sales_Model_Order $order
18
+ * @return Tigo_TigoMoney_Model_Payment_Redirect_Api_AuthorizationRequest
19
+ */
20
+ public function buildAuthorizationRequest($accessToken, Mage_Sales_Model_Order $order)
21
+ {
22
+ $request = $this->_getAuthorizationRequestInstance();
23
+
24
+ # Access Token
25
+ $request->setAccessToken($accessToken);
26
+
27
+ # Master Merchant Account Info
28
+ $request->setMasterMerchantAccount($this->_getDataHelper()->getMerchantAccount());
29
+ $request->setMasterMerchantPin($this->_getDataHelper()->getMerchantPin());
30
+ $request->setMasterMerchantId($this->_getDataHelper()->getMerchantId());
31
+
32
+ # Merchant Info
33
+ $request->setMerchantReference($this->_getDataHelper()->getMerchantReference());
34
+ $request->setMerchantCurrencyCode(Tigo_TigoMoney_Model_Payment_Redirect_Api_AuthorizationRequest::CURRENCY_CODE_USD);
35
+ $request->setMerchantFee(0);
36
+
37
+ # Subscriber
38
+ $request->setSubscriberAccount($order->getPayment()->getAdditionalInformation(Tigo_TigoMoney_Model_Payment_Redirect::ADDITIONAL_INFO_KEY_PHONE_NUMBER));
39
+ $request->setSubscriberCountry(Tigo_TigoMoney_Model_Payment_Redirect_Api_AuthorizationRequest::COUNTRY_CODE);
40
+ $request->setSubscriberCountryCode(Tigo_TigoMoney_Model_Payment_Redirect_Api_AuthorizationRequest::COUNTRY_DIAL_CODE);
41
+ $request->setSubscriberFirstName($order->getCustomerFirstname());
42
+ $request->setSubscriberLastName($order->getCustomerLastname());
43
+ $request->setSubscriberEmail($order->getCustomerEmail());
44
+
45
+ # Local Payment
46
+ $request->setLocalPaymentAmount($order->getBaseGrandTotal());
47
+ $request->setLocalPaymentCurrencyCode(Tigo_TigoMoney_Model_Payment_Redirect_Api_AuthorizationRequest::CURRENCY_CODE_USD);
48
+
49
+ # Origin Payment
50
+ $request->setOriginPaymentAmount($order->getBaseGrandTotal());
51
+ $request->setOriginPaymentCurrencyCode(Tigo_TigoMoney_Model_Payment_Redirect_Api_AuthorizationRequest::CURRENCY_CODE_USD);
52
+ $request->setOriginPaymentTax(0);
53
+ $request->setOriginPaymentFee(0);
54
+
55
+ # Additional Info
56
+ $request->setRedirectUri($this->_getDataHelper()->getRedirectUri());
57
+ $request->setCallbackUri($this->_getDataHelper()->getCallbackUri());
58
+ $request->setLanguage(Tigo_TigoMoney_Model_Payment_Redirect_Api_AuthorizationRequest::LANGUAGE_CODE_SPANISH);
59
+ $request->setMerchantTransactionId($order->getIncrementId());
60
+ $request->setTerminalId(Tigo_TigoMoney_Model_Payment_Redirect_Api_AuthorizationRequest::TERMINAL_ID);
61
+ $request->setExchangeRate(1);
62
+
63
+ return $request;
64
+ }
65
+
66
+ /**
67
+ * Builds a new generate access token request object
68
+ * @return Tigo_TigoMoney_Model_Payment_Redirect_Api_GenerateTokenRequest
69
+ */
70
+ public function buildGenerateAccessTokenRequest()
71
+ {
72
+ $request = $this->_getGenerateAccessTokenRequestInstance();
73
+ $request->setClientId($this->_getDataHelper()->getClientId());
74
+ $request->setClientSecret($this->_getDataHelper()->getClientSecret());
75
+ return $request;
76
+ }
77
+
78
+ /**
79
+ * Builds a new reverse transaction request object
80
+ * @param Mage_Sales_Model_Order $order
81
+ * @param string $accessToken
82
+ * @return Tigo_TigoMoney_Model_Payment_Redirect_Api_ReverseTransactionRequest
83
+ */
84
+ public function buildReverseTransactionRequest($accessToken, Mage_Sales_Model_Order $order)
85
+ {
86
+ $request = $this->_getReverseTransactionRequestInstance();
87
+
88
+ $request->setAccessToken($accessToken);
89
+ $request->setMasterAccountAccount($this->_getDataHelper()->getMerchantAccount());
90
+ $request->setMasterAccountPin($this->_getDataHelper()->getMerchantPin());
91
+ $request->setMasterAccountId($this->_getDataHelper()->getMerchantId());
92
+ $request->setSubscriberAccount(
93
+ $order->getPayment()->getAdditionalInformation(
94
+ Tigo_TigoMoney_Model_Payment_Redirect::ADDITIONAL_INFO_KEY_PHONE_NUMBER
95
+ )
96
+ );
97
+ $request->setLocalPaymentCurrencyCode(
98
+ Tigo_TigoMoney_Model_Payment_Redirect_Api_ReverseTransactionRequest::CURRENCY_CODE_USD
99
+ );
100
+ $request->setCountry(
101
+ Tigo_TigoMoney_Model_Payment_Redirect_Api_ReverseTransactionRequest::COUNTRY_CODE_EL_SALVADOR
102
+ );
103
+ $request->setLocalPaymentAmount($order->getBaseGrandTotal());
104
+ $request->setMerchantTransactionId($order->getIncrementId());
105
+ $request->setMfsTransactionId(
106
+ $order->getPayment()->getAdditionalInformation(
107
+ Tigo_TigoMoney_Model_Payment_Redirect::ADDITIONAL_INFO_KEY_MFS_TRANSACTION_ID
108
+ )
109
+ );
110
+ return $request;
111
+ }
112
+
113
+ /**
114
+ * Builds a new transaction status request object
115
+ * @param Mage_Sales_Model_Order $order
116
+ * @param string $accessToken
117
+ * @return Tigo_TigoMoney_Model_Payment_Redirect_Api_TransactionStatusRequest
118
+ */
119
+ public function buildTransactionStatusRequest($accessToken, Mage_Sales_Model_Order $order)
120
+ {
121
+ $request = $this->_getTransactionStatusRequestInstance();
122
+
123
+ $orderIncrementId = $order->getIncrementId();
124
+
125
+ $request->setAccessToken($accessToken);
126
+ $request->setCountry(
127
+ Tigo_TigoMoney_Model_Payment_Redirect_Api_TransactionStatusRequest::COUNTRY_CODE_EL_SALVADOR
128
+ );
129
+ $request->setMasterMerchantId($this->_getDataHelper()->getMerchantId());
130
+ $request->setMerchantTransactionId($orderIncrementId);
131
+ return $request;
132
+ }
133
+
134
+ /**
135
+ * Gets new AuthorizationRequest Instance
136
+ * @return Tigo_TigoMoney_Model_Payment_Redirect_Api_AuthorizationRequest
137
+ */
138
+ protected function _getAuthorizationRequestInstance()
139
+ {
140
+ return Mage::getModel('tigo_tigomoney/payment_redirect_api_authorizationRequest');
141
+ }
142
+
143
+ /**
144
+ * Data Helper Getter
145
+ * @return Tigo_TigoMoney_Helper_Data
146
+ */
147
+ protected function _getDataHelper()
148
+ {
149
+ if ($this->_dataHelper === null) {
150
+ $this->_dataHelper = Mage::helper('tigo_tigomoney');
151
+ }
152
+ return $this->_dataHelper;
153
+ }
154
+
155
+ /**
156
+ * Gets new GenerateTokenRequest Instance
157
+ * @return Tigo_TigoMoney_Model_Payment_Redirect_Api_GenerateTokenRequest
158
+ */
159
+ protected function _getGenerateAccessTokenRequestInstance()
160
+ {
161
+ return Mage::getModel('tigo_tigomoney/payment_redirect_api_generateTokenRequest');
162
+ }
163
+
164
+ /**
165
+ * Gets new ReverseTransactionRequest Instance
166
+ * @return Tigo_TigoMoney_Model_Payment_Redirect_Api_ReverseTransactionRequest
167
+ */
168
+ protected function _getReverseTransactionRequestInstance()
169
+ {
170
+ return Mage::getModel('tigo_tigomoney/payment_redirect_api_reverseTransactionRequest');
171
+ }
172
+
173
+ /**
174
+ * Gets new TransactionStatusRequest Instance
175
+ * @return Tigo_TigoMoney_Model_Payment_Redirect_Api_TransactionStatusRequest
176
+ */
177
+ protected function _getTransactionStatusRequestInstance()
178
+ {
179
+ return Mage::getModel('tigo_tigomoney/payment_redirect_api_transactionStatusRequest');
180
+ }
181
+ }
app/code/community/Tigo/TigoMoney/Model/Payment/Redirect/Api/RequestInterface.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Interface Tigo_TigoMoney_Model_Payment_Redirect_Api_RequestInterface
5
+ */
6
+ interface Tigo_TigoMoney_Model_Payment_Redirect_Api_RequestInterface
7
+ {
8
+ /**
9
+ * Returns request body
10
+ * @return string
11
+ */
12
+ public function getBody();
13
+
14
+ /**
15
+ * @return string
16
+ */
17
+ public function getEndpointPath();
18
+
19
+ /**
20
+ * Returns request headers
21
+ * @return array
22
+ */
23
+ public function getHeaders();
24
+
25
+ /**
26
+ * Returns request method
27
+ * @return string
28
+ */
29
+ public function getMethod();
30
+
31
+ /**
32
+ * Validates current request
33
+ * @return float
34
+ */
35
+ public function validate();
36
+
37
+ }
app/code/community/Tigo/TigoMoney/Model/Payment/Redirect/Api/ResponseInterface.php ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Interface Tigo_TigoMoney_Model_Payment_Redirect_Api_ResponseInterface
5
+ */
6
+ interface Tigo_TigoMoney_Model_Payment_Redirect_Api_ResponseInterface
7
+ {
8
+ /**
9
+ * Adds an error to the response
10
+ * @param string $error
11
+ * @return $this
12
+ */
13
+ public function addError($error);
14
+
15
+ /**
16
+ * Adds response data
17
+ * @param string $key
18
+ * @param mixed $data
19
+ * @return $this
20
+ */
21
+ public function addResponseData($key, $data);
22
+
23
+ /**
24
+ * Returns all errors
25
+ * @return string[]
26
+ */
27
+ public function getErrors();
28
+
29
+ /**
30
+ * Returns response data
31
+ * @param string $key
32
+ * @return mixed
33
+ */
34
+ public function getResponseData($key);
35
+
36
+ /**
37
+ * Was there an error in the response?
38
+ * @return bool
39
+ */
40
+ public function isError();
41
+
42
+ /**
43
+ * Was request successful?
44
+ * @return bool
45
+ */
46
+ public function isSuccess();
47
+ }
app/code/community/Tigo/TigoMoney/Model/Payment/Redirect/Api/ReverseTransactionRequest.php ADDED
@@ -0,0 +1,340 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Tigo_TigoMoney_Model_Payment_Redirect_Api_ReverseTransactionRequest
5
+ */
6
+ class Tigo_TigoMoney_Model_Payment_Redirect_Api_ReverseTransactionRequest
7
+ implements Tigo_TigoMoney_Model_Payment_Redirect_Api_RequestInterface
8
+ {
9
+ /**
10
+ * Content Type Json for Request Header
11
+ */
12
+ const CONTENT_TYPE_JSON = 'application/json';
13
+
14
+ /**
15
+ * Country Code - El Salvador
16
+ */
17
+ const COUNTRY_CODE_EL_SALVADOR = 'SLV';
18
+
19
+ /**
20
+ * Currency Code - USD
21
+ */
22
+ const CURRENCY_CODE_USD = 'USD';
23
+
24
+ /**
25
+ * Generate Token Enpoint Path
26
+ */
27
+ const ENDPOINT_PATH = 'v2/tigo/mfs/payments/transactions/';
28
+
29
+ /**
30
+ * Access Token
31
+ * @var null|string
32
+ */
33
+ protected $_accessToken = null;
34
+
35
+ /**
36
+ * Country
37
+ * @var null|string
38
+ */
39
+ protected $_country = null;
40
+
41
+ /**
42
+ * Local Payment - Amount
43
+ * @var null|string
44
+ */
45
+ protected $_localPaymentAmount = null;
46
+
47
+ /**
48
+ * Local Payment - Currency Code
49
+ * @var null|string
50
+ */
51
+ protected $_localPaymentCurrencyCode = null;
52
+
53
+ /**
54
+ * Master Account - Account
55
+ * @var null|string
56
+ */
57
+ protected $_masterAccountAccount = null;
58
+
59
+ /**
60
+ * Master Account - Id
61
+ * @var null|string
62
+ */
63
+ protected $_masterAccountId = null;
64
+
65
+ /**
66
+ * Master Account - Pin
67
+ * @var null|string
68
+ */
69
+ protected $_masterAccountPin = null;
70
+
71
+ /**
72
+ * Merchant Transaction Id
73
+ * @var null|string
74
+ */
75
+ protected $_merchantTransactionId = null;
76
+
77
+ /**
78
+ * Mfs Transaction Id
79
+ * @var null|string
80
+ */
81
+ protected $_mfsTransactionId = null;
82
+
83
+ /**
84
+ * Subscriber Account
85
+ * @var null|string
86
+ */
87
+ protected $_subscriberAccount = null;
88
+
89
+ /**
90
+ * Sets a float to the correct format used by the Tigo Api
91
+ * @param float $value
92
+ * @return string
93
+ */
94
+ protected function _formatFloat($value) {
95
+ return number_format($value, 2, '.', '');
96
+ }
97
+
98
+ /**
99
+ * Access Token Getter
100
+ * @return null|string
101
+ */
102
+ public function getAccessToken()
103
+ {
104
+ return $this->_accessToken;
105
+ }
106
+
107
+ /**
108
+ * @inheritdoc
109
+ */
110
+ public function getBody()
111
+ {
112
+ $return = array();
113
+
114
+ $return['MasterAccount'] = array();
115
+ $return['MasterAccount']['account'] = $this->getMasterAccountAccount();
116
+ $return['MasterAccount']['id'] = $this->getMasterAccountId();
117
+ $return['MasterAccount']['pin'] = $this->getMasterAccountPin();
118
+
119
+ $return['subscriberAccount'] = $this->getSubscriberAccount();
120
+
121
+ $return['LocalPayment'] = array();
122
+ $return['LocalPayment']['amount'] = $this->_formatFloat($this->getLocalPaymentAmount());
123
+ $return['LocalPayment']['currencyCode'] = $this->getLocalPaymentCurrencyCode();
124
+
125
+ return json_encode($return, JSON_UNESCAPED_SLASHES);
126
+ }
127
+
128
+ /**
129
+ * Country Getter
130
+ * @return null|string
131
+ */
132
+ public function getCountry()
133
+ {
134
+ return $this->_country;
135
+ }
136
+
137
+ /**
138
+ * @inheritdoc
139
+ */
140
+ public function getEndpointPath()
141
+ {
142
+ return self::ENDPOINT_PATH . strtoupper($this->getCountry()) . '/' . $this->getMfsTransactionId() . '/' .
143
+ $this->getMerchantTransactionId();
144
+ }
145
+
146
+ /**
147
+ * @inheritdoc
148
+ */
149
+ public function getHeaders()
150
+ {
151
+ return array(
152
+ Varien_Http_Client::CONTENT_TYPE => self::CONTENT_TYPE_JSON,
153
+ 'Authorization' => 'Bearer ' . $this->getAccessToken()
154
+ );
155
+ }
156
+
157
+ /**
158
+ * Local Payment Amount Getter
159
+ * @return null|string
160
+ */
161
+ public function getLocalPaymentAmount()
162
+ {
163
+ return $this->_localPaymentAmount;
164
+ }
165
+
166
+ /**
167
+ * Local Payment Currency Code Getter
168
+ * @return null|string
169
+ */
170
+ public function getLocalPaymentCurrencyCode()
171
+ {
172
+ return $this->_localPaymentCurrencyCode;
173
+ }
174
+
175
+ /**
176
+ * Master Account - Account Getter
177
+ * @return null|string
178
+ */
179
+ public function getMasterAccountAccount()
180
+ {
181
+ return $this->_masterAccountAccount;
182
+ }
183
+
184
+ /**
185
+ * Master Account Id Getter
186
+ * @return null|string
187
+ */
188
+ public function getMasterAccountId()
189
+ {
190
+ return $this->_masterAccountId;
191
+ }
192
+
193
+ /**
194
+ * Master Account Pin Getter
195
+ * @return null|string
196
+ */
197
+ public function getMasterAccountPin()
198
+ {
199
+ return $this->_masterAccountPin;
200
+ }
201
+
202
+ /**
203
+ * Merchant Transaction Id Getter
204
+ * @return null|string
205
+ */
206
+ public function getMerchantTransactionId()
207
+ {
208
+ return $this->_merchantTransactionId;
209
+ }
210
+
211
+ /**
212
+ * MFS Transaction Id Getter
213
+ * @return null
214
+ */
215
+ public function getMfsTransactionId()
216
+ {
217
+ return $this->_mfsTransactionId;
218
+ }
219
+
220
+ /**
221
+ * @inheritdoc
222
+ */
223
+ public function getMethod()
224
+ {
225
+ return Varien_Http_Client::DELETE;
226
+ }
227
+
228
+ /**
229
+ * Subscriber Account Getter
230
+ * @return null|string
231
+ */
232
+ public function getSubscriberAccount()
233
+ {
234
+ return $this->_subscriberAccount;
235
+ }
236
+
237
+ /**
238
+ * Access Token Setter
239
+ * @param mixed $accessToken
240
+ */
241
+ public function setAccessToken($accessToken)
242
+ {
243
+ $this->_accessToken = $accessToken;
244
+ }
245
+
246
+ /**
247
+ * Access Token Setter
248
+ * @param mixed $country
249
+ */
250
+ public function setCountry($country)
251
+ {
252
+ $this->_country = trim((string) $country);
253
+ }
254
+
255
+ /**
256
+ * Local Payment Amount Setter
257
+ * @param mixed $localPaymentAmount
258
+ */
259
+ public function setLocalPaymentAmount($localPaymentAmount)
260
+ {
261
+ $this->_localPaymentAmount = $localPaymentAmount;
262
+ }
263
+
264
+ /**
265
+ * Local Payment Currency Code Setter
266
+ * @param mixed $localPaymentCurrencyCode
267
+ */
268
+ public function setLocalPaymentCurrencyCode($localPaymentCurrencyCode)
269
+ {
270
+ $this->_localPaymentCurrencyCode = $localPaymentCurrencyCode;
271
+ }
272
+
273
+ /**
274
+ * Master Account - Account Setter
275
+ * @param mixed $masterAccountAccount
276
+ */
277
+ public function setMasterAccountAccount($masterAccountAccount)
278
+ {
279
+ $this->_masterAccountAccount = $masterAccountAccount;
280
+ }
281
+
282
+ /**
283
+ * Master Account - Id Setter
284
+ * @param mixed $masterAccountId
285
+ */
286
+ public function setMasterAccountId($masterAccountId)
287
+ {
288
+ $this->_masterAccountId = $masterAccountId;
289
+ }
290
+
291
+ /**
292
+ * Master Account - Pin Setter
293
+ * @param mixed $masterAccountPin
294
+ */
295
+ public function setMasterAccountPin($masterAccountPin)
296
+ {
297
+ $this->_masterAccountPin = $masterAccountPin;
298
+ }
299
+
300
+ /**
301
+ * Merchant Transaction Id Setter
302
+ * @param mixed $merchantTransactionId
303
+ */
304
+ public function setMerchantTransactionId($merchantTransactionId)
305
+ {
306
+ $this->_merchantTransactionId = trim((string) $merchantTransactionId);
307
+ }
308
+
309
+ /**
310
+ * MFS Transaction Id Setter
311
+ * @param mixed $mfsTransactionId
312
+ */
313
+ public function setMfsTransactionId($mfsTransactionId)
314
+ {
315
+ $this->_mfsTransactionId = trim((string) $mfsTransactionId);
316
+ }
317
+
318
+ /**
319
+ * Subscriber Account Setter
320
+ * @param mixed $subscriberAccount
321
+ */
322
+ public function setSubscriberAccount($subscriberAccount)
323
+ {
324
+ $this->_subscriberAccount = $subscriberAccount;
325
+ }
326
+
327
+ /**
328
+ * @inheritdoc
329
+ */
330
+ public function validate()
331
+ {
332
+ return (
333
+ $this->getAccessToken() && $this->getCountry() &&
334
+ $this->getMfsTransactionId() && $this->getMerchantTransactionId() &&
335
+ $this->getMasterAccountAccount() && $this->getMasterAccountPin() &&
336
+ $this->getSubscriberAccount() &&
337
+ $this->getLocalPaymentAmount() && $this->getLocalPaymentCurrencyCode()
338
+ );
339
+ }
340
+ }
app/code/community/Tigo/TigoMoney/Model/Payment/Redirect/Api/ReverseTransactionResponse.php ADDED
@@ -0,0 +1,248 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Tigo_TigoMoney_Model_Payment_Redirect_Api_ReverseTransactionResponse
5
+ */
6
+ class Tigo_TigoMoney_Model_Payment_Redirect_Api_ReverseTransactionResponse extends
7
+ Tigo_TigoMoney_Model_Payment_Redirect_Api_AbstractResponse
8
+ {
9
+ /**
10
+ * Response data key - Error
11
+ */
12
+ const RESPONSE_DATA_KEY_ERROR = 'error';
13
+
14
+ /**
15
+ * Response data key - Error - Description
16
+ */
17
+ const RESPONSE_DATA_KEY_ERROR_DESCRIPTION = 'error_description';
18
+
19
+ /**
20
+ * Response data key - Error - Type
21
+ */
22
+ const RESPONSE_DATA_KEY_ERROR_TYPE = 'error_type';
23
+
24
+ /**
25
+ * Response data key - Status
26
+ */
27
+ const RESPONSE_DATA_KEY_STATUS = 'status';
28
+
29
+ /**
30
+ * Response data key - Transaction - Correlation Id
31
+ */
32
+ const RESPONSE_DATA_KEY_TRANSACTION_CORRELATION_ID = 'transaction_correlation_id';
33
+
34
+ /**
35
+ * Response data key - Transaction - Merchant Transaction Id
36
+ */
37
+ const RESPONSE_DATA_KEY_TRANSACTION_MERCHANT_TRANSACTION_ID = 'transaction_merchant_transaction_id';
38
+
39
+ /**
40
+ * Response data key - Transaction - Message
41
+ */
42
+ const RESPONSE_DATA_KEY_TRANSACTION_MESSAGE = 'transaction_message';
43
+
44
+ /**
45
+ * Response data key - Transaction - MFS Transaction Id
46
+ */
47
+ const RESPONSE_DATA_KEY_TRANSACTION_MFS_TRANSACTION_ID = 'transaction_mfs_transaction_id';
48
+
49
+ /**
50
+ * Response data key - Transaction - Reverse Transaction Id
51
+ */
52
+ const RESPONSE_DATA_KEY_TRANSACTION_MFS_REVERSE_TRANSACTION_ID = 'transaction_mfs_reverse_transaction_id';
53
+
54
+ /**
55
+ * Response data key - Transaction - Status
56
+ */
57
+ const RESPONSE_DATA_KEY_TRANSACTION_STATUS = 'transaction_status';
58
+
59
+ /**
60
+ * Gets Error from response data
61
+ * @return string
62
+ */
63
+ public function getError()
64
+ {
65
+ return $this->getResponseData(self::RESPONSE_DATA_KEY_ERROR);
66
+ }
67
+
68
+ /**
69
+ * Gets ErrorDescription from response data
70
+ * @return string
71
+ */
72
+ public function getErrorDescription()
73
+ {
74
+ return $this->getResponseData(self::RESPONSE_DATA_KEY_ERROR_DESCRIPTION);
75
+ }
76
+
77
+ /**
78
+ * Gets Error Type from response data
79
+ * @return string
80
+ */
81
+ public function getErrorType()
82
+ {
83
+ return $this->getResponseData(self::RESPONSE_DATA_KEY_ERROR_TYPE);
84
+ }
85
+
86
+ /**
87
+ * Gets Status from response data
88
+ * @return string
89
+ */
90
+ public function getStatus()
91
+ {
92
+ return $this->getResponseData(self::RESPONSE_DATA_KEY_STATUS);
93
+ }
94
+
95
+ /**
96
+ * Gets Transaction - Correlation Id from response data
97
+ * @return string
98
+ */
99
+ public function getTransactionCorrelationId()
100
+ {
101
+ return $this->getResponseData(self::RESPONSE_DATA_KEY_TRANSACTION_CORRELATION_ID);
102
+ }
103
+
104
+ /**
105
+ * Gets Transaction - Merchant Transaction Id from response data
106
+ * @return string
107
+ */
108
+ public function getTransactionMerchantTransactionId()
109
+ {
110
+ return $this->getResponseData(self::RESPONSE_DATA_KEY_TRANSACTION_MERCHANT_TRANSACTION_ID);
111
+ }
112
+
113
+ /**
114
+ * Gets Transaction - Message from response data
115
+ * @return string
116
+ */
117
+ public function getTransactionMessage()
118
+ {
119
+ return $this->getResponseData(self::RESPONSE_DATA_KEY_TRANSACTION_MESSAGE);
120
+ }
121
+
122
+ /**
123
+ * Gets Transaction - Mfs Transaction Id from response data
124
+ * @return string
125
+ */
126
+ public function getTransactionMfsTransactionId()
127
+ {
128
+ return $this->getResponseData(self::RESPONSE_DATA_KEY_TRANSACTION_MFS_TRANSACTION_ID);
129
+ }
130
+
131
+ /**
132
+ * Gets Transaction - Reverse Transaction Id from response data
133
+ * @return string
134
+ */
135
+ public function getTransactionMfsReverseTransactionId()
136
+ {
137
+ return $this->getResponseData(self::RESPONSE_DATA_KEY_TRANSACTION_MFS_REVERSE_TRANSACTION_ID);
138
+ }
139
+
140
+ /**
141
+ * Gets Transaction - Status from response data
142
+ * @return string
143
+ */
144
+ public function getTransactionStatus()
145
+ {
146
+ return $this->getResponseData(self::RESPONSE_DATA_KEY_TRANSACTION_STATUS);
147
+ }
148
+
149
+ /**
150
+ * Sets Error to response data
151
+ * @param mixed $input
152
+ * @return $this
153
+ */
154
+ public function setError($input)
155
+ {
156
+ return $this->addResponseData(self::RESPONSE_DATA_KEY_ERROR, (string) $input);
157
+ }
158
+
159
+ /**
160
+ * Sets Error Description to response data
161
+ * @param mixed $input
162
+ * @return $this
163
+ */
164
+ public function setErrorDescription($input)
165
+ {
166
+ return $this->addResponseData(self::RESPONSE_DATA_KEY_ERROR_DESCRIPTION, (string) $input);
167
+ }
168
+
169
+ /**
170
+ * Sets Error Type to response data
171
+ * @param mixed $input
172
+ * @return $this
173
+ */
174
+ public function setErrorType($input)
175
+ {
176
+ return $this->addResponseData(self::RESPONSE_DATA_KEY_ERROR_TYPE, (string) $input);
177
+ }
178
+
179
+ /**
180
+ * Sets Status to response data
181
+ * @param mixed $input
182
+ * @return $this
183
+ */
184
+ public function setStatus($input)
185
+ {
186
+ return $this->addResponseData(self::RESPONSE_DATA_KEY_STATUS, (string) $input);
187
+ }
188
+
189
+ /**
190
+ * Sets Transaction - Correlation Id to response data
191
+ * @param mixed $input
192
+ * @return $this
193
+ */
194
+ public function setTransactionCorrelationId($input)
195
+ {
196
+ return $this->addResponseData(self::RESPONSE_DATA_KEY_TRANSACTION_CORRELATION_ID, (string) $input);
197
+ }
198
+
199
+ /**
200
+ * Sets Transaction - Merchant Transaction Id to response data
201
+ * @param mixed $input
202
+ * @return $this
203
+ */
204
+ public function setTransactionMerchantTransactionId($input)
205
+ {
206
+ return $this->addResponseData(self::RESPONSE_DATA_KEY_TRANSACTION_MERCHANT_TRANSACTION_ID, (string) $input);
207
+ }
208
+
209
+ /**
210
+ * Sets Transaction - Message to response data
211
+ * @param mixed $input
212
+ * @return $this
213
+ */
214
+ public function setTransactionMessage($input)
215
+ {
216
+ return $this->addResponseData(self::RESPONSE_DATA_KEY_TRANSACTION_MESSAGE, (string) $input);
217
+ }
218
+
219
+ /**
220
+ * Sets Transaction - Mfs Transaction Id to response data
221
+ * @param mixed $input
222
+ * @return $this
223
+ */
224
+ public function setTransactionMfsTransactionId($input)
225
+ {
226
+ return $this->addResponseData(self::RESPONSE_DATA_KEY_TRANSACTION_MFS_TRANSACTION_ID, (string) $input);
227
+ }
228
+
229
+ /**
230
+ * Sets Transaction - Reverse Transaction Id to response data
231
+ * @param mixed $input
232
+ * @return $this
233
+ */
234
+ public function setTransactionMfsReverseTransactionId($input)
235
+ {
236
+ return $this->addResponseData(self::RESPONSE_DATA_KEY_TRANSACTION_MFS_REVERSE_TRANSACTION_ID, (string) $input);
237
+ }
238
+
239
+ /**
240
+ * Sets Transaction - Status to response data
241
+ * @param mixed $input
242
+ * @return $this
243
+ */
244
+ public function setTransactionStatus($input)
245
+ {
246
+ return $this->addResponseData(self::RESPONSE_DATA_KEY_TRANSACTION_STATUS, (string) $input);
247
+ }
248
+ }
app/code/community/Tigo/TigoMoney/Model/Payment/Redirect/Api/TransactionStatusRequest.php ADDED
@@ -0,0 +1,160 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Tigo_TigoMoney_Model_Payment_Redirect_Api_TransactionStatusRequest
5
+ */
6
+ class Tigo_TigoMoney_Model_Payment_Redirect_Api_TransactionStatusRequest
7
+ implements Tigo_TigoMoney_Model_Payment_Redirect_Api_RequestInterface
8
+ {
9
+ /**
10
+ * Country Code - El Salvador
11
+ */
12
+ const COUNTRY_CODE_EL_SALVADOR = 'SLV';
13
+
14
+ /**
15
+ * Generate Token Enpoint Path
16
+ */
17
+ const ENDPOINT_PATH = 'v2/tigo/mfs/payments/transactions/';
18
+
19
+ /**
20
+ * Access Token
21
+ * @var null|string
22
+ */
23
+ protected $_accessToken = null;
24
+
25
+ /**
26
+ * Country
27
+ * @var null|string
28
+ */
29
+ protected $_country = null;
30
+
31
+ /**
32
+ * Master Merchant Id
33
+ * @var null|string
34
+ */
35
+ protected $_masterMerchantId = null;
36
+
37
+ /**
38
+ * Merchant Transaction Id
39
+ * @var null|string
40
+ */
41
+ protected $_merchantTransactionId = null;
42
+
43
+ /**
44
+ * Access Token Getter
45
+ * @return null|string
46
+ */
47
+ public function getAccessToken()
48
+ {
49
+ return $this->_accessToken;
50
+ }
51
+
52
+ /**
53
+ * @inheritdoc
54
+ */
55
+ public function getBody()
56
+ {
57
+ return '';
58
+ }
59
+
60
+ /**
61
+ * Country Getter
62
+ * @return null|string
63
+ */
64
+ public function getCountry()
65
+ {
66
+ return $this->_country;
67
+ }
68
+
69
+ /**
70
+ * @inheritdoc
71
+ */
72
+ public function getEndpointPath()
73
+ {
74
+ return self::ENDPOINT_PATH . strtoupper($this->getCountry()) . '/' . $this->getMasterMerchantId() . '/' .
75
+ $this->getMerchantTransactionId();
76
+ }
77
+
78
+ /**
79
+ * @inheritdoc
80
+ */
81
+ public function getHeaders()
82
+ {
83
+ return array(
84
+ 'Authorization' => 'Bearer ' . $this->getAccessToken()
85
+ );
86
+ }
87
+
88
+ /**
89
+ * Master Merchant Id Getter
90
+ * @return null
91
+ */
92
+ public function getMasterMerchantId()
93
+ {
94
+ return $this->_masterMerchantId;
95
+ }
96
+
97
+ /**
98
+ * Merchant Transaction Id Getter
99
+ * @return null|string
100
+ */
101
+ public function getMerchantTransactionId()
102
+ {
103
+ return $this->_merchantTransactionId;
104
+ }
105
+
106
+
107
+
108
+ /**
109
+ * @inheritdoc
110
+ */
111
+ public function getMethod()
112
+ {
113
+ return Varien_Http_Client::GET;
114
+ }
115
+
116
+ /**
117
+ * Access Token Setter
118
+ * @param mixed $accessToken
119
+ */
120
+ public function setAccessToken($accessToken)
121
+ {
122
+ $this->_accessToken = $accessToken;
123
+ }
124
+
125
+ /**
126
+ * Access Token Setter
127
+ * @param mixed $country
128
+ */
129
+ public function setCountry($country)
130
+ {
131
+ $this->_country = trim((string) $country);
132
+ }
133
+
134
+ /**
135
+ * Master Merchant Id Setter
136
+ * @param mixed $masterMerchantId
137
+ */
138
+ public function setMasterMerchantId($masterMerchantId)
139
+ {
140
+ $this->_masterMerchantId = trim((string)$masterMerchantId);
141
+ }
142
+
143
+ /**
144
+ * Merchant Transaction Id Setter
145
+ * @param mixed $merchantTransactionId
146
+ */
147
+ public function setMerchantTransactionId($merchantTransactionId)
148
+ {
149
+ $this->_merchantTransactionId = trim((string) $merchantTransactionId);
150
+ }
151
+
152
+ /**
153
+ * @inheritdoc
154
+ */
155
+ public function validate()
156
+ {
157
+ return ($this->getAccessToken() && $this->getCountry() &&
158
+ $this->getMasterMerchantId() && $this->getMerchantTransactionId());
159
+ }
160
+ }
app/code/community/Tigo/TigoMoney/Model/Payment/Redirect/Api/TransactionStatusResponse.php ADDED
@@ -0,0 +1,681 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Tigo_TigoMoney_Model_Payment_Redirect_Api_TransactionStatusResponse
5
+ */
6
+ class Tigo_TigoMoney_Model_Payment_Redirect_Api_TransactionStatusResponse extends
7
+ Tigo_TigoMoney_Model_Payment_Redirect_Api_AbstractResponse
8
+ {
9
+
10
+ /**
11
+ * Response data key - Callback Uri
12
+ */
13
+ const RESPONSE_DATA_KEY_CALLBACK_URI = 'callback_uri';
14
+
15
+ /**
16
+ * Response data key - Exchange Rate
17
+ */
18
+ const RESPONSE_DATA_KEY_EXCHANGE_RATE = 'exchange_rate';
19
+
20
+ /**
21
+ * Response data key - Language
22
+ */
23
+ const RESPONSE_DATA_KEY_LANGUAGE = 'language';
24
+
25
+ /**
26
+ * Response data key - Local Payment - Amount
27
+ */
28
+ const RESPONSE_DATA_KEY_LOCAL_PAYMENT_AMOUNT = 'local_payment_amount';
29
+
30
+ /**
31
+ * Response data key - Local Payment - Currency Code
32
+ */
33
+ const RESPONSE_DATA_KEY_LOCAL_PAYMENT_CURRENCY_CODE = 'local_payment_currency_code';
34
+
35
+ /**
36
+ * Response data key - Master Merchant - Account
37
+ */
38
+ const RESPONSE_DATA_KEY_MASTER_MERCHANT_ACCOUNT = 'master_merchant_account';
39
+
40
+ /**
41
+ * Response data key - Master Merchant - Id
42
+ */
43
+ const RESPONSE_DATA_KEY_MASTER_MERCHANT_ID = 'master_merchant_id';
44
+
45
+ /**
46
+ * Response data key - Merchant - Currency Code
47
+ */
48
+ const RESPONSE_DATA_KEY_MERCHANT_CURRENCY_CODE = 'merchant_currency_code';
49
+
50
+ /**
51
+ * Response data key - Merchant - Fee
52
+ */
53
+ const RESPONSE_DATA_KEY_MERCHANT_FEE = 'merchant_fee';
54
+
55
+ /**
56
+ * Response data key - Merchant - Reference
57
+ */
58
+ const RESPONSE_DATA_KEY_MERCHANT_REFERENCE = 'merchant_reference';
59
+
60
+ /**
61
+ * Response data key - Origin Payment - Amount
62
+ */
63
+ const RESPONSE_DATA_KEY_ORIGIN_PAYMENT_AMOUNT = 'origin_payment_amount';
64
+
65
+ /**
66
+ * Response data key - Origin Payment - Currency Code
67
+ */
68
+ const RESPONSE_DATA_KEY_ORIGIN_PAYMENT_CURRENCY_CODE = 'origin_payment_currency_code';
69
+
70
+ /**
71
+ * Response data key - Origin Payment - Fee
72
+ */
73
+ const RESPONSE_DATA_KEY_ORIGIN_PAYMENT_FEE = 'origin_payment_fee';
74
+
75
+ /**
76
+ * Response data key - Origin Payment - Tax
77
+ */
78
+ const RESPONSE_DATA_KEY_ORIGIN_PAYMENT_TAX = 'origin_payment_tax';
79
+
80
+ /**
81
+ * Response data key - Redirect Uri
82
+ */
83
+ const RESPONSE_DATA_KEY_REDIRECT_URI = 'redirect_uri';
84
+
85
+ /**
86
+ * Response data key - Subscriber - Account
87
+ */
88
+ const RESPONSE_DATA_KEY_SUBSCRIBER_ACCOUNT = 'subscriber_account';
89
+
90
+ /**
91
+ * Response data key - Subscriber - Country
92
+ */
93
+ const RESPONSE_DATA_KEY_SUBSCRIBER_COUNTRY = 'subscriber_country';
94
+
95
+ /**
96
+ * Response data key - Subscriber - Country Code
97
+ */
98
+ const RESPONSE_DATA_KEY_SUBSCRIBER_COUNTRY_CODE = 'subscriber_country_code';
99
+
100
+ /**
101
+ * Response data key - Subscriber - Email
102
+ */
103
+ const RESPONSE_DATA_KEY_SUBSCRIBER_EMAIL = 'subscriber_email';
104
+
105
+ /**
106
+ * Response data key - Subscriber - First Name
107
+ */
108
+ const RESPONSE_DATA_KEY_SUBSCRIBER_FIRST_NAME = 'subscriber_first_name';
109
+
110
+ /**
111
+ * Response data key - Subscriber - Last Name
112
+ */
113
+ const RESPONSE_DATA_KEY_SUBSCRIBER_LAST_NAME = 'subscriber_last_name';
114
+
115
+ /**
116
+ * Response data key - Terminal Id
117
+ */
118
+ const RESPONSE_DATA_KEY_TERMINAL_ID = 'terminal_id';
119
+
120
+ /**
121
+ * Response data key - Transaction - Completed On
122
+ */
123
+ const RESPONSE_DATA_KEY_TRANSACTION_COMPLETED_ON = 'transaction_completed_on';
124
+
125
+ /**
126
+ * Response data key - Transaction - Correlation Id
127
+ */
128
+ const RESPONSE_DATA_KEY_TRANSACTION_CORRELATION_ID = 'transaction_correlation_id';
129
+
130
+ /**
131
+ * Response data key - Transaction - Created On
132
+ */
133
+ const RESPONSE_DATA_KEY_TRANSACTION_CREATED_ON = 'transaction_created_on';
134
+
135
+ /**
136
+ * Response data key - Transaction - Merchant Transaction Id
137
+ */
138
+ const RESPONSE_DATA_KEY_TRANSACTION_MERCHANT_TRANSACTION_ID = 'transaction_merchant_transaction_id';
139
+
140
+ /**
141
+ * Response data key - Transaction - MFS Transaction Id
142
+ */
143
+ const RESPONSE_DATA_KEY_TRANSACTION_MFS_TRANSACTION_ID = 'transaction_mfs_transaction_id';
144
+
145
+ /**
146
+ * Response data key - Transaction - Status
147
+ */
148
+ const RESPONSE_DATA_KEY_TRANSACTION_STATUS = 'transaction_status';
149
+
150
+ /**
151
+ * Gets Callback Uri from response data
152
+ * @return string|null
153
+ */
154
+ public function getCallbackUrl()
155
+ {
156
+ return $this->getResponseData(self::RESPONSE_DATA_KEY_CALLBACK_URI);
157
+ }
158
+
159
+ /**
160
+ * Gets Exchange rate from response data
161
+ * @return float|null
162
+ */
163
+ public function getExchangeRate()
164
+ {
165
+ return $this->getResponseData(self::RESPONSE_DATA_KEY_EXCHANGE_RATE);
166
+ }
167
+
168
+ /**
169
+ * Gets Language from response data
170
+ * @return string|null
171
+ */
172
+ public function getLanguage()
173
+ {
174
+ return $this->getResponseData(self::RESPONSE_DATA_KEY_LANGUAGE);
175
+ }
176
+
177
+ /**
178
+ * Gets Local payment amount from response data
179
+ * @return float|null
180
+ */
181
+ public function getLocalPaymentAmount()
182
+ {
183
+ return $this->getResponseData(self::RESPONSE_DATA_KEY_LOCAL_PAYMENT_AMOUNT);
184
+ }
185
+
186
+ /**
187
+ * Gets Local payment currency code from response data
188
+ * @return string|null
189
+ */
190
+ public function getLocalPaymentCurrencyCode()
191
+ {
192
+ return $this->getResponseData(self::RESPONSE_DATA_KEY_LOCAL_PAYMENT_CURRENCY_CODE);
193
+ }
194
+
195
+ /**
196
+ * Gets Master_merchant_account from response data
197
+ * @return string|null
198
+ */
199
+ public function getMasterMerchantAccount()
200
+ {
201
+ return $this->getResponseData(self::RESPONSE_DATA_KEY_MASTER_MERCHANT_ACCOUNT);
202
+ }
203
+
204
+ /**
205
+ * Gets Master_merchant_id from response data
206
+ * @return string|null
207
+ */
208
+ public function getMasterMerchantId()
209
+ {
210
+ return $this->getResponseData(self::RESPONSE_DATA_KEY_MASTER_MERCHANT_ID);
211
+ }
212
+
213
+ /**
214
+ * Gets Merchant_currency_code from response data
215
+ * @return string|null
216
+ */
217
+ public function getMerchantCurrencyCode()
218
+ {
219
+ return $this->getResponseData(self::RESPONSE_DATA_KEY_MERCHANT_CURRENCY_CODE);
220
+ }
221
+
222
+ /**
223
+ * Gets Merchant_fee from response data
224
+ * @return float|null
225
+ */
226
+ public function getMerchantFee()
227
+ {
228
+ return $this->getResponseData(self::RESPONSE_DATA_KEY_MERCHANT_FEE);
229
+ }
230
+
231
+ /**
232
+ * Gets Merchant_reference from response data
233
+ * @return string|null
234
+ */
235
+ public function getMerchantReference()
236
+ {
237
+ return $this->getResponseData(self::RESPONSE_DATA_KEY_MERCHANT_REFERENCE);
238
+ }
239
+
240
+ /**
241
+ * Gets Origin_payment_amount from response data
242
+ * @return float|null
243
+ */
244
+ public function getOriginPaymentAmount()
245
+ {
246
+ return $this->getResponseData(self::RESPONSE_DATA_KEY_ORIGIN_PAYMENT_AMOUNT);
247
+ }
248
+
249
+ /**
250
+ * Gets Origin_payment_currency_code from response data
251
+ * @return string|null
252
+ */
253
+ public function getOriginPaymentCurrencyCode()
254
+ {
255
+ return $this->getResponseData(self::RESPONSE_DATA_KEY_ORIGIN_PAYMENT_CURRENCY_CODE);
256
+ }
257
+
258
+ /**
259
+ * Gets Origin_payment_fee from response data
260
+ * @return float|null
261
+ */
262
+ public function getOriginPaymentFee()
263
+ {
264
+ return $this->getResponseData(self::RESPONSE_DATA_KEY_ORIGIN_PAYMENT_FEE);
265
+ }
266
+
267
+ /**
268
+ * Gets Origin_payment_tax from response data
269
+ * @return float|null
270
+ */
271
+ public function getOriginPaymentTax()
272
+ {
273
+ return $this->getResponseData(self::RESPONSE_DATA_KEY_ORIGIN_PAYMENT_TAX);
274
+ }
275
+
276
+ /**
277
+ * Gets Redirect_uri from response data
278
+ * @return string|null
279
+ */
280
+ public function getRedirectUri()
281
+ {
282
+ return $this->getResponseData(self::RESPONSE_DATA_KEY_REDIRECT_URI);
283
+ }
284
+
285
+ /**
286
+ * Gets Subscriber_account from response data
287
+ * @return string|null
288
+ */
289
+ public function getSubscriberAccount()
290
+ {
291
+ return $this->getResponseData(self::RESPONSE_DATA_KEY_SUBSCRIBER_ACCOUNT);
292
+ }
293
+
294
+ /**
295
+ * Gets Subscriber_country from response data
296
+ * @return string|null
297
+ */
298
+ public function getSubscriberCountry()
299
+ {
300
+ return $this->getResponseData(self::RESPONSE_DATA_KEY_SUBSCRIBER_COUNTRY);
301
+ }
302
+
303
+ /**
304
+ * Gets Subscriber_country_code from response data
305
+ * @return string|null
306
+ */
307
+ public function getSubscriberCountryCode()
308
+ {
309
+ return $this->getResponseData(self::RESPONSE_DATA_KEY_SUBSCRIBER_COUNTRY_CODE);
310
+ }
311
+
312
+ /**
313
+ * Gets Subscriber_email from response data
314
+ * @return string|null
315
+ */
316
+ public function getSubscriberEmail()
317
+ {
318
+ return $this->getResponseData(self::RESPONSE_DATA_KEY_SUBSCRIBER_EMAIL);
319
+ }
320
+
321
+ /**
322
+ * Gets Subscriber_first_name from response data
323
+ * @return string|null
324
+ */
325
+ public function getSubscriberFirstName()
326
+ {
327
+ return $this->getResponseData(self::RESPONSE_DATA_KEY_SUBSCRIBER_FIRST_NAME);
328
+ }
329
+
330
+ /**
331
+ * Gets Subscriber_last_name from response data
332
+ * @return string|null
333
+ */
334
+ public function getSubscriberLastName()
335
+ {
336
+ return $this->getResponseData(self::RESPONSE_DATA_KEY_SUBSCRIBER_LAST_NAME);
337
+ }
338
+
339
+ /**
340
+ * Gets Terminal_id from response data
341
+ * @return string|null
342
+ */
343
+ public function getTerminalId()
344
+ {
345
+ return $this->getResponseData(self::RESPONSE_DATA_KEY_TERMINAL_ID);
346
+ }
347
+
348
+ /**
349
+ * Gets Transaction_completed_on from response data
350
+ * @return string|null
351
+ */
352
+ public function getTransactionCompletedOn()
353
+ {
354
+ return $this->getResponseData(self::RESPONSE_DATA_KEY_TRANSACTION_COMPLETED_ON);
355
+ }
356
+
357
+ /**
358
+ * Gets Transaction_correlation_id from response data
359
+ * @return string|null
360
+ */
361
+ public function getTransactionCorrelationId()
362
+ {
363
+ return $this->getResponseData(self::RESPONSE_DATA_KEY_TRANSACTION_CORRELATION_ID);
364
+ }
365
+
366
+ /**
367
+ * Gets Transaction_created_on from response data
368
+ * @return string|null
369
+ */
370
+ public function getTransactionCreatedOn()
371
+ {
372
+ return $this->getResponseData(self::RESPONSE_DATA_KEY_TRANSACTION_CREATED_ON);
373
+ }
374
+
375
+ /**
376
+ * Gets Transaction_merchant_transaction_id from response data
377
+ * @return string|null
378
+ */
379
+ public function getTransactionMerchantTransactionId()
380
+ {
381
+ return $this->getResponseData(self::RESPONSE_DATA_KEY_TRANSACTION_MERCHANT_TRANSACTION_ID);
382
+ }
383
+
384
+ /**
385
+ * Gets Transaction_mfs_transaction_id from response data
386
+ * @return string|null
387
+ */
388
+ public function getTransactionMfsTransactionId()
389
+ {
390
+ return $this->getResponseData(self::RESPONSE_DATA_KEY_TRANSACTION_MFS_TRANSACTION_ID);
391
+ }
392
+
393
+ /**
394
+ * Gets Transaction_status from response data
395
+ * @return string|null
396
+ */
397
+ public function getTransactionStatus()
398
+ {
399
+ return $this->getResponseData(self::RESPONSE_DATA_KEY_TRANSACTION_STATUS);
400
+ }
401
+
402
+ /**
403
+ * Sets Callback_uri to response data
404
+ * @param mixed $input
405
+ * @return $this
406
+ */
407
+ public function setCallbackUri($input)
408
+ {
409
+ return $this->addResponseData(self::RESPONSE_DATA_KEY_CALLBACK_URI, (string) $input);
410
+ }
411
+
412
+ /**
413
+ * Sets Exchange_rate to response data
414
+ * @param mixed $input
415
+ * @return $this
416
+ */
417
+ public function setExchangeRate($input)
418
+ {
419
+ return $this->addResponseData(self::RESPONSE_DATA_KEY_EXCHANGE_RATE, (float) $input);
420
+ }
421
+
422
+ /**
423
+ * Sets Language to response data
424
+ * @param mixed $input
425
+ * @return $this
426
+ */
427
+ public function setLanguage($input)
428
+ {
429
+ return $this->addResponseData(self::RESPONSE_DATA_KEY_LANGUAGE, (string) $input);
430
+ }
431
+
432
+ /**
433
+ * Sets Local_payment_amount to response data
434
+ * @param mixed $input
435
+ * @return $this
436
+ */
437
+ public function setLocalPaymentAmount($input)
438
+ {
439
+ return $this->addResponseData(self::RESPONSE_DATA_KEY_LOCAL_PAYMENT_AMOUNT, (float) $input);
440
+ }
441
+
442
+ /**
443
+ * Sets Local_payment_currency_code to response data
444
+ * @param mixed $input
445
+ * @return $this
446
+ */
447
+ public function setLocalPaymentCurrencyCode($input)
448
+ {
449
+ return $this->addResponseData(self::RESPONSE_DATA_KEY_LOCAL_PAYMENT_CURRENCY_CODE, (string) $input);
450
+ }
451
+
452
+ /**
453
+ * Sets Master_merchant_account to response data
454
+ * @param mixed $input
455
+ * @return $this
456
+ */
457
+ public function setMasterMerchantAccount($input)
458
+ {
459
+ return $this->addResponseData(self::RESPONSE_DATA_KEY_MASTER_MERCHANT_ACCOUNT, (string) $input);
460
+ }
461
+
462
+ /**
463
+ * Sets Master_merchant_id to response data
464
+ * @param mixed $input
465
+ * @return $this
466
+ */
467
+ public function setMasterMerchantId($input)
468
+ {
469
+ return $this->addResponseData(self::RESPONSE_DATA_KEY_MASTER_MERCHANT_ID, (string) $input);
470
+ }
471
+
472
+ /**
473
+ * Sets Merchant_currency_code to response data
474
+ * @param mixed $input
475
+ * @return $this
476
+ */
477
+ public function setMerchantCurrencyCode($input)
478
+ {
479
+ return $this->addResponseData(self::RESPONSE_DATA_KEY_MERCHANT_CURRENCY_CODE, (string) $input);
480
+ }
481
+
482
+ /**
483
+ * Sets Merchant_fee to response data
484
+ * @param mixed $input
485
+ * @return $this
486
+ */
487
+ public function setMerchantFee($input)
488
+ {
489
+ return $this->addResponseData(self::RESPONSE_DATA_KEY_MERCHANT_FEE, (float) $input);
490
+ }
491
+
492
+ /**
493
+ * Sets Merchant_reference to response data
494
+ * @param mixed $input
495
+ * @return $this
496
+ */
497
+ public function setMerchantReference($input)
498
+ {
499
+ return $this->addResponseData(self::RESPONSE_DATA_KEY_MERCHANT_REFERENCE, (string) $input);
500
+ }
501
+
502
+ /**
503
+ * Sets Origin_payment_amount to response data
504
+ * @param mixed $input
505
+ * @return $this
506
+ */
507
+ public function setOriginPaymentAmount($input)
508
+ {
509
+ return $this->addResponseData(self::RESPONSE_DATA_KEY_ORIGIN_PAYMENT_AMOUNT, (float) $input);
510
+ }
511
+
512
+ /**
513
+ * Sets Origin_payment_currency_code to response data
514
+ * @param mixed $input
515
+ * @return $this
516
+ */
517
+ public function setOriginPaymentCurrencyCode($input)
518
+ {
519
+ return $this->addResponseData(self::RESPONSE_DATA_KEY_ORIGIN_PAYMENT_CURRENCY_CODE, (string) $input);
520
+ }
521
+
522
+ /**
523
+ * Sets Origin_payment_fee to response data
524
+ * @param mixed $input
525
+ * @return $this
526
+ */
527
+ public function setOriginPaymentFee($input)
528
+ {
529
+ return $this->addResponseData(self::RESPONSE_DATA_KEY_ORIGIN_PAYMENT_FEE, (float) $input);
530
+ }
531
+
532
+ /**
533
+ * Sets Origin_payment_tax to response data
534
+ * @param mixed $input
535
+ * @return $this
536
+ */
537
+ public function setOriginPaymentTax($input)
538
+ {
539
+ return $this->addResponseData(self::RESPONSE_DATA_KEY_ORIGIN_PAYMENT_TAX, (float) $input);
540
+ }
541
+
542
+ /**
543
+ * Sets Redirect_uri to response data
544
+ * @param mixed $input
545
+ * @return $this
546
+ */
547
+ public function setRedirectUri($input)
548
+ {
549
+ return $this->addResponseData(self::RESPONSE_DATA_KEY_REDIRECT_URI, (string) $input);
550
+ }
551
+
552
+ /**
553
+ * Sets Subscriber_account to response data
554
+ * @param mixed $input
555
+ * @return $this
556
+ */
557
+ public function setSubscriberAccount($input)
558
+ {
559
+ return $this->addResponseData(self::RESPONSE_DATA_KEY_SUBSCRIBER_ACCOUNT, (string) $input);
560
+ }
561
+
562
+ /**
563
+ * Sets Subscriber_country to response data
564
+ * @param mixed $input
565
+ * @return $this
566
+ */
567
+ public function setSubscriberCountry($input)
568
+ {
569
+ return $this->addResponseData(self::RESPONSE_DATA_KEY_SUBSCRIBER_COUNTRY, (string) $input);
570
+ }
571
+
572
+ /**
573
+ * Sets Subscriber_country_code to response data
574
+ * @param mixed $input
575
+ * @return $this
576
+ */
577
+ public function setSubscriberCountryCode($input)
578
+ {
579
+ return $this->addResponseData(self::RESPONSE_DATA_KEY_SUBSCRIBER_COUNTRY_CODE, (string) $input);
580
+ }
581
+
582
+ /**
583
+ * Sets Subscriber_email to response data
584
+ * @param mixed $input
585
+ * @return $this
586
+ */
587
+ public function setSubscriberEmail($input)
588
+ {
589
+ return $this->addResponseData(self::RESPONSE_DATA_KEY_SUBSCRIBER_EMAIL, (string) $input);
590
+ }
591
+
592
+ /**
593
+ * Sets Subscriber_first_name to response data
594
+ * @param mixed $input
595
+ * @return $this
596
+ */
597
+ public function setSubscriberFirstName($input)
598
+ {
599
+ return $this->addResponseData(self::RESPONSE_DATA_KEY_SUBSCRIBER_FIRST_NAME, (string) $input);
600
+ }
601
+
602
+ /**
603
+ * Sets Subscriber_last_name to response data
604
+ * @param mixed $input
605
+ * @return $this
606
+ */
607
+ public function setSubscriberLastName($input)
608
+ {
609
+ return $this->addResponseData(self::RESPONSE_DATA_KEY_SUBSCRIBER_LAST_NAME, (string) $input);
610
+ }
611
+
612
+ /**
613
+ * Sets Terminal_id to response data
614
+ * @param mixed $input
615
+ * @return $this
616
+ */
617
+ public function setTerminalId($input)
618
+ {
619
+ return $this->addResponseData(self::RESPONSE_DATA_KEY_TERMINAL_ID, (string) $input);
620
+ }
621
+
622
+ /**
623
+ * Sets Transaction_completed_on to response data
624
+ * @param mixed $input
625
+ * @return $this
626
+ */
627
+ public function setTransactionCompletedOn($input)
628
+ {
629
+ return $this->addResponseData(self::RESPONSE_DATA_KEY_TRANSACTION_COMPLETED_ON, (string) $input);
630
+ }
631
+
632
+ /**
633
+ * Sets Transaction_correlation_id to response data
634
+ * @param mixed $input
635
+ * @return $this
636
+ */
637
+ public function setTransactionCorrelationId($input)
638
+ {
639
+ return $this->addResponseData(self::RESPONSE_DATA_KEY_TRANSACTION_CORRELATION_ID, (string) $input);
640
+ }
641
+
642
+ /**
643
+ * Sets Transaction_created_on to response data
644
+ * @param mixed $input
645
+ * @return $this
646
+ */
647
+ public function setTransactionCreatedOn($input)
648
+ {
649
+ return $this->addResponseData(self::RESPONSE_DATA_KEY_TRANSACTION_CREATED_ON, (string) $input);
650
+ }
651
+
652
+ /**
653
+ * Sets Transaction_merchant_transaction_id to response data
654
+ * @param mixed $input
655
+ * @return $this
656
+ */
657
+ public function setTransactionMerchantTransactionId($input)
658
+ {
659
+ return $this->addResponseData(self::RESPONSE_DATA_KEY_TRANSACTION_MERCHANT_TRANSACTION_ID, (string) $input);
660
+ }
661
+
662
+ /**
663
+ * Sets Transaction_mfs_transaction_id to response data
664
+ * @param mixed $input
665
+ * @return $this
666
+ */
667
+ public function setTransactionMfsTransactionId($input)
668
+ {
669
+ return $this->addResponseData(self::RESPONSE_DATA_KEY_TRANSACTION_MFS_TRANSACTION_ID, (string) $input);
670
+ }
671
+
672
+ /**
673
+ * Sets Transaction_status to response data
674
+ * @param mixed $input
675
+ * @return $this
676
+ */
677
+ public function setTransactionStatus($input)
678
+ {
679
+ return $this->addResponseData(self::RESPONSE_DATA_KEY_TRANSACTION_STATUS, (string) $input);
680
+ }
681
+ }
app/code/community/Tigo/TigoMoney/Model/Payment/Redirect/Sync.php ADDED
@@ -0,0 +1,484 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Tigo_TigoMoney_Model_Payment_Redirect_Sync
5
+ */
6
+ class Tigo_TigoMoney_Model_Payment_Redirect_Sync
7
+ {
8
+ /**
9
+ * Parameter Key - Merchant Transaction Id
10
+ */
11
+ const PARAM_KEY_MERCHANT_ACCESS_TOKEN = 'accessToken';
12
+
13
+ /**
14
+ * Parameter Key - Merchant Transaction Id
15
+ */
16
+ const PARAM_KEY_MERCHANT_TRANSACTION_ID = 'merchantTransactionId';
17
+
18
+ /**
19
+ * Parameter Key - MFS Transaction Id
20
+ */
21
+ const PARAM_KEY_MFS_TRANSACTION_ID = 'mfsTransactionId';
22
+
23
+ /**
24
+ * Parameter Key - Transaction Code
25
+ */
26
+ const PARAM_KEY_TRANSACTION_CODE = 'transactionCode';
27
+
28
+ /**
29
+ * Parameter Key - Transaction Description
30
+ */
31
+ const PARAM_KEY_TRANSACTION_DESCRIPTION = 'transactionDescription';
32
+
33
+ /**
34
+ * Parameter Key - Transaction Status
35
+ */
36
+ const PARAM_KEY_TRANSACTION_STATUS = 'transactionStatus';
37
+
38
+ /**
39
+ * Parameter Value - Transaction Status Cancel
40
+ */
41
+ const PARAM_VALUE_TRANSACTION_STATUS_CANCEL = 'cancel';
42
+
43
+ /**
44
+ * Parameter Value - Transaction Status Failure
45
+ */
46
+ const PARAM_VALUE_TRANSACTION_STATUS_FAILURE = 'fail';
47
+
48
+ /**
49
+ * Parameter Value - Transaction Status Initiated
50
+ */
51
+ const PARAM_VALUE_TRANSACTION_STATUS_INITIATED = 'initiated';
52
+
53
+ /**
54
+ * Parameter Value - Transaction Status Success
55
+ */
56
+ const PARAM_VALUE_TRANSACTION_STATUS_SUCCESS = 'success';
57
+
58
+ /**
59
+ * Api
60
+ * @var null|Tigo_TigoMoney_Model_Payment_Redirect_Api
61
+ */
62
+ protected $_api = null;
63
+
64
+ /**
65
+ * Data Helper
66
+ * @var null|Tigo_TigoMoney_Helper_Data
67
+ */
68
+ protected $_dataHelper = null;
69
+
70
+ /**
71
+ * Debug Model
72
+ * @var null|Tigo_TigoMoney_Helper_Data
73
+ */
74
+ protected $_debug = null;
75
+
76
+ /**
77
+ * Request Builder
78
+ * @var null|Tigo_TigoMoney_Model_Payment_Redirect_Api_RequestBuilder
79
+ */
80
+ protected $_requestBuilder = null;
81
+
82
+ /**
83
+ * Sets Request Info as Additional Information on the order payment instance and saves it
84
+ * @param string $mfsTransactionId
85
+ * @param string $transactionCode
86
+ * @param string $transactionDescription
87
+ * @param string $transactionStatus
88
+ * @param Mage_Sales_Model_Order $order
89
+ * @return $this
90
+ */
91
+ protected function _addTransactionInfoToOrder(
92
+ $mfsTransactionId,
93
+ $transactionCode,
94
+ $transactionDescription,
95
+ $transactionStatus,
96
+ Mage_Sales_Model_Order $order
97
+ ) {
98
+ $payment = $order->getPayment();
99
+
100
+ if ($mfsTransactionId) {
101
+ $payment->setAdditionalInformation(
102
+ Tigo_TigoMoney_Model_Payment_Redirect::ADDITIONAL_INFO_KEY_MFS_TRANSACTION_ID,
103
+ $mfsTransactionId
104
+ );
105
+ }
106
+
107
+ if ($transactionCode) {
108
+ $payment->setAdditionalInformation(
109
+ Tigo_TigoMoney_Model_Payment_Redirect::ADDITIONAL_INFO_KEY_TRANSACTION_CODE,
110
+ $transactionCode
111
+ );
112
+ }
113
+
114
+ if ($transactionDescription) {
115
+ $payment->setAdditionalInformation(
116
+ Tigo_TigoMoney_Model_Payment_Redirect::ADDITIONAL_INFO_KEY_TRANSACTION_DESCRIPTION,
117
+ $transactionDescription
118
+ );
119
+ }
120
+
121
+ if ($transactionStatus) {
122
+ $payment->setAdditionalInformation(
123
+ Tigo_TigoMoney_Model_Payment_Redirect::ADDITIONAL_INFO_KEY_TRANSACTION_STATUS,
124
+ $transactionStatus
125
+ );
126
+ }
127
+
128
+ $payment->save();
129
+
130
+ return $this;
131
+ }
132
+
133
+ /**
134
+ * Cancels an order
135
+ * @param Mage_Sales_Model_Order $order
136
+ * @return $this
137
+ */
138
+ public function _cancelOrder(Mage_Sales_Model_Order $order)
139
+ {
140
+ if ($order->canCancel()) {
141
+ $order
142
+ ->cancel()
143
+ ->save();
144
+ }
145
+ return $this;
146
+ }
147
+
148
+ /**
149
+ * Creates an invoice for an order
150
+ * @param Mage_Sales_Model_Order $order
151
+ * @return $this
152
+ */
153
+ public function _createInvoice(Mage_Sales_Model_Order $order)
154
+ {
155
+ if ($order->canInvoice()) {
156
+ $invoice = $order->prepareInvoice();
157
+ $invoice
158
+ ->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE)
159
+ ->register();
160
+
161
+ $transaction = $this->_getResourceTransactionInstance();
162
+ $transaction
163
+ ->addObject($invoice)
164
+ ->addObject($invoice->getOrder())
165
+ ->save();
166
+ }
167
+ return $this;
168
+ }
169
+
170
+ /**
171
+ * Writes info to debug file
172
+ * @param string $requestBody
173
+ */
174
+ protected function _debugRequest($requestBody)
175
+ {
176
+ $request = Mage::app()->getRequest();
177
+ $this->_getDebug()->debug('---- Callback from Tigo Payment Server ---');
178
+ $this->_getDebug()->debug('Route: ' .
179
+ $request->getRequestedRouteName() . '/' .
180
+ $request->getControllerName() . '/' .
181
+ $request->getActionName() . '/'
182
+ );
183
+ $this->_getDebug()->debug($requestBody);
184
+ }
185
+
186
+ /**
187
+ * Extracts info from request
188
+ * @param array $requestArray
189
+ * @return Varien_Object
190
+ */
191
+ protected function _extractRequest($requestArray)
192
+ {
193
+ $this->_debugRequest($requestArray);
194
+
195
+ $return = $this->_getVarienObjectInstance();
196
+
197
+ foreach($requestArray as $key => $value) {
198
+ $value = trim($value);
199
+ if ($value && $value != 'undefined') {
200
+ $return->setData(trim($key), $value);
201
+ }
202
+ }
203
+
204
+ return $return;
205
+ }
206
+
207
+ /**
208
+ * Api Getter
209
+ * @return Tigo_TigoMoney_Model_Payment_Redirect_Api
210
+ */
211
+ protected function _getApi()
212
+ {
213
+ if ($this->_api === null) {
214
+ $this->_api = Mage::getModel('tigo_tigomoney/payment_redirect_api');
215
+ }
216
+ return $this->_api;
217
+ }
218
+
219
+ /**
220
+ * Data Helper Getter
221
+ * @return Tigo_TigoMoney_Helper_Data
222
+ */
223
+ protected function _getDataHelper()
224
+ {
225
+ if ($this->_dataHelper === null) {
226
+ $this->_dataHelper = Mage::helper('tigo_tigomoney');
227
+ }
228
+ return $this->_dataHelper;
229
+ }
230
+
231
+ /**
232
+ * Debug Model Getter
233
+ * @return Tigo_TigoMoney_Model_Debug
234
+ */
235
+ protected function _getDebug()
236
+ {
237
+ if ($this->_debug === null) {
238
+ $this->_debug = Mage::getModel('tigo_tigomoney/debug');
239
+ }
240
+ return $this->_debug;
241
+ }
242
+
243
+ /**
244
+ * Request Builder Getter
245
+ * @return Tigo_TigoMoney_Model_Payment_Redirect_Api_RequestBuilder
246
+ */
247
+ protected function _getRequestBuilder()
248
+ {
249
+ if ($this->_requestBuilder === null) {
250
+ $this->_requestBuilder = Mage::getModel('tigo_tigomoney/payment_redirect_api_requestBuilder');
251
+ }
252
+ return $this->_requestBuilder;
253
+ }
254
+
255
+ /**
256
+ * Returns new Mage_Core_Model_Resource_Transaction instance
257
+ * @return Mage_Core_Model_Resource_Transaction
258
+ */
259
+ protected function _getResourceTransactionInstance()
260
+ {
261
+ return Mage::getModel('core/resource_transaction');
262
+ }
263
+
264
+ /**
265
+ * Returns new Mage_Sales_Model_Order instance
266
+ * @return Mage_Sales_Model_Order
267
+ */
268
+ protected function _getSalesOrderInstance()
269
+ {
270
+ return Mage::getModel('sales/order');
271
+ }
272
+
273
+ /**
274
+ * Returns new Varien_Object instance
275
+ * @return Varien_Object
276
+ */
277
+ protected function _getVarienObjectInstance()
278
+ {
279
+ return new Varien_Object();
280
+ }
281
+
282
+ /**
283
+ * Handles a status update callback
284
+ * @param array $requestParams
285
+ * @return bool
286
+ */
287
+ public function handleRequest($requestParams)
288
+ {
289
+ $return = false;
290
+ $request = $this->_extractRequest($requestParams);
291
+ $order = $this->_loadRequestOrder($request);
292
+ if ($order->getId()) {
293
+ $this->_addTransactionInfoToOrder(
294
+ $request->getData(self::PARAM_KEY_MFS_TRANSACTION_ID),
295
+ $request->getData(self::PARAM_KEY_TRANSACTION_CODE),
296
+ $request->getData(self::PARAM_KEY_TRANSACTION_DESCRIPTION),
297
+ $request->getData(self::PARAM_KEY_TRANSACTION_STATUS),
298
+ $order
299
+ );
300
+ if ($this->_isTransactionSuccessful($request)) {
301
+ if ($this->_isValidRequest(
302
+ $order,
303
+ array(self::PARAM_VALUE_TRANSACTION_STATUS_SUCCESS)
304
+ )
305
+ ) {
306
+ $this->_createInvoice($order);
307
+ $return = true;
308
+ }
309
+ } else {
310
+ if ($this->_isValidRequest(
311
+ $order,
312
+ array(self::PARAM_VALUE_TRANSACTION_STATUS_FAILURE, self::PARAM_VALUE_TRANSACTION_STATUS_CANCEL)
313
+ )
314
+ ) {
315
+ $this->_cancelOrder($order);
316
+ }
317
+ }
318
+ }
319
+ return $return;
320
+ }
321
+
322
+ /**
323
+ * Checks whether a request is valid for a specific order
324
+ * @param Mage_Sales_Model_Order $order
325
+ * @param array $status
326
+ * @return bool
327
+ */
328
+ protected function _isValidRequest(Mage_Sales_Model_Order $order, $status)
329
+ {
330
+ $return = false;
331
+
332
+ $accessTokenRequest = $this->_getRequestBuilder()->buildGenerateAccessTokenRequest();
333
+ $accessTokenResponse = $this->_getApi()->getAccessToken($accessTokenRequest);
334
+
335
+ if ($accessTokenResponse->isSuccess()) {
336
+ $transactionStatusRequest = $this->_getRequestBuilder()->buildTransactionStatusRequest(
337
+ $accessTokenResponse->getAccessToken(),
338
+ $order
339
+ );
340
+ $transactionStatusResponse = $this->_getApi()->getTransactionStatus($transactionStatusRequest);
341
+
342
+ $mfsTransactionId = $order->getPayment()->getAdditionalInformation(
343
+ Tigo_TigoMoney_Model_Payment_Redirect::ADDITIONAL_INFO_KEY_MFS_TRANSACTION_ID
344
+ );
345
+
346
+ # The following if checks:
347
+ # 1 - If the transaction status with the tigo payment server is the same informed in the request
348
+ # 2 - If the MFS transaction ID received during the authorization process is the same we are seeing now
349
+ # 3 - If the amount paid is equal or higher the one we received in the store
350
+ if (
351
+ ($transactionStatusResponse->isSuccess()) &&
352
+ (in_array($transactionStatusResponse->getTransactionStatus(), $status)) &&
353
+ ($transactionStatusResponse->getTransactionMfsTransactionId() == $mfsTransactionId) &&
354
+ ($transactionStatusResponse->getLocalPaymentAmount() >= $order->getBaseGrandTotal())
355
+ ) {
356
+ $return = true;
357
+ }
358
+ }
359
+
360
+ return $return;
361
+ }
362
+
363
+ /**
364
+ * Checks if the request is informing of a successful transaction
365
+ * @param Varien_Object $request
366
+ * @return bool
367
+ */
368
+ protected function _isTransactionSuccessful(Varien_Object $request)
369
+ {
370
+ $return = false;
371
+
372
+ $status = $request->getData(self::PARAM_KEY_TRANSACTION_STATUS);
373
+ if ($status == self::PARAM_VALUE_TRANSACTION_STATUS_SUCCESS) {
374
+ $return = true;
375
+ }
376
+
377
+ return $return;
378
+ }
379
+
380
+ /**
381
+ * Loads the order referred to by the incoming request
382
+ * @param Varien_Object $request
383
+ * @return Mage_Sales_Model_Order
384
+ */
385
+ protected function _loadRequestOrder(Varien_Object $request)
386
+ {
387
+ $order = $this->_getSalesOrderInstance();
388
+
389
+ $orderIncrementId = $request->getData(self::PARAM_KEY_MERCHANT_TRANSACTION_ID);
390
+ $order->loadByIncrementId($orderIncrementId);
391
+
392
+ return $order;
393
+ }
394
+
395
+ /**
396
+ * Should we cancel this order?
397
+ * @param Mage_Sales_Model_Order $order
398
+ * @return bool
399
+ */
400
+ protected function _shouldInitiatedOrderBeCanceled(Mage_Sales_Model_Order $order)
401
+ {
402
+ $return = false;
403
+
404
+ $fiveDaysAgo = strtotime('-5 days');
405
+ $orderCreatedAt = strtotime($order->getCreatedAt());
406
+
407
+ if (
408
+ $order->canCancel() &&
409
+ ($orderCreatedAt < $fiveDaysAgo)
410
+ ) {
411
+ $return = true;
412
+ }
413
+
414
+ return $return;
415
+ }
416
+
417
+ /**
418
+ * Handles a status update callback
419
+ * @param Mage_Sales_Model_Order $order
420
+ * @return null|
421
+ */
422
+ public function syncOrder($order)
423
+ {
424
+ $accessTokenRequest = $this->_getRequestBuilder()->buildGenerateAccessTokenRequest();
425
+ $accessTokenResponse = $this->_getApi()->getAccessToken($accessTokenRequest);
426
+
427
+ if ($accessTokenResponse->isSuccess()) {
428
+ $transactionStatusRequest = $this->_getRequestBuilder()->buildTransactionStatusRequest(
429
+ $accessTokenResponse->getAccessToken(),
430
+ $order
431
+ );
432
+ $transactionStatusResponse = $this->_getApi()->getTransactionStatus($transactionStatusRequest);
433
+
434
+ if ($transactionStatusResponse->isSuccess()) {
435
+ $status = $transactionStatusResponse->getTransactionStatus();
436
+
437
+ if ($status == self::PARAM_VALUE_TRANSACTION_STATUS_SUCCESS) {
438
+ /**
439
+ * Order has been paid
440
+ */
441
+ $this->_addTransactionInfoToOrder(
442
+ $transactionStatusResponse->getTransactionMfsTransactionId(),
443
+ null,
444
+ null,
445
+ $transactionStatusResponse->getTransactionStatus(),
446
+ $order
447
+ );
448
+ $this->_createInvoice($order);
449
+ } else if (
450
+ in_array(
451
+ $status,
452
+ array(self::PARAM_VALUE_TRANSACTION_STATUS_FAILURE, self::PARAM_VALUE_TRANSACTION_STATUS_CANCEL)
453
+ )
454
+ ) {
455
+ /**
456
+ * There was an error while the user tried to pay for the order
457
+ */
458
+ $this->_cancelOrder($order);
459
+ } else if ($status == self::PARAM_VALUE_TRANSACTION_STATUS_INITIATED) {
460
+ /**
461
+ * Order has been initiated, but not paid nor canceled
462
+ * In this case, orders will be canceled five days after placed
463
+ */
464
+ if ($this->_shouldInitiatedOrderBeCanceled($order)) {
465
+ $this->_getDebug()->debug(
466
+ $this->_getDataHelper()->__('Canceling initiated order #' . $order->getIncrementId())
467
+ );
468
+ $this->_cancelOrder($order);
469
+ }
470
+ }
471
+
472
+ } else {
473
+ Mage::throwException($this->_getDataHelper()->__(
474
+ 'An error happened while trying to retrieve the transaction status.'
475
+ ));
476
+ }
477
+ } else {
478
+ Mage::throwException($this->_getDataHelper()->__(
479
+ 'An error happened while trying to retrieve the access token.'
480
+ ));
481
+ }
482
+ return $this;
483
+ }
484
+ }
app/code/community/Tigo/TigoMoney/controllers/Adminhtml/Tigomoney/OrderController.php ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Tigo_TigoMoney_Adminhtml_OrderController
5
+ */
6
+ class Tigo_TigoMoney_Adminhtml_Tigomoney_OrderController extends Mage_Adminhtml_Controller_Action
7
+ {
8
+ /**
9
+ * Adminhtml Session
10
+ * @var null|Mage_Adminhtml_Model_Session
11
+ */
12
+ protected $_adminhtmlSession = null;
13
+
14
+ /**
15
+ * Sync Model
16
+ * @var null|Tigo_TigoMoney_Model_Payment_Redirect_Sync
17
+ */
18
+ protected $_sync = null;
19
+
20
+ /**
21
+ * Adminhtml Session Getter
22
+ * @return Mage_Adminhtml_Model_Session
23
+ */
24
+ protected function _getAdminhtmlSession()
25
+ {
26
+ if ($this->_adminhtmlSession === null) {
27
+ $this->_adminhtmlSession = Mage::getSingleton('adminhtml/session');
28
+ }
29
+ return $this->_adminhtmlSession;
30
+ }
31
+
32
+ /**
33
+ * Sync Model Getter
34
+ * @return Tigo_TigoMoney_Model_Payment_Redirect_Sync
35
+ */
36
+ protected function _getSync()
37
+ {
38
+ if ($this->_sync === null) {
39
+ $this->_sync = Mage::getModel('tigo_tigomoney/payment_redirect_sync');
40
+ }
41
+ return $this->_sync;
42
+ }
43
+
44
+ /**
45
+ * Is current user allowed?
46
+ * @return bool
47
+ */
48
+ protected function _isAllowed()
49
+ {
50
+ return Mage::getSingleton('admin/session')->isAllowed('sales/order');
51
+ }
52
+
53
+ /**
54
+ * Instantiates and loads an order
55
+ * @param int $orderId
56
+ * @return Mage_Sales_Model_Order
57
+ */
58
+ protected function _loadOrder($orderId)
59
+ {
60
+ return Mage::getModel('sales/order')->load($orderId);
61
+ }
62
+
63
+ /**
64
+ *
65
+ */
66
+ public function syncAction()
67
+ {
68
+ $orderId = $this->getRequest()->getParam('order_id');
69
+
70
+ $order = $this->_loadOrder($orderId);
71
+
72
+ if ($order->getId()) {
73
+ try {
74
+ $this->_getSync()->syncOrder($order);
75
+ } catch (Exception $e) {
76
+ $this->_getAdminhtmlSession()->addError($this->__(
77
+ 'There was an error while trying to sync your order.'
78
+ ));
79
+ }
80
+ } else {
81
+ $this->_getAdminhtmlSession()->addError($this->__('Specified order could not be found'));
82
+ }
83
+
84
+ return $this->_redirectReferer();
85
+ }
86
+ }
app/code/community/Tigo/TigoMoney/controllers/RedirectController.php ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Tigo_TigoMoney_RedirectController
5
+ */
6
+ class Tigo_TigoMoney_RedirectController extends Mage_Core_Controller_Front_Action
7
+ {
8
+ /**
9
+ * Retrieves Checkout Session
10
+ * @return Mage_Checkout_Model_Session
11
+ */
12
+ protected function _getCheckoutSession()
13
+ {
14
+ return Mage::getSingleton('checkout/session');
15
+ }
16
+
17
+ /**
18
+ * Retrieves last order from checkout session
19
+ * @return Mage_Sales_Model_Order
20
+ */
21
+ protected function _getLastOrder()
22
+ {
23
+ return $this->_getCheckoutSession()->getLastRealOrder();
24
+ }
25
+
26
+ /**
27
+ * Redirects customer to Tigo Payment Server
28
+ */
29
+ public function indexAction()
30
+ {
31
+ $lastOrder = $this->_getLastOrder();
32
+ if (
33
+ $lastOrder->getId() &&
34
+ $lastOrder->getPayment()->getMethod() == Tigo_TigoMoney_Model_Payment_Redirect::METHOD_CODE
35
+ ) {
36
+ $redirectUri = $lastOrder
37
+ ->getPayment()
38
+ ->getAdditionalInformation(Tigo_TigoMoney_Model_Payment_Redirect::ADDITIONAL_INFO_KEY_REDIRECT_URI);
39
+
40
+ if (!$redirectUri) {
41
+ $redirectUri = Mage::getBaseUrl();
42
+ }
43
+ } else {
44
+ $redirectUri = Mage::getBaseUrl();
45
+ }
46
+
47
+ return $this->_redirectUrl($redirectUri);
48
+ }
49
+ }
app/code/community/Tigo/TigoMoney/controllers/ReturnController.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Tigo_TigoMoney_ReturnController
5
+ */
6
+ class Tigo_TigoMoney_ReturnController extends Mage_Core_Controller_Front_Action
7
+ {
8
+ /**
9
+ * Sync Model Instance
10
+ * @var null|Tigo_TigoMoney_Model_Payment_Redirect_Sync
11
+ */
12
+ protected $_sync = null;
13
+
14
+ /**
15
+ * Sync Model Instance Getter
16
+ * @return Tigo_TigoMoney_Model_Payment_Redirect_Sync
17
+ */
18
+ protected function _getSync()
19
+ {
20
+ if ($this->_sync === null) {
21
+ $this->_sync = Mage::getModel('tigo_tigomoney/payment_redirect_sync');
22
+ }
23
+ return $this->_sync;
24
+ }
25
+
26
+ /**
27
+ * Handles the request, if any information received regarding the order
28
+ * @return void
29
+ */
30
+ public function indexAction()
31
+ {
32
+ $requestParams = $this->getRequest()->getParams();
33
+ $success = $this->_getSync()->handleRequest($requestParams);
34
+ if ($success) {
35
+ $this->_redirect('checkout/onepage/success/', array('_secure' => true));
36
+ } else {
37
+ $this->_redirect('checkout/onepage/failure/', array('_secure' => true));
38
+ }
39
+ }
40
+ }
app/code/community/Tigo/TigoMoney/controllers/SyncController.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Tigo_TigoMoney_ReturnController
5
+ */
6
+ class Tigo_TigoMoney_SyncController extends Mage_Core_Controller_Front_Action
7
+ {
8
+ /**
9
+ * Sync Model Instance
10
+ * @var null|Tigo_TigoMoney_Model_Payment_Redirect_Sync
11
+ */
12
+ protected $_sync = null;
13
+
14
+ /**
15
+ * Sync Model Instance Getter
16
+ * @return Tigo_TigoMoney_Model_Payment_Redirect_Sync
17
+ */
18
+ protected function _getSync()
19
+ {
20
+ if ($this->_sync === null) {
21
+ $this->_sync = Mage::getModel('tigo_tigomoney/payment_redirect_sync');
22
+ }
23
+ return $this->_sync;
24
+ }
25
+
26
+ /**
27
+ * Handles the request, if any information received regarding the order
28
+ * @return void
29
+ */
30
+ public function indexAction()
31
+ {
32
+ $requestParams = $this->getRequest()->getParams();
33
+ $this->_getSync()->handleRequest($requestParams);
34
+ }
35
+ }
app/code/community/Tigo/TigoMoney/etc/config.xml ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Tigo_TigoMoney>
5
+ <version>0.1.0</version>
6
+ </Tigo_TigoMoney>
7
+ </modules>
8
+ <global>
9
+ <models>
10
+ <tigo_tigomoney>
11
+ <class>Tigo_TigoMoney_Model</class>
12
+ </tigo_tigomoney>
13
+ </models>
14
+ <blocks>
15
+ <tigo_tigomoney>
16
+ <class>Tigo_TigoMoney_Block</class>
17
+ </tigo_tigomoney>
18
+ <checkout>
19
+ <rewrite>
20
+ <onepage_failure>Tigo_TigoMoney_Block_Rewrite_Checkout_Onepage_Failure</onepage_failure>
21
+ <onepage_success>Tigo_TigoMoney_Block_Rewrite_Checkout_Onepage_Success</onepage_success>
22
+ </rewrite>
23
+ </checkout>
24
+ </blocks>
25
+ <helpers>
26
+ <tigo_tigomoney>
27
+ <class>Tigo_TigoMoney_Helper</class>
28
+ </tigo_tigomoney>
29
+ </helpers>
30
+ </global>
31
+ <frontend>
32
+ <routers>
33
+ <tigomoney>
34
+ <use>standard</use>
35
+ <args>
36
+ <module>Tigo_TigoMoney</module>
37
+ <frontName>tigomoney</frontName>
38
+ </args>
39
+ </tigomoney>
40
+ </routers>
41
+ <translate>
42
+ <modules>
43
+ <Tigo_TigoMoney>
44
+ <files>
45
+ <default>Tigo_TigoMoney.csv</default>
46
+ </files>
47
+ </Tigo_TigoMoney>
48
+ </modules>
49
+ </translate>
50
+ </frontend>
51
+ <admin>
52
+ <routers>
53
+ <adminhtml>
54
+ <args>
55
+ <modules>
56
+ <tigomoney before="Mage_Adminhtml">Tigo_TigoMoney_Adminhtml</tigomoney>
57
+ </modules>
58
+ </args>
59
+ </adminhtml>
60
+ </routers>
61
+ </admin>
62
+ <adminhtml>
63
+ <events>
64
+ <controller_action_layout_render_before_adminhtml_sales_order_view>
65
+ <observers>
66
+ <add_sync_with_tigomoney_button>
67
+ <class>tigo_tigomoney/observer_adminOrderView</class>
68
+ <method>addSyncButton</method>
69
+ </add_sync_with_tigomoney_button>
70
+ </observers>
71
+ </controller_action_layout_render_before_adminhtml_sales_order_view>
72
+ </events>
73
+ <translate>
74
+ <modules>
75
+ <Tigo_TigoMoney>
76
+ <files>
77
+ <default>Tigo_TigoMoney.csv</default>
78
+ </files>
79
+ </Tigo_TigoMoney>
80
+ </modules>
81
+ </translate>
82
+ </adminhtml>
83
+ <crontab>
84
+ <jobs>
85
+ <tigo_tigomoney_sync_old_pending_orders>
86
+ <schedule><cron_expr>0 1 * * *</cron_expr></schedule>
87
+ <run><model>tigo_tigomoney/cron_syncOldPendingOrders::run</model></run>
88
+ </tigo_tigomoney_sync_old_pending_orders>
89
+ <tigo_tigomoney_sync_recent_pending_orders>
90
+ <schedule><config_path>payment/tigo_tigomoney/sync_recent_pending_orders_cron_schedule</config_path></schedule>
91
+ <run><model>tigo_tigomoney/cron_syncRecentPendingOrders::run</model></run>
92
+ </tigo_tigomoney_sync_recent_pending_orders>
93
+ </jobs>
94
+ </crontab>
95
+ <default>
96
+ <payment>
97
+ <tigo_tigomoney>
98
+ <model>tigo_tigomoney/payment_redirect</model>
99
+ <active>0</active>
100
+ <title>Tigo Money</title>
101
+ <description>To complete the payment using TIGO Money, a SMS will be sent to your mobile phone which will contain a PIN you will use to finish the transaction.</description>
102
+ <test_mode>0</test_mode>
103
+ <debug_mode>0</debug_mode>
104
+ <order_status>pending</order_status>
105
+ <allowspecific>1</allowspecific>
106
+ <specificcountry>SV</specificcountry>
107
+ <payment_action>authorize</payment_action>
108
+ <after_place_redirect_url_path>tigomoney/redirect/index</after_place_redirect_url_path>
109
+ <sync_recent_pending_orders_cron_schedule>*/5 * * * *</sync_recent_pending_orders_cron_schedule>
110
+ <failure_continue_shopping_url />
111
+ <success_continue_shopping_url />
112
+ </tigo_tigomoney>
113
+ </payment>
114
+ </default>
115
+ <phpunit>
116
+ <suite>
117
+ <modules>
118
+ <Tigo_TigoMoney/>
119
+ </modules>
120
+ </suite>
121
+ </phpunit>
122
+ </config>
app/code/community/Tigo/TigoMoney/etc/system.xml ADDED
@@ -0,0 +1,149 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <sections>
4
+ <payment>
5
+ <groups>
6
+ <tigo_tigomoney translate="label" module="paygate">
7
+ <label>Tigo Money</label>
8
+ <sort_order>100</sort_order>
9
+ <show_in_default>1</show_in_default>
10
+ <show_in_website>1</show_in_website>
11
+ <show_in_store>1</show_in_store>
12
+ <fields>
13
+ <active translate="label">
14
+ <label>Enabled</label>
15
+ <frontend_type>select</frontend_type>
16
+ <source_model>adminhtml/system_config_source_yesno</source_model>
17
+ <sort_order>10</sort_order>
18
+ <show_in_default>1</show_in_default>
19
+ <show_in_website>1</show_in_website>
20
+ <show_in_store>1</show_in_store>
21
+ <comment>
22
+ <model>tigo_tigomoney/adminhtml_configComment</model>
23
+ </comment>
24
+ </active>
25
+ <client_id>
26
+ <label>Tigo Client Id</label>
27
+ <frontend_type>text</frontend_type>
28
+ <sort_order>20</sort_order>
29
+ <show_in_default>1</show_in_default>
30
+ <show_in_website>1</show_in_website>
31
+ <show_in_store>1</show_in_store>
32
+ </client_id>
33
+ <client_secret>
34
+ <label>Tigo Client Secret</label>
35
+ <frontend_type>text</frontend_type>
36
+ <sort_order>30</sort_order>
37
+ <show_in_default>1</show_in_default>
38
+ <show_in_website>1</show_in_website>
39
+ <show_in_store>1</show_in_store>
40
+ </client_secret>
41
+ <merchant_account translate="label">
42
+ <label>Tigo Merchant Account</label>
43
+ <frontend_type>text</frontend_type>
44
+ <sort_order>40</sort_order>
45
+ <show_in_default>1</show_in_default>
46
+ <show_in_website>1</show_in_website>
47
+ <show_in_store>1</show_in_store>
48
+ </merchant_account>
49
+ <merchant_pin translate="label">
50
+ <label>Tigo Merchant Pin</label>
51
+ <frontend_type>text</frontend_type>
52
+ <sort_order>50</sort_order>
53
+ <show_in_default>1</show_in_default>
54
+ <show_in_website>1</show_in_website>
55
+ <show_in_store>1</show_in_store>
56
+ </merchant_pin>
57
+ <merchant_id translate="label">
58
+ <label>Tigo Merchant Id</label>
59
+ <frontend_type>text</frontend_type>
60
+ <sort_order>60</sort_order>
61
+ <show_in_default>1</show_in_default>
62
+ <show_in_website>1</show_in_website>
63
+ <show_in_store>1</show_in_store>
64
+ </merchant_id>
65
+ <merchant_reference translate="label">
66
+ <label>Tigo Merchant Reference</label>
67
+ <frontend_type>text</frontend_type>
68
+ <sort_order>70</sort_order>
69
+ <show_in_default>1</show_in_default>
70
+ <show_in_website>1</show_in_website>
71
+ <show_in_store>1</show_in_store>
72
+ </merchant_reference>
73
+ <title translate="label">
74
+ <label>Title</label>
75
+ <frontend_type>text</frontend_type>
76
+ <sort_order>80</sort_order>
77
+ <show_in_default>1</show_in_default>
78
+ <show_in_website>1</show_in_website>
79
+ <show_in_store>1</show_in_store>
80
+ </title>
81
+ <description translate="label">
82
+ <label>Description </label>
83
+ <frontend_type>textarea</frontend_type>
84
+ <sort_order>90</sort_order>
85
+ <show_in_default>1</show_in_default>
86
+ <show_in_website>1</show_in_website>
87
+ <show_in_store>1</show_in_store>
88
+ </description>
89
+ <test_mode translate="label">
90
+ <label>Test Mode Enabled?</label>
91
+ <frontend_type>select</frontend_type>
92
+ <source_model>adminhtml/system_config_source_yesno</source_model>
93
+ <sort_order>100</sort_order>
94
+ <show_in_default>1</show_in_default>
95
+ <show_in_website>1</show_in_website>
96
+ <show_in_store>1</show_in_store>
97
+ <comment>When test mode is enabled the module will use Tigo Money Secure Sandbox instead of the production environment.</comment>
98
+ </test_mode>
99
+ <debug_mode translate="label">
100
+ <label>Debug Mode Enabled?</label>
101
+ <frontend_type>select</frontend_type>
102
+ <source_model>adminhtml/system_config_source_yesno</source_model>
103
+ <sort_order>110</sort_order>
104
+ <show_in_default>1</show_in_default>
105
+ <show_in_website>1</show_in_website>
106
+ <show_in_store>1</show_in_store>
107
+ <comment>Enabling this option will create log entries for all requests to and from Tigo Payment Server in var/log/tigomoney.log</comment>
108
+ </debug_mode>
109
+ <order_status translate="label">
110
+ <label>New Order status</label>
111
+ <frontend_type>select</frontend_type>
112
+ <source_model>adminhtml/system_config_source_order_status</source_model>
113
+ <sort_order>120</sort_order>
114
+ <show_in_default>1</show_in_default>
115
+ <show_in_website>1</show_in_website>
116
+ <show_in_store>1</show_in_store>
117
+ </order_status>
118
+ <sync_recent_pending_orders_cron_schedule translate="label">
119
+ <label>Sync Recent Pending Orders (Crontab Format)</label>
120
+ <frontend_type>text</frontend_type>
121
+ <sort_order>130</sort_order>
122
+ <show_in_default>1</show_in_default>
123
+ <show_in_website>0</show_in_website>
124
+ <show_in_store>0</show_in_store>
125
+ </sync_recent_pending_orders_cron_schedule>
126
+ <failure_continue_shopping_url translate="label">
127
+ <label>Continue Shopping URL - Failure</label>
128
+ <frontend_type>text</frontend_type>
129
+ <sort_order>140</sort_order>
130
+ <show_in_default>1</show_in_default>
131
+ <show_in_website>0</show_in_website>
132
+ <show_in_store>0</show_in_store>
133
+ <comment>Leaving this field blank will default to the Magento behaviour: the link directs the user to the home page. Use complete urls, including protocol and domain. Ex: http://www.tigomoney.com.sv/</comment>
134
+ </failure_continue_shopping_url>
135
+ <success_continue_shopping_url translate="label">
136
+ <label>Continue Shopping URL - Success</label>
137
+ <frontend_type>text</frontend_type>
138
+ <sort_order>150</sort_order>
139
+ <show_in_default>1</show_in_default>
140
+ <show_in_website>0</show_in_website>
141
+ <show_in_store>0</show_in_store>
142
+ <comment>Leaving this field blank will default to the Magento behaviour: the link directs the user to the shopping cart. Use complete urls, including protocol and domain. Ex: http://www.tigomoney.com.sv/</comment>
143
+ </success_continue_shopping_url>
144
+ </fields>
145
+ </tigo_tigomoney>
146
+ </groups>
147
+ </payment>
148
+ </sections>
149
+ </config>
app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Block/Payment/Redirect/FormTest.php ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Tigo_TigoMoney_Block_Payment_Redirect_FormTest
5
+ */
6
+ class Tigo_TigoMoney_Block_Payment_Redirect_FormTest extends EcomDev_PHPUnit_Test_Case
7
+ {
8
+ /**
9
+ * @var String
10
+ */
11
+ protected $className = null;
12
+
13
+ /**
14
+ * @var Tigo_TigoMoney_Helper_Data|PHPUnit_Framework_MockObject_MockObject
15
+ */
16
+ protected $dataHelper = null;
17
+
18
+ /**
19
+ * @var Tigo_TigoMoney_Block_Payment_Redirect_Form|PHPUnit_Framework_MockObject_MockObject
20
+ */
21
+ protected $subject = null;
22
+
23
+ /**
24
+ * Sets up the unit test case
25
+ */
26
+ protected function setUp()
27
+ {
28
+ parent::setUp();
29
+
30
+ $this->className = Tigo_TigoMoney_Block_Payment_Redirect_Form::class;
31
+
32
+ $this->subject = $this
33
+ ->getMockBuilder($this->className)
34
+ ->setMethods(array('_isAdmin', 'getInfo'))
35
+ ->getMock();
36
+
37
+ $this->dataHelper = $this
38
+ ->getMockBuilder(Tigo_TigoMoney_Helper_Data::class)
39
+ ->setMethods(array('getDescription'))
40
+ ->getMock();
41
+ $this->replaceByMock('helper', 'tigo_tigomoney/data', $this->dataHelper);
42
+ }
43
+
44
+ public function testGetTemplateReturnsRightTemplatePath()
45
+ {
46
+ $this->assertEquals(
47
+ $this->subject->getTemplate(),
48
+ Tigo_TigoMoney_Block_Payment_Redirect_Form::TEMPLATE_PATH
49
+ );
50
+ }
51
+
52
+ public function testGetDescriptionGetsItFromDataHelper()
53
+ {
54
+ $expectedReturn = 'Checkout Description Message';
55
+ $this
56
+ ->dataHelper
57
+ ->expects($this->any())
58
+ ->method('getDescription')
59
+ ->will($this->returnValue($expectedReturn));
60
+ $return = $this->subject->getDescription();
61
+ $this->assertEquals($expectedReturn, $return);
62
+ }
63
+ }
64
+
app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Block/Payment/Redirect/InfoTest.php ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Tigo_TigoMoney_Block_Payment_Redirect_InfoTest
5
+ */
6
+ class Tigo_TigoMoney_Block_Payment_Redirect_InfoTest extends EcomDev_PHPUnit_Test_Case
7
+ {
8
+ /**
9
+ * @var String
10
+ */
11
+ protected $className = null;
12
+
13
+ /**
14
+ * @var Tigo_TigoMoney_Block_Payment_Redirect_Info|PHPUnit_Framework_MockObject_MockObject
15
+ */
16
+ protected $subject = null;
17
+
18
+ /**
19
+ * @var Mage_Payment_Model_Info|PHPUnit_Framework_MockObject_MockObject
20
+ */
21
+ protected $info = null;
22
+
23
+ /**
24
+ * Sets up the unit test case
25
+ */
26
+ protected function setUp()
27
+ {
28
+ parent::setUp();
29
+
30
+ $this->className = Tigo_TigoMoney_Block_Payment_Redirect_Info::class;
31
+
32
+ $this->subject = $this
33
+ ->getMockBuilder($this->className)
34
+ ->setMethods(array('getInfo'))
35
+ ->getMock();
36
+
37
+ $this->info = $this
38
+ ->getMockBuilder(Mage_Payment_Model_Info::class)
39
+ ->setMethods(array('getAdditionalInformation'))
40
+ ->getMock();
41
+
42
+ }
43
+
44
+ public function testGetTemplateReturnsRightTemplatePath()
45
+ {
46
+ $this->assertEquals(
47
+ $this->subject->getTemplate(),
48
+ Tigo_TigoMoney_Block_Payment_Redirect_Info::TEMPLATE_PATH
49
+ );
50
+ }
51
+
52
+ public function testGetSpecificInformationReturnsNothingOnFrontend()
53
+ {
54
+
55
+ $this->setCurrentStore(1);
56
+
57
+ $this->assertCount(0, $this->subject->getSpecificInformation());
58
+ }
59
+
60
+ public function testGetSpecificInformationReturnsRightInfoOnAdmin()
61
+ {
62
+ $mfsTransactionID = 'l2l2';
63
+ $authCode = '123123';
64
+ $transactionCode = '03930.039303.203920';
65
+ $accessTokenErrors = array('AT Error 1', 'AT Error 2');
66
+ $authorizationErrors = array('Auth Error 1', 'Auth Error 2', 'Auth Error 3');
67
+
68
+ $this->setCurrentStore('admin');
69
+
70
+ $this
71
+ ->info
72
+ ->expects($this->any())
73
+ ->method('getAdditionalInformation')
74
+ ->will(
75
+ $this->returnValueMap(
76
+ array(
77
+ array(Tigo_TigoMoney_Model_Payment_Redirect::ADDITIONAL_INFO_KEY_MFS_TRANSACTION_ID, $mfsTransactionID),
78
+ array(Tigo_TigoMoney_Model_Payment_Redirect::ADDITIONAL_INFO_KEY_AUTH_CODE, $authCode),
79
+ array(Tigo_TigoMoney_Model_Payment_Redirect::ADDITIONAL_INFO_KEY_TRANSACTION_CODE, $transactionCode),
80
+ array(Tigo_TigoMoney_Model_Payment_Redirect::ADDITIONAL_INFO_KEY_ACCESS_TOKEN_ERRORS, $accessTokenErrors),
81
+ array(Tigo_TigoMoney_Model_Payment_Redirect::ADDITIONAL_INFO_KEY_AUTHORIZATION_ERRORS, $authorizationErrors),
82
+ )
83
+ )
84
+ );
85
+
86
+ $this
87
+ ->subject
88
+ ->expects($this->any())
89
+ ->method('getInfo')
90
+ ->will($this->returnValue(($this->info)));
91
+
92
+ $return = $this->subject->getSpecificInformation();
93
+
94
+ $this->assertCount(5, $return);
95
+
96
+ $this->assertArrayHasKey(
97
+ Tigo_TigoMoney_Block_Payment_Redirect_Info::ADDITIONAL_INFO_RETURN_KEY_MFS_TRANSACTION_ID,
98
+ $return
99
+ );
100
+ $this->assertEquals(
101
+ $mfsTransactionID,
102
+ $return[Tigo_TigoMoney_Block_Payment_Redirect_Info::ADDITIONAL_INFO_RETURN_KEY_MFS_TRANSACTION_ID]
103
+ );
104
+
105
+ $this->assertArrayHasKey(
106
+ Tigo_TigoMoney_Block_Payment_Redirect_Info::ADDITIONAL_INFO_RETURN_KEY_AUTH_CODE,
107
+ $return
108
+ );
109
+ $this->assertEquals(
110
+ $authCode,
111
+ $return[Tigo_TigoMoney_Block_Payment_Redirect_Info::ADDITIONAL_INFO_RETURN_KEY_AUTH_CODE]
112
+ );
113
+
114
+ $this->assertArrayHasKey(
115
+ Tigo_TigoMoney_Block_Payment_Redirect_Info::ADDITIONAL_INFO_RETURN_KEY_TRANSACTION_CODE,
116
+ $return
117
+ );
118
+ $this->assertEquals(
119
+ $transactionCode,
120
+ $return[Tigo_TigoMoney_Block_Payment_Redirect_Info::ADDITIONAL_INFO_RETURN_KEY_TRANSACTION_CODE]
121
+ );
122
+
123
+ $this->assertArrayHasKey(
124
+ Tigo_TigoMoney_Block_Payment_Redirect_Info::ADDITIONAL_INFO_RETURN_KEY_ACCESS_TOKEN_ERRORS,
125
+ $return
126
+ );
127
+ $this->assertEquals(
128
+ $accessTokenErrors,
129
+ $return[Tigo_TigoMoney_Block_Payment_Redirect_Info::ADDITIONAL_INFO_RETURN_KEY_ACCESS_TOKEN_ERRORS]
130
+ );
131
+
132
+ $this->assertArrayHasKey(
133
+ Tigo_TigoMoney_Block_Payment_Redirect_Info::ADDITIONAL_INFO_RETURN_KEY_AUTHORIZATION_ERRORS,
134
+ $return
135
+ );
136
+ $this->assertEquals(
137
+ $authorizationErrors,
138
+ $return[Tigo_TigoMoney_Block_Payment_Redirect_Info::ADDITIONAL_INFO_RETURN_KEY_AUTHORIZATION_ERRORS]
139
+ );
140
+ }
141
+ }
142
+
app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Block/Payment/Rewrite/Checkout/Onepage/FailureTest.php ADDED
@@ -0,0 +1,173 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Tigo_TigoMoney_Block_Rewrite_Checkout_Onepage_FailureTest
5
+ */
6
+ class Tigo_TigoMoney_Block_Rewrite_Checkout_Onepage_FailureTest extends EcomDev_PHPUnit_Test_Case
7
+ {
8
+ /**
9
+ * @var String
10
+ */
11
+ protected $className = null;
12
+
13
+ /**
14
+ * @var Tigo_TigoMoney_Helper_Data|PHPUnit_Framework_MockObject_MockObject
15
+ */
16
+ protected $dataHelper = null;
17
+
18
+ /**
19
+ * @var Mage_Sales_Model_Order|PHPUnit_Framework_MockObject_MockObject
20
+ */
21
+ protected $order = null;
22
+
23
+ /**
24
+ * @var Mage_Sales_Model_Order_Payment|PHPUnit_Framework_MockObject_MockObject
25
+ */
26
+ protected $payment = null;
27
+
28
+ /**
29
+ * @var Tigo_TigoMoney_Block_Rewrite_Checkout_Onepage_Failure|PHPUnit_Framework_MockObject_MockObject
30
+ */
31
+ protected $subject = null;
32
+
33
+ /**
34
+ * Sets up the unit test case
35
+ */
36
+ protected function setUp()
37
+ {
38
+ $this->className = Tigo_TigoMoney_Block_Rewrite_Checkout_Onepage_Failure::class;
39
+
40
+ $this->subject = $this
41
+ ->getMockBuilder($this->className)
42
+ ->setMethods(array('getRealOrderId'))
43
+ ->getMock();
44
+
45
+
46
+ $this->dataHelper = $this
47
+ ->getHelperMock(
48
+ 'tigo_tigomoney/data',
49
+ array('getFailureContinueShoppingUrl')
50
+ );
51
+ $this->replaceByMock(
52
+ 'helper',
53
+ 'tigo_tigomoney/data',
54
+ $this->dataHelper
55
+ );
56
+ $this->replaceByMock(
57
+ 'helper',
58
+ 'tigo_tigomoney',
59
+ $this->dataHelper
60
+ );
61
+
62
+ $this->payment = $this
63
+ ->getModelMock(
64
+ 'sales/order_payment',
65
+ array('nonExistentMethod')
66
+ );
67
+ $this->order = $this
68
+ ->getModelMock(
69
+ 'sales/order',
70
+ array('loadByIncrementId', 'getPayment')
71
+ );
72
+ $this->order
73
+ ->expects($this->any())
74
+ ->method('getPayment')
75
+ ->will($this->returnValue($this->payment));
76
+ $this->replaceByMock('model', 'sales/order', $this->order);
77
+
78
+ }
79
+
80
+ public function testFailureUrlIsChangedWhenOrderIsTigoMoneyAndFailureContinueShoppingUrlNotEmpty()
81
+ {
82
+ $orderIncrementId = '1000000232';
83
+ $failureContinueShoppingUrl = 'http://nasa.gov/';
84
+
85
+ $this
86
+ ->payment
87
+ ->setMethod(Tigo_TigoMoney_Model_Payment_Redirect::METHOD_CODE);
88
+
89
+ $this
90
+ ->subject
91
+ ->expects($this->once())
92
+ ->method('getRealOrderId')
93
+ ->will($this->returnValue($orderIncrementId));
94
+
95
+ $this
96
+ ->order
97
+ ->expects($this->once())
98
+ ->method('loadByIncrementId')
99
+ ->with($orderIncrementId)
100
+ ->will($this->returnValue($this->order));
101
+
102
+ $this
103
+ ->dataHelper
104
+ ->expects($this->atLeastOnce())
105
+ ->method('getFailureContinueShoppingUrl')
106
+ ->will($this->returnValue($failureContinueShoppingUrl));
107
+
108
+ $this->assertEquals($failureContinueShoppingUrl, $this->subject->getContinueShoppingUrl());
109
+ }
110
+
111
+ public function testFailureUrlDoesNotChangeWhenOrderIsNotTigoMoney()
112
+ {
113
+ $orderIncrementId = '1000000232';
114
+ $failureContinueShoppingUrl = Mage::getModel('core/url')->getUrl('checkout/cart');
115
+
116
+ $this
117
+ ->payment
118
+ ->setMethod('checkmo');
119
+
120
+ $this
121
+ ->subject
122
+ ->expects($this->once())
123
+ ->method('getRealOrderId')
124
+ ->will($this->returnValue($orderIncrementId));
125
+
126
+ $this
127
+ ->order
128
+ ->expects($this->once())
129
+ ->method('loadByIncrementId')
130
+ ->with($orderIncrementId)
131
+ ->will($this->returnValue($this->order));
132
+
133
+ $this
134
+ ->dataHelper
135
+ ->expects($this->never())
136
+ ->method('getFailureContinueShoppingUrl');
137
+
138
+ $this->assertEquals($failureContinueShoppingUrl, $this->subject->getContinueShoppingUrl());
139
+ }
140
+
141
+ public function testFailureUrlDoesNotChangeWhenContinueShoppingFailureUrlEmpty()
142
+ {
143
+ $orderIncrementId = '1000000232';
144
+ $configFailureContinueShoppingUrl = '';
145
+ $failureContinueShoppingUrl = Mage::getModel('core/url')->getUrl('checkout/cart');
146
+
147
+ $this
148
+ ->payment
149
+ ->setMethod(Tigo_TigoMoney_Model_Payment_Redirect::METHOD_CODE);
150
+
151
+ $this
152
+ ->subject
153
+ ->expects($this->once())
154
+ ->method('getRealOrderId')
155
+ ->will($this->returnValue($orderIncrementId));
156
+
157
+ $this
158
+ ->order
159
+ ->expects($this->once())
160
+ ->method('loadByIncrementId')
161
+ ->with($orderIncrementId)
162
+ ->will($this->returnValue($this->order));
163
+
164
+ $this
165
+ ->dataHelper
166
+ ->expects($this->atLeastOnce())
167
+ ->method('getFailureContinueShoppingUrl')
168
+ ->will($this->returnValue($configFailureContinueShoppingUrl));
169
+
170
+ $this->assertEquals($failureContinueShoppingUrl, $this->subject->getContinueShoppingUrl());
171
+ }
172
+ }
173
+
app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Block/Payment/Rewrite/Checkout/Onepage/SuccessTest.php ADDED
@@ -0,0 +1,188 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Tigo_TigoMoney_Block_Rewrite_Checkout_Onepage_SuccessTest
5
+ */
6
+ class Tigo_TigoMoney_Block_Rewrite_Checkout_Onepage_SuccessTest extends EcomDev_PHPUnit_Test_Case
7
+ {
8
+ /**
9
+ * @var Mage_Checkout_Model_Session|PHPUnit_Framework_MockObject_MockObject
10
+ */
11
+ protected $checkoutSession = null;
12
+
13
+ /**
14
+ * @var String
15
+ */
16
+ protected $className = null;
17
+
18
+ /**
19
+ * @var Tigo_TigoMoney_Helper_Data|PHPUnit_Framework_MockObject_MockObject
20
+ */
21
+ protected $dataHelper = null;
22
+
23
+ /**
24
+ * @var Mage_Sales_Model_Order|PHPUnit_Framework_MockObject_MockObject
25
+ */
26
+ protected $order = null;
27
+
28
+ /**
29
+ * @var Mage_Sales_Model_Order_Payment|PHPUnit_Framework_MockObject_MockObject
30
+ */
31
+ protected $payment = null;
32
+
33
+ /**
34
+ * @var Tigo_TigoMoney_Block_Rewrite_Checkout_Onepage_Success|PHPUnit_Framework_MockObject_MockObject
35
+ */
36
+ protected $subject = null;
37
+
38
+ /**
39
+ * Sets up the unit test case
40
+ */
41
+ protected function setUp()
42
+ {
43
+ $this->className = Tigo_TigoMoney_Block_Rewrite_Checkout_Onepage_Success::class;
44
+
45
+ $this->subject = $this
46
+ ->getMockBuilder($this->className)
47
+ ->setMethods(array('nonExistentMethod'))
48
+ ->getMock();
49
+
50
+ $this->dataHelper = $this
51
+ ->getHelperMock(
52
+ 'tigo_tigomoney/data',
53
+ array('getSuccessContinueShoppingUrl')
54
+ );
55
+ $this->replaceByMock(
56
+ 'helper',
57
+ 'tigo_tigomoney/data',
58
+ $this->dataHelper
59
+ );
60
+ $this->replaceByMock(
61
+ 'helper',
62
+ 'tigo_tigomoney',
63
+ $this->dataHelper
64
+ );
65
+
66
+ $this->checkoutSession = $this
67
+ ->getMockBuilder(Mage_Checkout_Model_Session::class)
68
+ ->setMethods(array('getLastOrderId'))
69
+ ->getMock();
70
+ $this->replaceByMock(
71
+ 'singleton',
72
+ 'checkout/session',
73
+ $this->checkoutSession
74
+ );
75
+
76
+ $this->payment = $this
77
+ ->getModelMock(
78
+ 'sales/order_payment',
79
+ array('nonExistentMethod')
80
+ );
81
+ $this->order = $this
82
+ ->getModelMock(
83
+ 'sales/order',
84
+ array('load', 'getPayment')
85
+ );
86
+ $this->order
87
+ ->expects($this->any())
88
+ ->method('getPayment')
89
+ ->will($this->returnValue($this->payment));
90
+ $this->replaceByMock('model', 'sales/order', $this->order);
91
+
92
+ }
93
+
94
+ public function testSuccessUrlIsChangedWhenOrderIsTigoMoneyAndSuccessContinueShoppingUrlNotEmpty()
95
+ {
96
+ $orderId = '234';
97
+ $successContinueShoppingUrl = 'http://nasa.gov/';
98
+
99
+ $this
100
+ ->payment
101
+ ->setMethod(Tigo_TigoMoney_Model_Payment_Redirect::METHOD_CODE);
102
+
103
+ $this
104
+ ->checkoutSession
105
+ ->expects($this->once())
106
+ ->method('getLastOrderId')
107
+ ->will($this->returnValue($orderId));
108
+
109
+ $this
110
+ ->order
111
+ ->expects($this->once())
112
+ ->method('load')
113
+ ->with($orderId)
114
+ ->will($this->returnValue($this->order));
115
+
116
+ $this
117
+ ->dataHelper
118
+ ->expects($this->atLeastOnce())
119
+ ->method('getSuccessContinueShoppingUrl')
120
+ ->will($this->returnValue($successContinueShoppingUrl));
121
+
122
+ $this->assertEquals($successContinueShoppingUrl, $this->subject->getUrl());
123
+ }
124
+
125
+ public function testSuccessUrlDoesNotChangeWhenOrderIsNotTigoMoney()
126
+ {
127
+
128
+ $orderId = '234';
129
+ $successContinueShoppingUrl = Mage::getModel('core/url')->getUrl('');
130
+
131
+ $this
132
+ ->payment
133
+ ->setMethod('checkmo');
134
+
135
+ $this
136
+ ->checkoutSession
137
+ ->expects($this->once())
138
+ ->method('getLastOrderId')
139
+ ->will($this->returnValue($orderId));
140
+
141
+ $this
142
+ ->order
143
+ ->expects($this->once())
144
+ ->method('load')
145
+ ->with($orderId)
146
+ ->will($this->returnValue($this->order));
147
+
148
+ $this
149
+ ->dataHelper
150
+ ->expects($this->never())
151
+ ->method('getSuccessContinueShoppingUrl');
152
+
153
+ $this->assertEquals($successContinueShoppingUrl, $this->subject->getUrl());
154
+ }
155
+
156
+ public function testSuccessUrlDoesNotChangeWhenContinueShoppingSuccessUrlEmpty()
157
+ {
158
+ $orderId = '432';
159
+ $configSuccessContinueShoppingUrl = '';
160
+ $successContinueShoppingUrl = Mage::getModel('core/url')->getUrl('');
161
+
162
+ $this
163
+ ->payment
164
+ ->setMethod(Tigo_TigoMoney_Model_Payment_Redirect::METHOD_CODE);
165
+
166
+ $this
167
+ ->checkoutSession
168
+ ->expects($this->once())
169
+ ->method('getLastOrderId')
170
+ ->will($this->returnValue($orderId));
171
+
172
+ $this
173
+ ->order
174
+ ->expects($this->once())
175
+ ->method('load')
176
+ ->with($orderId)
177
+ ->will($this->returnValue($this->order));
178
+
179
+ $this
180
+ ->dataHelper
181
+ ->expects($this->atLeastOnce())
182
+ ->method('getSuccessContinueShoppingUrl')
183
+ ->will($this->returnValue($configSuccessContinueShoppingUrl));
184
+
185
+ $this->assertEquals($successContinueShoppingUrl, $this->subject->getUrl());
186
+ }
187
+ }
188
+
app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/ConfigTest.php ADDED
@@ -0,0 +1,213 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Tigo_TigoMoney_ConfigTest extends EcomDev_PHPUnit_Test_Case_Config
4
+ {
5
+ public function testClassesAliases()
6
+ {
7
+ /**
8
+ * Blocks
9
+ */
10
+ $this->assertBlockAlias(
11
+ 'tigo_tigomoney/payment_redirect_form',
12
+ Tigo_TigoMoney_Block_Payment_Redirect_Form::class
13
+ );
14
+ $this->assertBlockAlias(
15
+ 'tigo_tigomoney/payment_redirect_info',
16
+ Tigo_TigoMoney_Block_Payment_Redirect_Info::class
17
+ );
18
+ $this->assertBlockAlias(
19
+ 'tigo_tigomoney/rewrite_checkout_onepage_failure',
20
+ Tigo_TigoMoney_Block_Rewrite_Checkout_Onepage_Failure::class
21
+ );
22
+ $this->assertInstanceOf(
23
+ Mage_Checkout_Block_Onepage_Failure::class,
24
+ Mage::getModel(Tigo_TigoMoney_Block_Rewrite_Checkout_Onepage_Failure::class)
25
+ );
26
+ $this->assertBlockAlias(
27
+ 'tigo_tigomoney/rewrite_checkout_onepage_success',
28
+ Tigo_TigoMoney_Block_Rewrite_Checkout_Onepage_Success::class
29
+ );
30
+ $this->assertInstanceOf(
31
+ Mage_Checkout_Block_Onepage_Success::class,
32
+ Mage::getModel(Tigo_TigoMoney_Block_Rewrite_Checkout_Onepage_Success::class)
33
+ );
34
+
35
+ /**
36
+ * Helpers
37
+ */
38
+ $this->assertHelperAlias(
39
+ 'tigo_tigomoney',
40
+ Tigo_TigoMoney_Helper_Data::class
41
+ );
42
+ $this->assertHelperAlias(
43
+ 'tigo_tigomoney/data',
44
+ Tigo_TigoMoney_Helper_Data::class
45
+ );
46
+
47
+ /**
48
+ * Models
49
+ */
50
+ $this->assertModelAlias(
51
+ 'tigo_tigomoney/debug',
52
+ Tigo_TigoMoney_Model_Debug::class
53
+ );
54
+ $this->assertModelAlias(
55
+ 'tigo_tigomoney/observer_adminOrderView',
56
+ Tigo_TigoMoney_Model_Observer_AdminOrderView::class
57
+ );
58
+ $this->assertModelAlias(
59
+ 'tigo_tigomoney/observer_changeContinueShoppingUrlSuccess',
60
+ Tigo_TigoMoney_Model_Observer_ChangeContinueShoppingUrlSuccess::class
61
+ );
62
+ $this->assertModelAlias(
63
+ 'tigo_tigomoney/cron_syncOldPendingOrders',
64
+ Tigo_TigoMoney_Model_Cron_SyncOldPendingOrders::class
65
+ );
66
+ $this->assertModelAlias(
67
+ 'tigo_tigomoney/cron_syncRecentPendingOrders',
68
+ Tigo_TigoMoney_Model_Cron_SyncRecentPendingOrders::class
69
+ );
70
+ $this->assertModelAlias(
71
+ 'tigo_tigomoney/payment_redirect',
72
+ Tigo_TigoMoney_Model_Payment_Redirect::class
73
+ );
74
+ $this->assertModelAlias(
75
+ 'tigo_tigomoney/payment_redirect_api',
76
+ Tigo_TigoMoney_Model_Payment_Redirect_Api::class
77
+ );
78
+ $this->assertModelAlias(
79
+ 'tigo_tigomoney/payment_redirect_sync',
80
+ Tigo_TigoMoney_Model_Payment_Redirect_Sync::class
81
+ );
82
+ $this->assertModelAlias(
83
+ 'tigo_tigomoney/payment_redirect_api_authorizationRequest',
84
+ Tigo_TigoMoney_Model_Payment_Redirect_Api_AuthorizationRequest::class
85
+ );
86
+ $this->assertModelAlias(
87
+ 'tigo_tigomoney/payment_redirect_api_authorizationResponse',
88
+ Tigo_TigoMoney_Model_Payment_Redirect_Api_AuthorizationResponse::class
89
+ );
90
+ $this->assertModelAlias(
91
+ 'tigo_tigomoney/payment_redirect_api_generateTokenRequest',
92
+ Tigo_TigoMoney_Model_Payment_Redirect_Api_GenerateTokenRequest::class
93
+ );
94
+ $this->assertModelAlias(
95
+ 'tigo_tigomoney/payment_redirect_api_generateTokenResponse',
96
+ Tigo_TigoMoney_Model_Payment_Redirect_Api_GenerateTokenResponse::class
97
+ );
98
+ $this->assertModelAlias(
99
+ 'tigo_tigomoney/payment_redirect_api_requestBuilder',
100
+ Tigo_TigoMoney_Model_Payment_Redirect_Api_RequestBuilder::class
101
+ );
102
+ $this->assertModelAlias(
103
+ 'tigo_tigomoney/payment_redirect_api_reverseTransactionRequest',
104
+ Tigo_TigoMoney_Model_Payment_Redirect_Api_ReverseTransactionRequest::class
105
+ );
106
+ $this->assertModelAlias(
107
+ 'tigo_tigomoney/payment_redirect_api_reverseTransactionResponse',
108
+ Tigo_TigoMoney_Model_Payment_Redirect_Api_ReverseTransactionResponse::class
109
+ );
110
+ $this->assertModelAlias(
111
+ 'tigo_tigomoney/payment_redirect_api_transactionStatusRequest',
112
+ Tigo_TigoMoney_Model_Payment_Redirect_Api_TransactionStatusRequest::class
113
+ );
114
+ $this->assertModelAlias(
115
+ 'tigo_tigomoney/payment_redirect_api_transactionStatusResponse',
116
+ Tigo_TigoMoney_Model_Payment_Redirect_Api_TransactionStatusResponse::class
117
+ );
118
+ $this->assertModelAlias(
119
+ 'tigo_tigomoney/adminhtml_configComment',
120
+ Tigo_TigoMoney_Model_Adminhtml_ConfigComment::class
121
+ );
122
+ }
123
+
124
+ public function testModuleDefinitionSetup()
125
+ {
126
+ $this->assertModuleCodePool('community');
127
+ $this->assertModuleDepends('Mage_Payment');
128
+ $this->assertModuleDepends('Mage_Sales');
129
+ }
130
+
131
+ public function testModuleConfig()
132
+ {
133
+ $this->assertConfigNodeHasChild('default/payment', Tigo_TigoMoney_Model_Payment_Redirect::METHOD_CODE);
134
+ $this->assertConfigNodeHasChild(
135
+ 'default/payment/' . Tigo_TigoMoney_Model_Payment_Redirect::METHOD_CODE,
136
+ 'description'
137
+ );
138
+ $this->assertConfigNodeHasChild(
139
+ 'default/payment/' . Tigo_TigoMoney_Model_Payment_Redirect::METHOD_CODE,
140
+ 'failure_continue_shopping_url'
141
+ );
142
+ $this->assertConfigNodeHasChild(
143
+ 'default/payment/' . Tigo_TigoMoney_Model_Payment_Redirect::METHOD_CODE,
144
+ 'success_continue_shopping_url'
145
+ );
146
+ $this->assertConfigNodeValue(
147
+ 'default/payment/' . Tigo_TigoMoney_Model_Payment_Redirect::METHOD_CODE . '/model',
148
+ Tigo_TigoMoney_Model_Payment_Redirect::METHOD_CODE . '/payment_redirect'
149
+ );
150
+ $this->assertConfigNodeValue(
151
+ 'default/payment/' . Tigo_TigoMoney_Model_Payment_Redirect::METHOD_CODE . '/order_status',
152
+ 'pending'
153
+ );
154
+ $this->assertConfigNodeValue(
155
+ 'default/payment/' . Tigo_TigoMoney_Model_Payment_Redirect::METHOD_CODE . '/allowspecific',
156
+ '1'
157
+ );
158
+ $this->assertConfigNodeValue(
159
+ 'default/payment/' . Tigo_TigoMoney_Model_Payment_Redirect::METHOD_CODE . '/specificcountry',
160
+ 'SV'
161
+ );
162
+ $this->assertConfigNodeValue(
163
+ 'default/payment/' . Tigo_TigoMoney_Model_Payment_Redirect::METHOD_CODE . '/payment_action',
164
+ 'authorize'
165
+ );
166
+ $this->assertConfigNodeValue(
167
+ 'default/payment/' . Tigo_TigoMoney_Model_Payment_Redirect::METHOD_CODE . '/after_place_redirect_url_path',
168
+ 'tigomoney/redirect/index'
169
+ );
170
+ $this->assertConfigNodeValue(
171
+ 'global/blocks/checkout/rewrite/onepage_failure',
172
+ Tigo_TigoMoney_Block_Rewrite_Checkout_Onepage_Failure::class
173
+ );
174
+ $this->assertConfigNodeValue(
175
+ 'global/blocks/checkout/rewrite/onepage_success',
176
+ Tigo_TigoMoney_Block_Rewrite_Checkout_Onepage_Success::class
177
+ );
178
+ $this->assertConfigNodeHasChild(
179
+ 'crontab/jobs',
180
+ 'tigo_tigomoney_sync_old_pending_orders'
181
+ );
182
+ $this->assertConfigNodeValue(
183
+ 'crontab/jobs/tigo_tigomoney_sync_old_pending_orders/schedule/cron_expr',
184
+ '0 1 * * *'
185
+ );
186
+ $this->assertConfigNodeValue(
187
+ 'crontab/jobs/tigo_tigomoney_sync_old_pending_orders/run/model',
188
+ 'tigo_tigomoney/cron_syncOldPendingOrders::run'
189
+ );
190
+ $this->assertConfigNodeHasChild(
191
+ 'crontab/jobs',
192
+ 'tigo_tigomoney_sync_recent_pending_orders'
193
+ );
194
+ $this->assertConfigNodeValue(
195
+ 'crontab/jobs/tigo_tigomoney_sync_recent_pending_orders/schedule/config_path',
196
+ 'payment/tigo_tigomoney/sync_recent_pending_orders_cron_schedule'
197
+ );
198
+ $this->assertConfigNodeValue(
199
+ 'crontab/jobs/tigo_tigomoney_sync_recent_pending_orders/run/model',
200
+ 'tigo_tigomoney/cron_syncRecentPendingOrders::run'
201
+ );
202
+ }
203
+
204
+ public function testObserversAreDefined()
205
+ {
206
+ $this->assertEventObserverDefined(
207
+ 'adminhtml',
208
+ 'controller_action_layout_render_before_adminhtml_sales_order_view',
209
+ 'tigo_tigomoney/observer_adminOrderView',
210
+ 'addSyncButton'
211
+ );
212
+ }
213
+ }
app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Helper/DataTest.php ADDED
@@ -0,0 +1,265 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Tigo_TigoMoney_Helper_DataTest
5
+ */
6
+ class Tigo_TigoMoney_Helper_DataTest extends EcomDev_PHPUnit_Test_Case
7
+ {
8
+ /**
9
+ * @var Mage_Adminhtml_Helper_Data|PHPUnit_Framework_MockObject_MockObject
10
+ */
11
+ protected $adminhtmlHelper = null;
12
+
13
+ /**
14
+ * @var String
15
+ */
16
+ protected $className = null;
17
+
18
+ /**
19
+ * @var Mage_Sales_Model_Order|PHPUnit_Framework_MockObject_MockObject
20
+ */
21
+ protected $order = null;
22
+
23
+ /**
24
+ * @var Tigo_TigoMoney_Helper_Data|PHPUnit_Framework_MockObject_MockObject
25
+ */
26
+ protected $subject = null;
27
+
28
+ /**
29
+ * Sets up the unit test case
30
+ */
31
+ protected function setUp()
32
+ {
33
+ parent::setUp();
34
+
35
+ $this->subject = $this
36
+ ->getHelperMock('tigo_tigomoney/data', null);
37
+
38
+ $this->order = $this
39
+ ->getMockBuilder(Mage_Sales_Model_Order::class)
40
+ ->setMethods(array('getId'))
41
+ ->getMock();
42
+
43
+ $this->adminhtmlHelper = $this
44
+ ->getMockBuilder(Mage_Adminhtml_Helper_Data::class)
45
+ ->setMethods(null)
46
+ ->getMock();
47
+ $this->replaceByMock('helper', 'adminhtml', $this->adminhtmlHelper);
48
+
49
+ }
50
+
51
+ /**
52
+ * @loadFixtures default
53
+ */
54
+ public function testGetCallbackUriReturnsCorrectValue()
55
+ {
56
+ /** @var Mage_Core_Model_Url $urlModel */
57
+ $urlModel = Mage::getModel('core/url');
58
+ $expectedUrl = $urlModel->getUrl('tigomoney/sync');
59
+ $this->assertEquals(
60
+ $expectedUrl,
61
+ $this->subject->getCallbackUri()
62
+ );
63
+ }
64
+
65
+ /**
66
+ * @loadFixture default
67
+ */
68
+ public function testGetClientIdReturnsCorrectValue()
69
+ {
70
+ $expectedId = '123';
71
+ $this->assertEquals(
72
+ $expectedId,
73
+ $this->subject->getClientId()
74
+ );
75
+ }
76
+
77
+ /**
78
+ * @loadFixture default
79
+ */
80
+ public function testGetClientSecretReturnsCorrectValue()
81
+ {
82
+ $expectedSecret = 'asdf123fdsa';
83
+ $this->assertEquals(
84
+ $expectedSecret,
85
+ $this->subject->getClientSecret()
86
+ );
87
+ }
88
+
89
+ /**
90
+ * @loadFixture default
91
+ */
92
+ public function testGetInternalRedirectUriReturnsCorrectValue()
93
+ {
94
+ /** @var Mage_Core_Model_Url $urlModel */
95
+ $urlModel = Mage::getModel('core/url');
96
+ $expectedUrl = $urlModel->getUrl('tigomoney/redirect/index', array('_secure' => true));
97
+ $this->assertEquals(
98
+ $expectedUrl,
99
+ $this->subject->getInternalRedirectUri()
100
+ );
101
+ }
102
+
103
+ /**
104
+ * @loadFixture default
105
+ */
106
+ public function testGetMerchantAccountReturnsCorrectValue()
107
+ {
108
+ $expectedMerchantAccount = 'zaq1xsw2cde3';
109
+ $this->assertEquals(
110
+ $expectedMerchantAccount,
111
+ $this->subject->getMerchantAccount()
112
+ );
113
+ }
114
+
115
+ /**
116
+ * @loadFixture default
117
+ */
118
+ public function testGetMerchantIdReturnsCorrectValue()
119
+ {
120
+ $expectedMerchantId = '98098098';
121
+ $this->assertEquals(
122
+ $expectedMerchantId,
123
+ $this->subject->getMerchantId()
124
+ );
125
+ }
126
+
127
+ /**
128
+ * @loadFixture default
129
+ */
130
+ public function testGetMerchantPinReturnsCorrectValue()
131
+ {
132
+ $expectedMerchantPin = '6464646737373';
133
+ $this->assertEquals(
134
+ $expectedMerchantPin,
135
+ $this->subject->getMerchantPin()
136
+ );
137
+ }
138
+
139
+ /**
140
+ * @loadFixture default
141
+ */
142
+ public function testGetMerchantReferenceReturnsCorrectValue()
143
+ {
144
+ $expectedMerchantReference = 'Amazon';
145
+ $this->assertEquals(
146
+ $expectedMerchantReference,
147
+ $this->subject->getMerchantReference()
148
+ );
149
+ }
150
+
151
+ /**
152
+ * @loadFixture default
153
+ */
154
+ public function testGetDescriptionReturnsCorrectValue()
155
+ {
156
+ $expectedDescription = 'Test Description';
157
+ $this->assertEquals(
158
+ $expectedDescription,
159
+ $this->subject->getDescription()
160
+ );
161
+ }
162
+
163
+ /**
164
+ * @loadFixture default
165
+ */
166
+ public function testGetRedirectUriReturnsCorrectValue()
167
+ {
168
+ /** @var Mage_Core_Model_Url $urlModel */
169
+ $urlModel = Mage::getModel('core/url');
170
+ $expectedUrl = $urlModel->getUrl('tigomoney/return');
171
+ $this->assertEquals(
172
+ $expectedUrl,
173
+ $this->subject->getRedirectUri()
174
+ );
175
+ }
176
+
177
+ /**
178
+ * @loadFixture default
179
+ */
180
+ public function testGetFailureContinueShoppingUrlReturnsCorrectValue()
181
+ {
182
+ $expectedUrl = 'http://google.com/';
183
+ $this->assertEquals(
184
+ $expectedUrl,
185
+ $this->subject->getFailureContinueShoppingUrl()
186
+ );
187
+ }
188
+
189
+ /**
190
+ * @loadFixture default
191
+ */
192
+ public function testGetSuccessContinueShoppingUrlReturnsCorrectValue()
193
+ {
194
+ $expectedUrl = 'http://facebook.com/';
195
+ $this->assertEquals(
196
+ $expectedUrl,
197
+ $this->subject->getSuccessContinueShoppingUrl()
198
+ );
199
+ }
200
+
201
+ /**
202
+ * @loadFixture default
203
+ */
204
+ public function testGetSyncOrderUrlReturnsCorrectValue()
205
+ {
206
+ $orderId = 123928;
207
+ $this
208
+ ->order
209
+ ->expects($this->any())
210
+ ->method('getId')
211
+ ->will($this->returnValue($orderId));
212
+
213
+ /** @var Mage_Core_Model_Url $urlModel */
214
+ $urlModel = Mage::getModel('adminhtml/url');
215
+ $expectedUrl = $urlModel->getUrl(
216
+ 'adminhtml/tigomoney_order/sync',
217
+ array('order_id' => $orderId)
218
+ );
219
+ $this->assertEquals(
220
+ $expectedUrl,
221
+ $this->subject->getSyncOrderUrl($this->order)
222
+ );
223
+ }
224
+
225
+ /**
226
+ * @loadFixture default
227
+ */
228
+ public function testIsDebugModeEnabledReturnsTrueWhenConfigTrue()
229
+ {
230
+ $this->assertTrue(
231
+ $this->subject->isDebugModeEnabled()
232
+ );
233
+ }
234
+
235
+ /**
236
+ * @loadFixture default
237
+ */
238
+ public function testIsTestModeEnabledReturnsTrueWhenConfigTrue()
239
+ {
240
+ $this->assertTrue(
241
+ $this->subject->isTestModeEnabled()
242
+ );
243
+ }
244
+
245
+ /**
246
+ * @loadFixture disabledModes
247
+ */
248
+ public function testIsDebugModeEnabledReturnsFalseWhenConfigFalse()
249
+ {
250
+ $this->assertFalse(
251
+ $this->subject->isDebugModeEnabled()
252
+ );
253
+ }
254
+
255
+ /**
256
+ * @loadFixture disabledModes
257
+ */
258
+ public function testIsTestModeEnabledReturnsFalseWhenConfigFalse()
259
+ {
260
+ $this->assertFalse(
261
+ $this->subject->isTestModeEnabled()
262
+ );
263
+ }
264
+ }
265
+
app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Helper/DataTest/fixtures/default.yaml ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ config:
2
+ default/web/seo/use_rewrites: 1
3
+ default/payment/tigo_tigomoney/client_id: 123
4
+ default/payment/tigo_tigomoney/client_secret: asdf123fdsa
5
+ default/payment/tigo_tigomoney/merchant_account: zaq1xsw2cde3
6
+ default/payment/tigo_tigomoney/merchant_id: 98098098
7
+ default/payment/tigo_tigomoney/merchant_pin: 6464646737373
8
+ default/payment/tigo_tigomoney/merchant_reference: Amazon
9
+ default/payment/tigo_tigomoney/test_mode: 1
10
+ default/payment/tigo_tigomoney/debug_mode: 1
11
+ default/payment/tigo_tigomoney/description: Test Description
12
+ default/payment/tigo_tigomoney/failure_continue_shopping_url: http://google.com/
13
+ default/payment/tigo_tigomoney/success_continue_shopping_url: http://facebook.com/
app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Helper/DataTest/fixtures/disabledModes.yaml ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ config:
2
+ default/payment/tigo_tigomoney/test_mode: 0
3
+ default/payment/tigo_tigomoney/debug_mode: 0
app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Model/Adminhtml/ConfigCommentTest.php ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Tigo_TigoMoney_Model_Adminhtml_ConfigCommentTest
5
+ */
6
+ class Tigo_TigoMoney_Model_Adminhtml_ConfigCommentTest extends EcomDev_PHPUnit_Test_Case
7
+ {
8
+ /**
9
+ * @var String
10
+ */
11
+ protected $className = null;
12
+
13
+ /**
14
+ * @var Tigo_TigoMoney_Helper_Data|PHPUnit_Framework_MockObject_MockObject
15
+ */
16
+ protected $dataHelper = null;
17
+
18
+ /**
19
+ * @var Tigo_TigoMoney_Model_Adminhtml_ConfigComment|PHPUnit_Framework_MockObject_MockObject
20
+ */
21
+ protected $subject = null;
22
+
23
+ /**
24
+ * Sets up the unit test case
25
+ */
26
+ protected function setUp()
27
+ {
28
+ $this->className = Tigo_TigoMoney_Model_Adminhtml_ConfigComment::class;
29
+
30
+ $this->subject = $this->getModelMock(
31
+ 'tigo_tigomoney/adminhtml_configComment',
32
+ array('_isUrlRewriteEnabled')
33
+ );
34
+
35
+ $this->dataHelper = $this->getHelperMock(
36
+ 'tigo_tigomoney/data',
37
+ array(
38
+ 'getRedirectUri',
39
+ 'getCallbackUri'
40
+ )
41
+ );
42
+ $this->replaceByMock('helper', 'tigo_tigomoney/data', $this->dataHelper);
43
+ }
44
+
45
+ public function testGetCommentTextWillCallDataHelperMethodsForUrls()
46
+ {
47
+ $this
48
+ ->dataHelper
49
+ ->expects($this->once())
50
+ ->method('getRedirectUri');
51
+
52
+ $this
53
+ ->dataHelper
54
+ ->expects($this->once())
55
+ ->method('getCallbackUri');
56
+
57
+ $this->subject->getCommentText();
58
+ }
59
+
60
+ public function testGetCommentTextReturnNonRewrittenUrlsWhenUrlRewritesAreNotActive()
61
+ {
62
+ $this
63
+ ->subject
64
+ ->expects($this->any())
65
+ ->method('_isUrlRewriteEnabled')
66
+ ->will($this->returnValue(false));
67
+
68
+ $this
69
+ ->dataHelper
70
+ ->expects($this->once())
71
+ ->method('getRedirectUri')
72
+ ->will($this->returnValue('http://google.com/index.php/test'));
73
+
74
+ $this
75
+ ->dataHelper
76
+ ->expects($this->once())
77
+ ->method('getCallbackUri')
78
+ ->will($this->returnValue('http://microsoft.com/index.php/test'));
79
+
80
+ $return = $this->subject->getCommentText();
81
+
82
+ $this->assertRegExp('/http\:\/\/google\.com\/index\.php\/test/', $return);
83
+ $this->assertRegExp('/http\:\/\/microsoft\.com\/index\.php\/test/', $return);
84
+ }
85
+
86
+ public function testGetCommentTextReturnRewrittenUrlsWhenUrlRewritesAreActive()
87
+ {
88
+ $this
89
+ ->subject
90
+ ->expects($this->any())
91
+ ->method('_isUrlRewriteEnabled')
92
+ ->will($this->returnValue(true));
93
+
94
+ $this
95
+ ->dataHelper
96
+ ->expects($this->once())
97
+ ->method('getRedirectUri')
98
+ ->will($this->returnValue('http://google.com/index.php/test'));
99
+
100
+ $this
101
+ ->dataHelper
102
+ ->expects($this->once())
103
+ ->method('getCallbackUri')
104
+ ->will($this->returnValue('http://microsoft.com/index.php/test'));
105
+
106
+ $return = $this->subject->getCommentText();
107
+
108
+ $this->assertRegExp('/http\:\/\/google\.com\/test/', $return);
109
+ $this->assertRegExp('/http\:\/\/microsoft\.com\/test/', $return);
110
+ }
111
+ }
112
+
app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Model/Cron/SyncOldPendingOrdersTest.php ADDED
@@ -0,0 +1,192 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Tigo_TigoMoney_Model_Cron_SyncOldPendingOrdersTest
5
+ */
6
+ class Tigo_TigoMoney_Model_Cron_SyncOldPendingOrdersTest extends EcomDev_PHPUnit_Test_Case
7
+ {
8
+ /**
9
+ * @var Tigo_TigoMoney_Model_Debug|PHPUnit_Framework_MockObject_MockObject
10
+ */
11
+ protected $debug = null;
12
+
13
+ /**
14
+ * @var String
15
+ */
16
+ protected $className = null;
17
+
18
+ /**
19
+ * @var Mage_Sales_Model_Resource_Order_Collection|PHPUnit_Framework_MockObject_MockObject
20
+ */
21
+ protected $orderCollection = null;
22
+
23
+ /**
24
+ * @var Tigo_TigoMoney_Model_Cron_SyncOldPendingOrders|PHPUnit_Framework_MockObject_MockObject
25
+ */
26
+ protected $subject = null;
27
+
28
+ /**
29
+ * @var Tigo_TigoMoney_Model_Payment_Redirect_Sync|PHPUnit_Framework_MockObject_MockObject
30
+ */
31
+ protected $sync = null;
32
+
33
+ /**
34
+ * Sets up the unit test case
35
+ */
36
+ protected function setUp()
37
+ {
38
+ $this->className = Tigo_TigoMoney_Model_Cron_SyncOldPendingOrders::class;
39
+
40
+ $this->subject = $this
41
+ ->getMockBuilder($this->className)
42
+ ->setMethods(null)
43
+ ->getMock();
44
+
45
+ $this->debug = $this->getModelMock(
46
+ 'tigo_tigomoney/debug',
47
+ array('debug')
48
+ );
49
+ $this->replaceByMock('model', 'tigo_tigomoney/debug', $this->debug);
50
+
51
+
52
+ $this->orderCollection = $this->getResourceModelMock(
53
+ 'sales/order_collection',
54
+ array('addFieldToFilter', 'getItems')
55
+ );
56
+ $this->replaceByMock('resource_model', 'sales/order_collection', $this->orderCollection);
57
+
58
+
59
+ $this->sync = $this->getModelMock(
60
+ 'tigo_tigomoney/payment_redirect_sync',
61
+ array('syncOrder')
62
+ );
63
+ $this->replaceByMock('model', 'tigo_tigomoney/payment_redirect_sync', $this->sync);
64
+ }
65
+
66
+ public function testRunSyncsOnlyTigoMoneyPendingOrdersWithNoInvoicesAndNotCanceled()
67
+ {
68
+ $this
69
+ ->orderCollection
70
+ ->expects($this->exactly(2))
71
+ ->method('addFieldToFilter')
72
+ ->with(
73
+ $this->callback(
74
+ function($param) {
75
+ $return = false;
76
+ if ($param == 'payment.method' || $param == 'main_table.state') {
77
+ $return = true;
78
+ }
79
+ return $return;
80
+ }),
81
+ $this->callback(
82
+ function ($param) {
83
+ $return = false;
84
+ if (
85
+ ($param == array(array('like' => Tigo_TigoMoney_Model_Payment_Redirect::METHOD_CODE))) ||
86
+ ($param == array(array('nin' => array('complete', 'closed', 'canceled'))))
87
+ ) {
88
+ $return = true;
89
+ }
90
+ return $return;
91
+ }))
92
+ ->will($this->returnValue($this->orderCollection));
93
+
94
+ $order1 = $this->getModelMock('sales/order', array('hasInvoices', 'isCanceled'));
95
+ $order2 = $this->getModelMock('sales/order', array('hasInvoices', 'isCanceled'));
96
+ $order3 = $this->getModelMock('sales/order', array('hasInvoices', 'isCanceled'));
97
+ $order4 = $this->getModelMock('sales/order', array('hasInvoices', 'isCanceled'));
98
+
99
+ $order1
100
+ ->expects($this->any())
101
+ ->method('hasInvoices')
102
+ ->will($this->returnValue(false));
103
+ $order1
104
+ ->expects($this->any())
105
+ ->method('isCanceled')
106
+ ->will($this->returnValue(true));
107
+
108
+ $order2
109
+ ->expects($this->any())
110
+ ->method('hasInvoices')
111
+ ->will($this->returnValue(true));
112
+ $order2
113
+ ->expects($this->any())
114
+ ->method('isCanceled')
115
+ ->will($this->returnValue(false));
116
+
117
+ $order3
118
+ ->expects($this->any())
119
+ ->method('hasInvoices')
120
+ ->will($this->returnValue(true));
121
+ $order3
122
+ ->expects($this->any())
123
+ ->method('isCanceled')
124
+ ->will($this->returnValue(true));
125
+
126
+ $order4
127
+ ->expects($this->any())
128
+ ->method('hasInvoices')
129
+ ->will($this->returnValue(false));
130
+ $order4
131
+ ->expects($this->any())
132
+ ->method('isCanceled')
133
+ ->will($this->returnValue(false));
134
+
135
+ $this
136
+ ->orderCollection
137
+ ->expects($this->any())
138
+ ->method('getItems')
139
+ ->will($this->returnValue(array($order1, $order2, $order3, $order4)));
140
+
141
+ $this
142
+ ->sync
143
+ ->expects($this->once())
144
+ ->method('syncOrder')
145
+ ->with($order4);
146
+
147
+ $this->subject->run();
148
+ }
149
+
150
+ public function testRunWritesExceptionsToLog()
151
+ {
152
+ $this
153
+ ->orderCollection
154
+ ->expects($this->any())
155
+ ->method('addFieldToFilter')
156
+ ->will($this->returnValue($this->orderCollection));
157
+
158
+ $order1 = $this->getModelMock(
159
+ 'sales/order',
160
+ array('hasInvoices', 'isCanceled')
161
+ );
162
+
163
+ $order1
164
+ ->expects($this->any())
165
+ ->method('hasInvoices')
166
+ ->will($this->returnValue(false));
167
+ $order1
168
+ ->expects($this->any())
169
+ ->method('isCanceled')
170
+ ->will($this->returnValue(false));
171
+
172
+ $this
173
+ ->orderCollection
174
+ ->expects($this->any())
175
+ ->method('getItems')
176
+ ->will($this->returnValue(array($order1)));
177
+
178
+ $this
179
+ ->sync
180
+ ->expects($this->once())
181
+ ->method('syncOrder')
182
+ ->will($this->throwException(new Mage_Core_Exception('Error')));
183
+
184
+ $this
185
+ ->debug
186
+ ->expects($this->once())
187
+ ->method('debug');
188
+
189
+ $this->subject->run();
190
+ }
191
+ }
192
+
app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Model/Cron/SyncRecentPendingOrdersTest.php ADDED
@@ -0,0 +1,193 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Tigo_TigoMoney_Model_Cron_SyncRecentPendingOrdersTest
5
+ */
6
+ class Tigo_TigoMoney_Model_Cron_SyncRecentPendingOrdersTest extends EcomDev_PHPUnit_Test_Case
7
+ {
8
+ /**
9
+ * @var Tigo_TigoMoney_Model_Debug|PHPUnit_Framework_MockObject_MockObject
10
+ */
11
+ protected $debug = null;
12
+
13
+ /**
14
+ * @var String
15
+ */
16
+ protected $className = null;
17
+
18
+ /**
19
+ * @var Mage_Sales_Model_Resource_Order_Collection|PHPUnit_Framework_MockObject_MockObject
20
+ */
21
+ protected $orderCollection = null;
22
+
23
+ /**
24
+ * @var Tigo_TigoMoney_Model_Cron_SyncRecentPendingOrders|PHPUnit_Framework_MockObject_MockObject
25
+ */
26
+ protected $subject = null;
27
+
28
+ /**
29
+ * @var Tigo_TigoMoney_Model_Payment_Redirect_Sync|PHPUnit_Framework_MockObject_MockObject
30
+ */
31
+ protected $sync = null;
32
+
33
+ /**
34
+ * Sets up the unit test case
35
+ */
36
+ protected function setUp()
37
+ {
38
+ $this->className = Tigo_TigoMoney_Model_Cron_SyncRecentPendingOrders::class;
39
+
40
+ $this->subject = $this
41
+ ->getMockBuilder($this->className)
42
+ ->setMethods(null)
43
+ ->getMock();
44
+
45
+ $this->debug = $this->getModelMock(
46
+ 'tigo_tigomoney/debug',
47
+ array('debug')
48
+ );
49
+ $this->replaceByMock('model', 'tigo_tigomoney/debug', $this->debug);
50
+
51
+
52
+ $this->orderCollection = $this->getResourceModelMock(
53
+ 'sales/order_collection',
54
+ array('addFieldToFilter', 'getItems')
55
+ );
56
+ $this->replaceByMock('resource_model', 'sales/order_collection', $this->orderCollection);
57
+
58
+
59
+ $this->sync = $this->getModelMock(
60
+ 'tigo_tigomoney/payment_redirect_sync',
61
+ array('syncOrder')
62
+ );
63
+ $this->replaceByMock('model', 'tigo_tigomoney/payment_redirect_sync', $this->sync);
64
+ }
65
+
66
+ public function testRunSyncsOnlyTigoMoneyPendingOrdersWithNoInvoicesAndNotCanceled()
67
+ {
68
+ $this
69
+ ->orderCollection
70
+ ->expects($this->exactly(3))
71
+ ->method('addFieldToFilter')
72
+ ->with(
73
+ $this->callback(
74
+ function($param) {
75
+ $return = false;
76
+ if ($param == 'payment.method' || $param == 'main_table.state' || $param == 'main_table.created_at') {
77
+ $return = true;
78
+ }
79
+ return $return;
80
+ }),
81
+ $this->callback(
82
+ function ($param) {
83
+ $return = false;
84
+ if (
85
+ ($param == array(array('like' => Tigo_TigoMoney_Model_Payment_Redirect::METHOD_CODE))) ||
86
+ ($param == array(array('nin' => array('complete', 'closed', 'canceled')))) ||
87
+ (array_key_exists('from', $param) && array_key_exists('to', $param))
88
+ ) {
89
+ $return = true;
90
+ }
91
+ return $return;
92
+ }))
93
+ ->will($this->returnValue($this->orderCollection));
94
+
95
+ $order1 = $this->getModelMock('sales/order', array('hasInvoices', 'isCanceled'));
96
+ $order2 = $this->getModelMock('sales/order', array('hasInvoices', 'isCanceled'));
97
+ $order3 = $this->getModelMock('sales/order', array('hasInvoices', 'isCanceled'));
98
+ $order4 = $this->getModelMock('sales/order', array('hasInvoices', 'isCanceled'));
99
+
100
+ $order1
101
+ ->expects($this->any())
102
+ ->method('hasInvoices')
103
+ ->will($this->returnValue(false));
104
+ $order1
105
+ ->expects($this->any())
106
+ ->method('isCanceled')
107
+ ->will($this->returnValue(true));
108
+
109
+ $order2
110
+ ->expects($this->any())
111
+ ->method('hasInvoices')
112
+ ->will($this->returnValue(true));
113
+ $order2
114
+ ->expects($this->any())
115
+ ->method('isCanceled')
116
+ ->will($this->returnValue(false));
117
+
118
+ $order3
119
+ ->expects($this->any())
120
+ ->method('hasInvoices')
121
+ ->will($this->returnValue(true));
122
+ $order3
123
+ ->expects($this->any())
124
+ ->method('isCanceled')
125
+ ->will($this->returnValue(true));
126
+
127
+ $order4
128
+ ->expects($this->any())
129
+ ->method('hasInvoices')
130
+ ->will($this->returnValue(false));
131
+ $order4
132
+ ->expects($this->any())
133
+ ->method('isCanceled')
134
+ ->will($this->returnValue(false));
135
+
136
+ $this
137
+ ->orderCollection
138
+ ->expects($this->any())
139
+ ->method('getItems')
140
+ ->will($this->returnValue(array($order1, $order2, $order3, $order4)));
141
+
142
+ $this
143
+ ->sync
144
+ ->expects($this->once())
145
+ ->method('syncOrder')
146
+ ->with($order4);
147
+
148
+ $this->subject->run();
149
+ }
150
+
151
+ public function testRunWritesExceptionsToLog()
152
+ {
153
+ $this
154
+ ->orderCollection
155
+ ->expects($this->any())
156
+ ->method('addFieldToFilter')
157
+ ->will($this->returnValue($this->orderCollection));
158
+
159
+ $order1 = $this->getModelMock(
160
+ 'sales/order',
161
+ array('hasInvoices', 'isCanceled')
162
+ );
163
+
164
+ $order1
165
+ ->expects($this->any())
166
+ ->method('hasInvoices')
167
+ ->will($this->returnValue(false));
168
+ $order1
169
+ ->expects($this->any())
170
+ ->method('isCanceled')
171
+ ->will($this->returnValue(false));
172
+
173
+ $this
174
+ ->orderCollection
175
+ ->expects($this->any())
176
+ ->method('getItems')
177
+ ->will($this->returnValue(array($order1)));
178
+
179
+ $this
180
+ ->sync
181
+ ->expects($this->once())
182
+ ->method('syncOrder')
183
+ ->will($this->throwException(new Mage_Core_Exception('Error')));
184
+
185
+ $this
186
+ ->debug
187
+ ->expects($this->once())
188
+ ->method('debug');
189
+
190
+ $this->subject->run();
191
+ }
192
+ }
193
+
app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Model/DebugTest.php ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Tigo_TigoMoney_Model_DebugTest
5
+ */
6
+ class Tigo_TigoMoney_Model_DebugTest extends EcomDev_PHPUnit_Test_Case
7
+ {
8
+ /**
9
+ * @var String
10
+ */
11
+ protected $className = null;
12
+
13
+ /**
14
+ * @var Tigo_TigoMoney_Model_Debug|PHPUnit_Framework_MockObject_MockObject
15
+ */
16
+ protected $subject = null;
17
+
18
+ /**
19
+ * Sets up the unit test case
20
+ */
21
+ protected function setUp()
22
+ {
23
+ $this->className = Tigo_TigoMoney_Model_Debug::class;
24
+
25
+ $this->subject = $this
26
+ ->getMockBuilder($this->className)
27
+ ->setMethods(array('_writeLog'))
28
+ ->getMock();
29
+
30
+ }
31
+
32
+ /**
33
+ * @loadFixture debugModeOff
34
+ */
35
+ public function testDoesNotWriteToLogWhenDebugModeOff()
36
+ {
37
+ $this
38
+ ->subject
39
+ ->expects($this->never())
40
+ ->method('_writeLog');
41
+
42
+ $this
43
+ ->subject
44
+ ->debug('Test');
45
+ }
46
+
47
+ /**
48
+ * @loadFixture debugModeOn
49
+ */
50
+ public function testWritesCorrectStringValueToLogWhenDebugModeOn()
51
+ {
52
+ $debugValue = 'Test Test Test 123';
53
+ $this
54
+ ->subject
55
+ ->expects($this->once())
56
+ ->method('_writeLog')
57
+ ->with($debugValue);
58
+
59
+ $this
60
+ ->subject
61
+ ->debug($debugValue);
62
+ }
63
+
64
+ /**
65
+ * @loadFixture debugModeOn
66
+ */
67
+ public function testWritesCorrectArrayValueToLogWhenDebugModeOn()
68
+ {
69
+ $debugValue = array(1 => '234', 5 => '6789');
70
+ $this
71
+ ->subject
72
+ ->expects($this->once())
73
+ ->method('_writeLog')
74
+ ->with(print_r($debugValue, true));
75
+
76
+ $this
77
+ ->subject
78
+ ->debug($debugValue);
79
+ }
80
+ }
81
+
app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Model/DebugTest/fixtures/debugModeOff.yaml ADDED
@@ -0,0 +1,2 @@
 
 
1
+ config:
2
+ default/payment/tigo_tigomoney/debug_mode: 0
app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Model/DebugTest/fixtures/debugModeOn.yaml ADDED
@@ -0,0 +1,2 @@
 
 
1
+ config:
2
+ default/payment/tigo_tigomoney/debug_mode: 1
app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Model/Observer/AdminOrderViewTest.php ADDED
@@ -0,0 +1,295 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Tigo_TigoMoney_Model_Observer_AdminOrderViewTest
5
+ */
6
+ class Tigo_TigoMoney_Model_Observer_AdminOrderViewTest extends EcomDev_PHPUnit_Test_Case
7
+ {
8
+ /**
9
+ * @var String
10
+ */
11
+ protected $className = null;
12
+
13
+ /**
14
+ * @var Tigo_TigoMoney_Helper_Data
15
+ */
16
+ protected $dataHelper = null;
17
+
18
+ /**
19
+ * @var Mage_Core_Model_Observer|PHPUnit_Framework_MockObject_MockObject
20
+ */
21
+ protected $observer = null;
22
+
23
+ /**
24
+ * @var Mage_Sales_Model_Order|PHPUnit_Framework_MockObject_MockObject
25
+ */
26
+ protected $order = null;
27
+
28
+ /**
29
+ * @var Mage_Sales_Model_Order_Payment|PHPUnit_Framework_MockObject_MockObject
30
+ */
31
+ protected $payment = null;
32
+
33
+ /**
34
+ * @var Mage_Adminhtml_Block_Sales_Order_View|PHPUnit_Framework_MockObject_MockObject
35
+ */
36
+ protected $salesOrderViewBlock = null;
37
+
38
+ /**
39
+ * @var Tigo_TigoMoney_Model_Observer_AdminOrderView|PHPUnit_Framework_MockObject_MockObject
40
+ */
41
+ protected $subject = null;
42
+
43
+ /**
44
+ * Sets up the unit test case
45
+ */
46
+ protected function setUp()
47
+ {
48
+ $this->className = Tigo_TigoMoney_Model_Observer_AdminOrderView::class;
49
+
50
+ $this->subject = $this
51
+ ->getModelMock(
52
+ 'tigo_tigomoney/observer_adminOrderView',
53
+ array('_getSalesOrderEditBlock', '_getCurrentOrder')
54
+ );
55
+
56
+ $this->salesOrderViewBlock = $this->getBlockMock(
57
+ 'adminhtml/sales_order_view',
58
+ array('addButton'),
59
+ null,
60
+ array(),
61
+ null,
62
+ false
63
+ );
64
+
65
+
66
+ $this->payment = $this
67
+ ->getModelMock(
68
+ 'sales/order_payment',
69
+ array('getMethod')
70
+ );
71
+
72
+ $this->order = $this
73
+ ->getModelMock(
74
+ 'sales/order',
75
+ array('getId', 'getPayment', 'getStatus')
76
+ );
77
+
78
+ $this->order
79
+ ->expects($this->any())
80
+ ->method('getPayment')
81
+ ->will($this->returnValue($this->payment));
82
+
83
+ $this->replaceByMock('model', 'sales/order', $this->order);
84
+
85
+ $this->dataHelper = $this
86
+ ->getHelperMock(
87
+ 'tigo_tigomoney/data',
88
+ array()
89
+ );
90
+
91
+ $this->replaceByMock('helper', 'tigo_tigomoney', $this->dataHelper);
92
+
93
+ $this
94
+ ->subject
95
+ ->expects($this->any())
96
+ ->method('_getCurrentOrder')
97
+ ->will($this->returnValue($this->order));
98
+
99
+ $this->observer = $this
100
+ ->getModelMock(
101
+ 'core/observer',
102
+ null
103
+ );
104
+
105
+ $this->replaceByMock('model', 'core/observer', $this->observer);
106
+ }
107
+
108
+ public function testAddSyncButtonDoesNotAddButtonWhenSalesOrderEditNotFound()
109
+ {
110
+ $this
111
+ ->subject
112
+ ->expects($this->any())
113
+ ->method('_getSalesOrderEditBlock')
114
+ ->will($this->returnValue(null));
115
+
116
+ $this
117
+ ->salesOrderViewBlock
118
+ ->expects($this->never())
119
+ ->method('addButton');
120
+
121
+ $this->assertEquals(
122
+ $this->subject,
123
+ $this->subject->addSyncButton($this->observer)
124
+ );
125
+ }
126
+
127
+ public function testAddSyncButtonDoesNotAddButtonWhenOrderHasNoId()
128
+ {
129
+ $orderId = null;
130
+
131
+ $this
132
+ ->subject
133
+ ->expects($this->any())
134
+ ->method('_getSalesOrderEditBlock')
135
+ ->will($this->returnValue($this->salesOrderViewBlock));
136
+
137
+ $this
138
+ ->order
139
+ ->expects($this->any())
140
+ ->method('getId')
141
+ ->will($this->returnValue($orderId));
142
+
143
+ $this
144
+ ->salesOrderViewBlock
145
+ ->expects($this->never())
146
+ ->method('addButton');
147
+
148
+ $this->assertEquals(
149
+ $this->subject,
150
+ $this->subject->addSyncButton($this->observer)
151
+ );
152
+ }
153
+
154
+ public function testAddSyncButtonDoesNotAddButtonWhenPaymentMethodNotTigoMoney()
155
+ {
156
+ $orderId = 123123;
157
+ $paymentMethod = 'checkmo';
158
+
159
+ $this
160
+ ->subject
161
+ ->expects($this->any())
162
+ ->method('_getSalesOrderEditBlock')
163
+ ->will($this->returnValue($this->salesOrderViewBlock));
164
+
165
+ $this
166
+ ->order
167
+ ->expects($this->any())
168
+ ->method('getId')
169
+ ->will($this->returnValue($orderId));
170
+
171
+ $this
172
+ ->order
173
+ ->expects($this->any())
174
+ ->method('getId')
175
+ ->will($this->returnValue($orderId));
176
+
177
+ $this
178
+ ->payment
179
+ ->expects($this->any())
180
+ ->method('getMethod')
181
+ ->will($this->returnValue($paymentMethod));
182
+
183
+ $this
184
+ ->salesOrderViewBlock
185
+ ->expects($this->never())
186
+ ->method('addButton');
187
+
188
+ $this->assertEquals(
189
+ $this->subject,
190
+ $this->subject->addSyncButton($this->observer)
191
+ );
192
+ }
193
+
194
+ public function testAddSyncButtonDoesNotAddButtonWhenOrderStatusNotPending()
195
+ {
196
+ $orderId = 123123;
197
+ $paymentMethod = Tigo_TigoMoney_Model_Payment_Redirect::METHOD_CODE;
198
+ $status = 'processing';
199
+
200
+ $this
201
+ ->subject
202
+ ->expects($this->any())
203
+ ->method('_getSalesOrderEditBlock')
204
+ ->will($this->returnValue($this->salesOrderViewBlock));
205
+
206
+ $this
207
+ ->order
208
+ ->expects($this->any())
209
+ ->method('getId')
210
+ ->will($this->returnValue($orderId));
211
+
212
+ $this
213
+ ->order
214
+ ->expects($this->any())
215
+ ->method('getId')
216
+ ->will($this->returnValue($orderId));
217
+
218
+ $this
219
+ ->payment
220
+ ->expects($this->any())
221
+ ->method('getMethod')
222
+ ->will($this->returnValue($paymentMethod));
223
+
224
+ $this
225
+ ->order
226
+ ->expects($this->any())
227
+ ->method('getStatus')
228
+ ->will($this->returnValue($status));
229
+
230
+ $this
231
+ ->salesOrderViewBlock
232
+ ->expects($this->never())
233
+ ->method('addButton');
234
+
235
+ $this->assertEquals(
236
+ $this->subject,
237
+ $this->subject->addSyncButton($this->observer)
238
+ );
239
+ }
240
+
241
+ public function testAddSyncButtonAddsButtonSuccessfully()
242
+ {
243
+ $orderId = 123123;
244
+ $paymentMethod = Tigo_TigoMoney_Model_Payment_Redirect::METHOD_CODE;
245
+ $status = 'pending';
246
+
247
+ $this
248
+ ->subject
249
+ ->expects($this->any())
250
+ ->method('_getSalesOrderEditBlock')
251
+ ->will($this->returnValue($this->salesOrderViewBlock));
252
+
253
+ $this
254
+ ->order
255
+ ->expects($this->any())
256
+ ->method('getId')
257
+ ->will($this->returnValue($orderId));
258
+
259
+ $this
260
+ ->order
261
+ ->expects($this->any())
262
+ ->method('getId')
263
+ ->will($this->returnValue($orderId));
264
+
265
+ $this
266
+ ->payment
267
+ ->expects($this->any())
268
+ ->method('getMethod')
269
+ ->will($this->returnValue($paymentMethod));
270
+
271
+ $this
272
+ ->order
273
+ ->expects($this->any())
274
+ ->method('getStatus')
275
+ ->will($this->returnValue($status));
276
+
277
+ $this
278
+ ->salesOrderViewBlock
279
+ ->expects($this->once())
280
+ ->method('addButton')
281
+ ->with(
282
+ $this->equalTo('tigo_tigomoney_sync'),
283
+ array(
284
+ 'label' => $this->dataHelper->__(Tigo_TigoMoney_Model_Observer_AdminOrderView::BUTTON_LABEL),
285
+ 'onclick' => 'setLocation(\'' . $this->dataHelper->getSyncOrderUrl($this->order) . '\')',
286
+ 'class' => Tigo_TigoMoney_Model_Observer_AdminOrderView::BUTTON_CLASS
287
+ )
288
+ );
289
+
290
+ $this->assertEquals(
291
+ $this->subject,
292
+ $this->subject->addSyncButton($this->observer)
293
+ );
294
+ }
295
+ }
app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Model/Payment/Redirect/Api/AbstractResponseTest.php ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Tigo_TigoMoney_Model_Payment_Redirect_Api_AbstractResponseTest
5
+ */
6
+ class Tigo_TigoMoney_Model_Payment_Redirect_Api_AbstractResponseTest extends EcomDev_PHPUnit_Test_Case
7
+ {
8
+ /**
9
+ * @var String
10
+ */
11
+ protected $className = null;
12
+
13
+ /**
14
+ * @var Tigo_TigoMoney_Model_Payment_Redirect_Api_AbstractResponse|PHPUnit_Framework_MockObject_MockObject
15
+ */
16
+ protected $subject = null;
17
+
18
+ /**
19
+ * Sets up the unit test case
20
+ */
21
+ protected function setUp()
22
+ {
23
+ $this->className = Tigo_TigoMoney_Model_Payment_Redirect_Api_AbstractResponse::class;
24
+
25
+ $this->subject = $this
26
+ ->getModelMock(
27
+ 'tigo_tigomoney/payment_redirect_api_abstractResponse',
28
+ array(),
29
+ true,
30
+ array(new Varien_Object())
31
+ );
32
+
33
+ }
34
+
35
+ public function testResponseDataGetterSetter()
36
+ {
37
+ $key = 'mfsTransactionId';
38
+ $value = '393mas0932mam09maslk';
39
+ $this
40
+ ->subject
41
+ ->addResponseData($key, $value);
42
+ $this->assertEquals(
43
+ $value,
44
+ $this->subject->getResponseData($key)
45
+ );
46
+ }
47
+
48
+ public function testIsSuccessInitially()
49
+ {
50
+ $this->assertTrue(
51
+ $this->subject->isSuccess()
52
+ );
53
+ }
54
+
55
+ public function testIsErrorWhenErrorsAdded()
56
+ {
57
+ $this->subject->addError(('Some Error'));
58
+ $this->assertFalse(
59
+ $this->subject->isSuccess()
60
+ );
61
+ $this->assertTrue(
62
+ $this->subject->isError()
63
+ );
64
+ }
65
+
66
+ public function testErrorGetter()
67
+ {
68
+ $this->subject->addError(('Some Error 1'));
69
+ $this->subject->addError(('Some Error 1'));
70
+ $this->subject->addError(('Some Error 2'));
71
+ $this->subject->addError(('Some Error 3'));
72
+ $this->assertEquals(
73
+ array('Some Error 1', 'Some Error 2', 'Some Error 3'),
74
+ $this->subject->getErrors()
75
+ );
76
+ }
77
+
78
+ }
79
+
app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Model/Payment/Redirect/Api/AuthorizationRequestTest.php ADDED
@@ -0,0 +1,704 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Tigo_TigoMoney_Model_Payment_Redirect_Api_AuthorizationRequestTest
5
+ */
6
+ class Tigo_TigoMoney_Model_Payment_Redirect_Api_AuthorizationRequestTest extends EcomDev_PHPUnit_Test_Case
7
+ {
8
+ /**
9
+ * @var String
10
+ */
11
+ protected $className = null;
12
+
13
+ /**
14
+ * @var Tigo_TigoMoney_Model_Payment_Redirect_Api_AuthorizationRequest|PHPUnit_Framework_MockObject_MockObject
15
+ */
16
+ protected $subject = null;
17
+
18
+ /**
19
+ * Sets up the unit test case
20
+ */
21
+ protected function setUp()
22
+ {
23
+ $this->className = Tigo_TigoMoney_Model_Payment_Redirect_Api_AuthorizationRequest::class;
24
+
25
+ $this->subject = $this
26
+ ->getMockBuilder($this->className)
27
+ ->setMethods(null)
28
+ ->getMock();
29
+
30
+ }
31
+
32
+ public function testAccessTokenGetterSetter()
33
+ {
34
+ $value = '23298u294asdf0';
35
+ $this
36
+ ->subject
37
+ ->setAccessToken($value);
38
+ $this->assertEquals(
39
+ $value,
40
+ $this->subject->getAccessToken()
41
+ );
42
+ }
43
+
44
+ public function testCallbackUriGetterSetter()
45
+ {
46
+ $value = 'http://google.com/';
47
+ $this
48
+ ->subject
49
+ ->setCallbackUri($value);
50
+ $this->assertEquals(
51
+ $value,
52
+ $this->subject->getCallbackUri()
53
+ );
54
+ }
55
+
56
+ public function testExchangeRateGetterSetter()
57
+ {
58
+ $value = 1;
59
+ $this
60
+ ->subject
61
+ ->setExchangeRate($value);
62
+ $this->assertEquals(
63
+ $value,
64
+ $this->subject->getExchangeRate()
65
+ );
66
+ }
67
+
68
+ public function testEndpointPathGetter()
69
+ {
70
+ $value = Tigo_TigoMoney_Model_Payment_Redirect_Api_AuthorizationRequest::ENDPOINT_PATH;
71
+ $this->assertEquals(
72
+ $value,
73
+ $this->subject->getEndpointPath()
74
+ );
75
+ }
76
+
77
+ public function testHeaderGetter()
78
+ {
79
+ $accessToken = '39mvadsosm2';
80
+ $this
81
+ ->subject
82
+ ->setAccessToken($accessToken);
83
+ $this->assertEquals(
84
+ array(
85
+ Varien_Http_Client::CONTENT_TYPE => Tigo_TigoMoney_Model_Payment_Redirect_Api_AuthorizationRequest::CONTENT_TYPE_JSON,
86
+ 'Authorization' => 'Bearer ' . $accessToken
87
+ ),
88
+ $this->subject->getHeaders()
89
+ );
90
+ }
91
+
92
+ public function testLanguageGetterSetter()
93
+ {
94
+ $value = 'spa';
95
+ $this
96
+ ->subject
97
+ ->setLanguage($value);
98
+ $this->assertEquals(
99
+ $value,
100
+ $this->subject->getLanguage()
101
+ );
102
+ }
103
+
104
+ public function testLocalPaymentAmountGetterSetter()
105
+ {
106
+ $value = 1829.39;
107
+ $this
108
+ ->subject
109
+ ->setLocalPaymentAmount($value);
110
+ $this->assertEquals(
111
+ $value,
112
+ $this->subject->getLocalPaymentAmount()
113
+ );
114
+ }
115
+
116
+ public function testLocalPaymentCurrencyCodeGetterSetter()
117
+ {
118
+ $value = 'USD';
119
+ $this
120
+ ->subject
121
+ ->setLocalPaymentCurrencyCode($value);
122
+ $this->assertEquals(
123
+ $value,
124
+ $this->subject->getLocalPaymentCurrencyCode()
125
+ );
126
+ }
127
+
128
+ public function testMasterMerchantAccountGetterSetter()
129
+ {
130
+ $value = '9834938483';
131
+ $this
132
+ ->subject
133
+ ->setMasterMerchantAccount($value);
134
+ $this->assertEquals(
135
+ $value,
136
+ $this->subject->getMasterMerchantAccount()
137
+ );
138
+ }
139
+
140
+ public function testMasterMerchantPinGetterSetter()
141
+ {
142
+ $value = '393938';
143
+ $this
144
+ ->subject
145
+ ->setMasterMerchantPin($value);
146
+ $this->assertEquals(
147
+ $value,
148
+ $this->subject->getMasterMerchantPin()
149
+ );
150
+ }
151
+
152
+ public function testMasterMerchantIdGetterSetter()
153
+ {
154
+ $value = '1239871';
155
+ $this
156
+ ->subject
157
+ ->setMasterMerchantId($value);
158
+ $this->assertEquals(
159
+ $value,
160
+ $this->subject->getMasterMerchantId()
161
+ );
162
+ }
163
+
164
+ public function testMerchantReferenceGetterSetter()
165
+ {
166
+ $value = 'Amazon';
167
+ $this
168
+ ->subject
169
+ ->setMerchantReference($value);
170
+ $this->assertEquals(
171
+ $value,
172
+ $this->subject->getMerchantReference()
173
+ );
174
+ }
175
+
176
+ public function testMerchantTransactionIdGetterSetter()
177
+ {
178
+ $value = '10009283';
179
+ $this
180
+ ->subject
181
+ ->setMerchantTransactionId($value);
182
+ $this->assertEquals(
183
+ $value,
184
+ $this->subject->getMerchantTransactionId()
185
+ );
186
+ }
187
+
188
+ public function testMerchantFeeGetterSetter()
189
+ {
190
+ $value = 27.50;
191
+ $this
192
+ ->subject
193
+ ->setMerchantFee($value);
194
+ $this->assertEquals(
195
+ $value,
196
+ $this->subject->getMerchantFee()
197
+ );
198
+ }
199
+
200
+ public function testMerchantCurrencyCodeGetterSetter()
201
+ {
202
+ $value = 'USD';
203
+ $this
204
+ ->subject
205
+ ->setMerchantCurrencyCode($value);
206
+ $this->assertEquals(
207
+ $value,
208
+ $this->subject->getMerchantCurrencyCode()
209
+ );
210
+ }
211
+
212
+ public function testMethodGetter()
213
+ {
214
+ $this->assertEquals(
215
+ Varien_Http_Client::POST,
216
+ $this->subject->getMethod()
217
+ );
218
+ }
219
+
220
+ public function testOriginPaymentAmountGetterSetter()
221
+ {
222
+ $value = 8372.08;
223
+ $this
224
+ ->subject
225
+ ->setOriginPaymentAmount($value);
226
+ $this->assertEquals(
227
+ $value,
228
+ $this->subject->getOriginPaymentAmount()
229
+ );
230
+ }
231
+
232
+ public function testOriginPaymentCurrencyCodeGetterSetter()
233
+ {
234
+ $value = 'USD';
235
+ $this
236
+ ->subject
237
+ ->setOriginPaymentCurrencyCode($value);
238
+ $this->assertEquals(
239
+ $value,
240
+ $this->subject->getOriginPaymentCurrencyCode()
241
+ );
242
+ }
243
+
244
+ public function testOriginPaymentTaxGetterSetter()
245
+ {
246
+ $value = 9383.43;
247
+ $this
248
+ ->subject
249
+ ->setOriginPaymentTax($value);
250
+ $this->assertEquals(
251
+ $value,
252
+ $this->subject->getOriginPaymentTax()
253
+ );
254
+ }
255
+
256
+ public function testOriginPaymentFeeGetterSetter()
257
+ {
258
+ $value = 87.20;
259
+ $this
260
+ ->subject
261
+ ->setOriginPaymentFee($value);
262
+ $this->assertEquals(
263
+ $value,
264
+ $this->subject->getOriginPaymentFee()
265
+ );
266
+ }
267
+
268
+ public function testRedirectUriGetterSetter()
269
+ {
270
+ $value = 'http://amazon.com/';
271
+ $this
272
+ ->subject
273
+ ->setRedirectUri($value);
274
+ $this->assertEquals(
275
+ $value,
276
+ $this->subject->getRedirectUri()
277
+ );
278
+ }
279
+
280
+ public function testSubscriberAccountGetterSetter()
281
+ {
282
+ $value = '746363638';
283
+ $this
284
+ ->subject
285
+ ->setSubscriberAccount($value);
286
+ $this->assertEquals(
287
+ $value,
288
+ $this->subject->getSubscriberAccount()
289
+ );
290
+ }
291
+
292
+ public function testSubscriberCountryCodeGetterSetter()
293
+ {
294
+ $value = '57';
295
+ $this
296
+ ->subject
297
+ ->setSubscriberCountryCode($value);
298
+ $this->assertEquals(
299
+ $value,
300
+ $this->subject->getSubscriberCountryCode()
301
+ );
302
+ }
303
+
304
+ public function testSubscriberCountryGetterSetter()
305
+ {
306
+ $value = 'SLV';
307
+ $this
308
+ ->subject
309
+ ->setSubscriberCountry($value);
310
+ $this->assertEquals(
311
+ $value,
312
+ $this->subject->getSubscriberCountry()
313
+ );
314
+ }
315
+
316
+ public function testSubscriberFirstNameGetterSetter()
317
+ {
318
+ $value = 'John';
319
+ $this
320
+ ->subject
321
+ ->setSubscriberFirstName($value);
322
+ $this->assertEquals(
323
+ $value,
324
+ $this->subject->getSubscriberFirstName()
325
+ );
326
+ }
327
+
328
+ public function testSubscriberLastNameGetterSetter()
329
+ {
330
+ $value = 'Doe';
331
+ $this
332
+ ->subject
333
+ ->setSubscriberLastName($value);
334
+ $this->assertEquals(
335
+ $value,
336
+ $this->subject->getSubscriberLastName()
337
+ );
338
+ }
339
+
340
+ public function testSubscriberEmailGetterSetter()
341
+ {
342
+ $value = 'johndoe@gmail.com';
343
+ $this
344
+ ->subject
345
+ ->setSubscriberEmail($value);
346
+ $this->assertEquals(
347
+ $value,
348
+ $this->subject->getSubscriberEmail()
349
+ );
350
+ }
351
+
352
+ public function testTerminalIdGetterSetter()
353
+ {
354
+ $value = 'Magento';
355
+ $this
356
+ ->subject
357
+ ->setTerminalId($value);
358
+ $this->assertEquals(
359
+ $value,
360
+ $this->subject->getTerminalId()
361
+ );
362
+ }
363
+
364
+ public function testValidateDataProvider()
365
+ {
366
+ return array(
367
+ array('jsndf', '0sdnf', '09jasdf', 'lkmfalsdk', '83729837', 'SLV', '570', 'John', 'Doe', 'johndoe@gmail.com', 100.38, 'USD', 'http://google.com', 'http://amazon.com', 'SPA', '10000298', true),
368
+ array('jsndf', '0sdnf', '09jasdf', 'lkmfalsdk', '83729837', 'SLV', '570', 'John', 'Doe', 'johndoe@gmail.com', 100.38, 'USD', 'http://google.com', 'http://amazon.com', null, '10000298', false),
369
+ array('jsndf', '0sdnf', '09jasdf', 'lkmfalsdk', '83729837', 'SLV', '570', 'John', 'Doe', 'johndoe@gmail.com', 100.38, 'USD', 'http://google.com', null, 'SPA', '10000298', false),
370
+ array('jsndf', '0sdnf', '09jasdf', 'lkmfalsdk', '83729837', 'SLV', '570', 'John', 'Doe', 'johndoe@gmail.com', 100.38, 'USD', null, 'http://amazon.com', 'SPA', '10000298', false),
371
+ array('jsndf', '0sdnf', '09jasdf', 'lkmfalsdk', '83729837', 'SLV', '570', 'John', 'Doe', 'johndoe@gmail.com', 100.38, null, 'http://google.com', 'http://amazon.com', 'SPA', '10000298', false),
372
+ array('jsndf', '0sdnf', '09jasdf', 'lkmfalsdk', '83729837', 'SLV', '570', 'John', 'Doe', 'johndoe@gmail.com', null, 'USD', 'http://google.com', 'http://amazon.com', 'SPA', '10000298', false),
373
+ array('jsndf', '0sdnf', '09jasdf', 'lkmfalsdk', '83729837', 'SLV', '570', 'John', 'Doe', null, 100.38, 'USD', 'http://google.com', 'http://amazon.com', 'SPA', '10000298', false),
374
+ array('jsndf', '0sdnf', '09jasdf', 'lkmfalsdk', '83729837', 'SLV', '570', 'John', null, 'johndoe@gmail.com', 100.38, 'USD', 'http://google.com', 'http://amazon.com', 'SPA', '10000298', false),
375
+ array('jsndf', '0sdnf', '09jasdf', 'lkmfalsdk', '83729837', 'SLV', '570', null, 'Doe', 'johndoe@gmail.com', 100.38, 'USD', 'http://google.com', 'http://amazon.com', 'SPA', '10000298', false),
376
+ array('jsndf', '0sdnf', '09jasdf', 'lkmfalsdk', '83729837', 'SLV', null, 'John', 'Doe', 'johndoe@gmail.com', 100.38, 'USD', 'http://google.com', 'http://amazon.com', 'SPA', '10000298', false),
377
+ array('jsndf', '0sdnf', '09jasdf', 'lkmfalsdk', '83729837', null, '570', 'John', 'Doe', 'johndoe@gmail.com', 100.38, 'USD', 'http://google.com', 'http://amazon.com', 'SPA', '10000298', false),
378
+ array('jsndf', '0sdnf', '09jasdf', 'lkmfalsdk', null, 'SLV', '570', 'John', 'Doe', 'johndoe@gmail.com', 100.38, 'USD', 'http://google.com', 'http://amazon.com', 'SPA', '10000298', false),
379
+ array('jsndf', '0sdnf', '09jasdf', null, '83729837', 'SLV', '570', 'John', 'Doe', 'johndoe@gmail.com', 100.38, 'USD', 'http://google.com', 'http://amazon.com', 'SPA', '10000298', false),
380
+ array('jsndf', '0sdnf', null, 'lkmfalsdk', '83729837', 'SLV', '570', 'John', 'Doe', 'johndoe@gmail.com', 100.38, 'USD', 'http://google.com', 'http://amazon.com', 'SPA', '10000298', false),
381
+ array('jsndf', null, '09jasdf', 'lkmfalsdk', '83729837', 'SLV', '570', 'John', 'Doe', 'johndoe@gmail.com', 100.38, 'USD', 'http://google.com', 'http://amazon.com', 'SPA', '10000298', false),
382
+ array(null, '0sdnf', '09jasdf', 'lkmfalsdk', '83729837', 'SLV', '570', 'John', 'Doe', 'johndoe@gmail.com', 100.38, 'USD', 'http://google.com', 'http://amazon.com', 'SPA', '10000298', false)
383
+ );
384
+ }
385
+
386
+ /**
387
+ * @param $accessToken
388
+ * @param $masterMerchantAccount
389
+ * @param $masterMerchantPin
390
+ * @param $masterMerchantId
391
+ * @param $subscriberAccount
392
+ * @param $subscriberCountry
393
+ * @param $subscriberCountryCode
394
+ * @param $subscriberFirstName
395
+ * @param $subscriberLastName
396
+ * @param $subscriberEmail
397
+ * @param $localPaymentAmount
398
+ * @param $localPaymentCurrencyCode
399
+ * @param $redirectUri
400
+ * @param $callbackUri
401
+ * @param $language
402
+ * @param $merchantTransactionId
403
+ * @param $result
404
+ * @dataProvider testValidateDataProvider
405
+ */
406
+ public function testValidate(
407
+ $accessToken,
408
+ $masterMerchantAccount,
409
+ $masterMerchantPin,
410
+ $masterMerchantId,
411
+ $subscriberAccount,
412
+ $subscriberCountry,
413
+ $subscriberCountryCode,
414
+ $subscriberFirstName,
415
+ $subscriberLastName,
416
+ $subscriberEmail,
417
+ $localPaymentAmount,
418
+ $localPaymentCurrencyCode,
419
+ $redirectUri,
420
+ $callbackUri,
421
+ $language,
422
+ $merchantTransactionId,
423
+ $result
424
+ )
425
+ {
426
+ $this
427
+ ->subject
428
+ ->setAccessToken($accessToken);
429
+ $this
430
+ ->subject
431
+ ->setMasterMerchantAccount($masterMerchantAccount);
432
+
433
+ $this
434
+ ->subject
435
+ ->setMasterMerchantPin($masterMerchantPin);
436
+
437
+ $this
438
+ ->subject
439
+ ->setMasterMerchantId($masterMerchantId);
440
+
441
+ $this
442
+ ->subject
443
+ ->setSubscriberAccount($subscriberAccount);
444
+
445
+ $this
446
+ ->subject
447
+ ->setSubscriberCountry($subscriberCountry);
448
+
449
+ $this
450
+ ->subject
451
+ ->setSubscriberCountryCode($subscriberCountryCode);
452
+
453
+ $this
454
+ ->subject
455
+ ->setSubscriberFirstName($subscriberFirstName);
456
+
457
+ $this
458
+ ->subject
459
+ ->setSubscriberLastName($subscriberLastName);
460
+
461
+ $this
462
+ ->subject
463
+ ->setSubscriberEmail($subscriberEmail);
464
+
465
+ $this
466
+ ->subject
467
+ ->setLocalPaymentAmount($localPaymentAmount);
468
+
469
+ $this
470
+ ->subject
471
+ ->setLocalPaymentCurrencyCode($localPaymentCurrencyCode);
472
+
473
+ $this
474
+ ->subject
475
+ ->setRedirectUri($redirectUri);
476
+
477
+ $this
478
+ ->subject
479
+ ->setCallbackUri($callbackUri);
480
+
481
+ $this
482
+ ->subject
483
+ ->setLanguage($language);
484
+
485
+ $this
486
+ ->subject
487
+ ->setMerchantTransactionId($merchantTransactionId);
488
+
489
+ $this->assertEquals(
490
+ $result,
491
+ $this->subject->validate()
492
+ );
493
+ }
494
+
495
+ public function testGetBodyWithMerchantInfoDataProvider()
496
+ {
497
+ return array(
498
+ array('839232', '92839283', '932934', '29384234', 'Amazon', '28329823', 'Luis', 'Solano', 'luissolano@hotmail.com', 279.93, 279.93, 0, 0, 'http://google.com', 'http://amazon.com', '100009283', 1),
499
+ array('839232', '92839283', '932934', '29384234', null, '28329823', 'Luis', 'Solano', 'luissolano@hotmail.com', 279.93, 279.93, 0, 0, 'http://google.com', 'http://amazon.com', '100009283-1', 1)
500
+ );
501
+ }
502
+
503
+ /**
504
+ * @param $accessToken
505
+ * @param $merchantAccount
506
+ * @param $merchantPin
507
+ * @param $merchantId
508
+ * @param $merchantReference
509
+ * @param $subscriberAccount
510
+ * @param $subscriberFirstName
511
+ * @param $subscriberLastName
512
+ * @param $subscriberEmail
513
+ * @param $localPaymentAmount
514
+ * @param $originPaymentAmount
515
+ * @param $originPaymentTax
516
+ * @param $originPaymentFee
517
+ * @param $redirectUri
518
+ * @param $callbackUri
519
+ * @param $merchantTransactionId
520
+ * @param $exchangeRate
521
+ * @dataProvider testGetBodyWithMerchantInfoDataProvider
522
+ */
523
+ public function testGetBodyWithMerchantInfo(
524
+ $accessToken,
525
+ $merchantAccount,
526
+ $merchantPin,
527
+ $merchantId,
528
+ $merchantReference,
529
+ $subscriberAccount,
530
+ $subscriberFirstName,
531
+ $subscriberLastName,
532
+ $subscriberEmail,
533
+ $localPaymentAmount,
534
+ $originPaymentAmount,
535
+ $originPaymentTax,
536
+ $originPaymentFee,
537
+ $redirectUri,
538
+ $callbackUri,
539
+ $merchantTransactionId,
540
+ $exchangeRate
541
+ ) {
542
+ # Access Token
543
+ $this->subject->setAccessToken($accessToken);
544
+
545
+ # Master Merchant Account Info
546
+ $this->subject->setMasterMerchantAccount($merchantAccount);
547
+ $this->subject->setMasterMerchantPin($merchantPin);
548
+ $this->subject->setMasterMerchantId($merchantId);
549
+
550
+ # Merchant Info
551
+ $this->subject->setMerchantReference($merchantReference);
552
+ $this->subject->setMerchantCurrencyCode(Tigo_TigoMoney_Model_Payment_Redirect_Api_AuthorizationRequest::CURRENCY_CODE_USD);
553
+ $this->subject->setMerchantFee(0);
554
+
555
+ # Subscriber
556
+ $this->subject->setSubscriberAccount($subscriberAccount);
557
+ $this->subject->setSubscriberCountry(Tigo_TigoMoney_Model_Payment_Redirect_Api_AuthorizationRequest::COUNTRY_CODE);
558
+ $this->subject->setSubscriberCountryCode(Tigo_TigoMoney_Model_Payment_Redirect_Api_AuthorizationRequest::COUNTRY_DIAL_CODE);
559
+ $this->subject->setSubscriberFirstName($subscriberFirstName);
560
+ $this->subject->setSubscriberLastName($subscriberLastName);
561
+ $this->subject->setSubscriberEmail($subscriberEmail);
562
+
563
+ # Local Payment
564
+ $this->subject->setLocalPaymentAmount($localPaymentAmount);
565
+ $this->subject->setLocalPaymentCurrencyCode(Tigo_TigoMoney_Model_Payment_Redirect_Api_AuthorizationRequest::CURRENCY_CODE_USD);
566
+
567
+ # Origin Payment
568
+ $this->subject->setOriginPaymentAmount($originPaymentAmount);
569
+ $this->subject->setOriginPaymentCurrencyCode(Tigo_TigoMoney_Model_Payment_Redirect_Api_AuthorizationRequest::CURRENCY_CODE_USD);
570
+ $this->subject->setOriginPaymentTax($originPaymentTax);
571
+ $this->subject->setOriginPaymentFee($originPaymentFee);
572
+
573
+ # Additional Info
574
+ $this->subject->setRedirectUri($redirectUri);
575
+ $this->subject->setCallbackUri($callbackUri);
576
+ $this->subject->setLanguage(Tigo_TigoMoney_Model_Payment_Redirect_Api_AuthorizationRequest::LANGUAGE_CODE_SPANISH);
577
+ $this->subject->setMerchantTransactionId($merchantTransactionId);
578
+ $this->subject->setTerminalId(Tigo_TigoMoney_Model_Payment_Redirect_Api_AuthorizationRequest::TERMINAL_ID);
579
+ $this->subject->setExchangeRate($exchangeRate);
580
+
581
+ $requestBody = $this->subject->getBody();
582
+
583
+ $requestBodyJsonArr = json_decode($requestBody, true);
584
+
585
+ $this->assertEquals(
586
+ $requestBodyJsonArr['MasterMerchant']['account'],
587
+ $merchantAccount
588
+ );
589
+
590
+ $this->assertEquals(
591
+ $requestBodyJsonArr['MasterMerchant']['pin'],
592
+ $merchantPin
593
+ );
594
+
595
+ $this->assertEquals(
596
+ $requestBodyJsonArr['MasterMerchant']['id'],
597
+ $merchantId
598
+ );
599
+
600
+ if ($merchantReference) {
601
+ $this->assertArrayHasKey('Merchant', $requestBodyJsonArr);
602
+ if (array_key_exists('Merchant', $requestBodyJsonArr)) {
603
+ $this->assertEquals(
604
+ $requestBodyJsonArr['Merchant']['reference'],
605
+ $merchantReference
606
+ );
607
+ }
608
+ } else {
609
+ $this->assertArrayNotHasKey('Merchant', $requestBodyJsonArr);
610
+ }
611
+
612
+ $this->assertEquals(
613
+ $requestBodyJsonArr['Subscriber']['account'],
614
+ $subscriberAccount
615
+ );
616
+
617
+ $this->assertEquals(
618
+ $requestBodyJsonArr['Subscriber']['countryCode'],
619
+ Tigo_TigoMoney_Model_Payment_Redirect_Api_AuthorizationRequest::COUNTRY_DIAL_CODE
620
+ );
621
+
622
+ $this->assertEquals(
623
+ $requestBodyJsonArr['Subscriber']['country'],
624
+ Tigo_TigoMoney_Model_Payment_Redirect_Api_AuthorizationRequest::COUNTRY_CODE
625
+ );
626
+
627
+ $this->assertEquals(
628
+ $requestBodyJsonArr['Subscriber']['firstName'],
629
+ $subscriberFirstName
630
+ );
631
+
632
+ $this->assertEquals(
633
+ $requestBodyJsonArr['Subscriber']['lastName'],
634
+ $subscriberLastName
635
+ );
636
+
637
+ $this->assertEquals(
638
+ $requestBodyJsonArr['Subscriber']['emailId'],
639
+ $subscriberEmail
640
+ );
641
+
642
+ $this->assertEquals(
643
+ $requestBodyJsonArr['OriginPayment']['amount'],
644
+ number_format($originPaymentAmount, 2, '.', '')
645
+ );
646
+
647
+ $this->assertEquals(
648
+ $requestBodyJsonArr['OriginPayment']['currencyCode'],
649
+ Tigo_TigoMoney_Model_Payment_Redirect_Api_AuthorizationRequest::CURRENCY_CODE_USD
650
+ );
651
+
652
+ $this->assertEquals(
653
+ $requestBodyJsonArr['OriginPayment']['tax'],
654
+ number_format($originPaymentFee, 2, '.', '')
655
+ );
656
+
657
+ $this->assertEquals(
658
+ $requestBodyJsonArr['OriginPayment']['fee'],
659
+ number_format($originPaymentTax, 2, '.', '')
660
+ );
661
+
662
+ $this->assertEquals(
663
+ $requestBodyJsonArr['LocalPayment']['amount'],
664
+ number_format($localPaymentAmount, 2, '.', '')
665
+ );
666
+
667
+ $this->assertEquals(
668
+ $requestBodyJsonArr['LocalPayment']['currencyCode'],
669
+ Tigo_TigoMoney_Model_Payment_Redirect_Api_AuthorizationRequest::CURRENCY_CODE_USD
670
+ );
671
+
672
+ $this->assertEquals(
673
+ $requestBodyJsonArr['redirectUri'],
674
+ $redirectUri
675
+ );
676
+
677
+ $this->assertEquals(
678
+ $requestBodyJsonArr['callbackUri'],
679
+ $callbackUri
680
+ );
681
+
682
+ $this->assertEquals(
683
+ $requestBodyJsonArr['language'],
684
+ Tigo_TigoMoney_Model_Payment_Redirect_Api_AuthorizationRequest::LANGUAGE_CODE_SPANISH
685
+ );
686
+
687
+ $this->assertEquals(
688
+ $requestBodyJsonArr['terminalId'],
689
+ Tigo_TigoMoney_Model_Payment_Redirect_Api_AuthorizationRequest::TERMINAL_ID
690
+ );
691
+
692
+ $this->assertEquals(
693
+ $requestBodyJsonArr['exchangeRate'],
694
+ number_format($exchangeRate, 2, '.', '')
695
+ );
696
+
697
+ $this->assertEquals(
698
+ $requestBodyJsonArr['merchantTransactionId'],
699
+ $merchantTransactionId
700
+ );
701
+
702
+ }
703
+ }
704
+
app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Model/Payment/Redirect/Api/AuthorizationResponseTest.php ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Tigo_TigoMoney_Model_Payment_Redirect_Api_AuthorizationResponseTest
5
+ */
6
+ class Tigo_TigoMoney_Model_Payment_Redirect_Api_AuthorizationResponseTest extends EcomDev_PHPUnit_Test_Case
7
+ {
8
+ /**
9
+ * @var String
10
+ */
11
+ protected $className = null;
12
+
13
+ /**
14
+ * @var Tigo_TigoMoney_Model_Payment_Redirect_Api_AuthorizationResponse|PHPUnit_Framework_MockObject_MockObject
15
+ */
16
+ protected $subject = null;
17
+
18
+ /**
19
+ * Sets up the unit test case
20
+ */
21
+ protected function setUp()
22
+ {
23
+ $this->className = Tigo_TigoMoney_Model_Payment_Redirect_Api_AuthorizationResponse::class;
24
+
25
+ $this->subject = $this
26
+ ->getMockBuilder($this->className)
27
+ ->setMethods(null)
28
+ ->setConstructorArgs(array(new Varien_Object()))
29
+ ->getMock();
30
+
31
+ }
32
+
33
+ public function testAuthCodeGetterSetter()
34
+ {
35
+ $value = '9493230923';
36
+ $this
37
+ ->subject
38
+ ->setAuthCode($value);
39
+ $this->assertEquals(
40
+ $value,
41
+ $this->subject->getAuthCode()
42
+ );
43
+ }
44
+
45
+ public function testRedirectUriGetterSetter()
46
+ {
47
+ $value = 'http://altavista.com/';
48
+ $this
49
+ ->subject
50
+ ->setRedirectUri($value);
51
+ $this->assertEquals(
52
+ $value,
53
+ $this->subject->getRedirectUri()
54
+ );
55
+ }
56
+
57
+ }
58
+
app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Model/Payment/Redirect/Api/GenerateTokenRequestTest.php ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Tigo_TigoMoney_Model_Payment_Redirect_Api_GenerateTokenRequestTest
5
+ */
6
+ class Tigo_TigoMoney_Model_Payment_Redirect_Api_GenerateTokenRequestTest extends EcomDev_PHPUnit_Test_Case
7
+ {
8
+ /**
9
+ * @var String
10
+ */
11
+ protected $className = null;
12
+
13
+ /**
14
+ * @var Tigo_TigoMoney_Model_Payment_Redirect_Api_GenerateTokenRequest|PHPUnit_Framework_MockObject_MockObject
15
+ */
16
+ protected $subject = null;
17
+
18
+ /**
19
+ * Sets up the unit test case
20
+ */
21
+ protected function setUp()
22
+ {
23
+ $this->className = Tigo_TigoMoney_Model_Payment_Redirect_Api_GenerateTokenRequest::class;
24
+
25
+ $this->subject = $this
26
+ ->getMockBuilder($this->className)
27
+ ->setMethods(null)
28
+ ->getMock();
29
+
30
+ }
31
+
32
+ public function testClientIdGetterSetter()
33
+ {
34
+ $value = '12314123';
35
+ $this
36
+ ->subject
37
+ ->setClientId($value);
38
+ $this->assertEquals(
39
+ $value,
40
+ $this->subject->getClientId()
41
+ );
42
+ }
43
+
44
+ public function testClientSecretGetterSetter()
45
+ {
46
+ $value = 'mkdkmsdmf093asdfasdfas23';
47
+ $this
48
+ ->subject
49
+ ->setClientSecret($value);
50
+ $this->assertEquals(
51
+ $value,
52
+ $this->subject->getClientSecret()
53
+ );
54
+ }
55
+
56
+ public function testEndpointPathGetter()
57
+ {
58
+ $value = Tigo_TigoMoney_Model_Payment_Redirect_Api_GenerateTokenRequest::ENDPOINT_PATH;
59
+ $this->assertEquals(
60
+ $value,
61
+ $this->subject->getEndpointPath()
62
+ );
63
+ }
64
+
65
+ public function testHeaderGetter()
66
+ {
67
+ $clientId = '12314123';
68
+ $clientSecret = 'mkdkmsdmf093asdfasdfas23';
69
+ $this
70
+ ->subject
71
+ ->setClientId($clientId);
72
+ $this
73
+ ->subject
74
+ ->setClientSecret($clientSecret);
75
+ $this->assertEquals(
76
+ array(
77
+ Varien_Http_Client::CONTENT_TYPE => Varien_Http_Client::ENC_URLENCODED,
78
+ 'Authorization' => 'Basic ' . base64_encode($clientId . ':' . $clientSecret)
79
+ ),
80
+ $this->subject->getHeaders()
81
+ );
82
+ }
83
+
84
+ public function testMethodGetter()
85
+ {
86
+ $this->assertEquals(
87
+ Varien_Http_Client::POST,
88
+ $this->subject->getMethod()
89
+ );
90
+ }
91
+
92
+ public function testValidateDataProvider()
93
+ {
94
+ return array(
95
+ array('231231', 'asmsdafsdfln', true),
96
+ array('231231', null, false),
97
+ array(null, 'asmsdafsdfln', false),
98
+ );
99
+ }
100
+
101
+ /**
102
+ * @param $clientId
103
+ * @param $clientSecret
104
+ * @param $result
105
+ * @dataProvider testValidateDataProvider
106
+ */
107
+ public function testValidate(
108
+ $clientId,
109
+ $clientSecret,
110
+ $result
111
+ ) {
112
+ $this
113
+ ->subject
114
+ ->setClientId($clientId);
115
+ $this
116
+ ->subject
117
+ ->setClientSecret($clientSecret);
118
+
119
+ $this->assertEquals(
120
+ $result,
121
+ $this->subject->validate()
122
+ );
123
+ }
124
+
125
+ public function testGetBody() {
126
+
127
+ $requestBody = $this->subject->getBody();
128
+
129
+ $this->assertEquals(
130
+ Tigo_TigoMoney_Model_Payment_Redirect_Api_GenerateTokenRequest::REQUEST_BODY,
131
+ $requestBody
132
+ );
133
+
134
+ }
135
+ }
136
+
app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Model/Payment/Redirect/Api/GenerateTokenResponseTest.php ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Tigo_TigoMoney_Model_Payment_Redirect_Api_GenerateTokenResponseTest
5
+ */
6
+ class Tigo_TigoMoney_Model_Payment_Redirect_Api_GenerateTokenResponseTest extends EcomDev_PHPUnit_Test_Case
7
+ {
8
+ /**
9
+ * @var String
10
+ */
11
+ protected $className = null;
12
+
13
+ /**
14
+ * @var Tigo_TigoMoney_Model_Payment_Redirect_Api_GenerateTokenResponse|PHPUnit_Framework_MockObject_MockObject
15
+ */
16
+ protected $subject = null;
17
+
18
+ /**
19
+ * Sets up the unit test case
20
+ */
21
+ protected function setUp()
22
+ {
23
+ $this->className = Tigo_TigoMoney_Model_Payment_Redirect_Api_GenerateTokenResponse::class;
24
+
25
+ $this->subject = $this
26
+ ->getMockBuilder($this->className)
27
+ ->setMethods(null)
28
+ ->setConstructorArgs(array(new Varien_Object()))
29
+ ->getMock();
30
+
31
+ }
32
+
33
+ public function testAccessTokenGetterSetter()
34
+ {
35
+ $value = '393mas0932mam09maslk';
36
+ $this
37
+ ->subject
38
+ ->setAccessToken($value);
39
+ $this->assertEquals(
40
+ $value,
41
+ $this->subject->getAccessToken()
42
+ );
43
+ }
44
+
45
+ }
46
+
app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Model/Payment/Redirect/Api/RequestBuilderTest.php ADDED
@@ -0,0 +1,513 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Tigo_TigoMoney_Model_Payment_Redirect_Api_RequestBuilderTest
5
+ */
6
+ class Tigo_TigoMoney_Model_Payment_Redirect_Api_RequestBuilderTest extends EcomDev_PHPUnit_Test_Case
7
+ {
8
+
9
+ /**
10
+ * @var Tigo_TigoMoney_Model_Payment_Redirect_Api_AuthorizationRequest|PHPUnit_Framework_MockObject_MockObject
11
+ */
12
+ protected $authorizationRequest = null;
13
+
14
+ /**
15
+ * @var String
16
+ */
17
+ protected $className = null;
18
+
19
+ /**
20
+ * @var Tigo_TigoMoney_Helper_Data|PHPUnit_Framework_MockObject_MockObject
21
+ */
22
+ protected $dataHelper = null;
23
+
24
+ /**
25
+ * @var Tigo_TigoMoney_Model_Payment_Redirect_Api_GenerateTokenRequest|PHPUnit_Framework_MockObject_MockObject
26
+ */
27
+ protected $generateTokenRequest = null;
28
+
29
+ /**
30
+ * @var Mage_Sales_Model_Order|PHPUnit_Framework_MockObject_MockObject
31
+ */
32
+ protected $order = null;
33
+
34
+ /**
35
+ * @var Mage_Sales_Model_Order_Payment|PHPUnit_Framework_MockObject_MockObject
36
+ */
37
+ protected $payment = null;
38
+
39
+ /**
40
+ * @var Tigo_TigoMoney_Model_Payment_Redirect_Api_ReverseTransactionRequest|PHPUnit_Framework_MockObject_MockObject
41
+ */
42
+ protected $reverseTransactionRequest = null;
43
+
44
+ /**
45
+ * @var Tigo_TigoMoney_Model_Payment_Redirect_Api_RequestBuilder|PHPUnit_Framework_MockObject_MockObject
46
+ */
47
+ protected $subject = null;
48
+
49
+ /**
50
+ * @var Tigo_TigoMoney_Model_Payment_Redirect_Api_TransactionStatusRequest|PHPUnit_Framework_MockObject_MockObject
51
+ */
52
+ protected $transactionStatusRequest = null;
53
+
54
+ /**
55
+ * Sets up the unit test case
56
+ */
57
+ protected function setUp()
58
+ {
59
+ $this->className = Tigo_TigoMoney_Model_Payment_Redirect_Api_RequestBuilder::class;
60
+
61
+ $this->subject = $this
62
+ ->getMockBuilder($this->className)
63
+ ->setMethods(null)
64
+ ->getMock();
65
+
66
+ $this->authorizationRequest = $this->getModelMock(
67
+ 'tigo_tigomoney/payment_redirect_api_authorizationRequest',
68
+ array()
69
+ );
70
+
71
+ $this->authorizationRequest = $this
72
+ ->getMockBuilder(Tigo_TigoMoney_Model_Payment_Redirect_Api_AuthorizationRequest::class)
73
+ ->setMethods(null)
74
+ ->getMock();
75
+ $this->replaceByMock(
76
+ 'model',
77
+ 'tigo_tigomoney/payment_redirect_api_authorizationRequest',
78
+ $this->authorizationRequest
79
+ );
80
+
81
+ $this->generateTokenRequest = $this
82
+ ->getMockBuilder(Tigo_TigoMoney_Model_Payment_Redirect_Api_GenerateTokenRequest::class)
83
+ ->setMethods(null)
84
+ ->getMock();
85
+ $this->replaceByMock(
86
+ 'model',
87
+ 'tigo_tigomoney/payment_redirect_api_generateTokenRequest',
88
+ $this->generateTokenRequest
89
+ );
90
+
91
+ $this->reverseTransactionRequest = $this
92
+ ->getMockBuilder(Tigo_TigoMoney_Model_Payment_Redirect_Api_ReverseTransactionRequest::class)
93
+ ->setMethods(null)
94
+ ->getMock();
95
+ $this->replaceByMock(
96
+ 'model',
97
+ 'tigo_tigomoney/payment_redirect_api_reverseTransactionRequest',
98
+ $this->reverseTransactionRequest
99
+ );
100
+
101
+ $this->transactionStatusRequest = $this
102
+ ->getMockBuilder(Tigo_TigoMoney_Model_Payment_Redirect_Api_TransactionStatusRequest::class)
103
+ ->setMethods(null)
104
+ ->getMock();
105
+ $this->replaceByMock(
106
+ 'model',
107
+ 'tigo_tigomoney/payment_redirect_api_transactionStatusRequest',
108
+ $this->transactionStatusRequest
109
+ );
110
+
111
+ $this->payment = $this
112
+ ->getMockBuilder(Mage_Sales_Model_Order_Payment::class)
113
+ ->setMethods(null)
114
+ ->getMock();
115
+ $this->replaceByMock(
116
+ 'model',
117
+ 'sales/order_payment',
118
+ $this->payment
119
+ );
120
+
121
+ $this->order = $this
122
+ ->getMockBuilder(Mage_Sales_Model_Order::class)
123
+ ->setMethods(array('getPayment'))#, 'getCustomerFirstname', 'getCustomerLastname', 'getCustomerEmail', 'getBaseGrandTotal', 'getIncrementId'))
124
+ ->getMock();
125
+ $this
126
+ ->order
127
+ ->expects($this->any())
128
+ ->method('getPayment')
129
+ ->will($this->returnValue($this->payment));
130
+ $this->replaceByMock(
131
+ 'model',
132
+ 'sales/order',
133
+ $this->order
134
+ );
135
+
136
+ $this->dataHelper = $this->getHelperMock(
137
+ 'tigo_tigomoney/data',
138
+ array()
139
+ );
140
+ $this->replaceByMock(
141
+ 'helper',
142
+ 'tigo_tigomoney/data',
143
+ $this->dataHelper
144
+ );
145
+ }
146
+
147
+ /**
148
+ * @loadFixture default
149
+ */
150
+ public function testBuildAuthorizationRequest()
151
+ {
152
+ /** @var Mage_Core_Model_Url $url */
153
+ $url = Mage::getModel('core/url');
154
+
155
+ $accessToken = 'kmsdmsdoi234';
156
+ $masterMerchantAccount = 'zaq1xsw2cde3';
157
+ $masterMerchantPin = '6464646737373';
158
+ $masterMerchantId = '98098098';
159
+ $merchantReference = 'Amazon';
160
+ $merchantCurrencyCode = Tigo_TigoMoney_Model_Payment_Redirect_Api_AuthorizationRequest::CURRENCY_CODE_USD;
161
+ $merchantFee = 0;
162
+ $subscriberAccount = '234234234';
163
+ $subscriberCountry = Tigo_TigoMoney_Model_Payment_Redirect_Api_AuthorizationRequest::COUNTRY_CODE;
164
+ $subscriberCountryCode = Tigo_TigoMoney_Model_Payment_Redirect_Api_AuthorizationRequest::COUNTRY_DIAL_CODE;
165
+ $subscriberFirstName = 'John';
166
+ $subscriberLastName = 'Doe';
167
+ $subscriberEmail = 'johndoe@hotmail.com';
168
+ $localPaymentAmount = 123.32;
169
+ $localPaymentCurrencyCode = Tigo_TigoMoney_Model_Payment_Redirect_Api_AuthorizationRequest::CURRENCY_CODE_USD;
170
+ $originPaymentAmount = $localPaymentAmount;
171
+ $originPaymentCurrencyCode = Tigo_TigoMoney_Model_Payment_Redirect_Api_AuthorizationRequest::CURRENCY_CODE_USD;
172
+ $originPaymentTax = 0;
173
+ $originPaymentFee = 0;
174
+ $redirectUri = $url->getUrl('tigomoney/return');
175
+ $callbackUri = $url->getUrl('tigomoney/sync');
176
+ $language = Tigo_TigoMoney_Model_Payment_Redirect_Api_AuthorizationRequest::LANGUAGE_CODE_SPANISH;
177
+ $merchantTransactionId = '10000234';
178
+ $terminalId = Tigo_TigoMoney_Model_Payment_Redirect_Api_AuthorizationRequest::TERMINAL_ID;
179
+ $exchangeRate = 1;
180
+
181
+ $this
182
+ ->payment
183
+ ->setAdditionalInformation(Tigo_TigoMoney_Model_Payment_Redirect::ADDITIONAL_INFO_KEY_PHONE_NUMBER, $subscriberAccount);
184
+
185
+ $this
186
+ ->order
187
+ ->setCustomerFirstname($subscriberFirstName);
188
+
189
+ $this
190
+ ->order
191
+ ->setCustomerLastname($subscriberLastName);
192
+
193
+ $this
194
+ ->order
195
+ ->setCustomerEmail($subscriberEmail);
196
+
197
+ $this
198
+ ->order
199
+ ->setBaseGrandTotal($localPaymentAmount);
200
+
201
+ $this
202
+ ->order
203
+ ->setIncrementId($merchantTransactionId);
204
+
205
+ $request = $this->subject->buildAuthorizationRequest(
206
+ $accessToken,
207
+ $this->order
208
+ );
209
+
210
+ $this->assertEquals(
211
+ $accessToken,
212
+ $request->getAccessToken()
213
+ );
214
+
215
+ $this->assertEquals(
216
+ $masterMerchantAccount,
217
+ $request->getMasterMerchantAccount()
218
+ );
219
+
220
+ $this->assertEquals(
221
+ $masterMerchantPin,
222
+ $request->getMasterMerchantPin()
223
+ );
224
+
225
+ $this->assertEquals(
226
+ $masterMerchantId,
227
+ $request->getMasterMerchantId()
228
+ );
229
+
230
+ $this->assertEquals(
231
+ $merchantReference,
232
+ $request->getMerchantReference()
233
+ );
234
+
235
+ $this->assertEquals(
236
+ $merchantCurrencyCode,
237
+ $request->getMerchantCurrencyCode()
238
+ );
239
+
240
+ $this->assertEquals(
241
+ $merchantFee,
242
+ $request->getMerchantFee()
243
+ );
244
+
245
+ $this->assertEquals(
246
+ $subscriberAccount,
247
+ $request->getSubscriberAccount()
248
+ );
249
+
250
+ $this->assertEquals(
251
+ $subscriberCountry,
252
+ $request->getSubscriberCountry()
253
+ );
254
+
255
+ $this->assertEquals(
256
+ $subscriberCountryCode,
257
+ $request->getSubscriberCountryCode()
258
+ );
259
+
260
+ $this->assertEquals(
261
+ $subscriberFirstName,
262
+ $request->getSubscriberFirstName()
263
+ );
264
+
265
+ $this->assertEquals(
266
+ $subscriberLastName,
267
+ $request->getSubscriberLastName()
268
+ );
269
+
270
+ $this->assertEquals(
271
+ $subscriberEmail,
272
+ $request->getSubscriberEmail()
273
+ );
274
+
275
+ $this->assertEquals(
276
+ $localPaymentAmount,
277
+ $request->getLocalPaymentAmount()
278
+ );
279
+
280
+ $this->assertEquals(
281
+ $localPaymentCurrencyCode,
282
+ $request->getLocalPaymentCurrencyCode()
283
+ );
284
+
285
+ $this->assertEquals(
286
+ $originPaymentAmount,
287
+ $request->getOriginPaymentAmount()
288
+ );
289
+
290
+ $this->assertEquals(
291
+ $originPaymentCurrencyCode,
292
+ $request->getOriginPaymentCurrencyCode()
293
+ );
294
+
295
+ $this->assertEquals(
296
+ $originPaymentTax,
297
+ $request->getOriginPaymentTax()
298
+ );
299
+
300
+ $this->assertEquals(
301
+ $originPaymentFee,
302
+ $request->getOriginPaymentFee()
303
+ );
304
+
305
+ $this->assertEquals(
306
+ $redirectUri,
307
+ $request->getRedirectUri()
308
+ );
309
+
310
+ $this->assertEquals(
311
+ $callbackUri,
312
+ $request->getCallbackUri()
313
+ );
314
+
315
+ $this->assertEquals(
316
+ $language,
317
+ $request->getLanguage()
318
+ );
319
+
320
+ $this->assertEquals(
321
+ $merchantTransactionId,
322
+ $request->getMerchantTransactionId()
323
+ );
324
+
325
+ $this->assertEquals(
326
+ $terminalId,
327
+ $request->getTerminalId()
328
+ );
329
+
330
+ $this->assertEquals(
331
+ $exchangeRate,
332
+ $request->getExchangeRate()
333
+ );
334
+
335
+ $this->assertEquals(
336
+ $this->authorizationRequest,
337
+ $request
338
+ );
339
+ }
340
+
341
+ /**
342
+ * @loadFixture default
343
+ */
344
+ public function testGenerateAccessTokenRequest()
345
+ {
346
+ $clientId = '123';
347
+ $clientSecret = 'asdf123fdsa';
348
+
349
+ $request = $this->subject->buildGenerateAccessTokenRequest();
350
+
351
+ $this->assertEquals(
352
+ $this->generateTokenRequest,
353
+ $request
354
+ );
355
+
356
+ $this->assertEquals(
357
+ $clientId,
358
+ $request->getClientId()
359
+ );
360
+
361
+ $this->assertEquals(
362
+ $clientSecret,
363
+ $request->getClientSecret()
364
+ );
365
+ }
366
+
367
+ /**
368
+ * @loadFixture default
369
+ */
370
+ public function testBuildReverseTokenRequest()
371
+ {
372
+ $accessToken = 'sdlkfms3234';
373
+ $masterMerchantAccount = 'zaq1xsw2cde3';
374
+ $masterMerchantPin = '6464646737373';
375
+ $masterMerchantId = '98098098';
376
+ $mfsTransactionId = '234234234';
377
+ $incrementId = '100000234';
378
+ $subscriberAccount = '234234234';
379
+ $localPaymentAmount = 123.32;
380
+ $localPaymentCurrencyCode = Tigo_TigoMoney_Model_Payment_Redirect_Api_AuthorizationRequest::CURRENCY_CODE_USD;
381
+ $country = Tigo_TigoMoney_Model_Payment_Redirect_Api_AuthorizationRequest::COUNTRY_CODE;
382
+
383
+ $this
384
+ ->order
385
+ ->setBaseGrandTotal($localPaymentAmount);
386
+
387
+ $this
388
+ ->order
389
+ ->setIncrementId($incrementId);
390
+
391
+ $this
392
+ ->payment
393
+ ->setAdditionalInformation(
394
+ Tigo_TigoMoney_Model_Payment_Redirect::ADDITIONAL_INFO_KEY_PHONE_NUMBER,
395
+ $subscriberAccount
396
+ );
397
+
398
+ $this
399
+ ->payment
400
+ ->setAdditionalInformation(
401
+ Tigo_TigoMoney_Model_Payment_Redirect::ADDITIONAL_INFO_KEY_MFS_TRANSACTION_ID,
402
+ $mfsTransactionId
403
+ );
404
+
405
+ $request = $this->subject->buildReverseTransactionRequest(
406
+ $accessToken,
407
+ $this->order
408
+ );
409
+
410
+ $this->assertEquals(
411
+ $this->reverseTransactionRequest,
412
+ $request
413
+ );
414
+
415
+ $this->assertEquals(
416
+ $accessToken,
417
+ $request->getAccessToken()
418
+ );
419
+
420
+ $this->assertEquals(
421
+ $masterMerchantAccount,
422
+ $request->getMasterAccountAccount()
423
+ );
424
+
425
+ $this->assertEquals(
426
+ $masterMerchantPin,
427
+ $request->getMasterAccountPin()
428
+ );
429
+
430
+ $this->assertEquals(
431
+ $masterMerchantId,
432
+ $request->getMasterAccountId()
433
+ );
434
+
435
+ $this->assertEquals(
436
+ $subscriberAccount,
437
+ $request->getSubscriberAccount()
438
+ );
439
+
440
+ $this->assertEquals(
441
+ $localPaymentCurrencyCode,
442
+ $request->getLocalPaymentCurrencyCode()
443
+ );
444
+
445
+ $this->assertEquals(
446
+ $country,
447
+ $request->getCountry()
448
+ );
449
+
450
+ $this->assertEquals(
451
+ $localPaymentAmount,
452
+ $request->getLocalPaymentAmount()
453
+ );
454
+
455
+ $this->assertEquals(
456
+ $incrementId,
457
+ $request->getMerchantTransactionId()
458
+ );
459
+
460
+ $this->assertEquals(
461
+ $mfsTransactionId,
462
+ $request->getMfsTransactionId()
463
+ );
464
+ }
465
+
466
+
467
+
468
+ /**
469
+ * @loadFixture default
470
+ */
471
+ public function testBuildTransactionStatusRequest()
472
+ {
473
+ $orderIncrementId = '10000023';
474
+ $accessToken = 'asdf123fdsa';
475
+ $masterMerchantId = '98098098';
476
+ $country = Tigo_TigoMoney_Model_Payment_Redirect_Api_TransactionStatusRequest::COUNTRY_CODE_EL_SALVADOR;
477
+
478
+ $this
479
+ ->order
480
+ ->setIncrementId($orderIncrementId);
481
+
482
+ $request = $this->subject->buildTransactionStatusRequest(
483
+ $accessToken,
484
+ $this->order
485
+ );
486
+
487
+ $this->assertEquals(
488
+ $this->transactionStatusRequest,
489
+ $request
490
+ );
491
+
492
+ $this->assertEquals(
493
+ $accessToken,
494
+ $request->getAccessToken()
495
+ );
496
+
497
+ $this->assertEquals(
498
+ $orderIncrementId,
499
+ $request->getMerchantTransactionId()
500
+ );
501
+
502
+ $this->assertEquals(
503
+ $country,
504
+ $request->getCountry()
505
+ );
506
+
507
+ $this->assertEquals(
508
+ $masterMerchantId,
509
+ $request->getMasterMerchantId()
510
+ );
511
+ }
512
+ }
513
+
app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Model/Payment/Redirect/Api/RequestBuilderTest/fixtures/default.yaml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ config:
2
+ default/web/seo/use_rewrites: 1
3
+ default/payment/tigo_tigomoney/client_id: 123
4
+ default/payment/tigo_tigomoney/client_secret: asdf123fdsa
5
+ default/payment/tigo_tigomoney/merchant_account: zaq1xsw2cde3
6
+ default/payment/tigo_tigomoney/merchant_id: 98098098
7
+ default/payment/tigo_tigomoney/merchant_pin: 6464646737373
8
+ default/payment/tigo_tigomoney/merchant_reference: Amazon
9
+ default/payment/tigo_tigomoney/test_mode: 1
10
+ default/payment/tigo_tigomoney/debug_mode: 1
app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Model/Payment/Redirect/Api/ReverseTransactionRequestTest.php ADDED
@@ -0,0 +1,336 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Tigo_TigoMoney_Model_Payment_Redirect_Api_ReverseTransactionRequestTest
5
+ */
6
+ class Tigo_TigoMoney_Model_Payment_Redirect_Api_ReverseTransactionRequestTest extends EcomDev_PHPUnit_Test_Case
7
+ {
8
+ /**
9
+ * @var String
10
+ */
11
+ protected $className = null;
12
+
13
+ /**
14
+ * @var Tigo_TigoMoney_Model_Payment_Redirect_Api_ReverseTransactionRequest|PHPUnit_Framework_MockObject_MockObject
15
+ */
16
+ protected $subject = null;
17
+
18
+ /**
19
+ * Sets up the unit test case
20
+ */
21
+ protected function setUp()
22
+ {
23
+ $this->className = Tigo_TigoMoney_Model_Payment_Redirect_Api_ReverseTransactionRequest::class;
24
+
25
+ $this->subject = $this
26
+ ->getMockBuilder($this->className)
27
+ ->setMethods(null)
28
+ ->getMock();
29
+
30
+ }
31
+
32
+ public function testAccessTokenGetterSetter()
33
+ {
34
+ $value = 'asdff9kokasdf';
35
+ $this
36
+ ->subject
37
+ ->setAccessToken($value);
38
+ $this->assertEquals(
39
+ $value,
40
+ $this->subject->getAccessToken()
41
+ );
42
+ }
43
+
44
+ public function testCountryGetterSetter()
45
+ {
46
+ $value = Tigo_TigoMoney_Model_Payment_Redirect_Api_ReverseTransactionRequest::COUNTRY_CODE_EL_SALVADOR;
47
+ $this
48
+ ->subject
49
+ ->setCountry($value);
50
+ $this->assertEquals(
51
+ $value,
52
+ $this->subject->getCountry()
53
+ );
54
+ }
55
+
56
+ public function testLocalPaymentAmountGetterSetter()
57
+ {
58
+ $value = 108.39;
59
+ $this
60
+ ->subject
61
+ ->setLocalPaymentAmount($value);
62
+ $this->assertEquals(
63
+ $value,
64
+ $this->subject->getLocalPaymentAmount()
65
+ );
66
+ }
67
+
68
+ public function testLocalPaymentCurrencyCodeGetterSetter()
69
+ {
70
+ $value = Tigo_TigoMoney_Model_Payment_Redirect_Api_ReverseTransactionRequest::CURRENCY_CODE_USD;
71
+ $this
72
+ ->subject
73
+ ->setLocalPaymentCurrencyCode($value);
74
+ $this->assertEquals(
75
+ $value,
76
+ $this->subject->getLocalPaymentCurrencyCode()
77
+ );
78
+ }
79
+
80
+ public function testMasterAccountAccountGetterSetter()
81
+ {
82
+ $value = '938298329830283';
83
+ $this
84
+ ->subject
85
+ ->setMasterAccountAccount($value);
86
+ $this->assertEquals(
87
+ $value,
88
+ $this->subject->getMasterAccountAccount()
89
+ );
90
+ }
91
+
92
+ public function testMasterAccountIdGetterSetter()
93
+ {
94
+ $value = '3939393';
95
+ $this
96
+ ->subject
97
+ ->setMasterAccountId($value);
98
+ $this->assertEquals(
99
+ $value,
100
+ $this->subject->getMasterAccountId()
101
+ );
102
+ }
103
+
104
+ public function testMasterAccountPinGetterSetter()
105
+ {
106
+ $value = 'mcosd09msd8fms98n';
107
+ $this
108
+ ->subject
109
+ ->setMasterAccountPin($value);
110
+ $this->assertEquals(
111
+ $value,
112
+ $this->subject->getMasterAccountPin()
113
+ );
114
+ }
115
+
116
+ public function testMerchantTransactionIdGetterSetter()
117
+ {
118
+ $value = '10009839';
119
+ $this
120
+ ->subject
121
+ ->setMerchantTransactionId($value);
122
+ $this->assertEquals(
123
+ $value,
124
+ $this->subject->getMerchantTransactionId()
125
+ );
126
+ }
127
+
128
+ public function testMfsTransactionIdGetterSetter()
129
+ {
130
+ $value = '392282089329832982';
131
+ $this
132
+ ->subject
133
+ ->setMfsTransactionId($value);
134
+ $this->assertEquals(
135
+ $value,
136
+ $this->subject->getMfsTransactionId()
137
+ );
138
+ }
139
+
140
+ public function testSubscriberAccountGetterSetter()
141
+ {
142
+ $value = '50792839283';
143
+ $this
144
+ ->subject
145
+ ->setSubscriberAccount($value);
146
+ $this->assertEquals(
147
+ $value,
148
+ $this->subject->getSubscriberAccount()
149
+ );
150
+ }
151
+
152
+ public function testEndpointPathGetter()
153
+ {
154
+ $country = Tigo_TigoMoney_Model_Payment_Redirect_Api_ReverseTransactionRequest::COUNTRY_CODE_EL_SALVADOR;
155
+ $mfsTransactionId = '39398293823';
156
+ $merchantTransactionId = '3929382392vdfvdfs09093';
157
+ $endpoint = Tigo_TigoMoney_Model_Payment_Redirect_Api_ReverseTransactionRequest::ENDPOINT_PATH . $country
158
+ . '/' . $mfsTransactionId . '/' . $merchantTransactionId;
159
+
160
+ $this->subject->setCountry($country);
161
+ $this->subject->setMfsTransactionId($mfsTransactionId);
162
+ $this->subject->setMerchantTransactionId($merchantTransactionId);
163
+
164
+ $this->assertEquals(
165
+ $endpoint,
166
+ $this->subject->getEndpointPath()
167
+ );
168
+ }
169
+
170
+ public function testHeaderGetter()
171
+ {
172
+ $accessToken = 'lmflsdkmf9mp';
173
+ $this->subject->setAccessToken($accessToken);
174
+ $this->assertEquals(
175
+ array(
176
+ 'Content-Type' => 'application/json',
177
+ 'Authorization' => 'Bearer ' . $accessToken
178
+ ),
179
+ $this->subject->getHeaders()
180
+ );
181
+ }
182
+
183
+ public function testMethodGetter()
184
+ {
185
+ $this->assertEquals(
186
+ Varien_Http_Client::DELETE,
187
+ $this->subject->getMethod()
188
+ );
189
+ }
190
+
191
+ public function testValidateDataProvider()
192
+ {
193
+ return array(
194
+ array('92imoim92', 'SLV', '128391823019823', '100000932', '11ms09202039', '39230293asdf', 'asdf234234asdf', '938992892', 2093.32, 'USD', true),
195
+ array(null, 'SLV', '128391823019823', '100000932', '11ms09202039', '39230293asdf', 'asdf234234asdf', '938992892', 2093.32, 'USD', false),
196
+ array('92imoim92', null, '128391823019823', '100000932', '11ms09202039', '39230293asdf', 'asdf234234asdf', '938992892', 2093.32, 'USD', false),
197
+ array('92imoim92', 'SLV', null, '100000932', '11ms09202039', '39230293asdf', 'asdf234234asdf', '938992892', 2093.32, 'USD', false),
198
+ array('92imoim92', 'SLV', '128391823019823', null, '11ms09202039', '39230293asdf', 'asdf234234asdf', '938992892', 2093.32, 'USD', false),
199
+ array('92imoim92', 'SLV', '128391823019823', '100000932', null, '39230293asdf', 'asdf234234asdf', '938992892', 2093.32, 'USD', false),
200
+ array('92imoim92', 'SLV', '128391823019823', '100000932', '11ms09202039', null, 'asdf234234asdf', '938992892', 2093.32, 'USD', true),
201
+ array('92imoim92', 'SLV', '128391823019823', '100000932', '11ms09202039', '39230293asdf', null, '938992892', 2093.32, 'USD', false),
202
+ array('92imoim92', 'SLV', '128391823019823', '100000932', '11ms09202039', '39230293asdf', 'asdf234234asdf', null, 2093.32, 'USD', false),
203
+ array('92imoim92', 'SLV', '128391823019823', '100000932', '11ms09202039', '39230293asdf', 'asdf234234asdf', '938992892', null, 'USD', false),
204
+ array('92imoim92', 'SLV', '128391823019823', '100000932', '11ms09202039', '39230293asdf', 'asdf234234asdf', '938992892', 2093.32, null, false)
205
+ );
206
+ }
207
+
208
+ /**
209
+ * @param $accessToken
210
+ * @param $country
211
+ * @param $mfsTransactionId
212
+ * @param $merchantTransactionId
213
+ * @param $masterAccountAccount
214
+ * @param $masterAccountId
215
+ * @param $masterAccountPin
216
+ * @param $subscriberAccount
217
+ * @param $localPaymentAmount
218
+ * @param $localPaymentCurrencyCode
219
+ * @param $result
220
+ * @dataProvider testValidateDataProvider
221
+ */
222
+ public function testValidate(
223
+ $accessToken,
224
+ $country,
225
+ $mfsTransactionId,
226
+ $merchantTransactionId,
227
+ $masterAccountAccount,
228
+ $masterAccountId,
229
+ $masterAccountPin,
230
+ $subscriberAccount,
231
+ $localPaymentAmount,
232
+ $localPaymentCurrencyCode,
233
+ $result
234
+ ) {
235
+ $this
236
+ ->subject
237
+ ->setAccessToken($accessToken);
238
+ $this
239
+ ->subject
240
+ ->setCountry($country);
241
+ $this
242
+ ->subject
243
+ ->setMfsTransactionId($mfsTransactionId);
244
+ $this
245
+ ->subject
246
+ ->setMerchantTransactionId($merchantTransactionId);
247
+ $this
248
+ ->subject
249
+ ->setMasterAccountAccount($masterAccountAccount);
250
+ $this
251
+ ->subject
252
+ ->setMasterAccountId($masterAccountId);
253
+ $this
254
+ ->subject
255
+ ->setMasterAccountPin($masterAccountPin);
256
+ $this
257
+ ->subject
258
+ ->setSubscriberAccount($subscriberAccount);
259
+ $this
260
+ ->subject
261
+ ->setLocalPaymentAmount($localPaymentAmount);
262
+ $this
263
+ ->subject
264
+ ->setLocalPaymentCurrencyCode($localPaymentCurrencyCode);
265
+ $this->assertEquals(
266
+ $result,
267
+ $this->subject->validate()
268
+ );
269
+ }
270
+ public function testGetBodyDataProvider()
271
+ {
272
+ return array(
273
+ array('384398', '29382983', '23982938', '92839823', 38392.3900, 'USD'),
274
+ );
275
+ }
276
+
277
+ /**
278
+ * @param $masterAccountAccount
279
+ * @param $masterAccountId
280
+ * @param $masterAccountPin
281
+ * @param $subscriberAccount
282
+ * @param $localPaymentAmount
283
+ * @param $localPaymentCurrencyCode
284
+ * @dataProvider testGetBodyDataProvider
285
+ */
286
+ public function testGetBody(
287
+ $masterAccountAccount,
288
+ $masterAccountId,
289
+ $masterAccountPin,
290
+ $subscriberAccount,
291
+ $localPaymentAmount,
292
+ $localPaymentCurrencyCode
293
+ ) {
294
+ $this->subject->setMasterAccountAccount($masterAccountAccount);
295
+ $this->subject->setMasterAccountId($masterAccountId);
296
+ $this->subject->setMasterAccountPin($masterAccountPin);
297
+ $this->subject->setSubscriberAccount($subscriberAccount);
298
+ $this->subject->setLocalPaymentAmount($localPaymentAmount);
299
+ $this->subject->setLocalPaymentCurrencyCode($localPaymentCurrencyCode);
300
+
301
+ $requestBody = $this->subject->getBody();
302
+
303
+ $requestBodyJsonArr = json_decode($requestBody, true);
304
+
305
+ $this->assertEquals(
306
+ $requestBodyJsonArr['MasterAccount']['account'],
307
+ $masterAccountAccount
308
+ );
309
+
310
+ $this->assertEquals(
311
+ $requestBodyJsonArr['MasterAccount']['id'],
312
+ $masterAccountId
313
+ );
314
+
315
+ $this->assertEquals(
316
+ $requestBodyJsonArr['MasterAccount']['pin'],
317
+ $masterAccountPin
318
+ );
319
+
320
+ $this->assertEquals(
321
+ $requestBodyJsonArr['subscriberAccount'],
322
+ $subscriberAccount
323
+ );
324
+
325
+ $this->assertEquals(
326
+ $requestBodyJsonArr['LocalPayment']['amount'],
327
+ number_format($localPaymentAmount, 2, '.', '')
328
+ );
329
+
330
+ $this->assertEquals(
331
+ $requestBodyJsonArr['LocalPayment']['currencyCode'],
332
+ $localPaymentCurrencyCode
333
+ );
334
+ }
335
+ }
336
+
app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Model/Payment/Redirect/Api/ReverseTransactionResponseTest.php ADDED
@@ -0,0 +1,154 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Tigo_TigoMoney_Model_Payment_Redirect_Api_ReverseTransactionResponseTest
5
+ */
6
+ class Tigo_TigoMoney_Model_Payment_Redirect_Api_ReverseTransactionResponseTest extends EcomDev_PHPUnit_Test_Case
7
+ {
8
+ /**
9
+ * @var String
10
+ */
11
+ protected $className = null;
12
+
13
+ /**
14
+ * @var Tigo_TigoMoney_Model_Payment_Redirect_Api_ReverseTransactionResponse|PHPUnit_Framework_MockObject_MockObject
15
+ */
16
+ protected $subject = null;
17
+
18
+ /**
19
+ * Sets up the unit test case
20
+ */
21
+ protected function setUp()
22
+ {
23
+ $this->className = Tigo_TigoMoney_Model_Payment_Redirect_Api_ReverseTransactionResponse::class;
24
+
25
+ $this->subject = $this
26
+ ->getMockBuilder($this->className)
27
+ ->setMethods(null)
28
+ ->setConstructorArgs(array(new Varien_Object()))
29
+ ->getMock();
30
+
31
+ }
32
+
33
+ public function testErrorGetterSetter()
34
+ {
35
+ $value = '3938';
36
+ $this
37
+ ->subject
38
+ ->setError($value);
39
+ $this->assertEquals(
40
+ $value,
41
+ $this->subject->getError()
42
+ );
43
+ }
44
+
45
+ public function testErrorDescriptionGetterSetter()
46
+ {
47
+ $value = '3938';
48
+ $this
49
+ ->subject
50
+ ->setErrorDescription($value);
51
+ $this->assertEquals(
52
+ $value,
53
+ $this->subject->getErrorDescription()
54
+ );
55
+ }
56
+
57
+ public function testErrorTypeGetterSetter()
58
+ {
59
+ $value = 'warning';
60
+ $this
61
+ ->subject
62
+ ->setErrorType($value);
63
+ $this->assertEquals(
64
+ $value,
65
+ $this->subject->getErrorType()
66
+ );
67
+ }
68
+
69
+ public function testStatusGetterSetter()
70
+ {
71
+ $value = 'success';
72
+ $this
73
+ ->subject
74
+ ->setStatus($value);
75
+ $this->assertEquals(
76
+ $value,
77
+ $this->subject->getStatus()
78
+ );
79
+ }
80
+
81
+ public function testTransactionCorrelationIdGetterSetter()
82
+ {
83
+ $value = '02390293';
84
+ $this
85
+ ->subject
86
+ ->setTransactionCorrelationId($value);
87
+ $this->assertEquals(
88
+ $value,
89
+ $this->subject->getTransactionCorrelationId()
90
+ );
91
+ }
92
+
93
+ public function testTransactionMerchantTransactionIdGetterSetter()
94
+ {
95
+ $value = '1000023423';
96
+ $this
97
+ ->subject
98
+ ->setTransactionMerchantTransactionId($value);
99
+ $this->assertEquals(
100
+ $value,
101
+ $this->subject->getTransactionMerchantTransactionId()
102
+ );
103
+ }
104
+
105
+ public function testTransactionMessageGetterSetter()
106
+ {
107
+ $value = 'Transaction Refunded';
108
+ $this
109
+ ->subject
110
+ ->setTransactionMessage($value);
111
+ $this->assertEquals(
112
+ $value,
113
+ $this->subject->getTransactionMessage()
114
+ );
115
+ }
116
+
117
+ public function testTransactionMfsTransactionIdGetterSetter()
118
+ {
119
+ $value = '0209283029834';
120
+ $this
121
+ ->subject
122
+ ->setTransactionMfsTransactionId($value);
123
+ $this->assertEquals(
124
+ $value,
125
+ $this->subject->getTransactionMfsTransactionId()
126
+ );
127
+ }
128
+
129
+ public function testTransactionMfsReverseTransactionIdGetterSetter()
130
+ {
131
+ $value = '020928302983434343';
132
+ $this
133
+ ->subject
134
+ ->setTransactionMfsReverseTransactionId($value);
135
+ $this->assertEquals(
136
+ $value,
137
+ $this->subject->getTransactionMfsReverseTransactionId()
138
+ );
139
+ }
140
+
141
+ public function testTransactionStatusGetterSetter()
142
+ {
143
+ $value = 'success';
144
+ $this
145
+ ->subject
146
+ ->setTransactionStatus($value);
147
+ $this->assertEquals(
148
+ $value,
149
+ $this->subject->getTransactionStatus()
150
+ );
151
+ }
152
+
153
+ }
154
+
app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Model/Payment/Redirect/Api/TransactionStatusRequestTest.php ADDED
@@ -0,0 +1,175 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Tigo_TigoMoney_Model_Payment_Redirect_Api_TransactionStatusRequestTest
5
+ */
6
+ class Tigo_TigoMoney_Model_Payment_Redirect_Api_TransactionStatusRequestTest extends EcomDev_PHPUnit_Test_Case
7
+ {
8
+ /**
9
+ * @var String
10
+ */
11
+ protected $className = null;
12
+
13
+ /**
14
+ * @var Tigo_TigoMoney_Model_Payment_Redirect_Api_TransactionStatusRequest|PHPUnit_Framework_MockObject_MockObject
15
+ */
16
+ protected $subject = null;
17
+
18
+ /**
19
+ * Sets up the unit test case
20
+ */
21
+ protected function setUp()
22
+ {
23
+ $this->className = Tigo_TigoMoney_Model_Payment_Redirect_Api_TransactionStatusRequest::class;
24
+
25
+ $this->subject = $this
26
+ ->getMockBuilder($this->className)
27
+ ->setMethods(null)
28
+ ->getMock();
29
+
30
+ }
31
+
32
+ public function testAccessTokenGetterSetter()
33
+ {
34
+ $value = 'ASDmfiemasd39432';
35
+ $this
36
+ ->subject
37
+ ->setAccessToken($value);
38
+ $this->assertEquals(
39
+ $value,
40
+ $this->subject->getAccessToken()
41
+ );
42
+ }
43
+
44
+ public function testCountryGetterSetter()
45
+ {
46
+ $value = Tigo_TigoMoney_Model_Payment_Redirect_Api_TransactionStatusRequest::COUNTRY_CODE_EL_SALVADOR;
47
+ $this
48
+ ->subject
49
+ ->setCountry($value);
50
+ $this->assertEquals(
51
+ $value,
52
+ $this->subject->getCountry()
53
+ );
54
+ }
55
+
56
+ public function testMasterMerchantIdGetterSetter()
57
+ {
58
+ $value = '1238712938712';
59
+ $this
60
+ ->subject
61
+ ->setMasterMerchantId($value);
62
+ $this->assertEquals(
63
+ $value,
64
+ $this->subject->getMasterMerchantId()
65
+ );
66
+ }
67
+
68
+ public function testMerchantTransactionIdGetterSetter()
69
+ {
70
+ $value = '100009823';
71
+ $this
72
+ ->subject
73
+ ->setMerchantTransactionId($value);
74
+ $this->assertEquals(
75
+ $value,
76
+ $this->subject->getMerchantTransactionId()
77
+ );
78
+ }
79
+
80
+
81
+ public function testEndpointPathGetter()
82
+ {
83
+ $country = Tigo_TigoMoney_Model_Payment_Redirect_Api_TransactionStatusRequest::COUNTRY_CODE_EL_SALVADOR;
84
+ $masterMerchantId = '39398293823';
85
+ $merchantTransactionId = '3929382392vdfvdfs09093';
86
+ $endpoint = Tigo_TigoMoney_Model_Payment_Redirect_Api_TransactionStatusRequest::ENDPOINT_PATH . $country
87
+ . '/' . $masterMerchantId . '/' . $merchantTransactionId;
88
+
89
+ $this->subject->setCountry($country);
90
+ $this->subject->setMasterMerchantId($masterMerchantId);
91
+ $this->subject->setMerchantTransactionId($merchantTransactionId);
92
+
93
+ $this->assertEquals(
94
+ $endpoint,
95
+ $this->subject->getEndpointPath()
96
+ );
97
+ }
98
+
99
+ public function testHeaderGetter()
100
+ {
101
+ $accessToken = 'lmflsdkmf9mp';
102
+ $this->subject->setAccessToken($accessToken);
103
+ $this->assertEquals(
104
+ array(
105
+ 'Authorization' => 'Bearer ' . $accessToken
106
+ ),
107
+ $this->subject->getHeaders()
108
+ );
109
+ }
110
+
111
+ public function testMethodGetter()
112
+ {
113
+ $this->assertEquals(
114
+ Varien_Http_Client::GET,
115
+ $this->subject->getMethod()
116
+ );
117
+ }
118
+
119
+ public function testValidateDataProvider()
120
+ {
121
+ return array(
122
+ array('oieomosadoivdvd98', Tigo_TigoMoney_Model_Payment_Redirect_Api_TransactionStatusRequest::COUNTRY_CODE_EL_SALVADOR, '1234324234', '10000023', true),
123
+ array(null, Tigo_TigoMoney_Model_Payment_Redirect_Api_TransactionStatusRequest::COUNTRY_CODE_EL_SALVADOR, '1234324234', '10000023', false),
124
+ array('oieomosadoivdvd98', null, '1234324234', '10000023', false),
125
+ array('oieomosadoivdvd98', Tigo_TigoMoney_Model_Payment_Redirect_Api_TransactionStatusRequest::COUNTRY_CODE_EL_SALVADOR, null, '10000023', false),
126
+ array('oieomosadoivdvd98', Tigo_TigoMoney_Model_Payment_Redirect_Api_TransactionStatusRequest::COUNTRY_CODE_EL_SALVADOR, '1234324234', null, false),
127
+ );
128
+ }
129
+
130
+ /**
131
+ * @param $accessToken
132
+ * @param $country
133
+ * @param $merchantId
134
+ * @param $transactionId
135
+ * @param $result
136
+ * @dataProvider testValidateDataProvider
137
+ */
138
+ public function testValidate(
139
+ $accessToken,
140
+ $country,
141
+ $merchantId,
142
+ $transactionId,
143
+ $result
144
+ ) {
145
+ $this
146
+ ->subject
147
+ ->setAccessToken($accessToken);
148
+ $this
149
+ ->subject
150
+ ->setCountry($country);
151
+ $this
152
+ ->subject
153
+ ->setMasterMerchantId($merchantId);
154
+ $this
155
+ ->subject
156
+ ->setMerchantTransactionId($transactionId);
157
+
158
+ $this->assertEquals(
159
+ $result,
160
+ $this->subject->validate()
161
+ );
162
+ }
163
+
164
+ public function testGetBody() {
165
+
166
+ $requestBody = $this->subject->getBody();
167
+
168
+ $this->assertEquals(
169
+ '',
170
+ $requestBody
171
+ );
172
+
173
+ }
174
+ }
175
+
app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Model/Payment/Redirect/Api/TransactionStatusResponseTest.php ADDED
@@ -0,0 +1,370 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Tigo_TigoMoney_Model_Payment_Redirect_Api_TransactionStatusResponseTest
5
+ */
6
+ class Tigo_TigoMoney_Model_Payment_Redirect_Api_TransactionStatusResponseTest extends EcomDev_PHPUnit_Test_Case
7
+ {
8
+ /**
9
+ * @var String
10
+ */
11
+ protected $className = null;
12
+
13
+ /**
14
+ * @var Tigo_TigoMoney_Model_Payment_Redirect_Api_TransactionStatusResponse|PHPUnit_Framework_MockObject_MockObject
15
+ */
16
+ protected $subject = null;
17
+
18
+ /**
19
+ * Sets up the unit test case
20
+ */
21
+ protected function setUp()
22
+ {
23
+ $this->className = Tigo_TigoMoney_Model_Payment_Redirect_Api_TransactionStatusResponse::class;
24
+
25
+ $this->subject = $this
26
+ ->getMockBuilder($this->className)
27
+ ->setMethods(null)
28
+ ->setConstructorArgs(array(new Varien_Object()))
29
+ ->getMock();
30
+
31
+ }
32
+
33
+ public function testCallbackUrlGetterSetter()
34
+ {
35
+ $value = 'http://amazon.com/return/test';
36
+ $this
37
+ ->subject
38
+ ->setCallbackUri($value);
39
+ $this->assertEquals(
40
+ $value,
41
+ $this->subject->getCallbackUrl()
42
+ );
43
+ }
44
+
45
+ public function testExchangeRateGetterSetter()
46
+ {
47
+ $value = 1.3;
48
+ $this
49
+ ->subject
50
+ ->setExchangeRate($value);
51
+ $this->assertEquals(
52
+ $value,
53
+ $this->subject->getExchangeRate()
54
+ );
55
+ }
56
+
57
+ public function testLanguageGetterSetter()
58
+ {
59
+ $value = 'spa';
60
+ $this
61
+ ->subject
62
+ ->setLanguage($value);
63
+ $this->assertEquals(
64
+ $value,
65
+ $this->subject->getLanguage()
66
+ );
67
+ }
68
+
69
+ public function testLocalPaymentAmountGetterSetter()
70
+ {
71
+ $value = 1231.23;
72
+ $this
73
+ ->subject
74
+ ->setLocalPaymentAmount($value);
75
+ $this->assertEquals(
76
+ $value,
77
+ $this->subject->getLocalPaymentAmount()
78
+ );
79
+ }
80
+
81
+ public function testLocalPaymentCurrencyCodeGetterSetter()
82
+ {
83
+ $value = 'USD';
84
+ $this
85
+ ->subject
86
+ ->setLocalPaymentCurrencyCode($value);
87
+ $this->assertEquals(
88
+ $value,
89
+ $this->subject->getLocalPaymentCurrencyCode()
90
+ );
91
+ }
92
+
93
+ public function testMasterMerchantAccountGetterSetter()
94
+ {
95
+ $value = '123123';
96
+ $this
97
+ ->subject
98
+ ->setMasterMerchantAccount($value);
99
+ $this->assertEquals(
100
+ $value,
101
+ $this->subject->getMasterMerchantAccount()
102
+ );
103
+ }
104
+
105
+ public function testMasterMerchantIdGetterSetter()
106
+ {
107
+ $value = 'kmkmdfkdmf';
108
+ $this
109
+ ->subject
110
+ ->setMasterMerchantId($value);
111
+ $this->assertEquals(
112
+ $value,
113
+ $this->subject->getMasterMerchantId()
114
+ );
115
+ }
116
+
117
+ public function testMerchantReferenceGetterSetter()
118
+ {
119
+ $value = 'Amazon';
120
+ $this
121
+ ->subject
122
+ ->setMerchantReference($value);
123
+ $this->assertEquals(
124
+ $value,
125
+ $this->subject->getMerchantReference()
126
+ );
127
+ }
128
+
129
+ public function testMerchantCurrencyCodeGetterSetter()
130
+ {
131
+ $value = 'USD';
132
+ $this
133
+ ->subject
134
+ ->setMerchantCurrencyCode($value);
135
+ $this->assertEquals(
136
+ $value,
137
+ $this->subject->getMerchantCurrencyCode()
138
+ );
139
+ }
140
+
141
+ public function testMerchantFeeGetterSetter()
142
+ {
143
+ $value = 20.38;
144
+ $this
145
+ ->subject
146
+ ->setMerchantFee($value);
147
+ $this->assertEquals(
148
+ $value,
149
+ $this->subject->getMerchantFee()
150
+ );
151
+ }
152
+
153
+ public function testOriginPaymentAmountGetterSetter()
154
+ {
155
+ $value = 20.38;
156
+ $this
157
+ ->subject
158
+ ->setOriginPaymentAmount($value);
159
+ $this->assertEquals(
160
+ $value,
161
+ $this->subject->getOriginPaymentAmount()
162
+ );
163
+ }
164
+
165
+ public function testOriginPaymentCurrencyCodeGetterSetter()
166
+ {
167
+ $value = 'USD';
168
+ $this
169
+ ->subject
170
+ ->setOriginPaymentCurrencyCode($value);
171
+ $this->assertEquals(
172
+ $value,
173
+ $this->subject->getOriginPaymentCurrencyCode()
174
+ );
175
+ }
176
+
177
+ public function testOriginPaymentFeeGetterSetter()
178
+ {
179
+ $value = 123.23;
180
+ $this
181
+ ->subject
182
+ ->setOriginPaymentFee($value);
183
+ $this->assertEquals(
184
+ $value,
185
+ $this->subject->getOriginPaymentFee()
186
+ );
187
+ }
188
+
189
+ public function testOriginPaymentTaxGetterSetter()
190
+ {
191
+ $value = 123.34;
192
+ $this
193
+ ->subject
194
+ ->setOriginPaymentTax($value);
195
+ $this->assertEquals(
196
+ $value,
197
+ $this->subject->getOriginPaymentTax()
198
+ );
199
+ }
200
+
201
+ public function testRedirectUriGetterSetter()
202
+ {
203
+ $value = 'http://google.com/return/success';
204
+ $this
205
+ ->subject
206
+ ->setRedirectUri($value);
207
+ $this->assertEquals(
208
+ $value,
209
+ $this->subject->getRedirectUri()
210
+ );
211
+ }
212
+
213
+ public function testSubscriberAccountGetterSetter()
214
+ {
215
+ $value = '570293823';
216
+ $this
217
+ ->subject
218
+ ->setSubscriberAccount($value);
219
+ $this->assertEquals(
220
+ $value,
221
+ $this->subject->getSubscriberAccount()
222
+ );
223
+ }
224
+
225
+ public function testSubscriberCountryGetterSetter()
226
+ {
227
+ $value = '570293823';
228
+ $this
229
+ ->subject
230
+ ->setSubscriberCountry($value);
231
+ $this->assertEquals(
232
+ $value,
233
+ $this->subject->getSubscriberCountry()
234
+ );
235
+ }
236
+
237
+ public function testSubscriberCountryCodeGetterSetter()
238
+ {
239
+ $value = 'SLV';
240
+ $this
241
+ ->subject
242
+ ->setSubscriberCountryCode($value);
243
+ $this->assertEquals(
244
+ $value,
245
+ $this->subject->getSubscriberCountryCode()
246
+ );
247
+ }
248
+
249
+ public function testSubscriberEmailGetterSetter()
250
+ {
251
+ $value = 'johndoe@gmail.com';
252
+ $this
253
+ ->subject
254
+ ->setSubscriberEmail($value);
255
+ $this->assertEquals(
256
+ $value,
257
+ $this->subject->getSubscriberEmail()
258
+ );
259
+ }
260
+
261
+ public function testSubscriberFirstNameGetterSetter()
262
+ {
263
+ $value = 'John';
264
+ $this
265
+ ->subject
266
+ ->setSubscriberFirstName($value);
267
+ $this->assertEquals(
268
+ $value,
269
+ $this->subject->getSubscriberFirstName()
270
+ );
271
+ }
272
+
273
+ public function testSubscriberLastNameGetterSetter()
274
+ {
275
+ $value = 'Doe';
276
+ $this
277
+ ->subject
278
+ ->setSubscriberLastName($value);
279
+ $this->assertEquals(
280
+ $value,
281
+ $this->subject->getSubscriberLastName()
282
+ );
283
+ }
284
+
285
+ public function testTerminalIdGetterSetter()
286
+ {
287
+ $value = 'Magento';
288
+ $this
289
+ ->subject
290
+ ->setTerminalId($value);
291
+ $this->assertEquals(
292
+ $value,
293
+ $this->subject->getTerminalId()
294
+ );
295
+ }
296
+
297
+ public function testTransactionCompletedOnGetterSetter()
298
+ {
299
+ $value = '2018-09-13';
300
+ $this
301
+ ->subject
302
+ ->setTransactionCompletedOn($value);
303
+ $this->assertEquals(
304
+ $value,
305
+ $this->subject->getTransactionCompletedOn()
306
+ );
307
+ }
308
+
309
+ public function testTransactionCorrelationIdGetterSetter()
310
+ {
311
+ $value = 'o09cdkm09lkm09';
312
+ $this
313
+ ->subject
314
+ ->setTransactionCorrelationId($value);
315
+ $this->assertEquals(
316
+ $value,
317
+ $this->subject->getTransactionCorrelationId()
318
+ );
319
+ }
320
+
321
+ public function testTransactionCreatedOnGetterSetter()
322
+ {
323
+ $value = '2017-12-23';
324
+ $this
325
+ ->subject
326
+ ->setTransactionCreatedOn($value);
327
+ $this->assertEquals(
328
+ $value,
329
+ $this->subject->getTransactionCreatedOn()
330
+ );
331
+ }
332
+
333
+ public function testTransactionMerchantTransactionIdGetterSetter()
334
+ {
335
+ $value = '10000923';
336
+ $this
337
+ ->subject
338
+ ->setTransactionMerchantTransactionId($value);
339
+ $this->assertEquals(
340
+ $value,
341
+ $this->subject->getTransactionMerchantTransactionId()
342
+ );
343
+ }
344
+
345
+ public function testTransactionMfsTransactionIdGetterSetter()
346
+ {
347
+ $value = '23092309823';
348
+ $this
349
+ ->subject
350
+ ->setTransactionMfsTransactionId($value);
351
+ $this->assertEquals(
352
+ $value,
353
+ $this->subject->getTransactionMfsTransactionId()
354
+ );
355
+ }
356
+
357
+ public function testTransactionStatusGetterSetter()
358
+ {
359
+ $value = 'success';
360
+ $this
361
+ ->subject
362
+ ->setTransactionStatus($value);
363
+ $this->assertEquals(
364
+ $value,
365
+ $this->subject->getTransactionStatus()
366
+ );
367
+ }
368
+
369
+ }
370
+
app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Model/Payment/Redirect/ApiTest.php ADDED
@@ -0,0 +1,1012 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Tigo_TigoMoney_Model_Payment_Redirect_ApiTest
5
+ */
6
+ class Tigo_TigoMoney_Model_Payment_Redirect_ApiTest extends EcomDev_PHPUnit_Test_Case
7
+ {
8
+ /**
9
+ * @var Tigo_TigoMoney_Model_Payment_Redirect_Api_AuthorizationRequest|PHPUnit_Framework_MockObject_MockObject
10
+ */
11
+ protected $authorizationRequest = null;
12
+
13
+ /**
14
+ * @var String
15
+ */
16
+ protected $className = null;
17
+
18
+ /**
19
+ * @var Tigo_TigoMoney_Model_Debug|PHPUnit_Framework_MockObject_MockObject
20
+ */
21
+ protected $debug = null;
22
+
23
+ /**
24
+ * @var Tigo_TigoMoney_Model_Payment_Redirect_Api_GenerateTokenRequest|PHPUnit_Framework_MockObject_MockObject
25
+ */
26
+ protected $generateTokenRequest = null;
27
+
28
+ /**
29
+ * @var Tigo_TigoMoney_Model_Payment_Redirect_Api_ReverseTransactionRequest|PHPUnit_Framework_MockObject_MockObject
30
+ */
31
+ protected $reverseTransactionRequest = null;
32
+
33
+ /**
34
+ * @var Tigo_TigoMoney_Model_Payment_Redirect_Api_TransactionStatusRequest|PHPUnit_Framework_MockObject_MockObject
35
+ */
36
+ protected $transactionStatusRequest = null;
37
+
38
+ /**
39
+ * @var Tigo_TigoMoney_Model_Payment_Redirect_Api|PHPUnit_Framework_MockObject_MockObject
40
+ */
41
+ protected $subject = null;
42
+
43
+
44
+ /**
45
+ * @var Varien_Http_Client|PHPUnit_Framework_MockObject_MockObject
46
+ */
47
+ protected $varienHttpClient = null;
48
+
49
+
50
+ /**
51
+ * @var Zend_Http_Response|PHPUnit_Framework_MockObject_MockObject
52
+ */
53
+ protected $zendHttpResponse = null;
54
+
55
+ /**
56
+ * Sets up the unit test case
57
+ */
58
+ protected function setUp()
59
+ {
60
+ $this->className = Tigo_TigoMoney_Model_Payment_Redirect_Api::class;
61
+
62
+ $this->subject = $this
63
+ ->getMockBuilder($this->className)
64
+ ->setMethods(array('_getHttpClient'))
65
+ ->getMock();
66
+
67
+
68
+ $this->authorizationRequest = $this
69
+ ->getMockBuilder(Tigo_TigoMoney_Model_Payment_Redirect_Api_AuthorizationRequest::class)
70
+ ->setMethods(array('validate'))
71
+ ->getMock();
72
+ $this->replaceByMock(
73
+ 'model',
74
+ 'tigo_tigomoney/payment_redirect_api_authorizationRequest',
75
+ $this->authorizationRequest
76
+ );
77
+
78
+ $this->generateTokenRequest = $this
79
+ ->getMockBuilder(Tigo_TigoMoney_Model_Payment_Redirect_Api_GenerateTokenRequest::class)
80
+ ->setMethods(array('validate'))
81
+ ->getMock();
82
+ $this->replaceByMock(
83
+ 'model',
84
+ 'tigo_tigomoney/payment_redirect_api_generateTokenRequest',
85
+ $this->generateTokenRequest
86
+ );
87
+
88
+ $this->reverseTransactionRequest = $this
89
+ ->getMockBuilder(Tigo_TigoMoney_Model_Payment_Redirect_Api_ReverseTransactionRequest::class)
90
+ ->setMethods(array('validate'))
91
+ ->getMock();
92
+ $this->replaceByMock(
93
+ 'model',
94
+ 'tigo_tigomoney/payment_redirect_api_reverseTransactionRequest',
95
+ $this->reverseTransactionRequest
96
+ );
97
+
98
+ $this->transactionStatusRequest = $this
99
+ ->getMockBuilder(Tigo_TigoMoney_Model_Payment_Redirect_Api_TransactionStatusRequest::class)
100
+ ->setMethods(array('validate'))
101
+ ->getMock();
102
+ $this->replaceByMock(
103
+ 'model',
104
+ 'tigo_tigomoney/payment_redirect_api_transactionStatusRequest',
105
+ $this->transactionStatusRequest
106
+ );
107
+
108
+ $this->zendHttpResponse = $this
109
+ ->getMockBuilder(Zend_Http_Response::class)
110
+ ->setMethods(array('getBody', 'getStatus'))
111
+ ->disableOriginalConstructor()
112
+ ->getMock();
113
+
114
+ $this->varienHttpClient = $this
115
+ ->getMockBuilder(Varien_Http_Client::class)
116
+ ->setMethods(array('setUri', 'request'))
117
+ ->getMock();
118
+ $this->varienHttpClient
119
+ ->expects($this->any())
120
+ ->method('setUri')
121
+ ->will($this->returnValue($this->varienHttpClient));
122
+ $this->varienHttpClient
123
+ ->expects($this->any())
124
+ ->method('setHeaders')
125
+ ->will($this->returnValue($this->varienHttpClient));
126
+ $this->varienHttpClient
127
+ ->expects($this->any())
128
+ ->method('setRawData')
129
+ ->will($this->returnValue($this->varienHttpClient));
130
+ $this->varienHttpClient
131
+ ->expects($this->any())
132
+ ->method('setMethod')
133
+ ->will($this->returnValue($this->varienHttpClient));
134
+ $this->subject
135
+ ->expects($this->any())
136
+ ->method('_getHttpClient')
137
+ ->will($this->returnValue($this->varienHttpClient));
138
+ }
139
+
140
+ public function testGetAccessTokenDoesNotRequestWhenValidationFails()
141
+ {
142
+ $this
143
+ ->generateTokenRequest
144
+ ->expects($this->once())
145
+ ->method('validate')
146
+ ->will($this->returnValue(false));
147
+
148
+ $this
149
+ ->varienHttpClient
150
+ ->expects($this->never())
151
+ ->method('request');
152
+
153
+ $this
154
+ ->setExpectedException('Mage_Core_Exception');
155
+
156
+ $this
157
+ ->subject
158
+ ->getAccessToken($this->generateTokenRequest);
159
+ }
160
+
161
+ public function testGetRedirectUriDoesNotRequestWhenValidationFails()
162
+ {
163
+ $this
164
+ ->authorizationRequest
165
+ ->expects($this->once())
166
+ ->method('validate')
167
+ ->will($this->returnValue(false));
168
+
169
+ $this
170
+ ->varienHttpClient
171
+ ->expects($this->never())
172
+ ->method('request');
173
+
174
+ $this
175
+ ->setExpectedException('Mage_Core_Exception');
176
+
177
+ $this
178
+ ->subject
179
+ ->getRedirectUri($this->authorizationRequest);
180
+ }
181
+
182
+ public function testGetTransactionStatusDoesNotRequestWhenValidationFails()
183
+ {
184
+ $this
185
+ ->transactionStatusRequest
186
+ ->expects($this->once())
187
+ ->method('validate')
188
+ ->will($this->returnValue(false));
189
+
190
+ $this
191
+ ->varienHttpClient
192
+ ->expects($this->never())
193
+ ->method('request');
194
+
195
+ $this
196
+ ->setExpectedException('Mage_Core_Exception');
197
+
198
+ $this
199
+ ->subject
200
+ ->getTransactionStatus($this->transactionStatusRequest);
201
+ }
202
+
203
+ public function testReverseTransactionDoesNotRequestWhenValidationFails()
204
+ {
205
+ $this
206
+ ->reverseTransactionRequest
207
+ ->expects($this->once())
208
+ ->method('validate')
209
+ ->will($this->returnValue(false));
210
+
211
+ $this
212
+ ->varienHttpClient
213
+ ->expects($this->never())
214
+ ->method('request');
215
+
216
+ $this
217
+ ->setExpectedException('Mage_Core_Exception');
218
+
219
+ $this
220
+ ->subject
221
+ ->reverseTransaction($this->reverseTransactionRequest);
222
+ }
223
+
224
+ public function testGetAccessTokenRequestsWhenValidationPasses()
225
+ {
226
+ $accessToken = 'sadf09i234lmsdf09';
227
+
228
+ $this
229
+ ->generateTokenRequest
230
+ ->expects($this->once())
231
+ ->method('validate')
232
+ ->will($this->returnValue(true));
233
+
234
+ $this->varienHttpClient
235
+ ->expects($this->once())
236
+ ->method('request')
237
+ ->will($this->returnValue($this->zendHttpResponse));
238
+
239
+ $response = array(
240
+ 'accessToken' => $accessToken
241
+ );
242
+
243
+ $this
244
+ ->zendHttpResponse
245
+ ->expects($this->any())
246
+ ->method('getBody')
247
+ ->will($this->returnValue(json_encode($response)));
248
+
249
+ $this
250
+ ->zendHttpResponse
251
+ ->expects($this->any())
252
+ ->method('getStatus')
253
+ ->will($this->returnValue(200));
254
+
255
+ $return = $this
256
+ ->subject
257
+ ->getAccessToken($this->generateTokenRequest);
258
+
259
+ $this->assertEquals(
260
+ $accessToken,
261
+ $return->getAccessToken()
262
+ );
263
+ }
264
+
265
+ public function testGetRedirectUriRequestsWhenValidationPasses()
266
+ {
267
+ $authCode = 'sadf09i234lmsdf09';
268
+ $redirectUri = 'http://google.com/redirect';
269
+
270
+ $this
271
+ ->authorizationRequest
272
+ ->expects($this->once())
273
+ ->method('validate')
274
+ ->will($this->returnValue(true));
275
+
276
+ $this->varienHttpClient
277
+ ->expects($this->once())
278
+ ->method('request')
279
+ ->will($this->returnValue($this->zendHttpResponse));
280
+
281
+ $response = array(
282
+ 'authCode' => $authCode,
283
+ 'redirectUrl' => $redirectUri,
284
+ );
285
+
286
+ $this
287
+ ->zendHttpResponse
288
+ ->expects($this->any())
289
+ ->method('getBody')
290
+ ->will($this->returnValue(json_encode($response)));
291
+
292
+ $this
293
+ ->zendHttpResponse
294
+ ->expects($this->any())
295
+ ->method('getStatus')
296
+ ->will($this->returnValue(200));
297
+
298
+ $return = $this
299
+ ->subject
300
+ ->getRedirectUri($this->authorizationRequest);
301
+
302
+ $this->assertEquals(
303
+ $authCode,
304
+ $return->getAuthCode()
305
+ );
306
+
307
+ $this->assertEquals(
308
+ $redirectUri,
309
+ $return->getRedirectUri()
310
+ );
311
+ }
312
+
313
+ public function testGetTransactionStatusRequestsWhenValidationPasses()
314
+ {
315
+ $transactionMerchantTransactionId = '100002342';
316
+ $transactionMfsTransactionId = '2398123891293';
317
+ $transactionCreatedOn = '2017-02-02';
318
+ $transactionStatus = 'success';
319
+ $transactionCompletedOn = '2017-02-03';
320
+ $masterMerchantAccount = '434376';
321
+ $masterMerchantId = '123123';
322
+ $merchantReference = 'Test';
323
+ $merchantFee = '1.23';
324
+ $merchantCurrencyCode = 'USD';
325
+ $subscriberAccount = '5039292829';
326
+ $subscriberCountryCode = '503';
327
+ $subscriberCountry = 'SLV';
328
+ $subscriberFirstName = 'John';
329
+ $subscriberLastName = 'Doe';
330
+ $subscriberEmail = 'johndoe@yahoo.com';
331
+ $redirectUri = 'http://amazon.com/success';
332
+ $callbackUri = 'http://google.com/callback';
333
+ $language = 'spa';
334
+ $terminalId = 'Magento';
335
+ $exchangeRate = '1.23';
336
+ $originPaymentAmount = '1000.32';
337
+ $originPaymentCurrencyCode = 'ISD';
338
+ $originPaymentTax = '12.32';
339
+ $originPaymentFee = '5.00';
340
+ $localPaymentAmount = '10323.34';
341
+ $localPaymentCurrencyCode = 'USD';
342
+
343
+ $this
344
+ ->transactionStatusRequest
345
+ ->expects($this->once())
346
+ ->method('validate')
347
+ ->will($this->returnValue(true));
348
+
349
+ $this->varienHttpClient
350
+ ->expects($this->once())
351
+ ->method('request')
352
+ ->will($this->returnValue($this->zendHttpResponse));
353
+
354
+ $response = array(
355
+ 'Transaction' => array(
356
+ 'merchantTransactionId' => $transactionMerchantTransactionId,
357
+ 'mfsTransactionId' => $transactionMfsTransactionId,
358
+ 'createdOn' => $transactionCreatedOn,
359
+ 'status' => $transactionStatus,
360
+ 'completedOn' => $transactionCompletedOn
361
+ ),
362
+ 'MasterMerchant' => array(
363
+ 'id' => $masterMerchantId,
364
+ 'account' => $masterMerchantAccount
365
+ ),
366
+ 'Merchant' => array(
367
+ 'currencyCode' => $merchantCurrencyCode,
368
+ 'reference' => $merchantReference,
369
+ 'fee' => $merchantFee
370
+ ),
371
+ 'Subscriber' => array(
372
+ 'emailId' => $subscriberEmail,
373
+ 'account' => $subscriberAccount,
374
+ 'countryCode' => $subscriberCountryCode,
375
+ 'country' => $subscriberCountry,
376
+ 'firstName' => $subscriberFirstName,
377
+ 'lastName' => $subscriberLastName
378
+ ),
379
+ 'redirectUri' => $redirectUri,
380
+ 'callbackUri' => $callbackUri,
381
+ 'language' => $language,
382
+ 'terminalId' => $terminalId,
383
+ 'exchangeRate' => $exchangeRate,
384
+ 'OriginPayment' => array(
385
+ 'amount' => $originPaymentAmount,
386
+ 'currencyCode' => $originPaymentCurrencyCode,
387
+ 'tax' => $originPaymentTax,
388
+ 'fee' => $originPaymentFee
389
+ ),
390
+ 'LocalPayment' => array(
391
+ 'amount' => $localPaymentAmount,
392
+ 'currencyCode' => $localPaymentCurrencyCode
393
+ )
394
+ );
395
+
396
+ $this
397
+ ->zendHttpResponse
398
+ ->expects($this->any())
399
+ ->method('getBody')
400
+ ->will($this->returnValue(json_encode($response)));
401
+
402
+ $this
403
+ ->zendHttpResponse
404
+ ->expects($this->any())
405
+ ->method('getStatus')
406
+ ->will($this->returnValue(200));
407
+
408
+ $return = $this
409
+ ->subject
410
+ ->getTransactionStatus($this->transactionStatusRequest);
411
+
412
+ $this->assertEquals(
413
+ $transactionMerchantTransactionId,
414
+ $return->getTransactionMerchantTransactionId()
415
+ );
416
+
417
+ $this->assertEquals(
418
+ $transactionMfsTransactionId,
419
+ $return->getTransactionMfsTransactionId()
420
+ );
421
+
422
+ $this->assertEquals(
423
+ $transactionCreatedOn,
424
+ $return->getTransactionCreatedOn()
425
+ );
426
+
427
+ $this->assertEquals(
428
+ $transactionStatus,
429
+ $return->getTransactionStatus()
430
+ );
431
+
432
+ $this->assertEquals(
433
+ $transactionCompletedOn,
434
+ $return->getTransactionCompletedOn()
435
+ );
436
+
437
+ $this->assertEquals(
438
+ $masterMerchantAccount,
439
+ $return->getMasterMerchantAccount()
440
+ );
441
+
442
+ $this->assertEquals(
443
+ $masterMerchantId,
444
+ $return->getMasterMerchantId()
445
+ );
446
+
447
+ $this->assertEquals(
448
+ $merchantReference,
449
+ $return->getMerchantReference()
450
+ );
451
+
452
+ $this->assertEquals(
453
+ $merchantFee,
454
+ $return->getMerchantFee()
455
+ );
456
+
457
+ $this->assertEquals(
458
+ $merchantCurrencyCode,
459
+ $return->getMerchantCurrencyCode()
460
+ );
461
+
462
+ $this->assertEquals(
463
+ $subscriberAccount,
464
+ $return->getSubscriberAccount()
465
+ );
466
+
467
+ $this->assertEquals(
468
+ $subscriberCountryCode,
469
+ $return->getSubscriberCountryCode()
470
+ );
471
+
472
+ $this->assertEquals(
473
+ $subscriberFirstName,
474
+ $return->getSubscriberFirstName()
475
+ );
476
+
477
+ $this->assertEquals(
478
+ $subscriberLastName,
479
+ $return->getSubscriberLastName()
480
+ );
481
+
482
+ $this->assertEquals(
483
+ $subscriberEmail,
484
+ $return->getSubscriberEmail()
485
+ );
486
+
487
+ $this->assertEquals(
488
+ $subscriberCountry,
489
+ $return->getSubscriberCountry()
490
+ );
491
+
492
+ $this->assertEquals(
493
+ $redirectUri,
494
+ $return->getRedirectUri()
495
+ );
496
+
497
+ $this->assertEquals(
498
+ $callbackUri,
499
+ $return->getCallbackUrl()
500
+ );
501
+
502
+ $this->assertEquals(
503
+ $language,
504
+ $return->getLanguage()
505
+ );
506
+
507
+ $this->assertEquals(
508
+ $terminalId,
509
+ $return->getTerminalId()
510
+ );
511
+
512
+ $this->assertEquals(
513
+ $exchangeRate,
514
+ $return->getExchangeRate()
515
+ );
516
+
517
+ $this->assertEquals(
518
+ $originPaymentAmount,
519
+ $return->getOriginPaymentAmount()
520
+ );
521
+
522
+ $this->assertEquals(
523
+ $originPaymentCurrencyCode,
524
+ $return->getOriginPaymentCurrencyCode()
525
+ );
526
+
527
+ $this->assertEquals(
528
+ $originPaymentTax,
529
+ $return->getOriginPaymentTax()
530
+ );
531
+
532
+ $this->assertEquals(
533
+ $originPaymentFee,
534
+ $return->getOriginPaymentFee()
535
+ );
536
+
537
+ $this->assertEquals(
538
+ $localPaymentAmount,
539
+ $return->getLocalPaymentAmount()
540
+ );
541
+
542
+ $this->assertEquals(
543
+ $localPaymentCurrencyCode,
544
+ $return->getLocalPaymentCurrencyCode()
545
+ );
546
+ }
547
+
548
+
549
+ public function testReverseTransactionRequestsWhenValidationPasses()
550
+ {
551
+ $status = 'success';
552
+ $transactionMerchantTransactionId = '10009382';
553
+ $transactionCorrelationId = '00930930.039093093.090909309';
554
+ $transactionMfsTransactionId = '234209283092';
555
+ $transactionMfsReverseTransactionId = '39393939393';
556
+ $transactionStatus = 'failed';
557
+ $transactionMessage = 'The transaction failed';
558
+
559
+ $this
560
+ ->reverseTransactionRequest
561
+ ->expects($this->once())
562
+ ->method('validate')
563
+ ->will($this->returnValue(true));
564
+
565
+ $this->varienHttpClient
566
+ ->expects($this->once())
567
+ ->method('request')
568
+ ->will($this->returnValue($this->zendHttpResponse));
569
+
570
+ $response = array(
571
+ 'status' => $status,
572
+ 'Transaction' => array(
573
+ 'merchantTransactionId' => $transactionMerchantTransactionId,
574
+ 'correlationId' => $transactionCorrelationId,
575
+ 'mfsTransactionId' => $transactionMfsTransactionId,
576
+ 'mfsReverseTransactionId' => $transactionMfsReverseTransactionId,
577
+ 'status' => $transactionStatus,
578
+ 'message' => $transactionMessage
579
+ )
580
+ );
581
+
582
+ $this
583
+ ->zendHttpResponse
584
+ ->expects($this->any())
585
+ ->method('getBody')
586
+ ->will($this->returnValue(json_encode($response)));
587
+
588
+ $this
589
+ ->zendHttpResponse
590
+ ->expects($this->any())
591
+ ->method('getStatus')
592
+ ->will($this->returnValue(200));
593
+
594
+ $return = $this
595
+ ->subject
596
+ ->reverseTransaction($this->reverseTransactionRequest);
597
+
598
+ $this->assertEquals(
599
+ $status,
600
+ $return->getStatus()
601
+ );
602
+
603
+ $this->assertEquals(
604
+ $transactionMerchantTransactionId,
605
+ $return->getTransactionMerchantTransactionId()
606
+ );
607
+
608
+ $this->assertEquals(
609
+ $transactionCorrelationId,
610
+ $return->getTransactionCorrelationId()
611
+ );
612
+
613
+ $this->assertEquals(
614
+ $transactionMfsTransactionId,
615
+ $return->getTransactionMfsTransactionId()
616
+ );
617
+
618
+ $this->assertEquals(
619
+ $transactionStatus,
620
+ $return->getTransactionStatus()
621
+ );
622
+
623
+ $this->assertEquals(
624
+ $transactionMessage,
625
+ $return->getTransactionMessage()
626
+ );
627
+
628
+ $this->assertEquals(
629
+ $transactionMfsReverseTransactionId,
630
+ $return->getTransactionMfsReverseTransactionId()
631
+ );
632
+ }
633
+
634
+ public function testGetAccessTokenRequestsWhenValidationPassesAndReturnsErrorWhenRequestFails()
635
+ {
636
+ $errorDescription = 'An error occurred';
637
+
638
+ $this
639
+ ->generateTokenRequest
640
+ ->expects($this->once())
641
+ ->method('validate')
642
+ ->will($this->returnValue(true));
643
+
644
+ $this->varienHttpClient
645
+ ->expects($this->once())
646
+ ->method('request')
647
+ ->will($this->returnValue($this->zendHttpResponse));
648
+
649
+ $response = array(
650
+ 'error_description' => $errorDescription
651
+ );
652
+
653
+ $this
654
+ ->zendHttpResponse
655
+ ->expects($this->any())
656
+ ->method('getBody')
657
+ ->will($this->returnValue(json_encode($response)));
658
+
659
+ $this
660
+ ->zendHttpResponse
661
+ ->expects($this->any())
662
+ ->method('getStatus')
663
+ ->will($this->returnValue(503));
664
+
665
+ $return = $this
666
+ ->subject
667
+ ->getAccessToken($this->generateTokenRequest);
668
+
669
+ $this->assertContains(
670
+ $errorDescription,
671
+ $return->getErrors()
672
+ );
673
+ }
674
+
675
+ public function testGetRedirectUriRequestsWhenValidationPassesAndReturnsErrorWhenRequestFails()
676
+ {
677
+ $errorDescription = 'An error occurred';
678
+
679
+ $this
680
+ ->authorizationRequest
681
+ ->expects($this->once())
682
+ ->method('validate')
683
+ ->will($this->returnValue(true));
684
+
685
+ $this->varienHttpClient
686
+ ->expects($this->once())
687
+ ->method('request')
688
+ ->will($this->returnValue($this->zendHttpResponse));
689
+
690
+ $response = array(
691
+ 'error_description' => $errorDescription
692
+ );
693
+
694
+ $this
695
+ ->zendHttpResponse
696
+ ->expects($this->any())
697
+ ->method('getBody')
698
+ ->will($this->returnValue(json_encode($response)));
699
+
700
+ $this
701
+ ->zendHttpResponse
702
+ ->expects($this->any())
703
+ ->method('getStatus')
704
+ ->will($this->returnValue(503));
705
+
706
+ $return = $this
707
+ ->subject
708
+ ->getRedirectUri($this->authorizationRequest);
709
+
710
+ $this->assertContains(
711
+ $errorDescription,
712
+ $return->getErrors()
713
+ );
714
+ }
715
+
716
+ public function testGetTransactionStatusRequestsWhenValidationPassesAndReturnsErrorWhenRequestFails()
717
+ {
718
+ $errorDescription = 'An error occurred';
719
+
720
+ $this
721
+ ->transactionStatusRequest
722
+ ->expects($this->once())
723
+ ->method('validate')
724
+ ->will($this->returnValue(true));
725
+
726
+ $this->varienHttpClient
727
+ ->expects($this->once())
728
+ ->method('request')
729
+ ->will($this->returnValue($this->zendHttpResponse));
730
+
731
+ $response = array(
732
+ 'error_description' => $errorDescription
733
+ );
734
+
735
+ $this
736
+ ->zendHttpResponse
737
+ ->expects($this->any())
738
+ ->method('getBody')
739
+ ->will($this->returnValue(json_encode($response)));
740
+
741
+ $this
742
+ ->zendHttpResponse
743
+ ->expects($this->any())
744
+ ->method('getStatus')
745
+ ->will($this->returnValue(503));
746
+
747
+ $return = $this
748
+ ->subject
749
+ ->getTransactionStatus($this->transactionStatusRequest);
750
+
751
+ $this->assertContains(
752
+ $errorDescription,
753
+ $return->getErrors()
754
+ );
755
+ }
756
+
757
+ public function testReverseTransactionRequestsWhenValidationPassesAndReturnsErrorWhenRequestFails()
758
+ {
759
+ $status = 'failure';
760
+ $transactionMerchantTransactionId = '10009382';
761
+ $transactionCorrelationId = '00930930.039093093.090909309';
762
+ $transactionMfsTransactionId = '234209283092';
763
+ $transactionStatus = 'failed';
764
+ $transactionMessage = 'The transaction failed';
765
+ $errorType = 'Warning';
766
+ $error = '123';
767
+ $errorDescription = 'Could not connect to the database';
768
+
769
+ $this
770
+ ->reverseTransactionRequest
771
+ ->expects($this->once())
772
+ ->method('validate')
773
+ ->will($this->returnValue(true));
774
+
775
+ $this->varienHttpClient
776
+ ->expects($this->once())
777
+ ->method('request')
778
+ ->will($this->returnValue($this->zendHttpResponse));
779
+
780
+ $response = array(
781
+ 'status' => $status,
782
+ 'Transaction' => array(
783
+ 'merchantTransactionId' => $transactionMerchantTransactionId,
784
+ 'correlationId' => $transactionCorrelationId,
785
+ 'mfsTransactionId' => $transactionMfsTransactionId,
786
+ 'status' => $transactionStatus,
787
+ 'message' => $transactionMessage
788
+ ),
789
+ 'error' => $error,
790
+ 'error_type' => $errorType,
791
+ 'error_description' => $errorDescription
792
+ );
793
+
794
+ $this
795
+ ->zendHttpResponse
796
+ ->expects($this->any())
797
+ ->method('getBody')
798
+ ->will($this->returnValue(json_encode($response)));
799
+
800
+ $this
801
+ ->zendHttpResponse
802
+ ->expects($this->any())
803
+ ->method('getStatus')
804
+ ->will($this->returnValue(503));
805
+
806
+ $return = $this
807
+ ->subject
808
+ ->reverseTransaction($this->reverseTransactionRequest);
809
+
810
+ $this->assertContains(
811
+ $errorDescription,
812
+ $return->getErrors()
813
+ );
814
+
815
+ $this->assertEquals(
816
+ $status,
817
+ $return->getStatus()
818
+ );
819
+
820
+ $this->assertEquals(
821
+ $transactionMerchantTransactionId,
822
+ $return->getTransactionMerchantTransactionId()
823
+ );
824
+
825
+ $this->assertEquals(
826
+ $transactionCorrelationId,
827
+ $return->getTransactionCorrelationId()
828
+ );
829
+
830
+ $this->assertEquals(
831
+ $transactionMfsTransactionId,
832
+ $return->getTransactionMfsTransactionId()
833
+ );
834
+
835
+ $this->assertEquals(
836
+ $transactionStatus,
837
+ $return->getTransactionStatus()
838
+ );
839
+
840
+ $this->assertEquals(
841
+ $transactionMessage,
842
+ $return->getTransactionMessage()
843
+ );
844
+
845
+ $this->assertEquals(
846
+ $errorType,
847
+ $return->getErrorType()
848
+ );
849
+
850
+ $this->assertEquals(
851
+ $error,
852
+ $return->getError()
853
+ );
854
+ }
855
+
856
+ /**
857
+ * @loadFixture testModeOn
858
+ */
859
+ public function testApiUsesSandboxUrlWhenTestModeOn()
860
+ {
861
+ $this
862
+ ->generateTokenRequest
863
+ ->expects($this->once())
864
+ ->method('validate')
865
+ ->will($this->returnValue(true));
866
+
867
+ $this->varienHttpClient
868
+ ->expects($this->once())
869
+ ->method('request')
870
+ ->will($this->returnValue($this->zendHttpResponse));
871
+
872
+ $response = array(
873
+ 'accessToken' => 'lslsl2r23jrn'
874
+ );
875
+
876
+ $this
877
+ ->zendHttpResponse
878
+ ->expects($this->any())
879
+ ->method('getBody')
880
+ ->will($this->returnValue(json_encode($response)));
881
+
882
+ $this
883
+ ->zendHttpResponse
884
+ ->expects($this->any())
885
+ ->method('getStatus')
886
+ ->will($this->returnValue(200));
887
+
888
+ $this
889
+ ->varienHttpClient
890
+ ->expects($this->once())
891
+ ->method('setUri')
892
+ ->with($this->callback(function($endpoint) {
893
+ return (
894
+ strpos(
895
+ trim($endpoint),
896
+ Tigo_TigoMoney_Model_Payment_Redirect_Api::TEST_ENVIRONMENT_DOMAIN
897
+ ) === 0
898
+ );
899
+ }));
900
+
901
+ $this
902
+ ->subject
903
+ ->getAccessToken($this->generateTokenRequest);
904
+ }
905
+
906
+ /**
907
+ * @loadFixture testModeOff
908
+ */
909
+ public function testApiUsesProductionUrlWhenTestModeOff()
910
+ {
911
+ $this
912
+ ->generateTokenRequest
913
+ ->expects($this->once())
914
+ ->method('validate')
915
+ ->will($this->returnValue(true));
916
+
917
+ $this->varienHttpClient
918
+ ->expects($this->once())
919
+ ->method('request')
920
+ ->will($this->returnValue($this->zendHttpResponse));
921
+
922
+ $response = array(
923
+ 'accessToken' => 'lslsl2r23jrn'
924
+ );
925
+
926
+ $this
927
+ ->zendHttpResponse
928
+ ->expects($this->any())
929
+ ->method('getBody')
930
+ ->will($this->returnValue(json_encode($response)));
931
+
932
+ $this
933
+ ->zendHttpResponse
934
+ ->expects($this->any())
935
+ ->method('getStatus')
936
+ ->will($this->returnValue(200));
937
+
938
+ $this
939
+ ->varienHttpClient
940
+ ->expects($this->once())
941
+ ->method('setUri')
942
+ ->with($this->callback(function($endpoint) {
943
+ return (
944
+ strpos(
945
+ trim($endpoint),
946
+ Tigo_TigoMoney_Model_Payment_Redirect_Api::PROD_ENVIRONMENT_DOMAIN
947
+ ) === 0
948
+ );
949
+ }));
950
+
951
+ $this
952
+ ->subject
953
+ ->getAccessToken($this->generateTokenRequest);
954
+ }
955
+
956
+ /**
957
+ * @loadFixture testModeOff
958
+ */
959
+ public function testFetchResponseValueReturnsNullWhenKeyAndSubkeyNotFound()
960
+ {
961
+ $this
962
+ ->transactionStatusRequest
963
+ ->expects($this->once())
964
+ ->method('validate')
965
+ ->will($this->returnValue(true));
966
+
967
+ $this->varienHttpClient
968
+ ->expects($this->once())
969
+ ->method('request')
970
+ ->will($this->returnValue($this->zendHttpResponse));
971
+
972
+ $response = array(
973
+ 'Transaction' => array(
974
+ 'merchantTransactionId' => 'exists',
975
+ ),
976
+ 'redirectUri' => 'exists2'
977
+ );
978
+
979
+ $this
980
+ ->zendHttpResponse
981
+ ->expects($this->any())
982
+ ->method('getBody')
983
+ ->will($this->returnValue(json_encode($response)));
984
+
985
+ $this
986
+ ->zendHttpResponse
987
+ ->expects($this->any())
988
+ ->method('getStatus')
989
+ ->will($this->returnValue(200));
990
+
991
+ $return = $this
992
+ ->subject
993
+ ->getTransactionStatus($this->transactionStatusRequest);
994
+
995
+ $this->assertEmpty(
996
+ $return->getOriginPaymentCurrencyCode()
997
+ );
998
+
999
+ $this->assertEmpty(
1000
+ $return->getCallbackUrl()
1001
+ );
1002
+
1003
+ $this->assertNotNull(
1004
+ $return->getRedirectUri()
1005
+ );
1006
+
1007
+ $this->assertNotNull(
1008
+ $return->getTransactionMerchantTransactionId()
1009
+ );
1010
+ }
1011
+ }
1012
+
app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Model/Payment/Redirect/ApiTest/fixtures/testModeOff.yaml ADDED
@@ -0,0 +1,2 @@
 
 
1
+ config:
2
+ default/payment/tigo_tigomoney/test_mode: 0
app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Model/Payment/Redirect/ApiTest/fixtures/testModeOn.yaml ADDED
@@ -0,0 +1,2 @@
 
 
1
+ config:
2
+ default/payment/tigo_tigomoney/test_mode: 1
app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Model/Payment/Redirect/SyncTest.php ADDED
@@ -0,0 +1,1898 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Tigo_TigoMoney_Model_Payment_Redirect_SyncTest
5
+ */
6
+ class Tigo_TigoMoney_Model_Payment_Redirect_SyncTest extends EcomDev_PHPUnit_Test_Case
7
+ {
8
+ /**
9
+ * @var Tigo_TigoMoney_Model_Payment_Redirect_Api|PHPUnit_Framework_MockObject_MockObject
10
+ */
11
+ protected $api = null;
12
+
13
+ /**
14
+ * @var Mage_Core_Model_Resource_Transaction|PHPUnit_Framework_MockObject_MockObject
15
+ */
16
+ protected $coreResourceTransaction = null;
17
+
18
+ /**
19
+ * @var String
20
+ */
21
+ protected $className = null;
22
+
23
+ /**
24
+ * @var Tigo_TigoMoney_Model_Payment_Redirect_Api_GenerateTokenRequest|PHPUnit_Framework_MockObject_MockObject
25
+ */
26
+ protected $generateAccessTokenRequest = null;
27
+
28
+ /**
29
+ * @var Tigo_TigoMoney_Model_Payment_Redirect_Api_GenerateTokenResponse|PHPUnit_Framework_MockObject_MockObject
30
+ */
31
+ protected $generateAccessTokenResponse = null;
32
+
33
+ /**
34
+ * @var Mage_Sales_Model_Order_Invoice|PHPUnit_Framework_MockObject_MockObject
35
+ */
36
+ protected $invoice = null;
37
+
38
+ /**
39
+ * @var Mage_Sales_Model_Order|PHPUnit_Framework_MockObject_MockObject
40
+ */
41
+ protected $order = null;
42
+
43
+ /**
44
+ * @var Mage_Sales_Model_Order_Payment|PHPUnit_Framework_MockObject_MockObject
45
+ */
46
+ protected $payment = null;
47
+
48
+ /**
49
+ * @var array
50
+ */
51
+ protected $requestParams = array();
52
+
53
+ /**
54
+ * @var Tigo_TigoMoney_Model_Payment_Redirect_Sync|PHPUnit_Framework_MockObject_MockObject
55
+ */
56
+ protected $subject = null;
57
+
58
+ /**
59
+ * @var Tigo_TigoMoney_Model_Payment_Redirect_Api_TransactionStatusRequest|PHPUnit_Framework_MockObject_MockObject
60
+ */
61
+ protected $transactionStatusRequest = null;
62
+
63
+ /**
64
+ * @var Tigo_TigoMoney_Model_Payment_Redirect_Api_TransactionStatusResponse|PHPUnit_Framework_MockObject_MockObject
65
+ */
66
+ protected $transactionStatusResponse = null;
67
+
68
+ /**
69
+ * Sets up the unit test case
70
+ */
71
+ protected function setUp()
72
+ {
73
+ $this->className = Tigo_TigoMoney_Model_Payment_Redirect_Sync::class;
74
+
75
+ $this->subject = $this
76
+ ->getMockBuilder($this->className)
77
+ ->setMethods(array('_getResourceTransactionInstance'))
78
+ ->getMock();
79
+
80
+ $this->order = $this
81
+ ->getMockBuilder(Mage_Sales_Model_Order::class)
82
+ ->setMethods(array('loadByIncrementId', 'canCancel', 'cancel', 'prepareInvoice', 'canInvoice', 'save', 'getPayment'))
83
+ ->getMock();
84
+ $this->replaceByMock('model', 'sales/order', $this->order);
85
+
86
+ $this->payment = $this
87
+ ->getMockBuilder(Mage_Sales_Model_Order_Payment::class)
88
+ ->setMethods(array('save'))
89
+ ->getMock();
90
+ $this->order
91
+ ->expects($this->any())
92
+ ->method('getPayment')
93
+ ->will($this->returnValue($this->payment));
94
+
95
+ $this->invoice = $this
96
+ ->getMockBuilder(Mage_Sales_Model_Order_Invoice::class)
97
+ ->setMethods(array('setRequestedCaptureCase', 'register'))
98
+ ->getMock();
99
+
100
+ $this->generateAccessTokenResponse = $this
101
+ ->getMockBuilder(Tigo_TigoMoney_Model_Payment_Redirect_Api_GenerateTokenResponse::class)
102
+ ->setMethods(array('isSuccess'))
103
+ ->setConstructorArgs(array(new Varien_Object()))
104
+ ->getMock();
105
+ $this->replaceByMock('model', 'tigo_tigomoney/payment_redirect_api_generateTokenResponse', $this->generateAccessTokenResponse);
106
+
107
+ $this->transactionStatusResponse = $this
108
+ ->getMockBuilder(Tigo_TigoMoney_Model_Payment_Redirect_Api_TransactionStatusResponse::class)
109
+ ->setMethods(array('isSuccess'))
110
+ ->setConstructorArgs(array(new Varien_Object()))
111
+ ->getMock();
112
+ $this->replaceByMock('model', 'tigo_tigomoney/payment_redirect_api_transactionStatusResponse', $this->transactionStatusResponse);
113
+
114
+ $this->generateAccessTokenRequest = $this
115
+ ->getMockBuilder(Tigo_TigoMoney_Model_Payment_Redirect_Api_GenerateTokenRequest::class)
116
+ ->setMethods(array('getAccessToken'))
117
+ ->getMock();
118
+ $this->replaceByMock('model', 'tigo_tigomoney/payment_redirect_api_generateTokenRequest', $this->generateAccessTokenRequest);
119
+
120
+ $this->transactionStatusRequest = $this
121
+ ->getMockBuilder(Tigo_TigoMoney_Model_Payment_Redirect_Api_TransactionStatusRequest::class)
122
+ ->setMethods(null)
123
+ ->getMock();
124
+ $this->replaceByMock('model', 'tigo_tigomoney/payment_redirect_api_transactionStatusRequest', $this->transactionStatusRequest);
125
+
126
+ $this->api = $this
127
+ ->getMockBuilder(Tigo_TigoMoney_Model_Payment_Redirect_Api::class)
128
+ ->setMethods(array('getAccessToken', 'getTransactionStatus'))
129
+ ->getMock();
130
+ $this->api
131
+ ->expects($this->any())
132
+ ->method('getAccessToken')
133
+ ->will($this->returnValue($this->generateAccessTokenResponse));
134
+ $this->api
135
+ ->expects($this->any())
136
+ ->method('getTransactionStatus')
137
+ ->will($this->returnValue($this->transactionStatusResponse));
138
+ $this->replaceByMock('model', 'tigo_tigomoney/payment_redirect_api', $this->api);
139
+
140
+ $this->coreResourceTransaction = $this
141
+ ->getMockBuilder(Mage_Core_Model_Resource_Transaction::class)
142
+ ->setMethods(array('addObject', 'save'))
143
+ ->getMock();
144
+ $this
145
+ ->subject
146
+ ->expects($this->any())
147
+ ->method('_getResourceTransactionInstance')
148
+ ->will($this->returnValue($this->coreResourceTransaction));
149
+ }
150
+
151
+ protected function _getRequestParams(
152
+ $merchantTransactionId = null,
153
+ $mfsTransactionId = null,
154
+ $transactionCode = null,
155
+ $transactionDescription = null,
156
+ $transactionStatus = null,
157
+ $accessToken = null
158
+ )
159
+ {
160
+ return array(
161
+ Tigo_TigoMoney_Model_Payment_Redirect_Sync::PARAM_KEY_MERCHANT_TRANSACTION_ID => $merchantTransactionId,
162
+ Tigo_TigoMoney_Model_Payment_Redirect_Sync::PARAM_KEY_MFS_TRANSACTION_ID => $mfsTransactionId,
163
+ Tigo_TigoMoney_Model_Payment_Redirect_Sync::PARAM_KEY_TRANSACTION_CODE => $transactionCode,
164
+ Tigo_TigoMoney_Model_Payment_Redirect_Sync::PARAM_KEY_TRANSACTION_DESCRIPTION => $transactionDescription,
165
+ Tigo_TigoMoney_Model_Payment_Redirect_Sync::PARAM_KEY_TRANSACTION_STATUS => $transactionStatus,
166
+ Tigo_TigoMoney_Model_Payment_Redirect_Sync::PARAM_KEY_MERCHANT_ACCESS_TOKEN => $accessToken,
167
+ );
168
+ }
169
+
170
+ public function testHandleRequestDoesNotFindOrder()
171
+ {
172
+ $this
173
+ ->order
174
+ ->expects($this->any())
175
+ ->method('load')
176
+ ->with(null)
177
+ ->will($this->returnValue($this->order));
178
+ $this
179
+ ->order
180
+ ->expects($this->any())
181
+ ->method('getId')
182
+ ->will($this->returnValue(null));
183
+
184
+ $this
185
+ ->order
186
+ ->expects($this->never())
187
+ ->method('cancel');
188
+
189
+ $this
190
+ ->order
191
+ ->expects($this->never())
192
+ ->method('invoice');
193
+
194
+ $this
195
+ ->order
196
+ ->expects($this->never())
197
+ ->method('save');
198
+
199
+ $this->subject->handleRequest($this->_getRequestParams());
200
+ }
201
+
202
+ public function testHandleRequestInvoiceOrder()
203
+ {
204
+ $orderId = 233;
205
+ $orderIncrementId = '10000233';
206
+ $orderBaseGrandTotal = 2323.34;
207
+ $mfsTransactionId = '324234234';
208
+ $transactionCode = '09203920394.2930429304.2039402394';
209
+ $transactionDescription = 'Paid';
210
+ $transactionStatus = Tigo_TigoMoney_Model_Payment_Redirect_Sync::PARAM_VALUE_TRANSACTION_STATUS_SUCCESS;
211
+ $accessTokenForTransactionStatus = 'oiusdofiuasodifu';
212
+
213
+ $requestParams = $this->_getRequestParams(
214
+ $orderId,
215
+ $mfsTransactionId,
216
+ $transactionCode,
217
+ $transactionDescription,
218
+ $transactionStatus
219
+ );
220
+
221
+ $this
222
+ ->order
223
+ ->setId($orderId);
224
+
225
+ $this
226
+ ->order
227
+ ->setIncrementId($orderIncrementId);
228
+
229
+ $this
230
+ ->order
231
+ ->setBaseGrandTotal($orderBaseGrandTotal);
232
+
233
+ $this
234
+ ->order
235
+ ->expects($this->any())
236
+ ->method('loadByIncrementId')
237
+ ->with($orderId)
238
+ ->will($this->returnValue($this->order));
239
+
240
+ $this
241
+ ->order
242
+ ->expects($this->never())
243
+ ->method('cancel');
244
+
245
+ $this
246
+ ->order
247
+ ->expects($this->once())
248
+ ->method('canInvoice')
249
+ ->will($this->returnValue(true));
250
+
251
+ $this
252
+ ->order
253
+ ->expects($this->once())
254
+ ->method('prepareInvoice')
255
+ ->will($this->returnValue($this->invoice));
256
+
257
+ $this
258
+ ->payment
259
+ ->expects($this->once())
260
+ ->method('save');
261
+
262
+ $this
263
+ ->invoice
264
+ ->expects($this->once())
265
+ ->method('setRequestedCaptureCase')
266
+ ->with(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE)
267
+ ->will($this->returnValue($this->invoice));
268
+
269
+ $this
270
+ ->invoice
271
+ ->expects($this->once())
272
+ ->method('register');
273
+
274
+ $this
275
+ ->coreResourceTransaction
276
+ ->expects($this->exactly(2))
277
+ ->method('addObject')
278
+ ->with(
279
+ $this->callback(
280
+ function ($param) {
281
+ $return = false;
282
+ if (
283
+ $param instanceof Mage_Sales_Model_Order ||
284
+ $param instanceof Mage_Sales_Model_Order_Invoice
285
+ ) {
286
+ $return = true;
287
+ }
288
+ return $return;
289
+ }
290
+ )
291
+ )
292
+ ->will($this->returnValue($this->coreResourceTransaction));
293
+
294
+ $this
295
+ ->coreResourceTransaction
296
+ ->expects($this->once())
297
+ ->method('save')
298
+ ->will($this->returnValue($this->coreResourceTransaction));
299
+
300
+ $this
301
+ ->generateAccessTokenResponse
302
+ ->setAccessToken($accessTokenForTransactionStatus);
303
+
304
+ $this
305
+ ->generateAccessTokenResponse
306
+ ->expects($this->any())
307
+ ->method('isSuccess')
308
+ ->will($this->returnValue(true));
309
+
310
+ $this->transactionStatusResponse
311
+ ->setTransactionStatus(Tigo_TigoMoney_Model_Payment_Redirect_Sync::PARAM_VALUE_TRANSACTION_STATUS_SUCCESS);
312
+
313
+ $this->transactionStatusResponse
314
+ ->setTransactionMfsTransactionId($mfsTransactionId);
315
+
316
+ $this->transactionStatusResponse
317
+ ->setLocalPaymentAmount($orderBaseGrandTotal);
318
+
319
+ $this
320
+ ->transactionStatusResponse
321
+ ->expects($this->any())
322
+ ->method('isSuccess')
323
+ ->will($this->returnValue(true));
324
+
325
+ $this
326
+ ->api
327
+ ->expects($this->once())
328
+ ->method('getTransactionStatus')
329
+ ->with(
330
+ $this->callback(
331
+ function (Tigo_TigoMoney_Model_Payment_Redirect_Api_TransactionStatusRequest $request)
332
+ use ($accessTokenForTransactionStatus, $orderIncrementId) {
333
+ $return = false;
334
+ if (
335
+ ($request->getAccessToken() == $accessTokenForTransactionStatus) &&
336
+ ($request->getMerchantTransactionId() == $orderIncrementId)
337
+ ) {
338
+ $return = true;
339
+ }
340
+ return $return;
341
+ }
342
+ )
343
+ )
344
+ ->will($this->returnValue($this->transactionStatusResponse));
345
+
346
+ $return = $this->subject->handleRequest($requestParams);
347
+
348
+ $this->assertEquals(
349
+ $this
350
+ ->payment
351
+ ->getAdditionalInformation(Tigo_TigoMoney_Model_Payment_Redirect::ADDITIONAL_INFO_KEY_MFS_TRANSACTION_ID),
352
+ $mfsTransactionId
353
+ );
354
+
355
+ $this->assertEquals(
356
+ $this
357
+ ->payment
358
+ ->getAdditionalInformation(Tigo_TigoMoney_Model_Payment_Redirect::ADDITIONAL_INFO_KEY_TRANSACTION_CODE),
359
+ $transactionCode
360
+ );
361
+
362
+ $this->assertEquals(
363
+ $this
364
+ ->payment
365
+ ->getAdditionalInformation(Tigo_TigoMoney_Model_Payment_Redirect::ADDITIONAL_INFO_KEY_TRANSACTION_DESCRIPTION),
366
+ $transactionDescription
367
+ );
368
+
369
+ $this->assertEquals(
370
+ $this
371
+ ->payment
372
+ ->getAdditionalInformation(Tigo_TigoMoney_Model_Payment_Redirect::ADDITIONAL_INFO_KEY_TRANSACTION_STATUS),
373
+ $transactionStatus
374
+ );
375
+
376
+ $this->assertTrue($return);
377
+ }
378
+
379
+ public function testHandleRequestDoesRequestTransactionInfoWhenGenerateAccessTokenCallFails()
380
+ {
381
+ $orderId = 233;
382
+ $orderIncrementId = '10000233';
383
+ $mfsTransactionId = '324234234';
384
+ $transactionCode = '09203920394.2930429304.2039402394';
385
+ $transactionDescription = 'Paid';
386
+ $transactionStatus = Tigo_TigoMoney_Model_Payment_Redirect_Sync::PARAM_VALUE_TRANSACTION_STATUS_SUCCESS;
387
+ $accessTokenForTransactionStatus = null;
388
+
389
+ $requestParams = $this->_getRequestParams(
390
+ $orderId,
391
+ $mfsTransactionId,
392
+ $transactionCode,
393
+ $transactionDescription,
394
+ $transactionStatus
395
+ );
396
+
397
+ $this
398
+ ->order
399
+ ->setId($orderId);
400
+
401
+ $this
402
+ ->order
403
+ ->setIncrementId($orderIncrementId);
404
+
405
+ $this
406
+ ->order
407
+ ->expects($this->any())
408
+ ->method('loadByIncrementId')
409
+ ->with($orderId)
410
+ ->will($this->returnValue($this->order));
411
+
412
+ $this
413
+ ->generateAccessTokenResponse
414
+ ->setAccessToken($accessTokenForTransactionStatus);
415
+
416
+ $this
417
+ ->generateAccessTokenResponse
418
+ ->expects($this->any())
419
+ ->method('isSuccess')
420
+ ->will($this->returnValue(false));
421
+
422
+ $this
423
+ ->api
424
+ ->expects($this->never())
425
+ ->method('getTransactionStatus');
426
+
427
+ $this
428
+ ->order
429
+ ->expects($this->never())
430
+ ->method('cancel');
431
+
432
+ $this
433
+ ->order
434
+ ->expects($this->never())
435
+ ->method('canInvoice');
436
+
437
+ $this
438
+ ->order
439
+ ->expects($this->never())
440
+ ->method('prepareInvoice');
441
+
442
+ $this
443
+ ->payment
444
+ ->expects($this->once())
445
+ ->method('save');
446
+
447
+ $this
448
+ ->coreResourceTransaction
449
+ ->expects($this->never())
450
+ ->method('save');
451
+
452
+ $this->assertFalse($this->subject->handleRequest($requestParams));
453
+ }
454
+
455
+ public function testHandleRequestDoesRequestTransactionInfoWhenTransactionStatusCallFails()
456
+ {
457
+ $orderId = 233;
458
+ $orderIncrementId = '10000233';
459
+ $mfsTransactionId = '324234234';
460
+ $transactionCode = '09203920394.2930429304.2039402394';
461
+ $transactionDescription = 'Paid';
462
+ $transactionStatus = Tigo_TigoMoney_Model_Payment_Redirect_Sync::PARAM_VALUE_TRANSACTION_STATUS_SUCCESS;
463
+ $accessTokenForTransactionStatus = null;
464
+
465
+ $requestParams = $this->_getRequestParams(
466
+ $orderId,
467
+ $mfsTransactionId,
468
+ $transactionCode,
469
+ $transactionDescription,
470
+ $transactionStatus
471
+ );
472
+
473
+ $this
474
+ ->order
475
+ ->setId($orderId);
476
+
477
+ $this
478
+ ->order
479
+ ->setIncrementId($orderIncrementId);
480
+
481
+ $this
482
+ ->order
483
+ ->expects($this->any())
484
+ ->method('loadByIncrementId')
485
+ ->with($orderId)
486
+ ->will($this->returnValue($this->order));
487
+
488
+ $this
489
+ ->generateAccessTokenResponse
490
+ ->setAccessToken($accessTokenForTransactionStatus);
491
+
492
+ $this
493
+ ->generateAccessTokenResponse
494
+ ->expects($this->any())
495
+ ->method('isSuccess')
496
+ ->will($this->returnValue(true));
497
+
498
+ $this
499
+ ->api
500
+ ->expects($this->once())
501
+ ->method('getTransactionStatus')
502
+ ->with(
503
+ $this->callback(
504
+ function (Tigo_TigoMoney_Model_Payment_Redirect_Api_TransactionStatusRequest $request)
505
+ use ($accessTokenForTransactionStatus, $orderIncrementId) {
506
+ $return = false;
507
+ if (
508
+ ($request->getAccessToken() == $accessTokenForTransactionStatus) &&
509
+ ($request->getMerchantTransactionId() == $orderIncrementId)
510
+ ) {
511
+ $return = true;
512
+ }
513
+ return $return;
514
+ }
515
+ )
516
+ )
517
+ ->will($this->returnValue($this->transactionStatusResponse));
518
+
519
+ $this
520
+ ->transactionStatusResponse
521
+ ->expects($this->any())
522
+ ->method('isSuccess')
523
+ ->will($this->returnValue(false));
524
+
525
+ $this
526
+ ->order
527
+ ->expects($this->never())
528
+ ->method('cancel');
529
+
530
+ $this
531
+ ->order
532
+ ->expects($this->never())
533
+ ->method('canInvoice');
534
+
535
+ $this
536
+ ->order
537
+ ->expects($this->never())
538
+ ->method('prepareInvoice');
539
+
540
+ $this
541
+ ->payment
542
+ ->expects($this->once())
543
+ ->method('save');
544
+
545
+ $this
546
+ ->coreResourceTransaction
547
+ ->expects($this->never())
548
+ ->method('save');
549
+
550
+ $this->assertFalse($this->subject->handleRequest($requestParams));
551
+ }
552
+
553
+ public function testHandleRequestDoesNotInvoiceOrderWhenRequestDataInvalidDataProvider()
554
+ {
555
+ return array(
556
+ array('234234234', 'success', '8373.93', 'wrong', 'success', '8373.93'),
557
+ array('234234234', 'success', '8373.93', '234234234', 'wrong', '8373.93'),
558
+ array('234234234', 'success', '8373.93', '234234234', 'success', '10000.93'),
559
+ );
560
+ }
561
+
562
+ /**
563
+ * @param $mfsTransactionId
564
+ * @param $transactionStatus
565
+ * @param $orderBaseGrandTotal
566
+ * @param $transactionStatusResponseStatus
567
+ * @param $transactionStatusResponseMfsTransactionIdResponse
568
+ * @param $transactionStatusResponseOrderBaseGrandTotal
569
+ * @dataProvider testHandleRequestDoesNotInvoiceOrderWhenRequestDataInvalidDataProvider
570
+ */
571
+ public function testHandleRequestDoesNotInvoiceOrderWhenRequestDataInvalid(
572
+ $mfsTransactionId,
573
+ $transactionStatus,
574
+ $orderBaseGrandTotal,
575
+ $transactionStatusResponseStatus,
576
+ $transactionStatusResponseMfsTransactionIdResponse,
577
+ $transactionStatusResponseOrderBaseGrandTotal
578
+ )
579
+ {
580
+
581
+ $orderId = 233;
582
+ $orderIncrementId = '10000233';
583
+ $transactionCode = '09203920394.2930429304.2039402394';
584
+ $transactionDescription = 'Paid';
585
+ $accessTokenForTransactionStatus = 'oiusdofiuasodifu';
586
+
587
+ $requestParams = $this->_getRequestParams(
588
+ $orderId,
589
+ $mfsTransactionId,
590
+ $transactionCode,
591
+ $transactionDescription,
592
+ $transactionStatus
593
+ );
594
+
595
+ $this
596
+ ->order
597
+ ->setId($orderId);
598
+
599
+ $this
600
+ ->order
601
+ ->setIncrementId($orderIncrementId);
602
+
603
+ $this
604
+ ->order
605
+ ->setBaseGrandTotal($orderBaseGrandTotal);
606
+
607
+ $this
608
+ ->order
609
+ ->expects($this->any())
610
+ ->method('loadByIncrementId')
611
+ ->with($orderId)
612
+ ->will($this->returnValue($this->order));
613
+
614
+ $this
615
+ ->generateAccessTokenResponse
616
+ ->setAccessToken($accessTokenForTransactionStatus);
617
+
618
+ $this
619
+ ->generateAccessTokenResponse
620
+ ->expects($this->any())
621
+ ->method('isSuccess')
622
+ ->will($this->returnValue(true));
623
+
624
+ $this->transactionStatusResponse
625
+ ->setTransactionStatus($transactionStatusResponseStatus);
626
+
627
+ $this->transactionStatusResponse
628
+ ->setTransactionMfsTransactionId($transactionStatusResponseMfsTransactionIdResponse);
629
+
630
+ $this->transactionStatusResponse
631
+ ->setLocalPaymentAmount($transactionStatusResponseOrderBaseGrandTotal);
632
+
633
+ $this
634
+ ->transactionStatusResponse
635
+ ->expects($this->any())
636
+ ->method('isSuccess')
637
+ ->will($this->returnValue(true));
638
+
639
+ $this
640
+ ->api
641
+ ->expects($this->once())
642
+ ->method('getTransactionStatus')
643
+ ->with(
644
+ $this->callback(
645
+ function (Tigo_TigoMoney_Model_Payment_Redirect_Api_TransactionStatusRequest $request)
646
+ use ($accessTokenForTransactionStatus, $orderIncrementId) {
647
+ $return = false;
648
+ if (
649
+ ($request->getAccessToken() == $accessTokenForTransactionStatus) &&
650
+ ($request->getMerchantTransactionId() == $orderIncrementId)
651
+ ) {
652
+ $return = true;
653
+ }
654
+ return $return;
655
+ }
656
+ )
657
+ )
658
+ ->will($this->returnValue($this->transactionStatusResponse));
659
+
660
+
661
+ $this
662
+ ->order
663
+ ->expects($this->never())
664
+ ->method('cancel');
665
+
666
+ $this
667
+ ->order
668
+ ->expects($this->never())
669
+ ->method('canInvoice');
670
+
671
+ $this
672
+ ->order
673
+ ->expects($this->never())
674
+ ->method('prepareInvoice');
675
+
676
+ $this
677
+ ->payment
678
+ ->expects($this->once())
679
+ ->method('save');
680
+
681
+ $this
682
+ ->coreResourceTransaction
683
+ ->expects($this->never())
684
+ ->method('save');
685
+
686
+ $this->assertFalse($this->subject->handleRequest($requestParams));
687
+ }
688
+
689
+ public function testHandleRequestDoesNotInvoiceOrderWhenOrderCanInvoiceIsFalse()
690
+ {
691
+ $orderId = 233;
692
+ $orderIncrementId = '10000233';
693
+ $orderBaseGrandTotal = 2323.34;
694
+ $mfsTransactionId = '324234234';
695
+ $transactionCode = '09203920394.2930429304.2039402394';
696
+ $transactionDescription = 'Paid';
697
+ $transactionStatus = Tigo_TigoMoney_Model_Payment_Redirect_Sync::PARAM_VALUE_TRANSACTION_STATUS_SUCCESS;
698
+ $accessTokenForTransactionStatus = 'oiusdofiuasodifu';
699
+
700
+ $requestParams = $this->_getRequestParams(
701
+ $orderId,
702
+ $mfsTransactionId,
703
+ $transactionCode,
704
+ $transactionDescription,
705
+ $transactionStatus
706
+ );
707
+
708
+ $this
709
+ ->order
710
+ ->setId($orderId);
711
+
712
+ $this
713
+ ->order
714
+ ->setIncrementId($orderIncrementId);
715
+
716
+ $this
717
+ ->order
718
+ ->setBaseGrandTotal($orderBaseGrandTotal);
719
+
720
+ $this
721
+ ->order
722
+ ->expects($this->any())
723
+ ->method('loadByIncrementId')
724
+ ->with($orderId)
725
+ ->will($this->returnValue($this->order));
726
+
727
+ $this
728
+ ->order
729
+ ->expects($this->never())
730
+ ->method('cancel');
731
+
732
+ $this
733
+ ->order
734
+ ->expects($this->once())
735
+ ->method('canInvoice')
736
+ ->will($this->returnValue(false));
737
+
738
+ $this
739
+ ->order
740
+ ->expects($this->never())
741
+ ->method('prepareInvoice');
742
+
743
+ $this
744
+ ->payment
745
+ ->expects($this->once())
746
+ ->method('save');
747
+
748
+ $this
749
+ ->invoice
750
+ ->expects($this->never())
751
+ ->method('setRequestedCaptureCase');
752
+
753
+ $this
754
+ ->invoice
755
+ ->expects($this->never())
756
+ ->method('register');
757
+
758
+ $this
759
+ ->coreResourceTransaction
760
+ ->expects($this->never())
761
+ ->method('addObject');
762
+
763
+ $this
764
+ ->coreResourceTransaction
765
+ ->expects($this->never())
766
+ ->method('save');
767
+
768
+ $this
769
+ ->generateAccessTokenResponse
770
+ ->setAccessToken($accessTokenForTransactionStatus);
771
+
772
+ $this
773
+ ->generateAccessTokenResponse
774
+ ->expects($this->any())
775
+ ->method('isSuccess')
776
+ ->will($this->returnValue(true));
777
+
778
+ $this->transactionStatusResponse
779
+ ->setTransactionStatus(Tigo_TigoMoney_Model_Payment_Redirect_Sync::PARAM_VALUE_TRANSACTION_STATUS_SUCCESS);
780
+
781
+ $this->transactionStatusResponse
782
+ ->setTransactionMfsTransactionId($mfsTransactionId);
783
+
784
+ $this->transactionStatusResponse
785
+ ->setLocalPaymentAmount($orderBaseGrandTotal);
786
+
787
+ $this
788
+ ->transactionStatusResponse
789
+ ->expects($this->any())
790
+ ->method('isSuccess')
791
+ ->will($this->returnValue(true));
792
+
793
+ $this
794
+ ->api
795
+ ->expects($this->once())
796
+ ->method('getTransactionStatus')
797
+ ->with(
798
+ $this->callback(
799
+ function (Tigo_TigoMoney_Model_Payment_Redirect_Api_TransactionStatusRequest $request)
800
+ use ($accessTokenForTransactionStatus, $orderIncrementId) {
801
+ $return = false;
802
+ if (
803
+ ($request->getAccessToken() == $accessTokenForTransactionStatus) &&
804
+ ($request->getMerchantTransactionId() == $orderIncrementId)
805
+ ) {
806
+ $return = true;
807
+ }
808
+ return $return;
809
+ }
810
+ )
811
+ )
812
+ ->will($this->returnValue($this->transactionStatusResponse));
813
+
814
+ $this->assertTrue(
815
+ $this->subject->handleRequest($requestParams)
816
+ );
817
+ }
818
+
819
+ public function testHandleRequestCancelOrderDataProvider()
820
+ {
821
+ return array(
822
+ array(Tigo_TigoMoney_Model_Payment_Redirect_Sync::PARAM_VALUE_TRANSACTION_STATUS_FAILURE),
823
+ array(Tigo_TigoMoney_Model_Payment_Redirect_Sync::PARAM_VALUE_TRANSACTION_STATUS_CANCEL),
824
+ );
825
+ }
826
+
827
+ /**
828
+ * @param $status
829
+ * @dataProvider testHandleRequestCancelOrderDataProvider
830
+ */
831
+ public function testHandleRequestCancelOrder($status)
832
+ {
833
+ $orderId = 233;
834
+ $orderIncrementId = '10000233';
835
+ $orderBaseGrandTotal = 2323.34;
836
+ $mfsTransactionId = '324234234';
837
+ $transactionCode = '09203920394.2930429304.2039402394';
838
+ $transactionDescription = 'Pending';
839
+ $transactionStatus = $status;
840
+ $accessTokenForTransactionStatus = 'oiusdofiuasodifu';
841
+
842
+ $requestParams = $this->_getRequestParams(
843
+ $orderId,
844
+ $mfsTransactionId,
845
+ $transactionCode,
846
+ $transactionDescription,
847
+ $transactionStatus
848
+ );
849
+
850
+ $this
851
+ ->order
852
+ ->setId($orderId);
853
+
854
+ $this
855
+ ->order
856
+ ->setIncrementId($orderIncrementId);
857
+
858
+ $this
859
+ ->order
860
+ ->setBaseGrandTotal($orderBaseGrandTotal);
861
+
862
+ $this
863
+ ->order
864
+ ->expects($this->any())
865
+ ->method('loadByIncrementId')
866
+ ->with($orderId)
867
+ ->will($this->returnValue($this->order));
868
+
869
+ $this
870
+ ->order
871
+ ->expects($this->once())
872
+ ->method('canCancel')
873
+ ->will($this->returnValue(true));
874
+
875
+ $this
876
+ ->order
877
+ ->expects($this->once())
878
+ ->method('cancel')
879
+ ->will($this->returnValue($this->order));
880
+
881
+ $this
882
+ ->order
883
+ ->expects($this->once())
884
+ ->method('save');
885
+
886
+ $this
887
+ ->order
888
+ ->expects($this->never())
889
+ ->method('canInvoice');
890
+
891
+ $this
892
+ ->order
893
+ ->expects($this->never())
894
+ ->method('prepareInvoice');
895
+
896
+ $this
897
+ ->payment
898
+ ->expects($this->once())
899
+ ->method('save');
900
+
901
+ $this
902
+ ->invoice
903
+ ->expects($this->never())
904
+ ->method('setRequestedCaptureCase');
905
+
906
+ $this
907
+ ->invoice
908
+ ->expects($this->never())
909
+ ->method('register');
910
+
911
+ $this
912
+ ->coreResourceTransaction
913
+ ->expects($this->never())
914
+ ->method('addObject');
915
+
916
+ $this
917
+ ->coreResourceTransaction
918
+ ->expects($this->never())
919
+ ->method('save');
920
+
921
+ $this
922
+ ->generateAccessTokenResponse
923
+ ->setAccessToken($accessTokenForTransactionStatus);
924
+
925
+ $this
926
+ ->generateAccessTokenResponse
927
+ ->expects($this->any())
928
+ ->method('isSuccess')
929
+ ->will($this->returnValue(true));
930
+
931
+ $this->transactionStatusResponse
932
+ ->setTransactionStatus(Tigo_TigoMoney_Model_Payment_Redirect_Sync::PARAM_VALUE_TRANSACTION_STATUS_FAILURE);
933
+
934
+ $this->transactionStatusResponse
935
+ ->setTransactionMfsTransactionId($mfsTransactionId);
936
+
937
+ $this->transactionStatusResponse
938
+ ->setLocalPaymentAmount($orderBaseGrandTotal);
939
+
940
+ $this
941
+ ->transactionStatusResponse
942
+ ->expects($this->any())
943
+ ->method('isSuccess')
944
+ ->will($this->returnValue(true));
945
+
946
+ $this
947
+ ->api
948
+ ->expects($this->once())
949
+ ->method('getTransactionStatus')
950
+ ->with(
951
+ $this->callback(
952
+ function (Tigo_TigoMoney_Model_Payment_Redirect_Api_TransactionStatusRequest $request)
953
+ use ($accessTokenForTransactionStatus, $orderIncrementId) {
954
+ $return = false;
955
+ if (
956
+ ($request->getAccessToken() == $accessTokenForTransactionStatus) &&
957
+ ($request->getMerchantTransactionId() == $orderIncrementId)
958
+ ) {
959
+ $return = true;
960
+ }
961
+ return $return;
962
+ }
963
+ )
964
+ )
965
+ ->will($this->returnValue($this->transactionStatusResponse));
966
+
967
+ $return = $this->subject->handleRequest($requestParams);
968
+
969
+ $this->assertEquals(
970
+ $this
971
+ ->payment
972
+ ->getAdditionalInformation(Tigo_TigoMoney_Model_Payment_Redirect::ADDITIONAL_INFO_KEY_MFS_TRANSACTION_ID),
973
+ $mfsTransactionId
974
+ );
975
+
976
+ $this->assertEquals(
977
+ $this
978
+ ->payment
979
+ ->getAdditionalInformation(Tigo_TigoMoney_Model_Payment_Redirect::ADDITIONAL_INFO_KEY_TRANSACTION_CODE),
980
+ $transactionCode
981
+ );
982
+
983
+ $this->assertEquals(
984
+ $this
985
+ ->payment
986
+ ->getAdditionalInformation(Tigo_TigoMoney_Model_Payment_Redirect::ADDITIONAL_INFO_KEY_TRANSACTION_DESCRIPTION),
987
+ $transactionDescription
988
+ );
989
+
990
+ $this->assertEquals(
991
+ $this
992
+ ->payment
993
+ ->getAdditionalInformation(Tigo_TigoMoney_Model_Payment_Redirect::ADDITIONAL_INFO_KEY_TRANSACTION_STATUS),
994
+ $transactionStatus
995
+ );
996
+
997
+ $this->assertFalse($return);
998
+ }
999
+
1000
+ public function testHandleRequestDoesNotCancelOrderWhenRequestDataInvalidDataProvider()
1001
+ {
1002
+ return array(
1003
+ array('234234234', 'failure', '8373.93', 'wrong', 'failure', '8373.93'),
1004
+ array('234234234', 'failure', '8373.93', '234234234', 'initiated', '8373.93'),
1005
+ array('234234234', 'failure', '8373.93', '234234234', 'failure', '10000.93'),
1006
+ );
1007
+ }
1008
+
1009
+ /**
1010
+ * @param $mfsTransactionId
1011
+ * @param $transactionStatus
1012
+ * @param $orderBaseGrandTotal
1013
+ * @param $transactionStatusResponseStatus
1014
+ * @param $transactionStatusResponseMfsTransactionIdResponse
1015
+ * @param $transactionStatusResponseOrderBaseGrandTotal
1016
+ * @dataProvider testHandleRequestDoesNotCancelOrderWhenRequestDataInvalidDataProvider
1017
+ */
1018
+ public function testHandleRequestDoesNotCancelOrderWhenRequestDataInvalid(
1019
+ $mfsTransactionId,
1020
+ $transactionStatus,
1021
+ $orderBaseGrandTotal,
1022
+ $transactionStatusResponseStatus,
1023
+ $transactionStatusResponseMfsTransactionIdResponse,
1024
+ $transactionStatusResponseOrderBaseGrandTotal
1025
+ )
1026
+ {
1027
+ $orderId = 233;
1028
+ $orderIncrementId = '10000233';
1029
+ $transactionCode = '09203920394.2930429304.2039402394';
1030
+ $transactionDescription = 'Pending';
1031
+ $accessTokenForTransactionStatus = 'oiusdofiuasodifu';
1032
+
1033
+ $requestParams = $this->_getRequestParams(
1034
+ $orderId,
1035
+ $mfsTransactionId,
1036
+ $transactionCode,
1037
+ $transactionDescription,
1038
+ $transactionStatus
1039
+ );
1040
+
1041
+ $this
1042
+ ->order
1043
+ ->setId($orderId);
1044
+
1045
+ $this
1046
+ ->order
1047
+ ->setIncrementId($orderIncrementId);
1048
+
1049
+ $this
1050
+ ->order
1051
+ ->setBaseGrandTotal($orderBaseGrandTotal);
1052
+
1053
+ $this
1054
+ ->order
1055
+ ->expects($this->any())
1056
+ ->method('loadByIncrementId')
1057
+ ->with($orderId)
1058
+ ->will($this->returnValue($this->order));
1059
+
1060
+ $this
1061
+ ->order
1062
+ ->expects($this->never())
1063
+ ->method('canCancel')
1064
+ ->will($this->returnValue(true));
1065
+
1066
+ $this
1067
+ ->order
1068
+ ->expects($this->never())
1069
+ ->method('cancel')
1070
+ ->will($this->returnValue($this->order));
1071
+
1072
+ $this
1073
+ ->order
1074
+ ->expects($this->never())
1075
+ ->method('save');
1076
+
1077
+ $this
1078
+ ->order
1079
+ ->expects($this->never())
1080
+ ->method('canInvoice');
1081
+
1082
+ $this
1083
+ ->order
1084
+ ->expects($this->never())
1085
+ ->method('prepareInvoice');
1086
+
1087
+ $this
1088
+ ->payment
1089
+ ->expects($this->once())
1090
+ ->method('save');
1091
+
1092
+ $this
1093
+ ->invoice
1094
+ ->expects($this->never())
1095
+ ->method('setRequestedCaptureCase');
1096
+
1097
+ $this
1098
+ ->invoice
1099
+ ->expects($this->never())
1100
+ ->method('register');
1101
+
1102
+ $this
1103
+ ->coreResourceTransaction
1104
+ ->expects($this->never())
1105
+ ->method('addObject');
1106
+
1107
+ $this
1108
+ ->coreResourceTransaction
1109
+ ->expects($this->never())
1110
+ ->method('save');
1111
+
1112
+ $this
1113
+ ->generateAccessTokenResponse
1114
+ ->setAccessToken($accessTokenForTransactionStatus);
1115
+
1116
+ $this
1117
+ ->generateAccessTokenResponse
1118
+ ->expects($this->any())
1119
+ ->method('isSuccess')
1120
+ ->will($this->returnValue(true));
1121
+
1122
+ $this->transactionStatusResponse
1123
+ ->setTransactionStatus($transactionStatusResponseStatus);
1124
+
1125
+ $this->transactionStatusResponse
1126
+ ->setTransactionMfsTransactionId($transactionStatusResponseMfsTransactionIdResponse);
1127
+
1128
+ $this->transactionStatusResponse
1129
+ ->setLocalPaymentAmount($transactionStatusResponseOrderBaseGrandTotal);
1130
+
1131
+ $this
1132
+ ->transactionStatusResponse
1133
+ ->expects($this->any())
1134
+ ->method('isSuccess')
1135
+ ->will($this->returnValue(true));
1136
+
1137
+ $this
1138
+ ->api
1139
+ ->expects($this->once())
1140
+ ->method('getTransactionStatus')
1141
+ ->with(
1142
+ $this->callback(
1143
+ function (Tigo_TigoMoney_Model_Payment_Redirect_Api_TransactionStatusRequest $request)
1144
+ use ($accessTokenForTransactionStatus, $orderIncrementId) {
1145
+ $return = false;
1146
+ if (
1147
+ ($request->getAccessToken() == $accessTokenForTransactionStatus) &&
1148
+ ($request->getMerchantTransactionId() == $orderIncrementId)
1149
+ ) {
1150
+ $return = true;
1151
+ }
1152
+ return $return;
1153
+ }
1154
+ )
1155
+ )
1156
+ ->will($this->returnValue($this->transactionStatusResponse));
1157
+
1158
+ $this->subject->handleRequest($requestParams);
1159
+ }
1160
+
1161
+ public function testHandleRequestCancelOrderDoesNotCancelWhenGenerateTokenRequestFails()
1162
+ {
1163
+ $orderId = 233;
1164
+ $orderIncrementId = '10000233';
1165
+ $orderBaseGrandTotal = 2323.34;
1166
+ $mfsTransactionId = '324234234';
1167
+ $transactionCode = '09203920394.2930429304.2039402394';
1168
+ $transactionDescription = 'Pending';
1169
+ $transactionStatus = Tigo_TigoMoney_Model_Payment_Redirect_Sync::PARAM_VALUE_TRANSACTION_STATUS_FAILURE;
1170
+ $accessTokenForTransactionStatus = 'oiusdofiuasodifu';
1171
+
1172
+ $requestParams = $this->_getRequestParams(
1173
+ $orderId,
1174
+ $mfsTransactionId,
1175
+ $transactionCode,
1176
+ $transactionDescription,
1177
+ $transactionStatus
1178
+ );
1179
+
1180
+ $this
1181
+ ->order
1182
+ ->setId($orderId);
1183
+
1184
+ $this
1185
+ ->order
1186
+ ->setIncrementId($orderIncrementId);
1187
+
1188
+ $this
1189
+ ->order
1190
+ ->setBaseGrandTotal($orderBaseGrandTotal);
1191
+
1192
+ $this
1193
+ ->order
1194
+ ->expects($this->any())
1195
+ ->method('loadByIncrementId')
1196
+ ->with($orderId)
1197
+ ->will($this->returnValue($this->order));
1198
+
1199
+ $this
1200
+ ->order
1201
+ ->expects($this->never())
1202
+ ->method('canCancel')
1203
+ ->will($this->returnValue(true));
1204
+
1205
+ $this
1206
+ ->order
1207
+ ->expects($this->never())
1208
+ ->method('cancel')
1209
+ ->will($this->returnValue($this->order));
1210
+
1211
+ $this
1212
+ ->order
1213
+ ->expects($this->never())
1214
+ ->method('save');
1215
+
1216
+ $this
1217
+ ->order
1218
+ ->expects($this->never())
1219
+ ->method('canInvoice');
1220
+
1221
+ $this
1222
+ ->order
1223
+ ->expects($this->never())
1224
+ ->method('prepareInvoice');
1225
+
1226
+ $this
1227
+ ->payment
1228
+ ->expects($this->once())
1229
+ ->method('save');
1230
+
1231
+ $this
1232
+ ->invoice
1233
+ ->expects($this->never())
1234
+ ->method('setRequestedCaptureCase');
1235
+
1236
+ $this
1237
+ ->invoice
1238
+ ->expects($this->never())
1239
+ ->method('register');
1240
+
1241
+ $this
1242
+ ->coreResourceTransaction
1243
+ ->expects($this->never())
1244
+ ->method('addObject');
1245
+
1246
+ $this
1247
+ ->coreResourceTransaction
1248
+ ->expects($this->never())
1249
+ ->method('save');
1250
+
1251
+ $this
1252
+ ->generateAccessTokenResponse
1253
+ ->setAccessToken($accessTokenForTransactionStatus);
1254
+
1255
+ $this
1256
+ ->generateAccessTokenResponse
1257
+ ->expects($this->any())
1258
+ ->method('isSuccess')
1259
+ ->will($this->returnValue(false));
1260
+
1261
+ $this
1262
+ ->transactionStatusResponse
1263
+ ->expects($this->never())
1264
+ ->method('isSuccess');
1265
+
1266
+ $this
1267
+ ->api
1268
+ ->expects($this->never())
1269
+ ->method('getTransactionStatus');
1270
+
1271
+ $this->subject->handleRequest($requestParams);
1272
+ }
1273
+
1274
+ public function testHandleRequestCancelOrderDoesNotCancelWhenTransactionStatusRequestFails()
1275
+ {
1276
+ $orderId = 233;
1277
+ $orderIncrementId = '10000233';
1278
+ $orderBaseGrandTotal = 2323.34;
1279
+ $mfsTransactionId = '324234234';
1280
+ $transactionCode = '09203920394.2930429304.2039402394';
1281
+ $transactionDescription = 'Pending';
1282
+ $transactionStatus = Tigo_TigoMoney_Model_Payment_Redirect_Sync::PARAM_VALUE_TRANSACTION_STATUS_FAILURE;
1283
+ $accessTokenForTransactionStatus = 'oiusdofiuasodifu';
1284
+
1285
+ $requestParams = $this->_getRequestParams(
1286
+ $orderId,
1287
+ $mfsTransactionId,
1288
+ $transactionCode,
1289
+ $transactionDescription,
1290
+ $transactionStatus
1291
+ );
1292
+
1293
+ $this
1294
+ ->order
1295
+ ->setId($orderId);
1296
+
1297
+ $this
1298
+ ->order
1299
+ ->setIncrementId($orderIncrementId);
1300
+
1301
+ $this
1302
+ ->order
1303
+ ->setBaseGrandTotal($orderBaseGrandTotal);
1304
+
1305
+ $this
1306
+ ->order
1307
+ ->expects($this->any())
1308
+ ->method('loadByIncrementId')
1309
+ ->with($orderId)
1310
+ ->will($this->returnValue($this->order));
1311
+
1312
+ $this
1313
+ ->order
1314
+ ->expects($this->never())
1315
+ ->method('canCancel')
1316
+ ->will($this->returnValue(true));
1317
+
1318
+ $this
1319
+ ->order
1320
+ ->expects($this->never())
1321
+ ->method('cancel')
1322
+ ->will($this->returnValue($this->order));
1323
+
1324
+ $this
1325
+ ->order
1326
+ ->expects($this->never())
1327
+ ->method('save');
1328
+
1329
+ $this
1330
+ ->order
1331
+ ->expects($this->never())
1332
+ ->method('canInvoice');
1333
+
1334
+ $this
1335
+ ->order
1336
+ ->expects($this->never())
1337
+ ->method('prepareInvoice');
1338
+
1339
+ $this
1340
+ ->payment
1341
+ ->expects($this->once())
1342
+ ->method('save');
1343
+
1344
+ $this
1345
+ ->invoice
1346
+ ->expects($this->never())
1347
+ ->method('setRequestedCaptureCase');
1348
+
1349
+ $this
1350
+ ->invoice
1351
+ ->expects($this->never())
1352
+ ->method('register');
1353
+
1354
+ $this
1355
+ ->coreResourceTransaction
1356
+ ->expects($this->never())
1357
+ ->method('addObject');
1358
+
1359
+ $this
1360
+ ->coreResourceTransaction
1361
+ ->expects($this->never())
1362
+ ->method('save');
1363
+
1364
+ $this
1365
+ ->generateAccessTokenResponse
1366
+ ->setAccessToken($accessTokenForTransactionStatus);
1367
+
1368
+ $this
1369
+ ->generateAccessTokenResponse
1370
+ ->expects($this->any())
1371
+ ->method('isSuccess')
1372
+ ->will($this->returnValue(true));
1373
+
1374
+ $this
1375
+ ->transactionStatusResponse
1376
+ ->expects($this->any())
1377
+ ->method('isSuccess')
1378
+ ->will($this->returnValue(false));
1379
+
1380
+ $this
1381
+ ->api
1382
+ ->expects($this->once())
1383
+ ->method('getTransactionStatus')
1384
+ ->with(
1385
+ $this->callback(
1386
+ function (Tigo_TigoMoney_Model_Payment_Redirect_Api_TransactionStatusRequest $request)
1387
+ use ($accessTokenForTransactionStatus, $orderIncrementId) {
1388
+ $return = false;
1389
+ if (
1390
+ ($request->getAccessToken() == $accessTokenForTransactionStatus) &&
1391
+ ($request->getMerchantTransactionId() == $orderIncrementId)
1392
+ ) {
1393
+ $return = true;
1394
+ }
1395
+ return $return;
1396
+ }
1397
+ )
1398
+ )
1399
+ ->will($this->returnValue($this->transactionStatusResponse));
1400
+
1401
+ $this->subject->handleRequest($requestParams);
1402
+ }
1403
+
1404
+ public function testSyncOrderCreatesInvoiceWhenTransactionStatusSuccess()
1405
+ {
1406
+ $accessToken = 'maslkmsdalkfmsdf';
1407
+
1408
+ /**
1409
+ * Invoice and cancel methods have been extensively tested in the previos methods
1410
+ * We'll skip them to keep this test simpler
1411
+ */
1412
+ /** @var Tigo_TigoMoney_Model_Payment_Redirect_Sync|PHPUnit_Framework_MockObject_MockObject $subject */
1413
+ $subject = $this
1414
+ ->getMockBuilder($this->className)
1415
+ ->setMethods(array('_createInvoice', '_cancelOrder'))
1416
+ ->getMock();
1417
+
1418
+ $this
1419
+ ->generateAccessTokenResponse
1420
+ ->setAccessToken($accessToken);
1421
+
1422
+ $this
1423
+ ->api
1424
+ ->expects($this->once())
1425
+ ->method('getAccessToken')
1426
+ ->will($this->returnValue($this->generateAccessTokenResponse));
1427
+
1428
+ $this
1429
+ ->generateAccessTokenResponse
1430
+ ->expects($this->once())
1431
+ ->method('isSuccess')
1432
+ ->will($this->returnValue(true));
1433
+
1434
+ $this
1435
+ ->transactionStatusResponse
1436
+ ->setTransactionStatus(Tigo_TigoMoney_Model_Payment_Redirect_Sync::PARAM_VALUE_TRANSACTION_STATUS_SUCCESS);
1437
+
1438
+ $this
1439
+ ->api
1440
+ ->expects($this->once())
1441
+ ->method('getTransactionStatus')
1442
+ ->will($this->returnValue($this->transactionStatusResponse));
1443
+
1444
+ $this
1445
+ ->transactionStatusResponse
1446
+ ->expects($this->once())
1447
+ ->method('isSuccess')
1448
+ ->will($this->returnValue(true));
1449
+
1450
+ $subject
1451
+ ->expects($this->once())
1452
+ ->method('_createInvoice')
1453
+ ->with($this->order);
1454
+
1455
+ $subject->syncOrder($this->order);
1456
+ }
1457
+
1458
+ public function testSyncOrderCancelsOrderWhenTransactionStatusFailure()
1459
+ {
1460
+ $accessToken = 'maslkmsdalkfmsdf';
1461
+
1462
+ /**
1463
+ * Invoice and cancel methods have been extensively tested in the previous methods
1464
+ * We'll skip them to keep this test simpler
1465
+ */
1466
+ /** @var Tigo_TigoMoney_Model_Payment_Redirect_Sync|PHPUnit_Framework_MockObject_MockObject $subject */
1467
+ $subject = $this
1468
+ ->getMockBuilder($this->className)
1469
+ ->setMethods(array('_createInvoice', '_cancelOrder'))
1470
+ ->getMock();
1471
+
1472
+ $this
1473
+ ->generateAccessTokenResponse
1474
+ ->setAccessToken($accessToken);
1475
+
1476
+ $this
1477
+ ->api
1478
+ ->expects($this->once())
1479
+ ->method('getAccessToken')
1480
+ ->will($this->returnValue($this->generateAccessTokenResponse));
1481
+
1482
+ $this
1483
+ ->generateAccessTokenResponse
1484
+ ->expects($this->once())
1485
+ ->method('isSuccess')
1486
+ ->will($this->returnValue(true));
1487
+
1488
+ $this
1489
+ ->transactionStatusResponse
1490
+ ->setTransactionStatus(Tigo_TigoMoney_Model_Payment_Redirect_Sync::PARAM_VALUE_TRANSACTION_STATUS_FAILURE);
1491
+
1492
+ $this
1493
+ ->api
1494
+ ->expects($this->once())
1495
+ ->method('getTransactionStatus')
1496
+ ->will($this->returnValue($this->transactionStatusResponse));
1497
+
1498
+ $this
1499
+ ->transactionStatusResponse
1500
+ ->expects($this->once())
1501
+ ->method('isSuccess')
1502
+ ->will($this->returnValue(true));
1503
+
1504
+ $subject
1505
+ ->expects($this->once())
1506
+ ->method('_cancelOrder')
1507
+ ->with($this->order);
1508
+
1509
+ $subject->syncOrder($this->order);
1510
+ }
1511
+
1512
+ public function testSyncOrderCancelsOrderWhenTransactionStatusCancel()
1513
+ {
1514
+ $accessToken = 'maslkmsdalkfmsdf';
1515
+
1516
+ /**
1517
+ * Invoice and cancel methods have been extensively tested in the previos methods
1518
+ * We'll skip them to keep this test simpler
1519
+ */
1520
+ /** @var Tigo_TigoMoney_Model_Payment_Redirect_Sync|PHPUnit_Framework_MockObject_MockObject $subject */
1521
+ $subject = $this
1522
+ ->getMockBuilder($this->className)
1523
+ ->setMethods(array('_createInvoice', '_cancelOrder'))
1524
+ ->getMock();
1525
+
1526
+ $this
1527
+ ->generateAccessTokenResponse
1528
+ ->setAccessToken($accessToken);
1529
+
1530
+ $this
1531
+ ->api
1532
+ ->expects($this->once())
1533
+ ->method('getAccessToken')
1534
+ ->will($this->returnValue($this->generateAccessTokenResponse));
1535
+
1536
+ $this
1537
+ ->generateAccessTokenResponse
1538
+ ->expects($this->once())
1539
+ ->method('isSuccess')
1540
+ ->will($this->returnValue(true));
1541
+
1542
+ $this
1543
+ ->transactionStatusResponse
1544
+ ->setTransactionStatus(Tigo_TigoMoney_Model_Payment_Redirect_Sync::PARAM_VALUE_TRANSACTION_STATUS_CANCEL);
1545
+
1546
+ $this
1547
+ ->api
1548
+ ->expects($this->once())
1549
+ ->method('getTransactionStatus')
1550
+ ->will($this->returnValue($this->transactionStatusResponse));
1551
+
1552
+ $this
1553
+ ->transactionStatusResponse
1554
+ ->expects($this->once())
1555
+ ->method('isSuccess')
1556
+ ->will($this->returnValue(true));
1557
+
1558
+ $subject
1559
+ ->expects($this->once())
1560
+ ->method('_cancelOrder')
1561
+ ->with($this->order);
1562
+
1563
+ $subject->syncOrder($this->order);
1564
+ }
1565
+
1566
+ public function testSyncOrderCancelsOnlyInitiatedOrdersWhenOlderThanFiveDaysDataProvider()
1567
+ {
1568
+ $dateSixDaysAgo = date('Y-m-d h:i:s', time() - (6 * 24 * 60 * 60));
1569
+ $dateSevenDaysAgo = date('Y-m-d h:i:s', time() - (7 * 24 * 60 * 60));
1570
+ return array(
1571
+ array($dateSixDaysAgo, true),
1572
+ array($dateSevenDaysAgo, true),
1573
+ );
1574
+ }
1575
+
1576
+ /**
1577
+ * @param string $orderDate
1578
+ * @param boolean $canCancelOrder
1579
+ * @dataProvider testSyncOrderCancelsOnlyInitiatedOrdersWhenOlderThanFiveDaysDataProvider
1580
+ */
1581
+ public function testSyncOrderCancelsInitiatedOrdersOlderThanFiveDays(
1582
+ $orderDate,
1583
+ $canCancelOrder
1584
+ ) {
1585
+ $accessToken = 'maslkmsdalkfmsdf';
1586
+
1587
+ /**
1588
+ * Invoice and cancel methods have been extensively tested in the previous methods
1589
+ * We'll skip them to keep this test simpler
1590
+ */
1591
+ /** @var Tigo_TigoMoney_Model_Payment_Redirect_Sync|PHPUnit_Framework_MockObject_MockObject $subject */
1592
+ $subject = $this
1593
+ ->getMockBuilder($this->className)
1594
+ ->setMethods(array('_createInvoice', '_cancelOrder'))
1595
+ ->getMock();
1596
+
1597
+ $this
1598
+ ->generateAccessTokenResponse
1599
+ ->setAccessToken($accessToken);
1600
+
1601
+ $this
1602
+ ->api
1603
+ ->expects($this->once())
1604
+ ->method('getAccessToken')
1605
+ ->will($this->returnValue($this->generateAccessTokenResponse));
1606
+
1607
+ $this
1608
+ ->generateAccessTokenResponse
1609
+ ->expects($this->once())
1610
+ ->method('isSuccess')
1611
+ ->will($this->returnValue(true));
1612
+
1613
+ $this
1614
+ ->transactionStatusResponse
1615
+ ->setTransactionStatus(Tigo_TigoMoney_Model_Payment_Redirect_Sync::PARAM_VALUE_TRANSACTION_STATUS_INITIATED);
1616
+
1617
+ $this
1618
+ ->api
1619
+ ->expects($this->once())
1620
+ ->method('getTransactionStatus')
1621
+ ->will($this->returnValue($this->transactionStatusResponse));
1622
+
1623
+ $this
1624
+ ->transactionStatusResponse
1625
+ ->expects($this->once())
1626
+ ->method('isSuccess')
1627
+ ->will($this->returnValue(true));
1628
+
1629
+ $subject
1630
+ ->expects($this->once())
1631
+ ->method('_cancelOrder')
1632
+ ->with($this->order);
1633
+
1634
+ $this
1635
+ ->order
1636
+ ->expects($this->any())
1637
+ ->method('canCancel')
1638
+ ->will($this->returnValue($canCancelOrder));
1639
+
1640
+ $this
1641
+ ->order
1642
+ ->setCreatedAt($orderDate);
1643
+
1644
+ $subject->syncOrder($this->order);
1645
+ }
1646
+
1647
+ public function testSyncOrderDoesNotCancelInitiatedOrdersNoOlderThanFiveDaysOrCanCancelEqualsFalseDataProvider()
1648
+ {
1649
+ $dateTwoDaysAgo = date('Y-m-d h:i:s', time() - (2 * 24 * 60 * 60));
1650
+ $dateThreeDaysAgo = date('Y-m-d h:i:s', time() - (3 * 24 * 60 * 60));
1651
+ $dateSixDaysAgo = date('Y-m-d h:i:s', time() - (6 * 24 * 60 * 60));
1652
+ $dateSevenDaysAgo = date('Y-m-d h:i:s', time() - (7 * 24 * 60 * 60));
1653
+ return array(
1654
+ array($dateTwoDaysAgo, true),
1655
+ array($dateThreeDaysAgo, true),
1656
+ array($dateSixDaysAgo, false),
1657
+ array($dateSevenDaysAgo, false),
1658
+ );
1659
+ }
1660
+
1661
+ /**
1662
+ * @param string $orderDate
1663
+ * @param boolean $canCancelOrder
1664
+ * @dataProvider testSyncOrderDoesNotCancelInitiatedOrdersNoOlderThanFiveDaysOrCanCancelEqualsFalseDataProvider
1665
+ */
1666
+ public function testSyncOrderDoesNotCancelInitiatedOrdersNoOlderThanFiveDaysOrCanCancelEqualsFalse(
1667
+ $orderDate,
1668
+ $canCancelOrder
1669
+ ) {
1670
+ $accessToken = 'maslkmsdalkfmsdf';
1671
+
1672
+ /**
1673
+ * Invoice and cancel methods have been extensively tested in the previous methods
1674
+ * We'll skip them to keep this test simpler
1675
+ */
1676
+ /** @var Tigo_TigoMoney_Model_Payment_Redirect_Sync|PHPUnit_Framework_MockObject_MockObject $subject */
1677
+ $subject = $this
1678
+ ->getMockBuilder($this->className)
1679
+ ->setMethods(array('_createInvoice'))
1680
+ ->getMock();
1681
+
1682
+ $this
1683
+ ->generateAccessTokenResponse
1684
+ ->setAccessToken($accessToken);
1685
+
1686
+ $this
1687
+ ->api
1688
+ ->expects($this->once())
1689
+ ->method('getAccessToken')
1690
+ ->will($this->returnValue($this->generateAccessTokenResponse));
1691
+
1692
+ $this
1693
+ ->generateAccessTokenResponse
1694
+ ->expects($this->once())
1695
+ ->method('isSuccess')
1696
+ ->will($this->returnValue(true));
1697
+
1698
+ $this
1699
+ ->transactionStatusResponse
1700
+ ->setTransactionStatus(Tigo_TigoMoney_Model_Payment_Redirect_Sync::PARAM_VALUE_TRANSACTION_STATUS_INITIATED);
1701
+
1702
+ $this
1703
+ ->api
1704
+ ->expects($this->once())
1705
+ ->method('getTransactionStatus')
1706
+ ->will($this->returnValue($this->transactionStatusResponse));
1707
+
1708
+ $this
1709
+ ->transactionStatusResponse
1710
+ ->expects($this->once())
1711
+ ->method('isSuccess')
1712
+ ->will($this->returnValue(true));
1713
+
1714
+ $this
1715
+ ->order
1716
+ ->expects($this->any())
1717
+ ->method('canCancel')
1718
+ ->will($this->returnValue($canCancelOrder));
1719
+
1720
+ $this
1721
+ ->order
1722
+ ->expects($this->never())
1723
+ ->method('cancel')
1724
+ ->will($this->returnValue($canCancelOrder));
1725
+
1726
+ $this
1727
+ ->order
1728
+ ->setCreatedAt($orderDate);
1729
+
1730
+ $subject->syncOrder($this->order);
1731
+ }
1732
+
1733
+ public function testSyncOrderThrowsExceptionWhenGenerateAccessTokenRequestFails()
1734
+ {
1735
+ $accessToken = 'maslkmsdalkfmsdf';
1736
+
1737
+ /**
1738
+ * Invoice and cancel methods have been extensively tested in the previos methods
1739
+ * We'll skip them to keep this test simpler
1740
+ */
1741
+ /** @var Tigo_TigoMoney_Model_Payment_Redirect_Sync|PHPUnit_Framework_MockObject_MockObject $subject */
1742
+ $subject = $this
1743
+ ->getMockBuilder($this->className)
1744
+ ->setMethods(array('_createInvoice', '_cancelOrder'))
1745
+ ->getMock();
1746
+
1747
+ $this
1748
+ ->generateAccessTokenResponse
1749
+ ->setAccessToken($accessToken);
1750
+
1751
+ $this
1752
+ ->api
1753
+ ->expects($this->once())
1754
+ ->method('getAccessToken')
1755
+ ->will($this->returnValue($this->generateAccessTokenResponse));
1756
+
1757
+ $this
1758
+ ->generateAccessTokenResponse
1759
+ ->expects($this->once())
1760
+ ->method('isSuccess')
1761
+ ->will($this->returnValue(false));
1762
+
1763
+ $this
1764
+ ->api
1765
+ ->expects($this->never())
1766
+ ->method('getTransactionStatus');
1767
+
1768
+ $this
1769
+ ->transactionStatusResponse
1770
+ ->expects($this->never())
1771
+ ->method('isSuccess');
1772
+
1773
+ $subject
1774
+ ->expects($this->never())
1775
+ ->method('_cancelOrder');
1776
+
1777
+ $subject
1778
+ ->expects($this->never())
1779
+ ->method('_createInvoice');
1780
+
1781
+ $this->setExpectedException('Mage_Core_Exception');
1782
+
1783
+ $subject->syncOrder($this->order);
1784
+ }
1785
+
1786
+ public function testSyncOrderThrowsExceptionWhenTransactionStatusRequestFails()
1787
+ {
1788
+ $accessToken = 'maslkmsdalkfmsdf';
1789
+ $orderIncrementId = '200003982';
1790
+
1791
+ /**
1792
+ * Invoice and cancel methods have been extensively tested in the previos methods
1793
+ * We'll skip them to keep this test simpler
1794
+ */
1795
+ /** @var Tigo_TigoMoney_Model_Payment_Redirect_Sync|PHPUnit_Framework_MockObject_MockObject $subject */
1796
+ $subject = $this
1797
+ ->getMockBuilder($this->className)
1798
+ ->setMethods(array('_createInvoice', '_cancelOrder'))
1799
+ ->getMock();
1800
+
1801
+ $this
1802
+ ->order
1803
+ ->setIncrementId($orderIncrementId);
1804
+
1805
+ $this
1806
+ ->generateAccessTokenResponse
1807
+ ->setAccessToken($accessToken);
1808
+
1809
+ $this
1810
+ ->api
1811
+ ->expects($this->once())
1812
+ ->method('getAccessToken')
1813
+ ->will($this->returnValue($this->generateAccessTokenResponse));
1814
+
1815
+ $this
1816
+ ->generateAccessTokenResponse
1817
+ ->expects($this->once())
1818
+ ->method('isSuccess')
1819
+ ->will($this->returnValue(true));
1820
+
1821
+ $this
1822
+ ->transactionStatusResponse
1823
+ ->expects($this->once())
1824
+ ->method('isSuccess')
1825
+ ->will($this->returnValue(false));
1826
+
1827
+ $this
1828
+ ->api
1829
+ ->expects($this->once())
1830
+ ->method('getTransactionStatus')
1831
+ ->with(
1832
+ $this->callback(
1833
+ function (Tigo_TigoMoney_Model_Payment_Redirect_Api_TransactionStatusRequest $request)
1834
+ use ($accessToken, $orderIncrementId) {
1835
+ $return = false;
1836
+ if (
1837
+ ($request->getAccessToken() == $accessToken) &&
1838
+ ($request->getMerchantTransactionId() == $orderIncrementId)
1839
+ ) {
1840
+ $return = true;
1841
+ }
1842
+ return $return;
1843
+ }
1844
+ )
1845
+ )
1846
+ ->will($this->returnValue($this->transactionStatusResponse));
1847
+
1848
+ $subject
1849
+ ->expects($this->never())
1850
+ ->method('_cancelOrder');
1851
+
1852
+ $subject
1853
+ ->expects($this->never())
1854
+ ->method('_createInvoice');
1855
+
1856
+ $this->setExpectedException('Mage_Core_Exception');
1857
+
1858
+ $subject->syncOrder($this->order);
1859
+ }
1860
+
1861
+ public function testExtractRequestIgnoresUndefinedParameters()
1862
+ {
1863
+ $orderId = null;
1864
+ $orderIncrementId = '10000233';
1865
+ $mfsTransactionId = '324234234';
1866
+ $transactionCode = 'undefined';
1867
+ $transactionDescription = 'undefined';
1868
+ $transactionStatus = Tigo_TigoMoney_Model_Payment_Redirect_Sync::PARAM_VALUE_TRANSACTION_STATUS_FAILURE;
1869
+
1870
+ $requestParams = $this->_getRequestParams(
1871
+ $orderIncrementId,
1872
+ $mfsTransactionId,
1873
+ $transactionCode,
1874
+ $transactionDescription,
1875
+ $transactionStatus
1876
+ );
1877
+
1878
+ $expectedRequestAfterParsing = new Varien_Object();
1879
+ $expectedRequestAfterParsing
1880
+ ->setData(Tigo_TigoMoney_Model_Payment_Redirect_Sync::PARAM_KEY_MERCHANT_TRANSACTION_ID, $orderIncrementId)
1881
+ ->setData(Tigo_TigoMoney_Model_Payment_Redirect_Sync::PARAM_KEY_MFS_TRANSACTION_ID, $mfsTransactionId)
1882
+ ->setData(Tigo_TigoMoney_Model_Payment_Redirect_Sync::PARAM_KEY_TRANSACTION_STATUS , $transactionStatus);
1883
+
1884
+ $subject = $this
1885
+ ->getMockBuilder($this->className)
1886
+ ->setMethods(array('_loadRequestOrder'))
1887
+ ->getMock();
1888
+
1889
+ $subject
1890
+ ->expects($this->once())
1891
+ ->method('_loadRequestOrder')
1892
+ ->with($expectedRequestAfterParsing)
1893
+ ->will($this->returnValue($this->order));
1894
+
1895
+ $subject->handleRequest($requestParams);
1896
+ }
1897
+ }
1898
+
app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Model/Payment/RedirectTest.php ADDED
@@ -0,0 +1,875 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Tigo_TigoMoney_Model_Payment_RedirectTest
5
+ */
6
+ class Tigo_TigoMoney_Model_Payment_RedirectTest extends EcomDev_PHPUnit_Test_Case
7
+ {
8
+ /**
9
+ * @var Tigo_TigoMoney_Model_Payment_Redirect_Api_AuthorizationResponse|PHPUnit_Framework_MockObject_MockObject
10
+ */
11
+ protected $authorizationResponse = null;
12
+
13
+ /**
14
+ * @var Tigo_TigoMoney_Model_Payment_Redirect_Api_AuthorizationRequest|PHPUnit_Framework_MockObject_MockObject
15
+ */
16
+ protected $authorizationRequest = null;
17
+
18
+ /**
19
+ * @var Tigo_TigoMoney_Model_Payment_Redirect_Api|PHPUnit_Framework_MockObject_MockObject
20
+ */
21
+ protected $api = null;
22
+
23
+ /**
24
+ * @var String
25
+ */
26
+ protected $className = null;
27
+
28
+ /**
29
+ * @var Tigo_TigoMoney_Helper_Data|PHPUnit_Framework_MockObject_MockObject
30
+ */
31
+ protected $dataHelper = null;
32
+
33
+ /**
34
+ * @var Tigo_TigoMoney_Model_Payment_Redirect_Api_GenerateTokenRequest|PHPUnit_Framework_MockObject_MockObject
35
+ */
36
+ protected $generateTokenRequest = null;
37
+
38
+ /**
39
+ * @var Tigo_TigoMoney_Model_Payment_Redirect_Api_GenerateTokenResponse|PHPUnit_Framework_MockObject_MockObject
40
+ */
41
+ protected $generateTokenResponse = null;
42
+
43
+ /**
44
+ * @var Mage_Sales_Model_Order|PHPUnit_Framework_MockObject_MockObject
45
+ */
46
+ protected $order = null;
47
+
48
+ /**
49
+ * @var Mage_Sales_Model_Order_Payment|PHPUnit_Framework_MockObject_MockObject
50
+ */
51
+ protected $payment = null;
52
+
53
+ /**
54
+ * @var Mage_Payment_Model_Info|PHPUnit_Framework_MockObject_MockObject
55
+ */
56
+ protected $paymentInfo = null;
57
+
58
+ /**
59
+ * @var Tigo_TigoMoney_Model_Payment_Redirect_Api_RequestBuilder|PHPUnit_Framework_MockObject_MockObject
60
+ */
61
+ protected $requestBuilder = null;
62
+
63
+ /**
64
+ * @var Tigo_TigoMoney_Model_Payment_Redirect_Api_ReverseTransactionResponse|PHPUnit_Framework_MockObject_MockObject
65
+ */
66
+ protected $reverseTransactionRequest = null;
67
+
68
+ /**
69
+ * @var Tigo_TigoMoney_Model_Payment_Redirect_Api_ReverseTransactionResponse|PHPUnit_Framework_MockObject_MockObject
70
+ */
71
+ protected $reverseTransactionResponse = null;
72
+
73
+ /**
74
+ * @var Tigo_TigoMoney_Model_Payment_Redirect|PHPUnit_Framework_MockObject_MockObject
75
+ */
76
+ protected $subject = null;
77
+
78
+ /**
79
+ * Sets up the unit test case
80
+ */
81
+ protected function setUp()
82
+ {
83
+ $this->className = Tigo_TigoMoney_Model_Payment_Redirect::class;
84
+
85
+ $this->subject = $this
86
+ ->getModelMock(
87
+ 'tigo_tigomoney/payment_redirect',
88
+ array('nonExistentMethod')
89
+ );
90
+
91
+ $this->paymentInfo = $this
92
+ ->getModelMock(
93
+ 'payment/info',
94
+ array('nonExistentMethod')
95
+ );
96
+ $this
97
+ ->subject
98
+ ->setInfoInstance($this->paymentInfo);
99
+
100
+ $this->dataHelper = $this
101
+ ->getHelperMock(
102
+ 'tigo_tigomoney/data',
103
+ array('nonExistentMethod')
104
+ );
105
+ $this->replaceByMock(
106
+ 'helper',
107
+ 'tigo_tigomoney/data',
108
+ $this->dataHelper
109
+ );
110
+ $this->replaceByMock(
111
+ 'helper',
112
+ 'tigo_tigomoney',
113
+ $this->dataHelper
114
+ );
115
+
116
+ $this->payment = $this
117
+ ->getModelMock(
118
+ 'sales/order_payment',
119
+ array(
120
+ 'save',
121
+ 'getOrder',
122
+ 'setAmount',
123
+ 'setStatus',
124
+ 'setIsTransactionPending',
125
+ 'setIsTransactionClosed',
126
+ 'setTransactionId',
127
+ 'addTransaction'
128
+ )
129
+ );
130
+ $this->order = $this
131
+ ->getModelMock(
132
+ 'sales/order',
133
+ array('save', 'getPayment')
134
+ );
135
+ $this->payment
136
+ ->expects($this->any())
137
+ ->method('getOrder')
138
+ ->will($this->returnValue($this->order));
139
+ $this->order
140
+ ->expects($this->any())
141
+ ->method('getPayment')
142
+ ->will($this->returnValue($this->payment));
143
+
144
+ $this->generateTokenResponse = $this
145
+ ->getModelMock(
146
+ 'tigo_tigomoney/payment_redirect_api_generateTokenResponse',
147
+ array('isSuccess'),
148
+ false,
149
+ array(new Varien_Object())
150
+ );
151
+ $this->replaceByMock(
152
+ 'model',
153
+ 'tigo_tigomoney/payment_redirect_api_generateTokenResponse',
154
+ $this->generateTokenResponse
155
+ );
156
+
157
+ $this->authorizationResponse = $this
158
+ ->getModelMock(
159
+ 'tigo_tigomoney/payment_redirect_api_authorizationResponse',
160
+ array('isSuccess'),
161
+ false,
162
+ array(new Varien_Object())
163
+ );
164
+ $this->replaceByMock(
165
+ 'model',
166
+ 'tigo_tigomoney/payment_redirect_api_authorizationResponse',
167
+ $this->authorizationResponse
168
+ );
169
+
170
+ $this->reverseTransactionResponse = $this
171
+ ->getModelMock(
172
+ 'tigo_tigomoney/payment_redirect_api_reverseTransactionResponse',
173
+ array('isSuccess'),
174
+ false,
175
+ array(new Varien_Object())
176
+ );
177
+ $this->replaceByMock(
178
+ 'model',
179
+ 'tigo_tigomoney/payment_redirect_api_reverseTransactionResponse',
180
+ $this->reverseTransactionResponse
181
+ );
182
+
183
+ $this->generateTokenRequest = $this
184
+ ->getModelMock(
185
+ 'tigo_tigomoney/payment_redirect_api_generateTokenRequest',
186
+ array('nonExistentMethod')
187
+ );
188
+ $this->replaceByMock(
189
+ 'model',
190
+ 'tigo_tigomoney/payment_redirect_api_generateTokenRequest',
191
+ $this->generateTokenRequest
192
+ );
193
+
194
+ $this->authorizationRequest = $this
195
+ ->getModelMock(
196
+ 'tigo_tigomoney/payment_redirect_api_authorizationRequest',
197
+ array('nonExistentMethod')
198
+ );
199
+ $this->replaceByMock(
200
+ 'model',
201
+ 'tigo_tigomoney/payment_redirect_api_authorizationRequest',
202
+ $this->authorizationRequest
203
+ );
204
+
205
+ $this->reverseTransactionRequest = $this
206
+ ->getModelMock(
207
+ 'tigo_tigomoney/payment_redirect_api_reverseTransactionRequest',
208
+ array('nonExistentMethod')
209
+ );
210
+ $this->replaceByMock(
211
+ 'model',
212
+ 'tigo_tigomoney/payment_redirect_api_reverseTransactionRequest',
213
+ $this->reverseTransactionRequest
214
+ );
215
+
216
+ $this->requestBuilder = $this
217
+ ->getModelMock(
218
+ 'tigo_tigomoney/payment_redirect_api_requestBuilder',
219
+ array('buildAuthorizationRequest', 'buildReverseTransactionRequest', 'buildGenerateAccessTokenRequest')
220
+ );
221
+ $this->replaceByMock(
222
+ 'model',
223
+ 'tigo_tigomoney/payment_redirect_api_requestBuilder',
224
+ $this->requestBuilder
225
+ );
226
+
227
+ $this->api = $this
228
+ ->getModelMock(
229
+ 'tigo_tigomoney/payment_redirect_api',
230
+ array('getAccessToken', 'getRedirectUri', 'reverseTransaction')
231
+ );
232
+ $this->api
233
+ ->expects($this->any())
234
+ ->method('getAccessToken')
235
+ ->will($this->returnValue($this->generateTokenResponse));
236
+ $this->api
237
+ ->expects($this->any())
238
+ ->method('getRedirectUri')
239
+ ->will($this->returnValue($this->authorizationResponse));
240
+ $this->api
241
+ ->expects($this->any())
242
+ ->method('reverseTransaction')
243
+ ->will($this->returnValue($this->reverseTransactionResponse));
244
+ $this->replaceByMock(
245
+ 'model',
246
+ 'tigo_tigomoney/payment_redirect_api',
247
+ $this->api
248
+ );
249
+ }
250
+
251
+ public function testMethodCodeValue()
252
+ {
253
+ $expectedMethodCode = 'tigo_tigomoney';
254
+ $this
255
+ ->assertEquals(
256
+ $this->subject->getCode(),
257
+ $expectedMethodCode
258
+ );
259
+ }
260
+
261
+ public function testAssignData()
262
+ {
263
+ $phoneNumber = '748372837';
264
+ $phoneNumberDataKey = Tigo_TigoMoney_Model_Payment_Redirect::METHOD_CODE . '_phone_number';
265
+ $phoneNumberAdditionalInfoKey = Tigo_TigoMoney_Model_Payment_Redirect::ADDITIONAL_INFO_KEY_PHONE_NUMBER;
266
+ $data = array(
267
+ 'method' => Tigo_TigoMoney_Model_Payment_Redirect::METHOD_CODE,
268
+ $phoneNumberDataKey => $phoneNumber
269
+ );
270
+ $dataObj = new Varien_Object($data);
271
+
272
+ $this->subject
273
+ ->assignData(
274
+ $dataObj
275
+ );
276
+
277
+ $this->assertEquals(
278
+ $phoneNumber,
279
+ $this->paymentInfo->getAdditionalInformation($phoneNumberAdditionalInfoKey)
280
+ );
281
+ }
282
+
283
+ public function testAssignDataNonTigoMoney()
284
+ {
285
+ $phoneNumber = '748372837';
286
+ $phoneNumberDataKey = Tigo_TigoMoney_Model_Payment_Redirect::METHOD_CODE . '_phone_number';
287
+ $phoneNumberAdditionalInfoKey = Tigo_TigoMoney_Model_Payment_Redirect::ADDITIONAL_INFO_KEY_PHONE_NUMBER;
288
+ $data = array(
289
+ 'method' => 'checkmo',
290
+ $phoneNumberDataKey => $phoneNumber
291
+ );
292
+ $dataObj = new Varien_Object($data);
293
+
294
+ $this->subject
295
+ ->assignData(
296
+ $dataObj
297
+ );
298
+
299
+ $this->assertNull(
300
+ $this->paymentInfo->getAdditionalInformation($phoneNumberAdditionalInfoKey)
301
+ );
302
+ }
303
+
304
+ public function testAssignDataWorksWithArrays()
305
+ {
306
+ $phoneNumber = '748372837';
307
+ $phoneNumberDataKey = Tigo_TigoMoney_Model_Payment_Redirect::METHOD_CODE . '_phone_number';
308
+ $phoneNumberAdditionalInfoKey = Tigo_TigoMoney_Model_Payment_Redirect::ADDITIONAL_INFO_KEY_PHONE_NUMBER;
309
+ $data = array(
310
+ 'method' => 'checkmo',
311
+ $phoneNumberDataKey => $phoneNumber
312
+ );
313
+
314
+ $this->subject
315
+ ->assignData(
316
+ $data
317
+ );
318
+
319
+ $this->assertNull(
320
+ $this->paymentInfo->getAdditionalInformation($phoneNumberAdditionalInfoKey)
321
+ );
322
+ }
323
+
324
+ public function testGetOrderPlaceUrl()
325
+ {
326
+ $expectedUrl = $this->getModelMock(
327
+ 'core/url',
328
+ array('nonExistendMethod')
329
+ )
330
+ ->getUrl('tigomoney/redirect/index', array('_secure' => true));
331
+ $this
332
+ ->assertEquals(
333
+ $expectedUrl,
334
+ $this->subject->getOrderPlaceRedirectUrl()
335
+ );
336
+ }
337
+
338
+ public function testIsActiveDataProvider()
339
+ {
340
+ return array(
341
+ array('123123', 'asdfasdf', '123123321', '2321', true),
342
+ array(null, 'asdfasdf', '123123321', '2321', false),
343
+ array('123123', null, '123123321', '2321', false),
344
+ array('123123', 'asdfasdf', null, '2321', false),
345
+ array('123123', 'asdfasdf', '123123321', null, false),
346
+ );
347
+ }
348
+
349
+ /**
350
+ * @param $clientId
351
+ * @param $clientSecret
352
+ * @param $merchantAccount
353
+ * @param $merchantPin
354
+ * @param $clientId
355
+ * @param $shouldBeActive
356
+ * @dataProvider testIsActiveDataProvider
357
+ * @loadFixtures default
358
+ */
359
+ public function testIsActive(
360
+ $clientId,
361
+ $clientSecret,
362
+ $merchantAccount,
363
+ $merchantPin,
364
+ $shouldBeActive
365
+ ) {
366
+ $this->subject = $this
367
+ ->getMockBuilder($this->className)
368
+ ->setMethods(array('_getDataHelper', 'getConfigData'))
369
+ ->getMock();
370
+
371
+ $this
372
+ ->subject
373
+ ->expects($this->any())
374
+ ->method('getConfigData')
375
+ ->will($this->returnValue(true));
376
+
377
+ $dataHelper = $this
378
+ ->getHelperMock('tigo_tigomoney/data');
379
+
380
+ $this
381
+ ->subject
382
+ ->expects($this->any())
383
+ ->method('_getDataHelper')
384
+ ->will($this->returnValue($dataHelper));
385
+ $dataHelper
386
+ ->expects($this->any())
387
+ ->method('getClientId')
388
+ ->will($this->returnValue($clientId));
389
+ $dataHelper
390
+ ->expects($this->any())
391
+ ->method('getClientSecret')
392
+ ->will($this->returnValue($clientSecret));
393
+ $dataHelper
394
+ ->expects($this->any())
395
+ ->method('getMerchantAccount')
396
+ ->will($this->returnValue($merchantAccount));
397
+ $dataHelper
398
+ ->expects($this->any())
399
+ ->method('getMerchantPin')
400
+ ->will($this->returnValue($merchantPin));
401
+
402
+ $this
403
+ ->assertEquals(
404
+ $shouldBeActive,
405
+ $this->subject->isAvailable()
406
+ );
407
+ }
408
+
409
+ public function testCapture() {
410
+ $transactionId = '123123123';
411
+ $amount = 837.93;
412
+
413
+ /** @var Mage_Sales_Model_Order_Payment $payment */
414
+ $payment = $this->getMockBuilder(Mage_Sales_Model_Order_Payment::class)
415
+ ->setMethods(array('save'))
416
+ ->getMock();
417
+
418
+ $payment->setTransactionId($transactionId);
419
+
420
+ $this
421
+ ->subject
422
+ ->capture($payment, $amount);
423
+
424
+ $this
425
+ ->assertEquals(
426
+ $amount,
427
+ $payment->getAmount()
428
+ );
429
+
430
+ $this
431
+ ->assertEquals(
432
+ Tigo_TigoMoney_Model_Payment_Redirect::STATUS_SUCCESS,
433
+ $payment->getStatus()
434
+ );
435
+
436
+ $this
437
+ ->assertEquals(
438
+ $transactionId,
439
+ $payment->getTransactionId()
440
+ );
441
+
442
+ $this
443
+ ->assertTrue(
444
+ $payment->getIsTransactionClosed()
445
+ );
446
+ }
447
+
448
+ /**
449
+ * @loadFixture authorize
450
+ */
451
+ public function testAuthorizeSuccess()
452
+ {
453
+ $amount = 1883.38;
454
+ $authCode = '94949';
455
+ $accessToken = 'kmdkmdkmd';
456
+ $redirectUrl = 'http://google.com/redirect';
457
+
458
+ $this
459
+ ->generateTokenResponse
460
+ ->expects($this->once())
461
+ ->method('isSuccess')
462
+ ->will($this->returnValue(true));
463
+
464
+ $this
465
+ ->generateTokenResponse
466
+ ->setAccessToken($accessToken);
467
+
468
+ $this
469
+ ->requestBuilder
470
+ ->expects($this->once())
471
+ ->method('buildGenerateAccessTokenRequest')
472
+ ->will($this->returnValue($this->generateTokenRequest));
473
+
474
+ $this
475
+ ->requestBuilder
476
+ ->expects($this->once())
477
+ ->method('buildAuthorizationRequest')
478
+ ->with($accessToken, $this->order)
479
+ ->will($this->returnValue($this->authorizationRequest));
480
+
481
+ $this
482
+ ->authorizationResponse
483
+ ->expects($this->once())
484
+ ->method('isSuccess')
485
+ ->will($this->returnValue(true));
486
+
487
+ $this
488
+ ->authorizationResponse
489
+ ->setAuthCode($authCode);
490
+
491
+ $this
492
+ ->authorizationResponse
493
+ ->setRedirectUri($redirectUrl);
494
+
495
+ $this
496
+ ->api
497
+ ->expects($this->once())
498
+ ->method('getAccessToken')
499
+ ->with($this->generateTokenRequest)
500
+ ->will($this->returnValue($this->generateTokenResponse));
501
+
502
+ $this
503
+ ->api
504
+ ->expects($this->once())
505
+ ->method('getRedirectUri')
506
+ ->with($this->authorizationRequest)
507
+ ->will($this->returnValue($this->authorizationResponse));
508
+
509
+ $this
510
+ ->payment
511
+ ->expects($this->once())
512
+ ->method('setAmount')
513
+ ->with($amount)
514
+ ->will($this->returnValue($this->payment));
515
+
516
+ $this
517
+ ->payment
518
+ ->expects($this->once())
519
+ ->method('setStatus')
520
+ ->with(Tigo_TigoMoney_Model_Payment_Redirect::STATUS_APPROVED)
521
+ ->will($this->returnValue($this->payment));
522
+
523
+ $this
524
+ ->payment
525
+ ->expects($this->once())
526
+ ->method('setIsTransactionPending')
527
+ ->with(false)
528
+ ->will($this->returnValue($this->payment));
529
+
530
+ $this
531
+ ->payment
532
+ ->expects($this->once())
533
+ ->method('setIsTransactionClosed')
534
+ ->with(false)
535
+ ->will($this->returnValue($this->payment));
536
+
537
+ $this
538
+ ->payment
539
+ ->expects($this->once())
540
+ ->method('setTransactionId')
541
+ ->with($authCode)
542
+ ->will($this->returnValue($this->payment));
543
+
544
+ $this
545
+ ->payment
546
+ ->expects($this->once())
547
+ ->method('save')
548
+ ->will($this->returnValue($this->payment));
549
+
550
+
551
+ $this->assertEquals(
552
+ $this->subject,
553
+ $this->subject->authorize($this->payment, $amount)
554
+ );
555
+
556
+ $this
557
+ ->assertEquals(
558
+ $accessToken,
559
+ $this->payment->getAdditionalInformation(Tigo_TigoMoney_Model_Payment_Redirect::ADDITIONAL_INFO_KEY_ACCESS_TOKEN)
560
+ );
561
+
562
+ $this
563
+ ->assertEquals(
564
+ $redirectUrl,
565
+ $this->payment->getAdditionalInformation(Tigo_TigoMoney_Model_Payment_Redirect::ADDITIONAL_INFO_KEY_REDIRECT_URI)
566
+ );
567
+
568
+ $this
569
+ ->assertEquals(
570
+ $authCode,
571
+ $this->payment->getAdditionalInformation(Tigo_TigoMoney_Model_Payment_Redirect::ADDITIONAL_INFO_KEY_AUTH_CODE)
572
+ );
573
+ }
574
+
575
+ /**
576
+ * @loadFixture authorize
577
+ */
578
+ public function testAuthorizeAddsAuthorizationErrorsToPaymentOnAuthError()
579
+ {
580
+ $amount = 1883.38;
581
+ $accessToken = 'kmdkmdkmd';
582
+
583
+ $this
584
+ ->requestBuilder
585
+ ->expects($this->once())
586
+ ->method('buildGenerateAccessTokenRequest')
587
+ ->will($this->returnValue($this->generateTokenRequest));
588
+
589
+ $this
590
+ ->requestBuilder
591
+ ->expects($this->once())
592
+ ->method('buildAuthorizationRequest')
593
+ ->with($accessToken, $this->order)
594
+ ->will($this->returnValue($this->authorizationRequest));
595
+
596
+ $this
597
+ ->generateTokenResponse
598
+ ->expects($this->once())
599
+ ->method('isSuccess')
600
+ ->will($this->returnValue(true));
601
+
602
+ $this
603
+ ->generateTokenResponse
604
+ ->setAccessToken($accessToken);
605
+
606
+ $this
607
+ ->authorizationResponse
608
+ ->expects($this->once())
609
+ ->method('isSuccess')
610
+ ->will($this->returnValue(false));
611
+
612
+ $this
613
+ ->authorizationResponse
614
+ ->addError('Error 1');
615
+
616
+ $this
617
+ ->authorizationResponse
618
+ ->addError('Error 2');
619
+
620
+ $this
621
+ ->api
622
+ ->expects($this->once())
623
+ ->method('getRedirectUri')
624
+ ->will($this->returnValue($this->authorizationResponse));
625
+
626
+ $this
627
+ ->setExpectedException('Mage_Core_Exception');
628
+
629
+ $this->assertEquals(
630
+ $this->subject,
631
+ $this->subject->authorize($this->payment, $amount)
632
+ );
633
+
634
+ $this
635
+ ->assertEquals(
636
+ "Error 1\n Error 2",
637
+ $this->payment->getAdditionalInformation(Tigo_TigoMoney_Model_Payment_Redirect::ADDITIONAL_INFO_KEY_AUTHORIZATION_ERRORS)
638
+ );
639
+ }
640
+
641
+ /**
642
+ * @loadFixture authorize
643
+ */
644
+ public function testAuthorizeAddsAccessTokenErrorsToPaymentOnAccessTokenError()
645
+ {
646
+ $amount = 1883.38;
647
+
648
+ $this
649
+ ->requestBuilder
650
+ ->expects($this->once())
651
+ ->method('buildGenerateAccessTokenRequest')
652
+ ->will($this->returnValue($this->generateTokenRequest));
653
+
654
+ $this
655
+ ->generateTokenResponse
656
+ ->expects($this->once())
657
+ ->method('isSuccess')
658
+ ->will($this->returnValue(false));
659
+
660
+ $this
661
+ ->requestBuilder
662
+ ->expects($this->never())
663
+ ->method('buildAuthorizationRequest');
664
+
665
+ $this
666
+ ->api
667
+ ->expects($this->never())
668
+ ->method('getRedirectUri');
669
+
670
+ $this
671
+ ->generateTokenResponse
672
+ ->addError('Error 1');
673
+
674
+ $this
675
+ ->generateTokenResponse
676
+ ->addError('Error 2');
677
+
678
+ $this
679
+ ->generateTokenResponse
680
+ ->addError('Error 3');
681
+
682
+ $this
683
+ ->setExpectedException('Mage_Core_Exception');
684
+
685
+ $this->assertEquals(
686
+ $this->subject,
687
+ $this->subject->authorize($this->payment, $amount)
688
+ );
689
+
690
+ $this
691
+ ->assertEquals(
692
+ "Error 1\nError 2\nError 3",
693
+ $this->payment->getAdditionalInformation(Tigo_TigoMoney_Model_Payment_Redirect::ADDITIONAL_INFO_KEY_ACCESS_TOKEN_ERRORS)
694
+ );
695
+ }
696
+
697
+ /**
698
+ * @loadFixture refund
699
+ */
700
+ public function testRefundSuccess()
701
+ {
702
+ $amount = 783.38;
703
+ $accessToken = 'nininini';
704
+ $mfsReverseTransactionId = '838383';
705
+
706
+ $this
707
+ ->requestBuilder
708
+ ->expects($this->once())
709
+ ->method('buildGenerateAccessTokenRequest')
710
+ ->will($this->returnValue($this->generateTokenRequest));
711
+
712
+ $this
713
+ ->generateTokenResponse
714
+ ->expects($this->once())
715
+ ->method('isSuccess')
716
+ ->will($this->returnValue(true));
717
+
718
+ $this
719
+ ->generateTokenResponse
720
+ ->setAccessToken($accessToken);
721
+
722
+ $this
723
+ ->reverseTransactionResponse
724
+ ->expects($this->once())
725
+ ->method('isSuccess')
726
+ ->will($this->returnValue(true));
727
+
728
+ $this
729
+ ->reverseTransactionResponse
730
+ ->setTransactionMfsReverseTransactionId($mfsReverseTransactionId);
731
+
732
+
733
+ $this
734
+ ->requestBuilder
735
+ ->expects($this->once())
736
+ ->method('buildGenerateAccessTokenRequest')
737
+ ->will($this->returnValue($this->generateTokenResponse));
738
+
739
+ $this
740
+ ->requestBuilder
741
+ ->expects($this->once())
742
+ ->method('buildReverseTransactionRequest')
743
+ ->with($accessToken, $this->order)
744
+ ->will($this->returnValue($this->reverseTransactionRequest));
745
+
746
+ $this
747
+ ->api
748
+ ->expects($this->once())
749
+ ->method('reverseTransaction')
750
+ ->will($this->returnValue($this->reverseTransactionResponse));
751
+
752
+ $this
753
+ ->payment
754
+ ->expects($this->once())
755
+ ->method('setTransactionId')
756
+ ->with($mfsReverseTransactionId)
757
+ ->will($this->returnValue($this->payment));
758
+
759
+ $this
760
+ ->payment
761
+ ->expects($this->once())
762
+ ->method('addTransaction')
763
+ ->with(Mage_Sales_Model_Order_Payment_Transaction::TYPE_REFUND)
764
+ ->will($this->returnValue($this->payment));
765
+
766
+ $this->assertEquals(
767
+ $this->subject,
768
+ $this->subject->refund($this->payment, $amount)
769
+ );
770
+ }
771
+
772
+ /**
773
+ * @loadFixture refund
774
+ */
775
+ public function testRefundThrowsExceptionOnReverseError()
776
+ {
777
+ $amount = 783.38;
778
+ $accessToken = 'nininini';
779
+
780
+ $this
781
+ ->requestBuilder
782
+ ->expects($this->once())
783
+ ->method('buildGenerateAccessTokenRequest')
784
+ ->will($this->returnValue($this->generateTokenRequest));
785
+
786
+ $this
787
+ ->generateTokenResponse
788
+ ->expects($this->once())
789
+ ->method('isSuccess')
790
+ ->will($this->returnValue(true));
791
+
792
+ $this
793
+ ->generateTokenResponse
794
+ ->setAccessToken($accessToken);
795
+
796
+ $this
797
+ ->reverseTransactionResponse
798
+ ->expects($this->once())
799
+ ->method('isSuccess')
800
+ ->will($this->returnValue(false));
801
+
802
+
803
+ $this
804
+ ->requestBuilder
805
+ ->expects($this->once())
806
+ ->method('buildGenerateAccessTokenRequest')
807
+ ->will($this->returnValue($this->generateTokenResponse));
808
+
809
+ $this
810
+ ->requestBuilder
811
+ ->expects($this->once())
812
+ ->method('buildReverseTransactionRequest')
813
+ ->with($accessToken, $this->order)
814
+ ->will($this->returnValue($this->reverseTransactionRequest));
815
+
816
+ $this
817
+ ->api
818
+ ->expects($this->once())
819
+ ->method('reverseTransaction')
820
+ ->will($this->returnValue($this->reverseTransactionResponse));
821
+
822
+ $this
823
+ ->setExpectedException('Mage_Core_Exception');
824
+
825
+ $this->assertEquals(
826
+ $this->subject,
827
+ $this->subject->refund($this->payment, $amount)
828
+ );
829
+ }
830
+
831
+ /**
832
+ * @loadFixture refund
833
+ */
834
+ public function testRefundThrowsExceptionOnAccessTokenError()
835
+ {
836
+ $amount = 783.38;
837
+
838
+ $this
839
+ ->requestBuilder
840
+ ->expects($this->once())
841
+ ->method('buildGenerateAccessTokenRequest')
842
+ ->will($this->returnValue($this->generateTokenRequest));
843
+
844
+ $this
845
+ ->generateTokenResponse
846
+ ->expects($this->once())
847
+ ->method('isSuccess')
848
+ ->will($this->returnValue(false));
849
+
850
+ $this
851
+ ->requestBuilder
852
+ ->expects($this->once())
853
+ ->method('buildGenerateAccessTokenRequest')
854
+ ->will($this->returnValue($this->generateTokenResponse));
855
+
856
+ $this
857
+ ->requestBuilder
858
+ ->expects($this->never())
859
+ ->method('buildReverseTransactionRequest');
860
+
861
+ $this
862
+ ->api
863
+ ->expects($this->never())
864
+ ->method('reverseTransaction');
865
+
866
+ $this
867
+ ->setExpectedException('Mage_Core_Exception');
868
+
869
+ $this->assertEquals(
870
+ $this->subject,
871
+ $this->subject->refund($this->payment, $amount)
872
+ );
873
+ }
874
+ }
875
+
app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Model/Payment/RedirectTest/fixtures/authorize.yaml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ config:
2
+ default/web/seo/use_rewrites: 1
3
+ default/payment/tigo_tigomoney/client_id: 123
4
+ default/payment/tigo_tigomoney/client_secret: asdf123fdsa
5
+ default/payment/tigo_tigomoney/merchant_account: zaq1xsw2cde3
6
+ default/payment/tigo_tigomoney/merchant_id: 98098098
7
+ default/payment/tigo_tigomoney/merchant_pin: 6464646737373
8
+ default/payment/tigo_tigomoney/merchant_reference: Amazon
9
+ default/payment/tigo_tigomoney/test_mode: 1
10
+ default/payment/tigo_tigomoney/debug_mode: 1
app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Model/Payment/RedirectTest/fixtures/default.yaml ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ config:
2
+ default/web/seo/use_rewrites: 1
3
+ default/payment/tigo_tigomoney/active: 1
app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/Model/Payment/RedirectTest/fixtures/refund.yaml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ config:
2
+ default/web/seo/use_rewrites: 1
3
+ default/payment/tigo_tigomoney/client_id: 123
4
+ default/payment/tigo_tigomoney/client_secret: asdf123fdsa
5
+ default/payment/tigo_tigomoney/merchant_account: zaq1xsw2cde3
6
+ default/payment/tigo_tigomoney/merchant_id: 98098098
7
+ default/payment/tigo_tigomoney/merchant_pin: 6464646737373
8
+ default/payment/tigo_tigomoney/merchant_reference: Amazon
9
+ default/payment/tigo_tigomoney/test_mode: 1
10
+ default/payment/tigo_tigomoney/debug_mode: 1
app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/controllers/Adminhtml/Tigomoney/OrderControllerTest.php ADDED
@@ -0,0 +1,173 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Tigo_TigoMoney_Adminhtml_Tigomoney_OrderControllerTest
5
+ */
6
+ class Tigo_TigoMoney_Adminhtml_Tigomoney_OrderControllerTest extends EcomDev_PHPUnit_Test_Case_Controller
7
+ {
8
+ /**
9
+ * @var Mage_Adminhtml_Model_Session|PHPUnit_Framework_MockObject_MockObject
10
+ */
11
+ protected $adminhtmlSession = null;
12
+
13
+ /**
14
+ * @var Mage_Sales_Model_Order|PHPUnit_Framework_MockObject_MockObject
15
+ */
16
+ protected $order = null;
17
+
18
+ /**
19
+ * @var Tigo_TigoMoney_Model_Payment_Redirect_Sync|PHPUnit_Framework_MockObject_MockObject
20
+ */
21
+ protected $sync = null;
22
+
23
+ /**
24
+ * Sets up the unit test case
25
+ */
26
+ protected function setUp()
27
+ {
28
+ parent::setUp();
29
+
30
+ $this->mockAdminUserSession();
31
+
32
+ $this->adminhtmlSession = $this
33
+ ->getMockBuilder(Mage_Adminhtml_Model_Session::class)
34
+ ->setMethods(array('addError'))
35
+ ->getMock();
36
+ $this->replaceByMock('singleton', 'adminhtml/session', $this->adminhtmlSession);
37
+
38
+ $this->sync = $this
39
+ ->getMockBuilder(Tigo_TigoMoney_Model_Payment_Redirect_Sync::class)
40
+ ->setMethods(array('syncOrder'))
41
+ ->getMock();
42
+ $this->replaceByMock('model', 'tigo_tigomoney/payment_redirect_sync', $this->sync);
43
+
44
+ $this->order = $this
45
+ ->getMockBuilder(Mage_Sales_Model_Order::class)
46
+ ->setMethods(array('getId'))
47
+ ->getMock();
48
+
49
+ $this->replaceByMock('model', 'sales/order', $this->order);
50
+
51
+ }
52
+
53
+ /**
54
+ * @loadFixture default
55
+ */
56
+ public function testSyncActionAddsErrorRedirectsToOrderViewOnNoOrderSpecified()
57
+ {
58
+ $params = array();
59
+ $referer = $this->getUrlModel('adminhtml/sales_order/view', $params)->getUrl('adminhtml/sales_order/view');
60
+ $this->getRequest()->setMethod('GET');
61
+ $this->getRequest()->setParam(Mage_Core_Controller_Varien_Action::PARAM_NAME_REFERER_URL, $referer);
62
+
63
+ $this
64
+ ->order
65
+ ->expects($this->once())
66
+ ->method('getId')
67
+ ->will($this->returnValue(null));
68
+
69
+ $this
70
+ ->adminhtmlSession
71
+ ->expects($this->once())
72
+ ->method('addError');
73
+
74
+ $this->dispatch('adminhtml/tigomoney_order/sync');
75
+
76
+ $this->assertResponseHttpCode(302);
77
+ $this->assertRedirectToUrl($referer);
78
+ }
79
+
80
+ /**
81
+ * @loadFixture default
82
+ */
83
+ public function testSyncActionAddsErrorRedirectsToOrderViewOnSpecifiedOrderDoesntExist()
84
+ {
85
+ $params = array();
86
+ $referer = $this->getUrlModel('adminhtml/sales_order/view', $params)->getUrl('adminhtml/sales_order/view');
87
+ $orderId = 123123;
88
+
89
+ $this->getRequest()->setMethod('GET');
90
+ $this->getRequest()->setParam(Mage_Core_Controller_Varien_Action::PARAM_NAME_REFERER_URL, $referer);
91
+ $this->getRequest()->setParam('order_id', $orderId);
92
+
93
+ $this
94
+ ->order
95
+ ->expects($this->any())
96
+ ->method('getId')
97
+ ->will($this->returnValue(null));
98
+
99
+ $this
100
+ ->adminhtmlSession
101
+ ->expects($this->once())
102
+ ->method('addError');
103
+
104
+ $this->dispatch('adminhtml/tigomoney_order/sync');
105
+
106
+ $this->assertResponseHttpCode(302);
107
+ $this->assertRedirectToUrl($referer);
108
+ }
109
+
110
+ /**
111
+ * @loadFixture default
112
+ */
113
+ public function testSyncActionCallsSyncOrderRedirectsToGrid()
114
+ {
115
+ $params = array();
116
+ $referer = $this->getUrlModel('adminhtml/sales_order/view', $params)->getUrl('adminhtml/sales_order/view');
117
+ $orderId = 123123;
118
+
119
+ $this->getRequest()->setMethod('GET');
120
+ $this->getRequest()->setParam(Mage_Core_Controller_Varien_Action::PARAM_NAME_REFERER_URL, $referer);
121
+ $this->getRequest()->setParam('order_id', $orderId);
122
+
123
+ $this
124
+ ->order
125
+ ->expects($this->any())
126
+ ->method('getId')
127
+ ->will($this->returnValue($orderId));
128
+
129
+ $this
130
+ ->sync
131
+ ->expects($this->once())
132
+ ->method('syncOrder')
133
+ ->with($this->order);
134
+
135
+ $this->dispatch('adminhtml/tigomoney_order/sync');
136
+
137
+ $this->assertResponseHttpCode(302);
138
+ $this->assertRedirectToUrl($referer);
139
+ }
140
+
141
+ /**
142
+ * @loadFixture default
143
+ */
144
+ public function testSyncActionCallsSyncOrderReceivesExceptionAddsErrorRedirectsToGrid()
145
+ {
146
+ $params = array();
147
+ $referer = $this->getUrlModel('adminhtml/sales_order/view', $params)->getUrl('adminhtml/sales_order/view');
148
+ $orderId = 123123;
149
+
150
+ $this->getRequest()->setMethod('GET');
151
+ $this->getRequest()->setParam(Mage_Core_Controller_Varien_Action::PARAM_NAME_REFERER_URL, $referer);
152
+ $this->getRequest()->setParam('order_id', $orderId);
153
+
154
+ $this
155
+ ->order
156
+ ->expects($this->any())
157
+ ->method('getId')
158
+ ->will($this->returnValue($orderId));
159
+
160
+ $this
161
+ ->sync
162
+ ->expects($this->once())
163
+ ->method('syncOrder')
164
+ ->with($this->order)
165
+ ->will($this->throwException(new Mage_Core_Exception));
166
+
167
+ $this->dispatch('adminhtml/tigomoney_order/sync');
168
+
169
+ $this->assertResponseHttpCode(302);
170
+ $this->assertRedirectToUrl($referer);
171
+ }
172
+ }
173
+
app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/controllers/Adminhtml/Tigomoney/OrderControllerTest/fixtures/default.yaml ADDED
@@ -0,0 +1,2 @@
 
 
1
+ config:
2
+ default/web/seo/use_rewrites: 0
app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/controllers/RedirectControllerTest.php ADDED
@@ -0,0 +1,169 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Tigo_TigoMoney_RedirectControllerTest
5
+ */
6
+ class Tigo_TigoMoney_RedirectControllerTest extends EcomDev_PHPUnit_Test_Case_Controller
7
+ {
8
+ /**
9
+ * @var Mage_Checkout_Model_Session|PHPUnit_Framework_MockObject_MockObject
10
+ */
11
+ protected $checkoutSession = null;
12
+
13
+ /**
14
+ * @var Mage_Sales_Model_Order|PHPUnit_Framework_MockObject_MockObject
15
+ */
16
+ protected $order = null;
17
+
18
+ /**
19
+ * @var Mage_Sales_Model_Order_Payment|PHPUnit_Framework_MockObject_MockObject
20
+ */
21
+ protected $payment = null;
22
+
23
+ /**
24
+ * Sets up the unit test case
25
+ */
26
+ protected function setUp()
27
+ {
28
+ parent::setUp();
29
+
30
+ $this->payment = $this
31
+ ->getMockBuilder(Mage_Sales_Model_Order_Payment::class)
32
+ ->setMethods(array('getAdditionalInformation', 'getMethod'))
33
+ ->getMock();
34
+
35
+ $this->order = $this
36
+ ->getMockBuilder(Mage_Sales_Model_Order::class)
37
+ ->setMethods(array('getId', 'getPayment'))
38
+ ->getMock();
39
+ $this->order
40
+ ->expects($this->any())
41
+ ->method('getPayment')
42
+ ->will($this->returnValue($this->payment));
43
+
44
+ $this->checkoutSession = $this
45
+ ->getMockBuilder(Mage_Checkout_Model_Session::class)
46
+ ->setMethods(array('getLastRealOrder'))
47
+ ->getMock();
48
+ $this->checkoutSession
49
+ ->expects($this->any())
50
+ ->method('getLastRealOrder')
51
+ ->will($this->returnValue($this->order));
52
+ $this->replaceByMock('model', 'checkout/session', $this->checkoutSession);
53
+ }
54
+
55
+ /**
56
+ * @loadFixture default
57
+ */
58
+ public function testIndexActionSuccessfullyRedirectsToTigoRedirectUrl()
59
+ {
60
+ $redirectUrl = 'http://google.com/';
61
+ $orderId = 1928;
62
+ $paymentMethod = Tigo_TigoMoney_Model_Payment_Redirect::METHOD_CODE;
63
+
64
+ $this
65
+ ->order
66
+ ->expects($this->any())
67
+ ->method('getId')
68
+ ->will($this->returnValue($orderId));
69
+ $this
70
+ ->payment
71
+ ->expects($this->any())
72
+ ->method('getMethod')
73
+ ->will($this->returnValue($paymentMethod));
74
+
75
+ $this
76
+ ->payment
77
+ ->expects($this->any())
78
+ ->method('getAdditionalInformation')
79
+ ->with($this->equalTo(Tigo_TigoMoney_Model_Payment_Redirect::ADDITIONAL_INFO_KEY_REDIRECT_URI))
80
+ ->will($this->returnValue($redirectUrl));
81
+
82
+ $this->dispatch('tigomoney/redirect/index');
83
+
84
+ $this->assertResponseHttpCode(302);
85
+ $this->assertRedirectToUrl($redirectUrl);
86
+ }
87
+
88
+ /**
89
+ * @loadFixture default
90
+ */
91
+ public function testIndexActionRedirectsToHomeWhenOrderNotPresent()
92
+ {
93
+ $redirectUrl = Mage::getBaseUrl();
94
+ $orderId = null;
95
+
96
+ $this
97
+ ->order
98
+ ->expects($this->any())
99
+ ->method('getId')
100
+ ->will($this->returnValue($orderId));
101
+
102
+ $this->dispatch('tigomoney/redirect/index');
103
+
104
+ $this->assertResponseHttpCode(302);
105
+ $this->assertRedirectToUrl($redirectUrl);
106
+ }
107
+
108
+ /**
109
+ * @loadFixture default
110
+ */
111
+ public function testIndexActionRedirectsToHomeWhenPaymentMethodNotTigomoney()
112
+ {
113
+ $redirectUrl = Mage::getBaseUrl();
114
+ $orderId = 9282;
115
+ $paymentMethod = 'checkmo';
116
+
117
+ $this
118
+ ->order
119
+ ->expects($this->any())
120
+ ->method('getId')
121
+ ->will($this->returnValue($orderId));
122
+
123
+ $this
124
+ ->payment
125
+ ->expects($this->any())
126
+ ->method('getMethod')
127
+ ->will($this->returnValue($paymentMethod));
128
+
129
+ $this->dispatch('tigomoney/redirect/index');
130
+
131
+ $this->assertResponseHttpCode(302);
132
+ $this->assertRedirectToUrl($redirectUrl);
133
+ }
134
+
135
+ /**
136
+ * @loadFixture default
137
+ */
138
+ public function testIndexActionRedirectsToHomeWhenPaymentMethodIsTigomoneyButNoRedirectUrlIsFound()
139
+ {
140
+ $redirectUrl = Mage::getBaseUrl();
141
+ $orderId = 9282;
142
+ $paymentMethod = Tigo_TigoMoney_Model_Payment_Redirect::METHOD_CODE;
143
+
144
+ $this
145
+ ->order
146
+ ->expects($this->any())
147
+ ->method('getId')
148
+ ->will($this->returnValue($orderId));
149
+
150
+ $this
151
+ ->payment
152
+ ->expects($this->any())
153
+ ->method('getMethod')
154
+ ->will($this->returnValue($paymentMethod));
155
+
156
+ $this
157
+ ->payment
158
+ ->expects($this->once())
159
+ ->method('getAdditionalInformation')
160
+ ->with($this->equalTo(Tigo_TigoMoney_Model_Payment_Redirect::ADDITIONAL_INFO_KEY_REDIRECT_URI))
161
+ ->will($this->returnValue(null));
162
+
163
+ $this->dispatch('tigomoney/redirect/index');
164
+
165
+ $this->assertResponseHttpCode(302);
166
+ $this->assertRedirectToUrl($redirectUrl);
167
+ }
168
+ }
169
+
app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/controllers/RedirectControllerTest/fixtures/default.yaml ADDED
@@ -0,0 +1,2 @@
 
 
1
+ config:
2
+ default/web/seo/use_rewrites: 1
app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/controllers/ReturnControllerTest.php ADDED
@@ -0,0 +1,151 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Tigo_TigoMoney_SyncControllerTest
5
+ */
6
+ class Tigo_TigoMoney_ReturnControllerTest extends EcomDev_PHPUnit_Test_Case_Controller
7
+ {
8
+ /**
9
+ * @var Mage_Core_Model_Url|PHPUnit_Framework_MockObject_MockObject
10
+ */
11
+ protected $coreUrl = null;
12
+
13
+ /**
14
+ * @var Tigo_TigoMoney_Model_Payment_Redirect_Sync|PHPUnit_Framework_MockObject_MockObject
15
+ */
16
+ protected $sync = null;
17
+
18
+ /**
19
+ * Sets up the unit test case
20
+ */
21
+ protected function setUp()
22
+ {
23
+ parent::setUp();
24
+
25
+ $this->sync = $this
26
+ ->getModelMock('tigo_tigomoney/payment_redirect_sync', array('handleRequest'));
27
+ $this->replaceByMock('model', 'tigo_tigomoney/payment_redirect_sync', $this->sync);
28
+
29
+ $this->coreUrl = $this->getModelMock('core/url', array('nonExistentMethod'));
30
+ $this->coreUrl->setUseSession(false);
31
+ $this->replaceByMock('model', 'core/url', $this->coreUrl);
32
+ }
33
+
34
+ /**
35
+ * @return array
36
+ */
37
+ public function testCallbackIsDeliveredCorrectlyToSyncModelAndRedirectsToRightRouteDataProvider()
38
+ {
39
+ # Preg Replaces below were necessary. There was an Adminhtml controller test being
40
+ # executed before this one, and it was setting the base url cache in the store model,
41
+ # adding 'index.php' in the url regardless of the seo_rewrites value.
42
+ $params = array('_secure' => true);
43
+ $successRoute = $this->getUrlModel('checkout/onepage/success/', $params)->getUrl('checkout/onepage/success/', $params);
44
+ $failureRoute = $this->getUrlModel('checkout/onepage/failure/', $params)->getUrl('checkout/onepage/failure/', $params);
45
+ return array(
46
+ array(
47
+ Tigo_TigoMoney_Model_Payment_Redirect_Sync::PARAM_VALUE_TRANSACTION_STATUS_SUCCESS,
48
+ true,
49
+ preg_replace('/checkout\//', 'index.php/checkout/', $successRoute)
50
+ ),
51
+ array(
52
+ Tigo_TigoMoney_Model_Payment_Redirect_Sync::PARAM_VALUE_TRANSACTION_STATUS_CANCEL,
53
+ false,
54
+ preg_replace('/checkout\//', 'index.php/checkout/', $failureRoute)
55
+ ),
56
+ array(
57
+ Tigo_TigoMoney_Model_Payment_Redirect_Sync::PARAM_VALUE_TRANSACTION_STATUS_FAILURE,
58
+ false,
59
+ preg_replace('/checkout\//', 'index.php/checkout/', $failureRoute)
60
+ )
61
+ );
62
+ }
63
+
64
+ /**
65
+ * @param string $status
66
+ * @param bool $handleRequestReturnValue
67
+ * @param string $expectedRoute
68
+ * @dataProvider testCallbackIsDeliveredCorrectlyToSyncModelAndRedirectsToRightRouteDataProvider
69
+ */
70
+ public function testCallbackIsDeliveredCorrectlyToSyncModelAndRedirectsToRightRoute(
71
+ $status,
72
+ $handleRequestReturnValue,
73
+ $expectedRoute
74
+ )
75
+ {
76
+ $redirectUrl = $expectedRoute;
77
+ $merchantOrderId = '10001023';
78
+ $mfsTransactionId = '38382934293842384';
79
+ $transactionCode = '039303930.039303928372.84772737';
80
+ $transactionStatus = $status;
81
+
82
+ $this->getRequest()->setMethod('POST');
83
+ $this->getRequest()->setPost(
84
+ Tigo_TigoMoney_Model_Payment_Redirect_Sync::PARAM_KEY_MERCHANT_TRANSACTION_ID,
85
+ $merchantOrderId
86
+ );
87
+ $this->getRequest()->setPost(
88
+ Tigo_TigoMoney_Model_Payment_Redirect_Sync::PARAM_KEY_MFS_TRANSACTION_ID,
89
+ $mfsTransactionId
90
+ );
91
+ $this->getRequest()->setPost(
92
+ Tigo_TigoMoney_Model_Payment_Redirect_Sync::PARAM_KEY_TRANSACTION_CODE,
93
+ $transactionCode
94
+ );
95
+ $this->getRequest()->setPost(
96
+ Tigo_TigoMoney_Model_Payment_Redirect_Sync::PARAM_KEY_TRANSACTION_STATUS,
97
+ $transactionStatus
98
+ );
99
+
100
+ $this
101
+ ->sync
102
+ ->expects($this->once())
103
+ ->method('handleRequest')
104
+ ->with(
105
+ $this->callback(
106
+ function ($params) use ($merchantOrderId, $mfsTransactionId, $transactionCode, $transactionStatus) {
107
+ $return = false;
108
+ if (
109
+ (
110
+ $params[Tigo_TigoMoney_Model_Payment_Redirect_Sync::PARAM_KEY_MERCHANT_TRANSACTION_ID] == $merchantOrderId
111
+ ) &&
112
+ (
113
+ $params[Tigo_TigoMoney_Model_Payment_Redirect_Sync::PARAM_KEY_MFS_TRANSACTION_ID] == $mfsTransactionId
114
+ ) &&
115
+ (
116
+ $params[Tigo_TigoMoney_Model_Payment_Redirect_Sync::PARAM_KEY_TRANSACTION_CODE] == $transactionCode
117
+ ) &&
118
+ (
119
+ $params[Tigo_TigoMoney_Model_Payment_Redirect_Sync::PARAM_KEY_TRANSACTION_STATUS] == $transactionStatus
120
+ ) &&
121
+ array_key_exists(
122
+ Tigo_TigoMoney_Model_Payment_Redirect_Sync::PARAM_KEY_MERCHANT_TRANSACTION_ID,
123
+ $params
124
+ ) &&
125
+ array_key_exists(
126
+ Tigo_TigoMoney_Model_Payment_Redirect_Sync::PARAM_KEY_MFS_TRANSACTION_ID,
127
+ $params
128
+ ) &&
129
+ array_key_exists(
130
+ Tigo_TigoMoney_Model_Payment_Redirect_Sync::PARAM_KEY_TRANSACTION_CODE,
131
+ $params
132
+ ) &&
133
+ array_key_exists(
134
+ Tigo_TigoMoney_Model_Payment_Redirect_Sync::PARAM_KEY_TRANSACTION_STATUS,
135
+ $params
136
+ )
137
+ ) {
138
+ $return = true;
139
+ }
140
+ return $return;
141
+ }
142
+ )
143
+ )->will($this->returnValue($handleRequestReturnValue));
144
+
145
+ $this->dispatch('tigomoney/return/index');
146
+
147
+ $this->assertResponseHttpCode(302);
148
+ $this->assertRedirectToUrl($redirectUrl);
149
+ }
150
+ }
151
+
app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/controllers/SyncControllerTest.php ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Tigo_TigoMoney_ReturnControllerTest
5
+ */
6
+ class Tigo_TigoMoney_SyncControllerTest extends EcomDev_PHPUnit_Test_Case_Controller
7
+ {
8
+ /**
9
+ * @var Tigo_TigoMoney_Model_Payment_Redirect_Sync|PHPUnit_Framework_MockObject_MockObject
10
+ */
11
+ protected $sync = null;
12
+
13
+ /**
14
+ * Sets up the unit test case
15
+ */
16
+ protected function setUp()
17
+ {
18
+ parent::setUp();
19
+
20
+ $this->sync = $this
21
+ ->getMockBuilder(Tigo_TigoMoney_Model_Payment_Redirect_Sync::class)
22
+ ->setMethods(array('handleRequest'))
23
+ ->getMock();
24
+ $this->replaceByMock('model', 'tigo_tigomoney/payment_redirect_sync', $this->sync);
25
+ }
26
+
27
+ /**
28
+ * @loadFixture default
29
+ */
30
+ public function testCallbackIsDeliveredCorrectlyToSyncModel()
31
+ {
32
+ $merchantOrderId = '10001023';
33
+ $mfsTransactionId = '38382934293842384';
34
+ $transactionCode = '039303930.039303928372.84772737';
35
+ $transactionStatus = Tigo_TigoMoney_Model_Payment_Redirect_Sync::PARAM_VALUE_TRANSACTION_STATUS_SUCCESS;
36
+
37
+ $this->getRequest()->setMethod('POST');
38
+ $this->getRequest()->setPost(
39
+ Tigo_TigoMoney_Model_Payment_Redirect_Sync::PARAM_KEY_MERCHANT_TRANSACTION_ID,
40
+ $merchantOrderId
41
+ );
42
+ $this->getRequest()->setPost(
43
+ Tigo_TigoMoney_Model_Payment_Redirect_Sync::PARAM_KEY_MFS_TRANSACTION_ID,
44
+ $mfsTransactionId
45
+ );
46
+ $this->getRequest()->setPost(
47
+ Tigo_TigoMoney_Model_Payment_Redirect_Sync::PARAM_KEY_TRANSACTION_CODE,
48
+ $transactionCode
49
+ );
50
+ $this->getRequest()->setPost(
51
+ Tigo_TigoMoney_Model_Payment_Redirect_Sync::PARAM_KEY_TRANSACTION_STATUS,
52
+ $transactionStatus
53
+ );
54
+
55
+ $this
56
+ ->sync
57
+ ->expects($this->once())
58
+ ->method('handleRequest')
59
+ ->with(
60
+ $this->callback(
61
+ function ($params) use ($merchantOrderId, $mfsTransactionId, $transactionCode, $transactionStatus) {
62
+ $return = false;
63
+ if (
64
+ (
65
+ $params[Tigo_TigoMoney_Model_Payment_Redirect_Sync::PARAM_KEY_MERCHANT_TRANSACTION_ID] == $merchantOrderId
66
+ ) &&
67
+ (
68
+ $params[Tigo_TigoMoney_Model_Payment_Redirect_Sync::PARAM_KEY_MFS_TRANSACTION_ID] == $mfsTransactionId
69
+ ) &&
70
+ (
71
+ $params[Tigo_TigoMoney_Model_Payment_Redirect_Sync::PARAM_KEY_TRANSACTION_CODE] == $transactionCode
72
+ ) &&
73
+ (
74
+ $params[Tigo_TigoMoney_Model_Payment_Redirect_Sync::PARAM_KEY_TRANSACTION_STATUS] == $transactionStatus
75
+ ) &&
76
+ array_key_exists(
77
+ Tigo_TigoMoney_Model_Payment_Redirect_Sync::PARAM_KEY_MERCHANT_TRANSACTION_ID,
78
+ $params
79
+ ) &&
80
+ array_key_exists(
81
+ Tigo_TigoMoney_Model_Payment_Redirect_Sync::PARAM_KEY_MFS_TRANSACTION_ID,
82
+ $params
83
+ ) &&
84
+ array_key_exists(
85
+ Tigo_TigoMoney_Model_Payment_Redirect_Sync::PARAM_KEY_TRANSACTION_CODE,
86
+ $params
87
+ ) &&
88
+ array_key_exists(
89
+ Tigo_TigoMoney_Model_Payment_Redirect_Sync::PARAM_KEY_TRANSACTION_STATUS,
90
+ $params
91
+ )
92
+ ) {
93
+ $return = true;
94
+ }
95
+ return $return;
96
+ }
97
+ )
98
+ );
99
+
100
+ $this->dispatch('tigomoney/sync/index');
101
+
102
+ $this->assertResponseHttpCode(200);
103
+ $this->assertResponseBody($this->isEmpty());
104
+ }
105
+ }
106
+
app/code/community/Tigo/TigoMoney/tests/Tigo/TigoMoney/controllers/SyncControllerTest/fixtures/default.yaml ADDED
@@ -0,0 +1,2 @@
 
 
1
+ config:
2
+ default/web/seo/use_rewrites: 1
app/design/adminhtml/default/default/template/tigo_tigomoney/payment/redirect/info.phtml ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <img src="<?php echo $this->getSkinUrl('tigo_tigomoney/images/logo.png'); ?>">
2
+
3
+ <?php if ($_specificInfo = $this->getSpecificInformation()):?>
4
+ <table>
5
+ <?php foreach ($_specificInfo as $_label => $_value):?>
6
+ <tr>
7
+ <td><?php echo $this->escapeHtml($_label)?>:</td>
8
+ <td><?php echo nl2br(implode($this->getValueAsArray($_value, true), "\n"))?></td>
9
+ </tr>
10
+ <?php endforeach; ?>
11
+ </table>
12
+ <?php endif;?>
13
+
14
+ <?php echo $this->getChildHtml()?>
app/design/frontend/base/default/template/tigo_tigomoney/payment/redirect/form.phtml ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php /** @var Tigo_TigoMoney_Block_Payment_Redirect_Form $this */ ?>
2
+ <?php $_code=$this->getMethodCode() ?>
3
+ <ul class="form-list" id="payment_form_<?php echo $_code ?>" style="display:none;">
4
+ <li>
5
+ <div class="<?php echo $this->getMethodCode() ?>-instructions-content">
6
+ <img src="<?php echo $this->getSkinUrl('tigo_tigomoney/images/phones.png'); ?>" style="float:right" />
7
+ <?php echo $this->escapeHtml($this->getDescription()); ?>
8
+ </div>
9
+ </li>
10
+ <li>
11
+ <label for="<?php echo $_code ?>_phone_number" class="required"><em>*</em><?php echo $this->__('Enter your TIGO Phone Number') ?></label>
12
+ <div class="input-box">
13
+ <input type="text" id="<?php echo $_code ?>_phone_number" name="payment[<?php echo $_code ?>_phone_number]"
14
+ title="<?php echo Mage::helper('core')->jsQuoteEscape($this->__('Enter your TIGO Phone Number')) ?>"
15
+ class="input-text required-entry validate-length maximum-length-8 minimum-length-8 validate-digits"
16
+ value="" />
17
+ </div>
18
+ </li>
19
+ </ul>
app/design/frontend/base/default/template/tigo_tigomoney/payment/redirect/info.phtml ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <img src="<?php echo $this->getSkinUrl('tigo_tigomoney/images/logo.png'); ?>">
2
+
3
+ <?php if ($_specificInfo = $this->getSpecificInformation()):?>
4
+ <table>
5
+ <?php foreach ($_specificInfo as $_label => $_value):?>
6
+ <tr>
7
+ <td><?php echo $this->escapeHtml($_label)?>:</td>
8
+ <td><?php echo nl2br(implode($this->getValueAsArray($_value, true), "\n"))?></td>
9
+ </tr>
10
+ <?php endforeach; ?>
11
+ </table>
12
+ <?php endif;?>
13
+
14
+ <?php echo $this->getChildHtml()?>
app/etc/modules/Tigo_TigoMoney.xml ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Tigo_TigoMoney>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ <depends>
8
+ <Mage_Payment />
9
+ <Mage_Sales />
10
+ </depends>
11
+ </Tigo_TigoMoney>
12
+ </modules>
13
+ </config>
app/locale/es_ES/Tigo_TigoMoney.csv ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "To complete the payment using TIGO Money, a SMS will be sent to your mobile phone which will contain a PIN you will use to finish the transaction.","Para realizar las transaciones a traves de TIGO Money se enviara uma mensage a su celular pidiendo que coloque su PIN para realizar la transaccion."
2
+ "Enter your TIGO Phone Number","Introduce tu Número Tigo"
3
+ "Your store has two URIs which will be used by Tigo Payment Server. They are:","Tú tienda tiene dos URIs que serán utilizados por Tigo Payment Server. Estas Son:"
4
+ "Description ","Descripción"
5
+ "When test mode is enabled the module will use Tigo Money Secure Sandbox instead of the production environment.","Cuando el modo de prueba está habilitado, el módulo utilizará Tigo Money Secure Sandbox en lugar del entorno de producción"
6
+ "Enabling this option will create log entries for all requests to and from Tigo Payment Server in var/log/tigomoney.log","Habilitar esta opción creará entradas de registro para todas las solicitudes de y desde Tigo Payment Server en var/log/tigomoney.log"
7
+ "Sync Recent Pending Orders (Crontab Format)","Sincronizar Órdenes Pendientes (Crontab Format)"
8
+ "Leaving this field blank will default to the Magento behaviour: the link directs the user to the shopping cart. Use complete urls, including protocol and domain. Ex: http://www.tigomoney.com.sv/","Si deja este campo en blanco, el valor predeterminado será magento Comportamiento: el enlace dirige al usuario al carro de la compra. Use urls completas, incluyendo protocolo y dominio. Ex: http://www.tigomoney.com.sv/"
9
+ "Leaving this field blank will default to the Magento behaviour: the link directs the user to the home page. Use complete urls, including protocol and domain. Ex: http://www.tigomoney.com.sv/","Si deja este campo en blanco, el valor predeterminado será magento Comportamiento: el enlace dirige al usuario al Home Page. Use urls completas, incluyendo protocolo y dominio. Ex: http://www.tigomoney.com.sv/"
10
+ "Test Mode Enabled?","Modo de Prueba Habilitado?"
11
+ "Debug Mode Enabled?","Modo de Depuración Habilitado?"
12
+ "New Order status","Estado del Nuevo Pedido"
13
+ "Continue Shopping URL - Failure","Enlace Seguir Comprando - Compra fallida"
14
+ "Continue Shopping URL - Success","Enlace Seguir Comprando - Compra Exitosa"
15
+ "Enabled","Habilitado"
package.xml ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Tigo_TigoMoney</name>
4
+ <version>0.1.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://www.opensource.org/licenses/gpl-license.php">GPL</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Tigo Money Payment Gateway for El Salvador</summary>
10
+ <description>The payment gateway allows you to accept Tigo Money payment in your store.&#xD;
11
+ &#xD;
12
+ In order to register as merchant you need to start you enrollment flow here: http://www.tigomoney.com.sv/content/pygw_afiliacion</description>
13
+ <notes>Initial version of the module</notes>
14
+ <authors><author><name>Hugo Barrientos</name><user>tigo3030</user><email>hugol.barrientos@gmail.com</email></author></authors>
15
+ <date>2017-03-07</date>
16
+ <time>14:16:19</time>
17
+ <contents><target name="magecommunity"><dir name="Tigo"><dir name="TigoMoney"><dir name="Block"><dir name="Payment"><dir name="Redirect"><file name="Form.php" hash="d2c4760f6b97eec4c1414d54780e05de"/><file name="Info.php" hash="986152acab470b95ea4d214017c512aa"/></dir></dir><dir name="Rewrite"><dir name="Checkout"><dir name="Onepage"><file name="Failure.php" hash="66e46a57ecec0675d75fefc171186ac6"/><file name="Success.php" hash="edda938e133f44f5a6ae97a37f825186"/></dir></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="80ceee9503b429335458015d99e59bab"/></dir><dir name="Model"><dir name="Adminhtml"><file name="ConfigComment.php" hash="c951c0d7e3772a6bc52128f75b6ff1e6"/></dir><dir name="Cron"><file name="SyncOldPendingOrders.php" hash="54e9734267c8fc2138dae42aa9cf6dee"/><file name="SyncRecentPendingOrders.php" hash="a46febad8b15d640a1ee212f289cd232"/></dir><file name="Debug.php" hash="c66d6c8e07c8145ef9076a438f4d62dd"/><dir name="Observer"><file name="AdminOrderView.php" hash="438934f42353281538013a2ac4d63df3"/></dir><dir name="Payment"><dir name="Redirect"><dir name="Api"><file name="AbstractResponse.php" hash="ae3c7047d97c0c3121321ce9890d4213"/><file name="AuthorizationRequest.php" hash="ddc0113b4d62ea0e9640c85b62009c0d"/><file name="AuthorizationResponse.php" hash="4a0f3acedd90d2d6c60d8b86600d168d"/><file name="GenerateTokenRequest.php" hash="47d26b66d9bc7c6019f09ef8c27f2a70"/><file name="GenerateTokenResponse.php" hash="2e3539c37eb86fb1c511f2b90468c6ca"/><file name="RequestBuilder.php" hash="75f00030a94ee2a993b30fcc77c07680"/><file name="RequestInterface.php" hash="459a8fd57ed21a78a42b0fa4e36aa83c"/><file name="ResponseInterface.php" hash="f6f149ec71c3746d163b5805f20d7090"/><file name="ReverseTransactionRequest.php" hash="8ae5ba3104d738135938268bbe109101"/><file name="ReverseTransactionResponse.php" hash="a23041e50412b46ffbd63e6a1bbc340b"/><file name="TransactionStatusRequest.php" hash="d5a66aff926810d192e852a699cc3ff1"/><file name="TransactionStatusResponse.php" hash="519aadc2e0d2dbd5cd35f80249fd7aed"/></dir><file name="Api.php" hash="423f65fc43abcbbb1e98d452506d6d29"/><file name="Sync.php" hash="d41d1adf6898e54b3c21b2bfb53db608"/></dir><file name="Redirect.php" hash="77d54624ad6e24021b9c5c4bf2c38fc5"/></dir></dir><dir name="controllers"><dir name="Adminhtml"><dir name="Tigomoney"><file name="OrderController.php" hash="268035e58ab3e968f996a1a30eea59c3"/></dir></dir><file name="RedirectController.php" hash="5c0acc32849fdb06ecee91841feb5cea"/><file name="ReturnController.php" hash="83af85fa918e93c56158fb1c0bdc8a36"/><file name="SyncController.php" hash="491256edd725912482e4f274209319ac"/></dir><dir name="etc"><file name="config.xml" hash="5086b83f9b2c48738e59384d73bfd693"/><file name="system.xml" hash="5be8103a30968b1cb6f0e9389b943c0d"/></dir><dir name="tests"><dir name="Tigo"><dir name="TigoMoney"><dir name="Block"><dir name="Payment"><dir name="Redirect"><file name="FormTest.php" hash="2341c7beebb6a3da91b24c534a7ac3f2"/><file name="InfoTest.php" hash="d213e2cc7652449ac85a508534f739e9"/></dir><dir name="Rewrite"><dir name="Checkout"><dir name="Onepage"><file name="FailureTest.php" hash="d099694ff6756da4385a6c5ff005757a"/><file name="SuccessTest.php" hash="7ca77d96c79996ac208fc17b4d5fd04d"/></dir></dir></dir></dir></dir><file name="ConfigTest.php" hash="a6010a797697bc4bb289ad0d51757966"/><dir name="Helper"><dir name="DataTest"><dir name="fixtures"><file name="default.yaml" hash="79b16c8932fcfad426ccbfb9ed1a0935"/><file name="disabledModes.yaml" hash="fd7ed77c03df0cfd08c0001345af3afc"/></dir></dir><file name="DataTest.php" hash="525aeeb257a3ace3eb0c505e66fcd8d6"/></dir><dir name="Model"><dir name="Adminhtml"><file name="ConfigCommentTest.php" hash="5498ded8b8f1d0be6cd69474db2e7402"/></dir><dir name="Cron"><file name="SyncOldPendingOrdersTest.php" hash="fb923d64b0847c22176cc81a25da57ed"/><file name="SyncRecentPendingOrdersTest.php" hash="083fbded9eecc9dbbfa5591bb32a4cc1"/></dir><dir name="DebugTest"><dir name="fixtures"><file name="debugModeOff.yaml" hash="76a482f40a8e9589dc350078d93ab6dc"/><file name="debugModeOn.yaml" hash="c592a58c061b366c1d939d63ae6dd4a3"/></dir></dir><file name="DebugTest.php" hash="f7cf0ada2852545ed61854377c3e5f38"/><dir name="Observer"><file name="AdminOrderViewTest.php" hash="d13e9d081269b599a6a3a19c4290356f"/></dir><dir name="Payment"><dir name="Redirect"><dir name="Api"><file name="AbstractResponseTest.php" hash="695067a665c72c68de9effd131fa7207"/><file name="AuthorizationRequestTest.php" hash="6019d2695a3f6d2febebdb5c543eab28"/><file name="AuthorizationResponseTest.php" hash="7415223eb5017103f31c437d067af49b"/><file name="GenerateTokenRequestTest.php" hash="b6c3cdf230427ecfb90abada72d3348d"/><file name="GenerateTokenResponseTest.php" hash="9df9ec696bb5db0a0fbfe21827f67916"/><dir name="RequestBuilderTest"><dir name="fixtures"><file name="default.yaml" hash="0bf3b700be8c12f1ade7f4f742f441f6"/></dir></dir><file name="RequestBuilderTest.php" hash="4433560d3e131c94db5e6957d602a82a"/><file name="ReverseTransactionRequestTest.php" hash="ff0aaaedfa3cd40b851bb776092cf023"/><file name="ReverseTransactionResponseTest.php" hash="cc8a45cd42ebdaf255a859435aa3daf0"/><file name="TransactionStatusRequestTest.php" hash="2e8999f4298d3e9233409d591ea8c4ef"/><file name="TransactionStatusResponseTest.php" hash="2c41af9b96288e734343ff2739fc908b"/></dir><dir name="ApiTest"><dir name="fixtures"><file name="testModeOff.yaml" hash="6bc9816b2a785f060c90dbf5dcd3580c"/><file name="testModeOn.yaml" hash="14268bbb704bf57690dfffe7d1b9b341"/></dir></dir><file name="ApiTest.php" hash="55bb9e5f5fef2185006e63ab2880b346"/><file name="SyncTest.php" hash="9736e8673a125603c516384a96691b47"/></dir><dir name="RedirectTest"><dir name="fixtures"><file name="authorize.yaml" hash="0bf3b700be8c12f1ade7f4f742f441f6"/><file name="default.yaml" hash="8fb2e56cf3289502bacbba0db062f9b2"/><file name="refund.yaml" hash="0bf3b700be8c12f1ade7f4f742f441f6"/></dir></dir><file name="RedirectTest.php" hash="b12a600c6833e5763271a55707dc5c5c"/></dir></dir><dir name="controllers"><dir name="Adminhtml"><dir name="Tigomoney"><dir name="OrderControllerTest"><dir name="fixtures"><file name="default.yaml" hash="9320f1f2e82c4df0b5bd4d51325342f6"/></dir></dir><file name="OrderControllerTest.php" hash="ac4bc472e775c5449842bc7aad6de6ad"/></dir></dir><dir name="RedirectControllerTest"><dir name="fixtures"><file name="default.yaml" hash="91a767c3a34837548f08cc65c5da6ce8"/></dir></dir><file name="RedirectControllerTest.php" hash="c1551161d1bba63945e84f093227b94a"/><file name="ReturnControllerTest.php" hash="e9eecf9e0fe81aed8d012c79ee38affe"/><dir name="SyncControllerTest"><dir name="fixtures"><file name="default.yaml" hash="91a767c3a34837548f08cc65c5da6ce8"/></dir></dir><file name="SyncControllerTest.php" hash="0a6166063bca57e551f27a3cadb2400f"/></dir></dir></dir></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="tigo_tigomoney"><dir name="payment"><dir name="redirect"><file name="info.phtml" hash="f5bddf24740c6b0a5c4e498aceaa65b3"/></dir></dir></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="template"><dir name="tigo_tigomoney"><dir name="payment"><dir name="redirect"><file name="form.phtml" hash="271495b31d813cf4d5b5cb7d656fb30f"/><file name="info.phtml" hash="f5bddf24740c6b0a5c4e498aceaa65b3"/></dir></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Tigo_TigoMoney.xml" hash="f6a7aa42f27e4ad2a7c1dcf9e928385e"/></dir></target><target name="magelocale"><dir name="es_ES"><file name="Tigo_TigoMoney.csv" hash="986927657445ea2d9f87f2faa5cf938d"/></dir></target><target name="mageskin"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="tigo_tigomoney"><dir name="images"><file name="logo.png" hash="1c0b2bce148ebee560e2f9512703f58e"/></dir><file name=".DS_Store" hash="1dd38e74649b1bbfbc1fb3984f5fa40f"/></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="tigo_tigomoney"><dir name="images"><file name="logo.png" hash="1c0b2bce148ebee560e2f9512703f58e"/><file name="phones.png" hash="b47b3f1edb1789d40fc5e741db86b547"/></dir></dir></dir></dir></dir></target></contents>
18
+ <compatible/>
19
+ <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
20
+ </package>
skin/adminhtml/default/default/tigo_tigomoney/.DS_Store ADDED
Binary file
skin/adminhtml/default/default/tigo_tigomoney/images/logo.png ADDED
Binary file
skin/frontend/base/default/tigo_tigomoney/images/logo.png ADDED
Binary file
skin/frontend/base/default/tigo_tigomoney/images/phones.png ADDED
Binary file