active_accountability_merchant 1.97.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (259) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG +2948 -0
  3. data/CONTRIBUTORS +568 -0
  4. data/MIT-LICENSE +20 -0
  5. data/README.md +246 -0
  6. data/lib/active_merchant.rb +63 -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 +96 -0
  10. data/lib/active_merchant/billing/base.rb +61 -0
  11. data/lib/active_merchant/billing/check.rb +80 -0
  12. data/lib/active_merchant/billing/compatibility.rb +117 -0
  13. data/lib/active_merchant/billing/credit_card.rb +406 -0
  14. data/lib/active_merchant/billing/credit_card_formatting.rb +23 -0
  15. data/lib/active_merchant/billing/credit_card_methods.rb +343 -0
  16. data/lib/active_merchant/billing/cvv_result.rb +38 -0
  17. data/lib/active_merchant/billing/gateway.rb +330 -0
  18. data/lib/active_merchant/billing/gateways.rb +14 -0
  19. data/lib/active_merchant/billing/gateways/adyen.rb +503 -0
  20. data/lib/active_merchant/billing/gateways/allied_wallet.rb +205 -0
  21. data/lib/active_merchant/billing/gateways/authorize_net.rb +1055 -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 +980 -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/bambora_apac.rb +226 -0
  27. data/lib/active_merchant/billing/gateways/bank_frick.rb +225 -0
  28. data/lib/active_merchant/billing/gateways/banwire.rb +116 -0
  29. data/lib/active_merchant/billing/gateways/barclaycard_smartpay.rb +384 -0
  30. data/lib/active_merchant/billing/gateways/barclays_epdq_extra_plus.rb +15 -0
  31. data/lib/active_merchant/billing/gateways/be2bill.rb +131 -0
  32. data/lib/active_merchant/billing/gateways/beanstream.rb +217 -0
  33. data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +473 -0
  34. data/lib/active_merchant/billing/gateways/beanstream_interac.rb +57 -0
  35. data/lib/active_merchant/billing/gateways/blue_pay.rb +522 -0
  36. data/lib/active_merchant/billing/gateways/blue_snap.rb +522 -0
  37. data/lib/active_merchant/billing/gateways/bogus.rb +186 -0
  38. data/lib/active_merchant/billing/gateways/borgun.rb +220 -0
  39. data/lib/active_merchant/billing/gateways/bpoint.rb +277 -0
  40. data/lib/active_merchant/billing/gateways/braintree.rb +19 -0
  41. data/lib/active_merchant/billing/gateways/braintree/braintree_common.rb +22 -0
  42. data/lib/active_merchant/billing/gateways/braintree_blue.rb +740 -0
  43. data/lib/active_merchant/billing/gateways/braintree_orange.rb +19 -0
  44. data/lib/active_merchant/billing/gateways/bridge_pay.rb +244 -0
  45. data/lib/active_merchant/billing/gateways/cams.rb +230 -0
  46. data/lib/active_merchant/billing/gateways/card_connect.rb +316 -0
  47. data/lib/active_merchant/billing/gateways/card_save.rb +22 -0
  48. data/lib/active_merchant/billing/gateways/card_stream.rb +367 -0
  49. data/lib/active_merchant/billing/gateways/cardknox.rb +327 -0
  50. data/lib/active_merchant/billing/gateways/cardprocess.rb +254 -0
  51. data/lib/active_merchant/billing/gateways/cashnet.rb +219 -0
  52. data/lib/active_merchant/billing/gateways/cc5.rb +198 -0
  53. data/lib/active_merchant/billing/gateways/cecabank.rb +249 -0
  54. data/lib/active_merchant/billing/gateways/cenpos.rb +327 -0
  55. data/lib/active_merchant/billing/gateways/checkout.rb +214 -0
  56. data/lib/active_merchant/billing/gateways/checkout_v2.rb +270 -0
  57. data/lib/active_merchant/billing/gateways/citrus_pay.rb +22 -0
  58. data/lib/active_merchant/billing/gateways/clearhaus.rb +220 -0
  59. data/lib/active_merchant/billing/gateways/commercegate.rb +142 -0
  60. data/lib/active_merchant/billing/gateways/conekta.rb +228 -0
  61. data/lib/active_merchant/billing/gateways/creditcall.rb +271 -0
  62. data/lib/active_merchant/billing/gateways/credorax.rb +382 -0
  63. data/lib/active_merchant/billing/gateways/ct_payment.rb +268 -0
  64. data/lib/active_merchant/billing/gateways/culqi.rb +277 -0
  65. data/lib/active_merchant/billing/gateways/cyber_source.rb +828 -0
  66. data/lib/active_merchant/billing/gateways/d_local.rb +226 -0
  67. data/lib/active_merchant/billing/gateways/data_cash.rb +305 -0
  68. data/lib/active_merchant/billing/gateways/decidir.rb +233 -0
  69. data/lib/active_merchant/billing/gateways/dibs.rb +199 -0
  70. data/lib/active_merchant/billing/gateways/digitzs.rb +292 -0
  71. data/lib/active_merchant/billing/gateways/ebanx.rb +296 -0
  72. data/lib/active_merchant/billing/gateways/efsnet.rb +215 -0
  73. data/lib/active_merchant/billing/gateways/elavon.rb +320 -0
  74. data/lib/active_merchant/billing/gateways/element.rb +356 -0
  75. data/lib/active_merchant/billing/gateways/epay.rb +285 -0
  76. data/lib/active_merchant/billing/gateways/evo_ca.rb +308 -0
  77. data/lib/active_merchant/billing/gateways/eway.rb +226 -0
  78. data/lib/active_merchant/billing/gateways/eway_managed.rb +290 -0
  79. data/lib/active_merchant/billing/gateways/eway_rapid.rb +563 -0
  80. data/lib/active_merchant/billing/gateways/exact.rb +224 -0
  81. data/lib/active_merchant/billing/gateways/ezic.rb +195 -0
  82. data/lib/active_merchant/billing/gateways/fat_zebra.rb +218 -0
  83. data/lib/active_merchant/billing/gateways/federated_canada.rb +159 -0
  84. data/lib/active_merchant/billing/gateways/finansbank.rb +22 -0
  85. data/lib/active_merchant/billing/gateways/first_giving.rb +142 -0
  86. data/lib/active_merchant/billing/gateways/first_pay.rb +182 -0
  87. data/lib/active_merchant/billing/gateways/firstdata_e4.rb +451 -0
  88. data/lib/active_merchant/billing/gateways/firstdata_e4_v27.rb +485 -0
  89. data/lib/active_merchant/billing/gateways/flo2cash.rb +215 -0
  90. data/lib/active_merchant/billing/gateways/flo2cash_simple.rb +20 -0
  91. data/lib/active_merchant/billing/gateways/forte.rb +270 -0
  92. data/lib/active_merchant/billing/gateways/garanti.rb +259 -0
  93. data/lib/active_merchant/billing/gateways/global_collect.rb +336 -0
  94. data/lib/active_merchant/billing/gateways/global_transport.rb +194 -0
  95. data/lib/active_merchant/billing/gateways/hdfc.rb +206 -0
  96. data/lib/active_merchant/billing/gateways/hps.rb +350 -0
  97. data/lib/active_merchant/billing/gateways/iats_payments.rb +290 -0
  98. data/lib/active_merchant/billing/gateways/in_context_paypal_express.rb +15 -0
  99. data/lib/active_merchant/billing/gateways/inspire.rb +218 -0
  100. data/lib/active_merchant/billing/gateways/instapay.rb +162 -0
  101. data/lib/active_merchant/billing/gateways/ipp.rb +176 -0
  102. data/lib/active_merchant/billing/gateways/iridium.rb +468 -0
  103. data/lib/active_merchant/billing/gateways/itransact.rb +447 -0
  104. data/lib/active_merchant/billing/gateways/iveri.rb +251 -0
  105. data/lib/active_merchant/billing/gateways/jetpay.rb +402 -0
  106. data/lib/active_merchant/billing/gateways/jetpay_v2.rb +437 -0
  107. data/lib/active_merchant/billing/gateways/komoju.rb +115 -0
  108. data/lib/active_merchant/billing/gateways/kushki.rb +219 -0
  109. data/lib/active_merchant/billing/gateways/latitude19.rb +411 -0
  110. data/lib/active_merchant/billing/gateways/linkpoint.rb +449 -0
  111. data/lib/active_merchant/billing/gateways/litle.rb +507 -0
  112. data/lib/active_merchant/billing/gateways/mastercard.rb +267 -0
  113. data/lib/active_merchant/billing/gateways/maxipago.rb +220 -0
  114. data/lib/active_merchant/billing/gateways/mercado_pago.rb +277 -0
  115. data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +194 -0
  116. data/lib/active_merchant/billing/gateways/merchant_one.rb +113 -0
  117. data/lib/active_merchant/billing/gateways/merchant_partners.rb +245 -0
  118. data/lib/active_merchant/billing/gateways/merchant_ware.rb +319 -0
  119. data/lib/active_merchant/billing/gateways/merchant_ware_version_four.rb +286 -0
  120. data/lib/active_merchant/billing/gateways/merchant_warrior.rb +210 -0
  121. data/lib/active_merchant/billing/gateways/mercury.rb +356 -0
  122. data/lib/active_merchant/billing/gateways/metrics_global.rb +303 -0
  123. data/lib/active_merchant/billing/gateways/micropayment.rb +183 -0
  124. data/lib/active_merchant/billing/gateways/migs.rb +332 -0
  125. data/lib/active_merchant/billing/gateways/migs/migs_codes.rb +100 -0
  126. data/lib/active_merchant/billing/gateways/modern_payments.rb +37 -0
  127. data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +217 -0
  128. data/lib/active_merchant/billing/gateways/monei.rb +338 -0
  129. data/lib/active_merchant/billing/gateways/moneris.rb +377 -0
  130. data/lib/active_merchant/billing/gateways/moneris_us.rb +352 -0
  131. data/lib/active_merchant/billing/gateways/money_movers.rb +151 -0
  132. data/lib/active_merchant/billing/gateways/mundipagg.rb +293 -0
  133. data/lib/active_merchant/billing/gateways/nab_transact.rb +301 -0
  134. data/lib/active_merchant/billing/gateways/ncr_secure_pay.rb +165 -0
  135. data/lib/active_merchant/billing/gateways/net_registry.rb +199 -0
  136. data/lib/active_merchant/billing/gateways/netaxept.rb +180 -0
  137. data/lib/active_merchant/billing/gateways/netbanx.rb +294 -0
  138. data/lib/active_merchant/billing/gateways/netbilling.rb +232 -0
  139. data/lib/active_merchant/billing/gateways/netpay.rb +222 -0
  140. data/lib/active_merchant/billing/gateways/network_merchants.rb +241 -0
  141. data/lib/active_merchant/billing/gateways/nmi.rb +324 -0
  142. data/lib/active_merchant/billing/gateways/ogone.rb +478 -0
  143. data/lib/active_merchant/billing/gateways/omise.rb +324 -0
  144. data/lib/active_merchant/billing/gateways/openpay.rb +228 -0
  145. data/lib/active_merchant/billing/gateways/opp.rb +388 -0
  146. data/lib/active_merchant/billing/gateways/optimal_payment.rb +332 -0
  147. data/lib/active_merchant/billing/gateways/orbital.rb +1006 -0
  148. data/lib/active_merchant/billing/gateways/orbital/orbital_soft_descriptors.rb +47 -0
  149. data/lib/active_merchant/billing/gateways/pac_net_raven.rb +206 -0
  150. data/lib/active_merchant/billing/gateways/pagarme.rb +246 -0
  151. data/lib/active_merchant/billing/gateways/pago_facil.rb +122 -0
  152. data/lib/active_merchant/billing/gateways/pay_conex.rb +245 -0
  153. data/lib/active_merchant/billing/gateways/pay_gate_xml.rb +280 -0
  154. data/lib/active_merchant/billing/gateways/pay_hub.rb +213 -0
  155. data/lib/active_merchant/billing/gateways/pay_junction.rb +390 -0
  156. data/lib/active_merchant/billing/gateways/pay_junction_v2.rb +188 -0
  157. data/lib/active_merchant/billing/gateways/pay_secure.rb +111 -0
  158. data/lib/active_merchant/billing/gateways/paybox_direct.rb +200 -0
  159. data/lib/active_merchant/billing/gateways/payeezy.rb +410 -0
  160. data/lib/active_merchant/billing/gateways/payex.rb +410 -0
  161. data/lib/active_merchant/billing/gateways/payflow.rb +383 -0
  162. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +235 -0
  163. data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +43 -0
  164. data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +13 -0
  165. data/lib/active_merchant/billing/gateways/payflow_express.rb +220 -0
  166. data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +14 -0
  167. data/lib/active_merchant/billing/gateways/payflow_uk.rb +20 -0
  168. data/lib/active_merchant/billing/gateways/payment_express.rb +369 -0
  169. data/lib/active_merchant/billing/gateways/paymentez.rb +300 -0
  170. data/lib/active_merchant/billing/gateways/paymill.rb +371 -0
  171. data/lib/active_merchant/billing/gateways/paypal.rb +128 -0
  172. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +717 -0
  173. data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +65 -0
  174. data/lib/active_merchant/billing/gateways/paypal/paypal_recurring_api.rb +262 -0
  175. data/lib/active_merchant/billing/gateways/paypal_ca.rb +13 -0
  176. data/lib/active_merchant/billing/gateways/paypal_digital_goods.rb +44 -0
  177. data/lib/active_merchant/billing/gateways/paypal_express.rb +269 -0
  178. data/lib/active_merchant/billing/gateways/paypal_express_common.rb +30 -0
  179. data/lib/active_merchant/billing/gateways/payscout.rb +160 -0
  180. data/lib/active_merchant/billing/gateways/paystation.rb +207 -0
  181. data/lib/active_merchant/billing/gateways/payu_in.rb +248 -0
  182. data/lib/active_merchant/billing/gateways/payu_latam.rb +449 -0
  183. data/lib/active_merchant/billing/gateways/payway.rb +207 -0
  184. data/lib/active_merchant/billing/gateways/pin.rb +234 -0
  185. data/lib/active_merchant/billing/gateways/plugnpay.rb +284 -0
  186. data/lib/active_merchant/billing/gateways/pro_pay.rb +326 -0
  187. data/lib/active_merchant/billing/gateways/psigate.rb +227 -0
  188. data/lib/active_merchant/billing/gateways/psl_card.rb +296 -0
  189. data/lib/active_merchant/billing/gateways/qbms.rb +303 -0
  190. data/lib/active_merchant/billing/gateways/quantum.rb +276 -0
  191. data/lib/active_merchant/billing/gateways/quickbooks.rb +290 -0
  192. data/lib/active_merchant/billing/gateways/quickpay.rb +25 -0
  193. data/lib/active_merchant/billing/gateways/quickpay/quickpay_common.rb +184 -0
  194. data/lib/active_merchant/billing/gateways/quickpay/quickpay_v10.rb +301 -0
  195. data/lib/active_merchant/billing/gateways/quickpay/quickpay_v4to7.rb +226 -0
  196. data/lib/active_merchant/billing/gateways/qvalent.rb +289 -0
  197. data/lib/active_merchant/billing/gateways/realex.rb +374 -0
  198. data/lib/active_merchant/billing/gateways/redsys.rb +534 -0
  199. data/lib/active_merchant/billing/gateways/s5.rb +246 -0
  200. data/lib/active_merchant/billing/gateways/safe_charge.rb +262 -0
  201. data/lib/active_merchant/billing/gateways/sage.rb +448 -0
  202. data/lib/active_merchant/billing/gateways/sage_pay.rb +434 -0
  203. data/lib/active_merchant/billing/gateways/sallie_mae.rb +142 -0
  204. data/lib/active_merchant/billing/gateways/secure_net.rb +267 -0
  205. data/lib/active_merchant/billing/gateways/secure_pay.rb +200 -0
  206. data/lib/active_merchant/billing/gateways/secure_pay_au.rb +292 -0
  207. data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +104 -0
  208. data/lib/active_merchant/billing/gateways/securion_pay.rb +264 -0
  209. data/lib/active_merchant/billing/gateways/skip_jack.rb +450 -0
  210. data/lib/active_merchant/billing/gateways/smart_ps.rb +280 -0
  211. data/lib/active_merchant/billing/gateways/so_easy_pay.rb +194 -0
  212. data/lib/active_merchant/billing/gateways/spreedly_core.rb +306 -0
  213. data/lib/active_merchant/billing/gateways/stripe.rb +790 -0
  214. data/lib/active_merchant/billing/gateways/stripe_payment_intents.rb +267 -0
  215. data/lib/active_merchant/billing/gateways/swipe_checkout.rb +152 -0
  216. data/lib/active_merchant/billing/gateways/telr.rb +274 -0
  217. data/lib/active_merchant/billing/gateways/tns.rb +22 -0
  218. data/lib/active_merchant/billing/gateways/trans_first.rb +239 -0
  219. data/lib/active_merchant/billing/gateways/trans_first_transaction_express.rb +608 -0
  220. data/lib/active_merchant/billing/gateways/transact_pro.rb +224 -0
  221. data/lib/active_merchant/billing/gateways/transax.rb +22 -0
  222. data/lib/active_merchant/billing/gateways/transnational.rb +9 -0
  223. data/lib/active_merchant/billing/gateways/trexle.rb +218 -0
  224. data/lib/active_merchant/billing/gateways/trust_commerce.rb +490 -0
  225. data/lib/active_merchant/billing/gateways/usa_epay.rb +25 -0
  226. data/lib/active_merchant/billing/gateways/usa_epay_advanced.rb +1620 -0
  227. data/lib/active_merchant/billing/gateways/usa_epay_transaction.rb +355 -0
  228. data/lib/active_merchant/billing/gateways/vanco.rb +294 -0
  229. data/lib/active_merchant/billing/gateways/verifi.rb +225 -0
  230. data/lib/active_merchant/billing/gateways/viaklix.rb +176 -0
  231. data/lib/active_merchant/billing/gateways/visanet_peru.rb +245 -0
  232. data/lib/active_merchant/billing/gateways/webpay.rb +97 -0
  233. data/lib/active_merchant/billing/gateways/wepay.rb +237 -0
  234. data/lib/active_merchant/billing/gateways/wirecard.rb +432 -0
  235. data/lib/active_merchant/billing/gateways/world_net.rb +344 -0
  236. data/lib/active_merchant/billing/gateways/worldpay.rb +634 -0
  237. data/lib/active_merchant/billing/gateways/worldpay_online_payments.rb +215 -0
  238. data/lib/active_merchant/billing/gateways/worldpay_us.rb +221 -0
  239. data/lib/active_merchant/billing/model.rb +30 -0
  240. data/lib/active_merchant/billing/network_tokenization_credit_card.rb +39 -0
  241. data/lib/active_merchant/billing/payment_token.rb +21 -0
  242. data/lib/active_merchant/billing/rails.rb +3 -0
  243. data/lib/active_merchant/billing/response.rb +92 -0
  244. data/lib/active_merchant/connection.rb +195 -0
  245. data/lib/active_merchant/country.rb +336 -0
  246. data/lib/active_merchant/empty.rb +20 -0
  247. data/lib/active_merchant/errors.rb +35 -0
  248. data/lib/active_merchant/net_http_ssl_connection.rb +10 -0
  249. data/lib/active_merchant/network_connection_retries.rb +80 -0
  250. data/lib/active_merchant/post_data.rb +25 -0
  251. data/lib/active_merchant/posts_data.rb +92 -0
  252. data/lib/active_merchant/version.rb +3 -0
  253. data/lib/activemerchant.rb +1 -0
  254. data/lib/certs/cacert.pem +3988 -0
  255. data/lib/support/gateway_support.rb +69 -0
  256. data/lib/support/outbound_hosts.rb +28 -0
  257. data/lib/support/ssl_verify.rb +92 -0
  258. data/lib/support/ssl_version.rb +87 -0
  259. metadata +435 -0
