class ActiveMerchant::Billing::AlliedWalletGateway

Constants

ACTIONS

Public Class Methods

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

Public Instance Methods

authorize(amount, payment_method, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/allied_wallet.rb, line 29
def authorize(amount, payment_method, options = {})
  post = {}
  add_invoice(post, amount, options)
  add_payment_method(post, payment_method)
  add_customer_data(post, options)

  commit(:authorize, post)
end
capture(amount, authorization, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/allied_wallet.rb, line 38
def capture(amount, authorization, options = {})
  post = {}
  add_invoice(post, amount, options)
  add_reference(post, authorization, :capture)
  add_customer_data(post, options)

  commit(:capture, post)
end
purchase(amount, payment_method, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/allied_wallet.rb, line 20
def purchase(amount, payment_method, options = {})
  post = {}
  add_invoice(post, amount, options)
  add_payment_method(post, payment_method)
  add_customer_data(post, options)

  commit(:purchase, post)
end
refund(amount, authorization, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/allied_wallet.rb, line 54
def refund(amount, authorization, options = {})
  post = {}
  add_invoice(post, amount, options)
  add_reference(post, authorization, :refund)
  add_amount(post, amount)
  add_customer_data(post, options)

  commit(:refund, post)
end
scrub(transcript) click to toggle source
# File lib/active_merchant/billing/gateways/allied_wallet.rb, line 75
def scrub(transcript)
  transcript.
    gsub(%r((Authorization: Bearer )[a-zA-Z0-9._-]+)i, '\1[FILTERED]').
    gsub(%r(("cardNumber\\?":\\?")[^"]*)i, '\1[FILTERED]').
    gsub(%r(("cVVCode\\?":\\?")\d+[^"]*)i, '\1[FILTERED]').
    gsub(%r(("cVVCode\\?":)null), '\1[BLANK]').
    gsub(%r(("cVVCode\\?":\\?")\\?"), '\1[BLANK]"').
    gsub(%r(("cVVCode\\?":\\?")\s+), '\1[BLANK]"')
end
supports_scrubbing?() click to toggle source
# File lib/active_merchant/billing/gateways/allied_wallet.rb, line 71
def supports_scrubbing?
  true
end
verify(credit_card, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/allied_wallet.rb, line 64
def verify(credit_card, options = {})
  MultiResponse.run(:use_first_response) do |r|
    r.process { authorize(100, credit_card, options) }
    r.process(:ignore_result) { void(r.authorization, options) }
  end
end
void(authorization, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/allied_wallet.rb, line 47
def void(authorization, options = {})
  post = {}
  add_reference(post, authorization, :void)

  commit(:void, post)
end

Private Instance Methods

add_amount(post, amount) click to toggle source
# File lib/active_merchant/billing/gateways/allied_wallet.rb, line 87
def add_amount(post, amount)
  post[:amount] = amount
end
add_customer_data(post, options) click to toggle source
# File lib/active_merchant/billing/gateways/allied_wallet.rb, line 106
def add_customer_data(post, options)
  post[:email] = options[:email] || 'unspecified@example.com'
  post[:iPAddress] = options[:ip]
  if (billing_address = options[:billing_address])
    post[:firstName], post[:lastName] = split_names(billing_address[:name])
    post[:addressLine1] = billing_address[:address1]
    post[:addressLine2] = billing_address[:address2]
    post[:city] = billing_address[:city]
    post[:state] = billing_address[:state]
    post[:countryId] = billing_address[:country]
    post[:postalCode] = billing_address[:zip]
    post[:phone] = billing_address[:phone]
  end
end
add_invoice(post, money, options) click to toggle source
# File lib/active_merchant/billing/gateways/allied_wallet.rb, line 91
def add_invoice(post, money, options)
  post[:siteId] = @options[:site_id]
  post[:amount] = amount(money)
  post[:trackingId] = options[:order_id]
  post[:currency] = options[:currency] || currency(money)
end
add_payment_method(post, payment_method) click to toggle source
# File lib/active_merchant/billing/gateways/allied_wallet.rb, line 98
def add_payment_method(post, payment_method)
  post[:nameOnCard] = payment_method.name
  post[:cardNumber] = payment_method.number
  post[:cVVCode] = payment_method.verification_value
  post[:expirationYear] = format(payment_method.year, :four_digits)
  post[:expirationMonth] = format(payment_method.month, :two_digits)
end
add_reference(post, authorization, action) click to toggle source
# File lib/active_merchant/billing/gateways/allied_wallet.rb, line 121
def add_reference(post, authorization, action)
  transactions = {
    capture: :authorizetransactionid,
    void: :authorizeTransactionid,
    refund: :referencetransactionid,
    recurring: :saleTransactionid
  }
  post[transactions[action]] = authorization
end
commit(action, post) click to toggle source
# File lib/active_merchant/billing/gateways/allied_wallet.rb, line 139
def commit(action, post)
  begin
    raw_response = ssl_post(url(action), post.to_json, headers)
    response = parse(raw_response)
  rescue ResponseError => e
    raise unless e.response.code.to_s =~ /4\d\d/

    response = parse(e.response.body)
  end

  succeeded = success_from(response['status'])
  Response.new(
    succeeded,
    message_from(succeeded, response),
    response,
    authorization: response['id'],
    avs_result: AVSResult.new(code: response['avs_response']),
    cvv_result: CVVResult.new(response['cvv2_response']),
    test: test?
  )
rescue JSON::ParserError
  unparsable_response(raw_response)
end
headers() click to toggle source
# File lib/active_merchant/billing/gateways/allied_wallet.rb, line 169
def headers
  {
    'Content-type'  => 'application/json',
    'Authorization' => 'Bearer ' + @options[:token]
  }
end
message_from(succeeded, response) click to toggle source
# File lib/active_merchant/billing/gateways/allied_wallet.rb, line 196
def message_from(succeeded, response)
  if succeeded
    'Succeeded'
  else
    response['message'] || 'Unable to read error message'
  end
end
parse(body) click to toggle source
# File lib/active_merchant/billing/gateways/allied_wallet.rb, line 180
def parse(body)
  JSON.parse(body)
end
parse_element(response, node) click to toggle source
# File lib/active_merchant/billing/gateways/allied_wallet.rb, line 184
def parse_element(response, node)
  if node.has_elements?
    node.elements.each { |element| parse_element(response, element) }
  else
    response[node.name.underscore.to_sym] = node.text
  end
end
success_from(response) click to toggle source
# File lib/active_merchant/billing/gateways/allied_wallet.rb, line 192
def success_from(response)
  response == 'Successful'
end
unparsable_response(raw_response) click to toggle source
# File lib/active_merchant/billing/gateways/allied_wallet.rb, line 163
def unparsable_response(raw_response)
  message = 'Unparsable response received from Allied Wallet. Please contact Allied Wallet if you continue to receive this message.'
  message += " (The raw response returned by the API was #{raw_response.inspect})"
  return Response.new(false, message)
end
url(action) click to toggle source
# File lib/active_merchant/billing/gateways/allied_wallet.rb, line 176
def url(action)
  live_url + CGI.escape(@options[:merchant_id]) + '/' + ACTIONS[action] + 'transactions'
end