diff --git a/libs/payments/ui/src/lib/actions/updateCart.ts b/libs/payments/ui/src/lib/actions/updateCart.ts new file mode 100644 index 0000000000..e0dcc424c1 --- /dev/null +++ b/libs/payments/ui/src/lib/actions/updateCart.ts @@ -0,0 +1,18 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +'use server'; + +import { UpdateCart } from '@fxa/payments/cart'; +import { app } from '../nestapp/app'; + +export const updateCartAction = async ( + cartId: string, + version: number, + cartDetails: UpdateCart +) => { + const actionsService = await app.getActionsService(); + + await actionsService.updateCart(cartId, version, cartDetails); +}; diff --git a/libs/payments/ui/src/lib/nestapp/nextjs-actions.service.ts b/libs/payments/ui/src/lib/nestapp/nextjs-actions.service.ts index 567c97bfed..71aa0e487f 100644 --- a/libs/payments/ui/src/lib/nestapp/nextjs-actions.service.ts +++ b/libs/payments/ui/src/lib/nestapp/nextjs-actions.service.ts @@ -2,7 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import { CartService } from '@fxa/payments/cart'; +import { CartService, UpdateCart } from '@fxa/payments/cart'; import { Injectable } from '@nestjs/common'; /** @@ -15,8 +15,21 @@ export class NextJSActionsService { constructor(private cartService: CartService) {} async getCart(cartId: string) { + // TODO: validate incoming arguments with class-validator + const cart = await this.cartService.getCart(cartId); return cart; } + + async updateCart(cartId: string, version: number, cartDetails: UpdateCart) { + // TODO: validate incoming arguments with class-validator + + await this.cartService.updateCart(cartId, version, { + uid: cartDetails.uid, + taxAddress: cartDetails.taxAddress, + couponCode: cartDetails.couponCode, + email: cartDetails.email, + }); + } }