jelaniharris-activemerchant 1.24.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (219) hide show
  1. data/CHANGELOG +893 -0
  2. data/CONTRIBUTORS +307 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.md +196 -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 +57 -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 +170 -0
  17. data/lib/active_merchant/billing/gateways.rb +18 -0
  18. data/lib/active_merchant/billing/gateways/authorize_net.rb +694 -0
  19. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +946 -0
  20. data/lib/active_merchant/billing/gateways/barclays_epdq.rb +308 -0
  21. data/lib/active_merchant/billing/gateways/beanstream.rb +167 -0
  22. data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +388 -0
  23. data/lib/active_merchant/billing/gateways/beanstream_interac.rb +54 -0
  24. data/lib/active_merchant/billing/gateways/blue_pay.rb +492 -0
  25. data/lib/active_merchant/billing/gateways/bogus.rb +142 -0
  26. data/lib/active_merchant/billing/gateways/braintree.rb +17 -0
  27. data/lib/active_merchant/billing/gateways/braintree/braintree_common.rb +9 -0
  28. data/lib/active_merchant/billing/gateways/braintree_blue.rb +335 -0
  29. data/lib/active_merchant/billing/gateways/braintree_orange.rb +21 -0
  30. data/lib/active_merchant/billing/gateways/card_save.rb +23 -0
  31. data/lib/active_merchant/billing/gateways/card_stream.rb +230 -0
  32. data/lib/active_merchant/billing/gateways/certo_direct.rb +279 -0
  33. data/lib/active_merchant/billing/gateways/cyber_source.rb +430 -0
  34. data/lib/active_merchant/billing/gateways/data_cash.rb +597 -0
  35. data/lib/active_merchant/billing/gateways/efsnet.rb +235 -0
  36. data/lib/active_merchant/billing/gateways/elavon.rb +137 -0
  37. data/lib/active_merchant/billing/gateways/epay.rb +276 -0
  38. data/lib/active_merchant/billing/gateways/eway.rb +277 -0
  39. data/lib/active_merchant/billing/gateways/eway_managed.rb +265 -0
  40. data/lib/active_merchant/billing/gateways/exact.rb +227 -0
  41. data/lib/active_merchant/billing/gateways/federated_canada.rb +168 -0
  42. data/lib/active_merchant/billing/gateways/first_pay.rb +177 -0
  43. data/lib/active_merchant/billing/gateways/garanti.rb +262 -0
  44. data/lib/active_merchant/billing/gateways/ideal/ideal_base.rb +250 -0
  45. data/lib/active_merchant/billing/gateways/ideal/ideal_rabobank.pem +13 -0
  46. data/lib/active_merchant/billing/gateways/ideal/ideal_response.rb +29 -0
  47. data/lib/active_merchant/billing/gateways/ideal_rabobank.rb +55 -0
  48. data/lib/active_merchant/billing/gateways/inspire.rb +221 -0
  49. data/lib/active_merchant/billing/gateways/instapay.rb +164 -0
  50. data/lib/active_merchant/billing/gateways/iridium.rb +258 -0
  51. data/lib/active_merchant/billing/gateways/itransact.rb +450 -0
  52. data/lib/active_merchant/billing/gateways/jetpay.rb +276 -0
  53. data/lib/active_merchant/billing/gateways/linkpoint.rb +454 -0
  54. data/lib/active_merchant/billing/gateways/litle.rb +275 -0
  55. data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +157 -0
  56. data/lib/active_merchant/billing/gateways/merchant_ware.rb +289 -0
  57. data/lib/active_merchant/billing/gateways/migs.rb +259 -0
  58. data/lib/active_merchant/billing/gateways/migs/migs_codes.rb +100 -0
  59. data/lib/active_merchant/billing/gateways/modern_payments.rb +36 -0
  60. data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +220 -0
  61. data/lib/active_merchant/billing/gateways/moneris.rb +250 -0
  62. data/lib/active_merchant/billing/gateways/moneris_us.rb +211 -0
  63. data/lib/active_merchant/billing/gateways/nab_transact.rb +255 -0
  64. data/lib/active_merchant/billing/gateways/net_registry.rb +189 -0
  65. data/lib/active_merchant/billing/gateways/netaxept.rb +239 -0
  66. data/lib/active_merchant/billing/gateways/netbilling.rb +168 -0
  67. data/lib/active_merchant/billing/gateways/nmi.rb +13 -0
  68. data/lib/active_merchant/billing/gateways/ogone.rb +422 -0
  69. data/lib/active_merchant/billing/gateways/optimal_payment.rb +277 -0
  70. data/lib/active_merchant/billing/gateways/orbital.rb +353 -0
  71. data/lib/active_merchant/billing/gateways/orbital/orbital_soft_descriptors.rb +46 -0
  72. data/lib/active_merchant/billing/gateways/pay_junction.rb +397 -0
  73. data/lib/active_merchant/billing/gateways/pay_secure.rb +120 -0
  74. data/lib/active_merchant/billing/gateways/paybox_direct.rb +199 -0
  75. data/lib/active_merchant/billing/gateways/payflow.rb +266 -0
  76. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +211 -0
  77. data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +39 -0
  78. data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +13 -0
  79. data/lib/active_merchant/billing/gateways/payflow_express.rb +224 -0
  80. data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +15 -0
  81. data/lib/active_merchant/billing/gateways/payflow_uk.rb +21 -0
  82. data/lib/active_merchant/billing/gateways/payment_express.rb +282 -0
  83. data/lib/active_merchant/billing/gateways/paypal.rb +106 -0
  84. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +640 -0
  85. data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +49 -0
  86. data/lib/active_merchant/billing/gateways/paypal/paypal_recurring_api.rb +245 -0
  87. data/lib/active_merchant/billing/gateways/paypal_ca.rb +13 -0
  88. data/lib/active_merchant/billing/gateways/paypal_digital_goods.rb +43 -0
  89. data/lib/active_merchant/billing/gateways/paypal_express.rb +178 -0
  90. data/lib/active_merchant/billing/gateways/paypal_express_common.rb +30 -0
  91. data/lib/active_merchant/billing/gateways/paystation.rb +201 -0
  92. data/lib/active_merchant/billing/gateways/plugnpay.rb +298 -0
  93. data/lib/active_merchant/billing/gateways/psigate.rb +219 -0
  94. data/lib/active_merchant/billing/gateways/psl_card.rb +304 -0
  95. data/lib/active_merchant/billing/gateways/qbms.rb +297 -0
  96. data/lib/active_merchant/billing/gateways/quantum.rb +282 -0
  97. data/lib/active_merchant/billing/gateways/quickpay.rb +298 -0
  98. data/lib/active_merchant/billing/gateways/realex.rb +313 -0
  99. data/lib/active_merchant/billing/gateways/sage.rb +146 -0
  100. data/lib/active_merchant/billing/gateways/sage/sage_bankcard.rb +88 -0
  101. data/lib/active_merchant/billing/gateways/sage/sage_core.rb +116 -0
  102. data/lib/active_merchant/billing/gateways/sage/sage_virtual_check.rb +97 -0
  103. data/lib/active_merchant/billing/gateways/sage_pay.rb +320 -0
  104. data/lib/active_merchant/billing/gateways/sallie_mae.rb +144 -0
  105. data/lib/active_merchant/billing/gateways/samurai.rb +121 -0
  106. data/lib/active_merchant/billing/gateways/secure_net.rb +330 -0
  107. data/lib/active_merchant/billing/gateways/secure_pay.rb +31 -0
  108. data/lib/active_merchant/billing/gateways/secure_pay_au.rb +281 -0
  109. data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +113 -0
  110. data/lib/active_merchant/billing/gateways/skip_jack.rb +458 -0
  111. data/lib/active_merchant/billing/gateways/smart_ps.rb +271 -0
  112. data/lib/active_merchant/billing/gateways/stripe.rb +236 -0
  113. data/lib/active_merchant/billing/gateways/trans_first.rb +127 -0
  114. data/lib/active_merchant/billing/gateways/transax.rb +25 -0
  115. data/lib/active_merchant/billing/gateways/trust_commerce.rb +437 -0
  116. data/lib/active_merchant/billing/gateways/usa_epay.rb +23 -0
  117. data/lib/active_merchant/billing/gateways/usa_epay_advanced.rb +1496 -0
  118. data/lib/active_merchant/billing/gateways/usa_epay_transaction.rb +202 -0
  119. data/lib/active_merchant/billing/gateways/verifi.rb +233 -0
  120. data/lib/active_merchant/billing/gateways/viaklix.rb +194 -0
  121. data/lib/active_merchant/billing/gateways/vindicia.rb +359 -0
  122. data/lib/active_merchant/billing/gateways/wirecard.rb +318 -0
  123. data/lib/active_merchant/billing/gateways/worldpay.rb +280 -0
  124. data/lib/active_merchant/billing/integrations.rb +17 -0
  125. data/lib/active_merchant/billing/integrations/action_view_helper.rb +72 -0
  126. data/lib/active_merchant/billing/integrations/authorize_net_sim.rb +38 -0
  127. data/lib/active_merchant/billing/integrations/authorize_net_sim/helper.rb +228 -0
  128. data/lib/active_merchant/billing/integrations/authorize_net_sim/notification.rb +340 -0
  129. data/lib/active_merchant/billing/integrations/bogus.rb +23 -0
  130. data/lib/active_merchant/billing/integrations/bogus/helper.rb +17 -0
  131. data/lib/active_merchant/billing/integrations/bogus/notification.rb +11 -0
  132. data/lib/active_merchant/billing/integrations/bogus/return.rb +10 -0
  133. data/lib/active_merchant/billing/integrations/chronopay.rb +23 -0
  134. data/lib/active_merchant/billing/integrations/chronopay/helper.rb +120 -0
  135. data/lib/active_merchant/billing/integrations/chronopay/notification.rb +158 -0
  136. data/lib/active_merchant/billing/integrations/chronopay/return.rb +10 -0
  137. data/lib/active_merchant/billing/integrations/direc_pay.rb +41 -0
  138. data/lib/active_merchant/billing/integrations/direc_pay/helper.rb +200 -0
  139. data/lib/active_merchant/billing/integrations/direc_pay/notification.rb +76 -0
  140. data/lib/active_merchant/billing/integrations/direc_pay/return.rb +32 -0
  141. data/lib/active_merchant/billing/integrations/direc_pay/status.rb +37 -0
  142. data/lib/active_merchant/billing/integrations/directebanking.rb +47 -0
  143. data/lib/active_merchant/billing/integrations/directebanking/helper.rb +90 -0
  144. data/lib/active_merchant/billing/integrations/directebanking/notification.rb +120 -0
  145. data/lib/active_merchant/billing/integrations/directebanking/return.rb +11 -0
  146. data/lib/active_merchant/billing/integrations/dotpay.rb +22 -0
  147. data/lib/active_merchant/billing/integrations/dotpay/helper.rb +77 -0
  148. data/lib/active_merchant/billing/integrations/dotpay/notification.rb +86 -0
  149. data/lib/active_merchant/billing/integrations/dotpay/return.rb +11 -0
  150. data/lib/active_merchant/billing/integrations/dwolla.rb +30 -0
  151. data/lib/active_merchant/billing/integrations/dwolla/helper.rb +31 -0
  152. data/lib/active_merchant/billing/integrations/dwolla/notification.rb +55 -0
  153. data/lib/active_merchant/billing/integrations/dwolla/return.rb +38 -0
  154. data/lib/active_merchant/billing/integrations/e_payment_plans.rb +48 -0
  155. data/lib/active_merchant/billing/integrations/e_payment_plans/helper.rb +34 -0
  156. data/lib/active_merchant/billing/integrations/e_payment_plans/notification.rb +84 -0
  157. data/lib/active_merchant/billing/integrations/epay.rb +21 -0
  158. data/lib/active_merchant/billing/integrations/epay/helper.rb +55 -0
  159. data/lib/active_merchant/billing/integrations/epay/notification.rb +110 -0
  160. data/lib/active_merchant/billing/integrations/gestpay.rb +25 -0
  161. data/lib/active_merchant/billing/integrations/gestpay/common.rb +42 -0
  162. data/lib/active_merchant/billing/integrations/gestpay/helper.rb +70 -0
  163. data/lib/active_merchant/billing/integrations/gestpay/notification.rb +85 -0
  164. data/lib/active_merchant/billing/integrations/gestpay/return.rb +10 -0
  165. data/lib/active_merchant/billing/integrations/helper.rb +113 -0
  166. data/lib/active_merchant/billing/integrations/hi_trust.rb +27 -0
  167. data/lib/active_merchant/billing/integrations/hi_trust/helper.rb +58 -0
  168. data/lib/active_merchant/billing/integrations/hi_trust/notification.rb +59 -0
  169. data/lib/active_merchant/billing/integrations/hi_trust/return.rb +67 -0
  170. data/lib/active_merchant/billing/integrations/moneybookers.rb +26 -0
  171. data/lib/active_merchant/billing/integrations/moneybookers/helper.rb +59 -0
  172. data/lib/active_merchant/billing/integrations/moneybookers/notification.rb +129 -0
  173. data/lib/active_merchant/billing/integrations/nochex.rb +88 -0
  174. data/lib/active_merchant/billing/integrations/nochex/helper.rb +68 -0
  175. data/lib/active_merchant/billing/integrations/nochex/notification.rb +94 -0
  176. data/lib/active_merchant/billing/integrations/nochex/return.rb +10 -0
  177. data/lib/active_merchant/billing/integrations/notification.rb +62 -0
  178. data/lib/active_merchant/billing/integrations/payflow_link.rb +21 -0
  179. data/lib/active_merchant/billing/integrations/payflow_link/helper.rb +100 -0
  180. data/lib/active_merchant/billing/integrations/payflow_link/notification.rb +78 -0
  181. data/lib/active_merchant/billing/integrations/paypal.rb +39 -0
  182. data/lib/active_merchant/billing/integrations/paypal/helper.rb +119 -0
  183. data/lib/active_merchant/billing/integrations/paypal/notification.rb +155 -0
  184. data/lib/active_merchant/billing/integrations/paypal/return.rb +10 -0
  185. data/lib/active_merchant/billing/integrations/quickpay.rb +21 -0
  186. data/lib/active_merchant/billing/integrations/quickpay/helper.rb +71 -0
  187. data/lib/active_merchant/billing/integrations/quickpay/notification.rb +74 -0
  188. data/lib/active_merchant/billing/integrations/return.rb +42 -0
  189. data/lib/active_merchant/billing/integrations/robokassa.rb +49 -0
  190. data/lib/active_merchant/billing/integrations/robokassa/common.rb +19 -0
  191. data/lib/active_merchant/billing/integrations/robokassa/helper.rb +50 -0
  192. data/lib/active_merchant/billing/integrations/robokassa/notification.rb +55 -0
  193. data/lib/active_merchant/billing/integrations/robokassa/return.rb +17 -0
  194. data/lib/active_merchant/billing/integrations/sage_pay_form.rb +37 -0
  195. data/lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb +33 -0
  196. data/lib/active_merchant/billing/integrations/sage_pay_form/helper.rb +129 -0
  197. data/lib/active_merchant/billing/integrations/sage_pay_form/notification.rb +210 -0
  198. data/lib/active_merchant/billing/integrations/sage_pay_form/return.rb +31 -0
  199. data/lib/active_merchant/billing/integrations/two_checkout.rb +44 -0
  200. data/lib/active_merchant/billing/integrations/two_checkout/helper.rb +91 -0
  201. data/lib/active_merchant/billing/integrations/two_checkout/notification.rb +139 -0
  202. data/lib/active_merchant/billing/integrations/two_checkout/return.rb +17 -0
  203. data/lib/active_merchant/billing/integrations/valitor.rb +33 -0
  204. data/lib/active_merchant/billing/integrations/valitor/helper.rb +86 -0
  205. data/lib/active_merchant/billing/integrations/valitor/notification.rb +13 -0
  206. data/lib/active_merchant/billing/integrations/valitor/response_fields.rb +97 -0
  207. data/lib/active_merchant/billing/integrations/valitor/return.rb +13 -0
  208. data/lib/active_merchant/billing/integrations/verkkomaksut.rb +20 -0
  209. data/lib/active_merchant/billing/integrations/verkkomaksut/helper.rb +87 -0
  210. data/lib/active_merchant/billing/integrations/verkkomaksut/notification.rb +59 -0
  211. data/lib/active_merchant/billing/integrations/world_pay.rb +27 -0
  212. data/lib/active_merchant/billing/integrations/world_pay/helper.rb +100 -0
  213. data/lib/active_merchant/billing/integrations/world_pay/notification.rb +160 -0
  214. data/lib/active_merchant/billing/response.rb +32 -0
  215. data/lib/active_merchant/version.rb +3 -0
  216. data/lib/activemerchant.rb +1 -0
  217. data/lib/support/gateway_support.rb +58 -0
  218. data/lib/support/outbound_hosts.rb +25 -0
  219. metadata +447 -0
