fishman-activemerchant 1.18.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (188) hide show
  1. data/CHANGELOG +733 -0
  2. data/CONTRIBUTORS +257 -0
  3. data/MIT-LICENSE +20 -0
  4. data/gem-public_cert.pem +20 -0
  5. data/lib/active_merchant.rb +47 -0
  6. data/lib/active_merchant/billing.rb +9 -0
  7. data/lib/active_merchant/billing/avs_result.rb +98 -0
  8. data/lib/active_merchant/billing/base.rb +57 -0
  9. data/lib/active_merchant/billing/check.rb +68 -0
  10. data/lib/active_merchant/billing/credit_card.rb +260 -0
  11. data/lib/active_merchant/billing/credit_card_formatting.rb +21 -0
  12. data/lib/active_merchant/billing/credit_card_methods.rb +125 -0
  13. data/lib/active_merchant/billing/cvv_result.rb +38 -0
  14. data/lib/active_merchant/billing/expiry_date.rb +34 -0
  15. data/lib/active_merchant/billing/gateway.rb +170 -0
  16. data/lib/active_merchant/billing/gateways.rb +18 -0
  17. data/lib/active_merchant/billing/gateways/authorize_net.rb +693 -0
  18. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +858 -0
  19. data/lib/active_merchant/billing/gateways/barclays_epdq.rb +308 -0
  20. data/lib/active_merchant/billing/gateways/beanstream.rb +139 -0
  21. data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +282 -0
  22. data/lib/active_merchant/billing/gateways/beanstream_interac.rb +54 -0
  23. data/lib/active_merchant/billing/gateways/blue_pay.rb +11 -0
  24. data/lib/active_merchant/billing/gateways/bogus.rb +142 -0
  25. data/lib/active_merchant/billing/gateways/braintree.rb +17 -0
  26. data/lib/active_merchant/billing/gateways/braintree/braintree_common.rb +9 -0
  27. data/lib/active_merchant/billing/gateways/braintree_blue.rb +303 -0
  28. data/lib/active_merchant/billing/gateways/braintree_orange.rb +17 -0
  29. data/lib/active_merchant/billing/gateways/card_save.rb +23 -0
  30. data/lib/active_merchant/billing/gateways/card_stream.rb +230 -0
  31. data/lib/active_merchant/billing/gateways/cyber_source.rb +430 -0
  32. data/lib/active_merchant/billing/gateways/data_cash.rb +597 -0
  33. data/lib/active_merchant/billing/gateways/efsnet.rb +235 -0
  34. data/lib/active_merchant/billing/gateways/elavon.rb +134 -0
  35. data/lib/active_merchant/billing/gateways/epay.rb +274 -0
  36. data/lib/active_merchant/billing/gateways/eway.rb +277 -0
  37. data/lib/active_merchant/billing/gateways/eway_managed.rb +264 -0
  38. data/lib/active_merchant/billing/gateways/exact.rb +222 -0
  39. data/lib/active_merchant/billing/gateways/federated_canada.rb +168 -0
  40. data/lib/active_merchant/billing/gateways/first_pay.rb +177 -0
  41. data/lib/active_merchant/billing/gateways/garanti.rb +262 -0
  42. data/lib/active_merchant/billing/gateways/ideal/ideal_base.rb +250 -0
  43. data/lib/active_merchant/billing/gateways/ideal/ideal_rabobank.pem +13 -0
  44. data/lib/active_merchant/billing/gateways/ideal/ideal_response.rb +29 -0
  45. data/lib/active_merchant/billing/gateways/ideal_rabobank.rb +55 -0
  46. data/lib/active_merchant/billing/gateways/inspire.rb +221 -0
  47. data/lib/active_merchant/billing/gateways/instapay.rb +164 -0
  48. data/lib/active_merchant/billing/gateways/iridium.rb +258 -0
  49. data/lib/active_merchant/billing/gateways/jetpay.rb +276 -0
  50. data/lib/active_merchant/billing/gateways/linkpoint.rb +454 -0
  51. data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +156 -0
  52. data/lib/active_merchant/billing/gateways/merchant_ware.rb +289 -0
  53. data/lib/active_merchant/billing/gateways/modern_payments.rb +36 -0
  54. data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +220 -0
  55. data/lib/active_merchant/billing/gateways/moneris.rb +209 -0
  56. data/lib/active_merchant/billing/gateways/net_registry.rb +189 -0
  57. data/lib/active_merchant/billing/gateways/netaxept.rb +239 -0
  58. data/lib/active_merchant/billing/gateways/netbilling.rb +168 -0
  59. data/lib/active_merchant/billing/gateways/nmi.rb +13 -0
  60. data/lib/active_merchant/billing/gateways/ogone.rb +292 -0
  61. data/lib/active_merchant/billing/gateways/optimal_payment.rb +274 -0
  62. data/lib/active_merchant/billing/gateways/orbital.rb +321 -0
  63. data/lib/active_merchant/billing/gateways/orbital/orbital_soft_descriptors.rb +46 -0
  64. data/lib/active_merchant/billing/gateways/pay_junction.rb +392 -0
  65. data/lib/active_merchant/billing/gateways/pay_secure.rb +120 -0
  66. data/lib/active_merchant/billing/gateways/paybox_direct.rb +207 -0
  67. data/lib/active_merchant/billing/gateways/payflow.rb +253 -0
  68. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +207 -0
  69. data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +39 -0
  70. data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +13 -0
  71. data/lib/active_merchant/billing/gateways/payflow_express.rb +222 -0
  72. data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +15 -0
  73. data/lib/active_merchant/billing/gateways/payflow_uk.rb +21 -0
  74. data/lib/active_merchant/billing/gateways/payment_express.rb +235 -0
  75. data/lib/active_merchant/billing/gateways/paypal.rb +121 -0
  76. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +354 -0
  77. data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +49 -0
  78. data/lib/active_merchant/billing/gateways/paypal_ca.rb +13 -0
  79. data/lib/active_merchant/billing/gateways/paypal_express.rb +184 -0
  80. data/lib/active_merchant/billing/gateways/paypal_express_common.rb +25 -0
  81. data/lib/active_merchant/billing/gateways/paypal_express_de.rb +14 -0
  82. data/lib/active_merchant/billing/gateways/paystation.rb +201 -0
  83. data/lib/active_merchant/billing/gateways/plugnpay.rb +298 -0
  84. data/lib/active_merchant/billing/gateways/psigate.rb +219 -0
  85. data/lib/active_merchant/billing/gateways/psl_card.rb +304 -0
  86. data/lib/active_merchant/billing/gateways/qbms.rb +297 -0
  87. data/lib/active_merchant/billing/gateways/quantum.rb +282 -0
  88. data/lib/active_merchant/billing/gateways/quickpay.rb +297 -0
  89. data/lib/active_merchant/billing/gateways/realex.rb +311 -0
  90. data/lib/active_merchant/billing/gateways/sage.rb +146 -0
  91. data/lib/active_merchant/billing/gateways/sage/sage_bankcard.rb +88 -0
  92. data/lib/active_merchant/billing/gateways/sage/sage_core.rb +116 -0
  93. data/lib/active_merchant/billing/gateways/sage/sage_virtual_check.rb +97 -0
  94. data/lib/active_merchant/billing/gateways/sage_pay.rb +320 -0
  95. data/lib/active_merchant/billing/gateways/sallie_mae.rb +144 -0
  96. data/lib/active_merchant/billing/gateways/secure_net.rb +330 -0
  97. data/lib/active_merchant/billing/gateways/secure_pay.rb +31 -0
  98. data/lib/active_merchant/billing/gateways/secure_pay_au.rb +193 -0
  99. data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +113 -0
  100. data/lib/active_merchant/billing/gateways/skip_jack.rb +453 -0
  101. data/lib/active_merchant/billing/gateways/smart_ps.rb +271 -0
  102. data/lib/active_merchant/billing/gateways/stripe.rb +212 -0
  103. data/lib/active_merchant/billing/gateways/trans_first.rb +127 -0
  104. data/lib/active_merchant/billing/gateways/transax.rb +25 -0
  105. data/lib/active_merchant/billing/gateways/trust_commerce.rb +423 -0
  106. data/lib/active_merchant/billing/gateways/usa_epay.rb +194 -0
  107. data/lib/active_merchant/billing/gateways/verifi.rb +233 -0
  108. data/lib/active_merchant/billing/gateways/viaklix.rb +189 -0
  109. data/lib/active_merchant/billing/gateways/wirecard.rb +318 -0
  110. data/lib/active_merchant/billing/gateways/worldpay.rb +280 -0
  111. data/lib/active_merchant/billing/integrations.rb +17 -0
  112. data/lib/active_merchant/billing/integrations/action_view_helper.rb +68 -0
  113. data/lib/active_merchant/billing/integrations/bogus.rb +23 -0
  114. data/lib/active_merchant/billing/integrations/bogus/helper.rb +17 -0
  115. data/lib/active_merchant/billing/integrations/bogus/notification.rb +11 -0
  116. data/lib/active_merchant/billing/integrations/bogus/return.rb +10 -0
  117. data/lib/active_merchant/billing/integrations/chronopay.rb +23 -0
  118. data/lib/active_merchant/billing/integrations/chronopay/helper.rb +120 -0
  119. data/lib/active_merchant/billing/integrations/chronopay/notification.rb +158 -0
  120. data/lib/active_merchant/billing/integrations/chronopay/return.rb +10 -0
  121. data/lib/active_merchant/billing/integrations/direc_pay.rb +41 -0
  122. data/lib/active_merchant/billing/integrations/direc_pay/helper.rb +200 -0
  123. data/lib/active_merchant/billing/integrations/direc_pay/notification.rb +76 -0
  124. data/lib/active_merchant/billing/integrations/direc_pay/return.rb +32 -0
  125. data/lib/active_merchant/billing/integrations/direc_pay/status.rb +37 -0
  126. data/lib/active_merchant/billing/integrations/directebanking.rb +47 -0
  127. data/lib/active_merchant/billing/integrations/directebanking/helper.rb +90 -0
  128. data/lib/active_merchant/billing/integrations/directebanking/notification.rb +120 -0
  129. data/lib/active_merchant/billing/integrations/directebanking/return.rb +11 -0
  130. data/lib/active_merchant/billing/integrations/dwolla.rb +30 -0
  131. data/lib/active_merchant/billing/integrations/dwolla/helper.rb +28 -0
  132. data/lib/active_merchant/billing/integrations/dwolla/notification.rb +50 -0
  133. data/lib/active_merchant/billing/integrations/dwolla/return.rb +38 -0
  134. data/lib/active_merchant/billing/integrations/e_payment_plans.rb +48 -0
  135. data/lib/active_merchant/billing/integrations/e_payment_plans/helper.rb +34 -0
  136. data/lib/active_merchant/billing/integrations/e_payment_plans/notification.rb +84 -0
  137. data/lib/active_merchant/billing/integrations/gestpay.rb +25 -0
  138. data/lib/active_merchant/billing/integrations/gestpay/common.rb +42 -0
  139. data/lib/active_merchant/billing/integrations/gestpay/helper.rb +70 -0
  140. data/lib/active_merchant/billing/integrations/gestpay/notification.rb +85 -0
  141. data/lib/active_merchant/billing/integrations/gestpay/return.rb +10 -0
  142. data/lib/active_merchant/billing/integrations/helper.rb +96 -0
  143. data/lib/active_merchant/billing/integrations/hi_trust.rb +27 -0
  144. data/lib/active_merchant/billing/integrations/hi_trust/helper.rb +58 -0
  145. data/lib/active_merchant/billing/integrations/hi_trust/notification.rb +59 -0
  146. data/lib/active_merchant/billing/integrations/hi_trust/return.rb +67 -0
  147. data/lib/active_merchant/billing/integrations/moneybookers.rb +26 -0
  148. data/lib/active_merchant/billing/integrations/moneybookers/helper.rb +59 -0
  149. data/lib/active_merchant/billing/integrations/moneybookers/notification.rb +129 -0
  150. data/lib/active_merchant/billing/integrations/nochex.rb +88 -0
  151. data/lib/active_merchant/billing/integrations/nochex/helper.rb +68 -0
  152. data/lib/active_merchant/billing/integrations/nochex/notification.rb +94 -0
  153. data/lib/active_merchant/billing/integrations/nochex/return.rb +10 -0
  154. data/lib/active_merchant/billing/integrations/notification.rb +62 -0
  155. data/lib/active_merchant/billing/integrations/payflow_link.rb +21 -0
  156. data/lib/active_merchant/billing/integrations/payflow_link/helper.rb +58 -0
  157. data/lib/active_merchant/billing/integrations/payflow_link/notification.rb +78 -0
  158. data/lib/active_merchant/billing/integrations/paypal.rb +39 -0
  159. data/lib/active_merchant/billing/integrations/paypal/helper.rb +119 -0
  160. data/lib/active_merchant/billing/integrations/paypal/notification.rb +154 -0
  161. data/lib/active_merchant/billing/integrations/paypal/return.rb +10 -0
  162. data/lib/active_merchant/billing/integrations/quickpay.rb +21 -0
  163. data/lib/active_merchant/billing/integrations/quickpay/helper.rb +72 -0
  164. data/lib/active_merchant/billing/integrations/quickpay/notification.rb +74 -0
  165. data/lib/active_merchant/billing/integrations/return.rb +42 -0
  166. data/lib/active_merchant/billing/integrations/sage_pay_form.rb +37 -0
  167. data/lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb +33 -0
  168. data/lib/active_merchant/billing/integrations/sage_pay_form/helper.rb +111 -0
  169. data/lib/active_merchant/billing/integrations/sage_pay_form/notification.rb +210 -0
  170. data/lib/active_merchant/billing/integrations/sage_pay_form/return.rb +31 -0
  171. data/lib/active_merchant/billing/integrations/two_checkout.rb +23 -0
  172. data/lib/active_merchant/billing/integrations/two_checkout/helper.rb +59 -0
  173. data/lib/active_merchant/billing/integrations/two_checkout/notification.rb +114 -0
  174. data/lib/active_merchant/billing/integrations/two_checkout/return.rb +17 -0
  175. data/lib/active_merchant/billing/integrations/valitor.rb +33 -0
  176. data/lib/active_merchant/billing/integrations/valitor/helper.rb +86 -0
  177. data/lib/active_merchant/billing/integrations/valitor/notification.rb +13 -0
  178. data/lib/active_merchant/billing/integrations/valitor/response_fields.rb +97 -0
  179. data/lib/active_merchant/billing/integrations/valitor/return.rb +13 -0
  180. data/lib/active_merchant/billing/integrations/world_pay.rb +27 -0
  181. data/lib/active_merchant/billing/integrations/world_pay/helper.rb +100 -0
  182. data/lib/active_merchant/billing/integrations/world_pay/notification.rb +160 -0
  183. data/lib/active_merchant/billing/response.rb +32 -0
  184. data/lib/active_merchant/version.rb +3 -0
  185. data/lib/activemerchant.rb +1 -0
  186. data/lib/support/gateway_support.rb +58 -0
  187. data/lib/support/outbound_hosts.rb +25 -0
  188. metadata +335 -0
