UNPKG

pluggy-sdk

Version:

Official Node.js/TypeScript SDK for the Pluggy API.

325 lines (324 loc) 13 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PluggyPaymentsClient = void 0; const baseApi_1 = require("./baseApi"); /** * Creates a new client instance for interacting with Pluggy API for the Payments API * @constructor * @param API_KEY for authenticating to the API * @returns {PluggyPaymentsClient} a client for making requests */ class PluggyPaymentsClient extends baseApi_1.BaseApi { /** * Creates a payment request * @returns {PaymentRequest} PaymentRequest object */ async createPaymentRequest(paymentRequest) { return await this.createPostRequest(`payments/requests`, null, paymentRequest); } /** * Fetch a single payment request * @returns {PaymentRequest} PaymentRequest object */ async fetchPaymentRequest(id) { return await this.createGetRequest(`payments/requests/${id}`); } /** * Fetch all payment requests * @returns {PageResponse<PaymentRequest>} paged response of payment requests */ async fetchPaymentRequests(options = {}) { return await this.createGetRequest('payments/requests', { ...options }); } /** * Delete a payment request */ async deletePaymentRequest(id) { await this.createDeleteRequest(`payments/requests/${id}`); } /** * Creates a payment intent * @returns {PaymentIntent} PaymentIntent object */ async createPaymentIntent(params) { return await this.createPostRequest(`payments/intents`, null, params); } /** * Fetch a single payment intent * @returns {PaymentIntent} PaymentIntent object */ async fetchPaymentIntent(id) { return await this.createGetRequest(`payments/intents/${id}`); } /** * Fetch all payment intents * @returns {PageResponse<PaymentIntent>} paged response of payment intents */ async fetchPaymentIntents(options = {}) { return await this.createGetRequest('payments/intents', { ...options }); } /** * Creates a payment customer * @returns {PaymentCustomer} PaymentCustomer object */ async createPaymentCustomer(payload) { return await this.createPostRequest(`payments/customers`, null, payload); } /** * Fetch a single payment customer * @returns {PaymentCustomer} PaymentCustomer object */ async fetchPaymentCustomer(id) { return await this.createGetRequest(`payments/customers/${id}`); } /** * Fetch all payment customers * @returns {PageResponse<PaymentCustomer>} paged response of payment customers */ async fetchPaymentCustomers(options = {}) { return await this.createGetRequest('payments/customers', { ...options }); } /** * Delete a payment customer */ async deletePaymentCustomer(id) { await this.createDeleteRequest(`payments/customers/${id}`); } async updatePaymentCustomer(id, payload) { return await this.createPatchRequest(`payments/customers/${id}`, null, payload); } /** * Creates a payment recipient (bank account) * @returns {PaymentRecipient} PaymentRecipient object */ async createPaymentRecipient(payload) { return await this.createPostRequest(`payments/recipients`, null, payload); } /** * Fetch a single payment recipient * @returns {PaymentRecipient} PaymentRecipient object */ async fetchPaymentRecipient(id) { return await this.createGetRequest(`payments/recipients/${id}`); } /** * Fetch all payment recipients * @returns {PageResponse<PaymentRecipient>} paged response of payment recipients */ async fetchPaymentRecipients(options = {}) { return await this.createGetRequest('payments/recipients', { ...options }); } /** * Delete a payment recipient */ async deletePaymentRecipient(id) { await this.createDeleteRequest(`payments/recipients/${id}`); } /** * Update a payment recipient * @param id ID of the payment recipient * @param payload Fields to update * @returns {PaymentRecipient} PaymentRecipient object */ async updatePaymentRecipient(id, payload) { return await this.createPatchRequest(`payments/recipients/${id}`, null, payload); } /** * Fetch a single payment recipient institution * @returns {PaymentInstitution} PaymentInstitution object */ async fetchPaymentInstitution(id) { return await this.createGetRequest(`payments/recipients/institutions/${id}`); } /** * Fetch all payment recipient institutions * @returns {PageResponse<PaymentInstitution>} paged response of payment recipient institutions */ async fetchPaymentInstitutions(options) { return await this.createGetRequest('payments/recipients/institutions', { ...options }); } /** * Create a bulk payment * @returns {BulkPayment} BulkPayment object */ async createBulkPayment(payload) { return await this.createPostRequest(`payments/bulk`, null, payload); } /** * Fetch a single bulk payment * @returns {BulkPayment} BulkPayment object */ async fetchBulkPayment(id) { return await this.createGetRequest(`payments/bulk/${id}`); } /** * Fetch all bulk payments * @returns {PageResponse<BulkPayment>} paged response of bulk payments */ async fetchBulkPayments(options = {}) { return await this.createGetRequest('payments/bulk', options); } /** Deletes the bulk payment */ async deleteBulkPayment(id) { await this.createDeleteRequest(`payments/bulk/${id}`); } /** * Creates a smart account * @returns {SmartAccount} SmartAccount object */ async createSmartAccount(payload) { return await this.createPostRequest(`payments/smart-accounts`, null, payload); } /** * Fetch a single smart account * @returns {SmartAccount} SmartAccount object */ async fetchSmartAccount(id) { return await this.createGetRequest(`payments/smart-accounts/${id}`); } /** * Fetch a smart account current balance * @returns {SmartAccountBalance} SmartAccountBalance object */ async fetchSmartAccountBalance(id) { return await this.createGetRequest(`payments/smart-accounts/${id}/balance`); } /** * Fetch all smart accounts * @returns {PageResponse<SmartAccount>} paged response of smart accounts */ async fetchSmartAccounts(options = {}) { return await this.createGetRequest('payments/smart-accounts', options); } /** * Creates a payment request automatic pix * @param pixAutomaticPayload CreatePaymentRequestAutomaticPix * @returns {PaymentRequestAutomaticPix} PaymentRequestAutomaticPix object */ async createPaymentRequestPixAutomatico(pixAutomaticPayload) { return await this.createPostRequest(`payments/requests/automatic-pix`, null, pixAutomaticPayload); } /** * Fetch all scheduled payments from a payment request * @param paymentRequest ID of the payment request */ async fetchScheduledPayments(paymentRequest) { return await this.createGetRequest(`payments/requests/${paymentRequest}/schedules`); } /** * Fetch a single scheduled payment from a payment request * @param paymentRequest ID of the payment request * @param scheduleId ID of the scheduled payment */ async fetchScheduledPayment(paymentRequest, scheduleId) { return await this.createGetRequest(`payments/requests/${paymentRequest}/schedules/${scheduleId}`); } /** * Cancel a scheduled payment from a payment request * @param paymentRequest ID of the payment request * @param scheduleId ID of the scheduled payment */ async cancelScheduledPayment(paymentRequest, scheduleId) { await this.createPostRequest(`payments/requests/${paymentRequest}/schedules/${scheduleId}/cancel`); } /** * Cancel the payment request authorization of a scheduled payment (cancel all pending payments) * @param paymentRequest ID of the payment request */ async cancelScheduledPayments(paymentRequest) { await this.createPostRequest(`payments/requests/${paymentRequest}/schedules/cancel`); } /** * Schedule a new payment for an existing Pix Automático authorization * @param authorizationId ID of the Pix Automático authorization * @param payload ScheduleAutomaticPixPaymentRequest * @returns {AutomaticPixPayment} AutomaticPixPayment object */ async scheduleAutomaticPixPayment(authorizationId, payload) { return await this.createPostRequest(`payments/requests/${authorizationId}/automatic-pix/schedule`, null, payload); } /** * Retry a failed scheduled Pix Automático payment * @param paymentRequestId ID of the payment request * @param automaticPixPaymentId ID of the Pix Automático authorization * @param payload RetryAutomaticPixPaymentRequest * @returns {AutomaticPixPayment} AutomaticPixPayment object */ async retryAutomaticPixPayment(paymentRequestId, automaticPixPaymentId, payload) { return await this.createPostRequest(`payments/requests/${paymentRequestId}/automatic-pix/schedules/${automaticPixPaymentId}/retry`, null, payload); } /** * List scheduled Pix Automático payments for an authorization * @param automaticPixPaymentId ID of the Pix Automático authorization * @param options PaymentPixAutomaticFilters * @returns {AutomaticPixPaymentListResponse} List of scheduled payments */ async fetchAutomaticPixPayments(automaticPixPaymentId, options) { return await this.createGetRequest(`payments/requests/${automaticPixPaymentId}/automatic-pix/schedules`, options); } /** * Fetch a single scheduled Pix Automático payment * @param paymentRequestId ID of the payment request * @param automaticPixPaymentId ID of the Pix Automático authorization * @returns {AutomaticPixPayment} AutomaticPixPayment object */ async fetchAutomaticPixPayment(paymentRequestId, automaticPixPaymentId) { return await this.createGetRequest(`payments/requests/${paymentRequestId}/automatic-pix/schedules/${automaticPixPaymentId}`); } /** * Cancel a scheduled Pix Automático payment * @param paymentRequestId ID of the payment request * @param automaticPixPaymentId ID of the Pix Automático authorization */ async cancelAutomaticPixPayment(paymentRequestId, automaticPixPaymentId) { await this.createPostRequest(`payments/requests/${paymentRequestId}/automatic-pix/schedules/${automaticPixPaymentId}/cancel`); } /** * Cancel all scheduled Pix Automático payments for a payment request authorization * @param paymentRequestId ID of the payment request */ async cancelAutomaticPixAuthorization(paymentRequestId) { await this.createPostRequest(`payments/requests/${paymentRequestId}/automatic-pix/cancel`); } /** * Fetch all smart transfer preauthorizations * @param options SmartTransferPreauthorizationsFilters with page and pageSize * @returns {PageResponse<SmartTransferPreauthorization>} paged response of smart transfer preauthorizations */ async fetchSmartTransferPreauthorizations(options = {}) { return await this.createGetRequest('smart-transfers/preauthorizations', { ...options }); } /** * Creates a smart transfer preauthorization * @param payload CreateSmartTransferPreauthorization * @returns {SmartTransferPreauthorization} SmartTransferPreauthorization object */ async createSmartTransferPreauthorization(payload) { return await this.createPostRequest('smart-transfers/preauthorizations', null, payload); } /** * Fetch a single smart transfer preauthorization * @param id ID of the smart transfer preauthorization * @returns {SmartTransferPreauthorization} SmartTransferPreauthorization object */ async fetchSmartTransferPreauthorization(id) { return await this.createGetRequest(`smart-transfers/preauthorizations/${id}`); } /** * Creates a smart transfer payment * @param payload CreateSmartTransferPayment * @returns {SmartTransferPayment} SmartTransferPayment object */ async createSmartTransferPayment(payload) { return await this.createPostRequest('smart-transfers/payments', null, payload); } /** * Fetch a single smart transfer payment * @param id ID of the smart transfer payment * @returns {SmartTransferPayment} SmartTransferPayment object */ async fetchSmartTransferPayment(id) { return await this.createGetRequest(`smart-transfers/payments/${id}`); } } exports.PluggyPaymentsClient = PluggyPaymentsClient;