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,120 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ class PaySecureGateway < Gateway
4
+ URL = 'https://clearance.commsecure.com.au/cgi-bin/PSDirect'
5
+
6
+ self.money_format = :cents
7
+
8
+ # Currently Authorization and Capture is not implemented because
9
+ # capturing requires the original credit card information
10
+ TRANSACTIONS = {
11
+ :purchase => 'PURCHASE',
12
+ :authorization => 'AUTHORISE',
13
+ :capture => 'ADVICE',
14
+ :credit => 'REFUND'
15
+ }
16
+
17
+ SUCCESS = 'Accepted'
18
+ SUCCESS_MESSAGE = 'The transaction was approved'
19
+
20
+ self.supported_countries = ['AU']
21
+ self.homepage_url = 'http://www.commsecure.com.au/paysecure.shtml'
22
+ self.display_name = 'PaySecure'
23
+ self.supported_cardtypes = [:visa, :master, :american_express, :diners_club]
24
+
25
+ def initialize(options = {})
26
+ requires!(options, :login, :password)
27
+ @options = options
28
+ super
29
+ end
30
+
31
+ def purchase(money, credit_card, options = {})
32
+ requires!(options, :order_id)
33
+
34
+ post = {}
35
+ add_amount(post, money)
36
+ add_invoice(post, options)
37
+ add_credit_card(post, credit_card)
38
+
39
+ commit(:purchase, money, post)
40
+ end
41
+
42
+ private
43
+ # Used for capturing, which is currently not supported.
44
+ def add_reference(post, identification)
45
+ auth, trans_id = identification.split(";")
46
+ post[:authnum] = auth
47
+ post[:transid] = trans_id
48
+ end
49
+
50
+ def add_amount(post, money)
51
+ post[:amount] = amount(money)
52
+ end
53
+
54
+ def add_invoice(post, options)
55
+ post[:merchant_transid] = options[:order_id].to_s.slice(0,21)
56
+ post[:memnum] = options[:invoice]
57
+ post[:custnum] = options[:customer]
58
+ post[:clientdata] = options[:description]
59
+ end
60
+
61
+ def add_credit_card(post, credit_card)
62
+ post[:cardnum] = credit_card.number
63
+ post[:cardname] = credit_card.name
64
+ post[:expiry] = expdate(credit_card)
65
+ post[:cvv2] = credit_card.verification_value
66
+ end
67
+
68
+ def expdate(credit_card)
69
+ year = sprintf("%.4i", credit_card.year)
70
+ month = sprintf("%.2i", credit_card.month)
71
+
72
+ "#{month}#{year[-2..-1]}"
73
+ end
74
+
75
+ def commit(action, money, parameters)
76
+ response = parse( ssl_post(URL, post_data(action, parameters)) )
77
+
78
+ Response.new(successful?(response), message_from(response), response,
79
+ :test => test_response?(response),
80
+ :authorization => authorization_from(response)
81
+ )
82
+
83
+ end
84
+
85
+ def successful?(response)
86
+ response[:status] == SUCCESS
87
+ end
88
+
89
+ def authorization_from(response)
90
+ [ response[:authnum], response[:transid] ].compact.join(";")
91
+ end
92
+
93
+ def test_response?(response)
94
+ !!(response[:transid] =~ /SimProxy/)
95
+ end
96
+
97
+ def message_from(response)
98
+ successful?(response) ? SUCCESS_MESSAGE : response[:errorstring]
99
+ end
100
+
101
+ def parse(body)
102
+ response = {}
103
+ body.collect do |l|
104
+ key, value = l.split(":", 2)
105
+ response[key.to_s.downcase.to_sym] = value.strip
106
+ end
107
+ response
108
+ end
109
+
110
+ def post_data(action, parameters = {})
111
+ parameters[:request_type] = TRANSACTIONS[action]
112
+ parameters[:merchant_id] = @options[:login]
113
+ parameters[:password] = @options[:password]
114
+
115
+ parameters.reject{|k,v| v.blank?}.collect { |key, value| "#{key.to_s.upcase}=#{CGI.escape(value.to_s)}" }.join("&")
116
+ end
117
+ end
118
+ end
119
+ end
120
+
@@ -0,0 +1,236 @@
1
+ require File.dirname(__FILE__) + '/payflow/payflow_common_api'
2
+ require File.dirname(__FILE__) + '/payflow/payflow_response'
3
+ require File.dirname(__FILE__) + '/payflow_express'
4
+
5
+ module ActiveMerchant #:nodoc:
6
+ module Billing #:nodoc:
7
+ class PayflowGateway < Gateway
8
+ include PayflowCommonAPI
9
+
10
+ RECURRING_ACTIONS = Set.new([:add, :modify, :cancel, :inquiry, :reactivate, :payment])
11
+
12
+ self.supported_cardtypes = [:visa, :master, :american_express, :jcb, :discover, :diners_club]
13
+ self.homepage_url = 'https://www.paypal.com/cgi-bin/webscr?cmd=_payflow-pro-overview-outside'
14
+ self.display_name = 'PayPal Payflow Pro'
15
+
16
+ def authorize(money, credit_card_or_reference, options = {})
17
+ request = build_sale_or_authorization_request(:authorization, money, credit_card_or_reference, options)
18
+
19
+ commit(request)
20
+ end
21
+
22
+ def purchase(money, credit_card_or_reference, options = {})
23
+ request = build_sale_or_authorization_request(:purchase, money, credit_card_or_reference, options)
24
+
25
+ commit(request)
26
+ end
27
+
28
+ def credit(money, identification_or_credit_card, options = {})
29
+ if identification_or_credit_card.is_a?(String)
30
+ # Perform referenced credit
31
+ request = build_reference_request(:credit, money, identification_or_credit_card, options)
32
+ else
33
+ # Perform non-referenced credit
34
+ request = build_credit_card_request(:credit, money, identification_or_credit_card, options)
35
+ end
36
+
37
+ commit(request)
38
+ end
39
+
40
+ # Adds or modifies a recurring Payflow profile. See the Payflow Pro Recurring Billing Guide for more details:
41
+ # https://www.paypal.com/en_US/pdf/PayflowPro_RecurringBilling_Guide.pdf
42
+ #
43
+ # Several options are available to customize the recurring profile:
44
+ #
45
+ # * <tt>profile_id</tt> - is only required for editing a recurring profile
46
+ # * <tt>starting_at</tt> - takes a Date, Time, or string in mmddyyyy format. The date must be in the future.
47
+ # * <tt>name</tt> - The name of the customer to be billed. If not specified, the name from the credit card is used.
48
+ # * <tt>periodicity</tt> - The frequency that the recurring payments will occur at. Can be one of
49
+ # :bimonthly, :monthly, :biweekly, :weekly, :yearly, :daily, :semimonthly, :quadweekly, :quarterly, :semiyearly
50
+ # * <tt>payments</tt> - The term, or number of payments that will be made
51
+ # * <tt>comment</tt> - A comment associated with the profile
52
+ def recurring(money, credit_card, options = {})
53
+ options[:name] = credit_card.name if options[:name].blank? && credit_card
54
+ request = build_recurring_request(options[:profile_id] ? :modify : :add, money, options) do |xml|
55
+ add_credit_card(xml, credit_card) if credit_card
56
+ end
57
+ commit(request, :recurring)
58
+ end
59
+
60
+ def cancel_recurring(profile_id)
61
+ request = build_recurring_request(:cancel, 0, :profile_id => profile_id)
62
+ commit(request, :recurring)
63
+ end
64
+
65
+ def recurring_inquiry(profile_id, options = {})
66
+ request = build_recurring_request(:inquiry, nil, options.update( :profile_id => profile_id ))
67
+ commit(request, :recurring)
68
+ end
69
+
70
+ def express
71
+ @express ||= PayflowExpressGateway.new(@options)
72
+ end
73
+
74
+ private
75
+ def build_sale_or_authorization_request(action, money, credit_card_or_reference, options)
76
+ if credit_card_or_reference.is_a?(String)
77
+ build_reference_sale_or_authorization_request(action, money, credit_card_or_reference, options)
78
+ else
79
+ build_credit_card_request(action, money, credit_card_or_reference, options)
80
+ end
81
+ end
82
+
83
+ def build_reference_sale_or_authorization_request(action, money, reference, options)
84
+ xml = Builder::XmlMarkup.new
85
+ xml.tag! TRANSACTIONS[action] do
86
+ xml.tag! 'PayData' do
87
+ xml.tag! 'Invoice' do
88
+ xml.tag! 'TotalAmt', amount(money), 'Currency' => options[:currency] || currency(money)
89
+ end
90
+ xml.tag! 'Tender' do
91
+ xml.tag! 'Card' do
92
+ xml.tag! 'ExtData', 'Name' => 'ORIGID', 'Value' => reference
93
+ end
94
+ end
95
+ end
96
+ end
97
+ xml.target!
98
+ end
99
+
100
+ def build_credit_card_request(action, money, credit_card, options)
101
+ xml = Builder::XmlMarkup.new
102
+ xml.tag! TRANSACTIONS[action] do
103
+ xml.tag! 'PayData' do
104
+ xml.tag! 'Invoice' do
105
+ xml.tag! 'CustIP', options[:ip] unless options[:ip].blank?
106
+ xml.tag! 'InvNum', options[:order_id].to_s.gsub(/[^\w.]/, '') unless options[:order_id].blank?
107
+ xml.tag! 'Description', options[:description] unless options[:description].blank?
108
+
109
+ billing_address = options[:billing_address] || options[:address]
110
+ add_address(xml, 'BillTo', billing_address, options) if billing_address
111
+ add_address(xml, 'ShipTo', options[:shipping_address], options) if options[:shipping_address]
112
+
113
+ xml.tag! 'TotalAmt', amount(money), 'Currency' => options[:currency] || currency(money)
114
+ end
115
+
116
+ xml.tag! 'Tender' do
117
+ add_credit_card(xml, credit_card)
118
+ end
119
+ end
120
+ end
121
+ xml.target!
122
+ end
123
+
124
+ def add_credit_card(xml, credit_card)
125
+ xml.tag! 'Card' do
126
+ xml.tag! 'CardType', credit_card_type(credit_card)
127
+ xml.tag! 'CardNum', credit_card.number
128
+ xml.tag! 'ExpDate', expdate(credit_card)
129
+ xml.tag! 'NameOnCard', credit_card.first_name
130
+ xml.tag! 'CVNum', credit_card.verification_value if credit_card.verification_value?
131
+
132
+ if requires_start_date_or_issue_number?(credit_card)
133
+ xml.tag!('ExtData', 'Name' => 'CardStart', 'Value' => startdate(credit_card)) unless credit_card.start_month.blank? || credit_card.start_year.blank?
134
+ xml.tag!('ExtData', 'Name' => 'CardIssue', 'Value' => format(credit_card.issue_number, :two_digits)) unless credit_card.issue_number.blank?
135
+ end
136
+ xml.tag! 'ExtData', 'Name' => 'LASTNAME', 'Value' => credit_card.last_name
137
+ end
138
+ end
139
+
140
+ def credit_card_type(credit_card)
141
+ return '' if card_brand(credit_card).blank?
142
+
143
+ CARD_MAPPING[card_brand(credit_card).to_sym]
144
+ end
145
+
146
+ def expdate(creditcard)
147
+ year = sprintf("%.4i", creditcard.year)
148
+ month = sprintf("%.2i", creditcard.month)
149
+
150
+ "#{year}#{month}"
151
+ end
152
+
153
+ def startdate(creditcard)
154
+ year = format(creditcard.start_year, :two_digits)
155
+ month = format(creditcard.start_month, :two_digits)
156
+
157
+ "#{month}#{year}"
158
+ end
159
+
160
+ def build_recurring_request(action, money, options)
161
+ unless RECURRING_ACTIONS.include?(action)
162
+ raise StandardError, "Invalid Recurring Profile Action: #{action}"
163
+ end
164
+
165
+ xml = Builder::XmlMarkup.new
166
+ xml.tag! 'RecurringProfiles' do
167
+ xml.tag! 'RecurringProfile' do
168
+ xml.tag! action.to_s.capitalize do
169
+ unless [:cancel, :inquiry].include?(action)
170
+ xml.tag! 'RPData' do
171
+ xml.tag! 'Name', options[:name] unless options[:name].nil?
172
+ xml.tag! 'TotalAmt', amount(money), 'Currency' => options[:currency] || currency(money)
173
+ xml.tag! 'PayPeriod', get_pay_period(options)
174
+ xml.tag! 'Term', options[:payments] unless options[:payments].nil?
175
+ xml.tag! 'Comment', options[:comment] unless options[:comment].nil?
176
+
177
+
178
+ if initial_tx = options[:initial_transaction]
179
+ requires!(initial_tx, [:type, :authorization, :purchase])
180
+ requires!(initial_tx, :amount) if initial_tx[:type] == :purchase
181
+
182
+ xml.tag! 'OptionalTrans', TRANSACTIONS[initial_tx[:type]]
183
+ xml.tag! 'OptionalTransAmt', amount(initial_tx[:amount]) unless initial_tx[:amount].blank?
184
+ end
185
+
186
+ xml.tag! 'Start', format_rp_date(options[:starting_at] || Date.today + 1 )
187
+ xml.tag! 'EMail', options[:email] unless options[:email].nil?
188
+
189
+ billing_address = options[:billing_address] || options[:address]
190
+ add_address(xml, 'BillTo', billing_address, options) if billing_address
191
+ add_address(xml, 'ShipTo', options[:shipping_address], options) if options[:shipping_address]
192
+ end
193
+ xml.tag! 'Tender' do
194
+ yield xml
195
+ end
196
+ end
197
+ if action != :add
198
+ xml.tag! "ProfileID", options[:profile_id]
199
+ end
200
+ if action == :inquiry
201
+ xml.tag! "PaymentHistory", ( options[:history] ? 'Y' : 'N' )
202
+ end
203
+ end
204
+ end
205
+ end
206
+ end
207
+
208
+ def get_pay_period(options)
209
+ requires!(options, [:periodicity, :bimonthly, :monthly, :biweekly, :weekly, :yearly, :daily, :semimonthly, :quadweekly, :quarterly, :semiyearly])
210
+ case options[:periodicity]
211
+ when :weekly then 'Weekly'
212
+ when :biweekly then 'Bi-weekly'
213
+ when :semimonthly then 'Semi-monthly'
214
+ when :quadweekly then 'Every four weeks'
215
+ when :monthly then 'Monthly'
216
+ when :quarterly then 'Quarterly'
217
+ when :semiyearly then 'Semi-yearly'
218
+ when :yearly then 'Yearly'
219
+ end
220
+ end
221
+
222
+ def format_rp_date(time)
223
+ case time
224
+ when Time, Date then time.strftime("%m%d%Y")
225
+ else
226
+ time.to_s
227
+ end
228
+ end
229
+
230
+ def build_response(success, message, response, options = {})
231
+ PayflowResponse.new(success, message, response, options)
232
+ end
233
+ end
234
+ end
235
+ end
236
+
@@ -0,0 +1,207 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ module PayflowCommonAPI
4
+ def self.included(base)
5
+ base.default_currency = 'USD'
6
+
7
+ base.class_inheritable_accessor :partner
8
+
9
+ # Set the default partner to PayPal
10
+ base.partner = 'PayPal'
11
+
12
+ base.supported_countries = ['US', 'CA', 'SG', 'AU']
13
+
14
+ base.class_inheritable_accessor :timeout
15
+ base.timeout = 60
16
+
17
+ # Enable safe retry of failed connections
18
+ # Payflow is safe to retry because retried transactions use the same
19
+ # X-VPS-Request-ID header. If a transaction is detected as a duplicate
20
+ # only the original transaction data will be used by Payflow, and the
21
+ # subsequent Responses will have a :duplicate parameter set in the params
22
+ # hash.
23
+ base.retry_safe = true
24
+ end
25
+
26
+ XMLNS = 'http://www.paypal.com/XMLPay'
27
+ TEST_URL = 'https://pilot-payflowpro.paypal.com'
28
+ LIVE_URL = 'https://payflowpro.paypal.com'
29
+
30
+ CARD_MAPPING = {
31
+ :visa => 'Visa',
32
+ :master => 'MasterCard',
33
+ :discover => 'Discover',
34
+ :american_express => 'Amex',
35
+ :jcb => 'JCB',
36
+ :diners_club => 'DinersClub',
37
+ :switch => 'Switch',
38
+ :solo => 'Solo'
39
+ }
40
+
41
+ TRANSACTIONS = {
42
+ :purchase => "Sale",
43
+ :authorization => "Authorization",
44
+ :capture => "Capture",
45
+ :void => "Void",
46
+ :credit => "Credit"
47
+ }
48
+
49
+ CVV_CODE = {
50
+ 'Match' => 'M',
51
+ 'No Match' => 'N',
52
+ 'Service Not Available' => 'U',
53
+ 'Service not Requested' => 'P'
54
+ }
55
+
56
+ def initialize(options = {})
57
+ requires!(options, :login, :password)
58
+
59
+ @options = options
60
+ @options[:partner] = partner if @options[:partner].blank?
61
+ super
62
+ end
63
+
64
+ def test?
65
+ @options[:test] || super
66
+ end
67
+
68
+ def capture(money, authorization, options = {})
69
+ request = build_reference_request(:capture, money, authorization, options)
70
+ commit(request)
71
+ end
72
+
73
+ def void(authorization, options = {})
74
+ request = build_reference_request(:void, nil, authorization, options)
75
+ commit(request)
76
+ end
77
+
78
+ private
79
+ def build_request(body, request_type = nil)
80
+ xml = Builder::XmlMarkup.new
81
+ xml.instruct!
82
+ xml.tag! 'XMLPayRequest', 'Timeout' => 30, 'version' => "2.1", "xmlns" => XMLNS do
83
+ xml.tag! 'RequestData' do
84
+ xml.tag! 'Vendor', @options[:login]
85
+ xml.tag! 'Partner', @options[:partner]
86
+ if request_type == :recurring
87
+ xml << body
88
+ else
89
+ xml.tag! 'Transactions' do
90
+ xml.tag! 'Transaction' do
91
+ xml.tag! 'Verbosity', 'MEDIUM'
92
+ xml << body
93
+ end
94
+ end
95
+ end
96
+ end
97
+ xml.tag! 'RequestAuth' do
98
+ xml.tag! 'UserPass' do
99
+ xml.tag! 'User', !@options[:user].blank? ? @options[:user] : @options[:login]
100
+ xml.tag! 'Password', @options[:password]
101
+ end
102
+ end
103
+ end
104
+ xml.target!
105
+ end
106
+
107
+ def build_reference_request(action, money, authorization, options)
108
+ xml = Builder::XmlMarkup.new
109
+ xml.tag! TRANSACTIONS[action] do
110
+ xml.tag! 'PNRef', authorization
111
+
112
+ unless money.nil?
113
+ xml.tag! 'Invoice' do
114
+ xml.tag! 'TotalAmt', amount(money), 'Currency' => options[:currency] || currency(money)
115
+ end
116
+ end
117
+ end
118
+
119
+ xml.target!
120
+ end
121
+
122
+ def add_address(xml, tag, address, options)
123
+ return if address.nil?
124
+ xml.tag! tag do
125
+ xml.tag! 'Name', address[:name] unless address[:name].blank?
126
+ xml.tag! 'EMail', options[:email] unless options[:email].blank?
127
+ xml.tag! 'Phone', address[:phone] unless address[:phone].blank?
128
+ xml.tag! 'CustCode', options[:customer] if !options[:customer].blank? && tag == 'BillTo'
129
+
130
+ xml.tag! 'Address' do
131
+ xml.tag! 'Street', address[:address1] unless address[:address1].blank?
132
+ xml.tag! 'City', address[:city] unless address[:city].blank?
133
+ xml.tag! 'State', address[:state].blank? ? "N/A" : address[:state]
134
+ xml.tag! 'Country', address[:country] unless address[:country].blank?
135
+ xml.tag! 'Zip', address[:zip] unless address[:zip].blank?
136
+ end
137
+ end
138
+ end
139
+
140
+ def parse(data)
141
+ response = {}
142
+ xml = REXML::Document.new(data)
143
+ root = REXML::XPath.first(xml, "//ResponseData")
144
+
145
+ # REXML::XPath in Ruby 1.8.6 is now unable to match nodes based on their attributes
146
+ tx_result = REXML::XPath.first(root, "//TransactionResult")
147
+
148
+ if tx_result && tx_result.attributes['Duplicate'] == "true"
149
+ response[:duplicate] = true
150
+ end
151
+
152
+ root.elements.to_a.each do |node|
153
+ parse_element(response, node)
154
+ end
155
+
156
+ response
157
+ end
158
+
159
+ def parse_element(response, node)
160
+ node_name = node.name.underscore.to_sym
161
+ case
162
+ when node_name == :rp_payment_result
163
+ # Since we'll have multiple history items, we can't just flatten everything
164
+ # down as we do everywhere else. RPPaymentResult elements are not contained
165
+ # in an RPPaymentResults element so we'll come here multiple times
166
+ response[node_name] ||= []
167
+ response[node_name] << ( payment_result_response = {} )
168
+ node.elements.each{ |e| parse_element(payment_result_response, e) }
169
+ when node.has_elements?
170
+ node.elements.each{|e| parse_element(response, e) }
171
+ when node_name.to_s =~ /amt$/
172
+ # *Amt elements don't put the value in the #text - instead they use a Currency attribute
173
+ response[node_name] = node.attributes['Currency']
174
+ when node_name == :ext_data
175
+ response[node.attributes['Name'].underscore.to_sym] = node.attributes['Value']
176
+ else
177
+ response[node_name] = node.text
178
+ end
179
+ end
180
+
181
+ def build_headers(content_length)
182
+ {
183
+ "Content-Type" => "text/xml",
184
+ "Content-Length" => content_length.to_s,
185
+ "X-VPS-Client-Timeout" => timeout.to_s,
186
+ "X-VPS-VIT-Integration-Product" => "ActiveMerchant",
187
+ "X-VPS-VIT-Runtime-Version" => RUBY_VERSION,
188
+ "X-VPS-Request-ID" => Utils.generate_unique_id
189
+ }
190
+ end
191
+
192
+ def commit(request_body, request_type = nil)
193
+ request = build_request(request_body, request_type)
194
+ headers = build_headers(request.size)
195
+
196
+ response = parse(ssl_post(test? ? TEST_URL : LIVE_URL, request, headers))
197
+
198
+ build_response(response[:result] == "0", response[:message], response,
199
+ :test => test?,
200
+ :authorization => response[:pn_ref] || response[:rp_ref],
201
+ :cvv_result => CVV_CODE[response[:cv_result]],
202
+ :avs_result => { :code => response[:avs_result] }
203
+ )
204
+ end
205
+ end
206
+ end
207
+ end