@bunq-community/bunq-js-client
Version:
[ ](https://www.npmjs.com/package/@bunq-community/bunq-js-client) [ ](https://www.npmjs.com/p
72 lines (71 loc) • 2.71 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
class Payment {
/**
* @param {ApiAdapter} ApiAdapter
*/
constructor(ApiAdapter) {
this.ApiAdapter = ApiAdapter;
this.Session = ApiAdapter.Session;
}
/**
* @param {number} userId
* @param {number} monetaryAccountId
* @param {number} paymentId
* @param options
* @returns {Promise<void>}
*/
async get(userId, monetaryAccountId, paymentId, options = {}) {
const limiter = this.ApiAdapter.RequestLimitFactory.create("/payment");
const response = await limiter.run(async (axiosClient) => this.ApiAdapter.get(`/v1/user/${userId}/monetary-account/${monetaryAccountId}/payment/${paymentId}`, {}, {}, axiosClient));
return response.Response[0];
}
/**
* @param {number} userId
* @param {number} monetaryAccountId
* @param {PaginationOptions} options
* @returns {Promise<void>}
*/
async list(userId, monetaryAccountId, options = {
count: 200,
newer_id: false,
older_id: false
}) {
const params = {};
if (options.count !== undefined) {
params.count = options.count;
}
if (options.newer_id !== false && options.newer_id !== undefined) {
params.newer_id = options.newer_id;
}
if (options.older_id !== false && options.older_id !== undefined) {
params.older_id = options.older_id;
}
const limiter = this.ApiAdapter.RequestLimitFactory.create("/payment", "LIST");
const response = await limiter.run(async (axiosClient) => this.ApiAdapter.get(`/v1/user/${userId}/monetary-account/${monetaryAccountId}/payment`, {}, {
axiosOptions: {
params: params
}
}, axiosClient));
return response.Response;
}
/**
* @param {number} userId
* @param {number} monetaryAccountId
* @param {string} description
* @param {Amount} amount
* @param {CounterpartyAlias} counterpartyAlias
* @param options
* @returns {Promise<void>}
*/
async post(userId, monetaryAccountId, description, amount, counterpartyAlias, options = {}) {
const limiter = this.ApiAdapter.RequestLimitFactory.create("/payment", "POST");
const response = await limiter.run(async (axiosClient) => this.ApiAdapter.post(`/v1/user/${userId}/monetary-account/${monetaryAccountId}/payment`, {
counterparty_alias: counterpartyAlias,
description: description,
amount: amount
}, {}, {}, axiosClient));
return response.Response;
}
}
exports.default = Payment;