Iridiumcorp_Tpg - Version 1.15.0

Version Notes

Option to select transaction type: PREAUTH or SALE.
CrossReference feature added with new transaction types: VOID, REFUND and COLLECTION.
Fixed stock management bug on Hosted Payment Form payment when clicking on BACK button before payment is processed.

Download this release

Release Info

Developer Magento Core Team
Extension Iridiumcorp_Tpg
Version 1.15.0
Comparing to
See all releases


Code changes from version 1.14.1 to 1.15.0

app/code/local/Iridiumcorp/Sales/Model/Order/Payment.php CHANGED
@@ -175,7 +175,21 @@ class Iridiumcorp_Sales_Model_Order_Payment extends Mage_Sales_Model_Order_Payme
175
  public function place()
176
  {
177
  $nVersion = Mage::getModel('tpg/direct')->getVersion();
178
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
179
  if($nVersion >= 1411 || $nVersion == 1410 || $nVersion == 1401 || $nVersion == 1400)
180
  {
181
  Mage::dispatchEvent('sales_order_payment_place_start', array('payment' => $this));
@@ -242,7 +256,14 @@ class Iridiumcorp_Sales_Model_Order_Payment extends Mage_Sales_Model_Order_Payme
242
  if ($stateObject->getState() && $stateObject->getStatus())
243
  {
244
  $orderState = $stateObject->getState();
245
- $orderStatus = $stateObject->getStatus();
 
 
 
 
 
 
 
246
  $orderIsNotified = $stateObject->getIsNotified();
247
  }
248
  else if($order->getIsThreeDSecurePending())
@@ -263,11 +284,18 @@ class Iridiumcorp_Sales_Model_Order_Payment extends Mage_Sales_Model_Order_Payme
263
  }
264
  else
265
  {
266
- $orderStatus = $methodInstance->getConfigData('order_status');
267
- if (!$orderStatus || $order->getIsVirtual())
268
  {
269
- $orderStatus = $order->getConfig()->getStateDefaultStatus($orderState);
270
- }
 
 
 
 
 
 
 
 
271
  }
272
 
273
  $isCustomerNotified = (null !== $orderIsNotified) ? $orderIsNotified : $order->getCustomerNoteNotify();
@@ -366,26 +394,44 @@ class Iridiumcorp_Sales_Model_Order_Payment extends Mage_Sales_Model_Order_Payme
366
  }
367
 
368
  $orderIsNotified = null;
369
- if ($stateObject->getState() && $stateObject->getStatus()) {
 
370
  $orderState = $stateObject->getState();
371
- $orderStatus = $stateObject->getStatus();
 
 
 
 
 
 
 
372
  $orderIsNotified = $stateObject->getIsNotified();
373
- } else {
 
 
374
  /*
375
  * this flag will set if the order went to as authorization under fraud service for payflowpro
376
  */
377
- if ($this->getFraudFlag()) {
 
378
  $orderStatus = $methodInstance->getConfigData('fraud_order_status');
379
  $orderState = Mage_Sales_Model_Order::STATE_HOLDED;
380
- } else {
381
- /**
382
- * Change order status if it specified
383
- */
384
- $orderStatus = $methodInstance->getConfigData('order_status');
385
  }
386
 
387
- if (!$orderStatus || $this->getOrder()->getIsVirtual()) {
388
- $orderStatus = $this->getOrder()->getConfig()->getStateDefaultStatus($orderState);
 
 
 
 
 
 
 
 
389
  }
390
  }
391
 
@@ -401,4 +447,107 @@ class Iridiumcorp_Sales_Model_Order_Payment extends Mage_Sales_Model_Order_Payme
401
  return $this;
402
  }
403
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
404
  }
175
  public function place()
176
  {
177
  $nVersion = Mage::getModel('tpg/direct')->getVersion();
178
+ $paymentAction = Mage::getModel('tpg/direct')->getConfigData('payment_action');
179
+
180
+ if($paymentAction == Mage_Paygate_Model_Authorizenet::ACTION_AUTHORIZE_CAPTURE)
181
+ {
182
+ $ircOrderStatus = "irc_paid";
183
+ }
184
+ else if($paymentAction == Mage_Paygate_Model_Authorizenet::ACTION_AUTHORIZE)
185
+ {
186
+ $ircOrderStatus = "irc_preauth";
187
+ }
188
+ else
189
+ {
190
+ $ircOrderStatus = null;
191
+ }
192
+
193
  if($nVersion >= 1411 || $nVersion == 1410 || $nVersion == 1401 || $nVersion == 1400)
194
  {
195
  Mage::dispatchEvent('sales_order_payment_place_start', array('payment' => $this));
256
  if ($stateObject->getState() && $stateObject->getStatus())
257
  {
258
  $orderState = $stateObject->getState();
259
+ if($ircOrderStatus == null)
260
+ {
261
+ $orderStatus = $stateObject->getStatus();
262
+ }
263
+ else
264
+ {
265
+ $orderStatus = $ircOrderStatus;
266
+ }
267
  $orderIsNotified = $stateObject->getIsNotified();
268
  }
269
  else if($order->getIsThreeDSecurePending())
284
  }
285
  else
286
  {
287
+ if($ircOrderStatus == null)
 
288
  {
289
+ $orderStatus = $methodInstance->getConfigData('order_status');
290
+ if (!$orderStatus || $order->getIsVirtual())
291
+ {
292
+ $orderStatus = $order->getConfig()->getStateDefaultStatus($orderState);
293
+ }
294
+ }
295
+ else
296
+ {
297
+ $orderStatus = $ircOrderStatus;
298
+ }
299
  }
300
 
301
  $isCustomerNotified = (null !== $orderIsNotified) ? $orderIsNotified : $order->getCustomerNoteNotify();
394
  }
395
 
396
  $orderIsNotified = null;
397
+ if ($stateObject->getState() && $stateObject->getStatus())
398
+ {
399
  $orderState = $stateObject->getState();
400
+ if($ircOrderStatus == null)
401
+ {
402
+ $orderStatus = $stateObject->getStatus();
403
+ }
404
+ else
405
+ {
406
+ $orderStatus = $ircOrderStatus;
407
+ }
408
  $orderIsNotified = $stateObject->getIsNotified();
409
+ }
410
+ else
411
+ {
412
  /*
413
  * this flag will set if the order went to as authorization under fraud service for payflowpro
414
  */
415
+ if ($this->getFraudFlag())
416
+ {
417
  $orderStatus = $methodInstance->getConfigData('fraud_order_status');
418
  $orderState = Mage_Sales_Model_Order::STATE_HOLDED;
419
+ }
420
+ else
421
+ {
422
+ $orderStatus = $methodInstance->getConfigData('order_status');
 
423
  }
424
 
425
+ if($ircOrderStatus == null)
426
+ {
427
+ if (!$orderStatus || $this->getOrder()->getIsVirtual())
428
+ {
429
+ $orderStatus = $this->getOrder()->getConfig()->getStateDefaultStatus($orderState);
430
+ }
431
+ }
432
+ else
433
+ {
434
+ $orderStatus = $ircOrderStatus;
435
  }
436
  }
437
 
447
  return $this;
448
  }
449
  }
450
+
451
+ /**
452
+ * Create transaction,
453
+ * prepare its insertion into hierarchy and add its information to payment and comments
454
+ *
455
+ * To add transactions and related information,
456
+ * the following information should be set to payment before processing:
457
+ * - transaction_id
458
+ * - is_transaction_closed (optional) - whether transaction should be closed or open (closed by default)
459
+ * - parent_transaction_id (optional)
460
+ * - should_close_parent_transaction (optional) - whether to close parent transaction (closed by default)
461
+ *
462
+ * If the sales document is specified, it will be linked to the transaction as related for future usage.
463
+ * Currently transaction ID is set into the sales object
464
+ * This method writes the added transaction ID into last_trans_id field of the payment object
465
+ *
466
+ * To make sure transaction object won't cause trouble before saving, use $failsafe = true
467
+ *
468
+ * @param string $type
469
+ * @param Mage_Sales_Model_Abstract $salesDocument
470
+ * @param bool $failsafe
471
+ * @return null|Mage_Sales_Model_Order_Payment_Transaction
472
+ */
473
+ protected function _addTransaction($type, $salesDocument = null, $failsafe = false)
474
+ {
475
+ $model = Mage::getModel('tpg/direct');
476
+ $nVersion = $model->getVersion();
477
+
478
+ if($nVersion >= 1501)
479
+ {
480
+ if ($this->getSkipTransactionCreation())
481
+ {
482
+ $this->unsTransactionId();
483
+ return null;
484
+ }
485
+ }
486
+
487
+ // look for set transaction ids
488
+ $transactionId = $this->getTransactionId();
489
+ if (null !== $transactionId)
490
+ {
491
+ // set transaction parameters
492
+ $transaction = false;
493
+ if ($this->getOrder()->getId())
494
+ {
495
+ $transaction = $this->_lookupTransaction($transactionId);
496
+ }
497
+
498
+ if (!$transaction)
499
+ {
500
+ $transaction = Mage::getModel('sales/order_payment_transaction')->setTxnId($transactionId);
501
+ }
502
+ $transaction
503
+ ->setOrderPaymentObject($this)
504
+ ->setTxnType($type)
505
+ ->isFailsafe($failsafe);
506
+
507
+ if ($this->hasIsTransactionClosed())
508
+ {
509
+ $transaction->setIsClosed((int)$this->getIsTransactionClosed());
510
+ }
511
+
512
+ //set transaction addition information
513
+ if ($this->_transactionAdditionalInfo)
514
+ {
515
+ foreach ($this->_transactionAdditionalInfo as $key => $value)
516
+ {
517
+ $transaction->setAdditionalInformation($key, $value);
518
+ }
519
+ }
520
+
521
+ // link with sales entities
522
+ $this->setLastTransId($transactionId);
523
+ $this->setCreatedTransaction($transaction);
524
+ $this->getOrder()->addRelatedObject($transaction);
525
+ if ($salesDocument && $salesDocument instanceof Mage_Sales_Model_Abstract)
526
+ {
527
+ $salesDocument->setTransactionId($transactionId);
528
+ // TODO: linking transaction with the sales document
529
+ }
530
+
531
+ // link with parent transaction
532
+ $parentTransactionId = $this->getParentTransactionId();
533
+
534
+ if ($parentTransactionId)
535
+ {
536
+ $transaction->setParentTxnId($parentTransactionId);
537
+ if ($this->getShouldCloseParentTransaction())
538
+ {
539
+ $parentTransaction = $this->_lookupTransaction($parentTransactionId);
540
+ if ($parentTransaction)
541
+ {
542
+ if (!$parentTransaction->getIsClosed())
543
+ {
544
+ $parentTransaction->isFailsafe($failsafe)->close(false);
545
+ }
546
+ $this->getOrder()->addRelatedObject($parentTransaction);
547
+ }
548
+ }
549
+ }
550
+ return $transaction;
551
+ }
552
+ }
553
  }
app/code/local/Iridiumcorp/Sales/etc/config.xml CHANGED
@@ -11,7 +11,7 @@
11
  <rewrite>
12
  <order>Iridiumcorp_Sales_Model_Order</order>
13
  <order_invoice>Iridiumcorp_Sales_Model_Order_Invoice</order_invoice>
14
- <order_payment>Iridiumcorp_Sales_Model_Order_Payment</order_payment>
15
  <service_quote>Iridiumcorp_Sales_Model_Service_Quote</service_quote>
16
  </rewrite>
17
  </sales>
@@ -23,11 +23,11 @@
23
  <label>Iridiumcorp - Successful Payment</label>
24
  </irc_paid>
25
  <irc_pending_threed_secure translate="label">
26
- <label>Iridiumcorp - Pending 3D Secure</label>
27
- </irc_pending_threed_secure>
28
- <irc_failed_threed_secure translate="label">
29
- <label>Iridiumcorp - Failed 3D Secure</label>
30
- </irc_failed_threed_secure>
31
  <irc_pending translate="label">
32
  <label>Iridiumcorp - Pending Hosted Payment</label>
33
  </irc_pending>
@@ -37,6 +37,18 @@
37
  <irc_failed_hosted_payment translate="label">
38
  <label>Iridiumcorp - Failed Hosted Payment</label>
39
  </irc_failed_hosted_payment>
 
 
 
 
 
 
 
 
 
 
 
 
40
  </statuses>
41
  </order>
42
  </sales>
11
  <rewrite>
12
  <order>Iridiumcorp_Sales_Model_Order</order>
13
  <order_invoice>Iridiumcorp_Sales_Model_Order_Invoice</order_invoice>
14
+ <order_payment>Iridiumcorp_Sales_Model_Order_Payment</order_payment>
15
  <service_quote>Iridiumcorp_Sales_Model_Service_Quote</service_quote>
16
  </rewrite>
17
  </sales>
23
  <label>Iridiumcorp - Successful Payment</label>
24
  </irc_paid>
25
  <irc_pending_threed_secure translate="label">
26
+ <label>Iridiumcorp - Pending 3D Secure</label>
27
+ </irc_pending_threed_secure>
28
+ <irc_failed_threed_secure translate="label">
29
+ <label>Iridiumcorp - Failed 3D Secure</label>
30
+ </irc_failed_threed_secure>
31
  <irc_pending translate="label">
32
  <label>Iridiumcorp - Pending Hosted Payment</label>
33
  </irc_pending>
37
  <irc_failed_hosted_payment translate="label">
38
  <label>Iridiumcorp - Failed Hosted Payment</label>
39
  </irc_failed_hosted_payment>
40
+ <irc_refunded translate="label">
41
+ <label>Iridiumcorp - Payment Refunded</label>
42
+ </irc_refunded>
43
+ <irc_voided translate="label">
44
+ <label>Iridiumcorp - Payment Voided</label>
45
+ </irc_voided>
46
+ <irc_preauth translate="label">
47
+ <label>Iridiumcorp - Payment PreAuthorized</label>
48
+ </irc_preauth>
49
+ <irc_collected translate="label">
50
+ <label>Iridiumcorp - Payment Collected</label>
51
+ </irc_collected>
52
  </statuses>
53
  </order>
54
  </sales>
