diff --git a/src/lib/core.ts b/src/lib/core.ts index bfabd45..f2032d6 100644 --- a/src/lib/core.ts +++ b/src/lib/core.ts @@ -25,6 +25,7 @@ import { TransfersManager, AccountsManager as V2AccountsManager, CheckoutSessionsManager as V2CheckoutSessionsManager, + PaymentIntentsManager as V2PaymentIntentsManager, } from './managers/v2'; import { version } from './version'; @@ -37,6 +38,7 @@ class FintocV2 { accountVerifications: AccountVerificationsManager; customers: CustomersManager; checkoutSessions: V2CheckoutSessionsManager; + paymentIntents: V2PaymentIntentsManager; constructor(client: Client) { this.accounts = new V2AccountsManager('/v2/accounts', client); @@ -47,6 +49,7 @@ class FintocV2 { 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); } } diff --git a/src/lib/managers/v2/index.ts b/src/lib/managers/v2/index.ts index b01edf8..e73bb74 100644 --- a/src/lib/managers/v2/index.ts +++ b/src/lib/managers/v2/index.ts @@ -7,3 +7,4 @@ export * from './accountVerificationsManager'; export * from './movementsManager'; export * from './customersManager'; export * from './checkoutSessionsManager'; +export * from './paymentIntentsManager'; diff --git a/src/lib/managers/v2/paymentIntentsManager.ts b/src/lib/managers/v2/paymentIntentsManager.ts new file mode 100644 index 0000000..f62aa0e --- /dev/null +++ b/src/lib/managers/v2/paymentIntentsManager.ts @@ -0,0 +1,7 @@ +import { ManagerMixin } from '../../mixins'; +import { PaymentIntent } from '../../resources/v2/paymentIntent'; + +export class PaymentIntentsManager extends ManagerMixin { + static resource = 'payment_intent'; + static methods = ['list', 'get', 'create']; +} diff --git a/src/lib/resources/v2/index.ts b/src/lib/resources/v2/index.ts index 521f723..1547f3d 100644 --- a/src/lib/resources/v2/index.ts +++ b/src/lib/resources/v2/index.ts @@ -6,3 +6,4 @@ export * from './accountVerification'; export * from './checkoutSession'; export * from './movement'; export * from './customer'; +export * from './paymentIntent'; diff --git a/src/lib/resources/v2/paymentIntent.ts b/src/lib/resources/v2/paymentIntent.ts new file mode 100644 index 0000000..eb7be4d --- /dev/null +++ b/src/lib/resources/v2/paymentIntent.ts @@ -0,0 +1,4 @@ +import { ResourceMixin } from '../../mixins/resourceMixin'; + +export class PaymentIntent extends ResourceMixin { +} diff --git a/src/spec/integration.spec.ts b/src/spec/integration.spec.ts index f50ab24..4f5f1c7 100644 --- a/src/spec/integration.spec.ts +++ b/src/spec/integration.spec.ts @@ -1158,3 +1158,42 @@ test('fintoc.v2.checkoutSessions.expire()', async (t) => { t.is(checkoutSession.method, 'post'); t.is(checkoutSession.url, `v2/checkout_sessions/${checkoutSessionId}/expire`); }); + +test('fintoc.v2.paymentIntents.list()', async (t) => { + const ctx: any = t.context; + const paymentIntents = await ctx.fintoc.v2.paymentIntents.list(); + + let count = 0; + for await (const paymentIntent of paymentIntents) { + count += 1; + t.is(paymentIntent.method, 'get'); + t.is(paymentIntent.url, 'v2/payment_intents'); + } + + t.true(count > 0); +}); + +test('fintoc.v2.paymentIntents.get()', async (t) => { + const ctx: any = t.context; + const paymentIntentId = 'payment_intent_id'; + const paymentIntent = await ctx.fintoc.v2.paymentIntents.get(paymentIntentId); + + t.is(paymentIntent.method, 'get'); + t.is(paymentIntent.url, `v2/payment_intents/${paymentIntentId}`); +}); + +test('fintoc.v2.paymentIntents.create()', async (t) => { + const ctx: any = t.context; + const paymentIntentData = { + amount: 5000, + currency: 'CLP', + payment_method: 'payment_method_hashid', + }; + const paymentIntent = await ctx.fintoc.v2.paymentIntents.create(paymentIntentData); + + t.is(paymentIntent.method, 'post'); + t.is(paymentIntent.url, 'v2/payment_intents'); + t.is(paymentIntent.json.amount, paymentIntentData.amount); + t.is(paymentIntent.json.currency, paymentIntentData.currency); + t.is(paymentIntent.json.payment_method, paymentIntentData.payment_method); +});