Skip to content

Commit 8588abe

Browse files
authored
Merge pull request #73 from fintoc-com/feat-add-payment-intents-v2
Feat add payment intents v2
2 parents 296ff8e + 9d6ba3b commit 8588abe

6 files changed

Lines changed: 55 additions & 0 deletions

File tree

src/lib/core.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
TransfersManager,
2626
AccountsManager as V2AccountsManager,
2727
CheckoutSessionsManager as V2CheckoutSessionsManager,
28+
PaymentIntentsManager as V2PaymentIntentsManager,
2829
} from './managers/v2';
2930
import { version } from './version';
3031

@@ -37,6 +38,7 @@ class FintocV2 {
3738
accountVerifications: AccountVerificationsManager;
3839
customers: CustomersManager;
3940
checkoutSessions: V2CheckoutSessionsManager;
41+
paymentIntents: V2PaymentIntentsManager;
4042

4143
constructor(client: Client) {
4244
this.accounts = new V2AccountsManager('/v2/accounts', client);
@@ -47,6 +49,7 @@ class FintocV2 {
4749
this.accountVerifications = new AccountVerificationsManager('/v2/account_verifications', client);
4850
this.customers = new CustomersManager('/v2/customers', client);
4951
this.checkoutSessions = new V2CheckoutSessionsManager('/v2/checkout_sessions', client);
52+
this.paymentIntents = new V2PaymentIntentsManager('/v2/payment_intents', client);
5053
}
5154
}
5255

src/lib/managers/v2/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ export * from './accountVerificationsManager';
77
export * from './movementsManager';
88
export * from './customersManager';
99
export * from './checkoutSessionsManager';
10+
export * from './paymentIntentsManager';
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 { PaymentIntent } from '../../resources/v2/paymentIntent';
3+
4+
export class PaymentIntentsManager extends ManagerMixin<PaymentIntent> {
5+
static resource = 'payment_intent';
6+
static methods = ['list', 'get', 'create'];
7+
}

src/lib/resources/v2/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ export * from './accountVerification';
66
export * from './checkoutSession';
77
export * from './movement';
88
export * from './customer';
9+
export * from './paymentIntent';
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 PaymentIntent extends ResourceMixin<PaymentIntent> {
4+
}

src/spec/integration.spec.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,3 +1158,42 @@ test('fintoc.v2.checkoutSessions.expire()', async (t) => {
11581158
t.is(checkoutSession.method, 'post');
11591159
t.is(checkoutSession.url, `v2/checkout_sessions/${checkoutSessionId}/expire`);
11601160
});
1161+
1162+
test('fintoc.v2.paymentIntents.list()', async (t) => {
1163+
const ctx: any = t.context;
1164+
const paymentIntents = await ctx.fintoc.v2.paymentIntents.list();
1165+
1166+
let count = 0;
1167+
for await (const paymentIntent of paymentIntents) {
1168+
count += 1;
1169+
t.is(paymentIntent.method, 'get');
1170+
t.is(paymentIntent.url, 'v2/payment_intents');
1171+
}
1172+
1173+
t.true(count > 0);
1174+
});
1175+
1176+
test('fintoc.v2.paymentIntents.get()', async (t) => {
1177+
const ctx: any = t.context;
1178+
const paymentIntentId = 'payment_intent_id';
1179+
const paymentIntent = await ctx.fintoc.v2.paymentIntents.get(paymentIntentId);
1180+
1181+
t.is(paymentIntent.method, 'get');
1182+
t.is(paymentIntent.url, `v2/payment_intents/${paymentIntentId}`);
1183+
});
1184+
1185+
test('fintoc.v2.paymentIntents.create()', async (t) => {
1186+
const ctx: any = t.context;
1187+
const paymentIntentData = {
1188+
amount: 5000,
1189+
currency: 'CLP',
1190+
payment_method: 'payment_method_hashid',
1191+
};
1192+
const paymentIntent = await ctx.fintoc.v2.paymentIntents.create(paymentIntentData);
1193+
1194+
t.is(paymentIntent.method, 'post');
1195+
t.is(paymentIntent.url, 'v2/payment_intents');
1196+
t.is(paymentIntent.json.amount, paymentIntentData.amount);
1197+
t.is(paymentIntent.json.currency, paymentIntentData.currency);
1198+
t.is(paymentIntent.json.payment_method, paymentIntentData.payment_method);
1199+
});

0 commit comments

Comments
 (0)