Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 1x 12x 12x 12x 12x 1x 12x 12x 1x | import { Body, Controller, Get, Headers, Post, Req, UseGuards } from '@nestjs/common';
import { JwtAuthGuard } from '@app/common/guards/jwt-auth.guard';
import { BillingService } from '@app/modules/billing/billing.service';
import { IsOptional, IsString } from 'class-validator';
import { HttpCode, Param } from '@nestjs/common';
class SubscribeDto {
@IsString() planCode!: string;
@IsOptional() @IsString() period?: 'MONTHLY'|'ANNUAL';
@IsOptional() @IsString() paymentMethodId?: string;
}
@Controller('billing')
export class BillingController {
constructor(private readonly billing: BillingService) {}
@Get('plans')
listPlans() { return this.billing.listPlans(); }
@Post('subscribe')
@UseGuards(JwtAuthGuard)
subscribe(@Body() dto: SubscribeDto, @Req() req: any) {
return this.billing.subscribe(req.user.id, dto);
}
@Get('invoices')
@UseGuards(JwtAuthGuard)
myInvoices(@Req() req: any) { return this.billing.listInvoices(req.user.id); }
@Get('invoices/:id')
@UseGuards(JwtAuthGuard)
getInvoice(@Param('id') id: string, @Req() req: any) { return this.billing.getInvoice(Number(id), req.user.id); }
@Post('refunds/:merchantTransId')
@UseGuards(JwtAuthGuard)
@HttpCode(200)
refund(@Param('merchantTransId') tid: string, @Req() req: any) { return this.billing.requestRefund(tid, req.user.id); }
// Payment intents for CLICK/Stripe
@Post('payment-intents')
@UseGuards(JwtAuthGuard)
@HttpCode(201)
createIntent(
@Req() req: any,
@Body() body: { amountCents: number; currency?: string; purpose: string; subjectRef?: string },
) { return this.billing.createPaymentIntent(req.user.id, body); }
@Get('payments/:tid')
paymentStatus(@Param('tid') tid: string) { return this.billing.getPaymentByMerchantTransId(tid); }
@Post('webhooks/stripe')
stripeWebhook(@Req() req: any, @Headers('stripe-signature') sig: string) {
return this.billing.handleStripeWebhook(req, sig);
}
}
|