Class: Nihaopay::Transactions::Base
- Inherits:
-
Object
- Object
- Nihaopay::Transactions::Base
- Defined in:
- lib/nihaopay/transactions/base.rb
Constant Summary
Constants included from Queryable
Constants included from Api
Api::LIVE_HOST, Api::TEST_HOST, Api::VERSION
Instance Attribute Summary collapse
-
#amount ⇒ Object
Returns the value of attribute amount.
-
#captured ⇒ Object
Returns the value of attribute captured.
-
#currency ⇒ Object
Returns the value of attribute currency.
-
#note ⇒ Object
Returns the value of attribute note.
-
#reference ⇒ Object
Returns the value of attribute reference.
-
#status ⇒ Object
Returns the value of attribute status.
-
#time ⇒ Object
Returns the value of attribute time.
-
#token ⇒ Object
Returns the value of attribute token.
-
#transaction_id ⇒ Object
Returns the value of attribute transaction_id.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
- .build(options = {}) ⇒ Object
- .build_from_response!(response) ⇒ Object
- .request_body(params = {}) ⇒ Object
- .request_headers ⇒ Object
- .response_keys_map ⇒ Object
- .valid_attributes ⇒ Object
Instance Method Summary collapse
- #cancel ⇒ Object
- #capture ⇒ Object
-
#initialize(attributes = {}) ⇒ Base
constructor
A new instance of Base.
- #partial_capture(capture_amount) ⇒ Object
- #partial_refund(refund_amount, options = {}) ⇒ Object
- #refund(options = {}) ⇒ Object
- #release ⇒ Object
Methods included from Queryable
Methods included from Api
Constructor Details
#initialize(attributes = {}) ⇒ Base
Returns a new instance of Base.
10 11 12 |
# File 'lib/nihaopay/transactions/base.rb', line 10 def initialize(attributes = {}) assign_attributes(attributes) end |
Instance Attribute Details
#amount ⇒ Object
Returns the value of attribute amount.
8 9 10 |
# File 'lib/nihaopay/transactions/base.rb', line 8 def amount @amount end |
#captured ⇒ Object
Returns the value of attribute captured.
8 9 10 |
# File 'lib/nihaopay/transactions/base.rb', line 8 def captured @captured end |
#currency ⇒ Object
Returns the value of attribute currency.
8 9 10 |
# File 'lib/nihaopay/transactions/base.rb', line 8 def currency @currency end |
#note ⇒ Object
Returns the value of attribute note.
8 9 10 |
# File 'lib/nihaopay/transactions/base.rb', line 8 def note @note end |
#reference ⇒ Object
Returns the value of attribute reference.
8 9 10 |
# File 'lib/nihaopay/transactions/base.rb', line 8 def reference @reference end |
#status ⇒ Object
Returns the value of attribute status.
7 8 9 |
# File 'lib/nihaopay/transactions/base.rb', line 7 def status @status end |
#time ⇒ Object
Returns the value of attribute time.
8 9 10 |
# File 'lib/nihaopay/transactions/base.rb', line 8 def time @time end |
#token ⇒ Object
Returns the value of attribute token.
7 8 9 |
# File 'lib/nihaopay/transactions/base.rb', line 7 def token @token end |
#transaction_id ⇒ Object
Returns the value of attribute transaction_id.
7 8 9 |
# File 'lib/nihaopay/transactions/base.rb', line 7 def transaction_id @transaction_id end |
#type ⇒ Object
Returns the value of attribute type.
7 8 9 |
# File 'lib/nihaopay/transactions/base.rb', line 7 def type @type end |
Class Method Details
.build(options = {}) ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/nihaopay/transactions/base.rb', line 54 def build( = {}) = Nihaopay::HashUtil.symbolize_keys() attributes = Nihaopay::HashUtil.slice(, *valid_attributes) attributes[:token] ||= merchant_token attributes[:time] = attributes[:time] ? Time.parse(attributes[:time]) : Time.now response_keys_map.each { |k, v| attributes[v] = [k] } new(attributes) end |
.build_from_response!(response) ⇒ Object
49 50 51 52 |
# File 'lib/nihaopay/transactions/base.rb', line 49 def build_from_response!(response) validate_resource!(response) build(response.parsed_response) end |
.request_body(params = {}) ⇒ Object
45 46 47 |
# File 'lib/nihaopay/transactions/base.rb', line 45 def request_body(params = {}) params.map { |k, v| "#{k}=#{v}" }.join('&') end |
.request_headers ⇒ Object
41 42 43 |
# File 'lib/nihaopay/transactions/base.rb', line 41 def request_headers .merge('Content-Type' => 'application/x-www-form-urlencoded') end |
.response_keys_map ⇒ Object
67 68 69 |
# File 'lib/nihaopay/transactions/base.rb', line 67 def response_keys_map { id: :transaction_id } end |
.valid_attributes ⇒ Object
63 64 65 |
# File 'lib/nihaopay/transactions/base.rb', line 63 def valid_attributes %i[token transaction_id type status captured currency reference amount note time].freeze end |
Instance Method Details
#cancel ⇒ Object
26 27 28 |
# File 'lib/nihaopay/transactions/base.rb', line 26 def cancel Nihaopay::Transactions::Cancel.start(transaction_id, token: token) end |
#capture ⇒ Object
14 15 16 |
# File 'lib/nihaopay/transactions/base.rb', line 14 def capture Nihaopay::Transactions::Capture.start(transaction_id, amount, currency, token: token) end |
#partial_capture(capture_amount) ⇒ Object
18 19 20 |
# File 'lib/nihaopay/transactions/base.rb', line 18 def partial_capture(capture_amount) Nihaopay::Transactions::Capture.start(transaction_id, capture_amount, currency, token: token) end |
#partial_refund(refund_amount, options = {}) ⇒ Object
35 36 37 38 |
# File 'lib/nihaopay/transactions/base.rb', line 35 def partial_refund(refund_amount, = {}) [:token] = token Nihaopay::Transactions::Refund.start(transaction_id, refund_amount, currency, ) end |
#refund(options = {}) ⇒ Object
30 31 32 33 |
# File 'lib/nihaopay/transactions/base.rb', line 30 def refund( = {}) [:token] = token Nihaopay::Transactions::Refund.start(transaction_id, amount, currency, ) end |
#release ⇒ Object
22 23 24 |
# File 'lib/nihaopay/transactions/base.rb', line 22 def release Nihaopay::Transactions::Release.start(transaction_id, token: token) end |