Cardgate_Cgp - Version 1.1.11

Version Notes

- Added refund capability (see CardGate Settings-tab)
- Changed behaviour when payments for already canceled orders are successfully processed

Download this release

Release Info

Developer Cardgate BV
Extension Cardgate_Cgp
Version 1.1.11
Comparing to
See all releases


Code changes from version 1.1.10 to 1.1.11

app/code/local/Cardgate/Cgp/Block/Adminhtml/System/Config/Source/Version.php CHANGED
@@ -12,9 +12,33 @@ class Cardgate_Cgp_Block_Adminhtml_System_Config_Source_Version
12
 
13
  public function render (Varien_Data_Form_Element_Abstract $element)
14
  {
 
 
 
15
  $base = Mage::getSingleton( 'cgp/base' );
16
- $sTestMode = $base->isTest() ? "<span style='color:#F00'>TEST MODE</span><br/>\n" : '';
17
- $sTestMode.= !empty( $_SERVER['CGP_GATEWAY_URL'] ) ? "<span style='color:#F00'>FORCED URL : {$_SERVER['CGP_GATEWAY_URL']}</span><br/>\n" : '';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  return $sTestMode . 'CardGate v' . Mage::getConfig()->getNode( 'modules/Cardgate_Cgp/version' ) . ' / Magento v' . Mage::getVersion();
19
  }
20
 
12
 
13
  public function render (Varien_Data_Form_Element_Abstract $element)
14
  {
15
+ /**
16
+ * @var Cardgate_Cgp_Model_Base $base
17
+ */
18
  $base = Mage::getSingleton( 'cgp/base' );
19
+ /**
20
+ * @var Cardgate_Cgp_Model_Gateway_Default $gateway
21
+ */
22
+ $gateway = Mage::getModel( 'cgp/gateway_default');
23
+
24
+ $sTestMode = '';
25
+ $sTestMode.= $base->isTest() ? "<span style='color:#F00'>TEST MODE</span><br/>\n" : '';
26
+ $sTestMode.= !empty( $_SERVER['CGP_GATEWAY_URL'] ) ? "<span style='color:#F00'>FORCED GW URL : {$_SERVER['CGP_GATEWAY_URL']}</span><br/>\n" : '';
27
+ $sTestMode.= !empty( $_SERVER['CGP_API_URL'] ) ? "<span style='color:#F00'>FORCED API URL : {$_SERVER['CGP_API_URL']}</span><br/>\n" : '';
28
+
29
+ $missing = array();
30
+ foreach ( array('hash_key'=>'Hash Key','site_id'=>'Site ID','api_id'=>'RESTful API Username','api_key'=>'RESTful API Key') as $k=>$v ) {
31
+ if ( empty( $gateway->getConfigData( $k ) ) ) {
32
+ $missing[$k] = Mage::helper( 'cgp' )->__($v);
33
+ }
34
+ }
35
+ if ( !count( $missing ) ) {
36
+ $sTestMode.= Mage::helper( 'cgp' )->__("Refunds enabled.") . ' <a href="/cgp/standard/test?action=restful&hash=' . md5( $gateway->getConfigData( 'site_id' ) . $gateway->getConfigData( 'hash_key' )) . '" target="_blank">'.
37
+ Mage::helper( 'cgp' )->__("Test current RESTful settings") . "</a><br/>\n";
38
+ } else {
39
+ $sTestMode.= Mage::helper( 'cgp' )->__("Refunds disabled. Missing settings:") . " '".implode("', '", $missing)."'.<br/>\n";
40
+ }
41
+
42
  return $sTestMode . 'CardGate v' . Mage::getConfig()->getNode( 'modules/Cardgate_Cgp/version' ) . ' / Magento v' . Mage::getVersion();
43
  }
44
 
app/code/local/Cardgate/Cgp/Block/Paymentfee/Adminhtml/Sales/Order/Totals.php CHANGED
@@ -28,4 +28,10 @@ class Cardgate_Cgp_Block_Paymentfee_Adminhtml_Sales_Order_Totals extends Mage_Ad
28
 
29
  return Mage::helper( 'cgp/paymentfee' )->addToBlock( $this );
30
  }
 
 
 
 
 
 
31
  }
28
 
29
  return Mage::helper( 'cgp/paymentfee' )->addToBlock( $this );
30
  }
31
+
32
+ public function getInvoice ()
33
+ {
34
+ return $this->getParentBlock()->getInvoice();
35
+ }
36
+
37
  }
app/code/local/Cardgate/Cgp/Model/Base.php CHANGED
@@ -6,8 +6,7 @@
6
  * @category Mage
7
  * @package Cardgate_Cgp
8
  */
