Hps_Securesubmit - Version 1.0.0

Version Notes

This extension has been in production for six months with many websites. Many cross-platform (Windows vs. Linux) bugs were fixed during this process and the module has proved stable.

Download this release

Release Info

Developer Heartland Payment Systems
Extension Hps_Securesubmit
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

Files changed (56) hide show
  1. app/code/community/Hps/Securesubmit/Block/Form.php +9 -0
  2. app/code/community/Hps/Securesubmit/Block/Info.php +15 -0
  3. app/code/community/Hps/Securesubmit/Helper/Data.php +47 -0
  4. app/code/community/Hps/Securesubmit/Model/Payment.php +387 -0
  5. app/code/community/Hps/Securesubmit/Model/Resource/Setup.php +5 -0
  6. app/code/community/Hps/Securesubmit/Model/Resource/Storedcard.php +16 -0
  7. app/code/community/Hps/Securesubmit/Model/Resource/Storedcard/Collection.php +8 -0
  8. app/code/community/Hps/Securesubmit/Model/Source/Cctype.php +6 -0
  9. app/code/community/Hps/Securesubmit/Model/Source/PaymentAction.php +17 -0
  10. app/code/community/Hps/Securesubmit/Model/Storedcard.php +33 -0
  11. app/code/community/Hps/Securesubmit/Model/System/Config/Backend/Proxy.php +17 -0
  12. app/code/community/Hps/Securesubmit/controllers/StoredcardController.php +83 -0
  13. app/code/community/Hps/Securesubmit/etc/config.xml +79 -0
  14. app/code/community/Hps/Securesubmit/etc/system.xml +153 -0
  15. app/code/community/Hps/Securesubmit/sql/hps_securesubmit_setup/install-1.0.0.php +69 -0
  16. app/design/adminhtml/default/default/template/securesubmit/form.phtml +79 -0
  17. app/design/frontend/base/default/layout/securesubmit.xml +30 -0
  18. app/design/frontend/base/default/template/securesubmit/form.phtml +178 -0
  19. app/design/frontend/base/default/template/securesubmit/storedcards.phtml +40 -0
  20. app/etc/modules/Hps_Securesubmit.xml +9 -0
  21. js/securesubmit/secure.submit-1.0.1.js +115 -0
  22. lib/SecureSubmit/Hps.php +42 -0
  23. lib/SecureSubmit/entities/HpsAccountVerify.php +7 -0
  24. lib/SecureSubmit/entities/HpsAddress.php +9 -0
  25. lib/SecureSubmit/entities/HpsAuthorization.php +18 -0
  26. lib/SecureSubmit/entities/HpsBatch.php +8 -0
  27. lib/SecureSubmit/entities/HpsCardHolder.php +9 -0
  28. lib/SecureSubmit/entities/HpsCharge.php +7 -0
  29. lib/SecureSubmit/entities/HpsChargeExceptions.php +6 -0
  30. lib/SecureSubmit/entities/HpsCreditCard.php +27 -0
  31. lib/SecureSubmit/entities/HpsItemChoiceTypePosResponseVer10Transaction.php +63 -0
  32. lib/SecureSubmit/entities/HpsRefund.php +7 -0
  33. lib/SecureSubmit/entities/HpsReportTransactionDetails.php +14 -0
  34. lib/SecureSubmit/entities/HpsReportTransactionSummary.php +10 -0
  35. lib/SecureSubmit/entities/HpsReversal.php +13 -0
  36. lib/SecureSubmit/entities/HpsTokenData.php +11 -0
  37. lib/SecureSubmit/entities/HpsTransaction.php +111 -0
  38. lib/SecureSubmit/entities/HpsTransactionDetails.php +8 -0
  39. lib/SecureSubmit/entities/HpsTransactionHeader.php +9 -0
  40. lib/SecureSubmit/entities/HpsTransactionType.php +15 -0
  41. lib/SecureSubmit/entities/HpsVoid.php +7 -0
  42. lib/SecureSubmit/infrastructure/AVSResponseCodeHandler.php +49 -0
  43. lib/SecureSubmit/infrastructure/ApiConnectionException.php +4 -0
  44. lib/SecureSubmit/infrastructure/AuthenticationException.php +9 -0
  45. lib/SecureSubmit/infrastructure/CardException.php +13 -0
  46. lib/SecureSubmit/infrastructure/Exceptions.json +469 -0
  47. lib/SecureSubmit/infrastructure/HpsConfiguration.php +17 -0
  48. lib/SecureSubmit/infrastructure/HpsException.php +21 -0
  49. lib/SecureSubmit/infrastructure/HpsExceptionMapper.php +109 -0
  50. lib/SecureSubmit/infrastructure/HpsSdkCodes.php +14 -0
  51. lib/SecureSubmit/infrastructure/InvalidRequestException.php +10 -0
  52. lib/SecureSubmit/services/HpsBatchService.php +26 -0
  53. lib/SecureSubmit/services/HpsChargeService.php +602 -0
  54. lib/SecureSubmit/services/HpsService.php +129 -0
  55. lib/SecureSubmit/services/HpsTokenService.php +59 -0
  56. package.xml +20 -0
