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,201 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ class PayboxDirectGateway < Gateway
4
+ class_attribute :live_url_backup
5
+
6
+ self.test_url = 'https://preprod-ppps.paybox.com/PPPS.php'
7
+ self.live_url = 'https://ppps.paybox.com/PPPS.php'
8
+ self.live_url_backup = 'https://ppps1.paybox.com/PPPS.php'
9
+
10
+ # Payment API Version
11
+ API_VERSION = '00103'
12
+
13
+ # Transactions hash
14
+ TRANSACTIONS = {
15
+ :authorization => '00001',
16
+ :capture => '00002',
17
+ :purchase => '00003',
18
+ :unreferenced_credit => '00004',
19
+ :void => '00005',
20
+ :refund => '00014'
21
+ }
22
+
23
+ CURRENCY_CODES = {
24
+ "AUD"=> '036',
25
+ "CAD"=> '124',
26
+ "CZK"=> '203',
27
+ "DKK"=> '208',
28
+ "HKD"=> '344',
29
+ "ICK"=> '352',
30
+ "JPY"=> '392',
31
+ "NOK"=> '578',
32
+ "SGD"=> '702',
33
+ "SEK"=> '752',
34
+ "CHF"=> '756',
35
+ "GBP"=> '826',
36
+ "USD"=> '840',
37
+ "EUR"=> '978'
38
+ }
39
+
40
+ SUCCESS_CODES = ['00000']
41
+ UNAVAILABILITY_CODES = ['00001', '00097', '00098']
42
+ SUCCESS_MESSAGE = 'The transaction was approved'
43
+ FAILURE_MESSAGE = 'The transaction failed'
44
+
45
+ # Money is referenced in cents
46
+ self.money_format = :cents
47
+ self.default_currency = 'EUR'
48
+
49
+ # The countries the gateway supports merchants from as 2 digit ISO country codes
50
+ self.supported_countries = ['FR']
51
+
52
+ # The card types supported by the payment gateway
53
+ self.supported_cardtypes = [:visa, :master, :american_express, :diners_club, :jcb]
54
+
55
+ # The homepage URL of the gateway
56
+ self.homepage_url = 'http://www.paybox.com/'
57
+
58
+ # The name of the gateway
59
+ self.display_name = 'Paybox Direct'
60
+
61
+ def initialize(options = {})
62
+ requires!(options, :login, :password)
63
+ @options = options
64
+ super
65
+ end
66
+
67
+ def authorize(money, creditcard, options = {})
68
+ post = {}
69
+ add_invoice(post, options)
70
+ add_creditcard(post, creditcard)
71
+ commit('authorization', money, post)
72
+ end
73
+
74
+ def purchase(money, creditcard, options = {})
75
+ post = {}
76
+ add_invoice(post, options)
77
+ add_creditcard(post, creditcard)
78
+ commit('purchase', money, post)
79
+ end
80
+
81
+ def capture(money, authorization, options = {})
82
+ requires!(options, :order_id)
83
+ post = {}
84
+ add_invoice(post, options)
85
+ post[:numappel] = authorization[0,10]
86
+ post[:numtrans] = authorization[10,10]
87
+ commit('capture', money, post)
88
+ end
89
+
90
+ def void(identification, options = {})
91
+ requires!(options, :order_id, :amount)
92
+ post ={}
93
+ add_invoice(post, options)
94
+ add_reference(post, identification)
95
+ post[:porteur] = '000000000000000'
96
+ post[:dateval] = '0000'
97
+ commit('void', options[:amount], post)
98
+ end
99
+
100
+ def credit(money, identification, options = {})
101
+ deprecated CREDIT_DEPRECATION_MESSAGE
102
+ refund(money, identification, options)
103
+ end
104
+
105
+ def refund(money, identification, options = {})
106
+ post = {}
107
+ add_invoice(post, options)
108
+ add_reference(post, identification)
109
+ commit('refund', money, post)
110
+ end
111
+
112
+ def test?
113
+ @options[:test] || Base.gateway_mode == :test
114
+ end
115
+
116
+ private
117
+
118
+ def add_invoice(post, options)
119
+ post[:reference] = options[:order_id]
120
+ end
121
+
122
+ def add_creditcard(post, creditcard)
123
+ post[:porteur] = creditcard.number
124
+ post[:dateval] = expdate(creditcard)
125
+ post[:cvv] = creditcard.verification_value if creditcard.verification_value?
126
+ end
127
+
128
+ def add_reference(post, identification)
129
+ post[:numappel] = identification[0,10]
130
+ post[:numtrans] = identification[10,10]
131
+ end
132
+
133
+ def parse(body)
134
+ results = {}
135
+ body.split(/&/).each do |pair|
136
+ key,val = pair.split(/\=/)
137
+ results[key.downcase.to_sym] = CGI.unescape(val) if val
138
+ end
139
+ results
140
+ end
141
+
142
+ def commit(action, money = nil, parameters = nil)
143
+ parameters[:montant] = ('0000000000' + (money ? amount(money) : ''))[-10..-1]
144
+ parameters[:devise] = CURRENCY_CODES[options[:currency] || currency(money)]
145
+ request_data = post_data(action,parameters)
146
+ response = parse(ssl_post(test? ? self.test_url : self.live_url, request_data))
147
+ response = parse(ssl_post(self.live_url_backup, request_data)) if service_unavailable?(response) && !test?
148
+ Response.new(success?(response), message_from(response), response.merge(
149
+ :timestamp => parameters[:dateq]),
150
+ :test => test?,
151
+ :authorization => response[:numappel].to_s + response[:numtrans].to_s,
152
+ :fraud_review => false,
153
+ :sent_params => parameters.delete_if{|key,value| ['porteur','dateval','cvv'].include?(key.to_s)}
154
+ )
155
+ end
156
+
157
+ def success?(response)
158
+ SUCCESS_CODES.include?(response[:codereponse])
159
+ end
160
+
161
+ def service_unavailable?(response)
162
+ UNAVAILABILITY_CODES.include?(response[:codereponse])
163
+ end
164
+
165
+ def message_from(response)
166
+ success?(response) ? SUCCESS_MESSAGE : (response[:commentaire] || FAILURE_MESSAGE)
167
+ end
168
+
169
+ def post_data(action, parameters = {})
170
+
171
+ parameters.update(
172
+ :version => API_VERSION,
173
+ :type => TRANSACTIONS[action.to_sym],
174
+ :dateq => Time.now.strftime('%d%m%Y%H%M%S'),
175
+ :numquestion => unique_id(parameters[:order_id]),
176
+ :site => @options[:login].to_s[0,7],
177
+ :rang => @options[:login].to_s[7..-1],
178
+ :cle => @options[:password],
179
+ :pays => '',
180
+ :archivage => parameters[:order_id]
181
+ )
182
+
183
+ parameters.collect { |key, value| "#{key.to_s.upcase}=#{CGI.escape(value.to_s)}" }.join("&")
184
+ end
185
+
186
+ def unique_id(seed = 0)
187
+ randkey = "#{seed}#{Time.now.usec}".to_i % 2147483647 # Max paybox value for the question number
188
+
189
+ "0000000000#{randkey}"[-10..-1]
190
+ end
191
+
192
+ def expdate(credit_card)
193
+ year = sprintf("%.4i", credit_card.year)
194
+ month = sprintf("%.2i", credit_card.month)
195
+
196
+ "#{month}#{year[-2..-1]}"
197
+ end
198
+
199
+ end
200
+ end
201
+ end
@@ -0,0 +1,268 @@
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, options)
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, options)
26
+ end
27
+
28
+ def credit(money, identification_or_credit_card, options = {})
29
+ if identification_or_credit_card.is_a?(String)
30
+ deprecated CREDIT_DEPRECATION_MESSAGE
31
+ # Perform referenced credit
32
+ refund(money, identification_or_credit_card, options)
33
+ else
34
+ # Perform non-referenced credit
35
+ request = build_credit_card_request(:credit, money, identification_or_credit_card, options)
36
+ commit(request, options)
37
+ end
38
+ end
39
+
40
+ def refund(money, reference, options = {})
41
+ commit(build_reference_request(:credit, money, reference, options), options)
42
+ end
43
+
44
+ # Adds or modifies a recurring Payflow profile. See the Payflow Pro Recurring Billing Guide for more details:
45
+ # https://www.paypal.com/en_US/pdf/PayflowPro_RecurringBilling_Guide.pdf
46
+ #
47
+ # Several options are available to customize the recurring profile:
48
+ #
49
+ # * <tt>profile_id</tt> - is only required for editing a recurring profile
50
+ # * <tt>starting_at</tt> - takes a Date, Time, or string in mmddyyyy format. The date must be in the future.
51
+ # * <tt>name</tt> - The name of the customer to be billed. If not specified, the name from the credit card is used.
52
+ # * <tt>periodicity</tt> - The frequency that the recurring payments will occur at. Can be one of
53
+ # :bimonthly, :monthly, :biweekly, :weekly, :yearly, :daily, :semimonthly, :quadweekly, :quarterly, :semiyearly
54
+ # * <tt>payments</tt> - The term, or number of payments that will be made
55
+ # * <tt>comment</tt> - A comment associated with the profile
56
+ def recurring(money, credit_card, options = {})
57
+ options[:name] = credit_card.name if options[:name].blank? && credit_card
58
+ request = build_recurring_request(options[:profile_id] ? :modify : :add, money, options) do |xml|
59
+ add_credit_card(xml, credit_card) if credit_card
60
+ end
61
+ commit(request, options.merge(:request_type => :recurring))
62
+ end
63
+
64
+ def cancel_recurring(profile_id)
65
+ request = build_recurring_request(:cancel, 0, :profile_id => profile_id)
66
+ commit(request, options.merge(:request_type => :recurring))
67
+ end
68
+
69
+ def recurring_inquiry(profile_id, options = {})
70
+ request = build_recurring_request(:inquiry, nil, options.update( :profile_id => profile_id ))
71
+ commit(request, options.merge(:request_type => :recurring))
72
+ end
73
+
74
+ def express
75
+ @express ||= PayflowExpressGateway.new(@options)
76
+ end
77
+
78
+ private
79
+ def build_sale_or_authorization_request(action, money, credit_card_or_reference, options)
80
+ if credit_card_or_reference.is_a?(String)
81
+ build_reference_sale_or_authorization_request(action, money, credit_card_or_reference, options)
82
+ else
83
+ build_credit_card_request(action, money, credit_card_or_reference, options)
84
+ end
85
+ end
86
+
87
+ def build_reference_sale_or_authorization_request(action, money, reference, options)
88
+ xml = Builder::XmlMarkup.new
89
+ xml.tag! TRANSACTIONS[action] do
90
+ xml.tag! 'PayData' do
91
+ xml.tag! 'Invoice' do
92
+ # Fields accepted by PayFlow and recommended to be provided even for Reference Transaction, per Payflow docs.
93
+ xml.tag! 'CustIP', options[:ip] unless options[:ip].blank?
94
+ xml.tag! 'InvNum', options[:order_id].to_s.gsub(/[^\w.]/, '') unless options[:order_id].blank?
95
+ xml.tag! 'Description', options[:description] unless options[:description].blank?
96
+ xml.tag! 'Comment', options[:comment] unless options[:comment].blank?
97
+ xml.tag!('ExtData', 'Name'=> 'COMMENT2', 'Value'=> options[:comment2]) unless options[:comment2].blank?
98
+ xml.tag! 'TaxAmt', options[:taxamt] unless options[:taxamt].blank?
99
+ xml.tag! 'FreightAmt', options[:freightamt] unless options[:freightamt].blank?
100
+ xml.tag! 'DutyAmt', options[:dutyamt] unless options[:dutyamt].blank?
101
+ xml.tag! 'DiscountAmt', options[:discountamt] unless options[:discountamt].blank?
102
+
103
+ billing_address = options[:billing_address] || options[:address]
104
+ add_address(xml, 'BillTo', billing_address, options) if billing_address
105
+ add_address(xml, 'ShipTo', options[:shipping_address],options) if options[:shipping_address]
106
+
107
+ xml.tag! 'TotalAmt', amount(money), 'Currency' => options[:currency] || currency(money)
108
+ end
109
+ xml.tag! 'Tender' do
110
+ xml.tag! 'Card' do
111
+ xml.tag! 'ExtData', 'Name' => 'ORIGID', 'Value' => reference
112
+ end
113
+ end
114
+ end
115
+ end
116
+ xml.target!
117
+ end
118
+
119
+ def build_credit_card_request(action, money, credit_card, options)
120
+ xml = Builder::XmlMarkup.new
121
+ xml.tag! TRANSACTIONS[action] do
122
+ xml.tag! 'PayData' do
123
+ xml.tag! 'Invoice' do
124
+ xml.tag! 'CustIP', options[:ip] unless options[:ip].blank?
125
+ xml.tag! 'InvNum', options[:order_id].to_s.gsub(/[^\w.]/, '') unless options[:order_id].blank?
126
+ xml.tag! 'Description', options[:description] unless options[:description].blank?
127
+ # Comment and Comment2 will show up in manager.paypal.com as Comment1 and Comment2
128
+ xml.tag! 'Comment', options[:comment] unless options[:comment].blank?
129
+ xml.tag!('ExtData', 'Name'=> 'COMMENT2', 'Value'=> options[:comment2]) unless options[:comment2].blank?
130
+ xml.tag! 'TaxAmt', options[:taxamt] unless options[:taxamt].blank?
131
+ xml.tag! 'FreightAmt', options[:freightamt] unless options[:freightamt].blank?
132
+ xml.tag! 'DutyAmt', options[:dutyamt] unless options[:dutyamt].blank?
133
+ xml.tag! 'DiscountAmt', options[:discountamt] unless options[:discountamt].blank?
134
+
135
+ billing_address = options[:billing_address] || options[:address]
136
+ add_address(xml, 'BillTo', billing_address, options) if billing_address
137
+ add_address(xml, 'ShipTo', options[:shipping_address], options) if options[:shipping_address]
138
+
139
+ xml.tag! 'TotalAmt', amount(money), 'Currency' => options[:currency] || currency(money)
140
+ end
141
+
142
+ xml.tag! 'Tender' do
143
+ add_credit_card(xml, credit_card)
144
+ end
145
+ end
146
+ end
147
+ xml.target!
148
+ end
149
+
150
+ def add_credit_card(xml, credit_card)
151
+ xml.tag! 'Card' do
152
+ xml.tag! 'CardType', credit_card_type(credit_card)
153
+ xml.tag! 'CardNum', credit_card.number
154
+ xml.tag! 'ExpDate', expdate(credit_card)
155
+ xml.tag! 'NameOnCard', credit_card.first_name
156
+ xml.tag! 'CVNum', credit_card.verification_value if credit_card.verification_value?
157
+
158
+ if requires_start_date_or_issue_number?(credit_card)
159
+ xml.tag!('ExtData', 'Name' => 'CardStart', 'Value' => startdate(credit_card)) unless credit_card.start_month.blank? || credit_card.start_year.blank?
160
+ xml.tag!('ExtData', 'Name' => 'CardIssue', 'Value' => format(credit_card.issue_number, :two_digits)) unless credit_card.issue_number.blank?
161
+ end
162
+ xml.tag! 'ExtData', 'Name' => 'LASTNAME', 'Value' => credit_card.last_name
163
+ end
164
+ end
165
+
166
+ def credit_card_type(credit_card)
167
+ return '' if card_brand(credit_card).blank?
168
+
169
+ CARD_MAPPING[card_brand(credit_card).to_sym]
170
+ end
171
+
172
+ def expdate(creditcard)
173
+ year = sprintf("%.4i", creditcard.year.to_s.sub(/^0+/, ''))
174
+ month = sprintf("%.2i", creditcard.month.to_s.sub(/^0+/, ''))
175
+
176
+ "#{year}#{month}"
177
+ end
178
+
179
+ def startdate(creditcard)
180
+ year = format(creditcard.start_year, :two_digits)
181
+ month = format(creditcard.start_month, :two_digits)
182
+
183
+ "#{month}#{year}"
184
+ end
185
+
186
+ def build_recurring_request(action, money, options)
187
+ unless RECURRING_ACTIONS.include?(action)
188
+ raise StandardError, "Invalid Recurring Profile Action: #{action}"
189
+ end
190
+
191
+ xml = Builder::XmlMarkup.new
192
+ xml.tag! 'RecurringProfiles' do
193
+ xml.tag! 'RecurringProfile' do
194
+ xml.tag! action.to_s.capitalize do
195
+ unless [:cancel, :inquiry].include?(action)
196
+ xml.tag! 'RPData' do
197
+ xml.tag! 'Name', options[:name] unless options[:name].nil?
198
+ xml.tag! 'TotalAmt', amount(money), 'Currency' => options[:currency] || currency(money)
199
+ xml.tag! 'PayPeriod', get_pay_period(options)
200
+ xml.tag! 'Term', options[:payments] unless options[:payments].nil?
201
+ xml.tag! 'Comment', options[:comment] unless options[:comment].nil?
202
+ xml.tag! 'RetryNumDays', options[:retry_num_days] unless options[:retry_num_days].nil?
203
+ xml.tag! 'MaxFailPayments', options[:max_fail_payments] unless options[:max_fail_payments].nil?
204
+
205
+ if initial_tx = options[:initial_transaction]
206
+ requires!(initial_tx, [:type, :authorization, :purchase])
207
+ requires!(initial_tx, :amount) if initial_tx[:type] == :purchase
208
+
209
+ xml.tag! 'OptionalTrans', TRANSACTIONS[initial_tx[:type]]
210
+ xml.tag! 'OptionalTransAmt', amount(initial_tx[:amount]) unless initial_tx[:amount].blank?
211
+ end
212
+
213
+ if action == :add
214
+ xml.tag! 'Start', format_rp_date(options[:starting_at] || Date.today + 1 )
215
+ else
216
+ xml.tag! 'Start', format_rp_date(options[:starting_at]) unless options[:starting_at].nil?
217
+ end
218
+
219
+ xml.tag! 'EMail', options[:email] unless options[:email].nil?
220
+
221
+ billing_address = options[:billing_address] || options[:address]
222
+ add_address(xml, 'BillTo', billing_address, options) if billing_address
223
+ add_address(xml, 'ShipTo', options[:shipping_address], options) if options[:shipping_address]
224
+ end
225
+ xml.tag! 'Tender' do
226
+ yield xml
227
+ end
228
+ end
229
+ if action != :add
230
+ xml.tag! "ProfileID", options[:profile_id]
231
+ end
232
+ if action == :inquiry
233
+ xml.tag! "PaymentHistory", ( options[:history] ? 'Y' : 'N' )
234
+ end
235
+ end
236
+ end
237
+ end
238
+ end
239
+
240
+ def get_pay_period(options)
241
+ requires!(options, [:periodicity, :bimonthly, :monthly, :biweekly, :weekly, :yearly, :daily, :semimonthly, :quadweekly, :quarterly, :semiyearly])
242
+ case options[:periodicity]
243
+ when :weekly then 'Weekly'
244
+ when :biweekly then 'Bi-weekly'
245
+ when :semimonthly then 'Semi-monthly'
246
+ when :quadweekly then 'Every four weeks'
247
+ when :monthly then 'Monthly'
248
+ when :quarterly then 'Quarterly'
249
+ when :semiyearly then 'Semi-yearly'
250
+ when :yearly then 'Yearly'
251
+ end
252
+ end
253
+
254
+ def format_rp_date(time)
255
+ case time
256
+ when Time, Date then time.strftime("%m%d%Y")
257
+ else
258
+ time.to_s
259
+ end
260
+ end
261
+
262
+ def build_response(success, message, response, options = {})
263
+ PayflowResponse.new(success, message, response, options)
264
+ end
265
+ end
266
+ end
267
+ end
268
+