activemerchant-nsp 1.27.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (252) hide show
  1. data/CHANGELOG +952 -0
  2. data/CONTRIBUTORS +347 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.md +204 -0
  5. data/gem-public_cert.pem +20 -0
  6. data/lib/active_merchant.rb +63 -0
  7. data/lib/active_merchant/billing.rb +9 -0
  8. data/lib/active_merchant/billing/avs_result.rb +98 -0
  9. data/lib/active_merchant/billing/base.rb +56 -0
  10. data/lib/active_merchant/billing/check.rb +68 -0
  11. data/lib/active_merchant/billing/credit_card.rb +274 -0
  12. data/lib/active_merchant/billing/credit_card_formatting.rb +21 -0
  13. data/lib/active_merchant/billing/credit_card_methods.rb +143 -0
  14. data/lib/active_merchant/billing/cvv_result.rb +38 -0
  15. data/lib/active_merchant/billing/expiry_date.rb +34 -0
  16. data/lib/active_merchant/billing/gateway.rb +176 -0
  17. data/lib/active_merchant/billing/gateways.rb +18 -0
  18. data/lib/active_merchant/billing/gateways/authorize_net.rb +695 -0
  19. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +943 -0
  20. data/lib/active_merchant/billing/gateways/balanced.rb +462 -0
  21. data/lib/active_merchant/billing/gateways/barclays_epdq.rb +308 -0
  22. data/lib/active_merchant/billing/gateways/beanstream.rb +167 -0
  23. data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +389 -0
  24. data/lib/active_merchant/billing/gateways/beanstream_interac.rb +54 -0
  25. data/lib/active_merchant/billing/gateways/blue_pay.rb +492 -0
  26. data/lib/active_merchant/billing/gateways/bogus.rb +142 -0
  27. data/lib/active_merchant/billing/gateways/braintree.rb +19 -0
  28. data/lib/active_merchant/billing/gateways/braintree/braintree_common.rb +9 -0
  29. data/lib/active_merchant/billing/gateways/braintree_blue.rb +389 -0
  30. data/lib/active_merchant/billing/gateways/braintree_orange.rb +19 -0
  31. data/lib/active_merchant/billing/gateways/card_save.rb +23 -0
  32. data/lib/active_merchant/billing/gateways/card_stream.rb +230 -0
  33. data/lib/active_merchant/billing/gateways/certo_direct.rb +278 -0
  34. data/lib/active_merchant/billing/gateways/cyber_source.rb +576 -0
  35. data/lib/active_merchant/billing/gateways/data_cash.rb +597 -0
  36. data/lib/active_merchant/billing/gateways/efsnet.rb +235 -0
  37. data/lib/active_merchant/billing/gateways/elavon.rb +137 -0
  38. data/lib/active_merchant/billing/gateways/epay.rb +276 -0
  39. data/lib/active_merchant/billing/gateways/eway.rb +287 -0
  40. data/lib/active_merchant/billing/gateways/eway_managed.rb +265 -0
  41. data/lib/active_merchant/billing/gateways/exact.rb +227 -0
  42. data/lib/active_merchant/billing/gateways/fat_zebra.rb +152 -0
  43. data/lib/active_merchant/billing/gateways/federated_canada.rb +168 -0
  44. data/lib/active_merchant/billing/gateways/first_pay.rb +177 -0
  45. data/lib/active_merchant/billing/gateways/garanti.rb +262 -0
  46. data/lib/active_merchant/billing/gateways/ideal/ideal_base.rb +252 -0
  47. data/lib/active_merchant/billing/gateways/ideal/ideal_rabobank.pem +13 -0
  48. data/lib/active_merchant/billing/gateways/ideal/ideal_response.rb +29 -0
  49. data/lib/active_merchant/billing/gateways/ideal_rabobank.rb +55 -0
  50. data/lib/active_merchant/billing/gateways/inspire.rb +221 -0
  51. data/lib/active_merchant/billing/gateways/instapay.rb +164 -0
  52. data/lib/active_merchant/billing/gateways/iridium.rb +257 -0
  53. data/lib/active_merchant/billing/gateways/itransact.rb +450 -0
  54. data/lib/active_merchant/billing/gateways/jetpay.rb +276 -0
  55. data/lib/active_merchant/billing/gateways/linkpoint.rb +451 -0
  56. data/lib/active_merchant/billing/gateways/litle.rb +290 -0
  57. data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +157 -0
  58. data/lib/active_merchant/billing/gateways/merchant_ware.rb +289 -0
  59. data/lib/active_merchant/billing/gateways/metrics_global.rb +323 -0
  60. data/lib/active_merchant/billing/gateways/migs.rb +263 -0
  61. data/lib/active_merchant/billing/gateways/migs/migs_codes.rb +100 -0
  62. data/lib/active_merchant/billing/gateways/modern_payments.rb +38 -0
  63. data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +220 -0
  64. data/lib/active_merchant/billing/gateways/moneris.rb +250 -0
  65. data/lib/active_merchant/billing/gateways/moneris_us.rb +211 -0
  66. data/lib/active_merchant/billing/gateways/nab_transact.rb +257 -0
  67. data/lib/active_merchant/billing/gateways/net_registry.rb +189 -0
  68. data/lib/active_merchant/billing/gateways/netaxept.rb +239 -0
  69. data/lib/active_merchant/billing/gateways/netbilling.rb +196 -0
  70. data/lib/active_merchant/billing/gateways/nmi.rb +13 -0
  71. data/lib/active_merchant/billing/gateways/ogone.rb +427 -0
  72. data/lib/active_merchant/billing/gateways/optimal_payment.rb +277 -0
  73. data/lib/active_merchant/billing/gateways/orbital.rb +351 -0
  74. data/lib/active_merchant/billing/gateways/orbital/orbital_soft_descriptors.rb +46 -0
  75. data/lib/active_merchant/billing/gateways/pay_gate_xml.rb +266 -0
  76. data/lib/active_merchant/billing/gateways/pay_junction.rb +397 -0
  77. data/lib/active_merchant/billing/gateways/pay_secure.rb +120 -0
  78. data/lib/active_merchant/billing/gateways/paybox_direct.rb +201 -0
  79. data/lib/active_merchant/billing/gateways/payflow.rb +268 -0
  80. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +212 -0
  81. data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +39 -0
  82. data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +13 -0
  83. data/lib/active_merchant/billing/gateways/payflow_express.rb +224 -0
  84. data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +15 -0
  85. data/lib/active_merchant/billing/gateways/payflow_uk.rb +21 -0
  86. data/lib/active_merchant/billing/gateways/payment_express.rb +282 -0
  87. data/lib/active_merchant/billing/gateways/paypal.rb +106 -0
  88. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +653 -0
  89. data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +49 -0
  90. data/lib/active_merchant/billing/gateways/paypal/paypal_recurring_api.rb +245 -0
  91. data/lib/active_merchant/billing/gateways/paypal_ca.rb +13 -0
  92. data/lib/active_merchant/billing/gateways/paypal_digital_goods.rb +43 -0
  93. data/lib/active_merchant/billing/gateways/paypal_express.rb +178 -0
  94. data/lib/active_merchant/billing/gateways/paypal_express_common.rb +30 -0
  95. data/lib/active_merchant/billing/gateways/paystation.rb +201 -0
  96. data/lib/active_merchant/billing/gateways/payway.rb +214 -0
  97. data/lib/active_merchant/billing/gateways/plugnpay.rb +295 -0
  98. data/lib/active_merchant/billing/gateways/psigate.rb +219 -0
  99. data/lib/active_merchant/billing/gateways/psl_card.rb +304 -0
  100. data/lib/active_merchant/billing/gateways/qbms.rb +297 -0
  101. data/lib/active_merchant/billing/gateways/quantum.rb +282 -0
  102. data/lib/active_merchant/billing/gateways/quickpay.rb +298 -0
  103. data/lib/active_merchant/billing/gateways/realex.rb +313 -0
  104. data/lib/active_merchant/billing/gateways/sage.rb +148 -0
  105. data/lib/active_merchant/billing/gateways/sage/sage_bankcard.rb +88 -0
  106. data/lib/active_merchant/billing/gateways/sage/sage_core.rb +115 -0
  107. data/lib/active_merchant/billing/gateways/sage/sage_virtual_check.rb +97 -0
  108. data/lib/active_merchant/billing/gateways/sage_pay.rb +322 -0
  109. data/lib/active_merchant/billing/gateways/sallie_mae.rb +144 -0
  110. data/lib/active_merchant/billing/gateways/samurai.rb +121 -0
  111. data/lib/active_merchant/billing/gateways/secure_net.rb +330 -0
  112. data/lib/active_merchant/billing/gateways/secure_pay.rb +31 -0
  113. data/lib/active_merchant/billing/gateways/secure_pay_au.rb +284 -0
  114. data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +113 -0
  115. data/lib/active_merchant/billing/gateways/skip_jack.rb +458 -0
  116. data/lib/active_merchant/billing/gateways/smart_ps.rb +273 -0
  117. data/lib/active_merchant/billing/gateways/stripe.rb +236 -0
  118. data/lib/active_merchant/billing/gateways/trans_first.rb +127 -0
  119. data/lib/active_merchant/billing/gateways/transax.rb +23 -0
  120. data/lib/active_merchant/billing/gateways/trust_commerce.rb +423 -0
  121. data/lib/active_merchant/billing/gateways/usa_epay.rb +25 -0
  122. data/lib/active_merchant/billing/gateways/usa_epay_advanced.rb +1497 -0
  123. data/lib/active_merchant/billing/gateways/usa_epay_transaction.rb +206 -0
  124. data/lib/active_merchant/billing/gateways/verifi.rb +233 -0
  125. data/lib/active_merchant/billing/gateways/viaklix.rb +194 -0
  126. data/lib/active_merchant/billing/gateways/vindicia.rb +359 -0
  127. data/lib/active_merchant/billing/gateways/wirecard.rb +313 -0
  128. data/lib/active_merchant/billing/gateways/worldpay.rb +271 -0
  129. data/lib/active_merchant/billing/integrations.rb +17 -0
  130. data/lib/active_merchant/billing/integrations/action_view_helper.rb +73 -0
  131. data/lib/active_merchant/billing/integrations/authorize_net_sim.rb +38 -0
  132. data/lib/active_merchant/billing/integrations/authorize_net_sim/helper.rb +228 -0
  133. data/lib/active_merchant/billing/integrations/authorize_net_sim/notification.rb +340 -0
  134. data/lib/active_merchant/billing/integrations/bogus.rb +23 -0
  135. data/lib/active_merchant/billing/integrations/bogus/helper.rb +17 -0
  136. data/lib/active_merchant/billing/integrations/bogus/notification.rb +11 -0
  137. data/lib/active_merchant/billing/integrations/bogus/return.rb +10 -0
  138. data/lib/active_merchant/billing/integrations/chronopay.rb +23 -0
  139. data/lib/active_merchant/billing/integrations/chronopay/helper.rb +120 -0
  140. data/lib/active_merchant/billing/integrations/chronopay/notification.rb +158 -0
  141. data/lib/active_merchant/billing/integrations/chronopay/return.rb +10 -0
  142. data/lib/active_merchant/billing/integrations/direc_pay.rb +41 -0
  143. data/lib/active_merchant/billing/integrations/direc_pay/helper.rb +200 -0
  144. data/lib/active_merchant/billing/integrations/direc_pay/notification.rb +76 -0
  145. data/lib/active_merchant/billing/integrations/direc_pay/return.rb +32 -0
  146. data/lib/active_merchant/billing/integrations/direc_pay/status.rb +37 -0
  147. data/lib/active_merchant/billing/integrations/directebanking.rb +47 -0
  148. data/lib/active_merchant/billing/integrations/directebanking/helper.rb +90 -0
  149. data/lib/active_merchant/billing/integrations/directebanking/notification.rb +120 -0
  150. data/lib/active_merchant/billing/integrations/directebanking/return.rb +11 -0
  151. data/lib/active_merchant/billing/integrations/dotpay.rb +22 -0
  152. data/lib/active_merchant/billing/integrations/dotpay/helper.rb +77 -0
  153. data/lib/active_merchant/billing/integrations/dotpay/notification.rb +86 -0
  154. data/lib/active_merchant/billing/integrations/dotpay/return.rb +11 -0
  155. data/lib/active_merchant/billing/integrations/dwolla.rb +30 -0
  156. data/lib/active_merchant/billing/integrations/dwolla/helper.rb +31 -0
  157. data/lib/active_merchant/billing/integrations/dwolla/notification.rb +55 -0
  158. data/lib/active_merchant/billing/integrations/dwolla/return.rb +38 -0
  159. data/lib/active_merchant/billing/integrations/e_payment_plans.rb +48 -0
  160. data/lib/active_merchant/billing/integrations/e_payment_plans/helper.rb +34 -0
  161. data/lib/active_merchant/billing/integrations/e_payment_plans/notification.rb +84 -0
  162. data/lib/active_merchant/billing/integrations/easy_pay.rb +30 -0
  163. data/lib/active_merchant/billing/integrations/easy_pay/common.rb +40 -0
  164. data/lib/active_merchant/billing/integrations/easy_pay/helper.rb +40 -0
  165. data/lib/active_merchant/billing/integrations/easy_pay/notification.rb +51 -0
  166. data/lib/active_merchant/billing/integrations/epay.rb +21 -0
  167. data/lib/active_merchant/billing/integrations/epay/helper.rb +55 -0
  168. data/lib/active_merchant/billing/integrations/epay/notification.rb +110 -0
  169. data/lib/active_merchant/billing/integrations/first_data.rb +38 -0
  170. data/lib/active_merchant/billing/integrations/first_data/helper.rb +63 -0
  171. data/lib/active_merchant/billing/integrations/first_data/notification.rb +56 -0
  172. data/lib/active_merchant/billing/integrations/gestpay.rb +25 -0
  173. data/lib/active_merchant/billing/integrations/gestpay/common.rb +42 -0
  174. data/lib/active_merchant/billing/integrations/gestpay/helper.rb +70 -0
  175. data/lib/active_merchant/billing/integrations/gestpay/notification.rb +85 -0
  176. data/lib/active_merchant/billing/integrations/gestpay/return.rb +10 -0
  177. data/lib/active_merchant/billing/integrations/helper.rb +117 -0
  178. data/lib/active_merchant/billing/integrations/hi_trust.rb +27 -0
  179. data/lib/active_merchant/billing/integrations/hi_trust/helper.rb +58 -0
  180. data/lib/active_merchant/billing/integrations/hi_trust/notification.rb +59 -0
  181. data/lib/active_merchant/billing/integrations/hi_trust/return.rb +67 -0
  182. data/lib/active_merchant/billing/integrations/maksuturva.rb +86 -0
  183. data/lib/active_merchant/billing/integrations/maksuturva/helper.rb +119 -0
  184. data/lib/active_merchant/billing/integrations/maksuturva/notification.rb +48 -0
  185. data/lib/active_merchant/billing/integrations/moneybookers.rb +26 -0
  186. data/lib/active_merchant/billing/integrations/moneybookers/helper.rb +59 -0
  187. data/lib/active_merchant/billing/integrations/moneybookers/notification.rb +129 -0
  188. data/lib/active_merchant/billing/integrations/nelnet.rb +40 -0
  189. data/lib/active_merchant/billing/integrations/nelnet/helper.rb +34 -0
  190. data/lib/active_merchant/billing/integrations/nelnet/notification.rb +100 -0
  191. data/lib/active_merchant/billing/integrations/nochex.rb +88 -0
  192. data/lib/active_merchant/billing/integrations/nochex/helper.rb +68 -0
  193. data/lib/active_merchant/billing/integrations/nochex/notification.rb +94 -0
  194. data/lib/active_merchant/billing/integrations/nochex/return.rb +10 -0
  195. data/lib/active_merchant/billing/integrations/notification.rb +62 -0
  196. data/lib/active_merchant/billing/integrations/paxum.rb +44 -0
  197. data/lib/active_merchant/billing/integrations/paxum/common.rb +24 -0
  198. data/lib/active_merchant/billing/integrations/paxum/helper.rb +42 -0
  199. data/lib/active_merchant/billing/integrations/paxum/notification.rb +33 -0
  200. data/lib/active_merchant/billing/integrations/payflow_link.rb +21 -0
  201. data/lib/active_merchant/billing/integrations/payflow_link/helper.rb +100 -0
  202. data/lib/active_merchant/billing/integrations/payflow_link/notification.rb +78 -0
  203. data/lib/active_merchant/billing/integrations/paypal.rb +39 -0
  204. data/lib/active_merchant/billing/integrations/paypal/helper.rb +119 -0
  205. data/lib/active_merchant/billing/integrations/paypal/notification.rb +155 -0
  206. data/lib/active_merchant/billing/integrations/paypal/return.rb +10 -0
  207. data/lib/active_merchant/billing/integrations/paypal_payments_advanced.rb +20 -0
  208. data/lib/active_merchant/billing/integrations/paypal_payments_advanced/helper.rb +15 -0
  209. data/lib/active_merchant/billing/integrations/pxpay.rb +31 -0
  210. data/lib/active_merchant/billing/integrations/pxpay/helper.rb +110 -0
  211. data/lib/active_merchant/billing/integrations/pxpay/notification.rb +157 -0
  212. data/lib/active_merchant/billing/integrations/pxpay/return.rb +25 -0
  213. data/lib/active_merchant/billing/integrations/quickpay.rb +21 -0
  214. data/lib/active_merchant/billing/integrations/quickpay/helper.rb +71 -0
  215. data/lib/active_merchant/billing/integrations/quickpay/notification.rb +74 -0
  216. data/lib/active_merchant/billing/integrations/return.rb +42 -0
  217. data/lib/active_merchant/billing/integrations/robokassa.rb +49 -0
  218. data/lib/active_merchant/billing/integrations/robokassa/common.rb +19 -0
  219. data/lib/active_merchant/billing/integrations/robokassa/helper.rb +50 -0
  220. data/lib/active_merchant/billing/integrations/robokassa/notification.rb +55 -0
  221. data/lib/active_merchant/billing/integrations/robokassa/return.rb +17 -0
  222. data/lib/active_merchant/billing/integrations/sage_pay_form.rb +37 -0
  223. data/lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb +33 -0
  224. data/lib/active_merchant/billing/integrations/sage_pay_form/helper.rb +129 -0
  225. data/lib/active_merchant/billing/integrations/sage_pay_form/notification.rb +210 -0
  226. data/lib/active_merchant/billing/integrations/sage_pay_form/return.rb +31 -0
  227. data/lib/active_merchant/billing/integrations/two_checkout.rb +44 -0
  228. data/lib/active_merchant/billing/integrations/two_checkout/helper.rb +91 -0
  229. data/lib/active_merchant/billing/integrations/two_checkout/notification.rb +139 -0
  230. data/lib/active_merchant/billing/integrations/two_checkout/return.rb +17 -0
  231. data/lib/active_merchant/billing/integrations/valitor.rb +33 -0
  232. data/lib/active_merchant/billing/integrations/valitor/helper.rb +86 -0
  233. data/lib/active_merchant/billing/integrations/valitor/notification.rb +13 -0
  234. data/lib/active_merchant/billing/integrations/valitor/response_fields.rb +97 -0
  235. data/lib/active_merchant/billing/integrations/valitor/return.rb +13 -0
  236. data/lib/active_merchant/billing/integrations/verkkomaksut.rb +20 -0
  237. data/lib/active_merchant/billing/integrations/verkkomaksut/helper.rb +87 -0
  238. data/lib/active_merchant/billing/integrations/verkkomaksut/notification.rb +59 -0
  239. data/lib/active_merchant/billing/integrations/web_pay.rb +45 -0
  240. data/lib/active_merchant/billing/integrations/web_pay/common.rb +50 -0
  241. data/lib/active_merchant/billing/integrations/web_pay/helper.rb +68 -0
  242. data/lib/active_merchant/billing/integrations/web_pay/notification.rb +51 -0
  243. data/lib/active_merchant/billing/integrations/world_pay.rb +27 -0
  244. data/lib/active_merchant/billing/integrations/world_pay/helper.rb +100 -0
  245. data/lib/active_merchant/billing/integrations/world_pay/notification.rb +160 -0
  246. data/lib/active_merchant/billing/response.rb +64 -0
  247. data/lib/active_merchant/version.rb +3 -0
  248. data/lib/activemerchant.rb +1 -0
  249. data/lib/support/gateway_support.rb +65 -0
  250. data/lib/support/outbound_hosts.rb +25 -0
  251. data/lib/support/ssl_verify.rb +93 -0
  252. metadata +482 -0
