Class: Plaid::BankTransfer::Event::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/plaid/bank_transfer/event/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ void

Parameters:



10
11
12
# File 'lib/plaid/bank_transfer/event/client.rb', line 10

def initialize(client:)
  @client = client
end

Instance Method Details

#list(request_options: {}, **params) ⇒ Plaid::Internal::OffsetItemIterator

Use the /bank_transfer/event/list endpoint to get a list of Plaid-initiated ACH or bank transfer events based on specified filter criteria. When using Auth with micro-deposit verification enabled, this endpoint can be used to fetch status updates on ACH micro-deposits. For more details, see micro-deposit events.

Returns a Plaid::Internal::OffsetItemIterator that yields each Plaid::Types::BankTransferEvent in the bank_transfer_events field of every page, requesting pages as they are needed. Call pages on it to get each page as a Plaid::Types::BankTransferEventListResponse, including its other fields.

No request is sent by this call. The first page is requested when you start iterating (or call load_first_page), so an API error is raised by the loop (or by load_first_page), not by this call.

Examples:

client.bank_transfer.event.list

Parameters:

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Returns:



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
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/plaid/bank_transfer/event/client.rb', line 38

def list(request_options: {}, **params)
  params = Plaid::Internal::Types::Utils.normalize_keys(params)
  Plaid::Internal::OffsetItemIterator.new(
    initial_page: params[:offset],
    item_field: :bank_transfer_events,
    has_next_field: nil,
    step: true
  ) do |next_page|
    params[:offset] = next_page
    request = Plaid::Internal::JSON::Request.new(
      base_url: request_options[:base_url],
      method: "POST",
      path: "bank_transfer/event/list",
      body: Plaid::BankTransfer::Event::Types::BankTransferEventListRequest.new(params).to_h,
      request_options: request_options
    )
    begin
      response = @client.send(request)
    rescue Net::HTTPRequestTimeout
      raise Plaid::Errors::TimeoutError
    end
    code = response.code.to_i
    if code.between?(200, 299)
      begin
        parsed_response = (response.body.to_s.empty? ? nil : Plaid::Types::BankTransferEventListResponse.load(response.body))
      rescue ::JSON::ParserError
        raise Plaid::Errors::ResponseError.new(response.body, code: code, headers: response.to_hash)
      end
      [parsed_response, response]
    else
      error_class = Plaid::Errors::ResponseError.subclass_for_code(code)
      error_types = {
        400 => Plaid::Types::PlaidError,
        401 => Plaid::Types::PlaidError,
        429 => Plaid::Types::PlaidError,
        500 => Plaid::Types::PlaidError,
        (400..499) => Plaid::Types::PlaidError,
        (500..599) => Plaid::Types::PlaidError
      }
      error_body = Plaid::Errors::ResponseError.load_error_body(code, response.body, error_types)
      raise error_class.new(response.body, code: code, body: error_body, headers: response.to_hash)
    end
  end
end

#sync(request_options: {}, **params) ⇒ Plaid::Types::BankTransferEventSyncResponse

/bank_transfer/event/sync allows you to request up to the next 25 Plaid-initiated bank transfer events that happened after a specific event_id. When using Auth with micro-deposit verification enabled, this endpoint can be used to fetch status updates on ACH micro-deposits. For more details, see micro-deposit events.

Examples:

client.bank_transfer.event.sync(after_id: 1)

Parameters:

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Returns:



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/plaid/bank_transfer/event/client.rb', line 100

def sync(request_options: {}, **params)
  params = Plaid::Internal::Types::Utils.normalize_keys(params)
  request = Plaid::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "POST",
    path: "bank_transfer/event/sync",
    body: Plaid::BankTransfer::Event::Types::BankTransferEventSyncRequest.new(params).to_h,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Plaid::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    begin
      (response.body.to_s.empty? ? nil : Plaid::Types::BankTransferEventSyncResponse.load(response.body))
    rescue ::JSON::ParserError
      raise Plaid::Errors::ResponseError.new(response.body, code: code, headers: response.to_hash)
    end
  else
    error_class = Plaid::Errors::ResponseError.subclass_for_code(code)
    error_types = {
      400 => Plaid::Types::PlaidError,
      401 => Plaid::Types::PlaidError,
      429 => Plaid::Types::PlaidError,
      500 => Plaid::Types::PlaidError,
      (400..499) => Plaid::Types::PlaidError,
      (500..599) => Plaid::Types::PlaidError
    }
    error_body = Plaid::Errors::ResponseError.load_error_body(code, response.body, error_types)
    raise error_class.new(response.body, code: code, body: error_body, headers: response.to_hash)
  end
end