UNPKG

declastruct-stripe-sdk

Version:

declarative control of stripe constructs, via declastruct

40 lines 1.85 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.castToDeclaredStripeDiscountCoupon = void 0; const domain_glossary_price_1 = require("domain-glossary-price"); const helpful_errors_1 = require("helpful-errors"); const type_fns_1 = require("type-fns"); const DeclaredStripeDiscountCoupon_1 = require("../../domain/objects/DeclaredStripeDiscountCoupon"); const castToDeclaredStripeDiscountCoupon = (input) => { const coupon = new DeclaredStripeDiscountCoupon_1.DeclaredStripeDiscountCoupon({ id: input.id, name: input.name, amountOff: input.amount_off && input.currency ? new domain_glossary_price_1.Price({ amount: input.amount_off, currency: domain_glossary_price_1.isOfCurrency.assure(input.currency.toUpperCase()), }) : null, percentOff: input.percent_off ?? null, duration: input.duration === 'repeating' ? { choice: input.duration, months: input.duration_in_months ?? helpful_errors_1.UnexpectedCodePathError.throw('expected duration.months quantity to be defined when .choice is repeating', { input }), } : input.duration, metadata: (() => { const obj = input.metadata ? (0, type_fns_1.omit)(input.metadata, ['exid']) : {}; if (Object.keys(obj).length === 0) return null; return obj; })(), }); if ((0, type_fns_1.hasMetadata)(coupon, ['id'])) return coupon; throw new helpful_errors_1.UnexpectedCodePathError('expected coupon to have metadata', { coupon, }); }; exports.castToDeclaredStripeDiscountCoupon = castToDeclaredStripeDiscountCoupon; //# sourceMappingURL=castToDeclaredStripeDiscountCoupon.js.map