aktivemerchant 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
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,257 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ class GarantiGateway < Gateway
4
+ self.live_url = self.test_url = 'https://sanalposprov.garanti.com.tr/VPServlet'
5
+
6
+ # The countries the gateway supports merchants from as 2 digit ISO country codes
7
+ self.supported_countries = ['US','TR']
8
+
9
+ # The card types supported by the payment gateway
10
+ self.supported_cardtypes = [:visa, :master, :american_express, :discover]
11
+
12
+ # The homepage URL of the gateway
13
+ self.homepage_url = 'https://sanalposweb.garanti.com.tr'
14
+
15
+ # The name of the gateway
16
+ self.display_name = 'Garanti Sanal POS'
17
+
18
+ self.default_currency = 'TRL'
19
+
20
+ self.money_format = :cents
21
+
22
+ CURRENCY_CODES = {
23
+ 'YTL' => 949,
24
+ 'TRL' => 949,
25
+ 'TL' => 949,
26
+ 'USD' => 840,
27
+ 'EUR' => 978,
28
+ 'GBP' => 826,
29
+ 'JPY' => 392
30
+ }
31
+
32
+
33
+ def initialize(options = {})
34
+ requires!(options, :login, :password, :terminal_id, :merchant_id)
35
+ super
36
+ end
37
+
38
+ def purchase(money, credit_card, options = {})
39
+ options = options.merge(:gvp_order_type => "sales")
40
+ commit(money, build_sale_request(money, credit_card, options))
41
+ end
42
+
43
+ def authorize(money, credit_card, options = {})
44
+ options = options.merge(:gvp_order_type => "preauth")
45
+ commit(money, build_authorize_request(money, credit_card, options))
46
+ end
47
+
48
+ def capture(money, ref_id, options = {})
49
+ options = options.merge(:gvp_order_type => "postauth")
50
+ commit(money, build_capture_request(money, ref_id, options))
51
+ end
52
+
53
+ private
54
+
55
+ def security_data
56
+ rjusted_terminal_id = @options[:terminal_id].to_s.rjust(9, "0")
57
+ Digest::SHA1.hexdigest(@options[:password].to_s + rjusted_terminal_id).upcase
58
+ end
59
+
60
+ def generate_hash_data(order_id, terminal_id, credit_card_number, amount, security_data)
61
+ data = [order_id, terminal_id, credit_card_number, amount, security_data].join
62
+ Digest::SHA1.hexdigest(data).upcase
63
+ end
64
+
65
+ def build_xml_request(money, credit_card, options, &block)
66
+ card_number = credit_card.respond_to?(:number) ? credit_card.number : ''
67
+ hash_data = generate_hash_data(format_order_id(options[:order_id]), @options[:terminal_id], card_number, amount(money), security_data)
68
+
69
+ xml = Builder::XmlMarkup.new(:indent => 2)
70
+ xml.instruct! :xml, :version => "1.0", :encoding => "UTF-8"
71
+
72
+ xml.tag! 'GVPSRequest' do
73
+ xml.tag! 'Mode', test? ? 'TEST' : 'PROD'
74
+ xml.tag! 'Version', 'V0.01'
75
+ xml.tag! 'Terminal' do
76
+ xml.tag! 'ProvUserID', 'PROVAUT'
77
+ xml.tag! 'HashData', hash_data
78
+ xml.tag! 'UserID', @options[:login]
79
+ xml.tag! 'ID', @options[:terminal_id]
80
+ xml.tag! 'MerchantID', @options[:merchant_id]
81
+ end
82
+
83
+ if block_given?
84
+ yield xml
85
+ else
86
+ xml.target!
87
+ end
88
+ end
89
+ end
90
+
91
+ def build_sale_request(money, credit_card, options)
92
+ build_xml_request(money, credit_card, options) do |xml|
93
+ add_customer_data(xml, options)
94
+ add_order_data(xml, options) do
95
+ add_addresses(xml, options)
96
+ end
97
+ add_credit_card(xml, credit_card)
98
+ add_transaction_data(xml, money, options)
99
+
100
+ xml.target!
101
+ end
102
+ end
103
+
104
+ def build_authorize_request(money, credit_card, options)
105
+ build_xml_request(money, credit_card, options) do |xml|
106
+ add_customer_data(xml, options)
107
+ add_order_data(xml, options) do
108
+ add_addresses(xml, options)
109
+ end
110
+ add_credit_card(xml, credit_card)
111
+ add_transaction_data(xml, money, options)
112
+
113
+ xml.target!
114
+ end
115
+ end
116
+
117
+ def build_capture_request(money, ref_id, options)
118
+ options = options.merge(:order_id => ref_id)
119
+ build_xml_request(money, ref_id, options) do |xml|
120
+ add_customer_data(xml, options)
121
+ add_order_data(xml, options)
122
+ add_transaction_data(xml, money, options)
123
+
124
+ xml.target!
125
+ end
126
+ end
127
+
128
+ def add_customer_data(xml, options)
129
+ xml.tag! 'Customer' do
130
+ xml.tag! 'IPAddress', options[:ip] || '1.1.1.1'
131
+ xml.tag! 'EmailAddress', options[:email]
132
+ end
133
+ end
134
+
135
+ def add_order_data(xml, options, &block)
136
+ xml.tag! 'Order' do
137
+ xml.tag! 'OrderID', format_order_id(options[:order_id])
138
+ xml.tag! 'GroupID'
139
+
140
+ if block_given?
141
+ yield xml
142
+ end
143
+ end
144
+ end
145
+
146
+ def add_credit_card(xml, credit_card)
147
+ xml.tag! 'Card' do
148
+ xml.tag! 'Number', credit_card.number
149
+ xml.tag! 'ExpireDate', [format_exp(credit_card.month), format_exp(credit_card.year)].join
150
+ xml.tag! 'CVV2', credit_card.verification_value
151
+ end
152
+ end
153
+
154
+ def format_exp(value)
155
+ format(value, :two_digits)
156
+ end
157
+
158
+ # OrderId field must be A-Za-z0-9_ format and max 36 char
159
+ def format_order_id(order_id)
160
+ order_id.to_s.gsub(/[^A-Za-z0-9_]/, '')[0...36]
161
+ end
162
+
163
+ def add_addresses(xml, options)
164
+ xml.tag! 'AddressList' do
165
+ if billing_address = options[:billing_address] || options[:address]
166
+ xml.tag! 'Address' do
167
+ xml.tag! 'Type', 'B'
168
+ add_address(xml, billing_address)
169
+ end
170
+ end
171
+
172
+ if options[:shipping_address]
173
+ xml.tag! 'Address' do
174
+ xml.tag! 'Type', 'S'
175
+ add_address(xml, options[:shipping_address])
176
+ end
177
+ end
178
+ end
179
+ end
180
+
181
+ def add_address(xml, address)
182
+ xml.tag! 'Name', normalize(address[:name])
183
+ address_text = address[:address1]
184
+ address_text << " #{ address[:address2]}" if address[:address2]
185
+ xml.tag! 'Text', normalize(address_text)
186
+ xml.tag! 'City', normalize(address[:city])
187
+ xml.tag! 'District', normalize(address[:state])
188
+ xml.tag! 'PostalCode', address[:zip]
189
+ xml.tag! 'Country', normalize(address[:country])
190
+ xml.tag! 'Company', normalize(address[:company])
191
+ xml.tag! 'PhoneNumber', address[:phone].to_s.gsub(/[^0-9]/, '') if address[:phone]
192
+ end
193
+
194
+ def normalize(text)
195
+ return unless text
196
+
197
+ if ActiveSupport::Inflector.method(:transliterate).arity == -2
198
+ ActiveSupport::Inflector.transliterate(text,'')
199
+ elsif RUBY_VERSION >= '1.9'
200
+ text.gsub(/[^\x00-\x7F]+/, '')
201
+ else
202
+ ActiveSupport::Inflector.transliterate(text).to_s
203
+ end
204
+ end
205
+
206
+ def add_transaction_data(xml, money, options)
207
+ xml.tag! 'Transaction' do
208
+ xml.tag! 'Type', options[:gvp_order_type]
209
+ xml.tag! 'Amount', amount(money)
210
+ xml.tag! 'CurrencyCode', currency_code(options[:currency] || currency(money))
211
+ xml.tag! 'CardholderPresentCode', 0
212
+ end
213
+ end
214
+
215
+ def currency_code(currency)
216
+ CURRENCY_CODES[currency] || CURRENCY_CODES[default_currency]
217
+ end
218
+
219
+ def commit(money,request)
220
+ raw_response = ssl_post(self.live_url, "data=" + request)
221
+ response = parse(raw_response)
222
+
223
+ success = success?(response)
224
+
225
+ Response.new(success,
226
+ success ? 'Approved' : "Declined (Reason: #{response[:reason_code]} - #{response[:error_msg]} - #{response[:sys_err_msg]})",
227
+ response,
228
+ :test => test?,
229
+ :authorization => response[:order_id])
230
+ end
231
+
232
+ def parse(body)
233
+ xml = REXML::Document.new(body)
234
+
235
+ response = {}
236
+ xml.root.elements.to_a.each do |node|
237
+ parse_element(response, node)
238
+ end
239
+ response
240
+ end
241
+
242
+ def parse_element(response, node)
243
+ if node.has_elements?
244
+ node.elements.each{|element| parse_element(response, element) }
245
+ else
246
+ response[node.name.underscore.to_sym] = node.text
247
+ end
248
+ end
249
+
250
+ def success?(response)
251
+ response[:message] == "Approved"
252
+ end
253
+
254
+ end
255
+ end
256
+ end
257
+
@@ -0,0 +1,183 @@
1
+ require 'nokogiri'
2
+
3
+ module ActiveMerchant #:nodoc:
4
+ module Billing #:nodoc:
5
+ class GlobalTransportGateway < Gateway
6
+ self.test_url = 'https://certapia.globalpay.com/GlobalPay/transact.asmx/ProcessCreditCard'
7
+ self.live_url = 'https://api.globalpay.com/GlobalPay/transact.asmx/ProcessCreditCard'
8
+
9
+ self.supported_countries = %w(CA PR US)
10
+ self.default_currency = 'USD'
11
+ self.supported_cardtypes = [:visa, :master, :american_express, :discover, :diners_club, :jcb]
12
+
13
+ self.homepage_url = 'https://www.globalpaymentsinc.com'
14
+ self.display_name = 'Global Transport'
15
+
16
+ # Public: Create a new Global Transport gateway.
17
+ #
18
+ # options - A hash of options:
19
+ # :global_user_name - Your Global user name
20
+ # :global_password - Your Global password
21
+ # :term_type - 3 character field assigned by Global Transport after
22
+ # - your application is certified.
23
+ def initialize(options={})
24
+ requires!(options, :global_user_name, :global_password, :term_type)
25
+ super
26
+ end
27
+
28
+ def purchase(money, payment_method, options={})
29
+ post = {}
30
+ add_invoice(post, money, options)
31
+ add_payment_method(post, payment_method)
32
+ add_address(post, options)
33
+
34
+ commit('Sale', post, options)
35
+ end
36
+
37
+ def authorize(money, payment_method, options={})
38
+ post = {}
39
+ add_invoice(post, money, options)
40
+ add_payment_method(post, payment_method)
41
+ add_address(post, options)
42
+
43
+ commit('Auth', post, options)
44
+ end
45
+
46
+ def capture(money, authorization, options={})
47
+ post = {}
48
+ add_invoice(post, money, options)
49
+ add_auth(post, authorization)
50
+
51
+ commit('Force', post, options)
52
+ end
53
+
54
+ def refund(money, authorization, options={})
55
+ post = {}
56
+ add_invoice(post, money, options)
57
+ add_auth(post, authorization)
58
+
59
+ commit('Return', post, options)
60
+ end
61
+
62
+ def void(authorization, options={})
63
+ post = {}
64
+ add_auth(post, authorization)
65
+
66
+ commit('Void', post, options)
67
+ end
68
+
69
+ def verify(payment_method, options={})
70
+ post = {}
71
+ add_payment_method(post, payment_method)
72
+ add_address(post, options)
73
+
74
+ commit('CardVerify', post, options)
75
+ end
76
+
77
+ private
78
+
79
+ def add_address(post, options)
80
+ if address = (options[:billing_address] || options[:address])
81
+ post[:Street] = address[:address1]
82
+ post[:Zip] = address[:zip]
83
+ end
84
+ end
85
+
86
+ def add_auth(post, authorization)
87
+ post[:PNRef] = authorization
88
+ end
89
+
90
+ def add_invoice(post, money, options)
91
+ currency = (options[:currency] || currency(money))
92
+
93
+ post[:Amount] = localized_amount(money, currency)
94
+ post[:InvNum] = truncate(options[:order_id], 16)
95
+ end
96
+
97
+ def add_payment_method(post, payment_method)
98
+ post[:CardNum] = payment_method.number
99
+ post[:ExpDate] = expdate(payment_method)
100
+ post[:NameOnCard] = payment_method.name
101
+ post[:CVNum] = payment_method.verification_value
102
+ end
103
+
104
+ def parse(body)
105
+ response = {}
106
+
107
+ Nokogiri::XML(body).root.xpath('*').each do |node|
108
+ response[node.name.downcase.to_sym] = node.text
109
+ end
110
+
111
+ response
112
+ end
113
+
114
+ def commit(action, parameters, options)
115
+ raw = parse(ssl_post(url, post_data(action, parameters, options)))
116
+ Response.new(
117
+ success_from(raw),
118
+ message_from(raw),
119
+ raw,
120
+ authorization: authorization_from(raw),
121
+ test: test?,
122
+ avs_result: avs_from(raw),
123
+ cvv_result: cvv_from(raw)
124
+ )
125
+ end
126
+
127
+ def post_data(action, params, options)
128
+ post = default_params
129
+ post[:GlobalUserName] = @options[:global_user_name]
130
+ post[:GlobalPassword] = @options[:global_password]
131
+ post[:TransType] = action
132
+ post[:ExtData] = "<TermType>#{@options[:term_type]}</TermType>"
133
+
134
+ post.merge(params).map { |key, value| "#{key}=#{CGI.escape(value.to_s)}" }.join("&")
135
+ end
136
+
137
+ def url
138
+ (test? ? test_url : live_url)
139
+ end
140
+
141
+ def success_from(response)
142
+ (response[:result] == "0")
143
+ end
144
+
145
+ def message_from(response)
146
+ response[:respmsg]
147
+ end
148
+
149
+ def authorization_from(response)
150
+ response[:pnref]
151
+ end
152
+
153
+ def avs_from(response)
154
+ { code: response[:getavsresult] }
155
+ end
156
+
157
+ def cvv_from(response)
158
+ response[:getcvresult]
159
+ end
160
+
161
+ def default_params
162
+ {
163
+ CardNum: '',
164
+ ExpDate: '',
165
+ NameOnCard: '',
166
+ Amount: '',
167
+ PNRef: '',
168
+ Zip: '',
169
+ Street: '',
170
+ CVNum: '',
171
+ MagData: '',
172
+ InvNum: '',
173
+ ExtData: ''
174
+ }
175
+ end
176
+
177
+ def truncate(value, max_size)
178
+ return nil unless value
179
+ value.to_s[0, max_size]
180
+ end
181
+ end
182
+ end
183
+ end
@@ -0,0 +1,207 @@
1
+ require "nokogiri"
2
+
3
+ module ActiveMerchant #:nodoc:
4
+ module Billing #:nodoc:
5
+ class HdfcGateway < Gateway
6
+ self.display_name = "HDFC"
7
+ self.homepage_url = "http://www.hdfcbank.com/sme/sme-details/merchant-services/guzh6m0i"
8
+
9
+ self.test_url = "https://securepgtest.fssnet.co.in/pgway/servlet/"
10
+ self.live_url = "https://securepg.fssnet.co.in/pgway/servlet/"
11
+
12
+ self.supported_countries = ["IN"]
13
+ self.default_currency = "INR"
14
+ self.money_format = :dollars
15
+ self.supported_cardtypes = [:visa, :master, :discover, :diners_club]
16
+
17
+ def initialize(options={})
18
+ requires!(options, :login, :password)
19
+ super
20
+ end
21
+
22
+ def purchase(amount, payment_method, options={})
23
+ post = {}
24
+ add_invoice(post, amount, options)
25
+ add_payment_method(post, payment_method)
26
+ add_customer_data(post, options)
27
+
28
+ commit("purchase", post)
29
+ end
30
+
31
+ def authorize(amount, payment_method, options={})
32
+ post = {}
33
+ add_invoice(post, amount, options)
34
+ add_payment_method(post, payment_method)
35
+ add_customer_data(post, options)
36
+
37
+ commit("authorize", post)
38
+ end
39
+
40
+ def capture(amount, authorization, options={})
41
+ post = {}
42
+ add_invoice(post, amount, options)
43
+ add_reference(post, authorization)
44
+ add_customer_data(post, options)
45
+
46
+ commit("capture", post)
47
+ end
48
+
49
+ def refund(amount, authorization, options={})
50
+ post = {}
51
+ add_invoice(post, amount, options)
52
+ add_reference(post, authorization)
53
+ add_customer_data(post, options)
54
+
55
+ commit("refund", post)
56
+ end
57
+
58
+ private
59
+
60
+ CURRENCY_CODES = Hash.new{|h,k| raise ArgumentError.new("Unsupported currency for HDFC: #{k}")}
61
+ CURRENCY_CODES["AED"] = "784"
62
+ CURRENCY_CODES["AUD"] = "036"
63
+ CURRENCY_CODES["CAD"] = "124"
64
+ CURRENCY_CODES["EUR"] = "978"
65
+ CURRENCY_CODES["GBP"] = "826"
66
+ CURRENCY_CODES["INR"] = "356"
67
+ CURRENCY_CODES["OMR"] = "512"
68
+ CURRENCY_CODES["QAR"] = "634"
69
+ CURRENCY_CODES["SGD"] = "702"
70
+ CURRENCY_CODES["USD"] = "840"
71
+
72
+ def add_invoice(post, amount, options)
73
+ post[:amt] = amount(amount)
74
+ post[:currencycode] = CURRENCY_CODES[options[:currency] || currency(amount)]
75
+ post[:trackid] = escape(options[:order_id], 40) if options[:order_id]
76
+ post[:udf1] = escape(options[:description]) if options[:description]
77
+ post[:eci] = options[:eci] if options[:eci]
78
+ end
79
+
80
+ def add_customer_data(post, options)
81
+ post[:udf2] = escape(options[:email]) if options[:email]
82
+ if address = (options[:billing_address] || options[:address])
83
+ post[:udf3] = escape(address[:phone]) if address[:phone]
84
+ post[:udf4] = escape(<<EOA)
85
+ #{address[:name]}
86
+ #{address[:company]}
87
+ #{address[:address1]}
88
+ #{address[:address2]}
89
+ #{address[:city]} #{address[:state]} #{address[:zip]}
90
+ #{address[:country]}
91
+ EOA
92
+ end
93
+ end
94
+
95
+ def add_payment_method(post, payment_method)
96
+ post[:member] = escape(payment_method.name, 30)
97
+ post[:card] = escape(payment_method.number)
98
+ post[:cvv2] = escape(payment_method.verification_value)
99
+ post[:expyear] = format(payment_method.year, :four_digits)
100
+ post[:expmonth] = format(payment_method.month, :two_digits)
101
+ end
102
+
103
+ def add_reference(post, authorization)
104
+ tranid, member = split_authorization(authorization)
105
+ post[:transid] = tranid
106
+ post[:member] = member
107
+ end
108
+
109
+ def parse(xml)
110
+ response = {}
111
+
112
+ doc = Nokogiri::XML.fragment(fix_xml(xml))
113
+ doc.children.each do |node|
114
+ if node.text?
115
+ next
116
+ elsif (node.elements.size == 0)
117
+ response[node.name.downcase.to_sym] = node.text
118
+ else
119
+ node.elements.each do |childnode|
120
+ name = "#{node.name.downcase}_#{childnode.name.downcase}"
121
+ response[name.to_sym] = childnode.text
122
+ end
123
+ end
124
+ end
125
+
126
+ response
127
+ end
128
+
129
+ def fix_xml(xml)
130
+ xml.gsub(/&(?!(?:amp|quot|apos|lt|gt);)/, "&amp;")
131
+ end
132
+
133
+ ACTIONS = {
134
+ "purchase" => "1",
135
+ "refund" => "2",
136
+ "authorize" => "4",
137
+ "capture" => "5",
138
+ }
139
+
140
+ def commit(action, post)
141
+ post[:id] = @options[:login]
142
+ post[:password] = @options[:password]
143
+ post[:action] = ACTIONS[action] if ACTIONS[action]
144
+
145
+ raw = parse(ssl_post(url(action), build_request(post)))
146
+
147
+ succeeded = success_from(raw[:result])
148
+ Response.new(
149
+ succeeded,
150
+ message_from(succeeded, raw),
151
+ raw,
152
+ :authorization => authorization_from(post, raw),
153
+ :test => test?
154
+ )
155
+ end
156
+
157
+ def build_request(post)
158
+ xml = Builder::XmlMarkup.new :indent => 2
159
+ xml.instruct!
160
+ post.each do |field, value|
161
+ xml.tag!(field, value)
162
+ end
163
+ xml.target!
164
+ end
165
+
166
+ def url(action)
167
+ endpoint = "TranPortalXMLServlet"
168
+ (test? ? test_url : live_url) + endpoint
169
+ end
170
+
171
+ def success_from(result)
172
+ case result
173
+ when "CAPTURED", "APPROVED", "NOT ENROLLED", "ENROLLED"
174
+ true
175
+ else
176
+ false
177
+ end
178
+ end
179
+
180
+ def message_from(succeeded, response)
181
+ if succeeded
182
+ "Succeeded"
183
+ else
184
+ (response[:error_text] || response[:result] || "Unable to read error message").split("-").last
185
+ end
186
+ end
187
+
188
+ def authorization_from(request, response)
189
+ [response[:tranid], request[:member]].join("|")
190
+ end
191
+
192
+ def split_authorization(authorization)
193
+ tranid, member = authorization.split("|")
194
+ [tranid, member]
195
+ end
196
+
197
+ def escape(string, max_length=250)
198
+ return "" unless string
199
+ if max_length
200
+ string = string[0...max_length]
201
+ end
202
+ string.gsub(/[^A-Za-z0-9 \-_@\.\n]/, '')
203
+ end
204
+ end
205
+ end
206
+ end
207
+