EMerchantPay_Genesis_Client - Version 1.2.7

Version Notes

1.) Added Support for Recurring Transactions
- eMerchantPay Direct Payment Method
--nitRecurringSale
--InitRecurringSale (3D-Secure)
--RecurringSale

- eMerchantPay Checkout Payment Method
--InitRecurringSale
--InitRecurringSale (3D-Secure)
--RecurringSale

2.) Additional Payment Method Settings
- Available Recurring Transactions
- Managing Initial Fee
- Managing Cron Jobs Settings - External Module is needed

3.) Added Support for Genesis v1.4.2
- Updated PBV Sale & Yeepay APIs

- Added Client Validations in Payment Method Settings

4.) A few Issues have been resolved
- Payment Gateway Request Currency - The Base Currency has been used instead of checkout currency
- An additional Web Payment Form Locale check has been implemented - there was a problem while creating a Web Payment Form if the selected locale in admin is not by our Payment Gateway

1.) Added Support for GenesisLib v1.4 - Additional Transaction Types are now available using the eMerchantPay Checkout Method

2.) A possibility has been added to use an external GenesisGateway Library (installed by composer) instead of the integrated in Module

2.) A few minor issues were resolved regarding Capture / Refund Transactions

Download this release

Release Info

Developer eMerchantPay Ltd.
Extension EMerchantPay_Genesis_Client
Version 1.2.7
Comparing to
See all releases


Code changes from version 1.2.5 to 1.2.7

Files changed (38) hide show
  1. app/code/community/EMerchantPay/Genesis/Block/Form/Checkout.php +13 -3
  2. app/code/community/EMerchantPay/Genesis/Block/Form/Direct.php +15 -5
  3. app/code/community/EMerchantPay/Genesis/Block/Info/Checkout.php +3 -3
  4. app/code/community/EMerchantPay/Genesis/Block/Info/Direct.php +3 -3
  5. app/code/community/EMerchantPay/Genesis/Block/Redirect/Checkout.php +3 -3
  6. app/code/community/EMerchantPay/Genesis/Block/Redirect/Direct.php +3 -3
  7. app/code/community/EMerchantPay/Genesis/Helper/Data.php +420 -31
  8. app/code/community/EMerchantPay/Genesis/Model/Admin/Checkout/Options/Transaction/Recurring/Type.php +74 -0
  9. app/code/community/EMerchantPay/Genesis/Model/Admin/Checkout/Options/Transaction/Type.php +6 -5
  10. app/code/community/EMerchantPay/Genesis/Model/Admin/Direct/Options/Transaction/Recurring/Type.php +74 -0
  11. app/code/community/EMerchantPay/Genesis/Model/Admin/Direct/Options/Transaction/Type.php +5 -5
  12. app/code/community/EMerchantPay/Genesis/Model/Admin/Environment.php +5 -5
  13. app/code/community/EMerchantPay/Genesis/Model/Checkout.php +531 -51
  14. app/code/community/EMerchantPay/Genesis/Model/Direct.php +501 -75
  15. app/code/community/EMerchantPay/Genesis/Model/Task/Recurring.php +462 -0
  16. app/code/community/EMerchantPay/Genesis/Observer/CheckoutSubmitAllAfter.php +52 -0
  17. app/code/community/EMerchantPay/Genesis/Observer/GenesisAutoLoader.php +0 -74
  18. app/code/community/EMerchantPay/Genesis/Observer/SalesQuoteAddressCollectTotalsBefore.php +103 -0
  19. app/code/community/EMerchantPay/Genesis/controllers/CheckoutController.php +7 -10
  20. app/code/community/EMerchantPay/Genesis/controllers/DirectController.php +7 -8
  21. app/code/community/EMerchantPay/Genesis/etc/config.xml +48 -9
  22. app/code/community/EMerchantPay/Genesis/etc/system.xml +381 -32
  23. app/design/frontend/base/default/template/emerchantpay/form/checkout.phtml +13 -0
  24. app/design/frontend/base/default/template/emerchantpay/form/direct.phtml +13 -0
  25. lib/Genesis/src/Genesis/API/.DS_Store +0 -0
  26. lib/Genesis/src/Genesis/API/Constants/Payment/Methods.php +18 -0
  27. lib/Genesis/src/Genesis/API/Constants/Transaction/Parameters/PayByVouchers/CardTypes.php +71 -0
  28. lib/Genesis/src/Genesis/API/Constants/Transaction/Parameters/PayByVouchers/RedeemTypes.php +72 -0
  29. lib/Genesis/src/Genesis/API/Constants/Transaction/Types.php +100 -0
  30. lib/Genesis/src/Genesis/API/Request/.DS_Store +0 -0
  31. lib/Genesis/src/Genesis/API/Request/Financial/PayByVouchers/Sale.php +18 -0
  32. lib/Genesis/src/Genesis/API/Request/Financial/PayByVouchers/oBeP.php +18 -0
  33. lib/Genesis/src/Genesis/API/Request/WPF/.DS_Store +0 -0
  34. lib/Genesis/src/Genesis/API/Request/WPF/Create.php +71 -0
  35. lib/Genesis/src/Genesis/Config.php +1 -1
  36. lib/Genesis/src/Genesis/Utils/.DS_Store +0 -0
  37. lib/Genesis/src/Genesis/Utils/Common.php +20 -0
  38. package.xml +34 -5
