-
Notifications
You must be signed in to change notification settings - Fork 1
/
payments.rb
48 lines (38 loc) · 1.36 KB
/
payments.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
# frozen_string_literal: true
module Tikkie
module Api
module Resources
# Resource for Payments.
class Payments < List
include Enumerable
attr_reader :payment_request_token
def initialize(config, options = {})
@payment_request_token = options.delete(:payment_request_token)
super(config, options)
end
def each(&block)
payments.each(&block)
end
private
def load_resource
params = { pageNumber: page_number, pageSize: page_size }
params[:fromDate] = options[:from_date].respond_to?(:utc) ? options[:from_date].utc.iso8601 : options[:from_date] if options.key?(:from_date)
params[:toDate] = options[:to_date].respond_to?(:utc) ? options[:to_date].utc.iso8601 : options[:to_date] if options.key?(:to_date)
params[:includeRefunds] = options[:include_refunds] if options.key?(:include_refunds)
request.get("paymentrequests/#{payment_request_token}/payments", params)
end
def payments
@payments ||= begin
payments = []
if body[:payments]
body[:payments].each do |payment|
payments << Tikkie::Api::Resources::Payment.new(config, body: payment)
end
end
payments
end
end
end
end
end
end