aktivemerchant 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (193) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG +1596 -0
  3. data/CONTRIBUTORS +511 -0
  4. data/MIT-LICENSE +20 -0
  5. data/README.md +18 -0
  6. data/lib/active_merchant.rb +108 -0
  7. data/lib/active_merchant/billing.rb +13 -0
  8. data/lib/active_merchant/billing/apple_pay_payment_token.rb +22 -0
  9. data/lib/active_merchant/billing/avs_result.rb +98 -0
  10. data/lib/active_merchant/billing/base.rb +72 -0
  11. data/lib/active_merchant/billing/check.rb +76 -0
  12. data/lib/active_merchant/billing/compatibility.rb +120 -0
  13. data/lib/active_merchant/billing/credit_card.rb +352 -0
  14. data/lib/active_merchant/billing/credit_card_formatting.rb +24 -0
  15. data/lib/active_merchant/billing/credit_card_methods.rb +160 -0
  16. data/lib/active_merchant/billing/cvv_result.rb +38 -0
  17. data/lib/active_merchant/billing/gateway.rb +268 -0
  18. data/lib/active_merchant/billing/gateways.rb +17 -0
  19. data/lib/active_merchant/billing/gateways/adyen.rb +209 -0
  20. data/lib/active_merchant/billing/gateways/alfabank.rb +117 -0
  21. data/lib/active_merchant/billing/gateways/app55.rb +176 -0
  22. data/lib/active_merchant/billing/gateways/authorize_net.rb +419 -0
  23. data/lib/active_merchant/billing/gateways/authorize_net_arb.rb +417 -0
  24. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +976 -0
  25. data/lib/active_merchant/billing/gateways/balanced.rb +256 -0
  26. data/lib/active_merchant/billing/gateways/bank_frick.rb +225 -0
  27. data/lib/active_merchant/billing/gateways/banwire.rb +105 -0
  28. data/lib/active_merchant/billing/gateways/barclays_epdq.rb +314 -0
  29. data/lib/active_merchant/billing/gateways/barclays_epdq_extra_plus.rb +15 -0
  30. data/lib/active_merchant/billing/gateways/be2bill.rb +131 -0
  31. data/lib/active_merchant/billing/gateways/beanstream.rb +188 -0
  32. data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +393 -0
  33. data/lib/active_merchant/billing/gateways/beanstream_interac.rb +54 -0
  34. data/lib/active_merchant/billing/gateways/blue_pay.rb +506 -0
  35. data/lib/active_merchant/billing/gateways/bogus.rb +140 -0
  36. data/lib/active_merchant/billing/gateways/borgun.rb +210 -0
  37. data/lib/active_merchant/billing/gateways/braintree.rb +19 -0
  38. data/lib/active_merchant/billing/gateways/braintree/braintree_common.rb +9 -0
  39. data/lib/active_merchant/billing/gateways/braintree_blue.rb +515 -0
  40. data/lib/active_merchant/billing/gateways/braintree_orange.rb +20 -0
  41. data/lib/active_merchant/billing/gateways/bridge_pay.rb +189 -0
  42. data/lib/active_merchant/billing/gateways/card_save.rb +23 -0
  43. data/lib/active_merchant/billing/gateways/card_stream.rb +220 -0
  44. data/lib/active_merchant/billing/gateways/cashnet.rb +191 -0
  45. data/lib/active_merchant/billing/gateways/cc5.rb +201 -0
  46. data/lib/active_merchant/billing/gateways/cecabank.rb +229 -0
  47. data/lib/active_merchant/billing/gateways/certo_direct.rb +278 -0
  48. data/lib/active_merchant/billing/gateways/checkout.rb +213 -0
  49. data/lib/active_merchant/billing/gateways/commercegate.rb +143 -0
  50. data/lib/active_merchant/billing/gateways/conekta.rb +209 -0
  51. data/lib/active_merchant/billing/gateways/cyber_source.rb +709 -0
  52. data/lib/active_merchant/billing/gateways/data_cash.rb +600 -0
  53. data/lib/active_merchant/billing/gateways/efsnet.rb +219 -0
  54. data/lib/active_merchant/billing/gateways/elavon.rb +348 -0
  55. data/lib/active_merchant/billing/gateways/epay.rb +275 -0
  56. data/lib/active_merchant/billing/gateways/evo_ca.rb +308 -0
  57. data/lib/active_merchant/billing/gateways/eway.rb +214 -0
  58. data/lib/active_merchant/billing/gateways/eway_managed.rb +291 -0
  59. data/lib/active_merchant/billing/gateways/eway_rapid.rb +524 -0
  60. data/lib/active_merchant/billing/gateways/exact.rb +218 -0
  61. data/lib/active_merchant/billing/gateways/fat_zebra.rb +173 -0
  62. data/lib/active_merchant/billing/gateways/federated_canada.rb +160 -0
  63. data/lib/active_merchant/billing/gateways/finansbank.rb +23 -0
  64. data/lib/active_merchant/billing/gateways/first_giving.rb +143 -0
  65. data/lib/active_merchant/billing/gateways/first_pay.rb +160 -0
  66. data/lib/active_merchant/billing/gateways/firstdata_e4.rb +355 -0
  67. data/lib/active_merchant/billing/gateways/garanti.rb +257 -0
  68. data/lib/active_merchant/billing/gateways/global_transport.rb +183 -0
  69. data/lib/active_merchant/billing/gateways/hdfc.rb +207 -0
  70. data/lib/active_merchant/billing/gateways/hps.rb +288 -0
  71. data/lib/active_merchant/billing/gateways/iats_payments.rb +251 -0
  72. data/lib/active_merchant/billing/gateways/ideal/ideal_base.rb +246 -0
  73. data/lib/active_merchant/billing/gateways/ideal/ideal_rabobank.pem +13 -0
  74. data/lib/active_merchant/billing/gateways/ideal/ideal_response.rb +29 -0
  75. data/lib/active_merchant/billing/gateways/ideal_rabobank.rb +66 -0
  76. data/lib/active_merchant/billing/gateways/inspire.rb +213 -0
  77. data/lib/active_merchant/billing/gateways/instapay.rb +163 -0
  78. data/lib/active_merchant/billing/gateways/iridium.rb +457 -0
  79. data/lib/active_merchant/billing/gateways/itransact.rb +448 -0
  80. data/lib/active_merchant/billing/gateways/jetpay.rb +275 -0
  81. data/lib/active_merchant/billing/gateways/linkpoint.rb +438 -0
  82. data/lib/active_merchant/billing/gateways/litle.rb +346 -0
  83. data/lib/active_merchant/billing/gateways/maxipago.rb +197 -0
  84. data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +170 -0
  85. data/lib/active_merchant/billing/gateways/merchant_one.rb +114 -0
  86. data/lib/active_merchant/billing/gateways/merchant_ware.rb +319 -0
  87. data/lib/active_merchant/billing/gateways/merchant_ware_version_four.rb +268 -0
  88. data/lib/active_merchant/billing/gateways/merchant_warrior.rb +195 -0
  89. data/lib/active_merchant/billing/gateways/mercury.rb +333 -0
  90. data/lib/active_merchant/billing/gateways/metrics_global.rb +303 -0
  91. data/lib/active_merchant/billing/gateways/migs.rb +265 -0
  92. data/lib/active_merchant/billing/gateways/migs/migs_codes.rb +100 -0
  93. data/lib/active_merchant/billing/gateways/modern_payments.rb +37 -0
  94. data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +219 -0
  95. data/lib/active_merchant/billing/gateways/moneris.rb +309 -0
  96. data/lib/active_merchant/billing/gateways/moneris_us.rb +291 -0
  97. data/lib/active_merchant/billing/gateways/money_movers.rb +152 -0
  98. data/lib/active_merchant/billing/gateways/nab_transact.rb +280 -0
  99. data/lib/active_merchant/billing/gateways/net_registry.rb +198 -0
  100. data/lib/active_merchant/billing/gateways/netaxept.rb +181 -0
  101. data/lib/active_merchant/billing/gateways/netbilling.rb +190 -0
  102. data/lib/active_merchant/billing/gateways/netpay.rb +223 -0
  103. data/lib/active_merchant/billing/gateways/network_merchants.rb +242 -0
  104. data/lib/active_merchant/billing/gateways/nmi.rb +256 -0
  105. data/lib/active_merchant/billing/gateways/ogone.rb +435 -0
  106. data/lib/active_merchant/billing/gateways/openpay.rb +194 -0
  107. data/lib/active_merchant/billing/gateways/optimal_payment.rb +313 -0
  108. data/lib/active_merchant/billing/gateways/orbital.rb +803 -0
  109. data/lib/active_merchant/billing/gateways/orbital/orbital_soft_descriptors.rb +47 -0
  110. data/lib/active_merchant/billing/gateways/pac_net_raven.rb +207 -0
  111. data/lib/active_merchant/billing/gateways/pago_facil.rb +122 -0
  112. data/lib/active_merchant/billing/gateways/pay_gate_xml.rb +261 -0
  113. data/lib/active_merchant/billing/gateways/pay_junction.rb +390 -0
  114. data/lib/active_merchant/billing/gateways/pay_secure.rb +112 -0
  115. data/lib/active_merchant/billing/gateways/pay_u_latam.rb +462 -0
  116. data/lib/active_merchant/billing/gateways/paybox_direct.rb +188 -0
  117. data/lib/active_merchant/billing/gateways/payex.rb +412 -0
  118. data/lib/active_merchant/billing/gateways/payflow.rb +304 -0
  119. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +209 -0
  120. data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +39 -0
  121. data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +13 -0
  122. data/lib/active_merchant/billing/gateways/payflow_express.rb +224 -0
  123. data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +15 -0
  124. data/lib/active_merchant/billing/gateways/payflow_uk.rb +21 -0
  125. data/lib/active_merchant/billing/gateways/payment_express.rb +353 -0
  126. data/lib/active_merchant/billing/gateways/paymill.rb +281 -0
  127. data/lib/active_merchant/billing/gateways/paypal.rb +117 -0
  128. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +670 -0
  129. data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +65 -0
  130. data/lib/active_merchant/billing/gateways/paypal/paypal_recurring_api.rb +262 -0
  131. data/lib/active_merchant/billing/gateways/paypal_ca.rb +13 -0
  132. data/lib/active_merchant/billing/gateways/paypal_digital_goods.rb +44 -0
  133. data/lib/active_merchant/billing/gateways/paypal_express.rb +264 -0
  134. data/lib/active_merchant/billing/gateways/paypal_express_common.rb +30 -0
  135. data/lib/active_merchant/billing/gateways/payscout.rb +162 -0
  136. data/lib/active_merchant/billing/gateways/paystation.rb +199 -0
  137. data/lib/active_merchant/billing/gateways/payway.rb +207 -0
  138. data/lib/active_merchant/billing/gateways/pin.rb +197 -0
  139. data/lib/active_merchant/billing/gateways/plugnpay.rb +283 -0
  140. data/lib/active_merchant/billing/gateways/psigate.rb +216 -0
  141. data/lib/active_merchant/billing/gateways/psl_card.rb +303 -0
  142. data/lib/active_merchant/billing/gateways/qbms.rb +292 -0
  143. data/lib/active_merchant/billing/gateways/quantum.rb +276 -0
  144. data/lib/active_merchant/billing/gateways/quickpay.rb +367 -0
  145. data/lib/active_merchant/billing/gateways/realex.rb +298 -0
  146. data/lib/active_merchant/billing/gateways/redsys.rb +391 -0
  147. data/lib/active_merchant/billing/gateways/sage.rb +175 -0
  148. data/lib/active_merchant/billing/gateways/sage/sage_bankcard.rb +87 -0
  149. data/lib/active_merchant/billing/gateways/sage/sage_core.rb +114 -0
  150. data/lib/active_merchant/billing/gateways/sage/sage_vault.rb +149 -0
  151. data/lib/active_merchant/billing/gateways/sage/sage_virtual_check.rb +102 -0
  152. data/lib/active_merchant/billing/gateways/sage_pay.rb +398 -0
  153. data/lib/active_merchant/billing/gateways/sallie_mae.rb +143 -0
  154. data/lib/active_merchant/billing/gateways/secure_net.rb +252 -0
  155. data/lib/active_merchant/billing/gateways/secure_pay.rb +201 -0
  156. data/lib/active_merchant/billing/gateways/secure_pay_au.rb +281 -0
  157. data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +105 -0
  158. data/lib/active_merchant/billing/gateways/skip_jack.rb +452 -0
  159. data/lib/active_merchant/billing/gateways/smart_ps.rb +283 -0
  160. data/lib/active_merchant/billing/gateways/so_easy_pay.rb +194 -0
  161. data/lib/active_merchant/billing/gateways/spreedly_core.rb +247 -0
  162. data/lib/active_merchant/billing/gateways/stripe.rb +411 -0
  163. data/lib/active_merchant/billing/gateways/swipe_checkout.rb +157 -0
  164. data/lib/active_merchant/billing/gateways/tns.rb +227 -0
  165. data/lib/active_merchant/billing/gateways/trans_first.rb +126 -0
  166. data/lib/active_merchant/billing/gateways/transax.rb +23 -0
  167. data/lib/active_merchant/billing/gateways/transnational.rb +10 -0
  168. data/lib/active_merchant/billing/gateways/trust_commerce.rb +416 -0
  169. data/lib/active_merchant/billing/gateways/usa_epay.rb +25 -0
  170. data/lib/active_merchant/billing/gateways/usa_epay_advanced.rb +1516 -0
  171. data/lib/active_merchant/billing/gateways/usa_epay_transaction.rb +254 -0
  172. data/lib/active_merchant/billing/gateways/verifi.rb +225 -0
  173. data/lib/active_merchant/billing/gateways/viaklix.rb +183 -0
  174. data/lib/active_merchant/billing/gateways/vindicia.rb +385 -0
  175. data/lib/active_merchant/billing/gateways/webpay.rb +97 -0
  176. data/lib/active_merchant/billing/gateways/wepay.rb +189 -0
  177. data/lib/active_merchant/billing/gateways/wirecard.rb +421 -0
  178. data/lib/active_merchant/billing/gateways/worldpay.rb +331 -0
  179. data/lib/active_merchant/billing/gateways/worldpay_us.rb +181 -0
  180. data/lib/active_merchant/billing/model.rb +30 -0
  181. data/lib/active_merchant/billing/payment_token.rb +21 -0
  182. data/lib/active_merchant/billing/rails.rb +3 -0
  183. data/lib/active_merchant/billing/response.rb +91 -0
  184. data/lib/active_merchant/country.rb +332 -0
  185. data/lib/active_merchant/empty.rb +20 -0
  186. data/lib/active_merchant/errors.rb +29 -0
  187. data/lib/active_merchant/offsite_payments_shim.rb +19 -0
  188. data/lib/active_merchant/version.rb +3 -0
  189. data/lib/activemerchant.rb +1 -0
  190. data/lib/support/gateway_support.rb +71 -0
  191. data/lib/support/outbound_hosts.rb +25 -0
  192. data/lib/support/ssl_verify.rb +93 -0
  193. metadata +400 -0
