jelaniharris-activemerchant 1.24.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (219) hide show
  1. data/CHANGELOG +893 -0
  2. data/CONTRIBUTORS +307 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.md +196 -0
  5. data/gem-public_cert.pem +20 -0
  6. data/lib/active_merchant.rb +63 -0
  7. data/lib/active_merchant/billing.rb +9 -0
  8. data/lib/active_merchant/billing/avs_result.rb +98 -0
  9. data/lib/active_merchant/billing/base.rb +57 -0
  10. data/lib/active_merchant/billing/check.rb +68 -0
  11. data/lib/active_merchant/billing/credit_card.rb +274 -0
  12. data/lib/active_merchant/billing/credit_card_formatting.rb +21 -0
  13. data/lib/active_merchant/billing/credit_card_methods.rb +143 -0
  14. data/lib/active_merchant/billing/cvv_result.rb +38 -0
  15. data/lib/active_merchant/billing/expiry_date.rb +34 -0
  16. data/lib/active_merchant/billing/gateway.rb +170 -0
  17. data/lib/active_merchant/billing/gateways.rb +18 -0
  18. data/lib/active_merchant/billing/gateways/authorize_net.rb +694 -0
  19. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +946 -0
  20. data/lib/active_merchant/billing/gateways/barclays_epdq.rb +308 -0
  21. data/lib/active_merchant/billing/gateways/beanstream.rb +167 -0
  22. data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +388 -0
  23. data/lib/active_merchant/billing/gateways/beanstream_interac.rb +54 -0
  24. data/lib/active_merchant/billing/gateways/blue_pay.rb +492 -0
  25. data/lib/active_merchant/billing/gateways/bogus.rb +142 -0
  26. data/lib/active_merchant/billing/gateways/braintree.rb +17 -0
  27. data/lib/active_merchant/billing/gateways/braintree/braintree_common.rb +9 -0
  28. data/lib/active_merchant/billing/gateways/braintree_blue.rb +335 -0
  29. data/lib/active_merchant/billing/gateways/braintree_orange.rb +21 -0
  30. data/lib/active_merchant/billing/gateways/card_save.rb +23 -0
  31. data/lib/active_merchant/billing/gateways/card_stream.rb +230 -0
  32. data/lib/active_merchant/billing/gateways/certo_direct.rb +279 -0
  33. data/lib/active_merchant/billing/gateways/cyber_source.rb +430 -0
  34. data/lib/active_merchant/billing/gateways/data_cash.rb +597 -0
  35. data/lib/active_merchant/billing/gateways/efsnet.rb +235 -0
  36. data/lib/active_merchant/billing/gateways/elavon.rb +137 -0
  37. data/lib/active_merchant/billing/gateways/epay.rb +276 -0
  38. data/lib/active_merchant/billing/gateways/eway.rb +277 -0
  39. data/lib/active_merchant/billing/gateways/eway_managed.rb +265 -0
  40. data/lib/active_merchant/billing/gateways/exact.rb +227 -0
  41. data/lib/active_merchant/billing/gateways/federated_canada.rb +168 -0
  42. data/lib/active_merchant/billing/gateways/first_pay.rb +177 -0
  43. data/lib/active_merchant/billing/gateways/garanti.rb +262 -0
  44. data/lib/active_merchant/billing/gateways/ideal/ideal_base.rb +250 -0
  45. data/lib/active_merchant/billing/gateways/ideal/ideal_rabobank.pem +13 -0
  46. data/lib/active_merchant/billing/gateways/ideal/ideal_response.rb +29 -0
  47. data/lib/active_merchant/billing/gateways/ideal_rabobank.rb +55 -0
  48. data/lib/active_merchant/billing/gateways/inspire.rb +221 -0
  49. data/lib/active_merchant/billing/gateways/instapay.rb +164 -0
  50. data/lib/active_merchant/billing/gateways/iridium.rb +258 -0
  51. data/lib/active_merchant/billing/gateways/itransact.rb +450 -0
  52. data/lib/active_merchant/billing/gateways/jetpay.rb +276 -0
  53. data/lib/active_merchant/billing/gateways/linkpoint.rb +454 -0
  54. data/lib/active_merchant/billing/gateways/litle.rb +275 -0
  55. data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +157 -0
  56. data/lib/active_merchant/billing/gateways/merchant_ware.rb +289 -0
  57. data/lib/active_merchant/billing/gateways/migs.rb +259 -0
  58. data/lib/active_merchant/billing/gateways/migs/migs_codes.rb +100 -0
  59. data/lib/active_merchant/billing/gateways/modern_payments.rb +36 -0
  60. data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +220 -0
  61. data/lib/active_merchant/billing/gateways/moneris.rb +250 -0
  62. data/lib/active_merchant/billing/gateways/moneris_us.rb +211 -0
  63. data/lib/active_merchant/billing/gateways/nab_transact.rb +255 -0
  64. data/lib/active_merchant/billing/gateways/net_registry.rb +189 -0
  65. data/lib/active_merchant/billing/gateways/netaxept.rb +239 -0
  66. data/lib/active_merchant/billing/gateways/netbilling.rb +168 -0
  67. data/lib/active_merchant/billing/gateways/nmi.rb +13 -0
  68. data/lib/active_merchant/billing/gateways/ogone.rb +422 -0
  69. data/lib/active_merchant/billing/gateways/optimal_payment.rb +277 -0
  70. data/lib/active_merchant/billing/gateways/orbital.rb +353 -0
  71. data/lib/active_merchant/billing/gateways/orbital/orbital_soft_descriptors.rb +46 -0
  72. data/lib/active_merchant/billing/gateways/pay_junction.rb +397 -0
  73. data/lib/active_merchant/billing/gateways/pay_secure.rb +120 -0
  74. data/lib/active_merchant/billing/gateways/paybox_direct.rb +199 -0
  75. data/lib/active_merchant/billing/gateways/payflow.rb +266 -0
  76. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +211 -0
  77. data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +39 -0
  78. data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +13 -0
  79. data/lib/active_merchant/billing/gateways/payflow_express.rb +224 -0
  80. data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +15 -0
  81. data/lib/active_merchant/billing/gateways/payflow_uk.rb +21 -0
  82. data/lib/active_merchant/billing/gateways/payment_express.rb +282 -0
  83. data/lib/active_merchant/billing/gateways/paypal.rb +106 -0
  84. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +640 -0
  85. data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +49 -0
  86. data/lib/active_merchant/billing/gateways/paypal/paypal_recurring_api.rb +245 -0
  87. data/lib/active_merchant/billing/gateways/paypal_ca.rb +13 -0
  88. data/lib/active_merchant/billing/gateways/paypal_digital_goods.rb +43 -0
  89. data/lib/active_merchant/billing/gateways/paypal_express.rb +178 -0
  90. data/lib/active_merchant/billing/gateways/paypal_express_common.rb +30 -0
  91. data/lib/active_merchant/billing/gateways/paystation.rb +201 -0
  92. data/lib/active_merchant/billing/gateways/plugnpay.rb +298 -0
  93. data/lib/active_merchant/billing/gateways/psigate.rb +219 -0
  94. data/lib/active_merchant/billing/gateways/psl_card.rb +304 -0
  95. data/lib/active_merchant/billing/gateways/qbms.rb +297 -0
  96. data/lib/active_merchant/billing/gateways/quantum.rb +282 -0
  97. data/lib/active_merchant/billing/gateways/quickpay.rb +298 -0
  98. data/lib/active_merchant/billing/gateways/realex.rb +313 -0
  99. data/lib/active_merchant/billing/gateways/sage.rb +146 -0
  100. data/lib/active_merchant/billing/gateways/sage/sage_bankcard.rb +88 -0
  101. data/lib/active_merchant/billing/gateways/sage/sage_core.rb +116 -0
  102. data/lib/active_merchant/billing/gateways/sage/sage_virtual_check.rb +97 -0
  103. data/lib/active_merchant/billing/gateways/sage_pay.rb +320 -0
  104. data/lib/active_merchant/billing/gateways/sallie_mae.rb +144 -0
  105. data/lib/active_merchant/billing/gateways/samurai.rb +121 -0
  106. data/lib/active_merchant/billing/gateways/secure_net.rb +330 -0
  107. data/lib/active_merchant/billing/gateways/secure_pay.rb +31 -0
  108. data/lib/active_merchant/billing/gateways/secure_pay_au.rb +281 -0
  109. data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +113 -0
  110. data/lib/active_merchant/billing/gateways/skip_jack.rb +458 -0
  111. data/lib/active_merchant/billing/gateways/smart_ps.rb +271 -0
  112. data/lib/active_merchant/billing/gateways/stripe.rb +236 -0
  113. data/lib/active_merchant/billing/gateways/trans_first.rb +127 -0
  114. data/lib/active_merchant/billing/gateways/transax.rb +25 -0
  115. data/lib/active_merchant/billing/gateways/trust_commerce.rb +437 -0
  116. data/lib/active_merchant/billing/gateways/usa_epay.rb +23 -0
  117. data/lib/active_merchant/billing/gateways/usa_epay_advanced.rb +1496 -0
  118. data/lib/active_merchant/billing/gateways/usa_epay_transaction.rb +202 -0
  119. data/lib/active_merchant/billing/gateways/verifi.rb +233 -0
  120. data/lib/active_merchant/billing/gateways/viaklix.rb +194 -0
  121. data/lib/active_merchant/billing/gateways/vindicia.rb +359 -0
  122. data/lib/active_merchant/billing/gateways/wirecard.rb +318 -0
  123. data/lib/active_merchant/billing/gateways/worldpay.rb +280 -0
  124. data/lib/active_merchant/billing/integrations.rb +17 -0
  125. data/lib/active_merchant/billing/integrations/action_view_helper.rb +72 -0
  126. data/lib/active_merchant/billing/integrations/authorize_net_sim.rb +38 -0
  127. data/lib/active_merchant/billing/integrations/authorize_net_sim/helper.rb +228 -0
  128. data/lib/active_merchant/billing/integrations/authorize_net_sim/notification.rb +340 -0
  129. data/lib/active_merchant/billing/integrations/bogus.rb +23 -0
  130. data/lib/active_merchant/billing/integrations/bogus/helper.rb +17 -0
  131. data/lib/active_merchant/billing/integrations/bogus/notification.rb +11 -0
  132. data/lib/active_merchant/billing/integrations/bogus/return.rb +10 -0
  133. data/lib/active_merchant/billing/integrations/chronopay.rb +23 -0
  134. data/lib/active_merchant/billing/integrations/chronopay/helper.rb +120 -0
  135. data/lib/active_merchant/billing/integrations/chronopay/notification.rb +158 -0
  136. data/lib/active_merchant/billing/integrations/chronopay/return.rb +10 -0
  137. data/lib/active_merchant/billing/integrations/direc_pay.rb +41 -0
  138. data/lib/active_merchant/billing/integrations/direc_pay/helper.rb +200 -0
  139. data/lib/active_merchant/billing/integrations/direc_pay/notification.rb +76 -0
  140. data/lib/active_merchant/billing/integrations/direc_pay/return.rb +32 -0
  141. data/lib/active_merchant/billing/integrations/direc_pay/status.rb +37 -0
  142. data/lib/active_merchant/billing/integrations/directebanking.rb +47 -0
  143. data/lib/active_merchant/billing/integrations/directebanking/helper.rb +90 -0
  144. data/lib/active_merchant/billing/integrations/directebanking/notification.rb +120 -0
  145. data/lib/active_merchant/billing/integrations/directebanking/return.rb +11 -0
  146. data/lib/active_merchant/billing/integrations/dotpay.rb +22 -0
  147. data/lib/active_merchant/billing/integrations/dotpay/helper.rb +77 -0
  148. data/lib/active_merchant/billing/integrations/dotpay/notification.rb +86 -0
  149. data/lib/active_merchant/billing/integrations/dotpay/return.rb +11 -0
  150. data/lib/active_merchant/billing/integrations/dwolla.rb +30 -0
  151. data/lib/active_merchant/billing/integrations/dwolla/helper.rb +31 -0
  152. data/lib/active_merchant/billing/integrations/dwolla/notification.rb +55 -0
  153. data/lib/active_merchant/billing/integrations/dwolla/return.rb +38 -0
  154. data/lib/active_merchant/billing/integrations/e_payment_plans.rb +48 -0
  155. data/lib/active_merchant/billing/integrations/e_payment_plans/helper.rb +34 -0
  156. data/lib/active_merchant/billing/integrations/e_payment_plans/notification.rb +84 -0
  157. data/lib/active_merchant/billing/integrations/epay.rb +21 -0
  158. data/lib/active_merchant/billing/integrations/epay/helper.rb +55 -0
  159. data/lib/active_merchant/billing/integrations/epay/notification.rb +110 -0
  160. data/lib/active_merchant/billing/integrations/gestpay.rb +25 -0
  161. data/lib/active_merchant/billing/integrations/gestpay/common.rb +42 -0
  162. data/lib/active_merchant/billing/integrations/gestpay/helper.rb +70 -0
  163. data/lib/active_merchant/billing/integrations/gestpay/notification.rb +85 -0
  164. data/lib/active_merchant/billing/integrations/gestpay/return.rb +10 -0
  165. data/lib/active_merchant/billing/integrations/helper.rb +113 -0
  166. data/lib/active_merchant/billing/integrations/hi_trust.rb +27 -0
  167. data/lib/active_merchant/billing/integrations/hi_trust/helper.rb +58 -0
  168. data/lib/active_merchant/billing/integrations/hi_trust/notification.rb +59 -0
  169. data/lib/active_merchant/billing/integrations/hi_trust/return.rb +67 -0
  170. data/lib/active_merchant/billing/integrations/moneybookers.rb +26 -0
  171. data/lib/active_merchant/billing/integrations/moneybookers/helper.rb +59 -0
  172. data/lib/active_merchant/billing/integrations/moneybookers/notification.rb +129 -0
  173. data/lib/active_merchant/billing/integrations/nochex.rb +88 -0
  174. data/lib/active_merchant/billing/integrations/nochex/helper.rb +68 -0
  175. data/lib/active_merchant/billing/integrations/nochex/notification.rb +94 -0
  176. data/lib/active_merchant/billing/integrations/nochex/return.rb +10 -0
  177. data/lib/active_merchant/billing/integrations/notification.rb +62 -0
  178. data/lib/active_merchant/billing/integrations/payflow_link.rb +21 -0
  179. data/lib/active_merchant/billing/integrations/payflow_link/helper.rb +100 -0
  180. data/lib/active_merchant/billing/integrations/payflow_link/notification.rb +78 -0
  181. data/lib/active_merchant/billing/integrations/paypal.rb +39 -0
  182. data/lib/active_merchant/billing/integrations/paypal/helper.rb +119 -0
  183. data/lib/active_merchant/billing/integrations/paypal/notification.rb +155 -0
  184. data/lib/active_merchant/billing/integrations/paypal/return.rb +10 -0
  185. data/lib/active_merchant/billing/integrations/quickpay.rb +21 -0
  186. data/lib/active_merchant/billing/integrations/quickpay/helper.rb +71 -0
  187. data/lib/active_merchant/billing/integrations/quickpay/notification.rb +74 -0
  188. data/lib/active_merchant/billing/integrations/return.rb +42 -0
  189. data/lib/active_merchant/billing/integrations/robokassa.rb +49 -0
  190. data/lib/active_merchant/billing/integrations/robokassa/common.rb +19 -0
  191. data/lib/active_merchant/billing/integrations/robokassa/helper.rb +50 -0
  192. data/lib/active_merchant/billing/integrations/robokassa/notification.rb +55 -0
  193. data/lib/active_merchant/billing/integrations/robokassa/return.rb +17 -0
  194. data/lib/active_merchant/billing/integrations/sage_pay_form.rb +37 -0
  195. data/lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb +33 -0
  196. data/lib/active_merchant/billing/integrations/sage_pay_form/helper.rb +129 -0
  197. data/lib/active_merchant/billing/integrations/sage_pay_form/notification.rb +210 -0
  198. data/lib/active_merchant/billing/integrations/sage_pay_form/return.rb +31 -0
  199. data/lib/active_merchant/billing/integrations/two_checkout.rb +44 -0
  200. data/lib/active_merchant/billing/integrations/two_checkout/helper.rb +91 -0
  201. data/lib/active_merchant/billing/integrations/two_checkout/notification.rb +139 -0
  202. data/lib/active_merchant/billing/integrations/two_checkout/return.rb +17 -0
  203. data/lib/active_merchant/billing/integrations/valitor.rb +33 -0
  204. data/lib/active_merchant/billing/integrations/valitor/helper.rb +86 -0
  205. data/lib/active_merchant/billing/integrations/valitor/notification.rb +13 -0
  206. data/lib/active_merchant/billing/integrations/valitor/response_fields.rb +97 -0
  207. data/lib/active_merchant/billing/integrations/valitor/return.rb +13 -0
  208. data/lib/active_merchant/billing/integrations/verkkomaksut.rb +20 -0
  209. data/lib/active_merchant/billing/integrations/verkkomaksut/helper.rb +87 -0
  210. data/lib/active_merchant/billing/integrations/verkkomaksut/notification.rb +59 -0
  211. data/lib/active_merchant/billing/integrations/world_pay.rb +27 -0
  212. data/lib/active_merchant/billing/integrations/world_pay/helper.rb +100 -0
  213. data/lib/active_merchant/billing/integrations/world_pay/notification.rb +160 -0
  214. data/lib/active_merchant/billing/response.rb +32 -0
  215. data/lib/active_merchant/version.rb +3 -0
  216. data/lib/activemerchant.rb +1 -0
  217. data/lib/support/gateway_support.rb +58 -0
  218. data/lib/support/outbound_hosts.rb +25 -0
  219. metadata +447 -0
