Stripe integration flow

This commit is contained in:
metacryst
2026-03-05 00:29:34 -06:00
parent bdd260c2b5
commit 661bf86a1a
17 changed files with 303 additions and 117 deletions

View File

@@ -6,6 +6,56 @@ const stripe = new Stripe(process.env.STRIPE_SECRET);
export default class PaymentsHandler {
static async finishConnectSetup(req, res) {
const { code, networkId } = req.body;
console.log("onboarded", networkId)
const response = await stripe.oauth.token({
grant_type: "authorization_code",
code,
});
const { stripe_user_id, access_token } = response;
await db.networks.update(
networkId,
{
stripeAccountId: stripe_user_id,
stripeAccessToken: access_token, // rarely used, long-term access token for the platform
}
);
res.json({ success: true });
}
static async getProfile(networkId) {
let network = global.db.networks.get(networkId)
if (network) {
if (network.stripeAccountId) {
const account = await stripe.accounts.retrieve(network.stripeAccountId);
return {
chargesEnabled: account.charges_enabled,
payoutsEnabled: account.payouts_enabled,
detailsSubmitted: account.details_submitted,
email: account.email,
country: account.country,
}
} else {
return { connected: false }
}
} else {
throw new Error(`Network ${networkId} not found`)
}
}
static async getCustomers() {
const customers = await stripe.customers.list(
{ limit: 100 },
{ stripeAccount: 'acct_connected_account_id' }
);
console.log(customers)
}
static async newSubscription(req, res) {
try {
const session = await stripe.checkout.sessions.create({