Module: PayTrace::Debug

Defined in:
lib/paytrace/debug.rb

Overview

Useful helper methods for debugging.

Class Method Summary collapse

Class Method Details

.configure_test(un = "demo123", pw = "demo123", domain = "stage.paytrace.com") ⇒ Object

Helper method to configure a default test environment. Accepts username, password, and domain parameters. domain defaults to “stage.paytrace.com” and the username/password default to the credentials for the sandbox account



50
51
52
53
54
55
56
# File 'lib/paytrace/debug.rb', line 50

def self.configure_test(un = "demo123", pw = "demo123", domain = "stage.paytrace.com")
  PayTrace.configure do |config|
    config.user_name = un
    config.password = pw
    config.domain = domain
  end
end

.dump_transactionObject

Helper that loops through the response values and dumps them out



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/paytrace/debug.rb', line 9

def self.dump_transaction
  puts "[REQUEST] #{PayTrace::API::Gateway.last_request}"
  response = PayTrace::API::Gateway.last_response_object
  if(response.has_errors?)
    response.errors.each do |key, value|
      puts "[RESPONSE] ERROR: #{key.ljust(20)}#{value}"
    end
  else
    response.values.each do |key, value|
      puts "[RESPONSE] #{key.ljust(20)}#{value}"
    end
  end
end

.log(msg) ⇒ Object

Formatted output for a text message.



24
25
26
# File 'lib/paytrace/debug.rb', line 24

def self.log(msg)
  puts ">>>>>>           #{msg}"
end

.trace(&block) ⇒ Object

Helper method to dump a request response pair. Usage: Usage:

PayTrace::Debug.trace do
# code the intiates a request/response pair
end

Note: also includes exception handling to ensure responses are dumped even if an exception occurs



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/paytrace/debug.rb', line 34

def self.trace(&block)
  PayTrace::API::Gateway.debug = true

  begin
    yield
  rescue Exception => e
    puts "[REQUEST] #{PayTrace::API::Gateway.last_request}"

    raise
  else
    dump_transaction
  end
end