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
9 changes: 9 additions & 0 deletions src/lib/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@ import {
AccountVerificationsManager,
CustomersManager,
EntitiesManager,
PaymentMethodsManager,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ no sé por qué te molesta por esto

SimulateManager,
TransfersManager,
AccountsManager as V2AccountsManager,
CheckoutSessionsManager as V2CheckoutSessionsManager,
InvoicesManager as V2InvoicesManager,
PaymentIntentsManager as V2PaymentIntentsManager,
SubscriptionsManager as V2SubscriptionsManager,
} from './managers/v2';
import { version } from './version';

Expand All @@ -35,21 +38,27 @@ class FintocV2 {
accountNumbers: AccountNumbersManager;
simulate: SimulateManager;
entities: EntitiesManager;
invoices: V2InvoicesManager;
accountVerifications: AccountVerificationsManager;
customers: CustomersManager;
checkoutSessions: V2CheckoutSessionsManager;
paymentIntents: V2PaymentIntentsManager;
paymentMethods: PaymentMethodsManager;
subscriptions: V2SubscriptionsManager;

constructor(client: Client) {
this.accounts = new V2AccountsManager('/v2/accounts', client);
this.transfers = new TransfersManager('/v2/transfers', client);
this.accountNumbers = new AccountNumbersManager('/v2/account_numbers', client);
this.simulate = new SimulateManager('/v2/simulate', client);
this.entities = new EntitiesManager('/v2/entities', client);
this.invoices = new V2InvoicesManager('/v2/invoices', client);
this.accountVerifications = new AccountVerificationsManager('/v2/account_verifications', client);
this.customers = new CustomersManager('/v2/customers', client);
this.checkoutSessions = new V2CheckoutSessionsManager('/v2/checkout_sessions', client);
this.paymentIntents = new V2PaymentIntentsManager('/v2/payment_intents', client);
this.paymentMethods = new PaymentMethodsManager('/v2/payment_methods', client);
this.subscriptions = new V2SubscriptionsManager('/v2/subscriptions', client);
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/lib/managers/v2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ export * from './accountNumbersManager';
export * from './simulateManager';
export * from './entitiesManager';
export * from './accountVerificationsManager';
export * from './invoicesManager';
export * from './movementsManager';
export * from './customersManager';
export * from './checkoutSessionsManager';
export * from './paymentIntentsManager';
export * from './paymentMethodsManager';
export * from './subscriptionsManager';
7 changes: 7 additions & 0 deletions src/lib/managers/v2/invoicesManager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { ManagerMixin } from '../../mixins';
import { Invoice } from '../../resources/v2/invoice';

export class InvoicesManager extends ManagerMixin<Invoice> {
static resource = 'invoice';
static methods = ['list', 'get'];
}
7 changes: 7 additions & 0 deletions src/lib/managers/v2/paymentMethodsManager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { ManagerMixin } from '../../mixins';
import { PaymentMethod } from '../../resources/v2/paymentMethod';

export class PaymentMethodsManager extends ManagerMixin<PaymentMethod> {
static resource = 'payment_method';
static methods = ['list', 'get'];
}
14 changes: 14 additions & 0 deletions src/lib/managers/v2/subscriptionsManager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { ResourceArguments } from '../../../types';
import { ManagerMixin } from '../../mixins';
import { Subscription } from '../../resources/v2/subscription';

export class SubscriptionsManager extends ManagerMixin<Subscription> {
static resource = 'subscription';
static methods = ['list', 'get', 'cancel'];

cancel(subscriptionId: string, args?: ResourceArguments): Promise<Subscription> {
const innerArgs = args || {};
const path = `${this.buildPath()}/${subscriptionId}/cancel`;
return this._create({ path_: path, ...innerArgs });
}
}
3 changes: 3 additions & 0 deletions src/lib/resources/v2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ export * from './accountNumber';
export * from './entity';
export * from './accountVerification';
export * from './checkoutSession';
export * from './invoice';
export * from './movement';
export * from './customer';
export * from './paymentIntent';
export * from './paymentMethod';
export * from './subscription';
4 changes: 4 additions & 0 deletions src/lib/resources/v2/invoice.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { ResourceMixin } from '../../mixins/resourceMixin';

export class Invoice extends ResourceMixin<Invoice> {
}
4 changes: 4 additions & 0 deletions src/lib/resources/v2/paymentMethod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { ResourceMixin } from '../../mixins/resourceMixin';

export class PaymentMethod extends ResourceMixin<PaymentMethod> {
}
4 changes: 4 additions & 0 deletions src/lib/resources/v2/subscription.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { ResourceMixin } from '../../mixins/resourceMixin';

export class Subscription extends ResourceMixin<Subscription> {
}
78 changes: 78 additions & 0 deletions src/spec/integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1159,6 +1159,29 @@ test('fintoc.v2.checkoutSessions.expire()', async (t) => {
t.is(checkoutSession.url, `v2/checkout_sessions/${checkoutSessionId}/expire`);
});

test('fintoc.v2.invoices.list()', async (t) => {
const ctx: any = t.context;
const invoices = await ctx.fintoc.v2.invoices.list();

let count = 0;
for await (const invoice of invoices) {
count += 1;
t.is(invoice.method, 'get');
t.is(invoice.url, 'v2/invoices');
}

t.true(count > 0);
});

test('fintoc.v2.invoices.get()', async (t) => {
const ctx: any = t.context;
const invoiceId = 'invoice_id';
const invoice = await ctx.fintoc.v2.invoices.get(invoiceId);

t.is(invoice.method, 'get');
t.is(invoice.url, `v2/invoices/${invoiceId}`);
});

test('fintoc.v2.paymentIntents.list()', async (t) => {
const ctx: any = t.context;
const paymentIntents = await ctx.fintoc.v2.paymentIntents.list();
Expand Down Expand Up @@ -1197,3 +1220,58 @@ test('fintoc.v2.paymentIntents.create()', async (t) => {
t.is(paymentIntent.json.currency, paymentIntentData.currency);
t.is(paymentIntent.json.payment_method, paymentIntentData.payment_method);
});

test('fintoc.v2.paymentMethods.list()', async (t) => {
const ctx: any = t.context;
const paymentMethods = await ctx.fintoc.v2.paymentMethods.list();

let count = 0;
for await (const paymentMethod of paymentMethods) {
count += 1;
t.is(paymentMethod.method, 'get');
t.is(paymentMethod.url, 'v2/payment_methods');
}

t.true(count > 0);
});

test('fintoc.v2.paymentMethods.get()', async (t) => {
const ctx: any = t.context;
const paymentMethodId = 'payment_method_id';
const paymentMethod = await ctx.fintoc.v2.paymentMethods.get(paymentMethodId);

t.is(paymentMethod.method, 'get');
t.is(paymentMethod.url, `v2/payment_methods/${paymentMethodId}`);
});

test('fintoc.v2.subscriptions.list()', async (t) => {
const ctx: any = t.context;
const subscriptions = await ctx.fintoc.v2.subscriptions.list();

let count = 0;
for await (const subscription of subscriptions) {
count += 1;
t.is(subscription.method, 'get');
t.is(subscription.url, 'v2/subscriptions');
}

t.true(count > 0);
});

test('fintoc.v2.subscriptions.get()', async (t) => {
const ctx: any = t.context;
const subscriptionId = 'subscription_id';
const subscription = await ctx.fintoc.v2.subscriptions.get(subscriptionId);

t.is(subscription.method, 'get');
t.is(subscription.url, `v2/subscriptions/${subscriptionId}`);
});

test('fintoc.v2.subscriptions.cancel()', async (t) => {
const ctx: any = t.context;
const subscriptionId = 'subscription_id';
const subscription = await ctx.fintoc.v2.subscriptions.cancel(subscriptionId);

t.is(subscription.method, 'post');
t.is(subscription.url, `v2/subscriptions/${subscriptionId}/cancel`);
});
Loading