patmaddox-activemerchant 1.4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (295) hide show
  1. data/CHANGELOG +480 -0
  2. data/CONTRIBUTORS +126 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README +136 -0
  5. data/Rakefile +153 -0
  6. data/gem-public_cert.pem +20 -0
  7. data/init.rb +3 -0
  8. data/lib/active_merchant.rb +66 -0
  9. data/lib/active_merchant/billing/avs_result.rb +98 -0
  10. data/lib/active_merchant/billing/base.rb +57 -0
  11. data/lib/active_merchant/billing/check.rb +68 -0
  12. data/lib/active_merchant/billing/credit_card.rb +159 -0
  13. data/lib/active_merchant/billing/credit_card_formatting.rb +21 -0
  14. data/lib/active_merchant/billing/credit_card_methods.rb +125 -0
  15. data/lib/active_merchant/billing/cvv_result.rb +38 -0
  16. data/lib/active_merchant/billing/expiry_date.rb +34 -0
  17. data/lib/active_merchant/billing/gateway.rb +158 -0
  18. data/lib/active_merchant/billing/gateways.rb +18 -0
  19. data/lib/active_merchant/billing/gateways/authorize_net.rb +657 -0
  20. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +743 -0
  21. data/lib/active_merchant/billing/gateways/beanstream.rb +102 -0
  22. data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +233 -0
  23. data/lib/active_merchant/billing/gateways/beanstream_interac.rb +54 -0
  24. data/lib/active_merchant/billing/gateways/bogus.rb +101 -0
  25. data/lib/active_merchant/billing/gateways/braintree.rb +17 -0
  26. data/lib/active_merchant/billing/gateways/card_stream.rb +230 -0
  27. data/lib/active_merchant/billing/gateways/cyber_source.rb +406 -0
  28. data/lib/active_merchant/billing/gateways/data_cash.rb +595 -0
  29. data/lib/active_merchant/billing/gateways/efsnet.rb +229 -0
  30. data/lib/active_merchant/billing/gateways/elavon.rb +134 -0
  31. data/lib/active_merchant/billing/gateways/eway.rb +277 -0
  32. data/lib/active_merchant/billing/gateways/exact.rb +222 -0
  33. data/lib/active_merchant/billing/gateways/first_pay.rb +172 -0
  34. data/lib/active_merchant/billing/gateways/instapay.rb +164 -0
  35. data/lib/active_merchant/billing/gateways/jetpay.rb +270 -0
  36. data/lib/active_merchant/billing/gateways/linkpoint.rb +449 -0
  37. data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +154 -0
  38. data/lib/active_merchant/billing/gateways/merchant_ware.rb +283 -0
  39. data/lib/active_merchant/billing/gateways/modern_payments.rb +36 -0
  40. data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +220 -0
  41. data/lib/active_merchant/billing/gateways/moneris.rb +205 -0
  42. data/lib/active_merchant/billing/gateways/net_registry.rb +189 -0
  43. data/lib/active_merchant/billing/gateways/netbilling.rb +168 -0
  44. data/lib/active_merchant/billing/gateways/ogone.rb +279 -0
  45. data/lib/active_merchant/billing/gateways/pay_junction.rb +392 -0
  46. data/lib/active_merchant/billing/gateways/pay_secure.rb +120 -0
  47. data/lib/active_merchant/billing/gateways/payflow.rb +236 -0
  48. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +207 -0
  49. data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +39 -0
  50. data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +13 -0
  51. data/lib/active_merchant/billing/gateways/payflow_express.rb +138 -0
  52. data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +15 -0
  53. data/lib/active_merchant/billing/gateways/payflow_uk.rb +21 -0
  54. data/lib/active_merchant/billing/gateways/payment_express.rb +230 -0
  55. data/lib/active_merchant/billing/gateways/paypal.rb +121 -0
  56. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +326 -0
  57. data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +38 -0
  58. data/lib/active_merchant/billing/gateways/paypal_ca.rb +13 -0
  59. data/lib/active_merchant/billing/gateways/paypal_express.rb +130 -0
  60. data/lib/active_merchant/billing/gateways/paypal_express_common.rb +20 -0
  61. data/lib/active_merchant/billing/gateways/plugnpay.rb +292 -0
  62. data/lib/active_merchant/billing/gateways/psigate.rb +214 -0
  63. data/lib/active_merchant/billing/gateways/psl_card.rb +306 -0
  64. data/lib/active_merchant/billing/gateways/quickpay.rb +213 -0
  65. data/lib/active_merchant/billing/gateways/realex.rb +200 -0
  66. data/lib/active_merchant/billing/gateways/sage.rb +146 -0
  67. data/lib/active_merchant/billing/gateways/sage/sage_bankcard.rb +88 -0
  68. data/lib/active_merchant/billing/gateways/sage/sage_core.rb +116 -0
  69. data/lib/active_merchant/billing/gateways/sage/sage_virtual_check.rb +97 -0
  70. data/lib/active_merchant/billing/gateways/sage_pay.rb +308 -0
  71. data/lib/active_merchant/billing/gateways/sallie_mae.rb +144 -0
  72. data/lib/active_merchant/billing/gateways/secure_pay.rb +31 -0
  73. data/lib/active_merchant/billing/gateways/secure_pay_au.rb +157 -0
  74. data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +113 -0
  75. data/lib/active_merchant/billing/gateways/skip_jack.rb +452 -0
  76. data/lib/active_merchant/billing/gateways/smart_ps.rb +265 -0
  77. data/lib/active_merchant/billing/gateways/trans_first.rb +127 -0
  78. data/lib/active_merchant/billing/gateways/transax.rb +26 -0
  79. data/lib/active_merchant/billing/gateways/trust_commerce.rb +418 -0
  80. data/lib/active_merchant/billing/gateways/usa_epay.rb +194 -0
  81. data/lib/active_merchant/billing/gateways/verifi.rb +228 -0
  82. data/lib/active_merchant/billing/gateways/viaklix.rb +189 -0
  83. data/lib/active_merchant/billing/gateways/wirecard.rb +318 -0
  84. data/lib/active_merchant/billing/integrations.rb +29 -0
  85. data/lib/active_merchant/billing/integrations/action_view_helper.rb +79 -0
  86. data/lib/active_merchant/billing/integrations/bogus.rb +23 -0
  87. data/lib/active_merchant/billing/integrations/bogus/helper.rb +17 -0
  88. data/lib/active_merchant/billing/integrations/bogus/notification.rb +11 -0
  89. data/lib/active_merchant/billing/integrations/bogus/return.rb +10 -0
  90. data/lib/active_merchant/billing/integrations/chronopay.rb +23 -0
  91. data/lib/active_merchant/billing/integrations/chronopay/helper.rb +81 -0
  92. data/lib/active_merchant/billing/integrations/chronopay/notification.rb +156 -0
  93. data/lib/active_merchant/billing/integrations/chronopay/return.rb +10 -0
  94. data/lib/active_merchant/billing/integrations/gestpay.rb +25 -0
  95. data/lib/active_merchant/billing/integrations/gestpay/common.rb +42 -0
  96. data/lib/active_merchant/billing/integrations/gestpay/helper.rb +70 -0
  97. data/lib/active_merchant/billing/integrations/gestpay/notification.rb +83 -0
  98. data/lib/active_merchant/billing/integrations/gestpay/return.rb +10 -0
  99. data/lib/active_merchant/billing/integrations/helper.rb +93 -0
  100. data/lib/active_merchant/billing/integrations/hi_trust.rb +27 -0
  101. data/lib/active_merchant/billing/integrations/hi_trust/helper.rb +58 -0
  102. data/lib/active_merchant/billing/integrations/hi_trust/notification.rb +59 -0
  103. data/lib/active_merchant/billing/integrations/hi_trust/return.rb +67 -0
  104. data/lib/active_merchant/billing/integrations/nochex.rb +88 -0
  105. data/lib/active_merchant/billing/integrations/nochex/helper.rb +68 -0
  106. data/lib/active_merchant/billing/integrations/nochex/notification.rb +94 -0
  107. data/lib/active_merchant/billing/integrations/nochex/return.rb +10 -0
  108. data/lib/active_merchant/billing/integrations/notification.rb +62 -0
  109. data/lib/active_merchant/billing/integrations/paypal.rb +39 -0
  110. data/lib/active_merchant/billing/integrations/paypal/helper.rb +119 -0
  111. data/lib/active_merchant/billing/integrations/paypal/notification.rb +154 -0
  112. data/lib/active_merchant/billing/integrations/paypal/return.rb +10 -0
  113. data/lib/active_merchant/billing/integrations/quickpay.rb +17 -0
  114. data/lib/active_merchant/billing/integrations/quickpay/helper.rb +72 -0
  115. data/lib/active_merchant/billing/integrations/quickpay/notification.rb +74 -0
  116. data/lib/active_merchant/billing/integrations/return.rb +35 -0
  117. data/lib/active_merchant/billing/integrations/two_checkout.rb +23 -0
  118. data/lib/active_merchant/billing/integrations/two_checkout/helper.rb +59 -0
  119. data/lib/active_merchant/billing/integrations/two_checkout/notification.rb +114 -0
  120. data/lib/active_merchant/billing/integrations/two_checkout/return.rb +17 -0
  121. data/lib/active_merchant/billing/response.rb +32 -0
  122. data/lib/active_merchant/lib/connection.rb +170 -0
  123. data/lib/active_merchant/lib/country.rb +319 -0
  124. data/lib/active_merchant/lib/error.rb +4 -0
  125. data/lib/active_merchant/lib/post_data.rb +22 -0
  126. data/lib/active_merchant/lib/posts_data.rb +47 -0
  127. data/lib/active_merchant/lib/requires_parameters.rb +16 -0
  128. data/lib/active_merchant/lib/utils.rb +18 -0
  129. data/lib/active_merchant/lib/validateable.rb +76 -0
  130. data/lib/certs/cacert.pem +7815 -0
  131. data/lib/support/gateway_support.rb +58 -0
  132. data/script/destroy +14 -0
  133. data/script/generate +14 -0
  134. data/test/fixtures.yml +355 -0
  135. data/test/remote/gateways/remote_authorize_net_cim_test.rb +460 -0
  136. data/test/remote/gateways/remote_authorize_net_test.rb +145 -0
  137. data/test/remote/gateways/remote_beanstream_interac_test.rb +53 -0
  138. data/test/remote/gateways/remote_beanstream_test.rb +150 -0
  139. data/test/remote/gateways/remote_braintree_test.rb +154 -0
  140. data/test/remote/gateways/remote_card_stream_test.rb +148 -0
  141. data/test/remote/gateways/remote_cyber_source_test.rb +144 -0
  142. data/test/remote/gateways/remote_data_cash_test.rb +357 -0
  143. data/test/remote/gateways/remote_efsnet_test.rb +81 -0
  144. data/test/remote/gateways/remote_elavon_test.rb +66 -0
  145. data/test/remote/gateways/remote_eway_test.rb +74 -0
  146. data/test/remote/gateways/remote_exact_test.rb +60 -0
  147. data/test/remote/gateways/remote_first_pay_test.rb +87 -0
  148. data/test/remote/gateways/remote_instapay_test.rb +61 -0
  149. data/test/remote/gateways/remote_jetpay_test.rb +103 -0
  150. data/test/remote/gateways/remote_linkpoint_test.rb +121 -0
  151. data/test/remote/gateways/remote_merchant_e_solutions_test.rb +173 -0
  152. data/test/remote/gateways/remote_merchant_ware_test.rb +113 -0
  153. data/test/remote/gateways/remote_modern_payments_cim_test.rb +58 -0
  154. data/test/remote/gateways/remote_modern_payments_test.rb +57 -0
  155. data/test/remote/gateways/remote_moneris_test.rb +82 -0
  156. data/test/remote/gateways/remote_net_registry_test.rb +85 -0
  157. data/test/remote/gateways/remote_netbilling_test.rb +70 -0
  158. data/test/remote/gateways/remote_ogone_test.rb +115 -0
  159. data/test/remote/gateways/remote_pay_junction_test.rb +143 -0
  160. data/test/remote/gateways/remote_pay_secure_test.rb +39 -0
  161. data/test/remote/gateways/remote_payflow_express_test.rb +50 -0
  162. data/test/remote/gateways/remote_payflow_test.rb +237 -0
  163. data/test/remote/gateways/remote_payflow_uk_test.rb +173 -0
  164. data/test/remote/gateways/remote_payment_express_test.rb +136 -0
  165. data/test/remote/gateways/remote_paypal_express_test.rb +49 -0
  166. data/test/remote/gateways/remote_paypal_test.rb +191 -0
  167. data/test/remote/gateways/remote_plugnpay_test.rb +72 -0
  168. data/test/remote/gateways/remote_psigate_test.rb +50 -0
  169. data/test/remote/gateways/remote_psl_card_test.rb +125 -0
  170. data/test/remote/gateways/remote_quickpay_test.rb +190 -0
  171. data/test/remote/gateways/remote_realex_test.rb +224 -0
  172. data/test/remote/gateways/remote_sage_bankcard_test.rb +109 -0
  173. data/test/remote/gateways/remote_sage_pay_test.rb +219 -0
  174. data/test/remote/gateways/remote_sage_test.rb +87 -0
  175. data/test/remote/gateways/remote_sage_virtual_check_test.rb +62 -0
  176. data/test/remote/gateways/remote_sallie_mae_test.rb +51 -0
  177. data/test/remote/gateways/remote_secure_pay_au_test.rb +40 -0
  178. data/test/remote/gateways/remote_secure_pay_tech_test.rb +37 -0
  179. data/test/remote/gateways/remote_secure_pay_test.rb +28 -0
  180. data/test/remote/gateways/remote_skipjack_test.rb +105 -0
  181. data/test/remote/gateways/remote_trans_first_test.rb +34 -0
  182. data/test/remote/gateways/remote_transax_test.rb +112 -0
  183. data/test/remote/gateways/remote_trust_commerce_test.rb +152 -0
  184. data/test/remote/gateways/remote_usa_epay_test.rb +46 -0
  185. data/test/remote/gateways/remote_verifi_test.rb +107 -0
  186. data/test/remote/gateways/remote_viaklix_test.rb +43 -0
  187. data/test/remote/gateways/remote_wirecard_test.rb +111 -0
  188. data/test/remote/integrations/remote_gestpay_integration_test.rb +37 -0
  189. data/test/remote/integrations/remote_paypal_integration_test.rb +26 -0
  190. data/test/test_helper.rb +182 -0
  191. data/test/unit/avs_result_test.rb +59 -0
  192. data/test/unit/base_test.rb +55 -0
  193. data/test/unit/check_test.rb +88 -0
  194. data/test/unit/connection_test.rb +129 -0
  195. data/test/unit/country_code_test.rb +33 -0
  196. data/test/unit/country_test.rb +64 -0
  197. data/test/unit/credit_card_formatting_test.rb +19 -0
  198. data/test/unit/credit_card_methods_test.rb +179 -0
  199. data/test/unit/credit_card_test.rb +318 -0
  200. data/test/unit/cvv_result_test.rb +33 -0
  201. data/test/unit/expiry_date_test.rb +32 -0
  202. data/test/unit/gateways/authorize_net_cim_test.rb +676 -0
  203. data/test/unit/gateways/authorize_net_test.rb +290 -0
  204. data/test/unit/gateways/beanstream_interac_test.rb +51 -0
  205. data/test/unit/gateways/beanstream_test.rb +108 -0
  206. data/test/unit/gateways/bogus_test.rb +46 -0
  207. data/test/unit/gateways/braintree_test.rb +126 -0
  208. data/test/unit/gateways/card_stream_test.rb +90 -0
  209. data/test/unit/gateways/cyber_source_test.rb +188 -0
  210. data/test/unit/gateways/data_cash_test.rb +133 -0
  211. data/test/unit/gateways/efsnet_test.rb +123 -0
  212. data/test/unit/gateways/elavon_test.rb +139 -0
  213. data/test/unit/gateways/eway_test.rb +118 -0
  214. data/test/unit/gateways/exact_test.rb +156 -0
  215. data/test/unit/gateways/first_pay_test.rb +125 -0
  216. data/test/unit/gateways/gateway_test.rb +48 -0
  217. data/test/unit/gateways/instapay_test.rb +102 -0
  218. data/test/unit/gateways/jetpay_test.rb +185 -0
  219. data/test/unit/gateways/linkpoint_test.rb +197 -0
  220. data/test/unit/gateways/merchant_e_solutions_test.rb +169 -0
  221. data/test/unit/gateways/merchant_ware_test.rb +188 -0
  222. data/test/unit/gateways/modern_payments_cim_test.rb +162 -0
  223. data/test/unit/gateways/moneris_test.rb +158 -0
  224. data/test/unit/gateways/net_registry_test.rb +416 -0
  225. data/test/unit/gateways/netbilling_test.rb +54 -0
  226. data/test/unit/gateways/ogone_test.rb +319 -0
  227. data/test/unit/gateways/pay_junction_test.rb +123 -0
  228. data/test/unit/gateways/pay_secure_test.rb +71 -0
  229. data/test/unit/gateways/payflow_express_test.rb +173 -0
  230. data/test/unit/gateways/payflow_express_uk_test.rb +86 -0
  231. data/test/unit/gateways/payflow_test.rb +305 -0
  232. data/test/unit/gateways/payflow_uk_test.rb +30 -0
  233. data/test/unit/gateways/payment_express_test.rb +195 -0
  234. data/test/unit/gateways/paypal_express_test.rb +382 -0
  235. data/test/unit/gateways/paypal_test.rb +569 -0
  236. data/test/unit/gateways/plugnpay_test.rb +86 -0
  237. data/test/unit/gateways/psigate_test.rb +169 -0
  238. data/test/unit/gateways/psl_card_test.rb +64 -0
  239. data/test/unit/gateways/quickpay_test.rb +112 -0
  240. data/test/unit/gateways/realex_test.rb +151 -0
  241. data/test/unit/gateways/sage_bankcard_test.rb +196 -0
  242. data/test/unit/gateways/sage_pay_test.rb +139 -0
  243. data/test/unit/gateways/sage_virtual_check_test.rb +71 -0
  244. data/test/unit/gateways/sallie_mae_test.rb +53 -0
  245. data/test/unit/gateways/secure_pay_au_test.rb +207 -0
  246. data/test/unit/gateways/secure_pay_tech_test.rb +44 -0
  247. data/test/unit/gateways/secure_pay_test.rb +87 -0
  248. data/test/unit/gateways/skip_jack_test.rb +213 -0
  249. data/test/unit/gateways/trans_first_test.rb +112 -0
  250. data/test/unit/gateways/trust_commerce_test.rb +90 -0
  251. data/test/unit/gateways/usa_epay_test.rb +128 -0
  252. data/test/unit/gateways/verifi_test.rb +96 -0
  253. data/test/unit/gateways/viaklix_test.rb +78 -0
  254. data/test/unit/gateways/wirecard_test.rb +250 -0
  255. data/test/unit/generators/test_gateway_generator.rb +46 -0
  256. data/test/unit/generators/test_generator_helper.rb +20 -0
  257. data/test/unit/generators/test_integration_generator.rb +53 -0
  258. data/test/unit/integrations/action_view_helper_test.rb +50 -0
  259. data/test/unit/integrations/bogus_module_test.rb +20 -0
  260. data/test/unit/integrations/chronopay_module_test.rb +13 -0
  261. data/test/unit/integrations/gestpay_module_test.rb +14 -0
  262. data/test/unit/integrations/helpers/bogus_helper_test.rb +28 -0
  263. data/test/unit/integrations/helpers/chronopay_helper_test.rb +67 -0
  264. data/test/unit/integrations/helpers/gestpay_helper_test.rb +100 -0
  265. data/test/unit/integrations/helpers/hi_trust_helper_test.rb +16 -0
  266. data/test/unit/integrations/helpers/nochex_helper_test.rb +53 -0
  267. data/test/unit/integrations/helpers/paypal_helper_test.rb +171 -0
  268. data/test/unit/integrations/helpers/quickpay_helper_test.rb +40 -0
  269. data/test/unit/integrations/helpers/two_checkout_helper_test.rb +92 -0
  270. data/test/unit/integrations/hi_trust_module_test.rb +13 -0
  271. data/test/unit/integrations/nochex_module_test.rb +13 -0
  272. data/test/unit/integrations/notifications/chronopay_notification_test.rb +66 -0
  273. data/test/unit/integrations/notifications/gestpay_notification_test.rb +60 -0
  274. data/test/unit/integrations/notifications/hi_trust_notification_test.rb +59 -0
  275. data/test/unit/integrations/notifications/nochex_notification_test.rb +51 -0
  276. data/test/unit/integrations/notifications/notification_test.rb +54 -0
  277. data/test/unit/integrations/notifications/paypal_notification_test.rb +85 -0
  278. data/test/unit/integrations/notifications/quickpay_notification_test.rb +69 -0
  279. data/test/unit/integrations/notifications/two_checkout_notification_test.rb +55 -0
  280. data/test/unit/integrations/paypal_module_test.rb +28 -0
  281. data/test/unit/integrations/quickpay_module_test.rb +9 -0
  282. data/test/unit/integrations/returns/chronopay_return_test.rb +11 -0
  283. data/test/unit/integrations/returns/gestpay_return_test.rb +10 -0
  284. data/test/unit/integrations/returns/hi_trust_return_test.rb +24 -0
  285. data/test/unit/integrations/returns/nochex_return_test.rb +10 -0
  286. data/test/unit/integrations/returns/paypal_return_test.rb +10 -0
  287. data/test/unit/integrations/returns/return_test.rb +11 -0
  288. data/test/unit/integrations/returns/two_checkout_return_test.rb +24 -0
  289. data/test/unit/integrations/two_checkout_module_test.rb +13 -0
  290. data/test/unit/post_data_test.rb +55 -0
  291. data/test/unit/posts_data_test.rb +48 -0
  292. data/test/unit/response_test.rb +28 -0
  293. data/test/unit/utils_test.rb +7 -0
  294. data/test/unit/validateable_test.rb +60 -0
  295. metadata +367 -0
