Class: Finswitz::Client
- Inherits:
-
Object
- Object
- Finswitz::Client
- Defined in:
- lib/finswitz.rb
Class Method Summary collapse
Instance Method Summary collapse
- #card_pricing ⇒ Object
- #convert_wallet(payload) ⇒ Object
- #create_api_key(payload) ⇒ Object
- #create_collection(payload) ⇒ Object
- #create_escrow_hold(payload, idempotency_key: nil) ⇒ Object
- #create_payment_link(payload, idempotency_key: nil) ⇒ Object
- #create_split_rule(payload, idempotency_key: nil) ⇒ Object
- #dashboard_options(options = {}) ⇒ Object
- #execute_vendor_settlement(id, payload = {}, idempotency_key: nil) ⇒ Object
- #fund_wallet(payload) ⇒ Object
- #get(path, **options) ⇒ Object
- #get_card_transaction(card_id, transaction_id) ⇒ Object
- #get_transaction(reference) ⇒ Object
-
#initialize(api_key: nil, dashboard_token: nil, base_url: DEFAULT_BASE_URL) ⇒ Client
constructor
A new instance of Client.
- #issue_card(payload, idempotency_key: nil) ⇒ Object
- #kyc ⇒ Object
- #list_api_keys ⇒ Object
- #list_banks(query: nil) ⇒ Object
- #list_card_transactions(card_id, query: nil) ⇒ Object
- #list_cards(query: nil) ⇒ Object
- #list_collection_payments(id) ⇒ Object
- #list_collections ⇒ Object
- #list_escrow_holds ⇒ Object
- #list_split_rules ⇒ Object
- #list_transactions(query: nil) ⇒ Object
- #list_vendor_settlements ⇒ Object
- #list_webhook_logs(query: nil) ⇒ Object
- #me ⇒ Object
- #mobile_money(payload, idempotency_key: nil) ⇒ Object
- #mock_charge(payload) ⇒ Object
- #patch(path, body = {}, **options) ⇒ Object
- #pay_collection(slug, payload) ⇒ Object
- #post(path, body = {}, **options) ⇒ Object
- #public_collection(slug) ⇒ Object
- #refund(reference, payload = {}, idempotency_key: nil) ⇒ Object
- #release_escrow_hold(id, payload = {}, idempotency_key: nil) ⇒ Object
- #request(method, path, body: nil, query: nil, idempotency_key: nil, token_type: :api, token: nil) ⇒ Object
- #request_compliance_review(payload = {}) ⇒ Object
- #revoke_api_key(id) ⇒ Object
- #simulate_webhook(payload) ⇒ Object
- #submit_kyc(payload) ⇒ Object
- #transfer(payload, idempotency_key: nil) ⇒ Object
- #treasury ⇒ Object
- #update_collection(id, payload) ⇒ Object
- #update_settlement(payload) ⇒ Object
- #update_split_rule(id, payload) ⇒ Object
- #update_webhooks(payload) ⇒ Object
- #verify_account(payload) ⇒ Object
- #verify_settlement_account(payload) ⇒ Object
- #wallet_funding_status(query: nil) ⇒ Object
- #wallets ⇒ Object
Constructor Details
#initialize(api_key: nil, dashboard_token: nil, base_url: DEFAULT_BASE_URL) ⇒ Client
Returns a new instance of Client.
23 24 25 26 27 |
# File 'lib/finswitz.rb', line 23 def initialize(api_key: nil, dashboard_token: nil, base_url: DEFAULT_BASE_URL) @api_key = api_key @dashboard_token = dashboard_token @base_url = base_url.sub(%r{/+$}, "") end |
Class Method Details
.parse_webhook(raw_body) ⇒ Object
111 112 113 |
# File 'lib/finswitz.rb', line 111 def self.parse_webhook(raw_body) raw_body.is_a?(String) ? JSON.parse(raw_body) : raw_body end |
Instance Method Details
#card_pricing ⇒ Object
72 |
# File 'lib/finswitz.rb', line 72 def card_pricing = get("/cards/pricing") |
#convert_wallet(payload) ⇒ Object
89 |
# File 'lib/finswitz.rb', line 89 def convert_wallet(payload) = post("/developers/wallets/convert", payload, **) |
#create_api_key(payload) ⇒ Object
81 |
# File 'lib/finswitz.rb', line 81 def create_api_key(payload) = post("/developers/keys", payload, **) |
#create_collection(payload) ⇒ Object
100 |
# File 'lib/finswitz.rb', line 100 def create_collection(payload) = post("/developers/collections", payload, **) |
#create_escrow_hold(payload, idempotency_key: nil) ⇒ Object
95 |
# File 'lib/finswitz.rb', line 95 def create_escrow_hold(payload, idempotency_key: nil) = post("/developers/treasury/escrow", payload, **(idempotency_key: idempotency_key)) |
#create_payment_link(payload, idempotency_key: nil) ⇒ Object
64 |
# File 'lib/finswitz.rb', line 64 def create_payment_link(payload, idempotency_key: nil) = post("/payments/payment-links", payload, idempotency_key: idempotency_key) |
#create_split_rule(payload, idempotency_key: nil) ⇒ Object
92 |
# File 'lib/finswitz.rb', line 92 def create_split_rule(payload, idempotency_key: nil) = post("/developers/treasury/split-rules", payload, **(idempotency_key: idempotency_key)) |
#dashboard_options(options = {}) ⇒ Object
78 |
# File 'lib/finswitz.rb', line 78 def ( = {}) = .merge(token_type: :dashboard) |
#execute_vendor_settlement(id, payload = {}, idempotency_key: nil) ⇒ Object
98 |
# File 'lib/finswitz.rb', line 98 def execute_vendor_settlement(id, payload = {}, idempotency_key: nil) = post("/developers/treasury/settlements/#{URI.encode_www_form_component(id)}/execute", payload, **(idempotency_key: idempotency_key)) |
#fund_wallet(payload) ⇒ Object
87 |
# File 'lib/finswitz.rb', line 87 def fund_wallet(payload) = post("/developers/wallets/fund", payload, **) |
#get(path, **options) ⇒ Object
58 |
# File 'lib/finswitz.rb', line 58 def get(path, **) = request(:get, path, **) |
#get_card_transaction(card_id, transaction_id) ⇒ Object
76 |
# File 'lib/finswitz.rb', line 76 def get_card_transaction(card_id, transaction_id) = get("/cards/#{URI.encode_www_form_component(card_id)}/transactions/#{URI.encode_www_form_component(transaction_id)}") |
#get_transaction(reference) ⇒ Object
67 |
# File 'lib/finswitz.rb', line 67 def get_transaction(reference) = get("/payments/#{URI.encode_www_form_component(reference)}") |
#issue_card(payload, idempotency_key: nil) ⇒ Object
73 |
# File 'lib/finswitz.rb', line 73 def issue_card(payload, idempotency_key: nil) = post("/cards/issue", payload, idempotency_key: idempotency_key) |
#kyc ⇒ Object
107 |
# File 'lib/finswitz.rb', line 107 def kyc = get("/developers/kyc", **) |
#list_api_keys ⇒ Object
80 |
# File 'lib/finswitz.rb', line 80 def list_api_keys = get("/developers/keys", **) |
#list_banks(query: nil) ⇒ Object
70 |
# File 'lib/finswitz.rb', line 70 def list_banks(query: nil) = get("/payments/banks", query: query) |
#list_card_transactions(card_id, query: nil) ⇒ Object
75 |
# File 'lib/finswitz.rb', line 75 def list_card_transactions(card_id, query: nil) = get("/cards/#{URI.encode_www_form_component(card_id)}/transactions", query: query) |
#list_cards(query: nil) ⇒ Object
74 |
# File 'lib/finswitz.rb', line 74 def list_cards(query: nil) = get("/cards", query: query) |
#list_collection_payments(id) ⇒ Object
102 |
# File 'lib/finswitz.rb', line 102 def list_collection_payments(id) = get("/developers/collections/#{URI.encode_www_form_component(id)}/payments", **) |
#list_collections ⇒ Object
99 |
# File 'lib/finswitz.rb', line 99 def list_collections = get("/developers/collections", **) |
#list_escrow_holds ⇒ Object
94 |
# File 'lib/finswitz.rb', line 94 def list_escrow_holds = get("/developers/treasury/escrow", **) |
#list_split_rules ⇒ Object
91 |
# File 'lib/finswitz.rb', line 91 def list_split_rules = get("/developers/treasury/split-rules", **) |
#list_transactions(query: nil) ⇒ Object
68 |
# File 'lib/finswitz.rb', line 68 def list_transactions(query: nil) = get("/payments", query: query) |
#list_vendor_settlements ⇒ Object
97 |
# File 'lib/finswitz.rb', line 97 def list_vendor_settlements = get("/developers/treasury/settlements", **) |
#list_webhook_logs(query: nil) ⇒ Object
84 |
# File 'lib/finswitz.rb', line 84 def list_webhook_logs(query: nil) = get("/developers/webhooks/logs", **(query: query)) |
#me ⇒ Object
79 |
# File 'lib/finswitz.rb', line 79 def me = get("/developers/me", **) |
#mobile_money(payload, idempotency_key: nil) ⇒ Object
65 |
# File 'lib/finswitz.rb', line 65 def mobile_money(payload, idempotency_key: nil) = post("/payments/mobile-money", payload, idempotency_key: idempotency_key) |
#mock_charge(payload) ⇒ Object
66 |
# File 'lib/finswitz.rb', line 66 def mock_charge(payload) = post("/payments/mock/charge", payload) |
#patch(path, body = {}, **options) ⇒ Object
60 |
# File 'lib/finswitz.rb', line 60 def patch(path, body = {}, **) = request(:patch, path, body: body, **) |
#pay_collection(slug, payload) ⇒ Object
104 |
# File 'lib/finswitz.rb', line 104 def pay_collection(slug, payload) = post("/public/collections/#{URI.encode_www_form_component(slug)}/pay", payload, token_type: :none) |
#post(path, body = {}, **options) ⇒ Object
59 |
# File 'lib/finswitz.rb', line 59 def post(path, body = {}, **) = request(:post, path, body: body, **) |
#public_collection(slug) ⇒ Object
103 |
# File 'lib/finswitz.rb', line 103 def public_collection(slug) = get("/public/collections/#{URI.encode_www_form_component(slug)}", token_type: :none) |
#refund(reference, payload = {}, idempotency_key: nil) ⇒ Object
69 |
# File 'lib/finswitz.rb', line 69 def refund(reference, payload = {}, idempotency_key: nil) = post("/payments/#{URI.encode_www_form_component(reference)}/refund", payload, idempotency_key: idempotency_key) |
#release_escrow_hold(id, payload = {}, idempotency_key: nil) ⇒ Object
96 |
# File 'lib/finswitz.rb', line 96 def release_escrow_hold(id, payload = {}, idempotency_key: nil) = post("/developers/treasury/escrow/#{URI.encode_www_form_component(id)}/release", payload, **(idempotency_key: idempotency_key)) |
#request(method, path, body: nil, query: nil, idempotency_key: nil, token_type: :api, token: nil) ⇒ Object
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 |
# File 'lib/finswitz.rb', line 29 def request(method, path, body: nil, query: nil, idempotency_key: nil, token_type: :api, token: nil) bearer = token || (token_type == :dashboard ? @dashboard_token : @api_key) raise ArgumentError, token_type == :dashboard ? "Missing dashboard_token." : "Missing api_key." if token_type != :none && !bearer uri = URI(@base_url + path) uri.query = URI.encode_www_form(query.reject { |_key, value| value.nil? }) if query && !query.empty? klass = Net::HTTP.const_get(method.to_s.capitalize) req = klass.new(uri) req["Accept"] = "application/json" req["Authorization"] = "Bearer #{bearer}" unless token_type == :none req["Idempotency-Key"] = idempotency_key if idempotency_key if body req["Content-Type"] = "application/json" req.body = JSON.generate(body) end res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https", read_timeout: 30) do |http| http.request(req) end data = res.body && !res.body.empty? ? JSON.parse(res.body) : nil unless res.code.to_i.between?(200, 299) = data.is_a?(Hash) && data["error"] ? data["error"] : "Finswitz API request failed with #{res.code}" raise ApiError.new(, status: res.code.to_i, response: data) end data end |
#request_compliance_review(payload = {}) ⇒ Object
109 |
# File 'lib/finswitz.rb', line 109 def request_compliance_review(payload = {}) = post("/developers/compliance/request-review", payload, **) |
#revoke_api_key(id) ⇒ Object
82 |
# File 'lib/finswitz.rb', line 82 def revoke_api_key(id) = post("/developers/keys/#{URI.encode_www_form_component(id)}/revoke", {}, **) |
#simulate_webhook(payload) ⇒ Object
85 |
# File 'lib/finswitz.rb', line 85 def simulate_webhook(payload) = post("/developers/webhooks/simulate", payload, **) |
#submit_kyc(payload) ⇒ Object
108 |
# File 'lib/finswitz.rb', line 108 def submit_kyc(payload) = post("/developers/kyc", payload, **) |
#transfer(payload, idempotency_key: nil) ⇒ Object
62 |
# File 'lib/finswitz.rb', line 62 def transfer(payload, idempotency_key: nil) = post("/payments/transfer", payload, idempotency_key: idempotency_key) |
#treasury ⇒ Object
90 |
# File 'lib/finswitz.rb', line 90 def treasury = get("/developers/treasury", **) |
#update_collection(id, payload) ⇒ Object
101 |
# File 'lib/finswitz.rb', line 101 def update_collection(id, payload) = patch("/developers/collections/#{URI.encode_www_form_component(id)}", payload, **) |
#update_settlement(payload) ⇒ Object
105 |
# File 'lib/finswitz.rb', line 105 def update_settlement(payload) = post("/developers/settlement", payload, **) |
#update_split_rule(id, payload) ⇒ Object
93 |
# File 'lib/finswitz.rb', line 93 def update_split_rule(id, payload) = patch("/developers/treasury/split-rules/#{URI.encode_www_form_component(id)}", payload, **) |
#update_webhooks(payload) ⇒ Object
83 |
# File 'lib/finswitz.rb', line 83 def update_webhooks(payload) = request(:put, "/developers/webhooks", body: payload, **) |
#verify_account(payload) ⇒ Object
63 |
# File 'lib/finswitz.rb', line 63 def verify_account(payload) = post("/payments/verify-account", payload) |
#verify_settlement_account(payload) ⇒ Object
106 |
# File 'lib/finswitz.rb', line 106 def verify_settlement_account(payload) = post("/developers/verify-account", payload, **) |
#wallet_funding_status(query: nil) ⇒ Object
88 |
# File 'lib/finswitz.rb', line 88 def wallet_funding_status(query: nil) = get("/developers/wallets/fund/status", **(query: query)) |
#wallets ⇒ Object
86 |
# File 'lib/finswitz.rb', line 86 def wallets = get("/developers/wallets", **) |