activemerchant 1.4.2 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (227) hide show
  1. data.tar.gz.sig +0 -0
  2. data/CHANGELOG +78 -0
  3. data/{CONTRIBUTERS → CONTRIBUTORS} +44 -0
  4. data/{README → README.rdoc} +4 -1
  5. data/Rakefile +7 -13
  6. data/lib/active_merchant.rb +11 -21
  7. data/lib/active_merchant/billing/avs_result.rb +13 -10
  8. data/lib/active_merchant/billing/base.rb +2 -2
  9. data/lib/active_merchant/billing/check.rb +1 -1
  10. data/lib/active_merchant/billing/credit_card_methods.rb +2 -2
  11. data/lib/active_merchant/billing/expiry_date.rb +10 -4
  12. data/lib/active_merchant/billing/gateway.rb +7 -6
  13. data/lib/active_merchant/billing/gateways.rb +18 -3
  14. data/lib/active_merchant/billing/gateways/authorize_net.rb +20 -12
  15. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +40 -6
  16. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb.orig +736 -0
  17. data/lib/active_merchant/billing/gateways/braintree.rb +6 -211
  18. data/lib/active_merchant/billing/gateways/data_cash.rb +5 -7
  19. data/lib/active_merchant/billing/gateways/elavon.rb +134 -0
  20. data/lib/active_merchant/billing/gateways/eway.rb +7 -2
  21. data/lib/active_merchant/billing/gateways/first_pay.rb +172 -0
  22. data/lib/active_merchant/billing/gateways/instapay.rb +164 -0
  23. data/lib/active_merchant/billing/gateways/jetpay.rb +270 -0
  24. data/lib/active_merchant/billing/gateways/linkpoint.rb +65 -12
  25. data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +154 -0
  26. data/lib/active_merchant/billing/gateways/merchant_ware.rb +283 -0
  27. data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +12 -6
  28. data/lib/active_merchant/billing/gateways/ogone.rb +279 -0
  29. data/lib/active_merchant/billing/gateways/pay_secure.rb +1 -1
  30. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +1 -1
  31. data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +1 -1
  32. data/lib/active_merchant/billing/gateways/payflow_express.rb +1 -1
  33. data/lib/active_merchant/billing/gateways/payment_express.rb +20 -32
  34. data/lib/active_merchant/billing/gateways/paypal.rb +22 -9
  35. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +2 -1
  36. data/lib/active_merchant/billing/gateways/paypal_ca.rb +1 -1
  37. data/lib/active_merchant/billing/gateways/psl_card.rb +4 -6
  38. data/lib/active_merchant/billing/gateways/sage/sage_core.rb +7 -1
  39. data/lib/active_merchant/billing/gateways/{protx.rb → sage_pay.rb} +60 -35
  40. data/lib/active_merchant/billing/gateways/sallie_mae.rb +144 -0
  41. data/lib/active_merchant/billing/gateways/secure_pay.rb +1 -1
  42. data/lib/active_merchant/billing/gateways/skip_jack.rb +23 -10
  43. data/lib/active_merchant/billing/gateways/smart_ps.rb +265 -0
  44. data/lib/active_merchant/billing/gateways/transax.rb +25 -0
  45. data/lib/active_merchant/billing/gateways/viaklix.rb +38 -14
  46. data/lib/active_merchant/billing/gateways/wirecard.rb +15 -2
  47. data/lib/active_merchant/billing/integrations.rb +18 -11
  48. data/lib/active_merchant/billing/integrations/bogus.rb +4 -3
  49. data/lib/active_merchant/billing/integrations/chronopay.rb +4 -3
  50. data/lib/active_merchant/billing/integrations/chronopay/notification.rb +3 -1
  51. data/lib/active_merchant/billing/integrations/gestpay.rb +4 -5
  52. data/lib/active_merchant/billing/integrations/gestpay/notification.rb +3 -1
  53. data/lib/active_merchant/billing/integrations/hi_trust.rb +4 -3
  54. data/lib/active_merchant/billing/integrations/nochex.rb +4 -3
  55. data/lib/active_merchant/billing/integrations/nochex/notification.rb +1 -1
  56. data/lib/active_merchant/billing/integrations/paypal.rb +3 -4
  57. data/lib/active_merchant/billing/integrations/paypal/helper.rb +9 -8
  58. data/lib/active_merchant/billing/integrations/quickpay.rb +2 -3
  59. data/lib/active_merchant/billing/integrations/quickpay/helper.rb +1 -1
  60. data/lib/active_merchant/billing/integrations/two_checkout.rb +3 -3
  61. data/lib/active_merchant/lib/connection.rb +170 -0
  62. data/lib/active_merchant/lib/country.rb +4 -1
  63. data/lib/active_merchant/lib/posts_data.rb +22 -84
  64. data/test/fixtures.yml +39 -1
  65. data/test/remote/gateways/remote_authorize_net_cim_test.rb +2 -1
  66. data/test/remote/gateways/remote_authorize_net_test.rb +1 -1
  67. data/test/remote/gateways/remote_beanstream_interac_test.rb +1 -1
  68. data/test/remote/gateways/remote_beanstream_test.rb +1 -1
  69. data/test/remote/gateways/remote_braintree_test.rb +2 -9
  70. data/test/remote/gateways/remote_card_stream_test.rb +1 -1
  71. data/test/remote/gateways/remote_cyber_source_test.rb +1 -1
  72. data/test/remote/gateways/remote_data_cash_test.rb +1 -2
  73. data/test/remote/gateways/remote_efsnet_test.rb +1 -1
  74. data/test/remote/gateways/remote_elavon_test.rb +66 -0
  75. data/test/remote/gateways/remote_eway_test.rb +1 -1
  76. data/test/remote/gateways/remote_exact_test.rb +1 -1
  77. data/test/remote/gateways/remote_first_pay_test.rb +87 -0
  78. data/test/remote/gateways/remote_instapay_test.rb +61 -0
  79. data/test/remote/gateways/remote_jetpay_test.rb +103 -0
  80. data/test/remote/gateways/remote_linkpoint_test.rb +11 -2
  81. data/test/remote/gateways/remote_merchant_e_solutions_test.rb +173 -0
  82. data/test/remote/gateways/remote_merchant_ware_test.rb +113 -0
  83. data/test/remote/gateways/remote_modern_payments_cim_test.rb +1 -1
  84. data/test/remote/gateways/remote_modern_payments_test.rb +23 -9
  85. data/test/remote/gateways/remote_moneris_test.rb +1 -1
  86. data/test/remote/gateways/remote_net_registry_test.rb +1 -1
  87. data/test/remote/gateways/remote_netbilling_test.rb +1 -1
  88. data/test/remote/gateways/remote_ogone_test.rb +115 -0
  89. data/test/remote/gateways/remote_pay_junction_test.rb +1 -1
  90. data/test/remote/gateways/remote_pay_secure_test.rb +1 -1
  91. data/test/remote/gateways/remote_payflow_express_test.rb +1 -1
  92. data/test/remote/gateways/remote_payflow_test.rb +1 -1
  93. data/test/remote/gateways/remote_payflow_uk_test.rb +1 -1
  94. data/test/remote/gateways/remote_payment_express_test.rb +17 -7
  95. data/test/remote/gateways/remote_paypal_express_test.rb +1 -1
  96. data/test/remote/gateways/remote_paypal_test.rb +26 -2
  97. data/test/remote/gateways/remote_plugnpay_test.rb +1 -1
  98. data/test/remote/gateways/remote_psigate_test.rb +1 -1
  99. data/test/remote/gateways/remote_psl_card_test.rb +1 -3
  100. data/test/remote/gateways/remote_quickpay_test.rb +1 -1
  101. data/test/remote/gateways/remote_realex_test.rb +1 -1
  102. data/test/remote/gateways/remote_sage_bankcard_test.rb +1 -1
  103. data/test/remote/gateways/remote_sage_pay_test.rb +219 -0
  104. data/test/remote/gateways/remote_sage_test.rb +1 -1
  105. data/test/remote/gateways/remote_sage_virtual_check_test.rb +1 -1
  106. data/test/remote/gateways/remote_sallie_mae_test.rb +51 -0
  107. data/test/remote/gateways/remote_secure_pay_au_test.rb +1 -1
  108. data/test/remote/gateways/remote_secure_pay_tech_test.rb +1 -1
  109. data/test/remote/gateways/remote_secure_pay_test.rb +2 -2
  110. data/test/remote/gateways/remote_skipjack_test.rb +1 -1
  111. data/test/remote/gateways/remote_trans_first_test.rb +1 -1
  112. data/test/remote/gateways/remote_transax_test.rb +112 -0
  113. data/test/remote/gateways/remote_trust_commerce_test.rb +1 -1
  114. data/test/remote/gateways/remote_usa_epay_test.rb +1 -1
  115. data/test/remote/gateways/remote_verifi_test.rb +1 -1
  116. data/test/remote/gateways/remote_viaklix_test.rb +1 -1
  117. data/test/remote/gateways/remote_wirecard_test.rb +34 -0
  118. data/test/remote/integrations/remote_gestpay_integration_test.rb +1 -1
  119. data/test/remote/integrations/remote_paypal_integration_test.rb +1 -1
  120. data/test/test_helper.rb +81 -89
  121. data/test/unit/avs_result_test.rb +1 -1
  122. data/test/unit/base_test.rb +1 -2
  123. data/test/unit/check_test.rb +1 -1
  124. data/test/unit/connection_test.rb +129 -0
  125. data/test/unit/country_code_test.rb +1 -1
  126. data/test/unit/country_test.rb +1 -1
  127. data/test/unit/credit_card_formatting_test.rb +1 -1
  128. data/test/unit/credit_card_methods_test.rb +10 -1
  129. data/test/unit/credit_card_test.rb +1 -1
  130. data/test/unit/cvv_result_test.rb +1 -1
  131. data/test/unit/expiry_date_test.rb +13 -2
  132. data/test/unit/gateways/authorize_net_cim_test.rb +39 -1
  133. data/test/unit/gateways/authorize_net_test.rb +1 -1
  134. data/test/unit/gateways/beanstream_interac_test.rb +1 -1
  135. data/test/unit/gateways/beanstream_test.rb +1 -1
  136. data/test/unit/gateways/bogus_test.rb +1 -1
  137. data/test/unit/gateways/braintree_test.rb +16 -14
  138. data/test/unit/gateways/card_stream_test.rb +1 -1
  139. data/test/unit/gateways/cyber_source_test.rb +1 -1
  140. data/test/unit/gateways/data_cash_test.rb +2 -1
  141. data/test/unit/gateways/efsnet_test.rb +1 -1
  142. data/test/unit/gateways/elavon_test.rb +139 -0
  143. data/test/unit/gateways/eway_test.rb +1 -1
  144. data/test/unit/gateways/exact_test.rb +1 -1
  145. data/test/unit/gateways/first_pay_test.rb +125 -0
  146. data/test/unit/gateways/gateway_test.rb +1 -1
  147. data/test/unit/gateways/instapay_test.rb +102 -0
  148. data/test/unit/gateways/jetpay_test.rb +185 -0
  149. data/test/unit/gateways/linkpoint_test.rb +37 -7
  150. data/test/unit/gateways/merchant_e_solutions_test.rb +169 -0
  151. data/test/unit/gateways/merchant_ware_test.rb +188 -0
  152. data/test/unit/gateways/modern_payments_cim_test.rb +25 -34
  153. data/test/unit/gateways/moneris_test.rb +1 -1
  154. data/test/unit/gateways/net_registry_test.rb +1 -1
  155. data/test/unit/gateways/netbilling_test.rb +1 -1
  156. data/test/unit/gateways/ogone_test.rb +319 -0
  157. data/test/unit/gateways/pay_junction_test.rb +1 -1
  158. data/test/unit/gateways/pay_secure_test.rb +1 -1
  159. data/test/unit/gateways/payflow_express_test.rb +2 -2
  160. data/test/unit/gateways/payflow_express_uk_test.rb +73 -1
  161. data/test/unit/gateways/payflow_test.rb +1 -1
  162. data/test/unit/gateways/payflow_uk_test.rb +1 -1
  163. data/test/unit/gateways/payment_express_test.rb +3 -3
  164. data/test/unit/gateways/paypal_express_test.rb +1 -1
  165. data/test/unit/gateways/paypal_test.rb +50 -1
  166. data/test/unit/gateways/plugnpay_test.rb +1 -1
  167. data/test/unit/gateways/psigate_test.rb +1 -1
  168. data/test/unit/gateways/psl_card_test.rb +1 -1
  169. data/test/unit/gateways/quickpay_test.rb +1 -1
  170. data/test/unit/gateways/realex_test.rb +1 -1
  171. data/test/unit/gateways/sage_bankcard_test.rb +36 -2
  172. data/test/unit/gateways/{protx_test.rb → sage_pay_test.rb} +49 -32
  173. data/test/unit/gateways/sage_virtual_check_test.rb +1 -1
  174. data/test/unit/gateways/sallie_mae_test.rb +53 -0
  175. data/test/unit/gateways/secure_pay_au_test.rb +1 -1
  176. data/test/unit/gateways/secure_pay_tech_test.rb +1 -1
  177. data/test/unit/gateways/secure_pay_test.rb +24 -10
  178. data/test/unit/gateways/skip_jack_test.rb +81 -1
  179. data/test/unit/gateways/trans_first_test.rb +1 -1
  180. data/test/unit/gateways/trust_commerce_test.rb +1 -1
  181. data/test/unit/gateways/usa_epay_test.rb +1 -1
  182. data/test/unit/gateways/verifi_test.rb +1 -1
  183. data/test/unit/gateways/viaklix_test.rb +1 -1
  184. data/test/unit/gateways/wirecard_test.rb +19 -1
  185. data/test/unit/generators/test_generator_helper.rb +1 -1
  186. data/test/unit/integrations/action_view_helper_test.rb +1 -1
  187. data/test/unit/integrations/bogus_module_test.rb +1 -1
  188. data/test/unit/integrations/chronopay_module_test.rb +1 -1
  189. data/test/unit/integrations/gestpay_module_test.rb +1 -1
  190. data/test/unit/integrations/helpers/bogus_helper_test.rb +1 -1
  191. data/test/unit/integrations/helpers/chronopay_helper_test.rb +1 -1
  192. data/test/unit/integrations/helpers/gestpay_helper_test.rb +1 -1
  193. data/test/unit/integrations/helpers/hi_trust_helper_test.rb +1 -1
  194. data/test/unit/integrations/helpers/nochex_helper_test.rb +1 -1
  195. data/test/unit/integrations/helpers/paypal_helper_test.rb +11 -2
  196. data/test/unit/integrations/helpers/quickpay_helper_test.rb +1 -1
  197. data/test/unit/integrations/helpers/two_checkout_helper_test.rb +1 -1
  198. data/test/unit/integrations/hi_trust_module_test.rb +1 -1
  199. data/test/unit/integrations/nochex_module_test.rb +1 -1
  200. data/test/unit/integrations/notifications/chronopay_notification_test.rb +1 -1
  201. data/test/unit/integrations/notifications/gestpay_notification_test.rb +1 -1
  202. data/test/unit/integrations/notifications/hi_trust_notification_test.rb +1 -1
  203. data/test/unit/integrations/notifications/nochex_notification_test.rb +2 -2
  204. data/test/unit/integrations/notifications/notification_test.rb +1 -1
  205. data/test/unit/integrations/notifications/paypal_notification_test.rb +1 -1
  206. data/test/unit/integrations/notifications/quickpay_notification_test.rb +1 -1
  207. data/test/unit/integrations/notifications/two_checkout_notification_test.rb +1 -1
  208. data/test/unit/integrations/paypal_module_test.rb +1 -1
  209. data/test/unit/integrations/quickpay_module_test.rb +1 -1
  210. data/test/unit/integrations/returns/chronopay_return_test.rb +1 -1
  211. data/test/unit/integrations/returns/gestpay_return_test.rb +1 -1
  212. data/test/unit/integrations/returns/hi_trust_return_test.rb +1 -1
  213. data/test/unit/integrations/returns/nochex_return_test.rb +1 -1
  214. data/test/unit/integrations/returns/paypal_return_test.rb +1 -1
  215. data/test/unit/integrations/returns/return_test.rb +1 -1
  216. data/test/unit/integrations/returns/two_checkout_return_test.rb +1 -1
  217. data/test/unit/integrations/two_checkout_module_test.rb +1 -1
  218. data/test/unit/post_data_test.rb +1 -1
  219. data/test/unit/posts_data_test.rb +14 -66
  220. data/test/unit/response_test.rb +1 -1
  221. data/test/unit/utils_test.rb +1 -1
  222. data/test/unit/validateable_test.rb +1 -1
  223. metadata +41 -45
  224. metadata.gz.sig +0 -0
  225. data/test/extra/binding_of_caller.rb +0 -80
  226. data/test/extra/breakpoint.rb +0 -547
  227. data/test/remote/gateways/remote_protx_test.rb +0 -184
