Skip to content

Commit ed1655b

Browse files
authored
feat: void invoice (#18)
1 parent 4f9b01d commit ed1655b

File tree

5 files changed

+70
-3
lines changed

5 files changed

+70
-3
lines changed

libs/stripe/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@valor/nestjs-stripe",
3-
"version": "0.0.12",
3+
"version": "0.0.13",
44
"type": "commonjs",
55
"private": false,
66
"author": "opavlovskyi-valor-software",

libs/stripe/src/lib/controllers/invoice.controller.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@ import {
88
Param,
99
Get,
1010
Query,
11-
Logger} from '@nestjs/common';
11+
Logger,
12+
Patch} from '@nestjs/common';
1213
import { ApiBearerAuth, ApiTags, ApiResponse } from '@nestjs/swagger';
1314
import {
1415
BaseDataResponse,
1516
BaseSearchInvoiceDto,
1617
InvoiceDto,
18+
InvoiceFinalizeInvoiceDto,
1719
InvoicePreviewDto,
18-
InvoicePreviewResponse
20+
InvoicePreviewResponse,
21+
InvoiceVoidInvoiceDto
1922
} from '../dto';
2023
import { StripeAuthGuard } from '../stripe-auth.guard';
2124
import { StripeService } from '../stripe.service';
@@ -48,4 +51,22 @@ export class InvoiceController {
4851
return this.stripeService.upcomingInvoicePreview(dto);
4952
}
5053

54+
@ApiResponse({ type: BaseDataResponse<InvoiceDto> })
55+
@Patch(':invoiceId/void')
56+
voidInvoice(
57+
@Param('invoiceId') invoiceId: string,
58+
@Body() dto: InvoiceVoidInvoiceDto
59+
): Promise<BaseDataResponse<InvoiceDto>> {
60+
return this.stripeService.voidInvoice(invoiceId, dto);
61+
}
62+
63+
@ApiResponse({ type: BaseDataResponse<InvoiceDto> })
64+
@Patch(':invoiceId/finalize')
65+
finalizeInvoice(
66+
@Param('invoiceId') invoiceId: string,
67+
@Body() dto: InvoiceFinalizeInvoiceDto
68+
): Promise<BaseDataResponse<InvoiceDto>> {
69+
return this.stripeService.finalizeInvoice(invoiceId, dto);
70+
}
71+
5172
}

libs/stripe/src/lib/dto/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export * from './update-product.dto';
2121
export * from './update-customer.dto';
2222
export * from './save-webhook-endpoint.dto';
2323
export * from './save-test-clock.dto';
24+
export * from './update-invoice.dto';
2425

2526
export * from './stripe/customer.dto';
2627
export * from './stripe/subscription-item.dto';
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { ApiPropertyOptional } from '@nestjs/swagger';
2+
3+
export class InvoiceVoidInvoiceDto {
4+
@ApiPropertyOptional({ isArray: true, type: String })
5+
expand?: Array<string>;
6+
}
7+
8+
export class InvoiceFinalizeInvoiceDto {
9+
@ApiPropertyOptional()
10+
autoAdvance?:boolean;
11+
12+
@ApiPropertyOptional({ isArray: true, type: String })
13+
expand?: Array<string>;
14+
}

libs/stripe/src/lib/stripe.service.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ import {
5959
ListRequestParamsDto,
6060
TestClockDto,
6161
BaseSearchInvoiceDto,
62+
InvoiceVoidInvoiceDto,
63+
InvoiceFinalizeInvoiceDto,
6264
} from './dto';
6365
import { StripeConfig, STRIPE_CONFIG } from './stripe.config';
6466
import { StripeLogger } from './stripe.logger';
@@ -1018,6 +1020,35 @@ export class StripeService {
10181020
return this.handleError(exception, 'Search Invoices');
10191021
}
10201022
}
1023+
1024+
async voidInvoice(id: string, dto: InvoiceVoidInvoiceDto): Promise<BaseDataResponse<InvoiceDto>> {
1025+
try {
1026+
const invoice = await this.stripe.invoices.voidInvoice(id, {
1027+
expand: dto.expand
1028+
});
1029+
return {
1030+
success: true,
1031+
data: this.invoiceToDto(invoice)
1032+
};
1033+
} catch (exception) {
1034+
return this.handleError(exception, 'Void Invoice');
1035+
}
1036+
}
1037+
1038+
async finalizeInvoice(id: string, dto: InvoiceFinalizeInvoiceDto): Promise<BaseDataResponse<InvoiceDto>> {
1039+
try {
1040+
const invoice = await this.stripe.invoices.finalizeInvoice(id, {
1041+
auto_advance: dto.autoAdvance,
1042+
expand: dto.expand
1043+
});
1044+
return {
1045+
success: true,
1046+
data: this.invoiceToDto(invoice)
1047+
};
1048+
} catch (exception) {
1049+
return this.handleError(exception, 'Finalize Invoice');
1050+
}
1051+
}
10211052
//#endregion
10221053

10231054
//#region Quote

0 commit comments

Comments
 (0)