Initial import of zappier-edge from zapier monorepo

This commit is contained in:
George Lambert 2026-09-11 13:50:46 -04:00
commit f0d193b221
120 changed files with 19867 additions and 0 deletions

31
src/billing/reload.ts Normal file
View file

@ -0,0 +1,31 @@
import Stripe from 'stripe';
import { PaymentClient } from '../portal';
/**
* Stripe-backed reloads: creates a PaymentIntent and returns its client
* secret. The balance is credited only after the payment confirms (webhook
* step); until then creditedCents is 0 and the intent is pending.
*/
export function stripePaymentClient(secretKey: string): PaymentClient {
const stripe = new Stripe(secretKey);
return {
reload: async (customer, amountCents) => {
const intent = await stripe.paymentIntents.create({
amount: amountCents,
currency: 'usd',
automatic_payment_methods: { enabled: true },
metadata: { customerId: customer.id },
});
return {
mode: 'stripe',
creditedCents: 0,
clientSecret: intent.client_secret ?? undefined,
};
},
};
}
/** True when the key looks usable (not empty / not the setup placeholder). */
export function hasRealStripeKey(key: string | undefined): key is string {
return typeof key === 'string' && key.startsWith('sk_');
}