aktivemerchant 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (193) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG +1596 -0
  3. data/CONTRIBUTORS +511 -0
  4. data/MIT-LICENSE +20 -0
  5. data/README.md +18 -0
  6. data/lib/active_merchant.rb +108 -0
  7. data/lib/active_merchant/billing.rb +13 -0
  8. data/lib/active_merchant/billing/apple_pay_payment_token.rb +22 -0
  9. data/lib/active_merchant/billing/avs_result.rb +98 -0
  10. data/lib/active_merchant/billing/base.rb +72 -0
  11. data/lib/active_merchant/billing/check.rb +76 -0
  12. data/lib/active_merchant/billing/compatibility.rb +120 -0
  13. data/lib/active_merchant/billing/credit_card.rb +352 -0
  14. data/lib/active_merchant/billing/credit_card_formatting.rb +24 -0
  15. data/lib/active_merchant/billing/credit_card_methods.rb +160 -0
  16. data/lib/active_merchant/billing/cvv_result.rb +38 -0
  17. data/lib/active_merchant/billing/gateway.rb +268 -0
  18. data/lib/active_merchant/billing/gateways.rb +17 -0
  19. data/lib/active_merchant/billing/gateways/adyen.rb +209 -0
  20. data/lib/active_merchant/billing/gateways/alfabank.rb +117 -0
  21. data/lib/active_merchant/billing/gateways/app55.rb +176 -0
  22. data/lib/active_merchant/billing/gateways/authorize_net.rb +419 -0
  23. data/lib/active_merchant/billing/gateways/authorize_net_arb.rb +417 -0
  24. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +976 -0
  25. data/lib/active_merchant/billing/gateways/balanced.rb +256 -0
  26. data/lib/active_merchant/billing/gateways/bank_frick.rb +225 -0
  27. data/lib/active_merchant/billing/gateways/banwire.rb +105 -0
  28. data/lib/active_merchant/billing/gateways/barclays_epdq.rb +314 -0
  29. data/lib/active_merchant/billing/gateways/barclays_epdq_extra_plus.rb +15 -0
  30. data/lib/active_merchant/billing/gateways/be2bill.rb +131 -0
  31. data/lib/active_merchant/billing/gateways/beanstream.rb +188 -0
  32. data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +393 -0
  33. data/lib/active_merchant/billing/gateways/beanstream_interac.rb +54 -0
  34. data/lib/active_merchant/billing/gateways/blue_pay.rb +506 -0
  35. data/lib/active_merchant/billing/gateways/bogus.rb +140 -0
  36. data/lib/active_merchant/billing/gateways/borgun.rb +210 -0
  37. data/lib/active_merchant/billing/gateways/braintree.rb +19 -0
  38. data/lib/active_merchant/billing/gateways/braintree/braintree_common.rb +9 -0
  39. data/lib/active_merchant/billing/gateways/braintree_blue.rb +515 -0
  40. data/lib/active_merchant/billing/gateways/braintree_orange.rb +20 -0
  41. data/lib/active_merchant/billing/gateways/bridge_pay.rb +189 -0
  42. data/lib/active_merchant/billing/gateways/card_save.rb +23 -0
  43. data/lib/active_merchant/billing/gateways/card_stream.rb +220 -0
  44. data/lib/active_merchant/billing/gateways/cashnet.rb +191 -0
  45. data/lib/active_merchant/billing/gateways/cc5.rb +201 -0
  46. data/lib/active_merchant/billing/gateways/cecabank.rb +229 -0
  47. data/lib/active_merchant/billing/gateways/certo_direct.rb +278 -0
  48. data/lib/active_merchant/billing/gateways/checkout.rb +213 -0
  49. data/lib/active_merchant/billing/gateways/commercegate.rb +143 -0
  50. data/lib/active_merchant/billing/gateways/conekta.rb +209 -0
  51. data/lib/active_merchant/billing/gateways/cyber_source.rb +709 -0
  52. data/lib/active_merchant/billing/gateways/data_cash.rb +600 -0
  53. data/lib/active_merchant/billing/gateways/efsnet.rb +219 -0
  54. data/lib/active_merchant/billing/gateways/elavon.rb +348 -0
  55. data/lib/active_merchant/billing/gateways/epay.rb +275 -0
  56. data/lib/active_merchant/billing/gateways/evo_ca.rb +308 -0
  57. data/lib/active_merchant/billing/gateways/eway.rb +214 -0
  58. data/lib/active_merchant/billing/gateways/eway_managed.rb +291 -0
  59. data/lib/active_merchant/billing/gateways/eway_rapid.rb +524 -0
  60. data/lib/active_merchant/billing/gateways/exact.rb +218 -0
  61. data/lib/active_merchant/billing/gateways/fat_zebra.rb +173 -0
  62. data/lib/active_merchant/billing/gateways/federated_canada.rb +160 -0
  63. data/lib/active_merchant/billing/gateways/finansbank.rb +23 -0
  64. data/lib/active_merchant/billing/gateways/first_giving.rb +143 -0
  65. data/lib/active_merchant/billing/gateways/first_pay.rb +160 -0
  66. data/lib/active_merchant/billing/gateways/firstdata_e4.rb +355 -0
  67. data/lib/active_merchant/billing/gateways/garanti.rb +257 -0
  68. data/lib/active_merchant/billing/gateways/global_transport.rb +183 -0
  69. data/lib/active_merchant/billing/gateways/hdfc.rb +207 -0
  70. data/lib/active_merchant/billing/gateways/hps.rb +288 -0
  71. data/lib/active_merchant/billing/gateways/iats_payments.rb +251 -0
  72. data/lib/active_merchant/billing/gateways/ideal/ideal_base.rb +246 -0
  73. data/lib/active_merchant/billing/gateways/ideal/ideal_rabobank.pem +13 -0
  74. data/lib/active_merchant/billing/gateways/ideal/ideal_response.rb +29 -0
  75. data/lib/active_merchant/billing/gateways/ideal_rabobank.rb +66 -0
  76. data/lib/active_merchant/billing/gateways/inspire.rb +213 -0
  77. data/lib/active_merchant/billing/gateways/instapay.rb +163 -0
  78. data/lib/active_merchant/billing/gateways/iridium.rb +457 -0
  79. data/lib/active_merchant/billing/gateways/itransact.rb +448 -0
  80. data/lib/active_merchant/billing/gateways/jetpay.rb +275 -0
  81. data/lib/active_merchant/billing/gateways/linkpoint.rb +438 -0
  82. data/lib/active_merchant/billing/gateways/litle.rb +346 -0
  83. data/lib/active_merchant/billing/gateways/maxipago.rb +197 -0
  84. data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +170 -0
  85. data/lib/active_merchant/billing/gateways/merchant_one.rb +114 -0
  86. data/lib/active_merchant/billing/gateways/merchant_ware.rb +319 -0
  87. data/lib/active_merchant/billing/gateways/merchant_ware_version_four.rb +268 -0
  88. data/lib/active_merchant/billing/gateways/merchant_warrior.rb +195 -0
  89. data/lib/active_merchant/billing/gateways/mercury.rb +333 -0
  90. data/lib/active_merchant/billing/gateways/metrics_global.rb +303 -0
  91. data/lib/active_merchant/billing/gateways/migs.rb +265 -0
  92. data/lib/active_merchant/billing/gateways/migs/migs_codes.rb +100 -0
  93. data/lib/active_merchant/billing/gateways/modern_payments.rb +37 -0
  94. data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +219 -0
  95. data/lib/active_merchant/billing/gateways/moneris.rb +309 -0
  96. data/lib/active_merchant/billing/gateways/moneris_us.rb +291 -0
  97. data/lib/active_merchant/billing/gateways/money_movers.rb +152 -0
  98. data/lib/active_merchant/billing/gateways/nab_transact.rb +280 -0
  99. data/lib/active_merchant/billing/gateways/net_registry.rb +198 -0
  100. data/lib/active_merchant/billing/gateways/netaxept.rb +181 -0
  101. data/lib/active_merchant/billing/gateways/netbilling.rb +190 -0
  102. data/lib/active_merchant/billing/gateways/netpay.rb +223 -0
  103. data/lib/active_merchant/billing/gateways/network_merchants.rb +242 -0
  104. data/lib/active_merchant/billing/gateways/nmi.rb +256 -0
  105. data/lib/active_merchant/billing/gateways/ogone.rb +435 -0
  106. data/lib/active_merchant/billing/gateways/openpay.rb +194 -0
  107. data/lib/active_merchant/billing/gateways/optimal_payment.rb +313 -0
  108. data/lib/active_merchant/billing/gateways/orbital.rb +803 -0
  109. data/lib/active_merchant/billing/gateways/orbital/orbital_soft_descriptors.rb +47 -0
  110. data/lib/active_merchant/billing/gateways/pac_net_raven.rb +207 -0
  111. data/lib/active_merchant/billing/gateways/pago_facil.rb +122 -0
  112. data/lib/active_merchant/billing/gateways/pay_gate_xml.rb +261 -0
  113. data/lib/active_merchant/billing/gateways/pay_junction.rb +390 -0
  114. data/lib/active_merchant/billing/gateways/pay_secure.rb +112 -0
  115. data/lib/active_merchant/billing/gateways/pay_u_latam.rb +462 -0
  116. data/lib/active_merchant/billing/gateways/paybox_direct.rb +188 -0
  117. data/lib/active_merchant/billing/gateways/payex.rb +412 -0
  118. data/lib/active_merchant/billing/gateways/payflow.rb +304 -0
  119. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +209 -0
  120. data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +39 -0
  121. data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +13 -0
  122. data/lib/active_merchant/billing/gateways/payflow_express.rb +224 -0
  123. data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +15 -0
  124. data/lib/active_merchant/billing/gateways/payflow_uk.rb +21 -0
  125. data/lib/active_merchant/billing/gateways/payment_express.rb +353 -0
  126. data/lib/active_merchant/billing/gateways/paymill.rb +281 -0
  127. data/lib/active_merchant/billing/gateways/paypal.rb +117 -0
  128. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +670 -0
  129. data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +65 -0
  130. data/lib/active_merchant/billing/gateways/paypal/paypal_recurring_api.rb +262 -0
  131. data/lib/active_merchant/billing/gateways/paypal_ca.rb +13 -0
  132. data/lib/active_merchant/billing/gateways/paypal_digital_goods.rb +44 -0
  133. data/lib/active_merchant/billing/gateways/paypal_express.rb +264 -0
  134. data/lib/active_merchant/billing/gateways/paypal_express_common.rb +30 -0
  135. data/lib/active_merchant/billing/gateways/payscout.rb +162 -0
  136. data/lib/active_merchant/billing/gateways/paystation.rb +199 -0
  137. data/lib/active_merchant/billing/gateways/payway.rb +207 -0
  138. data/lib/active_merchant/billing/gateways/pin.rb +197 -0
  139. data/lib/active_merchant/billing/gateways/plugnpay.rb +283 -0
  140. data/lib/active_merchant/billing/gateways/psigate.rb +216 -0
  141. data/lib/active_merchant/billing/gateways/psl_card.rb +303 -0
  142. data/lib/active_merchant/billing/gateways/qbms.rb +292 -0
  143. data/lib/active_merchant/billing/gateways/quantum.rb +276 -0
  144. data/lib/active_merchant/billing/gateways/quickpay.rb +367 -0
  145. data/lib/active_merchant/billing/gateways/realex.rb +298 -0
  146. data/lib/active_merchant/billing/gateways/redsys.rb +391 -0
  147. data/lib/active_merchant/billing/gateways/sage.rb +175 -0
  148. data/lib/active_merchant/billing/gateways/sage/sage_bankcard.rb +87 -0
  149. data/lib/active_merchant/billing/gateways/sage/sage_core.rb +114 -0
  150. data/lib/active_merchant/billing/gateways/sage/sage_vault.rb +149 -0
  151. data/lib/active_merchant/billing/gateways/sage/sage_virtual_check.rb +102 -0
  152. data/lib/active_merchant/billing/gateways/sage_pay.rb +398 -0
  153. data/lib/active_merchant/billing/gateways/sallie_mae.rb +143 -0
  154. data/lib/active_merchant/billing/gateways/secure_net.rb +252 -0
  155. data/lib/active_merchant/billing/gateways/secure_pay.rb +201 -0
  156. data/lib/active_merchant/billing/gateways/secure_pay_au.rb +281 -0
  157. data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +105 -0
  158. data/lib/active_merchant/billing/gateways/skip_jack.rb +452 -0
  159. data/lib/active_merchant/billing/gateways/smart_ps.rb +283 -0
  160. data/lib/active_merchant/billing/gateways/so_easy_pay.rb +194 -0
  161. data/lib/active_merchant/billing/gateways/spreedly_core.rb +247 -0
  162. data/lib/active_merchant/billing/gateways/stripe.rb +411 -0
  163. data/lib/active_merchant/billing/gateways/swipe_checkout.rb +157 -0
  164. data/lib/active_merchant/billing/gateways/tns.rb +227 -0
  165. data/lib/active_merchant/billing/gateways/trans_first.rb +126 -0
  166. data/lib/active_merchant/billing/gateways/transax.rb +23 -0
  167. data/lib/active_merchant/billing/gateways/transnational.rb +10 -0
  168. data/lib/active_merchant/billing/gateways/trust_commerce.rb +416 -0
  169. data/lib/active_merchant/billing/gateways/usa_epay.rb +25 -0
  170. data/lib/active_merchant/billing/gateways/usa_epay_advanced.rb +1516 -0
  171. data/lib/active_merchant/billing/gateways/usa_epay_transaction.rb +254 -0
  172. data/lib/active_merchant/billing/gateways/verifi.rb +225 -0
  173. data/lib/active_merchant/billing/gateways/viaklix.rb +183 -0
  174. data/lib/active_merchant/billing/gateways/vindicia.rb +385 -0
  175. data/lib/active_merchant/billing/gateways/webpay.rb +97 -0
  176. data/lib/active_merchant/billing/gateways/wepay.rb +189 -0
  177. data/lib/active_merchant/billing/gateways/wirecard.rb +421 -0
  178. data/lib/active_merchant/billing/gateways/worldpay.rb +331 -0
  179. data/lib/active_merchant/billing/gateways/worldpay_us.rb +181 -0
  180. data/lib/active_merchant/billing/model.rb +30 -0
  181. data/lib/active_merchant/billing/payment_token.rb +21 -0
  182. data/lib/active_merchant/billing/rails.rb +3 -0
  183. data/lib/active_merchant/billing/response.rb +91 -0
  184. data/lib/active_merchant/country.rb +332 -0
  185. data/lib/active_merchant/empty.rb +20 -0
  186. data/lib/active_merchant/errors.rb +29 -0
  187. data/lib/active_merchant/offsite_payments_shim.rb +19 -0
  188. data/lib/active_merchant/version.rb +3 -0
  189. data/lib/activemerchant.rb +1 -0
  190. data/lib/support/gateway_support.rb +71 -0
  191. data/lib/support/outbound_hosts.rb +25 -0
  192. data/lib/support/ssl_verify.rb +93 -0
  193. metadata +400 -0
