Class: Paya::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/paya/base.rb

Instance Method Summary collapse

Instance Method Details

#check_number(options) ⇒ Object



124
125
126
127
128
# File 'lib/paya/base.rb', line 124

def check_number options
  <<xml
<CHECK_NUMBER>#{options[:check_number]}</CHECK_NUMBER>
xml
end

#consumer_info(options) ⇒ Object



120
121
122
# File 'lib/paya/base.rb', line 120

def consumer_info options
  options[:company_name].present? ? corporate_consumer(options) : non_corporate_consumer(options)
end

#corporate_consumer(options) ⇒ Object



130
131
132
133
134
# File 'lib/paya/base.rb', line 130

def corporate_consumer options
  <<xml
<COMPANY_NAME>#{options[:company_name]}</COMPANY_NAME>
xml
end

#data_packet(options = {}, identifier) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/paya/base.rb', line 69

def data_packet options={}, identifier
  identifier = options[:identifier] if options[:identifier].present?
  xml = <<xml
<AUTH_GATEWAY REQUEST_ID="#{options[:request_id]}">
<TRANSACTION>
<TRANSACTION_ID>#{options[:transaction_id]}</TRANSACTION_ID>
<MERCHANT>
<TERMINAL_ID>#{@terminal_id}</TERMINAL_ID>
</MERCHANT>
<PACKET>
<IDENTIFIER>#{identifier}</IDENTIFIER>
<ACCOUNT>
<ROUTING_NUMBER>#{options[:routing_number]}</ROUTING_NUMBER>
<ACCOUNT_NUMBER>#{options[:]}</ACCOUNT_NUMBER>
#{check_number(options) if options[:check_number].present?}
<ACCOUNT_TYPE>#{options[:]}</ACCOUNT_TYPE>
</ACCOUNT>
<CONSUMER>
#{consumer_info(options)}
<ADDRESS1>#{options[:address_1]}</ADDRESS1>
<ADDRESS2>#{options[:address_2]}</ADDRESS2>
<CITY>#{options[:city]}</CITY>
<STATE>#{options[:state]}</STATE>
<ZIP>#{options[:zip]}</ZIP>
<PHONE_NUMBER>#{options[:phone_number]}</PHONE_NUMBER>
<DL_STATE>#{options[:dl_state]}</DL_STATE>
<DL_NUMBER>#{options[:dl_number]}</DL_NUMBER>
<COURTESY_CARD_ID></COURTESY_CARD_ID>
#{identity_block options}
</CONSUMER>
<CHECK>
<CHECK_AMOUNT>#{options[:check_amount]}</CHECK_AMOUNT>
</CHECK>
</PACKET>
</TRANSACTION>
</AUTH_GATEWAY>
xml

  xml.gsub!("<", "&lt;").gsub!(">", "&gt;")
end

#get_archived_response(request_id) ⇒ Object Also known as: archived, get_archived, archived_response



57
58
59
60
61
62
63
# File 'lib/paya/base.rb', line 57

def get_archived_response request_id
  @terminal_id = terminal_id.to_s
  xml = Paya::GET_ARCHIVED_RESPONSE.gsub("&&&REQUEST_ID&&&", request_id).gsub("&&&TERMINAL_ID&&&", @terminal_id).gsub("&&&USER_NAME&&&", Paya.configuration.user_name).gsub("&&&PASSWORD", Paya.configuration.password)
  response = Paya.client.call(:get_archived_response, xml: xml)
  response_hash = Hash.from_xml(response.body[:get_archived_response])
  {request: xml, response: response_hash}
end

#identity_block(options) ⇒ Object



110
111
112
113
114
115
116
117
118
# File 'lib/paya/base.rb', line 110

def identity_block options
  if ["12", "13", "16", "17"].include? @terminal_id[2..3]
    <<xml
<IDENTITY>
<DOB_YEAR>#{options[:dob_year]}</DOB_YEAR>
</IDENTITY>
xml
  end
end

#non_corporate_consumer(options) ⇒ Object



136
137
138
139
140
141
# File 'lib/paya/base.rb', line 136

def non_corporate_consumer options
  <<xml
<FIRST_NAME>#{options[:first_name]}</FIRST_NAME>
<LAST_NAME>#{options[:last_name]}</LAST_NAME>
xml
end

