active_accountability_merchant 1.97.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (259) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG +2948 -0
  3. data/CONTRIBUTORS +568 -0
  4. data/MIT-LICENSE +20 -0
  5. data/README.md +246 -0
  6. data/lib/active_merchant.rb +63 -0
  7. data/lib/active_merchant/billing.rb +15 -0
  8. data/lib/active_merchant/billing/apple_pay_payment_token.rb +22 -0
  9. data/lib/active_merchant/billing/avs_result.rb +96 -0
  10. data/lib/active_merchant/billing/base.rb +61 -0
  11. data/lib/active_merchant/billing/check.rb +80 -0
  12. data/lib/active_merchant/billing/compatibility.rb +117 -0
  13. data/lib/active_merchant/billing/credit_card.rb +406 -0
  14. data/lib/active_merchant/billing/credit_card_formatting.rb +23 -0
  15. data/lib/active_merchant/billing/credit_card_methods.rb +343 -0
  16. data/lib/active_merchant/billing/cvv_result.rb +38 -0
  17. data/lib/active_merchant/billing/gateway.rb +330 -0
  18. data/lib/active_merchant/billing/gateways.rb +14 -0
  19. data/lib/active_merchant/billing/gateways/adyen.rb +503 -0
  20. data/lib/active_merchant/billing/gateways/allied_wallet.rb +205 -0
  21. data/lib/active_merchant/billing/gateways/authorize_net.rb +1055 -0
  22. data/lib/active_merchant/billing/gateways/authorize_net_arb.rb +417 -0
  23. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +980 -0
  24. data/lib/active_merchant/billing/gateways/axcessms.rb +181 -0
  25. data/lib/active_merchant/billing/gateways/balanced.rb +256 -0
  26. data/lib/active_merchant/billing/gateways/bambora_apac.rb +226 -0
  27. data/lib/active_merchant/billing/gateways/bank_frick.rb +225 -0
  28. data/lib/active_merchant/billing/gateways/banwire.rb +116 -0
  29. data/lib/active_merchant/billing/gateways/barclaycard_smartpay.rb +384 -0
  30. data/lib/active_merchant/billing/gateways/barclays_epdq_extra_plus.rb +15 -0
  31. data/lib/active_merchant/billing/gateways/be2bill.rb +131 -0
  32. data/lib/active_merchant/billing/gateways/beanstream.rb +217 -0
  33. data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +473 -0
  34. data/lib/active_merchant/billing/gateways/beanstream_interac.rb +57 -0
  35. data/lib/active_merchant/billing/gateways/blue_pay.rb +522 -0
  36. data/lib/active_merchant/billing/gateways/blue_snap.rb +522 -0
  37. data/lib/active_merchant/billing/gateways/bogus.rb +186 -0
  38. data/lib/active_merchant/billing/gateways/borgun.rb +220 -0
  39. data/lib/active_merchant/billing/gateways/bpoint.rb +277 -0
  40. data/lib/active_merchant/billing/gateways/braintree.rb +19 -0
  41. data/lib/active_merchant/billing/gateways/braintree/braintree_common.rb +22 -0
  42. data/lib/active_merchant/billing/gateways/braintree_blue.rb +740 -0
  43. data/lib/active_merchant/billing/gateways/braintree_orange.rb +19 -0
  44. data/lib/active_merchant/billing/gateways/bridge_pay.rb +244 -0
  45. data/lib/active_merchant/billing/gateways/cams.rb +230 -0
  46. data/lib/active_merchant/billing/gateways/card_connect.rb +316 -0
  47. data/lib/active_merchant/billing/gateways/card_save.rb +22 -0
  48. data/lib/active_merchant/billing/gateways/card_stream.rb +367 -0
  49. data/lib/active_merchant/billing/gateways/cardknox.rb +327 -0
  50. data/lib/active_merchant/billing/gateways/cardprocess.rb +254 -0
  51. data/lib/active_merchant/billing/gateways/cashnet.rb +219 -0
  52. data/lib/active_merchant/billing/gateways/cc5.rb +198 -0
  53. data/lib/active_merchant/billing/gateways/cecabank.rb +249 -0
  54. data/lib/active_merchant/billing/gateways/cenpos.rb +327 -0
  55. data/lib/active_merchant/billing/gateways/checkout.rb +214 -0
  56. data/lib/active_merchant/billing/gateways/checkout_v2.rb +270 -0
  57. data/lib/active_merchant/billing/gateways/citrus_pay.rb +22 -0
  58. data/lib/active_merchant/billing/gateways/clearhaus.rb +220 -0
  59. data/lib/active_merchant/billing/gateways/commercegate.rb +142 -0
  60. data/lib/active_merchant/billing/gateways/conekta.rb +228 -0
  61. data/lib/active_merchant/billing/gateways/creditcall.rb +271 -0
  62. data/lib/active_merchant/billing/gateways/credorax.rb +382 -0
  63. data/lib/active_merchant/billing/gateways/ct_payment.rb +268 -0
  64. data/lib/active_merchant/billing/gateways/culqi.rb +277 -0
  65. data/lib/active_merchant/billing/gateways/cyber_source.rb +828 -0
  66. data/lib/active_merchant/billing/gateways/d_local.rb +226 -0
  67. data/lib/active_merchant/billing/gateways/data_cash.rb +305 -0
  68. data/lib/active_merchant/billing/gateways/decidir.rb +233 -0
  69. data/lib/active_merchant/billing/gateways/dibs.rb +199 -0
  70. data/lib/active_merchant/billing/gateways/digitzs.rb +292 -0
  71. data/lib/active_merchant/billing/gateways/ebanx.rb +296 -0
  72. data/lib/active_merchant/billing/gateways/efsnet.rb +215 -0
  73. data/lib/active_merchant/billing/gateways/elavon.rb +320 -0
  74. data/lib/active_merchant/billing/gateways/element.rb +356 -0
  75. data/lib/active_merchant/billing/gateways/epay.rb +285 -0
  76. data/lib/active_merchant/billing/gateways/evo_ca.rb +308 -0
  77. data/lib/active_merchant/billing/gateways/eway.rb +226 -0
  78. data/lib/active_merchant/billing/gateways/eway_managed.rb +290 -0
  79. data/lib/active_merchant/billing/gateways/eway_rapid.rb +563 -0
  80. data/lib/active_merchant/billing/gateways/exact.rb +224 -0
  81. data/lib/active_merchant/billing/gateways/ezic.rb +195 -0
  82. data/lib/active_merchant/billing/gateways/fat_zebra.rb +218 -0
  83. data/lib/active_merchant/billing/gateways/federated_canada.rb +159 -0
  84. data/lib/active_merchant/billing/gateways/finansbank.rb +22 -0
  85. data/lib/active_merchant/billing/gateways/first_giving.rb +142 -0
  86. data/lib/active_merchant/billing/gateways/first_pay.rb +182 -0
  87. data/lib/active_merchant/billing/gateways/firstdata_e4.rb +451 -0
  88. data/lib/active_merchant/billing/gateways/firstdata_e4_v27.rb +485 -0
  89. data/lib/active_merchant/billing/gateways/flo2cash.rb +215 -0
  90. data/lib/active_merchant/billing/gateways/flo2cash_simple.rb +20 -0
  91. data/lib/active_merchant/billing/gateways/forte.rb +270 -0
  92. data/lib/active_merchant/billing/gateways/garanti.rb +259 -0
  93. data/lib/active_merchant/billing/gateways/global_collect.rb +336 -0
  94. data/lib/active_merchant/billing/gateways/global_transport.rb +194 -0
  95. data/lib/active_merchant/billing/gateways/hdfc.rb +206 -0
  96. data/lib/active_merchant/billing/gateways/hps.rb +350 -0
  97. data/lib/active_merchant/billing/gateways/iats_payments.rb +290 -0
  98. data/lib/active_merchant/billing/gateways/in_context_paypal_express.rb +15 -0
  99. data/lib/active_merchant/billing/gateways/inspire.rb +218 -0
  100. data/lib/active_merchant/billing/gateways/instapay.rb +162 -0
  101. data/lib/active_merchant/billing/gateways/ipp.rb +176 -0
  102. data/lib/active_merchant/billing/gateways/iridium.rb +468 -0
  103. data/lib/active_merchant/billing/gateways/itransact.rb +447 -0
  104. data/lib/active_merchant/billing/gateways/iveri.rb +251 -0
  105. data/lib/active_merchant/billing/gateways/jetpay.rb +402 -0
  106. data/lib/active_merchant/billing/gateways/jetpay_v2.rb +437 -0
  107. data/lib/active_merchant/billing/gateways/komoju.rb +115 -0
  108. data/lib/active_merchant/billing/gateways/kushki.rb +219 -0
  109. data/lib/active_merchant/billing/gateways/latitude19.rb +411 -0
  110. data/lib/active_merchant/billing/gateways/linkpoint.rb +449 -0
  111. data/lib/active_merchant/billing/gateways/litle.rb +507 -0
  112. data/lib/active_merchant/billing/gateways/mastercard.rb +267 -0
  113. data/lib/active_merchant/billing/gateways/maxipago.rb +220 -0
  114. data/lib/active_merchant/billing/gateways/mercado_pago.rb +277 -0
  115. data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +194 -0
  116. data/lib/active_merchant/billing/gateways/merchant_one.rb +113 -0
  117. data/lib/active_merchant/billing/gateways/merchant_partners.rb +245 -0
  118. data/lib/active_merchant/billing/gateways/merchant_ware.rb +319 -0
  119. data/lib/active_merchant/billing/gateways/merchant_ware_version_four.rb +286 -0
  120. data/lib/active_merchant/billing/gateways/merchant_warrior.rb +210 -0
  121. data/lib/active_merchant/billing/gateways/mercury.rb +356 -0
  122. data/lib/active_merchant/billing/gateways/metrics_global.rb +303 -0
  123. data/lib/active_merchant/billing/gateways/micropayment.rb +183 -0
  124. data/lib/active_merchant/billing/gateways/migs.rb +332 -0
  125. data/lib/active_merchant/billing/gateways/migs/migs_codes.rb +100 -0
  126. data/lib/active_merchant/billing/gateways/modern_payments.rb +37 -0
  127. data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +217 -0
  128. data/lib/active_merchant/billing/gateways/monei.rb +338 -0
  129. data/lib/active_merchant/billing/gateways/moneris.rb +377 -0
  130. data/lib/active_merchant/billing/gateways/moneris_us.rb +352 -0
  131. data/lib/active_merchant/billing/gateways/money_movers.rb +151 -0
  132. data/lib/active_merchant/billing/gateways/mundipagg.rb +293 -0
  133. data/lib/active_merchant/billing/gateways/nab_transact.rb +301 -0
  134. data/lib/active_merchant/billing/gateways/ncr_secure_pay.rb +165 -0
  135. data/lib/active_merchant/billing/gateways/net_registry.rb +199 -0
  136. data/lib/active_merchant/billing/gateways/netaxept.rb +180 -0
  137. data/lib/active_merchant/billing/gateways/netbanx.rb +294 -0
  138. data/lib/active_merchant/billing/gateways/netbilling.rb +232 -0
  139. data/lib/active_merchant/billing/gateways/netpay.rb +222 -0
  140. data/lib/active_merchant/billing/gateways/network_merchants.rb +241 -0
  141. data/lib/active_merchant/billing/gateways/nmi.rb +324 -0
  142. data/lib/active_merchant/billing/gateways/ogone.rb +478 -0
  143. data/lib/active_merchant/billing/gateways/omise.rb +324 -0
  144. data/lib/active_merchant/billing/gateways/openpay.rb +228 -0
  145. data/lib/active_merchant/billing/gateways/opp.rb +388 -0
  146. data/lib/active_merchant/billing/gateways/optimal_payment.rb +332 -0
  147. data/lib/active_merchant/billing/gateways/orbital.rb +1006 -0
  148. data/lib/active_merchant/billing/gateways/orbital/orbital_soft_descriptors.rb +47 -0
  149. data/lib/active_merchant/billing/gateways/pac_net_raven.rb +206 -0
  150. data/lib/active_merchant/billing/gateways/pagarme.rb +246 -0
  151. data/lib/active_merchant/billing/gateways/pago_facil.rb +122 -0
  152. data/lib/active_merchant/billing/gateways/pay_conex.rb +245 -0
  153. data/lib/active_merchant/billing/gateways/pay_gate_xml.rb +280 -0
  154. data/lib/active_merchant/billing/gateways/pay_hub.rb +213 -0
  155. data/lib/active_merchant/billing/gateways/pay_junction.rb +390 -0
  156. data/lib/active_merchant/billing/gateways/pay_junction_v2.rb +188 -0
  157. data/lib/active_merchant/billing/gateways/pay_secure.rb +111 -0
  158. data/lib/active_merchant/billing/gateways/paybox_direct.rb +200 -0
  159. data/lib/active_merchant/billing/gateways/payeezy.rb +410 -0
  160. data/lib/active_merchant/billing/gateways/payex.rb +410 -0
  161. data/lib/active_merchant/billing/gateways/payflow.rb +383 -0
  162. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +235 -0
  163. data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +43 -0
  164. data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +13 -0
  165. data/lib/active_merchant/billing/gateways/payflow_express.rb +220 -0
  166. data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +14 -0
  167. data/lib/active_merchant/billing/gateways/payflow_uk.rb +20 -0
  168. data/lib/active_merchant/billing/gateways/payment_express.rb +369 -0
  169. data/lib/active_merchant/billing/gateways/paymentez.rb +300 -0
  170. data/lib/active_merchant/billing/gateways/paymill.rb +371 -0
  171. data/lib/active_merchant/billing/gateways/paypal.rb +128 -0
  172. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +717 -0
  173. data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +65 -0
  174. data/lib/active_merchant/billing/gateways/paypal/paypal_recurring_api.rb +262 -0
  175. data/lib/active_merchant/billing/gateways/paypal_ca.rb +13 -0
  176. data/lib/active_merchant/billing/gateways/paypal_digital_goods.rb +44 -0
  177. data/lib/active_merchant/billing/gateways/paypal_express.rb +269 -0
  178. data/lib/active_merchant/billing/gateways/paypal_express_common.rb +30 -0
  179. data/lib/active_merchant/billing/gateways/payscout.rb +160 -0
  180. data/lib/active_merchant/billing/gateways/paystation.rb +207 -0
  181. data/lib/active_merchant/billing/gateways/payu_in.rb +248 -0
  182. data/lib/active_merchant/billing/gateways/payu_latam.rb +449 -0
  183. data/lib/active_merchant/billing/gateways/payway.rb +207 -0
  184. data/lib/active_merchant/billing/gateways/pin.rb +234 -0
  185. data/lib/active_merchant/billing/gateways/plugnpay.rb +284 -0
  186. data/lib/active_merchant/billing/gateways/pro_pay.rb +326 -0
  187. data/lib/active_merchant/billing/gateways/psigate.rb +227 -0
  188. data/lib/active_merchant/billing/gateways/psl_card.rb +296 -0
  189. data/lib/active_merchant/billing/gateways/qbms.rb +303 -0
  190. data/lib/active_merchant/billing/gateways/quantum.rb +276 -0
  191. data/lib/active_merchant/billing/gateways/quickbooks.rb +290 -0
  192. data/lib/active_merchant/billing/gateways/quickpay.rb +25 -0
  193. data/lib/active_merchant/billing/gateways/quickpay/quickpay_common.rb +184 -0
  194. data/lib/active_merchant/billing/gateways/quickpay/quickpay_v10.rb +301 -0
  195. data/lib/active_merchant/billing/gateways/quickpay/quickpay_v4to7.rb +226 -0
  196. data/lib/active_merchant/billing/gateways/qvalent.rb +289 -0
  197. data/lib/active_merchant/billing/gateways/realex.rb +374 -0
  198. data/lib/active_merchant/billing/gateways/redsys.rb +534 -0
  199. data/lib/active_merchant/billing/gateways/s5.rb +246 -0
  200. data/lib/active_merchant/billing/gateways/safe_charge.rb +262 -0
  201. data/lib/active_merchant/billing/gateways/sage.rb +448 -0
  202. data/lib/active_merchant/billing/gateways/sage_pay.rb +434 -0
  203. data/lib/active_merchant/billing/gateways/sallie_mae.rb +142 -0
  204. data/lib/active_merchant/billing/gateways/secure_net.rb +267 -0
  205. data/lib/active_merchant/billing/gateways/secure_pay.rb +200 -0
  206. data/lib/active_merchant/billing/gateways/secure_pay_au.rb +292 -0
  207. data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +104 -0
  208. data/lib/active_merchant/billing/gateways/securion_pay.rb +264 -0
  209. data/lib/active_merchant/billing/gateways/skip_jack.rb +450 -0
  210. data/lib/active_merchant/billing/gateways/smart_ps.rb +280 -0
  211. data/lib/active_merchant/billing/gateways/so_easy_pay.rb +194 -0
  212. data/lib/active_merchant/billing/gateways/spreedly_core.rb +306 -0
  213. data/lib/active_merchant/billing/gateways/stripe.rb +790 -0
  214. data/lib/active_merchant/billing/gateways/stripe_payment_intents.rb +267 -0
  215. data/lib/active_merchant/billing/gateways/swipe_checkout.rb +152 -0
  216. data/lib/active_merchant/billing/gateways/telr.rb +274 -0
  217. data/lib/active_merchant/billing/gateways/tns.rb +22 -0
  218. data/lib/active_merchant/billing/gateways/trans_first.rb +239 -0
  219. data/lib/active_merchant/billing/gateways/trans_first_transaction_express.rb +608 -0
  220. data/lib/active_merchant/billing/gateways/transact_pro.rb +224 -0
  221. data/lib/active_merchant/billing/gateways/transax.rb +22 -0
  222. data/lib/active_merchant/billing/gateways/transnational.rb +9 -0
  223. data/lib/active_merchant/billing/gateways/trexle.rb +218 -0
  224. data/lib/active_merchant/billing/gateways/trust_commerce.rb +490 -0
  225. data/lib/active_merchant/billing/gateways/usa_epay.rb +25 -0
  226. data/lib/active_merchant/billing/gateways/usa_epay_advanced.rb +1620 -0
  227. data/lib/active_merchant/billing/gateways/usa_epay_transaction.rb +355 -0
  228. data/lib/active_merchant/billing/gateways/vanco.rb +294 -0
  229. data/lib/active_merchant/billing/gateways/verifi.rb +225 -0
  230. data/lib/active_merchant/billing/gateways/viaklix.rb +176 -0
  231. data/lib/active_merchant/billing/gateways/visanet_peru.rb +245 -0
  232. data/lib/active_merchant/billing/gateways/webpay.rb +97 -0
  233. data/lib/active_merchant/billing/gateways/wepay.rb +237 -0
  234. data/lib/active_merchant/billing/gateways/wirecard.rb +432 -0
  235. data/lib/active_merchant/billing/gateways/world_net.rb +344 -0
  236. data/lib/active_merchant/billing/gateways/worldpay.rb +634 -0
  237. data/lib/active_merchant/billing/gateways/worldpay_online_payments.rb +215 -0
  238. data/lib/active_merchant/billing/gateways/worldpay_us.rb +221 -0
  239. data/lib/active_merchant/billing/model.rb +30 -0
  240. data/lib/active_merchant/billing/network_tokenization_credit_card.rb +39 -0
  241. data/lib/active_merchant/billing/payment_token.rb +21 -0
  242. data/lib/active_merchant/billing/rails.rb +3 -0
  243. data/lib/active_merchant/billing/response.rb +92 -0
  244. data/lib/active_merchant/connection.rb +195 -0
  245. data/lib/active_merchant/country.rb +336 -0
  246. data/lib/active_merchant/empty.rb +20 -0
  247. data/lib/active_merchant/errors.rb +35 -0
  248. data/lib/active_merchant/net_http_ssl_connection.rb +10 -0
  249. data/lib/active_merchant/network_connection_retries.rb +80 -0
  250. data/lib/active_merchant/post_data.rb +25 -0
  251. data/lib/active_merchant/posts_data.rb +92 -0
  252. data/lib/active_merchant/version.rb +3 -0
  253. data/lib/activemerchant.rb +1 -0
  254. data/lib/certs/cacert.pem +3988 -0
  255. data/lib/support/gateway_support.rb +69 -0
  256. data/lib/support/outbound_hosts.rb +28 -0
  257. data/lib/support/ssl_verify.rb +92 -0
  258. data/lib/support/ssl_version.rb +87 -0
  259. metadata +435 -0