@@ -0,0 +1,164 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ class InstapayGateway < Gateway
4
+ GATEWAY_URL = 'https://trans.instapaygateway.com/cgi-bin/process.cgi'
5
+
6
+ # The countries the gateway supports merchants from as 2 digit ISO country codes
7
+ self.supported_countries = ['US']
8
+ self.money_format = :dollars
9
+ self.default_currency = 'USD'
10
+ # The card types supported by the payment gateway
11
+ self.supported_cardtypes = [:visa, :master, :american_express, :discover]
12
+
13
+ # The homepage URL of the gateway
14
+ self.homepage_url = 'http://www.instapayllc.com'
15
+
16
+ # The name of the gateway
17
+ self.display_name = 'InstaPay'
18
+
19
+ SUCCESS = "Accepted"
20
+ SUCCESS_MESSAGE = "The transaction has been approved"
21
+
22
+ def initialize(options = {})
23
+ requires!(options, :login)
24
+ @options = options
25
+ super
26
+ end
27
+
28
+ def authorize(money, creditcard, options = {})
29
+ post = {}
30
+ post[:authonly] = 1
31
+ add_amount(post, money)
32
+ add_invoice(post, options)
33
+ add_creditcard(post, creditcard)
34
+ add_address(post, options)
35
+ add_customer_data(post, options)
36
+
37
+ commit('ns_quicksale_cc', post)
38
+ end
39
+
40
+ def purchase(money, creditcard, options = {})
41
+ post = {}
42
+ add_amount(post, money)
43
+ add_invoice(post, options)
44
+ add_creditcard(post, creditcard)
45
+ add_address(post, options)
46
+ add_customer_data(post, options)
47
+
48
+ commit('ns_quicksale_cc', post)
49
+ end
50
+
51
+ def capture(money, authorization, options = {})
52
+ post = {}
53
+ add_amount(post, money)
54
+ add_reference(post, authorization)
55
+ commit('ns_quicksale_cc', post)
56
+ end
57
+
58
+ private
59
+
60
+ def add_amount(post, money)
61
+ post[:amount] = amount(money)
62
+ end
63
+
64
+ def add_reference(post, reference)
65
+ post[:postonly] = reference
66
+ end
67
+
68
+ def add_customer_data(post, options)
69
+ post[:ci_email] = options[:email]
70
+ post["ci_IP Address"] = options[:ip]
71
+ end
72
+
73
+ def add_address(post, options)
74
+ if address = options[:billing_address] || options[:address]
75
+ post[:ci_billaddr1] = address[:address1]
76
+ post[:ci_billaddr2] = address[:address2]
77
+ post[:ci_billcity] = address[:city]
78
+ post[:ci_billstate] = address[:state]
79
+ post[:ci_billzip] = address[:zip]
80
+ post[:ci_billcountry] = address[:country]
81
+ post[:ci_phone] = address[:phone]
82
+ end
83
+
84
+ if address = options[:shipping_address]
85
+ post[:ci_shipaddr1] = address[:address1]
86
+ post[:ci_shipaddr2] = address[:address2]
87
+ post[:ci_shipcity] = address[:city]
88
+ post[:ci_shipstate] = address[:state]
89
+ post[:ci_shipzip] = address[:zip]
90
+ post[:ci_shipcountry] = address[:country]
91
+ end
92
+ end
93
+
94
+ def add_invoice(post, options)
95
+ post[:merchantordernumber] = options[:order_id]
96
+ post[:ci_memo] = options[:description]
97
+ post[:pocustomerrefid] = options[:invoice]
98
+ end
99
+
100
+ def add_creditcard(post, creditcard)
101
+ post[:ccnum] = creditcard.number
102
+ post[:expmon] = format(creditcard.month, :two_digits)
103
+ post[:cvv2] = creditcard.verification_value if creditcard.verification_value?
104
+ post[:expyear] = creditcard.year
105
+ post[:ccname] = creditcard.name
106
+ end
107
+
108
+ def parse(body)
109
+ results = {}
110
+ fields = body.split("\r\n")
111
+
112
+ response = fields[1].split('=')
113
+ response_data = response[1].split(':')
114
+
115
+ if response[0] == SUCCESS
116
+ results[:success] = true
117
+ results[:message] = SUCCESS_MESSAGE
118
+ results[:transaction_type] = response_data[0]
119
+ results[:authorization_code] = response_data[1]
120
+ results[:reference_number] = response_data[2]
121
+ results[:batch_number] = response_data[3]
122
+ results[:transaction_id] = response_data[4]
123
+ results[:avs_result] = response_data[5]
124
+ results[:authorize_net] = response_data[6]
125
+ results[:cvv_result] = response_data[7]
126
+ else
127
+ results[:success] = false
128
+ results[:result] = response_data[0]
129
+ results[:response_code] = response_data[1]
130
+ results[:message] = response_data[2]
131
+ end
132
+
133
+ fields[1..-1].each do |pair|
134
+ key, value = pair.split('=')
135
+ results[key] = value
136
+ end
137
+ results
138
+ end
139
+
140
+ def commit(action, parameters)
141
+ data = ssl_post GATEWAY_URL , post_data(action, parameters)
142
+ response = parse(data)
143
+
144
+ Response.new(response[:success] , response[:message], response,
145
+ :authorization => response[:transaction_id],
146
+ :avs_result => { :code => response[:avs_result] },
147
+ :cvv_result => response[:cvv_result]
148
+ )
149
+ end
150
+
151
+ def post_data(action, parameters = {})
152
+ post = {}
153
+ post[:acctid] = @options[:login]
154
+ if(@options[:password])
155
+ post[:merchantpin] = @options[:password]
156
+ end
157
+ post[:action] = action
158
+ request = post.merge(parameters).collect { |key, value| "#{key}=#{CGI.escape(value.to_s)}" }.join("&")
159
+ request
160
+ end
161
+ end
162
+ end
163
+ end
164
+
@@ -0,0 +1,270 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ class JetpayGateway < Gateway
4
+ TEST_URL = 'https://test1.jetpay.com/jetpay'
5
+ LIVE_URL = 'https://gateway17.jetpay.com/jetpay'
6
+
7
+ # The countries the gateway supports merchants from as 2 digit ISO country codes
8
+ self.supported_countries = ['US']
9
+
10
+ # The card types supported by the payment gateway
11
+ self.supported_cardtypes = [:visa, :master, :american_express, :discover]
12
+
13
+ # The homepage URL of the gateway
14
+ self.homepage_url = 'http://www.jetpay.com/'
15
+
16
+ # The name of the gateway
17
+ self.display_name = 'JetPay'
18
+
19
+ # all transactions are in cents
20
+ self.money_format = :cents
21
+
22
+ ACTION_CODE_MESSAGES = {
23
+ "001" => "Refer to card issuer.",
24
+ "002" => "Refer to card issuer, special condition.",
25
+ "003" => "Pick up card.",
26
+ "200" => "Deny - Pick up card.",
27
+ "005" => "Do not honor.",
28
+ "100" => "Deny.",
29
+ "006" => "Error.",
30
+ "181" => "Format error.",
31
+ "007" => "Pickup card, special condition.",
32
+ "104" => "Deny - New card issued.",
33
+ "110" => "Invalid amount.",
34
+ "014" => "Invalid account number (no such number).",
35
+ "111" => "Invalid account.",
36
+ "015" => "No such issuer.",
37
+ "103" => "Deny - Invalid manual Entry 4DBC.",
38
+ "182" => "Please wait.",
39
+ "109" => "Invalid merchant.",
40
+ "041" => "Pick up card (lost card).",
41
+ "043" => "Pick up card (stolen card).",
42
+ "051" => "Insufficient funds.",
43
+ "052" => "No checking account.",
44
+ "105" => "Deny - Account Cancelled.",
45
+ "054" => "Expired Card.",
46
+ "101" => "Expired Card.",
47
+ "183" => "Invalid currency code.",
48
+ "057" => "Transaction not permitted to cardholder.",
49
+ "115" => "Service not permitted.",
50
+ "062" => "Restricted card.",
51
+ "189" => "Deny - Cancelled or Closed Merchant/SE.",
52
+ "188" => "Deny - Expiration date required.",
53
+ "125" => "Invalid effective date.",
54
+ "122" => "Invalid card (CID) security code.",
55
+ "400" => "Reversal accepted.",
56
+ "992" => "DECLINE/TIMEOUT.",
57
+ "107" => "Please Call Issuer.",
58
+ "025" => "Transaction Not Found.",
59
+ "981" => "AVS Error.",
60
+ "913" => "Invalid Card Type.",
61
+ "996" => "Terminal ID Not Found."
62
+ }
63
+
64
+ def initialize(options = {})
65
+ requires!(options, :login)
66
+ @options = options
67
+ super
68
+ end
69
+
70
+ def purchase(money, credit_card, options = {})
71
+ commit(money, build_sale_request(money, credit_card, options))
72
+ end
73
+
74
+ def authorize(money, credit_card, options = {})
75
+ commit(money, build_authonly_request(money, credit_card, options))
76
+ end
77
+
78
+ def capture(money, reference, options = {})
79
+ commit(money, build_capture_request('CAPT', reference.split(";").first))
80
+ end
81
+
82
+ def void(reference, options = {})
83
+ transaction_id, approval, amount = reference.split(";")
84
+ commit(amount.to_i, build_void_request(amount.to_i, transaction_id, approval))
85
+ end
86
+
87
+ def credit(money, transaction_id_or_card, options = {})
88
+
89
+ if transaction_id_or_card.is_a?(String)
90
+ transaction_id = transaction_id_or_card.split(";").first
91
+ credit_card = options[:credit_card]
92
+ else
93
+ transaction_id = nil
94
+ credit_card = transaction_id_or_card
95
+ end
96
+
97
+ commit(money, build_credit_request('CREDIT', money, transaction_id, credit_card))
98
+ end
99
+
100
+ private
101
+
102
+ def build_xml_request(transaction_type, transaction_id = nil, &block)
103
+ xml = Builder::XmlMarkup.new
104
+ xml.tag! 'JetPay' do
105
+ # The basic values needed for any request
106
+ xml.tag! 'TerminalID', @options[:login]
107
+ xml.tag! 'TransactionType', transaction_type
108
+ xml.tag! 'TransactionID', transaction_id.nil? ? generate_unique_id.slice(0, 18) : transaction_id
109
+
110
+ if block_given?
111
+ yield xml
112
+ else
113
+ xml.target!
114
+ end
115
+ end
116
+ end
117
+
118
+ def build_sale_request(money, credit_card, options)
119
+ build_xml_request('SALE') do |xml|
120
+ add_credit_card(xml, credit_card)
121
+ add_addresses(xml, options)
122
+ add_customer_data(xml, options)
123
+ add_invoice_data(xml, options)
124
+ xml.tag! 'TotalAmount', amount(money)
125
+
126
+ xml.target!
127
+ end
128
+ end
129
+
130
+ def build_authonly_request(money, credit_card, options)
131
+ build_xml_request('AUTHONLY') do |xml|
132
+ add_credit_card(xml, credit_card)
133
+ add_addresses(xml, options)
134
+ add_customer_data(xml, options)
135
+ add_invoice_data(xml, options)
136
+ xml.tag! 'TotalAmount', amount(money)
137
+
138
+ xml.target!
139
+ end
140
+ end
141
+
142
+ def build_capture_request(transaction_type, transaction_id)
143
+ build_xml_request(transaction_type, transaction_id)
144
+ end
145
+
146
+ def build_void_request(money, transaction_id, approval)
147
+ build_xml_request('VOID', transaction_id) do |xml|
148
+ xml.tag! 'Approval', approval
149
+ xml.tag! 'TotalAmount', amount(money)
150
+
151
+ xml.target!
152
+ end
153
+ end
154
+
155
+ # `transaction_id` may be nil for unlinked credit transactions.
156
+ def build_credit_request(transaction_type, money, transaction_id, card)
157
+ build_xml_request(transaction_type, transaction_id) do |xml|
158
+ add_credit_card(xml, card) if card
159
+ xml.tag! 'TotalAmount', amount(money)
160
+
161
+ xml.target!
162
+ end
163
+ end
164
+
165
+ def commit(money, request)
166
+ response = parse(ssl_post(test? ? TEST_URL : LIVE_URL, request))
167
+
168
+ success = success?(response)
169
+ Response.new(success,
170
+ success ? 'APPROVED' : message_from(response),
171
+ response,
172
+ :test => test?,
173
+ :authorization => authorization_from(response, money),
174
+ :avs_result => { :code => response[:avs] },
175
+ :cvv_result => response[:cvv2]
176
+ )
177
+ end
178
+
179
+ def parse(body)
180
+ xml = REXML::Document.new(body)
181
+
182
+ response = {}
183
+ xml.root.elements.to_a.each do |node|
184
+ parse_element(response, node)
185
+ end
186
+ response
187
+ end
188
+
189
+ def parse_element(response, node)
190
+ if node.has_elements?
191
+ node.elements.each{|element| parse_element(response, element) }
192
+ else
193
+ response[node.name.underscore.to_sym] = node.text
194
+ end
195
+ end
196
+
197
+ def format_exp(value)
198
+ format(value, :two_digits)
199
+ end
200
+
201
+ def success?(response)
202
+ response[:action_code] == "000"
203
+ end
204
+
205
+ def message_from(response)
206
+ ACTION_CODE_MESSAGES[response[:action_code]]
207
+ end
208
+
209
+ def authorization_from(response, money)
210
+ original_amount = amount(money) if money
211
+ [ response[:transaction_id], response[:approval], original_amount ].join(";")
212
+ end
213
+
214
+ def add_credit_card(xml, credit_card)
215
+ xml.tag! 'CardNum', credit_card.number
216
+ xml.tag! 'CardExpMonth', format_exp(credit_card.month)
217
+ xml.tag! 'CardExpYear', format_exp(credit_card.year)
218
+
219
+ if credit_card.first_name || credit_card.last_name
220
+ xml.tag! 'CardName', [credit_card.first_name,credit_card.last_name].compact.join(' ')
221
+ end
222
+
223
+ unless credit_card.verification_value.nil? || (credit_card.verification_value.length == 0)
224
+ xml.tag! 'CVV2', credit_card.verification_value
225
+ end
226
+ end
227
+
228
+ def add_addresses(xml, options)
229
+ if billing_address = options[:billing_address] || options[:address]
230
+ xml.tag! 'BillingAddress', [billing_address[:address1], billing_address[:address2]].compact.join(" ")
231
+ xml.tag! 'BillingCity', billing_address[:city]
232
+ xml.tag! 'BillingStateProv', billing_address[:state]
233
+ xml.tag! 'BillingPostalCode', billing_address[:zip]
234
+ xml.tag! 'BillingCountry', lookup_country_code(billing_address[:country])
235
+ xml.tag! 'BillingPhone', billing_address[:phone]
236
+ end
237
+
238
+ if shipping_address = options[:shipping_address]
239
+ xml.tag! 'ShippingInfo' do
240
+ xml.tag! 'ShippingName', shipping_address[:name]
241
+
242
+ xml.tag! 'ShippingAddr' do
243
+ xml.tag! 'Address', [shipping_address[:address1], shipping_address[:address2]].compact.join(" ")
244
+ xml.tag! 'City', shipping_address[:city]
245
+ xml.tag! 'StateProv', shipping_address[:state]
246
+ xml.tag! 'PostalCode', shipping_address[:zip]
247
+ xml.tag! 'Country', lookup_country_code(shipping_address[:country])
248
+ end
249
+ end
250
+ end
251
+ end
252
+
253
+ def add_customer_data(xml, options)
254
+ xml.tag! 'Email', options[:email] if options[:email]
255
+ xml.tag! 'UserIPAddress', options[:ip] if options[:ip]
256
+ end
257
+
258
+ def add_invoice_data(xml, options)
259
+ xml.tag! 'OrderNumber', options[:order_id] if options[:order_id]
260
+ xml.tag! 'TaxAmount', amount(options[:tax]) if options[:tax]
261
+ end
262
+
263
+ def lookup_country_code(code)
264
+ country = Country.find(code) rescue nil
265
+ country && country.code(:alpha3)
266
+ end
267
+ end
268
+ end
269
+ end
270
+
@@ -82,12 +82,41 @@ module ActiveMerchant #:nodoc:
82
82
  # :transactiondetails => [:transactionorigin, :oid, :ponumber, :taxexempt, :terminaltype, :ip, :reference_number, :recurring, :tdate],
