Version Notes
v0.2.2 - Initial Release
Download this release
Release Info
Developer | Kash Corp. |
Extension | kash_gateway |
Version | 0.2.3 |
Comparing to | |
See all releases |
Code changes from version 0.1.4 to 0.2.3
- app/code/local/Kash/Gateway/Model/Api/Abstract.php +0 -4
- app/code/local/Kash/Gateway/Model/Api/Bb.php +73 -29
- app/code/local/Kash/Gateway/Model/Checkout.php +42 -21
- app/code/local/Kash/Gateway/Model/Config.php +0 -7
- app/code/local/Kash/Gateway/Model/Observer.php +84 -0
- app/code/local/Kash/Gateway/controllers/BbController.php +84 -70
- app/code/local/Kash/Gateway/etc/config.xml +28 -1
- app/code/local/Kash/Gateway/etc/system.xml +10 -0
- app/design/frontend/base/default/layout/kash/gateway.xml +0 -3
- app/design/frontend/base/default/template/kash/container.phtml +3 -3
- package.xml +17 -11
- skin/frontend/base/default/css/kash/lightwindow.css +3 -0
- skin/frontend/base/default/js/kash/lightwindow.js +8 -4
app/code/local/Kash/Gateway/Model/Api/Abstract.php
CHANGED
@@ -134,10 +134,6 @@ abstract class Kash_Gateway_Model_Api_Abstract extends Varien_Object
|
|
134 |
}
|
135 |
}
|
136 |
|
137 |
-
// TODO: Eventually fix this properly
|
138 |
-
// https://app.asana.com/0/56892580162484/63230238408321
|
139 |
-
$result['x_test'] = 'false';
|
140 |
-
|
141 |
return $result;
|
142 |
}
|
143 |
|
134 |
}
|
135 |
}
|
136 |
|
|
|
|
|
|
|
|
|
137 |
return $result;
|
138 |
}
|
139 |
|
app/code/local/Kash/Gateway/Model/Api/Bb.php
CHANGED
@@ -90,37 +90,43 @@ class Kash_Gateway_Model_Api_Bb extends Kash_Gateway_Model_Api_Abstract
|
|
90 |
'x_customer_email' => 'email',
|
91 |
'x_customer_first_name' => 'firstname',
|
92 |
'x_customer_last_name' => 'lastname',
|
93 |
-
'
|
94 |
-
'
|
95 |
-
'
|
96 |
-
'
|
97 |
-
'
|
98 |
-
'
|
99 |
'x_customer_phone' => 'telephone',
|
100 |
);
|
101 |
|
102 |
-
/**
|
103 |
-
* Map for billing address to do request (not response)
|
104 |
-
* Merging with $_billingAddressMap
|
105 |
-
*
|
106 |
-
* @var array
|
107 |
-
*/
|
108 |
-
protected $_billingAddressMapRequest = array();
|
109 |
-
|
110 |
/**
|
111 |
* Map for shipping address import/export (extends billing address mapper)
|
112 |
* @var array
|
113 |
*/
|
114 |
protected $_shippingAddressMap = array(
|
|
|
|
|
115 |
'x_customer_shipping_country' => 'country_id',
|
116 |
'x_customer_shipping_state' => 'region',
|
117 |
'x_customer_shipping_city' => 'city',
|
118 |
'x_customer_shipping_address1' => 'street',
|
119 |
'x_customer_shipping_address2' => 'street2',
|
120 |
'x_customer_shipping_zip' => 'postcode',
|
121 |
-
'
|
122 |
);
|
123 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
124 |
/**
|
125 |
* Return request for API
|
126 |
*
|
@@ -131,14 +137,17 @@ class Kash_Gateway_Model_Api_Bb extends Kash_Gateway_Model_Api_Abstract
|
|
131 |
$this->_exportLineItems($request);
|
132 |
|
133 |
// import/suppress shipping address, if any
|
134 |
-
|
135 |
-
|
136 |
-
|
|
|
|
|
137 |
|
138 |
$date = Zend_Date::now();
|
139 |
$request['x_timestamp'] = $date->getIso();
|
140 |
$request['x_signature'] = $this->getSignature($request, $this->getHmacKey());
|
141 |
|
|
|
142 |
return $request;
|
143 |
}
|
144 |
|
@@ -181,25 +190,26 @@ class Kash_Gateway_Model_Api_Bb extends Kash_Gateway_Model_Api_Abstract
|
|
181 |
*/
|
182 |
protected function _importAddresses(array $to)
|
183 |
{
|
184 |
-
|
185 |
-
$
|
186 |
-
|
187 |
-
$to = Varien_Object_Mapper::accumulateByMap(
|
188 |
-
$billingAddress,
|
189 |
-
$to,
|
190 |
-
array_merge(array_flip($this->_billingAddressMap), $this->_billingAddressMapRequest)
|
191 |
-
);
|
192 |
if ($regionCode = $this->_lookupRegionCodeFromAddress($billingAddress)) {
|
193 |
-
|
|
|
194 |
}
|
195 |
-
|
|
|
|
|
|
|
|
|
196 |
$to = Varien_Object_Mapper::accumulateByMap($shippingAddress, $to, array_flip($this->_shippingAddressMap));
|
197 |
if ($regionCode = $this->_lookupRegionCodeFromAddress($shippingAddress)) {
|
|
|
198 |
$to['x_customer_shipping_state'] = $regionCode;
|
199 |
}
|
200 |
-
$this->_importStreetFromAddress($billingAddress, $to, 'x_customer_shipping_address1', 'x_customer_shipping_address2');
|
201 |
$this->_importStreetFromAddress($shippingAddress, $to, 'x_customer_shipping_address1', 'x_customer_shipping_address2');
|
202 |
}
|
|
|
203 |
return $to;
|
204 |
}
|
205 |
|
@@ -232,4 +242,38 @@ class Kash_Gateway_Model_Api_Bb extends Kash_Gateway_Model_Api_Abstract
|
|
232 |
$value = $this->_getDataOrConfig('server_key');
|
233 |
return $value;
|
234 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
235 |
}
|
90 |
'x_customer_email' => 'email',
|
91 |
'x_customer_first_name' => 'firstname',
|
92 |
'x_customer_last_name' => 'lastname',
|
93 |
+
'x_customer_billing_country' => 'country_id', // iso-3166 two-character code
|
94 |
+
'x_customer_billing_state' => 'region',
|
95 |
+
'x_customer_billing_city' => 'city',
|
96 |
+
'x_customer_billing_address1' => 'street',
|
97 |
+
'x_customer_billing_address2' => 'street2',
|
98 |
+
'x_customer_billing_zip' => 'postcode',
|
99 |
'x_customer_phone' => 'telephone',
|
100 |
);
|
101 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
/**
|
103 |
* Map for shipping address import/export (extends billing address mapper)
|
104 |
* @var array
|
105 |
*/
|
106 |
protected $_shippingAddressMap = array(
|
107 |
+
'x_customer_shipping_first_name' => 'firstname',
|
108 |
+
'x_customer_shipping_last_name' => 'lastname',
|
109 |
'x_customer_shipping_country' => 'country_id',
|
110 |
'x_customer_shipping_state' => 'region',
|
111 |
'x_customer_shipping_city' => 'city',
|
112 |
'x_customer_shipping_address1' => 'street',
|
113 |
'x_customer_shipping_address2' => 'street2',
|
114 |
'x_customer_shipping_zip' => 'postcode',
|
115 |
+
'x_customer_shipping_phone' => 'telephone',
|
116 |
);
|
117 |
|
118 |
+
protected $logFile = null;
|
119 |
+
|
120 |
+
|
121 |
+
public function __construct() {
|
122 |
+
$logDir = Mage::getBaseDir("log");
|
123 |
+
if (!is_dir($logDir)) {
|
124 |
+
mkdir($logDir);
|
125 |
+
chmod($logDir, 0750);
|
126 |
+
}
|
127 |
+
$this->logFile = $logDir . DIRECTORY_SEPARATOR . 'kash.log';
|
128 |
+
|
129 |
+
}
|
130 |
/**
|
131 |
* Return request for API
|
132 |
*
|
137 |
$this->_exportLineItems($request);
|
138 |
|
139 |
// import/suppress shipping address, if any
|
140 |
+
$request = $this->_importAddresses($request);
|
141 |
+
|
142 |
+
$request['x_test'] = ($this->getXTest() === '1') ? 'true' : 'false';
|
143 |
+
$request['x_version'] = '23';
|
144 |
+
$request['x_plugin'] = 'magento';
|
145 |
|
146 |
$date = Zend_Date::now();
|
147 |
$request['x_timestamp'] = $date->getIso();
|
148 |
$request['x_signature'] = $this->getSignature($request, $this->getHmacKey());
|
149 |
|
150 |
+
$this->log('x_reference '.$request['x_reference'].': callSetBBCheckout()');
|
151 |
return $request;
|
152 |
}
|
153 |
|
190 |
*/
|
191 |
protected function _importAddresses(array $to)
|
192 |
{
|
193 |
+
// Fill in billing address information
|
194 |
+
$billingAddress = $this->getBillingAddress();
|
195 |
+
$to = Varien_Object_Mapper::accumulateByMap($billingAddress, $to, array_flip($this->_billingAddressMap));
|
|
|
|
|
|
|
|
|
|
|
196 |
if ($regionCode = $this->_lookupRegionCodeFromAddress($billingAddress)) {
|
197 |
+
// Change state to 2 letter representation (e.g. From 'California' to 'CA')
|
198 |
+
$to['x_customer_billing_state'] = $regionCode;
|
199 |
}
|
200 |
+
$this->_importStreetFromAddress($billingAddress, $to, 'x_customer_billing_address1', 'x_customer_billing_address2');
|
201 |
+
|
202 |
+
// Fill in shipping address information
|
203 |
+
if (!$this->getSuppressShipping() && $this->getAddress()) {
|
204 |
+
$shippingAddress = $this->getAddress();
|
205 |
$to = Varien_Object_Mapper::accumulateByMap($shippingAddress, $to, array_flip($this->_shippingAddressMap));
|
206 |
if ($regionCode = $this->_lookupRegionCodeFromAddress($shippingAddress)) {
|
207 |
+
// Change state to 2 letter representation (e.g. From 'California' to 'CA')
|
208 |
$to['x_customer_shipping_state'] = $regionCode;
|
209 |
}
|
|
|
210 |
$this->_importStreetFromAddress($shippingAddress, $to, 'x_customer_shipping_address1', 'x_customer_shipping_address2');
|
211 |
}
|
212 |
+
|
213 |
return $to;
|
214 |
}
|
215 |
|
242 |
$value = $this->_getDataOrConfig('server_key');
|
243 |
return $value;
|
244 |
}
|
245 |
+
|
246 |
+
//log a message to our kash log
|
247 |
+
public function log($msg) {
|
248 |
+
file_put_contents($this->logFile, $this->getXShopName()." ".date('c')." ".print_r($msg, true)."\n", FILE_APPEND | LOCK_EX);
|
249 |
+
}
|
250 |
+
|
251 |
+
public function getLog() {
|
252 |
+
$result = @file_get_contents($this->logFile);
|
253 |
+
return $result===FALSE ? date('c')." Could not read kash log" : $result;
|
254 |
+
}
|
255 |
+
|
256 |
+
/**
|
257 |
+
* Erase the log file once it's been sent to our server. In case it's been written to while
|
258 |
+
* we're sending it back, erase only the first $length characters and leave the rest for next time.
|
259 |
+
*/
|
260 |
+
public function resetLog($length) {
|
261 |
+
$file = @fopen($this->logFile, "r+");
|
262 |
+
if (!$file) {
|
263 |
+
return;
|
264 |
+
}
|
265 |
+
|
266 |
+
if (flock($file, LOCK_EX)) {
|
267 |
+
$contents = '';
|
268 |
+
while (!feof($file)) {
|
269 |
+
$contents .= fread($file, 8192);
|
270 |
+
}
|
271 |
+
ftruncate($file, 0);
|
272 |
+
rewind($file);
|
273 |
+
fwrite($file, substr($contents, $length));
|
274 |
+
fflush($file);
|
275 |
+
flock($file, LOCK_UN);
|
276 |
+
}
|
277 |
+
fclose($file);
|
278 |
+
}
|
279 |
}
|
app/code/local/Kash/Gateway/Model/Checkout.php
CHANGED
@@ -158,22 +158,23 @@ class Kash_Gateway_Model_Checkout
|
|
158 |
*/
|
159 |
public function start()
|
160 |
{
|
161 |
-
|
162 |
$this->_quote->collectTotals();
|
163 |
|
164 |
if (!$this->_quote->getGrandTotal() && !$this->_quote->hasNominalItems()) {
|
|
|
165 |
Mage::throwException(Mage::helper('kash_gateway')->__('Payment does not support processing orders with zero amount. To complete your purchase, proceed to the standard checkout process.'));
|
166 |
}
|
167 |
|
168 |
-
//Mage::helper('kash_gateway/checkout')->restoreQuote();
|
169 |
$this->_quote->reserveOrderId()->save();
|
|
|
|
|
170 |
// prepare API
|
171 |
-
$this->
|
172 |
-
$this->_api->setAmount($this->_quote->getGrandTotal())
|
173 |
->setCurrencyCode($this->_quote->getBaseCurrencyCode())
|
174 |
->setXInvoice($this->_quote->getReservedOrderId());
|
175 |
list($callbackUrl, $cancelUrl, $completeUrl) = $this->_giropayUrls;
|
176 |
-
$this->
|
177 |
'x_url_callback' => $callbackUrl,
|
178 |
'x_url_cancel' => $cancelUrl,
|
179 |
'x_url_complete' => $completeUrl,
|
@@ -182,29 +183,34 @@ class Kash_Gateway_Model_Checkout
|
|
182 |
'x_reference' => $this->_quote->getReservedOrderId(),
|
183 |
));
|
184 |
|
185 |
-
//
|
186 |
-
|
187 |
-
|
|
|
|
|
|
|
|
|
|
|
188 |
|
189 |
-
|
|
|
|
|
190 |
} else {
|
191 |
-
|
192 |
-
|
193 |
-
|
|
|
194 |
}
|
195 |
-
$this->_quote->getPayment()->save();
|
196 |
}
|
197 |
|
198 |
// add line items
|
199 |
$paymentCart = Mage::getModel('kash_gateway/cart', array($this->_quote));
|
200 |
-
$this->
|
201 |
|
202 |
// call API and redirect with token
|
203 |
-
$token = $this->
|
204 |
-
$token = $this->_api->callSetBBCheckout();
|
205 |
$this->_redirectUrl = $this->_config->post_url;
|
206 |
|
207 |
-
$this->_quote->getPayment()->save();
|
208 |
return $token;
|
209 |
}
|
210 |
|
@@ -288,7 +294,7 @@ class Kash_Gateway_Model_Checkout
|
|
288 |
|
289 |
$params = $this->getParams();
|
290 |
$result = array();
|
291 |
-
foreach ($this->
|
292 |
$result[$key] = $params[$val];
|
293 |
}
|
294 |
$payment->setAdditionalInformation($result);
|
@@ -351,7 +357,7 @@ class Kash_Gateway_Model_Checkout
|
|
351 |
/** +/
|
352 |
* @return Kash_Gateway_Model_Api_Bb
|
353 |
*/
|
354 |
-
public function
|
355 |
{
|
356 |
if (null === $this->_api) {
|
357 |
$this->_api = Mage::getModel($this->_apiType)->setConfigObject($this->_config);
|
@@ -366,6 +372,7 @@ class Kash_Gateway_Model_Checkout
|
|
366 |
*/
|
367 |
protected function _prepareGuestQuote()
|
368 |
{
|
|
|
369 |
$quote = $this->_quote;
|
370 |
$quote->setCustomerId(null)
|
371 |
->setCustomerEmail($quote->getBillingAddress()->getEmail())
|
@@ -374,6 +381,14 @@ class Kash_Gateway_Model_Checkout
|
|
374 |
return $this;
|
375 |
}
|
376 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
377 |
/**
|
378 |
* Checks if customer with email coming from Express checkout exists
|
379 |
* +/
|
@@ -395,6 +410,7 @@ class Kash_Gateway_Model_Checkout
|
|
395 |
*/
|
396 |
protected function _prepareNewCustomerQuote()
|
397 |
{
|
|
|
398 |
$quote = $this->_quote;
|
399 |
$billing = $quote->getBillingAddress();
|
400 |
$shipping = $quote->isVirtual() ? null : $quote->getShippingAddress();
|
@@ -454,11 +470,13 @@ class Kash_Gateway_Model_Checkout
|
|
454 |
*/
|
455 |
protected function _prepareCustomerQuote()
|
456 |
{
|
|
|
457 |
$quote = $this->_quote;
|
458 |
$billing = $quote->getBillingAddress();
|
459 |
$shipping = $quote->isVirtual() ? null : $quote->getShippingAddress();
|
460 |
|
461 |
$customer = $this->getCustomerSession()->getCustomer();
|
|
|
462 |
if (!$billing->getCustomerId() || $billing->getSaveInAddressBook()) {
|
463 |
$customerBilling = $billing->exportCustomerAddress();
|
464 |
$customer->addAddress($customerBilling);
|
@@ -492,6 +510,7 @@ class Kash_Gateway_Model_Checkout
|
|
492 |
*/
|
493 |
protected function _involveNewCustomer()
|
494 |
{
|
|
|
495 |
$customer = $this->_quote->getCustomer();
|
496 |
if ($customer->isConfirmationRequired()) {
|
497 |
$customer->sendNewAccountEmail('confirmation');
|
@@ -547,7 +566,7 @@ class Kash_Gateway_Model_Checkout
|
|
547 |
*/
|
548 |
public function checkSignature()
|
549 |
{
|
550 |
-
$api = $this->
|
551 |
$signature = $this->getParams('x_signature');
|
552 |
$sig = $api->getSignature($this->getParams(), $api->getHmacKey());
|
553 |
if ($sig === $signature) {
|
@@ -636,8 +655,10 @@ class Kash_Gateway_Model_Checkout
|
|
636 |
$ruleCoupon->save();
|
637 |
return $ruleCoupon->getCouponCode();
|
638 |
} catch (Exception $ex) {
|
|
|
|
|
639 |
Mage::logException($ex);
|
640 |
-
//Mage::throwException($ex);
|
641 |
}
|
642 |
}
|
643 |
}
|
|
158 |
*/
|
159 |
public function start()
|
160 |
{
|
161 |
+
$this->getApi()->log('quote '.$this->_quote->getId().': start()');
|
162 |
$this->_quote->collectTotals();
|
163 |
|
164 |
if (!$this->_quote->getGrandTotal() && !$this->_quote->hasNominalItems()) {
|
165 |
+
$this->getApi()->log('quote '.$this->_quote->getId().': Error, quote has items, but no amount.');
|
166 |
Mage::throwException(Mage::helper('kash_gateway')->__('Payment does not support processing orders with zero amount. To complete your purchase, proceed to the standard checkout process.'));
|
167 |
}
|
168 |
|
|
|
169 |
$this->_quote->reserveOrderId()->save();
|
170 |
+
$this->getApi()->log('quote '.$this->_quote->getId().' reserved orderId/x_reference '.$this->_quote->getReservedOrderId());
|
171 |
+
|
172 |
// prepare API
|
173 |
+
$this->getApi()->setAmount($this->_quote->getGrandTotal())
|
|
|
174 |
->setCurrencyCode($this->_quote->getBaseCurrencyCode())
|
175 |
->setXInvoice($this->_quote->getReservedOrderId());
|
176 |
list($callbackUrl, $cancelUrl, $completeUrl) = $this->_giropayUrls;
|
177 |
+
$this->getApi()->addData(array(
|
178 |
'x_url_callback' => $callbackUrl,
|
179 |
'x_url_cancel' => $cancelUrl,
|
180 |
'x_url_complete' => $completeUrl,
|
183 |
'x_reference' => $this->_quote->getReservedOrderId(),
|
184 |
));
|
185 |
|
186 |
+
// Always set billing address. This is always needed so that we can process payments.
|
187 |
+
$billingAddress = $this->_quote->getBillingAddress();
|
188 |
+
if ($billingAddress->validate() === true) {
|
189 |
+
$this->getApi()->setBillingAddress($billingAddress);
|
190 |
+
}
|
191 |
+
else {
|
192 |
+
$this->getApi()->log('x_reference '.$this->_quote->getReservedOrderId().': Could not validate billing address');
|
193 |
+
}
|
194 |
|
195 |
+
// Set shipping address unless the product is a virtual product
|
196 |
+
if ($this->_quote->getIsVirtual()) {
|
197 |
+
$this->getApi()->setSuppressShipping(true);
|
198 |
} else {
|
199 |
+
// Set shipping address
|
200 |
+
$shippingAddress = $this->_quote->getShippingAddress();
|
201 |
+
if ($shippingAddress->validate() === true) {
|
202 |
+
$this->getApi()->setAddress($shippingAddress);
|
203 |
}
|
|
|
204 |
}
|
205 |
|
206 |
// add line items
|
207 |
$paymentCart = Mage::getModel('kash_gateway/cart', array($this->_quote));
|
208 |
+
$this->getApi()->setPaymentCart($paymentCart);
|
209 |
|
210 |
// call API and redirect with token
|
211 |
+
$token = $this->getApi()->callSetBBCheckout();
|
|
|
212 |
$this->_redirectUrl = $this->_config->post_url;
|
213 |
|
|
|
214 |
return $token;
|
215 |
}
|
216 |
|
294 |
|
295 |
$params = $this->getParams();
|
296 |
$result = array();
|
297 |
+
foreach ($this->getApi()->responseMap as $key => $val) {
|
298 |
$result[$key] = $params[$val];
|
299 |
}
|
300 |
$payment->setAdditionalInformation($result);
|
357 |
/** +/
|
358 |
* @return Kash_Gateway_Model_Api_Bb
|
359 |
*/
|
360 |
+
public function getApi()
|
361 |
{
|
362 |
if (null === $this->_api) {
|
363 |
$this->_api = Mage::getModel($this->_apiType)->setConfigObject($this->_config);
|
372 |
*/
|
373 |
protected function _prepareGuestQuote()
|
374 |
{
|
375 |
+
$this->getApi()->log('x_reference '.$this->_quote->getReservedOrderId().': Preparing a quote for a GUEST user.');
|
376 |
$quote = $this->_quote;
|
377 |
$quote->setCustomerId(null)
|
378 |
->setCustomerEmail($quote->getBillingAddress()->getEmail())
|
381 |
return $this;
|
382 |
}
|
383 |
|
384 |
+
/**
|
385 |
+
* Logins the user so orders can be created with the right account
|
386 |
+
*/
|
387 |
+
public function loginUser() {
|
388 |
+
$customerId = $this->_lookupCustomerId();
|
389 |
+
$this->getCustomerSession()->loginById($customerId);
|
390 |
+
}
|
391 |
+
|
392 |
/**
|
393 |
* Checks if customer with email coming from Express checkout exists
|
394 |
* +/
|
410 |
*/
|
411 |
protected function _prepareNewCustomerQuote()
|
412 |
{
|
413 |
+
$this->getApi()->log('x_reference '.$this->_quote->getReservedOrderId().': preparing a new customer quote');
|
414 |
$quote = $this->_quote;
|
415 |
$billing = $quote->getBillingAddress();
|
416 |
$shipping = $quote->isVirtual() ? null : $quote->getShippingAddress();
|
470 |
*/
|
471 |
protected function _prepareCustomerQuote()
|
472 |
{
|
473 |
+
$this->getApi()->log('x_reference '.$this->_quote->getReservedOrderId().': preparing a quote for an existing customer');
|
474 |
$quote = $this->_quote;
|
475 |
$billing = $quote->getBillingAddress();
|
476 |
$shipping = $quote->isVirtual() ? null : $quote->getShippingAddress();
|
477 |
|
478 |
$customer = $this->getCustomerSession()->getCustomer();
|
479 |
+
|
480 |
if (!$billing->getCustomerId() || $billing->getSaveInAddressBook()) {
|
481 |
$customerBilling = $billing->exportCustomerAddress();
|
482 |
$customer->addAddress($customerBilling);
|
510 |
*/
|
511 |
protected function _involveNewCustomer()
|
512 |
{
|
513 |
+
$this->getApi()->log('x_reference '.$this->_quote->getReservedOrderId().': involve new customer, send them confirmation email.');
|
514 |
$customer = $this->_quote->getCustomer();
|
515 |
if ($customer->isConfirmationRequired()) {
|
516 |
$customer->sendNewAccountEmail('confirmation');
|
566 |
*/
|
567 |
public function checkSignature()
|
568 |
{
|
569 |
+
$api = $this->getApi();
|
570 |
$signature = $this->getParams('x_signature');
|
571 |
$sig = $api->getSignature($this->getParams(), $api->getHmacKey());
|
572 |
if ($sig === $signature) {
|
655 |
$ruleCoupon->save();
|
656 |
return $ruleCoupon->getCouponCode();
|
657 |
} catch (Exception $ex) {
|
658 |
+
$this->getApi()->log('Error: coupon exception');
|
659 |
+
$this->getApi()->log($ex);
|
660 |
Mage::logException($ex);
|
|
|
661 |
}
|
662 |
}
|
663 |
}
|
664 |
+
|
app/code/local/Kash/Gateway/Model/Config.php
CHANGED
@@ -131,13 +131,6 @@ class Kash_Gateway_Model_Config
|
|
131 |
switch ($fieldName) {
|
132 |
case 'merchant_country':
|
133 |
return "paypal/general/{$fieldName}";
|
134 |
-
case 'post_url':
|
135 |
-
case 'x_account_id':
|
136 |
-
case 'server_key':
|
137 |
-
if (Mage::getStoreConfig($this->_mapMethodFieldset('x_test'), $this->_storeId)) {
|
138 |
-
$fieldName .= '_test';
|
139 |
-
}
|
140 |
-
return "payment/{$this->_methodCode}/{$fieldName}";
|
141 |
default:
|
142 |
return "payment/{$this->_methodCode}/{$fieldName}";
|
143 |
}
|
131 |
switch ($fieldName) {
|
132 |
case 'merchant_country':
|
133 |
return "paypal/general/{$fieldName}";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
134 |
default:
|
135 |
return "payment/{$this->_methodCode}/{$fieldName}";
|
136 |
}
|
app/code/local/Kash/Gateway/Model/Observer.php
CHANGED
@@ -42,5 +42,89 @@ class Kash_Gateway_Model_Observer extends Varien_Object
|
|
42 |
}
|
43 |
}
|
44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
}
|
46 |
|
42 |
}
|
43 |
}
|
44 |
|
45 |
+
/**
|
46 |
+
* Listen for when an order is completed, then send that order's payment details and amount
|
47 |
+
* for analytics
|
48 |
+
*
|
49 |
+
* @param Varien_Object $observer
|
50 |
+
*/
|
51 |
+
public function sendReport($observer) {
|
52 |
+
$orderId = $observer->getData('order_ids')[0];
|
53 |
+
|
54 |
+
$order = Mage::getModel('sales/order')->load($orderId);
|
55 |
+
$payment = $order->getPayment()->getMethodInstance()->getCode();
|
56 |
+
$total = $order->getGrandTotal();
|
57 |
+
|
58 |
+
//standardize the 'kash' type, leave others as they are
|
59 |
+
if ($payment == 'kash_gateway') {
|
60 |
+
$payment = 'kash';
|
61 |
+
}
|
62 |
+
|
63 |
+
$config = Mage::getModel('kash_gateway/config', array(Kash_Gateway_Model_Config::METHOD_GATEWAY_KASH));
|
64 |
+
$api = Mage::getModel('kash_gateway/api_bb')->setConfigObject($config);
|
65 |
+
|
66 |
+
$url = $config->post_url.'/reporting';
|
67 |
+
|
68 |
+
$api->log("order ".$order->getIncrementId()." paid with: ".$payment);
|
69 |
+
$log = $api->getLog();
|
70 |
+
|
71 |
+
$data = array(
|
72 |
+
'x_account_id' => $config->x_account_id,
|
73 |
+
'x_merchant' => $config->x_shop_name,
|
74 |
+
'x_payment' => $payment,
|
75 |
+
'x_amount' => $total,
|
76 |
+
'x_log' => $log
|
77 |
+
);
|
78 |
+
$data['x_signature'] = $api->getSignature($data, $api->getHmacKey());
|
79 |
+
|
80 |
+
$options = array(
|
81 |
+
'http' => array(
|
82 |
+
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
|
83 |
+
'method' => 'POST',
|
84 |
+
'content' => http_build_query($data),
|
85 |
+
),
|
86 |
+
);
|
87 |
+
|
88 |
+
//send the stats and log back to the server.
|
89 |
+
$context = stream_context_create($options);
|
90 |
+
$result = file_get_contents($url, false, $context);
|
91 |
+
|
92 |
+
//If the server did not return an error, erase the part of the log we just sent.
|
93 |
+
if ($result !== FALSE) {
|
94 |
+
$api->resetLog(strlen($log));
|
95 |
+
}
|
96 |
+
}
|
97 |
+
|
98 |
+
/**
|
99 |
+
* Listen for when an order is created and log it
|
100 |
+
*
|
101 |
+
* @param Varien_Object $observer
|
102 |
+
*/
|
103 |
+
public function logOrderSave($observer) {
|
104 |
+
$order = $observer->getOrder();
|
105 |
+
|
106 |
+
$config = Mage::getModel('kash_gateway/config', array(Kash_Gateway_Model_Config::METHOD_GATEWAY_KASH));
|
107 |
+
$api = Mage::getModel('kash_gateway/api_bb')->setConfigObject($config);
|
108 |
+
|
109 |
+
$api->log('order '.$order->getIncrementId().': was saved, state is: '.$order->getState());
|
110 |
+
}
|
111 |
+
|
112 |
+
|
113 |
+
/**
|
114 |
+
* Listen for when an a quote is converted to an order and log it
|
115 |
+
*
|
116 |
+
* @param Varien_Object $observer
|
117 |
+
*/
|
118 |
+
public function logQuoteToOrder($observer) {
|
119 |
+
$order = $observer->getOrder();
|
120 |
+
$quote = $observer->getQuote();
|
121 |
+
|
122 |
+
$config = Mage::getModel('kash_gateway/config', array(Kash_Gateway_Model_Config::METHOD_GATEWAY_KASH));
|
123 |
+
$api = Mage::getModel('kash_gateway/api_bb')->setConfigObject($config);
|
124 |
+
|
125 |
+
$api->log('quote '.$quote->getId().': was converted to order '.$order->getIncrementId());
|
126 |
+
|
127 |
+
}
|
128 |
+
|
129 |
}
|
130 |
|
app/code/local/Kash/Gateway/controllers/BbController.php
CHANGED
@@ -43,6 +43,8 @@ class Kash_Gateway_BbController extends Mage_Core_Controller_Front_Action
|
|
43 |
*/
|
44 |
protected $_configMethod = Kash_Gateway_Model_Config::METHOD_GATEWAY_KASH;
|
45 |
|
|
|
|
|
46 |
/**
|
47 |
* Instantiate config
|
48 |
*/
|
@@ -50,12 +52,14 @@ class Kash_Gateway_BbController extends Mage_Core_Controller_Front_Action
|
|
50 |
{
|
51 |
parent::_construct();
|
52 |
$this->_config = Mage::getModel($this->_configType, array($this->_configMethod));
|
|
|
53 |
}
|
54 |
|
55 |
/**
|
56 |
* Get form for requesting form
|
57 |
*/
|
58 |
public function startAction(){
|
|
|
59 |
$paymentParams = $this->getPaymentRequest();
|
60 |
if(!$paymentParams){
|
61 |
return;
|
@@ -74,6 +78,7 @@ class Kash_Gateway_BbController extends Mage_Core_Controller_Front_Action
|
|
74 |
*/
|
75 |
public function getRequestAction()
|
76 |
{
|
|
|
77 |
try {
|
78 |
$paymentParams = $this->getPaymentRequest();
|
79 |
if(!$paymentParams){
|
@@ -94,6 +99,7 @@ class Kash_Gateway_BbController extends Mage_Core_Controller_Front_Action
|
|
94 |
} catch (Mage_Core_Exception $e) {
|
95 |
$this->_getCheckoutSession()->addError($e->getMessage());
|
96 |
} catch (Exception $e) {
|
|
|
97 |
$this->_getCheckoutSession()->addError($this->__('Unable to start BB Checkout.'));
|
98 |
Mage::logException($e);
|
99 |
}
|
@@ -106,6 +112,7 @@ class Kash_Gateway_BbController extends Mage_Core_Controller_Front_Action
|
|
106 |
*/
|
107 |
public function cancelAction()
|
108 |
{
|
|
|
109 |
$this->_initToken(false);
|
110 |
$this->_redirect('checkout/cart');
|
111 |
}
|
@@ -116,25 +123,47 @@ class Kash_Gateway_BbController extends Mage_Core_Controller_Front_Action
|
|
116 |
public function callbackAction()
|
117 |
{
|
118 |
$param = Mage::app()->getRequest()->getParam('x_reference');
|
119 |
-
$
|
120 |
-
|
|
|
|
|
121 |
|
122 |
$this->_config->setStoreId($this->_getQuote()->getStoreId());
|
123 |
$this->_checkout = Mage::getSingleton($this->_checkoutType, array(
|
124 |
'config' => $this->_config,
|
125 |
-
'quote' => $
|
126 |
));
|
|
|
127 |
|
128 |
$params = Mage::app()->getRequest()->getParams();
|
129 |
$this->_checkout->setParams($params);
|
130 |
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
138 |
}
|
139 |
}
|
140 |
|
@@ -143,25 +172,48 @@ class Kash_Gateway_BbController extends Mage_Core_Controller_Front_Action
|
|
143 |
*/
|
144 |
public function completeAction()
|
145 |
{
|
|
|
146 |
try {
|
147 |
-
if (!$this->_initCheckout()) {
|
148 |
$this->getResponse()->setRedirect(Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB));
|
149 |
return;
|
150 |
}
|
151 |
if (!$this->_checkout->checkSignature()) {
|
152 |
-
|
153 |
Mage::getSingleton('checkout/session')->addError('Not valid signature');
|
154 |
$this->_redirect('checkout/cart');
|
155 |
return;
|
156 |
}
|
157 |
if (!$this->_checkout->checkResult()) {
|
158 |
-
|
159 |
Mage::getSingleton('checkout/session')->addError('Kash Gateway not completed');
|
160 |
$this->_redirect('checkout/cart');
|
161 |
return;
|
162 |
}
|
163 |
|
164 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
165 |
if (!$this->_checkout->canSkipOrderReviewStep()) {
|
166 |
$this->_redirect('checkout/onepage/success');
|
167 |
} else {
|
@@ -171,6 +223,8 @@ class Kash_Gateway_BbController extends Mage_Core_Controller_Front_Action
|
|
171 |
} catch (Mage_Core_Exception $e) {
|
172 |
Mage::getSingleton('checkout/session')->addError($e->getMessage());
|
173 |
} catch (Exception $e) {
|
|
|
|
|
174 |
Mage::getSingleton('checkout/session')->addError($this->__('Unable to process Kash Gateway Checkout approval.'));
|
175 |
Mage::logException($e);
|
176 |
}
|
@@ -186,18 +240,18 @@ class Kash_Gateway_BbController extends Mage_Core_Controller_Front_Action
|
|
186 |
$session = $this->_getCheckoutSession();
|
187 |
// "last successful quote"
|
188 |
$quoteId = $session->getLastQuoteId();
|
189 |
-
$
|
190 |
|
191 |
$this->loadLayout();
|
192 |
$this->_initLayoutMessages('kash_gateway/session');
|
193 |
$reviewBlock = $this->getLayout()->getBlock('gateway.kash.review');
|
194 |
-
$reviewBlock->setQuote($
|
195 |
-
$detailsBlock = $reviewBlock->getChild('details')->setCustomQuote($
|
196 |
if ($reviewBlock->getChild('shipping_method')) {
|
197 |
-
$reviewBlock->getChild('shipping_method')->setCustomQuote($
|
198 |
}
|
199 |
if ($detailsBlock->getChild('totals')) {
|
200 |
-
$detailsBlock->getChild('totals')->setCustomQuote($
|
201 |
}
|
202 |
$this->renderLayout();
|
203 |
return;
|
@@ -207,60 +261,12 @@ class Kash_Gateway_BbController extends Mage_Core_Controller_Front_Action
|
|
207 |
Mage::getSingleton('checkout/session')->addError(
|
208 |
$this->__('Unable to initialize Kash Gateway Checkout review.')
|
209 |
);
|
|
|
210 |
Mage::logException($e);
|
211 |
}
|
212 |
$this->_redirect('checkout/cart');
|
213 |
}
|
214 |
|
215 |
-
/**
|
216 |
-
* Submit the order
|
217 |
-
*/
|
218 |
-
protected function placeOrder()
|
219 |
-
{
|
220 |
-
try {
|
221 |
-
$this->_initToken();
|
222 |
-
$this->_checkout->place();
|
223 |
-
|
224 |
-
// prepare session to success or cancellation page
|
225 |
-
$session = $this->_getCheckoutSession();
|
226 |
-
$session->clearHelperData();
|
227 |
-
|
228 |
-
// "last successful quote"
|
229 |
-
$quoteId = $this->_getQuote()->getId();
|
230 |
-
$session->setLastQuoteId($quoteId)
|
231 |
-
->setLastSuccessQuoteId($quoteId);
|
232 |
-
|
233 |
-
// an order may be created
|
234 |
-
$order = $this->_checkout->getOrder();
|
235 |
-
$this->invoiceOrder($order);
|
236 |
-
if ($order) {
|
237 |
-
$session->setLastOrderId($order->getId())
|
238 |
-
->setLastRealOrderId($order->getIncrementId());
|
239 |
-
}
|
240 |
-
|
241 |
-
// redirect if Payment specified some URL
|
242 |
-
$url = $this->_checkout->getRedirectUrl();
|
243 |
-
if ($url) {
|
244 |
-
$this->getResponse()->setRedirect($url);
|
245 |
-
return;
|
246 |
-
}
|
247 |
-
$this->_initToken(false); // no need in token anymore
|
248 |
-
return;
|
249 |
-
} catch (Mage_Core_Exception $e) {
|
250 |
-
Mage::helper('checkout')->sendPaymentFailedEmail($this->_getQuote(), $e->getMessage());
|
251 |
-
$this->_getSession()->addError($e->getMessage());
|
252 |
-
$this->_redirect('*/*/review');
|
253 |
-
} catch (Exception $e) {
|
254 |
-
Mage::helper('checkout')->sendPaymentFailedEmail(
|
255 |
-
$this->_getQuote(),
|
256 |
-
$this->__('Unable to place the order.')
|
257 |
-
);
|
258 |
-
$this->_getSession()->addError($this->__('Unable to place the order.'));
|
259 |
-
Mage::logException($e);
|
260 |
-
$this->_redirect('*/*/review');
|
261 |
-
}
|
262 |
-
}
|
263 |
-
|
264 |
/**
|
265 |
* Auto invoice for order
|
266 |
*
|
@@ -268,6 +274,7 @@ class Kash_Gateway_BbController extends Mage_Core_Controller_Front_Action
|
|
268 |
*/
|
269 |
protected function invoiceOrder($order)
|
270 |
{
|
|
|
271 |
if ($order->getState() == Mage_Sales_Model_Order::STATE_NEW) {
|
272 |
try {
|
273 |
if (!$order->canInvoice()) {
|
@@ -290,6 +297,8 @@ class Kash_Gateway_BbController extends Mage_Core_Controller_Front_Action
|
|
290 |
|
291 |
$transactionSave->save();
|
292 |
} catch (Exception $e) {
|
|
|
|
|
293 |
$order->addStatusHistoryComment('Kash Gateway: Exception occurred during automatically Invoice action. Exception message: ' . $e->getMessage(), false);
|
294 |
$order->save();
|
295 |
}
|
@@ -310,6 +319,7 @@ class Kash_Gateway_BbController extends Mage_Core_Controller_Front_Action
|
|
310 |
if (false === $setToken) {
|
311 |
// security measure for avoid unsetting token twice
|
312 |
if (!$this->_getSession()->getBBCheckoutToken()) {
|
|
|
313 |
Mage::throwException($this->__('Payment Kash Gateway Checkout Token does not exist.'));
|
314 |
}
|
315 |
$this->_getSession()->unsBBCheckoutToken();
|
@@ -320,6 +330,7 @@ class Kash_Gateway_BbController extends Mage_Core_Controller_Front_Action
|
|
320 |
}
|
321 |
if ($setToken = $this->getRequest()->getParam('x_reference')) {
|
322 |
if ($setToken !== $this->_getSession()->getBBCheckoutToken()) {
|
|
|
323 |
Mage::throwException($this->__('Wrong Payment Kash Gateway Checkout Token specified.'));
|
324 |
}
|
325 |
} else {
|
@@ -388,7 +399,9 @@ class Kash_Gateway_BbController extends Mage_Core_Controller_Front_Action
|
|
388 |
{
|
389 |
$quote = $this->_getQuote();
|
390 |
if (!$callback && (!$quote->hasItems() || $quote->getHasError())) {
|
391 |
-
|
|
|
|
|
392 |
Mage::log(Mage::helper('kash_gateway')->__('Unable to initialize Kash Gateway Checkout.'));
|
393 |
return null;
|
394 |
}
|
@@ -407,6 +420,7 @@ class Kash_Gateway_BbController extends Mage_Core_Controller_Front_Action
|
|
407 |
* Make params for Payment BB
|
408 |
*/
|
409 |
protected function getPaymentRequest(){
|
|
|
410 |
$this->_initCheckout();
|
411 |
|
412 |
if ($this->_getQuote()->getIsMultiShipping()) {
|
@@ -446,4 +460,4 @@ class Kash_Gateway_BbController extends Mage_Core_Controller_Front_Action
|
|
446 |
$params = $this->_checkout->start();
|
447 |
return $params;
|
448 |
}
|
449 |
-
}
|
43 |
*/
|
44 |
protected $_configMethod = Kash_Gateway_Model_Config::METHOD_GATEWAY_KASH;
|
45 |
|
46 |
+
protected $api = null;
|
47 |
+
|
48 |
/**
|
49 |
* Instantiate config
|
50 |
*/
|
52 |
{
|
53 |
parent::_construct();
|
54 |
$this->_config = Mage::getModel($this->_configType, array($this->_configMethod));
|
55 |
+
$this->api = Mage::getModel('kash_gateway/api_bb')->setConfigObject($this->_config);
|
56 |
}
|
57 |
|
58 |
/**
|
59 |
* Get form for requesting form
|
60 |
*/
|
61 |
public function startAction(){
|
62 |
+
$this->api->log('quote '.$this->_getQuote()->getId().': startAction()');
|
63 |
$paymentParams = $this->getPaymentRequest();
|
64 |
if(!$paymentParams){
|
65 |
return;
|
78 |
*/
|
79 |
public function getRequestAction()
|
80 |
{
|
81 |
+
$this->api->log('quote '.$this->_getQuote()->getId().': getRequestAction()');
|
82 |
try {
|
83 |
$paymentParams = $this->getPaymentRequest();
|
84 |
if(!$paymentParams){
|
99 |
} catch (Mage_Core_Exception $e) {
|
100 |
$this->_getCheckoutSession()->addError($e->getMessage());
|
101 |
} catch (Exception $e) {
|
102 |
+
$this->api->log($e);
|
103 |
$this->_getCheckoutSession()->addError($this->__('Unable to start BB Checkout.'));
|
104 |
Mage::logException($e);
|
105 |
}
|
112 |
*/
|
113 |
public function cancelAction()
|
114 |
{
|
115 |
+
$this->api->log('x_reference '.$this->_getQuote()->getReservedOrderId().': cancelAction()');
|
116 |
$this->_initToken(false);
|
117 |
$this->_redirect('checkout/cart');
|
118 |
}
|
123 |
public function callbackAction()
|
124 |
{
|
125 |
$param = Mage::app()->getRequest()->getParam('x_reference');
|
126 |
+
$this->api->log('x_reference '.$param.': callbackAction()');
|
127 |
+
|
128 |
+
$quote = Mage::getModel('sales/quote')->load($param, 'reserved_order_id');
|
129 |
+
$this->_quote = $quote;
|
130 |
|
131 |
$this->_config->setStoreId($this->_getQuote()->getStoreId());
|
132 |
$this->_checkout = Mage::getSingleton($this->_checkoutType, array(
|
133 |
'config' => $this->_config,
|
134 |
+
'quote' => $quote,
|
135 |
));
|
136 |
+
$this->api->log('x_reference '.$this->_getQuote()->getReservedOrderId().': quote is active? '.$quote->getIsActive());
|
137 |
|
138 |
$params = Mage::app()->getRequest()->getParams();
|
139 |
$this->_checkout->setParams($params);
|
140 |
|
141 |
+
$this->_checkout->loginUser();
|
142 |
+
|
143 |
+
if ($this->_checkout->checkSignature() && $this->_checkout->checkResult() && $quote->getIsActive()) {
|
144 |
+
$connection = Mage::getSingleton('core/resource')->getConnection('core_write');
|
145 |
+
try {
|
146 |
+
$connection->beginTransaction();
|
147 |
+
|
148 |
+
$this->_checkout->place();
|
149 |
+
$order = $this->_checkout->getOrder();
|
150 |
+
|
151 |
+
if ($order->getIncrementId() == $param) {
|
152 |
+
$this->invoiceOrder($order);
|
153 |
+
$connection->commit();
|
154 |
+
}
|
155 |
+
else {
|
156 |
+
$this->api->log('x_reference '.$param.': The new order id is not the expected order id! Rolling back');
|
157 |
+
$connection->rollback();
|
158 |
+
}
|
159 |
+
} catch (Exception $e) {
|
160 |
+
$this->api->log('x_reference '.$param. ': Error, rolling back');
|
161 |
+
$this->api->log($e);
|
162 |
+
$connection->rollback();
|
163 |
+
}
|
164 |
+
}
|
165 |
+
else {
|
166 |
+
$this->api->log('x_reference '.$param.': Checks failed, will not try and create order');
|
167 |
}
|
168 |
}
|
169 |
|
172 |
*/
|
173 |
public function completeAction()
|
174 |
{
|
175 |
+
$this->api->log('completeAction()');
|
176 |
try {
|
177 |
+
if (!$this->_initCheckout(true)) {
|
178 |
$this->getResponse()->setRedirect(Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB));
|
179 |
return;
|
180 |
}
|
181 |
if (!$this->_checkout->checkSignature()) {
|
182 |
+
$this->api->log('x_reference '.$this->_checkout->getParams('x_reference').': All requests and responses must be signed/verified using HMAC-SHA256');
|
183 |
Mage::getSingleton('checkout/session')->addError('Not valid signature');
|
184 |
$this->_redirect('checkout/cart');
|
185 |
return;
|
186 |
}
|
187 |
if (!$this->_checkout->checkResult()) {
|
188 |
+
$this->api->log('x_reference '.$this->_checkout->getParams('x_reference').': Result not completed');
|
189 |
Mage::getSingleton('checkout/session')->addError('Kash Gateway not completed');
|
190 |
$this->_redirect('checkout/cart');
|
191 |
return;
|
192 |
}
|
193 |
|
194 |
+
|
195 |
+
$this->_initToken();
|
196 |
+
|
197 |
+
// prepare session to success or cancellation page
|
198 |
+
$session = $this->_getCheckoutSession();
|
199 |
+
$session->clearHelperData();
|
200 |
+
|
201 |
+
// store the last successful quote and order so the correct order can be displayed on
|
202 |
+
// on the next screen. Get the Quote and Order from the db using xref, since it's not
|
203 |
+
// in the session once callback completes.
|
204 |
+
$xref = $this->_checkout->getParams('x_reference');
|
205 |
+
$quote = Mage::getModel('sales/quote')->load($xref, 'reserved_order_id');
|
206 |
+
$session->setLastQuoteId($quote->getId())
|
207 |
+
->setLastSuccessQuoteId($quote->getId());
|
208 |
+
|
209 |
+
//get the order that was created and store the IDs for use in info pages
|
210 |
+
$order = Mage::getModel('sales/order')->loadByIncrementId($xref);
|
211 |
+
$session->setLastOrderId($order->getId())
|
212 |
+
->setLastRealOrderId($order->getIncrementId());
|
213 |
+
|
214 |
+
// no need in token anymore
|
215 |
+
$this->_initToken(false);
|
216 |
+
|
217 |
if (!$this->_checkout->canSkipOrderReviewStep()) {
|
218 |
$this->_redirect('checkout/onepage/success');
|
219 |
} else {
|
223 |
} catch (Mage_Core_Exception $e) {
|
224 |
Mage::getSingleton('checkout/session')->addError($e->getMessage());
|
225 |
} catch (Exception $e) {
|
226 |
+
$this->api->log('x_reference '.$xref.': Could not complete action');
|
227 |
+
$this->api->log($e);
|
228 |
Mage::getSingleton('checkout/session')->addError($this->__('Unable to process Kash Gateway Checkout approval.'));
|
229 |
Mage::logException($e);
|
230 |
}
|
240 |
$session = $this->_getCheckoutSession();
|
241 |
// "last successful quote"
|
242 |
$quoteId = $session->getLastQuoteId();
|
243 |
+
$quote = Mage::getModel('sales/quote')->load($quoteId);
|
244 |
|
245 |
$this->loadLayout();
|
246 |
$this->_initLayoutMessages('kash_gateway/session');
|
247 |
$reviewBlock = $this->getLayout()->getBlock('gateway.kash.review');
|
248 |
+
$reviewBlock->setQuote($quote);
|
249 |
+
$detailsBlock = $reviewBlock->getChild('details')->setCustomQuote($quote);
|
250 |
if ($reviewBlock->getChild('shipping_method')) {
|
251 |
+
$reviewBlock->getChild('shipping_method')->setCustomQuote($quote);
|
252 |
}
|
253 |
if ($detailsBlock->getChild('totals')) {
|
254 |
+
$detailsBlock->getChild('totals')->setCustomQuote($quote);
|
255 |
}
|
256 |
$this->renderLayout();
|
257 |
return;
|
261 |
Mage::getSingleton('checkout/session')->addError(
|
262 |
$this->__('Unable to initialize Kash Gateway Checkout review.')
|
263 |
);
|
264 |
+
$this->api->log('Could not review order');
|
265 |
Mage::logException($e);
|
266 |
}
|
267 |
$this->_redirect('checkout/cart');
|
268 |
}
|
269 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
270 |
/**
|
271 |
* Auto invoice for order
|
272 |
*
|
274 |
*/
|
275 |
protected function invoiceOrder($order)
|
276 |
{
|
277 |
+
$this->api->log('order '.$order->getIncrementId().': Invoicing order');
|
278 |
if ($order->getState() == Mage_Sales_Model_Order::STATE_NEW) {
|
279 |
try {
|
280 |
if (!$order->canInvoice()) {
|
297 |
|
298 |
$transactionSave->save();
|
299 |
} catch (Exception $e) {
|
300 |
+
$this->api->log('order '.$order->getIncrementId().': Could not invoice order.');
|
301 |
+
$this->api->log($e);
|
302 |
$order->addStatusHistoryComment('Kash Gateway: Exception occurred during automatically Invoice action. Exception message: ' . $e->getMessage(), false);
|
303 |
$order->save();
|
304 |
}
|
319 |
if (false === $setToken) {
|
320 |
// security measure for avoid unsetting token twice
|
321 |
if (!$this->_getSession()->getBBCheckoutToken()) {
|
322 |
+
$this->api->log('checkout token does not exist');
|
323 |
Mage::throwException($this->__('Payment Kash Gateway Checkout Token does not exist.'));
|
324 |
}
|
325 |
$this->_getSession()->unsBBCheckoutToken();
|
330 |
}
|
331 |
if ($setToken = $this->getRequest()->getParam('x_reference')) {
|
332 |
if ($setToken !== $this->_getSession()->getBBCheckoutToken()) {
|
333 |
+
$this->api->log('wrong token');
|
334 |
Mage::throwException($this->__('Wrong Payment Kash Gateway Checkout Token specified.'));
|
335 |
}
|
336 |
} else {
|
399 |
{
|
400 |
$quote = $this->_getQuote();
|
401 |
if (!$callback && (!$quote->hasItems() || $quote->getHasError())) {
|
402 |
+
$this->api->log('x_reference '.$quote->getReservedOrderId().': Unable to initialize Checkout');
|
403 |
+
$this->api->log($quote->hasItems());
|
404 |
+
$this->api->log($quote->getHasError());
|
405 |
Mage::log(Mage::helper('kash_gateway')->__('Unable to initialize Kash Gateway Checkout.'));
|
406 |
return null;
|
407 |
}
|
420 |
* Make params for Payment BB
|
421 |
*/
|
422 |
protected function getPaymentRequest(){
|
423 |
+
$this->api->log('quote '.$this->_getQuote()->getId().': setting payment request');
|
424 |
$this->_initCheckout();
|
425 |
|
426 |
if ($this->_getQuote()->getIsMultiShipping()) {
|
460 |
$params = $this->_checkout->start();
|
461 |
return $params;
|
462 |
}
|
463 |
+
}
|
app/code/local/Kash/Gateway/etc/config.xml
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
<config>
|
3 |
<modules>
|
4 |
<Kash_Gateway>
|
5 |
-
<version>0.
|
6 |
</Kash_Gateway>
|
7 |
</modules>
|
8 |
<global>
|
@@ -105,6 +105,33 @@
|
|
105 |
</kash_gateway>
|
106 |
</observers>
|
107 |
</sales_quote_collect_totals_before>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
</events>
|
109 |
</frontend>
|
110 |
</config>
|
2 |
<config>
|
3 |
<modules>
|
4 |
<Kash_Gateway>
|
5 |
+
<version>0.2.3</version>
|
6 |
</Kash_Gateway>
|
7 |
</modules>
|
8 |
<global>
|
105 |
</kash_gateway>
|
106 |
</observers>
|
107 |
</sales_quote_collect_totals_before>
|
108 |
+
<checkout_onepage_controller_success_action>
|
109 |
+
<observers>
|
110 |
+
<kash_gateway>
|
111 |
+
<type>model</type>
|
112 |
+
<class>kash_gateway/observer</class>
|
113 |
+
<method>sendReport</method>
|
114 |
+
</kash_gateway>
|
115 |
+
</observers>
|
116 |
+
</checkout_onepage_controller_success_action>
|
117 |
+
<sales_order_save_after>
|
118 |
+
<observers>
|
119 |
+
<kash_gateway>
|
120 |
+
<type>model</type>
|
121 |
+
<class>kash_gateway/observer</class>
|
122 |
+
<method>logOrderSave</method>
|
123 |
+
</kash_gateway>
|
124 |
+
</observers>
|
125 |
+
</sales_order_save_after>
|
126 |
+
<sales_convert_quote_to_order>
|
127 |
+
<observers>
|
128 |
+
<kash_gateway>
|
129 |
+
<type>model</type>
|
130 |
+
<class>kash_gateway/observer</class>
|
131 |
+
<method>logQuoteToOrder</method>
|
132 |
+
</kash_gateway>
|
133 |
+
</observers>
|
134 |
+
</sales_convert_quote_to_order>
|
135 |
</events>
|
136 |
</frontend>
|
137 |
</config>
|
app/code/local/Kash/Gateway/etc/system.xml
CHANGED
@@ -103,6 +103,16 @@
|
|
103 |
<show_in_store>1</show_in_store>
|
104 |
<frontend_class>validate-number</frontend_class>
|
105 |
</sort_order>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
<model>
|
107 |
</model>
|
108 |
</fields>
|
103 |
<show_in_store>1</show_in_store>
|
104 |
<frontend_class>validate-number</frontend_class>
|
105 |
</sort_order>
|
106 |
+
<x_test translate="label comment">
|
107 |
+
<label>Test Mode</label>
|
108 |
+
<frontend_type>select</frontend_type>
|
109 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
110 |
+
<sort_order>200</sort_order>
|
111 |
+
<show_in_default>1</show_in_default>
|
112 |
+
<show_in_website>1</show_in_website>
|
113 |
+
<show_in_store>1</show_in_store>
|
114 |
+
<comment>While in test mode, Kash Gateway won't actually charge anybody and you can use any username and password to testing things out. However, please note that orders will still be created on Magento side.</comment>
|
115 |
+
</x_test>
|
116 |
<model>
|
117 |
</model>
|
118 |
</fields>
|
app/design/frontend/base/default/layout/kash/gateway.xml
CHANGED
@@ -25,9 +25,6 @@
|
|
25 |
<kash_gateway_bb_start>
|
26 |
<remove name="before_body_end"/>
|
27 |
<reference name="head">
|
28 |
-
<action method="addJs">
|
29 |
-
<script>lib/jquery/jquery-1.10.2.min.js</script>
|
30 |
-
</action>
|
31 |
<action method="addCss"><stylesheet>css/kash/start.css</stylesheet></action>
|
32 |
</reference>
|
33 |
<reference name="root">
|
25 |
<kash_gateway_bb_start>
|
26 |
<remove name="before_body_end"/>
|
27 |
<reference name="head">
|
|
|
|
|
|
|
28 |
<action method="addCss"><stylesheet>css/kash/start.css</stylesheet></action>
|
29 |
</reference>
|
30 |
<reference name="root">
|
app/design/frontend/base/default/template/kash/container.phtml
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
<script type="text/javascript">
|
2 |
-
|
3 |
-
|
4 |
-
}
|
5 |
</script>
|
1 |
<script type="text/javascript">
|
2 |
+
window.onload = function () {
|
3 |
+
document.getElementsByTagName('form')[0].submit();
|
4 |
+
};
|
5 |
</script>
|
package.xml
CHANGED
@@ -1,22 +1,28 @@
|
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>kash_gateway</name>
|
4 |
-
<version>0.
|
5 |
<stability>stable</stability>
|
6 |
<license>MITL</license>
|
7 |
<channel>community</channel>
|
8 |
<extends/>
|
9 |
<summary>Payment gateway that allows customers in the US to make payment via Direct Debit or Credit Card for just 0.5%.</summary>
|
10 |
-
<description
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
<compatible/>
|
21 |
<dependencies><required><php><min>5.4.45</min><max>5.6.15</max></php></required></dependencies>
|
22 |
</package>
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>kash_gateway</name>
|
4 |
+
<version>0.2.3</version>
|
5 |
<stability>stable</stability>
|
6 |
<license>MITL</license>
|
7 |
<channel>community</channel>
|
8 |
<extends/>
|
9 |
<summary>Payment gateway that allows customers in the US to make payment via Direct Debit or Credit Card for just 0.5%.</summary>
|
10 |
+
<description><a href="http://www.withkash.com">Kash</a> payment gateway allows you to accept payments for just 0.5% fee per transaction.<br />
|
11 |
+
<br />
|
12 |
+
- Accept Direct Debit payments<br />
|
13 |
+
- Accept credit card payments as well (you could either include or exclude the credit card fee in the total)<br />
|
14 |
+
- No monthly fee<br />
|
15 |
+
- No chargebacks on Direct Debit payments<br />
|
16 |
+
- Daily clearance (money deposited to your bank by next business day)<br />
|
17 |
+
<br />
|
18 |
+
You will need a Kash account in order to use this gateway. Please contact info@withkash.com for any questions.<br />
|
19 |
+
<br />
|
20 |
+
Direct Debit payment works by having the customers use their bank account to pay. Your customers can have the option to pay using a credit card as well. You can choose to either charge the credit card processing fee to the customer, or pay for the fee yourself like you do currently.</description>
|
21 |
+
<notes>v0.2.2 - Initial Release</notes>
|
22 |
+
<authors><author><name>Kash Corp.</name><user>Kash Corp</user><email>info@withkash.com</email></author></authors>
|
23 |
+
<date>2015-12-08</date>
|
24 |
+
<time>23:53:50</time>
|
25 |
+
<contents><target name="mageskin"><dir name="frontend"><dir name="base"><dir name="default"><dir name="css"><dir name="kash"><file name="lightwindow.css" hash="543637b1312fd4b72696f18c14fc7a54"/><file name="start.css" hash="d310d178769035d366ebb2caff9bd4a3"/><file name="._lightwindow.css" hash="6bac7309b1e370cf137d882ba90d6510"/></dir></dir><dir name="js"><dir name="kash"><file name="lightwindow.js" hash="d94daf37446ba2fd00222de24c7cf9b6"/><file name="._lightwindow.js" hash="6bac7309b1e370cf137d882ba90d6510"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Kash_Gateway.xml" hash="03365c54da611a023ea2a12c6404c455"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><dir name="kash"><file name="gateway.xml" hash="62ce90320a5d09cc8334e512c3cda3b3"/></dir></dir><dir name="template"><dir name="kash"><file name="container.phtml" hash="9dafeab90d16b221ab8684990ef62ec3"/><file name="form.phtml" hash="0b4b05f427474b08d1c52cfc09fc3485"/><file name="js.phtml" hash="3a1b1a96fd25b4035f41dbe95633f229"/><dir name="payment"><file name="mark.phtml" hash="96ac85ef2f73ec0953dee53cd3d7d0a7"/><file name="redirect.phtml" hash="9cd530bec26cc5f76ab01cfb57095c32"/><dir name="review"><file name="details.phtml" hash="ff2ad65893e66920a4cc8b098dc397c1"/></dir><file name="review.phtml" hash="ef1d435a2bc0e9daff56594a715bed1a"/></dir></dir></dir></dir></dir></dir><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="kash"><dir name="info"><file name="default.phtml" hash="79bcf1003e40c03ec35c383ec4ca5236"/></dir></dir></dir></dir></dir></dir></target><target name="magelocal"><dir name="Kash"><dir name="Gateway"><dir name="Block"><dir name="Adminhtml"><file name="Info.php" hash="186ac575a69755543d649d2174f43474"/><dir name="Sales"><dir name="Order"><file name="Grid.php" hash="757f5028ff98d3c375cf3345675d55b7"/></dir></dir></dir><dir name="Form"><file name="Bb.php" hash="2516cb64469800cfc450710250317d72"/></dir><dir name="Review"><file name="Details.php" hash="9a077c6688f913bd4f9fee74fad68b7e"/></dir><file name="Review.php" hash="a2a24914d577262188c491898c77307e"/></dir><dir name="Helper"><file name="Checkout.php" hash="89863d74391a81e7336073a8c9634ce8"/><file name="Data.php" hash="cc0eb77c1be47e1d4e846033cc2aed9a"/></dir><dir name="Model"><dir name="Api"><file name="Abstract.php" hash="99ed019c3e8e13caf90fa248e608c9ea"/><file name="Bb.php" hash="3cabc71ab5f616b0614fa3d628e9dc4a"/></dir><file name="Cart.php" hash="ced06fca31abf3fbe20e3e2eb430cfea"/><file name="Checkout.php" hash="bed98494d4bb1d93b6e6758555d98450"/><file name="Config.php" hash="5299275ecc589f56c9bc9c9123e39405"/><dir name="Method"><file name="Bb.php" hash="6cd0683fa597d31d830ae7787b0284cd"/></dir><file name="Observer.php" hash="eede09fb15543e8a535820612104e520"/><file name="Session.php" hash="1778fbe493d2ceb81d8a20b58a21ce3c"/></dir><dir name="controllers"><file name="BbController.php" hash="3ab8fcfabbc52474eb7f161fc91c5986"/></dir><dir name="data"><dir name="kash_gateway_setup"><file name="data-install-0.0.1.php" hash="5fe91e15bc5e6269eadcc50f8991250a"/><file name="data-upgrade-0.0.1-0.0.2.php" hash="632331f77e2238438e1bddfe4c2b82bf"/></dir></dir><dir name="etc"><file name="config.xml" hash="9538e1037a44f4280726f537f0a9d3e5"/><file name="system.xml" hash="3667ceed76bc0a905af96e7b4adbf2b0"/></dir><dir name="sql"><dir name="kash_gateway_setup"><file name="install-0.0.1.php" hash="9ecb52ba48345cdbee9ce0fd92d2aff9"/></dir></dir></dir></dir></target></contents>
|
26 |
<compatible/>
|
27 |
<dependencies><required><php><min>5.4.45</min><max>5.6.15</max></php></required></dependencies>
|
28 |
</package>
|
skin/frontend/base/default/css/kash/lightwindow.css
CHANGED
@@ -58,6 +58,9 @@
|
|
58 |
-webkit-box-sizing: content-box;
|
59 |
-moz-box-sizing: content-box;
|
60 |
box-sizing: content-box;
|
|
|
|
|
|
|
61 |
}
|
62 |
|
63 |
#lightwindow_loading {
|
58 |
-webkit-box-sizing: content-box;
|
59 |
-moz-box-sizing: content-box;
|
60 |
box-sizing: content-box;
|
61 |
+
/* needed for iOS scroller */
|
62 |
+
-webkit-overflow-scrolling: touch;
|
63 |
+
overflow-y: scroll;
|
64 |
}
|
65 |
|
66 |
#lightwindow_loading {
|
skin/frontend/base/default/js/kash/lightwindow.js
CHANGED
@@ -585,10 +585,14 @@ lightwindow.prototype = {
|
|
585 |
// Empty the contents
|
586 |
$('lightwindow_contents').innerHTML = '';
|
587 |
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
|
|
|
|
|
|
|
|
592 |
|
593 |
if (!this.windowActive) {
|
594 |
$('lightwindow_data_slide_inner').setStyle({
|
585 |
// Empty the contents
|
586 |
$('lightwindow_contents').innerHTML = '';
|
587 |
|
588 |
+
var userAgent = navigator.userAgent || navigator.vendor || window.opera;
|
589 |
+
if (!userAgent.match(/iPad|iPhone|iPod/i)) {
|
590 |
+
// Reset the scroll bars, except on iOS
|
591 |
+
$('lightwindow_contents').setStyle({
|
592 |
+
overflow: 'hidden'
|
593 |
+
});
|
594 |
+
}
|
595 |
+
|
596 |
|
597 |
if (!this.windowActive) {
|
598 |
$('lightwindow_data_slide_inner').setStyle({
|