Class Index [+]

Quicksearch

ActiveMerchant::Billing::GarantiGateway

Constants

URL
CURRENCY_CODES

Public Class Methods

new(options = {}) click to toggle source
    # File lib/active_merchant/billing/gateways/garanti.rb, line 37
37:       def initialize(options = {})
38:         requires!(options, :login, :password, :terminal_id, :merchant_id)
39:         @options = options
40:         super
41:       end

Public Instance Methods

authorize(money, credit_card, options = {}) click to toggle source
    # File lib/active_merchant/billing/gateways/garanti.rb, line 48
48:       def authorize(money, credit_card, options = {})
49:         options = options.merge(:gvp_order_type => "preauth")
50:         commit(money, build_authorize_request(money, credit_card, options))
51:       end
capture(money, ref_id, options = {}) click to toggle source
    # File lib/active_merchant/billing/gateways/garanti.rb, line 53
53:       def capture(money, ref_id, options = {})
54:         options = options.merge(:gvp_order_type => "postauth")
55:         commit(money, build_capture_request(money, ref_id, options))
56:       end
purchase(money, credit_card, options = {}) click to toggle source
    # File lib/active_merchant/billing/gateways/garanti.rb, line 43
43:       def purchase(money, credit_card, options = {})
44:         options = options.merge(:gvp_order_type => "sales")
45:         commit(money, build_sale_request(money, credit_card, options))
46:       end

Private Instance Methods

add_address(xml, address) click to toggle source
     # File lib/active_merchant/billing/gateways/garanti.rb, line 186
186:       def add_address(xml, address)
187:         xml.tag! 'Name', normalize(address[:name])
188:         address_text = address[:address1]
189:         address_text << " #{ address[:address2]}" if address[:address2]
190:         xml.tag! 'Text', normalize(address_text)
191:         xml.tag! 'City', normalize(address[:city])
192:         xml.tag! 'District', normalize(address[:state])
193:         xml.tag! 'PostalCode', address[:zip]
194:         xml.tag! 'Country', normalize(address[:country])
195:         xml.tag! 'Company', normalize(address[:company])
196:         xml.tag! 'PhoneNumber', address[:phone].to_s.gsub(/[^0-9]/, '') if address[:phone]
197:       end
add_addresses(xml, options) click to toggle source
     # File lib/active_merchant/billing/gateways/garanti.rb, line 168
168:       def add_addresses(xml, options)
169:         xml.tag! 'AddressList' do
170:           if billing_address = options[:billing_address] || options[:address]
171:             xml.tag! 'Address' do
172:               xml.tag! 'Type', 'B'
173:               add_address(xml, billing_address)
174:             end
175:           end
176: 
177:           if options[:shipping_address]
178:             xml.tag! 'Address' do
179:               xml.tag! 'Type', 'S'
180:               add_address(xml, options[:shipping_address])
181:             end
182:           end
183:         end
184:       end
add_credit_card(xml, credit_card) click to toggle source
     # File lib/active_merchant/billing/gateways/garanti.rb, line 151
151:       def add_credit_card(xml, credit_card)
152:         xml.tag! 'Card' do
153:           xml.tag! 'Number', credit_card.number
154:           xml.tag! 'ExpireDate', [format_exp(credit_card.month), format_exp(credit_card.year)].join
155:           xml.tag! 'CVV2', credit_card.verification_value
156:         end
157:       end
add_customer_data(xml, options) click to toggle source
     # File lib/active_merchant/billing/gateways/garanti.rb, line 133
133:       def add_customer_data(xml, options)
134:         xml.tag! 'Customer' do
135:           xml.tag! 'IPAddress', options[:ip] || '1.1.1.1'
136:           xml.tag! 'EmailAddress', options[:email]
137:         end
138:       end
add_order_data(xml, options, &block) click to toggle source
     # File lib/active_merchant/billing/gateways/garanti.rb, line 140
140:       def add_order_data(xml, options, &block)
141:         xml.tag! 'Order' do
142:           xml.tag! 'OrderID', format_order_id(options[:order_id])
143:           xml.tag! 'GroupID'
144: 
145:           if block_given?
146:             yield xml
147:           end
148:         end
149:       end
add_transaction_data(xml, money, options) click to toggle source
     # File lib/active_merchant/billing/gateways/garanti.rb, line 211
211:       def add_transaction_data(xml, money, options)
212:         xml.tag! 'Transaction' do
213:           xml.tag! 'Type', options[:gvp_order_type]
214:           xml.tag! 'Amount', amount(money)
215:           xml.tag! 'CurrencyCode', currency_code(options[:currency] || currency(money))
216:           xml.tag! 'CardholderPresentCode', 0
217:         end
218:       end
build_authorize_request(money, credit_card, options) click to toggle source
     # File lib/active_merchant/billing/gateways/garanti.rb, line 109
109:       def build_authorize_request(money, credit_card, options)
110:          build_xml_request(money, credit_card, options) do |xml|
111:           add_customer_data(xml, options)
112:           add_order_data(xml, options)  do |xml|
113:             add_addresses(xml, options)
114:           end
115:           add_credit_card(xml, credit_card)
116:           add_transaction_data(xml, money, options)
117: 
118:           xml.target!
119:         end
120:       end
build_capture_request(money, ref_id, options) click to toggle source
     # File lib/active_merchant/billing/gateways/garanti.rb, line 122