83
83
  # :periodic => [:action, :installments, :threshold, :startdate, :periodicity, :comments],
84
84
  # :notes => [:comments, :referred]
85
+ # :items => [:item => [:price, :quantity, :description, :id, :options => [:option => [:name, :value]]]]
85
86
  # }
86
87
  #
87
- #
88
- # IMPORTANT NOTICE:
89
88
  #
90
- # LinkPoint's Items entity is not yet supported in this module.
89
+ # LinkPoint's Items entity is an optional entity that can be attached to orders.
90
+ # It is entered as :line_items to be consistent with the CyberSource implementation
91
+ #
92
+ # The line_item hash goes in the options hash and should look like
93
+ #
94
+ # :line_items => [
95
+ # {
96
+ # :id => '123456',
97
+ # :description => 'Logo T-Shirt',
98
+ # :price => '12.00',
99
+ # :quantity => '1',
100
+ # :options => [
101
+ # {
102
+ # :name => 'Color',
103
+ # :value => 'Red'
104
+ # },
105
+ # {
106
+ # :name => 'Size',
107
+ # :value => 'XL'
108
+ # }
109
+ # ]
110
+ # },
111
+ # {
112
+ # :id => '111',
113
+ # :description => 'keychain',
114
+ # :price => '3.00',
115
+ # :quantity => '1'
116
+ # }
117
+ # ]
118
+ # This functionality is only supported by this particular gateway may
119
+ # be changed at any time
91
120
  #
