start_activemerchant 1.50.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (218) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG +1769 -0
  3. data/CONTRIBUTORS +540 -0
  4. data/MIT-LICENSE +20 -0
  5. data/README.md +226 -0
  6. data/lib/active_merchant.rb +67 -0
  7. data/lib/active_merchant/billing.rb +15 -0
  8. data/lib/active_merchant/billing/apple_pay_payment_token.rb +22 -0
  9. data/lib/active_merchant/billing/avs_result.rb +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 +404 -0
  14. data/lib/active_merchant/billing/credit_card_formatting.rb +24 -0
  15. data/lib/active_merchant/billing/credit_card_methods.rb +195 -0
  16. data/lib/active_merchant/billing/cvv_result.rb +38 -0
  17. data/lib/active_merchant/billing/gateway.rb +291 -0
  18. data/lib/active_merchant/billing/gateways.rb +14 -0
  19. data/lib/active_merchant/billing/gateways/allied_wallet.rb +203 -0
  20. data/lib/active_merchant/billing/gateways/app55.rb +176 -0
  21. data/lib/active_merchant/billing/gateways/authorize_net.rb +510 -0
  22. data/lib/active_merchant/billing/gateways/authorize_net_arb.rb +417 -0
  23. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +976 -0
  24. data/lib/active_merchant/billing/gateways/axcessms.rb +181 -0
  25. data/lib/active_merchant/billing/gateways/balanced.rb +256 -0
  26. data/lib/active_merchant/billing/gateways/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 +192 -0
  32. data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +389 -0
  33. data/lib/active_merchant/billing/gateways/beanstream_interac.rb +58 -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 +211 -0
  37. data/lib/active_merchant/billing/gateways/bpoint.rb +277 -0
  38. data/lib/active_merchant/billing/gateways/braintree.rb +19 -0
  39. data/lib/active_merchant/billing/gateways/braintree/braintree_common.rb +9 -0
  40. data/lib/active_merchant/billing/gateways/braintree_blue.rb +574 -0
  41. data/lib/active_merchant/billing/gateways/braintree_orange.rb +20 -0
  42. data/lib/active_merchant/billing/gateways/bridge_pay.rb +189 -0
  43. data/lib/active_merchant/billing/gateways/card_save.rb +23 -0
  44. data/lib/active_merchant/billing/gateways/card_stream.rb +238 -0
  45. data/lib/active_merchant/billing/gateways/cashnet.rb +202 -0
  46. data/lib/active_merchant/billing/gateways/cc5.rb +201 -0
  47. data/lib/active_merchant/billing/gateways/cecabank.rb +229 -0
  48. data/lib/active_merchant/billing/gateways/cenpos.rb +262 -0
  49. data/lib/active_merchant/billing/gateways/certo_direct.rb +278 -0
  50. data/lib/active_merchant/billing/gateways/checkout.rb +216 -0
  51. data/lib/active_merchant/billing/gateways/checkout_v2.rb +200 -0
  52. data/lib/active_merchant/billing/gateways/commercegate.rb +143 -0
  53. data/lib/active_merchant/billing/gateways/conekta.rb +210 -0
  54. data/lib/active_merchant/billing/gateways/cyber_source.rb +720 -0
  55. data/lib/active_merchant/billing/gateways/data_cash.rb +600 -0
  56. data/lib/active_merchant/billing/gateways/dibs.rb +206 -0
  57. data/lib/active_merchant/billing/gateways/efsnet.rb +219 -0
  58. data/lib/active_merchant/billing/gateways/elavon.rb +348 -0
  59. data/lib/active_merchant/billing/gateways/epay.rb +274 -0
  60. data/lib/active_merchant/billing/gateways/evo_ca.rb +308 -0
  61. data/lib/active_merchant/billing/gateways/eway.rb +214 -0
  62. data/lib/active_merchant/billing/gateways/eway_managed.rb +291 -0
  63. data/lib/active_merchant/billing/gateways/eway_rapid.rb +522 -0
  64. data/lib/active_merchant/billing/gateways/exact.rb +227 -0
  65. data/lib/active_merchant/billing/gateways/ezic.rb +206 -0
  66. data/lib/active_merchant/billing/gateways/fat_zebra.rb +213 -0
  67. data/lib/active_merchant/billing/gateways/federated_canada.rb +160 -0
  68. data/lib/active_merchant/billing/gateways/finansbank.rb +23 -0
  69. data/lib/active_merchant/billing/gateways/first_giving.rb +143 -0
  70. data/lib/active_merchant/billing/gateways/first_pay.rb +160 -0
  71. data/lib/active_merchant/billing/gateways/firstdata_e4.rb +413 -0
  72. data/lib/active_merchant/billing/gateways/flo2cash.rb +215 -0
  73. data/lib/active_merchant/billing/gateways/flo2cash_simple.rb +20 -0
  74. data/lib/active_merchant/billing/gateways/garanti.rb +261 -0
  75. data/lib/active_merchant/billing/gateways/global_transport.rb +179 -0
  76. data/lib/active_merchant/billing/gateways/hdfc.rb +207 -0
  77. data/lib/active_merchant/billing/gateways/hps.rb +287 -0
  78. data/lib/active_merchant/billing/gateways/iats_payments.rb +277 -0
  79. data/lib/active_merchant/billing/gateways/ideal/ideal_base.rb +246 -0
  80. data/lib/active_merchant/billing/gateways/ideal/ideal_rabobank.pem +13 -0
  81. data/lib/active_merchant/billing/gateways/ideal/ideal_response.rb +29 -0
  82. data/lib/active_merchant/billing/gateways/ideal_rabobank.rb +66 -0
  83. data/lib/active_merchant/billing/gateways/inspire.rb +219 -0
  84. data/lib/active_merchant/billing/gateways/instapay.rb +163 -0
  85. data/lib/active_merchant/billing/gateways/ipp.rb +175 -0
  86. data/lib/active_merchant/billing/gateways/iridium.rb +457 -0
  87. data/lib/active_merchant/billing/gateways/itransact.rb +448 -0
  88. data/lib/active_merchant/billing/gateways/jetpay.rb +275 -0
  89. data/lib/active_merchant/billing/gateways/linkpoint.rb +438 -0
  90. data/lib/active_merchant/billing/gateways/litle.rb +345 -0
  91. data/lib/active_merchant/billing/gateways/maxipago.rb +197 -0
  92. data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +170 -0
  93. data/lib/active_merchant/billing/gateways/merchant_one.rb +114 -0
  94. data/lib/active_merchant/billing/gateways/merchant_partners.rb +245 -0
  95. data/lib/active_merchant/billing/gateways/merchant_ware.rb +319 -0
  96. data/lib/active_merchant/billing/gateways/merchant_ware_version_four.rb +268 -0
  97. data/lib/active_merchant/billing/gateways/merchant_warrior.rb +195 -0
  98. data/lib/active_merchant/billing/gateways/mercury.rb +326 -0
  99. data/lib/active_merchant/billing/gateways/metrics_global.rb +303 -0
  100. data/lib/active_merchant/billing/gateways/migs.rb +280 -0
  101. data/lib/active_merchant/billing/gateways/migs/migs_codes.rb +100 -0
  102. data/lib/active_merchant/billing/gateways/modern_payments.rb +37 -0
  103. data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +219 -0
  104. data/lib/active_merchant/billing/gateways/monei.rb +307 -0
  105. data/lib/active_merchant/billing/gateways/moneris.rb +309 -0
  106. data/lib/active_merchant/billing/gateways/moneris_us.rb +298 -0
  107. data/lib/active_merchant/billing/gateways/money_movers.rb +152 -0
  108. data/lib/active_merchant/billing/gateways/nab_transact.rb +290 -0
  109. data/lib/active_merchant/billing/gateways/net_registry.rb +198 -0
  110. data/lib/active_merchant/billing/gateways/netaxept.rb +181 -0
  111. data/lib/active_merchant/billing/gateways/netbilling.rb +224 -0
  112. data/lib/active_merchant/billing/gateways/netpay.rb +223 -0
  113. data/lib/active_merchant/billing/gateways/network_merchants.rb +242 -0
  114. data/lib/active_merchant/billing/gateways/nmi.rb +256 -0
  115. data/lib/active_merchant/billing/gateways/ogone.rb +435 -0
  116. data/lib/active_merchant/billing/gateways/omise.rb +319 -0
  117. data/lib/active_merchant/billing/gateways/openpay.rb +194 -0
  118. data/lib/active_merchant/billing/gateways/optimal_payment.rb +314 -0
  119. data/lib/active_merchant/billing/gateways/orbital.rb +834 -0
  120. data/lib/active_merchant/billing/gateways/orbital/orbital_soft_descriptors.rb +47 -0
  121. data/lib/active_merchant/billing/gateways/pac_net_raven.rb +207 -0
  122. data/lib/active_merchant/billing/gateways/pago_facil.rb +122 -0
  123. data/lib/active_merchant/billing/gateways/pay_conex.rb +246 -0
  124. data/lib/active_merchant/billing/gateways/pay_gate_xml.rb +277 -0
  125. data/lib/active_merchant/billing/gateways/pay_hub.rb +213 -0
  126. data/lib/active_merchant/billing/gateways/pay_junction.rb +390 -0
  127. data/lib/active_merchant/billing/gateways/pay_secure.rb +112 -0
  128. data/lib/active_merchant/billing/gateways/paybox_direct.rb +188 -0
  129. data/lib/active_merchant/billing/gateways/payex.rb +412 -0
  130. data/lib/active_merchant/billing/gateways/payflow.rb +308 -0
  131. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +220 -0
  132. data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +39 -0
  133. data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +13 -0
  134. data/lib/active_merchant/billing/gateways/payflow_express.rb +224 -0
  135. data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +15 -0
  136. data/lib/active_merchant/billing/gateways/payflow_uk.rb +21 -0
  137. data/lib/active_merchant/billing/gateways/payment_express.rb +353 -0
  138. data/lib/active_merchant/billing/gateways/paymill.rb +282 -0
  139. data/lib/active_merchant/billing/gateways/paypal.rb +129 -0
  140. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +679 -0
  141. data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +65 -0
  142. data/lib/active_merchant/billing/gateways/paypal/paypal_recurring_api.rb +262 -0
  143. data/lib/active_merchant/billing/gateways/paypal_ca.rb +13 -0
  144. data/lib/active_merchant/billing/gateways/paypal_digital_goods.rb +44 -0
  145. data/lib/active_merchant/billing/gateways/paypal_express.rb +264 -0
  146. data/lib/active_merchant/billing/gateways/paypal_express_common.rb +30 -0
  147. data/lib/active_merchant/billing/gateways/payscout.rb +162 -0
  148. data/lib/active_merchant/billing/gateways/paystation.rb +199 -0
  149. data/lib/active_merchant/billing/gateways/payu_in.rb +247 -0
  150. data/lib/active_merchant/billing/gateways/payway.rb +207 -0
  151. data/lib/active_merchant/billing/gateways/pin.rb +207 -0
  152. data/lib/active_merchant/billing/gateways/plugnpay.rb +283 -0
  153. data/lib/active_merchant/billing/gateways/psigate.rb +216 -0
  154. data/lib/active_merchant/billing/gateways/psl_card.rb +303 -0
  155. data/lib/active_merchant/billing/gateways/qbms.rb +292 -0
  156. data/lib/active_merchant/billing/gateways/quantum.rb +276 -0
  157. data/lib/active_merchant/billing/gateways/quickbooks.rb +280 -0
  158. data/lib/active_merchant/billing/gateways/quickpay.rb +26 -0
  159. data/lib/active_merchant/billing/gateways/quickpay/quickpay_common.rb +188 -0
  160. data/lib/active_merchant/billing/gateways/quickpay/quickpay_v10.rb +240 -0
  161. data/lib/active_merchant/billing/gateways/quickpay/quickpay_v4to7.rb +227 -0
  162. data/lib/active_merchant/billing/gateways/qvalent.rb +179 -0
  163. data/lib/active_merchant/billing/gateways/realex.rb +298 -0
  164. data/lib/active_merchant/billing/gateways/redsys.rb +406 -0
  165. data/lib/active_merchant/billing/gateways/s5.rb +226 -0
  166. data/lib/active_merchant/billing/gateways/sage.rb +173 -0
  167. data/lib/active_merchant/billing/gateways/sage/sage_bankcard.rb +89 -0
  168. data/lib/active_merchant/billing/gateways/sage/sage_core.rb +115 -0
  169. data/lib/active_merchant/billing/gateways/sage/sage_vault.rb +149 -0
  170. data/lib/active_merchant/billing/gateways/sage/sage_virtual_check.rb +97 -0
  171. data/lib/active_merchant/billing/gateways/sage_pay.rb +399 -0
  172. data/lib/active_merchant/billing/gateways/sallie_mae.rb +143 -0
  173. data/lib/active_merchant/billing/gateways/secure_net.rb +263 -0
  174. data/lib/active_merchant/billing/gateways/secure_pay.rb +201 -0
  175. data/lib/active_merchant/billing/gateways/secure_pay_au.rb +281 -0
  176. data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +105 -0
  177. data/lib/active_merchant/billing/gateways/skip_jack.rb +451 -0
  178. data/lib/active_merchant/billing/gateways/smart_ps.rb +283 -0
  179. data/lib/active_merchant/billing/gateways/so_easy_pay.rb +194 -0
  180. data/lib/active_merchant/billing/gateways/spreedly_core.rb +247 -0
  181. data/lib/active_merchant/billing/gateways/stripe.rb +489 -0
  182. data/lib/active_merchant/billing/gateways/swipe_checkout.rb +157 -0
  183. data/lib/active_merchant/billing/gateways/tns.rb +227 -0
  184. data/lib/active_merchant/billing/gateways/trans_first.rb +126 -0
  185. data/lib/active_merchant/billing/gateways/transax.rb +23 -0
  186. data/lib/active_merchant/billing/gateways/transnational.rb +10 -0
  187. data/lib/active_merchant/billing/gateways/trust_commerce.rb +416 -0
  188. data/lib/active_merchant/billing/gateways/usa_epay.rb +25 -0
  189. data/lib/active_merchant/billing/gateways/usa_epay_advanced.rb +1516 -0
  190. data/lib/active_merchant/billing/gateways/usa_epay_transaction.rb +259 -0
  191. data/lib/active_merchant/billing/gateways/vanco.rb +280 -0
  192. data/lib/active_merchant/billing/gateways/verifi.rb +225 -0
  193. data/lib/active_merchant/billing/gateways/viaklix.rb +183 -0
  194. data/lib/active_merchant/billing/gateways/webpay.rb +97 -0
  195. data/lib/active_merchant/billing/gateways/wepay.rb +205 -0
  196. data/lib/active_merchant/billing/gateways/wirecard.rb +420 -0
  197. data/lib/active_merchant/billing/gateways/worldpay.rb +331 -0
  198. data/lib/active_merchant/billing/gateways/worldpay_online_payments.rb +204 -0
  199. data/lib/active_merchant/billing/gateways/worldpay_us.rb +181 -0
  200. data/lib/active_merchant/billing/model.rb +30 -0
  201. data/lib/active_merchant/billing/network_tokenization_credit_card.rb +24 -0
  202. data/lib/active_merchant/billing/payment_token.rb +21 -0
  203. data/lib/active_merchant/billing/rails.rb +3 -0
  204. data/lib/active_merchant/billing/response.rb +92 -0
  205. data/lib/active_merchant/connection.rb +172 -0
  206. data/lib/active_merchant/country.rb +332 -0
  207. data/lib/active_merchant/empty.rb +20 -0
  208. data/lib/active_merchant/errors.rb +35 -0
  209. data/lib/active_merchant/network_connection_retries.rb +79 -0
  210. data/lib/active_merchant/post_data.rb +24 -0
  211. data/lib/active_merchant/posts_data.rb +84 -0
  212. data/lib/active_merchant/version.rb +3 -0
  213. data/lib/activemerchant.rb +1 -0
  214. data/lib/certs/cacert.pem +3866 -0
  215. data/lib/support/gateway_support.rb +71 -0
  216. data/lib/support/outbound_hosts.rb +28 -0
  217. data/lib/support/ssl_verify.rb +93 -0
  218. metadata +387 -0
