UNPKG

@mozaic-io/mozaic-sdk-node

Version:

The Mozaic Node SDK enables you to pay your creators easily via the Mozaic API.

102 lines (101 loc) 5.12 kB
"use strict"; /** * This is the main entry point for working with Payment Cycles. * @group ResourcesGroup * @category ResourcesCat * @document ../../../documents/resources/PaymentCycles.md */ 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.PaymentCycles = void 0; const api_1 = require("../../api"); const BaseResource_1 = require("../BaseResource"); const PaymentCycle_1 = require("./PaymentCycle"); const PaymentCycleList_1 = require("./PaymentCycleList"); const PaymentCycleEntry_1 = require("./PaymentCycleEntry"); class PaymentCycles extends BaseResource_1.BaseResource { /** * @internal * You should not call this constructor directly. Instead, use the Mozaic main * entry point to get access to the SDK classes. * @param configuration */ constructor(mozaic, configuration) { super(); this._mozaic = mozaic; this._paymentCycleApi = new api_1.PaymentCyclesApi(configuration); } /** * Get the underlying API for direct calls to the Mozaic API. */ get PaymentCyclesApi() { return this._paymentCycleApi; } /** * Creates a Payment Cycle * @param name The name of the payment cycle * @param feeDirection Determines who will pay the fees for payments issued from this payment cycle. * @param memo A free text field containing user supplied information about the payment cycle. * @param accountingFromDateUtc The starting data of the payment cycle in UTC. * @param accountingToDateUtc The ending date of the payment cycle in UTC. * @returns {PaymentCycle} */ createPaymentCycle(name, feeDirection, memo, accountingFromDateUtc, accountingToDateUtc) { return __awaiter(this, void 0, void 0, function* () { const deets = { name: name, fee_direction: feeDirection, memo: memo, accounting_from: accountingFromDateUtc.toISOString(), accounting_to: accountingToDateUtc.toISOString() }; var result = yield this.execute(() => this._paymentCycleApi.createPaymentCycle(deets)); return new PaymentCycle_1.PaymentCycle(this._mozaic, this._paymentCycleApi, result); }); } /** * Returns a list of payment cycles using limit for the maximum item count and page to retrieve more than one page. * @param limit An integer number between 1 and 100. * @param page An integer number of the page starting at 1. * @param paymentCycleStatus An optional filter to only return payment cycles with a specific status. If not provided, all payment cycles will be returned. * @returns A list of PaymentCycle objects. */ getPaymentCycles(limit, page, paymentCycleStatus, sortBy, sortByAscending) { return __awaiter(this, void 0, void 0, function* () { var _a; this.throwIfLimitOrPageAreInvalid(limit, page); const result = yield this.execute(() => this._paymentCycleApi.listPaymentCycles(undefined, paymentCycleStatus, undefined, undefined, sortBy, sortByAscending, limit, page, undefined, undefined)); const data = (_a = result.data) === null || _a === void 0 ? void 0 : _a.map((value, index) => new PaymentCycle_1.PaymentCycle(this._mozaic, this._paymentCycleApi, value)); return new PaymentCycleList_1.PaymentCycleList(result, data); }); } /** * Retrieves a specific payment cycle id. * @param paymentCycleId the payment cycle id to retrieve. Note: This is the long format payment cycle id, not the 9 character short version: XXXX-XXXX. * @returns */ getPaymentCycle(paymentCycleId) { return __awaiter(this, void 0, void 0, function* () { const result = yield this.execute(() => this._paymentCycleApi.getPaymentCycleById(paymentCycleId)); return new PaymentCycle_1.PaymentCycle(this._mozaic, this._paymentCycleApi, result); }); } /** * Retrieve a payment cycle entry by its ID. */ getPaymentCycleEntry(paymentCycleEntryId) { return __awaiter(this, void 0, void 0, function* () { const result = yield this.execute(() => this._paymentCycleApi.getPaymentCycleEntryById("any", paymentCycleEntryId)); return new PaymentCycleEntry_1.PaymentCycleEntry(result); }); } } exports.PaymentCycles = PaymentCycles;