Skip to content

Commit

Permalink
fix: Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sashko9807 committed Dec 9, 2024
1 parent 4e5f115 commit d34dd63
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 25 deletions.
15 changes: 4 additions & 11 deletions apps/api/src/stripe/stripe.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
UnauthorizedException,
} from '@nestjs/common'
import { ApiBody, ApiTags } from '@nestjs/swagger'
import { Public, RoleMatchingMode, Roles } from 'nest-keycloak-connect'
import { Public, RoleMatchingMode, Roles } from 'nest-keycloak-connect'
import { CancelPaymentIntentDto } from './dto/cancel-payment-intent.dto'
import { CreatePaymentIntentDto } from './dto/create-payment-intent.dto'
import { UpdatePaymentIntentDto } from './dto/update-payment-intent.dto'
Expand Down Expand Up @@ -75,10 +75,7 @@ export class StripeController {

@Post('setup-intent/:id')
@Public()
updateSetupIntent(
@Param('id') id: string,
@Body() updateSetupIntentDto: UpdateSetupIntentDto,
) {
updateSetupIntent(@Param('id') id: string, @Body() updateSetupIntentDto: UpdateSetupIntentDto) {
return this.stripeService.updateSetupIntent(id, updateSetupIntentDto)
}

Expand All @@ -93,19 +90,15 @@ export class StripeController {
description: 'Create payment intent from setup intent',
})
@Public()
setupIntentToPaymentIntent(
@Param('id') id: string,
) {
setupIntentToPaymentIntent(@Param('id') id: string) {
return this.stripeService.setupIntentToPaymentIntent(id)
}

@Post('setup-intent/:id/subscription')
@ApiBody({
description: 'Create payment intent from setup intent',
})
setupIntentToSubscription(
@Param('id') id: string,
) {
setupIntentToSubscription(@Param('id') id: string) {
return this.stripeService.setupIntentToSubscription(id)
}

Expand Down
18 changes: 4 additions & 14 deletions apps/api/src/stripe/stripe.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ export class StripeService {
): Promise<Stripe.Response<Stripe.SetupIntent>> {
if (!inputDto.metadata.campaignId)
throw new BadRequestException('campaignId is missing from metadata')
await this.campaignService.validateCampaignId(
inputDto.metadata.campaignId as string,
)
await this.campaignService.validateCampaignId(inputDto.metadata.campaignId as string)
const idempotencyKey = crypto.randomUUID()
return await this.stripeClient.setupIntents.update(id, inputDto, { idempotencyKey })
}
Expand Down Expand Up @@ -85,9 +83,7 @@ export class StripeService {
{ idempotencyKey: `${idempotencyKey}--pm` },
)
}
async setupIntentToPaymentIntent(
setupIntentId: string,
): Promise<Stripe.PaymentIntent> {
async setupIntentToPaymentIntent(setupIntentId: string): Promise<Stripe.PaymentIntent> {
const setupIntent = await this.findSetupIntentById(setupIntentId)

if (setupIntent instanceof Error) throw new BadRequestException(setupIntent.message)
Expand Down Expand Up @@ -129,9 +125,7 @@ export class StripeService {
return await this.stripeClient.setupIntents.create({}, { idempotencyKey })
}

async setupIntentToSubscription(
setupIntentId: string,
): Promise<Stripe.PaymentIntent | Error> {
async setupIntentToSubscription(setupIntentId: string): Promise<Stripe.PaymentIntent | Error> {
const setupIntent = await this.findSetupIntentById(setupIntentId)
if (setupIntent instanceof Error) throw new BadRequestException(setupIntent.message)
const paymentMethod = setupIntent.payment_method as Stripe.PaymentMethod
Expand Down Expand Up @@ -196,11 +190,7 @@ export class StripeService {
} else return new Array<Stripe.Price>()
}

async createCustomer(
email: string,
name: string,
paymentMethod: Stripe.PaymentMethod,
) {
async createCustomer(email: string, name: string, paymentMethod: Stripe.PaymentMethod) {
const customerLookup = await this.stripeClient.customers.list({
email,
})
Expand Down

0 comments on commit d34dd63

Please sign in to comment.