class ActiveMerchant::Billing::App55Gateway
Public Class Methods
new(options = {})
click to toggle source
Create gateway
options:
:api_key - merchants App55 API Key :api_secret - merchants App55 Secret Key
Calls superclass method
ActiveMerchant::Billing::Gateway::new
# File lib/active_merchant/billing/gateways/app55.rb, line 19 def initialize(options = {}) requires!(options, :api_key, :api_secret) @api_key = options[:api_key] @api_secret = options[:api_secret] super end
Public Instance Methods
capture(money, authorization, options = {})
click to toggle source
Commit a pre-authorized transaction.
money - The monetary amount of the transaction in cents. authorization - The App55 transaction id string. options - A standard ActiveMerchant
options hash
# File lib/active_merchant/billing/gateways/app55.rb, line 53 def capture(money, authorization, options = {}) commit(:post, "transaction/#{authorization}") end
purchase(money, payment_method, options = {})
click to toggle source
Make a purchase (authorize and commit)
money - The monetary amount of the transaction in cents. payment_method - The CreditCard
or the App55 card token. options - A standard ActiveMerchant
options hash
# File lib/active_merchant/billing/gateways/app55.rb, line 31 def purchase(money, payment_method, options = {}) authorize(money, payment_method, options.merge(commit: true)) end
Private Instance Methods
add_address(card, options)
click to toggle source
# File lib/active_merchant/billing/gateways/app55.rb, line 74 def add_address(card, options) return unless card && card.kind_of?(Hash) address_hash = {} if address = (options[:billing_address] || options[:address]) address_hash[:street] = address[:address1] if address[:address1] address_hash[:street2] = address[:address2] if address[:address2] address_hash[:country] = address[:country] if address[:country] address_hash[:postal_code] = address[:zip] if address[:zip] address_hash[:city] = address[:city] if address[:city] card[:address] = address_hash end end
add_amount(obj, money, options)
click to toggle source
# File lib/active_merchant/billing/gateways/app55.rb, line 95 def add_amount(obj, money, options) obj[:amount] = amount(money) obj[:currency] = (options[:currency] || currency(money)) end
add_creditcard(post, creditcard, options)
click to toggle source
# File lib/active_merchant/billing/gateways/app55.rb, line 64 def add_creditcard(post, creditcard, options) card = {} card[:number] = creditcard.number card[:expiry] = ("%02d". % creditcard.month) + '/' + creditcard.year.to_s card[:security_code] = creditcard.verification_value if creditcard.verification_value? card[:holder_name] = creditcard.name if creditcard.name add_address(card, options) post[:card] = card end
add_customer_data(post, options)
click to toggle source
# File lib/active_merchant/billing/gateways/app55.rb, line 59 def add_customer_data(post, options) metadata_options = [:description, :browser_ip, :user_agent, :referrer] post.update(options.slice(*metadata_options)) end
add_transaction(post, money, options)
click to toggle source
# File lib/active_merchant/billing/gateways/app55.rb, line 87 def add_transaction(post, money, options) transaction = {} add_amount(transaction, money, options) transaction[:description] = (options[:description] || options[:email]) transaction[:commit] = options[:commit] post[:transaction] = transaction end
commit(method, resource, parameters=nil, meta={})
click to toggle source
# File lib/active_merchant/billing/gateways/app55.rb, line 106 def commit(method, resource, parameters=nil, meta={}) success = false begin raw_response = ssl_request( method, url(resource), post_data(parameters), headers ) response = parse(raw_response) success = response.key?("sig") rescue ResponseError => e response = parse(e.response.body) end Response.new( success, (success ? "OK" : response["error"]["message"]), response, test: test?, authorization: authorization_from(response) ) end
headers()
click to toggle source
# File lib/active_merchant/billing/gateways/app55.rb, line 168 def headers { "Authorization" => "Basic " + Base64.strict_encode64(@options[:api_key].to_s + ":" + @options[:api_secret].to_s), "User-Agent" => user_agent, } end
json_error(raw_response)
click to toggle source
# File lib/active_merchant/billing/gateways/app55.rb, line 138 def json_error(raw_response) msg = "Invalid response from app55 server: Received: #{raw_response.inspect})" { "error" => { "message" => msg } } end
parse(body)
click to toggle source
# File lib/active_merchant/billing/gateways/app55.rb, line 100 def parse(body) JSON.parse(body) rescue JSON::ParserError json_error(raw_response) end
post_data(params)
click to toggle source
# File lib/active_merchant/billing/gateways/app55.rb, line 151 def post_data(params) return nil unless params params.map do |key, value| next if value.blank? if value.is_a?(Hash) h = {} value.each do |k, v| h["#{key}.#{k}"] = v unless v.blank? end post_data(h) else "#{key}=#{CGI.escape(value.to_s)}" end end.compact.join("&") end
url(resource)
click to toggle source
# File lib/active_merchant/billing/gateways/app55.rb, line 147 def url(resource) (test? ? self.test_url : self.live_url) + resource end