app/code/local/Iridiumcorp/Tpg/Block/Adminhtml/Sales/Order/Payment.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Iridiumcorp_Tpg_Block_Adminhtml_Sales_Order_Payment extends Mage_Adminhtml_Block_Sales_Order_Payment
3
+ {
4
+ public function setPayment($payment)
5
+ {
6
+ parent::setPayment($payment);
7
+ $paymentInfoBlock = Mage::helper('payment')->getInfoBlock($payment);
8
+
9
+ if ($payment->getMethod() == 'tpg')
10
+ {
11
+
12
+ $paymentInfoBlock->setTemplate('payment/info/cc_tpg.phtml');
13
+ }
14
+
15
+ $this->setChild('info', $paymentInfoBlock);
16
+ $this->setData('payment', $payment);
17
+ return $this;
18
+ }
19
+
20
+ protected function _toHtml()
21
+ {
22
+ return $this->getChildHtml('info');
23
+ }
24
+
25
+ }
app/code/local/Iridiumcorp/Tpg/Model/Common/ThePaymentGateway/PaymentSystem.php CHANGED
@@ -1519,7 +1519,7 @@
1519
 
1520
  $todTransactionOutputData = null;
1521
  $goGatewayOutput = null;
1522
-
1523
  $sSOAPClient = new IRC_SOAP('CrossReferenceTransaction', IRC_GatewayTransaction::getSOAPNamespace());
1524
  // transaction details
1525
  if ($this->m_tdTransactionDetails != null)
1519
 
1520
  $todTransactionOutputData = null;
1521
  $goGatewayOutput = null;
1522
+
1523
  $sSOAPClient = new IRC_SOAP('CrossReferenceTransaction', IRC_GatewayTransaction::getSOAPNamespace());
1524
  // transaction details
1525
  if ($this->m_tdTransactionDetails != null)
app/code/local/Iridiumcorp/Tpg/Model/Direct.php CHANGED
@@ -19,9 +19,9 @@ class Iridiumcorp_Tpg_Model_Direct extends Mage_Payment_Model_Method_Abstract
19
  protected $_isGateway = true;
20
  protected $_canAuthorize = true;
21
  protected $_canCapture = true;
22
- protected $_canCapturePartial = true;
23
- protected $_canRefund = false;
24
- protected $_canVoid = false;
25
  protected $_canUseInternal = true;
26
  protected $_canUseCheckout = true;
27
  protected $_canUseForMultishipping = true;
@@ -77,8 +77,33 @@ class Iridiumcorp_Tpg_Model_Direct extends Mage_Payment_Model_Method_Abstract
77
  public function authorize(Varien_Object $payment, $amount)
78
  {
79
  $error = false;
 
 
80
 
81
- Mage::throwException('This payment module only allow capture payments.');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
 
83
  return $this;
84
  }
@@ -129,33 +154,41 @@ class Iridiumcorp_Tpg_Model_Direct extends Mage_Payment_Model_Method_Abstract
129
  return $this;
130
  }
131
 
132
- // fresh payment request
133
- $session->setThreedsecurerequired(null)
134
- ->setRedirectedpayment(null)
135
- ->setIshostedpayment(null)
136
- ->setHostedPayment(null)
137
- ->setMd(null)
138
- ->setPareq(null)
139
- ->setAcsurl(null)
140
- ->setPaymentprocessorresponse(null);
141
-
142
- $payment->setAmount($amount);
143
-
144
- switch ($mode)
145
- {
146
- case Iridiumcorp_Tpg_Model_Source_PaymentMode::PAYMENT_MODE_DIRECT_API:
147
- $error = $this->_runTransaction($payment, $amount);
148
- break;
149
- case Iridiumcorp_Tpg_Model_Source_PaymentMode::PAYMENT_MODE_HOSTED_PAYMENT_FORM:
150
- $error = $this->_runHostedPaymentTransaction($payment, $amount);
151
- break;
152
- case Iridiumcorp_Tpg_Model_Source_PaymentMode::PAYMENT_MODE_TRANSPARENT_REDIRECT:
153
- $error = $this->_runTransparentRedirectTransaction($payment, $amount);
154
- break;
155
- default:
156
- Mage::throwException('Invalid payment type: '.$this->getConfigData('mode'));
157
- break;
158
- }
 
 
 
 
 
 
 
 
159
  }
160
 
161
  if($error)
@@ -213,6 +246,7 @@ class Iridiumcorp_Tpg_Model_Direct extends Mage_Payment_Model_Method_Abstract
213
  $szEmailAddress = $billingAddress->getCustomerEmail();
214
  $szPhoneNumber = $billingAddress->getTelephone();
215
  $nDecimalAmount;
 
216
 
217
  $PaymentProcessorFullDomain = $this->_getPaymentProcessorFullDomain();
218
  $iclISOCurrencyList = IRC_ISOCurrencies::getISOCurrencyList();
@@ -223,12 +257,26 @@ class Iridiumcorp_Tpg_Model_Direct extends Mage_Payment_Model_Method_Abstract
223
  $rgeplRequestGatewayEntryPointList->add("https://gw2.".$PaymentProcessorFullDomain, 200, 2);
224
  $rgeplRequestGatewayEntryPointList->add("https://gw3.".$PaymentProcessorFullDomain, 300, 2);
225
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
226
  $cdtCardDetailsTransaction = new IRC_CardDetailsTransaction($rgeplRequestGatewayEntryPointList);
227
 
228
  $cdtCardDetailsTransaction->getMerchantAuthentication()->setMerchantID($MerchantID);
229
  $cdtCardDetailsTransaction->getMerchantAuthentication()->setPassword($Password);
230
 
231
- $cdtCardDetailsTransaction->getTransactionDetails()->getMessageDetails()->setTransactionType("SALE");
232
 
233
  if ($szCurrencyShort != '' &&
234
  $iclISOCurrencyList->getISOCurrency($szCurrencyShort, $icISOCurrency))
@@ -237,9 +285,8 @@ class Iridiumcorp_Tpg_Model_Direct extends Mage_Payment_Model_Method_Abstract
237
  $cdtCardDetailsTransaction->getTransactionDetails()->getCurrencyCode()->setValue($icISOCurrency->getISOCode());
238
  }
239
 
240
- $power = pow(10, $icISOCurrency->getExponent());
241
- $nDecimalAmount = $amount * $power;
242
- //$nAmount = new IRC_NullableInt($nDecimalAmount);
243
  $cdtCardDetailsTransaction->getTransactionDetails()->getAmount()->setValue($nDecimalAmount);
244
 
245
  $cdtCardDetailsTransaction->getTransactionDetails()->setOrderID($szOrderID);
@@ -315,18 +362,31 @@ class Iridiumcorp_Tpg_Model_Direct extends Mage_Payment_Model_Method_Abstract
315
  {
316
  $szLogMessage = "Transaction could not be completed for OrderID: ".$szOrderID.". Result details: ";
317
  $szNotificationMessage = 'Payment Processor Response: '.$cdtrCardDetailsTransactionResult->getMessage();
318
- $szCrossReference = $todTransactionOutputData->getCrossReference();
 
 
 
 
319
 
320
  switch ($cdtrCardDetailsTransactionResult->getStatusCode())
321
  {
322
  case 0:
323
  // status code of 0 - means transaction successful
324
- $szLogMessage = "Transaction successfully completed for OrderID: ".$szOrderID.". Result object details: ";
 
 
 
 
 
 
 
 
 
325
  Mage::getSingleton('core/session')->addSuccess($szNotificationMessage);
326
  break;
327
  case 3:
328
  // status code of 3 - means 3D Secure authentication required
329
- $szLogMessage = "3D Secure Authentication required for OrderID: ".$szOrderID.". Result object details: ";
330
  $szNotificationMessage = '';
331
 
332
  $szPaReq = $todTransactionOutputData->getThreeDSecureOutputData()->getPaREQ();
@@ -349,7 +409,7 @@ class Iridiumcorp_Tpg_Model_Direct extends Mage_Payment_Model_Method_Abstract
349
  case 20:
350
  // status code of 20 - means duplicate transaction
351
  $szPreviousTransactionMessage = $cdtrCardDetailsTransactionResult->getPreviousTransactionResult()->getMessage();
352
- $szLogMessage = "Duplicate transaction for OrderID: ".$szOrderID.". A duplicate transaction means that a transaction with these details has already been processed by the payment provider. The details of the original transaction: ".$szPreviousTransactionMessage.". Result object details: ";
353
  $szNotificationMessage = $szNotificationMessage.". A duplicate transaction means that a transaction with these details has already been processed by the payment provider. The details of the original transaction - Previous Transaction Response: ".$szPreviousTransactionMessage;
354
 
355
  if ($cdtrCardDetailsTransactionResult->getPreviousTransactionResult()->getStatusCode()->getValue() != 0)
@@ -375,7 +435,7 @@ class Iridiumcorp_Tpg_Model_Direct extends Mage_Payment_Model_Method_Abstract
375
  }
376
  $szLogMessage = $szLogMessage." ";
377
  }
378
- $szLogMessage = $szLogMessage.' Result object details: ';
379
  break;
380
  default:
381
  // unhandled status code
@@ -399,13 +459,7 @@ class Iridiumcorp_Tpg_Model_Direct extends Mage_Payment_Model_Method_Abstract
399
  $payment->setIsInvoicePaid(true);
400
  }
401
  }
402
-
403
- if($szCrossReference)
404
- {
405
- $szAdditionalData = "CrossReference=".$szCrossReference;
406
- $payment->setAdditionalData($szAdditionalData);
407
- }
408
-
409
  return $error;
410
  }
411
 
@@ -482,8 +536,7 @@ class Iridiumcorp_Tpg_Model_Direct extends Mage_Payment_Model_Method_Abstract
482
  $nCurrencyCode = $icISOCurrency->getISOCode();
483
  }
484
 
485
- $power = pow(10, $icISOCurrency->getExponent());
486
- $nAmount = $amount * $power;
487
 
488
  $szISO2CountryCode = $billingAddress->getCountry();
489
  $szCountryShort = $this->_getISO3Code($szISO2CountryCode);
@@ -493,10 +546,24 @@ class Iridiumcorp_Tpg_Model_Direct extends Mage_Payment_Model_Method_Abstract
493
  }
494
 
495
  $szOrderID = $payment->getOrder()->increment_id;
496
- $szTransactionType = 'SALE';
497
  //date time with 2008-12-01 14:12:00 +01:00 format
498
  $szTransactionDateTime = date('Y-m-d H:i:s P');
499
  $szOrderDescription = '';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
500
 
501
  $szCustomerName = $billingAddress->getfirstname();
502
  if($billingAddress->getfirstname())
@@ -578,6 +645,10 @@ class Iridiumcorp_Tpg_Model_Direct extends Mage_Payment_Model_Method_Abstract
578
  $session->setRedirectionmethod('_runRedirectedPaymentComplete');
579
  $payment->getOrder()->setIsHostedPaymentPending(true);
580
  }
 
 
 
 
581
  }
582
 
