start_activemerchant 1.50.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (218) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG +1769 -0
  3. data/CONTRIBUTORS +540 -0
  4. data/MIT-LICENSE +20 -0
  5. data/README.md +226 -0
  6. data/lib/active_merchant.rb +67 -0
  7. data/lib/active_merchant/billing.rb +15 -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 +404 -0
  14. data/lib/active_merchant/billing/credit_card_formatting.rb +24 -0
  15. data/lib/active_merchant/billing/credit_card_methods.rb +195 -0
  16. data/lib/active_merchant/billing/cvv_result.rb +38 -0
  17. data/lib/active_merchant/billing/gateway.rb +291 -0
  18. data/lib/active_merchant/billing/gateways.rb +14 -0
  19. data/lib/active_merchant/billing/gateways/allied_wallet.rb +203 -0
  20. data/lib/active_merchant/billing/gateways/app55.rb +176 -0
  21. data/lib/active_merchant/billing/gateways/authorize_net.rb +510 -0
  22. data/lib/active_merchant/billing/gateways/authorize_net_arb.rb +417 -0
  23. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +976 -0
  24. data/lib/active_merchant/billing/gateways/axcessms.rb +181 -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 +192 -0
  32. data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +389 -0
  33. data/lib/active_merchant/billing/gateways/beanstream_interac.rb +58 -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 +211 -0
  37. data/lib/active_merchant/billing/gateways/bpoint.rb +277 -0
  38. data/lib/active_merchant/billing/gateways/braintree.rb +19 -0
  39. data/lib/active_merchant/billing/gateways/braintree/braintree_common.rb +9 -0
  40. data/lib/active_merchant/billing/gateways/braintree_blue.rb +574 -0
  41. data/lib/active_merchant/billing/gateways/braintree_orange.rb +20 -0
  42. data/lib/active_merchant/billing/gateways/bridge_pay.rb +189 -0
  43. data/lib/active_merchant/billing/gateways/card_save.rb +23 -0
  44. data/lib/active_merchant/billing/gateways/card_stream.rb +238 -0
  45. data/lib/active_merchant/billing/gateways/cashnet.rb +202 -0
  46. data/lib/active_merchant/billing/gateways/cc5.rb +201 -0
  47. data/lib/active_merchant/billing/gateways/cecabank.rb +229 -0
  48. data/lib/active_merchant/billing/gateways/cenpos.rb +262 -0
  49. data/lib/active_merchant/billing/gateways/certo_direct.rb +278 -0
  50. data/lib/active_merchant/billing/gateways/checkout.rb +216 -0
  51. data/lib/active_merchant/billing/gateways/checkout_v2.rb +200 -0
  52. data/lib/active_merchant/billing/gateways/commercegate.rb +143 -0
  53. data/lib/active_merchant/billing/gateways/conekta.rb +210 -0
  54. data/lib/active_merchant/billing/gateways/cyber_source.rb +720 -0
  55. data/lib/active_merchant/billing/gateways/data_cash.rb +600 -0
  56. data/lib/active_merchant/billing/gateways/dibs.rb +206 -0
  57. data/lib/active_merchant/billing/gateways/efsnet.rb +219 -0
  58. data/lib/active_merchant/billing/gateways/elavon.rb +348 -0
  59. data/lib/active_merchant/billing/gateways/epay.rb +274 -0
  60. data/lib/active_merchant/billing/gateways/evo_ca.rb +308 -0
  61. data/lib/active_merchant/billing/gateways/eway.rb +214 -0
  62. data/lib/active_merchant/billing/gateways/eway_managed.rb +291 -0
  63. data/lib/active_merchant/billing/gateways/eway_rapid.rb +522 -0
  64. data/lib/active_merchant/billing/gateways/exact.rb +227 -0
  65. data/lib/active_merchant/billing/gateways/ezic.rb +206 -0
  66. data/lib/active_merchant/billing/gateways/fat_zebra.rb +213 -0
  67. data/lib/active_merchant/billing/gateways/federated_canada.rb +160 -0
  68. data/lib/active_merchant/billing/gateways/finansbank.rb +23 -0
  69. data/lib/active_merchant/billing/gateways/first_giving.rb +143 -0
  70. data/lib/active_merchant/billing/gateways/first_pay.rb +160 -0
  71. data/lib/active_merchant/billing/gateways/firstdata_e4.rb +413 -0
  72. data/lib/active_merchant/billing/gateways/flo2cash.rb +215 -0
  73. data/lib/active_merchant/billing/gateways/flo2cash_simple.rb +20 -0
  74. data/lib/active_merchant/billing/gateways/garanti.rb +261 -0
  75. data/lib/active_merchant/billing/gateways/global_transport.rb +179 -0
  76. data/lib/active_merchant/billing/gateways/hdfc.rb +207 -0
  77. data/lib/active_merchant/billing/gateways/hps.rb +287 -0
  78. data/lib/active_merchant/billing/gateways/iats_payments.rb +277 -0
  79. data/lib/active_merchant/billing/gateways/ideal/ideal_base.rb +246 -0
  80. data/lib/active_merchant/billing/gateways/ideal/ideal_rabobank.pem +13 -0
  81. data/lib/active_merchant/billing/gateways/ideal/ideal_response.rb +29 -0
  82. data/lib/active_merchant/billing/gateways/ideal_rabobank.rb +66 -0
  83. data/lib/active_merchant/billing/gateways/inspire.rb +219 -0
  84. data/lib/active_merchant/billing/gateways/instapay.rb +163 -0
  85. data/lib/active_merchant/billing/gateways/ipp.rb +175 -0
  86. data/lib/active_merchant/billing/gateways/iridium.rb +457 -0
  87. data/lib/active_merchant/billing/gateways/itransact.rb +448 -0
  88. data/lib/active_merchant/billing/gateways/jetpay.rb +275 -0
  89. data/lib/active_merchant/billing/gateways/linkpoint.rb +438 -0
  90. data/lib/active_merchant/billing/gateways/litle.rb +345 -0
  91. data/lib/active_merchant/billing/gateways/maxipago.rb +197 -0
  92. data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +170 -0
  93. data/lib/active_merchant/billing/gateways/merchant_one.rb +114 -0
  94. data/lib/active_merchant/billing/gateways/merchant_partners.rb +245 -0
  95. data/lib/active_merchant/billing/gateways/merchant_ware.rb +319 -0
  96. data/lib/active_merchant/billing/gateways/merchant_ware_version_four.rb +268 -0
  97. data/lib/active_merchant/billing/gateways/merchant_warrior.rb +195 -0
  98. data/lib/active_merchant/billing/gateways/mercury.rb +326 -0
  99. data/lib/active_merchant/billing/gateways/metrics_global.rb +303 -0
  100. data/lib/active_merchant/billing/gateways/migs.rb +280 -0
  101. data/lib/active_merchant/billing/gateways/migs/migs_codes.rb +100 -0
  102. data/lib/active_merchant/billing/gateways/modern_payments.rb +37 -0
  103. data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +219 -0
  104. data/lib/active_merchant/billing/gateways/monei.rb +307 -0
  105. data/lib/active_merchant/billing/gateways/moneris.rb +309 -0
  106. data/lib/active_merchant/billing/gateways/moneris_us.rb +298 -0
  107. data/lib/active_merchant/billing/gateways/money_movers.rb +152 -0
  108. data/lib/active_merchant/billing/gateways/nab_transact.rb +290 -0
  109. data/lib/active_merchant/billing/gateways/net_registry.rb +198 -0
  110. data/lib/active_merchant/billing/gateways/netaxept.rb +181 -0
  111. data/lib/active_merchant/billing/gateways/netbilling.rb +224 -0
  112. data/lib/active_merchant/billing/gateways/netpay.rb +223 -0
  113. data/lib/active_merchant/billing/gateways/network_merchants.rb +242 -0
  114. data/lib/active_merchant/billing/gateways/nmi.rb +256 -0
  115. data/lib/active_merchant/billing/gateways/ogone.rb +435 -0
  116. data/lib/active_merchant/billing/gateways/omise.rb +319 -0
  117. data/lib/active_merchant/billing/gateways/openpay.rb +194 -0
  118. data/lib/active_merchant/billing/gateways/optimal_payment.rb +314 -0
  119. data/lib/active_merchant/billing/gateways/orbital.rb +834 -0
  120. data/lib/active_merchant/billing/gateways/orbital/orbital_soft_descriptors.rb +47 -0
  121. data/lib/active_merchant/billing/gateways/pac_net_raven.rb +207 -0
  122. data/lib/active_merchant/billing/gateways/pago_facil.rb +122 -0
  123. data/lib/active_merchant/billing/gateways/pay_conex.rb +246 -0
  124. data/lib/active_merchant/billing/gateways/pay_gate_xml.rb +277 -0
  125. data/lib/active_merchant/billing/gateways/pay_hub.rb +213 -0
  126. data/lib/active_merchant/billing/gateways/pay_junction.rb +390 -0
  127. data/lib/active_merchant/billing/gateways/pay_secure.rb +112 -0
  128. data/lib/active_merchant/billing/gateways/paybox_direct.rb +188 -0
  129. data/lib/active_merchant/billing/gateways/payex.rb +412 -0
  130. data/lib/active_merchant/billing/gateways/payflow.rb +308 -0
  131. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +220 -0
  132. data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +39 -0
  133. data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +13 -0
  134. data/lib/active_merchant/billing/gateways/payflow_express.rb +224 -0
  135. data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +15 -0
  136. data/lib/active_merchant/billing/gateways/payflow_uk.rb +21 -0
  137. data/lib/active_merchant/billing/gateways/payment_express.rb +353 -0
  138. data/lib/active_merchant/billing/gateways/paymill.rb +282 -0
  139. data/lib/active_merchant/billing/gateways/paypal.rb +129 -0
  140. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +679 -0
  141. data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +65 -0
  142. data/lib/active_merchant/billing/gateways/paypal/paypal_recurring_api.rb +262 -0
  143. data/lib/active_merchant/billing/gateways/paypal_ca.rb +13 -0
  144. data/lib/active_merchant/billing/gateways/paypal_digital_goods.rb +44 -0
  145. data/lib/active_merchant/billing/gateways/paypal_express.rb +264 -0
  146. data/lib/active_merchant/billing/gateways/paypal_express_common.rb +30 -0
  147. data/lib/active_merchant/billing/gateways/payscout.rb +162 -0
  148. data/lib/active_merchant/billing/gateways/paystation.rb +199 -0
  149. data/lib/active_merchant/billing/gateways/payu_in.rb +247 -0
  150. data/lib/active_merchant/billing/gateways/payway.rb +207 -0
  151. data/lib/active_merchant/billing/gateways/pin.rb +207 -0
  152. data/lib/active_merchant/billing/gateways/plugnpay.rb +283 -0
  153. data/lib/active_merchant/billing/gateways/psigate.rb +216 -0
  154. data/lib/active_merchant/billing/gateways/psl_card.rb +303 -0
  155. data/lib/active_merchant/billing/gateways/qbms.rb +292 -0
  156. data/lib/active_merchant/billing/gateways/quantum.rb +276 -0
  157. data/lib/active_merchant/billing/gateways/quickbooks.rb +280 -0
  158. data/lib/active_merchant/billing/gateways/quickpay.rb +26 -0
  159. data/lib/active_merchant/billing/gateways/quickpay/quickpay_common.rb +188 -0
  160. data/lib/active_merchant/billing/gateways/quickpay/quickpay_v10.rb +240 -0
  161. data/lib/active_merchant/billing/gateways/quickpay/quickpay_v4to7.rb +227 -0
  162. data/lib/active_merchant/billing/gateways/qvalent.rb +179 -0
  163. data/lib/active_merchant/billing/gateways/realex.rb +298 -0
  164. data/lib/active_merchant/billing/gateways/redsys.rb +406 -0
  165. data/lib/active_merchant/billing/gateways/s5.rb +226 -0
  166. data/lib/active_merchant/billing/gateways/sage.rb +173 -0
  167. data/lib/active_merchant/billing/gateways/sage/sage_bankcard.rb +89 -0
  168. data/lib/active_merchant/billing/gateways/sage/sage_core.rb +115 -0
  169. data/lib/active_merchant/billing/gateways/sage/sage_vault.rb +149 -0
  170. data/lib/active_merchant/billing/gateways/sage/sage_virtual_check.rb +97 -0
  171. data/lib/active_merchant/billing/gateways/sage_pay.rb +399 -0
  172. data/lib/active_merchant/billing/gateways/sallie_mae.rb +143 -0
  173. data/lib/active_merchant/billing/gateways/secure_net.rb +263 -0
  174. data/lib/active_merchant/billing/gateways/secure_pay.rb +201 -0
  175. data/lib/active_merchant/billing/gateways/secure_pay_au.rb +281 -0
  176. data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +105 -0
  177. data/lib/active_merchant/billing/gateways/skip_jack.rb +451 -0
  178. data/lib/active_merchant/billing/gateways/smart_ps.rb +283 -0
  179. data/lib/active_merchant/billing/gateways/so_easy_pay.rb +194 -0
  180. data/lib/active_merchant/billing/gateways/spreedly_core.rb +247 -0
  181. data/lib/active_merchant/billing/gateways/stripe.rb +489 -0
  182. data/lib/active_merchant/billing/gateways/swipe_checkout.rb +157 -0
  183. data/lib/active_merchant/billing/gateways/tns.rb +227 -0
  184. data/lib/active_merchant/billing/gateways/trans_first.rb +126 -0
  185. data/lib/active_merchant/billing/gateways/transax.rb +23 -0
  186. data/lib/active_merchant/billing/gateways/transnational.rb +10 -0
  187. data/lib/active_merchant/billing/gateways/trust_commerce.rb +416 -0
  188. data/lib/active_merchant/billing/gateways/usa_epay.rb +25 -0
  189. data/lib/active_merchant/billing/gateways/usa_epay_advanced.rb +1516 -0
  190. data/lib/active_merchant/billing/gateways/usa_epay_transaction.rb +259 -0
  191. data/lib/active_merchant/billing/gateways/vanco.rb +280 -0
  192. data/lib/active_merchant/billing/gateways/verifi.rb +225 -0
  193. data/lib/active_merchant/billing/gateways/viaklix.rb +183 -0
  194. data/lib/active_merchant/billing/gateways/webpay.rb +97 -0
  195. data/lib/active_merchant/billing/gateways/wepay.rb +205 -0
  196. data/lib/active_merchant/billing/gateways/wirecard.rb +420 -0
  197. data/lib/active_merchant/billing/gateways/worldpay.rb +331 -0
  198. data/lib/active_merchant/billing/gateways/worldpay_online_payments.rb +204 -0
  199. data/lib/active_merchant/billing/gateways/worldpay_us.rb +181 -0
  200. data/lib/active_merchant/billing/model.rb +30 -0
  201. data/lib/active_merchant/billing/network_tokenization_credit_card.rb +24 -0
  202. data/lib/active_merchant/billing/payment_token.rb +21 -0
  203. data/lib/active_merchant/billing/rails.rb +3 -0
  204. data/lib/active_merchant/billing/response.rb +92 -0
  205. data/lib/active_merchant/connection.rb +172 -0
  206. data/lib/active_merchant/country.rb +332 -0
  207. data/lib/active_merchant/empty.rb +20 -0
  208. data/lib/active_merchant/errors.rb +35 -0
  209. data/lib/active_merchant/network_connection_retries.rb +79 -0
  210. data/lib/active_merchant/post_data.rb +24 -0
  211. data/lib/active_merchant/posts_data.rb +84 -0
  212. data/lib/active_merchant/version.rb +3 -0
  213. data/lib/activemerchant.rb +1 -0
  214. data/lib/certs/cacert.pem +3866 -0
  215. data/lib/support/gateway_support.rb +71 -0
  216. data/lib/support/outbound_hosts.rb +28 -0
  217. data/lib/support/ssl_verify.rb +93 -0
  218. metadata +387 -0
