Version Notes
-addition for estimate shipping and tax
-support for sb/live environment
Download this release
Release Info
Developer | Minkasu Inc |
Extension | minkasu_smartphone_checkout |
Version | 1.1.0 |
Comparing to | |
See all releases |
Code changes from version 1.0.0 to 1.1.0
- app/code/community/Minkasu/Wallet/Block/Adminhtml/System/Config/Frontend/MinkasuMode.php +56 -0
- app/code/community/Minkasu/Wallet/Helper/Api.php +22 -4
- app/code/community/Minkasu/Wallet/Helper/Data.php +2 -0
- app/code/community/Minkasu/Wallet/Model/Api/Type/Merchant.php +2 -0
- app/code/community/Minkasu/Wallet/Model/Api/Type/Transaction.php +1 -1
- app/code/community/Minkasu/Wallet/Model/Source/Api/Mode.php +21 -0
- app/code/community/Minkasu/Wallet/controllers/Adminhtml/Minkasu/Wallet/MerchantController.php +1 -0
- app/code/community/Minkasu/Wallet/controllers/PaymentController.php +37 -5
- app/code/community/Minkasu/Wallet/controllers/PaymentController.php.bk +432 -0
- app/code/community/Minkasu/Wallet/controllers/PaymentController.php.old +408 -0
- app/code/community/Minkasu/Wallet/controllers/TransactionController.php +8 -2
- app/code/community/Minkasu/Wallet/controllers/TransactionController.php~ +33 -4
- app/code/community/Minkasu/Wallet/etc/config.xml +2 -0
- app/code/community/Minkasu/Wallet/etc/system.xml +55 -16
- app/design/frontend/base/default/layout/minkasu_wallet.xml +5 -0
- app/design/frontend/base/default/template/minkasu/wallet/estimate_box.phtml +90 -0
- app/design/frontend/base/default/template/minkasu/wallet/pay.phtml +382 -21
- app/design/frontend/gravdept/acumen/template/minkasu/wallet/estimate_box.phtml +89 -0
- package.xml +6 -12
app/code/community/Minkasu/Wallet/Block/Adminhtml/System/Config/Frontend/MinkasuMode.php
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Minkasu_Wallet_Block_Adminhtml_System_Config_Frontend_MinkasuMode extends Mage_Adminhtml_Block_System_Config_Form_Field
|
3 |
+
{
|
4 |
+
|
5 |
+
/**
|
6 |
+
* Get element ID of the dependent field to toggle
|
7 |
+
*
|
8 |
+
* @param object $element
|
9 |
+
* @return String
|
10 |
+
*/
|
11 |
+
protected function _getToggleElementId($element)
|
12 |
+
{
|
13 |
+
return "payment_minkasu_wallet_gateway_url";
|
14 |
+
//return substr($element->getId(), 0, strrpos($element->getId(), 'gateway_url')) . 'active';
|
15 |
+
}
|
16 |
+
/**
|
17 |
+
* Get element ID of the dependent field's parent row
|
18 |
+
*
|
19 |
+
* @param object $element
|
20 |
+
* @return String
|
21 |
+
*/
|
22 |
+
protected function _getToggleRowElementId($element)
|
23 |
+
{
|
24 |
+
return 'row_'.$this->_getToggleElementId($element);
|
25 |
+
}
|
26 |
+
/**
|
27 |
+
* Override method to output our custom HTML with JavaScript
|
28 |
+
*
|
29 |
+
* @param Varien_Data_Form_Element_Abstract $element
|
30 |
+
* @return String
|
31 |
+
*/
|
32 |
+
protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
|
33 |
+
{
|
34 |
+
// Get the default HTML for this option
|
35 |
+
$html = parent::_getElementHtml($element);
|
36 |
+
// Set up additional JavaScript for our toggle action. Note we are using the two helper methods above
|
37 |
+
// to get the correct field ID's. They are hard-coded and depend on your option names in system.xml
|
38 |
+
//alert('{$element->getHtmlId()}'+ '='+ enabled);
|
39 |
+
$javaScript = "
|
40 |
+
<script type=\"text/javascript\">
|
41 |
+
Event.observe(window, 'load', function() {});
|
42 |
+
Event.observe('{$element->getHtmlId()}', 'change', function(){
|
43 |
+
enabled=$('{$element->getHtmlId()}').value;
|
44 |
+
if(enabled == 0) {
|
45 |
+
$('{$this->_getToggleElementId($element)}').value = 'https://transactions.minkasu.com';
|
46 |
+
}else {
|
47 |
+
$('{$this->_getToggleElementId($element)}').value = 'http://sb.minkasu.com';
|
48 |
+
}
|
49 |
+
$('{$this->_getToggleElementId($element)}').focus();
|
50 |
+
});
|
51 |
+
</script>";
|
52 |
+
|
53 |
+
$html .= $javaScript;
|
54 |
+
return $html;
|
55 |
+
}
|
56 |
+
}
|
app/code/community/Minkasu/Wallet/Helper/Api.php
CHANGED
@@ -4,10 +4,12 @@ class Minkasu_Wallet_Helper_Api extends Mage_Core_Helper_Data
|
|
4 |
/**
|
5 |
* Xml paths
|
6 |
*/
|
7 |
-
const XML_PATH_API_GATEWAY_URL
|
8 |
-
const XML_PATH_API_ACCOUNT_ID
|
9 |
-
const XML_PATH_API_TOKEN
|
10 |
-
const XML_PATH_API_ACTIVE
|
|
|
|
|
11 |
|
12 |
/**
|
13 |
* Minkasu API log filename
|
@@ -91,4 +93,20 @@ class Minkasu_Wallet_Helper_Api extends Mage_Core_Helper_Data
|
|
91 |
{
|
92 |
return Mage::getStoreConfigFlag(self::XML_PATH_API_ACTIVE);
|
93 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
}
|
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 |
+
const XML_PATH_API_MODE = 'payment/minkasu_wallet/mode';
|
12 |
+
const XML_PATH_API_ESTIMATE_ENABLED = 'payment/minkasu_wallet/estimate_enabled';
|
13 |
|
14 |
/**
|
15 |
* Minkasu API log filename
|
93 |
{
|
94 |
return Mage::getStoreConfigFlag(self::XML_PATH_API_ACTIVE);
|
95 |
}
|
96 |
+
|
97 |
+
/**
|
98 |
+
* @return int
|
99 |
+
*/
|
100 |
+
public function getApiMode()
|
101 |
+
{
|
102 |
+
return (int) Mage::getStoreConfigFlag(self::XML_PATH_API_MODE);
|
103 |
+
}
|
104 |
+
|
105 |
+
/**
|
106 |
+
* @return bool
|
107 |
+
*/
|
108 |
+
public function isApiEstimateEnabled()
|
109 |
+
{
|
110 |
+
return Mage::getStoreConfigFlag(self::XML_PATH_API_ESTIMATE_ENABLED);
|
111 |
+
}
|
112 |
}
|
app/code/community/Minkasu/Wallet/Helper/Data.php
CHANGED
@@ -53,6 +53,8 @@ class Minkasu_Wallet_Helper_Data extends Mage_Payment_Helper_Data
|
|
53 |
$session->unsetData('minkasu_bill_number');
|
54 |
$session->unsetData('minkasu_txn_id');
|
55 |
$session->unsetData('minkasu_payment_token');
|
|
|
|
|
56 |
return $this;
|
57 |
}
|
58 |
}
|
53 |
$session->unsetData('minkasu_bill_number');
|
54 |
$session->unsetData('minkasu_txn_id');
|
55 |
$session->unsetData('minkasu_payment_token');
|
56 |
+
$session->unsetData('minkasu_est_zip');
|
57 |
+
$session->unsetData('minkasu_est_state');
|
58 |
return $this;
|
59 |
}
|
60 |
}
|
app/code/community/Minkasu/Wallet/Model/Api/Type/Merchant.php
CHANGED
@@ -78,6 +78,8 @@ class Minkasu_Wallet_Model_Api_Type_Merchant extends Minkasu_Wallet_Model_Api_Ty
|
|
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(
|
78 |
'login_id' => $gatewayData['login_id'],
|
79 |
'key' => $gatewayData['key'],
|
80 |
'test_mode' => $gatewayData['test_mode'],
|
81 |
+
'merchant_acct_id' => $apiHelper->getApiAccountId(),
|
82 |
+
'minkasu_token' => $apiHelper->getApiToken(),
|
83 |
':id' => $apiHelper->getApiAccountId(),
|
84 |
':action' => 'gateway',
|
85 |
'headers' => array(
|
app/code/community/Minkasu/Wallet/Model/Api/Type/Transaction.php
CHANGED
@@ -68,7 +68,7 @@ class Minkasu_Wallet_Model_Api_Type_Transaction extends Minkasu_Wallet_Model_Api
|
|
68 |
'operation' => self::OPERATION_CREATE,
|
69 |
'amount' => $walletHelper->convertDollarsToCents($quote->getGrandTotal()),
|
70 |
'merchant_acct_id' => $apiHelper->getApiAccountId(),
|
71 |
-
'merchant_bill_number' =>
|
72 |
'minkasu_token' => $apiHelper->getApiToken(),
|
73 |
'beta_code' => 'mkbeta3314'
|
74 |
);
|
68 |
'operation' => self::OPERATION_CREATE,
|
69 |
'amount' => $walletHelper->convertDollarsToCents($quote->getGrandTotal()),
|
70 |
'merchant_acct_id' => $apiHelper->getApiAccountId(),
|
71 |
+
'merchant_bill_number' => -1, // Always initialize with invalid number. Will update later with order id when available
|
72 |
'minkasu_token' => $apiHelper->getApiToken(),
|
73 |
'beta_code' => 'mkbeta3314'
|
74 |
);
|
app/code/community/Minkasu/Wallet/Model/Source/Api/Mode.php
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Minkasu_Wallet_Model_Source_Api_Mode
|
4 |
+
{
|
5 |
+
/**
|
6 |
+
* Available modes
|
7 |
+
*/
|
8 |
+
const MODE_SANDBOX = 1;
|
9 |
+
const MODE_LIVE = 2;
|
10 |
+
|
11 |
+
/**
|
12 |
+
* @return array
|
13 |
+
*/
|
14 |
+
public function toOptionArray()
|
15 |
+
{
|
16 |
+
return array(
|
17 |
+
self::MODE_SANDBOX => Mage::helper('minkasu_wallet')->__('Sandbox'),
|
18 |
+
self::MODE_LIVE => Mage::helper('minkasu_wallet')->__('Live'),
|
19 |
+
);
|
20 |
+
}
|
21 |
+
}
|
app/code/community/Minkasu/Wallet/controllers/Adminhtml/Minkasu/Wallet/MerchantController.php
CHANGED
@@ -55,6 +55,7 @@ class Minkasu_Wallet_Adminhtml_Minkasu_Wallet_MerchantController extends Mage_Ad
|
|
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'],
|
55 |
'business_name' => $postData['name'],
|
56 |
'email' => $postData['email'],
|
57 |
'phone' => $postData['phone'],
|
58 |
+
'store_url' => Mage::getBaseUrl()
|
59 |
);
|
60 |
$gatewayData = array(
|
61 |
'login_id' => $postData['authNet_api_login_id'],
|
app/code/community/Minkasu/Wallet/controllers/PaymentController.php
CHANGED
@@ -2,6 +2,30 @@
|
|
2 |
|
3 |
class Minkasu_Wallet_PaymentController extends Mage_Core_Controller_Front_Action
|
4 |
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
/**
|
6 |
* Make a payment
|
7 |
*/
|
@@ -267,11 +291,19 @@ class Minkasu_Wallet_PaymentController extends Mage_Core_Controller_Front_Action
|
|
267 |
$quote->getShippingAddress()->setCollectShippingRates(true);
|
268 |
}
|
269 |
|
270 |
-
$
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
275 |
|
276 |
/** @var $checkoutSession Mage_Checkout_Model_Session */
|
277 |
$checkoutSession = Mage::getSingleton('checkout/session');
|
2 |
|
3 |
class Minkasu_Wallet_PaymentController extends Mage_Core_Controller_Front_Action
|
4 |
{
|
5 |
+
|
6 |
+
public function getShippingRatesAction()
|
7 |
+
{
|
8 |
+
|
9 |
+
$checkoutSession = Mage::getSingleton('checkout/session');
|
10 |
+
$quote = $checkoutSession->getQuote();
|
11 |
+
$address = $quote->getShippingAddress();
|
12 |
+
|
13 |
+
$rates = $address->collectShippingRates()->getGroupedAllShippingRates();
|
14 |
+
|
15 |
+
$result = array();
|
16 |
+
|
17 |
+
foreach ($rates as $carrier) {
|
18 |
+
foreach ($carrier as $rate) {
|
19 |
+
array_push($result, $rate->getData());
|
20 |
+
}
|
21 |
+
}
|
22 |
+
|
23 |
+
$this->getResponse()->setHeader('Content-type', 'application/json');
|
24 |
+
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
|
25 |
+
|
26 |
+
}
|
27 |
+
|
28 |
+
|
29 |
/**
|
30 |
* Make a payment
|
31 |
*/
|
291 |
$quote->getShippingAddress()->setCollectShippingRates(true);
|
292 |
}
|
293 |
|
294 |
+
$versionArr = Mage::getVersionInfo();
|
295 |
+
$versionStr = $versionArr['major'] . "." . $versionArr['minor'];
|
296 |
+
Mage::log("Minkasu - Magento Version: " . $versionStr);
|
297 |
+
$versionFlt = floatval($versionStr);
|
298 |
+
|
299 |
+
if ($versionFlt >= 1.8) {
|
300 |
+
Mage::log("Minkasu - Setting Payment Model Method Checks");
|
301 |
+
$data['checks'] = Mage_Payment_Model_Method_Abstract::CHECK_USE_CHECKOUT
|
302 |
+
| Mage_Payment_Model_Method_Abstract::CHECK_USE_FOR_COUNTRY
|
303 |
+
| Mage_Payment_Model_Method_Abstract::CHECK_USE_FOR_CURRENCY
|
304 |
+
| Mage_Payment_Model_Method_Abstract::CHECK_ORDER_TOTAL_MIN_MAX
|
305 |
+
| Mage_Payment_Model_Method_Abstract::CHECK_ZERO_TOTAL;
|
306 |
+
}
|
307 |
|
308 |
/** @var $checkoutSession Mage_Checkout_Model_Session */
|
309 |
$checkoutSession = Mage::getSingleton('checkout/session');
|
app/code/community/Minkasu/Wallet/controllers/PaymentController.php.bk
ADDED
@@ -0,0 +1,432 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Minkasu_Wallet_PaymentController extends Mage_Core_Controller_Front_Action
|
4 |
+
{
|
5 |
+
|
6 |
+
public function getShippingRatesAction()
|
7 |
+
{
|
8 |
+
|
9 |
+
$checkoutSession = Mage::getSingleton('checkout/session');
|
10 |
+
$quote = $checkoutSession->getQuote();
|
11 |
+
$address = $quote->getShippingAddress();
|
12 |
+
|
13 |
+
$rates = $address->collectShippingRates()->getGroupedAllShippingRates();
|
14 |
+
|
15 |
+
$result = array();
|
16 |
+
|
17 |
+
foreach ($rates as $carrier) {
|
18 |
+
foreach ($carrier as $rate) {
|
19 |
+
array_push($result, $rate->getData());
|
20 |
+
}
|
21 |
+
}
|
22 |
+
|
23 |
+
$this->getResponse()->setHeader('Content-type', 'application/json');
|
24 |
+
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
|
25 |
+
|
26 |
+
}
|
27 |
+
|
28 |
+
|
29 |
+
/**
|
30 |
+
* Make a payment
|
31 |
+
*/
|
32 |
+
public function paidAction()
|
33 |
+
{
|
34 |
+
/** @var $coreResource Mage_Core_Model_Resource */
|
35 |
+
$coreResource = Mage::getSingleton('core/resource');
|
36 |
+
$writeAdapter = $coreResource->getConnection('core_write');
|
37 |
+
|
38 |
+
// Step 1: Get the current quote object
|
39 |
+
/** @var $checkoutSession Mage_Checkout_Model_Session */
|
40 |
+
$checkoutSession = Mage::getSingleton('checkout/session');
|
41 |
+
$quote = $checkoutSession->getQuote();
|
42 |
+
|
43 |
+
try {
|
44 |
+
$writeAdapter->beginTransaction();
|
45 |
+
|
46 |
+
$minkasuTransactionId = $checkoutSession->getData('minkasu_txn_id');
|
47 |
+
$transactionInfoResponse = $this->_getMinkasuTransaction($minkasuTransactionId);
|
48 |
+
if (!isset($transactionInfoResponse['txn_state']) || $transactionInfoResponse['txn_state']
|
49 |
+
!= Minkasu_Wallet_Model_Api_Type_Transaction::STATE_PREAUTHED
|
50 |
+
) {
|
51 |
+
Mage::throwException('This transaction has wrong state.');
|
52 |
+
}
|
53 |
+
|
54 |
+
$customerDetails = $this->_extractCustomerDetails($transactionInfoResponse);
|
55 |
+
if (!($customerDetails['customer_details_valid'])) {
|
56 |
+
Mage::throwException('Required details not provided with payment.');
|
57 |
+
}
|
58 |
+
|
59 |
+
// Step 2: Set the checkout method as "guest
|
60 |
+
$quote->setCheckoutMethod('guest')->save();
|
61 |
+
// Step 2.1:Fill customer name (first name ?)
|
62 |
+
$quote->setCustomerFirstname($customerDetails['customer_name']);
|
63 |
+
// Step 3: Fill the address and save it as billing and shipping address
|
64 |
+
$addressInfo = $this->_prepareCustomerAddressInfo($customerDetails);
|
65 |
+
$this->_saveBillingAndShippingAddress($quote, $addressInfo);
|
66 |
+
|
67 |
+
// Step 4: Shipping method should already be set by now.
|
68 |
+
$checkoutSession->setStepData('shipping_method', 'complete', true);
|
69 |
+
|
70 |
+
// Step 5: Set payment method to minkasu wallet
|
71 |
+
$this->_savePayment($quote, array('method' => 'minkasu_wallet'));
|
72 |
+
|
73 |
+
// Calculate shipping rates now
|
74 |
+
$quote->getShippingAddress()->collectShippingRates()->save();
|
75 |
+
$quote->collectTotals()->save();
|
76 |
+
|
77 |
+
$writeAdapter->commit();
|
78 |
+
|
79 |
+
$order = $this->_saveOrder($quote);
|
80 |
+
|
81 |
+
if ($order->getId()) {
|
82 |
+
$this->_updateMinkasuTransactionWithOrderId($minkasuTransactionId, $order->getIncrementId());
|
83 |
+
} else {
|
84 |
+
Mage::throwException($this->__('Order has not been created.'));
|
85 |
+
}
|
86 |
+
} catch (Mage_Core_Exception $e) {
|
87 |
+
Mage::logException($e);
|
88 |
+
$writeAdapter->rollback();
|
89 |
+
|
90 |
+
try {
|
91 |
+
/** @var $client Minkasu_Wallet_Model_Api_Client */
|
92 |
+
$client = Mage::getModel('minkasu_wallet/api_client');
|
93 |
+
$client->getType('transaction')->voidTransaction($minkasuTransactionId);
|
94 |
+
} catch (Mage_Core_Exception $internalException) {
|
95 |
+
Mage::logException($internalException);
|
96 |
+
} catch (Exception $internalException) {
|
97 |
+
Mage::logException($internalException);
|
98 |
+
}
|
99 |
+
|
100 |
+
$this->_cleanCheckoutSessionParams();
|
101 |
+
$this->getResponse()->setHttpResponseCode(500);
|
102 |
+
$this->getResponse()->setBody($this->_prepareErrorBody($e->getMessage()));
|
103 |
+
$this->getResponse()->sendResponse();
|
104 |
+
die;
|
105 |
+
} catch (Exception $e) {
|
106 |
+
Mage::logException($e);
|
107 |
+
$writeAdapter->rollback();
|
108 |
+
|
109 |
+
try {
|
110 |
+
/** @var $client Minkasu_Wallet_Model_Api_Client */
|
111 |
+
$client = Mage::getModel('minkasu_wallet/api_client');
|
112 |
+
$client->getType('transaction')->voidTransaction($minkasuTransactionId);
|
113 |
+
} catch (Mage_Core_Exception $internalException) {
|
114 |
+
Mage::logException($internalException);
|
115 |
+
} catch (Exception $internalException) {
|
116 |
+
Mage::logException($internalException);
|
117 |
+
}
|
118 |
+
|
119 |
+
$this->_cleanCheckoutSessionParams();
|
120 |
+
$this->getResponse()->setHttpResponseCode(500);
|
121 |
+
$this->getResponse()->setBody(
|
122 |
+
$this->_prepareErrorBody('An error has occurred. Please contact store administrator.')
|
123 |
+
);
|
124 |
+
$this->getResponse()->sendResponse();
|
125 |
+
die;
|
126 |
+
}
|
127 |
+
|
128 |
+
$url = Mage::getUrl('checkout/onepage/success');
|
129 |
+
$this->getResponse()->setHttpResponseCode(201);
|
130 |
+
$this->getResponse()->setBody($this->_prepareBody(array('redirect_url' => $url)));
|
131 |
+
$this->getResponse()->sendResponse();
|
132 |
+
die;
|
133 |
+
}
|
134 |
+
|
135 |
+
/**
|
136 |
+
* @param string $minkasuTransactionId
|
137 |
+
*
|
138 |
+
* @return array
|
139 |
+
*/
|
140 |
+
protected function _getMinkasuTransaction($minkasuTransactionId)
|
141 |
+
{
|
142 |
+
/** @var $client Minkasu_Wallet_Model_Api_Client */
|
143 |
+
$client = Mage::getModel('minkasu_wallet/api_client');
|
144 |
+
$result = $client->getType('transaction')->getTransaction($minkasuTransactionId);
|
145 |
+
return $result;
|
146 |
+
}
|
147 |
+
|
148 |
+
/**
|
149 |
+
* @param array $response
|
150 |
+
*
|
151 |
+
* @return array
|
152 |
+
*/
|
153 |
+
protected function _extractCustomerDetails(array $response)
|
154 |
+
{
|
155 |
+
$result = array();
|
156 |
+
|
157 |
+
$result['customer_details_valid'] = false;
|
158 |
+
|
159 |
+
if (!isset($response['customer_address']) || (!isset($response['customer_name']))) {
|
160 |
+
return $result;
|
161 |
+
}
|
162 |
+
|
163 |
+
$result['customer_name'] = $response['customer_name'];
|
164 |
+
$result['street_1'] = $response['customer_address']['address_line_1'];
|
165 |
+
$result['street_2'] = $response['customer_address']['address_line_2'];
|
166 |
+
$result['city'] = $response['customer_address']['city'];
|
167 |
+
$result['state'] = $response['customer_address']['state'];
|
168 |
+
$result['zip'] = $response['customer_address']['zip'];
|
169 |
+
$result['phone'] = $response['phone'];
|
170 |
+
$result['email'] = $response['email'];
|
171 |
+
$result['customer_details_valid'] = true;
|
172 |
+
|
173 |
+
return $result;
|
174 |
+
}
|
175 |
+
|
176 |
+
/**
|
177 |
+
* @param array $customerDetails
|
178 |
+
*
|
179 |
+
* @return array
|
180 |
+
*/
|
181 |
+
protected function _prepareCustomerAddressInfo(array $customerDetails)
|
182 |
+
{
|
183 |
+
/** @var $regionModel Mage_Directory_Model_Region */
|
184 |
+
$regionModel = Mage::getModel('directory/region');
|
185 |
+
$regionModel->loadByCode($customerDetails['state'], 'US');
|
186 |
+
|
187 |
+
$customerNameParts = explode(' ', $customerDetails['customer_name']);
|
188 |
+
|
189 |
+
$addressInfo = array();
|
190 |
+
$addressInfo['firstname'] = $customerNameParts[0];
|
191 |
+
$addressInfo['lastname'] = end($customerNameParts);
|
192 |
+
$addressInfo['email'] = $customerDetails['email'];
|
193 |
+
$addressInfo['street'] = array(0 => $customerDetails['street_1'], 1 => $customerDetails['street_2']);
|
194 |
+
$addressInfo['city'] = $customerDetails['city'];
|
195 |
+
$addressInfo['region_id'] = $regionModel->getId();
|
196 |
+
$addressInfo['postcode'] = $customerDetails['zip'];
|
197 |
+
$addressInfo['country_id'] = 'US';
|
198 |
+
$addressInfo['telephone'] = $customerDetails['phone'];
|
199 |
+
$addressInfo['use_for_shipping'] = 1;
|
200 |
+
|
201 |
+
return $addressInfo;
|
202 |
+
}
|
203 |
+
|
204 |
+
/**
|
205 |
+
* @param $quote
|
206 |
+
* @param array $data
|
207 |
+
*
|
208 |
+
* @return $this
|
209 |
+
*/
|
210 |
+
protected function _saveBillingAndShippingAddress($quote, $data)
|
211 |
+
{
|
212 |
+
$address = $quote->getBillingAddress();
|
213 |
+
/** @var $addressForm Mage_Customer_Model_Form */
|
214 |
+
$addressForm = Mage::getModel('customer/form');
|
215 |
+
$addressForm->setFormCode('customer_address_edit');
|
216 |
+
$addressForm->setEntityType('customer_address');
|
217 |
+
$addressForm->setEntity($address);
|
218 |
+
// emulate request object
|
219 |
+
$addressData = $addressForm->extractData($addressForm->prepareRequest($data));
|
220 |
+
$addressErrors = $addressForm->validateData($addressData);
|
221 |
+
if (true !== $addressErrors) {
|
222 |
+
Mage::log("Minkasu - address validation failed");
|
223 |
+
}
|
224 |
+
$addressForm->compactData($addressData);
|
225 |
+
//unset billing address attributes which were not shown in form
|
226 |
+
foreach ($addressForm->getAttributes() as $attribute) {
|
227 |
+
if (!isset($data[$attribute->getAttributeCode()])) {
|
228 |
+
$address->setData($attribute->getAttributeCode(), NULL);
|
229 |
+
}
|
230 |
+
}
|
231 |
+
$address->setCustomerAddressId(null);
|
232 |
+
$address->setEmail($data['email']);
|
233 |
+
$address->implodeStreetAddress();
|
234 |
+
|
235 |
+
$billing = clone $address;
|
236 |
+
$billing->unsAddressId()->unsAddressType();
|
237 |
+
|
238 |
+
$shipping = $quote->getShippingAddress();
|
239 |
+
$shippingMethod = $shipping->getShippingMethod();
|
240 |
+
|
241 |
+
// Billing address properties that must be always copied to shipping address
|
242 |
+
$requiredBillingAttributes = array('customer_address_id');
|
243 |
+
|
244 |
+
// don't reset original shipping data, if it was not changed by customer
|
245 |
+
foreach ($shipping->getData() as $shippingKey => $shippingValue) {
|
246 |
+
if (!is_null($shippingValue) && !is_null($billing->getData($shippingKey))
|
247 |
+
&& !isset($data[$shippingKey]) && !in_array($shippingKey, $requiredBillingAttributes)
|
248 |
+
) {
|
249 |
+
$billing->unsetData($shippingKey);
|
250 |
+
}
|
251 |
+
}
|
252 |
+
|
253 |
+
$shipping->addData($billing->getData());
|
254 |
+
$shipping->setSameAsBilling(1);
|
255 |
+
$shipping->setSaveInAddressBook(0);
|
256 |
+
$shipping->setShippingMethod($shippingMethod);
|
257 |
+
$shipping->setCollectShippingRates(true);
|
258 |
+
|
259 |
+
/** @var $checkoutSession Mage_Checkout_Model_Session */
|
260 |
+
$checkoutSession = Mage::getSingleton('checkout/session');
|
261 |
+
$checkoutSession->setStepData('shipping', 'complete', true);
|
262 |
+
|
263 |
+
$quote->collectTotals();
|
264 |
+
$quote->save();
|
265 |
+
$quote->getShippingAddress()->setCollectShippingRates(true);
|
266 |
+
|
267 |
+
$checkoutSession->setStepData('billing', 'allow', true);
|
268 |
+
$checkoutSession->setStepData('billing', 'complete', true);
|
269 |
+
$checkoutSession->setStepData('shipping', 'allow', true);
|
270 |
+
|
271 |
+
return $this;
|
272 |
+
}
|
273 |
+
|
274 |
+
/**
|
275 |
+
* @param $quote
|
276 |
+
* @param array $data
|
277 |
+
*
|
278 |
+
* @return $this
|
279 |
+
*/
|
280 |
+
protected function _savePayment($quote, array $data)
|
281 |
+
{
|
282 |
+
try {
|
283 |
+
if($quote->isVirtual()) {
|
284 |
+
$quote->getBillingAddress()->setPaymentMethod(isset($data['method']) ? $data['method'] : null);
|
285 |
+
} else {
|
286 |
+
$quote->getShippingAddress()->setPaymentMethod(isset($data['method']) ? $data['method'] : null);
|
287 |
+
}
|
288 |
+
|
289 |
+
// shipping totals may be affected by payment method
|
290 |
+
if (!$quote->isVirtual() && $quote->getShippingAddress()) {
|
291 |
+
$quote->getShippingAddress()->setCollectShippingRates(true);
|
292 |
+
}
|
293 |
+
|
294 |
+
$data['checks'] = Mage_Payment_Model_Method_Abstract::CHECK_USE_CHECKOUT
|
295 |
+
| Mage_Payment_Model_Method_Abstract::CHECK_USE_FOR_COUNTRY
|
296 |
+
| Mage_Payment_Model_Method_Abstract::CHECK_USE_FOR_CURRENCY
|
297 |
+
| Mage_Payment_Model_Method_Abstract::CHECK_ORDER_TOTAL_MIN_MAX
|
298 |
+
| Mage_Payment_Model_Method_Abstract::CHECK_ZERO_TOTAL;
|
299 |
+
|
300 |
+
/** @var $checkoutSession Mage_Checkout_Model_Session */
|
301 |
+
$checkoutSession = Mage::getSingleton('checkout/session');
|
302 |
+
$payment = $quote->getPayment();
|
303 |
+
$payment->importData($data);
|
304 |
+
$payment->setTransactionId($checkoutSession->getData('minkasu_txn_id'));
|
305 |
+
$payment->setTransactionAdditionalInfo('quote-no', $quote->getQuoteId());
|
306 |
+
|
307 |
+
$quote->save();
|
308 |
+
$checkoutSession->setStepData('payment', 'complete', true);
|
309 |
+
} catch (Exception $e) {
|
310 |
+
Mage::logException($e);
|
311 |
+
}
|
312 |
+
return $this;
|
313 |
+
}
|
314 |
+
|
315 |
+
/**
|
316 |
+
* @param $quote
|
317 |
+
*
|
318 |
+
* @return Mage_Sales_Model_Order
|
319 |
+
*/
|
320 |
+
protected function _saveOrder($quote)
|
321 |
+
{
|
322 |
+
$quote->setCustomerId(null);
|
323 |
+
$quote->setCustomerEmail($quote->getBillingAddress()->getEmail());
|
324 |
+
$quote->setCustomerIsGuest(true);
|
325 |
+
$quote->setCustomerGroupId(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID);
|
326 |
+
|
327 |
+
/** @var $service Mage_Sales_Model_Service_Quote */
|
328 |
+
$service = Mage::getModel('sales/service_quote', $quote);
|
329 |
+
$service->submitAll();
|
330 |
+
|
331 |
+
/** @var $checkoutSession Mage_Checkout_Model_Session */
|
332 |
+
$checkoutSession = Mage::getSingleton('checkout/session');
|
333 |
+
$checkoutSession->setLastQuoteId($quote->getId());
|
334 |
+
$checkoutSession->setLastSuccessQuoteId($quote->getId());
|
335 |
+
$checkoutSession->clearHelperData();
|
336 |
+
|
337 |
+
$order = $service->getOrder();
|
338 |
+
|
339 |
+
if ($order->getId()) {
|
340 |
+
Mage::dispatchEvent('checkout_type_onepage_save_order_after', array('order'=>$order, 'quote'=>$quote));
|
341 |
+
|
342 |
+
/**
|
343 |
+
* we only want to send to customer about new order when there is no redirect to third party
|
344 |
+
*/
|
345 |
+
if ($order->getCanSendNewEmailFlag()) {
|
346 |
+
try {
|
347 |
+
$order->sendNewOrderEmail();
|
348 |
+
} catch (Exception $e) {
|
349 |
+
Mage::logException($e);
|
350 |
+
}
|
351 |
+
}
|
352 |
+
|
353 |
+
// add order information to the session
|
354 |
+
$checkoutSession->setLastOrderId($order->getId());
|
355 |
+
$checkoutSession->setRedirectUrl(null);
|
356 |
+
$checkoutSession->setLastRealOrderId($order->getIncrementId());
|
357 |
+
|
358 |
+
// as well a billing agreement can be created
|
359 |
+
$agreement = $order->getPayment()->getBillingAgreement();
|
360 |
+
if ($agreement) {
|
361 |
+
$checkoutSession->setLastBillingAgreementId($agreement->getId());
|
362 |
+
}
|
363 |
+
}
|
364 |
+
|
365 |
+
// add recurring profiles information to the session
|
366 |
+
$profiles = $service->getRecurringPaymentProfiles();
|
367 |
+
if ($profiles) {
|
368 |
+
$ids = array();
|
369 |
+
foreach ($profiles as $profile) {
|
370 |
+
$ids[] = $profile->getId();
|
371 |
+
}
|
372 |
+
$checkoutSession->setLastRecurringProfileIds($ids);
|
373 |
+
}
|
374 |
+
|
375 |
+
Mage::dispatchEvent(
|
376 |
+
'checkout_submit_all_after',
|
377 |
+
array('order' => $order, 'quote' => $quote, 'recurring_profiles' => $profiles)
|
378 |
+
);
|
379 |
+
|
380 |
+
$quote->save();
|
381 |
+
return $order;
|
382 |
+
}
|
383 |
+
|
384 |
+
/**
|
385 |
+
* @param string $minkasuTransactionId
|
386 |
+
* @param string $orderId
|
387 |
+
*
|
388 |
+
* @return array
|
389 |
+
*/
|
390 |
+
protected function _updateMinkasuTransactionWithOrderId($minkasuTransactionId, $orderId)
|
391 |
+
{
|
392 |
+
/** @var $client Minkasu_Wallet_Model_Api_Client */
|
393 |
+
$client = Mage::getModel('minkasu_wallet/api_client');
|
394 |
+
$result = $client->getType('transaction')->updateTransaction($minkasuTransactionId, array('merchant_bill_number' => $orderId), NULL);
|
395 |
+
|
396 |
+
return $result;
|
397 |
+
}
|
398 |
+
|
399 |
+
/**
|
400 |
+
* @return $this
|
401 |
+
*/
|
402 |
+
protected function _cleanCheckoutSessionParams()
|
403 |
+
{
|
404 |
+
/** @var $helper Minkasu_Wallet_Helper_Data */
|
405 |
+
$helper = Mage::helper('minkasu_wallet');
|
406 |
+
$helper->cleanCheckoutSessionParams();
|
407 |
+
return $this;
|
408 |
+
}
|
409 |
+
|
410 |
+
/**
|
411 |
+
* @param string $error
|
412 |
+
*
|
413 |
+
* @return string
|
414 |
+
*/
|
415 |
+
protected function _prepareErrorBody($error)
|
416 |
+
{
|
417 |
+
return $this->_prepareBody(array('error' => $this->__($error)));
|
418 |
+
}
|
419 |
+
|
420 |
+
/**
|
421 |
+
* @param array $data
|
422 |
+
*
|
423 |
+
* @return string
|
424 |
+
*/
|
425 |
+
protected function _prepareBody(array $data)
|
426 |
+
{
|
427 |
+
/** @var $helper Mage_Core_Helper_Data */
|
428 |
+
$helper = Mage::helper('core');
|
429 |
+
return $helper->jsonEncode($data);
|
430 |
+
}
|
431 |
+
}
|
432 |
+
?>
|
app/code/community/Minkasu/Wallet/controllers/PaymentController.php.old
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/TransactionController.php
CHANGED
@@ -18,6 +18,8 @@ class Minkasu_Wallet_TransactionController extends Mage_Core_Controller_Front_Ac
|
|
18 |
$expectedAddress = ($shippingAddress->exportCustomerAddress());
|
19 |
if ($expectedAddress != NULL) {
|
20 |
$data = $expectedAddress->getData();
|
|
|
|
|
21 |
$expectedAddressInfo = array (
|
22 |
'zip' => $data["postcode"],
|
23 |
'state' => $data["region"]
|
@@ -37,7 +39,8 @@ class Minkasu_Wallet_TransactionController extends Mage_Core_Controller_Front_Ac
|
|
37 |
$transactionInfo = $client->getType('transaction')->createTransaction($quote, $expectedAddressInfo);
|
38 |
|
39 |
$checkoutSession->setData('minkasu_amount', $quote->getGrandTotal());
|
40 |
-
|
|
|
41 |
$checkoutSession->setData('minkasu_txn_id', $transactionInfo['txn_id']);
|
42 |
$checkoutSession->setData('minkasu_payment_token',$transactionInfo['payment_token']);
|
43 |
$result = array(
|
@@ -76,6 +79,8 @@ class Minkasu_Wallet_TransactionController extends Mage_Core_Controller_Front_Ac
|
|
76 |
$expectedAddress = ($shippingAddress->exportCustomerAddress());
|
77 |
if ($expectedAddress != NULL) {
|
78 |
$data = $expectedAddress->getData();
|
|
|
|
|
79 |
$expectedAddressInfo = array (
|
80 |
'zip' => $data["postcode"],
|
81 |
'state' => $data["region"]
|
@@ -99,7 +104,8 @@ class Minkasu_Wallet_TransactionController extends Mage_Core_Controller_Front_Ac
|
|
99 |
->updateTransaction($minkasuTransactionId, $minkasuTransactionData, $expectedAddressInfo);
|
100 |
|
101 |
$checkoutSession->setData('minkasu_amount', $quote->getGrandTotal());
|
102 |
-
|
|
|
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.
|
18 |
$expectedAddress = ($shippingAddress->exportCustomerAddress());
|
19 |
if ($expectedAddress != NULL) {
|
20 |
$data = $expectedAddress->getData();
|
21 |
+
$checkoutSession->setData('minkasu_exp_zip', $data["postcode"]);
|
22 |
+
$checkoutSession->setData('minkasu_exp_state', $data["region"]);
|
23 |
$expectedAddressInfo = array (
|
24 |
'zip' => $data["postcode"],
|
25 |
'state' => $data["region"]
|
39 |
$transactionInfo = $client->getType('transaction')->createTransaction($quote, $expectedAddressInfo);
|
40 |
|
41 |
$checkoutSession->setData('minkasu_amount', $quote->getGrandTotal());
|
42 |
+
//TODO:AP:quoteId should be used as idempotency id down-the-road
|
43 |
+
//$checkoutSession->setData('minkasu_bill_number', $quote->getId());
|
44 |
$checkoutSession->setData('minkasu_txn_id', $transactionInfo['txn_id']);
|
45 |
$checkoutSession->setData('minkasu_payment_token',$transactionInfo['payment_token']);
|
46 |
$result = array(
|
79 |
$expectedAddress = ($shippingAddress->exportCustomerAddress());
|
80 |
if ($expectedAddress != NULL) {
|
81 |
$data = $expectedAddress->getData();
|
82 |
+
$checkoutSession->setData('minkasu_exp_zip', $data["postcode"]);
|
83 |
+
$checkoutSession->setData('minkasu_exp_state', $data["region"]);
|
84 |
$expectedAddressInfo = array (
|
85 |
'zip' => $data["postcode"],
|
86 |
'state' => $data["region"]
|
104 |
->updateTransaction($minkasuTransactionId, $minkasuTransactionData, $expectedAddressInfo);
|
105 |
|
106 |
$checkoutSession->setData('minkasu_amount', $quote->getGrandTotal());
|
107 |
+
//TODO:AP:quoteId should be used as idempotency id down-the-road
|
108 |
+
//$checkoutSession->setData('minkasu_bill_number', $quote->getId());
|
109 |
$checkoutSession->setData('minkasu_txn_id', $transactionInfo['txn_id']);
|
110 |
// Payment token will not be returned on an update transaction.
|
111 |
// Overwriting existing token with null causes later auth to fail.
|
app/code/community/Minkasu/Wallet/controllers/TransactionController.php~
CHANGED
@@ -12,6 +12,19 @@ class Minkasu_Wallet_TransactionController extends Mage_Core_Controller_Front_Ac
|
|
12 |
$quote = $cart->getQuote();
|
13 |
$checkoutSession = $cart->getCheckoutSession();
|
14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
try {
|
16 |
/** @var $session Mage_Core_Model_Session */
|
17 |
$session = Mage::getSingleton('core/session');
|
@@ -21,10 +34,11 @@ class Minkasu_Wallet_TransactionController extends Mage_Core_Controller_Front_Ac
|
|
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 |
-
|
|
|
28 |
$checkoutSession->setData('minkasu_txn_id', $transactionInfo['txn_id']);
|
29 |
$checkoutSession->setData('minkasu_payment_token',$transactionInfo['payment_token']);
|
30 |
$result = array(
|
@@ -57,6 +71,19 @@ class Minkasu_Wallet_TransactionController extends Mage_Core_Controller_Front_Ac
|
|
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');
|
@@ -70,12 +97,14 @@ class Minkasu_Wallet_TransactionController extends Mage_Core_Controller_Front_Ac
|
|
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 |
-
|
|
|
|
|
79 |
$result = array(
|
80 |
'txn_id' => $transactionInfo['txn_id'],
|
81 |
'payment_code' => $transactionInfo['payment_code'],
|
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');
|
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 |
+
//TODO:AP:quoteId should be used as idempotency id down-the-road
|
41 |
+
//$checkoutSession->setData('minkasu_bill_number', $quote->getId());
|
42 |
$checkoutSession->setData('minkasu_txn_id', $transactionInfo['txn_id']);
|
43 |
$checkoutSession->setData('minkasu_payment_token',$transactionInfo['payment_token']);
|
44 |
$result = array(
|
71 |
$minkasuTransactionData = array('amount' => $walletHelper->convertDollarsToCents($quote->getGrandTotal()));
|
72 |
$minkasuTransactionId = $checkoutSession->getData('minkasu_txn_id');
|
73 |
|
74 |
+
$expectedAddressInfo = NULL;
|
75 |
+
$shippingAddress = $quote->getShippingAddress();
|
76 |
+
if ($shippingAddress != NULL){
|
77 |
+
$expectedAddress = ($shippingAddress->exportCustomerAddress());
|
78 |
+
if ($expectedAddress != NULL) {
|
79 |
+
$data = $expectedAddress->getData();
|
80 |
+
$expectedAddressInfo = array (
|
81 |
+
'zip' => $data["postcode"],
|
82 |
+
'state' => $data["region"]
|
83 |
+
);
|
84 |
+
}
|
85 |
+
}
|
86 |
+
|
87 |
try {
|
88 |
/** @var $session Mage_Core_Model_Session */
|
89 |
$session = Mage::getSingleton('core/session');
|
97 |
/** @var $client Minkasu_Wallet_Model_Api_Client */
|
98 |
$client = Mage::getModel('minkasu_wallet/api_client');
|
99 |
$transactionInfo = $client->getType('transaction')
|
100 |
+
->updateTransaction($minkasuTransactionId, $minkasuTransactionData, $expectedAddressInfo);
|
101 |
|
102 |
$checkoutSession->setData('minkasu_amount', $quote->getGrandTotal());
|
103 |
$checkoutSession->setData('minkasu_bill_number', $quote->getId());
|
104 |
$checkoutSession->setData('minkasu_txn_id', $transactionInfo['txn_id']);
|
105 |
+
// Payment token will not be returned on an update transaction.
|
106 |
+
// Overwriting existing token with null causes later auth to fail.
|
107 |
+
//$checkoutSession->setData('minkasu_payment_token',$transactionInfo['payment_token']);
|
108 |
$result = array(
|
109 |
'txn_id' => $transactionInfo['txn_id'],
|
110 |
'payment_code' => $transactionInfo['payment_code'],
|
app/code/community/Minkasu/Wallet/etc/config.xml
CHANGED
@@ -94,6 +94,7 @@
|
|
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>
|
@@ -102,6 +103,7 @@
|
|
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>
|
94 |
<default>
|
95 |
<payment>
|
96 |
<minkasu_wallet>
|
97 |
+
<mode>0</mode>
|
98 |
<account_id backend_model="adminhtml/system_config_backend_encrypted"/>
|
99 |
<active>0</active>
|
100 |
<gateway_url>https://transactions.minkasu.com</gateway_url>
|
103 |
<title>Minkasu Smartphone Checkout</title>
|
104 |
<payment_action>authorize</payment_action>
|
105 |
<token backend_model="adminhtml/system_config_backend_encrypted"/>
|
106 |
+
<estimate_enabled>1</estimate_enabled>
|
107 |
</minkasu_wallet>
|
108 |
</payment>
|
109 |
</default>
|
app/code/community/Minkasu/Wallet/etc/system.xml
CHANGED
@@ -12,62 +12,101 @@
|
|
12 |
<show_in_website>1</show_in_website>
|
13 |
<show_in_store>1</show_in_store>
|
14 |
<fields>
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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>
|
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 |
-
|
26 |
-
|
27 |
-
<
|
28 |
-
<
|
|
|
|
|
|
|
29 |
<show_in_default>1</show_in_default>
|
30 |
<show_in_website>1</show_in_website>
|
31 |
-
<show_in_store>
|
32 |
-
</
|
|
|
33 |
<gateway_url>
|
34 |
<label>Gateway URL</label>
|
35 |
<frontend_type>text</frontend_type>
|
36 |
-
<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
|
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>
|
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
|
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>
|
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
|
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>
|
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>
|
12 |
<show_in_website>1</show_in_website>
|
13 |
<show_in_store>1</show_in_store>
|
14 |
<fields>
|
15 |
+
<mode>
|
16 |
+
<label>Test Mode</label>
|
17 |
+
<frontend_type>select</frontend_type>
|
18 |
+
<frontend_model>minkasu_wallet/adminhtml_system_config_frontend_minkasuMode</frontend_model>
|
19 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
20 |
+
<comment><![CDATA[Run against Minkasu LIVE/SandBox Environment.]]></comment>
|
21 |
+
<sort_order>10</sort_order>
|
22 |
+
<show_in_default>1</show_in_default>
|
23 |
+
<show_in_website>1</show_in_website>
|
24 |
+
<show_in_store>0</show_in_store>
|
25 |
+
</mode>
|
26 |
+
<!--mode>
|
27 |
+
<label>Mode</label>
|
28 |
+
<frontend_type>select</frontend_type>
|
29 |
+
<source_model>minkasu_wallet/source_api_mode</source_model>
|
30 |
+
<sort_order>10</sort_order>
|
31 |
+
<show_in_default>1</show_in_default>
|
32 |
+
<show_in_website>1</show_in_website>
|
33 |
+
<show_in_store>0</show_in_store>
|
34 |
+
</mode-->
|
35 |
+
<separator>
|
36 |
+
<frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
|
37 |
+
<sort_order>20</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 |
+
</separator>
|
42 |
+
<active>
|
43 |
<label>Enabled</label>
|
44 |
<frontend_type>select</frontend_type>
|
45 |
<source_model>adminhtml/system_config_source_yesno</source_model>
|
46 |
<backend_model>minkasu_wallet/system_config_backend_minkasuStatus</backend_model>
|
47 |
+
<sort_order>30</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 |
</active>
|
52 |
+
<!--
|
53 |
+
<active>
|
54 |
+
<label>Enabled</label>
|
55 |
+
<frontend_type>select</frontend_type>
|
56 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
57 |
+
<backend_model>minkasu_wallet/system_config_backend_minkasuStatus</backend_model>
|
58 |
+
<sort_order>40</sort_order>
|
59 |
<show_in_default>1</show_in_default>
|
60 |
<show_in_website>1</show_in_website>
|
61 |
+
<show_in_store>0</show_in_store>
|
62 |
+
</active>
|
63 |
+
-->
|
64 |
<gateway_url>
|
65 |
<label>Gateway URL</label>
|
66 |
<frontend_type>text</frontend_type>
|
67 |
+
<sort_order>50</sort_order>
|
|
|
68 |
<show_in_default>1</show_in_default>
|
69 |
<show_in_website>1</show_in_website>
|
70 |
<show_in_store>0</show_in_store>
|
71 |
</gateway_url>
|
72 |
+
<account_id>
|
73 |
<label>Account Id</label>
|
74 |
<comment><![CDATA[This data is stored encrypted in the database.]]></comment>
|
75 |
<frontend_type>text</frontend_type>
|
76 |
<backend_model>adminhtml/system_config_backend_encrypted</backend_model>
|
77 |
+
<sort_order>60</sort_order>
|
78 |
<show_in_default>1</show_in_default>
|
79 |
<show_in_website>1</show_in_website>
|
80 |
<show_in_store>0</show_in_store>
|
81 |
</account_id>
|
82 |
+
<token>
|
83 |
<label>Token</label>
|
84 |
<comment><![CDATA[This data is stored encrypted in the database.]]></comment>
|
85 |
<frontend_type>text</frontend_type>
|
86 |
<backend_model>adminhtml/system_config_backend_encrypted</backend_model>
|
87 |
+
<sort_order>70</sort_order>
|
88 |
<show_in_default>1</show_in_default>
|
89 |
<show_in_website>1</show_in_website>
|
90 |
<show_in_store>0</show_in_store>
|
91 |
</token>
|
92 |
+
<order_status>
|
93 |
<label>New Order Status</label>
|
94 |
<frontend_type>select</frontend_type>
|
95 |
<source_model>adminhtml/system_config_source_order_status</source_model>
|
96 |
+
<sort_order>80</sort_order>
|
97 |
<show_in_default>1</show_in_default>
|
98 |
<show_in_website>1</show_in_website>
|
99 |
<show_in_store>0</show_in_store>
|
100 |
</order_status>
|
101 |
+
<estimate_enabled translate="label">
|
102 |
+
<label>Enable Shipping and Tax Estimation</label>
|
103 |
+
<frontend_type>select</frontend_type>
|
104 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
105 |
+
<sort_order>90</sort_order>
|
106 |
+
<show_in_default>1</show_in_default>
|
107 |
+
<show_in_website>1</show_in_website>
|
108 |
+
<show_in_store>0</show_in_store>
|
109 |
+
</estimate_enabled>
|
110 |
</fields>
|
111 |
</minkasu_wallet>
|
112 |
</groups>
|
app/design/frontend/base/default/layout/minkasu_wallet.xml
CHANGED
@@ -6,6 +6,11 @@
|
|
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>
|
6 |
<action method="setTemplate" ifconfig="payment/minkasu_wallet/active">
|
7 |
<template>minkasu/wallet/pay.phtml</template>
|
8 |
</action>
|
9 |
+
<block type="minkasu_wallet/pay" name="checkout.cart.methods.minkasu_wallet.estimate_box">
|
10 |
+
<action method="setTemplate" ifconfig="payment/minkasu_wallet/active">
|
11 |
+
<template>minkasu/wallet/estimate_box.phtml</template>
|
12 |
+
</action>
|
13 |
+
</block>
|
14 |
</block>
|
15 |
</reference>
|
16 |
</checkout_cart_index>
|
app/design/frontend/base/default/template/minkasu/wallet/estimate_box.phtml
ADDED
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/** @var $_apiHelper Minkasu_Wallet_Helper_Api */
|
4 |
+
$_apiHelper = Mage::helper('minkasu_wallet/api');
|
5 |
+
$_apiEstimateEnabled = $_apiHelper->isApiEstimateEnabled();
|
6 |
+
|
7 |
+
$show_minkasu_estimate_box = $_apiEstimateEnabled;
|
8 |
+
|
9 |
+
?>
|
10 |
+
|
11 |
+
|
12 |
+
<?php if ($show_minkasu_estimate_box) : ?>
|
13 |
+
|
14 |
+
<div id="mk_shipping_est_div" style="display: block; overflow: auto">
|
15 |
+
<table style="border: 0px; margin:0px"><tr><td style="border: 0px; padding: 0px; width:100%"></td>
|
16 |
+
<td style="border: 0px; padding: 0px; padding-bottom: 30px; padding-top: 20px;">
|
17 |
+
|
18 |
+
<table id="mk_shipping_est_table" style="background-color: #E7F6F0; border: 1px solid #19D383; border-collapse: separate; border-spacing: 0px; border-radius: 3px; margin: 0px; padding-bottom: 10px; padding-left: 15px; padding-right: 15px; padding-top: 15px; width: 330px">
|
19 |
+
|
20 |
+
<tr>
|
21 |
+
<td style="border: 0px; padding-bottom: 5px; padding-left: 0px; padding-right: 5px; padding-top:0px; text-align: right; vertical-align: middle">
|
22 |
+
<span style="color: #333333; font-family: Open Sans; font-size: 12px;">Shipping & Taxes</span>
|
23 |
+
</td>
|
24 |
+
<td style="border: 0px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top:0px; vertical-align: middle">
|
25 |
+
<input type="text" id="ship_zip" style="background-color: white; border-color: #999999; box-sizing: content-box; color: #999999; font-family: Open Sans; font-size: 13px; font-style: italic; height: 16px; margin: 0px; padding: 4px; width: 85px" value="Zip code"/>
|
26 |
+
</td>
|
27 |
+
<td style="border: 0px; padding-bottom: 5px; padding-left: 5px; padding-right: 0px; padding-top:0px; vertical-align: middle">
|
28 |
+
<input type="button" id="mk_cart_est_btn" value="Estimate" style="background-color: #F2F2F2; border-color: #999999; border-radius: 2px; border-width: 1px; color: #333333; font-family: Open Sans; font-size: 12px; font-weight: 600; height: 24px; margin: 0px; padding: 4px; width: 80px">
|
29 |
+
</td>
|
30 |
+
</tr>
|
31 |
+
|
32 |
+
<tr id="discount_code_row" style="display:none">
|
33 |
+
<td style="border: 0px; padding-bottom: 5px; padding-left: 0px; padding-right: 5px; padding-top:5px; text-align: right; vertical-align: middle">
|
34 |
+
<span id="discount_txt" style="color: #333333; font-family: Open Sans; font-size: 12px;">Apply discount</span>
|
35 |
+
</td>
|
36 |
+
<td style="border: 0px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top:5px; vertical-align: middle">
|
37 |
+
<input type="text" id="discount_code" style="background-color: white; border-color: #999999; box-sizing: content-box; color: #999999; font-family: Open Sans; font-size: 13px; font-style: italic; height: 16px; margin: 0px; padding: 4px; width: 85px" value="Coupon"/>
|
38 |
+
</td>
|
39 |
+
<td style="border: 0px; padding-bottom: 5px; padding-left: 5px; padding-right: 0px; padding-top:5px; vertical-align: middle">
|
40 |
+
<input type="button" id="mk_cart_apply_btn" value="Apply" style="background-color: #F2F2F2; border-color: #999999; border-radius: 2px; border-width: 1px; color: #333333; font-family: Open Sans; font-size: 12px; font-weight: 600; height: 24px; margin: 0px; padding: 4px; width: 80px">
|
41 |
+
</td>
|
42 |
+
</tr>
|
43 |
+
|
44 |
+
<tr id="inprogress_indicator" style="display:none">
|
45 |
+
<td colspan="3" style="border: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top:10px; text-align:center">
|
46 |
+
<img src="https://transactions.minkasu.com/images/spinning_wheel.gif">
|
47 |
+
</td>
|
48 |
+
</tr>
|
49 |
+
|
50 |
+
<tr id="shipping_options_row" style="display:none">
|
51 |
+
<td style="border: 0px; padding-bottom: 5px; padding-left: 0px; padding-right: 5px; padding-top:5px; text-align: right;">
|
52 |
+
<span style="color: #333333; font-family: Open Sans; font-size: 12px;">Shipping</span>
|
53 |
+
</td>
|
54 |
+
<td id="shipping_options_cell" colspan="2" style="border: 0px; padding-bottom: 5px; padding-left: 5px; padding-right: 0px; padding-top:5px">
|
55 |
+
</td>
|
56 |
+
</tr>
|
57 |
+
|
58 |
+
<tr><td colspan="3" style="border: 0px; padding-bottom: 5px; padding-left: 0px; padding-right: 0px; padding-top:5px;"></td></tr>
|
59 |
+
|
60 |
+
<tr>
|
61 |
+
<td id="mk_checkout_td" colspan="3" style="border: 0px; border-top: 1px solid #DDDDDD; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top:10px;">
|
62 |
+
<div id="minkasu_payment_div"> </div>
|
63 |
+
<div class="buttons" style="height: 45px;">
|
64 |
+
<div class="right">
|
65 |
+
<input type="button" value="Checkout with Smart Phone (Minkasu)" id="button-mk-chkout" class="button" />
|
66 |
+
</div>
|
67 |
+
</div>
|
68 |
+
</td>
|
69 |
+
</tr>
|
70 |
+
|
71 |
+
</table>
|
72 |
+
|
73 |
+
</td></tr>
|
74 |
+
</table>
|
75 |
+
|
76 |
+
</div>
|
77 |
+
|
78 |
+
<?php else: ?>
|
79 |
+
|
80 |
+
<div class="row">
|
81 |
+
<div class="col-sm-12" style="text-align:right" id="minkasu_payment_div"></div>
|
82 |
+
</div>
|
83 |
+
|
84 |
+
<div class="buttons" style="height: 45px;">
|
85 |
+
<div class="right">
|
86 |
+
<input type="button" value="Checkout with Smart Phone (Minkasu)" id="button-mk-chkout" class="button" />
|
87 |
+
</div>
|
88 |
+
</div>
|
89 |
+
|
90 |
+
<?php endif; ?>
|
app/design/frontend/base/default/template/minkasu/wallet/pay.phtml
CHANGED
@@ -7,33 +7,86 @@ $chko_session = Mage::getSingleton('checkout/session');
|
|
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 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
-
|
33 |
-
|
34 |
-
|
35 |
-
</div>
|
36 |
-
</div>
|
37 |
|
38 |
<script type="text/javascript">
|
39 |
|
@@ -49,7 +102,6 @@ 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>
|
@@ -73,24 +125,259 @@ if (resolve_jquery_conflict) {
|
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
$.ajax({
|
95 |
url: '<?php echo $this->getUrl('minkasu_wallet/transaction/update') ?>',
|
96 |
type: 'post',
|
@@ -111,8 +398,8 @@ var minkasu_get_txnid_fn = function(mk_data) {
|
|
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',
|
@@ -138,13 +425,87 @@ var minkasu_get_txnid_fn = function(mk_data) {
|
|
138 |
|
139 |
|
140 |
$(document).ready(function() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
141 |
var minkasu_txn_id_good_for_use = false;
|
142 |
-
<?php if ($minkasu_txn_id
|
143 |
<?php if ($minkasu_amount == $quote->getGrandTotal()): ?>
|
144 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
<?php endif; ?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
146 |
<?php endif; ?>
|
147 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
148 |
$.getScript('<?php echo $_apiGatewayUrl ?>/scripts/minkasu-1.2.js', function() {
|
149 |
|
150 |
var payment_args = {
|
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 |
+
$minkasu_exp_zip = $chko_session->getData('minkasu_exp_zip');
|
11 |
+
$minkasu_exp_state = $chko_session->getData('minkasu_exp_state');
|
12 |
|
13 |
$shipping_method = $chko_session->getData('minkasu_shipping_method');
|
14 |
$shipping_estimated = $chko_session->getData('minkasu_shipping_estimated');
|
15 |
+
|
16 |
$quote = $chko_session->getQuote();
|
17 |
|
18 |
$shipping_estimate_not_needed = ($quote->isVirtual() || $shipping_estimated);
|
19 |
|
20 |
+
$address = $quote->getShippingAddress();
|
21 |
+
|
22 |
+
if ($address != NULL) {
|
23 |
+
$estimatedAddress = $address->exportCustomerAddress();
|
24 |
+
if ($estimatedAddress != NULL) {
|
25 |
+
$data = $estimatedAddress->getData();
|
26 |
+
$estimate_postcode = $data["postcode"];
|
27 |
+
}
|
28 |
+
}
|
29 |
+
|
30 |
+
$rates = $address->collectShippingRates()->getGroupedAllShippingRates();
|
31 |
+
|
32 |
+
$shipping_options = array();
|
33 |
+
|
34 |
+
foreach ($rates as $carrier) {
|
35 |
+
foreach ($carrier as $rate) {
|
36 |
+
array_push($shipping_options, $rate->getData());
|
37 |
+
}
|
38 |
+
}
|
39 |
+
|
40 |
+
if ($shipping_estimated){
|
41 |
+
$current_shipping_option_code = $address->getShippingMethod();
|
42 |
+
}
|
43 |
|
|
|
44 |
|
|
|
45 |
/** @var $_apiHelper Minkasu_Wallet_Helper_Api */
|
46 |
$_apiHelper = Mage::helper('minkasu_wallet/api');
|
47 |
$_apiGatewayUrl = $_apiHelper->getApiGatewayUrl();
|
48 |
+
$_apiEstimateEnabled = $_apiHelper->isApiEstimateEnabled();
|
49 |
+
|
50 |
+
$show_minkasu_estimate_box = $_apiEstimateEnabled;
|
51 |
+
|
52 |
+
$regionCollection = Mage::getModel('directory/region_api')->items("US");
|
53 |
+
|
54 |
+
$coupon_code = $quote->getCouponCode();
|
55 |
+
|
56 |
?>
|
57 |
+
|
58 |
+
<script>
|
59 |
+
|
60 |
+
var shipping_option_rates = [];
|
61 |
+
|
62 |
+
<?php foreach ($shipping_options as $shipping_option) { ?>
|
63 |
+
|
64 |
+
shipping_option_rates.push({
|
65 |
+
title: '<?php echo $shipping_option['method_title'] ?>',
|
66 |
+
code: '<?php echo $shipping_option['code'] ?>',
|
67 |
+
price: parseFloat('<?php echo $shipping_option['price'] ?>')
|
68 |
+
});
|
69 |
+
|
70 |
+
<?php } ?>
|
71 |
+
var current_shipping_option_code = "";
|
72 |
+
<?php if ($shipping_estimated) { ?>
|
73 |
+
current_shipping_option_code = '<?php echo $current_shipping_option_code; ?>';
|
74 |
+
<?php } ?>
|
75 |
+
|
76 |
+
region_ids = {};
|
77 |
+
<?php foreach($regionCollection as $region) { ?>
|
78 |
+
|
79 |
+
region_ids['<?php echo $region['code'];?>'] = <?php echo $region['region_id']; ?>;
|
80 |
+
|
81 |
+
<?php } ?>
|
82 |
+
|
83 |
+
</script>
|
84 |
+
|
85 |
<link href="<?php echo $_apiGatewayUrl ?>/scripts/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
|
|
|
|
|
86 |
|
87 |
+
|
88 |
+
<?php echo $this->getChildHtml('checkout.cart.methods.minkasu_wallet.estimate_box') ?>
|
89 |
+
|
|
|
|
|
90 |
|
91 |
<script type="text/javascript">
|
92 |
|
102 |
resolve_dollar_sym = true;
|
103 |
}
|
104 |
|
|
|
105 |
</script>
|
106 |
|
107 |
<script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
|
125 |
|
126 |
(function($) {
|
127 |
|
128 |
+
var _getStateAndCityFromZip = function(zip, cb_fn) {
|
129 |
+
|
130 |
+
var params = {
|
131 |
+
type: 'GET',
|
132 |
+
url: window.location.protocol + '//maps.googleapis.com/maps/api/geocode/json?address=' + zip,
|
133 |
+
success: function(response, textStatus, xhr) {
|
134 |
+
if (response.status != "OK") {
|
135 |
+
cb_fn(response.status, null);
|
136 |
+
}
|
137 |
+
var formatted_address = response.results[0].formatted_address;
|
138 |
+
//window.alert(formatted_address);
|
139 |
+
//formatted address = City, ST zip, USA
|
140 |
+
var fa_parts = formatted_address.split(",");
|
141 |
+
var city_str = fa_parts[0];
|
142 |
+
var state_short = (fa_parts[1].trim().split(" "))[0];
|
143 |
+
address_info = {city: city_str, state_code: state_short, country: "United States", zip: zip};
|
144 |
+
cb_fn(null, address_info);
|
145 |
+
},
|
146 |
+
error: function(XMLHttpRequest, textStatus) {
|
147 |
+
cb_fn(textStatus, null);
|
148 |
+
}
|
149 |
+
};
|
150 |
+
jQuery.ajax(params);
|
151 |
+
|
152 |
+
}
|
153 |
+
|
154 |
+
var updateCartPriceEstimateWithShippingOption = function(shipping_code) {
|
155 |
+
|
156 |
+
var req_data = { };
|
157 |
+
req_data["estimate_method"] = shipping_code;
|
158 |
+
req_data["do"] = "Update Total";
|
159 |
+
|
160 |
+
$("#mk_shipping_est_table").find("#inprogress_indicator").show();
|
161 |
+
|
162 |
+
$.ajax({
|
163 |
+
url: '<?php echo $this->getUrl("checkout/cart/estimateUpdatePost/") ?>',
|
164 |
+
type:'get',
|
165 |
+
data: $.param(req_data),
|
166 |
+
success: function(resp) {
|
167 |
+
//window.alert("Done");
|
168 |
+
$("#mk_shipping_est_table").find("#inprogress_indicator").hide();
|
169 |
+
location.reload();
|
170 |
+
},
|
171 |
+
error: function(jqXHR, textStatus, errorThrown) {
|
172 |
+
errorMsg = "Error getting cart estimates from server: " + textStatus + "; \n" + errorThrown + "\n" + JSON.stringify(jqXHR);
|
173 |
+
window.alert(errorMsg);
|
174 |
+
$("#mk_shipping_est_table").find("#inprogress_indicator").hide();
|
175 |
+
return;
|
176 |
+
}
|
177 |
+
});
|
178 |
+
|
179 |
+
};
|
180 |
+
|
181 |
+
var showShippingOptions = function() {
|
182 |
+
|
183 |
+
var so_el = $("#mk_shipping_est_table").find("#shipping_options_cell");
|
184 |
+
so_el.empty();
|
185 |
+
var shipping_option_elems = "";
|
186 |
+
for (i = 0; i < shipping_option_rates.length; i++) {
|
187 |
+
next_shipping = shipping_option_rates[i];
|
188 |
+
var checked_str = "";
|
189 |
+
if (next_shipping["code"] == current_shipping_option_code) {
|
190 |
+
// checked_str = "checked";
|
191 |
+
checked_str = "selected";
|
192 |
+
}
|
193 |
+
shipping_option_elems += "<option value=\"" + i + "\" " + checked_str + ">" + shipping_option_rates[i].title + "</option>";
|
194 |
+
}
|
195 |
+
|
196 |
+
so_el.append("<select name=\"mk_shipping_option\" " +
|
197 |
+
"style=\"background-color: white; border-color: #999999; box-sizing: content-box; color: #333333; " +
|
198 |
+
"font-family: Open Sans; font-size: 13px; height: auto; margin: 0px; padding: 4px; width: 100%\">" + shipping_option_elems + "</select>");
|
199 |
+
so_el.find('[name="mk_shipping_option"]').change(function() {
|
200 |
+
var current_shipping_option = $(this).val();
|
201 |
+
updateCartPriceEstimateWithShippingOption(shipping_option_rates[current_shipping_option].code);
|
202 |
+
});
|
203 |
+
$("#mk_shipping_est_table").find("#shipping_options_row").show();
|
204 |
+
$("#mk_shipping_est_table").find("#discount_code_row").show();
|
205 |
+
}
|
206 |
+
|
207 |
+
var getShippingRates = function(cb_fn) {
|
208 |
+
|
209 |
+
$.ajax({
|
210 |
+
url: '<?php echo $this->getUrl("minkasu_wallet/payment/getShippingRates") ?>',
|
211 |
+
type:'get',
|
212 |
+
success: function(resp) {
|
213 |
+
|
214 |
+
shipping_option_rates = [];
|
215 |
+
var current_shipping_option_valid = false;
|
216 |
+
for (var i = 0; i < resp.length; i++) {
|
217 |
+
shipping_option_rates.push({
|
218 |
+
title: resp[i].method_title,
|
219 |
+
code: resp[i].code,
|
220 |
+
price: parseFloat(resp[i].price)
|
221 |
+
});
|
222 |
+
if (current_shipping_option_code == resp[i].code) {
|
223 |
+
current_shipping_option_valid = true;
|
224 |
+
}
|
225 |
+
}
|
226 |
+
if (!current_shipping_option_valid) {
|
227 |
+
current_shipping_option_code = shipping_option_rates[0].code;
|
228 |
+
}
|
229 |
+
cb_fn({status: "success"});
|
230 |
+
},
|
231 |
+
error: function(jqXHR, textStatus, errorThrown) {
|
232 |
+
errorMsg = "Error getting shipping options: " + textStatus + "; \n" + errorThrown + "\n" + JSON.stringify(jqXHR);
|
233 |
+
window.alert(errorMsg);
|
234 |
+
cb_fn({status: "error"});
|
235 |
+
}
|
236 |
+
});
|
237 |
+
|
238 |
+
};
|
239 |
+
|
240 |
+
|
241 |
+
var updateCartPriceEstimateWithZip = function(zip) {
|
242 |
+
|
243 |
+
jQuery.cors = true;
|
244 |
+
var req_data = { };
|
245 |
+
|
246 |
+
_getStateAndCityFromZip(zip, function(error, address_info) {
|
247 |
+
|
248 |
+
if (error) {
|
249 |
+
errorMsg = "Error looking up zip code: " + error;
|
250 |
+
window.alert(errorMsg);
|
251 |
+
return;
|
252 |
+
}
|
253 |
+
|
254 |
+
req_data["country_id"] = "US";
|
255 |
+
req_data["region_id"] = region_ids[address_info.state_code];
|
256 |
+
req_data["estimate_postcode"] = zip;
|
257 |
+
|
258 |
+
$("#mk_shipping_est_table").find("#inprogress_indicator").show();
|
259 |
+
|
260 |
+
$.ajax({
|
261 |
+
url: '<?php echo $this->getUrl("checkout/cart/estimatePost/") ?>',
|
262 |
+
type:'post',
|
263 |
+
data: $.param(req_data),
|
264 |
+
success: function(resp) {
|
265 |
+
getShippingRates(function(result) {
|
266 |
+
if (result.status != "success") {
|
267 |
+
$("#mk_shipping_est_table").find("#inprogress_indicator").hide();
|
268 |
+
return;
|
269 |
+
}
|
270 |
+
updateCartPriceEstimateWithShippingOption(current_shipping_option_code);
|
271 |
+
});
|
272 |
+
},
|
273 |
+
error: function(jqXHR, textStatus, errorThrown) {
|
274 |
+
errorMsg = "Error getting cart estimates from server: " + textStatus + "; \n" + errorThrown + "\n" + JSON.stringify(jqXHR);
|
275 |
+
window.alert(errorMsg);
|
276 |
+
$("#mk_shipping_est_table").find("#inprogress_indicator").hide();
|
277 |
+
return;
|
278 |
+
}
|
279 |
+
});
|
280 |
+
});
|
281 |
+
};
|
282 |
+
|
283 |
+
var updateCartPriceEstimateWithDiscount = function(discount_code) {
|
284 |
+
|
285 |
+
jQuery.cors = true;
|
286 |
+
var req_data = { };
|
287 |
+
|
288 |
+
if (!discount_code || discount_code.length == 0) {
|
289 |
+
req_data["remove"] = "1";
|
290 |
+
} else {
|
291 |
+
req_data["coupon_code"] = discount_code;
|
292 |
+
}
|
293 |
+
|
294 |
+
$("#mk_shipping_est_table").find("#inprogress_indicator").show();
|
295 |
+
|
296 |
+
$.ajax({
|
297 |
+
url: '<?php echo $this->getUrl("checkout/cart/couponPost/") ?>',
|
298 |
+
type:'post',
|
299 |
+
data: $.param(req_data),
|
300 |
+
success: function(resp) {
|
301 |
+
window.location.reload();
|
302 |
+
},
|
303 |
+
error: function(jqXHR, textStatus, errorThrown) {
|
304 |
+
errorMsg = "Error apply discount code: " + textStatus + "; \n" + errorThrown + "\n" + JSON.stringify(jqXHR);
|
305 |
+
window.alert(errorMsg);
|
306 |
+
$("#mk_shipping_est_table").find("#inprogress_indicator").hide();
|
307 |
+
return;
|
308 |
+
}
|
309 |
+
});
|
310 |
+
};
|
311 |
+
|
312 |
+
var get_shipping_zip_code = function() {
|
313 |
+
var ship_zip_elem = $("#mk_shipping_est_table").find("#ship_zip");
|
314 |
+
var ship_zip_val = (ship_zip_elem.val() == "Zip code")? "" : ship_zip_elem.val();
|
315 |
+
return ship_zip_val;
|
316 |
+
}
|
317 |
+
|
318 |
+
var resetShippingZipCode = function() {
|
319 |
+
var shipZipElem = $("#mk_shipping_est_table").find("#ship_zip");
|
320 |
+
shipZipElem.val("Zip code");
|
321 |
+
shipZipElem.css("font-style", "italic");
|
322 |
+
shipZipElem.css("color", "#999999");
|
323 |
+
}
|
324 |
+
|
325 |
+
var get_discount_code = function() {
|
326 |
+
var discount_code_elem = $("#mk_shipping_est_table").find("#discount_code");
|
327 |
+
var discount_code_val = discount_code_elem.val();
|
328 |
+
return discount_code_val;
|
329 |
+
}
|
330 |
+
|
331 |
+
var resetDiscountCode = function() {
|
332 |
+
var shipZipElem = $("#mk_shipping_est_table").find("#discount_code");
|
333 |
+
shipZipElem.val("Coupon");
|
334 |
+
shipZipElem.css("font-style", "italic");
|
335 |
+
shipZipElem.css("color", "#999999");
|
336 |
+
}
|
337 |
+
|
338 |
+
var hide_default_estimate_block = false;
|
339 |
+
|
340 |
var minkasu_session_ready_for_chkout = function() {
|
341 |
|
342 |
<?php if ($shipping_estimate_not_needed): ?>
|
343 |
return true;
|
344 |
<?php else: ?>
|
345 |
+
if (hide_default_estimate_block && $(".shipping").is(":hidden")) {
|
346 |
+
$(".shipping").show("slow", function() {
|
347 |
+
alert("Please estimate shipping and taxes and retry.");
|
348 |
+
});
|
349 |
+
} else {
|
350 |
+
alert("Please estimate shipping and taxes and retry.");
|
351 |
+
}
|
352 |
return false;
|
353 |
<?php endif; ?>
|
354 |
|
355 |
};
|
356 |
|
357 |
+
|
358 |
+
|
359 |
var minkasu_get_txnid_fn = function(mk_data) {
|
360 |
|
361 |
<?php if ($minkasu_txn_id && $minkasu_bill_number == $quote->getId()): ?>
|
362 |
+
<?php if ($minkasu_amount == $quote->getGrandTotal()): ?>
|
363 |
+
<?php
|
364 |
+
$data = NULL;
|
365 |
+
$shippingAddress = $quote->getShippingAddress();
|
366 |
+
if ($shippingAddress != NULL) {
|
367 |
+
$expectedAddress = ($shippingAddress->exportCustomerAddress());
|
368 |
+
if ($expectedAddress != NULL) {
|
369 |
+
$data = $expectedAddress->getData();
|
370 |
+
}
|
371 |
+
}
|
372 |
+
if (($data != NULL) &&
|
373 |
+
($minkasu_exp_zip && ($minkasu_exp_zip == $data["postcode"])) &&
|
374 |
+
($minkasu_exp_state && ($minkasu_exp_state == $data["region"]))): ?>
|
375 |
+
console.log("Transaction id requested when already present.");
|
376 |
+
mk_data.error("Transaction id requested when already present.");
|
377 |
+
return;
|
378 |
+
<?php endif; ?>
|
379 |
+
<?php endif; ?>
|
380 |
+
console.log("Updating transaction...");
|
381 |
$.ajax({
|
382 |
url: '<?php echo $this->getUrl('minkasu_wallet/transaction/update') ?>',
|
383 |
type: 'post',
|
398 |
}
|
399 |
});
|
400 |
return;
|
|
|
401 |
<?php else: ?>
|
402 |
+
console.log("Creating transaction...");
|
403 |
$.ajax({
|
404 |
url: '<?php echo $this->getUrl('minkasu_wallet/transaction/create') ?>',
|
405 |
type: 'post',
|
425 |
|
426 |
|
427 |
$(document).ready(function() {
|
428 |
+
console.log("$_apiEstimateEnabled: " + <?php echo ($_apiEstimateEnabled)? "true":"false" ?>);
|
429 |
+
if (hide_default_estimate_block) {
|
430 |
+
// Hide the "Checkout with Multiple Addresses" option
|
431 |
+
// $(".method-checkout-cart-methods-multishipping").hide();
|
432 |
+
if ($("#co-shipping-method-form").length == 0) {
|
433 |
+
$(".shipping").hide();
|
434 |
+
}
|
435 |
+
}
|
436 |
var minkasu_txn_id_good_for_use = false;
|
437 |
+
<?php if ($minkasu_txn_id): ?>
|
438 |
<?php if ($minkasu_amount == $quote->getGrandTotal()): ?>
|
439 |
+
<?php
|
440 |
+
$data = NULL;
|
441 |
+
$shippingAddress = $quote->getShippingAddress();
|
442 |
+
if ($shippingAddress != NULL) {
|
443 |
+
$expectedAddress = ($shippingAddress->exportCustomerAddress());
|
444 |
+
if ($expectedAddress != NULL) {
|
445 |
+
$data = $expectedAddress->getData();
|
446 |
+
}
|
447 |
+
}
|
448 |
+
if (($data != NULL) &&
|
449 |
+
($minkasu_exp_zip && ($minkasu_exp_zip == $data["postcode"])) &&
|
450 |
+
($minkasu_exp_state && ($minkasu_exp_state == $data["region"]))): ?>
|
451 |
+
minkasu_txn_id_good_for_use = true;
|
452 |
+
<?php endif; ?>
|
453 |
+
<?php endif; ?>
|
454 |
<?php endif; ?>
|
455 |
+
|
456 |
+
$("#ship_zip").focus(function() {
|
457 |
+
if ($(this).val() == "Zip code" && $(this).css("font-style") == "italic") {
|
458 |
+
$(this).val("");
|
459 |
+
$(this).css("font-style", "normal");
|
460 |
+
$(this).css("color", "#333333");
|
461 |
+
}
|
462 |
+
});
|
463 |
+
|
464 |
+
$("#ship_zip").blur(function() {
|
465 |
+
if ($(this).val().length == 0) {
|
466 |
+
resetShippingZipCode();
|
467 |
+
}
|
468 |
+
});
|
469 |
+
|
470 |
+
<?php if ($shipping_estimated) : ?>
|
471 |
+
$("#mk_shipping_est_table").find("#ship_zip").val('<?php echo $estimate_postcode; ?>');
|
472 |
+
$("#mk_shipping_est_table").find("#ship_zip").css("font-style", "normal");
|
473 |
+
$("#mk_shipping_est_table").find("#ship_zip").css("color", "#333333");
|
474 |
+
showShippingOptions();
|
475 |
<?php endif; ?>
|
476 |
|
477 |
+
$("#mk_cart_est_btn").click(function() {
|
478 |
+
updateCartPriceEstimateWithZip(get_shipping_zip_code());
|
479 |
+
});
|
480 |
+
|
481 |
+
$("#discount_code").focus(function() {
|
482 |
+
if ($(this).val() == "Coupon" && $(this).css("font-style") == "italic") {
|
483 |
+
$(this).val("");
|
484 |
+
$(this).css("font-style", "normal");
|
485 |
+
$(this).css("color", "#333333");
|
486 |
+
}
|
487 |
+
});
|
488 |
+
|
489 |
+
$("#discount_code").blur(function() {
|
490 |
+
if ($(this).val().length == 0) {
|
491 |
+
resetDiscountCode();
|
492 |
+
}
|
493 |
+
});
|
494 |
+
|
495 |
+
<?php if ($coupon_code) : ?>
|
496 |
+
$("#discount_txt").text("Remove discount");
|
497 |
+
$("#discount_code").prop("disabled", true);
|
498 |
+
$("#mk_cart_apply_btn").prop("value", "Remove");
|
499 |
+
$("#mk_shipping_est_table").find("#discount_code").val('<?php echo $coupon_code; ?>');
|
500 |
+
$("#mk_shipping_est_table").find("#discount_code").css("font-style", "normal");
|
501 |
+
$("#mk_shipping_est_table").find("#discount_code").css("color", "#333333");
|
502 |
+
<?php endif; ?>
|
503 |
+
|
504 |
+
$("#mk_cart_apply_btn").click(function() {
|
505 |
+
updateCartPriceEstimateWithDiscount(($("#discount_code").prop("disabled"))? null : get_discount_code());
|
506 |
+
});
|
507 |
+
|
508 |
+
console.log("minkasu_txn_id_good_for_use: " + minkasu_txn_id_good_for_use);
|
509 |
$.getScript('<?php echo $_apiGatewayUrl ?>/scripts/minkasu-1.2.js', function() {
|
510 |
|
511 |
var payment_args = {
|
app/design/frontend/gravdept/acumen/template/minkasu/wallet/estimate_box.phtml
ADDED
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/** @var $_apiHelper Minkasu_Wallet_Helper_Api */
|
4 |
+
$_apiHelper = Mage::helper('minkasu_wallet/api');
|
5 |
+
$_apiEstimateEnabled = $_apiHelper->isApiEstimateEnabled();
|
6 |
+
|
7 |
+
$show_minkasu_estimate_box = $_apiEstimateEnabled;
|
8 |
+
|
9 |
+
?>
|
10 |
+
|
11 |
+
<?php if ($show_minkasu_estimate_box) : ?>
|
12 |
+
|
13 |
+
<div id="mk_shipping_est_div" style="/* display: block; */ /* overflow: auto */">
|
14 |
+
<table style="border: 0px; margin:0px;width: 100%;"><tbody><tr>
|
15 |
+
<td style="border: 0px; padding: 0px; padding-bottom: 20px; padding-top: 0px;">
|
16 |
+
|
17 |
+
<table id="mk_shipping_est_table" style="background-color: #E7F6F0; border: 1px solid #19D383; border-collapse: separate; border-spacing: 0px; border-radius: 3px; margin: 0px; padding-bottom: 10px; /* padding-left: 15px; */ /* padding-right: 15px; */ padding-top: 15px; max-width: 330px;width: 100%;">
|
18 |
+
|
19 |
+
<tbody><tr>
|
20 |
+
<td style="border: 0px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top:0px; vertical-align: middle">
|
21 |
+
<input type="text" id="ship_zip" style="background-color: white; border-color: #999999; box-sizing: content-box; color: #999999; font-family: Open Sans; font-size: 13px; font-style: italic; height: 16px; margin: 0px; padding: 4px; width: 65px;" value="Zip code">
|
22 |
+
</td>
|
23 |
+
<td style="border: 0px; padding-bottom: 5px; /* padding-left: 5px; */ padding-right: 5px; padding-top:0px; vertical-align: middle">
|
24 |
+
<input type="button" id="mk_cart_est_btn" value="Estimate Shipping" style="background-color: #F2F2F2; border-color: #999999; border-radius: 2px; border-width: 1px; color: #333333; font-family: Open Sans; font-size: 12px; font-weight: 600; height: 28px; margin: 0px; padding: 4px; width: 110px;">
|
25 |
+
</td>
|
26 |
+
</tr>
|
27 |
+
|
28 |
+
<tr id="discount_code_row" style="display:none">
|
29 |
+
|
30 |
+
<td style="border: 0px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top:5px; vertical-align: middle">
|
31 |
+
<input type="text" id="discount_code" style="background-color: white; border-color: #999999; box-sizing: content-box; color: #999999; font-family: Open Sans; font-size: 13px; font-style: italic; height: 16px; margin: 0px; padding: 4px; width: 65px;" value="Coupon">
|
32 |
+
</td>
|
33 |
+
<td style="border: 0px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top:5px; vertical-align: middle">
|
34 |
+
<input type="button" id="mk_cart_apply_btn" value="Apply" style="background-color: #F2F2F2; border-color: #999999; border-radius: 2px; border-width: 1px; color: #333333; font-family: Open Sans; font-size: 12px; font-weight: 600; height: 28px; margin: 0px; padding: 4px; width: 110px;">
|
35 |
+
</td>
|
36 |
+
</tr>
|
37 |
+
|
38 |
+
<tr id="inprogress_indicator" style="display:none">
|
39 |
+
<td colspan="2" style="border: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top:10px; text-align:center">
|
40 |
+
<img src="https://transactions.minkasu.com/images/spinning_wheel.gif" pagespeed_url_hash="632911007" onload="pagespeed.CriticalImages.checkImageForCriticality(this);" style="margin-left:auto; margin-right:auto">
|
41 |
+
</td>
|
42 |
+
</tr>
|
43 |
+
|
44 |
+
<tr id="shipping_method_label_row" style="display:none" >
|
45 |
+
<td colspan="2" style="padding-left:5px; margin-left: 0px; padding-top: 5px ">
|
46 |
+
<p style="font-family: Open Sans; font-size: 12px; font-weight: 600; text-align:left;"> Shipping Method: </p>
|
47 |
+
</td>
|
48 |
+
</tr>
|
49 |
+
|
50 |
+
<tr id="shipping_options_row" style="display:none">
|
51 |
+
|
52 |
+
<td id="shipping_options_cell" colspan="2" style="border: 0px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top:0px">
|
53 |
+
</td>
|
54 |
+
</tr>
|
55 |
+
|
56 |
+
<tr><td colspan="2" style="border: 0px; padding-bottom: 5px; padding-left: 0px; padding-right: 0px; padding-top:5px;"></td></tr>
|
57 |
+
|
58 |
+
<tr>
|
59 |
+
<td id="mk_checkout_td" colspan="2" style="border: 0px; border-top: 1px solid #DDDDDD; padding-bottom: 0px; padding-left: 0px; padding-right: 18px; padding-top:10px;/* text-align: center; */">
|
60 |
+
<div id="minkasu_payment_div"> </div>
|
61 |
+
<div class="buttons" style="height: 45px;">
|
62 |
+
<div class="right">
|
63 |
+
<input type="button" value="Checkout with Smart Phone (Minkasu)" id="button-mk-chkout" class="button" />
|
64 |
+
</div>
|
65 |
+
</div>
|
66 |
+
</td>
|
67 |
+
</tr>
|
68 |
+
|
69 |
+
</table>
|
70 |
+
|
71 |
+
</td></tr>
|
72 |
+
</table>
|
73 |
+
|
74 |
+
</div>
|
75 |
+
|
76 |
+
|
77 |
+
<?php else: ?>
|
78 |
+
|
79 |
+
<div class="row">
|
80 |
+
<div class="col-sm-12" style="text-align:right" id="minkasu_payment_div"></div>
|
81 |
+
</div>
|
82 |
+
|
83 |
+
<div class="buttons" style="height: 45px;">
|
84 |
+
<div class="right">
|
85 |
+
<input type="button" value="Checkout with Smart Phone (Minkasu)" id="button-mk-chkout" class="button" />
|
86 |
+
</div>
|
87 |
+
</div>
|
88 |
+
|
89 |
+
<?php endif; ?>
|
package.xml
CHANGED
@@ -1,26 +1,20 @@
|
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>minkasu_smartphone_checkout</name>
|
4 |
-
<version>1.
|
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
|
12 |
-

|
13 |
-
Processes online payments using authorize.net 
|
14 |
-
Supports multi-merchant Magento instances
|
15 |
-
Integrated with Jumio for credit card acceptance and verification 
|
16 |
-
Phone verification done by Twilio 
|
17 |
-
Mandatory phone verification for the customer prior to payment 
|
18 |
-
Order confirmation and order cancel notification to customer 
|
19 |
</notes>
|
20 |
<authors><author><name>Minkasu Inc</name><user>it-admin</user><email>it-admin@minkasu.com</email></author></authors>
|
21 |
-
<date>2015-
|
22 |
-
<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="
|
24 |
<compatible/>
|
25 |
<dependencies><required><php><min>5.2.0</min><max>5.6.0</max></php></required></dependencies>
|
26 |
</package>
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>minkasu_smartphone_checkout</name>
|
4 |
+
<version>1.1.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>-addition for estimate shipping and tax
|
12 |
+
-support for sb/live environment 
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
</notes>
|
14 |
<authors><author><name>Minkasu Inc</name><user>it-admin</user><email>it-admin@minkasu.com</email></author></authors>
|
15 |
+
<date>2015-05-11</date>
|
16 |
+
<time>22:02:04</time>
|
17 |
+
<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"/><file name="MinkasuMode.php" hash="8ca5b389ced96071807065a09aa7177e"/></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="1b8a9b51d0b4d881dc8616a47b33b3a9"/><file name="Data.php" hash="42a1ad7ddb0213039f3615a9f6805e24"/></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="f6b0f16d8175b18225d1cc092fcda89f"/><file name="Transaction.php" hash="692f2f8499f25edebd9feafed40eec3f"/><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="Source"><dir name="Api"><file name="Mode.php" hash="0e479fee542ff543ad1e3a2206b74acf"/></dir></dir><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="037736784a58e833a4c76ec7499fe509"/></dir></dir></dir><file name="PaymentController.php" hash="91eda20d426915a5670c7c8c643bf27d"/><file name="PaymentController.php.bk" hash="cac0b113f5ecf0effcc8d6f6c60faca6"/><file name="PaymentController.php.old" hash="981afd634443bc7998c76ec99c286e99"/><file name="PaymentController.php~" hash="229a669ed1748eacac248ee3bb85c157"/><file name="TransactionController.php" hash="361617e656a59979d886fe54cf2328a5"/><file name="TransactionController.php~" hash="7ba1f617632e7b7685e8d521c9134b01"/></dir><dir name="etc"><file name="config.xml" hash="1983201fe27ba3f916f19be150a0cab6"/><file name="system.xml" hash="cd39ecd60ac6c112528c14b4c77d1a28"/></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="383412265ce51df29662f23f1e3accea"/></dir><dir name="template"><dir name="minkasu"><dir name="wallet"><file name="pay.phtml" hash="9b29c41d1ada67233a8d0defc33f51d4"/><file name="estimate_box.phtml" hash="5162820b71379e5f25e3333a17184e16"/></dir></dir></dir></dir></dir><dir name="gravdept"><dir name="acumen"><dir name="template"><dir name="minkasu"><dir name="wallet"><file name="estimate_box.phtml" hash="7c839278df79b217ad5f53a24ad8b32d"/></dir></dir></dir></dir></dir></dir></target></contents>
|
18 |
<compatible/>
|
19 |
<dependencies><required><php><min>5.2.0</min><max>5.6.0</max></php></required></dependencies>
|
20 |
</package>
|