@@ -0,0 +1,197 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ class PinGateway < Gateway
4
+ self.test_url = 'https://test-api.pin.net.au/1'
5
+ self.live_url = 'https://api.pin.net.au/1'
6
+
7
+ self.default_currency = 'AUD'
8
+ self.money_format = :cents
9
+ self.supported_countries = ['AU']
10
+ self.supported_cardtypes = [:visa, :master, :american_express]
11
+ self.homepage_url = 'http://www.pin.net.au/'
12
+ self.display_name = 'Pin Payments'
13
+
14
+ def initialize(options = {})
15
+ requires!(options, :api_key)
16
+ super
17
+ end
18
+
19
+ # Create a charge using a credit card, card token or customer token
20
+ #
21
+ # To charge a credit card: purchase([money], [creditcard hash], ...)
22
+ # To charge a customer: purchase([money], [token], ...)
23
+ def purchase(money, creditcard, options = {})
24
+ post = {}
25
+
26
+ add_amount(post, money, options)
27
+ add_customer_data(post, options)
28
+ add_invoice(post, options)
29
+ add_creditcard(post, creditcard)
30
+ add_address(post, creditcard, options)
31
+ add_capture(post, options)
32
+
33
+ commit(:post, 'charges', post, options)
34
+ end
35
+
36
+ # Create a customer and associated credit card. The token that is returned
37
+ # can be used instead of a credit card parameter in the purchase method
38
+ def store(creditcard, options = {})
39
+ post = {}
40
+
41
+ add_creditcard(post, creditcard)
42
+ add_customer_data(post, options)
43
+ add_address(post, creditcard, options)
44
+ commit(:post, 'customers', post, options)
45
+ end
46
+
47
+ # Refund a transaction, note that the money attribute is ignored at the
48
+ # moment as the API does not support partial refunds. The parameter is
49
+ # kept for compatibility reasons
50
+ def refund(money, token, options = {})
51
+ commit(:post, "charges/#{CGI.escape(token)}/refunds", { :amount => amount(money) }, options)
52
+ end
53
+
54
+ # Authorize an amount on a credit card. Once authorized, you can later
55
+ # capture this charge using the charge token that is returned.
56
+ def authorize(money, creditcard, options = {})
57
+ options[:capture] = false
58
+
59
+ purchase(money, creditcard, options)
60
+ end
61
+
62
+ # Captures a previously authorized charge. Capturing a certin amount of the original
63
+ # authorization is currently not supported.
64
+ def capture(money, token, options = {})
65
+ commit(:put, "charges/#{CGI.escape(token)}/capture", {}, options)
66
+ end
67
+
68
+ # Updates the credit card for the customer.
69
+ def update(token, creditcard, options = {})
70
+ post = {}
71
+
72
+ add_creditcard(post, creditcard)
73
+ add_customer_data(post, options)
74
+ add_address(post, creditcard, options)
75
+ commit(:put, "customers/#{CGI.escape(token)}", post, options)
76
+ end
77
+
78
+ private
79
+
80
+ def add_amount(post, money, options)
81
+ post[:amount] = amount(money)
82
+ post[:currency] = (options[:currency] || currency(money))
83
+ post[:currency] = post[:currency].upcase if post[:currency]
84
+ end
85
+
86
+ def add_customer_data(post, options)
87
+ post[:email] = options[:email] if options[:email]
88
+ post[:ip_address] = options[:ip] if options[:ip]
89
+ end
90
+
91
+ def add_address(post, creditcard, options)
92
+ return if creditcard.kind_of?(String)
93
+ address = (options[:billing_address] || options[:address])
94
+ return unless address
95
+
96
+ post[:card] ||= {}
97
+ post[:card].merge!(
98
+ :address_line1 => address[:address1],
99
+ :address_city => address[:city],
100
+ :address_postcode => address[:zip],
101
+ :address_state => address[:state],
102
+ :address_country => address[:country]
103
+ )
104
+ end
105
+
106
+ def add_invoice(post, options)
107
+ post[:description] = options[:description] || "Active Merchant Purchase"
108
+ end
109
+
110
+ def add_capture(post, options)
111
+ capture = options[:capture]
112
+
113
+ post[:capture] = capture == false ? false : true
114
+ end
115
+
116
+ def add_creditcard(post, creditcard)
117
+ if creditcard.respond_to?(:number)
118
+ post[:card] ||= {}
119
+
120
+ post[:card].merge!(
121
+ :number => creditcard.number,
122
+ :expiry_month => creditcard.month,
123
+ :expiry_year => creditcard.year,
124
+ :cvc => creditcard.verification_value,
125
+ :name => creditcard.name
126
+ )
127
+ elsif creditcard.kind_of?(String)
128
+ if creditcard =~ /^card_/
129
+ post[:card_token] = creditcard
130
+ else
131
+ post[:customer_token] = creditcard
132
+ end
133
+ end
134
+ end
135
+
136
+ def headers(params = {})
137
+ result = {
138
+ "Content-Type" => "application/json",
139
+ "Authorization" => "Basic #{Base64.strict_encode64(options[:api_key] + ':').strip}"
140
+ }
141
+
142
+ result['X-Partner-Key'] = params[:partner_key] if params[:partner_key]
143
+ result['X-Safe-Card'] = params[:safe_card] if params[:safe_card]
144
+ result
145
+ end
146
+
147
+ def commit(method, action, params, options)
148
+ url = "#{test? ? test_url : live_url}/#{action}"
149
+
150
+ begin
151
+ body = parse(ssl_request(method, url, post_data(params), headers(options)))
152
+ rescue ResponseError => e
153
+ body = parse(e.response.body)
154
+ end
155
+
156
+ if body["response"]
157
+ success_response(body)
158
+ elsif body["error"]
159
+ error_response(body)
160
+ end
161
+ end
162
+
163
+ def success_response(body)
164
+ response = body["response"]
165
+ Response.new(
166
+ true,
167
+ response['status_message'],
168
+ body,
169
+ :authorization => token(response),
170
+ :test => test?
171
+ )
172
+ end
173
+
174
+ def error_response(body)
175
+ Response.new(
176
+ false,
177
+ body['error_description'],
178
+ body,
179
+ :authorization => nil,
180
+ :test => test?
181
+ )
182
+ end
183
+
184
+ def token(response)
185
+ response['token']
186
+ end
187
+
188
+ def parse(body)
189
+ JSON.parse(body)
190
+ end
191
+
192
+ def post_data(parameters = {})
193
+ parameters.to_json
194
+ end
195
+ end
196
+ end
197
+ end
@@ -0,0 +1,283 @@
1
+ module ActiveMerchant
2
+ module Billing
3
+ class PlugnpayGateway < Gateway
4
+ class PlugnpayPostData < PostData
5
+ # Fields that will be sent even if they are blank
6
+ self.required_fields = [ :publisher_name, :publisher_password,
7
+ :card_amount, :card_name, :card_number, :card_exp, :orderID ]
8
+ end
9
+ self.live_url = self.test_url = 'https://pay1.plugnpay.com/payment/pnpremote.cgi'
10
+
11
+ CARD_CODE_MESSAGES = {
12
+ "M" => "Card verification number matched",
13
+ "N" => "Card verification number didn't match",
14
+ "P" => "Card verification number was not processed",
15
+ "S" => "Card verification number should be on card but was not indicated",
16
+ "U" => "Issuer was not certified for card verification"
17
+ }
18
+
19
+ CARD_CODE_ERRORS = %w( N S )
20
+
21
+ AVS_MESSAGES = {
22
+ "A" => "Street address matches billing information, zip/postal code does not",
23
+ "B" => "Address information not provided for address verification check",
24
+ "E" => "Address verification service error",
25
+ "G" => "Non-U.S. card-issuing bank",
26
+ "N" => "Neither street address nor zip/postal match billing information",
27
+ "P" => "Address verification not applicable for this transaction",
28
+ "R" => "Payment gateway was unavailable or timed out",
29
+ "S" => "Address verification service not supported by issuer",
30
+ "U" => "Address information is unavailable",
31
+ "W" => "9-digit zip/postal code matches billing information, street address does not",
32
+ "X" => "Street address and 9-digit zip/postal code matches billing information",
33
+ "Y" => "Street address and 5-digit zip/postal code matches billing information",
34
+ "Z" => "5-digit zip/postal code matches billing information, street address does not",
35
+ }
36
+
37
+ AVS_ERRORS = %w( A E N R W Z )
38
+
39
+ PAYMENT_GATEWAY_RESPONSES = {
40
+ "P01" => "AVS Mismatch Failure",
41
+ "P02" => "CVV2 Mismatch Failure",
42
+ "P21" => "Transaction may not be marked",
43
+ "P30" => "Test Tran. Bad Card",
44
+ "P35" => "Test Tran. Problem",
45
+ "P40" => "Username already exists",
46
+ "P41" => "Username is blank",
47
+ "P50" => "Fraud Screen Failure",
48
+ "P51" => "Missing PIN Code",
49
+ "P52" => "Invalid Bank Acct. No.",
50
+ "P53" => "Invalid Bank Routing No.",
51
+ "P54" => "Invalid/Missing Check No.",
52
+ "P55" => "Invalid Credit Card No.",
53
+ "P56" => "Invalid CVV2/CVC2 No.",
54
+ "P57" => "Expired. CC Exp. Date",
55
+ "P58" => "Missing Data",
56
+ "P59" => "Missing Email Address",
57
+ "P60" => "Zip Code does not match Billing State.",
58
+ "P61" => "Invalid Billing Zip Code",
59
+ "P62" => "Zip Code does not match Shipping State.",
60
+ "P63" => "Invalid Shipping Zip Code",
61
+ "P64" => "Invalid Credit Card CVV2/CVC2 Format.",
62
+ "P65" => "Maximum number of attempts has been exceeded.",
63
+ "P66" => "Credit Card number has been flagged and can not be used to access this service.",
64
+ "P67" => "IP Address is on Blocked List.",
65
+ "P68" => "Billing country does not match ipaddress country.",
66
+ "P69" => "US based ipaddresses are currently blocked.",
67
+ "P70" => "Credit Cards issued from this bank are currently not being accepted.",
68
+ "P71" => "Credit Cards issued from this bank are currently not being accepted.",
69
+ "P72" => "Daily volume exceeded.",
70
+ "P73" => "Too many transactions within allotted time.",
71
+ "P91" => "Missing/incorrect password",
72
+ "P92" => "Account not configured for mobil administration",
73
+ "P93" => "IP Not registered to username.",
74
+ "P94" => "Mode not permitted for this account.",
75
+ "P95" => "Currently Blank",
76
+ "P96" => "Currently Blank",
77
+ "P97" => "Processor not responding",
78
+ "P98" => "Missing merchant/publisher name",
79
+ "P99" => "Currently Blank"
80
+ }
81
+
82
+ TRANSACTIONS = {
83
+ :authorization => 'auth',
84
+ :purchase => 'auth',
85
+ :capture => 'mark',
86
+ :void => 'void',
87
+ :refund => 'return',
88
+ :credit => 'newreturn'
89
+ }
90
+
91
+ SUCCESS_CODES = [ 'pending', 'success' ]
92
+ FAILURE_CODES = [ 'badcard', 'fraud' ]
93
+
94
+ self.default_currency = 'USD'
95
+ self.supported_countries = ['US']
96
+ self.supported_cardtypes = [:visa, :master, :american_express, :discover]
97
+ self.homepage_url = 'http://www.plugnpay.com/'
98
+ self.display_name = "Plug'n Pay"
99
+
100
+ def initialize(options = {})
101
+ requires!(options, :login, :password)
102
+ super
103
+ end
104
+
105
+ def purchase(money, creditcard, options = {})
106
+ post = PlugnpayPostData.new
107
+
108
+ add_amount(post, money, options)
109
+ add_creditcard(post, creditcard)
110
+ add_addresses(post, options)
111
+ add_invoice_data(post, options)
112
+ add_customer_data(post, options)
113
+
114
+ post[:authtype] = 'authpostauth'
115
+ commit(:authorization, post)
116
+ end
117
+
118
+ def authorize(money, creditcard, options = {})
119
+ post = PlugnpayPostData.new
120
+
121
+ add_amount(post, money, options)
122
+ add_creditcard(post, creditcard)
123
+ add_addresses(post, options)
124
+ add_invoice_data(post, options)
125
+ add_customer_data(post, options)
126
+
127
+ post[:authtype] = 'authonly'
128
+ commit(:authorization, post)
129
+ end
130
+
131
+ def capture(money, authorization, options = {})
132
+ post = PlugnpayPostData.new
133
+
134
+ post[:orderID] = authorization
135
+
136
+ add_amount(post, money, options)
137
+ add_customer_data(post, options)
138
+
139
+ commit(:capture, post)
140
+ end
141
+
142
+ def void(authorization, options = {})
143
+ post = PlugnpayPostData.new
144
+
145
+ post[:orderID] = authorization
146
+ post[:txn_type] = 'auth'
147
+
148
+ commit(:void, post)
149
+ end
150
+
151
+ def credit(money, identification_or_creditcard, options = {})
152
+ post = PlugnpayPostData.new
153
+ add_amount(post, money, options)
154
+
155
+ if identification_or_creditcard.is_a?(String)
156
+ ActiveMerchant.deprecated CREDIT_DEPRECATION_MESSAGE
157
+ refund(money, identification_or_creditcard, options)
158
+ else
159
+ add_creditcard(post, identification_or_creditcard)
160
+ add_addresses(post, options)
161
+ add_customer_data(post, options)
162
+
163
+ commit(:credit, post)
164
+ end
165
+ end
166
+
167
+ def refund(money, reference, options = {})
168
+ post = PlugnpayPostData.new
169
+ add_amount(post, money, options)
170
+ post[:orderID] = reference
171
+ commit(:refund, post)
172
+ end
173
+
174
+ private
175
+ def commit(action, post)
176
+ response = parse( ssl_post(self.live_url, post_data(action, post)) )
177
+ success = SUCCESS_CODES.include?(response[:finalstatus])
178
+ message = success ? 'Success' : message_from(response)
179
+
180
+ Response.new(success, message, response,
181
+ :test => test?,
182
+ :authorization => response[:orderid],
183
+ :avs_result => { :code => response[:avs_code] },
184
+ :cvv_result => response[:cvvresp]
185
+ )
186
+ end
187
+
188
+ def parse(body)
189
+ body = CGI.unescape(body)
190
+ results = {}
191
+ body.split('&').collect { |e| e.split('=') }.each do |key,value|
192
+ results[key.downcase.to_sym] = normalize(value.to_s.strip)
193
+ end
194
+
195
+ results.delete(:publisher_password)
196
+ results[:avs_message] = AVS_MESSAGES[results[:avs_code]] if results[:avs_code]
197
+ results[:card_code_message] = CARD_CODE_MESSAGES[results[:cvvresp]] if results[:cvvresp]
198
+
199
+ results
200
+ end
201
+
202
+ def post_data(action, post)
203
+ post[:mode] = TRANSACTIONS[action]
204
+ post[:convert] = 'underscores'
205
+ post[:app_level] = 0
206
+ post[:publisher_name] = @options[:login]
207
+ post[:publisher_password] = @options[:password]
208
+
209
+ post.to_s
210
+ end
211
+
212
+ def add_creditcard(post, creditcard)
213
+ post[:card_number] = creditcard.number
214
+ post[:card_cvv] = creditcard.verification_value
215
+ post[:card_exp] = expdate(creditcard)
216
+ post[:card_name] = creditcard.name.slice(0..38)
217
+ end
218
+
219
+ def add_customer_data(post, options)
220
+ post[:email] = options[:email]
221
+ post[:dontsndmail] = 'yes' unless options[:send_email_confirmation]
222
+ post[:ipaddress] = options[:ip]
223
+ end
224
+
225
+ def add_invoice_data(post, options)
226
+ post[:shipping] = amount(options[:shipping]) unless options[:shipping].blank?
227
+ post[:tax] = amount(options[:tax]) unless options[:tax].blank?
228
+ end
229
+
230
+ def add_addresses(post, options)
231
+ if address = options[:billing_address] || options[:address]
232
+ post[:card_address1] = address[:address1]
233
+ post[:card_zip] = address[:zip]
234
+ post[:card_city] = address[:city]
235
+ post[:card_country] = address[:country]
236
+ post[:phone] = address[:phone]
237
+
238
+ case address[:country]
239
+ when 'US', 'CA'
240
+ post[:card_state] = address[:state]
241
+ else
242
+ post[:card_state] = 'ZZ'
243
+ post[:card_prov] = address[:state]
244
+ end
245
+ end
246
+
247
+ if shipping_address = options[:shipping_address] || address
248
+ post[:shipname] = shipping_address[:name]
249
+ post[:address1] = shipping_address[:address1]
250
+ post[:address2] = shipping_address[:address2]
251
+ post[:city] = shipping_address[:city]
252
+
253
+ case shipping_address[:country]
254
+ when 'US', 'CA'
255
+ post[:state] = shipping_address[:state]
256
+ else
257
+ post[:state] = 'ZZ'
258
+ post[:province] = shipping_address[:state]
259
+ end
260
+
261
+ post[:country] = shipping_address[:country]
262
+ post[:zip] = shipping_address[:zip]
263
+ end
264
+ end
265
+
266
+ def add_amount(post, money, options)
267
+ post[:card_amount] = amount(money)
268
+ post[:currency] = options[:currency] || currency(money)
269
+ end
270
+
271
+ def message_from(results)
272
+ PAYMENT_GATEWAY_RESPONSES[results[:resp_code]]
273
+ end
274
+
275
+ def expdate(creditcard)
276
+ year = sprintf("%.4i", creditcard.year)
277
+ month = sprintf("%.2i", creditcard.month)
278
+
279
+ "#{month}/#{year[-2..-1]}"
280
+ end
281
+ end
282
+ end
283
+ end