Class: ActiveMerchant::Billing::UsaEpayCustom

Inherits:
UsaEpayTransactionGateway
  • Object
show all
Defined in:
lib/usaepay/gateway.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



5
6
7
# File 'lib/usaepay/gateway.rb', line 5

def key
  @key
end

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/usaepay/gateway.rb', line 5

def options
  @options
end

#pinObject (readonly)

Returns the value of attribute pin.



5
6
7
# File 'lib/usaepay/gateway.rb', line 5

def pin
  @pin
end

Instance Method Details

#add_save_card(post, options) ⇒ Object



67
68
69
# File 'lib/usaepay/gateway.rb', line 67

def add_save_card(post, options)
  post[:saveCard] = (options[:save_card] ? 1 : 0) if options.has_key?(:save_card)
end

#add_token(post, credit_card) ⇒ Object



63
64
65
# File 'lib/usaepay/gateway.rb', line 63

def add_token(post, credit_card)
  post[:card]   = credit_card
end

#authorize(money, credit_card, options = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/usaepay/gateway.rb', line 9

def authorize(money, credit_card, options = {})
  billing_address = options[:billing_address] || options[:address]

  post = {}
  post[:ip] = options[:ip_address] if options[:ip_address].present?
  post[:name] = billing_address[:name] if billing_address.present?
  add_amount(post, money)
  add_invoice(post, options)
  add_address_for_type(:billing, post, credit_card, billing_address) if billing_address
  if credit_card.is_a? String
    add_token(post, credit_card)
  else
    add_payment(post, credit_card)
    add_address(post, credit_card, options)
    unless credit_card.track_data.present?
      add_customer_data(post, options)
    end
  end

  add_split_payments(post, options)
  add_recurring_fields(post, options)
  add_custom_fields(post, options)
  add_line_items(post, options)
  add_test_mode(post, options)
  add_save_card(post, options)
  commit(:authorization, post)
end

#parse(body) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/usaepay/gateway.rb', line 71

def parse(body)
  fields = {}
  for line in body.split('&')
    key, value = *line.scan(%r{^(\w+)\=(.*)$}).flatten
    fields[key] = CGI.unescape(value.to_s)
  end
  {
    :status           => fields['UMstatus'],
    :auth_code        => fields['UMauthCode'],
    :ref_num          => fields['UMrefNum'],
    :batch            => fields['UMbatch'],
    :avs_result       => fields['UMavsResult'],
    :avs_result_code  => fields['UMavsResultCode'],
    :cvv2_result      => fields['UMcvv2Result'],
    :cvv2_result_code => fields['UMcvv2ResultCode'],
    :vpas_result_code => fields['UMvpasResultCode'],
    :result           => fields['UMresult'],
    :error            => fields['UMerror'],
    :error_code       => fields['UMerrorcode'],
    :acs_url          => fields['UMacsurl'],
    :payload          => fields['UMpayload'],
    :token            => fields['UMcardRef']
  }.delete_if { |k, v| v.nil? }
end

#purchase(money, payment, options = {}) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/usaepay/gateway.rb', line 37

def purchase(money, payment, options = {})
  post = {}

  add_amount(post, money)
  add_invoice(post, options)

  if payment.is_a? String
    add_token(post, payment)
  else
    add_payment(post, payment, options)
    unless payment.respond_to?(:track_data) && payment.track_data.present?
      add_address(post, payment, options)
      add_customer_data(post, options)
    end
  end

  add_split_payments(post, options)
  add_recurring_fields(post, options)
  add_custom_fields(post, options)
  add_line_items(post, options)
  add_test_mode(post, options)
  add_save_card(post, options)

  payment.respond_to?(:routing_number) ? commit(:check_purchase, post) : commit(:purchase, post)
end