minkasu_smartphone_checkout - Version 1.0.0

Version Notes

Minkasu features:

Processes online payments using authorize.net
Supports multi-merchant Magento instances
Integrated with Jumio for credit card acceptance and verification
Phone verification done by Twilio
Mandatory phone verification for the customer prior to payment
Order confirmation and order cancel notification to customer

Download this release

Release Info

Developer Minkasu Inc
Extension minkasu_smartphone_checkout
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

Files changed (38) hide show
  1. app/code/community/Minkasu/Wallet/Block/Adminhtml/Merchant/Create.php +21 -0
  2. app/code/community/Minkasu/Wallet/Block/Adminhtml/Merchant/Create/Form.php +102 -0
  3. app/code/community/Minkasu/Wallet/Block/Adminhtml/Merchant/Create/Success.php +35 -0
  4. app/code/community/Minkasu/Wallet/Block/Adminhtml/Merchant/Edit.php +21 -0
  5. app/code/community/Minkasu/Wallet/Block/Adminhtml/Merchant/Edit/Form.php +70 -0
  6. app/code/community/Minkasu/Wallet/Block/Adminhtml/System/Config/Frontend/MinkasuGroup.php +21 -0
  7. app/code/community/Minkasu/Wallet/Block/Pay.php +8 -0
  8. app/code/community/Minkasu/Wallet/Helper/Api.php +94 -0
  9. app/code/community/Minkasu/Wallet/Helper/Api/Merchant.php +30 -0
  10. app/code/community/Minkasu/Wallet/Helper/Data.php +58 -0
  11. app/code/community/Minkasu/Wallet/Model/Api/Adapter/Abstract.php +204 -0
  12. app/code/community/Minkasu/Wallet/Model/Api/Adapter/Curl.php +39 -0
  13. app/code/community/Minkasu/Wallet/Model/Api/Client.php +115 -0
  14. app/code/community/Minkasu/Wallet/Model/Api/Format/Abstract.php +13 -0
  15. app/code/community/Minkasu/Wallet/Model/Api/Format/Json.php +17 -0
  16. app/code/community/Minkasu/Wallet/Model/Api/Type/Abstract.php +56 -0
  17. app/code/community/Minkasu/Wallet/Model/Api/Type/Merchant.php +142 -0
  18. app/code/community/Minkasu/Wallet/Model/Api/Type/Transaction.php +289 -0
  19. app/code/community/Minkasu/Wallet/Model/Api/Type/Transaction.php~ +275 -0
  20. app/code/community/Minkasu/Wallet/Model/Observer.php +47 -0
  21. app/code/community/Minkasu/Wallet/Model/Observer.php~ +54 -0
  22. app/code/community/Minkasu/Wallet/Model/Payment.php +94 -0
  23. app/code/community/Minkasu/Wallet/Model/System/Config/Backend/MinkasuStatus.php +62 -0
  24. app/code/community/Minkasu/Wallet/controllers/Adminhtml/Minkasu/Wallet/MerchantController.php +140 -0
  25. app/code/community/Minkasu/Wallet/controllers/PaymentController.php +408 -0
  26. app/code/community/Minkasu/Wallet/controllers/PaymentController.php~ +410 -0
  27. app/code/community/Minkasu/Wallet/controllers/TransactionController.php +121 -0
  28. app/code/community/Minkasu/Wallet/controllers/TransactionController.php~ +93 -0
  29. app/code/community/Minkasu/Wallet/etc/config.xml +108 -0
  30. app/code/community/Minkasu/Wallet/etc/system.xml +76 -0
  31. app/code/community/Minkasu/Wallet/sql/minkasu_wallet_setup/install-0.0.0.1.php +11 -0
  32. app/design/adminhtml/default/default/layout/minkasu_wallet.xml +77 -0
  33. app/design/adminhtml/default/default/template/minkasu/wallet/merchant/create/success.phtml +9 -0
  34. app/design/adminhtml/default/default/template/minkasu/wallet/merchant/popup.phtml +38 -0
  35. app/design/frontend/base/default/layout/minkasu_wallet.xml +12 -0
  36. app/design/frontend/base/default/template/minkasu/wallet/pay.phtml +192 -0
  37. app/etc/modules/Minkasu_Wallet.xml +11 -0
  38. package.xml +26 -0