app/code/community/EMerchantPay/Genesis/Block/Form/Checkout.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/*
3
- * Copyright (C) 2015 eMerchantPay Ltd.
4
*
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
@@ -13,7 +13,7 @@
13
* GNU General Public License for more details.
14
*
15
* @author eMerchantPay
16
- * @copyright 2015 eMerchantPay Ltd.
17
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License, version 2 (GPL-2.0)
18
*/
19
@@ -32,4 +32,14 @@ class EMerchantPay_Genesis_Block_Form_Checkout extends Mage_Payment_Block_Form
32
parent::_construct();
33
$this->setTemplate('emerchantpay/form/checkout.phtml');
34
}
35
- }
1
<?php
2
/*
3
+ * Copyright (C) 2016 eMerchantPay Ltd.
4
*
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
13
* GNU General Public License for more details.
14
*
15
* @author eMerchantPay
16
+ * @copyright 2016 eMerchantPay Ltd.
17
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License, version 2 (GPL-2.0)
18
*/
19
32
parent::_construct();
33
$this->setTemplate('emerchantpay/form/checkout.phtml');
34
}
35
+
36
+ /**
37
+ * Determines if a Nominal Items were added to the cart
38
+ * @return bool
39
+ */
40
+ public function getHasNominalItems()
41
+ {
42
+ return
43
+ Mage::helper("emerchantpay")->getCheckoutHasRecurringItems();
44
+ }
45
+ }
app/code/community/EMerchantPay/Genesis/Block/Form/Direct.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/*
3
- * Copyright (C) 2015 eMerchantPay Ltd.
4
*
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
@@ -13,7 +13,7 @@
13
* GNU General Public License for more details.
14
*
15
* @author eMerchantPay
16
- * @copyright 2015 eMerchantPay Ltd.
17
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License, version 2 (GPL-2.0)
18
*/
19
@@ -55,7 +55,7 @@ class EMerchantPay_Genesis_Block_Form_Direct extends Mage_Payment_Block_Form
55
$availableTypes = $method->getConfigData('cctypes');
56
if ($availableTypes) {
57
$availableTypes = explode(',', $availableTypes);
58
- foreach ($types as $code=>$name) {
59
if (!in_array($code, $availableTypes)) {
60
unset($types[$code]);
61
}
@@ -106,7 +106,7 @@ class EMerchantPay_Genesis_Block_Form_Direct extends Mage_Payment_Block_Form
106
{
107
if ($this->getMethod()) {
108
$configData = $this->getMethod()->getConfigData('useccv');
109
- if(is_null($configData)){
110
return true;
111
}
112
return (bool) $configData;
@@ -127,4 +127,14 @@ class EMerchantPay_Genesis_Block_Form_Direct extends Mage_Payment_Block_Form
127
128
return parent::_toHtml();
129
}
130
- }
1
<?php
2
/*
3
+ * Copyright (C) 2016 eMerchantPay Ltd.
4
*
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
13
* GNU General Public License for more details.
14
*
15
* @author eMerchantPay
16
+ * @copyright 2016 eMerchantPay Ltd.
17
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License, version 2 (GPL-2.0)
18
*/
19
55
$availableTypes = $method->getConfigData('cctypes');
56
if ($availableTypes) {
57
$availableTypes = explode(',', $availableTypes);
58
+ foreach ($types as $code => $name) {
59
if (!in_array($code, $availableTypes)) {
60
unset($types[$code]);
61
}
106
{
107
if ($this->getMethod()) {
108
$configData = $this->getMethod()->getConfigData('useccv');
109
+ if (is_null($configData)) {
110
return true;
111
}
112
return (bool) $configData;
127
128
return parent::_toHtml();
129
}
130
+
131
+ /**
132
+ * Determines if a Nominal Items were added to the cart
133
+ * @return bool
134
+ */
135
+ public function getHasNominalItems()
136
+ {
137
+ return
138
+ Mage::helper("emerchantpay")->getCheckoutHasRecurringItems();
139
+ }
140
+ }
app/code/community/EMerchantPay/Genesis/Block/Info/Checkout.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/*
3
- * Copyright (C) 2015 eMerchantPay Ltd.
4
*
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
@@ -13,7 +13,7 @@
13
* GNU General Public License for more details.
14
*
15
* @author eMerchantPay
16
- * @copyright 2015 eMerchantPay Ltd.
17
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License, version 2 (GPL-2.0)
18
*/
19
@@ -34,4 +34,4 @@ class EMerchantPay_Genesis_Block_Info_Checkout extends Mage_Payment_Block_Info
34
{
35
return $this->getInfo()->getMethodInstance()->getCode();
36
}
37
- }
1
<?php
2
/*
3
+ * Copyright (C) 2016 eMerchantPay Ltd.
4
*
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
13
* GNU General Public License for more details.
14
*
15
* @author eMerchantPay
16
+ * @copyright 2016 eMerchantPay Ltd.
17
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License, version 2 (GPL-2.0)
18
*/
19
34
{
35
return $this->getInfo()->getMethodInstance()->getCode();
36
}
37
+ }
app/code/community/EMerchantPay/Genesis/Block/Info/Direct.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/*
3
- * Copyright (C) 2015 eMerchantPay Ltd.
4
*
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
@@ -13,7 +13,7 @@
13
* GNU General Public License for more details.
14
*
15
* @author eMerchantPay
16
- * @copyright 2015 eMerchantPay Ltd.
17
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License, version 2 (GPL-2.0)
18
*/
19
@@ -34,4 +34,4 @@ class EMerchantPay_Genesis_Block_Info_Direct extends Mage_Payment_Block_Info
34
{
35
return $this->getInfo()->getMethodInstance()->getCode();
36
}
37
- }
1
<?php
2
/*
3
+ * Copyright (C) 2016 eMerchantPay Ltd.
4
*
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
13
* GNU General Public License for more details.
14
*
15
* @author eMerchantPay
16
+ * @copyright 2016 eMerchantPay Ltd.
17
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License, version 2 (GPL-2.0)
18
*/
19
34
{
35
return $this->getInfo()->getMethodInstance()->getCode();
36
}
37
+ }
app/code/community/EMerchantPay/Genesis/Block/Redirect/Checkout.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/*
3
- * Copyright (C) 2015 eMerchantPay Ltd.
4
*
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
@@ -13,7 +13,7 @@
13
* GNU General Public License for more details.
14
*
15
* @author eMerchantPay
16
- * @copyright 2015 eMerchantPay Ltd.
17
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License, version 2 (GPL-2.0)
18
*/
19
@@ -98,4 +98,4 @@ class EMerchantPay_Genesis_Block_Redirect_Checkout extends Mage_Core_Block_Templ
98
{
99
$this->unique_id = Mage::helper('core')->uniqHash();
100
}
101
- }
1
<?php
2
/*
3
+ * Copyright (C) 2016 eMerchantPay Ltd.
4
*
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
13
* GNU General Public License for more details.
14
*
15
* @author eMerchantPay
16
+ * @copyright 2016 eMerchantPay Ltd.
17
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License, version 2 (GPL-2.0)
18
*/
19
98
{
99
$this->unique_id = Mage::helper('core')->uniqHash();
100
}
101
+ }
app/code/community/EMerchantPay/Genesis/Block/Redirect/Direct.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/*
3
- * Copyright (C) 2015 eMerchantPay Ltd.
4
*
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
@@ -13,7 +13,7 @@
13
* GNU General Public License for more details.
14
*
15
* @author eMerchantPay
16
- * @copyright 2015 eMerchantPay Ltd.
17
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License, version 2 (GPL-2.0)
18
*/
19
@@ -98,4 +98,4 @@ class EMerchantPay_Genesis_Block_Redirect_Direct extends Mage_Core_Block_Templat
98
{
99
$this->unique_id = Mage::helper('core')->uniqHash();
100
}
101
- }
1
<?php
2
/*
3
+ * Copyright (C) 2016 eMerchantPay Ltd.
4
*
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
13
* GNU General Public License for more details.
14
*
15
* @author eMerchantPay
16
+ * @copyright 2016 eMerchantPay Ltd.
17
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License, version 2 (GPL-2.0)
18
*/
19
98
{
99
$this->unique_id = Mage::helper('core')->uniqHash();
100
}
101
+ }
app/code/community/EMerchantPay/Genesis/Helper/Data.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/*
3
- * Copyright (C) 2015 eMerchantPay Ltd.
4
*
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
@@ -13,7 +13,7 @@
13
* GNU General Public License for more details.
14
*
15
* @author eMerchantPay
16
- * @copyright 2015 eMerchantPay Ltd.
17
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License, version 2 (GPL-2.0)
18
*/
19
@@ -24,28 +24,21 @@
24
*/
25
class EMerchantPay_Genesis_Helper_Data extends Mage_Core_Helper_Abstract
26
{
27
/**
28
* Include Genesis library
29
*
30
* @return void
31
*/
32
- public function initLibrary()
33
{
34
- // Mitigate PHP Bug #52339, as Magento already registers their AutoLoader
35
if (!class_exists('\Genesis\Genesis', false)) {
36
- $genesisAutoLoadParams = array(
37
- 'magento_root' => MAGENTO_ROOT,
38
- 'integrated_genesis_lib_auto_loader' => Mage::getBaseDir('lib') . DS . 'Genesis' . DS . 'vendor' . DS . 'autoload.php',
39
- 'genesis_composer_dir' => 'genesisgateway',
40
- 'check_genesis_lib_version' => '1',
41
- 'required_genesis_lib_version' => ">= 1.4"
42
- );
43
-
44
- $genesisAutoLoadVarienObj = new Varien_Object($genesisAutoLoadParams);
45
-
46
- /* This Event will be handled from Observer EMerchantPay_Genesis_Observer_GenesisAutoLoader (defined in etc/config.xml) */
47
- Mage::dispatchEvent('emerchantpay_genesis_init_library', array('genesis_auto_load_params' => $genesisAutoLoadVarienObj));
48
- }
49
}
50
51
/**
@@ -59,15 +52,33 @@ class EMerchantPay_Genesis_Helper_Data extends Mage_Core_Helper_Abstract
59
{
60
$this->initLibrary();
61
62
- \Genesis\Config::setEndpoint('emerchantpay');
63
64
- \Genesis\Config::setUsername($this->getConfigData($model, 'genesis_username'));
65
- \Genesis\Config::setPassword($this->getConfigData($model, 'genesis_password'));
66
67
- \Genesis\Config::setEnvironment($this->getConfigData($model, 'genesis_environment'));
68
69
\Genesis\Config::setToken(
70
- $this->getConfigData($model, 'genesis_token') ? $this->getConfigData($model, 'genesis_token') : ''
71
);
72
}
73
@@ -174,11 +185,29 @@ class EMerchantPay_Genesis_Helper_Data extends Mage_Core_Helper_Abstract
174
*
175
* @return string
176
*/
177
- public function getLocale()
178
{
179
- $locale = Mage::app()->getLocale()->getLocaleCode();
180
181
- return substr($locale, 0, 2);
182
}
183
184
/**
@@ -275,9 +304,14 @@ class EMerchantPay_Genesis_Helper_Data extends Mage_Core_Helper_Abstract
275
$product = $item->getProduct();
276
277
$productResult[$product->getSku()] = array(
278
- 'sku' => $product->getSku(),
279
- 'name' => $product->getName(),
280
- 'qty' => isset($productResult[$product->getSku()]['qty']) ? $productResult[$product->getSku()]['qty'] : 1,
281
);
282
}
283
@@ -290,6 +324,28 @@ class EMerchantPay_Genesis_Helper_Data extends Mage_Core_Helper_Abstract
290
return $description;
291
}
292
293
/**
294
* Restore customer Quote
295
*
@@ -344,6 +400,7 @@ class EMerchantPay_Genesis_Helper_Data extends Mage_Core_Helper_Abstract
344
)
345
->save();
346
break;
347
case \Genesis\API\Constants\Transaction\States::PENDING:
348
case \Genesis\API\Constants\Transaction\States::PENDING_ASYNC:
349
$order
@@ -355,9 +412,9 @@ class EMerchantPay_Genesis_Helper_Data extends Mage_Core_Helper_Abstract
355
)
356
->save();
357
break;
358
case \Genesis\API\Constants\Transaction\States::ERROR:
359
case \Genesis\API\Constants\Transaction\States::DECLINED:
360
-
361
/** @var Mage_Sales_Model_Order_Invoice $invoice */
362
foreach ($order->getInvoiceCollection() as $invoice) {
363
$invoice->cancel();
@@ -369,6 +426,7 @@ class EMerchantPay_Genesis_Helper_Data extends Mage_Core_Helper_Abstract
369
->save();
370
371
break;
372
default:
373
$order->save();
374
break;
@@ -400,7 +458,7 @@ class EMerchantPay_Genesis_Helper_Data extends Mage_Core_Helper_Abstract
400
);
401
402
foreach ($information as $field => $value) {
403
- if ($field == 'terminal_token') {
404
\Genesis\Config::setToken($value);
405
}
406
}
@@ -439,4 +497,335 @@ class EMerchantPay_Genesis_Helper_Data extends Mage_Core_Helper_Abstract
439
exit(0);
440
}
441
}
442
- }
1
<?php
2
/*
3
+ * Copyright (C) 2016 eMerchantPay Ltd.
4
*
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
13
* GNU General Public License for more details.
14
*
15
* @author eMerchantPay
16
+ * @copyright 2016 eMerchantPay Ltd.
17
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License, version 2 (GPL-2.0)
18
*/
19
24
*/
25
class EMerchantPay_Genesis_Helper_Data extends Mage_Core_Helper_Abstract
26
{
27
+ const SECURE_TRANSCTION_TYPE_SUFFIX = "3D";
28
+
29
+ const RAW_DETAILS_TRANSACTION_TYPE = 'transaction_type';
30
+ const RAW_DETAILS_TERMINAL_TOKEN = 'terminal_token';
31
+
32
/**
33
* Include Genesis library
34
*
35
* @return void
36
*/
37
+ public function initLibrary()
38
{
39
if (!class_exists('\Genesis\Genesis', false)) {
40
+ include Mage::getBaseDir('lib') . DS . 'Genesis' . DS . 'vendor' . DS . 'autoload.php';
41
+ }
42
}
43
44
/**
52
{
53
$this->initLibrary();
54
55
+ \Genesis\Config::setEndpoint(
56
+ \Genesis\API\Constants\Endpoints::EMERCHANTPAY
57
+ );
58
+
59
+ \Genesis\Config::setUsername(
60
+ $this->getConfigData(
61
+ $model,
62
+ 'genesis_username'
63
+ )
64
+ );
65
66
+ \Genesis\Config::setPassword(
67
+ $this->getConfigData(
68
+ $model,
69
+ 'genesis_password'
70
+ )
71
+ );
72
73
+ \Genesis\Config::setEnvironment(
74
+ $this->getConfigData(
75
+ $model,
76
+ 'genesis_environment'
77
+ )
78
+ );
79
80
\Genesis\Config::setToken(
81
+ $this->getConfigData($model, 'genesis_token') ?: ""
82
);
83
}
84
185
*
186
* @return string
187
*/
188
+ public function getLocale($default = 'en')
189
{
190
+ $languageCode = substr(
191
+ strtolower(
192
+ Mage::app()->getLocale()->getLocaleCode()
193
+ ),
194
+ 0,
195
+ 2
196
+ );
197
+
198
+ if (!\Genesis\API\Constants\i18n::isValidLanguageCode($languageCode)) {
199
+ $languageCode = $default;
200
+ }
201
+
202
+ if (!\Genesis\API\Constants\i18n::isValidLanguageCode($languageCode)) {
203
+ Mage::throwException(
204
+ $this->__('The provided argument is not a valid ISO-639-1 language code ' .
205
+ 'or is not supported by the Payment Gateway!'
206
+ )
207
+ );
208
+ }
209
210
+ return $languageCode;
211
}
212
213
/**
304
$product = $item->getProduct();
305
306
$productResult[$product->getSku()] = array(
307
+ 'sku' =>
308
+ $product->getSku(),
309
+ 'name' =>
310
+ $product->getName(),
311
+ 'qty' =>
312
+ isset($productResult[$product->getSku()]['qty'])
313
+ ? $productResult[$product->getSku()]['qty']
314
+ : 1,
315
);
316
}
317
324
return $description;
325
}
326
327
+ /**
328
+ * Get list of items in the order
329
+ *
330
+ * @see API parameter "Usage" or "Description"
331
+ *
332
+ * @param Mage_Payment_Model_Recurring_Profile $profile
333
+ *
334
+ * @return string Formatted List of Items
335
+ */
336
+ public function getRecurringProfileItemDescription($profile)
337
+ {
338
+ $product = $profile->getOrderItemInfo();
339
+
340
+ return
341
+ sprintf(
342
+ "%s (%s) x %d",
343
+ $product['name'],
344
+ $product['sku'],
345
+ $product['qty']
346
+ );
347
+ }
348
+
349
/**
350
* Restore customer Quote
351
*
400
)
401
->save();
402
break;
403
+
404
case \Genesis\API\Constants\Transaction\States::PENDING:
405
case \Genesis\API\Constants\Transaction\States::PENDING_ASYNC:
406
$order
412
)
413
->save();
414
break;
415
+
416
case \Genesis\API\Constants\Transaction\States::ERROR:
417
case \Genesis\API\Constants\Transaction\States::DECLINED:
418
/** @var Mage_Sales_Model_Order_Invoice $invoice */
419
foreach ($order->getInvoiceCollection() as $invoice) {
420
$invoice->cancel();
426
->save();
427
428
break;
429
+
430
default:
431
$order->save();
432
break;
458
);
459
460
foreach ($information as $field => $value) {
461
+ if ($field == self::RAW_DETAILS_TERMINAL_TOKEN) {
462
\Genesis\Config::setToken($value);
463
}
464
}
497
exit(0);
498
}
499
}
500
+
501
+ /**
502
+ * @param string $model
503
+ * @param string $key
504
+ * @return bool
505
+ */
506
+ public function getConfigBoolValue($model, $key)
507
+ {
508
+ return
509
+ filter_var(
510
+ $this->getConfigData(
511
+ $model,
512
+ $key
513
+ ),
514
+ FILTER_VALIDATE_BOOLEAN
515
+ );
516
+ }
517
+
518
+ /**
519
+ * @param string $method
520
+ * @return bool
521
+ */
522
+ public function getIsMethodActive($method)
523
+ {
524
+ return $this->getConfigBoolValue($method, 'active');
525
+ }
526
+
527
+ /**
528
+ * Returns true if the WebSite is configured over Secured SSL Connection
529
+ * @return bool
530
+ */
531
+ public function getIsSecureConnectionEnabled()
532
+ {
533
+ return (bool) Mage::app()->getStore()->isCurrentlySecure();
534
+ }
535
+
536
+ /**
537
+ * @param string $method
538
+ * @param Mage_Sales_Model_Quote $quote
539
+ * @return bool
540
+ */
541
+ public function validateRecurringMethodMinMaxOrderTotal($method, $quote)
542
+ {
543
+ if (!$this->getCheckoutHasRecurringItems($quote)) {
544
+ return false;
545
+ }
546
+
547
+ $total = $this->getRecurringQuoteBaseNominalRowTotal(
548
+ $quote
549
+ );
550
+
551
+ $minTotal = $this->getConfigData($method, 'min_order_total');
552
+ $maxTotal = $this->getConfigData($method, 'max_order_total');
553
+ if ($total == 0 || !empty($minTotal) && $total < $minTotal || !empty($maxTotal) && $total > $maxTotal) {
554
+ return false;
555
+ }
556
+
557
+ return true;
558
+ }
559
+
560
+ /**
561
+ * @param string $method
562
+ * @param Mage_Sales_Model_Quote $quote
563
+ * @param bool $requiresSecureConnection
564
+ * @param bool $supportsRecurring
565
+ * @return bool
566
+ */
567
+ public function getIsMethodAvailable(
568
+ $method,
569
+ $quote,
570
+ $requiresSecureConnection = false,
571
+ $supportsRecurring = true
572
+ ) {
573
+ return
574
+ $this->getIsMethodActive($method) &&
575
+ (!$requiresSecureConnection || $this->getIsSecureConnectionEnabled()) &&
576
+ (
577
+ ($supportsRecurring &&
578
+ (!$quote->hasNominalItems() || $this->getConfigBoolValue($method, 'recurring_enabled'))
579
+ ) ||
580
+ (!$supportsRecurring && !$quote->hasNominalItems())
581
+ );
582
+ }
583
+
584
+ /**
585
+ * @param string $transactionType
586
+ * @return bool
587
+ */
588
+ public function getIsTransaction3dSecure($transactionType)
589
+ {
590
+ return
591
+ $this->getStringEndsWith(
592
+ strtoupper($transactionType),
593
+ self::SECURE_TRANSCTION_TYPE_SUFFIX
594
+ );
595
+ }
596
+
597
+ /**
598
+ * @param string $haystack
599
+ * @param string $needle
600
+ * @return bool
601
+ */
602
+ public function getStringEndsWith($haystack, $needle)
603
+ {
604
+ $length = strlen($needle);
605
+ if ($length == 0) {
606
+ return true;
607
+ }
608
+
609
+ return (substr($haystack, -$length) === $needle);
610
+ }
611
+
612
+ /**
613
+ * Get the Remote Address of the machine
614
+ * @return string
615
+ */
616
+ public function getRemoteAddress()
617
+ {
618
+ $remoteAddress = Mage::helper('core/http')->getRemoteAddr(false);
619
+
620
+ if (empty($remoteAddress) && function_exists("parse_url") && function_exists("gethostbyname")) {
621
+ $parsedUrl = parse_url(
622
+ Mage::getBaseUrl(Mage_Core_Model_store::URL_TYPE_WEB)
623
+ );
624
+
625
+ if (isset($parsedUrl['host'])) {
626
+ $remoteAddress = gethostbyname(
627
+ $parsedUrl['host']
628
+ );
629
+ }
630
+ }
631
+
632
+ return $remoteAddress ?: "127.0.0.1";
633
+ }
634
+
635
+ /**
636
+ * Builds a Genesis Transaction Class name by Genesis Transaction
637
+ * @param string $transactionType
638
+ * @return string
639
+ */
640
+ public function getGenesisTransactionClassName($transactionType)
641
+ {
642
+ $this->initLibrary();
643
+
644
+ $className = \Genesis\Utils\Common::snakeCaseToCamelCase($transactionType);
645
+
646
+ if ($this->getIsTransaction3dSecure($transactionType)) {
647
+ $className =
648
+ substr(
649
+ $className,
650
+ 0,
651
+ strlen($className) - strlen(self::SECURE_TRANSCTION_TYPE_SUFFIX)
652
+ ) .
653
+ self::SECURE_TRANSCTION_TYPE_SUFFIX;
654
+ }
655
+
656
+ return $className;
657
+ }
658
+
659
+ /**
660
+ * @param string $transactionType
661
+ * @return bool
662
+ */
663
+ public function getIsTransactionTypeInitRecurring($transactionType)
664
+ {
665
+ $this->initLibrary();
666
+
667
+ $initRecurringTransactionTypes = array(
668
+ \Genesis\API\Constants\Transaction\Types::INIT_RECURRING_SALE,
669
+ \Genesis\API\Constants\Transaction\Types::INIT_RECURRING_SALE_3D
670
+ );
671
+
672
+ return !empty($transactionType) && in_array($transactionType, $initRecurringTransactionTypes);
673
+ }
674
+
675
+ /**
676
+ * Cancels a recurring profile when capture transaction is refunded
677
+ * @param Mage_Sales_Model_Order_Payment_Transaction $captureTransaction
678
+ * @return string|null
679
+ */
680
+ public function checkAndCancelRecurringProfile($captureTransaction)
681
+ {
682
+ $profileReferenceId = null;
683
+
684
+ if ($captureTransaction && $captureTransaction->getId()) {
685
+ $captureTransactionType = $this->getGenesisPaymentTransactionType(
686
+ $captureTransaction
687
+ );
688
+
689
+ if ($captureTransactionType && $this->getIsTransactionTypeInitRecurring($captureTransactionType)) {
690
+ $recurringProfileReferenceId =
691
+ $captureTransaction->getParentTxnId()
692
+ ?: $captureTransaction->getTxnId();
693
+
694
+ $recurringProfile = Mage::getModel("sales/recurring_profile")->load(
695
+ $recurringProfileReferenceId,
696
+ 'reference_id'
697
+ );
698
+
699
+ if ($recurringProfile && $recurringProfile->getId()) {
700
+ if ($recurringProfile->getState() != Mage_Sales_Model_Recurring_Profile::STATE_CANCELED) {
701
+ $recurringProfile->setState(
702
+ Mage_Sales_Model_Recurring_Profile::STATE_CANCELED
703
+ );
704
+
705
+ $recurringProfile->save();
706
+
707
+ $profileReferenceId = $recurringProfile->getReferenceId();
708
+ }
709
+ }
710
+ }
711
+ }
712
+
713
+ return $profileReferenceId;
714
+ }
715
+
716
+ /**
717
+ * Extracts a Transaction Param Value from Transaction Additional Information
718
+ * @param Mage_Sales_Model_Order_Payment_Transaction $transaction
719
+ * @return string|null
720
+ */
721
+ public function getGenesisPaymentTransactionParam($transaction, $paramName)
722
+ {
723
+ if (!is_object($transaction) || !$transaction->getId()) {
724
+ return null;
725
+ }
726
+
727
+ $transactionRawDetails = $transaction->getAdditionalInformation(
728
+ Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS
729
+ );
730
+
731
+ return
732
+ isset($transactionRawDetails[$paramName])
733
+ ? $transactionRawDetails[$paramName]
734
+ : null;
735
+ }
736
+
737
+ /**
738
+ * @param Mage_Sales_Model_Order_Payment_Transaction $transaction
739
+ * @return string|null
740
+ */
741
+ public function getGenesisPaymentTransactionType($transaction)
742
+ {
743
+ return $this->getGenesisPaymentTransactionParam(
744
+ $transaction,
745
+ self::RAW_DETAILS_TRANSACTION_TYPE
746
+ );
747
+ }
748
+
749
+ /**
750
+ * @param Mage_Sales_Model_Order_Payment_Transaction $transaction
751
+ * @return string|null
752
+ */
753
+ public function getGenesisPaymentTransactionToken($transaction)
754
+ {
755
+ return $this->getGenesisPaymentTransactionParam(
756
+ $transaction,
757
+ self::RAW_DETAILS_TERMINAL_TOKEN
758
+ );
759
+ }
760
+
761
+ /**
762
+ * Get Admin Session (Used to display Success and Error Messages)
763
+ * @return Mage_Core_Model_Session_Abstract
764
+ */
765
+ public function getAdminSession()
766
+ {
767
+ return Mage::getSingleton("adminhtml/session");
768
+ }
769
+
770
+ /**
771
+ * Get Init Recurring Fee Config Value for Method
772
+ * @param string $methodCode
773
+ * @return string
774
+ */
775
+ public function getMethodInitRecurringFee($methodCode)
776
+ {
777
+ return str_replace(
778
+ ',',
779
+ '.',
780
+ $this->getConfigData(
781
+ $methodCode,
782
+ 'recurring_initial_fee'
783
+ )
784
+ );
785
+ }
786
+
787
+ /**
788
+ * Returns a formatted MySQL Datetime Value
789
+ * @param int $time
790
+ * @return string
791
+ */
792
+ public function formatDateTimeToMySQLDateTime($time)
793
+ {
794
+ return
795
+ strftime(
796
+ '%Y-%m-%d %H:%M:%S',
797
+ $time
798
+ );
799
+ }
800
+
801
+ /**
802
+ * Detects if a Recurring Item has been added to the Cart
803
+ * @param Mage_Sales_Model_Quote|null $quote
804
+ * @return bool
805
+ */
806
+ public function getCheckoutHasRecurringItems($quote = null)
807
+ {
808
+ $quote = $quote ?: $this->getCheckoutSession()->getQuote();
809
+
810
+ return $quote->hasRecurringItems();
811
+ }
812
+
813
+ /**
814
+ * @param Mage_Sales_Model_Quote $quote
815
+ * @return float
816
+ */
817
+ public function getRecurringQuoteBaseNominalRowTotal($quote)
818
+ {
819
+ $baseNominalRowTotal = 0;
820
+
821
+ foreach ($quote->getAllAddresses() as $quoteAddress) {
822
+ foreach ($quoteAddress->getAllNominalItems() as $nominalItem) {
823
+ if ($nominalItem->getIsNominal()) {
824
+ $baseNominalRowTotal += $nominalItem->getBaseNominalRowTotal();
825
+ }
826
+ }
827
+ }
828
+
829
+ return $baseNominalRowTotal;
830
+ }
831
+ }
app/code/community/EMerchantPay/Genesis/Model/Admin/Checkout/Options/Transaction/Recurring/Type.php ADDED
@@ -0,0 +1,74 @@
1
+ <?php
2
+ /*
3
+ * Copyright (C) 2016 eMerchantPay Ltd.
4
+ *
5
+ * This program is free software; you can redistribute it and/or
6
+ * modify it under the terms of the GNU General Public License
7
+ * as published by the Free Software Foundation; either version 2
8
+ * of the License, or (at your option) any later version.
9
+ *
10
+ * This program is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ * GNU General Public License for more details.
14
+ *
15
+ * @author eMerchantPay
16
+ * @copyright 2016 eMerchantPay Ltd.
17
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License, version 2 (GPL-2.0)
18
+ */
19
+
20
+ /**
21
+ * Class EMerchantPay_Genesis_Model_Admin_Transaction_Type
22
+ *
23
+ * Admin options Drop-down for Genesis Transaction Types
24
+ */
25
+ class EMerchantPay_Genesis_Model_Admin_Checkout_Options_Transaction_Recurring_Type
26
+ {
27
+ /**
28
+ * Pre-load the required files
29
+ */
30
+ public function __construct()
31
+ {
32
+ /** @var EMerchantPay_Genesis_Helper_Data $helper */
33
+ $helper = Mage::helper('emerchantpay');
34
+
35
+ $helper->initLibrary();
36
+ }
37
+
38
+ /**
39
+ * Return the transaction types for an Options field
40
+ *
41
+ * @return array
42
+ */
43
+ public function toOptionArray()
44
+ {
45
+ $options = array();
46
+
47
+ foreach ($this->getTransactionTypes() as $code => $name) {
48
+ $options[] = array(
49
+ 'value' => $code,
50
+ 'label' => $name
51
+ );
52
+ }
53
+
54
+ return $options;
55
+ }
56
+
57
+ /**
58
+ * Get the transaction types as:
59
+ *
60
+ * key = Code Name
61
+ * value = Localized Name
62
+ *
63
+ * @return array
64
+ */
65
+ protected function getTransactionTypes()
66
+ {
67
+ return array(
68
+ \Genesis\API\Constants\Transaction\Types::INIT_RECURRING_SALE =>
69
+ Mage::helper('emerchantpay')->__('Init Recurring Sale'),
70
+ \Genesis\API\Constants\Transaction\Types::INIT_RECURRING_SALE_3D =>
71
+ Mage::helper('emerchantpay')->__('Init Recurring Sale (3D-Secure)')
72
+ );
73
+ }
74
+ }
app/code/community/EMerchantPay/Genesis/Model/Admin/Checkout/Options/Transaction/Type.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/*
3
- * Copyright (C) 2015 eMerchantPay Ltd.
4
*
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
@@ -13,7 +13,7 @@
13
* GNU General Public License for more details.
14
*
15
* @author eMerchantPay
16
- * @copyright 2015 eMerchantPay Ltd.
17
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License, version 2 (GPL-2.0)
18
*/
19
@@ -34,6 +34,7 @@ class EMerchantPay_Genesis_Model_Admin_Checkout_Options_Transaction_Type
34
35
$helper->initLibrary();
36
}
37
/**
38
* Return the transaction types for an Options field
39
*
@@ -43,7 +44,7 @@ class EMerchantPay_Genesis_Model_Admin_Checkout_Options_Transaction_Type
43
{
44
$options = array();
45
46
- foreach (static::getTransactionTypes() as $code => $name) {
47
$options[] = array(
48
'value' => $code,
49
'label' => $name
@@ -61,7 +62,7 @@ class EMerchantPay_Genesis_Model_Admin_Checkout_Options_Transaction_Type
61
*
62
* @return array
63
*/
64
- static function getTransactionTypes()
65
{
66
return array(
67
\Genesis\API\Constants\Transaction\Types::ABNIDEAL =>
@@ -106,4 +107,4 @@ class EMerchantPay_Genesis_Model_Admin_Checkout_Options_Transaction_Type
106
Mage::helper('emerchantpay')->__('WebMoney'),
107
);
108
}
109
- }
1
<?php
2
/*
3
+ * Copyright (C) 2016 eMerchantPay Ltd.
4
*
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
13
* GNU General Public License for more details.
14
*
15
* @author eMerchantPay
16
+ * @copyright 2016 eMerchantPay Ltd.
17
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License, version 2 (GPL-2.0)
18
*/
19
34
35
$helper->initLibrary();
36
}
37
+
38
/**
39
* Return the transaction types for an Options field
40
*
44
{
45
$options = array();
46
47
+ foreach ($this->getTransactionTypes() as $code => $name) {
48
$options[] = array(
49
'value' => $code,
50
'label' => $name
62
*
63
* @return array
64
*/
65
+ protected function getTransactionTypes()
66
{
67
return array(
68
\Genesis\API\Constants\Transaction\Types::ABNIDEAL =>
107
Mage::helper('emerchantpay')->__('WebMoney'),
108
);
109
}
110
+ }
app/code/community/EMerchantPay/Genesis/Model/Admin/Direct/Options/Transaction/Recurring/Type.php ADDED
@@ -0,0 +1,74 @@
1
+ <?php
2
+ /*
3
+ * Copyright (C) 2016 eMerchantPay Ltd.
4
+ *
5
+ * This program is free software; you can redistribute it and/or
6
+ * modify it under the terms of the GNU General Public License
7
+ * as published by the Free Software Foundation; either version 2
8
+ * of the License, or (at your option) any later version.
9
+ *
10
+ * This program is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ * GNU General Public License for more details.
14
+ *
15
+ * @author eMerchantPay
16
+ * @copyright 2016 eMerchantPay Ltd.
17
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License, version 2 (GPL-2.0)
18
+ */
19
+
20
+ /**
21
+ * Class EMerchantPay_Genesis_Model_Admin_Transaction_Type
22
+ *
23
+ * Admin options Drop-down for Genesis Transaction Types
24
+ */
25
+ class EMerchantPay_Genesis_Model_Admin_Direct_Options_Transaction_Recurring_Type
26
+ {
27
+ /**
28
+ * Pre-load the required files
29
+ */
30
+ public function __construct()
31
+ {
32
+ /** @var EMerchantPay_Genesis_Helper_Data $helper */
33
+ $helper = Mage::helper('emerchantpay');
34
+
35
+ $helper->initLibrary();
36
+ }
37
+
38
+ /**
39
+ * Return the transaction types for an Options field
40
+ *
41
+ * @return array
42
+ */
43
+ public function toOptionArray()
44
+ {
45
+ $options = array();
46
+
47
+ foreach ($this->getTransactionTypes() as $code => $name) {
48
+ $options[] = array(
49
+ 'value' => $code,
50
+ 'label' => $name
51
+ );
52
+ }
53
+
54
+ return $options;
55
+ }
56
+
57
+ /**
58
+ * Get the transaction types as:
59
+ *
60
+ * key = Code Name
61
+ * value = Localized Name
62
+ *
63
+ * @return array
64
+ */
65
+ protected function getTransactionTypes()
66
+ {
67
+ return array(
68
+ \Genesis\API\Constants\Transaction\Types::INIT_RECURRING_SALE =>
69
+ Mage::helper('emerchantpay')->__('Init Recurring Sale'),
70
+ \Genesis\API\Constants\Transaction\Types::INIT_RECURRING_SALE_3D =>
71
+ Mage::helper('emerchantpay')->__('Init Recurring Sale (3D-Secure)')
72
+ );
73
+ }
74
+ }
app/code/community/EMerchantPay/Genesis/Model/Admin/Direct/Options/Transaction/Type.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/*
3
- * Copyright (C) 2015 eMerchantPay Ltd.
4
*
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
@@ -13,7 +13,7 @@
13
* GNU General Public License for more details.
14
*
15
* @author eMerchantPay
16
- * @copyright 2015 eMerchantPay Ltd.
17
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License, version 2 (GPL-2.0)
18
*/
19
@@ -43,7 +43,7 @@ class EMerchantPay_Genesis_Model_Admin_Direct_Options_Transaction_Type
43
{
44
$options = array();
45
46
- foreach (static::getTransactionTypes() as $code => $name) {
47
$options[] = array(
48
'value' => $code,
49
'label' => $name
@@ -61,7 +61,7 @@ class EMerchantPay_Genesis_Model_Admin_Direct_Options_Transaction_Type
61
*
62
* @return array
63
*/
64
- static function getTransactionTypes()
65
{
66
return array(
67
\Genesis\API\Constants\Transaction\Types::AUTHORIZE =>
@@ -74,4 +74,4 @@ class EMerchantPay_Genesis_Model_Admin_Direct_Options_Transaction_Type
74
Mage::helper('emerchantpay')->__('Sale (3D-Secure)'),
75
);
76
}
77
- }
1
<?php
2
/*
3
+ * Copyright (C) 2016 eMerchantPay Ltd.
4
*
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
13
* GNU General Public License for more details.
14
*
15
* @author eMerchantPay
16
+ * @copyright 2016 eMerchantPay Ltd.
17
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License, version 2 (GPL-2.0)
18
*/
19
43
{
44
$options = array();
45
46
+ foreach ($this->getTransactionTypes() as $code => $name) {
47
$options[] = array(
48
'value' => $code,
49
'label' => $name
61
*
62
* @return array
63
*/
64
+ protected function getTransactionTypes()
65
{
66
return array(
67
\Genesis\API\Constants\Transaction\Types::AUTHORIZE =>
74
Mage::helper('emerchantpay')->__('Sale (3D-Secure)'),
75
);
76
}
77
+ }
app/code/community/EMerchantPay/Genesis/Model/Admin/Environment.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/*
3
- * Copyright (C) 2015 eMerchantPay Ltd.
4
*
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
@@ -13,7 +13,7 @@
13
* GNU General Public License for more details.
14
*
15
* @author eMerchantPay
16
- * @copyright 2015 eMerchantPay Ltd.
17
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License, version 2 (GPL-2.0)
18
*/
19
@@ -33,7 +33,7 @@ class EMerchantPay_Genesis_Model_Admin_Environment
33
{
34
$options = array();
35
36
- foreach (static::getEnvironmentOptions() as $code => $name) {
37
$options[] = array(
38
'value' => $code,
39
'label' => $name
@@ -48,11 +48,11 @@ class EMerchantPay_Genesis_Model_Admin_Environment
48
*
49
* @return array
50
*/
51
- static function getEnvironmentOptions()
52
{
53
return array(
54
'sandbox' => Mage::helper('emerchantpay')->__('Yes'),
55
'production' => Mage::helper('emerchantpay')->__('No'),
56
);
57
}
58
- }
1
<?php
2
/*
3
+ * Copyright (C) 2016 eMerchantPay Ltd.
4
*
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
13
* GNU General Public License for more details.
14
*
15
* @author eMerchantPay
16
+ * @copyright 2016 eMerchantPay Ltd.
17
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License, version 2 (GPL-2.0)
18
*/
19
33
{
34
$options = array();
35
36
+ foreach ($this->getEnvironmentOptions() as $code => $name) {
37
$options[] = array(
38
'value' => $code,
39
'label' => $name
48
*
49
* @return array
50
*/
51
+ protected function getEnvironmentOptions()
52
{
53
return array(
54
'sandbox' => Mage::helper('emerchantpay')->__('Yes'),
55
'production' => Mage::helper('emerchantpay')->__('No'),
56
);
57
}
58
+ }
app/code/community/EMerchantPay/Genesis/Model/Checkout.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/*
3
- * Copyright (C) 2015 eMerchantPay Ltd.
4
*
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
@@ -13,14 +13,21 @@
13
* GNU General Public License for more details.
14
*
15
* @author eMerchantPay
16
- * @copyright 2015 eMerchantPay Ltd.
17
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License, version 2 (GPL-2.0)
18
*/
19
20
- class EMerchantPay_Genesis_Model_Checkout extends Mage_Payment_Model_Method_Abstract
21
{
22
protected $_code = 'emerchantpay_checkout';
23
24
protected $_formBlockType = 'emerchantpay/form_checkout';
25
protected $_infoBlockType = 'emerchantpay/info_checkout';
26
@@ -34,8 +41,9 @@ class EMerchantPay_Genesis_Model_Checkout extends Mage_Payment_Model_Method_Abst
34
protected $_canUseInternal = false;
35
protected $_canUseCheckout = true;
36
37
- protected $_canUseForMultishipping = false;
38
- protected $_canFetchTransactionInfo = true;
39
40
/**
41
* WPF Create method piggyback-ing the Magento's internal Authorize method
@@ -60,6 +68,8 @@ class EMerchantPay_Genesis_Model_Checkout extends Mage_Payment_Model_Method_Abst
60
61
$genesis = new \Genesis\Genesis('WPF\Create');
62
63
$genesis
64
->request()
65
->setTransactionId(
@@ -67,12 +77,14 @@ class EMerchantPay_Genesis_Model_Checkout extends Mage_Payment_Model_Method_Abst
67
$order->getIncrementId()
68
)
69
)
70
- ->setCurrency($order->getBaseCurrencyCode())
71
->setAmount($amount)
72
->setUsage(
73
$this->getHelper()->__('Magento Payment')
74
)
75
- ->setDescription($this->getHelper()->getItemList($order))
76
->setCustomerPhone($billing->getTelephone())
77
->setCustomerEmail($order->getCustomerEmail())
78
->setNotificationUrl(
@@ -109,10 +121,29 @@ class EMerchantPay_Genesis_Model_Checkout extends Mage_Payment_Model_Method_Abst
109
foreach ($this->getTransactionTypes() as $transaction_type) {
110
if (is_array($transaction_type)) {
111
$genesis->request()->addTransactionType(
112
- $transaction_type['name'], $transaction_type['parameters']
113
);
114
} else {
115
- $genesis->request()->addTransactionType($transaction_type);
116
}
117
}
118
@@ -163,8 +194,13 @@ class EMerchantPay_Genesis_Model_Checkout extends Mage_Payment_Model_Method_Abst
163
164
/* Capture should only be possible, when Authorize Transaction Exists */
165
if (!isset($authorize) || $authorize === false) {
166
- Mage::log('Capture transaction for order #' . $payment->getOrder()->getIncrementId() . ' cannot be finished (No Authorize Transaction exists)');
167
- return $this;
168
}
169
170
$reference_id = $authorize->getTxnId();
@@ -185,7 +221,7 @@ class EMerchantPay_Genesis_Model_Checkout extends Mage_Payment_Model_Method_Abst
185
$reference_id
186
)
187
->setCurrency(
188
- $payment->getOrder()->getBaseCurrencyCode()
189
)
190
->setAmount(
191
$amount
@@ -193,9 +229,11 @@ class EMerchantPay_Genesis_Model_Checkout extends Mage_Payment_Model_Method_Abst
193
194
$genesis->execute();
195
196
$payment
197
->setTransactionId(
198
- $genesis->response()->getResponseObject()->unique_id
199
)
200
->setParentTransactionId(
201
$reference_id
@@ -208,14 +246,25 @@ class EMerchantPay_Genesis_Model_Checkout extends Mage_Payment_Model_Method_Abst
208
)
209
->setTransactionAdditionalInfo(
210
array(
211
- Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS => $this->getHelper()->getArrayFromGatewayResponse(
212
- $genesis->response()->getResponseObject()
213
- )
214
),
215
null
216
);
217
218
$payment->save();
219
} catch (Exception $exception) {
220
Mage::logException($exception);
221
@@ -243,13 +292,20 @@ class EMerchantPay_Genesis_Model_Checkout extends Mage_Payment_Model_Method_Abst
243
$this->getHelper()->initClient($this->getCode());
244
245
$this->getHelper()->setTokenByPaymentTransaction($payment);
246
-
247
- $capture = $payment->lookupTransaction(null, Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE);
248
249
/* Refund Transaction is only possible, when Capture Transaction Exists */
250
if (!isset($capture) || $capture === false) {
251
- Mage::log('Refund transaction for order #' . $payment->getOrder()->getIncrementId() . ' could not be completed! (No Capture Transaction Exists');
252
- return $this;
253
}
254
255
$reference_id = $capture->getTxnId();
@@ -259,26 +315,28 @@ class EMerchantPay_Genesis_Model_Checkout extends Mage_Payment_Model_Method_Abst
259
$genesis
260
->request()
261
->setTransactionId(
262
- $this->getHelper()->genTransactionId(
263
- $payment->getOrder()->getIncrementId()
264
- )
265
)
266
->setRemoteIp(
267
- $this->getHelper('core/http')->getRemoteAddr(false)
268
)
269
->setReferenceId(
270
- $reference_id
271
)
272
->setCurrency(
273
- $payment->getOrder()->getBaseCurrencyCode()
274
)
275
->setAmount($amount);
276
277
$genesis->execute();
278
279
$payment
280
->setTransactionId(
281
- $genesis->response()->getResponseObject()->unique_id
282
)
283
->setParentTransactionId(
284
$reference_id
@@ -291,14 +349,42 @@ class EMerchantPay_Genesis_Model_Checkout extends Mage_Payment_Model_Method_Abst
291
)
292
->setTransactionAdditionalInfo(
293
array(
294
- Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS => $this->getHelper()->getArrayFromGatewayResponse(
295
- $genesis->response()->getResponseObject()
296
- )
297
),
298
null
299
);
300
301
$payment->save();
302
} catch (Exception $exception) {
303
Mage::logException($exception);
304
@@ -351,9 +437,11 @@ class EMerchantPay_Genesis_Model_Checkout extends Mage_Payment_Model_Method_Abst
351
352
$genesis->execute();
353
354
$payment
355
->setTransactionId(
356
- $genesis->response()->getResponseObject()->unique_id
357
)
358
->setParentTransactionId(
359
$reference_id
@@ -366,14 +454,25 @@ class EMerchantPay_Genesis_Model_Checkout extends Mage_Payment_Model_Method_Abst
366
)
367
->setTransactionAdditionalInfo(
368
array(
369
- Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS => $this->getHelper()->getArrayFromGatewayResponse(
370
- $genesis->response()->getResponseObject()
371
- )
372
),
373
null
374
);
375
376
$payment->save();
377
} catch (Exception $exception) {
378
Mage::logException($exception);
379
@@ -424,8 +523,7 @@ class EMerchantPay_Genesis_Model_Checkout extends Mage_Payment_Model_Method_Abst
424
// Try to extract transaction details from the Gateway response
425
if ($reconcile->unique_id == $transactionId) {
426
$transaction_details = $reconcile;
427
- }
428
- else {
429
if ($reconcile->payment_transaction instanceof stdClass) {
430
if ($reconcile->payment_transaction->unique_id == $transactionId) {
431
$transaction_details = $reconcile->payment_transaction;
@@ -449,9 +547,10 @@ class EMerchantPay_Genesis_Model_Checkout extends Mage_Payment_Model_Method_Abst
449
// Set the default/updated transaction details
450
$payment->setAdditionalInformation(
451
array(
452
- Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS => $this->getHelper()->getArrayFromGatewayResponse(
453
- $transaction_details
454
- )
455
),
456
null
457
);
@@ -495,13 +594,22 @@ class EMerchantPay_Genesis_Model_Checkout extends Mage_Payment_Model_Method_Abst
495
return false;
496
}
497
498
public function processNotification($checkout_transaction)
499
{
500
try {
501
$this->getHelper()->initClient($this->getCode());
502
503
/** @var Mage_Sales_Model_Order_Payment_Transaction $transaction */
504
- $transaction = Mage::getModel('sales/order_payment_transaction')->load($checkout_transaction->unique_id, 'txn_id');
505
506
$order = $transaction->getOrder();
507
@@ -531,24 +639,26 @@ class EMerchantPay_Genesis_Model_Checkout extends Mage_Payment_Model_Method_Abst
531
->resetTransactionAdditionalInfo()
532
->setTransactionAdditionalInfo(
533
array(
534
- Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS => $this->getHelper()->getArrayFromGatewayResponse(
535
- $payment_transaction
536
- )
537
),
538
null
539
);
540
541
if ($payment_transaction->status == \Genesis\API\Constants\Transaction\States::APPROVED) {
542
$payment->setIsTransactionClosed(false);
543
- }
544
- else {
545
$payment->setIsTransactionClosed(true);
546
}
547
548
switch ($payment_transaction->transaction_type) {
549
case \Genesis\API\Constants\Transaction\Types::AUTHORIZE:
550
case \Genesis\API\Constants\Transaction\Types::AUTHORIZE_3D:
551
- $payment->registerAuthorizationNotification($payment_transaction->amount, true);
552
break;
553
case \Genesis\API\Constants\Transaction\Types::ABNIDEAL:
554
case \Genesis\API\Constants\Transaction\Types::CASHU:
@@ -558,19 +668,46 @@ class EMerchantPay_Genesis_Model_Checkout extends Mage_Payment_Model_Method_Abst
558
case \Genesis\API\Constants\Transaction\Types::SALE:
559
case \Genesis\API\Constants\Transaction\Types::SALE_3D:
560
case \Genesis\API\Constants\Transaction\Types::SOFORT:
561
- $payment->registerCaptureNotification($payment_transaction->amount, true);
562
break;
563
default:
564
break;
565
}
566
567
568
$payment->save();
569
}
570
571
$this->getHelper()->setOrderState(
572
$order,
573
- isset($payment_transaction) ? $payment_transaction->status : $checkout_transaction->status
574
);
575
576
return true;
@@ -582,6 +719,21 @@ class EMerchantPay_Genesis_Model_Checkout extends Mage_Payment_Model_Method_Abst
582
return false;
583
}
584
585
/**
586
* Get the selected transaction types in array
587
*
@@ -591,8 +743,12 @@ class EMerchantPay_Genesis_Model_Checkout extends Mage_Payment_Model_Method_Abst
591
{
592
$processed_list = array();
593
594
- $selected_types = array_filter(
595
- explode(',', $this->getConfigData('genesis_types'))
596
);
597
598
$alias_map = array(
@@ -646,6 +802,13 @@ class EMerchantPay_Genesis_Model_Checkout extends Mage_Payment_Model_Method_Abst
646
return $this->getHelper()->getRedirectUrl('checkout');
647
}
648
649
/**
650
* Get the helper or return its instance
651
*
@@ -661,4 +824,321 @@ class EMerchantPay_Genesis_Model_Checkout extends Mage_Payment_Model_Method_Abst
661
return Mage::helper($helper);
662
}
663
}
664
- }
1
<?php
2
/*
3
+ * Copyright (C) 2016 eMerchantPay Ltd.
4
*
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
13
* GNU General Public License for more details.
14
*
15
* @author eMerchantPay
16
+ * @copyright 2016 eMerchantPay Ltd.
17
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License, version 2 (GPL-2.0)
18
*/
19
20
+ /**
21
+ * EMerchantPay Checkout Payment Method Model
22
+ *
23
+ * Class EMerchantPay_Genesis_Model_Checkout
24
+ */
25
+ class EMerchantPay_Genesis_Model_Checkout extends Mage_Payment_Model_Method_Abstract implements Mage_Payment_Model_Recurring_Profile_MethodInterface
26
{
27
protected $_code = 'emerchantpay_checkout';
28
29
+ const LOG_FILE_NAME = "emerchantpay_genesis.log";
30
+
31
protected $_formBlockType = 'emerchantpay/form_checkout';
32
protected $_infoBlockType = 'emerchantpay/info_checkout';
33
41
protected $_canUseInternal = false;
42
protected $_canUseCheckout = true;
43
44
+ protected $_canUseForMultishipping = false;
45
+ protected $_canFetchTransactionInfo = true;
46
+ protected $_canManageRecurringProfiles = true;
47
48
/**
49
* WPF Create method piggyback-ing the Magento's internal Authorize method
68
69
$genesis = new \Genesis\Genesis('WPF\Create');
70
71
+ $orderItemsList = $this->getHelper()->getItemList($order);
72
+
73
$genesis
74
->request()
75
->setTransactionId(
77
$order->getIncrementId()
78
)
79
)
80
+ ->setCurrency(
81
+ $order->getOrderCurrencyCode()
82
+ )
83
->setAmount($amount)
84
->setUsage(
85
$this->getHelper()->__('Magento Payment')
86
)
87
+ ->setDescription($orderItemsList)
88
->setCustomerPhone($billing->getTelephone())
89
->setCustomerEmail($order->getCustomerEmail())
90
->setNotificationUrl(
121
foreach ($this->getTransactionTypes() as $transaction_type) {
122
if (is_array($transaction_type)) {
123
$genesis->request()->addTransactionType(
124
+ $transaction_type['name'],
125
+ $transaction_type['parameters']
126
);
127
} else {
128
+ if (\Genesis\API\Constants\Transaction\Types::isPayByVoucher($transaction_type)) {
129
+ $parameters = [
130
+ 'card_type' =>
131
+ \Genesis\API\Constants\Transaction\Parameters\PayByVouchers\CardTypes::VIRTUAL,
132
+ 'redeem_type' =>
133
+ \Genesis\API\Constants\Transaction\Parameters\PayByVouchers\RedeemTypes::INSTANT
134
+ ];
135
+ if ($transaction_type == \Genesis\API\Constants\Transaction\Types::PAYBYVOUCHER_YEEPAY) {
136
+ $parameters['product_name'] = $orderItemsList;
137
+ $parameters['product_category'] = $orderItemsList;
138
+ }
139
+ $genesis
140
+ ->request()
141
+ ->addTransactionType($transaction_type, $parameters);
142
+ } else {
143
+ $genesis
144
+ ->request()
145
+ ->addTransactionType($transaction_type);
146
+ }
147
}
148
}
149
194
195
/* Capture should only be possible, when Authorize Transaction Exists */
196
if (!isset($authorize) || $authorize === false) {
197
+ Mage::log(
198
+ 'Capture transaction for order #' .
199
+ $payment->getOrder()->getIncrementId() .
200
+ ' cannot be finished (No Authorize Transaction exists)'
201
+ );
202
+
203
+ return $this;
204
}
205
206
$reference_id = $authorize->getTxnId();
221
$reference_id
222
)
223
->setCurrency(
224
+ $payment->getOrder()->getOrderCurrencyCode()
225
)
226
->setAmount(
227
$amount
229
230
$genesis->execute();
231
232
+ $responseObject = $genesis->response()->getResponseObject();
233
+
234
$payment
235
->setTransactionId(
236
+ $responseObject->unique_id
237
)
238
->setParentTransactionId(
239
$reference_id
246
)
247
->setTransactionAdditionalInfo(
248
array(
249
+ Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS =>
250
+ $this->getHelper()->getArrayFromGatewayResponse(
251
+ $responseObject
252
+ )
253
),
254
null
255
);
256
257
$payment->save();
258
+
259
+ if ($responseObject->status == \Genesis\API\Constants\Transaction\States::APPROVED) {
260
+ $this->getHelper()->getAdminSession()->addSuccess(
261
+ $responseObject->message
262
+ );
263
+ } else {
264
+ $this->getHelper()->getAdminSession()->addError(
265
+ $responseObject->message
266
+ );
267
+ }
268
} catch (Exception $exception) {
269
Mage::logException($exception);
270
292
$this->getHelper()->initClient($this->getCode());
293
294
$this->getHelper()->setTokenByPaymentTransaction($payment);
295
+
296
+ $capture = $payment->lookupTransaction(
297
+ null,
298
+ Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE
299
+ );
300
301
/* Refund Transaction is only possible, when Capture Transaction Exists */
302
if (!isset($capture) || $capture === false) {
303
+ Mage::log(
304
+ 'Refund transaction for order #' .
305
+ $payment->getOrder()->getIncrementId() .
306
+ ' could not be completed! (No Capture Transaction Exists'
307
+ );
308
+ return $this;
309
}
310
311
$reference_id = $capture->getTxnId();
315
$genesis
316
->request()
317
->setTransactionId(
318
+ $this->getHelper()->genTransactionId(
319
+ $payment->getOrder()->getIncrementId()
320
+ )
321
)
322
->setRemoteIp(
323
+ $this->getHelper('core/http')->getRemoteAddr(false)
324
)
325
->setReferenceId(
326
+ $reference_id
327
)
328
->setCurrency(
329
+ $payment->getOrder()->getOrderCurrencyCode()
330
)
331
->setAmount($amount);
332
333
$genesis->execute();
334
335
+ $responseObject = $genesis->response()->getResponseObject();
336
+
337
$payment
338
->setTransactionId(
339
+ $responseObject->unique_id
340
)
341
->setParentTransactionId(
342
$reference_id
349
)
350
->setTransactionAdditionalInfo(
351
array(
352
+ Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS =>
353
+ $this->getHelper()->getArrayFromGatewayResponse(
354
+ $responseObject
355
+ )
356
),
357
null
358
);
359
360
$payment->save();
361
+
362
+ if ($responseObject->status == \Genesis\API\Constants\Transaction\States::APPROVED) {
363
+ $this->getHelper()->getAdminSession()->addSuccess(
364
+ $responseObject->message
365
+ );
366
+
367
+ if (isset($capture) && $capture !== false) {
368
+ $canceledProfileReferenceId = $this->getHelper()->checkAndCancelRecurringProfile(
369
+ $capture
370
+ );
371
+
372
+ if (isset($canceledProfileReferenceId)) {
373
+ $this->getHelper()->getAdminSession()->addNotice(
374
+ $this->getHelper()->__(
375
+ sprintf(
376
+ "Profile #%s has been canceled!",
377
+ $canceledProfileReferenceId
378
+ )
379
+ )
380
+ );
381
+ }
382
+ }
383
+ } else {
384
+ $this->getHelper()->getAdminSession()->addError(
385
+ $responseObject->message
386
+ );
387
+ }
388
} catch (Exception $exception) {
389
Mage::logException($exception);
390
437
438
$genesis->execute();
439
440
+ $responseObject = $genesis->response()->getResponseObject();
441
+
442
$payment
443
->setTransactionId(
444
+ $responseObject->unique_id
445
)
446
->setParentTransactionId(
447
$reference_id
454
)
455
->setTransactionAdditionalInfo(
456
array(
457
+ Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS =>
458
+ $this->getHelper()->getArrayFromGatewayResponse(
459
+ $responseObject
460
+ )
461
),
462
null
463
);
464
465
$payment->save();
466
+
467
+ if ($responseObject->status == \Genesis\API\Constants\Transaction\States::APPROVED) {
468
+ $this->getHelper()->getAdminSession()->addSuccess(
469
+ $responseObject->message
470
+ );
471
+ } else {
472
+ $this->getHelper()->getAdminSession()->addError(
473
+ $responseObject->message
474
+ );
475
+ }
476
} catch (Exception $exception) {
477
Mage::logException($exception);
478
523
// Try to extract transaction details from the Gateway response
524
if ($reconcile->unique_id == $transactionId) {
525
$transaction_details = $reconcile;
526
+ } else {
527
if ($reconcile->payment_transaction instanceof stdClass) {
528
if ($reconcile->payment_transaction->unique_id == $transactionId) {
529
$transaction_details = $reconcile->payment_transaction;
547
// Set the default/updated transaction details
548
$payment->setAdditionalInformation(
549
array(
550
+ Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS =>
551
+ $this->getHelper()->getArrayFromGatewayResponse(
552
+ $transaction_details
553
+ )
554
),
555
null
556
);
594
return false;
595
}
596
597
+ /**
598
+ * Handle an incoming Genesis notification
599
+ *
600
+ * @param stdClass $reconcile
601
+ * @return bool
602
+ */
603
public function processNotification($checkout_transaction)
604
{
605
try {
606
$this->getHelper()->initClient($this->getCode());
607
608
/** @var Mage_Sales_Model_Order_Payment_Transaction $transaction */
609
+ $transaction = Mage::getModel('sales/order_payment_transaction')->load(
610
+ $checkout_transaction->unique_id,
611
+ 'txn_id'
612
+ );
613
614
$order = $transaction->getOrder();
615
639
->resetTransactionAdditionalInfo()
640
->setTransactionAdditionalInfo(
641
array(
642
+ Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS =>
643
+ $this->getHelper()->getArrayFromGatewayResponse(
644
+ $payment_transaction
645
+ )
646
),
647
null
648
);
649
650
if ($payment_transaction->status == \Genesis\API\Constants\Transaction\States::APPROVED) {
651
$payment->setIsTransactionClosed(false);
652
+ } else {
653
$payment->setIsTransactionClosed(true);
654
}
655
656
switch ($payment_transaction->transaction_type) {
657
case \Genesis\API\Constants\Transaction\Types::AUTHORIZE:
658
case \Genesis\API\Constants\Transaction\Types::AUTHORIZE_3D:
659
+ $payment->registerAuthorizationNotification(
660
+ $payment_transaction->amount
661
+ );
662
break;
663
case \Genesis\API\Constants\Transaction\Types::ABNIDEAL:
664
case \Genesis\API\Constants\Transaction\Types::CASHU:
668
case \Genesis\API\Constants\Transaction\Types::SALE:
669
case \Genesis\API\Constants\Transaction\Types::SALE_3D:
670
case \Genesis\API\Constants\Transaction\Types::SOFORT:
671
+ case \Genesis\API\Constants\Transaction\Types::INIT_RECURRING_SALE:
672
+ case \Genesis\API\Constants\Transaction\Types::INIT_RECURRING_SALE_3D:
673
+ $payment->registerCaptureNotification(
674
+ $payment_transaction->amount
675
+ );
676
break;
677
default:
678
break;
679
}
680
681
+ $isTransactionApproved =
682
+ ($payment_transaction->status == \Genesis\API\Constants\Transaction\States::APPROVED);
683
+
684
+ if ($this->getHelper()->getIsTransactionTypeInitRecurring($payment_transaction->transaction_type)) {
685
+ $recurringProfile = Mage::getModel('sales/recurring_profile')->load(
686
+ $checkout_transaction->unique_id,
687
+ 'reference_id'
688
+ );
689
+
690
+ if ($recurringProfile && $recurringProfile->getId()) {
691
+ if ($recurringProfile->getState() == Mage_Sales_Model_Recurring_Profile::STATE_PENDING) {
692
+ $recurringProfile->setState(
693
+ ($isTransactionApproved
694
+ ? Mage_Sales_Model_Recurring_Profile::STATE_ACTIVE
695
+ : Mage_Sales_Model_Recurring_Profile::STATE_CANCELED
696
+ )
697
+ );
698
+ $recurringProfile->save();
699
+ }
700
+ }
701
+ }
702
703
$payment->save();
704
}
705
706
$this->getHelper()->setOrderState(
707
$order,
708
+ isset($payment_transaction)
709
+ ? $payment_transaction->status
710
+ : $checkout_transaction->status
711
);
712
713
return true;
719
return false;
720
}
721
722
+ /**
723
+ * Returns the available recurring transaction type for the Checkout PM
724
+ * @return array
725
+ */
726
+ public function getRecurringTransactionTypes()
727
+ {
728
+ return array_map(
729
+ 'trim',
730
+ explode(
731
+ ',',
732
+ $this->getConfigData('recurring_transaction_types')
733
+ )
734
+ );
735
+ }
736
+
737
/**
738
* Get the selected transaction types in array
739
*
743
{
744
$processed_list = array();
745
746
+ $selected_types = array_map(
747
+ 'trim',
748
+ explode(
749
+ ',',
750
+ $this->getConfigData('genesis_types')
751
+ )
752
);
753
754
$alias_map = array(
802
return $this->getHelper()->getRedirectUrl('checkout');
803
}
804
805
+ /*
806
+ public function getCheckoutRedirectUrl()
807
+ {
808
+ return Mage::getUrl('checkout/onepage/index', array('_fragment' => 'review', '_secure' => true));
809
+ }*/
810
+
811
+
812
/**
813
* Get the helper or return its instance
814
*
824
return Mage::helper($helper);
825
}
826
}
827
+
828
+ /**
829
+ * Determines if the Payment Method should be available on the checkout page
830
+ * @param Mage_Sales_Model_Quote $quote
831
+ * @param int|null $checksBitMask
832
+ * @return bool
833
+ */
834
+ public function isApplicableToQuote($quote, $checksBitMask)
835
+ {
836
+ return
837
+ parent::isApplicableToQuote($quote, $checksBitMask) ||
838
+ (
839
+ ($checksBitMask & self::CHECK_ORDER_TOTAL_MIN_MAX) &&
840
+ $this->getHelper()->validateRecurringMethodMinMaxOrderTotal(
841
+ $this->getCode(),
842
+ $quote
843
+ )
844
+ );
845
+ }
846
+
847
+ /**
848
+ * Determines if the Payment Method should be visible on the chechout page or not
849
+ * @param Mage_Sales_Model_Quote|null $quote
850
+ * @return bool
851
+ */
852
+ public function isAvailable($quote = null)
853
+ {
854
+ return
855
+ parent::isAvailable($quote) &&
856
+ $this->getHelper()->getIsMethodAvailable(
857
+ $this->getCode(),
858
+ $quote,
859
+ false,
860
+ true
861
+ );
862
+ }
863
+
864
+ /**
865
+ * Validate RP data
866
+ *
867
+ * @param Mage_Payment_Model_Recurring_Profile $profile
868
+ * @return $this
869
+ */
870
+ public function validateRecurringProfile(Mage_Payment_Model_Recurring_Profile $profile)
871
+ {
872
+ $logFileName = $this->getConfigData('cron_recurring_log_file');
873
+ $isLogEnabled = !empty($logFileName);
874
+
875
+ if ($isLogEnabled) {
876
+ Mage::log(__METHOD__.'; Profile #'.$profile->getId(), null, $logFileName);
877
+ }
878
+
879
+ return $this;
880
+ }
881
+
882
+ /**
883
+ * Submit RP to the gateway
884
+ *
885
+ * @param Mage_Payment_Model_Recurring_Profile $profile
886
+ * @param Mage_Payment_Model_Info $payment
887
+ * @return $this
888
+ */
889
+ public function submitRecurringProfile(
890
+ Mage_Payment_Model_Recurring_Profile $profile,
891
+ Mage_Payment_Model_Info $payment
892
+ ) {
893
+ $logFileName = $this->getConfigData('cron_recurring_log_file');
894
+ $isLogEnabled = !empty($logFileName);
895
+
896
+ if ($isLogEnabled) {
897
+ Mage::log(__METHOD__.'; Profile #'.$profile->getId(), null, $logFileName);
898
+ }
899
+
900
+ $this->getHelper()->initClient($this->getCode());
901
+
902
+ $genesis = new \Genesis\Genesis("WPF\\Create");
903
+
904
+ $amount = $profile->getInitAmount() ?: 0;
905
+
906
+ if (empty($amount)) {
907
+ Mage::throwException(
908
+ $this->getHelper()->__("Unable to create Init Recurring Transaction! Initial Fee must not be empty!")
909
+ );
910
+ }
911
+
912
+ $genesis
913
+ ->request()
914
+ ->setTransactionId(
915
+ $profile->getInternalReferenceId()
916
+ )
917
+ ->setCurrency(
918
+ $payment->getQuote()->getStoreCurrencyCode()
919
+ )
920
+ ->setAmount(
921
+ $amount
922
+ )
923
+ ->setUsage(
924
+ $this->getHelper()->__('Magento Init Recurring Payment')
925
+ )
926
+ ->setDescription(
927
+ $this->getHelper()->getRecurringProfileItemDescription(
928
+ $profile
929
+ )
930
+ )
931
+ ->setCustomerPhone(
932
+ $profile->getBillingAddressInfo()['telephone']
933
+ )
934
+ ->setCustomerEmail(
935
+ $profile->getBillingAddressInfo()['email']
936
+ )
937
+ ->setNotificationUrl(
938
+ $this->getHelper()->getNotifyURL('checkout')
939
+ )
940
+ ->setReturnSuccessUrl(
941
+ $this->getHelper()->getSuccessURL('checkout')
942
+ )
943
+ ->setReturnFailureUrl(
944
+ $this->getHelper()->getFailureURL('checkout')
945
+ )
946
+ ->setReturnCancelUrl(
947
+ $this->getHelper()->getCancelURL('checkout')
948
+ )
949
+ //Billing
950
+ ->setBillingFirstName(
951
+ $profile->getBillingAddressInfo()['firstname']
952
+ )
953
+ ->setBillingLastName(
954
+ $profile->getBillingAddressInfo()['lastname']
955
+ )
956
+ ->setBillingAddress1(
957
+ $profile->getBillingAddressInfo()['street']
958
+ )
959
+ ->setBillingZipCode(
960
+ $profile->getBillingAddressInfo()['postcode']
961
+ )
962
+ ->setBillingCity(
963
+ $profile->getBillingAddressInfo()['city']
964
+ )
965
+ ->setBillingState(
966
+ $profile->getBillingAddressInfo()['region']
967
+ )
968
+ ->setBillingCountry(
969
+ $profile->getBillingAddressInfo()['country_id']
970
+ )
971
+ //Shipping
972
+ ->setShippingFirstName(
973
+ $profile->getShippingAddressInfo()['firstname']
974
+ )
975
+ ->setShippingLastName(
976
+ $profile->getShippingAddressInfo()['lastname']
977
+ )
978
+ ->setShippingAddress1(
979
+ $profile->getShippingAddressInfo()['street']
980
+ )
981
+ ->setShippingZipCode(
982
+ $profile->getShippingAddressInfo()['postcode']
983
+ )
984
+ ->setShippingCity(
985
+ $profile->getShippingAddressInfo()['city']
986
+ )
987
+ ->setShippingState(
988
+ $profile->getShippingAddressInfo()['region']
989
+ )
990
+ ->setShippingCountry(
991
+ $profile->getShippingAddressInfo()['country_id']
992
+ )
993
+ ->setLanguage(
994
+ $this->getHelper()->getLocale()
995
+ );
996
+
997
+
998
+ foreach ($this->getRecurringTransactionTypes() as $transaction_type) {
999
+ $genesis->request()->addTransactionType($transaction_type);
1000
+ }
1001
+
1002
+ try {
1003
+ $genesis->execute();
1004
+
1005
+ $responseObject = $genesis->response()->getResponseObject();
1006
+
1007
+ if (isset($responseObject->redirect_url)) {
1008
+ $this
1009
+ ->getHelper()
1010
+ ->getCheckoutSession()
1011
+ ->setEmerchantPayCheckoutRedirectUrl(
1012
+ $responseObject->redirect_url
1013
+ );
1014
+ }
1015
+
1016
+ $profile->setReferenceId(
1017
+ $responseObject->unique_id
1018
+ );
1019
+
1020
+ $payment->setSkipTransactionCreation(true);
1021
+
1022
+
1023
+ $productItemInfo = new Varien_Object;
1024
+ $productItemInfo->setPaymentType(
1025
+ Mage_Sales_Model_Recurring_Profile::PAYMENT_TYPE_INITIAL
1026
+ );
1027
+ $productItemInfo->setPrice(
1028
+ $amount
1029
+ );
1030
+
1031
+ $order = $profile->createOrder($productItemInfo);
1032
+
1033
+ $order->setState(
1034
+ Mage_Sales_Model_Order::STATE_PAYMENT_REVIEW
1035
+ );
1036
+
1037
+ $order->setStatus(
1038
+ Mage_Sales_Model_Order::STATE_PAYMENT_REVIEW
1039
+ );
1040
+
1041
+ $payment = $order->getPayment();
1042
+ $payment
1043
+ ->setTransactionId(
1044
+ $responseObject->unique_id
1045
+ );
1046
+ $payment
1047
+ ->setIsTransactionPending(
1048
+ true
1049
+ );
1050
+ $payment
1051
+ ->setIsTransactionClosed(
1052
+ false
1053
+ );
1054
+ $payment
1055
+ ->setTransactionAdditionalInfo(
1056
+ array(
1057
+ Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS =>
1058
+ $this->getHelper()->getArrayFromGatewayResponse(
1059
+ $responseObject
1060
+ )
1061
+ ),
1062
+ null
1063
+ );
1064
+ $payment
1065
+ ->addTransaction(
1066
+ Mage_Sales_Model_Order_Payment_Transaction::TYPE_ORDER
1067
+ );
1068
+
1069
+ $order->save();
1070
+ $profile->addOrderRelation(
1071
+ $order->getId()
1072
+ );
1073
+ $order->save();
1074
+ $payment->save();
1075
+
1076
+ $profile->setState(
1077
+ Mage_Sales_Model_Recurring_Profile::STATE_PENDING
1078
+ );
1079
+
1080
+ return $this;
1081
+ } catch (Exception $e) {
1082
+ Mage::throwException(
1083
+ $e->getMessage()
1084
+ );
1085
+ }
1086
+ }
1087
+
1088
+ /**
1089
+ * Fetch RP details
1090
+ *
1091
+ * @param string $referenceId
1092
+ * @param Varien_Object $result
1093
+ * @return $this
1094
+ */
1095
+ public function getRecurringProfileDetails($referenceId, Varien_Object $result)
1096
+ {
1097
+ return $this;
1098
+ }
1099
+
1100
+ /**
1101
+ * Whether can get recurring profile details
1102
+ * @return bool
1103
+ */
1104
+ public function canGetRecurringProfileDetails()
1105
+ {
1106
+ return false;
1107
+ }
1108
+
1109
+ /**
1110
+ * Update RP data
1111
+ *
1112
+ * @param Mage_Payment_Model_Recurring_Profile $profile
1113
+ * @return bool
1114
+ */
1115
+ public function updateRecurringProfile(Mage_Payment_Model_Recurring_Profile $profile)
1116
+ {
1117
+ $logFileName = $this->getConfigData('cron_recurring_log_file');
1118
+ $isLogEnabled = !empty($logFileName);
1119
+
1120
+ if ($isLogEnabled) {
1121
+ Mage::log(__METHOD__.'; Profile #'.$profile->getId(), null, $logFileName);
1122
+ }
1123
+
1124
+ return $this;
1125
+ }
1126
+
1127
+ /**
1128
+ * Manage status
1129
+ *
1130
+ * @param Mage_Payment_Model_Recurring_Profile $profile
1131
+ * @return bool
1132
+ */
1133
+ public function updateRecurringProfileStatus(Mage_Payment_Model_Recurring_Profile $profile)
1134
+ {
1135
+ $logFileName = $this->getConfigData('cron_recurring_log_file');
1136
+ $isLogEnabled = !empty($logFileName);
1137
+
1138
+ if ($isLogEnabled) {
1139
+ Mage::log(__METHOD__.'; Profile #'.$profile->getId(), null, $logFileName);
1140
+ }
1141
+
1142
+ return $this;
1143
+ }
1144
+ }
app/code/community/EMerchantPay/Genesis/Model/Direct.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/*
3
- * Copyright (C) 2015 eMerchantPay Ltd.
4
*
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
@@ -13,7 +13,7 @@
13
* GNU General Public License for more details.
14
*
15
* @author eMerchantPay
16
- * @copyright 2015 eMerchantPay Ltd.
17
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License, version 2 (GPL-2.0)
18
*/
19
@@ -29,7 +29,7 @@
29
*
30
* @category
31
*/
32
- class EMerchantPay_Genesis_Model_Direct extends Mage_Payment_Model_Method_Cc
33
{
34
// Variables
35
protected $_code = 'emerchantpay_direct';
@@ -53,6 +53,25 @@ class EMerchantPay_Genesis_Model_Direct extends Mage_Payment_Model_Method_Cc
53
protected $_canUseForMultishipping = false;
54
protected $_canSaveCc = false;
55
56
/**
57
* Check if we're on a secure page and run
58
* the parent verification
@@ -63,13 +82,14 @@ class EMerchantPay_Genesis_Model_Direct extends Mage_Payment_Model_Method_Cc
63
*/
64
public function isAvailable($quote = null)
65
{
66
- $isSecure = (bool) Mage::app()->getStore()->isCurrentlySecure();
67
-
68
- if (!$isSecure) {
69
- return false;
70
- }
71
-
72
- return parent::isAvailable($quote);
73
}
74
75
/**
@@ -186,9 +206,11 @@ class EMerchantPay_Genesis_Model_Direct extends Mage_Payment_Model_Method_Cc
186
$genesis
187
->request()
188
->setTransactionId($this->getHelper()->genTransactionId($order->getIncrementId()))
189
- ->setRemoteIp($this->getHelper('core/http')->getRemoteAddr(false))
190
->setUsage($this->getHelper()->getItemList($order))
191
- ->setCurrency($order->getBaseCurrencyCode())
192
->setAmount($amount)
193
->setCardHolder($payment->getCcOwner())
194
->setCardNumber($payment->getCcNumber())
@@ -232,9 +254,10 @@ class EMerchantPay_Genesis_Model_Direct extends Mage_Payment_Model_Method_Cc
232
)
233
->setTransactionAdditionalInfo(
234
array(
235
- Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS => $this->getHelper()->getArrayFromGatewayResponse(
236
- $this->getGenesisResponse()
237
- )
238
),
239
null
240
);
@@ -282,9 +305,11 @@ class EMerchantPay_Genesis_Model_Direct extends Mage_Payment_Model_Method_Cc
282
$genesis
283
->request()
284
->setTransactionId($this->getHelper()->genTransactionId($order->getIncrementId()))
285
- ->setRemoteIp(Mage::helper('core/http')->getRemoteAddr(false))
286
->setUsage($this->getHelper()->getItemList($order))
287
- ->setCurrency($order->getBaseCurrencyCode())
288
->setAmount($amount)
289
->setCardHolder($payment->getCcOwner())
290
->setCardNumber($payment->getCcNumber())
@@ -328,9 +353,10 @@ class EMerchantPay_Genesis_Model_Direct extends Mage_Payment_Model_Method_Cc
328
->setPreparedMessage('3D-Secure: Redirecting customer to a verification page.')
329
->setTransactionAdditionalInfo(
330
array(
331
- Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS => $this->getHelper()->getArrayFromGatewayResponse(
332
- $this->getGenesisResponse()
333
- )
334
),
335
null
336
);
@@ -383,9 +409,11 @@ class EMerchantPay_Genesis_Model_Direct extends Mage_Payment_Model_Method_Cc
383
$genesis
384
->request()
385
->setTransactionId($this->getHelper()->genTransactionId($order->getIncrementId()))
386
- ->setRemoteIp($this->getHelper('core/http')->getRemoteAddr(false))
387
->setUsage($this->getHelper()->getItemList($order))
388
- ->setCurrency($order->getBaseCurrencyCode())
389
->setAmount($amount)
390
->setCardHolder($payment->getCcOwner())
391
->setCardNumber($payment->getCcNumber())
@@ -428,9 +456,10 @@ class EMerchantPay_Genesis_Model_Direct extends Mage_Payment_Model_Method_Cc
428
->setIsTransactionPending(false)
429