Class: Zaala::API::Client
- Inherits:
-
Object
- Object
- Zaala::API::Client
- Defined in:
- lib/zaala/api/client.rb
Instance Method Summary collapse
-
#add_login_credentials(username, password) ⇒ Object
Authenticate API calls.
-
#authorize(req) ⇒ Object
Authorizes a purchase transaction.
-
#cancel_authorization(req) ⇒ Object
Cancel a previous reservation of funds.
-
#check(req) ⇒ Object
Perform a solvency check.
-
#credit_advice(req) ⇒ Object
Authorizes a credit transaction.
-
#info(req) ⇒ Object
Returns available information about an authorization-ID.
-
#initialize(wsdl:, username: '', password: '', log: false, proxy: nil) ⇒ Client
constructor
-
Args : -
wsdl
-> URL that points to the WSDL file -username
-> Username (optional) -password
-> Password (optional).
-
-
#pre_authorize(req) ⇒ Object
Authorizes a reservation of funds for a future purchase.
-
#submit_authorization(req) ⇒ Object
Submits a purchase transaction with a previous authorization of funds.
-
#verify(req) ⇒ Object
Verifies the given MTAN.
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 add_login_credentials(username, password) @kar = Savon.client(wsdl: wsdl, basic_auth: [username, password]) end |
#authorize(req) ⇒ Object
Authorizes a purchase transaction.
51 52 53 54 55 56 57 |
# File 'lib/zaala/api/client.rb', line 51 def (req) ensure_operation_exists(:authorize) raise BadRequestError.new("authorize operation requires an AuthorizationRequest parameter") unless req.is_a?(AuthorizationRequest) res = call(:authorize, authorizationRequest: req.) AuthorizationResponse.(res.body[:authorizeResponse][:return]) end |
#cancel_authorization(req) ⇒ Object
Cancel a previous reservation of funds.
60 61 62 63 64 65 66 |
# File 'lib/zaala/api/client.rb', line 60 def (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.) CancellationResponse.(res.body[:cancelAuthorizationResponse][:return]) end |
#check(req) ⇒ Object
Perform a solvency check.
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.) CheckResponse.(res.body[:checkResponse][:return]) end |
#credit_advice(req) ⇒ Object
Authorizes a credit transaction.
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.
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.) InfoResponse.(res.body[:infoResponse][:return]) end |
#pre_authorize(req) ⇒ Object
Authorizes a reservation of funds for a future purchase.
42 43 44 45 46 47 48 |
# File 'lib/zaala/api/client.rb', line 42 def (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.) AuthorizationResponse.(res.body[:preAuthorizeResponse][:return]) end |
#submit_authorization(req) ⇒ Object
Submits a purchase transaction with a previous authorization of funds.
96 97 98 99 100 101 102 |
# File 'lib/zaala/api/client.rb', line 96 def (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.) SubmissionResponse.(res.body[:submitAuthorizationResponse][:return]) end |
#verify(req) ⇒ Object
Verifies the given MTAN.
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.) VerifyResponse.(res.body[:verifyResponse][:return]) end |