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,274 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ class EpayGateway < Gateway
4
+ self.live_url = 'https://ssl.ditonlinebetalingssystem.dk/'
5
+
6
+ self.default_currency = 'DKK'
7
+ self.money_format = :cents
8
+ self.supported_cardtypes = [:dankort, :forbrugsforeningen, :visa, :master,
9
+ :american_express, :diners_club, :jcb, :maestro]
10
+ self.supported_countries = ['DK', 'SE', 'NO']
11
+ self.homepage_url = 'http://epay.dk/'
12
+ self.display_name = 'ePay'
13
+
14
+ CURRENCY_CODES = {
15
+ :ADP => '020', :AED => '784', :AFA => '004', :ALL => '008', :AMD => '051',
16
+ :ANG => '532', :AOA => '973', :ARS => '032', :AUD => '036', :AWG => '533',
17
+ :AZM => '031', :BAM => '977', :BBD => '052', :BDT => '050', :BGL => '100',
18
+ :BGN => '975', :BHD => '048', :BIF => '108', :BMD => '060', :BND => '096',
19
+ :BOB => '068', :BOV => '984', :BRL => '986', :BSD => '044', :BTN => '064',
20
+ :BWP => '072', :BYR => '974', :BZD => '084', :CAD => '124', :CDF => '976',
21
+ :CHF => '756', :CLF => '990', :CLP => '152', :CNY => '156', :COP => '170',
22
+ :CRC => '188', :CUP => '192', :CVE => '132', :CYP => '196', :CZK => '203',
23
+ :DJF => '262', :DKK => '208', :DOP => '214', :DZD => '012', :ECS => '218',
24
+ :ECV => '983', :EEK => '233', :EGP => '818', :ERN => '232', :ETB => '230',
25
+ :EUR => '978', :FJD => '242', :FKP => '238', :GBP => '826', :GEL => '981',
26
+ :GHC => '288', :GIP => '292', :GMD => '270', :GNF => '324', :GTQ => '320',
27
+ :GWP => '624', :GYD => '328', :HKD => '344', :HNL => '340', :HRK => '191',
28
+ :HTG => '332', :HUF => '348', :IDR => '360', :ILS => '376', :INR => '356',
29
+ :IQD => '368', :IRR => '364', :ISK => '352', :JMD => '388', :JOD => '400',
30
+ :JPY => '392', :KES => '404', :KGS => '417', :KHR => '116', :KMF => '174',
31
+ :KPW => '408', :KRW => '410', :KWD => '414', :KYD => '136', :KZT => '398',
32
+ :LAK => '418', :LBP => '422', :LKR => '144', :LRD => '430', :LSL => '426',
33
+ :LTL => '440', :LVL => '428', :LYD => '434', :MAD => '504', :MDL => '498',
34
+ :MGF => '450', :MKD => '807', :MMK => '104', :MNT => '496', :MOP => '446',
35
+ :MRO => '478', :MTL => '470', :MUR => '480', :MVR => '462', :MWK => '454',
36
+ :MXN => '484', :MXV => '979', :MYR => '458', :MZM => '508', :NAD => '516',
37
+ :NGN => '566', :NIO => '558', :NOK => '578', :NPR => '524', :NZD => '554',
38
+ :OMR => '512', :PAB => '590', :PEN => '604', :PGK => '598', :PHP => '608',
39
+ :PKR => '586', :PLN => '985', :PYG => '600', :QAR => '634', :ROL => '642',
40
+ :RUB => '643', :RUR => '810', :RWF => '646', :SAR => '682', :SBD => '090',
41
+ :SCR => '690', :SDD => '736', :SEK => '752', :SGD => '702', :SHP => '654',
42
+ :SIT => '705', :SKK => '703', :SLL => '694', :SOS => '706', :SRG => '740',
43
+ :STD => '678', :SVC => '222', :SYP => '760', :SZL => '748', :THB => '764',
44
+ :TJS => '972', :TMM => '795', :TND => '788', :TOP => '776', :TPE => '626',
45
+ :TRL => '792', :TRY => '949', :TTD => '780', :TWD => '901', :TZS => '834',
46
+ :UAH => '980', :UGX => '800', :USD => '840', :UYU => '858', :UZS => '860',
47
+ :VEB => '862', :VND => '704', :VUV => '548', :XAF => '950', :XCD => '951',
48
+ :XOF => '952', :XPF => '953', :YER => '886', :YUM => '891', :ZAR => '710',
49
+ :ZMK => '894', :ZWD => '716'
50
+ }
51
+
52
+ # login: merchant number
53
+ # password: referrer url (for authorize authentication)
54
+ def initialize(options = {})
55
+ requires!(options, :login)
56
+ super
57
+ end
58
+
59
+ def authorize(money, credit_card_or_reference, options = {})
60
+ post = {}
61
+
62
+ add_amount(post, money, options)
63
+ add_invoice(post, options)
64
+ add_creditcard_or_reference(post, credit_card_or_reference)
65
+ add_instant_capture(post, false)
66
+
67
+ commit(:authorize, post)
68
+ end
69
+
70
+ def purchase(money, credit_card_or_reference, options = {})
71
+ post = {}
72
+
73
+ add_amount(post, money, options)
74
+ add_creditcard_or_reference(post, credit_card_or_reference)
75
+ add_invoice(post, options)
76
+ add_instant_capture(post, true)
77
+
78
+ commit(:authorize, post)
79
+ end
80
+
81
+ def capture(money, authorization, options = {})
82
+ post = {}
83
+
84
+ add_reference(post, authorization)
85
+ add_amount_without_currency(post, money)
86
+
87
+ commit(:capture, post)
88
+ end
89
+
90
+ def void(identification, options = {})
91
+ post = {}
92
+
93
+ add_reference(post, identification)
94
+
95
+ commit(:void, post)
96
+ end
97
+
98
+ def refund(money, identification, options = {})
99
+ post = {}
100
+
101
+ add_amount_without_currency(post, money)
102
+ add_reference(post, identification)
103
+
104
+ commit(:credit, post)
105
+ end
106
+
107
+ def credit(money, identification, options = {})
108
+ ActiveMerchant.deprecated CREDIT_DEPRECATION_MESSAGE
109
+ refund(money, identification, options)
110
+ end
111
+
112
+ private
113
+
114
+ def add_amount(post, money, options)
115
+ post[:amount] = amount(money)
116
+ post[:currency] = CURRENCY_CODES[(options[:currency] || currency(money)).to_sym]
117
+ end
118
+
119
+ def add_amount_without_currency(post, money)
120
+ post[:amount] = amount(money)
121
+ end
122
+
123
+ def add_reference(post, identification)
124
+ post[:transaction] = identification
125
+ end
126
+
127
+ def add_invoice(post, options)
128
+ post[:orderid] = format_order_number(options[:order_id])
129
+ end
130
+
131
+ def add_creditcard(post, credit_card)
132
+ post[:cardno] = credit_card.number
133
+ post[:cvc] = credit_card.verification_value
134
+ post[:expmonth] = credit_card.month
135
+ post[:expyear] = credit_card.year
136
+ end
137
+
138
+ def add_creditcard_or_reference(post, credit_card_or_reference)
139
+ if credit_card_or_reference.respond_to?(:number)
140
+ add_creditcard(post, credit_card_or_reference)
141
+ else
142
+ add_reference(post, credit_card_or_reference.to_s)
143
+ end
144
+ end
145
+
146
+ def add_instant_capture(post, option)
147
+ post[:instantcapture] = option ? 1 : 0
148
+ end
149
+
150
+ def commit(action, params)
151
+ response = send("do_#{action}", params)
152
+
153
+ if action == :authorize
154
+ Response.new response['accept'].to_i == 1,
155
+ response['errortext'],
156
+ response,
157
+ :test => test?,
158
+ :authorization => response['tid']
159
+ else
160
+ Response.new response['result'] == 'true',
161
+ messages(response['epay'], response['pbs']),
162
+ response,
163
+ :test => test?,
164
+ :authorization => params[:transaction]
165
+ end
166
+ end
167
+
168
+ def messages(epay, pbs = nil)
169
+ response = "ePay: #{epay}"
170
+ response << " PBS: #{pbs}" if pbs
171
+ return response
172
+ end
173
+
174
+ def soap_post(method, params)
175
+ data = xml_builder(params, method)
176
+ headers = make_headers(data, method)
177
+ REXML::Document.new(ssl_post(live_url + 'remote/payment.asmx', data, headers))
178
+ end
179
+
180
+ def do_authorize(params)
181
+ headers = {}
182
+ headers['Referer'] = (options[:password] || "activemerchant.org")
183
+
184
+ response = raw_ssl_request(:post, live_url + 'auth/default.aspx', authorize_post_data(params), headers)
185
+
186
+ # Authorize gives the response back by redirecting with the values in
187
+ # the URL query
188
+ if location = response['Location']
189
+ query = CGI::parse(URI.parse(location.gsub(' ', '%20')).query)
190
+ else
191
+ return {
192
+ 'accept' => '0',
193
+ 'errortext' => 'ePay did not respond as expected. Please try again.',
194
+ 'response_code' => response.code,
195
+ 'response_message' => response.message
196
+ }
197
+ end
198
+
199
+ result = {}
200
+ query.each_pair do |k,v|
201
+ result[k] = v.is_a?(Array) && v.size == 1 ? v[0] : v # make values like ['v'] into 'v'
202
+ end
203
+ result
204
+ end
205
+
206
+ def do_capture(params)
207
+ response = soap_post('capture', params)
208
+ {
209
+ 'result' => response.elements['//captureResponse/captureResult'].text,
210
+ 'pbs' => response.elements['//captureResponse/pbsResponse'].text,
211
+ 'epay' => response.elements['//captureResponse/epayresponse'].text
212
+ }
213
+ end
214
+
215
+ def do_credit(params)
216
+ response = soap_post('credit', params)
217
+ {
218
+ 'result' => response.elements['//creditResponse/creditResult'].text,
219
+ 'pbs' => response.elements['//creditResponse/pbsresponse'].text,
220
+ 'epay' => response.elements['//creditResponse/epayresponse'].text
221
+ }
222
+ end
223
+
224
+ def do_void(params)
225
+ response = soap_post('delete', params)
226
+ {
227
+ 'result' => response.elements['//deleteResponse/deleteResult'].text,
228
+ 'epay' => response.elements['//deleteResponse/epayresponse'].text
229
+ }
230
+ end
231
+
232
+ def make_headers(data, soap_call)
233
+ {
234
+ 'Content-Type' => 'text/xml; charset=utf-8',
235
+ 'Host' => "ssl.ditonlinebetalingssystem.dk",
236
+ 'Content-Length' => data.size.to_s,
237
+ 'SOAPAction' => self.live_url + 'remote/payment/' + soap_call
238
+ }
239
+ end
240
+
241
+ def xml_builder(params, soap_call)
242
+ xml = Builder::XmlMarkup.new(:indent => 2)
243
+ xml.instruct!
244
+ xml.tag! 'soap:Envelope', { 'xmlns:xsi' => 'http://schemas.xmlsoap.org/soap/envelope/',
245
+ 'xmlns:xsd' => 'http://www.w3.org/2001/XMLSchema',
246
+ 'xmlns:soap' => 'http://schemas.xmlsoap.org/soap/envelope/' } do
247
+ xml.tag! 'soap:Body' do
248
+ xml.tag! soap_call, { 'xmlns' => "#{self.live_url}remote/payment" } do
249
+ xml.tag! 'merchantnumber', @options[:login]
250
+ xml.tag! 'transactionid', params[:transaction]
251
+ xml.tag! 'amount', params[:amount].to_s if soap_call != 'delete'
252
+ end
253
+ end
254
+ end
255
+ xml.target!
256
+ end
257
+
258
+ def authorize_post_data(params = {})
259
+ params[:language] = '2'
260
+ params[:cms] = 'activemerchant'
261
+ params[:accepturl] = live_url + 'auth/default.aspx?accept=1'
262
+ params[:declineurl] = live_url + 'auth/default.aspx?decline=1'
263
+ params[:merchantnumber] = @options[:login]
264
+
265
+ params.collect { |key, value| "#{key}=#{CGI.escape(value.to_s)}" }.join("&")
266
+ end
267
+
268
+ # Limited to 20 digits max
269
+ def format_order_number(number)
270
+ number.to_s.gsub(/[^\w]/, '').rjust(4, "0")[0...20]
271
+ end
272
+ end
273
+ end
274
+ end
@@ -0,0 +1,308 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ # === EVO Canada payment gateway.
4
+ #
5
+ # EVO returns two different identifiers for most transactions, the
6
+ # +authcode+ and the +transactionid+. Since +transactionid+ is used more
7
+ # often (i.e. for {#capture}, {#refund}, {#void} and {#update}) we store it in the
8
+ # Response#authorization attribute. The +authcode+ from the merchant
9
+ # account is accessible via {Response#params}.
10
+ #
11
+ # Two different but related response messages are also returned from EVO.
12
+ # The message indicated by EVO's <tt>response_code</tt> parameter is returned as
13
+ # {Response#message} (Those messages can be seen in the {MESSAGES} hash.)
14
+ # The other, shorter message is available via {Response#params}.
15
+ #
16
+ # It's recommended to save the contents of the {Response#params} in your
17
+ # transaction log for future reference.
18
+ #
19
+ # === Sample Use
20
+ #
21
+ # gateway = ActiveMerchant::Billing::EvoCaGateway.new(username: 'demo', password: 'password')
22
+ #
23
+ # response = gateway.authorize(1000, credit_card, options)
24
+ #
25
+ # puts response.authorization # the transactionid
26
+ # puts response.params['authcode'] # the authcode from the merchant account
27
+ # puts response.message # the 'pretty' response message
28
+ # puts response.params['responsetext'] # the 'terse' response message
29
+ #
30
+ # gateway.capture(1000, response.authorization)
31
+ # gateway.update(response.authorization, shipping_carrier: 'fedex')
32
+ # gateway.refund(500, response.authorization)
33
+ #
34
+ class EvoCaGateway < Gateway
35
+ self.test_url = 'https://secure.evoepay.com/api/transact.php'
36
+ self.live_url = 'https://secure.evoepay.com/api/transact.php'
37
+
38
+ self.supported_countries = ['CA']
39
+ self.supported_cardtypes = [:visa, :master, :american_express, :jcb, :discover]
40
+ self.money_format = :dollars
41
+ self.homepage_url = 'http://www.evocanada.com/'
42
+ self.display_name = 'EVO Canada'
43
+
44
+ APPROVED, DECLINED, ERROR = 1, 2, 3
45
+
46
+ MESSAGES = {
47
+ 100 => 'Transaction was approved',
48
+ 200 => 'Transaction was declined by processor',
49
+ 201 => 'Do not honor',
50
+ 202 => 'Insufficient funds',
51
+ 203 => 'Over limit',
52
+ 204 => 'Transaction not allowed',
53
+ 220 => 'Incorrect payment data',
54
+ 221 => 'No such card issuer',
55
+ 222 => 'No card number on file with issuer',
56
+ 223 => 'Expired card',
57
+ 224 => 'Invalid expiration date',
58
+ 225 => 'Invalid card security code',
59
+ 240 => 'Call issuer for futher information',
60
+ 250 => 'Pick up card',
61
+ 251 => 'Lost card',
62
+ 252 => 'Stolen card',
63
+ 253 => 'Fraudulant card',
64
+ 260 => 'Declined with further instructions available',
65
+ 261 => 'Declined - stop all recurring payments',
66
+ 262 => 'Declined - stop this recurring program',
67
+ 263 => 'Declined - updated cardholder data available',
68
+ 264 => 'Declined - retry in a few days',
69
+ 300 => 'Transaction was rejected by gateway',
70
+ 400 => 'Transaction error returned by processor',
71
+ 410 => 'Invalid merchant configuration',
72
+ 411 => 'Merchant account is inactive',
73
+ 420 => 'Communication error',
74
+ 421 => 'Communication error with issuer',
75
+ 430 => 'Duplicate transaction at processor',
76
+ 440 => 'Processor format error',
77
+ 441 => 'Invalid transaction information',
78
+ 460 => 'Processor feature not available',
79
+ 461 => 'Unsupported card type'
80
+ }
81
+
82
+ # This gateway requires that a valid username and password be passed
83
+ # in the +options+ hash.
84
+ #
85
+ # === Required Options
86
+ #
87
+ # * <tt>:username</tt>
88
+ # * <tt>:password</tt>
89
+ def initialize(options = {})
90
+ requires!(options, :username, :password)
91
+ super
92
+ end
93
+
94
+ # Transaction sales are submitted and immediately flagged for settlement.
95
+ # These transactions will automatically be settled.
96
+ #
97
+ # Payment source can be either a {CreditCard} or {Check}.
98
+ #
99
+ # === Additional Options
100
+ # In addition to the standard options, this gateway supports
101
+ #
102
+ # * <tt>:tracking_number</tt> - Shipping tracking number
103
+ # * <tt>:shipping_carrier</tt> - ups/fedex/dhl/usps
104
+ # * <tt>:po_number</tt> - Purchase order
105
+ # * <tt>:tax</tt> - Tax amount
106
+ # * <tt>:shipping</tt> - Shipping cost
107
+ def purchase(money, credit_card_or_check, options = {})
108
+ post = {}
109
+ add_invoice(post, options)
110
+ add_order(post, options)
111
+ add_paymentmethod(post, credit_card_or_check)
112
+ add_address(post, options)
113
+ add_customer_data(post, options)
114
+ commit('sale', money, post)
115
+ end
116
+
117
+ # Transaction authorizations are authorized immediately but are not
118
+ # flagged for settlement. These transactions must be flagged for
119
+ # settlement using the _capture_ transaction type. Authorizations
120
+ # typically remain activate for three to seven business days.
121
+ #
122
+ # Payment source must be a {CreditCard}.
123
+ def authorize(money, credit_card, options = {})
124
+ post = {}
125
+ add_invoice(post, options)
126
+ add_order(post, options)
127
+ add_paymentmethod(post, credit_card)
128
+ add_address(post, options)
129
+ add_customer_data(post, options)
130
+ commit('auth', money, post)
131
+ end
132
+
133
+ # Transaction captures flag existing _authorizations_ for settlement. Only
134
+ # authorizations can be captured. Captures can be submitted for an amount
135
+ # equal to or less than the original authorization.
136
+ #
137
+ # The <tt>authorization</tt> parameter is the transaction ID, retrieved
138
+ # from Response#authorization. See EvoCaGateway#purchase for the
139
+ # <tt>options</tt>.
140
+ def capture(money, authorization, options = {})
141
+ post = {
142
+ :amount => amount(money),
143
+ :transactionid => authorization
144
+ }
145
+ add_order(post, options)
146
+ commit('capture', money, post)
147
+ end
148
+
149
+ # Transaction refunds will reverse a previously settled transaction. If
150
+ # the transaction has not been settled, it must be _voided_ instead of
151
+ # refunded.
152
+ #
153
+ # The <tt>identification</tt> parameter is the transaction ID, retrieved
154
+ # from {Response#authorization}.
155
+ def refund(money, identification)
156
+ post = {:transactionid => identification}
157
+ commit('refund', money, post)
158
+ end
159
+
160
+ # Transaction credits apply a negative amount to the cardholder's card.
161
+ # In most situations credits are disabled as transaction refunds should
162
+ # be used instead.
163
+ #
164
+ # Note that this is different from a {#refund} (which is usually what
165
+ # you'll be looking for).
166
+ def credit(money, credit_card, options = {})
167
+ post = {}
168
+ add_invoice(post, options)
169
+ add_order(post, options)
170
+ add_paymentmethod(post, credit_card)
171
+ add_address(post, options)
172
+ add_customer_data(post, options)
173
+ commit('credit', money, post)
174
+ end
175
+
176
+ # Transaction voids will cancel an existing sale or captured
177
+ # authorization. In addition, non-captured authorizations can be voided to
178
+ # prevent any future capture. Voids can only occur if the transaction has
179
+ # not been settled.
180
+ #
181
+ # The <tt>identification</tt> parameter is the transaction ID, retrieved
182
+ # from {Response#authorization}.
183
+ def void(identification)
184
+ post = {:transactionid => identification}
185
+ commit('void', nil, post)
186
+ end
187
+
188
+ # Transaction updates can be used to update previous transactions with
189
+ # specific order information, such as a tracking number and shipping
190
+ # carrier. See EvoCaGateway#purchase for <tt>options</tt>.
191
+ #
192
+ # The <tt>identification</tt> parameter is the transaction ID, retrieved
193
+ # from {Response#authorization}.
194
+ def update(identification, options)
195
+ post = {:transactionid => identification}
196
+ add_order(post, options)
197
+ commit('update', nil, post)
198
+ end
199
+
200
+ private
201
+
202
+ def add_customer_data(post, options)
203
+ post[:email] = options[:email]
204
+ post[:ipaddress] = options[:ip]
205
+ end
206
+
207
+ def add_address(post, options)
208
+ if address = options[:billing_address] || options[:address]
209
+ post[:firstname] = address[:first_name]
210
+ post[:lastname] = address[:last_name]
211
+ post[:address1] = address[:address1]
212
+ post[:address2] = address[:address2]
213
+ post[:company] = address[:company]
214
+ post[:phone] = address[:phone]
215
+ post[:city] = address[:city]
216
+ post[:state] = address[:state]
217
+ post[:zip] = address[:zip]
218
+ post[:country] = address[:country]
219
+ end
220
+
221
+ if address = options[:shipping_address]
222
+ post[:shipping_firstname] = address[:first_name]
223
+ post[:shipping_lastname] = address[:last_name]
224
+ post[:shipping_address1] = address[:address1]
225
+ post[:shipping_address2] = address[:address2]
226
+ post[:shipping_company] = address[:company]
227
+ post[:shipping_zip] = address[:zip]
228
+ post[:shipping_city] = address[:city]
229
+ post[:shipping_state] = address[:state]
230
+ post[:shipping_country] = address[:country]
231
+ end
232
+ end
233
+
234
+ def add_order(post, options)
235
+ post[:orderid] = options[:order_id]
236
+ post[:tracking_number] = options[:tracking_number]
237
+ post[:shipping_carrier] = options[:shipping_carrier]
238
+ end
239
+
240
+ def add_invoice(post, options)
241
+ post[:orderdescription] = options[:description]
242
+ post[:ponumber] = options[:po_number]
243
+ post[:shipping] = amount(options[:shipping])
244
+ post[:tax] = amount(options[:tax])
245
+ end
246
+
247
+ def add_paymentmethod(post, payment)
248
+ if card_brand(payment)=='check'
249
+ post[:payment] = 'check'
250
+ post[:checkname] = payment.name
251
+ post[:checkaba] = payment.routing_number
252
+ post[:checkaccount] = payment.account_number
253
+ post[:account_holder_type] = payment.account_holder_type
254
+ post[:account_type] = payment.account_type
255
+ else
256
+ post[:payment] = 'creditcard'
257
+ post[:ccnumber] = payment.number
258
+ post[:ccexp] = "#{format(payment.month, :two_digits)}#{format(payment.year, :two_digits)}"
259
+ post[:cvv] = payment.verification_value
260
+ end
261
+ end
262
+
263
+ def parse(body)
264
+ fields = {}
265
+ CGI::parse(body).each do |k, v|
266
+ fields[k.to_s] = v.kind_of?(Array) ? v[0] : v
267
+ end
268
+ fields
269
+ end
270
+
271
+ def success?(response)
272
+ response['response'].to_i == APPROVED
273
+ end
274
+
275
+ def commit(action, money, parameters)
276
+ parameters[:amount] = amount(money) unless action == 'void'
277
+
278
+ data = ssl_post self.live_url, post_data(action, parameters)
279
+ response = parse(data)
280
+ message = message_from(response)
281
+
282
+ Response.new(success?(response), message, response,
283
+ :test => test?,
284
+ :authorization => response['transactionid'],
285
+ :avs_result => { :code => response['avsresponse'] },
286
+ :cvv_result => response['cvvresponse']
287
+ )
288
+ end
289
+
290
+ def message_from(response)
291
+ MESSAGES.fetch(response['response_code'].to_i, false) || response['message']
292
+ end
293
+
294
+ def post_data(action, parameters = {})
295
+ post = {:type => action}
296
+
297
+ if test?
298
+ post[:username] = 'demo'
299
+ post[:password] = 'password'
300
+ else
301
+ post[:username] = options[:username]
302
+ post[:password] = options[:password]
303
+ end
304
+ post.merge(parameters).collect { |key, value| "#{key}=#{CGI.escape(value.to_s)}" unless value.nil? }.compact.join("&")
305
+ end
306
+ end
307
+ end
308
+ end