Skip to content

Commit df7a202

Browse files
authored
Merge pull request #76 from fintoc-com/pay-5310-add-paymentmethods-to-node-sdk
Add new invoicing endpoints to SDK
2 parents bc49bdf + 347fb13 commit df7a202

10 files changed

Lines changed: 133 additions & 0 deletions

File tree

src/lib/core.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,14 @@ import {
2121
AccountVerificationsManager,
2222
CustomersManager,
2323
EntitiesManager,
24+
PaymentMethodsManager,
2425
SimulateManager,
2526
TransfersManager,
2627
AccountsManager as V2AccountsManager,
2728
CheckoutSessionsManager as V2CheckoutSessionsManager,
29+
InvoicesManager as V2InvoicesManager,
2830
PaymentIntentsManager as V2PaymentIntentsManager,
31+
SubscriptionsManager as V2SubscriptionsManager,
2932
} from './managers/v2';
3033
import { version } from './version';
3134

@@ -35,21 +38,27 @@ class FintocV2 {
3538
accountNumbers: AccountNumbersManager;
3639
simulate: SimulateManager;
3740
entities: EntitiesManager;
41+
invoices: V2InvoicesManager;
3842
accountVerifications: AccountVerificationsManager;
3943
customers: CustomersManager;
4044
checkoutSessions: V2CheckoutSessionsManager;
4145
paymentIntents: V2PaymentIntentsManager;
46+
paymentMethods: PaymentMethodsManager;
47+
subscriptions: V2SubscriptionsManager;
4248

4349
constructor(client: Client) {
4450
this.accounts = new V2AccountsManager('/v2/accounts', client);
4551
this.transfers = new TransfersManager('/v2/transfers', client);
4652
this.accountNumbers = new AccountNumbersManager('/v2/account_numbers', client);
4753
this.simulate = new SimulateManager('/v2/simulate', client);
4854
this.entities = new EntitiesManager('/v2/entities', client);
55+
this.invoices = new V2InvoicesManager('/v2/invoices', client);
4956
this.accountVerifications = new AccountVerificationsManager('/v2/account_verifications', client);
5057
this.customers = new CustomersManager('/v2/customers', client);
5158
this.checkoutSessions = new V2CheckoutSessionsManager('/v2/checkout_sessions', client);
5259
this.paymentIntents = new V2PaymentIntentsManager('/v2/payment_intents', client);
60+
this.paymentMethods = new PaymentMethodsManager('/v2/payment_methods', client);
61+
this.subscriptions = new V2SubscriptionsManager('/v2/subscriptions', client);
5362
}
5463
}
5564

