@basel_mn/qv-api-client
Version:
TypeScript/JavaScript client for QV API, providing easy access to invoices, payments, and Swish integration
109 lines (86 loc) • 2.75 kB
Markdown
# Billmate QV API Client
Official TypeScript/JavaScript client for Billmate's QV API, providing easy access to invoices, payments, and Swish integration.
## Installation
To install this package, run:
```bash
npm install @billmate/qv-api-client
```
## Usage
### TypeScript
```typescript
import ApiClient from '@billmate/qv-api-client';
const client = new ApiClient({
baseURL: 'https://api.example.com',
accessToken: 'your-access-token'
});
// Invoices API
async function getInvoices() {
try {
const response = await client.invoices.getInvoices();
console.log('Invoices:', response.data);
} catch (error) {
console.error('Error:', error);
}
}
// Payments API
async function getPaymentMethods() {
try {
const methods = await client.payments.getPaymentMethods();
console.log('Payment methods:', methods);
} catch (error) {
console.error('Error:', error);
}
}
// Swish API
async function initiateSwishPayment() {
try {
const payment = await client.swish.initiatePayment({
invoiceId: '123',
// other payment details
});
console.log('Payment initiated:', payment);
} catch (error) {
console.error('Error:', error);
}
}
```
### JavaScript
```javascript
const ApiClient = require('@billmate/qv-api-client').default;
const client = new ApiClient({
baseURL: 'https://api.example.com',
accessToken: 'your-access-token'
});
```
## API Reference
### Invoices API
- `getInvoices(params?)`: Get a list of invoices
- `getInvoice(id)`: Get a specific invoice by ID
- `getInvoiceStatus(id)`: Get the status of an invoice
- `sendInvoiceReminder(id)`: Send a reminder for an invoice
- `createInvoicePayment(id, paymentData)`: Create a payment for an invoice
### Payments API
- `getPayments(params?)`: Get a list of payments
- `getPayment(id)`: Get a specific payment by ID
- `getPaymentMethods()`: Get available payment methods
### Swish API
- `getStatus(invoiceId, orderId?)`: Get Swish payment status
- `initiatePayment(paymentData)`: Initiate a Swish payment
- `initiateRefund(refundData)`: Initiate a Swish refund
## Error Handling
The client includes built-in error handling with detailed error information:
```typescript
try {
await client.invoices.getInvoices();
} catch (error) {
if (error.status === 404) {
console.error('Not found:', error.details);
} else if (error.status === 0) {
console.error('Network error:', error.details);
}
}
```
## Contributing
If you would like to contribute to this project, please fork the repository and submit a pull request.
## License
This project is licensed under the MIT License. See the LICENSE file for details.