UNPKG

@mozaic-io/mozaic-sdk-node

Version:

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

62 lines (61 loc) 2.91 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.Payment = void 0; const BaseResource_1 = require("../BaseResource"); class Payment extends BaseResource_1.BaseResource { /** * @internal * Internal use only. Please use the Mozaic object to utilize this object. */ constructor(mozaic, payment) { var _a; super(); this._mozaic = mozaic; this.rawObject = payment; if (payment.to === undefined) throw new Error("payment.to is undefined"); // Required fields this.id = this.throwIfNullOrUndefined("payment.id", payment.id); this.email = this.throwIfNullOrUndefined("payment.email", payment.to.email); this.status = this.throwIfNullOrUndefined("payment.status", payment.status); this.amount = this.throwIfNullOrUndefined("payment.amount", payment.amount); // Optional fields if (((_a = payment.payment_source) === null || _a === void 0 ? void 0 : _a.payment_source) == "payment-cycle") { this.paymentCycleId = payment.payment_source.id; this.paymentCycleEntryId = payment.payment_source.payment_cycle_entry_id; } this.memo = payment.memo; } /** * Returns the payment cycle entry that this payment was sent from. If the payment was not sent from a payment cycle, then this will be null. * @returns {PaymentCycleEntry | null} */ getPaymentCycleEntry() { return __awaiter(this, void 0, void 0, function* () { if (this.paymentCycleEntryId == null) return null; return yield this._mozaic.PaymentCycles.getPaymentCycleEntry(this.paymentCycleEntryId); }); } /** * Returns the payment cycle that this payment was sent from. If the payment was not sent from a payment cycle, then this will be null. * @returns {PaymentCycle | null} */ getPaymentCycle() { return __awaiter(this, void 0, void 0, function* () { if (this.paymentCycleId == null) return null; return yield this._mozaic.PaymentCycles.getPaymentCycle(this.paymentCycleId); }); } } exports.Payment = Payment;