#process(options, type = :ccd, guaranteed = true, debit_only = true, check_verification = false, identity_verification = false, dl_required = false) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/paya/base.rb', line 4

def process options, type=:ccd, guaranteed=true, debit_only=true, check_verification=false, identity_verification=false, dl_required=false
  type = type.to_s.capitalize
  sub_type = guaranteed ? 'Guaranteed' : 'NonGuaranteed'
  payment_type = debit_only ? 'DebitTransaction' : 'CreditDebitTransaction'

  handler = "Paya::#{type}::#{sub_type}::#{payment_type}".contantize
  handler.new options
  handler.process check_verification, identity_verification, dl_required
end

#process_single_ccd_check(options = {}, identifier = 'R') ⇒ Object



14
15
16
# File 'lib/paya/base.rb', line 14

def process_single_ccd_check options={}, identifier='R'
  process_single_check options, Paya.configuration.ccd_terminal_id, identifier
end

#process_single_certification_check(options = {}, terminal_id = nil, identifier = 'R') ⇒ Object



48
49
50
51
52
53
54
55
# File 'lib/paya/base.rb', line 48

def process_single_certification_check options={}, terminal_id=nil, identifier='R'
  @terminal_id = terminal_id.to_s
  @data_packet = data_packet(options, identifier)
  xml = Paya::PROCESS_SINGLE_CERTIFICATION_CHECK.gsub("&&&DATA_PACKET&&&", @data_packet).gsub("&&&TERMINAL_ID&&&", @terminal_id).gsub("&&&USER_NAME&&&", Paya.configuration.user_name).gsub("&&&PASSWORD&&&", Paya.configuration.password)
  response = Paya.client.call(:process_single_certification_check, xml: xml)
  response = Hash.from_xml(response.body[:process_single_certification_check_response][:process_single_certification_check_result])
  {request: xml, response: response}
end

#process_single_check(options = {}, terminal_id = nil, identifier = 'R') ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/paya/base.rb', line 30

def process_single_check options={}, terminal_id=nil, identifier='R'
  @terminal_id = terminal_id.to_s
  @data_packet = data_packet(options, identifier)
  xml = Paya::PROCESS_SINGLE_CHECK.gsub("&&&DATA_PACKET&&&", @data_packet).gsub("&&&TERMINAL_ID&&&", @terminal_id).gsub("&&&USER_NAME&&&", Paya.configuration.user_name).gsub("&&&PASSWORD&&&", Paya.configuration.password)
  response = Paya.client.call(:process_single_check, xml: xml)
  response_hash = Hash.from_xml(response.body[:process_single_check_response][:process_single_check_result])
  {request: xml, response: response_hash}
end

#process_single_check_with_tokenObject



39
40
41
42
43
44
45
46
# File 'lib/paya/base.rb', line 39

def process_single_check_with_token
  @terminal_id = terminal_id.to_s
  @data_packet = data_packet(options, identifier)
  xml = Paya::PROCESS_SINGLE_CERTIFICATION_CHECK.gsub("&&&DATA_PACKET&&&", @data_packet).gsub("&&&TERMINAL_ID&&&", @terminal_id).gsub("&&&USER_NAME&&&", Paya.configuration.user_name).gsub("&&&PASSWORD&&&", Paya.configuration.password)
  response = Paya.client.call(:process_single_certification_check, xml: xml)
  response_hash = Hash.from_xml(response.body[:process_single_certification_check_response][:process_single_certification_check_result])
  {request: xml, response: response_hash}
end

#process_single_ppd_check(options = {}, identifier = 'R') ⇒ Object



18
19
20
# File 'lib/paya/base.rb', line 18

def process_single_ppd_check options={}, identifier='R'
  process_single_check options, Paya.configuration.ppd_terminal_id, identifier
end

#process_single_tel_check(options = {}, identifier = 'R') ⇒ Object



26
27
28
# File 'lib/paya/base.rb', line 26

def process_single_tel_check options={}, identifier='R'
  process_single_check options, Paya.configuration.tel_terminal_id, identifier
end

#process_single_web_check(options = {}, identifier = 'R') ⇒ Object



22
23
24
# File 'lib/paya/base.rb', line 22

def process_single_web_check options={}, identifier='R'
  process_single_check options, Paya.configuration.web_terminal_id, identifier
end