583
  /**
@@ -611,15 +682,28 @@ class Iridiumcorp_Tpg_Model_Direct extends Mage_Payment_Model_Method_Abstract
611
  $nCurrencyCode = $icISOCurrency->getISOCode();
612
  }
613
 
614
- $power = pow(10, $icISOCurrency->getExponent());
615
- $nAmount = $amount * $power;
616
 
617
  $szOrderID = $payment->getOrder()->increment_id;
618
- $szTransactionType = 'SALE';
619
  //date time with 2008-12-01 14:12:00 +01:00 format
620
  $szTransactionDateTime = date('Y-m-d H:i:s P');
621
  $szOrderDescription = '';
622
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
623
  $szAddress1 = $billingAddress->getStreet1();
624
  $szAddress2 = $billingAddress->getStreet2();
625
  $szAddress3 = $billingAddress->getStreet3();
@@ -682,6 +766,10 @@ class Iridiumcorp_Tpg_Model_Direct extends Mage_Payment_Model_Method_Abstract
682
  Mage::getSingleton('checkout/session')->setRedirectionmethod('_runRedirectedPaymentComplete');
683
  $payment->getOrder()->setIsHostedPaymentPending(true);
684
  }
 
 
 
 
685
  }
686
 
687
  /**
@@ -731,13 +819,20 @@ class Iridiumcorp_Tpg_Model_Direct extends Mage_Payment_Model_Method_Abstract
731
  else
732
  {
733
  $message = "Payment Processor Response: ".$tdsarThreeDSecureAuthenticationResult->getMessage();
734
- $szLogMessage = "3D Secure transaction could not be completed for OrderID: ".$szOrderID.". Result object details: ";
 
735
 
736
  switch ($tdsarThreeDSecureAuthenticationResult->getStatusCode())
737
  {
738
  case 0:
739
  // status code of 0 - means transaction successful
740
- $szLogMessage = "3D Secure transaction successfully completed for OrderID: ".$szOrderID.". Result object details: ";
 
 
 
 
 
 
741
  break;
742
  case 5:
743
  // status code of 5 - means transaction declined
@@ -746,7 +841,7 @@ class Iridiumcorp_Tpg_Model_Direct extends Mage_Payment_Model_Method_Abstract
746
  case 20:
747
  // status code of 20 - means duplicate transaction
748
  $szPreviousTransactionMessage = $tdsarThreeDSecureAuthenticationResult->getPreviousTransactionResult()->getMessage();
749
- $szLogMessage = "Duplicate transaction for OrderID: ".$szOrderID.". A duplicate transaction means that a transaction with these details has already been processed by the payment provider. The details of the original transaction: ".$szPreviousTransactionMessage.". Result object details: ";
750
 
751
  if ($tdsarThreeDSecureAuthenticationResult->getPreviousTransactionResult()->getStatusCode()->getValue() == 0)
752
  {
@@ -796,6 +891,8 @@ class Iridiumcorp_Tpg_Model_Direct extends Mage_Payment_Model_Method_Abstract
796
  {
797
  $payment->setStatus(self::STATUS_APPROVED);
798
 
 
 
799
  if($nVersion == 1324 || $nVersion == 1330)
800
  {
801
  $payment->setIsInvoicePaid(true);
@@ -823,11 +920,14 @@ class Iridiumcorp_Tpg_Model_Direct extends Mage_Payment_Model_Method_Abstract
823
  }
824
 
825
  $message = "Payment Processor Response: ".$szMessage;
826
-
827
  switch ($szStatusCode)
828
  {
829
  case "0":
830
  Mage::log($szWording."transaction successfully completed. ".$message);
 
 
 
831
  break;
832
  case "20":
833
  Mage::log("Duplicate ".$szWording."transaction. ".$message);
@@ -846,11 +946,9 @@ class Iridiumcorp_Tpg_Model_Direct extends Mage_Payment_Model_Method_Abstract
846
  }
847
 
848
  $session->setPaymentprocessorresponse($message);
849
- if($szCrossReference)
850
- {
851
- $szAdditionalData = "CrossReference=".$szCrossReference;
852
- $payment->setAdditionalData($szAdditionalData);
853
- }
854
 
855
  if($error == true)
856
  {
@@ -880,17 +978,39 @@ class Iridiumcorp_Tpg_Model_Direct extends Mage_Payment_Model_Method_Abstract
880
  {
881
  $result = false;
882
  $session = Mage::getSingleton('checkout/session');
 
 
883
 
884
  if($session->getMd() &&
885
  $session->getAcsurl() &&
886
  $session->getPareq())
887
  {
888
  // Direct (API) for 3D Secure payments
 
 
 
 
 
 
 
 
 
 
889
  $result = Mage::getUrl('tpg/payment/threedsecure', array('_secure' => true));
890
  }
891
  if($session->getHashdigest())
892
  {
893
  // Hosted Payment Form and Transparent Redirect payments
 
 
 
 
 
 
 
 
 
 
894
  $result = Mage::getUrl('tpg/payment/redirect', array('_secure' => true));
895
  }
896
 
@@ -973,4 +1093,469 @@ class Iridiumcorp_Tpg_Model_Direct extends Mage_Payment_Model_Method_Abstract
973
 
974
  return $magentoVersion;
975
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
976
  }
19
  protected $_isGateway = true;
20
  protected $_canAuthorize = true;
21
  protected $_canCapture = true;
22
+ protected $_canCapturePartial = false;
23
+ protected $_canRefund = true;
24
+ protected $_canVoid = true;
25
  protected $_canUseInternal = true;
26
  protected $_canUseCheckout = true;
27
  protected $_canUseForMultishipping = true;
77
  public function authorize(Varien_Object $payment, $amount)
78
  {
79
  $error = false;
80
+ $mode = $this->getConfigData('mode');
81
+ $nVersion = $this->getVersion();
82
 
83
+ //Mage::throwException('This payment module only allow capture payments.');
84
+
85
+ // TODO : need to finish for non Direct API methods
86
+ switch ($mode)
87
+ {
88
+ case Iridiumcorp_Tpg_Model_Source_PaymentMode::PAYMENT_MODE_DIRECT_API:
89
+ $error = $this->_runTransaction($payment, $amount);
90
+ break;
91
+ case Iridiumcorp_Tpg_Model_Source_PaymentMode::PAYMENT_MODE_HOSTED_PAYMENT_FORM:
92
+ $error = $this->_runHostedPaymentTransaction($payment, $amount);
93
+ break;
94
+ case Iridiumcorp_Tpg_Model_Source_PaymentMode::PAYMENT_MODE_TRANSPARENT_REDIRECT:
95
+ $error = $this->_runTransparentRedirectTransaction($payment, $amount);
96
+ //Mage::throwException('TR not supported');
97
+ break;
98
+ default:
99
+ Mage::throwException('Invalid payment type: '.$this->getConfigData('mode'));
100
+ break;
101
+ }
102
+
103
+ if($error)
104
+ {
105
+ Mage::throwException($error);
106
+ }
107
 
108
  return $this;
109
  }
154
  return $this;
155
  }
156
 
157
+ if($session->getIsCollectionCrossReferenceTransaction())
158
+ {
159
+ // do a CrossReference transaction
160
+ $error = $this->_runCrossReferenceTransaction($payment, "COLLECTION", $amount);
161
+ }
162
+ else
163
+ {
164
+ // fresh payment request
165
+ $session->setThreedsecurerequired(null)
166
+ ->setRedirectedpayment(null)
167
+ ->setIshostedpayment(null)
168
+ ->setHostedPayment(null)
169
+ ->setMd(null)
170
+ ->setPareq(null)
171
+ ->setAcsurl(null)
172
+ ->setPaymentprocessorresponse(null);
173
+
174
+ $payment->setAmount($amount);
175
+
176
+ switch ($mode)
177
+ {
178
+ case Iridiumcorp_Tpg_Model_Source_PaymentMode::PAYMENT_MODE_DIRECT_API:
179
+ $error = $this->_runTransaction($payment, $amount);
180
+ break;
181
+ case Iridiumcorp_Tpg_Model_Source_PaymentMode::PAYMENT_MODE_HOSTED_PAYMENT_FORM:
182
+ $error = $this->_runHostedPaymentTransaction($payment, $amount);
183
+ break;
184
+ case Iridiumcorp_Tpg_Model_Source_PaymentMode::PAYMENT_MODE_TRANSPARENT_REDIRECT:
185
+ $error = $this->_runTransparentRedirectTransaction($payment, $amount);
186
+ break;
187
+ default:
188
+ Mage::throwException('Invalid payment type: '.$this->getConfigData('mode'));
189
+ break;
190
+ }
191
+ }
192
  }
193
 
194
  if($error)
246
  $szEmailAddress = $billingAddress->getCustomerEmail();
247
  $szPhoneNumber = $billingAddress->getTelephone();
248
  $nDecimalAmount;
249
+ $szTransactionType;
250
 
251
  $PaymentProcessorFullDomain = $this->_getPaymentProcessorFullDomain();
252
  $iclISOCurrencyList = IRC_ISOCurrencies::getISOCurrencyList();
257
  $rgeplRequestGatewayEntryPointList->add("https://gw2.".$PaymentProcessorFullDomain, 200, 2);
258
  $rgeplRequestGatewayEntryPointList->add("https://gw3.".$PaymentProcessorFullDomain, 300, 2);
259
 
260
+ $paymentAction = $this->getConfigData('payment_action');
261
+ if($paymentAction == Mage_Paygate_Model_Authorizenet::ACTION_AUTHORIZE_CAPTURE)
262
+ {
263
+ $szTransactionType = "SALE";
264
+ }
265
+ else if($paymentAction == Mage_Paygate_Model_Authorizenet::ACTION_AUTHORIZE)
266
+ {
267
+ $szTransactionType = "PREAUTH";
268
+ }
269
+ else
270
+ {
271
+ Mage::throwException('Unknown payment action: '.$paymentAction);
272
+ }
273
+
274
  $cdtCardDetailsTransaction = new IRC_CardDetailsTransaction($rgeplRequestGatewayEntryPointList);
275
 
276
  $cdtCardDetailsTransaction->getMerchantAuthentication()->setMerchantID($MerchantID);
277
  $cdtCardDetailsTransaction->getMerchantAuthentication()->setPassword($Password);
278
 
279
+ $cdtCardDetailsTransaction->getTransactionDetails()->getMessageDetails()->setTransactionType($szTransactionType);
280
 
281
  if ($szCurrencyShort != '' &&
282
  $iclISOCurrencyList->getISOCurrency($szCurrencyShort, $icISOCurrency))
285
  $cdtCardDetailsTransaction->getTransactionDetails()->getCurrencyCode()->setValue($icISOCurrency->getISOCode());
286
  }
287
 
288
+ $nDecimalAmount = $this->_getRoundedAmount($amount, $icISOCurrency->getExponent());
289
+
 
290
  $cdtCardDetailsTransaction->getTransactionDetails()->getAmount()->setValue($nDecimalAmount);
291
 
292
  $cdtCardDetailsTransaction->getTransactionDetails()->setOrderID($szOrderID);
362
  {
363
  $szLogMessage = "Transaction could not be completed for OrderID: ".$szOrderID.". Result details: ";
364
  $szNotificationMessage = 'Payment Processor Response: '.$cdtrCardDetailsTransactionResult->getMessage();
365
+ $szCrossReference = $todTransactionOutputData->getCrossReference();
366
+
367
+ /* serve out the CrossReference as the TransactionId - this need to be done to enable the "Refund" button
368
+ in the Magento CreditMemo internal refund mechanism */
369
+ $payment->setTransactionId($szCrossReference);
370
 
371
  switch ($cdtrCardDetailsTransactionResult->getStatusCode())
372
  {
373
  case 0:
374
  // status code of 0 - means transaction successful
375
+ $szLogMessage = "Transaction successfully completed for OrderID: ".$szOrderID.". Response object: ";
376
+
377
+ // serve out the CrossReference as a TransactionId in the Magento system
378
+ $order->setCustomerNote($szNotificationMessage);
379
+ $this->setPaymentAdditionalInformation($payment, $szCrossReference);
380
+
381
+ // deactivate the current quote - fixing the cart not emptied bug
382
+ Mage::getSingleton('checkout/session')->getQuote()->setIsActive(false)->save();
383
+
384
+ // add the success message
385
  Mage::getSingleton('core/session')->addSuccess($szNotificationMessage);
386
  break;
387
  case 3:
388
  // status code of 3 - means 3D Secure authentication required
389
+ $szLogMessage = "3D Secure Authentication required for OrderID: ".$szOrderID.". Response object: ";
390
  $szNotificationMessage = '';
391
 
392
  $szPaReq = $todTransactionOutputData->getThreeDSecureOutputData()->getPaREQ();
409
  case 20:
410
  // status code of 20 - means duplicate transaction
411
  $szPreviousTransactionMessage = $cdtrCardDetailsTransactionResult->getPreviousTransactionResult()->getMessage();
412
+ $szLogMessage = "Duplicate transaction for OrderID: ".$szOrderID.". A duplicate transaction means that a transaction with these details has already been processed by the payment provider. The details of the original transaction: ".$szPreviousTransactionMessage.". Response object: ";
413
  $szNotificationMessage = $szNotificationMessage.". A duplicate transaction means that a transaction with these details has already been processed by the payment provider. The details of the original transaction - Previous Transaction Response: ".$szPreviousTransactionMessage;
414
 
415
  if ($cdtrCardDetailsTransactionResult->getPreviousTransactionResult()->getStatusCode()->getValue() != 0)
435
  }
436
  $szLogMessage = $szLogMessage." ";
437
  }
438
+ $szLogMessage = $szLogMessage.' Response object: ';
439
  break;
440
  default:
441
  // unhandled status code
459
  $payment->setIsInvoicePaid(true);
460
  }
461
  }
462
+
 
 
 
 
 
 
463
  return $error;
464
  }
465
 
536
  $nCurrencyCode = $icISOCurrency->getISOCode();
537
  }
538
 
539
+ $nAmount = $this->_getRoundedAmount($amount, $icISOCurrency->getExponent());
 
540
 
541
  $szISO2CountryCode = $billingAddress->getCountry();
542
  $szCountryShort = $this->_getISO3Code($szISO2CountryCode);
546
  }
547
 
548
  $szOrderID = $payment->getOrder()->increment_id;
 
549
  //date time with 2008-12-01 14:12:00 +01:00 format
550
  $szTransactionDateTime = date('Y-m-d H:i:s P');
551
  $szOrderDescription = '';
552
+
553
+ //$szTransactionType = "SALE";
554
+ $paymentAction = $this->getConfigData('payment_action');
555
+ if($paymentAction == Mage_Paygate_Model_Authorizenet::ACTION_AUTHORIZE_CAPTURE)
556
+ {
557
+ $szTransactionType = "SALE";
558
+ }
559
+ else if($paymentAction == Mage_Paygate_Model_Authorizenet::ACTION_AUTHORIZE)
560
+ {
561
+ $szTransactionType = "PREAUTH";
562
+ }
563
+ else
564
+ {
565
+ Mage::throwException('Unknown payment action: '.$paymentAction);
566
+ }
567
 
568
  $szCustomerName = $billingAddress->getfirstname();
569
  if($billingAddress->getfirstname())
645
  $session->setRedirectionmethod('_runRedirectedPaymentComplete');
646
  $payment->getOrder()->setIsHostedPaymentPending(true);
647
  }
648
+
649
+ /* serve out a dummy CrossReference as the TransactionId - this need to be done to enable the "Refund" button
650
+ in the Magento CreditMemo internal refund mechanism */
651
+ $payment->setTransactionId($szOrderID."_".date('YmdHis'));
652
  }
653
 
654
  /**
682
  $nCurrencyCode = $icISOCurrency->getISOCode();
683
  }
684
 
685
+ $nAmount = $this->_getRoundedAmount($amount, $icISOCurrency->getExponent());
 
686
 
687
  $szOrderID = $payment->getOrder()->increment_id;
 
688
  //date time with 2008-12-01 14:12:00 +01:00 format
689
  $szTransactionDateTime = date('Y-m-d H:i:s P');
690
  $szOrderDescription = '';
691
 
692
+ //$szTransactionType = 'SALE';
693
+ $paymentAction = $this->getConfigData('payment_action');
694
+ if($paymentAction == Mage_Paygate_Model_Authorizenet::ACTION_AUTHORIZE_CAPTURE)
695
+ {
696
+ $szTransactionType = "SALE";
697
+ }
698
+ else if($paymentAction == Mage_Paygate_Model_Authorizenet::ACTION_AUTHORIZE)
699
+ {
700
+ $szTransactionType = "PREAUTH";
701
+ }
702
+ else
703
+ {
704
+ Mage::throwException('Unknown payment action: '.$paymentAction);
705
+ }
706
+
707
  $szAddress1 = $billingAddress->getStreet1();
708
  $szAddress2 = $billingAddress->getStreet2();
709
  $szAddress3 = $billingAddress->getStreet3();
766
  Mage::getSingleton('checkout/session')->setRedirectionmethod('_runRedirectedPaymentComplete');
767
  $payment->getOrder()->setIsHostedPaymentPending(true);
768
  }
769
+
770
+ /* serve out a dummy CrossReference as the TransactionId - this need to be done to enable the "Refund" button
771
+ in the Magento CreditMemo internal refund mechanism */
772
+ $payment->setTransactionId($szOrderID."_".date('YmdHis'));
773
  }
774
 