src/lib/managers/v2/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ export * from './accountNumbersManager';
44
export * from './simulateManager';
55
export * from './entitiesManager';
66
export * from './accountVerificationsManager';
7+
export * from './invoicesManager';
78
export * from './movementsManager';
89
export * from './customersManager';
910
export * from './checkoutSessionsManager';
1011
export * from './paymentIntentsManager';
12+
export * from './paymentMethodsManager';
13+
export * from './subscriptionsManager';
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { ManagerMixin } from '../../mixins';
2+
import { Invoice } from '../../resources/v2/invoice';
3+
4+
export class InvoicesManager extends ManagerMixin<Invoice> {
5+
static resource = 'invoice';
6+
static methods = ['list', 'get'];
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { ManagerMixin } from '../../mixins';
2+
import { PaymentMethod } from '../../resources/v2/paymentMethod';
3+
4+
export class PaymentMethodsManager extends ManagerMixin<PaymentMethod> {
5+
static resource = 'payment_method';
6+
static methods = ['list', 'get'];
7+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { ResourceArguments } from '../../../types';
2+
import { ManagerMixin } from '../../mixins';
3+
import { Subscription } from '../../resources/v2/subscription';
4+
5+
export class SubscriptionsManager extends ManagerMixin<Subscription> {
6+
static resource = 'subscription';
7+
static methods = ['list', 'get', 'cancel'];
8+
9+
cancel(subscriptionId: string, args?: ResourceArguments): Promise<Subscription> {
10+
const innerArgs = args || {};
11+
const path = `${this.buildPath()}/${subscriptionId}/cancel`;
12+
return this._create({ path_: path, ...innerArgs });
13+
}
14+
}

src/lib/resources/v2/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ export * from './accountNumber';
44
export * from './entity';
55
export * from './accountVerification';
66
export * from './checkoutSession';
7+
export * from './invoice';
78
export * from './movement';
89
export * from './customer';
910
export * from './paymentIntent';
11+
export * from './paymentMethod';
12+
export * from './subscription';

src/lib/resources/v2/invoice.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { ResourceMixin } from '../../mixins/resourceMixin';
2+
3+
export class Invoice extends ResourceMixin<Invoice> {
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { ResourceMixin } from '../../mixins/resourceMixin';
2+
3+
export class PaymentMethod extends ResourceMixin<PaymentMethod> {
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { ResourceMixin } from '../../mixins/resourceMixin';
2+
3+
export class Subscription extends ResourceMixin<Subscription> {
4+
}

src/spec/integration.spec.ts

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,6 +1159,29 @@ test('fintoc.v2.checkoutSessions.expire()', async (t) => {
11591159
t.is(checkoutSession.url, `v2/checkout_sessions/${checkoutSessionId}/expire`);
11601160
});
11611161

1162+
test('fintoc.v2.invoices.list()', async (t) => {
1163+
const ctx: any = t.context;
1164+
const invoices = await ctx.fintoc.v2.invoices.list();
1165+
1166+
let count = 0;
1167+
for await (const invoice of invoices) {
1168+
count += 1;
1169+
t.is(invoice.method, 'get');
1170+
t.is(invoice.url, 'v2/invoices');
1171+
}
1172+
1173+
t.true(count > 0);
1174+
});
1175+
1176+
test('fintoc.v2.invoices.get()', async (t) => {
1177+
const ctx: any = t.context;
1178+
const invoiceId = 'invoice_id';
1179+
const invoice = await ctx.fintoc.v2.invoices.get(invoiceId);
1180+
1181+
t.is(invoice.method, 'get');
1182+
t.is(invoice.url, `v2/invoices/${invoiceId}`);
1183+
});
1184+
11621185
test('fintoc.v2.paymentIntents.list()', async (t) => {
11631186
const ctx: any = t.context;
11641187
const paymentIntents = await ctx.fintoc.v2.paymentIntents.list();
@@ -1197,3 +1220,58 @@ test('fintoc.v2.paymentIntents.create()', async (t) => {
11971220
t.is(paymentIntent.json.currency, paymentIntentData.currency);
11981221
t.is(paymentIntent.json.payment_method, paymentIntentData.payment_method);
11991222
});
1223+
1224+
test('fintoc.v2.paymentMethods.list()', async (t) => {
1225+
const ctx: any = t.context;
1226+
const paymentMethods = await ctx.fintoc.v2.paymentMethods.list();
1227+
1228+
let count = 0;
1229+
for await (const paymentMethod of paymentMethods) {
1230+
count += 1;
1231+
t.is(paymentMethod.method, 'get');
1232+
t.is(paymentMethod.url, 'v2/payment_methods');
1233+
}
1234+
1235+
t.true(count > 0);
1236+
});
1237+
1238+
test('fintoc.v2.paymentMethods.get()', async (t) => {
1239+
const ctx: any = t.context;
1240+
const paymentMethodId = 'payment_method_id';
1241+
const paymentMethod = await ctx.fintoc.v2.paymentMethods.get(paymentMethodId);
1242+
1243+
t.is(paymentMethod.method, 'get');
1244+
t.is(paymentMethod.url, `v2/payment_methods/${paymentMethodId}`);
1245+
});
1246+
1247+
test('fintoc.v2.subscriptions.list()', async (t) => {
1248+
const ctx: any = t.context;
1249+
const subscriptions = await ctx.fintoc.v2.subscriptions.list();
1250+
1251+
let count = 0;
1252+
for await (const subscription of subscriptions) {
1253+
count += 1;
1254+
t.is(subscription.method, 'get');
1255+
t.is(subscription.url, 'v2/subscriptions');
1256+
}
1257+
1258+
t.true(count > 0);
1259+
});
1260+
1261+
test('fintoc.v2.subscriptions.get()', async (t) => {
1262+
const ctx: any = t.context;
1263+
const subscriptionId = 'subscription_id';
1264+
const subscription = await ctx.fintoc.v2.subscriptions.get(subscriptionId);
1265+
1266+
t.is(subscription.method, 'get');
1267+
t.is(subscription.url, `v2/subscriptions/${subscriptionId}`);
1268+
});
1269+
1270+
test('fintoc.v2.subscriptions.cancel()', async (t) => {
1271+
const ctx: any = t.context;
1272+
const subscriptionId = 'subscription_id';
1273+
const subscription = await ctx.fintoc.v2.subscriptions.cancel(subscriptionId);
1274+
1275+
t.is(subscription.method, 'post');
1276+
t.is(subscription.url, `v2/subscriptions/${subscriptionId}/cancel`);
1277+
});

0 commit comments

Comments
 (0)