Class: Giact::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/giact/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.

Parameters:

  • options (Hash) (defaults to: {})

    method options

Options Hash (options):

  • :gateway (Integer)

    Number (1-3) of gateway server to use

  • :company_id (String)

    Your Giact company ID

  • :username (String)

    Your Giact API username

  • :password (String)

    Your Giact API password



13
14
15
16
17
18
19
20
# File 'lib/giact/client.rb', line 13

def initialize(options={})
  options[:gateway] ||= 1
  self.class.base_uri("https://gatewaydtx#{options[:gateway]}.giact.com/RealTime/POST/RealTimeChecks.asmx")
  
  @company_id ||= Giact.company_id ||= options[:company_id]
  @username ||= Giact.username ||= options[:username]
  @password ||= Giact.password ||= options[:password]
end

Instance Attribute Details

#company_idObject (readonly)

Returns the value of attribute company_id.



6
7
8
# File 'lib/giact/client.rb', line 6

def company_id
  @company_id
end

Instance Method Details

#cancel_recurring(options = {}) ⇒ Object

Parameters:

  • options (Hash) (defaults to: {})

    method options

Options Hash (options):

  • :transaction_id (String)

    Transaction ID for which to cancel checks

  • :order_id (String)

    Order ID for which to cancel checks



107
108
109
110
111
112
113
114
115
# File 'lib/giact/client.rb', line 107

def cancel_recurring(options={})
  
  path = "/CancelRecurringBy#{options.keys.first.to_s.camelize.gsub(/Id$/, "ID")}"
  options.merge!(:company_id => self.company_id, :token => self.token)
  options.camelize_keys!
  
  response = self.class.post(path, :body => options)['string']
  Giact::CancelRecurringCheckList.from_response(response)
end

#installments_payments(payment_request) ⇒ Giact::PaymentReply

Process installment payments

Parameters:

Returns:

Raises:



79
80
81
82
83
84
85
86
87
88
89
# File 'lib/giact/client.rb', line 79

def installments_payments(payment_request)
  payment_request.merge!(:company_id => self.company_id, :token => self.token)
  raise Giact::InvalidRequest.new(payment_request.errors.full_messages) if not payment_request.is_a?(Giact::InstallmentPaymentRequest) or not payment_request.valid?
  
  response = self.class.post("/InstallmentsPayments", :body => payment_request.to_request_hash)
  if reply = response['string']
    Giact::PaymentReply.new(reply)
  else
    
  end
end

#loginString

Return an authentication token

Returns:

  • (String)

    authentication token



26
27
28
29
30
31
32
33
34
# File 'lib/giact/client.rb', line 26

def 
  response = self.class.post("/Login", :body => {:companyID => @company_id, :un => @username, :pw => @password})
  if auth_token = response['string']
    @token = auth_token
  else
    raise Giact::Unauthorized.new(response.body)
    
  end
end

#recurring_checks(options = {}) ⇒ Object

Parameters:

  • options (Hash) (defaults to: {})

    method options

Options Hash (options):

  • :transaction_id (String)

    Transaction ID to list checks

  • :order_id (String)

    Order ID to list checks



94
95
96
97
98
99
100
101
102
# File 'lib/giact/client.rb', line 94

def recurring_checks(options={})
  
  path = "/RecurringChecksBy#{options.keys.first.to_s.camelize.gsub(/Id$/, "ID")}"
  options.merge!(:company_id => self.company_id, :token => self.token)
  options.camelize_keys!
  
  response = self.class.post(path, :body => options)['string']
  Giact::RecurringCheckList.from_response(response)
end

#recurring_payments(payment_request) ⇒ Giact::PaymentReply

Process recurring payments

Parameters:

Returns:

Raises:



63
64
65
66
67
68
69
70
71
72
73
# File 'lib/giact/client.rb', line 63

def recurring_payments(payment_request)
  payment_request.merge!(:company_id => self.company_id, :token => self.token)
  raise Giact::InvalidRequest.new(payment_request.errors.full_messages) if not payment_request.is_a?(Giact::RecurringPaymentRequest) or not payment_request.valid?
  
  response = self.class.post("/RecurringPayments", :body => payment_request.to_request_hash)
  if reply = response['string']
    Giact::PaymentReply.new(reply)
  else
    
  end
end

#search_transactions(options = {}) ⇒ Object

Parameters:

  • options (Hash) (defaults to: {})

    method options

Options Hash (options):

  • :name_on_check (String)

    Name on check to search

  • :customer_id (String)

    Customer ID to search

  • :order_id (String)

    Order ID to search



122
123
124
125
126
127
128
129
130
# File 'lib/giact/client.rb', line 122

def search_transactions(options={})
  
  path = "/TransactionsBy#{options.keys.first.to_s.camelize.gsub(/Id$/, "ID")}"
  options.merge!(:company_id => self.company_id, :token => self.token)
  options.camelize_keys!
  
  response = self.class.post(path, :body => options)['string']
  Giact::TransactionResult.from_response(response)
end

#single_payment(payment_request) ⇒ Giact::PaymentReply

Process a single payment

Parameters:

Returns:

Raises:



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/giact/client.rb', line 47

def single_payment(payment_request)
  payment_request.merge!(:company_id => self.company_id, :token => self.token)
  raise Giact::InvalidRequest.new(payment_request.errors.full_messages) unless payment_request.valid?
  
  response = self.class.post("/SinglePayment", :body => payment_request.to_request_hash)
  if reply = response['string']
    Giact::PaymentReply.new(reply)
  else
    raise response.body
  end
end

#tokenString

Returns current authentication token or calls login

Returns:

  • (String)

    authentication token



39
40
41
# File 'lib/giact/client.rb', line 39

def token
  @token ||= self.
end