@@ -0,0 +1,576 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ # See the remote and mocked unit test files for example usage. Pay special
4
+ # attention to the contents of the options hash.
5
+ #
6
+ # Initial setup instructions can be found in
7
+ # http://cybersource.com/support_center/implementation/downloads/soap_api/SOAP_toolkits.pdf
8
+ #
9
+ # Debugging
10
+ # If you experience an issue with this gateway be sure to examine the
11
+ # transaction information from a general transaction search inside the
12
+ # CyberSource Business Center for the full error messages including field
13
+ # names.
14
+ #
15
+ # Important Notes
16
+ # * AVS and CVV only work against the production server. You will always
17
+ # get back X for AVS and no response for CVV against the test server.
18
+ # * Nexus is the list of states or provinces where you have a physical
19
+ # presence. Nexus is used to calculate tax. Leave blank to tax everyone.
20
+ # * If you want to calculate VAT for overseas customers you must supply a
21
+ # registration number in the options hash as vat_reg_number.
22
+ # * productCode is a value in the line_items hash that is used to tell
23
+ # CyberSource what kind of item you are selling. It is used when
24
+ # calculating tax/VAT.
25
+ # * All transactions use dollar values.
26
+ class CyberSourceGateway < Gateway
27
+ self.test_url = 'https://ics2wstest.ic3.com/commerce/1.x/transactionProcessor'
28
+ self.live_url = 'https://ics2ws.ic3.com/commerce/1.x/transactionProcessor'
29
+
30
+ XSD_VERSION = "1.69"
31
+
32
+ # visa, master, american_express, discover
33
+ self.supported_cardtypes = [:visa, :master, :american_express, :discover]
34
+ self.supported_countries = ['US']
35
+ self.default_currency = 'USD'
36
+ self.homepage_url = 'http://www.cybersource.com'
37
+ self.display_name = 'CyberSource'
38
+
39
+ # map credit card to the CyberSource expected representation
40
+ @@credit_card_codes = {
41
+ :visa => '001',
42
+ :master => '002',
43
+ :american_express => '003',
44
+ :discover => '004'
45
+ }
46
+
47
+ # map response codes to something humans can read
48
+ @@response_codes = {
49
+ :r100 => "Successful transaction",
50
+ :r101 => "Request is missing one or more required fields" ,
51
+ :r102 => "One or more fields contains invalid data",
52
+ :r150 => "General failure",
53
+ :r151 => "The request was received but a server time-out occurred",
54
+ :r152 => "The request was received, but a service timed out",
55
+ :r200 => "The authorization request was approved by the issuing bank but declined by CyberSource because it did not pass the AVS check",
56
+ :r201 => "The issuing bank has questions about the request",
57
+ :r202 => "Expired card",
58
+ :r203 => "General decline of the card",
59
+ :r204 => "Insufficient funds in the account",
60
+ :r205 => "Stolen or lost card",
61
+ :r207 => "Issuing bank unavailable",
62
+ :r208 => "Inactive card or card not authorized for card-not-present transactions",
63
+ :r209 => "American Express Card Identifiction Digits (CID) did not match",
64
+ :r210 => "The card has reached the credit limit",
65
+ :r211 => "Invalid card verification number",
66
+ :r221 => "The customer matched an entry on the processor's negative file",
67
+ :r230 => "The authorization request was approved by the issuing bank but declined by CyberSource because it did not pass the card verification check",
68
+ :r231 => "Invalid account number",
69
+ :r232 => "The card type is not accepted by the payment processor",
70
+ :r233 => "General decline by the processor",
71
+ :r234 => "A problem exists with your CyberSource merchant configuration",
72
+ :r235 => "The requested amount exceeds the originally authorized amount",
73
+ :r236 => "Processor failure",
74
+ :r237 => "The authorization has already been reversed",
75
+ :r238 => "The authorization has already been captured",
76
+ :r239 => "The requested transaction amount must match the previous transaction amount",
77
+ :r240 => "The card type sent is invalid or does not correlate with the credit card number",
78
+ :r241 => "The request ID is invalid",
79
+ :r242 => "You requested a capture, but there is no corresponding, unused authorization record.",
80
+ :r243 => "The transaction has already been settled or reversed",
81
+ :r244 => "The bank account number failed the validation check",
82
+ :r246 => "The capture or credit is not voidable because the capture or credit information has already been submitted to your processor",
83
+ :r247 => "You requested a credit for a capture that was previously voided",
84
+ :r250 => "The request was received, but a time-out occurred with the payment processor",
85
+ :r254 => "Your CyberSource account is prohibited from processing stand-alone refunds",
86
+ :r255 => "Your CyberSource account is not configured to process the service in the country you specified"
87
+ }
88
+
89
+ # These are the options that can be used when creating a new CyberSource
90
+ # Gateway object.
91
+ #
92
+ # :login => your username
93
+ #
94
+ # :password => the transaction key you generated in the Business Center
95
+ #
96
+ # :test => true sets the gateway to test mode
97
+ #
98
+ # :vat_reg_number => your VAT registration number
99
+ #
100
+ # :nexus => "WI CA QC" sets the states/provinces where you have a physical
101
+ # presense for tax purposes
102
+ #
103
+ # :ignore_avs => true don't want to use AVS so continue processing even
104
+ # if AVS would have failed
105
+ #
106
+ # :ignore_cvv => true don't want to use CVV so continue processing even
107
+ # if CVV would have failed
108
+ def initialize(options = {})
109
+ requires!(options, :login, :password)
110
+ @options = options
111
+ super
112
+ end
113
+
114
+ # Should run against the test servers or not?
115
+ def test?
116
+ @options[:test] || Base.gateway_mode == :test
117
+ end
118
+
119
+ # Request an authorization for an amount from CyberSource
120
+ #
121
+ # You must supply an :order_id in the options hash
122
+ def authorize(money, creditcard_or_reference, options = {})
123
+ requires!(options, :order_id)
124
+ setup_address_hash(options)
125
+ commit(build_auth_request(money, creditcard_or_reference, options), options )
126
+ end
127
+
128
+ def auth_reversal(money, identification, options = {})
129
+ commit(build_auth_reversal_request(money, identification, options), options)
130
+ end
131
+
132
+ # Capture an authorization that has previously been requested
133
+ def capture(money, authorization, options = {})
134
+ setup_address_hash(options)
135
+ commit(build_capture_request(money, authorization, options), options)
136
+ end
137
+
138
+ # Purchase is an auth followed by a capture
139
+ # You must supply an order_id in the options hash
140
+ def purchase(money, creditcard_or_reference, options = {})
141
+ requires!(options, :order_id)
142
+ setup_address_hash(options)
143
+ commit(build_purchase_request(money, creditcard_or_reference, options), options)
144
+ end
145
+
146
+ def void(identification, options = {})
147
+ commit(build_void_request(identification, options), options)
148
+ end
149
+
150
+ def refund(money, identification, options = {})
151
+ commit(build_credit_request(money, identification, options), options)
152
+ end
153
+
154
+ def credit(money, identification, options = {})
155
+ deprecated CREDIT_DEPRECATION_MESSAGE
156
+ refund(money, identification, options)
157
+ end
158
+
159
+ # Stores a customer subscription/profile with type "on-demand".
160
+ # To charge the card while creating a profile, pass
161
+ # options[:setup_fee] => money
162
+ def store(creditcard, options = {})
163
+ requires!(options, :order_id)
164
+ setup_address_hash(options)
165
+ commit(build_create_subscription_request(creditcard, options), options)
166
+ end
167
+
168
+ # Updates a customer subscription/profile
169
+ def update(reference, creditcard, options = {})
170
+ requires!(options, :order_id)
171
+ setup_address_hash(options)
172
+ commit(build_update_subscription_request(reference, creditcard, options), options)
173
+ end
174
+
175
+ # Removes a customer subscription/profile
176
+ def unstore(reference, options = {})
177
+ requires!(options, :order_id)
178
+ commit(build_delete_subscription_request(reference, options), options)
179
+ end
180
+
181
+ # Retrieves a customer subscription/profile
182
+ def retrieve(reference, options = {})
183
+ requires!(options, :order_id)
184
+ commit(build_retrieve_subscription_request(reference, options), options)
185
+ end
186
+
187
+ # CyberSource requires that you provide line item information for tax
188
+ # calculations. If you do not have prices for each item or want to
189
+ # simplify the situation then pass in one fake line item that costs the
190
+ # subtotal of the order
191
+ #
192
+ # The line_item hash goes in the options hash and should look like
193
+ #
194
+ # :line_items => [
195
+ # {
196
+ # :declared_value => '1',
197
+ # :quantity => '2',
198
+ # :code => 'default',
199
+ # :description => 'Giant Walrus',
200
+ # :sku => 'WA323232323232323'
201
+ # },
202
+ # {
203
+ # :declared_value => '6',
204
+ # :quantity => '1',
205
+ # :code => 'default',
206
+ # :description => 'Marble Snowcone',
207
+ # :sku => 'FAKE1232132113123'
208
+ # }
209
+ # ]
210
+ #
211
+ # This functionality is only supported by this particular gateway may
212
+ # be changed at any time
213
+ def calculate_tax(creditcard, options)
214
+ requires!(options, :line_items)
215
+ setup_address_hash(options)
216
+ commit(build_tax_calculation_request(creditcard, options), options)
217
+ end
218
+
219
+ private
220
+
221
+ # Create all address hash key value pairs so that we still function if we
222
+ # were only provided with one or two of them
223
+ def setup_address_hash(options)
224
+ options[:billing_address] = options[:billing_address] || options[:address] || {}
225
+ options[:shipping_address] = options[:shipping_address] || {}
226
+ end
227
+
228
+ def build_auth_request(money, creditcard_or_reference, options)
229
+ xml = Builder::XmlMarkup.new :indent => 2
230
+ add_creditcard_or_subscription(xml, money, creditcard_or_reference, options)
231
+ add_auth_service(xml)
232
+ add_business_rules_data(xml)
233
+ xml.target!
234
+ end
235
+
236
+ def build_tax_calculation_request(creditcard, options)
237
+ xml = Builder::XmlMarkup.new :indent => 2
238
+ add_address(xml, creditcard, options[:billing_address], options, false)
239
+ add_address(xml, creditcard, options[:shipping_address], options, true)
240
+ add_line_item_data(xml, options)
241
+ add_purchase_data(xml, 0, false, options)
242
+ add_tax_service(xml)
243
+ add_business_rules_data(xml)
244
+ xml.target!
245
+ end
246
+
247
+ def build_capture_request(money, authorization, options)
248
+ order_id, request_id, request_token = authorization.split(";")
249
+ options[:order_id] = order_id
250
+
251
+ xml = Builder::XmlMarkup.new :indent => 2
252
+ add_purchase_data(xml, money, true, options)
253
+ add_capture_service(xml, request_id, request_token)
254
+ add_business_rules_data(xml)
255
+ xml.target!
256
+ end
257
+
258
+ def build_purchase_request(money, creditcard_or_reference, options)
259
+ xml = Builder::XmlMarkup.new :indent => 2
260
+ add_creditcard_or_subscription(xml, money, creditcard_or_reference, options)
261
+ add_purchase_service(xml, options)
262
+ add_business_rules_data(xml)
263
+ xml.target!
264
+ end
265
+
266
+ def build_void_request(identification, options)
267
+ order_id, request_id, request_token = identification.split(";")
268
+ options[:order_id] = order_id
269
+
270
+ xml = Builder::XmlMarkup.new :indent => 2
271
+ add_void_service(xml, request_id, request_token)
272
+ xml.target!
273
+ end
274
+
275
+ def build_auth_reversal_request(money, identification, options)
276
+ order_id, request_id, request_token = identification.split(";")
277
+ options[:order_id] = order_id
278
+ xml = Builder::XmlMarkup.new :indent => 2
279
+ add_purchase_data(xml, money, true, options)
280
+ add_auth_reversal_service(xml, request_id, request_token)
281
+ xml.target!
282
+ end
283
+
284
+ def build_credit_request(money, identification, options)
285
+ order_id, request_id, request_token = identification.split(";")
286
+ options[:order_id] = order_id
287
+
288
+ xml = Builder::XmlMarkup.new :indent => 2
289
+ add_purchase_data(xml, money, true, options)
290
+ add_credit_service(xml, request_id, request_token)
291
+
292
+ xml.target!
293
+ end
294
+
295
+ def build_create_subscription_request(creditcard, options)
296
+ options[:subscription] = (options[:subscription] || {}).merge(:frequency => "on-demand", :amount => 0, :automatic_renew => false)
297
+
298
+ xml = Builder::XmlMarkup.new :indent => 2
299
+ add_address(xml, creditcard, options[:billing_address], options)
300
+ add_purchase_data(xml, options[:setup_fee] || 0, true, options)
301
+ add_creditcard(xml, creditcard)
302
+ add_creditcard_payment_method(xml)
303
+ add_subscription(xml, options)
304
+ add_purchase_service(xml, options) if options[:setup_fee]
305
+ add_subscription_create_service(xml, options)
306
+ add_business_rules_data(xml)
307
+ xml.target!
308
+ end
309
+
310
+ def build_update_subscription_request(reference, creditcard, options)
311
+ xml = Builder::XmlMarkup.new :indent => 2
312
+ add_address(xml, creditcard, options[:billing_address], options) unless options[:billing_address].blank?
313
+ add_purchase_data(xml, options[:setup_fee], true, options) unless options[:setup_fee].blank?
314
+ add_creditcard(xml, creditcard) if creditcard
315
+ add_creditcard_payment_method(xml) if creditcard
316
+ add_subscription(xml, options, reference)
317
+ add_subscription_update_service(xml, options)
318
+ add_business_rules_data(xml)
319
+ xml.target!
320
+ end
321
+
322
+ def build_delete_subscription_request(reference, options)
323
+ xml = Builder::XmlMarkup.new :indent => 2
324
+ add_subscription(xml, options, reference)
325
+ add_subscription_delete_service(xml, options)
326
+ xml.target!
327
+ end
328
+
329
+ def build_retrieve_subscription_request(reference, options)
330
+ xml = Builder::XmlMarkup.new :indent => 2
331
+ add_subscription(xml, options, reference)
332
+ add_subscription_retrieve_service(xml, options)
333
+ xml.target!
334
+ end
335
+
336
+ def add_business_rules_data(xml)
337
+ xml.tag! 'businessRules' do
338
+ xml.tag!('ignoreAVSResult', 'true') if @options[:ignore_avs]
339
+ xml.tag!('ignoreCVResult', 'true') if @options[:ignore_cvv]
340
+ end
341
+ end
342
+
343
+ def add_line_item_data(xml, options)
344
+ options[:line_items].each_with_index do |value, index|
345
+ xml.tag! 'item', {'id' => index} do
346
+ xml.tag! 'unitPrice', amount(value[:declared_value])
347
+ xml.tag! 'quantity', value[:quantity]
348
+ xml.tag! 'productCode', value[:code] || 'shipping_only'
349
+ xml.tag! 'productName', value[:description]
350
+ xml.tag! 'productSKU', value[:sku]
351
+ end
352
+ end
353
+ end
354
+
355
+ def add_merchant_data(xml, options)
356
+ xml.tag! 'merchantID', @options[:login]
357
+ xml.tag! 'merchantReferenceCode', options[:order_id]
358
+ xml.tag! 'clientLibrary' ,'Ruby Active Merchant'
359
+ xml.tag! 'clientLibraryVersion', VERSION
360
+ xml.tag! 'clientEnvironment' , RUBY_PLATFORM
361
+ end
362
+
363
+ def add_purchase_data(xml, money = 0, include_grand_total = false, options={})
364
+ xml.tag! 'purchaseTotals' do
365
+ xml.tag! 'currency', options[:currency] || currency(money)
366
+ xml.tag!('grandTotalAmount', amount(money)) if include_grand_total
367
+ end
368
+ end
369
+
370
+ def add_address(xml, creditcard, address, options, shipTo = false)
371
+ requires!(options, :email)
372
+
373
+ xml.tag! shipTo ? 'shipTo' : 'billTo' do
374
+ xml.tag! 'firstName', creditcard.first_name if creditcard
375
+ xml.tag! 'lastName', creditcard.last_name if creditcard
376
+ xml.tag! 'street1', address[:address1]
377
+ xml.tag! 'street2', address[:address2] unless address[:address2].blank?
378
+ xml.tag! 'city', address[:city]
379
+ xml.tag! 'state', address[:state]
380
+ xml.tag! 'postalCode', address[:zip]
381
+ xml.tag! 'country', address[:country]
382
+ xml.tag! 'company', address[:company] unless address[:company].blank?
383
+ xml.tag! 'companyTaxID', address[:companyTaxID] unless address[:company_tax_id].blank?
384
+ xml.tag! 'phoneNumber', address[:phone_number] unless address[:phone_number].blank?
385
+ xml.tag! 'email', options[:email]
386
+ xml.tag! 'driversLicenseNumber', options[:drivers_license_number] unless options[:drivers_license_number].blank?
387
+ xml.tag! 'driversLicenseState', options[:drivers_license_state] unless options[:drivers_license_state].blank?
388
+ end
389
+ end
390
+
391
+ def add_creditcard(xml, creditcard)
392
+ xml.tag! 'card' do
393
+ xml.tag! 'accountNumber', creditcard.number
394
+ xml.tag! 'expirationMonth', format(creditcard.month, :two_digits)
395
+ xml.tag! 'expirationYear', format(creditcard.year, :four_digits)
396
+ xml.tag!('cvNumber', creditcard.verification_value) unless (@options[:ignore_cvv] || creditcard.verification_value.blank? )
397
+ xml.tag! 'cardType', @@credit_card_codes[card_brand(creditcard).to_sym]
398
+ end
399
+ end
400
+
401
+ def add_tax_service(xml)
402
+ xml.tag! 'taxService', {'run' => 'true'} do
403
+ xml.tag!('nexus', @options[:nexus]) unless @options[:nexus].blank?
404
+ xml.tag!('sellerRegistration', @options[:vat_reg_number]) unless @options[:vat_reg_number].blank?
405
+ end
406
+ end
407
+
408
+ def add_auth_service(xml)
409
+ xml.tag! 'ccAuthService', {'run' => 'true'}
410
+ end
411
+
412
+ def add_capture_service(xml, request_id, request_token)
413
+ xml.tag! 'ccCaptureService', {'run' => 'true'} do
414
+ xml.tag! 'authRequestID', request_id
415
+ xml.tag! 'authRequestToken', request_token
416
+ end
417
+ end
418
+
419
+ def add_purchase_service(xml, options)
420
+ xml.tag! 'ccAuthService', {'run' => 'true'}
421
+ xml.tag! 'ccCaptureService', {'run' => 'true'}
422
+ end
423
+
424
+ def add_void_service(xml, request_id, request_token)
425
+ xml.tag! 'voidService', {'run' => 'true'} do
426
+ xml.tag! 'voidRequestID', request_id
427
+ xml.tag! 'voidRequestToken', request_token
428
+ end
429
+ end
430
+
431
+ def add_auth_reversal_service(xml, request_id, request_token)
432
+ xml.tag! 'ccAuthReversalService', {'run' => 'true'} do
433
+ xml.tag! 'authRequestID', request_id
434
+ xml.tag! 'authRequestToken', request_token
435
+ end
436
+ end
437
+
438
+ def add_credit_service(xml, request_id, request_token)
439
+ xml.tag! 'ccCreditService', {'run' => 'true'} do
440
+ xml.tag! 'captureRequestID', request_id
441
+ xml.tag! 'captureRequestToken', request_token
442
+ end
443
+ end
444
+
445
+ def add_subscription_create_service(xml, options)
446
+ xml.tag! 'paySubscriptionCreateService', {'run' => 'true'}
447
+ end
448
+
449
+ def add_subscription_update_service(xml, options)
450
+ xml.tag! 'paySubscriptionUpdateService', {'run' => 'true'}
451
+ end
452
+
453
+ def add_subscription_delete_service(xml, options)
454
+ xml.tag! 'paySubscriptionDeleteService', {'run' => 'true'}
455
+ end
456
+
457
+ def add_subscription_retrieve_service(xml, options)
458
+ xml.tag! 'paySubscriptionRetrieveService', {'run' => 'true'}
459
+ end
460
+
461
+ def add_subscription(xml, options, reference = nil)
462
+ options[:subscription] ||= {}
463
+
464
+ xml.tag! 'recurringSubscriptionInfo' do
465
+ if reference
466
+ _, subscription_id, _ = reference.split(";")
467
+ xml.tag! 'subscriptionID', subscription_id
468
+ end
469
+
470
+ xml.tag! 'status', options[:subscription][:status] if options[:subscription][:status]
471
+ xml.tag! 'amount', options[:subscription][:amount] if options[:subscription][:amount]
472
+ xml.tag! 'numberOfPayments', options[:subscription][:occurrences] if options[:subscription][:occurrences]
473
+ xml.tag! 'automaticRenew', options[:subscription][:automatic_renew] if options[:subscription][:automatic_renew]
474
+ xml.tag! 'frequency', options[:subscription][:frequency] if options[:subscription][:frequency]
475
+ xml.tag! 'startDate', options[:subscription][:start_date].strftime("%Y%m%d") if options[:subscription][:start_date]
476
+ xml.tag! 'endDate', options[:subscription][:end_date].strftime("%Y%m%d") if options[:subscription][:end_date]
477
+ xml.tag! 'approvalRequired', options[:subscription][:approval_required] || false
478
+ xml.tag! 'event', options[:subscription][:event] if options[:subscription][:event]
479
+ xml.tag! 'billPayment', options[:subscription][:bill_payment] if options[:subscription][:bill_payment]
480
+ end
481
+ end
482
+
483
+ def add_creditcard_payment_method(xml)
484
+ xml.tag! 'subscription' do
485
+ xml.tag! 'paymentMethod', "credit card"
486
+ end
487
+ end
488
+
489
+ def add_creditcard_or_subscription(xml, money, creditcard_or_reference, options)
490
+ if creditcard_or_reference.is_a?(String)
491
+ add_purchase_data(xml, money, true, options)
492
+ add_subscription(xml, options, creditcard_or_reference)
493
+ else
494
+ add_address(xml, creditcard_or_reference, options[:billing_address], options)
495
+ add_purchase_data(xml, money, true, options)
496
+ add_creditcard(xml, creditcard_or_reference)
497
+ end
498
+ end
499
+
500
+ # Where we actually build the full SOAP request using builder
501
+ def build_request(body, options)
502
+ xml = Builder::XmlMarkup.new :indent => 2
503
+ xml.instruct!
504
+ xml.tag! 's:Envelope', {'xmlns:s' => 'http://schemas.xmlsoap.org/soap/envelope/'} do
505
+ xml.tag! 's:Header' do
506
+ xml.tag! 'wsse:Security', {'s:mustUnderstand' => '1', 'xmlns:wsse' => 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'} do
507
+ xml.tag! 'wsse:UsernameToken' do
508
+ xml.tag! 'wsse:Username', @options[:login]
509
+ xml.tag! 'wsse:Password', @options[:password], 'Type' => 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText'
510
+ end
511
+ end
512
+ end
513
+ xml.tag! 's:Body', {'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance', 'xmlns:xsd' => 'http://www.w3.org/2001/XMLSchema'} do
514
+ xml.tag! 'requestMessage', {'xmlns' => "urn:schemas-cybersource-com:transaction-data-#{XSD_VERSION}"} do
515
+ add_merchant_data(xml, options)
516
+ xml << body
517
+ end
518
+ end
519
+ end
520
+ xml.target!
521
+ end
522
+
523
+ # Contact CyberSource, make the SOAP request, and parse the reply into a
524
+ # Response object
525
+ def commit(request, options)
526
+ response = parse(ssl_post(test? ? self.test_url : self.live_url, build_request(request, options)))
527
+
528
+ success = response[:decision] == "ACCEPT"
529
+ message = @@response_codes[('r' + response[:reasonCode]).to_sym] rescue response[:message]
530
+ authorization = success ? [ options[:order_id], response[:requestID], response[:requestToken] ].compact.join(";") : nil
531
+
532
+ Response.new(success, message, response,
533
+ :test => test?,
534
+ :authorization => authorization,
535
+ :avs_result => { :code => response[:avsCode] },
536
+ :cvv_result => response[:cvCode]
537
+ )
538
+ end
539
+
540
+ # Parse the SOAP response
541
+ # Technique inspired by the Paypal Gateway
542
+ def parse(xml)
543
+ reply = {}
544
+ xml = REXML::Document.new(xml)
545
+ if root = REXML::XPath.first(xml, "//c:replyMessage")
546
+ root.elements.to_a.each do |node|
547
+ case node.name
548
+ when 'c:reasonCode'
549
+ reply[:message] = reply(node.text)
550
+ else
551
+ parse_element(reply, node)
552
+ end
553
+ end
554
+ elsif root = REXML::XPath.first(xml, "//soap:Fault")
555
+ parse_element(reply, root)
556
+ reply[:message] = "#{reply[:faultcode]}: #{reply[:faultstring]}"
557
+ end
558
+ return reply
559
+ end
560
+
561
+ def parse_element(reply, node)
562
+ if node.has_elements?
563
+ node.elements.each{|e| parse_element(reply, e) }
564
+ else
565
+ if node.parent.name =~ /item/
566
+ parent = node.parent.name + (node.parent.attributes["id"] ? "_" + node.parent.attributes["id"] : '')
567
+ reply[(parent + '_' + node.name).to_sym] = node.text
568
+ else
569
+ reply[node.name.to_sym] = node.text
570
+ end
571
+ end
572
+ return reply
573
+ end
574
+ end
575
+ end
576
+ end