Accounts, Credits, and Payment

Official Downcity identity, credits, payment, and usage services.

@downcity/services separates four domains:

  • AccountsService owns login and user identity.
  • CreditsService owns Primary / Ephemeral Cards and accounting records.
  • PaymentService owns payment orders, Checkout, and webhooks.
  • UsageService aggregates user Credits consumption and AI technical usage.
const credits = new CreditsService();
const ai = new AIService({ credits });
const payment = new PaymentService({
  providers: [stripePaymentProvider()],
  resolve_topup: ({ topup_amount_minor }) => ({
    credits: topup_amount_minor * 10_000,
  }),
  on_paid: async (record) => {
    await credits.topup({
      card: { kind: "primary", user_id: record.user_id },
      credits: record.credits,
      source: "payment",
      ref: record.payment_id,
      idempotency_key: `payment:${record.payment_id}`,
    });
  },
});

federation.use(new AccountsService());
federation.use(credits);
federation.use(ai);
federation.use(payment);
federation.use(new UsageService({
  ai_usage_reader: ai,
  credits_usage_reader: credits,
}));

Start with Credits Cards for the credit model, then choose a payment provider.