Class: Nihaopay::SecurePay::Base
- Inherits:
-
Object
- Object
- Nihaopay::SecurePay::Base
show all
- Includes:
- Api
- Defined in:
- lib/nihaopay/secure_pay/base.rb
Constant Summary
Constants included
from Api
Api::LIVE_HOST, Api::TEST_HOST, Api::VERSION
Class Method Summary
collapse
Methods included from Api
included
Class Method Details
.request_body(params = {}) ⇒ Object
42
43
44
|
# File 'lib/nihaopay/secure_pay/base.rb', line 42
def request_body(params = {})
params.map { |k, v| "#{k}=#{v}" }.join('&')
end
|
29
30
31
|
# File 'lib/nihaopay/secure_pay/base.rb', line 29
def
authorization
end
|
.request_params(amount, currency, options) ⇒ Object
33
34
35
36
37
38
39
40
|
# File 'lib/nihaopay/secure_pay/base.rb', line 33
def request_params(amount, currency, options)
{ amount: amount.to_i,
currency: currency.to_s,
vendor: vendor.to_s,
reference: options[:reference].to_s.slice(0, 30),
ipn_url: options[:ipn_url].to_s,
callback_url: options[:callback_url].to_s }
end
|
.request_url ⇒ Object
25
26
27
|
# File 'lib/nihaopay/secure_pay/base.rb', line 25
def request_url
"#{base_url}/transactions/securepay"
end
|
.start(amount, currency, options = {}) ⇒ Object
16
17
18
19
20
21
22
23
|
# File 'lib/nihaopay/secure_pay/base.rb', line 16
def start(amount, currency, options = {})
with_failure do
@token = options.delete(:token)
params = request_params(amount, currency, options)
body = request_body(params)
HTTParty.post(request_url, headers: , body: body)
end
end
|
.with_failure(&_) ⇒ Object
7
8
9
10
11
12
13
14
|
# File 'lib/nihaopay/secure_pay/base.rb', line 7
def with_failure(&_)
response = yield
if response.code != 200
message = response.parsed_response.map { |k, v| "#{k}: #{v}" }.join(', ')
fail SecurePayTransactionError, message
end
response
end
|