122:       def build_capture_request(money, ref_id, options)
123:         options = options.merge(:order_id => ref_id)
124:          build_xml_request(money, ref_id, options) do |xml|
125:           add_customer_data(xml, options)
126:           add_order_data(xml, options)
127:           add_transaction_data(xml, money, options)
128: 
129:           xml.target!
130:         end
131:       end
build_sale_request(money, credit_card, options) click to toggle source
     # File lib/active_merchant/billing/gateways/garanti.rb, line 96
 96:       def build_sale_request(money, credit_card, options)
 97:         build_xml_request(money, credit_card, options) do |xml|
 98:           add_customer_data(xml, options)
 99:           add_order_data(xml, options) do |xml|
100:             add_addresses(xml, options)
101:           end
102:           add_credit_card(xml, credit_card)
103:           add_transaction_data(xml, money, options)
104: 
105:           xml.target!
106:         end
107:       end
build_xml_request(money, credit_card, options, &block) click to toggle source
    # File lib/active_merchant/billing/gateways/garanti.rb, line 70
70:       def build_xml_request(money, credit_card, options, &block)
71:         card_number = credit_card.respond_to?(:number) ? credit_card.number : ''
72:         hash_data   = generate_hash_data(format_order_id(options[:order_id]), @options[:terminal_id], card_number, amount(money), security_data)
73: 
74:         xml = Builder::XmlMarkup.new(:indent => 2)
75:         xml.instruct! :xml, :version => "1.0", :encoding => "UTF-8"
76: 
77:         xml.tag! 'GVPSRequest' do
78:           xml.tag! 'Mode', test? ? 'TEST' : 'PROD'
79:           xml.tag! 'Version', 'V0.01'
80:           xml.tag! 'Terminal' do
81:             xml.tag! 'ProvUserID', 'PROVAUT'
82:             xml.tag! 'HashData', hash_data
83:             xml.tag! 'UserID', @options[:login]
84:             xml.tag! 'ID', @options[:terminal_id]
85:             xml.tag! 'MerchantID', @options[:merchant_id]
86:           end
87: 
88:           if block_given?
89:             yield xml
90:           else
91:             xml.target!
92:           end
93:         end
94:       end
commit(money,request) click to toggle source
     # File lib/active_merchant/billing/gateways/garanti.rb, line 224
224:       def commit(money,request)
225:         raw_response = ssl_post(URL, "data=" + request)
226:         response = parse(raw_response)
227: 
228:         success = success?(response)
229: 
230:         Response.new(success,
231:                      success ? 'Approved' : "Declined (Reason: #{response[:reason_code]} - #{response[:error_msg]} - #{response[:sys_err_msg]})",
232:                      response,
233:                      :test => test?,
234:                      :authorization => response[:order_id])
235:       end
currency_code(currency) click to toggle source
     # File lib/active_merchant/billing/gateways/garanti.rb, line 220
220:       def currency_code(currency)
221:         CURRENCY_CODES[currency] || CURRENCY_CODES[default_currency]
222:       end
format_exp(value) click to toggle source
     # File lib/active_merchant/billing/gateways/garanti.rb, line 159
159:       def format_exp(value)
160:         format(value, :two_digits)
161:       end
format_order_id(order_id) click to toggle source

OrderId field must be A-Za-z0-9_ format and max 36 char

     # File lib/active_merchant/billing/gateways/garanti.rb, line 164
164:       def format_order_id(order_id)
165:         order_id.to_s.gsub(/[^A-Za-z0-9_]/, '')[0...36]
166:       end
generate_hash_data(order_id, terminal_id, credit_card_number, amount, security_data) click to toggle source
    # File lib/active_merchant/billing/gateways/garanti.rb, line 65
65:       def generate_hash_data(order_id, terminal_id, credit_card_number, amount, security_data)
66:         data = [order_id, terminal_id, credit_card_number, amount, security_data].join
67:         Digest::SHA1.hexdigest(data).upcase
68:       end
normalize(text) click to toggle source
     # File lib/active_merchant/billing/gateways/garanti.rb, line 199
199:       def normalize(text)
200:         return unless text
201:         
202:         if ActiveSupport::Inflector.method(:transliterate).arity == 2
203:           ActiveSupport::Inflector.transliterate(text,'')
204:         elsif RUBY_VERSION >= '1.9'
205:           text.gsub(/[^\x00-\x7F]+/, '')
206:         else
207:           ActiveSupport::Inflector.transliterate(text).to_s
208:         end
209:       end
parse(body) click to toggle source
     # File lib/active_merchant/billing/gateways/garanti.rb, line 237
237:       def parse(body)
238:         xml = REXML::Document.new(body)
239: 
240:         response = {}
241:         xml.root.elements.to_a.each do |node|
242:           parse_element(response, node)
243:         end
244:         response
245:       end
parse_element(response, node) click to toggle source
     # File lib/active_merchant/billing/gateways/garanti.rb, line 247
247:       def parse_element(response, node)
248:         if node.has_elements?
249:           node.elements.each{|element| parse_element(response, element) }
250:         else
251:           response[node.name.underscore.to_sym] = node.text
252:         end
253:       end
security_data() click to toggle source
    # File lib/active_merchant/billing/gateways/garanti.rb, line 60
60:       def security_data
61:         rjusted_terminal_id = @options[:terminal_id].to_s.rjust(9, "0")
62:         Digest::SHA1.hexdigest(@options[:password].to_s + rjusted_terminal_id).upcase
63:       end
success?(response) click to toggle source
     # File lib/active_merchant/billing/gateways/garanti.rb, line 255
255:       def success?(response)
256:         response[:message] == "Approved"
257:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.