jelaniharris-activemerchant 1.24.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (219) hide show
  1. data/CHANGELOG +893 -0
  2. data/CONTRIBUTORS +307 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.md +196 -0
  5. data/gem-public_cert.pem +20 -0
  6. data/lib/active_merchant.rb +63 -0
  7. data/lib/active_merchant/billing.rb +9 -0
  8. data/lib/active_merchant/billing/avs_result.rb +98 -0
  9. data/lib/active_merchant/billing/base.rb +57 -0
  10. data/lib/active_merchant/billing/check.rb +68 -0
  11. data/lib/active_merchant/billing/credit_card.rb +274 -0
  12. data/lib/active_merchant/billing/credit_card_formatting.rb +21 -0
  13. data/lib/active_merchant/billing/credit_card_methods.rb +143 -0
  14. data/lib/active_merchant/billing/cvv_result.rb +38 -0
  15. data/lib/active_merchant/billing/expiry_date.rb +34 -0
  16. data/lib/active_merchant/billing/gateway.rb +170 -0
  17. data/lib/active_merchant/billing/gateways.rb +18 -0
  18. data/lib/active_merchant/billing/gateways/authorize_net.rb +694 -0
  19. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +946 -0
  20. data/lib/active_merchant/billing/gateways/barclays_epdq.rb +308 -0
  21. data/lib/active_merchant/billing/gateways/beanstream.rb +167 -0
  22. data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +388 -0
  23. data/lib/active_merchant/billing/gateways/beanstream_interac.rb +54 -0
  24. data/lib/active_merchant/billing/gateways/blue_pay.rb +492 -0
  25. data/lib/active_merchant/billing/gateways/bogus.rb +142 -0
  26. data/lib/active_merchant/billing/gateways/braintree.rb +17 -0
  27. data/lib/active_merchant/billing/gateways/braintree/braintree_common.rb +9 -0
  28. data/lib/active_merchant/billing/gateways/braintree_blue.rb +335 -0
  29. data/lib/active_merchant/billing/gateways/braintree_orange.rb +21 -0
  30. data/lib/active_merchant/billing/gateways/card_save.rb +23 -0
  31. data/lib/active_merchant/billing/gateways/card_stream.rb +230 -0
  32. data/lib/active_merchant/billing/gateways/certo_direct.rb +279 -0
  33. data/lib/active_merchant/billing/gateways/cyber_source.rb +430 -0
  34. data/lib/active_merchant/billing/gateways/data_cash.rb +597 -0
  35. data/lib/active_merchant/billing/gateways/efsnet.rb +235 -0
  36. data/lib/active_merchant/billing/gateways/elavon.rb +137 -0
  37. data/lib/active_merchant/billing/gateways/epay.rb +276 -0
  38. data/lib/active_merchant/billing/gateways/eway.rb +277 -0
  39. data/lib/active_merchant/billing/gateways/eway_managed.rb +265 -0
  40. data/lib/active_merchant/billing/gateways/exact.rb +227 -0
  41. data/lib/active_merchant/billing/gateways/federated_canada.rb +168 -0
  42. data/lib/active_merchant/billing/gateways/first_pay.rb +177 -0
  43. data/lib/active_merchant/billing/gateways/garanti.rb +262 -0
  44. data/lib/active_merchant/billing/gateways/ideal/ideal_base.rb +250 -0
  45. data/lib/active_merchant/billing/gateways/ideal/ideal_rabobank.pem +13 -0
  46. data/lib/active_merchant/billing/gateways/ideal/ideal_response.rb +29 -0
  47. data/lib/active_merchant/billing/gateways/ideal_rabobank.rb +55 -0
  48. data/lib/active_merchant/billing/gateways/inspire.rb +221 -0
  49. data/lib/active_merchant/billing/gateways/instapay.rb +164 -0
  50. data/lib/active_merchant/billing/gateways/iridium.rb +258 -0
  51. data/lib/active_merchant/billing/gateways/itransact.rb +450 -0
  52. data/lib/active_merchant/billing/gateways/jetpay.rb +276 -0
  53. data/lib/active_merchant/billing/gateways/linkpoint.rb +454 -0
  54. data/lib/active_merchant/billing/gateways/litle.rb +275 -0
  55. data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +157 -0
  56. data/lib/active_merchant/billing/gateways/merchant_ware.rb +289 -0
  57. data/lib/active_merchant/billing/gateways/migs.rb +259 -0
  58. data/lib/active_merchant/billing/gateways/migs/migs_codes.rb +100 -0
  59. data/lib/active_merchant/billing/gateways/modern_payments.rb +36 -0
  60. data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +220 -0
  61. data/lib/active_merchant/billing/gateways/moneris.rb +250 -0
  62. data/lib/active_merchant/billing/gateways/moneris_us.rb +211 -0
  63. data/lib/active_merchant/billing/gateways/nab_transact.rb +255 -0
  64. data/lib/active_merchant/billing/gateways/net_registry.rb +189 -0
  65. data/lib/active_merchant/billing/gateways/netaxept.rb +239 -0
  66. data/lib/active_merchant/billing/gateways/netbilling.rb +168 -0
  67. data/lib/active_merchant/billing/gateways/nmi.rb +13 -0
  68. data/lib/active_merchant/billing/gateways/ogone.rb +422 -0
  69. data/lib/active_merchant/billing/gateways/optimal_payment.rb +277 -0
  70. data/lib/active_merchant/billing/gateways/orbital.rb +353 -0
  71. data/lib/active_merchant/billing/gateways/orbital/orbital_soft_descriptors.rb +46 -0
  72. data/lib/active_merchant/billing/gateways/pay_junction.rb +397 -0
  73. data/lib/active_merchant/billing/gateways/pay_secure.rb +120 -0
  74. data/lib/active_merchant/billing/gateways/paybox_direct.rb +199 -0
  75. data/lib/active_merchant/billing/gateways/payflow.rb +266 -0
  76. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +211 -0
  77. data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +39 -0
  78. data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +13 -0
  79. data/lib/active_merchant/billing/gateways/payflow_express.rb +224 -0
  80. data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +15 -0
  81. data/lib/active_merchant/billing/gateways/payflow_uk.rb +21 -0
  82. data/lib/active_merchant/billing/gateways/payment_express.rb +282 -0
  83. data/lib/active_merchant/billing/gateways/paypal.rb +106 -0
  84. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +640 -0
  85. data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +49 -0
  86. data/lib/active_merchant/billing/gateways/paypal/paypal_recurring_api.rb +245 -0
  87. data/lib/active_merchant/billing/gateways/paypal_ca.rb +13 -0
  88. data/lib/active_merchant/billing/gateways/paypal_digital_goods.rb +43 -0
  89. data/lib/active_merchant/billing/gateways/paypal_express.rb +178 -0
  90. data/lib/active_merchant/billing/gateways/paypal_express_common.rb +30 -0
  91. data/lib/active_merchant/billing/gateways/paystation.rb +201 -0
  92. data/lib/active_merchant/billing/gateways/plugnpay.rb +298 -0
  93. data/lib/active_merchant/billing/gateways/psigate.rb +219 -0
  94. data/lib/active_merchant/billing/gateways/psl_card.rb +304 -0
  95. data/lib/active_merchant/billing/gateways/qbms.rb +297 -0
  96. data/lib/active_merchant/billing/gateways/quantum.rb +282 -0
  97. data/lib/active_merchant/billing/gateways/quickpay.rb +298 -0
  98. data/lib/active_merchant/billing/gateways/realex.rb +313 -0
  99. data/lib/active_merchant/billing/gateways/sage.rb +146 -0
  100. data/lib/active_merchant/billing/gateways/sage/sage_bankcard.rb +88 -0
  101. data/lib/active_merchant/billing/gateways/sage/sage_core.rb +116 -0
  102. data/lib/active_merchant/billing/gateways/sage/sage_virtual_check.rb +97 -0
  103. data/lib/active_merchant/billing/gateways/sage_pay.rb +320 -0
  104. data/lib/active_merchant/billing/gateways/sallie_mae.rb +144 -0
  105. data/lib/active_merchant/billing/gateways/samurai.rb +121 -0
  106. data/lib/active_merchant/billing/gateways/secure_net.rb +330 -0
  107. data/lib/active_merchant/billing/gateways/secure_pay.rb +31 -0
  108. data/lib/active_merchant/billing/gateways/secure_pay_au.rb +281 -0
  109. data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +113 -0
  110. data/lib/active_merchant/billing/gateways/skip_jack.rb +458 -0
  111. data/lib/active_merchant/billing/gateways/smart_ps.rb +271 -0
  112. data/lib/active_merchant/billing/gateways/stripe.rb +236 -0
  113. data/lib/active_merchant/billing/gateways/trans_first.rb +127 -0
  114. data/lib/active_merchant/billing/gateways/transax.rb +25 -0
  115. data/lib/active_merchant/billing/gateways/trust_commerce.rb +437 -0
  116. data/lib/active_merchant/billing/gateways/usa_epay.rb +23 -0
  117. data/lib/active_merchant/billing/gateways/usa_epay_advanced.rb +1496 -0
  118. data/lib/active_merchant/billing/gateways/usa_epay_transaction.rb +202 -0
  119. data/lib/active_merchant/billing/gateways/verifi.rb +233 -0
  120. data/lib/active_merchant/billing/gateways/viaklix.rb +194 -0
  121. data/lib/active_merchant/billing/gateways/vindicia.rb +359 -0
  122. data/lib/active_merchant/billing/gateways/wirecard.rb +318 -0
  123. data/lib/active_merchant/billing/gateways/worldpay.rb +280 -0
  124. data/lib/active_merchant/billing/integrations.rb +17 -0
  125. data/lib/active_merchant/billing/integrations/action_view_helper.rb +72 -0
  126. data/lib/active_merchant/billing/integrations/authorize_net_sim.rb +38 -0
  127. data/lib/active_merchant/billing/integrations/authorize_net_sim/helper.rb +228 -0
  128. data/lib/active_merchant/billing/integrations/authorize_net_sim/notification.rb +340 -0
  129. data/lib/active_merchant/billing/integrations/bogus.rb +23 -0
  130. data/lib/active_merchant/billing/integrations/bogus/helper.rb +17 -0
  131. data/lib/active_merchant/billing/integrations/bogus/notification.rb +11 -0
  132. data/lib/active_merchant/billing/integrations/bogus/return.rb +10 -0
  133. data/lib/active_merchant/billing/integrations/chronopay.rb +23 -0
  134. data/lib/active_merchant/billing/integrations/chronopay/helper.rb +120 -0
  135. data/lib/active_merchant/billing/integrations/chronopay/notification.rb +158 -0
  136. data/lib/active_merchant/billing/integrations/chronopay/return.rb +10 -0
  137. data/lib/active_merchant/billing/integrations/direc_pay.rb +41 -0
  138. data/lib/active_merchant/billing/integrations/direc_pay/helper.rb +200 -0
  139. data/lib/active_merchant/billing/integrations/direc_pay/notification.rb +76 -0
  140. data/lib/active_merchant/billing/integrations/direc_pay/return.rb +32 -0
  141. data/lib/active_merchant/billing/integrations/direc_pay/status.rb +37 -0
  142. data/lib/active_merchant/billing/integrations/directebanking.rb +47 -0
  143. data/lib/active_merchant/billing/integrations/directebanking/helper.rb +90 -0
  144. data/lib/active_merchant/billing/integrations/directebanking/notification.rb +120 -0
  145. data/lib/active_merchant/billing/integrations/directebanking/return.rb +11 -0
  146. data/lib/active_merchant/billing/integrations/dotpay.rb +22 -0
  147. data/lib/active_merchant/billing/integrations/dotpay/helper.rb +77 -0
  148. data/lib/active_merchant/billing/integrations/dotpay/notification.rb +86 -0
  149. data/lib/active_merchant/billing/integrations/dotpay/return.rb +11 -0
  150. data/lib/active_merchant/billing/integrations/dwolla.rb +30 -0
  151. data/lib/active_merchant/billing/integrations/dwolla/helper.rb +31 -0
  152. data/lib/active_merchant/billing/integrations/dwolla/notification.rb +55 -0
  153. data/lib/active_merchant/billing/integrations/dwolla/return.rb +38 -0
  154. data/lib/active_merchant/billing/integrations/e_payment_plans.rb +48 -0
  155. data/lib/active_merchant/billing/integrations/e_payment_plans/helper.rb +34 -0
  156. data/lib/active_merchant/billing/integrations/e_payment_plans/notification.rb +84 -0
  157. data/lib/active_merchant/billing/integrations/epay.rb +21 -0
  158. data/lib/active_merchant/billing/integrations/epay/helper.rb +55 -0
  159. data/lib/active_merchant/billing/integrations/epay/notification.rb +110 -0
  160. data/lib/active_merchant/billing/integrations/gestpay.rb +25 -0
  161. data/lib/active_merchant/billing/integrations/gestpay/common.rb +42 -0
  162. data/lib/active_merchant/billing/integrations/gestpay/helper.rb +70 -0
  163. data/lib/active_merchant/billing/integrations/gestpay/notification.rb +85 -0
  164. data/lib/active_merchant/billing/integrations/gestpay/return.rb +10 -0
  165. data/lib/active_merchant/billing/integrations/helper.rb +113 -0
  166. data/lib/active_merchant/billing/integrations/hi_trust.rb +27 -0
  167. data/lib/active_merchant/billing/integrations/hi_trust/helper.rb +58 -0
  168. data/lib/active_merchant/billing/integrations/hi_trust/notification.rb +59 -0
  169. data/lib/active_merchant/billing/integrations/hi_trust/return.rb +67 -0
  170. data/lib/active_merchant/billing/integrations/moneybookers.rb +26 -0
  171. data/lib/active_merchant/billing/integrations/moneybookers/helper.rb +59 -0
  172. data/lib/active_merchant/billing/integrations/moneybookers/notification.rb +129 -0
  173. data/lib/active_merchant/billing/integrations/nochex.rb +88 -0
  174. data/lib/active_merchant/billing/integrations/nochex/helper.rb +68 -0
  175. data/lib/active_merchant/billing/integrations/nochex/notification.rb +94 -0
  176. data/lib/active_merchant/billing/integrations/nochex/return.rb +10 -0
  177. data/lib/active_merchant/billing/integrations/notification.rb +62 -0
  178. data/lib/active_merchant/billing/integrations/payflow_link.rb +21 -0
  179. data/lib/active_merchant/billing/integrations/payflow_link/helper.rb +100 -0
  180. data/lib/active_merchant/billing/integrations/payflow_link/notification.rb +78 -0
  181. data/lib/active_merchant/billing/integrations/paypal.rb +39 -0
  182. data/lib/active_merchant/billing/integrations/paypal/helper.rb +119 -0
  183. data/lib/active_merchant/billing/integrations/paypal/notification.rb +155 -0
  184. data/lib/active_merchant/billing/integrations/paypal/return.rb +10 -0
  185. data/lib/active_merchant/billing/integrations/quickpay.rb +21 -0
  186. data/lib/active_merchant/billing/integrations/quickpay/helper.rb +71 -0
  187. data/lib/active_merchant/billing/integrations/quickpay/notification.rb +74 -0
  188. data/lib/active_merchant/billing/integrations/return.rb +42 -0
  189. data/lib/active_merchant/billing/integrations/robokassa.rb +49 -0
  190. data/lib/active_merchant/billing/integrations/robokassa/common.rb +19 -0
  191. data/lib/active_merchant/billing/integrations/robokassa/helper.rb +50 -0
  192. data/lib/active_merchant/billing/integrations/robokassa/notification.rb +55 -0
  193. data/lib/active_merchant/billing/integrations/robokassa/return.rb +17 -0
  194. data/lib/active_merchant/billing/integrations/sage_pay_form.rb +37 -0
  195. data/lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb +33 -0
  196. data/lib/active_merchant/billing/integrations/sage_pay_form/helper.rb +129 -0
  197. data/lib/active_merchant/billing/integrations/sage_pay_form/notification.rb +210 -0
  198. data/lib/active_merchant/billing/integrations/sage_pay_form/return.rb +31 -0
  199. data/lib/active_merchant/billing/integrations/two_checkout.rb +44 -0
  200. data/lib/active_merchant/billing/integrations/two_checkout/helper.rb +91 -0
  201. data/lib/active_merchant/billing/integrations/two_checkout/notification.rb +139 -0
  202. data/lib/active_merchant/billing/integrations/two_checkout/return.rb +17 -0
  203. data/lib/active_merchant/billing/integrations/valitor.rb +33 -0
  204. data/lib/active_merchant/billing/integrations/valitor/helper.rb +86 -0
  205. data/lib/active_merchant/billing/integrations/valitor/notification.rb +13 -0
  206. data/lib/active_merchant/billing/integrations/valitor/response_fields.rb +97 -0
  207. data/lib/active_merchant/billing/integrations/valitor/return.rb +13 -0
  208. data/lib/active_merchant/billing/integrations/verkkomaksut.rb +20 -0
  209. data/lib/active_merchant/billing/integrations/verkkomaksut/helper.rb +87 -0
  210. data/lib/active_merchant/billing/integrations/verkkomaksut/notification.rb +59 -0
  211. data/lib/active_merchant/billing/integrations/world_pay.rb +27 -0
  212. data/lib/active_merchant/billing/integrations/world_pay/helper.rb +100 -0
  213. data/lib/active_merchant/billing/integrations/world_pay/notification.rb +160 -0
  214. data/lib/active_merchant/billing/response.rb +32 -0
  215. data/lib/active_merchant/version.rb +3 -0
  216. data/lib/activemerchant.rb +1 -0
  217. data/lib/support/gateway_support.rb +58 -0
  218. data/lib/support/outbound_hosts.rb +25 -0
  219. metadata +447 -0
