This repository has been archived by the owner on Apr 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a7aa4e1
commit f39edda
Showing
4 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { | ||
Controller, | ||
Delete, | ||
Get, | ||
Param, | ||
ParseIntPipe, | ||
Post, | ||
Query, | ||
} from '@nestjs/common'; | ||
import Stripe from 'stripe'; | ||
import { CursorPipe } from '../../pipes/cursor.pipe'; | ||
import { OptionalIntPipe } from '../../pipes/optional-int.pipe'; | ||
import { Scopes } from '../auth/scope.decorator'; | ||
import { StripeService } from './stripe.service'; | ||
|
||
@Controller('groups/:groupId/sources') | ||
export class StripeBillingController { | ||
constructor(private stripeService: StripeService) {} | ||
|
||
@Post() | ||
@Scopes('group-{groupId}:write-source') | ||
async create( | ||
@Param('groupId', ParseIntPipe) groupId: number, | ||
): Promise<Stripe.Checkout.Session> { | ||
return this.stripeService.createSession(groupId, 'setup'); | ||
} | ||
|
||
@Get() | ||
@Scopes('group-{groupId}:read-source') | ||
async getAll( | ||
@Param('groupId', ParseIntPipe) groupId: number, | ||
@Query('take', OptionalIntPipe) take?: number, | ||
@Query('cursor', CursorPipe) cursor?: { id: string }, | ||
): Promise<Stripe.CustomerSource[]> { | ||
return this.stripeService.getSources(groupId, { take, cursor }); | ||
} | ||
|
||
@Get(':id') | ||
@Scopes('group-{groupId}:read-source-{id}') | ||
async get( | ||
@Param('groupId', ParseIntPipe) groupId: number, | ||
@Param('id') id: string, | ||
): Promise<Stripe.Source> { | ||
return this.stripeService.getSource(groupId, id); | ||
} | ||
|
||
@Delete(':id') | ||
@Scopes('group-{groupId}:delete-source-{id}') | ||
async remove( | ||
@Param('groupId', ParseIntPipe) groupId: number, | ||
@Param('id') id: string, | ||
): Promise<void> { | ||
return this.stripeService.deleteSource(groupId, id); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters