From 302c3729c406c14c170e33e29896843650f31fce Mon Sep 17 00:00:00 2001 From: nobswebdev Date: Sat, 5 Sep 2026 18:55:58 +0200 Subject: [PATCH] add multi-crypto payment buttons to cart --- backend/src/consts/paymentMethodLabel.ts | 6 ++++ .../storefrontCart/StorefrontCartModule.ts | 3 +- .../controllers/StorefrontCartController.ts | 14 +++++++- .../storefrontCart/types/CookieCartSummary.ts | 2 -- .../views/partials/cart-totals-panel.hbs | 33 ++++++++++++------- 5 files changed, 41 insertions(+), 17 deletions(-) create mode 100644 backend/src/consts/paymentMethodLabel.ts diff --git a/backend/src/consts/paymentMethodLabel.ts b/backend/src/consts/paymentMethodLabel.ts new file mode 100644 index 0000000..04f003f --- /dev/null +++ b/backend/src/consts/paymentMethodLabel.ts @@ -0,0 +1,6 @@ +import { PaymentMethod } from '../modules/payment/types/PaymentMethod'; + +export const paymentMethodLabel: Record = { + [PaymentMethod.Xmr]: 'XMR', + [PaymentMethod.Btc]: 'BTC' +}; diff --git a/backend/src/modules/storefrontCart/StorefrontCartModule.ts b/backend/src/modules/storefrontCart/StorefrontCartModule.ts index ee0fa12..8967229 100644 --- a/backend/src/modules/storefrontCart/StorefrontCartModule.ts +++ b/backend/src/modules/storefrontCart/StorefrontCartModule.ts @@ -3,14 +3,13 @@ import { DiscountCodesModule } from '../discountCode/DiscountCodesModule'; import { ProductsModule } from '../product/ProductsModule'; import { StorefrontCoreModule } from '../storefrontCore/StorefrontCoreModule'; import { StorefrontProductModule } from '../storefrontProduct/StorefrontProductModule'; -import { ExchangeRateModule } from '../exchangeRate/ExchangeRateModule'; import { StorefrontCartController } from './controllers/StorefrontCartController'; import { StorefrontCartDiscountResolver } from './services/StorefrontCartDiscountResolver'; import { StorefrontCartService } from './services/StorefrontCartService'; import { StorefrontDiscountService } from './services/StorefrontDiscountService'; @Module({ - imports: [StorefrontCoreModule, StorefrontProductModule, ProductsModule, DiscountCodesModule, ExchangeRateModule], + imports: [StorefrontCoreModule, StorefrontProductModule, ProductsModule, DiscountCodesModule], controllers: [StorefrontCartController], providers: [StorefrontCartService, StorefrontDiscountService, StorefrontCartDiscountResolver], exports: [StorefrontCartService] diff --git a/backend/src/modules/storefrontCart/controllers/StorefrontCartController.ts b/backend/src/modules/storefrontCart/controllers/StorefrontCartController.ts index d2046c8..7628aee 100644 --- a/backend/src/modules/storefrontCart/controllers/StorefrontCartController.ts +++ b/backend/src/modules/storefrontCart/controllers/StorefrontCartController.ts @@ -1,7 +1,10 @@ import { Body, Controller, Get, HttpStatus, Post, Req, Res, UseFilters } from '@nestjs/common'; +import { ConfigService } from '@nestjs/config'; import { Throttle } from '@nestjs/throttler'; import type { Request, Response } from 'express'; import { throttleProfiles } from '../../../config/throttleProfiles'; +import type { Config } from '../../../types/Config'; +import { paymentMethodLabel } from '../../../consts/paymentMethodLabel'; import { StorefrontExceptionFilter } from '../../storefrontCore/filters/StorefrontExceptionFilter'; import { StorefrontCartCookieService } from '../../storefrontCore/services/StorefrontCartCookieService'; import { StorefrontCheckoutSessionCookieService } from '../../storefrontCore/services/StorefrontCheckoutSessionCookieService'; @@ -33,7 +36,8 @@ export class StorefrontCartController { private readonly feedbackCookieService: StorefrontFeedbackCookieService, private readonly checkoutSessionCookieService: StorefrontCheckoutSessionCookieService, private readonly captchaService: StorefrontCaptchaService, - private readonly captchaCookieService: StorefrontCaptchaCookieService + private readonly captchaCookieService: StorefrontCaptchaCookieService, + private readonly configService: ConfigService ) {} @Get('shop/cart') @@ -62,9 +66,17 @@ export class StorefrontCartController { this.captchaCookieService.setAnswer(req, res, encryptedAnswer); + const { enabledPaymentMethods } = this.configService.get('shopSettings') as Config['shopSettings']; + + const paymentMethods = enabledPaymentMethods.map(paymentMethod => ({ + paymentMethod, + paymentMethodLabel: paymentMethodLabel[paymentMethod] + })); + return res.render('cart-summary', { ...summary, ...shopLocals, + paymentMethods, captchaSvg }); } diff --git a/backend/src/modules/storefrontCart/types/CookieCartSummary.ts b/backend/src/modules/storefrontCart/types/CookieCartSummary.ts index f162516..5106ff5 100644 --- a/backend/src/modules/storefrontCart/types/CookieCartSummary.ts +++ b/backend/src/modules/storefrontCart/types/CookieCartSummary.ts @@ -4,8 +4,6 @@ import type { CookieCartExtended } from './CookieCartExtended'; export type CookieCartSummary = { cartExtended: CookieCartExtended; cartSubtotal: number; - cartTotalXmr: string | null; - fiatPerXmr: number | null; hasManualLines: boolean; hasAutoLines: boolean; cartTotalIssueMessage: string | null; diff --git a/backend/src/modules/storefrontCore/views/partials/cart-totals-panel.hbs b/backend/src/modules/storefrontCore/views/partials/cart-totals-panel.hbs index 0a83e79..19ca943 100644 --- a/backend/src/modules/storefrontCore/views/partials/cart-totals-panel.hbs +++ b/backend/src/modules/storefrontCore/views/partials/cart-totals-panel.hbs @@ -66,18 +66,27 @@ {{/if}}
- {{#unless hasIssues}} -
-
{{{captchaSvg}}}
- - -
- {{else}} - - {{/unless}} + {{#unless hasIssues}} +
+
{{{captchaSvg}}}
+ + +
+ {{#each paymentMethods}} + + {{/each}} +
+
{{else}} {{/unless}}