Throw on unsupported payment methods in issueInvoice.
Prevent checkout sessions from being created without an invoice when the payment method switch has no matching case.
This commit is contained in:
@@ -260,10 +260,6 @@ export class OrderService {
|
|||||||
amountFiat: deliveryCost
|
amountFiat: deliveryCost
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!shippingInvoice) {
|
|
||||||
throw new InternalServerErrorException('Failed to issue shipping invoice');
|
|
||||||
}
|
|
||||||
|
|
||||||
await this.orderRepo.update(orderId, {
|
await this.orderRepo.update(orderId, {
|
||||||
shippingInvoice: { id: shippingInvoice.id },
|
shippingInvoice: { id: shippingInvoice.id },
|
||||||
quotedAt
|
quotedAt
|
||||||
|
|||||||
@@ -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 { ConfigService } from '@nestjs/config';
|
||||||
import type { Repository } from 'typeorm';
|
import type { Repository } from 'typeorm';
|
||||||
import type { ElectrumWalletRpcClient } from '../../bitcoinWallet/services/ElectrumWalletRpcClient';
|
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'));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -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 { InjectRepository } from '@nestjs/typeorm';
|
||||||
import { ConfigService } from '@nestjs/config';
|
import { ConfigService } from '@nestjs/config';
|
||||||
import { Repository } from 'typeorm';
|
import { Repository } from 'typeorm';
|
||||||
@@ -32,12 +32,14 @@ export class InvoiceService {
|
|||||||
private readonly exchangeRateService: ExchangeRateService
|
private readonly exchangeRateService: ExchangeRateService
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async issueInvoice(data: IssueInvoiceData): Promise<Invoice | undefined> {
|
async issueInvoice(data: IssueInvoiceData): Promise<Invoice> {
|
||||||
switch (data.paymentMethod) {
|
switch (data.paymentMethod) {
|
||||||
case PaymentMethod.Xmr:
|
case PaymentMethod.Xmr:
|
||||||
return this.issueXmrInvoice(data);
|
return this.issueXmrInvoice(data);
|
||||||
case PaymentMethod.Btc:
|
case PaymentMethod.Btc:
|
||||||
return this.issueBtcInvoice(data);
|
return this.issueBtcInvoice(data);
|
||||||
|
default:
|
||||||
|
throw new InternalServerErrorException(`Unsupported payment method: ${String(data.paymentMethod)}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user