92
121
  class LinkpointGateway < Gateway
93
122
  # Your global PEM file. This will be assigned to you by linkpoint
@@ -247,16 +276,38 @@ module ActiveMerchant #:nodoc:
247
276
  # Loop over the params hash to construct the XML string
248
277
  for key, value in params
249
278
  elem = order.add_element(key.to_s)
250
- for k, v in params[key]
251
- elem.add_element(k.to_s).text = params[key][k].to_s if params[key][k]
279
+ if key == :items
280
+ build_items(elem, value)
281
+ else
282
+ for k, v in params[key]
283
+ elem.add_element(k.to_s).text = params[key][k].to_s if params[key][k]
284
+ end
252
285
  end
253
286
  # Linkpoint doesn't understand empty elements:
254
287
  order.delete(elem) if elem.size == 0
255
288
  end
256
-
257
289
  return xml.to_s
258
290
  end
259
-
291
+
292
+ # adds LinkPoint's Items entity to the XML. Called from post_data
293
+ def build_items(element, items)
294
+ for item in items
295
+ item_element = element.add_element("item")
296
+ for key, value in item
297
+ if key == :options
298
+ options_element = item_element.add_element("options")
299
+ for option in value
300
+ opt_element = options_element.add_element("option")
301
+ opt_element.add_element("name").text = option[:name] unless option[:name].blank?
302
+ opt_element.add_element("value").text = option[:value] unless option[:value].blank?
303
+ end
304
+ else
305
+ item_element.add_element(key.to_s).text = item[key].to_s unless item[key].blank?
306
+ end
307
+ end
308
+ end
309
+ end
310
+
260
311
  # Set up the parameters hash just once so we don't have to do it