@@ -0,0 +1,105 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ class BanwireGateway < Gateway
4
+ URL = 'https://banwire.com/api.pago_pro'
5
+
6
+ self.supported_countries = ['MX']
7
+ self.supported_cardtypes = [:visa, :master, :american_express]
8
+ self.homepage_url = 'http://www.banwire.com/'
9
+ self.display_name = 'Banwire'
10
+
11
+ def initialize(options = {})
12
+ requires!(options, :login)
13
+ super
14
+ end
15
+
16
+ def purchase(money, creditcard, options = {})
17
+ post = {}
18
+ add_response_type(post)
19
+ add_customer_data(post, options)
20
+ add_order_data(post, options)
21
+ add_creditcard(post, creditcard)
22
+ add_address(post, creditcard, options)
23
+ add_customer_data(post, options)
24
+ add_amount(post, money, options)
25
+
26
+ commit(money, post)
27
+ end
28
+
29
+ private
30
+
31
+ def add_response_type(post)
32
+ post[:response_format] = "JSON"
33
+ end
34
+
35
+ def add_customer_data(post, options)
36
+ post[:user] = @options[:login]
37
+ post[:phone] = options[:billing_address][:phone]
38
+ post[:mail] = options[:email]
39
+ end
40
+
41
+ def add_order_data(post, options)
42
+ post[:reference] = options[:order_id]
43
+ post[:concept] = options[:description]
44
+ end
45
+
46
+ def add_address(post, creditcard, options)
47
+ post[:address] = options[:billing_address][:address1]
48
+ post[:post_code] = options[:billing_address][:zip]
49
+ end
50
+
51
+ def add_creditcard(post, creditcard)
52
+ post[:card_num] = creditcard.number
53
+ post[:card_name] = creditcard.name
54
+ post[:card_type] = card_brand(creditcard)
55
+ post[:card_exp] = "#{sprintf("%02d", creditcard.month)}/#{"#{creditcard.year}"[-2, 2]}"
56
+ post[:card_ccv2] = creditcard.verification_value
57
+ end
58
+
59
+ def add_amount(post, money, options)
60
+ post[:ammount] = amount(money)
61
+ post[:currency] = options[:currency]
62
+ end
63
+
64
+ def card_brand(card)
65
+ brand = super
66
+ ({"master" => "mastercard", "american_express" => "amex"}[brand] || brand)
67
+ end
68
+
69
+ def parse(body)
70
+ JSON.parse(body)
71
+ end
72
+
73
+ def commit(money, parameters)
74
+ raw_response = ssl_post(URL, post_data(parameters))
75
+ begin
76
+ response = parse(raw_response)
77
+ rescue JSON::ParserError
78
+ response = json_error(raw_response)
79
+ end
80
+
81
+ Response.new(success?(response),
82
+ response["message"],
83
+ response,
84
+ :test => test?,
85
+ :authorization => response["code_auth"])
86
+ end
87
+
88
+ def success?(response)
89
+ (response["response"] == "ok")
90
+ end
91
+
92
+ def post_data(parameters = {})
93
+ parameters.collect { |key, value| "#{key}=#{CGI.escape(value.to_s)}" }.join("&")
94
+ end
95
+
96
+ def json_error(raw_response)
97
+ msg = 'Invalid response received from the Banwire API. Please contact Banwire support if you continue to receive this message.'
98
+ msg += " (The raw response returned by the API was #{raw_response.inspect})"
99
+ {
100
+ "message" => msg
101
+ }
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,314 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ class BarclaysEpdqGateway < Gateway
4
+ self.test_url = 'https://secure2.mde.epdq.co.uk:11500'
5
+ self.live_url = 'https://secure2.epdq.co.uk:11500'
6
+
7
+ self.supported_countries = ['GB']
8
+ self.default_currency = 'GBP'
9
+ self.supported_cardtypes = [:visa, :master, :american_express, :maestro, :switch ]
10
+ self.money_format = :cents
11
+ self.homepage_url = 'http://www.barclaycard.co.uk/business/accepting-payments/epdq-mpi/'
12
+ self.display_name = 'Barclays ePDQ MPI'
13
+
14
+ def initialize(options = {})
15
+ requires!(options, :login, :password, :client_id)
16
+ super
17
+ end
18
+
19
+ def authorize(money, creditcard, options = {})
20
+ document = Document.new(self, @options) do
21
+ add_order_form(options[:order_id]) do
22
+ add_consumer(options) do
23
+ add_creditcard(creditcard)
24
+ end
25
+ add_transaction(:PreAuth, money)
26
+ end
27
+ end
28
+
29
+ commit(document)
30
+ end
31
+
32
+ def purchase(money, creditcard, options = {})
33
+ # disable fraud checks if this is a repeat order:
34
+ if options[:payment_number] && (options[:payment_number] > 1)
35
+ no_fraud = true
36
+ else
37
+ no_fraud = options[:no_fraud]
38
+ end
39
+ document = Document.new(self, @options, :no_fraud => no_fraud) do
40
+ add_order_form(options[:order_id], options[:group_id]) do
41
+ add_consumer(options) do
42
+ add_creditcard(creditcard)
43
+ end
44
+ add_transaction(:Auth, money, options)
45
+ end
46
+ end
47
+ commit(document)
48
+ end
49
+
50
+ # authorization is your unique order ID, not the authorization
51
+ # code returned by ePDQ
52
+ def capture(money, authorization, options = {})
53
+ document = Document.new(self, @options) do
54
+ add_order_form(authorization) do
55
+ add_transaction(:PostAuth, money)
56
+ end
57
+ end
58
+
59
+ commit(document)
60
+ end
61
+
62
+ # authorization is your unique order ID, not the authorization
63
+ # code returned by ePDQ
64
+ def credit(money, creditcard_or_authorization, options = {})
65
+ if creditcard_or_authorization.is_a?(String)
66
+ ActiveMerchant.deprecated CREDIT_DEPRECATION_MESSAGE
67
+ refund(money, creditcard_or_authorization, options)
68
+ else
69
+ credit_new_order(money, creditcard_or_authorization, options)
70
+ end
71
+ end
72
+
73
+ def refund(money, authorization, options = {})
74
+ credit_existing_order(money, authorization, options)
75
+ end
76
+
77
+ def void(authorization, options = {})
78
+ document = Document.new(self, @options) do
79
+ add_order_form(authorization) do
80
+ add_transaction(:Void)
81
+ end
82
+ end
83
+
84
+ commit(document)
85
+ end
86
+
87
+ private
88
+ def credit_new_order(money, creditcard, options)
89
+ document = Document.new(self, @options) do
90
+ add_order_form do
91
+ add_consumer(options) do
92
+ add_creditcard(creditcard)
93
+ end
94
+ add_transaction(:Credit, money)
95
+ end
96
+ end
97
+
98
+ commit(document)
99
+ end
100
+
101
+ def credit_existing_order(money, authorization, options)
102
+ order_id, _ = authorization.split(":")
103
+ document = Document.new(self, @options) do
104
+ add_order_form(order_id) do
105
+ add_transaction(:Credit, money)
106
+ end
107
+ end
108
+
109
+ commit(document)
110
+ end
111
+
112
+ def parse(body)
113
+ parser = Parser.new(body)
114
+ response = parser.parse
115
+ Response.new(response[:success], response[:message], response,
116
+ :test => test?,
117
+ :authorization => response[:authorization],
118
+ :avs_result => response[:avsresponse],
119
+ :cvv_result => response[:cvv_result],
120
+ :order_id => response[:order_id],
121
+ :raw_response => response[:raw_response]
122
+ )
123
+ end
124
+
125
+ def commit(document)
126
+ url = (test? ? self.test_url : self.live_url)
127
+ data = ssl_post(url, document.to_xml)
128
+ parse(data)
129
+ end
130
+
131
+ class Parser
132
+ def initialize(response)
133
+ @response = response
134
+ end
135
+
136
+ def parse
137
+ require 'iconv' unless String.method_defined?(:encode)
138
+ if String.method_defined?(:encode)
139
+ doc = REXML::Document.new(@response.encode("UTF-8", "ISO-8859-1"))
140
+ else
141
+ ic = Iconv.new('UTF-8', 'ISO-8859-1')
142
+ doc = REXML::Document.new(ic.iconv(@response))
143
+ end
144
+
145
+ auth_type = find(doc, "//Transaction/Type").to_s
146
+
147
+ message = find(doc, "//Message/Text")
148
+ if message.blank?
149
+ message = find(doc, "//Transaction/CardProcResp/CcReturnMsg")
150
+ end
151
+
152
+ case auth_type
153
+ when 'Credit', 'Void'
154
+ success = find(doc, "//CcReturnMsg") == "Approved."
155
+ else
156
+ success = find(doc, "//Transaction/AuthCode").present?
157
+ end
158
+
159
+ {
160
+ :success => success,
161
+ :message => message,
162
+ :transaction_id => find(doc, "//Transaction/Id"),
163
+ :avs_result => find(doc, "//Transaction/AvsRespCode"),
164
+ :cvv_result => find(doc, "//Transaction/Cvv2Resp"),
165
+ :authorization => find(doc, "//OrderFormDoc/Id"),
166
+ :raw_response => @response
167
+ }
168
+ end
169
+
170
+ def find(doc, xpath)
171
+ REXML::XPath.first(doc, xpath).try(:text)
172
+ end
173
+ end
174
+
175
+ class Document
176
+ attr_reader :type, :xml
177
+
178
+ PAYMENT_INTERVALS = {
179
+ :days => 'D',
180
+ :months => 'M'
181
+ }
182
+
183
+ EPDQ_CARD_TYPES = {
184
+ :visa => 1,
185
+ :master => 2,
186
+ :switch => 9,
187
+ :maestro => 10,
188
+ }
189
+
190
+ def initialize(gateway, options = {}, document_options = {}, &block)
191
+ @gateway = gateway
192
+ @options = options
193
+ @document_options = document_options
194
+ @xml = Builder::XmlMarkup.new(:indent => 2)
195
+ build(&block)
196
+ end
197
+
198
+ def to_xml
199
+ @xml.target!
200
+ end
201
+
202
+ def build(&block)
203
+ xml.instruct!(:xml, :version => '1.0')
204
+ xml.EngineDocList do
205
+ xml.DocVersion "1.0"
206
+ xml.EngineDoc do
207
+ xml.ContentType "OrderFormDoc"
208
+ xml.User do
209
+ xml.Name(@options[:login])
210
+ xml.Password(@options[:password])
211
+ xml.ClientId({ :DataType => "S32" }, @options[:client_id])
212
+ end
213
+ xml.Instructions do
214
+ if @document_options[:no_fraud]
215
+ xml.Pipeline "PaymentNoFraud"
216
+ else
217
+ xml.Pipeline "Payment"
218
+ end
219
+ end
220
+ instance_eval(&block)
221
+ end
222
+ end
223
+ end
224
+
225
+ def add_order_form(order_id=nil, group_id=nil, &block)
226
+ xml.OrderFormDoc do
227
+ xml.Mode 'P'
228
+ xml.Id(order_id) if order_id
229
+ xml.GroupId(group_id) if group_id
230
+ instance_eval(&block)
231
+ end
232
+ end
233
+
234
+ def add_consumer(options=nil, &block)
235
+ xml.Consumer do
236
+ if options
237
+ xml.Email(options[:email]) if options[:email]
238
+ billing_address = options[:billing_address] || options[:address]
239
+ if billing_address
240
+ xml.BillTo do
241
+ xml.Location do
242
+ xml.Address do
243
+ xml.Street1 billing_address[:address1]
244
+ xml.Street2 billing_address[:address2]
245
+ xml.City billing_address[:city]
246
+ xml.StateProv billing_address[:state]
247
+ xml.PostalCode billing_address[:zip]
248
+ xml.Country billing_address[:country_code]
249
+ end
250
+ end
251
+ end
252
+ end
253
+ end
254
+ instance_eval(&block)
255
+ end
256
+ end
257
+
258
+ def add_creditcard(creditcard)
259
+ xml.PaymentMech do
260
+ xml.CreditCard do
261
+ xml.Type({ :DataType => 'S32' }, EPDQ_CARD_TYPES[creditcard.brand.to_sym])
262
+ xml.Number creditcard.number
263
+ xml.Expires({ :DataType => 'ExpirationDate', :Locale => 826 }, format_expiry_date(creditcard))
264
+ if creditcard.verification_value.present?
265
+ xml.Cvv2Indicator 1
266
+ xml.Cvv2Val creditcard.verification_value
267
+ else
268
+ xml.Cvv2Indicator 5
269
+ end
270
+ xml.IssueNum(creditcard.issue_number) if creditcard.issue_number.present?
271
+ end
272
+ end
273
+ end
274
+
275
+ def add_transaction(auth_type, amount = nil, options = {})
276
+ @auth_type = auth_type
277
+ xml.Transaction do
278
+ xml.Type @auth_type.to_s
279
+ if options[:payment_number] && options[:payment_number] > 1
280
+ xml.CardholderPresentCode({ :DataType => 'S32' }, 8)
281
+ else
282
+ xml.CardholderPresentCode({ :DataType => 'S32' }, 7)
283
+ end
284
+ if options[:payment_number]
285
+ xml.PaymentNumber({ :DataType => 'S32' }, options[:payment_number])
286
+ end
287
+ if options[:total_payments]
288
+ xml.TotalNumberPayments({ :DataType => 'S32' }, options[:total_payments])
289
+ end
290
+ if amount
291
+ xml.CurrentTotals do
292
+ xml.Totals do
293
+ xml.Total({ :DataType => 'Money', :Currency => 826 }, amount)
294
+ end
295
+ end
296
+ end
297
+ end
298
+ end
299
+
300
+ # date must be formatted MM/YY
301
+ def format_expiry_date(creditcard)
302
+ month_str = "%02d" % creditcard.month
303
+ if match = creditcard.year.to_s.match(/^\d{2}(\d{2})$/)
304
+ year_str = "%02d" % match[1].to_i
305
+ else
306
+ year_str = "%02d" % creditcard.year
307
+ end
308
+ "#{month_str}/#{year_str}"
309
+ end
310
+ end
311
+ end
312
+ end
313
+ end
314
+
@@ -0,0 +1,15 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ class BarclaysEpdqExtraPlusGateway < OgoneGateway
4
+ self.test_url = "https://mdepayments.epdq.co.uk/ncol/test/"
5
+ self.live_url = "https://payments.epdq.co.uk/ncol/prod/"
6
+
7
+ self.display_name = "Barclays ePDQ Extra Plus"
8
+ self.homepage_url = "http://www.barclaycard.co.uk/business/accepting-payments/epdq-ecomm/"
9
+
10
+ self.supported_countries = ["GB"]
11
+ self.supported_cardtypes = [:visa, :master, :american_express, :diners_club, :discover, :jcb, :maestro]
12
+ self.default_currency = "GBP"
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,131 @@
1
+ require "digest/sha2"
2
+
3
+ module ActiveMerchant #:nodoc:
4
+ module Billing #:nodoc:
5
+ class Be2billGateway < Gateway
6
+ self.test_url = 'https://secure-test.be2bill.com/front/service/rest/process.php'
7
+ self.live_url = 'https://secure-magenta1.be2bill.com/front/service/rest/process.php'
8
+
9
+ self.display_name = 'Be2Bill'
10
+ self.homepage_url = 'http://www.be2bill.com/'
11
+ self.supported_countries = ['FR']
12
+ self.supported_cardtypes = [:visa, :master, :american_express]
13
+ self.default_currency = 'EUR'
14
+ self.money_format = :cents
15
+
16
+ # These options are mandatory on be2bill (cf. tests) :
17
+ #
18
+ # options = { :order_id => order.id,
19
+ # :customer_id => user.id,
20
+ # :description => "Some description",
21
+ # :referrer => request.env['HTTP_REFERER'],
22
+ # :user_agent => request.env['HTTP_USER_AGENT'],
23
+ # :ip => request.remote_ip,
24
+ # :email => user.email }
25
+
26
+ def initialize(options = {})
27
+ requires!(options, :login, :password)
28
+ super
29
+ end
30
+
31
+ def authorize(money, creditcard, options = {})
32
+ post = {}
33
+ add_invoice(post, options)
34
+ add_creditcard(post, creditcard)
35
+ add_customer_data(post, options)
36
+
37
+ commit('authorization', money, post)
38
+ end
39
+
40
+ def purchase(money, creditcard, options = {})
41
+ post = {}
42
+ add_invoice(post, options)
43
+ add_creditcard(post, creditcard)
44
+ add_customer_data(post, options)
45
+
46
+ commit('payment', money, post)
47
+ end
48
+
49
+ def capture(money, authorization, options = {})
50
+ post = {}
51
+ add_invoice(post, options)
52
+ post[:TRANSACTIONID] = authorization
53
+
54
+ commit('capture', money, post)
55
+ end
56
+
57
+ private
58
+
59
+ def add_customer_data(post, options)
60
+ post[:CLIENTREFERRER] = options[:referrer]
61
+ post[:CLIENTUSERAGENT] = options[:user_agent]
62
+ post[:CLIENTIP] = options[:ip]
63
+ post[:CLIENTEMAIL] = options[:email]
64
+ post[:CLIENTIDENT] = options[:customer_id]
65
+ end
66
+
67
+ def add_invoice(post, options)
68
+ post[:ORDERID] = options[:order_id]
69
+ post[:DESCRIPTION] = options[:description]
70
+ end
71
+
72
+ def add_creditcard(post, creditcard)
73
+ post[:CARDFULLNAME] = creditcard ? creditcard.name : ''
74
+ post[:CARDCODE] = creditcard ? creditcard.number : ''
75
+ post[:CARDVALIDITYDATE] = creditcard ? "%02d-%02s" % [creditcard.month, creditcard.year.to_s[-2..-1]] : ''
76
+ post[:CARDCVV] = creditcard ? creditcard.verification_value : ''
77
+ end
78
+
79
+ def parse(response)
80
+ ActiveSupport::JSON.decode(response)
81
+ end
82
+
83
+ def commit(action, money, parameters)
84
+ parameters[:IDENTIFIER] = @options[:login]
85
+ parameters[:AMOUNT] = amount(money)
86
+ parameters[:VERSION] = '2.0'
87
+
88
+ url = (test? ? self.test_url : self.live_url)
89
+ response = parse(ssl_post(url, post_data(action, parameters)))
90
+
91
+ Response.new(
92
+ successful?(response),
93
+ message_from(response),
94
+ response,
95
+ :authorization => response['TRANSACTIONID'],
96
+ :test => test?
97
+ )
98
+ end
99
+
100
+ def successful?(response)
101
+ %w(0000 0001).include?(response['EXECCODE'])
102
+ end
103
+
104
+ def message_from(response)
105
+ if successful?(response)
106
+ "Approved : #{response['MESSAGE']}"
107
+ else
108
+ "Declined (#{response['EXECCODE']} - #{response['MESSAGE']}"
109
+ end
110
+ end
111
+
112
+ def post_data(action, parameters = {})
113
+ {
114
+ :method => action,
115
+ :params => parameters.merge(HASH: signature(parameters, action))
116
+ }.to_query
117
+ end
118
+
119
+ def signature(parameters, action)
120
+ parameters[:OPERATIONTYPE] = action unless parameters[:OPERATIONTYPE]
121
+
122
+ signature = @options[:password]
123
+ parameters.sort.each do |key, value|
124
+ signature += ("#{key.upcase}=#{value}" + @options[:password])
125
+ end
126
+
127
+ Digest::SHA256.hexdigest(signature)
128
+ end
129
+ end
130
+ end
131
+ end