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
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
- [Disputes](#disputes)
- [Links](#links)
- [Refresh intents](#refresh-intents)
- [Organizations](#organizations)
- [Webhook Signature Validation](#webhook-signature-validation)
- [Idempotency Keys](#idempotency-keys)
- [Serialization](#serialization)
Expand Down Expand Up @@ -419,6 +420,22 @@ const refreshIntent = await fintocClient.refreshIntents.create({
});
```

### Organizations

Creating an organization requires a JWS private key and a live API key. It returns the created organization, or the existing one if it was already created:

```javascript
const fintocClient = new Fintoc('your_api_key', 'path/to/private_key.pem');

const organization = await fintocClient.organizations.create({
name: 'Empresa SpA',
tax_id: '11.111.111-1',
founder_email: 'jared@piedpiper.com',
products: { business_accounts: {} },
external_reference: 'SOL-123',
});
```

### Webhook Signature Validation

To ensure the authenticity of incoming webhooks from Fintoc, you should always validate the signature. The SDK provides a `WebhookSignature` class to verify the `Fintoc-Signature` header
Expand Down
3 changes: 3 additions & 0 deletions src/lib/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
InvoicesManager,
LinkIntentsManager,
LinksManager,
OrganizationsManager,
PaymentIntentsManager,
PaymentLinksManager,
PayoutsManager,
Expand Down Expand Up @@ -96,6 +97,7 @@ export class Fintoc {
invoices: InvoicesManager;
linkIntents: LinkIntentsManager;
links: LinksManager;
organizations: OrganizationsManager;
paymentIntents: PaymentIntentsManager;
paymentLinks: PaymentLinksManager;
payouts: PayoutsManager;
Expand Down Expand Up @@ -126,6 +128,7 @@ export class Fintoc {
this.invoices = new InvoicesManager('/v1/invoices', this.#client);
this.linkIntents = new LinkIntentsManager('/v1/link_intents', this.#client);
this.links = new LinksManager('/v1/links', this.#client);
this.organizations = new OrganizationsManager('/v1/organizations', this.#client);
this.paymentIntents = new PaymentIntentsManager('/v1/payment_intents', this.#client);
this.paymentLinks = new PaymentLinksManager('/v1/payment_links', this.#client);
this.payouts = new PayoutsManager('/v1/payouts', this.#client);
Expand Down
1 change: 1 addition & 0 deletions src/lib/managers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export * from './disputesManager';
export * from './eventsManager';
export * from './invoicesManager';
export * from './linksManager';
export * from './organizationsManager';
export * from './movementsManager';
export * from './paymentIntentsManager';
export * from './paymentLinksManager';
Expand Down
7 changes: 7 additions & 0 deletions src/lib/managers/organizationsManager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { ManagerMixin } from '../mixins';
import { Organization } from '../resources/organization';

export class OrganizationsManager extends ManagerMixin<Organization> {
static resource = 'organization';
static methods = ['create'];
}
3 changes: 3 additions & 0 deletions src/lib/resources/organization.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { ResourceMixin } from '../mixins/resourceMixin';

export class Organization extends ResourceMixin<Organization> {}
37 changes: 37 additions & 0 deletions src/spec/integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,43 @@ test('fintoc.refunds.cancel()', async (t) => {
t.is(refund.headers['Idempotency-Key'], 'idem_123');
});

test('fintoc.organizations.create()', async (t) => {
const ctx: any = t.context;
const organizationData = {
name: 'Empresa SpA',
tax_id: '11.111.111-1',
founder_email: 'founder@example.com',
products: { business_accounts: {} },
external_reference: 'ref_123',
};
const organization = await ctx.fintoc.organizations.create(organizationData);

t.is(organization.method, 'post');
t.is(organization.url, 'v1/organizations');
t.is(organization.json.name, organizationData.name);
t.is(organization.json.tax_id, organizationData.tax_id);
t.is(organization.json.founder_email, organizationData.founder_email);
t.truthy(organization.json.products.business_accounts);
t.is(organization.json.external_reference, organizationData.external_reference);
t.true(organization.headers['Idempotency-Key'] && organization.headers['Idempotency-Key'].length > 0);
});

test('fintoc.organizations.create() with idempotency key', async (t) => {
const ctx: any = t.context;
const organization = await ctx.fintoc.organizations.create({
name: 'Empresa SpA',
tax_id: '11.111.111-1',
founder_email: 'founder@example.com',
products: { business_accounts: {} },
idempotency_key: 'idem_123',
});

t.is(organization.method, 'post');
t.is(organization.url, 'v1/organizations');
t.is(organization.headers['Idempotency-Key'], 'idem_123');
t.is(organization.json.idempotency_key, undefined);
});

test('fintoc.disputes.list()', async (t) => {
const ctx: any = t.context;
const disputes = await ctx.fintoc.disputes.list();
Expand Down
Loading