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.

Raises:



51
52
53
54
55
56
57
# File 'lib/zaala/api/client.rb', line 51

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

  res = call(:authorize, authorizationRequest: req.to_message)
  AuthorizationResponse.from_message(res.body[:authorizeResponse][:return])
end

#cancel_authorization(req) ⇒ Object

Cancel a previous reservation of funds.

Raises:



60
61
62
63
64
65
66
# File 'lib/zaala/api/client.rb', line 60

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 = call(:cancel_authorization, cancellationRequest: req.to_message)
  CancellationResponse.from_message(res.body[:cancelAuthorizationResponse][:return])
end

#check(req) ⇒ Object

Perform a solvency check.

Raises:



69
70
71
72
73
74
75
# File 'lib/zaala/api/client.rb', line 69

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

  res = call(:check, checkRequest: req.to_message)
  CheckResponse.from_message(res.body[:checkResponse][:return])
end

#credit_advice(req) ⇒ Object

Authorizes a credit transaction.

Raises:

  • (StandardError)


105
106
107
108
# File 'lib/zaala/api/client.rb', line 105

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

#info(req) ⇒ Object

Returns available information about an authorization-ID.

Raises:



78
79
80
81
82
83
84
# File 'lib/zaala/api/client.rb', line 78

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

  res = call(:info, infoRequest: req.to_message)
  InfoResponse.from_message(res.body[:infoResponse][:return])
end

#pre_authorize(req) ⇒ Object

Authorizes a reservation of funds for a future purchase.

Raises:



42
43
44
45
46
47
48
# 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 = call(:pre_authorize, authorizationRequest: req.to_message)
  AuthorizationResponse.from_message(res.body[:preAuthorizeResponse][:return])
end

#submit_authorization(req) ⇒ Object

Submits a purchase transaction with a previous authorization of funds.

Raises:



96
97
98
99
100
101
102
# File 'lib/zaala/api/client.rb', line 96

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

  res = call(:submit_authorization, submissionRequest: req.to_message)
  SubmissionResponse.from_message(res.body[:submitAuthorizationResponse][:return])
end

#verify(req) ⇒ Object

Verifies the given MTAN.

Raises:



87
88
89
90
91
92
93
# File 'lib/zaala/api/client.rb', line 87

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

  res = call(:verify, verifyRequest: req.to_message)
  VerifyResponse.from_message(res.body[:verifyResponse][:return])
end