UNPKG

payrex-js-sdk

Version:
211 lines (204 loc) 7.57 kB
"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getOwnPropSymbols = Object.getOwnPropertySymbols; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __propIsEnum = Object.prototype.propertyIsEnumerable; var __objRest = (source, exclude) => { var target = {}; for (var prop in source) if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0) target[prop] = source[prop]; if (source != null && __getOwnPropSymbols) for (var prop of __getOwnPropSymbols(source)) { if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop)) target[prop] = source[prop]; } return target; }; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var __async = (__this, __arguments, generator) => { return new Promise((resolve, reject) => { var fulfilled = (value) => { try { step(generator.next(value)); } catch (e) { reject(e); } }; var rejected = (value) => { try { step(generator.throw(value)); } catch (e) { reject(e); } }; var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected); step((generator = generator.apply(__this, __arguments)).next()); }); }; // src/billing-statement/service.ts var service_exports = {}; __export(service_exports, { default: () => BillingStatementService }); module.exports = __toCommonJS(service_exports); // src/utils.ts var import_qs = __toESM(require("qs"), 1); function formatRequestPayload(params) { return import_qs.default.stringify(params, { arrayFormat: "brackets" }); } // src/payment-intent/dto.ts var PaymentIntentDto = class { constructor(apiResponse) { this.id = apiResponse.id; this.resource = apiResponse.resource; this.amount = apiResponse.amount; this.amount_received = apiResponse.amount_received; this.amount_capturable = apiResponse.amount_capturable; this.client_secret = apiResponse.client_secret; this.currency = apiResponse.currency; this.description = apiResponse.description; this.livemode = apiResponse.livemode; this.metadata = apiResponse.metadata; this.next_action = apiResponse.next_action; this.payment_methods = apiResponse.payment_methods; this.payment_method_options = apiResponse.payment_method_options; this.statement_descriptor = apiResponse.statement_descriptor; this.status = apiResponse.status; this.created_at = apiResponse.created_at; this.updated_at = apiResponse.updated_at; } }; // src/statement-line-item/dto.ts var StatementLineItemDto = class { constructor(apiResponse) { this.id = apiResponse.id; this.resource = apiResponse.resource; this.description = apiResponse.description; this.unit_price = apiResponse.unit_price; this.quantity = apiResponse.quantity; this.billing_statement_id = apiResponse.billing_statement_id; this.livemode = apiResponse.livemode; this.created_at = apiResponse.created_at; this.updated_at = apiResponse.updated_at; } }; // src/billing-statement/dto.ts var BillingStatementDto = class { constructor(apiResponse) { this.id = apiResponse.id; this.resource = apiResponse.resource; this.amount = apiResponse.amount; this.currency = apiResponse.currency; this.customer_id = apiResponse.customer_id; this.description = apiResponse.description; this.status = apiResponse.status; this.line_items = apiResponse.line_items.map( (lineItem) => new StatementLineItemDto(lineItem) ); this.livemode = apiResponse.livemode; this.url = apiResponse.url; this.customer = apiResponse.customer; this.payment_intent = new PaymentIntentDto(apiResponse.payment_intent); this.metadata = apiResponse.metadata; this.payment_settings = apiResponse.payment_settings; this.billing_details_collection = apiResponse.billing_details_collection; this.due_at = apiResponse.due_at; this.created_at = apiResponse.created_at; this.updated_at = apiResponse.updated_at; } }; // src/billing-statement/service.ts var BillingStatementService = class { constructor(client) { this.client = client; this.basePath = "/billing_statements"; this.finalize = this.perform("finalize"); this.markUncollectible = this.perform("mark_uncollectible"); this.void = this.perform("void"); this.send = this.perform("send"); } create(params) { return __async(this, null, function* () { const response = yield this.client.send( "post", this.basePath, formatRequestPayload(params) ); return new BillingStatementDto(response.body); }); } update(params) { return __async(this, null, function* () { const _a = params, { id } = _a, payload = __objRest(_a, ["id"]); const response = yield this.client.send( "put", `${this.basePath}/${id}`, formatRequestPayload(payload) ); return new BillingStatementDto(response.body); }); } getById(id) { return __async(this, null, function* () { const response = yield this.client.send("get", `${this.basePath}/${id}`); return new BillingStatementDto(response.body); }); } getAll(searchParams) { return __async(this, null, function* () { let finalUrl = this.basePath; if (searchParams) { const _a = searchParams, { limit } = _a, compatibleParams = __objRest(_a, ["limit"]); const queryParams = new URLSearchParams(compatibleParams); if (typeof limit !== "undefined" && limit > 0) { queryParams.append("limit", limit.toString()); } finalUrl += `?${queryParams}`; } const response = yield this.client.send("get", finalUrl); return response.body.data.map( (billingStatement) => new BillingStatementDto(billingStatement) ); }); } delete(id) { return __async(this, null, function* () { const response = yield this.client.send("delete", `${this.basePath}/${id}`); return new BillingStatementDto(response.body); }); } perform(action) { return (id) => __async(this, null, function* () { const response = yield this.client.send( "post", `${this.basePath}/${id}/${action}` ); return new BillingStatementDto(response.body); }); } };