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,140 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ # Bogus Gateway
4
+ class BogusGateway < Gateway
5
+ AUTHORIZATION = '53433'
6
+
7
+ SUCCESS_MESSAGE = "Bogus Gateway: Forced success"
8
+ FAILURE_MESSAGE = "Bogus Gateway: Forced failure"
9
+ ERROR_MESSAGE = "Bogus Gateway: Use CreditCard number ending in 1 for success, 2 for exception and anything else for error"
10
+ UNSTORE_ERROR_MESSAGE = "Bogus Gateway: Use trans_id ending in 1 for success, 2 for exception and anything else for error"
11
+ CAPTURE_ERROR_MESSAGE = "Bogus Gateway: Use authorization number ending in 1 for exception, 2 for error and anything else for success"
12
+ VOID_ERROR_MESSAGE = "Bogus Gateway: Use authorization number ending in 1 for exception, 2 for error and anything else for success"
13
+ REFUND_ERROR_MESSAGE = "Bogus Gateway: Use trans_id number ending in 1 for exception, 2 for error and anything else for success"
14
+ CHECK_ERROR_MESSAGE = "Bogus Gateway: Use bank account number ending in 1 for success, 2 for exception and anything else for error"
15
+
16
+ self.supported_countries = []
17
+ self.supported_cardtypes = [:bogus]
18
+ self.homepage_url = 'http://example.com'
19
+ self.display_name = 'Bogus'
20
+
21
+ def authorize(money, paysource, options = {})
22
+ money = amount(money)
23
+ case normalize(paysource)
24
+ when /1$/
25
+ Response.new(true, SUCCESS_MESSAGE, {:authorized_amount => money}, :test => true, :authorization => AUTHORIZATION )
26
+ when /2$/
27
+ Response.new(false, FAILURE_MESSAGE, {:authorized_amount => money, :error => FAILURE_MESSAGE }, :test => true, :error_code => STANDARD_ERROR_CODE[:processing_error])
28
+ else
29
+ raise Error, error_message(paysource)
30
+ end
31
+ end
32
+
33
+ def purchase(money, paysource, options = {})
34
+ money = amount(money)
35
+ case normalize(paysource)
36
+ when /1$/, AUTHORIZATION
37
+ Response.new(true, SUCCESS_MESSAGE, {:paid_amount => money}, :test => true, :authorization => AUTHORIZATION)
38
+ when /2$/
39
+ Response.new(false, FAILURE_MESSAGE, {:paid_amount => money, :error => FAILURE_MESSAGE }, :test => true, :error_code => STANDARD_ERROR_CODE[:processing_error])
40
+ else
41
+ raise Error, error_message(paysource)
42
+ end
43
+ end
44
+
45
+ def credit(money, paysource, options = {})
46
+ if paysource.is_a?(String)
47
+ ActiveMerchant.deprecated CREDIT_DEPRECATION_MESSAGE
48
+ return refund(money, paysource, options)
49
+ end
50
+
51
+ money = amount(money)
52
+ case normalize(paysource)
53
+ when /1$/
54
+ Response.new(true, SUCCESS_MESSAGE, {:paid_amount => money}, :test => true )
55
+ when /2$/
56
+ Response.new(false, FAILURE_MESSAGE, {:paid_amount => money, :error => FAILURE_MESSAGE }, :test => true, :error_code => STANDARD_ERROR_CODE[:processing_error])
57
+ else
58
+ raise Error, error_message(paysource)
59
+ end
60
+ end
61
+
62
+ def refund(money, reference, options = {})
63
+ money = amount(money)
64
+ case reference
65
+ when /1$/
66
+ raise Error, REFUND_ERROR_MESSAGE
67
+ when /2$/
68
+ Response.new(false, FAILURE_MESSAGE, {:paid_amount => money, :error => FAILURE_MESSAGE }, :test => true, :error_code => STANDARD_ERROR_CODE[:processing_error])
69
+ else
70
+ Response.new(true, SUCCESS_MESSAGE, {:paid_amount => money}, :test => true)
71
+ end
72
+ end
73
+
74
+ def capture(money, reference, options = {})
75
+ money = amount(money)
76
+ case reference
77
+ when /1$/
78
+ raise Error, CAPTURE_ERROR_MESSAGE
79
+ when /2$/
80
+ Response.new(false, FAILURE_MESSAGE, {:paid_amount => money, :error => FAILURE_MESSAGE }, :test => true, :error_code => STANDARD_ERROR_CODE[:processing_error])
81
+ else
82
+ Response.new(true, SUCCESS_MESSAGE, {:paid_amount => money}, :test => true)
83
+ end
84
+ end
85
+
86
+ def void(reference, options = {})
87
+ case reference
88
+ when /1$/
89
+ raise Error, VOID_ERROR_MESSAGE
90
+ when /2$/
91
+ Response.new(false, FAILURE_MESSAGE, {:authorization => reference, :error => FAILURE_MESSAGE }, :test => true, :error_code => STANDARD_ERROR_CODE[:processing_error])
92
+ else
93
+ Response.new(true, SUCCESS_MESSAGE, {:authorization => reference}, :test => true)
94
+ end
95
+ end
96
+
97
+ def store(paysource, options = {})
98
+ case normalize(paysource)
99
+ when /1$/
100
+ Response.new(true, SUCCESS_MESSAGE, {:billingid => '1'}, :test => true, :authorization => AUTHORIZATION)
101
+ when /2$/
102
+ Response.new(false, FAILURE_MESSAGE, {:billingid => nil, :error => FAILURE_MESSAGE }, :test => true, :error_code => STANDARD_ERROR_CODE[:processing_error])
103
+ else
104
+ raise Error, error_message(paysource)
105
+ end
106
+ end
107
+
108
+ def unstore(reference, options = {})
109
+ case reference
110
+ when /1$/
111
+ Response.new(true, SUCCESS_MESSAGE, {}, :test => true)
112
+ when /2$/
113
+ Response.new(false, FAILURE_MESSAGE, {:error => FAILURE_MESSAGE },:test => true, :error_code => STANDARD_ERROR_CODE[:processing_error])
114
+ else
115
+ raise Error, UNSTORE_ERROR_MESSAGE
116
+ end
117
+ end
118
+
119
+ private
120
+
121
+ def normalize(paysource)
122
+ if paysource.respond_to?(:account_number) && (paysource.try(:number).blank? || paysource.number.blank?)
123
+ paysource.account_number
124
+ elsif paysource.respond_to?(:number)
125
+ paysource.number
126
+ else
127
+ paysource.to_s
128
+ end
129
+ end
130
+
131
+ def error_message(paysource)
132
+ if paysource.respond_to?(:account_number)
133
+ CHECK_ERROR_MESSAGE
134
+ elsif paysource.respond_to?(:number)
135
+ ERROR_MESSAGE
136
+ end
137
+ end
138
+ end
139
+ end
140
+ end
@@ -0,0 +1,211 @@
1
+ require "nokogiri"
2
+
3
+ module ActiveMerchant #:nodoc:
4
+ module Billing #:nodoc:
5
+ class BorgunGateway < Gateway
6
+ self.display_name = "Borgun"
7
+ self.homepage_url = 'http://www.borgun.com'
8
+
9
+ self.test_url = 'https://gatewaytest.borgun.is/ws/Heimir.pub.ws:Authorization'
10
+ self.live_url = 'https://gateway01.borgun.is/ws/Heimir.pub.ws:Authorization'
11
+
12
+ self.supported_countries = ['IS', 'GB', 'HU', 'CZ', 'DE', 'DK', 'SE' ]
13
+ self.default_currency = 'ISK'
14
+ self.money_format = :cents
15
+ self.supported_cardtypes = [:visa, :master, :american_express, :diners_club, :discover, :jcb]
16
+
17
+ self.homepage_url = 'https://www.borgun.is/'
18
+
19
+ def initialize(options={})
20
+ requires!(options, :processor, :merchant_id, :username, :password)
21
+ super
22
+ end
23
+
24
+ def purchase(money, payment, options={})
25
+ post = {}
26
+ post[:TransType] = '1'
27
+ add_invoice(post, money, options)
28
+ add_payment_method(post, payment)
29
+
30
+ commit('sale', post)
31
+ end
32
+
33
+ def authorize(money, payment, options={})
34
+ post = {}
35
+ post[:TransType] = '5'
36
+ add_invoice(post, money, options)
37
+ add_payment_method(post, payment)
38
+
39
+ commit('authonly', post)
40
+ end
41
+
42
+ def capture(money, authorization, options={})
43
+ post = {}
44
+ post[:TransType] = '1'
45
+ add_invoice(post, money, options)
46
+ add_reference(post, authorization)
47
+ commit('capture', post)
48
+ end
49
+
50
+ def refund(money, authorization, options={})
51
+ post = {}
52
+ post[:TransType] = '3'
53
+ add_invoice(post, money, options)
54
+ add_reference(post, authorization)
55
+ commit('refund', post)
56
+ end
57
+
58
+ def void(authorization, options={})
59
+ post = {}
60
+ # TransType and TrAmount must match original values from auth or purchase.
61
+ _, _, _, _, _, transtype, tramount = split_authorization(authorization)
62
+ post[:TransType] = transtype
63
+ add_invoice(post, tramount.to_i, options)
64
+ add_reference(post, authorization)
65
+ commit('void', post)
66
+ end
67
+
68
+ private
69
+
70
+ CURRENCY_CODES = Hash.new{|h,k| raise ArgumentError.new("Unsupported currency for HDFC: #{k}")}
71
+ CURRENCY_CODES["ISK"] = "352"
72
+ CURRENCY_CODES["EUR"] = "978"
73
+
74
+ def add_invoice(post, money, options)
75
+ post[:TrAmount] = amount(money)
76
+ post[:TrCurrency] = CURRENCY_CODES[options[:currency] || currency(money)]
77
+ end
78
+
79
+ def add_payment_method(post, payment_method)
80
+ post[:PAN] = payment_method.number
81
+ post[:ExpDate] = format(payment_method.year, :two_digits) + format(payment_method.month, :two_digits)
82
+ post[:CVC2] = payment_method.verification_value
83
+ post[:DateAndTime] = Time.now.strftime("%y%m%d%H%M%S")
84
+ post[:RRN] = 'AMRCNT' + six_random_digits
85
+ end
86
+
87
+ def add_reference(post, authorization)
88
+ dateandtime, batch, transaction, rrn, authcode, _, _ = split_authorization(authorization)
89
+ post[:DateAndTime] = dateandtime
90
+ post[:Batch] = batch
91
+ post[:Transaction] = transaction
92
+ post[:RRN] = rrn
93
+ post[:AuthCode] = authcode
94
+ end
95
+
96
+ def parse(xml)
97
+ response = {}
98
+
99
+ doc = Nokogiri::XML(CGI.unescapeHTML(xml))
100
+ body = doc.xpath('//getAuthorizationReply')
101
+ body = doc.xpath('//cancelAuthorizationReply') if body.length == 0
102
+ body.children.each do |node|
103
+ if node.text?
104
+ next
105
+ elsif (node.elements.size == 0)
106
+ response[node.name.downcase.to_sym] = node.text
107
+ else
108
+ node.elements.each do |childnode|
109
+ name = "#{node.name.downcase}_#{childnode.name.downcase}"
110
+ response[name.to_sym] = childnode.text
111
+ end
112
+ end
113
+ end
114
+
115
+ response
116
+ end
117
+
118
+ def commit(action, post)
119
+ post[:Version] = '1000'
120
+ post[:Processor] = @options[:processor]
121
+ post[:MerchantID] = @options[:merchant_id]
122
+ post[:TerminalID] = 1
123
+
124
+ url = (test? ? test_url : live_url)
125
+ request = build_request(action, post)
126
+ raw = ssl_post(url(action), request, headers)
127
+ pairs = parse(raw)
128
+ success = success_from(pairs)
129
+
130
+ Response.new(
131
+ success,
132
+ message_from(success, pairs),
133
+ pairs,
134
+ authorization: authorization_from(pairs),
135
+ test: test?
136
+ )
137
+ end
138
+
139
+ def success_from(response)
140
+ (response[:actioncode] == '000')
141
+ end
142
+
143
+ def message_from(succeeded, response)
144
+ if succeeded
145
+ "Succeeded"
146
+ else
147
+ response[:message] || "Error with ActionCode=#{response[:actioncode]}"
148
+ end
149
+ end
150
+
151
+ def authorization_from(response)
152
+ [
153
+ response[:dateandtime],
154
+ response[:batch],
155
+ response[:transaction],
156
+ response[:rrn],
157
+ response[:authcode],
158
+ response[:transtype],
159
+ response[:tramount]
160
+ ].join("|")
161
+ end
162
+
163
+ def split_authorization(authorization)
164
+ dateandtime, batch, transaction, rrn, authcode, transtype, tramount = authorization.split("|")
165
+ [dateandtime, batch, transaction, rrn, authcode, transtype, tramount]
166
+ end
167
+
168
+ def headers
169
+ {
170
+ 'Authorization' => 'Basic ' + Base64.strict_encode64(@options[:username].to_s + ':' + @options[:password].to_s),
171
+ }
172
+ end
173
+
174
+ def build_request(action, post)
175
+ mode = (action == 'void') ? 'cancel' : 'get'
176
+ xml = Builder::XmlMarkup.new :indent => 18
177
+ xml.instruct!(:xml, :version => '1.0', :encoding => 'utf-8')
178
+ xml.tag!("#{mode}Authorization") do
179
+ post.each do |field, value|
180
+ xml.tag!(field, value)
181
+ end
182
+ end
183
+ inner = CGI.escapeHTML(xml.target!)
184
+ envelope(mode).sub(/{{ :body }}/,inner)
185
+ end
186
+
187
+ def envelope(mode)
188
+ <<-EOS
189
+ <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:aut="http://Borgun/Heimir/pub/ws/Authorization">
190
+ <soapenv:Header/>
191
+ <soapenv:Body>
192
+ <aut:#{mode}AuthorizationInput>
193
+ <#{mode}AuthReqXml>
194
+ {{ :body }}
195
+ </#{mode}AuthReqXml>
196
+ </aut:#{mode}AuthorizationInput>
197
+ </soapenv:Body>
198
+ </soapenv:Envelope>
199
+ EOS
200
+ end
201
+
202
+ def url(action)
203
+ (test? ? test_url : live_url)
204
+ end
205
+
206
+ def six_random_digits
207
+ (0...6).map { (48 + rand(10)).chr }.join
208
+ end
209
+ end
210
+ end
211
+ end
@@ -0,0 +1,277 @@
1
+ require 'nokogiri'
2
+
3
+ module ActiveMerchant #:nodoc:
4
+ module Billing #:nodoc:
5
+ class BpointGateway < Gateway
6
+ self.live_url = 'https://www.bpoint.com.au/evolve/service_1_4_4.asmx'
7
+
8
+ self.supported_countries = ['AU']
9
+ self.default_currency = 'AUD'
10
+ self.supported_cardtypes = [:visa, :master, :american_express, :diners_club]
11
+
12
+ self.homepage_url = 'https://www.bpoint.com.au/bpoint'
13
+ self.display_name = 'BPoint'
14
+
15
+ def initialize(options={})
16
+ requires!(options, :username, :password, :merchant_number)
17
+ super
18
+ end
19
+
20
+ def store(credit_card, options={})
21
+ options[:crn1] ||= 'DEFAULT'
22
+ request_body = soap_request do |xml|
23
+ add_token(xml, credit_card, options)
24
+ end
25
+ commit(request_body)
26
+ end
27
+
28
+ def purchase(amount, credit_card, options={})
29
+ request_body = soap_request do |xml|
30
+ process_payment(xml) do |payment_xml|
31
+ add_purchase(payment_xml, amount, credit_card, options)
32
+ end
33
+ end
34
+ commit(request_body)
35
+ end
36
+
37
+ def authorize(amount, credit_card, options={})
38
+ request_body = soap_request do |xml|
39
+ process_payment(xml) do |payment_xml|
40
+ add_authorize(payment_xml, amount, credit_card, options)
41
+ end
42
+ end
43
+ commit(request_body)
44
+ end
45
+
46
+ def capture(amount, authorization, options={})
47
+ request_body = soap_request do |xml|
48
+ process_payment(xml) do |payment_xml|
49
+ add_capture(payment_xml, amount, authorization, options)
50
+ end
51
+ end
52
+ commit(request_body)
53
+ end
54
+
55
+ def refund(amount, authorization, options={})
56
+ request_body = soap_request do |xml|
57
+ process_payment(xml) do |payment_xml|
58
+ add_refund(payment_xml, amount, authorization, options)
59
+ end
60
+ end
61
+ commit(request_body)
62
+ end
63
+
64
+ def void(amount, authorization, options={})
65
+ request_body = soap_request do |xml|
66
+ process_payment(xml) do |payment_xml|
67
+ add_void(payment_xml, amount, authorization, options)
68
+ end
69
+ end
70
+ commit(request_body)
71
+ end
72
+
73
+ def verify(credit_card, options={})
74
+ MultiResponse.run(:use_first_response) do |r|
75
+ r.process { authorize(100, credit_card, options) }
76
+ r.process(:ignore_result) { void(100, r.authorization, options) }
77
+ end
78
+ end
79
+
80
+ def supports_scrubbing?
81
+ true
82
+ end
83
+
84
+ def scrub(transcript)
85
+ transcript.
86
+ gsub(%r((<password>).+(</password>)), '\1[FILTERED]\2').
87
+ gsub(%r((<CardNumber>).+(</CardNumber>)), '\1[FILTERED]\2').
88
+ gsub(%r((<CVC>).+(</CVC>)), '\1[FILTERED]\2')
89
+ end
90
+
91
+ private
92
+
93
+ def soap_request
94
+ Nokogiri::XML::Builder.new(:encoding => 'utf-8') do |xml|
95
+ xml.send('soap12:Envelope', soap_envelope_attributes) {
96
+ xml.send('soap12:Body') {
97
+ yield(xml) if block_given?
98
+ }
99
+ }
100
+ end.to_xml
101
+ end
102
+
103
+ def soap_envelope_attributes
104
+ { 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
105
+ 'xmlns:xsd' => 'http://www.w3.org/2001/XMLSchema',
106
+ 'xmlns:soap12' => 'http://www.w3.org/2003/05/soap-envelope' }
107
+ end
108
+
109
+ def process_payment(xml)
110
+ xml.send('ProcessPayment', { 'xmlns' => 'urn:Eve_1_4_4' }) {
111
+ credentials_xml(xml)
112
+ xml.send('txnReq') {
113
+ yield(xml) if block_given?
114
+ }
115
+ }
116
+ end
117
+
118
+ def add_token(xml, credit_card, options)
119
+ xml.send('AddToken', { 'xmlns' => 'urn:Eve_1_4_4' }) {
120
+ credentials_xml(xml)
121
+ xml.send('tokenRequest') {
122
+ xml.send('CRN1', options[:crn1])
123
+ xml.send('CRN2', '')
124
+ xml.send('CRN3', '')
125
+ xml.send('CardNumber', credit_card.number)
126
+ xml.send('ExpiryDate', expdate(credit_card))
127
+ }
128
+ }
129
+ end
130
+
131
+ def credentials_xml(xml)
132
+ xml.send('username', @options[:username])
133
+ xml.send('password', @options[:password])
134
+ xml.send('merchantNumber', @options[:merchant_number])
135
+ end
136
+
137
+ def add_purchase(xml, amount, credit_card, options)
138
+ payment_xml(xml, 'PAYMENT', amount, options)
139
+ credit_card_xml(xml, credit_card)
140
+ end
141
+
142
+ def add_authorize(xml, amount, credit_card, options)
143
+ payment_xml(xml, 'PREAUTH', amount, options)
144
+ credit_card_xml(xml, credit_card)
145
+ end
146
+
147
+ def add_capture(xml, amount, transaction_number, options)
148
+ payment_xml(xml, 'CAPTURE', amount, options)
149
+ transaction_number_xml(xml, transaction_number)
150
+ end
151
+
152
+ def add_refund(xml, amount, transaction_number, options)
153
+ payment_xml(xml, 'REFUND', amount, options)
154
+ transaction_number_xml(xml, transaction_number)
155
+ end
156
+
157
+ def add_void(xml, amount, transaction_number, options)
158
+ payment_xml(xml, 'REVERSAL', amount, options)
159
+ transaction_number_xml(xml, transaction_number)
160
+ end
161
+
162
+ def payment_xml(xml, payment_type, amount, options)
163
+ xml.send('PaymentType', payment_type)
164
+ xml.send('TxnType', 'WEB_SHOP')
165
+ xml.send('BillerCode', options.fetch(:biller_code, ''))
166
+ xml.send('MerchantReference', '')
167
+ xml.send('CRN1', '')
168
+ xml.send('CRN2', '')
169
+ xml.send('CRN3', '')
170
+ xml.send('Amount', amount)
171
+ end
172
+
173
+ def credit_card_xml(xml, credit_card)
174
+ xml.send('CardNumber', credit_card.number)
175
+ xml.send('ExpiryDate', expdate(credit_card))
176
+ xml.send('CVC', credit_card.verification_value)
177
+ end
178
+
179
+ def transaction_number_xml(xml, transaction_number)
180
+ xml.send('OriginalTransactionNumber', transaction_number)
181
+ end
182
+
183
+ def commit(request_body)
184
+ parse(ssl_post(live_url, request_body, request_headers))
185
+ end
186
+
187
+ def request_headers
188
+ { "Content-Type" => "application/soap+xml; charset=utf-8" }
189
+ end
190
+
191
+ def parse(body)
192
+ response_for(Nokogiri::XML(body).remove_namespaces!)
193
+ end
194
+
195
+ def response_for(xml_doc)
196
+ if xml_doc.xpath('//ProcessPaymentResponse').any?
197
+ ProcessPaymentResponse.new(xml_doc, self).to_response
198
+ elsif xml_doc.xpath('//AddTokenResponse').any?
199
+ AddTokenResponse.new(xml_doc, self).to_response
200
+ end
201
+ end
202
+
203
+ class BPointResponse
204
+ attr_reader :xml_doc, :gateway, :params
205
+
206
+ def initialize(xml_doc, gateway)
207
+ @xml_doc = xml_doc
208
+ @gateway = gateway
209
+ @params = init_params
210
+ end
211
+
212
+ def to_response
213
+ Response.new(success?, message, params, options)
214
+ end
215
+
216
+ private
217
+
218
+ def init_params
219
+ {}.tap do |h|
220
+ xml_doc.xpath(response_node).each do |node|
221
+ if node.elements.empty?
222
+ h[node.name.to_sym] = node.text
223
+ else
224
+ node.elements.each do |childnode|
225
+ name = "#{node.name}_#{childnode.name}"
226
+ h[name.to_sym] = childnode.text
227
+ end
228
+ end
229
+ end
230
+ end
231
+ end
232
+
233
+ def response_node
234
+ "//#{self.class.name.split('::').last}/*"
235
+ end
236
+
237
+ def options
238
+ { authorization: params[authorization_key], test: gateway.test? }
239
+ end
240
+ end
241
+
242
+ class ProcessPaymentResponse < BPointResponse
243
+
244
+ private
245
+
246
+ def authorization_key
247
+ :ProcessPaymentResult_TransactionNumber
248
+ end
249
+
250
+ def success?
251
+ params[:ProcessPaymentResult_ResponseCode] == '0'
252
+ end
253
+
254
+ def message
255
+ params[:ProcessPaymentResult_AuthorisationResult]
256
+ end
257
+ end
258
+
259
+ class AddTokenResponse < BPointResponse
260
+
261
+ private
262
+
263
+ def authorization_key
264
+ :AddTokenResult_Token
265
+ end
266
+
267
+ def success?
268
+ params[:response_ResponseCode] == 'SUCCESS'
269
+ end
270
+
271
+ def message
272
+ params[:response_ResponseCode].capitalize
273
+ end
274
+ end
275
+ end
276
+ end
277
+ end