@@ -0,0 +1,304 @@
1
+ module ActiveMerchant
2
+ module Billing
3
+ #
4
+ # ActiveMerchant PSL Card Gateway
5
+ #
6
+ # Notes:
7
+ # -To be able to use the capture function, the IP address of the machine must be
8
+ # registered with PSL
9
+ # -ESALE_KEYED should only be used in situations where the cardholder perceives the
10
+ # transaction to be Internet-based, such as purchasing from a web site/on-line store.
11
+ # If the Internet is used purely for the transport of information from the merchant
12
+ # directly to the gateway then the appropriate cardholder present or not present message
13
+ # type should be used rather than the ‘E’ equivalent.
14
+ # -The CV2 / AVS policies are set up with the account settings when signing up for an account
15
+ class PslCardGateway < Gateway
16
+ self.money_format = :cents
17
+ self.default_currency = 'GBP'
18
+
19
+ self.supported_countries = ['GB']
20
+ # Visa Credit, Visa Debit, Mastercard, Maestro, Solo, Electron,
21
+ # American Express, Diners Club, JCB, International Maestro,
22
+ # Style, Clydesdale Financial Services, Other
23
+
24
+ self.supported_cardtypes = [ :visa, :master, :american_express, :diners_club, :jcb, :switch, :solo, :maestro ]
25
+ self.homepage_url = 'http://www.paymentsolutionsltd.com/'
26
+ self.display_name = 'PSL Payment Solutions'
27
+
28
+ # Default ISO 3166 country code (GB)
29
+ cattr_accessor :location
30
+ self.location = 826
31
+
32
+ # PslCard server URL - The url is the same whether testing or live - use
33
+ # the test account when testing...
34
+ URL = 'https://pslcard3.paymentsolutionsltd.com/secure/transact.asp?'
35
+
36
+ # eCommerce sale transaction, details keyed by merchant or cardholder
37
+ MESSAGE_TYPE = 'ESALE_KEYED'
38
+
39
+ # The type of response that we want to get from PSL, options are HTML, XML or REDIRECT
40
+ RESPONSE_ACTION = 'HTML'
41
+
42
+ # Currency Codes
43
+ CURRENCY_CODES = {
44
+ 'AUD' => 036,
45
+ 'GBP' => 826,
46
+ 'USD' => 840
47
+ }
48
+
49
+ #The terminal used - only for swipe transactions, so hard coded to 32 for online
50
+ EMV_TERMINAL_TYPE = 32
51
+
52
+ #Different Dispatch types
53
+ DISPATCH_LATER = 'LATER'
54
+ DISPATCH_NOW = 'NOW'
55
+
56
+ # Return codes
57
+ APPROVED = '00'
58
+
59
+ #Nominal amount to authorize for a 'dispatch later' type
60
+ #The nominal amount is held straight away, when the goods are ready
61
+ #to be dispatched, PSL is informed and the full amount is the
62
+ #taken.
63
+ NOMINAL_AMOUNT = 101
64
+
65
+ AVS_CODE = {
66
+ "ALL MATCH" => 'Y',
67
+ "SECURITY CODE MATCH ONLY" => 'N',
68
+ "ADDRESS MATCH ONLY" => 'Y',
69
+ "NO DATA MATCHES" => 'N',
70
+ "DATA NOT CHECKED" => 'R',
71
+ "SECURITY CHECKS NOT SUPPORTED" => 'X'
72
+ }
73
+
74
+ CVV_CODE = {
75
+ "ALL MATCH" => 'M',
76
+ "SECURITY CODE MATCH ONLY" => 'M',
77
+ "ADDRESS MATCH ONLY" => 'N',
78
+ "NO DATA MATCHES" => 'N',
79
+ "DATA NOT CHECKED" => 'P',
80
+ "SECURITY CHECKS NOT SUPPORTED" => 'X'
81
+ }
82
+
83
+ # Create a new PslCardGateway
84
+ #
85
+ # The gateway requires that a valid :login be passed in the options hash
86
+ #
87
+ # Paramaters:
88
+ # -options:
89
+ # :login - the PslCard account login (required)
90
+ def initialize(options = {})
91
+ requires!(options, :login)
92
+
93
+ @options = options
94
+ super
95
+ end
96
+
97
+ # Purchase the item straight away
98
+ #
99
+ # Parameters:
100
+ # -money: Amount to be charged as an Integer value in cents
101
+ # -authorization: the PSL cross reference from the previous authorization
102
+ # -options:
103
+ #
104
+ # Returns:
105
+ # -ActiveRecord::Billing::Response object
106
+ #
107
+ def purchase(money, credit_card, options = {})
108
+ post = {}
109
+
110
+ add_amount(post, money, DISPATCH_NOW, options)
111
+ add_credit_card(post, credit_card)
112
+ add_address(post, options)
113
+ add_invoice(post, options)
114
+ add_purchase_details(post)
115
+
116
+ commit(post)
117
+ end
118
+
119
+ # Authorize the transaction
120
+ #
121
+ # Reserves the funds on the customer's credit card, but does not
122
+ # charge the card.
123
+ #
124
+ # This implementation does not authorize the full amount, rather it checks that the full amount
125
+ # is available and only 'reserves' the nominal amount (currently a pound and a penny)
126
+ #
127
+ # Parameters:
128
+ # -money: Amount to be charged as an Integer value in cents
129
+ # -authorization: the PSL cross reference from the previous authorization
130
+ # -options:
131
+ #
132
+ # Returns:
133
+ # -ActiveRecord::Billing::Response object
134
+ #
135
+ def authorize(money, credit_card, options = {})
136
+ post = {}
137
+
138
+ add_amount(post, money, DISPATCH_LATER, options)
139
+ add_credit_card(post, credit_card)
140
+ add_address(post, options)
141
+ add_invoice(post, options)
142
+ add_purchase_details(post)
143
+
144
+ commit(post)
145
+ end
146
+
147
+ # Post an authorization.
148
+ #
149
+ # Captures the funds from an authorized transaction.
150
+ #
151
+ # Parameters:
152
+ # -money: Amount to be charged as an Integer value in cents
153
+ # -authorization: The PSL Cross Reference
154
+ # -options:
155
+ #
156
+ # Returns:
157
+ # -ActiveRecord::Billing::Response object
158
+ #
159
+ def capture(money, authorization, options = {})
160
+ post = {}
161
+
162
+ add_amount(post, money, DISPATCH_NOW, options)
163
+ add_reference(post, authorization)
164
+ add_purchase_details(post)
165
+
166
+ commit(post)
167
+ end
168
+
169
+ private
170
+
171
+ def add_credit_card(post, credit_card)
172
+ post[:QAName] = credit_card.name
173
+ post[:CardNumber] = credit_card.number
174
+ post[:EMVTerminalType] = EMV_TERMINAL_TYPE
175
+ post[:ExpMonth] = credit_card.month
176
+ post[:ExpYear] = credit_card.year
177
+
178
+ if requires_start_date_or_issue_number?(credit_card)
179
+ post[:IssueNumber] = credit_card.issue_number unless credit_card.issue_number.blank?
180
+ post[:StartMonth] = credit_card.start_month unless credit_card.start_month.blank?
181
+ post[:StartYear] = credit_card.start_year unless credit_card.start_year.blank?
182
+ end
183
+
184
+ # CV2 check
185
+ post[:AVSCV2Check] = credit_card.verification_value? ? 'YES' : 'NO'
186
+ post[:CV2] = credit_card.verification_value if credit_card.verification_value?
187
+ end
188
+
189
+ def add_address(post, options)
190
+ address = options[:billing_address] || options[:address]
191
+ return if address.nil?
192
+
193
+ post[:QAAddress] = [:address1, :address2, :city, :state].collect{|a| address[a]}.reject{|a| a.blank?}.join(' ')
194
+ post[:QAPostcode] = address[:zip]
195
+ end
196
+
197
+ def add_invoice(post, options)
198
+ post[:MerchantName] = options[:merchant] || 'Merchant Name' # May use this as the order_id field
199
+ post[:OrderID] = options[:order_id] unless options[:order_id].blank?
200
+ end
201
+
202
+ def add_reference(post, authorization)
203
+ post[:CrossReference] = authorization
204
+ end
205
+
206
+ def add_amount(post, money, dispatch_type, options)
207
+ post[:CurrencyCode] = currency_code(options[:currency] || currency(money))
208
+
209
+ if dispatch_type == DISPATCH_LATER
210
+ post[:amount] = amount(NOMINAL_AMOUNT)
211
+ post[:DispatchLaterAmount] = amount(money)
212
+ else
213
+ post[:amount] = amount(money)
214
+ end
215
+
216
+ post[:Dispatch] = dispatch_type
217
+ end
218
+
219
+ def add_purchase_details(post)
220
+ post[:EchoAmount] = 'YES'
221
+ post[:SCBI] = 'YES' # Return information about the transaction
222
+ post[:MessageType] = MESSAGE_TYPE
223
+ end
224
+
225
+ # Get the currency code for the passed money object
226
+ #
227
+ # The money class stores the currency as an ISO 4217:2001 Alphanumeric,
228
+ # however PSL requires the ISO 4217:2001 Numeric code.
229
+ #
230
+ # Parameters:
231
+ # -money: Integer value in cents
232
+ #
233
+ # Returns:
234
+ # -the ISO 4217:2001 Numberic currency code
235
+ #
236
+ def currency_code(currency)
237
+ CURRENCY_CODES[currency]
238
+ end
239
+
240
+ # Parse the PSL response and create a Response object
241
+ #
242
+ # Parameters:
243
+ # -body: The response string returned from PSL, Formatted:
244
+ # Key=value&key=value...
245
+ #
246
+ # Returns:
247
+ # -a hash with all of the values returned in the PSL response
248
+ #
249
+ def parse(body)
250
+
251
+ fields = {}
252
+ for line in body.split('&')
253
+ key, value = *line.scan( %r{^(\w+)\=(.*)$} ).flatten
254
+ fields[key] = CGI.unescape(value)
255
+ end
256
+ fields.symbolize_keys
257
+ end
258
+
259
+ # Send the passed data to PSL for processing
260
+ #
261
+ # Parameters:
262
+ # -request: The data that is to be sent to PSL
263
+ #
264
+ # Returns:
265
+ # - ActiveMerchant::Billing::Response object
266
+ #
267
+ def commit(request)
268
+ response = parse( ssl_post(URL, post_data(request)) )
269
+
270
+ Response.new(response[:ResponseCode] == APPROVED, response[:Message], response,
271
+ :test => test?,
272
+ :authorization => response[:CrossReference],
273
+ :cvv_result => CVV_CODE[response[:AVSCV2Check]],
274
+ :avs_result => { :code => AVS_CODE[response[:AVSCV2Check]] }
275
+ )
276
+ end
277
+
278
+ # Put the passed data into a format that can be submitted to PSL
279
+ # Key=Value&Key=Value...
280
+ #
281
+ # Any ampersands and equal signs are removed from the data being posted
282
+ # as PSL puts them back into the response string which then cannot be parsed.
283
+ # This is after escaping before sending the request to PSL - this is a work
284
+ # around for the time being
285
+ #
286
+ # Parameters:
287
+ # -post: Hash of all the data to be sent
288
+ #
289
+ # Returns:
290
+ # -String: the data to be sent
291
+ #
292
+ def post_data(post)
293
+ post[:CountryCode] = self.location
294
+ post[:MerchantID] = @options[:login]
295
+ post[:ValidityID] = @options[:password]
296
+ post[:ResponseAction] = RESPONSE_ACTION
297
+
298
+ post.collect { |key, value|
299
+ "#{key}=#{CGI.escape(value.to_s.tr('&=', ' '))}"
300
+ }.join("&")
301
+ end
302
+ end
303
+ end
304
+ end
@@ -0,0 +1,297 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ class QbmsGateway < Gateway
4
+ API_VERSION = '4.0'
5
+
6
+ class_attribute :test_url, :live_url
7
+
8
+ self.test_url = "https://webmerchantaccount.ptc.quickbooks.com/j/AppGateway"
9
+ self.live_url = "https://webmerchantaccount.quickbooks.com/j/AppGateway"
10
+
11
+ self.homepage_url = 'http://payments.intuit.com/'
12
+ self.display_name = 'QuickBooks Merchant Services'
13
+ self.default_currency = 'USD'
14
+ self.supported_cardtypes = [ :visa, :master, :discover, :american_express, :diners_club, :jcb ]
15
+ self.supported_countries = [ 'US' ]
16
+
17
+ TYPES = {
18
+ :authorize => 'CustomerCreditCardAuth',
19
+ :capture => 'CustomerCreditCardCapture',
20
+ :purchase => 'CustomerCreditCardCharge',
21
+ :refund => 'CustomerCreditCardTxnVoidOrRefund',
22
+ :void => 'CustomerCreditCardTxnVoid',
23
+ :query => 'MerchantAccountQuery',
24
+ }
25
+
26
+ # Creates a new QbmsGateway
27
+ #
28
+ # The gateway requires that a valid app id, app login, and ticket be passed
29
+ # in the +options+ hash.
30
+ #
31
+ # ==== Options
32
+ #
33
+ # * <tt>:login</tt> -- The App Login (REQUIRED)
34
+ # * <tt>:ticket</tt> -- The Connection Ticket. (REQUIRED)
35
+ # * <tt>:pem</tt> -- The PEM-encoded SSL client key and certificate. (REQUIRED)
36
+ # * <tt>:test</tt> -- +true+ or +false+. If true, perform transactions against the test server.
37
+ # Otherwise, perform transactions against the production server.
38
+ #
39
+ def initialize(options = {})
40
+ requires!(options, :login, :ticket)
41
+ test_mode = options[:test] || false
42
+ @options = options
43
+ super
44
+ end
45
+
46
+ # Performs an authorization, which reserves the funds on the customer's credit card, but does not
47
+ # charge the card.
48
+ #
49
+ # ==== Parameters
50
+ #
51
+ # * <tt>money</tt> -- The amount to be authorized as an Integer value in cents.
52
+ # * <tt>creditcard</tt> -- The CreditCard details for the transaction.
53
+ # * <tt>options</tt> -- A hash of optional parameters.
54
+ #
55
+ def authorize(money, creditcard, options = {})
56
+ commit(:authorize, money, options.merge(:credit_card => creditcard))
57
+ end
58
+
59
+ # Perform a purchase, which is essentially an authorization and capture in a single operation.
60
+ #
61
+ # ==== Parameters
62
+ #
63
+ # * <tt>money</tt> -- The amount to be purchased as an Integer value in cents.
64
+ # * <tt>creditcard</tt> -- The CreditCard details for the transaction.
65
+ # * <tt>options</tt> -- A hash of optional parameters.
66
+ #
67
+ def purchase(money, creditcard, options = {})
68
+ commit(:purchase, money, options.merge(:credit_card => creditcard))
69
+ end
70
+
71
+ # Captures the funds from an authorized transaction.
72
+ #
73
+ # ==== Parameters
74
+ #
75
+ # * <tt>money</tt> -- The amount to be captured as an Integer value in cents.
76
+ # * <tt>authorization</tt> -- The authorization returned from the previous authorize request.
77
+ #
78
+ def capture(money, authorization, options = {})
79
+ commit(:capture, money, options.merge(:transaction_id => authorization))
80
+ end
81
+
82
+ # Void a previous transaction
83
+ #
84
+ # ==== Parameters
85
+ #
86
+ # * <tt>authorization</tt> - The authorization returned from the previous authorize request.
87
+ #
88
+ def void(authorization, options = {})
89
+ commit(:void, nil, options.merge(:transaction_id => authorization))
90
+ end
91
+
92
+ # Credit an account.
93
+ #
94
+ # This transaction is also referred to as a Refund and indicates to the gateway that
95
+ # money should flow from the merchant to the customer.
96
+ #
97
+ # ==== Parameters
98
+ #
99
+ # * <tt>money</tt> -- The amount to be credited to the customer as an Integer value in cents.
100
+ # * <tt>identification</tt> -- The ID of the original transaction against which the credit is being issued.
101
+ # * <tt>options</tt> -- A hash of parameters.
102
+ #
103
+ #
104
+ def credit(money, identification, options = {})
105
+ deprecated CREDIT_DEPRECATION_MESSAGE
106
+ refund(money, identification, options = {})
107
+ end
108
+
109
+ def refund(money, identification, options = {})
110
+ commit(:refund, money, options.merge(:transaction_id => identification))
111
+ end
112
+
113
+ # Query the merchant account status
114
+ def query
115
+ commit(:query, nil, {})
116
+ end
117
+
118
+ def test?
119
+ @options[:test] || super
120
+ end
121
+
122
+ private
123
+
124
+ def hosted?
125
+ @options[:pem]
126
+ end
127
+
128
+ def commit(action, money, parameters)
129
+ url = test? ? self.test_url : self.live_url
130
+
131
+ type = TYPES[action]
132
+ parameters[:trans_request_id] ||= SecureRandom.hex(10)
133
+
134
+ req = build_request(type, money, parameters)
135
+ data = ssl_post(url, req, "Content-Type" => "application/x-qbmsxml")
136
+ response = parse(type, data)
137
+ message = (response[:status_message] || '').strip
138
+
139
+ Response.new(success?(response), message, response,
140
+ :test => test?,
141
+ :authorization => response[:credit_card_trans_id],
142
+ :fraud_review => fraud_review?(response),
143
+ :avs_result => { :code => avs_result(response) },
144
+ :cvv_result => cvv_result(response)
145
+ )
146
+ end
147
+
148
+ def success?(response)
149
+ response[:status_code] == 0
150
+ end
151
+
152
+ def fraud_review?(response)
153
+ [10100, 10101].member? response[:status_code]
154
+ end
155
+
156
+ def parse(type, body)
157
+ xml = REXML::Document.new(body)
158
+
159
+ signon = REXML::XPath.first(xml, "//SignonMsgsRs/#{hosted? ? 'SignonAppCertRs' : 'SignonDesktopRs'}")
160
+ status_code = signon.attributes["statusCode"].to_i
161
+
162
+ if status_code != 0
163
+ return {
164
+ :status_code => status_code,
165
+ :status_message => signon.attributes["statusMessage"],
166
+ }
167
+ end
168
+
169
+ response = REXML::XPath.first(xml, "//QBMSXMLMsgsRs/#{type}Rs")
170
+
171
+ results = {
172
+ :status_code => response.attributes["statusCode"].to_i,
173
+ :status_message => response.attributes["statusMessage"],
174
+ }
175
+
176
+ response.elements.each do |e|
177
+ name = e.name.underscore.to_sym
178
+ value = e.text()
179
+
180
+ if old_value = results[name]
181
+ results[name] = [old_value] if !old_value.kind_of?(Array)
182
+ results[name] << value
183
+ else
184
+ results[name] = value
185
+ end
186
+ end
187
+
188
+ results
189
+ end
190
+
191
+ def build_request(type, money, parameters = {})
192
+ xml = Builder::XmlMarkup.new(:indent => 0)
193
+
194
+ xml.instruct!(:xml, :version => '1.0', :encoding => 'utf-8')
195
+ xml.instruct!(:qbmsxml, :version => API_VERSION)
196
+
197
+ xml.tag!("QBMSXML") do
198
+ xml.tag!("SignonMsgsRq") do
199
+ xml.tag!(hosted? ? "SignonAppCertRq" : "SignonDesktopRq") do
200
+ xml.tag!("ClientDateTime", Time.now.xmlschema)
201
+ xml.tag!("ApplicationLogin", @options[:login])
202
+ xml.tag!("ConnectionTicket", @options[:ticket])
203
+ end
204
+ end
205
+
206
+ xml.tag!("QBMSXMLMsgsRq") do
207
+ xml.tag!("#{type}Rq") do
208
+ method("build_#{type}").call(xml, money, parameters)
209
+ end
210
+ end
211
+ end
212
+
213
+ xml.target!
214
+ end
215
+
216
+ def build_CustomerCreditCardAuth(xml, money, parameters)
217
+ cc = parameters[:credit_card]
218
+ name = "#{cc.first_name} #{cc.last_name}"[0...30]
219
+
220
+ xml.tag!("TransRequestID", parameters[:trans_request_id])
221
+ xml.tag!("CreditCardNumber", cc.number)
222
+ xml.tag!("ExpirationMonth", cc.month)
223
+ xml.tag!("ExpirationYear", cc.year)
224
+ xml.tag!("IsECommerce", "true")
225
+ xml.tag!("Amount", amount(money))
226
+ xml.tag!("NameOnCard", name)
227
+ add_address(xml, parameters)
228
+ xml.tag!("CardSecurityCode", cc.verification_value) if cc.verification_value?
229
+ end
230
+
231
+ def build_CustomerCreditCardCapture(xml, money, parameters)
232
+ xml.tag!("TransRequestID", parameters[:trans_request_id])
233
+ xml.tag!("CreditCardTransID", parameters[:transaction_id])
234
+ xml.tag!("Amount", amount(money))
235
+ end
236
+
237
+ def build_CustomerCreditCardCharge(xml, money, parameters)
238
+ cc = parameters[:credit_card]
239
+ name = "#{cc.first_name} #{cc.last_name}"[0...30]
240
+
241
+ xml.tag!("TransRequestID", parameters[:trans_request_id])
242
+ xml.tag!("CreditCardNumber", cc.number)
243
+ xml.tag!("ExpirationMonth", cc.month)
244
+ xml.tag!("ExpirationYear", cc.year)
245
+ xml.tag!("IsECommerce", "true")
246
+ xml.tag!("Amount", amount(money))
247
+ xml.tag!("NameOnCard", name)
248
+ add_address(xml, parameters)
249
+ xml.tag!("CardSecurityCode", cc.verification_value) if cc.verification_value?
250
+ end
251
+
252
+ def build_CustomerCreditCardTxnVoidOrRefund(xml, money, parameters)
253
+ xml.tag!("TransRequestID", parameters[:trans_request_id])
254
+ xml.tag!("CreditCardTransID", parameters[:transaction_id])
255
+ xml.tag!("Amount", amount(money))
256
+ end
257
+
258
+ def build_CustomerCreditCardTxnVoid(xml, money, parameters)
259
+ xml.tag!("TransRequestID", parameters[:trans_request_id])
260
+ xml.tag!("CreditCardTransID", parameters[:transaction_id])
261
+ end
262
+
263
+ # Called reflectively by build_request
264
+ def build_MerchantAccountQuery(xml, money, parameters)
265
+ end
266
+
267
+ def add_address(xml, parameters)
268
+ if address = parameters[:billing_address] || parameters[:address]
269
+ xml.tag!("CreditCardAddress", address[:address1][0...30])
270
+ xml.tag!("CreditCardPostalCode", address[:zip][0...9])
271
+ end
272
+ end
273
+
274
+ def cvv_result(response)
275
+ case response[:card_security_code_match]
276
+ when "Pass" then 'M'
277
+ when "Fail" then 'N'
278
+ when "NotAvailable" then 'P'
279
+ end
280
+ end
281
+
282
+ def avs_result(response)
283
+ case "#{response[:avs_street]}|#{response[:avs_zip]}"
284
+ when "Pass|Pass" then "D"
285
+ when "Pass|Fail" then "A"
286
+ when "Pass|NotAvailable" then "B"
287
+ when "Fail|Pass" then "Z"
288
+ when "Fail|Fail" then "C"
289
+ when "Fail|NotAvailable" then "N"
290
+ when "NotAvailable|Pass" then "P"
291
+ when "NotAvailable|Fail" then "N"
292
+ when "NotAvailable|NotAvailable" then "U"
293
+ end
294
+ end
295
+ end
296
+ end
297
+ end