BluePay_CreditCard - Version 1.5.5.9

Version Notes

Fixed issue with multiple credit memos refunding an invoice

Download this release

Release Info

Developer Justin Slingerland
Extension BluePay_CreditCard
Version 1.5.5.9
Comparing to
See all releases


Code changes from version 1.5.5.8 to 1.5.5.9

app/code/local/BluePay/CreditCard/Model/CCPayment.php CHANGED
@@ -531,7 +531,6 @@ class BluePay_CreditCard_Model_CCPayment extends Mage_Payment_Model_Method_Cc
531
  $hashstr = $this->getConfigData('trans_key') . $this->getConfigData('login') .
532
  $payment->getTransactionType() . $payment->getAmount() . $payment->getRrno() .
533
  $this->getConfigData('test_mode');
534
- Mage::log($hashstr);
535
  return bin2hex( md5($hashstr, true) );
536
  }
537
 
531
  $hashstr = $this->getConfigData('trans_key') . $this->getConfigData('login') .
532
  $payment->getTransactionType() . $payment->getAmount() . $payment->getRrno() .
533
  $this->getConfigData('test_mode');
 
534
  return bin2hex( md5($hashstr, true) );
535
  }
536
 
app/code/local/BluePay/CreditCard/Model/CCPayment.php~ DELETED
@@ -1,694 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Magento
5
- *
6
- * NOTICE OF LICENSE
7
- *
8
- * This source file is subject to the Open Software License (OSL 3.0)
9
- * that is bundled with this package in the file LICENSE.txt.
10
- * It is also available through the world-wide-web at this URL:
11
- * http://opensource.org/licenses/osl-3.0.php
12
- * If you did not receive a copy of the license and are unable to
13
- * obtain it through the world-wide-web, please send an email
14
- * to license@magentocommerce.com so we can send you a copy immediately.
15
- *
16
- * DISCLAIMER
17
- *
18
- * Do not edit or add to this file if you wish to upgrade Magento to newer
19
- * versions in the future. If you wish to customize Magento for your
20
- * needs please refer to http://www.magentocommerce.com for more information.
21
- *
22
- * @category BluePay
23
- * @package BluePay_CreditCard
24
- * @copyright Copyright (c) 2010 BluePay Processing, LLC (http://www.bluepay.com)
25
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
26
- */
27
-
28
-
29
- class BluePay_CreditCard_Model_CCPayment extends Mage_Payment_Model_Method_Cc
30
- {
31
- //const CGI_URL = 'https://secure.bluepay.com/interfaces/bp10emu';
32
- const CGI_URL = 'http://www.assurebuy.com/echo.pl';
33
- const STQ_URL = 'https://secure.bluepay.com/interfaces/stq';
34
- const CURRENT_VERSION = '1.5.5.0';
35
-
36
- const REQUEST_METHOD_CC = 'CREDIT';
37
- const REQUEST_METHOD_ECHECK = 'ACH';
38
-
39
- const REQUEST_TYPE_AUTH_CAPTURE = 'SALE';
40
- const REQUEST_TYPE_AUTH_ONLY = 'AUTH';
41
- const REQUEST_TYPE_CAPTURE_ONLY = 'CAPTURE';
42
- const REQUEST_TYPE_CREDIT = 'REFUND';
43
- const REQUEST_TYPE_VOID = 'VOID';
44
- const REQUEST_TYPE_PRIOR_AUTH_CAPTURE = 'PRIOR_AUTH_CAPTURE';
45
-
46
- const ECHECK_ACCT_TYPE_CHECKING = 'CHECKING';
47
- const ECHECK_ACCT_TYPE_BUSINESS = 'BUSINESSCHECKING';
48
- const ECHECK_ACCT_TYPE_SAVINGS = 'SAVINGS';
49
-
50
- const ECHECK_TRANS_TYPE_CCD = 'CCD';
51
- const ECHECK_TRANS_TYPE_PPD = 'PPD';
52
- const ECHECK_TRANS_TYPE_TEL = 'TEL';
53
- const ECHECK_TRANS_TYPE_WEB = 'WEB';
54
-
55
- const RESPONSE_DELIM_CHAR = ',';
56
-
57
- const RESPONSE_CODE_APPROVED = 'APPROVED';
58
- const RESPONSE_CODE_DECLINED = 'DECLINED';
59
- const RESPONSE_CODE_ERROR = 'ERROR';
60
- const RESPONSE_CODE_MISSING = 'MISSING';
61
- const RESPONSE_CODE_HELD = 4;
62
-
63
-
64
- const INVOICE_ID = 0;
65
- const BANK_NAME = 1;
66
- const PAYMENT_ACCOUNT = 2;
67
- const AUTH_CODE = 3;
68
- const CARD_TYPE = 4;
69
- const AMOUNT = 5;
70
- const REBID = 6;
71
- const AVS = 7;
72
- const ORDER_ID = 8;
73
- const CARD_EXPIRE = 9;
74
- const Result = 10;
75
- const RRNO = 11;
76
- const CVV2 = 12;
77
- const PAYMENT_TYPE = 13;
78
- const MESSAGE = 14;
79
-
80
- protected $responseHeaders;
81
- protected $tempVar;
82
-
83
- protected $_code = 'ccpayment';
84
- protected $_formBlockType = 'creditcard/form';
85
- protected static $_dupe = true;
86
- protected static $_underscoreCache = array();
87
-
88
- /**
89
- * Availability options
90
- */
91
- protected $_isGateway = true;
92
- protected $_canAuthorize = true;
93
- protected $_canCapture = true;
94
- protected $_canCapturePartial = true;
95
- protected $_canRefund = true;
96
- protected $_canRefundInvoicePartial = true;
97
- protected $_canVoid = true;
98
- protected $_canUseInternal = true;
99
- protected $_canUseCheckout = true;
100
- protected $_canUseForMultishipping = true;
101
- protected $_canSaveCc = false;
102
-
103
- protected $_allowCurrencyCode = array('USD');
104
-
105
- /**
106
- * Fields that should be replaced in debug with '***'
107
- *
108
- * @var array
109
- */
110
- protected $_debugReplacePrivateDataKeys = array('x_login', 'x_tran_key',
111
- 'x_card_num', 'x_exp_date',
112
- 'x_card_code', 'x_bank_aba_code',
113
- 'x_bank_name', 'x_bank_acct_num',
114
- 'x_bank_acct_type','x_bank_acct_name',
115
- 'x_echeck_type');
116
-
117
- /**
118
- * Check method for processing with base currency
119
- *
120
- * @param string $currencyCode
121
- * @return boolean
122
- */
123
- public function canUseForCurrency($currencyCode)
124
- {
125
- if (!in_array($currencyCode, $this->getAcceptedCurrencyCodes())) {
126
- return false;
127
- }
128
- return true;
129
- }
130
-
131
- /**
132
- * Return array of currency codes supplied by Payment Gateway
133
- *
134
- * @return array
135
- */
136
- public function getAcceptedCurrencyCodes()
137
- {
138
- if (!$this->hasData('_accepted_currency')) {
139
- $acceptedCurrencyCodes = $this->_allowCurrencyCode;
140
- $acceptedCurrencyCodes[] = $this->getConfigData('currency');
141
- $this->setData('_accepted_currency', $acceptedCurrencyCodes);
142
- }
143
- return $this->_getData('_accepted_currency');
144
- }
145
-
146
- /**
147
- * Send authorize request to gateway
148
- */
149
-
150
- public function authorize(Varien_Object $payment, $amount)
151
- {
152
- if ($amount <= 0) {
153
- Mage::throwException(Mage::helper('paygate')->__('Invalid amount for authorization.'));
154
- }
155
- $payment->setTransactionType(self::REQUEST_TYPE_AUTH_ONLY);
156
- $payment->setAmount($amount);
157
-
158
- $request= $this->_buildRequest($payment);
159
- $result = $this->_postRequest($request);
160
-
161
- $payment->setCcApproval($result->getAuthCode())
162
- ->setLastTransId($result->getRrno())
163
- ->setTransactionId($result->getRrno())
164
- ->setIsTransactionClosed(0)
165
- ->setCcTransId($result->getRrno())
166
- ->setCcAvsStatus($result->getAvs())
167
- ->setCcCidStatus($result->getCvv2());
168
-
169
- switch ($result->getResult()) {
170
- case self::RESPONSE_CODE_APPROVED:
171
- $payment->setStatus(self::STATUS_APPROVED);
172
- return $this;
173
- case self::RESPONSE_CODE_DECLINED:
174
- Mage::throwException(Mage::helper('paygate')->__('The transaction has been declined'));
175
- case self::RESPONSE_CODE_ERROR:
176
- Mage::throwException(Mage::helper('paygate')->__('Error: ' . $result->getMessage()));
177
- default:
178
- Mage::throwException(Mage::helper('paygate')->__('An error has occured with your payment.'));
179
- }
180
- }
181
-
182
- /**
183
- * Send capture request to gateway
184
- */
185
- public function capture(Varien_Object $payment, $amount)
186
- {
187
- $payment->setAmount($amount);
188
- $result =$this->_checkDuplicate($payment);
189
- if ($payment->getCcTransId()) {
190
- $payment->setTransactionType(self::REQUEST_TYPE_CAPTURE_ONLY);
191
- } else {
192
- $payment->setTransactionType(self::REQUEST_TYPE_AUTH_CAPTURE);
193
- }
194
- $payment->setRrno($payment->getCcTransId());
195
- $request = $this->_buildRequest($payment);
196
- $result = $this->_postRequest($request);
197
- if ($result->getResult() == self::RESPONSE_CODE_APPROVED) {
198
- $payment->setStatus(self::STATUS_APPROVED);
199
- ////$payment->setCcTransId($result->getTransactionId());
200
- $payment->setLastTransId($result->getRrno());
201
- if (!$payment->getParentTransactionId() || $result->getRrno() != $payment->getParentTransactionId()) {
202
- $payment->setTransactionId($result->getRrno());
203
- }
204
- return $this;
205
- }
206
- switch ($result->getResult()) {
207
- case self::RESPONSE_CODE_DECLINED:
208
- Mage::throwException(Mage::helper('paygate')->__('The transaction has been declined.'));
209
- case self::RESPONSE_CODE_ERROR || self::RESPONSE_CODE_MISSING:
210
- if ($result->getMessage() == 'Already%20Captured') {
211
- $payment->setTransactionType(self::REQUEST_TYPE_AUTH_CAPTURE);
212
- $request=$this->_buildRequest($payment);
213
- $result =$this->_postRequest($request);
214
- if ($result->getResult() == self::RESPONSE_CODE_APPROVED && $result->getMessage() != 'DUPLICATE') {
215
- $payment->setStatus(self::STATUS_APPROVED);
216
- $payment->setLastTransId($result->getRrno());
217
- if (!$payment->getParentTransactionId() || $result->getRrno() != $payment->getParentTransactionId()) {
218
- $payment->setTransactionId($result->getRrno());
219
- }
220
- return $this;
221
- } else {
222
- Mage::throwException(Mage::helper('paygate')->__('Error: ' . $result->getMessage()));
223
- }
224
- } else {
225
- Mage::throwException(Mage::helper('paygate')->__('Error: ' . $result->getMessage()));
226
- }
227
- default:
228
- Mage::throwException(Mage::helper('paygate')->__('An error has occured with your payment.'));
229
- }
230
- Mage::throwException(Mage::helper('paygate')->__('Error in capturing the payment.'));
231
- }
232
-
233
-
234
- /**
235
- * Void the payment through gateway
236
- */
237
- public function void(Varien_Object $payment)
238
- {
239
- if ($payment->getParentTransactionId()) {
240
- $order = $payment->getOrder();
241
- $payment->setTransactionType(self::REQUEST_TYPE_CREDIT);
242
- $payment->setAmount($amount);
243
- $payment->setRrno($payment->getParentTransactionId());
244
- $request = $this->_buildRequest($payment);
245
- $result = $this->_postRequest($request);
246
- if ($result->getResult()==self::RESPONSE_CODE_APPROVED) {
247
- $payment->setStatus(self::STATUS_APPROVED);
248
- $order->setState(Mage_Sales_Model_Order::STATE_CANCELED, true)->save();
249
- return $this;
250
- }
251
- $payment->setStatus(self::STATUS_ERROR);
252
- Mage::throwException($this->_wrapGatewayError($result->getMessage()));
253
- }
254
- $payment->setStatus(self::STATUS_ERROR);
255
- Mage::throwException(Mage::helper('paygate')->__('Invalid transaction ID.'));
256
- }
257
-
258
- /**
259
- * refund the amount with transaction id
260
- */
261
- public function refund(Varien_Object $payment, $amount)
262
- {
263
- if ($payment->getRefundTransactionId() && $amount > 0) {
264
- $payment->setTransactionType(self::REQUEST_TYPE_CREDIT);
265
- $payment->setRrno($payment->getRefundTransactionId());
266
- $payment->setAmount($amount);
267
- $request = $this->_buildRequest($payment);
268
- $request->setRrno($payment->getRefundTransactionId());
269
- $result = $this->_postRequest($request);
270
- if ($result->getResult()==self::RESPONSE_CODE_APPROVED) {
271
- $payment->setStatus(self::STATUS_SUCCESS);
272
- return $this;
273
- }
274
- if ($result->getResult()==self::RESPONSE_CODE_DECLINED) {
275
- Mage::throwException($this->_wrapGatewayError('DECLINED'));
276
- }
277
- if ($result->getResult()==self::RESPONSE_CODE_ERROR) {
278
- Mage::throwException($this->_wrapGatewayError('ERROR'));
279
- }
280
- Mage::throwException($this->_wrapGatewayError($result->getRrno()));
281
- }
282
- Mage::throwException(Mage::helper('paygate')->__('Error in refunding the payment.'));
283
- }
284
-
285
- /**
286
- * Prepare request to gateway
287
- */
288
- protected function _buildRequest(Varien_Object $payment)
289
- {
290
- $order = $payment->getOrder();
291
- $this->setStore($order->getStoreId());
292
-
293
- if (!$payment->getPaymentType()) {
294
- $payment->setPaymentType(self::REQUEST_METHOD_CC);
295
- }
296
- $request = Mage::getModel('creditcard/CCPayment_request');
297
- if ($order && $order->getIncrementId()) {
298
- $request->setInvoiceID($order->getIncrementId());
299
- }
300
- $request->setMode(($this->getConfigData('test_mode') == 'TEST') ? 'TEST' : 'LIVE');
301
-
302
- if ($payment->getAdditionalData()) {
303
- $request->setRrno($payment->getAdditionalData());
304
- $payment->setRrno($payment->getAdditionalData());
305
- }
306
-
307
- $request->setMerchant($this->getConfigData('login'))
308
- ->setTransactionType($payment->getTransactionType())
309
- ->setPaymentType($payment->getPaymentType())
310
- ->setTamperProofSeal($this->calcTPS($payment));
311
- if($payment->getAmount()){
312
- $request->setAmount($payment->getAmount(),2);
313
- }
314
- if ($payment->getCcTransId()){
315
- $request->setRrno($payment->getCcTransId());
316
- }
317
- switch ($payment->getTransactionType()) {
318
- case self::REQUEST_TYPE_CREDIT:
319
- case self::REQUEST_TYPE_VOID:
320
- case self::REQUEST_TYPE_CAPTURE_ONLY:
321
- $request->setRrno($payment->getCcTransId());
322
- break;
323
- }
324
- $cart = Mage::helper('checkout/cart')->getCart()->getItemsCount();
325
- $cartSummary = Mage::helper('checkout/cart')->getCart()->getSummaryQty();
326
- Mage::getSingleton('core/session', array('name'=>'frontend'));
327
- $session = Mage::getSingleton('checkout/session');
328
-
329
- $comment = "";
330
-
331
- foreach ($session->getQuote()->getAllItems() as $item) {
332
-
333
- $comment .= $item->getQty() . ' ';
334
- $comment .= '[' . $item->getSku() . ']' . ' ';
335
- $comment .= $item->getName() . ' ';
336
- $comment .= $item->getDescription() . ' ';
337
- $comment .= $item->getBaseCalculationPrice . ' ';
338
- }
339
-
340
-
341
- if (!empty($order)) {
342
- $billing = $order->getBillingAddress();
343
- if (!empty($billing)) {
344
- $request->setName1($billing->getFirstname())
345
- ->setName2($billing->getLastname())
346
- ->setCompanyName($billing->getCompany())
347
- ->setAddr1($billing->getStreet(1))
348
- ->setCity($billing->getCity())
349
- ->setState($billing->getRegion())
350
- ->setZipcode($billing->getPostcode())
351
- ->setCountry($billing->getCountry())
352
- ->setPhone($billing->getTelephone())
353
- ->setFax($billing->getFax())
354
- ->setCustomId($billing->getCustomerId())
355
- ->setComment($comment)
356
- ->setEmail($order->getCustomerEmail());
357
- }
358
-
359
- $shipping = $order->getShippingAddress();
360
- if (!empty($shipping)) {
361
- $request->setXShipToFirstName($shipping->getFirstname())
362
- ->setXShipToLastName($shipping->getLastname())
363
- ->setXShipToCompany($shipping->getCompany())
364
- ->setXShipToAddress($shipping->getStreet(1))
365
- ->setXShipToCity($shipping->getCity())
366
- ->setXShipToState($shipping->getRegion())
367
- ->setXShipToZip($shipping->getPostcode())
368
- ->setXShipToCountry($shipping->getCountry());
369
- }
370
- }
371
-
372
- switch ($payment->getPaymentType()) {
373
- case self::REQUEST_METHOD_CC:
374
- if($payment->getCcNumber()){
375
- $temp = $payment->getCcExpYear();
376
- $CcExpYear = str_split($temp, 2);
377
- $request->setCcNum($payment->getCcNumber())
378
- ->setCcExpires(sprintf('%02d%02d', $payment->getCcExpMonth(), $CcExpYear[1]))
379
- ->setCvccvv2($payment->getCcCid());
380
- }
381
- break;
382
-
383
- case self::REQUEST_METHOD_ECHECK:
384
- $request->setAchRouting($payment->getEcheckRoutingNumber())
385
- ->setAchAccount($payment->getEcheckAccountNumber())
386
- ->setAchAccountType($payment->getEcheckAccountType())
387
- ->setName($payment->getEcheckAccountName())
388
- ->setDocType($payment->getEcheckType());
389
- break;
390
- }
391
- return $request;
392
- }
393
-
394
- protected function _postRequest(Varien_Object $request)
395
- {
396
- $debugData = array('request' => $request->getData());
397
- //if (!self::$_dupe) {
398
- $result = Mage::getModel('creditcard/CCPayment_result');
399
- //}
400
- if (isset($_POST["?Result"])) {
401
- $_POST["Result"] = $_POST["?Result"];
402
- unset($_POST["?Result"]);
403
- }
404
- if (!isset($_POST["Result"])) {
405
- $client = new Varien_Http_Client();
406
- //$uri = $this->getConfigData('cgi_url');
407
- $uri = 'http://www.assurebuy.com/echo.pl';
408
- $client->setUri($uri ? $uri : self::CGI_URL);
409
- $client->setConfig(array(
410
- 'maxredirects'=>0,
411
- 'timeout'=>30,
412
- 'useragent'=>'BluePay Magento Credit Card Plugin/' . self::CURRENT_VERSION,
413
- ));
414
- $client->setParameterPost($request->getData());
415
- $comma_separated = implode(",", $request->getData());
416
- //Mage::throwException($this->_wrapGatewayError($comma_separated));
417
- $client->setMethod(Zend_Http_Client::POST);
418
- try {
419
- $response = $client->request();
420
- }
421
- catch (Exception $e) {
422
- $debugData['result'] = $result->getData();
423
- $this->_debug($debugData);
424
- Mage::throwException($this->_wrapGatewayError($e->getMessage()));
425
- }
426
- $r = $response->getHeader('location');
427
- //if (self::$_dupe) {
428
- // return $result;
429
- //}
430
- if ($r) {
431
- $result->setResult($this->parseHeader($r, 'value', self::Result))
432
- ->setInvoiceId($this->parseHeader($r, 'value', self::INVOICE_ID))
433
- ->setBankName($this->parseHeader($r, 'value', self::BANK_NAME))
434
- ->setMessage($this->parseHeader($r, 'value', self::MESSAGE))
435
- ->setAuthCode($this->parseHeader($r, 'value', self::AUTH_CODE))
436
- ->setAvs($this->parseHeader($r, 'value', self::AVS))
437
- ->setRrno($this->parseHeader($r, 'value', self::RRNO))
438
- ->setAmount($this->parseHeader($r, 'value', self::AMOUNT))
439
- ->setPaymentType($this->parseHeader($r, 'value', self::PAYMENT_TYPE))
440
- ->setOrderId($this->parseHeader($r, 'value', self::ORDER_ID))
441
- ->setCvv2($this->parseHeader($r, 'value', self::CVV2));
442
- $this->assignBluePayToken($result->getRrno());
443
- }
444
- else {
445
- Mage::throwException(Mage::helper('paygate')->__('Error in payment gateway.'));
446
- }
447
-
448
- $debugData['result'] = $result->getData();
449
- $this->_debug($debugData);
450
- } else {
451
- $result->setResult($_POST["Result"]);
452
- $result->setMessage($_POST["MESSAGE"]);
453
- }
454
- return $result;
455
- }
456
-
457
- protected function _checkDuplicate(Varien_Object $payment)
458
- {
459
- if ($this->getConfigData('duplicate_check') == '0') {
460
- return;
461
- }
462
- $order = $payment->getOrder();
463
- $billing = $order->getBillingAddress();
464
- $reportStart = date("Y-m-d H:i:s", time() - (3600 * 5) - $this->getConfigData('duplicate_check'));
465
- $reportEnd = date("Y-m-d H:i:s", time() - (3600 * 5));
466
- $hashstr = $this->getConfigData('trans_key') . $this->getConfigData('login') .
467
- $reportStart . $reportEnd;
468
- $request = Mage::getModel('creditcard/CCPayment_request');
469
- $request->setData("MODE", $this->getConfigData('test_mode') == 'TEST' ? 'TEST' : 'LIVE');
470
- $request->setData("TAMPER_PROOF_SEAL", bin2hex(md5($hashstr, true)));
471
- $request->setData("ACCOUNT_ID", $this->getConfigData('login'));
472
- $request->setData("REPORT_START_DATE", $reportStart);
473
- $request->setData("REPORT_END_DATE", $reportEnd);
474
- $request->setData("EXCLUDE_ERRORS", 1);
475
- $request->setData("ISNULL_f_void", 1);
476
- $request->setData("name1", $billing['firstname']);
477
- $request->setData("name2", $billing['lastname']);
478
- $request->setData("amount", $payment->getAmount());
479
- $request->setData("status", '1');
480
- $request->setData("IGNORE_NULL_STR", '0');
481
- $request->setData("trans_type", "SALE");
482
- $client = new Varien_Http_Client();
483
-
484
- $client->setUri($uri ? $uri : self::STQ_URL);
485
- $client->setConfig(array(
486
- 'maxredirects'=>0,
487
- 'timeout'=>30,
488
- ));
489
- $client->setParameterPost($request->getData());
490
- $client->setMethod(Zend_Http_Client::POST);
491
- try {
492
- $response = $client->request();
493
- }
494
- catch (Exception $e) {
495
-
496
- $this->_debug($debugData);
497
- Mage::throwException($this->_wrapGatewayError($e->getMessage()));
498
- }
499
- $p = parse_str($client->request()->getBody());
500
- if ($id) {
501
- $conn = Mage::getSingleton('core/resource')->getConnection('core_read');
502
- $result = $conn->fetchAll("SELECT * FROM sales_payment_transaction WHERE txn_id='$id'");
503
- if ($result)
504
- return;
505
- self::$_dupe = true;
506
- $payment->setTransactionType(self::REQUEST_TYPE_CREDIT);
507
- $payment->setCcTransId($id);
508
- $payment->setRrno($id);
509
- $request = $this->_buildRequest($payment);
510
- $result = $this->_postRequest($request);
511
- $payment->setCcTransId('');
512
- }
513
- }
514
-
515
-
516
- /**
517
- * Gateway response wrapper
518
- */
519
- protected function _wrapGatewayError($text)
520
- {
521
- return Mage::helper('paygate')->__('Gateway error: %s', $text);
522
- }
523
-
524
- protected final function calcTPS(Varien_Object $payment) {
525
-
526
- $order = $payment->getOrder();
527
- $billing = $order->getBillingAddress();
528
-
529
- $hashstr = $this->getConfigData('trans_key') . $this->getConfigData('login') .
530
- $payment->getTransactionType() . $payment->getAmount() . $payment->getRrno() .
531
- $this->getConfigData('test_mode');
532
- return bin2hex( md5($hashstr, true) );
533
- }
534
-
535
- protected function parseHeader($header, $nameVal, $pos) {
536
- $nameVal = ($nameVal == 'name') ? '0' : '1';
537
- $s = explode("?", $header);
538
- $t = explode("&", $s[1]);
539
- $value = explode("=", $t[$pos]);
540
- return $value[$nameVal];
541
- }
542
-
543
- public function validate()
544
- {
545
- /*
546
- * calling parent validate function
547
- */
548
- $info = $this->getInfoInstance();
549
- $errorMsg = false;
550
- $availableTypes = explode(',',$this->getConfigData('cctypes'));
551
-
552
- $ccNumber = $info->getCcNumber();
553
-
554
- // remove credit card number delimiters such as "-" and space
555
- $ccNumber = preg_replace('/[\-\s]+/', '', $ccNumber);
556
- $info->setCcNumber($ccNumber);
557
-
558
- $ccType = '';
559
-
560
- if (in_array($info->getCcType(), $availableTypes)){
561
- if ($this->validateCcNum($ccNumber)
562
- // Other credit card type number validation
563
- || ($this->OtherCcType($info->getCcType()) && $this->validateCcNumOther($ccNumber))) {
564
-
565
- $ccType = 'OT';
566
- $ccTypeRegExpList = array(
567
- //Solo, Switch or Maestro. International safe
568
- /*
569
- // Maestro / Solo
570
- 'SS' => '/^((6759[0-9]{12})|(6334|6767[0-9]{12})|(6334|6767[0-9]{14,15})'
571
- . '|(5018|5020|5038|6304|6759|6761|6763[0-9]{12,19})|(49[013][1356][0-9]{12})'
572
- . '|(633[34][0-9]{12})|(633110[0-9]{10})|(564182[0-9]{10}))([0-9]{2,3})?$/',
573
- */
574
- // Solo only
575
- 'SO' => '/(^(6334)[5-9](\d{11}$|\d{13,14}$))|(^(6767)(\d{12}$|\d{14,15}$))/',
576
- 'SM' => '/(^(5[0678])\d{11,18}$)|(^(6[^05])\d{11,18}$)|(^(601)[^1]\d{9,16}$)|(^(6011)\d{9,11}$)'
577
- . '|(^(6011)\d{13,16}$)|(^(65)\d{11,13}$)|(^(65)\d{15,18}$)'
578
- . '|(^(49030)[2-9](\d{10}$|\d{12,13}$))|(^(49033)[5-9](\d{10}$|\d{12,13}$))'
579
- . '|(^(49110)[1-2](\d{10}$|\d{12,13}$))|(^(49117)[4-9](\d{10}$|\d{12,13}$))'
580
- . '|(^(49118)[0-2](\d{10}$|\d{12,13}$))|(^(4936)(\d{12}$|\d{14,15}$))/',
581
- // Visa
582
- 'VI' => '/^4[0-9]{12}([0-9]{3})?$/',
583
- // Master Card
584
- 'MC' => '/^5[1-5][0-9]{14}$/',
585
- // American Express
586
- 'AE' => '/^3[47][0-9]{13}$/',
587
- // Discovery
588
- 'DI' => '/^6011[0-9]{12}$/',
589
- // JCB
590
- 'JCB' => '/^(3[0-9]{15}|(2131|1800)[0-9]{11})$/'
591
- );
592
-
593
- foreach ($ccTypeRegExpList as $ccTypeMatch=>$ccTypeRegExp) {
594
- if (preg_match($ccTypeRegExp, $ccNumber)) {
595
- $ccType = $ccTypeMatch;
596
- break;
597
- }
598
- }
599
-
600
- if (!$this->OtherCcType($info->getCcType()) && $ccType!=$info->getCcType()) {
601
- $errorMsg = Mage::helper('payment')->__('Credit card number mismatch with credit card type.');
602
- }
603
- }
604
- else {
605
- $errorMsg = Mage::helper('payment')->__('Invalid Credit Card Number');
606
- }
607
-
608
- }
609
- else {
610
- $errorMsg = Mage::helper('payment')->__('Credit card type is not allowed for this payment method.');
611
- }
612
-
613
- //validate credit card verification number
614
- if ($errorMsg === false && $this->hasVerification()) {
615
- $verifcationRegEx = $this->getVerificationRegEx();
616
- $regExp = isset($verifcationRegEx[$info->getCcType()]) ? $verifcationRegEx[$info->getCcType()] : '';
617
- if (!$info->getCcCid() || !$regExp || !preg_match($regExp ,$info->getCcCid())){
618
- $errorMsg = Mage::helper('payment')->__('Please enter a valid credit card verification number.');
619
- }
620
- }
621
-
622
- if ($ccType != 'SS' && !$this->_validateExpDate($info->getCcExpYear(), $info->getCcExpMonth())) {
623
- $errorMsg = Mage::helper('payment')->__('Incorrect credit card expiration date.');
624
- }
625
-
626
- if($errorMsg) {
627
- if ($this->getConfigData('use_iframe') == '1') {
628
- $errorMsg = '';
629
- }
630
- }
631
-
632
- //This must be after all validation conditions
633
- if ($this->getIsCentinelValidationEnabled()) {
634
- $this->getCentinelValidator()->validate($this->getCentinelValidationData());
635
- }
636
-
637
- return $this;
638
- }
639
-
640
- public function assignData($data)
641
- {
642
- if (!($data instanceof Varien_Object)) {
643
- $data = new Varien_Object($data);
644
- }
645
-
646
- $info = $this->getInfoInstance();
647
- $info->setCcType($data->getCcType())
648
- ->setCcOwner($data->getCcOwner())
649
- ->setCcLast4(substr($data->getCcNumber(), -4))
650
- ->setCcNumber($data->getCcNumber())
651
- ->setCcCid($data->getCcCid())
652
- ->setCcExpMonth($data->getCcExpMonth())
653
- ->setCcExpYear($data->getCcExpYear())
654
- ->setCcSsIssue($data->getCcSsIssue())
655
- ->setCcSsStartMonth($data->getCcSsStartMonth())
656
- ->setCcSsStartYear($data->getCcSsStartYear())
657
- ->setAdditionalData($data->getBpToken());
658
- return $this;
659
-
660
- }
661
-
662
- public function assignBluePayToken($token)
663
- {
664
- $info = $this->getInfoInstance();
665
- $info->setAdditionalData($token);
666
- }
667
-
668
- public function prepareSave()
669
- {
670
- $info = $this->getInfoInstance();
671
-
672
- if ($this->_canSaveCc) {
673
- $info->setCcNumberEnc($info->encrypt('xxxx-'.$info->getCcLast4()));
674
- }
675
- if ($info->getAdditionalData()) {
676
- $info->setAdditionalData($info->getAdditionalData());
677
- }
678
- //$info->setCcCidEnc($info->encrypt($info->getCcCid()));
679
- $info->setCcNumber(null)
680
- ->setCcCid(null);
681
- return $this;
682
-
683
- }
684
-
685
- public function hasVerificationBackend()
686
- {
687
- $configData = $this->getConfigData('useccv_backend');
688
- if(is_null($configData)){
689
- return true;
690
- }
691
- return (bool) $configData;
692
- }
693
-
694
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>BluePay_CreditCard</name>
4
- <version>1.5.5.8</version>
5
  <stability>stable</stability>
6
  <license>GNU General Public License</license>
7
  <channel>community</channel>
@@ -11,8 +11,8 @@
11
  <notes>Fixed issue with multiple credit memos refunding an invoice</notes>
12
  <authors><author><name>Justin Slingerland</name><user>jslingerland</user><email>jslingerland@bluepay.com</email></author></authors>
13
  <date>2016-02-03</date>
14
- <time>16:27:03</time>
15
- <contents><target name="mageetc"><dir name="modules"><file name="BluePay_CreditCard.xml" hash="8a84b7d3e004f61f9d55e428b55cea8c"/></dir></target><target name="mageweb"><dir name="js"><dir name="bluepay"><file name="bluepay.js" hash="c371e7e864f1b3db25328fa08e3e9c27"/><dir name="easyXDM"><file name="easyXDM.Widgets.debug.js" hash="26b23561d39a64b926fe8dafea2f0a7b"/><file name="easyXDM.Widgets.js" hash="26b23561d39a64b926fe8dafea2f0a7b"/><file name="easyXDM.Widgets.min.js" hash="790f5fa04af75a8013d0ff5fd6dc770d"/><file name="easyXDM.debug.js" hash="2f74fa97b0aacdfb5e8570e381465905"/><file name="easyXDM.js" hash="499464a0c3d89679c11df6ee5d188df5"/><file name="easyXDM.min.js" hash="e3fd912457d7213fe5ccae7bf0fd0c82"/><file name="name.html" hash="990620350432f6c7e28f1e111ce598c8"/><file name=".gitignore" hash="f256c78995e7e95eb33afc3cee8ff195"/></dir></dir></dir></target><target name="magelocal"><dir name="BluePay"><dir name="CreditCard"><dir name="Block"><file name="Form.php" hash="3132dfeb27e31edb4c5a2a862126cdd7"/></dir><dir name="Helper"><file name="Data.php" hash="dc77bf42a31b7dd5dc31b92549c99abc"/></dir><dir name="Model"><dir name="CCPayment"><file name="Debug.php" hash="bde283680e78d3891affd630c0959bc8"/><file name="Request.php" hash="0317b2c7dc66004767405b78a3cc2631"/><file name="Result.php" hash="0d285e50805f03af609c87d91fce092a"/><dir name="Source"><file name="Cctype.php" hash="9d0f6dd894fb1006ed9bedce966f270b"/><file name="PaymentAction.php" hash="a233de610ff201a77d920fd73ecfb24a"/></dir></dir><file name="CCPayment.php" hash="b1b05dc6f7a429a1026c09f86148ff75"/><file name="CCPayment.php~" hash="5eeb7bebef806110f6e36d5dae8280e0"/><file name="Config.php" hash="387ecaf88faa6c7d740b78d9e2dd2db6"/><dir name="Mysql4"><dir name="CCPayment"><dir name="Debug"><file name="Collection.php" hash="9d4c92ad278242715d08b6e202770ce1"/></dir><file name="Debug.php" hash="4f64c922ddb5b80d36538696471b69b5"/></dir></dir></dir><dir name="etc"><file name="config.xml" hash="f514f783fd39e1836b6ef4fc5087ea18"/><file name="system.xml" hash="a7622a714caebe79f607e6aea2fffee1"/></dir><dir name="sql"><dir name="creditcard_setup"><file name="mysql4-install-0.7.0.php" hash="c97f60ff629417efef8beebf619caa9a"/></dir></dir></dir></dir></target><target name="magecore"><dir name="Mage"><dir name="Adminhtml"><dir name="Model"><dir name="System"><dir name="Config"><dir name="Source"><file name="Testmode.php" hash="3f72e89b4f8239ad839d591310468453"/><dir name="Order"><dir name="Status"><file name="Processingcomplete.php" hash="f9eb96ffc645117a04cc094b62fb24d4"/></dir></dir><file name="Duplicatewindow.php" hash="86b5f8c6d10b2cca813919c8aead0464"/></dir></dir></dir></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="template"><dir name="bluepay"><file name="creditcard.phtml" hash="4084bffebe86bead51a4910091fe82a5"/><file name="form.phtml" hash="e5cf9ce8eeaeae71fb3372fb542f7431"/><file name="creditcardiframe.phtml" hash="55c518297c050fc4ce6a82a65d6620b0"/><file name="button.phtml" hash="85af90e7faab002f872f82e3d663139f"/><file name="inforeview.phtml" hash="0d29af5174235ded956fea6e92302a54"/></dir></dir></dir></dir></dir><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="bluepay"><file name="creditcard.phtml" hash="d4a89cf407884beaa1db416cdd450fad"/></dir></dir></dir></dir></dir></target></contents>
16
  <compatible/>
17
  <dependencies><required><php><min>5.3.0</min><max>5.6.99</max></php></required></dependencies>
18
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>BluePay_CreditCard</name>
4
+ <version>1.5.5.9</version>
5
  <stability>stable</stability>
6
  <license>GNU General Public License</license>
7
  <channel>community</channel>
11
  <notes>Fixed issue with multiple credit memos refunding an invoice</notes>
12
  <authors><author><name>Justin Slingerland</name><user>jslingerland</user><email>jslingerland@bluepay.com</email></author></authors>
13
  <date>2016-02-03</date>
14
+ <time>16:37:39</time>
15
+ <contents><target name="mageetc"><dir name="modules"><file name="BluePay_CreditCard.xml" hash="8a84b7d3e004f61f9d55e428b55cea8c"/></dir></target><target name="mageweb"><dir name="js"><dir name="bluepay"><file name="bluepay.js" hash="c371e7e864f1b3db25328fa08e3e9c27"/><dir name="easyXDM"><file name="easyXDM.Widgets.debug.js" hash="26b23561d39a64b926fe8dafea2f0a7b"/><file name="easyXDM.Widgets.js" hash="26b23561d39a64b926fe8dafea2f0a7b"/><file name="easyXDM.Widgets.min.js" hash="790f5fa04af75a8013d0ff5fd6dc770d"/><file name="easyXDM.debug.js" hash="2f74fa97b0aacdfb5e8570e381465905"/><file name="easyXDM.js" hash="499464a0c3d89679c11df6ee5d188df5"/><file name="easyXDM.min.js" hash="e3fd912457d7213fe5ccae7bf0fd0c82"/><file name="name.html" hash="990620350432f6c7e28f1e111ce598c8"/><file name=".gitignore" hash="f256c78995e7e95eb33afc3cee8ff195"/></dir></dir></dir></target><target name="magelocal"><dir name="BluePay"><dir name="CreditCard"><dir name="Block"><file name="Form.php" hash="3132dfeb27e31edb4c5a2a862126cdd7"/></dir><dir name="Helper"><file name="Data.php" hash="dc77bf42a31b7dd5dc31b92549c99abc"/></dir><dir name="Model"><dir name="CCPayment"><file name="Debug.php" hash="bde283680e78d3891affd630c0959bc8"/><file name="Request.php" hash="0317b2c7dc66004767405b78a3cc2631"/><file name="Result.php" hash="0d285e50805f03af609c87d91fce092a"/><dir name="Source"><file name="Cctype.php" hash="9d0f6dd894fb1006ed9bedce966f270b"/><file name="PaymentAction.php" hash="a233de610ff201a77d920fd73ecfb24a"/></dir></dir><file name="CCPayment.php" hash="0782f8480dd567ad2558da66ccbc1c8f"/><file name="Config.php" hash="387ecaf88faa6c7d740b78d9e2dd2db6"/><dir name="Mysql4"><dir name="CCPayment"><dir name="Debug"><file name="Collection.php" hash="9d4c92ad278242715d08b6e202770ce1"/></dir><file name="Debug.php" hash="4f64c922ddb5b80d36538696471b69b5"/></dir></dir></dir><dir name="etc"><file name="config.xml" hash="f514f783fd39e1836b6ef4fc5087ea18"/><file name="system.xml" hash="a7622a714caebe79f607e6aea2fffee1"/></dir><dir name="sql"><dir name="creditcard_setup"><file name="mysql4-install-0.7.0.php" hash="c97f60ff629417efef8beebf619caa9a"/></dir></dir></dir></dir></target><target name="magecore"><dir name="Mage"><dir name="Adminhtml"><dir name="Model"><dir name="System"><dir name="Config"><dir name="Source"><file name="Testmode.php" hash="3f72e89b4f8239ad839d591310468453"/><dir name="Order"><dir name="Status"><file name="Processingcomplete.php" hash="f9eb96ffc645117a04cc094b62fb24d4"/></dir></dir><file name="Duplicatewindow.php" hash="86b5f8c6d10b2cca813919c8aead0464"/></dir></dir></dir></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="template"><dir name="bluepay"><file name="creditcard.phtml" hash="4084bffebe86bead51a4910091fe82a5"/><file name="form.phtml" hash="e5cf9ce8eeaeae71fb3372fb542f7431"/><file name="creditcardiframe.phtml" hash="55c518297c050fc4ce6a82a65d6620b0"/><file name="button.phtml" hash="85af90e7faab002f872f82e3d663139f"/><file name="inforeview.phtml" hash="0d29af5174235ded956fea6e92302a54"/></dir></dir></dir></dir></dir><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="bluepay"><file name="creditcard.phtml" hash="d4a89cf407884beaa1db416cdd450fad"/></dir></dir></dir></dir></dir></target></contents>
16
  <compatible/>
17
  <dependencies><required><php><min>5.3.0</min><max>5.6.99</max></php></required></dependencies>
18
  </package>