775
  /**
819
  else
820
  {
821
  $message = "Payment Processor Response: ".$tdsarThreeDSecureAuthenticationResult->getMessage();
822
+ $szLogMessage = "3D Secure transaction could not be completed for OrderID: ".$szOrderID.". Response object: ";
823
+ $szCrossReference = $todTransactionOutputData->getCrossReference();
824
 
825
  switch ($tdsarThreeDSecureAuthenticationResult->getStatusCode())
826
  {
827
  case 0:
828
  // status code of 0 - means transaction successful
829
+ $szLogMessage = "3D Secure transaction successfully completed for OrderID: ".$szOrderID.". Response object: ";
830
+
831
+ // serve out the CrossReference as a TransactionId in the Magento system
832
+ $this->setPaymentAdditionalInformation($payment, $szCrossReference);
833
+
834
+ // need to store the new CrossReference and only store it against the payment object in the payment controller class
835
+ $session->setNewCrossReference($szCrossReference);
836
  break;
837
  case 5:
838
  // status code of 5 - means transaction declined
841
  case 20:
842
  // status code of 20 - means duplicate transaction
843
  $szPreviousTransactionMessage = $tdsarThreeDSecureAuthenticationResult->getPreviousTransactionResult()->getMessage();
844
+ $szLogMessage = "Duplicate transaction for OrderID: ".$szOrderID.". A duplicate transaction means that a transaction with these details has already been processed by the payment provider. The details of the original transaction: ".$szPreviousTransactionMessage.". Response object: ";
845
 
846
  if ($tdsarThreeDSecureAuthenticationResult->getPreviousTransactionResult()->getStatusCode()->getValue() == 0)
847
  {
891
  {
892
  $payment->setStatus(self::STATUS_APPROVED);
893
 
894
+
895
+
896
  if($nVersion == 1324 || $nVersion == 1330)
897
  {
898
  $payment->setIsInvoicePaid(true);
920
  }
921
 
922
  $message = "Payment Processor Response: ".$szMessage;
923
+
924
  switch ($szStatusCode)
925
  {
926
  case "0":
927
  Mage::log($szWording."transaction successfully completed. ".$message);
928
+
929
+ // need to store the new CrossReference and only store it against the payment object in the payment controller class
930
+ $session->setNewCrossReference($szCrossReference);
931
  break;
932
  case "20":
933
  Mage::log("Duplicate ".$szWording."transaction. ".$message);
946
  }
947
 
948
  $session->setPaymentprocessorresponse($message);
949
+
950
+ // store the CrossReference and other data
951
+ $this->setPaymentAdditionalInformation($payment, $szCrossReference);
 
 
952
 
953
  if($error == true)
954
  {
978
  {
979
  $result = false;
980
  $session = Mage::getSingleton('checkout/session');
981
+ $nVersion = $this->getVersion();
982
+ $mode = $this->getConfigData('mode');
983
 
984
  if($session->getMd() &&
985
  $session->getAcsurl() &&
986
  $session->getPareq())
987
  {
988
  // Direct (API) for 3D Secure payments
989
+ if($nVersion >= 1410)
990
+ {
991
+ // need to re-add the ordered item quantity to stock as per not completed 3DS transaction
992
+ if($mode != Iridiumcorp_Tpg_Model_Source_PaymentMode::PAYMENT_MODE_TRANSPARENT_REDIRECT)
993
+ {
994
+ $order = Mage::getModel('sales/order')->load(Mage::getSingleton('checkout/session')->getLastOrderId());
995
+ $this->addOrderedItemsToStock($order);
996
+ }
997
+ }
998
+
999
  $result = Mage::getUrl('tpg/payment/threedsecure', array('_secure' => true));
1000
  }
1001
  if($session->getHashdigest())
1002
  {
1003
  // Hosted Payment Form and Transparent Redirect payments
1004
+ if($nVersion >= 1410)
1005
+ {
1006
+ // need to re-add the ordered item quantity to stock as per not completed 3DS transaction
1007
+ if(!Mage::getSingleton('checkout/session')->getPares())
1008
+ {
1009
+ $order = Mage::getModel('sales/order')->load(Mage::getSingleton('checkout/session')->getLastOrderId());
1010
+ $this->addOrderedItemsToStock($order);
1011
+ }
1012
+ }
1013
+
1014
  $result = Mage::getUrl('tpg/payment/redirect', array('_secure' => true));
1015
  }
1016
 
1093
 
1094
  return $magentoVersion;
1095
  }
1096
+
1097
+ private function _getRoundedAmount($amount, $nExponent)
1098
+ {
1099
+ $nDecimalAmount;
1100
+
1101
+ // round the amount before use
1102
+ $amount = round($amount, $nExponent);
1103
+ $power = pow(10, $nExponent);
1104
+ $nDecimalAmount = $amount * $power;
1105
+
1106
+ return $nDecimalAmount;
1107
+ }
1108
+
1109
+ /**
1110
+ * Depreciated function - sets the additional_information column data in the sales_flat_order_payment table
1111
+ *
1112
+ * @param unknown_type $payment
1113
+ * @param unknown_type $szCrossReference
1114
+ * @param unknown_type $szTransactionType
1115
+ * @param unknown_type $szTransactionDate
1116
+ */
1117
+ public function setPaymentAdditionalInformation($payment, $szCrossReference)
1118
+ {
1119
+ $arAdditionalInformationArray = array();
1120
+
1121
+ $paymentAction = $this->getConfigData('payment_action');
1122
+ if($paymentAction == Mage_Paygate_Model_Authorizenet::ACTION_AUTHORIZE_CAPTURE)
1123
+ {
1124
+ $szTransactionType = "SALE";
1125
+ }
1126
+ else if($paymentAction == Mage_Paygate_Model_Authorizenet::ACTION_AUTHORIZE)
1127
+ {
1128
+ $szTransactionType = "PREAUTH";
1129
+ }
1130
+ else
1131
+ {
1132
+ Mage::throwException('Unknown payment action: '.$paymentAction);
1133
+ }
1134
+
1135
+ $szTransactionDate = date("Ymd");
1136
+
1137
+ $arAdditionalInformationArray["CrossReference"] = $szCrossReference;
1138
+ $arAdditionalInformationArray["TransactionType"] = $szTransactionType;
1139
+ $arAdditionalInformationArray["TransactionDateTime"] = $szTransactionDate;
1140
+
1141
+ $payment->setAdditionalInformation($arAdditionalInformationArray);
1142
+ }
1143
+
1144
+ /**
1145
+ * Deduct the order items from the stock
1146
+ *
1147
+ * @param unknown_type $order
1148
+ */
1149
+ public function subtractOrderedItemsFromStock($order)
1150
+ {
1151
+ $nVersion = Mage::getModel('tpg/direct')->getVersion();
1152
+ $isCustomStockManagementEnabled = Mage::getModel('tpg/direct')->getConfigData('customstockmanagementenabled');
1153
+
1154
+ if($nVersion >= 1410 &&
1155
+ $isCustomStockManagementEnabled)
1156
+ {
1157
+ $items = $order->getAllItems();
1158
+ foreach ($items as $itemId => $item)
1159
+ {
1160
+ // ordered quantity of the item from stock
1161
+ $quantity = $item->getQtyOrdered();
1162
+ $productId = $item->getProductId();
1163
+
1164
+ $stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($productId);
1165
+ $stockManagement = $stock->getManageStock();
1166
+
1167
+ if($stockManagement)
1168
+ {
1169
+ $stock->setQty($stock->getQty() - $quantity);
1170
+ $stock->save();
1171
+ }
1172
+ }
1173
+ }
1174
+ }
1175
+
1176
+ /**
1177
+ * Re-add the order items to the stock to balance the incorrect stock management before a payment is completed
1178
+ *
1179
+ * @param unknown_type $order
1180
+ */
1181
+ public function addOrderedItemsToStock($order)
1182
+ {
1183
+ $nVersion = Mage::getModel('tpg/direct')->getVersion();
1184
+ $isCustomStockManagementEnabled = Mage::getModel('tpg/direct')->getConfigData('customstockmanagementenabled');
1185
+
1186
+ if($nVersion >= 1410 &&
1187
+ $isCustomStockManagementEnabled)
1188
+ {
1189
+ $items = $order->getAllItems();
1190
+ foreach ($items as $itemId => $item)
1191
+ {
1192
+ // ordered quantity of the item from stock
1193
+ $quantity = $item->getQtyOrdered();
1194
+ $productId = $item->getProductId();
1195
+
1196
+ $stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($productId);
1197
+ $stockManagement = $stock->getManageStock();
1198
+
1199
+ if($stockManagement)
1200
+ {
1201
+ $stock->setQty($stock->getQty() + $quantity);
1202
+ $stock->save();
1203
+ }
1204
+ }
1205
+ }
1206
+ }
1207
+
1208
+ /**
1209
+ * Override the refund function to run a CrossReference transaction
1210
+ *
1211
+ * @param Varien_Object $payment
1212
+ * @param unknown_type $amount
1213
+ * @return unknown
1214
+ */
1215
+ public function refund(Varien_Object $payment, $amount)
1216
+ {
1217
+ $error = false;
1218
+ $szTransactionType = "REFUND";
1219
+ $orderStatus = 'irc_refunded';
1220
+ $szMessage = 'Payment refunded';
1221
+ $arAdditionalInformationArray;
1222
+
1223
+ if($amount > 0)
1224
+ {
1225
+ $error = $this->_runCrossReferenceTransaction($payment, $szTransactionType, $amount);
1226
+ }
1227
+ else
1228
+ {
1229
+ $error = 'Error in refunding the payment';
1230
+ }
1231
+
1232
+ if($error === false)
1233
+ {
1234
+ $order = $payment->getOrder();
1235
+ $payment = $order->getPayment();
1236
+ $arAdditionalInformationArray = $payment->getAdditionalInformation();
1237
+
1238
+ $arAdditionalInformationArray["Refunded"] = 1;
1239
+ $payment->setAdditionalInformation($arAdditionalInformationArray);
1240
+ $payment->save();
1241
+
1242
+ $order->setState('canceled', $orderStatus, $szMessage, false);
1243
+ $order->save();
1244
+ }
1245
+ else
1246
+ {
1247
+ Mage::throwException($error);
1248
+ }
1249
+
1250
+ return $this;
1251
+ }
1252
+
1253
+ /**
1254
+ * Iridiumcorp VOID functionality
1255
+ * Note: if a transaction (payment) is once voided (canceled) it isn't possible to redo this action
1256
+ *
1257
+ * @param Varien_Object $payment
1258
+ * @return unknown
1259
+ */
1260
+ public function ircVoid(Varien_Object $payment)
1261
+ {
1262
+ $error = false;
1263
+ $szTransactionType = "VOID";
1264
+ $orderStatus = "irc_voided";
1265
+ $arAdditionalInformationArray;
1266
+
1267
+ // attempt a VOID and accordingly to the last saved transaction id (CrossReference) set the new message
1268
+ $szLastTransId = $payment->getLastTransId();
1269
+ $transaction = $payment->getTransaction($szLastTransId);
1270
+ $szMagentoTxnType = $transaction->getTxnType();
1271
+ $szMessage = "Payment voided";
1272
+
1273
+ if($szMagentoTxnType == "capture")
1274
+ {
1275
+ $szMessage = "Payment voided";
1276
+ }
1277
+ else if($szMagentoTxnType == "authorization")
1278
+ {
1279
+ $szMessage = "PreAuthorization voided";
1280
+ }
1281
+ else if($szMagentoTxnType == "refund")
1282
+ {
1283
+ $szMessage = "Refund voided";
1284
+ }
1285
+ else
1286
+ {
1287
+ // general message
1288
+ $szMessage = "Payment voided";
1289
+ }
1290
+
1291
+ $error = $this->_runCrossReferenceTransaction($payment, $szTransactionType);
1292
+
1293
+ if ($error === false)
1294
+ {
1295
+ $order = $payment->getOrder();
1296
+ $invoices = $order->getInvoiceCollection();
1297
+ $payment = $order->getPayment();
1298
+ $arAdditionalInformationArray = $payment->getAdditionalInformation();
1299
+
1300
+ $arAdditionalInformationArray["Voided"] = 1;
1301
+ $payment->setAdditionalInformation($arAdditionalInformationArray);
1302
+ $payment->save();
1303
+
1304
+ // cancel the invoices
1305
+ foreach ($invoices as $invoice)
1306
+ {
1307
+ $invoice->cancel();
1308
+ $invoice->save();
1309
+ }
1310
+
1311
+ // udpate the order
1312
+ $order->setActionBy($payment->getLggdInAdminUname())
1313
+ ->setActionDate(date('Y-m-d H:i:s'))
1314
+ ->setVoided(1)
1315
+ ->setState('canceled', $orderStatus, $szMessage, false);
1316
+ $order->save();
1317
+
1318
+ $result = "0";
1319
+ }
1320
+ else
1321
+ {
1322
+ $result = $error;
1323
+ }
1324
+
1325
+ return $result;
1326
+ }
1327
+
1328
+ /**
1329
+ * Iridiumcorp COLLECTION functionality (capture called in Magento)
1330
+ *
1331
+ * @param Varien_Object $payment
1332
+ * @param unknown_type $szOrderID
1333
+ * @param unknown_type $szCrossReference
1334
+ * @return unknown
1335
+ */
1336
+ public function ircCollection(Varien_Object $payment, $szOrderID, $szCrossReference)
1337
+ {
1338
+ $szTransactionType = "COLLECTION";
1339
+ $orderStatus = 'irc_collected';
1340
+ $szMessage = 'Preauthorization successfully collected';
1341
+ $state = Mage_Sales_Model_Order::STATE_PROCESSING;
1342
+ $arAdditionalInformationArray;
1343
+
1344
+ $error = $this->_captureAuthorizedPayment($payment);
1345
+
1346
+ if($error === false)
1347
+ {
1348
+ $order = $payment->getOrder();
1349
+ $invoices = $order->getInvoiceCollection();
1350
+ $payment = $order->getPayment();
1351
+ $arAdditionalInformationArray = $payment->getAdditionalInformation();
1352
+
1353
+ $arAdditionalInformationArray["Collected"] = 1;
1354
+ $payment->setAdditionalInformation($arAdditionalInformationArray);
1355
+ $payment->save();
1356
+
1357
+ // update the invoices to paid status
1358
+ foreach ($invoices as $invoice)
1359
+ {
1360
+ $invoice->pay()->save();
1361
+ }
1362
+
1363
+ $order->setActionBy($payment->getLggdInAdminUname())
1364
+ ->setActionDate(date('Y-m-d H:i:s'))
1365
+ ->setState($state, $orderStatus, $szMessage, false);
1366
+ $order->save();
1367
+
1368
+ $result = "0";
1369
+ }
1370
+ else
1371
+ {
1372
+ $result = $error;
1373
+ }
1374
+
1375
+ return $result;
1376
+ }
1377
+
1378
+ /**
1379
+ * Private capture function for an authorized payment
1380
+ *
1381
+ * @param Varien_Object $payment
1382
+ * @return unknown
1383
+ */
1384
+ private function _captureAuthorizedPayment(Varien_Object $payment)
1385
+ {
1386
+ $error = false;
1387
+ $session = Mage::getSingleton('checkout/session');
1388
+
1389
+ try
1390
+ {
1391
+ // set the COLLECTION variable to true
1392
+ $session->setIsCollectionCrossReferenceTransaction(true);
1393
+
1394
+ $invoice = $payment->getOrder()->prepareInvoice();
1395
+ $invoice->register();
1396
+
1397
+ if ($this->_canCapture)
1398
+ {
1399
+ $invoice->capture();
1400
+ }
1401
+
1402
+ $payment->getOrder()->addRelatedObject($invoice);
1403
+ $payment->setCreatedInvoice($invoice);
1404
+ }
1405
+ catch(Exception $exc)
1406
+ {
1407
+ $error = "Couldn't capture pre-authorized payment. Message: ".$exc->getMessage();
1408
+ Mage::log($exc->getMessage());
1409
+ }
1410
+
1411
+ // remove the COLLECTION session variable once finished the COLLECTION attempt
1412
+ $session->setIsCollectionCrossReferenceTransaction(null);
1413
+
1414
+ return $error;
1415
+ }
1416
+
1417
+ /**
1418
+ * Internal CrossReference function for all VOID, REFUND, COLLECTION transaction types
1419
+ *
1420
+ * @param Varien_Object $payment
1421
+ * @param unknown_type $szTransactionType
1422
+ * @param unknown_type $amount
1423
+ * @return unknown
1424
+ */
1425
+ private function _runCrossReferenceTransaction(Varien_Object $payment, $szTransactionType, $amount = false)
1426
+ {
1427
+ $error = false;
1428
+ $boTransactionProcessed = false;
1429
+ $PaymentProcessorFullDomain;
1430
+ $rgeplRequestGatewayEntryPointList;
1431
+ $crtCrossReferenceTransaction;
1432
+ $crtrCrossReferenceTransactionResult;
1433
+ $todTransactionOutputData;
1434
+ $szMerchantID = $this->getConfigData('merchantid');
1435
+ $szPassword = $this->getConfigData('password');
1436
+ //
1437
+ $iclISOCurrencyList = IRC_ISOCurrencies::getISOCurrencyList();
1438
+ $szAmount;
1439
+ $nAmount;
1440
+ $szCurrencyShort;
1441
+ $iclISOCurrencyList;
1442
+ $power;
1443
+ $nDecimalAmount;
1444
+ $szNewCrossReference;
1445
+
1446
+ $order = $payment->getOrder();
1447
+ $szOrderID = $order->getRealOrderId();;
1448
+ //$szCrossReference = $payment->getLastTransId();
1449
+ $additionalInformation = $payment->getAdditionalInformation();
1450
+
1451
+ $szCrossReference = $additionalInformation["CrossReference"];
1452
+ $szCrossReference = $payment->getLastTransId();
1453
+
1454
+ // check the CrossRference and TransactionType parameters
1455
+ if(!$szCrossReference)
1456
+ {
1457
+ $error = 'Error occurred for '.$szTransactionType.': Missing Cross Reference';
1458
+ }
1459
+ if(!$szTransactionType)
1460
+ {
1461
+ $error = 'Error occurred for '.$szTransactionType.': Missing Transaction Type';
1462
+ }
1463
+
1464
+ if($error === false)
1465
+ {
1466
+ $PaymentProcessorFullDomain = $this->_getPaymentProcessorFullDomain();
1467
+
1468
+ $rgeplRequestGatewayEntryPointList = new IRC_RequestGatewayEntryPointList();
1469
+ $rgeplRequestGatewayEntryPointList->add("https://gw1.".$PaymentProcessorFullDomain, 100, 2);
1470
+ $rgeplRequestGatewayEntryPointList->add("https://gw2.".$PaymentProcessorFullDomain, 200, 2);
1471
+ $rgeplRequestGatewayEntryPointList->add("https://gw3.".$PaymentProcessorFullDomain, 300, 2);
1472
+
1473
+ $crtCrossReferenceTransaction = new IRC_CrossReferenceTransaction($rgeplRequestGatewayEntryPointList);
1474
+ $crtCrossReferenceTransaction->getMerchantAuthentication()->setMerchantID($szMerchantID);
1475
+ $crtCrossReferenceTransaction->getMerchantAuthentication()->setPassword($szPassword);
1476
+
1477
+ // if no amount is specified get the grand total amount
1478
+ if($amount === false)
1479
+ {
1480
+ $nAmount = $order->getBaseGrandTotal();
1481
+ }
1482
+ else
1483
+ {
1484
+ $nAmount = $amount;
1485
+ }
1486
+
1487
+ $szCurrencyShort = $order->getOrderCurrency()->getCurrencyCode();
1488
+ if ($szCurrencyShort != '' &&
1489
+ $iclISOCurrencyList->getISOCurrency($szCurrencyShort, $icISOCurrency))
1490
+ {
1491
+ $nCurrencyCode = new IRC_NullableInt($icISOCurrency->getISOCode());
1492
+ $crtCrossReferenceTransaction->getTransactionDetails()->getCurrencyCode()->setValue($icISOCurrency->getISOCode());
1493
+ }
1494
+
1495
+ // round the amount before use
1496
+ $nAmount = round($nAmount, $icISOCurrency->getExponent());
1497
+ $power = pow(10, $icISOCurrency->getExponent());
1498
+ $nDecimalAmount = $nAmount * $power;
1499
+
1500
+ $crtCrossReferenceTransaction->getTransactionDetails()->setOrderID($szOrderID);
1501
+ $crtCrossReferenceTransaction->getTransactionDetails()->getAmount()->setValue($nDecimalAmount);
1502
+
1503
+ $crtCrossReferenceTransaction->getTransactionDetails()->getMessageDetails()->setCrossReference($szCrossReference);
1504
+ $crtCrossReferenceTransaction->getTransactionDetails()->getMessageDetails()->setTransactionType($szTransactionType);
1505
+
1506
+ try
1507
+ {
1508
+ $boTransactionProcessed = $crtCrossReferenceTransaction->processTransaction($crtrCrossReferenceTransactionResult, $todTransactionOutputData);
1509
+ }
1510
+ catch (Exception $exc)
1511
+ {
1512
+ Mage::log("exception: ".$exc->getMessage());
1513
+ }
1514
+
1515
+ if ($boTransactionProcessed == false)
1516
+ {
1517
+ // could not communicate with the payment gateway
1518
+ $error = "Couldn't complete ".$szTransactionType." transaction. Details: ".$crtCrossReferenceTransaction->getLastException();
1519
+ $szLogMessage = $error;
1520
+ }
1521
+ else
1522
+ {
1523
+ switch($crtrCrossReferenceTransactionResult->getStatusCode())
1524
+ {
1525
+ case 0:
1526
+ $error = false;
1527
+ $szNewCrossReference = $todTransactionOutputData->getCrossReference();
1528
+ $szLogMessage = $szTransactionType . " CrossReference transaction successfully completed. Response object: ";
1529
+
1530
+ $payment->setTransactionId($szNewCrossReference)
1531
+ ->setParentTransactionId($szCrossReference)
1532
+ ->setIsTransactionClosed(1);
1533
+ $payment->save();
1534
+ break;
1535
+ default:
1536
+ $szLogMessage = $crtrCrossReferenceTransactionResult->getMessage();
1537
+ if ($crtrCrossReferenceTransactionResult->getErrorMessages()->getCount() > 0)
1538
+ {
1539
+ $szLogMessage = $szLogMessage.".";
1540
+
1541
+ for ($LoopIndex = 0; $LoopIndex < $crtrCrossReferenceTransactionResult->getErrorMessages()->getCount(); $LoopIndex++)
1542
+ {
1543
+ $szLogMessage = $szLogMessage.$crtrCrossReferenceTransactionResult->getErrorMessages()->getAt($LoopIndex).";";
1544
+ }
1545
+ $szLogMessage = $szLogMessage." ";
1546
+ }
1547
+
1548
+ $error = "Couldn't complete ".$szTransactionType." transaction for CrossReference: " . $szCrossReference . ". Payment Response: ".$szLogMessage;
1549
+ $szLogMessage = $szTransactionType . " CrossReference transaction failed. Response object: ";
1550
+ break;
1551
+ }
1552
+
1553
+ $szLogMessage = $szLogMessage.print_r($crtrCrossReferenceTransactionResult, 1);
1554
+ }
1555
+
1556
+ Mage::log($szLogMessage);
1557
+ }
1558
+
1559
+ return $error;
1560
+ }
1561
  }