app/code/community/Hps/Securesubmit/Block/Form.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Hps_Securesubmit_Block_Form extends Mage_Payment_Block_Form_Ccsave
3
+ {
4
+ protected function _construct()
5
+ {
6
+ parent::_construct();
7
+ $this->setTemplate('securesubmit/form.phtml');
8
+ }
9
+ }
app/code/community/Hps/Securesubmit/Block/Info.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Hps_Securesubmit_Block_Info extends Mage_Payment_Block_Info
3
+ {
4
+ protected function _prepareSpecificInformation($transport = null)
5
+ {
6
+ $transport = parent::_prepareSpecificInformation($transport);
7
+ $data = array();
8
+ $info = $this->getInfo();
9
+
10
+ $data[Mage::helper("payment")->__("Payment Type")] = "Secure Token";
11
+
12
+ return $transport->setData(array_merge($data, $transport->getData()));
13
+ }
14
+ }
15
+
app/code/community/Hps/Securesubmit/Helper/Data.php ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Hps_Securesubmit_Helper_Data extends Mage_Core_Helper_Abstract
3
+ {
4
+ const XML_PATH_PAYMENT_HPS_SECURESUBMIT_USE_HTTP_PROXY = 'payment/hps_securesubmit/use_http_proxy';
5
+ const XML_PATH_PAYMENT_HPS_SECURESUBMIT_HTTP_PROXY_HOST = 'payment/hps_securesubmit/http_proxy_host';
6
+ const XML_PATH_PAYMENT_HPS_SECURESUBMIT_HTTP_PROXY_PORT = 'payment/hps_securesubmit/http_proxy_port';
7
+
8
+ /**
9
+ * @param $customerId
10
+ * @return Hps_Securesubmit_Model_Storedcard[]|Hps_Securesubmit_Model_Resource_Storedcard_Collection
11
+ */
12
+ public function getStoredCards($customerId)
13
+ {
14
+ $cardCollection = Mage::getResourceModel('hps_securesubmit/storedcard_collection')
15
+ ->addFieldToFilter('customer_id', $customerId);
16
+ return $cardCollection;
17
+ }
18
+
19
+ public function saveMultiToken($token,$cardData,$cardType)
20
+ {
21
+ $_session = Mage::getSingleton('customer/session');
22
+ $_loggedIn = $_session->isLoggedIn();
23
+
24
+ if($_loggedIn){
25
+ $_customerId = $_session->getCustomer()->getId();
26
+
27
+ $storedCard = Mage::getModel('hps_securesubmit/storedcard');
28
+ $storedCard->setDt(Varien_Date::now())
29
+ ->setCustomerId($_customerId)
30
+ ->setTokenValue($token)
31
+ ->setCcType($cardType)
32
+ ->setCcLast4($cardData->number)
33
+ ->setCcExpMonth(str_pad($cardData->expMonth, 2, '0', STR_PAD_LEFT))
34
+ ->setCcExpYear($cardData->expYear);
35
+ try{
36
+ $storedCard->removeDuplicates();
37
+ $storedCard->save();
38
+ return $storedCard;
39
+ }catch (Exception $e){
40
+ if($e->getCode() == '23000'){
41
+ Mage::throwException($this->__('Customer Not Found : Card could not be saved.'));
42
+ }
43
+ Mage::throwException($e->getMessage());
44
+ }
45
+ }
46
+ }
47
+ }
app/code/community/Hps/Securesubmit/Model/Payment.php ADDED
@@ -0,0 +1,387 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ require_once Mage::getBaseDir('lib').DS.'SecureSubmit'.DS.'Hps.php';
4
+
5
+ class Hps_Securesubmit_Model_Payment extends Mage_Payment_Model_Method_Cc
6
+ {
7
+ protected $_code = 'hps_securesubmit';
8
+ protected $_isGateway = true;
9
+ protected $_canCapture = true;
10
+ protected $_canCapturePartial = true;
11
+ protected $_canRefund = true;
12
+ protected $_canRefundInvoicePartial = true;
13
+ protected $_canVoid = true;
14
+ protected $_canAuthorize = true;
15
+
16
+ protected $_supportedCurrencyCodes = array('USD');
17
+ protected $_minOrderTotal = 0.5;
18
+
19
+ protected $_formBlockType = 'hps_securesubmit/form';
20
+ protected $_infoBlockType = 'hps_securesubmit/info';
21
+
22
+ /**
23
+ * Fields that should be replaced in debug with '***'
24
+ *
25
+ * @var array
26
+ */
27
+ protected $_debugReplacePrivateDataKeys = array('SecretAPIKey');
28
+
29
+ public function validate()
30
+ {
31
+ $info = $this->getInfoInstance();
32
+ $additionalData = new Varien_Object($info->getAdditionalData() ? unserialize($info->getAdditionalData()) : null);
33
+
34
+ // Only validate when not using token
35
+ if ($additionalData->getUseCreditCard()) {
36
+ parent::validate();
37
+ }
38
+
39
+ return $this;
40
+ }
41
+
42
+ /**
43
+ * Capture payment
44
+ *
45
+ * @param Varien_Object $payment
46
+ * @param float $amount
47
+ * @return $this
48
+ */
49
+ public function capture(Varien_Object $payment, $amount)
50
+ {
51
+ $this->_authorize($payment, $amount, true);
52
+ }
53
+
54
+ /**
55
+ * Authorize payment
56
+ *
57
+ * @param Varien_Object $payment
58
+ * @param float $amount
59
+ * @return $this
60
+ */
61
+ public function authorize(Varien_Object $payment, $amount)
62
+ {
63
+ $this->_authorize($payment, $amount, false);
64
+ }
65
+
66
+ /**
67
+ * Authorize or Capture payment
68
+ *
69
+ * @param Varien_Object $payment
70
+ * @param float $amount
71
+ * @param bool $capture
72
+ * @return $this
73
+ */
74
+ private function _authorize(Varien_Object $payment, $amount, $capture)
75
+ {
76
+ $order = $payment->getOrder(); /* @var $order Mage_Sales_Model_Order */
77
+ $billing = $order->getBillingAddress();
78
+ $multiToken = false;
79
+ $cardData = null;
80
+ $cardType = null;
81
+ $additionalData = new Varien_Object($payment->getAdditionalData() ? unserialize($payment->getAdditionalData()) : null);
82
+ $secureToken = $additionalData->getSecuresubmitToken() ? $additionalData->getSecuresubmitToken() : null;
83
+ $saveCreditCard = !! $additionalData->getCcSaveFuture();
84
+ $useCreditCard = !! $additionalData->getUseCreditCard();
85
+
86
+ if ($saveCreditCard && ! $useCreditCard) {
87
+ $multiToken = true;
88
+ $cardData = new HpsCreditCard();
89
+ $cardData->number = $payment->getCcLast4();
90
+ $cardData->expYear = $payment->getCcExpYear();
91
+ $cardData->expMonth = $payment->getCcExpMonth();
92
+ }
93
+
94
+ $config = new HpsConfiguration();
95
+ // Use HTTP proxy
96
+ if (Mage::getStoreConfig('payment/hps_securesubmit/use_http_proxy')) {
97
+ $config->useProxy = true;
98
+ $config->proxyOptions = array(
99
+ 'proxy_host' => Mage::getStoreConfig('payment/hps_securesubmit/http_proxy_host'),
100
+ 'proxy_port' => Mage::getStoreConfig('payment/hps_securesubmit/http_proxy_port'),
101
+ );
102
+ }
103
+
104
+ $config->secretApiKey = $this->getConfigData('secretapikey');
105
+ $config->versionNumber = '1573';
106
+ $config->developerId = '002914';
107
+
108
+ $chargeService = new HpsChargeService($config);
109
+
110
+ $address = new HpsAddress();
111
+ $address->address = $billing->getStreet(1);
112
+ $address->city = $billing->getCity();
113
+ $address->state = $billing->getRegion();
114
+ $address->zip = preg_replace('/[^0-9]/', '', $billing->getPostcode());
115
+ $address->country = $billing->getCountry();
116
+
117
+ $cardHolder = new HpsCardHolder();
118
+ $cardHolder->firstName = $billing->getData('firstname');
119
+ $cardHolder->lastName = $billing->getData('lastname');
120
+ $cardHolder->phone = preg_replace('/[^0-9]/', '', $billing->getTelephone());
121
+ $cardHolder->emailAddress = $billing->getData('email');
122
+ $cardHolder->address = $address;
123
+
124
+ if ($useCreditCard) {
125
+ $cardOrToken = new HpsCreditCard();
126
+ $cardOrToken->number = $payment->getCcNumber();
127
+ $cardOrToken->expYear = $payment->getCcExpYear();
128
+ $cardOrToken->expMonth = $payment->getCcExpMonth();
129
+ $cardOrToken->cvv = $payment->getCcCid();
130
+ } else {
131
+ $cardOrToken = new HpsTokenData();
132
+ $cardOrToken->tokenValue = $secureToken;
133
+ }
134
+
135
+ $details = new HpsTransactionDetails();
136
+ $details->invoiceNumber = $order->getIncrementId();
137
+
138
+ try
139
+ {
140
+ if ($capture)
141
+ {
142
+ if ($payment->getCcTransId())
143
+ {
144
+ $response = $chargeService->capture(
145
+ $payment->getCcTransId(),
146
+ $amount);
147
+ }
148
+ else
149
+ {
150
+ $response = $chargeService->charge(
151
+ $amount,
152
+ strtolower($order->getBaseCurrencyCode()),
153
+ $cardOrToken,
154
+ $cardHolder,
155
+ $multiToken,
156
+ $details);
157
+ }
158
+ }
159
+ else
160
+ {
161
+ $response = $chargeService->authorize(
162
+ $amount,
163
+ strtolower($order->getBaseCurrencyCode()),
164
+ $cardOrToken,
165
+ $cardHolder,
166
+ $multiToken,
167
+ $details);
168
+ }
169
+ }
170
+ catch (CardException $e) {
171
+ $this->_debugChargeService($chargeService, $e);
172
+ $payment->setStatus(self::STATUS_DECLINED);
173
+ $this->throwUserError($e->getMessage(), $e->ResultText, TRUE);
174
+ }
175
+ catch (Exception $e)
176
+ {
177
+ $this->_debugChargeService($chargeService, $e);
178
+ Mage::logException($e);
179
+ $payment->setStatus(self::STATUS_ERROR);
180
+ $this->throwUserError($e->getMessage());
181
+ }
182
+
183
+ // No exception thrown so action was a success
184
+ $this->_debugChargeService($chargeService);
185
+ $payment->setStatus(self::STATUS_APPROVED);
186
+ $payment->setAmount($amount);
187
+ $payment->setLastTransId($response->transactionId);
188
+ $payment->setCcTransId($response->transactionId);
189
+ $payment->setTransactionId($response->transactionId);
190
+ $payment->setIsTransactionClosed(0);
191
+ if($multiToken){
192
+ if ($response->tokenData->responseCode == '0') {
193
+ Mage::helper('hps_securesubmit')->saveMultiToken($response->tokenData->tokenValue,$cardData,$response->cardType);
194
+ } else {
195
+ Mage::log(Mage::helper('hps_securesubmit')->__('Requested multi token has not been generated for the transaction # %s.', $response->transactionId), Zend_Log::WARN);
196
+ }
197
+ }
198
+ return $this;
199
+ }
200
+
201
+ public function refund(Varien_Object $payment, $amount)
202
+ {
203
+ if ($this->canVoid($payment)) {
204
+ // First try to void the payment and if the batch is already closed - try to refund the payment.
205
+ try {
206
+ $this->void($payment);
207
+ } catch (Mage_Core_Exception $e) {
208
+ $this->_refund($payment, $amount);
209
+ }
210
+ } else {
211
+ $this->_refund($payment, $amount);
212
+ }
213
+ return $this;
214
+ }
215
+
216
+ /**
217
+ * Void payment abstract method
218
+ *
219
+ * @param Varien_Object $payment
220
+ *
221
+ * @return Hps_Securesubmit_Model_Payment
222
+ */
223
+ public function void(Varien_Object $payment)
224
+ {
225
+ $transactionId = $payment->getCcTransId();
226
+
227
+ $config = new HpsServicesConfig();
228
+ $config->secretAPIKey = $this->getConfigData('secretapikey');
229
+ $config->versionNbr = '1509';
230
+ $config->developerId = '002914';
231
+
232
+ $chargeService = new HpsChargeService($config);
233
+ try {
234
+ $voidResponse = $chargeService->void($transactionId);
235
+ }
236
+ catch (HpsException $e)
237
+ {
238
+ $this->_debugChargeService($chargeService, $e);
239
+ Mage::throwException($e->getMessage());
240
+ }
241
+ catch (Exception $e) {
242
+ $this->_debugChargeService($chargeService, $e);
243
+ Mage::logException($e);
244
+ Mage::throwException(Mage::helper('hps_securesubmit')->__('An unexpected error occurred. Please try again or contact a system administrator.'));
245
+ }
246
+ $this->_debugChargeService($chargeService);
247
+
248
+ $payment
249
+ ->setTransactionId($voidResponse->TransactionId)
250
+ ->setParentTransactionId($transactionId)
251
+ ->setIsTransactionClosed(1)
252
+ ->setShouldCloseParentTransaction(1);
253
+
254
+ return $this;
255
+ }
256
+
257
+ protected function _refund(Varien_Object $payment, $amount)
258
+ {
259
+ $transactionId = $payment->getCcTransId();
260
+ $order = $payment->getOrder();
261
+
262
+ $config = new HpsConfiguration();
263
+ $config->secretApiKey = $this->getConfigData('secretapikey');
264
+ $config->versionNumber = '1573';
265
+ $config->developerId = '002914';
266
+
267
+ $chargeService = new HpsChargeService($config);
268
+ try {
269
+ $refundResponse = $chargeService->refundTransaction(
270
+ $amount,
271
+ strtolower($order->getBaseCurrencyCode()),
272
+ $transactionId);
273
+
274
+ }
275
+ catch (HpsException $e)
276
+ {
277
+ $this->_debugChargeService($chargeService, $e);
278
+ $this->throwUserError($e->getMessage());
279
+ }
280
+ catch (Exception $e) {
281
+ $this->_debugChargeService($chargeService, $e);
282
+ Mage::logException($e);
283
+ $this->throwUserError($e->getMessage());
284
+ }
285
+ $this->_debugChargeService($chargeService);
286
+
287
+ $payment
288
+ ->setTransactionId($refundResponse->transactionId)
289
+ ->setParentTransactionId($transactionId)
290
+ ->setIsTransactionClosed(1)
291
+ ->setShouldCloseParentTransaction(1);
292
+
293
+ return $this;
294
+ }
295
+
296
+ public function isAvailable($quote = null)
297
+ {
298
+ if($quote && $quote->getBaseGrandTotal()<$this->_minOrderTotal) {
299
+ return false;
300
+ }
301
+
302
+ return $this->getConfigData('secretapikey', ($quote ? $quote->getStoreId() : null))
303
+ && parent::isAvailable($quote);
304
+ }
305
+
306
+ public function canUseForCurrency($currencyCode)
307
+ {
308
+ if (!in_array($currencyCode, $this->_supportedCurrencyCodes)) {
309
+ return false;
310
+ }
311
+
312
+ return true;
313
+ }
314
+
315
+ public function assignData($data)
316
+ {
317
+ parent::assignData($data);
318
+
319
+ if ( ! ($data instanceof Varien_Object)) {
320
+ $data = new Varien_Object($data);
321
+ }
322
+ $info = $this->getInfoInstance();
323
+
324
+ if ( ! $info->getCcLast4() && $data->getCcLastFour()) {
325
+ $info->setCcLast4($data->getCcLastFour());
326
+ }
327
+
328
+ $details = array();
329
+ if ($data->getData('cc_save_future')) {
330
+ $details['cc_save_future'] = 1;
331
+ }
332
+ if ($data->getData('securesubmit_token')) {
333
+ $details['securesubmit_token'] = $data->getData('securesubmit_token');
334
+ }
335
+ if ($data->getData('use_credit_card')) {
336
+ $details['use_credit_card'] = 1;
337
+ }
338
+ if ( ! empty($details)) {
339
+ $this->getInfoInstance()->setAdditionalData(serialize($details));
340
+ }
341
+
342
+ return $this;
343
+ }
344
+
345
+ /**
346
+ * @param string $error
347
+ * @param string $detailedError
348
+ * @param bool $goToPaymentSection
349
+ * @throws Mage_Core_Exception
350
+ */
351
+ public function throwUserError($error, $detailedError = NULL, $goToPaymentSection = FALSE)
352
+ {
353
+ // Register detailed error for error reporting elsewhere
354
+ $detailedError = $detailedError ? $error.' ['.$detailedError.']' : $error;
355
+ Mage::unregister('payment_detailed_error');
356
+ Mage::register('payment_detailed_error', $detailedError);
357
+
358
+ // Replace gateway error with custom error message for customers
359
+ $error = Mage::helper('hps_securesubmit')->__($error);
360
+ if ($customMessage = $this->getConfigData('custom_message')) {
361
+ $error = sprintf($customMessage, $error);
362
+ }
363
+
364
+ // Send checkout session back to payment section to avoid double-attempt to charge single-use token
365
+ if ($goToPaymentSection && Mage::app()->getRequest()->getOriginalPathInfo() == '/checkout/onepage/saveOrder') {
366
+ Mage::getSingleton('checkout/session')->setGotoSection('payment');
367
+ }
368
+ throw new Mage_Core_Exception($error);
369
+ }
370
+
371
+ /**
372
+ * @param HpsChargeService $chargeService
373
+ * @param Exception|null $exception
374
+ */
375
+ public function _debugChargeService(HpsChargeService $chargeService, $exception = NULL)
376
+ {
377
+ if ($this->getDebugFlag()) {
378
+ $this->_debug(array(
379
+ 'store' => Mage::app()->getStore($this->getStore())->getFrontendName(),
380
+ 'exception_message' => $exception ? get_class($exception).': '.$exception->getMessage() : '',
381
+ 'last_request' => $chargeService->lastRequest,
382
+ 'last_response' => $chargeService->lastResponse,
383
+ ));
384
+ }
385
+ }
386
+
387
+ }
app/code/community/Hps/Securesubmit/Model/Resource/Setup.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+
3
+ class Hps_Securesubmit_Model_Resource_Setup extends Mage_Core_Model_Resource_Setup{
4
+
5
+ }
app/code/community/Hps/Securesubmit/Model/Resource/Storedcard.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Hps_Securesubmit_Model_Resource_Storedcard extends Mage_Core_Model_Resource_Db_Abstract{
4
+ protected function _construct()
5
+ {
6
+ $this->_init('hps_securesubmit/storedcard', 'storedcard_id');
7
+ }
8
+
9
+ public function removeDuplicates(Hps_Securesubmit_Model_Storedcard $storedcard)
10
+ {
11
+ $this->_getWriteAdapter()->delete($this->getMainTable(), array(
12
+ 'customer_id = ?' => $storedcard->getCustomerId(),
13
+ 'token_value = ?' => $storedcard->getTokenValue()
14
+ ));
15
+ }
16
+ }
app/code/community/Hps/Securesubmit/Model/Resource/Storedcard/Collection.php ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Hps_Securesubmit_Model_Resource_Storedcard_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract {
4
+ protected function _construct()
5
+ {
6
+ $this->_init('hps_securesubmit/storedcard');
7
+ }
8
+ }
app/code/community/Hps/Securesubmit/Model/Source/Cctype.php ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ <?php
2
+ class Hps_Securesubmit_Model_Source_Cctype extends Mage_Payment_Model_Source_Cctype
3
+ {
4
+ protected $_allowedTypes = array('AE','VI','MC','DI','JCB','OT');
5
+
6
+ }
app/code/community/Hps/Securesubmit/Model/Source/PaymentAction.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Hps_Securesubmit_Model_Source_PaymentAction
3
+ {
4
+ public function toOptionArray()
5
+ {
6
+ return array(
7
+ array(
8
+ 'value' => Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE,
9
+ 'label' => 'Authorize'
10
+ ),
11
+ array(
12
+ 'value' => Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE_CAPTURE,
13
+ 'label' => 'Authorize and Capture'
14
+ ),
15
+ );
16
+ }
17
+ }
app/code/community/Hps/Securesubmit/Model/Storedcard.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @method Hps_Securesubmit_Model_Resource_Storedcard getResource()
4
+ * @method string getDt()
5
+ * @method Hps_Securesubmit_Model_Storedcard setDt(string $value)
6
+ * @method int getCustomerId()
7
+ * @method Hps_Securesubmit_Model_Storedcard setCustomerId(int $value)
8
+ * @method string getTokenValue()
9
+ * @method Hps_Securesubmit_Model_Storedcard setTokenValue(string $value)
10
+ * @method string getCcType()
11
+ * @method Hps_Securesubmit_Model_Storedcard setCcType(string $value)
12
+ * @method string getCcLast4()
13
+ * @method Hps_Securesubmit_Model_Storedcard setCcLast4(string $value)
14
+ * @method string getCcExpMonth()
15
+ * @method Hps_Securesubmit_Model_Storedcard setCcExpMonth(string $value)
16
+ * @method string getCcExpYear()
17
+ * @method Hps_Securesubmit_Model_Storedcard setCcExpYear(string $value)
18
+ */
19
+ class Hps_Securesubmit_Model_Storedcard extends Mage_Core_Model_Abstract
20
+ {
21
+
22
+ protected function _construct()
23
+ {
24
+ $this->_init('hps_securesubmit/storedcard');
25
+ }
26
+
27
+ public function removeDuplicates()
28
+ {
29
+ $this->getResource()->removeDuplicates($this);
30
+ return $this;
31
+ }
32
+
33
+ }
app/code/community/Hps/Securesubmit/Model/System/Config/Backend/Proxy.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Hps_Securesubmit_Model_System_Config_Backend_Proxy extends Mage_Core_Model_Config_Data
3
+ {
4
+ protected function _beforeSave()
5
+ {
6
+ if ($this->getFieldsetDataValue('use_http_proxy')) {
7
+ $httpProxyHost = $this->getFieldsetDataValue('http_proxy_host');
8
+ if (empty($httpProxyHost)) {
9
+ Mage::throwException(Mage::helper('hps_securesubmit')->__('HTTP Proxy Host is required for using proxy.'));
10
+ }
11
+ $httpProxyPort = $this->getFieldsetDataValue('http_proxy_port');
12
+ if (empty($httpProxyPort)) {
13
+ Mage::throwException(Mage::helper('hps_securesubmit')->__('HTTP Proxy Port is required for using proxy.'));
14
+ }
15
+ }
16
+ }
17
+ }
app/code/community/Hps/Securesubmit/controllers/StoredcardController.php ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Hps_Securesubmit_StoredcardController extends Mage_core_Controller_Front_Action
4
+ {
5
+
6
+ public function preDispatch()
7
+ {
8
+ parent::preDispatch();
9
+
10
+ if (!Mage::getSingleton('customer/session')->authenticate($this)) {
11
+ $this->setFlag('', self::FLAG_NO_DISPATCH, true);
12
+ }
13
+ }
14
+
15
+ /*
16
+ * Customer Account > Manage Cards
17
+ *
18
+ * Shows customer list of their stored cards
19
+ */
20
+ public function indexAction()
21
+ {
22
+ $this->loadLayout();
23
+ $this->renderLayout();
24
+ }
25
+
26
+ /*
27
+ * Customer can delete their stored cards
28
+ */
29
+ public function deleteAction()
30
+ {
31
+ try{
32
+ $storedCard = Mage::getModel('hps_securesubmit/storedcard');
33
+ $storedCard->load($this->getRequest()->getParam('storedcard_id'));
34
+ if ( ! $storedCard->getId() || $storedCard->getCustomerId() != Mage::getSingleton('customer/session')->getCustomerId()) {
35
+ throw new Mage_Core_Exception($this->__('Stored card no longer exists.'));
36
+ }
37
+ $storedCard->delete();
38
+ Mage::getSingleton('customer/session')->addSuccess($this->__('Stored card has been deleted.'));
39
+ }
40
+ catch (Mage_Core_Exception $e) {
41
+ Mage::getSingleton('customer/session')->addError($e->getMessage());
42
+ }
43
+ catch (Exception $e) {
44
+ Mage::logException($e);
45
+ Mage::getSingleton('customer/session')->addError($this->__('An unexpected error occurred deleting your stored card. We apologize for the inconvenience, please contact us for further support.'));
46
+ }
47
+ $this->_redirect('*/*');
48
+ }
49
+
50
+ /*
51
+ * Get token data during checkout
52
+ */
53
+ public function getTokenDataAction()
54
+ {
55
+ try {
56
+ $storedCard = Mage::getModel('hps_securesubmit/storedcard');
57
+ $storedCard->load($this->getRequest()->getParam('storedcard_id'));
58
+ if ( ! $storedCard->getId() || $storedCard->getCustomerId() != Mage::getSingleton('customer/session')->getCustomerId()) {
59
+ throw new Mage_Core_Exception($this->__('Stored card no longer exists.'));
60
+ }
61
+ $result = array(
62
+ 'error' => FALSE,
63
+ 'token' => array(
64
+ 'token_value' => $storedCard->getTokenValue(),
65
+ 'cc_last4' => $storedCard->getCcLast4(),
66
+ 'cc_exp_month' => $storedCard->getCcExpMonth(),
67
+ 'cc_exp_year' => $storedCard->getCcExpYear(),
68
+ 'cc_type' => $storedCard->getCcType(),
69
+ )
70
+ );
71
+ }
72
+ catch (Mage_Core_Exception $e) {
73
+ $result = array('error' => TRUE, 'message' => $e->getMessage());
74
+ }
75
+ catch (Exception $e) {
76
+ Mage::logException($e);
77
+ $result = array('error' => TRUE, 'message' => $this->__('An unexpected error occurred retrieving your stored card. We apologize for the inconvenience, please contact us for further support.'));
78
+ }
79
+ $this->getResponse()->setHeader('Content-Type', 'application/json', TRUE);
80
+ $this->getResponse()->setBody(json_encode($result));
81
+ }
82
+
83
+ }
app/code/community/Hps/Securesubmit/etc/config.xml ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <modules>
4
+ <Hps_Securesubmit>
5
+ <version>1.0.0</version>
6
+ </Hps_Securesubmit>
7
+ </modules>
8
+ <global>
9
+ <resources>
10
+ <hps_securesubmit_setup>
11
+ <setup>
12
+ <module>Hps_Securesubmit</module>
13
+ <class>Hps_Securesubmit_Model_Resource_Setup</class>
14
+ </setup>
15
+ </hps_securesubmit_setup>
16
+ </resources>
17
+ <models>
18
+ <hps_securesubmit>
19
+ <class>Hps_Securesubmit_Model</class>
20
+ <resourceModel>hps_securesubmit_resource</resourceModel>
21
+ </hps_securesubmit>
22
+ <hps_securesubmit_resource>
23
+ <class>Hps_Securesubmit_Model_Resource</class>
24
+ <entities>
25
+ <storedcard>
26
+ <table>storedcard</table>
27
+ </storedcard>
28
+ </entities>
29
+ </hps_securesubmit_resource>
30
+ </models>
31
+ <helpers>
32
+ <hps_securesubmit>
33
+ <class>Hps_Securesubmit_Helper</class>
34
+ </hps_securesubmit>
35
+ </helpers>
36
+ <blocks>
37
+ <hps_securesubmit>
38
+ <class>Hps_Securesubmit_Block</class>
39
+ </hps_securesubmit>
40
+ </blocks>
41
+ </global>
42
+ <default>
43
+ <payment>
44
+ <hps_securesubmit>
45
+ <model>hps_securesubmit/payment</model>
46
+ <payment_action>authorize_capture</payment_action>
47
+ <title>Credit Card (SecureSubmit)</title>
48
+ <cctypes>AE,VI,MC,DI,JCB</cctypes>
49
+ <useccv>1</useccv>
50
+ <min_order_total>0.50</min_order_total>
51
+ <secretapikey backend_model="adminhtml/system_config_backend_encrypted" />
52
+ <publicapikey backend_model="adminhtml/system_config_backend_encrypted" />
53
+ <use_http_proxy>0</use_http_proxy>
54
+ <debug>0</debug>
55
+ </hps_securesubmit>
56
+ </payment>
57
+ </default>
58
+ <frontend>
59
+ <secure_url>
60
+ <securesubmit>/securesubmit/</securesubmit>
61
+ </secure_url>
62
+ <layout>
63
+ <updates>
64
+ <hps_securesubmit module="Hps_Securesubmit">
65
+ <file>securesubmit.xml</file>
66
+ </hps_securesubmit>
67
+ </updates>
68
+ </layout>
69
+ <routers>
70
+ <hps_securesubmit>
71
+ <use>standard</use>
72
+ <args>
73
+ <module>Hps_Securesubmit</module>
74
+ <frontName>securesubmit</frontName>
75
+ </args>
76
+ </hps_securesubmit>
77
+ </routers>
78
+ </frontend>
79
+ </config>
app/code/community/Hps/Securesubmit/etc/system.xml ADDED
@@ -0,0 +1,153 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <sections>
4
+ <payment>
5
+ <groups>
6
+ <hps_securesubmit translate="label" module="hps_securesubmit">
7
+ <label>Secure Submit</label>
8
+ <frontend_type>text</frontend_type>
9
+ <sort_order>20</sort_order>
10
+ <show_in_default>1</show_in_default>
11
+ <show_in_website>1</show_in_website>
12
+ <show_in_store>1</show_in_store>
13
+ <comment><![CDATA[<a href="http://developer.heartlandpaymentsystems.com/SecureSubmit" target="_blank">Click here to sign up for SecureSubmit account</a>]]></comment>
14
+ <fields>
15
+ <active translate="label">
16
+ <label>Enabled</label>
17
+ <frontend_type>select</frontend_type>
18
+ <source_model>adminhtml/system_config_source_yesno</source_model>
19
+ <sort_order>10</sort_order>
20
+ <show_in_default>1</show_in_default>
21
+ <show_in_website>1</show_in_website>
22
+ <show_in_store>0</show_in_store>
23
+ </active>
24
+ <order_status translate="label">
25
+ <label>New order status</label>
26
+ <frontend_type>select</frontend_type>
27
+ <source_model>adminhtml/system_config_source_order_status_processing</source_model>
28
+ <sort_order>4</sort_order>
29
+ <show_in_default>1</show_in_default>
30
+ <show_in_website>1</show_in_website>
31
+ <show_in_store>0</show_in_store>
32
+ </order_status>
33
+ <title translate="label">
34
+ <label>Title</label>
35
+ <frontend_type>text</frontend_type>
36
+ <sort_order>20</sort_order>
37
+ <show_in_default>1</show_in_default>
38
+ <show_in_website>1</show_in_website>
39
+ <show_in_store>1</show_in_store>
40
+ </title>
41
+ <secretapikey translate="label">
42
+ <label>Secret Api Key</label>
43
+ <frontend_type>obscure</frontend_type>
44
+ <backend_model>adminhtml/system_config_backend_encrypted</backend_model>
45
+ <sort_order>30</sort_order>
46
+ <show_in_default>1</show_in_default>
47
+ <show_in_website>1</show_in_website>
48
+ <show_in_store>1</show_in_store>
49
+ </secretapikey>
50
+ <publicapikey translate="label">
51
+ <label>Public Api Key</label>
52
+ <frontend_type>obscure</frontend_type>
53
+ <backend_model>adminhtml/system_config_backend_encrypted</backend_model>
54
+ <sort_order>40</sort_order>
55
+ <show_in_default>1</show_in_default>
56
+ <show_in_website>1</show_in_website>
57
+ <show_in_store>1</show_in_store>
58
+ </publicapikey>
59
+ <cctypes translate="label">
60
+ <label>Credit Card Types</label>
61
+ <frontend_type>multiselect</frontend_type>
62
+ <source_model>hps_securesubmit/source_cctype</source_model>
63
+ <sort_order>50</sort_order>
64
+ <show_in_default>1</show_in_default>
65
+ <show_in_website>1</show_in_website>
66
+ <show_in_store>0</show_in_store>
67
+ </cctypes>
68
+ <payment_action translate="label">
69
+ <label>Payment Action</label>
70
+ <frontend_type>select</frontend_type>
71
+ <source_model>hps_securesubmit/source_paymentAction</source_model>
72
+ <sort_order>60</sort_order>
73
+ <show_in_default>1</show_in_default>
74
+ <show_in_website>1</show_in_website>
75
+ <show_in_store>0</show_in_store>
76
+ </payment_action>
77
+ <allow_card_saving translate="label">
78
+ <label>Allow Card Saving</label>
79
+ <frontend_type>select</frontend_type>
80
+ <source_model>adminhtml/system_config_source_yesno</source_model>
81
+ <sort_order>60</sort_order>
82
+ <show_in_default>1</show_in_default>
83
+ <show_in_website>1</show_in_website>
84
+ <show_in_store>1</show_in_store>
85
+ <comment><![CDATA[
86
+ Heartland Account must be configured for multi-use tokenization.]]>
87
+ </comment>
88
+ </allow_card_saving>
89
+ <custom_message>
90
+ <label>Custom Error Message</label>
91
+ <frontend_type>textarea</frontend_type>
92
+ <sort_order>65</sort_order>
93
+ <show_in_default>1</show_in_default>
94
+ <show_in_website>1</show_in_website>
95
+ <show_in_store>1</show_in_store>
96
+ <comment><![CDATA[
97
+ To use the default Secure Submit error message use %s in the custom message text, ex.
98
+ My message. %s -> will be displayed as: My message. Original Secure Submit message.]]>
99
+ </comment>
100
+ </custom_message>
101
+ <sort_order translate="label">
102
+ <label>Sort Order</label>
103
+ <frontend_type>text</frontend_type>
104
+ <sort_order>70</sort_order>
105
+ <show_in_default>1</show_in_default>
106
+ <show_in_website>1</show_in_website>
107
+ <show_in_store>0</show_in_store>
108
+ </sort_order>
109
+ <use_http_proxy translate="label">
110
+ <label>Use HTTP Proxy</label>
111
+ <frontend_type>select</frontend_type>
112
+ <source_model>adminhtml/system_config_source_yesno</source_model>
113
+ <backend_model>hps_securesubmit/system_config_backend_proxy</backend_model>
114
+ <sort_order>80</sort_order>
115
+ <show_in_default>1</show_in_default>
116
+ <show_in_website>1</show_in_website>
117
+ <show_in_store>0</show_in_store>
118
+ </use_http_proxy>
119
+ <http_proxy_host translate="label">
120
+ <label>HTTP Proxy Host</label>
121
+ <frontend_type>text</frontend_type>
122
+ <sort_order>90</sort_order>
123
+ <show_in_default>1</show_in_default>
124
+ <show_in_website>1</show_in_website>
125
+ <show_in_store>0</show_in_store>
126
+ <depends><use_http_proxy>1</use_http_proxy></depends>
127
+ <comment>Example: example.com</comment>
128
+ </http_proxy_host>
129
+ <http_proxy_port translate="label">
130
+ <label>HTTP Proxy Port</label>
131
+ <frontend_type>text</frontend_type>
132
+ <sort_order>100</sort_order>
133
+ <show_in_default>1</show_in_default>
134
+ <show_in_website>1</show_in_website>
135
+ <show_in_store>0</show_in_store>
136
+ <comment>Example: 8888</comment>
137
+ <depends><use_http_proxy>1</use_http_proxy></depends>
138
+ </http_proxy_port>
139
+ <debug translate="label">
140
+ <label>Debug</label>
141
+ <frontend_type>select</frontend_type>
142
+ <source_model>adminhtml/system_config_source_yesno</source_model>
143
+ <sort_order>110</sort_order>
144
+ <show_in_default>1</show_in_default>
145
+ <show_in_website>1</show_in_website>
146
+ <show_in_store>0</show_in_store>
147
+ </debug>
148
+ </fields>
149
+ </hps_securesubmit>
150
+ </groups>
151
+ </payment>
152
+ </sections>
153
+ </config>
app/code/community/Hps/Securesubmit/sql/hps_securesubmit_setup/install-1.0.0.php ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $installer = $this;
3
+ $installer->startSetup();
4
+
5
+ $table = $installer->getConnection()
6
+ ->newTable($installer->getTable('hps_securesubmit/storedcard'))
7
+ ->addColumn(
8
+ 'storedcard_id',
9
+ Varien_Db_Ddl_Table::TYPE_INTEGER,
10
+ null,
11
+ array('identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true)
12
+ )
13
+ ->addColumn(
14
+ 'dt',
15
+ Varien_Db_Ddl_Table::TYPE_DATETIME,
16
+ null,
17
+ array())
18
+ ->addColumn(
19
+ 'customer_id',
20
+ Varien_Db_Ddl_Table::TYPE_INTEGER,
21
+ null,
22
+ array('unsigned' => true, 'nullable' => false, 'default' => '0')
23
+ )
24
+ ->addColumn(
25
+ 'token_value',
26
+ Varien_Db_Ddl_Table::TYPE_VARCHAR,
27
+ 255,
28
+ array('nullable' => false)
29
+ )
30
+ ->addColumn(
31
+ 'cc_type',
32
+ Varien_Db_Ddl_Table::TYPE_VARCHAR,
33
+ 25,
34
+ array('nullable' => false)
35
+ )
36
+ ->addColumn(
37
+ 'cc_last4',
38
+ Varien_Db_Ddl_Table::TYPE_VARCHAR,
39
+ 4,
40
+ array('nullable' => false)
41
+ )
42
+ ->addColumn(
43
+ 'cc_exp_month',
44
+ Varien_Db_Ddl_Table::TYPE_VARCHAR,
45
+ 2,
46
+ array('nullable' => false)
47
+ )
48
+ ->addColumn(
49
+ 'cc_exp_year',
50
+ Varien_Db_Ddl_Table::TYPE_VARCHAR,
51
+ 4,
52
+ array('nullable' => false)
53
+ )
54
+ ->addForeignKey(
55
+ $installer->getFkName(
56
+ 'hps_securesubmit/storedcard',
57
+ 'customer_id',
58
+ 'customer/entity',
59
+ 'entity_id'),
60
+ 'customer_id',
61
+ $installer->getTable(
62
+ 'customer/entity'),
63
+ 'entity_id',
64
+ Varien_Db_Ddl_Table::ACTION_CASCADE,
65
+ Varien_Db_Ddl_Table::ACTION_CASCADE
66
+ );
67
+
68
+ $installer->getConnection()->createTable($table);
69
+ $installer->endSetup();
app/design/adminhtml/default/default/template/securesubmit/form.phtml ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php $_code=$this->getMethodCode() ?>
2
+ <ul id="payment_form_<?php echo $_code ?>" style="display:none">
3
+ <input type="hidden" name="payment[use_credit_card]" value="1" />
4
+ <li>
5
+ <div class="input-box">
6
+ <label for="<?php echo $_code ?>_cc_number"><?php echo Mage::helper('payment')->__('Credit Card Number') ?> <span class="required">*</span></label><br/>
7
+ <input type="text" id="<?php echo $_code ?>_cc_number" name="payment[cc_number]" title="<?php echo Mage::helper('payment')->__('Credit Card Number') ?>" class="input-text validate-cc-number" value="<?php echo $this->getInfoData('cc_number')?>"/>
8
+ </div>
9
+ </li>
10
+ <li>
11
+ <div class="input-box">
12
+ <label for="<?php echo $_code ?>_expiration"><?php echo Mage::helper('payment')->__('Expiration Date') ?> <span class="required">*</span></label><br/>
13
+ <select id="<?php echo $_code ?>_expiration" style="width:140px;" name="payment[cc_exp_month]" class="validate-cc-exp required-entry">
14
+ <?php $_ccExpMonth = $this->getInfoData('cc_exp_month') ?>
15
+ <?php foreach ($this->getCcMonths() as $k=>$v): ?>
16
+ <option value="<?php echo $k ?>" <?php if($k==$_ccExpMonth): ?>selected="selected"<?php endif ?>><?php echo $v ?></option>
17
+ <?php endforeach ?>
18
+ </select>
19
+ <?php $_ccExpYear = $this->getInfoData('cc_exp_year') ?>
20
+ <select id="<?php echo $_code ?>_expiration_yr" style="width:103px;" name="payment[cc_exp_year]" class="required-entry">
21
+ <?php foreach ($this->getCcYears() as $k=>$v): ?>
22
+ <option value="<?php echo $k ? $k : '' ?>" <?php if($k==$_ccExpYear): ?>selected="selected"<?php endif ?>><?php echo $v ?></option>
23
+ <?php endforeach ?>
24
+ </select>
25
+ </div>
26
+ </li>
27
+ <?php if($this->hasVerification()): ?>
28
+ <li>
29
+ <div class="input-box">
30
+ <label for="<?php echo $_code ?>_cc_cid"><?php echo Mage::helper('payment')->__('Card Verification Number') ?> <span class="required">*</span></label><br/>
31
+ <input type="text" title="<?php echo Mage::helper('payment')->__('Card Verification Number') ?>" class="required-entry input-text validate-cc-cvn" id="<?php echo $_code ?>_cc_cid" name="payment[cc_cid]" style="width:3em;" value="<?php echo $this->getInfoData('cc_cid')?>"/>
32
+ </div>
33
+ </li>
34
+ <?php endif; ?>
35
+ <?php if ($this->hasSsCardType()): ?>
36
+ <li id="<?php echo $_code ?>_cc_type_ss_div">
37
+ <ul class="inner-form">
38
+ <li class="form-alt"><label for="<?php echo $_code ?>_cc_issue" class="required"><em>*</em><?php echo $this->__('Switch/Solo/Maestro Only') ?></label></li>
39
+ <li>
40
+ <label for="<?php echo $_code ?>_cc_issue"><?php echo $this->__('Issue Number') ?>:</label>
41
+ <span class="input-box">
42
+ <input type="text" title="<?php echo $this->__('Issue Number') ?>" class="input-text validate-cc-ukss cvv" id="<?php echo $_code ?>_cc_issue" name="payment[cc_ss_issue]" value="" />
43
+ </span>
44
+ </li>
45
+
46
+ <li>
47
+ <label for="<?php echo $_code ?>_start_month"><?php echo $this->__('Start Date') ?>:</label>
48
+ <div class="input-box">
49
+ <select id="<?php echo $_code ?>_start_month" name="payment[cc_ss_start_month]" class="validate-cc-ukss month">
50
+ <?php foreach ($this->getCcMonths() as $k=>$v): ?>
51
+ <option value="<?php echo $k?$k:'' ?>"<?php if($k==$this->getInfoData('cc_ss_start_month')): ?> selected="selected"<?php endif ?>><?php echo $v ?></option>
52
+ <?php endforeach ?>
53
+ </select>
54
+ <select id="<?php echo $_code ?>_start_year" name="payment[cc_ss_start_year]" class="validate-cc-ukss year">
55
+ <?php foreach ($this->getSsStartYears() as $k=>$v): ?>
56
+ <option value="<?php echo $k?$k:'' ?>"<?php if($k==$this->getInfoData('cc_ss_start_year')): ?> selected="selected"<?php endif ?>><?php echo $v ?></option>
57
+ <?php endforeach ?>
58
+ </select>
59
+ </div>
60
+ </li>
61
+ <li class="adv-container">&nbsp;</li>
62
+ </ul>
63
+ <script type="text/javascript">
64
+ //<![CDATA[
65
+ var SSChecked<?php echo $_code ?> = function() {
66
+ var elm = $('<?php echo $_code ?>_cc_type');
67
+ if (['SS','SM','SO'].indexOf(elm.value) != -1) {
68
+ $('<?php echo $_code ?>_cc_type_ss_div').show();
69
+ } else {
70
+ $('<?php echo $_code ?>_cc_type_ss_div').hide();
71
+ }
72
+ };
73
+ Event.observe($('<?php echo $_code ?>_cc_type'), 'change', SSChecked<?php echo $_code ?>);
74
+ SSChecked<?php echo $_code ?>();
75
+ //]]>
76
+ </script>
77
+ </li>
78
+ <?php endif; ?>
79
+ </ul>
app/design/frontend/base/default/layout/securesubmit.xml ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+
3
+ <layout version="0.1.0">
4
+ <onestepcheckout_index_index>
5
+ <reference name="head">
6
+ <action method="addJs"><file>securesubmit/secure.submit-1.0.1.js</file></action>
7
+ </reference>
8
+ </onestepcheckout_index_index>
9
+ <checkout_onepage_index>
10
+ <reference name="head">
11
+ <action method="addJs"><file>securesubmit/secure.submit-1.0.1.js</file></action>
12
+ </reference>
13
+ </checkout_onepage_index>
14
+ <customer_account>
15
+ <reference name="customer_account_navigation">
16
+ <action method="addLink" >
17
+ <name>save_token</name>
18
+ <path>securesubmit/storedcard/index</path>
19
+ <label>Manage Cards</label>
20
+ </action>
21
+ </reference>
22
+ </customer_account>
23
+
24
+ <hps_securesubmit_storedcard_index>
25
+ <update handle="customer_account" />
26
+ <reference name="my.account.wrapper">
27
+ <block type="core/template" name="hps_securesubmit_content" template="securesubmit/storedcards.phtml"/>
28
+ </reference>
29
+ </hps_securesubmit_storedcard_index>
30
+ </layout>
app/design/frontend/base/default/template/securesubmit/form.phtml ADDED
@@ -0,0 +1,178 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php /* @var $this Hps_Securesubmit_Block_Form */
2
+ $_code = $this->getMethodCode();
3
+ $public_key = Mage::getModel('hps_securesubmit/payment')->getConfigData('publicapikey');
4
+ $allow_card_saving = Mage::getModel('hps_securesubmit/payment')->getConfigData('allow_card_saving');
5
+ $_loggedIn = Mage::getSingleton('customer/session')->isLoggedIn();
6
+ if ($_loggedIn && $allow_card_saving) {
7
+ $customerStoredCards = Mage::helper('hps_securesubmit')->getStoredCards( Mage::getSingleton('customer/session')->getCustomerId());
8
+ }
9
+ ?>
10
+ <ul class="form-list" id="payment_form_<?php echo $_code ?>" style="display:none">
11
+ <?php if($_loggedIn && $allow_card_saving && count($customerStoredCards)): ?>
12
+ <li>
13
+ <label for="<?php echo $_code ?>_stored_card_checkbox"><?php echo $this->__('Use a stored card') ?></label>
14
+ <div class="input-box">
15
+ <input type="checkbox" id="<?php echo $_code ?>_stored_card_checkbox" />
16
+ </div>
17
+ </li>
18
+ <li id="<?php echo $_code ?>_stored_cards" style="display: none">
19
+ <label for="<?php echo $_code ?>_stored_card_select"><?php echo $this->__('Stored Card') ?></label>
20
+ <div class="input-box">
21
+ <select id="<?php echo $_code ?>_stored_card_select" autocomplete="off">
22
+ <?php foreach ($customerStoredCards as $key => $card): ?>
23
+ <option value="<?php echo $card->getId() ?>"><?php echo $card->getCcType().' ************'.$card->getCcLast4().' ('.$card->getCcExpMonth().'/'.$card->getCcExpYear().')' ?></option>
24
+ <?php endforeach ?>
25
+ </select>
26
+ </div>
27
+ </li>
28
+ <?php endif ?>
29
+ <li class="stored_cards_selected">
30
+ <label for="<?php echo $_code ?>_cc_number"><?php echo $this->__('Credit Card Number') ?> <span class="required">*</span></label>
31
+ <div class="input-box">
32
+ <input type="text" id="<?php echo $_code ?>_cc_number" title="<?php echo $this->__('Credit Card Number') ?>" class="input-text validate-cc-number validate-cc-type" value="" autocomplete="off" />
33
+ <input type="hidden" id="<?php echo $_code ?>_token" name="payment[securesubmit_token]" value="">
34
+ <input type="hidden" id="<?php echo $_code ?>_cc_last_four" name="payment[cc_last_four]" value="">
35
+ </div>
36
+ </li>
37
+ <li class="stored_cards_selected">
38
+ <label for="<?php echo $_code ?>_expiration"><?php echo $this->__('Expiration Date') ?> <span class="required">*</span></label>
39
+ <div class="input-box">
40
+ <div class="v-fix">
41
+ <select id="<?php echo $_code ?>_expiration" name="payment[cc_exp_month]" class="month required-entry validate-cc-exp" autocomplete="off">
42
+ <?php $_ccExpMonth = $this->getInfoData('cc_exp_month') ?>
43
+ <?php foreach ($this->getCcMonths() as $k=>$v): ?>
44
+ <option value="<?php echo $k?$k:'' ?>" <?php if($k==$_ccExpMonth): ?> selected="selected"<?php endif ?>><?php echo $v ?></option>
45
+ <?php endforeach ?>
46
+ </select>
47
+ </div>
48
+ <div class="v-fix">
49
+ <select id="<?php echo $_code ?>_expiration_yr" name="payment[cc_exp_year]" class="year required-entry" autocomplete="off">
50
+ <?php foreach ($this->getCcYears() as $k=>$v): ?>
51
+ <option value="<?php echo $k?$k:'' ?>" <?php if($k==$this->getInfoData('cc_exp_year')):?> selected="selected"<?php endif ?>><?php echo $v ?></option>
52
+ <?php endforeach ?>
53
+ </select>
54
+ </div>
55
+ </div>
56
+ </li>
57
+ <li class="stored_cards_selected">
58
+ <label for="<?php echo $_code ?>_cc_cid"><?php echo $this->__('Card Verification Number') ?> <span class="required">*</span></label>
59
+ <div class="input-box">
60
+ <div class="v-fix">
61
+ <input type="text" title="<?php echo $this->__('Card Verification Number') ?>" class="cvv required-entry input-text validate-cc-cvn" id="<?php echo $_code ?>_cc_cid" value="" autocomplete="off" />
62
+ </div>
63
+ <a href="#" class="cvv-what-is-this"><?php echo $this->__('What is this?') ?></a>
64
+ </div>
65
+ </li>
66
+ <?php if ($_loggedIn && $allow_card_saving && $public_key): ?>
67
+ <li class="stored_cards_selected">
68
+ <label for="<?php echo $_code ?>_cc_save_future"><?php echo $this->__('Save this card for future use?') ?></label>
69
+ <div class="input-box">
70
+ <input type="checkbox" id="<?php echo $_code ?>_cc_save_future" name="payment[cc_save_future]" value="Y" autocomplete="off" />
71
+ </div>
72
+ </li>
73
+ <?php endif ?>
74
+ </ul>
75
+ <script type="text/javascript">
76
+ //<![CDATA[
77
+ <?php if($_loggedIn && $allow_card_saving && count($customerStoredCards)): ?>
78
+ $('<?php echo $_code ?>_stored_card_checkbox').observe('click',function() {
79
+ $$('.stored_cards_selected').invoke('toggle');
80
+ $('<?php echo $_code ?>_stored_cards').toggle();
81
+ $('<?php echo $_code ?>_cc_number').toggleClassName('validate-cc-number');
82
+ });
83
+ <?php endif ?>
84
+
85
+ Payment.prototype._secureSubmitOldSave = Payment.prototype.save;
86
+ Object.extend(Payment.prototype, {
87
+ save: function() {
88
+ if (this.currentMethod != 'hps_securesubmit') {
89
+ this._secureSubmitOldSave();
90
+ return;
91
+ }
92
+
93
+ if (checkout.loadWaiting != false) return;
94
+
95
+ // Use stored card checked, get existing token data
96
+ if (this.secureSubmitUseStoredCard()) {
97
+ var storedcardId = $('hps_securesubmit_stored_card_select').value;
98
+ checkout.setLoadWaiting('payment');
99
+ new Ajax.Request(this.secureSubmitGetTokenDataUrl, {
100
+ method: 'post',
101
+ parameters: {storedcard_id: storedcardId},
102
+ onSuccess: function(response) {
103
+ var data = response.responseJSON;
104
+ if (data && data.token) {
105
+ $('hps_securesubmit_expiration').value = parseInt(data.token.cc_exp_month);
106
+ $('hps_securesubmit_expiration_yr').value = data.token.cc_exp_year;
107
+ }
108
+ this.secureSubmitResponseHandler({
109
+ token_value: data.token.token_value,
110
+ token_type: null, // 'supt'?
111
+ token_expire: new Date().toISOString(),
112
+ card: {
113
+ number: data.token.cc_last4
114
+ }
115
+ });
116
+ }.bind(this),
117
+ onFailure: function() {
118
+ alert('Unknown error. Please try again.');
119
+ checkout.setLoadWaiting(false);
120
+ }
121
+ });
122
+ }
123
+ // Use stored card not checked, get new token
124
+ else {
125
+ var validator = new Validation(this.form);
126
+ if (this.validate() && validator.validate()) {
127
+ checkout.setLoadWaiting('payment');
128
+
129
+ hps.tokenize({
130
+ data: {
131
+ public_key: this.secureSubmitPublicKey,
132
+ number: $('hps_securesubmit_cc_number').value,
133
+ cvc: $('hps_securesubmit_cc_cid').value,
134
+ exp_month: $('hps_securesubmit_expiration').value,
135
+ exp_year: $('hps_securesubmit_expiration_yr').value
136
+ },
137
+ success: this.secureSubmitResponseHandler.bind(this),
138
+ error: this.secureSubmitResponseHandler.bind(this)
139
+ });
140
+ }
141
+ }
142
+ },
143
+ secureSubmitUseStoredCard: function () {
144
+ var storedCheckbox = $('hps_securesubmit_stored_card_checkbox');
145
+ return storedCheckbox && storedCheckbox.checked;
146
+ },
147
+ secureSubmitResponseHandler: function (response) {
148
+ var tokenField = $('hps_securesubmit_token'),
149
+ lastFourField = $('hps_securesubmit_cc_last_four');
150
+ tokenField.value = lastFourField.value = null;
151
+
152
+ if (response && response.error) {
153
+ if (response.message) {
154
+ alert(response.message);
155
+ }
156
+ checkout.setLoadWaiting(false);
157
+ } else if (response && response.token_value) {
158
+ tokenField.value = response.token_value;
159
+ lastFourField.value = response.card.number.substr(-4);
160
+
161
+ // Continue Magento checkout steps
162
+ new Ajax.Request(this.saveUrl, {
163
+ method:'post',
164
+ onComplete: this.onComplete,
165
+ onSuccess: this.onSave,
166
+ onFailure: checkout.ajaxFailure.bind(checkout),
167
+ parameters: Form.serialize(this.form)
168
+ });
169
+ } else {
170
+ alert('Unexpected error.')
171
+ }
172
+ }
173
+ });
174
+
175
+ payment.secureSubmitPublicKey = '<?php echo $public_key ?>';
176
+ payment.secureSubmitGetTokenDataUrl = '<?php echo Mage::getUrl('securesubmit/storedcard/getTokenData', array('_secure' => TRUE)) ?>';
177
+ //]]>
178
+ </script>
app/design/frontend/base/default/template/securesubmit/storedcards.phtml ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $_storedCards = Mage::helper('hps_securesubmit')->getStoredCards(Mage::getSingleton('customer/session')->getCustomerId());
3
+ ?>
4
+
5
+ <h1><?php echo $this->__('Manage Saved Cards') ?></h1>
6
+ <div class="box-account">
7
+ <div class="box-head">
8
+ <h2><?php echo $this->__('Saved Credit Cards') ?></h2>
9
+ </div>
10
+ <?php if (count($_storedCards)): ?>
11
+ <table class="data-table" id="stored-cards-table">
12
+ <col width="1" />
13
+ <col width="1" />
14
+ <col width="1" />
15
+ <col width="1" />
16
+ <thead>
17
+ <tr>
18
+ <th><?php echo $this->__('Card Type') ?></th>
19
+ <th><?php echo $this->__('Card Number') ?></th>
20
+ <th><?php echo $this->__('Expiration Date') ?></th>
21
+ <th>&nbsp;</th>
22
+ </tr>
23
+ </thead>
24
+ <tbody>
25
+ <?php foreach ($_storedCards->getData() as $card): ?>
26
+ <tr id="credit_cards">
27
+ <td class="a-center"><span class="nobr"><?php echo $card['cc_type'] ?></span></td>
28
+ <td class="a-center"><span class="nobr"><?php echo "************".$card['cc_last4'] ?></span></td>
29
+ <td class="a-center"><span class="nobr"><?php echo $card['cc_exp_month'] ."-".$card['cc_exp_year'] ?></span></td>
30
+ <td><a href="<?php echo Mage::getUrl('securesubmit/storedcard/delete', array('storedcard_id' => $card['storedcard_id'], '_secure' => TRUE)) ?>">Delete</a></td>
31
+ </tr>
32
+ <?php endforeach; ?>
33
+ </tbody>
34
+ </table>
35
+ <?php else: ?>
36
+ <p>
37
+ <?php echo $this->__('You do not have any saved credit cards.') ?>
38
+ </p>
39
+ <?php endif; ?>
40
+ </div>
app/etc/modules/Hps_Securesubmit.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Hps_Securesubmit>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ </Hps_Securesubmit>
8
+ </modules>
9
+ </config>
js/securesubmit/secure.submit-1.0.1.js ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*global $ */
2
+ var hps = (function () {
3
+ "use strict";
4
+
5
+ var HPS = {
6
+
7
+ Tag: "SecureSubmit",
8
+
9
+ Urls: {
10
+ CERT: "https://posgateway.cert.secureexchange.net/Hps.Exchange.PosGateway.Hpf.v1/api/token",
11
+ PROD: "https://api.heartlandportico.com/SecureSubmit.v1/api/token"
12
+ },
13
+
14
+ tokenize: function (options) {
15
+ var gateway_url, params, env, getter_impl;
16
+
17
+ // add additional service parameters
18
+ params = $H({
19
+ "api_key": options.data.public_key,
20
+ "object": "token",
21
+ "token_type": "supt",
22
+ "_method": "post",
23
+ "card[number]": HPS.trim(options.data.number),
24
+ "card[cvc]": HPS.trim(options.data.cvc),
25
+ "card[exp_month]": HPS.trim(options.data.exp_month),
26
+ "card[exp_year]": HPS.trim(options.data.exp_year)
27
+ });
28
+
29
+ env = options.data.public_key.split("_")[1];
30
+
31
+ if (env === "uat") {
32
+ gateway_url = HPS.Urls.UAT;
33
+ } else if (env === "cert") {
34
+ gateway_url = HPS.Urls.CERT;
35
+ } else {
36
+ gateway_url = HPS.Urls.PROD;
37
+ }
38
+
39
+ new Ajax.JSONP(gateway_url, {
40
+ parameters: params,
41
+ onComplete: function(json) {
42
+
43
+ // Request failed, handle error
44
+ if (typeof json.error === 'object') {
45
+ // call error handler if provided and valid
46
+ if (typeof options.error === 'function') {
47
+ options.error(json.error);
48
+ } else {
49
+ // handle exception
50
+ HPS.error(json.error.message);
51
+ }
52
+ } else if (typeof options.success === 'function') {
53
+ options.success(json);
54
+ }
55
+ }
56
+ });
57
+
58
+ },
59
+
60
+ trim: function (string) {
61
+ if (string !== undefined && typeof string === "string" ) {
62
+ string = string.toString().replace(/^\s\s*/, '').replace(/\s\s*$/, '');
63
+ }
64
+ return string;
65
+ },
66
+
67
+ empty: function (val) {
68
+ return val === undefined || val.length === 0;
69
+ },
70
+
71
+ error: function (message) {
72
+ if (console && console.log) {
73
+ console.log([HPS.Tag, ": ", message].join(""));
74
+ }
75
+ }
76
+ };
77
+
78
+ return HPS;
79
+ }());
80
+
81
+ Ajax.JSONP = Class.create(Ajax.Base, (function() {
82
+ var id = 0,
83
+ head = document.getElementsByTagName('head')[0];
84
+
85
+ return {
86
+ initialize: function($super, url, options) {
87
+ $super(options);
88
+ this.request(url);
89
+ },
90
+
91
+ request: function(url) {
92
+ var callbackName = '_prototypeJSONPCallback_' + (id++),
93
+ self = this,
94
+ script;
95
+
96
+ this.options.parameters["callback"] = callbackName;
97
+
98
+ url += (url.include('?') ? '&' : '?') + Object.toQueryString(this.options.parameters);
99
+
100
+ window[callbackName] = function(json) {
101
+ script.remove();
102
+ script = null;
103
+ window[callbackName] = undefined;
104
+ if (self.options.onComplete) {
105
+ self.options.onComplete.call(self, json);
106
+ }
107
+ }
108
+ script = new Element('script', {
109
+ type: 'text/javascript',
110
+ src: url
111
+ });
112
+ head.appendChild(script);
113
+ }
114
+ };
115
+ })());
lib/SecureSubmit/Hps.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined('DS')) define('DS', DIRECTORY_SEPARATOR);
3
+ if ( ! defined('PS')) define('PS', PATH_SEPARATOR);
4
+
5
+ // Infrastructure
6
+ require_once(dirname(__FILE__).DS.'infrastructure/HpsConfiguration.php');
7
+ require_once(dirname(__FILE__).DS.'infrastructure/HpsException.php');
8
+ require_once(dirname(__FILE__).DS.'infrastructure/ApiConnectionException.php');
9
+ require_once(dirname(__FILE__).DS.'infrastructure/AuthenticationException.php');
10
+ require_once(dirname(__FILE__).DS.'infrastructure/AVSResponseCodeHandler.php');
11
+ require_once(dirname(__FILE__).DS.'infrastructure/CardException.php');
12
+ require_once(dirname(__FILE__).DS.'infrastructure/HpsExceptionMapper.php');
13
+ require_once(dirname(__FILE__).DS.'infrastructure/HpsSdkCodes.php');
14
+ require_once(dirname(__FILE__).DS.'infrastructure/InvalidRequestException.php');
15
+
16
+ // Entities
17
+ require_once(dirname(__FILE__).DS.'entities/HpsTransaction.php');
18
+ require_once(dirname(__FILE__).DS.'entities/HpsAuthorization.php');
19
+ require_once(dirname(__FILE__).DS.'entities/HpsAccountVerify.php');
20
+ require_once(dirname(__FILE__).DS.'entities/HpsAddress.php');
21
+ require_once(dirname(__FILE__).DS.'entities/HpsTransactionType.php');
22
+ require_once(dirname(__FILE__).DS.'entities/HpsBatch.php');
23
+ require_once(dirname(__FILE__).DS.'entities/HpsCardHolder.php');
24
+ require_once(dirname(__FILE__).DS.'entities/HpsCharge.php');
25
+ require_once(dirname(__FILE__).DS.'entities/HpsChargeExceptions.php');
26
+ require_once(dirname(__FILE__).DS.'entities/HpsCreditCard.php');
27
+ require_once(dirname(__FILE__).DS.'entities/HpsItemChoiceTypePosResponseVer10Transaction.php');
28
+ require_once(dirname(__FILE__).DS.'entities/HpsRefund.php');
29
+ require_once(dirname(__FILE__).DS.'entities/HpsReportTransactionDetails.php');
30
+ require_once(dirname(__FILE__).DS.'entities/HpsReportTransactionSummary.php');
31
+ require_once(dirname(__FILE__).DS.'entities/HpsReversal.php');
32
+ require_once(dirname(__FILE__).DS.'entities/HpsTokenData.php');
33
+ require_once(dirname(__FILE__).DS.'entities/HpsTransactionDetails.php');
34
+ require_once(dirname(__FILE__).DS.'entities/HpsTransactionHeader.php');
35
+ require_once(dirname(__FILE__).DS.'entities/HpsVoid.php');
36
+
37
+
38
+ // Services
39
+ require_once(dirname(__FILE__).DS.'services/HpsTokenService.php');
40
+ require_once(dirname(__FILE__).DS.'services/HpsService.php');
41
+ require_once(dirname(__FILE__).DS.'services/HpsChargeService.php');
42
+ require_once(dirname(__FILE__).DS.'services/HpsBatchService.php');
lib/SecureSubmit/entities/HpsAccountVerify.php ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsAccountVerify extends HpsAuthorization{
4
+ public function __construct($header){
5
+ parent::__construct($header);
6
+ }
7
+ }
lib/SecureSubmit/entities/HpsAddress.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsAddress {
4
+ public $address = null,
5
+ $city = null,
6
+ $state = null,
7
+ $zip = null,
8
+ $country = null;
9
+ }
lib/SecureSubmit/entities/HpsAuthorization.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ class HpsAuthorization extends HpsTransaction {
5
+ public $avsResultCode = null,
6
+ $avsResultText = null,
7
+ $cvvResultCode = null,
8
+ $cvvResultText = null,
9
+ $cpcIndicator = null,
10
+ $authorizationCode = null,
11
+ $authorizedAmount = null,
12
+ $cardType = null,
13
+ $tokenData = null;
14
+
15
+ public function __construct($header){
16
+ parent::__construct($header);
17
+ }
18
+ }
lib/SecureSubmit/entities/HpsBatch.php ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsBatch {
4
+ public $id = null,
5
+ $transactionCount = null,
6
+ $totalAmount = null,
7
+ $sequenceNumber = null;
8
+ }
lib/SecureSubmit/entities/HpsCardHolder.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsCardHolder {
4
+ public $firstName = null,
5
+ $lastName = null,
6
+ $phone = null,
7
+ $emailAddress = null,
8
+ $address = null;
9
+ }
lib/SecureSubmit/entities/HpsCharge.php ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsCharge extends HpsAuthorization{
4
+ public function __construct($header){
5
+ parent::__construct($header);
6
+ }
7
+ }
lib/SecureSubmit/entities/HpsChargeExceptions.php ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsChargeExceptions {
4
+ public $cardException = null,
5
+ $hpsException = null;
6
+ }
lib/SecureSubmit/entities/HpsCreditCard.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ class HpsCreditCard {
5
+ public $number = null,
6
+ $cvv = null,
7
+ $expMonth = null,
8
+ $expYear = null;
9
+
10
+ function cardType(){
11
+ $regexMap = array(
12
+ 'Amex' => '/^3[47][0-9]{13}$/',
13
+ 'MasterCard' => '/^5[1-5][0-9]{14}$/',
14
+ 'Visa' => '/^4[0-9]{12}(?:[0-9]{3})?$/',
15
+ 'DinersClub' => '/^3(?:0[0-5]|[68][0-9])[0-9]{11}$/',
16
+ 'EnRoute' => '/^(2014|2149)/',
17
+ 'Discover' => '/^6(?:011|5[0-9]{2})[0-9]{12}$/',
18
+ 'Jcb' => '/^(?:2131|1800|35\d{3})\d{11}$/',
19
+ );
20
+ foreach($regexMap as $card=>$rx){
21
+ if(preg_match($rx, $this->number)){
22
+ return $card;
23
+ }
24
+ }
25
+ return "Unknown";
26
+ }
27
+ }
lib/SecureSubmit/entities/HpsItemChoiceTypePosResponseVer10Transaction.php ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsItemChoiceTypePosResponseVer10Transaction{
4
+ static public $AddAttachment = "AddAttachment";
5
+ static public $Authenticate = "Authenticate";
6
+ static public $BatchClose = "BatchClose";
7
+ static public $CancelImpersonation = "CancelImpersonation";
8
+ static public $CheckSale = "CheckSale";
9
+ static public $CheckVoid = "CheckVoid";
10
+ static public $CreditAccountVerify = "CreditAccountVerify";
11
+ static public $CreditAddToBatch = "CreditAddToBatch";
12
+ static public $CreditAuth = "CreditAuth";
13
+ static public $CreditCPCEdit = "CreditCPCEdit";
14
+ static public $CreditIncrementalAuth = "CreditIncrementalAuth";
15
+ static public $CreditOfflineAuth = "CreditOfflineAuth";
16
+ static public $CreditOfflineSale = "CreditOfflineSale";
17
+ static public $CreditReturn = "CreditReturn";
18
+ static public $CreditReversal = "CreditReversal";
19
+ static public $CreditSale = "CreditSale";
20
+ static public $CreditTxnEdit = "CreditTxnEdit";
21
+ static public $CreditVoid = "CreditVoid";
22
+ static public $DebitAddValue = "DebitAddValue";
23
+ static public $DebitReturn = "DebitReturn";
24
+ static public $DebitReversal = "DebitReversal";
25
+ static public $DebitSale = "DebitSale";
26
+ static public $EBTBalanceInquiry = "EBTBalanceInquiry";
27
+ static public $EBTCashBackPurchase = "EBTCashBackPurchase";
28
+ static public $EBTCashBenefitWithdrawal = "EBTCashBenefitWithdrawal";
29
+ static public $EBTFSPurchase = "EBTFSPurchase";
30
+ static public $EBTFSReturn = "EBTFSReturn";
31
+ static public $EBTVoucherPurchase = "EBTVoucherPurchase";
32
+ static public $EndToEndTest = "EndToEndTest";
33
+ static public $FindTransactions = "FindTransactions";
34
+ static public $GetAttachments = "GetAttachments";
35
+ static public $GetUserDeviceSettings = "GetUserDeviceSettings";
36
+ static public $GetUserSettings = "GetUserSettings";
37
+ static public $GiftCardActivate = "GiftCardActivate";
38
+ static public $GiftCardAddValue = "GiftCardAddValue";
39
+ static public $GiftCardBalance = "GiftCardBalance";
40
+ static public $GiftCardCurrentDayTotals = "GiftCardCurrentDayTotals";
41
+ static public $GiftCardDeactivate = "GiftCardDeactivate";
42
+ static public $GiftCardPreviousDayTotals = "GiftCardPreviousDayTotals";
43
+ static public $GiftCardReplace = "GiftCardReplace";
44
+ static public $GiftCardReversal = "GiftCardReversal";
45
+ static public $GiftCardSale = "GiftCardSale";
46
+ static public $GiftCardVoid = "GiftCardVoid";
47
+ static public $Impersonate = "Impersonate";
48
+ static public $InvalidateAuthentication = "InvalidateAuthentication";
49
+ static public $ManageSettings = "ManageSettings";
50
+ static public $ManageUsers = "ManageUsers";
51
+ static public $PrePaidAddValue = "PrePaidAddValue";
52
+ static public $PrePaidBalanceInquiry = "PrePaidBalanceInquiry";
53
+ static public $RecurringBilling = "RecurringBilling";
54
+ static public $ReportActivity = "ReportActivity";
55
+ static public $ReportBatchDetail = "ReportBatchDetail";
56
+ static public $ReportBatchHistory = "ReportBatchHistory";
57
+ static public $ReportBatchSummary = "ReportBatchSummary";
58
+ static public $ReportOpenAuths = "ReportOpenAuths";
59
+ static public $ReportSearch = "ReportSearch";
60
+ static public $ReportTxnDetail = "ReportTxnDetail";
61
+ static public $SendReceipt = "SendReceipt";
62
+ static public $TestCredentials = "TestCredentials";
63
+ }
lib/SecureSubmit/entities/HpsRefund.php ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsRefund extends HpsTransaction{
4
+ public function __construct($header){
5
+ parent::__construct($header);
6
+ }
7
+ }
lib/SecureSubmit/entities/HpsReportTransactionDetails.php ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ class HpsReportTransactionDetails extends HpsAuthorization {
5
+ public $originalTransactionId = null,
6
+ $maskedCardNumber = null,
7
+ $transactionType = null,
8
+ $transactionDate = null,
9
+ $exceptions = null;
10
+
11
+ public function __construct($header){
12
+ parent::__construct($header);
13
+ }
14
+ }
lib/SecureSubmit/entities/HpsReportTransactionSummary.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsReportTransactionSummary extends HpsTransaction{
4
+ public $amount = null,
5
+ $originalTransactionId = null,
6
+ $maskedCardNumber = null,
7
+ $transactionType = null,
8
+ $transactionDate = null,
9
+ $exceptions = null;
10
+ }
lib/SecureSubmit/entities/HpsReversal.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsReversal extends HpsTransaction{
4
+ public $avsResultCode = null,
5
+ $avsResultText = null,
6
+ $cvvResultCode = null,
7
+ $cvvResultText = null,
8
+ $cpcIndicator = null;
9
+
10
+ public function __construct($header){
11
+ parent::__construct($header);
12
+ }
13
+ }
lib/SecureSubmit/entities/HpsTokenData.php ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsTokenData {
4
+ public $tokenValue = null,
5
+ $responseCode = null,
6
+ $responseMessage = null;
7
+
8
+ public function __construct($responseMessage = null){
9
+ $this->responseMessage = $responseMessage;
10
+ }
11
+ }
lib/SecureSubmit/entities/HpsTransaction.php ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsTransaction {
4
+ public $transactionHeader = null,
5
+ $transactionId = null,
6
+ $responseCode = null,
7
+ $responseText = null,
8
+ $referenceNumber = null;
9
+
10
+ public function __construct($transactionHeader=null){
11
+ $this->transactionHeader = $transactionHeader;
12
+ }
13
+
14
+ static public function transactionTypeToServiceName($transactionType){
15
+ switch ($transactionType){
16
+ case HpsTransactionType::$AUTHORIZE :
17
+ return HpsItemChoiceTypePosResponseVer10Transaction::$CreditAuth;
18
+ break;
19
+
20
+ case HpsTransactionType::$CAPTURE:
21
+ return HpsItemChoiceTypePosResponseVer10Transaction::$CreditAddToBatch;
22
+ break;
23
+
24
+ case HpsTransactionType::$CHARGE:
25
+ return HpsItemChoiceTypePosResponseVer10Transaction::$CreditSale;
26
+ break;
27
+
28
+ case HpsTransactionType::$REFUND:
29
+ return HpsItemChoiceTypePosResponseVer10Transaction::$CreditReturn;
30
+ break;
31
+
32
+ case HpsTransactionType::$REVERSE:
33
+ return HpsItemChoiceTypePosResponseVer10Transaction::$CreditReversal;
34
+ break;
35
+
36
+ case HpsTransactionType::$VERIFY:
37
+ return HpsItemChoiceTypePosResponseVer10Transaction::$CreditAccountVerify;
38
+ break;
39
+
40
+ case HpsTransactionType::$LIST:
41
+ return HpsItemChoiceTypePosResponseVer10Transaction::$ReportActivity;
42
+ break;
43
+
44
+ case HpsTransactionType::$GET:
45
+ return HpsItemChoiceTypePosResponseVer10Transaction::$ReportTxnDetail;
46
+ break;
47
+
48
+ case HpsTransactionType::$VOID:
49
+ return HpsItemChoiceTypePosResponseVer10Transaction::$CreditVoid;
50
+ break;
51
+
52
+ case HpsTransactionType::$BATCH_CLOSE:
53
+ return HpsItemChoiceTypePosResponseVer10Transaction::$BatchClose;
54
+ break;
55
+
56
+ case HpsTransactionType::$SECURITY_ERROR:
57
+ return "SecurityError";
58
+ break;
59
+
60
+ default:
61
+ return "";
62
+ }
63
+ }
64
+
65
+ static public function serviceNameToTransactionType($serviceName){
66
+ switch ($serviceName){
67
+ case HpsItemChoiceTypePosResponseVer10Transaction::$CreditAuth:
68
+ return HpsTransactionType::$CAPTURE;
69
+ break;
70
+
71
+ case HpsItemChoiceTypePosResponseVer10Transaction::$CreditAddToBatch:
72
+ return HpsTransactionType::$CAPTURE;
73
+ break;
74
+
75
+ case HpsItemChoiceTypePosResponseVer10Transaction::$CreditSale:
76
+ return HpsTransactionType::$CHARGE;
77
+ break;
78
+
79
+ case HpsItemChoiceTypePosResponseVer10Transaction::$CreditReturn:
80
+ return HpsTransactionType::$REFUND;
81
+ break;
82
+
83
+ case HpsItemChoiceTypePosResponseVer10Transaction::$CreditReversal:
84
+ return HpsTransactionType::$REVERSE;
85
+ break;
86
+
87
+ case HpsItemChoiceTypePosResponseVer10Transaction::$CreditAccountVerify:
88
+ return HpsTransactionType::$VERIFY;
89
+ break;
90
+
91
+ case HpsItemChoiceTypePosResponseVer10Transaction::$ReportActivity:
92
+ return HpsTransactionType::$LIST;
93
+ break;
94
+
95
+ case HpsItemChoiceTypePosResponseVer10Transaction::$ReportTxnDetail:
96
+ return HpsTransactionType::$GET;
97
+ break;
98
+
99
+ case HpsItemChoiceTypePosResponseVer10Transaction::$CreditVoid:
100
+ return HpsTransactionType::$VOID;
101
+ break;
102
+
103
+ case HpsItemChoiceTypePosResponseVer10Transaction::$BatchClose:
104
+ return HpsTransactionType::$BATCH_CLOSE;
105
+ break;
106
+
107
+ default:
108
+ return null;
109
+ }
110
+ }
111
+ }
lib/SecureSubmit/entities/HpsTransactionDetails.php ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsTransactionDetails {
4
+ public $memo = null,
5
+ $invoiceNumber = null,
6
+ $customerId = null,
7
+ $clientTransactionId = null;
8
+ }
lib/SecureSubmit/entities/HpsTransactionHeader.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ class HpsTransactionHeader {
5
+ public $gatewayResponseCode = null,
6
+ $gatewayResponseMessage = null,
7
+ $responseDt = null,
8
+ $clientTxnId = null;
9
+ }
lib/SecureSubmit/entities/HpsTransactionType.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsTransactionType {
4
+ static public $AUTHORIZE = 0;
5
+ static public $CAPTURE = 1;
6
+ static public $CHARGE = 2;
7
+ static public $REFUND = 3;
8
+ static public $REVERSE = 4;
9
+ static public $VERIFY = 5;
10
+ static public $LIST = 6;
11
+ static public $GET = 7;
12
+ static public $VOID = 8;
13
+ static public $SECURITY_ERROR = 9;
14
+ static public $BATCH_CLOSE = 10;
15
+ }
lib/SecureSubmit/entities/HpsVoid.php ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsVoid extends HpsTransaction{
4
+ public function __construct($header){
5
+ parent::__construct($header);
6
+ }
7
+ }
lib/SecureSubmit/infrastructure/AVSResponseCodeHandler.php ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ class AVSResponseCodeHandler {
5
+ private $avsResultCode;
6
+ private $config;
7
+ private $response;
8
+ private $transaction;
9
+ private $transactionId;
10
+ private $ver;
11
+
12
+ function __construct($response, $hpsChargeService=null, $config=null)
13
+ {
14
+ $this->config = $config;
15
+ if(count($this->config->avsResponseErrors) == 0){
16
+ return;
17
+ }
18
+
19
+ $this->transaction = $response->Transaction;
20
+ $this->transactionId = $response->Header->GatewayTxnId;
21
+
22
+ if(isset($this->transaction->CreditSale) && is_object($this->transaction->CreditSale)){
23
+ $this->avsResultCode = $this->transaction->CreditSale->AVSRsltCode;
24
+ $this->evaluate($hpsChargeService,'sale');
25
+ }else if(isset($this->transaction->CreditAuth) && is_object($this->transaction->CreditAuth)){
26
+ $this->avsResultCode = $this->transaction->CreditAuth->AVSRsltCode;
27
+ $this->evaluate($hpsChargeService,'auth');
28
+ }
29
+ }
30
+
31
+ function evaluate($hpsChargeService,$type){
32
+ $exceptionFound = false;
33
+ $code = "";
34
+ $message = "";
35
+
36
+ foreach ($this->config->avsResponseErrors as $c=>$m) {
37
+ if($this->avsResultCode == $c){
38
+ $code = $c;
39
+ $message = $m;
40
+ $exceptionFound = true;
41
+ }
42
+ }
43
+
44
+ if($exceptionFound){
45
+ $hpsChargeService->void($this->transactionId);
46
+ throw new HpsException($message,$code);
47
+ }
48
+ }
49
+ }
lib/SecureSubmit/infrastructure/ApiConnectionException.php ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ <?php
2
+ class ApiConnectionException extends HpsException{
3
+
4
+ }
lib/SecureSubmit/infrastructure/AuthenticationException.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class AuthenticationException extends HpsException{
4
+
5
+ public function __construct($message){
6
+ parent::__construct($message, null);
7
+ }
8
+
9
+ }
lib/SecureSubmit/infrastructure/CardException.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class CardException extends HpsException{
4
+ public $TransactionId = null;
5
+ public $ResultText = null;
6
+
7
+ public function __construct($transactionId, $code, $message, $resultText = null) {
8
+ $this->TransactionId = $transactionId;
9
+ $this->ResultText = $resultText;
10
+ parent::__construct($message, $code);
11
+ }
12
+
13
+ }
lib/SecureSubmit/infrastructure/Exceptions.json ADDED
@@ -0,0 +1,469 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "version": "1.0.0",
3
+
4
+ "exception_mappings":[
5
+ {
6
+ "object":"exception_mapping",
7
+ "category":"issuer",
8
+ "exception_codes":[
9
+ "02",
10
+ "03",
11
+ "04",
12
+ "05",
13
+ "41",
14
+ "43",
15
+ "44",
16
+ "51",
17
+ "56",
18
+ "61",
19
+ "62",
20
+ "63",
21
+ "65",
22
+ "78"
23
+ ],
24
+ "mapping_type":"CardException",
25
+ "mapping_code":"card_declined",
26
+ "mapping_message":"Exception_Message_CardDeclined"
27
+ },
28
+ {
29
+ "object":"exception_mapping",
30
+ "category":"issuer",
31
+ "exception_codes":[
32
+ "06",
33
+ "07",
34
+ "12",
35
+ "15",
36
+ "19",
37
+ "12",
38
+ "52",
39
+ "53",
40
+ "57",
41
+ "58",
42
+ "76",
43
+ "77",
44
+ "91",
45
+ "96",
46
+ "EC"
47
+ ],
48
+ "mapping_type":"CardException",
49
+ "mapping_code":"processing_error",
50
+ "mapping_message":"Exception_Message_ProcessingError"
51
+ },
52
+ {
53
+ "object":"exception_mapping",
54
+ "category":"issuer",
55
+ "exception_codes":[
56
+ "13"
57
+ ],
58
+ "mapping_type":"CardException",
59
+ "mapping_code":"invalid_amount",
60
+ "mapping_message":"Exception_Message_ChargeAmount"
61
+ },
62
+ {
63
+ "object":"exception_mapping",
64
+ "category":"issuer",
65
+ "exception_codes":[
66
+ "14"
67
+ ],
68
+ "mapping_type":"CardException",
69
+ "mapping_code":"incorrect_number",
70
+ "mapping_message":"Exception_Message_IncorrectNumber"
71
+ },
72
+ {
73
+ "object":"exception_mapping",
74
+ "category":"issuer",
75
+ "exception_codes":[
76
+ "54"
77
+ ],
78
+ "mapping_type":"CardException",
79
+ "mapping_code":"expired_card",
80
+ "mapping_message":"Exception_Message_CardExpired"
81
+ },
82
+ {
83
+ "object":"exception_mapping",
84
+ "category":"issuer",
85
+ "exception_codes":[
86
+ "55"
87
+ ],
88
+ "mapping_type":"CardException",
89
+ "mapping_code":"invalid_pin",
90
+ "mapping_message":"Exception_Message_InvalidPin"
91
+ },
92
+ {
93
+ "object":"exception_mapping",
94
+ "category":"issuer",
95
+ "exception_codes":[
96
+ "75"
97
+ ],
98
+ "mapping_type":"CardException",
99
+ "mapping_code":"pin_retries_exceeded",
100
+ "mapping_message":"Exception_Message_PinExceeded"
101
+ },
102
+ {
103
+ "object":"exception_mapping",
104
+ "category":"issuer",
105
+ "exception_codes":[
106
+ "80"
107
+ ],
108
+ "mapping_type":"CardException",
109
+ "mapping_code":"invalid_expiry",
110
+ "mapping_message":"Exception_Message_InvalidExpiry"
111
+ },
112
+ {
113
+ "object":"exception_mapping",
114
+ "category":"issuer",
115
+ "exception_codes":[
116
+ "80"
117
+ ],
118
+ "mapping_type":"CardException",
119
+ "mapping_code":"invalid_expiry",
120
+ "mapping_message":"Exception_Message_InvalidExpiry"
121
+ },
122
+ {
123
+ "object":"exception_mapping",
124
+ "category":"issuer",
125
+ "exception_codes":[
126
+ "86"
127
+ ],
128
+ "mapping_type":"CardException",
129
+ "mapping_code":"pin_verification",
130
+ "mapping_message":"Exception_Message_PinVerification"
131
+ },
132
+ {
133
+ "object":"exception_mapping",
134
+ "category":"issuer",
135
+ "exception_codes":[
136
+ "EB",
137
+ "N7"
138
+ ],
139
+ "mapping_type":"CardException",
140
+ "mapping_code":"incorrect_cvc",
141
+ "mapping_message":"Exception_Message_IncorrectCvc"
142
+ },
143
+ {
144
+ "object":"exception_mapping",
145
+ "category":"gateway",
146
+ "exception_codes":[
147
+ "-2"
148
+ ],
149
+ "mapping_type":"AuthenticationException",
150
+ "mapping_message":"Exception_Message_AuthenticationError"
151
+ },
152
+ {
153
+ "object":"exception_mapping",
154
+ "category":"gateway",
155
+ "exception_codes":[
156
+ "1"
157
+ ],
158
+ "mapping_type":"HpsException"
159
+ },
160
+ {
161
+ "object":"exception_mapping",
162
+ "category":"gateway",
163
+ "exception_codes":[
164
+ "3"
165
+ ],
166
+ "mapping_type":"HpsException",
167
+ "mapping_code":"invalid_original_transaction"
168
+ },
169
+ {
170
+ "object":"exception_mapping",
171
+ "category":"gateway",
172
+ "exception_codes":[
173
+ "5"
174
+ ],
175
+ "mapping_type":"HpsException",
176
+ "mapping_code":"no_open_batch"
177
+ },
178
+ {
179
+ "object":"exception_mapping",
180
+ "category":"gateway",
181
+ "param":"card",
182
+ "exception_codes":[
183
+ "12"
184
+ ],
185
+ "mapping_type":"InvalidRequestException",
186
+ "mapping_code":"invalid_cpc_data",
187
+ "mapping_message":"Exception_Message_InvalidCpcData"
188
+ },
189
+ {
190
+ "object":"exception_mapping",
191
+ "category":"gateway",
192
+ "param":"card",
193
+ "exception_codes":[
194
+ "13"
195
+ ],
196
+ "mapping_type":"InvalidRequestException",
197
+ "mapping_code":"invalid_card_data",
198
+ "mapping_message":"Exception_Message_InvalidCardData"
199
+ },
200
+ {
201
+ "object":"exception_mapping",
202
+ "category":"gateway",
203
+ "exception_codes":[
204
+ "14"
205
+ ],
206
+ "mapping_type":"CardException",
207
+ "mapping_code":"invalid_number",
208
+ "mapping_message":"Exception_Message_InvalidNumber"
209
+ },
210
+ {
211
+ "object":"exception_mapping",
212
+ "category":"gateway",
213
+ "exception_codes":[
214
+ "30"
215
+ ],
216
+ "mapping_type":"HpsException",
217
+ "mapping_message":"Exception_Message_GatewayTimedOut"
218
+ },
219
+ {
220
+ "object":"exception_mapping",
221
+ "category":"sdk",
222
+ "param":"gatewayTransactionId",
223
+ "exception_codes":[
224
+ "0"
225
+ ],
226
+ "mapping_type":"InvalidRequestException",
227
+ "mapping_code":"invalid_transaction_id",
228
+ "mapping_message":"Exception_Message_TransactionIdLessThanEqualZero"
229
+ },
230
+ {
231
+ "object":"exception_mapping",
232
+ "category":"sdk",
233
+ "param":"HpsServiceUri",
234
+ "exception_codes":[
235
+ "1"
236
+ ],
237
+ "mapping_type":"InvalidRequestException",
238
+ "mapping_code":"sdk_exception",
239
+ "mapping_message":"Exception_Message_InvalidGatewayUrl"
240
+ },
241
+ {
242
+ "object":"exception_mapping",
243
+ "category":"sdk",
244
+ "exception_codes":[
245
+ "2"
246
+ ],
247
+ "mapping_type":"ApiConnectionException",
248
+ "mapping_code":"sdk_exception",
249
+ "mapping_message":"Exception_Message_UnableToProcessTransaction"
250
+ },
251
+ {
252
+ "object":"exception_mapping",
253
+ "category":"sdk",
254
+ "param":"start",
255
+ "exception_codes":[
256
+ "3"
257
+ ],
258
+ "mapping_type":"InvalidRequestException",
259
+ "mapping_code":"invalid_date",
260
+ "mapping_message":"Exception_Message_FutureDate"
261
+ },
262
+ {
263
+ "object":"exception_mapping",
264
+ "category":"sdk",
265
+ "param":"end",
266
+ "exception_codes":[
267
+ "4"
268
+ ],
269
+ "mapping_type":"InvalidRequestException",
270
+ "mapping_code":"invalid_date",
271
+ "mapping_message":"Exception_Message_FutureDate"
272
+ },
273
+ {
274
+ "object":"exception_mapping",
275
+ "category":"sdk",
276
+ "param":"currency",
277
+ "exception_codes":[
278
+ "5"
279
+ ],
280
+ "mapping_type":"InvalidRequestException",
281
+ "mapping_code":"missing_currency",
282
+ "mapping_message":"Exception_Message_ArgumentNull"
283
+ },
284
+ {
285
+ "object":"exception_mapping",
286
+ "category":"sdk",
287
+ "param":"currency",
288
+ "exception_codes":[
289
+ "6"
290
+ ],
291
+ "mapping_type":"InvalidRequestException",
292
+ "mapping_code":"invalid_currency",
293
+ "mapping_message":"Exception_Message_InvalidCurrency"
294
+ },
295
+ {
296
+ "object":"exception_mapping",
297
+ "category":"sdk",
298
+ "param":"amount",
299
+ "exception_codes":[
300
+ "7"
301
+ ],
302
+ "mapping_type":"InvalidRequestException",
303
+ "mapping_code":"invalid_amount",
304
+ "mapping_message":"Exception_Message_ChargeAmount"
305
+ },
306
+ {
307
+ "object":"exception_mapping",
308
+ "category":"sdk",
309
+ "exception_codes":[
310
+ "8"
311
+ ],
312
+ "mapping_type":"HpsException",
313
+ "mapping_code":"gateway_timeout",
314
+ "mapping_message":"Exception_Message_UnableToReverseTransactionAfterGatewayTimeout"
315
+ },
316
+ {
317
+ "object":"exception_mapping",
318
+ "category":"sdk",
319
+ "exception_codes":[
320
+ "9"
321
+ ],
322
+ "mapping_type":"HpsException",
323
+ "mapping_code":"issuer_timeout",
324
+ "mapping_message":"Exception_Message_UnableToReverseTransactionAfterIssuerTimeout"
325
+ },
326
+ {
327
+ "object":"exception_mapping",
328
+ "category":"sdk",
329
+ "exception_codes":[
330
+ "10"
331
+ ],
332
+ "mapping_type":"CardException",
333
+ "mapping_code":"processing_error",
334
+ "mapping_message":"Exception_Message_ProcessingError"
335
+ }
336
+ ],
337
+ "exception_messages":[
338
+ {
339
+ "object":"exception_message",
340
+ "code":"Exception_Message_ArgumentNull",
341
+ "message":"Argument can't be null."
342
+ },
343
+ {
344
+ "object":"exception_message",
345
+ "code":"Exception_Message_AuthenticationError",
346
+ "message":"Authentication error. Please double check your service configuration."
347
+ },
348
+ {
349
+ "object":"exception_message",
350
+ "code":"Exception_Message_CardDeclined",
351
+ "message":"The card was declined."
352
+ },
353
+ {
354
+ "object":"exception_message",
355
+ "code":"Exception_Message_CardExpired",
356
+ "message":"The card has expired."
357
+ },
358
+ {
359
+ "object":"exception_message",
360
+ "code":"Exception_Message_ChargeAmount",
361
+ "message":"Must be greater than or equal 0."
362
+ },
363
+ {
364
+ "object":"exception_message",
365
+ "code":"Exception_Message_FutureDate",
366
+ "message":"Date can not be in the future."
367
+ },
368
+ {
369
+ "object":"exception_message",
370
+ "code":"Exception_Message_IncorrectCvc",
371
+ "message":"The card's security code is incorrect."
372
+ },
373
+ {
374
+ "object":"exception_message",
375
+ "code":"Exception_Message_IncorrectNumber",
376
+ "message":"The card number is incorrect."
377
+ },
378
+ {
379
+ "object":"exception_message",
380
+ "code":"Exception_Message_InvalidConfig",
381
+ "message":"The HPS SDK has not been properly configured. Please make sure to initialize the config either in a service constructor or in your App.config or Web.config file."
382
+ },
383
+ {
384
+ "object":"exception_message",
385
+ "code":"Exception_Message_InvalidCurrency",
386
+ "message":"The only supported currency is \"usd\""
387
+ },
388
+ {
389
+ "object":"exception_message",
390
+ "code":"Exception_Message_InvalidExpiry",
391
+ "message":"Card expiration date is invalid."
392
+ },
393
+ {
394
+ "object":"exception_message",
395
+ "code":"Exception_Message_InvalidNumber",
396
+ "message":"The card number is not a valid credit card number."
397
+ },
398
+ {
399
+ "object":"exception_message",
400
+ "code":"Exception_Message_InvalidPin",
401
+ "message":"The 4-digit pin is invalid."
402
+ },
403
+ {
404
+ "object":"exception_message",
405
+ "code":"Exception_Message_PinExceeded",
406
+ "message":"Maximum number of pin retries exceeded."
407
+ },
408
+ {
409
+ "object":"exception_message",
410
+ "code":"Exception_Message_PinVerification",
411
+ "message":"Can't verify card pin number."
412
+ },
413
+ {
414
+ "object":"exception_message",
415
+ "code":"Exception_Message_ProcessingError",
416
+ "message":"An error occurred while processing the card."
417
+ },
418
+ {
419
+ "object":"exception_message",
420
+ "code":"Exception_Message_TransactionIdLessThanEqualZero",
421
+ "message":"Transaction ID must be greater than zero."
422
+ },
423
+ {
424
+ "object":"exception_message",
425
+ "code":"Exception_Message_UnexpectedResponseCode",
426
+ "message":"Unsuccessful response code ({0}) received from HPS Gateway."
427
+ },
428
+ {
429
+ "object":"exception_message",
430
+ "code":"Exception_Message_UnexpectedResponseType",
431
+ "message":"Received unexpected response from POS Gateway. (Request and response transaction types don't match)."
432
+ },
433
+ {
434
+ "object":"exception_message",
435
+ "code":"Exception_Message_InvalidCpcData",
436
+ "message":"Invalid CPC data."
437
+ },
438
+ {
439
+ "object":"exception_message",
440
+ "code":"Exception_Message_InvalidCardData",
441
+ "message":"Invalid card data."
442
+ },
443
+ {
444
+ "object":"exception_message",
445
+ "code":"Exception_Message_GatewayTimedOut",
446
+ "message":"Gateway timed out."
447
+ },
448
+ {
449
+ "object":"exception_message",
450
+ "code":"Exception_Message_InvalidGatewayUrl",
451
+ "message":"Invalid HpsServiceUri."
452
+ },
453
+ {
454
+ "object":"exception_message",
455
+ "code":"Exception_Message_UnableToProcessTransaction",
456
+ "message":"Unable to process the payment transaction."
457
+ },
458
+ {
459
+ "object":"exception_message",
460
+ "code":"Exception_Message_UnableToReverseTransactionAfterGatewayTimeout",
461
+ "message":"Error occurred while reversing a charge due to HPS gateway time-out."
462
+ },
463
+ {
464
+ "object":"exception_message",
465
+ "code":"Exception_Message_UnableToReverseTransactionAfterIssuerTimeout",
466
+ "message":"Error occurred while reversing a charge due to issuer time-out."
467
+ }
468
+ ]
469
+ }
lib/SecureSubmit/infrastructure/HpsConfiguration.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsConfiguration {
4
+ public $secretApiKey = null,
5
+ $licenseId = null,
6
+ $siteId = null,
7
+ $deviceId = null,
8
+ $versionNumber = null,
9
+ $userName = null,
10
+ $password = null,
11
+ $developerId = null,
12
+ $siteTrace = null,
13
+ $useProxy = null,
14
+ $proxyOptions = null,
15
+ $avsResponseErrors = null,
16
+ $serviceUri = "https://posgateway.cert.secureexchange.net/Hps.Exchange.PosGateway/PosGatewayService.asmx";
17
+ }
lib/SecureSubmit/infrastructure/HpsException.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class HpsException extends Exception{
3
+ public $code = null,
4
+ $innerException = null,
5
+ $responseCode = null,
6
+ $responseText = null;
7
+
8
+ public function __construct($message, $code, $innerException = null){
9
+ $this->code = $code;
10
+ $this->innerException = $innerException;
11
+ parent::__construct($message, 0, $innerException);
12
+ }
13
+
14
+ public function code(){
15
+ if($this->code == null){
16
+ return "unknown";
17
+ }else{
18
+ return $this->code;
19
+ }
20
+ }
21
+ }
lib/SecureSubmit/infrastructure/HpsExceptionMapper.php ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsExceptionMapper{
4
+ public $exceptions = null;
5
+
6
+ public function __construct(){
7
+ $path = realpath(dirname(__FILE__));
8
+ $fileName = $path .'/Exceptions.json';
9
+ $fh = fopen($fileName,'r');
10
+ $jsonString = fread($fh, filesize($fileName));
11
+ $this->exceptions = json_decode($jsonString);
12
+ }
13
+
14
+ public function version_number(){
15
+ return $this->exceptions->version;
16
+ }
17
+
18
+ public function map_issuer_exception($transaction_id, $response_code, $response_text, $result_text = null){
19
+ $mapping = $this->exception_for_category_and_code('issuer', $response_code);
20
+
21
+ if(isset($mapping)){
22
+ $message = $this->message_for_mapping($mapping, $response_text);
23
+ $code = $mapping->mapping_code;
24
+ return new CardException($transaction_id, $code, $message, $result_text);
25
+ }else{
26
+ return new CardException($transaction_id, 'unknown_card_exception', $response_text, $result_text);
27
+ }
28
+ }
29
+
30
+ public function map_gateway_exception($transaction_id, $response_code, $response_text){
31
+ $mapping = $this->exception_for_category_and_code('gateway',$response_code);
32
+
33
+ if(isset($mapping)){
34
+ $message = $this->message_for_mapping($mapping, $response_text);
35
+ $code = $mapping->exception_codes[0];
36
+ $exception_type = $mapping->mapping_type;
37
+
38
+ if($exception_type == 'AuthenticationException'){
39
+ return new AuthenticationException($message);
40
+ }else if($exception_type == "CardException"){
41
+ return new CardException($transaction_id, $code, $message);
42
+ }else if($exception_type == "InvalidRequestException"){
43
+ return new InvalidRequestException($message, $mapping->param, $code);
44
+ }else if(isset($code)){
45
+ return new HpsException($response_text,$code);
46
+ }
47
+
48
+ }
49
+ return new HpsException($response_text,"unknown");
50
+ }
51
+
52
+ public function map_sdk_exception($error_code, $inner_exception = null){
53
+ $mapping = $this->exception_for_category_and_code('sdk', $error_code);
54
+ $sdk_codes = get_class_vars('HpsSdkCodes');
55
+ foreach($sdk_codes as $code_name=>$code_value){
56
+ if($code_value == $error_code){
57
+ $sdk_code_name = $code_name;
58
+ break;
59
+ }
60
+ }
61
+
62
+ if(isset($sdk_code_name)){
63
+ $response_text = $sdk_code_name;
64
+ }else{
65
+ $response_text = 'unknown';
66
+ }
67
+
68
+ if(isset($mapping)){
69
+ $message = $this->message_for_mapping($mapping, $response_text);
70
+ $code = $mapping->mapping_code;
71
+ $exception_type = $mapping->mapping_type;
72
+
73
+ if($exception_type == "InvalidRequestException"){
74
+ return new InvalidRequestException($message, $mapping->param, $code, $inner_exception);
75
+ }else if($exception_type == "ApiConnectionException"){
76
+ return new ApiConnectionException($message, $code, $inner_exception);
77
+ }else if(isset($code)){
78
+ return new HpsException($message, $code, $inner_exception);
79
+ }
80
+ }
81
+
82
+ return new HpsException('unknown', 'unknown', $inner_exception);
83
+ }
84
+
85
+ private function exception_for_category_and_code($category, $code){
86
+ foreach($this->exceptions->exception_mappings as $key=>$mapping){
87
+ if($mapping->category == $category && in_array($code,$mapping->exception_codes)){
88
+ return $mapping;
89
+ }
90
+ }
91
+ }
92
+
93
+ private function message_for_mapping($mapping, $original_message){
94
+ if(isset($mapping) && $mapping != null && $mapping != ""){
95
+ if(isset($mapping->mapping_message)){
96
+ $message = $mapping->mapping_message;
97
+ if(isset($message)){
98
+ foreach($this->exceptions->exception_messages as $key=>$exception_mapping){
99
+ if($exception_mapping->code == $message){
100
+ return $exception_mapping->message;
101
+ }
102
+ }
103
+ }
104
+ }
105
+ }
106
+ return $original_message;
107
+ }
108
+
109
+ }
lib/SecureSubmit/infrastructure/HpsSdkCodes.php ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class HpsSdkCodes {
3
+ public static $invalidTransactionId = "0",
4
+ $invalidGatewayUrl = "1",
5
+ $unableToProcessTransaction = "2",
6
+ $invalidStartDate = "3",
7
+ $invalidEndDate = "4",
8
+ $missingCurrency = "5",
9
+ $invalidCurrency = "6",
10
+ $invalidAmount = "7",
11
+ $reversalErrorAfterGatewayTimeout = "8",
12
+ $reversalErrorAfterIssuerTimeout = "9",
13
+ $processingError = "10";
14
+ }
lib/SecureSubmit/infrastructure/InvalidRequestException.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class InvalidRequestException extends HpsException{
3
+ public $param = null;
4
+
5
+ public function __construct($message, $param = null, $code = null, $innerException = null){
6
+ $this->param = $param;
7
+ parent::__construct($message, $code, $innerException);
8
+ }
9
+
10
+ }
lib/SecureSubmit/services/HpsBatchService.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsBatchService extends HpsService{
4
+ public function closeBatch(){
5
+ $xml = new DOMDocument();
6
+ $hpsTransaction = $xml->createElement('hps:Transaction');
7
+ $hpsBatchClose = $xml->createElement('hps:BatchClose');
8
+ $hpsTransaction->appendChild($hpsBatchClose);
9
+
10
+ $response = $this->doTransaction($hpsTransaction);
11
+ $header = $response->Header;
12
+
13
+ if($header->GatewayRspCode != "0"){
14
+ throw $this->exceptionMapper->map_gateway_exception($header->GatewayTxnId,$header->GatewayRspCode,$header->GatewayRspMsg);
15
+ }
16
+
17
+ $batchClose = $response->Transaction->BatchClose;
18
+ $result = new HpsBatch();
19
+ $result->id = (isset($batchClose->BatchId) ? $batchClose->BatchId : null);
20
+ $result->sequenceNumber = (isset($batchClose->BatchSeqNbr) ? $batchClose->BatchSeqNbr : null);
21
+ $result->totalAmount = (isset($batchClose->TotalAmt) ? $batchClose->TotalAmt : null);
22
+ $result->transactionCount = (isset($batchClose->TxnCnt) ? $batchClose->TxnCnt : null);
23
+
24
+ return $result;
25
+ }
26
+ }
lib/SecureSubmit/services/HpsChargeService.php ADDED
@@ -0,0 +1,602 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsChargeService extends HpsService{
4
+
5
+ public function authorize($amount, $currency, $cardOrToken, $cardHolder=null, $requestMultiUseToken=false, $details=null){
6
+ $this->_checkAmount($amount);
7
+ $this->_checkCurrency($currency);
8
+ $amount = sprintf("%0.2f",round($amount,3));
9
+
10
+ $xml = new DOMDocument();
11
+ $hpsTransaction = $xml->createElement('hps:Transaction');
12
+ $hpsCreditAuth = $xml->createElement('hps:CreditAuth');
13
+ $hpsBlock1 = $xml->createElement('hps:Block1');
14
+ $hpsBlock1->appendChild($xml->createElement('hps:AllowDup','Y'));
15
+ $hpsBlock1->appendChild($xml->createElement('hps:Amt',$amount));
16
+ if($cardHolder != null){
17
+ $hpsBlock1->appendChild($this->_hydrateCardHolderData($cardHolder,$xml));
18
+ }
19
+
20
+ if($details != null){
21
+ $hpsBlock1->appendChild($this->_hydrateAdditionalTxnFields($details,$xml));
22
+ }
23
+ $cardData = $xml->createElement('hps:CardData');
24
+ if($cardOrToken instanceOf HpsCreditCard){
25
+ $cardData->appendChild($this->_hydrateManualEntry($cardOrToken,$xml));
26
+ }else{
27
+ $tokenData = $xml->createElement('hps:TokenData');
28
+ $tokenData->appendChild($xml->createElement('hps:TokenValue',$cardOrToken->tokenValue));
29
+ $cardData->appendChild($tokenData);
30
+ }
31
+ $cardData->appendChild($xml->createElement('hps:TokenRequest',($requestMultiUseToken) ? 'Y' : 'N'));
32
+ $hpsBlock1->appendChild($cardData);
33
+ $hpsCreditAuth->appendChild($hpsBlock1);
34
+ $hpsTransaction->appendChild($hpsCreditAuth);
35
+ return $this->_submitAuthorize($hpsTransaction, $amount, $currency);
36
+ }
37
+
38
+ public function capture($transactionId, $amount=null, $gratuity=null){
39
+ $xml = new DOMDocument();
40
+ $hpsTransaction = $xml->createElement('hps:Transaction');
41
+ $hpsCreditAddToBatch = $xml->createElement('hps:CreditAddToBatch');
42
+ $hpsCreditAddToBatch->appendChild($xml->createElement('hps:GatewayTxnId',$transactionId));
43
+ if($amount != null){
44
+ $amount = sprintf("%0.2f",round($amount,3));
45
+ $hpsCreditAddToBatch->appendChild($xml->createElement('hps:Amt',$amount));
46
+ }
47
+ if($gratuity != null){
48
+ $hpsCreditAddToBatch->appendChild($xml->createElement('hps:GratuityAmtInfo',$gratuity));
49
+ }
50
+ $hpsTransaction->appendChild($hpsCreditAddToBatch);
51
+ $response = $this->doTransaction($hpsTransaction);
52
+ $header = $response->Header;
53
+
54
+ if($header->GatewayRspCode != 0){
55
+ throw $this->exceptionMapper->map_gateway_exception($transactionId,$header->GatewayRspCode,$header->GatewayRspMsg);
56
+ }
57
+
58
+ return $this->get($transactionId);
59
+ }
60
+
61
+ public function charge($amount, $currency, $cardOrToken, $cardHolder=null, $requestMultiUseToken=false, $details=null){
62
+ $this->_checkAmount($amount);
63
+ $this->_checkCurrency($currency);
64
+ $amount = sprintf("%0.2f",round($amount,3));
65
+
66
+ $xml = new DOMDocument();
67
+ $hpsTransaction = $xml->createElement('hps:Transaction');
68
+ $hpsCreditSale = $xml->createElement('hps:CreditSale');
69
+ $hpsBlock1 = $xml->createElement('hps:Block1');
70
+ $hpsBlock1->appendChild($xml->createElement('hps:AllowDup','Y'));
71
+ $hpsBlock1->appendChild($xml->createElement('hps:Amt',$amount));
72
+ if($cardHolder != null){
73
+ $hpsBlock1->appendChild($this->_hydrateCardHolderData($cardHolder,$xml));
74
+ }
75
+
76
+ if($details != null){
77
+ $hpsBlock1->appendChild($this->_hydrateAdditionalTxnFields($details,$xml));
78
+ }
79
+ $cardData = $xml->createElement('hps:CardData');
80
+ if($cardOrToken instanceOf HpsCreditCard){
81
+ $cardData->appendChild($this->_hydrateManualEntry($cardOrToken,$xml));
82
+ }else{
83
+ $tokenData = $xml->createElement('hps:TokenData');
84
+ $tokenData->appendChild($xml->createElement('hps:TokenValue',$cardOrToken->tokenValue));
85
+ $cardData->appendChild($tokenData);
86
+ }
87
+ $cardData->appendChild($xml->createElement('hps:TokenRequest',($requestMultiUseToken) ? 'Y' : 'N'));
88
+ $hpsBlock1->appendChild($cardData);
89
+ $hpsCreditSale->appendChild($hpsBlock1);
90
+ $hpsTransaction->appendChild($hpsCreditSale);
91
+
92
+ return $this->_submitCharge($hpsTransaction,$amount,$currency);
93
+ }
94
+
95
+ public function get($transactionId){
96
+ if($transactionId <= 0){
97
+ throw $this->exceptionMapper->map_sdk_exception(HpsSdkCodes::$invalidTransactionId);
98
+ }
99
+
100
+ $xml = new DOMDocument();
101
+ $hpsTransaction = $xml->createElement('hps:Transaction');
102
+ $hpsReportTxnDetail = $xml->createElement('hps:ReportTxnDetail');
103
+ $hpsReportTxnDetail->appendChild($xml->createElement('hps:TxnId',$transactionId));
104
+ $hpsTransaction->appendChild($hpsReportTxnDetail);
105
+
106
+ $response = $this->doTransaction($hpsTransaction);
107
+ $detail = $response->Transaction->ReportTxnDetail;
108
+
109
+ $header = $this->hydrateTransactionHeader($response->Header);
110
+ $result = new HpsReportTransactionDetails($header);
111
+ $result->transactionId = $detail->GatewayTxnId;
112
+ $result->originalTransactionId = (isset($detail->OriginalGatewayTxnId) ? $detail->OriginalGatewayTxnId : null);
113
+ $result->authorizedAmount = (isset($detail->Data->AuthAmt) ? $detail->Data->AuthAmt : null);
114
+ $result->authorizationCode = (isset($detail->Data->AuthCode) ? $detail->Data->AuthCode : null);
115
+ $result->avsResultCode = (isset($detail->Data->AVSRsltCode) ? $detail->Data->AVSRsltCode : null);
116
+ $result->avsResultText = (isset($detail->Data->AVSRsltText) ? $detail->Data->AVSRsltText : null);
117
+ $result->cardType = (isset($detail->Data->CardType) ? $detail->Data->CardType : null);
118
+ $result->maskedCardNumber = (isset($detail->Data->MaskedCardNbr) ? $detail->Data->MaskedCardNbr : null);
119
+ $result->transactionType = (isset($detail->ServiceName) ? HpsTransaction::serviceNameToTransactionType($detail->ServiceName) : null);
120
+ $result->transactionDate = (isset($detail->RspUtcDT) ? $detail->RspUtcDT : null);
121
+ $result->cpcIndicator = (isset($detail->Data->CPCInd) ? $detail->Data->CPCInd : null);
122
+ $result->cvvResultCode = (isset($detail->Data->CVVRsltCode) ? $detail->Data->CVVRsltCode : null);
123
+ $result->cvvResultText = (isset($detail->Data->CVVRsltText) ? $detail->Data->CVVRsltText : null);
124
+ $result->referenceNumber = (isset($detail->Data->RefNbr) ? $detail->Data->RefNbr : null);
125
+ $result->responseCode = (isset($detail->Data->RspCode) ? $detail->Data->RspCode : null);
126
+ $result->responseText = (isset($detail->Data->RspText) ? $detail->Data->RspText : null);
127
+
128
+ $tokenizationMessage = (isset($detail->Data->TokenizationMsg) ? $detail->Data->TokenizationMsg : null);
129
+ if($tokenizationMessage != null){
130
+ $result->tokenData = new HpsTokenData($tokenizationMessage);
131
+ }
132
+
133
+ $headerResponseCode = (isset($response->Header->GatewayRspCode) ? $response->Header->GatewayRspCode : null);
134
+ $dataResponseCode = (isset($detail->Data->RspCode) ? $detail->Data->RspCode : null);
135
+
136
+ if($headerResponseCode != "0" || $dataResponseCode != "00"){
137
+ $exceptions = new HpsChargeExceptions();
138
+
139
+ if($headerResponseCode != "0"){
140
+ $message = $response->Header->GatewayRspMsg;
141
+ $exceptions->hpsException = $this->exceptionMapper->map_gateway_exception($result->transactionId,$headerResponseCode,$message);
142
+ }
143
+ if($dataResponseCode != "00"){
144
+ $message = $detail->Data->RspText;
145
+ $exceptions->cardException = $this->exceptionMapper->map_issuer_exception($transactionId,$dataResponseCode,$message);
146
+ }
147
+ $result->exceptions = $exceptions;
148
+ }
149
+ return $result;
150
+ }
151
+
152
+ public function listTransactions($startDate, $endDate, $filterBy=null){
153
+ date_default_timezone_set("UTC");
154
+ $dateFormat = 'Y-m-d\TH:i:s.00\Z';
155
+ $current = new DateTime();
156
+ $currentTime = $current->format($dateFormat);
157
+
158
+ if($startDate > $currentTime){
159
+ throw $this->exceptionMapper->map_sdk_exception(HpsSdkCodes::$invalidStartDate);
160
+ }
161
+ else if($endDate > $currentTime){
162
+ throw $this->exceptionMapper->map_sdk_exception(HpsSdkCodes::$invalidEndDate);
163
+ }
164
+
165
+ $xml = new DOMDocument();
166
+ $hpsTransaction = $xml->createElement('hps:Transaction');
167
+ $hpsReportActivity = $xml->createElement('hps:ReportActivity');
168
+ $hpsReportActivity->appendChild($xml->createElement('hps:RptStartUtcDT',$startDate));
169
+ $hpsReportActivity->appendChild($xml->createElement('hps:RptEndUtcDT',$endDate));
170
+ $hpsTransaction->appendChild($hpsReportActivity);
171
+
172
+ $response = $this->doTransaction($hpsTransaction);
173
+
174
+ // Gateway Exception
175
+ if($response->Header->GatewayRspCode !=0){
176
+ $transactionId = $response->Header->GatewayTxnId;
177
+ $responseCode = $response->Header->GatewayRspCode;
178
+ $responseMessage = $response->Header->GatewayRspMessage;
179
+ throw $this->exceptionMapper->map_gateway_exception($transactionId,$responseCode,$responseMessage);
180
+ }
181
+ $result = array();
182
+ if($response->Transaction->ReportActivity->Header->TxnCnt == "0"){
183
+ return $result;
184
+ }
185
+
186
+ foreach ($response->Transaction->ReportActivity->Details as $charge) {
187
+ if($filterBy != null && $charge->ServiceName != HpsTransaction::transactionTypeToServiceName($filterBy)){
188
+ continue;
189
+ }else{
190
+ $summary = new HpsReportTransactionSummary();
191
+ $summary->transactionId = (isset($charge->GatewayTxnId) ? $charge->GatewayTxnId : null);
192
+ $summary->originalTransactionId = (isset($charge->OriginalGatewayTxnId) ? $charge->OriginalGatewayTxnId : null);
193
+ $summary->maskedCardNumber = (isset($charge->MaskedCardNbr) ? $charge->MaskedCardNbr : null);
194
+ $summary->responseCode = (isset($charge->IssuerRspCode) ? $charge->IssuerRspCode : null);
195
+ $summary->responseText = (isset($charge->IssuerRspText) ? $charge->IssuerRspText : null);
196
+
197
+ if($filterBy != null ){
198
+ $summary->transactionType = (isset($charge->ServiceName) ? HpsTransaction::transactionTypeToServiceName($charge->ServiceName) : null);
199
+ }
200
+
201
+ $gwResponseCode = (isset($charge->GatewayRspCode) ? $charge->GatewayRspCode : null);
202
+ $issuerResponseCode = (isset($charge->IssuerRspCode) ? $charge->IssuerRspCode : null);
203
+
204
+ if($gwResponseCode != "0" || $issuerResponseCode != "00"){
205
+ $exceptions = new HpsChargeExceptions();
206
+ if($gwResponseCode != "0"){
207
+ $message = $charge->GatewayRspMsg;
208
+ $exceptions->hpsException = $this->exceptionMapper->map_gateway_exception($charge->GatewayTxnId, $gwResponseCode, $message);
209
+ }
210
+ if($issuerResponseCode != "00"){
211
+ $message = $charge->IssuerRspText;
212
+ $exceptions->cardException = $this->exceptionMapper->map_issuer_exception($charge->GatewayTxnId, $issuerResponseCode, $message);
213
+ }
214
+ $summary->exceptions = $exceptions;
215
+ }
216
+ }
217
+ $result = $summary;
218
+ }
219
+ return $result;
220
+ }
221
+
222
+ public function refund($amount, $currency, $cardOrToken, $cardHolder=null, $details=null){
223
+ $this->_checkAmount($amount);
224
+ $this->_checkCurrency($currency);
225
+ $amount = sprintf("%0.2f",round($amount,3));
226
+
227
+ $xml = new DOMDocument();
228
+ $hpsTransaction = $xml->createElement('hps:Transaction');
229
+ $hpsCreditReturn = $xml->createElement('hps:CreditReturn');
230
+ $hpsBlock1 = $xml->createElement('hps:Block1');
231
+ $hpsBlock1->appendChild($xml->createElement('hps:AllowDup','Y'));
232
+ $hpsBlock1->appendChild($xml->createElement('hps:Amt',$amount));
233
+ if($cardHolder != null){
234
+ $hpsBlock1->appendChild($this->_hydrateCardHolderData($cardHolder,$xml));
235
+ }
236
+ if($details != null){
237
+ $hpsBlock1->appendChild($this->_hydrateAdditionalTxnFields($details,$xml));
238
+ }
239
+ $cardData = $xml->createElement('hps:CardData');
240
+ if($cardOrToken instanceOf HpsCreditCard){
241
+ $cardData->appendChild($this->_hydrateManualEntry($cardOrToken,$xml));
242
+ }else{
243
+ $tokenData = $xml->createElement('hps:TokenData');
244
+ $tokenData->appendChild($xml->createElement('hps:TokenValue',$cardOrToken->tokenValue));
245
+ $cardData->appendChild($tokenData);
246
+ }
247
+ $hpsBlock1->appendChild($cardData);
248
+ $hpsCreditReturn->appendChild($hpsBlock1);
249
+ $hpsTransaction->appendChild($hpsCreditReturn);
250
+ return $this->_submitRefund($hpsTransaction);
251
+ }
252
+
253
+ public function refundTransaction($amount,$currency,$transactionId, $cardHolder=null, $details=null){
254
+ $this->_checkAmount($amount);
255
+ $this->_checkCurrency($currency);
256
+ $amount = sprintf("%0.2f",round($amount,3));
257
+
258
+ $xml = new DOMDocument();
259
+ $hpsTransaction = $xml->createElement('hps:Transaction');
260
+ $hpsCreditReturn = $xml->createElement('hps:CreditReturn');
261
+ $hpsBlock1 = $xml->createElement('hps:Block1');
262
+ $hpsBlock1->appendChild($xml->createElement('hps:AllowDup','Y'));
263
+ $hpsBlock1->appendChild($xml->createElement('hps:Amt',$amount));
264
+ $hpsBlock1->appendChild($xml->createElement('hps:GatewayTxnId',$transactionId));
265
+ if($cardHolder != null){
266
+ $hpsBlock1->appendChild($this->_hydrateCardHolderData($cardHolder,$xml));
267
+ }
268
+ if($details != null){
269
+ $hpsBlock1->appendChild($this->_hydrateAdditionalTxnFields($details,$xml));
270
+ }
271
+ $hpsCreditReturn->appendChild($hpsBlock1);
272
+ $hpsTransaction->appendChild($hpsCreditReturn);
273
+ return $this->_submitRefund($hpsTransaction);
274
+ }
275
+
276
+ public function reverse($cardOrToken, $amount, $currency, $details=null){
277
+ $this->_checkAmount($amount);
278
+ $this->_checkCurrency($currency);
279
+ $amount = sprintf("%0.2f",round($amount,3));
280
+
281
+ $xml = new DOMDocument();
282
+ $hpsTransaction = $xml->createElement('hps:Transaction');
283
+ $hpsCreditReversal = $xml->createElement('hps:CreditReversal');
284
+ $hpsBlock1 = $xml->createElement('hps:Block1');
285
+ $hpsBlock1->appendChild($xml->createElement('hps:Amt',$amount));
286
+ if($details != null){
287
+ $hpsBlock1->appendChild($this->_hydrateAdditionalTxnFields($details,$xml));
288
+ }
289
+ $cardData = $xml->createElement('hps:CardData');
290
+ if($cardOrToken instanceOf HpsCreditCard){
291
+ $cardData->appendChild($this->_hydrateManualEntry($cardOrToken,$xml));
292
+ }else{
293
+ $tokenData = $xml->createElement('hps:TokenData');
294
+ $tokenData->appendChild($xml->createElement('hps:TokenValue',$cardOrToken->tokenValue));
295
+ $cardData->appendChild($tokenData);
296
+ }
297
+ $hpsBlock1->appendChild($cardData);
298
+ $hpsCreditReversal->appendChild($hpsBlock1);
299
+ $hpsTransaction->appendChild($hpsCreditReversal);
300
+
301
+ return $this->_submitReverse($hpsTransaction);
302
+ }
303
+
304
+ public function reverseTransaction($transactionId, $amount,$currency, $details=null){
305
+ $this->_checkAmount($amount);
306
+ $this->_checkCurrency($currency);
307
+ $amount = sprintf("%0.2f",round($amount,3));
308
+
309
+ $xml = new DOMDocument();
310
+ $hpsTransaction = $xml->createElement('hps:Transaction');
311
+ $hpsCreditReversal = $xml->createElement('hps:CreditReversal');
312
+ $hpsBlock1 = $xml->createElement('hps:Block1');
313
+ $hpsBlock1->appendChild($xml->createElement('hps:Amt',$amount));
314
+ $hpsBlock1->appendChild($xml->createElement('hps:GatewayTxnId',$transactionId));
315
+ if($details != null){
316
+ $hpsBlock1->appendChild($this->_hydrateAdditionalTxnFields($details,$xml));
317
+ }
318
+ $hpsCreditReversal->appendChild($hpsBlock1);
319
+ $hpsTransaction->appendChild($hpsCreditReversal);
320
+
321
+ return $this->_submitReverse($hpsTransaction);
322
+ }
323
+
324
+ public function verify($cardOrToken, $cardHolder=null, $requestMultiUseToken=false){
325
+ $xml = new DOMDocument();
326
+ $hpsTransaction = $xml->createElement('hps:Transaction');
327
+ $hpsCreditAccountVerify = $xml->createElement('hps:CreditAccountVerify');
328
+ $hpsBlock1 = $xml->createElement('hps:Block1');
329
+ if($cardHolder != null){
330
+ $hpsBlock1->appendChild($this->_hydrateCardHolderData($cardHolder,$xml));
331
+ }
332
+ $cardData = $xml->createElement('hps:CardData');
333
+ if($cardOrToken instanceOf HpsCreditCard){
334
+ $cardData->appendChild($this->_hydrateManualEntry($cardOrToken,$xml));
335
+ }else{
336
+ $tokenData = $xml->createElement('hps:TokenData');
337
+ $tokenData->appendChild($xml->createElement('hps:TokenValue',$cardOrToken->tokenValue));
338
+ $cardData->appendChild($tokenData);
339
+ }
340
+ $cardData->appendChild($xml->createElement('hps:TokenRequest',($requestMultiUseToken) ? 'Y' : 'N'));
341
+ $hpsBlock1->appendChild($cardData);
342
+ $hpsCreditAccountVerify->appendChild($hpsBlock1);
343
+ $hpsTransaction->appendChild($hpsCreditAccountVerify);
344
+
345
+ $response = $this->doTransaction($hpsTransaction);
346
+ $header = $response->Header;
347
+
348
+ if($header->GatewayRspCode != "0"){
349
+ throw $this->exceptionMapper->map_gateway_exception($header->GatewayTxnId,$header->GatewayRspCode,$header->GatewayRspMsg);
350
+ }
351
+
352
+ $accountVerify = $response->Transaction->CreditAccountVerify;
353
+ $result = new HpsAccountVerify($this->hydrateTransactionHeader($header));
354
+ $result->transactionId = (isset($accountVerify->GatewayTxnId) ? $accountVerify->GatewayTxnId : null);
355
+ $result->avsResultCode = (isset($accountVerify->AVSRsltCode) ? $accountVerify->AVSRsltCode : null);
356
+ $result->avsResultText = (isset($accountVerify->AVSRsltText) ? $accountVerify->AVSRsltText : null);
357
+ $result->referenceNumber = (isset($accountVerify->RefNbr) ? $accountVerify->RefNbr : null);
358
+ $result->responseCode = (isset($accountVerify->RspCode) ? $accountVerify->RspCode : null);
359
+ $result->responseText = (isset($accountVerify->RspText) ? $accountVerify->RspText : null);
360
+ $result->cardType = (isset($accountVerify->CardType) ? $accountVerify->CardType : null);
361
+ $result->cpcIndicator = (isset($accountVerify->CPCInd) ? $accountVerify->CPCInd : null);
362
+ $result->cvvResultCode = (isset($accountVerify->CVVRsltCode) ? $accountVerify->CVVRsltCode : null);
363
+ $result->cvvResultText = (isset($accountVerify->CVVRsltText) ? $accountVerify->CVVRsltText : null);
364
+ $result->authorizationCode = (isset($accountVerify->AuthCode) ? $accountVerify->AuthCode : null);
365
+ $result->authorizedAmount = (isset($accountVerify->AuthAmt) ? $accountVerify->AuthAmt : null);
366
+
367
+ if($result->responseCode != "00" && $result->responseCode != "85"){
368
+ throw $this->exceptionMapper->map_issuer_exception($result->transactionId, $result->responseCode, $result->responseText);
369
+ }
370
+
371
+ if(isset($header->TokenData) && is_object($header->TokenData)){
372
+ $result->tokenData = new HpsTokenData();
373
+ $result->tokenData->responseCode = $header->TokenData->TokenRspCode;
374
+ $result->tokenData->responseMessage = $header->TokenData->TokenRspMsg;
375
+ $result->tokenData->tokenValue = $header->TokenData->TokenValue;
376
+ }
377
+
378
+ return $result;
379
+ }
380
+
381
+ public function void($transactionId){
382
+ $xml = new DOMDocument();
383
+ $hpsTransaction = $xml->createElement('hps:Transaction');
384
+ $hpsCreditVoid = $xml->createElement('hps:CreditVoid');
385
+ $hpsCreditVoid->appendChild($xml->createElement('hps:GatewayTxnId',$transactionId));
386
+ $hpsTransaction->appendChild($hpsCreditVoid);
387
+
388
+ $response = $this->doTransaction($hpsTransaction);
389
+ $header = $response->Header;
390
+
391
+ if($header->GatewayRspCode != "0"){
392
+ throw $this->exceptionMapper->map_gateway_exception($header->GatewayTxnId,$header->GatewayRspCode,$header->GatewayRspMsg);
393
+ }
394
+
395
+ $creditVoid = $response->Transaction->CreditVoid;
396
+ $result = new HpsVoid($this->hydrateTransactionHeader($header));
397
+ $result->transactionId = (isset($creditVoid->GatewayTxnId) ? $creditVoid->GatewayTxnId : null);
398
+ $result->responseCode = "00";
399
+ $result->responseText = "";
400
+ return $result;
401
+ }
402
+
403
+ private function _checkAmount($amount){
404
+ if ($amount <= 0 || $amount == null){
405
+ throw $this->exceptionMapper->map_sdk_exception(HpsSdkCodes::$invalidAmount);
406
+ }
407
+ }
408
+
409
+ private function _checkCurrency($currency){
410
+ if ($currency == null or $currency == ""){
411
+ throw $this->exceptionMapper->map_sdk_exception(HpsSdkCodes::$missingCurrency);
412
+ }
413
+ if (strtolower($currency) != "usd"){
414
+ throw $this->exceptionMapper->map_sdk_exception(HpsSdkCodes::$invalidCurrency);
415
+ }
416
+ }
417
+
418
+ private function _hydrateAdditionalTxnFields($details,DOMDocument $xml){
419
+ $additionalTxnFields = $xml->createElement('hps:AdditionalTxnFields');
420
+ if($details->memo != null && $details->memo != ""){
421
+ $additionalTxnFields->appendChild($xml->createElement('hps:Description',$details->memo));
422
+ }
423
+ if($details->invoiceNumber != null && $details->invoiceNumber != ""){
424
+ $additionalTxnFields->appendChild($xml->createElement('hps:InvoiceNbr',$details->invoiceNumber));
425
+ }
426
+ if($details->customerId != null && $details->customerId != ""){
427
+ $additionalTxnFields->appendChild($xml->createElement('hps:CustomerID',$details->customerId));
428
+ }
429
+ return $additionalTxnFields;
430
+ }
431
+
432
+ private function _hydrateCardHolderData(HpsCardHolder $cardHolder, DOMDocument $xml){
433
+ $cardHolderData = $xml->createElement('hps:CardHolderData');
434
+ $cardHolderData->appendChild($xml->createElement('hps:CardHolderFirstName',$cardHolder->firstName));
435
+ $cardHolderData->appendChild($xml->createElement('hps:CardHolderLastName',$cardHolder->lastName));
436
+ $cardHolderData->appendChild($xml->createElement('hps:CardHolderEmail',$cardHolder->emailAddress));
437
+ $cardHolderData->appendChild($xml->createElement('hps:CardHolderPhone',$cardHolder->phone));
438
+ $cardHolderData->appendChild($xml->createElement('hps:CardHolderAddr',$cardHolder->address->address));
439
+ $cardHolderData->appendChild($xml->createElement('hps:CardHolderCity',$cardHolder->address->city));
440
+ $cardHolderData->appendChild($xml->createElement('hps:CardHolderState',$cardHolder->address->state));
441
+ $cardHolderData->appendChild($xml->createElement('hps:CardHolderZip',$cardHolder->address->zip));
442
+
443
+ return $cardHolderData;
444
+ }
445
+
446
+ private function _hydrateManualEntry(HpsCreditCard $card,DOMDocument $xml){
447
+ $manualEntry = $xml->createElement('hps:ManualEntry');
448
+ $manualEntry->appendChild($xml->createElement('hps:CardNbr',$card->number));
449
+ $manualEntry->appendChild($xml->createElement('hps:ExpMonth',$card->expMonth));
450
+ $manualEntry->appendChild($xml->createElement('hps:ExpYear',$card->expYear));
451
+ $manualEntry->appendChild($xml->createElement('hps:CVV2',$card->cvv));
452
+ $manualEntry->appendChild($xml->createElement('hps:CardPresent',"N"));
453
+ $manualEntry->appendChild($xml->createElement('hps:ReaderPresent',"N"));
454
+
455
+ return $manualEntry;
456
+ }
457
+
458
+ private function _processChargeGatewayResponse($responseCode, $responseText, $transactionId, $amount, $currency){
459
+ if($responseCode != 0){
460
+ if($responseCode == 30){
461
+ try{
462
+ $this->reverseTransaction($transactionId, $amount, $currency);
463
+ }catch (Exception $e){
464
+ $exception = $this->exceptionMapper->map_sdk_exception(HpsSdkCodes::$reversalErrorAfterGatewayTimeout, $e);
465
+ $exception->responseCode = $responseCode;
466
+ $exception->responseText = $responseText;
467
+ throw $exception;
468
+ }
469
+ }
470
+ $exception = $this->exceptionMapper->map_gateway_exception($transactionId,$responseCode, $responseText);
471
+ $exception->responseCode = $responseCode;
472
+ $exception->responseText = $responseText;
473
+ throw $exception;
474
+ }
475
+ }
476
+
477
+ private function _processChargeIssuerResponse($responseCode, $responseText, $transactionId, $amount, $currency){
478
+ if($responseCode == "91"){
479
+ try{
480
+ $this->reverseTransaction($transactionId, $amount, $currency);
481
+ }catch (Exception $e){
482
+ $exception = $this->exceptionMapper->map_sdk_exception(HpsSdkCodes::$reversalErrorAfterIssuerTimeout, $e);
483
+ $exception->responseCode = $responseCode;
484
+ $exception->responseText = $responseText;
485
+ throw $exception;
486
+ }
487
+ $exception = $this->exceptionMapper->map_sdk_exception(HpsSdkCodes::$processingError);
488
+ $exception->responseCode = $responseCode;
489
+ $exception->responseText = $responseText;
490
+ throw $exception;
491
+ }else if($responseCode != "00"){
492
+ $exception = $this->exceptionMapper->map_issuer_exception($transactionId, $responseCode, $responseText);
493
+ $exception->responseCode = $responseCode;
494
+ $exception->responseText = $responseText;
495
+ throw $exception;
496
+ }
497
+ }
498
+
499
+ private function _submitAuthorize($transaction, $amount, $currency){
500
+ $response = $this->doTransaction($transaction);
501
+ $avsChecking = new AVSResponseCodeHandler($response,$this,$this->config);
502
+ $header = $response->Header;
503
+ $this->_processChargeGatewayResponse($header->GatewayRspCode,$header->GatewayRspMsg,$header->GatewayTxnId,$amount,$currency);
504
+
505
+ $authResponse = $response->Transaction->CreditAuth;
506
+ $this->_processChargeIssuerResponse($authResponse->RspCode,$authResponse->RspText,$authResponse->GatewayTxnId,$amount,$currency);
507
+
508
+ $result = new HpsAuthorization($this->hydrateTransactionHeader($header));
509
+ $result->transactionId = $header->GatewayTxnId;
510
+ $result->authorizedAmount = (isset($authResponse->AuthAmt) ? $authResponse->AuthAmt : null);
511
+ $result->authorizationCode = (isset($authResponse->AuthCode) ? $authResponse->AuthCode : null);
512
+ $result->avsResultCode = (isset($authResponse->AVSRsltCode) ? $authResponse->AVSRsltCode : null);
513
+ $result->avsResultText = (isset($authResponse->AVSRsltText) ? $authResponse->AVSRsltText : null);
514
+ $result->cardType = (isset($authResponse->CardType) ? $authResponse->CardType : null);
515
+ $result->cpcIndicator = (isset($authResponse->CPCInd) ? $authResponse->CPCInd : null);
516
+ $result->cvvResultCode = (isset($authResponse->CVVRsltCode) ? $authResponse->CVVRsltCode : null);
517
+ $result->cvvResultText = (isset($authResponse->CVVRsltText) ? $authResponse->CVVRsltText : null);
518
+ $result->referenceNumber = (isset($authResponse->RefNbr) ? $authResponse->RefNbr : null);
519
+ $result->responseCode = (isset($authResponse->RspCode) ? $authResponse->RspCode : null);
520
+ $result->responseText = (isset($authResponse->RspText) ? $authResponse->RspText : null);
521
+
522
+ if(isset($header->TokenData) && is_object($header->TokenData)){
523
+ $result->tokenData = new HpsTokenData();
524
+ $result->tokenData->responseCode = $header->TokenData->TokenRspCode;
525
+ $result->tokenData->responseMessage = $header->TokenData->TokenRspMsg;
526
+ $result->tokenData->tokenValue = $header->TokenData->TokenValue;
527
+ }
528
+
529
+ return $result;
530
+ }
531
+
532
+ private function _submitCharge($transaction, $amount, $currency){
533
+ $response = $this->doTransaction($transaction);
534
+ $avsChecking = new AVSResponseCodeHandler($response,$this,$this->config);
535
+ $header = $response->Header;
536
+ $this->_processChargeGatewayResponse($header->GatewayRspCode,$header->GatewayRspMsg,$header->GatewayTxnId,$amount,$currency);
537
+
538
+ $creditSaleRsp = $response->Transaction->CreditSale;
539
+ $this->_processChargeIssuerResponse($creditSaleRsp->RspCode,$creditSaleRsp->RspText,$creditSaleRsp->GatewayTxnId,$amount,$currency);
540
+
541
+ $result = new HpsCharge($this->hydrateTransactionHeader($header));
542
+ $result->transactionId = $header->GatewayTxnId;
543
+ $result->authorizedAmount = (isset($creditSaleRsp->AuthAmt) ? $creditSaleRsp->AuthAmt : null);
544
+ $result->authorizationCode = (isset($creditSaleRsp->AuthCode) ? $creditSaleRsp->AuthCode : null);
545
+ $result->avsResultCode = (isset($creditSaleRsp->AVSRsltCode) ? $creditSaleRsp->AVSRsltCode : null);
546
+ $result->avsResultText = (isset($creditSaleRsp->AVSRsltText) ? $creditSaleRsp->AVSRsltText : null);
547
+ $result->cardType = (isset($creditSaleRsp->CardType) ? $creditSaleRsp->CardType : null);
548
+ $result->cpcIndicator = (isset($creditSaleRsp->CPCInd) ? $creditSaleRsp->CPCInd : null);
549
+ $result->cvvResultCode = (isset($creditSaleRsp->CVVRsltCode) ? $creditSaleRsp->CVVRsltCode : null);
550
+ $result->cvvResultText = (isset($creditSaleRsp->CVVRsltText) ? $creditSaleRsp->CVVRsltText : null);
551
+ $result->referenceNumber = (isset($creditSaleRsp->RefNbr) ? $creditSaleRsp->RefNbr : null);
552
+ $result->responseCode = (isset($creditSaleRsp->RspCode) ? $creditSaleRsp->RspCode : null);
553
+ $result->responseText = (isset($creditSaleRsp->RspText) ? $creditSaleRsp->RspText : null);
554
+
555
+ if(isset($header->TokenData) && is_object($header->TokenData)){
556
+ $result->tokenData = new HpsTokenData();
557
+ $result->tokenData->responseCode = $header->TokenData->TokenRspCode;
558
+ $result->tokenData->responseMessage = $header->TokenData->TokenRspMsg;
559
+ $result->tokenData->tokenValue = $header->TokenData->TokenValue;
560
+ }
561
+
562
+ return $result;
563
+ }
564
+
565
+ private function _submitRefund($transaction){
566
+ $response = $this->doTransaction($transaction);
567
+ $header = $response->Header;
568
+
569
+ if($header->GatewayRspCode != "0"){
570
+ throw $this->exceptionMapper->map_gateway_exception($header->GatewayTxnId,$header->GatewayRspCode,$header->GatewayRspMsg);
571
+ }
572
+
573
+ $result = new HpsRefund($this->hydrateTransactionHeader($header));
574
+ $result->transactionId = $header->GatewayTxnId;
575
+ $result->responseCode = "00";
576
+ $result->responseText = "";
577
+
578
+ return $result;
579
+ }
580
+
581
+ private function _submitReverse($transaction){
582
+ $response = $this->doTransaction($transaction);
583
+ $header = $response->Header;
584
+
585
+ if($header->GatewayRspCode != "0"){
586
+ throw $this->exceptionMapper->map_gateway_exception($header->GatewayTxnId,$header->GatewayRspCOde,$header->GatewayRspMsg);
587
+ }
588
+
589
+ $reversal = (isset($response->Transaction->CreditReversal) ? $response->Transaction->CreditReversal : null);
590
+ $result = new HpsReversal($this->hydrateTransactionHeader($header));
591
+ $result->transactionId = (isset($header->GatewayTxnId) ? $header->GatewayTxnId : null);
592
+ $result->avsResultCode = (isset($reversal->AVSRsltCode) ? $reversal->AVSRsltCode : null);
593
+ $result->avsResultText = (isset($reversal->AVSRsltText) ? $reversal->AVSRsltText : null);
594
+ $result->cpcIndicator = (isset($reversal->CPCInd) ? $reversal->CPCInd : null);
595
+ $result->cvvResultCode = (isset($reversal->CVVRsltCode) ? $reversal->CVVRsltCode : null);
596
+ $result->cvvResultText = (isset($reversal->CVVRsltText) ? $reversal->CVVRsltText : null);
597
+ $result->referenceNumber = (isset($reversal->RefNbr) ? $reversal->RefNbr : null);
598
+ $result->responseCode = (isset($reversal->RspCode) ? $reversal->RspCode : null);
599
+ $result->responseText = (isset($reversal->RspText) ? $reversal->RspText : null);
600
+ return $result;
601
+ }
602
+ }
lib/SecureSubmit/services/HpsService.php ADDED
@@ -0,0 +1,129 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsService {
4
+ public $exceptionMapper = null,
5
+ $config = null;
6
+
7
+ public function __construct(HpsConfiguration $config=null){
8
+ if($config != null){
9
+ $this->config = $config;
10
+ }
11
+ $this->exceptionMapper = new HpsExceptionMapper();
12
+ }
13
+
14
+ public function doTransaction($transaction){
15
+ if($this->_configurationInvalid()){
16
+ throw $this->exceptionMapper->map_sdk_exception(HpsSdkCodes::$invalidTransactionId);
17
+ }
18
+
19
+ $xml = new DOMDocument('1.0', 'utf-8');
20
+ $soapEnvelope = $xml->createElement('soapenv:Envelope');
21
+ $soapEnvelope->setAttribute('xmlns:soapenv', 'http://schemas.xmlsoap.org/soap/envelope/');
22
+ $soapEnvelope->setAttribute('xmlns:hps', 'http://Hps.Exchange.PosGateway');
23
+
24
+ $soapBody = $xml->createElement('soapenv:Body');
25
+ $hpsRequest = $xml->createElement('hps:PosRequest');
26
+ $hpsVersion = $xml->createElement('hps:Ver1.0');
27
+ $hpsHeader = $xml->createElement('hps:Header');
28
+
29
+ if ($this->config->secretApiKey != NULL && $this->config->secretApiKey != ""){
30
+ $hpsHeader->appendChild($xml->createElement('hps:SecretAPIKey',$this->config->secretApiKey));
31
+ }else{
32
+ $hpsHeader->appendChild($xml->createElement('hps:UserName',$this->config->userName));
33
+ $hpsHeader->appendChild($xml->createElement('hps:Password',$this->config->password));
34
+ $hpsHeader->appendChild($xml->createElement('hps:DeviceId',$this->config->deviceId));
35
+ $hpsHeader->appendChild($xml->createElement('hps:LicenseId',$this->config->licenseId));
36
+ $hpsHeader->appendChild($xml->createElement('hps:SiteId',$this->config->siteId));
37
+ }
38
+ if ($this->config->developerId != null && $this->config->developerId != ""){
39
+ $hpsHeader->appendChild($xml->createElement('hps:DeveloperID',$this->config->developerId));
40
+ $hpsHeader->appendChild($xml->createElement('hps:VersionNbr',$this->config->versionNumber));
41
+ $hpsHeader->appendChild($xml->createElement('hps:SiteTrace',$this->config->siteTrace));
42
+ }
43
+
44
+ $hpsVersion->appendChild($hpsHeader);
45
+ $transaction = $xml->importNode($transaction,true);
46
+ $hpsVersion->appendChild($transaction);
47
+ $hpsRequest->appendChild($hpsVersion);
48
+ $soapBody->appendChild($hpsRequest);
49
+ $soapEnvelope->appendChild($soapBody);
50
+ $xml->appendChild($soapEnvelope);
51
+
52
+ //cURL
53
+ try{
54
+ $header = array(
55
+ "Content-type: text/xml;charset=\"utf-8\"",
56
+ "Accept: text/xml",
57
+ "SOAPAction: \"\"",
58
+ "Content-length: ".strlen($xml->saveXML()),
59
+ );
60
+ $soap_do = curl_init();
61
+ curl_setopt($soap_do, CURLOPT_URL, $this->_gatewayUrlForKey($this->config->secretApiKey));
62
+ curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 10);
63
+ curl_setopt($soap_do, CURLOPT_TIMEOUT, 10);
64
+ curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
65
+ curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);
66
+ curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false);
67
+ curl_setopt($soap_do, CURLOPT_POST, true);
68
+ curl_setopt($soap_do, CURLOPT_POSTFIELDS, $xml->saveXML());
69
+ curl_setopt($soap_do, CURLOPT_HTTPHEADER, $header);
70
+
71
+ if($this->config->useProxy){
72
+ curl_setopt($soap_do, CURLOPT_PROXY, $this->config->proxyOptions['proxy_host']);
73
+ curl_setopt($soap_do, CURLOPT_PROXYPORT, $this->config->proxyOptions['proxy_port']);
74
+ }
75
+ $curlResponse = curl_exec($soap_do);
76
+ $curlInfo = curl_getinfo($soap_do);
77
+
78
+ if($curlInfo['http_code'] == '200'){
79
+ $responseObject = $this->_XML2Array($curlResponse);
80
+ $ver = "Ver1.0";
81
+ return $responseObject->$ver;
82
+ }else{
83
+ throw $this->exceptionMapper->map_sdk_exception(HpsSdkCodes::$unableToProcessTransaction);
84
+ }
85
+ }catch (Exception $e){
86
+ throw $this->exceptionMapper->map_sdk_exception(HpsSdkCodes::$unableToProcessTransaction, $e);
87
+ }
88
+ }
89
+
90
+ private function _configurationInvalid(){
91
+ if($this->config == null && (
92
+ $this->config->secretApiKey == null ||
93
+ $this->config->userName == null ||
94
+ $this->config->password == null ||
95
+ $this->config->licenseId == null ||
96
+ $this->config->deviceId == null ||
97
+ $this->config->siteId == null)
98
+ ){
99
+ return true;
100
+ }
101
+ return false;
102
+ }
103
+
104
+ private function _gatewayUrlForKey($apiKey){
105
+ if ($apiKey != NULL && $apiKey != "" && strpos($apiKey, '_cert_') !== false){
106
+ return "https://posgateway.cert.secureexchange.net/Hps.Exchange.PosGateway/PosGatewayService.asmx";
107
+ }else{
108
+ return "https://posgateway.secureexchange.net/Hps.Exchange.PosGateway/PosGatewayService.asmx";
109
+ }
110
+ }
111
+
112
+ public function hydrateTransactionHeader($header){
113
+ $result = new HpsTransactionHeader();
114
+ $result->gatewayResponseCode = $header['GatewayRspCode'];
115
+ $result->gatewayResponseMessage = $header['GatewayRspMsg'];
116
+ $result->responseDt = $header['RspDT'];
117
+ $result->clientTxnId = $header['GatewayTxnId'];
118
+ return $result;
119
+ }
120
+
121
+ private function _XML2Array($xml){
122
+ $envelope = simplexml_load_string($xml, "SimpleXMLElement", 0,'http://schemas.xmlsoap.org/soap/envelope/');
123
+ foreach($envelope->Body as $response) {
124
+ foreach ($response->children('http://Hps.Exchange.PosGateway') as $item) {
125
+ return $item;
126
+ }
127
+ }
128
+ }
129
+ }
lib/SecureSubmit/services/HpsTokenService.php ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ // This should only be used for testing tokens.
3
+
4
+ class HpsTokenService {
5
+ private $_publicAPIKey = null;
6
+ private $_url = null;
7
+
8
+ function __construct($publicAPIKey){
9
+ $this->_publicAPIKey = $publicAPIKey;
10
+
11
+ if($publicAPIKey == null || $publicAPIKey == ""){
12
+ throw new HpsException("Public Key not found","0");
13
+ }
14
+
15
+ $components = explode("_",$publicAPIKey);
16
+ if(count($components) != 3){
17
+ throw new HpsException("Public API Key must Contain three underscores","0");
18
+ }
19
+
20
+ if(strtolower($components[1]) == "prod"){
21
+ $this->_url = "https://api.heartlandportico.com/SecureSubmit.v1/api/token";
22
+ }else {
23
+ $this->_url = "https://posgateway.cert.secureexchange.net/Hps.Exchange.PosGateway.Hpf.v1/api/token";
24
+ }
25
+ }
26
+
27
+ function getToken(HpsCreditCard $cardData){
28
+ try{
29
+ $data['api_key'] = $this->_publicAPIKey;
30
+ $data['object'] = 'token';
31
+ $data['token_type'] = 'supt';
32
+ $data['_method'] = 'post';
33
+ $data['card[number]'] = $cardData->number;
34
+ $data['card[cvc]'] = $cardData->cvv;
35
+ $data['card[exp_month]'] = $cardData->expMonth;
36
+ $data['card[exp_year]'] = $cardData->expYear;
37
+
38
+ $header = array('Content-type: application/json');
39
+
40
+ $tokenFetch = curl_init();
41
+ curl_setopt($tokenFetch, CURLOPT_URL, $this->_url ."?". http_build_query($data));
42
+ curl_setopt($tokenFetch, CURLOPT_CONNECTTIMEOUT, 10);
43
+ curl_setopt($tokenFetch, CURLOPT_TIMEOUT, 10);
44
+ curl_setopt($tokenFetch, CURLOPT_RETURNTRANSFER, true );
45
+ curl_setopt($tokenFetch, CURLOPT_SSL_VERIFYPEER, false);
46
+ curl_setopt($tokenFetch, CURLOPT_SSL_VERIFYHOST, false);
47
+ curl_setopt($tokenFetch, CURLOPT_HTTPHEADER, $header);
48
+ $curlResponse = curl_exec($tokenFetch);
49
+
50
+ $response = json_decode($curlResponse);
51
+ if(isset($response->error) && is_object($response->error)){
52
+ throw new HpsException($response->error->message,$response->error->code);
53
+ }
54
+ return $response;
55
+ }catch (Exception $e){
56
+ throw new HpsException($e->getMessage(),$e->getCode());
57
+ }
58
+ }
59
+ }
package.xml ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Hps_Securesubmit</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="https://github.com/SecureSubmit/magento-extension/blob/master/LICENSE">Custom</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Take credit card payments and store cards in a PCI friendly way.</summary>
10
+ <description>Use Heartland Payment Systems SecureSubmit platform to charge, authorize, void, refund and partial refund credit cards.&#xD;
11
+ &#xD;
12
+ Allow customers to store their cards for reduced friction at next checkout using our multi-use card tokenization process which helps reduce PCI scope.</description>
13
+ <notes>This extension has been in production for six months with many websites. Many cross-platform (Windows vs. Linux) bugs were fixed during this process and the module has proved stable.</notes>
14
+ <authors><author><name>Heartland Payment Systems</name><user>markhagan</user><email>mark.hagan@e-hps.com</email></author></authors>
15
+ <date>2014-03-20</date>
16
+ <time>13:29:30</time>
17
+ <contents><target name="magecommunity"><dir name="Hps"><dir name="Securesubmit"><dir name="Block"><file name="Form.php" hash="2fbc3cb4093c7790992c7091108e8af4"/><file name="Info.php" hash="4a7685fe8e068f7a0621e896c182cb5c"/></dir><dir name="Helper"><file name="Data.php" hash="04aeff6f94f56a49cf7527518c6212a1"/></dir><dir name="Model"><file name="Payment.php" hash="8639797c0fab1bfe57fa3571ef5e3434"/><dir name="Resource"><file name="Setup.php" hash="f568cb09a6a06fc3d52f145684997416"/><dir name="Storedcard"><file name="Collection.php" hash="021134d46837197e800f54a4b90b0048"/></dir><file name="Storedcard.php" hash="f2a993c8e4236bc03b1273a33a03b5d0"/></dir><dir name="Source"><file name="Cctype.php" hash="b5f75e4a3284f79b2cfab926b193c98b"/><file name="PaymentAction.php" hash="9fc55ebaaeaccba6c40597d25a1cf9d3"/></dir><file name="Storedcard.php" hash="82c7228d2182a0cba979dc4c66a2321c"/><dir name="System"><dir name="Config"><dir name="Backend"><file name="Proxy.php" hash="97028069630bddf2b94cb1b5b0886076"/></dir></dir></dir></dir><dir name="controllers"><file name="StoredcardController.php" hash="cb9e5f7de4f52fd7a764a87f0f4699a8"/></dir><dir name="etc"><file name="config.xml" hash="99eeaf1f8ef190601b9554116fb3eee4"/><file name="system.xml" hash="27da99752da25df0cd2186c45261912c"/></dir><dir name="sql"><dir name="hps_securesubmit_setup"><file name="install-1.0.0.php" hash="57917d8b3b29830eb1a219466df4555b"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="securesubmit"><file name="form.phtml" hash="beef4bae4a8c5d1040d1afc9800f0a9e"/></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="securesubmit.xml" hash="28339d8a8907f0e319fd371d73f211df"/></dir><dir name="template"><dir name="securesubmit"><file name="form.phtml" hash="603c3e7807c55e340a3a730fc259b3de"/><file name="storedcards.phtml" hash="3412f0560d4ba696dc9bc3ed996e0577"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Hps_Securesubmit.xml" hash="d5aed3f48a45f8e611b68d1e6f34c959"/></dir></target><target name="mage"><dir name="js"><dir name="securesubmit"><file name="secure.submit-1.0.1.js" hash="a149dc8efcfa3b507d6b2b3c784d9db3"/></dir></dir></target><target name="magelib"><dir name="SecureSubmit"><file name="Hps.php" hash="8855d261c2df0de3fe7ad8e6e59668ad"/><dir name="entities"><file name="HpsAccountVerify.php" hash="a910342548320ba07ebc4c9cda2f7c96"/><file name="HpsAddress.php" hash="2e4554c509e1de8e8cb6b0d1f599d657"/><file name="HpsAuthorization.php" hash="c46f0ad9033d3197e641c1b63bd90c7e"/><file name="HpsBatch.php" hash="46ee0321f3c9f3824fdb930736c8df7e"/><file name="HpsCardHolder.php" hash="f74938b2f53d703c777def01adde5e91"/><file name="HpsCharge.php" hash="5e94b3094db8e4f231a456cedce40985"/><file name="HpsChargeExceptions.php" hash="927b346fdac882cf97fd46b5e740e363"/><file name="HpsCreditCard.php" hash="9394bb9cd123d572d2f3376f3ce52594"/><file name="HpsItemChoiceTypePosResponseVer10Transaction.php" hash="3516bf8acb77af8d4a36d02ed991d09e"/><file name="HpsRefund.php" hash="05a8dae7c7e0faf1e67ae628eca75ea2"/><file name="HpsReportTransactionDetails.php" hash="ad0221581bf4ee24410c1ed4aac4d305"/><file name="HpsReportTransactionSummary.php" hash="1d46cce9a3274f25c092171e034479bc"/><file name="HpsReversal.php" hash="1ffd02ea88816b9a7ef5579d6219d6b8"/><file name="HpsTokenData.php" hash="bfc42e3ed9ff078598d694565d7fd3be"/><file name="HpsTransaction.php" hash="fd2bb80e28f9143bb25a3df1508fb927"/><file name="HpsTransactionDetails.php" hash="ded777de86d2b93882b2779283247b64"/><file name="HpsTransactionHeader.php" hash="114de2d7b3648143d0ef16588dfbc1af"/><file name="HpsTransactionType.php" hash="58a73f5915ff2d3f9d89935232e90796"/><file name="HpsVoid.php" hash="09902616437fd001ec17cde2b6dd9780"/></dir><dir name="infrastructure"><file name="AVSResponseCodeHandler.php" hash="b376458f6bbf14907fd96b6b17566861"/><file name="ApiConnectionException.php" hash="8b6e2d5e4d7e3368adb34e1ab20412b0"/><file name="AuthenticationException.php" hash="4685a4fa0209ed56ef0ee38868f52840"/><file name="CardException.php" hash="09bf8965e0e101dcaf560c0927812306"/><file name="Exceptions.json" hash="8f7cbcb2b18963603ee3a62d6888c36d"/><file name="HpsConfiguration.php" hash="48ed3ba9eed035d5e57d245f5174b5bc"/><file name="HpsException.php" hash="89899dd8d9351d5fd4d198c0560864d4"/><file name="HpsExceptionMapper.php" hash="5f81eacdaea3ccb756a89b04ec4c20d6"/><file name="HpsSdkCodes.php" hash="b827c7268a5743a5fd45e992eeab2450"/><file name="InvalidRequestException.php" hash="a01ca17d036ce2e6410647aa1bd25491"/></dir><dir name="services"><file name="HpsBatchService.php" hash="8e46d58de558258c8af585c0a646b9ea"/><file name="HpsChargeService.php" hash="e1474cade11a45ccf450e182094e0e35"/><file name="HpsService.php" hash="52aefe6d72b1e4118fdd8ec04b75e28c"/><file name="HpsTokenService.php" hash="bfdee5e18ebdc2133f3512040e0da766"/></dir></dir></target></contents>
18
+ <compatible/>
19
+ <dependencies><required><php><min>5.2.0</min><max>5.5.10</max></php></required></dependencies>
20
+ </package>