@zooly/srv-stripe-payment is a dedicated service package that handles all payment business logic and Stripe integration. It's separate from the general @zooly/app-srv package to ensure payment logic is reusable and testable independently of the Next.js API route framework.
NOTE - this package should never be imported in a client package. It's server-only and contains Stripe secret key operations.
@zooly/srv-stripe-paymentpackages/srv-stripe-paymentAll monetary amounts are in integer cents, not dollars. Every variable, parameter, column, and API field that represents money must use the Cent suffix to make the unit unambiguous (e.g. amountCent, platformFeeCent, totalBrandPriceCent). Never store or pass currency as floating-point dollars in the payment system.
The package provides a service layer that sits between API routes and the database access layer:
API Routes (Next.js) → @zooly/srv-stripe-payment → @zooly/app-db → Database
stripe.ts)getProductByPayForId.ts)payFor/payForId to a PaymentProductknownAmountCent (cart total calculated externally), sellerAccountId from campaign (defaults to "zooly_acc")createPaymentIntent.ts)createMerchPaymentIntent.ts)stripe_payment DB record with payFor: "MERCH", payForId: sessionId, buyerUserId: sessionIdmerch-pi-{paymentId} and metadata { stripePaymentId, merchSessionId }stripePaymentDbId) on the merch session for later retrieval at completion time{ stripePaymentId, stripeClientSecret, stripePublishableKey }completePayment.ts)refund.ts)payoutDaemon.ts: Daily cron daemon for automated payoutsdoPayout.ts: Per-account payout processing logicadvancePayout.ts: Advance payout mechanismpaymentLogger.ts)@zooly/app-db - Database access layer@zooly/types - Shared type definitions@zooly/util - Utility functions (Stripe fee calculation)stripe - Stripe SDKThis package is used by Next.js API routes in apps/zooly-app/app/api/payments/ and apps/zooly-app/app/api/merch/. API routes are thin layers that:
The merch payment flow uses:
createMerchPaymentIntent() — called by /api/merch/create-payment-intentcompletePaymentFromClient() — called by /api/merch/order/completegetProductByPayForId("MERCH", sessionId, knownAmountCent) — called internally by completePayment()handleStripeWebhook — automatically picks up merch payments from metadata.stripePaymentId@zooly/app-db, never raw table objectsOn This Page
OverviewPackage DetailsCurrency ConventionKey FeaturesArchitectureCore ModulesStripe Client & Operations (,[object Object],)Product Resolution & Pricing (,[object Object],)Payment Intent Creation (,[object Object],)Merch Payment Intent Creation (,[object Object],)Payment Completion (,[object Object],)Refund Processing (,[object Object],)Payout ManagementLogging (,[object Object],)DependenciesUsageMerch IntegrationKey Design PrinciplesRelated Documentation