### Install Fintoc with pnpm Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/configuration.md Install the Fintoc library using pnpm. ```bash pnpm add fintoc ``` -------------------------------- ### Install Fintoc with npm Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/configuration.md Install the Fintoc library using npm. ```bash npm install fintoc ``` -------------------------------- ### Minimal Fintoc SDK Setup Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/usage-patterns.md Initialize the Fintoc SDK with only your API key. This is the most basic setup for making API calls. ```typescript import { Fintoc } from 'fintoc'; const fintoc = new Fintoc(process.env.FINTOC_API_KEY!); ``` -------------------------------- ### Install Fintoc with yarn Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/configuration.md Install the Fintoc library using yarn. ```bash yarn add fintoc ``` -------------------------------- ### Install Fintoc Node.js Client Source: https://github.com/fintoc-com/fintoc-node/blob/master/README.md Install the Fintoc Node.js client using npm or yarn. ```sh # Using npm npm install fintoc ``` ```sh # Using yarn yarn add fintoc ``` -------------------------------- ### Resource Parameters Examples Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/quick-reference.md Examples of how to structure resource arguments for Fintoc API calls. Supports simple types, nested objects, arrays, and mixed types. ```typescript { since: '2025-01-01', until: '2025-12-31' } ``` ```typescript { amount: 50000, counterparty: { account_number: '012969100000000026' } } ``` ```typescript { enabled_events: ['charge.created', 'charge.refunded'] } ``` ```typescript { lazy: false, idempotency_key: 'key-123' } ``` -------------------------------- ### Usage Example: Custom User-Agent Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/api-reference-fintoc-client.md Shows how to initialize the Fintoc client with a custom User-Agent header. ```APIDOC ### Custom User-Agent ```typescript const fintoc = new Fintoc('your_api_key', undefined, { userAgent: 'my-app/1.0.0' }); ``` ``` -------------------------------- ### PaymentIntentsManager Example Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/types-and-interfaces.md Example of a manager class implementing the IManagerMixinConstructor interface. ```typescript // From src/lib/managers/paymentIntentsManager.ts export class PaymentIntentsManager extends ManagerMixin { static resource = 'payment_intent'; static methods = ['list', 'get', 'create', 'expire', 'checkEligibility']; } ``` -------------------------------- ### IResourceMixin Usage Examples Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/types-and-interfaces.md Demonstrates how to use the serialize, update, and delete methods on a resource instance. ```typescript // Serialize to plain object const data = resource.serialize(); // Update the resource const updated = await resource.update({ /* changes */ }); // Delete the resource const id = await resource.delete(); ``` -------------------------------- ### Example .env File for Fintoc Configuration Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/configuration.md Illustrates how to set Fintoc-related environment variables in a .env file for local development. ```env FINTOC_API_KEY=fk_live_abc123xyz789 FINTOC_PRIVATE_KEY=/etc/fintoc/private_key.pem FINTOC_WEBHOOK_SECRET=whsec_abc123xyz789 ``` -------------------------------- ### ProductsManager Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/api-reference-managers.md Manages V2 products. Supports listing and getting products. ```APIDOC ## ProductsManager ### Description Manages V2 products. Supports listing and getting products. ### Resource path `/v2/products` ### Available methods `list`, `get` ### Example Usage ```typescript const products = await fintoc.v2.products.list(); ``` ``` -------------------------------- ### Check Node.js Version Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/configuration.md Verify your installed Node.js version using this command. ```bash node --version ``` -------------------------------- ### Fintoc SDK Setup with All Options Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/usage-patterns.md Initialize the Fintoc SDK with an API key, a private key, and custom options. Use this for advanced configurations, such as setting a custom user agent. ```typescript import { Fintoc } from 'fintoc'; import fs from 'fs'; const privateKey = fs.readFileSync('/path/to/private_key.pem'); const fintoc = new Fintoc( process.env.FINTOC_API_KEY!, privateKey, { userAgent: 'my-app/1.0.0' } ); ``` -------------------------------- ### Webhook Verification Example in Express.js Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/webhook-signature-jws.md An example demonstrating how to use WebhookSignature.verifyHeader within an Express.js middleware to authenticate incoming webhooks. Ensure you have the raw request body available and your webhook secret configured. ```typescript import { WebhookSignature, WebhookSignatureError } from 'fintoc'; // In an Express.js middleware app.post('/webhooks/fintoc', (req, res) => { const payload = req.rawBody; // Must be the exact raw body const signature = req.headers['fintoc-signature']; const webhookSecret = process.env.FINTOC_WEBHOOK_SECRET; try { WebhookSignature.verifyHeader(payload, signature, webhookSecret); // Webhook is authentic, process it const event = JSON.parse(payload); console.log('Received event:', event.type); res.status(200).json({ received: true }); } catch (error) { if (error instanceof WebhookSignatureError) { console.error('Invalid webhook signature:', error.message); res.status(401).json({ error: 'Unauthorized' }); } else { res.status(500).json({ error: 'Internal server error' }); } } }); ``` -------------------------------- ### Post-Operation Handlers Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/architecture.md Implement post-operation handlers to modify resources after they are fetched. This example shows how to update the client with specific parameters after a 'get' operation. ```typescript class LinksManager extends ManagerMixin { protected postGetHandler(link, token, args) { link._updateClient(this._client.extend({ params: { link_token: token } })); return link; } } ``` -------------------------------- ### Usage Example: V2 API Call Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/api-reference-fintoc-client.md Shows how to create a transfer using the V2 API. ```APIDOC ```typescript // Create a transfer using V2 API const transfer = await fintoc.v2.transfers.create({ amount: 54123, currency: 'mxn', account_id: 'acc_12345678', counterparty: { account_number: '012969100000000026' } }); ``` ``` -------------------------------- ### Usage Example: Basic Initialization and V1 API Call Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/api-reference-fintoc-client.md Demonstrates initializing the Fintoc client with an API key and listing payment intents using the V1 API. ```APIDOC ### Usage Example ```typescript import { Fintoc } from 'fintoc'; // Initialize client with API key const fintoc = new Fintoc('your_api_key'); // List all payment intents (V1 API) const paymentIntents = await fintoc.paymentIntents.list({ since: '2025-01-01', until: '2025-12-31' }); for await (const pi of paymentIntents) { console.log(pi.id, pi.amount, pi.status); } // Get a specific payment intent const paymentIntent = await fintoc.paymentIntents.get('pi_12312312'); ``` ``` -------------------------------- ### Usage Example: With JWS Signature Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/api-reference-fintoc-client.md Demonstrates initializing the Fintoc client with a private key for JWS signature generation. ```APIDOC ### With JWS Signature ```typescript import { Fintoc } from 'fintoc'; import fs from 'fs'; // Initialize with private key for request signing const privateKey = fs.readFileSync('/path/to/private_key.pem'); const fintoc = new Fintoc('your_api_key', privateKey); // All requests will now be signed with JWS const result = await fintoc.v2.transfers.create({ amount: 54123, currency: 'mxn', account_id: 'acc_12345678', counterparty: { account_number: '012969100000000026' } }); ``` ``` -------------------------------- ### Import Fintoc SDK with TypeScript Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/README.md Demonstrates how to import the Fintoc SDK and define resource arguments using TypeScript. Ensure you have the necessary types installed. ```typescript import { Fintoc, ResourceArguments } from 'fintoc'; const args: ResourceArguments = { since: '2025-01-01', amount: 50000 }; ``` -------------------------------- ### Get Specific Resource Instance Source: https://github.com/fintoc-com/fintoc-node/blob/master/README.md You can use the `get` method to retrieve a specific instance of a resource by its ID. ```APIDOC ## Get Payment Intent ### Description Retrieves a specific payment intent by its ID. ### Method `get(id)` ### Parameters - **id** (string) - Required - The unique identifier of the payment intent. ### Request Example ```javascript const paymentIntent = await fintocClient.paymentIntents.get('pi_8anqVLlBC8ROodem'); console.log(paymentIntent.created_at, paymentIntent.amount, paymentIntent.status); ``` ### Response - Returns the specific payment intent object. ``` -------------------------------- ### Initialize Fintoc Client Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/api-reference-fintoc-client.md Instantiate the Fintoc client with your API key. This is the primary way to start interacting with the Fintoc API. ```typescript import { Fintoc } from 'fintoc'; // Initialize client with API key const fintoc = new Fintoc('your_api_key'); ``` -------------------------------- ### SimulateManager Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/api-reference-managers.md Manages V2 simulations. Supports listing, getting, and creating simulations. ```APIDOC ## SimulateManager ### Description Manages V2 simulations. Supports listing, getting, and creating simulations. ### Resource path `/v2/simulate` ### Available methods `list`, `get`, `create` ### Example Usage ```typescript const simulation = await fintoc.v2.simulate.create({ type: 'movement', data: { /* simulation data */ } }); ``` ``` -------------------------------- ### Create a Transfer (V2 API) Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/api-reference-fintoc-client.md Example of creating a money transfer using the V2 API. Requires `fintoc.v2.transfers.create`. ```typescript // Create a transfer using V2 API const transfer = await fintoc.v2.transfers.create({ amount: 54123, currency: 'mxn', account_id: 'acc_12345678', counterparty: { account_number: '012969100000000026' } }); ``` -------------------------------- ### CustomersManager Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/api-reference-managers.md Manages V2 customers. Supports listing and getting customers. ```APIDOC ## CustomersManager ### Description Manages V2 customers. Supports listing and getting customers. ### Resource path `/v2/customers` ### Available methods `list`, `get` ### Example Usage ```typescript const customers = await fintoc.v2.customers.list(); ``` ``` -------------------------------- ### Get and Cancel V2 Subscription Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/resource-types.md Retrieves a V2 subscription and demonstrates how to cancel it. ```typescript const subscription = await fintoc.v2.subscriptions.get('sub_12345678'); const cancelled = await subscription.cancel(); ``` -------------------------------- ### PaymentIntent Class with Mappings Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/types-and-interfaces.md Example of a PaymentIntent class extending ResourceMixin, defining custom mappings for API fields. ```typescript // From src/lib/resources/paymentIntent.ts export class PaymentIntent extends ResourceMixin { static mappings = { recipient_account: 'transfer_account', sender_account: 'transfer_account', } } ``` -------------------------------- ### Update Resource (Via Instance) Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/quick-reference.md Update a resource by first getting the instance and then calling the update method on it. ```typescript // Via instance const webhook = await fintoc.webhookEndpoints.get('we_12345678'); const updated = await webhook.update({ enabled_events: [...] }); ``` -------------------------------- ### List and Get Tax Returns Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/api-reference-managers.md Demonstrates how to retrieve a list of all tax returns or a specific tax return by its ID. ```typescript const taxReturns = await fintoc.taxReturns.list(); const taxReturn = await fintoc.taxReturns.get('tr_12345678'); ``` -------------------------------- ### TypeScript Configuration (tsconfig.json) Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/configuration.md Example tsconfig.json settings for a TypeScript project using the Fintoc SDK. Ensure target, lib, module, and other options are set appropriately. ```json { "compilerOptions": { "target": "ES2020", "lib": ["ES2020"], "module": "commonjs", "declaration": true, "strict": true, "esModuleInterop": true, "skipLibCheck": true, "forceConsistentCasingInFileNames": true } } ``` -------------------------------- ### List Resources Source: https://github.com/fintoc-com/fintoc-node/blob/master/README.md You can use the `list` method to retrieve all instances of a resource. This method returns an async generator and can accept API-specific filtering parameters. For example, `PaymentIntent` resources can be filtered using `since` and `until`. ```APIDOC ## List Webhook Endpoints ### Description Lists all webhook endpoint instances. ### Method `list()` ### Parameters - `options` (object) - Optional. Filtering parameters for the API. - `since` (string) - Optional. Filter results created after this date. - `until` (string) - Optional. Filter results created before this date. - `lazy` (boolean) - Optional. If `false`, returns a list instead of an async generator. Defaults to `true`. ### Request Example ```javascript const webhookEndpoints = await fintocClient.webhookEndpoints.list(); const paymentIntents = await fintocClient.paymentIntents.list({ since: '2019-07-24', until: '2021-05-12', }); // To iterate over the async generator: for await (const paymentIntent of paymentIntents) { console.log(paymentIntent.id); } // To get all instances as an array: const allPaymentIntents = await fintocClient.paymentIntents.list({ lazy: false }); console.log(Array.isArray(allPaymentIntents)); // true ``` ### Response - Returns an async generator yielding resource instances, or an array if `lazy: false`. ``` -------------------------------- ### Fintoc Authentication Error: Missing API Key Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/errors-and-exceptions.md Example showing that an empty string for the API key results in an AuthenticationError. ```typescript const fintoc = new Fintoc(''); // Error: unauthorized: missing_api_key ``` -------------------------------- ### Get Dispute and Submit for Review Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/resource-types.md Retrieves a payment dispute and submits it for review. Also shows how to create a supporting document for the dispute. ```typescript const dispute = await fintoc.disputes.get('dis_12345678'); await dispute.submitForReview(); await dispute.createDocument({ file: 'base64_content' }); ``` -------------------------------- ### Get Specific Payment Intent Source: https://github.com/fintoc-com/fintoc-node/blob/master/README.md Retrieve a single payment intent by its ID using the `get` method. ```javascript const paymentIntent = await fintocClient.paymentIntents.get('pi_8anqVLlBC8ROodem'); ``` -------------------------------- ### Performing Operations with Managers Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/README.md Illustrates how to use manager methods to perform collection operations like listing, getting, and creating payment intents. ```typescript await fintoc.paymentIntents.list() // Manager method await fintoc.paymentIntents.get(id) // Manager method await fintoc.paymentIntents.create({}) // Manager method ``` -------------------------------- ### Initialize Fintoc Client with JWS Signing from File Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/webhook-signature-jws.md Load your private key from a file and initialize the Fintoc client. This ensures all subsequent POST, PUT, and PATCH requests are automatically signed with JWS. ```typescript import { Fintoc } from 'fintoc'; import fs from 'fs'; // Load private key from file const privateKey = fs.readFileSync('/path/to/private_key.pem', 'utf8'); // Initialize Fintoc client with JWS signing const fintoc = new Fintoc('your_api_key', privateKey); // All POST, PUT, and PATCH requests will automatically include JWS signatures const transfer = await fintoc.v2.transfers.create({ amount: 100000, currency: 'clp', account_id: 'acc_12345678', counterparty: { account_number: '012969100000000026' } }); ``` -------------------------------- ### Get, Update, and Delete a Link Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/resource-types.md Retrieves a user's link to their financial institution, updates its status, and demonstrates deletion. The get() method sets the link token internally for subsequent operations. ```typescript const link = await fintoc.links.get('link_token_12345'); // Link token is now set internally for subsequent operations const updated = await fintoc.links.update('link_token_12345', { status: 'disconnected' }); ``` -------------------------------- ### Get Resource Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/quick-reference.md Retrieves a specific resource by its ID. ```APIDOC ## Get Resource ### Description Retrieves a specific resource by its ID. ### Method GET (implied) ### Endpoint `/resources/{id}` (implied, specific resource type depends on the manager, e.g., `/payment_intents/{id}`) ### Parameters #### Path Parameters - **id** (string) - Required - The unique identifier of the resource. ### Request Example ```typescript const resource = await fintoc.paymentIntents.get('pi_12345678'); ``` ### Response #### Success Response (200) - **resource** (object) - The requested resource object. #### Response Example ```json { "id": "pi_12345678", ... } ``` ``` -------------------------------- ### get Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/api-reference-managers.md Retrieves a single resource by its unique identifier. ```APIDOC ## get ### Description Retrieve a single resource by identifier. ### Method get ### Parameters #### Path Parameters - **identifier** (string) - Required - Resource ID #### Query Parameters - **args** (ResourceArguments) - Optional - Additional query parameters ### Request Example ```typescript const paymentIntent = await fintoc.paymentIntents.get('pi_8anqVLlBC8ROodem'); console.log(paymentIntent.amount, paymentIntent.status); ``` ### Response #### Success Response - **ResourceType** - The requested resource ``` -------------------------------- ### create Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/api-reference-managers.md Creates a new instance of a resource with the provided arguments. ```APIDOC ## create ### Description Create a new instance of the resource. ### Method create ### Parameters #### Path Parameters None #### Query Parameters - **args** (ResourceArguments) - Optional - Resource data per API specification **Special Parameters:** - `idempotency_key` (string, optional): For idempotent requests ### Request Example ```typescript const webhook = await fintoc.webhookEndpoints.create({ url: 'https://example.com/webhooks', enabled_events: ['link.created', 'link.deleted'], description: 'Production webhook endpoint' }); ``` ### Response #### Success Response - **ResourceType** - The created resource ``` -------------------------------- ### Initialize Fintoc Client and List Payment Intents Source: https://github.com/fintoc-com/fintoc-node/blob/master/README.md Initialize the Fintoc client with your API key and demonstrate listing payment intents with a date filter. Requires Node 10+. ```javascript import { Fintoc } from 'fintoc'; const fintocClient = new Fintoc('your_api_key'); // List all succeeded payment intents since the beginning of 2025 const paymentIntents = await fintocClient.paymentIntents.list({ since: '2025-01-01' }); for await (const pi of paymentIntents) { console.log(pi.created_at, pi.amount, pi.status); } ``` ```javascript // Get a specific payment intent const paymentIntent = await fintocClient.paymentIntents.get('pi_12312312'); console.log(paymentIntent.created_at, paymentIntent.amount, paymentIntent.status); ``` -------------------------------- ### Automatic Resource Identifier Usage Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/resource-mixin-methods.md Demonstrates how the Fintoc library automatically uses the resource's identifier for get, update, and delete operations. The 'get' operation retrieves a resource, and subsequent 'update' and 'delete' calls on that resource instance use its internal identifier. ```typescript const link = await fintoc.links.get('link_token'); const updated = await link.update({ /* ... */ }); // Uses _linkToken internally const deleted = await link.delete(); // Uses _linkToken internally ``` -------------------------------- ### Get Resource Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/quick-reference.md Retrieve a specific resource by its unique identifier. ```typescript const resource = await fintoc.paymentIntents.get('pi_12345678'); ``` -------------------------------- ### Initialize Fintoc SDK Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/quick-reference.md Instantiate the Fintoc client with your API key. Optionally, provide a private key for JWS signing and configuration options. ```typescript import { Fintoc } from 'fintoc'; const fintoc = new Fintoc('your_api_key', privateKey?, options?) ``` -------------------------------- ### Fintoc SDK Initialization Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/quick-reference.md Initialize the Fintoc SDK with your API key. Optionally, you can provide a private key and configuration options. ```APIDOC ## Fintoc SDK Initialization ### Description Initialize the Fintoc SDK with your API key. Optionally, you can provide a private key and configuration options. ### Method ```typescript new Fintoc(apiKey: string, privateKey?: string, options?: object) ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```typescript import { Fintoc } from 'fintoc'; const fintoc = new Fintoc('your_api_key', privateKey?, options?) ``` ### Response #### Success Response (200) An instance of the Fintoc SDK. #### Response Example ```typescript // No direct response example, returns an initialized Fintoc object ``` ``` -------------------------------- ### Load API and Private Keys from Environment Variables Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/configuration.md Recommended approach for storing sensitive configuration like API keys. Ensure FINTOC_API_KEY is set. ```javascript const apiKey = process.env.FINTOC_API_KEY; const privateKey = process.env.FINTOC_PRIVATE_KEY; if (!apiKey) { throw new Error('FINTOC_API_KEY environment variable is required'); } const fintoc = new Fintoc(apiKey, privateKey); ``` -------------------------------- ### EntitiesManager Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/api-reference-managers.md Manages V2 entities. Supports listing and getting entities. ```APIDOC ## EntitiesManager ### Description Manages V2 entities. Supports listing and getting entities. ### Resource path `/v2/entities` ### Available methods `list`, `get` ### Example Usage ```typescript const entities = await fintoc.v2.entities.list(); ``` ``` -------------------------------- ### InvoicesManager (V2) Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/api-reference-managers.md Manages V2 invoices. Supports listing and getting invoices. ```APIDOC ## InvoicesManager (V2) ### Description Manages V2 invoices. Supports listing and getting invoices. ### Resource path `/v2/invoices` ### Available methods `list`, `get` ### Example Usage ```typescript const invoices = await fintoc.v2.invoices.list(); ``` ``` -------------------------------- ### Initialize Fintoc Client with JWS Signing from File Path Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/webhook-signature-jws.md Pass the file path of your private key directly to the Fintoc client constructor. The library will handle reading the key from the specified location. ```typescript // Pass file path directly const fintoc = new Fintoc('your_api_key', '/etc/fintoc/private_key.pem'); ``` -------------------------------- ### Integration Testing with API Key Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/configuration.md This snippet demonstrates setting up the Fintoc SDK for integration testing using an environment variable for the API key. It shows creating a test charge. ```typescript const fintoc = new Fintoc(process.env.TEST_API_KEY!); // Create test resources const testCharge = await fintoc.charges.create({ amount: 1000, currency: 'clp', description: 'Test charge' }); // Run tests... ``` -------------------------------- ### Initialize Fintoc Client with JWS Signing from Buffer Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/webhook-signature-jws.md Initialize the Fintoc client with a private key provided as a Buffer. This is useful if you have already loaded the key into memory. ```typescript import fs from 'fs'; const keyBuffer = fs.readFileSync('/path/to/key.pem'); const fintoc = new Fintoc('your_api_key', keyBuffer); ``` -------------------------------- ### Whoami Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/resource-types.md Retrieves information about the currently authenticated account. Supports only the 'get' operation. ```APIDOC ## Whoami ### Description Retrieves information about the currently authenticated account. Supports only the 'get' operation. ### Operations - get ### Example Usage ```typescript const account = await fintoc.whoami.get('whoami'); ``` ``` -------------------------------- ### V2 SubscriptionsManager Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/api-reference-managers.md Manages V2 subscriptions. Supports listing, getting, and canceling subscriptions. ```APIDOC ## V2 SubscriptionsManager ### Description Manages V2 subscriptions. Supports listing, getting, and canceling subscriptions. ### Resource path `/v2/subscriptions` ### Available methods `list`, `get`, `cancel` ### `cancel` Method #### Description Cancel a subscription. #### Arguments - `subscriptionId` (string) - The ID of the subscription to cancel. - `args` (ResourceArguments) - Optional. Additional arguments for the cancel operation. #### Returns - `Promise`: A promise that resolves with the canceled Subscription object. ### Example Usage ```typescript const subscription = await fintoc.v2.subscriptions.cancel('sub_8anqVLlBC8ROodem'); ``` ``` -------------------------------- ### Using Async Generators for Efficient Listing Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/README.md Demonstrates the default memory-efficient way to list items using async generators. Also shows how to fetch all items at once, though not recommended for large datasets. ```typescript // Memory efficient (default) const items = await fintoc.paymentIntents.list(); for await (const item of items) { } // Get all at once (not recommended for large datasets) const items = await fintoc.paymentIntents.list({ lazy: false }); ``` -------------------------------- ### Access V1 and V2 APIs Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/configuration.md Demonstrates how to instantiate the Fintoc client and access both the default V1 API and the V2 API using the `.v2` property. V1 is the legacy API, while V2 includes most new features. ```typescript const fintoc = new Fintoc('your_api_key'); // V1 API (default) const accounts = await fintoc.accounts.list(); // V2 API (accessed via .v2 property) const v2Accounts = await fintoc.v2.accounts.list(); ``` -------------------------------- ### PaymentMethodsManager Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/api-reference-managers.md Manages V2 payment methods. Supports listing and getting payment methods. ```APIDOC ## PaymentMethodsManager ### Description Manages V2 payment methods. Supports listing and getting payment methods. ### Resource path `/v2/payment_methods` ### Available methods `list`, `get` ### Example Usage ```typescript const methods = await fintoc.v2.paymentMethods.list(); ``` ``` -------------------------------- ### AccountVerificationsManager Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/api-reference-managers.md Manages V2 account verifications. Supports listing and getting account verifications. ```APIDOC ## AccountVerificationsManager ### Description Manages V2 account verifications. Supports listing and getting account verifications. ### Resource path `/v2/account_verifications` ### Available methods `list`, `get` ### Example Usage ```typescript const verifications = await fintoc.v2.accountVerifications.list(); ``` ``` -------------------------------- ### Extend Client with Custom Parameters Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/types-and-interfaces.md Demonstrates how to extend an existing client instance with custom parameters, such as a specific link token. This is an internal usage pattern. ```typescript // Used internally by managers const extendedClient = client.extend({ params: { link_token: 'token_12345' } }); ``` -------------------------------- ### AccountNumbersManager Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/api-reference-managers.md Manages V2 account numbers. Supports listing and getting account numbers. ```APIDOC ## AccountNumbersManager ### Description Manages V2 account numbers. Supports listing and getting account numbers. ### Resource path `/v2/account_numbers` ### Available methods `list`, `get` ### Example Usage ```typescript const accountNumbers = await fintoc.v2.accountNumbers.list(); ``` ``` -------------------------------- ### Create a Subscription Intent Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/resource-types.md Initiate the creation of a subscription by creating a SubscriptionIntent. This is useful for setting up recurring payments. ```typescript const intent = await fintoc.subscriptionIntents.create({ amount: 10000, frequency: 'monthly' }); ``` -------------------------------- ### list Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/api-reference-managers.md Lists all instances of a resource. By default, it returns an async generator for memory efficiency, but can be configured to return a full array. ```APIDOC ## list ### Description Lists all instances of the resource. By default returns an async generator for memory efficiency. ### Method list ### Parameters #### Path Parameters None #### Query Parameters - **args** (ResourceArguments & { lazy?: boolean }) - Optional - Filter parameters per resource type, with an option to set `lazy` to false to return a full array instead of a generator. ### Request Example ```typescript // Returns async generator (memory efficient, lazy loading) const items = await manager.list(); for await (const item of items) { console.log(item); } // Returns full array (use with caution—may be memory intensive) const allItems = await manager.list({ lazy: false }); console.log(allItems.length); // With filters const filtered = await manager.list({ since: '2025-01-01', until: '2025-12-31', lazy: false }); ``` ### Response #### Success Response - **AsyncGenerator** by default or **ResourceType[]** if `lazy: false` ``` -------------------------------- ### TransfersManager Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/api-reference-managers.md Manages V2 transfers. Supports listing, getting, creating, and returning transfers. ```APIDOC ## TransfersManager ### Description Manages V2 transfers. Supports listing, getting, creating, and returning transfers. ### Resource path `/v2/transfers` ### Available methods `list`, `get`, `create`, `return` ### `return` Method #### Description Return a transfer. #### Arguments - `args` (ResourceArguments) - Optional. Arguments for the return operation, including `transfer_id`. #### Returns - `Promise`: A promise that resolves with the returned Transfer object. ### Example Usage ```typescript const transfer = await fintoc.v2.transfers.return({ transfer_id: 'trf_12345678' }); ``` ``` -------------------------------- ### V2 Product Operations Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/resource-types.md Manages product records, supporting list and get operations. ```APIDOC ## V2 Product ### Description Manages product records, supporting list and get operations. ### Operations - list - get ### Example Usage ```typescript const products = await fintoc.v2.products.list(); ``` ``` -------------------------------- ### Fintoc Node Project File Organization Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/MANIFEST.md Illustrates the directory structure for the Fintoc Node.js library, showing the location of key documentation files like README.md and MANIFEST.md. ```tree output/ ├── README.md # Start here ├── MANIFEST.md # This file │ ├── [QUICK START] ├── quick-reference.md # Fast lookup ├── configuration.md # Setup guide ├── api-reference-fintoc-client.md # Main class │ ├── [DETAILED REFERENCE] ├── api-reference-managers.md # All managers ├── resource-types.md # All resources ├── resource-mixin-methods.md # Instance methods ├── types-and-interfaces.md # Types │ ├── [SECURITY & ERRORS] ├── webhook-signature-jws.md # Security ├── errors-and-exceptions.md # Error handling │ ├── [DEEP DIVES] ├── usage-patterns.md # Real examples └── architecture.md # Technical internals ``` -------------------------------- ### Invoice (V1) Operations Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/resource-types.md Represents a financial invoice. Supports list and get operations. ```APIDOC ## Invoice (V1) Operations ### Description Represents a financial invoice. Supports `list` and `get` operations. ### Method GET ### Endpoint `/invoices` ``` -------------------------------- ### Initialize Fintoc Client with JWS Signing from Environment Variable Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/webhook-signature-jws.md Initialize the Fintoc client using a private key stored in an environment variable. This is a common practice for managing sensitive credentials. ```typescript const privateKeyPEM = process.env.FINTOC_PRIVATE_KEY; const fintoc = new Fintoc('your_api_key', privateKeyPEM); ``` -------------------------------- ### Account Operations Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/resource-types.md Represents a financial account linked through Fintoc. Supports get operations. ```APIDOC ## Account Operations ### Description Represents a financial account linked through Fintoc. Supports `get` operations. ### Method GET ### Endpoint `/accounts/{id}` ### Parameters #### Path Parameters - **id** (string) - Required - The identifier of the account. ### Response #### Success Response (200) - **id** (string) - Account identifier - **holder_name** (string) - Account holder name - **number** (string) - Account number - **currency** (string) - Currency code - **balance** (object) - Account balance (may be nested object) ``` -------------------------------- ### Complete Update-Serialize Workflow Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/resource-mixin-methods.md Demonstrates a complete workflow of retrieving, updating, and serializing a resource instance. This is useful for managing and preparing resource data for logging or storage. ```typescript import { Fintoc } from 'fintoc'; const fintoc = new Fintoc('your_api_key'); // Get a webhook endpoint const webhook = await fintoc.webhookEndpoints.get('we_8anqVLlBC8ROodem'); console.log('Original:', webhook.serialize()); // { id: 'we_...', url: 'https://example.com/hook', enabled: true, ... } // Update it const updated = await webhook.update({ enabled_events: ['charge.created', 'charge.refunded'] }); console.log('Updated:', updated.serialize()); // { id: 'we_...', url: 'https://example.com/hook', enabled: true, enabled_events: [...], ... } // Serialize for logging/storage const data = updated.serialize(); console.log(JSON.stringify(data, null, 2)); ``` -------------------------------- ### Basic Fintoc Node.js Usage Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/README.md Demonstrates basic operations including listing payments, creating a charge, and updating a webhook endpoint using the Fintoc Node.js client. ```typescript import { Fintoc } from 'fintoc'; const fintoc = new Fintoc(process.env.FINTOC_API_KEY); // List payments const payments = await fintoc.paymentIntents.list(); for await (const payment of payments) { console.log(payment.id, payment.amount); } // Create a charge const charge = await fintoc.charges.create({ amount: 50000, currency: 'clp' }); // Get and update const webhook = await fintoc.webhookEndpoints.get('we_12345'); await webhook.update({ enabled_events: ['charge.created'] }); ``` -------------------------------- ### V2 AccountVerification Operations Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/resource-types.md Retrieves the account verification status, supporting list and get operations. ```APIDOC ## V2 AccountVerification ### Description Retrieves the account verification status, supporting list and get operations. ### Operations - list - get ### Example Usage ```typescript const verifications = await fintoc.v2.accountVerifications.list(); ``` ``` -------------------------------- ### Interacting with Resource Instances Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/README.md Shows how to use resource methods on individual instances, such as updating, deleting, and serializing data. ```typescript const pi = await fintoc.paymentIntents.get(id); await pi.update({}) // Resource method await pi.delete() // Resource method const data = pi.serialize() // Resource method ``` -------------------------------- ### Create Resource Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/quick-reference.md Creates a new resource with the provided details. ```APIDOC ## Create Resource ### Description Creates a new resource with the provided details. ### Method POST (implied) ### Endpoint `/resources` (implied, specific resource type depends on the manager, e.g., `/charges`) ### Parameters #### Request Body - **amount** (number) - Required - The amount of the charge. - **currency** (string) - Required - The currency of the amount (e.g., 'clp'). - **idempotency_key** (string) - Required - A unique key to ensure the request is processed only once. ### Request Example ```typescript const resource = await fintoc.charges.create({ amount: 50000, currency: 'clp', idempotency_key: 'unique-key-12345' }); ``` ### Response #### Success Response (201) - **resource** (object) - The created resource object. #### Response Example ```json { "id": "resource_id", "amount": 50000, "currency": "clp", "status": "pending", ... } ``` ``` -------------------------------- ### List and Get Invoices Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/api-reference-managers.md Use InvoicesManager to list all invoices or retrieve a specific invoice by its ID. ```typescript const invoices = await fintoc.invoices.list(); const invoice = await fintoc.invoices.get('inv_12345678'); ``` -------------------------------- ### Get Current Account Info Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/resource-types.md Retrieve information about the currently authenticated account. This is a read-only operation. ```typescript const account = await fintoc.whoami.get('whoami'); ``` -------------------------------- ### List and Get Accounts Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/api-reference-managers.md Use AccountsManager to list all accounts or retrieve a specific account by its ID. ```typescript const accounts = await fintoc.accounts.list(); const account = await fintoc.accounts.get('acc_12345678'); ``` -------------------------------- ### Create Resource Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/quick-reference.md Create a new resource by providing the necessary parameters such as amount, currency, and an idempotency key. ```typescript const resource = await fintoc.charges.create({ amount: 50000, currency: 'clp', idempotency_key: 'unique-key-12345' }); ``` -------------------------------- ### Event Operations Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/resource-types.md Represents an API event log entry. Supports list and get operations. ```APIDOC ## Event Operations ### Description Represents an API event log entry. Supports `list` and `get` operations. ### Method GET ### Endpoint `/events` ### Parameters #### Query Parameters - **since** (string) - Optional - Filter events created since this timestamp. ``` -------------------------------- ### Production Configuration with Best Practices Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/configuration.md Configure the Fintoc client for production, emphasizing security and logging. Uses environment variables for sensitive information and includes basic error handling. ```typescript const fintoc = new Fintoc( process.env.FINTOC_API_KEY!, process.env.FINTOC_PRIVATE_KEY, { userAgent: `${process.env.APP_NAME}/${process.env.APP_VERSION}` } ); // Log API interactions process.on('unhandledRejection', (reason) => { console.error('Unhandled rejection:', reason); process.exit(1); }); ``` -------------------------------- ### Dispute Operations Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/resource-types.md Represents a payment dispute. Supports list, get, submitForReview, and createDocument operations. ```APIDOC ## Dispute Operations ### Description Represents a payment dispute. Supports `list`, `get`, `submitForReview`, and `createDocument` operations. ### Method GET, POST ### Endpoint `/disputes/{id}` (for get) `/disputes` (for list, createDocument) ### Parameters #### Path Parameters - **id** (string) - Required - The identifier of the dispute. #### Request Body (for createDocument) - **file** (string) - Required - The base64 encoded content of the document. ``` -------------------------------- ### Charge Operations Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/resource-types.md Represents a charge request against an account. Supports list, get, and create operations. ```APIDOC ## Charge Operations ### Description Represents a charge request against an account. Supports `list`, `get`, and `create` operations. ### Method POST ### Endpoint `/charges` ### Parameters #### Request Body - **amount** (integer) - Required - The amount of the charge. - **currency** (string) - Required - The currency of the charge (e.g., 'clp'). - **description** (string) - Optional - A description for the charge. ``` -------------------------------- ### List Resources (Array) Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/quick-reference.md Use the array pattern to load all resources into memory. Set `lazy: false` to enable this behavior. ```typescript // Array (loads all into memory) const items = await fintoc.paymentIntents.list({ lazy: false }); ``` -------------------------------- ### Using ResourceArguments for Simple Parameters Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/types-and-interfaces.md Demonstrates how to use the ResourceArguments type for simple key-value pairs, such as date ranges for listing resources. ```typescript import { Fintoc } from 'fintoc'; import { ResourceArguments } from 'fintoc'; const fintoc = new Fintoc('your_api_key'); // Simple parameters const args1: ResourceArguments = { since: '2025-01-01', until: '2025-12-31' }; const payments = await fintoc.paymentIntents.list(args1); ``` -------------------------------- ### List Resources (Full Array) Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/api-reference-managers.md Retrieve all resources as a full array. Use with caution for large datasets as it may consume significant memory. ```typescript // Returns full array (use with caution—may be memory intensive) const allItems = await manager.list({ lazy: false }); console.log(allItems.length); ``` -------------------------------- ### V2 Entity Operations Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/resource-types.md Manages entity records (persons or companies), supporting list and get operations. ```APIDOC ## V2 Entity ### Description Manages entity records (persons or companies), supporting list and get operations. ### Operations - list - get ### Example Usage ```typescript const entities = await fintoc.v2.entities.list(); ``` ``` -------------------------------- ### RefreshIntent Operations Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/resource-types.md Represents a request to refresh link credentials. Supports list, get, and create operations. ```APIDOC ## RefreshIntent Operations ### Description Represents a request to refresh link credentials. Supports `list`, `get`, and `create` operations. ### Method POST ### Endpoint `/refresh_intents` ### Parameters #### Request Body - **link_token** (string) - Required - The token of the link to refresh. ``` -------------------------------- ### Initialize Fintoc Client Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/quick-reference.md Initialize the Fintoc client with your API key and optionally a private key for JWS signing and a custom user agent. The API key is required, while the private key and user agent are optional. ```typescript const fintoc = new Fintoc( 'your_api_key', '/path/to/private_key.pem', { userAgent: 'my-app/1.0.0' } ); ``` -------------------------------- ### Fintoc Constructor with API Key Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/configuration.md Initialize the Fintoc client with your API key. Ensure your API key is kept secure and not committed to version control. ```typescript constructor(apiKey: string, jwsPrivateKey?: string, options?: { userAgent?: string }) ``` -------------------------------- ### PaymentLink Operations Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/resource-types.md Represents a shareable payment link. Supports list, get, create, and cancel operations. ```APIDOC ## PaymentLink Operations ### Description Represents a shareable payment link. Supports `list`, `get`, `create`, and `cancel` operations. ### Method POST, GET ### Endpoint `/payment_links` ### Parameters #### Request Body (for create) - **amount** (integer) - Required - The amount of the payment. - **description** (string) - Optional - A description for the payment link. ``` -------------------------------- ### Fintoc Authentication Error: Invalid API Key Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/errors-and-exceptions.md Example demonstrating how an invalid API key triggers an AuthenticationError. ```typescript const fintoc = new Fintoc('invalid_key'); // Error: unauthorized: invalid_api_key ``` -------------------------------- ### Resource Instance Methods Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/README.md These methods are available on individual resource instances, allowing for operations directly on that specific resource. ```APIDOC ## Methods on Resource Instances ### `update(args?)` #### Description Updates the current resource instance with new data. #### Method Not applicable (SDK method) #### Parameters - **args** (object) - Required - The updated data for the resource. #### Returns - `Promise` - A promise that resolves with the updated resource. ### `delete(args?)` #### Description Deletes the current resource instance. #### Method Not applicable (SDK method) #### Parameters - **args** (object) - Optional - Additional arguments for the delete operation. #### Returns - `Promise` - A promise that resolves with a confirmation message or status. ### `serialize()` #### Description Converts the resource instance into a plain JavaScript object. #### Method Not applicable (SDK method) #### Parameters None. #### Returns - `Record` - A plain object representing the resource. ``` -------------------------------- ### Handle Nonexistent Key File Error Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/webhook-signature-jws.md Shows how to handle errors when the specified private key file path does not exist or cannot be read. This is crucial for ensuring your application can gracefully manage file access issues. ```typescript import { Fintoc } from 'fintoc'; try { const fintoc = new Fintoc('your_api_key', '/nonexistent/path/to/key.pem'); } catch (error) { console.error('Cannot read key file:', error.message); // Error: Failed to read private key file: /nonexistent/path/to/key.pem. ... } ``` -------------------------------- ### Fintoc Client Constructor Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/api-reference-fintoc-client.md Initializes a new Fintoc Client instance. Accepts options for API base URL, API key, User-Agent, default query parameters, and an optional private key for JWS signatures. ```typescript constructor(options: IConstructorOptions) ``` -------------------------------- ### Fintoc Client Constructor Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/api-reference-fintoc-client.md Initializes the Fintoc client with an API key and optional JWS private key or custom user agent for authentication and configuration. ```APIDOC ## Constructor ```typescript constructor(apiKey: string, jwsPrivateKey?: string, options?: { userAgent?: string }) ``` ### Parameters #### Path Parameters * **apiKey** (string) - Required - API key from your Fintoc Dashboard * **jwsPrivateKey** (string \| Buffer) - Optional - Private key for JWS signature generation (PEM format, file path, or Buffer) * **options** ({ userAgent?: string }) - Optional - Optional configuration object * **userAgent** (string) - Optional - Custom User-Agent header value (defaults to `fintoc-node/{version}`) ### Returns Instance of `Fintoc` class with initialized resource managers. ``` -------------------------------- ### Get a Single Payment Intent Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/usage-patterns.md Retrieve a specific payment intent using its ID and log its status and amount. ```typescript const payment = await fintoc.paymentIntents.get('pi_12345678'); console.log(payment.status, payment.amount); ``` -------------------------------- ### Get Current Account Information Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/api-reference-managers.md Retrieves the current authenticated account's information using the 'whoami' endpoint. ```typescript const currentAccount = await fintoc.whoami.get('whoami'); ``` -------------------------------- ### Fintoc Client Class Structure Source: https://github.com/fintoc-com/fintoc-node/blob/master/_autodocs/architecture.md The Fintoc client class serves as the main entry point, managing access to both V1 and V2 API versions through direct properties and a nested `.v2` namespace respectively. It initializes internal HTTP clients and various resource managers. ```typescript export class Fintoc { #client: Client; // V1 managers accounts: AccountsManager; charges: ChargesManager; // ... // V2 namespace v2: FintocV2; constructor(apiKey, jwsPrivateKey?, options?) { // Initialize internal Client // Initialize all managers with paths } } class FintocV2 { // V2 managers only accounts: V2AccountsManager; transfers: TransfersManager; // ... } ```