Version Notes
v0.2.6 - Support Online Refund
Download this release
Release Info
| Developer | Kash Corp. |
| Extension | kash_gateway |
| Version | 0.2.9 |
| Comparing to | |
| See all releases | |
Code changes from version 0.2.5 to 0.2.9
- app/code/local/Kash/Gateway/Helper/Checkout.php +0 -67
- app/code/local/Kash/Gateway/Helper/Data.php +22 -4
- app/code/local/Kash/Gateway/Model/Api/Bb.php +4 -56
- app/code/local/Kash/Gateway/Model/Checkout.php +20 -14
- app/code/local/Kash/Gateway/Model/Config.php +2 -2
- app/code/local/Kash/Gateway/Model/Logger.php +59 -0
- app/code/local/Kash/Gateway/Model/Observer.php +8 -15
- app/code/local/Kash/Gateway/Model/{Method/Bb.php → Offsite.php} +33 -8
- app/code/local/Kash/Gateway/controllers/{BbController.php → OffsiteController.php} +50 -39
- app/code/local/Kash/Gateway/etc/config.xml +66 -13
- app/code/local/Kash/Gateway/kashlib/KashApi.php +78 -0
- app/design/frontend/base/default/layout/kash/gateway.xml +4 -4
- app/etc/modules/Kash_Gateway.xml +6 -0
- package.xml +146 -7
app/code/local/Kash/Gateway/Helper/Checkout.php
DELETED
|
@@ -1,67 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
|
| 3 |
-
/**
|
| 4 |
-
* Checkout helper
|
| 5 |
-
*/
|
| 6 |
-
class Kash_Gateway_Helper_Checkout extends Mage_Core_Helper_Abstract
|
| 7 |
-
{
|
| 8 |
-
/**
|
| 9 |
-
* Restore last active quote based on checkout session
|
| 10 |
-
*
|
| 11 |
-
* @return bool True if quote restored successfully, false otherwise
|
| 12 |
-
*/
|
| 13 |
-
public function restoreQuote()
|
| 14 |
-
{
|
| 15 |
-
$order = $this->_getCheckoutSession()->getLastRealOrder();
|
| 16 |
-
if ($order->getId()) {
|
| 17 |
-
$quote = $this->_getQuote($order->getQuoteId());
|
| 18 |
-
if ($quote->getId()) {
|
| 19 |
-
$quote->setIsActive(1)
|
| 20 |
-
->setReservedOrderId(null)
|
| 21 |
-
->save();
|
| 22 |
-
$this->_getCheckoutSession()
|
| 23 |
-
->replaceQuote($quote)
|
| 24 |
-
->unsLastRealOrderId();
|
| 25 |
-
return true;
|
| 26 |
-
}
|
| 27 |
-
}
|
| 28 |
-
return false;
|
| 29 |
-
}
|
| 30 |
-
|
| 31 |
-
/**
|
| 32 |
-
* Cancel last placed order with specified comment message
|
| 33 |
-
*
|
| 34 |
-
* @param string $comment Comment appended to order history
|
| 35 |
-
* @return bool True if order cancelled, false otherwise
|
| 36 |
-
*/
|
| 37 |
-
public function cancelCurrentOrder($comment)
|
| 38 |
-
{
|
| 39 |
-
$order = $this->_getCheckoutSession()->getLastRealOrder();
|
| 40 |
-
if ($order->getId() && $order->getState() != Mage_Sales_Model_Order::STATE_CANCELED) {
|
| 41 |
-
$order->registerCancellation($comment)->save();
|
| 42 |
-
return true;
|
| 43 |
-
}
|
| 44 |
-
return false;
|
| 45 |
-
}
|
| 46 |
-
|
| 47 |
-
/**
|
| 48 |
-
* Return checkout session instance
|
| 49 |
-
*
|
| 50 |
-
* @return Mage_Checkout_Model_Session
|
| 51 |
-
*/
|
| 52 |
-
protected function _getCheckoutSession()
|
| 53 |
-
{
|
| 54 |
-
return Mage::getSingleton('checkout/session');
|
| 55 |
-
}
|
| 56 |
-
|
| 57 |
-
/**
|
| 58 |
-
* Return sales quote instance for specified ID
|
| 59 |
-
*
|
| 60 |
-
* @param int $quoteId Quote identifier
|
| 61 |
-
* @return Mage_Sales_Model_Quote
|
| 62 |
-
*/
|
| 63 |
-
protected function _getQuote($quoteId)
|
| 64 |
-
{
|
| 65 |
-
return Mage::getModel('sales/quote')->load($quoteId);
|
| 66 |
-
}
|
| 67 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/local/Kash/Gateway/Helper/Data.php
CHANGED
|
@@ -1,10 +1,28 @@
|
|
| 1 |
<?php
|
| 2 |
|
| 3 |
/**
|
| 4 |
-
*
|
|
|
|
| 5 |
*
|
| 6 |
-
*
|
|
|
|
| 7 |
*/
|
| 8 |
-
class Kash_Gateway_Helper_Data extends Mage_Core_Helper_Abstract
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
<?php
|
| 2 |
|
| 3 |
/**
|
| 4 |
+
* This is a special Helper class that gets loaded if Mage::helper() asks only
|
| 5 |
+
* for the namespace. E.g. Mage::helper('kash_gateway')
|
| 6 |
*
|
| 7 |
+
* Mage_Core_Model_Config::getHelperClassName() will automatically change the
|
| 8 |
+
* requested 'kash_gateway' to 'kash_gateway/data'.
|
| 9 |
*/
|
| 10 |
+
class Kash_Gateway_Helper_Data extends Mage_Core_Helper_Abstract
|
| 11 |
+
{
|
| 12 |
+
/**
|
| 13 |
+
* Helper function to retrieve the logger.
|
| 14 |
+
* Use it via `Mage::helper('kash_gateway')->logger()`
|
| 15 |
+
*/
|
| 16 |
+
public function logger()
|
| 17 |
+
{
|
| 18 |
+
$config = $this->config();
|
| 19 |
+
$logger = Mage::getModel('kash_gateway/logger', array($config->x_shop_name));
|
| 20 |
+
return $logger;
|
| 21 |
+
}
|
| 22 |
|
| 23 |
+
public function config()
|
| 24 |
+
{
|
| 25 |
+
$config = Mage::getModel('kash_gateway/config', array(Kash_Gateway_Model_Config::METHOD_GATEWAY_KASH));
|
| 26 |
+
return $config;
|
| 27 |
+
}
|
| 28 |
+
}
|
app/code/local/Kash/Gateway/Model/Api/Bb.php
CHANGED
|
@@ -115,18 +115,6 @@ class Kash_Gateway_Model_Api_Bb extends Kash_Gateway_Model_Api_Abstract
|
|
| 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 |
*
|
|
@@ -140,14 +128,15 @@ class Kash_Gateway_Model_Api_Bb extends Kash_Gateway_Model_Api_Abstract
|
|
| 140 |
$request = $this->_importAddresses($request);
|
| 141 |
|
| 142 |
$request['x_test'] = ($this->getXTest() === '1') ? 'true' : 'false';
|
| 143 |
-
$request['x_version'] = '
|
| 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 |
-
$
|
|
|
|
| 151 |
return $request;
|
| 152 |
}
|
| 153 |
|
|
@@ -163,7 +152,7 @@ class Kash_Gateway_Model_Api_Bb extends Kash_Gateway_Model_Api_Abstract
|
|
| 163 |
ksort($request);
|
| 164 |
$signature = '';
|
| 165 |
foreach ($request as $key => $val) {
|
| 166 |
-
if ($key === 'x_signature') {
|
| 167 |
continue;
|
| 168 |
}
|
| 169 |
$signature .= $key . $val;
|
|
@@ -219,12 +208,6 @@ class Kash_Gateway_Model_Api_Bb extends Kash_Gateway_Model_Api_Abstract
|
|
| 219 |
return $value;
|
| 220 |
}
|
| 221 |
|
| 222 |
-
protected function getXShopName()
|
| 223 |
-
{
|
| 224 |
-
$value = $this->_getDataOrConfig('x_shop_name');
|
| 225 |
-
return $value;
|
| 226 |
-
}
|
| 227 |
-
|
| 228 |
protected function getXTest()
|
| 229 |
{
|
| 230 |
$value = $this->_getDataOrConfig('x_test');
|
|
@@ -241,39 +224,4 @@ class Kash_Gateway_Model_Api_Bb extends Kash_Gateway_Model_Api_Abstract
|
|
| 241 |
{
|
| 242 |
return $this->_getDataOrConfig('x_show_gateway_ref');
|
| 243 |
}
|
| 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 |
}
|
| 115 |
'x_customer_shipping_phone' => 'telephone',
|
| 116 |
);
|
| 117 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
/**
|
| 119 |
* Return request for API
|
| 120 |
*
|
| 128 |
$request = $this->_importAddresses($request);
|
| 129 |
|
| 130 |
$request['x_test'] = ($this->getXTest() === '1') ? 'true' : 'false';
|
| 131 |
+
$request['x_version'] = '0.2.9';
|
| 132 |
$request['x_plugin'] = 'magento';
|
| 133 |
|
| 134 |
$date = Zend_Date::now();
|
| 135 |
$request['x_timestamp'] = $date->getIso();
|
| 136 |
$request['x_signature'] = $this->getSignature($request, $this->getHmacKey());
|
| 137 |
|
| 138 |
+
$logger = Mage::helper('kash_gateway')->logger();
|
| 139 |
+
$logger->log('x_reference '.$request['x_reference'].': callSetBBCheckout()');
|
| 140 |
return $request;
|
| 141 |
}
|
| 142 |
|
| 152 |
ksort($request);
|
| 153 |
$signature = '';
|
| 154 |
foreach ($request as $key => $val) {
|
| 155 |
+
if ($key === 'x_signature' || substr($key, 0, 2) !== "x_") {
|
| 156 |
continue;
|
| 157 |
}
|
| 158 |
$signature .= $key . $val;
|
| 208 |
return $value;
|
| 209 |
}
|
| 210 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 211 |
protected function getXTest()
|
| 212 |
{
|
| 213 |
$value = $this->_getDataOrConfig('x_test');
|
| 224 |
{
|
| 225 |
return $this->_getDataOrConfig('x_show_gateway_ref');
|
| 226 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 227 |
}
|
app/code/local/Kash/Gateway/Model/Checkout.php
CHANGED
|
@@ -60,7 +60,7 @@ class Kash_Gateway_Model_Checkout
|
|
| 60 |
*
|
| 61 |
* @var array
|
| 62 |
*/
|
| 63 |
-
protected $
|
| 64 |
|
| 65 |
/**
|
| 66 |
* Customer ID
|
|
@@ -105,9 +105,9 @@ class Kash_Gateway_Model_Checkout
|
|
| 105 |
* @param string $completeUrl - complete payment result
|
| 106 |
* @return $this
|
| 107 |
*/
|
| 108 |
-
public function
|
| 109 |
{
|
| 110 |
-
$this->
|
| 111 |
return $this;
|
| 112 |
}
|
| 113 |
|
|
@@ -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 |
-
$
|
| 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 |
-
$
|
| 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->
|
| 177 |
$this->getApi()->addData(array(
|
| 178 |
'x_url_callback' => $callbackUrl,
|
| 179 |
'x_url_cancel' => $cancelUrl,
|
|
@@ -189,7 +190,7 @@ class Kash_Gateway_Model_Checkout
|
|
| 189 |
$this->getApi()->setBillingAddress($billingAddress);
|
| 190 |
}
|
| 191 |
else {
|
| 192 |
-
$
|
| 193 |
}
|
| 194 |
|
| 195 |
// Set shipping address unless the product is a virtual product
|
|
@@ -372,7 +373,8 @@ class Kash_Gateway_Model_Checkout
|
|
| 372 |
*/
|
| 373 |
protected function _prepareGuestQuote()
|
| 374 |
{
|
| 375 |
-
$
|
|
|
|
| 376 |
$quote = $this->_quote;
|
| 377 |
$quote->setCustomerId(null)
|
| 378 |
->setCustomerEmail($quote->getBillingAddress()->getEmail())
|
|
@@ -410,7 +412,8 @@ class Kash_Gateway_Model_Checkout
|
|
| 410 |
*/
|
| 411 |
protected function _prepareNewCustomerQuote()
|
| 412 |
{
|
| 413 |
-
$
|
|
|
|
| 414 |
$quote = $this->_quote;
|
| 415 |
$billing = $quote->getBillingAddress();
|
| 416 |
$shipping = $quote->isVirtual() ? null : $quote->getShippingAddress();
|
|
@@ -470,7 +473,8 @@ class Kash_Gateway_Model_Checkout
|
|
| 470 |
*/
|
| 471 |
protected function _prepareCustomerQuote()
|
| 472 |
{
|
| 473 |
-
$
|
|
|
|
| 474 |
$quote = $this->_quote;
|
| 475 |
$billing = $quote->getBillingAddress();
|
| 476 |
$shipping = $quote->isVirtual() ? null : $quote->getShippingAddress();
|
|
@@ -510,7 +514,8 @@ class Kash_Gateway_Model_Checkout
|
|
| 510 |
*/
|
| 511 |
protected function _involveNewCustomer()
|
| 512 |
{
|
| 513 |
-
$
|
|
|
|
| 514 |
$customer = $this->_quote->getCustomer();
|
| 515 |
if ($customer->isConfirmationRequired()) {
|
| 516 |
$customer->sendNewAccountEmail('confirmation');
|
|
@@ -655,8 +660,9 @@ class Kash_Gateway_Model_Checkout
|
|
| 655 |
$ruleCoupon->save();
|
| 656 |
return $ruleCoupon->getCouponCode();
|
| 657 |
} catch (Exception $ex) {
|
| 658 |
-
$
|
| 659 |
-
$
|
|
|
|
| 660 |
Mage::logException($ex);
|
| 661 |
}
|
| 662 |
}
|
| 60 |
*
|
| 61 |
* @var array
|
| 62 |
*/
|
| 63 |
+
protected $_callbackUrls = array();
|
| 64 |
|
| 65 |
/**
|
| 66 |
* Customer ID
|
| 105 |
* @param string $completeUrl - complete payment result
|
| 106 |
* @return $this
|
| 107 |
*/
|
| 108 |
+
public function setCallbackUrls($callbackUrl, $cancelUrl, $completeUrl)
|
| 109 |
{
|
| 110 |
+
$this->_callbackUrls = array($callbackUrl, $cancelUrl, $completeUrl);
|
| 111 |
return $this;
|
| 112 |
}
|
| 113 |
|
| 158 |
*/
|
| 159 |
public function start()
|
| 160 |
{
|
| 161 |
+
$logger = Mage::helper('kash_gateway')->logger();
|
| 162 |
+
$logger->log('quote '.$this->_quote->getId().': start()');
|
| 163 |
$this->_quote->collectTotals();
|
| 164 |
|
| 165 |
if (!$this->_quote->getGrandTotal() && !$this->_quote->hasNominalItems()) {
|
| 166 |
+
$logger->log('quote '.$this->_quote->getId().': Error, quote has items, but no amount.');
|
| 167 |
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.'));
|
| 168 |
}
|
| 169 |
|
| 170 |
$this->_quote->reserveOrderId()->save();
|
| 171 |
+
$logger->log('quote '.$this->_quote->getId().' reserved orderId/x_reference '.$this->_quote->getReservedOrderId());
|
| 172 |
|
| 173 |
// prepare API
|
| 174 |
$this->getApi()->setAmount($this->_quote->getGrandTotal())
|
| 175 |
->setCurrencyCode($this->_quote->getBaseCurrencyCode())
|
| 176 |
->setXInvoice($this->_quote->getReservedOrderId());
|
| 177 |
+
list($callbackUrl, $cancelUrl, $completeUrl) = $this->_callbackUrls;
|
| 178 |
$this->getApi()->addData(array(
|
| 179 |
'x_url_callback' => $callbackUrl,
|
| 180 |
'x_url_cancel' => $cancelUrl,
|
| 190 |
$this->getApi()->setBillingAddress($billingAddress);
|
| 191 |
}
|
| 192 |
else {
|
| 193 |
+
$logger->log('x_reference '.$this->_quote->getReservedOrderId().': Could not validate billing address');
|
| 194 |
}
|
| 195 |
|
| 196 |
// Set shipping address unless the product is a virtual product
|
| 373 |
*/
|
| 374 |
protected function _prepareGuestQuote()
|
| 375 |
{
|
| 376 |
+
$logger = Mage::helper('kash_gateway')->logger();
|
| 377 |
+
$logger->log('x_reference '.$this->_quote->getReservedOrderId().': Preparing a quote for a GUEST user.');
|
| 378 |
$quote = $this->_quote;
|
| 379 |
$quote->setCustomerId(null)
|
| 380 |
->setCustomerEmail($quote->getBillingAddress()->getEmail())
|
| 412 |
*/
|
| 413 |
protected function _prepareNewCustomerQuote()
|
| 414 |
{
|
| 415 |
+
$logger = Mage::helper('kash_gateway')->logger();
|
| 416 |
+
$logger->log('x_reference '.$this->_quote->getReservedOrderId().': preparing a new customer quote');
|
| 417 |
$quote = $this->_quote;
|
| 418 |
$billing = $quote->getBillingAddress();
|
| 419 |
$shipping = $quote->isVirtual() ? null : $quote->getShippingAddress();
|
| 473 |
*/
|
| 474 |
protected function _prepareCustomerQuote()
|
| 475 |
{
|
| 476 |
+
$logger = Mage::helper('kash_gateway')->logger();
|
| 477 |
+
$logger->log('x_reference '.$this->_quote->getReservedOrderId().': preparing a quote for an existing customer');
|
| 478 |
$quote = $this->_quote;
|
| 479 |
$billing = $quote->getBillingAddress();
|
| 480 |
$shipping = $quote->isVirtual() ? null : $quote->getShippingAddress();
|
| 514 |
*/
|
| 515 |
protected function _involveNewCustomer()
|
| 516 |
{
|
| 517 |
+
$logger = Mage::helper('kash_gateway')->logger();
|
| 518 |
+
$logger->log('x_reference '.$this->_quote->getReservedOrderId().': involve new customer, send them confirmation email.');
|
| 519 |
$customer = $this->_quote->getCustomer();
|
| 520 |
if ($customer->isConfirmationRequired()) {
|
| 521 |
$customer->sendNewAccountEmail('confirmation');
|
| 660 |
$ruleCoupon->save();
|
| 661 |
return $ruleCoupon->getCouponCode();
|
| 662 |
} catch (Exception $ex) {
|
| 663 |
+
$logger = Mage::helper('kash_gateway')->logger();
|
| 664 |
+
$logger->log('Error: coupon exception');
|
| 665 |
+
$logger->log($ex);
|
| 666 |
Mage::logException($ex);
|
| 667 |
}
|
| 668 |
}
|
app/code/local/Kash/Gateway/Model/Config.php
CHANGED
|
@@ -20,10 +20,10 @@ class Kash_Gateway_Model_Config
|
|
| 20 |
const METHOD_GATEWAY_KASH = 'kash_gateway';
|
| 21 |
|
| 22 |
/**
|
| 23 |
-
* URL for get request
|
| 24 |
* @var string
|
| 25 |
*/
|
| 26 |
-
const REQUEST_GATEWAY_KASH = '
|
| 27 |
|
| 28 |
/**
|
| 29 |
* Discount code
|
| 20 |
const METHOD_GATEWAY_KASH = 'kash_gateway';
|
| 21 |
|
| 22 |
/**
|
| 23 |
+
* URL for get request
|
| 24 |
* @var string
|
| 25 |
*/
|
| 26 |
+
const REQUEST_GATEWAY_KASH = 'kash_gateway/offsite/getRequest';
|
| 27 |
|
| 28 |
/**
|
| 29 |
* Discount code
|
app/code/local/Kash/Gateway/Model/Logger.php
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
class Kash_Gateway_Model_Logger
|
| 4 |
+
{
|
| 5 |
+
protected $logFile = null;
|
| 6 |
+
protected $shopName = '';
|
| 7 |
+
|
| 8 |
+
public function __construct($params = array())
|
| 9 |
+
{
|
| 10 |
+
if ($params) {
|
| 11 |
+
$this->shopName = array_shift($params);
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
$logDir = Mage::getBaseDir("log");
|
| 15 |
+
if (!is_dir($logDir)) {
|
| 16 |
+
mkdir($logDir);
|
| 17 |
+
chmod($logDir, 0750);
|
| 18 |
+
}
|
| 19 |
+
$this->logFile = $logDir . DIRECTORY_SEPARATOR . 'kash.log';
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
//log a message to our kash.log
|
| 23 |
+
public function log($msg)
|
| 24 |
+
{
|
| 25 |
+
file_put_contents($this->logFile, $this->shopName." ".date('c')." ".print_r($msg, true)."\n", FILE_APPEND | LOCK_EX);
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
public function getLog()
|
| 29 |
+
{
|
| 30 |
+
$result = @file_get_contents($this->logFile);
|
| 31 |
+
return $result===FALSE ? date('c')." Could not read kash log" : $result;
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
/**
|
| 35 |
+
* Erase the log file once it's been sent to our server. In case it's been
|
| 36 |
+
* written to while we're sending it back, erase only the first $length
|
| 37 |
+
* characters and leave the rest for next time.
|
| 38 |
+
*/
|
| 39 |
+
public function resetLog($length)
|
| 40 |
+
{
|
| 41 |
+
$file = @fopen($this->logFile, "r+");
|
| 42 |
+
if (!$file) {
|
| 43 |
+
return;
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
if (flock($file, LOCK_EX)) {
|
| 47 |
+
$contents = '';
|
| 48 |
+
while (!feof($file)) {
|
| 49 |
+
$contents .= fread($file, 8192);
|
| 50 |
+
}
|
| 51 |
+
ftruncate($file, 0);
|
| 52 |
+
rewind($file);
|
| 53 |
+
fwrite($file, substr($contents, $length));
|
| 54 |
+
fflush($file);
|
| 55 |
+
flock($file, LOCK_UN);
|
| 56 |
+
}
|
| 57 |
+
fclose($file);
|
| 58 |
+
}
|
| 59 |
+
}
|
app/code/local/Kash/Gateway/Model/Observer.php
CHANGED
|
@@ -65,8 +65,9 @@ class Kash_Gateway_Model_Observer extends Varien_Object
|
|
| 65 |
|
| 66 |
$url = $config->post_url.'/reporting';
|
| 67 |
|
| 68 |
-
$
|
| 69 |
-
$log
|
|
|
|
| 70 |
|
| 71 |
$data = array(
|
| 72 |
'x_account_id' => $config->x_account_id,
|
|
@@ -91,7 +92,7 @@ class Kash_Gateway_Model_Observer extends Varien_Object
|
|
| 91 |
|
| 92 |
//If the server did not return an error, erase the part of the log we just sent.
|
| 93 |
if ($result !== FALSE) {
|
| 94 |
-
$
|
| 95 |
}
|
| 96 |
}
|
| 97 |
|
|
@@ -102,14 +103,10 @@ class Kash_Gateway_Model_Observer extends Varien_Object
|
|
| 102 |
*/
|
| 103 |
public function logOrderSave($observer) {
|
| 104 |
$order = $observer->getOrder();
|
| 105 |
-
|
| 106 |
-
$
|
| 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 |
*
|
|
@@ -118,12 +115,8 @@ class Kash_Gateway_Model_Observer extends Varien_Object
|
|
| 118 |
public function logQuoteToOrder($observer) {
|
| 119 |
$order = $observer->getOrder();
|
| 120 |
$quote = $observer->getQuote();
|
| 121 |
-
|
| 122 |
-
$
|
| 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 |
}
|
| 65 |
|
| 66 |
$url = $config->post_url.'/reporting';
|
| 67 |
|
| 68 |
+
$logger = Mage::helper('kash_gateway')->logger();
|
| 69 |
+
$logger->log("order ".$order->getIncrementId()." paid with: ".$payment);
|
| 70 |
+
$log = $logger->getLog();
|
| 71 |
|
| 72 |
$data = array(
|
| 73 |
'x_account_id' => $config->x_account_id,
|
| 92 |
|
| 93 |
//If the server did not return an error, erase the part of the log we just sent.
|
| 94 |
if ($result !== FALSE) {
|
| 95 |
+
$logger->resetLog(strlen($log));
|
| 96 |
}
|
| 97 |
}
|
| 98 |
|
| 103 |
*/
|
| 104 |
public function logOrderSave($observer) {
|
| 105 |
$order = $observer->getOrder();
|
| 106 |
+
$logger = Mage::helper('kash_gateway')->logger();
|
| 107 |
+
$logger->log('order '.$order->getIncrementId().': was saved, state is: '.$order->getState());
|
|
|
|
|
|
|
|
|
|
| 108 |
}
|
| 109 |
|
|
|
|
| 110 |
/**
|
| 111 |
* Listen for when an a quote is converted to an order and log it
|
| 112 |
*
|
| 115 |
public function logQuoteToOrder($observer) {
|
| 116 |
$order = $observer->getOrder();
|
| 117 |
$quote = $observer->getQuote();
|
| 118 |
+
$logger = Mage::helper('kash_gateway')->logger();
|
| 119 |
+
$logger->log('quote '.$quote->getId().': was converted to order '.$order->getIncrementId());
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
}
|
| 121 |
|
| 122 |
}
|
app/code/local/Kash/Gateway/Model/{Method/Bb.php → Offsite.php}
RENAMED
|
@@ -1,17 +1,16 @@
|
|
| 1 |
<?php
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
* @author Blue Badger <jonathan@badger.blue>
|
| 7 |
-
*/
|
| 8 |
-
class Kash_Gateway_Model_Method_Bb extends Mage_Payment_Model_Method_Abstract
|
| 9 |
{
|
| 10 |
protected $_code = Kash_Gateway_Model_Config::METHOD_GATEWAY_KASH;
|
| 11 |
protected $_formBlockType = 'kash_gateway/form_bb';
|
| 12 |
protected $_infoBlockType = 'kash_gateway/adminhtml_info';
|
| 13 |
|
| 14 |
protected $_canUseInternal = false;
|
|
|
|
|
|
|
| 15 |
|
| 16 |
/**
|
| 17 |
* Config instance
|
|
@@ -64,7 +63,7 @@ class Kash_Gateway_Model_Method_Bb extends Mage_Payment_Model_Method_Abstract
|
|
| 64 |
* Also updates store ID in config object
|
| 65 |
*
|
| 66 |
* @param Mage_Core_Model_Store|int $store
|
| 67 |
-
* @return
|
| 68 |
*/
|
| 69 |
public function setStore($store)
|
| 70 |
{
|
|
@@ -97,7 +96,7 @@ class Kash_Gateway_Model_Method_Bb extends Mage_Payment_Model_Method_Abstract
|
|
| 97 |
*/
|
| 98 |
public function getCheckoutRedirectUrl()
|
| 99 |
{
|
| 100 |
-
return Mage::getUrl('kash_gateway/
|
| 101 |
}
|
| 102 |
|
| 103 |
/**
|
|
@@ -108,4 +107,30 @@ class Kash_Gateway_Model_Method_Bb extends Mage_Payment_Model_Method_Abstract
|
|
| 108 |
return true;
|
| 109 |
}
|
| 110 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
}
|
| 1 |
<?php
|
| 2 |
|
| 3 |
+
require_once(Mage::getModuleDir('kashlib', 'Kash_Gateway').'/kashlib/KashApi.php');
|
| 4 |
+
|
| 5 |
+
class Kash_Gateway_Model_Offsite extends Mage_Payment_Model_Method_Abstract
|
|
|
|
|
|
|
|
|
|
| 6 |
{
|
| 7 |
protected $_code = Kash_Gateway_Model_Config::METHOD_GATEWAY_KASH;
|
| 8 |
protected $_formBlockType = 'kash_gateway/form_bb';
|
| 9 |
protected $_infoBlockType = 'kash_gateway/adminhtml_info';
|
| 10 |
|
| 11 |
protected $_canUseInternal = false;
|
| 12 |
+
protected $_canRefund = true;
|
| 13 |
+
protected $_canRefundInvoicePartial = true;
|
| 14 |
|
| 15 |
/**
|
| 16 |
* Config instance
|
| 63 |
* Also updates store ID in config object
|
| 64 |
*
|
| 65 |
* @param Mage_Core_Model_Store|int $store
|
| 66 |
+
* @return Kash_Gateway_Model_Offsite
|
| 67 |
*/
|
| 68 |
public function setStore($store)
|
| 69 |
{
|
| 96 |
*/
|
| 97 |
public function getCheckoutRedirectUrl()
|
| 98 |
{
|
| 99 |
+
return Mage::getUrl('kash_gateway/offsite/start', array('_secure'=>true));
|
| 100 |
}
|
| 101 |
|
| 102 |
/**
|
| 107 |
return true;
|
| 108 |
}
|
| 109 |
|
| 110 |
+
/**
|
| 111 |
+
* Refund specified amount for payment
|
| 112 |
+
*
|
| 113 |
+
* @param Varien_Object $payment
|
| 114 |
+
* @param float $amount
|
| 115 |
+
*
|
| 116 |
+
* @return Mage_Payment_Model_Abstract
|
| 117 |
+
*/
|
| 118 |
+
public function refund(Varien_Object $payment, $amount)
|
| 119 |
+
{
|
| 120 |
+
$kashTransactionId = $payment->getCreditmemo()->getInvoice()->getTransactionId();
|
| 121 |
+
$logger = Mage::helper('kash_gateway')->logger();
|
| 122 |
+
$logger->log('refunding $' . $amount . ' for ' . $kashTransactionId);
|
| 123 |
+
|
| 124 |
+
$gatewayUrl = $this->_config->post_url;
|
| 125 |
+
$serverKey = $this->_config->server_key;
|
| 126 |
+
$kashApi = new KashApi($gatewayUrl, $serverKey);
|
| 127 |
+
|
| 128 |
+
$result = $kashApi->refund($kashTransactionId, $amount);
|
| 129 |
+
if ($result->statusCode !== 200) {
|
| 130 |
+
Mage::throwException(Mage::helper('kash_gateway')->__($result->body->message));
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
return $this;
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
}
|
app/code/local/Kash/Gateway/controllers/{BbController.php → OffsiteController.php}
RENAMED
|
@@ -1,11 +1,9 @@
|
|
| 1 |
<?php
|
| 2 |
|
| 3 |
/**
|
| 4 |
-
*
|
| 5 |
-
*
|
| 6 |
-
* @author Blue Badger <jonathan@badger.blue>
|
| 7 |
*/
|
| 8 |
-
class
|
| 9 |
{
|
| 10 |
/**
|
| 11 |
* @var Kash_Gateway_Model_Checkout
|
|
@@ -58,8 +56,10 @@ class Kash_Gateway_BbController extends Mage_Core_Controller_Front_Action
|
|
| 58 |
/**
|
| 59 |
* Get form for requesting form
|
| 60 |
*/
|
| 61 |
-
public function startAction()
|
| 62 |
-
|
|
|
|
|
|
|
| 63 |
$paymentParams = $this->getPaymentRequest();
|
| 64 |
if(!$paymentParams){
|
| 65 |
return;
|
|
@@ -78,7 +78,8 @@ class Kash_Gateway_BbController extends Mage_Core_Controller_Front_Action
|
|
| 78 |
*/
|
| 79 |
public function getRequestAction()
|
| 80 |
{
|
| 81 |
-
$
|
|
|
|
| 82 |
try {
|
| 83 |
$paymentParams = $this->getPaymentRequest();
|
| 84 |
if(!$paymentParams){
|
|
@@ -99,7 +100,7 @@ class Kash_Gateway_BbController extends Mage_Core_Controller_Front_Action
|
|
| 99 |
} catch (Mage_Core_Exception $e) {
|
| 100 |
$this->_getCheckoutSession()->addError($e->getMessage());
|
| 101 |
} catch (Exception $e) {
|
| 102 |
-
$
|
| 103 |
$this->_getCheckoutSession()->addError($this->__('Unable to start BB Checkout.'));
|
| 104 |
Mage::logException($e);
|
| 105 |
}
|
|
@@ -112,7 +113,8 @@ class Kash_Gateway_BbController extends Mage_Core_Controller_Front_Action
|
|
| 112 |
*/
|
| 113 |
public function cancelAction()
|
| 114 |
{
|
| 115 |
-
$
|
|
|
|
| 116 |
$this->_initToken(false);
|
| 117 |
$this->_redirect('checkout/cart');
|
| 118 |
}
|
|
@@ -123,7 +125,8 @@ class Kash_Gateway_BbController extends Mage_Core_Controller_Front_Action
|
|
| 123 |
public function callbackAction()
|
| 124 |
{
|
| 125 |
$param = Mage::app()->getRequest()->getParam('x_reference');
|
| 126 |
-
$
|
|
|
|
| 127 |
|
| 128 |
$quote = Mage::getModel('sales/quote')->load($param, 'reserved_order_id');
|
| 129 |
$this->_quote = $quote;
|
|
@@ -133,10 +136,11 @@ class Kash_Gateway_BbController extends Mage_Core_Controller_Front_Action
|
|
| 133 |
'config' => $this->_config,
|
| 134 |
'quote' => $quote,
|
| 135 |
));
|
| 136 |
-
$
|
| 137 |
|
| 138 |
$params = Mage::app()->getRequest()->getParams();
|
| 139 |
$this->_checkout->setParams($params);
|
|
|
|
| 140 |
|
| 141 |
$this->_checkout->loginUser();
|
| 142 |
|
|
@@ -149,21 +153,21 @@ class Kash_Gateway_BbController extends Mage_Core_Controller_Front_Action
|
|
| 149 |
$order = $this->_checkout->getOrder();
|
| 150 |
|
| 151 |
if ($order->getIncrementId() == $param) {
|
| 152 |
-
$this->invoiceOrder($order);
|
| 153 |
$connection->commit();
|
| 154 |
}
|
| 155 |
else {
|
| 156 |
-
$
|
| 157 |
$connection->rollback();
|
| 158 |
}
|
| 159 |
} catch (Exception $e) {
|
| 160 |
-
$
|
| 161 |
-
$
|
| 162 |
$connection->rollback();
|
| 163 |
}
|
| 164 |
}
|
| 165 |
else {
|
| 166 |
-
$
|
| 167 |
}
|
| 168 |
}
|
| 169 |
|
|
@@ -172,20 +176,21 @@ class Kash_Gateway_BbController extends Mage_Core_Controller_Front_Action
|
|
| 172 |
*/
|
| 173 |
public function completeAction()
|
| 174 |
{
|
| 175 |
-
$
|
|
|
|
| 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 |
-
$
|
| 183 |
Mage::getSingleton('checkout/session')->addError('Not valid signature');
|
| 184 |
$this->_redirect('checkout/cart');
|
| 185 |
return;
|
| 186 |
}
|
| 187 |
if (!$this->_checkout->checkResult()) {
|
| 188 |
-
$
|
| 189 |
Mage::getSingleton('checkout/session')->addError('Kash Gateway not completed');
|
| 190 |
$this->_redirect('checkout/cart');
|
| 191 |
return;
|
|
@@ -223,8 +228,8 @@ class Kash_Gateway_BbController extends Mage_Core_Controller_Front_Action
|
|
| 223 |
} catch (Mage_Core_Exception $e) {
|
| 224 |
Mage::getSingleton('checkout/session')->addError($e->getMessage());
|
| 225 |
} catch (Exception $e) {
|
| 226 |
-
$
|
| 227 |
-
$
|
| 228 |
Mage::getSingleton('checkout/session')->addError($this->__('Unable to process Kash Gateway Checkout approval.'));
|
| 229 |
Mage::logException($e);
|
| 230 |
}
|
|
@@ -261,7 +266,8 @@ class Kash_Gateway_BbController extends Mage_Core_Controller_Front_Action
|
|
| 261 |
Mage::getSingleton('checkout/session')->addError(
|
| 262 |
$this->__('Unable to initialize Kash Gateway Checkout review.')
|
| 263 |
);
|
| 264 |
-
$
|
|
|
|
| 265 |
Mage::logException($e);
|
| 266 |
}
|
| 267 |
$this->_redirect('checkout/cart');
|
|
@@ -272,9 +278,10 @@ class Kash_Gateway_BbController extends Mage_Core_Controller_Front_Action
|
|
| 272 |
*
|
| 273 |
* @param $order Mage_Sales_Model_Order
|
| 274 |
*/
|
| 275 |
-
protected function invoiceOrder($order)
|
| 276 |
{
|
| 277 |
-
$
|
|
|
|
| 278 |
if ($order->getState() == Mage_Sales_Model_Order::STATE_NEW) {
|
| 279 |
try {
|
| 280 |
if (!$order->canInvoice()) {
|
|
@@ -283,7 +290,8 @@ class Kash_Gateway_BbController extends Mage_Core_Controller_Front_Action
|
|
| 283 |
}
|
| 284 |
$invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
|
| 285 |
|
| 286 |
-
$invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::
|
|
|
|
| 287 |
$invoice->register();
|
| 288 |
|
| 289 |
$invoice->getOrder()->setCustomerNoteNotify(false);
|
|
@@ -297,8 +305,8 @@ class Kash_Gateway_BbController extends Mage_Core_Controller_Front_Action
|
|
| 297 |
|
| 298 |
$transactionSave->save();
|
| 299 |
} catch (Exception $e) {
|
| 300 |
-
$
|
| 301 |
-
$
|
| 302 |
$order->addStatusHistoryComment('Kash Gateway: Exception occurred during automatically Invoice action. Exception message: ' . $e->getMessage(), false);
|
| 303 |
$order->save();
|
| 304 |
}
|
|
@@ -315,11 +323,12 @@ class Kash_Gateway_BbController extends Mage_Core_Controller_Front_Action
|
|
| 315 |
*/
|
| 316 |
protected function _initToken($setToken = null)
|
| 317 |
{
|
|
|
|
| 318 |
if (null !== $setToken) {
|
| 319 |
if (false === $setToken) {
|
| 320 |
// security measure for avoid unsetting token twice
|
| 321 |
if (!$this->_getSession()->getBBCheckoutToken()) {
|
| 322 |
-
$
|
| 323 |
Mage::throwException($this->__('Payment Kash Gateway Checkout Token does not exist.'));
|
| 324 |
}
|
| 325 |
$this->_getSession()->unsBBCheckoutToken();
|
|
@@ -330,7 +339,7 @@ class Kash_Gateway_BbController extends Mage_Core_Controller_Front_Action
|
|
| 330 |
}
|
| 331 |
if ($setToken = $this->getRequest()->getParam('x_reference')) {
|
| 332 |
if ($setToken !== $this->_getSession()->getBBCheckoutToken()) {
|
| 333 |
-
$
|
| 334 |
Mage::throwException($this->__('Wrong Payment Kash Gateway Checkout Token specified.'));
|
| 335 |
}
|
| 336 |
} else {
|
|
@@ -397,11 +406,12 @@ class Kash_Gateway_BbController extends Mage_Core_Controller_Front_Action
|
|
| 397 |
*/
|
| 398 |
protected function _initCheckout($callback = false)
|
| 399 |
{
|
|
|
|
| 400 |
$quote = $this->_getQuote();
|
| 401 |
if (!$callback && (!$quote->hasItems() || $quote->getHasError())) {
|
| 402 |
-
$
|
| 403 |
-
$
|
| 404 |
-
$
|
| 405 |
Mage::log(Mage::helper('kash_gateway')->__('Unable to initialize Kash Gateway Checkout.'));
|
| 406 |
return null;
|
| 407 |
}
|
|
@@ -419,8 +429,10 @@ class Kash_Gateway_BbController extends Mage_Core_Controller_Front_Action
|
|
| 419 |
/**
|
| 420 |
* Make params for Payment BB
|
| 421 |
*/
|
| 422 |
-
protected function getPaymentRequest()
|
| 423 |
-
|
|
|
|
|
|
|
| 424 |
$this->_initCheckout();
|
| 425 |
|
| 426 |
if ($this->_getQuote()->getIsMultiShipping()) {
|
|
@@ -450,11 +462,10 @@ class Kash_Gateway_BbController extends Mage_Core_Controller_Front_Action
|
|
| 450 |
return null;
|
| 451 |
}
|
| 452 |
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
Mage::getUrl('
|
| 456 |
-
Mage::getUrl('
|
| 457 |
-
Mage::getUrl('gateway/bb/complete', array('_secure'=>true))
|
| 458 |
);
|
| 459 |
|
| 460 |
$params = $this->_checkout->start();
|
| 1 |
<?php
|
| 2 |
|
| 3 |
/**
|
| 4 |
+
* Offsite Checkout Controller
|
|
|
|
|
|
|
| 5 |
*/
|
| 6 |
+
class Kash_Gateway_OffsiteController extends Mage_Core_Controller_Front_Action
|
| 7 |
{
|
| 8 |
/**
|
| 9 |
* @var Kash_Gateway_Model_Checkout
|
| 56 |
/**
|
| 57 |
* Get form for requesting form
|
| 58 |
*/
|
| 59 |
+
public function startAction()
|
| 60 |
+
{
|
| 61 |
+
$logger = Mage::helper('kash_gateway')->logger();
|
| 62 |
+
$logger->log('quote '.$this->_getQuote()->getId().': startAction()');
|
| 63 |
$paymentParams = $this->getPaymentRequest();
|
| 64 |
if(!$paymentParams){
|
| 65 |
return;
|
| 78 |
*/
|
| 79 |
public function getRequestAction()
|
| 80 |
{
|
| 81 |
+
$logger = Mage::helper('kash_gateway')->logger();
|
| 82 |
+
$logger->log('quote '.$this->_getQuote()->getId().': getRequestAction()');
|
| 83 |
try {
|
| 84 |
$paymentParams = $this->getPaymentRequest();
|
| 85 |
if(!$paymentParams){
|
| 100 |
} catch (Mage_Core_Exception $e) {
|
| 101 |
$this->_getCheckoutSession()->addError($e->getMessage());
|
| 102 |
} catch (Exception $e) {
|
| 103 |
+
$logger->log($e);
|
| 104 |
$this->_getCheckoutSession()->addError($this->__('Unable to start BB Checkout.'));
|
| 105 |
Mage::logException($e);
|
| 106 |
}
|
| 113 |
*/
|
| 114 |
public function cancelAction()
|
| 115 |
{
|
| 116 |
+
$logger = Mage::helper('kash_gateway')->logger();
|
| 117 |
+
$logger->log('x_reference '.$this->_getQuote()->getReservedOrderId().': cancelAction()');
|
| 118 |
$this->_initToken(false);
|
| 119 |
$this->_redirect('checkout/cart');
|
| 120 |
}
|
| 125 |
public function callbackAction()
|
| 126 |
{
|
| 127 |
$param = Mage::app()->getRequest()->getParam('x_reference');
|
| 128 |
+
$logger = Mage::helper('kash_gateway')->logger();
|
| 129 |
+
$logger->log('x_reference '.$param.': callbackAction()');
|
| 130 |
|
| 131 |
$quote = Mage::getModel('sales/quote')->load($param, 'reserved_order_id');
|
| 132 |
$this->_quote = $quote;
|
| 136 |
'config' => $this->_config,
|
| 137 |
'quote' => $quote,
|
| 138 |
));
|
| 139 |
+
$logger->log('x_reference '.$this->_getQuote()->getReservedOrderId().': quote is active? '.$quote->getIsActive());
|
| 140 |
|
| 141 |
$params = Mage::app()->getRequest()->getParams();
|
| 142 |
$this->_checkout->setParams($params);
|
| 143 |
+
$kashTransactionId = $this->_checkout->getParams('x_gateway_reference');
|
| 144 |
|
| 145 |
$this->_checkout->loginUser();
|
| 146 |
|
| 153 |
$order = $this->_checkout->getOrder();
|
| 154 |
|
| 155 |
if ($order->getIncrementId() == $param) {
|
| 156 |
+
$this->invoiceOrder($order, $kashTransactionId);
|
| 157 |
$connection->commit();
|
| 158 |
}
|
| 159 |
else {
|
| 160 |
+
$logger->log('x_reference '.$param.': The new order id is not the expected order id! Rolling back');
|
| 161 |
$connection->rollback();
|
| 162 |
}
|
| 163 |
} catch (Exception $e) {
|
| 164 |
+
$logger->log('x_reference '.$param. ': Error, rolling back');
|
| 165 |
+
$logger->log($e);
|
| 166 |
$connection->rollback();
|
| 167 |
}
|
| 168 |
}
|
| 169 |
else {
|
| 170 |
+
$logger->log('x_reference '.$param.': Checks failed, will not try and create order');
|
| 171 |
}
|
| 172 |
}
|
| 173 |
|
| 176 |
*/
|
| 177 |
public function completeAction()
|
| 178 |
{
|
| 179 |
+
$logger = Mage::helper('kash_gateway')->logger();
|
| 180 |
+
$logger->log('completeAction()');
|
| 181 |
try {
|
| 182 |
if (!$this->_initCheckout(true)) {
|
| 183 |
$this->getResponse()->setRedirect(Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB));
|
| 184 |
return;
|
| 185 |
}
|
| 186 |
if (!$this->_checkout->checkSignature()) {
|
| 187 |
+
$logger->log('x_reference '.$this->_checkout->getParams('x_reference').': All requests and responses must be signed/verified using HMAC-SHA256');
|
| 188 |
Mage::getSingleton('checkout/session')->addError('Not valid signature');
|
| 189 |
$this->_redirect('checkout/cart');
|
| 190 |
return;
|
| 191 |
}
|
| 192 |
if (!$this->_checkout->checkResult()) {
|
| 193 |
+
$logger->log('x_reference '.$this->_checkout->getParams('x_reference').': Result not completed');
|
| 194 |
Mage::getSingleton('checkout/session')->addError('Kash Gateway not completed');
|
| 195 |
$this->_redirect('checkout/cart');
|
| 196 |
return;
|
| 228 |
} catch (Mage_Core_Exception $e) {
|
| 229 |
Mage::getSingleton('checkout/session')->addError($e->getMessage());
|
| 230 |
} catch (Exception $e) {
|
| 231 |
+
$logger->log('x_reference '.$xref.': Could not complete action');
|
| 232 |
+
$logger->log($e);
|
| 233 |
Mage::getSingleton('checkout/session')->addError($this->__('Unable to process Kash Gateway Checkout approval.'));
|
| 234 |
Mage::logException($e);
|
| 235 |
}
|
| 266 |
Mage::getSingleton('checkout/session')->addError(
|
| 267 |
$this->__('Unable to initialize Kash Gateway Checkout review.')
|
| 268 |
);
|
| 269 |
+
$logger = Mage::helper('kash_gateway')->logger();
|
| 270 |
+
$logger->log('Could not review order');
|
| 271 |
Mage::logException($e);
|
| 272 |
}
|
| 273 |
$this->_redirect('checkout/cart');
|
| 278 |
*
|
| 279 |
* @param $order Mage_Sales_Model_Order
|
| 280 |
*/
|
| 281 |
+
protected function invoiceOrder($order, $kashTransactionId)
|
| 282 |
{
|
| 283 |
+
$logger = Mage::helper('kash_gateway')->logger();
|
| 284 |
+
$logger->log('order '.$order->getIncrementId().': Invoicing order');
|
| 285 |
if ($order->getState() == Mage_Sales_Model_Order::STATE_NEW) {
|
| 286 |
try {
|
| 287 |
if (!$order->canInvoice()) {
|
| 290 |
}
|
| 291 |
$invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
|
| 292 |
|
| 293 |
+
$invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE);
|
| 294 |
+
$invoice->setTransactionId($kashTransactionId);
|
| 295 |
$invoice->register();
|
| 296 |
|
| 297 |
$invoice->getOrder()->setCustomerNoteNotify(false);
|
| 305 |
|
| 306 |
$transactionSave->save();
|
| 307 |
} catch (Exception $e) {
|
| 308 |
+
$logger->log('order '.$order->getIncrementId().': Could not invoice order.');
|
| 309 |
+
$logger->log($e);
|
| 310 |
$order->addStatusHistoryComment('Kash Gateway: Exception occurred during automatically Invoice action. Exception message: ' . $e->getMessage(), false);
|
| 311 |
$order->save();
|
| 312 |
}
|
| 323 |
*/
|
| 324 |
protected function _initToken($setToken = null)
|
| 325 |
{
|
| 326 |
+
$logger = Mage::helper('kash_gateway')->logger();
|
| 327 |
if (null !== $setToken) {
|
| 328 |
if (false === $setToken) {
|
| 329 |
// security measure for avoid unsetting token twice
|
| 330 |
if (!$this->_getSession()->getBBCheckoutToken()) {
|
| 331 |
+
$logger->log('checkout token does not exist');
|
| 332 |
Mage::throwException($this->__('Payment Kash Gateway Checkout Token does not exist.'));
|
| 333 |
}
|
| 334 |
$this->_getSession()->unsBBCheckoutToken();
|
| 339 |
}
|
| 340 |
if ($setToken = $this->getRequest()->getParam('x_reference')) {
|
| 341 |
if ($setToken !== $this->_getSession()->getBBCheckoutToken()) {
|
| 342 |
+
$logger->log('wrong token');
|
| 343 |
Mage::throwException($this->__('Wrong Payment Kash Gateway Checkout Token specified.'));
|
| 344 |
}
|
| 345 |
} else {
|
| 406 |
*/
|
| 407 |
protected function _initCheckout($callback = false)
|
| 408 |
{
|
| 409 |
+
$logger = Mage::helper('kash_gateway')->logger();
|
| 410 |
$quote = $this->_getQuote();
|
| 411 |
if (!$callback && (!$quote->hasItems() || $quote->getHasError())) {
|
| 412 |
+
$logger->log('x_reference '.$quote->getReservedOrderId().': Unable to initialize Checkout');
|
| 413 |
+
$logger->log($quote->hasItems());
|
| 414 |
+
$logger->log($quote->getHasError());
|
| 415 |
Mage::log(Mage::helper('kash_gateway')->__('Unable to initialize Kash Gateway Checkout.'));
|
| 416 |
return null;
|
| 417 |
}
|
| 429 |
/**
|
| 430 |
* Make params for Payment BB
|
| 431 |
*/
|
| 432 |
+
protected function getPaymentRequest()
|
| 433 |
+
{
|
| 434 |
+
$logger = Mage::helper('kash_gateway')->logger();
|
| 435 |
+
$logger->log('quote '.$this->_getQuote()->getId().': setting payment request');
|
| 436 |
$this->_initCheckout();
|
| 437 |
|
| 438 |
if ($this->_getQuote()->getIsMultiShipping()) {
|
| 462 |
return null;
|
| 463 |
}
|
| 464 |
|
| 465 |
+
$this->_checkout->setCallbackUrls(
|
| 466 |
+
Mage::getUrl('kash_gateway/offsite/callback', array('_secure'=>true)),
|
| 467 |
+
Mage::getUrl('kash_gateway/offsite/cancel', array('_secure'=>true)),
|
| 468 |
+
Mage::getUrl('kash_gateway/offsite/complete', array('_secure'=>true))
|
|
|
|
| 469 |
);
|
| 470 |
|
| 471 |
$params = $this->_checkout->start();
|
app/code/local/Kash/Gateway/etc/config.xml
CHANGED
|
@@ -1,13 +1,33 @@
|
|
| 1 |
<?xml version="1.0"?>
|
|
|
|
|
|
|
| 2 |
<config>
|
|
|
|
| 3 |
<modules>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
<Kash_Gateway>
|
| 5 |
-
<version>0.2.
|
| 6 |
</Kash_Gateway>
|
| 7 |
</modules>
|
|
|
|
|
|
|
| 8 |
<global>
|
|
|
|
| 9 |
<models>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
<kash_gateway>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
<class>Kash_Gateway_Model</class>
|
| 12 |
<resourceModel>kash_gateway_resource</resourceModel>
|
| 13 |
</kash_gateway>
|
|
@@ -15,6 +35,7 @@
|
|
| 15 |
<class>Kash_Gateway_Model_Resource</class>
|
| 16 |
</kash_gateway_resource>
|
| 17 |
</models>
|
|
|
|
| 18 |
<blocks>
|
| 19 |
<kash_gateway>
|
| 20 |
<class>Kash_Gateway_Block</class>
|
|
@@ -25,11 +46,17 @@
|
|
| 25 |
</rewrite>
|
| 26 |
</adminhtml>
|
| 27 |
</blocks>
|
|
|
|
| 28 |
<helpers>
|
| 29 |
<kash_gateway>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
<class>Kash_Gateway_Helper</class>
|
| 31 |
</kash_gateway>
|
| 32 |
</helpers>
|
|
|
|
| 33 |
<resources>
|
| 34 |
<kash_gateway_setup>
|
| 35 |
<setup>
|
|
@@ -37,6 +64,7 @@
|
|
| 37 |
</setup>
|
| 38 |
</kash_gateway_setup>
|
| 39 |
</resources>
|
|
|
|
| 40 |
<fieldsets>
|
| 41 |
<sales_convert_quote_payment>
|
| 42 |
<x_gateway_reference>
|
|
@@ -46,16 +74,7 @@
|
|
| 46 |
</fieldsets>
|
| 47 |
</global>
|
| 48 |
|
| 49 |
-
|
| 50 |
-
<layout>
|
| 51 |
-
<updates>
|
| 52 |
-
<kash_gateway>
|
| 53 |
-
<file>kash/gateway.xml</file>
|
| 54 |
-
</kash_gateway>
|
| 55 |
-
</updates>
|
| 56 |
-
</layout>
|
| 57 |
-
</frontend>
|
| 58 |
-
|
| 59 |
<adminhtml>
|
| 60 |
<events>
|
| 61 |
<core_collection_abstract_load_before>
|
|
@@ -70,12 +89,28 @@
|
|
| 70 |
</events>
|
| 71 |
</adminhtml>
|
| 72 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
<default>
|
| 74 |
<payment>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
<kash_gateway>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
<active>0</active>
|
| 77 |
<bbtypes>AE,VI,MC,DI</bbtypes>
|
| 78 |
-
<model>kash_gateway/method_bb</model>
|
| 79 |
<order_status>processing</order_status>
|
| 80 |
<title>Direct Debit or Credit Card</title>
|
| 81 |
<post_url>https://gateway.withkash.com/</post_url>
|
|
@@ -85,17 +120,26 @@
|
|
| 85 |
</payment>
|
| 86 |
</default>
|
| 87 |
|
|
|
|
| 88 |
<frontend>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
<routers>
|
| 90 |
<kash_gateway>
|
| 91 |
<use>standard</use>
|
| 92 |
<args>
|
| 93 |
<module>Kash_Gateway</module>
|
| 94 |
-
<frontName>
|
| 95 |
</args>
|
| 96 |
</kash_gateway>
|
| 97 |
</routers>
|
| 98 |
<events>
|
|
|
|
| 99 |
<sales_quote_collect_totals_before>
|
| 100 |
<observers>
|
| 101 |
<kash_gateway>
|
|
@@ -105,6 +149,8 @@
|
|
| 105 |
</kash_gateway>
|
| 106 |
</observers>
|
| 107 |
</sales_quote_collect_totals_before>
|
|
|
|
|
|
|
| 108 |
<checkout_onepage_controller_success_action>
|
| 109 |
<observers>
|
| 110 |
<kash_gateway>
|
|
@@ -114,6 +160,11 @@
|
|
| 114 |
</kash_gateway>
|
| 115 |
</observers>
|
| 116 |
</checkout_onepage_controller_success_action>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
<sales_order_save_after>
|
| 118 |
<observers>
|
| 119 |
<kash_gateway>
|
|
@@ -123,6 +174,8 @@
|
|
| 123 |
</kash_gateway>
|
| 124 |
</observers>
|
| 125 |
</sales_order_save_after>
|
|
|
|
|
|
|
| 126 |
<sales_convert_quote_to_order>
|
| 127 |
<observers>
|
| 128 |
<kash_gateway>
|
| 1 |
<?xml version="1.0"?>
|
| 2 |
+
|
| 3 |
+
<!-- The root node for a Magento module configuration -->
|
| 4 |
<config>
|
| 5 |
+
|
| 6 |
<modules>
|
| 7 |
+
<!--
|
| 8 |
+
This tag must match the namespace and module name exactly, but
|
| 9 |
+
with slash replaced with underscore.
|
| 10 |
+
|
| 11 |
+
Our namespace is "Kash" and our module name is "Gateway".
|
| 12 |
+
-->
|
| 13 |
<Kash_Gateway>
|
| 14 |
+
<version>0.2.9</version>
|
| 15 |
</Kash_Gateway>
|
| 16 |
</modules>
|
| 17 |
+
|
| 18 |
+
<!-- Configure module's behaviour in the `global` area -->
|
| 19 |
<global>
|
| 20 |
+
<!-- Defining models -->
|
| 21 |
<models>
|
| 22 |
+
<!--
|
| 23 |
+
Unique identifier in the model's node.
|
| 24 |
+
By convention, we put the module's name in lowercase.
|
| 25 |
+
-->
|
| 26 |
<kash_gateway>
|
| 27 |
+
<!--
|
| 28 |
+
The path to our models directory, with directory separators
|
| 29 |
+
replaced by underscores.
|
| 30 |
+
-->
|
| 31 |
<class>Kash_Gateway_Model</class>
|
| 32 |
<resourceModel>kash_gateway_resource</resourceModel>
|
| 33 |
</kash_gateway>
|
| 35 |
<class>Kash_Gateway_Model_Resource</class>
|
| 36 |
</kash_gateway_resource>
|
| 37 |
</models>
|
| 38 |
+
|
| 39 |
<blocks>
|
| 40 |
<kash_gateway>
|
| 41 |
<class>Kash_Gateway_Block</class>
|
| 46 |
</rewrite>
|
| 47 |
</adminhtml>
|
| 48 |
</blocks>
|
| 49 |
+
|
| 50 |
<helpers>
|
| 51 |
<kash_gateway>
|
| 52 |
+
<!--
|
| 53 |
+
The path to our Helper directory, with directory separators
|
| 54 |
+
replaced by underscores.
|
| 55 |
+
-->
|
| 56 |
<class>Kash_Gateway_Helper</class>
|
| 57 |
</kash_gateway>
|
| 58 |
</helpers>
|
| 59 |
+
|
| 60 |
<resources>
|
| 61 |
<kash_gateway_setup>
|
| 62 |
<setup>
|
| 64 |
</setup>
|
| 65 |
</kash_gateway_setup>
|
| 66 |
</resources>
|
| 67 |
+
|
| 68 |
<fieldsets>
|
| 69 |
<sales_convert_quote_payment>
|
| 70 |
<x_gateway_reference>
|
| 74 |
</fieldsets>
|
| 75 |
</global>
|
| 76 |
|
| 77 |
+
<!-- Configure module's behaviour in the `adminhtml` area -->
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
<adminhtml>
|
| 79 |
<events>
|
| 80 |
<core_collection_abstract_load_before>
|
| 89 |
</events>
|
| 90 |
</adminhtml>
|
| 91 |
|
| 92 |
+
<!--
|
| 93 |
+
Default values for our module's configuration. The values here serve as
|
| 94 |
+
defaults for the fields defined in `system.xml`.
|
| 95 |
+
-->
|
| 96 |
<default>
|
| 97 |
<payment>
|
| 98 |
+
<!--
|
| 99 |
+
Unique identifier in the model's node.
|
| 100 |
+
By convention, we put the module's name in lowercase.
|
| 101 |
+
-->
|
| 102 |
<kash_gateway>
|
| 103 |
+
<!--
|
| 104 |
+
This specifies the class Magneto will talk to for
|
| 105 |
+
information about this payment method.
|
| 106 |
+
|
| 107 |
+
It's in lower case and with slash replaced with
|
| 108 |
+
underscore.
|
| 109 |
+
-->
|
| 110 |
+
<model>kash_gateway/offsite</model>
|
| 111 |
+
|
| 112 |
<active>0</active>
|
| 113 |
<bbtypes>AE,VI,MC,DI</bbtypes>
|
|
|
|
| 114 |
<order_status>processing</order_status>
|
| 115 |
<title>Direct Debit or Credit Card</title>
|
| 116 |
<post_url>https://gateway.withkash.com/</post_url>
|
| 120 |
</payment>
|
| 121 |
</default>
|
| 122 |
|
| 123 |
+
<!-- Configure module's behaviour in the `frontend` area -->
|
| 124 |
<frontend>
|
| 125 |
+
<layout>
|
| 126 |
+
<updates>
|
| 127 |
+
<kash_gateway>
|
| 128 |
+
<file>kash/gateway.xml</file>
|
| 129 |
+
</kash_gateway>
|
| 130 |
+
</updates>
|
| 131 |
+
</layout>
|
| 132 |
<routers>
|
| 133 |
<kash_gateway>
|
| 134 |
<use>standard</use>
|
| 135 |
<args>
|
| 136 |
<module>Kash_Gateway</module>
|
| 137 |
+
<frontName>kash_gateway</frontName>
|
| 138 |
</args>
|
| 139 |
</kash_gateway>
|
| 140 |
</routers>
|
| 141 |
<events>
|
| 142 |
+
<!-- Event emitted by `app/code/core/Mage/Sales/Model/Quote.php` -->
|
| 143 |
<sales_quote_collect_totals_before>
|
| 144 |
<observers>
|
| 145 |
<kash_gateway>
|
| 149 |
</kash_gateway>
|
| 150 |
</observers>
|
| 151 |
</sales_quote_collect_totals_before>
|
| 152 |
+
|
| 153 |
+
<!-- Event emitted by `app/code/core/Mage/Checkout/controllers/OnepageController.php` -->
|
| 154 |
<checkout_onepage_controller_success_action>
|
| 155 |
<observers>
|
| 156 |
<kash_gateway>
|
| 160 |
</kash_gateway>
|
| 161 |
</observers>
|
| 162 |
</checkout_onepage_controller_success_action>
|
| 163 |
+
|
| 164 |
+
<!--
|
| 165 |
+
"_save_after" event emitted by `app/code/core/Mage/Core/Model/Abstract.php`
|
| 166 |
+
`_eventPrefix` defined in `app/code/core/Mage/Sales/Model/Order.php`
|
| 167 |
+
-->
|
| 168 |
<sales_order_save_after>
|
| 169 |
<observers>
|
| 170 |
<kash_gateway>
|
| 174 |
</kash_gateway>
|
| 175 |
</observers>
|
| 176 |
</sales_order_save_after>
|
| 177 |
+
|
| 178 |
+
<!-- Event emitted by `app/code/core/Mage/Sales/Model/Convert/Quote.php` -->
|
| 179 |
<sales_convert_quote_to_order>
|
| 180 |
<observers>
|
| 181 |
<kash_gateway>
|
app/code/local/Kash/Gateway/kashlib/KashApi.php
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* This is a reusable component to talk to kash_api.
|
| 5 |
+
*/
|
| 6 |
+
class KashApi
|
| 7 |
+
{
|
| 8 |
+
private static $apiUrlProd = 'https://api.withkash.com/v1';
|
| 9 |
+
|
| 10 |
+
protected $_gatewayUrl;
|
| 11 |
+
protected $_serverKey;
|
| 12 |
+
|
| 13 |
+
public function __construct($gatewayUrl, $serverKey)
|
| 14 |
+
{
|
| 15 |
+
$this->_gatewayUrl = $gatewayUrl;
|
| 16 |
+
$this->_serverKey = $serverKey;
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
public function refund($kashTransactionId, $refundAmount)
|
| 20 |
+
{
|
| 21 |
+
$requestHeaders = array(
|
| 22 |
+
'Authorization: Basic ' . base64_encode($this->_serverKey . ':')
|
| 23 |
+
);
|
| 24 |
+
|
| 25 |
+
$url = self::$apiUrlProd;
|
| 26 |
+
if (strpos($this->_gatewayUrl, 'februalia') !== false) {
|
| 27 |
+
$url = str_replace('withkash', 'februalia', $url);
|
| 28 |
+
}
|
| 29 |
+
else if ($this->gatewayUrl === 'http://kash-gateway') {
|
| 30 |
+
$url = 'http://kash-api:8080';
|
| 31 |
+
}
|
| 32 |
+
$url .= '/refunds';
|
| 33 |
+
|
| 34 |
+
$requestPayload = array(
|
| 35 |
+
'amount' => $refundAmount * 100,
|
| 36 |
+
'transaction_id' => $kashTransactionId
|
| 37 |
+
);
|
| 38 |
+
|
| 39 |
+
// create a new cURL resource
|
| 40 |
+
$ch = curl_init($url);
|
| 41 |
+
|
| 42 |
+
// set URL and other appropriate options
|
| 43 |
+
curl_setopt($ch, CURLOPT_POST ,1);
|
| 44 |
+
curl_setopt($ch, CURLOPT_POSTFIELDS, $requestPayload);
|
| 45 |
+
curl_setopt($ch, CURLOPT_HTTPHEADER, $requestHeaders);
|
| 46 |
+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
| 47 |
+
curl_setopt($ch, CURLOPT_HEADER, 1);
|
| 48 |
+
|
| 49 |
+
// Execute the request.
|
| 50 |
+
$rawResponse = curl_exec($ch);
|
| 51 |
+
$result = null;
|
| 52 |
+
$errorMessage = null;
|
| 53 |
+
if ($rawResponse === FALSE) {
|
| 54 |
+
$errorMessage = curl_error($ch);
|
| 55 |
+
}
|
| 56 |
+
else {
|
| 57 |
+
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
| 58 |
+
$headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
|
| 59 |
+
$headers = substr($rawResponse, 0, $headerSize);
|
| 60 |
+
$rawBody = substr($rawResponse, $headerSize);
|
| 61 |
+
$body = json_decode($rawBody);
|
| 62 |
+
|
| 63 |
+
$result = new stdClass();
|
| 64 |
+
$result->statusCode = $statusCode;
|
| 65 |
+
$result->headers = $headers;
|
| 66 |
+
$result->body = $body;
|
| 67 |
+
$result->rawBody = $rawBody;
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
// close cURL resource, and free up system resources
|
| 71 |
+
curl_close($ch);
|
| 72 |
+
|
| 73 |
+
if (!$result) {
|
| 74 |
+
throw new Exception($errorMessage);
|
| 75 |
+
}
|
| 76 |
+
return $result;
|
| 77 |
+
}
|
| 78 |
+
}
|
app/design/frontend/base/default/layout/kash/gateway.xml
CHANGED
|
@@ -22,7 +22,7 @@
|
|
| 22 |
|
| 23 |
</default>
|
| 24 |
|
| 25 |
-
<
|
| 26 |
<remove name="before_body_end"/>
|
| 27 |
<reference name="head">
|
| 28 |
<action method="addCss"><stylesheet>css/kash/start.css</stylesheet></action>
|
|
@@ -38,9 +38,9 @@
|
|
| 38 |
template="kash/container.phtml"/>
|
| 39 |
</reference>
|
| 40 |
</reference>
|
| 41 |
-
</
|
| 42 |
|
| 43 |
-
<
|
| 44 |
<remove name="right"/>
|
| 45 |
<remove name="left"/>
|
| 46 |
|
|
@@ -81,5 +81,5 @@
|
|
| 81 |
</action>
|
| 82 |
</reference>
|
| 83 |
<block type="core/text_list" name="additional.product.info"/>
|
| 84 |
-
</
|
| 85 |
</layout>
|
| 22 |
|
| 23 |
</default>
|
| 24 |
|
| 25 |
+
<kash_gateway_offsite_start>
|
| 26 |
<remove name="before_body_end"/>
|
| 27 |
<reference name="head">
|
| 28 |
<action method="addCss"><stylesheet>css/kash/start.css</stylesheet></action>
|
| 38 |
template="kash/container.phtml"/>
|
| 39 |
</reference>
|
| 40 |
</reference>
|
| 41 |
+
</kash_gateway_offsite_start>
|
| 42 |
|
| 43 |
+
<kash_gateway_offsite_review>
|
| 44 |
<remove name="right"/>
|
| 45 |
<remove name="left"/>
|
| 46 |
|
| 81 |
</action>
|
| 82 |
</reference>
|
| 83 |
<block type="core/text_list" name="additional.product.info"/>
|
| 84 |
+
</kash_gateway_offsite_review>
|
| 85 |
</layout>
|
app/etc/modules/Kash_Gateway.xml
CHANGED
|
@@ -2,8 +2,14 @@
|
|
| 2 |
<config>
|
| 3 |
<modules>
|
| 4 |
<Kash_Gateway>
|
|
|
|
|
|
|
| 5 |
<active>true</active>
|
|
|
|
|
|
|
| 6 |
<codePool>local</codePool>
|
|
|
|
|
|
|
| 7 |
<depends>
|
| 8 |
<Mage_Payment/>
|
| 9 |
</depends>
|
| 2 |
<config>
|
| 3 |
<modules>
|
| 4 |
<Kash_Gateway>
|
| 5 |
+
|
| 6 |
+
<!-- Whether our module is active: true or false -->
|
| 7 |
<active>true</active>
|
| 8 |
+
|
| 9 |
+
<!-- Which code pool to use: core, community or local -->
|
| 10 |
<codePool>local</codePool>
|
| 11 |
+
|
| 12 |
+
<!-- Our dependencies (also in Namespace_ModuleName format) -->
|
| 13 |
<depends>
|
| 14 |
<Mage_Payment/>
|
| 15 |
</depends>
|
package.xml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
<?xml version="1.0"?>
|
| 2 |
<package>
|
| 3 |
<name>kash_gateway</name>
|
| 4 |
-
<version>0.2.
|
| 5 |
<stability>stable</stability>
|
| 6 |
<license>MITL</license>
|
| 7 |
<channel>community</channel>
|
|
@@ -18,11 +18,150 @@
|
|
| 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.
|
| 22 |
-
<authors
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
<compatible/>
|
| 27 |
-
<dependencies
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
</package>
|
| 1 |
<?xml version="1.0"?>
|
| 2 |
<package>
|
| 3 |
<name>kash_gateway</name>
|
| 4 |
+
<version>0.2.9</version>
|
| 5 |
<stability>stable</stability>
|
| 6 |
<license>MITL</license>
|
| 7 |
<channel>community</channel>
|
| 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.6 - Support Online Refund</notes>
|
| 22 |
+
<authors>
|
| 23 |
+
<author>
|
| 24 |
+
<name>Kash Corp.</name>
|
| 25 |
+
<user>Kash Corp</user>
|
| 26 |
+
<email>info@withkash.com</email>
|
| 27 |
+
</author>
|
| 28 |
+
</authors>
|
| 29 |
+
<date>2017-03-13</date>
|
| 30 |
+
<time>23:00:00</time>
|
| 31 |
+
<contents>
|
| 32 |
+
<target name="mageetc">
|
| 33 |
+
<dir name="modules">
|
| 34 |
+
<file name="Kash_Gateway.xml" hash="2b23e09bdd8ecff348d3a72bebb6926e"/>
|
| 35 |
+
</dir>
|
| 36 |
+
</target>
|
| 37 |
+
<target name="mageskin">
|
| 38 |
+
<dir name="frontend">
|
| 39 |
+
<dir name="base">
|
| 40 |
+
<dir name="default">
|
| 41 |
+
<dir name="js">
|
| 42 |
+
<dir name="kash">
|
| 43 |
+
<file name="lightwindow.js" hash="d94daf37446ba2fd00222de24c7cf9b6"/>
|
| 44 |
+
</dir>
|
| 45 |
+
</dir>
|
| 46 |
+
<dir name="css">
|
| 47 |
+
<dir name="kash">
|
| 48 |
+
<file name="lightwindow.css" hash="543637b1312fd4b72696f18c14fc7a54"/>
|
| 49 |
+
<file name="start.css" hash="d310d178769035d366ebb2caff9bd4a3"/>
|
| 50 |
+
</dir>
|
| 51 |
+
</dir>
|
| 52 |
+
</dir>
|
| 53 |
+
</dir>
|
| 54 |
+
</dir>
|
| 55 |
+
</target>
|
| 56 |
+
<target name="magedesign">
|
| 57 |
+
<dir name="frontend">
|
| 58 |
+
<dir name="base">
|
| 59 |
+
<dir name="default">
|
| 60 |
+
<dir name="template">
|
| 61 |
+
<dir name="kash">
|
| 62 |
+
<file name="container.phtml" hash="eea03cce8b67b3a1239bb3676409c2e5"/>
|
| 63 |
+
<file name="form.phtml" hash="0b4b05f427474b08d1c52cfc09fc3485"/>
|
| 64 |
+
<file name="js.phtml" hash="cc2180154f614c40f13e7819f8153eca"/>
|
| 65 |
+
<dir name="payment">
|
| 66 |
+
<file name="mark.phtml" hash="4499c690fe7126e4cedf83499f2eee52"/>
|
| 67 |
+
<file name="redirect.phtml" hash="29673aeed089aecb40c2371e38feb0f4"/>
|
| 68 |
+
<file name="review.phtml" hash="ef1d435a2bc0e9daff56594a715bed1a"/>
|
| 69 |
+
<dir name="review">
|
| 70 |
+
<file name="details.phtml" hash="ff2ad65893e66920a4cc8b098dc397c1"/>
|
| 71 |
+
</dir>
|
| 72 |
+
</dir>
|
| 73 |
+
</dir>
|
| 74 |
+
</dir>
|
| 75 |
+
<dir name="layout">
|
| 76 |
+
<dir name="kash">
|
| 77 |
+
<file name="gateway.xml" hash="bcc9519024a9e2b2e514dd801f322e88"/>
|
| 78 |
+
</dir>
|
| 79 |
+
</dir>
|
| 80 |
+
</dir>
|
| 81 |
+
</dir>
|
| 82 |
+
</dir>
|
| 83 |
+
<dir name="adminhtml">
|
| 84 |
+
<dir name="default">
|
| 85 |
+
<dir name="default">
|
| 86 |
+
<dir name="template">
|
| 87 |
+
<dir name="kash">
|
| 88 |
+
<dir name="info">
|
| 89 |
+
<file name="default.phtml" hash="79bcf1003e40c03ec35c383ec4ca5236"/>
|
| 90 |
+
</dir>
|
| 91 |
+
</dir>
|
| 92 |
+
</dir>
|
| 93 |
+
</dir>
|
| 94 |
+
</dir>
|
| 95 |
+
</dir>
|
| 96 |
+
</target>
|
| 97 |
+
<target name="magelocal">
|
| 98 |
+
<dir name="Kash">
|
| 99 |
+
<dir name="Gateway">
|
| 100 |
+
<dir name="sql">
|
| 101 |
+
<dir name="kash_gateway_setup">
|
| 102 |
+
<file name="install-0.0.1.php" hash="9ecb52ba48345cdbee9ce0fd92d2aff9"/>
|
| 103 |
+
</dir>
|
| 104 |
+
</dir>
|
| 105 |
+
<dir name="kashlib">
|
| 106 |
+
<file name="KashApi.php" hash="9a15c80500c3b61759ee1b3e8934c293"/>
|
| 107 |
+
</dir>
|
| 108 |
+
<dir name="etc">
|
| 109 |
+
<file name="config.xml" hash="9a879773ffc772661f769f801b53dcbd"/>
|
| 110 |
+
<file name="system.xml" hash="ca30f6ca733fd3bb8bf7acc0ebe4d705"/>
|
| 111 |
+
</dir>
|
| 112 |
+
<dir name="data">
|
| 113 |
+
<dir name="kash_gateway_setup">
|
| 114 |
+
<file name="data-install-0.0.1.php" hash="5fe91e15bc5e6269eadcc50f8991250a"/>
|
| 115 |
+
<file name="data-upgrade-0.0.1-0.0.2.php" hash="632331f77e2238438e1bddfe4c2b82bf"/>
|
| 116 |
+
</dir>
|
| 117 |
+
</dir>
|
| 118 |
+
<dir name="controllers">
|
| 119 |
+
<file name="OffsiteController.php" hash="0144411e8d5eaea6bde1d4ef05fa5ff5"/>
|
| 120 |
+
</dir>
|
| 121 |
+
<dir name="Model">
|
| 122 |
+
<file name="Cart.php" hash="ced06fca31abf3fbe20e3e2eb430cfea"/>
|
| 123 |
+
<file name="Checkout.php" hash="408554209310d17415332616598fe88a"/>
|
| 124 |
+
<file name="Config.php" hash="56f27fab288fbe25c775cc7144b96e09"/>
|
| 125 |
+
<file name="Logger.php" hash="9092354e4fa3a1613390008fdf9fed2a"/>
|
| 126 |
+
<file name="Observer.php" hash="137920115b9670ca001bb199608d2800"/>
|
| 127 |
+
<file name="Offsite.php" hash="69daf29d2d7d3eb0e12903ee5999156c"/>
|
| 128 |
+
<file name="Session.php" hash="1778fbe493d2ceb81d8a20b58a21ce3c"/>
|
| 129 |
+
<dir name="Api">
|
| 130 |
+
<file name="Abstract.php" hash="dda4315e8a6b95ef3017f90cecfb250d"/>
|
| 131 |
+
<file name="Bb.php" hash="d0af525342b37bfd2b9921b99938d25c"/>
|
| 132 |
+
</dir>
|
| 133 |
+
</dir>
|
| 134 |
+
<dir name="Helper">
|
| 135 |
+
<file name="Data.php" hash="9593094f8794d90dfb2008e2f9984b1c"/>
|
| 136 |
+
</dir>
|
| 137 |
+
<dir name="Block">
|
| 138 |
+
<file name="Review.php" hash="a2a24914d577262188c491898c77307e"/>
|
| 139 |
+
<dir name="Review">
|
| 140 |
+
<file name="Details.php" hash="9a077c6688f913bd4f9fee74fad68b7e"/>
|
| 141 |
+
</dir>
|
| 142 |
+
<dir name="Form">
|
| 143 |
+
<file name="Bb.php" hash="be99610adaba2bbcb9877ba7ad56cf0f"/>
|
| 144 |
+
</dir>
|
| 145 |
+
<dir name="Adminhtml">
|
| 146 |
+
<file name="Info.php" hash="186ac575a69755543d649d2174f43474"/>
|
| 147 |
+
<dir name="Sales">
|
| 148 |
+
<dir name="Order">
|
| 149 |
+
<file name="Grid.php" hash="5f3900c603a9bb6c870c50bdadf52f73"/>
|
| 150 |
+
</dir>
|
| 151 |
+
</dir>
|
| 152 |
+
</dir>
|
| 153 |
+
</dir>
|
| 154 |
+
</dir>
|
| 155 |
+
</dir>
|
| 156 |
+
</target>
|
| 157 |
+
</contents>
|
| 158 |
<compatible/>
|
| 159 |
+
<dependencies>
|
| 160 |
+
<required>
|
| 161 |
+
<php>
|
| 162 |
+
<min>5.4.45</min>
|
| 163 |
+
<max>5.6.99</max>
|
| 164 |
+
</php>
|
| 165 |
+
</required>
|
| 166 |
+
</dependencies>
|
| 167 |
</package>
|