@@ -0,0 +1,205 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ class WepayGateway < Gateway
4
+ self.test_url = 'https://stage.wepayapi.com/v2'
5
+ self.live_url = 'https://wepayapi.com/v2'
6
+
7
+ self.supported_countries = ['US']
8
+ self.supported_cardtypes = [:visa, :master, :american_express, :discover]
9
+ self.homepage_url = 'https://www.wepay.com/'
10
+ self.default_currency = 'USD'
11
+ self.display_name = 'WePay'
12
+
13
+ def initialize(options = {})
14
+ requires!(options, :client_id, :account_id, :access_token)
15
+ super(options)
16
+ end
17
+
18
+ def purchase(money, payment_method, options = {})
19
+ post = {}
20
+ if payment_method.is_a?(String)
21
+ purchase_with_token(post, money, payment_method, options)
22
+ else
23
+ MultiResponse.run do |r|
24
+ r.process { store(payment_method, options) }
25
+ r.process { purchase_with_token(post, money, split_authorization(r.authorization).first, options) }
26
+ end
27
+ end
28
+ end
29
+
30
+ def authorize(money, payment_method, options = {})
31
+ post = {auto_capture: 0}
32
+ if payment_method.is_a?(String)
33
+ purchase_with_token(post, money, payment_method, options)
34
+ else
35
+ MultiResponse.run do |r|
36
+ r.process { store(payment_method, options) }
37
+ r.process { purchase_with_token(post, money, split_authorization(r.authorization).first, options) }
38
+ end
39
+ end
40
+ end
41
+
42
+ def capture(money, identifier, options = {})
43
+ post = {}
44
+ post[:checkout_id] = split_authorization(identifier).first
45
+ commit('/checkout/capture', post)
46
+ end
47
+
48
+ def void(identifier, options = {})
49
+ post = {}
50
+ post[:checkout_id] = split_authorization(identifier).first
51
+ post[:cancel_reason] = (options[:description] || "Void")
52
+ commit('/checkout/cancel', post)
53
+ end
54
+
55
+ def refund(money, identifier, options = {})
56
+ checkout_id, original_amount = split_authorization(identifier)
57
+
58
+ post = {}
59
+ post[:checkout_id] = checkout_id
60
+ if(money && (original_amount != amount(money)))
61
+ post[:amount] = amount(money)
62
+ end
63
+ post[:refund_reason] = (options[:description] || "Refund")
64
+ post[:app_fee] = options[:application_fee] if options[:application_fee]
65
+ post[:payer_email_message] = options[:payer_email_message] if options[:payer_email_message]
66
+ post[:payee_email_message] = options[:payee_email_message] if options[:payee_email_message]
67
+ commit("/checkout/refund", post)
68
+ end
69
+
70
+ def store(creditcard, options = {})
71
+ requires!(options, :email)
72
+
73
+ post = {}
74
+ post[:client_id] = @options[:client_id]
75
+ post[:user_name] = "#{creditcard.first_name} #{creditcard.last_name}"
76
+ post[:email] = options[:email] || "unspecified@example.com"
77
+ post[:cc_number] = creditcard.number
78
+ post[:cvv] = creditcard.verification_value unless options[:recurring]
79
+ post[:expiration_month] = "#{creditcard.month}"
80
+ post[:expiration_year] = "#{creditcard.year}"
81
+ post[:original_ip] = options[:ip] if options[:ip]
82
+ post[:original_device] = options[:device_fingerprint] if options[:device_fingerprint]
83
+ if(billing_address = (options[:billing_address] || options[:address]))
84
+ post[:address] = {
85
+ "address1" => billing_address[:address1],
86
+ "city" => billing_address[:city],
87
+ "country" => billing_address[:country]
88
+ }
89
+ if(post[:country] == "US")
90
+ post[:address]["zip"] = billing_address[:zip]
91
+ post[:address]["state"] = billing_address[:state]
92
+ else
93
+ post[:address]["region"] = billing_address[:state]
94
+ post[:address]["postcode"] = billing_address[:zip]
95
+ end
96
+ end
97
+
98
+ if options[:recurring] == true
99
+ post[:client_secret] = @options[:client_secret]
100
+ commit('/credit_card/transfer', post)
101
+ else
102
+ commit('/credit_card/create', post)
103
+ end
104
+ end
105
+
106
+ private
107
+
108
+ def purchase_with_token(post, money, token, options)
109
+ add_token(post, token)
110
+ add_product_data(post, money, options)
111
+ commit('/checkout/create', post)
112
+ end
113
+
114
+ def add_product_data(post, money, options)
115
+ post[:account_id] = @options[:account_id]
116
+ post[:amount] = amount(money)
117
+ post[:short_description] = (options[:description] || "Purchase")
118
+ post[:type] = (options[:type] || "GOODS")
119
+ post[:currency] = (options[:currency] || currency(money))
120
+ post[:long_description] = options[:long_description] if options[:long_description]
121
+ post[:payer_email_message] = options[:payer_email_message] if options[:payer_email_message]
122
+ post[:payee_email_message] = options[:payee_email_message] if options[:payee_email_message]
123
+ post[:reference_id] = options[:order_id] if options[:order_id]
124
+ post[:app_fee] = options[:application_fee] if options[:application_fee]
125
+ post[:fee_payer] = options[:fee_payer] if options[:fee_payer]
126
+ post[:redirect_uri] = options[:redirect_uri] if options[:redirect_uri]
127
+ post[:callback_uri] = options[:callback_uri] if options[:callback_uri]
128
+ post[:fallback_uri] = options[:fallback_uri] if options[:fallback_uri]
129
+ post[:require_shipping] = options[:require_shipping] if options[:require_shipping]
130
+ post[:shipping_fee] = options[:shipping_fee] if options[:shipping_fee]
131
+ post[:charge_tax] = options[:charge_tax] if options[:charge_tax]
132
+ post[:mode] = options[:mode] if options[:mode]
133
+ post[:preapproval_id] = options[:preapproval_id] if options[:preapproval_id]
134
+ post[:prefill_info] = options[:prefill_info] if options[:prefill_info]
135
+ post[:funding_sources] = options[:funding_sources] if options[:funding_sources]
136
+ end
137
+
138
+ def add_token(post, token)
139
+ post[:payment_method_id] = token
140
+ post[:payment_method_type] = "credit_card"
141
+ end
142
+
143
+ def parse(response)
144
+ JSON.parse(response)
145
+ end
146
+
147
+ def commit(action, params, options={})
148
+ begin
149
+ response = parse(ssl_post(
150
+ ((test? ? test_url : live_url) + action),
151
+ params.to_json,
152
+ headers
153
+ ))
154
+ rescue ResponseError => e
155
+ response = parse(e.response.body)
156
+ end
157
+
158
+ return Response.new(
159
+ success_from(response),
160
+ message_from(response),
161
+ response,
162
+ authorization: authorization_from(response, params),
163
+ test: test?
164
+ )
165
+
166
+ rescue JSON::ParserError
167
+ return unparsable_response(response)
168
+ end
169
+
170
+ def success_from(response)
171
+ (!response["error"])
172
+ end
173
+
174
+ def message_from(response)
175
+ (response["error"] ? response["error_description"] : "Success")
176
+ end
177
+
178
+ def authorization_from(response, params)
179
+ return response["credit_card_id"].to_s if response["credit_card_id"]
180
+
181
+ [response["checkout_id"], params[:amount]].join('|')
182
+ end
183
+
184
+ def split_authorization(authorization)
185
+ auth, original_amount = authorization.to_s.split("|")
186
+ [auth, original_amount]
187
+ end
188
+
189
+ def unparsable_response(raw_response)
190
+ message = "Invalid JSON response received from WePay. Please contact WePay support if you continue to receive this message."
191
+ message += " (The raw response returned by the API was #{raw_response.inspect})"
192
+ return Response.new(false, message)
193
+ end
194
+
195
+ def headers
196
+ {
197
+ "Content-Type" => "application/json",
198
+ "User-Agent" => "ActiveMerchantBindings/#{ActiveMerchant::VERSION}",
199
+ "Authorization" => "Bearer #{@options[:access_token]}"
200
+ }
201
+ end
202
+ end
203
+ end
204
+ end
205
+
@@ -0,0 +1,420 @@
1
+ require 'base64'
2
+
3
+ module ActiveMerchant #:nodoc:
4
+ module Billing #:nodoc:
5
+ class WirecardGateway < Gateway
6
+ self.test_url = 'https://c3-test.wirecard.com/secure/ssl-gateway'
7
+ self.live_url = 'https://c3.wirecard.com/secure/ssl-gateway'
8
+
9
+ # The Namespaces are not really needed, because it just tells the System, that there's actually no namespace used.
10
+ # It's just specified here for completeness.
11
+ ENVELOPE_NAMESPACES = {
12
+ 'xmlns:xsi' => 'http://www.w3.org/1999/XMLSchema-instance',
13
+ 'xsi:noNamespaceSchemaLocation' => 'wirecard.xsd'
14
+ }
15
+
16
+ PERMITTED_TRANSACTIONS = %w[ PREAUTHORIZATION CAPTURE PURCHASE ]
17
+
18
+ RETURN_CODES = %w[ ACK NOK ]
19
+
20
+ # Wirecard only allows phone numbers with a format like this: +xxx(yyy)zzz-zzzz-ppp, where:
21
+ # xxx = Country code
22
+ # yyy = Area or city code
23
+ # zzz-zzzz = Local number
24
+ # ppp = PBX extension
25
+ # For example, a typical U.S. or Canadian number would be "+1(202)555-1234-739" indicating PBX extension 739 at phone
26
+ # number 5551234 within area code 202 (country code 1).
27
+ VALID_PHONE_FORMAT = /\+\d{1,3}(\(?\d{3}\)?)?\d{3}-\d{4}-\d{3}/
28
+
29
+ self.supported_cardtypes = [ :visa, :master, :american_express, :diners_club, :jcb, :switch ]
30
+ self.supported_countries = %w(AD CY GI IM MT RO CH AT DK GR IT MC SM TR BE EE HU LV NL SK GB BG FI IS LI NO SI VA FR IL LT PL ES CZ DE IE LU PT SE)
31
+ self.homepage_url = 'http://www.wirecard.com'
32
+ self.display_name = 'Wirecard'
33
+ self.default_currency = 'EUR'
34
+ self.money_format = :cents
35
+
36
+ # Public: Create a new Wirecard gateway.
37
+ #
38
+ # options - A hash of options:
39
+ # :login - The username
40
+ # :password - The password
41
+ # :signature - The BusinessCaseSignature
42
+ def initialize(options = {})
43
+ requires!(options, :login, :password, :signature)
44
+ super
45
+ end
46
+
47
+ # Authorization - the second parameter may be a CreditCard or
48
+ # a String which represents a GuWID reference to an earlier
49
+ # transaction. If a GuWID is given, rather than a CreditCard,
50
+ # then then the :recurring option will be forced to "Repeated"
51
+ def authorize(money, payment_method, options = {})
52
+ if payment_method.respond_to?(:number)
53
+ options[:credit_card] = payment_method
54
+ else
55
+ options[:preauthorization] = payment_method
56
+ end
57
+ commit(:preauthorization, money, options)
58
+ end
59
+
60
+ def capture(money, authorization, options = {})
61
+ options[:preauthorization] = authorization
62
+ commit(:capture, money, options)
63
+ end
64
+
65
+ # Purchase - the second parameter may be a CreditCard or
66
+ # a String which represents a GuWID reference to an earlier
67
+ # transaction. If a GuWID is given, rather than a CreditCard,
68
+ # then then the :recurring option will be forced to "Repeated"
69
+ def purchase(money, payment_method, options = {})
70
+ if payment_method.respond_to?(:number)
71
+ options[:credit_card] = payment_method
72
+ else
73
+ options[:preauthorization] = payment_method
74
+ end
75
+ commit(:purchase, money, options)
76
+ end
77
+
78
+ def void(identification, options = {})
79
+ options[:preauthorization] = identification
80
+ commit(:reversal, nil, options)
81
+ end
82
+
83
+ def refund(money, identification, options = {})
84
+ options[:preauthorization] = identification
85
+ commit(:bookback, money, options)
86
+ end
87
+
88
+ # Store card - Wirecard supports the notion of "Recurring
89
+ # Transactions" by allowing the merchant to provide a reference
90
+ # to an earlier transaction (the GuWID) rather than a credit
91
+ # card. A reusable reference (GuWID) can be obtained by sending
92
+ # a purchase or authorization transaction with the element
93
+ # "RECURRING_TRANSACTION/Type" set to "Initial". Subsequent
94
+ # transactions can then use the GuWID in place of a credit
95
+ # card by setting "RECURRING_TRANSACTION/Type" to "Repeated".
96
+ #
97
+ # This implementation of card store utilizes a Wirecard
98
+ # "Authorization Check" (a Preauthorization that is automatically
99
+ # reversed). It defaults to a check amount of "100" (i.e.
100
+ # $1.00) but this can be overriden (see below).
101
+ #
102
+ # IMPORTANT: In order to reuse the stored reference, the
103
+ # +authorization+ from the response should be saved by
104
+ # your application code.
105
+ #
106
+ # ==== Options specific to +store+
107
+ #
108
+ # * <tt>:amount</tt> -- The amount, in cents, that should be
109
+ # "validated" by the Authorization Check. This amount will
110
+ # be reserved and then reversed. Default is 100.
111
+ #
112
+ # Note: This is not the only way to achieve a card store
113
+ # operation at Wirecard. Any +purchase+ or +authorize+
114
+ # can be sent with +options[:recurring] = 'Initial'+ to make
115
+ # the returned authorization/GuWID usable in later transactions
116
+ # with +options[:recurring] = 'Repeated'+.
117
+ def store(creditcard, options = {})
118
+ options[:credit_card] = creditcard
119
+ options[:recurring] = 'Initial'
120
+ money = options.delete(:amount) || 100
121
+ # Amex does not support authorization_check
122
+ if creditcard.brand == 'american_express'
123
+ commit(:preauthorization, money, options)
124
+ else
125
+ commit(:authorization_check, money, options)
126
+ end
127
+ end
128
+
129
+ private
130
+ def clean_description(description)
131
+ description.to_s.slice(0,32).encode("US-ASCII", invalid: :replace, undef: :replace, replace: '?')
132
+ end
133
+
134
+ def prepare_options_hash(options)
135
+ result = @options.merge(options)
136
+ setup_address_hash!(result)
137
+ result
138
+ end
139
+
140
+ # Create all address hash key value pairs so that
141
+ # it still works if only provided with one or two of them
142
+ def setup_address_hash!(options)
143
+ options[:billing_address] = options[:billing_address] || options[:address] || {}
144
+ options[:shipping_address] = options[:shipping_address] || {}
145
+ # Include Email in address-hash from options-hash
146
+ options[:billing_address][:email] = options[:email] if options[:email]
147
+ end
148
+
149
+ # If a GuWID (string-based reference) is passed rather than a
150
+ # credit card, then the :recurring type needs to be forced to
151
+ # "Repeated"
152
+ def setup_recurring_flag(options)
153
+ options[:recurring] = 'Repeated' if options[:preauthorization].present?
154
+ end
155
+
156
+ # Contact WireCard, make the XML request, and parse the
157
+ # reply into a Response object
158
+ def commit(action, money, options)
159
+ request = build_request(action, money, options)
160
+
161
+ headers = { 'Content-Type' => 'text/xml',
162
+ 'Authorization' => encoded_credentials }
163
+
164
+ response = parse(ssl_post(test? ? self.test_url : self.live_url, request, headers))
165
+ # Pending Status also means Acknowledged (as stated in their specification)
166
+ success = response[:FunctionResult] == "ACK" || response[:FunctionResult] == "PENDING"
167
+ message = response[:Message]
168
+ authorization = response[:GuWID]
169
+
170
+ Response.new(success, message, response,
171
+ :test => test?,
172
+ :authorization => authorization,
173
+ :avs_result => { :code => avs_code(response, options) },
174
+ :cvv_result => response[:CVCResponseCode]
175
+ )
176
+ rescue ResponseError => e
177
+ if e.response.code == "401"
178
+ return Response.new(false, "Invalid Login")
179
+ else
180
+ raise
181
+ end
182
+ end
183
+
184
+ # Generates the complete xml-message, that gets sent to the gateway
185
+ def build_request(action, money, options)
186
+ options = prepare_options_hash(options)
187
+ options[:action] = action
188
+ xml = Builder::XmlMarkup.new :indent => 2
189
+ xml.instruct!
190
+ xml.tag! 'WIRECARD_BXML' do
191
+ xml.tag! 'W_REQUEST' do
192
+ xml.tag! 'W_JOB' do
193
+ xml.tag! 'JobID', ''
194
+ # UserID for this transaction
195
+ xml.tag! 'BusinessCaseSignature', options[:signature] || options[:login]
196
+ # Create the whole rest of the message
197
+ add_transaction_data(xml, money, options)
198
+ end
199
+ end
200
+ end
201
+ xml.target!
202
+ end
203
+
204
+ # Includes the whole transaction data (payment, creditcard, address)
205
+ def add_transaction_data(xml, money, options)
206
+ options[:order_id] ||= generate_unique_id
207
+
208
+ xml.tag! "FNC_CC_#{options[:action].to_s.upcase}" do
209
+ xml.tag! 'FunctionID', clean_description(options[:description])
210
+ xml.tag! 'CC_TRANSACTION' do
211
+ xml.tag! 'TransactionID', options[:order_id]
212
+ xml.tag! 'CommerceType', options[:commerce_type] if options[:commerce_type]
213
+ case options[:action]
214
+ when :preauthorization, :purchase, :authorization_check
215
+ setup_recurring_flag(options)
216
+ add_invoice(xml, money, options)
217
+
218
+ if options[:credit_card]
219
+ add_creditcard(xml, options[:credit_card])
220
+ else
221
+ xml.tag! 'GuWID', options[:preauthorization]
222
+ end
223
+
224
+ add_address(xml, options[:billing_address])
225
+ when :capture, :bookback
226
+ xml.tag! 'GuWID', options[:preauthorization]
227
+ add_amount(xml, money)
228
+ when :reversal
229
+ xml.tag! 'GuWID', options[:preauthorization]
230
+ end
231
+ end
232
+ end
233
+ end
234
+
235
+ # Includes the payment (amount, currency, country) to the transaction-xml
236
+ def add_invoice(xml, money, options)
237
+ add_amount(xml, money)
238
+ xml.tag! 'Currency', options[:currency] || currency(money)
239
+ xml.tag! 'CountryCode', options[:billing_address][:country]
240
+ xml.tag! 'RECURRING_TRANSACTION' do
241
+ xml.tag! 'Type', options[:recurring] || 'Single'
242
+ end
243
+ end
244
+
245
+ # Include the amount in the transaction-xml
246
+ def add_amount(xml, money)
247
+ xml.tag! 'Amount', amount(money)
248
+ end
249
+
250
+ # Includes the credit-card data to the transaction-xml
251
+ def add_creditcard(xml, creditcard)
252
+ raise "Creditcard must be supplied!" if creditcard.nil?
253
+ xml.tag! 'CREDIT_CARD_DATA' do
254
+ xml.tag! 'CreditCardNumber', creditcard.number
255
+ xml.tag! 'CVC2', creditcard.verification_value
256
+ xml.tag! 'ExpirationYear', creditcard.year
257
+ xml.tag! 'ExpirationMonth', format(creditcard.month, :two_digits)
258
+ xml.tag! 'CardHolderName', [creditcard.first_name, creditcard.last_name].join(' ')
259
+ end
260
+ end
261
+
262
+ # Includes the IP address of the customer to the transaction-xml
263
+ def add_customer_data(xml, options)
264
+ return unless options[:ip]
265
+ xml.tag! 'CONTACT_DATA' do
266
+ xml.tag! 'IPAddress', options[:ip]
267
+ end
268
+ end
269
+
270
+ # Includes the address to the transaction-xml
271
+ def add_address(xml, address)
272
+ return if address.nil?
273
+ xml.tag! 'CORPTRUSTCENTER_DATA' do
274
+ xml.tag! 'ADDRESS' do
275
+ xml.tag! 'Address1', address[:address1]
276
+ xml.tag! 'Address2', address[:address2] if address[:address2]
277
+ xml.tag! 'City', address[:city]
278
+ xml.tag! 'ZipCode', address[:zip]
279
+
280
+ if address[:state] =~ /[A-Za-z]{2}/ && address[:country] =~ /^(us|ca)$/i
281
+ xml.tag! 'State', address[:state].upcase
282
+ end
283
+
284
+ xml.tag! 'Country', address[:country]
285
+ xml.tag! 'Phone', address[:phone] if address[:phone] =~ VALID_PHONE_FORMAT
286
+ xml.tag! 'Email', address[:email]
287
+ end
288
+ end
289
+ end
290
+
291
+ # Read the XML message from the gateway and check if it was successful,
292
+ # and also extract required return values from the response.
293
+ def parse(xml)
294
+ basepath = '/WIRECARD_BXML/W_RESPONSE'
295
+ response = {}
296
+
297
+ xml = REXML::Document.new(xml)
298
+ if root = REXML::XPath.first(xml, "#{basepath}/W_JOB")
299
+ parse_response(response, root)
300
+ elsif root = REXML::XPath.first(xml, "//ERROR")
301
+ parse_error_only_response(response, root)
302
+ else
303
+ response[:Message] = "No valid XML response message received. \
304
+ Propably wrong credentials supplied with HTTP header."
305
+ end
306
+
307
+ response
308
+ end
309
+
310
+ def parse_error_only_response(response, root)
311
+ error_code = REXML::XPath.first(root, "Number")
312
+ response[:ErrorCode] = error_code.text if error_code
313
+ response[:Message] = parse_error(root)
314
+ end
315
+
316
+ # Parse the <ProcessingStatus> Element which contains all important information
317
+ def parse_response(response, root)
318
+ status = nil
319
+
320
+ root.elements.to_a.each do |node|
321
+ if node.name =~ /FNC_CC_/
322
+ status = REXML::XPath.first(node, "CC_TRANSACTION/PROCESSING_STATUS")
323
+ end
324
+ end
325
+
326
+ message = ""
327
+ if status
328
+ if info = status.elements['Info']
329
+ message << info.text
330
+ end
331
+
332
+ status.elements.to_a.each do |node|
333
+ if (node.elements.size == 0)
334
+ response[node.name.to_sym] = (node.text || '').strip
335
+ else
336
+ node.elements.each do |childnode|
337
+ name = "#{node.name}_#{childnode.name}"
338
+ response[name.to_sym] = (childnode.text || '').strip
339
+ end
340
+ end
341
+ end
342
+
343
+ error_code = REXML::XPath.first(status, "ERROR/Number")
344
+ response['ErrorCode'] = error_code.text if error_code
345
+ end
346
+
347
+ parse_error(root, message)
348
+ response[:Message] = message
349
+ end
350
+
351
+ # Parse a generic error response from the gateway
352
+ def parse_error(root, message = "")
353
+ # Get errors if available and append them to the message
354
+ errors = errors_to_string(root)
355
+ unless errors.strip.blank?
356
+ message << ' - ' unless message.strip.blank?
357
+ message << errors
358
+ end
359
+ message
360
+ end
361
+
362
+ # Parses all <ERROR> elements in the response and converts the information
363
+ # to a single string
364
+ def errors_to_string(root)
365
+ # Get context error messages (can be 0..*)
366
+ errors = []
367
+ REXML::XPath.each(root, "//ERROR") do |error_elem|
368
+ error = {}
369
+ error[:Advice] = []
370
+ error[:Message] = error_elem.elements['Message'].text
371
+ error_elem.elements.each('Advice') do |advice|
372
+ error[:Advice] << advice.text
373
+ end
374
+ errors << error
375
+ end
376
+ # Convert all messages to a single string
377
+ string = ''
378
+ errors.each do |error|
379
+ string << error[:Message] if error[:Message]
380
+ error[:Advice].each_with_index do |advice, index|
381
+ string << ' (' if index == 0
382
+ string << "#{index+1}. #{advice}"
383
+ string << ' and ' if index < error[:Advice].size - 1
384
+ string << ')' if index == error[:Advice].size - 1
385
+ end
386
+ end
387
+ string
388
+ end
389
+
390
+ # Amex have different AVS response codes
391
+ AMEX_TRANSLATED_AVS_CODES = {
392
+ "A" => "B", # CSC and Address Matched
393
+ "F" => "D", # All Data Matched
394
+ "N" => "I", # CSC Match
395
+ "U" => "U", # Data Not Checked
396
+ "Y" => "D", # All Data Matched
397
+ "Z" => "P", # CSC and Postcode Matched
398
+ }
399
+
400
+ # Amex have different AVS response codes to visa etc
401
+ def avs_code(response, options)
402
+ if response.has_key?(:AVS_ProviderResultCode)
403
+ if options[:credit_card].present? && ActiveMerchant::Billing::CreditCard.brand?(options[:credit_card].number) == "american_express"
404
+ AMEX_TRANSLATED_AVS_CODES[response[:AVS_ProviderResultCode]]
405
+ else
406
+ response[:AVS_ProviderResultCode]
407
+ end
408
+ end
409
+ end
410
+
411
+ # Encode login and password in Base64 to supply as HTTP header
412
+ # (for http basic authentication)
413
+ def encoded_credentials
414
+ credentials = [@options[:login], @options[:password]].join(':')
415
+ "Basic " << Base64.encode64(credentials).strip
416
+ end
417
+ end
418
+ end
419
+ end
420
+