class ActiveMerchant::Billing::BanwireGateway

Constants

URL

Public Class Methods

new(options = {}) click to toggle source
Calls superclass method ActiveMerchant::Billing::Gateway::new
# File lib/active_merchant/billing/gateways/banwire.rb, line 11
def initialize(options = {})
  requires!(options, :login)
  super
end

Public Instance Methods

purchase(money, creditcard, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/banwire.rb, line 16
def purchase(money, creditcard, options = {})
  post = {}
  add_response_type(post)
  add_customer_data(post, options)
  add_order_data(post, options)
  add_creditcard(post, creditcard)
  add_address(post, creditcard, options)
  add_customer_data(post, options)
  add_amount(post, money, options)

  commit(money, post)
end

Private Instance Methods

add_address(post, creditcard, options) click to toggle source
# File lib/active_merchant/billing/gateways/banwire.rb, line 46
def add_address(post, creditcard, options)
  post[:address] = options[:billing_address][:address1]
  post[:post_code] = options[:billing_address][:zip]
end
add_amount(post, money, options) click to toggle source
# File lib/active_merchant/billing/gateways/banwire.rb, line 59
def add_amount(post, money, options)
  post[:ammount] = amount(money)
  post[:currency] = options[:currency]
end
add_creditcard(post, creditcard) click to toggle source
# File lib/active_merchant/billing/gateways/banwire.rb, line 51
def add_creditcard(post, creditcard)
  post[:card_num] = creditcard.number
  post[:card_name] = creditcard.name
  post[:card_type] = card_brand(creditcard)
  post[:card_exp] = "#{sprintf("%02d", creditcard.month)}/#{"#{creditcard.year}"[-2, 2]}"
  post[:card_ccv2] = creditcard.verification_value
end
add_customer_data(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/banwire.rb, line 35
def add_customer_data(post, options)
  post[:user] = @options[:login]
  post[:phone] = options[:billing_address][:phone]
  post[:mail] = options[:email] || "unspecified@email.com"
end
add_order_data(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/banwire.rb, line 41
def add_order_data(post, options)
  post[:reference] = options[:order_id] || generate_unique_id
  post[:concept] = options[:description]
end
add_response_type(post) click to toggle source
# File lib/active_merchant/billing/gateways/banwire.rb, line 31
def add_response_type(post)
  post[:response_format] = "JSON"
end
card_brand(card) click to toggle source
# File lib/active_merchant/billing/gateways/banwire.rb, line 64
def card_brand(card)
  brand = super
  ({"master" => "mastercard", "american_express" => "amex"}[brand] || brand)
end
commit(money, parameters) click to toggle source
# File lib/active_merchant/billing/gateways/banwire.rb, line 73
def commit(money, parameters)
  raw_response = ssl_post(URL, post_data(parameters))
  begin
    response = parse(raw_response)
  rescue JSON::ParserError
    response = json_error(raw_response)
  end

  Response.new(success?(response),
               response["message"],
               response,
               :test => test?,
               :authorization => response["code_auth"])
end
json_error(raw_response) click to toggle source
# File lib/active_merchant/billing/gateways/banwire.rb, line 96
def json_error(raw_response)
  msg = 'Invalid response received from the Banwire API.  Please contact Banwire support if you continue to receive this message.'
  msg += "  (The raw response returned by the API was #{raw_response.inspect})"
  {
    "message" => msg
  }
end
parse(body) click to toggle source
# File lib/active_merchant/billing/gateways/banwire.rb, line 69
def parse(body)
  JSON.parse(body)
end
post_data(parameters = {}) click to toggle source
# File lib/active_merchant/billing/gateways/banwire.rb, line 92
def post_data(parameters = {})
  parameters.collect { |key, value| "#{key}=#{CGI.escape(value.to_s)}" }.join("&")
end
success?(response) click to toggle source
# File lib/active_merchant/billing/gateways/banwire.rb, line 88
def success?(response)
  (response["response"] == "ok")
end