@aglyn/plugins-commerce 1.0.0-beta.230 → 1.0.0-beta.231
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +13 -13
- package/src/index.d.ts +0 -1
- package/src/index.js +0 -1
- package/src/index.js.map +1 -1
- package/src/lib/barcode/barcode-decode.d.ts +71 -0
- package/src/lib/barcode/barcode-decode.js +498 -0
- package/src/lib/barcode/barcode-decode.js.map +1 -0
- package/src/lib/barcode/barcode-encode.d.ts +44 -0
- package/src/lib/barcode/barcode-encode.js +138 -0
- package/src/lib/barcode/barcode-encode.js.map +1 -0
- package/src/lib/barcode/barcode-scanner.component.d.ts +23 -0
- package/src/lib/barcode/barcode-scanner.component.js +260 -0
- package/src/lib/barcode/barcode-scanner.component.js.map +1 -0
- package/src/lib/barcode/scan-button.component.d.ts +10 -0
- package/src/lib/barcode/scan-button.component.js +62 -0
- package/src/lib/barcode/scan-button.component.js.map +1 -0
- package/src/lib/barcode/scanner-wedge.d.ts +35 -0
- package/src/lib/barcode/scanner-wedge.js +108 -0
- package/src/lib/barcode/scanner-wedge.js.map +1 -0
- package/src/lib/components/account.js +10 -1
- package/src/lib/components/account.js.map +1 -1
- package/src/lib/components/cart-extras.d.ts +45 -0
- package/src/lib/components/cart-extras.js +127 -0
- package/src/lib/components/cart-extras.js.map +1 -0
- package/src/lib/components/cart.js +82 -15
- package/src/lib/components/cart.js.map +1 -1
- package/src/lib/components/checkout-return-notice.d.ts +26 -0
- package/src/lib/components/checkout-return-notice.js +48 -0
- package/src/lib/components/checkout-return-notice.js.map +1 -0
- package/src/lib/components/commerce-console-page.js +124 -0
- package/src/lib/components/commerce-console-page.js.map +1 -1
- package/src/lib/components/commerce-console-sections.d.ts +1 -1
- package/src/lib/components/commerce-console-sections.js +4 -0
- package/src/lib/components/commerce-console-sections.js.map +1 -1
- package/src/lib/components/console/bulk-fulfill.d.ts +44 -0
- package/src/lib/components/console/bulk-fulfill.js +84 -0
- package/src/lib/components/console/bulk-fulfill.js.map +1 -0
- package/src/lib/components/console/customer-notifications-card.component.d.ts +19 -0
- package/src/lib/components/console/customer-notifications-card.component.js +149 -0
- package/src/lib/components/console/customer-notifications-card.component.js.map +1 -0
- package/src/lib/components/console/host-orders-card.component.js +84 -5
- package/src/lib/components/console/host-orders-card.component.js.map +1 -1
- package/src/lib/components/console/locations-card.component.js +164 -57
- package/src/lib/components/console/locations-card.component.js.map +1 -1
- package/src/lib/components/console/order-detail-dialog.component.js +209 -61
- package/src/lib/components/console/order-detail-dialog.component.js.map +1 -1
- package/src/lib/components/console/order-fulfillment-panel.component.d.ts +48 -0
- package/src/lib/components/console/order-fulfillment-panel.component.js +542 -0
- package/src/lib/components/console/order-fulfillment-panel.component.js.map +1 -0
- package/src/lib/components/console/order-invoice.component.d.ts +33 -0
- package/src/lib/components/console/order-invoice.component.js +81 -0
- package/src/lib/components/console/order-invoice.component.js.map +1 -0
- package/src/lib/components/console/order-receipt-resend.component.d.ts +21 -0
- package/src/lib/components/console/order-receipt-resend.component.js +203 -0
- package/src/lib/components/console/order-receipt-resend.component.js.map +1 -0
- package/src/lib/components/console/order-returns.component.d.ts +36 -0
- package/src/lib/components/console/order-returns.component.js +142 -0
- package/src/lib/components/console/order-returns.component.js.map +1 -0
- package/src/lib/components/console/order-shipping-actions.component.d.ts +54 -0
- package/src/lib/components/console/order-shipping-actions.component.js +149 -0
- package/src/lib/components/console/order-shipping-actions.component.js.map +1 -0
- package/src/lib/components/console/order-webhooks-card.component.d.ts +50 -0
- package/src/lib/components/console/order-webhooks-card.component.js +623 -0
- package/src/lib/components/console/order-webhooks-card.component.js.map +1 -0
- package/src/lib/components/console/order-zones.d.ts +155 -0
- package/src/lib/components/console/order-zones.js +40 -0
- package/src/lib/components/console/order-zones.js.map +1 -0
- package/src/lib/components/console/payment-methods-card.component.d.ts +67 -0
- package/src/lib/components/console/payment-methods-card.component.js +395 -0
- package/src/lib/components/console/payment-methods-card.component.js.map +1 -0
- package/src/lib/components/console/pos/pos-api.d.ts +124 -0
- package/src/lib/components/console/pos/pos-api.js +101 -0
- package/src/lib/components/console/pos/pos-api.js.map +1 -0
- package/src/lib/components/console/pos/pos-cart-panel.component.d.ts +36 -0
- package/src/lib/components/console/pos/pos-cart-panel.component.js +160 -0
- package/src/lib/components/console/pos/pos-cart-panel.component.js.map +1 -0
- package/src/lib/components/console/pos/pos-item-dialog.component.d.ts +39 -0
- package/src/lib/components/console/pos/pos-item-dialog.component.js +352 -0
- package/src/lib/components/console/pos/pos-item-dialog.component.js.map +1 -0
- package/src/lib/components/console/pos/pos-product-grid.component.d.ts +47 -0
- package/src/lib/components/console/pos/pos-product-grid.component.js +272 -0
- package/src/lib/components/console/pos/pos-product-grid.component.js.map +1 -0
- package/src/lib/components/console/pos/pos-receipt-panel.component.d.ts +27 -0
- package/src/lib/components/console/pos/pos-receipt-panel.component.js +282 -0
- package/src/lib/components/console/pos/pos-receipt-panel.component.js.map +1 -0
- package/src/lib/components/console/pos/pos-tender-dialogs.component.d.ts +53 -0
- package/src/lib/components/console/pos/pos-tender-dialogs.component.js +445 -0
- package/src/lib/components/console/pos/pos-tender-dialogs.component.js.map +1 -0
- package/src/lib/components/console/pos/pos-tender-panel.component.d.ts +31 -0
- package/src/lib/components/console/pos/pos-tender-panel.component.js +640 -0
- package/src/lib/components/console/pos/pos-tender-panel.component.js.map +1 -0
- package/src/lib/components/console/pos/use-pos-display.d.ts +43 -0
- package/src/lib/components/console/pos/use-pos-display.js +161 -0
- package/src/lib/components/console/pos/use-pos-display.js.map +1 -0
- package/src/lib/components/console/pos-devices-card.component.d.ts +14 -0
- package/src/lib/components/console/pos-devices-card.component.js +546 -0
- package/src/lib/components/console/pos-devices-card.component.js.map +1 -0
- package/src/lib/components/console/pos-display/brand-screen.d.ts +33 -0
- package/src/lib/components/console/pos-display/brand-screen.js +85 -0
- package/src/lib/components/console/pos-display/brand-screen.js.map +1 -0
- package/src/lib/components/console/pos-display/cart-screen.d.ts +29 -0
- package/src/lib/components/console/pos-display/cart-screen.js +166 -0
- package/src/lib/components/console/pos-display/cart-screen.js.map +1 -0
- package/src/lib/components/console/pos-display/pairing-screen.d.ts +24 -0
- package/src/lib/components/console/pos-display/pairing-screen.js +127 -0
- package/src/lib/components/console/pos-display/pairing-screen.js.map +1 -0
- package/src/lib/components/console/pos-display/pos-display-api.d.ts +90 -0
- package/src/lib/components/console/pos-display/pos-display-api.js +140 -0
- package/src/lib/components/console/pos-display/pos-display-api.js.map +1 -0
- package/src/lib/components/console/pos-display/receipt-screen.d.ts +35 -0
- package/src/lib/components/console/pos-display/receipt-screen.js +200 -0
- package/src/lib/components/console/pos-display/receipt-screen.js.map +1 -0
- package/src/lib/components/console/pos-display/tip-screen.d.ts +36 -0
- package/src/lib/components/console/pos-display/tip-screen.js +211 -0
- package/src/lib/components/console/pos-display/tip-screen.js.map +1 -0
- package/src/lib/components/console/pos-display-page.component.d.ts +16 -0
- package/src/lib/components/console/pos-display-page.component.js +407 -0
- package/src/lib/components/console/pos-display-page.component.js.map +1 -0
- package/src/lib/components/console/pos-ops/pos-customer-lookup.component.d.ts +40 -0
- package/src/lib/components/console/pos-ops/pos-customer-lookup.component.js +289 -0
- package/src/lib/components/console/pos-ops/pos-customer-lookup.component.js.map +1 -0
- package/src/lib/components/console/pos-ops/pos-last-receipt.component.d.ts +34 -0
- package/src/lib/components/console/pos-ops/pos-last-receipt.component.js +61 -0
- package/src/lib/components/console/pos-ops/pos-last-receipt.component.js.map +1 -0
- package/src/lib/components/console/pos-ops/pos-operations-bar.component.d.ts +38 -0
- package/src/lib/components/console/pos-ops/pos-operations-bar.component.js +129 -0
- package/src/lib/components/console/pos-ops/pos-operations-bar.component.js.map +1 -0
- package/src/lib/components/console/pos-ops/pos-ops-api.d.ts +37 -0
- package/src/lib/components/console/pos-ops/pos-ops-api.js +60 -0
- package/src/lib/components/console/pos-ops/pos-ops-api.js.map +1 -0
- package/src/lib/components/console/pos-ops/pos-pin-pad.component.d.ts +48 -0
- package/src/lib/components/console/pos-ops/pos-pin-pad.component.js +220 -0
- package/src/lib/components/console/pos-ops/pos-pin-pad.component.js.map +1 -0
- package/src/lib/components/console/pos-ops/pos-receipt-actions.component.d.ts +63 -0
- package/src/lib/components/console/pos-ops/pos-receipt-actions.component.js +186 -0
- package/src/lib/components/console/pos-ops/pos-receipt-actions.component.js.map +1 -0
- package/src/lib/components/console/pos-ops/pos-receipt.d.ts +39 -0
- package/src/lib/components/console/pos-ops/pos-receipt.js +182 -0
- package/src/lib/components/console/pos-ops/pos-receipt.js.map +1 -0
- package/src/lib/components/console/pos-ops/pos-return-dialog.component.d.ts +40 -0
- package/src/lib/components/console/pos-ops/pos-return-dialog.component.js +465 -0
- package/src/lib/components/console/pos-ops/pos-return-dialog.component.js.map +1 -0
- package/src/lib/components/console/pos-ops/pos-shift-history-card.component.d.ts +29 -0
- package/src/lib/components/console/pos-ops/pos-shift-history-card.component.js +253 -0
- package/src/lib/components/console/pos-ops/pos-shift-history-card.component.js.map +1 -0
- package/src/lib/components/console/pos-ops/pos-shift-panel.component.d.ts +34 -0
- package/src/lib/components/console/pos-ops/pos-shift-panel.component.js +494 -0
- package/src/lib/components/console/pos-ops/pos-shift-panel.component.js.map +1 -0
- package/src/lib/components/console/pos-ops/pos-shift-report.component.d.ts +37 -0
- package/src/lib/components/console/pos-ops/pos-shift-report.component.js +102 -0
- package/src/lib/components/console/pos-ops/pos-shift-report.component.js.map +1 -0
- package/src/lib/components/console/pos-ops/pos-staff-pins-card.component.d.ts +30 -0
- package/src/lib/components/console/pos-ops/pos-staff-pins-card.component.js +277 -0
- package/src/lib/components/console/pos-ops/pos-staff-pins-card.component.js.map +1 -0
- package/src/lib/components/console/pos-ops/register-ops.d.ts +28 -0
- package/src/lib/components/console/pos-ops/register-ops.js +28 -0
- package/src/lib/components/console/pos-ops/register-ops.js.map +1 -0
- package/src/lib/components/console/pos-ops/use-pos-cashier.d.ts +46 -0
- package/src/lib/components/console/pos-ops/use-pos-cashier.js +128 -0
- package/src/lib/components/console/pos-ops/use-pos-cashier.js.map +1 -0
- package/src/lib/components/console/pos-ops/use-pos-sale-receipt.d.ts +36 -0
- package/src/lib/components/console/pos-ops/use-pos-sale-receipt.js +64 -0
- package/src/lib/components/console/pos-ops/use-pos-sale-receipt.js.map +1 -0
- package/src/lib/components/console/pos-page.component.d.ts +13 -5
- package/src/lib/components/console/pos-page.component.js +729 -657
- package/src/lib/components/console/pos-page.component.js.map +1 -1
- package/src/lib/components/console/product-editor-dialog.component.js +51 -7
- package/src/lib/components/console/product-editor-dialog.component.js.map +1 -1
- package/src/lib/components/console/product-labels-dialog.component.d.ts +13 -0
- package/src/lib/components/console/product-labels-dialog.component.js +197 -0
- package/src/lib/components/console/product-labels-dialog.component.js.map +1 -0
- package/src/lib/components/console/product-register-fields.component.d.ts +19 -0
- package/src/lib/components/console/product-register-fields.component.js +241 -0
- package/src/lib/components/console/product-register-fields.component.js.map +1 -0
- package/src/lib/components/console/product-zones.d.ts +44 -0
- package/src/lib/components/console/product-zones.js.map +1 -1
- package/src/lib/components/console/products-hub-card.component.js +12 -0
- package/src/lib/components/console/products-hub-card.component.js.map +1 -1
- package/src/lib/components/console/register-hardware-card.component.d.ts +33 -0
- package/src/lib/components/console/register-hardware-card.component.js +826 -0
- package/src/lib/components/console/register-hardware-card.component.js.map +1 -0
- package/src/lib/components/console/registers-card.component.js +24 -5
- package/src/lib/components/console/registers-card.component.js.map +1 -1
- package/src/lib/components/console/return-actions.d.ts +38 -0
- package/src/lib/components/console/return-actions.js +76 -0
- package/src/lib/components/console/return-actions.js.map +1 -0
- package/src/lib/components/console/return-detail-dialog.component.d.ts +34 -0
- package/src/lib/components/console/return-detail-dialog.component.js +718 -0
- package/src/lib/components/console/return-detail-dialog.component.js.map +1 -0
- package/src/lib/components/console/return-settings-card.component.d.ts +34 -0
- package/src/lib/components/console/return-settings-card.component.js +195 -0
- package/src/lib/components/console/return-settings-card.component.js.map +1 -0
- package/src/lib/components/console/return-zones.d.ts +87 -0
- package/src/lib/components/console/return-zones.js +31 -0
- package/src/lib/components/console/return-zones.js.map +1 -0
- package/src/lib/components/console/returns-card.component.d.ts +45 -0
- package/src/lib/components/console/returns-card.component.js +159 -0
- package/src/lib/components/console/returns-card.component.js.map +1 -0
- package/src/lib/components/console/shipping-settings-card.component.js +161 -5
- package/src/lib/components/console/shipping-settings-card.component.js.map +1 -1
- package/src/lib/components/console/shippingeasy-card.component.d.ts +59 -0
- package/src/lib/components/console/shippingeasy-card.component.js +378 -0
- package/src/lib/components/console/shippingeasy-card.component.js.map +1 -0
- package/src/lib/components/console/shipstation-card.component.d.ts +35 -0
- package/src/lib/components/console/shipstation-card.component.js +345 -0
- package/src/lib/components/console/shipstation-card.component.js.map +1 -0
- package/src/lib/components/console/start-return-dialog.component.d.ts +40 -0
- package/src/lib/components/console/start-return-dialog.component.js +243 -0
- package/src/lib/components/console/start-return-dialog.component.js.map +1 -0
- package/src/lib/components/console/stock-movements-card.component.js +2 -1
- package/src/lib/components/console/stock-movements-card.component.js.map +1 -1
- package/src/lib/components/console/store-settings-card.component.js +2 -66
- package/src/lib/components/console/store-settings-card.component.js.map +1 -1
- package/src/lib/components/console/store-zones.d.ts +42 -0
- package/src/lib/components/console/store-zones.js +39 -0
- package/src/lib/components/console/store-zones.js.map +1 -0
- package/src/lib/components/order-status.d.ts +36 -0
- package/src/lib/components/order-status.js +502 -0
- package/src/lib/components/order-status.js.map +1 -0
- package/src/lib/components/product-detail.js +41 -2
- package/src/lib/components/product-detail.js.map +1 -1
- package/src/lib/components/return-request.d.ts +32 -0
- package/src/lib/components/return-request.js +576 -0
- package/src/lib/components/return-request.js.map +1 -0
- package/src/lib/components/storefront-payment-appearance.d.ts +32 -0
- package/src/lib/components/storefront-payment-appearance.js +114 -0
- package/src/lib/components/storefront-payment-appearance.js.map +1 -0
- package/src/lib/components/storefront-payment-element.d.ts +57 -1
- package/src/lib/components/storefront-payment-element.js +332 -33
- package/src/lib/components/storefront-payment-element.js.map +1 -1
- package/src/lib/constants/order-status.d.ts +22 -0
- package/src/lib/constants/order-status.js +22 -0
- package/src/lib/constants/order-status.js.map +1 -0
- package/src/lib/constants/return-request.d.ts +27 -0
- package/src/lib/constants/return-request.js +32 -0
- package/src/lib/constants/return-request.js.map +1 -0
- package/src/lib/constants/stock-movement-query.js +2 -1
- package/src/lib/constants/stock-movement-query.js.map +1 -1
- package/src/lib/declarations.console-server.js +9 -0
- package/src/lib/declarations.console-server.js.map +1 -1
- package/src/lib/declarations.server.d.ts +2 -1
- package/src/lib/declarations.server.js +47 -1
- package/src/lib/declarations.server.js.map +1 -1
- package/src/lib/model/buyer-notifications.d.ts +59 -0
- package/src/lib/model/buyer-notifications.js +97 -0
- package/src/lib/model/buyer-notifications.js.map +1 -0
- package/src/lib/model/commerce-orders.d.ts +127 -1
- package/src/lib/model/commerce-orders.js +24 -15
- package/src/lib/model/commerce-orders.js.map +1 -1
- package/src/lib/model/commerce-payment-methods.d.ts +146 -0
- package/src/lib/model/commerce-payment-methods.js +247 -0
- package/src/lib/model/commerce-payment-methods.js.map +1 -0
- package/src/lib/model/commerce-pos-ops.d.ts +437 -0
- package/src/lib/model/commerce-pos-ops.js +721 -0
- package/src/lib/model/commerce-pos-ops.js.map +1 -0
- package/src/lib/model/commerce-pos.d.ts +263 -0
- package/src/lib/model/commerce-pos.js +375 -0
- package/src/lib/model/commerce-pos.js.map +1 -0
- package/src/lib/model/commerce-printers.d.ts +211 -0
- package/src/lib/model/commerce-printers.js +181 -0
- package/src/lib/model/commerce-printers.js.map +1 -0
- package/src/lib/model/commerce-receipt.d.ts +97 -0
- package/src/lib/model/commerce-receipt.js +180 -0
- package/src/lib/model/commerce-receipt.js.map +1 -0
- package/src/lib/model/commerce-returns.d.ts +207 -0
- package/src/lib/model/commerce-returns.js +300 -0
- package/src/lib/model/commerce-returns.js.map +1 -0
- package/src/lib/model/commerce-shipping.d.ts +44 -1
- package/src/lib/model/commerce-shipping.js +53 -9
- package/src/lib/model/commerce-shipping.js.map +1 -1
- package/src/lib/model/commerce-tax-engine.d.ts +90 -0
- package/src/lib/model/commerce-tax-engine.js +129 -0
- package/src/lib/model/commerce-tax-engine.js.map +1 -0
- package/src/lib/model/commerce.d.ts +88 -2
- package/src/lib/model/commerce.js +89 -1
- package/src/lib/model/commerce.js.map +1 -1
- package/src/lib/model/index.d.ts +15 -0
- package/src/lib/model/index.js +15 -0
- package/src/lib/model/index.js.map +1 -1
- package/src/lib/model/order-events.d.ts +154 -0
- package/src/lib/model/order-events.js +153 -0
- package/src/lib/model/order-events.js.map +1 -0
- package/src/lib/model/order-fulfillment.d.ts +117 -0
- package/src/lib/model/order-fulfillment.js +217 -0
- package/src/lib/model/order-fulfillment.js.map +1 -0
- package/src/lib/model/order-history.d.ts +58 -0
- package/src/lib/model/order-history.js +22 -0
- package/src/lib/model/order-history.js.map +1 -0
- package/src/lib/model/order-list-fields.d.ts +9 -1
- package/src/lib/model/order-list-fields.js +7 -1
- package/src/lib/model/order-list-fields.js.map +1 -1
- package/src/lib/model/order-shipping-export.d.ts +91 -0
- package/src/lib/model/order-shipping-export.js +192 -0
- package/src/lib/model/order-shipping-export.js.map +1 -0
- package/src/lib/model/order-status-view.d.ts +103 -0
- package/src/lib/model/order-status-view.js +156 -0
- package/src/lib/model/order-status-view.js.map +1 -0
- package/src/lib/model/order-webhooks.d.ts +142 -0
- package/src/lib/model/order-webhooks.js +91 -0
- package/src/lib/model/order-webhooks.js.map +1 -0
- package/src/lib/model/product-channel.d.ts +56 -0
- package/src/lib/model/product-channel.js +86 -0
- package/src/lib/model/product-channel.js.map +1 -0
- package/src/lib/model/product-modifiers.d.ts +80 -0
- package/src/lib/model/product-modifiers.js +140 -0
- package/src/lib/model/product-modifiers.js.map +1 -0
- package/src/lib/model/shippingeasy.d.ts +94 -0
- package/src/lib/model/shippingeasy.js +267 -0
- package/src/lib/model/shippingeasy.js.map +1 -0
- package/src/lib/model/shipstation.d.ts +125 -0
- package/src/lib/model/shipstation.js +399 -0
- package/src/lib/model/shipstation.js.map +1 -0
- package/src/lib/model/smart-collection-reads.d.ts +32 -0
- package/src/lib/model/smart-collection-reads.js +63 -0
- package/src/lib/model/smart-collection-reads.js.map +1 -0
- package/src/lib/model/tracking-url.d.ts +74 -0
- package/src/lib/model/tracking-url.js +159 -0
- package/src/lib/model/tracking-url.js.map +1 -0
- package/src/lib/plugin-config.d.ts +13 -0
- package/src/lib/plugin-config.js +77 -5
- package/src/lib/plugin-config.js.map +1 -1
- package/src/lib/plugin.js +23 -0
- package/src/lib/plugin.js.map +1 -1
- package/src/lib/pos-ops-config.d.ts +39 -0
- package/src/lib/pos-ops-config.js +88 -0
- package/src/lib/pos-ops-config.js.map +1 -0
- package/src/lib/printing/print-document.d.ts +106 -0
- package/src/lib/printing/print-document.js +464 -0
- package/src/lib/printing/print-document.js.map +1 -0
- package/src/lib/printing/product-labels.d.ts +58 -0
- package/src/lib/printing/product-labels.js +116 -0
- package/src/lib/printing/product-labels.js.map +1 -0
- package/src/lib/printing/render-epson.d.ts +57 -0
- package/src/lib/printing/render-epson.js +135 -0
- package/src/lib/printing/render-epson.js.map +1 -0
- package/src/lib/printing/render-star.d.ts +45 -0
- package/src/lib/printing/render-star.js +100 -0
- package/src/lib/printing/render-star.js.map +1 -0
- package/src/lib/printing/render-text.d.ts +25 -0
- package/src/lib/printing/render-text.js +53 -0
- package/src/lib/printing/render-text.js.map +1 -0
- package/src/lib/server/api-v1/openapi.js +27 -4
- package/src/lib/server/api-v1/openapi.js.map +1 -1
- package/src/lib/server/api-v1/order-view.d.ts +67 -0
- package/src/lib/server/api-v1/order-view.js +120 -0
- package/src/lib/server/api-v1/order-view.js.map +1 -0
- package/src/lib/server/api-v1/orders-and-products.js +58 -65
- package/src/lib/server/api-v1/orders-and-products.js.map +1 -1
- package/src/lib/server/billing-webhook.js +135 -28
- package/src/lib/server/billing-webhook.js.map +1 -1
- package/src/lib/server/cancel-order.js +29 -0
- package/src/lib/server/cancel-order.js.map +1 -1
- package/src/lib/server/carrier-rates-availability.d.ts +26 -0
- package/src/lib/server/carrier-rates-availability.js +76 -0
- package/src/lib/server/carrier-rates-availability.js.map +1 -0
- package/src/lib/server/carrier-shipping.d.ts +84 -0
- package/src/lib/server/carrier-shipping.js +135 -0
- package/src/lib/server/carrier-shipping.js.map +1 -0
- package/src/lib/server/cart-checkout.d.ts +2 -0
- package/src/lib/server/cart-checkout.js +226 -22
- package/src/lib/server/cart-checkout.js.map +1 -1
- package/src/lib/server/checkout-extras.d.ts +64 -0
- package/src/lib/server/checkout-extras.js +157 -0
- package/src/lib/server/checkout-extras.js.map +1 -0
- package/src/lib/server/{feed.d.ts → checkout-status.d.ts} +2 -7
- package/src/lib/server/checkout-status.js +111 -0
- package/src/lib/server/checkout-status.js.map +1 -0
- package/src/lib/server/checkout.js +86 -9
- package/src/lib/server/checkout.js.map +1 -1
- package/src/lib/server/draft-order.js +34 -5
- package/src/lib/server/draft-order.js.map +1 -1
- package/src/lib/server/fulfill-order.d.ts +127 -10
- package/src/lib/server/fulfill-order.js +451 -49
- package/src/lib/server/fulfill-order.js.map +1 -1
- package/src/lib/server/legacy-feed.d.ts +28 -0
- package/src/lib/server/legacy-feed.js +52 -0
- package/src/lib/server/legacy-feed.js.map +1 -0
- package/src/lib/server/native-checkout.d.ts +34 -15
- package/src/lib/server/native-checkout.js +32 -17
- package/src/lib/server/native-checkout.js.map +1 -1
- package/src/lib/server/order-event-host-emit.d.ts +23 -0
- package/src/lib/server/order-event-host-emit.js +30 -0
- package/src/lib/server/order-event-host-emit.js.map +1 -0
- package/src/lib/server/order-event-triggers.d.ts +37 -0
- package/src/lib/server/order-event-triggers.js +119 -0
- package/src/lib/server/order-event-triggers.js.map +1 -0
- package/src/lib/server/order-events.d.ts +62 -0
- package/src/lib/server/order-events.js +109 -0
- package/src/lib/server/order-events.js.map +1 -0
- package/src/lib/server/order-history.d.ts +23 -0
- package/src/lib/server/order-history.js +65 -0
- package/src/lib/server/order-history.js.map +1 -0
- package/src/lib/server/order-notifications.d.ts +185 -0
- package/src/lib/server/order-notifications.js +567 -0
- package/src/lib/server/order-notifications.js.map +1 -0
- package/src/lib/server/order-receipt-send.d.ts +39 -0
- package/src/lib/server/order-receipt-send.js +151 -0
- package/src/lib/server/order-receipt-send.js.map +1 -0
- package/src/lib/server/order-status-token.d.ts +31 -0
- package/src/lib/server/order-status-token.js +75 -0
- package/src/lib/server/order-status-token.js.map +1 -0
- package/src/lib/server/order-status.d.ts +58 -0
- package/src/lib/server/order-status.js +141 -0
- package/src/lib/server/order-status.js.map +1 -0
- package/src/lib/server/order-webhooks.d.ts +108 -0
- package/src/lib/server/order-webhooks.js +622 -0
- package/src/lib/server/order-webhooks.js.map +1 -0
- package/src/lib/server/orders-shipping-prepare.d.ts +26 -0
- package/src/lib/server/orders-shipping-prepare.js +121 -0
- package/src/lib/server/orders-shipping-prepare.js.map +1 -0
- package/src/lib/server/payment-method-domains.d.ts +209 -0
- package/src/lib/server/payment-method-domains.js +444 -0
- package/src/lib/server/payment-method-domains.js.map +1 -0
- package/src/lib/server/payment-methods.d.ts +77 -0
- package/src/lib/server/payment-methods.js +284 -0
- package/src/lib/server/payment-methods.js.map +1 -0
- package/src/lib/server/pos-auth.d.ts +50 -0
- package/src/lib/server/pos-auth.js +121 -0
- package/src/lib/server/pos-auth.js.map +1 -0
- package/src/lib/server/pos-customer.d.ts +49 -0
- package/src/lib/server/pos-customer.js +257 -0
- package/src/lib/server/pos-customer.js.map +1 -0
- package/src/lib/server/pos-display.d.ts +57 -0
- package/src/lib/server/pos-display.js +419 -0
- package/src/lib/server/pos-display.js.map +1 -0
- package/src/lib/server/pos-fee-month.d.ts +34 -0
- package/src/lib/server/pos-fee-month.js +36 -0
- package/src/lib/server/pos-fee-month.js.map +1 -0
- package/src/lib/server/pos-ops-gate.d.ts +161 -0
- package/src/lib/server/pos-ops-gate.js +295 -0
- package/src/lib/server/pos-ops-gate.js.map +1 -0
- package/src/lib/server/pos-ops-routes.d.ts +22 -0
- package/src/lib/server/pos-ops-routes.js +36 -0
- package/src/lib/server/pos-ops-routes.js.map +1 -0
- package/src/lib/server/pos-order.d.ts +1 -18
- package/src/lib/server/pos-order.js +222 -42
- package/src/lib/server/pos-order.js.map +1 -1
- package/src/lib/server/pos-payment.d.ts +39 -0
- package/src/lib/server/pos-payment.js +922 -0
- package/src/lib/server/pos-payment.js.map +1 -0
- package/src/lib/server/pos-print.d.ts +82 -0
- package/src/lib/server/pos-print.js +193 -0
- package/src/lib/server/pos-print.js.map +1 -0
- package/src/lib/server/pos-readers.d.ts +27 -0
- package/src/lib/server/pos-readers.js +276 -0
- package/src/lib/server/pos-readers.js.map +1 -0
- package/src/lib/server/pos-refund-authority.d.ts +60 -0
- package/src/lib/server/pos-refund-authority.js +72 -0
- package/src/lib/server/pos-refund-authority.js.map +1 -0
- package/src/lib/server/pos-return.d.ts +58 -0
- package/src/lib/server/pos-return.js +891 -0
- package/src/lib/server/pos-return.js.map +1 -0
- package/src/lib/server/pos-sale-stamp.d.ts +66 -0
- package/src/lib/server/pos-sale-stamp.js +84 -0
- package/src/lib/server/pos-sale-stamp.js.map +1 -0
- package/src/lib/server/pos-sale.d.ts +170 -0
- package/src/lib/server/pos-sale.js +461 -0
- package/src/lib/server/pos-sale.js.map +1 -0
- package/src/lib/server/pos-shift.d.ts +45 -0
- package/src/lib/server/pos-shift.js +484 -0
- package/src/lib/server/pos-shift.js.map +1 -0
- package/src/lib/server/pos-staff-pin.d.ts +26 -0
- package/src/lib/server/pos-staff-pin.js +339 -0
- package/src/lib/server/pos-staff-pin.js.map +1 -0
- package/src/lib/server/pos-stripe.d.ts +91 -0
- package/src/lib/server/pos-stripe.js +129 -0
- package/src/lib/server/pos-stripe.js.map +1 -0
- package/src/lib/server/pos-terminal-connection-token.d.ts +48 -0
- package/src/lib/server/pos-terminal-connection-token.js +166 -0
- package/src/lib/server/pos-terminal-connection-token.js.map +1 -0
- package/src/lib/server/pos-terminal.d.ts +218 -0
- package/src/lib/server/pos-terminal.js +1014 -0
- package/src/lib/server/pos-terminal.js.map +1 -0
- package/src/lib/server/print-queue.d.ts +124 -0
- package/src/lib/server/print-queue.js +301 -0
- package/src/lib/server/print-queue.js.map +1 -0
- package/src/lib/server/printer-poll.d.ts +75 -0
- package/src/lib/server/printer-poll.js +325 -0
- package/src/lib/server/printer-poll.js.map +1 -0
- package/src/lib/server/printer-secret.d.ts +39 -0
- package/src/lib/server/printer-secret.js +56 -0
- package/src/lib/server/printer-secret.js.map +1 -0
- package/src/lib/server/printers.d.ts +114 -0
- package/src/lib/server/printers.js +546 -0
- package/src/lib/server/printers.js.map +1 -0
- package/src/lib/server/product-catalog.d.ts +42 -0
- package/src/lib/server/product-catalog.js +305 -0
- package/src/lib/server/product-catalog.js.map +1 -0
- package/src/lib/server/refund.js +110 -45
- package/src/lib/server/refund.js.map +1 -1
- package/src/lib/server/reserve.js +2 -0
- package/src/lib/server/reserve.js.map +1 -1
- package/src/lib/server/return-status-action.d.ts +37 -0
- package/src/lib/server/return-status-action.js +57 -0
- package/src/lib/server/return-status-action.js.map +1 -0
- package/src/lib/server/returns.d.ts +119 -0
- package/src/lib/server/returns.js +938 -0
- package/src/lib/server/returns.js.map +1 -0
- package/src/lib/server/shipment-records.d.ts +36 -0
- package/src/lib/server/shipment-records.js +289 -0
- package/src/lib/server/shipment-records.js.map +1 -0
- package/src/lib/server/shipping-connector-gates.d.ts +40 -0
- package/src/lib/server/shipping-connector-gates.js +97 -0
- package/src/lib/server/shipping-connector-gates.js.map +1 -0
- package/src/lib/server/shipping-connectors.d.ts +29 -0
- package/src/lib/server/shipping-connectors.js +236 -0
- package/src/lib/server/shipping-connectors.js.map +1 -0
- package/src/lib/server/shippingeasy.d.ts +238 -0
- package/src/lib/server/shippingeasy.js +787 -0
- package/src/lib/server/shippingeasy.js.map +1 -0
- package/src/lib/server/shipstation.d.ts +129 -0
- package/src/lib/server/shipstation.js +483 -0
- package/src/lib/server/shipstation.js.map +1 -0
- package/src/lib/server/site-page-resolver.d.ts +5 -0
- package/src/lib/server/site-page-resolver.js +156 -1
- package/src/lib/server/site-page-resolver.js.map +1 -1
- package/src/lib/server/stock-levels.d.ts +21 -0
- package/src/lib/server/stock-levels.js +263 -0
- package/src/lib/server/stock-levels.js.map +1 -0
- package/src/lib/server/stripe-refund.d.ts +47 -0
- package/src/lib/server/stripe-refund.js +87 -0
- package/src/lib/server/stripe-refund.js.map +1 -0
- package/src/lib/server/supplier-update.js +46 -5
- package/src/lib/server/supplier-update.js.map +1 -1
- package/src/lib/server/tax-engine-quote.d.ts +47 -0
- package/src/lib/server/tax-engine-quote.js +105 -0
- package/src/lib/server/tax-engine-quote.js.map +1 -0
- package/src/lib/server.js +138 -2
- package/src/lib/server.js.map +1 -1
- package/src/lib/site.js +12 -0
- package/src/lib/site.js.map +1 -1
- package/src/lib/subprocessors.d.ts +26 -0
- package/src/lib/subprocessors.js +50 -0
- package/src/lib/subprocessors.js.map +1 -0
- package/src/lib/tenant-emails.js +461 -3
- package/src/lib/tenant-emails.js.map +1 -1
- package/src/lib/testing/fake-firestore.d.ts +45 -0
- package/src/lib/testing/fake-firestore.js +189 -0
- package/src/lib/testing/fake-firestore.js.map +1 -0
- package/src/lib/testing/memory-firestore.d.ts +123 -0
- package/src/lib/testing/memory-firestore.js +274 -0
- package/src/lib/testing/memory-firestore.js.map +1 -0
- package/src/lib/testing/pos-ops-harness.d.ts +50 -0
- package/src/lib/testing/pos-ops-harness.js +184 -0
- package/src/lib/testing/pos-ops-harness.js.map +1 -0
- package/src/lib/testing/pos-ops-memory-firestore.d.ts +55 -0
- package/src/lib/testing/pos-ops-memory-firestore.js +376 -0
- package/src/lib/testing/pos-ops-memory-firestore.js.map +1 -0
- package/src/lib/transfer/records-transfer.d.ts +11 -1
- package/src/lib/transfer/records-transfer.js +127 -5
- package/src/lib/transfer/records-transfer.js.map +1 -1
- package/src/lib/transfer/records.server.d.ts +9 -2
- package/src/lib/transfer/records.server.js +58 -7
- package/src/lib/transfer/records.server.js.map +1 -1
- package/src/lib/transfer/register-transfer-resources.js +40 -1
- package/src/lib/transfer/register-transfer-resources.js.map +1 -1
- package/src/lib/transfer/register-transfer-ui.js +4 -1
- package/src/lib/transfer/register-transfer-ui.js.map +1 -1
- package/src/lib/transfer/shipping-presets.d.ts +23 -0
- package/src/lib/transfer/shipping-presets.js +156 -0
- package/src/lib/transfer/shipping-presets.js.map +1 -0
- package/src/lib/transfer/tracking-transfer.d.ts +101 -0
- package/src/lib/transfer/tracking-transfer.js +546 -0
- package/src/lib/transfer/tracking-transfer.js.map +1 -0
- package/src/lib/transfer/tracking.server.d.ts +37 -0
- package/src/lib/transfer/tracking.server.js +393 -0
- package/src/lib/transfer/tracking.server.js.map +1 -0
- package/src/lib/transfer/transfer-keys.d.ts +2 -1
- package/src/lib/transfer/transfer-keys.js +6 -2
- package/src/lib/transfer/transfer-keys.js.map +1 -1
- package/src/lib/utils/code128.d.ts +37 -0
- package/src/lib/utils/code128.js +199 -0
- package/src/lib/utils/code128.js.map +1 -0
- package/src/lib/utils/order-invoice.d.ts +55 -0
- package/src/lib/utils/order-invoice.js +127 -0
- package/src/lib/utils/order-invoice.js.map +1 -0
- package/src/lib/utils/use-checkout-return-notice.d.ts +34 -0
- package/src/lib/utils/use-checkout-return-notice.js +78 -0
- package/src/lib/utils/use-checkout-return-notice.js.map +1 -0
- package/src/lib/server/feed.js +0 -69
- package/src/lib/server/feed.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/server/pos-return.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { claimAttempt, type PluginApiHandler, type PluginApiRequest } from '@aglyn/aglyn/server'\nimport { createResourceUid } from '@aglyn/aglyn/app-utils/create-resource-uid'\nimport { nameSearchKey } from '@aglyn/aglyn/app-utils/name-search'\nimport { recordPluginPersonRefund } from '@aglyn/aglyn/plugin-manager/plugin-person-records'\nimport { reverseOrderConversion } from '@aglyn/aglyn/plugin-manager/plugin-conversion-credit'\nimport * as CommerceModel from '../model'\nimport {\n planPosReturn,\n posMoney,\n posRefundableByTender,\n posReturnedQuantities,\n posReturnLineValues,\n posTenderLabel,\n POS_STRIPE_TENDERS,\n splitPosRefund,\n type PosCashEvent,\n type PosRefundAllocation,\n type PosRegisterReturn,\n type PosReturnPick,\n type PosReturnSource,\n} from '../model/commerce-pos-ops'\nimport { ORDER_REFUNDED_EVENT, RETURN_REFUNDED_EVENT } from '../model/order-events'\nimport { raiseOrderEvent } from './order-events'\nimport { applyGiftCardRiskToOrder } from './gift-card-risk'\nimport { notifyOrderBuyer } from './order-notifications'\nimport { decidePosRefundAuthority } from './pos-refund-authority'\nimport {\n authorizePosOps,\n defaultPosOpsDeps,\n posOpsBody,\n posOpsCleanId,\n posOpsIdempotencyKey,\n readPosRegister,\n isPosManager,\n resolvePosCashier,\n type PosOpsDeps,\n} from './pos-ops-gate'\nimport { createStripeRefund } from './stripe-refund'\n\n/*==========================================\n * RETURNS AT THE REGISTER (AGL-3609): `POST /api/commerce/pos-return`.\n *\n * find an order by its number (typed or scanned off the receipt's\n * barcode), its id, or the customer's email\n * refund picked lines and quantities back, restocked to the register's\n * location, the money sent back to the sale's OWN payments\n *\n * Each payment gets its money back the way it came: a card through Stripe\n * (the same refund the order dialog sends), cash out of the drawer — a cash\n * event on the open shift, so the count still balances — a gift card\n * re-credited, and a room charge reversed on the stay's folio.\n *\n * THE ORDER OF WORK is what keeps a failure honest:\n * 1. every refusal that needs no money to move (role, limit, quantities,\n * the split, the shift rule) — before anything is written;\n * 2. the attempt claim, so a retried tap replays instead of refunding twice;\n * 3. the RESERVATION on the order, in a transaction that re-reads it: the\n * cents, the units and each payment's share are taken before any money\n * moves, so two registers returning the same line cannot both succeed;\n * 4. the Stripe refunds first, because they are the ones that can say no —\n * if the first one does, nothing has moved and the reservation is\n * handed back whole;\n * 5. then the tenders that cannot fail for a reason outside this database.\n * A card that fails after another payment already went back leaves a\n * PARTIAL return: what moved is recorded, what did not is handed back on\n * the order, and the cashier is told the amount still owed.\n *=========================================*/\n\nexport interface PosReturnSideEffects {\n hostId: string\n orderId: string\n /** The return's id, the same under the register and in the store's returns. */\n returnId: string\n /** The return as the store's returns list holds it, for the return event. */\n storeReturn: CommerceModel.HostReturn\n /** The Stripe refunds the return made, if any, for the refund event. */\n refundIds: string[]\n email: string | null | undefined\n refundCents: number\n closedTheOrder: boolean\n returnedProductIds: string[]\n fullyRefunded: boolean\n lineIndexes: number[]\n /** The lines this return finished taking back in full. */\n fullLineIndexes: number[]\n}\n\nexport interface PosReturnDeps extends PosOpsDeps {\n /** What every refund tells the rest of the workspace, after the money moved. Never throws. */\n afterRefund(input: PosReturnSideEffects): Promise<void>\n}\n\nexport function defaultPosReturnDeps(): PosReturnDeps {\n const base = defaultPosOpsDeps()\n return {\n ...base,\n afterRefund: async (input) => {\n const settle = async (label: string, work: () => Promise<unknown>) => {\n try {\n await work()\n } catch (error) {\n console.error(`[pos-return] ${label} failed`, input.orderId, error)\n }\n }\n const hostRef = base.firestore().collection('hosts').doc(input.hostId)\n if (input.returnedProductIds.length) {\n await settle('gift card void', () =>\n applyGiftCardRiskToOrder({\n firestore: base.firestore(),\n hostRef,\n orderId: input.orderId,\n action: {\n kind: 'void',\n reason: 'refund',\n ...(input.fullyRefunded ? {} : { productIds: input.returnedProductIds }),\n },\n }),\n )\n }\n await settle('person refund', () =>\n recordPluginPersonRefund({\n hostId: input.hostId,\n refId: input.orderId,\n email: input.email,\n amountCents: input.refundCents,\n closedTheSale: input.closedTheOrder,\n }),\n )\n await settle('conversion reversal', () =>\n reverseOrderConversion({\n hostId: input.hostId,\n orderId: input.orderId,\n amountCents: input.refundCents,\n closedTheOrder: input.closedTheOrder,\n }),\n )\n // The same events a refund from the order dialog and a refunded online\n // return raise, so accounting and the merchant's webhooks hear a\n // register return too (AGL-3611's events).\n await settle('refund event', () =>\n raiseOrderEvent(ORDER_REFUNDED_EVENT, {\n hostId: input.hostId,\n orderId: input.orderId,\n key: `pos-return:${input.returnId}`,\n extra: {\n refund: {\n id: input.refundIds[0] ?? null,\n amountCents: input.refundCents,\n lineItemIds: input.fullLineIndexes,\n full: input.fullyRefunded,\n },\n },\n }),\n )\n await settle('return event', () =>\n raiseOrderEvent(RETURN_REFUNDED_EVENT, {\n hostId: input.hostId,\n orderId: input.orderId,\n key: `return-refunded:${input.returnId}`,\n extra: {\n return: {\n id: input.returnId,\n status: input.storeReturn.status,\n lines: input.storeReturn.lines.map((line) => ({ ...line })),\n refundCents: input.storeReturn.refundCents ?? null,\n },\n },\n }),\n )\n await settle('buyer notice', () =>\n notifyOrderBuyer({ hostId: input.hostId, orderId: input.orderId }, 'refunded', {\n refundId: '',\n refundCents: input.refundCents,\n refundLineIndexes: input.lineIndexes,\n fullyRefunded: input.fullyRefunded,\n }),\n )\n },\n }\n}\n\ntype Outcome = { status: number; body: Record<string, unknown> }\n\n/** The statuses a return may be taken against. */\nconst RETURNABLE: ReadonlySet<string> = new Set([\n 'paid',\n 'partially_fulfilled',\n 'fulfilled',\n 'delivered',\n])\n\n/** One order as the return dialog lists it. */\nfunction returnSummary(id: string, raw: Record<string, any>, held: readonly number[] = []) {\n const order = CommerceModel.liftLegacyOrder(raw as any) as unknown as PosReturnSource &\n Record<string, any>\n const values = posReturnLineValues(order)\n const returned = posReturnedQuantities(order)\n return {\n id,\n number: order['number'] ?? null,\n label: CommerceModel.formatOrderNumber(order as any, id),\n status: order['status'],\n channel: order['channel'] ?? 'online',\n createdAtMs: Number(order['createdAtMs'] ?? 0),\n customerEmail: order['customerEmail'] ?? null,\n customerName: order['customerName'] ?? null,\n totalCents: Number(order.totals?.totalCents ?? order.amountCents ?? 0),\n refundedCents: Number(order.refundedCents ?? 0),\n returnable: RETURNABLE.has(String(order['status'])),\n lines: (order.lineItems ?? []).map((line: any, index: number) => ({\n index,\n name: String(line?.name ?? ''),\n variantLabel: line?.variantLabel ?? null,\n quantity: Math.max(1, Math.round(Number(line?.quantity ?? 1))),\n returned: returned[index] ?? 0,\n // Units an online return holds or already took (AGL-3611).\n held: held[index] ?? 0,\n valueCents: values[index] ?? 0,\n })),\n tenders: posRefundableByTender(order).map((tender) => ({\n id: tender.id,\n method: tender.method,\n label: posTenderLabel(tender),\n amountCents: tender.amountCents,\n refundableCents: tender.refundableCents,\n })),\n }\n}\n\nasync function findOrders(\n hostRef: FirebaseFirestore.DocumentReference,\n rawText: unknown,\n): Promise<Array<{ id: string; data: Record<string, any> }>> {\n const text = String(rawText ?? '').trim().slice(0, 200)\n if (!text) return []\n const orders = hostRef.collection('orders')\n const digits = text.replace(/^#/, '')\n if (/^\\d{1,12}$/.test(digits)) {\n const snapshot = await orders.where('number', '==', Number(digits)).limit(5).get()\n return snapshot.docs.map((doc) => ({ id: doc.id, data: (doc.data() ?? {}) as Record<string, any> }))\n }\n if (text.includes('@')) {\n const snapshot = await orders\n .where('customerEmailLower', '==', nameSearchKey(text))\n .orderBy('createdAtMs', 'desc')\n .limit(10)\n .get()\n return snapshot.docs.map((doc) => ({ id: doc.id, data: (doc.data() ?? {}) as Record<string, any> }))\n }\n const id = posOpsCleanId(text)\n if (!id) return []\n const snapshot = await orders.doc(id).get()\n return snapshot.exists ? [{ id, data: (snapshot.data() ?? {}) as Record<string, any> }] : []\n}\n\nfunction parsePicks(raw: unknown): PosReturnPick[] {\n if (!Array.isArray(raw)) return []\n return raw.slice(0, 200).map((entry: any) => ({\n index: Number(entry?.index),\n quantity: Number(entry?.quantity),\n }))\n}\n\nfunction parseSplit(raw: unknown): Array<{ paymentId: string; amountCents: number }> | null {\n if (!Array.isArray(raw) || !raw.length) return null\n return raw.slice(0, 20).map((entry: any) => ({\n paymentId: String(entry?.paymentId ?? ''),\n amountCents: Number(entry?.amountCents),\n }))\n}\n\n/** What a refunded tender moved, and how to hand back a reservation it did not. */\ninterface TenderResult {\n allocation: PosRefundAllocation\n status: 'refunded' | 'failed'\n refundId?: string\n error?: string\n}\n\nexport async function handlePosReturn(deps: PosReturnDeps, req: PluginApiRequest): Promise<Outcome> {\n if (req.method !== 'POST') return { status: 405, body: { error: 'Method not allowed' } }\n const body = posOpsBody(req)\n const gate = await authorizePosOps(deps, req, body['hostId'])\n if ('error' in gate) return { status: gate.status, body: { error: gate.error } }\n const staff = gate.staff\n const action = String(body['action'] ?? '')\n\n if (action === 'find') {\n const found = await findOrders(staff.hostRef, body['text'])\n const held = await Promise.all(\n found.map(async (entry) =>\n unitsHeldByOnlineReturns(\n (await staff.hostRef.collection('returns').where('orderId', '==', entry.id).get()).docs,\n ),\n ),\n )\n return {\n status: 200,\n body: { orders: found.map((entry, at) => returnSummary(entry.id, entry.data, held[at])) },\n }\n }\n if (action !== 'refund') return { status: 400, body: { error: 'Unknown action' } }\n\n const register = await readPosRegister(staff, body['registerId'])\n if ('error' in register) return { status: register.status, body: { error: register.error } }\n const registerId = register.ref.id\n const orderId = posOpsCleanId(body['orderId'])\n if (!orderId) return { status: 400, body: { error: 'Missing orderId' } }\n const idempotencyKey = posOpsIdempotencyKey(req)\n if (!idempotencyKey) {\n return { status: 400, body: { error: 'A refund needs an Idempotency-Key header.' } }\n }\n const picks = parsePicks(body['lines'])\n const requestedSplit = parseSplit(body['tenders'])\n const restock = body['restock'] !== false\n const reason = String(body['reason'] ?? '').trim().slice(0, 200)\n const reasonCode: CommerceModel.ReturnReason = CommerceModel.RETURN_REASONS.includes(\n body['reasonCode'] as CommerceModel.ReturnReason,\n )\n ? (body['reasonCode'] as CommerceModel.ReturnReason)\n : 'other'\n const firestore = deps.firestore()\n const orderRef = staff.hostRef.collection('orders').doc(orderId)\n const storeReturns = staff.hostRef.collection('returns').where('orderId', '==', orderId)\n\n // 1. Every refusal that needs no money to move.\n const snapshot = await orderRef.get()\n if (!snapshot.exists) return { status: 404, body: { error: 'Unknown order' } }\n const order = CommerceModel.liftLegacyOrder(snapshot.data() as any) as unknown as PosReturnSource &\n Record<string, any>\n if (!RETURNABLE.has(String(order['status']))) {\n return { status: 409, body: { error: `Orders in \"${order['status']}\" cannot be returned.` } }\n }\n if (CommerceModel.orderDisputeBlocksRefund(order as any)) {\n return {\n status: 409,\n body: {\n error:\n 'A chargeback is open on this order, so it was not refunded. Respond to the ' +\n 'dispute or accept it in the Stripe dashboard first.',\n },\n }\n }\n const plan = planPosReturn(order, picks, unitsHeldByOnlineReturns((await storeReturns.get()).docs))\n if ('error' in plan) return { status: 400, body: { error: plan.error } }\n const split = splitPosRefund(order, plan.refundCents, requestedSplit)\n if ('error' in split) return { status: 400, body: { error: split.error } }\n\n const cashier = await resolvePosCashier(deps, staff, registerId, body['cashierAssertion'])\n // The limit is the person at the till's: a PIN-switched cashier is held\n // to it even on a device a workspace admin signed in on.\n const cashierIsManager =\n cashier.cashierId === staff.uid\n ? staff.isManager\n : await memberIsPosManager(deps, staff.hostRef, staff.hostId, cashier.cashierId)\n const authority = await decidePosRefundAuthority(deps, {\n hostId: staff.hostId,\n hostRef: staff.hostRef,\n registerId,\n refundCents: plan.refundCents,\n limitCents: staff.settings.refundLimitCents,\n isManager: cashierIsManager,\n managerAssertion: body['managerAssertion'],\n })\n if ('body' in authority) return { status: 403, body: authority.body }\n\n const needsCash = split.allocations.some((slice) => slice.method === 'cash')\n const needsStripe = split.allocations.some((slice) => POS_STRIPE_TENDERS.has(slice.method))\n const openShiftId = String(register.data['openShiftId'] ?? '') || null\n if (needsCash && !openShiftId && staff.settings.requireOpenShift) {\n return { status: 409, body: { error: 'Open a shift before paying cash out of the drawer.' } }\n }\n if (needsStripe && !process.env.STRIPE_SECRET_KEY) {\n return { status: 501, body: { error: 'Payments are not configured.' } }\n }\n\n // 2. The attempt claim.\n const claimed = await claimAttempt(firestore as any, {\n kind: 'pos-return',\n scopeId: staff.hostId,\n orgId: staff.orgId,\n key: `${orderId}:${idempotencyKey}`,\n busyMessage: 'This return is already being refunded',\n })\n if ('replay' in claimed) return { status: claimed.replay.status, body: claimed.replay.body as any }\n const claim = claimed.claim\n\n // 3. The reservation, re-read under the transaction.\n type Reserved = {\n refundCents: number\n lineCents: number[]\n completedLines: number[]\n allocations: PosRefundAllocation[]\n prior: { refundedCents: number; returnedQuantities: Record<string, number>; posPaymentRefunds: Record<string, number> }\n }\n let reserved: Reserved\n try {\n reserved = await firestore.runTransaction(async (transaction) => {\n const fresh = CommerceModel.liftLegacyOrder(\n ((await transaction.get(orderRef)).data() ?? {}) as any,\n ) as unknown as PosReturnSource & Record<string, any>\n if (!RETURNABLE.has(String(fresh['status']))) {\n throw new ReturnRefusal(409, `Orders in \"${fresh['status']}\" cannot be returned.`)\n }\n const freshPlan = planPosReturn(\n fresh,\n picks,\n unitsHeldByOnlineReturns((await transaction.get(storeReturns)).docs),\n )\n if ('error' in freshPlan) throw new ReturnRefusal(409, freshPlan.error)\n const freshSplit = splitPosRefund(fresh, freshPlan.refundCents, requestedSplit)\n if ('error' in freshSplit) throw new ReturnRefusal(409, freshSplit.error)\n const prior = {\n refundedCents: Number(fresh.refundedCents ?? 0),\n returnedQuantities: { ...(fresh.returnedQuantities ?? {}) },\n posPaymentRefunds: { ...(fresh.posPaymentRefunds ?? {}) },\n }\n const posPaymentRefunds = { ...prior.posPaymentRefunds }\n for (const slice of freshSplit.allocations) {\n posPaymentRefunds[slice.paymentId] = (posPaymentRefunds[slice.paymentId] ?? 0) + slice.amountCents\n }\n transaction.update(orderRef, {\n refundedCents: prior.refundedCents + freshPlan.refundCents,\n returnedQuantities: freshPlan.returnedQuantities,\n posPaymentRefunds,\n })\n return {\n refundCents: freshPlan.refundCents,\n lineCents: freshPlan.lineCents,\n completedLines: freshPlan.completedLines,\n allocations: freshSplit.allocations,\n prior,\n }\n })\n } catch (error) {\n await claim.release()\n if (error instanceof ReturnRefusal) return { status: error.status, body: { error: error.message } }\n throw error\n }\n\n // 4–5. The money, Stripe first.\n const tenders = posRefundableByTender(order)\n const tenderOf = (paymentId: string) => tenders.find((tender) => tender.id === paymentId)\n const ordered = [...reserved.allocations].sort(\n (a, b) => Number(POS_STRIPE_TENDERS.has(b.method)) - Number(POS_STRIPE_TENDERS.has(a.method)),\n )\n const results: TenderResult[] = []\n for (const allocation of ordered) {\n const tender = tenderOf(allocation.paymentId)\n const anyMoved = results.some((result) => result.status === 'refunded')\n try {\n if (POS_STRIPE_TENDERS.has(allocation.method)) {\n const paymentIntentId = tender?.paymentIntentId ?? String(order['paymentIntentId'] ?? '')\n if (!paymentIntentId) throw new ReturnRefusal(409, 'That card payment has nothing Stripe can refund.')\n const refund = await createStripeRefund({\n paymentIntentId,\n amountCents: allocation.amountCents,\n idempotencyKey: claim.stripeKey ? `${claim.stripeKey}:${allocation.paymentId}` : null,\n metadata: { hostId: staff.hostId, orderId, registerId, kind: 'pos-return' },\n fetch: deps.fetch,\n })\n if ('error' in refund) throw new ReturnRefusal(refund.status, refund.error)\n results.push({ allocation, status: 'refunded', refundId: refund.refundId })\n } else if (allocation.method === 'gift_card') {\n await creditGiftCard(firestore, staff.hostRef, tender?.giftCardId ?? '', allocation.amountCents, orderId, deps.now())\n results.push({ allocation, status: 'refunded' })\n } else if (allocation.method === 'folio') {\n await reverseFolio(staff.hostRef, tender?.reservationId ?? String(order['reservationId'] ?? ''), allocation.amountCents, orderId, deps.now())\n results.push({ allocation, status: 'refunded' })\n } else {\n // Cash: recorded on the drawer with the return itself, below.\n results.push({ allocation, status: 'refunded' })\n }\n } catch (error) {\n const message = error instanceof ReturnRefusal ? error.message : 'Refund failed'\n if (!(error instanceof ReturnRefusal)) console.error('[pos-return] tender failed', allocation, error)\n if (!anyMoved) {\n // Nothing has moved: hand the whole reservation back and let the\n // same attempt be tried again.\n await firestore\n .runTransaction(async (transaction) => {\n await transaction.get(orderRef)\n transaction.update(orderRef, reserved.prior)\n })\n .catch((rollback) => console.error('[pos-return] rollback failed', orderId, rollback))\n await claim.release()\n return {\n status: error instanceof ReturnRefusal ? error.status : 502,\n body: { error: message },\n }\n }\n results.push({ allocation, status: 'failed', error: message })\n }\n }\n\n const failed = results.filter((result) => result.status === 'failed')\n const refundedCents = results\n .filter((result) => result.status === 'refunded')\n .reduce((sum, result) => sum + result.allocation.amountCents, 0)\n const cashCents = results\n .filter((result) => result.status === 'refunded' && result.allocation.method === 'cash')\n .reduce((sum, result) => sum + result.allocation.amountCents, 0)\n const now = deps.now()\n // One id names the return under the register (its tenders and shift) and\n // in the store's returns list beside the online ones (AGL-3611).\n const returnId = createResourceUid()\n const returnRef = register.ref.collection('returns').doc(returnId)\n const storeReturnRef = staff.hostRef.collection('returns').doc(returnId)\n const orderLabel = CommerceModel.formatOrderNumber(order as any, orderId)\n const lines = picks.map((pick, at) => ({\n index: pick.index,\n quantity: pick.quantity,\n name: String(order.lineItems?.[pick.index]?.name ?? ''),\n refundCents: reserved.lineCents[at] ?? 0,\n }))\n\n // The record, the drawer, the order: one transaction.\n let closedTheOrder = false\n let fullyRefunded = false\n let shiftIdForReturn: string | null = null\n let storeReturn: CommerceModel.HostReturn | null = null\n await firestore.runTransaction(async (transaction) => {\n const freshRegister = await transaction.get(register.ref)\n const shiftId = String(freshRegister.get('openShiftId') ?? '') || null\n const shiftRef = shiftId ? register.ref.collection('shifts').doc(shiftId) : null\n const shiftSnapshot = shiftRef ? await transaction.get(shiftRef) : null\n const fresh = CommerceModel.liftLegacyOrder(\n ((await transaction.get(orderRef)).data() ?? {}) as any,\n ) as unknown as PosReturnSource & Record<string, any>\n const shiftOpen = Boolean(shiftSnapshot?.exists && shiftSnapshot.get('status') === 'open')\n shiftIdForReturn = shiftOpen ? shiftId : null\n\n // Hand back what a failed card did not refund.\n const failedCents = failed.reduce((sum, result) => sum + result.allocation.amountCents, 0)\n const posPaymentRefunds = { ...(fresh.posPaymentRefunds ?? {}) }\n for (const result of failed) {\n posPaymentRefunds[result.allocation.paymentId] = Math.max(\n 0,\n (posPaymentRefunds[result.allocation.paymentId] ?? 0) - result.allocation.amountCents,\n )\n }\n const orderRefunded = Math.max(0, Number(fresh.refundedCents ?? 0) - failedCents)\n const totalCents = Number(fresh.totals?.totalCents ?? fresh.amountCents ?? 0)\n fullyRefunded = orderRefunded >= totalCents && totalCents > 0\n closedTheOrder =\n fullyRefunded &&\n fresh['status'] !== 'refunded' &&\n CommerceModel.canTransitionOrder(fresh['status'] as CommerceModel.OrderStatus, 'refunded')\n const completedLines = Object.entries(fresh.returnedQuantities ?? {})\n .filter(([index, count]) => count >= Math.max(1, Number(fresh.lineItems?.[Number(index)]?.quantity ?? 1)))\n .map(([index]) => Number(index))\n const tenderWords = results\n .map(\n (result) =>\n `${posMoney(result.allocation.amountCents)} to ${posTenderLabel(\n tenderOf(result.allocation.paymentId) ?? { method: result.allocation.method },\n )}${result.status === 'failed' ? ' (FAILED)' : ''}`,\n )\n .join(', ')\n const units = picks.reduce((sum, pick) => sum + pick.quantity, 0)\n transaction.update(orderRef, {\n refundedCents: orderRefunded,\n posPaymentRefunds,\n ...(closedTheOrder ? { status: 'refunded' } : {}),\n ...(completedLines.length\n ? {\n refundedLineItemIds: [\n ...new Set([...(fresh.refundedLineItemIds ?? []), ...completedLines]),\n ].sort((a, b) => a - b),\n }\n : {}),\n timeline: CommerceModel.appendOrderEvent(\n fresh as any,\n 'refund',\n `Returned at the register: ${units} ${units === 1 ? 'item' : 'items'}, ${tenderWords}` +\n (restock ? '; restocked' : '') +\n (authority.approvedBy ? '; approved by a manager' : ''),\n now,\n ),\n })\n const record: PosRegisterReturn = {\n hostId: staff.hostId,\n registerId,\n orderId,\n ...(typeof order['number'] === 'number' ? { orderNumber: order['number'] } : {}),\n ...(shiftOpen && shiftId ? { shiftId } : {}),\n lines,\n refundedCents,\n tenders: results.map((result) => ({\n ...result.allocation,\n status: result.status,\n ...(result.refundId ? { refundId: result.refundId } : {}),\n ...(result.error ? { error: result.error } : {}),\n })),\n restocked: restock,\n ...(register.data['locationId'] ? { locationId: String(register.data['locationId']) } : {}),\n cashierId: cashier.cashierId,\n ...(authority.approvedBy ? { approvedBy: authority.approvedBy } : {}),\n ...(reason ? { reason } : {}),\n status: failed.length ? 'partial' : 'refunded',\n atMs: now,\n }\n transaction.create(returnRef, record)\n const restockedLines = picks.map((pick) => ({ lineItemId: pick.index, quantity: pick.quantity }))\n const registerLocationId = register.data['locationId'] ? String(register.data['locationId']) : undefined\n storeReturn = {\n orderId,\n orderNumber: orderLabel,\n customerEmail: (order['customerEmail'] as string | undefined) ?? null,\n customerName: (order['customerName'] as string | undefined) ?? null,\n lines: picks.map((pick) => ({ lineItemId: pick.index, quantity: pick.quantity, reason: reasonCode })),\n status: 'refunded',\n requestedBy: 'merchant',\n source: 'register',\n registerId,\n ...(reason ? { merchantNote: reason } : {}),\n ...(restock\n ? {\n restock: {\n lines: restockedLines,\n ...(registerLocationId ? { locationId: registerLocationId } : {}),\n atMs: now,\n },\n }\n : {}),\n refundedAtMs: now,\n refundCents: refundedCents,\n timeline: [\n {\n atMs: now,\n event: 'refunded',\n detail: `At the register${failed.length ? `; ${posMoney(failed.reduce((sum, result) => sum + result.allocation.amountCents, 0))} still owed` : ''}`,\n },\n ],\n createdAtMs: now,\n updatedAtMs: now,\n }\n transaction.create(storeReturnRef, storeReturn)\n if (shiftOpen && shiftRef && cashCents > 0) {\n const event: PosCashEvent = {\n id: returnRef.id,\n type: 'refund',\n amountCents: cashCents,\n reason: `Return ${orderLabel}`,\n by: cashier.cashierId,\n atMs: now,\n orderId,\n }\n const cashEvents = Array.isArray(shiftSnapshot?.get('cashEvents')) ? shiftSnapshot!.get('cashEvents') : []\n transaction.update(shiftRef, { cashEvents: [...cashEvents, event] })\n }\n })\n\n // Restock what came back to the register's location.\n let restockedUnits = 0\n if (restock) {\n restockedUnits = await restockReturn(\n firestore,\n staff.hostRef,\n order,\n picks,\n String(register.data['locationId'] ?? order['locationId'] ?? '') || undefined,\n orderId,\n now,\n ).catch((error) => {\n console.error('[pos-return] restock failed', orderId, error)\n return 0\n })\n }\n\n // The drawer opens for the cash being handed back.\n if (cashCents > 0) {\n await deps.printer.kickDrawer({\n hostId: staff.hostId,\n registerId,\n reason: 'cash_refund',\n causeId: returnRef.id,\n createdBy: cashier.cashierId,\n })\n }\n\n const payload = {\n returnId: returnRef.id,\n refundedCents,\n outstandingCents: failed.reduce((sum, result) => sum + result.allocation.amountCents, 0),\n partial: failed.length > 0,\n tenders: results.map((result) => ({\n method: result.allocation.method,\n label: posTenderLabel(tenderOf(result.allocation.paymentId) ?? { method: result.allocation.method }),\n amountCents: result.allocation.amountCents,\n status: result.status,\n ...(result.error ? { error: result.error } : {}),\n })),\n cashOutCents: cashCents,\n restockedUnits,\n shiftId: shiftIdForReturn,\n fullyRefunded,\n }\n await claim.record(200, payload)\n if (refundedCents > 0) {\n await deps.afterRefund({\n hostId: staff.hostId,\n orderId,\n email: order['customerEmail'] ?? null,\n refundCents: refundedCents,\n closedTheOrder,\n fullyRefunded,\n returnedProductIds: [\n ...new Set(\n picks\n .map((pick) => String((order.lineItems?.[pick.index] as { productId?: string } | undefined)?.productId ?? ''))\n .filter(Boolean),\n ),\n ],\n lineIndexes: picks.map((pick) => pick.index),\n fullLineIndexes: reserved.completedLines,\n returnId,\n storeReturn: storeReturn as unknown as CommerceModel.HostReturn,\n refundIds: results.flatMap((result) => (result.refundId ? [result.refundId] : [])),\n })\n }\n return { status: 200, body: payload }\n}\n\n/**\n * Units per order line that the store's OTHER returns — the online returns\n * flow (AGL-3611) — hold or already took back. The register's own returns are\n * left out: `returnedQuantities` on the order already counts them.\n */\nexport function unitsHeldByOnlineReturns(\n docs: ReadonlyArray<{ data(): FirebaseFirestore.DocumentData | undefined }>,\n): number[] {\n const held: number[] = []\n for (const doc of docs) {\n const entry = (doc.data() ?? {}) as CommerceModel.HostReturn\n if (entry.source === 'register' || !CommerceModel.returnHoldsUnits(entry)) continue\n for (const line of entry.lines ?? []) {\n const index = Number(line?.lineItemId)\n if (!Number.isInteger(index) || index < 0) continue\n held[index] = (held[index] ?? 0) + Math.max(0, Math.floor(Number(line?.quantity) || 0))\n }\n }\n return held\n}\n\n/** Whether a member is a workspace admin and this site's admin, asked now. */\nasync function memberIsPosManager(\n deps: PosOpsDeps,\n hostRef: FirebaseFirestore.DocumentReference,\n hostId: string,\n uid: string,\n): Promise<boolean> {\n const host = await hostRef.get()\n const role = (host.get('memberRoles') ?? {})[uid]\n return isPosManager(role, await deps.membership(uid, hostId))\n}\n\nclass ReturnRefusal extends Error {\n constructor(\n readonly status: number,\n message: string,\n ) {\n super(message)\n }\n}\n\n/**\n * Store credit back on the card it came off. A voided or frozen card takes\n * nothing: a void is a fraud or refund decision, and re-crediting it would\n * undo that decision by the back door.\n */\nasync function creditGiftCard(\n firestore: FirebaseFirestore.Firestore,\n hostRef: FirebaseFirestore.DocumentReference,\n code: string,\n amountCents: number,\n orderId: string,\n now: number,\n): Promise<void> {\n const id = String(code ?? '').trim()\n if (!id || id.includes('/') || id.length > 64) throw new ReturnRefusal(409, 'That gift card payment does not name its card.')\n const ref = hostRef.collection('giftCards').doc(id)\n await firestore.runTransaction(async (transaction) => {\n const card = await transaction.get(ref)\n if (!card.exists) throw new ReturnRefusal(409, 'That gift card no longer exists.')\n if (card.get('voidedAtMs') != null || card.get('frozenAtMs') != null) {\n throw new ReturnRefusal(409, 'That gift card is voided or frozen, so it cannot take a refund.')\n }\n transaction.update(ref, {\n balanceCents: Math.max(0, Math.round(Number(card.get('balanceCents') ?? 0))) + amountCents,\n lastCreditAtMs: now,\n lastCreditOrderId: orderId,\n })\n })\n}\n\n/** A room charge taken back: a negative line on the same stay's folio. */\nasync function reverseFolio(\n hostRef: FirebaseFirestore.DocumentReference,\n reservationId: string,\n amountCents: number,\n orderId: string,\n now: number,\n): Promise<void> {\n const id = posOpsCleanId(reservationId)\n if (!id) throw new ReturnRefusal(409, 'That room charge does not name its stay.')\n const ref = hostRef.collection('reservations').doc(id)\n const firestore = hostRef.firestore\n await firestore.runTransaction(async (transaction) => {\n const stay = await transaction.get(ref)\n if (!stay.exists) throw new ReturnRefusal(409, 'That stay no longer exists.')\n const folio = Array.isArray(stay.get('folio')) ? stay.get('folio') : []\n transaction.update(ref, {\n folio: [...folio, { orderId, amountCents: -amountCents, note: 'Return at the register', atMs: now }],\n })\n })\n}\n\n/**\n * The returned units back on the shelf, at the register's location, with an\n * adjustment row each so the stock history says why the count went up.\n * Only variants that track stock move.\n */\nasync function restockReturn(\n firestore: FirebaseFirestore.Firestore,\n hostRef: FirebaseFirestore.DocumentReference,\n order: PosReturnSource & Record<string, any>,\n picks: readonly PosReturnPick[],\n locationId: string | undefined,\n orderId: string,\n now: number,\n): Promise<number> {\n const byProduct = new Map<string, Array<{ variantId?: string; quantity: number }>>()\n for (const pick of picks) {\n const line = (order.lineItems ?? [])[pick.index] as Record<string, any> | undefined\n const productId = String(line?.['productId'] ?? '')\n if (!productId) continue\n byProduct.set(productId, [\n ...(byProduct.get(productId) ?? []),\n { ...(line?.['variantId'] ? { variantId: String(line['variantId']) } : {}), quantity: pick.quantity },\n ])\n }\n let units = 0\n for (const [productId, lines] of byProduct) {\n const ref = hostRef.collection('products').doc(productId)\n units += await firestore.runTransaction(async (transaction) => {\n const snapshot = await transaction.get(ref)\n if (!snapshot.exists) return 0\n const product = CommerceModel.liftLegacyProduct(snapshot.data() as any)\n let variants = product.variants\n const rows: Array<{ variantId: string; quantity: number }> = []\n for (const line of lines) {\n const variantId = line.variantId ?? product.variants[0]?.id\n const variant = variants.find((candidate) => candidate.id === variantId)\n if (!variantId || !variant || variant.inventory == null) continue\n variants = CommerceModel.adjustVariantInventory({ variants }, variantId, line.quantity, locationId)\n rows.push({ variantId, quantity: line.quantity })\n }\n if (!rows.length) return 0\n transaction.update(ref, {\n variants,\n ...CommerceModel.productStockFields({ ...product, variants }),\n updatedAtMs: now,\n })\n for (const row of rows) {\n transaction.create(hostRef.collection('inventoryAdjustments').doc(createResourceUid()), {\n productId,\n variantId: row.variantId,\n delta: row.quantity,\n reason: 'refund',\n orderId,\n ...(locationId ? { locationId } : {}),\n atMs: now,\n } satisfies CommerceModel.InventoryAdjustment)\n }\n return rows.reduce((sum, row) => sum + row.quantity, 0)\n })\n }\n return units\n}\n\nexport function createPosReturnHandler(\n deps: () => PosReturnDeps = defaultPosReturnDeps,\n): PluginApiHandler {\n return async (req, res) => {\n try {\n const outcome = await handlePosReturn(deps(), req)\n return res.status(outcome.status).json(outcome.body)\n } catch (error) {\n console.error('[pos-return] failed', error)\n return res.status(500).json({ error: 'The return could not be refunded' })\n }\n }\n}\n\nexport const posReturnHandler = createPosReturnHandler()\n"],"names":["claimAttempt","createResourceUid","nameSearchKey","recordPluginPersonRefund","reverseOrderConversion","CommerceModel","planPosReturn","posMoney","posRefundableByTender","posReturnedQuantities","posReturnLineValues","posTenderLabel","POS_STRIPE_TENDERS","splitPosRefund","ORDER_REFUNDED_EVENT","RETURN_REFUNDED_EVENT","raiseOrderEvent","applyGiftCardRiskToOrder","notifyOrderBuyer","decidePosRefundAuthority","authorizePosOps","defaultPosOpsDeps","posOpsBody","posOpsCleanId","posOpsIdempotencyKey","readPosRegister","isPosManager","resolvePosCashier","createStripeRefund","defaultPosReturnDeps","base","afterRefund","input","settle","label","work","error","console","orderId","hostRef","firestore","collection","doc","hostId","returnedProductIds","length","action","kind","reason","fullyRefunded","productIds","refId","email","amountCents","refundCents","closedTheSale","closedTheOrder","key","returnId","extra","refund","id","refundIds","lineItemIds","fullLineIndexes","full","return","status","storeReturn","lines","map","line","refundId","refundLineIndexes","lineIndexes","RETURNABLE","Set","returnSummary","raw","held","order","liftLegacyOrder","values","returned","number","formatOrderNumber","channel","createdAtMs","Number","customerEmail","customerName","totalCents","totals","refundedCents","returnable","has","String","lineItems","index","name","variantLabel","quantity","Math","max","round","valueCents","tenders","tender","method","refundableCents","findOrders","rawText","snapshot","text","trim","slice","orders","digits","replace","test","where","limit","get","docs","data","includes","orderBy","exists","parsePicks","Array","isArray","entry","parseSplit","paymentId","handlePosReturn","deps","req","body","register","gate","staff","found","Promise","all","unitsHeldByOnlineReturns","at","registerId","ref","idempotencyKey","picks","requestedSplit","restock","reasonCode","RETURN_REASONS","orderRef","storeReturns","orderDisputeBlocksRefund","plan","split","cashier","cashierIsManager","cashierId","uid","isManager","memberIsPosManager","authority","limitCents","settings","refundLimitCents","managerAssertion","needsCash","allocations","some","needsStripe","openShiftId","requireOpenShift","process","env","STRIPE_SECRET_KEY","claimed","scopeId","orgId","busyMessage","replay","claim","reserved","runTransaction","transaction","fresh","ReturnRefusal","freshPlan","freshSplit","prior","returnedQuantities","posPaymentRefunds","update","lineCents","completedLines","release","message","tenderOf","find","ordered","sort","a","b","results","allocation","anyMoved","result","paymentIntentId","stripeKey","metadata","fetch","push","creditGiftCard","giftCardId","now","reverseFolio","reservationId","catch","rollback","failed","filter","reduce","sum","cashCents","returnRef","storeReturnRef","orderLabel","pick","shiftIdForReturn","freshRegister","shiftId","shiftRef","shiftSnapshot","shiftOpen","Boolean","failedCents","orderRefunded","canTransitionOrder","Object","entries","count","tenderWords","join","units","refundedLineItemIds","timeline","appendOrderEvent","approvedBy","record","orderNumber","restocked","locationId","atMs","create","restockedLines","lineItemId","registerLocationId","undefined","requestedBy","source","merchantNote","refundedAtMs","event","detail","updatedAtMs","type","by","cashEvents","restockedUnits","restockReturn","printer","kickDrawer","causeId","createdBy","payload","outstandingCents","partial","cashOutCents","productId","flatMap","returnHoldsUnits","isInteger","floor","host","role","membership","Error","code","card","balanceCents","lastCreditAtMs","lastCreditOrderId","stay","folio","note","byProduct","Map","set","variantId","product","liftLegacyProduct","variants","rows","variant","candidate","inventory","adjustVariantInventory","productStockFields","row","delta","createPosReturnHandler","res","outcome","json","posReturnHandler"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,YAAY,QAAsD,sBAAqB;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AC4M,KAAKpQ,MAAM,EAAE,OAAO;YACzB8I,YAAYQ,MAAM,CAAChD,KAAK;gBACtB6J;eACG3S,cAAciT,kBAAkB,CAAC,aAAKR;gBAASE;;gBAClDrC,aAAalD;;YAEf,KAAK,MAAM8F,OAAON,KAAM;gBACtBtH,YAAYqE,MAAM,CAACzN,QAAQE,UAAU,CAAC,wBAAwBC,GAAG,CAACzC,sBAAsB;oBACtFwR;oBACAoB,WAAWU,IAAIV,SAAS;oBACxBW,OAAOD,IAAIlN,QAAQ;oBACnBrD,QAAQ;oBACRV;mBACIwN,aAAa;oBAAEA;gBAAW,IAAI,CAAC;oBACnCC,MAAMtC;;YAEV;YACA,OAAOwF,KAAKjF,MAAM,CAAC,CAACC,KAAKsF,MAAQtF,MAAMsF,IAAIlN,QAAQ,EAAE;QACvD;IACF;IACA,OAAOiJ;AACT;AAEA,OAAO,SAASmE,uBACdlL,OAA4B1G,oBAAoB;IAEhD,OAAO,OAAO2G,KAAKkL;QACjB,IAAI;YACF,MAAMC,UAAU,MAAMrL,gBAAgBC,QAAQC;YAC9C,OAAOkL,IAAIvP,MAAM,CAACwP,QAAQxP,MAAM,EAAEyP,IAAI,CAACD,QAAQlL,IAAI;QACrD,EAAE,OAAOrG,OAAO;YACdC,QAAQD,KAAK,CAAC,uBAAuBA;YACrC,OAAOsR,IAAIvP,MAAM,CAAC,KAAKyP,IAAI,CAAC;gBAAExR,OAAO;YAAmC;QAC1E;IACF;AACF;AAEA,OAAO,MAAMyR,mBAAmBJ,yBAAwB"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import { type PosOpsDeps } from './pos-ops-gate';
|
|
18
|
+
export interface PosSaleStampInput {
|
|
19
|
+
hostId: string;
|
|
20
|
+
hostRef: FirebaseFirestore.DocumentReference;
|
|
21
|
+
registerId: string;
|
|
22
|
+
/** The register's `openShiftId`, from the read the sale already made. */
|
|
23
|
+
openShiftId: unknown;
|
|
24
|
+
/** Who the sale route's own gate admitted. */
|
|
25
|
+
signedInUid: string;
|
|
26
|
+
/** The sale request's body. */
|
|
27
|
+
body: Record<string, any>;
|
|
28
|
+
/** The site's merged commerce config. */
|
|
29
|
+
config: Record<string, unknown> | null | undefined;
|
|
30
|
+
deps?: PosOpsDeps;
|
|
31
|
+
}
|
|
32
|
+
export interface PosSaleStamp {
|
|
33
|
+
cashierId: string;
|
|
34
|
+
/** The fields the order document takes, besides `cashierId`. */
|
|
35
|
+
fields: {
|
|
36
|
+
shiftId?: string;
|
|
37
|
+
customerName?: string;
|
|
38
|
+
customerRecord?: {
|
|
39
|
+
kind: string;
|
|
40
|
+
id: string;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export type PosSaleStampOutcome = {
|
|
45
|
+
ok: true;
|
|
46
|
+
stamp: PosSaleStamp;
|
|
47
|
+
} | {
|
|
48
|
+
ok: false;
|
|
49
|
+
status: number;
|
|
50
|
+
error: string;
|
|
51
|
+
};
|
|
52
|
+
/** The attached customer, bounded; nothing when the register sent none. */
|
|
53
|
+
export declare function posSaleCustomerFields(raw: unknown): PosSaleStamp['fields'];
|
|
54
|
+
export declare function posSaleStamp(input: PosSaleStampInput): Promise<PosSaleStampOutcome>;
|
|
55
|
+
/**
|
|
56
|
+
* Who takes a payment toward an open sale: the member a cashier assertion
|
|
57
|
+
* names, checked against the SALE's register (an assertion minted at one
|
|
58
|
+
* till does not ring at another), or the member signed in on the device.
|
|
59
|
+
*/
|
|
60
|
+
export declare function posPaymentCashierId(input: {
|
|
61
|
+
hostId: string;
|
|
62
|
+
orderId: string;
|
|
63
|
+
signedInUid: string;
|
|
64
|
+
assertion: unknown;
|
|
65
|
+
deps?: PosOpsDeps;
|
|
66
|
+
}): Promise<string>;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright 2026 Aglyn LLC
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/ import { posOpsSettings } from "../pos-ops-config.js";
|
|
18
|
+
import { defaultPosOpsDeps, posOpsCleanId, resolvePosCashier } from "./pos-ops-gate.js";
|
|
19
|
+
const bounded = (value, max)=>typeof value === 'string' ? value.trim().slice(0, max) : '';
|
|
20
|
+
/** The attached customer, bounded; nothing when the register sent none. */ export function posSaleCustomerFields(raw) {
|
|
21
|
+
if (!raw || typeof raw !== 'object') return {};
|
|
22
|
+
const customer = raw;
|
|
23
|
+
const name = bounded(customer['name'], 200);
|
|
24
|
+
const kind = bounded(customer['kind'], 40);
|
|
25
|
+
const id = posOpsCleanId(customer['id']);
|
|
26
|
+
return _extends({}, name ? {
|
|
27
|
+
customerName: name
|
|
28
|
+
} : {}, kind && kind !== 'none' && id ? {
|
|
29
|
+
customerRecord: {
|
|
30
|
+
kind,
|
|
31
|
+
id
|
|
32
|
+
}
|
|
33
|
+
} : {});
|
|
34
|
+
}
|
|
35
|
+
export async function posSaleStamp(input) {
|
|
36
|
+
var _input_deps;
|
|
37
|
+
const shiftId = posOpsCleanId(input.openShiftId);
|
|
38
|
+
if (!shiftId && posOpsSettings(input.config).requireOpenShift) {
|
|
39
|
+
return {
|
|
40
|
+
ok: false,
|
|
41
|
+
status: 409,
|
|
42
|
+
error: 'Open a shift on this register before ringing a sale.'
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
const assertion = input.body['cashierAssertion'];
|
|
46
|
+
const cashier = assertion ? await resolvePosCashier((_input_deps = input.deps) != null ? _input_deps : defaultPosOpsDeps(), {
|
|
47
|
+
uid: input.signedInUid,
|
|
48
|
+
hostId: input.hostId,
|
|
49
|
+
hostRef: input.hostRef
|
|
50
|
+
}, input.registerId, assertion) : {
|
|
51
|
+
cashierId: input.signedInUid
|
|
52
|
+
};
|
|
53
|
+
return {
|
|
54
|
+
ok: true,
|
|
55
|
+
stamp: {
|
|
56
|
+
cashierId: cashier.cashierId,
|
|
57
|
+
fields: _extends({}, shiftId ? {
|
|
58
|
+
shiftId
|
|
59
|
+
} : {}, posSaleCustomerFields(input.body['customer']))
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Who takes a payment toward an open sale: the member a cashier assertion
|
|
65
|
+
* names, checked against the SALE's register (an assertion minted at one
|
|
66
|
+
* till does not ring at another), or the member signed in on the device.
|
|
67
|
+
*/ export async function posPaymentCashierId(input) {
|
|
68
|
+
var _input_deps;
|
|
69
|
+
const orderId = posOpsCleanId(input.orderId);
|
|
70
|
+
if (!input.assertion || !orderId) return input.signedInUid;
|
|
71
|
+
const deps = (_input_deps = input.deps) != null ? _input_deps : defaultPosOpsDeps();
|
|
72
|
+
const hostRef = deps.firestore().collection('hosts').doc(input.hostId);
|
|
73
|
+
const order = await hostRef.collection('orders').doc(orderId).get();
|
|
74
|
+
const registerId = posOpsCleanId(order.get('registerId'));
|
|
75
|
+
if (!registerId) return input.signedInUid;
|
|
76
|
+
const { cashierId } = await resolvePosCashier(deps, {
|
|
77
|
+
uid: input.signedInUid,
|
|
78
|
+
hostId: input.hostId,
|
|
79
|
+
hostRef
|
|
80
|
+
}, registerId, input.assertion);
|
|
81
|
+
return cashierId;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
//# sourceMappingURL=pos-sale-stamp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/server/pos-sale-stamp.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { posOpsSettings } from '../pos-ops-config'\nimport { defaultPosOpsDeps, posOpsCleanId, resolvePosCashier, type PosOpsDeps } from './pos-ops-gate'\n\n/*==========================================\n * WHAT EVERY REGISTER SALE CARRIES (AGL-3609), stamped where the sale is\n * written:\n *\n * cashierId the member a PIN switched in, re-checked against their\n * role now, or the member signed in on the device\n * shiftId the register's open shift, so the X and Z reports count\n * the sale — and a refusal when the site requires a shift\n * and none is open\n * customerRecord the person the cashier attached from the lookup, with\n * the name the receipt and the order show. Never their\n * phone: `customerPhone` is the number a buyer gave for\n * order texts, and a lookup is not that\n *=========================================*/\n\nexport interface PosSaleStampInput {\n hostId: string\n hostRef: FirebaseFirestore.DocumentReference\n registerId: string\n /** The register's `openShiftId`, from the read the sale already made. */\n openShiftId: unknown\n /** Who the sale route's own gate admitted. */\n signedInUid: string\n /** The sale request's body. */\n body: Record<string, any>\n /** The site's merged commerce config. */\n config: Record<string, unknown> | null | undefined\n deps?: PosOpsDeps\n}\n\nexport interface PosSaleStamp {\n cashierId: string\n /** The fields the order document takes, besides `cashierId`. */\n fields: {\n shiftId?: string\n customerName?: string\n customerRecord?: { kind: string; id: string }\n }\n}\n\nexport type PosSaleStampOutcome =\n | { ok: true; stamp: PosSaleStamp }\n | { ok: false; status: number; error: string }\n\nconst bounded = (value: unknown, max: number): string =>\n typeof value === 'string' ? value.trim().slice(0, max) : ''\n\n/** The attached customer, bounded; nothing when the register sent none. */\nexport function posSaleCustomerFields(raw: unknown): PosSaleStamp['fields'] {\n if (!raw || typeof raw !== 'object') return {}\n const customer = raw as Record<string, unknown>\n const name = bounded(customer['name'], 200)\n const kind = bounded(customer['kind'], 40)\n const id = posOpsCleanId(customer['id'])\n return {\n ...(name ? { customerName: name } : {}),\n ...(kind && kind !== 'none' && id ? { customerRecord: { kind, id } } : {}),\n }\n}\n\nexport async function posSaleStamp(input: PosSaleStampInput): Promise<PosSaleStampOutcome> {\n const shiftId = posOpsCleanId(input.openShiftId)\n if (!shiftId && posOpsSettings(input.config).requireOpenShift) {\n return { ok: false, status: 409, error: 'Open a shift on this register before ringing a sale.' }\n }\n const assertion = input.body['cashierAssertion']\n const cashier = assertion\n ? await resolvePosCashier(\n input.deps ?? defaultPosOpsDeps(),\n { uid: input.signedInUid, hostId: input.hostId, hostRef: input.hostRef },\n input.registerId,\n assertion,\n )\n : { cashierId: input.signedInUid }\n return {\n ok: true,\n stamp: {\n cashierId: cashier.cashierId,\n fields: {\n ...(shiftId ? { shiftId } : {}),\n ...posSaleCustomerFields(input.body['customer']),\n },\n },\n }\n}\n\n/**\n * Who takes a payment toward an open sale: the member a cashier assertion\n * names, checked against the SALE's register (an assertion minted at one\n * till does not ring at another), or the member signed in on the device.\n */\nexport async function posPaymentCashierId(input: {\n hostId: string\n orderId: string\n signedInUid: string\n assertion: unknown\n deps?: PosOpsDeps\n}): Promise<string> {\n const orderId = posOpsCleanId(input.orderId)\n if (!input.assertion || !orderId) return input.signedInUid\n const deps = input.deps ?? defaultPosOpsDeps()\n const hostRef = deps.firestore().collection('hosts').doc(input.hostId)\n const order = await hostRef.collection('orders').doc(orderId).get()\n const registerId = posOpsCleanId(order.get('registerId'))\n if (!registerId) return input.signedInUid\n const { cashierId } = await resolvePosCashier(\n deps,\n { uid: input.signedInUid, hostId: input.hostId, hostRef },\n registerId,\n input.assertion,\n )\n return cashierId\n}\n"],"names":["posOpsSettings","defaultPosOpsDeps","posOpsCleanId","resolvePosCashier","bounded","value","max","trim","slice","posSaleCustomerFields","raw","customer","name","kind","id","customerName","customerRecord","posSaleStamp","input","shiftId","openShiftId","config","requireOpenShift","ok","status","error","assertion","body","cashier","deps","uid","signedInUid","hostId","hostRef","registerId","cashierId","stamp","fields","posPaymentCashierId","orderId","firestore","collection","doc","order","get"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,cAAc,QAAQ,uBAAmB;AAClD,SAASC,iBAAiB,EAAEC,aAAa,EAAEC,iBAAiB,QAAyB,oBAAgB;AA8CrG,MAAMC,UAAU,CAACC,OAAgBC,MAC/B,OAAOD,UAAU,WAAWA,MAAME,IAAI,GAAGC,KAAK,CAAC,GAAGF,OAAO;AAE3D,yEAAyE,GACzE,OAAO,SAASG,sBAAsBC,GAAY;IAChD,IAAI,CAACA,OAAO,OAAOA,QAAQ,UAAU,OAAO,CAAC;IAC7C,MAAMC,WAAWD;IACjB,MAAME,OAAOR,QAAQO,QAAQ,CAAC,OAAO,EAAE;IACvC,MAAME,OAAOT,QAAQO,QAAQ,CAAC,OAAO,EAAE;IACvC,MAAMG,KAAKZ,cAAcS,QAAQ,CAAC,KAAK;IACvC,OAAO,aACDC,OAAO;QAAEG,cAAcH;IAAK,IAAI,CAAC,GAC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AAC;IAC3C,IAAI,CAACV,YAAY,OAAOhB,MAAMa,WAAW;IACzC,MAAM,EAAEI,SAAS,EAAE,GAAG,MAAMhC,kBAC1B0B,MACA;QAAEC,KAAKZ,MAAMa,WAAW;QAAEC,QAAQd,MAAMc,MAAM;QAAEC;IAAQ,GACxDC,YACAhB,MAAMQ,SAAS;IAEjB,OAAOS;AACT"}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import * as CommerceModel from '../model';
|
|
18
|
+
export type PosLiftedOrder = CommerceModel.HostOrder & {
|
|
19
|
+
$id: string;
|
|
20
|
+
/** The sale's platform take, before any card processing (AGL-2111). */
|
|
21
|
+
posTakeFeeCents?: number;
|
|
22
|
+
/** The org the invoiced part of the take accrues to. */
|
|
23
|
+
posFeeOrgId?: string;
|
|
24
|
+
/** The promotion slot this sale holds until it completes (AGL-305). */
|
|
25
|
+
discountId?: string;
|
|
26
|
+
discountHoldKey?: string;
|
|
27
|
+
paymentIntentIds?: string[];
|
|
28
|
+
reservationId?: string;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* A payment's id, derived from the register's attempt key so a retried tap
|
|
32
|
+
* finds the payment it already started instead of starting a second one.
|
|
33
|
+
*/
|
|
34
|
+
export declare function posPaymentId(orderId: string, attemptKey: string): string;
|
|
35
|
+
/** What one ledger change decided. */
|
|
36
|
+
export type PosPaymentStep = {
|
|
37
|
+
kind: 'refuse';
|
|
38
|
+
status: number;
|
|
39
|
+
error: string;
|
|
40
|
+
}
|
|
41
|
+
/** Nothing to change: the payment is already in the state asked for. */
|
|
42
|
+
| {
|
|
43
|
+
kind: 'keep';
|
|
44
|
+
} | {
|
|
45
|
+
kind: 'put';
|
|
46
|
+
payment: CommerceModel.OrderPayment;
|
|
47
|
+
/** A timeline line for the order, when the change is worth one. */
|
|
48
|
+
event?: {
|
|
49
|
+
event: string;
|
|
50
|
+
detail?: string;
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
export type PosPaymentOutcome = {
|
|
54
|
+
ok: false;
|
|
55
|
+
status: number;
|
|
56
|
+
error: string;
|
|
57
|
+
} | {
|
|
58
|
+
ok: true;
|
|
59
|
+
order: PosLiftedOrder;
|
|
60
|
+
payment: CommerceModel.OrderPayment | null;
|
|
61
|
+
/** True only on the call whose change completed the sale. */
|
|
62
|
+
completed: boolean;
|
|
63
|
+
changed: boolean;
|
|
64
|
+
};
|
|
65
|
+
/** The open sale's ledger, as the register reads it back after any change. */
|
|
66
|
+
export declare function posSaleSummary(order: PosLiftedOrder): {
|
|
67
|
+
orderId: string;
|
|
68
|
+
status: CommerceModel.OrderStatus;
|
|
69
|
+
totalCents: number;
|
|
70
|
+
paidCents: number;
|
|
71
|
+
dueCents: number;
|
|
72
|
+
tenderableCents: number;
|
|
73
|
+
tipCents: number;
|
|
74
|
+
payments: {
|
|
75
|
+
livemode?: boolean;
|
|
76
|
+
failureMessage?: string;
|
|
77
|
+
readerId?: string;
|
|
78
|
+
checkoutUrl?: string;
|
|
79
|
+
changeCents?: number;
|
|
80
|
+
last4?: string;
|
|
81
|
+
cardBrand?: string;
|
|
82
|
+
status: CommerceModel.OrderPaymentStatus;
|
|
83
|
+
tipCents?: number;
|
|
84
|
+
id: string;
|
|
85
|
+
method: CommerceModel.OrderPaymentMethod;
|
|
86
|
+
amountCents: number;
|
|
87
|
+
}[];
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* The fields that complete a sale, when its settled payments now cover the
|
|
91
|
+
* total; null when the balance is still open or the sale is not pending.
|
|
92
|
+
*
|
|
93
|
+
* Pure, so the spec can hold the arithmetic: the fee is every card payment's
|
|
94
|
+
* own `application_fee_amount` plus the take the cards did not carry, the tip
|
|
95
|
+
* is summed beside the total and never inside it.
|
|
96
|
+
*/
|
|
97
|
+
export declare function posCompletionPatch(order: PosLiftedOrder, payments: CommerceModel.OrderPayment[], nowMs: number): {
|
|
98
|
+
patch: Record<string, unknown>;
|
|
99
|
+
invoiceTakeCents: number;
|
|
100
|
+
} | null;
|
|
101
|
+
/**
|
|
102
|
+
* The ONE writer of a sale's ledger. Runs `prepare` (extra reads) and
|
|
103
|
+
* `decide` inside one transaction on the order, writes the payment, and
|
|
104
|
+
* completes the sale in the same commit when the balance reaches zero.
|
|
105
|
+
*/
|
|
106
|
+
export declare function applyPosPayment<C = undefined>(options: {
|
|
107
|
+
hostId: string;
|
|
108
|
+
orderId: string;
|
|
109
|
+
paymentId: string;
|
|
110
|
+
/** Reads beyond the order (a gift card, a stay), before any write. */
|
|
111
|
+
prepare?: (transaction: any) => Promise<C>;
|
|
112
|
+
decide: (sale: {
|
|
113
|
+
order: PosLiftedOrder;
|
|
114
|
+
payments: CommerceModel.OrderPayment[];
|
|
115
|
+
existing: CommerceModel.OrderPayment | undefined;
|
|
116
|
+
context: C;
|
|
117
|
+
}) => PosPaymentStep;
|
|
118
|
+
/** Writes beyond the order, in the same transaction, for a `put`. */
|
|
119
|
+
write?: (transaction: any, context: C, payment: CommerceModel.OrderPayment, previous: CommerceModel.OrderPayment | undefined) => void;
|
|
120
|
+
nowMs?: number;
|
|
121
|
+
}): Promise<PosPaymentOutcome>;
|
|
122
|
+
export interface PosSaleCompletedEvent {
|
|
123
|
+
hostId: string;
|
|
124
|
+
orderId: string;
|
|
125
|
+
order: CommerceModel.HostOrder;
|
|
126
|
+
}
|
|
127
|
+
export type PosSaleCompletedListener = (event: PosSaleCompletedEvent) => void | Promise<void>;
|
|
128
|
+
/** Subscribes to completed register sales; returns the unsubscribe. */
|
|
129
|
+
export declare function onPosSaleCompleted(listener: PosSaleCompletedListener): () => void;
|
|
130
|
+
/**
|
|
131
|
+
* Tells every listener a register sale completed. Awaited, and never throws:
|
|
132
|
+
* the money is already taken, so a listener's failure is logged, not
|
|
133
|
+
* returned to a cashier who would ring the sale again.
|
|
134
|
+
*/
|
|
135
|
+
export declare function notifyPosSaleCompleted(event: PosSaleCompletedEvent): Promise<void>;
|
|
136
|
+
/** Reads the sale as it stands, for the register's status polls. */
|
|
137
|
+
export declare function readPosSale(hostId: string, orderId: string): Promise<PosLiftedOrder | null>;
|
|
138
|
+
/**
|
|
139
|
+
* Everything that follows a sale being paid, run once by the call whose
|
|
140
|
+
* commit completed it. Each step is guarded on its own and none can undo the
|
|
141
|
+
* sale: the money is taken, so a failure here is logged and said on the order
|
|
142
|
+
* rather than thrown back at a cashier who would ring it again.
|
|
143
|
+
*/
|
|
144
|
+
export declare function completePosSale(hostId: string, order: PosLiftedOrder): Promise<void>;
|
|
145
|
+
/**
|
|
146
|
+
* Sends a receipt the customer (or the cashier for them) explicitly asked
|
|
147
|
+
* for, to the address or number they gave (AGL-3607, AGL-3608).
|
|
148
|
+
*
|
|
149
|
+
* It goes through the buyer-notification door first, so the order's
|
|
150
|
+
* once-per-channel marker is claimed and a completion that races this call
|
|
151
|
+
* cannot send a second copy. The door can skip it, though, for reasons that
|
|
152
|
+
* do not apply to a request made at the counter: the store switched
|
|
153
|
+
* automatic receipts or texts off, a receipt already went out on that
|
|
154
|
+
* channel to an earlier address, or the door would use the email the order
|
|
155
|
+
* was opened with rather than the one just typed. In each of those cases the
|
|
156
|
+
* receipt is sent explicitly, as the order dialog's "Resend receipt" does.
|
|
157
|
+
*/
|
|
158
|
+
export declare function deliverChosenPosReceipt(ref: {
|
|
159
|
+
hostId: string;
|
|
160
|
+
orderId: string;
|
|
161
|
+
}, input: {
|
|
162
|
+
channel: 'email' | 'sms';
|
|
163
|
+
to: string;
|
|
164
|
+
orderEmail?: string;
|
|
165
|
+
}): Promise<'sent' | 'failed' | 'not_configured'>;
|
|
166
|
+
/**
|
|
167
|
+
* Hands back a promotion slot an open sale was holding, when the sale is
|
|
168
|
+
* voided rather than paid.
|
|
169
|
+
*/
|
|
170
|
+
export declare function releasePosSaleDiscount(hostId: string, order: PosLiftedOrder): Promise<void>;
|