seamusabshere-active_merchant 1.4.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (277) hide show
  1. data/CHANGELOG +399 -0
  2. data/CONTRIBUTERS +90 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README +133 -0
  5. data/Rakefile +161 -0
  6. data/active_merchant.gemspec +17 -0
  7. data/gem-public_cert.pem +20 -0
  8. data/generators/gateway/USAGE +5 -0
  9. data/generators/gateway/gateway_generator.rb +61 -0
  10. data/generators/gateway/templates/gateway.rb +77 -0
  11. data/generators/gateway/templates/gateway_test.rb +49 -0
  12. data/generators/gateway/templates/remote_gateway_test.rb +57 -0
  13. data/generators/integration/USAGE +5 -0
  14. data/generators/integration/integration_generator.rb +68 -0
  15. data/generators/integration/templates/helper.rb +34 -0
  16. data/generators/integration/templates/helper_test.rb +54 -0
  17. data/generators/integration/templates/integration.rb +18 -0
  18. data/generators/integration/templates/module_test.rb +9 -0
  19. data/generators/integration/templates/notification.rb +100 -0
  20. data/generators/integration/templates/notification_test.rb +41 -0
  21. data/init.rb +3 -0
  22. data/lib/active_merchant.rb +76 -0
  23. data/lib/active_merchant/billing/avs_result.rb +95 -0
  24. data/lib/active_merchant/billing/base.rb +57 -0
  25. data/lib/active_merchant/billing/check.rb +68 -0
  26. data/lib/active_merchant/billing/credit_card.rb +157 -0
  27. data/lib/active_merchant/billing/credit_card_formatting.rb +21 -0
  28. data/lib/active_merchant/billing/credit_card_methods.rb +125 -0
  29. data/lib/active_merchant/billing/cvv_result.rb +38 -0
  30. data/lib/active_merchant/billing/expiry_date.rb +28 -0
  31. data/lib/active_merchant/billing/gateway.rb +162 -0
  32. data/lib/active_merchant/billing/gateways.rb +3 -0
  33. data/lib/active_merchant/billing/gateways/authorize_net.rb +646 -0
  34. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +702 -0
  35. data/lib/active_merchant/billing/gateways/beanstream.rb +102 -0
  36. data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +233 -0
  37. data/lib/active_merchant/billing/gateways/beanstream_interac.rb +54 -0
  38. data/lib/active_merchant/billing/gateways/bogus.rb +86 -0
  39. data/lib/active_merchant/billing/gateways/braintree.rb +222 -0
  40. data/lib/active_merchant/billing/gateways/card_stream.rb +230 -0
  41. data/lib/active_merchant/billing/gateways/cyber_source.rb +406 -0
  42. data/lib/active_merchant/billing/gateways/data_cash.rb +595 -0
  43. data/lib/active_merchant/billing/gateways/efsnet.rb +229 -0
  44. data/lib/active_merchant/billing/gateways/eway.rb +272 -0
  45. data/lib/active_merchant/billing/gateways/exact.rb +222 -0
  46. data/lib/active_merchant/billing/gateways/linkpoint.rb +396 -0
  47. data/lib/active_merchant/billing/gateways/modern_payments.rb +36 -0
  48. data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +214 -0
  49. data/lib/active_merchant/billing/gateways/moneris.rb +205 -0
  50. data/lib/active_merchant/billing/gateways/net_registry.rb +189 -0
  51. data/lib/active_merchant/billing/gateways/netbilling.rb +168 -0
  52. data/lib/active_merchant/billing/gateways/pay_junction.rb +392 -0
  53. data/lib/active_merchant/billing/gateways/pay_secure.rb +120 -0
  54. data/lib/active_merchant/billing/gateways/payflow.rb +236 -0
  55. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +213 -0
  56. data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +39 -0
  57. data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +13 -0
  58. data/lib/active_merchant/billing/gateways/payflow_express.rb +138 -0
  59. data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +15 -0
  60. data/lib/active_merchant/billing/gateways/payflow_uk.rb +21 -0
  61. data/lib/active_merchant/billing/gateways/payment_express.rb +242 -0
  62. data/lib/active_merchant/billing/gateways/paypal.rb +108 -0
  63. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +325 -0
  64. data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +38 -0
  65. data/lib/active_merchant/billing/gateways/paypal_ca.rb +13 -0
  66. data/lib/active_merchant/billing/gateways/paypal_express.rb +130 -0
  67. data/lib/active_merchant/billing/gateways/paypal_express_common.rb +20 -0
  68. data/lib/active_merchant/billing/gateways/plugnpay.rb +292 -0
  69. data/lib/active_merchant/billing/gateways/protx.rb +284 -0
  70. data/lib/active_merchant/billing/gateways/psigate.rb +214 -0
  71. data/lib/active_merchant/billing/gateways/psl_card.rb +302 -0
  72. data/lib/active_merchant/billing/gateways/quickpay.rb +183 -0
  73. data/lib/active_merchant/billing/gateways/realex.rb +200 -0
  74. data/lib/active_merchant/billing/gateways/sage.rb +145 -0
  75. data/lib/active_merchant/billing/gateways/sage/sage_bankcard.rb +88 -0
  76. data/lib/active_merchant/billing/gateways/sage/sage_core.rb +110 -0
  77. data/lib/active_merchant/billing/gateways/sage/sage_virtual_check.rb +97 -0
  78. data/lib/active_merchant/billing/gateways/secure_pay.rb +31 -0
  79. data/lib/active_merchant/billing/gateways/secure_pay_au.rb +157 -0
  80. data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +113 -0
  81. data/lib/active_merchant/billing/gateways/skip_jack.rb +439 -0
  82. data/lib/active_merchant/billing/gateways/trans_first.rb +127 -0
  83. data/lib/active_merchant/billing/gateways/trust_commerce.rb +414 -0
  84. data/lib/active_merchant/billing/gateways/usa_epay.rb +194 -0
  85. data/lib/active_merchant/billing/gateways/verifi.rb +228 -0
  86. data/lib/active_merchant/billing/gateways/viaklix.rb +165 -0
  87. data/lib/active_merchant/billing/gateways/wirecard.rb +305 -0
  88. data/lib/active_merchant/billing/integrations.rb +21 -0
  89. data/lib/active_merchant/billing/integrations/action_view_helper.rb +79 -0
  90. data/lib/active_merchant/billing/integrations/bogus.rb +22 -0
  91. data/lib/active_merchant/billing/integrations/bogus/helper.rb +17 -0
  92. data/lib/active_merchant/billing/integrations/bogus/notification.rb +11 -0
  93. data/lib/active_merchant/billing/integrations/bogus/return.rb +10 -0
  94. data/lib/active_merchant/billing/integrations/chronopay.rb +22 -0
  95. data/lib/active_merchant/billing/integrations/chronopay/helper.rb +81 -0
  96. data/lib/active_merchant/billing/integrations/chronopay/notification.rb +156 -0
  97. data/lib/active_merchant/billing/integrations/chronopay/return.rb +10 -0
  98. data/lib/active_merchant/billing/integrations/gestpay.rb +26 -0
  99. data/lib/active_merchant/billing/integrations/gestpay/common.rb +42 -0
  100. data/lib/active_merchant/billing/integrations/gestpay/helper.rb +70 -0
  101. data/lib/active_merchant/billing/integrations/gestpay/notification.rb +83 -0
  102. data/lib/active_merchant/billing/integrations/gestpay/return.rb +10 -0
  103. data/lib/active_merchant/billing/integrations/helper.rb +93 -0
  104. data/lib/active_merchant/billing/integrations/hi_trust.rb +26 -0
  105. data/lib/active_merchant/billing/integrations/hi_trust/helper.rb +58 -0
  106. data/lib/active_merchant/billing/integrations/hi_trust/notification.rb +59 -0
  107. data/lib/active_merchant/billing/integrations/hi_trust/return.rb +67 -0
  108. data/lib/active_merchant/billing/integrations/nochex.rb +87 -0
  109. data/lib/active_merchant/billing/integrations/nochex/helper.rb +68 -0
  110. data/lib/active_merchant/billing/integrations/nochex/notification.rb +94 -0
  111. data/lib/active_merchant/billing/integrations/nochex/return.rb +10 -0
  112. data/lib/active_merchant/billing/integrations/notification.rb +62 -0
  113. data/lib/active_merchant/billing/integrations/paypal.rb +40 -0
  114. data/lib/active_merchant/billing/integrations/paypal/helper.rb +118 -0
  115. data/lib/active_merchant/billing/integrations/paypal/notification.rb +154 -0
  116. data/lib/active_merchant/billing/integrations/paypal/return.rb +10 -0
  117. data/lib/active_merchant/billing/integrations/return.rb +35 -0
  118. data/lib/active_merchant/billing/integrations/two_checkout.rb +23 -0
  119. data/lib/active_merchant/billing/integrations/two_checkout/helper.rb +59 -0
  120. data/lib/active_merchant/billing/integrations/two_checkout/notification.rb +114 -0
  121. data/lib/active_merchant/billing/integrations/two_checkout/return.rb +17 -0
  122. data/lib/active_merchant/billing/response.rb +32 -0
  123. data/lib/active_merchant/lib/country.rb +298 -0
  124. data/lib/active_merchant/lib/error.rb +4 -0
  125. data/lib/active_merchant/lib/post_data.rb +22 -0
  126. data/lib/active_merchant/lib/posts_data.rb +89 -0
  127. data/lib/active_merchant/lib/requires_parameters.rb +16 -0
  128. data/lib/active_merchant/lib/utils.rb +18 -0
  129. data/lib/active_merchant/lib/validateable.rb +76 -0
  130. data/lib/certs/cacert.pem +7815 -0
  131. data/lib/support/gateway_support.rb +58 -0
  132. data/lib/tasks/cia.rb +90 -0
  133. data/script/destroy +14 -0
  134. data/script/generate +14 -0
  135. data/test/extra/binding_of_caller.rb +80 -0
  136. data/test/extra/breakpoint.rb +547 -0
  137. data/test/fixtures.yml +301 -0
  138. data/test/remote/gateways/remote_authorize_net_cim_test.rb +459 -0
  139. data/test/remote/gateways/remote_authorize_net_test.rb +145 -0
  140. data/test/remote/gateways/remote_beanstream_interac_test.rb +53 -0
  141. data/test/remote/gateways/remote_beanstream_test.rb +150 -0
  142. data/test/remote/gateways/remote_braintree_test.rb +154 -0
  143. data/test/remote/gateways/remote_card_stream_test.rb +148 -0
  144. data/test/remote/gateways/remote_cyber_source_test.rb +144 -0
  145. data/test/remote/gateways/remote_data_cash_test.rb +357 -0
  146. data/test/remote/gateways/remote_efsnet_test.rb +81 -0
  147. data/test/remote/gateways/remote_eway_test.rb +74 -0
  148. data/test/remote/gateways/remote_exact_test.rb +60 -0
  149. data/test/remote/gateways/remote_linkpoint_test.rb +112 -0
  150. data/test/remote/gateways/remote_modern_payments_cim_test.rb +58 -0
  151. data/test/remote/gateways/remote_modern_payments_test.rb +43 -0
  152. data/test/remote/gateways/remote_moneris_test.rb +82 -0
  153. data/test/remote/gateways/remote_net_registry_test.rb +85 -0
  154. data/test/remote/gateways/remote_netbilling_test.rb +70 -0
  155. data/test/remote/gateways/remote_pay_junction_test.rb +143 -0
  156. data/test/remote/gateways/remote_pay_secure_test.rb +39 -0
  157. data/test/remote/gateways/remote_payflow_express_test.rb +50 -0
  158. data/test/remote/gateways/remote_payflow_test.rb +237 -0
  159. data/test/remote/gateways/remote_payflow_uk_test.rb +173 -0
  160. data/test/remote/gateways/remote_payment_express_test.rb +126 -0
  161. data/test/remote/gateways/remote_paypal_express_test.rb +49 -0
  162. data/test/remote/gateways/remote_paypal_test.rb +167 -0
  163. data/test/remote/gateways/remote_plugnpay_test.rb +72 -0
  164. data/test/remote/gateways/remote_protx_test.rb +184 -0
  165. data/test/remote/gateways/remote_psigate_test.rb +50 -0
  166. data/test/remote/gateways/remote_psl_card_test.rb +106 -0
  167. data/test/remote/gateways/remote_quickpay_test.rb +182 -0
  168. data/test/remote/gateways/remote_realex_test.rb +224 -0
  169. data/test/remote/gateways/remote_sage_bankcard_test.rb +109 -0
  170. data/test/remote/gateways/remote_sage_test.rb +87 -0
  171. data/test/remote/gateways/remote_sage_virtual_check_test.rb +62 -0
  172. data/test/remote/gateways/remote_secure_pay_au_test.rb +40 -0
  173. data/test/remote/gateways/remote_secure_pay_tech_test.rb +37 -0
  174. data/test/remote/gateways/remote_secure_pay_test.rb +28 -0
  175. data/test/remote/gateways/remote_skipjack_test.rb +105 -0
  176. data/test/remote/gateways/remote_trans_first_test.rb +34 -0
  177. data/test/remote/gateways/remote_trust_commerce_test.rb +152 -0
  178. data/test/remote/gateways/remote_usa_epay_test.rb +46 -0
  179. data/test/remote/gateways/remote_verifi_test.rb +107 -0
  180. data/test/remote/gateways/remote_viaklix_test.rb +43 -0
  181. data/test/remote/gateways/remote_wirecard_test.rb +77 -0
  182. data/test/remote/integrations/remote_gestpay_integration_test.rb +37 -0
  183. data/test/remote/integrations/remote_paypal_integration_test.rb +26 -0
  184. data/test/test_helper.rb +191 -0
  185. data/test/unit/avs_result_test.rb +59 -0
  186. data/test/unit/base_test.rb +55 -0
  187. data/test/unit/check_test.rb +88 -0
  188. data/test/unit/country_code_test.rb +33 -0
  189. data/test/unit/country_test.rb +64 -0
  190. data/test/unit/credit_card_formatting_test.rb +19 -0
  191. data/test/unit/credit_card_methods_test.rb +170 -0
  192. data/test/unit/credit_card_test.rb +311 -0
  193. data/test/unit/cvv_result_test.rb +33 -0
  194. data/test/unit/expiry_date_test.rb +21 -0
  195. data/test/unit/gateways/authorize_net_cim_test.rb +638 -0
  196. data/test/unit/gateways/authorize_net_test.rb +291 -0
  197. data/test/unit/gateways/beanstream_interac_test.rb +51 -0
  198. data/test/unit/gateways/beanstream_test.rb +108 -0
  199. data/test/unit/gateways/bogus_test.rb +42 -0
  200. data/test/unit/gateways/braintree_test.rb +116 -0
  201. data/test/unit/gateways/card_stream_test.rb +90 -0
  202. data/test/unit/gateways/cyber_source_test.rb +188 -0
  203. data/test/unit/gateways/data_cash_test.rb +132 -0
  204. data/test/unit/gateways/efsnet_test.rb +123 -0
  205. data/test/unit/gateways/eway_test.rb +118 -0
  206. data/test/unit/gateways/exact_test.rb +156 -0
  207. data/test/unit/gateways/gateway_test.rb +48 -0
  208. data/test/unit/gateways/linkpoint_test.rb +167 -0
  209. data/test/unit/gateways/modern_payments_cim_test.rb +171 -0
  210. data/test/unit/gateways/moneris_test.rb +158 -0
  211. data/test/unit/gateways/net_registry_test.rb +416 -0
  212. data/test/unit/gateways/netbilling_test.rb +54 -0
  213. data/test/unit/gateways/pay_junction_test.rb +123 -0
  214. data/test/unit/gateways/pay_secure_test.rb +71 -0
  215. data/test/unit/gateways/payflow_express_test.rb +173 -0
  216. data/test/unit/gateways/payflow_express_uk_test.rb +14 -0
  217. data/test/unit/gateways/payflow_test.rb +301 -0
  218. data/test/unit/gateways/payflow_uk_test.rb +30 -0
  219. data/test/unit/gateways/payment_express_test.rb +195 -0
  220. data/test/unit/gateways/paypal_express_test.rb +382 -0
  221. data/test/unit/gateways/paypal_test.rb +520 -0
  222. data/test/unit/gateways/plugnpay_test.rb +86 -0
  223. data/test/unit/gateways/protx_test.rb +122 -0
  224. data/test/unit/gateways/psigate_test.rb +169 -0
  225. data/test/unit/gateways/psl_card_test.rb +64 -0
  226. data/test/unit/gateways/quickpay_test.rb +112 -0
  227. data/test/unit/gateways/realex_test.rb +151 -0
  228. data/test/unit/gateways/sage_bankcard_test.rb +162 -0
  229. data/test/unit/gateways/sage_virtual_check_test.rb +71 -0
  230. data/test/unit/gateways/secure_pay_au_test.rb +207 -0
  231. data/test/unit/gateways/secure_pay_tech_test.rb +44 -0
  232. data/test/unit/gateways/secure_pay_test.rb +87 -0
  233. data/test/unit/gateways/skip_jack_test.rb +133 -0
  234. data/test/unit/gateways/trans_first_test.rb +112 -0
  235. data/test/unit/gateways/trust_commerce_test.rb +78 -0
  236. data/test/unit/gateways/usa_epay_test.rb +128 -0
  237. data/test/unit/gateways/verifi_test.rb +96 -0
  238. data/test/unit/gateways/viaklix_test.rb +78 -0
  239. data/test/unit/gateways/wirecard_test.rb +232 -0
  240. data/test/unit/generators/test_gateway_generator.rb +46 -0
  241. data/test/unit/generators/test_generator_helper.rb +20 -0
  242. data/test/unit/generators/test_integration_generator.rb +53 -0
  243. data/test/unit/integrations/action_view_helper_test.rb +50 -0
  244. data/test/unit/integrations/bogus_module_test.rb +20 -0
  245. data/test/unit/integrations/chronopay_module_test.rb +13 -0
  246. data/test/unit/integrations/gestpay_module_test.rb +14 -0
  247. data/test/unit/integrations/helpers/bogus_helper_test.rb +28 -0
  248. data/test/unit/integrations/helpers/chronopay_helper_test.rb +67 -0
  249. data/test/unit/integrations/helpers/gestpay_helper_test.rb +100 -0
  250. data/test/unit/integrations/helpers/hi_trust_helper_test.rb +16 -0
  251. data/test/unit/integrations/helpers/nochex_helper_test.rb +53 -0
  252. data/test/unit/integrations/helpers/paypal_helper_test.rb +162 -0
  253. data/test/unit/integrations/helpers/two_checkout_helper_test.rb +92 -0
  254. data/test/unit/integrations/hi_trust_module_test.rb +13 -0
  255. data/test/unit/integrations/nochex_module_test.rb +13 -0
  256. data/test/unit/integrations/notifications/chronopay_notification_test.rb +66 -0
  257. data/test/unit/integrations/notifications/gestpay_notification_test.rb +60 -0
  258. data/test/unit/integrations/notifications/hi_trust_notification_test.rb +59 -0
  259. data/test/unit/integrations/notifications/nochex_notification_test.rb +51 -0
  260. data/test/unit/integrations/notifications/notification_test.rb +54 -0
  261. data/test/unit/integrations/notifications/paypal_notification_test.rb +85 -0
  262. data/test/unit/integrations/notifications/two_checkout_notification_test.rb +55 -0
  263. data/test/unit/integrations/paypal_module_test.rb +28 -0
  264. data/test/unit/integrations/returns/chronopay_return_test.rb +11 -0
  265. data/test/unit/integrations/returns/gestpay_return_test.rb +10 -0
  266. data/test/unit/integrations/returns/hi_trust_return_test.rb +24 -0
  267. data/test/unit/integrations/returns/nochex_return_test.rb +10 -0
  268. data/test/unit/integrations/returns/paypal_return_test.rb +10 -0
  269. data/test/unit/integrations/returns/return_test.rb +11 -0
  270. data/test/unit/integrations/returns/two_checkout_return_test.rb +24 -0
  271. data/test/unit/integrations/two_checkout_module_test.rb +13 -0
  272. data/test/unit/post_data_test.rb +55 -0
  273. data/test/unit/posts_data_test.rb +100 -0
  274. data/test/unit/response_test.rb +28 -0
  275. data/test/unit/utils_test.rb +7 -0
  276. data/test/unit/validateable_test.rb +60 -0
  277. metadata +454 -0
