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,268 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ class MerchantWareVersionFourGateway < Gateway
4
+ self.live_url = 'https://ps1.merchantware.net/Merchantware/ws/RetailTransaction/v4/Credit.asmx'
5
+ self.test_url = 'https://staging.merchantware.net/Merchantware/ws/RetailTransaction/v4/Credit.asmx'
6
+
7
+ self.supported_countries = ['US']
8
+ self.supported_cardtypes = [:visa, :master, :american_express, :discover]
9
+ self.homepage_url = 'http://merchantwarehouse.com/merchantware'
10
+ self.display_name = 'MerchantWARE'
11
+
12
+ ENV_NAMESPACES = { "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance",
13
+ "xmlns:xsd" => "http://www.w3.org/2001/XMLSchema",
14
+ "xmlns:soap" => "http://schemas.xmlsoap.org/soap/envelope/" }
15
+
16
+ TX_NAMESPACE = "http://schemas.merchantwarehouse.com/merchantware/40/Credit/"
17
+
18
+ ACTIONS = {
19
+ :purchase => "SaleKeyed",
20
+ :reference_purchase => 'RepeatSale',
21
+ :authorize => "PreAuthorizationKeyed",
22
+ :capture => "PostAuthorization",
23
+ :void => "VoidPreAuthorization",
24
+ :refund => "Refund"
25
+ }
26
+
27
+ # Creates a new MerchantWareVersionFourGateway
28
+ #
29
+ # The gateway requires that a valid login, password, and name be passed
30
+ # in the +options+ hash.
31
+ #
32
+ # ==== Options
33
+ #
34
+ # * <tt>:login</tt> - The MerchantWARE SiteID.
35
+ # * <tt>:password</tt> - The MerchantWARE Key.
36
+ # * <tt>:name</tt> - The MerchantWARE Name.
37
+ def initialize(options = {})
38
+ requires!(options, :login, :password, :name)
39
+ super
40
+ end
41
+
42
+ # Authorize a credit card for a given amount.
43
+ #
44
+ # ==== Parameters
45
+ # * <tt>money</tt> - The amount to be authorized as an Integer value in cents.
46
+ # * <tt>credit_card</tt> - The CreditCard details for the transaction.
47
+ # * <tt>options</tt>
48
+ # * <tt>:order_id</tt> - A unique reference for this order (required).
49
+ # * <tt>:billing_address</tt> - The billing address for the cardholder.
50
+ def authorize(money, credit_card, options = {})
51
+ request = build_purchase_request(:authorize, money, credit_card, options)
52
+ commit(:authorize, request)
53
+ end
54
+
55
+ # Authorize and immediately capture funds from a credit card.
56
+ #
57
+ # ==== Parameters
58
+ # * <tt>money</tt> - The amount to be authorized as anInteger value in cents.
59
+ # * <tt>payment_source</tt> - The CreditCard details or 'token' from prior transaction
60
+ # * <tt>options</tt>
61
+ # * <tt>:order_id</tt> - A unique reference for this order (required).
62
+ # * <tt>:billing_address</tt> - The billing address for the cardholder.
63
+ def purchase(money, payment_source, options = {})
64
+ action = payment_source.is_a?(String) ? :reference_purchase : :purchase
65
+ request = build_purchase_request(action, money, payment_source, options)
66
+ commit(action, request)
67
+ end
68
+
69
+ # Capture authorized funds from a credit card.
70
+ #
71
+ # ==== Parameters
72
+ # * <tt>money</tt> - The amount to be captured as anInteger value in cents.
73
+ # * <tt>authorization</tt> - The authorization string returned from the initial authorization.
74
+ def capture(money, authorization, options = {})
75
+ request = build_capture_request(:capture, money, authorization, options)
76
+ commit(:capture, request)
77
+ end
78
+
79
+ # Void a transaction.
80
+ #
81
+ # ==== Parameters
82
+ # * <tt>authorization</tt> - The authorization string returned from the initial authorization or purchase.
83
+ def void(authorization, options = {})
84
+ reference, options[:order_id] = split_reference(authorization)
85
+ request = soap_request(:void) do |xml|
86
+ add_reference_token(xml, reference)
87
+ end
88
+ commit(:void, request)
89
+ end
90
+
91
+ # Refund an amount back a cardholder
92
+ #
93
+ # ==== Parameters
94
+ #
95
+ # * <tt>money</tt> - The amount to be refunded as an Integer value in cents.
96
+ # * <tt>identification</tt> - The credit card you want to refund or the authorization for the existing transaction you are refunding.
97
+ # * <tt>options</tt>
98
+ # * <tt>:order_id</tt> - A unique reference for this order (required when performing a non-referenced credit)
99
+ def refund(money, identification, options = {})
100
+ reference, options[:order_id] = split_reference(identification)
101
+
102
+ request = soap_request(:refund) do |xml|
103
+ add_reference_token(xml, reference)
104
+ add_invoice(xml, options)
105
+ add_amount(xml, money, "overrideAmount")
106
+ end
107
+
108
+ commit(:refund, request)
109
+ end
110
+
111
+ private
112
+
113
+ def soap_request(action)
114
+ xml = Builder::XmlMarkup.new :indent => 2
115
+ xml.instruct!
116
+ xml.tag! "soap:Envelope", ENV_NAMESPACES do
117
+ xml.tag! "soap:Body" do
118
+ xml.tag! ACTIONS[action], "xmlns" => TX_NAMESPACE do
119
+ xml.tag! "merchantName", @options[:name]
120
+ xml.tag! "merchantSiteId", @options[:login]
121
+ xml.tag! "merchantKey", @options[:password]
122
+ yield xml
123
+ end
124
+ end
125
+ end
126
+ xml.target!
127
+ end
128
+
129
+ def build_purchase_request(action, money, payment_source, options)
130
+ requires!(options, :order_id)
131
+
132
+ soap_request(action) do |xml|
133
+ add_invoice(xml, options)
134
+ add_amount(xml, money)
135
+ add_payment_source(xml, payment_source)
136
+ add_address(xml, options)
137
+ end
138
+ end
139
+
140
+ def build_capture_request(action, money, identification, options)
141
+ reference, options[:order_id] = split_reference(identification)
142
+
143
+ soap_request(action) do |xml|
144
+ add_reference_token(xml, reference)
145
+ add_invoice(xml, options)
146
+ add_amount(xml, money)
147
+ end
148
+ end
149
+
150
+ def add_invoice(xml, options)
151
+ xml.tag! "invoiceNumber", options[:order_id].to_s.gsub(/[^\w]/, '').slice(0, 25)
152
+ end
153
+
154
+ def add_amount(xml, money, tag = "amount")
155
+ xml.tag! tag, amount(money)
156
+ end
157
+
158
+ def add_reference_token(xml, reference)
159
+ xml.tag! "token", reference
160
+ end
161
+
162
+ def add_address(xml, options)
163
+ address = options[:billing_address] || options[:address] || {}
164
+ xml.tag! "avsStreetAddress", address[:address1]
165
+ xml.tag! "avsStreetZipCode", address[:zip]
166
+ end
167
+
168
+ def add_payment_source(xml, source)
169
+ if source.is_a?(String)
170
+ add_reference_token(xml, source)
171
+ else
172
+ add_credit_card(xml, source)
173
+ end
174
+ end
175
+
176
+ def add_credit_card(xml, credit_card)
177
+ xml.tag! "cardNumber", credit_card.number
178
+ xml.tag! "expirationDate", expdate(credit_card)
179
+ xml.tag! "cardholder", credit_card.name
180
+ xml.tag! "cardSecurityCode", credit_card.verification_value if credit_card.verification_value?
181
+ end
182
+
183
+ def split_reference(reference)
184
+ reference.to_s.split(";")
185
+ end
186
+
187
+ def parse(action, data)
188
+ response = {}
189
+ xml = REXML::Document.new(data)
190
+
191
+ root = REXML::XPath.first(xml, "//#{ACTIONS[action]}Response/#{ACTIONS[action]}Result")
192
+
193
+ root.elements.each do |element|
194
+ response[element.name] = element.text
195
+ end
196
+
197
+ if response["ErrorMessage"].present?
198
+ response[:message] = response["ErrorMessage"]
199
+ response[:success] = false
200
+ else
201
+ status, code, message = response["ApprovalStatus"].split(";")
202
+ response[:status] = status
203
+
204
+ if response[:success] = status == "APPROVED"
205
+ response[:message] = status
206
+ else
207
+ response[:message] = message
208
+ response[:failure_code] = code
209
+ end
210
+ end
211
+
212
+ response
213
+ end
214
+
215
+ def parse_error(http_response, action)
216
+ response = {}
217
+ response[:http_code] = http_response.code
218
+ response[:http_message] = http_response.message
219
+ response[:success] = false
220
+
221
+ document = REXML::Document.new(http_response.body)
222
+ node = REXML::XPath.first(document, "//#{ACTIONS[action]}Response/#{ACTIONS[action]}Result")
223
+
224
+ node.elements.each do |element|
225
+ response[element.name] = element.text
226
+ end
227
+
228
+ response[:message] = response["ErrorMessage"].to_s.gsub("\n", " ")
229
+ response
230
+ rescue REXML::ParseException
231
+ response[:http_body] = http_response.body
232
+ response[:message] = "Failed to parse the failed response"
233
+ response
234
+ end
235
+
236
+ def soap_action(action)
237
+ "#{TX_NAMESPACE}#{ACTIONS[action]}"
238
+ end
239
+
240
+ def url
241
+ test? ? test_url : live_url
242
+ end
243
+
244
+ def commit(action, request)
245
+ begin
246
+ data = ssl_post(url, request,
247
+ "Content-Type" => 'text/xml; charset=utf-8',
248
+ "SOAPAction" => soap_action(action)
249
+ )
250
+ response = parse(action, data)
251
+ rescue ActiveMerchant::ResponseError => e
252
+ response = parse_error(e.response, action)
253
+ end
254
+
255
+ Response.new(response[:success], response[:message], response,
256
+ :test => test?,
257
+ :authorization => authorization_from(response),
258
+ :avs_result => { :code => response["AvsResponse"] },
259
+ :cvv_result => response["CvResponse"]
260
+ )
261
+ end
262
+
263
+ def authorization_from(response)
264
+ response['Token']
265
+ end
266
+ end
267
+ end
268
+ end
@@ -0,0 +1,195 @@
1
+ require 'digest/md5'
2
+ require 'rexml/document'
3
+
4
+ module ActiveMerchant #:nodoc:
5
+ module Billing #:nodoc:
6
+ class MerchantWarriorGateway < Gateway
7
+ TOKEN_TEST_URL = 'https://base.merchantwarrior.com/token/'
8
+ TOKEN_LIVE_URL = 'https://api.merchantwarrior.com/token/'
9
+
10
+ POST_TEST_URL = 'https://base.merchantwarrior.com/post/'
11
+ POST_LIVE_URL = 'https://api.merchantwarrior.com/post/'
12
+
13
+ self.supported_countries = ['AU']
14
+ self.supported_cardtypes = [:visa, :master, :american_express,
15
+ :diners_club, :discover]
16
+ self.homepage_url = 'http://www.merchantwarrior.com/'
17
+ self.display_name = 'MerchantWarrior'
18
+
19
+ self.money_format = :dollars
20
+ self.default_currency = 'AUD'
21
+
22
+ def initialize(options = {})
23
+ requires!(options, :merchant_uuid, :api_key, :api_passphrase)
24
+ super
25
+ end
26
+
27
+ def authorize(money, payment_method, options = {})
28
+ post = {}
29
+ add_amount(post, money, options)
30
+ add_product(post, options)
31
+ add_address(post, options)
32
+ add_payment_method(post, payment_method)
33
+ commit('processAuth', post)
34
+ end
35
+
36
+ def purchase(money, payment_method, options = {})
37
+ post = {}
38
+ add_amount(post, money, options)
39
+ add_product(post, options)
40
+ add_address(post, options)
41
+ add_payment_method(post, payment_method)
42
+ commit('processCard', post)
43
+ end
44
+
45
+ def capture(money, identification, options = {})
46
+ post = {}
47
+ add_amount(post, money, options)
48
+ add_transaction(post, identification)
49
+ post.merge!('captureAmount' => amount(money))
50
+ commit('processCapture', post)
51
+ end
52
+
53
+ def refund(money, identification, options = {})
54
+ post = {}
55
+ add_amount(post, money, options)
56
+ add_transaction(post, identification)
57
+ post['refundAmount'] = amount(money)
58
+ commit('refundCard', post)
59
+ end
60
+
61
+ def store(creditcard, options = {})
62
+ post = {
63
+ 'cardName' => scrub_name(creditcard.name),
64
+ 'cardNumber' => creditcard.number,
65
+ 'cardExpiryMonth' => format(creditcard.month, :two_digits),
66
+ 'cardExpiryYear' => format(creditcard.year, :two_digits)
67
+ }
68
+ commit('addCard', post)
69
+ end
70
+
71
+ private
72
+
73
+ def add_transaction(post, identification)
74
+ post['transactionID'] = identification
75
+ end
76
+
77
+ def add_address(post, options)
78
+ return unless(address = (options[:billing_address] || options[:address]))
79
+
80
+ post['customerName'] = scrub_name(address[:name])
81
+ post['customerCountry'] = address[:country]
82
+ post['customerState'] = address[:state]
83
+ post['customerCity'] = address[:city]
84
+ post['customerAddress'] = address[:address1]
85
+ post['customerPostCode'] = address[:zip]
86
+ end
87
+
88
+ def add_product(post, options)
89
+ post['transactionProduct'] = truncate(options[:description], 34)
90
+ end
91
+
92
+ def add_payment_method(post, payment_method)
93
+ if payment_method.respond_to?(:number)
94
+ add_creditcard(post, payment_method)
95
+ else
96
+ add_token(post, payment_method)
97
+ end
98
+ end
99
+
100
+ def add_token(post, token)
101
+ post['cardID'] = token
102
+ end
103
+
104
+ def add_creditcard(post, creditcard)
105
+ post['paymentCardNumber'] = creditcard.number
106
+ post['paymentCardName'] = scrub_name(creditcard.name)
107
+ post['paymentCardExpiry'] = creditcard.expiry_date.expiration.strftime("%m%y")
108
+ post['paymentCardCSC'] = creditcard.verification_value if creditcard.verification_value?
109
+ end
110
+
111
+ def scrub_name(name)
112
+ name.gsub(/[^a-zA-Z\. -]/, '')
113
+ end
114
+
115
+ def add_amount(post, money, options)
116
+ currency = (options[:currency] || currency(money))
117
+
118
+ post['transactionAmount'] = amount(money)
119
+ post['transactionCurrency'] = currency
120
+ post['hash'] = verification_hash(amount(money), currency)
121
+ end
122
+
123
+ def verification_hash(money, currency)
124
+ Digest::MD5.hexdigest(
125
+ (
126
+ @options[:api_passphrase].to_s +
127
+ @options[:merchant_uuid].to_s +
128
+ money.to_s +
129
+ currency
130
+ ).downcase
131
+ )
132
+ end
133
+
134
+ def parse(body)
135
+ xml = REXML::Document.new(body)
136
+
137
+ response = {}
138
+ xml.root.elements.to_a.each do |node|
139
+ parse_element(response, node)
140
+ end
141
+ response
142
+ end
143
+
144
+ def parse_element(response, node)
145
+ if node.has_elements?
146
+ node.elements.each{|element| parse_element(response, element)}
147
+ else
148
+ response[node.name.underscore.to_sym] = node.text
149
+ end
150
+ end
151
+
152
+ def commit(action, post)
153
+ add_auth(action, post)
154
+
155
+ response = parse(ssl_post(url_for(action, post), post_data(post)))
156
+
157
+ Response.new(
158
+ success?(response),
159
+ response[:response_message],
160
+ response,
161
+ :test => test?,
162
+ :authorization => (response[:card_id] || response[:transaction_id])
163
+ )
164
+ end
165
+
166
+ def add_auth(action, post)
167
+ post['merchantUUID'] = @options[:merchant_uuid]
168
+ post['apiKey'] = @options[:api_key]
169
+ unless token?(post)
170
+ post['method'] = action
171
+ end
172
+ end
173
+
174
+ def url_for(action, post)
175
+ if token?(post)
176
+ [(test? ? TOKEN_TEST_URL : TOKEN_LIVE_URL), action].join("/")
177
+ else
178
+ (test? ? POST_TEST_URL : POST_LIVE_URL)
179
+ end
180
+ end
181
+
182
+ def token?(post)
183
+ (post["cardID"] || post["cardName"])
184
+ end
185
+
186
+ def success?(response)
187
+ (response[:response_code] == '0')
188
+ end
189
+
190
+ def post_data(post)
191
+ post.collect{|k,v| "#{k}=#{CGI.escape(v.to_s)}" }.join("&")
192
+ end
193
+ end
194
+ end
195
+ end