diff --git a/backend/src/modules/order/services/OrderService.ts b/backend/src/modules/order/services/OrderService.ts index 882930f..0edb1bb 100644 --- a/backend/src/modules/order/services/OrderService.ts +++ b/backend/src/modules/order/services/OrderService.ts @@ -260,10 +260,6 @@ export class OrderService { amountFiat: deliveryCost }); - if (!shippingInvoice) { - throw new InternalServerErrorException('Failed to issue shipping invoice'); - } - await this.orderRepo.update(orderId, { shippingInvoice: { id: shippingInvoice.id }, quotedAt diff --git a/backend/src/modules/payment/services/InvoiceService.spec.ts b/backend/src/modules/payment/services/InvoiceService.spec.ts index 3b959ab..e187ddd 100644 --- a/backend/src/modules/payment/services/InvoiceService.spec.ts +++ b/backend/src/modules/payment/services/InvoiceService.spec.ts @@ -1,4 +1,4 @@ -import { Logger, ServiceUnavailableException } from '@nestjs/common'; +import { Logger, InternalServerErrorException, ServiceUnavailableException } from '@nestjs/common'; import type { ConfigService } from '@nestjs/config'; import type { Repository } from 'typeorm'; import type { ElectrumWalletRpcClient } from '../../bitcoinWallet/services/ElectrumWalletRpcClient'; @@ -301,4 +301,15 @@ describe('InvoiceService', () => { ) ); }); + + it('throws for unsupported payment methods', async () => { + await expect( + service.issueInvoice({ + paymentMethod: 'eth' as PaymentMethod, + reason: InvoiceReason.Checkout, + contextId: 'session-uuid', + amountFiat: 15 + }) + ).rejects.toThrow(new InternalServerErrorException('Unsupported payment method: eth')); + }); }); diff --git a/backend/src/modules/payment/services/InvoiceService.ts b/backend/src/modules/payment/services/InvoiceService.ts index 1c5fcd0..5a4f0fb 100644 --- a/backend/src/modules/payment/services/InvoiceService.ts +++ b/backend/src/modules/payment/services/InvoiceService.ts @@ -1,4 +1,4 @@ -import { Injectable, Logger, ServiceUnavailableException } from '@nestjs/common'; +import { Injectable, InternalServerErrorException, Logger, ServiceUnavailableException } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { ConfigService } from '@nestjs/config'; import { Repository } from 'typeorm'; @@ -32,12 +32,14 @@ export class InvoiceService { private readonly exchangeRateService: ExchangeRateService ) {} - async issueInvoice(data: IssueInvoiceData): Promise { + async issueInvoice(data: IssueInvoiceData): Promise { switch (data.paymentMethod) { case PaymentMethod.Xmr: return this.issueXmrInvoice(data); case PaymentMethod.Btc: return this.issueBtcInvoice(data); + default: + throw new InternalServerErrorException(`Unsupported payment method: ${String(data.paymentMethod)}`); } }