@@ -0,0 +1,127 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ class TransFirstGateway < Gateway
4
+ URL = 'https://webservices.primerchants.com/creditcard.asmx/CCSale'
5
+
6
+ self.supported_countries = ['US']
7
+ self.supported_cardtypes = [:visa, :master, :american_express, :discover]
8
+ self.homepage_url = 'http://www.transfirst.com/'
9
+ self.display_name = 'TransFirst'
10
+
11
+ UNUSED_FIELDS = %w(ECIValue UserId CAVVData TrackData POSInd EComInd MerchZIP MerchCustPNum MCC InstallmentNum InstallmentOf POSEntryMode POSConditionCode AuthCharInd CardCertData)
12
+
13
+ DECLINED = 'The transaction was declined'
14
+
15
+ def initialize(options = {})
16
+ requires!(options, :login, :password)
17
+ @options = options
18
+ super
19
+ end
20
+
21
+ def purchase(money, credit_card, options = {})
22
+ post = {}
23
+
24
+ add_amount(post, money)
25
+ add_invoice(post, options)
26
+ add_credit_card(post, credit_card)
27
+ add_address(post, options)
28
+
29
+ commit(post)
30
+ end
31
+
32
+ private
33
+ def add_amount(post, money)
34
+ add_pair(post, :Amount, amount(money), :required => true)
35
+ end
36
+
37
+ def add_address(post, options)
38
+ address = options[:billing_address] || options[:address]
39
+
40
+ if address
41
+ add_pair(post, :Address, address[:address1])
42
+ add_pair(post, :ZipCode, address[:zip])
43
+ end
44
+ end
45
+
46
+ def add_invoice(post, options)
47
+ add_pair(post, :RefID, options[:order_id], :required => true)
48
+ add_pair(post, :PONumber, options[:invoice], :required => true)
49
+ add_pair(post, :SaleTaxAmount, amount(options[:tax] || 0))
50
+ add_pair(post, :PaymentDesc, options[:description], :required => true)
51
+ add_pair(post, :TaxIndicator, 0)
52
+ end
53
+
54
+ def add_credit_card(post, credit_card)
55
+ add_pair(post, :CardHolderName, credit_card.name, :required => true)
56
+ add_pair(post, :CardNumber, credit_card.number, :required => true)
57
+
58
+ add_pair(post, :Expiration, expdate(credit_card), :required => true)
59
+ add_pair(post, :CVV2, credit_card.verification_value)
60
+ end
61
+
62
+ def add_unused_fields(post)
63
+ UNUSED_FIELDS.each do |f|
64
+ post[f] = ""
65
+ end
66
+ end
67
+
68
+ def expdate(credit_card)
69
+ year = format(credit_card.year, :two_digits)
70
+ month = format(credit_card.month, :two_digits)
71
+
72
+ "#{month}#{year}"
73
+ end
74
+
75
+ def parse(data)
76
+ response = {}
77
+
78
+ xml = REXML::Document.new(data)
79
+ root = REXML::XPath.first(xml, "//CCSaleDebitResponse")
80
+
81
+ if root.nil?
82
+ response[:message] = data.to_s.strip
83
+ else
84
+ root.elements.to_a.each do |node|
85
+ response[node.name.underscore.to_sym] = node.text
86
+ end
87
+ end
88
+
89
+ response
90
+ end
91
+
92
+ def commit(params)
93
+ response = parse( ssl_post(URL, post_data(params)) )
94
+
95
+ Response.new(response[:status] == "Authorized", message_from(response), response,
96
+ :test => test?,
97
+ :authorization => response[:trans_id],
98
+ :avs_result => { :code => response[:avs_code] },
99
+ :cvv_result => response[:cvv2_code]
100
+ )
101
+ end
102
+
103
+ def message_from(response)
104
+ case response[:message]
105
+ when 'Call Voice Center'
106
+ DECLINED
107
+ else
108
+ response[:message]
109
+ end
110
+ end
111
+
112
+ def post_data(params = {})
113
+ add_unused_fields(params)
114
+ params[:MerchantID] = @options[:login]
115
+ params[:RegKey] = @options[:password]
116
+
117
+ request = params.collect { |key, value| "#{key}=#{CGI.escape(value.to_s)}" }.join("&")
118
+ request
119
+ end
120
+
121
+ def add_pair(post, key, value, options = {})
122
+ post[key] = value if !value.blank? || options[:required]
123
+ end
124
+ end
125
+ end
126
+ end
127
+
@@ -0,0 +1,414 @@
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
+ 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
+ self.money_format = :cents
105
+ self.supported_cardtypes = [:visa, :master, :discover, :american_express, :diners_club, :jcb]
106
+ self.supported_countries = ['US']
107
+ self.homepage_url = 'http://www.trustcommerce.com/'
108
+ self.display_name = 'TrustCommerce'
109
+
110
+ def self.tclink?
111
+ defined?(TCLink)
112
+ end
113
+
114
+ # Creates a new TrustCommerceGateway
115
+ #
116
+ # The gateway requires that a valid login and password be passed
117
+ # in the +options+ hash.
118
+ #
119
+ # ==== Options
120
+ #
121
+ # * <tt>:login</tt> -- The TrustCommerce account login.
122
+ # * <tt>:password</tt> -- The TrustCommerce account password.
123
+ # * <tt>:test => +true+ or +false+</tt> -- Perform test transactions
124
+ #
125
+ # ==== Test Account Credentials
126
+ # * <tt>:login</tt> -- TestMerchant
127
+ # * <tt>:password</tt> -- password
128
+ def initialize(options = {})
129
+ requires!(options, :login, :password)
130
+
131
+ @options = options
132
+ super
133
+ end
134
+
135
+ def tclink?
136
+ self.class.tclink?
137
+ end
138
+
139
+ def test?
140
+ @options[:test] || super
141
+ end
142
+
143
+ # authorize() is the first half of the preauth(authorize)/postauth(capture) model. The TC API docs call this
144
+ # preauth, we preserve active_merchant's nomenclature of authorize() for consistency with the rest of the library. This
145
+ # method simply checks to make sure funds are available for a transaction, and returns a transid that can be used later to
146
+ # postauthorize (capture) the funds.
147
+
148
+ def authorize(money, creditcard_or_billing_id, options = {})
149
+ parameters = {
150
+ :amount => amount(money),
151
+ }
152
+
153
+ add_order_id(parameters, options)
154
+ add_customer_data(parameters, options)
155
+ add_payment_source(parameters, creditcard_or_billing_id)
156
+ add_addresses(parameters, options)
157
+ commit('preauth', parameters)
158
+ end
159
+
160
+ # purchase() is a simple sale. This is one of the most common types of transactions, and is extremely simple. All that you need
161
+ # to process a purchase are an amount in cents or a money object and a creditcard object or billingid string.
162
+ def purchase(money, creditcard_or_billing_id, options = {})
163
+ parameters = {
164
+ :amount => amount(money),
165
+ }
166
+
167
+ add_order_id(parameters, options)
168
+ add_customer_data(parameters, options)
169
+ add_payment_source(parameters, creditcard_or_billing_id)
170
+ add_addresses(parameters, options)
171
+ commit('sale', parameters)
172
+ end
173
+
174
+ # capture() is the second half of the preauth(authorize)/postauth(capture) model. The TC API docs call this
175
+ # postauth, we preserve active_merchant's nomenclature of capture() for consistency with the rest of the library. To process
176
+ # a postauthorization with TC, you need an amount in cents or a money object, and a TC transid.
177
+ def capture(money, authorization, options = {})
178
+ parameters = {
179
+ :amount => amount(money),
180
+ :transid => authorization,
181
+ }
182
+
183
+ commit('postauth', parameters)
184
+ end
185
+
186
+ # credit() allows you to return money to a card that was previously billed. You need to supply the amount, in cents or a money object,
187
+ # that you want to refund, and a TC transid for the transaction that you are refunding.
188
+ def credit(money, identification, options = {})
189
+ parameters = {
190
+ :amount => amount(money),
191
+ :transid => identification
192
+ }
193
+
194
+ commit('credit', parameters)
195
+ end
196
+
197
+ # void() clears an existing authorization and releases the reserved fund
198
+ # s back to the cardholder. The TC API refers to this transaction as a
199
+ # reversal. After voiding, you will no longer be able to capture funds
200
+ # from this authorization. TrustCommerce seems to always return a status
201
+ # of "accepted" even if the transid you are trying to deauthorize has
202
+ # already been captured. Note: Your account needs to be configured by
203
+ # TrustCommerce to allow for reversal transactions before you can use this
204
+ # method.
205
+ #
206
+ # NOTE: AMEX preauth's cannot be reversed. If you want to clear it more
207
+ # quickly than the automatic expiration (7-10 days), you will have to
208
+ # capture it and then immediately issue a credit for the same amount
209
+ # which should clear the customers credit card with 48 hours according to
210
+ # TC.
211
+ def void(authorization, options = {})
212
+ parameters = {
213
+ :transid => authorization,
214
+ }
215
+
216
+ commit('reversal', parameters)
217
+ end
218
+
219
+ # recurring() a TrustCommerce account that is activated for Citatdel, TrustCommerce's
220
+ # hosted customer billing info database.
221
+ #
222
+ # Recurring billing uses the same TC action as a plain-vanilla 'store', but we have a separate method for clarity. It can be called
223
+ # like store, with the addition of a required 'periodicity' parameter:
224
+ #
225
+ # The parameter :periodicity should be specified as either :bimonthly, :monthly, :biweekly, :weekly, :yearly or :daily
226
+ #
227
+ # gateway.recurring(tendollar, creditcard, :periodicity => :weekly)
228
+ #
229
+ # You can optionally specify how long you want payments to continue using 'payments'
230
+ def recurring(money, creditcard, options = {})
231
+ requires!(options, [:periodicity, :bimonthly, :monthly, :biweekly, :weekly, :yearly, :daily] )
232
+
233
+ cycle = case options[:periodicity]
234
+ when :monthly
235
+ '1m'
236
+ when :bimonthly
237
+ '2m'
238
+ when :weekly
239
+ '1w'
240
+ when :biweekly
241
+ '2w'
242
+ when :yearly
243
+ '1y'
244
+ when :daily
245
+ '1d'
246
+ end
247
+
248
+ parameters = {
249
+ :amount => amount(money),
250
+ :cycle => cycle,
251
+ :verify => options[:verify] || 'y',
252
+ :billingid => options[:billingid] || nil,
253
+ :payments => options[:payments] || nil,
254
+ }
255
+
256
+ add_creditcard(parameters, creditcard)
257
+
258
+ commit('store', parameters)
259
+ end
260
+
261
+ # store() requires a TrustCommerce account that is activated for Citatdel. You can call it with a credit card and a billing ID
262
+ # you would like to use to reference the stored credit card info for future captures. Use 'verify' to specify whether you want
263
+ # to simply store the card in the DB, or you want TC to verify the data first.
264
+
265
+ def store(creditcard, options = {})
266
+ parameters = {
267
+ :verify => options[:verify] || 'y',
268
+ :billingid => options[:billingid] || options[:billing_id] || nil,
269
+ }
270
+
271
+ add_creditcard(parameters, creditcard)
272
+ add_addresses(parameters, options)
273
+ commit('store', parameters)
274
+ end
275
+
276
+ # To unstore a creditcard stored in Citadel using store() or recurring(), all that is required is the billing id. When you run
277
+ # unstore() the information will be removed and a Response object will be returned indicating the success of the action.
278
+ def unstore(identification, options = {})
279
+ parameters = {
280
+ :billingid => identification,
281
+ }
282
+
283
+ commit('unstore', parameters)
284
+ end
285
+
286
+ private
287
+ def add_payment_source(params, source)
288
+ if source.is_a?(String)
289
+ add_billing_id(params, source)
290
+ else
291
+ add_creditcard(params, source)
292
+ end
293
+ end
294
+
295
+ def expdate(creditcard)
296
+ year = sprintf("%.4i", creditcard.year)
297
+ month = sprintf("%.2i", creditcard.month)
298
+
299
+ "#{month}#{year[-2..-1]}"
300
+ end
301
+
302
+ def add_creditcard(params, creditcard)
303
+ params[:media] = "cc"
304
+ params[:name] = creditcard.name
305
+ params[:cc] = creditcard.number
306
+ params[:exp] = expdate(creditcard)
307
+ params[:cvv] = creditcard.verification_value if creditcard.verification_value?
308
+ end
309
+
310
+ def add_order_id(params, options)
311
+ params[:ticket] = options[:order_id] unless options[:order_id].blank?
312
+ end
313
+
314
+ def add_billing_id(params, billingid)
315
+ params[:billingid] = billingid
316
+ end
317
+
318
+ def add_customer_data(params, options)
319
+ params[:email] = options[:email] unless options[:email].blank?
320
+ params[:ip] = options[:ip] unless options[:ip].blank?
321
+ end
322
+
323
+ def add_addresses(params, options)
324
+ address = options[:billing_address] || options[:address]
325
+
326
+ if address
327
+ params[:address1] = address[:address1] unless address[:address1].blank?
328
+ params[:address2] = address[:address2] unless address[:address2].blank?
329
+ params[:city] = address[:city] unless address[:city].blank?
330
+ params[:state] = address[:state] unless address[:state].blank?
331
+ params[:zip] = address[:zip] unless address[:zip].blank?
332
+ params[:country] = address[:country] unless address[:country].blank?
333
+ params[:avs] = 'n'
334
+ end
335
+
336
+ if shipping_address = options[:shipping_address]
337
+ params[:shipto_name] = shipping_address[:name] unless shipping_address[:name].blank?
338
+ params[:shipto_address1] = shipping_address[:address1] unless shipping_address[:address1].blank?
339
+ params[:shipto_address2] = shipping_address[:address2] unless shipping_address[:address2].blank?
340
+ params[:shipto_city] = shipping_address[:city] unless shipping_address[:city].blank?
341
+ params[:shipto_state] = shipping_address[:state] unless shipping_address[:state].blank?
342
+ params[:shipto_zip] = shipping_address[:zip] unless shipping_address[:zip].blank?
343
+ params[:shipto_country] = shipping_address[:country] unless shipping_address[:country].blank?
344
+ end
345
+ end
346
+
347
+ def clean_and_stringify_params(parameters)
348
+ # TCLink wants us to send a hash with string keys, and activemerchant pushes everything around with
349
+ # symbol keys. Before sending our input to TCLink, we convert all our keys to strings and dump the symbol keys.
350
+ # We also remove any pairs with nil values, as these confuse TCLink.
351
+ parameters.keys.reverse.each do |key|
352
+ if parameters[key]
353
+ parameters[key.to_s] = parameters[key]
354
+ end
355
+ parameters.delete(key)
356
+ end
357
+ end
358
+
359
+ def post_data(parameters)
360
+ parameters.collect { |key, value| "#{key}=#{ CGI.escape(value.to_s)}" }.join("&")
361
+ end
362
+
363
+ def commit(action, parameters)
364
+ parameters[:custid] = @options[:login]
365
+ parameters[:password] = @options[:password]
366
+ parameters[:demo] = test? ? 'y' : 'n'
367
+ parameters[:action] = action
368
+
369
+ clean_and_stringify_params(parameters)
370
+
371
+ data = if tclink?
372
+ TCLink.send(parameters)
373
+ else
374
+ parse( ssl_post(URL, post_data(parameters)) )
375
+ end
376
+
377
+ # to be considered successful, transaction status must be either "approved" or "accepted"
378
+ success = SUCCESS_TYPES.include?(data["status"])
379
+ message = message_from(data)
380
+ Response.new(success, message, data,
381
+ :test => test?,
382
+ :authorization => data["transid"],
383
+ :cvv_result => data["cvv"],
384
+ :avs_result => { :code => data["avs"] }
385
+ )
386
+ end
387
+
388
+ def parse(body)
389
+ results = {}
390
+
391
+ body.split(/\n/).each do |pair|
392
+ key,val = pair.split(/=/)
393
+ results[key] = val
394
+ end
395
+
396
+ results
397
+ end
398
+
399
+ def message_from(data)
400
+ status = case data["status"]
401
+ when "decline"
402
+ return DECLINE_CODES[data["declinetype"]]
403
+ when "baddata"
404
+ return BADDATA_CODES[data["error"]]
405
+ when "error"
406
+ return ERROR_CODES[data["errortype"]]
407
+ else
408
+ return "The transaction was successful"
409
+ end
410
+ end
411
+
412
+ end
413
+ end
414
+ end