9
- class Cardgate_Cgp_Model_Base extends Varien_Object
10
- {
11
 
12
  protected $_callback;
13
 
@@ -20,8 +19,7 @@ class Cardgate_Cgp_Model_Base extends Varien_Object
20
  /**
21
  * Initialize basic cgp settings
22
  */
23
- public function _construct ()
24
- {
25
  $this->_config = Mage::getStoreConfig( 'cgp/settings' );
26
  }
27
 
@@ -31,8 +29,7 @@ class Cardgate_Cgp_Model_Base extends Varien_Object
31
  * @param string $field
32
  * @return mixed
33
  */
34
- public function getConfigData ( $field )
35
- {
36
  if ( isset( $this->_config[$field] ) ) {
37
  return $this->_config[$field];
38
  } else {
@@ -46,8 +43,7 @@ class Cardgate_Cgp_Model_Base extends Varien_Object
46
  * @param array $data
47
  * @return Cardgate_Cgp_Model_Base
48
  */
49
- public function setCallbackData ( $data )
50
- {
51
  $this->_callback = $data;
52
  return $this;
53
  }
@@ -58,8 +54,7 @@ class Cardgate_Cgp_Model_Base extends Varien_Object
58
  * @param string $field
59
  * @return string
60
  */
61
- public function getCallbackData ( $field = null )
62
- {
63
  if ( $field === null ) {
64
  return $this->_callback;
65
  } else {
@@ -72,8 +67,7 @@ class Cardgate_Cgp_Model_Base extends Varien_Object
72
  *
73
  * @return bool
74
  */
75
- public function isDebug ()
76
- {
77
  return $this->getConfigData( 'debug' );
78
  }
79
 
@@ -82,8 +76,7 @@ class Cardgate_Cgp_Model_Base extends Varien_Object
82
  *
83
  * @return bool
84
  */
85
- public function isTest ()
86
- {
87
  return ( $this->getConfigData( 'test_mode' ) == "test" );
88
  }
89
 
@@ -93,8 +86,7 @@ class Cardgate_Cgp_Model_Base extends Varien_Object
93
  * @param string $msg
94
  * @return void
95
  */
96
- public function log ( $msg )
97
- {
98
  if ( $this->getConfigData( 'debug' ) ) {
99
  Mage::log( $msg, null, $this->_logFileName );
100
  }
@@ -105,10 +97,10 @@ class Cardgate_Cgp_Model_Base extends Varien_Object
105
  *
106
  * @return Cardgate_Cgp_Model_Base
107
  */
108
- public function lock ()
109
- {
110
  $varDir = Mage::getConfig()->getVarDir( 'locks' );
111
- $lockFilename = $varDir . DS . $this->getCallbackData( 'ref' ) . '.lock';
112
  $fp = @fopen( $lockFilename, 'x' );
113
 
114
  if ( $fp ) {
@@ -126,24 +118,34 @@ class Cardgate_Cgp_Model_Base extends Varien_Object
126
  *
127
  * @return Cardgate_Cgp_Model_Base
128
  */
129
- public function unlock ()
130
- {
131
  $this->_isLocked = false;
132
  $varDir = Mage::getConfig()->getVarDir( 'locks' );
133
- $lockFilename = $varDir . DS . $this->getCallbackData( 'ref' ) . '.lock';
134
  unlink( $lockFilename );
135
 
136
  return $this;
137
  }
138
 
 
 
 
 
 
 
 
 
 
 
 
139
  /**
140
  * Create and mail invoice
141
  *
142
  * @param Mage_Sales_Model_Order $order
143
  * @return boolean
144
  */
145
- protected function createInvoice ( Mage_Sales_Model_Order $order )
146
- {
147
  if ( $order->canInvoice() && ! $order->hasInvoices() ) {
148
  $invoice = $order->prepareInvoice();
149
  $invoice->register();
@@ -165,8 +167,7 @@ class Cardgate_Cgp_Model_Base extends Varien_Object
165
  }
166
 
167
  $statusMessage = $mail_invoice ? "Invoice # %s created and send to customer." : "Invoice # %s created.";
168
- $order->addStatusToHistory( $order->getStatus(),
169
- Mage::helper( "cgp" )->__( $statusMessage, $invoice->getIncrementId(), $mail_invoice ) );
170
 
171
  return true;
172
  }
@@ -180,8 +181,7 @@ class Cardgate_Cgp_Model_Base extends Varien_Object
180
  * @param Mage_Sales_Model_Order $order
181
  * @return void
182
  */
183
- protected function eventInvoicingFailed ( $order )
184
- {
185
  $storeId = $order->getStore()->getId();
186
 
187
  $ident = Mage::getStoreConfig( 'cgp/settings/notification_email' );
@@ -195,12 +195,32 @@ class Cardgate_Cgp_Model_Base extends Varien_Object
195
  $mail->addTo( $recipient_email, $recipient_name );
196
  $mail->setSubject( Mage::helper( "cgp" )->__( 'Automatic invoice creation failed' ) );
197
  $mail->setBodyText(
198
- Mage::helper( "cgp" )->__(
199
- 'Magento was unable to create an invoice for Order # %s after a successful payment via Card Gate (transaction # %s)',
200
- $order->getIncrementId(), $this->getCallbackData( 'transaction_id' ) ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
201
  $mail->setBodyHtml(
202
  Mage::helper( "cgp" )->__(
203
- 'Magento was unable to create an invoice for <b>Order # %s</b> after a successful payment via Card Gate <b>(transaction # %s)</b>',
204
  $order->getIncrementId(), $this->getCallbackData( 'transaction_id' ) ) );
205
  $mail->send();
206
  }
@@ -211,17 +231,13 @@ class Cardgate_Cgp_Model_Base extends Varien_Object
211
  * @param Mage_Sales_Model_Order $order
212
  * @return boolean
213
  */
214
- protected function validateAmount ( Mage_Sales_Model_Order $order )
215
- {
216
  $amountInCents = ( int ) sprintf( '%.0f', $order->getGrandTotal() * 100 );
217
  $callbackAmount = ( int ) $this->getCallbackData( 'amount' );
218
 
219
  if ( ( $amountInCents != $callbackAmount ) and ( abs( $callbackAmount - $amountInCents ) > 1 ) ) {
220
- $this->log(
221
- 'OrderID: ' . $order->getId() . ' do not match amounts. Sent ' . $amountInCents . ', received: ' .
222
- $callbackAmount );
223
- $statusMessage = Mage::helper( "cgp" )->__(
224
- "Hacker attempt: Order total amount does not match CardGate's gross total amount!" );
225
  $order->addStatusToHistory( $order->getStatus(), $statusMessage );
226
  $order->save();
227
  return false;
@@ -230,14 +246,51 @@ class Cardgate_Cgp_Model_Base extends Varien_Object
230
  return true;
231
  }
232
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
233
  /**
234
  * Process callback for all transactions
235
  *
236
  * @return void
237
  */
238
- public function processCallback ()
239
- {
240
  $id = $this->getCallbackData( 'ref' );
 
 
 
 
241
  $order = Mage::getModel( 'sales/order' );
242
  $order->loadByIncrementId( $id );
243
 
@@ -251,6 +304,16 @@ class Cardgate_Cgp_Model_Base extends Varien_Object
251
  exit();
252
  }
253
 
 
 
 
 
 
 
 
 
 
 
254
  $statusWaitconf = $this->getConfigData( "waitconf_status" );
255
  $statusPending = $this->getConfigData( "pending_status" );
256
  $statusComplete = $this->getConfigData( "complete_status" );
@@ -265,9 +328,7 @@ class Cardgate_Cgp_Model_Base extends Varien_Object
265
  $newStatus = true;
266
  $statusMessage = '';
267
 
268
- $this->log(
269
- "Got: {$statusPending}/{$statusComplete}/{$statusFailed}/{$statusFraud}/{$autocreateInvoice}/{$evInvoicingFailed} : " .
270
- $this->getCallbackData( 'status_id' ) );
271
 
272
  switch ( $this->getCallbackData( 'status_id' ) ) {
273
  case "0":
@@ -318,9 +379,9 @@ class Cardgate_Cgp_Model_Base extends Varien_Object
318
  $newState = Mage_Sales_Model_Order::STATE_PENDING_PAYMENT;
319
  $newStatus = $statusPending;
320
  $statusMessage = Mage::helper( 'cgp' )->__( 'Transaction pending: Waiting for customer action.' );
321
- $order->sendNewOrderEmail();
322
- $order->setIsCustomerNotified( true );
323
- $order->save();
324
  break;
325
  case "701":
326
  // Direct debit pending status
@@ -328,9 +389,9 @@ class Cardgate_Cgp_Model_Base extends Varien_Object
328
  $newState = Mage_Sales_Model_Order::STATE_PENDING_PAYMENT;
329
  $newStatus = $statusWaitconf;
330
  $statusMessage = Mage::helper( 'cgp' )->__( 'Transaction pending: Waiting for confirmation.' );
331
- $order->sendNewOrderEmail();
332
- $order->setIsCustomerNotified( true );
333
- $order->save();
334
  break;
335
  default:
336
  $msg = 'Status not recognised: ' . $this->getCallbackData( 'status' );
@@ -339,22 +400,24 @@ class Cardgate_Cgp_Model_Base extends Varien_Object
339
  }
340
 
341
  // Additional logging for direct-debit
342
- if ( $this->getCallbackData( 'recipient_name' ) && $this->getCallbackData( 'recipient_iban' )
343
- && $this->getCallbackData( 'recipient_bic' ) && $this->getCallbackData( 'recipient_reference' )
344
- ) {
345
- $statusMessage.= "<br/>\n" . Mage::helper( 'cgp' )->__( 'Additional information' )." : "
346
- . "<br/>\n" . Mage::helper( 'cgp' )->__( 'Benificiary' ) ." : ". $this->getCallbackData( 'recipient_name' )
347
- . "<br/>\n" . Mage::helper( 'cgp' )->__( 'Benificiary IBAN' ) ." : ". $this->getCallbackData( 'recipient_iban' )
348
- . "<br/>\n" . Mage::helper( 'cgp' )->__( 'Benificiary BIC' ) ." : ". $this->getCallbackData( 'recipient_bic' )
349
- . "<br/>\n" . Mage::helper( 'cgp' )->__( 'Reference' ) ." : ". $this->getCallbackData( 'recipient_reference' );
350
- }
 
 
 
 
351
 
352
  // Update only certain states
353
  $canUpdate = false;
354
  $undoCancel = false;
355
- if ( $order->getState() == Mage_Sales_Model_Order::STATE_NEW ||
356
- $order->getState() == Mage_Sales_Model_Order::STATE_PENDING_PAYMENT ||
357
- $order->getState() == Mage_Sales_Model_Order::STATE_CANCELED ) {
358
  $canUpdate = true;
359
  }
360
 
@@ -363,37 +426,27 @@ class Cardgate_Cgp_Model_Base extends Varien_Object
363
  if ( $_item->getStatusLabel() == ucfirst( $statusComplete ) ) {
364
  $canUpdate = false;
365
  // Uncancel an order if the payment is considered complete
366
- } elseif ( ( $_item->getStatusLabel() == ucfirst( $statusFailed ) ) ||
367
- ( $_item->getStatusLabel() == ucfirst( $statusFraud ) ) ) {
368
  $undoCancel = true;
369
  }
370
  }
371
 
372
- // increase inventory if the payment failed
373
  if ( $canUpdate && ! $complete && $canceled && $order->getStatus() != Mage_Sales_Model_Order::STATE_CANCELED ) {
 
374
  foreach ( $order->getAllItems() as $_item ) {
375
- $qty = $_item->getQtyOrdered();
376
  $stockItem = Mage::getModel( 'cataloginventory/stock_item' )->loadByProduct( $_item->getProductId() );
377
- $stockItemId = $stockItem->getId();
378
- $stock = array();
379
  // then set product's stock data to update
380
- if ( ! $stockItemId ) {
381
- // FIXME: This cant work!
382
  $stockItem->setData( 'product_id', $_item->getProductId() );
383
  $stockItem->setData( 'stock_id', 1 );
384
- } else {
385
- $stock = $stockItem->getData();
386
  }
387
 
388
- $oldQty = $stockItem->getData( 'qty' );
389
- $stockItem->setData( 'qty', $oldQty + $qty );
390
  // call save() method to save your product with updated data
391
  try {
392
  $stockItem->save();
393
- // $product->save($p);
394
- } catch ( Exception $ex ) {
395
- // handle the error here!!
396
- }
397
  }
398
  }
399
 
@@ -423,6 +476,31 @@ class Cardgate_Cgp_Model_Base extends Varien_Object
423
 
424
  // Update the status if changed
425
  if ( $canUpdate && ( ( $newState != $order->getState() ) || ( $newStatus != $order->getStatus() ) ) ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
426
  // Create an invoice when the payment is completed
427
  if ( $complete && ! $canceled && $autocreateInvoice ) {
428
  $invoiceCreated = $this->createInvoice( $order );
@@ -438,14 +516,6 @@ class Cardgate_Cgp_Model_Base extends Varien_Object
438
  }
439
  }
440
 
441
- // Set order state and status
442
- if ( $newState == $order->getState() ) {
443
- $order->addStatusToHistory( $newStatus, $statusMessage );
444
- } else {
445
- $order->setState( $newState, $newStatus, $statusMessage );
446
- }
447
- $this->log( "Changing state to '$newState' from '".$order->getState()."' with message '$statusMessage' for order ID: $id." );
448
-
449
  // Send new order e-mail
450
  if ( $complete && ! $canceled && ! $order->getEmailSent() ) {
451
  $order->sendNewOrderEmail();
6
  * @category Mage
7
  * @package Cardgate_Cgp
8
  */
9
+ class Cardgate_Cgp_Model_Base extends Varien_Object {
 
10
 
11
  protected $_callback;
12
 
19
  /**
20
  * Initialize basic cgp settings
21
  */
22
+ public function _construct () {
 
23
  $this->_config = Mage::getStoreConfig( 'cgp/settings' );
24
  }
25
 
29
  * @param string $field
30
  * @return mixed
31
  */
32
+ public function getConfigData ( $field ) {
 
33
  if ( isset( $this->_config[$field] ) ) {
34
  return $this->_config[$field];
35
  } else {
43
  * @param array $data
44
  * @return Cardgate_Cgp_Model_Base
45
  */
46
+ public function setCallbackData ( $data ) {
 
47
  $this->_callback = $data;
48
  return $this;
49
  }
54
  * @param string $field
55
  * @return string
56
  */
57
+ public function getCallbackData ( $field = null ) {
 
58
  if ( $field === null ) {
59
  return $this->_callback;
60
  } else {
67
  *
68
  * @return bool
69
  */
70
+ public function isDebug () {
 
71
  return $this->getConfigData( 'debug' );
72
  }
73
 
76
  *
77
  * @return bool
78
  */
79
+ public function isTest () {
 
80
  return ( $this->getConfigData( 'test_mode' ) == "test" );
81
  }
82
 
86
  * @param string $msg
87
  * @return void
88
  */
89
+ public function log ( $msg ) {
 
90
  if ( $this->getConfigData( 'debug' ) ) {
91
  Mage::log( $msg, null, $this->_logFileName );
92
  }
97
  *
98
  * @return Cardgate_Cgp_Model_Base
99
  */
100
+ public function lock ( $trxid = '' ) {
101
+ $lockKey = ( $trxid != '' ? $trxid : $this->getCallbackData( 'ref' ) );
102
  $varDir = Mage::getConfig()->getVarDir( 'locks' );
103
+ $lockFilename = $varDir . DS . 'cgp-' . $lockKey . '.lock';
104
  $fp = @fopen( $lockFilename, 'x' );
105
 
106
  if ( $fp ) {
118
  *
119
  * @return Cardgate_Cgp_Model_Base
120
  */
121
+ public function unlock ( $trxid = '' ) {
122
+ $lockKey = ( $trxid != '' ? $trxid : $this->getCallbackData( 'ref' ) );
123
  $this->_isLocked = false;
124
  $varDir = Mage::getConfig()->getVarDir( 'locks' );
125
+ $lockFilename = $varDir . DS . 'cgp-' . $lockKey . '.lock';
126
  unlink( $lockFilename );
127
 
128
  return $this;
129
  }
130
 
131
+ public function isLocked ( $trxid = '' ) {
132
+ if ( $this->_isLocked ) {
133
+ return true;
134
+ }
135
+
136
+ $lockKey = ( $trxid != '' ? $trxid : $this->getCallbackData( 'ref' ) );
137
+ $varDir = Mage::getConfig()->getVarDir( 'locks' );
138
+ $lockFilename = $varDir . DS . 'cgp-' . $lockKey . '.lock';
139
+ return file_exists( $lockFilename );
140
+ }
141
+
142
  /**
143
  * Create and mail invoice
144
  *
145
  * @param Mage_Sales_Model_Order $order
146
  * @return boolean
147
  */
148
+ protected function createInvoice ( Mage_Sales_Model_Order $order ) {
 
149
  if ( $order->canInvoice() && ! $order->hasInvoices() ) {
150
  $invoice = $order->prepareInvoice();
151
  $invoice->register();
167
  }
168
 
169
  $statusMessage = $mail_invoice ? "Invoice # %s created and send to customer." : "Invoice # %s created.";
170
+ $order->addStatusToHistory( $order->getStatus(), Mage::helper( "cgp" )->__( $statusMessage, $invoice->getIncrementId(), $mail_invoice ) );
 
171
 
172
  return true;
173
  }
181
  * @param Mage_Sales_Model_Order $order
182
  * @return void
183
  */
184
+ protected function eventInvoicingFailed ( $order ) {
 
185
  $storeId = $order->getStore()->getId();
186
 
187
  $ident = Mage::getStoreConfig( 'cgp/settings/notification_email' );
195
  $mail->addTo( $recipient_email, $recipient_name );
196
  $mail->setSubject( Mage::helper( "cgp" )->__( 'Automatic invoice creation failed' ) );
197
  $mail->setBodyText(
198
+ Mage::helper( "cgp" )->__( 'Magento was unable to create an invoice for Order # %s after a successful payment via CardGate (transaction # %s)', $order->getIncrementId(), $this->getCallbackData( 'transaction_id' ) ) );
199
+ $mail->setBodyHtml(
200
+ Mage::helper( "cgp" )->__( 'Magento was unable to create an invoice for <b>Order # %s</b> after a successful payment via CardGate <b>(transaction # %s)</b>', $order->getIncrementId(),
201
+ $this->getCallbackData( 'transaction_id' ) ) );
202
+ $mail->send();
203
+ }
204
+
205
+ protected function eventRefundFailed ( $order ) {
206
+ $storeId = $order->getStore()->getId();
207
+
208
+ $ident = Mage::getStoreConfig( 'cgp/settings/notification_email' );
209
+ $sender_email = Mage::getStoreConfig( 'trans_email/ident_general/email', $storeId );
210
+ $sender_name = Mage::getStoreConfig( 'trans_email/ident_general/name', $storeId );
211
+ $recipient_email = Mage::getStoreConfig( 'trans_email/ident_' . $ident . '/email', $storeId );
212
+ $recipient_name = Mage::getStoreConfig( 'trans_email/ident_' . $ident . '/name', $storeId );
213
+
214
+ $mail = new Zend_Mail();
215
+ $mail->setFrom( $sender_email, $sender_name );
216
+ $mail->addTo( $recipient_email, $recipient_name );
217
+ $mail->setSubject( Mage::helper( "cgp" )->__( 'CardGate refund failed' ) );
218
+ $mail->setBodyText(
219
+ Mage::helper( "cgp" )->__( 'CardGate was unable to succesfully complete a refund for Order # %s (transaction # %s). Please visit https://my.cardgate.com/ for more details.', $order->getIncrementId(),
220
+ $this->getCallbackData( 'transaction_id' ) ) );
221
  $mail->setBodyHtml(
222
  Mage::helper( "cgp" )->__(
223
+ "CardGate was unable to succesfully complete a refund for <b>Order # %s</b> <b>(transaction # %s)</b>. Please visit <a href='https://my.cardgate.com/'>https://my.cardgate.com/</a> for more details.",
224
  $order->getIncrementId(), $this->getCallbackData( 'transaction_id' ) ) );
225
  $mail->send();
226
  }
231
  * @param Mage_Sales_Model_Order $order
232
  * @return boolean
233
  */
234
+ protected function validateAmount ( Mage_Sales_Model_Order $order ) {
 
235
  $amountInCents = ( int ) sprintf( '%.0f', $order->getGrandTotal() * 100 );
236
  $callbackAmount = ( int ) $this->getCallbackData( 'amount' );
237
 
238
  if ( ( $amountInCents != $callbackAmount ) and ( abs( $callbackAmount - $amountInCents ) > 1 ) ) {
239
+ $this->log( 'OrderID: ' . $order->getId() . ' do not match amounts. Sent ' . $amountInCents . ', received: ' . $callbackAmount );
240
+ $statusMessage = Mage::helper( "cgp" )->__( "Hacker attempt: Order total amount does not match CardGate's gross total amount!" );
 
 
 
241
  $order->addStatusToHistory( $order->getStatus(), $statusMessage );
242
  $order->save();
243
  return false;
246
  return true;
247
  }
248
 
249
+ public function processRefundCallback () {
250
+ $id = $this->getCallbackData( 'ref' );
251
+ /**
252
+ *
253
+ * @var Mage_Sales_Model_Order $order
254
+ */
255
+ $order = Mage::getModel( 'sales/order' );
256
+ $order->loadByIncrementId( $id );
257
+
258
+ // Log callback data
259
+ $this->log( 'Receiving refund-callback data:' );
260
+ $this->log( $this->getCallbackData() );
261
+
262
+ switch ( $this->getCallbackData( 'status_id' ) ) {
263
+ case "0":
264
+ $statusMessage = sprintf( Mage::helper( 'cgp' )->__( 'CardGate refund %s successfully authorised. Amount: %s' ), $this->getCallbackData( 'transaction_id' ), number_format( $this->getCallbackData( 'amount' ) / 100, 2 ) );
265
+ break;
266
+ case "300":
267
+ $statusMessage = sprintf( Mage::helper( 'cgp' )->__( 'CardGate refund %s failed. Amount: %s' ), $this->getCallbackData( 'transaction_id' ), number_format( $this->getCallbackData( 'amount' ) / 100, 2 ) );
268
+ $this->eventRefundFailed( $order );
269
+ break;
270
+ case "400":
271
+ $statusMessage = sprintf( Mage::helper( 'cgp' )->__( 'CardGate refund %s complete. Amount: %s' ), $this->getCallbackData( 'transaction_id' ), number_format( $this->getCallbackData( 'amount' ) / 100, 2 ) );
272
+ break;
273
+ default:
274
+ $msg = 'Refund-status not recognised: ' . $this->getCallbackData( 'status' );
275
+ $this->log( $msg );
276
+ die( $msg );
277
+ }
278
+
279
+ $order->addStatusHistoryComment( $statusMessage );
280
+ $order->save();
281
+ }
282
+
283
  /**
284
  * Process callback for all transactions
285
  *
286
  * @return void
287
  */
288
+ public function processCallback () {
 
289
  $id = $this->getCallbackData( 'ref' );
290
+ /**
291
+ *
292
+ * @var Mage_Sales_Model_Order $order
293
+ */
294
  $order = Mage::getModel( 'sales/order' );
295
  $order->loadByIncrementId( $id );
296
 
304
  exit();
305
  }
306
 
307
+ $transactionid = $this->getCallbackData( 'transaction_id' );
308
+
309
+ $payment = $order->getPayment();
310
+ $payment->setTransactionId( $transactionid );
311
+
312
+ $info = $payment->getMethodInstance()->getInfoInstance();
313
+ $info->setAdditionalInformation( 'cardgate_transaction_id', $transactionid );
314
+
315
+ // $this->log( $payment->getData() );
316
+
317
  $statusWaitconf = $this->getConfigData( "waitconf_status" );
318
  $statusPending = $this->getConfigData( "pending_status" );
319
  $statusComplete = $this->getConfigData( "complete_status" );
328
  $newStatus = true;
329
  $statusMessage = '';
330
 
331
+ $this->log( "Got: {$statusPending}/{$statusComplete}/{$statusFailed}/{$statusFraud}/{$autocreateInvoice}/{$evInvoicingFailed} : " . $this->getCallbackData( 'status_id' ) );
 
 
332
 
333
  switch ( $this->getCallbackData( 'status_id' ) ) {
334
  case "0":
379
  $newState = Mage_Sales_Model_Order::STATE_PENDING_PAYMENT;
380
  $newStatus = $statusPending;
381
  $statusMessage = Mage::helper( 'cgp' )->__( 'Transaction pending: Waiting for customer action.' );
382
+ $order->sendNewOrderEmail();
383
+ $order->setIsCustomerNotified( true );
384
+ $order->save();
385
  break;
386
  case "701":
387
  // Direct debit pending status
389
  $newState = Mage_Sales_Model_Order::STATE_PENDING_PAYMENT;
390
  $newStatus = $statusWaitconf;
391
  $statusMessage = Mage::helper( 'cgp' )->__( 'Transaction pending: Waiting for confirmation.' );
392
+ $order->sendNewOrderEmail();
393
+ $order->setIsCustomerNotified( true );
394
+ $order->save();
395
  break;
396
  default:
397
  $msg = 'Status not recognised: ' . $this->getCallbackData( 'status' );
400
  }
401
 
402
  // Additional logging for direct-debit
403
+ if ( $this->getCallbackData( 'recipient_name' ) && $this->getCallbackData( 'recipient_iban' ) && $this->getCallbackData( 'recipient_bic' ) && $this->getCallbackData( 'recipient_reference' ) ) {
404
+ $statusMessage .= "<br/>\n" . Mage::helper( 'cgp' )->__( 'Additional information' ) . " : " . "<br/>\n" . Mage::helper( 'cgp' )->__( 'Benificiary' ) . " : " . $this->getCallbackData( 'recipient_name' ) . "<br/>\n" .
405
+ Mage::helper( 'cgp' )->__( 'Benificiary IBAN' ) . " : " . $this->getCallbackData( 'recipient_iban' ) . "<br/>\n" . Mage::helper( 'cgp' )->__( 'Benificiary BIC' ) . " : " . $this->getCallbackData( 'recipient_bic' ) .
406
+ "<br/>\n" . Mage::helper( 'cgp' )->__( 'Reference' ) . " : " . $this->getCallbackData( 'recipient_reference' );
407
+
408
+ $info->setAdditionalInformation( 'recipient_name', $this->getCallbackData( 'recipient_name' ) );
409
+ $info->setAdditionalInformation( 'recipient_iban', $this->getCallbackData( 'recipient_iban' ) );
410
+ $info->setAdditionalInformation( 'recipient_bic', $this->getCallbackData( 'recipient_bic' ) );
411
+ $info->setAdditionalInformation( 'recipient_reference', $this->getCallbackData( 'recipient_reference' ) );
412
+
413
+ }
414
+
415
+ $info->save();
416
 
417
  // Update only certain states
418
  $canUpdate = false;
419
  $undoCancel = false;
420
+ if ( $order->getState() == Mage_Sales_Model_Order::STATE_NEW || $order->getState() == Mage_Sales_Model_Order::STATE_PENDING_PAYMENT || $order->getState() == Mage_Sales_Model_Order::STATE_CANCELED ) {
 
 
421
  $canUpdate = true;
422
  }
423
 
426
  if ( $_item->getStatusLabel() == ucfirst( $statusComplete ) ) {
427
  $canUpdate = false;
428
  // Uncancel an order if the payment is considered complete
429
+ } elseif ( ( $_item->getStatusLabel() == ucfirst( $statusFailed ) ) || ( $_item->getStatusLabel() == ucfirst( $statusFraud ) ) ) {
 
430
  $undoCancel = true;
431
  }
432
  }
433
 
434
+ // Unclaim inventory if the payment failed
435
  if ( $canUpdate && ! $complete && $canceled && $order->getStatus() != Mage_Sales_Model_Order::STATE_CANCELED ) {
436
+ $statusMessage .= "<br/>\n" . Mage::helper( 'cgp' )->__( "Unclaimed inventory because order changed to 'Canceled' state." );
437
  foreach ( $order->getAllItems() as $_item ) {
 
438
  $stockItem = Mage::getModel( 'cataloginventory/stock_item' )->loadByProduct( $_item->getProductId() );
 
 
439
  // then set product's stock data to update
440
+ if ( ! $stockItem->getId() ) {
 
441
  $stockItem->setData( 'product_id', $_item->getProductId() );
442
  $stockItem->setData( 'stock_id', 1 );
 
 
443
  }
444
 
445
+ $stockItem->setData( 'qty', $stockItem->getData( 'qty' ) + $_item->getQtyOrdered() );
 
446
  // call save() method to save your product with updated data
447
  try {
448
  $stockItem->save();
449
+ } catch ( Exception $ex ) { }
 
 
 
450
  }
451
  }
452
 
476
 
477
  // Update the status if changed
478
  if ( $canUpdate && ( ( $newState != $order->getState() ) || ( $newStatus != $order->getStatus() ) ) ) {
479
+
480
+ // Reclaim inventory
481
+ if ( $order->getState() == Mage_Sales_Model_Order::STATE_CANCELED && $newState == Mage_Sales_Model_Order::STATE_PROCESSING ) {
482
+ $statusMessage .= "<br/>\n" . Mage::helper( 'cgp' )->__( "Reclaimed inventory because order changed from 'Canceled' to 'Processing' state." );
483
+ foreach ( $order->getAllItems() as $_item ) {
484
+ $stockItem = Mage::getModel( 'cataloginventory/stock_item' )->loadByProduct( $_item->getProductId() );
485
+ if ( ! $stockItem->getId() ) {
486
+ $stockItem->setData( 'product_id', $_item->getProductId() );
487
+ $stockItem->setData( 'stock_id', 1 );
488
+ }
489
+ $stockItem->setData( 'qty', $stockItem->getData( 'qty' ) - $_item->getQtyOrdered() );
490
+ try {
491
+ $stockItem->save();
492
+ } catch ( Exception $ex ) {}
493
+ }
494
+ }
495
+
496
+ // Set order state and status
497
+ if ( $newState == $order->getState() ) {
498
+ $order->addStatusToHistory( $newStatus, $statusMessage );
499
+ } else {
500
+ $order->setState( $newState, $newStatus, $statusMessage );
501
+ }
502
+ $this->log( "Changing state to '$newState' from '" . $order->getState() . "' with message '$statusMessage' for order ID: $id." );
503
+
504
  // Create an invoice when the payment is completed
505
  if ( $complete && ! $canceled && $autocreateInvoice ) {
506
  $invoiceCreated = $this->createInvoice( $order );
516
  }
517
  }
518
 
 
 
 
 
 
 
 
 
519
  // Send new order e-mail
520
  if ( $complete && ! $canceled && ! $order->getEmailSent() ) {
521
  $order->sendNewOrderEmail();
app/code/local/Cardgate/Cgp/Model/Gateway/Abstract.php CHANGED
@@ -6,8 +6,7 @@
6
  * @category Mage
7
  * @package Cardgate_Cgp
8
  */
9
- abstract class Cardgate_Cgp_Model_Gateway_Abstract extends Mage_Payment_Model_Method_Abstract
10
- {
11
 
12
  /**
13
  * config root (cgp or payment)
@@ -33,51 +32,68 @@ abstract class Cardgate_Cgp_Model_Gateway_Abstract extends Mage_Payment_Model_Me
33
  /**
34
  * Paymentgateway URL
35
  *
36
- * @var string
37
  */
38
  protected $_url = 'https://secure.curopayments.net/gateway/cardgate/';
 
 
 
 
 
39
  protected $_urlStaging = 'https://secure-staging.curopayments.net/gateway/cardgate/';
40
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  /**
42
  * supported countries
43
- *
44
  * @var array
45
  */
46
- protected $_supportedCurrencies = array(
47
- 'EUR',
48
- 'USD',
49
- 'JPY',
50
- 'BGN',
51
- 'CZK',
52
- 'DKK',
53
- 'GBP',
54
- 'HUF',
55
- 'LTL',
56
- 'LVL',
57
- 'PLN',
58
- 'RON',
59
- 'SEK',
60
- 'CHF',
61
- 'NOK',
62
- 'HRK',
63
- 'RUB',
64
- 'TRY',
65
- 'AUD',
66
- 'BRL',
67
- 'CAD',
68
- 'CNY',
69
- 'HKD',
70
- 'IDR',
71
- 'ILS',
72
- 'INR',
73
- 'KRW',
74
- 'MXN',
75
- 'MYR',
76
- 'NZD',
77
- 'PHP',
78
- 'SGD',
79
- 'THB',
80
- 'ZAR'
81
  );
82
 
83
  /**
@@ -91,34 +107,66 @@ abstract class Cardgate_Cgp_Model_Gateway_Abstract extends Mage_Payment_Model_Me
91
 
92
  protected $_canCapture = true;
93
 
94
- protected $_canUseInternal = false;
95
 
96
  protected $_canUseCheckout = true;
97
 
98
  protected $_canUseForMultishipping = false;
99
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
100
  /**
101
  * Return Gateway Url
102
  *
103
  * @return string
104
  */
105
- public function getGatewayUrl ()
106
- {
107
  if ( ! empty( $_SERVER['CGP_GATEWAY_URL'] ) ) {
108
  return $_SERVER['CGP_GATEWAY_URL'];
109
  } else {
110
- $base = Mage::getSingleton( 'cgp/base' );
111
  return $base->isTest() ? $this->_urlStaging : $this->_url;
112
  }
113
  }
114
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  /**
116
  * Get plugin version to send to gateway (debugging purposes)
117
  *
118
  * @return string
119
  */
120
- public function getPluginVersion ()
121
- {
122
  return ( string ) Mage::getConfig()->getNode( 'modules/Cardgate_Cgp/version' );
123
  }
124
 
@@ -127,8 +175,7 @@ abstract class Cardgate_Cgp_Model_Gateway_Abstract extends Mage_Payment_Model_Me
127
  *
128
  * @return Mage_Checkout_Model_Session
129
  */
130
- public function getCheckout ()
131
- {
132
  return Mage::getSingleton( 'checkout/session' );
133
  }
134
 
@@ -137,8 +184,7 @@ abstract class Cardgate_Cgp_Model_Gateway_Abstract extends Mage_Payment_Model_Me
137
  *
138
  * @return Mage_Sales_Model_Quote
139
  */
140
- public function getQuote ()
141
- {
142
  return $this->getCheckout()->getQuote();
143
  }
144
 
@@ -147,8 +193,7 @@ abstract class Cardgate_Cgp_Model_Gateway_Abstract extends Mage_Payment_Model_Me
147
  *
148
  * @return Mage_Sales_Model_Order
149
  */
150
- public function getOrder ()
151
- {
152
  $order = Mage::getModel( 'sales/order' );
153
  $order->loadByIncrementId( $this->getCheckout()
154
  ->getLastRealOrderId() );
@@ -161,8 +206,7 @@ abstract class Cardgate_Cgp_Model_Gateway_Abstract extends Mage_Payment_Model_Me
161
  * @param Mage_Sales_Model_Order $order
162
  * @return void
163
  */
164
- public function setSortOrder ( $order )
165
- {
166
  $this->sort_order = $this->getConfigData( 'sort_order' );
167
  }
168
 
@@ -172,13 +216,12 @@ abstract class Cardgate_Cgp_Model_Gateway_Abstract extends Mage_Payment_Model_Me
172
  * @param string $url
173
  * @return string
174
  */
175
- function getModelUrl ( $url )
176
- {
177
  if ( ! empty( $this->_model ) ) {
178
  $url .= '/model/' . $this->_model;
179
  }
180
- return Mage::getUrl( $url, array(
181
- '_secure' => true
182
  ) );
183
  }
184
 
@@ -187,8 +230,7 @@ abstract class Cardgate_Cgp_Model_Gateway_Abstract extends Mage_Payment_Model_Me
187
  *
188
  * @return string
189
  */
190
- public function getOrderPlaceRedirectUrl ()
191
- {
192
  $_SESSION['cgp_formdata'] = $_POST;
193
  return $this->getModelUrl( 'cgp/standard/redirect' );
194
  }
@@ -200,16 +242,17 @@ abstract class Cardgate_Cgp_Model_Gateway_Abstract extends Mage_Payment_Model_Me
200
  * @param mixed $store
201
  * @return mixed
202
  */
203
- public function getConfigData ( $field, $storeId = null )
204
- {
205
  if ( $storeId === null ) {
206
  $storeId = $this->getStore();
207
  }
208
 
209
  $configSettings = Mage::getStoreConfig( $this->_module . '/settings', $storeId );
210
- if ( ! is_array( $configSettings ) ) $configSettings = array();
 
211
  $configGateway = Mage::getStoreConfig( $this->_module . '/' . $this->_code, $storeId );
212
- if ( ! is_array( $configGateway ) ) $configGateway = array();
 
213
  $config = array_merge( $configSettings, $configGateway );
214
 
215
  return @$config[$field];
@@ -220,8 +263,7 @@ abstract class Cardgate_Cgp_Model_Gateway_Abstract extends Mage_Payment_Model_Me
220
  *
221
  * @return Cardgate_Cgp_Model_Abstract
222
  */
223
- public function validate ()
224
- {
225
  parent::validate();
226
  $base = Mage::getSingleton( 'cgp/base' );
227
 
@@ -231,9 +273,7 @@ abstract class Cardgate_Cgp_Model_Gateway_Abstract extends Mage_Payment_Model_Me
231
  }
232
  if ( ! in_array( $currency_code, $this->_supportedCurrencies ) ) {
233
  $base->log( 'Unacceptable currency code (' . $currency_code . ').' );
234
- Mage::throwException(
235
- Mage::helper( 'cgp' )->__( 'Selected currency code ' ) . $currency_code .
236
- Mage::helper( 'cgp' )->__( ' is not compatible with Card Gate Plus' ) );
237
  }
238
 
239
  return $this;
@@ -245,13 +285,12 @@ abstract class Cardgate_Cgp_Model_Gateway_Abstract extends Mage_Payment_Model_Me
245
  * @param Mage_Sales_Model_Order $order
246
  * @return void
247
  */
248
- protected function initiateTransactionStatus ( $order )
249
- {
250
  // Change order status
251
  $newState = Mage_Sales_Model_Order::STATE_PENDING_PAYMENT;
252
  $newStatus = $this->getConfigData( 'initialized_status' );
253
  $statusMessage = Mage::helper( 'cgp' )->__( 'Transaction started, waiting for payment.' );
254
- $statusMessage.= "<br/>\n" . Mage::helper( 'cgp' )->__( 'Paymentmethod used' ) . ' : ' . $order->getPayment()->getMethod();
255
  if ( $order->getState() != Mage_Sales_Model_Order::STATE_PROCESSING ) {
256
  $order->setState( $newState, $newStatus, $statusMessage );
257
  $order->save();
@@ -263,8 +302,7 @@ abstract class Cardgate_Cgp_Model_Gateway_Abstract extends Mage_Payment_Model_Me
263
  *
264
  * @return array
265
  */
266
- public function getCheckoutFormFields ()
267
- {
268
  $base = Mage::getSingleton( 'cgp/base' );
269
  $extra_data = $_SESSION['cgp_formdata']['payment']['cgp'];
270
 
@@ -282,142 +320,144 @@ abstract class Cardgate_Cgp_Model_Gateway_Abstract extends Mage_Payment_Model_Me
282
  $cartitems = array();
283
 
284
  foreach ( $order->getAllItems() as $itemId => $item ) {
285
- if ( $item->getQtyToInvoice() > 0 ) {
286
- $cartitems[] = array(
287
- 'quantity' => $item->getQtyToInvoice(),
288
- 'sku' => $item->getSku(),
289
- 'name' => $item->getName(),
290
- 'price' => sprintf( '%01.2f', ( float ) $item->getPriceInclTax() ),
291
- 'vat_amount' => sprintf( '%01.2f', ( float ) $item->getTaxAmount() ),
292
- 'vat' => ( float ) $item->getData( 'tax_percent' ),
293
- 'vat_inc' => 1,
294
- 'type' => 1
295
- );
296
- }
297
  }
298
 
299
  if ( $order->getDiscountAmount() < 0 ) {
300
- $amount = $order->getDiscountAmount();
301
- $applyAfter = Mage::helper( 'tax' )->applyTaxAfterDiscount( $order->getStoreId() );
302
- $priceIncludesTax = Mage::helper( 'tax' )->priceIncludesTax( $order->getStoreId() );
303
-
304
- if ( $applyAfter == true && $priceIncludesTax == false ) {
305
- // With this setting active the discount will not have the correct value.
306
- // We need to take each respective products rate and calculate a new value.
307
- $amount = 0;
308
- foreach ( $order->getAllVisibleItems() as $product ) {
309
- $rate = $product->getTaxPercent();
310
- $newAmount = $product->getDiscountAmount() * ( ( $rate / 100 ) + 1 );
311
- $amount -= $newAmount;
312
- }
313
- // If the discount also extends to shipping
314
- $shippingDiscount = $order->getShippingDiscountAmount();
315
- if ( $shippingDiscount ) {
316
- $taxClass = Mage::getStoreConfig( 'tax/classes/shipping_tax_class' );
317
- $rate = $this->getTaxRate( $taxClass );
318
- $newAmount = $shippingDiscount * ( ( $rate / 100 ) + 1 );
319
- $amount -= $newAmount;
320
- }
321
- }
322
-
323
- $cartitems[] = array(
324
- 'quantity' => '1',
325
- 'sku' => 'cg-discount',
326
- 'name' => 'Discount',
327
- 'price' => sprintf( '%01.2f', round( $amount, 2 ) ),
328
- 'vat_amount' => 0,
329
- 'vat' => 0,
330
- 'vat_inc' => 1,
331
- 'type' => 4
332
- );
 
 
333
  }
334
 
335
  // add shipping
336
  if ( $order->getShippingAmount() > 0 ) {
337
-
338
- $tax_info = $order->getFullTaxInfo();
339
-
340
- $flags = 8;
341
- if ( ! isset( $tax_info[0]['percent'] ) ) {
342
- $tax_rate = 0;
343
- } else {
344
- $tax_rate = $tax_info[0]['percent'];
345
- $flags += 32;
346
- }
347
- $tax_rate = ( isset( $tax_info[0]['percent'] ) ? $tax_info[0]['percent'] : 0 );
348
- $cartitems[] = array(
349
- 'quantity' => '1',
350
- 'sku' => 'cg-shipping',
351
- 'name' => 'Shipping fee',
352
- 'price' => sprintf( '%01.2f', $order->getShippingInclTax() ),
353
- 'vat_amount' => sprintf( '%01.2f', $order->getShippingTaxAmount() ),
354
- 'vat' => $tax_rate,
355
- 'vat_inc' => 1,
356
- 'type' => 2
357
- );
358
  }
359
 
360
  // add invoice fee
361
- if ( $order->getPayment()->getAdditionalInformation('invoice_fee') > 0 ) {
362
-
363
- $tax_rate = $order->getPayment()->getAdditionalInformation('invoice_fee_rate');
364
- $cartitems[] = array(
365
- 'quantity' => '1',
366
- 'sku' => 'cg-invoice',
367
- 'name' => 'Invoice fee',
368
- 'price' => sprintf( '%01.2f', $order->getPayment()->getAdditionalInformation('invoice_fee') ),
369
- 'vat_amount' => ( isset( $tax_info[0]['percent'] ) ? round( $order->getPayment()->getAdditionalInformation('invoice_fee') * ( $tax_rate / 100 ), 2 ) : 0 ),
370
- 'vat' => $tax_rate,
371
- 'vat_inc' => 1,
372
- 'type' => 5
373
- );
374
  }
375
 
376
  // add Magestore affiliateplus discount
377
- if ( !is_null($order->getAffiliateplusDiscount()) && $order->getAffiliateplusDiscount() != 0 ) {
378
  $cartitems[] = array(
379
- 'quantity' => '1',
380
- 'sku' => 'cg-affdiscount',
381
- 'name' => 'Discount',
382
- 'price' => sprintf( '%01.2f', $order->getAffiliateplusDiscount() ),
383
- 'vat_amount' => 0,
384
- 'vat' => 0,
385
- 'vat_inc' => 1,
386
- 'type' => 4
387
- );
388
  }
389
 
390
  // add ET Payment Extra Charge
391
- if ( !is_null($order->getEtPaymentExtraCharge()) && $order->getEtPaymentExtraCharge() != 0 ) {
392
  $cartitems[] = array(
393
- 'quantity' => '1',
394
- 'sku' => 'cg-paymentcharge',
395
- 'name' => 'ET Payment fee',
396
- 'price' => sprintf( '%01.2f', $order->getEtPaymentExtraCharge() ),
397
- 'vat_amount' => sprintf( '%01.2f', $order->getEtPaymentExtraCharge()-$order->getEtPaymentExtraChargeExcludingTax() ),
398
- //'vat' => 0,
399
- 'vat_inc' => 1,
400
- 'type' => 5
401
- );
402
  }
403
 
404
  // failsafe
405
  $cartpricetotal = $cartvattotal = 0;
406
- foreach ($cartitems as $cartitem) {
407
- $cartpricetotal+=ceil($cartitem['price']*100);
408
- $cartvattotal+=ceil($cartitem['vat_amount']*100);
409
  }
410
- if ($cartpricetotal != ceil( $order->getGrandTotal() * 100) || $cartvattotal != ceil( $order->getTaxAmount() * 100)) {
411
  $cartitems[] = array(
412
- 'quantity' => '1',
413
- 'sku' => 'cg-correction',
414
- 'name' => 'Correction',
415
- 'price' => sprintf( '%01.2f', (ceil($order->getGrandTotal()*100)/100) - ( $cartpricetotal/100 ) ),
416
- 'vat_amount' => sprintf( '%01.2f', (ceil($order->getTaxAmount()*100)/100) - ( $cartvattotal/100 ) ),
417
- //'vat' => 0,
418
- 'vat_inc' => 1,
419
- 'type' => 5
420
- );
421
  }
422
 
423
  $s_arr['cartitems'] = serialize( $cartitems );
@@ -471,8 +511,7 @@ abstract class Cardgate_Cgp_Model_Gateway_Abstract extends Mage_Payment_Model_Me
471
  if ( isset( $extra_data['klarna-personal-number'] ) ) {
472
  $s_arr['dob'] = $extra_data['klarna-personal-number'];
473
  } else {
474
- $s_arr['dob'] = $extra_data['klarna-dob_day'] . '-' . $extra_data['klarna-dob_month'] . '-' .
475
- $extra_data['klarna-dob_year'];
476
  $s_arr['gender'] = $extra_data['klarna-gender'];
477
  }
478
  $s_arr['language'] = $extra_data['klarna-language'];
@@ -487,8 +526,7 @@ abstract class Cardgate_Cgp_Model_Gateway_Abstract extends Mage_Payment_Model_Me
487
  if ( isset( $extra_data['klarna-account-personal-number'] ) ) {
488
  $s_arr['dob'] = $extra_data['klarna-account-personal-number'];
489
  } else {
490
- $s_arr['dob'] = $extra_data['klarna-account-dob_day'] . '-' . $extra_data['klarna-account-dob_month'] .
491
- '-' . $extra_data['klarna-account-dob_year'];
492
  $s_arr['gender'] = $extra_data['klarna-account-gender'];
493
  }
494
  $s_arr['language'] = $extra_data['klarna-account-language'];
@@ -510,12 +548,12 @@ abstract class Cardgate_Cgp_Model_Gateway_Abstract extends Mage_Payment_Model_Me
510
  case 'przelewy24':
511
  $s_arr['option'] = 'przelewy24';
512
  break;
513
-
514
  // Afterpay
515
  case 'afterpay':
516
  $s_arr['option'] = 'afterpay';
517
  break;
518
-
519
  // Bitcoin
520
  case 'bitcoin':
521
  $s_arr['option'] = 'bitcoin';
@@ -536,8 +574,7 @@ abstract class Cardgate_Cgp_Model_Gateway_Abstract extends Mage_Payment_Model_Me
536
  $s_arr['first_name'] = $customer->getFirstname();
537
  $s_arr['last_name'] = $customer->getLastname();
538
  $s_arr['email'] = $order->getCustomerEmail();
539
- $s_arr['address'] = $customer->getStreet( 1 ) .
540
- ( $customer->getStreet( 2 ) ? ', ' . $customer->getStreet( 2 ) : '' );
541
  $s_arr['city'] = $customer->getCity();
542
  $s_arr['country_code'] = $customer->getCountry();
543
  $s_arr['postal_code'] = $customer->getPostcode();
@@ -545,11 +582,11 @@ abstract class Cardgate_Cgp_Model_Gateway_Abstract extends Mage_Payment_Model_Me
545
  $s_arr['state'] = $customer->getRegionCode();
546
 
547
  if ( $this->getConfigData( 'use_backoffice_urls' ) == false ) {
548
- $s_arr['return_url'] = Mage::getUrl( 'cgp/standard/success/', array(
549
- '_secure' => true
550
  ) );
551
- $s_arr['return_url_failed'] = Mage::getUrl( 'cgp/standard/cancel/', array(
552
- '_secure' => true
553
  ) );
554
  }
555
 
@@ -565,13 +602,10 @@ abstract class Cardgate_Cgp_Model_Gateway_Abstract extends Mage_Payment_Model_Me
565
  $hash_prefix = '';
566
  }
567
 
568
- $s_arr['amount'] = sprintf( '%.0f', ceil( $order->getGrandTotal() * 100) );
569
  $s_arr['currency'] = $order->getOrderCurrencyCode();
570
- $s_arr['description'] = str_replace( '%id%', $order->getIncrementId(),
571
- $this->getConfigData( 'order_description' ) );
572
- $s_arr['hash'] = md5(
573
- $hash_prefix . $this->getConfigData( 'site_id' ) . $s_arr['amount'] . $s_arr['ref'] .
574
- $this->getConfigData( 'hash_key' ) );
575
 
576
  // Logging
577
  $base->log( 'Initiating a new transaction' );
@@ -582,4 +616,153 @@ abstract class Cardgate_Cgp_Model_Gateway_Abstract extends Mage_Payment_Model_Me
582
  $locale = Mage::app()->getLocale()->getLocaleCode();
583
  return $s_arr;
584
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
585
  }
6
  * @category Mage
7
  * @package Cardgate_Cgp
8
  */
9
+ abstract class Cardgate_Cgp_Model_Gateway_Abstract extends Mage_Payment_Model_Method_Abstract {
 
10
 
11
  /**
12
  * config root (cgp or payment)
32
  /**
33
  * Paymentgateway URL
34
  *
35
+ * @var string $_url
36
  */
37
  protected $_url = 'https://secure.curopayments.net/gateway/cardgate/';
38
+
39
+ /**
40
+ *
41
+ * @var string $_urlStaging
42
+ */
43
  protected $_urlStaging = 'https://secure-staging.curopayments.net/gateway/cardgate/';
44
 
45
+ /**
46
+ *
47
+ * @var string $_apiUrl
48
+ */
49
+ protected $_apiUrl = 'https://secure.curopayments.net/rest/v1/';
50
+
51
+ /**
52
+ *
53
+ * @var string $_apiUrlStaging
54
+ */
55
+ protected $_apiUrlStaging = 'https://secure-staging.curopayments.net/rest/v1/';
56
+
57
  /**
58
  * supported countries
59
+ *
60
  * @var array
61
  */
62
+ protected $_supportedCurrencies = array(
63
+ 'EUR',
64
+ 'USD',
65
+ 'JPY',
66
+ 'BGN',
67
+ 'CZK',
68
+ 'DKK',
69
+ 'GBP',
70
+ 'HUF',
71
+ 'LTL',
72
+ 'LVL',
73
+ 'PLN',
74
+ 'RON',
75
+ 'SEK',
76
+ 'CHF',
77
+ 'NOK',
78
+ 'HRK',
79
+ 'RUB',
80
+ 'TRY',
81
+ 'AUD',
82
+ 'BRL',
83
+ 'CAD',
84
+ 'CNY',
85
+ 'HKD',
86
+ 'IDR',
87
+ 'ILS',
88
+ 'INR',
89
+ 'KRW',
90
+ 'MXN',
91
+ 'MYR',
92
+ 'NZD',
93
+ 'PHP',
94
+ 'SGD',
95
+ 'THB',
96
+ 'ZAR'
97
  );
98
 
99
  /**
107
 
108
  protected $_canCapture = true;
109
 
110
+ protected $_canUseInternal = true;
111
 
112
  protected $_canUseCheckout = true;
113
 
114
  protected $_canUseForMultishipping = false;
115
 
116
+ protected $_canRefund = true;
117
+
118
+ protected $_canRefundInvoicePartial = true;
119
+
120
+ protected $_canVoid = true;
121
+
122
+ protected $_canCapturePartial = true;
123
+
124
+ public function __construct()
125
+ {
126
+ /**
127
+ * @var Cardgate_Cgp_Model_Base $base
128
+ */
129
+ $base = Mage::getSingleton( 'cgp/base' );
130
+ if ( empty( $base->getConfigData( 'api_key' ) ) || empty( $base->getConfigData( 'api_id' ) ) ) {
131
+ $this->_canRefund = false;
132
+ $this->_canRefundInvoicePartial = false;
133
+ }
134
+ }
135
+
136
  /**
137
  * Return Gateway Url
138
  *
139
  * @return string
140
  */
141
+ public function getGatewayUrl () {
 
142
  if ( ! empty( $_SERVER['CGP_GATEWAY_URL'] ) ) {
143
  return $_SERVER['CGP_GATEWAY_URL'];
144
  } else {
145
+ $base = Mage::getSingleton( 'cgp/base' );
146
  return $base->isTest() ? $this->_urlStaging : $this->_url;
147
  }
148
  }
149
 
150
+ /**
151
+ * Return API Url
152
+ *
153
+ * @return string
154
+ */
155
+ public function getAPIUrl () {
156
+ if ( ! empty( $_SERVER['CGP_API_URL'] ) ) {
157
+ return $_SERVER['CGP_API_URL'];
158
+ } else {
159
+ $base = Mage::getSingleton( 'cgp/base' );
160
+ return $base->isTest() ? $this->_apiUrlStaging : $this->_apiUrl;
161
+ }
162
+ }
163
+
164
  /**
165
  * Get plugin version to send to gateway (debugging purposes)
166
  *
167
  * @return string
168
  */
169
+ public function getPluginVersion () {
 
170
  return ( string ) Mage::getConfig()->getNode( 'modules/Cardgate_Cgp/version' );
171
  }
172
 
175
  *
176
  * @return Mage_Checkout_Model_Session
177
  */
178
+ public function getCheckout () {
 
179
  return Mage::getSingleton( 'checkout/session' );
180
  }
181
 
184
  *
185
  * @return Mage_Sales_Model_Quote
186
  */
187
+ public function getQuote () {
 
188
  return $this->getCheckout()->getQuote();
189
  }
190
 
193
  *
194
  * @return Mage_Sales_Model_Order
195
  */
196
+ public function getOrder () {
 
197
  $order = Mage::getModel( 'sales/order' );
198
  $order->loadByIncrementId( $this->getCheckout()
199
  ->getLastRealOrderId() );
206
  * @param Mage_Sales_Model_Order $order
207
  * @return void
208
  */
209
+ public function setSortOrder ( $order ) {
 
210
  $this->sort_order = $this->getConfigData( 'sort_order' );
211
  }
212
 
216
  * @param string $url
217
  * @return string
218
  */
219
+ function getModelUrl ( $url ) {
 
220
  if ( ! empty( $this->_model ) ) {
221
  $url .= '/model/' . $this->_model;
222
  }
223
+ return Mage::getUrl( $url, array(
224
+ '_secure' => true
225
  ) );
226
  }
227
 
230
  *
231
  * @return string
232
  */
233
+ public function getOrderPlaceRedirectUrl () {
 
234
  $_SESSION['cgp_formdata'] = $_POST;
235
  return $this->getModelUrl( 'cgp/standard/redirect' );
236
  }
242
  * @param mixed $store
243
  * @return mixed
244
  */
245
+ public function getConfigData ( $field, $storeId = null ) {
 
246
  if ( $storeId === null ) {
247
  $storeId = $this->getStore();
248
  }
249
 
250
  $configSettings = Mage::getStoreConfig( $this->_module . '/settings', $storeId );
251
+ if ( ! is_array( $configSettings ) )
252
+ $configSettings = array();
253
  $configGateway = Mage::getStoreConfig( $this->_module . '/' . $this->_code, $storeId );
254
+ if ( ! is_array( $configGateway ) )
255
+ $configGateway = array();
256
  $config = array_merge( $configSettings, $configGateway );
257
 
258
  return @$config[$field];
263
  *
264
  * @return Cardgate_Cgp_Model_Abstract
265
  */
266
+ public function validate () {
 
267
  parent::validate();
268
  $base = Mage::getSingleton( 'cgp/base' );
269
 
273
  }
274
  if ( ! in_array( $currency_code, $this->_supportedCurrencies ) ) {
275
  $base->log( 'Unacceptable currency code (' . $currency_code . ').' );
276
+ Mage::throwException( Mage::helper( 'cgp' )->__( 'Selected currency code "%s" is not compatible with CardGate', $currency_code ) );
 
 
277
  }
278
 
279
  return $this;
285
  * @param Mage_Sales_Model_Order $order
286
  * @return void
287
  */
288
+ protected function initiateTransactionStatus ( $order ) {
 
289
  // Change order status
290
  $newState = Mage_Sales_Model_Order::STATE_PENDING_PAYMENT;
291
  $newStatus = $this->getConfigData( 'initialized_status' );
292
  $statusMessage = Mage::helper( 'cgp' )->__( 'Transaction started, waiting for payment.' );
293
+ $statusMessage .= "<br/>\n" . Mage::helper( 'cgp' )->__( 'Paymentmethod used' ) . ' : ' . $order->getPayment()->getMethod();
294
  if ( $order->getState() != Mage_Sales_Model_Order::STATE_PROCESSING ) {
295
  $order->setState( $newState, $newStatus, $statusMessage );
296
  $order->save();
302
  *
303
  * @return array
304
  */
305
+ public function getCheckoutFormFields () {
 
306
  $base = Mage::getSingleton( 'cgp/base' );
307
  $extra_data = $_SESSION['cgp_formdata']['payment']['cgp'];
308
 
320
  $cartitems = array();
321
 
322
  foreach ( $order->getAllItems() as $itemId => $item ) {
323
+ if ( $item->getQtyToInvoice() > 0 ) {
324
+ $cartitems[] = array(
325
+ 'quantity' => $item->getQtyToInvoice(),
326
+ 'sku' => $item->getSku(),
327
+ 'name' => $item->getName(),
328
+ 'price' => sprintf( '%01.2f', ( float ) $item->getPriceInclTax() ),
329
+ 'vat_amount' => sprintf( '%01.2f', ( float ) $item->getTaxAmount() ),
330
+ 'vat' => ( float ) $item->getData( 'tax_percent' ),
331
+ 'vat_inc' => 1,
332
+ 'type' => 1
333
+ );
334
+ }
335
  }
336
 
337
  if ( $order->getDiscountAmount() < 0 ) {
338
+ $amount = $order->getDiscountAmount();
339
+ $applyAfter = Mage::helper( 'tax' )->applyTaxAfterDiscount( $order->getStoreId() );
340
+ $priceIncludesTax = Mage::helper( 'tax' )->priceIncludesTax( $order->getStoreId() );
341
+
342
+ if ( $applyAfter == true && $priceIncludesTax == false ) {
343
+ // With this setting active the discount will not have the
344
+ // correct value.
345
+ // We need to take each respective products rate and calculate a
346
+ // new value.
347
+ $amount = 0;
348
+ foreach ( $order->getAllVisibleItems() as $product ) {
349
+ $rate = $product->getTaxPercent();
350
+ $newAmount = $product->getDiscountAmount() * ( ( $rate / 100 ) + 1 );
351
+ $amount -= $newAmount;
352
+ }
353
+ // If the discount also extends to shipping
354
+ $shippingDiscount = $order->getShippingDiscountAmount();
355
+ if ( $shippingDiscount ) {
356
+ $taxClass = Mage::getStoreConfig( 'tax/classes/shipping_tax_class' );
357
+ $rate = $this->getTaxRate( $taxClass );
358
+ $newAmount = $shippingDiscount * ( ( $rate / 100 ) + 1 );
359
+ $amount -= $newAmount;
360
+ }
361
+ }
362
+
363
+ $cartitems[] = array(
364
+ 'quantity' => '1',
365
+ 'sku' => 'cg-discount',
366
+ 'name' => 'Discount',
367
+ 'price' => sprintf( '%01.2f', round( $amount, 2 ) ),
368
+ 'vat_amount' => 0,
369
+ 'vat' => 0,
370
+ 'vat_inc' => 1,
371
+ 'type' => 4
372
+ );
373
  }
374
 
375
  // add shipping
376
  if ( $order->getShippingAmount() > 0 ) {
377
+
378
+ $tax_info = $order->getFullTaxInfo();
379
+
380
+ $flags = 8;
381
+ if ( ! isset( $tax_info[0]['percent'] ) ) {
382
+ $tax_rate = 0;
383
+ } else {
384
+ $tax_rate = $tax_info[0]['percent'];
385
+ $flags += 32;
386
+ }
387
+ $tax_rate = ( isset( $tax_info[0]['percent'] ) ? $tax_info[0]['percent'] : 0 );
388
+ $cartitems[] = array(
389
+ 'quantity' => '1',
390
+ 'sku' => 'cg-shipping',
391
+ 'name' => 'Shipping fee',
392
+ 'price' => sprintf( '%01.2f', $order->getShippingInclTax() ),
393
+ 'vat_amount' => sprintf( '%01.2f', $order->getShippingTaxAmount() ),
394
+ 'vat' => $tax_rate,
395
+ 'vat_inc' => 1,
396
+ 'type' => 2
397
+ );
398
  }
399
 
400
  // add invoice fee
401
+ if ( $order->getPayment()->getAdditionalInformation( 'invoice_fee' ) > 0 ) {
402
+
403
+ $tax_rate = $order->getPayment()->getAdditionalInformation( 'invoice_fee_rate' );
404
+ $cartitems[] = array(
405
+ 'quantity' => '1',
406
+ 'sku' => 'cg-invoice',
407
+ 'name' => 'Invoice fee',
408
+ 'price' => sprintf( '%01.2f', $order->getPayment()->getAdditionalInformation( 'invoice_fee' ) ),
409
+ 'vat_amount' => ( isset( $tax_info[0]['percent'] ) ? round( $order->getPayment()->getAdditionalInformation( 'invoice_fee' ) * ( $tax_rate / 100 ), 2 ) : 0 ),
410
+ 'vat' => $tax_rate,
411
+ 'vat_inc' => 1,
412
+ 'type' => 5
413
+ );
414
  }
415
 
416
  // add Magestore affiliateplus discount
417
+ if ( ! is_null( $order->getAffiliateplusDiscount() ) && $order->getAffiliateplusDiscount() != 0 ) {
418
  $cartitems[] = array(
419
+ 'quantity' => '1',
420
+ 'sku' => 'cg-affdiscount',
421
+ 'name' => 'Discount',
422
+ 'price' => sprintf( '%01.2f', $order->getAffiliateplusDiscount() ),
423
+ 'vat_amount' => 0,
424
+ 'vat' => 0,
425
+ 'vat_inc' => 1,
426
+ 'type' => 4
427
+ );
428
  }
429
 
430
  // add ET Payment Extra Charge
431
+ if ( ! is_null( $order->getEtPaymentExtraCharge() ) && $order->getEtPaymentExtraCharge() != 0 ) {
432
  $cartitems[] = array(
433
+ 'quantity' => '1',
434
+ 'sku' => 'cg-paymentcharge',
435
+ 'name' => 'ET Payment fee',
436
+ 'price' => sprintf( '%01.2f', $order->getEtPaymentExtraCharge() ),
437
+ 'vat_amount' => sprintf( '%01.2f', $order->getEtPaymentExtraCharge() - $order->getEtPaymentExtraChargeExcludingTax() ),
438
+ // 'vat' => 0,
439
+ 'vat_inc' => 1,
440
+ 'type' => 5
441
+ );
442
  }
443
 
444
  // failsafe
445
  $cartpricetotal = $cartvattotal = 0;
446
+ foreach ( $cartitems as $cartitem ) {
447
+ $cartpricetotal += ceil( $cartitem['price'] * 100 );
448
+ $cartvattotal += ceil( $cartitem['vat_amount'] * 100 );
449
  }
450
+ if ( $cartpricetotal != ceil( $order->getGrandTotal() * 100 ) || $cartvattotal != ceil( $order->getTaxAmount() * 100 ) ) {
451
  $cartitems[] = array(
452
+ 'quantity' => '1',
453
+ 'sku' => 'cg-correction',
454
+ 'name' => 'Correction',
455
+ 'price' => sprintf( '%01.2f', ( ceil( $order->getGrandTotal() * 100 ) / 100 ) - ( $cartpricetotal / 100 ) ),
456
+ 'vat_amount' => sprintf( '%01.2f', ( ceil( $order->getTaxAmount() * 100 ) / 100 ) - ( $cartvattotal / 100 ) ),
457
+ // 'vat' => 0,
458
+ 'vat_inc' => 1,
459
+ 'type' => 5
460
+ );
461
  }
462
 
463
  $s_arr['cartitems'] = serialize( $cartitems );
511
  if ( isset( $extra_data['klarna-personal-number'] ) ) {
512
  $s_arr['dob'] = $extra_data['klarna-personal-number'];
513
  } else {
514
+ $s_arr['dob'] = $extra_data['klarna-dob_day'] . '-' . $extra_data['klarna-dob_month'] . '-' . $extra_data['klarna-dob_year'];
 
515
  $s_arr['gender'] = $extra_data['klarna-gender'];
516
  }
517
  $s_arr['language'] = $extra_data['klarna-language'];
526
  if ( isset( $extra_data['klarna-account-personal-number'] ) ) {
527
  $s_arr['dob'] = $extra_data['klarna-account-personal-number'];
528
  } else {
529
+ $s_arr['dob'] = $extra_data['klarna-account-dob_day'] . '-' . $extra_data['klarna-account-dob_month'] . '-' . $extra_data['klarna-account-dob_year'];
 
530
  $s_arr['gender'] = $extra_data['klarna-account-gender'];
531
  }
532
  $s_arr['language'] = $extra_data['klarna-account-language'];
548
  case 'przelewy24':
549
  $s_arr['option'] = 'przelewy24';
550
  break;
551
+
552
  // Afterpay
553
  case 'afterpay':
554
  $s_arr['option'] = 'afterpay';
555
  break;
556
+
557
  // Bitcoin
558
  case 'bitcoin':
559
  $s_arr['option'] = 'bitcoin';
574
  $s_arr['first_name'] = $customer->getFirstname();
575
  $s_arr['last_name'] = $customer->getLastname();
576
  $s_arr['email'] = $order->getCustomerEmail();
577
+ $s_arr['address'] = $customer->getStreet( 1 ) . ( $customer->getStreet( 2 ) ? ', ' . $customer->getStreet( 2 ) : '' );
 
578
  $s_arr['city'] = $customer->getCity();
579
  $s_arr['country_code'] = $customer->getCountry();
580
  $s_arr['postal_code'] = $customer->getPostcode();
582
  $s_arr['state'] = $customer->getRegionCode();
583
 
584
  if ( $this->getConfigData( 'use_backoffice_urls' ) == false ) {
585
+ $s_arr['return_url'] = Mage::getUrl( 'cgp/standard/success/', array(
586
+ '_secure' => true
587
  ) );
588
+ $s_arr['return_url_failed'] = Mage::getUrl( 'cgp/standard/cancel/', array(
589
+ '_secure' => true
590
  ) );
591
  }
592
 
602
  $hash_prefix = '';
603
  }
604
 
605
+ $s_arr['amount'] = sprintf( '%.0f', ceil( $order->getGrandTotal() * 100 ) );
606
  $s_arr['currency'] = $order->getOrderCurrencyCode();
607
+ $s_arr['description'] = str_replace( '%id%', $order->getIncrementId(), $this->getConfigData( 'order_description' ) );
608
+ $s_arr['hash'] = md5( $hash_prefix . $this->getConfigData( 'site_id' ) . $s_arr['amount'] . $s_arr['ref'] . $this->getConfigData( 'hash_key' ) );
 
 
 
609
 
610
  // Logging
611
  $base->log( 'Initiating a new transaction' );
616
  $locale = Mage::app()->getLocale()->getLocaleCode();
617
  return $s_arr;
618
  }
619
+
620
+ protected function _getParentTransactionId ( Varien_Object $payment ) {
621
+ return $payment->getParentTransactionId() ? $payment->getParentTransactionId() : $payment->getLastTransId();
622
+ }
623
+
624
+ /**
625
+ * Do RESTful API call
626
+ * @param string $entrypoint
627
+ * @param string $calldata
628
+ * @return Zend_Http_Response
629
+ * @throws Zend_Http_Client_Exception
630
+ */
631
+ public function doApiCall( $entrypoint, $calldata = array() ) {
632
+ $config = array(
633
+ 'maxredirects' => 5,
634
+ 'timeout' => 30,
635
+ 'verifypeer' => 0
636
+ );
637
+
638
+ $data = array();
639
+ $data['shop_version'] = 'Magento ' . Mage::getVersion();
640
+ $data['plugin_name'] = 'Cardgate_Cgp';
641
+ $data['plugin_version'] = $this->getPluginVersion();
642
+ $data = array_merge( $data, $calldata );
643
+
644
+ $APIid = $this->getConfigData( 'api_id' );
645
+ $APIkey = $this->getConfigData( 'api_key' );
646
+ $headers = array(
647
+ 'Accept: application/json'
648
+ );
649
+
650
+ $client = new Varien_Http_Client();
651
+ $client->setUri( $this->getAPIUrl() . $entrypoint )
652
+ ->setAuth( $APIid, $APIkey, Varien_Http_Client::AUTH_BASIC )
653
+ ->setConfig( $config )
654
+ ->setMethod( Zend_Http_Client::POST )
655
+ ->setHeaders( $headers )
656
+ ->setRawData( json_encode( $data ) );
657
+ $response = $client->request();
658
+ $responsecode = $response->getStatus();
659
+ $responsebody = $response->getBody();
660
+ $result = json_decode( $responsebody, true );
661
+ return array( 'code'=>$responsecode, 'result'=>$result, 'body'=>$responsebody );
662
+ }
663
+
664
+ /**
665
+ * Refund a capture transaction
666
+ *
667
+ * @param Mage_Sales_Model_Order_Payment $payment
668
+ * @param float $amount
669
+ */
670
+ public function refund ( Varien_Object $payment, $amount ) {
671
+
672
+ /**
673
+ *
674
+ * @var Cardgate_Cgp_Model_Base $base
675
+ */
676
+ $base = Mage::getModel( 'cgp/base' );
677
+
678
+ $trxid = $this->_getParentTransactionId( $payment );
679
+ $base->log( "CG REFUND " . $trxid . " -- " . $amount );
680
+ if ( $trxid ) {
681
+ if ( $base->isLocked( $trxid ) ) {
682
+ $base->log( "Transaction {$trxid} is locked, can't refund now. Aborting." );
683
+ Mage::throwException( "Transaction {$trxid} is locked, can't refund now. Aborting." );
684
+ }
685
+
686
+ /**
687
+ *
688
+ * @var Mage_Sales_Model_Order $order
689
+ */
690
+ $order = $payment->getOrder();
691
+ $currencycode = $order->getOrderCurrencyCode();
692
+
693
+ if ( ! in_array( $currencycode, $this->_supportedCurrencies ) ) {
694
+ $base->log( 'Unacceptable currency code (' . $currencycode . ').' );
695
+ Mage::throwException( Mage::helper( 'cgp' )->__( 'Selected currency code "%s" is not compatible with CardGate', $currencycode ) );
696
+ }
697
+
698
+ $apiresult = array();
699
+ try {
700
+ $apiresult = $this->doApiCall('refund', array(
701
+ 'refund' => array(
702
+ 'site_id' => $this->getConfigData( 'site_id' ),
703
+ 'transaction_id' => $trxid,
704
+ 'amount' => sprintf( '%.0f', ceil( $amount * 100 ) ),
705
+ 'currency' => $currencycode
706
+ )
707
+
708
+ ));
709
+ $result = $apiresult['result'];
710
+ } catch ( Exception $e ) {
711
+ $base->log( 'Refund failed! ' . $e->getCode() . '/' . $e->getMessage() );
712
+ Mage::throwException( Mage::helper( 'cgp' )->__( 'CardGate refund for Transaction %s failed. Reason: %s', $trxid, $e->getCode() . '/' . $e->getMessage() ) );
713
+ }
714
+
715
+ $base->log( 'CardGate refund request for ' . $trxid . ' amount: ' . $currencycode . ' ' . $amount . '. Response: ' . $apiresult['body'] );
716
+
717
+ if ( $apiresult['code'] < 200 || $apiresult['code'] > 299 || ! is_array( $result ) || isset( $result['error'] ) ) {
718
+ $base->log( 'CardGate refund for Transaction ' . $trxid . ' declined. Got: ' . $apiresult['body'] );
719
+ Mage::throwException( Mage::helper( 'cgp' )->__( 'CardGate refund for Transaction %s declined. Reason: %s', $trxid, ( isset( $result['error']['message'] ) ? $result['error']['message'] : "({$apiresult['code']}) {$apiresult['body']}" ) ) );
720
+ } else {
721
+ /**
722
+ *
723
+ * @var Mage_Sales_Model_Order_Payment $refundpayment
724
+ */
725
+ $refundpayment = Mage::getModel( 'sales/order_payment' )->setMethod( $this->_code )
726
+ ->setTransactionId( $result['refund']['transaction_id'] )
727
+ ->setIsTransactionClosed( true );
728
+
729
+ $order->setPayment( $refundpayment );
730
+ $refundpayment->addTransaction( Mage_Sales_Model_Order_Payment_Transaction::TYPE_REFUND, null, false, "CardGate refund {$result['refund']['transaction_id']}" );
731
+
732
+ $order->save();
733
+
734
+ if ( $result['refund']['action'] == 'redirect' ) {
735
+ $order->addStatusHistoryComment( Mage::helper( 'cgp' )->__( "Action required for Cardgate refund <b>Order # %s</b> <b>(transaction # %s)</b>. <a href='%s' target='_blank'>Click here</a>", $order->getIncrementId(), $result['refund']['transaction_id'], $result['refund']['url'] ) );
736
+
737
+ $storeId = $order->getStore()->getId();
738
+ $ident = Mage::getStoreConfig( 'cgp/settings/notification_email' );
739
+ $sender_email = Mage::getStoreConfig( 'trans_email/ident_general/email', $storeId );
740
+ $sender_name = Mage::getStoreConfig( 'trans_email/ident_general/name', $storeId );
741
+ $recipient_email = Mage::getStoreConfig( 'trans_email/ident_' . $ident . '/email', $storeId );
742
+ $recipient_name = Mage::getStoreConfig( 'trans_email/ident_' . $ident . '/name', $storeId );
743
+
744
+ $mail = new Zend_Mail();
745
+ $mail->setFrom( $sender_email, $sender_name );
746
+ $mail->addTo( $recipient_email, $recipient_name );
747
+ $mail->setSubject( Mage::helper( "cgp" )->__( 'Cardgate refund action required' ) );
748
+ $mail->setBodyText(
749
+ Mage::helper( "cgp" )->__( 'Action required for Cardgate refund Order # %s (transaction # %s). See URL %s', $order->getIncrementId(), $result['refund']['transaction_id'], $result['refund']['url'] ) );
750
+ $mail->setBodyHtml(
751
+ Mage::helper( "cgp" )->__(
752
+ "Action required for Cardgate refund <b>Order # %s</b> <b>(transaction # %s)</b>. <a href='%s' target='_blank'>Click here</a>",
753
+ $order->getIncrementId(), $result['refund']['transaction_id'], $result['refund']['url'] ) );
754
+ $mail->send();
755
+
756
+ Mage::getSingleton( 'core/session' )->addWarning( Mage::helper( 'cgp' )->__( "Action required for Cardgate refund <b>Order # %s</b> <b>(transaction # %s)</b>. <a href='%s' target='_blank'>Click here</a>", $order->getIncrementId(), $result['refund']['transaction_id'], $result['refund']['url'] ) );
757
+ }
758
+
759
+ }
760
+ } else {
761
+ $base->log( 'CardGate refund failed because transaction could not be found' );
762
+ Mage::throwException( sprintf( Mage::helper( 'cgp' )->__( 'CardGate refund failed because transaction could not be found' ) ) );
763
+ }
764
+
765
+ return $this;
766
+ }
767
+
768
  }
app/code/local/Cardgate/Cgp/controllers/StandardController.php CHANGED
@@ -6,8 +6,7 @@
6
  * @category Mage
7
  * @package Cardgate_Cgp
8
  */
9
- class Cardgate_Cgp_StandardController extends Mage_Core_Controller_Front_Action
10
- {
11
 
12
  private $_gatewayModel;
13
 
@@ -17,12 +16,10 @@ class Cardgate_Cgp_StandardController extends Mage_Core_Controller_Front_Action
17
  * @param array $data
18
  * @return boolean
19
  */
20
- protected function validate ( $data )
21
- {
22
  $base = Mage::getSingleton( 'cgp/base' );
23
 
24
- $hashString = ( $data['is_test'] ? 'TEST' : '' ) . $data['transaction_id'] . $data['currency'] . $data['amount'] .
25
- $data['ref'] . $data['status'] . $base->getConfigData( 'hash_key' );
26
 
27
  if ( md5( $hashString ) == $data['hash'] ) {
28
  return true;
@@ -34,11 +31,10 @@ class Cardgate_Cgp_StandardController extends Mage_Core_Controller_Front_Action
34
  /**
35
  * Check if within the URL is param model
36
  * if not, return default gateway model
37
- *
38
  * @return string
39
  */
40
- protected function getGatewayModel ()
41
- {
42
  if ( $this->_gatewayModel ) {
43
  return $this->_gatewayModel;
44
  }
@@ -56,8 +52,7 @@ class Cardgate_Cgp_StandardController extends Mage_Core_Controller_Front_Action
56
  /**
57
  * Redirect customer to the gateway using his prefered payment method
58
  */
59
- public function redirectAction ()
60
- {
61
  $paymentModel = 'cgp/' . $this->getGatewayModel();
62
  Mage::register( 'cgp_model', $paymentModel );
63
 
@@ -76,18 +71,15 @@ class Cardgate_Cgp_StandardController extends Mage_Core_Controller_Front_Action
76
  /**
77
  * After a failed transaction a customer will be send here
78
  */
79
- public function cancelAction ()
80
- {
81
  switch ( $_REQUEST['cgpstatusid'] ) {
82
  case 0:
83
- $message = $this->__(
84
- 'Your payment is being evaluated by the bank. Please do not attempt to pay again, until your payment is either confirmed or denied by the bank.' );
85
  break;
86
  case 305:
87
  break;
88
  case 300:
89
- $message = $this->__(
90
- 'Your payment has failed. If you wish, you can try using a different payment method.' );
91
  break;
92
  }
93
  if ( isset( $message ) ) {
@@ -123,7 +115,7 @@ class Cardgate_Cgp_StandardController extends Mage_Core_Controller_Front_Action
123
 
124
  if ( $quote->getId() ) {
125
  $quote->setIsActive( true );
126
- if ($quote->getReservedOrderId()) {
127
  $quote->setOrigOrderId( $quote->getReservedOrderId() );
128
  $quote->setReservedOrderId();
129
  }
@@ -139,8 +131,7 @@ class Cardgate_Cgp_StandardController extends Mage_Core_Controller_Front_Action
139
  /**
140
  * After a successful transaction a customer will be send here
141
  */
142
- public function successAction ()
143
- {
144
  $session = Mage::getSingleton( 'checkout/session' );
145
  $quote = Mage::getModel( 'sales/quote' )->load( $session->getCardgateQuoteId() );
146
  if ( $quote->getId() ) {
@@ -150,16 +141,15 @@ class Cardgate_Cgp_StandardController extends Mage_Core_Controller_Front_Action
150
  // clear session flag so that next order will redirect to the gateway
151
  // $session->setCgpOnestepCheckout(false);
152
 
153
- $this->_redirect( 'checkout/onepage/success', array(
154
- '_secure' => true
155
  ) );
156
  }
157
 
158
  /**
159
  * Control URL called by gateway
160
  */
161
- public function controlAction ()
162
- {
163
  $base = Mage::getModel( 'cgp/base' );
164
  $data = $this->getRequest()->getPost();
165
 
@@ -172,25 +162,29 @@ class Cardgate_Cgp_StandardController extends Mage_Core_Controller_Front_Action
172
  }
173
 
174
  // Process callback
175
- $base->setCallbackData( $data )->processCallback();
 
 
 
 
176
 
177
  // Obtain quote and status
178
  $status = ( int ) $data['status'];
179
  $quote = Mage::getModel( 'sales/quote' )->load( $data['extra'] );
180
 
181
- // Set Mage_Sales_Model_Quote to inactive and delete
182
  if ( 200 <= $status && $status <= 299 ) {
183
-
184
- // $retain = $base->getConfigData('retain_cart_on_cancel');
185
  if ( $quote->getId() ) {
186
  $quote->setIsActive( false );
187
  $quote->delete();
188
  }
189
- // Set Mage_Sales_Model_Quote to active and save
 
190
  } else {
 
191
  if ( $quote->getId() ) {
192
  $quote->setIsActive( true );
193
- if ($quote->getReservedOrderId()) {
194
  $quote->setOrigOrderId( $quote->getReservedOrderId() );
195
  $quote->setReservedOrderId();
196
  }
@@ -201,4 +195,47 @@ class Cardgate_Cgp_StandardController extends Mage_Core_Controller_Front_Action
201
  // Display transaction_id and status
202
  echo $data['transaction_id'] . '.' . $data['status'];
203
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
204
  }
6
  * @category Mage
7
  * @package Cardgate_Cgp
8
  */
9
+ class Cardgate_Cgp_StandardController extends Mage_Core_Controller_Front_Action {
 
10
 
11
  private $_gatewayModel;
12
 
16
  * @param array $data
17
  * @return boolean
18
  */
19
+ protected function validate ( $data ) {
 
20
  $base = Mage::getSingleton( 'cgp/base' );
21
 
22
+ $hashString = ( ( $data['is_test'] || $data['testmode'] ) ? 'TEST' : '' ) . $data['transaction_id'] . $data['currency'] . $data['amount'] . $data['ref'] . $data['status'] . $base->getConfigData( 'hash_key' );
 
23
 
24
  if ( md5( $hashString ) == $data['hash'] ) {
25
  return true;
31
  /**
32
  * Check if within the URL is param model
33
  * if not, return default gateway model
34
+ *
35
  * @return string
36
  */
37
+ protected function getGatewayModel () {
 
38
  if ( $this->_gatewayModel ) {
39
  return $this->_gatewayModel;
40
  }
52
  /**
53
  * Redirect customer to the gateway using his prefered payment method
54
  */
55
+ public function redirectAction () {
 
56
  $paymentModel = 'cgp/' . $this->getGatewayModel();
57
  Mage::register( 'cgp_model', $paymentModel );
58
 
71
  /**
72
  * After a failed transaction a customer will be send here
73
  */
74
+ public function cancelAction () {
 
75
  switch ( $_REQUEST['cgpstatusid'] ) {
76
  case 0:
77
+ $message = $this->__( 'Your payment is being evaluated by the bank. Please do not attempt to pay again, until your payment is either confirmed or denied by the bank.' );
 
78
  break;
79
  case 305:
80
  break;
81
  case 300:
82
+ $message = $this->__( 'Your payment has failed. If you wish, you can try using a different payment method.' );
 
83
  break;
84
  }
85
  if ( isset( $message ) ) {
115
 
116
  if ( $quote->getId() ) {
117
  $quote->setIsActive( true );
118
+ if ( $quote->getReservedOrderId() ) {
119
  $quote->setOrigOrderId( $quote->getReservedOrderId() );
120
  $quote->setReservedOrderId();
121
  }
131
  /**
132
  * After a successful transaction a customer will be send here
133
  */
134
+ public function successAction () {
 
135
  $session = Mage::getSingleton( 'checkout/session' );
136
  $quote = Mage::getModel( 'sales/quote' )->load( $session->getCardgateQuoteId() );
137
  if ( $quote->getId() ) {
141
  // clear session flag so that next order will redirect to the gateway
142
  // $session->setCgpOnestepCheckout(false);
143
 
144
+ $this->_redirect( 'checkout/onepage/success', array(
145
+ '_secure' => true
146
  ) );
147
  }
148
 
149
  /**
150
  * Control URL called by gateway
151
  */
152
+ public function controlAction () {
 
153
  $base = Mage::getModel( 'cgp/base' );
154
  $data = $this->getRequest()->getPost();
155
 
162
  }
163
 
164
  // Process callback
165
+ if ( intval( $data['amount'] ) < 0 ) {
166
+ $base->setCallbackData( $data )->processRefundCallback();
167
+ } else {
168
+ $base->setCallbackData( $data )->processCallback();
169
+ }
170
 
171
  // Obtain quote and status
172
  $status = ( int ) $data['status'];
173
  $quote = Mage::getModel( 'sales/quote' )->load( $data['extra'] );
174
 
 
175
  if ( 200 <= $status && $status <= 299 ) {
176
+ // Set Mage_Sales_Model_Quote to inactive and delete
 
177
  if ( $quote->getId() ) {
178
  $quote->setIsActive( false );
179
  $quote->delete();
180
  }
181
+ } elseif ( 400 <= $status && $status <= 499 ) {
182
+ // Refund callback - do nothing
183
  } else {
184
+ // Set Mage_Sales_Model_Quote to active and save
185
  if ( $quote->getId() ) {
186
  $quote->setIsActive( true );
187
+ if ( $quote->getReservedOrderId() ) {
188
  $quote->setOrigOrderId( $quote->getReservedOrderId() );
189
  $quote->setReservedOrderId();
190
  }
195
  // Display transaction_id and status
196
  echo $data['transaction_id'] . '.' . $data['status'];
197
  }
198
+
199
+ public function testAction () {
200
+ $base = Mage::getModel( 'cgp/base' );
201
+ switch ( $this->getRequest()->getParam('action') ) {
202
+ case "restful":
203
+ echo '<pre>';
204
+ if ( $this->getRequest()->getParam('hash') != md5( $base->getConfigData( 'site_id' ) . $base->getConfigData( 'hash_key' ) ) ) {
205
+ die ( 'HASHKEY ERROR' );
206
+ }
207
+
208
+ /**
209
+ * @var Cardgate_Cgp_Model_Gateway_Default $gateway
210
+ */
211
+ $gateway = Mage::getModel( 'cgp/gateway_default');
212
+ $result = $gateway->doApiCall( 'billingoptions/' . $gateway->getConfigData( 'site_id' ));
213
+ if ( $result['code'] == 200 ) {
214
+ echo "OK.\nRESTful API call for API user '" . $gateway->getConfigData( 'api_id' ) . "' successfull.\n\n-------------\nBilling options for site " . $gateway->getConfigData( 'site_id' ) . ":\n-------------\n\n";
215
+ foreach ($result['result']['billing_options'] as $option) {
216
+ echo "{$option['name']}\n";
217
+ }
218
+ } else {
219
+ echo "ERROR.\nRESTful API call for API user '" . $gateway->getConfigData( 'api_id' ) . "' did not return status 200.\n\n-------------\nResult:\n-------------\n\n";
220
+ print_r( $result );
221
+ }
222
+ break;
223
+ default:
224
+ echo "NOT IMPLEMENTED";
225
+ break;
226
+ }
227
+ }
228
+
229
+ public function versionAction () {
230
+ $base = Mage::getModel( 'cgp/base' );
231
+ if ( $this->getRequest()->getParam('hash') != md5( $base->getConfigData( 'site_id' ) . $base->getConfigData( 'hash_key' ) ) ) {
232
+ die ( json_encode( array ( 'error'=>true, 'message'=>'Hash error' ) ) );
233
+ }
234
+ /**
235
+ * @var Cardgate_Cgp_Model_Gateway_Default $gateway
236
+ */
237
+ $gateway = Mage::getModel( 'cgp/gateway_default');
238
+ die ( json_encode( array ( 'plugin_version'=>$gateway->getPluginVersion(), 'magento_version'=>Mage::getVersion() ) ) );
239
+ }
240
+
241
  }
app/code/local/Cardgate/Cgp/etc/config.xml CHANGED
@@ -10,7 +10,7 @@
10
  <config>
11
  <modules>
12
  <Cardgate_Cgp>
13
- <version>1.1.10</version>
14
  </Cardgate_Cgp>
15
  </modules>
16
 
10
  <config>
11
  <modules>
12
  <Cardgate_Cgp>
13
+ <version>1.1.11</version>
14
  </Cardgate_Cgp>
15
  </modules>
16
 
app/code/local/Cardgate/Cgp/etc/system.xml CHANGED
@@ -63,7 +63,7 @@
63
  <show_in_default>1</show_in_default>
64
  <show_in_website>1</show_in_website>
65
  <show_in_store>1</show_in_store>
66
- </site_id>
67
  <hash_key translate="label comment">
68
  <label>Hash Key</label>
69
  <frontend_type>text</frontend_type>
@@ -73,6 +73,24 @@
73
  <show_in_website>1</show_in_website>
74
  <show_in_store>1</show_in_store>
75
  </hash_key>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
  <use_backoffice_urls translate="label comment">
77
  <label>Use back-office URLs</label>
78
  <frontend_type>select</frontend_type>
63
  <show_in_default>1</show_in_default>
64
  <show_in_website>1</show_in_website>
65
  <show_in_store>1</show_in_store>
66
+ </site_id>
67
  <hash_key translate="label comment">
68
  <label>Hash Key</label>
69
  <frontend_type>text</frontend_type>
73
  <show_in_website>1</show_in_website>
74
  <show_in_store>1</show_in_store>
75
  </hash_key>
76
+ <api_id translate="label comment">
77
+ <label>RESTful API Username</label>
78
+ <frontend_type>text</frontend_type>
79
+ <comment><![CDATA[Needed only for refund-functionality: Fill in your API Username.]]></comment>
80
+ <sort_order>41</sort_order>
81
+ <show_in_default>1</show_in_default>
82
+ <show_in_website>0</show_in_website>
83
+ <show_in_store>0</show_in_store>
84
+ </api_id>
85
+ <api_key translate="label comment">
86
+ <label>RESTful API Key</label>
87
+ <frontend_type>text</frontend_type>
88
+ <comment><![CDATA[Needed only for refund-functionality: Fill in your secret API key. Please contact your account manager to retrieve the API Username and Key for your account.]]></comment>
89
+ <sort_order>42</sort_order>
90
+ <show_in_default>1</show_in_default>
91
+ <show_in_website>0</show_in_website>
92
+ <show_in_store>0</show_in_store>
93
+ </api_key>
94
  <use_backoffice_urls translate="label comment">
95
  <label>Use back-office URLs</label>
96
  <frontend_type>select</frontend_type>
app/locale/nl_NL/Cardgate_Cgp.csv CHANGED
@@ -39,8 +39,6 @@
39
  "Enabled","Ingeschakeld"
40
  "Title","Titel"
41
  "You will be redirected to finish your payment.","U zult worden doorgelinkt om uw betaling af te ronden."
42
- "Selected currency code ","Geselecteerde valuta code "
43
- " is not compatible with Card Gate Plus"," wordt niet ondersteund door Card Gate Plus"
44
  "Transaction started, waiting for payment.","Transactie gestart, wacht op betaling"
45
  "Paymentmethod used","Gebruikte betaalmethode"
46
  "Additional information","Extra informatie"
@@ -49,7 +47,7 @@
49
  "Select your bank","Selecteer uw bank"
50
  "Invoice # %s created and send to customer.","Factuur # %s is aangemaakt en verzonden naar de klant."
51
  "Invoice # %s created.","Factuur # %s is aangemaakt."
52
- "Hacker attempt: Order total amount does not match Card Gate Plus' gross total amount!","Hack poging: Het order bedrag komt niet overeen met het bedrag verzonden naar Card Gate Plus"
53
  "Payment complete.","Betaling afgerond."
54
  "Payment failed or canceled by user.","Betaling mislukt of geannuleerd door de klant."
55
  "Transaction failed, payment is fraud.","Betaling afgewezen door anti-fraude instellingen."
@@ -57,7 +55,8 @@
57
  "Notifications recipient","Ontvanger van meldingen"
58
  "Notify on failed invoice creation","Melden van mislukte poging om een factuur aan te maken"
59
  "Automatic invoice creation failed","Het automatisch genereren van de factuur is mislukt"
60
- "Magento was unable to create an invoice for Order # %s after a successful payment via Card Gate Plus (transaction # %s)","Het is Magento niet gelukt een factuur aan te maken voor Order # %s na een succesvolle transactie via Card Gate Plus (transactie # %s)"
 
61
  "Year","Jaar"
62
  "Month","Maand"
63
  "Day","Dag"
@@ -94,3 +93,24 @@
94
  "Benificiary IBAN","Begunstidge IBAN"
95
  "Benificiary BIC","Begunstidge BIC"
96
  "Reference","Referentie"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  "Enabled","Ingeschakeld"
40
  "Title","Titel"
41
  "You will be redirected to finish your payment.","U zult worden doorgelinkt om uw betaling af te ronden."
 
 
42
  "Transaction started, waiting for payment.","Transactie gestart, wacht op betaling"
43
  "Paymentmethod used","Gebruikte betaalmethode"
44
  "Additional information","Extra informatie"
47
  "Select your bank","Selecteer uw bank"
48
  "Invoice # %s created and send to customer.","Factuur # %s is aangemaakt en verzonden naar de klant."
49
  "Invoice # %s created.","Factuur # %s is aangemaakt."
50
+ "Hacker attempt: Order total amount does not match CardGate's gross total amount!","Hack poging: Het order bedrag komt niet overeen met het bedrag verzonden naar CardGate!"
51
  "Payment complete.","Betaling afgerond."
52
  "Payment failed or canceled by user.","Betaling mislukt of geannuleerd door de klant."
53
  "Transaction failed, payment is fraud.","Betaling afgewezen door anti-fraude instellingen."
55
  "Notifications recipient","Ontvanger van meldingen"
56
  "Notify on failed invoice creation","Melden van mislukte poging om een factuur aan te maken"
57
  "Automatic invoice creation failed","Het automatisch genereren van de factuur is mislukt"
58
+ "Magento was unable to create an invoice for Order # %s after a successful payment via CardGate (transaction # %s)","Het is Magento niet gelukt een factuur aan te maken voor Order # %s na een succesvolle transactie via CardGate (transactie # %s)"
59
+ "Magento was unable to create an invoice for <b>Order # %s</b> after a successful payment via CardGate <b>(transaction # %s)</b>","Het is Magento niet gelukt een factuur aan te maken voor <b>Order # %s</b> na een succesvolle transactie via CardGate <b>(transactie # %s)</b>"
60
  "Year","Jaar"
61
  "Month","Maand"
62
  "Day","Dag"
93
  "Benificiary IBAN","Begunstidge IBAN"
94
  "Benificiary BIC","Begunstidge BIC"
95
  "Reference","Referentie"
96
+ "Selected currency code "%s" is not compatible with CardGate","Geselecteerde valuta code "%s" wordt niet ondersteund door CardGate"
97
+ "RESTful API Username","RESTful API Gebruikernaam"
98
+ "Needed only for refund-functionality: Fill in your API Username.","Alleen nodig voor terugboekings-functionaliteit: Vul hier uw API Gebruikersnaam in."
99
+ "RESTful API Key","RESTful API Sleutel"
100
+ "Needed only for refund-functionality: Fill in your secret API key. Please contact your account manager to retrieve the API Username and Key for your account.","Alleen nodig voor terugboekings-functionaliteit: Vul hier uw geheime API Sleutel in. Neem contact op met uw accoutmanager om de API Gebruikersnaam en Sleutel te ontvangen voor uw account."
101
+ "Refunds enabled.","Terugboekingen ingeschakeld."
102
+ "Test current RESTful settings","Test huidige RESTful instellingen"
103
+ "Refunds disabled. Missing settings:","Terugboekingen uitgeschakeld. Ontbrekende instellingen:"
104
+ "CardGate refund %s successfully authorised. Amount: %s","CardGate terugboeking %s succesvol geautoriseerd. Bedrag: %s"
105
+ "CardGate refund %s failed. Amount: %s","CardGate terugboeking %s mislukt. Bedrag: %s"
106
+ "CardGate refund %s complete. Amount: %s","CardGate terugboeking %s voltooid. Bedrag: %s"
107
+ "CardGate refund failed","CardGate terugboeking mislukt"
108
+ "CardGate was unable to succesfully complete a refund for Order # %s (transaction # %s). Please visit https://my.cardgate.com/ for more details.","CardGate kon een terugboeking niet succesvol voltooien voor Order # %s (transactie # %s). Bezoek https://my.cardgate.com/ voor meer informatie."
109
+ "CardGate was unable to succesfully complete a refund for <b>Order # %s</b> <b>(transaction # %s)</b>. Please visit <a href='https://my.cardgate.com/'>https://my.cardgate.com/</a> for more details.","CardGate kon een terugboeking niet succesvol voltooien voor <b>Order # %s</b> <b>(transactie # %s)</b>. Bezoek <a href='https://my.cardgate.com/'>https://my.cardgate.com/</a> voor meer informatie."
110
+ "CardGate refund for Transaction %s declined. Reason: %s","CardGate terugboeking voor Transaction %s afgewezen. Reden: %s"
111
+ "Cardgate refund action required","Cardgate terugboeking handeling benodigd"
112
+ "Action required for Cardgate refund Order # %s (transaction # %s). See URL %s","Handeling benodigd voor Cardgate terugboeking Order # %s (transactie # %s). Zie URL %s"
113
+ "Action required for Cardgate refund <b>Order # %s</b> <b>(transaction # %s)</b>. <a href='%s' target='_blank'>Click here</a>","Handeling benodigd voor Cardgate terugboeking <b>Order # %s</b> <b>(transactie # %s)</b>. <a href='%s' target='_blank'>Klik hier</a>"
114
+ "CardGate refund failed because transaction could not be found","CardGate terugboeking mislukt omdat de transactie niet gevonden kon worden"
115
+ "Unclaimed inventory because order changed to 'Canceled' state.","Voorraad teruggeboekt omdat de order wijzigde naar 'Geannuleerd' status."
116
+ "Reclaimed inventory because order changed from 'Canceled' to 'Processing' state.","Voorraad herboekt omdat de order wijzigde van 'Geannuleerd' naar 'Bezig met verwerken' status."
package.xml CHANGED
@@ -1,20 +1,20 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Cardgate_Cgp</name>
4
- <version>1.1.10</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Card Gate Payment Module</summary>
10
  <description>Card Gate is a Payment Service Provider from the Netherlands. We offer various payment methods against competitive rates.</description>
11
- <notes>- Added compatibility with Magestore Affiliateplus (http://www.magestore.com/affiliateplus/)&#xD;
12
- - Added compatibility with ET Payment Extra Charge (https://shop.etwebsolutions.com/eng/magento-extensions/et-payment-extra-charge.html)&#xD;
13
- - Added support for correcting additional discount/charges.</notes>
14
  <authors><author><name>Cardgate BV</name><user>cardgateplus</user><email>support@cardgate.com</email></author></authors>
15
- <date>2016-05-26</date>
16
- <time>09:22:23</time>
17
- <contents><target name="mageskin"><dir name="adminhtml"><dir name="default"><dir name="default"><file name="cardgate_cgp.css" hash="bebfc13fca1b36867c17864ae70fdabd"/><dir name="images"><dir name="cardgate"><file name="cardgate_cgp.png" hash="b97b15baba0b27042733c8ea4b4fb6bc"/></dir></dir></dir></dir></dir></target><target name="magelocale"><dir><dir name="nl_NL"><file name="Cardgate_Cgp.csv" hash="c3f92e7f8c8a62cbe26075ef113294d9"/><file name="Cardgate_Cgp.csv.from_package" hash="c3f92e7f8c8a62cbe26075ef113294d9"/></dir></dir></target><target name="mageetc"><dir name="modules"><file name="ZzCardgate_Cgp.xml" hash="c7a72af045f4b737b50cc6c360d4300d"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="template"><dir name="cardgate"><dir name="cgp"><dir name="checkout"><file name="fee.phtml" hash="79362bab3963195ad6727d077fe87b11"/></dir><dir name="form"><file name="banktransfer.phtml" hash="ff7a2a827a7b7a5ed9bcb5d484c30c68"/><file name="ideal.phtml" hash="42fdfee86ba3a098f5f73e9240332581"/><file name="klarna.phtml" hash="e2876171abf8e94d7b77a47ce9279561"/><file name="klarnaaccount.phtml" hash="419f88941703c8562369844bb6a1d692"/></dir><file name="redirect.phtml" hash="ecb2b0a854cd6358adeba535f8889046"/></dir></dir></dir></dir></dir></dir></target><target name="magelocal"><dir name="Cardgate"><dir name="Cgp"><dir name="Block"><dir name="Adminhtml"><dir name="System"><dir name="Config"><dir name="Source"><file name="Version.php" hash="73d6f00aa532e14d021c6a142ba549fd"/></dir></dir></dir></dir><dir name="Form"><file name="Banktransfer.php" hash="be49e1b58910ee33b329badaa9fc85ce"/><file name="Ideal.php" hash="24a367e9b73955b3579438cb5eec213c"/><file name="Klarna.php" hash="c66cbcc135151dcc4337d22fc0552a46"/><file name="Klarnaaccount.php" hash="77e35328922bfb232f93896b77367c1e"/></dir><dir name="Paymentfee"><dir name="Adminhtml"><dir name="Sales"><dir name="Order"><file name="Totals.php" hash="7f4fb8293923e064ecbd77451c52afd9"/></dir></dir></dir><dir name="Checkout"><file name="Fee.php" hash="07e72679dc8ddd5f7e2db9e24bb76aa6"/></dir><dir name="Creditmemo"><file name="Totals.php" hash="87021e3b682c1abf1ae95e173730023a"/></dir><dir name="Invoice"><dir name="Totals"><file name="Fee.php" hash="40c399761dccfd494d7cfb439447c5e3"/></dir></dir><dir name="Order"><dir name="Totals"><file name="Fee.php" hash="0cde857c2b7f33cdb5927143a98f0958"/></dir></dir></dir><file name="Redirect.php" hash="2f854d58133eebad7f128a08d799f7ef"/></dir><dir name="Helper"><file name="Data.php" hash="ed47b3c61a5e701e1683a7717c6b8ef1"/><file name="Paymentfee.php" hash="23700e6d5f7f96f149214679fa6ed614"/></dir><dir name="Model"><dir name="Adminhtml"><dir name="System"><dir name="Config"><dir name="Source"><file name="Languages.php" hash="fb24871559fa1ce2613438ad5613a196"/><file name="Modes.php" hash="678a822a7f0c0665fc696c44937825be"/><file name="Orderstatus.php" hash="610ca9cedb01e329d821f4e407e5bfc8"/><file name="Version.php" hash="818a7ae5f4126fbb0c8fc76376e03c65"/></dir></dir></dir></dir><file name="Base.php" hash="56f9937fb48514ac0c309790b640a597"/><dir name="Gateway"><file name="Abstract.php" hash="248e1d2c6be211036f4888708ca8bcbb"/><file name="Afterpay.php" hash="054b525c972119fd330291776c2550ac"/><file name="Americanexpress.php" hash="705926d7a69fb889f54185743f4cac9f"/><file name="Banktransfer.php" hash="d4d5712ab327c418ee2d949e49faee01"/><file name="Bitcoin.php" hash="001420be0c8d665d905bcc79275e989e"/><file name="Cartebancaire.php" hash="451bff78fa26e4bae883d0c18ca1f844"/><file name="Cartebleue.php" hash="b7974f8f8e655daaf50a899d15cc15fd"/><file name="Default.php" hash="dd934ee60d32000773f26be805d46925"/><file name="Directdebit.php" hash="7890209183bab5f47edcca60a19cd007"/><file name="Giropay.php" hash="ea35629ddfd08cd341128af6d95c8911"/><file name="Ideal.php" hash="1b5b6318c3e544659f465fdbc463fa51"/><file name="Klarna.php" hash="901891d606ea469296e75251fc7abe14"/><file name="Klarnaaccount.php" hash="4d85440b0df2df05ec001c6a5d7416dd"/><file name="Maestro.php" hash="c29f0bd00282c992017a2487d12d8bda"/><file name="Mastercard.php" hash="3febe4f0ee3cc630cd959e8ce086d2ee"/><file name="Mistercash.php" hash="d618b6ab14ffa5d9810cf65232b6d2a3"/><file name="Paypal.php" hash="ad4600fdc877a84a6a4f8647ae2587df"/><file name="Przelewy24.php" hash="f49bfa8354fa2bce2add3221a04843cf"/><file name="Sofortbanking.php" hash="544531b74c8fd34e7ccd48a32210d81f"/><file name="Visa.php" hash="50cbf582c2b5192923d290fcbec35870"/><file name="Vpay.php" hash="acf7d286f343b4e663a55a8540bf45d2"/><file name="Webmoney.php" hash="72a36f0854db4c02e0477208b47faccf"/></dir><file name="Observer.php" hash="72363edbe183cfa833e276f0e3cda200"/><dir name="Paymentfee"><dir name="Creditmemo"><file name="Total.php" hash="5191056c5dae3862c2a468acd3e5cbac"/></dir><dir name="Invoice"><dir name="Pdf"><file name="Total.php" hash="314df1d94874fcb856af2e0be4019782"/></dir><file name="Tax.php" hash="dc485fa37d31e13e20f578cb58075486"/><file name="Total.php" hash="f26e4dc51d0e510eb1c2c65750dec92b"/></dir><dir name="Quote"><file name="Quote.php" hash="d09d4d5c4b55770b0a50f80f0a5fa643"/><file name="TaxTotal.php" hash="a1f53b6ed1988364aa396b3bd7afa1e0"/><file name="Total.php" hash="a525e84dc0d62a4ca073a7ddb80f162b"/></dir></dir></dir><dir name="controllers"><file name="StandardController.php" hash="793d913a16fc5a6ad56f6c4f306af793"/></dir><dir name="etc"><file name="adminhtml.xml" hash="f14dc99c26f44cc53b4a5974dd9cdd2d"/><file name="config.xml" hash="d35856aab11eb81870a87d09f9fcdffb"/><file name="system.xml" hash="816dcbbc6a0b93dd6ec3a598831bbede"/></dir></dir></dir></target></contents>
18
  <compatible/>
19
  <dependencies><required><php><min>5.4.0</min><max>7.1.0</max></php></required></dependencies>
20
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Cardgate_Cgp</name>
4
+ <version>1.1.11</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Card Gate Payment Module</summary>
10
  <description>Card Gate is a Payment Service Provider from the Netherlands. We offer various payment methods against competitive rates.</description>
11
+ <notes>- Added refund capability (see CardGate Settings-tab)&#xD;
12
+ - Changed behaviour when payments for already canceled orders are successfully processed&#xD;
13
+ </notes>
14
  <authors><author><name>Cardgate BV</name><user>cardgateplus</user><email>support@cardgate.com</email></author></authors>
15
+ <date>2016-06-16</date>
16
+ <time>20:40:10</time>
17
+ <contents><target name="mageskin"><dir name="adminhtml"><dir name="default"><dir name="default"><file name="cardgate_cgp.css" hash="bebfc13fca1b36867c17864ae70fdabd"/><dir name="images"><dir name="cardgate"><file name="cardgate_cgp.png" hash="b97b15baba0b27042733c8ea4b4fb6bc"/></dir></dir></dir></dir></dir></target><target name="magelocale"><dir><dir name="nl_NL"><file name="Cardgate_Cgp.csv" hash="c08c70afdd28ab2e1e1be47c3171f7c1"/><file name="Cardgate_Cgp.csv.from_package" hash="c3f92e7f8c8a62cbe26075ef113294d9"/></dir></dir></target><target name="mageetc"><dir name="modules"><file name="ZzCardgate_Cgp.xml" hash="c7a72af045f4b737b50cc6c360d4300d"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="template"><dir name="cardgate"><dir name="cgp"><dir name="checkout"><file name="fee.phtml" hash="79362bab3963195ad6727d077fe87b11"/></dir><dir name="form"><file name="banktransfer.phtml" hash="ff7a2a827a7b7a5ed9bcb5d484c30c68"/><file name="ideal.phtml" hash="42fdfee86ba3a098f5f73e9240332581"/><file name="klarna.phtml" hash="e2876171abf8e94d7b77a47ce9279561"/><file name="klarnaaccount.phtml" hash="419f88941703c8562369844bb6a1d692"/></dir><file name="redirect.phtml" hash="ecb2b0a854cd6358adeba535f8889046"/></dir></dir></dir></dir></dir></dir></target><target name="magelocal"><dir name="Cardgate"><dir name="Cgp"><dir name="Block"><dir name="Adminhtml"><dir name="System"><dir name="Config"><dir name="Source"><file name="Version.php" hash="5ae77a4b27da149eb798a0aa80045b9a"/></dir></dir></dir></dir><dir name="Form"><file name="Banktransfer.php" hash="be49e1b58910ee33b329badaa9fc85ce"/><file name="Ideal.php" hash="24a367e9b73955b3579438cb5eec213c"/><file name="Klarna.php" hash="c66cbcc135151dcc4337d22fc0552a46"/><file name="Klarnaaccount.php" hash="77e35328922bfb232f93896b77367c1e"/></dir><dir name="Paymentfee"><dir name="Adminhtml"><dir name="Sales"><dir name="Order"><file name="Totals.php" hash="7b2d199e11a13936213e87a54bc09e5c"/></dir></dir></dir><dir name="Checkout"><file name="Fee.php" hash="07e72679dc8ddd5f7e2db9e24bb76aa6"/></dir><dir name="Creditmemo"><file name="Totals.php" hash="87021e3b682c1abf1ae95e173730023a"/></dir><dir name="Invoice"><dir name="Totals"><file name="Fee.php" hash="40c399761dccfd494d7cfb439447c5e3"/></dir></dir><dir name="Order"><dir name="Totals"><file name="Fee.php" hash="0cde857c2b7f33cdb5927143a98f0958"/></dir></dir></dir><file name="Redirect.php" hash="2f854d58133eebad7f128a08d799f7ef"/></dir><dir name="Helper"><file name="Data.php" hash="ed47b3c61a5e701e1683a7717c6b8ef1"/><file name="Paymentfee.php" hash="23700e6d5f7f96f149214679fa6ed614"/></dir><dir name="Model"><dir name="Adminhtml"><dir name="System"><dir name="Config"><dir name="Source"><file name="Languages.php" hash="fb24871559fa1ce2613438ad5613a196"/><file name="Modes.php" hash="678a822a7f0c0665fc696c44937825be"/><file name="Orderstatus.php" hash="610ca9cedb01e329d821f4e407e5bfc8"/><file name="Version.php" hash="818a7ae5f4126fbb0c8fc76376e03c65"/></dir></dir></dir></dir><file name="Base.php" hash="372af34e77c7120ac1673249da3230b7"/><dir name="Gateway"><file name="Abstract.php" hash="6ef906565112d705e384b910f0fbfb57"/><file name="Afterpay.php" hash="054b525c972119fd330291776c2550ac"/><file name="Americanexpress.php" hash="705926d7a69fb889f54185743f4cac9f"/><file name="Banktransfer.php" hash="d4d5712ab327c418ee2d949e49faee01"/><file name="Bitcoin.php" hash="001420be0c8d665d905bcc79275e989e"/><file name="Cartebancaire.php" hash="451bff78fa26e4bae883d0c18ca1f844"/><file name="Cartebleue.php" hash="b7974f8f8e655daaf50a899d15cc15fd"/><file name="Default.php" hash="dd934ee60d32000773f26be805d46925"/><file name="Directdebit.php" hash="7890209183bab5f47edcca60a19cd007"/><file name="Giropay.php" hash="ea35629ddfd08cd341128af6d95c8911"/><file name="Ideal.php" hash="1b5b6318c3e544659f465fdbc463fa51"/><file name="Klarna.php" hash="901891d606ea469296e75251fc7abe14"/><file name="Klarnaaccount.php" hash="4d85440b0df2df05ec001c6a5d7416dd"/><file name="Maestro.php" hash="c29f0bd00282c992017a2487d12d8bda"/><file name="Mastercard.php" hash="3febe4f0ee3cc630cd959e8ce086d2ee"/><file name="Mistercash.php" hash="d618b6ab14ffa5d9810cf65232b6d2a3"/><file name="Paypal.php" hash="ad4600fdc877a84a6a4f8647ae2587df"/><file name="Przelewy24.php" hash="f49bfa8354fa2bce2add3221a04843cf"/><file name="Sofortbanking.php" hash="544531b74c8fd34e7ccd48a32210d81f"/><file name="Visa.php" hash="50cbf582c2b5192923d290fcbec35870"/><file name="Vpay.php" hash="acf7d286f343b4e663a55a8540bf45d2"/><file name="Webmoney.php" hash="72a36f0854db4c02e0477208b47faccf"/></dir><file name="Observer.php" hash="72363edbe183cfa833e276f0e3cda200"/><dir name="Paymentfee"><dir name="Creditmemo"><file name="Total.php" hash="5191056c5dae3862c2a468acd3e5cbac"/></dir><dir name="Invoice"><dir name="Pdf"><file name="Total.php" hash="314df1d94874fcb856af2e0be4019782"/></dir><file name="Tax.php" hash="dc485fa37d31e13e20f578cb58075486"/><file name="Total.php" hash="f26e4dc51d0e510eb1c2c65750dec92b"/></dir><dir name="Quote"><file name="Quote.php" hash="d09d4d5c4b55770b0a50f80f0a5fa643"/><file name="TaxTotal.php" hash="a1f53b6ed1988364aa396b3bd7afa1e0"/><file name="Total.php" hash="a525e84dc0d62a4ca073a7ddb80f162b"/></dir></dir></dir><dir name="controllers"><file name="StandardController.php" hash="3a613e0268c5d42d733fbb17df2ed171"/></dir><dir name="etc"><file name="adminhtml.xml" hash="f14dc99c26f44cc53b4a5974dd9cdd2d"/><file name="config.xml" hash="993a92e5ee7fb50232a4e9c16f38bf14"/><file name="system.xml" hash="06d8bfa170c034bfd40219beb6a71479"/></dir></dir></dir></target></contents>
18
  <compatible/>
19
  <dependencies><required><php><min>5.4.0</min><max>7.1.0</max></php></required></dependencies>
20
  </package>