BluePay_CreditCard - Version 1.5.6.3

Version Notes

Fixed undefined index errors

Download this release

Release Info

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


Code changes from version 1.5.6.2 to 1.5.6.3

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