import { initContract } from '@ts-rest/core'; import { z } from 'zod'; import { subscriptionSchema, createSubscriptionSchema, paymentSchema, verifyPaymentSchema, } from '../schemas/shopkeeper-billing.schemas'; import { errorResponseSchema } from '../schemas/common.schemas'; const c = initContract(); export const shopkeeperBillingContract = c.router({ getSubscription: { method: 'GET', path: '/shopkeeper/subscription', responses: { 200: subscriptionSchema.nullable(), 401: errorResponseSchema, }, summary: 'Get current subscription', }, createSubscription: { method: 'POST', path: '/shopkeeper/subscription', body: createSubscriptionSchema, responses: { 201: z.object({ subscription: subscriptionSchema, paymentUrl: z.string().optional() }), 400: errorResponseSchema, 401: errorResponseSchema, }, summary: 'Subscribe to a plan', }, cancelSubscription: { method: 'POST', path: '/shopkeeper/subscription/cancel', body: z.object({}), responses: { 200: subscriptionSchema, 401: errorResponseSchema, }, summary: 'Cancel subscription', }, verifyPayment: { method: 'POST', path: '/shopkeeper/subscription/verify-payment', body: verifyPaymentSchema, responses: { 200: z.object({ verified: z.boolean(), subscription: subscriptionSchema.optional() }), 400: errorResponseSchema, 401: errorResponseSchema, }, summary: 'Verify mobile money payment', }, listPayments: { method: 'GET', path: '/shopkeeper/subscription/payments', query: z.object({ limit: z.coerce.number().int().min(1).max(100).optional() }), responses: { 200: z.object({ payments: z.array(paymentSchema) }), 401: errorResponseSchema, }, summary: 'Payment history', }, paystackWebhook: { method: 'POST', path: '/shopkeeper/billing/webhook/paystack', body: z.record(z.unknown()), responses: { 200: z.object({ received: z.boolean() }) }, summary: 'Paystack payment webhook', }, });