@redwoodjs-stripe/api
Version:
API-side code for RedwoodJS-Stripe projects
67 lines (66 loc) • 2.23 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 checkouts_exports = {};
__export(checkouts_exports, {
checkout: () => checkout,
retrieveStripeCheckoutSession: () => retrieveStripeCheckoutSession
});
module.exports = __toCommonJS(checkouts_exports);
var import_deepOmitNils = require("../../lib/deepOmitNils.js");
var import_stripe = require("../../lib/stripe.js");
const checkout = async ({
customer,
mode,
cart,
successUrl = "http://localhost:8910/stripe-demo?success=true&sessionId={CHECKOUT_SESSION_ID}",
cancelUrl = "http://localhost:8910/stripe-demo?success=false",
allowPromotionCodes = false
}) => {
const line_items = cart.map((product) => ({
price: product.id,
quantity: product.quantity
}));
const payload = (0, import_deepOmitNils.deepOmitNils)({
success_url: successUrl,
cancel_url: cancelUrl,
// eslint-disable-next-line camelcase
line_items,
mode,
payment_method_types: ["card"],
allow_promotion_codes: allowPromotionCodes,
customer: customer?.id ?? null
});
const session = await import_stripe.stripe.checkout.sessions.create(payload);
const { id, url } = session;
return {
id,
url
};
};
const retrieveStripeCheckoutSession = async ({
id
}) => {
const session = await import_stripe.stripe.checkout.sessions.retrieve(id);
return session;
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
checkout,
retrieveStripeCheckoutSession
});