Class: PaygatePk::Providers::PayFast::Tokenization::Instrument

Inherits:
Client
  • Object
show all
Defined in:
lib/paygate_pk/providers/pay_fast/tokenization/instrument.rb

Overview

used to generate the bearer_token

Constant Summary collapse

INSTRUMENTS_ENDPOINT =
"/api/user/instruments"

Instance Method Summary collapse

Methods inherited from Client

#create_checkout, #get_access_token, #get_bearer_token, #initialize, #instruments, #verify_ipn!

Constructor Details

This class inherits a constructor from PaygatePk::Providers::PayFast::Client

Instance Method Details

#list(token:, user_id:, mobile_number:, options: {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/paygate_pk/providers/pay_fast/tokenization/instrument.rb', line 11

def list(token:, user_id:, mobile_number:, options: {})
  ensure_present!(token: token,
                  user_id: user_id,
                  mobile_number: mobile_number)

  resp = http.get(INSTRUMENTS_ENDPOINT,
                  params: body(user_id, mobile_number, options),
                  headers: { "Authorization" => "Bearer #{token}" })

  # Response is an array of hashes with instrument_token, account_type, description, instrument_alias
  Array(resp).map do |h|
    PaygatePk::Contracts::Instrument.new(
      instrument_token: h["instrument_token"],
      account_type: h["account_type"],
      description: h["description"],
      instrument_alias: h["instrument_alias"],
      raw: h
    )
  end
end