Class: Zaala::API::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/zaala/api/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(wsdl:, username: '', password: '', log: false, proxy: nil) ⇒ Client

  • Args :

    • wsdl -> URL that points to the WSDL file

    • username -> Username (optional)

    • password -> Password (optional)



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/zaala/api/client.rb', line 12

def initialize(wsdl:, username: '', password: '', log: false, proxy: nil)
  symbolize_keys = lambda { |key| key.to_sym }
  params = {
    wsdl: wsdl,
    open_timeout: 30, # seconds
    read_timeout: 30, # seconds
    convert_response_tags_to: symbolize_keys,
    log: log,
    proxy: proxy
  }

  @kar = if username != '' && password != ''
    Savon.client(params.merge({
      basic_auth: [username, password],
    }))
  else
    Savon.client(params)
  end
end

Instance Method Details

#add_login_credentials(username, password) ⇒ Object

Authenticate API calls

  • Args :

    • username -> Username

    • password -> Password



37
38
39
# File 'lib/zaala/api/client.rb', line 37

def (username, password)
  @kar = Savon.client(wsdl: wsdl, basic_auth: [username, password])
end

#authorize(req) ⇒ Object

Authorizes a purchase transaction.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/zaala/api/client.rb', line 58

def authorize(req)
  ensure_operation_exists(:authorize)
  raise BadRequestError.new("authorize operation requires an AuthorizationRequest parameter") unless req.is_a?(AuthorizationRequest)

  res = @kar.call(:authorize) do
    message(authorizationRequest: req.to_message)
  end
  AuthorizationResponse.from_message(res.body[:authorizeResponse][:return])
rescue Savon::SOAPFault => e
  # Extract bad request errors
  maybe_raise_invalid_fields(e.to_hash[:Fault])
  # Fallback to standard errro
  raise StandardError, e.to_hash.dig(:Fault, :faultstring)
end

#cancel_authorization(req) ⇒ Object

Cancel a previous reservation of funds.



74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/zaala/api/client.rb', line 74

def cancel_authorization(req)
  ensure_operation_exists(:cancel_authorization)
  raise BadRequestError.new("cancel_authorization operation requires a CancellationRequest parameter") unless req.is_a?(CancellationRequest)

  res = @kar.call(:cancel_authorization) do
    message(cancellationRequest: req.to_message)
  end
  CancellationResponse.from_message(res.body[:cancelAuthorizationResponse][:return])
rescue Savon::SOAPFault => e
  # Extract bad request errors
  maybe_raise_invalid_fields(e.to_hash[:Fault])
  # Fallback to standard errro
  raise StandardError, e.to_hash.dig(:Fault, :faultstring)
end

#check(req) ⇒ Object

Perform a solvency check.



90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/zaala/api/client.rb', line 90

def check(req)
  ensure_operation_exists(:check)
  raise BadRequestError.new("check operation requires a CheckRequest parameter") unless req.is_a?(CheckRequest)

  res = @kar.call(:check) do
    message(checkRequest: req.to_message)
  end
  CheckResponse.from_message(res.body[:checkResponse][:return])
rescue Savon::SOAPFault => e
  # Extract bad request errors
  maybe_raise_invalid_fields(e.to_hash[:Fault])
  # Fallback to standard errro
  raise StandardError, e.to_hash.dig(:Fault, :faultstring)
end

#credit_advice(req) ⇒ Object

Authorizes a credit transaction.

Raises:

  • (StandardError)


154
155
156
157
# File 'lib/zaala/api/client.rb', line 154

def credit_advice(req)
  ensure_operation_exists(:credit_advice)
  raise StandardError, 'unimplemented operation'
end

#info(req) ⇒ Object

Returns available information about an authorization-ID.



106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/zaala/api/client.rb', line 106

def info(req)
  ensure_operation_exists(:info)
  raise BadRequestError.new("info operation requires an InfoRequest parameter") unless req.is_a?(InfoRequest)

  res = @kar.call(:info) do
    message(infoRequest: req.to_message)
  end
  InfoResponse.from_message(res.body[:infoResponse][:return])
rescue Savon::SOAPFault => e
  # Extract bad request errors
  maybe_raise_invalid_fields(e.to_hash[:Fault])
  # Fallback to standard errro
  raise StandardError, e.to_hash.dig(:Fault, :faultstring)
end

#pre_authorize(req) ⇒ Object

Authorizes a reservation of funds for a future purchase.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/zaala/api/client.rb', line 42

def pre_authorize(req)
  ensure_operation_exists(:pre_authorize)
  raise BadRequestError.new("pre_authorize operation requires an AuthorizationRequest parameter") unless req.is_a?(AuthorizationRequest)

  res = @kar.call(:pre_authorize) do
    message(authorizationRequest: req.to_message)
  end
  AuthorizationResponse.from_message(res.body[:preAuthorizeResponse][:return])
rescue Savon::SOAPFault => e
  # Extract bad request errors
  maybe_raise_invalid_fields(e.to_hash[:Fault])
  # Fallback to standard errro
  raise StandardError, e.to_hash.dig(:Fault, :faultstring)
end

#submit_authorization(req) ⇒ Object

Submits a purchase transaction with a previous authorization of funds.



138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/zaala/api/client.rb', line 138

def submit_authorization(req)
  ensure_operation_exists(:submit_authorization)
  raise BadRequestError.new("info operation requires a SubmissionRequest parameter") unless req.is_a?(SubmissionRequest)

  res = @kar.call(:submit_authorization) do
    message(submissionRequest: req.to_message)
  end
  SubmissionResponse.from_message(res.body[:submitAuthorizationResponse][:return])
rescue Savon::SOAPFault => e
  # Extract bad request errors
  maybe_raise_invalid_fields(e.to_hash[:Fault])
  # Fallback to standard errro
  raise StandardError, e.to_hash.dig(:Fault, :faultstring)
end

#verify(req) ⇒ Object

Verifies the given MTAN.



122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/zaala/api/client.rb', line 122

def verify(req)
  ensure_operation_exists(:verify)
  raise BadRequestError.new("info operation requires a VerifyRequest parameter") unless req.is_a?(VerifyRequest)

  res = @kar.call(:verify) do
    message(verifyRequest: req.to_message)
  end
  VerifyResponse.from_message(res.body[:verifyResponse][:return])
rescue Savon::SOAPFault => e
  # Extract bad request errors
  maybe_raise_invalid_fields(e.to_hash[:Fault])
  # Fallback to standard errro
  raise StandardError, e.to_hash.dig(:Fault, :faultstring)
end