UNPKG

akua-sdk

Version:

TypeScript SDK for Akua Acquiring Processor

204 lines (203 loc) 7.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MerchantService = void 0; const mapper_1 = require("../helpers/mapper"); /** * Service responsible for managing merchant-related operations in the Akua API. * @class MerchantService */ class MerchantService { httpClient; /** * Creates an instance of MerchantService. * @param {HttpClient} httpClient - The HTTP client instance used for making API requests. */ constructor(httpClient) { this.httpClient = httpClient; } /** * Creates a new merchant in the Akua system. * @async * @param {CreateMerchantRequest} createMerchantRequest - The data required to create a new merchant * @returns {Promise<ApiResponse<MerchantDTO>>} A promise that resolves to the newly created merchant information * @example * // Create a new merchant * await merchantService.create({ * name: 'My Store', * organization_id: 'org_123', * country: 'US', * city: 'New York', * state: 'NY', * billing_address: { * street: '123 Main St', * city: 'New York', * state: 'NY', * country: 'US', * postal_code: '10001' * }, * location_address: { * street: '123 Main St', * city: 'New York', * state: 'NY', * country: 'US', * postal_code: '10001' * }, * classification_mode: 'retail', * default_currency: 'USD', * supported_currencies: ['USD', 'EUR'], * activity: 'retail', * alias: 'my-store-ny', * email: 'store@example.com', * external_id: 'ext_123', * phone: '+1234567890', * tax_id: '123456789', * rails: { * VISA: { * category_code: '5411', * payfac_id: 'payfac_123' * }, * MASTERCARD: { * category_code: '5411', * payfac_id: 'payfac_123' * } * } * }); */ async create(createMerchantRequest) { const response = await this.httpClient.post('/v1/merchants', createMerchantRequest); const mappedData = mapper_1.Mapper.mapToMerchantDTO(response.data); return { ...response, data: mappedData, }; } /** * Retrieves a merchant's information by its unique identifier. * @async * @param {string} merchantId - The unique identifier of the merchant to retrieve. * @returns {Promise<ApiResponse<MerchantDTO>>} A promise that resolves to the merchant's information. * @example * // Get merchant information by ID * await merchantService.getById('merch_123456789'); */ async getById(merchantId) { const response = await this.httpClient.get(`/v1/merchants/${merchantId}`); return { ...response, data: mapper_1.Mapper.mapToMerchantDTO(response.data), }; } /** * Deletes a merchant from the Akua system. * @async * @param {string} merchantId - The unique identifier of the merchant to delete. * @returns {Promise<ApiResponse<void>>} A promise that resolves when the merchant is successfully deleted. * @example * // Delete a merchant by ID * await merchantService.delete('merch_123456789'); */ async delete(merchantId) { const response = await this.httpClient.delete(`/v1/merchants/${merchantId}`); return response; } /** * Updates the rails configuration for a merchant. * @async * @param {string} merchantId - The unique identifier of the merchant to update. * @param {UpdateMerchantRailsRequest} updateRailsRequest - The new rails configuration for the merchant. * @returns {Promise<ApiResponse<MerchantDTO>>} A promise that resolves to the updated merchant information. * @example * // Update merchant rails configuration * await merchantService.updateRails('merch_123456789', { * VISA: { * category_code: '1234', * payfac_id: 'pfc-123', * external_id: 'mer-ext-123', * classification: 'micro-merchant', * annual_volume: [ * { * currency: 'COP', * value: 10000000 * } * ], * products: { * DEBIT: { * network_merchant_id: 'VISA-123', * enabled: true * }, * CREDIT: { * network_merchant_id: 'VISA-123', * enabled: true * } * } * } * }); */ async updateRails(merchantId, updateRailsRequest) { const response = await this.httpClient.put(`/v1/merchants/${merchantId}/rails`, updateRailsRequest); return { ...response, data: mapper_1.Mapper.mapToMerchantDTO(response.data), }; } /** * Lists all merchants for an organization with pagination support. * @async * @param {ListMerchantsRequest} request - The request parameters for listing merchants. * @returns {Promise<ApiResponse<MerchantDTO[]>>} A promise that resolves to a paginated list of merchants. * @example * // List merchants for an organization * await merchantService.get({ * organization_id: 'org-d0j35vc4t5u70r4eso70', * page: 1, * page_size: 20, * sort: 'created_at:desc' * }); */ async get(request) { const queryParams = new URLSearchParams(); queryParams.append('organization_id', request.organization_id); if (request.page) queryParams.append('page', request.page.toString()); if (request.page_size) queryParams.append('page_size', request.page_size.toString()); if (request.sort) queryParams.append('sort', request.sort); const response = await this.httpClient.get(`/v1/merchants?${queryParams.toString()}`); const mappedData = mapper_1.Mapper.mapToMerchantDTO(response.data.data); return { ...response, data: mappedData, pagination: response.data.pagination, }; } /** * Updates an existing merchant's information. * @async * @param {string} merchantId - The unique identifier of the merchant to update. * @param {UpdateMerchantRequest} updateRequest - The data to update the merchant with. * @returns {Promise<ApiResponse<MerchantDTO>>} A promise that resolves to the updated merchant information. * @example * // Update a merchant * await merchantService.update('merch_123456789', { * name: 'Updated Store Name', * email: 'updated@example.com', * phone: '+1987654321', * billing_address: { * street: '456 New St', * city: 'Los Angeles', * state: 'CA', * country: 'US', * postal_code: '90001' * } * }); */ async update(merchantId, updateRequest) { const response = await this.httpClient.put(`/v1/merchants/${merchantId}`, updateRequest); return { ...response, data: mapper_1.Mapper.mapToMerchantDTO(response.data), }; } } exports.MerchantService = MerchantService;