261
312
  # for every action.
262
313
  def parameters(money, creditcard, options = {})
@@ -307,10 +358,10 @@ module ActiveMerchant #:nodoc:
307
358
 
308
359
  if creditcard
309
360
  params[:creditcard] = {
310
- :cardnumber => creditcard.number,
311
- :cardexpmonth => creditcard.month,
312
- :cardexpyear => format_creditcard_expiry_year(creditcard.year),
313
- :track => nil
361
+ :cardnumber => creditcard.number,
362
+ :cardexpmonth => creditcard.month,
363
+ :cardexpyear => format_creditcard_expiry_year(creditcard.year),
364
+ :track => nil
314
365
  }
315
366
 
316
367
  if creditcard.verification_value?
@@ -324,7 +375,7 @@ module ActiveMerchant #:nodoc:
324
375
  if billing_address = options[:billing_address] || options[:address]
325
376
 
326
377
  params[:billing] = {}
327
- params[:billing][:name] = billing_address[:name] || creditcard ? creditcard.name : nil
378
+ params[:billing][:name] = billing_address[:name] || (creditcard ? creditcard.name : nil)
328
379
  params[:billing][:address1] = billing_address[:address1] unless billing_address[:address1].blank?
329
380
  params[:billing][:address2] = billing_address[:address2] unless billing_address[:address2].blank?
330
381
  params[:billing][:city] = billing_address[:city] unless billing_address[:city].blank?
@@ -348,6 +399,8 @@ module ActiveMerchant #:nodoc:
348
399
  params[:shipping][:country] = shipping_address[:country] unless shipping_address[:country].blank?
349
400
  end
350
401
 
402
+ params[:items] = options[:line_items] if options[:line_items]
403
+
351
404
  return params
352
405
  end
353
406