Class: Tikkie::Api::V1::Requests::PaymentRequests

Inherits:
Object
  • Object
show all
Defined in:
lib/tikkie/api/v1/requests/payment_requests.rb

Overview

Payment requests operations at Tikkie.

Instance Method Summary collapse

Constructor Details

#initialize(request) ⇒ PaymentRequests

Returns a new instance of PaymentRequests.



11
12
13
# File 'lib/tikkie/api/v1/requests/payment_requests.rb', line 11

def initialize(request)
  @request = request
end

Instance Method Details

#create(platform_token, user_token, bank_account_token, options = {}) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/tikkie/api/v1/requests/payment_requests.rb', line 35

def create(platform_token, user_token, , options = {})
  params = {
    currency: options.fetch(:currency),
    description: options.fetch(:description)
  }
  params[:amountInCents] = to_cents(options[:amount]) if options.key?(:amount)
  params[:externalId] = options[:external_id] if options.key?(:external_id)

  response = @request.post("/tikkie/platforms/#{platform_token}/users/#{user_token}/bankaccounts/#{}/paymentrequests", params)

  Tikkie::Api::V1::Responses::PaymentRequestCreated.new(response)
end

#get(platform_token, user_token, payment_request_token) ⇒ Object



29
30
31
32
33
# File 'lib/tikkie/api/v1/requests/payment_requests.rb', line 29

def get(platform_token, user_token, payment_request_token)
  response = @request.get("/tikkie/platforms/#{platform_token}/users/#{user_token}/paymentrequests/#{payment_request_token}")

  Tikkie::Api::V1::Responses::PaymentRequest.new(response)
end

#list(platform_token, user_token, options = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/tikkie/api/v1/requests/payment_requests.rb', line 15

def list(platform_token, user_token, options = {})
  offset = options[:offset] || 0
  limit = options[:limit] || 20
  from_date = options[:from_date]
  to_date = options[:to_date]

  params = { offset: offset, limit: limit }
  params[:fromDate] = from_date.respond_to?(:utc) ? from_date.utc.iso8601 : from_date if from_date
  params[:toDate] = to_date.respond_to?(:utc) ? to_date.utc.iso8601 : to_date if to_date

  response = @request.get("/tikkie/platforms/#{platform_token}/users/#{user_token}/paymentrequests", params)
  Tikkie::Api::V1::Responses::PaymentRequests.new(response, offset: offset, limit: limit)
end