EMerchantPay_Genesis_Client - Version 1.2.9

Version Notes

1.) Fix Order Status Update after Synchronous Transaction (Sale, Authorize) using Direct Payment Method

2.) Online Refund was not possible after processing Sale3D Transaction using Direct Payment Method

Download this release

Release Info

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


Code changes from version 1.2.8 to 1.2.9

app/code/community/EMerchantPay/Genesis/Block/Form/Direct.php CHANGED
@@ -73,7 +73,7 @@ class EMerchantPay_Genesis_Block_Form_Direct extends Mage_Payment_Block_Form
73
public function getCcMonths()
74
{
75
$months = $this->getData('cc_months');
76
- if (is_null($months)) {
77
$months[0] = $this->__('Month');
78
$months = array_merge($months, $this->_getConfig()->getMonths());
79
$this->setData('cc_months', $months);
@@ -89,7 +89,7 @@ class EMerchantPay_Genesis_Block_Form_Direct extends Mage_Payment_Block_Form
89
public function getCcYears()
90
{
91
$years = $this->getData('cc_years');
92
- if (is_null($years)) {
93
$years = $this->_getConfig()->getYears();
94
$years = array(0=>$this->__('Year'))+$years;
95
$this->setData('cc_years', $years);
@@ -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;
@@ -121,9 +121,12 @@ class EMerchantPay_Genesis_Block_Form_Direct extends Mage_Payment_Block_Form
121
*/
122
protected function _toHtml()
123
{
124
- Mage::dispatchEvent('payment_form_block_to_html_before', array(
125
- 'block' => $this
126
- ));
127
128
return parent::_toHtml();
129
}
73
public function getCcMonths()
74
{
75
$months = $this->getData('cc_months');
76
+ if ($months === null) {
77
$months[0] = $this->__('Month');
78
$months = array_merge($months, $this->_getConfig()->getMonths());
79
$this->setData('cc_months', $months);
89
public function getCcYears()
90
{
91
$years = $this->getData('cc_years');
92
+ if ($years === null) {
93
$years = $this->_getConfig()->getYears();
94
$years = array(0=>$this->__('Year'))+$years;
95
$this->setData('cc_years', $years);
106
{
107
if ($this->getMethod()) {
108
$configData = $this->getMethod()->getConfigData('useccv');
109
+ if ($configData === null) {
110
return true;
111
}
112
return (bool) $configData;
121
*/
122
protected function _toHtml()
123
{
124
+ Mage::dispatchEvent(
125
+ 'payment_form_block_to_html_before',
126
+ array(
127
+ 'block' => $this
128
+ )
129
+ );
130
131
return parent::_toHtml();
132
}
app/code/community/EMerchantPay/Genesis/Block/Redirect/Checkout.php CHANGED
@@ -25,9 +25,9 @@
25
class EMerchantPay_Genesis_Block_Redirect_Checkout extends Mage_Core_Block_Template
26
{
27
/** @var String */
28
- private $unique_id;
29
/** @var EMerchantPay_Genesis_Helper_Data $helper */
30
- private $helper;
31
32
protected function _construct()
33
{
@@ -51,7 +51,7 @@ class EMerchantPay_Genesis_Block_Redirect_Checkout extends Mage_Core_Block_Templ
51
52
$form
53
->setAction(
54
- $this->helper->getCheckoutSession()->getEmerchantPayCheckoutRedirectUrl()
55
)
56
->setId('emerchantpay_redirect_notification')
57
->setName('emerchantpay_redirect_notification')
@@ -80,22 +80,22 @@ class EMerchantPay_Genesis_Block_Redirect_Checkout extends Mage_Core_Block_Templ
80
*/
81
public function getButtonId()
82
{
83
- return sprintf('redirect_to_dest_%s', $this->unique_id);
84
}
85
86
/**
87
* Set Helper
88
*/
89
- private function setHelper()
90
{
91
- $this->helper = Mage::helper('emerchantpay');
92
}
93
94
/**
95
* Set Unique Id
96
*/
97
- private function setUniqueId()
98
{
99
- $this->unique_id = Mage::helper('core')->uniqHash();
100
}
101
}
25
class EMerchantPay_Genesis_Block_Redirect_Checkout extends Mage_Core_Block_Template
26
{
27
/** @var String */
28
+ protected $_uniqueId;
29
/** @var EMerchantPay_Genesis_Helper_Data $helper */
30
+ protected $_helper;
31
32
protected function _construct()
33
{
51
52
$form
53
->setAction(
54
+ $this->_helper->getCheckoutSession()->getEmerchantPayCheckoutRedirectUrl()
55
)
56
->setId('emerchantpay_redirect_notification')
57
->setName('emerchantpay_redirect_notification')
80
*/
81
public function getButtonId()
82
{
83
+ return sprintf('redirect_to_dest_%s', $this->_uniqueId);
84
}
85
86
/**
87
* Set Helper
88
*/
89
+ protected function setHelper()
90
{
91
+ $this->_helper = Mage::helper('emerchantpay');
92
}
93
94
/**
95
* Set Unique Id
96
*/
97
+ protected function setUniqueId()
98
{
99
+ $this->_uniqueId = Mage::helper('core')->uniqHash();
100
}
101
}
app/code/community/EMerchantPay/Genesis/Block/Redirect/Direct.php CHANGED
@@ -25,9 +25,9 @@
25
class EMerchantPay_Genesis_Block_Redirect_Direct extends Mage_Core_Block_Template
26
{
27
/** @var String */
28
- private $unique_id;
29
/** @var EMerchantPay_Genesis_Helper_Data $helper */
30
- private $helper;
31
32
protected function _construct()
33
{
@@ -47,7 +47,7 @@ class EMerchantPay_Genesis_Block_Redirect_Direct extends Mage_Core_Block_Templat
47
*/
48
public function getButtonId()
49
{
50
- return sprintf('redirect_to_dest_%s', $this->unique_id);
51
}
52
53
/**
@@ -61,7 +61,7 @@ class EMerchantPay_Genesis_Block_Redirect_Direct extends Mage_Core_Block_Templat
61
62
$form
63
->setAction(
64
- $this->helper->getCheckoutSession()->getEmerchantPayDirectRedirectUrl()
65
)
66
->setId('emerchantpay_redirect_notification')
67
->setName('emerchantpay_redirect_notification')
@@ -86,16 +86,16 @@ class EMerchantPay_Genesis_Block_Redirect_Direct extends Mage_Core_Block_Templat
86
/**
87
* Set Helper
88
*/
89
- private function setHelper()
90
{
91
- $this->helper = Mage::helper('emerchantpay');
92
}
93
94
/**
95
* Set Unique Id
96
*/
97
- private function setUniqueId()
98
{
99
- $this->unique_id = Mage::helper('core')->uniqHash();
100
}
101
}
25
class EMerchantPay_Genesis_Block_Redirect_Direct extends Mage_Core_Block_Template
26
{
27
/** @var String */
28
+ protected $_uniqueId;
29
/** @var EMerchantPay_Genesis_Helper_Data $helper */
30
+ protected $_helper;
31
32
protected function _construct()
33
{
47
*/
48
public function getButtonId()
49
{
50
+ return sprintf('redirect_to_dest_%s', $this->_uniqueId);
51
}
52
53
/**
61
62
$form
63
->setAction(
64
+ $this->_helper->getCheckoutSession()->getEmerchantPayDirectRedirectUrl()
65
)
66
->setId('emerchantpay_redirect_notification')
67
->setName('emerchantpay_redirect_notification')
86
/**
87
* Set Helper
88
*/
89
+ protected function setHelper()
90
{
91
+ $this->_helper = Mage::helper('emerchantpay');
92
}
93
94
/**
95
* Set Unique Id
96
*/
97
+ protected function setUniqueId()
98
{
99
+ $this->_uniqueId = Mage::helper('core')->uniqHash();
100
}
101
}
app/code/community/EMerchantPay/Genesis/Helper/Data.php CHANGED
@@ -37,7 +37,9 @@ class EMerchantPay_Genesis_Helper_Data extends Mage_Core_Helper_Abstract
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
@@ -201,7 +203,8 @@ class EMerchantPay_Genesis_Helper_Data extends Mage_Core_Helper_Abstract
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
);
@@ -234,7 +237,9 @@ class EMerchantPay_Genesis_Helper_Data extends Mage_Core_Helper_Abstract
234
public function getQuote($quoteId)
235
{
236
return Mage::getModel('sales/quote')->load(
237
- abs(intval($quoteId))
238
);
239
}
240
@@ -246,36 +251,36 @@ class EMerchantPay_Genesis_Helper_Data extends Mage_Core_Helper_Abstract
246
*/
247
public function getArrayFromGatewayResponse($response)
248
{
249
- $transaction_details = array();
250
251
foreach ($response as $key => $value) {
252
if (is_string($value)) {
253
- $transaction_details[$key] = $value;
254
}
255
256
if ($value instanceof DateTime) {
257
- $transaction_details[$key] = $value->format('c');
258
}
259
}
260
261
- return $transaction_details;
262
}
263
264
/**
265
* Get DESC list of specific transactions from payment object
266
*
267
* @param Mage_Sales_Model_Order_Payment $payment
268
- * @param array|string $type_filter
269
* @return array
270
*/
271
- public function getTransactionFromPaymentObject($payment, $type_filter)
272
{
273
$transactions = array();
274
275
$collection = Mage::getModel('sales/order_payment_transaction')->getCollection()
276
->setOrderFilter($payment->getOrder())
277
->addPaymentIdFilter($payment->getId())
278
- ->addTxnTypeFilter($type_filter)
279
->setOrder('created_at', Varien_Data_Collection::SORT_ORDER_DESC);
280
281
/** @var Mage_Sales_Model_Order_Payment_Transaction $txn */
@@ -291,7 +296,7 @@ class EMerchantPay_Genesis_Helper_Data extends Mage_Core_Helper_Abstract
291
*
292
* @see API parameter "Usage" or "Description"
293
*
294
- * @param Mage_Sales_Model_Order_Payment $order
295
*
296
* @return string Formatted List of Items
297
*/
@@ -493,8 +498,6 @@ class EMerchantPay_Genesis_Helper_Data extends Mage_Core_Helper_Abstract
493
->getResponse()
494
->setRedirect($target)
495
->sendHeaders();
496
-
497
- exit(0);
498
}
499
}
500
@@ -564,12 +567,8 @@ class EMerchantPay_Genesis_Helper_Data extends Mage_Core_Helper_Abstract
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()) &&
@@ -617,45 +616,15 @@ class EMerchantPay_Genesis_Helper_Data extends Mage_Core_Helper_Abstract
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
@@ -785,17 +754,12 @@ class EMerchantPay_Genesis_Helper_Data extends Mage_Core_Helper_Abstract
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
/**
37
public function initLibrary()
38
{
39
if (!class_exists('\Genesis\Genesis', false)) {
40
+ // @codingStandardsIgnoreStart
41
include Mage::getBaseDir('lib') . DS . 'Genesis' . DS . 'vendor' . DS . 'autoload.php';
42
+ // @codingStandardsIgnoreEnd
43
}
44
}
45
203
204
if (!\Genesis\API\Constants\i18n::isValidLanguageCode($languageCode)) {
205
Mage::throwException(
206
+ $this->__(
207
+ 'The provided argument is not a valid ISO-639-1 language code ' .
208
'or is not supported by the Payment Gateway!'
209
)
210
);
237
public function getQuote($quoteId)
238
{
239
return Mage::getModel('sales/quote')->load(
240
+ abs(
241
+ (int) $quoteId
242
+ )
243
);
244
}
245
251
*/
252
public function getArrayFromGatewayResponse($response)
253
{
254
+ $transactionDetails = array();
255
256
foreach ($response as $key => $value) {
257
if (is_string($value)) {
258
+ $transactionDetails[$key] = $value;
259
}
260
261
if ($value instanceof DateTime) {
262
+ $transactionDetails[$key] = $value->format('c');
263
}
264
}
265
266
+ return $transactionDetails;
267
}
268
269
/**
270
* Get DESC list of specific transactions from payment object
271
*
272
* @param Mage_Sales_Model_Order_Payment $payment
273
+ * @param array|string $typeFilter
274
* @return array
275
*/
276
+ public function getTransactionFromPaymentObject($payment, $typeFilter)
277
{
278
$transactions = array();
279
280
$collection = Mage::getModel('sales/order_payment_transaction')->getCollection()
281
->setOrderFilter($payment->getOrder())
282
->addPaymentIdFilter($payment->getId())
283
+ ->addTxnTypeFilter($typeFilter)
284
->setOrder('created_at', Varien_Data_Collection::SORT_ORDER_DESC);
285
286
/** @var Mage_Sales_Model_Order_Payment_Transaction $txn */
296
*
297
* @see API parameter "Usage" or "Description"
298
*
299
+ * @param Mage_Sales_Model_Order $order
300
*
301
* @return string Formatted List of Items
302
*/
498
->getResponse()
499
->setRedirect($target)
500
->sendHeaders();
501
}
502
}
503
567
* @param bool $supportsRecurring
568
* @return bool
569
*/
570
+ public function getIsMethodAvailable($method, $quote, $requiresSecureConnection = false, $supportsRecurring = true)
571
+ {
572
return
573
$this->getIsMethodActive($method) &&
574
(!$requiresSecureConnection || $this->getIsSecureConnectionEnabled()) &&
616
{
617
$remoteAddress = Mage::helper('core/http')->getRemoteAddr(false);
618
619
+ if (!$remoteAddress && function_exists("gethostbyname")) {
620
+ $requestHostName = Mage::app()->getRequest()->getHttpHost();
621
622
+ $remoteAddress = gethostbyname($requestHostName);
623
}
624
625
return $remoteAddress ?: "127.0.0.1";
626
}
627
628
/**
629
* @param string $transactionType
630
* @return bool
754
}
755
756
/**
757
+ * Returns the current datetime as a formatted MySQL Datetime Value
758
* @return string
759
*/
760
+ public function formatCurrentDateTimeToMySQLDateTime()
761
{
762
+ return Mage::getSingleton('core/date')->gmtDate();
763
}
764
765
/**
app/code/community/EMerchantPay/Genesis/Model/Checkout.php CHANGED
@@ -22,7 +22,8 @@
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
@@ -118,31 +119,31 @@ class EMerchantPay_Genesis_Model_Checkout extends Mage_Payment_Model_Method_Abst
118
->setLanguage($this->getHelper()->getLocale());
119
120
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
}
@@ -203,7 +204,7 @@ class EMerchantPay_Genesis_Model_Checkout extends Mage_Payment_Model_Method_Abst
203
return $this;
204
}
205
206
- $reference_id = $authorize->getTxnId();
207
208
$genesis = new \Genesis\Genesis('Financial\Capture');
209
@@ -218,7 +219,7 @@ class EMerchantPay_Genesis_Model_Checkout extends Mage_Payment_Model_Method_Abst
218
$this->getHelper('core/http')->getRemoteAddr(false)
219
)
220
->setReferenceId(
221
- $reference_id
222
)
223
->setCurrency(
224
$payment->getOrder()->getOrderCurrencyCode()
@@ -233,10 +234,12 @@ class EMerchantPay_Genesis_Model_Checkout extends Mage_Payment_Model_Method_Abst
233
234
$payment
235
->setTransactionId(
236
$responseObject->unique_id
237
)
238
->setParentTransactionId(
239
- $reference_id
240
)
241
->setShouldCloseParentTransaction(
242
true
@@ -308,7 +311,7 @@ class EMerchantPay_Genesis_Model_Checkout extends Mage_Payment_Model_Method_Abst
308
return $this;
309
}
310
311
- $reference_id = $capture->getTxnId();
312
313
$genesis = new \Genesis\Genesis('Financial\Refund');
314
@@ -323,7 +326,7 @@ class EMerchantPay_Genesis_Model_Checkout extends Mage_Payment_Model_Method_Abst
323
$this->getHelper('core/http')->getRemoteAddr(false)
324
)
325
->setReferenceId(
326
- $reference_id
327
)
328
->setCurrency(
329
$payment->getOrder()->getOrderCurrencyCode()
@@ -336,10 +339,12 @@ class EMerchantPay_Genesis_Model_Checkout extends Mage_Payment_Model_Method_Abst
336
337
$payment
338
->setTransactionId(
339
$responseObject->unique_id
340
)
341
->setParentTransactionId(
342
- $reference_id
343
)
344
->setShouldCloseParentTransaction(
345
true
@@ -412,12 +417,15 @@ class EMerchantPay_Genesis_Model_Checkout extends Mage_Payment_Model_Method_Abst
412
413
$this->getHelper()->setTokenByPaymentTransaction($payment);
414
415
- $transactions = $this->getHelper()->getTransactionFromPaymentObject($payment, array(
416
- Mage_Sales_Model_Order_Payment_Transaction::TYPE_AUTH,
417
- Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE
418
- ));
419
420
- $reference_id = $transactions ? reset($transactions)->getTxnId() : null;
421
422
$genesis = new \Genesis\Genesis('Financial\Void');
423
@@ -432,7 +440,7 @@ class EMerchantPay_Genesis_Model_Checkout extends Mage_Payment_Model_Method_Abst
432
$this->getHelper('core/http')->getRemoteAddr(false)
433
)
434
->setReferenceId(
435
- $reference_id
436
);
437
438
$genesis->execute();
@@ -441,10 +449,12 @@ class EMerchantPay_Genesis_Model_Checkout extends Mage_Payment_Model_Method_Abst
441
442
$payment
443
->setTransactionId(
444
$responseObject->unique_id
445
)
446
->setParentTransactionId(
447
- $reference_id
448
)
449
->setShouldCloseParentTransaction(
450
true
@@ -508,32 +518,38 @@ class EMerchantPay_Genesis_Model_Checkout extends Mage_Payment_Model_Method_Abst
508
/** @var Mage_Sales_Model_Order_Payment_Transaction $transaction */
509
$transaction = Mage::getModel('sales/order_payment_transaction')->load($transactionId, 'txn_id');
510
511
- $checkout_transaction = $transaction->getOrder()->getPayment()->lookupTransaction(
512
null,
513
Mage_Sales_Model_Order_Payment_Transaction::TYPE_ORDER
514
);
515
516
- $reconcile = $this->reconcile($checkout_transaction->getTxnId());
517
518
// Get the current details
519
- $transaction_details = $payment->getAdditionalInformation(
520
Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS
521
);
522
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;
530
}
531
}
532
533
if ($reconcile->payment_transaction instanceof ArrayObject) {
534
- foreach ($reconcile->payment_transaction as $payment_transaction) {
535
- if ($payment_transaction->unique_id == $transactionId) {
536
- $transaction_details = $payment_transaction;
537
}
538
}
539
}
@@ -549,7 +565,7 @@ class EMerchantPay_Genesis_Model_Checkout extends Mage_Payment_Model_Method_Abst
549
array(
550
Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS =>
551
$this->getHelper()->getArrayFromGatewayResponse(
552
- $transaction_details
553
)
554
),
555
null
@@ -565,20 +581,20 @@ class EMerchantPay_Genesis_Model_Checkout extends Mage_Payment_Model_Method_Abst
565
/**
566
* Execute a WPF Reconcile
567
*
568
- * @param $unique_id
569
*
570
- * @return EMerchantPay_Genesis_Model_Checkout
571
*
572
* @throws Mage_Core_Exception
573
*/
574
- public function reconcile($unique_id)
575
{
576
try {
577
$this->getHelper()->initClient($this->getCode());
578
579
$genesis = new \Genesis\Genesis('WPF\Reconcile');
580
581
- $genesis->request()->setUniqueId($unique_id);
582
583
$genesis->execute();
584
@@ -597,121 +613,151 @@ class EMerchantPay_Genesis_Model_Checkout extends Mage_Payment_Model_Method_Abst
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
616
- if ($order) {
617
- $transaction
618
- ->setOrderPaymentObject(
619
- $order->getPayment()
620
- )
621
- ->setAdditionalInformation(
622
- Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS,
623
- $this->getHelper()->getArrayFromGatewayResponse(
624
- $checkout_transaction
625
- )
626
)
627
- ->save();
628
-
629
- if (isset($checkout_transaction->payment_transaction)) {
630
- $payment_transaction = $checkout_transaction->payment_transaction;
631
-
632
- $payment = $order->getPayment();
633
-
634
- $payment
635
- ->setTransactionId($payment_transaction->unique_id)
636
- ->setParentTransactionId($checkout_transaction->unique_id)
637
- ->setShouldCloseParentTransaction(true)
638
- ->setIsTransactionPending(false)
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:
665
- case \Genesis\API\Constants\Transaction\Types::NETELLER:
666
- case \Genesis\API\Constants\Transaction\Types::PAYSAFECARD:
667
- case \Genesis\API\Constants\Transaction\Types::PPRO:
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;
714
}
715
} catch (Exception $exception) {
716
Mage::logException($exception);
717
}
@@ -741,9 +787,9 @@ class EMerchantPay_Genesis_Model_Checkout extends Mage_Payment_Model_Method_Abst
741
*/
742
public function getTransactionTypes()
743
{
744
- $processed_list = array();
745
746
- $selected_types = array_map(
747
'trim',
748
explode(
749
',',
@@ -751,7 +797,7 @@ class EMerchantPay_Genesis_Model_Checkout extends Mage_Payment_Model_Method_Abst
751
)
752
);
753
754
- $alias_map = array(
755
\Genesis\API\Constants\Payment\Methods::EPS =>
756
\Genesis\API\Constants\Transaction\Types::PPRO,
757
\Genesis\API\Constants\Payment\Methods::GIRO_PAY =>
@@ -768,21 +814,21 @@ class EMerchantPay_Genesis_Model_Checkout extends Mage_Payment_Model_Method_Abst
768
\Genesis\API\Constants\Transaction\Types::PPRO,
769
);
770
771
- foreach ($selected_types as $selected_type) {
772
- if (array_key_exists($selected_type, $alias_map)) {
773
- $transaction_type = $alias_map[$selected_type];
774
775
- $processed_list[$transaction_type]['name'] = $transaction_type;
776
777
- $processed_list[$transaction_type]['parameters'][] = array(
778
- 'payment_method' => $selected_type
779
);
780
} else {
781
- $processed_list[] = $selected_type;
782
}
783
}
784
785
- return $processed_list;
786
}
787
788
/**
@@ -802,13 +848,6 @@ class EMerchantPay_Genesis_Model_Checkout extends Mage_Payment_Model_Method_Abst
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
*
@@ -816,9 +855,9 @@ class EMerchantPay_Genesis_Model_Checkout extends Mage_Payment_Model_Method_Abst
816
*
817
* @return EMerchantPay_Genesis_Helper_Data|mixed
818
*/
819
- private function getHelper($helper = '')
820
{
821
- if (empty($helper)) {
822
return Mage::helper('emerchantpay');
823
} else {
824
return Mage::helper($helper);
@@ -889,7 +928,8 @@ class EMerchantPay_Genesis_Model_Checkout extends Mage_Payment_Model_Method_Abst
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
@@ -903,7 +943,7 @@ class EMerchantPay_Genesis_Model_Checkout extends Mage_Payment_Model_Method_Abst
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
);
@@ -995,8 +1035,8 @@ class EMerchantPay_Genesis_Model_Checkout extends Mage_Payment_Model_Method_Abst
995
);
996
997
998
- foreach ($this->getRecurringTransactionTypes() as $transaction_type) {
999
- $genesis->request()->addTransactionType($transaction_type);
1000
}
1001
1002
try {
@@ -1004,17 +1044,23 @@ class EMerchantPay_Genesis_Model_Checkout extends Mage_Payment_Model_Method_Abst
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);
@@ -1039,10 +1085,14 @@ class EMerchantPay_Genesis_Model_Checkout extends Mage_Payment_Model_Method_Abst
1039
);
1040
1041
$payment = $order->getPayment();
1042
$payment
1043
->setTransactionId(
1044
$responseObject->unique_id
1045
);
1046
$payment
1047
->setIsTransactionPending(
1048
true
@@ -1077,12 +1127,13 @@ class EMerchantPay_Genesis_Model_Checkout extends Mage_Payment_Model_Method_Abst
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
/**
@@ -1110,7 +1161,7 @@ class EMerchantPay_Genesis_Model_Checkout extends Mage_Payment_Model_Method_Abst
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
{
@@ -1128,7 +1179,7 @@ class EMerchantPay_Genesis_Model_Checkout extends Mage_Payment_Model_Method_Abst
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
{
22
*
23
* Class EMerchantPay_Genesis_Model_Checkout
24
*/
25
+ class EMerchantPay_Genesis_Model_Checkout
26
+ extends Mage_Payment_Model_Method_Abstract implements Mage_Payment_Model_Recurring_Profile_MethodInterface
27
{
28
protected $_code = 'emerchantpay_checkout';
29
119
->setLanguage($this->getHelper()->getLocale());
120
121
122
+ foreach ($this->getTransactionTypes() as $transactionType) {
123
+ if (is_array($transactionType)) {
124
$genesis->request()->addTransactionType(
125
+ $transactionType['name'],
126
+ $transactionType['parameters']
127
);
128
} else {
129
+ if (\Genesis\API\Constants\Transaction\Types::isPayByVoucher($transactionType)) {
130
+ $parameters = array(
131
'card_type' =>
132
\Genesis\API\Constants\Transaction\Parameters\PayByVouchers\CardTypes::VIRTUAL,
133
'redeem_type' =>
134
\Genesis\API\Constants\Transaction\Parameters\PayByVouchers\RedeemTypes::INSTANT
135
+ );
136
+ if ($transactionType == \Genesis\API\Constants\Transaction\Types::PAYBYVOUCHER_YEEPAY) {
137
$parameters['product_name'] = $orderItemsList;
138
$parameters['product_category'] = $orderItemsList;
139
}
140
$genesis
141
->request()
142
+ ->addTransactionType($transactionType, $parameters);
143
} else {
144
$genesis
145
->request()
146
+ ->addTransactionType($transactionType);
147
}
148
}
149
}
204
return $this;
205
}
206
207
+ $referenceId = $authorize->getTxnId();
208
209
$genesis = new \Genesis\Genesis('Financial\Capture');
210
219
$this->getHelper('core/http')->getRemoteAddr(false)
220
)
221
->setReferenceId(
222
+ $referenceId
223
)
224
->setCurrency(
225
$payment->getOrder()->getOrderCurrencyCode()
234
235
$payment
236
->setTransactionId(
237
+ // @codingStandardsIgnoreStart
238
$responseObject->unique_id
239
+ // @codingStandardsIgnoreEnd
240
)
241
->setParentTransactionId(
242
+ $referenceId
243
)
244
->setShouldCloseParentTransaction(
245
true
311
return $this;
312
}
313
314
+ $referenceId = $capture->getTxnId();
315
316
$genesis = new \Genesis\Genesis('Financial\Refund');
317
326
$this->getHelper('core/http')->getRemoteAddr(false)
327
)
328
->setReferenceId(
329
+ $referenceId
330
)
331
->setCurrency(
332
$payment->getOrder()->getOrderCurrencyCode()
339
340
$payment
341
->setTransactionId(
342
+ // @codingStandardsIgnoreStart
343
$responseObject->unique_id
344
+ // @codingStandardsIgnoreEnd
345
)
346
->setParentTransactionId(
347
+ $referenceId
348
)
349
->setShouldCloseParentTransaction(
350
true
417
418
$this->getHelper()->setTokenByPaymentTransaction($payment);
419
420
+ $transactions = $this->getHelper()->getTransactionFromPaymentObject(
421
+ $payment,
422
+ array(
423
+ Mage_Sales_Model_Order_Payment_Transaction::TYPE_AUTH,
424
+ Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE
425
+ )
426
+ );
427
428
+ $referenceId = $transactions ? reset($transactions)->getTxnId() : null;
429
430
$genesis = new \Genesis\Genesis('Financial\Void');
431
440
$this->getHelper('core/http')->getRemoteAddr(false)
441
)
442
->setReferenceId(
443
+ $referenceId
444
);
445
446
$genesis->execute();
449
450
$payment
451
->setTransactionId(
452
+ // @codingStandardsIgnoreStart
453
$responseObject->unique_id
454
+ // @codingStandardsIgnoreEnd
455
)
456
->setParentTransactionId(
457
+ $referenceId
458
)
459
->setShouldCloseParentTransaction(
460
true
518
/** @var Mage_Sales_Model_Order_Payment_Transaction $transaction */
519
$transaction = Mage::getModel('sales/order_payment_transaction')->load($transactionId, 'txn_id');
520
521
+ $checkoutTransaction = $transaction->getOrder()->getPayment()->lookupTransaction(
522
null,
523
Mage_Sales_Model_Order_Payment_Transaction::TYPE_ORDER
524
);
525
526
+ $reconcile = $this->reconcile(
527
+ $checkoutTransaction->getTxnId()
528
+ );
529
530
// Get the current details
531
+ $transactionDetails = $payment->getAdditionalInformation(
532
Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS
533
);
534
535
// Try to extract transaction details from the Gateway response
536
+ // @codingStandardsIgnoreStart
537
if ($reconcile->unique_id == $transactionId) {
538
+ $transactionDetails = $reconcile;
539
} else {
540
if ($reconcile->payment_transaction instanceof stdClass) {
541
if ($reconcile->payment_transaction->unique_id == $transactionId) {
542
+ $transactionDetails = $reconcile->payment_transaction;
543
+ // @codingStandardsIgnoreEnd
544
}
545
}
546
547
+ // @codingStandardsIgnoreStart
548
if ($reconcile->payment_transaction instanceof ArrayObject) {
549
+ foreach ($reconcile->payment_transaction as $paymentTransaction) {
550
+ if ($paymentTransaction->unique_id == $transactionId) {
551
+ // @codingStandardsIgnoreEnd
552
+ $transactionDetails = $paymentTransaction;
553
}
554
}
555
}
565
array(
566
Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS =>
567
$this->getHelper()->getArrayFromGatewayResponse(
568
+ $transactionDetails
569
)
570
),
571
null
581
/**
582
* Execute a WPF Reconcile
583
*
584
+ * @param string $uniqueId
585
*
586
+ * @return bool|stdClass
587
*
588
* @throws Mage_Core_Exception
589
*/
590
+ public function reconcile($uniqueId)
591
{
592
try {
593
$this->getHelper()->initClient($this->getCode());
594
595
$genesis = new \Genesis\Genesis('WPF\Reconcile');
596
597
+ $genesis->request()->setUniqueId($uniqueId);
598
599
$genesis->execute();
600
613
/**
614
* Handle an incoming Genesis notification
615
*
616
+ * @param stdClass $checkoutTransaction
617
* @return bool
618
*/
619
+ // @codingStandardsIgnoreStart
620
+ public function processNotification($checkoutTransaction)
621
{
622
+ // @codingStandardsIgnoreEnd
623
try {
624
$this->getHelper()->initClient($this->getCode());
625
626
/** @var Mage_Sales_Model_Order_Payment_Transaction $transaction */
627
$transaction = Mage::getModel('sales/order_payment_transaction')->load(
628
+ // @codingStandardsIgnoreStart
629
+ $checkoutTransaction->unique_id,
630
+ // @codingStandardsIgnoreEnd
631
'txn_id'
632
);
633
634
$order = $transaction->getOrder();
635
636
+ if (!$order) {
637
+ return false;
638
+ }
639
+
640
+ $transaction
641
+ ->setOrderPaymentObject(
642
+ $order->getPayment()
643
+ )
644
+ ->setAdditionalInformation(
645
+ Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS,
646
+ $this->getHelper()->getArrayFromGatewayResponse(
647
+ $checkoutTransaction
648
)
649
+ )
650
+ ->save();
651
652
+ // @codingStandardsIgnoreStart
653
+ if (!isset($checkoutTransaction->payment_transaction)) {
654
+ // @codingStandardsIgnoreEnd
655
656
+ $this->getHelper()->setOrderState(
657
+ $order,
658
+ $checkoutTransaction->status
659
+ );
660
661
+ return false;
662
+ }
663
664
+ // @codingStandardsIgnoreStart
665
+ $paymentTransaction = $checkoutTransaction->payment_transaction;
666
+ // @codingStandardsIgnoreEnd
667
668
+ $payment = $order->getPayment();
669
670
+ $payment
671
+ ->setTransactionId(
672
+ // @codingStandardsIgnoreStart
673
+ $paymentTransaction->unique_id
674
+ // @codingStandardsIgnoreEnd
675
+ )
676
+ ->setParentTransactionId(
677
+ // @codingStandardsIgnoreStart
678
+ $checkoutTransaction->unique_id
679
+ // @codingStandardsIgnoreEnd
680
+ )
681
+ ->setShouldCloseParentTransaction(true)
682
+ ->setIsTransactionPending(false)
683
+ ->resetTransactionAdditionalInfo()
684
+ ->setTransactionAdditionalInfo(
685
+ array(
686
+ Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS =>
687
+ $this->getHelper()->getArrayFromGatewayResponse(
688
+ $paymentTransaction
689
+ )
690
+ ),
691
+ null
692
+ );
693
694
+ if ($paymentTransaction->status == \Genesis\API\Constants\Transaction\States::APPROVED) {
695
+ $payment->setIsTransactionClosed(false);
696
+ } else {
697
+ $payment->setIsTransactionClosed(true);
698
+ }
699
+
700
+ // @codingStandardsIgnoreStart
701
+ switch ($paymentTransaction->transaction_type) {
702
+ // @codingStandardsIgnoreEnd
703
+ case \Genesis\API\Constants\Transaction\Types::AUTHORIZE:
704
+ case \Genesis\API\Constants\Transaction\Types::AUTHORIZE_3D:
705
+ $payment->registerAuthorizationNotification(
706
+ $paymentTransaction->amount
707
+ );
708
+ break;
709
+ case \Genesis\API\Constants\Transaction\Types::ABNIDEAL:
710
+ case \Genesis\API\Constants\Transaction\Types::CASHU:
711
+ case \Genesis\API\Constants\Transaction\Types::NETELLER:
712
+ case \Genesis\API\Constants\Transaction\Types::PAYSAFECARD:
713
+ case \Genesis\API\Constants\Transaction\Types::PPRO:
714
+ case \Genesis\API\Constants\Transaction\Types::SALE:
715
+ case \Genesis\API\Constants\Transaction\Types::SALE_3D:
716
+ case \Genesis\API\Constants\Transaction\Types::SOFORT:
717
+ case \Genesis\API\Constants\Transaction\Types::INIT_RECURRING_SALE:
718
+ case \Genesis\API\Constants\Transaction\Types::INIT_RECURRING_SALE_3D:
719
+ $payment->registerCaptureNotification(
720
+ $paymentTransaction->amount
721
+ );
722
+ break;
723
+ default:
724
+ break;
725
+ }
726
+
727
+ $isTransactionApproved =
728
+ ($paymentTransaction->status == \Genesis\API\Constants\Transaction\States::APPROVED);
729
+
730
+ // @codingStandardsIgnoreStart
731
+ if ($this->getHelper()->getIsTransactionTypeInitRecurring($paymentTransaction->transaction_type)) {
732
+ // @codingStandardsIgnoreEnd
733
+ $recurringProfile = Mage::getModel('sales/recurring_profile')->load(
734
+ // @codingStandardsIgnoreStart
735
+ $checkoutTransaction->unique_id,
736
+ // @codingStandardsIgnoreEnd
737
+ 'reference_id'
738
);
739
740
+ if ($recurringProfile && $recurringProfile->getId()) {
741
+ if ($recurringProfile->getState() == Mage_Sales_Model_Recurring_Profile::STATE_PENDING) {
742
+ $recurringProfile->setState(
743
+ ($isTransactionApproved
744
+ ? Mage_Sales_Model_Recurring_Profile::STATE_ACTIVE
745
+ : Mage_Sales_Model_Recurring_Profile::STATE_CANCELED
746
+ )
747
+ );
748
+ $recurringProfile->save();
749
+ }
750
+ }
751
}
752
+
753
+ $payment->save();
754
+
755
+ $this->getHelper()->setOrderState(
756
+ $order,
757
+ $paymentTransaction->status
758
+ );
759
+
760
+ return true;
761
} catch (Exception $exception) {
762
Mage::logException($exception);
763
}
787
*/
788
public function getTransactionTypes()
789
{
790
+ $processedList = array();
791
792
+ $selectedTypes = array_map(
793
'trim',
794
explode(
795
',',
797
)
798
);
799
800
+ $aliasMap = array(
801
\Genesis\API\Constants\Payment\Methods::EPS =>
802
\Genesis\API\Constants\Transaction\Types::PPRO,
803
\Genesis\API\Constants\Payment\Methods::GIRO_PAY =>
814
\Genesis\API\Constants\Transaction\Types::PPRO,
815
);
816
817
+ foreach ($selectedTypes as $selectedType) {
818
+ if (array_key_exists($selectedType, $aliasMap)) {
819
+ $transactionType = $aliasMap[$selectedType];
820
821
+ $processedList[$transactionType]['name'] = $transactionType;
822
823
+ $processedList[$transactionType]['parameters'][] = array(
824
+ 'payment_method' => $selectedType
825
);
826
} else {
827
+ $processedList[] = $selectedType;
828
}
829
}
830
831
+ return $processedList;
832
}
833
834
/**
848
return $this->getHelper()->getRedirectUrl('checkout');
849
}
850
851
/**
852
* Get the helper or return its instance
853
*
855
*
856
* @return EMerchantPay_Genesis_Helper_Data|mixed
857
*/
858
+ protected function getHelper($helper = '')
859
{
860
+ if (!$helper) {
861
return Mage::helper('emerchantpay');
862
} else {
863
return Mage::helper($helper);
928
public function submitRecurringProfile(
929
Mage_Payment_Model_Recurring_Profile $profile,
930
Mage_Payment_Model_Info $payment
931
+ )
932
+ {
933
$logFileName = $this->getConfigData('cron_recurring_log_file');
934
$isLogEnabled = !empty($logFileName);
935
943
944
$amount = $profile->getInitAmount() ?: 0;
945
946
+ if (!$amount) {
947
Mage::throwException(
948
$this->getHelper()->__("Unable to create Init Recurring Transaction! Initial Fee must not be empty!")
949
);
1035
);
1036
1037
1038
+ foreach ($this->getRecurringTransactionTypes() as $transactionType) {
1039
+ $genesis->request()->addTransactionType($transactionType);
1040
}
1041
1042
try {
1044
1045
$responseObject = $genesis->response()->getResponseObject();
1046
1047
+ // @codingStandardsIgnoreStart
1048
if (isset($responseObject->redirect_url)) {
1049
+ // @codingStandardsIgnoreEnd
1050
$this
1051
->getHelper()
1052
->getCheckoutSession()
1053
->setEmerchantPayCheckoutRedirectUrl(
1054
+ // @codingStandardsIgnoreStart
1055
$responseObject->redirect_url
1056
+ // @codingStandardsIgnoreEnd
1057
);
1058
}
1059
1060
$profile->setReferenceId(
1061
+ // @codingStandardsIgnoreStart
1062
$responseObject->unique_id
1063
+ // @codingStandardsIgnoreEnd
1064
);
1065
1066
$payment->setSkipTransactionCreation(true);
1085
);
1086
1087
$payment = $order->getPayment();
1088
+
1089
$payment
1090
->setTransactionId(
1091
+ // @codingStandardsIgnoreStart
1092
$responseObject->unique_id
1093
+ // @codingStandardsIgnoreEnd
1094
);
1095
+
1096
$payment
1097
->setIsTransactionPending(
1098
true
1127
Mage_Sales_Model_Recurring_Profile::STATE_PENDING
1128
);
1129
1130
} catch (Exception $e) {
1131
Mage::throwException(
1132
$e->getMessage()
1133
);
1134
}
1135
+
1136
+ return $this;
1137
}
1138
1139
/**
1161
* Update RP data
1162
*
1163
* @param Mage_Payment_Model_Recurring_Profile $profile
1164
+ * @return $this
1165
*/
1166
public function updateRecurringProfile(Mage_Payment_Model_Recurring_Profile $profile)
1167
{
1179
* Manage status
1180
*
1181
* @param Mage_Payment_Model_Recurring_Profile $profile
1182
+ * @return $this
1183
*/
1184
public function updateRecurringProfileStatus(Mage_Payment_Model_Recurring_Profile $profile)
1185
{
app/code/community/EMerchantPay/Genesis/Model/Direct.php CHANGED
@@ -29,7 +29,8 @@
29
*
30
* @category
31
*/
32
- class EMerchantPay_Genesis_Model_Direct extends Mage_Payment_Model_Method_Cc implements Mage_Payment_Model_Recurring_Profile_MethodInterface
33
{
34
// Variables
35
protected $_code = 'emerchantpay_direct';
@@ -116,6 +117,67 @@ class EMerchantPay_Genesis_Model_Direct extends Mage_Payment_Model_Method_Cc imp
116
return $this;
117
}
118
119
/**
120
* Payment action getter compatible with payment model
121
*
@@ -127,16 +189,15 @@ class EMerchantPay_Genesis_Model_Direct extends Mage_Payment_Model_Method_Cc imp
127
{
128
$this->getHelper()->initLibrary();
129
130
- switch ($this->getConfigData('genesis_type')) {
131
default:
132
case \Genesis\API\Constants\Transaction\Types::AUTHORIZE:
133
case \Genesis\API\Constants\Transaction\Types::AUTHORIZE_3D:
134
return Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE;
135
- break;
136
case \Genesis\API\Constants\Transaction\Types::SALE:
137
case \Genesis\API\Constants\Transaction\Types::SALE_3D:
138
return Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE_CAPTURE;
139
- break;
140
}
141
}
142
@@ -150,11 +211,13 @@ class EMerchantPay_Genesis_Model_Direct extends Mage_Payment_Model_Method_Cc imp
150
*/
151
public function authorize(Varien_Object $payment, $amount)
152
{
153
- if ($this->is3dEnabled()) {
154
- return $this->_authorize3d($payment, $amount);
155
} else {
156
- return $this->_authorize($payment, $amount);
157
}
158
}
159
160
/**
@@ -170,274 +233,161 @@ class EMerchantPay_Genesis_Model_Direct extends Mage_Payment_Model_Method_Cc imp
170
$authorize = $payment->lookupTransaction(null, Mage_Sales_Model_Order_Payment_Transaction::TYPE_AUTH);
171
172
if ($authorize) {
173
- return $this->_capture($payment, $amount);
174
} else {
175
- if ($this->is3dEnabled()) {
176
- return $this->_sale3d($payment, $amount);
177
} else {
178
- return $this->_sale($payment, $amount);
179
}
180
}
181
}
182
183
/**
184
- * Genesis Authorize Payment Method
185
*
186
* @param Varien_Object|Mage_Sales_Model_Order_Payment $payment
187
- * @param String $amount
188
*
189
* @return EMerchantPay_Genesis_Model_Direct
190
*/
191
- private function _authorize($payment, $amount)
192
{
193
- Mage::log('Authorize transaction for order #' . $payment->getOrder()->getIncrementId());
194
-
195
try {
196
$this->getHelper()->initClient($this->getCode());
197
198
/** @var Mage_Sales_Model_Order $order */
199
$order = $payment->getOrder();
200
201
- $billing = $order->getBillingAddress();
202
$shipping = $order->getShippingAddress();
203
204
- $genesis = new \Genesis\Genesis('Financial\Cards\Authorize');
205
206
$genesis
207
->request()
208
- ->setTransactionId($this->getHelper()->genTransactionId($order->getIncrementId()))
209
- ->setRemoteIp($this->getHelper()->getRemoteAddress())
210
- ->setUsage($this->getHelper()->getItemList($order))
211
- ->setCurrency(
212
- $order->getOrderCurrencyCode()
213
- )
214
- ->setAmount($amount)
215
- ->setCardHolder($payment->getCcOwner())
216
- ->setCardNumber($payment->getCcNumber())
217
- ->setExpirationYear($payment->getCcExpYear())
218
- ->setExpirationMonth($payment->getCcExpMonth())
219
- ->setCvv($payment->getCcCid())
220
- ->setCustomerEmail($order->getCustomerEmail())
221
- ->setCustomerPhone($billing->getTelephone())
222
- ->setBillingFirstName($billing->getData('firstname'))
223
- ->setBillingLastName($billing->getData('lastname'))
224
- ->setBillingAddress1($billing->getStreet(1))
225
- ->setBillingAddress2($billing->getStreet(2))
226
- ->setBillingZipCode($billing->getPostcode())
227
- ->setBillingCity($billing->getCity())
228
- ->setBillingState($billing->getRegion())
229
- ->setBillingCountry($billing->getCountry())
230
- ->setShippingFirstName($shipping->getData('firstname'))
231
- ->setShippingLastName($shipping->getData('lastname'))
232
- ->setShippingAddress1($shipping->getStreet(1))
233
- ->setShippingAddress2($shipping->getStreet(2))
234
- ->setShippingZipCode($shipping->getPostcode())
235
- ->setShippingCity($shipping->getCity())
236
- ->setShippingState($shipping->getRegion())
237
- ->setShippinCountry($shipping->getCountry());
238
-
239
- $genesis->execute();
240
-
241
- $this->setGenesisResponse(
242
- $genesis->response()->getResponseObject()
243
- );
244
-
245
- $payment
246
->setTransactionId(
247
- $this->getGenesisResponse()->unique_id
248
)
249
- ->setIsTransactionClosed(
250
- false
251
)
252
- ->setIsTransactionPending(
253
- false
254
)
255
- ->setTransactionAdditionalInfo(
256
- array(
257
- Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS =>
258
- $this->getHelper()->getArrayFromGatewayResponse(
259
- $this->getGenesisResponse()
260
- )
261
- ),
262
- null
263
- );
264
-
265
- $payment->save();
266
-
267
- if ($this->getGenesisResponse()->status == \Genesis\API\Constants\Transaction\States::DECLINED) {
268
- throw new \Genesis\Exceptions\ErrorAPI(
269
- $this->getGenesisResponse()->message
270
);
271
- }
272
- } catch (Exception $exception) {
273
- Mage::logException($exception);
274
-
275
- Mage::throwException(
276
- $this->getHelper()->__($exception->getMessage())
277
- );
278
- }
279
-
280
- return $this;
281
- }
282
-
283
- /**
284
- * Genesis Authorize Payment Method with 3D-Secure
285
- *
286
- * @param Varien_Object|Mage_Sales_Model_Order_Payment $payment
287
- * @param String $amount
288
- *
289
- * @return EMerchantPay_Genesis_Model_Direct
290
- */
291
- private function _authorize3d($payment, $amount)
292
- {
293
- Mage::log('Authorize 3D-Secure transaction for order #' . $payment->getOrder()->getIncrementId());
294
-
295
- try {
296
- $this->getHelper()->initClient($this->getCode());
297
-
298
- $order = $payment->getOrder();
299
-
300
- $billing = $order->getBillingAddress();
301
- $shipping = $order->getShippingAddress();
302
-
303
- $genesis = new \Genesis\Genesis('Financial\Cards\Authorize3D');
304
305
$genesis
306
->request()
307
- ->setTransactionId($this->getHelper()->genTransactionId($order->getIncrementId()))
308
- ->setRemoteIp($this->getHelper()->getRemoteAddress())
309
- ->setUsage($this->getHelper()->getItemList($order))
310
- ->setCurrency(
311
- $order->getOrderCurrencyCode()
312
- )
313
- ->setAmount($amount)
314
- ->setCardHolder($payment->getCcOwner())
315
- ->setCardNumber($payment->getCcNumber())
316
- ->setExpirationYear($payment->getCcExpYear())
317
- ->setExpirationMonth($payment->getCcExpMonth())
318
- ->setCvv($payment->getCcCid())
319
- ->setCustomerEmail($order->getCustomerEmail())
320
- ->setCustomerPhone($billing->getTelephone())
321
- ->setBillingFirstName($billing->getData('firstname'))
322
- ->setBillingLastName($billing->getData('lastname'))
323
- ->setBillingAddress1($billing->getStreet(1))
324
- ->setBillingAddress2($billing->getStreet(2))
325
- ->setBillingZipCode($billing->getPostcode())
326
- ->setBillingCity($billing->getCity())
327
- ->setBillingState($billing->getRegion())
328
- ->setBillingCountry($billing->getCountry())
329
- ->setShippingFirstName($shipping->getData('firstname'))
330
- ->setShippingLastName($shipping->getData('lastname'))
331
- ->setShippingAddress1($shipping->getStreet(1))
332
- ->setShippingAddress2($shipping->getStreet(2))
333
- ->setShippingZipCode($shipping->getPostcode())
334
- ->setShippingCity($shipping->getCity())
335
- ->setShippingState($shipping->getRegion())
336
- ->setShippinCountry($shipping->getCountry())
337
- ->setNotificationUrl($this->getHelper()->getNotifyURL('direct'))
338
- ->setReturnSuccessUrl($this->getHelper()->getSuccessURL('direct'))
339
- ->setReturnFailureUrl($this->getHelper()->getFailureURL('direct'));
340
-
341
- $genesis->execute();
342
-
343
- $this->setGenesisResponse(
344
- $genesis->response()->getResponseObject()
345
- );
346
-
347
- $payment
348
- ->setTransactionId(
349
- $this->getGenesisResponse()->unique_id
350
)
351
- ->setIsTransactionClosed(false)
352
- ->setIsTransactionPending(true)
353
- ->setPreparedMessage('3D-Secure: Redirecting customer to a verification page.')
354
- ->setTransactionAdditionalInfo(
355
- array(
356
- Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS =>
357
- $this->getHelper()->getArrayFromGatewayResponse(
358
- $this->getGenesisResponse()
359
- )
360
- ),
361
- null
362
- );
363
-
364
- $payment->save();
365
-
366
- if ($this->getGenesisResponse()->status == \Genesis\API\Constants\Transaction\States::DECLINED) {
367
- throw new \Genesis\Exceptions\ErrorAPI(
368
- $this->getGenesisResponse()->message
369
);
370
- }
371
-
372
- // Save the redirect url with our
373
- $this->getHelper()->getCheckoutSession()->setEmerchantPayDirectRedirectUrl(
374
- $this->getGenesisResponse()->redirect_url
375
- );
376
- } catch (Exception $exception) {
377
- Mage::logException($exception);
378
-
379
- Mage::throwException(
380
- $this->getHelper()->__($exception->getMessage())
381
- );
382
- }
383
-
384
- return $this;
385
- }
386
-
387
- /**
388
- * Genesis Sale (Auth/Capture) Payment Method
389
- *
390
- * @param Varien_Object|Mage_Sales_Model_Order_Payment $payment
391
- * @param String $amount
392
- *
393
- * @return EMerchantPay_Genesis_Model_Direct
394
- */
395
- private function _sale($payment, $amount)
396
- {
397
- Mage::log('Sale transaction for order #' . $payment->getOrder()->getIncrementId());
398
-
399
- try {
400
- $this->getHelper()->initClient($this->getCode());
401
-
402
- $order = $payment->getOrder();
403
-
404
- $billing = $order->getBillingAddress();
405
- $shipping = $order->getShippingAddress();
406
-
407
- $genesis = new \Genesis\Genesis('Financial\Cards\Sale');
408
409
$genesis
410
->request()
411
- ->setTransactionId($this->getHelper()->genTransactionId($order->getIncrementId()))
412
- ->setRemoteIp($this->getHelper()->getRemoteAddress())
413
- ->setUsage($this->getHelper()->getItemList($order))
414
- ->setCurrency(
415
- $order->getOrderCurrencyCode()
416
)
417
- ->setAmount($amount)
418
- ->setCardHolder($payment->getCcOwner())
419
- ->setCardNumber($payment->getCcNumber())
420
- ->setExpirationYear($payment->getCcExpYear())
421
- ->setExpirationMonth($payment->getCcExpMonth())
422
- ->setCvv($payment->getCcCid())
423
- ->setCustomerEmail($order->getCustomerEmail())
424
- ->setCustomerPhone($billing->getTelephone())
425
- ->setBillingFirstName($billing->getData('firstname'))
426
- ->setBillingLastName($billing->getData('lastname'))
427
- ->setBillingAddress1($billing->getStreet(1))
428
- ->setBillingAddress2($billing->getStreet(2))
429
- ->setBillingZipCode($billing->getPostcode())
430
- ->setBillingCity($billing->getCity())
431
- ->setBillingState($billing->getRegion())
432
- ->setBillingCountry($billing->getCountry())
433
- ->setShippingFirstName($shipping->getData('firstname'))
434
- ->setShippingLastName($shipping->getData('lastname'))
435
- ->setShippingAddress1($shipping->getStreet(1))
436
- ->setShippingAddress2($shipping->getStreet(2))
437
- ->setShippingZipCode($shipping->getPostcode())
438
- ->setShippingCity($shipping->getCity())
439
- ->setShippingState($shipping->getRegion())
440
- ->setShippinCountry($shipping->getCountry());
441
442
$genesis->execute();
443
@@ -449,11 +399,12 @@ class EMerchantPay_Genesis_Model_Direct extends Mage_Payment_Model_Method_Cc imp
449
->setTransactionId(
450
$this->getGenesisResponse()->unique_id
451
)
452
- ->setCurrencyCode(
453
- $this->getGenesisResponse()->currency
454
)
455
- ->setIsTransactionClosed(false)
456
- ->setIsTransactionPending(false)
457
->setTransactionAdditionalInfo(
458
array(
459
Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS =>
@@ -464,120 +415,28 @@ class EMerchantPay_Genesis_Model_Direct extends Mage_Payment_Model_Method_Cc imp
464
null
465
);
466
467
- $payment->save();
468
-
469
- if ($this->getGenesisResponse()->status == \Genesis\API\Constants\Transaction\States::DECLINED) {
470
- throw new \Genesis\Exceptions\ErrorAPI(
471
- $this->getGenesisResponse()->message
472
);
473
}
474
- } catch (Exception $exception) {
475
- Mage::logException($exception);
476
477
- Mage::throwException(
478
- $exception->getMessage()
479
- );
480
- }
481
-
482
- return $this;
483
- }
484
-
485
- /**
486
- * Genesis Sale (Auth/Capture) Payment Method with 3D-Secure
487
- *
488
- * @param Varien_Object|Mage_Sales_Model_Order_Payment $payment
489
- * @param String $amount
490
- *
491
- * @return EMerchantPay_Genesis_Model_Direct
492
- */
493
- private function _sale3d($payment, $amount)
494
- {
495
- Mage::log('Sale 3D-Secure transaction for order #' . $payment->getOrder()->getIncrementId());
496
-
497
- try {
498
- $this->getHelper()->initClient($this->getCode());
499
-
500
- $order = $payment->getOrder();
501
-
502
- $billing = $order->getBillingAddress();
503
- $shipping = $order->getShippingAddress();
504
-
505
- $genesis = new \Genesis\Genesis('Financial\Cards\Sale3D');
506
-
507
- $genesis
508
- ->request()
509
- ->setTransactionId($this->getHelper()->genTransactionId($order->getIncrementId()))
510
- ->setRemoteIp($this->getHelper()->getRemoteAddress())
511
- ->setUsage($this->getHelper()->getItemList($order))
512
- ->setCurrency(
513
- $order->getOrderCurrencyCode()
514
- )
515
- ->setAmount($amount)
516
- ->setCardHolder($payment->getCcOwner())
517
- ->setCardNumber($payment->getCcNumber())
518
- ->setExpirationYear($payment->getCcExpYear())
519
- ->setExpirationMonth($payment->getCcExpMonth())
520
- ->setCvv($payment->getCcCid())
521
- ->setCustomerEmail($order->getCustomerEmail())
522
- ->setCustomerPhone($billing->getTelephone())
523
- ->setBillingFirstName($billing->getData('firstname'))
524
- ->setBillingLastName($billing->getData('lastname'))
525
- ->setBillingAddress1($billing->getStreet(1))
526
- ->setBillingAddress2($billing->getStreet(2))
527
- ->setBillingZipCode($billing->getPostcode())
528
- ->setBillingCity($billing->getCity())
529
- ->setBillingState($billing->getRegion())
530
- ->setBillingCountry($billing->getCountry())
531
- ->setShippingFirstName($shipping->getData('firstname'))
532
- ->setShippingLastName($shipping->getData('lastname'))
533
- ->setShippingAddress1($shipping->getStreet(1))
534
- ->setShippingAddress2($shipping->getStreet(2))
535
- ->setShippingZipCode($shipping->getPostcode())
536
- ->setShippingCity($shipping->getCity())
537
- ->setShippingState($shipping->getRegion())
538
- ->setShippinCountry($shipping->getCountry())
539
- ->setNotificationUrl($this->getHelper()->getNotifyURL('direct'))
540
- ->setReturnSuccessUrl($this->getHelper()->getSuccessURL('direct'))
541
- ->setReturnFailureUrl($this->getHelper()->getFailureURL('direct'));
542
-
543
- $genesis->execute();
544
545
- $this->setGenesisResponse(
546
- $genesis->response()->getResponseObject()
547
);
548
549
- // Hold transaction creation
550
- $payment
551
- ->setTransactionId(
552
- $this->getGenesisResponse()->unique_id
553
- )
554
- ->setIsTransactionClosed(false)
555
- ->setIsTransactionPending(true)
556
- ->setPreparedMessage(
557
- $this->getHelper()->__('3D-Secure: Redirecting customer to a verification page.')
558
- )
559
- ->setTransactionAdditionalInfo(
560
- array(
561
- Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS =>
562
- $this->getHelper()->getArrayFromGatewayResponse(
563
- $this->getGenesisResponse()
564
- )
565
- ),
566
- null
567
);
568
-
569
- $payment->save();
570
-
571
- if ($this->getGenesisResponse()->status == \Genesis\API\Constants\Transaction\States::DECLINED) {
572
throw new \Genesis\Exceptions\ErrorAPI(
573
$this->getGenesisResponse()->message
574
);
575
}
576
-
577
- // Save the redirect url with our
578
- $this->getHelper()->getCheckoutSession()->setEmerchantPayDirectRedirectUrl(
579
- $this->getGenesisResponse()->redirect_url
580
- );
581
} catch (Exception $exception) {
582
Mage::logException($exception);
583
@@ -599,7 +458,7 @@ class EMerchantPay_Genesis_Model_Direct extends Mage_Payment_Model_Method_Cc imp
599
*
600
* @throws Mage_Core_Exception
601
*/
602
- private function _capture($payment, $amount)
603
{
604
Mage::log('Capture transaction for order #' . $payment->getOrder()->getIncrementId());
605
@@ -608,7 +467,7 @@ class EMerchantPay_Genesis_Model_Direct extends Mage_Payment_Model_Method_Cc imp
608
609
$authorize = $payment->lookupTransaction(null, Mage_Sales_Model_Order_Payment_Transaction::TYPE_AUTH);
610
611
- $reference_id = $authorize->getTxnId();
612
613
$genesis = new \Genesis\Genesis('Financial\Capture');
614
@@ -623,7 +482,7 @@ class EMerchantPay_Genesis_Model_Direct extends Mage_Payment_Model_Method_Cc imp
623
$this->getHelper()->getRemoteAddress()
624
)
625
->setReferenceId(
626
- $reference_id
627
)
628
->setCurrency(
629
$payment->getOrder()->getOrderCurrencyCode()
@@ -638,10 +497,12 @@ class EMerchantPay_Genesis_Model_Direct extends Mage_Payment_Model_Method_Cc imp
638
639
$payment
640
->setTransactionId(
641
$responseObject->unique_id
642
)
643
->setParentTransactionId(
644
- $reference_id
645
)
646
->setIsTransactionClosed(
647
false
@@ -701,7 +562,7 @@ class EMerchantPay_Genesis_Model_Direct extends Mage_Payment_Model_Method_Cc imp
701
702
$capture = $payment->lookupTransaction(null, Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE);
703
704
- $reference_id = $capture->getTxnId();
705
706
$genesis = new \Genesis\Genesis('Financial\Refund');
707
@@ -716,7 +577,7 @@ class EMerchantPay_Genesis_Model_Direct extends Mage_Payment_Model_Method_Cc imp
716
$this->getHelper()->getRemoteAddress()
717
)
718
->setReferenceId(
719
- $reference_id
720
)
721
->setCurrency(
722
$payment->getOrder()->getOrderCurrencyCode()
@@ -729,10 +590,12 @@ class EMerchantPay_Genesis_Model_Direct extends Mage_Payment_Model_Method_Cc imp
729
730
$payment
731
->setTransactionId(
732
$responseObject->unique_id
733
)
734
->setParentTransactionId(
735
- $reference_id
736
)
737
->setShouldCloseParentTransaction(
738
true
@@ -800,12 +663,15 @@ class EMerchantPay_Genesis_Model_Direct extends Mage_Payment_Model_Method_Cc imp
800
try {
801
$this->getHelper()->initClient($this->getCode());
802
803
- $transactions = $this->getHelper()->getTransactionFromPaymentObject($payment, array(
804
- Mage_Sales_Model_Order_Payment_Transaction::TYPE_AUTH,
805
- Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE
806
- ));
807
808
- $reference_id = $transactions ? reset($transactions)->getTxnId() : null;
809
810
$genesis = new \Genesis\Genesis('Financial\Void');
811
@@ -818,7 +684,7 @@ class EMerchantPay_Genesis_Model_Direct extends Mage_Payment_Model_Method_Cc imp
818
$this->getHelper()->getRemoteAddress()
819
)
820
->setReferenceId(
821
- $reference_id
822
);
823
824
$genesis->execute();
@@ -827,10 +693,12 @@ class EMerchantPay_Genesis_Model_Direct extends Mage_Payment_Model_Method_Cc imp
827
828
$payment
829
->setTransactionId(
830
$responseObject->unique_id
831
)
832
->setParentTransactionId(
833
- $reference_id
834
)
835
->setShouldCloseParentTransaction(
836
true
@@ -919,17 +787,17 @@ class EMerchantPay_Genesis_Model_Direct extends Mage_Payment_Model_Method_Cc imp
919
*
920
* @see EMerchantPay_Genesis_DirectController::notifyAction
921
*
922
- * @param $unique_id
923
* @return mixed
924
*/
925
- public function reconcile($unique_id)
926
{
927
try {
928
$this->getHelper()->initClient($this->getCode());
929
930
$genesis = new \Genesis\Genesis('NonFinancial\Reconcile\Transaction');
931
932
- $genesis->request()->setUniqueId($unique_id);
933
934
$genesis->execute();
935
@@ -949,16 +817,20 @@ class EMerchantPay_Genesis_Model_Direct extends Mage_Payment_Model_Method_Cc imp
949
* Handle an incoming Genesis notification
950
*
951
* @param stdClass $reconcile
952
- * @return bool
953
*/
954
public function processNotification($reconcile)
955
{
956
try {
957
$this->getHelper()->initClient($this->getCode());
958
959
/** @var Mage_Sales_Model_Order_Payment_Transaction $transaction */
960
$transaction = Mage::getModel('sales/order_payment_transaction')->load(
961
$reconcile->unique_id,
962
'txn_id'
963
);
964
@@ -987,7 +859,9 @@ class EMerchantPay_Genesis_Model_Direct extends Mage_Payment_Model_Method_Cc imp
987
988
$transaction->save();
989
990
switch ($reconcile->transaction_type) {
991
case \Genesis\API\Constants\Transaction\Types::AUTHORIZE:
992
case \Genesis\API\Constants\Transaction\Types::AUTHORIZE_3D:
993
$payment->registerAuthorizationNotification($reconcile->amount);
@@ -997,15 +871,25 @@ class EMerchantPay_Genesis_Model_Direct extends Mage_Payment_Model_Method_Cc imp
997
case \Genesis\API\Constants\Transaction\Types::INIT_RECURRING_SALE:
998
case \Genesis\API\Constants\Transaction\Types::INIT_RECURRING_SALE_3D:
999
$payment->setShouldCloseParentTransaction(true);
1000
$payment->registerCaptureNotification($reconcile->amount);
1001
break;
1002
default:
1003
break;
1004
}
1005
1006
if ($this->getHelper()->getIsTransactionTypeInitRecurring($reconcile->transaction_type)) {
1007
$recurringProfile = Mage::getModel('sales/recurring_profile')->load(
1008
$reconcile->unique_id,
1009
'reference_id'
1010
);
1011
@@ -1048,27 +932,13 @@ class EMerchantPay_Genesis_Model_Direct extends Mage_Payment_Model_Method_Cc imp
1048
*/
1049
public function getOrderPlaceRedirectUrl()
1050
{
1051
- if ($this->is3dEnabled()) {
1052
return $this->getHelper()->getRedirectUrl('direct');
1053
}
1054
1055
return false;
1056
}
1057
1058
- /**
1059
- * Check whether we're doing 3D transactions,
1060
- * based on the module configuration
1061
- *
1062
- * @return bool
1063
- */
1064
- private function is3dEnabled()
1065
- {
1066
- return
1067
- $this->getHelper()->getIsTransaction3dSecure(
1068
- $this->getConfigData('genesis_type')
1069
- );
1070
- }
1071
-
1072
/**
1073
* Get the helper or return its instance
1074
*
@@ -1076,9 +946,9 @@ class EMerchantPay_Genesis_Model_Direct extends Mage_Payment_Model_Method_Cc imp
1076
*
1077
* @return EMerchantPay_Genesis_Helper_Data|mixed
1078
*/
1079
- private function getHelper($helper = '')
1080
{
1081
- if (empty($helper)) {
1082
return Mage::helper('emerchantpay');
1083
} else {
1084
return Mage::helper($helper);
@@ -1109,11 +979,14 @@ class EMerchantPay_Genesis_Model_Direct extends Mage_Payment_Model_Method_Cc imp
1109
* @param Mage_Payment_Model_Recurring_Profile $profile
1110
* @param Mage_Payment_Model_Info $payment
1111
* @return $this
1112
*/
1113
public function submitRecurringProfile(
1114
Mage_Payment_Model_Recurring_Profile $profile,
1115
Mage_Payment_Model_Info $payment
1116
) {
1117
$logFileName = $this->getConfigData('cron_recurring_log_file');
1118
$isLogEnabled = !empty($logFileName);
1119
@@ -1124,11 +997,12 @@ class EMerchantPay_Genesis_Model_Direct extends Mage_Payment_Model_Method_Cc imp
1124
$this->getHelper()->initClient($this->getCode());
1125
1126
$transactionType = $this->getConfigData('recurring_transaction_type');
1127
- $transactionClassName = $this->getHelper()->getGenesisTransactionClassName(
1128
- $transactionType
1129
- );
1130
1131
- $genesis = new \Genesis\Genesis("Financial\\Cards\\Recurring\\{$transactionClassName}");
1132
1133
$amount = $profile->getInitAmount() ?: 0;
1134
@@ -1237,16 +1111,20 @@ class EMerchantPay_Genesis_Model_Direct extends Mage_Payment_Model_Method_Cc imp
1237
1238
$responseObject = $genesis->response()->getResponseObject();
1239
1240
if (isset($responseObject->redirect_url)) {
1241
- $this->getHelper()
1242
- ->getCheckoutSession()
1243
- ->setEmerchantPayCheckoutRedirectUrl(
1244
- $responseObject->redirect_url
1245
- );
1246
}
1247
1248
$profile->setReferenceId(
1249
$responseObject->unique_id
1250
);
1251
1252
$payment->setSkipTransactionCreation(true);
@@ -1284,7 +1162,9 @@ class EMerchantPay_Genesis_Model_Direct extends Mage_Payment_Model_Method_Cc imp
1284
1285
$payment
1286
->setTransactionId(
1287
$responseObject->unique_id
1288
);
1289
$payment
1290
->setIsTransactionPending(
@@ -1347,6 +1227,8 @@ class EMerchantPay_Genesis_Model_Direct extends Mage_Payment_Model_Method_Cc imp
1347
$e->getMessage()
1348
);
1349
}
1350
}
1351
1352
/**
29
*
30
* @category
31
*/
32
+ class EMerchantPay_Genesis_Model_Direct
33
+ extends Mage_Payment_Model_Method_Cc implements Mage_Payment_Model_Recurring_Profile_MethodInterface
34
{
35
// Variables
36
protected $_code = 'emerchantpay_direct';
117
return $this;
118
}
119
120
+ /**
121
+ * Retrieve information from payment configuration
122
+ *
123
+ * @param string $field
124
+ * @param int|string|null|Mage_Core_Model_Store $storeId
125
+ *
126
+ * @return mixed
127
+ */
128
+ public function getConfigData($field, $storeId = null)
129
+ {
130
+ if (($field == 'order_status') && (!$this->getIsThreeDEnabled())) {
131
+ //This will force Mage_Sales_Model_Order_Payment to load the default status for State
132
+ //Look into: Mage_Sales_Model_Order_Payment->place()
133
+ return null;
134
+ } else {
135
+ return parent::getConfigData($field, $storeId);
136
+ }
137
+ }
138
+
139
+ /**
140
+ * Retrieves the Module Transaction Type Setting
141
+ *
142
+ * @return string
143
+ */
144
+ protected function getConfigTransactionType()
145
+ {
146
+ return $this->getConfigData('genesis_type');
147
+ }
148
+
149
+ /**
150
+ * Check whether we're doing 3D transactions,
151
+ * based on the module configuration
152
+ *
153
+ * @return bool
154
+ */
155
+ protected function getIsThreeDEnabled()
156
+ {
157
+ return
158
+ $this->getHelper()->getIsTransaction3dSecure(
159
+ $this->getConfigTransactionType()
160
+ );
161
+ }
162
+
163
+ /**
164
+ * Builds full Request Class Name by Transaction Type
165
+ * @param string $transactionType
166
+ * @return string
167
+ */
168
+ protected function getTransactionTypeRequestClassName($transactionType)
169
+ {
170
+ $requestClassName = \Genesis\Utils\Common::snakeCaseToCamelCase(
171
+ str_replace('3d', '3D', $transactionType)
172
+ );
173
+
174
+ $recurringInnerNamespace =
175
+ strpos($transactionType, 'recurring') !== false
176
+ ? "Recurring\\"
177
+ : '';
178
+ return "Financial\\Cards\\{$recurringInnerNamespace}{$requestClassName}";
179
+ }
180
+
181
/**
182
* Payment action getter compatible with payment model
183
*
189
{
190
$this->getHelper()->initLibrary();
191
192
+ switch ($this->getConfigTransactionType()) {
193
default:
194
case \Genesis\API\Constants\Transaction\Types::AUTHORIZE:
195
case \Genesis\API\Constants\Transaction\Types::AUTHORIZE_3D:
196
return Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE;
197
+
198
case \Genesis\API\Constants\Transaction\Types::SALE:
199
case \Genesis\API\Constants\Transaction\Types::SALE_3D:
200
return Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE_CAPTURE;
201
}
202
}
203
211
*/
212
public function authorize(Varien_Object $payment, $amount)
213
{
214
+ if ($this->getIsThreeDEnabled()) {
215
+ Mage::log('Authorize 3D-Secure transaction for order #' . $payment->getOrder()->getIncrementId());
216
} else {
217
+ Mage::log('Authorize transaction for order #' . $payment->getOrder()->getIncrementId());
218
}
219
+
220
+ return $this->processTransaction($payment, $amount);
221
}
222
223
/**
233
$authorize = $payment->lookupTransaction(null, Mage_Sales_Model_Order_Payment_Transaction::TYPE_AUTH);
234
235
if ($authorize) {
236
+ return $this->doCapture($payment, $amount);
237
} else {
238
+ if ($this->getIsThreeDEnabled()) {
239
+ Mage::log('Sale 3D-Secure transaction for order #' . $payment->getOrder()->getIncrementId());
240
} else {
241
+ Mage::log('Sale transaction for order #' . $payment->getOrder()->getIncrementId());
242
}
243
+
244
+ return $this->processTransaction($payment, $amount);
245
}
246
}
247
248
/**
249
+ * Sends a transaction to the Gateway
250
+ * - Authorize
251
+ * - Authorize (3D Secure)
252
+ * - Sale
253
+ * - Sale (3D Secure)
254
*
255
* @param Varien_Object|Mage_Sales_Model_Order_Payment $payment
256
+ * @param float $amount
257
*
258
* @return EMerchantPay_Genesis_Model_Direct
259
*/
260
+ protected function processTransaction(Varien_Object $payment, $amount)
261
{
262
try {
263
$this->getHelper()->initClient($this->getCode());
264
265
+ $transactionType = $this->getConfigTransactionType();
266
+
267
+ $isThreeDEnabled = $this->getIsThreeDEnabled();
268
+
269
/** @var Mage_Sales_Model_Order $order */
270
$order = $payment->getOrder();
271
272
+ $billing = $order->getBillingAddress();
273
$shipping = $order->getShippingAddress();
274
275
+ $genesis = new \Genesis\Genesis(
276
+ $this->getTransactionTypeRequestClassName(
277
+ $transactionType
278
+ )
279
+ );
280
281
$genesis
282
->request()
283
->setTransactionId(
284
+ $this->getHelper()->genTransactionId(
285
+ $order->getIncrementId()
286
+ )
287
)
288
+ ->setRemoteIp(
289
+ $this->getHelper()->getRemoteAddress()
290
)
291
+ ->setUsage(
292
+ $this->getHelper()->getItemList($order)
293
)
294
+ ->setCurrency(
295
+ $order->getOrderCurrencyCode()
296
+ )
297
+ ->setAmount(
298
+ $amount
299
+ )
300
+ ->setCardHolder(
301
+ $payment->getCcOwner()
302
+ )
303
+ ->setCardNumber(
304
+ $payment->getCcNumber()
305
+ )
306
+ ->setExpirationYear(
307
+ $payment->getCcExpYear()
308
+ )
309
+ ->setExpirationMonth(
310
+ $payment->getCcExpMonth()
311
+ )
312
+ ->setCvv(
313
+ $payment->getCcCid()
314
+ )
315
+ ->setCustomerEmail(
316
+ $order->getCustomerEmail()
317
+ )
318
+ ->setCustomerPhone(
319
+ $billing->getTelephone()
320
);
321
322
+ //Billing Information
323
$genesis
324
->request()
325
+ ->setBillingFirstName(
326
+ $billing->getData('firstname')
327
)
328
+ ->setBillingLastName(
329
+ $billing->getData('lastname')
330
+ )
331
+ ->setBillingAddress1(
332
+ $billing->getStreet(1)
333
+ )
334
+ ->setBillingAddress2(
335
+ $billing->getStreet(2)
336
+ )
337
+ ->setBillingZipCode(
338
+ $billing->getPostcode()
339
+ )
340
+ ->setBillingCity(
341
+ $billing->getCity()
342
+ )
343
+ ->setBillingState(
344
+ $billing->getRegion()
345
+ )
346
+ ->setBillingCountry(
347
+ $billing->getCountry()
348
);
349
350
+ //Shipping Information
351
$genesis
352
->request()
353
+ ->setShippingFirstName(
354
+ $shipping->getData('firstname')
355
+ )
356
+ ->setShippingLastName(
357
+ $shipping->getData('lastname')
358
+ )
359
+ ->setShippingAddress1(
360
+ $shipping->getStreet(1)
361
+ )
362
+ ->setShippingAddress2(
363
+ $shipping->getStreet(2)
364
+ )
365
+ ->setShippingZipCode(
366
+ $shipping->getPostcode()
367
+ )
368
+ ->setShippingCity(
369
+ $shipping->getCity()
370
+ )
371
+ ->setShippingState(
372
+ $shipping->getRegion()
373
+ )
374
+ ->setShippingCountry(
375
+ $shipping->getCountry()
376
+ );
377
+
378
+ if ($isThreeDEnabled) {
379
+ $genesis
380
+ ->request()
381
+ ->setNotificationUrl(
382
+ $this->getHelper()->getNotifyURL('direct')
383
)
384
+ ->setReturnSuccessUrl(
385
+ $this->getHelper()->getSuccessURL('direct')
386
+ )
387
+ ->setReturnFailureUrl(
388
+ $this->getHelper()->getFailureURL('direct')
389
+ );
390
+ }
391
392
$genesis->execute();
393
399
->setTransactionId(
400
$this->getGenesisResponse()->unique_id
401
)
402
+ ->setIsTransactionClosed(
403
+ false
404
+ )
405
+ ->setIsTransactionPending(
406
+ $isThreeDEnabled
407
)
408
->setTransactionAdditionalInfo(
409
array(
410
Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS =>
415
null
416
);
417
418
+ if ($isThreeDEnabled) {
419
+ $payment->setPreparedMessage(
420
+ $this->getHelper()->__('3D-Secure: Redirecting customer to a verification page.')
421
);
422
}
423
424
+ $payment->save();
425
426
+ $gatewayStatus = new \Genesis\API\Constants\Transaction\States(
427
+ $this->getGenesisResponse()->status
428
);
429
430
+ if ($gatewayStatus->isPendingAsync()) {
431
+ // Save the redirect url with our
432
+ $this->getHelper()->getCheckoutSession()->setEmerchantPayDirectRedirectUrl(
433
+ $this->getGenesisResponse()->redirect_url
434
);
435
+ } elseif (!$gatewayStatus->isApproved()) {
436
throw new \Genesis\Exceptions\ErrorAPI(
437
$this->getGenesisResponse()->message
438
);
439
}
440
} catch (Exception $exception) {
441
Mage::logException($exception);
442
458
*
459
* @throws Mage_Core_Exception
460
*/
461
+ protected function doCapture($payment, $amount)
462
{
463
Mage::log('Capture transaction for order #' . $payment->getOrder()->getIncrementId());
464
467
468
$authorize = $payment->lookupTransaction(null, Mage_Sales_Model_Order_Payment_Transaction::TYPE_AUTH);
469
470
+ $referenceId = $authorize->getTxnId();
471
472
$genesis = new \Genesis\Genesis('Financial\Capture');
473
482
$this->getHelper()->getRemoteAddress()
483
)
484
->setReferenceId(
485
+ $referenceId
486
)
487
->setCurrency(
488
$payment->getOrder()->getOrderCurrencyCode()
497
498
$payment
499
->setTransactionId(
500
+ // @codingStandardsIgnoreStart
501
$responseObject->unique_id
502
+ // @codingStandardsIgnoreEnd
503
)
504
->setParentTransactionId(
505
+ $referenceId
506
)
507
->setIsTransactionClosed(
508
false
562
563
$capture = $payment->lookupTransaction(null, Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE);
564
565
+ $referenceId = $capture->getTxnId();
566
567
$genesis = new \Genesis\Genesis('Financial\Refund');
568
577
$this->getHelper()->getRemoteAddress()
578
)
579
->setReferenceId(
580
+ $referenceId
581
)
582
->setCurrency(
583
$payment->getOrder()->getOrderCurrencyCode()
590
591
$payment
592
->setTransactionId(
593
+ // @codingStandardsIgnoreStart
594
$responseObject->unique_id
595
+ // @codingStandardsIgnoreEnd
596
)
597
->setParentTransactionId(
598
+ $referenceId
599
)
600
->setShouldCloseParentTransaction(
601
true
663
try {
664
$this->getHelper()->initClient($this->getCode());
665
666
+ $transactions = $this->getHelper()->getTransactionFromPaymentObject(
667
+ $payment,
668
+ array(
669
+ Mage_Sales_Model_Order_Payment_Transaction::TYPE_AUTH,
670
+ Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE
671
+ )
672
+ );
673
674
+ $referenceId = $transactions ? reset($transactions)->getTxnId() : null;
675
676
$genesis = new \Genesis\Genesis('Financial\Void');
677
684
$this->getHelper()->getRemoteAddress()
685
)
686
->setReferenceId(
687
+ $referenceId
688
);
689
690
$genesis->execute();
693
694
$payment
695
->setTransactionId(
696
+ // @codingStandardsIgnoreStart
697
$responseObject->unique_id
698
+ // @codingStandardsIgnoreEnd
699
)
700
->setParentTransactionId(
701
+ $referenceId
702
)
703
->setShouldCloseParentTransaction(
704
true
787
*
788
* @see EMerchantPay_Genesis_DirectController::notifyAction
789
*
790
+ * @param $uniqueId
791
* @return mixed
792
*/
793
+ public function reconcile($uniqueId)
794
{
795
try {
796
$this->getHelper()->initClient($this->getCode());
797
798
$genesis = new \Genesis\Genesis('NonFinancial\Reconcile\Transaction');
799
800
+ $genesis->request()->setUniqueId($uniqueId);
801
802
$genesis->execute();
803
817
* Handle an incoming Genesis notification
818
*
819
* @param stdClass $reconcile
820
+ * @return $this
821
*/
822
+ // @codingStandardsIgnoreStart
823
public function processNotification($reconcile)
824
{
825
+ // @codingStandardsIgnoreEnd
826
try {
827
$this->getHelper()->initClient($this->getCode());
828
829
/** @var Mage_Sales_Model_Order_Payment_Transaction $transaction */
830
$transaction = Mage::getModel('sales/order_payment_transaction')->load(
831
+ // @codingStandardsIgnoreStart
832
$reconcile->unique_id,
833
+ // @codingStandardsIgnoreEnd
834
'txn_id'
835
);
836
859
860
$transaction->save();
861
862
+ // @codingStandardsIgnoreStart
863
switch ($reconcile->transaction_type) {
864
+ // @codingStandardsIgnoreEnd
865
case \Genesis\API\Constants\Transaction\Types::AUTHORIZE:
866
case \Genesis\API\Constants\Transaction\Types::AUTHORIZE_3D:
867
$payment->registerAuthorizationNotification($reconcile->amount);
871
case \Genesis\API\Constants\Transaction\Types::INIT_RECURRING_SALE:
872
case \Genesis\API\Constants\Transaction\Types::INIT_RECURRING_SALE_3D:
873
$payment->setShouldCloseParentTransaction(true);
874
+ $payment->setTransactionId(
875
+ // @codingStandardsIgnoreStart
876
+ $reconcile->unique_id
877
+ // @codingStandardsIgnoreEnd
878
+ );
879
+
880
$payment->registerCaptureNotification($reconcile->amount);
881
break;
882
default:
883
break;
884
}
885
886
+ // @codingStandardsIgnoreStart
887
if ($this->getHelper()->getIsTransactionTypeInitRecurring($reconcile->transaction_type)) {
888
+ // @codingStandardsIgnoreEnd
889
$recurringProfile = Mage::getModel('sales/recurring_profile')->load(
890
+ // @codingStandardsIgnoreStart
891
$reconcile->unique_id,
892
+ // @codingStandardsIgnoreEnd
893
'reference_id'
894
);
895
932
*/
933
public function getOrderPlaceRedirectUrl()
934
{
935
+ if ($this->getIsThreeDEnabled()) {
936
return $this->getHelper()->getRedirectUrl('direct');
937
}
938
939
return false;
940
}
941
942
/**
943
* Get the helper or return its instance
944
*
946
*
947
* @return EMerchantPay_Genesis_Helper_Data|mixed
948
*/
949
+ protected function getHelper($helper = '')
950
{
951
+ if (!$helper) {
952
return Mage::helper('emerchantpay');
953
} else {
954
return Mage::helper($helper);
979
* @param Mage_Payment_Model_Recurring_Profile $profile
980
* @param Mage_Payment_Model_Info $payment
981
* @return $this
982
+ * @throws Mage_Core_Exception
983
*/
984
+ // @codingStandardsIgnoreStart
985
public function submitRecurringProfile(
986
Mage_Payment_Model_Recurring_Profile $profile,
987
Mage_Payment_Model_Info $payment
988
) {
989
+ // @codingStandardsIgnoreEnd
990
$logFileName = $this->getConfigData('cron_recurring_log_file');
991
$isLogEnabled = !empty($logFileName);
992
997
$this->getHelper()->initClient($this->getCode());
998
999
$transactionType = $this->getConfigData('recurring_transaction_type');
1000
1001
+ $genesis = new \Genesis\Genesis(
1002
+ $this->getTransactionTypeRequestClassName(
1003
+ $transactionType
1004
+ )
1005
+ );
1006
1007
$amount = $profile->getInitAmount() ?: 0;
1008
1111
1112
$responseObject = $genesis->response()->getResponseObject();
1113
1114
+ // @codingStandardsIgnoreStart
1115
if (isset($responseObject->redirect_url)) {
1116
+ // @codingStandardsIgnoreEnd
1117
+ $this->getHelper()->getCheckoutSession()->setEmerchantPayCheckoutRedirectUrl(
1118
+ // @codingStandardsIgnoreStart
1119
+ $responseObject->redirect_url
1120
+ // @codingStandardsIgnoreEnd
1121
+ );
1122
}
1123
1124
$profile->setReferenceId(
1125
+ // @codingStandardsIgnoreStart
1126
$responseObject->unique_id
1127
+ // @codingStandardsIgnoreEnd
1128
);
1129
1130
$payment->setSkipTransactionCreation(true);
1162
1163
$payment
1164
->setTransactionId(
1165
+ // @codingStandardsIgnoreStart
1166
$responseObject->unique_id
1167
+ // @codingStandardsIgnoreEnd
1168
);
1169
$payment
1170
->setIsTransactionPending(
1227
$e->getMessage()
1228
);
1229
}
1230
+
1231
+ return $this;
1232
}
1233
1234
/**
app/code/community/EMerchantPay/Genesis/Model/Task/Recurring.php CHANGED
@@ -41,7 +41,7 @@ class EMerchantPay_Genesis_Model_Task_Recurring