@redwoodjs-stripe/api
Version:
API-side code for RedwoodJS-Stripe projects
69 lines (68 loc) • 2.37 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var stripeItems_exports = {};
__export(stripeItems_exports, {
stripeItem: () => stripeItem,
stripeItems: () => stripeItems
});
module.exports = __toCommonJS(stripeItems_exports);
var import_deepOmitNils = require("../../lib/deepOmitNils.js");
var import_stripe = require("../../lib/stripe.js");
const stripeItems = async ({
params = { productParams: {}, priceParams: {} }
}) => {
const { productParams = {}, priceParams = {} } = (0, import_deepOmitNils.deepOmitNils)(params) ?? {};
const products = await import_stripe.stripe.products.list(productParams);
const itemList = [];
for (const product of products.data) {
const prices = await import_stripe.stripe.prices.list({
product: product.id,
...priceParams
});
const price = prices.data[0];
if (typeof price !== "undefined") {
itemList.push({
id: price.id,
name: product.name,
description: product.description,
images: product.images,
price: price.unit_amount,
type: price.type
});
}
}
return itemList;
};
const stripeItem = async ({ id }) => {
const price = await import_stripe.stripe.prices.retrieve(id.toString());
const product = await import_stripe.stripe.products.retrieve(price.product.toString());
return {
id: price.id,
name: product.name,
description: product.description,
images: product.images,
price: price.unit_amount,
type: price.type
};
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
stripeItem,
stripeItems
});