app/code/community/Minkasu/Wallet/Block/Adminhtml/Merchant/Create.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Minkasu_Wallet_Block_Adminhtml_Merchant_Create extends Mage_Adminhtml_Block_Widget_Form_Container
4
+ {
5
+ /**
6
+ * {@inheritdoc}
7
+ */
8
+ public function __construct()
9
+ {
10
+ parent::__construct();
11
+ $this->_objectId = 'object_id';
12
+ $this->_blockGroup = 'minkasu_wallet';
13
+ $this->_controller = 'adminhtml_merchant';
14
+ $this->_mode = 'create';
15
+ $this->_headerText = Mage::helper('minkasu_wallet')->__('Minkasu Merchant Create Form');
16
+
17
+ $this->_removeButton('reset');
18
+ $this->_removeButton('back');
19
+ $this->_updateButton('save', 'label', Mage::helper('minkasu_wallet')->__('Create'));
20
+ }
21
+ }
app/code/community/Minkasu/Wallet/Block/Adminhtml/Merchant/Create/Form.php ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Minkasu_Wallet_Block_Adminhtml_Merchant_Create_Form extends Mage_Adminhtml_Block_Widget_Form
4
+ {
5
+ /**
6
+ * {@inheritdoc}
7
+ */
8
+ protected function _prepareForm()
9
+ {
10
+ $form = new Varien_Data_Form(array(
11
+ 'id' => 'edit_form',
12
+ 'method' => 'post',
13
+ 'action' => $this->getUrl('*/*/save', array('_current' => true)),
14
+ ));
15
+
16
+ $form->setUseContainer(true);
17
+ $this->setForm($form);
18
+
19
+ $generalFieldset = $form->addFieldset('general', array('legend' => $this->__('General Information')));
20
+ $generalFieldset->addField('name', 'text', array(
21
+ 'label' => $this->__('Store Name'),
22
+ 'name' => 'name',
23
+ 'required' => true,
24
+ ));
25
+ $generalFieldset->addField('email', 'text', array(
26
+ 'label' => $this->__('Email'),
27
+ 'name' => 'email',
28
+ 'class' => 'validate-email',
29
+ 'required' => true,
30
+ ));
31
+ $generalFieldset->addField('phone', 'text', array(
32
+ 'label' => $this->__('Phone'),
33
+ 'name' => 'phone',
34
+ 'required' => false,
35
+ ));
36
+ $generalFieldset->addField('authNet_api_login_id', 'text', array(
37
+ 'label' => $this->__('Your Authorize.net API Login ID'),
38
+ 'name' => 'authNet_api_login_id',
39
+ 'required' => true,
40
+ ));
41
+ $generalFieldset->addField('authNet_transaction_key', 'text', array(
42
+ 'label' => $this->__('Your Authorize.net Transaction Key'),
43
+ 'name' => 'authNet_transaction_key',
44
+ 'required' => true,
45
+ ));
46
+ $generalFieldset->addField('authNet_gateway', 'select', array(
47
+ 'label' => $this->__('Authorize.net Test Mode'),
48
+ 'name' => 'authNet_gateway',
49
+ 'options' => array(
50
+ Minkasu_Wallet_Model_Api_Type_Merchant::GATEWAY_AUTHORIZENET_SANDBOX => $this->__('Yes'),
51
+ Minkasu_Wallet_Model_Api_Type_Merchant::GATEWAY_AUTHORIZENET => $this->__('No'),
52
+ ),
53
+ 'required' => true,
54
+ ));
55
+ $generalFieldset->addField('terms', 'checkbox', array(
56
+ 'label' => $this->__('Terms & Conditions'),
57
+ 'note' => $this->__(
58
+ 'I agree to the Minkasu <a href="%s" target="_blank">Terms & Conditions</a>',
59
+ 'https://transactions.minkasu.com/terms/merchant.html'
60
+ ),
61
+ 'name' => 'terms',
62
+ 'onclick' => 'this.value = this.checked ? 1 : 0;',
63
+ 'required' => true,
64
+ ));
65
+
66
+ /** @var $adminhtmlSession Mage_Adminhtml_Model_Session */
67
+ $adminhtmlSession = Mage::getSingleton('adminhtml/session');
68
+ $merchantDetails = $adminhtmlSession->getData('minkasu_merchant_details', true);
69
+ if ($merchantDetails) {
70
+ $form->setValues($merchantDetails);
71
+ } else {
72
+ $store = Mage::app()->getStore();
73
+ /** @var $paygate Mage_Paygate_Model_Authorizenet */
74
+ $paygate = Mage::getModel('paygate/authorizenet');
75
+ /** @var $helper Minkasu_Wallet_Helper_Data */
76
+ $helper = Mage::helper('minkasu_wallet');
77
+ $form->setValues(array(
78
+ 'name' => Mage::app()->getStore()->getFrontendName(),
79
+ 'phone' => $helper->getStorePhone($store),
80
+ 'email' => $helper->getGeneralEmail($store),
81
+ 'authNet_api_login_id' => $paygate->getConfigData('login'),
82
+ 'authNet_transaction_key' => $paygate->getConfigData('trans_key'),
83
+ 'authNet_gateway' => $this->_getAuthorizeNetGateway((bool) $paygate->getConfigData('test')),
84
+ ));
85
+ }
86
+ return parent::_prepareForm();
87
+ }
88
+
89
+ /**
90
+ * @param bool $isTestMode
91
+ *
92
+ * @return string
93
+ */
94
+ protected function _getAuthorizeNetGateway($isTestMode)
95
+ {
96
+ if ($isTestMode) {
97
+ return Minkasu_Wallet_Model_Api_Type_Merchant::GATEWAY_AUTHORIZENET_SANDBOX;
98
+ } else {
99
+ return Minkasu_Wallet_Model_Api_Type_Merchant::GATEWAY_AUTHORIZENET;
100
+ }
101
+ }
102
+ }
app/code/community/Minkasu/Wallet/Block/Adminhtml/Merchant/Create/Success.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Minkasu_Wallet_Block_Adminhtml_Merchant_Create_Success extends Mage_Adminhtml_Block_Template
4
+ {
5
+ /**
6
+ * @var Minkasu_Wallet_Helper_Api
7
+ */
8
+ protected $_apiHelper;
9
+
10
+ /**
11
+ * {@inheritdoc}
12
+ */
13
+ protected function _construct()
14
+ {
15
+ parent::_construct();
16
+
17
+ $this->_apiHelper = Mage::helper('minkasu_wallet/api');
18
+ }
19
+
20
+ /**
21
+ * @return int
22
+ */
23
+ public function getApiAccountId()
24
+ {
25
+ return $this->_apiHelper->getApiAccountId();
26
+ }
27
+
28
+ /**
29
+ * @return string
30
+ */
31
+ public function getApiToken()
32
+ {
33
+ return $this->_apiHelper->getApiToken();
34
+ }
35
+ }
app/code/community/Minkasu/Wallet/Block/Adminhtml/Merchant/Edit.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Minkasu_Wallet_Block_Adminhtml_Merchant_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
4
+ {
5
+ /**
6
+ * {@inheritdoc}
7
+ */
8
+ public function __construct()
9
+ {
10
+ parent::__construct();
11
+ $this->_objectId = 'object_id';
12
+ $this->_blockGroup = 'minkasu_wallet';
13
+ $this->_controller = 'adminhtml_merchant';
14
+ $this->_mode = 'edit';
15
+ $this->_headerText = Mage::helper('minkasu_wallet')->__('Minkasu Merchant Settings');
16
+
17
+ $this->_removeButton('reset');
18
+ $this->_removeButton('back');
19
+ $this->_updateButton('save', 'label', Mage::helper('minkasu_wallet')->__('Update'));
20
+ }
21
+ }
app/code/community/Minkasu/Wallet/Block/Adminhtml/Merchant/Edit/Form.php ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Minkasu_Wallet_Block_Adminhtml_Merchant_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
4
+ {
5
+ /**
6
+ * {@inheritdoc}
7
+ */
8
+ protected function _prepareForm()
9
+ {
10
+ $form = new Varien_Data_Form(array(
11
+ 'id' => 'edit_form',
12
+ 'method' => 'post',
13
+ 'action' => $this->getUrl('*/*/update', array('_current' => true)),
14
+ ));
15
+
16
+ $form->setUseContainer(true);
17
+ $this->setForm($form);
18
+
19
+ $generalFieldset = $form->addFieldset('general', array('legend' => $this->__('Authorize.net Information')));
20
+ $generalFieldset->addField('authNet_api_login_id', 'text', array(
21
+ 'label' => $this->__('Your Authorize.net API Login ID'),
22
+ 'name' => 'authNet_api_login_id',
23
+ 'required' => true,
24
+ ));
25
+ $generalFieldset->addField('authNet_transaction_key', 'text', array(
26
+ 'label' => $this->__('Your Authorize.net Transaction Key'),
27
+ 'name' => 'authNet_transaction_key',
28
+ 'required' => true,
29
+ ));
30
+ $generalFieldset->addField('authNet_gateway', 'select', array(
31
+ 'label' => $this->__('Authorize.net Test Mode'),
32
+ 'name' => 'authNet_gateway',
33
+ 'options' => array(
34
+ Minkasu_Wallet_Model_Api_Type_Merchant::GATEWAY_AUTHORIZENET_SANDBOX => $this->__('Yes'),
35
+ Minkasu_Wallet_Model_Api_Type_Merchant::GATEWAY_AUTHORIZENET => $this->__('No'),
36
+ ),
37
+ 'required' => true,
38
+ ));
39
+
40
+ /** @var $adminhtmlSession Mage_Adminhtml_Model_Session */
41
+ $adminhtmlSession = Mage::getSingleton('adminhtml/session');
42
+ $merchantDetails = $adminhtmlSession->getData('minkasu_merchant_details', true);
43
+ if ($merchantDetails) {
44
+ $form->setValues($merchantDetails);
45
+ } else {
46
+ /** @var $paygate Mage_Paygate_Model_Authorizenet */
47
+ $paygate = Mage::getModel('paygate/authorizenet');
48
+ $form->setValues(array(
49
+ 'authNet_api_login_id' => $paygate->getConfigData('login'),
50
+ 'authNet_transaction_key' => $paygate->getConfigData('trans_key'),
51
+ 'authNet_gateway' => $this->_getAuthorizeNetGateway((bool) $paygate->getConfigData('test')),
52
+ ));
53
+ }
54
+ return parent::_prepareForm();
55
+ }
56
+
57
+ /**
58
+ * @param bool $isTestMode
59
+ *
60
+ * @return string
61
+ */
62
+ protected function _getAuthorizeNetGateway($isTestMode)
63
+ {
64
+ if ($isTestMode) {
65
+ return Minkasu_Wallet_Model_Api_Type_Merchant::GATEWAY_AUTHORIZENET_SANDBOX;
66
+ } else {
67
+ return Minkasu_Wallet_Model_Api_Type_Merchant::GATEWAY_AUTHORIZENET;
68
+ }
69
+ }
70
+ }
app/code/community/Minkasu/Wallet/Block/Adminhtml/System/Config/Frontend/MinkasuGroup.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Minkasu_Wallet_Block_Adminhtml_System_Config_Frontend_MinkasuGroup
4
+ extends Mage_Adminhtml_Block_System_Config_Form_Fieldset
5
+ {
6
+ /**
7
+ * {@inheritdoc}
8
+ */
9
+ protected function _getHeaderCommentHtml($element)
10
+ {
11
+ /** @var $apiHelper Minkasu_Wallet_Helper_Api */
12
+ $apiHelper = Mage::helper('minkasu_wallet/api');
13
+ if ($apiHelper->getApiAccountId() && $apiHelper->getApiToken()) {
14
+ $linkName = 'Edit your Minkasu account';
15
+ } else {
16
+ $linkName = 'Create a Minkasu account';
17
+ }
18
+ $element->comment = sprintf($element->comment, $apiHelper->__($linkName));
19
+ return parent::_getHeaderCommentHtml($element);
20
+ }
21
+ }
app/code/community/Minkasu/Wallet/Block/Pay.php ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Minkasu_Wallet_Block_Pay extends Mage_Core_Block_Template
3
+ {
4
+ public function _toHtml()
5
+ {
6
+ return parent::_toHtml();
7
+ }
8
+ }
app/code/community/Minkasu/Wallet/Helper/Api.php ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Minkasu_Wallet_Helper_Api extends Mage_Core_Helper_Data
3
+ {
4
+ /**
5
+ * Xml paths
6
+ */
7
+ const XML_PATH_API_GATEWAY_URL = 'payment/minkasu_wallet/gateway_url';
8
+ const XML_PATH_API_ACCOUNT_ID = 'payment/minkasu_wallet/account_id';
9
+ const XML_PATH_API_TOKEN = 'payment/minkasu_wallet/token';
10
+ const XML_PATH_API_ACTIVE = 'payment/minkasu_wallet/active';
11
+
12
+ /**
13
+ * Minkasu API log filename
14
+ */
15
+ const LOG_FILENAME = 'minkasu_api.log';
16
+
17
+ /**
18
+ * @return string
19
+ */
20
+ public function getApiGatewayUrl()
21
+ {
22
+ return rtrim(Mage::getStoreConfig(self::XML_PATH_API_GATEWAY_URL), '/');
23
+ }
24
+
25
+ /**
26
+ * @return int
27
+ */
28
+ public function getApiAccountId()
29
+ {
30
+ return (int) Mage::getStoreConfig(self::XML_PATH_API_ACCOUNT_ID);
31
+ }
32
+
33
+ /**
34
+ * @return string
35
+ */
36
+ public function getApiToken()
37
+ {
38
+ return Mage::getStoreConfig(self::XML_PATH_API_TOKEN);
39
+ }
40
+
41
+ /**
42
+ * @param string $accountId
43
+ *
44
+ * @return $this
45
+ */
46
+ public function saveApiAccountId($accountId)
47
+ {
48
+ $this->_saveConfig(self::XML_PATH_API_ACCOUNT_ID, $accountId);
49
+ return $this;
50
+ }
51
+
52
+ /**
53
+ * @param string $key
54
+ * @param string $value
55
+ *
56
+ * @return $this
57
+ */
58
+ protected function _saveConfig($key, $value)
59
+ {
60
+ /** @var $config Mage_Core_Model_Config */
61
+ $config = Mage::getModel('core/config');
62
+ /** @var $coreHelper Mage_Core_Helper_Data */
63
+ $coreHelper = Mage::helper('core');
64
+ $config->saveConfig($key, $coreHelper->encrypt($value));
65
+ return $this;
66
+ }
67
+
68
+ /**
69
+ * @param string $token
70
+ *
71
+ * @return $this
72
+ */
73
+ public function saveApiToken($token)
74
+ {
75
+ $this->_saveConfig(self::XML_PATH_API_TOKEN, $token);
76
+ return $this;
77
+ }
78
+
79
+ /**
80
+ * @return string
81
+ */
82
+ public function getApiLogFilename()
83
+ {
84
+ return self::LOG_FILENAME;
85
+ }
86
+
87
+ /**
88
+ * @return bool
89
+ */
90
+ public function isApiActive()
91
+ {
92
+ return Mage::getStoreConfigFlag(self::XML_PATH_API_ACTIVE);
93
+ }
94
+ }
app/code/community/Minkasu/Wallet/Helper/Api/Merchant.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Minkasu_Wallet_Helper_Api_Merchant extends Mage_Core_Helper_Data
4
+ {
5
+ /**
6
+ * @var bool
7
+ */
8
+ protected $_isMerchantActive;
9
+
10
+ /**
11
+ * @return bool
12
+ */
13
+ public function isMerchantActive()
14
+ {
15
+ if (null === $this->_isMerchantActive) {
16
+ /** @var $client Minkasu_Wallet_Model_Api_Client */
17
+ $client = Mage::getModel('minkasu_wallet/api_client');
18
+ $result = $client->getType('merchant')->getMerchantStatus();
19
+
20
+ if (Minkasu_Wallet_Model_Api_Type_Merchant::STATUS_ACTIVE === $result['status']) {
21
+ $this->_isMerchantActive = true;
22
+ } elseif (Minkasu_Wallet_Model_Api_Type_Merchant::STATUS_INACTIVE === $result['status']) {
23
+ $this->_isMerchantActive = false;
24
+ } else {
25
+ Mage::throwException($this->__('Wrong merchant status passed.'));
26
+ }
27
+ }
28
+ return $this->_isMerchantActive;
29
+ }
30
+ }
app/code/community/Minkasu/Wallet/Helper/Data.php ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Minkasu_Wallet_Helper_Data extends Mage_Payment_Helper_Data
4
+ {
5
+ /**
6
+ * @param mixed $amount
7
+ *
8
+ * @return int
9
+ */
10
+ public function convertDollarsToCents($amount)
11
+ {
12
+ return $amount * 100;
13
+ }
14
+
15
+ /**
16
+ * @param int $amount
17
+ *
18
+ * @return mixed
19
+ */
20
+ public function convertCentsToDollars($amount)
21
+ {
22
+ return $amount / 100;
23
+ }
24
+
25
+ /**
26
+ * @param null $store
27
+ *
28
+ * @return string
29
+ */
30
+ public function getStorePhone($store = null)
31
+ {
32
+ return Mage::getStoreConfig(Mage_Core_Model_Store::XML_PATH_STORE_STORE_PHONE, $store);
33
+ }
34
+
35
+ /**
36
+ * @param null $store
37
+ *
38
+ * @return string
39
+ */
40
+ public function getGeneralEmail($store = null)
41
+ {
42
+ return Mage::getStoreConfig('trans_email/ident_general/email', $store);
43
+ }
44
+
45
+ /**
46
+ * @return $this
47
+ */
48
+ public function cleanCheckoutSessionParams()
49
+ {
50
+ /** @var $session Mage_Checkout_Model_Session */
51
+ $session = Mage::getSingleton('checkout/session');
52
+ $session->unsetData('minkasu_amount');
53
+ $session->unsetData('minkasu_bill_number');
54
+ $session->unsetData('minkasu_txn_id');
55
+ $session->unsetData('minkasu_payment_token');
56
+ return $this;
57
+ }
58
+ }
app/code/community/Minkasu/Wallet/Model/Api/Adapter/Abstract.php ADDED
@@ -0,0 +1,204 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ abstract class Minkasu_Wallet_Model_Api_Adapter_Abstract
4
+ {
5
+ /**
6
+ * API response formats
7
+ */
8
+ const FORMAT_JSON = 'json';
9
+
10
+ /**
11
+ * Timeout in sec
12
+ */
13
+ const CLIENT_TIMEOUT = 10;
14
+
15
+ /**
16
+ * HTTP Response Codes
17
+ */
18
+ const HTTP_OK = 200;
19
+ const HTTP_CREATED = 201;
20
+ const HTTP_INTERNAL_ERROR = 500;
21
+
22
+ /**
23
+ * The adapter options
24
+ *
25
+ * @var array
26
+ */
27
+ protected $_options = array(
28
+ 'url' => ':url/:type/:id/:action',
29
+ 'format' => self::FORMAT_JSON,
30
+ );
31
+
32
+ /**
33
+ * Instantiate a new adapter
34
+ *
35
+ * @param array $options
36
+ */
37
+ public function __construct(array $options = array())
38
+ {
39
+ $this->_options = array_merge($this->_options, $options);
40
+ }
41
+
42
+ /**
43
+ * Send a request to the server, receive a response
44
+ *
45
+ * @abstract
46
+ * @param string $url
47
+ * @param array $parameters
48
+ * @param string $httpMethod
49
+ * @return string HTTP response
50
+ */
51
+ abstract protected function _doRequest($url, array $parameters = array(), $httpMethod = Varien_Http_Client::GET);
52
+
53
+ /**
54
+ * Send a GET request
55
+ *
56
+ * @param string $type
57
+ * @param array $parameters
58
+ * @return array Data
59
+ */
60
+ public function get($type, array $parameters = array())
61
+ {
62
+ $response = $this->_request($type, $parameters, Varien_Http_Client::GET);
63
+ try {
64
+ $decodedResponse = $this->decodeResponse($response->getBody());
65
+ } catch (Exception $e) {
66
+ Mage::logException($e);
67
+ $decodedResponse = $response->getBody();
68
+ }
69
+
70
+ if (self::HTTP_OK !== $response->getStatus()) {
71
+ /** @var $apiHelper Minkasu_Wallet_Helper_Api */
72
+ $apiHelper = Mage::helper('minkasu_wallet/api');
73
+ /** @var $helper Minkasu_Wallet_Helper_Data */
74
+ $helper = Mage::helper('minkasu_wallet');
75
+
76
+ if (is_array($decodedResponse) && isset($decodedResponse['error'])) {
77
+ $error = $decodedResponse['error'];
78
+ } else {
79
+ $error = $decodedResponse;
80
+ }
81
+
82
+ Mage::log(
83
+ $helper->__(
84
+ 'API type: %s. Params: %s. HTTP code: %s. Response: %s.',
85
+ $type, json_encode($parameters), $response->getStatus(), $response->getBody()
86
+ ),
87
+ null,
88
+ $apiHelper->getApiLogFilename()
89
+ );
90
+ Mage::throwException($helper->__('Minkasu API error has been occurred. Error: %s.', $error));
91
+ }
92
+ return $decodedResponse;
93
+ }
94
+
95
+ /**
96
+ * Send a POST request
97
+ *
98
+ * @param string $type
99
+ * @param array $parameters
100
+ * @return array Data
101
+ */
102
+ public function post($type, array $parameters = array())
103
+ {
104
+ $response = $this->_request($type, $parameters, Varien_Http_Client::POST);
105
+ try {
106
+ $decodedResponse = $this->decodeResponse($response->getBody());
107
+ } catch (Exception $e) {
108
+ Mage::logException($e);
109
+ $decodedResponse = $response->getBody();
110
+ }
111
+
112
+ if (self::HTTP_OK !== $response->getStatus()) {
113
+ /** @var $apiHelper Minkasu_Wallet_Helper_Api */
114
+ $apiHelper = Mage::helper('minkasu_wallet/api');
115
+ /** @var $helper Minkasu_Wallet_Helper_Data */
116
+ $helper = Mage::helper('minkasu_wallet');
117
+
118
+ if (is_array($decodedResponse) && isset($decodedResponse['error'])) {
119
+ $error = $decodedResponse['error'];
120
+ } else {
121
+ $error = $decodedResponse;
122
+ }
123
+
124
+ Mage::log(
125
+ $helper->__(
126
+ 'API type: %s. Params: %s. HTTP code: %s. Response: %s.',
127
+ $type, json_encode($parameters), $response->getStatus(), $response->getBody()
128
+ ),
129
+ null,
130
+ $apiHelper->getApiLogFilename()
131
+ );
132
+ Mage::throwException($helper->__('Minkasu API error has been occurred. Error: %s.', $error));
133
+ }
134
+ return $decodedResponse;
135
+ }
136
+
137
+ /**
138
+ * Send a request to the server, receive a response,
139
+ * decode the response and returns a SimpleXMLElement object or an associative array
140
+ *
141
+ * @param string $type
142
+ * @param array $parameters
143
+ * @param string $httpMethod
144
+ * @return Zend_Http_Response
145
+ */
146
+ protected function _request($type, array $parameters = array(), $httpMethod = Varien_Http_Client::GET)
147
+ {
148
+ /** @var $apiHelper Minkasu_Wallet_Helper_Api */
149
+ $apiHelper = Mage::helper('minkasu_wallet/api');
150
+
151
+ $url = strtr($this->_options['url'], array(
152
+ ':url' => $apiHelper->getApiGatewayUrl(),
153
+ ':type' => $type,
154
+ ));
155
+ if (isset($parameters[':id'])) {
156
+ $url = str_replace(':id', $parameters[':id'], $url);
157
+ unset($parameters[':id']);
158
+ } else {
159
+ $url = str_replace(':id', '', $url);
160
+ }
161
+ if (isset($parameters[':action'])) {
162
+ $url = str_replace(':action', $parameters[':action'], $url);
163
+ unset($parameters[':action']);
164
+ } else {
165
+ $url = str_replace(':action', '', $url);
166
+ }
167
+ $url = rtrim($url, '/');
168
+
169
+ return $this->_doRequest($url, $parameters, $httpMethod);
170
+ }
171
+
172
+ /**
173
+ * Get encoded response and transform it to a PHP array or a SimpleXMLElement object
174
+ *
175
+ * @param string $response
176
+ * @return array|SimpleXMLElement
177
+ */
178
+ public function decodeResponse($response)
179
+ {
180
+ /** @var $format Minkasu_Wallet_Model_Api_Format_Abstract */
181
+ $format = Mage::getSingleton("minkasu_wallet/api_format_{$this->_options['format']}");
182
+
183
+ if (false === $format || !$format instanceof Minkasu_Wallet_Model_Api_Format_Abstract) {
184
+ Mage::throwException("Format '{$this->_options['format']}' not found.");
185
+ }
186
+
187
+ return $format->decodeResponse($response);
188
+ }
189
+
190
+ /**
191
+ * Change an option value.
192
+ *
193
+ * @param string $name
194
+ * @param mixed $value
195
+ *
196
+ * @return Minkasu_Wallet_Model_Api_Adapter_Abstract
197
+ */
198
+ public function setOption($name, $value)
199
+ {
200
+ $this->_options[$name] = $value;
201
+
202
+ return $this;
203
+ }
204
+ }
app/code/community/Minkasu/Wallet/Model/Api/Adapter/Curl.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Minkasu_Wallet_Model_Api_Adapter_Curl extends Minkasu_Wallet_Model_Api_Adapter_Abstract
4
+ {
5
+ /**
6
+ * Send a request to the server, receive a response
7
+ *
8
+ * @param string $url
9
+ * @param array $parameters
10
+ * @param string $httpMethod
11
+ * @return Zend_Http_Response
12
+ */
13
+ protected function _doRequest($url, array $parameters = array(), $httpMethod = Varien_Http_Client::GET)
14
+ {
15
+ $client = new Varien_Http_Client();
16
+ $client->setConfig(array(
17
+ 'timeout' => self::CLIENT_TIMEOUT,
18
+ ));
19
+ $client->resetParameters(true);
20
+ $client->setUri($url);
21
+ $client->setMethod($httpMethod);
22
+
23
+ if (isset($parameters['headers'])) {
24
+ $client->setConfig(array('strict' => false));
25
+ $client->setHeaders($parameters['headers']);
26
+ unset($parameters['headers']);
27
+ }
28
+
29
+ if (Varien_Http_Client::GET == $httpMethod) {
30
+ $client->setParameterGet($parameters);
31
+ } elseif (Varien_Http_Client::POST == $httpMethod) {
32
+ $client->setParameterPost($parameters);
33
+ } else {
34
+ Mage::throwException("Invalid http request method '{$httpMethod}'.");
35
+ }
36
+
37
+ return $client->request();
38
+ }
39
+ }
app/code/community/Minkasu/Wallet/Model/Api/Client.php ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Minkasu_Wallet_Model_Api_Client
4
+ {
5
+ /**
6
+ * @var Minkasu_Wallet_Model_Api_Adapter_Abstract
7
+ */
8
+ protected $_adapter;
9
+
10
+ /**
11
+ * The list of loaded API type instances
12
+ *
13
+ * @var array
14
+ */
15
+ protected $_types = array();
16
+
17
+ /**
18
+ * Instantiate a new adapter
19
+ *
20
+ * @param Minkasu_Wallet_Model_Api_Adapter_Abstract $adapter Custom adapter
21
+ */
22
+ public function __construct($adapter = null)
23
+ {
24
+ if (empty($adapter)) {
25
+ $this->setAdapter(Mage::getSingleton('minkasu_wallet/api_adapter_curl'));
26
+ } elseif ($adapter instanceof Minkasu_Wallet_Model_Api_Adapter_Abstract) {
27
+ $this->setAdapter($adapter);
28
+ } else {
29
+ Mage::throwException('Invalid client');
30
+ }
31
+ }
32
+
33
+ /**
34
+ * Call any type, GET method
35
+ *
36
+ * @param string $type
37
+ * @param array $parameters
38
+ * @return array
39
+ */
40
+ public function get($type, array $parameters = array())
41
+ {
42
+ return $this->getAdapter()->get($type, $parameters);
43
+ }
44
+
45
+ /**
46
+ * Call any type, POST method
47
+ *
48
+ * @param string $type
49
+ * @param array $parameters
50
+ * @return array
51
+ */
52
+ public function post($type, array $parameters = array())
53
+ {
54
+ return $this->getAdapter()->post($type, $parameters);
55
+ }
56
+
57
+ /**
58
+ * Get the adapter
59
+ *
60
+ * @return Minkasu_Wallet_Model_Api_Adapter_Abstract
61
+ */
62
+ public function getAdapter()
63
+ {
64
+ return $this->_adapter;
65
+ }
66
+
67
+ /**
68
+ * Inject another adapter
69
+ *
70
+ * @param Minkasu_Wallet_Model_Api_Adapter_Abstract $adapter
71
+ * @return Minkasu_Wallet_Model_Api_Client
72
+ */
73
+ public function setAdapter(Minkasu_Wallet_Model_Api_Adapter_Abstract $adapter)
74
+ {
75
+ $this->_adapter = $adapter;
76
+
77
+ return $this;
78
+ }
79
+
80
+ /**
81
+ * Inject an API type instance
82
+ *
83
+ * @param string $name
84
+ * @param Minkasu_Wallet_Model_Api_Type_Abstract $instance
85
+ *
86
+ * @return Minkasu_Wallet_Model_Api_Client
87
+ */
88
+ public function setType($name, Minkasu_Wallet_Model_Api_Type_Abstract $instance)
89
+ {
90
+ $this->_types[$name] = $instance;
91
+
92
+ return $this;
93
+ }
94
+
95
+ /**
96
+ * Get any API type instance
97
+ *
98
+ * @param string $name
99
+ * @return Minkasu_Wallet_Model_Api_Type_Abstract
100
+ */
101
+ public function getType($name)
102
+ {
103
+ if (!isset($this->_types[$name])) {
104
+ /** @var $type Minkasu_Wallet_Model_Api_Type_Abstract */
105
+ $type = Mage::getSingleton("minkasu_wallet/api_type_{$name}", array($this));
106
+
107
+ if (false === $type || !$type instanceof Minkasu_Wallet_Model_Api_Type_Abstract) {
108
+ Mage::throwException("Type '{$name}' not found.");
109
+ }
110
+ $this->setType($name, $type);
111
+ }
112
+
113
+ return $this->_types[$name];
114
+ }
115
+ }
app/code/community/Minkasu/Wallet/Model/Api/Format/Abstract.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ abstract class Minkasu_Wallet_Model_Api_Format_Abstract
4
+ {
5
+ /**
6
+ * Decode an http response to a PHP array
7
+ *
8
+ * @abstract
9
+ * @param string $response
10
+ * @return array
11
+ */
12
+ abstract public function decodeResponse($response);
13
+ }
app/code/community/Minkasu/Wallet/Model/Api/Format/Json.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Minkasu_Wallet_Model_Api_Format_Json extends Minkasu_Wallet_Model_Api_Format_Abstract
4
+ {
5
+ /**
6
+ * Decode a json response to a PHP array
7
+ *
8
+ * @param string $response
9
+ * @return array
10
+ */
11
+ public function decodeResponse($response)
12
+ {
13
+ /** @var $helper Mage_Core_Helper_Data */
14
+ $helper = Mage::helper('core');
15
+ return $helper->jsonDecode($response);
16
+ }
17
+ }
app/code/community/Minkasu/Wallet/Model/Api/Type/Abstract.php ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ abstract class Minkasu_Wallet_Model_Api_Type_Abstract
4
+ {
5
+ /**
6
+ * API type request params
7
+ */
8
+ const PARAM_NAME_ACCOUNT_ID = 'merchant_acct_id';
9
+ const PARAM_NAME_TOKEN = 'minkasu_token';
10
+
11
+ /**
12
+ * The client
13
+ *
14
+ * @var Minkasu_Wallet_Model_Api_Client
15
+ */
16
+ protected $_client;
17
+
18
+ /**
19
+ * The client
20
+ *
21
+ * @param array $params
22
+ */
23
+ public function __construct(array $params)
24
+ {
25
+ $this->_client = array_shift($params);
26
+ }
27
+
28
+ /**
29
+ * Call any type, GET method
30
+ *
31
+ * @param array $parameters
32
+ * @return array
33
+ */
34
+ public function get(array $parameters = array())
35
+ {
36
+ return $this->_client->get($this->_getApiName(), $parameters);
37
+ }
38
+
39
+ /**
40
+ * Call any type, POST method
41
+ *
42
+ * @param array $parameters
43
+ * @return array
44
+ */
45
+ public function post(array $parameters = array())
46
+ {
47
+ return $this->_client->post($this->_getApiName(), $parameters);
48
+ }
49
+
50
+ /**
51
+ * Get API type name
52
+ *
53
+ * @return string
54
+ */
55
+ abstract protected function _getApiName();
56
+ }
app/code/community/Minkasu/Wallet/Model/Api/Type/Merchant.php ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Minkasu_Wallet_Model_Api_Type_Merchant extends Minkasu_Wallet_Model_Api_Type_Abstract
4
+ {
5
+ /**
6
+ * Type API name
7
+ */
8
+ const API_NAME = 'merchant';
9
+
10
+ /**
11
+ * Supported gateways
12
+ */
13
+ const GATEWAY_AUTHORIZENET = 'AuthorizeNet';
14
+ const GATEWAY_AUTHORIZENET_SANDBOX = 'AuthorizeNetSandBox';
15
+
16
+ /**
17
+ * Operations with a merchant
18
+ */
19
+ const OPERATION_CREATE = 'new_merchant_signup';
20
+
21
+ /**
22
+ * Merchant channel name
23
+ */
24
+ const CHANNEL_NAME = 'magento';
25
+
26
+ /**
27
+ * Merchant statuses
28
+ */
29
+ const STATUS_ACTIVE = 'A';
30
+ const STATUS_INACTIVE = 'I';
31
+
32
+ /**
33
+ * @return string
34
+ */
35
+ protected function _getApiName()
36
+ {
37
+ return self::API_NAME;
38
+ }
39
+
40
+ /**
41
+ * Create a Minkasu merchant
42
+ *
43
+ * @param array $merchantData
44
+ * @param array $gatewayData
45
+ *
46
+ * @return array
47
+ */
48
+ public function createMerchant(array $merchantData, array $gatewayData)
49
+ {
50
+ $params = array_merge(
51
+ $merchantData,
52
+ array(
53
+ 'operation' => self::OPERATION_CREATE,
54
+ 'generate_token' => true,
55
+ 'channel' => self::CHANNEL_NAME,
56
+ 'update_gw_credentials' => true,
57
+ 'username' => '',
58
+ 'passwd' => '',
59
+ )
60
+ );
61
+ $params['gw_details'] = $gatewayData;
62
+
63
+ return $this->post($params);
64
+ }
65
+
66
+ /**
67
+ * Create a Minkasu merchant gateway
68
+ *
69
+ * @param array $gatewayData
70
+ *
71
+ * @return array
72
+ */
73
+ public function updateMerchantGateway(array $gatewayData)
74
+ {
75
+ /** @var $apiHelper Minkasu_Wallet_Helper_Api */
76
+ $apiHelper = Mage::helper('minkasu_wallet/api');
77
+ $params = array(
78
+ 'login_id' => $gatewayData['login_id'],
79
+ 'key' => $gatewayData['key'],
80
+ 'test_mode' => $gatewayData['test_mode'],
81
+ ':id' => $apiHelper->getApiAccountId(),
82
+ ':action' => 'gateway',
83
+ 'headers' => array(
84
+ 'merchant_acct_id' => $apiHelper->getApiAccountId(),
85
+ 'minkasu_token' => $apiHelper->getApiToken(),
86
+ ),
87
+ );
88
+ return $this->post($params);
89
+ }
90
+
91
+ /**
92
+ * @return array
93
+ */
94
+ public function getMerchantStatus()
95
+ {
96
+ /** @var $apiHelper Minkasu_Wallet_Helper_Api */
97
+ $apiHelper = Mage::helper('minkasu_wallet/api');
98
+ $params = array(
99
+ ':id' => $apiHelper->getApiAccountId(),
100
+ ':action' => 'status',
101
+ 'headers' => array(
102
+ 'merchant_acct_id' => $apiHelper->getApiAccountId(),
103
+ 'minkasu_token' => $apiHelper->getApiToken(),
104
+ ),
105
+ );
106
+ return $this->get($params);
107
+ }
108
+
109
+ /**
110
+ * @return array
111
+ */
112
+ public function activateMerchant()
113
+ {
114
+ /** @var $apiHelper Minkasu_Wallet_Helper_Api */
115
+ $apiHelper = Mage::helper('minkasu_wallet/api');
116
+ $params = array(
117
+ 'merchant_acct_id' => $apiHelper->getApiAccountId(),
118
+ 'minkasu_token' => $apiHelper->getApiToken(),
119
+ 'status' => self::STATUS_ACTIVE,
120
+ ':id' => $apiHelper->getApiAccountId(),
121
+ ':action' => 'status',
122
+ );
123
+ return $this->post($params);
124
+ }
125
+
126
+ /**
127
+ * @return array
128
+ */
129
+ public function deactivateMerchant()
130
+ {
131
+ /** @var $apiHelper Minkasu_Wallet_Helper_Api */
132
+ $apiHelper = Mage::helper('minkasu_wallet/api');
133
+ $params = array(
134
+ 'merchant_acct_id' => $apiHelper->getApiAccountId(),
135
+ 'minkasu_token' => $apiHelper->getApiToken(),
136
+ 'status' => self::STATUS_INACTIVE,
137
+ ':id' => $apiHelper->getApiAccountId(),
138
+ ':action' => 'status',
139
+ );
140
+ return $this->post($params);
141
+ }
142
+ }
app/code/community/Minkasu/Wallet/Model/Api/Type/Transaction.php ADDED
@@ -0,0 +1,289 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Minkasu_Wallet_Model_Api_Type_Transaction extends Minkasu_Wallet_Model_Api_Type_Abstract
4
+ {
5
+ /**
6
+ * Field names
7
+ */
8
+ const FIELD_NAME_PAYMENT_CODE = 'payment_code';
9
+ const FIELD_NAME_STATUS = 'status';
10
+ const FIELD_NAME_ACTION = 'act';
11
+
12
+ /**
13
+ * Operations with a transaction
14
+ */
15
+ const OPERATION_CREATE = 'new_transaction';
16
+ const OPERATION_UPDATE = 'update_transaction_details';
17
+ const OPERATION_AUTHORIZE = 'authorize';
18
+ const OPERATION_CAPTURE = 'capture';
19
+ const OPERATION_CANCEL = 'cancel';
20
+ const OPERATION_REFUND = 'refund';
21
+ const OPERATION_VOID = 'void';
22
+
23
+ /**
24
+ * Type API name
25
+ */
26
+ const API_NAME = 'transactions';
27
+
28
+ /**
29
+ * Transaction states
30
+ */
31
+ const STATE_CREATED = 0;
32
+ const STATE_AUTHORIZED = 1;
33
+ const STATE_CAPTURED = 2;
34
+ const STATE_CANCELED = 3;
35
+ const STATE_CREDITED = 4;
36
+ const STATE_PREAUTHED = 5;
37
+ const STATE_PREAUTH_VOIDED = 6;
38
+
39
+ /**
40
+ * Get payment code of a transaction id
41
+ *
42
+ * @param int $transactionId
43
+ * @return array
44
+ */
45
+ public function getPaymentCode($transactionId)
46
+ {
47
+ $params = array(
48
+ ':id' => $transactionId,
49
+ ':field' => self::FIELD_NAME_PAYMENT_CODE,
50
+ );
51
+ return $this->get($params);
52
+ }
53
+
54
+ /**
55
+ * Create a Minkasu transaction
56
+ *
57
+ * @param Mage_Sales_Model_Quote $quote
58
+ * @return array
59
+ */
60
+ public function createTransaction(Mage_Sales_Model_Quote $quote, array $expectedShippingInfo)
61
+ {
62
+ /** @var $apiHelper Minkasu_Wallet_Helper_Api */
63
+ $apiHelper = Mage::helper('minkasu_wallet/api');
64
+ /** @var $walletHelper Minkasu_Wallet_Helper_Data */
65
+ $walletHelper = Mage::helper('minkasu_wallet');
66
+
67
+ $params = array(
68
+ 'operation' => self::OPERATION_CREATE,
69
+ 'amount' => $walletHelper->convertDollarsToCents($quote->getGrandTotal()),
70
+ 'merchant_acct_id' => $apiHelper->getApiAccountId(),
71
+ 'merchant_bill_number' => $quote->getId(),
72
+ 'minkasu_token' => $apiHelper->getApiToken(),
73
+ 'beta_code' => 'mkbeta3314'
74
+ );
75
+
76
+ if ($expectedShippingInfo) {
77
+ $params['expected_shipping_info'] = $expectedShippingInfo;
78
+ }
79
+
80
+ return $this->post($params);
81
+ }
82
+
83
+ /**
84
+ * Update a Minkasu transaction
85
+ *
86
+ * @param $transactionId
87
+ * @param array $transactionData
88
+ * @return array
89
+ */
90
+ public function updateTransaction($transactionId, array $transactionData, array $expectedShippingInfo)
91
+ {
92
+ /** @var $apiHelper Minkasu_Wallet_Helper_Api */
93
+ $apiHelper = Mage::helper('minkasu_wallet/api');
94
+
95
+ $params = array(
96
+ 'operation' => self::OPERATION_UPDATE,
97
+ 'merchant_acct_id' => $apiHelper->getApiAccountId(),
98
+ 'minkasu_token' => $apiHelper->getApiToken(),
99
+ 'beta_code' => 'mkbeta3314',
100
+ ':id' => $transactionId,
101
+ );
102
+ $params = array_merge($params, $transactionData);
103
+ if ($expectedShippingInfo != NULL) {
104
+ $params['expected_shipping_info'] = $expectedShippingInfo;
105
+ }
106
+
107
+ return $this->post($params);
108
+ }
109
+
110
+ /**
111
+ * Authorize a Minkasu transaction
112
+ *
113
+ * @param string $transactionId
114
+ * @param string $paymentToken
115
+ *
116
+ * @return array
117
+ */
118
+ public function authorizeTransaction($transactionId, $paymentToken, $amount)
119
+ {
120
+ /** @var $walletHelper Minkasu_Wallet_Helper_Data */
121
+ $walletHelper = Mage::helper('minkasu_wallet');
122
+ /** @var $apiHelper Minkasu_Wallet_Helper_Api */
123
+ $apiHelper = Mage::helper('minkasu_wallet/api');
124
+
125
+ $params = array(
126
+ 'operation' => self::OPERATION_AUTHORIZE,
127
+ 'authorize_amount' => $walletHelper->convertDollarsToCents($amount),
128
+ 'merchant_acct_id' => $apiHelper->getApiAccountId(),
129
+ 'minkasu_token' => $apiHelper->getApiToken(),
130
+ 'payment_token' => $paymentToken,
131
+ ':id' => $transactionId,
132
+ ':action' => self::FIELD_NAME_ACTION,
133
+ );
134
+
135
+ return $this->post($params);
136
+ }
137
+
138
+ /**
139
+ * Capture a Minkasu transaction
140
+ *
141
+ * @param string $transactionId
142
+ *
143
+ * @return array
144
+ */
145
+ public function captureTransaction($transactionId, $amount)
146
+ {
147
+
148
+ /** @var $walletHelper Minkasu_Wallet_Helper_Data */
149
+ $walletHelper = Mage::helper('minkasu_wallet');
150
+ /** @var $apiHelper Minkasu_Wallet_Helper_Api */
151
+ $apiHelper = Mage::helper('minkasu_wallet/api');
152
+
153
+ $params = array(
154
+ 'operation' => self::OPERATION_CAPTURE,
155
+ 'capture_amount' => $walletHelper->convertDollarsToCents($amount),
156
+ 'merchant_acct_id' => $apiHelper->getApiAccountId(),
157
+ 'minkasu_token' => $apiHelper->getApiToken(),
158
+ ':id' => $transactionId,
159
+ ':action' => self::FIELD_NAME_ACTION,
160
+ );
161
+
162
+ return $this->post($params);
163
+ }
164
+
165
+ /**
166
+ * Cancel a Minkasu transaction
167
+ *
168
+ * @param string $transactionId
169
+ *
170
+ * @return array
171
+ */
172
+ public function cancelTransaction($transactionId)
173
+ {
174
+ /** @var $apiHelper Minkasu_Wallet_Helper_Api */
175
+ $apiHelper = Mage::helper('minkasu_wallet/api');
176
+
177
+ $params = array(
178
+ 'operation' => self::OPERATION_CANCEL,
179
+ 'merchant_acct_id' => $apiHelper->getApiAccountId(),
180
+ 'minkasu_token' => $apiHelper->getApiToken(),
181
+ ':id' => $transactionId,
182
+ ':action' => self::FIELD_NAME_ACTION,
183
+ );
184
+
185
+ return $this->post($params);
186
+ }
187
+
188
+ /**
189
+ * Refund a Minkasu transaction
190
+ *
191
+ * @param string $transactionId
192
+ *
193
+ * @return array
194
+ */
195
+ public function refundTransaction($transactionId, $amount)
196
+ {
197
+ /** @var $walletHelper Minkasu_Wallet_Helper_Data */
198
+ $walletHelper = Mage::helper('minkasu_wallet');
199
+ /** @var $apiHelper Minkasu_Wallet_Helper_Api */
200
+ $apiHelper = Mage::helper('minkasu_wallet/api');
201
+
202
+ $params = array(
203
+ 'operation' => self::OPERATION_REFUND,
204
+ 'merchant_acct_id' => $apiHelper->getApiAccountId(),
205
+ 'minkasu_token' => $apiHelper->getApiToken(),
206
+ 'refund_amount' => $walletHelper->convertDollarsToCents($amount),
207
+ ':id' => $transactionId,
208
+ ':action' => self::FIELD_NAME_ACTION,
209
+ );
210
+
211
+ return $this->post($params);
212
+ }
213
+
214
+ /**
215
+ * Get a Minkasu transaction
216
+ *
217
+ * @param string $transactionId
218
+ *
219
+ * @return array
220
+ */
221
+ public function getTransaction($transactionId)
222
+ {
223
+ /** @var $apiHelper Minkasu_Wallet_Helper_Api */
224
+ $apiHelper = Mage::helper('minkasu_wallet/api');
225
+
226
+ $url = sprintf('%s/%s/%s', $apiHelper->getApiGatewayUrl(), $this->_getApiName(), $transactionId);
227
+ $data = array(
228
+ 'merchant_acct_id' => $apiHelper->getApiAccountId(),
229
+ 'minkasu_token' => $apiHelper->getApiToken()
230
+ );
231
+ $query = http_build_query($data);
232
+ $options = array(
233
+ 'http' => array(
234
+ 'header' => "Content-Type: application/x-www-form-urlencoded\r\nContent-Length: " . strlen($query),
235
+ 'method' => Varien_Http_Client::GET,
236
+ 'content' => $query,
237
+ ),
238
+ );
239
+ $context = stream_context_create($options);
240
+ $result = file_get_contents($url, false, $context);
241
+ return json_decode($result, true);
242
+ }
243
+
244
+ /**
245
+ * Void a Minkasu transaction
246
+ *
247
+ * @param string $transactionId
248
+ *
249
+ * @return array
250
+ */
251
+ public function voidTransaction($transactionId)
252
+ {
253
+ /** @var $apiHelper Minkasu_Wallet_Helper_Api */
254
+ $apiHelper = Mage::helper('minkasu_wallet/api');
255
+
256
+ $params = array(
257
+ 'operation' => self::OPERATION_VOID,
258
+ 'merchant_acct_id' => $apiHelper->getApiAccountId(),
259
+ 'minkasu_token' => $apiHelper->getApiToken(),
260
+ ':id' => $transactionId,
261
+ ':action' => self::FIELD_NAME_ACTION,
262
+ );
263
+
264
+ return $this->post($params);
265
+ }
266
+
267
+ /**
268
+ * @param string $transactionId
269
+ *
270
+ * @return array
271
+ */
272
+ public function getTransactionStatus($transactionId)
273
+ {
274
+ $params = array(
275
+ ':id' => $transactionId,
276
+ ':action' => self::FIELD_NAME_STATUS
277
+ );
278
+
279
+ return $this->get($params);
280
+ }
281
+
282
+ /**
283
+ * @return string
284
+ */
285
+ protected function _getApiName()
286
+ {
287
+ return self::API_NAME;
288
+ }
289
+ }
app/code/community/Minkasu/Wallet/Model/Api/Type/Transaction.php~ ADDED
@@ -0,0 +1,275 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Minkasu_Wallet_Model_Api_Type_Transaction extends Minkasu_Wallet_Model_Api_Type_Abstract
4
+ {
5
+ /**
6
+ * Field names
7
+ */
8
+ const FIELD_NAME_PAYMENT_CODE = 'payment_code';
9
+ const FIELD_NAME_STATUS = 'status';
10
+ const FIELD_NAME_ACTION = 'act';
11
+
12
+ /**
13
+ * Operations with a transaction
14
+ */
15
+ const OPERATION_CREATE = 'new_transaction';
16
+ const OPERATION_UPDATE = 'update_transaction_details';
17
+ const OPERATION_AUTHORIZE = 'authorize';
18
+ const OPERATION_CAPTURE = 'capture';
19
+ const OPERATION_CANCEL = 'cancel';
20
+ const OPERATION_REFUND = 'refund';
21
+ const OPERATION_VOID = 'void';
22
+
23
+ /**
24
+ * Type API name
25
+ */
26
+ const API_NAME = 'transactions';
27
+
28
+ /**
29
+ * Transaction states
30
+ */
31
+ const STATE_CREATED = 0;
32
+ const STATE_AUTHORIZED = 1;
33
+ const STATE_CAPTURED = 2;
34
+ const STATE_CANCELED = 3;
35
+ const STATE_CREDITED = 4;
36
+ const STATE_PREAUTHED = 5;
37
+ const STATE_PREAUTH_VOIDED = 6;
38
+
39
+ /**
40
+ * Get payment code of a transaction id
41
+ *
42
+ * @param int $transactionId
43
+ * @return array
44
+ */
45
+ public function getPaymentCode($transactionId)
46
+ {
47
+ $params = array(
48
+ ':id' => $transactionId,
49
+ ':field' => self::FIELD_NAME_PAYMENT_CODE,
50
+ );
51
+ return $this->get($params);
52
+ }
53
+
54
+ /**
55
+ * Create a Minkasu transaction
56
+ *
57
+ * @param Mage_Sales_Model_Quote $quote
58
+ * @return array
59
+ */
60
+ public function createTransaction(Mage_Sales_Model_Quote $quote)
61
+ {
62
+ /** @var $apiHelper Minkasu_Wallet_Helper_Api */
63
+ $apiHelper = Mage::helper('minkasu_wallet/api');
64
+ /** @var $walletHelper Minkasu_Wallet_Helper_Data */
65
+ $walletHelper = Mage::helper('minkasu_wallet');
66
+
67
+ $params = array(
68
+ 'operation' => self::OPERATION_CREATE,
69
+ 'amount' => $walletHelper->convertDollarsToCents($quote->getGrandTotal()),
70
+ 'merchant_acct_id' => $apiHelper->getApiAccountId(),
71
+ 'merchant_bill_number' => $quote->getId(),
72
+ 'minkasu_token' => $apiHelper->getApiToken(),
73
+ 'beta_code' => 'mkbeta3314'
74
+ );
75
+
76
+ return $this->post($params);
77
+ }
78
+
79
+ /**
80
+ * Update a Minkasu transaction
81
+ *
82
+ * @param $transactionId
83
+ * @param array $transactionData
84
+ * @return array
85
+ */
86
+ public function updateTransaction($transactionId, array $transactionData)
87
+ {
88
+ /** @var $apiHelper Minkasu_Wallet_Helper_Api */
89
+ $apiHelper = Mage::helper('minkasu_wallet/api');
90
+
91
+ $params = array(
92
+ 'operation' => self::OPERATION_UPDATE,
93
+ 'merchant_acct_id' => $apiHelper->getApiAccountId(),
94
+ 'minkasu_token' => $apiHelper->getApiToken(),
95
+ 'beta_code' => 'mkbeta3314',
96
+ ':id' => $transactionId,
97
+ );
98
+ $params = array_merge($params, $transactionData);
99
+
100
+ return $this->post($params);
101
+ }
102
+
103
+ /**
104
+ * Authorize a Minkasu transaction
105
+ *
106
+ * @param string $transactionId
107
+ * @param string $paymentToken
108
+ *
109
+ * @return array
110
+ */
111
+ public function authorizeTransaction($transactionId, $paymentToken)
112
+ {
113
+ /** @var $apiHelper Minkasu_Wallet_Helper_Api */
114
+ $apiHelper = Mage::helper('minkasu_wallet/api');
115
+
116
+ $params = array(
117
+ 'operation' => self::OPERATION_AUTHORIZE,
118
+ 'merchant_acct_id' => $apiHelper->getApiAccountId(),
119
+ 'minkasu_token' => $apiHelper->getApiToken(),
120
+ 'payment_token' => $paymentToken,
121
+ ':id' => $transactionId,
122
+ ':action' => self::FIELD_NAME_ACTION,
123
+ );
124
+
125
+ return $this->post($params);
126
+ }
127
+
128
+ /**
129
+ * Capture a Minkasu transaction
130
+ *
131
+ * @param string $transactionId
132
+ *
133
+ * @return array
134
+ */
135
+ public function captureTransaction($transactionId)
136
+ {
137
+ /** @var $apiHelper Minkasu_Wallet_Helper_Api */
138
+ $apiHelper = Mage::helper('minkasu_wallet/api');
139
+
140
+ $params = array(
141
+ 'operation' => self::OPERATION_CAPTURE,
142
+ 'merchant_acct_id' => $apiHelper->getApiAccountId(),
143
+ 'minkasu_token' => $apiHelper->getApiToken(),
144
+ ':id' => $transactionId,
145
+ ':action' => self::FIELD_NAME_ACTION,
146
+ );
147
+
148
+ return $this->post($params);
149
+ }
150
+
151
+ /**
152
+ * Cancel a Minkasu transaction
153
+ *
154
+ * @param string $transactionId
155
+ *
156
+ * @return array
157
+ */
158
+ public function cancelTransaction($transactionId)
159
+ {
160
+ /** @var $apiHelper Minkasu_Wallet_Helper_Api */
161
+ $apiHelper = Mage::helper('minkasu_wallet/api');
162
+
163
+ $params = array(
164
+ 'operation' => self::OPERATION_CANCEL,
165
+ 'merchant_acct_id' => $apiHelper->getApiAccountId(),
166
+ 'minkasu_token' => $apiHelper->getApiToken(),
167
+ ':id' => $transactionId,
168
+ ':action' => self::FIELD_NAME_ACTION,
169
+ );
170
+
171
+ return $this->post($params);
172
+ }
173
+
174
+ /**
175
+ * Refund a Minkasu transaction
176
+ *
177
+ * @param string $transactionId
178
+ *
179
+ * @return array
180
+ */
181
+ public function refundTransaction($transactionId, $amount)
182
+ {
183
+ /** @var $walletHelper Minkasu_Wallet_Helper_Data */
184
+ $walletHelper = Mage::helper('minkasu_wallet');
185
+ /** @var $apiHelper Minkasu_Wallet_Helper_Api */
186
+ $apiHelper = Mage::helper('minkasu_wallet/api');
187
+
188
+ $params = array(
189
+ 'operation' => self::OPERATION_REFUND,
190
+ 'merchant_acct_id' => $apiHelper->getApiAccountId(),
191
+ 'minkasu_token' => $apiHelper->getApiToken(),
192
+ 'refund_amount' => $walletHelper->convertDollarsToCents($amount),
193
+ ':id' => $transactionId,
194
+ ':action' => self::FIELD_NAME_ACTION,
195
+ );
196
+
197
+ return $this->post($params);
198
+ }
199
+
200
+ /**
201
+ * Get a Minkasu transaction
202
+ *
203
+ * @param string $transactionId
204
+ *
205
+ * @return array
206
+ */
207
+ public function getTransaction($transactionId)
208
+ {
209
+ /** @var $apiHelper Minkasu_Wallet_Helper_Api */
210
+ $apiHelper = Mage::helper('minkasu_wallet/api');
211
+
212
+ $url = sprintf('%s/%s/%s', $apiHelper->getApiGatewayUrl(), $this->_getApiName(), $transactionId);
213
+ $data = array(
214
+ 'merchant_acct_id' => $apiHelper->getApiAccountId(),
215
+ 'minkasu_token' => $apiHelper->getApiToken()
216
+ );
217
+ $query = http_build_query($data);
218
+ $options = array(
219
+ 'http' => array(
220
+ 'header' => "Content-Type: application/x-www-form-urlencoded\r\nContent-Length: " . strlen($query),
221
+ 'method' => Varien_Http_Client::GET,
222
+ 'content' => $query,
223
+ ),
224
+ );
225
+ $context = stream_context_create($options);
226
+ $result = file_get_contents($url, false, $context);
227
+ return json_decode($result, true);
228
+ }
229
+
230
+ /**
231
+ * Void a Minkasu transaction
232
+ *
233
+ * @param string $transactionId
234
+ *
235
+ * @return array
236
+ */
237
+ public function voidTransaction($transactionId)
238
+ {
239
+ /** @var $apiHelper Minkasu_Wallet_Helper_Api */
240
+ $apiHelper = Mage::helper('minkasu_wallet/api');
241
+
242
+ $params = array(
243
+ 'operation' => self::OPERATION_VOID,
244
+ 'merchant_acct_id' => $apiHelper->getApiAccountId(),
245
+ 'minkasu_token' => $apiHelper->getApiToken(),
246
+ ':id' => $transactionId,
247
+ ':action' => self::FIELD_NAME_ACTION,
248
+ );
249
+
250
+ return $this->post($params);
251
+ }
252
+
253
+ /**
254
+ * @param string $transactionId
255
+ *
256
+ * @return array
257
+ */
258
+ public function getTransactionStatus($transactionId)
259
+ {
260
+ $params = array(
261
+ ':id' => $transactionId,
262
+ ':action' => self::FIELD_NAME_STATUS
263
+ );
264
+
265
+ return $this->get($params);
266
+ }
267
+
268
+ /**
269
+ * @return string
270
+ */
271
+ protected function _getApiName()
272
+ {
273
+ return self::API_NAME;
274
+ }
275
+ }
app/code/community/Minkasu/Wallet/Model/Observer.php ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Minkasu_Wallet_Model_Observer
4
+ {
5
+ /**
6
+ * @param Varien_Event_Observer $observer
7
+ * @return $this
8
+ */
9
+ public function saveOrderQuoteToSession(Varien_Event_Observer $observer)
10
+ {
11
+ /** @var Mage_Checkout_Model_Cart $cart */
12
+ $cart = $observer->getEvent()->getCart();
13
+ $checkoutSession = $cart->getCheckoutSession();
14
+ $shippingMethod = $cart->getQuote()->getShippingAddress()->getShippingMethod();
15
+ $checkoutSession->setData('minkasu_shipping_method', $shippingMethod);
16
+ $checkoutSession->setData('minkasu_shipping_estimated', $shippingMethod ? true : false);
17
+
18
+ return $this;
19
+ }
20
+
21
+ /**
22
+ * Show a warning to a customer if he goes miss checkout cart page
23
+ *
24
+ * @param Varien_Event_Observer $observer
25
+ * @return $this
26
+ */
27
+ public function showNotice(Varien_Event_Observer $observer)
28
+ {
29
+ /** @var $apiHelper Minkasu_Wallet_Helper_Api */
30
+ $apiHelper = Mage::helper('minkasu_wallet/api');
31
+ if (false === $apiHelper->isApiActive()) {
32
+ return $this;
33
+ }
34
+
35
+ /** @var Mage_Checkout_OnepageController $controller */
36
+ $controller = $observer->getData('controller_action');
37
+ /** @var $coreSession Mage_Core_Model_Session */
38
+ $coreSession = Mage::getSingleton('core/session');
39
+ $coreSession->addWarning(
40
+ $controller->__(
41
+ 'You can <a href="%s">checkout quickly</a> using Minkasu App.',
42
+ Mage::getUrl('checkout/cart')
43
+ )
44
+ );
45
+ return $this;
46
+ }
47
+ }
app/code/community/Minkasu/Wallet/Model/Observer.php~ ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Minkasu_Wallet_Model_Observer
4
+ {
5
+ /**
6
+ * @param Varien_Event_Observer $observer
7
+ * @return $this
8
+ */
9
+ public function saveOrderQuoteToSession(Varien_Event_Observer $observer)
10
+ {
11
+ /** @var Mage_Checkout_Model_Cart $cart */
12
+ $cart = $observer->getEvent()->getCart();
13
+ $checkoutSession = $cart->getCheckoutSession();
14
+ $shippingAddress = $cart->getQuote()->getShippingAddress();
15
+ $shippingMethod = $cart->getQuote()->getShippingAddress()->getShippingMethod();
16
+ $checkoutSession->setData('minkasu_shipping_method', $shippingMethod);
17
+ $checkoutSession->setData('minkasu_shipping_estimated', $shippingMethod ? true : false);
18
+ if (($shippingAddress) && ($shippingAddress->exportCustomerAddress() != NULL)) {
19
+ $postcode = $shippingAddress->exportCustomerAddress()->getData()["postcode"];
20
+ $checkoutSession->setData('minkasu_estimate_postcode', $postcode);
21
+ } else {
22
+
23
+ }
24
+ //Mage::log($shippingAddress, true);
25
+ return $this;
26
+ }
27
+
28
+ /**
29
+ * Show a warning to a customer if he goes miss checkout cart page
30
+ *
31
+ * @param Varien_Event_Observer $observer
32
+ * @return $this
33
+ */
34
+ public function showNotice(Varien_Event_Observer $observer)
35
+ {
36
+ /** @var $apiHelper Minkasu_Wallet_Helper_Api */
37
+ $apiHelper = Mage::helper('minkasu_wallet/api');
38
+ if (false === $apiHelper->isApiActive()) {
39
+ return $this;
40
+ }
41
+
42
+ /** @var Mage_Checkout_OnepageController $controller */
43
+ $controller = $observer->getData('controller_action');
44
+ /** @var $coreSession Mage_Core_Model_Session */
45
+ $coreSession = Mage::getSingleton('core/session');
46
+ $coreSession->addWarning(
47
+ $controller->__(
48
+ 'You can <a href="%s">checkout quickly</a> using Minkasu App.',
49
+ Mage::getUrl('checkout/cart')
50
+ )
51
+ );
52
+ return $this;
53
+ }
54
+ }
app/code/community/Minkasu/Wallet/Model/Payment.php ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Minkasu_Wallet_Model_Payment extends Mage_Payment_Model_Method_Abstract
4
+ {
5
+ protected $_code = 'minkasu_wallet';
6
+
7
+ protected $_canUseCheckout = false;
8
+ protected $_canUseInternal = false;
9
+ protected $_canUseForMultishipping = false;
10
+
11
+ protected $_canAuthorize = true;
12
+ protected $_canCapture = true;
13
+ protected $_canRefund = true;
14
+ protected $_canVoid = true;
15
+
16
+ public function isAvailable($quote = null)
17
+ {
18
+ return true;
19
+ }
20
+
21
+ /**
22
+ * {@inheritdoc}
23
+ */
24
+ public function isApplicableToQuote($quote, $checks)
25
+ {
26
+ return true;
27
+ }
28
+
29
+ /**
30
+ * {@inheritdoc}
31
+ */
32
+ public function authorize(Varien_Object $payment, $amount)
33
+ {
34
+ /** @var $checkoutSession Mage_Checkout_Model_Session */
35
+ $checkoutSession = Mage::getSingleton('checkout/session');
36
+
37
+ /** @var $client Minkasu_Wallet_Model_Api_Client */
38
+ $client = Mage::getModel('minkasu_wallet/api_client');
39
+ $client->getType('transaction')->authorizeTransaction(
40
+ $checkoutSession->getData('minkasu_txn_id'),
41
+ $checkoutSession->getData('minkasu_payment_token'),
42
+ $amount
43
+ );
44
+
45
+ $payment->setTransactionId($checkoutSession->getData('minkasu_txn_id'));
46
+ $payment->setIsTransactionClosed(0);
47
+ $payment->setTransactionAdditionalInfo('quote number', $checkoutSession->getData('minkasu_bill_number'));
48
+
49
+ /** @var $helper Minkasu_Wallet_Helper_Data */
50
+ $helper = Mage::helper('minkasu_wallet');
51
+ $helper->cleanCheckoutSessionParams();
52
+
53
+ return $this;
54
+ }
55
+
56
+ /**
57
+ * {@inheritdoc}
58
+ */
59
+ public function capture(Varien_Object $payment, $amount)
60
+ {
61
+ /** @var $client Minkasu_Wallet_Model_Api_Client */
62
+ $client = Mage::getModel('minkasu_wallet/api_client');
63
+ $client->getType('transaction')->captureTransaction($payment->getData('parent_transaction_id'), $amount);
64
+ $payment->setIsTransactionClosed(0);
65
+
66
+ return $this;
67
+ }
68
+
69
+ /**
70
+ * {@inheritdoc}
71
+ */
72
+ public function refund(Varien_Object $payment, $amount)
73
+ {
74
+ /** @var $client Minkasu_Wallet_Model_Api_Client */
75
+ $client = Mage::getModel('minkasu_wallet/api_client');
76
+ $transactionId = str_replace('-capture', '', $payment->getData('parent_transaction_id'));
77
+ $client->getType('transaction')->refundTransaction($transactionId, $amount);
78
+ $payment->setIsTransactionClosed(0);
79
+
80
+ return $this;
81
+ }
82
+
83
+ /**
84
+ * {@inheritdoc}
85
+ */
86
+ public function cancel(Varien_Object $payment)
87
+ {
88
+ /** @var $client Minkasu_Wallet_Model_Api_Client */
89
+ $client = Mage::getModel('minkasu_wallet/api_client');
90
+ $client->getType('transaction')->cancelTransaction($payment->getData('parent_transaction_id'));
91
+
92
+ return $this;
93
+ }
94
+ }
app/code/community/Minkasu/Wallet/Model/System/Config/Backend/MinkasuStatus.php ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Minkasu_Wallet_Model_System_Config_Backend_MinkasuStatus extends Mage_Core_Model_Config_Data
4
+ {
5
+ /**
6
+ * {@inheritdoc}
7
+ */
8
+ protected function _afterSave()
9
+ {
10
+ parent::_afterSave();
11
+
12
+ if (false === $this->isValueChanged()) {
13
+ return $this;
14
+ }
15
+ try {
16
+ /** @var $apiHelper Minkasu_Wallet_Helper_Api */
17
+ $apiHelper = Mage::helper('minkasu_wallet/api');
18
+ if (!$apiHelper->getApiAccountId() || !$apiHelper->getApiToken()) {
19
+ Mage::throwException($this->_getHelper()->__('Your Minkasu credentials are empty.'));
20
+ }
21
+
22
+ /** @var $client Minkasu_Wallet_Model_Api_Client */
23
+ $client = Mage::getModel('minkasu_wallet/api_client');
24
+ if ('1' === $this->getValue()) {
25
+ $result = $client->getType('merchant')->activateMerchant();
26
+ $message = 'You have succesfully activated your Minkasu Account.';
27
+ } else {
28
+ $result = $client->getType('merchant')->deactivateMerchant();
29
+ $message = 'You have succesfully deactivated your Minkasu Account.'
30
+ . 'To enable it, open the Minkasu section and set Enabled=Yes.';
31
+ }
32
+ if (null === $result) {
33
+ $this->_getSession()->addSuccess(
34
+ $this->_getHelper()->__($message)
35
+ );
36
+ } else {
37
+ $this->_getSession()->addError(
38
+ $this->_getHelper()->__('An error occurred during activating your Minkasu account.')
39
+ );
40
+ }
41
+ } catch (Exception $e) {
42
+ $this->_getSession()->addException($e, $e->getMessage());
43
+ }
44
+ return $this;
45
+ }
46
+
47
+ /**
48
+ * @return Mage_Adminhtml_Model_Session
49
+ */
50
+ protected function _getSession()
51
+ {
52
+ return Mage::getSingleton('adminhtml/session');
53
+ }
54
+
55
+ /**
56
+ * @return Minkasu_Wallet_Helper_Data
57
+ */
58
+ protected function _getHelper()
59
+ {
60
+ return Mage::helper('minkasu_wallet');
61
+ }
62
+ }
app/code/community/Minkasu/Wallet/controllers/Adminhtml/Minkasu/Wallet/MerchantController.php ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Minkasu_Wallet_Adminhtml_Minkasu_Wallet_MerchantController extends Mage_Adminhtml_Controller_Action
4
+ {
5
+ /**
6
+ * {@inheritdoc}
7
+ */
8
+ protected function _construct()
9
+ {
10
+ parent::_construct();
11
+ $this->setUsedModuleName('Minkasu_Wallet');
12
+ }
13
+
14
+ /**
15
+ * Create a Minkasu merchant
16
+ */
17
+ public function createAction()
18
+ {
19
+ /** @var $apiHelper Minkasu_Wallet_Helper_Api */
20
+ $apiHelper = Mage::helper('minkasu_wallet/api');
21
+ $hasMinkasuMerchant = $apiHelper->getApiAccountId() && $apiHelper->getApiToken();
22
+ if ($hasMinkasuMerchant) {
23
+ $this->_getSession()->addNotice(
24
+ $this->__('You already have Minkasu merchant account. Please delete the credentials and try again.')
25
+ );
26
+ }
27
+
28
+ $this->loadLayout();
29
+ if ($hasMinkasuMerchant) {
30
+ $this->getLayout()->getBlock('content')->unsetChild('minkasu_wallet.merchant.create');
31
+ }
32
+ $this->renderLayout();
33
+ }
34
+
35
+ /**
36
+ * Create a Minkasu merchant
37
+ */
38
+ public function editAction()
39
+ {
40
+ $this->loadLayout();
41
+ $this->renderLayout();
42
+ }
43
+
44
+ /**
45
+ * Save a Minkasu merchant
46
+ */
47
+ public function saveAction()
48
+ {
49
+ try {
50
+ if (false === $this->getRequest()->isPost()) {
51
+ Mage::throwException($this->__('Wrong request type.'));
52
+ }
53
+ $postData = $this->getRequest()->getPost();
54
+ $userData = array(
55
+ 'business_name' => $postData['name'],
56
+ 'email' => $postData['email'],
57
+ 'phone' => $postData['phone'],
58
+ );
59
+ $gatewayData = array(
60
+ 'login_id' => $postData['authNet_api_login_id'],
61
+ 'key' => $postData['authNet_transaction_key'],
62
+ 'gateway' => $postData['authNet_gateway'],
63
+ );
64
+ /** @var $client Minkasu_Wallet_Model_Api_Client */
65
+ $client = Mage::getModel('minkasu_wallet/api_client');
66
+ $result = $client->getType('merchant')->createMerchant($userData, $gatewayData);
67
+ if (isset($result['merchant_id']) && isset($result['minkasu_token'])) {
68
+ $apiHelper = Mage::helper('minkasu_wallet/api');
69
+ $apiHelper->saveApiAccountId($result['merchant_id']);
70
+ $apiHelper->saveApiToken($result['minkasu_token']);
71
+
72
+ $this->_getSession()->addSuccess(
73
+ $this->__('You have successfully created your Minkasu account and added it your Magento configuration.')
74
+ );
75
+ $this->_redirect('*/*/successCreate');
76
+ } else {
77
+ $this->_getSession()->addError($this->__('An error occurred during creating a Minkasu merchant.'));
78
+ $this->_getSession()->setData('minkasu_merchant_details', $postData);
79
+ $this->_redirect('*/*/create');
80
+ }
81
+ } catch (Exception $e) {
82
+ $this->_getSession()->addException($e, $e->getMessage());
83
+ $this->_getSession()->setData('minkasu_merchant_details', $postData);
84
+ $this->_redirect('*/*/create');
85
+ }
86
+ }
87
+
88
+ /**
89
+ * Update a Minkasu merchant
90
+ */
91
+ public function updateAction()
92
+ {
93
+ try {
94
+ if (false === $this->getRequest()->isPost()) {
95
+ Mage::throwException($this->__('Wrong request type.'));
96
+ }
97
+ $postData = $this->getRequest()->getPost();
98
+ $gatewayData = array(
99
+ 'login_id' => $postData['authNet_api_login_id'],
100
+ 'key' => $postData['authNet_transaction_key'],
101
+ 'test_mode' => $postData['authNet_gateway'],
102
+ );
103
+ /** @var $client Minkasu_Wallet_Model_Api_Client */
104
+ $client = Mage::getModel('minkasu_wallet/api_client');
105
+ $result = $client->getType('merchant')->updateMerchantGateway($gatewayData);
106
+ if (isset($result['status']) && 'success' == $result['status']) {
107
+ $this->_getSession()->addSuccess(
108
+ $this->__('Merchant has been updated successfully.')
109
+ );
110
+ $this->_redirect('*/*/successUpdate');
111
+ } else {
112
+ $this->_getSession()->addError($this->__('An error occurred during updating a Minkasu merchant.'));
113
+ $this->_getSession()->setData('minkasu_merchant_details', $postData);
114
+ $this->_redirect('*/*/edit');
115
+ }
116
+ } catch (Exception $e) {
117
+ $this->_getSession()->addException($e, $e->getMessage());
118
+ $this->_getSession()->setData('minkasu_merchant_details', $postData);
119
+ $this->_redirect('*/*/edit');
120
+ }
121
+ }
122
+
123
+ /**
124
+ * Show success page after Minkasu merchant creation
125
+ */
126
+ public function successCreateAction()
127
+ {
128
+ $this->loadLayout();
129
+ $this->renderLayout();
130
+ }
131
+
132
+ /**
133
+ * Show success page after Minkasu merchant updating
134
+ */
135
+ public function successUpdateAction()
136
+ {
137
+ $this->loadLayout();
138
+ $this->renderLayout();
139
+ }
140
+ }
app/code/community/Minkasu/Wallet/controllers/PaymentController.php ADDED
@@ -0,0 +1,408 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Minkasu_Wallet_PaymentController extends Mage_Core_Controller_Front_Action
4
+ {
5
+ /**
6
+ * Make a payment
7
+ */
8
+ public function paidAction()
9
+ {
10
+ /** @var $coreResource Mage_Core_Model_Resource */
11
+ $coreResource = Mage::getSingleton('core/resource');
12
+ $writeAdapter = $coreResource->getConnection('core_write');
13
+
14
+ // Step 1: Get the current quote object
15
+ /** @var $checkoutSession Mage_Checkout_Model_Session */
16
+ $checkoutSession = Mage::getSingleton('checkout/session');
17
+ $quote = $checkoutSession->getQuote();
18
+
19
+ try {
20
+ $writeAdapter->beginTransaction();
21
+
22
+ $minkasuTransactionId = $checkoutSession->getData('minkasu_txn_id');
23
+ $transactionInfoResponse = $this->_getMinkasuTransaction($minkasuTransactionId);
24
+ if (!isset($transactionInfoResponse['txn_state']) || $transactionInfoResponse['txn_state']
25
+ != Minkasu_Wallet_Model_Api_Type_Transaction::STATE_PREAUTHED
26
+ ) {
27
+ Mage::throwException('This transaction has wrong state.');
28
+ }
29
+
30
+ $customerDetails = $this->_extractCustomerDetails($transactionInfoResponse);
31
+ if (!($customerDetails['customer_details_valid'])) {
32
+ Mage::throwException('Required details not provided with payment.');
33
+ }
34
+
35
+ // Step 2: Set the checkout method as "guest
36
+ $quote->setCheckoutMethod('guest')->save();
37
+ // Step 2.1:Fill customer name (first name ?)
38
+ $quote->setCustomerFirstname($customerDetails['customer_name']);
39
+ // Step 3: Fill the address and save it as billing and shipping address
40
+ $addressInfo = $this->_prepareCustomerAddressInfo($customerDetails);
41
+ $this->_saveBillingAndShippingAddress($quote, $addressInfo);
42
+
43
+ // Step 4: Shipping method should already be set by now.
44
+ $checkoutSession->setStepData('shipping_method', 'complete', true);
45
+
46
+ // Step 5: Set payment method to minkasu wallet
47
+ $this->_savePayment($quote, array('method' => 'minkasu_wallet'));
48
+
49
+ // Calculate shipping rates now
50
+ $quote->getShippingAddress()->collectShippingRates()->save();
51
+ $quote->collectTotals()->save();
52
+
53
+ $writeAdapter->commit();
54
+
55
+ $order = $this->_saveOrder($quote);
56
+
57
+ if ($order->getId()) {
58
+ $this->_updateMinkasuTransactionWithOrderId($minkasuTransactionId, $order->getIncrementId());
59
+ } else {
60
+ Mage::throwException($this->__('Order has not been created.'));
61
+ }
62
+ } catch (Mage_Core_Exception $e) {
63
+ Mage::logException($e);
64
+ $writeAdapter->rollback();
65
+
66
+ try {
67
+ /** @var $client Minkasu_Wallet_Model_Api_Client */
68
+ $client = Mage::getModel('minkasu_wallet/api_client');
69
+ $client->getType('transaction')->voidTransaction($minkasuTransactionId);
70
+ } catch (Mage_Core_Exception $internalException) {
71
+ Mage::logException($internalException);
72
+ } catch (Exception $internalException) {
73
+ Mage::logException($internalException);
74
+ }
75
+
76
+ $this->_cleanCheckoutSessionParams();
77
+ $this->getResponse()->setHttpResponseCode(500);
78
+ $this->getResponse()->setBody($this->_prepareErrorBody($e->getMessage()));
79
+ $this->getResponse()->sendResponse();
80
+ die;
81
+ } catch (Exception $e) {
82
+ Mage::logException($e);
83
+ $writeAdapter->rollback();
84
+
85
+ try {
86
+ /** @var $client Minkasu_Wallet_Model_Api_Client */
87
+ $client = Mage::getModel('minkasu_wallet/api_client');
88
+ $client->getType('transaction')->voidTransaction($minkasuTransactionId);
89
+ } catch (Mage_Core_Exception $internalException) {
90
+ Mage::logException($internalException);
91
+ } catch (Exception $internalException) {
92
+ Mage::logException($internalException);
93
+ }
94
+
95
+ $this->_cleanCheckoutSessionParams();
96
+ $this->getResponse()->setHttpResponseCode(500);
97
+ $this->getResponse()->setBody(
98
+ $this->_prepareErrorBody('An error has occurred. Please contact store administrator.')
99
+ );
100
+ $this->getResponse()->sendResponse();
101
+ die;
102
+ }
103
+
104
+ $url = Mage::getUrl('checkout/onepage/success');
105
+ $this->getResponse()->setHttpResponseCode(201);
106
+ $this->getResponse()->setBody($this->_prepareBody(array('redirect_url' => $url)));
107
+ $this->getResponse()->sendResponse();
108
+ die;
109
+ }
110
+
111
+ /**
112
+ * @param string $minkasuTransactionId
113
+ *
114
+ * @return array
115
+ */
116
+ protected function _getMinkasuTransaction($minkasuTransactionId)
117
+ {
118
+ /** @var $client Minkasu_Wallet_Model_Api_Client */
119
+ $client = Mage::getModel('minkasu_wallet/api_client');
120
+ $result = $client->getType('transaction')->getTransaction($minkasuTransactionId);
121
+ return $result;
122
+ }
123
+
124
+ /**
125
+ * @param array $response
126
+ *
127
+ * @return array
128
+ */
129
+ protected function _extractCustomerDetails(array $response)
130
+ {
131
+ $result = array();
132
+
133
+ $result['customer_details_valid'] = false;
134
+
135
+ if (!isset($response['customer_address']) || (!isset($response['customer_name']))) {
136
+ return $result;
137
+ }
138
+
139
+ $result['customer_name'] = $response['customer_name'];
140
+ $result['street_1'] = $response['customer_address']['address_line_1'];
141
+ $result['street_2'] = $response['customer_address']['address_line_2'];
142
+ $result['city'] = $response['customer_address']['city'];
143
+ $result['state'] = $response['customer_address']['state'];
144
+ $result['zip'] = $response['customer_address']['zip'];
145
+ $result['phone'] = $response['phone'];
146
+ $result['email'] = $response['email'];
147
+ $result['customer_details_valid'] = true;
148
+
149
+ return $result;
150
+ }
151
+
152
+ /**
153
+ * @param array $customerDetails
154
+ *
155
+ * @return array
156
+ */
157
+ protected function _prepareCustomerAddressInfo(array $customerDetails)
158
+ {
159
+ /** @var $regionModel Mage_Directory_Model_Region */
160
+ $regionModel = Mage::getModel('directory/region');
161
+ $regionModel->loadByCode($customerDetails['state'], 'US');
162
+
163
+ $customerNameParts = explode(' ', $customerDetails['customer_name']);
164
+
165
+ $addressInfo = array();
166
+ $addressInfo['firstname'] = $customerNameParts[0];
167
+ $addressInfo['lastname'] = end($customerNameParts);
168
+ $addressInfo['email'] = $customerDetails['email'];
169
+ $addressInfo['street'] = array(0 => $customerDetails['street_1'], 1 => $customerDetails['street_2']);
170
+ $addressInfo['city'] = $customerDetails['city'];
171
+ $addressInfo['region_id'] = $regionModel->getId();
172
+ $addressInfo['postcode'] = $customerDetails['zip'];
173
+ $addressInfo['country_id'] = 'US';
174
+ $addressInfo['telephone'] = $customerDetails['phone'];
175
+ $addressInfo['use_for_shipping'] = 1;
176
+
177
+ return $addressInfo;
178
+ }
179
+
180
+ /**
181
+ * @param $quote
182
+ * @param array $data
183
+ *
184
+ * @return $this
185
+ */
186
+ protected function _saveBillingAndShippingAddress($quote, $data)
187
+ {
188
+ $address = $quote->getBillingAddress();
189
+ /** @var $addressForm Mage_Customer_Model_Form */
190
+ $addressForm = Mage::getModel('customer/form');
191
+ $addressForm->setFormCode('customer_address_edit');
192
+ $addressForm->setEntityType('customer_address');
193
+ $addressForm->setEntity($address);
194
+ // emulate request object
195
+ $addressData = $addressForm->extractData($addressForm->prepareRequest($data));
196
+ $addressErrors = $addressForm->validateData($addressData);
197
+ if (true !== $addressErrors) {
198
+ Mage::log("Minkasu - address validation failed");
199
+ }
200
+ $addressForm->compactData($addressData);
201
+ //unset billing address attributes which were not shown in form
202
+ foreach ($addressForm->getAttributes() as $attribute) {
203
+ if (!isset($data[$attribute->getAttributeCode()])) {
204
+ $address->setData($attribute->getAttributeCode(), NULL);
205
+ }
206
+ }
207
+ $address->setCustomerAddressId(null);
208
+ $address->setEmail($data['email']);
209
+ $address->implodeStreetAddress();
210
+
211
+ $billing = clone $address;
212
+ $billing->unsAddressId()->unsAddressType();
213
+
214
+ $shipping = $quote->getShippingAddress();
215
+ $shippingMethod = $shipping->getShippingMethod();
216
+
217
+ // Billing address properties that must be always copied to shipping address
218
+ $requiredBillingAttributes = array('customer_address_id');
219
+
220
+ // don't reset original shipping data, if it was not changed by customer
221
+ foreach ($shipping->getData() as $shippingKey => $shippingValue) {
222
+ if (!is_null($shippingValue) && !is_null($billing->getData($shippingKey))
223
+ && !isset($data[$shippingKey]) && !in_array($shippingKey, $requiredBillingAttributes)
224
+ ) {
225
+ $billing->unsetData($shippingKey);
226
+ }
227
+ }
228
+
229
+ $shipping->addData($billing->getData());
230
+ $shipping->setSameAsBilling(1);
231
+ $shipping->setSaveInAddressBook(0);
232
+ $shipping->setShippingMethod($shippingMethod);
233
+ $shipping->setCollectShippingRates(true);
234
+
235
+ /** @var $checkoutSession Mage_Checkout_Model_Session */
236
+ $checkoutSession = Mage::getSingleton('checkout/session');
237
+ $checkoutSession->setStepData('shipping', 'complete', true);
238
+
239
+ $quote->collectTotals();
240
+ $quote->save();
241
+ $quote->getShippingAddress()->setCollectShippingRates(true);
242
+
243
+ $checkoutSession->setStepData('billing', 'allow', true);
244
+ $checkoutSession->setStepData('billing', 'complete', true);
245
+ $checkoutSession->setStepData('shipping', 'allow', true);
246
+
247
+ return $this;
248
+ }
249
+
250
+ /**
251
+ * @param $quote
252
+ * @param array $data
253
+ *
254
+ * @return $this
255
+ */
256
+ protected function _savePayment($quote, array $data)
257
+ {
258
+ try {
259
+ if($quote->isVirtual()) {
260
+ $quote->getBillingAddress()->setPaymentMethod(isset($data['method']) ? $data['method'] : null);
261
+ } else {
262
+ $quote->getShippingAddress()->setPaymentMethod(isset($data['method']) ? $data['method'] : null);
263
+ }
264
+
265
+ // shipping totals may be affected by payment method
266
+ if (!$quote->isVirtual() && $quote->getShippingAddress()) {
267
+ $quote->getShippingAddress()->setCollectShippingRates(true);
268
+ }
269
+
270
+ $data['checks'] = Mage_Payment_Model_Method_Abstract::CHECK_USE_CHECKOUT
271
+ | Mage_Payment_Model_Method_Abstract::CHECK_USE_FOR_COUNTRY
272
+ | Mage_Payment_Model_Method_Abstract::CHECK_USE_FOR_CURRENCY
273
+ | Mage_Payment_Model_Method_Abstract::CHECK_ORDER_TOTAL_MIN_MAX
274
+ | Mage_Payment_Model_Method_Abstract::CHECK_ZERO_TOTAL;
275
+
276
+ /** @var $checkoutSession Mage_Checkout_Model_Session */
277
+ $checkoutSession = Mage::getSingleton('checkout/session');
278
+ $payment = $quote->getPayment();
279
+ $payment->importData($data);
280
+ $payment->setTransactionId($checkoutSession->getData('minkasu_txn_id'));
281
+ $payment->setTransactionAdditionalInfo('quote-no', $quote->getQuoteId());
282
+
283
+ $quote->save();
284
+ $checkoutSession->setStepData('payment', 'complete', true);
285
+ } catch (Exception $e) {
286
+ Mage::logException($e);
287
+ }
288
+ return $this;
289
+ }
290
+
291
+ /**
292
+ * @param $quote
293
+ *
294
+ * @return Mage_Sales_Model_Order
295
+ */
296
+ protected function _saveOrder($quote)
297
+ {
298
+ $quote->setCustomerId(null);
299
+ $quote->setCustomerEmail($quote->getBillingAddress()->getEmail());
300
+ $quote->setCustomerIsGuest(true);
301
+ $quote->setCustomerGroupId(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID);
302
+
303
+ /** @var $service Mage_Sales_Model_Service_Quote */
304
+ $service = Mage::getModel('sales/service_quote', $quote);
305
+ $service->submitAll();
306
+
307
+ /** @var $checkoutSession Mage_Checkout_Model_Session */
308
+ $checkoutSession = Mage::getSingleton('checkout/session');
309
+ $checkoutSession->setLastQuoteId($quote->getId());
310
+ $checkoutSession->setLastSuccessQuoteId($quote->getId());
311
+ $checkoutSession->clearHelperData();
312
+
313
+ $order = $service->getOrder();
314
+
315
+ if ($order->getId()) {
316
+ Mage::dispatchEvent('checkout_type_onepage_save_order_after', array('order'=>$order, 'quote'=>$quote));
317
+
318
+ /**
319
+ * we only want to send to customer about new order when there is no redirect to third party
320
+ */
321
+ if ($order->getCanSendNewEmailFlag()) {
322
+ try {
323
+ $order->sendNewOrderEmail();
324
+ } catch (Exception $e) {
325
+ Mage::logException($e);
326
+ }
327
+ }
328
+
329
+ // add order information to the session
330
+ $checkoutSession->setLastOrderId($order->getId());
331
+ $checkoutSession->setRedirectUrl(null);
332
+ $checkoutSession->setLastRealOrderId($order->getIncrementId());
333
+
334
+ // as well a billing agreement can be created
335
+ $agreement = $order->getPayment()->getBillingAgreement();
336
+ if ($agreement) {
337
+ $checkoutSession->setLastBillingAgreementId($agreement->getId());
338
+ }
339
+ }
340
+
341
+ // add recurring profiles information to the session
342
+ $profiles = $service->getRecurringPaymentProfiles();
343
+ if ($profiles) {
344
+ $ids = array();
345
+ foreach ($profiles as $profile) {
346
+ $ids[] = $profile->getId();
347
+ }
348
+ $checkoutSession->setLastRecurringProfileIds($ids);
349
+ }
350
+
351
+ Mage::dispatchEvent(
352
+ 'checkout_submit_all_after',
353
+ array('order' => $order, 'quote' => $quote, 'recurring_profiles' => $profiles)
354
+ );
355
+
356
+ $quote->save();
357
+ return $order;
358
+ }
359
+
360
+ /**
361
+ * @param string $minkasuTransactionId
362
+ * @param string $orderId
363
+ *
364
+ * @return array
365
+ */
366
+ protected function _updateMinkasuTransactionWithOrderId($minkasuTransactionId, $orderId)
367
+ {
368
+ /** @var $client Minkasu_Wallet_Model_Api_Client */
369
+ $client = Mage::getModel('minkasu_wallet/api_client');
370
+ $result = $client->getType('transaction')->updateTransaction($minkasuTransactionId, array('merchant_bill_number' => $orderId), NULL);
371
+
372
+ return $result;
373
+ }
374
+
375
+ /**
376
+ * @return $this
377
+ */
378
+ protected function _cleanCheckoutSessionParams()
379
+ {
380
+ /** @var $helper Minkasu_Wallet_Helper_Data */
381
+ $helper = Mage::helper('minkasu_wallet');
382
+ $helper->cleanCheckoutSessionParams();
383
+ return $this;
384
+ }
385
+
386
+ /**
387
+ * @param string $error
388
+ *
389
+ * @return string
390
+ */
391
+ protected function _prepareErrorBody($error)
392
+ {
393
+ return $this->_prepareBody(array('error' => $this->__($error)));
394
+ }
395
+
396
+ /**
397
+ * @param array $data
398
+ *
399
+ * @return string
400
+ */
401
+ protected function _prepareBody(array $data)
402
+ {
403
+ /** @var $helper Mage_Core_Helper_Data */
404
+ $helper = Mage::helper('core');
405
+ return $helper->jsonEncode($data);
406
+ }
407
+ }
408
+ ?>
app/code/community/Minkasu/Wallet/controllers/PaymentController.php~ ADDED
@@ -0,0 +1,410 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Minkasu_Wallet_PaymentController extends Mage_Core_Controller_Front_Action
4
+ {
5
+ /**
6
+ * Make a payment
7
+ */
8
+ public function paidAction()
9
+ {
10
+ /** @var $coreResource Mage_Core_Model_Resource */
11
+ $coreResource = Mage::getSingleton('core/resource');
12
+ $writeAdapter = $coreResource->getConnection('core_write');
13
+
14
+ // Step 1: Get the current quote object
15
+ /** @var $checkoutSession Mage_Checkout_Model_Session */
16
+ $checkoutSession = Mage::getSingleton('checkout/session');
17
+ $quote = $checkoutSession->getQuote();
18
+
19
+ try {
20
+ $writeAdapter->beginTransaction();
21
+
22
+ $minkasuTransactionId = $checkoutSession->getData('minkasu_txn_id');
23
+ $transactionInfoResponse = $this->_getMinkasuTransaction($minkasuTransactionId);
24
+ if (!isset($transactionInfoResponse['txn_state']) || $transactionInfoResponse['txn_state']
25
+ != Minkasu_Wallet_Model_Api_Type_Transaction::STATE_PREAUTHED
26
+ ) {
27
+ Mage::throwException('This transaction has wrong state.');
28
+ }
29
+
30
+ $customerDetails = $this->_extractCustomerDetails($transactionInfoResponse);
31
+ if (!($customerDetails['customer_details_valid'])) {
32
+ Mage::throwException('Required details not provided with payment.');
33
+ }
34
+
35
+ // Step 2: Set the checkout method as "guest
36
+ $quote->setCheckoutMethod('guest')->save();
37
+ // Step 2.1:Fill customer name (first name ?)
38
+ $quote->setCustomerFirstname($customerDetails['customer_name']);
39
+ // Step 3: Fill the address and save it as billing and shipping address
40
+ $addressInfo = $this->_prepareCustomerAddressInfo($customerDetails);
41
+ $this->_saveBillingAndShippingAddress($quote, $addressInfo);
42
+
43
+ // Step 4: Shipping method should already be set by now.
44
+ $checkoutSession->setStepData('shipping_method', 'complete', true);
45
+
46
+ // Step 5: Set payment method to minkasu wallet
47
+ $this->_savePayment($quote, array('method' => 'minkasu_wallet'));
48
+
49
+ // Calculate shipping rates now
50
+ $quote->getShippingAddress()->collectShippingRates()->save();
51
+ $quote->collectTotals()->save();
52
+
53
+ Mage::log("Minkasu - Estimated and collected totals");
54
+
55
+ $writeAdapter->commit();
56
+
57
+
58
+ $order = $this->_saveOrder($quote);
59
+ if ($order->getId()) {
60
+ $this->_updateMinkasuTransactionWithOrderId($minkasuTransactionId, $order->getIncrementId());
61
+ } else {
62
+ Mage::throwException($this->__('Order has not been created.'));
63
+ }
64
+ } catch (Mage_Core_Exception $e) {
65
+ Mage::logException($e);
66
+ $writeAdapter->rollback();
67
+
68
+ try {
69
+ /** @var $client Minkasu_Wallet_Model_Api_Client */
70
+ $client = Mage::getModel('minkasu_wallet/api_client');
71
+ $client->getType('transaction')->voidTransaction($minkasuTransactionId);
72
+ } catch (Mage_Core_Exception $internalException) {
73
+ Mage::logException($internalException);
74
+ } catch (Exception $internalException) {
75
+ Mage::logException($internalException);
76
+ }
77
+
78
+ $this->_cleanCheckoutSessionParams();
79
+ $this->getResponse()->setHttpResponseCode(500);
80
+ $this->getResponse()->setBody($this->_prepareErrorBody($e->getMessage()));
81
+ $this->getResponse()->sendResponse();
82
+ die;
83
+ } catch (Exception $e) {
84
+ Mage::logException($e);
85
+ $writeAdapter->rollback();
86
+
87
+ try {
88
+ /** @var $client Minkasu_Wallet_Model_Api_Client */
89
+ $client = Mage::getModel('minkasu_wallet/api_client');
90
+ $client->getType('transaction')->voidTransaction($minkasuTransactionId);
91
+ } catch (Mage_Core_Exception $internalException) {
92
+ Mage::logException($internalException);
93
+ } catch (Exception $internalException) {
94
+ Mage::logException($internalException);
95
+ }
96
+
97
+ $this->_cleanCheckoutSessionParams();
98
+ $this->getResponse()->setHttpResponseCode(500);
99
+ $this->getResponse()->setBody(
100
+ $this->_prepareErrorBody('An error has occurred. Please contact store administrator.')
101
+ );
102
+ $this->getResponse()->sendResponse();
103
+ die;
104
+ }
105
+
106
+ $url = Mage::getUrl('checkout/onepage/success');
107
+ $this->getResponse()->setHttpResponseCode(201);
108
+ $this->getResponse()->setBody($this->_prepareBody(array('redirect_url' => $url)));
109
+ $this->getResponse()->sendResponse();
110
+ die;
111
+ }
112
+
113
+ /**
114
+ * @param string $minkasuTransactionId
115
+ *
116
+ * @return array
117
+ */
118
+ protected function _getMinkasuTransaction($minkasuTransactionId)
119
+ {
120
+ /** @var $client Minkasu_Wallet_Model_Api_Client */
121
+ $client = Mage::getModel('minkasu_wallet/api_client');
122
+ $result = $client->getType('transaction')->getTransaction($minkasuTransactionId);
123
+ return $result;
124
+ }
125
+
126
+ /**
127
+ * @param array $response
128
+ *
129
+ * @return array
130
+ */
131
+ protected function _extractCustomerDetails(array $response)
132
+ {
133
+ $result = array();
134
+
135
+ $result['customer_details_valid'] = false;
136
+
137
+ if (!isset($response['customer_address']) || (!isset($response['customer_name']))) {
138
+ return $result;
139
+ }
140
+
141
+ $result['customer_name'] = $response['customer_name'];
142
+ $result['street_1'] = $response['customer_address']['address_line_1'];
143
+ $result['street_2'] = $response['customer_address']['address_line_2'];
144
+ $result['city'] = $response['customer_address']['city'];
145
+ $result['state'] = $response['customer_address']['state'];
146
+ $result['zip'] = $response['customer_address']['zip'];
147
+ $result['phone'] = $response['phone'];
148
+ $result['email'] = $response['email'];
149
+ $result['customer_details_valid'] = true;
150
+
151
+ return $result;
152
+ }
153
+
154
+ /**
155
+ * @param array $customerDetails
156
+ *
157
+ * @return array
158
+ */
159
+ protected function _prepareCustomerAddressInfo(array $customerDetails)
160
+ {
161
+ /** @var $regionModel Mage_Directory_Model_Region */
162
+ $regionModel = Mage::getModel('directory/region');
163
+ $regionModel->loadByCode($customerDetails['state'], 'US');
164
+
165
+ $customerNameParts = explode(' ', $customerDetails['customer_name']);
166
+
167
+ $addressInfo = array();
168
+ $addressInfo['firstname'] = $customerNameParts[0];
169
+ $addressInfo['lastname'] = end($customerNameParts);
170
+ $addressInfo['email'] = $customerDetails['email'];
171
+ $addressInfo['street'] = array(0 => $customerDetails['street_1'], 1 => $customerDetails['street_2']);
172
+ $addressInfo['city'] = $customerDetails['city'];
173
+ $addressInfo['region_id'] = $regionModel->getId();
174
+ $addressInfo['postcode'] = $customerDetails['zip'];
175
+ $addressInfo['country_id'] = 'US';
176
+ $addressInfo['telephone'] = $customerDetails['phone'];
177
+ $addressInfo['use_for_shipping'] = 1;
178
+
179
+ return $addressInfo;
180
+ }
181
+
182
+ /**
183
+ * @param $quote
184
+ * @param array $data
185
+ *
186
+ * @return $this
187
+ */
188
+ protected function _saveBillingAndShippingAddress($quote, $data)
189
+ {
190
+ $address = $quote->getBillingAddress();
191
+ /** @var $addressForm Mage_Customer_Model_Form */
192
+ $addressForm = Mage::getModel('customer/form');
193
+ $addressForm->setFormCode('customer_address_edit');
194
+ $addressForm->setEntityType('customer_address');
195
+ $addressForm->setEntity($address);
196
+ // emulate request object
197
+ $addressData = $addressForm->extractData($addressForm->prepareRequest($data));
198
+ $addressErrors = $addressForm->validateData($addressData);
199
+ if (true !== $addressErrors) {
200
+ Mage::log("Minkasu - address validation failed");
201
+ }
202
+ $addressForm->compactData($addressData);
203
+ //unset billing address attributes which were not shown in form
204
+ foreach ($addressForm->getAttributes() as $attribute) {
205
+ if (!isset($data[$attribute->getAttributeCode()])) {
206
+ $address->setData($attribute->getAttributeCode(), NULL);
207
+ }
208
+ }
209
+ $address->setCustomerAddressId(null);
210
+ $address->setEmail($data['email']);
211
+ $address->implodeStreetAddress();
212
+
213
+ $billing = clone $address;
214
+ $billing->unsAddressId()->unsAddressType();
215
+
216
+ $shipping = $quote->getShippingAddress();
217
+ $shippingMethod = $shipping->getShippingMethod();
218
+
219
+ // Billing address properties that must be always copied to shipping address
220
+ $requiredBillingAttributes = array('customer_address_id');
221
+
222
+ // don't reset original shipping data, if it was not changed by customer
223
+ foreach ($shipping->getData() as $shippingKey => $shippingValue) {
224
+ if (!is_null($shippingValue) && !is_null($billing->getData($shippingKey))
225
+ && !isset($data[$shippingKey]) && !in_array($shippingKey, $requiredBillingAttributes)
226
+ ) {
227
+ $billing->unsetData($shippingKey);
228
+ }
229
+ }
230
+
231
+ $shipping->addData($billing->getData());
232
+ $shipping->setSameAsBilling(1);
233
+ $shipping->setSaveInAddressBook(0);
234
+ $shipping->setShippingMethod($shippingMethod);
235
+ $shipping->setCollectShippingRates(true);
236
+
237
+ /** @var $checkoutSession Mage_Checkout_Model_Session */
238
+ $checkoutSession = Mage::getSingleton('checkout/session');
239
+ $checkoutSession->setStepData('shipping', 'complete', true);
240
+
241
+ $quote->collectTotals();
242
+ $quote->save();
243
+ $quote->getShippingAddress()->setCollectShippingRates(true);
244
+
245
+ $checkoutSession->setStepData('billing', 'allow', true);
246
+ $checkoutSession->setStepData('billing', 'complete', true);
247
+ $checkoutSession->setStepData('shipping', 'allow', true);
248
+
249
+ return $this;
250
+ }
251
+
252
+ /**
253
+ * @param $quote
254
+ * @param array $data
255
+ *
256
+ * @return $this
257
+ */
258
+ protected function _savePayment($quote, array $data)
259
+ {
260
+ try {
261
+ if($quote->isVirtual()) {
262
+ $quote->getBillingAddress()->setPaymentMethod(isset($data['method']) ? $data['method'] : null);
263
+ } else {
264
+ $quote->getShippingAddress()->setPaymentMethod(isset($data['method']) ? $data['method'] : null);
265
+ }
266
+
267
+ // shipping totals may be affected by payment method
268
+ if (!$quote->isVirtual() && $quote->getShippingAddress()) {
269
+ $quote->getShippingAddress()->setCollectShippingRates(true);
270
+ }
271
+
272
+ $data['checks'] = Mage_Payment_Model_Method_Abstract::CHECK_USE_CHECKOUT
273
+ | Mage_Payment_Model_Method_Abstract::CHECK_USE_FOR_COUNTRY
274
+ | Mage_Payment_Model_Method_Abstract::CHECK_USE_FOR_CURRENCY
275
+ | Mage_Payment_Model_Method_Abstract::CHECK_ORDER_TOTAL_MIN_MAX
276
+ | Mage_Payment_Model_Method_Abstract::CHECK_ZERO_TOTAL;
277
+
278
+ /** @var $checkoutSession Mage_Checkout_Model_Session */
279
+ $checkoutSession = Mage::getSingleton('checkout/session');
280
+ $payment = $quote->getPayment();
281
+ $payment->importData($data);
282
+ $payment->setTransactionId($checkoutSession->getData('minkasu_txn_id'));
283
+ $payment->setTransactionAdditionalInfo('quote-no', $quote->getQuoteId());
284
+
285
+ $quote->save();
286
+ $checkoutSession->setStepData('payment', 'complete', true);
287
+ } catch (Exception $e) {
288
+ Mage::logException($e);
289
+ }
290
+ return $this;
291
+ }
292
+
293
+ /**
294
+ * @param $quote
295
+ *
296
+ * @return Mage_Sales_Model_Order
297
+ */
298
+ protected function _saveOrder($quote)
299
+ {
300
+ $quote->setCustomerId(null);
301
+ $quote->setCustomerEmail($quote->getBillingAddress()->getEmail());
302
+ $quote->setCustomerIsGuest(true);
303
+ $quote->setCustomerGroupId(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID);
304
+
305
+ /** @var $service Mage_Sales_Model_Service_Quote */
306
+ $service = Mage::getModel('sales/service_quote', $quote);
307
+ $service->submitAll();
308
+
309
+ /** @var $checkoutSession Mage_Checkout_Model_Session */
310
+ $checkoutSession = Mage::getSingleton('checkout/session');
311
+ $checkoutSession->setLastQuoteId($quote->getId());
312
+ $checkoutSession->setLastSuccessQuoteId($quote->getId());
313
+ $checkoutSession->clearHelperData();
314
+
315
+ $order = $service->getOrder();
316
+
317
+ if ($order->getId()) {
318
+ Mage::dispatchEvent('checkout_type_onepage_save_order_after', array('order'=>$order, 'quote'=>$quote));
319
+
320
+ /**
321
+ * we only want to send to customer about new order when there is no redirect to third party
322
+ */
323
+ if ($order->getCanSendNewEmailFlag()) {
324
+ try {
325
+ $order->sendNewOrderEmail();
326
+ } catch (Exception $e) {
327
+ Mage::logException($e);
328
+ }
329
+ }
330
+
331
+ // add order information to the session
332
+ $checkoutSession->setLastOrderId($order->getId());
333
+ $checkoutSession->setRedirectUrl(null);
334
+ $checkoutSession->setLastRealOrderId($order->getIncrementId());
335
+
336
+ // as well a billing agreement can be created
337
+ $agreement = $order->getPayment()->getBillingAgreement();
338
+ if ($agreement) {
339
+ $checkoutSession->setLastBillingAgreementId($agreement->getId());
340
+ }
341
+ }
342
+
343
+ // add recurring profiles information to the session
344
+ $profiles = $service->getRecurringPaymentProfiles();
345
+ if ($profiles) {
346
+ $ids = array();
347
+ foreach ($profiles as $profile) {
348
+ $ids[] = $profile->getId();
349
+ }
350
+ $checkoutSession->setLastRecurringProfileIds($ids);
351
+ }
352
+
353
+ Mage::dispatchEvent(
354
+ 'checkout_submit_all_after',
355
+ array('order' => $order, 'quote' => $quote, 'recurring_profiles' => $profiles)
356
+ );
357
+
358
+ $quote->save();
359
+ return $order;
360
+ }
361
+
362
+ /**
363
+ * @param string $minkasuTransactionId
364
+ * @param string $orderId
365
+ *
366
+ * @return array
367
+ */
368
+ protected function _updateMinkasuTransactionWithOrderId($minkasuTransactionId, $orderId)
369
+ {
370
+ /** @var $client Minkasu_Wallet_Model_Api_Client */
371
+ $client = Mage::getModel('minkasu_wallet/api_client');
372
+ $result = $client->getType('transaction')->updateTransaction($minkasuTransactionId, array('merchant_bill_number' => $orderId), NULL);
373
+
374
+ return $result;
375
+ }
376
+
377
+ /**
378
+ * @return $this
379
+ */
380
+ protected function _cleanCheckoutSessionParams()
381
+ {
382
+ /** @var $helper Minkasu_Wallet_Helper_Data */
383
+ $helper = Mage::helper('minkasu_wallet');
384
+ $helper->cleanCheckoutSessionParams();
385
+ return $this;
386
+ }
387
+
388
+ /**
389
+ * @param string $error
390
+ *
391
+ * @return string
392
+ */
393
+ protected function _prepareErrorBody($error)
394
+ {
395
+ return $this->_prepareBody(array('error' => $this->__($error)));
396
+ }
397
+
398
+ /**
399
+ * @param array $data
400
+ *
401
+ * @return string
402
+ */
403
+ protected function _prepareBody(array $data)
404
+ {
405
+ /** @var $helper Mage_Core_Helper_Data */
406
+ $helper = Mage::helper('core');
407
+ return $helper->jsonEncode($data);
408
+ }
409
+ }
410
+ ?>
app/code/community/Minkasu/Wallet/controllers/TransactionController.php ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Minkasu_Wallet_TransactionController extends Mage_Core_Controller_Front_Action
4
+ {
5
+ /**
6
+ * Create a Minkasu transaction
7
+ */
8
+ public function createAction()
9
+ {
10
+ /** @var $cart Mage_Checkout_Model_Cart */
11
+ $cart = Mage::getModel('checkout/cart');
12
+ $quote = $cart->getQuote();
13
+ $checkoutSession = $cart->getCheckoutSession();
14
+
15
+ $expectedAddressInfo = NULL;
16
+ $shippingAddress = $quote->getShippingAddress();
17
+ if ($shippingAddress != NULL){
18
+ $expectedAddress = ($shippingAddress->exportCustomerAddress());
19
+ if ($expectedAddress != NULL) {
20
+ $data = $expectedAddress->getData();
21
+ $expectedAddressInfo = array (
22
+ 'zip' => $data["postcode"],
23
+ 'state' => $data["region"]
24
+ );
25
+ }
26
+ }
27
+
28
+ try {
29
+ /** @var $session Mage_Core_Model_Session */
30
+ $session = Mage::getSingleton('core/session');
31
+ if ($this->getRequest()->getParam('form_key') !== $session->getFormKey()) {
32
+ Mage::throwException($this->__('Wrong form key.'));
33
+ }
34
+
35
+ /** @var $client Minkasu_Wallet_Model_Api_Client */
36
+ $client = Mage::getModel('minkasu_wallet/api_client');
37
+ $transactionInfo = $client->getType('transaction')->createTransaction($quote, $expectedAddressInfo);
38
+
39
+ $checkoutSession->setData('minkasu_amount', $quote->getGrandTotal());
40
+ $checkoutSession->setData('minkasu_bill_number', $quote->getId());
41
+ $checkoutSession->setData('minkasu_txn_id', $transactionInfo['txn_id']);
42
+ $checkoutSession->setData('minkasu_payment_token',$transactionInfo['payment_token']);
43
+ $result = array(
44
+ 'txn_id' => $transactionInfo['txn_id'],
45
+ 'payment_code' => $transactionInfo['payment_code'],
46
+ 'payment_code_ttl' => $transactionInfo['payment_code_ttl'],
47
+ );
48
+ } catch (Exception $e) {
49
+ Mage::logException($e);
50
+ $result = array('error' => $e->getMessage());
51
+ }
52
+
53
+
54
+ $this->getResponse()->setHeader('Content-type', 'application/json');
55
+ $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
56
+ }
57
+
58
+ /**
59
+ * Update a Minkasu transaction
60
+ */
61
+ public function updateAction()
62
+ {
63
+ /** @var $cart Mage_Checkout_Model_Cart */
64
+ $cart = Mage::getModel('checkout/cart');
65
+ $quote = $cart->getQuote();
66
+ $checkoutSession = $cart->getCheckoutSession();
67
+
68
+ /** @var $walletHelper Minkasu_Wallet_Helper_Data */
69
+ $walletHelper = Mage::helper('minkasu_wallet');
70
+ $minkasuTransactionData = array('amount' => $walletHelper->convertDollarsToCents($quote->getGrandTotal()));
71
+ $minkasuTransactionId = $checkoutSession->getData('minkasu_txn_id');
72
+
73
+ $expectedAddressInfo = NULL;
74
+ $shippingAddress = $quote->getShippingAddress();
75
+ if ($shippingAddress != NULL){
76
+ $expectedAddress = ($shippingAddress->exportCustomerAddress());
77
+ if ($expectedAddress != NULL) {
78
+ $data = $expectedAddress->getData();
79
+ $expectedAddressInfo = array (
80
+ 'zip' => $data["postcode"],
81
+ 'state' => $data["region"]
82
+ );
83
+ }
84
+ }
85
+
86
+ try {
87
+ /** @var $session Mage_Core_Model_Session */
88
+ $session = Mage::getSingleton('core/session');
89
+ if ($this->getRequest()->getParam('form_key') !== $session->getFormKey()) {
90
+ Mage::throwException($this->__('Wrong form key.'));
91
+ }
92
+
93
+ if (!$minkasuTransactionId) {
94
+ Mage::throwException($this->__("Transaction doesn't exist."));
95
+ }
96
+ /** @var $client Minkasu_Wallet_Model_Api_Client */
97
+ $client = Mage::getModel('minkasu_wallet/api_client');
98
+ $transactionInfo = $client->getType('transaction')
99
+ ->updateTransaction($minkasuTransactionId, $minkasuTransactionData, $expectedAddressInfo);
100
+
101
+ $checkoutSession->setData('minkasu_amount', $quote->getGrandTotal());
102
+ $checkoutSession->setData('minkasu_bill_number', $quote->getId());
103
+ $checkoutSession->setData('minkasu_txn_id', $transactionInfo['txn_id']);
104
+ // Payment token will not be returned on an update transaction.
105
+ // Overwriting existing token with null causes later auth to fail.
106
+ //$checkoutSession->setData('minkasu_payment_token',$transactionInfo['payment_token']);
107
+ $result = array(
108
+ 'txn_id' => $transactionInfo['txn_id'],
109
+ 'payment_code' => $transactionInfo['payment_code'],
110
+ 'payment_code_ttl' => $transactionInfo['payment_code_ttl'],
111
+ );
112
+ } catch (Exception $e) {
113
+ Mage::logException($e);
114
+ $result = array('error' => $e->getMessage());
115
+ }
116
+
117
+
118
+ $this->getResponse()->setHeader('Content-type', 'application/json');
119
+ $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
120
+ }
121
+ }
app/code/community/Minkasu/Wallet/controllers/TransactionController.php~ ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Minkasu_Wallet_TransactionController extends Mage_Core_Controller_Front_Action
4
+ {
5
+ /**
6
+ * Create a Minkasu transaction
7
+ */
8
+ public function createAction()
9
+ {
10
+ /** @var $cart Mage_Checkout_Model_Cart */
11
+ $cart = Mage::getModel('checkout/cart');
12
+ $quote = $cart->getQuote();
13
+ $checkoutSession = $cart->getCheckoutSession();
14
+
15
+ try {
16
+ /** @var $session Mage_Core_Model_Session */
17
+ $session = Mage::getSingleton('core/session');
18
+ if ($this->getRequest()->getParam('form_key') !== $session->getFormKey()) {
19
+ Mage::throwException($this->__('Wrong form key.'));
20
+ }
21
+
22
+ /** @var $client Minkasu_Wallet_Model_Api_Client */
23
+ $client = Mage::getModel('minkasu_wallet/api_client');
24
+ $transactionInfo = $client->getType('transaction')->createTransaction($quote);
25
+
26
+ $checkoutSession->setData('minkasu_amount', $quote->getGrandTotal());
27
+ $checkoutSession->setData('minkasu_bill_number', $quote->getId());
28
+ $checkoutSession->setData('minkasu_txn_id', $transactionInfo['txn_id']);
29
+ $checkoutSession->setData('minkasu_payment_token',$transactionInfo['payment_token']);
30
+ $result = array(
31
+ 'txn_id' => $transactionInfo['txn_id'],
32
+ 'payment_code' => $transactionInfo['payment_code'],
33
+ 'payment_code_ttl' => $transactionInfo['payment_code_ttl'],
34
+ );
35
+ } catch (Exception $e) {
36
+ Mage::logException($e);
37
+ $result = array('error' => $e->getMessage());
38
+ }
39
+
40
+
41
+ $this->getResponse()->setHeader('Content-type', 'application/json');
42
+ $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
43
+ }
44
+
45
+ /**
46
+ * Update a Minkasu transaction
47
+ */
48
+ public function updateAction()
49
+ {
50
+ /** @var $cart Mage_Checkout_Model_Cart */
51
+ $cart = Mage::getModel('checkout/cart');
52
+ $quote = $cart->getQuote();
53
+ $checkoutSession = $cart->getCheckoutSession();
54
+
55
+ /** @var $walletHelper Minkasu_Wallet_Helper_Data */
56
+ $walletHelper = Mage::helper('minkasu_wallet');
57
+ $minkasuTransactionData = array('amount' => $walletHelper->convertDollarsToCents($quote->getGrandTotal()));
58
+ $minkasuTransactionId = $checkoutSession->getData('minkasu_txn_id');
59
+
60
+ try {
61
+ /** @var $session Mage_Core_Model_Session */
62
+ $session = Mage::getSingleton('core/session');
63
+ if ($this->getRequest()->getParam('form_key') !== $session->getFormKey()) {
64
+ Mage::throwException($this->__('Wrong form key.'));
65
+ }
66
+
67
+ if (!$minkasuTransactionId) {
68
+ Mage::throwException($this->__("Transaction doesn't exist."));
69
+ }
70
+ /** @var $client Minkasu_Wallet_Model_Api_Client */
71
+ $client = Mage::getModel('minkasu_wallet/api_client');
72
+ $transactionInfo = $client->getType('transaction')
73
+ ->updateTransaction($minkasuTransactionId, $minkasuTransactionData);
74
+
75
+ $checkoutSession->setData('minkasu_amount', $quote->getGrandTotal());
76
+ $checkoutSession->setData('minkasu_bill_number', $quote->getId());
77
+ $checkoutSession->setData('minkasu_txn_id', $transactionInfo['txn_id']);
78
+ $checkoutSession->setData('minkasu_payment_token',$transactionInfo['payment_token']);
79
+ $result = array(
80
+ 'txn_id' => $transactionInfo['txn_id'],
81
+ 'payment_code' => $transactionInfo['payment_code'],
82
+ 'payment_code_ttl' => $transactionInfo['payment_code_ttl'],
83
+ );
84
+ } catch (Exception $e) {
85
+ Mage::logException($e);
86
+ $result = array('error' => $e->getMessage());
87
+ }
88
+
89
+
90
+ $this->getResponse()->setHeader('Content-type', 'application/json');
91
+ $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
92
+ }
93
+ }
app/code/community/Minkasu/Wallet/etc/config.xml ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Minkasu_Wallet>
5
+ <version>0.0.0.1</version>
6
+ </Minkasu_Wallet>
7
+ </modules>
8
+ <global>
9
+ <models>
10
+ <minkasu_wallet>
11
+ <class>Minkasu_Wallet_Model</class>
12
+ </minkasu_wallet>
13
+ </models>
14
+ <helpers>
15
+ <minkasu_wallet>
16
+ <class>Minkasu_Wallet_Helper</class>
17
+ </minkasu_wallet>
18
+ </helpers>
19
+ <resources>
20
+ <minkasu_wallet_setup>
21
+ <setup>
22
+ <module>Minkasu_Wallet</module>
23
+ <class>Mage_Core_Model_Resource_Setup</class>
24
+ </setup>
25
+ <connection>
26
+ <use>core_setup</use>
27
+ </connection>
28
+ </minkasu_wallet_setup>
29
+ </resources>
30
+ <blocks>
31
+ <minkasu_wallet>
32
+ <class>Minkasu_Wallet_Block</class>
33
+ </minkasu_wallet>
34
+ </blocks>
35
+ <events>
36
+ <checkout_cart_save_after>
37
+ <observers>
38
+ <minkasu_wallet_save_order_quote_to_session>
39
+ <type>singleton</type>
40
+ <class>minkasu_wallet/observer</class>
41
+ <method>saveOrderQuoteToSession</method>
42
+ </minkasu_wallet_save_order_quote_to_session>
43
+ </observers>
44
+ </checkout_cart_save_after>
45
+ <controller_action_predispatch_checkout_onepage_index>
46
+ <observers>
47
+ <minkasu_wallet_show_notice>
48
+ <type>singleton</type>
49
+ <class>minkasu_wallet/observer</class>
50
+ <method>showNotice</method>
51
+ </minkasu_wallet_show_notice>
52
+ </observers>
53
+ </controller_action_predispatch_checkout_onepage_index>
54
+ </events>
55
+ </global>
56
+ <frontend>
57
+ <routers>
58
+ <minkasu_wallet>
59
+ <use>standard</use>
60
+ <args>
61
+ <module>Minkasu_Wallet</module>
62
+ <frontName>minkasu_wallet</frontName>
63
+ </args>
64
+ </minkasu_wallet>
65
+ </routers>
66
+ <layout>
67
+ <updates>
68
+ <minkasu_wallet>
69
+ <file>minkasu_wallet.xml</file>
70
+ </minkasu_wallet>
71
+ </updates>
72
+ </layout>
73
+ </frontend>
74
+ <adminhtml>
75
+ <layout>
76
+ <updates>
77
+ <minkasu_wallet>
78
+ <file>minkasu_wallet.xml</file>
79
+ </minkasu_wallet>
80
+ </updates>
81
+ </layout>
82
+ </adminhtml>
83
+ <admin>
84
+ <routers>
85
+ <adminhtml>
86
+ <args>
87
+ <modules>
88
+ <contentmanager before="Mage_Adminhtml">Minkasu_Wallet_Adminhtml</contentmanager>
89
+ </modules>
90
+ </args>
91
+ </adminhtml>
92
+ </routers>
93
+ </admin>
94
+ <default>
95
+ <payment>
96
+ <minkasu_wallet>
97
+ <account_id backend_model="adminhtml/system_config_backend_encrypted"/>
98
+ <active>0</active>
99
+ <gateway_url>https://transactions.minkasu.com</gateway_url>
100
+ <model>minkasu_wallet/payment</model>
101
+ <order_status>pending</order_status>
102
+ <title>Minkasu Smartphone Checkout</title>
103
+ <payment_action>authorize</payment_action>
104
+ <token backend_model="adminhtml/system_config_backend_encrypted"/>
105
+ </minkasu_wallet>
106
+ </payment>
107
+ </default>
108
+ </config>
app/code/community/Minkasu/Wallet/etc/system.xml ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <sections>
4
+ <payment>
5
+ <groups>
6
+ <minkasu_wallet translate="label comment" module="minkasu_wallet">
7
+ <label>Minkasu. Smartphone Checkout</label>
8
+ <comment><![CDATA[<a href="#" onclick="openCreateMerchantPopup(); return false;">%s</a>]]></comment>
9
+ <frontend_model>minkasu_wallet/adminhtml_system_config_frontend_minkasuGroup</frontend_model>
10
+ <sort_order>670</sort_order>
11
+ <show_in_default>1</show_in_default>
12
+ <show_in_website>1</show_in_website>
13
+ <show_in_store>1</show_in_store>
14
+ <fields>
15
+ <active translate="label">
16
+ <label>Enabled</label>
17
+ <frontend_type>select</frontend_type>
18
+ <source_model>adminhtml/system_config_source_yesno</source_model>
19
+ <backend_model>minkasu_wallet/system_config_backend_minkasuStatus</backend_model>
20
+ <sort_order>10</sort_order>
21
+ <show_in_default>1</show_in_default>
22
+ <show_in_website>1</show_in_website>
23
+ <show_in_store>0</show_in_store>
24
+ </active>
25
+ <title translate="label">
26
+ <label>Title</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
+ </title>
33
+ <gateway_url>
34
+ <label>Gateway URL</label>
35
+ <frontend_type>text</frontend_type>
36
+ <sort_order>20</sort_order>
37
+ <sort_order>30</sort_order>
38
+ <show_in_default>1</show_in_default>
39
+ <show_in_website>1</show_in_website>
40
+ <show_in_store>0</show_in_store>
41
+ </gateway_url>
42
+ <account_id translate="label">
43
+ <label>Account Id</label>
44
+ <comment><![CDATA[This data is stored encrypted in the database.]]></comment>
45
+ <frontend_type>text</frontend_type>
46
+ <backend_model>adminhtml/system_config_backend_encrypted</backend_model>
47
+ <sort_order>40</sort_order>
48
+ <show_in_default>1</show_in_default>
49
+ <show_in_website>1</show_in_website>
50
+ <show_in_store>0</show_in_store>
51
+ </account_id>
52
+ <token translate="label">
53
+ <label>Token</label>
54
+ <comment><![CDATA[This data is stored encrypted in the database.]]></comment>
55
+ <frontend_type>text</frontend_type>
56
+ <backend_model>adminhtml/system_config_backend_encrypted</backend_model>
57
+ <sort_order>50</sort_order>
58
+ <show_in_default>1</show_in_default>
59
+ <show_in_website>1</show_in_website>
60
+ <show_in_store>0</show_in_store>
61
+ </token>
62
+ <order_status translate="label">
63
+ <label>New Order Status</label>
64
+ <frontend_type>select</frontend_type>
65
+ <source_model>adminhtml/system_config_source_order_status</source_model>
66
+ <sort_order>60</sort_order>
67
+ <show_in_default>1</show_in_default>
68
+ <show_in_website>1</show_in_website>
69
+ <show_in_store>0</show_in_store>
70
+ </order_status>
71
+ </fields>
72
+ </minkasu_wallet>
73
+ </groups>
74
+ </payment>
75
+ </sections>
76
+ </config>
app/code/community/Minkasu/Wallet/sql/minkasu_wallet_setup/install-0.0.0.1.php ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /** @var $helper Minkasu_Wallet_Helper_Data */
4
+ $helper = Mage::helper('minkasu_wallet');
5
+ /** @var $notice Mage_AdminNotification_Model_Inbox */
6
+ $notice = Mage::getModel('adminnotification/inbox');
7
+ $message = $helper->__(
8
+ 'You have installed Minkasu_Wallet module. Please open "System" > "Configuration" > "Sales" > "Payment Methods"'
9
+ . ' for creating a merchant account</a>.'
10
+ );
11
+ $notice->addNotice($message, $message);
app/design/adminhtml/default/default/layout/minkasu_wallet.xml ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout version="0.1.0">
3
+ <adminhtml_system_config_edit>
4
+ <reference name="head">
5
+ <action method="addItem">
6
+ <type>js_css</type>
7
+ <name>prototype/windows/themes/default.css</name>
8
+ </action>
9
+ <action method="addCss">
10
+ <name>lib/prototype/windows/themes/magento.css</name>
11
+ </action>
12
+ </reference>
13
+ <reference name="content">
14
+ <block type="adminhtml/template" name="minkasu_wallet.merchant.popup" template="minkasu/wallet/merchant/popup.phtml"/>
15
+ </reference>
16
+ </adminhtml_system_config_edit>
17
+
18
+ <adminhtml_minkasu_wallet_merchant_create>
19
+ <reference name="root">
20
+ <action method="setTemplate">
21
+ <path>empty.phtml</path>
22
+ </action>
23
+ </reference>
24
+ <reference name="content">
25
+ <block type="core/messages" name="messages" as="messages"/>
26
+ <block type="minkasu_wallet/adminhtml_merchant_create" name="minkasu_wallet.merchant.create"/>
27
+ </reference>
28
+ <remove name="after_body_start"/>
29
+ <remove name="global_notices"/>
30
+ <remove name="before_body_end"/>
31
+ </adminhtml_minkasu_wallet_merchant_create>
32
+
33
+ <adminhtml_minkasu_wallet_merchant_edit>
34
+ <reference name="root">
35
+ <action method="setTemplate">
36
+ <path>empty.phtml</path>
37
+ </action>
38
+ </reference>
39
+ <reference name="content">
40
+ <block type="core/messages" name="messages" as="messages"/>
41
+ <block type="minkasu_wallet/adminhtml_merchant_edit" name="minkasu_wallet.merchant.edit"/>
42
+ </reference>
43
+ <remove name="after_body_start"/>
44
+ <remove name="global_notices"/>
45
+ <remove name="before_body_end"/>
46
+ </adminhtml_minkasu_wallet_merchant_edit>
47
+
48
+ <adminhtml_minkasu_wallet_merchant_successcreate>
49
+ <reference name="root">
50
+ <action method="setTemplate">
51
+ <path>empty.phtml</path>
52
+ </action>
53
+ </reference>
54
+ <reference name="content">
55
+ <block type="core/messages" name="messages" as="messages"/>
56
+ <block type="minkasu_wallet/adminhtml_merchant_create_success" name="minkasu_wallet.merchant.create.success" template="minkasu/wallet/merchant/create/success.phtml"/>
57
+ </reference>
58
+ <remove name="after_body_start"/>
59
+ <remove name="global_notices"/>
60
+ <remove name="before_body_end"/>
61
+ </adminhtml_minkasu_wallet_merchant_successcreate>
62
+
63
+ <adminhtml_minkasu_wallet_merchant_successupdate>
64
+ <reference name="root">
65
+ <action method="setTemplate">
66
+ <path>empty.phtml</path>
67
+ </action>
68
+ </reference>
69
+ <reference name="content">
70
+ <block type="core/messages" name="messages" as="messages"/>
71
+ <block type="adminhtml/template" name="minkasu_wallet.merchant.update.success"/>
72
+ </reference>
73
+ <remove name="after_body_start"/>
74
+ <remove name="global_notices"/>
75
+ <remove name="before_body_end"/>
76
+ </adminhtml_minkasu_wallet_merchant_successupdate>
77
+ </layout>
app/design/adminhtml/default/default/template/minkasu/wallet/merchant/create/success.phtml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php /** @var $this Minkasu_Wallet_Block_Adminhtml_Merchant_Create_Success */ ?>
2
+
3
+ <p><?php echo $this->__('Account Id:') ?> <?php echo $this->getApiAccountId() ?></p>
4
+ <p><?php echo $this->__('Account Token: ') ?> <?php echo $this->getApiToken() ?></p>
5
+ <script type="text/javascript">
6
+ var parentDocument = window.parent.document;
7
+ parentDocument.getElementById('payment_minkasu_wallet_account_id').value = '<?php echo $this->getApiAccountId() ?>';
8
+ parentDocument.getElementById('payment_minkasu_wallet_token').value = '<?php echo $this->getApiToken() ?>';
9
+ </script>
app/design/adminhtml/default/default/template/minkasu/wallet/merchant/popup.phtml ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /** @var $apiHelper Minkasu_Wallet_Helper_Api */
3
+ $apiHelper = Mage::helper('minkasu_wallet/api');
4
+ $isMerchantExist = $apiHelper->getApiAccountId() && $apiHelper->getApiToken();
5
+ ?>
6
+ <script type="text/javascript">
7
+ function openCreateMerchantPopup() {
8
+ var url = '<?php echo $this->getUrl('adminhtml/minkasu_wallet_merchant/' . ($isMerchantExist ? 'edit' : 'create')) ?>';
9
+ var loadingMask = $('loading-mask');
10
+
11
+ if ($('browser_window') && typeof(Windows) != 'undefined') {
12
+ Windows.focus('browser_window');
13
+ return;
14
+ }
15
+ var dialogWindow = Dialog.info(null, {
16
+ closable:true,
17
+ resizable:false,
18
+ draggable:false,
19
+ className:'magento',
20
+ windowClassName:'popup-window',
21
+ width:600,
22
+ height:<?php echo ($isMerchantExist ? 200 : 335) ?>,
23
+ zIndex:1000,
24
+ recenterAuto:true,
25
+ hideEffect:Element.hide,
26
+ showEffect:function() {
27
+ loadingMask.style.zIndex = Windows.maxZIndex + 2;
28
+ loadingMask.show();
29
+ },
30
+ id:'browser_window',
31
+ url:url,
32
+ onload:function() {
33
+ loadingMask.hide();
34
+ Element.show('browser_window');
35
+ }
36
+ });
37
+ }
38
+ </script>
app/design/frontend/base/default/layout/minkasu_wallet.xml ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout version="0.1.0">
3
+ <checkout_cart_index>
4
+ <reference name="checkout.cart.methods">
5
+ <block type="minkasu_wallet/pay" name="checkout.cart.methods.minkasu_wallet.bottom">
6
+ <action method="setTemplate" ifconfig="payment/minkasu_wallet/active">
7
+ <template>minkasu/wallet/pay.phtml</template>
8
+ </action>
9
+ </block>
10
+ </reference>
11
+ </checkout_cart_index>
12
+ </layout>
app/design/frontend/base/default/template/minkasu/wallet/pay.phtml ADDED
@@ -0,0 +1,192 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!--p>Checkout with Minkasu</p-->
2
+
3
+ <?php
4
+
5
+ $chko_session = Mage::getSingleton('checkout/session');
6
+
7
+ $minkasu_amount = $chko_session->getData('minkasu_amount');
8
+ $minkasu_bill_number = $chko_session->getData('minkasu_bill_number');
9
+ $minkasu_txn_id = $chko_session->getData('minkasu_txn_id');
10
+
11
+
12
+ $shipping_method = $chko_session->getData('minkasu_shipping_method');
13
+ $shipping_estimated = $chko_session->getData('minkasu_shipping_estimated');
14
+ $quote = $chko_session->getQuote();
15
+
16
+ $shipping_estimate_not_needed = ($quote->isVirtual() || $shipping_estimated);
17
+
18
+ $chkout_btn_id = "button-mk-chkout";
19
+
20
+ ?>
21
+
22
+ <?php
23
+ /** @var $_apiHelper Minkasu_Wallet_Helper_Api */
24
+ $_apiHelper = Mage::helper('minkasu_wallet/api');
25
+ $_apiGatewayUrl = $_apiHelper->getApiGatewayUrl();
26
+ ?>
27
+ <link href="<?php echo $_apiGatewayUrl ?>/scripts/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
28
+ <div class="row">
29
+ <div class="col-sm-12" style="text-align:right" id="minkasu_payment_div"></div>
30
+ </div>
31
+
32
+ <div class="buttons" style="height: 45px;">
33
+ <div class="right">
34
+ <input type="button" value="Checkout with Smart Phone (Minkasu)" id=<?php echo $chkout_btn_id ?> class="button" />
35
+ </div>
36
+ </div>
37
+
38
+ <script type="text/javascript">
39
+
40
+ var resolve_jquery_conflict = false;
41
+
42
+ if (typeof jQuery !== 'undefined') {
43
+ resolve_jquery_conflict = true;
44
+ }
45
+
46
+ var resolve_dollar_sym = false;
47
+
48
+ if (typeof $ !== 'undefined') {
49
+ resolve_dollar_sym = true;
50
+ }
51
+
52
+
53
+ </script>
54
+
55
+ <script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
56
+ <script type="text/javascript" src="<?php echo $_apiGatewayUrl ?>/scripts/bootstrap/dist/js/bootstrap.min.js"></script>
57
+ <script> jQuery.support.cors = true; </script>
58
+ <script type="text/javascript" src="<?php echo $_apiGatewayUrl ?>/scripts/jquery.qrcode.min.js"></script>
59
+ <script type="text/javascript">
60
+
61
+ var minkasuJQuery = null;
62
+
63
+ if (resolve_jquery_conflict) {
64
+ console.log("Restoring previous version of jquery");
65
+ minkasuJQuery = jQuery.noConflict(true);
66
+ } else if (resolve_dollar_sym) {
67
+ console.log("Restoring dollar symbol");
68
+ minkasuJQuery = jQuery.noConflict(); // restore only the $ symbol
69
+ } else {
70
+ console.log("No previous version of jquery or dollar symbol loaded");
71
+ minkasuJQuery = jQuery;
72
+ }
73
+
74
+ (function($) {
75
+
76
+ var minkasu_session_ready_for_chkout = function() {
77
+
78
+ <?php if ($shipping_estimate_not_needed): ?>
79
+ return true;
80
+ <?php else: ?>
81
+ alert("Please estimate shipping and taxes and retry.");
82
+ return false;
83
+ <?php endif; ?>
84
+
85
+ };
86
+
87
+ var minkasu_get_txnid_fn = function(mk_data) {
88
+
89
+ <?php if ($minkasu_txn_id && $minkasu_bill_number == $quote->getId()): ?>
90
+ <?php if ($minkasu_amount == $quote->getGrandTotal()): ?>
91
+ mk_data.error("Transaction id requested when already present.");
92
+ return;
93
+ <?php else: ?>
94
+ $.ajax({
95
+ url: '<?php echo $this->getUrl('minkasu_wallet/transaction/update') ?>',
96
+ type: 'post',
97
+ data: {form_key: '<?php echo Mage::getSingleton('core/session')->getFormKey() ?>'},
98
+ dataType: 'json',
99
+ success: function(resp) {
100
+ if (typeof resp.error !== 'undefined') {
101
+ mk_data.error(resp.error);
102
+ } else {
103
+ mk_data.success({"txn_id": resp.txn_id, "payment_code": resp.payment_code, "payment_code_ttl": resp.payment_code_ttl});
104
+ }
105
+ return;
106
+ },
107
+ error: function(jqXHR, textStatus, errorThrown) {
108
+ errorMsg = "Error updating txn_id: " + textStatus + "; \n" + errorThrown + "\n" + JSON.stringify(jqXHR);
109
+ mk_data.error(errorMsg);
110
+ return;
111
+ }
112
+ });
113
+ return;
114
+ <?php endif; ?>
115
+ <?php else: ?>
116
+ $.ajax({
117
+ url: '<?php echo $this->getUrl('minkasu_wallet/transaction/create') ?>',
118
+ type: 'post',
119
+ data: {form_key: '<?php echo Mage::getSingleton('core/session')->getFormKey() ?>'},
120
+ dataType: 'json',
121
+ success: function(resp) {
122
+ if (typeof resp.error !== 'undefined') {
123
+ mk_data.error(resp.error);
124
+ } else {
125
+ mk_data.success({"txn_id": resp.txn_id, "payment_code": resp.payment_code, "payment_code_ttl": resp.payment_code_ttl});
126
+ }
127
+ return;
128
+ },
129
+ error: function(jqXHR, textStatus, errorThrown) {
130
+ errorMsg = "Error getting new txn_id: " + textStatus + "; \n" + errorThrown + "\n" + JSON.stringify(jqXHR);
131
+ mk_data.error(errorMsg);
132
+ return;
133
+ }
134
+ });
135
+ <?php endif; ?>
136
+
137
+ };
138
+
139
+
140
+ $(document).ready(function() {
141
+ var minkasu_txn_id_good_for_use = false;
142
+ <?php if ($minkasu_txn_id && $minkasu_bill_number == $quote->getId()): ?>
143
+ <?php if ($minkasu_amount == $quote->getGrandTotal()): ?>
144
+ minkasu_txn_id_good_for_use = true;
145
+ <?php endif; ?>
146
+ <?php endif; ?>
147
+
148
+ $.getScript('<?php echo $_apiGatewayUrl ?>/scripts/minkasu-1.2.js', function() {
149
+
150
+ var payment_args = {
151
+ transaction_id: ((minkasu_txn_id_good_for_use)?'<?php echo $minkasu_txn_id ?>':null),
152
+ pre_check_fn: minkasu_session_ready_for_chkout,
153
+ get_txn_id_fn: ((minkasu_txn_id_good_for_use)?null: minkasu_get_txnid_fn)
154
+ };
155
+
156
+ var minkasu_options = {btn_elem_selector: '#button-mk-chkout', redirect_url: '<?php echo $this->getUrl('checkout/cart') ?>'};
157
+
158
+ accept_payment_with_minkasu('#minkasu_payment_div', payment_args, minkasu_options, $,
159
+ function (payment_details) {
160
+ console.log('Obtained customer info: ' + JSON.stringify(payment_details));
161
+ if (payment_details.discardable_residual_page) {
162
+ window.location = '<?php echo $this->getUrl('') ?>';
163
+ return;
164
+ }
165
+
166
+ <?php if (($minkasu_amount) && ($minkasu_bill_number)): ?>
167
+ payment_details['amount'] = <?php echo $minkasu_amount ?>;
168
+ payment_details['merchant_bill_num'] = <?php echo $minkasu_bill_number ?>;
169
+ <?php endif; ?>
170
+ $.ajax({
171
+ url: '<?php echo $this->getUrl('minkasu_wallet/payment/paid') ?>',
172
+ type: 'post',
173
+ data: $.param(payment_details),
174
+ dataType: 'json',
175
+ success: function(json) {
176
+ console.log('Payment done call complete. Data: ' + JSON.stringify(json));
177
+ window.location.href = json['redirect_url'];
178
+ },
179
+ error: function(json) {
180
+ console.log('Payment done call failed.');
181
+ alert(json.responseJSON.error);
182
+ window.location.href = '<?php echo $this->getUrl('checkout/cart') ?>';
183
+ }
184
+ });
185
+ }
186
+ );
187
+ });
188
+
189
+ });
190
+
191
+ })(minkasuJQuery);
192
+ </script>
app/etc/modules/Minkasu_Wallet.xml ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <config>
2
+ <modules>
3
+ <Minkasu_Wallet>
4
+ <active>true</active>
5
+ <codePool>community</codePool>
6
+ <depends>
7
+ <Mage_Payment />
8
+ </depends>
9
+ </Minkasu_Wallet>
10
+ </modules>
11
+ </config>
package.xml ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>minkasu_smartphone_checkout</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license>MITL</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Enjoy higher conversion and greater security by offering a smartphone checkout option for your customers </summary>
10
+ <description>Enjoy higher conversion and greater security by offering a smartphone checkout option for your customers </description>
11
+ <notes>Minkasu features:&#xD;
12
+ &#xD;
13
+ Processes online payments using authorize.net &#xD;
14
+ Supports multi-merchant Magento instances&#xD;
15
+ Integrated with Jumio for credit card acceptance and verification &#xD;
16
+ Phone verification done by Twilio &#xD;
17
+ Mandatory phone verification for the customer prior to payment &#xD;
18
+ Order confirmation and order cancel notification to customer &#xD;
19
+ </notes>
20
+ <authors><author><name>Minkasu Inc</name><user>it-admin</user><email>it-admin@minkasu.com</email></author></authors>
21
+ <date>2015-04-02</date>
22
+ <time>23:29:03</time>
23
+ <contents><target name="magecommunity"><dir name="Minkasu"><dir name="Wallet"><dir name="Block"><dir name="Adminhtml"><dir name="Merchant"><dir name="Create"><file name="Form.php" hash="77e288884729c197292d3799b2094d7b"/><file name="Success.php" hash="d1ed1419a27fed884c9d8d83eef9546c"/></dir><file name="Create.php" hash="108bac82be521ce9a98ffdcd716c7b4c"/><dir name="Edit"><file name="Form.php" hash="6d98746a2004442e70d6fa1e0c243723"/></dir><file name="Edit.php" hash="2c0b329a6f6df4af99da5c6407c280c8"/></dir><dir name="System"><dir name="Config"><dir name="Frontend"><file name="MinkasuGroup.php" hash="e3df5a38723927aa073f462e1648ddef"/></dir></dir></dir></dir><file name="Pay.php" hash="6545b86f80ab7a1aa43ddaaecce48112"/></dir><dir name="Helper"><dir name="Api"><file name="Merchant.php" hash="4972dbcce4b79f7e2a55f6a90aafed28"/></dir><file name="Api.php" hash="06697ab598bf34eab26e2da5959c2a59"/><file name="Data.php" hash="980d68a04425701049c06a7ab54babc4"/></dir><dir name="Model"><dir name="Api"><dir name="Adapter"><file name="Abstract.php" hash="bdfd40f16708a30f05662ce7c7c0d121"/><file name="Curl.php" hash="5c4fede05147f1ad95725e498ec169c8"/></dir><file name="Client.php" hash="8575b8b0d52635b0ec5942d2ace4dba6"/><dir name="Format"><file name="Abstract.php" hash="011af2c9cd958efffbba03e411cc1627"/><file name="Json.php" hash="f32759fe608158aede8c39d4816b8236"/></dir><dir name="Type"><file name="Abstract.php" hash="df9ed9fa6e616f233c7e01d7943ee709"/><file name="Merchant.php" hash="538f7cde93085cdf11b4687fcc9c88f9"/><file name="Transaction.php" hash="e23a56c71d75e93d4fabfcca2717c6fe"/><file name="Transaction.php~" hash="23545e15da56da3800c12a4ad6ce5139"/></dir></dir><file name="Observer.php" hash="e6492743eb60b10fdaee95536149ee2d"/><file name="Observer.php~" hash="9c3277299b811406040d738af4ce5d59"/><file name="Payment.php" hash="adf9bb580fca57262754ef6e6b035ae9"/><dir name="System"><dir name="Config"><dir name="Backend"><file name="MinkasuStatus.php" hash="3d1b41d010c4ec15311beebce2e88ae5"/></dir></dir></dir></dir><dir name="controllers"><dir name="Adminhtml"><dir name="Minkasu"><dir name="Wallet"><file name="MerchantController.php" hash="33779a2e4556c232943e197146757053"/></dir></dir></dir><file name="PaymentController.php" hash="981afd634443bc7998c76ec99c286e99"/><file name="PaymentController.php~" hash="229a669ed1748eacac248ee3bb85c157"/><file name="TransactionController.php" hash="2c2a841bb1afb753bc84c9caef448965"/><file name="TransactionController.php~" hash="c931c259fde55a209111f10453a5300b"/></dir><dir name="etc"><file name="config.xml" hash="006b92ac00c051e384a2946d2fb271f2"/><file name="system.xml" hash="e8e87d81b789d0f69bd9a8d25760f5a4"/></dir><dir name="sql"><dir name="minkasu_wallet_setup"><file name="install-0.0.0.1.php" hash="ccbed051e0d98bf2fa167ea7b13edb4f"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Minkasu_Wallet.xml" hash="a8daca594f8108b5fd5f28b04842fa91"/></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="minkasu_wallet.xml" hash="95ca0132f2696fd91c0a67922030c8a2"/></dir><dir name="template"><dir name="minkasu"><dir name="wallet"><dir name="merchant"><dir name="create"><file name="success.phtml" hash="fec665badf6dc1032514ac0dd3b31996"/></dir><file name="popup.phtml" hash="328a29e8aa36cd7cc269d12128647658"/></dir></dir></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="minkasu_wallet.xml" hash="85f4110729a56420ccb82eee5eceaa6a"/></dir><dir name="template"><dir name="minkasu"><dir name="wallet"><file name="pay.phtml" hash="7430a6dec3b70e2802fa4a0aa43cb5e5"/></dir></dir></dir></dir></dir></dir></target></contents>
24
+ <compatible/>
25
+ <dependencies><required><php><min>5.2.0</min><max>5.6.0</max></php></required></dependencies>
26
+ </package>