@@ -0,0 +1,168 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ class NetbillingGateway < Gateway
4
+ URL = 'https://secure.netbilling.com:1402/gw/sas/direct3.1'
5
+
6
+ TRANSACTIONS = {
7
+ :authorization => 'A',
8
+ :purchase => 'S',
9
+ :referenced_credit => 'R',
10
+ :unreferenced_credit => 'C',
11
+ :capture => 'D'
12
+ }
13
+
14
+ SUCCESS_CODES = [ '1', 'T' ]
15
+ SUCCESS_MESSAGE = 'The transaction was approved'
16
+ FAILURE_MESSAGE = 'The transaction failed'
17
+ TEST_LOGIN = '104901072025'
18
+
19
+ self.display_name = 'NETbilling'
20
+ self.homepage_url = 'http://www.netbilling.com'
21
+ self.supported_countries = ['US']
22
+ self.supported_cardtypes = [:visa, :master, :american_express, :discover, :jcb, :diners_club]
23
+
24
+ def initialize(options = {})
25
+ requires!(options, :login)
26
+ @options = options
27
+ super
28
+ end
29
+
30
+ def authorize(money, credit_card, options = {})
31
+ post = {}
32
+ add_amount(post, money)
33
+ add_invoice(post, options)
34
+ add_credit_card(post, credit_card)
35
+ add_address(post, credit_card, options)
36
+ add_customer_data(post, options)
37
+
38
+ commit(:authorization, money, post)
39
+ end
40
+
41
+ def purchase(money, credit_card, options = {})
42
+ post = {}
43
+ add_amount(post, money)
44
+ add_invoice(post, options)
45
+ add_credit_card(post, credit_card)
46
+ add_address(post, credit_card, options)
47
+ add_customer_data(post, options)
48
+
49
+ commit(:purchase, money, post)
50
+ end
51
+
52
+ def capture(money, authorization, options = {})
53
+ post = {}
54
+ add_reference(post, authorization)
55
+ commit(:capture, money, post)
56
+ end
57
+
58
+ def test?
59
+ @options[:login] == TEST_LOGIN || super
60
+ end
61
+
62
+ private
63
+ def add_amount(post, money)
64
+ post[:amount] = amount(money)
65
+ end
66
+
67
+ def add_reference(post, reference)
68
+ post[:orig_id] = reference
69
+ end
70
+
71
+ def add_customer_data(post, options)
72
+ post[:cust_email] = options[:email]
73
+ post[:cust_ip] = options[:ip]
74
+ end
75
+
76
+ def add_address(post, credit_card, options)
77
+ if billing_address = options[:billing_address] || options[:address]
78
+ post[:bill_street] = billing_address[:address1]
79
+ post[:cust_phone] = billing_address[:phone]
80
+ post[:bill_zip] = billing_address[:zip]
81
+ post[:bill_city] = billing_address[:city]
82
+ post[:bill_country] = billing_address[:country]
83
+ post[:bill_state] = billing_address[:state]
84
+ end
85
+
86
+ if shipping_address = options[:shipping_address]
87
+ first_name, last_name = parse_first_and_last_name(shipping_address[:name])
88
+
89
+ post[:ship_name1] = first_name
90
+ post[:ship_name2] = last_name
91
+ post[:ship_street] = shipping_address[:address1]
92
+ post[:ship_zip] = shipping_address[:zip]
93
+ post[:ship_city] = shipping_address[:city]
94
+ post[:ship_country] = shipping_address[:country]
95
+ post[:ship_state] = shipping_address[:state]
96
+ end
97
+ end
98
+
99
+ def add_invoice(post, options)
100
+ post[:description] = options[:description]
101
+ end
102
+
103
+ def add_credit_card(post, credit_card)
104
+ post[:bill_name1] = credit_card.first_name
105
+ post[:bill_name2] = credit_card.last_name
106
+ post[:card_number] = credit_card.number
107
+ post[:card_expire] = expdate(credit_card)
108
+ post[:card_cvv2] = credit_card.verification_value
109
+ end
110
+
111
+ def parse(body)
112
+ results = {}
113
+ body.split(/&/).each do |pair|
114
+ key,val = pair.split(/=/)
115
+ results[key.to_sym] = CGI.unescape(val)
116
+ end
117
+ results
118
+ end
119
+
120
+ def commit(action, money, parameters)
121
+ response = parse(ssl_post(URL, post_data(action, parameters)))
122
+
123
+ Response.new(success?(response), message_from(response), response,
124
+ :test => test_response?(response),
125
+ :authorization => response[:trans_id],
126
+ :avs_result => { :code => response[:avs_code]},
127
+ :cvv_result => response[:cvv2_code]
128
+ )
129
+ end
130
+
131
+ def test_response?(response)
132
+ !!(test? || response[:auth_msg] =~ /TEST/)
133
+ end
134
+
135
+ def success?(response)
136
+ SUCCESS_CODES.include?(response[:status_code])
137
+ end
138
+
139
+ def message_from(response)
140
+ success?(response) ? SUCCESS_MESSAGE : (response[:auth_msg] || FAILURE_MESSAGE)
141
+ end
142
+
143
+ def expdate(credit_card)
144
+ year = sprintf("%.4i", credit_card.year)
145
+ month = sprintf("%.2i", credit_card.month)
146
+
147
+ "#{month}#{year[-2..-1]}"
148
+ end
149
+
150
+ def post_data(action, parameters = {})
151
+ parameters[:account_id] = @options[:login]
152
+ parameters[:pay_type] = 'C'
153
+ parameters[:tran_type] = TRANSACTIONS[action]
154
+
155
+ parameters.reject{|k,v| v.blank?}.collect { |key, value| "#{key}=#{CGI.escape(value.to_s)}" }.join("&")
156
+ end
157
+
158
+ def parse_first_and_last_name(value)
159
+ name = value.to_s.split(' ')
160
+
161
+ last_name = name.pop || ''
162
+ first_name = name.join(' ')
163
+ [ first_name, last_name ]
164
+ end
165
+ end
166
+ end
167
+ end
168
+
@@ -0,0 +1,13 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ class NmiGateway < AuthorizeNetGateway
4
+ self.test_url = 'https://secure.networkmerchants.com/gateway/transact.dll'
5
+ self.live_url = 'https://secure.networkmerchants.com/gateway/transact.dll'
6
+ self.homepage_url = 'http://nmi.com/'
7
+ self.display_name = 'NMI'
8
+ self.supported_countries = ['US']
9
+ self.supported_cardtypes = [:visa, :master, :american_express, :discover]
10
+ end
11
+ end
12
+ end
13
+
@@ -0,0 +1,422 @@
1
+ # coding: utf-8
2
+ require 'rexml/document'
3
+
4
+ module ActiveMerchant #:nodoc:
5
+ module Billing #:nodoc:
6
+ # = Ogone DirectLink Gateway
7
+ #
8
+ # DirectLink is the API version of the Ogone Payment Platform. It allows server to server
9
+ # communication between Ogone systems and your e-commerce website.
10
+ #
11
+ # This implementation follows the specification provided in the DirectLink integration
12
+ # guide version 4.3.0 (25 April 2012), available here:
13
+ # https://secure.ogone.com/ncol/Ogone_DirectLink_EN.pdf
14
+ #
15
+ # It also features aliases, which allow to store/unstore credit cards, as specified in
16
+ # the Alias Manager Option guide version 3.2.1 (25 April 2012) available here:
17
+ # https://secure.ogone.com/ncol/Ogone_Alias_EN.pdf
18
+ #
19
+ # It also implements the 3-D Secure feature, as specified in the DirectLink with
20
+ # 3-D Secure guide version 3.0 (25 April 2012) available here:
21
+ # https://secure.ogone.com/ncol/Ogone_DirectLink-3-D_EN.pdf
22
+ #
23
+ # It was last tested on Release 4.92 of Ogone DirectLink + AliasManager + Direct Link 3D
24
+ # (25 April 2012).
25
+ #
26
+ # For any questions or comments, please contact one of the following:
27
+ # - Joel Cogen (joel.cogen@belighted.com)
28
+ # - Nicolas Jacobeus (nicolas.jacobeus@belighted.com),
29
+ # - Sébastien Grosjean (public@zencocoon.com),
30
+ # - Rémy Coutable (remy@jilion.com).
31
+ #
32
+ # == Usage
33
+ #
34
+ # gateway = ActiveMerchant::Billing::OgoneGateway.new(
35
+ # :login => "my_ogone_psp_id",
36
+ # :user => "my_ogone_user_id",
37
+ # :password => "my_ogone_pswd",
38
+ # :signature => "my_ogone_sha_signature", # Only if you configured your Ogone environment so.
39
+ # :signature_encryptor => "sha512", # Can be "sha1" (default), "sha256" or "sha512".
40
+ # # Must be the same as the one configured in your Ogone account.
41
+ # )
42
+ #
43
+ # # set up credit card object as in main ActiveMerchant example
44
+ # creditcard = ActiveMerchant::Billing::CreditCard.new(
45
+ # :type => 'visa',
46
+ # :number => '4242424242424242',
47
+ # :month => 8,
48
+ # :year => 2009,
49
+ # :first_name => 'Bob',
50
+ # :last_name => 'Bobsen'
51
+ # )
52
+ #
53
+ # # run request
54
+ # response = gateway.purchase(1000, creditcard, :order_id => "1") # charge 10 EUR
55
+ #
56
+ # If you don't provide an :order_id, the gateway will generate a random one for you.
57
+ #
58
+ # puts response.success? # Check whether the transaction was successful
59
+ # puts response.message # Retrieve the message returned by Ogone
60
+ # puts response.authorization # Retrieve the unique transaction ID returned by Ogone
61
+ # puts response.order_id # Retrieve the order ID
62
+ #
63
+ # == Alias feature
64
+ #
65
+ # To use the alias feature, simply add :billing_id in the options hash:
66
+ #
67
+ # # Associate the alias to that credit card
68
+ # gateway.purchase(1000, creditcard, :order_id => "1", :billing_id => "myawesomecustomer")
69
+ #
70
+ # # You can use the alias instead of the credit card for subsequent orders
71
+ # gateway.purchase(2000, "myawesomecustomer", :order_id => "2")
72
+ #
73
+ # # You can also create an alias without making a purchase using store
74
+ # gateway.store(creditcard, :billing_id => "myawesomecustomer")
75
+ #
76
+ # # When using store, you can also let Ogone generate the alias for you
77
+ # response = gateway.store(creditcard)
78
+ # puts response.billing_id # Retrieve the generated alias
79
+ #
80
+ # == 3-D Secure feature
81
+ #
82
+ # To use the 3-D Secure feature, simply add :d3d => true in the options hash:
83
+ # gateway.purchase(2000, "myawesomecustomer", :order_id => "2", :d3d => true)
84
+ #
85
+ # Specific 3-D Secure request options are (please refer to the documentation for more infos about these options):
86
+ # :win_3ds => :main_window (default), :pop_up or :pop_ix.
87
+ # :http_accept => "*/*" (default), or any other HTTP_ACCEPT header value.
88
+ # :http_user_agent => The cardholder's User-Agent string
89
+ # :accept_url => URL of the web page to show the customer when the payment is authorized.
90
+ # (or waiting to be authorized).
91
+ # :decline_url => URL of the web page to show the customer when the acquirer rejects the authorization
92
+ # more than the maximum permitted number of authorization attempts (10 by default, but can
93
+ # be changed in the "Global transaction parameters" tab, "Payment retry" section of the
94
+ # Technical Information page).
95
+ # :exception_url => URL of the web page to show the customer when the payment result is uncertain.
96
+ # :paramplus => Field to submit the miscellaneous parameters and their values that you wish to be
97
+ # returned in the post sale request or final redirection.
98
+ # :complus => Field to submit a value you wish to be returned in the post sale request or output.
99
+ # :language => Customer's language, for example: "en_EN"
100
+ #
101
+ class OgoneGateway < Gateway
102
+
103
+ URLS = {
104
+ :order => 'https://secure.ogone.com/ncol/%s/orderdirect.asp',
105
+ :maintenance => 'https://secure.ogone.com/ncol/%s/maintenancedirect.asp'
106
+ }
107
+
108
+ CVV_MAPPING = { 'OK' => 'M',
109
+ 'KO' => 'N',
110
+ 'NO' => 'P' }
111
+
112
+ AVS_MAPPING = { 'OK' => 'M',
113
+ 'KO' => 'N',
114
+ 'NO' => 'R' }
115
+
116
+ SUCCESS_MESSAGE = "The transaction was successful"
117
+
118
+ THREE_D_SECURE_DISPLAY_WAYS = { :main_window => 'MAINW', # display the identification page in the main window
119
+ # (default value).
120
+ :pop_up => 'POPUP', # display the identification page in a pop-up window
121
+ # and return to the main window at the end.
122
+ :pop_ix => 'POPIX' } # display the identification page in a pop-up window
123
+ # and remain in the pop-up window.
124
+
125
+ OGONE_NO_SIGNATURE_DEPRECATION_MESSAGE = "Signature usage will be required from a future release of ActiveMerchant's Ogone Gateway. Please update your Ogone account to use it."
126
+ OGONE_LOW_ENCRYPTION_DEPRECATION_MESSAGE = "SHA512 signature encryptor will be required from a future release of ActiveMerchant's Ogone Gateway. Please update your Ogone account to use it."
127
+ OGONE_STORE_OPTION_DEPRECATION_MESSAGE = "The 'store' option has been renamed to 'billing_id', and its usage is deprecated."
128
+
129
+ self.supported_countries = ['BE', 'DE', 'FR', 'NL', 'AT', 'CH']
130
+ # also supports Airplus and UATP
131
+ self.supported_cardtypes = [:visa, :master, :american_express, :diners_club, :discover, :jcb, :maestro]
132
+ self.homepage_url = 'http://www.ogone.com/'
133
+ self.display_name = 'Ogone'
134
+ self.default_currency = 'EUR'
135
+ self.money_format = :cents
136
+
137
+ def initialize(options = {})
138
+ requires!(options, :login, :user, :password)
139
+ @options = options
140
+ super
141
+ end
142
+
143
+ # Verify and reserve the specified amount on the account, without actually doing the transaction.
144
+ def authorize(money, payment_source, options = {})
145
+ post = {}
146
+ add_invoice(post, options)
147
+ add_payment_source(post, payment_source, options)
148
+ add_address(post, payment_source, options)
149
+ add_customer_data(post, options)
150
+ add_money(post, money, options)
151
+ commit('RES', post)
152
+ end
153
+
154
+ # Verify and transfer the specified amount.
155
+ def purchase(money, payment_source, options = {})
156
+ post = {}
157
+ add_invoice(post, options)
158
+ add_payment_source(post, payment_source, options)
159
+ add_address(post, payment_source, options)
160
+ add_customer_data(post, options)
161
+ add_money(post, money, options)
162
+ commit('SAL', post)
163
+ end
164
+
165
+ # Complete a previously authorized transaction.
166
+ def capture(money, authorization, options = {})
167
+ post = {}
168
+ add_authorization(post, reference_from(authorization))
169
+ add_invoice(post, options)
170
+ add_customer_data(post, options)
171
+ add_money(post, money, options)
172
+ commit('SAL', post)
173
+ end
174
+
175
+ # Cancels a previously authorized transaction.
176
+ def void(identification, options = {})
177
+ post = {}
178
+ add_authorization(post, reference_from(identification))
179
+ commit('DES', post)
180
+ end
181
+
182
+ # Credit the specified account by a specific amount.
183
+ def credit(money, identification_or_credit_card, options = {})
184
+ if reference_transaction?(identification_or_credit_card)
185
+ deprecated CREDIT_DEPRECATION_MESSAGE
186
+ # Referenced credit: refund of a settled transaction
187
+ refund(money, identification_or_credit_card, options)
188
+ else # must be a credit card or card reference
189
+ perform_non_referenced_credit(money, identification_or_credit_card, options)
190
+ end
191
+ end
192
+
193
+ # Refund of a settled transaction
194
+ def refund(money, reference, options = {})
195
+ perform_reference_credit(money, reference, options)
196
+ end
197
+
198
+ # Store a credit card by creating an Ogone Alias
199
+ def store(payment_source, options = {})
200
+ options.merge!(:alias_operation => 'BYOGONE') unless options.has_key?(:billing_id) || options.has_key?(:store)
201
+ response = authorize(1, payment_source, options)
202
+ void(response.authorization) if response.success?
203
+ response
204
+ end
205
+
206
+ def test?
207
+ @options[:test] || super
208
+ end
209
+
210
+ private
211
+
212
+ def reference_from(authorization)
213
+ authorization.split(";").first
214
+ end
215
+
216
+ def reference_transaction?(identifier)
217
+ return false unless identifier.is_a?(String)
218
+ _, action = identifier.split(";")
219
+ !action.nil?
220
+ end
221
+
222
+ def perform_reference_credit(money, payment_target, options = {})
223
+ post = {}
224
+ add_authorization(post, reference_from(payment_target))
225
+ add_money(post, money, options)
226
+ commit('RFD', post)
227
+ end
228
+
229
+ def perform_non_referenced_credit(money, payment_target, options = {})
230
+ # Non-referenced credit: acts like a reverse purchase
231
+ post = {}
232
+ add_invoice(post, options)
233
+ add_payment_source(post, payment_target, options)
234
+ add_address(post, payment_target, options)
235
+ add_customer_data(post, options)
236
+ add_money(post, money, options)
237
+ commit('RFD', post)
238
+ end
239
+
240
+ def add_payment_source(post, payment_source, options)
241
+ if payment_source.is_a?(String)
242
+ add_alias(post, payment_source, options[:alias_operation])
243
+ add_eci(post, options[:eci] || '9')
244
+ else
245
+ if options.has_key?(:store)
246
+ deprecated OGONE_STORE_OPTION_DEPRECATION_MESSAGE
247
+ options[:billing_id] ||= options[:store]
248
+ end
249
+ add_alias(post, options[:billing_id], options[:alias_operation])
250
+ add_eci(post, options[:eci] || '7')
251
+ add_d3d(post, options) if options[:d3d]
252
+ add_creditcard(post, payment_source)
253
+ end
254
+ end
255
+
256
+ def add_d3d(post, options)
257
+ add_pair post, 'FLAG3D', 'Y'
258
+ win_3ds = THREE_D_SECURE_DISPLAY_WAYS.key?(options[:win_3ds]) ?
259
+ THREE_D_SECURE_DISPLAY_WAYS[options[:win_3ds]] :
260
+ THREE_D_SECURE_DISPLAY_WAYS[:main_window]
261
+ add_pair post, 'WIN3DS', win_3ds
262
+
263
+ add_pair post, 'HTTP_ACCEPT', options[:http_accept] || "*/*"
264
+ add_pair post, 'HTTP_USER_AGENT', options[:http_user_agent] if options[:http_user_agent]
265
+ add_pair post, 'ACCEPTURL', options[:accept_url] if options[:accept_url]
266
+ add_pair post, 'DECLINEURL', options[:decline_url] if options[:decline_url]
267
+ add_pair post, 'EXCEPTIONURL', options[:exception_url] if options[:exception_url]
268
+ add_pair post, 'PARAMPLUS', options[:paramplus] if options[:paramplus]
269
+ add_pair post, 'COMPLUS', options[:complus] if options[:complus]
270
+ add_pair post, 'LANGUAGE', options[:language] if options[:language]
271
+ end
272
+
273
+ def add_eci(post, eci)
274
+ add_pair post, 'ECI', eci.to_s
275
+ end
276
+
277
+ def add_alias(post, _alias, alias_operation = nil)
278
+ add_pair post, 'ALIAS', _alias
279
+ add_pair post, 'ALIASOPERATION', alias_operation unless alias_operation.nil?
280
+ end
281
+
282
+ def add_authorization(post, authorization)
283
+ add_pair post, 'PAYID', authorization
284
+ end
285
+
286
+ def add_money(post, money, options)
287
+ add_pair post, 'currency', options[:currency] || @options[:currency] || currency(money)
288
+ add_pair post, 'amount', amount(money)
289
+ end
290
+
291
+ def add_customer_data(post, options)
292
+ add_pair post, 'EMAIL', options[:email]
293
+ add_pair post, 'REMOTE_ADDR', options[:ip]
294
+ end
295
+
296
+ def add_address(post, creditcard, options)
297
+ return unless options[:billing_address]
298
+ add_pair post, 'Owneraddress', options[:billing_address][:address1]
299
+ add_pair post, 'OwnerZip', options[:billing_address][:zip]
300
+ add_pair post, 'ownertown', options[:billing_address][:city]
301
+ add_pair post, 'ownercty', options[:billing_address][:country]
302
+ add_pair post, 'ownertelno', options[:billing_address][:phone]
303
+ end
304
+
305
+ def add_invoice(post, options)
306
+ add_pair post, 'orderID', options[:order_id] || generate_unique_id[0...30]
307
+ add_pair post, 'COM', options[:description]
308
+ end
309
+
310
+ def add_creditcard(post, creditcard)
311
+ add_pair post, 'CN', creditcard.name
312
+ add_pair post, 'CARDNO', creditcard.number
313
+ add_pair post, 'ED', "%02d%02s" % [creditcard.month, creditcard.year.to_s[-2..-1]]
314
+ add_pair post, 'CVC', creditcard.verification_value
315
+ end
316
+
317
+ def parse(body)
318
+ xml_root = REXML::Document.new(body).root
319
+ response = convert_attributes_to_hash(xml_root.attributes)
320
+
321
+ # Add HTML_ANSWER element (3-D Secure specific to the response's params)
322
+ # Note: HTML_ANSWER is not an attribute so we add it "by hand" to the response
323
+ if html_answer = REXML::XPath.first(xml_root, "//HTML_ANSWER")
324
+ response["HTML_ANSWER"] = html_answer.text
325
+ end
326
+
327
+ response
328
+ end
329
+
330
+ def commit(action, parameters)
331
+ add_pair parameters, 'PSPID', @options[:login]
332
+ add_pair parameters, 'USERID', @options[:user]
333
+ add_pair parameters, 'PSWD', @options[:password]
334
+
335
+ url = URLS[parameters['PAYID'] ? :maintenance : :order] % [test? ? "test" : "prod"]
336
+ response = parse(ssl_post(url, post_data(action, parameters)))
337
+
338
+ options = {
339
+ :authorization => [response["PAYID"], action].join(";"),
340
+ :test => test?,
341
+ :avs_result => { :code => AVS_MAPPING[response["AAVCheck"]] },
342
+ :cvv_result => CVV_MAPPING[response["CVCCheck"]]
343
+ }
344
+ OgoneResponse.new(successful?(response), message_from(response), response, options)
345
+ end
346
+
347
+ def successful?(response)
348
+ response["NCERROR"] == "0"
349
+ end
350
+
351
+ def message_from(response)
352
+ if successful?(response)
353
+ SUCCESS_MESSAGE
354
+ else
355
+ format_error_message(response["NCERRORPLUS"])
356
+ end
357
+ end
358
+
359
+ def format_error_message(message)
360
+ raw_message = message.to_s.strip
361
+ case raw_message
362
+ when /\|/
363
+ raw_message.split("|").join(", ").capitalize
364
+ when /\//
365
+ raw_message.split("/").first.to_s.capitalize
366
+ else
367
+ raw_message.to_s.capitalize
368
+ end
369
+ end
370
+
371
+ def post_data(action, parameters = {})
372
+ add_pair parameters, 'Operation', action
373
+ @options[:signature] ? add_signature(parameters) : deprecated(OGONE_NO_SIGNATURE_DEPRECATION_MESSAGE)
374
+ parameters.to_query
375
+ end
376
+
377
+ def add_signature(parameters)
378
+ deprecated(OGONE_LOW_ENCRYPTION_DEPRECATION_MESSAGE) unless @options[:signature_encryptor] == 'sha512'
379
+
380
+ sha_encryptor = case @options[:signature_encryptor]
381
+ when 'sha256'
382
+ Digest::SHA256
383
+ when 'sha512'
384
+ Digest::SHA512
385
+ else
386
+ Digest::SHA1
387
+ end
388
+
389
+ string_to_digest = if @options[:signature_encryptor]
390
+ parameters.sort { |a, b| a[0].upcase <=> b[0].upcase }.map { |k, v| "#{k.upcase}=#{v}" }.join(@options[:signature])
391
+ else
392
+ %w[orderID amount currency CARDNO PSPID Operation ALIAS].map { |key| parameters[key] }.join
393
+ end
394
+ string_to_digest << @options[:signature]
395
+
396
+ add_pair parameters, 'SHASign', sha_encryptor.hexdigest(string_to_digest).upcase
397
+ end
398
+
399
+ def add_pair(post, key, value)
400
+ post[key] = value if !value.blank?
401
+ end
402
+
403
+ def convert_attributes_to_hash(rexml_attributes)
404
+ response_hash = {}
405
+ rexml_attributes.each do |key, value|
406
+ response_hash[key] = value
407
+ end
408
+ response_hash
409
+ end
410
+ end
411
+
412
+ class OgoneResponse < Response
413
+ def order_id
414
+ @params['orderID']
415
+ end
416
+
417
+ def billing_id
418
+ @params['ALIAS']
419
+ end
420
+ end
421
+ end
422
+ end