@@ -0,0 +1,216 @@
1
+ require 'rexml/document'
2
+
3
+ module ActiveMerchant #:nodoc:
4
+ module Billing #:nodoc:
5
+ # This class implements the Psigate gateway for the ActiveMerchant module.
6
+ #
7
+ # Modifications by Sean O'Hara ( sohara at sohara dot com )
8
+ #
9
+ # Usage for a PreAuth (authorize) is as follows:
10
+ #
11
+ # gateway = PsigateGateway.new(
12
+ # :login => 'teststore',
13
+ # :password => 'psigate1234'
14
+ # )
15
+ #
16
+ # creditcard = CreditCard.new(
17
+ # :number => '4242424242424242',
18
+ # :month => 8,
19
+ # :year => 2006,
20
+ # :first_name => 'Longbob',
21
+ # :last_name => 'Longsen'
22
+ # )
23
+ #
24
+ # twenty = 2000
25
+ # response = @gateway.authorize(twenty, creditcard,
26
+ # :order_id => 1234,
27
+ # :billing_address => {
28
+ # :address1 => '123 fairweather Lane',
29
+ # :address2 => 'Apt B',
30
+ # :city => 'New York',
31
+ # :state => 'NY',
32
+ # :country => 'U.S.A.',
33
+ # :zip => '10010'
34
+ # },
35
+ # :email => 'jack@yahoo.com'
36
+ # )
37
+ class PsigateGateway < Gateway
38
+ self.test_url = 'https://dev.psigate.com:7989/Messenger/XMLMessenger'
39
+ self.live_url = 'https://secure.psigate.com:17934/Messenger/XMLMessenger'
40
+
41
+ self.supported_cardtypes = [:visa, :master, :american_express]
42
+ self.supported_countries = ['CA']
43
+ self.homepage_url = 'http://www.psigate.com/'
44
+ self.display_name = 'Psigate'
45
+
46
+ SUCCESS_MESSAGE = 'Success'
47
+ FAILURE_MESSAGE = 'The transaction was declined'
48
+
49
+ def initialize(options = {})
50
+ requires!(options, :login, :password)
51
+ super
52
+ end
53
+
54
+ def authorize(money, creditcard, options = {})
55
+ requires!(options, :order_id)
56
+ options[:CardAction] = "1"
57
+ commit(money, creditcard, options)
58
+ end
59
+
60
+ def purchase(money, creditcard, options = {})
61
+ requires!(options, :order_id)
62
+ options[:CardAction] = "0"
63
+ commit(money, creditcard, options)
64
+ end
65
+
66
+ def capture(money, authorization, options = {})
67
+ options[:CardAction] = "2"
68
+ options[:order_id], options[:trans_ref_number] = split_authorization(authorization)
69
+ commit(money, nil, options)
70
+ end
71
+
72
+ def credit(money, authorization, options = {})
73
+ ActiveMerchant.deprecated CREDIT_DEPRECATION_MESSAGE
74
+ refund(money, authorization, options)
75
+ end
76
+
77
+ def refund(money, authorization, options = {})
78
+ options[:CardAction] = "3"
79
+ options[:order_id], options[:trans_ref_number] = split_authorization(authorization)
80
+ commit(money, nil, options)
81
+ end
82
+
83
+ def void(authorization, options = {})
84
+ options[:CardAction] = "9"
85
+ options[:order_id], options[:trans_ref_number] = split_authorization(authorization)
86
+ commit(nil, nil, options)
87
+ end
88
+
89
+ private
90
+
91
+ def commit(money, creditcard, options = {})
92
+ response = parse(ssl_post(url, post_data(money, creditcard, options)))
93
+
94
+ Response.new(successful?(response), message_from(response), response,
95
+ :test => test?,
96
+ :authorization => build_authorization(response) ,
97
+ :avs_result => { :code => response[:avsresult] },
98
+ :cvv_result => response[:cardidresult]
99
+ )
100
+ end
101
+
102
+ def url
103
+ (test? ? self.test_url : self.live_url)
104
+ end
105
+
106
+ def successful?(response)
107
+ response[:approved] == "APPROVED"
108
+ end
109
+
110
+ def parse(xml)
111
+ response = {:message => "Global Error Receipt", :complete => false}
112
+
113
+ xml = REXML::Document.new(xml)
114
+ xml.elements.each('//Result/*') do |node|
115
+ response[node.name.downcase.to_sym] = normalize(node.text)
116
+ end unless xml.root.nil?
117
+
118
+ response
119
+ end
120
+
121
+ def post_data(money, creditcard, options)
122
+ xml = REXML::Document.new
123
+ xml << REXML::XMLDecl.new
124
+ root = xml.add_element("Order")
125
+
126
+ parameters(money, creditcard, options).each do |key, value|
127
+ root.add_element(key.to_s).text = value if value
128
+ end
129
+
130
+ xml.to_s
131
+ end
132
+
133
+ def parameters(money, creditcard, options = {})
134
+ params = {
135
+ # General order parameters
136
+ :StoreID => @options[:login],
137
+ :Passphrase => @options[:password],
138
+ :TestResult => options[:test_result],
139
+ :OrderID => options[:order_id],
140
+ :UserID => options[:user_id],
141
+ :Phone => options[:phone],
142
+ :Fax => options[:fax],
143
+ :Email => options[:email],
144
+ :TransRefNumber => options[:trans_ref_number],
145
+
146
+ # Credit Card parameters
147
+ :PaymentType => "CC",
148
+ :CardAction => options[:CardAction],
149
+
150
+ # Financial parameters
151
+ :CustomerIP => options[:ip],
152
+ :SubTotal => amount(money),
153
+ :Tax1 => options[:tax1],
154
+ :Tax2 => options[:tax2],
155
+ :ShippingTotal => options[:shipping_total],
156
+ }
157
+
158
+ if creditcard
159
+ exp_month = sprintf("%.2i", creditcard.month) unless creditcard.month.blank?
160
+ exp_year = creditcard.year.to_s[2,2] unless creditcard.year.blank?
161
+ card_id_code = (creditcard.verification_value.blank? ? nil : "1")
162
+
163
+ params.update(
164
+ :CardNumber => creditcard.number,
165
+ :CardExpMonth => exp_month,
166
+ :CardExpYear => exp_year,
167
+ :CardIDCode => card_id_code,
168
+ :CardIDNumber => creditcard.verification_value
169
+ )
170
+ end
171
+
172
+ if(address = (options[:billing_address] || options[:address]))
173
+ params[:Bname] = address[:name] || creditcard.name
174
+ params[:Baddress1] = address[:address1] unless address[:address1].blank?
175
+ params[:Baddress2] = address[:address2] unless address[:address2].blank?
176
+ params[:Bcity] = address[:city] unless address[:city].blank?
177
+ params[:Bprovince] = address[:state] unless address[:state].blank?
178
+ params[:Bpostalcode] = address[:zip] unless address[:zip].blank?
179
+ params[:Bcountry] = address[:country] unless address[:country].blank?
180
+ params[:Bcompany] = address[:company] unless address[:company].blank?
181
+ end
182
+
183
+ if address = options[:shipping_address]
184
+ params[:Sname] = address[:name] || creditcard.name
185
+ params[:Saddress1] = address[:address1] unless address[:address1].blank?
186
+ params[:Saddress2] = address[:address2] unless address[:address2].blank?
187
+ params[:Scity] = address[:city] unless address[:city].blank?
188
+ params[:Sprovince] = address[:state] unless address[:state].blank?
189
+ params[:Spostalcode] = address[:zip] unless address[:zip].blank?
190
+ params[:Scountry] = address[:country] unless address[:country].blank?
191
+ params[:Scompany] = address[:company] unless address[:company].blank?
192
+ end
193
+
194
+ params
195
+ end
196
+
197
+ def message_from(response)
198
+ if response[:approved] == "APPROVED"
199
+ return SUCCESS_MESSAGE
200
+ else
201
+ return FAILURE_MESSAGE if response[:errmsg].blank?
202
+ return response[:errmsg].gsub(/[^\w]/, ' ').split.join(" ").capitalize
203
+ end
204
+ end
205
+
206
+ def split_authorization(authorization)
207
+ order_id, trans_ref_number = authorization.split(';')
208
+ [order_id, trans_ref_number]
209
+ end
210
+
211
+ def build_authorization(response)
212
+ [response[:orderid], response[:transrefnumber]].join(";")
213
+ end
214
+ end
215
+ end
216
+ end
@@ -0,0 +1,303 @@
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 self.live_url - The url is the same whether testing or live - use
33
+ # the test account when testing...
34
+ self.live_url = self.test_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
+ super
94
+ end
95
+
96
+ # Purchase the item straight away
97
+ #
98
+ # Parameters:
99
+ # -money: Amount to be charged as an Integer value in cents
100
+ # -authorization: the PSL cross reference from the previous authorization
101
+ # -options:
102
+ #
103
+ # Returns:
104
+ # -ActiveRecord::Billing::Response object
105
+ #
106
+ def purchase(money, credit_card, options = {})
107
+ post = {}
108
+
109
+ add_amount(post, money, DISPATCH_NOW, options)
110
+ add_credit_card(post, credit_card)
111
+ add_address(post, options)
112
+ add_invoice(post, options)
113
+ add_purchase_details(post)
114
+
115
+ commit(post)
116
+ end
117
+
118
+ # Authorize the transaction
119
+ #
120
+ # Reserves the funds on the customer's credit card, but does not
121
+ # charge the card.
122
+ #
123
+ # This implementation does not authorize the full amount, rather it checks that the full amount
124
+ # is available and only 'reserves' the nominal amount (currently a pound and a penny)
125
+ #
126
+ # Parameters:
127
+ # -money: Amount to be charged as an Integer value in cents
128
+ # -authorization: the PSL cross reference from the previous authorization
129
+ # -options:
130
+ #
131
+ # Returns:
132
+ # -ActiveRecord::Billing::Response object
133
+ #
134
+ def authorize(money, credit_card, options = {})
135
+ post = {}
136
+
137
+ add_amount(post, money, DISPATCH_LATER, options)
138
+ add_credit_card(post, credit_card)
139
+ add_address(post, options)
140
+ add_invoice(post, options)
141
+ add_purchase_details(post)
142
+
143
+ commit(post)
144
+ end
145
+
146
+ # Post an authorization.
147
+ #
148
+ # Captures the funds from an authorized transaction.
149
+ #
150
+ # Parameters:
151
+ # -money: Amount to be charged as an Integer value in cents
152
+ # -authorization: The PSL Cross Reference
153
+ # -options:
154
+ #
155
+ # Returns:
156
+ # -ActiveRecord::Billing::Response object
157
+ #
158
+ def capture(money, authorization, options = {})
159
+ post = {}
160
+
161
+ add_amount(post, money, DISPATCH_NOW, options)
162
+ add_reference(post, authorization)
163
+ add_purchase_details(post)
164
+
165
+ commit(post)
166
+ end
167
+
168
+ private
169
+
170
+ def add_credit_card(post, credit_card)
171
+ post[:QAName] = credit_card.name
172
+ post[:CardNumber] = credit_card.number
173
+ post[:EMVTerminalType] = EMV_TERMINAL_TYPE
174
+ post[:ExpMonth] = credit_card.month
175
+ post[:ExpYear] = credit_card.year
176
+
177
+ if requires_start_date_or_issue_number?(credit_card)
178
+ post[:IssueNumber] = credit_card.issue_number unless credit_card.issue_number.blank?
179
+ post[:StartMonth] = credit_card.start_month unless credit_card.start_month.blank?
180
+ post[:StartYear] = credit_card.start_year unless credit_card.start_year.blank?
181
+ end
182
+
183
+ # CV2 check
184
+ post[:AVSCV2Check] = credit_card.verification_value? ? 'YES' : 'NO'
185
+ post[:CV2] = credit_card.verification_value if credit_card.verification_value?
186
+ end
187
+
188
+ def add_address(post, options)
189
+ address = options[:billing_address] || options[:address]
190
+ return if address.nil?
191
+
192
+ post[:QAAddress] = [:address1, :address2, :city, :state].collect{|a| address[a]}.reject{|a| a.blank?}.join(' ')
193
+ post[:QAPostcode] = address[:zip]
194
+ end
195
+
196
+ def add_invoice(post, options)
197
+ post[:MerchantName] = options[:merchant] || 'Merchant Name' # May use this as the order_id field
198
+ post[:OrderID] = options[:order_id] unless options[:order_id].blank?
199
+ end
200
+
201
+ def add_reference(post, authorization)
202
+ post[:CrossReference] = authorization
203
+ end
204
+
205
+ def add_amount(post, money, dispatch_type, options)
206
+ post[:CurrencyCode] = currency_code(options[:currency] || currency(money))
207
+
208
+ if dispatch_type == DISPATCH_LATER
209
+ post[:amount] = amount(NOMINAL_AMOUNT)
210
+ post[:DispatchLaterAmount] = amount(money)
211
+ else
212
+ post[:amount] = amount(money)
213
+ end
214
+
215
+ post[:Dispatch] = dispatch_type
216
+ end
217
+
218
+ def add_purchase_details(post)
219
+ post[:EchoAmount] = 'YES'
220
+ post[:SCBI] = 'YES' # Return information about the transaction
221
+ post[:MessageType] = MESSAGE_TYPE
222
+ end
223
+
224
+ # Get the currency code for the passed money object
225
+ #
226
+ # The money class stores the currency as an ISO 4217:2001 Alphanumeric,
227
+ # however PSL requires the ISO 4217:2001 Numeric code.
228
+ #
229
+ # Parameters:
230
+ # -money: Integer value in cents
231
+ #
232
+ # Returns:
233
+ # -the ISO 4217:2001 Numberic currency code
234
+ #
235
+ def currency_code(currency)
236
+ CURRENCY_CODES[currency]
237
+ end
238
+
239
+ # Parse the PSL response and create a Response object
240
+ #
241
+ # Parameters:
242
+ # -body: The response string returned from PSL, Formatted:
243
+ # Key=value&key=value...
244
+ #
245
+ # Returns:
246
+ # -a hash with all of the values returned in the PSL response
247
+ #
248
+ def parse(body)
249
+
250
+ fields = {}
251
+ for line in body.split('&')
252
+ key, value = *line.scan( %r{^(\w+)\=(.*)$} ).flatten
253
+ fields[key] = CGI.unescape(value)
254
+ end
255
+ fields.symbolize_keys
256
+ end
257
+
258
+ # Send the passed data to PSL for processing
259
+ #
260
+ # Parameters:
261
+ # -request: The data that is to be sent to PSL
262
+ #
263
+ # Returns:
264
+ # - ActiveMerchant::Billing::Response object
265
+ #
266
+ def commit(request)
267
+ response = parse( ssl_post(self.live_url, post_data(request)) )
268
+
269
+ Response.new(response[:ResponseCode] == APPROVED, response[:Message], response,
270
+ :test => test?,
271
+ :authorization => response[:CrossReference],
272
+ :cvv_result => CVV_CODE[response[:AVSCV2Check]],
273
+ :avs_result => { :code => AVS_CODE[response[:AVSCV2Check]] }
274
+ )
275
+ end
276
+
277
+ # Put the passed data into a format that can be submitted to PSL
278
+ # Key=Value&Key=Value...
279
+ #
280
+ # Any ampersands and equal signs are removed from the data being posted
281
+ # as PSL puts them back into the response string which then cannot be parsed.
282
+ # This is after escaping before sending the request to PSL - this is a work
283
+ # around for the time being
284
+ #
285
+ # Parameters:
286
+ # -post: Hash of all the data to be sent
287
+ #
288
+ # Returns:
289
+ # -String: the data to be sent
290
+ #
291
+ def post_data(post)
292
+ post[:CountryCode] = self.location
293
+ post[:MerchantID] = @options[:login]
294
+ post[:ValidityID] = @options[:password]
295
+ post[:ResponseAction] = RESPONSE_ACTION
296
+
297
+ post.collect { |key, value|
298
+ "#{key}=#{CGI.escape(value.to_s.tr('&=', ' '))}"
299
+ }.join("&")
300
+ end
301
+ end
302
+ end
303
+ end