@@ -0,0 +1,298 @@
1
+ require 'rexml/document'
2
+ require 'digest/md5'
3
+
4
+ module ActiveMerchant #:nodoc:
5
+ module Billing #:nodoc:
6
+ class QuickpayGateway < Gateway
7
+ URL = 'https://secure.quickpay.dk/api'
8
+
9
+ self.default_currency = 'DKK'
10
+ self.money_format = :cents
11
+ self.supported_cardtypes = [:dankort, :forbrugsforeningen, :visa, :master, :american_express, :diners_club, :jcb, :maestro]
12
+ self.supported_countries = ['DK', 'SE']
13
+ self.homepage_url = 'http://quickpay.dk/'
14
+ self.display_name = 'Quickpay'
15
+
16
+ MD5_CHECK_FIELDS = {
17
+ 3 => {
18
+ :authorize => %w(protocol msgtype merchant ordernumber amount
19
+ currency autocapture cardnumber expirationdate
20
+ cvd cardtypelock testmode),
21
+
22
+ :capture => %w(protocol msgtype merchant amount transaction),
23
+
24
+ :cancel => %w(protocol msgtype merchant transaction),
25
+
26
+ :refund => %w(protocol msgtype merchant amount transaction),
27
+
28
+ :subscribe => %w(protocol msgtype merchant ordernumber cardnumber
29
+ expirationdate cvd cardtypelock description testmode),
30
+
31
+ :recurring => %w(protocol msgtype merchant ordernumber amount
32
+ currency autocapture transaction),
33
+
34
+ :status => %w(protocol msgtype merchant transaction),
35
+
36
+ :chstatus => %w(protocol msgtype merchant)
37
+ },
38
+
39
+ 4 => {
40
+ :authorize => %w(protocol msgtype merchant ordernumber amount
41
+ currency autocapture cardnumber expirationdate cvd
42
+ cardtypelock testmode fraud_remote_addr
43
+ fraud_http_accept fraud_http_accept_language
44
+ fraud_http_accept_encoding fraud_http_accept_charset
45
+ fraud_http_referer fraud_http_user_agent apikey),
46
+
47
+ :capture => %w(protocol msgtype merchant amount transaction
48
+ fraud_remote_addr fraud_http_accept
49
+ fraud_http_accept_language fraud_http_accept_encoding
50
+ fraud_http_accept_charset fraud_http_referer
51
+ fraud_http_user_agent apikey),
52
+
53
+ :cancel => %w(protocol msgtype merchant transaction fraud_remote_addr
54
+ fraud_http_accept fraud_http_accept_language
55
+ fraud_http_accept_encoding fraud_http_accept_charset
56
+ fraud_http_referer fraud_http_user_agent apikey),
57
+
58
+ :refund => %w(protocol msgtype merchant amount transaction
59
+ fraud_remote_addr fraud_http_accept fraud_http_accept_language
60
+ fraud_http_accept_encoding fraud_http_accept_charset
61
+ fraud_http_referer fraud_http_user_agent apikey),
62
+
63
+ :subscribe => %w(protocol msgtype merchant ordernumber cardnumber
64
+ expirationdate cvd cardtypelock description testmode
65
+ fraud_remote_addr fraud_http_accept fraud_http_accept_language
66
+ fraud_http_accept_encoding fraud_http_accept_charset
67
+ fraud_http_referer fraud_http_user_agent apikey),
68
+
69
+ :recurring => %w(protocol msgtype merchant ordernumber amount currency
70
+ autocapture transaction fraud_remote_addr fraud_http_accept
71
+ fraud_http_accept_language fraud_http_accept_encoding
72
+ fraud_http_accept_charset fraud_http_referer
73
+ fraud_http_user_agent apikey),
74
+
75
+ :status => %w(protocol msgtype merchant transaction fraud_remote_addr
76
+ fraud_http_accept fraud_http_accept_language
77
+ fraud_http_accept_encoding fraud_http_accept_charset
78
+ fraud_http_referer fraud_http_user_agent apikey),
79
+
80
+ :chstatus => %w(protocol msgtype merchant fraud_remote_addr fraud_http_accept
81
+ fraud_http_accept_language fraud_http_accept_encoding
82
+ fraud_http_accept_charset fraud_http_referer
83
+ fraud_http_user_agent apikey)
84
+ }
85
+ }
86
+
87
+ APPROVED = '000'
88
+
89
+ # The login is the QuickpayId
90
+ # The password is the md5checkword from the Quickpay manager
91
+ # To use the API-key from the Quickpay manager, specify :api-key
92
+ # Using the API-key, requires that you use version 4. Specify :version => 4 in options.
93
+ def initialize(options = {})
94
+ requires!(options, :login, :password)
95
+ @protocol = options.delete(:version) || 3 # default to protocol version 3
96
+ @options = options
97
+ super
98
+ end
99
+
100
+ def authorize(money, credit_card_or_reference, options = {})
101
+ post = {}
102
+
103
+ add_amount(post, money, options)
104
+ add_invoice(post, options)
105
+ add_creditcard_or_reference(post, credit_card_or_reference, options)
106
+ add_autocapture(post, false)
107
+ add_fraud_parameters(post, options)
108
+ add_testmode(post)
109
+
110
+ commit(recurring_or_authorize(credit_card_or_reference), post)
111
+ end
112
+
113
+ def purchase(money, credit_card_or_reference, options = {})
114
+ post = {}
115
+
116
+ add_amount(post, money, options)
117
+ add_creditcard_or_reference(post, credit_card_or_reference, options)
118
+ add_invoice(post, options)
119
+ add_fraud_parameters(post, options)
120
+ add_autocapture(post, true)
121
+
122
+ commit(recurring_or_authorize(credit_card_or_reference), post)
123
+ end
124
+
125
+ def capture(money, authorization, options = {})
126
+ post = {}
127
+
128
+ add_reference(post, authorization)
129
+ add_amount_without_currency(post, money)
130
+ add_fraud_parameters(post, options)
131
+
132
+ commit(:capture, post)
133
+ end
134
+
135
+ def void(identification, options = {})
136
+ post = {}
137
+
138
+ add_reference(post, identification)
139
+ add_fraud_parameters(post, options)
140
+
141
+ commit(:cancel, post)
142
+ end
143
+
144
+ def refund(money, identification, options = {})
145
+ post = {}
146
+
147
+ add_amount_without_currency(post, money)
148
+ add_reference(post, identification)
149
+ add_fraud_parameters(post, options)
150
+
151
+ commit(:refund, post)
152
+ end
153
+
154
+ def credit(money, identification, options = {})
155
+ deprecated CREDIT_DEPRECATION_MESSAGE
156
+ refund(money, identification, options)
157
+ end
158
+
159
+ def store(creditcard, options = {})
160
+ post = {}
161
+
162
+ add_creditcard(post, creditcard, options)
163
+ add_invoice(post, options)
164
+ add_description(post, options)
165
+ add_fraud_parameters(post, options)
166
+ add_testmode(post)
167
+
168
+ commit(:subscribe, post)
169
+ end
170
+
171
+ private
172
+
173
+ def add_amount(post, money, options = {})
174
+ post[:amount] = amount(money)
175
+ post[:currency] = options[:currency] || currency(money)
176
+ end
177
+
178
+ def add_amount_without_currency(post, money, options = {})
179
+ post[:amount] = amount(money)
180
+ end
181
+
182
+ def add_invoice(post, options)
183
+ post[:ordernumber] = format_order_number(options[:order_id])
184
+ end
185
+
186
+ def add_creditcard(post, credit_card, options)
187
+ post[:cardnumber] = credit_card.number
188
+ post[:cvd] = credit_card.verification_value
189
+ post[:expirationdate] = expdate(credit_card)
190
+ post[:cardtypelock] = options[:cardtypelock] unless options[:cardtypelock].blank?
191
+ end
192
+
193
+ def add_reference(post, identification)
194
+ post[:transaction] = identification
195
+ end
196
+
197
+ def add_creditcard_or_reference(post, credit_card_or_reference, options)
198
+ if credit_card_or_reference.is_a?(String)
199
+ add_reference(post, credit_card_or_reference)
200
+ else
201
+ add_creditcard(post, credit_card_or_reference, options)
202
+ end
203
+ end
204
+
205
+ def add_autocapture(post, autocapture)
206
+ post[:autocapture] = autocapture ? 1 : 0
207
+ end
208
+
209
+ def recurring_or_authorize(credit_card_or_reference)
210
+ credit_card_or_reference.is_a?(String) ? :recurring : :authorize
211
+ end
212
+
213
+ def add_description(post, options)
214
+ post[:description] = options[:description]
215
+ end
216
+
217
+ def add_testmode(post)
218
+ return if post[:transaction].present?
219
+ post[:testmode] = test? ? '1' : '0'
220
+ end
221
+
222
+ def add_fraud_parameters(post, options)
223
+ if @protocol == 4
224
+ post[:fraud_remote_addr] = options[:fraud_remote_addr] if options[:fraud_remote_addr]
225
+ post[:fraud_http_accept] = options[:fraud_http_accept] if options[:fraud_http_accept]
226
+ post[:fraud_http_accept_language] = options[:fraud_http_accept_language] if options[:fraud_http_accept_language]
227
+ post[:fraud_http_accept_encoding] = options[:fraud_http_accept_encoding] if options[:fraud_http_accept_encoding]
228
+ post[:fraud_http_accept_charset] = options[:fraud_http_accept_charset] if options[:fraud_http_accept_charset]
229
+ post[:fraud_http_referer] = options[:fraud_http_referer] if options[:fraud_http_referer]
230
+ post[:fraud_http_user_agent] = options[:fraud_http_user_agent] if options[:fraud_http_user_agent]
231
+ end
232
+ end
233
+
234
+ def commit(action, params)
235
+ response = parse(ssl_post(URL, post_data(action, params)))
236
+
237
+ Response.new(successful?(response), message_from(response), response,
238
+ :test => test?,
239
+ :authorization => response[:transaction]
240
+ )
241
+ end
242
+
243
+ def successful?(response)
244
+ response[:qpstat] == APPROVED
245
+ end
246
+
247
+ def parse(data)
248
+ response = {}
249
+
250
+ doc = REXML::Document.new(data)
251
+
252
+ doc.root.elements.each do |element|
253
+ response[element.name.to_sym] = element.text
254
+ end
255
+
256
+ response
257
+ end
258
+
259
+ def message_from(response)
260
+ response[:qpstatmsg].to_s
261
+ end
262
+
263
+ def post_data(action, params = {})
264
+ params[:protocol] = @protocol
265
+ params[:msgtype] = action.to_s
266
+ params[:merchant] = @options[:login]
267
+ params[:apikey] = @options[:apikey] if @options[:apikey]
268
+ params[:md5check] = generate_check_hash(action, params)
269
+
270
+ params.collect { |key, value| "#{key}=#{CGI.escape(value.to_s)}" }.join("&")
271
+ end
272
+
273
+ def generate_check_hash(action, params)
274
+ string = MD5_CHECK_FIELDS[@protocol][action].collect do |key|
275
+ params[key.to_sym]
276
+ end.join('')
277
+
278
+ # Add the md5checkword
279
+ string << @options[:password].to_s
280
+
281
+ Digest::MD5.hexdigest(string)
282
+ end
283
+
284
+ def expdate(credit_card)
285
+ year = format(credit_card.year, :two_digits)
286
+ month = format(credit_card.month, :two_digits)
287
+
288
+ "#{year}#{month}"
289
+ end
290
+
291
+ # Limited to 20 digits max
292
+ def format_order_number(number)
293
+ number.to_s.gsub(/[^\w_]/, '').rjust(4, "0")[0...20]
294
+ end
295
+ end
296
+ end
297
+ end
298
+
@@ -0,0 +1,313 @@
1
+ require 'nokogiri'
2
+ require 'digest/sha1'
3
+
4
+ module ActiveMerchant
5
+ module Billing
6
+ # Realex is the leading CC gateway in Ireland
7
+ # see http://www.realexpayments.com
8
+ # Contributed by John Ward (john@ward.name)
9
+ # see http://thinedgeofthewedge.blogspot.com
10
+ #
11
+ # Realex works using the following
12
+ # login - The unique id of the merchant
13
+ # password - The secret is used to digitally sign the request
14
+ # account - This is an optional third part of the authentication process
15
+ # and is used if the merchant wishes do distuinguish cc traffic from the different sources
16
+ # by using a different account. This must be created in advance
17
+ #
18
+ # the Realex team decided to make the orderid unique per request,
19
+ # so if validation fails you can not correct and resend using the
20
+ # same order id
21
+ class RealexGateway < Gateway
22
+ URL = 'https://epage.payandshop.com/epage-remote.cgi'
23
+
24
+ CARD_MAPPING = {
25
+ 'master' => 'MC',
26
+ 'visa' => 'VISA',
27
+ 'american_express' => 'AMEX',
28
+ 'diners_club' => 'DINERS',
29
+ 'switch' => 'SWITCH',
30
+ 'solo' => 'SWITCH',
31
+ 'laser' => 'LASER'
32
+ }
33
+
34
+ self.money_format = :cents
35
+ self.default_currency = 'EUR'
36
+ self.supported_cardtypes = [ :visa, :master, :american_express, :diners_club, :switch, :solo, :laser ]
37
+ self.supported_countries = [ 'IE', 'GB' ]
38
+ self.homepage_url = 'http://www.realexpayments.com/'
39
+ self.display_name = 'Realex'
40
+
41
+ SUCCESS, DECLINED = "Successful", "Declined"
42
+ BANK_ERROR = REALEX_ERROR = "Gateway is in maintenance. Please try again later."
43
+ ERROR = CLIENT_DEACTIVATED = "Gateway Error"
44
+
45
+ def initialize(options = {})
46
+ requires!(options, :login, :password)
47
+ options[:refund_hash] = Digest::SHA1.hexdigest(options[:rebate_secret]) if options.has_key?(:rebate_secret)
48
+ @options = options
49
+ super
50
+ end
51
+
52
+ def purchase(money, credit_card, options = {})
53
+ requires!(options, :order_id)
54
+
55
+ request = build_purchase_or_authorization_request(:purchase, money, credit_card, options)
56
+ commit(request)
57
+ end
58
+
59
+ def authorize(money, creditcard, options = {})
60
+ requires!(options, :order_id)
61
+
62
+ request = build_purchase_or_authorization_request(:authorization, money, creditcard, options)
63
+ commit(request)
64
+ end
65
+
66
+ def capture(money, authorization, options = {})
67
+ request = build_capture_request(authorization, options)
68
+ commit(request)
69
+ end
70
+
71
+ def refund(money, authorization, options = {})
72
+ request = build_refund_request(money, authorization, options)
73
+ commit(request)
74
+ end
75
+
76
+ def credit(money, authorization, options = {})
77
+ deprecated CREDIT_DEPRECATION_MESSAGE
78
+ refund(money, authorization, options)
79
+ end
80
+
81
+ def void(authorization, options = {})
82
+ request = build_void_request(authorization, options)
83
+ commit(request)
84
+ end
85
+
86
+ private
87
+ def commit(request)
88
+ response = parse(ssl_post(URL, request))
89
+
90
+ Response.new(response[:result] == "00", message_from(response), response,
91
+ :test => response[:message] =~ /\[ test system \]/,
92
+ :authorization => authorization_from(response),
93
+ :cvv_result => response[:cvnresult],
94
+ :avs_result => {
95
+ :street_match => response[:avspostcoderesponse],
96
+ :postal_match => response[:avspostcoderesponse]
97
+ }
98
+ )
99
+ end
100
+
101
+ def parse(xml)
102
+ response = {}
103
+
104
+ doc = Nokogiri::XML(xml)
105
+ doc.xpath('//response/*').each do |node|
106
+ if (node.elements.size == 0)
107
+ response[node.name.downcase.to_sym] = normalize(node.text)
108
+ else
109
+ node.elements.each do |childnode|
110
+ name = "#{node.name.downcase}_#{childnode.name.downcase}"
111
+ response[name.to_sym] = normalize(childnode.text)
112
+ end
113
+ end
114
+ end unless doc.root.nil?
115
+
116
+ response
117
+ end
118
+
119
+ def authorization_from(parsed)
120
+ [parsed[:orderid], parsed[:pasref], parsed[:authcode]].join(';')
121
+ end
122
+
123
+ def build_purchase_or_authorization_request(action, money, credit_card, options)
124
+ timestamp = new_timestamp
125
+ xml = Builder::XmlMarkup.new :indent => 2
126
+ xml.tag! 'request', 'timestamp' => timestamp, 'type' => 'auth' do
127
+ add_merchant_details(xml, options)
128
+ xml.tag! 'orderid', sanitize_order_id(options[:order_id])
129
+ add_amount(xml, money, options)
130
+ add_card(xml, credit_card)
131
+ xml.tag! 'autosettle', 'flag' => auto_settle_flag(action)
132
+ add_signed_digest(xml, timestamp, @options[:login], sanitize_order_id(options[:order_id]), amount(money), (options[:currency] || currency(money)), credit_card.number)
133
+ add_comments(xml, options)
134
+ add_address_and_customer_info(xml, options)
135
+ end
136
+ xml.target!
137
+ end
138
+
139
+ def build_capture_request(authorization, options)
140
+ timestamp = new_timestamp
141
+ xml = Builder::XmlMarkup.new :indent => 2
142
+ xml.tag! 'request', 'timestamp' => timestamp, 'type' => 'settle' do
143
+ add_merchant_details(xml, options)
144
+ add_transaction_identifiers(xml, authorization, options)
145
+ add_comments(xml, options)
146
+ add_signed_digest(xml, timestamp, @options[:login], sanitize_order_id(options[:order_id]), nil, nil, nil)
147
+ end
148
+ xml.target!
149
+ end
150
+
151
+ def build_refund_request(money, authorization, options)
152
+ timestamp = new_timestamp
153
+ xml = Builder::XmlMarkup.new :indent => 2
154
+ xml.tag! 'request', 'timestamp' => timestamp, 'type' => 'rebate' do
155
+ add_merchant_details(xml, options)
156
+ add_transaction_identifiers(xml, authorization, options)
157
+ xml.tag! 'amount', amount(money), 'currency' => options[:currency] || currency(money)
158
+ xml.tag! 'refundhash', @options[:refund_hash] if @options[:refund_hash]
159
+ xml.tag! 'autosettle', 'flag' => 1
160
+ add_comments(xml, options)
161
+ add_signed_digest(xml, timestamp, @options[:login], sanitize_order_id(options[:order_id]), amount(money), (options[:currency] || currency(money)), nil)
162
+ end
163
+ xml.target!
164
+ end
165
+
166
+ def build_void_request(authorization, options)
167
+ timestamp = new_timestamp
168
+ xml = Builder::XmlMarkup.new :indent => 2
169
+ xml.tag! 'request', 'timestamp' => timestamp, 'type' => 'void' do
170
+ add_merchant_details(xml, options)
171
+ add_transaction_identifiers(xml, authorization, options)
172
+ add_comments(xml, options)
173
+ add_signed_digest(xml, timestamp, @options[:login], sanitize_order_id(options[:order_id]), nil, nil, nil)
174
+ end
175
+ xml.target!
176
+ end
177
+
178
+ def add_address_and_customer_info(xml, options)
179
+ billing_address = options[:billing_address] || options[:address]
180
+ shipping_address = options[:shipping_address]
181
+
182
+ return unless billing_address || shipping_address || options[:customer] || options[:invoice] || options[:ip]
183
+
184
+ xml.tag! 'tssinfo' do
185
+ xml.tag! 'custnum', options[:customer] if options[:customer]
186
+ xml.tag! 'prodid', options[:invoice] if options[:invoice]
187
+ xml.tag! 'custipaddress', options[:ip] if options[:ip]
188
+
189
+ if billing_address
190
+ xml.tag! 'address', 'type' => 'billing' do
191
+ xml.tag! 'code', avs_input_code( billing_address )
192
+ xml.tag! 'country', billing_address[:country]
193
+ end
194
+ end
195
+
196
+ if shipping_address
197
+ xml.tag! 'address', 'type' => 'shipping' do
198
+ xml.tag! 'code', format_shipping_zip_code(shipping_address[:zip])
199
+ xml.tag! 'country', shipping_address[:country]
200
+ end
201
+ end
202
+ end
203
+ end
204
+
205
+ def add_merchant_details(xml, options)
206
+ xml.tag! 'merchantid', @options[:login]
207
+ if options[:account] || @options[:account]
208
+ xml.tag! 'account', (options[:account] || @options[:account])
209
+ end
210
+ end
211
+
212
+ def add_transaction_identifiers(xml, authorization, options)
213
+ options[:order_id], pasref, authcode = authorization.split(';')
214
+ xml.tag! 'orderid', sanitize_order_id(options[:order_id])
215
+ xml.tag! 'pasref', pasref
216
+ xml.tag! 'authcode', authcode
217
+ end
218
+
219
+ def add_comments(xml, options)
220
+ return unless options[:description]
221
+ xml.tag! 'comments' do
222
+ xml.tag! 'comment', options[:description], 'id' => 1
223
+ end
224
+ end
225
+
226
+ def add_amount(xml, money, options)
227
+ xml.tag! 'amount', amount(money), 'currency' => options[:currency] || currency(money)
228
+ end
229
+
230
+ def add_card(xml, credit_card)
231
+ xml.tag! 'card' do
232
+ xml.tag! 'number', credit_card.number
233
+ xml.tag! 'expdate', expiry_date(credit_card)
234
+ xml.tag! 'chname', credit_card.name
235
+ xml.tag! 'type', CARD_MAPPING[card_brand(credit_card).to_s]
236
+ xml.tag! 'issueno', credit_card.issue_number
237
+ xml.tag! 'cvn' do
238
+ xml.tag! 'number', credit_card.verification_value
239
+ xml.tag! 'presind', (options['presind'] || (credit_card.verification_value? ? 1 : nil))
240
+ end
241
+ end
242
+ end
243
+
244
+ def avs_input_code(address)
245
+ address.values_at(:zip, :address1).map{ |v| extract_digits(v) }.join('|')
246
+ end
247
+
248
+ def format_shipping_zip_code(zip)
249
+ zip.to_s.gsub(/\W/, '')
250
+ end
251
+
252
+ def extract_digits(string)
253
+ return "" if string.nil?
254
+ string.gsub(/[\D]/,'')
255
+ end
256
+
257
+ def new_timestamp
258
+ Time.now.strftime('%Y%m%d%H%M%S')
259
+ end
260
+
261
+ def add_signed_digest(xml, *values)
262
+ string = Digest::SHA1.hexdigest(values.join("."))
263
+ xml.tag! 'sha1hash', Digest::SHA1.hexdigest([string, @options[:password]].join("."))
264
+ end
265
+
266
+ def auto_settle_flag(action)
267
+ action == :authorization ? '0' : '1'
268
+ end
269
+
270
+ def expiry_date(credit_card)
271
+ "#{format(credit_card.month, :two_digits)}#{format(credit_card.year, :two_digits)}"
272
+ end
273
+
274
+ def normalize(field)
275
+ case field
276
+ when "true" then true
277
+ when "false" then false
278
+ when "" then nil
279
+ when "null" then nil
280
+ else field
281
+ end
282
+ end
283
+
284
+ def message_from(response)
285
+ message = nil
286
+ case response[:result]
287
+ when "00"
288
+ message = SUCCESS
289
+ when "101"
290
+ message = response[:message]
291
+ when "102", "103"
292
+ message = DECLINED
293
+ when /^2[0-9][0-9]/
294
+ message = BANK_ERROR
295
+ when /^3[0-9][0-9]/
296
+ message = REALEX_ERROR
297
+ when /^5[0-9][0-9]/
298
+ message = response[:message]
299
+ when "600", "601", "603"
300
+ message = ERROR
301
+ when "666"
302
+ message = CLIENT_DEACTIVATED
303
+ else
304
+ message = DECLINED
305
+ end
306
+ end
307
+
308
+ def sanitize_order_id(order_id)
309
+ order_id.to_s.gsub(/[^a-zA-Z0-9\-_]/, '')
310
+ end
311
+ end
312
+ end
313
+ end