app/code/local/Iridiumcorp/Tpg/Model/Source/PaymentAction.php CHANGED
@@ -4,12 +4,19 @@ class Iridiumcorp_Tpg_Model_Source_PaymentAction extends Mage_Paygate_Model_Auth
4
  {
5
  public function toOptionArray()
6
  {
7
- return array(
8
- // override the core class to ONLy allow capture transactions (immediate settlement)
9
- array(
10
- 'value' => Mage_Paygate_Model_Authorizenet::ACTION_AUTHORIZE_CAPTURE,
11
- 'label' => Mage::helper('paygate')->__('Authorize and Capture')
 
 
12
  ),
 
 
 
 
 
13
  );
14
  }
15
  }
4
  {
5
  public function toOptionArray()
6
  {
7
+ return array
8
+ (
9
+ // override the core class to ONLY allow capture transactions (immediate settlement)
10
+ array
11
+ (
12
+ 'value' => Mage_Paygate_Model_Authorizenet::ACTION_AUTHORIZE,
13
+ 'label' => Mage::helper('paygate')->__('PREAUTH')
14
  ),
15
+ array
16
+ (
17
+ 'value' => Mage_Paygate_Model_Authorizenet::ACTION_AUTHORIZE_CAPTURE,
18
+ 'label' => Mage::helper('paygate')->__('SALE')
19
+ )
20
  );
21
  }
22
  }
app/code/local/Iridiumcorp/Tpg/controllers/PaymentController.php CHANGED
@@ -26,7 +26,7 @@ class Iridiumcorp_Tpg_PaymentController extends Mage_Core_Controller_Front_Actio
26
  }
27
 
28
  /**
29
- * When a customer cancel payment from paypal.
30
  */
31
  public function cancelAction()
