Skip to content

Commit

Permalink
add celebration UX to cash payments
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgabrielma committed Jan 30, 2025
1 parent bb69290 commit e525ecf
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ final class PointOfSaleOrderController: PointOfSaleOrderControllerProtocol {
init(orderService: POSOrderServiceProtocol,
receiptService: POSReceiptServiceProtocol,
stores: StoresManager = ServiceLocator.stores,
currencySettings: CurrencySettings = ServiceLocator.currencySettings) {
currencySettings: CurrencySettings = ServiceLocator.currencySettings,
celebration: PaymentCaptureCelebrationProtocol = PaymentCaptureCelebration()) {
self.orderService = orderService
self.receiptService = receiptService
self.stores = stores
self.storeCurrency = currencySettings.currencyCode
self.currencyFormatter = CurrencyFormatter(currencySettings: currencySettings)
self.celebration = celebration
}

var orderStatePublisher: AnyPublisher<PointOfSaleInternalOrderState, Never> {
Expand All @@ -44,6 +46,7 @@ final class PointOfSaleOrderController: PointOfSaleOrderControllerProtocol {
private let receiptService: POSReceiptServiceProtocol

private let currencyFormatter: CurrencyFormatter
private let celebration: PaymentCaptureCelebrationProtocol
private let storeCurrency: CurrencyCode
private let stores: StoresManager

Expand Down Expand Up @@ -101,6 +104,10 @@ final class PointOfSaleOrderController: PointOfSaleOrderControllerProtocol {
orderState = .idle
}

private func celebrate() {
celebration.celebrate()
}

@MainActor
func collectCashPayment() async throws {
guard let siteID = stores.sessionManager.defaultStoreID else {
Expand All @@ -123,7 +130,11 @@ final class PointOfSaleOrderController: PointOfSaleOrderControllerProtocol {
order: updatedOrder,
giftCard: nil,
fields: fieldsToUpdate,
onCompletion: { result in
onCompletion: { [weak self] result in
guard let self = self else { return }
if case .success = result {
self.celebrate()
}
continuation.resume(with: result)
})
stores.dispatch(action)
Expand Down

0 comments on commit e525ecf

Please sign in to comment.