Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,10 @@ accounts = client.v2.accounts.list

# Update an account
updated_account = client.v2.accounts.update('account_id', description: 'Updated Description')

# Get the account certificate (signed download URL)
certificate = client.v2.accounts.certificate('account_id')
certificate.download_url
```

#### Account Numbers
Expand All @@ -461,6 +465,9 @@ updated_account_number = client.v2.account_numbers.update(
'account_number_id',
description: 'Updated account number'
)

# Get the certificate for an account number
certificate = client.v2.account_numbers.certificate('account_number_id')
```

#### Transfers
Expand Down
6 changes: 6 additions & 0 deletions lib/fintoc/v2/managers/account_numbers_manager.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'fintoc/v2/resources/account_number'
require 'fintoc/v2/resources/account_certificate'

module Fintoc
module V2
Expand Down Expand Up @@ -33,6 +34,11 @@ def delete(account_number_id)
_delete_account_number(account_number_id)
end

def certificate(account_number_id)
data = @client.get(version: :v2).call("account_numbers/#{account_number_id}/certificate")
Fintoc::V2::AccountCertificate.new(**data)
end

private

def _create_account_number(
Expand Down
6 changes: 6 additions & 0 deletions lib/fintoc/v2/managers/accounts_manager.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'fintoc/v2/resources/account'
require 'fintoc/v2/resources/account_certificate'

module Fintoc
module V2
Expand Down Expand Up @@ -27,6 +28,11 @@ def update(account_id, idempotency_key: nil, **params)
build_account(data)
end

def certificate(account_id)
data = @client.get(version: :v2).call("accounts/#{account_id}/certificate")
Fintoc::V2::AccountCertificate.new(**data)
end

private

def _create_account(entity_id:, description:, idempotency_key: nil, **params)
Expand Down
4 changes: 4 additions & 0 deletions lib/fintoc/v2/resources/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ def update(description: nil, idempotency_key: nil)
refresh_from_account(updated_account)
end

def certificate
@client.accounts.certificate(@id)
end

def active?
@status == 'active'
end
Expand Down
26 changes: 26 additions & 0 deletions lib/fintoc/v2/resources/account_certificate.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module Fintoc
module V2
class AccountCertificate
attr_reader :object, :account_id, :account_number_id, :download_url, :expires_at

def initialize(
object:,
account_id:,
account_number_id:,
download_url:,
expires_at: nil,
**
)
@object = object
@account_id = account_id
@account_number_id = account_number_id
@download_url = download_url
@expires_at = expires_at
end

def to_s
"📄 Account certificate (#{@account_number_id})"
end
end
end
end
4 changes: 4 additions & 0 deletions lib/fintoc/v2/resources/account_number.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ def update(description: nil, status: nil, metadata: nil, idempotency_key: nil)
refresh_from_account_number(updated_account_number)
end

def certificate
@client.account_numbers.certificate(@id)
end

def enabled?
@status == 'enabled'
end
Expand Down
7 changes: 7 additions & 0 deletions spec/fixtures/v2/account_certificate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"object": "account_certificate",
"account_id": "acc_31yYL7h9LVPg121AgFtCyJPDsgM",
"account_number_id": "acno_31yYL5uOb39vzvRIszPhoXYMjt4",
"download_url": "https://storage.example.com/account_certificates/certificate.pdf?signature=2d9a",
"expires_at": "2026-11-09T18:05:00Z"
}
71 changes: 71 additions & 0 deletions spec/lib/fintoc/v2/account_certificate_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
require 'json'
require 'webmock/rspec'
require 'fintoc/v2/client/client'

RSpec.describe Fintoc::V2::AccountCertificate do
let(:client) { Fintoc::V2::Client.new('sk_test_certificates') }
let(:payload) do
JSON.parse(File.read('spec/fixtures/v2/account_certificate.json'), symbolize_names: true)
end
let(:account_id) { payload[:account_id] }
let(:account_number_id) { payload[:account_number_id] }
let(:headers) { { 'Content-Type' => 'application/json' } }

before do
stub_request(:get, "https://api.fintoc.com/v2/accounts/#{account_id}/certificate")
.to_return(body: payload.to_json, headers: headers)
stub_request(:get, "https://api.fintoc.com/v2/account_numbers/#{account_number_id}/certificate")
.to_return(body: payload.to_json, headers: headers)
end

describe 'accounts manager #certificate' do
it 'returns the account certificate' do
expect(client.accounts.certificate(account_id))
.to be_a(described_class).and have_attributes(payload)
end
end

describe 'account numbers manager #certificate' do
it 'returns the account certificate' do
expect(client.account_numbers.certificate(account_number_id))
.to be_a(described_class).and have_attributes(payload)
end
end

describe 'Account#certificate' do
let(:account) do
Fintoc::V2::Account.new(
id: account_id, object: 'account', mode: 'test', description: 'Main',
available_balance: 0, currency: 'MXN', is_root: true,
root_account_number_id: account_number_id, root_account_number: '738969123456789120',
status: 'active', entity: {}, client:
)
end

it 'fetches the certificate of the account' do
expect(account.certificate).to be_a(described_class).and have_attributes(payload)
end
end

describe 'AccountNumber#certificate' do
let(:account_number) do
Fintoc::V2::AccountNumber.new(
id: account_number_id, object: 'account_number', description: 'Main',
number: '738969123456789120', created_at: '2026-11-09T18:00:00Z',
updated_at: '2026-11-09T18:00:00Z', mode: 'test', status: 'enabled', is_root: true,
account_id:, metadata: {}, client:
)
end

it 'fetches the certificate of the account number' do
expect(account_number.certificate).to be_a(described_class).and have_attributes(payload)
end
end

describe '#to_s' do
it 'does not expose the signed download URL' do
expect(described_class.new(**payload).to_s)
.to eq("📄 Account certificate (#{account_number_id})")
end
end
end
Loading