-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
193 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* @docs https://docs.mollie.com/reference/v2/terminals-api/get-terminal | ||
*/ | ||
import createMollieClient, { Terminal } from '@mollie/api-client'; | ||
|
||
const mollieClient = createMollieClient({ apiKey: 'test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM' }); | ||
|
||
(async () => { | ||
try { | ||
const terminal: Terminal = await mollieClient.terminals.get('term_7MgL4wea46qkRcoTZjWEH'); | ||
|
||
console.log(terminal); | ||
} catch (error) { | ||
console.warn(error); | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* @docs https://docs.mollie.com/reference/v2/terminals-api/list-terminals | ||
*/ | ||
import createMollieClient, { List, Terminal } from '@mollie/api-client'; | ||
|
||
const mollieClient = createMollieClient({ apiKey: 'test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM' }); | ||
|
||
(async () => { | ||
try { | ||
const terminals: List<Terminal> = await mollieClient.terminals.page(); | ||
|
||
console.log(terminals); | ||
} catch (error) { | ||
console.warn(terminals); | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import type TransformingNetworkClient from '../../communication/TransformingNetworkClient'; | ||
import renege from '../../plumbing/renege'; | ||
import type Callback from '../../types/Callback'; | ||
import Binder from '../Binder'; | ||
import { type PageParameters, IterateParameters } from './parameters'; | ||
import {Page} from "../../types"; | ||
import Terminal, {TerminalData} from "../../data/terminals/Terminal"; | ||
|
||
const pathSegment = 'terminals'; | ||
|
||
export default class TerminalsBinder extends Binder<TerminalData, Terminal> { | ||
constructor(protected readonly networkClient: TransformingNetworkClient) { | ||
super(); | ||
} | ||
|
||
/** | ||
* Retrieve a single terminal object by its terminal ID. This terminal object symbolizes the physical device that you have received from us. | ||
* | ||
* For more information on accepting point-of-sale payments, please refer to the [point-of-sale guide](https://docs.mollie.com/point-of-sale/overview). | ||
* | ||
* @see https://docs.mollie.com/reference/v2/terminals-api/get-terminal | ||
*/ | ||
public get(id: string): Promise<Terminal>; | ||
public get(id: string, callback: Callback<Terminal>): void; | ||
public get(id: string) { | ||
if (renege(this, this.get, ...arguments)) return; | ||
return this.networkClient.get(`${pathSegment}/${id}`); | ||
} | ||
|
||
/** | ||
* Retrieve a list of all of your terminals. | ||
* | ||
* The results are paginated. See pagination for more information. | ||
* | ||
* @see https://docs.mollie.com/reference/v2/terminals-api/list-terminals | ||
*/ | ||
public page(parameters?: PageParameters): Promise<Page<Terminal>>; | ||
public page(parameters: PageParameters, callback: Callback<Page<Terminal>>): void; | ||
public page(parameters: PageParameters = {}) { | ||
if (renege(this, this.page, ...arguments)) return; | ||
return this.networkClient.page<TerminalData, Terminal>(pathSegment, 'terminals', parameters).then(result => this.injectPaginationHelpers(result, this.page, parameters)); | ||
} | ||
|
||
/** | ||
* Retrieve a list of all of your terminals. | ||
* | ||
* The results are paginated. See pagination for more information. | ||
* | ||
* @see https://docs.mollie.com/reference/v2/terminals-api/list-terminals | ||
*/ | ||
public iterate(parameters?: IterateParameters) { | ||
const { valuesPerMinute, ...query } = parameters ?? {}; | ||
return this.networkClient.iterate<TerminalData, Terminal>(pathSegment, 'terminals', query, valuesPerMinute); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import {PaginationParameters, ThrottlingParameter} from "../../types/parameters"; | ||
|
||
export type PageParameters = PaginationParameters & { | ||
profileId?: string; | ||
testmode?: boolean; | ||
}; | ||
|
||
export type IterateParameters = Omit<PageParameters, 'limit'> & ThrottlingParameter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import type TransformingNetworkClient from '../../communication/TransformingNetworkClient'; | ||
import type Seal from '../../types/Seal'; | ||
import Helper from "../Helper"; | ||
import type Model from '../Model'; | ||
import {Links} from "../global"; | ||
|
||
export interface TerminalData extends Model<'terminal'> { | ||
/** | ||
* The identifier used for referring to the profile the terminal was created on. For example, pfl_QkEhN94Ba. | ||
*/ | ||
profileId: string | ||
/** | ||
* The terminal's status. Refer to the documentation regarding statuses for more info about which statuses occur at what point. | ||
* | ||
* @see https://docs.mollie.com/reference/v2/terminals-api/get-terminal#response | ||
*/ | ||
status: TerminalStatus | ||
/** | ||
* The brand of the terminal. For example, ‘PAX’. | ||
*/ | ||
brand: string | ||
/** | ||
* The model of the terminal. For example for a PAX A920, this field’s value will be ‘A920’. | ||
*/ | ||
model: string | ||
/** | ||
* The serial number of the terminal. The serial number is provided at terminal creation time. | ||
*/ | ||
serialNumber: string | ||
/** | ||
* The currency which is set for the terminal, in [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217) format. Please take into consideration that currently our terminals are bound to a specific currency, chosen during setup. | ||
*/ | ||
currency?: string | ||
/** | ||
* A short description of the terminal. The description can be used as an identifier for the terminal. Currently, the description is set when the terminal is initially configured. It will be visible in the dashboard as well as on the device itself. | ||
*/ | ||
description: string | ||
/** | ||
* The date and time the terminal was created, in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format. | ||
*/ | ||
createdAt: string | ||
/** | ||
* The date and time the terminal was last updated, in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format. | ||
*/ | ||
updatedAt: string | ||
_links: Links | ||
} | ||
|
||
export enum TerminalStatus { | ||
pending = 'pending', | ||
active = 'active', | ||
inactive = 'inactive' | ||
} | ||
|
||
type Terminal = Seal<TerminalData, Helper<TerminalData, Terminal>>; | ||
|
||
export default Terminal; | ||
|
||
export function transform(networkClient: TransformingNetworkClient, input: TerminalData): Terminal { | ||
return Object.assign(Object.create(new Helper(networkClient, input._links)), input); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import axios from 'axios'; | ||
import httpAdapter from 'axios/lib/adapters/http'; | ||
import dotenv from 'dotenv'; | ||
import createMollieClient from '../..'; | ||
|
||
/** | ||
* Overwrite the default XMLHttpRequestAdapter | ||
*/ | ||
axios.defaults.adapter = httpAdapter; | ||
|
||
/** | ||
* Load the API_KEY environment variable | ||
*/ | ||
dotenv.config(); | ||
|
||
const mollieClient = createMollieClient({ apiKey: process.env.API_KEY }); | ||
|
||
describe('terminals', () => { | ||
it('should integrate', async () => { | ||
const terminals = await mollieClient.terminals.page(); | ||
|
||
expect(terminals).toBeDefined(); | ||
|
||
const terminal = await mollieClient.terminals.get(terminals[0].id); | ||
expect(terminal).toBeDefined(); | ||
}); | ||
}); |