Hps_Securesubmit - Version 1.0.7

Version Notes

Allows for newer versions of PHP to install the extension through Magento Connect

Download this release

Release Info

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


Code changes from version 1.0.6 to 1.0.7

Files changed (205) hide show
  1. app/code/community/Hps/Securesubmit/Block/Adminhtml/Form.php +46 -0
  2. app/code/community/Hps/Securesubmit/Block/Adminhtml/Paypal/Settlement/Report.php +53 -0
  3. app/code/community/Hps/Securesubmit/Block/Adminhtml/Paypal/Settlement/Report/Grid.php +93 -0
  4. app/code/community/Hps/Securesubmit/Block/Paypal/Credit/Form.php +41 -0
  5. app/code/community/Hps/Securesubmit/Block/Paypal/Form.php +58 -0
  6. app/code/community/Hps/Securesubmit/Block/Paypal/Info.php +21 -0
  7. app/code/community/Hps/Securesubmit/Block/Paypal/Review.php +218 -0
  8. app/code/community/Hps/Securesubmit/Block/Paypal/Review/Billing.php +37 -0
  9. app/code/community/Hps/Securesubmit/Block/Paypal/Review/Details.php +38 -0
  10. app/code/community/Hps/Securesubmit/Block/Paypal/Review/Shipping.php +31 -0
  11. app/code/community/Hps/Securesubmit/Block/Paypal/Shortcut.php +183 -0
  12. app/code/community/Hps/Securesubmit/Controller/Paypal/Abstract.php +516 -0
  13. app/code/community/Hps/Securesubmit/Model/Api/Abstract.php +581 -0
  14. app/code/community/Hps/Securesubmit/Model/Api/Paypal.php +300 -0
  15. app/code/community/Hps/Securesubmit/Model/Config.php +1571 -0
  16. app/code/community/Hps/Securesubmit/Model/Paypal.php +415 -0
  17. app/code/community/Hps/Securesubmit/Model/Paypal/Cart.php +506 -0
  18. app/code/community/Hps/Securesubmit/Model/Paypal/Checkout.php +1036 -0
  19. app/code/community/Hps/Securesubmit/Model/Paypal/Credit.php +37 -0
  20. app/code/community/Hps/Securesubmit/Model/Report.php +17 -0
  21. app/code/community/Hps/Securesubmit/Model/Resource/Report.php +9 -0
  22. app/code/community/Hps/Securesubmit/Model/Resource/Report/Collection.php +15 -0
  23. app/code/community/Hps/Securesubmit/Model/Session.php +22 -0
  24. app/code/community/Hps/Securesubmit/controllers/Adminhtml/Hps/.DS_Store +0 -0
  25. app/code/community/Hps/Securesubmit/controllers/Adminhtml/Hps/._.DS_Store +0 -0
  26. app/code/community/Hps/Securesubmit/controllers/Adminhtml/Hps/Paypal/ReportsController.php +18 -0
  27. app/code/community/Hps/Securesubmit/controllers/PaypalController.php +45 -0
  28. app/code/community/Hps/Securesubmit/etc/adminhtml.xml +61 -0
  29. app/code/community/Hps/Securesubmit/sql/hps_securesubmit_setup/mysql4-upgrade-1.0.0-1.0.1.php +13 -0
  30. app/code/community/Hps/Securesubmit/sql/hps_securesubmit_setup/mysql4-upgrade-1.0.1-1.1.0.php +24 -0
  31. app/design/frontend/base/default/template/securesubmit/.DS_Store +0 -0
  32. app/design/frontend/base/default/template/securesubmit/paypal/review.phtml +177 -0
  33. app/design/frontend/base/default/template/securesubmit/paypal/review/details.phtml +64 -0
  34. app/design/frontend/base/default/template/securesubmit/paypal/review/shipping/method.phtml +53 -0
  35. app/design/frontend/base/default/template/securesubmit/paypal/shortcut.phtml +80 -0
  36. js/securesubmit/checkout-form.js +233 -0
  37. lib/SecureSubmit/.DS_Store +0 -0
  38. lib/SecureSubmit/LICENSE.txt +32 -0
  39. lib/SecureSubmit/PRIVACY.txt +66 -0
  40. lib/SecureSubmit/README.md +684 -0
  41. lib/SecureSubmit/index.php +1 -0
  42. lib/SecureSubmit/src/Abstractions/HpsBuilderAbstract.php +168 -0
  43. lib/SecureSubmit/src/Abstractions/HpsGatewayServiceAbstract.php +109 -0
  44. lib/SecureSubmit/src/Abstractions/HpsPayPlanResourceAbstract.php +27 -0
  45. lib/SecureSubmit/src/Abstractions/HpsPayPlanResourceInterface.php +7 -0
  46. lib/SecureSubmit/src/Entities/AltPayment/HpsAltPaymentAddToBatch.php +19 -0
  47. lib/SecureSubmit/src/Entities/AltPayment/HpsAltPaymentAuth.php +19 -0
  48. lib/SecureSubmit/src/Entities/AltPayment/HpsAltPaymentCreateSession.php +31 -0
  49. lib/SecureSubmit/src/Entities/AltPayment/HpsAltPaymentReturn.php +5 -0
  50. lib/SecureSubmit/src/Entities/AltPayment/HpsAltPaymentSale.php +19 -0
  51. lib/SecureSubmit/src/Entities/AltPayment/HpsAltPaymentSessionInfo.php +72 -0
  52. lib/SecureSubmit/src/Entities/AltPayment/HpsAltPaymentVoid.php +5 -0
  53. lib/SecureSubmit/src/Entities/AltPayment/HpsBuyerData.php +31 -0
  54. lib/SecureSubmit/src/Entities/AltPayment/HpsLineItem.php +11 -0
  55. lib/SecureSubmit/src/Entities/AltPayment/HpsPaymentData.php +19 -0
  56. lib/SecureSubmit/src/Entities/AltPayment/HpsShippingInfo.php +10 -0
  57. lib/SecureSubmit/src/Entities/Batch/HpsBatch.php +9 -0
  58. lib/SecureSubmit/src/Entities/Check/HpsCheck.php +45 -0
  59. lib/SecureSubmit/src/Entities/Check/HpsCheckHolder.php +11 -0
  60. lib/SecureSubmit/src/Entities/Check/HpsCheckResponse.php +44 -0
  61. lib/SecureSubmit/src/Entities/Check/HpsCheckResponseDetails.php +10 -0
  62. lib/SecureSubmit/src/Entities/Credit/HpsAccountVerify.php +5 -0
  63. lib/SecureSubmit/src/Entities/Credit/HpsAuthorization.php +42 -0
  64. lib/SecureSubmit/src/Entities/Credit/HpsCPCData.php +8 -0
  65. lib/SecureSubmit/src/Entities/Credit/HpsCPCEdit.php +12 -0
  66. lib/SecureSubmit/src/Entities/Credit/HpsCardHolder.php +5 -0
  67. lib/SecureSubmit/src/Entities/Credit/HpsCharge.php +5 -0
  68. lib/SecureSubmit/src/Entities/Credit/HpsChargeExceptions.php +7 -0
  69. lib/SecureSubmit/src/Entities/Credit/HpsCreditCard.php +28 -0
  70. lib/SecureSubmit/src/Entities/Credit/HpsRecurringBilling.php +5 -0
  71. lib/SecureSubmit/src/Entities/Credit/HpsRefund.php +12 -0
  72. lib/SecureSubmit/src/Entities/Credit/HpsReportTransactionDetails.php +65 -0
  73. lib/SecureSubmit/src/Entities/Credit/HpsReportTransactionSummary.php +71 -0
  74. lib/SecureSubmit/src/Entities/Credit/HpsReversal.php +24 -0
  75. lib/SecureSubmit/src/Entities/Credit/HpsVoid.php +12 -0
  76. lib/SecureSubmit/src/Entities/Debit/HpsDebitAddValue.php +5 -0
  77. lib/SecureSubmit/src/Entities/Debit/HpsDebitReturn.php +5 -0
  78. lib/SecureSubmit/src/Entities/Debit/HpsDebitReversal.php +5 -0
  79. lib/SecureSubmit/src/Entities/Debit/HpsDebitSale.php +5 -0
  80. lib/SecureSubmit/src/Entities/Fluent/HpsBuilderAction.php +19 -0
  81. lib/SecureSubmit/src/Entities/Fluent/HpsUnknownPropertyException.php +27 -0
  82. lib/SecureSubmit/src/Entities/Gift/HpsEncryptionData.php +30 -0
  83. lib/SecureSubmit/src/Entities/Gift/HpsGiftCard.php +15 -0
  84. lib/SecureSubmit/src/Entities/Gift/HpsGiftCardActivate.php +47 -0
  85. lib/SecureSubmit/src/Entities/Gift/HpsGiftCardAddValue.php +5 -0
  86. lib/SecureSubmit/src/Entities/Gift/HpsGiftCardAlias.php +23 -0
  87. lib/SecureSubmit/src/Entities/Gift/HpsGiftCardBalance.php +5 -0
  88. lib/SecureSubmit/src/Entities/Gift/HpsGiftCardDeactivate.php +5 -0
  89. lib/SecureSubmit/src/Entities/Gift/HpsGiftCardReplace.php +5 -0
  90. lib/SecureSubmit/src/Entities/Gift/HpsGiftCardReversal.php +5 -0
  91. lib/SecureSubmit/src/Entities/Gift/HpsGiftCardReward.php +5 -0
  92. lib/SecureSubmit/src/Entities/Gift/HpsGiftCardSale.php +18 -0
  93. lib/SecureSubmit/src/Entities/Gift/HpsGiftCardVoid.php +5 -0
  94. lib/SecureSubmit/src/Entities/HpsAddress.php +10 -0
  95. lib/SecureSubmit/src/Entities/HpsConsumer.php +10 -0
  96. lib/SecureSubmit/src/Entities/HpsDirectMarketData.php +15 -0
  97. lib/SecureSubmit/src/Entities/HpsTokenData.php +13 -0
  98. lib/SecureSubmit/src/Entities/HpsTransaction.php +125 -0
  99. lib/SecureSubmit/src/Entities/HpsTransactionDetails.php +9 -0
  100. lib/SecureSubmit/src/Entities/HpsTransactionHeader.php +9 -0
  101. lib/SecureSubmit/src/Entities/PayPlan/HpsPayPlanCustomer.php +164 -0
  102. lib/SecureSubmit/src/Entities/PayPlan/HpsPayPlanPaymentMethod.php +214 -0
  103. lib/SecureSubmit/src/Entities/PayPlan/HpsPayPlanSchedule.php +178 -0
  104. lib/SecureSubmit/src/Entities/index.php +1 -0
  105. lib/SecureSubmit/src/Infrastructure/Enums/HpsACHType.php +5 -0
  106. lib/SecureSubmit/src/Infrastructure/Enums/HpsAccountType.php +7 -0
  107. lib/SecureSubmit/src/Infrastructure/Enums/HpsCardBrand.php +9 -0
  108. lib/SecureSubmit/src/Infrastructure/Enums/HpsCheckType.php +7 -0
  109. lib/SecureSubmit/src/Infrastructure/Enums/HpsDataEntryMode.php +7 -0
  110. lib/SecureSubmit/src/Infrastructure/Enums/HpsExceptionCodes.php +40 -0
  111. lib/SecureSubmit/src/Infrastructure/Enums/HpsGiftCardAliasAction.php +8 -0
  112. lib/SecureSubmit/src/Infrastructure/Enums/HpsItemChoiceTypePosResponseVer10Transaction.php +64 -0
  113. lib/SecureSubmit/src/Infrastructure/Enums/HpsPayPlanAccountType.php +7 -0
  114. lib/SecureSubmit/src/Infrastructure/Enums/HpsPayPlanCustomerStatus.php +7 -0
  115. lib/SecureSubmit/src/Infrastructure/Enums/HpsPayPlanPaymentMethodStatus.php +9 -0
  116. lib/SecureSubmit/src/Infrastructure/Enums/HpsPayPlanPaymentMethodType.php +7 -0
  117. lib/SecureSubmit/src/Infrastructure/Enums/HpsPayPlanScheduleDuration.php +8 -0
  118. lib/SecureSubmit/src/Infrastructure/Enums/HpsPayPlanScheduleFrequency.php +12 -0
  119. lib/SecureSubmit/src/Infrastructure/Enums/HpsPayPlanScheduleStatus.php +6 -0
  120. lib/SecureSubmit/src/Infrastructure/Enums/HpsSECCode.php +11 -0
  121. lib/SecureSubmit/src/Infrastructure/Enums/HpsTaxType.php +8 -0
  122. lib/SecureSubmit/src/Infrastructure/Enums/HpsTransactionType.php +16 -0
  123. lib/SecureSubmit/src/Infrastructure/HpsApiConnectionException.php +9 -0
  124. lib/SecureSubmit/src/Infrastructure/HpsArgumentException.php +9 -0
  125. lib/SecureSubmit/src/Infrastructure/HpsAuthenticationException.php +10 -0
  126. lib/SecureSubmit/src/Infrastructure/HpsCheckException.php +16 -0
  127. lib/SecureSubmit/src/Infrastructure/HpsConfiguration.php +18 -0
  128. lib/SecureSubmit/src/Infrastructure/HpsCreditException.php +21 -0
  129. lib/SecureSubmit/src/Infrastructure/HpsCreditExceptionDetails.php +7 -0
  130. lib/SecureSubmit/src/Infrastructure/HpsException.php +18 -0
  131. lib/SecureSubmit/src/Infrastructure/HpsGatewayException.php +21 -0
  132. lib/SecureSubmit/src/Infrastructure/HpsGatewayExceptionDetails.php +7 -0
  133. lib/SecureSubmit/src/Infrastructure/HpsInvalidRequestException.php +15 -0
  134. lib/SecureSubmit/src/Infrastructure/HpsProcessorException.php +21 -0
  135. lib/SecureSubmit/src/Infrastructure/HpsProcessorExceptionDetails.php +7 -0
  136. lib/SecureSubmit/src/Infrastructure/Validation/HpsGatewayResponseValidation.php +97 -0
  137. lib/SecureSubmit/src/Infrastructure/Validation/HpsInputValidation.php +63 -0
  138. lib/SecureSubmit/src/Infrastructure/Validation/HpsIssuerResponseValidation.php +100 -0
  139. lib/SecureSubmit/src/Infrastructure/Validation/HpsProcessorResponseValidation.php +41 -0
  140. lib/SecureSubmit/src/Infrastructure/index.php +1 -0
  141. lib/SecureSubmit/src/Services/Fluent/Gateway/Check/HpsCheckServiceOverrideBuilder.php +83 -0
  142. lib/SecureSubmit/src/Services/Fluent/Gateway/Check/HpsCheckServiceReturnBuilder.php +83 -0
  143. lib/SecureSubmit/src/Services/Fluent/Gateway/Check/HpsCheckServiceSaleBuilder.php +83 -0
  144. lib/SecureSubmit/src/Services/Fluent/Gateway/Check/HpsCheckServiceVoidBuilder.php +72 -0
  145. lib/SecureSubmit/src/Services/Fluent/Gateway/Credit/HpsCreditServiceAuthorizeBuilder.php +137 -0
  146. lib/SecureSubmit/src/Services/Fluent/Gateway/Credit/HpsCreditServiceCaptureBuilder.php +80 -0
  147. lib/SecureSubmit/src/Services/Fluent/Gateway/Credit/HpsCreditServiceChargeBuilder.php +142 -0
  148. lib/SecureSubmit/src/Services/Fluent/Gateway/Credit/HpsCreditServiceCpcEditBuilder.php +78 -0
  149. lib/SecureSubmit/src/Services/Fluent/Gateway/Credit/HpsCreditServiceEditBuilder.php +75 -0
  150. lib/SecureSubmit/src/Services/Fluent/Gateway/Credit/HpsCreditServiceGetBuilder.php +58 -0
  151. lib/SecureSubmit/src/Services/Fluent/Gateway/Credit/HpsCreditServiceListTransactionsBuilder.php +84 -0
  152. lib/SecureSubmit/src/Services/Fluent/Gateway/Credit/HpsCreditServiceRefundBuilder.php +130 -0
  153. lib/SecureSubmit/src/Services/Fluent/Gateway/Credit/HpsCreditServiceReverseBuilder.php +125 -0
  154. lib/SecureSubmit/src/Services/Fluent/Gateway/Credit/HpsCreditServiceVerifyBuilder.php +86 -0
  155. lib/SecureSubmit/src/Services/Fluent/Gateway/Credit/HpsCreditServiceVoidBuilder.php +62 -0
  156. lib/SecureSubmit/src/Services/Fluent/Gateway/Debit/HpsDebitServiceAddValueBuilder.php +139 -0
  157. lib/SecureSubmit/src/Services/Fluent/Gateway/Debit/HpsDebitServiceChargeBuilder.php +149 -0
  158. lib/SecureSubmit/src/Services/Fluent/Gateway/Debit/HpsDebitServiceReturnBuilder.php +139 -0
  159. lib/SecureSubmit/src/Services/Fluent/Gateway/Debit/HpsDebitServiceReverseBuilder.php +116 -0
  160. lib/SecureSubmit/src/Services/Fluent/Gateway/GiftCard/HpsGiftCardServiceActivateBuilder.php +96 -0
  161. lib/SecureSubmit/src/Services/Fluent/Gateway/GiftCard/HpsGiftCardServiceAddValueBuilder.php +96 -0
  162. lib/SecureSubmit/src/Services/Fluent/Gateway/GiftCard/HpsGiftCardServiceAliasBuilder.php +96 -0
  163. lib/SecureSubmit/src/Services/Fluent/Gateway/GiftCard/HpsGiftCardServiceBalanceBuilder.php +60 -0
  164. lib/SecureSubmit/src/Services/Fluent/Gateway/GiftCard/HpsGiftCardServiceDeactivateBuilder.php +60 -0
  165. lib/SecureSubmit/src/Services/Fluent/Gateway/GiftCard/HpsGiftCardServiceReplaceBuilder.php +78 -0
  166. lib/SecureSubmit/src/Services/Fluent/Gateway/GiftCard/HpsGiftCardServiceReverseBuilder.php +92 -0
  167. lib/SecureSubmit/src/Services/Fluent/Gateway/GiftCard/HpsGiftCardServiceRewardBuilder.php +93 -0
  168. lib/SecureSubmit/src/Services/Fluent/Gateway/GiftCard/HpsGiftCardServiceSaleBuilder.php +106 -0
  169. lib/SecureSubmit/src/Services/Fluent/Gateway/GiftCard/HpsGiftCardServiceVoidBuilder.php +60 -0
  170. lib/SecureSubmit/src/Services/Fluent/Gateway/HpsFluentCheckService.php +43 -0
  171. lib/SecureSubmit/src/Services/Fluent/Gateway/HpsFluentCreditService.php +88 -0
  172. lib/SecureSubmit/src/Services/Fluent/Gateway/HpsFluentDebitService.php +43 -0
  173. lib/SecureSubmit/src/Services/Fluent/Gateway/HpsFluentGiftCardService.php +84 -0
  174. lib/SecureSubmit/src/Services/Fluent/Gateway/PayPlan/HpsPayPlanCustomerServiceAddBuilder.php +76 -0
  175. lib/SecureSubmit/src/Services/Fluent/Gateway/PayPlan/HpsPayPlanCustomerServiceDeleteBuilder.php +76 -0
  176. lib/SecureSubmit/src/Services/Fluent/Gateway/PayPlan/HpsPayPlanCustomerServiceEditBuilder.php +122 -0
  177. lib/SecureSubmit/src/Services/Fluent/Gateway/PayPlan/HpsPayPlanCustomerServiceGetBuilder.php +76 -0
  178. lib/SecureSubmit/src/Services/Fluent/Gateway/PayPlan/HpsPayPlanCustomerServiceSearchBuilder.php +83 -0
  179. lib/SecureSubmit/src/Services/Fluent/Gateway/PayPlan/HpsPayPlanPaymentMethodServiceAddBuilder.php +75 -0
  180. lib/SecureSubmit/src/Services/Fluent/Gateway/PayPlan/HpsPayPlanPaymentMethodServiceDeleteBuilder.php +76 -0
  181. lib/SecureSubmit/src/Services/Fluent/Gateway/PayPlan/HpsPayPlanPaymentMethodServiceEditBuilder.php +122 -0
  182. lib/SecureSubmit/src/Services/Fluent/Gateway/PayPlan/HpsPayPlanPaymentMethodServiceGetBuilder.php +76 -0
  183. lib/SecureSubmit/src/Services/Fluent/Gateway/PayPlan/HpsPayPlanPaymentMethodServiceSearchBuilder.php +83 -0
  184. lib/SecureSubmit/src/Services/Fluent/Gateway/PayPlan/HpsPayPlanScheduleServiceAddBuilder.php +75 -0
  185. lib/SecureSubmit/src/Services/Fluent/Gateway/PayPlan/HpsPayPlanScheduleServiceDeleteBuilder.php +76 -0
  186. lib/SecureSubmit/src/Services/Fluent/Gateway/PayPlan/HpsPayPlanScheduleServiceEditBuilder.php +122 -0
  187. lib/SecureSubmit/src/Services/Fluent/Gateway/PayPlan/HpsPayPlanScheduleServiceGetBuilder.php +76 -0
  188. lib/SecureSubmit/src/Services/Fluent/Gateway/PayPlan/HpsPayPlanScheduleServiceSearchBuilder.php +83 -0
  189. lib/SecureSubmit/src/Services/Gateway/AltPayment/HpsAltPaymentService.php +341 -0
  190. lib/SecureSubmit/src/Services/Gateway/AltPayment/HpsPayPalService.php +6 -0
  191. lib/SecureSubmit/src/Services/Gateway/HpsBatchService.php +30 -0
  192. lib/SecureSubmit/src/Services/Gateway/HpsCheckService.php +124 -0
  193. lib/SecureSubmit/src/Services/Gateway/HpsCreditService.php +485 -0
  194. lib/SecureSubmit/src/Services/Gateway/HpsDebitService.php +307 -0
  195. lib/SecureSubmit/src/Services/Gateway/HpsGiftCardService.php +272 -0
  196. lib/SecureSubmit/src/Services/Gateway/HpsRestGatewayService.php +123 -0
  197. lib/SecureSubmit/src/Services/Gateway/HpsSoapGatewayService.php +289 -0
  198. lib/SecureSubmit/src/Services/Gateway/HpsTokenService.php +54 -0
  199. lib/SecureSubmit/src/Services/Gateway/PayPlan/HpsPayPlanCustomerService.php +55 -0
  200. lib/SecureSubmit/src/Services/Gateway/PayPlan/HpsPayPlanPaymentMethodService.php +92 -0
  201. lib/SecureSubmit/src/Services/Gateway/PayPlan/HpsPayPlanScheduleService.php +58 -0
  202. lib/SecureSubmit/src/Services/HpsServicesConfig.php +70 -0
  203. lib/SecureSubmit/src/Services/index.php +1 -0
  204. lib/SecureSubmit/src/index.php +1 -0
  205. package.xml +7 -7
app/code/community/Hps/Securesubmit/Block/Adminhtml/Form.php ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Hps_Securesubmit_Block_Adminhtml_Form extends Hps_Securesubmit_Block_Form
3
+ {
4
+ /**
5
+ * Retrieve stored cards for the customer
6
+ *
7
+ * @return Hps_Securesubmit_Model_Storedcard[]|Hps_Securesubmit_Model_Resource_Storedcard_Collection
8
+ */
9
+ public function getCustomerStoredCards()
10
+ {
11
+ if ( ! Mage::app()->getStore()->isAdmin()) {
12
+ return array();
13
+ }
14
+ if ( ! Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/use_saved_card')) {
15
+ return array();
16
+ }
17
+ if ( ! $customerId = Mage::getSingleton('adminhtml/session_quote')->getCustomerId()) {
18
+ return array();
19
+ }
20
+ return Mage::helper('hps_securesubmit')->getStoredCards($customerId);
21
+ }
22
+
23
+ /**
24
+ * Retrieve customer stored credit cards JavaScript config
25
+ *
26
+ * @return array
27
+ */
28
+ public function getJsConfig()
29
+ {
30
+ $config = array();
31
+ $collection = $this->getCustomerStoredCards();
32
+ if (count($collection) === 0) {
33
+ return $config;
34
+ }
35
+
36
+ foreach ($collection as $card) { /** @var $card Hps_Securesubmit_Model_Storedcard */
37
+ $config[$card->getId()] = array(
38
+ 'cc_exp_month' => $card->getCcExpMonth(),
39
+ 'cc_exp_year' => $card->getCcExpYear(),
40
+ 'token_value' => $card->getTokenValue(),
41
+ 'cc_last_four' => $card->getCcLast4(),
42
+ );
43
+ }
44
+ return $config;
45
+ }
46
+ }
app/code/community/Hps/Securesubmit/Block/Adminhtml/Paypal/Settlement/Report.php ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magento.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magento.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Paypal
23
+ * @copyright Copyright (c) 2006-2014 X.commerce, Inc. (http://www.magento.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Adminhtml paypal settlement reports grid block
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Paypal
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Hps_Securesubmit_Block_Adminhtml_Paypal_Settlement_Report extends Mage_Adminhtml_Block_Widget_Grid_Container
35
+ {
36
+ /**
37
+ * Prepare grid container, add additional buttons
38
+ */
39
+ public function __construct()
40
+ {
41
+ $this->_blockGroup = 'hps_securesubmit';
42
+ $this->_controller = 'adminhtml_paypal_settlement_report';
43
+ $this->_headerText = Mage::helper('hps_securesubmit')->__('HPS PayPal Settlement Reports');
44
+ parent::__construct();
45
+ $this->_removeButton('add');
46
+ // $message = Mage::helper('hps_securesubmit')->__('Connecting to PayPal SFTP server to fetch new reports. Are you sure you want to proceed?');
47
+ // $this->_addButton('fetch', array(
48
+ // 'label' => Mage::helper('hps_securesubmit')->__('Fetch Updates'),
49
+ // 'onclick' => "confirmSetLocation('{$message}', '{$this->getUrl('*/*/fetch')}')",
50
+ // 'class' => 'task'
51
+ // ));
52
+ }
53
+ }
app/code/community/Hps/Securesubmit/Block/Adminhtml/Paypal/Settlement/Report/Grid.php ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Hps_Securesubmit_Block_Adminhtml_Paypal_Settlement_Report_Grid extends Mage_Adminhtml_Block_Widget_Grid
4
+ {
5
+ /**
6
+ * Retain filter parameters in session
7
+ *
8
+ * @var bool
9
+ */
10
+ protected $_saveParametersInSession = true;
11
+
12
+ public function __construct()
13
+ {
14
+ parent::__construct();
15
+ $this->setId('HpsSecuresubmitReportSettlementGrid');
16
+ // This is the primary key of the database
17
+ $this->setDefaultSort('row_id');
18
+ $this->setDefaultDir('DESC');
19
+ $this->setSaveParametersInSession(true);
20
+ $this->setUseAjax(true);
21
+ }
22
+
23
+ protected function _prepareCollection()
24
+ {
25
+ $collection = Mage::getModel('hps_securesubmit/report')->getCollection();
26
+ $this->setCollection($collection);
27
+ return parent::_prepareCollection();
28
+ }
29
+
30
+ protected function _prepareColumns()
31
+ {
32
+ $this->addColumn('row_id', array(
33
+ 'header' => Mage::helper('hps_securesubmit')->__('ID'),
34
+ 'align' =>'right',
35
+ 'width' => '50px',
36
+ 'index' => 'row_id',
37
+ ));
38
+
39
+ $this->addColumn('order_id', array(
40
+ 'header' => Mage::helper('hps_securesubmit')->__('Order ID'),
41
+ 'align' => 'left',
42
+ 'width' => '80px',
43
+ 'index' => 'order_id',
44
+ ));
45
+
46
+ $this->addColumn('payer_email', array(
47
+ 'header' => Mage::helper('hps_securesubmit')->__('Payer Email'),
48
+ 'align' => 'left',
49
+ 'index' => 'payer_email',
50
+ ));
51
+
52
+ //$this->addColumn('invoice_id', array(
53
+ // 'header' => Mage::helper('hps_securesubmit')->__('Invoice ID'),
54
+ // 'align' => 'left',
55
+ // 'width' => '80px',
56
+ // 'index' => 'invoice_id',
57
+ //));
58
+
59
+ $this->addColumn('transaction_id', array(
60
+ 'header' => Mage::helper('hps_securesubmit')->__('Transaction ID'),
61
+ 'align' => 'left',
62
+ 'width' => '80px',
63
+ 'index' => 'transaction_id',
64
+ ));
65
+
66
+
67
+ $this->addColumn('last_known_status', array(
68
+ 'header' => Mage::helper('hps_securesubmit')->__('Last Known Status'),
69
+ 'align' => 'left',
70
+ 'index' => 'last_known_status',
71
+ ));
72
+
73
+ $this->addColumn('created_time', array(
74
+ 'header' => Mage::helper('hps_securesubmit')->__('Creation Time'),
75
+ 'align' => 'left',
76
+ 'width' => '120px',
77
+ 'type' => 'date',
78
+ 'default' => '--',
79
+ 'index' => 'created_time',
80
+ ));
81
+
82
+ $this->addColumn('update_time', array(
83
+ 'header' => Mage::helper('hps_securesubmit')->__('Update Time'),
84
+ 'align' => 'left',
85
+ 'width' => '120px',
86
+ 'type' => 'date',
87
+ 'default' => '--',
88
+ 'index' => 'update_time',
89
+ ));
90
+
91
+ return parent::_prepareColumns();
92
+ }
93
+ }
app/code/community/Hps/Securesubmit/Block/Paypal/Credit/Form.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Hps
4
+ * @package Hps_Securesubmit
5
+ * @copyright Copyright (c) 2015 Heartland Payment Systems (https://www.magento.com)
6
+ * @license https://github.com/SecureSubmit/heartland-magento-extension/blob/master/LICENSE Custom License
7
+ */
8
+
9
+ /**
10
+ * PayPal Credit payment form
11
+ */
12
+ class Hps_Securesubmit_Block_Credit_Form extends Hps_Securesubmit_Block_Paypal_Form
13
+ {
14
+ /**
15
+ * Payment method code
16
+ * @var string
17
+ */
18
+ protected $_methodCode = 'hps_paypal_credit';
19
+
20
+ /**
21
+ * Set template and redirect message
22
+ */
23
+ protected function _construct()
24
+ {
25
+ $this->_config = Mage::getModel('hps_securesubmit/config')->setMethod($this->getMethodCode());
26
+ $mark = Mage::getConfig()->getBlockClassName('core/template');
27
+ $mark = new $mark;
28
+ $mark->setTemplate('paypal/payment/mark.phtml')
29
+ ->setPaymentAcceptanceMarkHref('https://www.securecheckout.billmelater.com/paycapture-content/'
30
+ . 'fetch?hash=AU826TU8&content=/bmlweb/ppwpsiw.html')
31
+ ->setPaymentAcceptanceMarkSrc('https://www.paypalobjects.com/webstatic/en_US/i/buttons/'
32
+ . 'ppc-acceptance-medium.png')
33
+ ->setPaymentWhatIs('See terms');
34
+ $this->setTemplate('paypal/payment/redirect.phtml')
35
+ ->setRedirectMessage(
36
+ Mage::helper('paypal')->__('You will be redirected to the PayPal website.')
37
+ )
38
+ ->setMethodTitle('') // Output PayPal mark, omit title
39
+ ->setMethodLabelAfterHtml($mark->toHtml());
40
+ }
41
+ }
app/code/community/Hps/Securesubmit/Block/Paypal/Form.php ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Hps
4
+ * @package Hps_Securesubmit
5
+ * @copyright Copyright (c) 2015 Heartland Payment Systems (https://www.magento.com)
6
+ * @license https://github.com/SecureSubmit/heartland-magento-extension/blob/master/LICENSE Custom License
7
+ */
8
+
9
+ /**
10
+ * PayPal Standard payment "form"
11
+ */
12
+ class Hps_Securesubmit_Block_Paypal_Form extends Mage_Payment_Block_Form
13
+ {
14
+ /**
15
+ * Payment method code
16
+ * @var string
17
+ */
18
+ protected $_methodCode = 'hps_paypal';
19
+
20
+ /**
21
+ * Config model instance
22
+ *
23
+ * @var Hps_Securesubmit_Model_Config
24
+ */
25
+ protected $_config;
26
+
27
+ /**
28
+ * Set template and redirect message
29
+ */
30
+ protected function _construct()
31
+ {
32
+ $this->_config = Mage::getModel('paypal/config')->setMethod($this->getMethodCode());
33
+ $locale = Mage::app()->getLocale();
34
+ $mark = Mage::getConfig()->getBlockClassName('core/template');
35
+ $mark = new $mark;
36
+ $mark->setTemplate('paypal/payment/mark.phtml')
37
+ ->setPaymentAcceptanceMarkHref($this->_config->getPaymentMarkWhatIsPaypalUrl($locale))
38
+ ->setPaymentAcceptanceMarkSrc($this->_config->getPaymentMarkImageUrl($locale->getLocaleCode()))
39
+ ; // known issue: code above will render only static mark image
40
+ $this->setTemplate('paypal/payment/redirect.phtml')
41
+ ->setRedirectMessage(
42
+ Mage::helper('paypal')->__('You will be redirected to the PayPal website.')
43
+ )
44
+ ->setMethodTitle('') // Output PayPal mark, omit title
45
+ ->setMethodLabelAfterHtml($mark->toHtml())
46
+ ;
47
+ return parent::_construct();
48
+ }
49
+
50
+ /**
51
+ * Payment method code getter
52
+ * @return string
53
+ */
54
+ public function getMethodCode()
55
+ {
56
+ return $this->_methodCode;
57
+ }
58
+ }
app/code/community/Hps/Securesubmit/Block/Paypal/Info.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Hps
4
+ * @package Hps_Securesubmit
5
+ * @copyright Copyright (c) 2015 Heartland Payment Systems (https://www.magento.com)
6
+ * @license https://github.com/SecureSubmit/heartland-magento-extension/blob/master/LICENSE Custom License
7
+ */
8
+
9
+ class Hps_SecureSubmit_Block_Paypal_Info extends Mage_Payment_Block_Info
10
+ {
11
+ protected function _prepareSpecificInformation($transport = null)
12
+ {
13
+ $transport = parent::_prepareSpecificInformation($transport);
14
+ $data = array();
15
+ $info = $this->getInfo();
16
+
17
+ $data[Mage::helper("payment")->__("Payment Type")] = "PayPal";
18
+
19
+ return $transport->setData(array_merge($data, $transport->getData()));
20
+ }
21
+ }
app/code/community/Hps/Securesubmit/Block/Paypal/Review.php ADDED
@@ -0,0 +1,218 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Hps
4
+ * @package Hps_Securesubmit
5
+ * @copyright Copyright (c) 2015 Heartland Payment Systems (https://www.magento.com)
6
+ * @license https://github.com/SecureSubmit/heartland-magento-extension/blob/master/LICENSE Custom License
7
+ */
8
+
9
+ /**
10
+ * Paypal Express Onepage checkout block
11
+ */
12
+ class Hps_Securesubmit_Block_Paypal_Review extends Mage_Core_Block_Template
13
+ {
14
+ /**
15
+ * @var Mage_Sales_Model_Quote
16
+ */
17
+ protected $_quote;
18
+
19
+ /**
20
+ * Currently selected shipping rate
21
+ *
22
+ * @var Mage_Sales_Model_Quote_Address_Rate
23
+ */
24
+ protected $_currentShippingRate = null;
25
+
26
+ /**
27
+ * Paypal action prefix
28
+ *
29
+ * @var string
30
+ */
31
+ protected $_paypalActionPrefix = 'paypal';
32
+
33
+ /**
34
+ * Quote object setter
35
+ *
36
+ * @param Mage_Sales_Model_Quote $quote
37
+ * @return Hps_Securesubmit_Block_Paypal_Review
38
+ */
39
+ public function setQuote(Mage_Sales_Model_Quote $quote)
40
+ {
41
+ $this->_quote = $quote;
42
+ return $this;
43
+ }
44
+
45
+ /**
46
+ * Return quote billing address
47
+ *
48
+ * @return Mage_Sales_Model_Quote_Address
49
+ */
50
+ public function getBillingAddress()
51
+ {
52
+ return $this->_quote->getBillingAddress();
53
+ }
54
+
55
+ /**
56
+ * Return quote shipping address
57
+ *
58
+ * @return Mage_Sales_Model_Quote_Address
59
+ */
60
+ public function getShippingAddress()
61
+ {
62
+ if ($this->_quote->getIsVirtual()) {
63
+ return false;
64
+ }
65
+ return $this->_quote->getShippingAddress();
66
+ }
67
+
68
+ /**
69
+ * Get HTML output for specified address
70
+ *
71
+ * @param Mage_Sales_Model_Quote_Address
72
+ * @return string
73
+ */
74
+ public function renderAddress($address)
75
+ {
76
+ return $address->getFormated(true);
77
+ }
78
+
79
+ /**
80
+ * Return carrier name from config, base on carrier code
81
+ *
82
+ * @param $carrierCode string
83
+ * @return string
84
+ */
85
+ public function getCarrierName($carrierCode)
86
+ {
87
+ if ($name = Mage::getStoreConfig("carriers/{$carrierCode}/title")) {
88
+ return $name;
89
+ }
90
+ return $carrierCode;
91
+ }
92
+
93
+ /**
94
+ * Get either shipping rate code or empty value on error
95
+ *
96
+ * @param Varien_Object $rate
97
+ * @return string
98
+ */
99
+ public function renderShippingRateValue(Varien_Object $rate)
100
+ {
101
+ if ($rate->getErrorMessage()) {
102
+ return '';
103
+ }
104
+ return $rate->getCode();
105
+ }
106
+
107
+ /**
108
+ * Get shipping rate code title and its price or error message
109
+ *
110
+ * @param Varien_Object $rate
111
+ * @param string $format
112
+ * @param string $inclTaxFormat
113
+ * @return string
114
+ */
115
+ public function renderShippingRateOption($rate, $format = '%s - %s%s', $inclTaxFormat = ' (%s %s)')
116
+ {
117
+ $renderedInclTax = '';
118
+ if ($rate->getErrorMessage()) {
119
+ $price = $rate->getErrorMessage();
120
+ } else {
121
+ $price = $this->_getShippingPrice($rate->getPrice(),
122
+ $this->helper('tax')->displayShippingPriceIncludingTax());
123
+
124
+ $incl = $this->_getShippingPrice($rate->getPrice(), true);
125
+ if (($incl != $price) && $this->helper('tax')->displayShippingBothPrices()) {
126
+ $renderedInclTax = sprintf($inclTaxFormat, Mage::helper('tax')->__('Incl. Tax'), $incl);
127
+ }
128
+ }
129
+ return sprintf($format, $this->escapeHtml($rate->getMethodTitle()), $price, $renderedInclTax);
130
+ }
131
+
132
+ /**
133
+ * Getter for current shipping rate
134
+ *
135
+ * @return Mage_Sales_Model_Quote_Address_Rate
136
+ */
137
+ public function getCurrentShippingRate()
138
+ {
139
+ return $this->_currentShippingRate;
140
+ }
141
+
142
+ /**
143
+ * Set paypal actions prefix
144
+ */
145
+ public function setPaypalActionPrefix($prefix)
146
+ {
147
+ $this->_paypalActionPrefix = $prefix;
148
+ }
149
+
150
+ /**
151
+ * Return formatted shipping price
152
+ *
153
+ * @param float $price
154
+ * @param bool $isInclTax
155
+ *
156
+ * @return bool
157
+ */
158
+ protected function _getShippingPrice($price, $isInclTax)
159
+ {
160
+ return $this->_formatPrice($this->helper('tax')->getShippingPrice($price, $isInclTax, $this->_address));
161
+ }
162
+
163
+ /**
164
+ * Format price base on store convert price method
165
+ *
166
+ * @param float $price
167
+ * @return string
168
+ */
169
+ protected function _formatPrice($price)
170
+ {
171
+ return $this->_quote->getStore()->convertPrice($price, true);
172
+ }
173
+
174
+ /**
175
+ * Retrieve payment method and assign additional template values
176
+ *
177
+ * @return Hps_Securesubmit_Block_Paypal_Review
178
+ */
179
+ protected function _beforeToHtml()
180
+ {
181
+ $methodInstance = $this->_quote->getPayment()->getMethodInstance();
182
+ $this->setPaymentMethodTitle($methodInstance->getTitle());
183
+
184
+ $this->setShippingRateRequired(true);
185
+ if ($this->_quote->getIsVirtual()) {
186
+ $this->setShippingRateRequired(false);
187
+ } else {
188
+ // prepare shipping rates
189
+ $this->_address = $this->_quote->getShippingAddress();
190
+ $groups = $this->_address->getGroupedAllShippingRates();
191
+ if ($groups && $this->_address) {
192
+ $this->setShippingRateGroups($groups);
193
+ // determine current selected code & name
194
+ foreach ($groups as $code => $rates) {
195
+ foreach ($rates as $rate) {
196
+ if ($this->_address->getShippingMethod() == $rate->getCode()) {
197
+ $this->_currentShippingRate = $rate;
198
+ break(2);
199
+ }
200
+ }
201
+ }
202
+ }
203
+
204
+ $canEditShippingAddress = $this->_quote->getMayEditShippingAddress() && $this->_quote->getPayment()
205
+ ->getAdditionalInformation(Hps_Securesubmit_Model_Paypal_Checkout::PAYMENT_INFO_BUTTON) == 1;
206
+ // misc shipping parameters
207
+ $this->setShippingMethodSubmitUrl($this->getUrl("securesubmit/paypal/saveShippingMethod"))
208
+ ->setCanEditShippingAddress($canEditShippingAddress)
209
+ ->setCanEditShippingMethod($this->_quote->getMayEditShippingMethod())
210
+ ;
211
+ }
212
+
213
+ $this->setEditUrl($this->getUrl("securesubmit/paypal/edit"))
214
+ ->setPlaceOrderUrl($this->getUrl("securesubmit/paypal/placeOrder"));
215
+
216
+ return parent::_beforeToHtml();
217
+ }
218
+ }
app/code/community/Hps/Securesubmit/Block/Paypal/Review/Billing.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Hps
4
+ * @package Hps_Securesubmit
5
+ * @copyright Copyright (c) 2015 Heartland Payment Systems (https://www.magento.com)
6
+ * @license https://github.com/SecureSubmit/heartland-magento-extension/blob/master/LICENSE Custom License
7
+ */
8
+
9
+ /**
10
+ * Paypal Express Onepage checkout block for Billing Address
11
+ */
12
+ class Hps_Securesubmit_Block_Paypal_Review_Billing extends Mage_Checkout_Block_Onepage_Billing
13
+ {
14
+ /**
15
+ * Return Sales Quote Address model
16
+ *
17
+ * @return Mage_Sales_Model_Quote_Address
18
+ */
19
+ public function getAddress()
20
+ {
21
+ if (is_null($this->_address)) {
22
+ if ($this->isCustomerLoggedIn() || $this->getQuote()->getBillingAddress()) {
23
+ $this->_address = $this->getQuote()->getBillingAddress();
24
+ if (!$this->_address->getFirstname()) {
25
+ $this->_address->setFirstname($this->getQuote()->getCustomer()->getFirstname());
26
+ }
27
+ if (!$this->_address->getLastname()) {
28
+ $this->_address->setLastname($this->getQuote()->getCustomer()->getLastname());
29
+ }
30
+ } else {
31
+ $this->_address = Mage::getModel('sales/quote_address');
32
+ }
33
+ }
34
+
35
+ return $this->_address;
36
+ }
37
+ }
app/code/community/Hps/Securesubmit/Block/Paypal/Review/Details.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Hps
4
+ * @package Hps_Securesubmit
5
+ * @copyright Copyright (c) 2015 Heartland Payment Systems (https://www.magento.com)
6
+ * @license https://github.com/SecureSubmit/heartland-magento-extension/blob/master/LICENSE Custom License
7
+ */
8
+
9
+ /**
10
+ * Paypal Express Onepage checkout block
11
+ */
12
+ class Hps_Securesubmit_Block_Paypal_Review_Details extends Mage_Checkout_Block_Cart_Totals
13
+ {
14
+ protected $_address;
15
+
16
+ /**
17
+ * Return review shipping address
18
+ *
19
+ * @return Mage_Sales_Model_Order_Address
20
+ */
21
+ public function getAddress()
22
+ {
23
+ if (empty($this->_address)) {
24
+ $this->_address = $this->getQuote()->getShippingAddress();
25
+ }
26
+ return $this->_address;
27
+ }
28
+
29
+ /**
30
+ * Return review quote totals
31
+ *
32
+ * @return array
33
+ */
34
+ public function getTotals()
35
+ {
36
+ return $this->getQuote()->getTotals();
37
+ }
38
+ }
app/code/community/Hps/Securesubmit/Block/Paypal/Review/Shipping.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Hps
4
+ * @package Hps_Securesubmit
5
+ * @copyright Copyright (c) 2015 Heartland Payment Systems (https://www.magento.com)
6
+ * @license https://github.com/SecureSubmit/heartland-magento-extension/blob/master/LICENSE Custom License
7
+ */
8
+
9
+ /**
10
+ * Paypal Express Onepage checkout block for Shipping Address
11
+ */
12
+ class Hps_Securesubmit_Block_Paypal_Review_Shipping extends Mage_Checkout_Block_Onepage_Shipping
13
+ {
14
+ /**
15
+ * Return Sales Quote Address model (shipping address)
16
+ *
17
+ * @return Mage_Sales_Model_Quote_Address
18
+ */
19
+ public function getAddress()
20
+ {
21
+ if (is_null($this->_address)) {
22
+ if ($this->isCustomerLoggedIn() || $this->getQuote()->getShippingAddress()) {
23
+ $this->_address = $this->getQuote()->getShippingAddress();
24
+ } else {
25
+ $this->_address = Mage::getModel('sales/quote_address');
26
+ }
27
+ }
28
+
29
+ return $this->_address;
30
+ }
31
+ }
app/code/community/Hps/Securesubmit/Block/Paypal/Shortcut.php ADDED
@@ -0,0 +1,183 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Hps
4
+ * @package Hps_Securesubmit
5
+ * @copyright Copyright (c) 2015 Heartland Payment Systems (https://www.magento.com)
6
+ * @license https://github.com/SecureSubmit/heartland-magento-extension/blob/master/LICENSE Custom License
7
+ */
8
+
9
+ /**
10
+ * Paypal expess checkout shortcut link
11
+ *
12
+ * @method string getShortcutHtmlId()
13
+ * @method string getImageUrl()
14
+ * @method string getCheckoutUrl()
15
+ * @method string getBmlShortcutHtmlId()
16
+ * @method string getBmlCheckoutUrl()
17
+ * @method string getBmlImageUrl()
18
+ * @method string getIsBmlEnabled()
19
+ * @method string getConfirmationUrl()
20
+ * @method string getIsInCatalogProduct()
21
+ * @method string getConfirmationMessage()
22
+ */
23
+ class Hps_Securesubmit_Block_Paypal_Shortcut extends Mage_Core_Block_Template
24
+ {
25
+ /**
26
+ * Position of "OR" label against shortcut
27
+ */
28
+ const POSITION_BEFORE = 'before';
29
+ const POSITION_AFTER = 'after';
30
+
31
+ /**
32
+ * Whether the block should be eventually rendered
33
+ *
34
+ * @var bool
35
+ */
36
+ protected $_shouldRender = true;
37
+
38
+ /**
39
+ * Payment method code
40
+ *
41
+ * @var string
42
+ */
43
+ protected $_paymentMethodCode = 'hps_paypal';
44
+
45
+ /**
46
+ * Start express action
47
+ *
48
+ * @var string
49
+ */
50
+ protected $_startAction = 'securesubmit/paypal/start/button/1';
51
+
52
+ /**
53
+ * Express checkout model factory name
54
+ *
55
+ * @var string
56
+ */
57
+ protected $_checkoutType = 'hps_securesubmit/paypal_checkout';
58
+
59
+ /**
60
+ * @return Mage_Core_Block_Abstract
61
+ */
62
+ protected function _beforeToHtml()
63
+ {
64
+ $result = parent::_beforeToHtml();
65
+ $config = Mage::getModel('paypal/config', array($this->_paymentMethodCode));
66
+ $isInCatalog = $this->getIsInCatalogProduct();
67
+ $quote = ($isInCatalog || '' == $this->getIsQuoteAllowed())
68
+ ? null : Mage::getSingleton('checkout/session')->getQuote();
69
+
70
+ // check visibility on cart or product page
71
+ $context = $isInCatalog ? 'visible_on_product' : 'visible_on_cart';
72
+ // if (!$config->$context) {
73
+ // $this->_shouldRender = false;
74
+ // return $result;
75
+ // }
76
+
77
+ // if ($isInCatalog) {
78
+ // /** @var Mage_Catalog_Model_Product $currentProduct */
79
+ // $currentProduct = Mage::registry('current_product');
80
+ // if (!is_null($currentProduct)) {
81
+ // $price = (float)$currentProduct->getFinalPrice();
82
+ // $typeInstance = $currentProduct->getTypeInstance();
83
+ // if (empty($price) && !$currentProduct->isSuper() && !$typeInstance->canConfigure($currentProduct)) {
84
+ // $this->_shouldRender = false;
85
+ // return $result;
86
+ // }
87
+ // }
88
+ // }
89
+
90
+ // validate minimum quote amount and validate quote for zero grandtotal
91
+ if (null !== $quote && (!$quote->validateMinimumAmount()
92
+ || (!$quote->getGrandTotal() && !$quote->hasNominalItems()))) {
93
+ $this->_shouldRender = false;
94
+ return $result;
95
+ }
96
+
97
+ // check payment method availability
98
+ $methodInstance = Mage::helper('payment')->getMethodInstance($this->_paymentMethodCode);
99
+ if (!$methodInstance || !$methodInstance->isAvailable($quote)) {
100
+ $this->_shouldRender = false;
101
+ return $result;
102
+ }
103
+
104
+ // set misc data
105
+ $this->setShortcutHtmlId($this->helper('core')->uniqHash('hps_shortcut_'))
106
+ ->setCheckoutUrl($this->getUrl($this->_startAction));
107
+
108
+ $this->_getBmlShortcut($quote);
109
+
110
+ // use static image if in catalog
111
+ // if ($isInCatalog || null === $quote) {
112
+ // $this->setImageUrl($config->getExpressCheckoutShortcutImageUrl(Mage::app()->getLocale()->getLocaleCode()));
113
+ // } else {
114
+ $this->setImageUrl('https://www.paypalobjects.com/webstatic/en_US/i/buttons/checkout-logo-medium.png');
115
+ // }
116
+
117
+ // // ask whether to create a billing agreement
118
+ // $customerId = Mage::getSingleton('customer/session')->getCustomerId(); // potential issue for caching
119
+ // if (Mage::helper('paypal')->shouldAskToCreateBillingAgreement($config, $customerId)) {
120
+ // $this->setConfirmationUrl($this->getUrl($this->_startAction,
121
+ // array(Hps_Securesubmit_Model_Paypal_Checkout::PAYMENT_INFO_TRANSPORT_BILLING_AGREEMENT => 1)
122
+ // ));
123
+ // $this->setConfirmationMessage(Mage::helper('paypal')->__('Would you like to sign a billing agreement to streamline further purchases with PayPal?'));
124
+ // }
125
+
126
+ return $result;
127
+ }
128
+
129
+ /**
130
+ * @param $quote
131
+ *
132
+ * @return Hps_Securesubmit_Block_Paypal_Shortcut
133
+ */
134
+ protected function _getBmlShortcut($quote)
135
+ {
136
+ $bml = Mage::helper('payment')->getMethodInstance('hps_paypal_bml');
137
+ $isBmlEnabled = $bml && $bml->isAvailable($quote);
138
+ $this->setBmlShortcutHtmlId($this->helper('core')->uniqHash('hps_shortcut_bml_'))
139
+ ->setBmlCheckoutUrl($this->getUrl('securesubmit/paypal/credit/button/1'))
140
+ ->setBmlImageUrl('https://www.paypalobjects.com/webstatic/en_US/i/buttons/ppcredit-logo-medium.png')
141
+ ->setMarketMessage('https://www.paypalobjects.com/webstatic/en_US/btn/btn_bml_text.png')
142
+ ->setMarketMessageUrl('https://www.securecheckout.billmelater.com/paycapture-content/'
143
+ . 'fetch?hash=AU826TU8&content=/bmlweb/ppwpsiw.html')
144
+ ->setIsBmlEnabled(true);
145
+ return $this;
146
+ }
147
+
148
+ /**
149
+ * Render the block if needed
150
+ *
151
+ * @return string
152
+ */
153
+ protected function _toHtml()
154
+ {
155
+ if (!$this->_shouldRender) {
156
+ return '';
157
+ }
158
+ return parent::_toHtml();
159
+ }
160
+
161
+ /**
162
+ * Check is "OR" label position before shortcut
163
+ *
164
+ * @return bool
165
+ */
166
+ public function isOrPositionBefore()
167
+ {
168
+ return ($this->getIsInCatalogProduct() && !$this->getShowOrPosition())
169
+ || ($this->getShowOrPosition() && $this->getShowOrPosition() == self::POSITION_BEFORE);
170
+
171
+ }
172
+
173
+ /**
174
+ * Check is "OR" label position after shortcut
175
+ *
176
+ * @return bool
177
+ */
178
+ public function isOrPositionAfter()
179
+ {
180
+ return (!$this->getIsInCatalogProduct() && !$this->getShowOrPosition())
181
+ || ($this->getShowOrPosition() && $this->getShowOrPosition() == self::POSITION_AFTER);
182
+ }
183
+ }
app/code/community/Hps/Securesubmit/Controller/Paypal/Abstract.php ADDED
@@ -0,0 +1,516 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Hps
4
+ * @package Hps_Securesubmit
5
+ * @copyright Copyright (c) 2015 Heartland Payment Systems (https://www.magento.com)
6
+ * @license https://github.com/SecureSubmit/heartland-magento-extension/blob/master/LICENSE Custom License
7
+ */
8
+
9
+ /**
10
+ * Abstract PayPal Checkout Controller
11
+ */
12
+ abstract class Hps_Securesubmit_Controller_Paypal_Abstract extends Mage_Core_Controller_Front_Action
13
+ {
14
+ /**
15
+ * @var Hps_Securesubmit_Model_Paypal_Checkout
16
+ */
17
+ protected $_checkout = null;
18
+
19
+ /**
20
+ * @var Hps_Securesubmit_Model_Config
21
+ */
22
+ protected $_config = null;
23
+
24
+ /**
25
+ * @var Mage_Sales_Model_Quote
26
+ */
27
+ protected $_quote = false;
28
+
29
+ /**
30
+ * Instantiate config
31
+ */
32
+ protected function _construct()
33
+ {
34
+ parent::_construct();
35
+ $this->_config = Mage::getModel($this->_configType, array($this->_configMethod));
36
+ }
37
+
38
+ /**
39
+ * Start PayPal Checkout by requesting initial token and dispatching customer to PayPal
40
+ */
41
+ public function startAction()
42
+ {
43
+ try {
44
+ $this->_initCheckout();
45
+
46
+ if ($this->_getQuote()->getIsMultiShipping()) {
47
+ $this->_getQuote()->setIsMultiShipping(false);
48
+ $this->_getQuote()->removeAllAddresses();
49
+ }
50
+
51
+ $customer = Mage::getSingleton('customer/session')->getCustomer();
52
+ $quoteCheckoutMethod = $this->_getQuote()->getCheckoutMethod();
53
+ if ($customer && $customer->getId()) {
54
+ $this->_checkout->setCustomerWithAddressChange(
55
+ $customer, $this->_getQuote()->getBillingAddress(), $this->_getQuote()->getShippingAddress()
56
+ );
57
+ } elseif ((!$quoteCheckoutMethod
58
+ || $quoteCheckoutMethod != Mage_Checkout_Model_Type_Onepage::METHOD_REGISTER)
59
+ && !Mage::helper('checkout')->isAllowedGuestCheckout(
60
+ $this->_getQuote(),
61
+ $this->_getQuote()->getStoreId()
62
+ )) {
63
+ Mage::getSingleton('core/session')->addNotice(
64
+ Mage::helper('paypal')->__('To proceed to Checkout, please log in using your email address.')
65
+ );
66
+ $this->redirectLogin();
67
+ Mage::getSingleton('customer/session')
68
+ ->setBeforeAuthUrl(Mage::getUrl('*/*/*', array('_current' => true)));
69
+ return;
70
+ }
71
+
72
+ $button = (bool)$this->getRequest()->getParam('button');
73
+ $credit = (bool)$this->getRequest()->getParam('credit');
74
+ $token = $this->_checkout->start(Mage::getUrl('*/*/return'), Mage::getUrl('*/*/cancel'), array(
75
+ 'button' => $button,
76
+ 'credit' => $credit,
77
+ ));
78
+ if ($token && $url = $this->_checkout->getRedirectUrl()) {
79
+ $this->_initToken($token);
80
+ $this->getResponse()->setRedirect($url);
81
+ return;
82
+ }
83
+ } catch (Mage_Core_Exception $e) {
84
+ // print_r($e->getMessage());die();
85
+ $this->_getCheckoutSession()->addError($e->getMessage());
86
+ Mage::log(Mage::helper('hps_securesubmit')->__("Error creating PayPal session: %s", $e->getMessage()), Zend_Log::WARN);
87
+ } catch (Exception $e) {
88
+ // print_r($e->getMessage());die();
89
+ $this->_getCheckoutSession()->addError($this->__('Unable to start PayPal Checkout.'));
90
+ Mage::logException($e);
91
+ Mage::log(Mage::helper('hps_securesubmit')->__("Error creating PayPal session: %s", $e->getMessage()), Zend_Log::WARN);
92
+ }
93
+ $this->_redirect('checkout/cart');
94
+ }
95
+
96
+ /**
97
+ * Return shipping options items for shipping address from request
98
+ */
99
+ public function shippingOptionsCallbackAction()
100
+ {
101
+ try {
102
+ $quoteId = $this->getRequest()->getParam('quote_id');
103
+ $this->_quote = Mage::getModel('sales/quote')->load($quoteId);
104
+ $this->_initCheckout();
105
+ $response = $this->_checkout->getShippingOptionsCallbackResponse($this->getRequest()->getParams());
106
+ $this->getResponse()->setBody($response);
107
+ } catch (Exception $e) {
108
+ Mage::logException($e);
109
+ }
110
+ }
111
+
112
+ /**
113
+ * Cancel PayPal Checkout
114
+ */
115
+ public function cancelAction()
116
+ {
117
+ try {
118
+ $this->_initToken(false);
119
+ // TODO verify if this logic of order cancelation is deprecated
120
+ // if there is an order - cancel it
121
+ $orderId = $this->_getCheckoutSession()->getLastOrderId();
122
+ $order = ($orderId) ? Mage::getModel('sales/order')->load($orderId) : false;
123
+ if ($order && $order->getId() && $order->getQuoteId() == $this->_getCheckoutSession()->getQuoteId()) {
124
+ $order->cancel()->save();
125
+ $this->_getCheckoutSession()
126
+ ->unsLastQuoteId()
127
+ ->unsLastSuccessQuoteId()
128
+ ->unsLastOrderId()
129
+ ->unsLastRealOrderId()
130
+ ->addSuccess($this->__('PayPal Checkout and Order have been canceled.'))
131
+ ;
132
+ } else {
133
+ $this->_getCheckoutSession()->addSuccess($this->__('PayPal Checkout has been canceled.'));
134
+ }
135
+ } catch (Mage_Core_Exception $e) {
136
+ $this->_getCheckoutSession()->addError($e->getMessage());
137
+ } catch (Exception $e) {
138
+ $this->_getCheckoutSession()->addError($this->__('Unable to cancel PayPal Checkout.'));
139
+ Mage::logException($e);
140
+ }
141
+
142
+ $this->_redirect('checkout/cart');
143
+ }
144
+
145
+ /**
146
+ * Return from PayPal and dispatch customer to order review page
147
+ */
148
+ public function returnAction()
149
+ {
150
+ if ($this->getRequest()->getParam('retry_authorization') == 'true'
151
+ && is_array($this->_getCheckoutSession()->getPaypalTransactionData())
152
+ ) {
153
+ $this->_forward('placeOrder');
154
+ return;
155
+ }
156
+ try {
157
+ $token = $this->getRequest()->getParam('token');
158
+ $payerId = $this->getRequest()->getParam('PayerID');
159
+ $this->_getCheckoutSession()->unsPaypalTransactionData();
160
+ $this->_checkout = $this->_initCheckout();
161
+ $token = $this->_initToken();
162
+ $this->_checkout->returnFromPaypal($token, $payerId);
163
+ $this->_getSession()->setPayPalPayerId($payerId);
164
+
165
+ if ($this->_checkout->canSkipOrderReviewStep()) {
166
+ $this->_forward('placeOrder');
167
+ } else {
168
+ $this->_redirect('*/*/review');
169
+ }
170
+
171
+ return;
172
+ } catch (Mage_Core_Exception $e) {
173
+ die();
174
+ Mage::getSingleton('checkout/session')->addError($e->getMessage());
175
+ }
176
+ catch (Exception $e) {
177
+ die();
178
+ Mage::getSingleton('checkout/session')->addError($this->__('Unable to process PayPal Checkout approval.'));
179
+ Mage::logException($e);
180
+ }
181
+ $this->_redirect('checkout/cart');
182
+ }
183
+
184
+ /**
185
+ * Review order after returning from PayPal
186
+ */
187
+ public function reviewAction()
188
+ {
189
+ try {
190
+ $this->_initCheckout();
191
+ $token = $this->_initToken();
192
+ $this->_checkout->prepareOrderReview($token);
193
+ $this->loadLayout();
194
+ $this->_initLayoutMessages('paypal/session');
195
+ $reviewBlock = $this->getLayout()->getBlock('hps.securesubmit.paypal.review');
196
+ $reviewBlock->setQuote($this->_getQuote());
197
+ $reviewBlock->getChild('details')->setQuote($this->_getQuote());
198
+ if ($reviewBlock->getChild('shipping_method')) {
199
+ $reviewBlock->getChild('shipping_method')->setQuote($this->_getQuote());
200
+ }
201
+ $this->renderLayout();
202
+ return;
203
+ }
204
+ catch (Mage_Core_Exception $e) {
205
+ Mage::getSingleton('checkout/session')->addError($e->getMessage());
206
+ }
207
+ catch (Exception $e) {
208
+ Mage::getSingleton('checkout/session')->addError(
209
+ $this->__('Unable to initialize PayPal Checkout review.')
210
+ );
211
+ Mage::logException($e);
212
+ }
213
+ $this->_redirect('checkout/cart');
214
+ }
215
+
216
+ /**
217
+ * Dispatch customer back to PayPal for editing payment information
218
+ */
219
+ public function editAction()
220
+ {
221
+ try {
222
+ $this->getResponse()->setRedirect($this->_config->getPayPalCheckoutEditUrl($this->_initToken()));
223
+ }
224
+ catch (Mage_Core_Exception $e) {
225
+ $this->_getSession()->addError($e->getMessage());
226
+ $this->_redirect('*/*/review');
227
+ }
228
+ }
229
+
230
+ /**
231
+ * Update shipping method (combined action for ajax and regular request)
232
+ */
233
+ public function saveShippingMethodAction()
234
+ {
235
+ try {
236
+ $isAjax = $this->getRequest()->getParam('isAjax');
237
+ $this->_initCheckout();
238
+ $this->_checkout->updateShippingMethod($this->getRequest()->getParam('shipping_method'));
239
+ if ($isAjax) {
240
+ $this->loadLayout('hps_securesubmit_paypal_review_details');
241
+ $this->getResponse()->setBody($this->getLayout()->getBlock('root')
242
+ ->setQuote($this->_getQuote())
243
+ ->toHtml());
244
+ return;
245
+ }
246
+ } catch (Mage_Core_Exception $e) {
247
+ $this->_getSession()->addError($e->getMessage());
248
+ } catch (Exception $e) {
249
+ $this->_getSession()->addError($this->__('Unable to update shipping method.'));
250
+ Mage::logException($e);
251
+ }
252
+ if ($isAjax) {
253
+ $this->getResponse()->setBody('<script type="text/javascript">window.location.href = '
254
+ . Mage::getUrl('*/*/review') . ';</script>');
255
+ } else {
256
+ $this->_redirect('*/*/review');
257
+ }
258
+ }
259
+
260
+ /**
261
+ * Update Order (combined action for ajax and regular request)
262
+ */
263
+ public function updateShippingMethodsAction()
264
+ {
265
+ try {
266
+ $this->_initCheckout();
267
+ $this->_checkout->prepareOrderReview($this->_initToken());
268
+ $this->loadLayout('hps_securesubmit_paypal_review');
269
+
270
+ $this->getResponse()->setBody($this->getLayout()->getBlock('express.review.shipping.method')
271
+ ->setQuote($this->_getQuote())
272
+ ->toHtml());
273
+ return;
274
+ } catch (Mage_Core_Exception $e) {
275
+ $this->_getSession()->addError($e->getMessage());
276
+ } catch (Exception $e) {
277
+ $this->_getSession()->addError($this->__('Unable to update shipping method.'));
278
+ Mage::logException($e);
279
+ }
280
+ $this->getResponse()->setBody('<script type="text/javascript">window.location.href = '
281
+ . Mage::getUrl('*/*/review') . ';</script>');
282
+ }
283
+
284
+ /**
285
+ * Submit the order
286
+ */
287
+ public function placeOrderAction()
288
+ {
289
+ try {
290
+ $requiredAgreements = Mage::helper('checkout')->getRequiredAgreementIds();
291
+ if ($requiredAgreements) {
292
+ $postedAgreements = array_keys($this->getRequest()->getPost('agreement', array()));
293
+ if (array_diff($requiredAgreements, $postedAgreements)) {
294
+ Mage::throwException(Mage::helper('paypal')->__('Please agree to all the terms and conditions before placing the order.'));
295
+ }
296
+ }
297
+ $this->_initCheckout();
298
+ $this->_checkout->place($this->_initToken());
299
+
300
+ // prepare session to success or cancellation page
301
+ $session = $this->_getCheckoutSession();
302
+ $session->clearHelperData();
303
+
304
+ // "last successful quote"
305
+ $quoteId = $this->_getQuote()->getId();
306
+ $session->setLastQuoteId($quoteId)->setLastSuccessQuoteId($quoteId);
307
+
308
+ // an order may be created
309
+ $order = $this->_checkout->getOrder();
310
+ if ($order) {
311
+ $session->setLastOrderId($order->getId())
312
+ ->setLastRealOrderId($order->getIncrementId());
313
+ // as well a billing agreement can be created
314
+ $agreement = $this->_checkout->getBillingAgreement();
315
+ if ($agreement) {
316
+ $session->setLastBillingAgreementId($agreement->getId());
317
+ }
318
+ }
319
+
320
+ // recurring profiles may be created along with the order or without it
321
+ $profiles = $this->_checkout->getRecurringPaymentProfiles();
322
+ if ($profiles) {
323
+ $ids = array();
324
+ foreach($profiles as $profile) {
325
+ $ids[] = $profile->getId();
326
+ }
327
+ $session->setLastRecurringProfileIds($ids);
328
+ }
329
+
330
+ // redirect if PayPal specified some URL (for example, to Giropay bank)
331
+ $url = $this->_checkout->getRedirectUrl();
332
+ if ($url) {
333
+ $this->getResponse()->setRedirect($url);
334
+ return;
335
+ }
336
+ $this->_initToken(false); // no need in token anymore
337
+ $this->_redirect('checkout/onepage/success');
338
+ return;
339
+ } catch (Hps_Securesubmit_Model_Api_ProcessableException $e) {
340
+ // print_r($e);die();
341
+ $this->_processPaypalApiError($e);
342
+ } catch (Mage_Core_Exception $e) {
343
+ // print_r($e);die();
344
+ Mage::helper('checkout')->sendPaymentFailedEmail($this->_getQuote(), $e->getMessage());
345
+ $this->_getSession()->addError($e->getMessage());
346
+ $this->_redirect('*/*/review');
347
+ } catch (Exception $e) {
348
+ // print_r($e);die();
349
+ Mage::helper('checkout')->sendPaymentFailedEmail(
350
+ $this->_getQuote(),
351
+ $this->__('Unable to place the order.')
352
+ );
353
+ $this->_getSession()->addError($this->__('Unable to place the order.'));
354
+ Mage::logException($e);
355
+ $this->_redirect('*/*/review');
356
+ }
357
+ }
358
+
359
+ /**
360
+ * Process PayPal API's processable errors
361
+ *
362
+ * @param Hps_Securesubmit_Model_Api_ProcessableException $exception
363
+ * @throws Hps_Securesubmit_Model_Api_ProcessableException
364
+ */
365
+ protected function _processPaypalApiError($exception)
366
+ {
367
+ switch ($exception->getCode()) {
368
+ case Hps_Securesubmit_Model_Api_ProcessableException::API_MAX_PAYMENT_ATTEMPTS_EXCEEDED:
369
+ case Hps_Securesubmit_Model_Api_ProcessableException::API_TRANSACTION_EXPIRED:
370
+ $this->getResponse()->setRedirect(
371
+ $this->_getQuote()->getPayment()->getCheckoutRedirectUrl()
372
+ );
373
+ break;
374
+ case Hps_Securesubmit_Model_Api_ProcessableException::API_DO_EXPRESS_CHECKOUT_FAIL:
375
+ $this->_redirectSameToken();
376
+ break;
377
+ case Hps_Securesubmit_Model_Api_ProcessableException::API_UNABLE_TRANSACTION_COMPLETE:
378
+ if ($this->_config->getPaymentAction() == Mage_Payment_Model_Method_Abstract::ACTION_ORDER) {
379
+ $paypalTransactionData = $this->_getCheckoutSession()->getPaypalTransactionData();
380
+ $this->getResponse()->setRedirect(
381
+ $this->_config->getPayPalCheckoutOrderUrl($paypalTransactionData['transaction_id'])
382
+ );
383
+ } else {
384
+ $this->_redirectSameToken();
385
+ }
386
+ break;
387
+ default:
388
+ $this->_redirectToCartAndShowError($exception->getUserMessage());
389
+ break;
390
+ }
391
+
392
+ }
393
+
394
+ /**
395
+ * Redirect customer back to PayPal with the same token
396
+ */
397
+ protected function _redirectSameToken()
398
+ {
399
+ $token = $this->_initToken();
400
+ $this->getResponse()->setRedirect(
401
+ $this->_config->getPayPalCheckoutStartUrl($token)
402
+ );
403
+ }
404
+
405
+ /**
406
+ * Redirect customer to shopping cart and show error message
407
+ *
408
+ * @param string $errorMessage
409
+ */
410
+ protected function _redirectToCartAndShowError($errorMessage)
411
+ {
412
+ $cart = Mage::getSingleton('checkout/cart');
413
+ $cart->getCheckoutSession()->addError($errorMessage);
414
+ $this->_redirect('checkout/cart');
415
+ }
416
+
417
+ /**
418
+ * Instantiate quote and checkout
419
+ *
420
+ * @return Hps_Securesubmit_Model_Paypal_Checkout
421
+ * @throws Mage_Core_Exception
422
+ */
423
+ protected function _initCheckout()
424
+ {
425
+ $quote = $this->_getQuote();
426
+ if (!$quote->hasItems() || $quote->getHasError()) {
427
+ $this->getResponse()->setHeader('HTTP/1.1','403 Forbidden');
428
+ Mage::throwException(Mage::helper('paypal')->__('Unable to initialize PayPal Checkout.'));
429
+ }
430
+ $this->_checkout = Mage::getSingleton($this->_checkoutType, array(
431
+ 'config' => $this->_config,
432
+ 'quote' => $quote,
433
+ ));
434
+
435
+ return $this->_checkout;
436
+ }
437
+
438
+ /**
439
+ * Search for proper checkout token in request or session or (un)set specified one
440
+ * Combined getter/setter
441
+ *
442
+ * @param string $setToken
443
+ * @return Hps_Securesubmit_PaypalController|string
444
+ */
445
+ protected function _initToken($setToken = null)
446
+ {
447
+ if (null !== $setToken) {
448
+ if (false === $setToken) {
449
+ // security measure for avoid unsetting token twice
450
+ if (!$this->_getSession()->getPayPalCheckoutToken()) {
451
+ Mage::throwException($this->__('PayPal Checkout Token does not exist.'));
452
+ }
453
+ $this->_getSession()->unsPayPalCheckoutToken();
454
+ } else {
455
+ $this->_getSession()->setPayPalCheckoutToken($setToken);
456
+ }
457
+ return $this;
458
+ }
459
+ if ($setToken = $this->getRequest()->getParam('token')) {
460
+ if ($setToken !== $this->_getSession()->getPayPalCheckoutToken()) {
461
+ Mage::throwException($this->__('Wrong PayPal Checkout Token specified.'));
462
+ }
463
+ } else {
464
+ $setToken = $this->_getSession()->getPayPalCheckoutToken();
465
+ }
466
+ return $setToken;
467
+ }
468
+
469
+ /**
470
+ * PayPal session instance getter
471
+ *
472
+ * @return Mage_PayPal_Model_Session
473
+ */
474
+ private function _getSession()
475
+ {
476
+ return Mage::getSingleton('hps_securesubmit/session');
477
+ }
478
+
479
+ /**
480
+ * Return checkout session object
481
+ *
482
+ * @return Mage_Checkout_Model_Session
483
+ */
484
+ protected function _getCheckoutSession()
485
+ {
486
+ return Mage::getSingleton('checkout/session');
487
+ }
488
+
489
+ /**
490
+ * Return checkout quote object
491
+ *
492
+ * @return Mage_Sales_Model_Quote
493
+ */
494
+ private function _getQuote()
495
+ {
496
+ if (!$this->_quote) {
497
+ $this->_quote = $this->_getCheckoutSession()->getQuote();
498
+ }
499
+ return $this->_quote;
500
+ }
501
+
502
+ /**
503
+ * Redirect to login page
504
+ *
505
+ */
506
+ public function redirectLogin()
507
+ {
508
+ $this->setFlag('', 'no-dispatch', true);
509
+ $this->getResponse()->setRedirect(
510
+ Mage::helper('core/url')->addRequestParam(
511
+ Mage::helper('customer')->getLoginUrl(),
512
+ array('context' => 'checkout')
513
+ )
514
+ );
515
+ }
516
+ }
app/code/community/Hps/Securesubmit/Model/Api/Abstract.php ADDED
@@ -0,0 +1,581 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Hps
4
+ * @package Hps_Securesubmit
5
+ * @copyright Copyright (c) 2015 Heartland Payment Systems (https://www.magento.com)
6
+ * @license https://github.com/SecureSubmit/heartland-magento-extension/blob/master/LICENSE Custom License
7
+ */
8
+
9
+ /**
10
+ * Abstract class for Paypal API wrappers
11
+ *
12
+ * @author Magento Core Team <core@magentocommerce.com>
13
+ */
14
+ abstract class Hps_Securesubmit_Model_Api_Abstract extends Varien_Object
15
+ {
16
+ /**
17
+ * Config instance
18
+ * @var Hps_Securesubmit_Model_Config
19
+ */
20
+ protected $_config = null;
21
+
22
+ /**
23
+ * Global private to public interface map
24
+ * @var array
25
+ */
26
+ protected $_globalMap = array();
27
+
28
+ /**
29
+ * Filter callbacks for exporting $this data to API call
30
+ *
31
+ * @var array
32
+ */
33
+ protected $_exportToRequestFilters = array();
34
+
35
+ /**
36
+ * Filter callbacks for importing API result to $this data
37
+ *
38
+ * @var array
39
+ */
40
+ protected $_importFromRequestFilters = array();
41
+
42
+ /**
43
+ * Line items export to request mapping settings
44
+ * @var array
45
+ */
46
+ protected $_lineItemExportItems = array();
47
+ protected $_lineItemExportItemsFilters = array();
48
+ protected $_lineItemTotalExportMap = array();
49
+
50
+ /**
51
+ * PayPal shopping cart instance
52
+ *
53
+ * @var Hps_Securesubmit_Model_Paypal_Cart
54
+ */
55
+ protected $_cart = null;
56
+
57
+ /**
58
+ * Shipping options export to request mapping settings
59
+ * @var array
60
+ */
61
+ protected $_shippingOptionsExportItemsFormat = array();
62
+
63
+ /**
64
+ * Imported recurring profiles array
65
+ *
66
+ * @var array
67
+ */
68
+ protected $_recurringPaymentProfiles = array();
69
+
70
+ /**
71
+ * Fields that should be replaced in debug with '***'
72
+ *
73
+ * @var array
74
+ */
75
+ protected $_debugReplacePrivateDataKeys = array();
76
+
77
+ /**
78
+ * Return Paypal Api user name based on config data
79
+ *
80
+ * @return string
81
+ */
82
+ public function getApiUsername()
83
+ {
84
+ return $this->_config->apiUsername;
85
+ }
86
+
87
+ /**
88
+ * Return Paypal Api password based on config data
89
+ *
90
+ * @return string
91
+ */
92
+ public function getApiPassword()
93
+ {
94
+ return $this->_config->apiPassword;
95
+ }
96
+
97
+ /**
98
+ * Return Paypal Api signature based on config data
99
+ *
100
+ * @return string
101
+ */
102
+ public function getApiSignature()
103
+ {
104
+ return $this->_config->apiSignature;
105
+ }
106
+
107
+ /**
108
+ * Return Paypal Api certificate based on config data
109
+ *
110
+ * @return string
111
+ */
112
+ public function getApiCertificate()
113
+ {
114
+ return $this->_config->getApiCertificate();
115
+ }
116
+
117
+ /**
118
+ * BN code getter
119
+ *
120
+ * @return string
121
+ */
122
+ public function getBuildNotationCode()
123
+ {
124
+ return $this->_config->getBuildNotationCode();
125
+ }
126
+
127
+ /**
128
+ * Return Paypal Api proxy status based on config data
129
+ *
130
+ * @return bool
131
+ */
132
+ public function getUseProxy()
133
+ {
134
+ return $this->_getDataOrConfig('use_proxy', false);
135
+ }
136
+
137
+ /**
138
+ * Return Paypal Api proxy host based on config data
139
+ *
140
+ * @return string
141
+ */
142
+ public function getProxyHost()
143
+ {
144
+ return $this->_getDataOrConfig('proxy_host', '127.0.0.1');
145
+ }
146
+
147
+ /**
148
+ * Return Paypal Api proxy port based on config data
149
+ *
150
+ * @return string
151
+ */
152
+ public function getProxyPort()
153
+ {
154
+ return $this->_getDataOrConfig('proxy_port', '808');
155
+ }
156
+
157
+ /**
158
+ * @deprecated after 1.4.1.0
159
+ *
160
+ * @return bool
161
+ */
162
+ public function getDebug()
163
+ {
164
+ return $this->getDebugFlag();
165
+ }
166
+
167
+ /**
168
+ * PayPal page CSS getter
169
+ *
170
+ * @return string
171
+ */
172
+ public function getPageStyle()
173
+ {
174
+ return $this->_getDataOrConfig('page_style');
175
+ }
176
+
177
+ /**
178
+ * PayPal page header image URL getter
179
+ *
180
+ * @return string
181
+ */
182
+ public function getHdrimg()
183
+ {
184
+ return $this->_getDataOrConfig('paypal_hdrimg');
185
+ }
186
+
187
+ /**
188
+ * PayPal page header border color getter
189
+ *
190
+ * @return string
191
+ */
192
+ public function getHdrbordercolor()
193
+ {
194
+ return $this->_getDataOrConfig('paypal_hdrbordercolor');
195
+ }
196
+
197
+ /**
198
+ * PayPal page header background color getter
199
+ *
200
+ * @return string
201
+ */
202
+ public function getHdrbackcolor()
203
+ {
204
+ return $this->_getDataOrConfig('paypal_hdrbackcolor');
205
+ }
206
+
207
+ /**
208
+ * PayPal page "payflow color" (?) getter
209
+ *
210
+ * @return string
211
+ */
212
+ public function getPayflowcolor()
213
+ {
214
+ return $this->_getDataOrConfig('paypal_payflowcolor');
215
+ }
216
+
217
+ /**
218
+ * Payment action getter
219
+ *
220
+ * @return string
221
+ */
222
+ public function getPaymentAction()
223
+ {
224
+ return $this->_getDataOrConfig('payment_action');
225
+ }
226
+
227
+ /**
228
+ * PayPal merchant email getter
229
+ */
230
+ public function getBusinessAccount()
231
+ {
232
+ return $this->_getDataOrConfig('business_account');
233
+ }
234
+
235
+ /**
236
+ * Import $this public data to specified object or array
237
+ *
238
+ * @param array|Varien_Object $to
239
+ * @param array $publicMap
240
+ * @return array|Varien_Object
241
+ */
242
+ public function &import($to, array $publicMap = array())
243
+ {
244
+ return Varien_Object_Mapper::accumulateByMap(array($this, 'getDataUsingMethod'), $to, $publicMap);
245
+ }
246
+
247
+ /**
248
+ * Export $this public data from specified object or array
249
+ *
250
+ * @param array|Varien_Object $from
251
+ * @param array $publicMap
252
+ * @return Hps_Securesubmit_Model_Api_Abstract
253
+ */
254
+ public function export($from, array $publicMap = array())
255
+ {
256
+ Varien_Object_Mapper::accumulateByMap($from, array($this, 'setDataUsingMethod'), $publicMap);
257
+ return $this;
258
+ }
259
+
260
+ /**
261
+ * Set PayPal cart instance
262
+ *
263
+ * @param Hps_Securesubmit_Model_Paypal_Cart $cart
264
+ * @return Hps_Securesubmit_Model_Api_Abstract
265
+ */
266
+ public function setPaypalCart(Hps_Securesubmit_Model_Paypal_Cart $cart)
267
+ {
268
+ $this->_cart = $cart;
269
+ return $this;
270
+ }
271
+
272
+ /**
273
+ * Config instance setter
274
+ * @param Hps_Securesubmit_Model_Config $config
275
+ * @return Hps_Securesubmit_Model_Api_Abstract
276
+ */
277
+ public function setConfigObject(Hps_Securesubmit_Model_Config $config)
278
+ {
279
+ $this->_config = $config;
280
+ return $this;
281
+ }
282
+
283
+ /**
284
+ * Current locale code getter
285
+ *
286
+ * @return string
287
+ */
288
+ public function getLocaleCode()
289
+ {
290
+ return Mage::app()->getLocale()->getLocaleCode();
291
+ }
292
+
293
+ /**
294
+ * Always take into accoun
295
+ */
296
+ public function getFraudManagementFiltersEnabled()
297
+ {
298
+ return 1;
299
+ }
300
+
301
+ /**
302
+ * Set recurring profiles
303
+ *
304
+ * @param array $items
305
+ * @return Hps_Securesubmit_Model_Api_Abstract
306
+ */
307
+ public function addRecurringPaymentProfiles(array $items)
308
+ {
309
+ if ($items) {
310
+ $this->_recurringPaymentProfiles = $items;
311
+ }
312
+ return $this;
313
+ }
314
+
315
+ /**
316
+ * Export $this public data to private request array
317
+ *
318
+ * @param array $internalRequestMap
319
+ * @param array $request
320
+ * @return array
321
+ */
322
+ protected function &_exportToRequest(array $privateRequestMap, array $request = array())
323
+ {
324
+ $map = array();
325
+ foreach ($privateRequestMap as $key) {
326
+ if (isset($this->_globalMap[$key])) {
327
+ $map[$this->_globalMap[$key]] = $key;
328
+ }
329
+ }
330
+ $result = Varien_Object_Mapper::accumulateByMap(array($this, 'getDataUsingMethod'), $request, $map);
331
+ foreach ($privateRequestMap as $key) {
332
+ if (isset($this->_exportToRequestFilters[$key]) && isset($result[$key])) {
333
+ $callback = $this->_exportToRequestFilters[$key];
334
+ $privateKey = $result[$key];
335
+ $publicKey = $map[$this->_globalMap[$key]];
336
+ $result[$key] = call_user_func(array($this, $callback), $privateKey, $publicKey);
337
+ }
338
+ }
339
+ return $result;
340
+ }
341
+
342
+ /**
343
+ * Import $this public data from a private response array
344
+ *
345
+ * @param array $privateResponseMap
346
+ * @param array $response
347
+ */
348
+ protected function _importFromResponse(array $privateResponseMap, array $response)
349
+ {
350
+ $map = array();
351
+ foreach ($privateResponseMap as $key) {
352
+ if (isset($this->_globalMap[$key])) {
353
+ $map[$key] = $this->_globalMap[$key];
354
+ }
355
+ if (isset($response[$key]) && isset($this->_importFromRequestFilters[$key])) {
356
+ $callback = $this->_importFromRequestFilters[$key];
357
+ $response[$key] = call_user_func(array($this, $callback), $response[$key], $key, $map[$key]);
358
+ }
359
+ }
360
+ Varien_Object_Mapper::accumulateByMap($response, array($this, 'setDataUsingMethod'), $map);
361
+ }
362
+
363
+ /**
364
+ * Prepare line items request
365
+ *
366
+ * Returns true if there were line items added
367
+ *
368
+ * @param array &$request
369
+ * @param int $i
370
+ * @return true|bool
371
+ */
372
+ protected function _exportLineItems()
373
+ {
374
+ if (!$this->_cart) {
375
+ return;
376
+ }
377
+
378
+ // add cart line items
379
+ $items = $this->_cart->getItems();
380
+ if (empty($items) || !$this->getIsLineItemsEnabled()) {
381
+ return;
382
+ }
383
+ $result = array();
384
+ foreach ($items as $item) {
385
+ $lineItem = new HpsLineItem();
386
+ foreach ($this->_lineItemExportItems as $publicKey) {
387
+ $value = $item->getDataUsingMethod($publicKey);
388
+ switch ($publicKey) {
389
+ case 'id':
390
+ $lineItem->number = $value;
391
+ break;
392
+ case 'qty':
393
+ $lineItem->quantity = $value;
394
+ break;
395
+ default:
396
+ $lineItem->$publicKey = $value;
397
+ break;
398
+ }
399
+ }
400
+ $result[] = $lineItem;
401
+ }
402
+ return $result;
403
+ }
404
+
405
+ /**
406
+ * Prepare shipping options request
407
+ * Returns false if there are no shipping options
408
+ *
409
+ * @param array &$request
410
+ * @param int $i
411
+ * @return bool
412
+ */
413
+ protected function _exportShippingOptions(array &$request, $i = 0)
414
+ {
415
+ $options = $this->getShippingOptions();
416
+ if (empty($options)) {
417
+ return false;
418
+ }
419
+ foreach ($options as $option) {
420
+ foreach ($this->_shippingOptionsExportItemsFormat as $publicKey => $privateFormat) {
421
+ $value = $option->getDataUsingMethod($publicKey);
422
+ if (is_float($value)) {
423
+ $value = $this->_filterAmount($value);
424
+ }
425
+ if (is_bool($value)) {
426
+ $value = $this->_filterBool($value);
427
+ }
428
+ $request[sprintf($privateFormat, $i)] = $value;
429
+ }
430
+ $i++;
431
+ }
432
+ return true;
433
+ }
434
+
435
+ /**
436
+ * Filter amounts in API calls
437
+ * @param float|string $value
438
+ * @return string
439
+ */
440
+ protected function _filterAmount($value)
441
+ {
442
+ return sprintf('%.2F', $value);
443
+ }
444
+
445
+ /**
446
+ * Filter boolean values in API calls
447
+ *
448
+ * @param mixed $value
449
+ * @return string
450
+ */
451
+ protected function _filterBool($value)
452
+ {
453
+ return ($value) ? 'true' : 'false';
454
+ }
455
+
456
+ /**
457
+ * Filter int values in API calls
458
+ *
459
+ * @param mixed $value
460
+ * @return int
461
+ */
462
+ protected function _filterInt($value)
463
+ {
464
+ return (int)$value;
465
+ }
466
+
467
+ /**
468
+ * Unified getter that looks in data or falls back to config
469
+ *
470
+ * @param string $key
471
+ * @param mixed $default
472
+ * @return mixed
473
+ */
474
+ protected function _getDataOrConfig($key, $default = null)
475
+ {
476
+ if ($this->hasData($key)) {
477
+ return $this->getData($key);
478
+ }
479
+ return $this->_config->$key ? $this->_config->$key : $default;
480
+ }
481
+
482
+
483
+ /**
484
+ * region_id workaround: PayPal requires state code, try to find one in the address
485
+ *
486
+ * @param Varien_Object $address
487
+ * @return string
488
+ */
489
+ protected function _lookupRegionCodeFromAddress(Varien_Object $address)
490
+ {
491
+ if ($regionId = $address->getData('region_id')) {
492
+ $region = Mage::getModel('directory/region')->load($regionId);
493
+ if ($region->getId()) {
494
+ return $region->getCode();
495
+ }
496
+ }
497
+ return '';
498
+ }
499
+
500
+ /**
501
+ * Street address workaround: divides address lines into parts by specified keys
502
+ * (keys should go as 3rd, 4th[...] parameters)
503
+ *
504
+ * @param Varien_Object $address
505
+ * @param array $request
506
+ */
507
+ protected function _importStreetFromAddress(Varien_Object $address, array &$to)
508
+ {
509
+ $keys = func_get_args(); array_shift($keys); array_shift($keys);
510
+ $street = $address->getStreet();
511
+ if (!$keys || !$street || !is_array($street)) {
512
+ return;
513
+ }
514
+
515
+ $street = Mage::helper('customer/address')
516
+ ->convertStreetLines($address->getStreet(), count($keys));
517
+
518
+ $i = 0;
519
+ foreach ($keys as $key) {
520
+ $to[$key] = isset($street[$i]) ? $street[$i]: '';
521
+ $i++;
522
+ }
523
+ }
524
+
525
+ /**
526
+ * Build query string from request
527
+ *
528
+ * @param array $request
529
+ * @return string
530
+ */
531
+ protected function _buildQuery($request)
532
+ {
533
+ return http_build_query($request);
534
+ }
535
+
536
+ /**
537
+ * Filter qty in API calls
538
+ * Paypal note: The value for quantity must be a positive integer. Null, zero, or negative numbers are not allowed.
539
+ *
540
+ * @param float|string|int $value
541
+ * @return string
542
+ */
543
+ protected function _filterQty($value)
544
+ {
545
+ return intval($value);
546
+ }
547
+
548
+ /**
549
+ * Log debug data to file
550
+ *
551
+ * @param mixed $debugData
552
+ */
553
+ protected function _debug($debugData)
554
+ {
555
+ if ($this->getDebugFlag()) {
556
+ Mage::getModel('core/log_adapter', 'payment_' . $this->_config->getMethodCode() . '.log')
557
+ ->setFilterDataKeys($this->_debugReplacePrivateDataKeys)
558
+ ->log($debugData);
559
+ }
560
+ }
561
+
562
+ /**
563
+ * Define if debugging is enabled
564
+ *
565
+ * @return bool
566
+ */
567
+ public function getDebugFlag()
568
+ {
569
+ return $this->_config->debug;
570
+ }
571
+
572
+ /**
573
+ * Check whether API certificate authentication should be used
574
+ *
575
+ * @return bool
576
+ */
577
+ public function getUseCertAuthentication()
578
+ {
579
+ return (bool)$this->_config->apiAuthentication;
580
+ }
581
+ }
app/code/community/Hps/Securesubmit/Model/Api/Paypal.php ADDED
@@ -0,0 +1,300 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ require_once Mage::getBaseDir('lib').DS.'SecureSubmit'.DS.'Hps.php';
4
+ /**
5
+ * @category Hps
6
+ * @package Hps_Securesubmit
7
+ * @copyright Copyright (c) 2015 Heartland Payment Systems (https://www.magento.com)
8
+ * @license https://github.com/SecureSubmit/heartland-magento-extension/blob/master/LICENSE Custom License
9
+ */
10
+
11
+ /**
12
+ * NVP API wrappers model
13
+ * @TODO: move some parts to abstract, don't hesitate to throw exceptions on api calls
14
+ */
15
+ class Hps_Securesubmit_Model_Api_Paypal extends Hps_Securesubmit_Model_Api_Abstract
16
+ {
17
+ /**
18
+ * Filter callbacks for preparing internal amounts to NVP request
19
+ *
20
+ * @var array
21
+ */
22
+ protected $_exportToRequestFilters = array(
23
+ 'AMT' => '_filterAmount',
24
+ 'ITEMAMT' => '_filterAmount',
25
+ 'TRIALAMT' => '_filterAmount',
26
+ 'SHIPPINGAMT' => '_filterAmount',
27
+ 'TAXAMT' => '_filterAmount',
28
+ 'INITAMT' => '_filterAmount',
29
+ 'CREDITCARDTYPE' => '_filterCcType',
30
+ 'AUTOBILLAMT' => '_filterBillFailedLater',
31
+ 'BILLINGPERIOD' => '_filterPeriodUnit',
32
+ 'TRIALBILLINGPERIOD' => '_filterPeriodUnit',
33
+ 'FAILEDINITAMTACTION' => '_filterInitialAmountMayFail',
34
+ 'BILLINGAGREEMENTSTATUS' => '_filterBillingAgreementStatus',
35
+ 'NOSHIPPING' => '_filterInt',
36
+ );
37
+
38
+ protected $_importFromRequestFilters = array(
39
+ 'REDIRECTREQUIRED' => '_filterToBool',
40
+ 'SUCCESSPAGEREDIRECTREQUESTED' => '_filterToBool',
41
+ 'PAYMENTSTATUS' => '_filterPaymentStatusFromNvpToInfo',
42
+ );
43
+
44
+ /**
45
+ * SetExpressCheckout request/response map
46
+ * @var array
47
+ */
48
+ protected $_setExpressCheckoutRequest = array(
49
+ 'PAYMENTACTION', 'AMT', 'CURRENCYCODE', 'RETURNURL', 'CANCELURL', 'INVNUM', 'SOLUTIONTYPE', 'NOSHIPPING',
50
+ 'GIROPAYCANCELURL', 'GIROPAYSUCCESSURL', 'BANKTXNPENDINGURL',
51
+ 'PAGESTYLE', 'HDRIMG', 'HDRBORDERCOLOR', 'HDRBACKCOLOR', 'PAYFLOWCOLOR', 'LOCALECODE',
52
+ 'BILLINGTYPE', 'SUBJECT', 'ITEMAMT', 'SHIPPINGAMT', 'TAXAMT', 'REQBILLINGADDRESS',
53
+ 'USERSELECTEDFUNDINGSOURCE'
54
+ );
55
+ protected $_setExpressCheckoutResponse = array('TOKEN');
56
+
57
+ /**
58
+ * GetExpressCheckoutDetails request/response map
59
+ * @var array
60
+ */
61
+ protected $_getExpressCheckoutDetailsRequest = array('TOKEN', 'SUBJECT',);
62
+
63
+ /**
64
+ * Line items export mapping settings
65
+ * @var array
66
+ */
67
+ protected $_lineItemExportItems = array(
68
+ 'id',
69
+ 'name',
70
+ 'qty',
71
+ 'amount',
72
+ );
73
+
74
+ /**
75
+ * SetExpressCheckout call
76
+ * @link https://cms.paypal.com/us/cgi-bin/?&cmd=_render-content&content_ID=developer/e_howto_api_nvp_r_SetExpressCheckout
77
+ * TODO: put together style and giropay settings
78
+ */
79
+ public function callSetExpressCheckout($credit = null)
80
+ {
81
+ $this->_prepareExpressCheckoutCallRequest($this->_setExpressCheckoutRequest);
82
+ $request = $this->_exportToRequest($this->_setExpressCheckoutRequest);
83
+
84
+ $amount = $this->getAmount();
85
+ $currency = $this->getCurrencyCode();
86
+ $totals = $this->_cart->getTotals();
87
+
88
+ $buyer = new HpsBuyerData();
89
+ $buyer->returnUrl = $this->getReturnUrl();
90
+ $buyer->cancelUrl = $this->getCancelUrl();
91
+ $buyer->credit = $credit;
92
+
93
+ $payment = new HpsPaymentData();
94
+ $payment->subtotal = $totals[Mage_Paypal_Model_Cart::TOTAL_SUBTOTAL];
95
+ $payment->shippingAmount = $totals[Mage_Paypal_Model_Cart::TOTAL_SHIPPING];
96
+ $payment->taxAmount = $totals[Mage_Paypal_Model_Cart::TOTAL_TAX];
97
+ $payment->paymentType = (Mage::getStoreConfig('payment/hps_paypal/payment_action') == 'authorize_capture'
98
+ ? 'Sale' : 'Authorization');
99
+
100
+ // import/suppress shipping address, if any
101
+ $options = $this->getShippingOptions();
102
+ $shippingInfo = null;
103
+ if ($this->getAddress()) {
104
+ $a = $this->getAddress();
105
+ $regionModel = Mage::getModel('directory/region')->load($a->getRegionId());
106
+ $shippingInfo = new HpsShippingInfo();
107
+ $shippingInfo->name = $a->getFirstname() . ' ' . $a->getMiddlename() . ' ' . $a->getLastname();
108
+ $shippingInfo->address = new HpsAddress();
109
+ $shippingInfo->address->address = $a->getData('street');
110
+ $shippingInfo->address->city = $a->getCity();
111
+ $shippingInfo->address->state = $regionModel->getCode();
112
+ $shippingInfo->address->zip = $a->getPostcode();
113
+ $shippingInfo->address->country = $a->getCountryId();
114
+
115
+ if ($a->getEmail()) {
116
+ $buyer->emailAddress = $a->getEmail();
117
+ }
118
+ } elseif ($options && (count($options) <= 10)) { // doesn't support more than 10 shipping options
119
+ // $request['CALLBACK'] = $this->getShippingOptionsCallbackUrl();
120
+ // $request['CALLBACKTIMEOUT'] = 6; // max value
121
+ // $request['MAXAMT'] = $request['AMT'] + 999.00; // it is impossible to calculate max amount
122
+ // $this->_exportShippingOptions($request);
123
+ }
124
+
125
+ $lineItems = $this->_exportLineItems();
126
+
127
+ $config = new HpsServicesConfig();
128
+ if (Mage::getStoreConfig('payment/hps_paypal/use_sandbox')) {
129
+ $config->username = Mage::getStoreConfig('payment/hps_paypal/username');
130
+ $config->password = Mage::getStoreConfig('payment/hps_paypal/password');
131
+ $config->deviceId = Mage::getStoreConfig('payment/hps_paypal/device_id');
132
+ $config->licenseId = Mage::getStoreConfig('payment/hps_paypal/license_id');
133
+ $config->siteId = Mage::getStoreConfig('payment/hps_paypal/site_id');
134
+ $config->soapServiceUri = "https://posgateway.secureexchange.net/Hps.Exchange.PosGateway/PosGatewayService.asmx";
135
+ //$config->soapServiceUri = "https://api-uat.heartlandportico.com/paymentserver.v1/PosGatewayService.asmx";
136
+ //$config->soapServiceUri = "https://api-uat.heartlandportico.com/paymentserver.HotFix/POSGatewayService.asmx";
137
+ } else {
138
+ $config->secretApiKey = Mage::getStoreConfig('payment/hps_paypal/secretapikey');
139
+ }
140
+
141
+ $paypalService = new HpsPayPalService($config);
142
+ $response = $paypalService->createSession($amount, $currency, $buyer, $payment, $shippingInfo, $lineItems);
143
+
144
+ $this->token = $response->sessionId;
145
+ return $response;
146
+ }
147
+
148
+ /**
149
+ * GetExpressCheckoutDetails call
150
+ * @link https://cms.paypal.com/us/cgi-bin/?&cmd=_render-content&content_ID=developer/e_howto_api_nvp_r_GetExpressCheckoutDetails
151
+ */
152
+ function callGetExpressCheckoutDetails()
153
+ {
154
+ $this->_prepareExpressCheckoutCallRequest($this->_getExpressCheckoutDetailsRequest);
155
+ $request = $this->_exportToRequest($this->_getExpressCheckoutDetailsRequest);
156
+
157
+ $token = $this->getToken();
158
+
159
+ $config = new HpsServicesConfig();
160
+ if (Mage::getStoreConfig('payment/hps_paypal/use_sandbox')) {
161
+ $config->username = Mage::getStoreConfig('payment/hps_paypal/username');
162
+ $config->password = Mage::getStoreConfig('payment/hps_paypal/password');
163
+ $config->deviceId = Mage::getStoreConfig('payment/hps_paypal/device_id');
164
+ $config->licenseId = Mage::getStoreConfig('payment/hps_paypal/license_id');
165
+ $config->siteId = Mage::getStoreConfig('payment/hps_paypal/site_id');
166
+ $config->soapServiceUri = "https://posgateway.secureexchange.net/Hps.Exchange.PosGateway/PosGatewayService.asmx";
167
+ //$config->soapServiceUri = "https://api-uat.heartlandportico.com/paymentserver.v1/PosGatewayService.asmx";
168
+ //$config->soapServiceUri = "https://api-uat.heartlandportico.com/paymentserver.HotFix/POSGatewayService.asmx";
169
+ } else {
170
+ $config->secretApiKey = Mage::getStoreConfig('payment/hps_paypal/secretapikey');
171
+ }
172
+
173
+ $paypalService = new HpsPayPalService($config);
174
+ $response = $paypalService->sessionInfo($token);
175
+
176
+ return $response;
177
+ }
178
+
179
+ /**
180
+ * Filter for credit card type
181
+ *
182
+ * @param string $value
183
+ * @return string
184
+ */
185
+ protected function _filterCcType($value)
186
+ {
187
+ if (isset($this->_supportedCcTypes[$value])) {
188
+ return $this->_supportedCcTypes[$value];
189
+ }
190
+ return '';
191
+ }
192
+
193
+ /**
194
+ * Filter for true/false values (converts to boolean)
195
+ *
196
+ * @param mixed $value
197
+ * @return mixed
198
+ */
199
+ protected function _filterToBool($value)
200
+ {
201
+ if ('false' === $value || '0' === $value) {
202
+ return false;
203
+ } elseif ('true' === $value || '1' === $value) {
204
+ return true;
205
+ }
206
+ return $value;
207
+ }
208
+
209
+ /**
210
+ * Filter for 'AUTOBILLAMT'
211
+ *
212
+ * @param string $value
213
+ * @return string
214
+ */
215
+ protected function _filterBillFailedLater($value)
216
+ {
217
+ return $value ? 'AddToNextBilling' : 'NoAutoBill';
218
+ }
219
+
220
+ /**
221
+ * Filter for 'BILLINGPERIOD' and 'TRIALBILLINGPERIOD'
222
+ *
223
+ * @param string $value
224
+ * @return string
225
+ */
226
+ protected function _filterPeriodUnit($value)
227
+ {
228
+ switch ($value) {
229
+ case 'day': return 'Day';
230
+ case 'week': return 'Week';
231
+ case 'semi_month': return 'SemiMonth';
232
+ case 'month': return 'Month';
233
+ case 'year': return 'Year';
234
+ }
235
+ }
236
+
237
+ /**
238
+ * Filter for 'FAILEDINITAMTACTION'
239
+ *
240
+ * @param string $value
241
+ * @return string
242
+ */
243
+ protected function _filterInitialAmountMayFail($value)
244
+ {
245
+ return $value ? 'ContinueOnFailure' : 'CancelOnFailure';
246
+ }
247
+
248
+ /**
249
+ * Filter for billing agreement status
250
+ *
251
+ * @param string $value
252
+ * @return string
253
+ */
254
+ protected function _filterBillingAgreementStatus($value)
255
+ {
256
+ switch ($value) {
257
+ case 'canceled': return 'Canceled';
258
+ case 'active': return 'Active';
259
+ }
260
+ }
261
+
262
+ /**
263
+ * Convert payment status from NVP format to paypal/info model format
264
+ *
265
+ * @param string $value
266
+ * @return string|null
267
+ */
268
+ protected function _filterPaymentStatusFromNvpToInfo($value)
269
+ {
270
+ switch ($value) {
271
+ case 'None': return Hps_Securesubmit_Model_Info::PAYMENTSTATUS_NONE;
272
+ case 'Completed': return Hps_Securesubmit_Model_Info::PAYMENTSTATUS_COMPLETED;
273
+ case 'Denied': return Hps_Securesubmit_Model_Info::PAYMENTSTATUS_DENIED;
274
+ case 'Expired': return Hps_Securesubmit_Model_Info::PAYMENTSTATUS_EXPIRED;
275
+ case 'Failed': return Hps_Securesubmit_Model_Info::PAYMENTSTATUS_FAILED;
276
+ case 'In-Progress': return Hps_Securesubmit_Model_Info::PAYMENTSTATUS_INPROGRESS;
277
+ case 'Pending': return Hps_Securesubmit_Model_Info::PAYMENTSTATUS_PENDING;
278
+ case 'Refunded': return Hps_Securesubmit_Model_Info::PAYMENTSTATUS_REFUNDED;
279
+ case 'Partially-Refunded': return Hps_Securesubmit_Model_Info::PAYMENTSTATUS_REFUNDEDPART;
280
+ case 'Reversed': return Hps_Securesubmit_Model_Info::PAYMENTSTATUS_REVERSED;
281
+ case 'Canceled-Reversal': return Hps_Securesubmit_Model_Info::PAYMENTSTATUS_UNREVERSED;
282
+ case 'Processed': return Hps_Securesubmit_Model_Info::PAYMENTSTATUS_PROCESSED;
283
+ case 'Voided': return Hps_Securesubmit_Model_Info::PAYMENTSTATUS_VOIDED;
284
+ }
285
+ }
286
+
287
+ /**
288
+ * Check the EC request against unilateral payments mode and remove the SUBJECT if needed
289
+ *
290
+ * @param &array $requestFields
291
+ */
292
+ protected function _prepareExpressCheckoutCallRequest(&$requestFields)
293
+ {
294
+ if (!$this->_config->shouldUseUnilateralPayments()) {
295
+ if ($key = array_search('SUBJECT', $requestFields)) {
296
+ unset($requestFields[$key]);
297
+ }
298
+ }
299
+ }
300
+ }
app/code/community/Hps/Securesubmit/Model/Config.php ADDED
@@ -0,0 +1,1571 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Hps
4
+ * @package Hps_Securesubmit
5
+ * @copyright Copyright (c) 2015 Heartland Payment Systems (https://www.magento.com)
6
+ * @license https://github.com/SecureSubmit/heartland-magento-extension/blob/master/LICENSE Custom License
7
+ */
8
+
9
+ /**
10
+ * Config model that is aware of all Hps_Securesubmit payment methods
11
+ * Works with PayPal-specific system configuration
12
+ */
13
+ class Hps_Securesubmit_Model_Config
14
+ {
15
+ /**
16
+ * PayPal Standard
17
+ * @var string
18
+ */
19
+ const METHOD_WPS = 'paypal_standard';
20
+
21
+ /**
22
+ * US locale
23
+ */
24
+ const LOCALE_US = 'en_US';
25
+
26
+ /**
27
+ * PayPal Website Payments Pro - Express Checkout
28
+ * @var string
29
+ */
30
+ const METHOD_WPP_EXPRESS = 'paypal_express';
31
+
32
+ /**
33
+ * PayPal Bill Me Later - Express Checkout
34
+ * @var string
35
+ */
36
+ const METHOD_BML = 'paypal_express_bml';
37
+
38
+ /**
39
+ * PayPal Website Payments Pro - Direct Payments
40
+ * @var string
41
+ */
42
+ const METHOD_WPP_DIRECT = 'paypal_direct';
43
+
44
+ /**
45
+ * Direct Payments (Payflow Edition)
46
+ * @var string
47
+ */
48
+ const METHOD_WPP_PE_DIRECT = 'paypaluk_direct';
49
+
50
+ /**
51
+ * PayPal Bill Me Later - Express Checkout (Payflow Edition)
52
+ * @var string
53
+ */
54
+ const METHOD_WPP_PE_BML = 'paypaluk_express_bml';
55
+
56
+ /**
57
+ * Express Checkout (Payflow Edition)
58
+ * @var string
59
+ */
60
+ const METHOD_WPP_PE_EXPRESS = 'paypaluk_express';
61
+
62
+ /**
63
+ * Payflow Pro Gateway
64
+ * @var string
65
+ */
66
+ const METHOD_PAYFLOWPRO = 'verisign';
67
+
68
+ const METHOD_PAYFLOWLINK = 'payflow_link';
69
+ const METHOD_PAYFLOWADVANCED = 'payflow_advanced';
70
+
71
+ const METHOD_HOSTEDPRO = 'hosted_pro';
72
+
73
+ const METHOD_BILLING_AGREEMENT = 'paypal_billing_agreement';
74
+
75
+ /**
76
+ * Buttons and images
77
+ * @var string
78
+ */
79
+ const EC_FLAVOR_DYNAMIC = 'dynamic';
80
+ const EC_FLAVOR_STATIC = 'static';
81
+ const EC_BUTTON_TYPE_SHORTCUT = 'ecshortcut';
82
+ const EC_BUTTON_TYPE_MARK = 'ecmark';
83
+ const PAYMENT_MARK_37x23 = '37x23';
84
+ const PAYMENT_MARK_50x34 = '50x34';
85
+ const PAYMENT_MARK_60x38 = '60x38';
86
+ const PAYMENT_MARK_180x113 = '180x113';
87
+
88
+ const DEFAULT_LOGO_TYPE = 'wePrefer_150x60';
89
+
90
+ /**
91
+ * Payment actions
92
+ * @var string
93
+ */
94
+ const PAYMENT_ACTION_SALE = 'Sale';
95
+ const PAYMENT_ACTION_ORDER = 'Order';
96
+ const PAYMENT_ACTION_AUTH = 'Authorization';
97
+
98
+ /**
99
+ * Authorization amounts for Account Verification
100
+ *
101
+ * @deprecated since 1.6.2.0
102
+ * @var int
103
+ */
104
+ const AUTHORIZATION_AMOUNT_ZERO = 0;
105
+ const AUTHORIZATION_AMOUNT_ONE = 1;
106
+ const AUTHORIZATION_AMOUNT_FULL = 2;
107
+
108
+ /**
109
+ * Require Billing Address
110
+ * @var int
111
+ */
112
+ const REQUIRE_BILLING_ADDRESS_NO = 0;
113
+ const REQUIRE_BILLING_ADDRESS_ALL = 1;
114
+ const REQUIRE_BILLING_ADDRESS_VIRTUAL = 2;
115
+
116
+ /**
117
+ * Fraud management actions
118
+ * @var string
119
+ */
120
+ const FRAUD_ACTION_ACCEPT = 'Acept';
121
+ const FRAUD_ACTION_DENY = 'Deny';
122
+
123
+ /**
124
+ * Refund types
125
+ * @var string
126
+ */
127
+ const REFUND_TYPE_FULL = 'Full';
128
+ const REFUND_TYPE_PARTIAL = 'Partial';
129
+
130
+ /**
131
+ * Express Checkout flows
132
+ * @var string
133
+ */
134
+ const EC_SOLUTION_TYPE_SOLE = 'Sole';
135
+ const EC_SOLUTION_TYPE_MARK = 'Mark';
136
+
137
+ /**
138
+ * Payment data transfer methods (Standard)
139
+ *
140
+ * @var string
141
+ */
142
+ const WPS_TRANSPORT_IPN = 'ipn';
143
+ const WPS_TRANSPORT_PDT = 'pdt';
144
+ const WPS_TRANSPORT_IPN_PDT = 'ipn_n_pdt';
145
+
146
+ /**
147
+ * Billing Agreement Signup
148
+ *
149
+ * @var string
150
+ */
151
+ const EC_BA_SIGNUP_AUTO = 'auto';
152
+ const EC_BA_SIGNUP_ASK = 'ask';
153
+ const EC_BA_SIGNUP_NEVER = 'never';
154
+
155
+ /**
156
+ * Config path for enabling/disabling order review step in express checkout
157
+ */
158
+ const XML_PATH_PAYPAL_EXPRESS_SKIP_ORDER_REVIEW_STEP_FLAG = 'payment/paypal_express/skip_order_review_step';
159
+
160
+ /**
161
+ * Default URL for centinel API (PayPal Direct)
162
+ *
163
+ * @var string
164
+ */
165
+ public $centinelDefaultApiUrl = 'https://paypal.cardinalcommerce.com/maps/txns.asp';
166
+
167
+ /**
168
+ * Current payment method code
169
+ * @var string
170
+ */
171
+ protected $_methodCode = null;
172
+
173
+ /**
174
+ * Current store id
175
+ *
176
+ * @var int
177
+ */
178
+ protected $_storeId = null;
179
+
180
+ /**
181
+ * Instructions for generating proper BN code
182
+ *
183
+ * @var array
184
+ */
185
+ protected $_buildNotationPPMap = array(
186
+ 'paypal_standard' => 'WPS',
187
+ 'paypal_express' => 'EC',
188
+ 'paypal_direct' => 'DP',
189
+ 'paypaluk_express' => 'EC',
190
+ 'paypaluk_direct' => 'DP',
191
+ );
192
+
193
+ /**
194
+ * Style system config map (Express Checkout)
195
+ *
196
+ * @var array
197
+ */
198
+ protected $_ecStyleConfigMap = array(
199
+ 'page_style' => 'page_style',
200
+ 'paypal_hdrimg' => 'hdrimg',
201
+ 'paypal_hdrbordercolor' => 'hdrbordercolor',
202
+ 'paypal_hdrbackcolor' => 'hdrbackcolor',
203
+ 'paypal_payflowcolor' => 'payflowcolor',
204
+ );
205
+
206
+ /**
207
+ * Currency codes supported by PayPal methods
208
+ *
209
+ * @var array
210
+ */
211
+ protected $_supportedCurrencyCodes = array('AUD', 'CAD', 'CZK', 'DKK', 'EUR', 'HKD', 'HUF', 'ILS', 'JPY', 'MXN',
212
+ 'NOK', 'NZD', 'PLN', 'GBP', 'SGD', 'SEK', 'CHF', 'USD', 'TWD', 'THB');
213
+
214
+ /**
215
+ * Merchant country supported by PayPal
216
+ *
217
+ * @var array
218
+ */
219
+ protected $_supportedCountryCodes = array(
220
+ 'AE','AR','AT','AU','BE','BG','BR','CA','CH','CL','CR','CY','CZ','DE','DK','DO','EC','EE','ES','FI','FR','GB',
221
+ 'GF','GI','GP','GR','HK','HU','ID','IE','IL','IN','IS','IT','JM','JP','KR','LI','LT','LU','LV','MQ','MT','MX',
222
+ 'MY','NL','NO','NZ','PH','PL','PT','RE','RO','SE','SG','SI','SK','SM','TH','TR','TW','US','UY','VE','VN','ZA');
223
+
224
+ /**
225
+ * Buyer country supported by PayPal
226
+ *
227
+ * @var array
228
+ */
229
+ protected $_supportedBuyerCountryCodes = array(
230
+ 'AF ', 'AX ', 'AL ', 'DZ ', 'AS ', 'AD ', 'AO ', 'AI ', 'AQ ', 'AG ', 'AR ', 'AM ', 'AW ', 'AU ', 'AT ', 'AZ ',
231
+ 'BS ', 'BH ', 'BD ', 'BB ', 'BY ', 'BE ', 'BZ ', 'BJ ', 'BM ', 'BT ', 'BO ', 'BA ', 'BW ', 'BV ', 'BR ', 'IO ',
232
+ 'BN ', 'BG ', 'BF ', 'BI ', 'KH ', 'CM ', 'CA ', 'CV ', 'KY ', 'CF ', 'TD ', 'CL ', 'CN ', 'CX ', 'CC ', 'CO ',
233
+ 'KM ', 'CG ', 'CD ', 'CK ', 'CR ', 'CI ', 'HR ', 'CU ', 'CY ', 'CZ ', 'DK ', 'DJ ', 'DM ', 'DO ', 'EC ', 'EG ',
234
+ 'SV ', 'GQ ', 'ER ', 'EE ', 'ET ', 'FK ', 'FO ', 'FJ ', 'FI ', 'FR ', 'GF ', 'PF ', 'TF ', 'GA ', 'GM ', 'GE ',
235
+ 'DE ', 'GH ', 'GI ', 'GR ', 'GL ', 'GD ', 'GP ', 'GU ', 'GT ', 'GG ', 'GN ', 'GW ', 'GY ', 'HT ', 'HM ', 'VA ',
236
+ 'HN ', 'HK ', 'HU ', 'IS ', 'IN ', 'ID ', 'IR ', 'IQ ', 'IE ', 'IM ', 'IL ', 'IT ', 'JM ', 'JP ', 'JE ', 'JO ',
237
+ 'KZ ', 'KE ', 'KI ', 'KP ', 'KR ', 'KW ', 'KG ', 'LA ', 'LV ', 'LB ', 'LS ', 'LR ', 'LY ', 'LI ', 'LT ', 'LU ',
238
+ 'MO ', 'MK ', 'MG ', 'MW ', 'MY ', 'MV ', 'ML ', 'MT ', 'MH ', 'MQ ', 'MR ', 'MU ', 'YT ', 'MX ', 'FM ', 'MD ',
239
+ 'MC ', 'MN ', 'MS ', 'MA ', 'MZ ', 'MM ', 'NA ', 'NR ', 'NP ', 'NL ', 'AN ', 'NC ', 'NZ ', 'NI ', 'NE ', 'NG ',
240
+ 'NU ', 'NF ', 'MP ', 'NO ', 'OM ', 'PK ', 'PW ', 'PS ', 'PA ', 'PG ', 'PY ', 'PE ', 'PH ', 'PN ', 'PL ', 'PT ',
241
+ 'PR ', 'QA ', 'RE ', 'RO ', 'RU ', 'RW ', 'SH ', 'KN ', 'LC ', 'PM ', 'VC ', 'WS ', 'SM ', 'ST ', 'SA ', 'SN ',
242
+ 'CS ', 'SC ', 'SL ', 'SG ', 'SK ', 'SI ', 'SB ', 'SO ', 'ZA ', 'GS ', 'ES ', 'LK ', 'SD ', 'SR ', 'SJ ', 'SZ ',
243
+ 'SE ', 'CH ', 'SY ', 'TW ', 'TJ ', 'TZ ', 'TH ', 'TL ', 'TG ', 'TK ', 'TO ', 'TT ', 'TN ', 'TR ', 'TM ', 'TC ',
244
+ 'TV ', 'UG ', 'UA ', 'AE ', 'GB ', 'US ', 'UM ', 'UY ', 'UZ ', 'VU ', 'VE ', 'VN ', 'VG ', 'VI ', 'WF ', 'EH ',
245
+ 'YE ', 'ZM ', 'ZW'
246
+ );
247
+
248
+ /**
249
+ * Locale codes supported by misc images (marks, shortcuts etc)
250
+ *
251
+ * @var array
252
+ * @link https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_ECButtonIntegration#id089QD0O0TX4__id08AH904I0YK
253
+ */
254
+ protected $_supportedImageLocales = array('de_DE', 'en_AU', 'en_GB', self::LOCALE_US,
255
+ 'es_ES', 'es_XC', 'fr_FR', 'fr_XC', 'it_IT', 'ja_JP', 'nl_NL', 'pl_PL', 'zh_CN', 'zh_XC',
256
+ );
257
+
258
+ /**
259
+ * Set method and store id, if specified
260
+ *
261
+ * @param array $params
262
+ */
263
+ public function __construct($params = array())
264
+ {
265
+ if ($params) {
266
+ $method = array_shift($params);
267
+ $this->setMethod($method);
268
+ if ($params) {
269
+ $storeId = array_shift($params);
270
+ $this->setStoreId($storeId);
271
+ }
272
+ }
273
+ }
274
+
275
+ /**
276
+ * Method code setter
277
+ *
278
+ * @param string|Mage_Payment_Model_Method_Abstract $method
279
+ * @return Hps_Securesubmit_Model_Config
280
+ */
281
+ public function setMethod($method)
282
+ {
283
+ if ($method instanceof Mage_Payment_Model_Method_Abstract) {
284
+ $this->_methodCode = $method->getCode();
285
+ } elseif (is_string($method)) {
286
+ $this->_methodCode = $method;
287
+ }
288
+ return $this;
289
+ }
290
+
291
+ /**
292
+ * Payment method instance code getter
293
+ *
294
+ * @return string
295
+ */
296
+ public function getMethodCode()
297
+ {
298
+ return $this->_methodCode;
299
+ }
300
+
301
+ /**
302
+ * Store ID setter
303
+ *
304
+ * @param int $storeId
305
+ * @return Hps_Securesubmit_Model_Config
306
+ */
307
+ public function setStoreId($storeId)
308
+ {
309
+ $this->_storeId = (int)$storeId;
310
+ return $this;
311
+ }
312
+
313
+ /**
314
+ * Check whether method active in configuration and supported for merchant country or not
315
+ *
316
+ * @param string $method Method code
317
+ * @return bool
318
+ */
319
+ public function isMethodActive($method)
320
+ {
321
+ if ($this->isMethodSupportedForCountry($method)
322
+ && Mage::getStoreConfigFlag("payment/{$method}/active", $this->_storeId)
323
+ ) {
324
+ return true;
325
+ }
326
+ return false;
327
+ }
328
+
329
+ /**
330
+ * Check whether method available for checkout or not
331
+ * Logic based on merchant country, methods dependence
332
+ *
333
+ * @param string $method Method code
334
+ * @return bool
335
+ */
336
+ public function isMethodAvailable($methodCode = null)
337
+ {
338
+ if ($methodCode === null) {
339
+ $methodCode = $this->getMethodCode();
340
+ }
341
+
342
+ $result = true;
343
+
344
+ if (!$this->isMethodActive($methodCode)) {
345
+ $result = false;
346
+ }
347
+
348
+ switch ($methodCode) {
349
+ case self::METHOD_WPS:
350
+ if (!$this->businessAccount) {
351
+ $result = false;
352
+ break;
353
+ }
354
+ // check for direct payments dependence
355
+ if ($this->isMethodActive(self::METHOD_WPP_DIRECT)
356
+ || $this->isMethodActive(self::METHOD_WPP_PE_DIRECT)) {
357
+ $result = false;
358
+ }
359
+ break;
360
+ case self::METHOD_WPP_EXPRESS:
361
+ // check for direct payments dependence
362
+ if ($this->isMethodActive(self::METHOD_WPP_PE_DIRECT)) {
363
+ $result = false;
364
+ } elseif ($this->isMethodActive(self::METHOD_WPP_DIRECT)) {
365
+ $result = true;
366
+ }
367
+ break;
368
+ case self::METHOD_BML:
369
+ // check for express payments dependence
370
+ if (!$this->isMethodActive(self::METHOD_WPP_EXPRESS)) {
371
+ $result = false;
372
+ }
373
+ break;
374
+ case self::METHOD_WPP_PE_EXPRESS:
375
+ // check for direct payments dependence
376
+ if ($this->isMethodActive(self::METHOD_WPP_PE_DIRECT)) {
377
+ $result = true;
378
+ } elseif (!$this->isMethodActive(self::METHOD_WPP_PE_DIRECT)
379
+ && !$this->isMethodActive(self::METHOD_PAYFLOWPRO)) {
380
+ $result = false;
381
+ }
382
+ break;
383
+ case self::METHOD_WPP_PE_BML:
384
+ // check for express payments dependence
385
+ if (!$this->isMethodActive(self::METHOD_WPP_PE_EXPRESS)) {
386
+ $result = false;
387
+ }
388
+ break;
389
+ case self::METHOD_BILLING_AGREEMENT:
390
+ $result = $this->isWppApiAvailabe();
391
+ break;
392
+ case self::METHOD_WPP_DIRECT:
393
+ case self::METHOD_WPP_PE_DIRECT:
394
+ break;
395
+ }
396
+ return $result;
397
+ }
398
+
399
+ /**
400
+ * Config field magic getter
401
+ * The specified key can be either in camelCase or under_score format
402
+ * Tries to map specified value according to set payment method code, into the configuration value
403
+ * Sets the values into public class parameters, to avoid redundant calls of this method
404
+ *
405
+ * @param string $key
406
+ * @return string|null
407
+ */
408
+ public function __get($key)
409
+ {
410
+ $underscored = strtolower(preg_replace('/(.)([A-Z])/', "$1_$2", $key));
411
+ $value = Mage::getStoreConfig($this->_getSpecificConfigPath($underscored), $this->_storeId);
412
+ $value = $this->_prepareValue($underscored, $value);
413
+ $this->$key = $value;
414
+ $this->$underscored = $value;
415
+ return $value;
416
+ }
417
+
418
+ /**
419
+ * Perform additional config value preparation and return new value if needed
420
+ *
421
+ * @param string $key Underscored key
422
+ * @param string $value Old value
423
+ * @return string Modified value or old value
424
+ */
425
+ protected function _prepareValue($key, $value)
426
+ {
427
+ // Always set payment action as "Sale" for Unilateral payments in EC
428
+ if ($key == 'payment_action'
429
+ && $value != self::PAYMENT_ACTION_SALE
430
+ && $this->_methodCode == self::METHOD_WPP_EXPRESS
431
+ && $this->shouldUseUnilateralPayments())
432
+ {
433
+ return self::PAYMENT_ACTION_SALE;
434
+ }
435
+ return $value;
436
+ }
437
+
438
+ /**
439
+ * Return merchant country codes supported by PayPal
440
+ *
441
+ * @return array
442
+ */
443
+ public function getSupportedMerchantCountryCodes()
444
+ {
445
+ return $this->_supportedCountryCodes;
446
+ }
447
+
448
+ /**
449
+ * Return buyer country codes supported by PayPal
450
+ *
451
+ * @return array
452
+ */
453
+ public function getSupportedBuyerCountryCodes()
454
+ {
455
+ return $this->_supportedBuyerCountryCodes;
456
+ }
457
+
458
+ /**
459
+ * Return merchant country code, use default country if it not specified in General settings
460
+ *
461
+ * @return string
462
+ */
463
+ public function getMerchantCountry()
464
+ {
465
+ $countryCode = Mage::getStoreConfig($this->_mapGeneralFieldset('merchant_country'), $this->_storeId);
466
+ if (!$countryCode) {
467
+ $countryCode = Mage::helper('core')->getDefaultCountry($this->_storeId);
468
+ }
469
+ return $countryCode;
470
+ }
471
+
472
+ /**
473
+ * Check whether method supported for specified country or not
474
+ * Use $_methodCode and merchant country by default
475
+ *
476
+ * @return bool
477
+ */
478
+ public function isMethodSupportedForCountry($method = null, $countryCode = null)
479
+ {
480
+ if ($method === null) {
481
+ $method = $this->getMethodCode();
482
+ }
483
+ if ($countryCode === null) {
484
+ $countryCode = $this->getMerchantCountry();
485
+ }
486
+ $countryMethods = $this->getCountryMethods($countryCode);
487
+ if (in_array($method, $countryMethods)) {
488
+ return true;
489
+ }
490
+ return false;
491
+ }
492
+
493
+ /**
494
+ * Return list of allowed methods for specified country iso code
495
+ *
496
+ * @param string $countryCode 2-letters iso code
497
+ * @return array
498
+ */
499
+ public function getCountryMethods($countryCode = null)
500
+ {
501
+ $countryMethods = array(
502
+ 'other' => array(
503
+ self::METHOD_WPS,
504
+ self::METHOD_WPP_EXPRESS,
505
+ self::METHOD_BILLING_AGREEMENT,
506
+ ),
507
+ 'US' => array(
508
+ self::METHOD_PAYFLOWADVANCED,
509
+ self::METHOD_WPP_DIRECT,
510
+ self::METHOD_WPS,
511
+ self::METHOD_PAYFLOWPRO,
512
+ self::METHOD_PAYFLOWLINK,
513
+ self::METHOD_WPP_EXPRESS,
514
+ self::METHOD_BML,
515
+ self::METHOD_BILLING_AGREEMENT,
516
+ self::METHOD_WPP_PE_EXPRESS,
517
+ self::METHOD_WPP_PE_BML,
518
+ ),
519
+ 'CA' => array(
520
+ self::METHOD_WPP_DIRECT,
521
+ self::METHOD_WPS,
522
+ self::METHOD_PAYFLOWPRO,
523
+ self::METHOD_PAYFLOWLINK,
524
+ self::METHOD_WPP_EXPRESS,
525
+ self::METHOD_BILLING_AGREEMENT,
526
+ ),
527
+ 'GB' => array(
528
+ self::METHOD_WPP_DIRECT,
529
+ self::METHOD_WPS,
530
+ self::METHOD_WPP_PE_DIRECT,
531
+ self::METHOD_HOSTEDPRO,
532
+ self::METHOD_WPP_EXPRESS,
533
+ self::METHOD_BILLING_AGREEMENT,
534
+ self::METHOD_WPP_PE_EXPRESS,
535
+ ),
536
+ 'AU' => array(
537
+ self::METHOD_WPS,
538
+ self::METHOD_PAYFLOWPRO,
539
+ self::METHOD_HOSTEDPRO,
540
+ self::METHOD_WPP_EXPRESS,
541
+ self::METHOD_BILLING_AGREEMENT,
542
+ ),
543
+ 'NZ' => array(
544
+ self::METHOD_WPS,
545
+ self::METHOD_PAYFLOWPRO,
546
+ self::METHOD_WPP_EXPRESS,
547
+ self::METHOD_BILLING_AGREEMENT,
548
+ ),
549
+ 'JP' => array(
550
+ self::METHOD_WPS,
551
+ self::METHOD_HOSTEDPRO,
552
+ self::METHOD_WPP_EXPRESS,
553
+ self::METHOD_BILLING_AGREEMENT,
554
+ ),
555
+ 'FR' => array(
556
+ self::METHOD_WPS,
557
+ self::METHOD_HOSTEDPRO,
558
+ self::METHOD_WPP_EXPRESS,
559
+ self::METHOD_BILLING_AGREEMENT,
560
+ ),
561
+ 'IT' => array(
562
+ self::METHOD_WPS,
563
+ self::METHOD_HOSTEDPRO,
564
+ self::METHOD_WPP_EXPRESS,
565
+ self::METHOD_BILLING_AGREEMENT,
566
+ ),
567
+ 'ES' => array(
568
+ self::METHOD_WPS,
569
+ self::METHOD_HOSTEDPRO,
570
+ self::METHOD_WPP_EXPRESS,
571
+ self::METHOD_BILLING_AGREEMENT,
572
+ ),
573
+ 'HK' => array(
574
+ self::METHOD_WPS,
575
+ self::METHOD_HOSTEDPRO,
576
+ self::METHOD_WPP_EXPRESS,
577
+ self::METHOD_BILLING_AGREEMENT,
578
+ ),
579
+ );
580
+ if ($countryCode === null) {
581
+ return $countryMethods;
582
+ }
583
+ return isset($countryMethods[$countryCode]) ? $countryMethods[$countryCode] : $countryMethods['other'];
584
+ }
585
+
586
+ /**
587
+ * Return start url for PayPal Basic
588
+ *
589
+ * @param string $token
590
+ * @return string
591
+ */
592
+ public function getPayPalBasicStartUrl($token)
593
+ {
594
+ $params = array(
595
+ 'cmd' => '_express-checkout',
596
+ 'token' => $token,
597
+ );
598
+
599
+ if ($this->isOrderReviewStepDisabled()) {
600
+ $params['useraction'] = 'commit';
601
+ }
602
+
603
+ return $this->getPaypalUrl($params);
604
+ }
605
+
606
+ /**
607
+ * Check whether order review step enabled in configuration
608
+ *
609
+ * @return bool
610
+ */
611
+ public function isOrderReviewStepDisabled()
612
+ {
613
+ return Mage::getStoreConfigFlag(self::XML_PATH_PAYPAL_EXPRESS_SKIP_ORDER_REVIEW_STEP_FLAG);
614
+ }
615
+
616
+ /**
617
+ * Get url for dispatching customer to express checkout start
618
+ *
619
+ * @param string $token
620
+ * @return string
621
+ */
622
+ public function getExpressCheckoutStartUrl($token)
623
+ {
624
+ return $this->getPaypalUrl(array(
625
+ 'cmd' => '_express-checkout',
626
+ 'token' => $token,
627
+ ));
628
+ }
629
+
630
+ /**
631
+ * Get url for dispatching customer to checkout retrial
632
+ *
633
+ * @param string $orderId
634
+ * @return string
635
+ */
636
+ public function getExpressCheckoutOrderUrl($orderId)
637
+ {
638
+ return $this->getPaypalUrl(array(
639
+ 'cmd' => '_express-checkout',
640
+ 'order_id' => $orderId,
641
+ ));
642
+ }
643
+
644
+ /**
645
+ * Get url that allows to edit checkout details on paypal side
646
+ *
647
+ * @param $token
648
+ * @return string
649
+ */
650
+ public function getExpressCheckoutEditUrl($token)
651
+ {
652
+ return $this->getPaypalUrl(array(
653
+ 'cmd' => '_express-checkout',
654
+ 'useraction' => 'continue',
655
+ 'token' => $token,
656
+ ));
657
+ }
658
+
659
+ /**
660
+ * Get url for additional actions that PayPal may require customer to do after placing the order.
661
+ * For instance, redirecting customer to bank for payment confirmation.
662
+ *
663
+ * @param string $token
664
+ * @return string
665
+ */
666
+ public function getExpressCheckoutCompleteUrl($token)
667
+ {
668
+ return $this->getPaypalUrl(array(
669
+ 'cmd' => '_complete-express-checkout',
670
+ 'token' => $token,
671
+ ));
672
+ }
673
+
674
+ /**
675
+ * Retrieve url for initialization of billing agreement
676
+ *
677
+ * @param string $token
678
+ * @return string
679
+ */
680
+ public function getStartBillingAgreementUrl($token)
681
+ {
682
+ return $this->getPaypalUrl(array(
683
+ 'cmd' => '_customer-billing-agreement',
684
+ 'token' => $token,
685
+ ));
686
+ }
687
+
688
+ /**
689
+ * PayPal web URL generic getter
690
+ *
691
+ * @param array $params
692
+ * @return string
693
+ */
694
+ public function getPaypalUrl(array $params = array())
695
+ {
696
+ return sprintf('https://www.%spaypal.com/cgi-bin/webscr%s',
697
+ $this->sandboxFlag ? 'sandbox.' : '',
698
+ $params ? '?' . http_build_query($params) : ''
699
+ );
700
+ }
701
+
702
+ /**
703
+ * Whether Express Checkout button should be rendered dynamically
704
+ *
705
+ * @return bool
706
+ */
707
+ public function areButtonsDynamic()
708
+ {
709
+ return $this->buttonFlavor === self::EC_FLAVOR_DYNAMIC;
710
+ }
711
+
712
+ /**
713
+ * Express checkout shortcut pic URL getter
714
+ * PayPal will ignore "pal", if there is no total amount specified
715
+ *
716
+ * @param string $localeCode
717
+ * @param float $orderTotal
718
+ * @param string $pal encrypted summary about merchant
719
+ * @see Paypal_Model_Api_Nvp::callGetPalDetails()
720
+ */
721
+ public function getExpressCheckoutShortcutImageUrl($localeCode, $orderTotal = null, $pal = null)
722
+ {
723
+ $country = Mage::getStoreConfig(Hps_Securesubmit_Helper_Data::MERCHANT_COUNTRY_CONFIG_PATH);
724
+ if ($country == Hps_Securesubmit_Helper_Data::US_COUNTRY
725
+ && ($this->areButtonsDynamic() || $this->buttonType != self::EC_BUTTON_TYPE_MARK)
726
+ ) {
727
+ return 'https://www.paypalobjects.com/webstatic/en_US/i/buttons/checkout-logo-medium.png';
728
+ }
729
+ if ($this->areButtonsDynamic()) {
730
+ return $this->_getDynamicImageUrl(self::EC_BUTTON_TYPE_SHORTCUT, $localeCode, $orderTotal, $pal);
731
+ }
732
+ if ($this->buttonType === self::EC_BUTTON_TYPE_MARK) {
733
+ return $this->getPaymentMarkImageUrl($localeCode);
734
+ }
735
+ return sprintf('https://www.paypal.com/%s/i/btn/btn_xpressCheckout.gif',
736
+ $this->_getSupportedLocaleCode($localeCode));
737
+ }
738
+
739
+ /**
740
+ * Get PayPal "mark" image URL
741
+ * Supposed to be used on payment methods selection
742
+ * $staticSize is applicable for static images only
743
+ *
744
+ * @param string $localeCode
745
+ * @param float $orderTotal
746
+ * @param string $pal
747
+ * @param string $staticSize
748
+ */
749
+ public function getPaymentMarkImageUrl($localeCode, $orderTotal = null, $pal = null, $staticSize = null)
750
+ {
751
+ $country = Mage::getStoreConfig(Hps_Securesubmit_Helper_Data::MERCHANT_COUNTRY_CONFIG_PATH);
752
+ if ($country == Hps_Securesubmit_Helper_Data::US_COUNTRY) {
753
+ return 'https://www.paypalobjects.com/webstatic/en_US/i/buttons/pp-acceptance-medium.png';
754
+ }
755
+ if ($this->areButtonsDynamic()) {
756
+ return $this->_getDynamicImageUrl(self::EC_BUTTON_TYPE_MARK, $localeCode, $orderTotal, $pal);
757
+ }
758
+
759
+ if (null === $staticSize) {
760
+ $staticSize = $this->paymentMarkSize;
761
+ }
762
+ switch ($staticSize) {
763
+ case self::PAYMENT_MARK_37x23:
764
+ case self::PAYMENT_MARK_50x34:
765
+ case self::PAYMENT_MARK_60x38:
766
+ case self::PAYMENT_MARK_180x113:
767
+ break;
768
+ default:
769
+ $staticSize = self::PAYMENT_MARK_37x23;
770
+ }
771
+ return sprintf('https://www.paypal.com/%s/i/logo/PayPal_mark_%s.gif',
772
+ $this->_getSupportedLocaleCode($localeCode), $staticSize);
773
+ }
774
+
775
+ /**
776
+ * Get "What Is PayPal" localized URL
777
+ * Supposed to be used with "mark" as popup window
778
+ *
779
+ * @param Mage_Core_Model_Locale $locale
780
+ */
781
+ public function getPaymentMarkWhatIsPaypalUrl(Mage_Core_Model_Locale $locale = null)
782
+ {
783
+ $countryCode = 'US';
784
+ if (null !== $locale) {
785
+ $shouldEmulate = (null !== $this->_storeId) && (Mage::app()->getStore()->getId() != $this->_storeId);
786
+ if ($shouldEmulate) {
787
+ $locale->emulate($this->_storeId);
788
+ }
789
+ $countryCode = $locale->getLocale()->getRegion();
790
+ if ($shouldEmulate) {
791
+ $locale->revert();
792
+ }
793
+ }
794
+ return sprintf('https://www.paypal.com/%s/cgi-bin/webscr?cmd=xpt/Marketing/popup/OLCWhatIsPayPal-outside',
795
+ strtolower($countryCode)
796
+ );
797
+ }
798
+
799
+ /**
800
+ * Getter for Solution banner images
801
+ *
802
+ * @param string $localeCode
803
+ * @param bool $isVertical
804
+ * @param bool $isEcheck
805
+ */
806
+ public function getSolutionImageUrl($localeCode, $isVertical = false, $isEcheck = false)
807
+ {
808
+ return sprintf('https://www.paypal.com/%s/i/bnr/%s_solution_PP%s.gif',
809
+ $this->_getSupportedLocaleCode($localeCode),
810
+ $isVertical ? 'vertical' : 'horizontal', $isEcheck ? 'eCheck' : ''
811
+ );
812
+ }
813
+
814
+ /**
815
+ * Getter for Payment form logo images
816
+ *
817
+ * @param string $localeCode
818
+ */
819
+ public function getPaymentFormLogoUrl($localeCode)
820
+ {
821
+ $locale = $this->_getSupportedLocaleCode($localeCode);
822
+
823
+ $imageType = 'logo';
824
+ $domain = 'paypal.com';
825
+ list (,$country) = explode('_', $locale);
826
+ $countryPrefix = $country . '/';
827
+
828
+ switch ($locale) {
829
+ case 'en_GB':
830
+ $imageName = 'horizontal_solution_PP';
831
+ $imageType = 'bnr';
832
+ $countryPrefix = '';
833
+ break;
834
+ case 'de_DE':
835
+ $imageName = 'lockbox_150x47';
836
+ break;
837
+ case 'fr_FR':
838
+ $imageName = 'bnr_horizontal_solution_PP_327wx80h';
839
+ $imageType = 'bnr';
840
+ $locale = self::LOCALE_US;
841
+ $domain = 'paypalobjects.com';
842
+ break;
843
+ case 'it_IT':
844
+ $imageName = 'bnr_horizontal_solution_PP_178wx80h';
845
+ $imageType = 'bnr';
846
+ $domain = 'paypalobjects.com';
847
+ break;
848
+ default:
849
+ $imageName='PayPal_mark_60x38';
850
+ $countryPrefix = '';
851
+ break;
852
+ }
853
+ return sprintf('https://www.%s/%s/%si/%s/%s.gif', $domain, $locale, $countryPrefix, $imageType, $imageName);
854
+ }
855
+
856
+ /**
857
+ * Return supported types for PayPal logo
858
+ *
859
+ * @return array
860
+ */
861
+ public function getAdditionalOptionsLogoTypes()
862
+ {
863
+ return array(
864
+ 'wePrefer_150x60' => Mage::helper('paypal')->__('We prefer PayPal (150 X 60)'),
865
+ 'wePrefer_150x40' => Mage::helper('paypal')->__('We prefer PayPal (150 X 40)'),
866
+ 'nowAccepting_150x60' => Mage::helper('paypal')->__('Now accepting PayPal (150 X 60)'),
867
+ 'nowAccepting_150x40' => Mage::helper('paypal')->__('Now accepting PayPal (150 X 40)'),
868
+ 'paymentsBy_150x60' => Mage::helper('paypal')->__('Payments by PayPal (150 X 60)'),
869
+ 'paymentsBy_150x40' => Mage::helper('paypal')->__('Payments by PayPal (150 X 40)'),
870
+ 'shopNowUsing_150x60' => Mage::helper('paypal')->__('Shop now using (150 X 60)'),
871
+ 'shopNowUsing_150x40' => Mage::helper('paypal')->__('Shop now using (150 X 40)'),
872
+ );
873
+ }
874
+
875
+ /**
876
+ * Return PayPal logo URL with additional options
877
+ *
878
+ * @param string $localeCode Supported locale code
879
+ * @param string $type One of supported logo types
880
+ * @return string|bool Logo Image URL or false if logo disabled in configuration
881
+ */
882
+ public function getAdditionalOptionsLogoUrl($localeCode, $type = false)
883
+ {
884
+ $configType = Mage::getStoreConfig($this->_mapGenericStyleFieldset('logo'), $this->_storeId);
885
+ if (!$configType) {
886
+ return false;
887
+ }
888
+ $type = $type ? $type : $configType;
889
+ $locale = $this->_getSupportedLocaleCode($localeCode);
890
+ $supportedTypes = array_keys($this->getAdditionalOptionsLogoTypes());
891
+ if (!in_array($type, $supportedTypes)) {
892
+ $type = self::DEFAULT_LOGO_TYPE;
893
+ }
894
+ return sprintf('https://www.paypalobjects.com/%s/i/bnr/bnr_%s.gif', $locale, $type);
895
+ }
896
+
897
+ /**
898
+ * BN code getter
899
+ *
900
+ * @return mixed
901
+ */
902
+ public function getBuildNotationCode()
903
+ {
904
+ return Mage::getStoreConfig("paypal/bncode", $this->_storeId);
905
+ }
906
+
907
+ /**
908
+ * Express Checkout button "flavors" source getter
909
+ *
910
+ * @return array
911
+ */
912
+ public function getExpressCheckoutButtonFlavors()
913
+ {
914
+ return array(
915
+ self::EC_FLAVOR_DYNAMIC => Mage::helper('paypal')->__('Dynamic'),
916
+ self::EC_FLAVOR_STATIC => Mage::helper('paypal')->__('Static'),
917
+ );
918
+ }
919
+
920
+ /**
921
+ * Express Checkout button types source getter
922
+ *
923
+ * @return array
924
+ */
925
+ public function getExpressCheckoutButtonTypes()
926
+ {
927
+ return array(
928
+ self::EC_BUTTON_TYPE_SHORTCUT => Mage::helper('paypal')->__('Shortcut'),
929
+ self::EC_BUTTON_TYPE_MARK => Mage::helper('paypal')->__('Acceptance Mark Image'),
930
+ );
931
+ }
932
+
933
+ /**
934
+ * Payment actions source getter
935
+ *
936
+ * @return array
937
+ */
938
+ public function getPaymentActions()
939
+ {
940
+ $paymentActions = array(
941
+ self::PAYMENT_ACTION_AUTH => Mage::helper('paypal')->__('Authorization'),
942
+ self::PAYMENT_ACTION_SALE => Mage::helper('paypal')->__('Sale')
943
+ );
944
+ if (!is_null($this->_methodCode) && $this->_methodCode == self::METHOD_WPP_EXPRESS) {
945
+ $paymentActions[self::PAYMENT_ACTION_ORDER] = Mage::helper('paypal')->__('Order');
946
+ }
947
+ return $paymentActions;
948
+ }
949
+
950
+ /**
951
+ * Require Billing Address source getter
952
+ *
953
+ * @return array
954
+ */
955
+ public function getRequireBillingAddressOptions()
956
+ {
957
+ return array(
958
+ self::REQUIRE_BILLING_ADDRESS_ALL => Mage::helper('paypal')->__('Yes'),
959
+ self::REQUIRE_BILLING_ADDRESS_NO => Mage::helper('paypal')->__('No'),
960
+ self::REQUIRE_BILLING_ADDRESS_VIRTUAL => Mage::helper('paypal')->__('For Virtual Quotes Only'),
961
+ );
962
+ }
963
+
964
+ /**
965
+ * Mapper from PayPal-specific payment actions to Magento payment actions
966
+ *
967
+ * @return string|null
968
+ */
969
+ public function getPaymentAction()
970
+ {
971
+ switch ($this->paymentAction) {
972
+ case self::PAYMENT_ACTION_AUTH:
973
+ return Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE;
974
+ case self::PAYMENT_ACTION_SALE:
975
+ return Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE_CAPTURE;
976
+ case self::PAYMENT_ACTION_ORDER:
977
+ return Mage_Payment_Model_Method_Abstract::ACTION_ORDER;
978
+ }
979
+ }
980
+
981
+ /**
982
+ * Returns array of possible Authorization Amounts for Account Verification
983
+ *
984
+ * @deprecated since 1.6.2.0
985
+ * @return array
986
+ */
987
+ public function getAuthorizationAmounts()
988
+ {
989
+ return array();
990
+ }
991
+
992
+ /**
993
+ * Express Checkout "solution types" source getter
994
+ * "sole" = "Express Checkout for Auctions" - PayPal allows guest checkout
995
+ * "mark" = "Normal Express Checkout" - PayPal requires to checkout with PayPal buyer account only
996
+ *
997
+ * @return array
998
+ */
999
+ public function getExpressCheckoutSolutionTypes()
1000
+ {
1001
+ return array(
1002
+ self::EC_SOLUTION_TYPE_SOLE => Mage::helper('paypal')->__('Yes'),
1003
+ self::EC_SOLUTION_TYPE_MARK => Mage::helper('paypal')->__('No'),
1004
+ );
1005
+ }
1006
+
1007
+ /**
1008
+ * Retrieve express checkout billing agreement signup options
1009
+ *
1010
+ * @return array
1011
+ */
1012
+ public function getExpressCheckoutBASignupOptions()
1013
+ {
1014
+ return array(
1015
+ self::EC_BA_SIGNUP_AUTO => Mage::helper('paypal')->__('Auto'),
1016
+ self::EC_BA_SIGNUP_ASK => Mage::helper('paypal')->__('Ask Customer'),
1017
+ self::EC_BA_SIGNUP_NEVER => Mage::helper('paypal')->__('Never')
1018
+ );
1019
+ }
1020
+
1021
+ /**
1022
+ * Whether to ask customer to create billing agreements
1023
+ * Unilateral payments are incompatible with the billing agreements
1024
+ *
1025
+ * @return bool
1026
+ */
1027
+ public function shouldAskToCreateBillingAgreement()
1028
+ {
1029
+ return ($this->allow_ba_signup === self::EC_BA_SIGNUP_ASK) && !$this->shouldUseUnilateralPayments();
1030
+ }
1031
+
1032
+ /**
1033
+ * Check whether only Unilateral payments (Accelerated Boarding) possible for Express method or not
1034
+ *
1035
+ * @return bool
1036
+ */
1037
+ public function shouldUseUnilateralPayments()
1038
+ {
1039
+ return $this->business_account && !$this->isWppApiAvailabe();
1040
+ }
1041
+
1042
+ /**
1043
+ * Check whether WPP API credentials are available for this method
1044
+ *
1045
+ * @return bool
1046
+ */
1047
+ public function isWppApiAvailabe()
1048
+ {
1049
+ return $this->api_username && $this->api_password && ($this->api_signature || $this->api_cert);
1050
+ }
1051
+
1052
+ /**
1053
+ * Payment data delivery methods getter for PayPal Standard
1054
+ *
1055
+ * @return array
1056
+ */
1057
+ public function getWpsPaymentDeliveryMethods()
1058
+ {
1059
+ return array(
1060
+ self::WPS_TRANSPORT_IPN => Mage::helper('adminhtml')->__('IPN (Instant Payment Notification) Only'),
1061
+ // not supported yet:
1062
+ // self::WPS_TRANSPORT_PDT => Mage::helper('adminhtml')->__('PDT (Payment Data Transfer) Only'),
1063
+ // self::WPS_TRANSPORT_IPN_PDT => Mage::helper('adminhtml')->__('Both IPN and PDT'),
1064
+ );
1065
+ }
1066
+
1067
+ /**
1068
+ * Return list of supported credit card types by Paypal Direct gateway
1069
+ *
1070
+ * @return array
1071
+ */
1072
+ public function getWppCcTypesAsOptionArray()
1073
+ {
1074
+ $model = Mage::getModel('payment/source_cctype')->setAllowedTypes(array('AE', 'VI', 'MC', 'SM', 'SO', 'DI'));
1075
+ return $model->toOptionArray();
1076
+ }
1077
+
1078
+ /**
1079
+ * Return list of supported credit card types by Paypal Direct (Payflow Edition) gateway
1080
+ *
1081
+ * @return array
1082
+ */
1083
+ public function getWppPeCcTypesAsOptionArray()
1084
+ {
1085
+ $model = Mage::getModel('payment/source_cctype')->setAllowedTypes(array('VI', 'MC', 'SM', 'SO', 'OT', 'AE'));
1086
+ return $model->toOptionArray();
1087
+ }
1088
+
1089
+ /**
1090
+ * Return list of supported credit card types by Payflow Pro gateway
1091
+ *
1092
+ * @return array
1093
+ */
1094
+ public function getPayflowproCcTypesAsOptionArray()
1095
+ {
1096
+ $model = Mage::getModel('payment/source_cctype')->setAllowedTypes(array('AE', 'VI', 'MC', 'JCB', 'DI'));
1097
+ return $model->toOptionArray();
1098
+ }
1099
+
1100
+ /**
1101
+ * Check whether the specified payment method is a CC-based one
1102
+ *
1103
+ * @param string $code
1104
+ * @return bool
1105
+ */
1106
+ public static function getIsCreditCardMethod($code)
1107
+ {
1108
+ switch ($code) {
1109
+ case self::METHOD_WPP_DIRECT:
1110
+ case self::METHOD_WPP_PE_DIRECT:
1111
+ case self::METHOD_PAYFLOWPRO:
1112
+ case self::METHOD_PAYFLOWLINK:
1113
+ case self::METHOD_PAYFLOWADVANCED:
1114
+ case self::METHOD_HOSTEDPRO:
1115
+ return true;
1116
+ }
1117
+ return false;
1118
+ }
1119
+
1120
+ /**
1121
+ * Check whether specified currency code is supported
1122
+ *
1123
+ * @param string $code
1124
+ * @return bool
1125
+ */
1126
+ public function isCurrencyCodeSupported($code)
1127
+ {
1128
+ if (in_array($code, $this->_supportedCurrencyCodes)) {
1129
+ return true;
1130
+ }
1131
+ if ($this->getMerchantCountry() == 'BR' && $code == 'BRL') {
1132
+ return true;
1133
+ }
1134
+ if ($this->getMerchantCountry() == 'MY' && $code == 'MYR') {
1135
+ return true;
1136
+ }
1137
+ return false;
1138
+ }
1139
+
1140
+ /**
1141
+ * Export page style current settings to specified object
1142
+ *
1143
+ * @param Varien_Object $to
1144
+ */
1145
+ public function exportExpressCheckoutStyleSettings(Varien_Object $to)
1146
+ {
1147
+ foreach ($this->_ecStyleConfigMap as $key => $exportKey) {
1148
+ if ($this->$key) {
1149
+ $to->setData($exportKey, $this->$key);
1150
+ }
1151
+ }
1152
+ }
1153
+
1154
+ /**
1155
+ * Dynamic PayPal image URL getter
1156
+ * Also can render dynamic Acceptance Mark
1157
+ *
1158
+ * @param string $type
1159
+ * @param string $localeCode
1160
+ * @param float $orderTotal
1161
+ * @param string $pal
1162
+ */
1163
+ protected function _getDynamicImageUrl($type, $localeCode, $orderTotal, $pal)
1164
+ {
1165
+ $params = array(
1166
+ 'cmd' => '_dynamic-image',
1167
+ 'buttontype' => $type,
1168
+ 'locale' => $this->_getSupportedLocaleCode($localeCode),
1169
+ );
1170
+ if ($orderTotal) {
1171
+ $params['ordertotal'] = sprintf('%.2F', $orderTotal);
1172
+ if ($pal) {
1173
+ $params['pal'] = $pal;
1174
+ }
1175
+ }
1176
+ return sprintf('https://fpdbs%s.paypal.com/dynamicimageweb?%s',
1177
+ $this->sandboxFlag ? '.sandbox' : '', http_build_query($params)
1178
+ );
1179
+ }
1180
+
1181
+ /**
1182
+ * Check whether specified locale code is supported. Fallback to en_US
1183
+ *
1184
+ * @param string $localeCode
1185
+ * @return string
1186
+ */
1187
+ protected function _getSupportedLocaleCode($localeCode = null)
1188
+ {
1189
+ if (!$localeCode || !in_array($localeCode, $this->_supportedImageLocales)) {
1190
+ return self::LOCALE_US;
1191
+ }
1192
+ return $localeCode;
1193
+ }
1194
+
1195
+ /**
1196
+ * Map any supported payment method into a config path by specified field name
1197
+ *
1198
+ * @param string $fieldName
1199
+ * @return string|null
1200
+ */
1201
+ protected function _getSpecificConfigPath($fieldName)
1202
+ {
1203
+ $path = null;
1204
+ switch ($this->_methodCode) {
1205
+ case self::METHOD_WPS:
1206
+ $path = $this->_mapStandardFieldset($fieldName);
1207
+ break;
1208
+ case self::METHOD_BML:
1209
+ $path = $this->_mapBmlFieldset($fieldName);
1210
+ break;
1211
+ case self::METHOD_WPP_PE_BML:
1212
+ $path = $this->_mapBmlUkFieldset($fieldName);
1213
+ break;
1214
+ case self::METHOD_WPP_EXPRESS:
1215
+ case self::METHOD_WPP_PE_EXPRESS:
1216
+ $path = $this->_mapExpressFieldset($fieldName);
1217
+ break;
1218
+ case self::METHOD_WPP_DIRECT:
1219
+ case self::METHOD_WPP_PE_DIRECT:
1220
+ $path = $this->_mapDirectFieldset($fieldName);
1221
+ break;
1222
+ case self::METHOD_BILLING_AGREEMENT:
1223
+ case self::METHOD_HOSTEDPRO:
1224
+ $path = $this->_mapMethodFieldset($fieldName);
1225
+ break;
1226
+ }
1227
+
1228
+ if ($path === null) {
1229
+ switch ($this->_methodCode) {
1230
+ case self::METHOD_WPP_EXPRESS:
1231
+ case self::METHOD_BML:
1232
+ case self::METHOD_WPP_DIRECT:
1233
+ case self::METHOD_BILLING_AGREEMENT:
1234
+ case self::METHOD_HOSTEDPRO:
1235
+ $path = $this->_mapWppFieldset($fieldName);
1236
+ break;
1237
+ case self::METHOD_WPP_PE_EXPRESS:
1238
+ case self::METHOD_WPP_PE_DIRECT:
1239
+ case self::METHOD_PAYFLOWADVANCED:
1240
+ case self::METHOD_PAYFLOWLINK:
1241
+ $path = $this->_mapWpukFieldset($fieldName);
1242
+ break;
1243
+ }
1244
+ }
1245
+
1246
+ if ($path === null) {
1247
+ $path = $this->_mapGeneralFieldset($fieldName);
1248
+ }
1249
+ if ($path === null) {
1250
+ $path = $this->_mapGenericStyleFieldset($fieldName);
1251
+ }
1252
+ return $path;
1253
+ }
1254
+
1255
+ /**
1256
+ * Check wheter specified country code is supported by build notation codes for specific countries
1257
+ *
1258
+ * @param $code
1259
+ * @return string|null
1260
+ */
1261
+ private function _matchBnCountryCode($code)
1262
+ {
1263
+ switch ($code) {
1264
+ // GB == UK
1265
+ case 'GB':
1266
+ return 'UK';
1267
+ // Australia, Austria, Belgium, Canada, China, France, Germany, Hong Kong, Italy
1268
+ case 'AU': case 'AT': case 'BE': case 'CA': case 'CN': case 'FR': case 'DE': case 'HK': case 'IT':
1269
+ // Japan, Mexico, Netherlands, Poland, Singapore, Spain, Switzerland, United Kingdom, United States
1270
+ case 'JP': case 'MX': case 'NL': case 'PL': case 'SG': case 'ES': case 'CH': case 'UK': case 'US':
1271
+ return $code;
1272
+ }
1273
+ }
1274
+
1275
+ /**
1276
+ * Map PayPal Standard config fields
1277
+ *
1278
+ * @param string $fieldName
1279
+ * @return string|null
1280
+ */
1281
+ protected function _mapStandardFieldset($fieldName)
1282
+ {
1283
+ switch ($fieldName)
1284
+ {
1285
+ case 'line_items_summary':
1286
+ case 'sandbox_flag':
1287
+ return 'payment/' . self::METHOD_WPS . "/{$fieldName}";
1288
+ default:
1289
+ return $this->_mapMethodFieldset($fieldName);
1290
+ }
1291
+ }
1292
+
1293
+ /**
1294
+ * Map PayPal Express config fields
1295
+ *
1296
+ * @param string $fieldName
1297
+ * @return string|null
1298
+ */
1299
+ protected function _mapExpressFieldset($fieldName)
1300
+ {
1301
+ switch ($fieldName)
1302
+ {
1303
+ case 'transfer_shipping_options':
1304
+ case 'solution_type':
1305
+ case 'visible_on_cart':
1306
+ case 'visible_on_product':
1307
+ case 'require_billing_address':
1308
+ case 'authorization_honor_period':
1309
+ case 'order_valid_period':
1310
+ case 'child_authorization_number':
1311
+ case 'allow_ba_signup':
1312
+ return "payment/{$this->_methodCode}/{$fieldName}";
1313
+ default:
1314
+ return $this->_mapMethodFieldset($fieldName);
1315
+ }
1316
+ }
1317
+
1318
+ /**
1319
+ * Map PayPal Express Bill Me Later config fields
1320
+ *
1321
+ * @param string $fieldName
1322
+ * @return string|null
1323
+ */
1324
+ protected function _mapBmlFieldset($fieldName)
1325
+ {
1326
+ switch ($fieldName)
1327
+ {
1328
+ case 'allow_ba_signup':
1329
+ return "payment/" . self::METHOD_WPP_EXPRESS . "/{$fieldName}";
1330
+ default:
1331
+ return $this->_mapExpressFieldset($fieldName);
1332
+ }
1333
+ }
1334
+
1335
+ /**
1336
+ * Map PayPal Express Bill Me Later config fields (Payflow Edition)
1337
+ *
1338
+ * @param string $fieldName
1339
+ * @return string|null
1340
+ */
1341
+ protected function _mapBmlUkFieldset($fieldName)
1342
+ {
1343
+ switch ($fieldName)
1344
+ {
1345
+ case 'allow_ba_signup':
1346
+ return "payment/" . self::METHOD_WPP_PE_EXPRESS . "/{$fieldName}";
1347
+ default:
1348
+ return $this->_mapExpressFieldset($fieldName);
1349
+ }
1350
+ }
1351
+
1352
+ /**
1353
+ * Map PayPal Direct config fields
1354
+ *
1355
+ * @param string $fieldName
1356
+ * @return string|null
1357
+ */
1358
+ protected function _mapDirectFieldset($fieldName)
1359
+ {
1360
+ switch ($fieldName)
1361
+ {
1362
+ case 'useccv':
1363
+ case 'centinel':
1364
+ case 'centinel_is_mode_strict':
1365
+ case 'centinel_api_url':
1366
+ return "payment/{$this->_methodCode}/{$fieldName}";
1367
+ default:
1368
+ return $this->_mapMethodFieldset($fieldName);
1369
+ }
1370
+ }
1371
+
1372
+ /**
1373
+ * Map PayPal Website Payments Pro common config fields
1374
+ *
1375
+ * @param string $fieldName
1376
+ * @return string|null
1377
+ */
1378
+ protected function _mapWppFieldset($fieldName)
1379
+ {
1380
+ switch ($fieldName)
1381
+ {
1382
+ case 'api_authentication':
1383
+ case 'api_username':
1384
+ case 'api_password':
1385
+ case 'api_signature':
1386
+ case 'api_cert':
1387
+ case 'sandbox_flag':
1388
+ case 'use_proxy':
1389
+ case 'proxy_host':
1390
+ case 'proxy_port':
1391
+ case 'button_flavor':
1392
+ return "paypal/wpp/{$fieldName}";
1393
+ default:
1394
+ return null;
1395
+ }
1396
+ }
1397
+
1398
+ /**
1399
+ * Map PayPal Website Payments Pro common config fields
1400
+ *
1401
+ * @param string $fieldName
1402
+ * @return string|null
1403
+ */
1404
+ protected function _mapWpukFieldset($fieldName)
1405
+ {
1406
+ $pathPrefix = 'paypal/wpuk';
1407
+ // Use PUMP credentials from Verisign for EC when Direct Payments are unavailable
1408
+ if ($this->_methodCode == self::METHOD_WPP_PE_EXPRESS
1409
+ && !$this->isMethodAvailable(self::METHOD_WPP_PE_DIRECT)) {
1410
+ $pathPrefix = 'payment/verisign';
1411
+ } elseif ($this->_methodCode == self::METHOD_PAYFLOWADVANCED
1412
+ || $this->_methodCode == self::METHOD_PAYFLOWLINK
1413
+ ) {
1414
+ $pathPrefix = 'payment/' . $this->_methodCode;
1415
+ }
1416
+ switch ($fieldName) {
1417
+ case 'partner':
1418
+ case 'user':
1419
+ case 'vendor':
1420
+ case 'pwd':
1421
+ case 'sandbox_flag':
1422
+ case 'use_proxy':
1423
+ case 'proxy_host':
1424
+ case 'proxy_port':
1425
+ return $pathPrefix . '/' . $fieldName;
1426
+ default:
1427
+ return null;
1428
+ }
1429
+ }
1430
+
1431
+ /**
1432
+ * Map PayPal common style config fields
1433
+ *
1434
+ * @param string $fieldName
1435
+ * @return string|null
1436
+ */
1437
+ protected function _mapGenericStyleFieldset($fieldName)
1438
+ {
1439
+ switch ($fieldName) {
1440
+ case 'logo':
1441
+ case 'page_style':
1442
+ case 'paypal_hdrimg':
1443
+ case 'paypal_hdrbackcolor':
1444
+ case 'paypal_hdrbordercolor':
1445
+ case 'paypal_payflowcolor':
1446
+ return "paypal/style/{$fieldName}";
1447
+ default:
1448
+ return null;
1449
+ }
1450
+ }
1451
+
1452
+ /**
1453
+ * Map PayPal General Settings
1454
+ *
1455
+ * @param string $fieldName
1456
+ * @return string|null
1457
+ */
1458
+ protected function _mapGeneralFieldset($fieldName)
1459
+ {
1460
+ switch ($fieldName)
1461
+ {
1462
+ case 'business_account':
1463
+ case 'merchant_country':
1464
+ return "paypal/general/{$fieldName}";
1465
+ default:
1466
+ return null;
1467
+ }
1468
+ }
1469
+
1470
+ /**
1471
+ * Map PayPal General Settings
1472
+ *
1473
+ * @param string $fieldName
1474
+ * @return string|null
1475
+ */
1476
+ protected function _mapMethodFieldset($fieldName)
1477
+ {
1478
+ if (!$this->_methodCode) {
1479
+ return null;
1480
+ }
1481
+ switch ($fieldName)
1482
+ {
1483
+ case 'active':
1484
+ case 'title':
1485
+ case 'payment_action':
1486
+ case 'allowspecific':
1487
+ case 'specificcountry':
1488
+ case 'line_items_enabled':
1489
+ case 'cctypes':
1490
+ case 'sort_order':
1491
+ case 'debug':
1492
+ case 'verify_peer':
1493
+ case 'mobile_optimized':
1494
+ return "payment/{$this->_methodCode}/{$fieldName}";
1495
+ default:
1496
+ return null;
1497
+ }
1498
+ }
1499
+
1500
+ /**
1501
+ * Payment API authentication methods source getter
1502
+ *
1503
+ * @return array
1504
+ */
1505
+ public function getApiAuthenticationMethods()
1506
+ {
1507
+ return array(
1508
+ '0' => Mage::helper('paypal')->__('API Signature'),
1509
+ '1' => Mage::helper('paypal')->__('API Certificate')
1510
+ );
1511
+ }
1512
+
1513
+ /**
1514
+ * Api certificate getter
1515
+ *
1516
+ * @return string
1517
+ */
1518
+ public function getApiCertificate()
1519
+ {
1520
+ $websiteId = Mage::app()->getStore($this->_storeId)->getWebsiteId();
1521
+ return Mage::getModel('paypal/cert')->loadByWebsite($websiteId, false)->getCertPath();
1522
+ }
1523
+
1524
+
1525
+ /**
1526
+ * Get PublisherId from stored config
1527
+ *
1528
+ * @return mixed
1529
+ */
1530
+ public function getBmlPublisherId()
1531
+ {
1532
+ return Mage::getStoreConfig('payment/paypal_express_bml/publisher_id', $this->_storeId);
1533
+ }
1534
+
1535
+ /**
1536
+ * Get Display option from stored config
1537
+ * @param $section
1538
+ *
1539
+ * @return mixed
1540
+ */
1541
+ public function getBmlDisplay($section)
1542
+ {
1543
+ // $display = Mage::getStoreConfig('payment/paypal_express_bml/'.$section.'_display', $this->_storeId);
1544
+ $ecActive = Mage::getStoreConfig('payment/hps_paypal/active', $this->_storeId);
1545
+ $bmlActive = Mage::getStoreConfig('payment/hps_paypal_credit/active', $this->_storeId);
1546
+ return ($bmlActive && $ecActive); // ? $display : 0;
1547
+ }
1548
+
1549
+ /**
1550
+ * Get Position option from stored config
1551
+ * @param $section
1552
+ *
1553
+ * @return mixed
1554
+ */
1555
+ public function getBmlPosition($section)
1556
+ {
1557
+ return Mage::getStoreConfig('payment/paypal_express_bml/'.$section.'_position', $this->_storeId);
1558
+ }
1559
+
1560
+ /**
1561
+ * Get Size option from stored config
1562
+ * @param $section
1563
+ *
1564
+ * @return mixed
1565
+ */
1566
+ public function getBmlSize($section)
1567
+ {
1568
+ return Mage::getStoreConfig('payment/paypal_express_bml/'.$section.'_size', $this->_storeId);
1569
+ }
1570
+ }
1571
+
app/code/community/Hps/Securesubmit/Model/Paypal.php ADDED
@@ -0,0 +1,415 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ require_once Mage::getBaseDir('lib').DS.'SecureSubmit'.DS.'Hps.php';
4
+ /**
5
+ * @category Hps
6
+ * @package Hps_Securesubmit
7
+ * @copyright Copyright (c) 2015 Heartland Payment Systems (https://www.magento.com)
8
+ * @license https://github.com/SecureSubmit/heartland-magento-extension/blob/master/LICENSE Custom License
9
+ */
10
+
11
+ class Hps_Securesubmit_Model_Paypal extends Mage_Payment_Model_Method_Cc
12
+ {
13
+ protected $_code = 'hps_paypal';
14
+ protected $_isGateway = true;
15
+ protected $_canCapture = true;
16
+ protected $_canCapturePartial = true;
17
+ protected $_canRefund = true;
18
+ protected $_canRefundInvoicePartial = true;
19
+ protected $_canVoid = true;
20
+ protected $_canAuthorize = true;
21
+
22
+ protected $_supportedCurrencyCodes = array('USD');
23
+ protected $_minOrderTotal = 0.5;
24
+
25
+ protected $_formBlockType = 'hps_securesubmit/paypal_form';
26
+ protected $_infoBlockType = 'hps_securesubmit/paypal_info';
27
+
28
+ /**
29
+ * Fields that should be replaced in debug with '***'
30
+ *
31
+ * @var array
32
+ */
33
+ protected $_debugReplacePrivateDataKeys = array('SecretAPIKey');
34
+
35
+ public function validate()
36
+ {
37
+ $info = $this->getInfoInstance();
38
+ $additionalData = new Varien_Object($info->getAdditionalData() ? unserialize($info->getAdditionalData()) : null);
39
+
40
+ // Only validate when not using token
41
+ if ($additionalData->getUseCreditCard()) {
42
+ parent::validate();
43
+ }
44
+
45
+ return $this;
46
+ }
47
+
48
+ /**
49
+ * Capture payment
50
+ *
51
+ * @param Varien_Object $payment
52
+ * @param float $amount
53
+ * @return $this
54
+ */
55
+ public function capture(Varien_Object $payment, $amount)
56
+ {
57
+ $this->_authorize($payment, $amount, true);
58
+ }
59
+
60
+ /**
61
+ * Authorize payment
62
+ *
63
+ * @param Varien_Object $payment
64
+ * @param float $amount
65
+ * @return $this
66
+ */
67
+ public function authorize(Varien_Object $payment, $amount)
68
+ {
69
+ $this->_authorize($payment, $amount, false);
70
+ }
71
+
72
+ /**
73
+ * Authorize or Capture payment
74
+ *
75
+ * @param Varien_Object $payment
76
+ * @param float $amount
77
+ * @param bool $capture
78
+ * @return $this
79
+ */
80
+ private function _authorize(Varien_Object $payment, $amount, $capture)
81
+ {
82
+ $order = $payment->getOrder(); /* @var $order Mage_Sales_Model_Order */
83
+ $billing = $order->getBillingAddress();
84
+ $shipping = $order->getShippingAddress();
85
+ $multiToken = false;
86
+ $cardData = null;
87
+ $cardType = null;
88
+ $additionalData = new Varien_Object($payment->getAdditionalData() ? unserialize($payment->getAdditionalData()) : null);
89
+ $secureToken = $additionalData->getSecuresubmitToken() ? $additionalData->getSecuresubmitToken() : null;
90
+ $saveCreditCard = !! (bool)$additionalData->getCcSaveFuture();
91
+ $useCreditCard = !! (bool)$additionalData->getUseCreditCard();
92
+ $token = Mage::getSingleton('hps_securesubmit/session')->getPayPalCheckoutToken();
93
+ $payerId = Mage::getSingleton('hps_securesubmit/session')->getPayPalPayerId();
94
+
95
+ if ($saveCreditCard && ! $useCreditCard) {
96
+ $multiToken = true;
97
+ $cardData = new HpsCreditCard();
98
+ $cardData->number = $payment->getCcLast4();
99
+ $cardData->expYear = $payment->getCcExpYear();
100
+ $cardData->expMonth = $payment->getCcExpMonth();
101
+ }
102
+
103
+ $config = $this->_getServicesConfig();
104
+ // Use HTTP proxy
105
+ if (Mage::getStoreConfig('payment/hps_paypal/use_http_proxy')) {
106
+ $config->useProxy = true;
107
+ $config->proxyOptions = array(
108
+ 'proxy_host' => Mage::getStoreConfig('payment/hps_paypal/http_proxy_host'),
109
+ 'proxy_port' => Mage::getStoreConfig('payment/hps_paypal/http_proxy_port'),
110
+ );
111
+ }
112
+
113
+
114
+ $payPalService = new HpsPayPalService($config);
115
+
116
+ $regionModel = Mage::getModel('directory/region')->load($shipping->getRegionId());
117
+
118
+ $address = new HpsAddress();
119
+ $address->address = $shipping->getStreet(1);
120
+ $address->city = $shipping->getCity();
121
+ $address->state = $regionModel->getCode();
122
+ $address->zip = preg_replace('/[^0-9]/', '', $shipping->getPostcode());
123
+ $address->country = $shipping->getCountryId();
124
+
125
+ $currency = $order->getBaseCurrencyCode();
126
+ $taxAmount = $order->getTaxAmount();
127
+ $shippingAmount = $order->getShippingAmount();
128
+ $subtotal = $amount - $taxAmount - $shippingAmount;
129
+
130
+ $buyer = new HpsBuyerData();
131
+ $buyer->payerId = $payerId;
132
+ $buyer->emailAddress = $shipping->getData('email');
133
+
134
+ $paymentData = new HpsPaymentData();
135
+ $paymentData->subtotal = $subtotal;
136
+ $paymentData->shippingAmount = $shippingAmount;
137
+ $paymentData->taxAmount = $taxAmount;
138
+
139
+ $shippingInfo = new HpsShippingInfo();
140
+ $shippingInfo->name = $billing->getData('firstname') . ' ' . $billing->getData('lastname');
141
+ $shippingInfo->address = $address;
142
+
143
+ //$details = new HpsTransactionDetails();
144
+ //$details->invoiceNumber = $order->getIncrementId();
145
+
146
+ try
147
+ {
148
+ if ($capture)
149
+ {
150
+ if ($payment->getCcTransId())
151
+ {
152
+ $response = $payPalService->capture(
153
+ $payment->getCcTransId(),
154
+ $amount
155
+ );
156
+ }
157
+ else
158
+ {
159
+ $response = $payPalService->sale(
160
+ $token,
161
+ $amount,
162
+ $currency,
163
+ $buyer,
164
+ $paymentData,
165
+ $shippingInfo
166
+ );
167
+ }
168
+ }
169
+ else
170
+ {
171
+ $response = $payPalService->authorize(
172
+ $token,
173
+ $amount,
174
+ $currency,
175
+ $buyer,
176
+ $paymentData,
177
+ $shippingInfo
178
+ );
179
+ }
180
+
181
+ $report = Mage::getModel('hps_securesubmit/report')
182
+ ->loadByOrderId($order->getRealOrderId());
183
+ if ($report->getData() === array()) {
184
+ $report = Mage::getModel('hps_securesubmit/report');
185
+ $report
186
+ ->setOrderId($order->getRealOrderId())
187
+ ->setPayerEmail($shipping->getData('email'))
188
+ ->setCreatedTime(date('Y-m-d H:i:s'));
189
+ }
190
+ $report
191
+ ->setTransactionId($response->transactionId)
192
+ ->setLastKnownStatus($response->status . ' (' . $response->statusMessage . ')')
193
+ ->setUpdateTime(date('Y-m-d H:i:s'))
194
+ ->save();
195
+
196
+ // No exception thrown so action was a success
197
+ $this->_debugChargeService($payPalService);
198
+ $payment->setStatus(self::STATUS_APPROVED);
199
+ $payment->setAmount($amount);
200
+ $payment->setLastTransId($response->transactionId);
201
+ $payment->setCcTransId($response->transactionId);
202
+ $payment->setTransactionId($response->transactionId);
203
+ $payment->setIsTransactionClosed(0);
204
+ }
205
+ catch (HpsProcessorException $e) {
206
+ $this->_debugChargeService($payPalService, $e);
207
+ $payment->setStatus(self::STATUS_DECLINED);
208
+ $this->throwUserError($e->getMessage(), null, TRUE);
209
+ }
210
+ catch (Exception $e)
211
+ {
212
+ $this->_debugChargeService($payPalService, $e);
213
+ Mage::logException($e);
214
+ $payment->setStatus(self::STATUS_ERROR);
215
+ $this->throwUserError($e->getMessage());
216
+ }
217
+
218
+ return $this;
219
+ }
220
+
221
+ public function refund(Varien_Object $payment, $amount)
222
+ {
223
+ $transactionId = $payment->getCcTransId();
224
+ $order = $payment->getOrder();
225
+
226
+ $config = $this->_getServicesConfig();
227
+ $payPalService = new HpsPayPalService($config);
228
+
229
+ try {
230
+ $refundResponse = $payPalService->refund(
231
+ $transactionId,
232
+ $payment->getBaseTotalDue() == $amount,
233
+ $amount
234
+ );
235
+
236
+ $this->_debugChargeService($payPalService);
237
+ $payment
238
+ ->setTransactionId($refundResponse->transactionId)
239
+ ->setParentTransactionId($transactionId)
240
+ ->setIsTransactionClosed(1)
241
+ ->setShouldCloseParentTransaction(1);
242
+
243
+ }
244
+ catch (HpsException $e)
245
+ {
246
+ $this->_debugChargeService($payPalService, $e);
247
+ $this->throwUserError($e->getMessage());
248
+ }
249
+ catch (Exception $e) {
250
+ $this->_debugChargeService($payPalService, $e);
251
+ Mage::logException($e);
252
+ $this->throwUserError($e->getMessage());
253
+ }
254
+
255
+ return $this;
256
+ }
257
+
258
+ /**
259
+ * Void payment abstract method
260
+ *
261
+ * @param Varien_Object $payment
262
+ *
263
+ * @return Hps_Securesubmit_Model_Payment
264
+ */
265
+ public function void(Varien_Object $payment)
266
+ {
267
+ $transactionId = $payment->getCcTransId();
268
+ $config = $this->_getServicesConfig();
269
+
270
+ $payPalService = new HpsPayPalService($config);
271
+ try {
272
+ $voidResponse = $payPalService->void($transactionId);
273
+
274
+ $this->_debugChargeService($payPalService);
275
+ $payment
276
+ ->setTransactionId($voidResponse->transactionId)
277
+ ->setParentTransactionId($transactionId)
278
+ ->setIsTransactionClosed(1)
279
+ ->setShouldCloseParentTransaction(1);
280
+ }
281
+ catch (HpsException $e)
282
+ {
283
+ $this->_debugChargeService($payPalService, $e);
284
+ Mage::throwException($e->getMessage());
285
+ }
286
+ catch (Exception $e) {
287
+ $this->_debugChargeService($payPalService, $e);
288
+ Mage::logException($e);
289
+ Mage::throwException(Mage::helper('hps_securesubmit')->__('An unexpected error occurred. Please try again or contact a system administrator.'));
290
+ }
291
+
292
+ return $this;
293
+ }
294
+
295
+ public function isAvailable($quote = null)
296
+ {
297
+ if($quote && $quote->getBaseGrandTotal()<$this->_minOrderTotal) {
298
+ return false;
299
+ }
300
+
301
+ return $this->getConfigData('secretapikey', ($quote ? $quote->getStoreId() : null))
302
+ && parent::isAvailable($quote);
303
+ }
304
+
305
+ public function canUseForCurrency($currencyCode)
306
+ {
307
+ if (!in_array($currencyCode, $this->_supportedCurrencyCodes)) {
308
+ return false;
309
+ }
310
+
311
+ return true;
312
+ }
313
+
314
+ public function assignData($data)
315
+ {
316
+ parent::assignData($data);
317
+
318
+ if ( ! ($data instanceof Varien_Object)) {
319
+ $data = new Varien_Object($data);
320
+ }
321
+ $info = $this->getInfoInstance();
322
+
323
+ if ( ! $info->getCcLast4() && $data->getCcLastFour()) {
324
+ $info->setCcLast4($data->getCcLastFour());
325
+ }
326
+
327
+ $details = array();
328
+ if ($data->getData('cc_save_future')) {
329
+ $details['cc_save_future'] = 1;
330
+ }
331
+ if ($data->getData('securesubmit_token')) {
332
+ $details['securesubmit_token'] = $data->getData('securesubmit_token');
333
+ }
334
+ if ($data->getData('use_credit_card')) {
335
+ $details['use_credit_card'] = 1;
336
+ }
337
+ if ( ! empty($details)) {
338
+ $this->getInfoInstance()->setAdditionalData(serialize($details));
339
+ }
340
+
341
+ return $this;
342
+ }
343
+
344
+ /**
345
+ * Checkout redirect URL getter for onepage checkout (hardcode)
346
+ *
347
+ * @see Mage_Checkout_OnepageController::savePaymentAction()
348
+ * @see Mage_Sales_Model_Quote_Payment::getCheckoutRedirectUrl()
349
+ * @return string
350
+ */
351
+ public function getCheckoutRedirectUrl()
352
+ {
353
+ return Mage::getUrl('securesubmit/paypal/start');
354
+ }
355
+
356
+ /**
357
+ * @param string $error
358
+ * @param string $detailedError
359
+ * @param bool $goToPaymentSection
360
+ * @throws Mage_Core_Exception
361
+ */
362
+ public function throwUserError($error, $detailedError = NULL, $goToPaymentSection = FALSE)
363
+ {
364
+ // Register detailed error for error reporting elsewhere
365
+ $detailedError = $detailedError ? $error.' ['.$detailedError.']' : $error;
366
+ Mage::unregister('payment_detailed_error');
367
+ Mage::register('payment_detailed_error', $detailedError);
368
+
369
+ // Replace gateway error with custom error message for customers
370
+ $error = Mage::helper('hps_securesubmit')->__($error);
371
+ if ($customMessage = $this->getConfigData('custom_message')) {
372
+ $error = sprintf($customMessage, $error);
373
+ }
374
+
375
+ // Send checkout session back to payment section to avoid double-attempt to charge single-use token
376
+ if ($goToPaymentSection && Mage::app()->getRequest()->getOriginalPathInfo() == '/checkout/onepage/saveOrder') {
377
+ Mage::getSingleton('checkout/session')->setGotoSection('payment');
378
+ }
379
+ throw new Mage_Core_Exception($error);
380
+ }
381
+
382
+ /**
383
+ * @param HpsPayPalService $payPalService
384
+ * @param Exception|null $exception
385
+ */
386
+ public function _debugChargeService(HpsPayPalService $payPalService, $exception = NULL)
387
+ {
388
+ if ($this->getDebugFlag()) {
389
+ $this->_debug(array(
390
+ 'store' => Mage::app()->getStore($this->getStore())->getFrontendName(),
391
+ 'exception_message' => $exception ? get_class($exception).': '.$exception->getMessage() : '',
392
+ // 'last_request' => $payPalService->lastRequest,
393
+ // 'last_response' => $payPalService->lastResponse,
394
+ ));
395
+ }
396
+ }
397
+
398
+ protected function _getServicesConfig()
399
+ {
400
+ $config = new HpsServicesConfig();
401
+ if (Mage::getStoreConfig('payment/hps_paypal/use_sandbox')) {
402
+ $config->username = Mage::getStoreConfig('payment/hps_paypal/username');
403
+ $config->password = Mage::getStoreConfig('payment/hps_paypal/password');
404
+ $config->deviceId = Mage::getStoreConfig('payment/hps_paypal/device_id');
405
+ $config->licenseId = Mage::getStoreConfig('payment/hps_paypal/license_id');
406
+ $config->siteId = Mage::getStoreConfig('payment/hps_paypal/site_id');
407
+ $config->soapServiceUri = "https://posgateway.secureexchange.net/Hps.Exchange.PosGateway/PosGatewayService.asmx";
408
+ //$config->soapServiceUri = "https://api-uat.heartlandportico.com/paymentserver.v1/PosGatewayService.asmx";
409
+ //$config->soapServiceUri = "https://api-uat.heartlandportico.com/paymentserver.HotFix/POSGatewayService.asmx";
410
+ } else {
411
+ $config->secretApiKey = Mage::getStoreConfig('payment/hps_paypal/secretapikey');
412
+ }
413
+ return $config;
414
+ }
415
+ }
app/code/community/Hps/Securesubmit/Model/Paypal/Cart.php ADDED
@@ -0,0 +1,506 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Hps
4
+ * @package Hps_Securesubmit
5
+ * @copyright Copyright (c) 2015 Heartland Payment Systems (https://www.magento.com)
6
+ * @license https://github.com/SecureSubmit/heartland-magento-extension/blob/master/LICENSE Custom License
7
+ */
8
+
9
+ /**
10
+ * PayPal-specific model for shopping cart items and totals
11
+ * The main idea is to accommodate all possible totals into PayPal-compatible 4 totals and line items
12
+ */
13
+ class Hps_Securesubmit_Model_Paypal_Cart
14
+ {
15
+ /**
16
+ * Totals that PayPal suppports when passing shopping cart
17
+ *
18
+ * @var string
19
+ */
20
+ const TOTAL_SUBTOTAL = 'subtotal';
21
+ const TOTAL_DISCOUNT = 'discount';
22
+ const TOTAL_TAX = 'tax';
23
+ const TOTAL_SHIPPING = 'shipping';
24
+
25
+ /**
26
+ * Order or quote instance
27
+ *
28
+ * @var Mage_Sales_Model_Order
29
+ * @var Mage_Sales_Model_Quote
30
+ */
31
+ protected $_salesEntity = null;
32
+
33
+ /**
34
+ * Rendered cart items
35
+ * Array of Varien_Objects
36
+ *
37
+ * @var array
38
+ */
39
+ protected $_items = array();
40
+
41
+ /**
42
+ * Rendered cart totals
43
+ * Associative array with the keys from constants above
44
+ *
45
+ * @var array
46
+ */
47
+ protected $_totals = array();
48
+
49
+ /**
50
+ * Set of optional descriptions for the item that may replace a total and composed of several amounts
51
+ * Array of strings
52
+ *
53
+ * @var array
54
+ */
55
+ protected $_totalLineItemDescriptions = array();
56
+
57
+ /**
58
+ * Lazy initialization indicator for rendering
59
+ *
60
+ * @var bool
61
+ */
62
+ protected $_shouldRender = true;
63
+
64
+ /**
65
+ * Validation result for the rendered cart items
66
+ *
67
+ * @var bool
68
+ */
69
+ protected $_areItemsValid = false;
70
+
71
+ /**
72
+ * Validation result for the rendered totals
73
+ *
74
+ * @var bool
75
+ */
76
+ protected $_areTotalsValid = false;
77
+
78
+ /**
79
+ * Whether to render discount total as a line item
80
+ * Use case: WPP
81
+ *
82
+ * @var bool
83
+ */
84
+ protected $_isDiscountAsItem = false;
85
+
86
+ /**
87
+ * Whether to render shipping total as a line item
88
+ * Use case: WPS
89
+ *
90
+ * @var bool
91
+ */
92
+ protected $_isShippingAsItem = false;
93
+
94
+ /**
95
+ * Require instance of an order or a quote
96
+ *
97
+ * @param array $params
98
+ */
99
+ public function __construct($params = array())
100
+ {
101
+ $salesEntity = array_shift($params);
102
+ if (is_object($salesEntity)
103
+ && (($salesEntity instanceof Mage_Sales_Model_Order) || ($salesEntity instanceof Mage_Sales_Model_Quote))) {
104
+ $this->_salesEntity = $salesEntity;
105
+ } else {
106
+ throw new Exception('Invalid sales entity provided.');
107
+ }
108
+ }
109
+
110
+ /**
111
+ * Getter for the current sales entity
112
+ *
113
+ * @return Mage_Sales_Model_Order
114
+ * @return Mage_Sales_Model_Quote
115
+ */
116
+ public function getSalesEntity()
117
+ {
118
+ return $this->_salesEntity;
119
+ }
120
+
121
+ /**
122
+ * Render and get line items
123
+ * By default returns false if the items are invalid
124
+ *
125
+ * @param bool $bypassValidation
126
+ * @return array|false
127
+ */
128
+ public function getItems($bypassValidation = false)
129
+ {
130
+ $this->_render();
131
+ if (!$bypassValidation && !$this->_areItemsValid) {
132
+ return false;
133
+ }
134
+ return $this->_items;
135
+ }
136
+
137
+ /**
138
+ * Render and get totals
139
+ * If the totals are invalid for any reason, they will be merged into one amount (subtotal is utilized for it)
140
+ * An option to substract discount from the subtotal is available
141
+ *
142
+ * @param bool $mergeDiscount
143
+ * @return array
144
+ */
145
+ public function getTotals($mergeDiscount = false)
146
+ {
147
+ $this->_render();
148
+
149
+ // cut down totals to one total if they are invalid
150
+ if (!$this->_areTotalsValid) {
151
+ $totals = array(
152
+ self::TOTAL_SUBTOTAL => $this->_totals[self::TOTAL_SUBTOTAL] + $this->_totals[self::TOTAL_TAX]
153
+ );
154
+ if (!$this->_isShippingAsItem) {
155
+ $totals[self::TOTAL_SUBTOTAL] += $this->_totals[self::TOTAL_SHIPPING];
156
+ }
157
+ if (!$this->_isDiscountAsItem) {
158
+ $totals[self::TOTAL_SUBTOTAL] -= $this->_totals[self::TOTAL_DISCOUNT];
159
+ }
160
+ return $totals;
161
+ } elseif ($mergeDiscount) {
162
+ $totals = $this->_totals;
163
+ unset($totals[self::TOTAL_DISCOUNT]);
164
+ if (!$this->_isDiscountAsItem) {
165
+ $totals[self::TOTAL_SUBTOTAL] -= $this->_totals[self::TOTAL_DISCOUNT];
166
+ }
167
+ return $totals;
168
+ }
169
+ return $this->_totals;
170
+ }
171
+
172
+ /**
173
+ * Add a line item
174
+ *
175
+ * @param string $name
176
+ * @param numeric $qty
177
+ * @param float $amount
178
+ * @param string $identifier
179
+ * @return Varien_Object
180
+ */
181
+ public function addItem($name, $qty, $amount, $identifier = null)
182
+ {
183
+ $this->_shouldRender = true;
184
+ $item = new Varien_Object(array(
185
+ 'name' => $name,
186
+ 'qty' => $qty,
187
+ 'amount' => (float)$amount,
188
+ ));
189
+ if ($identifier) {
190
+ $item->setData('id', $identifier);
191
+ }
192
+ $this->_items[] = $item;
193
+ return $item;
194
+ }
195
+
196
+ /**
197
+ * Remove item from cart by identifier
198
+ *
199
+ * @param string $identifier
200
+ * @return bool
201
+ */
202
+ public function removeItem($identifier)
203
+ {
204
+ foreach ($this->_items as $key => $item) {
205
+ if ($item->getId() == $identifier) {
206
+ unset($this->_items[$key]);
207
+ return true;
208
+ }
209
+ }
210
+ return false;
211
+ }
212
+
213
+ /**
214
+ * Compound the specified amount with the specified total
215
+ *
216
+ * @param string $code
217
+ * @param float $amount
218
+ * @param string $lineItemDescription
219
+ * @return Hps_Securesubmit_Model_Paypal_Cart
220
+ */
221
+ public function updateTotal($code, $amount, $lineItemDescription = null)
222
+ {
223
+ $this->_shouldRender = true;
224
+ if (isset($this->_totals[$code])) {
225
+ $this->_totals[$code] += $amount;
226
+ if ($lineItemDescription) {
227
+ $this->_totalLineItemDescriptions[$code][] = $lineItemDescription;
228
+ }
229
+ }
230
+ return $this;
231
+ }
232
+
233
+ /**
234
+ * Get/Set whether to render the discount total as a line item
235
+ *
236
+ * @param $setValue
237
+ * @return bool|Hps_Securesubmit_Model_Paypal_Cart
238
+ */
239
+ public function isDiscountAsItem($setValue = null)
240
+ {
241
+ return $this->_totalAsItem('_isDiscountAsItem', $setValue);
242
+ }
243
+
244
+ /**
245
+ * Get/Set whether to render the discount total as a line item
246
+ *
247
+ * @param $setValue
248
+ * @return bool|Hps_Securesubmit_Model_Paypal_Cart
249
+ */
250
+ public function isShippingAsItem($setValue = null)
251
+ {
252
+ return $this->_totalAsItem('_isShippingAsItem', $setValue);
253
+ }
254
+
255
+ /**
256
+ * (re)Render all items and totals
257
+ */
258
+ protected function _render()
259
+ {
260
+ if (!$this->_shouldRender) {
261
+ return;
262
+ }
263
+
264
+ // regular items from the sales entity
265
+ $this->_items = array();
266
+ foreach ($this->_salesEntity->getAllItems() as $item) {
267
+ if (!$item->getParentItem()) {
268
+ $this->_addRegularItem($item);
269
+ }
270
+ }
271
+ end($this->_items);
272
+ $lastRegularItemKey = key($this->_items);
273
+
274
+ // regular totals
275
+ $shippingDescription = '';
276
+ if ($this->_salesEntity instanceof Mage_Sales_Model_Order) {
277
+ $shippingDescription = $this->_salesEntity->getShippingDescription();
278
+ $this->_totals = array(
279
+ self::TOTAL_SUBTOTAL => $this->_salesEntity->getBaseSubtotal(),
280
+ self::TOTAL_TAX => $this->_salesEntity->getBaseTaxAmount(),
281
+ self::TOTAL_SHIPPING => $this->_salesEntity->getBaseShippingAmount(),
282
+ self::TOTAL_DISCOUNT => abs($this->_salesEntity->getBaseDiscountAmount()),
283
+ );
284
+ $this->_applyHiddenTaxWorkaround($this->_salesEntity);
285
+ } else {
286
+ $address = $this->_salesEntity->getIsVirtual() ?
287
+ $this->_salesEntity->getBillingAddress() : $this->_salesEntity->getShippingAddress();
288
+ $shippingDescription = $address->getShippingDescription();
289
+ $this->_totals = array (
290
+ self::TOTAL_SUBTOTAL => $this->_salesEntity->getBaseSubtotal(),
291
+ self::TOTAL_TAX => $address->getBaseTaxAmount(),
292
+ self::TOTAL_SHIPPING => $address->getBaseShippingAmount(),
293
+ self::TOTAL_DISCOUNT => abs($address->getBaseDiscountAmount()),
294
+ );
295
+ $this->_applyHiddenTaxWorkaround($address);
296
+ }
297
+ $originalDiscount = $this->_totals[self::TOTAL_DISCOUNT];
298
+
299
+ // arbitrary items, total modifications
300
+ Mage::dispatchEvent('paypal_prepare_line_items', array('paypal_cart' => $this));
301
+
302
+ // distinguish original discount among the others
303
+ if ($originalDiscount > 0.0001 && isset($this->_totalLineItemDescriptions[self::TOTAL_DISCOUNT])) {
304
+ $this->_totalLineItemDescriptions[self::TOTAL_DISCOUNT][] = Mage::helper('sales')->__('Discount (%s)', Mage::app()->getStore()->convertPrice($originalDiscount, true, false));
305
+ }
306
+
307
+ // discount, shipping as items
308
+ if ($this->_isDiscountAsItem && $this->_totals[self::TOTAL_DISCOUNT]) {
309
+ $this->addItem(Mage::helper('paypal')->__('Discount'), 1, -1.00 * $this->_totals[self::TOTAL_DISCOUNT],
310
+ $this->_renderTotalLineItemDescriptions(self::TOTAL_DISCOUNT)
311
+ );
312
+ }
313
+ $shippingItemId = $this->_renderTotalLineItemDescriptions(self::TOTAL_SHIPPING, $shippingDescription);
314
+ if ($this->_isShippingAsItem && (float)$this->_totals[self::TOTAL_SHIPPING]) {
315
+ $this->addItem(Mage::helper('paypal')->__('Shipping'), 1, (float)$this->_totals[self::TOTAL_SHIPPING],
316
+ $shippingItemId
317
+ );
318
+ }
319
+
320
+ // compound non-regular items into subtotal
321
+ foreach ($this->_items as $key => $item) {
322
+ if ($key > $lastRegularItemKey && $item->getAmount() != 0) {
323
+ $this->_totals[self::TOTAL_SUBTOTAL] += $item->getAmount();
324
+ }
325
+ }
326
+
327
+ $this->_validate();
328
+ // if cart items are invalid, prepare cart for transfer without line items
329
+ if (!$this->_areItemsValid) {
330
+ $this->removeItem($shippingItemId);
331
+ }
332
+
333
+ $this->_shouldRender = false;
334
+ }
335
+
336
+ /**
337
+ * Merge multiple descriptions by a total code into a string
338
+ *
339
+ * @param string $code
340
+ * @param string $prepend
341
+ * @param string $append
342
+ * @param string $glue
343
+ * @return string
344
+ */
345
+ protected function _renderTotalLineItemDescriptions($code, $prepend = '', $append = '', $glue = '; ')
346
+ {
347
+ $result = array();
348
+ if ($prepend) {
349
+ $result[] = $prepend;
350
+ }
351
+ if (isset($this->_totalLineItemDescriptions[$code])) {
352
+ $result = array_merge($this->_totalLineItemDescriptions[$code]);
353
+ }
354
+ if ($append) {
355
+ $result[] = $append;
356
+ }
357
+ return implode($glue, $result);
358
+ }
359
+
360
+ /**
361
+ * Check the line items and totals according to PayPal business logic limitations
362
+ */
363
+ protected function _validate()
364
+ {
365
+ $this->_areItemsValid = true;
366
+ $this->_areTotalsValid = false;
367
+
368
+ $referenceAmount = $this->_salesEntity->getBaseGrandTotal();
369
+
370
+ $itemsSubtotal = 0;
371
+ foreach ($this->_items as $i) {
372
+ $itemsSubtotal = $itemsSubtotal + $i['qty'] * $i['amount'];
373
+ }
374
+ $sum = $itemsSubtotal + $this->_totals[self::TOTAL_TAX];
375
+ if (!$this->_isShippingAsItem) {
376
+ $sum += $this->_totals[self::TOTAL_SHIPPING];
377
+ }
378
+ if (!$this->_isDiscountAsItem) {
379
+ $sum -= $this->_totals[self::TOTAL_DISCOUNT];
380
+ }
381
+ /**
382
+ * numbers are intentionally converted to strings because of possible comparison error
383
+ * see http://php.net/float
384
+ */
385
+ // match sum of all the items and totals to the reference amount
386
+ if (sprintf('%.4F', $sum) != sprintf('%.4F', $referenceAmount)) {
387
+ $adjustment = $sum - $referenceAmount;
388
+ $this->_totals[self::TOTAL_SUBTOTAL] = $this->_totals[self::TOTAL_SUBTOTAL] - $adjustment;
389
+ }
390
+
391
+ // PayPal requires to have discount less than items subtotal
392
+ if (!$this->_isDiscountAsItem) {
393
+ $this->_areTotalsValid = round($this->_totals[self::TOTAL_DISCOUNT], 4) < round($itemsSubtotal, 4);
394
+ } else {
395
+ $this->_areTotalsValid = $itemsSubtotal > 0.00001;
396
+ }
397
+
398
+ $this->_areItemsValid = $this->_areItemsValid && $this->_areTotalsValid;
399
+ }
400
+
401
+ /**
402
+ * Check whether items are valid
403
+ *
404
+ * @return bool
405
+ */
406
+ public function areItemsValid()
407
+ {
408
+ return $this->_areItemsValid;
409
+ }
410
+
411
+ /**
412
+ * Add a usual line item with amount and qty
413
+ *
414
+ * @param Varien_Object $salesItem
415
+ * @return Varien_Object
416
+ */
417
+ protected function _addRegularItem(Varien_Object $salesItem)
418
+ {
419
+ if ($this->_salesEntity instanceof Mage_Sales_Model_Order) {
420
+ $qty = (int) $salesItem->getQtyOrdered();
421
+ $amount = (float) $salesItem->getBasePrice();
422
+ // TODO: nominal item for order
423
+ } else {
424
+ $qty = (int) $salesItem->getTotalQty();
425
+ $amount = $salesItem->isNominal() ? 0 : (float) $salesItem->getBaseCalculationPrice();
426
+ }
427
+ // workaround in case if item subtotal precision is not compatible with PayPal (.2)
428
+ $subAggregatedLabel = '';
429
+ if ($amount - round($amount, 2)) {
430
+ $amount = $amount * $qty;
431
+ $subAggregatedLabel = ' x' . $qty;
432
+ $qty = 1;
433
+ }
434
+
435
+ // aggregate item price if item qty * price does not match row total
436
+ if (($amount * $qty) != $salesItem->getBaseRowTotal()) {
437
+ $amount = (float) $salesItem->getBaseRowTotal();
438
+ $subAggregatedLabel = ' x' . $qty;
439
+ $qty = 1;
440
+ }
441
+
442
+ return $this->addItem($salesItem->getName() . $subAggregatedLabel, $qty, $amount, $salesItem->getSku());
443
+ }
444
+
445
+ /**
446
+ * Get/Set for the specified variable.
447
+ * If the value changes, the re-rendering is commenced
448
+ *
449
+ * @param string $var
450
+ * @param $setValue
451
+ * @return bool|Hps_Securesubmit_Model_Paypal_Cart
452
+ */
453
+ private function _totalAsItem($var, $setValue = null)
454
+ {
455
+ if (null !== $setValue) {
456
+ if ($setValue != $this->$var) {
457
+ $this->_shouldRender = true;
458
+ }
459
+ $this->$var = $setValue;
460
+ return $this;
461
+ }
462
+ return $this->$var;
463
+ }
464
+
465
+ /**
466
+ * Add "hidden" discount and shipping tax
467
+ *
468
+ * Go ahead, try to understand ]:->
469
+ *
470
+ * Tax settings for getting "discount tax":
471
+ * - Catalog Prices = Including Tax
472
+ * - Apply Customer Tax = After Discount
473
+ * - Apply Discount on Prices = Including Tax
474
+ *
475
+ * Test case for getting "hidden shipping tax":
476
+ * - Make sure shipping is taxable (set shipping tax class)
477
+ * - Catalog Prices = Including Tax
478
+ * - Shipping Prices = Including Tax
479
+ * - Apply Customer Tax = After Discount
480
+ * - Create a shopping cart price rule with % discount applied to the Shipping Amount
481
+ * - run shopping cart and estimate shipping
482
+ * - go to PayPal
483
+ *
484
+ * @param Mage_Core_Model_Abstract $salesEntity
485
+ */
486
+ private function _applyHiddenTaxWorkaround($salesEntity)
487
+ {
488
+ $this->_totals[self::TOTAL_TAX] += (float)$salesEntity->getBaseHiddenTaxAmount();
489
+ $this->_totals[self::TOTAL_TAX] += (float)$salesEntity->getBaseShippingHiddenTaxAmount();
490
+ }
491
+
492
+ /**
493
+ * Check whether any item has negative amount
494
+ *
495
+ * @return bool
496
+ */
497
+ public function hasNegativeItemAmount()
498
+ {
499
+ foreach ($this->_items as $item) {
500
+ if ($item->getAmount() < 0) {
501
+ return true;
502
+ }
503
+ }
504
+ return false;
505
+ }
506
+ }
app/code/community/Hps/Securesubmit/Model/Paypal/Checkout.php ADDED
@@ -0,0 +1,1036 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Hps
4
+ * @package Hps_Securesubmit
5
+ * @copyright Copyright (c) 2015 Heartland Payment Systems (https://www.magento.com)
6
+ * @license https://github.com/SecureSubmit/heartland-magento-extension/blob/master/LICENSE Custom License
7
+ */
8
+
9
+ /**
10
+ * Wrapper that performs Paypal Express and Checkout communication
11
+ * Use current Paypal Express method instance
12
+ */
13
+ class Hps_Securesubmit_Model_Paypal_Checkout
14
+ {
15
+ /**
16
+ * Cache ID prefix for "pal" lookup
17
+ * @var string
18
+ */
19
+ const PAL_CACHE_ID = 'paypal_express_checkout_pal';
20
+
21
+ /**
22
+ * Keys for passthrough variables in sales/quote_payment and sales/order_payment
23
+ * Uses additional_information as storage
24
+ * @var string
25
+ */
26
+ const PAYMENT_INFO_TRANSPORT_TOKEN = 'paypal_express_checkout_token';
27
+ const PAYMENT_INFO_TRANSPORT_SHIPPING_OVERRIDEN = 'paypal_express_checkout_shipping_overriden';
28
+ const PAYMENT_INFO_TRANSPORT_SHIPPING_METHOD = 'paypal_express_checkout_shipping_method';
29
+ const PAYMENT_INFO_TRANSPORT_PAYER_ID = 'paypal_express_checkout_payer_id';
30
+ const PAYMENT_INFO_TRANSPORT_REDIRECT = 'paypal_express_checkout_redirect_required';
31
+ const PAYMENT_INFO_TRANSPORT_BILLING_AGREEMENT = 'paypal_ec_create_ba';
32
+
33
+ /**
34
+ * Flag which says that was used PayPal Express Checkout button for checkout
35
+ * Uses additional_information as storage
36
+ * @var string
37
+ */
38
+ const PAYMENT_INFO_BUTTON = 'button';
39
+
40
+ /**
41
+ * Flag which says that was used PayPal Credit Checkout button for checkout
42
+ * Uses additional_information as storage
43
+ * @var string
44
+ */
45
+ const PAYMENT_INFO_CREDIT = 'credit';
46
+
47
+ /**
48
+ * @var Mage_Sales_Model_Quote
49
+ */
50
+ protected $_quote = null;
51
+
52
+ /**
53
+ * Config instance
54
+ * @var Hps_Securesubmit_Model_Config
55
+ */
56
+ protected $_config = null;
57
+
58
+ /**
59
+ * API instance
60
+ * @var Hps_Securesubmit_Model_Api_Nvp
61
+ */
62
+ protected $_api = null;
63
+
64
+ /**
65
+ * Api Model Type
66
+ *
67
+ * @var string
68
+ */
69
+ protected $_apiType = 'hps_securesubmit/api_paypal';
70
+
71
+ /**
72
+ * Payment method type
73
+ *
74
+ * @var unknown_type
75
+ */
76
+ protected $_methodType = 'hps_paypal';
77
+
78
+ /**
79
+ * State helper variables
80
+ * @var string
81
+ */
82
+ protected $_redirectUrl = '';
83
+ protected $_pendingPaymentMessage = '';
84
+ protected $_checkoutRedirectUrl = '';
85
+
86
+ /**
87
+ * @var Mage_Customer_Model_Session
88
+ */
89
+ protected $_customerSession;
90
+
91
+ /**
92
+ * Redirect urls supposed to be set to support giropay
93
+ *
94
+ * @var array
95
+ */
96
+ protected $_giropayUrls = array();
97
+
98
+ /**
99
+ * Create Billing Agreement flag
100
+ *
101
+ * @var bool
102
+ */
103
+ protected $_isBARequested = false;
104
+
105
+ /**
106
+ * Flag for Bill Me Later mode
107
+ *
108
+ * @var bool
109
+ */
110
+ protected $_isBml = false;
111
+
112
+ /**
113
+ * Customer ID
114
+ *
115
+ * @var int
116
+ */
117
+ protected $_customerId = null;
118
+
119
+ /**
120
+ * Recurring payment profiles
121
+ *
122
+ * @var array
123
+ */
124
+ protected $_recurringPaymentProfiles = array();
125
+
126
+ /**
127
+ * Billing agreement that might be created during order placing
128
+ *
129
+ * @var Mage_Sales_Model_Billing_Agreement
130
+ */
131
+ protected $_billingAgreement = null;
132
+
133
+ /**
134
+ * Order
135
+ *
136
+ * @var Mage_Sales_Model_QuoteMage_Sales_Model_Quote
137
+ */
138
+ protected $_order = null;
139
+
140
+ /**
141
+ * Set quote and config instances
142
+ * @param array $params
143
+ */
144
+ public function __construct($params = array())
145
+ {
146
+ if (isset($params['quote']) && $params['quote'] instanceof Mage_Sales_Model_Quote) {
147
+ $this->_quote = $params['quote'];
148
+ } else {
149
+ throw new Exception('Quote instance is required.');
150
+ }
151
+ if (isset($params['config']) && $params['config'] instanceof Hps_Securesubmit_Model_Config) {
152
+ $this->_config = $params['config'];
153
+ } else {
154
+ throw new Exception('Config instance is required.');
155
+ }
156
+ $this->_customerSession = isset($params['session']) && $params['session'] instanceof Mage_Customer_Model_Session
157
+ ? $params['session'] : Mage::getSingleton('customer/session');
158
+ }
159
+
160
+ /**
161
+ * Checkout with PayPal image URL getter
162
+ * Spares API calls of getting "pal" variable, by putting it into cache per store view
163
+ * @return string
164
+ */
165
+ public function getCheckoutShortcutImageUrl()
166
+ {
167
+ // get "pal" thing from cache or lookup it via API
168
+ $pal = null;
169
+ if ($this->_config->areButtonsDynamic()) {
170
+ $cacheId = self::PAL_CACHE_ID . Mage::app()->getStore()->getId();
171
+ $pal = Mage::app()->loadCache($cacheId);
172
+ if (-1 == $pal) {
173
+ $pal = null;
174
+ } elseif (!$pal) {
175
+ $pal = null;
176
+ $this->_getApi();
177
+ try {
178
+ $this->_api->callGetPalDetails();
179
+ $pal = $this->_api->getPal();
180
+ Mage::app()->saveCache($pal, $cacheId, array(Mage_Core_Model_Config::CACHE_TAG));
181
+ } catch (Exception $e) {
182
+ Mage::app()->saveCache(-1, $cacheId, array(Mage_Core_Model_Config::CACHE_TAG));
183
+ Mage::logException($e);
184
+ }
185
+ }
186
+ }
187
+
188
+ return $this->_config->getExpressCheckoutShortcutImageUrl(
189
+ Mage::app()->getLocale()->getLocaleCode(),
190
+ $this->_quote->getBaseGrandTotal(),
191
+ $pal
192
+ );
193
+ }
194
+
195
+ /**
196
+ * Setter that enables giropay redirects flow
197
+ *
198
+ * @param string $successUrl - payment success result
199
+ * @param string $cancelUrl - payment cancellation result
200
+ * @param string $pendingUrl - pending payment result
201
+ * @return Hps_Securesubmit_Model_Paypal_Checkout
202
+ */
203
+ public function prepareGiropayUrls($successUrl, $cancelUrl, $pendingUrl)
204
+ {
205
+ $this->_giropayUrls = array($successUrl, $cancelUrl, $pendingUrl);
206
+ return $this;
207
+ }
208
+
209
+ /**
210
+ * Set create billing agreement flag
211
+ *
212
+ * @param bool $flag
213
+ * @return Hps_Securesubmit_Model_Paypal_Checkout
214
+ */
215
+ public function setIsBillingAgreementRequested($flag)
216
+ {
217
+ $this->_isBARequested = $flag;
218
+ return $this;
219
+ }
220
+
221
+ /**
222
+ * Setter for customer Id
223
+ *
224
+ * @param int $id
225
+ * @return Hps_Securesubmit_Model_Paypal_Checkout
226
+ * @deprecated please use self::setCustomer
227
+ */
228
+ public function setCustomerId($id)
229
+ {
230
+ $this->_customerId = $id;
231
+ return $this;
232
+ }
233
+
234
+ /**
235
+ * Set flag that forces to use BillMeLater
236
+ *
237
+ * @param bool $isBml
238
+ */
239
+ public function setIsBml($isBml)
240
+ {
241
+ $this->_isBml = $isBml;
242
+ }
243
+
244
+ /**
245
+ * Setter for customer
246
+ *
247
+ * @param Mage_Customer_Model_Customer $customer
248
+ * @return Hps_Securesubmit_Model_Paypal_Checkout
249
+ */
250
+ public function setCustomer($customer)
251
+ {
252
+ $this->_quote->assignCustomer($customer);
253
+ $this->_customerId = $customer->getId();
254
+ return $this;
255
+ }
256
+
257
+ /**
258
+ * Setter for customer with billing and shipping address changing ability
259
+ *
260
+ * @param Mage_Customer_Model_Customer $customer
261
+ * @param Mage_Sales_Model_Quote_Address $billingAddress
262
+ * @param Mage_Sales_Model_Quote_Address $shippingAddress
263
+ * @return Hps_Securesubmit_Model_Paypal_Checkout
264
+ */
265
+ public function setCustomerWithAddressChange($customer, $billingAddress = null, $shippingAddress = null)
266
+ {
267
+ $this->_quote->assignCustomerWithAddressChange($customer, $billingAddress, $shippingAddress);
268
+ $this->_customerId = $customer->getId();
269
+ return $this;
270
+ }
271
+
272
+ /**
273
+ * Reserve order ID for specified quote and start checkout on PayPal
274
+ *
275
+ * @param string $returnUrl
276
+ * @param string $cancelUrl
277
+ * @param array|null $params
278
+ * @return mixed
279
+ */
280
+ public function start($returnUrl, $cancelUrl, $params = null)
281
+ {
282
+ $button = null;
283
+ $credit = null;
284
+ if (!empty($params)) {
285
+ if (isset($params['button'])) $button = $params['button'];
286
+ if (isset($params['credit'])) $credit = $params['credit'];
287
+ }
288
+ $this->_quote->collectTotals();
289
+
290
+ if (!$this->_quote->getGrandTotal() && !$this->_quote->hasNominalItems()) {
291
+ Mage::throwException(Mage::helper('paypal')->__('PayPal does not support processing orders with zero amount. To complete your purchase, proceed to the standard checkout process.'));
292
+ }
293
+
294
+ $this->_quote->reserveOrderId()->save();
295
+ // prepare API
296
+ $this->_getApi();
297
+ $solutionType = $this->_config->getMerchantCountry() == 'DE'
298
+ ? Hps_Securesubmit_Model_Config::EC_SOLUTION_TYPE_MARK : $this->_config->solutionType;
299
+ $this->_api->setAmount($this->_quote->getBaseGrandTotal())
300
+ ->setCurrencyCode($this->_quote->getBaseCurrencyCode())
301
+ ->setInvNum($this->_quote->getReservedOrderId())
302
+ ->setReturnUrl($returnUrl)
303
+ ->setCancelUrl($cancelUrl)
304
+ ->setSolutionType($solutionType)
305
+ ->setPaymentAction($this->_config->paymentAction);
306
+
307
+ // supress or export shipping address
308
+ if ($this->_quote->getIsVirtual()) {
309
+ if ($this->_config->requireBillingAddress == Hps_Securesubmit_Model_Config::REQUIRE_BILLING_ADDRESS_VIRTUAL) {
310
+ $this->_api->setRequireBillingAddress(1);
311
+ }
312
+ $this->_api->setSuppressShipping(true);
313
+ } else {
314
+ $address = $this->_quote->getShippingAddress();
315
+ $isOverriden = 0;
316
+ if (true === $address->validate()) {
317
+ $isOverriden = 1;
318
+ $this->_api->setAddress($address);
319
+ }
320
+ $this->_quote->getPayment()->setAdditionalInformation(
321
+ self::PAYMENT_INFO_TRANSPORT_SHIPPING_OVERRIDEN, $isOverriden
322
+ );
323
+ $this->_quote->getPayment()->save();
324
+ }
325
+
326
+ // // add line items
327
+ $paypalCart = Mage::getModel('hps_securesubmit/paypal_cart', array($this->_quote));
328
+ $this->_api->setPaypalCart($paypalCart)
329
+ ->setIsLineItemsEnabled($this->_config->lineItemsEnabled)
330
+ ;
331
+
332
+ // // add shipping options if needed and line items are available
333
+ // if ($this->_config->lineItemsEnabled && $this->_config->transferShippingOptions && $paypalCart->getItems()) {
334
+ if (!$this->_quote->getIsVirtual() && !$this->_quote->hasNominalItems()) {
335
+ if ($options = $this->_prepareShippingOptions($address, true)) {
336
+ $this->_api->setShippingOptionsCallbackUrl(
337
+ Mage::getUrl('*/*/shippingOptionsCallback', array('quote_id' => $this->_quote->getId()))
338
+ )->setShippingOptions($options);
339
+ }
340
+ }
341
+ // }
342
+
343
+ // // add recurring payment profiles information
344
+ // if ($profiles = $this->_quote->prepareRecurringPaymentProfiles()) {
345
+ // foreach ($profiles as $profile) {
346
+ // $profile->setMethodCode(Hps_Securesubmit_Model_Config::METHOD_WPP_EXPRESS);
347
+ // if (!$profile->isValid()) {
348
+ // Mage::throwException($profile->getValidationErrors(true, true));
349
+ // }
350
+ // }
351
+ // $this->_api->addRecurringPaymentProfiles($profiles);
352
+ // }
353
+
354
+ // $this->_config->exportExpressCheckoutStyleSettings($this->_api);
355
+
356
+ // call API and redirect with token
357
+ // print "setting checkout session";
358
+ $response = $this->_api->callSetExpressCheckout($credit);
359
+ // print_r($response);
360
+ $token = $response->sessionId;
361
+ $this->_redirectUrl = $response->redirectUrl;
362
+
363
+ $this->_quote->getPayment()->unsAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_BILLING_AGREEMENT);
364
+
365
+ // Set flag that we came from Express Checkout button
366
+ if (!empty($button)) {
367
+ $this->_quote->getPayment()->setAdditionalInformation(self::PAYMENT_INFO_BUTTON, 1);
368
+ } elseif ($this->_quote->getPayment()->hasAdditionalInformation(self::PAYMENT_INFO_BUTTON)) {
369
+ $this->_quote->getPayment()->unsAdditionalInformation(self::PAYMENT_INFO_BUTTON);
370
+ }
371
+
372
+ // Set flag that we came from Credit Checkout button
373
+ if (!empty($credit)) {
374
+ $this->_quote->getPayment()->setAdditionalInformation(self::PAYMENT_INFO_CREDIT, 1);
375
+ } elseif ($this->_quote->getPayment()->hasAdditionalInformation(self::PAYMENT_INFO_CREDIT)) {
376
+ $this->_quote->getPayment()->unsAdditionalInformation(self::PAYMENT_INFO_CREDIT);
377
+ }
378
+
379
+ $this->_quote->getPayment()->save();
380
+ return $token;
381
+ }
382
+
383
+ /**
384
+ * Check whether system can skip order review page before placing order
385
+ *
386
+ * @return bool
387
+ */
388
+ public function canSkipOrderReviewStep()
389
+ {
390
+ $isOnepageCheckout = !$this->_quote->getPayment()
391
+ ->getAdditionalInformation(Hps_Securesubmit_Model_Paypal_Checkout::PAYMENT_INFO_BUTTON);
392
+ return $this->_config->isOrderReviewStepDisabled() && $isOnepageCheckout;
393
+ }
394
+
395
+ /**
396
+ * Update quote when returned from PayPal
397
+ * rewrite billing address by paypal
398
+ * save old billing address for new customer
399
+ * export shipping address in case address absence
400
+ *
401
+ * @param string $token
402
+ */
403
+ public function returnFromPaypal($token, $payerId)
404
+ {
405
+ $this->_getApi();
406
+ $response = $this->_api->setToken($token)
407
+ ->callGetExpressCheckoutDetails();
408
+ $quote = $this->_quote;
409
+
410
+ $this->_ignoreAddressValidation();
411
+ $shippingAddress = null;
412
+ $billingAddress = null;
413
+
414
+ // import shipping address
415
+ $exportedShippingAddress = $response->shipping;
416
+ if (!$quote->getIsVirtual()) {
417
+ $shippingAddress = $quote->getShippingAddress();
418
+ if ($shippingAddress) {
419
+ if ($exportedShippingAddress
420
+ && $quote->getPayment()->getAdditionalInformation(self::PAYMENT_INFO_BUTTON) == 1
421
+ ) {
422
+ $this->_setExportedAddressData($shippingAddress, $exportedShippingAddress);
423
+ // PayPal doesn't provide detailed shipping info: prefix, middlename, lastname, suffix
424
+ $shippingAddress->setPrefix(null);
425
+ $shippingAddress->setFirstname($response->buyer->firstName);
426
+ $shippingAddress->setMiddlename(null);
427
+ $shippingAddress->setLastname($response->buyer->lastName);
428
+ $shippingAddress->setEmail($response->buyer->emailAddress);
429
+ $shippingAddress->setSuffix(null);
430
+ $shippingAddress->setCollectShippingRates(true);
431
+ $shippingAddress->setSameAsBilling(0);
432
+ }
433
+
434
+ // import shipping method
435
+ $code = '';
436
+ if ($this->_api->getShippingRateCode()) {
437
+ if ($code = $this->_matchShippingMethodCode($shippingAddress, $this->_api->getShippingRateCode())) {
438
+ // possible bug of double collecting rates :-/
439
+ $shippingAddress->setShippingMethod($code)->setCollectShippingRates(true);
440
+ }
441
+ }
442
+ $quote->getPayment()->setAdditionalInformation(
443
+ self::PAYMENT_INFO_TRANSPORT_SHIPPING_METHOD,
444
+ $code
445
+ );
446
+ }
447
+ }
448
+
449
+ // import billing address
450
+ $portBillingFromShipping = $quote->getPayment()->getAdditionalInformation(self::PAYMENT_INFO_BUTTON) == 1
451
+ // && $this->_config->requireBillingAddress != Hps_Securesubmit_Model_Config::REQUIRE_BILLING_ADDRESS_ALL
452
+ && !$quote->isVirtual();
453
+ if ($portBillingFromShipping) {
454
+ $billingAddress = clone $shippingAddress;
455
+ $billingAddress->unsAddressId()
456
+ ->unsAddressType();
457
+ $data = $billingAddress->getData();
458
+ $data['save_in_address_book'] = 0;
459
+ $quote->getBillingAddress()->addData($data);
460
+ $quote->getShippingAddress()->setSameAsBilling(1);
461
+ } else {
462
+ $billingAddress = $quote->getBillingAddress();
463
+ }
464
+ // $exportedBillingAddress = $this->_api->getExportedBillingAddress();
465
+ // $this->_setExportedAddressData($billingAddress, $exportedBillingAddress);
466
+ // $billingAddress->setCustomerNotes($exportedBillingAddress->getData('note'));
467
+ $quote->setBillingAddress($billingAddress);
468
+ $quote->save();
469
+
470
+ // import payment info
471
+ $payment = $quote->getPayment();
472
+ $payment->setMethod($this->_methodType);
473
+ //Mage::getSingleton('paypal/info')->importToPayment($this->_api, $payment);
474
+ $payment->setAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_PAYER_ID, $payerId)
475
+ ->setAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_TOKEN, $token)
476
+ ;
477
+ $quote->collectTotals()->save();
478
+ }
479
+
480
+ /**
481
+ * Check whether order review has enough data to initialize
482
+ *
483
+ * @param $token
484
+ * @throws Mage_Core_Exception
485
+ */
486
+ public function prepareOrderReview($token = null)
487
+ {
488
+ $payment = $this->_quote->getPayment();
489
+ if (!$payment || !$payment->getAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_PAYER_ID)) {
490
+ Mage::throwException(Mage::helper('paypal')->__('Payer is not identified.'));
491
+ }
492
+ $this->_quote->setMayEditShippingAddress(
493
+ 1 != $this->_quote->getPayment()->getAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_SHIPPING_OVERRIDEN)
494
+ );
495
+ $this->_quote->setMayEditShippingMethod(
496
+ '' == $this->_quote->getPayment()->getAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_SHIPPING_METHOD)
497
+ );
498
+ $this->_ignoreAddressValidation();
499
+ $this->_quote->collectTotals()->save();
500
+ }
501
+
502
+ /**
503
+ * Return callback response with shipping options
504
+ *
505
+ * @param array $request
506
+ * @return string
507
+ */
508
+ public function getShippingOptionsCallbackResponse(array $request)
509
+ {
510
+ // prepare debug data
511
+ $logger = Mage::getModel('core/log_adapter', 'payment_' . $this->_methodType . '.log');
512
+ $debugData = array('request' => $request, 'response' => array());
513
+
514
+ try {
515
+ // obtain addresses
516
+ $this->_getApi();
517
+ $address = $this->_api->prepareShippingOptionsCallbackAddress($request);
518
+ $quoteAddress = $this->_quote->getShippingAddress();
519
+
520
+ // compare addresses, calculate shipping rates and prepare response
521
+ $options = array();
522
+ if ($address && $quoteAddress && !$this->_quote->getIsVirtual()) {
523
+ foreach ($address->getExportedKeys() as $key) {
524
+ $quoteAddress->setDataUsingMethod($key, $address->getData($key));
525
+ }
526
+ $quoteAddress->setCollectShippingRates(true)->collectTotals();
527
+ $options = $this->_prepareShippingOptions($quoteAddress, false, true);
528
+ }
529
+ $response = $this->_api->setShippingOptions($options)->formatShippingOptionsCallback();
530
+
531
+ // log request and response
532
+ $debugData['response'] = $response;
533
+ $logger->log($debugData);
534
+ return $response;
535
+ } catch (Exception $e) {
536
+ $logger->log($debugData);
537
+ throw $e;
538
+ }
539
+ }
540
+
541
+ /**
542
+ * Set shipping method to quote, if needed
543
+ * @param string $methodCode
544
+ */
545
+ public function updateShippingMethod($methodCode)
546
+ {
547
+ if (!$this->_quote->getIsVirtual() && $shippingAddress = $this->_quote->getShippingAddress()) {
548
+ if ($methodCode != $shippingAddress->getShippingMethod()) {
549
+ $this->_ignoreAddressValidation();
550
+ $shippingAddress->setShippingMethod($methodCode)->setCollectShippingRates(true);
551
+ $this->_quote->collectTotals()->save();
552
+ }
553
+ }
554
+ }
555
+
556
+ /**
557
+ * Place the order and recurring payment profiles when customer returned from paypal
558
+ * Until this moment all quote data must be valid
559
+ *
560
+ * @param string $token
561
+ * @param string $shippingMethodCode
562
+ */
563
+ public function place($token, $shippingMethodCode = null)
564
+ {
565
+ if ($shippingMethodCode) {
566
+ $this->updateShippingMethod($shippingMethodCode);
567
+ }
568
+
569
+ $isNewCustomer = false;
570
+ switch ($this->getCheckoutMethod()) {
571
+ case Mage_Checkout_Model_Type_Onepage::METHOD_GUEST:
572
+ $this->_prepareGuestQuote();
573
+ break;
574
+ case Mage_Checkout_Model_Type_Onepage::METHOD_REGISTER:
575
+ $this->_prepareNewCustomerQuote();
576
+ $isNewCustomer = true;
577
+ break;
578
+ default:
579
+ $this->_prepareCustomerQuote();
580
+ break;
581
+ }
582
+
583
+ $this->_ignoreAddressValidation();
584
+ $this->_quote->collectTotals();
585
+ $service = Mage::getModel('sales/service_quote', $this->_quote);
586
+ $service->submitAll();
587
+ $this->_quote->save();
588
+
589
+ if ($isNewCustomer) {
590
+ try {
591
+ $this->_involveNewCustomer();
592
+ } catch (Exception $e) {
593
+ Mage::logException($e);
594
+ }
595
+ }
596
+
597
+ $this->_recurringPaymentProfiles = $service->getRecurringPaymentProfiles();
598
+ // TODO: send recurring profile emails
599
+
600
+ /** @var $order Mage_Sales_Model_Order */
601
+ $order = $service->getOrder();
602
+ if (!$order) {
603
+ return;
604
+ }
605
+ $this->_billingAgreement = $order->getPayment()->getBillingAgreement();
606
+
607
+ // commence redirecting to finish payment, if paypal requires it
608
+ if ($order->getPayment()->getAdditionalInformation(
609
+ Hps_Securesubmit_Model_Paypal_Checkout::PAYMENT_INFO_TRANSPORT_REDIRECT
610
+ )) {
611
+ $this->_redirectUrl = $this->_config->getExpressCheckoutCompleteUrl($token);
612
+ }
613
+
614
+ switch ($order->getState()) {
615
+ // even after placement paypal can disallow to authorize/capture, but will wait until bank transfers money
616
+ case Mage_Sales_Model_Order::STATE_PENDING_PAYMENT:
617
+ // TODO
618
+ break;
619
+ // regular placement, when everything is ok
620
+ case Mage_Sales_Model_Order::STATE_PROCESSING:
621
+ case Mage_Sales_Model_Order::STATE_COMPLETE:
622
+ case Mage_Sales_Model_Order::STATE_PAYMENT_REVIEW:
623
+ $order->sendNewOrderEmail();
624
+ break;
625
+ }
626
+ $this->_order = $order;
627
+ }
628
+
629
+ /**
630
+ * Make sure addresses will be saved without validation errors
631
+ */
632
+ private function _ignoreAddressValidation()
633
+ {
634
+ $this->_quote->getBillingAddress()->setShouldIgnoreValidation(true);
635
+ if (!$this->_quote->getIsVirtual()) {
636
+ $this->_quote->getShippingAddress()->setShouldIgnoreValidation(true);
637
+ if (!$this->_config->requireBillingAddress && !$this->_quote->getBillingAddress()->getEmail()) {
638
+ $this->_quote->getBillingAddress()->setSameAsBilling(1);
639
+ }
640
+ }
641
+ }
642
+
643
+ /**
644
+ * Determine whether redirect somewhere specifically is required
645
+ *
646
+ * @return string
647
+ */
648
+ public function getRedirectUrl()
649
+ {
650
+ return $this->_redirectUrl;
651
+ }
652
+
653
+ /**
654
+ * Return recurring payment profiles
655
+ *
656
+ * @return array
657
+ */
658
+ public function getRecurringPaymentProfiles()
659
+ {
660
+ return $this->_recurringPaymentProfiles;
661
+ }
662
+
663
+ /**
664
+ * Get created billing agreement
665
+ *
666
+ * @return Mage_Sales_Model_Billing_Agreement|null
667
+ */
668
+ public function getBillingAgreement()
669
+ {
670
+ return $this->_billingAgreement;
671
+ }
672
+
673
+ /**
674
+ * Return order
675
+ *
676
+ * @return Mage_Sales_Model_Order
677
+ */
678
+ public function getOrder()
679
+ {
680
+ return $this->_order;
681
+ }
682
+
683
+ /**
684
+ * Get checkout method
685
+ *
686
+ * @return string
687
+ */
688
+ public function getCheckoutMethod()
689
+ {
690
+ if ($this->getCustomerSession()->isLoggedIn()) {
691
+ return Mage_Checkout_Model_Type_Onepage::METHOD_CUSTOMER;
692
+ }
693
+ if (!$this->_quote->getCheckoutMethod()) {
694
+ if (Mage::helper('checkout')->isAllowedGuestCheckout($this->_quote)) {
695
+ $this->_quote->setCheckoutMethod(Mage_Checkout_Model_Type_Onepage::METHOD_GUEST);
696
+ } else {
697
+ $this->_quote->setCheckoutMethod(Mage_Checkout_Model_Type_Onepage::METHOD_REGISTER);
698
+ }
699
+ }
700
+ return $this->_quote->getCheckoutMethod();
701
+ }
702
+
703
+ /**
704
+ * Sets address data from exported address
705
+ *
706
+ * @param Mage_Sales_Model_Quote_Address $address
707
+ * @param HpsShippingInfo $exportedAddress
708
+ */
709
+ protected function _setExportedAddressData($address, $exportedAddress)
710
+ {
711
+ // Exported data is more priority if we came from Express Checkout button
712
+ $isButton = (bool)$this->_quote->getPayment()->getAdditionalInformation(self::PAYMENT_INFO_BUTTON);
713
+ if ($isButton) {
714
+ $regionModel = Mage::getModel('directory/region')->loadByCode($exportedAddress->address->state, $exportedAddress->address->country);
715
+ $address->setData('street', $exportedAddress->address->address);
716
+ $address->setCity($exportedAddress->address->city);
717
+ $address->setRegionId($regionModel->getId());
718
+ $address->setPostcode($exportedAddress->address->zip);
719
+ $address->setCountryId($exportedAddress->address->country);
720
+ }
721
+ }
722
+
723
+ /**
724
+ * Set create billing agreement flag to api call
725
+ *
726
+ * @return Hps_Securesubmit_Model_Paypal_Checkout
727
+ */
728
+ protected function _setBillingAgreementRequest()
729
+ {
730
+ if (!$this->_customerId || $this->_quote->hasNominalItems()) {
731
+ return $this;
732
+ }
733
+
734
+ $isRequested = $this->_isBARequested || $this->_quote->getPayment()
735
+ ->getAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_BILLING_AGREEMENT);
736
+
737
+ if (!($this->_config->allow_ba_signup == Hps_Securesubmit_Model_Config::EC_BA_SIGNUP_AUTO
738
+ || $isRequested && $this->_config->shouldAskToCreateBillingAgreement())) {
739
+ return $this;
740
+ }
741
+
742
+ if (!Mage::getModel('sales/billing_agreement')->needToCreateForCustomer($this->_customerId)) {
743
+ return $this;
744
+ }
745
+ $this->_api->setBillingType($this->_api->getBillingAgreementType());
746
+ return $this;
747
+ }
748
+
749
+ /**
750
+ * @return Hps_Securesubmit_Model_Api_Nvp
751
+ */
752
+ protected function _getApi()
753
+ {
754
+ if (null === $this->_api) {
755
+ $this->_api = Mage::getModel($this->_apiType)->setConfigObject($this->_config);
756
+ }
757
+ return $this->_api;
758
+ }
759
+
760
+ /**
761
+ * Attempt to collect address shipping rates and return them for further usage in instant update API
762
+ * Returns empty array if it was impossible to obtain any shipping rate
763
+ * If there are shipping rates obtained, the method must return one of them as default.
764
+ *
765
+ * @param Mage_Sales_Model_Quote_Address $address
766
+ * @param bool $mayReturnEmpty
767
+ * @return array|false
768
+ */
769
+ protected function _prepareShippingOptions(
770
+ Mage_Sales_Model_Quote_Address $address,
771
+ $mayReturnEmpty = false, $calculateTax = false
772
+ ) {
773
+ $options = array(); $i = 0; $iMin = false; $min = false;
774
+ $userSelectedOption = null;
775
+
776
+ foreach ($address->getGroupedAllShippingRates() as $group) {
777
+ foreach ($group as $rate) {
778
+ $amount = (float)$rate->getPrice();
779
+ if ($rate->getErrorMessage()) {
780
+ continue;
781
+ }
782
+ $isDefault = $address->getShippingMethod() === $rate->getCode();
783
+ $amountExclTax = Mage::helper('tax')->getShippingPrice($amount, false, $address);
784
+ $amountInclTax = Mage::helper('tax')->getShippingPrice($amount, true, $address);
785
+
786
+ $options[$i] = new Varien_Object(array(
787
+ 'is_default' => $isDefault,
788
+ 'name' => trim("{$rate->getCarrier()} - {$rate->getMethodTitle()}", ' -'),
789
+ 'code' => $rate->getCode(),
790
+ 'amount' => $amountExclTax,
791
+ ));
792
+ if ($calculateTax) {
793
+ $options[$i]->setTaxAmount(
794
+ $amountInclTax - $amountExclTax
795
+ + $address->getTaxAmount() - $address->getShippingTaxAmount()
796
+ );
797
+ }
798
+ if ($isDefault) {
799
+ $userSelectedOption = $options[$i];
800
+ }
801
+ if (false === $min || $amountInclTax < $min) {
802
+ $min = $amountInclTax;
803
+ $iMin = $i;
804
+ }
805
+ $i++;
806
+ }
807
+ }
808
+
809
+ if ($mayReturnEmpty && is_null($userSelectedOption)) {
810
+ $options[] = new Varien_Object(array(
811
+ 'is_default' => true,
812
+ 'name' => Mage::helper('paypal')->__('N/A'),
813
+ 'code' => 'no_rate',
814
+ 'amount' => 0.00,
815
+ ));
816
+ if ($calculateTax) {
817
+ $options[$i]->setTaxAmount($address->getTaxAmount());
818
+ }
819
+ } elseif (is_null($userSelectedOption) && isset($options[$iMin])) {
820
+ $options[$iMin]->setIsDefault(true);
821
+ }
822
+
823
+ // Magento will transfer only first 10 cheapest shipping options if there are more than 10 available.
824
+ if (count($options) > 10) {
825
+ usort($options, array(get_class($this),'cmpShippingOptions'));
826
+ array_splice($options, 10);
827
+ // User selected option will be always included in options list
828
+ if (!is_null($userSelectedOption) && !in_array($userSelectedOption, $options)) {
829
+ $options[9] = $userSelectedOption;
830
+ }
831
+ }
832
+
833
+ return $options;
834
+ }
835
+
836
+ /**
837
+ * Compare two shipping options based on their amounts
838
+ *
839
+ * This function is used as a callback comparison function in shipping options sorting process
840
+ * @see self::_prepareShippingOptions()
841
+ *
842
+ * @param Varien_Object $option1
843
+ * @param Varien_Object $option2
844
+ * @return integer
845
+ */
846
+ protected static function cmpShippingOptions(Varien_Object $option1, Varien_Object $option2)
847
+ {
848
+ if ($option1->getAmount() == $option2->getAmount()) {
849
+ return 0;
850
+ }
851
+ return ($option1->getAmount() < $option2->getAmount()) ? -1 : 1;
852
+ }
853
+
854
+ /**
855
+ * Try to find whether the code provided by PayPal corresponds to any of possible shipping rates
856
+ * This method was created only because PayPal has issues with returning the selected code.
857
+ * If in future the issue is fixed, we don't need to attempt to match it. It would be enough to set the method code
858
+ * before collecting shipping rates
859
+ *
860
+ * @param Mage_Sales_Model_Quote_Address $address
861
+ * @param string $selectedCode
862
+ * @return string
863
+ */
864
+ protected function _matchShippingMethodCode(Mage_Sales_Model_Quote_Address $address, $selectedCode)
865
+ {
866
+ $options = $this->_prepareShippingOptions($address, false);
867
+ foreach ($options as $option) {
868
+ if ($selectedCode === $option['code'] // the proper case as outlined in documentation
869
+ || $selectedCode === $option['name'] // workaround: PayPal may return name instead of the code
870
+ // workaround: PayPal may concatenate code and name, and return it instead of the code:
871
+ || $selectedCode === "{$option['code']} {$option['name']}"
872
+ ) {
873
+ return $option['code'];
874
+ }
875
+ }
876
+ return '';
877
+ }
878
+
879
+ /**
880
+ * Prepare quote for guest checkout order submit
881
+ *
882
+ * @return Hps_Securesubmit_Model_Paypal_Checkout
883
+ */
884
+ protected function _prepareGuestQuote()
885
+ {
886
+ $quote = $this->_quote;
887
+ $quote->setCustomerId(null)
888
+ ->setCustomerEmail($quote->getBillingAddress()->getEmail())
889
+ ->setCustomerIsGuest(true)
890
+ ->setCustomerGroupId(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID);
891
+ return $this;
892
+ }
893
+
894
+ /**
895
+ * Checks if customer with email coming from Express checkout exists
896
+ *
897
+ * @return int
898
+ */
899
+ protected function _lookupCustomerId()
900
+ {
901
+ return Mage::getModel('customer/customer')
902
+ ->setWebsiteId(Mage::app()->getWebsite()->getId())
903
+ ->loadByEmail($this->_quote->getCustomerEmail())
904
+ ->getId();
905
+ }
906
+
907
+ /**
908
+ * Prepare quote for customer registration and customer order submit
909
+ * and restore magento customer data from quote
910
+ *
911
+ * @return Hps_Securesubmit_Model_Paypal_Checkout
912
+ */
913
+ protected function _prepareNewCustomerQuote()
914
+ {
915
+ $quote = $this->_quote;
916
+ $billing = $quote->getBillingAddress();
917
+ $shipping = $quote->isVirtual() ? null : $quote->getShippingAddress();
918
+
919
+ $customerId = $this->_lookupCustomerId();
920
+ if ($customerId) {
921
+ $this->getCustomerSession()->loginById($customerId);
922
+ return $this->_prepareCustomerQuote();
923
+ }
924
+
925
+ $customer = $quote->getCustomer();
926
+ /** @var $customer Mage_Customer_Model_Customer */
927
+ $customerBilling = $billing->exportCustomerAddress();
928
+ $customer->addAddress($customerBilling);
929
+ $billing->setCustomerAddress($customerBilling);
930
+ $customerBilling->setIsDefaultBilling(true);
931
+ if ($shipping && !$shipping->getSameAsBilling()) {
932
+ $customerShipping = $shipping->exportCustomerAddress();
933
+ $customer->addAddress($customerShipping);
934
+ $shipping->setCustomerAddress($customerShipping);
935
+ $customerShipping->setIsDefaultShipping(true);
936
+ } elseif ($shipping) {
937
+ $customerBilling->setIsDefaultShipping(true);
938
+ }
939
+ /**
940
+ * @todo integration with dynamica attributes customer_dob, customer_taxvat, customer_gender
941
+ */
942
+ if ($quote->getCustomerDob() && !$billing->getCustomerDob()) {
943
+ $billing->setCustomerDob($quote->getCustomerDob());
944
+ }
945
+
946
+ if ($quote->getCustomerTaxvat() && !$billing->getCustomerTaxvat()) {
947
+ $billing->setCustomerTaxvat($quote->getCustomerTaxvat());
948
+ }
949
+
950
+ if ($quote->getCustomerGender() && !$billing->getCustomerGender()) {
951
+ $billing->setCustomerGender($quote->getCustomerGender());
952
+ }
953
+
954
+ Mage::helper('core')->copyFieldset('checkout_onepage_billing', 'to_customer', $billing, $customer);
955
+ $customer->setEmail($quote->getCustomerEmail());
956
+ $customer->setPrefix($quote->getCustomerPrefix());
957
+ $customer->setFirstname($quote->getCustomerFirstname());
958
+ $customer->setMiddlename($quote->getCustomerMiddlename());
959
+ $customer->setLastname($quote->getCustomerLastname());
960
+ $customer->setSuffix($quote->getCustomerSuffix());
961
+ $customer->setPassword($customer->decryptPassword($quote->getPasswordHash()));
962
+ $customer->setPasswordHash($customer->hashPassword($customer->getPassword()));
963
+ $customer->save();
964
+ $quote->setCustomer($customer);
965
+
966
+ return $this;
967
+ }
968
+
969
+ /**
970
+ * Prepare quote for customer order submit
971
+ *
972
+ * @return Hps_Securesubmit_Model_Paypal_Checkout
973
+ */
974
+ protected function _prepareCustomerQuote()
975
+ {
976
+ $quote = $this->_quote;
977
+ $billing = $quote->getBillingAddress();
978
+ $shipping = $quote->isVirtual() ? null : $quote->getShippingAddress();
979
+
980
+ $customer = $this->getCustomerSession()->getCustomer();
981
+ if (!$billing->getCustomerId() || $billing->getSaveInAddressBook()) {
982
+ $customerBilling = $billing->exportCustomerAddress();
983
+ $customer->addAddress($customerBilling);
984
+ $billing->setCustomerAddress($customerBilling);
985
+ }
986
+ if ($shipping && ((!$shipping->getCustomerId() && !$shipping->getSameAsBilling())
987
+ || (!$shipping->getSameAsBilling() && $shipping->getSaveInAddressBook()))) {
988
+ $customerShipping = $shipping->exportCustomerAddress();
989
+ $customer->addAddress($customerShipping);
990
+ $shipping->setCustomerAddress($customerShipping);
991
+ }
992
+
993
+ if (isset($customerBilling) && !$customer->getDefaultBilling()) {
994
+ $customerBilling->setIsDefaultBilling(true);
995
+ }
996
+ if ($shipping && isset($customerBilling) && !$customer->getDefaultShipping() && $shipping->getSameAsBilling()) {
997
+ $customerBilling->setIsDefaultShipping(true);
998
+ } elseif ($shipping && isset($customerShipping) && !$customer->getDefaultShipping()) {
999
+ $customerShipping->setIsDefaultShipping(true);
1000
+ }
1001
+ $quote->setCustomer($customer);
1002
+
1003
+ return $this;
1004
+ }
1005
+
1006
+ /**
1007
+ * Involve new customer to system
1008
+ *
1009
+ * @return Hps_Securesubmit_Model_Paypal_Checkout
1010
+ */
1011
+ protected function _involveNewCustomer()
1012
+ {
1013
+ $customer = $this->_quote->getCustomer();
1014
+ if ($customer->isConfirmationRequired()) {
1015
+ $customer->sendNewAccountEmail('confirmation');
1016
+ $url = Mage::helper('customer')->getEmailConfirmationUrl($customer->getEmail());
1017
+ $this->getCustomerSession()->addSuccess(
1018
+ Mage::helper('customer')->__('Account confirmation is required. Please, check your e-mail for confirmation link. To resend confirmation email please <a href="%s">click here</a>.', $url)
1019
+ );
1020
+ } else {
1021
+ $customer->sendNewAccountEmail();
1022
+ $this->getCustomerSession()->loginById($customer->getId());
1023
+ }
1024
+ return $this;
1025
+ }
1026
+
1027
+ /**
1028
+ * Get customer session object
1029
+ *
1030
+ * @return Mage_Customer_Model_Session
1031
+ */
1032
+ public function getCustomerSession()
1033
+ {
1034
+ return $this->_customerSession;
1035
+ }
1036
+ }
app/code/community/Hps/Securesubmit/Model/Paypal/Credit.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Hps
4
+ * @package Hps_Securesubmit
5
+ * @copyright Copyright (c) 2015 Heartland Payment Systems (https://www.magento.com)
6
+ * @license https://github.com/SecureSubmit/heartland-magento-extension/blob/master/LICENSE Custom License
7
+ */
8
+
9
+ /**
10
+ * PayPal Credit method
11
+ */
12
+ class Hps_Sescuresubmit_Model_Paypal_Credit extends Hps_Securesubmit_Model_Paypal
13
+ {
14
+ /**
15
+ * Payment method code
16
+ * @var string
17
+ */
18
+ protected $_code = 'hps_paypal_credit';
19
+
20
+ /**
21
+ * Checkout payment form
22
+ * @var string
23
+ */
24
+
25
+ protected $_formBlockType = 'hps_securesubmit/paypal_credit_form';
26
+ protected $_infoBlockType = 'hps_securesubmit/paypal_info';
27
+
28
+ /**
29
+ * Checkout redirect URL getter for onepage checkout
30
+ *
31
+ * @return string
32
+ */
33
+ public function getCheckoutRedirectUrl()
34
+ {
35
+ return Mage::getUrl('securesubmit/paypal/credit');
36
+ }
37
+ }
app/code/community/Hps/Securesubmit/Model/Report.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Hps_Securesubmit_Model_Report extends Mage_Core_Model_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ parent::_construct();
8
+ $this->_init('hps_securesubmit/report');
9
+ }
10
+
11
+ public function loadByOrderId($orderId)
12
+ {
13
+ $collection = $this->getCollection()
14
+ ->addFieldToFilter('order_id', $orderId);
15
+ return $collection->getFirstItem();
16
+ }
17
+ }
app/code/community/Hps/Securesubmit/Model/Resource/Report.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Hps_Securesubmit_Model_Resource_Report extends Mage_Core_Model_Resource_Db_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ $this->_init('hps_securesubmit/report', 'row_id');
8
+ }
9
+ }
app/code/community/Hps/Securesubmit/Model/Resource/Report/Collection.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Hps
4
+ * @package Hps_Securesubmit
5
+ * @copyright Copyright (c) 2015 Heartland Payment Systems (https://www.magento.com)
6
+ * @license https://github.com/SecureSubmit/heartland-magento-extension/blob/master/LICENSE Custom License
7
+ */
8
+
9
+ class Hps_Securesubmit_Model_Resource_Report_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
10
+ {
11
+ protected function _construct()
12
+ {
13
+ $this->_init('hps_securesubmit/report');
14
+ }
15
+ }
app/code/community/Hps/Securesubmit/Model/Session.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Hps
4
+ * @package Hps_Securesubmit
5
+ * @copyright Copyright (c) 2015 Heartland Payment Systems (https://www.magento.com)
6
+ * @license https://github.com/SecureSubmit/heartland-magento-extension/blob/master/LICENSE Custom License
7
+ */
8
+
9
+ /**
10
+ *
11
+ * Paypal transaction session namespace
12
+ *
13
+ * @author Magento Core Team <core@magentocommerce.com>
14
+ */
15
+ class Hps_Securesubmit_Model_Session extends Mage_Core_Model_Session_Abstract
16
+ {
17
+ public function __construct()
18
+ {
19
+ $this->init('hps_securesubmit');
20
+ }
21
+ }
22
+
app/code/community/Hps/Securesubmit/controllers/Adminhtml/Hps/.DS_Store ADDED
Binary file
app/code/community/Hps/Securesubmit/controllers/Adminhtml/Hps/._.DS_Store ADDED
Binary file
app/code/community/Hps/Securesubmit/controllers/Adminhtml/Hps/Paypal/ReportsController.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Hps_Securesubmit_Adminhtml_Hps_Paypal_ReportsController extends Mage_Adminhtml_Controller_Action
4
+ {
5
+ protected function _initAction()
6
+ {
7
+ $this->loadLayout();
8
+ // ->_setActiveMenu('hps_securesubmit/items');
9
+ // ->_addBreadcrumb(Mage::helper('adminhtml')->__('Items Manager'), Mage::helper('adminhtml')->__('Item Manager'));
10
+ return $this;
11
+ }
12
+
13
+ public function indexAction() {
14
+ $this->_initAction();
15
+ $this->_addContent($this->getLayout()->createBlock('hps_securesubmit/adminhtml_paypal_settlement_report'));
16
+ $this->renderLayout();
17
+ }
18
+ }
app/code/community/Hps/Securesubmit/controllers/PaypalController.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Hps
4
+ * @package Hps_Securesubmit
5
+ * @copyright Copyright (c) 2015 Heartland Payment Systems (https://www.magento.com)
6
+ * @license https://github.com/SecureSubmit/heartland-magento-extension/blob/master/LICENSE Custom License
7
+ */
8
+
9
+ /**
10
+ * Paypal Checkout Controller
11
+ */
12
+ class Hps_Securesubmit_PaypalController extends Hps_Securesubmit_Controller_Paypal_Abstract
13
+ {
14
+ /**
15
+ * Config mode type
16
+ *
17
+ * @var string
18
+ */
19
+ protected $_configType = 'hps_securesubmit/config';
20
+
21
+ /**
22
+ * Config method type
23
+ *
24
+ * @var string
25
+ */
26
+ protected $_configMethod = Hps_Securesubmit_Model_Config::METHOD_WPP_EXPRESS;
27
+
28
+ /**
29
+ * Checkout mode type
30
+ *
31
+ * @var string
32
+ */
33
+ protected $_checkoutType = 'hps_securesubmit/paypal_checkout';
34
+
35
+ /**
36
+ * Action for Bill Me Later checkout button (product view and shopping cart pages)
37
+ */
38
+ public function creditAction()
39
+ {
40
+ $this->_forward('start', 'paypal', 'securesubmit', array(
41
+ 'credit' => 1,
42
+ 'button' => $this->getRequest()->getParam('button')
43
+ ));
44
+ }
45
+ }
app/code/community/Hps/Securesubmit/etc/adminhtml.xml ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <acl>
4
+ <resources>
5
+ <admin>
6
+ <children>
7
+ <sales>
8
+ <children>
9
+ <order>
10
+ <children>
11
+ <actions>
12
+ <children>
13
+ <use_saved_card translate="title" module="hps_securesubmit">
14
+ <title>Use Saved Card</title>
15
+ <sort_order>110</sort_order>
16
+ </use_saved_card>
17
+ </children>
18
+ </actions>
19
+ </children>
20
+ </order>
21
+ </children>
22
+ </sales>
23
+ <report>
24
+ <children>
25
+ <salesroot>
26
+ <children>
27
+ <hps_paypal_settlement_reports translate="title">
28
+ <title>HPS PayPal Settlement Reports</title>
29
+ <children>
30
+ <view translate="title">
31
+ <title>View</title>
32
+ </view>
33
+ <fetch translate="title">
34
+ <title>Fetch</title>
35
+ </fetch>
36
+ </children>
37
+ </hps_paypal_settlement_reports>
38
+ </children>
39
+ </salesroot>
40
+ </children>
41
+ </report>
42
+ </children>
43
+ </admin>
44
+ </resources>
45
+ </acl>
46
+ <menu>
47
+ <report>
48
+ <children>
49
+ <salesroot translate="title">
50
+ <children>
51
+ <hps_paypal_settlement_reports translate="title">
52
+ <title>Hps PayPal Settlement Reports</title>
53
+ <action>adminhtml/hps_paypal_reports</action>
54
+ <sort_order>100</sort_order>
55
+ </hps_paypal_settlement_reports>
56
+ </children>
57
+ </salesroot>
58
+ </children>
59
+ </report>
60
+ </menu>
61
+ </config>
app/code/community/Hps/Securesubmit/sql/hps_securesubmit_setup/mysql4-upgrade-1.0.0-1.0.1.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /** @var $this Hps_Securesubmit_Model_Resource_Setup */
3
+ $installer = $this;
4
+ $installer->startSetup();
5
+
6
+ /*
7
+ * Add 'use_stored_card' column to 'sales_flat_quote_payment' and 'sales_flat_order_payment' tables.
8
+ */
9
+
10
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_payment'), 'securesubmit_use_stored_card', 'TINYINT UNSIGNED DEFAULT NULL');
11
+ $installer->getConnection()->addColumn($installer->getTable('sales/order_payment'), 'securesubmit_use_stored_card', 'TINYINT UNSIGNED DEFAULT NULL');
12
+
13
+ $installer->endSetup();
app/code/community/Hps/Securesubmit/sql/hps_securesubmit_setup/mysql4-upgrade-1.0.1-1.1.0.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $installer = $this;
4
+
5
+ $installer->startSetup();
6
+
7
+ $installer->run("
8
+
9
+ -- DROP TABLE IF EXISTS {$this->getTable('hps_securesubmit/report')};
10
+ CREATE TABLE {$this->getTable('hps_securesubmit/report')} (
11
+ `row_id` int(11) unsigned NOT NULL auto_increment,
12
+ `payer_email` varchar(255) NOT NULL default '',
13
+ `order_id` varchar(255) NOT NULL default '',
14
+ `invoice_id` varchar(255) NOT NULL default '',
15
+ `transaction_id` varchar(255) NOT NULL default '',
16
+ `last_known_status` varchar(255) NOT NULL default '',
17
+ `created_time` datetime NULL,
18
+ `update_time` datetime NULL,
19
+ PRIMARY KEY (`row_id`)
20
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
21
+
22
+ ");
23
+
24
+ $installer->endSetup();
app/design/frontend/base/default/template/securesubmit/.DS_Store ADDED
Binary file
app/design/frontend/base/default/template/securesubmit/paypal/review.phtml ADDED
@@ -0,0 +1,177 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Academic Free License (AFL 3.0)
8
+ * that is bundled with this package in the file LICENSE_AFL.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/afl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magento.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magento.com for more information.
20
+ *
21
+ * @category design
22
+ * @package base_default
23
+ * @copyright Copyright (c) 2006-2014 X.commerce, Inc. (http://www.magento.com)
24
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
+ */
26
+ /** @var $this Mage_Paypal_Block_Express_Review */
27
+ ?>
28
+ <div class="page-title">
29
+ <h1><?php echo $this->__('Review Order') ?></h1>
30
+ </div>
31
+ <?php echo $this->getMessagesBlock()->toHtml() ?>
32
+ <?php if ($this->getShippingAddress()): ?>
33
+ <div class="info-set col2-set">
34
+ <h2 class="legend"><?php echo $this->__('Shipping Information') ?></h2>
35
+ <div class="col-1">
36
+ <div class="box">
37
+ <div class="box-title">
38
+ <h3><?php echo $this->__('Shipping Address') ?><span class="separator"><?php if ($this->getCanEditShippingAddress()):?> | </span><a href="<?php echo $this->getEditUrl() ?>"><?php echo $this->__('Edit') ?></a><?php endif;?></h3>
39
+ </div>
40
+ <div class="box-content">
41
+ <address><?php echo $this->renderAddress($this->getShippingAddress())?></address>
42
+ </div>
43
+ </div>
44
+ </div>
45
+ <div class="col-2">
46
+ <div class="box">
47
+ <div class="box-title">
48
+ <h3><?php echo $this->__('Shipping Method') ?></h3>
49
+ </div>
50
+ <div class="box-content">
51
+ <form method="post" id="shipping_method_form" action="<?php echo $this->escapeHtml($this->getShippingMethodSubmitUrl()) ?>">
52
+ <?php if ($this->getCanEditShippingMethod() || !$this->getCurrentShippingRate()):?>
53
+ <?php if ($groups = $this->getShippingRateGroups()):?>
54
+ <?php $currentRate = $this->getCurrentShippingRate(); ?>
55
+ <fieldset>
56
+ <select name="shipping_method" id="shipping_method" style="width:250px;" class="required-entry">
57
+ <?php if (!$currentRate):?>
58
+ <option value=""><?php echo $this->__('Please select a shipping method...') ?></option>
59
+ <?php endif;?>
60
+ <?php foreach ($groups as $code => $rates):?>
61
+ <optgroup label="<?php echo $this->escapeHtml($this->getCarrierName($code)) ?>" style="font-style:normal;">
62
+ <?php foreach ($rates as $rate):?>
63
+ <option value="<?php echo $this->renderShippingRateValue($rate)?>"<?php echo ($currentRate === $rate) ? ' selected="selected"' : '' ;?>>
64
+ <?php echo $this->renderShippingRateOption($rate)?>
65
+ </option>
66
+ <?php endforeach;?>
67
+ </optgroup>
68
+ <?php endforeach;?>
69
+ </select>
70
+ </fieldset>
71
+ <p class="actions">
72
+ <button id="update_shipping_method_submit" type="submit" class="button"><span><span><?php echo $this->__('Update Shipping Method') ?></span></span></button>
73
+ </p>
74
+ <?php else: ?>
75
+ <p><strong><?php echo $this->__('Sorry, no quotes are available for this order at this time.') ?></strong></p>
76
+ <?php endif;?>
77
+ <?php else: ?>
78
+ <p><strong><?php echo $this->renderShippingRateOption($this->getCurrentShippingRate())?></strong></p>
79
+ <?php endif; ?>
80
+ </form>
81
+ </div>
82
+ </div>
83
+ </div>
84
+ </div>
85
+ <?php endif; ?>
86
+
87
+ <div class="info-set col2-set">
88
+ <h2 class="legend"><?php echo $this->__('Billing Information') ?></h2>
89
+ <div class="col-1">
90
+ <div class="box">
91
+ <div class="box-title">
92
+ <h3><?php echo $this->__('Payment Method') ?> <span class="separator">|</span>
93
+ <?php if($this->getEditUrl()):?><a href="<?php echo $this->getEditUrl() ?>"><?php echo $this->__('Edit Payment Information') ?></a> <?php endif ?>
94
+ </h3>
95
+ </div>
96
+ <div class="box-content">
97
+ <?php echo $this->escapeHtml($this->getPaymentMethodTitle()) ?>
98
+ </div>
99
+ </div>
100
+ </div>
101
+ </div>
102
+
103
+ <div class="info-set">
104
+ <h2 class="legend"><?php echo $this->__('Items in Your Shopping Cart') ?><span class="separator"> | </span><a href="<?php echo $this->getUrl('checkout/cart') ?>"><?php echo $this->__('Edit Shopping Cart') ?></a></h2>
105
+ <div id="details-reload">
106
+ <?php echo $this->getChildHtml('details') ?>
107
+ </div>
108
+ </div>
109
+ <form method="post" id="order_review_form" action="<?php echo $this->getPlaceOrderUrl() ?>">
110
+ <?php echo $this->getChildHtml('agreements'); ?>
111
+ <div class="buttons-set buttons-set-order" id="review-buttons-container">
112
+ <button type="button" id="review_button" value="<?php echo $this->__('Place Order') ?>" class="button btn-checkout"><span><span><?php echo $this->__('Place Order') ?></span></span></button>
113
+ <button type="button" id="review_submit" value="<?php echo $this->__('Place Order') ?>" class="button btn-checkout"><span><span><?php echo $this->__('Place Order') ?></span></span></button>
114
+ <span class="please-wait" id="review-please-wait" style="display:none;">
115
+ <img src="<?php echo $this->getSkinUrl('images/opc-ajax-loader.gif') ?>" alt="<?php echo $this->__('Submitting order information...') ?>" title="<?php echo $this->__('Submitting order information...') ?>" class="v-middle" /> <?php echo $this->__('Submitting order information...') ?>
116
+ </span>
117
+ </div>
118
+ </form>
119
+ <script type="text/javascript">
120
+ //<![CDATA[
121
+ // submit buttons are not needed when submitting with ajax
122
+ $('review_submit').hide();
123
+ if ($('update_shipping_method_submit')) {
124
+ $('update_shipping_method_submit').hide();
125
+ }
126
+
127
+ <?php if ($this->getUseAjax()):?>
128
+ OrderReviewController.prototype._submitOrder = function() {
129
+ if (this._canSubmitOrder) {
130
+ if (this._pleaseWait) {
131
+ this._pleaseWait.show();
132
+ }
133
+ new Ajax.Request(this.form.action, {
134
+ parameters: {isAjax: 1, method: 'POST'},
135
+ onSuccess: function(transport) {
136
+ try{
137
+ response = eval('(' + transport.responseText + ')');
138
+ } catch (e) {
139
+ response = {};
140
+ }
141
+ if (response.redirect) {
142
+ setLocation(response.redirect);
143
+ return;
144
+ }
145
+ if (response.success) {
146
+ setLocation('<?php echo $this->getSuccessUrl()?>');
147
+ return;
148
+ } else {
149
+ var msg = response.error_messages;
150
+ if (typeof(msg)=='object') {
151
+ msg = msg.join("\n");
152
+ }
153
+ if (msg) {
154
+ $('review-please-wait').hide();
155
+ alert(msg);
156
+ return;
157
+ }
158
+ }
159
+ $('review-please-wait').hide();
160
+ alert('<?php echo $this->jsQuoteEscape($this->__('Unknown Error. Please try again later.')); ?>');
161
+ return;
162
+ },
163
+ onFailure: function(){
164
+ alert('<?php echo $this->jsQuoteEscape($this->__('Server Error. Please try again.')) ?>');
165
+ $('review-please-wait').hide();
166
+ }
167
+ });
168
+ }
169
+ }
170
+ <?php endif ?>
171
+
172
+ PayPalExpressAjax = new OrderReviewController($('order_review_form'), $('review_button'),
173
+ $('shipping_method'), $('shipping_method_form'), 'details-reload'
174
+ );
175
+ PayPalExpressAjax.addPleaseWait($('review-please-wait'));
176
+ //]]>
177
+ </script>
app/design/frontend/base/default/template/securesubmit/paypal/review/details.phtml ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Academic Free License (AFL 3.0)
8
+ * that is bundled with this package in the file LICENSE_AFL.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/afl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magento.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magento.com for more information.
20
+ *
21
+ * @category design
22
+ * @package base_default
23
+ * @copyright Copyright (c) 2006-2014 X.commerce, Inc. (http://www.magento.com)
24
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
+ */
26
+
27
+ /**
28
+ * @see Mage_Paypal_Block_Express_Review_Details
29
+ */
30
+ ?>
31
+ <table id="details-table" class="data-table">
32
+ <?php if ($this->helper('tax')->displayCartBothPrices()): $colspan = $rowspan = 2; else: $colspan = $rowspan = 1; endif; ?>
33
+ <col />
34
+ <col width="1" />
35
+ <col width="1" />
36
+ <col width="1" />
37
+ <?php if ($this->helper('tax')->displayCartBothPrices()): ?>
38
+ <col width="1" />
39
+ <col width="1" />
40
+ <?php endif; ?>
41
+ <thead>
42
+ <tr>
43
+ <th rowspan="<?php echo $rowspan ?>"><?php echo $this->__('Product Name') ?></th>
44
+ <th colspan="<?php echo $colspan ?>" class="a-center"><?php echo $this->__('Price') ?></th>
45
+ <th rowspan="<?php echo $rowspan ?>" class="a-center"><?php echo $this->__('Qty') ?></th>
46
+ <th colspan="<?php echo $colspan ?>" class="a-center"><?php echo $this->__('Subtotal') ?></th>
47
+ </tr>
48
+ <?php if ($this->helper('tax')->displayCartBothPrices()): ?>
49
+ <tr>
50
+ <th class="a-right"><?php echo $this->helper('tax')->getIncExcTaxLabel(false) ?></th>
51
+ <th><?php echo $this->helper('tax')->getIncExcTaxLabel(true) ?></th>
52
+ <th class="a-right"><?php echo $this->helper('tax')->getIncExcTaxLabel(false) ?></th>
53
+ <th><?php echo $this->helper('tax')->getIncExcTaxLabel(true) ?></th>
54
+ </tr>
55
+ <?php endif; ?>
56
+ </thead>
57
+ <?php echo $this->getChildHtml('totals'); ?>
58
+ <tbody>
59
+ <?php foreach($this->getItems() as $_item): ?>
60
+ <?php echo $this->getItemHtml($_item) ?>
61
+ <?php endforeach ?>
62
+ </tbody>
63
+ </table>
64
+ <script type="text/javascript">decorateTable('details-table');</script>
app/design/frontend/base/default/template/securesubmit/paypal/review/shipping/method.phtml ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Academic Free License (AFL 3.0)
8
+ * that is bundled with this package in the file LICENSE_AFL.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/afl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magento.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magento.com for more information.
20
+ *
21
+ * @category design
22
+ * @package base_default
23
+ * @copyright Copyright (c) 2006-2014 X.commerce, Inc. (http://www.magento.com)
24
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
+ */
26
+ /** @var $this Mage_Paypal_Block_Express_Review */
27
+ ?>
28
+ <fieldset id="shipping-method-container">
29
+ <?php if ($this->getCanEditShippingMethod() || !$this->getCurrentShippingRate()):?>
30
+ <?php if ($groups = $this->getShippingRateGroups()):?>
31
+ <?php $currentRate = $this->getCurrentShippingRate(); ?>
32
+ <select name="shipping_method" id="shipping_method" style="width:250px;" class="required-entry">
33
+ <?php if (!$currentRate):?>
34
+ <option value=""><?php echo $this->__('Please select a shipping method...') ?></option>
35
+ <?php endif;?>
36
+ <?php foreach ($groups as $code => $rates):?>
37
+ <optgroup label="<?php echo $this->escapeHtml($this->getCarrierName($code)) ?>" style="font-style:normal;">
38
+ <?php foreach ($rates as $rate):?>
39
+ <option value="<?php echo $this->renderShippingRateValue($rate)?>"<?php echo ($currentRate === $rate) ? ' selected="selected"' : '' ;?>>
40
+ <?php echo $this->renderShippingRateOption($rate)?>
41
+ </option>
42
+ <?php endforeach;?>
43
+ </optgroup>
44
+ <?php endforeach;?>
45
+ </select>
46
+ <?php else: ?>
47
+ <p><strong><?php echo $this->__('Sorry, no quotes are available for this order at this time.') ?></strong></p>
48
+ <?php endif;?>
49
+ <?php else: ?>
50
+ <p><strong><?php echo $this->renderShippingRateOption($this->getCurrentShippingRate())?></strong></p>
51
+ <?php endif; ?>
52
+ </fieldset>
53
+ <div style="display:none" id="shipping_method_update"><p><?php echo $this->__('Please update order data to get shipping methods and rates') ?></p></div>
app/design/frontend/base/default/template/securesubmit/paypal/shortcut.phtml ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Academic Free License (AFL 3.0)
8
+ * that is bundled with this package in the file LICENSE_AFL.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/afl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magento.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magento.com for more information.
20
+ *
21
+ * @category design
22
+ * @package base_default
23
+ * @copyright Copyright (c) 2006-2014 X.commerce, Inc. (http://www.magento.com)
24
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
+ */
26
+ ?>
27
+ <?php
28
+ /**
29
+ * @var $this Mage_Paypal_Block_Express_Shortcut
30
+ */
31
+ ?>
32
+ <p class="paypal-logo">
33
+ <?php $shortcutHtmlId = $this->getShortcutHtmlId() ?>
34
+ <?php $bmlShortcutHtmlId = $this->getBmlShortcutHtmlId() ?>
35
+ <?php if ($this->isOrPositionBefore()): ?>
36
+ <span class="paypal-or"><?php echo $this->__('-OR-');?></span>
37
+ <?php endif; ?>
38
+ <a data-action="checkout-form-submit" id="<?php echo $shortcutHtmlId ?>" href="<?php echo $this->getCheckoutUrl()?>"><img src="<?php echo $this->getImageUrl()?>" alt="<?php echo Mage::helper('paypal')->__('Checkout with PayPal');?>" title="<?php echo Mage::helper('paypal')->__('Checkout with PayPal');?>" /></a>
39
+ <?php if ($this->getIsBmlEnabled()): ?>
40
+ <span class="paypal-or"><?php echo $this->__('-OR-');?></span>
41
+ </p>
42
+ <li class="bml-checkout-type">
43
+ <p class="paypal-logo">
44
+ <span class="bml_button">
45
+ <a id="<?php echo $bmlShortcutHtmlId ?>" href="<?php echo $this->getBmlCheckoutUrl()?>"><img src="<?php echo $this->getBmlImageUrl()?>" alt="<?php echo Mage::helper('paypal')->__('Checkout with PayPal Paypal Credit');?>" title="<?php echo Mage::helper('paypal')->__('Checkout with PayPal Paypal Credit');?>" /></a>
46
+ <a href="<?php echo $this->getMarketMessageUrl()?>"><img src="<?php echo $this->getMarketMessage()?>" /></a>
47
+ </span>
48
+ </p>
49
+ </li>
50
+ <?php else: ?>
51
+ </p>
52
+ <?php endif;?>
53
+ <?php if ($this->isOrPositionAfter()): ?>
54
+ <li>
55
+ <p class="paypal-logo">
56
+ <span class="paypal-or"><?php echo $this->__('-OR-');?></span>
57
+ </p>
58
+ </li>
59
+ <?php endif; ?>
60
+ <?php if ($this->getConfirmationUrl() || $this->getIsInCatalogProduct()): ?>
61
+ <?php if ($this->getIsInCatalogProduct()): ?>
62
+ <input type="hidden" id="pp_checkout_url" name="return_url" value="" />
63
+ <?php endif; ?>
64
+ <script type="text/javascript">
65
+ //<![CDATA[
66
+ $$('#<?php echo $shortcutHtmlId ?>','#<?php echo $bmlShortcutHtmlId ?>').invoke('observe', 'click', function(event) {
67
+ <?php if ($this->getConfirmationUrl()): ?>
68
+ if (confirm('<?php echo Mage::helper('core')->jsQuoteEscape($this->getConfirmationMessage())?>')) {
69
+ this.href = '<?php echo $this->getConfirmationUrl() ?>';
70
+ }
71
+ <?php endif; ?>
72
+ <?php if ($this->getIsInCatalogProduct()): ?>
73
+ $('pp_checkout_url').value = this.href;
74
+ productAddToCartForm.submit(this);
75
+ event.stop();
76
+ <?php endif; ?>
77
+ });
78
+ //]]>
79
+ </script>
80
+ <?php endif; ?>
js/securesubmit/checkout-form.js ADDED
@@ -0,0 +1,233 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ document.observe('dom:loaded', function () {
2
+ // Override default Payment save handler
3
+ if (typeof Payment != "undefined") {
4
+ if (typeof Payment.prototype._secureSubmitOldSave === 'undefined') {
5
+ var oldPayment = Object.clone(Payment.prototype);
6
+ Payment.prototype._secureSubmitOldSave = oldPayment.save;
7
+ }
8
+ Object.extend(Payment.prototype, {
9
+ save: function() {
10
+ if (this.currentMethod != 'hps_securesubmit') {
11
+ this._secureSubmitOldSave();
12
+ return;
13
+ }
14
+
15
+ if (checkout.loadWaiting != false) return;
16
+
17
+ // Use stored card checked, get existing token data
18
+ if (this.secureSubmitUseStoredCard()) {
19
+ var storedcardId = $('hps_securesubmit_stored_card_select').value;
20
+ checkout.setLoadWaiting('payment');
21
+ new Ajax.Request(this.secureSubmitGetTokenDataUrl, {
22
+ method: 'post',
23
+ parameters: {storedcard_id: storedcardId},
24
+ onSuccess: function(response) {
25
+ var data = response.responseJSON;
26
+ if (data && data.token) {
27
+ $('hps_securesubmit_expiration').value = parseInt(data.token.cc_exp_month);
28
+ $('hps_securesubmit_expiration_yr').value = data.token.cc_exp_year;
29
+ }
30
+ this.secureSubmitResponseHandler({
31
+ token_value: data.token.token_value,
32
+ token_type: null, // 'supt'?
33
+ token_expire: new Date().toISOString(),
34
+ card: {
35
+ number: data.token.cc_last4
36
+ }
37
+ });
38
+ }.bind(this),
39
+ onFailure: function() {
40
+ alert('Unknown error. Please try again.');
41
+ checkout.setLoadWaiting(false);
42
+ }
43
+ });
44
+ }
45
+ // Use stored card not checked, get new token
46
+ else {
47
+ var validator = new Validation(this.form);
48
+ if (this.validate() && validator.validate()) {
49
+ checkout.setLoadWaiting('payment');
50
+
51
+ hps.tokenize({
52
+ data: {
53
+ public_key: this.secureSubmitPublicKey,
54
+ number: $('hps_securesubmit_cc_number').value,
55
+ cvc: $('hps_securesubmit_cc_cid').value,
56
+ exp_month: $('hps_securesubmit_expiration').value,
57
+ exp_year: $('hps_securesubmit_expiration_yr').value
58
+ },
59
+ success: this.secureSubmitResponseHandler.bind(this),
60
+ error: this.secureSubmitResponseHandler.bind(this)
61
+ });
62
+ }
63
+ }
64
+ },
65
+ secureSubmitUseStoredCard: function () {
66
+ var storedCheckbox = $('hps_securesubmit_stored_card_checkbox');
67
+ return storedCheckbox && storedCheckbox.checked;
68
+ },
69
+ secureSubmitResponseHandler: function (response) {
70
+ var tokenField = $('hps_securesubmit_token'),
71
+ lastFourField = $('hps_securesubmit_cc_last_four');
72
+ tokenField.value = lastFourField.value = null;
73
+
74
+ if (response && response.error) {
75
+ if (response.message) {
76
+ alert(response.message);
77
+ }
78
+ checkout.setLoadWaiting(false);
79
+ } else if (response && response.token_value) {
80
+ tokenField.value = response.token_value;
81
+ lastFourField.value = response.card.number.substr(-4);
82
+
83
+ // Continue Magento checkout steps
84
+ new Ajax.Request(this.saveUrl, {
85
+ method:'post',
86
+ onComplete: this.onComplete,
87
+ onSuccess: this.onSave,
88
+ onFailure: checkout.ajaxFailure.bind(checkout),
89
+ parameters: Form.serialize(this.form)
90
+ });
91
+ } else {
92
+ alert('Unexpected error.')
93
+ }
94
+ }
95
+ });
96
+ }
97
+
98
+ function multishipping(multiForm){
99
+ var secureSubmit = {
100
+ save: function() {
101
+ if (payment.currentMethod != 'hps_securesubmit') {
102
+ multiForm.submit();
103
+ return;
104
+ }
105
+
106
+ document.getElementById('payment-continue').disable();
107
+
108
+ // Use stored card checked, get existing token data
109
+ if (this.secureSubmitUseStoredCard()) {
110
+ var storedcardId = $('hps_securesubmit_stored_card_select').value;
111
+
112
+ new Ajax.Request(this.secureSubmitGetTokenDataUrl, {
113
+ method: 'post',
114
+ parameters: {storedcard_id: storedcardId},
115
+ onSuccess: function(response) {
116
+ var data = response.responseJSON;
117
+ if (data && data.token) {
118
+ $('hps_securesubmit_expiration').value = parseInt(data.token.cc_exp_month);
119
+ $('hps_securesubmit_expiration_yr').value = data.token.cc_exp_year;
120
+ }
121
+ this.secureSubmitResponseHandler({
122
+ token_value: data.token.token_value,
123
+ token_type: null, // 'supt'?
124
+ token_expire: new Date().toISOString(),
125
+ card: {
126
+ number: data.token.cc_last4
127
+ }
128
+ });
129
+ }.bind(this),
130
+ onFailure: function() {
131
+ alert('Unknown error. Please try again.');
132
+ }
133
+ });
134
+ }
135
+ // Use stored card not checked, get new token
136
+ else {
137
+ var validator = new Validation(multiForm);
138
+ if (validator.validate()) {
139
+
140
+ hps.tokenize({
141
+ data: {
142
+ public_key: this.secureSubmitPublicKey,
143
+ number: $('hps_securesubmit_cc_number').value,
144
+ cvc: $('hps_securesubmit_cc_cid').value,
145
+ exp_month: $('hps_securesubmit_expiration').value,
146
+ exp_year: $('hps_securesubmit_expiration_yr').value
147
+ },
148
+ success: this.secureSubmitResponseHandler.bind(this),
149
+ error: this.secureSubmitResponseHandler.bind(this),
150
+ });
151
+ }
152
+ }
153
+ },
154
+ secureSubmitUseStoredCard: function () {
155
+ var storedCheckbox = $('hps_securesubmit_stored_card_checkbox');
156
+ return storedCheckbox && storedCheckbox.checked;
157
+ },
158
+ secureSubmitResponseHandler: function (response) {
159
+ var tokenField = $('hps_securesubmit_token'),
160
+ lastFourField = $('hps_securesubmit_cc_last_four');
161
+ tokenField.value = lastFourField.value = null;
162
+
163
+ if (response && response.error) {
164
+ if (response.message) {
165
+ alert(response.message);
166
+ }
167
+ } else if (response && response.token_value) {
168
+ tokenField.value = response.token_value;
169
+ lastFourField.value = response.card.number.substr(-4);
170
+
171
+ // Continue Magento checkout steps
172
+ document.getElementById('payment-continue').enable();
173
+ multiForm.submit();
174
+ } else {
175
+ alert('Unexpected error.')
176
+ }
177
+ }
178
+ };
179
+ return secureSubmit;
180
+ }
181
+
182
+ if (typeof OPC != "undefined") {
183
+ if (typeof OPC.prototype._secureSubmitOldSubmit === 'undefined') {
184
+ var oldOPC = Object.clone(OPC.prototype);
185
+ OPC.prototype._secureSubmitOldSubmit = oldOPC.submit;
186
+ }
187
+ Object.extend(OPC.prototype, {
188
+ save: function() {
189
+ if (this.sectionsToValidate[0].currentMethod != 'hps_securesubmit') {
190
+ this._secureSubmitOldSubmit();
191
+ return;
192
+ }
193
+ hps.tokenize({
194
+ data: {
195
+ public_key: this.secureSubmitPublicKey,
196
+ number: $('hps_securesubmit_cc_number').value,
197
+ cvc: $('hps_securesubmit_cc_cid').value,
198
+ exp_month: $('hps_securesubmit_expiration').value,
199
+ exp_year: $('hps_securesubmit_expiration_yr').value
200
+ },
201
+ success: this.secureSubmitResponseHandler.bind(this),
202
+ error: this.secureSubmitResponseHandler.bind(this)
203
+ });
204
+ },
205
+ secureSubmitResponseHandler: function (response) {
206
+ var tokenField = $('hps_securesubmit_token'),
207
+ lastFourField = $('hps_securesubmit_cc_last_four');
208
+ tokenField.value = lastFourField.value = null;
209
+
210
+ if (response && response.error) {
211
+ if (response.message) {
212
+ alert(response.message);
213
+ }
214
+ checkout.setLoadWaiting(false);
215
+ } else if (response && response.token_value) {
216
+ tokenField.value = response.token_value;
217
+ lastFourField.value = response.card.number.substr(-4);
218
+
219
+ this.setLoadWaiting(true);
220
+ var params = Form.serialize(this.form);
221
+ var request = new Ajax.Request(this.saveUrl, {
222
+ method: 'post',
223
+ parameters: params,
224
+ onSuccess: this.setResponse.bind(this),
225
+ onFailure: this.ajaxFailure.bind(this)
226
+ });;
227
+ } else {
228
+ alert('Unexpected error.')
229
+ }
230
+ }
231
+ });
232
+ }
233
+ });
lib/SecureSubmit/.DS_Store ADDED
Binary file
lib/SecureSubmit/LICENSE.txt ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ END-USER LICENSE AGREEMENT FOR SECURE SUBMIT
2
+ REVISED 11.13.13
3
+ IMPORTANT READ CAREFULLY:
4
+ This Heartland Payment Systems (�HPS�) End-User License Agreement (�EULA�) is a legal agreement between you (either an individual or a single entity) and HPS for the Secure Submit software product accompanying this EULA, which includes computer software and may include associated media, printed materials, and online or electronic documentation (�Software�). By downloading, copying or otherwise using the Software, you agree to the terms of this EULA and any additional terms and conditions that may be added to the EULA by HPS. BY DOWNLOADING, COPYING OR USING THE SOFTWARE YOU ACKNOWLEDGE THAT YOU HAVE READ, UNDERSTOOD, AND AGREED TO BE BOUND BY THE TERMS HEREIN. IF YOU HAVE ANY QUESTIONS ON THE TERMS OF USE, YOU SHOULD CONSULT WITH AN ATTORNEY BEFORE DOWNLOADING OR USING THE SOFTWARE. If you do not agree to the terms of this EULA, do not download or use the Software. As used herein, the words �you� and �your� mean the person or entity that has downloaded or used the Software. The words �we,� �us� and �our� means HPS. You must be at least 18 years of age in any of the fifty United States (or 21 in Puerto Rico) to use the Software. By downloading or using the Software, you agree that you will use the Software only in the United States or United States territories.
5
+ GRANT OF LICENSE
6
+ HPS hereby grants you a limited, non-exclusive, non-transferable, royalty-free license to make and use an unlimited number of copies of the Software accompanying this EULA: (1) solely for your internal purpose of integrating session-based data encryption into HPS�s payment processing platform; or (2) to make and distribute new programs incorporating the Software for the purpose of integrating to HPS�s payment processing platform for sublicensing to those who have an internal purpose of integrating session-based data encryption into HPS�s payment processing platform (the �Purpose�).
7
+ USE RESTRICTION
8
+ You acknowledge that the Software acquired hereunder can only be used for the Purpose. Use of the Software for any other purpose is a violation of this EULA and you agree to be subject to any and all penalties and remedies available at law or in equity for violation of intellectual property laws and treaties.
9
+ TERMINATION
10
+ Without prejudice to any other rights, HPS may terminate this EULA if you fail to comply with the terms and conditions of this EULA. In any event, this EULA shall terminate if you no longer have a purpose of integrating session-based data encryption into HPS�s payment processing platform. In the event of termination of this EULA, you must destroy all copies of the Software and all of its component parts.
11
+ RESERVATION OF RIGHTS
12
+ You agree that the Software is owned HPS and all rights not expressly granted herein are reserved by HPS.
13
+ PRODUCT MAINTENANCE
14
+ You understand and agree that HPS may provide updates to the Software from time to time but HPS shall have no obligation to provide maintenance or updates to you for Software licensed under this Agreement.
15
+ MISAPPROPRIATION
16
+ You shall promptly advise HPS, in writing, of any misappropriation or misuse of the Software by any person which may come to your attention.
17
+ U.S. GOVERNMENT RESTRICTED RIGHTS AND EXPORT RESTRICTIONS
18
+ The Software is provided with restricted rights. Use, duplication, or disclosure by the Government is subject to restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in Technical Data and Computer Software clause at DFARS 252.227-7013 or subparagraphs (c)(1) and (2) of the Commercial Computer Software Restricted Rights at 48 CFR 52.227-19, as applicable. Manufacturer is Heartland Payment Systems, 90 Nassau Street, Princeton, NJ 08542. You acknowledge that the Software acquired hereunder is subject to the export control laws and regulations of the U.S.A., and any amendments thereof. You acknowledge and agree that you will not, directly or indirectly, export the Software.
19
+ DISCLAIMER OF WARRANTY
20
+ THE SOFTWARE IS PROVIDED �AS IS� WITHOUT WARRANTY OF ANY KIND, WHATSOEVER, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. YOU ASSUME THE ENTIRE RISK ARISING OUT OF THE USE OR PERFORMANCE OF THE SOFTWARE.
21
+ DISCLAIMER OF DAMAGES AND LIMITATION OF LIABILITY
22
+
23
+ IN NO EVENT SHALL HPS, ITS BUSINESS PARTNERS, ITS OWNERS, DIRECTORS, EMPLOYEES OR AGENTS BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL, PUNITIVE, EXEMPLARY, CONSEQUENTIAL OR OTHER DAMAGES WHATSOEVER, INCLUDING BUT NOT LIMITED TO PROPERTY DAMAGE, LOSS OF USE, LOSS OF BUSINESS, ECONOMIC LOSS, LOSS OF DATA OR LOSS OF PROFITS, WITHOUT REGARD TO THE FORM OF ACTION (INCLUDING BUT NOT LIMITED TO CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTIONS) ARISING OUT OF OR IN CONNECTION WITH YOUR USE OF THE SOFTWARE, EVEN IF HPS, ITS BUSINESS PARTNERS, ITS OWNERS, DIRECTORS, EMPLOYEES OR AGENTS HAD BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE OR LOSS. BECAUSE SOME STATES OR JURISDICTIONS DO NOT ALLOW LIMITATION OR EXCLUSION OF DAMAGES, THE ABOVE LIMITATION MAY NOT FULLY APPLY TO YOU.
24
+
25
+ MISCELLANEOUS
26
+
27
+ This EULA shall be construed, interpreted and performed exclusively according to the laws of the State of New Jersey, United States of America, without giving effect to any principles of conflicts of law. You expressly agree that any action at law or in equity arising out of or directly or indirectly relating to this EULA or the Software shall be filed only in the federal or state courts sitting in Mercer County, New Jersey. You hereby consent and submit to personal jurisdiction of such courts for the purposes of any action related to the Software, your access or use thereof, or this EULA, and to extra-territorial service of process.
28
+
29
+ This EULA may not be assigned by you. HPS may assign their rights and obligations set forth in this EULA at any time. Should any part or provision of this EULA be held unlawful, void, invalid or unenforceable, that portion shall be deemed severable from this EULA shall not affect the validity and enforceability of any remaining provisions. Except as provided herein, this EULA constitutes the entire agreement between you and HPS pertaining to the download or use of the Software. Nothing herein shall alter or modify your agreements with HPS related to payment processing or other services or products provided to you by HPS. HPS�s failure to enforce any provision of this EULA or any additional terms shall not be deemed a waiver of such provisions nor of its right to enforce such provision. This EULA may be accepted in electronic form (e.g., by an electronic or other means of demonstrating assent) and your acceptance will be deemed binding between you and HPS. You hereby agree, without limitation, that you not will contest the validity or enforceability of this EULA.
30
+
31
+ CONTACT
32
+ Should you have any questions concerning this EULA, or if you desire to contact HPS for any reason, please write: Heartland Payment Systems, 90 Nassau Street, Princeton, NJ 08452. Attention: Legal.
lib/SecureSubmit/PRIVACY.txt ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Online Privacy & Cookie Policy Statement ("Privacy Policy")
2
+
3
+ Last modified on June 21, 2012
4
+
5
+ Heartland Payment Systems, Inc. (�Heartland,� �we,� �us,� �our�) recognizes the importance of maintaining effective privacy practices. This Privacy & Cookie Policy explains the online data collection and use policies that apply to the websites, mobile applications and online services (collectively �Services�) that are owned or controlled by Heartland and are linked to this Policy page.
6
+ Click below to jump to a particular topic:
7
+
8
+ 1. Information Collection and Use
9
+ 2. Sharing of Information
10
+ 3. Children�s Privacy
11
+ 4. Your Choices
12
+ 5. Data Protection and Storage
13
+ 6. Third-Party Websites and Services
14
+ 7. Changes to Our Privacy Policy
15
+ 8. Contact Us
16
+
17
+ 1. Information Collection and Use
18
+
19
+ We collect information from various sources to provide our Services to you, to analyze and improve our Services, and to communicate with you (e.g., to send you updates or notices about our organization, or emails about products or services that we believe may be of interest to you).
20
+ Information that you provide to us: We collect information that you provide to us when you set up an account with us, use our Services, or communicate with us. For example, if you register for an online account with us, then we may request your personal information (e.g., name, postal address, email address, DOB, telephone number, credit/debit card number, security code) or as applicable your business information, to complete the registration process, to process transactions, to send you information about our products, to send you promotional offers from third parties that we think may be of interest to you, or to otherwise provide our Services to you. Similarly, if you request information from us through an online contact form (or if you email us), we collect the information you provide (e.g., name, telephone number, email address) so that we can respond to you.
21
+
22
+ Information collected from third parties: We may collect information about you or your business from third parties in the course of providing our Services to you. For example, we may obtain information from our merchant customersor we may collect information from a school or university about consumer/students to provide services to those consumer/student. For some services,we may also collect information from third parties, such as credit reporting agencies or financial institutions, or other entities with information pertaining to the Services that we are providing to you.
23
+
24
+ Information collected through technology: When you visit our websites or mobile applications (or when you use any of our online services) we may collect certain information about your computer or device through technology such as cookies, web beacons, or other tracking/recording tools. The information collected may include, but is not limited to, IP addresses, referring URLs, access times, browser types, device types, mobile device identifiers, or information about your interactions with our websites, applications or services. (Note that a �cookie� is a text file placed on a computer�s hard drive or stored on a mobile device; a �web beacon,� also known as an Internet tag, pixel tag or clear GIF, is used to transmit information back to a web server.) We may use the information described in this paragraph to, among other things, (i) operate our Services, including by remembering information so that you will not have to re-enter it during your visit or the next time you sign in to your account, (ii) identify and protect our customers, (iii) control unauthorized use or abuse of our Services, (iv) provide custom, personalized content and information, which could include advertising, (v) monitor aggregate traffic patterns on our websites and services, and (vi) analyze and improve our Services.
25
+
26
+ 2. Sharing of Information
27
+
28
+ We do not sell or share your information with third parties outside Heartland and our group of companies (which include any parents, subsidiaries and affiliates), without your consent, except as described below and in this Policy:
29
+ We may share your information with our service providers and business partners (e.g., financial institutions or card brands that issue payment cards or are involved in transaction processing; entities that assist with fraud prevention or collections; merchants that sell gift cards managed through our websites or services; schools), who assist us in providing our Services. We may also share information with our service providers and business partners to help us monitor usage and other analytics regarding our Services, and to help us improve these offerings. When we share your information with our service providers and business partners, we only provide the information that these third parties reasonably need to perform their functions.
30
+ We may aggregate, or strip information of personally identifying characteristics, and may share that aggregated or anonymized information with third parties.
31
+ We may share or disclose your information if we determine, in our sole discretion, that we are required to do so under applicable law or regulatory requirements, or if we reasonably believe disclosure is necessary to prevent harm or financial loss, or in connection with preventing fraud or illegal activity, and/or to enforce our Terms of Use.
32
+ We reserve the right to transfer any information we collect in the event we sell or transfer all or a portion of our business or assets (including any shares in the company) or any portion or combination of our products, services, businesses and/or assets. Should such a transaction occur (whether a divestiture, merger, acquisition, bankruptcy, dissolution, reorganization, liquidation, or similar transaction or proceeding), we will use reasonable efforts to ensure that any transferred information is treated in a manner consistent with this Privacy Policy.
33
+ 3. Children�s Privacy
34
+
35
+ Heartland�s websites, mobile applications and services are intended for use strictly by adults. Heartland does not knowingly solicit or collect personal information from children under the age of 13. If Heartland obtains knowledge that it has collected personal information from a child under 13 in retrievable form in its files, Heartland will delete that information.
36
+
37
+ 4. Your Choices
38
+
39
+ Email Communications. From time to time, we may send you emails regarding updates to our websites, mobile applications or products/services, notices about our organization, or information about products/services we offer (or promotional offers from third parties) that we think may be of interest to you. If you wish to unsubscribe from such emails, simply click the �unsubscribe link� provided at the bottom of the email communication. Note that you cannot unsubscribe from certain Services-related email communications (e.g., account verification, confirmations of transactions, technical or legal notices).
40
+
41
+ Modifying Account Information. If you have an online account with us, you may have the ability to modify certain information in your account (e.g., your contact information) through �profile,� �account,� �settings,� or �preferences� options provided on the website or service. If you have any questions about modifying or updating any information in your account, please contact us at the email address, postal address, or telephone number provided below.
42
+
43
+ Cookie Controls. You may be able to set your Internet browser or mobile device to block cookies or other tracking/recording tools, including cookies associated with our websites or Services, or to indicate when a cookie is being set by us. However, it is important to remember that many of our websites or Services may not function properly if your cookies are disabled. For information and instructions about how to manage your cookies, refer to your Internet browser�s or mobile device�s technical information. Further information on how to adjust your cookie preferences through your browser is available at the external, third-party informational website www.allaboutcookies.org.
44
+
45
+ 5. Data Protection and Storage
46
+
47
+ Heartland maintains reasonable administrative, technical and physical safeguards to protect the confidentiality of information transmitted online, including but not limited to encryption, firewalls and SSL (Secure Sockets Layer). Heartland has implemented policies and practices pursuant to various security rules and regulations relating to the security and safeguarding of payment cardholder data, including the Payment Card Industry Data Security Standards (PCI-DSS). Heartland is not liable for loss of passwords due to user negligence. If you believe your password has been lost or compromised, we recommend that you immediately change your password.
48
+
49
+ We may store and process information in the United States or any other country in which Heartland or its parents, subsidiaries, affiliates or service providers maintain facilities. Heartland may transfer information that we collect about you, including personal information, to parents, subsidiaries, affiliates, or service providers across borders and from your country or jurisdiction to other countries or jurisdictions around the world. If you are located in the European Union or other regions with laws governing data collection and use that may differ from U.S. law, please note that we may transfer information, including personal information, to a country and jurisdiction that does not have the same data protection laws as your jurisdiction, and you consent to the transfer of information to the U.S. or any other country in which Heartland or its parent, subsidiaries, affiliates or service providers maintain facilities and to the use and disclosure of information as described in this Privacy Policy.
50
+
51
+ 6. Third-Party Websites and Services
52
+
53
+ Our websites or Services may provide links to (or links from) third-party websites or services � none of which are governed by this Privacy Policy. To the extent that any linked third-party websites or services you visit are not owned or controlled by Heartland, we are not responsible for those websites� or services� content or information practices. We strongly encourage you to review the privacy policies of any site or service before providing any personal information.
54
+
55
+ 7. Changes to Privacy Policy
56
+
57
+ We reserve the right to change this Privacy Policy from time to time in our sole discretion. We will post changes on this page and indicate the �last modified� date at the top of this page. Please check back often for any updates. Your continued use of our website, mobile application or services after any change in this Privacy Policy will constitute your acceptance of such change.
58
+
59
+ 8. Contact Us
60
+
61
+ For additional inquiries about this Privacy Policy, please contact Heartland at 1-888-798-3131 to speak to a legal representative, or send us an email at PrivacyPolicy@e-hps.com, or letter.
62
+
63
+ General Counsel Office
64
+ Heartland Payment Systems, Inc.
65
+ 90 Nassau Street
66
+ Princeton, NJ 08542
lib/SecureSubmit/README.md ADDED
@@ -0,0 +1,684 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # SecureSubmit PHP SDK
2
+
3
+ This PHP SDK makes it easy to process payments against the Heartland Payment Systems Portico Gateway.
4
+
5
+ ## Installation
6
+
7
+ Add this SDK to your PHP project and require it once.
8
+
9
+ ```php
10
+ <?php
11
+ require_once 'Hps.php';
12
+ ?>
13
+ ```
14
+
15
+ Using Composer? Require this library in your `composer.json`:
16
+
17
+ ```json
18
+ {
19
+ "require": {
20
+ "securesubmit/heartland-php": "*"
21
+ }
22
+ }
23
+ ```
24
+
25
+ and run `composer update` to pull down the dependency and update your autoloader.
26
+
27
+ ## Usage
28
+
29
+ Supported Gateway Calls
30
+
31
+ Credit:
32
+
33
+ - [CreditAccountVerify](#verify-a-card) (4.1)
34
+ - [CreditAddToBatch](#capturing-an-authorization) (4.2)
35
+ - [CreditAuth](#create-an-authorization) (4.3)
36
+ - CreditCPCEdit (4.4)
37
+ - [CreditReturn](#refund-a-credit-transaction) (4.7)
38
+ - [CreditReversal](#reverse-a-credit-transaction) (4.8)
39
+ - [CreditSale](#create-a-charge) (4.9)
40
+ - [CreditTxnEdit](#edit-a-credit-transaction) (4.10)
41
+ - [CreditVoid](#void-a-credit-transaction) (4.11)
42
+ - [ReportActivity](#list-credit-transactions) (10.4)
43
+ - [ReportTxnDetail](#get-a-credit-transaction) (10.8)
44
+ - BatchClose (10.3)
45
+
46
+ Check:
47
+
48
+ - [CheckSale](#run-a-check) (6.1)
49
+ - [CheckVoid](#void-a-check-transaction) (6.2)
50
+
51
+ Gift Card:
52
+
53
+ - [GiftCardActivate](#activate-a-gift-card) (8.1)
54
+ - [GiftCardAddValue](#add-value-to-a-gift-card) (8.2)
55
+ - GiftCardAlias (8.3)
56
+ - [GiftCardBalance](#check-a-gift-cards-balance) (8.4)
57
+ - [GiftCardDeactivate](#deactivate-a-gift-card) (8.6)
58
+ - [GiftCardReplace](#replace-a-gift-card) (8.8)
59
+ - [GiftCardReversal](#reverse-a-gift-card-transaction) (8.12)
60
+ - GiftCardReward (8.9)
61
+ - [GiftCardSale](#charge-a-gift-card) (8.10)
62
+ - [GiftCardVoid](#void-a-gift-card-transaction) (8.11)
63
+
64
+ ### Configuration / Authentication
65
+
66
+ Authentication with SecureSubmit is simple: you will pass your Secret API Key (found on your Account Settings screen) to the SDK via your configuration. Once you have done this, you can start making calls to the API immediately. Examples of authentication are as follows:
67
+
68
+ ```php
69
+ <?php
70
+
71
+ $config = new HpsServicesConfig();
72
+ $config->secretApiKey = "secret api key";
73
+ $config->versionNumber = '0000'; // this is provided to you during the certification process
74
+ $config->developerId = '000000'; // this is provided to you during the certification process
75
+
76
+ // Use this config when creating gateway service instances
77
+ $creditService = new HpsCreditService($config);
78
+ ```
79
+
80
+ ### Credit Transactions
81
+
82
+ #### Create a Card Holder
83
+
84
+ ```php
85
+ <?php
86
+
87
+ $cardHolder = new HpsCardHolder();
88
+ $address = new HpsAddress();
89
+ $address->zip = "47130"
90
+ $cardHolder->address = $address;
91
+ $cardHolder->firstName = 'Richard';
92
+ $cardHolder->lastName = 'Smith';
93
+ ```
94
+
95
+ #### Create a Payment Method
96
+
97
+ More often than not, you will want to send calls to the gateway using a single-use token obtained via one of our Javascript libraries:
98
+
99
+ ```php
100
+ <?php
101
+
102
+ $token = new HpsTokenData();
103
+ $token->tokenValue = $_POST['securesubmit_token'];
104
+ ```
105
+
106
+ Other times, you'll want to create a credit card object:
107
+
108
+ ```php
109
+ <?php
110
+
111
+ $card = new HpsCreditCard();
112
+ $card->number = "4111111111111111";
113
+ $card->expYear = 2015;
114
+ $card->expMonth = 12;
115
+ $card->cvv = 123;
116
+ ```
117
+
118
+ #### Create a Charge
119
+
120
+ The credit sale transaction authorizes a sale purchased with a credit card. The authorization is placed in the current open batch (should auto-close for e-commerce transactions). If a batch is not open, this transaction will create an open batch.
121
+
122
+ ##### Parameters
123
+
124
+ - Amount: The amount (in dollars)
125
+ - Currency: The currency (3-letter ISO code for currency).
126
+ - Card or Token: The payment method information.
127
+ - CardHolder (optional): The card holder information (used for AVS).
128
+
129
+ ##### Returns: `HpsCharge`
130
+
131
+ ```php
132
+ <?php
133
+
134
+ $creditService = new HpsCreditService($config);
135
+
136
+ // Charge a token
137
+ $creditService->charge(10, 'usd', $token, $cardHolder);
138
+
139
+ // Charge a card
140
+ $creditService->charge(10, 'usd', $card, $cardHolder);
141
+ ```
142
+
143
+ #### Create an Authorization
144
+
145
+ A credit authorization transaction authorizes a credit card transaction. The authorization is NOT placed in the batch. The credit authorization transaction can be committed by using the capture method.
146
+
147
+ ##### Parameters
148
+
149
+ - Amount: The amount (in dollars)
150
+ - Currency: The currency (3-letter ISO code for currency).
151
+ - Card: The credit card information.
152
+ - CardHolder (optional): The card holder information (used for AVS).
153
+
154
+ ##### Returns: `HpsAuthorization`
155
+
156
+ - Authorization Code: If authorized, authorization code returned by the Issuer
157
+ - Avs Result Code: If address verification requested, address verification result code returned by the Issuer
158
+ - Avs Result Text: Description of AVS result code
159
+ - Cvv Result Code: If card verification was provided in the request, card verification result code provided by the Issuer
160
+ - Cvv Result Text: Description of CVV result code
161
+ - Cpc Indicator: If the commercial card was specified in the request, the commercial card response indicator returned by the Issuer
162
+ - Authorized Amount: If supplied from the Issuer on a partial authorization, the authorized amount (less than the original or requested amount).
163
+ - Card Type: Card brand name
164
+ - Descriptor: Generated by concatenating the TxnDescriptor string from the transaction request to a configurable merchant DBA name. This string is sent to the card issuer for the Merchant Name.
165
+ - Token Data
166
+ - Token Rsp Code: The response code associated with the token Look-up or generation
167
+ - Token Rsp Message: The response text associated with the token Look-up or generation
168
+ - Token Value: The token used to replace swiped or manually entered card data for this transaction.
169
+
170
+ ##### Important
171
+
172
+ In order to complete the transaction and recieve funds, credit authorizations must be "captured". Please refer to the next section entitled "Capturing an Authorization" for additional details.
173
+
174
+ ```php
175
+ <?php
176
+
177
+ $creditService = new HpsCreditService($config);
178
+
179
+ // Authorize a token
180
+ $creditService->authorize(10, 'usd', $token, $cardHolder);
181
+
182
+ // Authorize a card
183
+ $creditService->authorize(10, 'usd', $card, $cardHolder);
184
+ ```
185
+
186
+ #### Capturing an Authorization
187
+
188
+ A Capture transaction adds a previous authorization transaction to the current open batch. If a batch is not open, this transaction will create one.
189
+
190
+ ##### Parameters
191
+
192
+ - Transaction Id: The authorization transaction Id.
193
+ - Amount (optional): An amount to charge (optional). Used if different from original authorization.
194
+
195
+ ##### Returns: `HpsReportTransactionDetails` (See `HpsAuthorization`)
196
+
197
+ - Original Transaction Id: If the transaction performed an action on a previous transaction, this field records the transaction that was acted upon.
198
+ - Masked Card Number: Card number (masked)
199
+ - Settlement Amount: Settlement amount
200
+ - Transaction Type: The transaction type (i.e. Authorize, Capture, Charge, Refund, etc...)
201
+ - Transaction Utc Date: Date of the transaction in universal time.
202
+ - Exceptions: Any exceptions which may have occured during the transaction.
203
+ - Memo: a free-form field (for Merchant reporting/record-keeping purposes only).
204
+ - Invoice Number: This will not be used at settlement. (for Merchant reporting/record-keeping purposes only).
205
+ - Customer Id: free-form field for Merchant use. This is intended to be the customer identification. (for Merchant reporting/record-keeping purposes only).
206
+
207
+ ```php
208
+ <?php
209
+
210
+ $creditService = new HpsCreditService($config);
211
+
212
+ // Authorize the token
213
+ $authorizeResponse = $creditService->authorize(10, 'usd', $token, $cardHolder);
214
+
215
+ // Record the transactionId from the authorization
216
+ $transactionId = $response->transactionId;
217
+
218
+ // Later, capture the authorization using the transactionId
219
+ $captureResponse = $creditService->capture($transactionid);
220
+ ```
221
+
222
+ #### Verify a Card
223
+
224
+ A credit account verify transaction is used to verify that the account is in good standing with the issuer. This is a zero dollar transaction with no associated authorization. Since VISA and other issuers have started assessing penalties for one dollar authorizations, this provides a way for merchants to accomplish the same task while avoiding these penalties.
225
+
226
+ ##### Parameters
227
+
228
+ - Card: The credit card information.
229
+ - CardHolder (optional): The card holder information (used for AVS).
230
+
231
+ ##### Returns: `HpsAccountVerify` (See `HpsAuthorization`)
232
+
233
+ ##### Important
234
+
235
+ American Express requires AVS data to be sent for card verification.
236
+
237
+ ```php
238
+ <?php
239
+
240
+ $creditService = new HpsCreditService($config);
241
+
242
+ $creditService->verify($card, $cardHolder);
243
+ ```
244
+
245
+ #### Refund a Credit Transaction
246
+
247
+ The credit return transaction returns funds to the cardholder. The transaction is generally used as a counterpart to a credit card transaction that needs to be reversed, and the batch containing the original transaction has already been closed. The credit return transaction is placed in the current open batch. If a batch is not open, this transaction will create an open batch.
248
+
249
+ ##### Parameters
250
+
251
+ - Amount: The amount (in specified currency)
252
+ - Currency: The currency (3-letter ISO code for currency).
253
+ - Transaction Id: The Id of the Transaction to be refunded.
254
+
255
+ ##### Returns: `HpsRefund`
256
+
257
+ ```php
258
+ <?php
259
+
260
+ $creditService = new HpsCreditService($config);
261
+
262
+ // Create the charge
263
+ $chargeResponse = $creditService->charge(10, 'usd', $token, $cardHolder);
264
+
265
+ // Record the transactionId from the charge
266
+ $transactionId = $chargeResponse->transactionId;
267
+
268
+ // Later, refund the charge
269
+ $refundResponse = $creditService->refund(10, 'usd', $transactionId);
270
+ ```
271
+
272
+ #### Reverse a Credit Transaction
273
+
274
+ A reverse transaction reverses a Charge or Authorize transaction from the active open authorizations or current open batch.
275
+
276
+ ##### Parameters
277
+
278
+ - Transaction ID: The transaction ID of charge to reverse.
279
+ - Amount: The amount (in specified currency).
280
+ - Currency: The currency (3-letter ISO code for currency).
281
+
282
+ ##### Returns: `HpsReversal`
283
+
284
+ ```php
285
+ <?php
286
+
287
+ $creditService = new HpsCreditService($config);
288
+
289
+ // Create the charge
290
+ $chargeResponse = $creditService->charge(10, 'usd', $token, $cardHolder);
291
+
292
+ // Record the transactionId from the charge
293
+ $transactionId = $chargeResponse->transactionId;
294
+
295
+ // Later, reverse the charge
296
+ $reverseResponse = $creditService->reverse($transactionId, 10, 'usd');
297
+ ```
298
+
299
+ #### Void a Credit Transaction
300
+
301
+ A credit void transaction is used to inactivate a transaction. The transaction must be an Authorize, Charge or Return. The transaction must be active in order to be voided. Authorize transactions do not have to be associated with a batch to be voided. Transactions may be voided after they are associated with a batch as long as the batch is not closed.
302
+
303
+ > _Note_: If the batch containing the original transaction has been closed, a Return transaction may be used to credit the cardholder.
304
+
305
+ > _Note_: If a transaction has been returned, it cannot be voided.
306
+
307
+ ##### Parameters
308
+
309
+ - Transaction ID - The transaction ID of charge to void.
310
+
311
+ ##### Returns: `HpsVoid`
312
+
313
+ ```php
314
+ <?php
315
+
316
+ // Create the charge
317
+ $chargeResponse = $creditService->charge(10, 'usd', $token, $cardHolder);
318
+
319
+ // Record the transactionId from the charge
320
+ $transactionId = $chargeResponse->transactionId;
321
+
322
+ // Later, void the charge
323
+ $voidResponse = $creditService->void($transactionId);
324
+ ```
325
+
326
+ #### Edit a Credit Transaction
327
+
328
+ An edit transaction changes the data on a previously approved Charge or Authorize transaction.
329
+
330
+ > _Note_: When the settlement amount of a transaction is altered with this service, the Portico Gateway does not send an update to the Issuer. For example, if the settlement amount of a transaction is reduced, a reversal for the difference is not sent. Likewise, if the amount is increased, an additional authorization is not sent. These additional operations are the responsibility of the POS. Additional features like this are being considered for future releases of the Portico Gateway.
331
+
332
+ ##### Parameters
333
+
334
+ - Transaction ID - The transaction ID of charge to void.
335
+ - Amount - If not null, revises (replaces) the authorized amount of the original auth. If null, does not affect the authorized amount of the original auth.
336
+ - Gratuity - If not null, revises (replaces) the gratuity amount information of the original auth. If null, does not affect the gratuity amount information, if any, of the original auth. This element is for informational purposes only and does not affect the authorized amount.
337
+
338
+ ##### Returns: `HpsTransaction`
339
+
340
+ ```php
341
+ <?php
342
+
343
+ $creditService = new HpsCreditService($config);
344
+
345
+ // Create an authorization
346
+ $authorizeResponse = $creditService->authorize(10, 'usd', $token, $cardHolder);
347
+
348
+ // Record the authorization's transactionId
349
+ $transactionId = $authorizeResponse->transactionId;
350
+
351
+ // Edit the authorization
352
+ $creditService->edit($transactionId, 15, 5);
353
+ ```
354
+
355
+ ### Reporting
356
+
357
+ #### List Credit Transactions
358
+
359
+ Gets a list of transaction summaries between a set of dates and filtered if specified.
360
+
361
+ ##### Parameters
362
+
363
+ - Start: Start date.
364
+ - End: End date.
365
+ - Filter By (optional): filter the result set by transaction type.
366
+
367
+ ##### Returns: `array(HpsReportTransactionSummary)`
368
+
369
+ ```php
370
+ <?php
371
+
372
+ $creditService = new HpsCreditService($config);
373
+
374
+ $dateFormat = 'Y-m-d\TH:i:s.00\Z';
375
+ $dateMinus10 = new DateTime();
376
+ $dateMinus10->sub(new DateInterval('P10D'));
377
+ $dateMinus10Utc = gmdate($dateFormat, $dateMinus10->Format('U'));
378
+ $nowUtc = gmdate($dateFormat);
379
+
380
+ $transactions = $creditService->listTransactions($dateMinus10Utc, $nowUtc, HpsTransactionType::CHARGE);
381
+ ```
382
+
383
+ #### Get a Credit Transaction
384
+
385
+ Gets an HPS transaction given a Transaction ID.
386
+
387
+ ##### Parameters
388
+
389
+ - Transaction ID: The transaction ID for the transaction.
390
+
391
+ ##### Returns: `HpsReportTransactionDetails`
392
+
393
+ ```php
394
+ <?php
395
+
396
+ $creditService = new HpsCreditService($config);
397
+
398
+ $dateFormat = 'Y-m-d\TH:i:s.00\Z';
399
+ $dateMinus10 = new DateTime();
400
+ $dateMinus10->sub(new DateInterval('P10D'));
401
+ $dateMinus10Utc = gmdate($dateFormat, $dateMinus10->Format('U'));
402
+ $nowUtc = gmdate($dateFormat);
403
+
404
+ $transactions = $creditService->listTransactions($dateMinus10Utc, $nowUtc, HpsTransactionType::CAPTURE);
405
+
406
+ $charge = $creditService->get($transactios[0]->transactionId);
407
+ ```
408
+
409
+ ### Check Transactions
410
+
411
+ #### Create a Check Holder
412
+
413
+ ```php
414
+ <?php
415
+
416
+ $checkHolder = new HpsCheckHolder();
417
+ $checkHolder->address = new HpsAddress();
418
+ $checkHolder->address->address = '6860 Dallas Parkway';
419
+ $checkHolder->address->city = 'Plano';
420
+ $checkHolder->address->state = 'TX';
421
+ $checkHolder->address->zip = '75024';
422
+ $checkHolder->dlNumber = '1234567';
423
+ $checkHolder->dlState = 'TX';
424
+ $checkHolder->firstName = 'John';
425
+ $checkHolder->lastName = 'Doe';
426
+ $checkHolder->phone = '1234567890';
427
+ ```
428
+
429
+ #### Create a Check
430
+
431
+ ```php
432
+ <?php
433
+
434
+ $check = new HpsCheck();
435
+ $check->accountNumber = '24413815';
436
+ $check->routingNumber = '490000018';
437
+ $check->checkType = HpsCheckType::PERSONAL;
438
+ $check->secCode = HpsSECCode::PPD;
439
+ $check->accountType = HpsAccountType::CHECKING;
440
+ $check->checkHolder = $checkHolder;
441
+ ```
442
+
443
+ #### Run a Check
444
+
445
+ ##### Parameters
446
+
447
+ - Check: The check.
448
+ - Amount: The amount (in dollars)
449
+
450
+ ##### Returns: `HpsCheckResponse`
451
+
452
+ ```php
453
+ <?php
454
+
455
+ $checkService = new HpsCheckService($config);
456
+
457
+ $checkService->sale($check, 10);
458
+ ```
459
+
460
+ #### Void a Check Transaction
461
+
462
+ ##### Parameters
463
+
464
+ - Transaction ID: the transaction ID.
465
+
466
+ ##### Returns: `HpsCheckResponse`
467
+
468
+ ```php
469
+ <?php
470
+
471
+ $checkService = new HpsCheckService($config);
472
+
473
+ // Run a Check
474
+ $saleResponse = $checkService->sale($check, 10);
475
+
476
+ // Record the sale's transactionId
477
+ $transactionId = $saleResponse->transactionId;
478
+
479
+ // Later, void the transaction with the transactionId
480
+ $voidResponse = $checkService->void($transactionId);
481
+ ```
482
+
483
+ ### Gift Card Transactions
484
+
485
+ #### Create a Gfit Card
486
+
487
+ ```php
488
+ <?php
489
+
490
+ $giftCard = new HpsGiftCard();
491
+ $giftCard->number = "5022440000000000098";
492
+ $giftCard->expMonth = '12';
493
+ $giftCard->expYear = '39';
494
+ ```
495
+
496
+ #### Charge a Gift Card
497
+
498
+ ##### Parameters
499
+
500
+ - Amount: The amount (in dollars)
501
+ - Currency: The currency (3-letter ISO code for currency).
502
+ - Card or Token: The payment method information.
503
+ - CardHolder (optional): The card holder information (used for AVS).
504
+
505
+ ##### Returns: `HpsGiftCardSale`
506
+
507
+ ```php
508
+ <?php
509
+
510
+ $giftService = new HpsGiftCardService($config);
511
+
512
+ $giftService->sale($giftCard, 10);
513
+ ```
514
+
515
+ #### Activate a Gift Card
516
+
517
+ ##### Parameters
518
+
519
+ - Amount: The amount (in dollars)
520
+ - Currency: The currency (3-letter ISO code for currency).
521
+ - Gift Card: The gift card.
522
+
523
+ ##### Returns: `HpsGiftCardActivate`
524
+
525
+ ```php
526
+ <?php
527
+
528
+ $giftService = new HpsGiftCardService($config);
529
+
530
+ $giftService->activate(100, 'usd', $giftCard);
531
+ ```
532
+
533
+ #### Add Value to a Gift Card
534
+
535
+ ##### Parameters
536
+
537
+ - Amount: The amount (in dollars)
538
+ - Currency: The currency (3-letter ISO code for currency).
539
+ - Gift Card: The gift card.
540
+
541
+ ##### Returns: `HpsGiftCardAddValue`
542
+
543
+ ```php
544
+ <?php
545
+
546
+ $giftService = new HpsGiftCardService($config);
547
+
548
+ $giftService->activate(100, 'usd', $giftCard);
549
+ ```
550
+
551
+ #### Check a Gift Card's Balance
552
+
553
+ ##### Parameters
554
+
555
+ - Gift Card: The gift card.
556
+
557
+ ##### Returns: `HpsGiftCardBalance`
558
+
559
+ ```php
560
+ <?php
561
+
562
+ $giftService = new HpsGiftCardService($config);
563
+
564
+ $balanceResponse = $giftService->balance($giftCard);
565
+
566
+ // Record the balance
567
+ $balance = $balanceResponse->balanceAmount;
568
+ ```
569
+
570
+ #### Deactivate a Gift Card
571
+
572
+ ##### Parameters
573
+
574
+ - Gift Card: The gift card.
575
+
576
+ ##### Returns: `HpsGiftCardDeactivate`
577
+
578
+ ```php
579
+ <?php
580
+
581
+ $giftService = new HpsGiftCardService($config);
582
+
583
+ $giftService->deactivate($giftCard);
584
+ ```
585
+
586
+ #### Replace a Gift Card
587
+
588
+ ##### Parameters
589
+
590
+ - Old Gift Card: The gift card to be replaced.
591
+ - New Gift Card: The gift card to replace the old.
592
+
593
+ ##### Returns: `HpsGiftCardReplace`
594
+
595
+ ```php
596
+ <?php
597
+
598
+ $giftService = new HpsGiftCardService($config);
599
+
600
+ $giftService->replace($oldGiftCard, $newGiftCard);
601
+ ```
602
+
603
+ #### Reverse a Gift Card Transaction
604
+
605
+ ##### Parameters
606
+
607
+ - Transaction ID: The transaction ID.
608
+
609
+ ##### Returns: `HpsGiftCardReversal`
610
+
611
+ ```php
612
+ <?php
613
+
614
+ $giftService = new HpsGiftCardService($config);
615
+
616
+ // Charge the Gift Card
617
+ $saleResponse = $giftService->sale($giftCard, 10);
618
+
619
+ // Record the transactionId
620
+ $transactionId = $saleResponse->transactionId;
621
+
622
+ // Later, reverse the transaction
623
+ $reverseResponse = $giftService->reverse($transactionId);
624
+ ```
625
+
626
+ #### Void a Gift Card Transaction
627
+
628
+ ##### Parameters
629
+
630
+ - Transaction ID: The transaction ID.
631
+
632
+ ##### Returns: `HpsGiftCardVoid`
633
+
634
+ ```php
635
+ <?php
636
+
637
+ $giftService = new HpsGiftCardService($config);
638
+
639
+ // Charge the Gift Card
640
+ $saleResponse = $giftService->sale($giftCard, 10);
641
+
642
+ // Record the transactionId
643
+ $transactionId = $saleResponse->transactionId;
644
+
645
+ // Later, void the transaction
646
+ $voidResponse = $giftService->void($transactionId);
647
+ ```
648
+
649
+ ## Testing
650
+
651
+ Clone this repository locally, install dependencies with Composer, and run PHPUnit against the provided tests.
652
+
653
+ ```
654
+ $ git clone https://github.com/SecureSubmit/heartland-php.git
655
+ $ cd heartland-php
656
+ $ composer install
657
+ $ php vendor/bin/phpunit -c tests/phpunit.xml
658
+ ```
659
+
660
+ This will run through all of our test suites by default. To run a single test suite, pass the `--testsuite`
661
+ option to `php vendor/bin/phpunit` with one of the following values:
662
+
663
+ - `fluent`
664
+ - `gateway-check`
665
+ - `gateway-credit`
666
+ - `gateway-debit`
667
+ - `gateway-giftcard`
668
+ - `gateway-token`
669
+ - `general`
670
+ - `certification`
671
+
672
+ Example:
673
+
674
+ ```
675
+ $ php vendor/bin/phpunit -c tests/phpunit.xml --testsuite certification
676
+ ```
677
+
678
+ ## Contributing
679
+
680
+ 1. Fork it
681
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
682
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
683
+ 4. Push to the branch (`git push origin my-new-feature`)
684
+ 5. Create new Pull Request
lib/SecureSubmit/index.php ADDED
@@ -0,0 +1 @@
 
1
+ <?php
lib/SecureSubmit/src/Abstractions/HpsBuilderAbstract.php ADDED
@@ -0,0 +1,168 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ abstract class HpsBuilderAbstract
4
+ {
5
+ /** @var array(HpsBuilderAction) */
6
+ public $builderActions = array();
7
+
8
+ /** @var bool */
9
+ public $executed = false;
10
+
11
+ /** @var array(callable) */
12
+ public $validations = array();
13
+
14
+ /** @var HpsRestGatewayService */
15
+ protected $service = null;
16
+
17
+ /**
18
+ * @param HpsGatewayServiceAbstract $service
19
+ *
20
+ * @return HpsBuilderAbstract
21
+ */
22
+ public function __construct($service)
23
+ {
24
+ $this->service = $service;
25
+ }
26
+
27
+ /**
28
+ * @return HpsBuilderAbstract
29
+ */
30
+ public function execute()
31
+ {
32
+ foreach ($this->builderActions as $action) {
33
+ call_user_func_array($action->action, $action->arguments);
34
+ }
35
+ $this->validate();
36
+ $this->executed = true;
37
+ return $this;
38
+ }
39
+
40
+ /**
41
+ * @return HpsBuilderAbstract
42
+ */
43
+ public function addAction($action)
44
+ {
45
+ $this->builderActions[] = $action;
46
+ return $this;
47
+ }
48
+
49
+ /**
50
+ * @throws HpsException
51
+ */
52
+ public function checkStatus()
53
+ {
54
+ if (!$this->executed) {
55
+ throw new HpsException('Builder actions not executed');
56
+ }
57
+ }
58
+
59
+ /**
60
+ * Allows for automatic setter functions
61
+ * in child classes.
62
+ *
63
+ * @param string $name
64
+ * @param array $args
65
+ *
66
+ * @throws HpsUnknownPropertyException
67
+ *
68
+ * @return HpsBuilderAbstract
69
+ */
70
+ public function __call($name, array $args)
71
+ {
72
+ switch (true) {
73
+ case substr($name, 0, 4) == 'with':
74
+ $property = substr($name, 4);
75
+ $property = strtolower(substr($property, 0, 1)) . substr($property, 1);
76
+ $this->setPropertyIfExists($property, $args[0]);
77
+ break;
78
+ default:
79
+ return false;
80
+ break;
81
+ }
82
+ return $this;
83
+ }
84
+
85
+ /**
86
+ * @throws Exception
87
+ */
88
+ protected function validate()
89
+ {
90
+ $actions = $this->compileActionCounts();
91
+ foreach ($this->validations as $validation) {
92
+ $result = call_user_func_array($validation['callback'], array($actions));
93
+ if (!$result) {
94
+ $class = $validation['exceptionType'];
95
+ throw new $class($validation['exceptionMessage'], 0);
96
+ }
97
+ }
98
+ }
99
+
100
+ /**
101
+ * @return array
102
+ */
103
+ protected function compileActionCounts()
104
+ {
105
+ $counts = array();
106
+
107
+ foreach ($this->builderActions as $action) {
108
+ $counts[$action->name] = isset($counts[$action->name]) ? $counts[$action->name]+1 : 1;
109
+ }
110
+
111
+ return $counts;
112
+ }
113
+
114
+ /**
115
+ * @param callable $callback
116
+ * @param string $exceptionType
117
+ * @param string $exceptionMessage
118
+ *
119
+ * @return HpsBuilderAbstract
120
+ */
121
+ protected function addValidation($callback, $exceptionType, $exceptionMessage = '')
122
+ {
123
+ $this->validations[] = array(
124
+ 'callback' => $callback,
125
+ 'exceptionType' => $exceptionType,
126
+ 'exceptionMessage' => $exceptionMessage,
127
+ );
128
+ return $this;
129
+ }
130
+
131
+ /**
132
+ * Sets a property if it exists on the current object.
133
+ *
134
+ * @param string $property
135
+ * @param mixed $value
136
+ *
137
+ * @throws HpsUnknownPropertyException
138
+ *
139
+ * @return null
140
+ */
141
+ private function setPropertyIfExists($property, $value)
142
+ {
143
+ if (property_exists($this, $property)) {
144
+ if ($value == null) {
145
+ return $this;
146
+ }
147
+
148
+ $action = new HpsBuilderAction($property, array($this, 'setProperty'));
149
+ $action->arguments = array($property, $value);
150
+ $this->addAction($action);
151
+ } else {
152
+ throw new HpsUnknownPropertyException($this, $property);
153
+ }
154
+ }
155
+
156
+ /**
157
+ * Sets a property on the current object.
158
+ *
159
+ * @param string $property
160
+ * @param mixed $value
161
+ *
162
+ * @return null
163
+ */
164
+ protected function setProperty($property, $value)
165
+ {
166
+ $this->{$property} = $value;
167
+ }
168
+ }
lib/SecureSubmit/src/Abstractions/HpsGatewayServiceAbstract.php ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ abstract class HpsGatewayServiceAbstract
4
+ {
5
+ protected $_config = null;
6
+ protected $_baseConfig = null;
7
+ protected $_url = null;
8
+ protected $_amount = null;
9
+ protected $_currency = null;
10
+ protected $_filterBy = null;
11
+
12
+ public function __construct(HpsServicesConfig $config = null)
13
+ {
14
+ if ($config != null) {
15
+ $this->_config = $config;
16
+ }
17
+ }
18
+
19
+ public function servicesConfig()
20
+ {
21
+ return $this->_config;
22
+ }
23
+
24
+ public function setServicesConfig($value)
25
+ {
26
+ $this->_config = $value;
27
+ }
28
+
29
+ abstract protected function processResponse($curlResponse, $curlInfo, $curlError);
30
+
31
+ protected function submitRequest($url, $headers, $data = null, $httpVerb = 'POST', $keyType = HpsServicesConfig::KEY_TYPE_SECRET, $options = null)
32
+ {
33
+ if ($this->_isConfigInvalid()) {
34
+ throw new HpsAuthenticationException(
35
+ HpsExceptionCodes::INVALID_CONFIGURATION,
36
+ "The HPS SDK has not been properly configured. "
37
+ ."Please make sure to initialize the config "
38
+ ."in a service constructor."
39
+ );
40
+ }
41
+
42
+ if (!$this->_config->validateApiKey($keyType)) {
43
+ $type = $this->_config->getKeyType($keyType);
44
+ $message = "The HPS SDK requires a valid {$keyType} API key to be used";
45
+ if ($type == $keyType) {
46
+ $message .= ".";
47
+ } else {
48
+ $message .= ", but a(n) {$type} key is currently configured.";
49
+ }
50
+ throw new HpsAuthenticationException(
51
+ HpsExceptionCodes::INVALID_CONFIGURATION,
52
+ $message
53
+ );
54
+ }
55
+
56
+ try {
57
+ $request = curl_init();
58
+ curl_setopt($request, CURLOPT_URL, $url);
59
+ curl_setopt($request, CURLOPT_CONNECTTIMEOUT, 60);
60
+ curl_setopt($request, CURLOPT_TIMEOUT, 60);
61
+ curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
62
+ curl_setopt($request, CURLOPT_SSL_VERIFYPEER, false);
63
+ curl_setopt($request, CURLOPT_SSL_VERIFYHOST, false);
64
+ if ($data != null) {
65
+ curl_setopt($request, CURLOPT_CUSTOMREQUEST, $httpVerb);
66
+ curl_setopt($request, CURLOPT_POSTFIELDS, $data);
67
+ }
68
+ curl_setopt($request, CURLOPT_HTTPHEADER, $headers);
69
+ curl_setopt($request, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS);
70
+
71
+ if ($this->_config->useProxy) {
72
+ curl_setopt($request, CURLOPT_PROXY, $this->_config->proxyOptions['proxy_host']);
73
+ curl_setopt($request, CURLOPT_PROXYPORT, $this->_config->proxyOptions['proxy_port']);
74
+ }
75
+ $curlResponse = curl_exec($request);
76
+ $curlInfo = curl_getinfo($request);
77
+ $curlError = curl_errno($request);
78
+
79
+ if ($curlError == 28) {
80
+ throw new HpsException("gateway_time-out");
81
+ }
82
+
83
+ return $this->processResponse($curlResponse, $curlInfo, $curlError);
84
+ } catch (Exception $e) {
85
+ throw new HpsGatewayException(
86
+ $e->getCode() != null ? $e->getCode() : HpsExceptionCodes::UNKNOWN_GATEWAY_ERROR,
87
+ $e->getMessage() != null ? $e->getMessage() : 'Unable to process transaction',
88
+ null,
89
+ null,
90
+ $e
91
+ );
92
+ }
93
+ }
94
+
95
+ protected function _isConfigInvalid()
96
+ {
97
+ if ($this->_config == null && (
98
+ $this->_config->secretApiKey == null ||
99
+ $this->_config->userName == null ||
100
+ $this->_config->password == null ||
101
+ $this->_config->licenseId == -1 ||
102
+ $this->_config->deviceId == -1 ||
103
+ $this->_config->siteId == -1)
104
+ ) {
105
+ return true;
106
+ }
107
+ return false;
108
+ }
109
+ }
lib/SecureSubmit/src/Abstractions/HpsPayPlanResourceAbstract.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ abstract class HpsPayPlanResourceAbstract implements HpsPayPlanResourceInterface
4
+ {
5
+ /** @var string|null */
6
+ public $statusSetDate = null;
7
+
8
+ /** @var string|null */
9
+ public $creationDate = null;
10
+
11
+ /** @var string|null */
12
+ public $lastChangeDate = null;
13
+
14
+ protected function isNotNull($value)
15
+ {
16
+ return $value !== null;
17
+ }
18
+
19
+ public function getEditableFieldsWithValues($class, $params = array())
20
+ {
21
+ $array = array_intersect_key(
22
+ get_object_vars($this),
23
+ array_flip(call_user_func_array($class.'::getEditableFields', $params))
24
+ );
25
+ return array_filter($array, array($this, 'isNotNull'));
26
+ }
27
+ }
lib/SecureSubmit/src/Abstractions/HpsPayPlanResourceInterface.php ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ interface HpsPayPlanResourceInterface
4
+ {
5
+ public static function getEditableFields();
6
+ public static function getSearchableFields();
7
+ }
lib/SecureSubmit/src/Entities/AltPayment/HpsAltPaymentAddToBatch.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsAltPaymentAddToBatch extends HpsAuthorization
4
+ {
5
+ public $status = null;
6
+ public $statusMessage = null;
7
+
8
+ public static function fromDict($rsp, $txnType, $returnType = 'HpsAltPaymentAddToBatch')
9
+ {
10
+ $addToBatch = $rsp->Transaction->$txnType;
11
+
12
+ $capture = parent::fromDict($rsp, $txnType, $returnType);
13
+
14
+ $capture->status = isset($addToBatch->Status) ? (string)$addToBatch->Status : null;
15
+ $capture->statusMessage = isset($addToBatch->StatusMessage) ? (string)$addToBatch->StatusMessage : null;
16
+
17
+ return $capture;
18
+ }
19
+ }
lib/SecureSubmit/src/Entities/AltPayment/HpsAltPaymentAuth.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsAltPaymentAuth extends HpsAuthorization
4
+ {
5
+ public $status = null;
6
+ public $statusMessage = null;
7
+
8
+ public static function fromDict($rsp, $txnType, $returnType = 'HpsAltPaymentAuth')
9
+ {
10
+ $authorize = $rsp->Transaction->$txnType;
11
+
12
+ $auth = parent::fromDict($rsp, $txnType, $returnType);
13
+
14
+ $auth->status = isset($authorize->Status) ? (string)$authorize->Status : null;
15
+ $auth->statusMessage = isset($authorize->StatusMessage) ? (string)$authorize->StatusMessage : null;
16
+
17
+ return $auth;
18
+ }
19
+ }
lib/SecureSubmit/src/Entities/AltPayment/HpsAltPaymentCreateSession.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsAltPaymentCreateSession extends HpsAuthorization
4
+ {
5
+ public $sessionId = null;
6
+ public $redirectUrl = null;
7
+
8
+ public static function fromDict($rsp, $txnType, $returnType = 'HpsAltPaymentCreateSession')
9
+ {
10
+ $createSession = $rsp->Transaction->$txnType;
11
+
12
+ $session = parent::fromDict($rsp, $txnType, $returnType);
13
+ if (isset($createSession->Session)) {
14
+ $pairs = self::nvpToArray($createSession->Session);
15
+ }
16
+
17
+ $session->sessionId = isset($pairs['SessionId']) ? $pairs['SessionId'] : null;
18
+ $session->redirectUrl = isset($pairs['RedirectUrl']) ? $pairs['RedirectUrl'] : null;
19
+
20
+ return $session;
21
+ }
22
+
23
+ protected static function nvpToArray($pairs)
24
+ {
25
+ $array = array();
26
+ foreach ($pairs->NameValuePair as $pair) {
27
+ $array[(string)$pair->Name] = (string)$pair->Value;
28
+ }
29
+ return $array;
30
+ }
31
+ }
lib/SecureSubmit/src/Entities/AltPayment/HpsAltPaymentReturn.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsAltPaymentReturn extends HpsAuthorization
4
+ {
5
+ }
lib/SecureSubmit/src/Entities/AltPayment/HpsAltPaymentSale.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsAltPaymentSale extends HpsAuthorization
4
+ {
5
+ public $status = null;
6
+ public $statusMessage = null;
7
+
8
+ public static function fromDict($rsp, $txnType, $returnType = 'HpsAltPaymentSale')
9
+ {
10
+ $charge = $rsp->Transaction->$txnType;
11
+
12
+ $sale = parent::fromDict($rsp, $txnType, $returnType);
13
+
14
+ $sale->status = isset($charge->Status) ? (string)$charge->Status : null;
15
+ $sale->statusMessage = isset($charge->StatusMessage) ? (string)$charge->StatusMessage : null;
16
+
17
+ return $sale;
18
+ }
19
+ }
lib/SecureSubmit/src/Entities/AltPayment/HpsAltPaymentSessionInfo.php ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsAltPaymentSessionInfo extends HpsAuthorization
4
+ {
5
+ /** @var string|null */
6
+ public $status = null;
7
+
8
+ /** @var HpsBuyerData|null */
9
+ public $buyer = null;
10
+
11
+ /** @var HpsPaymentData|null */
12
+ public $payment = null;
13
+
14
+ /** @var HpsShippingInfo|null */
15
+ public $shipping = null;
16
+
17
+ /** @var array(HpsLineItem)|null */
18
+ public $lineItems = null;
19
+
20
+ public static function fromDict($rsp, $txnType, $returnType = 'HpsAltPaymentSessionInfo')
21
+ {
22
+ $sessionInfo = $rsp->Transaction->$txnType;
23
+ $buyer = self::nvpToArray($sessionInfo->Buyer);
24
+ $payment = self::nvpToArray($sessionInfo->Payment);
25
+ $shipping = self::nvpToArray($sessionInfo->Shipping->Address);
26
+ $lineItems = self::nvpToArray($sessionInfo->LineItem->Detail);
27
+
28
+ $session = parent::fromDict($rsp, $txnType, $returnType);
29
+ $session->status = isset($sessionInfo->Status) ? (string)$sessionInfo->Status : null;
30
+
31
+ $session->buyer = new HpsBuyerData();
32
+ $session->buyer->emailAddress = isset($buyer['EmailAddress']) ? $buyer['EmailAddress'] : null;
33
+ $session->buyer->payerId = isset($buyer['BuyerId']) ? $buyer['BuyerId'] : null;
34
+ $session->buyer->status = isset($buyer['Status']) ? $buyer['Status'] : null;
35
+ $session->buyer->countryCode = isset($buyer['CountryCode']) ? $buyer['CountryCode'] : null;
36
+ $session->buyer->firstName = isset($buyer['FirstName']) ? $buyer['FirstName'] : null;
37
+ $session->buyer->lastName = isset($buyer['LastName']) ? $buyer['LastName'] : null;
38
+
39
+ $session->shipping = new HpsShippingInfo();
40
+ $session->shipping->name = isset($shipping['ShipName']) ? $shipping['ShipName'] : null;
41
+ $session->shipping->address = new HpsAddress();
42
+ $session->shipping->address->address = isset($shipping['ShipAddress']) ? $shipping['ShipAddress'] : null;
43
+ $session->shipping->address->city = isset($shipping['ShipCity']) ? $shipping['ShipCity'] : null;
44
+ $session->shipping->address->state = isset($shipping['ShipState']) ? $shipping['ShipState'] : null;
45
+ $session->shipping->address->zip = isset($shipping['ShipZip']) ? $shipping['ShipZip'] : null;
46
+ $session->shipping->address->country = isset($shipping['ShipCountryCode']) ? $shipping['ShipCountryCode'] : null;
47
+
48
+ $session->payment = new HpsPaymentData();
49
+ $session->payment->subtotal = isset($payment['ItemAmount']) ? $payment['ItemAmount'] : null;
50
+ $session->payment->shippingAmount = isset($payment['ShippingAmount']) ? $payment['ShippingAmount'] : null;
51
+ $session->payment->taxAmount = isset($payment['TaxAmount']) ? $payment['TaxAmount'] : null;
52
+
53
+ $session->lineItems = array();
54
+ $lineItem = new HpsLineitem();
55
+ $lineItem->name = isset($lineItems['Name']) ? $lineItems['Name'] : null;
56
+ $lineItem->amount = isset($lineItems['Amount']) ? $lineItems['Amount'] : null;
57
+ $lineItem->number = isset($lineItems['Number']) ? $lineItems['Number'] : null;
58
+ $lineItem->quantity = isset($lineItems['Quantity']) ? $lineItems['Quantity'] : null;
59
+ $lineItem->taxAmount = isset($lineItems['TaxAmount']) ? $lineItems['TaxAmount'] : null;
60
+
61
+ return $session;
62
+ }
63
+
64
+ protected static function nvpToArray($pairs)
65
+ {
66
+ $array = array();
67
+ foreach ($pairs->NameValuePair as $pair) {
68
+ $array[(string)$pair->Name] = (string)$pair->Value;
69
+ }
70
+ return $array;
71
+ }
72
+ }
lib/SecureSubmit/src/Entities/AltPayment/HpsAltPaymentVoid.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsAltPaymentVoid extends HpsAuthorization
4
+ {
5
+ }
lib/SecureSubmit/src/Entities/AltPayment/HpsBuyerData.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsBuyerData
4
+ {
5
+ /** @var string|null */
6
+ public $returnUrl = null;
7
+
8
+ /** @var string|null */
9
+ public $cancelUrl = null;
10
+
11
+ /** @var string|null */
12
+ public $emailAddress = null;
13
+
14
+ /** @var string|null */
15
+ public $payerId = null;
16
+
17
+ /** @var string|null */
18
+ public $status = null;
19
+
20
+ /** @var string|null */
21
+ public $countryCode = null;
22
+
23
+ /** @var string|null */
24
+ public $firstName = null;
25
+
26
+ /** @var string|null */
27
+ public $lastName = null;
28
+
29
+ /** @var string|null */
30
+ public $credit = null;
31
+ }
lib/SecureSubmit/src/Entities/AltPayment/HpsLineItem.php ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsLineItem
4
+ {
5
+ public $name = null;
6
+ public $description = null;
7
+ public $number = null;
8
+ public $amount = null;
9
+ public $quantity = null;
10
+ public $taxAmount = null;
11
+ }
lib/SecureSubmit/src/Entities/AltPayment/HpsPaymentData.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsPaymentData
4
+ {
5
+ /** @var double|null */
6
+ public $subtotal = null;
7
+
8
+ /** @var double|null */
9
+ public $shippingAmount = null;
10
+
11
+ /** @var double|null */
12
+ public $taxAmount = null;
13
+
14
+ /** @var string|null */
15
+ public $paymentType = null;
16
+
17
+ /** @var string|null */
18
+ public $invoiceNumber = null;
19
+ }
lib/SecureSubmit/src/Entities/AltPayment/HpsShippingInfo.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsShippingInfo
4
+ {
5
+ /** @var string|null */
6
+ public $name = null;
7
+
8
+ /** @var HpsAddress|null */
9
+ public $address = null;
10
+ }
lib/SecureSubmit/src/Entities/Batch/HpsBatch.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsBatch
4
+ {
5
+ public $id = null;
6
+ public $transactionCount = null;
7
+ public $totalAmount = null;
8
+ public $sequenceNumber = null;
9
+ }
lib/SecureSubmit/src/Entities/Check/HpsCheck.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsCheck
4
+ {
5
+ public $routingNumber = null;
6
+ public $accountNumber = null;
7
+ public $checkNumber = null;
8
+ public $checkType = null;
9
+ public $checkHolder = null;
10
+ public $micrNumber = null;
11
+
12
+ /**
13
+ * Account Type: Checking, Savings.
14
+ *
15
+ * <b>NOTE:</b> If processing with Colonnade, Account Type must be specified.
16
+ *
17
+ * @var null
18
+ */
19
+ public $accountType = null;
20
+
21
+ /**
22
+ * Data Entry Mode indicating whether the check data was manually entered or obtained from a check reader.
23
+ * Default value is HpsDataEntryMode::MANUAL.
24
+ *
25
+ * @var string|null
26
+ */
27
+ public $dataEntryMode = HpsDataEntryMode::MANUAL;
28
+
29
+ /**
30
+ * Indicates Check Verify. Requires processor setup to utilise. Contact your HPS representative for more information
31
+ * on the GETI eBronze program.
32
+ *
33
+ * @var null
34
+ */
35
+ public $checkVerify = null;
36
+
37
+ /**
38
+ * NACHA Standard Entry Class Code.
39
+ *
40
+ * <b>NOTE:</b> If processing with Colonnade, SECCode is required for CHeck Sale transactions.
41
+ *
42
+ * @var null
43
+ */
44
+ public $secCode = null;
45
+ }
lib/SecureSubmit/src/Entities/Check/HpsCheckHolder.php ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsCheckHolder extends HpsConsumer
4
+ {
5
+ public $checkName = null;
6
+ public $dlState = null;
7
+ public $dlNumber = null;
8
+ public $ssl4 = null;
9
+ public $dobYear = null;
10
+ public $courtesyCard = null;
11
+ }
lib/SecureSubmit/src/Entities/Check/HpsCheckResponse.php ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsCheckResponse extends HpsTransaction
4
+ {
5
+ public $authorizationCode = null;
6
+ public $customerId = null;
7
+ public $details = null;
8
+
9
+ public static function fromDict($rsp, $txnType, $returnType = 'HpsCheckResponse')
10
+ {
11
+ $response = $rsp->Transaction->$txnType;
12
+
13
+ $sale = parent::fromDict($rsp, $txnType, $returnType);
14
+ $sale->responseCode = (isset($response->RspCode) ? (string)$response->RspCode : null);
15
+ $sale->responseText = (isset($response->RspMessage) ? (string)$response->RspMessage : null);
16
+ $sale->authorizationCode = (isset($response->AuthCode) ? (string)$response->AuthCode : null);
17
+
18
+ if ($response->CheckRspInfo) {
19
+ $sale->details = array();
20
+
21
+ $checkInfo = $response->CheckRspInfo;
22
+ if (count($checkInfo) > 1) {
23
+ foreach ($checkInfo as $details) {
24
+ $sale->details[] = self::_hydrateRspDetails($details);
25
+ }
26
+ } else {
27
+ $sale->details = self::_hydrateRspDetails($checkInfo);
28
+ }
29
+ }
30
+
31
+ return $sale;
32
+ }
33
+
34
+ private static function _hydrateRspDetails($checkInfo)
35
+ {
36
+ $details = new HpsCheckResponseDetails();
37
+ $details->messageType = (isset($checkInfo->Type) ? (string)$checkInfo->Type : null);
38
+ $details->code = (isset($checkInfo->Code) ? (string)$checkInfo->Code : null);
39
+ $details->message = (isset($checkInfo->Message) ? (string)$checkInfo->Message : null);
40
+ $details->fieldNumber = (isset($checkInfo->FieldNumber) ? (string)$checkInfo->FieldNumber : null);
41
+ $details->fieldName = (isset($checkInfo->FieldName) ? (string)$checkInfo->FieldName : null);
42
+ return $details;
43
+ }
44
+ }
lib/SecureSubmit/src/Entities/Check/HpsCheckResponseDetails.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsCheckResponseDetails
4
+ {
5
+ public $messageType = null;
6
+ public $code = null;
7
+ public $message = null;
8
+ public $fieldNumber = null;
9
+ public $fieldName = null;
10
+ }
lib/SecureSubmit/src/Entities/Credit/HpsAccountVerify.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsAccountVerify extends HpsAuthorization
4
+ {
5
+ }
lib/SecureSubmit/src/Entities/Credit/HpsAuthorization.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsAuthorization extends HpsTransaction
4
+ {
5
+ public $avsResultCode = null;
6
+ public $avsResultText = null;
7
+ public $cvvResultCode = null;
8
+ public $cvvResultText = null;
9
+ public $cpcIndicator = null;
10
+ public $authorizationCode = null;
11
+ public $authorizedAmount = null;
12
+ public $cardType = null;
13
+ public $description = null;
14
+ public $invoiceNumber = null;
15
+ public $customerId = null;
16
+ public $descriptor = null;
17
+ public $tokenData = null;
18
+
19
+ public static function fromDict($rsp, $txnType, $returnType = 'HpsAuthorization')
20
+ {
21
+ $authResponse = $rsp->Transaction->$txnType;
22
+
23
+ $auth = parent::fromDict($rsp, $txnType, $returnType);
24
+ $auth->authorizationCode = (isset($authResponse->AuthCode) ? (string)$authResponse->AuthCode : null);
25
+ $auth->avsResultCode = (isset($authResponse->AVSRsltCode) ? (string)$authResponse->AVSRsltCode : null);
26
+ $auth->avsResultText = (isset($authResponse->AVSRsltText) ? (string)$authResponse->AVSRsltText : null);
27
+ $auth->cvvResultCode = (isset($authResponse->CVVRsltCode) ? (string)$authResponse->CVVRsltCode : null);
28
+ $auth->cvvResultText = (isset($authResponse->CVVRsltText) ? (string)$authResponse->CVVRsltText : null);
29
+ $auth->authorizedAmount = (isset($authResponse->AuthAmt) ? (string)$authResponse->AuthAmt : null);
30
+ $auth->cardType = (isset($authResponse->CardType) ? (string)$authResponse->CardType : null);
31
+ $auth->descriptor = (isset($authResponse->TxnDescriptor) ? (string)$authResponse->TxnDescriptor : null);
32
+ $auth->cpcIndicator = (isset($authResponse->CPCInd) ? (string)$authResponse->CPCInd : null);
33
+
34
+ if (isset($rsp->Header->TokenData)) {
35
+ $auth->tokenData = new HpsTokenData();
36
+ $auth->tokenData->responseCode = (isset($rsp->Header->TokenData->TokenRspCode) ? (string)$rsp->Header->TokenData->TokenRspCode : null);
37
+ $auth->tokenData->responseMessage = (isset($rsp->Header->TokenData->TokenRspMsg) ? (string)$rsp->Header->TokenData->TokenRspMsg : null);
38
+ $auth->tokenData->tokenValue = (isset($rsp->Header->TokenData->TokenValue) ? (string)$rsp->Header->TokenData->TokenValue : null);
39
+ }
40
+ return $auth;
41
+ }
42
+ }
lib/SecureSubmit/src/Entities/Credit/HpsCPCData.php ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsCPCData
4
+ {
5
+ public $CardHolderPONbr = null;
6
+ public $TaxType = null;
7
+ public $TaxAmt = null;
8
+ }
lib/SecureSubmit/src/Entities/Credit/HpsCPCEdit.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsCPCEdit extends HpsTransaction
4
+ {
5
+ public static function fromDict($rsp, $txnType, $returnType = 'HpsCPCEdit')
6
+ {
7
+ $cpcEdit = parent::fromDict($rsp, $txnType, $returnType);
8
+ $cpcEdit->responseCode = '00';
9
+ $cpcEdit->responseText = '';
10
+ return $cpcEdit;
11
+ }
12
+ }
lib/SecureSubmit/src/Entities/Credit/HpsCardHolder.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsCardHolder extends HpsConsumer
4
+ {
5
+ }
lib/SecureSubmit/src/Entities/Credit/HpsCharge.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsCharge extends HpsAuthorization
4
+ {
5
+ }
lib/SecureSubmit/src/Entities/Credit/HpsChargeExceptions.php ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsChargeExceptions
4
+ {
5
+ public $cardException = null;
6
+ public $hpsException = null;
7
+ }
lib/SecureSubmit/src/Entities/Credit/HpsCreditCard.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsCreditCard
4
+ {
5
+ public $number = null;
6
+ public $cvv = null;
7
+ public $expMonth = null;
8
+ public $expYear = null;
9
+
10
+ public function cardType()
11
+ {
12
+ $regexMap = array(
13
+ 'Amex' => '/^3[47][0-9]{13}$/',
14
+ 'MasterCard' => '/^5[1-5][0-9]{14}$/',
15
+ 'Visa' => '/^4[0-9]{12}(?:[0-9]{3})?$/',
16
+ 'DinersClub' => '/^3(?:0[0-5]|[68][0-9])[0-9]{11}$/',
17
+ 'EnRoute' => '/^(2014|2149)/',
18
+ 'Discover' => '/^6(?:011|5[0-9]{2})[0-9]{12}$/',
19
+ 'Jcb' => '/^(?:2131|1800|35\d{3})\d{11}$/',
20
+ );
21
+ foreach ($regexMap as $card => $rx) {
22
+ if (preg_match($rx, $this->number)) {
23
+ return $card;
24
+ }
25
+ }
26
+ return "Unknown";
27
+ }
28
+ }
lib/SecureSubmit/src/Entities/Credit/HpsRecurringBilling.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsRecurringBilling extends HpsAuthorization
4
+ {
5
+ }
lib/SecureSubmit/src/Entities/Credit/HpsRefund.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsRefund extends HpsTransaction
4
+ {
5
+ public static function fromDict($rsp, $txnType, $returnType = 'HpsRefund')
6
+ {
7
+ $refund = parent::fromDict($rsp, $txnType, $returnType);
8
+ $refund->responseCode = '00';
9
+ $refund->responseText = '';
10
+ return $refund;
11
+ }
12
+ }
lib/SecureSubmit/src/Entities/Credit/HpsReportTransactionDetails.php ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsReportTransactionDetails extends HpsAuthorization
4
+ {
5
+ public $issuerTransactionId = null;
6
+ public $issuerValidationCode = null;
7
+ public $originalTransactionId = null;
8
+ public $maskedCardNumber = null;
9
+ public $settlementAmount = null;
10
+ public $transactionType = null;
11
+ public $transactionUTCDate = null;
12
+ public $exceptions = null;
13
+ public $memo = null;
14
+ public $invoiceNumber = null;
15
+ public $customerId = null;
16
+
17
+ public static function fromDict($rsp, $txnType, $returnType = 'HpsReportTransactionDetails')
18
+ {
19
+ $reportResponse = $rsp->Transaction->$txnType;
20
+
21
+ $details = parent::fromDict($rsp, $txnType, $returnType);
22
+ $details->originalTransactionId = (isset($reportResponse->OriginalGatewayTxnId) ? (string)$reportResponse->OriginalGatewayTxnId : null);
23
+ $details->authorizedAmount = (isset($reportResponse->Data->AuthAmt) ? (string)$reportResponse->Data->AuthAmt : null);
24
+ $details->maskedCardNumber = (isset($reportResponse->Data->MaskedCardNbr) ? (string)$reportResponse->Data->MaskedCardNbr : null);
25
+ $details->authorizationCode = (isset($reportResponse->Data->AuthCode) ? (string)$reportResponse->Data->AuthCode : null);
26
+ $details->avsResultCode = (isset($reportResponse->Data->AVSRsltCode) ? (string)$reportResponse->Data->AVSRsltCode : null);
27
+ $details->avsResultText = (isset($reportResponse->Data->AVSRsltText) ? (string)$reportResponse->Data->AVSRsltText : null);
28
+ $details->cardType = (isset($reportResponse->Data->CardType) ? (string)$reportResponse->Data->CardType : null);
29
+ $details->descriptor = (isset($reportResponse->Data->TxnDescriptor) ? (string)$reportResponse->Data->TxnDescriptor : null);
30
+ $details->transactionType = (isset($reportResponse->ServiceName) ? HpsTransaction::serviceNameToTransactionType((string)$reportResponse->ServiceName) : null);
31
+ $details->transactionUTCDate = (isset($reportResponse->RspUtcDT) ? (string)$reportResponse->RspUtcDT : null);
32
+ $details->cpcIndicator = (isset($reportResponse->Data->CPCInd) ? (string)$reportResponse->Data->CPCInd : null);
33
+ $details->cvvResultCode = (isset($reportResponse->Data->CVVRsltCode) ? (string)$reportResponse->Data->CVVRsltCode : null);
34
+ $details->cvvResultText = (isset($reportResponse->Data->CVVRsltText) ? (string)$reportResponse->Data->CVVRsltText : null);
35
+ $details->referenceNumber = (isset($reportResponse->Data->RefNbr) ? (string)$reportResponse->Data->RefNbr : null);
36
+ $details->responseCode = (isset($reportResponse->Data->RspCode) ? (string)$reportResponse->Data->RspCode : null);
37
+ $details->responseText = (isset($reportResponse->Data->RspText) ? (string)$reportResponse->Data->RspText : null);
38
+
39
+ if (isset($reportResponse->Data->TokenizationMsg)) {
40
+ $details->tokenData = new HpsTokenData();
41
+ $details->tokenData->responseMessage = (string)$reportResponse->Data->TokenizationMsg;
42
+ }
43
+
44
+ if (isset($reportResponse->Data->AdditionalTxnFields)) {
45
+ $additionalTxnFields = $reportResponse->Data->additionalTxnFields;
46
+ $details->memo = (isset($additionalTxnFields->Description) ? (string)$additionalTxnFields->Description : null);
47
+ $details->invoiceNumber = (isset($additionalTxnFields->InvoiceNbr) ? (string)$additionalTxnFields->InvoiceNbr : null);
48
+ $details->customerId = (isset($additionalTxnFields->CustomerId) ? (string)$additionalTxnFields->CustomerId : null);
49
+ }
50
+
51
+ if ((string)$reportResponse->Data->RspCode != '00') {
52
+ if ($details->exceptions == null) {
53
+ $details->exceptions = new HpsChargeExceptions();
54
+ }
55
+
56
+ $details->exceptions->issuerException = HpsIssuerResponseValidation::getException(
57
+ (string)$rsp->Header->GatewayTxnId,
58
+ (string)$reportResponse->Data->RspCode,
59
+ (string)$reportResponse->Data->RspText
60
+ );
61
+ }
62
+
63
+ return $details;
64
+ }
65
+ }
lib/SecureSubmit/src/Entities/Credit/HpsReportTransactionSummary.php ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsReportTransactionSummary extends HpsTransaction
4
+ {
5
+ public $amount = null;
6
+ public $settlementAmount = null;
7
+ public $originalTransactionId = null;
8
+ public $maskedCardNumber = null;
9
+ public $transactionType = null;
10
+ public $transactionUTCDate = null;
11
+ public $exceptions = null;
12
+
13
+ public static function fromDict($rsp, $txnType, $filterBy = null, $returnType = 'HpsReportTransactionSummary')
14
+ {
15
+ $transactions = array();
16
+
17
+ if ((string)$rsp->Transaction->ReportActivity->Header->TxnCnt == "0") {
18
+ return $transactions;
19
+ }
20
+
21
+ if ($filterBy != null && is_string($filterBy)) {
22
+ $filterBy = HpsTransaction::serviceNameToTransactionType($filterBy);
23
+ }
24
+
25
+ $summary = null;
26
+ $serviceName = (isset($filterBy) ? HpsTransaction::transactionTypeToServiceName($filterBy) : null);
27
+
28
+ foreach ($rsp->Transaction->ReportActivity->Details as $charge) {
29
+ if (isset($serviceName) && $serviceName != (string)$charge->ServiceName) {
30
+ continue;
31
+ }
32
+
33
+ $summary = new HpsReportTransactionSummary();
34
+
35
+ // Hydrate the header
36
+ $summary->_header = new HpsTransactionHeader();
37
+ $summary->_header->gatewayResponseCode = (string)$charge->GatewayRspCode;
38
+ $summary->_header->gatewayResponseMessage = (string)$charge->GatewayRspMsg;
39
+
40
+ $summary->transactionId = (string)$charge->GatewayTxnId;
41
+
42
+ $summary->originalTransactionId = (isset($charge->OriginalGatewayTxnId) ? (string)$charge->OriginalGatewayTxnId : null);
43
+ $summary->maskedCardNumber = (isset($charge->MaskedCardNbr) ? (string)$charge->MaskedCardNbr : null);
44
+ $summary->responseCode = (isset($charge->IssuerRspCode) ? (string)$charge->IssuerRspCode : null);
45
+ $summary->responseText = (isset($charge->IssuerRspText) ? (string)$charge->IssuerRspText : null);
46
+ $summary->amount = (isset($charge->Amt) ? (string)$charge->Amt : null);
47
+ $summary->settlementAmount = (isset($charge->SettlementAmt) ? (string)$charge->SettlementAmt : null);
48
+ $summary->transactionType = (isset($charge->ServiceName) ? HpsTransaction::serviceNameToTransactionType((string)$charge->ServiceName) : null);
49
+ $summary->transactionUTCDate = (isset($charge->TxnUtcDT) ? (string)$charge->TxnUtcDT : null);
50
+
51
+ $gwResponseCode = (isset($charge->GatewayRspCode) ? (string)$charge->GatewayRspCode : null);
52
+ $issuerResponseCode = (isset($charge->IssuerRspCode) ? (string)$charge->IssuerRspCode : null);
53
+
54
+ if ($gwResponseCode != "0" || $issuerResponseCode != "00") {
55
+ $exceptions = new HpsChargeExceptions();
56
+ if ($gwResponseCode != "0") {
57
+ $message = (string)$charge->GatewayRspMsg;
58
+ $exceptions->hpsException = HpsGatewayResponseValidation::getException((string)$charge->GatewayTxnId, $gwResponseCode, $message);
59
+ }
60
+ if ($issuerResponseCode != "00") {
61
+ $message = (string)$charge->IssuerRspText;
62
+ $exceptions->cardException = HpsIssuerResponseValidation::getException((string)$charge->GatewayTxnId, $issuerResponseCode, $message);
63
+ }
64
+ $summary->exceptions = $exceptions;
65
+ }
66
+
67
+ $transactions[] = $summary;
68
+ }
69
+ return $transactions;
70
+ }
71
+ }
lib/SecureSubmit/src/Entities/Credit/HpsReversal.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsReversal extends HpsTransaction
4
+ {
5
+ public $avsResultCode = null;
6
+ public $avsResultText = null;
7
+ public $cvvResultCode = null;
8
+ public $cvvResultText = null;
9
+ public $cpcIndicator = null;
10
+
11
+ public static function fromDict($rsp, $txnType, $returnType = 'HpsReversal')
12
+ {
13
+ $reverseResponse = $rsp->Transaction->$txnType;
14
+
15
+ $reverse = parent::fromDict($rsp, $txnType, $returnType);
16
+ $reverse->avsResultCode = (isset($reverseResponse->AVSRsltCode) ? (string)$reverseResponse->AVSRsltCode : null);
17
+ $reverse->avsResultText = (isset($reverseResponse->AVSRsltText) ? (string)$reverseResponse->AVSRsltText : null);
18
+ $reverse->cpcIndicator = (isset($reverseResponse->CPCInd) ? (string)$reverseResponse->CPCInd : null);
19
+ $reverse->cvvResultCode = (isset($reverseResponse->CVVRsltCode) ? (string)$reverseResponse->CVVRsltCode : null);
20
+ $reverse->cvvResultText = (isset($reverseResponse->CVVRsltText) ? (string)$reverseResponse->CVVRsltText : null);
21
+
22
+ return $reverse;
23
+ }
24
+ }
lib/SecureSubmit/src/Entities/Credit/HpsVoid.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsVoid extends HpsTransaction
4
+ {
5
+ public static function fromDict($rsp, $txnType, $returnType = 'HpsVoid')
6
+ {
7
+ $void = parent::fromDict($rsp, $txnType, $returnType);
8
+ $void->responseCode = '00';
9
+ $void->responseText = '';
10
+ return $void;
11
+ }
12
+ }
lib/SecureSubmit/src/Entities/Debit/HpsDebitAddValue.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsDebitAddValue extends HpsAuthorization
4
+ {
5
+ }
lib/SecureSubmit/src/Entities/Debit/HpsDebitReturn.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsDebitReturn extends HpsAuthorization
4
+ {
5
+ }
lib/SecureSubmit/src/Entities/Debit/HpsDebitReversal.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsDebitReversal extends HpsAuthorization
4
+ {
5
+ }
lib/SecureSubmit/src/Entities/Debit/HpsDebitSale.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsDebitSale extends HpsAuthorization
4
+ {
5
+ }
lib/SecureSubmit/src/Entities/Fluent/HpsBuilderAction.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsBuilderAction
4
+ {
5
+ /** @var callable|null */
6
+ public $action = null;
7
+
8
+ /** @var string|null */
9
+ public $name = null;
10
+
11
+ /** @var array */
12
+ public $arguments = null;
13
+
14
+ public function __construct($name = null, $action = null)
15
+ {
16
+ $this->name = $name;
17
+ $this->action = $action;
18
+ }
19
+ }
lib/SecureSubmit/src/Entities/Fluent/HpsUnknownPropertyException.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Exception to be thrown when a property that
5
+ * doesn't exist attempts to be set using
6
+ * HpsBuilderAbstract::__call magic method.
7
+ */
8
+ class HpsUnknownPropertyException extends HpsException
9
+ {
10
+ /**
11
+ * Instantiates new HpsUnknownPropertyException.
12
+ *
13
+ * @param object $obj
14
+ * @param string $property
15
+ * @param int $code
16
+ * @param HpsException $inner
17
+ *
18
+ * @return HpsUnknownPropertyException
19
+ */
20
+ public function __construct($obj, $property, $code = 0, HpsException $inner = null)
21
+ {
22
+ $className = get_class($obj);
23
+ $message = 'Failed to set non-existent property "' . $property
24
+ . '" on class "' . $className . '"';
25
+ parent::__construct($message, $code, $inner);
26
+ }
27
+ }
lib/SecureSubmit/src/Entities/Gift/HpsEncryptionData.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsEncryptionData
4
+ {
5
+ public $version = null;
6
+
7
+ /**
8
+ * This is required in certain encryption versions when supplying
9
+ * track data and indicates which track has been supplied.
10
+ *
11
+ * @var null
12
+ */
13
+ public $encryptedTrackNumber = null;
14
+
15
+ /**
16
+ * This is requied in certain encryption versions;
17
+ * the Key Transmission Block (KTB) used at the point of sale.
18
+ *
19
+ * @var null
20
+ */
21
+ public $ktb = null;
22
+
23
+ /**
24
+ * This is required in certain encryption versions;
25
+ * the Key Serial Number (KSN) used at the point of sale.
26
+ *
27
+ * @var null
28
+ */
29
+ public $ksn = null;
30
+ }
lib/SecureSubmit/src/Entities/Gift/HpsGiftCard.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsGiftCard
4
+ {
5
+ public $number = null;
6
+ public $expMonth = null;
7
+ public $expYear = null;
8
+ public $isTrackData = false;
9
+ public $encryptionData = null;
10
+
11
+ public function __construct($number = null)
12
+ {
13
+ $this->number = $number;
14
+ }
15
+ }
lib/SecureSubmit/src/Entities/Gift/HpsGiftCardActivate.php ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsGiftCardActivate extends HpsTransaction
4
+ {
5
+ /**
6
+ * The HPS gift card activate response
7
+ */
8
+
9
+ public $authorizationCode = null;
10
+ public $balanceAmount = null;
11
+ public $pointsBalanceAmount = null;
12
+
13
+ /**
14
+ * The rewards (dollars or points) added to the account as
15
+ * a result of the transaction.
16
+ *
17
+ * @var null
18
+ */
19
+ public $rewards = null;
20
+
21
+ /**
22
+ * Notes contain reward messages to be displayed on a receipt,
23
+ * mobile app, or web page to inform an account holder about
24
+ * special rewards or promotions available on the account.
25
+ *
26
+ * @var string
27
+ */
28
+ public $notes = null;
29
+
30
+ public static function fromDict($rsp, $txnType, $returnType = 'HpsGiftCardActivate')
31
+ {
32
+ $activationRsp = $rsp->Transaction->$txnType;
33
+
34
+ $activation = new $returnType();
35
+
36
+ $activation->transactionId = (string)$rsp->Header->GatewayTxnId;
37
+ $activation->authorizationCode = (isset($activationRsp->AuthCode) ? (string)$activationRsp->AuthCode : null);
38
+ $activation->balanceAmount = (isset($activationRsp->BalanceAmt) ? (string)$activationRsp->BalanceAmt : null);
39
+ $activation->pointsBalanceAmount = (isset($activationRsp->PointsBalanceAmount) ? (string)$activationRsp->PointsBalanceAmount : null);
40
+ $activation->rewards = (isset($activationRsp->Rewards) ? (string)$activationRsp->Rewards : null);
41
+ $activation->notes = (isset($activationRsp->Notes) ? (string)$activationRsp->Notes : null);
42
+ $activation->responseCode = (isset($activationRsp->RspCode) ? (string)$activationRsp->RspCode : null);
43
+ $activation->responseText = (isset($activationRsp->RspText) ? (string)$activationRsp->RspText : null);
44
+
45
+ return $activation;
46
+ }
47
+ }
lib/SecureSubmit/src/Entities/Gift/HpsGiftCardAddValue.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsGiftCardAddValue extends HpsGiftCardActivate
4
+ {
5
+ }
lib/SecureSubmit/src/Entities/Gift/HpsGiftCardAlias.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsGiftCardAlias extends HpsTransaction
4
+ {
5
+ /**
6
+ * The Hps gift card alias response.
7
+ */
8
+
9
+ public $giftCard = null;
10
+
11
+ public static function fromDict($rsp, $txnType, $returnType = 'HpsGiftCardAlias')
12
+ {
13
+ $item = $rsp->Transaction->$txnType;
14
+
15
+ $alias = new HpsGiftCardAlias();
16
+ $alias->transactionId = (string)$rsp->Header->GatewayTxnId;
17
+ $alias->giftCard = new HpsGiftCard($item->CardData);
18
+ $alias->responseCode = (isset($item->RspCode) ? (string)$item->RspCode : null);
19
+ $alias->responseText = (isset($item->RspText) ? (string)$item->RspText : null);
20
+
21
+ return $alias;
22
+ }
23
+ }
lib/SecureSubmit/src/Entities/Gift/HpsGiftCardBalance.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsGiftCardBalance extends HpsGiftCardActivate
4
+ {
5
+ }
lib/SecureSubmit/src/Entities/Gift/HpsGiftCardDeactivate.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsGiftCardDeactivate extends HpsGiftCardActivate
4
+ {
5
+ }
lib/SecureSubmit/src/Entities/Gift/HpsGiftCardReplace.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsGiftCardReplace extends HpsGiftCardActivate
4
+ {
5
+ }
lib/SecureSubmit/src/Entities/Gift/HpsGiftCardReversal.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsGiftCardReversal extends HpsGiftCardActivate
4
+ {
5
+ }
lib/SecureSubmit/src/Entities/Gift/HpsGiftCardReward.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsGiftCardReward extends HpsGiftCardActivate
4
+ {
5
+ }
lib/SecureSubmit/src/Entities/Gift/HpsGiftCardSale.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsGiftCardSale extends HpsGiftCardActivate
4
+ {
5
+ public $splitTenderCardAmount = null;
6
+ public $splitTenderBalanceDue = null;
7
+
8
+ public static function fromDict($rsp, $txnType, $returnType = 'HpsGiftCardSale')
9
+ {
10
+ $item = $rsp->Transaction;
11
+
12
+ $sale = parent::fromDict($rsp, $txnType, $returnType);
13
+ $sale->splitTenderCardAmount = (isset($item->SplitTenderCardAmt) ? (string)$item->SplitTenderCardAmt : null);
14
+ $sale->splitTenderBalanceDue = (isset($item->SplitTenderBalanceDueAmt) ? (string)$item->SplitTenderBalanceDueAmt : null);
15
+
16
+ return $sale;
17
+ }
18
+ }
lib/SecureSubmit/src/Entities/Gift/HpsGiftCardVoid.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsGiftCardVoid extends HpsGiftCardActivate
4
+ {
5
+ }
lib/SecureSubmit/src/Entities/HpsAddress.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsAddress
4
+ {
5
+ public $address = null;
6
+ public $city = null;
7
+ public $state = null;
8
+ public $zip = null;
9
+ public $country = null;
10
+ }
lib/SecureSubmit/src/Entities/HpsConsumer.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsConsumer
4
+ {
5
+ public $firstName = null;
6
+ public $lastName = null;
7
+ public $phone = null;
8
+ public $email = null;
9
+ public $address = null;
10
+ }
lib/SecureSubmit/src/Entities/HpsDirectMarketData.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsDirectMarketData
4
+ {
5
+ public $invoiceNumber = null;
6
+ public $shipMonth = null;
7
+ public $shipDay = null;
8
+
9
+ public function __construct($invoiceNumber = null, $shipMonth = null, $shipDay = null)
10
+ {
11
+ $this->invoiceNumber = $invoiceNumber;
12
+ $this->shipMonth = $shipMonth;
13
+ $this->shipDay = $shipDay;
14
+ }
15
+ }
lib/SecureSubmit/src/Entities/HpsTokenData.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsTokenData
4
+ {
5
+ public $tokenValue = null;
6
+ public $responseCode = null;
7
+ public $responseMessage = null;
8
+
9
+ public function __construct($responseMessage = null)
10
+ {
11
+ $this->responseMessage = $responseMessage;
12
+ }
13
+ }
lib/SecureSubmit/src/Entities/HpsTransaction.php ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsTransaction
4
+ {
5
+ public $transactionId = null;
6
+ public $clientTransactionId = null;
7
+ public $responseCode = null;
8
+ public $responseText = null;
9
+ public $referenceNumber = null;
10
+ protected $_header = null;
11
+
12
+ public static function fromDict($rsp, $txnType, $returnType = 'HpsTransaction')
13
+ {
14
+ $transaction = new $returnType();
15
+
16
+ // Hydrate the header
17
+ $transaction->_header = new HpsTransactionHeader();
18
+ $transaction->_header->gatewayResponseCode = (string)$rsp->Header->GatewayRspCode;
19
+ $transaction->_header->gatewayResponseMessage = (string)$rsp->Header->GatewayRspMsg;
20
+ $transaction->_header->responseDt = (string)$rsp->Header->RspDT;
21
+ $transaction->_header->clientTxnId = (isset($rsp->Header->ClientTxnId) ? (string)$rsp->Header->ClientTxnId : null);
22
+
23
+ $transaction->transactionId = (string)$rsp->Header->GatewayTxnId;
24
+ if (isset($rsp->Header->ClientTxnId)) {
25
+ $transaction->clientTransactionId = (string)$rsp->Header->ClientTxnId;
26
+ }
27
+
28
+ // Hydrate the body
29
+ $item = $rsp->Transaction->$txnType;
30
+ if ($item != null) {
31
+ $transaction->responseCode = (isset($item->RspCode) ? (string)$item->RspCode : null);
32
+ $transaction->responseText = (isset($item->RspText) ? (string)$item->RspText : null);
33
+ $transaction->referenceNumber = (isset($item->RefNbr) ? (string)$item->RefNbr : null);
34
+ }
35
+
36
+ return $transaction;
37
+ }
38
+
39
+ public function gatewayResponse()
40
+ {
41
+ return (object)array(
42
+ 'code' => $this->_header->gatewayResponseCode,
43
+ 'message' => $this->_header->gatewayResponseMessage,
44
+ );
45
+ }
46
+
47
+ public static function transactionTypeToServiceName($transactionType)
48
+ {
49
+ switch ($transactionType) {
50
+ case HpsTransactionType::AUTHORIZE:
51
+ return HpsItemChoiceTypePosResponseVer10Transaction::CREDIT_AUTH;
52
+ break;
53
+ case HpsTransactionType::CAPTURE:
54
+ return HpsItemChoiceTypePosResponseVer10Transaction::CREDIT_ADD_TO_BATCH;
55
+ break;
56
+ case HpsTransactionType::CHARGE:
57
+ return HpsItemChoiceTypePosResponseVer10Transaction::CREDIT_SALE;
58
+ break;
59
+ case HpsTransactionType::REFUND:
60
+ return HpsItemChoiceTypePosResponseVer10Transaction::CREDIT_RETURN;
61
+ break;
62
+ case HpsTransactionType::REVERSE:
63
+ return HpsItemChoiceTypePosResponseVer10Transaction::CREDIT_REVERSAL;
64
+ break;
65
+ case HpsTransactionType::VERIFY:
66
+ return HpsItemChoiceTypePosResponseVer10Transaction::CREDIT_ACCOUNT_VERIFY;
67
+ break;
68
+ case HpsTransactionType::LIST_TRANSACTION:
69
+ return HpsItemChoiceTypePosResponseVer10Transaction::REPORT_ACTIVITY;
70
+ break;
71
+ case HpsTransactionType::GET:
72
+ return HpsItemChoiceTypePosResponseVer10Transaction::REPORT_TXN_DETAIL;
73
+ break;
74
+ case HpsTransactionType::VOID:
75
+ return HpsItemChoiceTypePosResponseVer10Transaction::CREDIT_VOID;
76
+ break;
77
+ case HpsTransactionType::BATCH_CLOSE:
78
+ return HpsItemChoiceTypePosResponseVer10Transaction::BATCH_CLOSE;
79
+ break;
80
+ case HpsTransactionType::SECURITY_ERROR:
81
+ return "SecurityError";
82
+ break;
83
+ default:
84
+ return "";
85
+ }
86
+ }
87
+
88
+ public static function serviceNameToTransactionType($serviceName)
89
+ {
90
+ switch ($serviceName) {
91
+ case HpsItemChoiceTypePosResponseVer10Transaction::CREDIT_AUTH:
92
+ return HpsTransactionType::AUTHORIZE;
93
+ break;
94
+ case HpsItemChoiceTypePosResponseVer10Transaction::CREDIT_ADD_TO_BATCH:
95
+ return HpsTransactionType::CAPTURE;
96
+ break;
97
+ case HpsItemChoiceTypePosResponseVer10Transaction::CREDIT_SALE:
98
+ return HpsTransactionType::CHARGE;
99
+ break;
100
+ case HpsItemChoiceTypePosResponseVer10Transaction::CREDIT_RETURN:
101
+ return HpsTransactionType::REFUND;
102
+ break;
103
+ case HpsItemChoiceTypePosResponseVer10Transaction::CREDIT_REVERSAL:
104
+ return HpsTransactionType::REVERSE;
105
+ break;
106
+ case HpsItemChoiceTypePosResponseVer10Transaction::CREDIT_ACCOUNT_VERIFY:
107
+ return HpsTransactionType::VERIFY;
108
+ break;
109
+ case HpsItemChoiceTypePosResponseVer10Transaction::REPORT_ACTIVITY:
110
+ return HpsTransactionType::LIST_TRANSACTION;
111
+ break;
112
+ case HpsItemChoiceTypePosResponseVer10Transaction::REPORT_TXN_DETAIL:
113
+ return HpsTransactionType::GET;
114
+ break;
115
+ case HpsItemChoiceTypePosResponseVer10Transaction::CREDIT_VOID:
116
+ return HpsTransactionType::VOID;
117
+ break;
118
+ case HpsItemChoiceTypePosResponseVer10Transaction::BATCH_CLOSE:
119
+ return HpsTransactionType::BATCH_CLOSE;
120
+ break;
121
+ default:
122
+ return null;
123
+ }
124
+ }
125
+ }
lib/SecureSubmit/src/Entities/HpsTransactionDetails.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsTransactionDetails
4
+ {
5
+ public $memo = null;
6
+ public $invoiceNumber = null;
7
+ public $customerId = null;
8
+ public $clientTransactionId = null;
9
+ }
lib/SecureSubmit/src/Entities/HpsTransactionHeader.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsTransactionHeader
4
+ {
5
+ public $gatewayResponseCode = null;
6
+ public $gatewayResponseMessage = null;
7
+ public $responseDt = null;
8
+ public $clientTxnId = null;
9
+ }
lib/SecureSubmit/src/Entities/PayPlan/HpsPayPlanCustomer.php ADDED
@@ -0,0 +1,164 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsPayPlanCustomer extends HpsPayPlanResourceAbstract
4
+ {
5
+ /** @var string|null */
6
+ public $customerKey = null;
7
+
8
+ /** @var string|null */
9
+ public $customerIdentifier = null;
10
+
11
+ /** @var string|null */
12
+ public $firstName = null;
13
+
14
+ /** @var string|null */
15
+ public $lastName = null;
16
+
17
+ /** @var string|null */
18
+ public $company = null;
19
+
20
+ /** @var string|null */
21
+ public $customerStatus = null;
22
+
23
+ /** @var string|null */
24
+ public $primaryEmail = null;
25
+
26
+ /** @var string|null */
27
+ public $phoneDay = null;
28
+
29
+ /** @var string|null */
30
+ public $phoneDayExt = null;
31
+
32
+ /** @var string|null */
33
+ public $phoneEvening = null;
34
+
35
+ /** @var string|null */
36
+ public $phoneEveningExt = null;
37
+
38
+ /** @var string|null */
39
+ public $phoneMobile = null;
40
+
41
+ /** @var string|null */
42
+ public $phoneMobileExt = null;
43
+
44
+ /** @var string|null */
45
+ public $fax = null;
46
+
47
+ /** @var string|null */
48
+ public $title = null;
49
+
50
+ /** @var string|null */
51
+ public $department = null;
52
+
53
+ /** @var string|null */
54
+ public $addressLine1 = null;
55
+
56
+ /** @var string|null */
57
+ public $addressLine2 = null;
58
+
59
+ /** @var string|null */
60
+ public $city = null;
61
+
62
+ /** @var string|null */
63
+ public $country = null;
64
+
65
+ /** @var string|null */
66
+ public $stateProvince = null;
67
+
68
+ /** @var string|null */
69
+ public $zipPostalCode = null;
70
+
71
+ /** @var array(HpsPayPlanPaymentMethod)|null */
72
+ public $paymentMethods = null;
73
+
74
+ /** @var array(HpsPayPlanSchedule)|null */
75
+ public $schedules = null;
76
+
77
+ public static function getEditableFields()
78
+ {
79
+ return array(
80
+ 'customerIdentifier',
81
+ 'firstName',
82
+ 'lastName',
83
+ 'company',
84
+ 'customerStatus',
85
+ 'title',
86
+ 'department',
87
+ 'primaryEmail',
88
+ 'secondaryEmail',
89
+ 'phoneDay',
90
+ 'phoneDayExt',
91
+ 'phoneEvening',
92
+ 'phoneEveningExt',
93
+ 'phoneMobile',
94
+ 'phoneMobileExt',
95
+ 'fax',
96
+ 'addressLine1',
97
+ 'addressLine2',
98
+ 'city',
99
+ 'stateProvince',
100
+ 'zipPostalCode',
101
+ 'country',
102
+ );
103
+ }
104
+
105
+ public static function getSearchableFields()
106
+ {
107
+ return array(
108
+ 'customerIdentifier',
109
+ 'company',
110
+ 'firstName',
111
+ 'lastName',
112
+ 'primaryEmail',
113
+ 'customerStatus',
114
+ 'phoneNumber',
115
+ 'city',
116
+ 'stateProvince',
117
+ 'zipPostalCode',
118
+ 'country',
119
+ 'hasSchedules',
120
+ 'hasActiveSchedules',
121
+ 'hasPaymentMethods',
122
+ 'hasActivePaymentMethods',
123
+ );
124
+ }
125
+
126
+ public static function fromStdClass($obj)
127
+ {
128
+ $ret = new HpsPayPlanCustomer();
129
+ $ret->customerKey = property_exists($obj, 'customerKey') ? $obj->customerKey : null;
130
+ $ret->customerIdentifier = property_exists($obj, 'customerIdentifier') ? $obj->customerIdentifier : null;
131
+ $ret->firstName = property_exists($obj, 'firstName') ? $obj->firstName : null;
132
+ $ret->lastName = property_exists($obj, 'lastName') ? $obj->lastName : null;
133
+ $ret->company = property_exists($obj, 'company') ? $obj->company : null;
134
+ $ret->customerStatus = property_exists($obj, 'customerStatus') ? $obj->customerStatus : null;
135
+ $ret->primaryEmail = property_exists($obj, 'primaryEmail') ? $obj->primaryEmail : null;
136
+ $ret->phoneDay = property_exists($obj, 'phoneDay') ? $obj->phoneDay : null;
137
+ $ret->phoneDayExt = property_exists($obj, 'phoneDayExt') ? $obj->phoneDayExt : null;
138
+ $ret->phoneEvening = property_exists($obj, 'phoneEvening') ? $obj->phoneEvening : null;
139
+ $ret->phoneEveningExt = property_exists($obj, 'phoneEveningExt') ? $obj->phoneEveningExt : null;
140
+ $ret->phoneMobile = property_exists($obj, 'phoneMobile') ? $obj->phoneMobile : null;
141
+ $ret->phoneMobileExt = property_exists($obj, 'phoneMobileExt') ? $obj->phoneMobileExt : null;
142
+ $ret->fax = property_exists($obj, 'fax') ? $obj->fax : null;
143
+ $ret->title = property_exists($obj, 'title') ? $obj->title : null;
144
+ $ret->department = property_exists($obj, 'department') ? $obj->department : null;
145
+ $ret->addressLine1 = property_exists($obj, 'addressLine1') ? $obj->addressLine1 : null;
146
+ $ret->addressLine2 = property_exists($obj, 'addressLine2') ? $obj->addressLine2 : null;
147
+ $ret->city = property_exists($obj, 'city') ? $obj->city : null;
148
+ $ret->country = property_exists($obj, 'country') ? $obj->country : null;
149
+ $ret->stateProvince = property_exists($obj, 'stateProvince') ? $obj->stateProvince : null;
150
+ $ret->zipPostalCode = property_exists($obj, 'zipPostalCode') ? $obj->zipPostalCode : null;
151
+ $ret->paymentMethods = property_exists($obj, 'paymentMethods') ? array_map('HpsPayPlanPaymentMethod::fromStdClass', $obj->paymentMethods) : null;
152
+ $ret->schedules = property_exists($obj, 'schedules') ? array_map('HpsPayPlanSchedule::fromStdClass', $obj->schedules) : null;
153
+ $ret->creationDate = property_exists($obj, 'creationDate') ? $obj->creationDate : null;
154
+ $ret->lastChangeDate = property_exists($obj, 'lastChangeDate') ? $obj->lastChangeDate : null;
155
+ $ret->statusSetDate = property_exists($obj, 'statusSetDate') ? $obj->statusSetDate : null;
156
+ return $ret;
157
+ }
158
+
159
+ // Needs to be implemented to get name of child class
160
+ public function getEditableFieldsWithValues($class = '', $params = array())
161
+ {
162
+ return parent::getEditableFieldsWithValues(get_class(), $params);
163
+ }
164
+ }
lib/SecureSubmit/src/Entities/PayPlan/HpsPayPlanPaymentMethod.php ADDED
@@ -0,0 +1,214 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsPayPlanPaymentMethod extends HpsPayPlanResourceAbstract
4
+ {
5
+ /** @var string|null */
6
+ public $paymentMethodKey = null;
7
+
8
+ /** @var string|null */
9
+ public $paymentMethodType = null;
10
+
11
+ /** @var string|null */
12
+ public $preferredPayment = null;
13
+
14
+ /** @var string|null */
15
+ public $paymentStatus = null;
16
+
17
+ /** @var string|null */
18
+ public $paymentMethodIdentifier = null;
19
+
20
+ /** @var integer|null */
21
+ public $customerKey = null;
22
+
23
+ /** @var string|null */
24
+ public $customerIdentifier = null;
25
+
26
+ /** @var string|null */
27
+ public $customerStatus = null;
28
+
29
+ /** @var string|null */
30
+ public $firstName = null;
31
+
32
+ /** @var string|null */
33
+ public $lastName = null;
34
+
35
+ /** @var string|null */
36
+ public $company = null;
37
+
38
+ /** @var string|null */
39
+ public $nameOnAccount = null;
40
+
41
+ /** @var string|null */
42
+ public $accountNumberLast4 = null;
43
+
44
+ /** @var string|null */
45
+ public $paymentMethod = null;
46
+
47
+ /** @var string|null */
48
+ public $cardBrand = null;
49
+
50
+ /** @var string|null */
51
+ public $expirationDate = null;
52
+
53
+ /** @var string|null */
54
+ public $cvvResponseCode = null;
55
+
56
+ /** @var string|null */
57
+ public $avsResponseCode = null;
58
+
59
+ /** @var string|null */
60
+ public $achType = null;
61
+
62
+ /** @var string|null */
63
+ public $accountType = null;
64
+
65
+ /** @var string|null */
66
+ public $routingNumber = null;
67
+
68
+ /** @var string|null */
69
+ public $telephoneIndicator = null;
70
+
71
+ /** @var string|null */
72
+ public $addressLine1 = null;
73
+
74
+ /** @var string|null */
75
+ public $addressLine2 = null;
76
+
77
+ /** @var string|null */
78
+ public $city = null;
79
+
80
+ /** @var string|null */
81
+ public $stateProvince = null;
82
+
83
+ /** @var string|null */
84
+ public $zipPostalCode = null;
85
+
86
+ /** @var string|null */
87
+ public $country = null;
88
+
89
+ /** @var string|null */
90
+ public $accountHolderYob = null;
91
+
92
+ /** @var string|null */
93
+ public $driversLicenseState = null;
94
+
95
+ /** @var string|null */
96
+ public $driversLicenseNumber = null;
97
+
98
+ /** @var string|null */
99
+ public $socialSecurityNumberLast4 = null;
100
+
101
+ /** @var string|null */
102
+ public $hasSchedules = null;
103
+
104
+ /** @var string|null */
105
+ public $hasActiveSchedules = null;
106
+
107
+ public static function getEditableFields($type = null)
108
+ {
109
+ $fields = array(
110
+ 'preferredPayment',
111
+ 'paymentStatus',
112
+ 'paymentMethodIdentifier',
113
+ 'nameOnAccount',
114
+ 'addressLine1',
115
+ 'addressLine2',
116
+ 'city',
117
+ 'stateProvince',
118
+ 'zipPostalCode',
119
+ );
120
+
121
+ $ccOnly = array(
122
+ 'expirationDate',
123
+ 'country',
124
+ );
125
+
126
+ $achOnly = array(
127
+ 'telephoneIndicator',
128
+ 'accountHolderYob',
129
+ 'driversLicenseState',
130
+ 'driversLicenseNumber',
131
+ 'socialSecurityNumberLast4',
132
+ );
133
+
134
+ switch ($type) {
135
+ case HpsPayPlanPaymentMethodType::ACH:
136
+ return array_merge($fields, $achOnly);
137
+ break;
138
+ case HpsPayPlanPaymentMethodType::CREDIT_CARD:
139
+ return array_merge($fields, $ccOnly);
140
+ break;
141
+ default:
142
+ return array_merge($fields, $achOnly, $ccOnly);
143
+ break;
144
+ }
145
+ }
146
+
147
+ public static function getSearchableFields()
148
+ {
149
+ return array(
150
+ 'customerIdentifier',
151
+ 'achType',
152
+ 'accountType',
153
+ 'accountNumberLast4',
154
+ 'routingNumber',
155
+ 'cardBrand',
156
+ 'cardBINNumber',
157
+ 'expirationDateStart',
158
+ 'expirationDateEnd',
159
+ 'paymentMethodType',
160
+ 'paymentStatus',
161
+ 'hasSchedules',
162
+ 'hasActiveSchedules',
163
+ );
164
+ }
165
+
166
+ public static function fromStdClass($obj)
167
+ {
168
+ $ret = new HpsPayPlanPaymentMethod();
169
+ $ret->paymentMethodKey = property_exists($obj, 'paymentMethodKey') ? $obj->paymentMethodKey : null;
170
+ $ret->paymentMethodType = property_exists($obj, 'paymentMethodType') ? $obj->paymentMethodType : null;
171
+ $ret->preferredPayment = property_exists($obj, 'preferredPayment') ? $obj->preferredPayment : null;
172
+ $ret->paymentStatus = property_exists($obj, 'paymentStatus') ? $obj->paymentStatus : null;
173
+ $ret->paymentMethodIdentifier = property_exists($obj, 'paymentMethodIdentifier') ? $obj->paymentMethodIdentifier : null;
174
+ $ret->customerKey = property_exists($obj, 'customerKey') ? $obj->customerKey : null;
175
+ $ret->customerIdentifier = property_exists($obj, 'customerIdentifier') ? $obj->customerIdentifier : null;
176
+ $ret->customerStatus = property_exists($obj, 'customerStatus') ? $obj->customerStatus : null;
177
+ $ret->firstName = property_exists($obj, 'firstName') ? $obj->firstName : null;
178
+ $ret->lastName = property_exists($obj, 'lastName') ? $obj->lastName : null;
179
+ $ret->company = property_exists($obj, 'company') ? $obj->company : null;
180
+ $ret->nameOnAccount = property_exists($obj, 'nameOnAccount') ? $obj->nameOnAccount : null;
181
+ $ret->accountNumberLast4 = property_exists($obj, 'accountNumberLast4') ? $obj->accountNumberLast4 : null;
182
+ $ret->paymentMethod = property_exists($obj, 'paymentMethod') ? $obj->paymentMethod : null;
183
+ $ret->cardBrand = property_exists($obj, 'cardBrand') ? $obj->cardBrand : null;
184
+ $ret->expirationDate = property_exists($obj, 'expirationDate') ? $obj->expirationDate : null;
185
+ $ret->cvvResponseCode = property_exists($obj, 'cvvResponseCode') ? $obj->cvvResponseCode : null;
186
+ $ret->avsResponseCode = property_exists($obj, 'avsResponseCode') ? $obj->avsResponseCode : null;
187
+ $ret->achType = property_exists($obj, 'achType') ? $obj->achType : null;
188
+ $ret->accountType = property_exists($obj, 'accountType') ? $obj->accountType : null;
189
+ $ret->routingNumber = property_exists($obj, 'routingNumber') ? $obj->routingNumber : null;
190
+ $ret->telephoneIndicator = property_exists($obj, 'telephoneIndicator') ? $obj->telephoneIndicator : null;
191
+ $ret->addressLine1 = property_exists($obj, 'addressLine1') ? $obj->addressLine1 : null;
192
+ $ret->addressLine2 = property_exists($obj, 'addressLine2') ? $obj->addressLine2 : null;
193
+ $ret->city = property_exists($obj, 'city') ? $obj->city : null;
194
+ $ret->stateProvince = property_exists($obj, 'stateProvince') ? $obj->stateProvince : null;
195
+ $ret->zipPostalCode = property_exists($obj, 'zipPostalCode') ? $obj->zipPostalCode : null;
196
+ $ret->country = property_exists($obj, 'country') ? $obj->country : null;
197
+ $ret->accountHolderYob = property_exists($obj, 'accountHolderYob') ? $obj->accountHolderYob : null;
198
+ $ret->driversLicenseState = property_exists($obj, 'driversLicenseState') ? $obj->driversLicenseState : null;
199
+ $ret->driversLicenseNumber = property_exists($obj, 'driversLicenseNumber') ? $obj->driversLicenseNumber : null;
200
+ $ret->socialSecurityNumberLast4 = property_exists($obj, 'socialSecurityNumberLast4') ? $obj->socialSecurityNumberLast4 : null;
201
+ $ret->hasSchedules = property_exists($obj, 'hasSchedules') ? $obj->hasSchedules : null;
202
+ $ret->hasActiveSchedules = property_exists($obj, 'hasActiveSchedules') ? $obj->hasActiveSchedules : null;
203
+ $ret->creationDate = property_exists($obj, 'creationDate') ? $obj->creationDate : null;
204
+ $ret->lastChangeDate = property_exists($obj, 'lastChangeDate') ? $obj->lastChangeDate : null;
205
+ $ret->statusSetDate = property_exists($obj, 'statusSetDate') ? $obj->statusSetDate : null;
206
+ return $ret;
207
+ }
208
+
209
+ // Needs to be implemented to get name of child class
210
+ public function getEditableFieldsWithValues($class = '', $params = array())
211
+ {
212
+ return parent::getEditableFieldsWithValues(get_class(), array($this->paymentMethodType));
213
+ }
214
+ }
lib/SecureSubmit/src/Entities/PayPlan/HpsPayPlanSchedule.php ADDED
@@ -0,0 +1,178 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsPayPlanSchedule extends HpsPayPlanResourceAbstract
4
+ {
5
+ /** @var integer|null */
6
+ public $scheduleKey = null;
7
+
8
+ /** @var string|null */
9
+ public $scheduleIdentifier = null;
10
+
11
+ /** @var integer|null */
12
+ public $customerKey = null;
13
+
14
+ /** @var string|null */
15
+ public $scheduleName = null;
16
+
17
+ /** @var string|null */
18
+ public $scheduleStatus = null;
19
+
20
+ /** @var string|null */
21
+ public $paymentMethodKey = null;
22
+
23
+ /** @var object|array|null */
24
+ public $subtotalAmount = null;
25
+
26
+ /** @var object|array|null */
27
+ public $taxAmount = null;
28
+
29
+ /** @var decimal|null */
30
+ public $totalAmount = null;
31
+
32
+ /** @var integer|null */
33
+ public $deviceId = null;
34
+
35
+ /** @var date|null */
36
+ public $startDate = null;
37
+
38
+ /** @var string|null */
39
+ public $processingDateInfo = null;
40
+
41
+ /** @var string|null */
42
+ public $frequency = null;
43
+
44
+ /** @var string|null */
45
+ public $duration = null;
46
+
47
+ /** @var date|null */
48
+ public $endDate = null;
49
+
50
+ /** @var integer|null */
51
+ public $reprocessingCount = null;
52
+
53
+ /** @var string|null */
54
+ public $emailReceipt = null;
55
+
56
+ /** @var string|null */
57
+ public $emailAdvanceNotice = null;
58
+
59
+ /** @var string|null */
60
+ public $nextProcessingDate = null;
61
+
62
+ /** @var string|null */
63
+ public $previousProcessingDate = null;
64
+
65
+ /** @var integer|null */
66
+ public $approvedTransactionCount = null;
67
+
68
+ /** @var integer|null */
69
+ public $failureCount = null;
70
+
71
+ /** @var decimal|null */
72
+ public $totalApprovedAmountToDate = null;
73
+
74
+ /** @var integer|null */
75
+ public $numberOfPayments = null;
76
+
77
+ /** @var integer|null */
78
+ public $numberOfPaymentsRemaining = null;
79
+
80
+ /** @var string|null */
81
+ public $cancellationDate = null;
82
+
83
+ /** @var string|null */
84
+ public $scheduleStarted = null;
85
+
86
+ public static function getEditableFields()
87
+ {
88
+ return array(
89
+ 'scheduleName',
90
+ 'scheduleStatus',
91
+ 'deviceId',
92
+ 'paymentMethodKey',
93
+ 'subtotalAmount',
94
+ 'taxAmount',
95
+ 'numberOfPaymentsRemaining',
96
+ 'endDate',
97
+ 'cancellationDate',
98
+ 'reprocessingCount',
99
+ 'emailReceipt',
100
+ 'emailAdvanceNotice',
101
+ 'processingDateInfo',
102
+ // Only editable when scheduleStarted = false
103
+ 'scheduleIdentifier',
104
+ 'startDate',
105
+ 'frequency',
106
+ 'duration',
107
+ // Only editable when scheduleStarted = true
108
+ 'nextProcessingDate',
109
+ );
110
+ }
111
+
112
+ public static function getSearchableFields()
113
+ {
114
+ return array(
115
+ 'scheduleIdentifier',
116
+ 'scheduleName',
117
+ 'deviceIdFilter',
118
+ 'deviceName',
119
+ 'customerIdentifier',
120
+ 'customerKey',
121
+ 'lastname',
122
+ 'company',
123
+ 'paymentMethodType',
124
+ 'paymentMethodKey',
125
+ 'achType',
126
+ 'accountType',
127
+ 'cardBrand',
128
+ 'totalAmount',
129
+ 'startDate',
130
+ 'previousProcessingDate',
131
+ 'nextProcessingDate',
132
+ 'frequency',
133
+ 'duration',
134
+ 'scheduleStatus',
135
+ );
136
+ }
137
+
138
+ public static function fromStdClass($obj)
139
+ {
140
+ $ret = new HpsPayPlanSchedule();
141
+ $ret->scheduleKey = property_exists($obj, 'scheduleKey') ? $obj->scheduleKey : null;
142
+ $ret->scheduleIdentifier = property_exists($obj, 'scheduleIdentifier') ? $obj->scheduleIdentifier : null;
143
+ $ret->customerKey = property_exists($obj, 'customerKey') ? $obj->customerKey : null;
144
+ $ret->scheduleName = property_exists($obj, 'scheduleName') ? $obj->scheduleName : null;
145
+ $ret->scheduleStatus = property_exists($obj, 'scheduleStatus') ? $obj->scheduleStatus : null;
146
+ $ret->paymentMethodKey = property_exists($obj, 'paymentMethodKey') ? $obj->paymentMethodKey : null;
147
+ $ret->subtotalAmount = property_exists($obj, 'subtotalAmount') ? $obj->subtotalAmount : null;
148
+ $ret->taxAmount = property_exists($obj, 'taxAmount') ? $obj->taxAmount : null;
149
+ $ret->totalAmount = property_exists($obj, 'totalAmount') ? $obj->totalAmount : null;
150
+ $ret->deviceId = property_exists($obj, 'deviceId') ? $obj->deviceId : null;
151
+ $ret->startDate = property_exists($obj, 'startDate') ? $obj->startDate : null;
152
+ $ret->processingDateInfo = property_exists($obj, 'processingDateInfo') ? $obj->processingDateInfo : null;
153
+ $ret->frequency = property_exists($obj, 'frequency') ? $obj->frequency : null;
154
+ $ret->duration = property_exists($obj, 'duration') ? $obj->duration : null;
155
+ $ret->endDate = property_exists($obj, 'endDate') ? $obj->endDate : null;
156
+ $ret->reprocessingCount = property_exists($obj, 'reprocessingCount') ? $obj->reprocessingCount : null;
157
+ $ret->emailReceipt = property_exists($obj, 'emailReceipt') ? $obj->emailReceipt : null;
158
+ $ret->emailAdvanceNotice = property_exists($obj, 'emailAdvanceNotice') ? $obj->emailAdvanceNotice : null;
159
+ $ret->nextProcessingDate = property_exists($obj, 'nextProcessingDate') ? $obj->nextProcessingDate : null;
160
+ $ret->previousProcessingDate = property_exists($obj, 'previousProcessingDate') ? $obj->previousProcessingDate : null;
161
+ $ret->approvedTransactionCount = property_exists($obj, 'approvedTransactionCount') ? $obj->approvedTransactionCount : null;
162
+ $ret->failureCount = property_exists($obj, 'failureCount') ? $obj->failureCount : null;
163
+ $ret->totalApprovedAmountToDate = property_exists($obj, 'totalApprovedAmountToDate') ? $obj->totalApprovedAmountToDate : null;
164
+ $ret->numberOfPaymentsRemaining = property_exists($obj, 'numberOfPaymentsRemaining') ? $obj->numberOfPaymentsRemaining : null;
165
+ $ret->cancellationDate = property_exists($obj, 'cancellationDate') ? $obj->cancellationDate : null;
166
+ $ret->scheduleStarted = property_exists($obj, 'scheduleStarted') ? $obj->scheduleStarted : null;
167
+ $ret->creationDate = property_exists($obj, 'creationDate') ? $obj->creationDate : null;
168
+ $ret->lastChangeDate = property_exists($obj, 'lastChangeDate') ? $obj->lastChangeDate : null;
169
+ $ret->statusSetDate = property_exists($obj, 'statusSetDate') ? $obj->statusSetDate : null;
170
+ return $ret;
171
+ }
172
+
173
+ // Needs to be implemented to get name of child class
174
+ public function getEditableFieldsWithValues($class = '', $params = array())
175
+ {
176
+ return parent::getEditableFieldsWithValues(get_class(), $params);
177
+ }
178
+ }
lib/SecureSubmit/src/Entities/index.php ADDED
@@ -0,0 +1 @@
 
1
+ <?php
lib/SecureSubmit/src/Infrastructure/Enums/HpsACHType.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+
3
+ abstract class HpsACHType extends HpsAccountType
4
+ {
5
+ }
lib/SecureSubmit/src/Infrastructure/Enums/HpsAccountType.php ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ abstract class HpsAccountType
4
+ {
5
+ const CHECKING = 'Checking';
6
+ const SAVINGS = 'Savings';
7
+ }
lib/SecureSubmit/src/Infrastructure/Enums/HpsCardBrand.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ abstract class HpsCardBrand
4
+ {
5
+ const MASTERCARD = 'MC';
6
+ const AMEX = 'Amex';
7
+ const VISA = 'Visa';
8
+ const DISCOVER = 'Disc';
9
+ }
lib/SecureSubmit/src/Infrastructure/Enums/HpsCheckType.php ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ abstract class HpsCheckType
4
+ {
5
+ const PERSONAL = 'PERSONAL';
6
+ const BUSINESS = 'BUSINESS';
7
+ }
lib/SecureSubmit/src/Infrastructure/Enums/HpsDataEntryMode.php ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ abstract class HpsDataEntryMode
4
+ {
5
+ const MANUAL = 'MANUAL';
6
+ const SWIPE = 'SWIPE';
7
+ }
lib/SecureSubmit/src/Infrastructure/Enums/HpsExceptionCodes.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ abstract class HpsExceptionCodes
4
+ {
5
+ // general codes
6
+ const AUTHENTICATION_ERROR = 0;
7
+ const INVALID_CONFIGURATION = 1;
8
+
9
+ // input codes
10
+ const INVALID_AMOUNT = 2;
11
+ const MISSING_CURRENCY = 3;
12
+ const INVALID_CURRENCY = 4;
13
+ const INVALID_DATE = 5;
14
+ const MISSING_CHECK_NAME = 27;
15
+
16
+ // gateway codes
17
+ const UNKNOWN_GATEWAY_ERROR = 6;
18
+ const INVALID_ORIGINAL_TRANSACTION = 7;
19
+ const NO_OPEN_BATCH = 8;
20
+ const INVALID_CPC_DATA = 9;
21
+ const INVALID_CARD_DATA = 10;
22
+ const INVALID_NUMBER = 11;
23
+ const GATEWAY_TIMEOUT = 12;
24
+ const UNEXPECTED_GATEWAY_RESPONSE = 13;
25
+ const GATEWAY_TIMEOUT_REVERSAL_ERROR = 14;
26
+
27
+ // credit issuer codes
28
+ const INCORRECT_NUMBER = 15;
29
+ const EXPIRED_CARD = 16;
30
+ const INVALID_PIN = 17;
31
+ const PIN_ENTRIES_EXCEEDED = 18;
32
+ const INVALID_EXPIRY = 19;
33
+ const PIN_VERIFICATION = 20;
34
+ const ISSUER_TIMEOUT = 21;
35
+ const INCORRECT_CVC = 22;
36
+ const CARD_DECLINED = 23;
37
+ const PROCESSING_ERROR = 24;
38
+ const ISSUER_TIMEOUT_REVERSAL_ERROR = 25;
39
+ const UNKNOWN_CREDIT_ERROR = 26;
40
+ }
lib/SecureSubmit/src/Infrastructure/Enums/HpsGiftCardAliasAction.php ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ abstract class HpsGiftCardAliasAction
4
+ {
5
+ const DELETE = 'DELETE';
6
+ const ADD = 'ADD';
7
+ const CREATE = 'CREATE';
8
+ }
lib/SecureSubmit/src/Infrastructure/Enums/HpsItemChoiceTypePosResponseVer10Transaction.php ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ abstract class HpsItemChoiceTypePosResponseVer10Transaction
4
+ {
5
+ const ADD_ATTACHMENT = 'AddAttachment';
6
+ const AUTHENTICATE = 'Authenticate';
7
+ const BATCH_CLOSE = 'BatchClose';
8
+ const CANCEL_IMPERSONATION = 'CancelImpersonation';
9
+ const CHECK_SALE = 'CheckSale';
10
+ const CHECK_VOID = 'CheckVoid';
11
+ const CREDIT_ACCOUNT_VERIFY = 'CreditAccountVerify';
12
+ const CREDIT_ADD_TO_BATCH = 'CreditAddToBatch';
13
+ const CREDIT_AUTH = 'CreditAuth';
14
+ const CREDIT_CPC_EDIT = 'CreditCPCEdit';
15
+ const CREDIT_INCREMENTAL_AUTH = 'CreditIncrementalAuth';
16
+ const CREDIT_OFFLINE_AUTH = 'CreditOfflineAuth';
17
+ const CREDIT_OFFLINE_SALE = 'CreditOfflineSale';
18
+ const CREDIT_RETURN = 'CreditReturn';
19
+ const CREDIT_REVERSAL = 'CreditReversal';
20
+ const CREDIT_SALE = 'CreditSale';
21
+ const CREDIT_TXN_EDIT = 'CreditTxnEdit';
22
+ const CREDIT_VOID = 'CreditVoid';
23
+ const DEBIT_ADD_VALUE = 'DebitAddValue';
24
+ const DEBIT_RETURN = 'DebitReturn';
25
+ const DEBIT_REVERSAL = 'DebitReversal';
26
+ const DEBIT_SALE = 'DebitSale';
27
+ const EBT_BALANCE_INQUIRY = 'EBTBalanceInquiry';
28
+ const EBT_CASH_BACK_PURCHASE = 'EBTCashBackPurchase';
29
+ const EBT_CASH_BENEFIT_WITHDRAWAL = 'EBTCashBenefitWithdrawal';
30
+ const EBT_FS_PURCHASE = 'EBTFSPurchase';
31
+ const EBT_FS_RETURN = 'EBTFSReturn';
32
+ const EBT_VOUCHER_PURCHASE = 'EBTVoucherPurchase';
33
+ const END_TO_END_TEST = 'EndToEndTest';
34
+ const FIND_TRANSACTIONS = 'FindTransactions';
35
+ const GET_ATTACHMENTS = 'GetAttachments';
36
+ const GET_USER_DEVICE_SETTINGS = 'GetUserDeviceSettings';
37
+ const GET_USER_SETTINGS = 'GetUserSettings';
38
+ const GIFT_CARD_ACTIVATE = 'GiftCardActivate';
39
+ const GIFT_CARD_ADD_VALUE = 'GiftCardAddValue';
40
+ const GIFT_CARD_BALANCE = 'GiftCardBalance';
41
+ const GIFT_CARD_CURRENT_DAY_TOTALS = 'GiftCardCurrentDayTotals';
42
+ const GIFT_CARD_DEACTIVATE = 'GiftCardDeactivate';
43
+ const GIFT_CARD_PREVIOUS_DAY_TOTALS = 'GiftCardPreviousDayTotals';
44
+ const GIFT_CARD_REPLACE = 'GiftCardReplace';
45
+ const GIFT_CARD_REVERSAL = 'GiftCardReversal';
46
+ const GIFT_CARD_SALE = 'GiftCardSale';
47
+ const GIFT_CARD_VOID = 'GiftCardVoid';
48
+ const IMPERSONATE = 'Impersonate';
49
+ const INVALIDATE_AUTHENTICATION = 'InvalidateAuthentication';
50
+ const MANAGE_SETTINGS = 'ManageSettings';
51
+ const MANAGE_USERS = 'ManageUsers';
52
+ const PRE_PAID_ADD_VALUE = 'PrePaidAddValue';
53
+ const PRE_PAID_BALANCE_INQUIRY = 'PrePaidBalanceInquiry';
54
+ const RECURRING_BILLING = 'RecurringBilling';
55
+ const REPORT_ACTIVITY = 'ReportActivity';
56
+ const REPORT_BATCH_DETAIL = 'ReportBatchDetail';
57
+ const REPORT_BATCH_HISTORY = 'ReportBatchHistory';
58
+ const REPORT_BATCH_SUMMARY = 'ReportBatchSummary';
59
+ const REPORT_OPEN_AUTHS = 'ReportOpenAuths';
60
+ const REPORT_SEARCH = 'ReportSearch';
61
+ const REPORT_TXN_DETAIL = 'ReportTxnDetail';
62
+ const SEND_RECEIPT = 'SendReceipt';
63
+ const TEST_CREDENTIALS = 'TestCredentials';
64
+ }
lib/SecureSubmit/src/Infrastructure/Enums/HpsPayPlanAccountType.php ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ abstract class HpsPayPlanAccountType
4
+ {
5
+ const BUSINESS = 'Business';
6
+ const PERSONAL = 'Personal';
7
+ }
lib/SecureSubmit/src/Infrastructure/Enums/HpsPayPlanCustomerStatus.php ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ abstract class HpsPayPlanCustomerStatus
4
+ {
5
+ const ACTIVE = 'Active';
6
+ const INACTIVE = 'Inactive';
7
+ }
lib/SecureSubmit/src/Infrastructure/Enums/HpsPayPlanPaymentMethodStatus.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ abstract class HpsPayPlanPaymentMethodStatus extends HpsPayPlanCustomerStatus
4
+ {
5
+ const INVALID = 'Invalid';
6
+ const REVOKED = 'Revoked';
7
+ const EXPIRED = 'Expired';
8
+ const LOST_STOLEN = 'Lost/Stolen';
9
+ }
lib/SecureSubmit/src/Infrastructure/Enums/HpsPayPlanPaymentMethodType.php ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ abstract class HpsPayPlanPaymentMethodType
4
+ {
5
+ const ACH = 'ACH';
6
+ const CREDIT_CARD = 'Credit Card';
7
+ }
lib/SecureSubmit/src/Infrastructure/Enums/HpsPayPlanScheduleDuration.php ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ abstract class HpsPayPlanScheduleDuration
4
+ {
5
+ const ONGOING = 'Ongoing';
6
+ const END_DATE = 'End Date';
7
+ const LIMITED_NUMBER = 'Limited Number';
8
+ }
lib/SecureSubmit/src/Infrastructure/Enums/HpsPayPlanScheduleFrequency.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ abstract class HpsPayPlanScheduleFrequency
4
+ {
5
+ const WEEKLY = 'Weekly';
6
+ const BIWEEKLY = 'Bi-Weekly';
7
+ const SEMIMONTHLY = 'Semi-Monthly';
8
+ const MONTHLY = 'Monthly';
9
+ const QUARTERLY = 'Quarterly';
10
+ const SEMIANNUALLY = 'Semi-Annually';
11
+ const ANNUALLY = 'Annually';
12
+ }
lib/SecureSubmit/src/Infrastructure/Enums/HpsPayPlanScheduleStatus.php ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ <?php
2
+
3
+ abstract class HpsPayPlanScheduleStatus extends HpsPayPlanCustomerStatus
4
+ {
5
+ const FAILED = 'FAILED';
6
+ }
lib/SecureSubmit/src/Infrastructure/Enums/HpsSECCode.php ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ abstract class HpsSECCode
4
+ {
5
+ const PPD = 'PPD';
6
+ const CCD = 'CCD';
7
+ const POP = 'POP';
8
+ const WEB = 'WEB';
9
+ const TEL = 'TEL';
10
+ const EBRONZE = 'eBronze';
11
+ }
lib/SecureSubmit/src/Infrastructure/Enums/HpsTaxType.php ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ abstract class HpsTaxType
4
+ {
5
+ const NOT_USED = 'NOTUSED';
6
+ const SALES_TAX = 'SALESTAX';
7
+ const TAX_EXEMPT = 'TAXEXEMPT';
8
+ }
lib/SecureSubmit/src/Infrastructure/Enums/HpsTransactionType.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ abstract class HpsTransactionType
4
+ {
5
+ const AUTHORIZE = 1;
6
+ const CAPTURE = 2;
7
+ const CHARGE = 3;
8
+ const REFUND = 4;
9
+ const REVERSE = 5;
10
+ const VERIFY = 6;
11
+ const LIST_TRANSACTION = 7;
12
+ const GET = 8;
13
+ const VOID = 9;
14
+ const SECURITY_ERROR = 10;
15
+ const BATCH_CLOSE = 11;
16
+ }
lib/SecureSubmit/src/Infrastructure/HpsApiConnectionException.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsApiConnectionException extends HpsException
4
+ {
5
+ public function __construct($message, $code, $innerException = null)
6
+ {
7
+ parent::__construct($message, $code, $innerException);
8
+ }
9
+ }
lib/SecureSubmit/src/Infrastructure/HpsArgumentException.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsArgumentException extends HpsException
4
+ {
5
+ public function __construct($message, $code, $innerException = null)
6
+ {
7
+ parent::__construct($message, $code, $innerException);
8
+ }
9
+ }
lib/SecureSubmit/src/Infrastructure/HpsAuthenticationException.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsAuthenticationException extends HpsException
4
+ {
5
+ public function __construct($code, $message)
6
+ {
7
+ $this->code = $code;
8
+ $this->message = $message;
9
+ }
10
+ }
lib/SecureSubmit/src/Infrastructure/HpsCheckException.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsCheckException extends HpsException
4
+ {
5
+ public $transactionId = null;
6
+ public $details = null;
7
+ public $code = null;
8
+
9
+ public function __construct($transactionId, $details, $code, $message = null)
10
+ {
11
+ $this->transactionId = $transactionId;
12
+ $this->details = $details;
13
+ $this->code = $code;
14
+ $this->message = $message;
15
+ }
16
+ }
lib/SecureSubmit/src/Infrastructure/HpsConfiguration.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsConfiguration
4
+ {
5
+ public $secretApiKey = null;
6
+ public $licenseId = -1;
7
+ public $siteId = -1;
8
+ public $deviceId = -1;
9
+ public $versionNumber = null;
10
+ public $userName = null;
11
+ public $password = null;
12
+ public $developerId = null;
13
+ public $siteTrace = null;
14
+ public $useProxy = null;
15
+ public $proxyOptions = null;
16
+ public $avsResponseErrors = null;
17
+ public $serviceUri = "https://posgateway.cert.secureexchange.net/Hps.Exchange.PosGateway/PosGatewayService.asmx";
18
+ }
lib/SecureSubmit/src/Infrastructure/HpsCreditException.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsCreditException extends HpsException
4
+ {
5
+ public $transactionId = null;
6
+ public $code = null;
7
+ public $details = null;
8
+
9
+ public function __construct($transactionId, $code, $message, $issuerCode = null, $issuerMessage = null, $innerException = null)
10
+ {
11
+ $this->transactionId = $transactionId;
12
+ $this->code = $code;
13
+
14
+ if ($issuerCode != null || $issuerMessage != null) {
15
+ $this->details = new HpsCreditExceptionDetails();
16
+ $this->details->issuerResponseCode = $issuerCode;
17
+ $this->details->issuerResponseText = $issuerMessage;
18
+ parent::__construct($message, $code, $innerException);
19
+ }
20
+ }
21
+ }
lib/SecureSubmit/src/Infrastructure/HpsCreditExceptionDetails.php ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsCreditExceptionDetails
4
+ {
5
+ public $issuerResponseCode = null;
6
+ public $issuerResponseText = null;
7
+ }
lib/SecureSubmit/src/Infrastructure/HpsException.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsException extends Exception
4
+ {
5
+ public $code = null;
6
+ public $innerException = null;
7
+
8
+ public function __construct($message, $code = null, $innerException = null)
9
+ {
10
+ $this->message = $message;
11
+ if ($code != null) {
12
+ $this->code = $code;
13
+ }
14
+ if ($innerException != null) {
15
+ $this->innerException = $innerException;
16
+ }
17
+ }
18
+ }
lib/SecureSubmit/src/Infrastructure/HpsGatewayException.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsGatewayException extends HpsException
4
+ {
5
+ public $code = null;
6
+ public $details = null;
7
+
8
+ public function __construct($code, $message, $gatewayResponseCode = null, $gatewayResponseMessage = null, $innerException = null)
9
+ {
10
+ $this->code = $code;
11
+ $this->message = $message;
12
+
13
+ if ($gatewayResponseCode != null || $gatewayResponseMessage != null) {
14
+ $this->details = new HpsGatewayExceptionDetails();
15
+ $this->details->gatewayResponseCode = $gatewayResponseCode;
16
+ $this->details->gatewayResponseMessage = $gatewayResponseMessage;
17
+
18
+ $this->innerException = $innerException;
19
+ }
20
+ }
21
+ }
lib/SecureSubmit/src/Infrastructure/HpsGatewayExceptionDetails.php ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsGatewayExceptionDetails
4
+ {
5
+ public $gatewayResponseCode = null;
6
+ public $gatewayResponseMessage = null;
7
+ }
lib/SecureSubmit/src/Infrastructure/HpsInvalidRequestException.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsInvalidRequestException extends HpsException
4
+ {
5
+ public $param = null;
6
+ public $code = null;
7
+
8
+ public function __construct($code, $message, $paramName = null)
9
+ {
10
+ $this->param = $paramName;
11
+ $this->message = $message;
12
+ $this->code = $code;
13
+ parent::__construct($message);
14
+ }
15
+ }
lib/SecureSubmit/src/Infrastructure/HpsProcessorException.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsProcessorException extends HpsException
4
+ {
5
+ public $transactionId = null;
6
+ public $code = null;
7
+ public $details = null;
8
+
9
+ public function __construct($transactionId, $code, $message, $processorCode = null, $processorMessage = null, $innerException = null)
10
+ {
11
+ $this->transactionId = $transactionId;
12
+ $this->code = $code;
13
+
14
+ if ($processorCode != null || $processorMessage != null) {
15
+ $this->details = new HpsProcessorExceptionDetails();
16
+ $this->details->processorResponseCode = $processorCode;
17
+ $this->details->processorResponseText = $processorMessage;
18
+ parent::__construct($message, $code, $innerException);
19
+ }
20
+ }
21
+ }
lib/SecureSubmit/src/Infrastructure/HpsProcessorExceptionDetails.php ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsProcessorExceptionDetails
4
+ {
5
+ public $processorResponseCode = null;
6
+ public $processorResponseText = null;
7
+ }
lib/SecureSubmit/src/Infrastructure/Validation/HpsGatewayResponseValidation.php ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsGatewayResponseValidation
4
+ {
5
+ public static function checkResponse($response, $expectedType)
6
+ {
7
+ $rspCode = $response->Header->GatewayRspCode;
8
+ $rspText = $response->Header->GatewayRspMsg;
9
+ $e = HpsGatewayResponseValidation::getException($rspCode, $rspText, $response);
10
+
11
+ if ($e != null) {
12
+ throw $e;
13
+ }
14
+
15
+ if (!isset($response->Transaction) || !isset($response->Transaction->$expectedType)) {
16
+ throw new HpsGatewayException(
17
+ HpsExceptionCodes::UNEXPECTED_GATEWAY_ERROR,
18
+ 'Unexpected response from HPS gateway'
19
+ );
20
+ }
21
+ }
22
+
23
+ public static function getException($responseCode, $responseText, $response)
24
+ {
25
+ $e = null;
26
+
27
+ switch ($responseCode) {
28
+ case '0':
29
+ break;
30
+ case '-2':
31
+ $e = new HpsAuthenticationException(
32
+ HpsExceptionCodes::AUTHENTICATION_ERROR,
33
+ 'Authentication Error. Please double check your service configuration'
34
+ );
35
+ break;
36
+ case '3':
37
+ print_r($response);
38
+ $e = new HpsGatewayException(
39
+ HpsExceptionCodes::INVALID_ORIGINAL_TRANSACTION,
40
+ $responseText,
41
+ $responseCode,
42
+ $responseText
43
+ );
44
+ break;
45
+ case '5':
46
+ $e = new HpsGatewayException(
47
+ HpsExceptionCodes::NO_OPEN_BATCH,
48
+ $responseText,
49
+ $responseCode,
50
+ $responseText
51
+ );
52
+ break;
53
+ case '12':
54
+ $e = new HpsGatewayException(
55
+ HpsExceptionCodes::INVALID_CPC_DATA,
56
+ 'Invalid CPC data',
57
+ $responseCode,
58
+ $responseText
59
+ );
60
+ break;
61
+ case '13':
62
+ $e = new HpsGatewayException(
63
+ HpsExceptionCodes::INVALID_CARD_DATA,
64
+ 'Invalid card data',
65
+ $responseCode,
66
+ $responseText
67
+ );
68
+ break;
69
+ case '14':
70
+ $e = new HpsGatewayException(
71
+ HpsExceptionCodes::INVALID_NUMBER,
72
+ 'The card number is not valid',
73
+ $responseCode,
74
+ $responseText
75
+ );
76
+ break;
77
+ case '30':
78
+ $e = new HpsGatewayException(
79
+ HpsExceptionCodes::GATEWAY_ERROR,
80
+ 'Gateway timed out',
81
+ $responseCode,
82
+ $responseText
83
+ );
84
+ break;
85
+ case '1':
86
+ default:
87
+ $e = new HpsGatewayException(
88
+ HpsExceptionCodes::UNKNOWN_GATEWAY_ERROR,
89
+ $responseText,
90
+ $responseCode,
91
+ $responseText
92
+ );
93
+ }
94
+
95
+ return $e;
96
+ }
97
+ }
lib/SecureSubmit/src/Infrastructure/Validation/HpsInputValidation.php ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsInputValidation
4
+ {
5
+ private static $_defaultAllowedCurrencies = array('usd');
6
+
7
+ public static function checkAmount($amount)
8
+ {
9
+ if ($amount < 0 || $amount == null) {
10
+ throw new HpsInvalidRequestException(
11
+ HpsExceptionCodes::INVALID_AMOUNT,
12
+ 'Must be greater than or equal to 0.',
13
+ 'amount'
14
+ );
15
+ }
16
+ $amount = preg_replace('/[^0-9\.]/', '', $amount);
17
+ return sprintf("%0.2f", round($amount, 3));
18
+ }
19
+
20
+ public static function checkCurrency($currency, $allowedCurrencies = null)
21
+ {
22
+ $currencies = self::$_defaultAllowedCurrencies;
23
+ if (isset($allowedCurrencies) && is_array($allowedCurrencies)) {
24
+ $currencies = $allowedCurrencies;
25
+ }
26
+
27
+ if ($currency == null || $currency == '') {
28
+ throw new HpsInvalidRequestException(
29
+ HpsExceptionCodes::MISSING_CURRENCY,
30
+ 'Currency cannot be none',
31
+ 'currency'
32
+ );
33
+ } else if (!in_array(strtolower($currency), $currencies)) {
34
+ throw new HpsInvalidRequestException(
35
+ HpsExceptionCodes::INVALID_CURRENCY,
36
+ "'".strtolower($currency)."' is not a supported currency",
37
+ 'currency'
38
+ );
39
+ }
40
+ }
41
+
42
+ public static function cleanPhoneNumber($number)
43
+ {
44
+ return preg_replace('/\D+/', '', $number);
45
+ }
46
+
47
+ public static function cleanZipCode($zip)
48
+ {
49
+ return preg_replace('/\D+/', '', $zip);
50
+ }
51
+
52
+ public static function checkDateNotFuture($date)
53
+ {
54
+ $current = date('Y-m-d\TH:i:s.00\Z', time());
55
+
56
+ if ($date != null && $date > $current) {
57
+ throw new HpsInvalidRequestException(
58
+ HpsExceptionCodes::INVALID_DATE,
59
+ 'Date cannot be in the future'
60
+ );
61
+ }
62
+ }
63
+ }
lib/SecureSubmit/src/Infrastructure/Validation/HpsIssuerResponseValidation.php ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsIssuerResponseValidation
4
+ {
5
+ public static $_issuerCodeToCreditExceptionCode = array(
6
+ '02' => HpsExceptionCodes::CARD_DECLINED,
7
+ '03' => HpsExceptionCodes::CARD_DECLINED,
8
+ '04' => HpsExceptionCodes::CARD_DECLINED,
9
+ '05' => HpsExceptionCodes::CARD_DECLINED,
10
+ '41' => HpsExceptionCodes::CARD_DECLINED,
11
+ '43' => HpsExceptionCodes::CARD_DECLINED,
12
+ '44' => HpsExceptionCodes::CARD_DECLINED,
13
+ '51' => HpsExceptionCodes::CARD_DECLINED,
14
+ '56' => HpsExceptionCodes::CARD_DECLINED,
15
+ '61' => HpsExceptionCodes::CARD_DECLINED,
16
+ '62' => HpsExceptionCodes::CARD_DECLINED,
17
+ '63' => HpsExceptionCodes::CARD_DECLINED,
18
+ '65' => HpsExceptionCodes::CARD_DECLINED,
19
+ '78' => HpsExceptionCodes::CARD_DECLINED,
20
+ '06' => HpsExceptionCodes::PROCESSING_ERROR,
21
+ '07' => HpsExceptionCodes::PROCESSING_ERROR,
22
+ '12' => HpsExceptionCodes::PROCESSING_ERROR,
23
+ '15' => HpsExceptionCodes::PROCESSING_ERROR,
24
+ '19' => HpsExceptionCodes::PROCESSING_ERROR,
25
+ '52' => HpsExceptionCodes::PROCESSING_ERROR,
26
+ '53' => HpsExceptionCodes::PROCESSING_ERROR,
27
+ '57' => HpsExceptionCodes::PROCESSING_ERROR,
28
+ '58' => HpsExceptionCodes::PROCESSING_ERROR,
29
+ '76' => HpsExceptionCodes::PROCESSING_ERROR,
30
+ '77' => HpsExceptionCodes::PROCESSING_ERROR,
31
+ '96' => HpsExceptionCodes::PROCESSING_ERROR,
32
+ 'EC' => HpsExceptionCodes::PROCESSING_ERROR,
33
+ '13' => HpsExceptionCodes::INVALID_AMOUNT,
34
+ '14' => HpsExceptionCodes::INCORRECT_NUMBER,
35
+ '54' => HpsExceptionCodes::EXPIRED_CARD,
36
+ '55' => HpsExceptionCodes::INVALID_PIN,
37
+ '75' => HpsExceptionCodes::PIN_ENTRIES_EXCEEDED,
38
+ '80' => HpsExceptionCodes::INVALID_EXPIRY,
39
+ '86' => HpsExceptionCodes::PIN_VERIFICATION,
40
+ '91' => HpsExceptionCodes::ISSUER_TIMEOUT,
41
+ 'EB' => HpsExceptionCodes::INCORRECT_CVC,
42
+ 'N7' => HpsExceptionCodes::INCORRECT_CVC,
43
+ );
44
+
45
+ public static $_creditExceptionCodeToMessage = array(
46
+ HpsExceptionCodes::CARD_DECLINED => "The card was declined.",
47
+ HpsExceptionCodes::PROCESSING_ERROR => "An error occurred while processing the card.",
48
+ HpsExceptionCodes::INVALID_AMOUNT => "Must be greater than or equal 0.",
49
+ HpsExceptionCodes::EXPIRED_CARD => "The card has expired.",
50
+ HpsExceptionCodes::INVALID_PIN => "The 4-digit pin is invalid.",
51
+ HpsExceptionCodes::PIN_ENTRIES_EXCEEDED => "Maximum number of pin retries exceeded.",
52
+ HpsExceptionCodes::INVALID_EXPIRY => "Card expiration date is invalid.",
53
+ HpsExceptionCodes::PIN_VERIFICATION => "Can't verify card pin number.",
54
+ HpsExceptionCodes::INCORRECT_CVC => "The card's security code is incorrect.",
55
+ HpsExceptionCodes::ISSUER_TIMEOUT => "The card issuer timed-out.",
56
+ HpsExceptionCodes::UNKNOWN_CREDIT_ERROR => "An unknown issuer error has occurred.",
57
+ HpsExceptionCodes::INCORRECT_NUMBER => "The card number is incorrect."
58
+ );
59
+
60
+ public static function checkResponse($transactionId, $responseCode, $responseText)
61
+ {
62
+ $e = HpsIssuerResponseValidation::getException($transactionId, $responseCode, $responseText);
63
+
64
+ if ($e != null) {
65
+ throw $e;
66
+ }
67
+ }
68
+
69
+ public static function getException($transactionId, $responseCode, $responseText)
70
+ {
71
+ $responseCode = (string)$responseCode;
72
+ if ($responseCode == '85' || $responseCode == '00') {
73
+ return null;
74
+ }
75
+
76
+ $code = null;
77
+ if (array_key_exists($responseCode, self::$_issuerCodeToCreditExceptionCode)) {
78
+ $code = self::$_issuerCodeToCreditExceptionCode[$responseCode];
79
+ }
80
+
81
+ if ($code == null) {
82
+ return new HpsCreditException(
83
+ $transactionId,
84
+ HpsExceptionCodes::UNKNOWN_CREDIT_ERROR,
85
+ self::$_creditExceptionCodeToMessage[HpsExceptionCodes::UNKNOWN_CREDIT_ERROR],
86
+ $responseCode,
87
+ $responseText
88
+ );
89
+ }
90
+
91
+ $message = null;
92
+ if (array_key_exists($code, self::$_creditExceptionCodeToMessage)) {
93
+ $message = self::$_creditExceptionCodeToMessage[$code];
94
+ } else {
95
+ $message = 'Unknown issuer error';
96
+ }
97
+
98
+ return new HpsCreditException($transactionId, $code, $message, $responseCode, $responseText);
99
+ }
100
+ }
lib/SecureSubmit/src/Infrastructure/Validation/HpsProcessorResponseValidation.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsProcessorResponseValidation
4
+ {
5
+ public static function checkResponse($transactionId, $responseCode, $responseText, $item)
6
+ {
7
+ $e = self::getException($transactionId, $responseCode, $responseText, $item);
8
+
9
+ if ($e != null) {
10
+ throw $e;
11
+ }
12
+ }
13
+
14
+ public static function getException($transactionId, $responseCode, $responseText, $item)
15
+ {
16
+ $responseCode = (string)$responseCode;
17
+ $code = null;
18
+ $message = null;
19
+
20
+ if ($responseCode == '0') {
21
+ return null;
22
+ }
23
+
24
+ if (isset($item->Processor) && isset($item->Processor->Response)) {
25
+ $error = self::nvpToArray($item->Processor->Response);
26
+ $code = $error['Code'];
27
+ $message = $error['Message'];
28
+ }
29
+
30
+ return new HpsProcessorException($transactionId, $code, $message, $responseCode, $responseText);
31
+ }
32
+
33
+ protected static function nvpToArray($pairs)
34
+ {
35
+ $array = array();
36
+ foreach ($pairs->NameValuePair as $pair) {
37
+ $array[(string)$pair->Name] = (string)$pair->Value;
38
+ }
39
+ return $array;
40
+ }
41
+ }
lib/SecureSubmit/src/Infrastructure/index.php ADDED
@@ -0,0 +1 @@
 
1
+ <?php
lib/SecureSubmit/src/Services/Fluent/Gateway/Check/HpsCheckServiceOverrideBuilder.php ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * A fluent interface for creating and executing an override
5
+ * transaction through the HpsCheckService.
6
+ *
7
+ * @method HpsCheckServiceOverrideBuilder withCheck(HpsCheck $check)
8
+ * @method HpsCheckServiceOverrideBuilder withAmount(double $amount)
9
+ * @method HpsCheckServiceOverrideBuilder withClientTransactionId(string $clientTransactionId)
10
+ */
11
+ class HpsCheckServiceOverrideBuilder extends HpsBuilderAbstract
12
+ {
13
+ /** @var HpsCheck|null */
14
+ protected $check = null;
15
+
16
+ /** @var double|null */
17
+ protected $amount = null;
18
+
19
+ /** @var string|null */
20
+ protected $clientTransactionId = null;
21
+
22
+ /**
23
+ * Instatiates a new HpsCheckServiceOverrideBuilder
24
+ *
25
+ * @param HpsSoapGatewayService $service
26
+ */
27
+ public function __construct(HpsSoapGatewayService $service)
28
+ {
29
+ parent::__construct($service);
30
+ $this->setUpValidations();
31
+ }
32
+
33
+ /**
34
+ * Creates an override transaction through the HpsCheckService
35
+ */
36
+ public function execute()
37
+ {
38
+ parent::execute();
39
+
40
+ $saleSvc = new HpsCheckService($this->service->servicesConfig());
41
+ return $saleSvc->override(
42
+ $this->check,
43
+ $this->amount,
44
+ $this->clientTransactionId
45
+ );
46
+ }
47
+
48
+ /**
49
+ * Setups up validations for building sales.
50
+ *
51
+ * @return null
52
+ */
53
+ private function setUpValidations()
54
+ {
55
+ $this
56
+ ->addValidation(array($this, 'checkNotNull'), 'HpsArgumentException', 'Override needs an check')
57
+ ->addValidation(array($this, 'amountNotNull'), 'HpsArgumentException', 'Override needs an amount');
58
+ }
59
+
60
+ /**
61
+ * Ensures an amount has been set.
62
+ *
63
+ * @param array $actionCounts
64
+ *
65
+ * @return bool
66
+ */
67
+ protected function amountNotNull($actionCounts)
68
+ {
69
+ return isset($actionCounts['amount']);
70
+ }
71
+
72
+ /**
73
+ * Ensures a check has been set.
74
+ *
75
+ * @param array $actionCounts
76
+ *
77
+ * @return bool
78
+ */
79
+ protected function checkNotNull($actionCounts)
80
+ {
81
+ return isset($actionCounts['check']);
82
+ }
83
+ }
lib/SecureSubmit/src/Services/Fluent/Gateway/Check/HpsCheckServiceReturnBuilder.php ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * A fluent interface for creating and executing a return
5
+ * transaction through the HpsCheckService.
6
+ *
7
+ * @method HpsCheckServiceReturnBuilder withCheck(HpsCheck $check)
8
+ * @method HpsCheckServiceReturnBuilder withAmount(double $amount)
9
+ * @method HpsCheckServiceReturnBuilder withClientTransactionId(string $clientTransactionId)
10
+ */
11
+ class HpsCheckServiceReturnBuilder extends HpsBuilderAbstract
12
+ {
13
+ /** @var HpsCheck|null */
14
+ protected $check = null;
15
+
16
+ /** @var double|null */
17
+ protected $amount = null;
18
+
19
+ /** @var string|null */
20
+ protected $clientTransactionId = null;
21
+
22
+ /**
23
+ * Instatiates a new HpsCheckServiceReturnBuilder
24
+ *
25
+ * @param HpsSoapGatewayService $service
26
+ */
27
+ public function __construct(HpsSoapGatewayService $service)
28
+ {
29
+ parent::__construct($service);
30
+ $this->setUpValidations();
31
+ }
32
+
33
+ /**
34
+ * Creates a return transaction through the HpsCheckService
35
+ */
36
+ public function execute()
37
+ {
38
+ parent::execute();
39
+
40
+ $returnSvc = new HpsCheckService($this->service->servicesConfig());
41
+ return $returnSvc->returnCheck(
42
+ $this->check,
43
+ $this->amount,
44
+ $this->clientTransactionId
45
+ );
46
+ }
47
+
48
+ /**
49
+ * Setups up validations for building returns.
50
+ *
51
+ * @return null
52
+ */
53
+ private function setUpValidations()
54
+ {
55
+ $this
56
+ ->addValidation(array($this, 'checkNotNull'), 'HpsArgumentException', 'Return needs an check')
57
+ ->addValidation(array($this, 'amountNotNull'), 'HpsArgumentException', 'Return needs an amount');
58
+ }
59
+
60
+ /**
61
+ * Ensures an amount has been set.
62
+ *
63
+ * @param array $actionCounts
64
+ *
65
+ * @return bool
66
+ */
67
+ protected function amountNotNull($actionCounts)
68
+ {
69
+ return isset($actionCounts['amount']);
70
+ }
71
+
72
+ /**
73
+ * Ensures a check has been set.
74
+ *
75
+ * @param array $actionCounts
76
+ *
77
+ * @return bool
78
+ */
79
+ protected function checkNotNull($actionCounts)
80
+ {
81
+ return isset($actionCounts['check']);
82
+ }
83
+ }
lib/SecureSubmit/src/Services/Fluent/Gateway/Check/HpsCheckServiceSaleBuilder.php ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * A fluent interface for creating and executing a sale
5
+ * transaction through the HpsCheckService.
6
+ *
7
+ * @method HpsCheckServiceSaleBuilder withCheck(HpsCheck $check)
8
+ * @method HpsCheckServiceSaleBuilder withAmount(double $amount)
9
+ * @method HpsCheckServiceSaleBuilder withClientTransactionId(string $clientTransactionId)
10
+ */
11
+ class HpsCheckServiceSaleBuilder extends HpsBuilderAbstract
12
+ {
13
+ /** @var HpsCheck|null */
14
+ protected $check = null;
15
+
16
+ /** @var double|null */
17
+ protected $amount = null;
18
+
19
+ /** @var string|null */
20
+ protected $clientTransactionId = null;
21
+
22
+ /**
23
+ * Instatiates a new HpsCheckServiceSaleBuilder
24
+ *
25
+ * @param HpsSoapGatewayService $service
26
+ */
27
+ public function __construct(HpsSoapGatewayService $service)
28
+ {
29
+ parent::__construct($service);
30
+ $this->setUpValidations();
31
+ }
32
+
33
+ /**
34
+ * Creates a sale transaction through the HpsCheckService
35
+ */
36
+ public function execute()
37
+ {
38
+ parent::execute();
39
+
40
+ $saleSvc = new HpsCheckService($this->service->servicesConfig());
41
+ return $saleSvc->sale(
42
+ $this->check,
43
+ $this->amount,
44
+ $this->clientTransactionId
45
+ );
46
+ }
47
+
48
+ /**
49
+ * Setups up validations for building sales.
50
+ *
51
+ * @return null
52
+ */
53
+ private function setUpValidations()
54
+ {
55
+ $this
56
+ ->addValidation(array($this, 'checkNotNull'), 'HpsArgumentException', 'Sale needs a check')
57
+ ->addValidation(array($this, 'amountNotNull'), 'HpsArgumentException', 'Sale needs an amount');
58
+ }
59
+
60
+ /**
61
+ * Ensures an amount has been set.
62
+ *
63
+ * @param array $actionCounts
64
+ *
65
+ * @return bool
66
+ */
67
+ protected function amountNotNull($actionCounts)
68
+ {
69
+ return isset($actionCounts['amount']);
70
+ }
71
+
72
+ /**
73
+ * Ensures a check has been set.
74
+ *
75
+ * @param array $actionCounts
76
+ *
77
+ * @return bool
78
+ */
79
+ protected function checkNotNull($actionCounts)
80
+ {
81
+ return isset($actionCounts['check']);
82
+ }
83
+ }
lib/SecureSubmit/src/Services/Fluent/Gateway/Check/HpsCheckServiceVoidBuilder.php ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * A fluent interface for creating and executing a void
5
+ * transaction through the HpsCheckService.
6
+ *
7
+ * @method HpsCheckServiceVoidBuilder withTransactionId(string $transactionId)
8
+ * @method HpsCheckServiceVoidBuilder withClientTransactionId(string $clientTransactionId)
9
+ */
10
+ class HpsCheckServiceVoidBuilder extends HpsBuilderAbstract
11
+ {
12
+ /** @var string|null */
13
+ protected $transactionId = null;
14
+
15
+ /** @var string|null */
16
+ protected $clientTransactionId = null;
17
+
18
+ /**
19
+ * Instatiates a new HpsCheckServiceVoidBuilder
20
+ *
21
+ * @param HpsSoapGatewayService $service
22
+ */
23
+ public function __construct(HpsSoapGatewayService $service)
24
+ {
25
+ parent::__construct($service);
26
+ $this->setUpValidations();
27
+ }
28
+
29
+ /**
30
+ * Creates a void transaction through the HpsCheckService
31
+ */
32
+ public function execute()
33
+ {
34
+ parent::execute();
35
+
36
+ $voidSvc = new HpsCheckService($this->service->servicesConfig());
37
+ return $voidSvc->void(
38
+ $this->transactionId,
39
+ $this->clientTransactionId
40
+ );
41
+ }
42
+
43
+ /**
44
+ * Setups up validations for building voids.
45
+ *
46
+ * @return null
47
+ */
48
+ private function setUpValidations()
49
+ {
50
+ $this
51
+ ->addValidation(array($this, 'onlyOneTransactionId'), 'HpsArgumentException', 'Void can only use one transaction id');
52
+ }
53
+
54
+ /**
55
+ * Ensures there is only one transaction id, and checks that
56
+ * there is only one transactionId or one clientTransactionId
57
+ * in use. Both cannot be used.
58
+ *
59
+ * @param array $actionCounts
60
+ *
61
+ * @return bool
62
+ */
63
+ public function onlyOneTransactionId($actionCounts)
64
+ {
65
+ return (isset($actionCounts['transactionId']) && $actionCounts['transactionId'] == 1
66
+ && (!isset($actionCounts['clientTransactionId'])
67
+ || isset($actionCounts['clientTransactionId']) && $actionCounts['clientTransactionId'] == 0))
68
+ || (isset($actionCounts['clientTransactionId']) && $actionCounts['clientTransactionId'] == 1
69
+ && (!isset($actionCounts['transactionId'])
70
+ || isset($actionCounts['transactionId']) && $actionCounts['transactionId'] == 0));
71
+ }
72
+ }
lib/SecureSubmit/src/Services/Fluent/Gateway/Credit/HpsCreditServiceAuthorizeBuilder.php ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * A fluent interface for creating and executing an authorization
5
+ * transaction through the HpsCreditService.
6
+ *
7
+ * @method HpsCreditServiceAuthorizeBuilder withAmount(double $amount)
8
+ * @method HpsCreditServiceAuthorizeBuilder withCurrency(string $currency)
9
+ * @method HpsCreditServiceAuthorizeBuilder withCard(HpsCreditCard $card)
10
+ * @method HpsCreditServiceAuthorizeBuilder withToken(HpsTokenData $token)
11
+ * @method HpsCreditServiceAuthorizeBuilder withCardHolder(HpsCardHolder $cardHolder)
12
+ * @method HpsCreditServiceAuthorizeBuilder withRequestMultiUseToken(bool $requestMultiUseToken)
13
+ * @method HpsCreditServiceAuthorizeBuilder withDetails(HpsTransactionDetails $details)
14
+ * @method HpsCreditServiceAuthorizeBuilder withTxnDescriptor(string $txnDescriptor)
15
+ * @method HpsCreditServiceAuthorizeBuilder withAllowPartialAuth(bool $allowPartialAuth)
16
+ * @method HpsCreditServiceAuthorizeBuilder withCpcReq(bool $cpcReq)
17
+ */
18
+ class HpsCreditServiceAuthorizeBuilder extends HpsBuilderAbstract
19
+ {
20
+ /** @var double|null */
21
+ protected $amount = null;
22
+
23
+ /** @var string|null */
24
+ protected $currency = null;
25
+
26
+ /** @var HpsCreditCard|null */
27
+ protected $card = null;
28
+
29
+ /** @var HpsTokenData|null */
30
+ protected $token = null;
31
+
32
+ /** @var HpsCardHolder|null */
33
+ protected $cardHolder = null;
34
+
35
+ /** @var bool|null */
36
+ protected $requestMultiUseToken = false;
37
+
38
+ /** @var HpsTransactionDetails|null */
39
+ protected $details = null;
40
+
41
+ /** @var string|null */
42
+ protected $txnDescriptor = null;
43
+
44
+ /** @var bool|null */
45
+ protected $allowPartialAuth = false;
46
+
47
+ /** @var bool|null */
48
+ protected $cpcReq = false;
49
+
50
+ /**
51
+ * Instatiates a new HpsCreditServiceAuthorizeBuilder
52
+ *
53
+ * @param HpsSoapGatewayService $service
54
+ */
55
+ public function __construct(HpsSoapGatewayService $service)
56
+ {
57
+ parent::__construct($service);
58
+ $this->setUpValidations();
59
+ }
60
+
61
+ /**
62
+ * Creates an authorization transaction through the HpsCreditService
63
+ */
64
+ public function execute()
65
+ {
66
+ parent::execute();
67
+
68
+ $authorizationSvc = new HpsCreditService($this->service->servicesConfig());
69
+ return $authorizationSvc->authorize(
70
+ $this->amount,
71
+ $this->currency,
72
+ isset($this->card) ? $this->card : $this->token,
73
+ $this->cardHolder,
74
+ $this->requestMultiUseToken,
75
+ $this->details,
76
+ $this->txnDescriptor,
77
+ $this->allowPartialAuth,
78
+ $this->cpcReq
79
+ );
80
+ }
81
+
82
+ /**
83
+ * Setups up validations for building authorizations.
84
+ *
85
+ * @return null
86
+ */
87
+ private function setUpValidations()
88
+ {
89
+ $this
90
+ ->addValidation(array($this, 'onlyOnePaymentMethod'), 'HpsArgumentException', 'Authorize can only use one payment method')
91
+ ->addValidation(array($this, 'amountNotNull'), 'HpsArgumentException', 'Authorize needs an amount')
92
+ ->addValidation(array($this, 'currencyNotNull'), 'HpsArgumentException', 'Authorize needs a currency');
93
+ }
94
+
95
+ /**
96
+ * Ensures there is only one payment method, and checks that
97
+ * there is only one card or one token in use. Both cannot be
98
+ * used.
99
+ *
100
+ * @param array $actionCounts
101
+ *
102
+ * @return bool
103
+ */
104
+ public function onlyOnePaymentMethod($actionCounts)
105
+ {
106
+ return (isset($actionCounts['card']) && $actionCounts['card'] == 1
107
+ && (!isset($actionCounts['token'])
108
+ || isset($actionCounts['token']) && $actionCounts['token'] == 0))
109
+ || (isset($actionCounts['token']) && $actionCounts['token'] == 1
110
+ && (!isset($actionCounts['card'])
111
+ || isset($actionCounts['card']) && $actionCounts['card'] == 0));
112
+ }
113
+
114
+ /**
115
+ * Ensures an amount has been set.
116
+ *
117
+ * @param array $actionCounts
118
+ *
119
+ * @return bool
120
+ */
121
+ protected function amountNotNull($actionCounts)
122
+ {
123
+ return isset($actionCounts['amount']);
124
+ }
125
+
126
+ /**
127
+ * Ensures a currency has been set.
128
+ *
129
+ * @param array $actionCounts
130
+ *
131
+ * @return bool
132
+ */
133
+ protected function currencyNotNull($actionCounts)
134
+ {
135
+ return isset($actionCounts['currency']);
136
+ }
137
+ }
lib/SecureSubmit/src/Services/Fluent/Gateway/Credit/HpsCreditServiceCaptureBuilder.php ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * A fluent interface for creating and executing a capture
5
+ * transaction through the HpsCreditService.
6
+ *
7
+ * @method HpsCreditServiceCaptureBuilder withTransactionId(string $transactionId)
8
+ * @method HpsCreditServiceCaptureBuilder withAmount(double $amount)
9
+ * @method HpsCreditServiceCaptureBuilder withGratuity(double $gratuity)
10
+ * @method HpsCreditServiceCaptureBuilder withClientTransactionId(string $clientTransactionId)
11
+ * @method HpsCreditServiceCaptureBuilder withDirectMarketData(HpsDirectMarketData $directMarketData)
12
+ */
13
+ class HpsCreditServiceCaptureBuilder extends HpsBuilderAbstract
14
+ {
15
+ /** @var string|null */
16
+ protected $transactionId = null;
17
+
18
+ /** @var double|null */
19
+ protected $amount = null;
20
+
21
+ /** @var double|null */
22
+ protected $gratuity = null;
23
+
24
+ /** @var string|null */
25
+ protected $clientTransactionId = null;
26
+
27
+ /** @var HpsDirectMarketData|null */
28
+ protected $directMarketData = null;
29
+
30
+ /**
31
+ * Instatiates a new HpsCreditServiceCaptureBuilder
32
+ *
33
+ * @param HpsSoapGatewayService $service
34
+ */
35
+ public function __construct(HpsSoapGatewayService $service)
36
+ {
37
+ parent::__construct($service);
38
+ $this->setUpValidations();
39
+ }
40
+
41
+ /**
42
+ * Creates a capture transaction through the HpsCreditService
43
+ */
44
+ public function execute()
45
+ {
46
+ parent::execute();
47
+
48
+ $captureSvc = new HpsCreditService($this->service->servicesConfig());
49
+ return $captureSvc->capture(
50
+ $this->transactionId,
51
+ $this->amount,
52
+ $this->gratuity,
53
+ $this->clientTransactionId,
54
+ $this->directMarketData
55
+ );
56
+ }
57
+
58
+ /**
59
+ * Setups up validations for building captures.
60
+ *
61
+ * @return null
62
+ */
63
+ private function setUpValidations()
64
+ {
65
+ $this
66
+ ->addValidation(array($this, 'transactionIdNotNull'), 'HpsArgumentException', 'Capture needs a transactionId');
67
+ }
68
+
69
+ /**
70
+ * Ensures a transactionId has been set.
71
+ *
72
+ * @param array $actionCounts
73
+ *
74
+ * @return bool
75
+ */
76
+ protected function transactionIdNotNull($actionCounts)
77
+ {
78
+ return isset($actionCounts['transactionId']);
79
+ }
80
+ }
lib/SecureSubmit/src/Services/Fluent/Gateway/Credit/HpsCreditServiceChargeBuilder.php ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * A fluent interface for creating and executing a charge
5
+ * transaction through the HpsCreditService.
6
+ *
7
+ * @method HpsCreditServiceChargeBuilder withAmount(double $amount)
8
+ * @method HpsCreditServiceChargeBuilder withCurrency(string $currency)
9
+ * @method HpsCreditServiceChargeBuilder withCard(HpsCreditCard $card)
10
+ * @method HpsCreditServiceChargeBuilder withToken(HpsTokenData $token)
11
+ * @method HpsCreditServiceChargeBuilder withCardHolder(HpsCardHolder $cardHolder)
12
+ * @method HpsCreditServiceChargeBuilder withRequestMultiUseToken(bool $requestMultiUseToken)
13
+ * @method HpsCreditServiceChargeBuilder withDetails(HpsTransactionDetails $details)
14
+ * @method HpsCreditServiceChargeBuilder withTxnDescriptor(string $txnDescriptor)
15
+ * @method HpsCreditServiceChargeBuilder withAllowPartialAuth(bool $allowPartialAuth)
16
+ * @method HpsCreditServiceChargeBuilder withCpcReq(bool $cpcReq)
17
+ * @method HpsCreditServiceChargeBuilder withDirectMarketData(HpsDirectMarketData $directMarketData)
18
+ */
19
+ class HpsCreditServiceChargeBuilder extends HpsBuilderAbstract
20
+ {
21
+ /** @var double|null */
22
+ protected $amount = null;
23
+
24
+ /** @var string|null */
25
+ protected $currency = null;
26
+
27
+ /** @var HpsCreditCard|null */
28
+ protected $card = null;
29
+
30
+ /** @var HpsTokenData|null */
31
+ protected $token = null;
32
+
33
+ /** @var HpsCardHolder|null */
34
+ protected $cardHolder = null;
35
+
36
+ /** @var bool|null */
37
+ protected $requestMultiUseToken = false;
38
+
39
+ /** @var HpsTransactionDetails|null */
40
+ protected $details = null;
41
+
42
+ /** @var string|null */
43
+ protected $txnDescriptor = null;
44
+
45
+ /** @var bool|null */
46
+ protected $allowPartialAuth = false;
47
+
48
+ /** @var bool|null */
49
+ protected $cpcReq = false;
50
+
51
+ /** @var HpsDirectMarketData|null */
52
+ protected $directMarketData = null;
53
+
54
+ /**
55
+ * Instatiates a new HpsCreditServiceChargeBuilder
56
+ *
57
+ * @param HpsSoapGatewayService $service
58
+ */
59
+ public function __construct(HpsSoapGatewayService $service)
60
+ {
61
+ parent::__construct($service);
62
+ $this->setUpValidations();
63
+ }
64
+
65
+ /**
66
+ * Creates a charge transaction through the HpsCreditService
67
+ */
68
+ public function execute()
69
+ {
70
+ parent::execute();
71
+
72
+ $chargeSvc = new HpsCreditService($this->service->servicesConfig());
73
+ return $chargeSvc->charge(
74
+ $this->amount,
75
+ $this->currency,
76
+ isset($this->card) ? $this->card : $this->token,
77
+ $this->cardHolder,
78
+ $this->requestMultiUseToken,
79
+ $this->details,
80
+ $this->txnDescriptor,
81
+ $this->allowPartialAuth,
82
+ $this->cpcReq,
83
+ $this->directMarketData
84
+ );
85
+ }
86
+
87
+ /**
88
+ * Setups up validations for building charges.
89
+ *
90
+ * @return null
91
+ */
92
+ private function setUpValidations()
93
+ {
94
+ $this
95
+ ->addValidation(array($this, 'onlyOnePaymentMethod'), 'HpsArgumentException', 'Charge can only use one payment method')
96
+ ->addValidation(array($this, 'amountNotNull'), 'HpsArgumentException', 'Charge needs an amount')
97
+ ->addValidation(array($this, 'currencyNotNull'), 'HpsArgumentException', 'Charge needs an currency');
98
+ }
99
+
100
+ /**
101
+ * Ensures there is only one payment method, and checks that
102
+ * there is only one card or one token in use. Both cannot be
103
+ * used.
104
+ *
105
+ * @param array $actionCounts
106
+ *
107
+ * @return bool
108
+ */
109
+ public function onlyOnePaymentMethod($actionCounts)
110
+ {
111
+ return (isset($actionCounts['card']) && $actionCounts['card'] == 1
112
+ && (!isset($actionCounts['token'])
113
+ || isset($actionCounts['token']) && $actionCounts['token'] == 0))
114
+ || (isset($actionCounts['token']) && $actionCounts['token'] == 1
115
+ && (!isset($actionCounts['card'])
116
+ || isset($actionCounts['card']) && $actionCounts['card'] == 0));
117
+ }
118
+
119
+ /**
120
+ * Ensures an amount has been set.
121
+ *
122
+ * @param array $actionCounts
123
+ *
124
+ * @return bool
125
+ */
126
+ protected function amountNotNull($actionCounts)
127
+ {
128
+ return isset($actionCounts['amount']);
129
+ }
130
+
131
+ /**
132
+ * Ensures a currency has been set.
133
+ *
134
+ * @param array $actionCounts
135
+ *
136
+ * @return bool
137
+ */
138
+ protected function currencyNotNull($actionCounts)
139
+ {
140
+ return isset($actionCounts['currency']);
141
+ }
142
+ }
lib/SecureSubmit/src/Services/Fluent/Gateway/Credit/HpsCreditServiceCpcEditBuilder.php ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * A fluent interface for creating and executing a cpcEdit
5
+ * transaction through the HpsCreditService.
6
+ *
7
+ * @method HpsCreditServiceCpcEditBuilder withTransactionId(string $transactionId)
8
+ * @method HpsCreditServiceCpcEditBuilder withDirectMarketData(HpsCPCData $cpcData)
9
+ */
10
+ class HpsCreditServiceCpcEditBuilder extends HpsBuilderAbstract
11
+ {
12
+ /** @var string|null */
13
+ protected $transactionId = null;
14
+
15
+ /** @var HpsCPCData|null */
16
+ protected $cpcData = null;
17
+
18
+ /**
19
+ * Instatiates a new HpsCreditServiceCpcEditBuilder
20
+ *
21
+ * @param HpsSoapGatewayService $service
22
+ */
23
+ public function __construct(HpsSoapGatewayService $service)
24
+ {
25
+ parent::__construct($service);
26
+ $this->setUpValidations();
27
+ }
28
+
29
+ /**
30
+ * Creates a cpcEdit transaction through the HpsCreditService
31
+ */
32
+ public function execute()
33
+ {
34
+ parent::execute();
35
+
36
+ $cpcEditSvc = new HpsCreditService($this->service->servicesConfig());
37
+ return $cpcEditSvc->cpcEdit(
38
+ $this->transactionId,
39
+ $this->cpcData
40
+ );
41
+ }
42
+
43
+ /**
44
+ * Setups up validations for building cpcEdits.
45
+ *
46
+ * @return null
47
+ */
48
+ private function setUpValidations()
49
+ {
50
+ $this
51
+ ->addValidation(array($this, 'transactionIdNotNull'), 'HpsArgumentException', 'CpcEdit needs a transactionId')
52
+ ->addValidation(array($this, 'cpcDataNotNull'), 'HpsArgumentException', 'CpcEdit needs cpcData');
53
+ }
54
+
55
+ /**
56
+ * Ensures a transactionId has been set.
57
+ *
58
+ * @param array $actionCounts
59
+ *
60
+ * @return bool
61
+ */
62
+ protected function transactionIdNotNull($actionCounts)
63
+ {
64
+ return isset($actionCounts['transactionId']);
65
+ }
66
+
67
+ /**
68
+ * Ensures cpcData has been set.
69
+ *
70
+ * @param array $actionCounts
71
+ *
72
+ * @return bool
73
+ */
74
+ protected function cpcDataNotNull($actionCounts)
75
+ {
76
+ return isset($actionCounts['cpcData']);
77
+ }
78
+ }
lib/SecureSubmit/src/Services/Fluent/Gateway/Credit/HpsCreditServiceEditBuilder.php ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * A fluent interface for creating and executing an edit
5
+ * transaction through the HpsCreditService.
6
+ *
7
+ * @method HpsCreditServiceEditBuilder withTransactionId(string $transactionId)
8
+ * @method HpsCreditServiceEditBuilder withAmount(double $amount)
9
+ * @method HpsCreditServiceEditBuilder withGratuity(double $gratuity)
10
+ * @method HpsCreditServiceEditBuilder withClientTransactionId(string $clientTransactionId)
11
+ */
12
+ class HpsCreditServiceEditBuilder extends HpsBuilderAbstract
13
+ {
14
+ /** @var string|null */
15
+ protected $transactionId = null;
16
+
17
+ /** @var double|null */
18
+ protected $amount = null;
19
+
20
+ /** @var double|null */
21
+ protected $gratuity = null;
22
+
23
+ /** @var string|null */
24
+ protected $clientTransactionId = null;
25
+
26
+ /**
27
+ * Instatiates a new HpsCreditServiceEditBuilder
28
+ *
29
+ * @param HpsSoapGatewayService $service
30
+ */
31
+ public function __construct(HpsSoapGatewayService $service)
32
+ {
33
+ parent::__construct($service);
34
+ $this->setUpValidations();
35
+ }
36
+
37
+ /**
38
+ * Creates an edit transaction through the HpsCreditService
39
+ */
40
+ public function execute()
41
+ {
42
+ parent::execute();
43
+
44
+ $editSvc = new HpsCreditService($this->service->servicesConfig());
45
+ return $editSvc->edit(
46
+ $this->transactionId,
47
+ $this->amount,
48
+ $this->gratuity,
49
+ $this->clientTransactionId
50
+ );
51
+ }
52
+
53
+ /**
54
+ * Setups up validations for building edits.
55
+ *
56
+ * @return null
57
+ */
58
+ private function setUpValidations()
59
+ {
60
+ $this
61
+ ->addValidation(array($this, 'transactionIdNotNull'), 'HpsArgumentException', 'Edit needs a transactionId');
62
+ }
63
+
64
+ /**
65
+ * Ensures a transactionId has been set.
66
+ *
67
+ * @param array $actionCounts
68
+ *
69
+ * @return bool
70
+ */
71
+ protected function transactionIdNotNull($actionCounts)
72
+ {
73
+ return isset($actionCounts['transactionId']);
74
+ }
75
+ }
lib/SecureSubmit/src/Services/Fluent/Gateway/Credit/HpsCreditServiceGetBuilder.php ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * A fluent interface for creating and executing a get
5
+ * transaction through the HpsCreditService.
6
+ *
7
+ * @method HpsCreditServiceGetBuilder withTransactionId(string $transactionId)
8
+ */
9
+ class HpsCreditServiceGetBuilder extends HpsBuilderAbstract
10
+ {
11
+ /** @var string|null */
12
+ protected $transactionId = null;
13
+
14
+ /**
15
+ * Instatiates a new HpsCreditServiceGetBuilder
16
+ *
17
+ * @param HpsSoapGatewayService $service
18
+ */
19
+ public function __construct(HpsSoapGatewayService $service)
20
+ {
21
+ parent::__construct($service);
22
+ $this->setUpValidations();
23
+ }
24
+
25
+ /**
26
+ * Creates a get transaction through the HpsCreditService
27
+ */
28
+ public function execute()
29
+ {
30
+ parent::execute();
31
+
32
+ $getSvc = new HpsCreditService($this->service->servicesConfig());
33
+ return $getSvc->get($this->transactionId);
34
+ }
35
+
36
+ /**
37
+ * Setups up validations for building edits.
38
+ *
39
+ * @return null
40
+ */
41
+ private function setUpValidations()
42
+ {
43
+ $this
44
+ ->addValidation(array($this, 'transactionIdNotNull'), 'HpsArgumentException', 'Get needs a transactionId');
45
+ }
46
+
47
+ /**
48
+ * Ensures a transactionId has been set.
49
+ *
50
+ * @param array $actionCounts
51
+ *
52
+ * @return bool
53
+ */
54
+ protected function transactionIdNotNull($actionCounts)
55
+ {
56
+ return isset($actionCounts['transactionId']);
57
+ }
58
+ }
lib/SecureSubmit/src/Services/Fluent/Gateway/Credit/HpsCreditServiceListTransactionsBuilder.php ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * A fluent interface for creating and executing a listTransactions
5
+ * transaction through the HpsCreditService.
6
+ *
7
+ * @method HpsCreditServiceListTransactionsBuilder withStartDate(string $startDate)
8
+ * @method HpsCreditServiceListTransactionsBuilder withEndDate(string $endDate)
9
+ * @method HpsCreditServiceListTransactionsBuilder withFilterBy(integer|string $filterBy)
10
+ * @method HpsCreditServiceListTransactionsBuilder withClientTransactionId(string $clientTransactionId)
11
+ */
12
+ class HpsCreditServiceListTransactionsBuilder extends HpsBuilderAbstract
13
+ {
14
+ /** @var string|null */
15
+ protected $startDate = null;
16
+
17
+ /** @var string|null */
18
+ protected $endDate = null;
19
+
20
+ /** @var integer|string|null */
21
+ protected $filterBy = null;
22
+
23
+ /**
24
+ * Instatiates a new HpsCreditServiceListTransactionsBuilder
25
+ *
26
+ * @param HpsSoapGatewayService $service
27
+ */
28
+ public function __construct(HpsSoapGatewayService $service)
29
+ {
30
+ parent::__construct($service);
31
+ $this->setUpValidations();
32
+ }
33
+
34
+ /**
35
+ * Creates a listTransactions transaction through the HpsCreditService
36
+ */
37
+ public function execute()
38
+ {
39
+ parent::execute();
40
+
41
+ $listTransactionsSvc = new HpsCreditService($this->service->servicesConfig());
42
+ return $listTransactionsSvc->listTransactions(
43
+ $this->startDate,
44
+ $this->endDate,
45
+ $this->filterBy
46
+ );
47
+ }
48
+
49
+ /**
50
+ * Setups up validations for building edits.
51
+ *
52
+ * @return null
53
+ */
54
+ private function setUpValidations()
55
+ {
56
+ $this
57
+ ->addValidation(array($this, 'startDateNotNull'), 'HpsArgumentException', 'ListTransactions needs a startDate')
58
+ ->addValidation(array($this, 'endDateNotNull'), 'HpsArgumentException', 'ListTransactions needs an endDate');
59
+ }
60
+
61
+ /**
62
+ * Ensures a startDate has been set.
63
+ *
64
+ * @param array $actionCounts
65
+ *
66
+ * @return bool
67
+ */
68
+ protected function startDateNotNull($actionCounts)
69
+ {
70
+ return isset($actionCounts['startDate']);
71
+ }
72
+
73
+ /**
74
+ * Ensures an endDate has been set.
75
+ *
76
+ * @param array $actionCounts
77
+ *
78
+ * @return bool
79
+ */
80
+ protected function endDateNotNull($actionCounts)
81
+ {
82
+ return isset($actionCounts['endDate']);
83
+ }
84
+ }
lib/SecureSubmit/src/Services/Fluent/Gateway/Credit/HpsCreditServiceRefundBuilder.php ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * A fluent interface for creating and executing a refund
5
+ * transaction through the HpsCreditService.
6
+ *
7
+ * @method HpsCreditServiceRefundBuilder withAmount(double $amount)
8
+ * @method HpsCreditServiceRefundBuilder withCurrency(string $currency)
9
+ * @method HpsCreditServiceRefundBuilder withCard(HpsCreditCard $card)
10
+ * @method HpsCreditServiceRefundBuilder withToken(HpsTokenData $token)
11
+ * @method HpsCreditServiceRefundBuilder withTransactionId(HpsTokenData $transactionId)
12
+ * @method HpsCreditServiceRefundBuilder withCardHolder(HpsCardHolder $cardHolder)
13
+ * @method HpsCreditServiceRefundBuilder withDetails(HpsTransactionDetails $details)
14
+ */
15
+ class HpsCreditServiceRefundBuilder extends HpsBuilderAbstract
16
+ {
17
+ /** @var double|null */
18
+ protected $amount = null;
19
+
20
+ /** @var string|null */
21
+ protected $currency = null;
22
+
23
+ /** @var HpsCreditCard|null */
24
+ protected $card = null;
25
+
26
+ /** @var HpsTokenData|null */
27
+ protected $token = null;
28
+
29
+ /** @var string|null */
30
+ protected $transactionId = null;
31
+
32
+ /** @var HpsCardHolder|null */
33
+ protected $cardHolder = null;
34
+
35
+ /** @var HpsTransactionDetails|null */
36
+ protected $details = null;
37
+
38
+ /**
39
+ * Instatiates a new HpsCreditServiceRefundBuilder
40
+ *
41
+ * @param HpsSoapGatewayService $service
42
+ */
43
+ public function __construct(HpsSoapGatewayService $service)
44
+ {
45
+ parent::__construct($service);
46
+ $this->setUpValidations();
47
+ }
48
+
49
+ /**
50
+ * Creates a refund transaction through the HpsCreditService
51
+ */
52
+ public function execute()
53
+ {
54
+ parent::execute();
55
+
56
+ $refundSvc = new HpsCreditService($this->service->servicesConfig());
57
+ return $refundSvc->refund(
58
+ $this->amount,
59
+ $this->currency,
60
+ isset($this->card) ? $this->card : (isset($this->token) ? $this->token : $this->transactionId),
61
+ $this->cardHolder,
62
+ $this->details
63
+ );
64
+ }
65
+
66
+ /**
67
+ * Setups up validations for building refunds.
68
+ *
69
+ * @return null
70
+ */
71
+ private function setUpValidations()
72
+ {
73
+ $this
74
+ ->addValidation(array($this, 'onlyOnePaymentMethod'), 'HpsArgumentException', 'Refund can only use one payment method')
75
+ ->addValidation(array($this, 'amountNotNull'), 'HpsArgumentException', 'Refund needs an amount')
76
+ ->addValidation(array($this, 'currencyNotNull'), 'HpsArgumentException', 'Refund needs an currency');
77
+ }
78
+
79
+ /**
80
+ * Ensures there is only one payment method, and checks that
81
+ * there is only one card, one token, or one transactionId
82
+ * in use.
83
+ *
84
+ * @param array $actionCounts
85
+ *
86
+ * @return bool
87
+ */
88
+ public function onlyOnePaymentMethod($actionCounts)
89
+ {
90
+ return (isset($actionCounts['card']) && $actionCounts['card'] == 1
91
+ && (!isset($actionCounts['token'])
92
+ || isset($actionCounts['token']) && $actionCounts['token'] == 0)
93
+ && (!isset($actionCounts['transactionId'])
94
+ || isset($actionCounts['transactionId']) == 0))
95
+ || (isset($actionCounts['token']) && $actionCounts['token'] == 1
96
+ && (!isset($actionCounts['card'])
97
+ || isset($actionCounts['card']) && $actionCounts['card'] == 0)
98
+ && (!isset($actionCounts['transactionId'])
99
+ || isset($actionCounts['transactionId']) == 0))
100
+ || (isset($actionCounts['transactionId']) && $actionCounts['transactionId'] == 1
101
+ && (!isset($actionCounts['card'])
102
+ || isset($actionCounts['card']) && $actionCounts['card'] == 0)
103
+ && (!isset($actionCounts['token'])
104
+ || isset($actionCounts['token']) == 0));
105
+ }
106
+
107
+ /**
108
+ * Ensures an amount has been set.
109
+ *
110
+ * @param array $actionCounts
111
+ *
112
+ * @return bool
113
+ */
114
+ protected function amountNotNull($actionCounts)
115
+ {
116
+ return isset($actionCounts['amount']);
117
+ }
118
+
119
+ /**
120
+ * Ensures a currency has been set.
121
+ *
122
+ * @param array $actionCounts
123
+ *
124
+ * @return bool
125
+ */
126
+ protected function currencyNotNull($actionCounts)
127
+ {
128
+ return isset($actionCounts['currency']);
129
+ }
130
+ }
lib/SecureSubmit/src/Services/Fluent/Gateway/Credit/HpsCreditServiceReverseBuilder.php ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * A fluent interface for creating and executing a reverse
5
+ * transaction through the HpsCreditService.
6
+ *
7
+ * @method HpsCreditServiceReverseBuilder withAmount(double $amount)
8
+ * @method HpsCreditServiceReverseBuilder withCurrency(string $currency)
9
+ * @method HpsCreditServiceReverseBuilder withCard(HpsCreditCard $card)
10
+ * @method HpsCreditServiceReverseBuilder withToken(HpsTokenData $token)
11
+ * @method HpsCreditServiceReverseBuilder withTransactionId(string $transactionId)
12
+ * @method HpsCreditServiceReverseBuilder withDetails(HpsTransactionDetails $details)
13
+ */
14
+ class HpsCreditServiceReverseBuilder extends HpsBuilderAbstract
15
+ {
16
+ /** @var double|null */
17
+ protected $amount = null;
18
+
19
+ /** @var string|null */
20
+ protected $currency = null;
21
+
22
+ /** @var HpsCreditCard|null */
23
+ protected $card = null;
24
+
25
+ /** @var HpsTokenData|null */
26
+ protected $token = null;
27
+
28
+ /** @var string|null */
29
+ protected $transactionId = null;
30
+
31
+ /** @var HpsTransactionDetails|null */
32
+ protected $details = null;
33
+
34
+ /**
35
+ * Instatiates a new HpsCreditServiceReverseBuilder
36
+ *
37
+ * @param HpsSoapGatewayService $service
38
+ */
39
+ public function __construct(HpsSoapGatewayService $service)
40
+ {
41
+ parent::__construct($service);
42
+ $this->setUpValidations();
43
+ }
44
+
45
+ /**
46
+ * Creates a reverse transaction through the HpsCreditService
47
+ */
48
+ public function execute()
49
+ {
50
+ parent::execute();
51
+
52
+ $reverseSvc = new HpsCreditService($this->service->servicesConfig());
53
+ return $reverseSvc->reverse(
54
+ isset($this->card) ? $this->card : (isset($this->token) ? $this->token : $this->transactionId),
55
+ $this->amount,
56
+ $this->currency,
57
+ $this->details
58
+ );
59
+ }
60
+
61
+ /**
62
+ * Setups up validations for building reverses.
63
+ *
64
+ * @return null
65
+ */
66
+ private function setUpValidations()
67
+ {
68
+ $this
69
+ ->addValidation(array($this, 'onlyOnePaymentMethod'), 'HpsArgumentException', 'Reverse can only use one payment method')
70
+ ->addValidation(array($this, 'amountNotNull'), 'HpsArgumentException', 'Reverse needs an amount')
71
+ ->addValidation(array($this, 'currencyNotNull'), 'HpsArgumentException', 'Reverse needs an currency');
72
+ }
73
+
74
+ /**
75
+ * Ensures there is only one payment method, and checks that
76
+ * there is only one card, one token, or one transactionId
77
+ * in use.
78
+ *
79
+ * @param array $actionCounts
80
+ *
81
+ * @return bool
82
+ */
83
+ public function onlyOnePaymentMethod($actionCounts)
84
+ {
85
+ return (isset($actionCounts['card']) && $actionCounts['card'] == 1
86
+ && (!isset($actionCounts['token'])
87
+ || isset($actionCounts['token']) && $actionCounts['token'] == 0)
88
+ && (!isset($actionCounts['transactionId'])
89
+ || isset($actionCounts['transactionId']) == 0))
90
+ || (isset($actionCounts['token']) && $actionCounts['token'] == 1
91
+ && (!isset($actionCounts['card'])
92
+ || isset($actionCounts['card']) && $actionCounts['card'] == 0)
93
+ && (!isset($actionCounts['transactionId'])
94
+ || isset($actionCounts['transactionId']) == 0))
95
+ || (isset($actionCounts['transactionId']) && $actionCounts['transactionId'] == 1
96
+ && (!isset($actionCounts['card'])
97
+ || isset($actionCounts['card']) && $actionCounts['card'] == 0)
98
+ && (!isset($actionCounts['token'])
99
+ || isset($actionCounts['token']) == 0));
100
+ }
101
+
102
+ /**
103
+ * Ensures an amount has been set.
104
+ *
105
+ * @param array $actionCounts
106
+ *
107
+ * @return bool
108
+ */
109
+ protected function amountNotNull($actionCounts)
110
+ {
111
+ return isset($actionCounts['amount']);
112
+ }
113
+
114
+ /**
115
+ * Ensures a currency has been set.
116
+ *
117
+ * @param array $actionCounts
118
+ *
119
+ * @return bool
120
+ */
121
+ protected function currencyNotNull($actionCounts)
122
+ {
123
+ return isset($actionCounts['currency']);
124
+ }
125
+ }
lib/SecureSubmit/src/Services/Fluent/Gateway/Credit/HpsCreditServiceVerifyBuilder.php ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * A fluent interface for creating and executing a verify
5
+ * transaction through the HpsCreditService.
6
+ *
7
+ * @method HpsCreditServiceVerifyBuilder withCard(HpsCreditCard $card)
8
+ * @method HpsCreditServiceVerifyBuilder withToken(HpsTokenData $token)
9
+ * @method HpsCreditServiceVerifyBuilder withCardHolder(HpsCardHolder $cardHolder)
10
+ * @method HpsCreditServiceVerifyBuilder withRequestMultiUseToken(bool $requestMultiUseToken)
11
+ * @method HpsCreditServiceVerifyBuilder withClientTransactionId(string $clientTransactionId)
12
+ */
13
+ class HpsCreditServiceVerifyBuilder extends HpsBuilderAbstract
14
+ {
15
+ /** @var HpsCreditCard|null */
16
+ protected $card = null;
17
+
18
+ /** @var HpsTokenData|null */
19
+ protected $token = null;
20
+
21
+ /** @var HpsCardHolder|null */
22
+ protected $cardHolder = null;
23
+
24
+ /** @var bool|null */
25
+ protected $requestMultiUseToken = false;
26
+
27
+ /** @var string|null */
28
+ protected $clientTransactionId = null;
29
+
30
+ /**
31
+ * Instatiates a new HpsCreditServiceVerifyBuilder
32
+ *
33
+ * @param HpsSoapGatewayService $service
34
+ */
35
+ public function __construct(HpsSoapGatewayService $service)
36
+ {
37
+ parent::__construct($service);
38
+ $this->setUpValidations();
39
+ }
40
+
41
+ /**
42
+ * Creates a verify transaction through the HpsCreditService
43
+ */
44
+ public function execute()
45
+ {
46
+ parent::execute();
47
+
48
+ $verifySvc = new HpsCreditService($this->service->servicesConfig());
49
+ return $verifySvc->verify(
50
+ isset($this->card) ? $this->card : $this->token,
51
+ $this->cardHolder,
52
+ $this->requestMultiUseToken,
53
+ $this->clientTransactionId
54
+ );
55
+ }
56
+
57
+ /**
58
+ * Setups up validations for building verifys.
59
+ *
60
+ * @return null
61
+ */
62
+ private function setUpValidations()
63
+ {
64
+ $this
65
+ ->addValidation(array($this, 'onlyOnePaymentMethod'), 'HpsArgumentException', 'Verify can only use one payment method');
66
+ }
67
+
68
+ /**
69
+ * Ensures there is only one payment method, and checks that
70
+ * there is only one card or one token in use. Both cannot be
71
+ * used.
72
+ *
73
+ * @param array $actionCounts
74
+ *
75
+ * @return bool
76
+ */
77
+ public function onlyOnePaymentMethod($actionCounts)
78
+ {
79
+ return (isset($actionCounts['card']) && $actionCounts['card'] == 1
80
+ && (!isset($actionCounts['token'])
81
+ || isset($actionCounts['token']) && $actionCounts['token'] == 0))
82
+ || (isset($actionCounts['token']) && $actionCounts['token'] == 1
83
+ && (!isset($actionCounts['card'])
84
+ || isset($actionCounts['card']) && $actionCounts['card'] == 0));
85
+ }
86
+ }
lib/SecureSubmit/src/Services/Fluent/Gateway/Credit/HpsCreditServiceVoidBuilder.php ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * A fluent interface for creating and executing a void
5
+ * transaction through the HpsCreditService.
6
+ *
7
+ * @method HpsCreditServiceVoidBuilder withTransactionId(string $transactionId)
8
+ * @method HpsCreditServiceVoidBuilder withClientTransactionId(string $clientTransactionId)
9
+ */
10
+ class HpsCreditServiceVoidBuilder extends HpsBuilderAbstract
11
+ {
12
+ /** @var string|null */
13
+ protected $transactionId = null;
14
+
15
+ /** @var string|null */
16
+ protected $clientTransactionId = null;
17
+
18
+ /**
19
+ * Instatiates a new HpsCreditServiceVoidBuilder
20
+ *
21
+ * @param HpsSoapGatewayService $service
22
+ */
23
+ public function __construct(HpsSoapGatewayService $service)
24
+ {
25
+ parent::__construct($service);
26
+ $this->setUpValidations();
27
+ }
28
+
29
+ /**
30
+ * Creates a void transaction through the HpsCreditService
31
+ */
32
+ public function execute()
33
+ {
34
+ parent::execute();
35
+
36
+ $voidSvc = new HpsCreditService($this->service->servicesConfig());
37
+ return $voidSvc->void($this->transactionId);
38
+ }
39
+
40
+ /**
41
+ * Setups up validations for building edits.
42
+ *
43
+ * @return null
44
+ */
45
+ private function setUpValidations()
46
+ {
47
+ $this
48
+ ->addValidation(array($this, 'transactionIdNotNull'), 'HpsArgumentException', 'Void needs a transactionId');
49
+ }
50
+
51
+ /**
52
+ * Ensures a transactionId has been set.
53
+ *
54
+ * @param array $actionCounts
55
+ *
56
+ * @return bool
57
+ */
58
+ protected function transactionIdNotNull($actionCounts)
59
+ {
60
+ return isset($actionCounts['transactionId']);
61
+ }
62
+ }
lib/SecureSubmit/src/Services/Fluent/Gateway/Debit/HpsDebitServiceAddValueBuilder.php ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * A fluent interface for creating and executing a addValue
5
+ * transaction through the HpsDebitService.
6
+ *
7
+ * @method HpsDebitServiceAddValueBuilder withAmount(double $amount)
8
+ * @method HpsDebitServiceAddValueBuilder withCurrency(string $currency)
9
+ * @method HpsDebitServiceAddValueBuilder withTrackData(string $trackData)
10
+ * @method HpsDebitServiceAddValueBuilder withPinBlock(string $pinBlock)
11
+ * @method HpsDebitServiceAddValueBuilder withEncryptionData(HpsEncryptionData $encryptionData)
12
+ * @method HpsDebitServiceAddValueBuilder withAllowDuplicates(bool $allowDuplicates)
13
+ * @method HpsDebitServiceAddValueBuilder withCardHolder(HpsCardHolder $cardHolder)
14
+ * @method HpsDebitServiceAddValueBuilder withDetails(HpsTransactionDetails $details)
15
+ * @method HpsDebitServiceAddValueBuilder withClientTransactionId(string $clientTransactionId)
16
+ */
17
+ class HpsDebitServiceAddValueBuilder extends HpsBuilderAbstract
18
+ {
19
+ /** @var double|null */
20
+ protected $amount = null;
21
+
22
+ /** @var string|null */
23
+ protected $currency = null;
24
+
25
+ /** @var string|null */
26
+ protected $trackData = null;
27
+
28
+ /** @var string|null */
29
+ protected $pinBlock = null;
30
+
31
+ /** @var HpsEncryptionData|null */
32
+ protected $encryptionData = null;
33
+
34
+ /** @var bool|null */
35
+ protected $allowDuplicates = false;
36
+
37
+ /** @var HpsCardHolder|null */
38
+ protected $cardHolder = null;
39
+
40
+ /** @var HpsTransactionDetails|null */
41
+ protected $details = null;
42
+
43
+ /** @var string|null */
44
+ protected $clientTransactionId = null;
45
+
46
+ /**
47
+ * Instatiates a new HpsDebitServiceAddValueBuilder
48
+ *
49
+ * @param HpsSoapGatewayService $service
50
+ */
51
+ public function __construct(HpsSoapGatewayService $service)
52
+ {
53
+ parent::__construct($service);
54
+ $this->setUpValidations();
55
+ }
56
+
57
+ /**
58
+ * Creates a addValue transaction through the HpsDebitService
59
+ */
60
+ public function execute()
61
+ {
62
+ parent::execute();
63
+
64
+ $addValueSvc = new HpsDebitService($this->service->servicesConfig());
65
+ return $addValueSvc->addValue(
66
+ $this->amount,
67
+ $this->currency,
68
+ $this->trackData,
69
+ $this->pinBlock,
70
+ $this->encryptionData,
71
+ $this->allowDuplicates,
72
+ $this->cardHolder,
73
+ $this->details,
74
+ $this->clientTransactionId
75
+ );
76
+ }
77
+
78
+ /**
79
+ * Setups up validations for building addValues.
80
+ *
81
+ * @return null
82
+ */
83
+ private function setUpValidations()
84
+ {
85
+ $this
86
+ ->addValidation(array($this, 'amountNotNull'), 'HpsArgumentException', 'AddValue needs an amount')
87
+ ->addValidation(array($this, 'currencyNotNull'), 'HpsArgumentException', 'AddValue needs an currency')
88
+ ->addValidation(array($this, 'trackDataNotNull'), 'HpsArgumentException', 'AddValue needs an trackData')
89
+ ->addValidation(array($this, 'pinBlockNotNull'), 'HpsArgumentException', 'AddValue needs an pinBlock');
90
+ }
91
+
92
+ /**
93
+ * Ensures an amount has been set.
94
+ *
95
+ * @param array $actionCounts
96
+ *
97
+ * @return bool
98
+ */
99
+ protected function amountNotNull($actionCounts)
100
+ {
101
+ return isset($actionCounts['amount']);
102
+ }
103
+
104
+ /**
105
+ * Ensures a currency has been set.
106
+ *
107
+ * @param array $actionCounts
108
+ *
109
+ * @return bool
110
+ */
111
+ protected function currencyNotNull($actionCounts)
112
+ {
113
+ return isset($actionCounts['currency']);
114
+ }
115
+
116
+ /**
117
+ * Ensures a trackData has been set.
118
+ *
119
+ * @param array $actionCounts
120
+ *
121
+ * @return bool
122
+ */
123
+ protected function trackDataNotNull($actionCounts)
124
+ {
125
+ return isset($actionCounts['trackData']);
126
+ }
127
+
128
+ /**
129
+ * Ensures a pinBlock has been set.
130
+ *
131
+ * @param array $actionCounts
132
+ *
133
+ * @return bool
134
+ */
135
+ protected function pinBlockNotNull($actionCounts)
136
+ {
137
+ return isset($actionCounts['pinBlock']);
138
+ }
139
+ }
lib/SecureSubmit/src/Services/Fluent/Gateway/Debit/HpsDebitServiceChargeBuilder.php ADDED
@@ -0,0 +1,149 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * A fluent interface for creating and executing a charge
5
+ * transaction through the HpsDebitService.
6
+ *
7
+ * @method HpsDebitServiceChargeBuilder withAmount(double $amount)
8
+ * @method HpsDebitServiceChargeBuilder withCurrency(string $currency)
9
+ * @method HpsDebitServiceChargeBuilder withTrackData(string $trackData)
10
+ * @method HpsDebitServiceChargeBuilder withPinBlock(string $pinBlock)
11
+ * @method HpsDebitServiceChargeBuilder withEncryptionData(HpsEncryptionData $encryptionData)
12
+ * @method HpsDebitServiceChargeBuilder withAllowDuplicates(bool $allowDuplicates)
13
+ * @method HpsDebitServiceChargeBuilder withCashBackAmount(double $caseBackAmount)
14
+ * @method HpsDebitServiceChargeBuilder withAllowPartialAuth(bool $allowPartialAuth)
15
+ * @method HpsDebitServiceChargeBuilder withCardHolder(HpsCardHolder $cardHolder)
16
+ * @method HpsDebitServiceChargeBuilder withDetails(HpsTransactionDetails $details)
17
+ * @method HpsDebitServiceChargeBuilder withClientTransactionId(string $clientTransactionId)
18
+ */
19
+ class HpsDebitServiceChargeBuilder extends HpsBuilderAbstract
20
+ {
21
+ /** @var double|null */
22
+ protected $amount = null;
23
+
24
+ /** @var string|null */
25
+ protected $currency = null;
26
+
27
+ /** @var string|null */
28
+ protected $trackData = null;
29
+
30
+ /** @var string|null */
31
+ protected $pinBlock = null;
32
+
33
+ /** @var HpsEncryptionData|null */
34
+ protected $encryptionData = null;
35
+
36
+ /** @var bool|null */
37
+ protected $allowDuplicates = false;
38
+
39
+ /** @var double|null */
40
+ protected $cashBackAmount = null;
41
+
42
+ /** @var bool|null */
43
+ protected $allowPartialAuth = false;
44
+
45
+ /** @var HpsCardHolder|null */
46
+ protected $cardHolder = null;
47
+
48
+ /** @var HpsTransactionDetails|null */
49
+ protected $details = null;
50
+
51
+ /** @var string|null */
52
+ protected $clientTransactionId = null;
53
+
54
+ /**
55
+ * Instatiates a new HpsDebitServiceChargeBuilder
56
+ *
57
+ * @param HpsSoapGatewayService $service
58
+ */
59
+ public function __construct(HpsSoapGatewayService $service)
60
+ {
61
+ parent::__construct($service);
62
+ $this->setUpValidations();
63
+ }
64
+
65
+ /**
66
+ * Creates a charge transaction through the HpsDebitService
67
+ */
68
+ public function execute()
69
+ {
70
+ parent::execute();
71
+
72
+ $chargeSvc = new HpsDebitService($this->service->servicesConfig());
73
+ return $chargeSvc->charge(
74
+ $this->amount,
75
+ $this->currency,
76
+ $this->trackData,
77
+ $this->pinBlock,
78
+ $this->encryptionData,
79
+ $this->allowDuplicates,
80
+ $this->cashBackAmount,
81
+ $this->allowPartialAuth,
82
+ $this->cardHolder,
83
+ $this->details,
84
+ $this->clientTransactionId
85
+ );
86
+ }
87
+
88
+ /**
89
+ * Setups up validations for building charges.
90
+ *
91
+ * @return null
92
+ */
93
+ private function setUpValidations()
94
+ {
95
+ $this
96
+ ->addValidation(array($this, 'amountNotNull'), 'HpsArgumentException', 'Charge needs an amount')
97
+ ->addValidation(array($this, 'currencyNotNull'), 'HpsArgumentException', 'Charge needs an currency')
98
+ ->addValidation(array($this, 'trackDataNotNull'), 'HpsArgumentException', 'Charge needs an trackData')
99
+ ->addValidation(array($this, 'pinBlockNotNull'), 'HpsArgumentException', 'Charge needs an pinBlock');
100
+ }
101
+
102
+ /**
103
+ * Ensures an amount has been set.
104
+ *
105
+ * @param array $actionCounts
106
+ *
107
+ * @return bool
108
+ */
109
+ protected function amountNotNull($actionCounts)
110
+ {
111
+ return isset($actionCounts['amount']);
112
+ }
113
+
114
+ /**
115
+ * Ensures a currency has been set.
116
+ *
117
+ * @param array $actionCounts
118
+ *
119
+ * @return bool
120
+ */
121
+ protected function currencyNotNull($actionCounts)
122
+ {
123
+ return isset($actionCounts['currency']);
124
+ }
125
+
126
+ /**
127
+ * Ensures a trackData has been set.
128
+ *
129
+ * @param array $actionCounts
130
+ *
131
+ * @return bool
132
+ */
133
+ protected function trackDataNotNull($actionCounts)
134
+ {
135
+ return isset($actionCounts['trackData']);
136
+ }
137
+
138
+ /**
139
+ * Ensures a pinBlock has been set.
140
+ *
141
+ * @param array $actionCounts
142
+ *
143
+ * @return bool
144
+ */
145
+ protected function pinBlockNotNull($actionCounts)
146
+ {
147
+ return isset($actionCounts['pinBlock']);
148
+ }
149
+ }
lib/SecureSubmit/src/Services/Fluent/Gateway/Debit/HpsDebitServiceReturnBuilder.php ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * A fluent interface for creating and executing a return
5
+ * transaction through the HpsDebitService.
6
+ *
7
+ * @method HpsDebitServiceReturnBuilder withTransactionId(string $transactionId)
8
+ * @method HpsDebitServiceReturnBuilder withAmount(double $amount)
9
+ * @method HpsDebitServiceReturnBuilder withTrackData(string $trackData)
10
+ * @method HpsDebitServiceReturnBuilder withPinBlock(string $pinBlock)
11
+ * @method HpsDebitServiceReturnBuilder withEncryptionData(HpsEncryptionData $encryptionData)
12
+ * @method HpsDebitServiceReturnBuilder withAllowDuplicates(bool $allowDuplicates)
13
+ * @method HpsDebitServiceReturnBuilder withCardHolder(HpsCardHolder $cardHolder)
14
+ * @method HpsDebitServiceReturnBuilder withDetails(HpsTransactionDetails $details)
15
+ * @method HpsDebitServiceReturnBuilder withClientTransactionId(string $clientTransactionId)
16
+ */
17
+ class HpsDebitServiceReturnBuilder extends HpsBuilderAbstract
18
+ {
19
+ /** @var string|null */
20
+ protected $transactionId = null;
21
+
22
+ /** @var double|null */
23
+ protected $amount = null;
24
+
25
+ /** @var string|null */
26
+ protected $trackData = null;
27
+
28
+ /** @var string|null */
29
+ protected $pinBlock = null;
30
+
31
+ /** @var HpsEncryptionData|null */
32
+ protected $encryptionData = null;
33
+
34
+ /** @var bool|null */
35
+ protected $allowDuplicates = false;
36
+
37
+ /** @var HpsCardHolder|null */
38
+ protected $cardHolder = null;
39
+
40
+ /** @var HpsTransactionDetails|null */
41
+ protected $details = null;
42
+
43
+ /** @var string|null */
44
+ protected $clientTransactionId = null;
45
+
46
+ /**
47
+ * Instatiates a new HpsDebitServiceReturnBuilder
48
+ *
49
+ * @param HpsSoapGatewayService $service
50
+ */
51
+ public function __construct(HpsSoapGatewayService $service)
52
+ {
53
+ parent::__construct($service);
54
+ $this->setUpValidations();
55
+ }
56
+
57
+ /**
58
+ * Creates a return transaction through the HpsDebitService
59
+ */
60
+ public function execute()
61
+ {
62
+ parent::execute();
63
+
64
+ $returnSvc = new HpsDebitService($this->service->servicesConfig());
65
+ return $returnSvc->returnDebit(
66
+ $this->transactionId,
67
+ $this->amount,
68
+ $this->trackData,
69
+ $this->pinBlock,
70
+ $this->allowDuplicates,
71
+ $this->cardHolder,
72
+ $this->encryptionData,
73
+ $this->details,
74
+ $this->clientTransactionId
75
+ );
76
+ }
77
+
78
+ /**
79
+ * Setups up validations for building returns.
80
+ *
81
+ * @return null
82
+ */
83
+ private function setUpValidations()
84
+ {
85
+ $this
86
+ ->addValidation(array($this, 'transactionIdNotNull'), 'HpsArgumentException', 'Return needs an transactionId')
87
+ ->addValidation(array($this, 'amountNotNull'), 'HpsArgumentException', 'Return needs an amount')
88
+ ->addValidation(array($this, 'trackDataNotNull'), 'HpsArgumentException', 'Return needs an trackData')
89
+ ->addValidation(array($this, 'pinBlockNotNull'), 'HpsArgumentException', 'Return needs an pinBlock');
90
+ }
91
+
92
+ /**
93
+ * Ensures a transactionId has been set.
94
+ *
95
+ * @param array $actionCounts
96
+ *
97
+ * @return bool
98
+ */
99
+ protected function transactionIdNotNull($actionCounts)
100
+ {
101
+ return isset($actionCounts['transactionId']);
102
+ }
103
+
104
+ /**
105
+ * Ensures an amount has been set.
106
+ *
107
+ * @param array $actionCounts
108
+ *
109
+ * @return bool
110
+ */
111
+ protected function amountNotNull($actionCounts)
112
+ {
113
+ return isset($actionCounts['amount']);
114
+ }
115
+
116
+ /**
117
+ * Ensures a trackData has been set.
118
+ *
119
+ * @param array $actionCounts
120
+ *
121
+ * @return bool
122
+ */
123
+ protected function trackDataNotNull($actionCounts)
124
+ {
125
+ return isset($actionCounts['trackData']);
126
+ }
127
+
128
+ /**
129
+ * Ensures a pinBlock has been set.
130
+ *
131
+ * @param array $actionCounts
132
+ *
133
+ * @return bool
134
+ */
135
+ protected function pinBlockNotNull($actionCounts)
136
+ {
137
+ return isset($actionCounts['pinBlock']);
138
+ }
139
+ }
lib/SecureSubmit/src/Services/Fluent/Gateway/Debit/HpsDebitServiceReverseBuilder.php ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * A fluent interface for creating and executing a reverse
5
+ * transaction through the HpsDebitService.
6
+ *
7
+ * @method HpsDebitServiceReverseBuilder withTransactionId(string $transactionId)
8
+ * @method HpsDebitServiceReverseBuilder withAmount(double $amount)
9
+ * @method HpsDebitServiceReverseBuilder withTrackData(string $trackData)
10
+ * @method HpsDebitServiceReverseBuilder withAuthorizedAmount(double $authorizedAmount)
11
+ * @method HpsDebitServiceReverseBuilder withEncryptionData(HpsEncryptionData $encryptionData)
12
+ * @method HpsDebitServiceReverseBuilder withDetails(HpsTransactionDetails $details)
13
+ * @method HpsDebitServiceReverseBuilder withClientTransactionId(string $clientTransactionId)
14
+ */
15
+ class HpsDebitServiceReverseBuilder extends HpsBuilderAbstract
16
+ {
17
+ /** @var string|null */
18
+ protected $transactionId = null;
19
+
20
+ /** @var double|null */
21
+ protected $amount = null;
22
+
23
+ /** @var string|null */
24
+ protected $trackData = null;
25
+
26
+ /** @var double|null */
27
+ protected $authorizedAmount = null;
28
+
29
+ /** @var HpsEncryptionData|null */
30
+ protected $encryptionData = null;
31
+
32
+ /** @var HpsTransactionDetails|null */
33
+ protected $details = null;
34
+
35
+ /** @var string|null */
36
+ protected $clientTransactionId = null;
37
+
38
+ /**
39
+ * Instatiates a new HpsDebitServiceReverseBuilder
40
+ *
41
+ * @param HpsSoapGatewayService $service
42
+ */
43
+ public function __construct(HpsSoapGatewayService $service)
44
+ {
45
+ parent::__construct($service);
46
+ $this->setUpValidations();
47
+ }
48
+
49
+ /**
50
+ * Creates a reverse transaction through the HpsDebitService
51
+ */
52
+ public function execute()
53
+ {
54
+ parent::execute();
55
+
56
+ $reverseSvc = new HpsDebitService($this->service->servicesConfig());
57
+ return $reverseSvc->reverse(
58
+ $this->transactionId,
59
+ $this->amount,
60
+ $this->trackData,
61
+ $this->authorizedAmount,
62
+ $this->encryptionData,
63
+ $this->details,
64
+ $this->clientTransactionId
65
+ );
66
+ }
67
+
68
+ /**
69
+ * Setups up validations for building reverses.
70
+ *
71
+ * @return null
72
+ */
73
+ private function setUpValidations()
74
+ {
75
+ $this
76
+ ->addValidation(array($this, 'transactionIdNotNull'), 'HpsArgumentException', 'Reverse needs an transactionId')
77
+ ->addValidation(array($this, 'amountNotNull'), 'HpsArgumentException', 'Reverse needs an amount')
78
+ ->addValidation(array($this, 'trackDataNotNull'), 'HpsArgumentException', 'Reverse needs an trackData');
79
+ }
80
+
81
+ /**
82
+ * Ensures a transactionId has been set.
83
+ *
84
+ * @param array $actionCounts
85
+ *
86
+ * @return bool
87
+ */
88
+ protected function transactionIdNotNull($actionCounts)
89
+ {
90
+ return isset($actionCounts['transactionId']);
91
+ }
92
+
93
+ /**
94
+ * Ensures an amount has been set.
95
+ *
96
+ * @param array $actionCounts
97
+ *
98
+ * @return bool
99
+ */
100
+ protected function amountNotNull($actionCounts)
101
+ {
102
+ return isset($actionCounts['amount']);
103
+ }
104
+
105
+ /**
106
+ * Ensures a trackData has been set.
107
+ *
108
+ * @param array $actionCounts
109
+ *
110
+ * @return bool
111
+ */
112
+ protected function trackDataNotNull($actionCounts)
113
+ {
114
+ return isset($actionCounts['trackData']);
115
+ }
116
+ }
lib/SecureSubmit/src/Services/Fluent/Gateway/GiftCard/HpsGiftCardServiceActivateBuilder.php ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * A fluent interface for creating and executing an activate
5
+ * transaction through the HpsGiftCardService.
6
+ *
7
+ * @method HpsGiftCardServiceActivateBuilder withCard(HpsGiftCard $card)
8
+ * @method HpsGiftCardServiceActivateBuilder withAmount(double $amount)
9
+ * @method HpsGiftCardServiceActivateBuilder withCurrency(string $currency)
10
+ */
11
+ class HpsGiftCardServiceActivateBuilder extends HpsBuilderAbstract
12
+ {
13
+ /** @var HpsGiftCard|null */
14
+ protected $card = null;
15
+
16
+ /** @var double|null */
17
+ protected $amount = null;
18
+
19
+ /** @var string|null */
20
+ protected $currency = null;
21
+
22
+ /**
23
+ * Instatiates a new HpsGiftCardServiceActivateBuilder
24
+ *
25
+ * @param HpsSoapGatewayService $service
26
+ */
27
+ public function __construct(HpsSoapGatewayService $service)
28
+ {
29
+ parent::__construct($service);
30
+ $this->setUpValidations();
31
+ }
32
+
33
+ /**
34
+ * Creates an activate transaction through the HpsGiftCardService
35
+ */
36
+ public function execute()
37
+ {
38
+ parent::execute();
39
+
40
+ $activateSvc = new HpsGiftCardService($this->service->servicesConfig());
41
+ return $activateSvc->activate(
42
+ $this->amount,
43
+ $this->currency,
44
+ $this->card
45
+ );
46
+ }
47
+
48
+ /**
49
+ * Setups up validations for building activates.
50
+ *
51
+ * @return null
52
+ */
53
+ private function setUpValidations()
54
+ {
55
+ $this
56
+ ->addValidation(array($this, 'cardNotNull'), 'HpsArgumentException', 'Activate needs a card')
57
+ ->addValidation(array($this, 'amountNotNull'), 'HpsArgumentException', 'Activate needs an amount')
58
+ ->addValidation(array($this, 'currencyNotNull'), 'HpsArgumentException', 'Activate needs a currency');
59
+ }
60
+
61
+ /**
62
+ * Ensures a card has been set.
63
+ *
64
+ * @param array $actionCounts
65
+ *
66
+ * @return bool
67
+ */
68
+ protected function cardNotNull($actionCounts)
69
+ {
70
+ return isset($actionCounts['card']);
71
+ }
72
+
73
+ /**
74
+ * Ensures an amount has been set.
75
+ *
76
+ * @param array $actionCounts
77
+ *
78
+ * @return bool
79
+ */
80
+ protected function amountNotNull($actionCounts)
81
+ {
82
+ return isset($actionCounts['amount']);
83
+ }
84
+
85
+ /**
86
+ * Ensures a currency has been set.
87
+ *
88
+ * @param array $actionCounts
89
+ *
90
+ * @return bool
91
+ */
92
+ protected function currencyNotNull($actionCounts)
93
+ {
94
+ return isset($actionCounts['currency']);
95
+ }
96
+ }
lib/SecureSubmit/src/Services/Fluent/Gateway/GiftCard/HpsGiftCardServiceAddValueBuilder.php ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * A fluent interface for creating and executing an addValue
5
+ * transaction through the HpsGiftCardService.
6
+ *
7
+ * @method HpsGiftCardServiceAddValueBuilder withCard(HpsGiftCard $card)
8
+ * @method HpsGiftCardServiceAddValueBuilder withAmount(double $amount)
9
+ * @method HpsGiftCardServiceAddValueBuilder withCurrency(string $currency)
10
+ */
11
+ class HpsGiftCardServiceAddValueBuilder extends HpsBuilderAbstract
12
+ {
13
+ /** @var HpsGiftCard|null */
14
+ protected $card = null;
15
+
16
+ /** @var double|null */
17
+ protected $amount = null;
18
+
19
+ /** @var string|null */
20
+ protected $currency = null;
21
+
22
+ /**
23
+ * Instatiates a new HpsGiftCardServiceAddValueBuilder
24
+ *
25
+ * @param HpsSoapGatewayService $service
26
+ */
27
+ public function __construct(HpsSoapGatewayService $service)
28
+ {
29
+ parent::__construct($service);
30
+ $this->setUpValidations();
31
+ }
32
+
33
+ /**
34
+ * Creates an addValue transaction through the HpsGiftCardService
35
+ */
36
+ public function execute()
37
+ {
38
+ parent::execute();
39
+
40
+ $addValueSvc = new HpsGiftCardService($this->service->servicesConfig());
41
+ return $addValueSvc->addValue(
42
+ $this->amount,
43
+ $this->currency,
44
+ $this->card
45
+ );
46
+ }
47
+
48
+ /**
49
+ * Setups up validations for building addValues.
50
+ *
51
+ * @return null
52
+ */
53
+ private function setUpValidations()
54
+ {
55
+ $this
56
+ ->addValidation(array($this, 'cardNotNull'), 'HpsArgumentException', 'AddValue needs a card')
57
+ ->addValidation(array($this, 'amountNotNull'), 'HpsArgumentException', 'AddValue needs an amount')
58
+ ->addValidation(array($this, 'currencyNotNull'), 'HpsArgumentException', 'AddValue needs a currency');
59
+ }
60
+
61
+ /**
62
+ * Ensures a card has been set.
63
+ *
64
+ * @param array $actionCounts
65
+ *
66
+ * @return bool
67
+ */
68
+ protected function cardNotNull($actionCounts)
69
+ {
70
+ return isset($actionCounts['card']);
71
+ }
72
+
73
+ /**
74
+ * Ensures an amount has been set.
75
+ *
76
+ * @param array $actionCounts
77
+ *
78
+ * @return bool
79
+ */
80
+ protected function amountNotNull($actionCounts)
81
+ {
82
+ return isset($actionCounts['amount']);
83
+ }
84
+
85
+ /**
86
+ * Ensures a currency has been set.
87
+ *
88
+ * @param array $actionCounts
89
+ *
90
+ * @return bool
91
+ */
92
+ protected function currencyNotNull($actionCounts)
93
+ {
94
+ return isset($actionCounts['currency']);
95
+ }
96
+ }
lib/SecureSubmit/src/Services/Fluent/Gateway/GiftCard/HpsGiftCardServiceAliasBuilder.php ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * A fluent interface for creating and executing an alias
5
+ * transaction through the HpsGiftCardService.
6
+ *
7
+ * @method HpsGiftCardServiceAliasBuilder withCard(HpsGiftCard $card)
8
+ * @method HpsGiftCardServiceAliasBuilder withAlias(string $alias)
9
+ * @method HpsGiftCardServiceAliasBuilder withAction(string $action)
10
+ */
11
+ class HpsGiftCardServiceAliasBuilder extends HpsBuilderAbstract
12
+ {
13
+ /** @var HpsGiftCard|null */
14
+ protected $card = null;
15
+
16
+ /** @var string|null */
17
+ protected $alias = null;
18
+
19
+ /** @var string|null */
20
+ protected $action = null;
21
+
22
+ /**
23
+ * Instatiates a new HpsGiftCardServiceAliasBuilder
24
+ *
25
+ * @param HpsSoapGatewayService $service
26
+ */
27
+ public function __construct(HpsSoapGatewayService $service)
28
+ {
29
+ parent::__construct($service);
30
+ $this->setUpValidations();
31
+ }
32
+
33
+ /**
34
+ * Creates an alias transaction through the HpsGiftCardService
35
+ */
36
+ public function execute()
37
+ {
38
+ parent::execute();
39
+
40
+ $aliasSvc = new HpsGiftCardService($this->service->servicesConfig());
41
+ return $aliasSvc->alias(
42
+ $this->action,
43
+ $this->card,
44
+ $this->alias
45
+ );
46
+ }
47
+
48
+ /**
49
+ * Setups up validations for building aliases.
50
+ *
51
+ * @return null
52
+ */
53
+ private function setUpValidations()
54
+ {
55
+ $this
56
+ ->addValidation(array($this, 'cardNotNull'), 'HpsArgumentException', 'Alias needs a card')
57
+ ->addValidation(array($this, 'aliasNotNull'), 'HpsArgumentException', 'Alias needs an alias')
58
+ ->addValidation(array($this, 'actionNotNull'), 'HpsArgumentException', 'Alias needs an action');
59
+ }
60
+
61
+ /**
62
+ * Ensures a card has been set.
63
+ *
64
+ * @param array $actionCounts
65
+ *
66
+ * @return bool
67
+ */
68
+ protected function cardNotNull($actionCounts)
69
+ {
70
+ return isset($actionCounts['card']);
71
+ }
72
+
73
+ /**
74
+ * Ensures an alias has been set.
75
+ *
76
+ * @param array $actionCounts
77
+ *
78
+ * @return bool
79
+ */
80
+ protected function aliasNotNull($actionCounts)
81
+ {
82
+ return isset($actionCounts['alias']);
83
+ }
84
+
85
+ /**
86
+ * Ensures a action has been set.
87
+ *
88
+ * @param array $actionCounts
89
+ *
90
+ * @return bool
91
+ */
92
+ protected function actionNotNull($actionCounts)
93
+ {
94
+ return isset($actionCounts['action']);
95
+ }
96
+ }
lib/SecureSubmit/src/Services/Fluent/Gateway/GiftCard/HpsGiftCardServiceBalanceBuilder.php ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * A fluent interface for creating and executing a balance
5
+ * transaction through the HpsGiftCardService.
6
+ *
7
+ * @method HpsGiftCardServiceBalanceBuilder withCard(HpsGiftCard $card)
8
+ */
9
+ class HpsGiftCardServiceBalanceBuilder extends HpsBuilderAbstract
10
+ {
11
+ /** @var HpsGiftCard|null */
12
+ protected $card = null;
13
+
14
+ /**
15
+ * Instatiates a new HpsGiftCardServiceBalanceBuilder
16
+ *
17
+ * @param HpsSoapGatewayService $service
18
+ */
19
+ public function __construct(HpsSoapGatewayService $service)
20
+ {
21
+ parent::__construct($service);
22
+ $this->setUpValidations();
23
+ }
24
+
25
+ /**
26
+ * Creates a balance transaction through the HpsGiftCardService
27
+ */
28
+ public function execute()
29
+ {
30
+ parent::execute();
31
+
32
+ $balanceSvc = new HpsGiftCardService($this->service->servicesConfig());
33
+ return $balanceSvc->balance(
34
+ $this->card
35
+ );
36
+ }
37
+
38
+ /**
39
+ * Setups up validations for building balances.
40
+ *
41
+ * @return null
42
+ */
43
+ private function setUpValidations()
44
+ {
45
+ $this
46
+ ->addValidation(array($this, 'cardNotNull'), 'HpsArgumentException', 'Balance needs a card');
47
+ }
48
+
49
+ /**
50
+ * Ensures a card has been set.
51
+ *
52
+ * @param array $actionCounts
53
+ *
54
+ * @return bool
55
+ */
56
+ protected function cardNotNull($actionCounts)
57
+ {
58
+ return isset($actionCounts['card']);
59
+ }
60
+ }
lib/SecureSubmit/src/Services/Fluent/Gateway/GiftCard/HpsGiftCardServiceDeactivateBuilder.php ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * A fluent interface for creating and executing a deactivate
5
+ * transaction through the HpsGiftCardService.
6
+ *
7
+ * @method HpsGiftCardServiceDeactivateBuilder withCard(HpsGiftCard $card)
8
+ */
9
+ class HpsGiftCardServiceDeactivateBuilder extends HpsBuilderAbstract
10
+ {
11
+ /** @var HpsGiftCard|null */
12
+ protected $card = null;
13
+
14
+ /**
15
+ * Instatiates a new HpsGiftCardServiceDeactivateBuilder
16
+ *
17
+ * @param HpsSoapGatewayService $service
18
+ */
19
+ public function __construct(HpsSoapGatewayService $service)
20
+ {
21
+ parent::__construct($service);
22
+ $this->setUpValidations();
23
+ }
24
+
25
+ /**
26
+ * Creates a deactivate transaction through the HpsGiftCardService
27
+ */
28
+ public function execute()
29
+ {
30
+ parent::execute();
31
+
32
+ $deactivateSvc = new HpsGiftCardService($this->service->servicesConfig());
33
+ return $deactivateSvc->deactivate(
34
+ $this->card
35
+ );
36
+ }
37
+
38
+ /**
39
+ * Setups up validations for building deactivates.
40
+ *
41
+ * @return null
42
+ */
43
+ private function setUpValidations()
44
+ {
45
+ $this
46
+ ->addValidation(array($this, 'cardNotNull'), 'HpsArgumentException', 'Deactivate needs a card');
47
+ }
48
+
49
+ /**
50
+ * Ensures a card has been set.
51
+ *
52
+ * @param array $actionCounts
53
+ *
54
+ * @return bool
55
+ */
56
+ protected function cardNotNull($actionCounts)
57
+ {
58
+ return isset($actionCounts['card']);
59
+ }
60
+ }
lib/SecureSubmit/src/Services/Fluent/Gateway/GiftCard/HpsGiftCardServiceReplaceBuilder.php ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * A fluent interface for creating and executing a replace
5
+ * transaction through the HpsGiftCardService.
6
+ *
7
+ * @method HpsGiftCardServiceReplaceBuilder withOldCard(HpsGiftCard $oldCard)
8
+ * @method HpsGiftCardServiceReplaceBuilder withNewCard(HpsGiftCard $newCard)
9
+ */
10
+ class HpsGiftCardServiceReplaceBuilder extends HpsBuilderAbstract
11
+ {
12
+ /** @var HpsGiftCard|null */
13
+ protected $oldCard = null;
14
+
15
+ /** @var HpsGiftCard|null */
16
+ protected $newCard = null;
17
+
18
+ /**
19
+ * Instatiates a new HpsGiftCardServiceReplaceBuilder
20
+ *
21
+ * @param HpsSoapGatewayService $service
22
+ */
23
+ public function __construct(HpsSoapGatewayService $service)
24
+ {
25
+ parent::__construct($service);
26
+ $this->setUpValidations();
27
+ }
28
+
29
+ /**
30
+ * Creates a replace transaction through the HpsGiftCardService
31
+ */
32
+ public function execute()
33
+ {
34
+ parent::execute();
35
+
36
+ $replaceSvc = new HpsGiftCardService($this->service->servicesConfig());
37
+ return $replaceSvc->replace(
38
+ $this->oldCard,
39
+ $this->newCard
40
+ );
41
+ }
42
+
43
+ /**
44
+ * Setups up validations for building replaces.
45
+ *
46
+ * @return null
47
+ */
48
+ private function setUpValidations()
49
+ {
50
+ $this
51
+ ->addValidation(array($this, 'oldCardNotNull'), 'HpsArgumentException', 'Replace needs an oldCard')
52
+ ->addValidation(array($this, 'newCardNotNull'), 'HpsArgumentException', 'Replace needs a newCard');
53
+ }
54
+
55
+ /**
56
+ * Ensures an oldCard has been set.
57
+ *
58
+ * @param array $actionCounts
59
+ *
60
+ * @return bool
61
+ */
62
+ protected function oldCardNotNull($actionCounts)
63
+ {
64
+ return isset($actionCounts['oldCard']);
65
+ }
66
+
67
+ /**
68
+ * Ensures a newCard has been set.
69
+ *
70
+ * @param array $actionCounts
71
+ *
72
+ * @return bool
73
+ */
74
+ protected function newCardNotNull($actionCounts)
75
+ {
76
+ return isset($actionCounts['newCard']);
77
+ }
78
+ }
lib/SecureSubmit/src/Services/Fluent/Gateway/GiftCard/HpsGiftCardServiceReverseBuilder.php ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * A fluent interface for creating and executing a reverse
5
+ * transaction through the HpsGiftCardService.
6
+ *
7
+ * @method HpsGiftCardServiceReverseBuilder withCard(HpsGiftCard $card)
8
+ * @method HpsGiftCardServiceReverseBuilder withAmount(double $amount)
9
+ * @method HpsGiftCardServiceReverseBuilder withCurrency(string $currency)
10
+ * @method HpsGiftCardServiceReverseBuilder withTransactionId(string $transactionId)
11
+ */
12
+ class HpsGiftCardServiceReverseBuilder extends HpsBuilderAbstract
13
+ {
14
+ /** @var HpsGiftCard|null */
15
+ protected $card = null;
16
+
17
+ /** @var double|null */
18
+ protected $amount = null;
19
+
20
+ /** @var string */
21
+ protected $currency = 'usd';
22
+
23
+ /** @var string|null */
24
+ protected $transactionId = null;
25
+
26
+ /**
27
+ * Instatiates a new HpsGiftCardServiceReverseBuilder
28
+ *
29
+ * @param HpsSoapGatewayService $service
30
+ */
31
+ public function __construct(HpsSoapGatewayService $service)
32
+ {
33
+ parent::__construct($service);
34
+ $this->setUpValidations();
35
+ }
36
+
37
+ /**
38
+ * Creates a reverse transaction through the HpsGiftCardService
39
+ */
40
+ public function execute()
41
+ {
42
+ parent::execute();
43
+
44
+ $reverseSvc = new HpsGiftCardService($this->service->servicesConfig());
45
+ return $reverseSvc->reverse(
46
+ isset($this->card) ? $this->card : $this->transactionId,
47
+ $this->amount,
48
+ $this->currency
49
+ );
50
+ }
51
+
52
+ /**
53
+ * Setups up validations for building reverses.
54
+ *
55
+ * @return null
56
+ */
57
+ private function setUpValidations()
58
+ {
59
+ $this
60
+ ->addValidation(array($this, 'cardOrTransactionId'), 'HpsArgumentException', 'Reverse needs a card')
61
+ ->addValidation(array($this, 'amountNotNull'), 'HpsArgumentException', 'Reverse needs an amount');
62
+ }
63
+
64
+ /**
65
+ * Ensures a card has been set.
66
+ *
67
+ * @param array $actionCounts
68
+ *
69
+ * @return bool
70
+ */
71
+ protected function cardOrTransactionId($actionCounts)
72
+ {
73
+ return (isset($actionCounts['card']) && $actionCounts['card'] == 1
74
+ && (!isset($actionCounts['transactionId'])
75
+ || isset($actionCounts['transactionId']) && $actionCounts['transactionId'] == 0))
76
+ || (isset($actionCounts['transactionId']) && $actionCounts['transactionId'] == 1
77
+ && (!isset($actionCounts['card'])
78
+ || isset($actionCounts['card']) && $actionCounts['card'] == 0));
79
+ }
80
+
81
+ /**
82
+ * Ensures an amount has been set.
83
+ *
84
+ * @param array $actionCounts
85
+ *
86
+ * @return bool
87
+ */
88
+ protected function amountNotNull($actionCounts)
89
+ {
90
+ return isset($actionCounts['amount']);
91
+ }
92
+ }
lib/SecureSubmit/src/Services/Fluent/Gateway/GiftCard/HpsGiftCardServiceRewardBuilder.php ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * A fluent interface for creating and executing a reward
5
+ * transaction through the HpsGiftCardService.
6
+ *
7
+ * @method HpsGiftCardServiceRewardBuilder withCard(HpsGiftCard $card)
8
+ * @method HpsGiftCardServiceRewardBuilder withAmount(double $amount)
9
+ * @method HpsGiftCardServiceRewardBuilder withCurrency(string $currency)
10
+ * @method HpsGiftCardServiceRewardBuilder withGratuity(double $gratuity)
11
+ * @method HpsGiftCardServiceRewardBuilder withTax(double $tax)
12
+ */
13
+ class HpsGiftCardServiceRewardBuilder extends HpsBuilderAbstract
14
+ {
15
+ /** @var HpsGiftCard|null */
16
+ protected $card = null;
17
+
18
+ /** @var double|null */
19
+ protected $amount = null;
20
+
21
+ /** @var string */
22
+ protected $currency = 'usd';
23
+
24
+ /** @var double|null */
25
+ protected $gratuity = null;
26
+
27
+ /** @var double|null */
28
+ protected $tax = null;
29
+
30
+ /**
31
+ * Instatiates a new HpsGiftCardServiceRewardBuilder
32
+ *
33
+ * @param HpsSoapGatewayService $service
34
+ */
35
+ public function __construct(HpsSoapGatewayService $service)
36
+ {
37
+ parent::__construct($service);
38
+ $this->setUpValidations();
39
+ }
40
+
41
+ /**
42
+ * Creates a reward transaction through the HpsGiftCardService
43
+ */
44
+ public function execute()
45
+ {
46
+ parent::execute();
47
+
48
+ $rewardSvc = new HpsGiftCardService($this->service->servicesConfig());
49
+ return $rewardSvc->reward(
50
+ $this->card,
51
+ $this->amount,
52
+ $this->currency,
53
+ $this->gratuity,
54
+ $this->tax
55
+ );
56
+ }
57
+
58
+ /**
59
+ * Setups up validations for building rewards.
60
+ *
61
+ * @return null
62
+ */
63
+ private function setUpValidations()
64
+ {
65
+ $this
66
+ ->addValidation(array($this, 'cardNotNull'), 'HpsArgumentException', 'Reward needs a card')
67
+ ->addValidation(array($this, 'amountNotNull'), 'HpsArgumentException', 'Reward needs an amount');
68
+ }
69
+
70
+ /**
71
+ * Ensures a card has been set.
72
+ *
73
+ * @param array $actionCounts
74
+ *
75
+ * @return bool
76
+ */
77
+ protected function cardNotNull($actionCounts)
78
+ {
79
+ return isset($actionCounts['card']);
80
+ }
81
+
82
+ /**
83
+ * Ensures an amount has been set.
84
+ *
85
+ * @param array $actionCounts
86
+ *
87
+ * @return bool
88
+ */
89
+ protected function amountNotNull($actionCounts)
90
+ {
91
+ return isset($actionCounts['amount']);
92
+ }
93
+ }
lib/SecureSubmit/src/Services/Fluent/Gateway/GiftCard/HpsGiftCardServiceSaleBuilder.php ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * A fluent interface for creating and executing a sale
5
+ * transaction through the HpsGiftCardService.
6
+ *
7
+ * @method HpsGiftCardServiceSaleBuilder withCard(HpsGiftCard $card)
8
+ * @method HpsGiftCardServiceSaleBuilder withAmount(double $amount)
9
+ * @method HpsGiftCardServiceSaleBuilder withCurrency(string $currency)
10
+ * @method HpsGiftCardServiceRewardBuilder withGratuity(double $gratuity)
11
+ * @method HpsGiftCardServiceRewardBuilder withTax(double $tax)
12
+ */
13
+ class HpsGiftCardServiceSaleBuilder extends HpsBuilderAbstract
14
+ {
15
+ /** @var HpsGiftCard|null */
16
+ protected $card = null;
17
+
18
+ /** @var double|null */
19
+ protected $amount = null;
20
+
21
+ /** @var string */
22
+ protected $currency = 'usd';
23
+
24
+ /** @var double|null */
25
+ protected $gratuity = null;
26
+
27
+ /** @var double|null */
28
+ protected $tax = null;
29
+
30
+ /**
31
+ * Instatiates a new HpsGiftCardServiceSaleBuilder
32
+ *
33
+ * @param HpsSoapGatewayService $service
34
+ */
35
+ public function __construct(HpsSoapGatewayService $service)
36
+ {
37
+ parent::__construct($service);
38
+ $this->setUpValidations();
39
+ }
40
+
41
+ /**
42
+ * Creates a sale transaction through the HpsGiftCardService
43
+ */
44
+ public function execute()
45
+ {
46
+ parent::execute();
47
+
48
+ $saleSvc = new HpsGiftCardService($this->service->servicesConfig());
49
+ return $saleSvc->sale(
50
+ $this->card,
51
+ $this->amount,
52
+ $this->currency,
53
+ $this->gratuity,
54
+ $this->tax
55
+ );
56
+ }
57
+
58
+ /**
59
+ * Setups up validations for building sales.
60
+ *
61
+ * @return null
62
+ */
63
+ private function setUpValidations()
64
+ {
65
+ $this
66
+ ->addValidation(array($this, 'cardNotNull'), 'HpsArgumentException', 'Sale needs a card')
67
+ ->addValidation(array($this, 'amountNotNull'), 'HpsArgumentException', 'Sale needs an amount')
68
+ ->addValidation(array($this, 'currencyNotNull'), 'HpsArgumentException', 'Sale needs a currency');
69
+ }
70
+
71
+ /**
72
+ * Ensures a card has been set.
73
+ *
74
+ * @param array $actionCounts
75
+ *
76
+ * @return bool
77
+ */
78
+ protected function cardNotNull($actionCounts)
79
+ {
80
+ return isset($actionCounts['card']);
81
+ }
82
+
83
+ /**
84
+ * Ensures an amount has been set.
85
+ *
86
+ * @param array $actionCounts
87
+ *
88
+ * @return bool
89
+ */
90
+ protected function amountNotNull($actionCounts)
91
+ {
92
+ return isset($actionCounts['amount']);
93
+ }
94
+
95
+ /**
96
+ * Ensures a currency has been set.
97
+ *
98
+ * @param array $actionCounts
99
+ *
100
+ * @return bool
101
+ */
102
+ protected function currencyNotNull($actionCounts)
103
+ {
104
+ return isset($actionCounts['currency']);
105
+ }
106
+ }
lib/SecureSubmit/src/Services/Fluent/Gateway/GiftCard/HpsGiftCardServiceVoidBuilder.php ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * A fluent interface for creating and executing a void
5
+ * transaction through the HpsGiftCardService.
6
+ *
7
+ * @method HpsGiftCardServiceVoidBuilder withTransactionId(string $transactionId)
8
+ */
9
+ class HpsGiftCardServiceVoidBuilder extends HpsBuilderAbstract
10
+ {
11
+ /** @var string|null */
12
+ protected $transactionId = null;
13
+
14
+ /**
15
+ * Instatiates a new HpsGiftCardServiceVoidBuilder
16
+ *
17
+ * @param HpsSoapGatewayService $service
18
+ */
19
+ public function __construct(HpsSoapGatewayService $service)
20
+ {
21
+ parent::__construct($service);
22
+ $this->setUpValidations();
23
+ }
24
+
25
+ /**
26
+ * Creates a void transaction through the HpsGiftCardService
27
+ */
28
+ public function execute()
29
+ {
30
+ parent::execute();
31
+
32
+ $voidSvc = new HpsGiftCardService($this->service->servicesConfig());
33
+ return $voidSvc->void(
34
+ $this->transactionId
35
+ );
36
+ }
37
+
38
+ /**
39
+ * Setups up validations for building voids.
40
+ *
41
+ * @return null
42
+ */
43
+ private function setUpValidations()
44
+ {
45
+ $this
46
+ ->addValidation(array($this, 'transactionIdNotNull'), 'HpsArgumentException', 'Void needs a transactionId');
47
+ }
48
+
49
+ /**
50
+ * Ensures a transactionId has been set.
51
+ *
52
+ * @param array $actionCounts
53
+ *
54
+ * @return bool
55
+ */
56
+ protected function transactionIdNotNull($actionCounts)
57
+ {
58
+ return isset($actionCounts['transactionId']);
59
+ }
60
+ }
lib/SecureSubmit/src/Services/Fluent/Gateway/HpsFluentCheckService.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsFluentCheckService extends HpsSoapGatewayService
4
+ {
5
+ public function __construct($config = null)
6
+ {
7
+ parent::__construct($config);
8
+ }
9
+
10
+ public function withConfig($config)
11
+ {
12
+ $this->_config = $config;
13
+ return $this;
14
+ }
15
+
16
+ public function override($amount = null)
17
+ {
18
+ $builder = new HpsCheckServiceOverrideBuilder($this);
19
+ return $builder
20
+ ->withAmount($amount);
21
+ }
22
+
23
+ public function returnCheck($amount = null)
24
+ {
25
+ $builder = new HpsCheckServiceReturnBuilder($this);
26
+ return $builder
27
+ ->withAmount($amount);
28
+ }
29
+
30
+ public function sale($amount = null)
31
+ {
32
+ $builder = new HpsCheckServiceSaleBuilder($this);
33
+ return $builder
34
+ ->withAmount($amount);
35
+ }
36
+
37
+ public function void($transactionId = null)
38
+ {
39
+ $builder = new HpsCheckServiceVoidBuilder($this);
40
+ return $builder
41
+ ->withTransactionId($transactionId);
42
+ }
43
+ }
lib/SecureSubmit/src/Services/Fluent/Gateway/HpsFluentCreditService.php ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsFluentCreditService extends HpsSoapGatewayService
4
+ {
5
+ public function __construct($config = null)
6
+ {
7
+ parent::__construct($config);
8
+ }
9
+
10
+ public function withConfig($config)
11
+ {
12
+ $this->_config = $config;
13
+ return $this;
14
+ }
15
+
16
+ public function authorize($amount = null)
17
+ {
18
+ $builder = new HpsCreditServiceAuthorizeBuilder($this);
19
+ return $builder
20
+ ->withAmount($amount)
21
+ ->withCurrency('usd');
22
+ }
23
+
24
+ public function capture($transactionId = null)
25
+ {
26
+ $builder = new HpsCreditServiceCaptureBuilder($this);
27
+ return $builder
28
+ ->withTransactionId($transactionId);
29
+ }
30
+
31
+ public function charge($amount = null)
32
+ {
33
+ $builder = new HpsCreditServiceChargeBuilder($this);
34
+ return $builder
35
+ ->withAmount($amount)
36
+ ->withCurrency('usd');
37
+ }
38
+
39
+ public function cpcEdit()
40
+ {
41
+ return new HpsCreditServiceCpcEditBuilder($this);
42
+ }
43
+
44
+ public function edit()
45
+ {
46
+ return new HpsCreditServiceEditBuilder($this);
47
+ }
48
+
49
+ public function get($transactionId = null)
50
+ {
51
+ $builder = new HpsCreditServiceGetBuilder($this);
52
+ return $builder
53
+ ->withTransactionId($transactionId);
54
+ }
55
+
56
+ public function listTransactions()
57
+ {
58
+ return new HpsCreditServiceListTransactionsBuilder($this);
59
+ }
60
+
61
+ public function refund($amount = null)
62
+ {
63
+ $builder = new HpsCreditServiceRefundBuilder($this);
64
+ return $builder
65
+ ->withAmount($amount)
66
+ ->withCurrency('usd');
67
+ }
68
+
69
+ public function reverse($amount = null)
70
+ {
71
+ $builder = new HpsCreditServiceReverseBuilder($this);
72
+ return $builder
73
+ ->withAmount($amount)
74
+ ->withCurrency('usd');
75
+ }
76
+
77
+ public function verify()
78
+ {
79
+ return new HpsCreditServiceVerifyBuilder($this);
80
+ }
81
+
82
+ public function void($transactionId = null)
83
+ {
84
+ $builder = new HpsCreditServiceVoidBuilder($this);
85
+ return $builder
86
+ ->withTransactionId($transactionId);
87
+ }
88
+ }
lib/SecureSubmit/src/Services/Fluent/Gateway/HpsFluentDebitService.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsFluentDebitService extends HpsSoapGatewayService
4
+ {
5
+ public function __construct($config = null)
6
+ {
7
+ parent::__construct($config);
8
+ }
9
+
10
+ public function withConfig($config)
11
+ {
12
+ $this->_config = $config;
13
+ return $this;
14
+ }
15
+
16
+ public function addValue($amount = null)
17
+ {
18
+ $builder = new HpsDebitServiceAddValueBuilder($this);
19
+ return $builder
20
+ ->withAmount($amount);
21
+ }
22
+
23
+ public function charge($amount = null)
24
+ {
25
+ $builder = new HpsDebitServiceChargeBuilder($this);
26
+ return $builder
27
+ ->withAmount($amount);
28
+ }
29
+
30
+ public function returnDebit($transactionId = null)
31
+ {
32
+ $builder = new HpsDebitServiceReturnBuilder($this);
33
+ return $builder
34
+ ->withTransactionId($transactionId);
35
+ }
36
+
37
+ public function reverse($transactionId = null)
38
+ {
39
+ $builder = new HpsDebitServiceReverseBuilder($this);
40
+ return $builder
41
+ ->withTransactionId($transactionId);
42
+ }
43
+ }
lib/SecureSubmit/src/Services/Fluent/Gateway/HpsFluentGiftCardService.php ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsFluentGiftCardService extends HpsSoapGatewayService
4
+ {
5
+ public function __construct($config = null)
6
+ {
7
+ parent::__construct($config);
8
+ }
9
+
10
+ public function withConfig($config)
11
+ {
12
+ $this->_config = $config;
13
+ return $this;
14
+ }
15
+
16
+ public function activate($amount = null)
17
+ {
18
+ $builder = new HpsGiftCardServiceActivateBuilder($this);
19
+ return $builder
20
+ ->withAmount($amount)
21
+ ->withCurrency('usd');
22
+ }
23
+
24
+ public function addValue($amount = null)
25
+ {
26
+ $builder = new HpsGiftCardServiceAddValueBuilder($this);
27
+ return $builder
28
+ ->withAmount($amount);
29
+ }
30
+
31
+ public function alias($amount = null)
32
+ {
33
+ $builder = new HpsGiftCardServiceAliasBuilder($this);
34
+ return $builder
35
+ ->withAmount($amount)
36
+ ->withCurrency('usd');
37
+ }
38
+
39
+ public function balance()
40
+ {
41
+ return new HpsGiftCardServiceBalanceBuilder($this);
42
+ }
43
+
44
+ public function deactivate()
45
+ {
46
+ return new HpsGiftCardServiceDeactivateBuilder($this);
47
+ }
48
+
49
+ public function replace()
50
+ {
51
+ return new HpsGiftCardServiceReplaceBuilder($this);
52
+ }
53
+
54
+ public function reverse($amount = null)
55
+ {
56
+ $builder = new HpsGiftCardServiceReverseBuilder($this);
57
+ return $builder
58
+ ->withAmount($amount)
59
+ ->withCurrency('usd');
60
+ }
61
+
62
+ public function reward($amount = null)
63
+ {
64
+ $builder = new HpsGiftCardServiceRewardBuilder($this);
65
+ return $builder
66
+ ->withAmount($amount)
67
+ ->withCurrency('usd');
68
+ }
69
+
70
+ public function sale($amount = null)
71
+ {
72
+ $builder = new HpsGiftCardServiceSaleBuilder($this);
73
+ return $builder
74
+ ->withAmount($amount)
75
+ ->withCurrency('usd');
76
+ }
77
+
78
+ public function void($transactionId = null)
79
+ {
80
+ $builder = new HpsGiftCardServiceVoidBuilder($this);
81
+ return $builder
82
+ ->withTransactionId($transactionId);
83
+ }
84
+ }
lib/SecureSubmit/src/Services/Fluent/Gateway/PayPlan/HpsPayPlanCustomerServiceAddBuilder.php ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @method HpsPayPlanCustomerServiceAddBuilder withData(array $data)
5
+ * @method HpsPayPlanCustomerServiceAddBuilder withConfig(HpsServiceConfig $config)
6
+ */
7
+ class HpsPayPlanCustomerServiceAddBuilder extends HpsBuilderAbstract
8
+ {
9
+ /** @var array */
10
+ protected $data = array();
11
+
12
+ /**
13
+ * Instatiates a new HpsPayPlanCustomerServiceAddBuilder
14
+ *
15
+ * @param HpsRestGatewayService $service
16
+ */
17
+ public function __construct(HpsRestGatewayService $service)
18
+ {
19
+ parent::__construct($service);
20
+ $this->setUpValidations();
21
+ }
22
+
23
+ /**
24
+ * Creates an add transaction through the HpsPayPlanCustomerService
25
+ */
26
+ public function execute()
27
+ {
28
+ parent::execute();
29
+
30
+ $service = new HpsPayPlanCustomerService($this->service->servicesConfig());
31
+ $obj = new HpsPayPlanCustomer();
32
+
33
+ foreach ($this->data as $k => $v) {
34
+ $obj->$k = $v;
35
+ }
36
+ unset($usableData, $k, $v);
37
+
38
+ return $service->add($obj);
39
+ }
40
+
41
+ /**
42
+ * Setups up validations for building customer
43
+ * adds.
44
+ *
45
+ * @return null
46
+ */
47
+ private function setUpValidations()
48
+ {
49
+ $this
50
+ ->addValidation(array($this, 'dataNotEmpty'), 'HpsArgumentException', 'Add needs a non-empty data set');
51
+ }
52
+
53
+ /**
54
+ * Ensures the data set is not empty.
55
+ *
56
+ * @param array $actionCounts
57
+ *
58
+ * @return bool
59
+ */
60
+ protected function dataNotEmpty($actionCounts)
61
+ {
62
+ return !empty($this->data);
63
+ }
64
+
65
+ /**
66
+ * @param string $key
67
+ * @param mixed $value
68
+ *
69
+ * @return HpsPayPlanCustomerServiceAddBuilder
70
+ */
71
+ public function set($key, $value)
72
+ {
73
+ $this->data[$key] = $value;
74
+ return $this;
75
+ }
76
+ }
lib/SecureSubmit/src/Services/Fluent/Gateway/PayPlan/HpsPayPlanCustomerServiceDeleteBuilder.php ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @method HpsPayPlanCustomerServiceDeleteBuilder withData(array $data)
5
+ * @method HpsPayPlanCustomerServiceDeleteBuilder withCustomer(HpsPayPlanCustomer $customer)
6
+ * @method HpsPayPlanCustomerServiceDeleteBuilder withCustomerKey(string $customerKey)
7
+ */
8
+ class HpsPayPlanCustomerServiceDeleteBuilder extends HpsBuilderAbstract
9
+ {
10
+ /** @var array */
11
+ protected $data = array();
12
+
13
+ /** @var HpsPayPlanCustomer|null */
14
+ protected $customer = null;
15
+
16
+ /** @var string|null */
17
+ protected $customerKey = null;
18
+
19
+ /**
20
+ * Instatiates a new HpsPayPlanCustomerServiceDeleteBuilder
21
+ *
22
+ * @param HpsRestGatewayService $service
23
+ */
24
+ public function __construct(HpsRestGatewayService $service)
25
+ {
26
+ parent::__construct($service);
27
+ $this->setUpValidations();
28
+ }
29
+
30
+ /**
31
+ * Creates an delete transaction through the HpsPayPlanCustomerService
32
+ */
33
+ public function execute()
34
+ {
35
+ parent::execute();
36
+
37
+ if ($this->customer != null) {
38
+ $this->customerKey = $this->customer->customerKey;
39
+ }
40
+
41
+ $service = new HpsPayPlanCustomerService($this->service->servicesConfig());
42
+
43
+ return $service->delete($this->customerKey);
44
+ }
45
+
46
+ /**
47
+ * Setups up validations for building customer
48
+ * deletes.
49
+ *
50
+ * @return null
51
+ */
52
+ private function setUpValidations()
53
+ {
54
+ $this
55
+ ->addValidation(array($this, 'onlyOneCustomerIdentifier'), 'HpsArgumentException', 'Delete can only use one customer identifier ($customer or $customerKey)');
56
+ }
57
+
58
+ /**
59
+ * Ensures there is only one customer identifier, and
60
+ * checks that there is only one customer or one
61
+ * customerKey in use. Both cannot be used.
62
+ *
63
+ * @param array $actionCounts
64
+ *
65
+ * @return bool
66
+ */
67
+ public function onlyOneCustomerIdentifier($actionCounts)
68
+ {
69
+ return (isset($actionCounts['customer']) && $actionCounts['customer'] == 1
70
+ && (!isset($actionCounts['customerKey'])
71
+ || isset($actionCounts['customerKey']) && $actionCounts['customerKey'] == 0))
72
+ || (isset($actionCounts['customerKey']) && $actionCounts['customerKey'] == 1
73
+ && (!isset($actionCounts['customer'])
74
+ || isset($actionCounts['customer']) && $actionCounts['customer'] == 0));
75
+ }
76
+ }
lib/SecureSubmit/src/Services/Fluent/Gateway/PayPlan/HpsPayPlanCustomerServiceEditBuilder.php ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @method HpsPayPlanCustomerServiceEditBuilder withData(array $data)
5
+ * @method HpsPayPlanCustomerServiceEditBuilder withCustomer(HpsPaymentCustomer $customer)
6
+ * @method HpsPayPlanCustomerServiceEditBuilder withCustomerKey(string $customerKey)
7
+ */
8
+ class HpsPayPlanCustomerServiceEditBuilder extends HpsBuilderAbstract
9
+ {
10
+ /** @var array */
11
+ protected $data = array();
12
+
13
+ /** @var HpsPaymentCustomer|null */
14
+ protected $customer = null;
15
+
16
+ /** @var string|null */
17
+ protected $customerKey = null;
18
+
19
+ /**
20
+ * Instatiates a new HpsPayPlanCustomerServiceEditBuilder
21
+ *
22
+ * @param HpsRestGatewayService $service
23
+ */
24
+ public function __construct(HpsRestGatewayService $service)
25
+ {
26
+ parent::__construct($service);
27
+ $this->setUpValidations();
28
+ }
29
+
30
+ /**
31
+ * Creates an edit transaction through the HpsPayPlanCustomerService
32
+ */
33
+ public function execute()
34
+ {
35
+ parent::execute();
36
+
37
+ if ($this->customer != null) {
38
+ $this->customerKey = $this->customer->customerKey;
39
+ }
40
+
41
+ $service = new HpsPayPlanCustomerService($this->service->servicesConfig());
42
+ $obj = new HpsPayPlanCustomer();
43
+ $obj->customerKey = $this->customerKey;
44
+
45
+ $usableData = array_intersect_key(
46
+ $this->data,
47
+ array_flip(HpsPayPlanCustomer::getEditableFields())
48
+ );
49
+ foreach ($usableData as $k => $v) {
50
+ $obj->$k = $v;
51
+ }
52
+ unset($usableData, $k, $v);
53
+
54
+ return $service->edit($obj);
55
+ }
56
+
57
+ /**
58
+ * Setups up validations for building customer
59
+ * edits.
60
+ *
61
+ * @return null
62
+ */
63
+ private function setUpValidations()
64
+ {
65
+ $this
66
+ ->addValidation(array($this, 'onlyOneCustomerIdentifier'), 'HpsArgumentException', 'Edit can only use one customer identifier ($customer or $customerKey)')
67
+ ->addValidation(array($this, 'dataNotEmpty'), 'HpsArgumentException', 'Edit needs a non-empty data set');
68
+ }
69
+
70
+ /**
71
+ * Ensures there is only one customer identifier, and
72
+ * checks that there is only one customer or one
73
+ * customerKey in use. Both cannot be used.
74
+ *
75
+ * @param array $actionCounts
76
+ *
77
+ * @return bool
78
+ */
79
+ public function onlyOneCustomerIdentifier($actionCounts)
80
+ {
81
+ return (isset($actionCounts['customer']) && $actionCounts['customer'] == 1
82
+ && (!isset($actionCounts['customerKey'])
83
+ || isset($actionCounts['customerKey']) && $actionCounts['customerKey'] == 0))
84
+ || (isset($actionCounts['customerKey']) && $actionCounts['customerKey'] == 1
85
+ && (!isset($actionCounts['customer'])
86
+ || isset($actionCounts['customer']) && $actionCounts['customer'] == 0));
87
+ }
88
+
89
+ /**
90
+ * Ensures the data set is not empty.
91
+ *
92
+ * @param array $actionCounts
93
+ *
94
+ * @return bool
95
+ */
96
+ protected function dataNotEmpty($actionCounts)
97
+ {
98
+ return !empty($this->data);
99
+ }
100
+
101
+ /**
102
+ * @param string $key
103
+ * @param mixed $value
104
+ *
105
+ * @return HpsPayPlanCustomerServiceEditBuilder
106
+ */
107
+ public function update($key, $value)
108
+ {
109
+ $this->data[$key] = $value;
110
+ return $this;
111
+ }
112
+
113
+ /**
114
+ * @param string $key
115
+ *
116
+ * @return HpsPayPlanCustomerServiceEditBuilder
117
+ */
118
+ public function ignore($key)
119
+ {
120
+ return $this->update($key, null);
121
+ }
122
+ }
lib/SecureSubmit/src/Services/Fluent/Gateway/PayPlan/HpsPayPlanCustomerServiceGetBuilder.php ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @method HpsPayPlanCustomerServiceGetBuilder withData(array $data)
5
+ * @method HpsPayPlanCustomerServiceGetBuilder withCustomer(HpsPayPlanCustomer $customer)
6
+ * @method HpsPayPlanCustomerServiceGetBuilder withCustomerKey(string $customerKey)
7
+ */
8
+ class HpsPayPlanCustomerServiceGetBuilder extends HpsBuilderAbstract
9
+ {
10
+ /** @var array */
11
+ protected $data = array();
12
+
13
+ /** @var HpsPayPlanCustomer|null */
14
+ protected $customer = null;
15
+
16
+ /** @var string|null */
17
+ protected $customerKey = null;
18
+
19
+ /**
20
+ * Instatiates a new HpsPayPlanCustomerServiceGetBuilder
21
+ *
22
+ * @param HpsRestGatewayService $service
23
+ */
24
+ public function __construct(HpsRestGatewayService $service)
25
+ {
26
+ parent::__construct($service);
27
+ $this->setUpValidations();
28
+ }
29
+
30
+ /**
31
+ * Creates an get transaction through the HpsPayPlanCustomerService
32
+ */
33
+ public function execute()
34
+ {
35
+ parent::execute();
36
+
37
+ if ($this->customer != null) {
38
+ $this->customerKey = $this->customer->customerKey;
39
+ }
40
+
41
+ $service = new HpsPayPlanCustomerService($this->service->servicesConfig());
42
+
43
+ return $service->get($this->customerKey);
44
+ }
45
+
46
+ /**
47
+ * Setups up validations for building customer
48
+ * gets.
49
+ *
50
+ * @return null
51
+ */
52
+ private function setUpValidations()
53
+ {
54
+ $this
55
+ ->addValidation(array($this, 'onlyOneCustomerIdentifier'), 'HpsArgumentException', 'Get can only use one customer identifier ($customer or $customerKey)');
56
+ }
57
+
58
+ /**
59
+ * Ensures there is only one customer identifier, and
60
+ * checks that there is only one customer or one
61
+ * customerKey in use. Both cannot be used.
62
+ *
63
+ * @param array $actionCounts
64
+ *
65
+ * @return bool
66
+ */
67
+ public function onlyOneCustomerIdentifier($actionCounts)
68
+ {
69
+ return (isset($actionCounts['customer']) && $actionCounts['customer'] == 1
70
+ && (!isset($actionCounts['customerKey'])
71
+ || isset($actionCounts['customerKey']) && $actionCounts['customerKey'] == 0))
72
+ || (isset($actionCounts['customerKey']) && $actionCounts['customerKey'] == 1
73
+ && (!isset($actionCounts['customer'])
74
+ || isset($actionCounts['customer']) && $actionCounts['customer'] == 0));
75
+ }
76
+ }
lib/SecureSubmit/src/Services/Fluent/Gateway/PayPlan/HpsPayPlanCustomerServiceSearchBuilder.php ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @method HpsPayPlanCustomerServiceSearchBuilder withData(array $data)
5
+ */
6
+ class HpsPayPlanCustomerServiceSearchBuilder extends HpsBuilderAbstract
7
+ {
8
+ /** @var array */
9
+ protected $data = array();
10
+
11
+ /**
12
+ * Instatiates a new HpsPayPlanCustomerServiceSearchBuilder
13
+ *
14
+ * @param HpsRestGatewayService $service
15
+ */
16
+ public function __construct(HpsRestGatewayService $service)
17
+ {
18
+ parent::__construct($service);
19
+ $this->setUpValidations();
20
+ }
21
+
22
+ /**
23
+ * Creates an search transaction through the HpsPayPlanCustomerService
24
+ */
25
+ public function execute()
26
+ {
27
+ parent::execute();
28
+
29
+ $service = new HpsPayPlanCustomerService($this->service->servicesConfig());
30
+ $usableData = array_intersect_key(
31
+ $this->data,
32
+ array_flip(HpsPayPlanCustomer::getSearchableFields())
33
+ );
34
+
35
+ return $service->search($usableData);
36
+ }
37
+
38
+ /**
39
+ * Setups up validations for building customer
40
+ * searches.
41
+ *
42
+ * @return null
43
+ */
44
+ private function setUpValidations()
45
+ {
46
+ $this
47
+ ->addValidation(array($this, 'dataNotEmpty'), 'HpsArgumentException', 'Search needs a non-empty data set');
48
+ }
49
+
50
+ /**
51
+ * Ensures the data set is not empty.
52
+ *
53
+ * @param array $actionCounts
54
+ *
55
+ * @return bool
56
+ */
57
+ protected function dataNotEmpty($actionCounts)
58
+ {
59
+ return !empty($this->data);
60
+ }
61
+
62
+ /**
63
+ * @param string $key
64
+ * @param mixed $value
65
+ *
66
+ * @return HpsPayPlanCustomerServiceSearchBuilder
67
+ */
68
+ public function filter($key, $value)
69
+ {
70
+ $this->data[$key] = $value;
71
+ return $this;
72
+ }
73
+
74
+ /**
75
+ * @param string $key
76
+ *
77
+ * @return HpsPayPlanCustomerServiceSearchBuilder
78
+ */
79
+ public function ignore($key)
80
+ {
81
+ return $this->filter($key, null);
82
+ }
83
+ }
lib/SecureSubmit/src/Services/Fluent/Gateway/PayPlan/HpsPayPlanPaymentMethodServiceAddBuilder.php ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @method HpsPayPlanPaymentMethodServiceAddBuilder withData(array $data)
5
+ */
6
+ class HpsPayPlanPaymentMethodServiceAddBuilder extends HpsBuilderAbstract
7
+ {
8
+ /** @var array */
9
+ protected $data = array();
10
+
11
+ /**
12
+ * Instatiates a new HpsPayPlanPaymentMethodServiceAddBuilder
13
+ *
14
+ * @param HpsRestGatewayService $service
15
+ */
16
+ public function __construct(HpsRestGatewayService $service)
17
+ {
18
+ parent::__construct($service);
19
+ $this->setUpValidations();
20
+ }
21
+
22
+ /**
23
+ * Creates an add transaction through the HpsPayPlanPaymentMethodService
24
+ */
25
+ public function execute()
26
+ {
27
+ parent::execute();
28
+
29
+ $service = new HpsPayPlanPaymentMethodService($this->service->servicesConfig());
30
+ $obj = new HpsPayPlanPaymentMethod();
31
+
32
+ foreach ($this->data as $k => $v) {
33
+ $obj->$k = $v;
34
+ }
35
+ unset($usableData, $k, $v);
36
+
37
+ return $service->add($obj);
38
+ }
39
+
40
+ /**
41
+ * Setups up validations for building payment method
42
+ * adds.
43
+ *
44
+ * @return null
45
+ */
46
+ private function setUpValidations()
47
+ {
48
+ $this
49
+ ->addValidation(array($this, 'dataNotEmpty'), 'HpsArgumentException', 'Add needs a non-empty data set');
50
+ }
51
+
52
+ /**
53
+ * Ensures the data set is not empty.
54
+ *
55
+ * @param array $actionCounts
56
+ *
57
+ * @return bool
58
+ */
59
+ protected function dataNotEmpty($actionCounts)
60
+ {
61
+ return !empty($this->data);
62
+ }
63
+
64
+ /**
65
+ * @param string $key
66
+ * @param mixed $value
67
+ *
68
+ * @return HpsPayPlanPaymentMethodServiceAddBuilder
69
+ */
70
+ public function set($key, $value)
71
+ {
72
+ $this->data[$key] = $value;
73
+ return $this;
74
+ }
75
+ }
lib/SecureSubmit/src/Services/Fluent/Gateway/PayPlan/HpsPayPlanPaymentMethodServiceDeleteBuilder.php ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @method HpsPayPlanPaymentMethodServiceDeleteBuilder withData(array $data)
5
+ * @method HpsPayPlanPaymentMethodServiceDeleteBuilder withPaymentMethod(HpsPayPlanPaymentMethod $paymentMethod)
6
+ * @method HpsPayPlanPaymentMethodServiceDeleteBuilder withPaymentMethodKey(string $paymentMethodKey)
7
+ */
8
+ class HpsPayPlanPaymentMethodServiceDeleteBuilder extends HpsBuilderAbstract
9
+ {
10
+ /** @var array */
11
+ protected $data = array();
12
+
13
+ /** @var HpsPayPlanPaymentMethod|null */
14
+ protected $paymentMethod = null;
15
+
16
+ /** @var string|null */
17
+ protected $paymentMethodKey = null;
18
+
19
+ /**
20
+ * Instatiates a new HpsPayPlanPaymentMethodServiceDeleteBuilder
21
+ *
22
+ * @param HpsRestGatewayService $service
23
+ */
24
+ public function __construct(HpsRestGatewayService $service)
25
+ {
26
+ parent::__construct($service);
27
+ $this->setUpValidations();
28
+ }
29
+
30
+ /**
31
+ * Creates an delete transaction through the HpsPayPlanPaymentMethodService
32
+ */
33
+ public function execute()
34
+ {
35
+ parent::execute();
36
+
37
+ if ($this->paymentMethod != null) {
38
+ $this->paymentMethodKey = $this->paymentMethod->paymentMethodKey;
39
+ }
40
+
41
+ $service = new HpsPayPlanPaymentMethodService($this->service->servicesConfig());
42
+
43
+ return $service->delete($this->paymentMethodKey);
44
+ }
45
+
46
+ /**
47
+ * Setups up validations for building payment method
48
+ * deletes.
49
+ *
50
+ * @return null
51
+ */
52
+ private function setUpValidations()
53
+ {
54
+ $this
55
+ ->addValidation(array($this, 'onlyOnePaymentMethodIdentifier'), 'HpsArgumentException', 'Delete can only use one payment method identifier ($paymentMethod or $paymentMethodKey)');
56
+ }
57
+
58
+ /**
59
+ * Ensures there is only one payment method identifier, and
60
+ * checks that there is only one paymentMethod or one
61
+ * paymentMethodKey in use. Both cannot be used.
62
+ *
63
+ * @param array $actionCounts
64
+ *
65
+ * @return bool
66
+ */
67
+ public function onlyOnePaymentMethodIdentifier($actionCounts)
68
+ {
69
+ return (isset($actionCounts['paymentMethod']) && $actionCounts['paymentMethod'] == 1
70
+ && (!isset($actionCounts['paymentMethodKey'])
71
+ || isset($actionCounts['paymentMethodKey']) && $actionCounts['paymentMethodKey'] == 0))
72
+ || (isset($actionCounts['paymentMethodKey']) && $actionCounts['paymentMethodKey'] == 1
73
+ && (!isset($actionCounts['paymentMethod'])
74
+ || isset($actionCounts['paymentMethod']) && $actionCounts['paymentMethod'] == 0));
75
+ }
76
+ }
lib/SecureSubmit/src/Services/Fluent/Gateway/PayPlan/HpsPayPlanPaymentMethodServiceEditBuilder.php ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @method HpsPayPlanPaymentMethodServiceEditBuilder withData(array $data)
5
+ * @method HpsPayPlanPaymentMethodServiceEditBuilder withPaymentMethod(HpsPayPlanPaymentMethod $paymentMethod)
6
+ * @method HpsPayPlanPaymentMethodServiceEditBuilder withPaymentMethodKey(string $paymentMethodKey)
7
+ */
8
+ class HpsPayPlanPaymentMethodServiceEditBuilder extends HpsBuilderAbstract
9
+ {
10
+ /** @var array */
11
+ protected $data = array();
12
+
13
+ /** @var HpsPayPlanPaymentMethod|null */
14
+ protected $paymentMethod = null;
15
+
16
+ /** @var string|null */
17
+ protected $paymentMethodKey = null;
18
+
19
+ /**
20
+ * Instatiates a new HpsPayPlanPaymentMethodServiceEditBuilder
21
+ *
22
+ * @param HpsRestGatewayService $service
23
+ */
24
+ public function __construct(HpsRestGatewayService $service)
25
+ {
26
+ parent::__construct($service);
27
+ $this->setUpValidations();
28
+ }
29
+
30
+ /**
31
+ * Creates an edit transaction through the HpsPayPlanPaymentMethodService
32
+ */
33
+ public function execute()
34
+ {
35
+ parent::execute();
36
+
37
+ if ($this->paymentMethod != null) {
38
+ $this->paymentMethodKey = $this->paymentMethod->paymentMethodKey;
39
+ }
40
+
41
+ $service = new HpsPayPlanPaymentMethodService($this->service->servicesConfig());
42
+ $obj = new HpsPayPlanPaymentMethod();
43
+ $obj->paymentMethodKey = $this->paymentMethodKey;
44
+
45
+ $usableData = array_intersect_key(
46
+ $this->data,
47
+ array_flip(HpsPayPlanPaymentMethod::getEditableFields())
48
+ );
49
+ foreach ($usableData as $k => $v) {
50
+ $obj->$k = $v;
51
+ }
52
+ unset($usableData, $k, $v);
53
+
54
+ return $service->edit($obj);
55
+ }
56
+
57
+ /**
58
+ * Setups up validations for building payment method
59
+ * edits.
60
+ *
61
+ * @return null
62
+ */
63
+ private function setUpValidations()
64
+ {
65
+ $this
66
+ ->addValidation(array($this, 'onlyOnePaymentMethodIdentifier'), 'HpsArgumentException', 'Edit can only use one payment method identifier ($paymentMethod or $paymentMethodKey)')
67
+ ->addValidation(array($this, 'dataNotEmpty'), 'HpsArgumentException', 'Edit needs a non-empty data set');
68
+ }
69
+
70
+ /**
71
+ * Ensures there is only one payment method identifier, and
72
+ * checks that there is only one paymentMethod or one
73
+ * paymentMethodKey in use. Both cannot be used.
74
+ *
75
+ * @param array $actionCounts
76
+ *
77
+ * @return bool
78
+ */
79
+ public function onlyOnePaymentMethodIdentifier($actionCounts)
80
+ {
81
+ return (isset($actionCounts['paymentMethod']) && $actionCounts['paymentMethod'] == 1
82
+ && (!isset($actionCounts['paymentMethodKey'])
83
+ || isset($actionCounts['paymentMethodKey']) && $actionCounts['paymentMethodKey'] == 0))
84
+ || (isset($actionCounts['paymentMethodKey']) && $actionCounts['paymentMethodKey'] == 1
85
+ && (!isset($actionCounts['paymentMethod'])
86
+ || isset($actionCounts['paymentMethod']) && $actionCounts['paymentMethod'] == 0));
87
+ }
88
+
89
+ /**
90
+ * Ensures the data set is not empty.
91
+ *
92
+ * @param array $actionCounts
93
+ *
94
+ * @return bool
95
+ */
96
+ protected function dataNotEmpty($actionCounts)
97
+ {
98
+ return !empty($this->data);
99
+ }
100
+
101
+ /**
102
+ * @param string $key
103
+ * @param mixed $value
104
+ *
105
+ * @return HpsPayPlanPaymentMethodServiceEditBuilder
106
+ */
107
+ public function update($key, $value)
108
+ {
109
+ $this->data[$key] = $value;
110
+ return $this;
111
+ }
112
+
113
+ /**
114
+ * @param string $key
115
+ *
116
+ * @return HpsPayPlanPaymentMethodServiceEditBuilder
117
+ */
118
+ public function ignore($key)
119
+ {
120
+ return $this->update($key, null);
121
+ }
122
+ }
lib/SecureSubmit/src/Services/Fluent/Gateway/PayPlan/HpsPayPlanPaymentMethodServiceGetBuilder.php ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @method HpsPayPlanPaymentMethodServiceGetBuilder withData(array $data)
5
+ * @method HpsPayPlanPaymentMethodServiceGetBuilder withPaymentMethod(HpsPayPlanPaymentMethod $paymentMethod)
6
+ * @method HpsPayPlanPaymentMethodServiceGetBuilder withPaymentMethodKey(string $paymentMethodKey)
7
+ */
8
+ class HpsPayPlanPaymentMethodServiceGetBuilder extends HpsBuilderAbstract
9
+ {
10
+ /** @var array */
11
+ protected $data = array();
12
+
13
+ /** @var HpsPayPlanPaymentMethod|null */
14
+ protected $paymentMethod = null;
15
+
16
+ /** @var string|null */
17
+ protected $paymentMethodKey = null;
18
+
19
+ /**
20
+ * Instatiates a new HpsPayPlanPaymentMethodServiceGetBuilder
21
+ *
22
+ * @param HpsRestGatewayService $service
23
+ */
24
+ public function __construct(HpsRestGatewayService $service)
25
+ {
26
+ parent::__construct($service);
27
+ $this->setUpValidations();
28
+ }
29
+
30
+ /**
31
+ * Creates an get transaction through the HpsPayPlanPaymentMethodService
32
+ */
33
+ public function execute()
34
+ {
35
+ parent::execute();
36
+
37
+ if ($this->paymentMethod != null) {
38
+ $this->paymentMethodKey = $this->paymentMethod->paymentMethodKey;
39
+ }
40
+
41
+ $service = new HpsPayPlanPaymentMethodService($this->service->servicesConfig());
42
+
43
+ return $service->get($this->paymentMethodKey);
44
+ }
45
+
46
+ /**
47
+ * Setups up validations for building payment method
48
+ * gets.
49
+ *
50
+ * @return null
51
+ */
52
+ private function setUpValidations()
53
+ {
54
+ $this
55
+ ->addValidation(array($this, 'onlyOnePaymentMethodIdentifier'), 'HpsArgumentException', 'Get can only use one payment method identifier ($paymentMethod or $paymentMethodKey)');
56
+ }
57
+
58
+ /**
59
+ * Ensures there is only one payment method identifier, and
60
+ * checks that there is only one paymentMethod or one
61
+ * paymentMethodKey in use. Both cannot be used.
62
+ *
63
+ * @param array $actionCounts
64
+ *
65
+ * @return bool
66
+ */
67
+ public function onlyOnePaymentMethodIdentifier($actionCounts)
68
+ {
69
+ return (isset($actionCounts['paymentMethod']) && $actionCounts['paymentMethod'] == 1
70
+ && (!isset($actionCounts['paymentMethodKey'])
71
+ || isset($actionCounts['paymentMethodKey']) && $actionCounts['paymentMethodKey'] == 0))
72
+ || (isset($actionCounts['paymentMethodKey']) && $actionCounts['paymentMethodKey'] == 1
73
+ && (!isset($actionCounts['paymentMethod'])
74
+ || isset($actionCounts['paymentMethod']) && $actionCounts['paymentMethod'] == 0));
75
+ }
76
+ }
lib/SecureSubmit/src/Services/Fluent/Gateway/PayPlan/HpsPayPlanPaymentMethodServiceSearchBuilder.php ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @method HpsPayPlanPaymentMethodServiceSearchBuilder withData(array $data)
5
+ */
6
+ class HpsPayPlanPaymentMethodServiceSearchBuilder extends HpsBuilderAbstract
7
+ {
8
+ /** @var array */
9
+ protected $data = array();
10
+
11
+ /**
12
+ * Instatiates a new HpsPayPlanPaymentMethodServiceSearchBuilder
13
+ *
14
+ * @param HpsRestGatewayService $service
15
+ */
16
+ public function __construct(HpsRestGatewayService $service)
17
+ {
18
+ parent::__construct($service);
19
+ $this->setUpValidations();
20
+ }
21
+
22
+ /**
23
+ * Creates an search transaction through the HpsPayPlanPaymentMethodService
24
+ */
25
+ public function execute()
26
+ {
27
+ parent::execute();
28
+
29
+ $service = new HpsPayPlanPaymentMethodService($this->service->servicesConfig());
30
+ $usableData = array_intersect_key(
31
+ $this->data,
32
+ array_flip(HpsPayPlanPaymentMethod::getSearchableFields())
33
+ );
34
+
35
+ return $service->search($usableData);
36
+ }
37
+
38
+ /**
39
+ * Setups up validations for building payment method
40
+ * searches.
41
+ *
42
+ * @return null
43
+ */
44
+ private function setUpValidations()
45
+ {
46
+ $this
47
+ ->addValidation(array($this, 'dataNotEmpty'), 'HpsArgumentException', 'Search needs a non-empty data set');
48
+ }
49
+
50
+ /**
51
+ * Ensures the data set is not empty.
52
+ *
53
+ * @param array $actionCounts
54
+ *
55
+ * @return bool
56
+ */
57
+ protected function dataNotEmpty($actionCounts)
58
+ {
59
+ return !empty($this->data);
60
+ }
61
+
62
+ /**
63
+ * @param string $key
64
+ * @param mixed $value
65
+ *
66
+ * @return HpsPayPlanPaymentMethodServiceSearchBuilder
67
+ */
68
+ public function filter($key, $value)
69
+ {
70
+ $this->data[$key] = $value;
71
+ return $this;
72
+ }
73
+
74
+ /**
75
+ * @param string $key
76
+ *
77
+ * @return HpsPayPlanPaymentMethodServiceSearchBuilder
78
+ */
79
+ public function ignore($key)
80
+ {
81
+ return $this->filter($key, null);
82
+ }
83
+ }
lib/SecureSubmit/src/Services/Fluent/Gateway/PayPlan/HpsPayPlanScheduleServiceAddBuilder.php ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @method HpsPayPlanScheduleServiceAddBuilder withData(array $data)
5
+ */
6
+ class HpsPayPlanScheduleServiceAddBuilder extends HpsBuilderAbstract
7
+ {
8
+ /** @var array */
9
+ protected $data = array();
10
+
11
+ /**
12
+ * Instatiates a new HpsPayPlanScheduleServiceAddBuilder
13
+ *
14
+ * @param HpsRestGatewayService $service
15
+ */
16
+ public function __construct(HpsRestGatewayService $service)
17
+ {
18
+ parent::__construct($service);
19
+ $this->setUpValidations();
20
+ }
21
+
22
+ /**
23
+ * Creates an add transaction through the HpsPayPlanScheduleService
24
+ */
25
+ public function execute()
26
+ {
27
+ parent::execute();
28
+
29
+ $service = new HpsPayPlanScheduleService($this->service->servicesConfig());
30
+ $obj = new HpsPayPlanSchedule();
31
+
32
+ foreach ($this->data as $k => $v) {
33
+ $obj->$k = $v;
34
+ }
35
+ unset($usableData, $k, $v);
36
+
37
+ return $service->add($obj);
38
+ }
39
+
40
+ /**
41
+ * Setups up validations for building payment schedule
42
+ * adds.
43
+ *
44
+ * @return null
45
+ */
46
+ private function setUpValidations()
47
+ {
48
+ $this
49
+ ->addValidation(array($this, 'dataNotEmpty'), 'HpsArgumentException', 'Add needs a non-empty data set');
50
+ }
51
+
52
+ /**
53
+ * Ensures the data set is not empty.
54
+ *
55
+ * @param array $actionCounts
56
+ *
57
+ * @return bool
58
+ */
59
+ protected function dataNotEmpty($actionCounts)
60
+ {
61
+ return !empty($this->data);
62
+ }
63
+
64
+ /**
65
+ * @param string $key
66
+ * @param mixed $value
67
+ *
68
+ * @return HpsPayPlanScheduleServiceAddBuilder
69
+ */
70
+ public function set($key, $value)
71
+ {
72
+ $this->data[$key] = $value;
73
+ return $this;
74
+ }
75
+ }
lib/SecureSubmit/src/Services/Fluent/Gateway/PayPlan/HpsPayPlanScheduleServiceDeleteBuilder.php ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @method HpsPayPlanScheduleServiceDeleteBuilder withData(array $data)
5
+ * @method HpsPayPlanScheduleServiceDeleteBuilder withSchedule(HpsPayPlanSchedule $paymentSchedule)
6
+ * @method HpsPayPlanScheduleServiceDeleteBuilder withScheduleKey(string $paymentScheduleKey)
7
+ */
8
+ class HpsPayPlanScheduleServiceDeleteBuilder extends HpsBuilderAbstract
9
+ {
10
+ /** @var array */
11
+ protected $data = array();
12
+
13
+ /** @var HpsPayPlanSchedule|null */
14
+ protected $paymentSchedule = null;
15
+
16
+ /** @var string|null */
17
+ protected $paymentScheduleKey = null;
18
+
19
+ /**
20
+ * Instatiates a new HpsPayPlanScheduleServiceDeleteBuilder
21
+ *
22
+ * @param HpsRestGatewayService $service
23
+ */
24
+ public function __construct(HpsRestGatewayService $service)
25
+ {
26
+ parent::__construct($service);
27
+ $this->setUpValidations();
28
+ }
29
+
30
+ /**
31
+ * Creates an delete transaction through the HpsPayPlanScheduleService
32
+ */
33
+ public function execute()
34
+ {
35
+ parent::execute();
36
+
37
+ if ($this->paymentSchedule != null) {
38
+ $this->paymentScheduleKey = $this->paymentSchedule->paymentScheduleKey;
39
+ }
40
+
41
+ $service = new HpsPayPlanScheduleService($this->service->servicesConfig());
42
+
43
+ return $service->delete($this->paymentScheduleKey);
44
+ }
45
+
46
+ /**
47
+ * Setups up validations for building payment schedule
48
+ * deletes.
49
+ *
50
+ * @return null
51
+ */
52
+ private function setUpValidations()
53
+ {
54
+ $this
55
+ ->addValidation(array($this, 'onlyOneScheduleIdentifier'), 'HpsArgumentException', 'Delete can only use one payment schedule identifier ($paymentSchedule or $paymentScheduleKey)');
56
+ }
57
+
58
+ /**
59
+ * Ensures there is only one payment schedule identifier, and
60
+ * checks that there is only one paymentSchedule or one
61
+ * paymentScheduleKey in use. Both cannot be used.
62
+ *
63
+ * @param array $actionCounts
64
+ *
65
+ * @return bool
66
+ */
67
+ public function onlyOneScheduleIdentifier($actionCounts)
68
+ {
69
+ return (isset($actionCounts['paymentSchedule']) && $actionCounts['paymentSchedule'] == 1
70
+ && (!isset($actionCounts['paymentScheduleKey'])
71
+ || isset($actionCounts['paymentScheduleKey']) && $actionCounts['paymentScheduleKey'] == 0))
72
+ || (isset($actionCounts['paymentScheduleKey']) && $actionCounts['paymentScheduleKey'] == 1
73
+ && (!isset($actionCounts['paymentSchedule'])
74
+ || isset($actionCounts['paymentSchedule']) && $actionCounts['paymentSchedule'] == 0));
75
+ }
76
+ }
lib/SecureSubmit/src/Services/Fluent/Gateway/PayPlan/HpsPayPlanScheduleServiceEditBuilder.php ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @method HpsPayPlanScheduleServiceEditBuilder withData(array $data)
5
+ * @method HpsPayPlanScheduleServiceEditBuilder withSchedule(HpsPayPlanSchedule $paymentSchedule)
6
+ * @method HpsPayPlanScheduleServiceEditBuilder withScheduleKey(string $paymentScheduleKey)
7
+ */
8
+ class HpsPayPlanScheduleServiceEditBuilder extends HpsBuilderAbstract
9
+ {
10
+ /** @var array */
11
+ protected $data = array();
12
+
13
+ /** @var HpsPayPlanSchedule|null */
14
+ protected $paymentSchedule = null;
15
+
16
+ /** @var string|null */
17
+ protected $paymentScheduleKey = null;
18
+
19
+ /**
20
+ * Instatiates a new HpsPayPlanScheduleServiceEditBuilder
21
+ *
22
+ * @param HpsRestGatewayService $service
23
+ */
24
+ public function __construct(HpsRestGatewayService $service)
25
+ {
26
+ parent::__construct($service);
27
+ $this->setUpValidations();
28
+ }
29
+
30
+ /**
31
+ * Creates an edit transaction through the HpsPayPlanScheduleService
32
+ */
33
+ public function execute()
34
+ {
35
+ parent::execute();
36
+
37
+ if ($this->paymentSchedule != null) {
38
+ $this->paymentScheduleKey = $this->paymentSchedule->paymentScheduleKey;
39
+ }
40
+
41
+ $service = new HpsPayPlanScheduleService($this->service->servicesConfig());
42
+ $obj = new HpsPayPlanSchedule();
43
+ $obj->paymentScheduleKey = $this->paymentScheduleKey;
44
+
45
+ $usableData = array_intersect_key(
46
+ $this->data,
47
+ array_flip(HpsPayPlanSchedule::getEditableFields())
48
+ );
49
+ foreach ($usableData as $k => $v) {
50
+ $obj->$k = $v;
51
+ }
52
+ unset($usableData, $k, $v);
53
+
54
+ return $service->edit($obj);
55
+ }
56
+
57
+ /**
58
+ * Setups up validations for building payment schedule
59
+ * edits.
60
+ *
61
+ * @return null
62
+ */
63
+ private function setUpValidations()
64
+ {
65
+ $this
66
+ ->addValidation(array($this, 'onlyOneScheduleIdentifier'), 'HpsArgumentException', 'Edit can only use one payment schedule identifier ($paymentSchedule or $paymentScheduleKey)')
67
+ ->addValidation(array($this, 'dataNotEmpty'), 'HpsArgumentException', 'Edit needs a non-empty data set');
68
+ }
69
+
70
+ /**
71
+ * Ensures there is only one payment schedule identifier, and
72
+ * checks that there is only one paymentSchedule or one
73
+ * paymentScheduleKey in use. Both cannot be used.
74
+ *
75
+ * @param array $actionCounts
76
+ *
77
+ * @return bool
78
+ */
79
+ public function onlyOneScheduleIdentifier($actionCounts)
80
+ {
81
+ return (isset($actionCounts['paymentSchedule']) && $actionCounts['paymentSchedule'] == 1
82
+ && (!isset($actionCounts['paymentScheduleKey'])
83
+ || isset($actionCounts['paymentScheduleKey']) && $actionCounts['paymentScheduleKey'] == 0))
84
+ || (isset($actionCounts['paymentScheduleKey']) && $actionCounts['paymentScheduleKey'] == 1
85
+ && (!isset($actionCounts['paymentSchedule'])
86
+ || isset($actionCounts['paymentSchedule']) && $actionCounts['paymentSchedule'] == 0));
87
+ }
88
+
89
+ /**
90
+ * Ensures the data set is not empty.
91
+ *
92
+ * @param array $actionCounts
93
+ *
94
+ * @return bool
95
+ */
96
+ protected function dataNotEmpty($actionCounts)
97
+ {
98
+ return !empty($this->data);
99
+ }
100
+
101
+ /**
102
+ * @param string $key
103
+ * @param mixed $value
104
+ *
105
+ * @return HpsPayPlanScheduleServiceEditBuilder
106
+ */
107
+ public function update($key, $value)
108
+ {
109
+ $this->data[$key] = $value;
110
+ return $this;
111
+ }
112
+
113
+ /**
114
+ * @param string $key
115
+ *
116
+ * @return HpsPayPlanScheduleServiceEditBuilder
117
+ */
118
+ public function ignore($key)
119
+ {
120
+ return $this->update($key, null);
121
+ }
122
+ }
lib/SecureSubmit/src/Services/Fluent/Gateway/PayPlan/HpsPayPlanScheduleServiceGetBuilder.php ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @method HpsPayPlanScheduleServiceGetBuilder withData(array $data)
5
+ * @method HpsPayPlanScheduleServiceGetBuilder withSchedule(HpsPayPlanSchedule $paymentSchedule)
6
+ * @method HpsPayPlanScheduleServiceGetBuilder withScheduleKey(string $paymentScheduleKey)
7
+ */
8
+ class HpsPayPlanScheduleServiceGetBuilder extends HpsBuilderAbstract
9
+ {
10
+ /** @var array */
11
+ protected $data = array();
12
+
13
+ /** @var HpsPayPlanSchedule|null */
14
+ protected $paymentSchedule = null;
15
+
16
+ /** @var string|null */
17
+ protected $paymentScheduleKey = null;
18
+
19
+ /**
20
+ * Instatiates a new HpsPayPlanScheduleServiceGetBuilder
21
+ *
22
+ * @param HpsRestGatewayService $service
23
+ */
24
+ public function __construct(HpsRestGatewayService $service)
25
+ {
26
+ parent::__construct($service);
27
+ $this->setUpValidations();
28
+ }
29
+
30
+ /**
31
+ * Creates an get transaction through the HpsPayPlanScheduleService
32
+ */
33
+ public function execute()
34
+ {
35
+ parent::execute();
36
+
37
+ if ($this->paymentSchedule != null) {
38
+ $this->paymentScheduleKey = $this->paymentSchedule->paymentScheduleKey;
39
+ }
40
+
41
+ $service = new HpsPayPlanScheduleService($this->service->servicesConfig());
42
+
43
+ return $service->get($this->paymentScheduleKey);
44
+ }
45
+
46
+ /**
47
+ * Setups up validations for building payment schedule
48
+ * gets.
49
+ *
50
+ * @return null
51
+ */
52
+ private function setUpValidations()
53
+ {
54
+ $this
55
+ ->addValidation(array($this, 'onlyOneScheduleIdentifier'), 'HpsArgumentException', 'Get can only use one payment schedule identifier ($paymentSchedule or $paymentScheduleKey)');
56
+ }
57
+
58
+ /**
59
+ * Ensures there is only one payment schedule identifier, and
60
+ * checks that there is only one paymentSchedule or one
61
+ * paymentScheduleKey in use. Both cannot be used.
62
+ *
63
+ * @param array $actionCounts
64
+ *
65
+ * @return bool
66
+ */
67
+ public function onlyOneScheduleIdentifier($actionCounts)
68
+ {
69
+ return (isset($actionCounts['paymentSchedule']) && $actionCounts['paymentSchedule'] == 1
70
+ && (!isset($actionCounts['paymentScheduleKey'])
71
+ || isset($actionCounts['paymentScheduleKey']) && $actionCounts['paymentScheduleKey'] == 0))
72
+ || (isset($actionCounts['paymentScheduleKey']) && $actionCounts['paymentScheduleKey'] == 1
73
+ && (!isset($actionCounts['paymentSchedule'])
74
+ || isset($actionCounts['paymentSchedule']) && $actionCounts['paymentSchedule'] == 0));
75
+ }
76
+ }
lib/SecureSubmit/src/Services/Fluent/Gateway/PayPlan/HpsPayPlanScheduleServiceSearchBuilder.php ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @method HpsPayPlanScheduleServiceSearchBuilder withData(array $data)
5
+ */
6
+ class HpsPayPlanScheduleServiceSearchBuilder extends HpsBuilderAbstract
7
+ {
8
+ /** @var array */
9
+ protected $data = array();
10
+
11
+ /**
12
+ * Instatiates a new HpsPayPlanScheduleServiceSearchBuilder
13
+ *
14
+ * @param HpsRestGatewayService $service
15
+ */
16
+ public function __construct(HpsRestGatewayService $service)
17
+ {
18
+ parent::__construct($service);
19
+ $this->setUpValidations();
20
+ }
21
+
22
+ /**
23
+ * Creates an search transaction through the HpsPayPlanScheduleService
24
+ */
25
+ public function execute()
26
+ {
27
+ parent::execute();
28
+
29
+ $service = new HpsPayPlanScheduleService($this->service->servicesConfig());
30
+ $usableData = array_intersect_key(
31
+ $this->data,
32
+ array_flip(HpsPayPlanSchedule::getSearchableFields())
33
+ );
34
+
35
+ return $service->search($usableData);
36
+ }
37
+
38
+ /**
39
+ * Setups up validations for building payment schedule
40
+ * searches.
41
+ *
42
+ * @return null
43
+ */
44
+ private function setUpValidations()
45
+ {
46
+ $this
47
+ ->addValidation(array($this, 'dataNotEmpty'), 'HpsArgumentException', 'Search needs a non-empty data set');
48
+ }
49
+
50
+ /**
51
+ * Ensures the data set is not empty.
52
+ *
53
+ * @param array $actionCounts
54
+ *
55
+ * @return bool
56
+ */
57
+ protected function dataNotEmpty($actionCounts)
58
+ {
59
+ return !empty($this->data);
60
+ }
61
+
62
+ /**
63
+ * @param string $key
64
+ * @param mixed $value
65
+ *
66
+ * @return HpsPayPlanScheduleServiceSearchBuilder
67
+ */
68
+ public function filter($key, $value)
69
+ {
70
+ $this->data[$key] = $value;
71
+ return $this;
72
+ }
73
+
74
+ /**
75
+ * @param string $key
76
+ *
77
+ * @return HpsPayPlanScheduleServiceSearchBuilder
78
+ */
79
+ public function ignore($key)
80
+ {
81
+ return $this->filter($key, null);
82
+ }
83
+ }
lib/SecureSubmit/src/Services/Gateway/AltPayment/HpsAltPaymentService.php ADDED
@@ -0,0 +1,341 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsAltPaymentService extends HpsSoapGatewayService
4
+ {
5
+ /** @var string|null */
6
+ protected $_transactionType = null;
7
+
8
+ public function authorize($sessionId, $amount, $currency, HpsBuyerData $buyer, HpsPaymentData $payment, HpsShippingInfo $shippingAddress = null, $lineItems = null)
9
+ {
10
+ HpsInputValidation::checkAmount($amount);
11
+ HpsInputValidation::checkCurrency($currency);
12
+
13
+ $xml = new DOMDocument();
14
+ $transaction = $xml->createElement('hps:Transaction');
15
+ $auth = $xml->createElement('hps:AltPaymentAuth');
16
+
17
+ $auth->appendChild($xml->createElement('hps:TransactionType', $this->_transactionType));
18
+ $auth->appendChild($xml->createElement('hps:SessionId', $sessionId));
19
+ $auth->appendChild($this->hydrateBuyerData($buyer, $xml));
20
+ $auth->appendChild($xml->createElement('hps:Amt', $amount));
21
+ $auth->appendChild($this->hydratePaymentData($payment, $xml));
22
+ if ($shippingAddress != null) {
23
+ $auth->appendChild($this->hydrateShippingData($shippingAddress, $xml));
24
+ }
25
+ if ($lineItems != null) {
26
+ $auth->appendChild($this->hydrateLineItems($lineItems, $xml));
27
+ }
28
+
29
+ $transaction->appendChild($auth);
30
+ return $this->_submitTransaction($transaction, 'AltPaymentAuth');
31
+ }
32
+
33
+ public function capture($transactionId, $amount)
34
+ {
35
+ HpsInputValidation::checkAmount($amount);
36
+
37
+ $xml = new DOMDocument();
38
+ $transaction = $xml->createElement('hps:Transaction');
39
+ $capture = $xml->createElement('hps:AltPaymentAddToBatch');
40
+
41
+ $capture->appendChild($xml->createElement('hps:TransactionType', $this->_transactionType));
42
+ $capture->appendChild($xml->createElement('hps:GatewayTxnId', $transactionId));
43
+ $capture->appendChild($xml->createElement('hps:Amt', $amount));
44
+
45
+ $payment = $xml->createElement('hps:Payment');
46
+ $nvp = $xml->createElement('hps:NameValuePair');
47
+ $nvp->appendChild($xml->createElement('hps:Name', 'FullyCapturedFlag'));
48
+ $nvp->appendChild($xml->createElement('hps:Value', 'true'));
49
+ $payment->appendChild($nvp);
50
+
51
+ $capture->appendChild($payment);
52
+ $transaction->appendChild($capture);
53
+ return $this->_submitTransaction($transaction, 'AltPaymentAddToBatch');
54
+ }
55
+
56
+ public function createSession($amount, $currency, HpsBuyerData $buyer, HpsPaymentData $payment, HpsShippingInfo $shippingAddress = null, $lineItems = null)
57
+ {
58
+ HpsInputValidation::checkAmount($amount);
59
+ HpsInputValidation::checkCurrency($currency);
60
+
61
+ $xml = new DOMDocument();
62
+ $transaction = $xml->createElement('hps:Transaction');
63
+ $createSession = $xml->createElement('hps:AltPaymentCreateSession');
64
+
65
+ $createSession->appendChild($xml->createElement('hps:TransactionType', $this->_transactionType));
66
+ $createSession->appendChild($this->hydrateBuyerData($buyer, $xml));
67
+ $createSession->appendChild($xml->createElement('hps:Amt', $amount));
68
+ $createSession->appendChild($this->hydratePaymentData($payment, $xml));
69
+ if ($shippingAddress != null) {
70
+ $createSession->appendChild($this->hydrateShippingData($shippingAddress, $xml));
71
+ }
72
+ if ($lineItems != null) {
73
+ $createSession->appendChild($this->hydrateLineItems($lineItems, $xml));
74
+ }
75
+
76
+ $transaction->appendChild($createSession);
77
+ return $this->_submitTransaction($transaction, 'AltPaymentCreateSession');
78
+ }
79
+
80
+ public function refund($transactionId, $isPartial = false, $partialAmount = null)
81
+ {
82
+ $xml = new DOMDocument();
83
+ $transaction = $xml->createElement('hps:Transaction');
84
+ $return = $xml->createElement('hps:AltPaymentReturn');
85
+
86
+ $return->appendChild($xml->createElement('hps:TransactionType', $this->_transactionType));
87
+ $return->appendChild($xml->createElement('hps:GatewayTxnId', $transactionId));
88
+
89
+ if ($isPartial) {
90
+ $return->appendChild($xml->createElement('hps:Amt', $partialAmount));
91
+ }
92
+
93
+ $payment = $xml->createElement('hps:Return');
94
+ $nvp = $xml->createElement('hps:NameValuePair');
95
+ $nvp->appendChild($xml->createElement('hps:Name', 'ReturnType'));
96
+ $nvp->appendChild($xml->createElement('hps:Value', $isPartial ? 'partial' : 'full'));
97
+ $payment->appendChild($nvp);
98
+
99
+ $return->appendChild($payment);
100
+ $transaction->appendChild($return);
101
+ return $this->_submitTransaction($transaction, 'AltPaymentReturn');
102
+ }
103
+
104
+ public function sale($sessionId, $amount, $currency, HpsBuyerData $buyer, HpsPaymentData $payment, HpsShippingInfo $shippingAddress = null, $lineItems = null)
105
+ {
106
+ HpsInputValidation::checkAmount($amount);
107
+ HpsInputValidation::checkCurrency($currency);
108
+
109
+ $xml = new DOMDocument();
110
+ $transaction = $xml->createElement('hps:Transaction');
111
+ $sale = $xml->createElement('hps:AltPaymentSale');
112
+
113
+ $sale->appendChild($xml->createElement('hps:TransactionType', $this->_transactionType));
114
+ $sale->appendChild($xml->createElement('hps:SessionId', $sessionId));
115
+ $sale->appendChild($this->hydrateBuyerData($buyer, $xml));
116
+ $sale->appendChild($xml->createElement('hps:Amt', $amount));
117
+ $sale->appendChild($this->hydratePaymentData($payment, $xml));
118
+ if ($shippingAddress != null) {
119
+ $sale->appendChild($this->hydrateShippingData($shippingAddress, $xml));
120
+ }
121
+ if ($lineItems != null) {
122
+ $sale->appendChild($this->hydrateLineItems($lineItems, $xml));
123
+ }
124
+
125
+ $transaction->appendChild($sale);
126
+ return $this->_submitTransaction($transaction, 'AltPaymentSale');
127
+ }
128
+
129
+ public function void($transactionId)
130
+ {
131
+ $xml = new DOMDocument();
132
+ $transaction = $xml->createElement('hps:Transaction');
133
+ $void = $xml->createElement('hps:AltPaymentVoid');
134
+
135
+ $void->appendChild($xml->createElement('hps:TransactionType', $this->_transactionType));
136
+ $void->appendChild($xml->createElement('hps:GatewayTxnId', $transactionId));
137
+
138
+ $transaction->appendChild($void);
139
+ return $this->_submitTransaction($transaction, 'AltPaymentVoid');
140
+ }
141
+
142
+ public function sessionInfo($sessionId)
143
+ {
144
+ $xml = new DOMDocument();
145
+ $transaction = $xml->createElement('hps:Transaction');
146
+ $info = $xml->createElement('hps:AltPaymentSessionInfo');
147
+
148
+ $info->appendChild($xml->createElement('hps:TransactionType', $this->_transactionType));
149
+ $info->appendChild($xml->createElement('hps:SessionId', $sessionId));
150
+
151
+ $transaction->appendChild($info);
152
+ return $this->_submitTransaction($transaction, 'AltPaymentSessionInfo');
153
+ }
154
+
155
+ public function setTransactionType($type)
156
+ {
157
+ $this->_transactionType = $type;
158
+ }
159
+
160
+ protected function hydrateBuyerData(HpsBuyerData $buyer, DOMDocument $xml)
161
+ {
162
+ $data = $xml->createElement('hps:Buyer');
163
+ if (isset($buyer->returnUrl)) {
164
+ $data->appendChild($this->hydrateNameValuePair('ReturnUrl', $buyer->returnUrl, $xml));
165
+ }
166
+ if (isset($buyer->cancelUrl)) {
167
+ $data->appendChild($this->hydrateNameValuePair('CancelUrl', $buyer->cancelUrl, $xml));
168
+ }
169
+ if (isset($buyer->emailAddress)) {
170
+ $data->appendChild($this->hydrateNameValuePair('EmailAddress', $buyer->emailAddress, $xml));
171
+ }
172
+ if (isset($buyer->payerId)) {
173
+ $data->appendChild($this->hydrateNameValuePair('BuyerId', $buyer->payerId, $xml));
174
+ }
175
+ if (isset($buyer->credit) && $buyer->credit != false) {
176
+ $data->appendChild($this->hydrateNameValuePair('FundingSource', 'credit', $xml));
177
+ }
178
+ return $data;
179
+ }
180
+
181
+ protected function hydrateLineItems($items, DOMDocument $xml)
182
+ {
183
+ $lineItems = $xml->createElement('hps:LineItem');
184
+
185
+ foreach ($items as $item) {
186
+ if (!$item instanceof HpsLineItem) {
187
+ continue;
188
+ }
189
+ $detail = $xml->createElement('hps:Detail');
190
+ if (isset($item->name)) {
191
+ $detail->appendChild($this->hydrateNameValuePair('Name', $item->name, $xml));
192
+ }
193
+ if (isset($item->description)) {
194
+ $detail->appendChild($this->hydrateNameValuePair('Description', $item->description, $xml));
195
+ }
196
+ if (isset($item->number)) {
197
+ $detail->appendChild($this->hydrateNameValuePair('Number', $item->number, $xml));
198
+ }
199
+ if (isset($item->amount)) {
200
+ $detail->appendChild($this->hydrateNameValuePair('Amount', $item->amount, $xml));
201
+ }
202
+ if (isset($item->quantity)) {
203
+ $detail->appendChild($this->hydrateNameValuePair('Quantity', $item->quantity, $xml));
204
+ }
205
+ if (isset($item->taxAmount)) {
206
+ $detail->appendChild($this->hydrateNameValuePair('TaxAmount', $item->taxAmount, $xml));
207
+ }
208
+ $lineItems->appendChild($detail);
209
+ }
210
+ return $lineItems;
211
+ }
212
+
213
+ protected function hydrateNameValuePair($name, $value, DOMDocument $xml)
214
+ {
215
+ $nvp = $xml->createElement('hps:NameValuePair');
216
+ $nvp->appendChild($xml->createElement('hps:Name', $name));
217
+ $nvp->appendChild($xml->createElement('hps:Value', $value));
218
+ return $nvp;
219
+ }
220
+
221
+ protected function hydratePaymentData(HpsPaymentData $payment, DOMDocument $xml)
222
+ {
223
+ $data = $xml->createElement('hps:Payment');
224
+ $data->appendChild($this->hydrateNameValuePair('ItemAmount', $payment->subtotal, $xml));
225
+ if (isset($payment->shippingAmount)) {
226
+ $data->appendChild($this->hydrateNameValuePair('ShippingAmount', $payment->shippingAmount, $xml));
227
+ }
228
+ if (isset($payment->taxAmount)) {
229
+ $data->appendChild($this->hydrateNameValuePair('TaxAmount', $payment->taxAmount, $xml));
230
+ }
231
+ if (isset($payment->paymentType)) {
232
+ $data->appendChild($this->hydrateNameValuePair('PaymentType', $payment->paymentType, $xml));
233
+ }
234
+ if (isset($payment->invoiceNumber)) {
235
+ $data->appendChild($this->hydrateNameValuePair('InvoiceNbr', $payment->invoiceNumber, $xml));
236
+ }
237
+ return $data;
238
+ }
239
+
240
+ protected function hydrateShippingData(HpsShippingInfo $info, DOMDocument $xml)
241
+ {
242
+ $shipping = $xml->createElement('hps:Shipping');
243
+ $address = $xml->createElement('hps:Address');
244
+ $address->appendChild($this->hydrateNameValuePair('AllowAddressOverride', 'false', $xml));
245
+ $address->appendChild($this->hydrateNameValuePair('ShipName', $info->name, $xml));
246
+ $address->appendChild($this->hydrateNameValuePair('ShipAddress', $info->address->address, $xml));
247
+ $address->appendChild($this->hydrateNameValuePair('ShipCity', $info->address->city, $xml));
248
+ $address->appendChild($this->hydrateNameValuePair('ShipState', $info->address->state, $xml));
249
+ $address->appendChild($this->hydrateNameValuePair('ShipZip', $info->address->zip, $xml));
250
+ $address->appendChild($this->hydrateNameValuePair('ShipCountryCode', $info->address->country, $xml));
251
+ $shipping->appendChild($address);
252
+ return $shipping;
253
+ }
254
+
255
+ private function _processGatewayResponse($response, $expectedType)
256
+ {
257
+ $gatewayRspCode = (isset($response->Header->GatewayRspCode) ? $response->Header->GatewayRspCode : null);
258
+ $transactionId = (isset($response->Header->GatewayTxnId) ? $response->Header->GatewayTxnId : null);
259
+
260
+ if ($gatewayRspCode == '0') {
261
+ return;
262
+ }
263
+
264
+ if ($gatewayRspCode == '30') {
265
+ try {
266
+ $this->reverse($transactionId, $this->_amount, $this->_currency);
267
+ } catch (Exception $e) {
268
+ throw new HpsGatewayException(
269
+ HpsExceptionCodes::GATEWAY_TIMEOUT_REVERSAL_ERROR,
270
+ 'Error occurred while reversing a charge due to HPS gateway timeout',
271
+ $e
272
+ );
273
+ }
274
+ }
275
+
276
+ HpsGatewayResponseValidation::checkResponse($response, $expectedType);
277
+ }
278
+
279
+ private function _processProcessorResponse($response, $expectedType)
280
+ {
281
+ $transactionId = (isset($response->Header->GatewayTxnId) ? $response->Header->GatewayTxnId : null);
282
+ $item = $response->Transaction->$expectedType;
283
+
284
+ if ($item != null) {
285
+ $responseCode = (isset($item->RspCode) ? $item->RspCode : null);
286
+ $responseMessage = (isset($item->RspMessage) ? $item->RspMessage : null);
287
+ HpsProcessorResponseValidation::checkResponse($transactionId, $responseCode, $responseMessage, $item);
288
+ }
289
+ }
290
+
291
+ private function _submitTransaction($transaction, $txnType, $clientTxnId = null, $cardData = null)
292
+ {
293
+ try {
294
+ $response = $this->doTransaction($transaction, $clientTxnId);
295
+ } catch (HpsException $e) {
296
+ if ($e->innerException != null && $e->innerException->getMessage() == 'gateway_time-out') {
297
+ // if (in_array($txnType, array('CreditSale', 'CreditAuth'))) {
298
+ // try {
299
+ // $this->reverse($cardData, $this->_amount, $this->_currency);
300
+ // } catch (Exception $e) {
301
+ // throw new HpsGatewayException('0', HpsExceptionCodes::GATEWAY_TIMEOUT_REVERSAL_ERROR);
302
+ // }
303
+ // }
304
+ throw new HpsException('An error occurred and the gateway has timed out', 'gateway_timeout', $e, 'gateway_timeout');
305
+ }
306
+ throw $e;
307
+ }
308
+
309
+ $this->_processGatewayResponse($response, $txnType);
310
+ $this->_processProcessorResponse($response, $txnType);
311
+
312
+ $rvalue = null;
313
+ switch ($txnType) {
314
+ case 'AltPaymentCreateSession':
315
+ $rvalue = HpsAltPaymentCreateSession::fromDict($response, $txnType);
316
+ break;
317
+ case 'AltPaymentSessionInfo':
318
+ $rvalue = HpsAltPaymentSessionInfo::fromDict($response, $txnType);
319
+ break;
320
+ case 'AltPaymentSale':
321
+ $rvalue = HpsAltPaymentSale::fromDict($response, $txnType);
322
+ break;
323
+ case 'AltPaymentAuth':
324
+ $rvalue = HpsAltPaymentAuth::fromDict($response, $txnType);
325
+ break;
326
+ case 'AltPaymentAddToBatch':
327
+ $rvalue = HpsAltPaymentAddToBatch::fromDict($response, $txnType);
328
+ break;
329
+ case 'AltPaymentReturn':
330
+ $rvalue = HpsAltPaymentReturn::fromDict($response, $txnType);
331
+ break;
332
+ case 'AltPaymentVoid':
333
+ $rvalue = HpsAltPaymentVoid::fromDict($response, $txnType);
334
+ break;
335
+ default:
336
+ break;
337
+ }
338
+
339
+ return $rvalue;
340
+ }
341
+ }
lib/SecureSubmit/src/Services/Gateway/AltPayment/HpsPayPalService.php ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsPayPalService extends HpsAltPaymentService
4
+ {
5
+ protected $_transactionType = 'PAYPAL';
6
+ }
lib/SecureSubmit/src/Services/Gateway/HpsBatchService.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsBatchService extends HpsSoapGatewayService
4
+ {
5
+ public function __construct($config = null)
6
+ {
7
+ parent::__construct($config);
8
+ }
9
+
10
+ public function closeBatch()
11
+ {
12
+ $xml = new DOMDocument();
13
+ $hpsTransaction = $xml->createElement('hps:Transaction');
14
+ $hpsBatchClose = $xml->createElement('hps:BatchClose');
15
+ $hpsTransaction->appendChild($hpsBatchClose);
16
+
17
+ $response = $this->doTransaction($hpsTransaction);
18
+ HpsGatewayResponseValidation::checkResponse($response, 'BatchClose');
19
+
20
+ //Process the response
21
+ $batchClose = $response->Transaction->BatchClose;
22
+ $result = new HpsBatch();
23
+ $result->id = (isset($batchClose->BatchId) ? $batchClose->BatchId : null);
24
+ $result->sequenceNumber = (isset($batchClose->BatchSeqNbr) ? $batchClose->BatchSeqNbr : null);
25
+ $result->totalAmount = (isset($batchClose->TotalAmt) ? $batchClose->TotalAmt : null);
26
+ $result->transactionCount = (isset($batchClose->TxnCnt) ? $batchClose->TxnCnt : null);
27
+
28
+ return $result;
29
+ }
30
+ }
lib/SecureSubmit/src/Services/Gateway/HpsCheckService.php ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsCheckService extends HpsSoapGatewayService
4
+ {
5
+ public function __construct(HpsServicesConfig $config)
6
+ {
7
+ parent::__construct($config);
8
+ }
9
+
10
+ /**
11
+ * A Sale transaction is used to process transactions using bank account information as the payment method.
12
+ * The transaction service can be used to perform a Sale or Return transaction by indicating the Check Action.
13
+ *
14
+ * <b>NOTE:</b> The Portico Gateway supports both GETI and HPS Colonnade for processing check transactions. While
15
+ * the available services are the same regardless of the check processor, the services may have different behaviors.
16
+ * For example, GETI-processed Check Sale transactions support the ability to override a Check Sale transaction
17
+ * already presented as well as the ability to verify a check.
18
+ * @param string $action Type of Check Action (Sale, Return, Override)
19
+ * @param string $check The Check information.
20
+ * @param string $amount The amount of the sale.
21
+ *
22
+ * @returns HpsCheckSale
23
+ */
24
+ public function sale(HpsCheck $check, $amount, $clientTransactionId = null)
25
+ {
26
+ return $this->_buildTransaction('SALE', $check, $amount, $clientTransactionId);
27
+ }
28
+
29
+ public function returnCheck(HpsCheck $check, $amount, $clientTransactionId = null)
30
+ {
31
+ throw new HpsException('Check action RETURN not currently supported');
32
+ return $this->_buildTransaction('RETURN', $check, $amount, $clientTransactionId);
33
+ }
34
+
35
+ public function override(HpsCheck $check, $amount, $clientTransactionId = null)
36
+ {
37
+ throw new HpsException('Check action OVERRIDE not currently supported');
38
+ return $this->_buildTransaction('OVERRIDE', $check, $amount, $clientTransactionId);
39
+ }
40
+
41
+ /**
42
+ * A <b>Void</b> transaction is used to cancel a previously successful sale transaction. The original sale transaction
43
+ * can be identified by the GatewayTxnid of the original or by the ClientTxnId of the original if provided on the
44
+ * original Sale Transaction.
45
+ *
46
+ * @param null $transactionId
47
+ * @param null $clientTransactionId
48
+ */
49
+ public function void($transactionId = null, $clientTransactionId = null)
50
+ {
51
+ if (($transactionId == null && $clientTransactionId == null) || ($transactionId != null && $clientTransactionId != null)) {
52
+ throw new HpsException('Please provide either a transaction id or a client transaction id');
53
+ }
54
+
55
+ $xml = new DOMDocument();
56
+ $hpsTransaction = $xml->createElement('hps:Transaction');
57
+ $hpsCheckVoid = $xml->createElement('hps:CheckVoid');
58
+ $hpsBlock1 = $xml->createElement('hps:Block1');
59
+
60
+ if ($transactionId != null) {
61
+ $hpsBlock1->appendChild($xml->createElement('hps:GatewayTxnId', $transactionId));
62
+ } else {
63
+ $hpsBlock1->appendChild($xml->createElement('hps:ClientTxnId', $clientTransactionId));
64
+ }
65
+
66
+ $hpsCheckVoid->appendChild($hpsBlock1);
67
+ $hpsTransaction->appendChild($hpsCheckVoid);
68
+ return $this->_submitTransaction($hpsTransaction, 'CheckVoid');
69
+ }
70
+
71
+ private function _buildTransaction($action, HpsCheck $check, $amount, $clientTransactionId = null)
72
+ {
73
+ $amount = HpsInputValidation::checkAmount($amount);
74
+
75
+ if ($check->secCode == HpsSECCode::CCD &&
76
+ ($check->checkHolder == null || $check->checkHolder->checkName == null)) {
77
+ throw new HpsInvalidRequestException(
78
+ HpsExceptionCodes::MISSING_CHECK_NAME,
79
+ 'For SEC code CCD, the check name is required',
80
+ 'check_name'
81
+ );
82
+ }
83
+
84
+ $xml = new DOMDocument();
85
+ $hpsTransaction = $xml->createElement('hps:Transaction');
86
+ $hpsCheckSale = $xml->createElement('hps:CheckSale');
87
+ $hpsBlock1 = $xml->createElement('hps:Block1');
88
+
89
+ $hpsBlock1->appendChild($xml->createElement('hps:Amt', sprintf("%0.2f", round($amount, 3))));
90
+ $hpsBlock1->appendChild($this->_hydrateCheckData($check, $xml));
91
+ $hpsBlock1->appendChild($xml->createElement('hps:CheckAction', $action));
92
+ $hpsBlock1->appendChild($xml->createElement('hps:SECCode', $check->secCode));
93
+ if ($check->checkType != null) {
94
+ $hpsBlock1->appendChild($xml->createElement('hps:CheckType', $check->checkType));
95
+ }
96
+ $hpsBlock1->appendChild($xml->createElement('hps:DataEntryMode', $check->dataEntryMode));
97
+ if ($check->checkHolder != null) {
98
+ $hpsBlock1->appendChild($this->_hydrateConsumerInfo($check, $xml));
99
+ }
100
+
101
+ $hpsCheckSale->appendChild($hpsBlock1);
102
+ $hpsTransaction->appendChild($hpsCheckSale);
103
+
104
+ return $this->_submitTransaction($hpsTransaction, 'CheckSale', $clientTransactionId);
105
+ }
106
+
107
+ private function _submitTransaction($transaction, $txnType, $clientTransactionId = null)
108
+ {
109
+ $rsp = $this->doTransaction($transaction, $clientTransactionId);
110
+ HpsGatewayResponseValidation::checkResponse($rsp, $txnType);
111
+ $response = HpsCheckResponse::fromDict($rsp, $txnType);
112
+
113
+ if ($response->responseCode != 0) {
114
+ throw new HpsCheckException(
115
+ $rsp->Header->GatewayTxnId,
116
+ $response->details,
117
+ $response->responseCode,
118
+ $response->responseText
119
+ );
120
+ }
121
+
122
+ return $response;
123
+ }
124
+ }
lib/SecureSubmit/src/Services/Gateway/HpsCreditService.php ADDED
@@ -0,0 +1,485 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsCreditService extends HpsSoapGatewayService
4
+ {
5
+ public function __construct(HpsServicesConfig $config = null)
6
+ {
7
+ parent::__construct($config);
8
+ }
9
+
10
+ public function authorize($amount, $currency, $cardOrToken, $cardHolder = null, $requestMultiUseToken = false, $details = null, $txnDescriptor = null, $allowPartialAuth = false, $cpcReq = false)
11
+ {
12
+ HpsInputValidation::checkCurrency($currency);
13
+ $this->_currency = $currency;
14
+ $this->_amount = HpsInputValidation::checkAmount($amount);
15
+
16
+ $xml = new DOMDocument();
17
+ $hpsTransaction = $xml->createElement('hps:Transaction');
18
+ $hpsCreditAuth = $xml->createElement('hps:CreditAuth');
19
+ $hpsBlock1 = $xml->createElement('hps:Block1');
20
+
21
+ $hpsBlock1->appendChild($xml->createElement('hps:AllowDup', 'Y'));
22
+ $hpsBlock1->appendChild($xml->createElement('hps:AllowPartialAuth', ($allowPartialAuth ? 'Y' : 'N')));
23
+ $hpsBlock1->appendChild($xml->createElement('hps:Amt', $amount));
24
+ if ($cardHolder != null) {
25
+ $hpsBlock1->appendChild($this->_hydrateCardHolderData($cardHolder, $xml));
26
+ }
27
+ if ($details != null) {
28
+ $hpsBlock1->appendChild($this->_hydrateAdditionalTxnFields($details, $xml));
29
+ }
30
+ if ($txnDescriptor != null && $txnDescriptor != '') {
31
+ $hpsBlock1->appendChild($xml->createElement('hps:TxnDescriptor', $txnDescriptor));
32
+ }
33
+
34
+ $cardData = $xml->createElement('hps:CardData');
35
+ if ($cardOrToken instanceof HpsCreditCard) {
36
+ $cardData->appendChild($this->_hydrateManualEntry($cardOrToken, $xml));
37
+ } else {
38
+ $tokenData = $xml->createElement('hps:TokenData');
39
+ $tokenData->appendChild($xml->createElement('hps:TokenValue', $cardOrToken->tokenValue));
40
+ $cardData->appendChild($tokenData);
41
+ }
42
+ $cardData->appendChild($xml->createElement('hps:TokenRequest', ($requestMultiUseToken) ? 'Y' : 'N'));
43
+ if ($cpcReq) {
44
+ $hpsBlock1->appendChild($xml->createElement('hps:CPCReq', 'Y'));
45
+ }
46
+
47
+ $hpsBlock1->appendChild($cardData);
48
+ $hpsCreditAuth->appendChild($hpsBlock1);
49
+ $hpsTransaction->appendChild($hpsCreditAuth);
50
+
51
+ return $this->_submitTransaction($hpsTransaction, 'CreditAuth', (isset($details->clientTransactionId) ? $details->clientTransactionId : null), $cardOrToken);
52
+ }
53
+
54
+ public function capture($transactionId, $amount = null, $gratuity = null, $clientTransactionId = null, $directMarketData = null)
55
+ {
56
+ $xml = new DOMDocument();
57
+ $hpsTransaction = $xml->createElement('hps:Transaction');
58
+ $hpsCreditAddToBatch = $xml->createElement('hps:CreditAddToBatch');
59
+
60
+ $hpsCreditAddToBatch->appendChild($xml->createElement('hps:GatewayTxnId', $transactionId));
61
+ if ($amount != null) {
62
+ $amount = sprintf("%0.2f", round($amount, 3));
63
+ $hpsCreditAddToBatch->appendChild($xml->createElement('hps:Amt', $amount));
64
+ }
65
+ if ($gratuity != null) {
66
+ $hpsCreditAddToBatch->appendChild($xml->createElement('hps:GratuityAmtInfo', $gratuity));
67
+ }
68
+
69
+ if ($directMarketData != null && $directMarketData->invoiceNumber != null) {
70
+ $hpsCreditAddToBatch->appendChild($this->_hydrateDirectMarketData($directMarketData, $xml));
71
+ }
72
+
73
+ $hpsTransaction->appendChild($hpsCreditAddToBatch);
74
+ $response = $this->doTransaction($hpsTransaction);
75
+ $this->_processChargeGatewayResponse($response, 'CreditAddToBatch');
76
+
77
+ return $this->get($transactionId);
78
+ }
79
+
80
+ public function charge($amount, $currency, $cardOrToken, $cardHolder = null, $requestMultiUseToken = false, $details = null, $txnDescriptor = null, $allowPartialAuth = false, $cpcReq = false, $directMarketData = null)
81
+ {
82
+ HpsInputValidation::checkCurrency($currency);
83
+ $this->_currency = $currency;
84
+ $this->_amount = HpsInputValidation::checkAmount($amount);
85
+
86
+ $xml = new DOMDocument();
87
+ $hpsTransaction = $xml->createElement('hps:Transaction');
88
+ $hpsCreditSale = $xml->createElement('hps:CreditSale');
89
+ $hpsBlock1 = $xml->createElement('hps:Block1');
90
+
91
+ $hpsBlock1->appendChild($xml->createElement('hps:AllowDup', 'Y'));
92
+ $hpsBlock1->appendChild($xml->createElement('hps:AllowPartialAuth', ($allowPartialAuth ? 'Y' : 'N')));
93
+ $hpsBlock1->appendChild($xml->createElement('hps:Amt', $amount));
94
+ if ($cardHolder != null) {
95
+ $hpsBlock1->appendChild($this->_hydrateCardHolderData($cardHolder, $xml));
96
+ }
97
+ if ($details != null) {
98
+ $hpsBlock1->appendChild($this->_hydrateAdditionalTxnFields($details, $xml));
99
+ }
100
+ if ($txnDescriptor != null && $txnDescriptor != '') {
101
+ $hpsBlock1->appendChild($xml->createElement('hps:TxnDescriptor', $txnDescriptor));
102
+ }
103
+
104
+ $cardData = $xml->createElement('hps:CardData');
105
+ if ($cardOrToken instanceof HpsCreditCard) {
106
+ $cardData->appendChild($this->_hydrateManualEntry($cardOrToken, $xml));
107
+ } else {
108
+ $tokenData = $xml->createElement('hps:TokenData');
109
+ $tokenData->appendChild($xml->createElement('hps:TokenValue', $cardOrToken->tokenValue));
110
+ $cardData->appendChild($tokenData);
111
+ }
112
+ if ($cpcReq) {
113
+ $hpsBlock1->appendChild($xml->createElement('hps:CPCReq', 'Y'));
114
+ }
115
+ $cardData->appendChild($xml->createElement('hps:TokenRequest', ($requestMultiUseToken) ? 'Y' : 'N'));
116
+
117
+ if ($directMarketData != null && $directMarketData->invoiceNumber != null) {
118
+ $hpsBlock1->appendChild($this->_hydrateDirectMarketData($directMarketData, $xml));
119
+ }
120
+
121
+ $hpsBlock1->appendChild($cardData);
122
+ $hpsCreditSale->appendChild($hpsBlock1);
123
+ $hpsTransaction->appendChild($hpsCreditSale);
124
+
125
+ return $this->_submitTransaction($hpsTransaction, 'CreditSale', (isset($details->clientTransactionId) ? $details->clientTransactionId : null), $cardOrToken);
126
+ }
127
+
128
+ public function recurring($schedule, $amount, $cardOrTokenOrPMKey, $cardHolder = null, $oneTime = false, $details = null)
129
+ {
130
+ $this->_amount = HpsInputValidation::checkAmount($amount);
131
+
132
+ $xml = new DOMDocument();
133
+ $hpsTransaction = $xml->createElement('hps:Transaction');
134
+ $hpsRecurringBilling = $xml->createElement('hps:RecurringBilling');
135
+ $hpsBlock1 = $xml->createElement('hps:Block1');
136
+
137
+ $hpsBlock1->appendChild($xml->createElement('hps:AllowDup', 'Y'));
138
+ $hpsBlock1->appendChild($xml->createElement('hps:Amt', $amount));
139
+ if ($cardHolder != null) {
140
+ $hpsBlock1->appendChild($this->_hydrateCardHolderData($cardHolder, $xml));
141
+ }
142
+ if ($details != null) {
143
+ $hpsBlock1->appendChild($this->_hydrateAdditionalTxnFields($details, $xml));
144
+ }
145
+
146
+ if ($cardOrTokenOrPMKey instanceof HpsCreditCard) {
147
+ $cardData = $xml->createElement('hps:CardData');
148
+ $cardData->appendChild($this->_hydrateManualEntry($cardOrTokenOrPMKey, $xml));
149
+ $hpsBlock1->appendChild($cardData);
150
+ } else if ($cardOrTokenOrPMKey instanceof HpsTokenData) {
151
+ $cardData = $xml->createElement('hps:CardData');
152
+ $tokenData = $xml->createElement('hps:TokenData');
153
+ $tokenData->appendChild($xml->createElement('hps:TokenValue', $cardOrTokenOrPMKey->tokenValue));
154
+ $cardData->appendChild($tokenData);
155
+ $hpsBlock1->appendChild($cardData);
156
+ } else {
157
+ $hpsBlock1->appendChild($xml->createElement('hps:PaymentMethodKey', $cardOrTokenOrPMKey));
158
+ }
159
+
160
+ $id = $schedule;
161
+ if ($schedule instanceof HpsPayPlanSchedule) {
162
+ $id = $schedule->scheduleIdentifier;
163
+ }
164
+ $recurringData = $xml->createElement('hps:RecurringData');
165
+ $recurringData->appendChild($xml->createElement('hps:ScheduleID', $id));
166
+ $recurringData->appendChild($xml->createElement('hps:OneTime', ($oneTime ? 'Y' : 'N')));
167
+
168
+ $hpsBlock1->appendChild($recurringData);
169
+ $hpsRecurringBilling->appendChild($hpsBlock1);
170
+ $hpsTransaction->appendChild($hpsRecurringBilling);
171
+
172
+ return $this->_submitTransaction($hpsTransaction, 'RecurringBilling', (isset($details->clientTransactionId) ? $details->clientTransactionId : null), $cardOrTokenOrPMKey);
173
+ }
174
+
175
+ public function cpcEdit($transactionId, $cpcData)
176
+ {
177
+ $xml = new DOMDocument();
178
+ $hpsTransaction = $xml->createElement('hps:Transaction');
179
+ $hpsPosCreditCPCEdit = $xml->createElement('hps:CreditCPCEdit');
180
+ $hpsPosCreditCPCEdit->appendChild($xml->createElement('hps:GatewayTxnId', $transactionId));
181
+ $hpsPosCreditCPCEdit->appendChild($this->_hydrateCPCData($cpcData, $xml));
182
+ $hpsTransaction->appendChild($hpsPosCreditCPCEdit);
183
+
184
+ return $this->_submitTransaction($hpsTransaction, 'CreditCPCEdit');
185
+ }
186
+
187
+ public function edit($transactionId, $amount = null, $gratuity = null, $clientTransactionId = null)
188
+ {
189
+ $xml = new DOMDocument();
190
+ $hpsTransaction = $xml->createElement('hps:Transaction');
191
+ $hpsCreditTxnEdit = $xml->createElement('hps:CreditTxnEdit');
192
+
193
+ $hpsCreditTxnEdit->appendChild($xml->createElement('hps:GatewayTxnId', $transactionId));
194
+ if ($amount != null) {
195
+ $amount = sprintf('%0.2f', round($amount, 3));
196
+ $hpsCreditTxnEdit->appendChild($xml->createElement('hps:Amt', $amount));
197
+ }
198
+ if ($gratuity != null) {
199
+ $hpsCreditTxnEdit->appendChild($xml->createElement('hps:GratuityAmtInfo', $gratuity));
200
+ }
201
+
202
+ $hpsTransaction->appendChild($hpsCreditTxnEdit);
203
+ $trans = $this->_submitTransaction($hpsTransaction, 'CreditTxnEdit', $clientTransactionId);
204
+
205
+ $trans->responseCode = '00';
206
+ $trans->responseText = '';
207
+
208
+ return $trans;
209
+ }
210
+
211
+ public function get($transactionId)
212
+ {
213
+ if ($transactionId <= 0) {
214
+ throw new HpsArgumentException('Invalid Transaction Id');
215
+ }
216
+
217
+ $xml = new DOMDocument();
218
+ $hpsTransaction = $xml->createElement('hps:Transaction');
219
+ $hpsReportTxnDetail = $xml->createElement('hps:ReportTxnDetail');
220
+ $hpsReportTxnDetail->appendChild($xml->createElement('hps:TxnId', $transactionId));
221
+ $hpsTransaction->appendChild($hpsReportTxnDetail);
222
+
223
+ return $this->_submitTransaction($hpsTransaction, 'ReportTxnDetail');
224
+ }
225
+
226
+ public function listTransactions($startDate, $endDate, $filterBy = null)
227
+ {
228
+ $this->_filterBy = $filterBy;
229
+ date_default_timezone_set("UTC");
230
+ $dateFormat = 'Y-m-d\TH:i:s.00\Z';
231
+ $current = new DateTime();
232
+ $currentTime = $current->format($dateFormat);
233
+
234
+ HpsInputValidation::checkDateNotFuture($startDate);
235
+ HpsInputValidation::checkDateNotFuture($endDate);
236
+
237
+ $xml = new DOMDocument();
238
+ $hpsTransaction = $xml->createElement('hps:Transaction');
239
+ $hpsReportActivity = $xml->createElement('hps:ReportActivity');
240
+ $hpsReportActivity->appendChild($xml->createElement('hps:RptStartUtcDT', $startDate));
241
+ $hpsReportActivity->appendChild($xml->createElement('hps:RptEndUtcDT', $endDate));
242
+ $hpsTransaction->appendChild($hpsReportActivity);
243
+
244
+ return $this->_submitTransaction($hpsTransaction, 'ReportActivity');
245
+ }
246
+
247
+ public function refund($amount, $currency, $cardData, $cardHolder = null, $details = null)
248
+ {
249
+ HpsInputValidation::checkCurrency($currency);
250
+ $this->_currency = $currency;
251
+ $this->_amount = HpsInputValidation::checkAmount($amount);
252
+
253
+ $xml = new DOMDocument();
254
+ $hpsTransaction = $xml->createElement('hps:Transaction');
255
+ $hpsCreditReturn = $xml->createElement('hps:CreditReturn');
256
+ $hpsBlock1 = $xml->createElement('hps:Block1');
257
+
258
+ $hpsBlock1->appendChild($xml->createElement('hps:AllowDup', 'Y'));
259
+ $hpsBlock1->appendChild($xml->createElement('hps:Amt', $amount));
260
+ if ($cardData instanceof HpsCreditCard) {
261
+ $cardDataElement = $xml->createElement('hps:CardData');
262
+ $cardDataElement->appendChild($this->_hydrateManualEntry($cardData, $xml));
263
+ $hpsBlock1->appendChild($cardDataElement);
264
+ } else if ($cardData instanceof HpsTokenData) {
265
+ $cardDataElement = $xml->createElement('hps:CardData');
266
+ $tokenData = $xml->createElement('hps:TokenData');
267
+ $tokenData->appendChild($xml->createElement('hps:TokenValue', $cardData->tokenValue));
268
+ $cardDataElement->appendChild($tokenData);
269
+ $hpsBlock1->appendChild($cardDataElement);
270
+ } else {
271
+ $hpsBlock1->appendChild($xml->createElement('hps:GatewayTxnId', $cardData));
272
+ }
273
+ if ($cardHolder != null) {
274
+ $hpsBlock1->appendChild($this->_hydrateCardHolderData($cardHolder, $xml));
275
+ }
276
+ if ($details != null) {
277
+ $hpsBlock1->appendChild($this->_hydrateAdditionalTxnFields($details, $xml));
278
+ }
279
+
280
+ $hpsCreditReturn->appendChild($hpsBlock1);
281
+ $hpsTransaction->appendChild($hpsCreditReturn);
282
+
283
+ return $this->_submitTransaction($hpsTransaction, 'CreditReturn', (isset($details->clientTransactionId) ? $details->clientTransationId : null));
284
+ }
285
+
286
+ public function reverse($cardData, $amount, $currency, $details = null)
287
+ {
288
+ HpsInputValidation::checkCurrency($currency);
289
+ $this->_currency = $currency;
290
+ $this->_amount = HpsInputValidation::checkAmount($amount);
291
+
292
+ $xml = new DOMDocument();
293
+ $hpsTransaction = $xml->createElement('hps:Transaction');
294
+ $hpsCreditReversal = $xml->createElement('hps:CreditReversal');
295
+ $hpsBlock1 = $xml->createElement('hps:Block1');
296
+
297
+ $hpsBlock1->appendChild($xml->createElement('hps:Amt', $amount));
298
+ $cardDataElement = null;
299
+ if ($cardData instanceof HpsCreditCard) {
300
+ $cardDataElement = $xml->createElement('hps:CardData');
301
+ $cardDataElement->appendChild($this->_hydrateManualEntry($cardData, $xml));
302
+ } else if ($cardData instanceof HpsTokenData) {
303
+ $cardDataElement = $xml->createElement('hps:CardData');
304
+ $tokenData = $xml->createElement('hps:TokenData');
305
+ $tokenData->appendChild($xml->createElement('hps:TokenValue', $cardData->tokenValue));
306
+ $cardDataElement->appendChild($tokenData);
307
+ } else {
308
+ $cardDataElement = $xml->createElement('hps:GatewayTxnId', $cardData);
309
+ }
310
+ $hpsBlock1->appendChild($cardDataElement);
311
+ if ($details != null) {
312
+ $hpsBlock1->appendChild($this->_hydrateAdditionalTxnFields($details, $xml));
313
+ }
314
+
315
+ $hpsCreditReversal->appendChild($hpsBlock1);
316
+ $hpsTransaction->appendChild($hpsCreditReversal);
317
+
318
+ return $this->_submitTransaction($hpsTransaction, 'CreditReversal', (isset($details->clientTransactionId) ? $details->clientTransactionId : null));
319
+ }
320
+
321
+ public function verify($cardOrToken, $cardHolder = null, $requestMultiUseToken = false, $clientTransactionId = null)
322
+ {
323
+ $xml = new DOMDocument();
324
+ $hpsTransaction = $xml->createElement('hps:Transaction');
325
+ $hpsCreditAccountVerify = $xml->createElement('hps:CreditAccountVerify');
326
+ $hpsBlock1 = $xml->createElement('hps:Block1');
327
+
328
+ if ($cardHolder != null) {
329
+ $hpsBlock1->appendChild($this->_hydrateCardHolderData($cardHolder, $xml));
330
+ }
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
+
342
+ $hpsBlock1->appendChild($cardData);
343
+ $hpsCreditAccountVerify->appendChild($hpsBlock1);
344
+ $hpsTransaction->appendChild($hpsCreditAccountVerify);
345
+
346
+ return $this->_submitTransaction($hpsTransaction, 'CreditAccountVerify', $clientTransactionId);
347
+ }
348
+
349
+ public function void($transactionId, $clientTransactionId = null)
350
+ {
351
+ $xml = new DOMDocument();
352
+ $hpsTransaction = $xml->createElement('hps:Transaction');
353
+ $hpsCreditVoid = $xml->createElement('hps:CreditVoid');
354
+ $hpsCreditVoid->appendChild($xml->createElement('hps:GatewayTxnId', $transactionId));
355
+ $hpsTransaction->appendChild($hpsCreditVoid);
356
+
357
+ return $this->_submitTransaction($hpsTransaction, 'CreditVoid', $clientTransactionId);
358
+ }
359
+
360
+ private function _processChargeGatewayResponse($response, $expectedType)
361
+ {
362
+ $gatewayRspCode = (isset($response->Header->GatewayRspCode) ? $response->Header->GatewayRspCode : null);
363
+ $transactionId = (isset($response->Header->GatewayTxnId) ? $response->Header->GatewayTxnId : null);
364
+
365
+ if ($gatewayRspCode == '0') {
366
+ return;
367
+ }
368
+
369
+ if ($gatewayRspCode == '30') {
370
+ try {
371
+ $this->reverse($transactionId, $this->_amount, $this->_currency);
372
+ } catch (Exception $e) {
373
+ throw new HpsGatewayException(
374
+ HpsExceptionCodes::GATEWAY_TIMEOUT_REVERSAL_ERROR,
375
+ 'Error occurred while reversing a charge due to HPS gateway timeout',
376
+ $e
377
+ );
378
+ }
379
+ }
380
+
381
+ HpsGatewayResponseValidation::checkResponse($response, $expectedType);
382
+ }
383
+
384
+ private function _processChargeIssuerResponse($response, $expectedType)
385
+ {
386
+ $transactionId = (isset($response->Header->GatewayTxnId) ? $response->Header->GatewayTxnId : null);
387
+ $item = $response->Transaction->$expectedType;
388
+
389
+ if ($item != null) {
390
+ $responseCode = (isset($item->RspCode) ? $item->RspCode : null);
391
+ $responseText = (isset($item->RspText) ? $item->RspText : null);
392
+
393
+ if ($responseCode != null) {
394
+ // check if we need to do a reversal
395
+ if ($responseCode == '91') {
396
+ try {
397
+ $this->reverse($transactionId, $this->_amount, $this->_currency);
398
+ } catch (HpsGatewayException $e) {
399
+ // if the transaction wasn't found; throw the original timeout exception
400
+ if ($e->details->gatewayResponseCode == 3) {
401
+ HpsIssuerResponseValidation::checkResponse($transactionId, $responseCode, $responseText);
402
+ }
403
+ throw new HpsCreditException(
404
+ $transactionId,
405
+ HpsExceptionCodes::ISSUER_TIMEOUT_REVERSAL_ERROR,
406
+ 'Error occurred while reversing a charge due to HPS issuer timeout',
407
+ $e
408
+ );
409
+ } catch (HpsException $e) {
410
+ throw new HpsCreditException(
411
+ $transactionId,
412
+ HpsExceptionCodes::ISSUER_TIMEOUT_REVERSAL_ERROR,
413
+ 'Error occurred while reversing a charge due to HPS issuer timeout',
414
+ $e
415
+ );
416
+ }
417
+ }
418
+ HpsIssuerResponseValidation::checkResponse($transactionId, $responseCode, $responseText);
419
+ }
420
+ }
421
+ }
422
+
423
+ private function _submitTransaction($transaction, $txnType, $clientTxnId = null, $cardData = null)
424
+ {
425
+ try {
426
+ $response = $this->doTransaction($transaction, $clientTxnId);
427
+ } catch (HpsException $e) {
428
+ if ($e->innerException != null && $e->innerException->getMessage() == 'gateway_time-out') {
429
+ if (in_array($txnType, array('CreditSale', 'CreditAuth'))) {
430
+ try {
431
+ $this->reverse($cardData, $this->_amount, $this->_currency);
432
+ } catch (Exception $e) {
433
+ throw new HpsGatewayException('0', HpsExceptionCodes::GATEWAY_TIMEOUT_REVERSAL_ERROR);
434
+ }
435
+ }
436
+ throw new HpsException('An error occurred and the gateway has timed out', 'gateway_timeout', $e, 'gateway_timeout');
437
+ }
438
+ throw $e;
439
+ }
440
+
441
+ $this->_processChargeGatewayResponse($response, $txnType);
442
+ $this->_processChargeIssuerResponse($response, $txnType);
443
+
444
+ $rvalue = null;
445
+ switch ($txnType) {
446
+ case 'ReportTxnDetail':
447
+ $rvalue = HpsReportTransactionDetails::fromDict($response, $txnType);
448
+ break;
449
+ case 'ReportActivity':
450
+ $rvalue = HpsReportTransactionSummary::fromDict($response, $txnType, $this->_filterBy);
451
+ break;
452
+ case 'CreditSale':
453
+ $rvalue = HpsCharge::fromDict($response, $txnType);
454
+ break;
455
+ case 'CreditAccountVerify':
456
+ $rvalue = HpsAccountVerify::fromDict($response, $txnType);
457
+ break;
458
+ case 'CreditAuth':
459
+ $rvalue = HpsAuthorization::fromDict($response, $txnType);
460
+ break;
461
+ case 'CreditReturn':
462
+ $rvalue = HpsRefund::fromDict($response, $txnType);
463
+ break;
464
+ case 'CreditReversal':
465
+ $rvalue = HpsReversal::fromDict($response, $txnType);
466
+ break;
467
+ case 'CreditVoid':
468
+ $rvalue = HpsVoid::fromDict($response, $txnType);
469
+ break;
470
+ case 'CreditCPCEdit':
471
+ $rvalue = HpsCPCEdit::fromDict($response, $txnType);
472
+ break;
473
+ case 'CreditTxnEdit':
474
+ $rvalue = HpsTransaction::fromDict($response, $txnType);
475
+ break;
476
+ case 'RecurringBilling':
477
+ $rvalue = HpsRecurringBilling::fromDict($response, $txnType);
478
+ break;
479
+ default:
480
+ break;
481
+ }
482
+
483
+ return $rvalue;
484
+ }
485
+ }
lib/SecureSubmit/src/Services/Gateway/HpsDebitService.php ADDED
@@ -0,0 +1,307 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsDebitService extends HpsSoapGatewayService
4
+ {
5
+ public function __construct($config = null)
6
+ {
7
+ parent::__construct($config);
8
+ }
9
+
10
+ /**
11
+ * The Debit Add Value transaction adds value to a stored value card. The transaction is placed in the current
12
+ * open batch. If a batch is not open, this transaction creates an open batch.
13
+ *
14
+ * @param double $amount Authorization amount.
15
+ * @param string $currency Currency ("usd")
16
+ * @param string $trackData Track data read from the card by the card reader.
17
+ * @param string $pinBlock PIN block.
18
+ * @param HpsEncryptionData $encryptionData E3 encryption data group.
19
+ * @param bool $allowDuplicates Indicates whether to allow duplicate transactions.
20
+ * @param HpsCardHolder $cardHolder Card holder information.
21
+ * @param HpsTransactionDetails $details Group containing additional transaction fields to be included in detail reporting.
22
+ * @param string $clientTransactionId Optional client transaction ID.
23
+ *
24
+ * @return HpsDebitAddValue The AddValue (Authorization) response.
25
+ */
26
+ public function addValue($amount, $currency, $trackData, $pinBlock, HpsEncryptionData $encryptionData = null, $allowDuplicates = false, HpsCardHolder $cardHolder = null, HpsTransactionDetails $details = null, $clientTransactionId = null)
27
+ {
28
+ HpsInputValidation::checkAmount($amount);
29
+ HpsInputValidation::checkCurrency($currency);
30
+
31
+ /* Build the transaction request. */
32
+ $xml = new DOMDocument();
33
+ $hpsTransaction = $xml->createElement('hps:Transaction');
34
+ $hpsGiftCard = $xml->createElement('hps:DebitAddValue');
35
+ $hpsBlock1 = $xml->createElement('hps:Block1');
36
+
37
+ $hpsBlock1->appendChild($xml->createElement('hps:TrackData', $trackData));
38
+ $hpsBlock1->appendChild($xml->createElement('hps:AllowDup', ($allowDuplicates ? 'Y' : 'N')));
39
+ if ($cardHolder != null) {
40
+ $hpsBlock1->appendChild($this->_hydrateCardHolderData($cardHolder, $xml));
41
+ }
42
+ $hpsBlock1->appendChild($xml->createElement('hps:Amt', $amount));
43
+ $hpsBlock1->appendChild($xml->createElement('hps:PinBlock', $pinBlock));
44
+ if ($encryptionData != null) {
45
+ $hpsBlock1->appendChild($this->_hydrateEncryptionData($encryptionData, $xml));
46
+ }
47
+ if ($details != null) {
48
+ $hpsBlock1->appendChild($this->_hydrateAdditionalTxnFields($details, $xml));
49
+ }
50
+
51
+ $hpsGiftCard->appendChild($hpsBlock1);
52
+ $hpsTransaction->appendChild($hpsGiftCard);
53
+
54
+ return $this->_submitTransaction($hpsTransaction, 'DebitAddValue', $clientTransactionId);
55
+ }
56
+
57
+ /**
58
+ * A Debit Return transaction returns funds to the cardholder. The transaction is generally used as a
59
+ * counterpart to a Debit Charge transaction that needs to be reversed. The Debit Return transaction is
60
+ * placed in the current open batch. If a batch is not open, this transaction create an open batch.
61
+ *
62
+ * @param string $transactionId The gateway transaciton ID of the charge to be returned.
63
+ * @param double $amount Authorization amount.
64
+ * @param string $trackData Track data read from the card by the card reader.
65
+ * @param string $pinBlock PIN block.
66
+ * @param bool $allowDuplicates Indicates whether to allow duplicate transactions.
67
+ * @param HpsCardHolder $cardHolder Card holder information.
68
+ * @param HpsEncryptionData $encryptionData E3 encryption data group.
69
+ * @param HpsTransactionDetails $details Group containing additional transaction fields to be included in detail reporting.
70
+ * @param string $clientTransactionId Optional client transaction ID.
71
+ *
72
+ * @return HpsDebit The Return (Authorization) results.
73
+ */
74
+ public function returnDebit($transactionId, $amount, $trackData, $pinBlock, $allowDuplicates = false, HpsCardHolder $cardHolder = null, HpsEncryptionData $encryptionData = null, HpsTransactionDetails $details = null, $clientTransactionId = null)
75
+ {
76
+ HpsInputValidation::checkAmount($amount);
77
+
78
+ /* Build the transaction request. */
79
+ $xml = new DOMDocument();
80
+ $hpsTransaction = $xml->createElement('hps:Transaction');
81
+ $hpsGiftCard = $xml->createElement('hps:DebitReturn');
82
+ $hpsBlock1 = $xml->createElement('hps:Block1');
83
+
84
+ $hpsBlock1->appendChild($xml->createElement('hps:TrackData', $trackData));
85
+ $hpsBlock1->appendChild($xml->createElement('hps:AllowDup', ($allowDuplicates ? 'Y' : 'N')));
86
+ if ($cardHolder != null) {
87
+ $hpsBlock1->appendChild($this->_hydrateCardHolderData($cardHolder, $xml));
88
+ }
89
+ $hpsBlock1->appendChild($xml->createElement('hps:Amt', $amount));
90
+ $hpsBlock1->appendChild($xml->createElement('hps:PinBlock', $pinBlock));
91
+ if ($encryptionData != null) {
92
+ $hpsBlock1->appendChild($this->_hydrateEncryptionData($encryptionData, $xml));
93
+ }
94
+ if ($details != null) {
95
+ $hpsBlock1->appendChild($this->_hydrateAdditionalTxnFields($details, $xml));
96
+ }
97
+
98
+ $hpsGiftCard->appendChild($hpsBlock1);
99
+ $hpsTransaction->appendChild($hpsGiftCard);
100
+
101
+ return $this->_submitTransaction($hpsTransaction, 'DebitReturn', $clientTransactionId);
102
+ }
103
+
104
+ /**
105
+ * A Debit Reversal transaction reverses a Debit Charge or Debit Return transaction.
106
+ *
107
+ * @param string $transactionId The gateway transaciton ID of the charge to be reversed.
108
+ * @param double $amount Authorization amount.
109
+ * @param string $trackData Track data read from the card by the card reader.
110
+ * @param double $authorizedAmount Settlement amount or New Authorization amount after reversal occures.
111
+ * @param HpsEncryptionData $encryptionData E3 encryption data group.
112
+ * @param HpsTransactionDetails $details Group containing additional transaction fields to be included in detail reporting.
113
+ * @param string $clientTransactionId Optional client transaction ID.
114
+ *
115
+ * @return HpsDebit The reversal result.
116
+ */
117
+ public function reverse($transactionId, $amount, $trackData, $authorizedAmount = null, HpsEncryptionData $encryptionData = null, HpsTransactionDetails $details = null, $clientTransactionId = null)
118
+ {
119
+ HpsInputValidation::checkAmount($amount);
120
+
121
+ /* Build the transaction request. */
122
+ $xml = new DOMDocument();
123
+ $hpsTransaction = $xml->createElement('hps:Transaction');
124
+ $hpsGiftCard = $xml->createElement('hps:DebitReversal');
125
+ $hpsBlock1 = $xml->createElement('hps:Block1');
126
+
127
+ $hpsBlock1->appendChild($xml->createElement('hps:GatewayTxnId', $transactionId));
128
+ $hpsBlock1->appendChild($xml->createElement('hps:TrackData', $trackData));
129
+ $hpsBlock1->appendChild($xml->createElement('hps:Amt', $amount));
130
+ if ($encryptionData != null) {
131
+ $hpsBlock1->appendChild($this->_hydrateEncryptionData($encryptionData, $xml));
132
+ }
133
+ if ($details != null) {
134
+ $hpsBlock1->appendChild($this->_hydrateAdditionalTxnFields($details, $xml));
135
+ }
136
+
137
+ $hpsGiftCard->appendChild($hpsBlock1);
138
+ $hpsTransaction->appendChild($hpsGiftCard);
139
+
140
+ if (isset($authorizedAmount)) {
141
+ $block = $transaction->Item->Block1;
142
+ $block->authAmt = $authorizedAmount->value;
143
+ $block->authAmtSpecified = true;
144
+ }
145
+
146
+ $rsp = $this->_submitTransaction($hpsTransaction, 'DebitReversal', $clientTransactionId);
147
+ $rsp->responseCode = '00';
148
+ $rsp->responseText = '';
149
+
150
+ return $rsp;
151
+ }
152
+
153
+ /**
154
+ * A Debit Charge transaction performs a sale purchased with a Debit Card. The Debit Charge is placed
155
+ * in the current open batch. If a batch is not open, this transaction creates an open batch.
156
+ *
157
+ * @param double $amount Authorization amount.
158
+ * @param string $currency Currency ("usd")
159
+ * @param string $trackData Track data read from the card by the card reader.
160
+ * @param string $pinBlock PIN block.
161
+ * @param HpsEncryptionData $encryptionData E3 encryption data group.
162
+ * @param bool $allowDuplicates Indicates whether to allow duplicate transactions.
163
+ * @param double $cashBackAmount Contains the portion of the amount that is cash back.
164
+ * @param bool $allowPartialAuth Indicate whether to allow partial authorization.
165
+ * @param HpsCardHolder $cardHolder Card holder information.
166
+ * @param HpsTransactionDetails $details Group containing additional transaction fields to be included in detail reporting.
167
+ * @param string $clientTransactionId Optional client transaction ID.
168
+ *
169
+ * @return HpsDebit The Debit Charge result.
170
+ */
171
+ public function charge($amount, $currency, $trackData, $pinBlock, HpsEncryptionData $encryptionData = null, $allowDuplicates = false, $cashBackAmount = null, $allowPartialAuth = false, HpsCardHolder $cardHolder = null, HpsTransactionDetails $details = null, $clientTransactionId = null)
172
+ {
173
+ HpsInputValidation::checkAmount($amount);
174
+ HpsInputValidation::checkCurrency($currency);
175
+
176
+ $xml = new DOMDocument();
177
+ $hpsTransaction = $xml->createElement('hps:Transaction');
178
+ $hpsGiftCard = $xml->createElement('hps:DebitSale');
179
+ $hpsBlock1 = $xml->createElement('hps:Block1');
180
+
181
+ $hpsBlock1->appendChild($xml->createElement('hps:TrackData', $trackData));
182
+ $hpsBlock1->appendChild($xml->createElement('hps:AllowDup', ($allowDuplicates ? 'Y' : 'N')));
183
+ if ($cardHolder != null) {
184
+ $hpsBlock1->appendChild($this->_hydrateCardHolderData($cardHolder, $xml));
185
+ }
186
+ $hpsBlock1->appendChild($xml->createElement('hps:Amt', $amount));
187
+ $hpsBlock1->appendChild($xml->createElement('hps:CashbackAmtInfo', isset($cashBackAmount) ? $cashBackAmount : 0));
188
+ $hpsBlock1->appendChild($xml->createElement('hps:AllowPartialAuth', ($allowPartialAuth ? 'Y' : 'N')));
189
+ $hpsBlock1->appendChild($xml->createElement('hps:PinBlock', $pinBlock));
190
+ if ($encryptionData != null) {
191
+ $hpsBlock1->appendChild($this->_hydrateEncryptionData($encryptionData, $xml));
192
+ }
193
+ if ($details != null) {
194
+ $hpsBlock1->appendChild($this->_hydrateAdditionalTxnFields($details, $xml));
195
+ }
196
+
197
+ $hpsGiftCard->appendChild($hpsBlock1);
198
+ $hpsTransaction->appendChild($hpsGiftCard);
199
+
200
+ return $this->_submitTransaction($hpsTransaction, 'DebitSale', $clientTransactionId);
201
+ }
202
+
203
+ private function _processChargeGatewayResponse($response, $expectedType)
204
+ {
205
+ $gatewayRspCode = (isset($response->Header->GatewayRspCode) ? $response->Header->GatewayRspCode : null);
206
+ $transactionId = (isset($response->Header->GatewayTxnId) ? $response->Header->GatewayTxnId : null);
207
+
208
+ if ($gatewayRspCode == '0') {
209
+ return;
210
+ }
211
+
212
+ if ($gatewayRspCode == '30') {
213
+ try {
214
+ $this->reverse($transactionId, $this->_amount, $this->_currency);
215
+ } catch (Exception $e) {
216
+ throw new HpsGatewayException(
217
+ HpsExceptionCodes::GATEWAY_TIMEOUT_REVERSAL_ERROR,
218
+ 'Error occurred while reversing a charge due to HPS gateway timeout',
219
+ $e
220
+ );
221
+ }
222
+ }
223
+
224
+ HpsGatewayResponseValidation::checkResponse($response, $expectedType);
225
+ }
226
+
227
+ private function _processChargeIssuerResponse($response, $expectedType)
228
+ {
229
+ $transactionId = (isset($response->Header->GatewayTxnId) ? $response->Header->GatewayTxnId : null);
230
+ $item = $response->Transaction->$expectedType;
231
+
232
+ if ($item != null) {
233
+ $responseCode = (isset($item->RspCode) ? $item->RspCode : null);
234
+ $responseText = (isset($item->RspText) ? $item->RspText : null);
235
+
236
+ if ($responseCode != null) {
237
+ // check if we need to do a reversal
238
+ if ($responseCode == '91') {
239
+ try {
240
+ $this->reverse($transactionId, $this->_amount, $this->_currency);
241
+ } catch (HpsGatewayException $e) {
242
+ // if the transaction wasn't found; throw the original timeout exception
243
+ if ($e->details->gatewayResponseCode == 3) {
244
+ HpsIssuerResponseValidation::checkResponse($transactionId, $responseCode, $responseText);
245
+ }
246
+ throw new HpsCreditException(
247
+ $transactionId,
248
+ HpsExceptionCodes::ISSUER_TIMEOUT_REVERSAL_ERROR,
249
+ 'Error occurred while reversing a charge due to HPS issuer timeout',
250
+ $e
251
+ );
252
+ } catch (HpsException $e) {
253
+ throw new HpsCreditException(
254
+ $transactionId,
255
+ HpsExceptionCodes::ISSUER_TIMEOUT_REVERSAL_ERROR,
256
+ 'Error occurred while reversing a charge due to HPS issuer timeout',
257
+ $e
258
+ );
259
+ }
260
+ }
261
+ HpsIssuerResponseValidation::checkResponse($transactionId, $responseCode, $responseText);
262
+ }
263
+ }
264
+ }
265
+
266
+ private function _submitTransaction($transaction, $txnType, $clientTxnId = null, $cardData = null)
267
+ {
268
+ try {
269
+ $response = $this->doTransaction($transaction, $clientTxnId);
270
+ } catch (HpsException $e) {
271
+ if ($e->innerException != null && $e->innerException->getMessage() == 'gateway_time-out') {
272
+ if ($txnType == 'DebitSale') {
273
+ try {
274
+ $this->reverse($cardData, $this->_amount, $this->_currency);
275
+ } catch (Exception $e) {
276
+ throw new HpsGatewayException('0', HpsExceptionCodes::GATEWAY_TIMEOUT_REVERSAL_ERROR);
277
+ }
278
+ }
279
+ throw new HpsException('An error occurred and the gateway has timed out', 'gateway_timeout', $e, 'gateway_timeout');
280
+ }
281
+ throw $e;
282
+ }
283
+
284
+ $this->_processChargeGatewayResponse($response, $txnType);
285
+ $this->_processChargeIssuerResponse($response, $txnType);
286
+
287
+ $rvalue = null;
288
+ switch ($txnType) {
289
+ case 'DebitSale':
290
+ $rvalue = HpsDebitSale::fromDict($response, $txnType);
291
+ break;
292
+ case 'DebitAddValue':
293
+ $rvalue = HpsDebitAddValue::fromDict($response, $txnType);
294
+ break;
295
+ case 'DebitReturn':
296
+ $rvalue = HpsDebitReturn::fromDict($response, $txnType);
297
+ break;
298
+ case 'DebitReversal':
299
+ $rvalue = HpsDebitReversal::fromDict($response, $txnType);
300
+ break;
301
+ default:
302
+ break;
303
+ }
304
+
305
+ return $rvalue;
306
+ }
307
+ }
lib/SecureSubmit/src/Services/Gateway/HpsGiftCardService.php ADDED
@@ -0,0 +1,272 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsGiftCardService extends HpsSoapGatewayService
4
+ {
5
+ public function __construct(HpsServicesConfig $config)
6
+ {
7
+ parent::__construct($config);
8
+ }
9
+
10
+ public function activate($amount, $currency, $giftCard)
11
+ {
12
+ HpsInputValidation::checkCurrency($currency);
13
+ $amount = HpsInputValidation::checkAmount($amount);
14
+ $txnType = 'GiftCardActivate';
15
+
16
+ $xml = new DOMDocument();
17
+ $hpsTransaction = $xml->createElement('hps:Transaction');
18
+ $hpsGiftCard = $xml->createElement('hps:'.$txnType);
19
+ $hpsBlock1 = $xml->createElement('hps:Block1');
20
+
21
+ $hpsBlock1->appendChild($xml->createElement('hps:Amt', $amount));
22
+ $hpsBlock1->appendChild($this->_hydrateGiftCardData($giftCard, $xml));
23
+
24
+ $hpsGiftCard->appendChild($hpsBlock1);
25
+ $hpsTransaction->appendChild($hpsGiftCard);
26
+
27
+ return $this->_submitTransaction($hpsTransaction, $txnType);
28
+ }
29
+
30
+ public function addValue($amount, $currency, $giftCard)
31
+ {
32
+ HpsInputValidation::checkCurrency($currency);
33
+ $amount = HpsInputValidation::checkAmount($amount);
34
+ $txnType = 'GiftCardAddValue';
35
+
36
+ $xml = new DOMDocument();
37
+ $hpsTransaction = $xml->createElement('hps:Transaction');
38
+ $hpsGiftCard = $xml->createElement('hps:'.$txnType);
39
+ $hpsBlock1 = $xml->createElement('hps:Block1');
40
+
41
+ $hpsBlock1->appendChild($xml->createElement('hps:Amt', $amount));
42
+ $hpsBlock1->appendChild($this->_hydrateGiftCardData($giftCard, $xml));
43
+
44
+ $hpsGiftCard->appendChild($hpsBlock1);
45
+ $hpsTransaction->appendChild($hpsGiftCard);
46
+
47
+ return $this->_submitTransaction($hpsTransaction, $txnType);
48
+ }
49
+
50
+ public function alias($action, $giftCard, $aliasStr)
51
+ {
52
+ $txnType = 'GiftCardAlias';
53
+
54
+ $xml = new DOMDocument();
55
+ $hpsTransaction = $xml->createElement('hps:Transaction');
56
+ $hpsGiftCardAlias = $xml->createElement('hps:'. $txnType);
57
+ $hpsBlock1 = $xml->createElement('hps:Block1');
58
+
59
+ $hpsBlock1->appendChild($xml->createElement('hps:Action', strtoupper($action)));
60
+ $hpsBlock1->appendChild($xml->createElement('hps:Alias', $aliasStr));
61
+ $hpsBlock1->appendChild($this->_hydrateGiftCardData($giftCard, $xml));
62
+
63
+ $hpsGiftCardAlias->appendChild($hpsBlock1);
64
+ $hpsTransaction->appendChild($hpsGiftCardAlias);
65
+
66
+ return $this->_submitTransaction($hpsTransaction, $txnType);
67
+ }
68
+
69
+ public function balance($giftCard)
70
+ {
71
+ $txnType = 'GiftCardBalance';
72
+
73
+ $xml = new DOMDocument();
74
+ $hpsTransaction = $xml->createElement('hps:Transaction');
75
+ $hpsGiftCard = $xml->createElement('hps:'. $txnType);
76
+ $hpsBlock1 = $xml->createElement('hps:Block1');
77
+
78
+ $hpsBlock1->appendChild($this->_hydrateGiftCardData($giftCard, $xml));
79
+
80
+ $hpsGiftCard->appendChild($hpsBlock1);
81
+ $hpsTransaction->appendChild($hpsGiftCard);
82
+
83
+ return $this->_submitTransaction($hpsTransaction, $txnType);
84
+ }
85
+
86
+ public function deactivate($giftCard)
87
+ {
88
+ $txnType = 'GiftCardDeactivate';
89
+
90
+ $xml = new DOMDocument();
91
+ $hpsTransaction = $xml->createElement('hps:Transaction');
92
+ $hpsGiftCard = $xml->createElement('hps:'. $txnType);
93
+ $hpsBlock1 = $xml->createElement('hps:Block1');
94
+
95
+ $hpsBlock1->appendChild($this->_hydrateGiftCardData($giftCard, $xml));
96
+
97
+ $hpsGiftCard->appendChild($hpsBlock1);
98
+ $hpsTransaction->appendChild($hpsGiftCard);
99
+
100
+ return $this->_submitTransaction($hpsTransaction, $txnType);
101
+ }
102
+
103
+ public function replace($oldGiftCard, $newGiftCard)
104
+ {
105
+ $txnType = 'GiftCardReplace';
106
+
107
+ $xml = new DOMDocument();
108
+ $hpsTransaction = $xml->createElement('hps:Transaction');
109
+ $hpsGiftCard = $xml->createElement('hps:'. $txnType);
110
+ $hpsBlock1 = $xml->createElement('hps:Block1');
111
+
112
+ $hpsBlock1->appendChild($this->_hydrateGiftCardData($oldGiftCard, $xml, 'OldCardData'));
113
+ $hpsBlock1->appendChild($this->_hydrateGiftCardData($newGiftCard, $xml, 'NewCardData'));
114
+
115
+ $hpsGiftCard->appendChild($hpsBlock1);
116
+ $hpsTransaction->appendChild($hpsGiftCard);
117
+
118
+ return $this->_submitTransaction($hpsTransaction, $txnType);
119
+ }
120
+
121
+ public function reverse($cardData, $amount, $currency = 'usd')
122
+ {
123
+ $txnType = 'GiftCardReversal';
124
+
125
+ HpsInputValidation::checkCurrency($currency);
126
+ $amount = HpsInputValidation::checkAmount($amount);
127
+
128
+ $xml = new DOMDocument();
129
+ $hpsTransaction = $xml->createElement('hps:Transaction');
130
+ $hpsGiftCard = $xml->createElement('hps:'. $txnType);
131
+ $hpsBlock1 = $xml->createElement('hps:Block1');
132
+
133
+ $hpsBlock1->appendChild($xml->createElement('hps:Amt', $amount));
134
+ if ($cardData instanceof HpsGiftCard) {
135
+ $hpsBlock1->appendChild($this->_hydrateGiftCardData($cardData, $xml));
136
+ } else {
137
+ $hpsBlock1->appendChild($xml->createElement('hps:GatewayTxnId', $cardData));
138
+ }
139
+
140
+ $hpsGiftCard->appendChild($hpsBlock1);
141
+ $hpsTransaction->appendChild($hpsGiftCard);
142
+
143
+ return $this->_submitTransaction($hpsTransaction, $txnType);
144
+ }
145
+
146
+ public function reward($giftCard, $amount, $currency = 'usd', $gratuity = null, $tax = null)
147
+ {
148
+ $txnType = 'GiftCardReward';
149
+
150
+ HpsInputValidation::checkCurrency($currency);
151
+ $amount = HpsInputValidation::checkAmount($amount);
152
+
153
+ $xml = new DOMDocument();
154
+ $hpsTransaction = $xml->createElement('hps:Transaction');
155
+ $hpsGiftCard = $xml->createElement('hps:'. $txnType);
156
+ $hpsBlock1 = $xml->createElement('hps:Block1');
157
+
158
+ $hpsBlock1->appendChild($xml->createElement('hps:Amt', $amount));
159
+ $hpsBlock1->appendChild($this->_hydrateGiftCardData($giftCard, $xml));
160
+ if (strtolower($currency) == 'usd' || $currency == 'points') {
161
+ $hpsBlock1->appendChild($xml->createElement('hps:Currency', (strtolower($currency) == 'usd' ? 'USD' : 'POINTS')));
162
+ }
163
+ if ($gratuity != null) {
164
+ $hpsBlock1->appendChild($xml->createElement('hps:GratuityAmtInfo', $gratuity));
165
+ }
166
+ if ($tax != null) {
167
+ $hpsBlock1->appendChild($xml->createElement('hps:TaxAmtInfo', $tax));
168
+ }
169
+
170
+ $hpsGiftCard->appendChild($hpsBlock1);
171
+ $hpsTransaction->appendChild($hpsGiftCard);
172
+
173
+ return $this->_submitTransaction($hpsTransaction, $txnType);
174
+ }
175
+
176
+ public function sale($giftCard, $amount, $currency = 'usd', $gratuity = null, $tax = null)
177
+ {
178
+ $txnType = 'GiftCardSale';
179
+
180
+ HpsInputValidation::checkCurrency($currency);
181
+ $amount = HpsInputValidation::checkAmount($amount);
182
+
183
+ $xml = new DOMDocument();
184
+ $hpsTransaction = $xml->createElement('hps:Transaction');
185
+ $hpsGiftCard = $xml->createElement('hps:'. $txnType);
186
+ $hpsBlock1 = $xml->createElement('hps:Block1');
187
+
188
+ $hpsBlock1->appendChild($xml->createElement('hps:Amt', $amount));
189
+ $hpsBlock1->appendChild($this->_hydrateGiftCardData($giftCard, $xml));
190
+ if (strtolower($currency) == 'usd' || $currency == 'points') {
191
+ $hpsBlock1->appendChild($xml->createElement('hps:Currency', (strtolower($currency) == 'usd' ? 'USD' : 'POINTS')));
192
+ }
193
+ if ($gratuity != null) {
194
+ $hpsBlock1->appendChild($xml->createElement('hps:GratuityAmtInfo', $gratuity));
195
+ }
196
+ if ($tax != null) {
197
+ $hpsBlock1->appendChild($xml->createElement('hps:TaxAmtInfo', $tax));
198
+ }
199
+
200
+ $hpsGiftCard->appendChild($hpsBlock1);
201
+ $hpsTransaction->appendChild($hpsGiftCard);
202
+
203
+ return $this->_submitTransaction($hpsTransaction, $txnType);
204
+ }
205
+
206
+ public function void($transactionId)
207
+ {
208
+ $txnType = 'GiftCardVoid';
209
+
210
+ $xml = new DOMDocument();
211
+ $hpsTransaction = $xml->createElement('hps:Transaction');
212
+ $hpsGiftCard = $xml->createElement('hps:'. $txnType);
213
+ $hpsBlock1 = $xml->createElement('hps:Block1');
214
+
215
+ $hpsBlock1->appendChild($xml->createElement('hps:GatewayTxnId', $transactionId));
216
+
217
+ $hpsGiftCard->appendChild($hpsBlock1);
218
+ $hpsTransaction->appendChild($hpsGiftCard);
219
+
220
+ return $this->_submitTransaction($hpsTransaction, $txnType);
221
+ }
222
+
223
+ private function _submitTransaction($transaction, $txnType, $clientTxnId = null)
224
+ {
225
+ $response = $this->doTransaction($transaction, $clientTxnId);
226
+
227
+ HpsGatewayResponseValidation::checkResponse($response, $txnType);
228
+ HpsIssuerResponseValidation::checkResponse(
229
+ $response->Header->GatewayTxnId,
230
+ $response->Transaction->$txnType->RspCode,
231
+ $response->Transaction->$txnType->RspText
232
+ );
233
+
234
+ $rvalue = '';
235
+ switch ($txnType) {
236
+ case 'GiftCardActivate':
237
+ $rvalue = HpsGiftCardActivate::fromDict($response, $txnType, 'HpsGiftCardActivate');
238
+ break;
239
+ case 'GiftCardAddValue':
240
+ $rvalue = HpsGiftCardAddValue::fromDict($response, $txnType, 'HpsGiftCardAddValue');
241
+ break;
242
+ case 'GiftCardAlias':
243
+ $rvalue = HpsGiftCardAlias::fromDict($response, $txnType, 'HpsGiftCardAlias');
244
+ break;
245
+ case 'GiftCardBalance':
246
+ $rvalue = HpsGiftCardBalance::fromDict($response, $txnType, 'HpsGiftCardBalance');
247
+ break;
248
+ case 'GiftCardDeactivate':
249
+ $rvalue = HpsGiftCardDeactivate::fromDict($response, $txnType, 'HpsGiftCardDeactivate');
250
+ break;
251
+ case 'GiftCardReplace':
252
+ $rvalue = HpsGiftCardReplace::fromDict($response, $txnType, 'HpsGiftCardReplace');
253
+ break;
254
+ case 'GiftCardReward':
255
+ $rvalue = HpsGiftCardReward::fromDict($response, $txnType, 'HpsGiftCardReward');
256
+ break;
257
+ case 'GiftCardSale':
258
+ $rvalue = HpsGiftCardSale::fromDict($response, $txnType, 'HpsGiftCardSale');
259
+ break;
260
+ case 'GiftCardVoid':
261
+ $rvalue = HpsGiftCardVoid::fromDict($response, $txnType, 'HpsGiftCardVoid');
262
+ break;
263
+ case 'GiftCardReversal':
264
+ $rvalue = HpsGiftCardReversal::fromDict($response, $txnType, 'HpsGiftCardReversal');
265
+ break;
266
+ default:
267
+ break;
268
+ }
269
+
270
+ return $rvalue;
271
+ }
272
+ }
lib/SecureSubmit/src/Services/Gateway/HpsRestGatewayService.php ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsRestGatewayService extends HpsGatewayServiceAbstract
4
+ {
5
+ const CERT_URL = '';
6
+ const PROD_URL = '';
7
+ const UAT_URL = 'https://api-uat.heartlandportico.com/payplan.v2';
8
+ protected $limit = null;
9
+ protected $offset = null;
10
+ protected $searchFields = null;
11
+
12
+ public function page($limit, $offset)
13
+ {
14
+ $this->limit = $limit;
15
+ $this->offset = $offset;
16
+ return $this;
17
+ }
18
+
19
+ public function search($searchFields)
20
+ {
21
+ $this->searchFields = $searchFields;
22
+ return $this;
23
+ }
24
+
25
+ protected function doRequest($verb, $endpoint, $data = null)
26
+ {
27
+ $url = $this->_gatewayUrlForKey() . '/' . $endpoint;
28
+
29
+ if (isset($this->limit) && isset($this->offset)) {
30
+ $paging = array(
31
+ 'limit' => $this->limit,
32
+ 'offset' => $this->offset,
33
+ );
34
+ $url .= '?' . http_build_query($paging);
35
+ }
36
+
37
+ if ($this->searchFields != null) {
38
+ $data = $this->searchFields;
39
+ }
40
+
41
+ $encodedData = json_encode($data);
42
+
43
+ $identity = array();
44
+ if (isset($this->_config->siteId)) {
45
+ $identity[0] = 'SiteID='.$this->_config->siteId;
46
+ }
47
+ if (isset($this->_config->deviceId)) {
48
+ $identity[1] = 'DeviceID='.$this->_config->deviceId;
49
+ }
50
+ if (isset($this->_config->licenseId)) {
51
+ $identity[2] = 'LicenseID='.$this->_config->licenseId;
52
+ }
53
+
54
+ $auth = isset($this->_config->username)
55
+ ? $this->_config->username.':'.$this->_config->password
56
+ : $this->_config->secretApiKey;
57
+ $header = array(
58
+ 'Authorization: Basic '.base64_encode($auth),
59
+ 'Content-Type: application/json; charset=utf-8',
60
+ 'Content-Length: '.strlen($encodedData),
61
+ );
62
+
63
+ if (isset($this->_config->username)) {
64
+ $header[] = 'HPS-Identity: '.implode(',', $identity);
65
+ }
66
+ $keyType = HpsServicesConfig::KEY_TYPE_SECRET;
67
+ return $this->submitRequest($url, $header, $encodedData, $verb, $keyType);
68
+ }
69
+
70
+ protected function processResponse($curlResponse, $curlInfo, $curlError)
71
+ {
72
+ $response = json_decode($curlResponse);
73
+
74
+ switch ($curlInfo['http_code']) {
75
+ case '200':
76
+ case '204':
77
+ return $response;
78
+ break;
79
+ case '400':
80
+ throw new HpsException($response->error->message);
81
+ break;
82
+ default:
83
+ throw new HpsException('Unexpected response');
84
+ break;
85
+ }
86
+ }
87
+
88
+ protected function hydrateObject($result, $type)
89
+ {
90
+ return $type::fromStdClass($result);
91
+ }
92
+
93
+ protected function hydrateSearchResults($resultSet, $type)
94
+ {
95
+ $results = array();
96
+ foreach ($resultSet->results as $result) {
97
+ $results[] = $this->hydrateObject($result, $type);
98
+ }
99
+ unset($result);
100
+
101
+ return (object)array(
102
+ 'offset' => $resultSet->offset,
103
+ 'limit' => $resultSet->limit,
104
+ 'total' => $resultSet->totalMatchingRecords,
105
+ 'results' => $results,
106
+ );
107
+ }
108
+
109
+ private function _gatewayUrlForKey()
110
+ {
111
+ if ($this->_config->secretApiKey != null && $this->_config->secretApiKey != "") {
112
+ if (strpos($this->_config->secretApiKey, '_cert_') !== false) {
113
+ return self::CERT_URL;
114
+ } else if (strpos($this->_config->secretApiKey, '_uat_') !== false) {
115
+ return self::UAT_URL;
116
+ } else {
117
+ return self::PROD_URL;
118
+ }
119
+ } else {
120
+ return $this->_config->soapServiceUri;
121
+ }
122
+ }
123
+ }
lib/SecureSubmit/src/Services/Gateway/HpsSoapGatewayService.php ADDED
@@ -0,0 +1,289 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsSoapGatewayService extends HpsGatewayServiceAbstract
4
+ {
5
+ public function doTransaction($transaction, $clientTransactionId = null)
6
+ {
7
+ $xml = new DOMDocument('1.0', 'utf-8');
8
+ $soapEnvelope = $xml->createElement('soapenv:Envelope');
9
+ $soapEnvelope->setAttribute('xmlns:soapenv', 'http://schemas.xmlsoap.org/soap/envelope/');
10
+ $soapEnvelope->setAttribute('xmlns:hps', 'http://Hps.Exchange.PosGateway');
11
+
12
+ $soapBody = $xml->createElement('soapenv:Body');
13
+ $hpsRequest = $xml->createElement('hps:PosRequest');
14
+
15
+ $hpsVersion = $xml->createElement('hps:Ver1.0');
16
+ $hpsHeader = $xml->createElement('hps:Header');
17
+
18
+ if ($this->_config->secretApiKey != null && $this->_config->secretApiKey != "") {
19
+ $hpsHeader->appendChild($xml->createElement('hps:SecretAPIKey', $this->_config->secretApiKey));
20
+ } else {
21
+ $hpsHeader->appendChild($xml->createElement('hps:SiteId', $this->_config->siteId));
22
+ $hpsHeader->appendChild($xml->createElement('hps:DeviceId', $this->_config->deviceId));
23
+ $hpsHeader->appendChild($xml->createElement('hps:LicenseId', $this->_config->licenseId));
24
+ $hpsHeader->appendChild($xml->createElement('hps:UserName', $this->_config->username));
25
+ $hpsHeader->appendChild($xml->createElement('hps:Password', $this->_config->password));
26
+ }
27
+ if ($this->_config->developerId != null && $this->_config->developerId != "") {
28
+ $hpsHeader->appendChild($xml->createElement('hps:DeveloperID', $this->_config->developerId));
29
+ $hpsHeader->appendChild($xml->createElement('hps:VersionNbr', $this->_config->versionNumber));
30
+ $hpsHeader->appendChild($xml->createElement('hps:SiteTrace', $this->_config->siteTrace));
31
+ }
32
+ if ($clientTransactionId != null) {
33
+ $hpsHeader->appendChild($xml->createElement('hps:ClientTxnId', $clientTransactionId));
34
+ }
35
+
36
+ $hpsVersion->appendChild($hpsHeader);
37
+ $transaction = $xml->importNode($transaction, true);
38
+ $hpsVersion->appendChild($transaction);
39
+
40
+ $hpsRequest->appendChild($hpsVersion);
41
+ $soapBody->appendChild($hpsRequest);
42
+ $soapEnvelope->appendChild($soapBody);
43
+ $xml->appendChild($soapEnvelope);
44
+
45
+ $url = $this->_gatewayUrlForKey();
46
+ $header = array(
47
+ 'Content-type: text/xml;charset="utf-8"',
48
+ 'Accept: text/xml',
49
+ 'SOAPAction: ""',
50
+ 'Content-length: '.strlen($xml->saveXML()),
51
+ );
52
+ $data = $xml->saveXML();
53
+ Mage::log($data);
54
+
55
+ return $this->submitRequest($url, $header, $data);
56
+ }
57
+
58
+ protected function processResponse($curlResponse, $curlInfo, $curlError)
59
+ {
60
+ Mage::log($curlResponse);
61
+ switch ($curlInfo['http_code']) {
62
+ case '200':
63
+ $responseObject = $this->_XML2Array($curlResponse);
64
+ $ver = "Ver1.0";
65
+ return $responseObject->$ver;
66
+ break;
67
+ case '500':
68
+ $faultString = $this->_XMLFault2String($curlResponse);
69
+ throw new HpsException($faultString);
70
+ break;
71
+ default:
72
+ throw new HpsException('Unexpected response');
73
+ break;
74
+ }
75
+ }
76
+
77
+ protected function _hydrateAdditionalTxnFields($details, DOMDocument $xml)
78
+ {
79
+ $additionalTxnFields = $xml->createElement('hps:AdditionalTxnFields');
80
+
81
+ if ($details->memo != null && $details->memo != "") {
82
+ $additionalTxnFields->appendChild($xml->createElement('hps:Description', $details->memo));
83
+ }
84
+
85
+ if ($details->invoiceNumber != null && $details->invoiceNumber != "") {
86
+ $additionalTxnFields->appendChild($xml->createElement('hps:InvoiceNbr', $details->invoiceNumber));
87
+ }
88
+
89
+ if ($details->customerId != null && $details->customerId != "") {
90
+ $additionalTxnFields->appendChild($xml->createElement('hps:CustomerID', $details->customerId));
91
+ }
92
+
93
+ return $additionalTxnFields;
94
+ }
95
+
96
+ protected function _hydrateCardHolderData(HpsCardHolder $cardHolder, DOMDocument $xml)
97
+ {
98
+ $cardHolderData = $xml->createElement('hps:CardHolderData');
99
+ $cardHolderData->appendChild($xml->createElement('hps:CardHolderFirstName', $cardHolder->firstName));
100
+ $cardHolderData->appendChild($xml->createElement('hps:CardHolderLastName', $cardHolder->lastName));
101
+ $cardHolderData->appendChild($xml->createElement('hps:CardHolderEmail', $cardHolder->email));
102
+ $cardHolderData->appendChild($xml->createElement('hps:CardHolderPhone', $cardHolder->phone));
103
+ $cardHolderData->appendChild($xml->createElement('hps:CardHolderAddr', $cardHolder->address->address));
104
+ $cardHolderData->appendChild($xml->createElement('hps:CardHolderCity', $cardHolder->address->city));
105
+ $cardHolderData->appendChild($xml->createElement('hps:CardHolderState', $cardHolder->address->state));
106
+ $cardHolderData->appendChild($xml->createElement('hps:CardHolderZip', $cardHolder->address->zip));
107
+
108
+ return $cardHolderData;
109
+ }
110
+
111
+ protected function _hydrateCheckData(HpsCheck $check, DOMDocument $xml)
112
+ {
113
+ $checkData = $xml->createElement('hps:AccountInfo');
114
+
115
+ if ($check->accountNumber != null) {
116
+ $checkData->appendChild($xml->createElement('hps:AccountNumber', $check->accountNumber));
117
+ }
118
+
119
+ if ($check->checkNumber != null) {
120
+ $checkData->appendChild($xml->createElement('hps:CheckNumber', $check->checkNumber));
121
+ }
122
+
123
+ if ($check->micrNumber != null) {
124
+ $checkData->appendChild($xml->createElement('hps:MICRData', $check->micrNumber));
125
+ }
126
+
127
+ if ($check->routingNumber != null) {
128
+ $checkData->appendChild($xml->createElement('hps:RoutingNumber', $check->routingNumber));
129
+ }
130
+
131
+ if ($check->accountType != null) {
132
+ $checkData->appendChild($xml->createElement('hps:AccountType', strtoupper($check->accountType)));
133
+ }
134
+
135
+ return $checkData;
136
+ }
137
+
138
+ protected function _hydrateConsumerInfo(HpsCheck $check, DOMDocument $xml)
139
+ {
140
+ $consumerInfo = $xml->createElement('hps:ConsumerInfo');
141
+
142
+ if ($check->checkHolder->address != null) {
143
+ $consumerInfo->appendChild($xml->createElement('hps:Address1', $check->checkHolder->address->address));
144
+ $consumerInfo->appendChild($xml->createElement('hps:City', $check->checkHolder->address->city));
145
+ $consumerInfo->appendChild($xml->createElement('hps:State', $check->checkHolder->address->state));
146
+ $consumerInfo->appendChild($xml->createElement('hps:Zip', $check->checkHolder->address->zip));
147
+ }
148
+
149
+ if ($check->checkHolder->checkName != null) {
150
+ $consumerInfo->appendChild($xml->createElement('hps:CheckName', $check->checkHolder->checkName));
151
+ }
152
+
153
+ if ($check->checkHolder->courtesyCard != null) {
154
+ $consumerInfo->appendChild($xml->createElement('hps:CourtesyCard', $check->checkHolder->courtesyCard));
155
+ }
156
+
157
+ if ($check->checkHolder->dlNumber != null) {
158
+ $consumerInfo->appendChild($xml->createElement('hps:DLNumber', $check->checkHolder->dlNumber));
159
+ }
160
+
161
+ if ($check->checkHolder->dlState != null) {
162
+ $consumerInfo->appendChild($xml->createElement('hps:DLState', $check->checkHolder->dlState));
163
+ }
164
+
165
+ if ($check->checkHolder->email != null) {
166
+ $consumerInfo->appendChild($xml->createElement('hps:EmailAddress', $check->checkHolder->email));
167
+ }
168
+
169
+ if ($check->checkHolder->firstName != null) {
170
+ $consumerInfo->appendChild($xml->createElement('hps:FirstName', $check->checkHolder->firstName));
171
+ }
172
+
173
+ if ($check->checkHolder->lastName != null) {
174
+ $consumerInfo->appendChild($xml->createElement('hps:LastName', $check->checkHolder->lastName));
175
+ }
176
+
177
+ if ($check->checkHolder->phone != null) {
178
+ $consumerInfo->appendChild($xml->createElement('hps:PhoneNumber', $check->checkHolder->phone));
179
+ }
180
+
181
+ return $consumerInfo;
182
+ }
183
+
184
+ protected function _hydrateCPCData(HpsCPCData $cpcData, DOMDocument $xml)
185
+ {
186
+ $cpcDataElement = $xml->createElement('hps:CPCData');
187
+ $cpcDataElement->appendChild($xml->createElement('hps:CardHolderPONbr', $cpcData->CardHolderPONbr));
188
+ $cpcDataElement->appendChild($xml->createElement('hps:TaxAmt', $cpcData->TaxAmt));
189
+ $cpcDataElement->appendChild($xml->createElement('hps:TaxType', $cpcData->TaxType));
190
+
191
+ return $cpcDataElement;
192
+ }
193
+
194
+ protected function _hydrateDirectMarketData(HpsDirectMarketData $data, DOMDocument $xml)
195
+ {
196
+ $directMktDataElement = $xml->createElement('hps:DirectMktData');
197
+ $directMktDataElement->appendChild($xml->createElement('hps:DirectMktInvoiceNbr', $data->invoiceNumber));
198
+ $directMktDataElement->appendChild($xml->createElement('hps:DirectMktShipMonth', $data->shipMonth));
199
+ $directMktDataElement->appendChild($xml->createElement('hps:DirectMktShipDay', $data->shipDay));
200
+
201
+ return $directMktDataElement;
202
+ }
203
+
204
+ protected function _hydrateEncryptionData(HpsEncryptionData $encryptionData, DOMDocument $xml)
205
+ {
206
+ $encData = $xml->createElement('hps:EncryptionData');
207
+ if ($encryptionData->encryptedTrackNumber != null) {
208
+ $encData->appendChild($xml->createElement('hps:EncryptedTrackNumber', $encryptionData->encryptedTrackNumber));
209
+ }
210
+ $encData->appendChild($xml->createElement('hps:KSN', $encryptionData->ksn));
211
+ $encData->appendChild($xml->createElement('hps:KTB', $encryptionData->ksn));
212
+ $encData->appendChild($xml->createElement('hps:Version', $encryptionData->version));
213
+ return $encData;
214
+ }
215
+
216
+ protected function _hydrateGiftCardData(HpsGiftCard $giftCard, DOMDocument $xml, $elementName = 'CardData')
217
+ {
218
+ $giftCardData = $xml->createElement('hps:'.$elementName);
219
+ if ($giftCard->isTrackData == true) {
220
+ $giftCardData->appendChild($xml->createElement('hps:TrackData', $giftCard->number));
221
+ } else {
222
+ $giftCardData->appendChild($xml->createElement('hps:CardNbr', $giftCard->number));
223
+ }
224
+
225
+ if ($giftCard->encryptionData != null) {
226
+ $giftCardData->appendChild($this->_hydrateEncryptionData($giftCard->encryptionData, $xml));
227
+ }
228
+
229
+ return $giftCardData;
230
+ }
231
+
232
+ protected function _hydrateManualEntry(HpsCreditCard $card, DOMDocument $xml)
233
+ {
234
+ $manualEntry = $xml->createElement('hps:ManualEntry');
235
+
236
+ if (isset($card->number)) {
237
+ $manualEntry->appendChild($xml->createElement('hps:CardNbr', $card->number));
238
+ }
239
+
240
+ if (isset($card->expMonth)) {
241
+ $manualEntry->appendChild($xml->createElement('hps:ExpMonth', $card->expMonth));
242
+ }
243
+
244
+ if (isset($card->expYear)) {
245
+ $manualEntry->appendChild($xml->createElement('hps:ExpYear', $card->expYear));
246
+ }
247
+
248
+ if (isset($card->cvv)) {
249
+ $manualEntry->appendChild($xml->createElement('hps:CVV2', $card->cvv));
250
+ }
251
+
252
+ $manualEntry->appendChild($xml->createElement('hps:CardPresent', 'N'));
253
+ $manualEntry->appendChild($xml->createElement('hps:ReaderPresent', 'N'));
254
+
255
+ return $manualEntry;
256
+ }
257
+
258
+ private function _gatewayUrlForKey()
259
+ {
260
+ if ($this->_config->secretApiKey != null && $this->_config->secretApiKey != "") {
261
+ if (strpos($this->_config->secretApiKey, '_cert_') !== false) {
262
+ return "https://posgateway.cert.secureexchange.net/Hps.Exchange.PosGateway/PosGatewayService.asmx";
263
+ } else if (strpos($this->_config->secretApiKey, '_uat_') !== false) {
264
+ return "https://posgateway.uat.secureexchange.net/Hps.Exchange.PosGateway/PosGatewayService.asmx";
265
+ } else {
266
+ return "https://posgateway.secureexchange.net/Hps.Exchange.PosGateway/PosGatewayService.asmx";
267
+ }
268
+ } else {
269
+ return $this->_config->soapServiceUri;
270
+ }
271
+ }
272
+
273
+ private function _XML2Array($xml)
274
+ {
275
+ $envelope = simplexml_load_string($xml, "SimpleXMLElement", 0, 'http://schemas.xmlsoap.org/soap/envelope/');
276
+ foreach ($envelope->Body as $response) {
277
+ foreach ($response->children('http://Hps.Exchange.PosGateway') as $item) {
278
+ return $item;
279
+ }
280
+ }
281
+ }
282
+
283
+ private function _XMLFault2String($xml)
284
+ {
285
+ $dom = new DOMDocument();
286
+ $dom->loadXML($xml);
287
+ return $dom->getElementsByTagName('faultstring')->item(0)->nodeValue;
288
+ }
289
+ }
lib/SecureSubmit/src/Services/Gateway/HpsTokenService.php ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ // This should only be used for testing tokens.
3
+ class HpsTokenService extends HpsRestGatewayService
4
+ {
5
+ protected $_publicAPIKey = null;
6
+ protected $_url = null;
7
+
8
+ public function __construct($publicAPIKey)
9
+ {
10
+ $this->_config = new HpsServicesConfig();
11
+ $this->_config->publicApiKey = $publicAPIKey;
12
+
13
+ $components = explode("_", $publicAPIKey);
14
+ if (count($components) == 3 && strtolower($components[1]) == "prod") {
15
+ $this->_url = "https://api.heartlandportico.com/SecureSubmit.v1/api/token";
16
+ } else {
17
+ $this->_url = "https://posgateway.cert.secureexchange.net/Hps.Exchange.PosGateway.Hpf.v1/api/token";
18
+ }
19
+ }
20
+
21
+ public function getToken(HpsCreditCard $cardData)
22
+ {
23
+ $data = array();
24
+ $data['api_key'] = $this->_config->publicApiKey;
25
+ $data['object'] = 'token';
26
+ $data['token_type'] = 'supt';
27
+ $data['_method'] = 'post';
28
+ $data['card[number]'] = $cardData->number;
29
+ $data['card[cvc]'] = $cardData->cvv;
30
+ $data['card[exp_month]'] = $cardData->expMonth;
31
+ $data['card[exp_year]'] = $cardData->expYear;
32
+
33
+ $url = $this->_url ."?". http_build_query($data);
34
+ $header = array('Content-type: application/json');
35
+
36
+ return $this->submitRequest($url, $header, null, 'GET', HpsServicesConfig::KEY_TYPE_PUBLIC);
37
+ }
38
+
39
+ protected function processResponse($curlResponse, $curlInfo, $curlError)
40
+ {
41
+ $response = json_decode($curlResponse);
42
+
43
+ if (isset($response->error) && is_object($response->error)) {
44
+ throw new HpsException($response->error->message, $response->error->code);
45
+ }
46
+
47
+ return $response;
48
+ }
49
+
50
+ protected function _isConfigInvalid()
51
+ {
52
+ return $this->_config->publicApiKey == null || $this->_url == null;
53
+ }
54
+ }
lib/SecureSubmit/src/Services/Gateway/PayPlan/HpsPayPlanCustomerService.php ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsPayPlanCustomerService extends HpsRestGatewayService
4
+ {
5
+ public function add(HpsPayPlanCustomer $customer)
6
+ {
7
+ $result = $this->doRequest('POST', 'customers', $customer->getEditableFieldsWithValues());
8
+ return $this->hydrateObject($result, 'HpsPayPlanCustomer');
9
+ }
10
+
11
+ public function edit(HpsPayPlanCustomer $customer)
12
+ {
13
+ $data = $customer->getEditableFieldsWithValues();
14
+ $result = $this->doRequest('PUT', 'customers/'.$customer->customerKey, $data);
15
+ return $this->hydrateObject($result, 'HpsPayPlanCustomer');
16
+ }
17
+
18
+ public function findAll($searchFields = array())
19
+ {
20
+ // Cannot have an array as the root object
21
+ // in a JSON document
22
+ $data = $searchFields === array() ? (object)array() : $searchFields;
23
+ $results = $this
24
+ ->doRequest('POST', 'searchCustomers', $data);
25
+
26
+ return $this->hydrateSearchResults($results, 'HpsPayPlanCustomer');
27
+ }
28
+
29
+ public function get($customer)
30
+ {
31
+ $id = null;
32
+ if ($customer instanceof HpsPayPlanCustomer) {
33
+ $id = $customer->customerKey;
34
+ } else {
35
+ $id = $customer;
36
+ }
37
+ $result = $this->doRequest('GET', 'customers/'.$id);
38
+ return $this->hydrateObject($result, 'HpsPayPlanCustomer');
39
+ }
40
+
41
+ public function delete($customer, $forceDelete = false)
42
+ {
43
+ $id = null;
44
+ if ($customer instanceof HpsPayPlanCustomer) {
45
+ $id = $customer->customerKey;
46
+ } else {
47
+ $id = $customer;
48
+ }
49
+
50
+ $data = array(
51
+ 'forceDelete' => $forceDelete,
52
+ );
53
+ return $this->doRequest('DELETE', 'customers/'.$id, $data);
54
+ }
55
+ }
lib/SecureSubmit/src/Services/Gateway/PayPlan/HpsPayPlanPaymentMethodService.php ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsPayPlanPaymentMethodService extends HpsRestGatewayService
4
+ {
5
+ public function add(HpsPayPlanPaymentMethod $paymentMethod)
6
+ {
7
+ $result = null;
8
+ if ($paymentMethod->paymentMethodType == HpsPayPlanPaymentMethodType::ACH) {
9
+ $result = $this->addACH($paymentMethod);
10
+ } else {
11
+ $result = $this->addCreditCard($paymentMethod);
12
+ }
13
+ return $this->hydrateObject($result, 'HpsPayPlanPaymentMethod');
14
+ }
15
+
16
+ public function edit(HpsPayPlanPaymentMethod $paymentMethod)
17
+ {
18
+ $result = null;
19
+ if ($paymentMethod->paymentMethodType == HpsPayPlanPaymentMethodType::ACH) {
20
+ $result = $this->editACH($paymentMethod);
21
+ } else {
22
+ $result = $this->editCreditCard($paymentMethod);
23
+ }
24
+ return $this->hydrateObject($result, 'HpsPayPlanPaymentMethod');
25
+ }
26
+
27
+ public function findAll($searchFields = array())
28
+ {
29
+ // Cannot have an array as the root object
30
+ // in a JSON document
31
+ $data = $searchFields === array() ? (object)array() : $searchFields;
32
+ $results = $this
33
+ ->doRequest('POST', 'searchPaymentMethods', $data);
34
+
35
+ return $this->hydrateSearchResults($results, 'HpsPayPlanPaymentMethod');
36
+ }
37
+
38
+ public function get($paymentMethod)
39
+ {
40
+ $id = null;
41
+ if ($paymentMethod instanceof HpsPayPlanPaymentMethod) {
42
+ $id = $paymentMethod->paymentMethodKey;
43
+ } else {
44
+ $id = $paymentMethod;
45
+ }
46
+ $result = $this->doRequest('GET', 'paymentMethods/'.$id);
47
+ return $this->hydrateObject($result, 'HpsPayPlanPaymentMethod');
48
+ }
49
+
50
+ public function delete($paymentMethod, $forceDelete = false)
51
+ {
52
+ $id = null;
53
+ if ($paymentMethod instanceof HpsPayPlanPaymentMethod) {
54
+ $id = $paymentMethod->paymentMethodKey;
55
+ } else {
56
+ $id = $paymentMethod;
57
+ }
58
+
59
+ $data = array(
60
+ 'forceDelete' => $forceDelete,
61
+ );
62
+ return $this->doRequest('DELETE', 'paymentMethods/'.$id, $data);
63
+ }
64
+
65
+
66
+ private function addCreditCard(HpsPayPlanPaymentMethod $paymentMethod)
67
+ {
68
+ $data = $paymentMethod->getEditableFieldsWithValues();
69
+ $data['customerKey'] = $paymentMethod->customerKey;
70
+ $data['accountNumber'] = $paymentMethod->accountNumber;
71
+ return $this->doRequest('POST', 'paymentMethodsCreditCard', $data);
72
+ }
73
+
74
+ private function editCreditCard(HpsPayPlanPaymentMethod $paymentMethod)
75
+ {
76
+ $data = $paymentMethod->getEditableFieldsWithValues();
77
+ return $this->doRequest('PUT', 'paymentMethodsCreditCard/'.$paymentMethod->paymentMethodKey, $data);
78
+ }
79
+
80
+ private function addACH(HpsPayPlanPaymentMethod $paymentMethod)
81
+ {
82
+ $data = $paymentMethod->getEditableFieldsWithValues();
83
+ $data['customerKey'] = $paymentMethod->customerKey;
84
+ return $this->doRequest('POST', 'paymentMethodsACH', $data);
85
+ }
86
+
87
+ private function editACH(HpsPayPlanPaymentMethod $paymentMethod)
88
+ {
89
+ $data = $paymentMethod->getEditableFieldsWithValues();
90
+ return $this->doRequest('PUT', 'paymentMethodsACH/'.$paymentMethod->paymentMethodKey, $data);
91
+ }
92
+ }
lib/SecureSubmit/src/Services/Gateway/PayPlan/HpsPayPlanScheduleService.php ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsPayPlanScheduleService extends HpsRestGatewayService
4
+ {
5
+ public function add(HpsPayPlanSchedule $schedule)
6
+ {
7
+ $data = $schedule->getEditableFieldsWithValues();
8
+ $data['customerKey'] = $schedule->customerKey;
9
+ $data['numberOfPayments'] = $schedule->numberOfPayments;
10
+ $result = $this->doRequest('POST', 'schedules', $data);
11
+ return $this->hydrateObject($result, 'HpsPayPlanSchedule');
12
+ }
13
+
14
+ public function edit(HpsPayPlanSchedule $schedule)
15
+ {
16
+ $data = $schedule->getEditableFieldsWithValues();
17
+ $result = $this->doRequest('PUT', 'schedules/'.$schedule->scheduleKey, $data);
18
+ return $this->hydrateObject($result, 'HpsPayPlanSchedule');
19
+ }
20
+
21
+ public function findAll($searchFields = array())
22
+ {
23
+ // Cannot have an array as the root object
24
+ // in a JSON document
25
+ $data = $searchFields === array() ? (object)array() : $searchFields;
26
+ $results = $this
27
+ ->doRequest('POST', 'searchSchedules', $data);
28
+
29
+ return $this->hydrateSearchResults($results, 'HpsPayPlanSchedule');
30
+ }
31
+
32
+ public function get($schedule)
33
+ {
34
+ $id = null;
35
+ if ($schedule instanceof HpsPayPlanSchedule) {
36
+ $id = $schedule->scheduleKey;
37
+ } else {
38
+ $id = $schedule;
39
+ }
40
+ $result = $this->doRequest('GET', 'schedules/'.$id);
41
+ return $this->hydrateObject($result, 'HpsPayPlanSchedule');
42
+ }
43
+
44
+ public function delete($schedule, $forceDelete = false)
45
+ {
46
+ $id = null;
47
+ if ($schedule instanceof HpsPayPlanSchedule) {
48
+ $id = $schedule->scheduleKey;
49
+ } else {
50
+ $id = $schedule;
51
+ }
52
+
53
+ $data = array(
54
+ 'forceDelete' => $forceDelete,
55
+ );
56
+ return $this->doRequest('DELETE', 'schedules/'.$id, $data);
57
+ }
58
+ }
lib/SecureSubmit/src/Services/HpsServicesConfig.php ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class HpsServicesConfig
4
+ {
5
+ const KEY_TYPE_SECRET = 'secret';
6
+ const KEY_TYPE_PUBLIC = 'public';
7
+ const KEY_TYPE_UNKNOWN = 'unknown';
8
+ public $credentialToken = null;
9
+ public $secretApiKey = null;
10
+ public $publicApiKey = null;
11
+ public $licenseId = null;
12
+ public $siteId = null;
13
+ public $deviceId = null;
14
+ public $versionNumber = null;
15
+ public $username = null;
16
+ public $password = null;
17
+ public $developerId = null;
18
+ public $siteTrace = null;
19
+ public $useProxy = null;
20
+ public $proxyOptions = null;
21
+ public $soapServiceUri = "https://posgateway.cert.secureexchange.net/Hps.Exchange.PosGateway/PosGatewayService.asmx";
22
+ public $payPlanBaseUri = null;
23
+
24
+ public function serviceUri()
25
+ {
26
+ return $this->soapServiceUri;
27
+ }
28
+
29
+ public function setServiceUri(string $value)
30
+ {
31
+ $this->soapServiceUri = $value;
32
+ }
33
+
34
+ public function validateApiKey($keyType)
35
+ {
36
+ return true;
37
+ // return ($keyType == self::KEY_TYPE_PUBLIC && $this->validatePublicApiKey())
38
+ // || ($keyType == self::KEY_TYPE_SECRET && $this->validateSecretApiKey());
39
+ }
40
+
41
+ public function getKeyType($keyType)
42
+ {
43
+ $key = $keyType == self::KEY_TYPE_SECRET ? $this->secretApiKey : $this->publicApiKey;
44
+ switch (true) {
45
+ case substr($key, 0, 6) == 'skapi_':
46
+ return self::KEY_TYPE_SECRET;
47
+ break;
48
+ case substr($key, 0, 6) == 'pkapi_':
49
+ return self::KEY_TYPE_PUBLIC;
50
+ break;
51
+ default:
52
+ return self::KEY_TYPE_UNKNOWN;
53
+ break;
54
+ }
55
+ }
56
+
57
+ protected function validateSecretApiKey()
58
+ {
59
+ return is_string($this->secretApiKey)
60
+ && $this->getKeyType(self::KEY_TYPE_SECRET) == self::KEY_TYPE_SECRET
61
+ && strlen($this->secretApiKey) >= 48;
62
+ }
63
+
64
+ protected function validatePublicApiKey()
65
+ {
66
+ return is_string($this->publicApiKey)
67
+ && $this->getKeyType(self::KEY_TYPE_PUBLIC) == self::KEY_TYPE_PUBLIC
68
+ && strlen($this->publicApiKey) >= 28;
69
+ }
70
+ }
lib/SecureSubmit/src/Services/index.php ADDED
@@ -0,0 +1 @@
 
1
+ <?php
lib/SecureSubmit/src/index.php ADDED
@@ -0,0 +1 @@
 
1
+ <?php
package.xml CHANGED
@@ -1,20 +1,20 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Hps_Securesubmit</name>
4
- <version>1.0.6</version>
5
  <stability>stable</stability>
6
- <license uri="https://github.com/SecureSubmit/heartland-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>Fix inlined checkout javascript for older versions of Magento</notes>
14
  <authors><author><name>Heartland Payment Systems</name><user>markhagan</user><email>EntApp_DevPortal@e-hps.com</email></author></authors>
15
- <date>2015-04-03</date>
16
- <time>15:00:11</time>
17
- <contents><target name="magecommunity"><dir name="Hps"><dir name="Securesubmit"><dir name="Block"><file name="Form.php" hash="a2e7bd1c2457cc7f12cb114b6957fefb"/><file name="Info.php" hash="3fa6b51d26f335e5ca52ee58a4399a3c"/></dir><dir name="Helper"><file name="Data.php" hash="04aeff6f94f56a49cf7527518c6212a1"/></dir><dir name="Model"><file name="Payment.php" hash="3c72d498069ead0f0898bc5f3525f847"/><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="b3fde0de1a10e823ce680317738fd802"/><file name="system.xml" hash="be8a2c1d74b72b45bd14eed62cc5a5e7"/></dir><dir name="sql"><dir name="hps_securesubmit_setup"><file name="install-1.0.0.php" hash="57917d8b3b29830eb1a219466df4555b"/></dir></dir><file name=".DS_Store" hash="4a6d92e7f95a9f9208c420e97eb1d4ea"/></dir></dir></target><target name="mageweb"><dir name="js"><dir name="securesubmit"><file name="admin-checkout.js" hash="1493f7f32243bad6d4facd577a375198"/><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="ad9fbec07d00343bb53f71a835874ea4"/><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="b33260d307dd557d6fd287b32638c1aa"/><file name="HpsChargeService.php" hash="b3ae575ac87b364e4e847440792fa7c3"/><file name="HpsService.php" hash="52aefe6d72b1e4118fdd8ec04b75e28c"/><file name="HpsTokenService.php" hash="bfdee5e18ebdc2133f3512040e0da766"/></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="securesubmit.xml" hash="cc04e952cc17ea3462931a9e7a655316"/></dir><dir name="template"><dir name="securesubmit"><file name="form.phtml" hash="b6329408b11e9e979494a923e639f6cf"/></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="securesubmit.xml" hash="8aca5736bbba6ec8341cf9510c0ea5ab"/></dir><dir name="template"><dir name="securesubmit"><file name="form.phtml" hash="313ae740ba48618afac2797fddb162c9"/><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></contents>
18
  <compatible/>
19
- <dependencies><required><php><min>5.2.0</min><max>5.5.15</max></php></required></dependencies>
20
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Hps_Securesubmit</name>
4
+ <version>1.0.7</version>
5
  <stability>stable</stability>
6
+ <license uri="https://github.com/hps/heartland-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>Allows for newer versions of PHP to install the extension through Magento Connect</notes>
14
  <authors><author><name>Heartland Payment Systems</name><user>markhagan</user><email>EntApp_DevPortal@e-hps.com</email></author></authors>
15
+ <date>2015-12-15</date>
16
+ <time>18:58:58</time>
17
+ <contents><target name="magecommunity"><dir name="Hps"><dir name="Securesubmit"><dir name="Block"><dir name="Adminhtml"><file name="Form.php" hash="ab296bcf9018c73690bb0f5ab381381d"/><dir name="Paypal"><dir name="Settlement"><dir name="Report"><file name="Grid.php" hash="06a2fe96172be2af5cd1087fd72c91ad"/></dir><file name="Report.php" hash="eb1824305f2e290647f33a590872d5f7"/></dir></dir></dir><file name="Form.php" hash="a2e7bd1c2457cc7f12cb114b6957fefb"/><file name="Info.php" hash="3fa6b51d26f335e5ca52ee58a4399a3c"/><dir name="Paypal"><dir name="Credit"><file name="Form.php" hash="bf5dfaed60db99e60cb29a2e6aba82a3"/></dir><file name="Form.php" hash="0ee38aa63acf96cb650f7a9f2357ff84"/><file name="Info.php" hash="e23c3c2cb2ad60b05e24c1ecdd057d9a"/><dir name="Review"><file name="Billing.php" hash="62a22e1f5bd65c4d9369b5794779ffe9"/><file name="Details.php" hash="57d97c8a2c3b7ddac7dc4cda43e4363f"/><file name="Shipping.php" hash="694374b68714b6d58d9af8b9fb15d502"/></dir><file name="Review.php" hash="87c8f3bf319799b33170bec9f42e2544"/><file name="Shortcut.php" hash="4874a291018d9a6651d03cb9aeb54e07"/></dir></dir><dir name="Controller"><dir name="Paypal"><file name="Abstract.php" hash="0accc2a086374ab6f8260bd9e1a30337"/></dir></dir><dir name="Helper"><file name="Data.php" hash="04aeff6f94f56a49cf7527518c6212a1"/></dir><dir name="Model"><dir name="Api"><file name="Abstract.php" hash="77651db9410c0a7eca66f888cfd1eab5"/><file name="Paypal.php" hash="96439865e72b6c260138f650bd31a9ec"/></dir><file name="Config.php" hash="43c18bb31f7d774de93b1c1c0c541f82"/><file name="Payment.php" hash="3c72d498069ead0f0898bc5f3525f847"/><dir name="Paypal"><file name="Cart.php" hash="b64c4896eba58fc573f228656453d448"/><file name="Checkout.php" hash="ef815ce706cf67bac08853673e8bee7c"/><file name="Credit.php" hash="1f84b1addec3ff6887c81e6d240cc1ee"/></dir><file name="Paypal.php" hash="96ad238d35a79d31e9541f8755a24dde"/><file name="Report.php" hash="7f5e5bf0c652b37cf8c42eb553c8b3e0"/><dir name="Resource"><dir name="Report"><file name="Collection.php" hash="5870728a842922bbbff9c50173a90bd4"/></dir><file name="Report.php" hash="59598e2958a864119925c6e847b66121"/><file name="Setup.php" hash="f568cb09a6a06fc3d52f145684997416"/><dir name="Storedcard"><file name="Collection.php" hash="021134d46837197e800f54a4b90b0048"/></dir><file name="Storedcard.php" hash="f2a993c8e4236bc03b1273a33a03b5d0"/></dir><file name="Session.php" hash="136b4146cea2f596847f0b838ec3f532"/><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"><dir name="Adminhtml"><dir name="Hps"><dir name="Paypal"><file name="ReportsController.php" hash="bdb457590d4de2a7b9fe0055220e08f5"/></dir><file name=".DS_Store" hash="194577a7e20bdcc7afbb718f502c134c"/><file name="._.DS_Store" hash="f0d9d90674bab5908378533975df5a01"/></dir></dir><file name="PaypalController.php" hash="bf8e1033a2320ab9d9f70d99ff40c598"/><file name="StoredcardController.php" hash="cb9e5f7de4f52fd7a764a87f0f4699a8"/></dir><dir name="etc"><file name="adminhtml.xml" hash="8dc53c22d22cd633ebd6c06e7262c741"/><file name="config.xml" hash="b3fde0de1a10e823ce680317738fd802"/><file name="system.xml" hash="be8a2c1d74b72b45bd14eed62cc5a5e7"/></dir><dir name="sql"><dir name="hps_securesubmit_setup"><file name="install-1.0.0.php" hash="57917d8b3b29830eb1a219466df4555b"/><file name="mysql4-upgrade-1.0.0-1.0.1.php" hash="510826261ea81ea6a09d4ea84c59d41d"/><file name="mysql4-upgrade-1.0.1-1.1.0.php" hash="4044126ddfe49f5add3c530fcb6565fb"/></dir></dir><file name=".DS_Store" hash="4a6d92e7f95a9f9208c420e97eb1d4ea"/></dir></dir></target><target name="mageweb"><dir name="js"><dir name="securesubmit"><file name="admin-checkout.js" hash="1493f7f32243bad6d4facd577a375198"/><file name="checkout-form.js" hash="18ab8f124105d3aa22623ba6b8b76d25"/><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"/><file name="LICENSE.txt" hash="de081f847a769f89be5a1f80862005ba"/><file name="PRIVACY.txt" hash="58cdc5fbbff24a84a838b0174b254f70"/><file name="README.md" hash="bf88790111a10eb3643d62489b66c4d0"/><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><file name="index.php" hash="feabe5cc691b088d6ade3e04d6b120fc"/><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="ad9fbec07d00343bb53f71a835874ea4"/><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="b33260d307dd557d6fd287b32638c1aa"/><file name="HpsChargeService.php" hash="b3ae575ac87b364e4e847440792fa7c3"/><file name="HpsService.php" hash="52aefe6d72b1e4118fdd8ec04b75e28c"/><file name="HpsTokenService.php" hash="bfdee5e18ebdc2133f3512040e0da766"/></dir><dir name="src"><dir name="Abstractions"><file name="HpsBuilderAbstract.php" hash="6498e7b7e00716574a9dd238d1d7da5e"/><file name="HpsGatewayServiceAbstract.php" hash="3a13e35a1d3ea514ea67aadda34095f0"/><file name="HpsPayPlanResourceAbstract.php" hash="df262df6345c4932626e60afecdeb478"/><file name="HpsPayPlanResourceInterface.php" hash="22dd33e354f46218d2872eab956d57c1"/></dir><dir name="Entities"><dir name="AltPayment"><file name="HpsAltPaymentAddToBatch.php" hash="209a67ef29955f4e311a7b63242a019c"/><file name="HpsAltPaymentAuth.php" hash="179ac60bb7d4fbf8e536efb8f875ad65"/><file name="HpsAltPaymentCreateSession.php" hash="fc3c655d80d1e2559ad0606e72842cb8"/><file name="HpsAltPaymentReturn.php" hash="990b0596137a8833c145bdd55af802cb"/><file name="HpsAltPaymentSale.php" hash="c818e0a33ce76568cc6dc12a828c027f"/><file name="HpsAltPaymentSessionInfo.php" hash="a89b480b53bb0eb81ad71630d8712ba5"/><file name="HpsAltPaymentVoid.php" hash="aa60698f841c95d6d0c68ce42412a216"/><file name="HpsBuyerData.php" hash="bced7dbbfef25c606586f248a03afda3"/><file name="HpsLineItem.php" hash="4ff06a280975312365cf10a730636682"/><file name="HpsPaymentData.php" hash="c53ad30c9a01df727e5fff81e57cfbc4"/><file name="HpsShippingInfo.php" hash="fc29c5f4abfd1902d1f890ba4c60b2f5"/></dir><dir name="Batch"><file name="HpsBatch.php" hash="d9af4664e64172cb8edaeaa1ea7c7337"/></dir><dir name="Check"><file name="HpsCheck.php" hash="8fb85bd4d608e72a9690285ec46fa6d2"/><file name="HpsCheckHolder.php" hash="58f865b34faf2790fef26066de775a15"/><file name="HpsCheckResponse.php" hash="ff3c752bc85554424e62ed7efbc053f2"/><file name="HpsCheckResponseDetails.php" hash="28928ceb2dea574603a376aed1691a90"/></dir><dir name="Credit"><file name="HpsAccountVerify.php" hash="527a69e5a39153b764e6c14e0d98bf34"/><file name="HpsAuthorization.php" hash="7ec1bbfa6efa5bc48432b5de81eda314"/><file name="HpsCPCData.php" hash="54f7d36b10ef067c1bbc1d31866f020b"/><file name="HpsCPCEdit.php" hash="f04b0089485ba9e7eacba8e15815ec97"/><file name="HpsCardHolder.php" hash="ffee4609a3ffa886a386a12dea3f4508"/><file name="HpsCharge.php" hash="512fb9e459b336a9e256d8f1e08e36b9"/><file name="HpsChargeExceptions.php" hash="c7df102696a205a4c5689c48878ac5f3"/><file name="HpsCreditCard.php" hash="a64984f73b32c98120b44c7ab11407a9"/><file name="HpsRecurringBilling.php" hash="9da8f9b16179729b77615f04993b05bf"/><file name="HpsRefund.php" hash="aa4664916ebb94b8f2066fd7c17b0fd4"/><file name="HpsReportTransactionDetails.php" hash="9e81fbeb3b8d37231e65e9b38e026363"/><file name="HpsReportTransactionSummary.php" hash="dd157b169ffb8e71dd158fe1bf592c1a"/><file name="HpsReversal.php" hash="350191a2d38189ef8e098ed1f922c1d3"/><file name="HpsVoid.php" hash="bf6216cea2f130789a045fc226c54cd0"/></dir><dir name="Debit"><file name="HpsDebitAddValue.php" hash="9053c701093889f864dd36af208f4f71"/><file name="HpsDebitReturn.php" hash="519cb73c6fc4ce716453d5ff94f437a0"/><file name="HpsDebitReversal.php" hash="223f6db72f0219ef25eb0f0adec4e9be"/><file name="HpsDebitSale.php" hash="74fa1e1425cfe6294146c879a4049aa8"/></dir><dir name="Fluent"><file name="HpsBuilderAction.php" hash="8649cc2c53fd961f350070193fedb5c6"/><file name="HpsUnknownPropertyException.php" hash="d019e8645fae6f984ad7b7ea3cebb546"/></dir><dir name="Gift"><file name="HpsEncryptionData.php" hash="4b8d70dd2617504237ee9473b948e358"/><file name="HpsGiftCard.php" hash="73f4d366045409b50c6d4426d3cfd8f2"/><file name="HpsGiftCardActivate.php" hash="8fce968cabe957f092086571eac6fa52"/><file name="HpsGiftCardAddValue.php" hash="131a9d7cbc711a4e3e85c66049028f30"/><file name="HpsGiftCardAlias.php" hash="133d2d4701c5aa88fa0eece6ee69de06"/><file name="HpsGiftCardBalance.php" hash="9b9fe395d218c79c55faf28fd736b431"/><file name="HpsGiftCardDeactivate.php" hash="323ca5a67c6ff0169925192952881db5"/><file name="HpsGiftCardReplace.php" hash="f122a7d924a56fcc406bc8b1c82ac2b2"/><file name="HpsGiftCardReversal.php" hash="88ba755e52f41311206add4fa8ee5e09"/><file name="HpsGiftCardReward.php" hash="f758e8c5462d336236ae0d257789cdaf"/><file name="HpsGiftCardSale.php" hash="0f758ef6653215be643abaea4964352a"/><file name="HpsGiftCardVoid.php" hash="f0294740f5b7f545167d5fb258f4dcdd"/></dir><file name="HpsAddress.php" hash="8de2c8ea4a2b0a440d1b4bc0bf8321b8"/><file name="HpsConsumer.php" hash="1254142dfa0821cbb0bf154cf51f34d2"/><file name="HpsDirectMarketData.php" hash="e476ccc0c25c1681fa624365be6b8306"/><file name="HpsTokenData.php" hash="18ab9125315bb8e5f9cb272966dac22b"/><file name="HpsTransaction.php" hash="f109d2d26ba237afb2dc17bc287f63a9"/><file name="HpsTransactionDetails.php" hash="4e77261d0aced118b49e26ef786beace"/><file name="HpsTransactionHeader.php" hash="ebd21539f84425f0e2fc57c6049a26a1"/><dir name="PayPlan"><file name="HpsPayPlanCustomer.php" hash="2714a7525fb3830fc018544ea0622ab5"/><file name="HpsPayPlanPaymentMethod.php" hash="2d38df9da8b03f37aae752480e831257"/><file name="HpsPayPlanSchedule.php" hash="b87e28803ca7bddac9a42feaed0a5155"/></dir><file name="index.php" hash="feabe5cc691b088d6ade3e04d6b120fc"/></dir><dir name="Infrastructure"><dir name="Enums"><file name="HpsACHType.php" hash="1ff5593689a404cb0179c2b5cb5fe19e"/><file name="HpsAccountType.php" hash="760d91e120f443c326e6c7586aa61092"/><file name="HpsCardBrand.php" hash="9532bb7c40811c114a1eeeffa8b9732c"/><file name="HpsCheckType.php" hash="d60c676d93c8ada169deb14ddc8e64e7"/><file name="HpsDataEntryMode.php" hash="c323d884a7a305f9af647ea1d9a4177e"/><file name="HpsExceptionCodes.php" hash="94e6177576e9e9938e60a5bb386315d4"/><file name="HpsGiftCardAliasAction.php" hash="ebcb27c6fb800e17693ed4af2e8a8943"/><file name="HpsItemChoiceTypePosResponseVer10Transaction.php" hash="686225a07738db2233a2228bec6baabf"/><file name="HpsPayPlanAccountType.php" hash="4d383c42a990fb077fae49386c08b870"/><file name="HpsPayPlanCustomerStatus.php" hash="3ff092e8dd97f2a2474fb64103cb238f"/><file name="HpsPayPlanPaymentMethodStatus.php" hash="b020c52de7987ed3011cb97e4d440c6a"/><file name="HpsPayPlanPaymentMethodType.php" hash="1f77c5c8528815f05803c1381cb4151a"/><file name="HpsPayPlanScheduleDuration.php" hash="05101e6fe3b725b43917b59770f2dbb1"/><file name="HpsPayPlanScheduleFrequency.php" hash="0b3f029c64315ee9c8701d23319941c1"/><file name="HpsPayPlanScheduleStatus.php" hash="3579b52ccf36e576fd2dfb36118716f6"/><file name="HpsSECCode.php" hash="551661613c127c068f139083338b92d1"/><file name="HpsTaxType.php" hash="ba0e05330880810e58370f2f3490ca81"/><file name="HpsTransactionType.php" hash="a38b3f4c654a4fa3b2c2d64b8afacf24"/></dir><file name="HpsApiConnectionException.php" hash="ac5a8064a7c2a1616035a5702f36cd50"/><file name="HpsArgumentException.php" hash="855c43e88fc24b582cfe56875d7cff42"/><file name="HpsAuthenticationException.php" hash="6feb2fdc5499b460274524aa469d9a7d"/><file name="HpsCheckException.php" hash="94870f2438217b3275d05fb943a0a8c0"/><file name="HpsConfiguration.php" hash="962030209b58ea19c1b92330ce10e90c"/><file name="HpsCreditException.php" hash="a16bf1ecd6a2c866b7b40351aab3df34"/><file name="HpsCreditExceptionDetails.php" hash="d71c54b2846283a8f97aae74a747dfd9"/><file name="HpsException.php" hash="8d2025b7fae9f0f756341b876a0dab41"/><file name="HpsGatewayException.php" hash="cdd6db6c8436e3e78ee15cdd7a043a9d"/><file name="HpsGatewayExceptionDetails.php" hash="16dd36360e2237ca89e056c61766bcdd"/><file name="HpsInvalidRequestException.php" hash="7877e48463ef3f488bb92423ae445412"/><file name="HpsProcessorException.php" hash="ba28a92f0e551053506dcc391c5bc431"/><file name="HpsProcessorExceptionDetails.php" hash="6a569aacf045c19ade6472a857a3a274"/><dir name="Validation"><file name="HpsGatewayResponseValidation.php" hash="da8321b85030758d4a0d8bdd60222fc0"/><file name="HpsInputValidation.php" hash="1f51837f70c322f2a7c1cc39df752b1a"/><file name="HpsIssuerResponseValidation.php" hash="81d4625dc46e67bc59569620eed035c3"/><file name="HpsProcessorResponseValidation.php" hash="8dd4e86f84a509e756a74f499363407c"/></dir><file name="index.php" hash="feabe5cc691b088d6ade3e04d6b120fc"/></dir><dir name="Services"><dir name="Fluent"><dir name="Gateway"><dir name="Check"><file name="HpsCheckServiceOverrideBuilder.php" hash="fff87fca19d16cdc84586842540cd455"/><file name="HpsCheckServiceReturnBuilder.php" hash="4e953a852c9ab7526f1698c3e119a620"/><file name="HpsCheckServiceSaleBuilder.php" hash="0c2fa60711bd1c5ed8e890d423c0178f"/><file name="HpsCheckServiceVoidBuilder.php" hash="b7b40a6979a7f9407f6979f9e09295a0"/></dir><dir name="Credit"><file name="HpsCreditServiceAuthorizeBuilder.php" hash="0bf4ed6c057282754abdaaa86f40e236"/><file name="HpsCreditServiceCaptureBuilder.php" hash="2344fc2c40d52820bb0a74859e88168e"/><file name="HpsCreditServiceChargeBuilder.php" hash="13835b698c89eeb2e272de7e8037f469"/><file name="HpsCreditServiceCpcEditBuilder.php" hash="2f377011fb9ab5a36e1e63bafc6967cc"/><file name="HpsCreditServiceEditBuilder.php" hash="06755dd0baa05b3d7c621b981a209c73"/><file name="HpsCreditServiceGetBuilder.php" hash="0c90dfd82b9d5876010996bc3a5724a2"/><file name="HpsCreditServiceListTransactionsBuilder.php" hash="590c8e3f0cb5abd7f37f83bd9efca4fe"/><file name="HpsCreditServiceRefundBuilder.php" hash="74989514e3f90faac7af7ea42ff45cde"/><file name="HpsCreditServiceReverseBuilder.php" hash="de7e71f7ae431776381fee9214b2438d"/><file name="HpsCreditServiceVerifyBuilder.php" hash="7058d38bdfa9219fef1fad1976e81332"/><file name="HpsCreditServiceVoidBuilder.php" hash="590bc78af55b5d851cdd24043530fa84"/></dir><dir name="Debit"><file name="HpsDebitServiceAddValueBuilder.php" hash="5f972b68a5afa062cbf911bfb3a946bc"/><file name="HpsDebitServiceChargeBuilder.php" hash="26aafce2a87bbbd8231a039209c49657"/><file name="HpsDebitServiceReturnBuilder.php" hash="2e11267e12bdd338b953db352a373961"/><file name="HpsDebitServiceReverseBuilder.php" hash="b088431d3ba0726d44cc418e92267958"/></dir><dir name="GiftCard"><file name="HpsGiftCardServiceActivateBuilder.php" hash="65e3ebd1c6ded3860b238d03e542fe3b"/><file name="HpsGiftCardServiceAddValueBuilder.php" hash="432582c9fd6617c86b373f5fe0b14fb1"/><file name="HpsGiftCardServiceAliasBuilder.php" hash="23b6e876818560166497f556905cfcfb"/><file name="HpsGiftCardServiceBalanceBuilder.php" hash="6bebaac04d059204a2408d693f77c449"/><file name="HpsGiftCardServiceDeactivateBuilder.php" hash="92b16b331414c40ea11de330bd447273"/><file name="HpsGiftCardServiceReplaceBuilder.php" hash="063e6b33a673c23553047a6f72927b2a"/><file name="HpsGiftCardServiceReverseBuilder.php" hash="2f7b96b1f9608cb7e3526ecb9b15558f"/><file name="HpsGiftCardServiceRewardBuilder.php" hash="242fbe42ab731b138e4d74be4cde4e9a"/><file name="HpsGiftCardServiceSaleBuilder.php" hash="e0a87760bf2584ba07694bbb6534d3f5"/><file name="HpsGiftCardServiceVoidBuilder.php" hash="fff556a586bb09d22f521a90d30fb809"/></dir><file name="HpsFluentCheckService.php" hash="f722f875ed58a2be6e40b8a9dab66bb1"/><file name="HpsFluentCreditService.php" hash="301eeb5b6998cbd0f34990b0c0a54272"/><file name="HpsFluentDebitService.php" hash="63e86fe32a92c80cc5bd163283da6c64"/><file name="HpsFluentGiftCardService.php" hash="8a93e1afe2efc6f4e4db673fa61deee6"/><dir name="PayPlan"><file name="HpsPayPlanCustomerServiceAddBuilder.php" hash="e24d3255eeb44df4a9188ee6355f4af3"/><file name="HpsPayPlanCustomerServiceDeleteBuilder.php" hash="8b7646782d20308550b2fcd7e60cd1b1"/><file name="HpsPayPlanCustomerServiceEditBuilder.php" hash="e46190e3926f77b2a6bebb01140273b6"/><file name="HpsPayPlanCustomerServiceGetBuilder.php" hash="01b327c5c7f0e08918d7e49af338f364"/><file name="HpsPayPlanCustomerServiceSearchBuilder.php" hash="d411d14b4f52787ec9cad99087a4dbe9"/><file name="HpsPayPlanPaymentMethodServiceAddBuilder.php" hash="0409afd2934a875932985ce972aaa63b"/><file name="HpsPayPlanPaymentMethodServiceDeleteBuilder.php" hash="decec6ded5a4f0105592d8e223e40546"/><file name="HpsPayPlanPaymentMethodServiceEditBuilder.php" hash="5b73f43349c59f51f6c0af593900b530"/><file name="HpsPayPlanPaymentMethodServiceGetBuilder.php" hash="7d36bab7be54328de460d10cb7517aa7"/><file name="HpsPayPlanPaymentMethodServiceSearchBuilder.php" hash="1abf6bd6f2f3dc23513a1ee053d7a324"/><file name="HpsPayPlanScheduleServiceAddBuilder.php" hash="ec46e983b59f36dffc721c38e1783451"/><file name="HpsPayPlanScheduleServiceDeleteBuilder.php" hash="575e48a5d83820219d1af19a4c6f74b8"/><file name="HpsPayPlanScheduleServiceEditBuilder.php" hash="5665c1807226305456ecba027b04162b"/><file name="HpsPayPlanScheduleServiceGetBuilder.php" hash="c5b892091c1b2a32db3d48fa64b62e65"/><file name="HpsPayPlanScheduleServiceSearchBuilder.php" hash="68462acb4bdae55ff1895e53e36ebcaa"/></dir></dir></dir><dir name="Gateway"><dir name="AltPayment"><file name="HpsAltPaymentService.php" hash="4598ceace95ee666cb38dfc3546053e1"/><file name="HpsPayPalService.php" hash="c91eebb0eca8bdda2505b78c4746db28"/></dir><file name="HpsBatchService.php" hash="96c99c3a4c0ef3bcd73ec804912caeb7"/><file name="HpsCheckService.php" hash="c3c5b51aea67ef20ed657a7814344e95"/><file name="HpsCreditService.php" hash="4f2e15d27ab65d4e862b926891ffc8eb"/><file name="HpsDebitService.php" hash="3e1de3f705a9bb48a01fb132894264a3"/><file name="HpsGiftCardService.php" hash="b386c0d74b5c8eb74bc1c7f584bf99ad"/><file name="HpsRestGatewayService.php" hash="07c2a91fa455394c671c8b0018d8d65c"/><file name="HpsSoapGatewayService.php" hash="196ce540ca0c3bbed9b19472b80de3bd"/><file name="HpsTokenService.php" hash="f5bf762400e9c67ac28451693b31ebbe"/><dir name="PayPlan"><file name="HpsPayPlanCustomerService.php" hash="5eb04d200802380de80360e3bb96234b"/><file name="HpsPayPlanPaymentMethodService.php" hash="17d8c5c0b74f88d6f8c76bcc65175279"/><file name="HpsPayPlanScheduleService.php" hash="cddffbf0c2d36ba2e3448b21453c17eb"/></dir></dir><file name="HpsServicesConfig.php" hash="90f781e4a916517073b3e071aba7ad18"/><file name="index.php" hash="feabe5cc691b088d6ade3e04d6b120fc"/></dir><file name="index.php" hash="feabe5cc691b088d6ade3e04d6b120fc"/></dir><file name=".DS_Store" hash="194577a7e20bdcc7afbb718f502c134c"/></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="securesubmit.xml" hash="cc04e952cc17ea3462931a9e7a655316"/></dir><dir name="template"><dir name="securesubmit"><file name="form.phtml" hash="b6329408b11e9e979494a923e639f6cf"/></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="securesubmit.xml" hash="8aca5736bbba6ec8341cf9510c0ea5ab"/></dir><dir name="template"><dir name="securesubmit"><file name="form.phtml" hash="313ae740ba48618afac2797fddb162c9"/><dir name="paypal"><dir name="review"><file name="details.phtml" hash="0dc5e1201e7e424f089c15fc83a1c70f"/><dir name="shipping"><file name="method.phtml" hash="cc426553636aa08840bee1c4778d89e4"/></dir></dir><file name="review.phtml" hash="cfc643de65b962ba27306587357f45d3"/><file name="shortcut.phtml" hash="268bfac86e653ec5981cd201075f4105"/></dir><file name="storedcards.phtml" hash="3412f0560d4ba696dc9bc3ed996e0577"/><file name=".DS_Store" hash="194577a7e20bdcc7afbb718f502c134c"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Hps_Securesubmit.xml" hash="d5aed3f48a45f8e611b68d1e6f34c959"/></dir></target></contents>
18
  <compatible/>
19
+ <dependencies><required><php><min>5.2.0</min><max>5.6.16</max></php></required></dependencies>
20
  </package>