-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpayment.rb
68 lines (53 loc) · 1.47 KB
/
payment.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# frozen_string_literal: true
require 'time'
module Tikkie
module Api
module Resources
# Resource for a Payment.
class Payment < Base
attr_reader :payment_request_token
def initialize(config, options = {})
@payment_request_token = options.delete(:payment_request_token)
@payment_token = options.delete(:payment_token)
super
end
def payment_token
@payment_token || body[:paymentToken]
end
def tikkie_id
body[:tikkieId]
end
def counter_party_name
body[:counterPartyName]
end
def counter_party_account_number
body[:counterPartyAccountNumber]
end
def amount
Tikkie::Api::Amount.from_cents(body[:amountInCents]).to_d
end
def description
body[:description]
end
def created_at
Time.parse(body[:createdDateTime]) if body[:createdDateTime]
end
def refunds
@refunds ||= begin
refunds = []
if body[:refunds]
body[:refunds].each do |refund|
refunds << Tikkie::Api::Resources::Refund.new(config, body: refund)
end
end
refunds
end
end
private
def load_resource
request.get("paymentrequests/#{payment_request_token}/payments/#{payment_token}", options)
end
end
end
end
end