@@ -0,0 +1,30 @@
1
+ module ActiveMerchant
2
+ module Billing
3
+ module PaypalExpressCommon
4
+ def self.included(base)
5
+ if base.respond_to?(:class_attribute)
6
+ base.class_attribute :test_redirect_url
7
+ base.class_attribute :live_redirect_url
8
+ else
9
+ base.class_inheritable_accessor :test_redirect_url
10
+ base.class_inheritable_accessor :live_redirect_url
11
+ end
12
+ base.live_redirect_url = 'https://www.paypal.com/cgibin/webscr'
13
+ end
14
+
15
+ def redirect_url
16
+ test? ? test_redirect_url : live_redirect_url
17
+ end
18
+
19
+ def redirect_url_for(token, options = {})
20
+ options = {:review => true, :mobile => false}.update(options)
21
+
22
+ cmd = options[:mobile] ? '_express-checkout-mobile' : '_express-checkout'
23
+ url = "#{redirect_url}?cmd=#{cmd}&token=#{token}"
24
+ url += '&useraction=commit' unless options[:review]
25
+
26
+ url
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,201 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ class PaystationGateway < Gateway
4
+
5
+ URL = "https://www.paystation.co.nz/direct/paystation.dll"
6
+
7
+ # an "error code" of "0" means "No error - transaction successful"
8
+ SUCCESSFUL_RESPONSE_CODE = '0'
9
+
10
+ # an "error code" of "34" means "Future Payment Stored OK"
11
+ SUCCESSFUL_FUTURE_PAYMENT = '34'
12
+
13
+ # TODO: check this with paystation
14
+ self.supported_countries = ['NZ']
15
+
16
+ # TODO: check this with paystation (amex and diners need to be enabled)
17
+ self.supported_cardtypes = [:visa, :master, :american_express, :diners_club ]
18
+
19
+ self.homepage_url = 'http://paystation.co.nz'
20
+ self.display_name = 'Paystation'
21
+
22
+ self.default_currency = 'NZD'
23
+ self.money_format = :cents
24
+
25
+ def initialize(options = {})
26
+ # You need to pass your Paystation ID and Gateway ID
27
+ requires!(options, :paystation_id, :gateway_id)
28
+ @options = options
29
+ super
30
+ end
31
+
32
+ def authorize(money, credit_card, options = {})
33
+ post = new_request
34
+
35
+ add_invoice(post, options)
36
+ add_amount(post, money, options)
37
+
38
+ add_credit_card(post, credit_card)
39
+
40
+ add_authorize_flag(post, options)
41
+
42
+ commit(post)
43
+ end
44
+
45
+ def capture(money, authorization_token, options = {})
46
+ post = new_request
47
+
48
+ add_invoice(post, options)
49
+ add_amount(post, money, options)
50
+
51
+ add_authorization_token(post, authorization_token, options[:credit_card_verification])
52
+
53
+ commit(post)
54
+ end
55
+
56
+ def purchase(money, payment_source, options = {})
57
+ post = new_request
58
+
59
+ add_invoice(post, options)
60
+ add_amount(post, money, options)
61
+
62
+ if payment_source.is_a?(String)
63
+ add_token(post, payment_source)
64
+ else
65
+ add_credit_card(post, payment_source)
66
+ end
67
+
68
+ add_customer_data(post, options) if options.has_key?(:customer)
69
+
70
+ commit(post)
71
+ end
72
+
73
+ def store(credit_card, options = {})
74
+ post = new_request
75
+
76
+ add_invoice(post, options)
77
+ add_credit_card(post, credit_card)
78
+ store_credit_card(post, options)
79
+
80
+ commit(post)
81
+ end
82
+
83
+ private
84
+
85
+ def new_request
86
+ {
87
+ :pi => @options[:paystation_id], # paystation account id
88
+ :gi => @options[:gateway_id], # paystation gateway id
89
+ "2p" => "t", # two-party transaction type
90
+ :nr => "t", # -- redirect??
91
+ :df => "yymm" # date format: optional sometimes, required others
92
+ }
93
+ end
94
+
95
+ def add_customer_data(post, options)
96
+ post[:mc] = options[:customer]
97
+ end
98
+
99
+ def add_invoice(post, options)
100
+ requires!(options, :order_id)
101
+
102
+ post[:ms] = options[:order_id] # "Merchant Session", must be unique per request
103
+ post[:mo] = options[:invoice] # "Order Details", displayed in Paystation Admin
104
+ post[:mr] = options[:description] # "Merchant Reference Code", seen from Paystation Admin
105
+ end
106
+
107
+ def add_credit_card(post, credit_card)
108
+
109
+ post[:cn] = credit_card.number
110
+ post[:ct] = credit_card.brand
111
+ post[:ex] = format_date(credit_card.month, credit_card.year)
112
+ post[:cc] = credit_card.verification_value if credit_card.verification_value?
113
+
114
+ end
115
+
116
+ # bill a token (stored via "store") rather than a Credit Card
117
+ def add_token(post, token)
118
+ post[:fp] = "t" # turn on "future payments" - what paystation calls Token Billing
119
+ post[:ft] = token
120
+ end
121
+
122
+ def store_credit_card(post, options)
123
+
124
+ post[:fp] = "t" # turn on "future payments" - what paystation calls Token Billing
125
+ post[:fs] = "t" # tells paystation to store right now, not bill
126
+ post[:ft] = options[:token] if options[:token] # specify a token to use that, or let Paystation generate one
127
+
128
+ end
129
+
130
+ def add_authorize_flag(post, options)
131
+ post[:pa] = "t" # tells Paystation that this is a pre-auth authorisation payment (account must be in pre-auth mode)
132
+ end
133
+
134
+ def add_authorization_token(post, auth_token, verification_value = nil)
135
+ post[:cp] = "t" # Capture Payment flag – tells Paystation this transaction should be treated as a capture payment
136
+ post[:cx] = auth_token
137
+ post[:cc] = verification_value
138
+ end
139
+
140
+ def add_amount(post, money, options)
141
+
142
+ post[:am] = amount(money)
143
+ post[:cu] = options[:currency] || currency(money)
144
+
145
+ end
146
+
147
+ def parse(xml_response)
148
+ response = {}
149
+
150
+ xml = REXML::Document.new(xml_response)
151
+
152
+ # for normal payments, the root node is <Response>
153
+ # for "future payments", it's <PaystationFuturePaymentResponse>
154
+ xml.elements.each("#{xml.root.name}/*") do |element|
155
+ response[element.name.underscore.to_sym] = element.text
156
+ end
157
+
158
+ response
159
+ end
160
+
161
+ def commit(post)
162
+
163
+ post[:tm] = "T" if test? # test mode
164
+
165
+ pstn_prefix_params = post.collect { |key, value| "pstn_#{key}=#{CGI.escape(value.to_s)}" }.join("&")
166
+
167
+ # need include paystation param as "initiator flag for payment engine"
168
+ data = ssl_post(URL, "#{pstn_prefix_params}&paystation=_empty")
169
+ response = parse(data)
170
+ message = message_from(response)
171
+
172
+ PaystationResponse.new(success?(response), message, response,
173
+ :test => (response[:tm] && response[:tm].downcase == "t"),
174
+ :authorization => response[:paystation_transaction_id]
175
+ )
176
+ end
177
+
178
+ def success?(response)
179
+ (response[:ec] == SUCCESSFUL_RESPONSE_CODE) || (response[:ec] == SUCCESSFUL_FUTURE_PAYMENT)
180
+ end
181
+
182
+ def message_from(response)
183
+ response[:em]
184
+ end
185
+
186
+ def format_date(month, year)
187
+ "#{format(year, :two_digits)}#{format(month, :two_digits)}"
188
+ end
189
+
190
+ end
191
+
192
+ class PaystationResponse < Response
193
+ # add a method to response so we can easily get the token
194
+ # for Validate transactions
195
+ def token
196
+ @params["future_payment_token"]
197
+ end
198
+ end
199
+ end
200
+ end
201
+
@@ -0,0 +1,298 @@
1
+ module ActiveMerchant
2
+ module Billing
3
+
4
+ class PlugnpayGateway < Gateway
5
+ class PlugnpayPostData < PostData
6
+ # Fields that will be sent even if they are blank
7
+ self.required_fields = [ :publisher_name, :publisher_password,
8
+ :card_amount, :card_name, :card_number, :card_exp, :orderID ]
9
+ end
10
+
11
+ URL = 'https://pay1.plugnpay.com/payment/pnpremote.cgi'
12
+
13
+ CARD_CODE_MESSAGES = {
14
+ "M" => "Card verification number matched",
15
+ "N" => "Card verification number didn't match",
16
+ "P" => "Card verification number was not processed",
17
+ "S" => "Card verification number should be on card but was not indicated",
18
+ "U" => "Issuer was not certified for card verification"
19
+ }
20
+
21
+ CARD_CODE_ERRORS = %w( N S )
22
+
23
+ AVS_MESSAGES = {
24
+ "A" => "Street address matches billing information, zip/postal code does not",
25
+ "B" => "Address information not provided for address verification check",
26
+ "E" => "Address verification service error",
27
+ "G" => "Non-U.S. card-issuing bank",
28
+ "N" => "Neither street address nor zip/postal match billing information",
29
+ "P" => "Address verification not applicable for this transaction",
30
+ "R" => "Payment gateway was unavailable or timed out",
31
+ "S" => "Address verification service not supported by issuer",
32
+ "U" => "Address information is unavailable",
33
+ "W" => "9-digit zip/postal code matches billing information, street address does not",
34
+ "X" => "Street address and 9-digit zip/postal code matches billing information",
35
+ "Y" => "Street address and 5-digit zip/postal code matches billing information",
36
+ "Z" => "5-digit zip/postal code matches billing information, street address does not",
37
+ }
38
+
39
+ AVS_ERRORS = %w( A E N R W Z )
40
+
41
+ PAYMENT_GATEWAY_RESPONSES = {
42
+ "P01" => "AVS Mismatch Failure",
43
+ "P02" => "CVV2 Mismatch Failure",
44
+ "P21" => "Transaction may not be marked",
45
+ "P30" => "Test Tran. Bad Card",
46
+ "P35" => "Test Tran. Problem",
47
+ "P40" => "Username already exists",
48
+ "P41" => "Username is blank",
49
+ "P50" => "Fraud Screen Failure",
50
+ "P51" => "Missing PIN Code",
51
+ "P52" => "Invalid Bank Acct. No.",
52
+ "P53" => "Invalid Bank Routing No.",
53
+ "P54" => "Invalid/Missing Check No.",
54
+ "P55" => "Invalid Credit Card No.",
55
+ "P56" => "Invalid CVV2/CVC2 No.",
56
+ "P57" => "Expired. CC Exp. Date",
57
+ "P58" => "Missing Data",
58
+ "P59" => "Missing Email Address",
59
+ "P60" => "Zip Code does not match Billing State.",
60
+ "P61" => "Invalid Billing Zip Code",
61
+ "P62" => "Zip Code does not match Shipping State.",
62
+ "P63" => "Invalid Shipping Zip Code",
63
+ "P64" => "Invalid Credit Card CVV2/CVC2 Format.",
64
+ "P65" => "Maximum number of attempts has been exceeded.",
65
+ "P66" => "Credit Card number has been flagged and can not be used to access this service.",
66
+ "P67" => "IP Address is on Blocked List.",
67
+ "P68" => "Billing country does not match ipaddress country.",
68
+ "P69" => "US based ipaddresses are currently blocked.",
69
+ "P70" => "Credit Cards issued from this bank are currently not being accepted.",
70
+ "P71" => "Credit Cards issued from this bank are currently not being accepted.",
71
+ "P72" => "Daily volume exceeded.",
72
+ "P73" => "Too many transactions within allotted time.",
73
+ "P91" => "Missing/incorrect password",
74
+ "P92" => "Account not configured for mobil administration",
75
+ "P93" => "IP Not registered to username.",
76
+ "P94" => "Mode not permitted for this account.",
77
+ "P95" => "Currently Blank",
78
+ "P96" => "Currently Blank",
79
+ "P97" => "Processor not responding",
80
+ "P98" => "Missing merchant/publisher name",
81
+ "P99" => "Currently Blank"
82
+ }
83
+
84
+ TRANSACTIONS = {
85
+ :authorization => 'auth',
86
+ :purchase => 'auth',
87
+ :capture => 'mark',
88
+ :void => 'void',
89
+ :refund => 'return',
90
+ :credit => 'newreturn'
91
+ }
92
+
93
+ SUCCESS_CODES = [ 'pending', 'success' ]
94
+ FAILURE_CODES = [ 'badcard', 'fraud' ]
95
+
96
+ self.default_currency = 'USD'
97
+ self.supported_countries = ['US']
98
+ self.supported_cardtypes = [:visa, :master, :american_express, :discover]
99
+ self.homepage_url = 'http://www.plugnpay.com/'
100
+ self.display_name = "Plug'n Pay"
101
+
102
+ def initialize(options = {})
103
+ requires!(options, :login, :password)
104
+ @options = options
105
+ super
106
+ end
107
+
108
+ def purchase(money, creditcard, options = {})
109
+ post = PlugnpayPostData.new
110
+
111
+ add_amount(post, money, options)
112
+ add_creditcard(post, creditcard)
113
+ add_addresses(post, options)
114
+ add_invoice_data(post, options)
115
+ add_customer_data(post, options)
116
+
117
+ post[:authtype] = 'authpostauth'
118
+ commit(:authorization, post)
119
+ end
120
+
121
+ def authorize(money, creditcard, options = {})
122
+ post = PlugnpayPostData.new
123
+
124
+ add_amount(post, money, options)
125
+ add_creditcard(post, creditcard)
126
+ add_addresses(post, options)
127
+ add_invoice_data(post, options)
128
+ add_customer_data(post, options)
129
+
130
+ post[:authtype] = 'authonly'
131
+ commit(:authorization, post)
132
+ end
133
+
134
+ def capture(money, authorization, options = {})
135
+ post = PlugnpayPostData.new
136
+
137
+ post[:orderID] = authorization
138
+
139
+ add_amount(post, money, options)
140
+ add_customer_data(post, options)
141
+
142
+ commit(:capture, post)
143
+ end
144
+
145
+ def void(authorization, options = {})
146
+ post = PlugnpayPostData.new
147
+
148
+ post[:orderID] = authorization
149
+ post[:txn_type] = 'auth'
150
+
151
+ commit(:void, post)
152
+ end
153
+
154
+ def credit(money, identification_or_creditcard, options = {})
155
+ post = PlugnpayPostData.new
156
+ add_amount(post, money, options)
157
+
158
+ if identification_or_creditcard.is_a?(String)
159
+ deprecated CREDIT_DEPRECATION_MESSAGE
160
+ refund(money, identification_or_creditcard, options)
161
+ else
162
+ add_creditcard(post, identification_or_creditcard)
163
+ add_addresses(post, options)
164
+ add_customer_data(post, options)
165
+
166
+ commit(:credit, post)
167
+ end
168
+ end
169
+
170
+ def refund(money, reference, options = {})
171
+ post = PlugnpayPostData.new
172
+ add_amount(post, money, options)
173
+ post[:orderID] = reference
174
+ commit(:refund, post)
175
+ end
176
+
177
+ private
178
+ def commit(action, post)
179
+ response = parse( ssl_post(URL, post_data(action, post)) )
180
+
181
+ success = SUCCESS_CODES.include?(response[:finalstatus])
182
+ message = success ? 'Success' : message_from(response)
183
+
184
+ Response.new(success, message, response,
185
+ :test => test?,
186
+ :authorization => response[:orderid],
187
+ :avs_result => { :code => response[:avs_code] },
188
+ :cvv_result => response[:cvvresp]
189
+ )
190
+ end
191
+
192
+ def parse(body)
193
+ body = CGI.unescape(body)
194
+ results = {}
195
+ body.split('&').collect { |e| e.split('=') }.each do |key,value|
196
+ results[key.downcase.to_sym] = normalize(value.to_s.strip)
197
+ end
198
+
199
+ results.delete(:publisher_password)
200
+ results[:avs_message] = AVS_MESSAGES[results[:avs_code]] if results[:avs_code]
201
+ results[:card_code_message] = CARD_CODE_MESSAGES[results[:cvvresp]] if results[:cvvresp]
202
+
203
+ results
204
+ end
205
+
206
+ def post_data(action, post)
207
+ post[:mode] = TRANSACTIONS[action]
208
+ post[:convert] = 'underscores'
209
+ post[:app_level] = 0
210
+ post[:publisher_name] = @options[:login]
211
+ post[:publisher_password] = @options[:password]
212
+
213
+ post.to_s
214
+ end
215
+
216
+ def add_creditcard(post, creditcard)
217
+ post[:card_number] = creditcard.number
218
+ post[:card_cvv] = creditcard.verification_value
219
+ post[:card_exp] = expdate(creditcard)
220
+ post[:card_name] = creditcard.name.slice(0..38)
221
+ end
222
+
223
+ def add_customer_data(post, options)
224
+ post[:email] = options[:email]
225
+ post[:dontsndmail] = 'yes' unless options[:send_email_confirmation]
226
+ post[:ipaddress] = options[:ip]
227
+ end
228
+
229
+ def add_invoice_data(post, options)
230
+ post[:shipping] = amount(options[:shipping]) unless options[:shipping].blank?
231
+ post[:tax] = amount(options[:tax]) unless options[:tax].blank?
232
+ end
233
+
234
+ def add_addresses(post, options)
235
+ if address = options[:billing_address] || options[:address]
236
+ post[:card_address1] = address[:address1]
237
+ post[:card_zip] = address[:zip]
238
+ post[:card_city] = address[:city]
239
+ post[:card_country] = address[:country]
240
+ post[:phone] = address[:phone]
241
+
242
+ case address[:country]
243
+ when 'US', 'CA'
244
+ post[:card_state] = address[:state]
245
+ else
246
+ post[:card_state] = 'ZZ'
247
+ post[:card_prov] = address[:state]
248
+ end
249
+ end
250
+
251
+ if shipping_address = options[:shipping_address] || address
252
+ post[:shipname] = shipping_address[:name]
253
+ post[:address1] = shipping_address[:address1]
254
+ post[:address2] = shipping_address[:address2]
255
+ post[:city] = shipping_address[:city]
256
+
257
+ case shipping_address[:country]
258
+ when 'US', 'CA'
259
+ post[:state] = shipping_address[:state]
260
+ else
261
+ post[:state] = 'ZZ'
262
+ post[:province] = shipping_address[:state]
263
+ end
264
+
265
+ post[:country] = shipping_address[:country]
266
+ post[:zip] = shipping_address[:zip]
267
+ end
268
+ end
269
+
270
+ def add_amount(post, money, options)
271
+ post[:card_amount] = amount(money)
272
+ post[:currency] = options[:currency] || currency(money)
273
+ end
274
+
275
+ # Make a ruby type out of the response string
276
+ def normalize(field)
277
+ case field
278
+ when "true" then true
279
+ when "false" then false
280
+ when "" then nil
281
+ when "null" then nil
282
+ else field
283
+ end
284
+ end
285
+
286
+ def message_from(results)
287
+ PAYMENT_GATEWAY_RESPONSES[results[:resp_code]]
288
+ end
289
+
290
+ def expdate(creditcard)
291
+ year = sprintf("%.4i", creditcard.year)
292
+ month = sprintf("%.2i", creditcard.month)
293
+
294
+ "#{month}/#{year[-2..-1]}"
295
+ end
296
+ end
297
+ end
298
+ end