@@ -0,0 +1,447 @@
1
+ require 'nokogiri'
2
+
3
+ module ActiveMerchant #:nodoc:
4
+ module Billing #:nodoc:
5
+ # iTransact, Inc. is an authorized reseller of the PaymentClearing gateway. If your merchant service provider uses PaymentClearing.com to process payments, you can use this module.
6
+ #
7
+ #
8
+ # Please note, the username and API Access Key are not what you use to log into the Merchant Control Panel.
9
+ #
10
+ # ==== How to get your GatewayID and API Access Key
11
+ #
12
+ # 1. If you don't already have a Gateway Account, go to http://www.itransact.com/merchant/test.html to sign up.
13
+ # 2. Go to http://support.paymentclearing.com and login or register, if necessary.
14
+ # 3. Click on "Submit a Ticket."
15
+ # 4. Select "Merchant Support" as the department and click "Next"
16
+ # 5. Enter *both* your company name and GatewayID. Put "API Access Key" in the subject. In the body, you can request a username, but it may already be in use.
17
+ #
18
+ # ==== Initialization
19
+ #
20
+ # Once you have the username, API Access Key, and your GatewayId, you're ready
21
+ # to begin. You initialize the Gateway like so:
22
+ #
23
+ # gateway = ActiveMerchant::Billing::ItransactGateway.new(
24
+ # :login => "#{THE_USERNAME}",
25
+ # :password => "#{THE_API_ACCESS_KEY}",
26
+ # :gateway_id => "#{THE_GATEWAY_ID}"
27
+ # )
28
+ #
29
+ # ==== Important Notes
30
+ # 1. Recurring is not implemented
31
+ # 1. CreditTransactions are not implemented (these are credits not related to a previously run transaction).
32
+ # 1. TransactionStatus is not implemented
33
+ #
34
+ class ItransactGateway < Gateway
35
+ self.live_url = self.test_url = 'https://secure.paymentclearing.com/cgi-bin/rc/xmltrans2.cgi'
36
+
37
+ # The countries the gateway supports merchants from as 2 digit ISO country codes
38
+ self.supported_countries = ['US']
39
+
40
+ # The card types supported by the payment gateway
41
+ self.supported_cardtypes = [:visa, :master, :american_express, :discover]
42
+
43
+ # The homepage URL of the gateway
44
+ self.homepage_url = 'http://www.itransact.com/'
45
+
46
+ # The name of the gateway
47
+ self.display_name = 'iTransact'
48
+
49
+ #
50
+ # Creates a new instance of the iTransact Gateway.
51
+ #
52
+ # ==== Parameters
53
+ # * <tt>options</tt> - A Hash of options
54
+ #
55
+ # ==== Options Hash
56
+ # * <tt>:login</tt> - A String containing your PaymentClearing assigned API Access Username
57
+ # * <tt>:password</tt> - A String containing your PaymentClearing assigned API Access Key
58
+ # * <tt>:gateway_id</tt> - A String containing your PaymentClearing assigned GatewayID
59
+ # * <tt>:test_mode</tt> - <tt>true</tt> or <tt>false</tt>. Run *all* transactions with the 'TestMode' element set to 'TRUE'.
60
+ #
61
+ def initialize(options = {})
62
+ requires!(options, :login, :password, :gateway_id)
63
+ super
64
+ end
65
+
66
+ # Performs an authorize transaction. In PaymentClearing's documentation
67
+ # this is known as a "PreAuth" transaction.
68
+ #
69
+ # ==== Parameters
70
+ # * <tt>money</tt> - The amount to be captured. Should be an Integer amount in cents.
71
+ # * <tt>creditcard</tt> - The CreditCard details for the transaction
72
+ # * <tt>options</tt> - A Hash of options
73
+ #
74
+ # ==== Options Hash
75
+ # The standard options apply here (:order_id, :ip, :customer, :invoice, :merchant, :description, :email, :currency, :address, :billing_address, :shipping_address), as well as:
76
+ # * <tt>:order_items</tt> - An Array of Hash objects with the keys <tt>:description</tt>, <tt>:cost</tt> (in cents!), and <tt>:quantity</tt>. If this is provided, <tt>:description</tt> and <tt>money</tt> will be ignored.
77
+ # * <tt>:vendor_data</tt> - An Array of Hash objects with the keys being the name of the VendorData element and value being the value.
78
+ # * <tt>:send_customer_email</tt> - <tt>true</tt> or <tt>false</tt>. Runs the transaction with the 'SendCustomerEmail' element set to 'TRUE' or 'FALSE'.
79
+ # * <tt>:send_merchant_email</tt> - <tt>true</tt> or <tt>false</tt>. Runs the transaction with the 'SendMerchantEmail' element set to 'TRUE' or 'FALSE'.
80
+ # * <tt>:email_text</tt> - An Array of (up to ten (10)) String objects to be included in emails
81
+ # * <tt>:test_mode</tt> - <tt>true</tt> or <tt>false</tt>. Runs the transaction with the 'TestMode' element set to 'TRUE' or 'FALSE'.
82
+ #
83
+ # ==== Examples
84
+ # response = gateway.authorize(1000, creditcard,
85
+ # :order_id => '1212', :address => {...}, :email => 'test@test.com',
86
+ # :order_items => [
87
+ # {:description => 'Line Item 1', :cost => '8.98', :quantity => '6'},
88
+ # {:description => 'Line Item 2', :cost => '6.99', :quantity => '4'}
89
+ # ],
90
+ # :vendor_data => [{'repId' => '1234567'}, {'customerId' => '9886'}],
91
+ # :send_customer_email => true,
92
+ # :send_merchant_email => true,
93
+ # :email_text => ['line1', 'line2', 'line3'],
94
+ # :test_mode => true
95
+ # )
96
+ #
97
+ def authorize(money, payment_source, options = {})
98
+ payload = Nokogiri::XML::Builder.new do |xml|
99
+ xml.AuthTransaction {
100
+ xml.Preauth
101
+ add_customer_data(xml, payment_source, options)
102
+ add_invoice(xml, money, options)
103
+ add_payment_source(xml, payment_source)
104
+ add_transaction_control(xml, options)
105
+ add_vendor_data(xml, options)
106
+ }
107
+ end.doc
108
+
109
+ commit(payload)
110
+ end
111
+
112
+ # Performs an authorize and capture in single transaction. In PaymentClearing's
113
+ # documentation this is known as an "Auth" or a "Sale" transaction
114
+ #
115
+ # ==== Parameters
116
+ # * <tt>money</tt> - The amount to be captured. Should be <tt>nil</tt> or an Integer amount in cents.
117
+ # * <tt>creditcard</tt> - The CreditCard details for the transaction
118
+ # * <tt>options</tt> - A Hash of options
119
+ #
120
+ # ==== Options Hash
121
+ # The standard options apply here (:order_id, :ip, :customer, :invoice, :merchant, :description, :email, :currency, :address, :billing_address, :shipping_address), as well as:
122
+ # * <tt>:order_items</tt> - An Array of Hash objects with the keys <tt>:description</tt>, <tt>:cost</tt> (in cents!), and <tt>:quantity</tt>. If this is provided, <tt>:description</tt> and <tt>money</tt> will be ignored.
123
+ # * <tt>:vendor_data</tt> - An Array of Hash objects with the keys being the name of the VendorData element and value being the value.
124
+ # * <tt>:send_customer_email</tt> - <tt>true</tt> or <tt>false</tt>. Runs the transaction with the 'SendCustomerEmail' element set to 'TRUE' or 'FALSE'.
125
+ # * <tt>:send_merchant_email</tt> - <tt>true</tt> or <tt>false</tt>. Runs the transaction with the 'SendMerchantEmail' element set to 'TRUE' or 'FALSE'.
126
+ # * <tt>:email_text</tt> - An Array of (up to ten (10)) String objects to be included in emails
127
+ # * <tt>:test_mode</tt> - <tt>true</tt> or <tt>false</tt>. Runs the transaction with the 'TestMode' element set to 'TRUE' or 'FALSE'.
128
+ #
129
+ # ==== Examples
130
+ # response = gateway.purchase(1000, creditcard,
131
+ # :order_id => '1212', :address => {...}, :email => 'test@test.com',
132
+ # :order_items => [
133
+ # {:description => 'Line Item 1', :cost => '8.98', :quantity => '6'},
134
+ # {:description => 'Line Item 2', :cost => '6.99', :quantity => '4'}
135
+ # ],
136
+ # :vendor_data => [{'repId' => '1234567'}, {'customerId' => '9886'}],
137
+ # :send_customer_email => true,
138
+ # :send_merchant_email => true,
139
+ # :email_text => ['line1', 'line2', 'line3'],
140
+ # :test_mode => true
141
+ # )
142
+ #
143
+ def purchase(money, payment_source, options = {})
144
+ payload = Nokogiri::XML::Builder.new do |xml|
145
+ xml.AuthTransaction {
146
+ add_customer_data(xml, payment_source, options)
147
+ add_invoice(xml, money, options)
148
+ add_payment_source(xml, payment_source)
149
+ add_transaction_control(xml, options)
150
+ add_vendor_data(xml, options)
151
+ }
152
+ end.doc
153
+
154
+ commit(payload)
155
+ end
156
+
157
+ # Captures the funds from an authorize transaction. In PaymentClearing's
158
+ # documentation this is known as a "PostAuth" transaction.
159
+ #
160
+ # ==== Parameters
161
+ # * <tt>money</tt> - The amount to be captured. Should be an Integer amount in cents
162
+ # * <tt>authorization</tt> - The authorization returned from the previous capture or purchase request
163
+ # * <tt>options</tt> - A Hash of options, all are optional.
164
+ #
165
+ # ==== Options Hash
166
+ # The standard options apply here (:order_id, :ip, :customer, :invoice, :merchant, :description, :email, :currency, :address, :billing_address, :shipping_address), as well as:
167
+ # * <tt>:vendor_data</tt> - An Array of Hash objects with the keys being the name of the VendorData element and value being the value.
168
+ # * <tt>:send_customer_email</tt> - <tt>true</tt> or <tt>false</tt>. Runs the transaction with the 'SendCustomerEmail' element set to 'TRUE' or 'FALSE'.
169
+ # * <tt>:send_merchant_email</tt> - <tt>true</tt> or <tt>false</tt>. Runs the transaction with the 'SendMerchantEmail' element set to 'TRUE' or 'FALSE'.
170
+ # * <tt>:email_text</tt> - An Array of (up to ten (10)) String objects to be included in emails
171
+ # * <tt>:test_mode</tt> - <tt>true</tt> or <tt>false</tt>. Runs the transaction with the 'TestMode' element set to 'TRUE' or 'FALSE'.
172
+ #
173
+ # ==== Examples
174
+ # response = gateway.capture(1000, creditcard,
175
+ # :vendor_data => [{'repId' => '1234567'}, {'customerId' => '9886'}],
176
+ # :send_customer_email => true,
177
+ # :send_merchant_email => true,
178
+ # :email_text => ['line1', 'line2', 'line3'],
179
+ # :test_mode => true
180
+ # )
181
+ #
182
+ def capture(money, authorization, options = {})
183
+ payload = Nokogiri::XML::Builder.new do |xml|
184
+ xml.PostAuthTransaction {
185
+ xml.OperationXID(authorization)
186
+ add_invoice(xml, money, options)
187
+ add_transaction_control(xml, options)
188
+ add_vendor_data(xml, options)
189
+ }
190
+ end.doc
191
+
192
+ commit(payload)
193
+ end
194
+
195
+ # This will reverse a previously run transaction which *has* *not* settled.
196
+ #
197
+ # ==== Parameters
198
+ # * <tt>authorization</tt> - The authorization returned from the previous capture or purchase request
199
+ # * <tt>options</tt> - A Hash of options, all are optional
200
+ #
201
+ # ==== Options Hash
202
+ # The standard options (:order_id, :ip, :customer, :invoice, :merchant, :description, :email, :currency, :address, :billing_address, :shipping_address) are ignored.
203
+ # * <tt>:vendor_data</tt> - An Array of Hash objects with the keys being the name of the VendorData element and value being the value.
204
+ # * <tt>:send_customer_email</tt> - <tt>true</tt> or <tt>false</tt>. Runs the transaction with the 'SendCustomerEmail' element set to 'TRUE' or 'FALSE'.
205
+ # * <tt>:send_merchant_email</tt> - <tt>true</tt> or <tt>false</tt>. Runs the transaction with the 'SendMerchantEmail' element set to 'TRUE' or 'FALSE'.
206
+ # * <tt>:email_text</tt> - An Array of (up to ten (10)) String objects to be included in emails
207
+ # * <tt>:test_mode</tt> - <tt>true</tt> or <tt>false</tt>. Runs the transaction with the 'TestMode' element set to 'TRUE' or 'FALSE'.
208
+ #
209
+ # ==== Examples
210
+ # response = gateway.void('9999999999',
211
+ # :vendor_data => [{'repId' => '1234567'}, {'customerId' => '9886'}],
212
+ # :send_customer_email => true,
213
+ # :send_merchant_email => true,
214
+ # :email_text => ['line1', 'line2', 'line3'],
215
+ # :test_mode => true
216
+ # )
217
+ #
218
+ def void(authorization, options = {})
219
+ payload = Nokogiri::XML::Builder.new do |xml|
220
+ xml.VoidTransaction {
221
+ xml.OperationXID(authorization)
222
+ add_transaction_control(xml, options)
223
+ add_vendor_data(xml, options)
224
+ }
225
+ end.doc
226
+
227
+ commit(payload)
228
+ end
229
+
230
+ # This will reverse a previously run transaction which *has* settled.
231
+ #
232
+ # ==== Parameters
233
+ # * <tt>money</tt> - The amount to be credited. Should be an Integer amount in cents
234
+ # * <tt>authorization</tt> - The authorization returned from the previous capture or purchase request
235
+ # * <tt>options</tt> - A Hash of options, all are optional
236
+ #
237
+ # ==== Options Hash
238
+ # The standard options (:order_id, :ip, :customer, :invoice, :merchant, :description, :email, :currency, :address, :billing_address, :shipping_address) are ignored.
239
+ # * <tt>:vendor_data</tt> - An Array of Hash objects with the keys being the name of the VendorData element and value being the value.
240
+ # * <tt>:send_customer_email</tt> - <tt>true</tt> or <tt>false</tt>. Runs the transaction with the 'SendCustomerEmail' element set to 'TRUE' or 'FALSE'.
241
+ # * <tt>:send_merchant_email</tt> - <tt>true</tt> or <tt>false</tt>. Runs the transaction with the 'SendMerchantEmail' element set to 'TRUE' or 'FALSE'.
242
+ # * <tt>:email_text</tt> - An Array of (up to ten (10)) String objects to be included in emails
243
+ # * <tt>:test_mode</tt> - <tt>true</tt> or <tt>false</tt>. Runs the transaction with the 'TestMode' element set to 'TRUE' or 'FALSE'.
244
+ #
245
+ # ==== Examples
246
+ # response = gateway.refund(555, '9999999999',
247
+ # :vendor_data => [{'repId' => '1234567'}, {'customerId' => '9886'}],
248
+ # :send_customer_email => true,
249
+ # :send_merchant_email => true,
250
+ # :email_text => ['line1', 'line2', 'line3'],
251
+ # :test_mode => true
252
+ # )
253
+ #
254
+ def refund(money, authorization, options = {})
255
+ payload = Nokogiri::XML::Builder.new do |xml|
256
+ xml.TranCredTransaction {
257
+ xml.OperationXID(authorization)
258
+ add_invoice(xml, money, options)
259
+ add_transaction_control(xml, options)
260
+ add_vendor_data(xml, options)
261
+ }
262
+ end.doc
263
+
264
+ commit(payload)
265
+ end
266
+
267
+ private
268
+
269
+ def add_customer_data(xml, payment_source, options)
270
+ billing_address = options[:billing_address] || options[:address]
271
+ shipping_address = options[:shipping_address] || options[:address]
272
+
273
+ xml.CustomerData {
274
+ xml.Email(options[:email]) unless options[:email].blank?
275
+ xml.CustId(options[:order_id]) unless options[:order_id].blank?
276
+ xml.BillingAddress {
277
+ xml.FirstName(payment_source.first_name || parse_first_name(billing_address[:name]))
278
+ xml.LastName(payment_source.last_name || parse_last_name(billing_address[:name]))
279
+ xml.Address1(billing_address[:address1])
280
+ xml.Address2(billing_address[:address2]) unless billing_address[:address2].blank?
281
+ xml.City(billing_address[:city])
282
+ xml.State(billing_address[:state])
283
+ xml.Zip(billing_address[:zip])
284
+ xml.Country(billing_address[:country])
285
+ xml.Phone(billing_address[:phone])
286
+ }
287
+ xml.ShippingAddress {
288
+ xml.FirstName(payment_source.first_name || parse_first_name(shipping_address[:name]))
289
+ xml.LastName(payment_source.last_name || parse_last_name(shipping_address[:name]))
290
+ xml.Address1(shipping_address[:address1])
291
+ xml.Address2(shipping_address[:address2]) unless shipping_address[:address2].blank?
292
+ xml.City(shipping_address[:city])
293
+ xml.State(shipping_address[:state])
294
+ xml.Zip(shipping_address[:zip])
295
+ xml.Country(shipping_address[:country])
296
+ xml.Phone(shipping_address[:phone])
297
+ } unless shipping_address.blank?
298
+ }
299
+ end
300
+
301
+ def add_invoice(xml, money, options)
302
+ xml.AuthCode options[:force] if options[:force]
303
+ if options[:order_items].blank?
304
+ xml.Total(amount(money)) unless(money.nil? || money < 0.01)
305
+ xml.Description(options[:description]) unless(options[:description].blank?)
306
+ else
307
+ xml.OrderItems {
308
+ options[:order_items].each do |item|
309
+ xml.Item {
310
+ xml.Description(item[:description])
311
+ xml.Cost(amount(item[:cost]))
312
+ xml.Qty(item[:quantity].to_s)
313
+ }
314
+ end
315
+ }
316
+ end
317
+ end
318
+
319
+ def add_payment_source(xml, source)
320
+ case determine_funding_source(source)
321
+ when :credit_card then add_creditcard(xml, source)
322
+ when :check then add_check(xml, source)
323
+ end
324
+ end
325
+
326
+ def determine_funding_source(payment_source)
327
+ case payment_source
328
+ when ActiveMerchant::Billing::CreditCard
329
+ :credit_card
330
+ when ActiveMerchant::Billing::Check
331
+ :check
332
+ end
333
+ end
334
+
335
+ def add_creditcard(xml, creditcard)
336
+ xml.AccountInfo {
337
+ xml.CardAccount {
338
+ xml.AccountNumber(creditcard.number.to_s)
339
+ xml.ExpirationMonth(creditcard.month.to_s.rjust(2, '0'))
340
+ xml.ExpirationYear(creditcard.year.to_s)
341
+ xml.CVVNumber(creditcard.verification_value.to_s) unless creditcard.verification_value.blank?
342
+ }
343
+ }
344
+ end
345
+
346
+ def add_check(xml, check)
347
+ xml.AccountInfo {
348
+ xml.ABA(check.routing_number.to_s)
349
+ xml.AccountNumber(check.account_number.to_s)
350
+ xml.AccountSource(check.account_type.to_s)
351
+ xml.AccountType(check.account_holder_type.to_s)
352
+ xml.CheckNumber(check.number.to_s)
353
+ }
354
+ end
355
+
356
+ def add_transaction_control(xml, options)
357
+ xml.TransactionControl {
358
+ # if there was a 'global' option set...
359
+ xml.TestMode(@options[:test_mode].upcase) if !@options[:test_mode].blank?
360
+ # allow the global option to be overridden...
361
+ xml.TestMode(options[:test_mode].upcase) if !options[:test_mode].blank?
362
+ xml.SendCustomerEmail(options[:send_customer_email].upcase) unless options[:send_customer_email].blank?
363
+ xml.SendMerchantEmail(options[:send_merchant_email].upcase) unless options[:send_merchant_email].blank?
364
+ xml.EmailText {
365
+ options[:email_text].each do |item|
366
+ xml.EmailTextItem(item)
367
+ end
368
+ } if options[:email_text]
369
+ }
370
+ end
371
+
372
+ def add_vendor_data(xml, options)
373
+ return if options[:vendor_data].blank?
374
+ xml.VendorData {
375
+ options[:vendor_data].each do |k, v|
376
+ xml.Element {
377
+ xml.Name(k)
378
+ xml.Key(v)
379
+ }
380
+ end
381
+ }
382
+ end
383
+
384
+ def commit(payload)
385
+ # Set the Content-Type header -- otherwise the URL decoding messes up
386
+ # the Base64 encoded payload signature!
387
+ response = parse(ssl_post(self.live_url, post_data(payload), 'Content-Type' => 'text/xml'))
388
+
389
+ Response.new(successful?(response), response[:error_message], response,
390
+ :test => test?,
391
+ :authorization => response[:xid],
392
+ :avs_result => { :code => response[:avs_response] },
393
+ :cvv_result => response[:cvv_response])
394
+ end
395
+
396
+ def post_data(payload)
397
+ payload_xml = payload.root.to_xml(:indent => 0)
398
+
399
+ payload_signature = sign_payload(payload_xml)
400
+
401
+ request = Nokogiri::XML::Builder.new do |xml|
402
+ xml.GatewayInterface {
403
+ xml.APICredentials {
404
+ xml.Username(@options[:login])
405
+ xml.PayloadSignature(payload_signature)
406
+ xml.TargetGateway(@options[:gateway_id])
407
+ }
408
+ }
409
+ end.doc
410
+
411
+ request.root.children.first.after payload.root
412
+ request.to_xml(:indent => 0)
413
+ end
414
+
415
+ def parse(raw_xml)
416
+ doc = REXML::Document.new(raw_xml)
417
+ response = Hash.new
418
+ transaction_result = doc.root.get_elements('TransactionResponse/TransactionResult/*')
419
+ transaction_result.each do |e|
420
+ response[e.name.to_s.underscore.to_sym] = e.text unless e.text.blank?
421
+ end
422
+ response
423
+ end
424
+
425
+ def successful?(response)
426
+ # Turns out the PaymentClearing gateway is not consistent...
427
+ response[:status].casecmp('ok').zero?
428
+ end
429
+
430
+ def test_mode?(response)
431
+ # The '1' is a legacy thing; most of the time it should be 'TRUE'...
432
+ response[:test_mode] == 'TRUE' || response[:test_mode] == '1'
433
+ end
434
+
435
+ def message_from(response)
436
+ response[:error_message]
437
+ end
438
+
439
+ def sign_payload(payload)
440
+ key = @options[:password].to_s
441
+ digest=OpenSSL::HMAC.digest(OpenSSL::Digest::SHA1.new(key), key, payload)
442
+ signature = Base64.encode64(digest)
443
+ signature.chomp!
444
+ end
445
+ end
446
+ end
447
+ end
@@ -0,0 +1,251 @@
1
+ require 'nokogiri'
2
+
3
+ module ActiveMerchant #:nodoc:
4
+ module Billing #:nodoc:
5
+ class IveriGateway < Gateway
6
+ self.live_url = self.test_url = 'https://portal.nedsecure.co.za/iVeriWebService/Service.asmx'
7
+
8
+ self.supported_countries = ['US', 'ZA', 'GB']
9
+ self.default_currency = 'ZAR'
10
+ self.money_format = :cents
11
+ self.supported_cardtypes = [:visa, :master, :american_express]
12
+
13
+ self.homepage_url = 'http://www.iveri.com'
14
+ self.display_name = 'iVeri'
15
+
16
+ def initialize(options={})
17
+ requires!(options, :app_id, :cert_id)
18
+ super
19
+ end
20
+
21
+ def purchase(money, payment_method, options={})
22
+ post = build_vxml_request('Debit', options) do |xml|
23
+ add_auth_purchase_params(xml, money, payment_method, options)
24
+ end
25
+
26
+ commit(post)
27
+ end
28
+
29
+ def authorize(money, payment_method, options={})
30
+ post = build_vxml_request('Authorisation', options) do |xml|
31
+ add_auth_purchase_params(xml, money, payment_method, options)
32
+ end
33
+
34
+ commit(post)
35
+ end
36
+
37
+ def capture(money, authorization, options={})
38
+ post = build_vxml_request('Debit', options) do |xml|
39
+ add_authorization(xml, authorization, options)
40
+ end
41
+
42
+ commit(post)
43
+ end
44
+
45
+ def refund(money, authorization, options={})
46
+ post = build_vxml_request('Credit', options) do |xml|
47
+ add_amount(xml, money, options)
48
+ add_authorization(xml, authorization, options)
49
+ end
50
+
51
+ commit(post)
52
+ end
53
+
54
+ def void(authorization, options={})
55
+ post = build_vxml_request('Void', options) do |xml|
56
+ add_authorization(xml, authorization, options)
57
+ end
58
+
59
+ commit(post)
60
+ end
61
+
62
+ def verify(credit_card, options={})
63
+ authorize(0, credit_card, options)
64
+ end
65
+
66
+ def verify_credentials
67
+ void = void('', options)
68
+ return true if void.message == 'Missing OriginalMerchantTrace'
69
+ false
70
+ end
71
+
72
+ def supports_scrubbing?
73
+ true
74
+ end
75
+
76
+ def scrub(transcript)
77
+ transcript.
78
+ gsub(%r((CertificateID=\\\")[^\\]*), '\1[FILTERED]').
79
+ gsub(%r((&lt;PAN&gt;)[^&]*), '\1[FILTERED]').
80
+ gsub(%r((&lt;CardSecurityCode&gt;)[^&]*), '\1[FILTERED]')
81
+ end
82
+
83
+ private
84
+
85
+ def build_xml_envelope(vxml)
86
+ builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
87
+ xml[:soap].Envelope 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance', 'xmlns:xsd' => 'http://www.w3.org/2001/XMLSchema', 'xmlns:soap' => 'http://schemas.xmlsoap.org/soap/envelope/' do
88
+ xml[:soap].Body do
89
+ xml.Execute 'xmlns' => 'http://iveri.com/' do
90
+ xml.validateRequest 'true'
91
+ xml.protocol 'V_XML'
92
+ xml.protocolVersion '2.0'
93
+ xml.request vxml
94
+ end
95
+ end
96
+ end
97
+ end
98
+
99
+ builder.to_xml
100
+ end
101
+
102
+ def build_vxml_request(action, options)
103
+ builder = Nokogiri::XML::Builder.new do |xml|
104
+ xml.V_XML('Version' => '2.0', 'CertificateID' => @options[:cert_id], 'Direction' => 'Request') do
105
+ xml.Transaction('ApplicationID' => @options[:app_id], 'Command' => action, 'Mode' => mode) do
106
+ yield(xml)
107
+ end
108
+ end
109
+ end
110
+
111
+ builder.doc.root.to_xml
112
+ end
113
+
114
+ def add_auth_purchase_params(post, money, payment_method, options)
115
+ add_card_holder_authentication(post, options)
116
+ add_amount(post, money, options)
117
+ add_electronic_commerce_indicator(post, options)
118
+ add_payment_method(post, payment_method, options)
119
+ end
120
+
121
+ def add_amount(post, money, options)
122
+ post.Amount(amount(money))
123
+ post.Currency(options[:currency] || default_currency)
124
+ end
125
+
126
+ def add_electronic_commerce_indicator(post, options)
127
+ post.ElectronicCommerceIndicator(options[:eci]) if options[:eci]
128
+ end
129
+
130
+ def add_authorization(post, authorization, options)
131
+ post.MerchantReference(split_auth(authorization)[2])
132
+ post.TransactionIndex(split_auth(authorization)[1])
133
+ post.OriginalRequestID(split_auth(authorization)[0])
134
+ end
135
+
136
+ def add_payment_method(post, payment_method, options)
137
+ post.ExpiryDate("#{format(payment_method.month, :two_digits)}#{payment_method.year}")
138
+ add_new_reference(post, options)
139
+ post.CardSecurityCode(payment_method.verification_value)
140
+ post.PAN(payment_method.number)
141
+ end
142
+
143
+ def add_new_reference(post, options)
144
+ post.MerchantReference(options[:order_id] || generate_unique_id)
145
+ end
146
+
147
+ def add_card_holder_authentication(post, options)
148
+ post.CardHolderAuthenticationID(options[:xid]) if options[:xid]
149
+ post.CardHolderAuthenticationData(options[:cavv]) if options[:cavv]
150
+ end
151
+
152
+ def commit(post)
153
+ raw_response = begin
154
+ ssl_post(live_url, build_xml_envelope(post), headers(post))
155
+ rescue ActiveMerchant::ResponseError => e
156
+ e.response.body
157
+ end
158
+
159
+ parsed = parse(raw_response)
160
+ succeeded = success_from(parsed)
161
+
162
+ Response.new(
163
+ succeeded,
164
+ message_from(parsed, succeeded),
165
+ parsed,
166
+ authorization: authorization_from(parsed),
167
+ error_code: error_code_from(parsed, succeeded),
168
+ test: test?
169
+ )
170
+ end
171
+
172
+ def mode
173
+ test? ? 'Test' : 'Live'
174
+ end
175
+
176
+ def headers(post)
177
+ {
178
+ 'Content-Type' => 'text/xml; charset=utf-8',
179
+ 'Content-Length' => post.size.to_s,
180
+ 'SOAPAction' => 'http://iveri.com/Execute'
181
+ }
182
+ end
183
+
184
+ def parse(body)
185
+ parsed = {}
186
+
187
+ vxml = Nokogiri::XML(body).remove_namespaces!.xpath('//Envelope/Body/ExecuteResponse/ExecuteResult').inner_text
188
+ doc = Nokogiri::XML(vxml)
189
+ doc.xpath('*').each do |node|
190
+ if node.elements.empty?
191
+ parsed[underscore(node.name)] = node.text
192
+ else
193
+ node.elements.each do |childnode|
194
+ parse_element(parsed, childnode)
195
+ end
196
+ end
197
+ end
198
+ parsed
199
+ end
200
+
201
+ def parse_element(parsed, node)
202
+ if !node.attributes.empty?
203
+ node.attributes.each do |a|
204
+ parsed[underscore(node.name)+ '_' + underscore(a[1].name)] = a[1].value
205
+ end
206
+ end
207
+
208
+ if !node.elements.empty?
209
+ node.elements.each { |e| parse_element(parsed, e) }
210
+ else
211
+ parsed[underscore(node.name)] = node.text
212
+ end
213
+ end
214
+
215
+ def success_from(response)
216
+ response['result_status'] == '0'
217
+ end
218
+
219
+ def message_from(response, succeeded)
220
+ if succeeded
221
+ 'Succeeded'
222
+ else
223
+ response['result_description'] || response['result_acquirer_description']
224
+ end
225
+ end
226
+
227
+ def authorization_from(response)
228
+ "#{response['transaction_request_id']}|#{response['transaction_index']}|#{response['merchant_reference']}"
229
+ end
230
+
231
+ def split_auth(authorization)
232
+ request_id, transaction_index, merchant_reference = authorization.to_s.split('|')
233
+ [request_id, transaction_index, merchant_reference]
234
+ end
235
+
236
+ def error_code_from(response, succeeded)
237
+ unless succeeded
238
+ response['result_code']
239
+ end
240
+ end
241
+
242
+ def underscore(camel_cased_word)
243
+ camel_cased_word.to_s.gsub(/::/, '/').
244
+ gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
245
+ gsub(/([a-z\d])([A-Z])/, '\1_\2').
246
+ tr('-', '_').
247
+ downcase
248
+ end
249
+ end
250
+ end
251
+ end