32
  {
@@ -42,17 +42,6 @@ class Iridiumcorp_Tpg_PaymentController extends Mage_Core_Controller_Front_Actio
42
  */
43
  public function redirectAction()
44
  {
45
- $nVersion = Mage::getModel('tpg/direct')->getVersion();
46
-
47
- if($nVersion >= 1410)
48
- {
49
- // need to re-add the ordered item quantity to stock as per not completed 3DS transaction
50
- if(!Mage::getSingleton('checkout/session')->getPares())
51
- {
52
- $order = Mage::getModel('sales/order')->load(Mage::getSingleton('checkout/session')->getLastOrderId());
53
- $this->_addOrderedItemsToStock($order);
54
- }
55
- }
56
  $this->getResponse()->setBody($this->getLayout()->createBlock('tpg/redirect')->toHtml());
57
  }
58
 
@@ -62,20 +51,6 @@ class Iridiumcorp_Tpg_PaymentController extends Mage_Core_Controller_Front_Actio
62
  */
63
  public function threedsecureAction()
64
  {
65
- $nVersion = Mage::getModel('tpg/direct')->getVersion();
66
-
67
- if($nVersion >= 1410)
68
- {
69
- $mode = Mage::getModel('tpg/direct')->getConfigData('mode');
70
-
71
- // need to re-add the ordered item quantity to stock as per not completed 3DS transaction
72
- if($mode != Iridiumcorp_Tpg_Model_Source_PaymentMode::PAYMENT_MODE_TRANSPARENT_REDIRECT)
73
- {
74
- $order = Mage::getModel('sales/order')->load(Mage::getSingleton('checkout/session')->getLastOrderId());
75
- $this->_addOrderedItemsToStock($order);
76
- }
77
- }
78
-
79
  $this->getResponse()->setBody($this->getLayout()->createBlock('tpg/threedsecure')->toHtml());
80
  }
81
 
@@ -105,8 +80,8 @@ class Iridiumcorp_Tpg_PaymentController extends Mage_Core_Controller_Front_Actio
105
  $iridiumcorpOrderId = Mage::getSingleton('checkout/session')->getTpgOrderId();
106
  $szOrderStatus = $order->getStatus();
107
 
108
- if($szOrderStatus != 'irc_paid')
109
- //if($iridiumcorpOrderId)
110
  {
111
  // cart is not empty
112
  // complete the 3D Secure transaction with the 3D Authorization result
@@ -185,7 +160,11 @@ class Iridiumcorp_Tpg_PaymentController extends Mage_Core_Controller_Front_Actio
185
 
186
  if($nVersion >= 1410)
187
  {
188
- $this->_subtractOrderedItemsFromStock($order);
 
 
 
 
189
  $this->_updateInvoices($order, $szPaymentProcessorResponse);
190
  }
191
 
@@ -265,8 +244,8 @@ class Iridiumcorp_Tpg_PaymentController extends Mage_Core_Controller_Front_Actio
265
  $szPreviousMessage = $this->getRequest()->getPost('PreviousMessage');
266
  $szOrderID = $this->getRequest()->getPost('OrderID');
267
 
268
- if($szOrderStatus != 'irc_paid')
269
- //if($iridiumcorpOrderId)
270
  {
271
  $checkout->saveOrderAfterRedirectedPaymentAction(true,
272
  $this->getRequest()->getPost('StatusCode'),
@@ -304,7 +283,8 @@ class Iridiumcorp_Tpg_PaymentController extends Mage_Core_Controller_Front_Actio
304
  $szNotificationMessage = $szNotificationMessage.'<br/>'.$szPaymentProcessorResponse;
305
  }
306
 
307
- $order->getPayment()->setAdditionalData("CrossReference=".$this->getRequest()->getPost('CrossReference'));
 
308
 
309
  if($nVersion >= 1410)
310
  {
@@ -345,7 +325,11 @@ class Iridiumcorp_Tpg_PaymentController extends Mage_Core_Controller_Front_Actio
345
 
346
  if($nVersion >= 1410)
347
  {
348
- $this->_subtractOrderedItemsFromStock($order);
 
 
 
 
349
  $this->_updateInvoices($order, $szPaymentProcessorResponse);
350
  }
351
 
@@ -419,7 +403,10 @@ class Iridiumcorp_Tpg_PaymentController extends Mage_Core_Controller_Front_Actio
419
 
420
  if($nVersion >= 1410)
421
  {
422
- $this->_subtractOrderedItemsFromStock($order);
 
 
 
423
  $this->_updateInvoices($order, $szMessage);
424
  }
425
  }
@@ -547,7 +534,8 @@ class Iridiumcorp_Tpg_PaymentController extends Mage_Core_Controller_Front_Actio
547
 
548
  if($szErrorMessage)
549
  {
550
- $order->getPayment()->setAdditionalData("CrossReference=".$szCrossReference);
 
551
 
552
  if($nVersion >= 1410)
553
  {
@@ -586,7 +574,10 @@ class Iridiumcorp_Tpg_PaymentController extends Mage_Core_Controller_Front_Actio
586
 
587
  if($nVersion >= 1410)
588
  {
589
- $this->_subtractOrderedItemsFromStock($order);
 
 
 
590
  $this->_updateInvoices($order, $szMessage);
591
  }
592
 
@@ -780,8 +771,8 @@ class Iridiumcorp_Tpg_PaymentController extends Mage_Core_Controller_Front_Actio
780
  $iridiumcorpOrderId = Mage::getSingleton('checkout/session')->getTpgOrderId();
781
  $szOrderStatus = $order->getStatus();
782
 
783
- if($szOrderStatus != 'irc_paid')
784
- //if($iridiumcorpOrderId)
785
  {
786
  $checkout->saveOrderAfterRedirectedPaymentAction(false,
787
  $this->getRequest()->getPost('StatusCode'),
@@ -823,8 +814,9 @@ class Iridiumcorp_Tpg_PaymentController extends Mage_Core_Controller_Front_Actio
823
  {
824
  $szNotificationMessage = $szNotificationMessage.'<br/>'.$szPaymentProcessorResponse;
825
  }
826
-
827
- $order->getPayment()->setAdditionalData("CrossReference=".$this->getRequest()->getPost('CrossReference'));
 
828
 
829
  if($nVersion >= 1410)
830
  {
@@ -866,7 +858,11 @@ class Iridiumcorp_Tpg_PaymentController extends Mage_Core_Controller_Front_Actio
866
 
867
  if($nVersion >= 1410)
868
  {
869
- $this->_subtractOrderedItemsFromStock($order);
 
 
 
 
870
  $this->_updateInvoices($order, $szPaymentProcessorResponse);
871
  }
872
 
@@ -883,71 +879,6 @@ class Iridiumcorp_Tpg_PaymentController extends Mage_Core_Controller_Front_Actio
883
  }
884
  }
885
 
886
- /**
887
- * Deduct the order items from the stock
888
- *
889
- * @param unknown_type $order
890
- */
891
- private function _subtractOrderedItemsFromStock($order)
892
- {
893
- $nVersion = Mage::getModel('tpg/direct')->getVersion();
894
- $isCustomStockManagementEnabled = Mage::getModel('tpg/direct')->getConfigData('customstockmanagementenabled');
895
-
896
- if($nVersion >= 1410 &&
897
- $isCustomStockManagementEnabled)
898
- {
899
- $items = $order->getAllItems();
900
- foreach ($items as $itemId => $item)
901
- {
902
- // ordered quantity of the item from stock
903
- $quantity = $item->getQtyOrdered();
904
- $productId = $item->getProductId();
905
-
906
- $stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($productId);
907
- $stockManagement = $stock->getManageStock();
908
-
909
- if($stockManagement)
910
- {
911
- $stock->setQty($stock->getQty() - $quantity);
912
- $stock->save();
913
- }
914
- }
915
- }
916
- }
917
-
918
- /**
919
- * Re-add the order items to the stock to balance the incorrect stock management before a payment is completed
920
- *
921
- * @param unknown_type $order
922
- */
923
- private function _addOrderedItemsToStock($order)
924
- {
925
- $nVersion = Mage::getModel('tpg/direct')->getVersion();
926
- $isCustomStockManagementEnabled = Mage::getModel('tpg/direct')->getConfigData('customstockmanagementenabled');
927
-
928
- if($nVersion >= 1410 &&
929
- $isCustomStockManagementEnabled)
930
- {
931
- $items = $order->getAllItems();
932
- foreach ($items as $itemId => $item)
933
- {
934
- // ordered quantity of the item from stock
935
- $quantity = $item->getQtyOrdered();
936
- $productId = $item->getProductId();
937
-
938
- $stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($productId);
939
- $stockManagement = $stock->getManageStock();
940
-
941
- if($stockManagement)
942
- {
943
- $stock->setQty($stock->getQty() + $quantity);
944
- $stock->save();
945
- }
946
- }
947
- }
948
- }
949
-
950
-
951
  private function _clearSessionVariables()
952
  {
953
  // clear all the custom session variables used in the payment module in case of a failed payment
@@ -981,7 +912,25 @@ class Iridiumcorp_Tpg_PaymentController extends Mage_Core_Controller_Front_Actio
981
  private function _updateInvoices($order, $message)
982
  {
983
  $invoices = $order->getInvoiceCollection();
984
- $status = Mage_Sales_Model_Order::STATE_PROCESSING;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
985
 
986
  foreach ($invoices as $invoice)
987
  {
@@ -989,8 +938,18 @@ class Iridiumcorp_Tpg_PaymentController extends Mage_Core_Controller_Front_Actio
989
  $invoice->pay()->save();
990
  }
991
  // add a comment to the order comments
992
- //$order->addStatusToHistory($status, $message, false);
993
- $order->setState($status, 'irc_paid', $message, false);
 
 
 
 
 
 
 
 
 
 
994
  $order->save();
995
  }
996
 
@@ -1026,4 +985,48 @@ class Iridiumcorp_Tpg_PaymentController extends Mage_Core_Controller_Front_Actio
1026
  }
1027
  }
1028
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1029
  }
26
  }
27
 
28
  /**
29
+ * When a customer cancel payment.
30
  */
31
  public function cancelAction()
32
  {
42
  */
43
  public function redirectAction()
44
  {
 
 
 
 
 
 
 
 
 
 
 
45
  $this->getResponse()->setBody($this->getLayout()->createBlock('tpg/redirect')->toHtml());
46
  }
47
 
51
  */
52
  public function threedsecureAction()
53
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
  $this->getResponse()->setBody($this->getLayout()->createBlock('tpg/threedsecure')->toHtml());
55
  }
56
 
80
  $iridiumcorpOrderId = Mage::getSingleton('checkout/session')->getTpgOrderId();
81
  $szOrderStatus = $order->getStatus();
82
 
83
+ if($szOrderStatus != 'irc_paid' &&
84
+ $szOrderStatus != 'irc_preauth')
85
  {
86
  // cart is not empty
87
  // complete the 3D Secure transaction with the 3D Authorization result
160
 
161
  if($nVersion >= 1410)
162
  {
163
+ // TODO : no need to remove stock item as the system will do it in 1.6 version
164
+ if($nVersion < 1600)
165
+ {
166
+ Mage::getModel('tpg/direct')->subtractOrderedItemsFromStock($order);
167
+ }
168
  $this->_updateInvoices($order, $szPaymentProcessorResponse);
169
  }
170
 
244
  $szPreviousMessage = $this->getRequest()->getPost('PreviousMessage');
245
  $szOrderID = $this->getRequest()->getPost('OrderID');
246
 
247
+ if($szOrderStatus != 'irc_paid' &&
248
+ $szOrderStatus != 'irc_preauth')
249
  {
250
  $checkout->saveOrderAfterRedirectedPaymentAction(true,
251
  $this->getRequest()->getPost('StatusCode'),
283
  $szNotificationMessage = $szNotificationMessage.'<br/>'.$szPaymentProcessorResponse;
284
  }
285
 
286
+ $model->setPaymentAdditionalInformation($order->getPayment(), $this->getRequest()->getPost('CrossReference'));
287
+ //$order->getPayment()->setTransactionId($this->getRequest()->getPost('CrossReference'));
288
 
289
  if($nVersion >= 1410)
290
  {
325
 
326
  if($nVersion >= 1410)
327
  {
328
+ // TODO : no need to remove stock item as the system will do it in 1.6 version
329
+ if($nVersion < 1600)
330
+ {
331
+ $model->subtractOrderedItemsFromStock($order);
332
+ }
333
  $this->_updateInvoices($order, $szPaymentProcessorResponse);
334
  }
335
 
403
 
404
  if($nVersion >= 1410)
405
  {
406
+ if($nVersion < 1600)
407
+ {
408
+ $model->subtractOrderedItemsFromStock($order);
409
+ }
410
  $this->_updateInvoices($order, $szMessage);
411
  }
412
  }
534
 
535
  if($szErrorMessage)
536
  {
537
+ $model->setPaymentAdditionalInformation($order->getPayment(), $szCrossReference);
538
+ //$order->getPayment()->setTransactionId($szCrossReference);
539
 
540
  if($nVersion >= 1410)
541
  {
574
 
575
  if($nVersion >= 1410)
576
  {
577
+ if($nVersion < 1600)
578
+ {
579
+ $model->subtractOrderedItemsFromStock($order);
580
+ }
581
  $this->_updateInvoices($order, $szMessage);
582
  }
583
 
771
  $iridiumcorpOrderId = Mage::getSingleton('checkout/session')->getTpgOrderId();
772
  $szOrderStatus = $order->getStatus();
773
 
774
+ if($szOrderStatus != 'irc_paid' &&
775
+ $szOrderStatus != 'irc_preauth')
776
  {
777
  $checkout->saveOrderAfterRedirectedPaymentAction(false,
778
  $this->getRequest()->getPost('StatusCode'),
814
  {
815
  $szNotificationMessage = $szNotificationMessage.'<br/>'.$szPaymentProcessorResponse;
816
  }
817
+
818
+ $model->setPaymentAdditionalInformation($order->getPayment(), $this->getRequest()->getPost('CrossReference'));
819
+ //$order->getPayment()->setTransactionId($this->getRequest()->getPost('CrossReference'));
820
 
821
  if($nVersion >= 1410)
822
  {
858
 
859
  if($nVersion >= 1410)
860
  {
861
+ // TODO : no need to remove stock item as the system will do it in 1.6 version
862
+ if($nVersion < 1600)
863
+ {
864
+ $model->subtractOrderedItemsFromStock($order);
865
+ }
866
  $this->_updateInvoices($order, $szPaymentProcessorResponse);
867
  }
868
 
879
  }
880
  }
881
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
882
  private function _clearSessionVariables()
883
  {
884
  // clear all the custom session variables used in the payment module in case of a failed payment
912
  private function _updateInvoices($order, $message)
913
  {
914
  $invoices = $order->getInvoiceCollection();
915
+ $state = Mage_Sales_Model_Order::STATE_PROCESSING;
916
+ $payment = $order->getPayment();
917
+ $transaction;
918
+ $session = Mage::getSingleton('checkout/session');
919
+ $szNewCrossReference;
920
+
921
+ $transactionId = $payment->getLastTransId();
922
+ $transaction = $payment->getTransaction($transactionId);
923
+ $transactionType = $transaction->getTxnType();
924
+
925
+ if($session->getNewCrossReference())
926
+ {
927
+ $szNewCrossReference = $session->getNewCrossReference();
928
+ $value = $transaction->setTxnId($szNewCrossReference);
929
+ $transaction->save();
930
+ $payment->setLastTransId($szNewCrossReference);
931
+
932
+ $session->setNewCrossReference(null);
933
+ }
934
 
935
  foreach ($invoices as $invoice)
936
  {
938
  $invoice->pay()->save();
939
  }
940
  // add a comment to the order comments
941
+ if($transactionType == 'authorization')
942
+ {
943
+ $order->setState($state, 'irc_preauth', $message, true);
944
+ }
945
+ else if($transactionType == 'capture')
946
+ {
947
+ $order->setState($state, 'irc_paid', $message, true);
948
+ }
949
+ else
950
+ {
951
+ Mage::throwException('invalid transaction type [' . $transactionType . '] for invoice updating');
952
+ }
953
  $order->save();
954
  }
955
 
985
  }
986
  }
987
  }
988
+
989
+ /**
990
+ * Refund actioned when the user clicks the VOID button in the admin backend
991
+ *
992
+ * @return unknown
993
+ */
994
+ public function voidAction()
995
+ {
996
+ $model = Mage::getSingleton('tpg/direct');
997
+ $parameters = $this->getRequest()->getParams();
998
+ $szOrderID = $parameters['OrderID'];
999
+ $szCrossReference = $parameters['CrossReference'];
1000
+
1001
+ $order = Mage::getModel('sales/order')->loadByIncrementId((int)$szOrderID);
1002
+ $payment = $order->getPayment();
1003
+
1004
+ $result = Mage::getModel('tpg/direct')->ircVoid($payment);
1005
+
1006
+ if($result == "0")
1007
+ {
1008
+ $model->addOrderedItemsToStock($order);
1009
+ }
1010
+
1011
+ return $this->getResponse()->setBody($result);
1012
+ }
1013
+
1014
+ /**
1015
+ * Refund actioned when the user clicks the COLLECT button in the admin backend
1016
+ *
1017
+ * @return unknown
1018
+ */
1019
+ public function collectionAction()
1020
+ {
1021
+ $parameters = $this->getRequest()->getParams();
1022
+ $szOrderID = $parameters['OrderID'];
1023
+ $szCrossReference = $parameters['CrossReference'];
1024
+
1025
+ $order = Mage::getModel('sales/order')->loadByIncrementId((int)$szOrderID);
1026
+ $payment = $order->getPayment();
1027
+
1028
+ $result = Mage::getModel('tpg/direct')->ircCollection($payment, $szOrderID, $szCrossReference);
1029
+
1030
+ return $this->getResponse()->setBody($result);
1031
+ }
1032
  }
app/code/local/Iridiumcorp/Tpg/etc/config.xml CHANGED
@@ -37,6 +37,16 @@
37
  <tpg>
38
  <class>Iridiumcorp_Tpg_Block</class>
39
  </tpg>
 
 
 
 
 
 
 
 
 
 
40
  </blocks>
41
  <!-- Define the helper class type -->
42
  <helpers>
@@ -51,6 +61,15 @@
51
  </helpers>
52
  </global>
53
 
 
 
 
 
 
 
 
 
 
54
  <frontend>
55
  <secure_url>
56
  <tpg>/tpg/standard</tpg>
37
  <tpg>
38
  <class>Iridiumcorp_Tpg_Block</class>
39
  </tpg>
40
+ <payment>
41
+ <rewrite>
42
+ <info_cc>Iridiumcorp_Tpg_Block_Payment_Info_Cc</info_cc>
43
+ </rewrite>
44
+ </payment>
45
+ <adminhtml>
46
+ <rewrite>
47
+ <sales_order_payment>Iridiumcorp_Tpg_Block_Adminhtml_Sales_Order_Payment</sales_order_payment>
48
+ </rewrite>
49
+ </adminhtml>
50
  </blocks>
51
  <!-- Define the helper class type -->
52
  <helpers>
61
  </helpers>
62
  </global>
63
 
64
+ <adminhtml>
65
+ <layout>
66
+ <updates>
67
+ <tpg>
68
+ <file>tpg.xml</file>
69
+ </tpg>
70
+ </updates>
71
+ </layout>
72
+ </adminhtml>
73
  <frontend>
74
  <secure_url>
75
  <tpg>/tpg/standard</tpg>
app/code/local/Iridiumcorp/Tpg/sql/tpg_setup/mysql4-install-0.1.0.php CHANGED
@@ -16,6 +16,10 @@ try
16
  DELETE FROM `{$installer->getTable('sales_order_status')}` WHERE (`status`='irc_pending');
17
  DELETE FROM `{$installer->getTable('sales_order_status')}` WHERE (`status`='irc_pending_hosted_payment');
18
  DELETE FROM `{$installer->getTable('sales_order_status')}` WHERE (`status`='irc_pending_threed_secure');
 
 
 
 
19
 
20
  INSERT INTO `{$installer->getTable('sales_order_status')}` (`status`, `label`) VALUES ('irc_failed_hosted_payment', 'Iridiumcorp - Failed Payment');
21
  INSERT INTO `{$installer->getTable('sales_order_status')}` (`status`, `label`) VALUES ('irc_failed_threed_secure', 'Iridiumcorp - Failed 3D Secure');
@@ -23,6 +27,10 @@ try
23
  INSERT INTO `{$installer->getTable('sales_order_status')}` (`status`, `label`) VALUES ('irc_pending', 'Iridiumcorp - Pending Hosted Payment');
24
  INSERT INTO `{$installer->getTable('sales_order_status')}` (`status`, `label`) VALUES ('irc_pending_hosted_payment', 'Iridiumcorp - Pending Hosted Payment');
25
  INSERT INTO `{$installer->getTable('sales_order_status')}` (`status`, `label`) VALUES ('irc_pending_threed_secure', 'Iridiumcorp - Pending 3D Secure');
 
 
 
 
26
  ");
27
  }
28
  catch(Exception $exc)
@@ -30,6 +38,6 @@ catch(Exception $exc)
30
  Mage::log("Error during script installation: ". $exc->__toString());
31
  }
32
 
33
- Mage::log('iridiumcorp installer script started');
34
 
35
  $installer->endSetup();
16
  DELETE FROM `{$installer->getTable('sales_order_status')}` WHERE (`status`='irc_pending');
17
  DELETE FROM `{$installer->getTable('sales_order_status')}` WHERE (`status`='irc_pending_hosted_payment');
18
  DELETE FROM `{$installer->getTable('sales_order_status')}` WHERE (`status`='irc_pending_threed_secure');
19
+ DELETE FROM `{$installer->getTable('sales_order_status')}` WHERE (`status`='irc_refunded');
20
+ DELETE FROM `{$installer->getTable('sales_order_status')}` WHERE (`status`='irc_voided');
21
+ DELETE FROM `{$installer->getTable('sales_order_status')}` WHERE (`status`='irc_preauth');
22
+ DELETE FROM `{$installer->getTable('sales_order_status')}` WHERE (`status`='irc_collected');
23
 
24
  INSERT INTO `{$installer->getTable('sales_order_status')}` (`status`, `label`) VALUES ('irc_failed_hosted_payment', 'Iridiumcorp - Failed Payment');
25
  INSERT INTO `{$installer->getTable('sales_order_status')}` (`status`, `label`) VALUES ('irc_failed_threed_secure', 'Iridiumcorp - Failed 3D Secure');
27
  INSERT INTO `{$installer->getTable('sales_order_status')}` (`status`, `label`) VALUES ('irc_pending', 'Iridiumcorp - Pending Hosted Payment');
28
  INSERT INTO `{$installer->getTable('sales_order_status')}` (`status`, `label`) VALUES ('irc_pending_hosted_payment', 'Iridiumcorp - Pending Hosted Payment');
29
  INSERT INTO `{$installer->getTable('sales_order_status')}` (`status`, `label`) VALUES ('irc_pending_threed_secure', 'Iridiumcorp - Pending 3D Secure');
30
+ INSERT INTO `{$installer->getTable('sales_order_status')}` (`status`, `label`) VALUES ('irc_refunded', 'Iridiumcorp - Payment Refunded');
31
+ INSERT INTO `{$installer->getTable('sales_order_status')}` (`status`, `label`) VALUES ('irc_voided', 'Iridiumcorp - Payment Voided');
32
+ INSERT INTO `{$installer->getTable('sales_order_status')}` (`status`, `label`) VALUES ('irc_preauth', 'Iridiumcorp - PreAuthorized');
33
+ INSERT INTO `{$installer->getTable('sales_order_status')}` (`status`, `label`) VALUES ('irc_collected', 'Iridiumcorp - Payment Collected');
34
  ");
35
  }
36
  catch(Exception $exc)
38
  Mage::log("Error during script installation: ". $exc->__toString());
39
  }
40
 
41
+ Mage::log('iridiumcorp installer script ended');
42
 
43
  $installer->endSetup();
app/design/adminhtml/default/default/layout/tpg.xml ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout>
3
+ <adminhtml_sales_order_view>
4
+ <reference name="head">
5
+ <action method="addItem">
6
+ <type>skin_js</type>
7
+ <name>tpg.js</name>
8
+ </action>
9
+ </reference>
10
+ </adminhtml_sales_order_view>
11
+ </layout>
app/design/adminhtml/default/default/template/payment/info/cc_tpg.phtml ADDED
@@ -0,0 +1,172 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $m_boTransactionAuthorised = false;
3
+ $m_boValidCrossReference = false;
4
+ $m_boExtensionVersionWithCrossReferenceFeature = true;
5
+
6
+ $m_order = $this->getInfo()->getOrder();
7
+ $m_payment = $m_order->getPayment();
8
+ $m_szOrderID = $m_order->getRealOrderId();
9
+ $m_szOrderStatus = $m_order->getStatus();
10
+ $m_szAmount = $m_order->getBaseGrandTotal();
11
+ $m_nPaymentVoided = 0;//(int)$m_order->getVoided();
12
+ $m_nPaymentRefunded = 0;
13
+ $m_nPaymentCollected = 0;
14
+ $m_boCanVoid = false;
15
+ $m_boCanCollect = false;
16
+
17
+ // get the additional information column data for a Magento payment
18
+ $additional_info = $m_payment->getAdditionalInformation();
19
+ $szToday = date("Ymd");
20
+
21
+ // for redirected transactions the TransactionId can't be updated with a new CrossReference (ie: 3DS transaction), need to revert back to additional_info
22
+ //$szCrossReference = $m_payment->getLastTransId();
23
+ $additionalInfo = $m_payment->getAdditionalInformation();
24
+ if(!key_exists("CrossReference", $additionalInfo))
25
+ {
26
+ $szCrossReference = false;
27
+ }
28
+ else
29
+ {
30
+ $szCrossReference = $additional_info["CrossReference"];
31
+ }
32
+
33
+ if(!key_exists("TransactionDateTime", $additionalInfo))
34
+ {
35
+ $szTransactionDateTime = false;
36
+ }
37
+ else
38
+ {
39
+ $szTransactionDateTime = $additional_info["TransactionDateTime"];
40
+ }
41
+
42
+ if(!key_exists("TransactionType", $additionalInfo))
43
+ {
44
+ $szTransactionType = false;
45
+ }
46
+ else
47
+ {
48
+ $szTransactionType = $additional_info["TransactionType"];
49
+ }
50
+
51
+ if(key_exists("Voided", $additionalInfo))
52
+ {
53
+ $m_nPaymentVoided = (int)$additional_info["Voided"];
54
+ }
55
+ if(key_exists("Refunded", $additionalInfo))
56
+ {
57
+ $m_nPaymentRefunded = (int)$additional_info["Refunded"];
58
+ }
59
+ if(key_exists("Collected", $additionalInfo))
60
+ {
61
+ $m_nPaymentCollected = (int)$additional_info["Collected"];
62
+ }
63
+
64
+ if(!$szCrossReference ||
65
+ !$szTransactionDateTime ||
66
+ !$szTransactionType)
67
+ {
68
+ $m_boExtensionVersionWithCrossReferenceFeature = false;
69
+ }
70
+ else
71
+ {
72
+ if($szTransactionType == 'PREAUTH')
73
+ {
74
+ $m_szTransactionType = "PREAUTH";
75
+
76
+ // check if payment can be voided
77
+ if (!$m_nPaymentVoided &&
78
+ !$m_nPaymentRefunded &&
79
+ // payment must be successful
80
+ $m_szOrderStatus == "irc_preauth")
81
+ {
82
+ if (strtotime($szToday) == strtotime($szTransactionDateTime))
83
+ {
84
+ $m_boCanVoid = true;
85
+ }
86
+ }
87
+
88
+ // check if payment can be collected
89
+ if(!$m_nPaymentVoided &&
90
+ !$m_nPaymentCollected &&
91
+ // payment must be successful
92
+ $m_szOrderStatus == "irc_preauth")
93
+ {
94
+ $m_boCanCollect = true;
95
+ }
96
+ }
97
+ else if($szTransactionType == 'SALE')
98
+ {
99
+ $m_szTransactionType = "SALE";
100
+
101
+ // check if payment can be voided
102
+ if(!$m_nPaymentVoided &&
103
+ !$m_nPaymentRefunded &&
104
+ // payment must be successful
105
+ $m_szOrderStatus == "irc_paid")
106
+ {
107
+ if(strtotime($szToday) == strtotime($szTransactionDateTime) &&
108
+ // for the time being only allow to execute a root VOID
109
+ $m_szOrderStatus == "irc_paid")
110
+ {
111
+ $m_boCanVoid = true;
112
+ }
113
+ }
114
+
115
+ // check if it can be collected - only preauth can be collected
116
+ $m_nPaymentCollected = 0;
117
+ }
118
+ else
119
+ {
120
+ Mage::log('Order info error: transaction type: '.$szTransactionType.' is not supported by the Iridiumcorp/Tpg extension');
121
+ }
122
+ }
123
+ ?>
124
+
125
+ <div>
126
+ CrossReference:
127
+ <?php
128
+ if(!$m_boExtensionVersionWithCrossReferenceFeature)
129
+ {
130
+ echo "<span style=\"font-weight:bold;color:Red;\">Missing data*</span>";
131
+ }
132
+ else
133
+ {
134
+ echo "<span style=\"font-weight:bold;\">".$szCrossReference."</span>";
135
+ }
136
+ ?>
137
+ </div>
138
+ <div>
139
+ Transaction Type:
140
+ <?php
141
+ if(!$m_boExtensionVersionWithCrossReferenceFeature)
142
+ {
143
+ echo "<span style=\"font-weight:bold;color:Red;\">Missing data*</span>";
144
+ }
145
+ else
146
+ {
147
+ echo "<span style=\"font-weight:bold;\">".$m_szTransactionType."</span>";
148
+ }
149
+ ?>
150
+ </div>
151
+ <div>
152
+ Amount: <?php echo "<span style=\"font-weight:bold\">".$m_szAmount."</span>"; ?>
153
+ </div>
154
+
155
+ <?php if(!$m_boExtensionVersionWithCrossReferenceFeature): ?>
156
+ <div>
157
+ <span style="font-weight:bold;color:Red;">* Incomplete orders and orders processed through an older payment extension will not have all the data necessary for CrossReference payments</span>
158
+ </div>
159
+ <?php else: ?>
160
+ <div>
161
+ <?php if($m_boCanVoid): ?>
162
+ <button type="button" id="voidButton" onclick="IRC_runCrossReferenceTransaction('<?php echo $this->getUrl('tpg/payment/void', array('_secure' => true)); ?>', '<?php echo $m_szOrderID; ?>', '<?php echo $szCrossReference; ?>', 'VOID');">
163
+ <span>VOID</span>
164
+ </button>
165
+ <?php endif; ?>
166
+ <?php if($m_boCanCollect): ?>
167
+ <button type="button" id="collectionButton" onclick="IRC_runCrossReferenceTransaction('<?php echo $this->getUrl('tpg/payment/collection', array('_secure' => true)); ?>', '<?php echo $m_szOrderID; ?>', '<?php echo $szCrossReference; ?>', 'COLLECTION');">
168
+ <span>COLLECT</span>
169
+ </button>
170
+ <?php endif; ?>
171
+ </div>
172
+ <?php endif; ?>
app/design/frontend/base/default/template/tpg/form.phtml CHANGED
@@ -11,6 +11,9 @@
11
  <li>
12
  <?php echo $this->__('You will be redirected to a secure page where you can complete your payment.') ?>
13
  </li>
 
 
 
14
  </ul>
15
  </fieldset>
16
  <?php } else {?>
11
  <li>
12
  <?php echo $this->__('You will be redirected to a secure page where you can complete your payment.') ?>
13
  </li>
14
+ <li class='notice-msg'>
15
+ <?php echo $this->__('Please do not attempt to click the "BACK" button in your browser once you were redirected to the secure payment page to complete your payment. If you need to change your order you can do it before placing your order.') ?>
16
+ </li>
17
  </ul>
18
  </fieldset>
19
  <?php } else {?>
app/design/frontend/default/default/template/tpg/form.phtml CHANGED
@@ -11,6 +11,9 @@
11
  <li>
12
  <?php echo $this->__('You will be redirected to a secure page where you can complete your payment.') ?>
13
  </li>
 
 
 
14
  </ul>
15
  </fieldset>
16
  <?php } else {?>
11
  <li>
12
  <?php echo $this->__('You will be redirected to a secure page where you can complete your payment.') ?>
13
  </li>
14
+ <li class='notice-msg'>
15
+ <?php echo $this->__('Please do not attempt to click the "BACK" button in your browser once you were redirected to the secure payment page to complete your payment. If you need to change your order you can do it before placing your order.') ?>
16
+ </li>
17
  </ul>
18
  </fieldset>
19
  <?php } else {?>
package.xml CHANGED
@@ -1,18 +1,20 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Iridiumcorp_Tpg</name>
4
- <version>1.14.1</version>
5
  <stability>stable</stability>
6
  <license>OSL v3.0</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Iridiumcorp payment extension compatible with Magento v 1.3, 1.4, 1.5 and 1.6</summary>
10
- <description>Fully supports 3D secure transactions. Also supports all of the integration methods provided by Iridiumcorp.</description>
11
- <notes>Added credit card number validation class</notes>
 
 
12
  <authors><author><name>Iridiumcorp</name><user>auto-converted</user><email>support@iridiumcorp.net</email></author></authors>
13
- <date>2012-01-26</date>
14
- <time>14:16:01</time>
15
- <contents><target name="mageskin"><dir name="frontend"><dir name="default"><dir name="default"><dir name="images"><file name="iridium_corporation.jpg" hash="589faaa1b7e80b32a425175ecfc3b455"/></dir></dir></dir><dir name="base"><dir name="default"><dir name="images"><file name="iridium_corporation.jpg" hash="589faaa1b7e80b32a425175ecfc3b455"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="tpg"><file name="form.phtml" hash="b0838917ecb3a7d1167dd94c10981c9f"/><file name="info.phtml" hash="38bfb7011b9cb1b3f48fa1ed3ea8b1e7"/></dir></dir></dir></dir><dir name="base"><dir name="default"><dir name="template"><dir name="tpg"><file name="form.phtml" hash="8b0d05b93432af9f2ea43bb1796e30de"/><file name="info.phtml" hash="38bfb7011b9cb1b3f48fa1ed3ea8b1e7"/></dir></dir></dir></dir></dir><dir name="frontend"><dir name="default"><dir name="default"><dir name="template"><dir name="tpg"><file name="form.phtml" hash="f0eaaa923f0719ac5865719806b9da1a"/><file name="info.phtml" hash="e9011580324f811d71aeb8c0b0f64734"/></dir></dir></dir></dir><dir name="base"><dir name="default"><dir name="template"><dir name="tpg"><file name="form.phtml" hash="04b96613a5d71ec9a125543bc6728f4b"/><file name="info.phtml" hash="e9011580324f811d71aeb8c0b0f64734"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Iridiumcorp_All.xml" hash="f1a85eaa7631af1906f461b662519732"/></dir></target><target name="magelocal"><dir name="Iridiumcorp"><dir name="Tpg"><dir name="Block"><file name="Error.php" hash="905367210beb53a0bc68dc6033e24127"/><file name="Form.php" hash="4b1d51aa84982486f3139510c41a221a"/><file name="Info.php" hash="f88445c4880bfe14914252bc76b6fc28"/><file name="Redirect.php" hash="a91a8a8f8b5ad887ed2cdd8d52732b8b"/><file name="Threedsecure.php" hash="5e753e1e1bbf0ada18f7292d4031da97"/></dir><dir name="controllers"><file name="PaymentController.php" hash="68d3636ed06255730f7fcb816c3289ba"/></dir><dir name="etc"><file name="config.xml" hash="a22141f14f4b641de6088d0ead20ba49"/><file name="system.xml" hash="95ae76c5feb8dda560bca6a576e36c3c"/></dir><dir name="Helper"><file name="Data.php" hash="a72fba87e718c94d993a57199e20ca96"/></dir><dir name="Model"><dir name="Common"><dir name="ThePaymentGateway"><file name="PaymentSystem.php" hash="74698dc7049a4ffa890481d29a1c620c"/><file name="SOAP.php" hash="9be2001c48e0c4919a915f6db1509cdd"/><file name="TPG_Common.php" hash="655bdcebcea8ffa3a2d8fa275bd2b80b"/></dir><file name="GlobalErrors.php" hash="a9c7bab60ebfe87967c794194e1e7208"/><file name="ISOCountries.php" hash="fc63d76fbe25458ba351f114782074cb"/><file name="ISOCurrencies.php" hash="89ac1e124e89c0713ef43a0cf6dd0e2b"/><file name="PaymentFormHelper.php" hash="f75b9bcc9c09bd359a24f8e8b2702a07"/></dir><dir name="Source"><file name="HashMethod.php" hash="36d7fb4fc762feae459f0e67d51006f4"/><file name="OrderStatus.php" hash="95eb926db39d4afeb26784a9396f7b18"/><file name="PaymentAction.php" hash="bd8dc40852b9ff8c80c08fc01f35a988"/><file name="PaymentMode.php" hash="6849defade8a7da4cfaeff3227ae5b83"/><file name="ResultDeliveryMethod.php" hash="05f3806f2ff4bd5b1568bfb1681b2242"/></dir><dir name="Resource"><dir name="Eav"><dir name="Mysql4"><file name="Setup.php" hash="d75ce704c7f0161f0bea4aa780679af8"/></dir></dir></dir><file name="Direct.php" hash="93379d38de07b6fab21fb63ed602879e"/><file name="Request.php" hash="a96e462ed3c1882048ea45f2c3a6662c"/></dir><dir name="sql"><dir name="tpg_setup"><file name="mysql4-install-0.1.0.php" hash="ef633b313caa213b729fe4b11860795e"/></dir></dir></dir><dir name="Checkout"><dir name="Block"><dir name="Onepage"><dir name="Payment"><file name="Methods.php" hash="47de7ef027476c184a01f6c249a56065"/></dir></dir></dir><dir name="etc"><file name="config.xml" hash="aaa95b6e1d6e145940bf9ba9bbe1dc0f"/></dir><dir name="Model"><dir name="Type"><file name="Onepage.php" hash="21ae90067e90c3b092014191adf01475"/></dir></dir></dir><dir name="Sales"><dir name="etc"><file name="config.xml" hash="6e5a6db08b9bbaf959ec31a20ec5ffc2"/></dir><dir name="Model"><dir name="Order"><file name="Invoice.php" hash="1d4318c7b307f40b4a208dcb116fa14b"/><file name="Payment.php" hash="cd56b85013bbae52bb9bfe1984721045"/></dir><dir name="Service"><file name="Quote.php" hash="fbeac3e28f152fe6ee0419620188bab1"/></dir><file name="Order.php" hash="a57c4bd661dbc322d5bd18aa2f51dd67"/></dir></dir></dir></target></contents>
16
  <compatible/>
17
  <dependencies/>
18
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Iridiumcorp_Tpg</name>
4
+ <version>1.15.0</version>
5
  <stability>stable</stability>
6
  <license>OSL v3.0</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Iridiumcorp payment extension compatible with Magento v 1.3, 1.4, 1.5 and 1.6</summary>
10
+ <description>Fully supports 3D secure and CrossReference transactions. Also supports all of the integration methods provided by Iridiumcorp.</description>
11
+ <notes>Option to select transaction type: PREAUTH or SALE.&#xD;
12
+ CrossReference feature added with new transaction types: VOID, REFUND and COLLECTION.&#xD;
13
+ Fixed stock management bug on Hosted Payment Form payment when clicking on BACK button before payment is processed.</notes>
14
  <authors><author><name>Iridiumcorp</name><user>auto-converted</user><email>support@iridiumcorp.net</email></author></authors>
15
+ <date>2012-02-17</date>
16
+ <time>11:29:58</time>
17
+ <contents><target name="mageskin"><dir name="frontend"><dir name="default"><dir name="default"><dir name="images"><file name="iridium_corporation.jpg" hash="589faaa1b7e80b32a425175ecfc3b455"/></dir></dir></dir><dir name="base"><dir name="default"><dir name="images"><file name="iridium_corporation.jpg" hash="589faaa1b7e80b32a425175ecfc3b455"/></dir></dir></dir></dir><dir name="adminhtml"><dir name="default"><dir name="default"><file name="tpg.js" hash="11194666936eda1fd7cead21dd819780"/></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="tpg"><file name="form.phtml" hash="b0838917ecb3a7d1167dd94c10981c9f"/><file name="info.phtml" hash="38bfb7011b9cb1b3f48fa1ed3ea8b1e7"/></dir><dir name="payment"><dir name="info"><file name="cc_tpg.phtml" hash="47dcca27b2a817249400721c8d5be2ca"/></dir></dir></dir><dir name="layout"><file name="tpg.xml" hash="28c93adfaf4b96f413aea26cf0da992b"/></dir></dir></dir><dir name="base"><dir name="default"><dir name="template"><dir name="tpg"><file name="form.phtml" hash="8b0d05b93432af9f2ea43bb1796e30de"/><file name="info.phtml" hash="38bfb7011b9cb1b3f48fa1ed3ea8b1e7"/></dir></dir></dir></dir></dir><dir name="frontend"><dir name="default"><dir name="default"><dir name="template"><dir name="tpg"><file name="form.phtml" hash="d5dee34f1c379f1a03da6f40541b2bae"/><file name="info.phtml" hash="e9011580324f811d71aeb8c0b0f64734"/></dir></dir></dir></dir><dir name="base"><dir name="default"><dir name="template"><dir name="tpg"><file name="form.phtml" hash="a2c7a26645595c49b1c8038e31767958"/><file name="info.phtml" hash="e9011580324f811d71aeb8c0b0f64734"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Iridiumcorp_All.xml" hash="f1a85eaa7631af1906f461b662519732"/></dir></target><target name="magelocal"><dir name="Iridiumcorp"><dir name="Tpg"><dir name="Block"><dir name="Adminhtml"><dir name="Sales"><dir name="Order"><file name="Payment.php" hash="8f226ae53f00312da96f92db7e2d8f1e"/></dir></dir></dir><file name="Error.php" hash="905367210beb53a0bc68dc6033e24127"/><file name="Form.php" hash="4b1d51aa84982486f3139510c41a221a"/><file name="Info.php" hash="f88445c4880bfe14914252bc76b6fc28"/><file name="Redirect.php" hash="a91a8a8f8b5ad887ed2cdd8d52732b8b"/><file name="Threedsecure.php" hash="5e753e1e1bbf0ada18f7292d4031da97"/></dir><dir name="controllers"><file name="PaymentController.php" hash="1feb345f6f7db943fbb43f2c21d50276"/></dir><dir name="etc"><file name="config.xml" hash="2b81a460a62143de1ae7ce5d8dd5fa0f"/><file name="system.xml" hash="95ae76c5feb8dda560bca6a576e36c3c"/></dir><dir name="Helper"><file name="Data.php" hash="a72fba87e718c94d993a57199e20ca96"/></dir><dir name="Model"><dir name="Common"><dir name="ThePaymentGateway"><file name="PaymentSystem.php" hash="d9814b7eb1302ddba2fa07c49f8d930c"/><file name="SOAP.php" hash="9be2001c48e0c4919a915f6db1509cdd"/><file name="TPG_Common.php" hash="655bdcebcea8ffa3a2d8fa275bd2b80b"/></dir><file name="GlobalErrors.php" hash="a9c7bab60ebfe87967c794194e1e7208"/><file name="ISOCountries.php" hash="fc63d76fbe25458ba351f114782074cb"/><file name="ISOCurrencies.php" hash="89ac1e124e89c0713ef43a0cf6dd0e2b"/><file name="PaymentFormHelper.php" hash="f75b9bcc9c09bd359a24f8e8b2702a07"/></dir><dir name="Source"><file name="HashMethod.php" hash="36d7fb4fc762feae459f0e67d51006f4"/><file name="OrderStatus.php" hash="95eb926db39d4afeb26784a9396f7b18"/><file name="PaymentAction.php" hash="5ec68f91d5948041074e78af1baaeb8f"/><file name="PaymentMode.php" hash="6849defade8a7da4cfaeff3227ae5b83"/><file name="ResultDeliveryMethod.php" hash="05f3806f2ff4bd5b1568bfb1681b2242"/></dir><dir name="Resource"><dir name="Eav"><dir name="Mysql4"><file name="Setup.php" hash="d75ce704c7f0161f0bea4aa780679af8"/></dir></dir></dir><file name="Direct.php" hash="84376c6f4c909dc7803aa0755bc6cc26"/><file name="Request.php" hash="a96e462ed3c1882048ea45f2c3a6662c"/></dir><dir name="sql"><dir name="tpg_setup"><file name="mysql4-install-0.1.0.php" hash="e8b5155029f630e15f2937e22ed7efd2"/></dir></dir></dir><dir name="Checkout"><dir name="Block"><dir name="Onepage"><dir name="Payment"><file name="Methods.php" hash="47de7ef027476c184a01f6c249a56065"/></dir></dir></dir><dir name="etc"><file name="config.xml" hash="aaa95b6e1d6e145940bf9ba9bbe1dc0f"/></dir><dir name="Model"><dir name="Type"><file name="Onepage.php" hash="21ae90067e90c3b092014191adf01475"/></dir></dir></dir><dir name="Sales"><dir name="etc"><file name="config.xml" hash="b9c67ea0cfbba619d4437188bd1591fb"/></dir><dir name="Model"><dir name="Order"><file name="Invoice.php" hash="1d4318c7b307f40b4a208dcb116fa14b"/><file name="Payment.php" hash="a97669d0eab389a5a8ab36bd3d41a2cd"/></dir><dir name="Service"><file name="Quote.php" hash="fbeac3e28f152fe6ee0419620188bab1"/></dir><file name="Order.php" hash="a57c4bd661dbc322d5bd18aa2f51dd67"/></dir></dir></dir></target></contents>
18
  <compatible/>
19
  <dependencies/>
20
  </package>
skin/adminhtml/default/default/tpg.js ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function IRC_runCrossReferenceTransaction(szActionURL, szOrderID, szCrossReference, szTransactionType)
2
+ {
3
+ var szConfirmMessage;
4
+ var szText;
5
+
6
+ if (szActionURL == "")
7
+ {
8
+ alert("Error: Invalid action URL");
9
+ }
10
+
11
+ if (szTransactionType == "VOID")
12
+ {
13
+ szConfirmMessage = "Are you sure you would like to void this payment?";
14
+ szText = "<ul class='messages'><li class='success-msg'><ul><li>Payment successfully voided</li></ul></li></ul>";
15
+ }
16
+ else if (szTransactionType == "COLLECTION")
17
+ {
18
+ szConfirmMessage = "Are you sure you would like to collect this authorized payment?";
19
+ szText = "<ul class='messages'><li class='success-msg'><ul><li>Authorized payment successfully collected</li></ul></li></ul>";
20
+ }
21
+ else
22
+ {
23
+ alert("Error: Unknown transaction type to run for this action: " + szTransactionType);
24
+ return;
25
+ }
26
+
27
+ if (confirm(szConfirmMessage))
28
+ {
29
+ new Ajax.Request(szActionURL,
30
+ { method: "post",
31
+ parameters: { OrderID: szOrderID, CrossReference: szCrossReference },
32
+ onSuccess: function (result) { var szMessage = result.responseText; if (szMessage == "0") { location.href = location.href; /* cheating with displaying a success message before the page is refreshed */ $('messages').update(szText); } else { alert(szMessage); } }
33
+ });
34
+ }
35
+ }