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,20 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ class Flo2cashSimpleGateway < Flo2cashGateway
4
+ self.display_name = 'Flo2Cash Simple'
5
+
6
+ def purchase(amount, payment_method, options={})
7
+ post = {}
8
+ add_invoice(post, amount, options)
9
+ add_payment_method(post, payment_method)
10
+ add_customer_data(post, options)
11
+
12
+ commit("ProcessPurchase", post)
13
+ end
14
+
15
+ # Flo2Cash's "simple mode" does not support auth/capture
16
+ undef_method :authorize
17
+ undef_method :capture
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,261 @@
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(strip_invalid_xml_chars(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
+ def strip_invalid_xml_chars(xml)
255
+ xml.gsub(/&(?!(?:[a-z]+|#[0-9]+|x[a-zA-Z0-9]+);)/, '&amp;')
256
+ end
257
+
258
+ end
259
+ end
260
+ end
261
+
@@ -0,0 +1,179 @@
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
+ end
178
+ end
179
+ end