Repository navigation
feat: console screens for promotions, promo codes, segments and campaigns - #106
Merged
Merged
Conversation
Android pushes never worked with store-level FCM credentials and some iOS devices were rejected, because of several stacked defects: - configureFcm put the service account JSON into credentials.private_key, so no valid Firebase client was ever built from a store channel - FcmChannel required the platform-wide Firebase project to be configured - credentials were always resolved from the store, never the network app - one APNs environment per channel rejected sandbox/dev build tokens - registerDevice never reassigned a token to the latest customer and did not normalize platform casing - mail/database errors ran before push and stopped it; failures and dead tokens were never handled or logged Introduce Push\StorefrontPushChannel with isolated Firebase/APNs clients, network-first credential resolution with wrong-app and wrong-environment retries, dead token pruning, and high priority payloads. Order notifications share a StorefrontOrderNotification base class. Add a customers/unregister-device endpoint and an admin test push action.
Codecov requires full patch coverage. Cover the FCM and APNs transport send paths, PushMessage setters, APNs environment short-circuit, explicit push routes, and pruning/logging failure handling. Read device attributes with data_get so devices returned by a custom push route do not need to be Eloquent models, and drop two unreachable branches.
Storefront order notifications were already stored in the core
notifications table, but customers had no way to read them. Add
storefront/v1/notifications endpoints for the authenticated customer to
list (filter by unread/type, limit/offset), count unread, read, mark as
read, mark all as read and delete their notifications, scoped to the
storefront app (store, or network and its member stores).
Add customer notification preferences (order update pushes, promotions)
stored on the contact meta and honored by the notifications, and
broadcast new notifications in realtime on contact.{uuid} through a
broadcast channel that never fails the send.
…asts Also drop null values from inbox item data, and read notification data through the model's array cast.
…ration Add promotions owned by a store or network: automatic or code based percentage, fixed amount, free delivery and buy X get Y discounts, with product/category/store targeting, minimum subtotal and item conditions, first order only, date ranges and weekly schedule windows, usage limits (total, per customer, per code), budgets, maximum discounts, stacking and priorities. Checkout prices the cart's promotions when a checkout is created, stores them on the checkout options and reserves each use under a row lock, so the amount charged (cash, Stripe, QPay) always matches the discount shown. Capture records a discount transaction item and order meta and redeems the reservations; multi-store orders split the discount per store. Stale reservations are released by a scheduled command. Cart endpoints apply, remove and preview codes; the public API lists the storefront's live deals; the console API manages promotions and generates codes.
…campaigns # Conflicts: # server/src/routes.php
Customer segments are rule based audiences of a store's or network's customers (order count bounds, ordered or lapsed within N days, joined within N days, minimum spend, reachable by push, explicit customers). Campaigns send a title/body with an optional image and deep link to a segment (or explicit recipients, or everyone) by push and/or inbox, now or at a scheduled time. storefront:dispatch-campaigns claims due campaigns atomically and queues delivery in batches; customers who turned promotions off are skipped. Promotions can be announced with a campaign that goes out when the promotion starts, and announcements for promotions that stopped running are canceled. The console API manages segments (with live audience previews) and campaigns (send now, cancel, audience count). The existing promotional push action now sends a tracked campaign.
…ampaigns Promotions now has Promotions, Campaigns, Segments and Push Notifications tabs (and sidebar entries). Promotions: list with type, trigger, status, schedule, redemptions and discount given; a form for discounts, conditions, targeting, limits and stacking; activate/pause/end; promo code generation and management; and announcing a promotion to a segment. Segments: rule builder with a live count of matching customers. Campaigns: message, audience, channels and deep link, saved as a draft, sent now or scheduled, with send and cancel actions.
after:starts_at failed validation whenever starts_at was empty.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## release/v0.4.22 #106 +/- ##
=====================================================
Coverage 100.00% 100.00%
- Complexity 1772 2281 +509
=====================================================
Files 135 182 +47
Lines 7778 9070 +1292
=====================================================
+ Hits 7778 9070 +1292
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Console screens for the promotions work. The Storefront Promotions section (sidebar and tabs) now has Promotions, Campaigns, Segments and the existing Push Notifications.
Promotions
POST promotions/{id}/announce.Campaigns
Segments
Plumbing
promotion,promotion-code,customer-segmentandcampaign.storefront.promotions.*. Other locales fall back and still need translating.Related Issue
Part of the promotions / notifications work. No tracking issue.
Type of Change
Implementation Notes
Layout::SectionwithTable, row dropdown actions, andmodalsManagerforms. Monetary fields useMoneyInput(minor units, same as the API) and dates useDateTimeInput.applies_toand reloads the selected products and categories when it opens.Validation
Not clicked through in a browser. The local console runs the published engine package, not this checkout. I did run the API behind these screens against a local MySQL database:
Temporary rows were cleaned up afterwards. A manual pass in the console is still needed before merging.
Documentation Impact
fleetbase/fleetbase.ioAPI Reference Impact
fleetbase/postmanDocumentation Notes
fleetbase.io, Storefront → Promotions: user guide for promotions, promo codes, segments and campaigns.
Risk
UI only. The promotions route's index is now the promotions list, and Push Notifications moved to
promotions/push-notifications, so existing sidebar and tab links are updated.Screenshots / Recordings
Not captured (see Validation).