@@ -0,0 +1,168 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ class NetbillingGateway < Gateway
4
+ URL = 'https://secure.netbilling.com:1402/gw/sas/direct3.1'
5
+
6
+ TRANSACTIONS = {
7
+ :authorization => 'A',
8
+ :purchase => 'S',
9
+ :referenced_credit => 'R',
10
+ :unreferenced_credit => 'C',
11
+ :capture => 'D'
12
+ }
13
+
14
+ SUCCESS_CODES = [ '1', 'T' ]
15
+ SUCCESS_MESSAGE = 'The transaction was approved'
16
+ FAILURE_MESSAGE = 'The transaction failed'
17
+ TEST_LOGIN = '104901072025'
18
+
19
+ self.display_name = 'NETbilling'
20
+ self.homepage_url = 'http://www.netbilling.com'
21
+ self.supported_countries = ['US']
22
+ self.supported_cardtypes = [:visa, :master, :american_express, :discover, :jcb, :diners_club]
23
+
24
+ def initialize(options = {})
25
+ requires!(options, :login)
26
+ @options = options
27
+ super
28
+ end
29
+
30
+ def authorize(money, credit_card, options = {})
31
+ post = {}
32
+ add_amount(post, money)
33
+ add_invoice(post, options)
34
+ add_credit_card(post, credit_card)
35
+ add_address(post, credit_card, options)
36
+ add_customer_data(post, options)
37
+
38
+ commit(:authorization, money, post)
39
+ end
40
+
41
+ def purchase(money, credit_card, options = {})
42
+ post = {}
43
+ add_amount(post, money)
44
+ add_invoice(post, options)
45
+ add_credit_card(post, credit_card)
46
+ add_address(post, credit_card, options)
47
+ add_customer_data(post, options)
48
+
49
+ commit(:purchase, money, post)
50
+ end
51
+
52
+ def capture(money, authorization, options = {})
53
+ post = {}
54
+ add_reference(post, authorization)
55
+ commit(:capture, money, post)
56
+ end
57
+
58
+ def test?
59
+ @options[:login] == TEST_LOGIN || super
60
+ end
61
+
62
+ private
63
+ def add_amount(post, money)
64
+ post[:amount] = amount(money)
65
+ end
66
+
67
+ def add_reference(post, reference)
68
+ post[:orig_id] = reference
69
+ end
70
+
71
+ def add_customer_data(post, options)
72
+ post[:cust_email] = options[:email]
73
+ post[:cust_ip] = options[:ip]
74
+ end
75
+
76
+ def add_address(post, credit_card, options)
77
+ if billing_address = options[:billing_address] || options[:address]
78
+ post[:bill_street] = billing_address[:address1]
79
+ post[:cust_phone] = billing_address[:phone]
80
+ post[:bill_zip] = billing_address[:zip]
81
+ post[:bill_city] = billing_address[:city]
82
+ post[:bill_country] = billing_address[:country]
83
+ post[:bill_state] = billing_address[:state]
84
+ end
85
+
86
+ if shipping_address = options[:shipping_address]
87
+ first_name, last_name = parse_first_and_last_name(shipping_address[:name])
88
+
89
+ post[:ship_name1] = first_name
90
+ post[:ship_name2] = last_name
91
+ post[:ship_street] = shipping_address[:address1]
92
+ post[:ship_zip] = shipping_address[:zip]
93
+ post[:ship_city] = shipping_address[:city]
94
+ post[:ship_country] = shipping_address[:country]
95
+ post[:ship_state] = shipping_address[:state]
96
+ end
97
+ end
98
+
99
+ def add_invoice(post, options)
100
+ post[:description] = options[:description]
101
+ end
102
+
103
+ def add_credit_card(post, credit_card)
104
+ post[:bill_name1] = credit_card.first_name
105
+ post[:bill_name2] = credit_card.last_name
106
+ post[:card_number] = credit_card.number
107
+ post[:card_expire] = expdate(credit_card)
108
+ post[:card_cvv2] = credit_card.verification_value
109
+ end
110
+
111
+ def parse(body)
112
+ results = {}
113
+ body.split(/&/).each do |pair|
114
+ key,val = pair.split(/=/)
115
+ results[key.to_sym] = CGI.unescape(val)
116
+ end
117
+ results
118
+ end
119
+
120
+ def commit(action, money, parameters)
121
+ response = parse(ssl_post(URL, post_data(action, parameters)))
122
+
123
+ Response.new(success?(response), message_from(response), response,
124
+ :test => test_response?(response),
125
+ :authorization => response[:trans_id],
126
+ :avs_result => { :code => response[:avs_code]},
127
+ :cvv_result => response[:cvv2_code]
128
+ )
129
+ end
130
+
131
+ def test_response?(response)
132
+ !!(test? || response[:auth_msg] =~ /TEST/)
133
+ end
134
+
135
+ def success?(response)
136
+ SUCCESS_CODES.include?(response[:status_code])
137
+ end
138
+
139
+ def message_from(response)
140
+ success?(response) ? SUCCESS_MESSAGE : (response[:auth_msg] || FAILURE_MESSAGE)
141
+ end
142
+
143
+ def expdate(credit_card)
144
+ year = sprintf("%.4i", credit_card.year)
145
+ month = sprintf("%.2i", credit_card.month)
146
+
147
+ "#{month}#{year[-2..-1]}"
148
+ end
149
+
150
+ def post_data(action, parameters = {})
151
+ parameters[:account_id] = @options[:login]
152
+ parameters[:pay_type] = 'C'
153
+ parameters[:tran_type] = TRANSACTIONS[action]
154
+
155
+ parameters.reject{|k,v| v.blank?}.collect { |key, value| "#{key}=#{CGI.escape(value.to_s)}" }.join("&")
156
+ end
157
+
158
+ def parse_first_and_last_name(value)
159
+ name = value.to_s.split(' ')
160
+
161
+ last_name = name.pop || ''
162
+ first_name = name.join(' ')
163
+ [ first_name, last_name ]
164
+ end
165
+ end
166
+ end
167
+ end
168
+
@@ -0,0 +1,279 @@
1
+ require 'rexml/document'
2
+
3
+ module ActiveMerchant #:nodoc:
4
+ module Billing #:nodoc:
5
+ # = Ogone DirectLink Gateway
6
+ #
7
+ # DirectLink is the API version of the Ogone Payment Platform. It allows server to server
8
+ # communication between Ogone systems and your e-commerce website.
9
+ #
10
+ # This implementation follows the specification provided in the DirectLink integration
11
+ # guide version 2.4 (December 2008), available here:
12
+ # https://secure.ogone.com/ncol/Ogone_DirectLink_EN.pdf
13
+ #
14
+ # It also features aliases, which allow to store/unstore credit cards, as specified in
15
+ # the Alias Manager Option guide version 2.2 available here:
16
+ # https://secure.ogone.com/ncol/Ogone_Alias_EN.pdf
17
+ #
18
+ # It was last tested on Release 04.79 of Ogone e-Commerce (dated 11/02/2009).
19
+ #
20
+ # For any questions or comments, please contact Nicolas Jacobeus (nj@belighted.com).
21
+ #
22
+ # == Example use:
23
+ #
24
+ # gateway = ActiveMerchant::Billing::OgoneGateway.new(
25
+ # :login => "my_ogone_psp_id",
26
+ # :user => "my_ogone_user_id",
27
+ # :password => "my_ogone_pswd",
28
+ # :signature => "my_ogone_sha1_signature" # extra security, only if you configured your Ogone environment so
29
+ # )
30
+ #
31
+ # # set up credit card obj as in main ActiveMerchant example
32
+ # creditcard = ActiveMerchant::Billing::CreditCard.new(
33
+ # :type => 'visa',
34
+ # :number => '4242424242424242',
35
+ # :month => 8,
36
+ # :year => 2009,
37
+ # :first_name => 'Bob',
38
+ # :last_name => 'Bobsen'
39
+ # )
40
+ #
41
+ # # run request
42
+ # response = gateway.purchase(1000, creditcard, :order_id => "1") # charge 10 EUR
43
+ #
44
+ # If you don't provide an :order_id, the gateway will generate a random one for you.
45
+ #
46
+ # puts response.success? # Check whether the transaction was successful
47
+ # puts response.message # Retrieve the message returned by Ogone
48
+ # puts response.authorization # Retrieve the unique transaction ID returned by Ogone
49
+ #
50
+ # To use the alias feature, simply add :alias in the options hash:
51
+ #
52
+ # gateway.purchase(1000, creditcard, :order_id => "1", :alias => "myawesomecustomer") # associates the alias to that creditcard
53
+ # gateway.purchase(2000, nil, :order_id => "2", :alias => "myawesomecustomer") # don't need to know the creditcard for subsequent orders
54
+ #
55
+ class OgoneGateway < Gateway
56
+
57
+ URLS = {
58
+ :test => { :order => 'https://secure.ogone.com/ncol/test/orderdirect.asp',
59
+ :maintenance => 'https://secure.ogone.com/ncol/test/maintenancedirect.asp' },
60
+ :production => { :order => 'https://secure.ogone.com/ncol/prod/orderdirect.asp',
61
+ :maintenance => 'https://secure.ogone.com/ncol/prod/maintenancedirect.asp' }
62
+ }
63
+
64
+ CVV_MAPPING = { 'OK' => 'M',
65
+ 'KO' => 'N',
66
+ 'NO' => 'P' }
67
+
68
+ AVS_MAPPING = { 'OK' => 'M',
69
+ 'KO' => 'N',
70
+ 'NO' => 'R' }
71
+ SUCCESS_MESSAGE = "The transaction was successful"
72
+
73
+ self.supported_countries = ['BE', 'DE', 'FR', 'NL', 'AT', 'CH']
74
+ # also supports Airplus and UATP
75
+ self.supported_cardtypes = [:visa, :master, :american_express, :diners_club, :discover, :jcb, :maestro]
76
+ self.homepage_url = 'http://www.ogone.com/'
77
+ self.display_name = 'Ogone'
78
+ self.default_currency = 'EUR'
79
+ self.money_format = :cents
80
+
81
+ def initialize(options = {})
82
+ requires!(options, :login, :user, :password)
83
+ @options = options
84
+ super
85
+ end
86
+
87
+ # Verify and reserve the specified amount on the account, without actually doing the transaction.
88
+ def authorize(money, payment_source, options = {})
89
+ post = {}
90
+ add_invoice(post, options)
91
+ add_payment_source(post, payment_source, options)
92
+ add_address(post, payment_source, options)
93
+ add_customer_data(post, options)
94
+ add_money(post, money, options)
95
+ commit('RES', post)
96
+ end
97
+
98
+ # Verify and transfer the specified amount.
99
+ def purchase(money, payment_source, options = {})
100
+ post = {}
101
+ add_invoice(post, options)
102
+ add_payment_source(post, payment_source, options)
103
+ add_address(post, payment_source, options)
104
+ add_customer_data(post, options)
105
+ add_money(post, money, options)
106
+ commit('SAL', post)
107
+ end
108
+
109
+ # Complete a previously authorized transaction.
110
+ def capture(money, authorization, options = {})
111
+ post = {}
112
+ add_authorization(post, reference_from(authorization))
113
+ add_invoice(post, options)
114
+ add_customer_data(post, options)
115
+ add_money(post, money, options)
116
+ commit('SAL', post)
117
+ end
118
+
119
+ # Cancels a previously authorized transaction.
120
+ def void(identification, options = {})
121
+ post = {}
122
+ add_authorization(post, reference_from(identification))
123
+ commit('DES', post)
124
+ end
125
+
126
+ # Credit the specified account by a specific amount.
127
+ def credit(money, identification_or_credit_card, options = {})
128
+ if reference_transaction?(identification_or_credit_card)
129
+ # Referenced credit: refund of a settled transaction
130
+ perform_reference_credit(money, identification_or_credit_card, options)
131
+ else # must be a credit card or card reference
132
+ perform_non_referenced_credit(money, identification_or_credit_card, options)
133
+ end
134
+ end
135
+
136
+ def test?
137
+ @options[:test] || super
138
+ end
139
+
140
+ private
141
+ def reference_from(authorization)
142
+ authorization.split(";").first
143
+ end
144
+
145
+ def reference_transaction?(identifier)
146
+ return false unless identifier.is_a?(String)
147
+ reference, action = identifier.split(";")
148
+ !action.nil?
149
+ end
150
+
151
+ def perform_reference_credit(money, payment_target, options = {})
152
+ post = {}
153
+ add_authorization(post, reference_from(payment_target))
154
+ add_money(post, money, options)
155
+ commit('RFD', post)
156
+ end
157
+
158
+ def perform_non_referenced_credit(money, payment_target, options = {})
159
+ # Non-referenced credit: acts like a reverse purchase
160
+ post = {}
161
+ add_invoice(post, options)
162
+ add_payment_source(post, payment_target, options)
163
+ add_address(post, payment_target, options)
164
+ add_customer_data(post, options)
165
+ add_money(post, money, options)
166
+ commit('RFD', post)
167
+ end
168
+
169
+ def add_payment_source(post, payment_source, options)
170
+ if payment_source.is_a?(String)
171
+ add_alias(post, payment_source)
172
+ add_eci(post, '9')
173
+ else
174
+ add_alias(post, options[:store])
175
+ add_creditcard(post, payment_source)
176
+ end
177
+ end
178
+
179
+ def add_eci(post, eci)
180
+ add_pair post, 'ECI', eci
181
+ end
182
+
183
+ def add_alias(post, _alias)
184
+ add_pair post, 'ALIAS', _alias
185
+ end
186
+
187
+ def add_authorization(post, authorization)
188
+ add_pair post, 'PAYID', authorization
189
+ end
190
+
191
+ def add_money(post, money, options)
192
+ add_pair post, 'currency', options[:currency] || currency(money)
193
+ add_pair post, 'amount', amount(money)
194
+ end
195
+
196
+ def add_customer_data(post, options)
197
+ add_pair post, 'EMAIL', options[:email]
198
+ add_pair post, 'REMOTE_ADDR', options[:ip]
199
+ end
200
+
201
+ def add_address(post, creditcard, options)
202
+ return unless options[:billing_address]
203
+ add_pair post, 'Owneraddress', options[:billing_address][:address1]
204
+ add_pair post, 'OwnerZip', options[:billing_address][:zip]
205
+ add_pair post, 'ownertown', options[:billing_address][:city]
206
+ add_pair post, 'ownercty', options[:billing_address][:country]
207
+ add_pair post, 'ownertelno', options[:billing_address][:phone]
208
+ end
209
+
210
+ def add_invoice(post, options)
211
+ add_pair post, 'orderID', options[:order_id] || generate_unique_id[0...30]
212
+ add_pair post, 'COM', options[:description]
213
+ end
214
+
215
+ def add_creditcard(post, creditcard)
216
+ add_pair post, 'CN', creditcard.name
217
+ add_pair post, 'CARDNO', creditcard.number
218
+ add_pair post, 'ED', "%02d%02s" % [creditcard.month, creditcard.year.to_s[-2..-1]]
219
+ add_pair post, 'CVC', creditcard.verification_value
220
+ end
221
+
222
+ def parse(body)
223
+ xml = REXML::Document.new(body)
224
+ xml.root.attributes
225
+ end
226
+
227
+ def commit(action, parameters)
228
+ add_pair parameters, 'PSPID', @options[:login]
229
+ add_pair parameters, 'USERID', @options[:user]
230
+ add_pair parameters, 'PSWD', @options[:password]
231
+ url = URLS[test? ? :test : :production][parameters['PAYID'] ? :maintenance : :order ]
232
+ response = parse(ssl_post(url, post_data(action, parameters)))
233
+ options = { :authorization => [response["PAYID"], action].join(";"),
234
+ :test => test?,
235
+ :avs_result => { :code => AVS_MAPPING[response["AAVCheck"]] },
236
+ :cvv_result => CVV_MAPPING[response["CVCCheck"]] }
237
+ Response.new(successful?(response), message_from(response), response, options)
238
+ end
239
+
240
+ def successful?(response)
241
+ response["NCERROR"] == "0"
242
+ end
243
+
244
+ def message_from(response)
245
+ if successful?(response)
246
+ SUCCESS_MESSAGE
247
+ else
248
+ format_error_message(response["NCERRORPLUS"])
249
+ end
250
+ end
251
+
252
+ def format_error_message(message)
253
+ raw_message = message.to_s.strip
254
+ case raw_message
255
+ when /\|/
256
+ raw_message.split("|").join(", ").capitalize
257
+ when /\//
258
+ raw_message.split("/").first.to_s.capitalize
259
+ else
260
+ raw_message.to_s.capitalize
261
+ end
262
+ end
263
+
264
+ def post_data(action, parameters = {})
265
+ add_pair parameters, 'Operation' , action
266
+ if @options[:signature] # the user wants a SHA-1 signature
267
+ string = ['orderID','amount','currency','CARDNO','PSPID','Operation','ALIAS'].map{|s|parameters[s]}.join + @options[:signature]
268
+ add_pair parameters, 'SHASign' , Digest::SHA1.hexdigest(string)
269
+ end
270
+ parameters.collect { |key, value| "#{key}=#{CGI.escape(value.to_s)}" }.join("&")
271
+ end
272
+
273
+ def add_pair(post, key, value, options = {})
274
+ post[key] = value if !value.blank? || options[:required]
275
+ end
276
+
277
+ end
278
+ end
279
+ end
@@ -0,0 +1,392 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ # PayJunction Gateway
4
+ #
5
+ # This gateway accepts the following arguments:
6
+ # :login => your PayJunction username
7
+ # :password => your PayJunction pass
8
+ #
9
+ # Example use:
10
+ #
11
+ # gateway = ActiveMerchant::Billing::Base.gateway(:pay_junction).new(
12
+ # :login => "my_account",
13
+ # :password => "my_pass"
14
+ # )
15
+ #
16
+ # # set up credit card obj as in main ActiveMerchant example
17
+ # creditcard = ActiveMerchant::Billing::CreditCard.new(
18
+ # :type => 'visa',
19
+ # :number => '4242424242424242',
20
+ # :month => 8,
21
+ # :year => 2009,
22
+ # :first_name => 'Bob',
23
+ # :last_name => 'Bobsen'
24
+ # )
25
+ #
26
+ # # optionally specify address if using AVS
27
+ # address = { :address1 => '101 Test Ave', :city => 'Test', :state => 'TS',
28
+ # :zip => '10101', :country => 'US' }
29
+ #
30
+ # # run request
31
+ # response = gateway.purchase(1000, creditcard, :address => address) # charge 10 dollars
32
+ #
33
+ # 1) Check whether the transaction was successful
34
+ #
35
+ # response.success?
36
+ #
37
+ # 2) Retrieve the message returned by PayJunction
38
+ #
39
+ # response.message
40
+ #
41
+ # 3) Retrieve the unique transaction ID returned by PayJunction
42
+ #
43
+ # response.authorization
44
+ #
45
+ # This gateway supports "instant" transactions. These transactions allow you
46
+ # to execute an operation on a previously run card without card information
47
+ # provided you have the transaction id from a previous transaction with the
48
+ # same card. All functions that take a credit card object for this gateway
49
+ # can take a transaction id string instead.
50
+ #
51
+ # Test Transactions
52
+ #
53
+ # See the source for initialize() for test account information. Note that
54
+ # PayJunction does not allow test transactions on your account, so if the
55
+ # gateway is running in :test mode your transaction will be run against
56
+ # PayJunction's global test account and will not show up in your account.
57
+ #
58
+ # Transactions ran on this account go through a test processor, so there is no
59
+ # need to void or otherwise cancel transactions. However, for further safety,
60
+ # please use the special card numbers 4433221111223344 or 4444333322221111 and
61
+ # keep transaction amounts below $4.00 when testing.
62
+ #
63
+ # Also note, transactions ran for an amount between $0.00 and $1.99 will likely
64
+ # result in denial. To demonstrate approvals, use amounts between $2.00 and $4.00.
65
+ #
66
+ # Test transactions can be checked by logging into
67
+ # PayJunction Web Login with username 'pj-cm-01' and password 'pj-cm-01p'
68
+ #
69
+ # Usage Details
70
+ #
71
+ # Below is a map of values accepted by PayJunction and how you should submit
72
+ # each to ActiveMerchant
73
+ #
74
+ # PayJunction Field ActiveMerchant Use
75
+ #
76
+ # dc_logon provide as :login value to gateway instantation
77
+ # dc_password provide as :password value to gateway instantiation
78
+ #
79
+ # dc_name will be retrieved from credit_card.name
80
+ # dc_first_name :first_name on CreditCard object instantation
81
+ # dc_last_name :last_name on CreditCard object instantation
82
+ # dc_number :number on CreditCard object instantation
83
+ # dc_expiration_month :month on CreditCard object instantation
84
+ # dc_expiration_year :year on CreditCard object instantation
85
+ # dc_verification_number :verification_value on CC object instantation
86
+ #
87
+ # dc_transaction_amount include as argument to method for your transaction type
88
+ # dc_transaction_type do nothing, set by your transaction type
89
+ # dc_version do nothing, always "1.2"
90
+ #
91
+ # dc_transaction_id submit as a string in place of CreditCard obj for
92
+ # "instant" transactions.
93
+ #
94
+ # dc_invoice :order_id in options for transaction method
95
+ # dc_notes :description in options for transaction method
96
+ #
97
+ # See example use above for address AVS fields
98
+ # See #recurring for periodic transaction fields
99
+ class PayJunctionGateway < Gateway
100
+ API_VERSION = '1.2'
101
+
102
+ class_inheritable_accessor :test_url, :live_url
103
+
104
+ self.test_url = "https://demo.payjunction.com/quick_link"
105
+ self.live_url = "https://payjunction.com/quick_link"
106
+
107
+ TEST_LOGIN = 'pj-ql-01'
108
+ TEST_PASSWORD = 'pj-ql-01p'
109
+
110
+ SUCCESS_CODES = ["00", "85"]
111
+ SUCCESS_MESSAGE = 'The transaction was approved.'
112
+
113
+ FAILURE_MESSAGE = 'The transaction was declined.'
114
+
115
+ DECLINE_CODES = {
116
+ "AE" => 'Address verification failed because address did not match.',
117
+ 'ZE' => 'Address verification failed because zip did not match.',
118
+ 'XE' => 'Address verification failed because zip and address did not match.',
119
+ 'YE' => 'Address verification failed because zip and address did not match.',
120
+ 'OE' => 'Address verification failed because address or zip did not match.',
121
+ 'UE' => 'Address verification failed because cardholder address unavailable.',
122
+ 'RE' => 'Address verification failed because address verification system is not working.',
123
+ 'SE' => 'Address verification failed because address verification system is unavailable.',
124
+ 'EE' => 'Address verification failed because transaction is not a mail or phone order.',
125
+ 'GE' => 'Address verification failed because international support is unavailable.',
126
+ 'CE' => 'Declined because CVV2/CVC2 code did not match.',
127
+ '04' => 'Declined. Pick up card.',
128
+ '07' => 'Declined. Pick up card (Special Condition).',
129
+ '41' => 'Declined. Pick up card (Lost).',
130
+ '43' => 'Declined. Pick up card (Stolen).',
131
+ '13' => 'Declined because of the amount is invalid.',
132
+ '14' => 'Declined because the card number is invalid.',
133
+ '80' => 'Declined because of an invalid date.',
134
+ '05' => 'Declined. Do not honor.',
135
+ '51' => 'Declined because of insufficient funds.',
136
+ 'N4' => 'Declined because the amount exceeds issuer withdrawal limit.',
137
+ '61' => 'Declined because the amount exceeds withdrawal limit.',
138
+ '62' => 'Declined because of an invalid service code (restricted).',
139
+ '65' => 'Declined because the card activity limit exceeded.',
140
+ '93' => 'Declined because there a violation (the transaction could not be completed).',
141
+ '06' => 'Declined because address verification failed.',
142
+ '54' => 'Declined because the card has expired.',
143
+ '15' => 'Declined because there is no such issuer.',
144
+ '96' => 'Declined because of a system error.',
145
+ 'N7' => 'Declined because of a CVV2/CVC2 mismatch.',
146
+ 'M4' => 'Declined.',
147
+ "FE" => "There was a format error with your Trinity Gateway Service (API) request.",
148
+ "LE" => "Could not log you in (problem with dc_logon and/or dc_password).",
149
+ 'NL' => 'Aborted because of a system error, please try again later. ',
150
+ 'AB' => 'Aborted because of an upstream system error, please try again later.'
151
+ }
152
+
153
+ self.supported_cardtypes = [:visa, :master, :american_express, :discover]
154
+ self.supported_countries = ['US']
155
+ self.homepage_url = 'http://www.payjunction.com/'
156
+ self.display_name = 'PayJunction'
157
+
158
+ def initialize(options = {})
159
+ requires!(options, :login, :password)
160
+ @options = options
161
+ super
162
+ end
163
+
164
+ # The first half of the preauth(authorize)/postauth(capture) model.
165
+ # Checks to make sure funds are available for a transaction, and returns a
166
+ # transaction_id that can be used later to postauthorize (capture) the funds.
167
+ def authorize(money, payment_source, options = {})
168
+ parameters = {
169
+ :transaction_amount => amount(money),
170
+ }
171
+
172
+ add_payment_source(parameters, payment_source)
173
+ add_address(parameters, options)
174
+ add_optional_fields(parameters, options)
175
+ commit('AUTHORIZATION', parameters)
176
+ end
177
+
178
+ # A simple sale, capturing funds immediately.
179
+ # Execute authorization and capture in a single step.
180
+ def purchase(money, payment_source, options = {})
181
+ parameters = {
182
+ :transaction_amount => amount(money),
183
+ }
184
+
185
+ add_payment_source(parameters, payment_source)
186
+ add_address(parameters, options)
187
+ add_optional_fields(parameters, options)
188
+ commit('AUTHORIZATION_CAPTURE', parameters)
189
+ end
190
+
191
+ # The second half of the preauth(authorize)/postauth(capture) model.
192
+ # Retrieve funds that have been previously authorized with _authorization_
193
+ def capture(money, authorization, options = {})
194
+ parameters = {
195
+ :transaction_id => authorization,
196
+ :posture => 'capture'
197
+ }
198
+
199
+ add_optional_fields(parameters, options)
200
+ commit('update', parameters)
201
+ end
202
+
203
+ # Return money to a card that was previously billed.
204
+ # _authorization_ should be the transaction id of the transaction we are returning.
205
+ def credit(money, authorization, options = {})
206
+ parameters = {
207
+ :transaction_amount => amount(money),
208
+ :transaction_id => authorization
209
+ }
210
+
211
+ commit('CREDIT', parameters)
212
+ end
213
+
214
+ # Cancel a transaction that has been charged but has not yet made it
215
+ # through the batch process.
216
+ def void(money, authorization, options = {})
217
+ parameters = {
218
+ :transaction_id => authorization,
219
+ :posture => 'void'
220
+ }
221
+
222
+ add_optional_fields(parameters, options)
223
+ commit('update', parameters)
224
+ end
225
+
226
+ # Set up a sale that will be made on a regular basis for the same amount
227
+ # (ex. $20 a month for 12 months)
228
+ #
229
+ # The parameter :periodicity should be specified as either :monthly, :weekly, or :daily
230
+ # The parameter :payments should be the number of payments to be made
231
+ #
232
+ # gateway.recurring('2000', creditcard, :periodicity => :monthly, :payments => 12)
233
+ #
234
+ # The optional parameter :starting_at takes a date or time argument or a string in
235
+ # YYYYMMDD format and can be used to specify when the first charge will be made.
236
+ # If omitted the first charge will be immediate.
237
+ def recurring(money, payment_source, options = {})
238
+ requires!(options, [:periodicity, :monthly, :weekly, :daily], :payments)
239
+
240
+ periodic_type = case options[:periodicity]
241
+ when :monthly
242
+ 'month'
243
+ when :weekly
244
+ 'week'
245
+ when :daily
246
+ 'day'
247
+ end
248
+
249
+ if options[:starting_at].nil?
250
+ start_date = Time.now.strftime('%Y-%m-%d')
251
+ elsif options[:starting_at].is_a?(String)
252
+ sa = options[:starting_at]
253
+ start_date = "#{sa[0..3]}-#{sa[4..5]}-#{sa[6..7]}"
254
+ else
255
+ start_date = options[:starting_at].strftime('%Y-%m-%d')
256
+ end
257
+
258
+ parameters = {
259
+ :transaction_amount => amount(money),
260
+ :schedule_periodic_type => periodic_type,
261
+ :schedule_create => 'true',
262
+ :schedule_limit => options[:payments].to_i > 1 ? options[:payments] : 1,
263
+ :schedule_periodic_number => 1,
264
+ :schedule_start => start_date
265
+ }
266
+
267
+ add_payment_source(parameters, payment_source)
268
+ add_optional_fields(parameters, options)
269
+ add_address(parameters, options)
270
+ commit('AUTHORIZATION_CAPTURE', parameters)
271
+ end
272
+
273
+ def test?
274
+ test_login? || @options[:test] || super
275
+ end
276
+
277
+ private
278
+
279
+ def test_login?
280
+ @options[:login] == TEST_LOGIN && @options[:password] == TEST_PASSWORD
281
+ end
282
+
283
+ # add fields depending on payment source selected (cc or transaction id)
284
+ def add_payment_source(params, source)
285
+ if source.is_a?(String)
286
+ add_billing_id(params, source)
287
+ else
288
+ add_creditcard(params, source)
289
+ end
290
+ end
291
+
292
+ # add fields for credit card
293
+ def add_creditcard(params, creditcard)
294
+ params[:name] = creditcard.name
295
+ params[:number] = creditcard.number
296
+ params[:expiration_month] = creditcard.month
297
+ params[:expiration_year] = creditcard.year
298
+ params[:verification_number] = creditcard.verification_value if creditcard.verification_value?
299
+ end
300
+
301
+ # add field for "instant" transaction, using previous transaction id
302
+ def add_billing_id(params, billingid)
303
+ params[:transaction_id] = billingid
304
+ end
305
+
306
+ # add address fields if present
307
+ def add_address(params, options)
308
+ address = options[:billing_address] || options[:address]
309
+
310
+ if address
311
+ params[:address] = address[:address1] unless address[:address1].blank?
312
+ params[:city] = address[:city] unless address[:city].blank?
313
+ params[:state] = address[:state] unless address[:state].blank?
314
+ params[:zipcode] = address[:zip] unless address[:zip].blank?
315
+ params[:country] = address[:country] unless address[:country].blank?
316
+ end
317
+ end
318
+
319
+ def add_optional_fields(params, options)
320
+ params[:notes] = options[:description] unless options[:description].blank?
321
+ params[:invoice] = options[:order_id].to_s.gsub(/[^-\/\w.,']/, '') unless options[:order_id].blank?
322
+ end
323
+
324
+ def commit(action, parameters)
325
+ url = test? ? self.test_url : self.live_url
326
+
327
+ response = parse( ssl_post(url, post_data(action, parameters)) )
328
+
329
+ Response.new(successful?(response), message_from(response), response,
330
+ :test => test?,
331
+ :authorization => response[:transaction_id] || parameters[:transaction_id]
332
+ )
333
+ end
334
+
335
+ def successful?(response)
336
+ SUCCESS_CODES.include?(response[:response_code]) || response[:query_status] == true
337
+ end
338
+
339
+ def message_from(response)
340
+ if successful?(response)
341
+ SUCCESS_MESSAGE
342
+ else
343
+ DECLINE_CODES[response[:response_code]] || FAILURE_MESSAGE
344
+ end
345
+ end
346
+
347
+ def post_data(action, params)
348
+ if test?
349
+ # test requests must use global test account
350
+ params[:logon] = TEST_LOGIN
351
+ params[:password] = TEST_PASSWORD
352
+ else
353
+ params[:logon] = @options[:login]
354
+ params[:password] = @options[:password]
355
+ end
356
+ params[:version] = API_VERSION
357
+ params[:transaction_type] = action
358
+
359
+ params.reject{|k,v| v.blank?}.collect{ |k, v| "dc_#{k.to_s}=#{CGI.escape(v.to_s)}" }.join("&")
360
+ end
361
+
362
+ def parse(body)
363
+ # PayJunction uses the Field Separator ASCII character to separate key/val
364
+ # pairs in the response. The <FS> character's octal value is 034.
365
+ #
366
+ # Sample response:
367
+ #
368
+ # transaction_id=44752<FS>response_code=M4<FS>response_message=Declined (INV TEST CARD).
369
+
370
+ pairs = body.chomp.split("\034")
371
+ response = {}
372
+ pairs.each do |pair|
373
+ key, val = pair.split('=')
374
+ response[key[3..-1].to_sym] = val ? normalize(val) : nil
375
+ end
376
+ response
377
+ end
378
+
379
+ # Make a ruby type out of the response string
380
+ def normalize(field)
381
+ case field
382
+ when "true" then true
383
+ when "false" then false
384
+ when "" then nil
385
+ when "null" then nil
386
+ else field
387
+ end
388
+ end
389
+
390
+ end
391
+ end
392
+ end