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,240 @@
1
+ require 'json'
2
+ require 'active_merchant/billing/gateways/quickpay/quickpay_common'
3
+
4
+ module ActiveMerchant
5
+ module Billing
6
+ class QuickpayV10Gateway < Gateway
7
+ include QuickpayCommon
8
+ API_VERSION = 10
9
+
10
+ self.live_url = self.test_url = 'https://api.quickpay.net'
11
+
12
+ def initialize(options = {})
13
+ requires!(options, :api_key)
14
+ super
15
+ end
16
+
17
+ def purchase(money, credit_card, options = {})
18
+ MultiResponse.run(true) do |r|
19
+ r.process { create_payment(money, options) }
20
+ r.process {
21
+ post = authorization_params(money, credit_card, options)
22
+ add_autocapture(post, true)
23
+ commit(synchronized_path("/payments/#{r.authorization}/authorize"), post)
24
+ }
25
+ end
26
+ end
27
+
28
+ def authorize(money, credit_card, options = {})
29
+ MultiResponse.run(true) do |r|
30
+ r.process { create_payment(money, options) }
31
+ r.process {
32
+ post = authorization_params(money, credit_card, options)
33
+ commit(synchronized_path("/payments/#{r.authorization}/authorize"), post)
34
+ }
35
+ end
36
+ end
37
+
38
+ def void(identification)
39
+ commit(synchronized_path "/payments/#{identification}/cancel")
40
+ end
41
+
42
+ def credit(money, identification, options = {})
43
+ ActiveMerchant.deprecated CREDIT_DEPRECATION_MESSAGE
44
+ refund(money, identification, options)
45
+ end
46
+
47
+ def capture(money, identification, options = {})
48
+ post = {}
49
+ add_amount(post, money, options)
50
+ add_additional_params(:capture, post, options)
51
+ commit(synchronized_path("/payments/#{identification}/capture"), post)
52
+ end
53
+
54
+ def refund(money, identification, options = {})
55
+ post = {}
56
+ add_amount(post, money, options)
57
+ add_additional_params(:refund, post, options)
58
+ commit(synchronized_path("/payments/#{identification}/refund"), post)
59
+ end
60
+
61
+ def store(credit_card, options = {})
62
+ MultiResponse.run(true) do |r|
63
+ r.process { create_subscription(options) }
64
+ r.process {
65
+ authorize_subscription(r.authorization, credit_card, options)
66
+ }
67
+ end
68
+ end
69
+
70
+ def unstore(identification)
71
+ commit(synchronized_path "/subscriptions/#{identification}/cancel")
72
+ end
73
+
74
+ private
75
+
76
+ def authorization_params(money, credit_card, options = {})
77
+ post = {}
78
+
79
+ add_amount(post, money, options)
80
+ add_credit_card(post, credit_card)
81
+ add_additional_params(:authorize, post, options)
82
+
83
+ post
84
+ end
85
+
86
+ def create_subscription(options = {})
87
+ post = {}
88
+
89
+ add_subscription_invoice(post, options)
90
+ commit('/subscriptions', post)
91
+ end
92
+
93
+ def authorize_subscription(identification, credit_card, options = {})
94
+ post = {}
95
+
96
+ add_credit_card(post, credit_card, options)
97
+ add_additional_params(:authorize_subscription, post, options)
98
+ commit(synchronized_path("/subscriptions/#{identification}/authorize"), post)
99
+ end
100
+
101
+ def create_payment(money, options = {})
102
+ post = {}
103
+ add_currency(post, money, options)
104
+ add_invoice(post, options)
105
+ commit('/payments', post)
106
+ end
107
+
108
+ def commit(action, params = {})
109
+ success = false
110
+ begin
111
+ response = parse(ssl_post(self.live_url + action, params.to_json, headers))
112
+ success = successful?(response)
113
+ rescue ResponseError => e
114
+ response = response_error(e.response.body)
115
+ rescue JSON::ParserError
116
+ response = json_error(response)
117
+ end
118
+
119
+ Response.new(success, message_from(success, response), response,
120
+ :test => test?,
121
+ :authorization => response['id']
122
+ )
123
+ end
124
+
125
+ def add_subscription_invoice(post, options = {})
126
+ requires!(options, :order_id, :description)
127
+ post[:order_id] = options[:order_id]
128
+ post[:description] = options[:description]
129
+ end
130
+
131
+ def add_currency(post, money, options)
132
+ post[:currency] = options[:currency] || currency(money)
133
+ end
134
+
135
+ def add_amount(post, money, options)
136
+ post[:amount] = amount(money)
137
+ end
138
+
139
+ def add_autocapture(post, value)
140
+ post[:auto_capture] = value
141
+ end
142
+
143
+ def add_order_id(post, options)
144
+ requires!(options, :order_id)
145
+ post[:order_id] = options[:order_id]
146
+ end
147
+
148
+ def add_invoice(post, options)
149
+ add_order_id(post, options)
150
+
151
+ if options[:billing_address]
152
+ post[:invoice_address] = map_address(options[:billing_address])
153
+ end
154
+
155
+ if options[:shipping_address]
156
+ post[:shipping_address] = map_address(options[:shipping_address])
157
+ end
158
+
159
+ [:metadata, :brading_id, :variables].each do |field|
160
+ post[field] = options[field] if options[field]
161
+ end
162
+ end
163
+
164
+ def add_additional_params(action, post, options = {})
165
+ MD5_CHECK_FIELDS[API_VERSION][action].each do |key|
166
+ key = key.to_sym
167
+ post[key] = options[key] if options[key]
168
+ end
169
+ end
170
+
171
+ def add_credit_card(post, credit_card, options = {})
172
+ post[:card] ||= {}
173
+ post[:card][:number] = credit_card.number
174
+ post[:card][:cvd] = credit_card.verification_value
175
+ post[:card][:expiration] = expdate(credit_card)
176
+ post[:card][:issued_to] = credit_card.name
177
+ end
178
+
179
+ def parse(body)
180
+ JSON.parse(body)
181
+ end
182
+
183
+ def successful?(response)
184
+ has_error = response['errors']
185
+ invalid_code = (response.key?('qp_status_code') and response['qp_status_code'] != "20000")
186
+
187
+ !(has_error || invalid_code)
188
+ end
189
+
190
+ def message_from(success, response)
191
+ success ? 'OK' : (response['message'] || response['qp_status_msg'])
192
+ end
193
+
194
+ def map_address(address)
195
+ return {} if address.nil?
196
+ requires!(address, :name, :address1, :city, :zip, :country)
197
+ mapped = {
198
+ :name => address[:name],
199
+ :street => address[:address1],
200
+ :city => address[:city],
201
+ :region => address[:address2],
202
+ :zip_code => address[:zip],
203
+ :country_code => address[:country]
204
+ }
205
+ mapped
206
+ end
207
+
208
+ def headers
209
+ auth = Base64.strict_encode64(":#{@options[:api_key]}")
210
+ {
211
+ "Authorization" => "Basic " + auth,
212
+ "User-Agent" => "Quickpay-v#{API_VERSION} ActiveMerchantBindings/#{ActiveMerchant::VERSION}",
213
+ "Accept" => "application/json",
214
+ "Accept-Version" => "v#{API_VERSION}",
215
+ "Content-Type" => "application/json"
216
+ }
217
+ end
218
+
219
+ def response_error(raw_response)
220
+ begin
221
+ parse(raw_response)
222
+ rescue JSON::ParserError
223
+ json_error(raw_response)
224
+ end
225
+ end
226
+
227
+ def json_error(raw_response)
228
+ msg = 'Invalid response received from the Quickpay API.'
229
+ msg += " (The raw response returned by the API was #{raw_response.inspect})"
230
+ { "message" => msg }
231
+ end
232
+
233
+ def synchronized_path(path)
234
+ "#{path}?synchronized"
235
+ end
236
+
237
+ end
238
+
239
+ end
240
+ end
@@ -0,0 +1,227 @@
1
+ require 'rexml/document'
2
+ require 'digest/md5'
3
+ require 'active_merchant/billing/gateways/quickpay/quickpay_common'
4
+
5
+ module ActiveMerchant #:nodoc:
6
+ module Billing #:nodoc:
7
+ class QuickpayV4to7Gateway < Gateway
8
+ include QuickpayCommon
9
+ self.live_url = self.test_url = 'https://secure.quickpay.dk/api'
10
+ APPROVED = '000'
11
+
12
+ # The login is the QuickpayId
13
+ # The password is the md5checkword from the Quickpay manager
14
+ # To use the API-key from the Quickpay manager, specify :api-key
15
+ # Using the API-key, requires that you use version 4+. Specify :version => 4/5/6/7 in options.
16
+ def initialize(options = {})
17
+ requires!(options, :login, :password)
18
+ @protocol = options.delete(:version) || 7 # default to protocol version 7
19
+ super
20
+ end
21
+
22
+ def authorize(money, credit_card_or_reference, options = {})
23
+ post = {}
24
+
25
+ action = recurring_or_authorize(credit_card_or_reference)
26
+
27
+ add_amount(post, money, options)
28
+ add_invoice(post, options)
29
+ add_creditcard_or_reference(post, credit_card_or_reference, options)
30
+ add_autocapture(post, false)
31
+ add_fraud_parameters(post, options) if action.eql?(:authorize)
32
+ add_testmode(post)
33
+
34
+ commit(action, post)
35
+ end
36
+
37
+ def purchase(money, credit_card_or_reference, options = {})
38
+ post = {}
39
+
40
+ action = recurring_or_authorize(credit_card_or_reference)
41
+
42
+ add_amount(post, money, options)
43
+ add_creditcard_or_reference(post, credit_card_or_reference, options)
44
+ add_invoice(post, options)
45
+ add_fraud_parameters(post, options) if action.eql?(:authorize)
46
+ add_autocapture(post, true)
47
+
48
+ commit(action, post)
49
+ end
50
+
51
+ def capture(money, authorization, options = {})
52
+ post = {}
53
+
54
+ add_finalize(post, options)
55
+ add_reference(post, authorization)
56
+ add_amount_without_currency(post, money)
57
+ commit(:capture, post)
58
+ end
59
+
60
+ def void(identification, options = {})
61
+ post = {}
62
+
63
+ add_reference(post, identification)
64
+
65
+ commit(:cancel, post)
66
+ end
67
+
68
+ def refund(money, identification, options = {})
69
+ post = {}
70
+
71
+ add_amount_without_currency(post, money)
72
+ add_reference(post, identification)
73
+
74
+ commit(:refund, post)
75
+ end
76
+
77
+ def credit(money, identification, options = {})
78
+ ActiveMerchant.deprecated CREDIT_DEPRECATION_MESSAGE
79
+ refund(money, identification, options)
80
+ end
81
+
82
+ def store(creditcard, options = {})
83
+ post = {}
84
+
85
+ add_creditcard(post, creditcard, options)
86
+ add_amount(post, 0, options) if @protocol >= 7
87
+ add_invoice(post, options)
88
+ add_description(post, options)
89
+ add_fraud_parameters(post, options)
90
+ add_testmode(post)
91
+
92
+ commit(:subscribe, post)
93
+ end
94
+
95
+ private
96
+
97
+ def add_amount(post, money, options = {})
98
+ post[:amount] = amount(money)
99
+ post[:currency] = options[:currency] || currency(money)
100
+ end
101
+
102
+ def add_amount_without_currency(post, money, options = {})
103
+ post[:amount] = amount(money)
104
+ end
105
+
106
+ def add_invoice(post, options)
107
+ post[:ordernumber] = format_order_number(options[:order_id])
108
+ end
109
+
110
+ def add_creditcard(post, credit_card, options)
111
+ post[:cardnumber] = credit_card.number
112
+ post[:cvd] = credit_card.verification_value
113
+ post[:expirationdate] = expdate(credit_card)
114
+ post[:cardtypelock] = options[:cardtypelock] unless options[:cardtypelock].blank?
115
+ post[:acquirers] = options[:acquirers] unless options[:acquirers].blank?
116
+ end
117
+
118
+ def add_reference(post, identification)
119
+ post[:transaction] = identification
120
+ end
121
+
122
+ def add_creditcard_or_reference(post, credit_card_or_reference, options)
123
+ if credit_card_or_reference.is_a?(String)
124
+ add_reference(post, credit_card_or_reference)
125
+ else
126
+ add_creditcard(post, credit_card_or_reference, options)
127
+ end
128
+ end
129
+
130
+ def add_autocapture(post, autocapture)
131
+ post[:autocapture] = autocapture ? 1 : 0
132
+ end
133
+
134
+ def recurring_or_authorize(credit_card_or_reference)
135
+ credit_card_or_reference.is_a?(String) ? :recurring : :authorize
136
+ end
137
+
138
+ def add_description(post, options)
139
+ post[:description] = options[:description]
140
+ end
141
+
142
+ def add_testmode(post)
143
+ return if post[:transaction].present?
144
+ post[:testmode] = test? ? '1' : '0'
145
+ end
146
+
147
+ def add_fraud_parameters(post, options)
148
+ if @protocol >= 4
149
+ post[:fraud_remote_addr] = options[:ip] if options[:ip]
150
+ post[:fraud_http_accept] = options[:fraud_http_accept] if options[:fraud_http_accept]
151
+ post[:fraud_http_accept_language] = options[:fraud_http_accept_language] if options[:fraud_http_accept_language]
152
+ post[:fraud_http_accept_encoding] = options[:fraud_http_accept_encoding] if options[:fraud_http_accept_encoding]
153
+ post[:fraud_http_accept_charset] = options[:fraud_http_accept_charset] if options[:fraud_http_accept_charset]
154
+ post[:fraud_http_referer] = options[:fraud_http_referer] if options[:fraud_http_referer]
155
+ post[:fraud_http_user_agent] = options[:fraud_http_user_agent] if options[:fraud_http_user_agent]
156
+ end
157
+ end
158
+
159
+ def add_finalize(post, options)
160
+ post[:finalize] = options[:finalize] ? '1' : '0'
161
+ end
162
+
163
+ def commit(action, params)
164
+ response = parse(ssl_post(self.live_url, post_data(action, params)))
165
+
166
+ Response.new(successful?(response), message_from(response), response,
167
+ :test => test?,
168
+ :authorization => response[:transaction]
169
+ )
170
+ end
171
+
172
+ def successful?(response)
173
+ response[:qpstat] == APPROVED
174
+ end
175
+
176
+ def parse(data)
177
+ response = {}
178
+
179
+ doc = REXML::Document.new(data)
180
+
181
+ doc.root.elements.each do |element|
182
+ response[element.name.to_sym] = element.text
183
+ end
184
+
185
+ response
186
+ end
187
+
188
+ def message_from(response)
189
+ response[:qpstatmsg].to_s
190
+ end
191
+
192
+ def post_data(action, params = {})
193
+ params[:protocol] = @protocol
194
+ params[:msgtype] = action.to_s
195
+ params[:merchant] = @options[:login]
196
+ params[:apikey] = @options[:apikey] if @options[:apikey]
197
+ params[:md5check] = generate_check_hash(action, params)
198
+
199
+ params.collect { |key, value| "#{key}=#{CGI.escape(value.to_s)}" }.join("&")
200
+ end
201
+
202
+ def generate_check_hash(action, params)
203
+ string = MD5_CHECK_FIELDS[@protocol][action].collect do |key|
204
+ params[key.to_sym]
205
+ end.join('')
206
+
207
+ # Add the md5checkword
208
+ string << @options[:password].to_s
209
+
210
+ Digest::MD5.hexdigest(string)
211
+ end
212
+
213
+ def expdate(credit_card)
214
+ year = format(credit_card.year, :two_digits)
215
+ month = format(credit_card.month, :two_digits)
216
+
217
+ "#{year}#{month}"
218
+ end
219
+
220
+ # Limited to 20 digits max
221
+ def format_order_number(number)
222
+ number.to_s.gsub(/[^\w]/, '').rjust(4, "0")[0...20]
223
+ end
224
+ end
225
+ end
226
+ end
227
+