@@ -0,0 +1,490 @@
1
+ begin
2
+ require 'tclink'
3
+ rescue LoadError
4
+ # Falls back to an SSL post to TrustCommerce
5
+ end
6
+
7
+ module ActiveMerchant #:nodoc:
8
+ module Billing #:nodoc:
9
+ # TO USE:
10
+ # First, make sure you have everything setup correctly and all of your dependencies in place with:
11
+ #
12
+ # require 'rubygems'
13
+ # require 'active_merchant'
14
+ #
15
+ # ActiveMerchant expects amounts to be Integer values in cents
16
+ #
17
+ # tendollar = 1000
18
+ #
19
+ # Next, create a credit card object using a TC approved test card.
20
+ #
21
+ # creditcard = ActiveMerchant::Billing::CreditCard.new(
22
+ # :number => '4111111111111111',
23
+ # :month => 8,
24
+ # :year => 2006,
25
+ # :first_name => 'Longbob',
26
+ # :last_name => 'Longsen'
27
+ # )
28
+ #
29
+ # To finish setting up, create the active_merchant object you will be using, with the TrustCommerce gateway. If you have a
30
+ # functional TrustCommerce account, replace login and password with your account info. Otherwise the defaults will work for
31
+ # testing.
32
+ #
33
+ # gateway = ActiveMerchant::Billing::Base.gateway(:trust_commerce).new(:login => "TestMerchant", :password => "password")
34
+ #
35
+ # Now we are ready to process our transaction
36
+ #
37
+ # response = gateway.purchase(tendollar, creditcard)
38
+ #
39
+ # Sending a transaction to TrustCommerce with active_merchant returns a Response object, which consistently allows you to:
40
+ #
41
+ # 1) Check whether the transaction was successful
42
+ #
43
+ # response.success?
44
+ #
45
+ # 2) Retrieve any message returned by TrustCommerce, either a "transaction was successful" note or an explanation of why the
46
+ # transaction was rejected.
47
+ #
48
+ # response.message
49
+ #
50
+ # 3) Retrieve and store the unique transaction ID returned by Trust Commerece, for use in referencing the transaction in the future.
51
+ #
52
+ # response.params["transid"]
53
+ #
54
+ # For higher performance and failover with the TrustCommerceGateway you can install the TCLink library from http://www.trustcommerce.com/tclink.html.
55
+ # Follow the instructions available there to get it working on your system. ActiveMerchant will automatically use tclink if available.
56
+ #
57
+ # The TCLink library has the following added benefits:
58
+ # * Good transaction times. Transaction duration under 1.2 seconds are common.
59
+ # * Fail-over to geographically distributed servers for extreme reliability
60
+ #
61
+ # Once it is installed, you should be able to make sure
62
+ # that it is visible to your ruby install by opening irb and typing "require 'tclink'", which should return "true".
63
+ #
64
+ # This should be enough to get you started with Trust Commerce and active_merchant. For further information, review the methods
65
+ # below and the rest of active_merchant's documentation, as well as Trust Commerce's user and developer documentation.
66
+
67
+ class TrustCommerceGateway < Gateway
68
+ self.live_url = self.test_url = 'https://vault.trustcommerce.com/trans/'
69
+
70
+ SUCCESS_TYPES = ['approved', 'accepted']
71
+
72
+ DECLINE_CODES = {
73
+ 'decline' => 'The credit card was declined',
74
+ 'avs' => 'AVS failed; the address entered does not match the billing address on file at the bank',
75
+ 'cvv' => 'CVV failed; the number provided is not the correct verification number for the card',
76
+ 'call' => 'The card must be authorized manually over the phone',
77
+ 'expiredcard' => 'Issuer was not certified for card verification',
78
+ 'carderror' => 'Card number is invalid',
79
+ 'authexpired' => 'Attempt to postauth an expired (more than 14 days old) preauth',
80
+ 'fraud' => 'CrediGuard fraud score was below requested threshold',
81
+ 'blacklist' => 'CrediGuard blacklist value was triggered',
82
+ 'velocity' => 'CrediGuard velocity control value was triggered',
83
+ 'dailylimit' => 'Daily limit in transaction count or amount as been reached',
84
+ 'weeklylimit' => 'Weekly limit in transaction count or amount as been reached',
85
+ 'monthlylimit' => 'Monthly limit in transaction count or amount as been reached'
86
+ }
87
+
88
+ BADDATA_CODES = {
89
+ 'missingfields' => 'One or more parameters required for this transaction type were not sent',
90
+ 'extrafields' => 'Parameters not allowed for this transaction type were sent',
91
+ 'badformat' => 'A field was improperly formatted, such as non-digit characters in a number field',
92
+ 'badlength' => 'A field was longer or shorter than the server allows',
93
+ 'merchantcantaccept' => "The merchant can't accept data passed in this field",
94
+ 'mismatch' => 'Data in one of the offending fields did not cross-check with the other offending field'
95
+ }
96
+
97
+ ERROR_CODES = {
98
+ 'cantconnect' => "Couldn't connect to the TrustCommerce gateway",
99
+ 'dnsfailure' => 'The TCLink software was unable to resolve DNS hostnames',
100
+ 'linkfailure' => 'The connection was established, but was severed before the transaction could complete',
101
+ 'failtoprocess' => 'The bank servers are offline and unable to authorize transactions'
102
+ }
103
+
104
+ TEST_LOGIN = 'TestMerchant'
105
+ TEST_PASSWORD = 'password'
106
+
107
+ VOIDABLE_ACTIONS = %w(preauth sale postauth credit)
108
+
109
+ self.money_format = :cents
110
+ self.supported_cardtypes = [:visa, :master, :discover, :american_express, :diners_club, :jcb]
111
+ self.supported_countries = ['US']
112
+ self.homepage_url = 'http://www.trustcommerce.com/'
113
+ self.display_name = 'TrustCommerce'
114
+
115
+ def self.tclink?
116
+ defined?(TCLink)
117
+ end
118
+
119
+ # Creates a new TrustCommerceGateway
120
+ #
121
+ # The gateway requires that a valid login and password be passed
122
+ # in the +options+ hash.
123
+ #
124
+ # ==== Options
125
+ #
126
+ # * <tt>:login</tt> -- The TrustCommerce account login.
127
+ # * <tt>:password</tt> -- The TrustCommerce account password.
128
+ # * <tt>:test => +true+ or +false+</tt> -- Perform test transactions
129
+ #
130
+ # ==== Test Account Credentials
131
+ # * <tt>:login</tt> -- TestMerchant
132
+ # * <tt>:password</tt> -- password
133
+ def initialize(options = {})
134
+ requires!(options, :login, :password)
135
+
136
+ super
137
+ end
138
+
139
+ def tclink?
140
+ self.class.tclink?
141
+ end
142
+
143
+ def test?
144
+ ((@options[:login] == TEST_LOGIN && @options[:password] == TEST_PASSWORD) || super)
145
+ end
146
+
147
+ # authorize() is the first half of the preauth(authorize)/postauth(capture) model. The TC API docs call this
148
+ # preauth, we preserve active_merchant's nomenclature of authorize() for consistency with the rest of the library. This
149
+ # method simply checks to make sure funds are available for a transaction, and returns a transid that can be used later to
150
+ # postauthorize (capture) the funds.
151
+
152
+ def authorize(money, creditcard_or_billing_id, options = {})
153
+ parameters = {
154
+ :amount => amount(money),
155
+ }
156
+
157
+ add_order_id(parameters, options)
158
+ add_aggregator(parameters, options)
159
+ add_customer_data(parameters, options)
160
+ add_payment_source(parameters, creditcard_or_billing_id)
161
+ add_addresses(parameters, options)
162
+ add_custom_fields(parameters, options)
163
+
164
+ commit('preauth', parameters)
165
+ end
166
+
167
+ # purchase() is a simple sale. This is one of the most common types of transactions, and is extremely simple. All that you need
168
+ # to process a purchase are an amount in cents or a money object and a creditcard object or billingid string.
169
+ def purchase(money, creditcard_or_billing_id, options = {})
170
+ parameters = {
171
+ :amount => amount(money),
172
+ }
173
+
174
+ add_order_id(parameters, options)
175
+ add_aggregator(parameters, options)
176
+ add_customer_data(parameters, options)
177
+ add_payment_source(parameters, creditcard_or_billing_id)
178
+ add_addresses(parameters, options)
179
+ add_custom_fields(parameters, options)
180
+
181
+ commit('sale', parameters)
182
+ end
183
+
184
+ # capture() is the second half of the preauth(authorize)/postauth(capture) model. The TC API docs call this
185
+ # postauth, we preserve active_merchant's nomenclature of capture() for consistency with the rest of the library. To process
186
+ # a postauthorization with TC, you need an amount in cents or a money object, and a TC transid.
187
+ def capture(money, authorization, options = {})
188
+ transaction_id, _ = split_authorization(authorization)
189
+ parameters = {
190
+ :amount => amount(money),
191
+ :transid => transaction_id,
192
+ }
193
+ add_aggregator(parameters, options)
194
+ add_custom_fields(parameters, options)
195
+
196
+ commit('postauth', parameters)
197
+ end
198
+
199
+ # refund() allows you to return money to a card that was previously billed. You need to supply the amount, in cents or a money object,
200
+ # that you want to refund, and a TC transid for the transaction that you are refunding.
201
+ def refund(money, identification, options = {})
202
+ transaction_id, _ = split_authorization(identification)
203
+
204
+ parameters = {
205
+ :amount => amount(money),
206
+ :transid => transaction_id
207
+ }
208
+
209
+ add_aggregator(parameters, options)
210
+ add_custom_fields(parameters, options)
211
+
212
+ commit('credit', parameters)
213
+ end
214
+
215
+ def credit(money, identification, options = {})
216
+ ActiveMerchant.deprecated CREDIT_DEPRECATION_MESSAGE
217
+ refund(money, identification, options)
218
+ end
219
+
220
+ # void() clears an existing authorization and releases the reserved fund
221
+ # s back to the cardholder. The TC API refers to this transaction as a
222
+ # reversal. After voiding, you will no longer be able to capture funds
223
+ # from this authorization. TrustCommerce seems to always return a status
224
+ # of "accepted" even if the transid you are trying to deauthorize has
225
+ # already been captured. Note: Your account needs to be configured by
226
+ # TrustCommerce to allow for reversal transactions before you can use this
227
+ # method.
228
+ #
229
+ # void() is also used to to cancel a capture (postauth), purchase (sale),
230
+ # or refund (credit) or a before it is sent for settlement.
231
+ #
232
+ # NOTE: AMEX preauth's cannot be reversed. If you want to clear it more
233
+ # quickly than the automatic expiration (7-10 days), you will have to
234
+ # capture it and then immediately issue a credit for the same amount
235
+ # which should clear the customers credit card with 48 hours according to
236
+ # TC.
237
+ def void(authorization, options = {})
238
+ transaction_id, original_action = split_authorization(authorization)
239
+ action = (VOIDABLE_ACTIONS - ['preauth']).include?(original_action) ? 'void' : 'reversal'
240
+
241
+ parameters = {
242
+ :transid => transaction_id,
243
+ }
244
+
245
+ add_aggregator(parameters, options)
246
+ add_custom_fields(parameters, options)
247
+
248
+ commit(action, parameters)
249
+ end
250
+
251
+ # recurring() a TrustCommerce account that is activated for Citadel, TrustCommerce's
252
+ # hosted customer billing info database.
253
+ #
254
+ # Recurring billing uses the same TC action as a plain-vanilla 'store', but we have a separate method for clarity. It can be called
255
+ # like store, with the addition of a required 'periodicity' parameter:
256
+ #
257
+ # The parameter :periodicity should be specified as either :bimonthly, :monthly, :biweekly, :weekly, :yearly or :daily
258
+ #
259
+ # gateway.recurring(tendollar, creditcard, :periodicity => :weekly)
260
+ #
261
+ # You can optionally specify how long you want payments to continue using 'payments'
262
+ def recurring(money, creditcard, options = {})
263
+ ActiveMerchant.deprecated RECURRING_DEPRECATION_MESSAGE
264
+
265
+ requires!(options, [:periodicity, :bimonthly, :monthly, :biweekly, :weekly, :yearly, :daily])
266
+
267
+ cycle = case options[:periodicity]
268
+ when :monthly
269
+ '1m'
270
+ when :bimonthly
271
+ '2m'
272
+ when :weekly
273
+ '1w'
274
+ when :biweekly
275
+ '2w'
276
+ when :yearly
277
+ '1y'
278
+ when :daily
279
+ '1d'
280
+ end
281
+
282
+ parameters = {
283
+ :amount => amount(money),
284
+ :cycle => cycle,
285
+ :verify => options[:verify] || 'y',
286
+ :billingid => options[:billingid] || nil,
287
+ :payments => options[:payments] || nil,
288
+ }
289
+
290
+ add_creditcard(parameters, creditcard)
291
+
292
+ commit('store', parameters)
293
+ end
294
+
295
+ # store() requires a TrustCommerce account that is activated for Citadel. You can call it with a credit card and a billing ID
296
+ # you would like to use to reference the stored credit card info for future captures. Use 'verify' to specify whether you want
297
+ # to simply store the card in the DB, or you want TC to verify the data first.
298
+
299
+ def store(creditcard, options = {})
300
+ parameters = {
301
+ :verify => options[:verify] || 'y',
302
+ :billingid => options[:billingid] || options[:billing_id] || nil,
303
+ }
304
+
305
+ add_creditcard(parameters, creditcard)
306
+ add_addresses(parameters, options)
307
+ add_custom_fields(parameters, options)
308
+
309
+ commit('store', parameters)
310
+ end
311
+
312
+ # To unstore a creditcard stored in Citadel using store() or recurring(), all that is required is the billing id. When you run
313
+ # unstore() the information will be removed and a Response object will be returned indicating the success of the action.
314
+ def unstore(identification, options = {})
315
+ parameters = {
316
+ :billingid => identification,
317
+ }
318
+
319
+ add_custom_fields(parameters, options)
320
+
321
+ commit('unstore', parameters)
322
+ end
323
+
324
+ def supports_scrubbing
325
+ true
326
+ end
327
+
328
+ def scrub(transcript)
329
+ transcript.
330
+ gsub(%r((Authorization: Basic )\w+), '\1[FILTERED]').
331
+ gsub(%r((&?cc=)\d*(&?)), '\1[FILTERED]\2').
332
+ gsub(%r((&?password=)[^&]+(&?)), '\1[FILTERED]\2').
333
+ gsub(%r((&?cvv=)\d*(&?)), '\1[FILTERED]\2')
334
+ end
335
+
336
+ private
337
+
338
+ def add_custom_fields(params, options)
339
+ options[:custom_fields]&.each do |key, value|
340
+ params[key.to_sym] = value
341
+ end
342
+ end
343
+
344
+ def add_aggregator(params, options)
345
+ if @options[:aggregator_id] || application_id != Gateway.application_id
346
+ params[:aggregators] = 1
347
+ params[:aggregator1] = @options[:aggregator_id] || application_id
348
+ end
349
+ end
350
+
351
+ def add_payment_source(params, source)
352
+ if source.is_a?(String)
353
+ add_billing_id(params, source)
354
+ elsif card_brand(source) == 'check'
355
+ add_check(params, source)
356
+ else
357
+ add_creditcard(params, source)
358
+ end
359
+ end
360
+
361
+ def add_check(params, check)
362
+ params[:media] = 'ach'
363
+ params[:routing] = check.routing_number
364
+ params[:account] = check.account_number
365
+ params[:savings] = 'y' if check.account_type == 'savings'
366
+ params[:name] = check.name
367
+ end
368
+
369
+ def add_creditcard(params, creditcard)
370
+ params[:media] = 'cc'
371
+ params[:name] = creditcard.name
372
+ params[:cc] = creditcard.number
373
+ params[:exp] = expdate(creditcard)
374
+ params[:cvv] = creditcard.verification_value if creditcard.verification_value?
375
+ end
376
+
377
+ def add_order_id(params, options)
378
+ params[:ticket] = options[:order_id] unless options[:order_id].blank?
379
+ end
380
+
381
+ def add_billing_id(params, billingid)
382
+ params[:billingid] = billingid
383
+ end
384
+
385
+ def add_customer_data(params, options)
386
+ params[:email] = options[:email] unless options[:email].blank?
387
+ params[:ip] = options[:ip] unless options[:ip].blank?
388
+ end
389
+
390
+ def add_addresses(params, options)
391
+ address = options[:billing_address] || options[:address]
392
+
393
+ if address
394
+ params[:address1] = address[:address1] unless address[:address1].blank?
395
+ params[:address2] = address[:address2] unless address[:address2].blank?
396
+ params[:city] = address[:city] unless address[:city].blank?
397
+ params[:state] = address[:state] unless address[:state].blank?
398
+ params[:zip] = address[:zip] unless address[:zip].blank?
399
+ params[:country] = address[:country] unless address[:country].blank?
400
+ params[:avs] = 'n'
401
+ end
402
+
403
+ if shipping_address = options[:shipping_address]
404
+ params[:shipto_name] = shipping_address[:name] unless shipping_address[:name].blank?
405
+ params[:shipto_address1] = shipping_address[:address1] unless shipping_address[:address1].blank?
406
+ params[:shipto_address2] = shipping_address[:address2] unless shipping_address[:address2].blank?
407
+ params[:shipto_city] = shipping_address[:city] unless shipping_address[:city].blank?
408
+ params[:shipto_state] = shipping_address[:state] unless shipping_address[:state].blank?
409
+ params[:shipto_zip] = shipping_address[:zip] unless shipping_address[:zip].blank?
410
+ params[:shipto_country] = shipping_address[:country] unless shipping_address[:country].blank?
411
+ end
412
+ end
413
+
414
+ def clean_and_stringify_params(parameters)
415
+ # TCLink wants us to send a hash with string keys, and activemerchant pushes everything around with
416
+ # symbol keys. Before sending our input to TCLink, we convert all our keys to strings and dump the symbol keys.
417
+ # We also remove any pairs with nil values, as these confuse TCLink.
418
+ parameters.keys.reverse_each do |key|
419
+ if parameters[key]
420
+ parameters[key.to_s] = parameters[key]
421
+ end
422
+ parameters.delete(key)
423
+ end
424
+ end
425
+
426
+ def post_data(parameters)
427
+ parameters.collect { |key, value| "#{key}=#{CGI.escape(value.to_s)}" }.join('&')
428
+ end
429
+
430
+ def commit(action, parameters)
431
+ parameters[:custid] = @options[:login]
432
+ parameters[:password] = @options[:password]
433
+ parameters[:demo] = test? ? 'y' : 'n'
434
+ parameters[:action] = action
435
+
436
+ clean_and_stringify_params(parameters)
437
+
438
+ data = if tclink?
439
+ TCLink.send(parameters)
440
+ else
441
+ parse(ssl_post(self.live_url, post_data(parameters)))
442
+ end
443
+
444
+ # to be considered successful, transaction status must be either "approved" or "accepted"
445
+ success = SUCCESS_TYPES.include?(data['status'])
446
+ message = message_from(data)
447
+ Response.new(success, message, data,
448
+ :test => test?,
449
+ :authorization => authorization_from(action, data),
450
+ :cvv_result => data['cvv'],
451
+ :avs_result => { :code => data['avs'] }
452
+ )
453
+ end
454
+
455
+ def parse(body)
456
+ results = {}
457
+
458
+ body.split(/\n/).each do |pair|
459
+ key, val = pair.split(/=/)
460
+ results[key] = val
461
+ end
462
+
463
+ results
464
+ end
465
+
466
+ def message_from(data)
467
+ case data['status']
468
+ when 'decline'
469
+ return DECLINE_CODES[data['declinetype']]
470
+ when 'baddata'
471
+ return BADDATA_CODES[data['error']]
472
+ when 'error'
473
+ return ERROR_CODES[data['errortype']]
474
+ else
475
+ return 'The transaction was successful'
476
+ end
477
+ end
478
+
479
+ def authorization_from(action, data)
480
+ authorization = data['transid']
481
+ authorization = "#{authorization}|#{action}" if authorization && VOIDABLE_ACTIONS.include?(action)
482
+ authorization
483
+ end
484
+
485
+ def split_authorization(authorization)
486
+ authorization&.split('|')
487
+ end
488
+ end
489
+ end
490
+ end