UNPKG

@basel_mn/qv-api-client

Version:

TypeScript/JavaScript client for QV API, providing easy access to invoices, payments, and Swish integration

80 lines (79 loc) 2.94 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.InvoicesApi = void 0; class InvoicesApi { constructor(client) { this.client = client; } getInvoices() { return __awaiter(this, arguments, void 0, function* (params = {}) { try { const response = yield this.client.get('/invoices', { params }); console.log('api client: Invoices status:', response.status); if (response.status !== 200) { throw new Error('Failed to fetch invoices'); } return response; } catch (error) { throw error; } }); } getInvoice(_a) { return __awaiter(this, arguments, void 0, function* ({ id, hash }) { try { const { data } = yield this.client.get(`/invoices/${id}/${hash}`); console.log('api client: Invoice detail:', `/invoices/${id}/${hash}`); console.log('api client: Invoice detail status:', data.status); return data; } catch (error) { throw error; } }); } getInvoiceStatus(id) { return __awaiter(this, void 0, void 0, function* () { try { const { data } = yield this.client.get(`/invoices/${id}/status`); return data; } catch (error) { throw error; } }); } sendInvoiceReminder(id) { return __awaiter(this, void 0, void 0, function* () { try { const { data } = yield this.client.post(`/invoices/${id}/reminder`); return data; } catch (error) { throw error; } }); } createInvoicePayment(id, paymentData) { return __awaiter(this, void 0, void 0, function* () { try { const { data } = yield this.client.post(`/invoices/${id}/payment`, paymentData); return data; } catch (error) { throw error; } }); } } exports.InvoicesApi = InvoicesApi;