← Writing

Shared carts: you pick, a friend pays.

Designing a shared cart link: a snapshot instead of a live cart, an address the payer can't change, and a phone number the payer never sees.

Sakshyam Baral··4 min readproductdesignsecurity

Shared carts in Laayo work like this. You fill a cart, tap Share in the cart header, and send the link to someone, usually on WhatsApp. They open it and see a sheet: who shared it, the restaurant, each dish with its price, the item total and where it will be delivered. They tap "View cart and pay", pay, and the food comes to you.

It is a small feature with a surprising number of decisions in it.

A snapshot, not a live cart

The link points to a snapshot taken when you share: the restaurant, every cart line (item, quantity, options, add-ons), the delivery address you picked, the zone and the item total. It expires after a day.

I could have linked to the live cart, so that edits after sharing would show up. I didn't. The person paying should pay for what they saw, and a cart that can change while a friend is on the payment screen is a good way to start an argument between friends.

When the friend opens the link, the server rebuilds the lines against the live menu:

  • sold-out dishes show greyed out as "Not available", and the rest are added
  • a closed restaurant shows as closed, with the button disabled
  • an expired or already ordered link shows a small sheet that says so and offers to open the restaurant
  • if the sharer opens their own link, it simply opens their own cart
  • if the friend already has a cart from another restaurant, they are asked "Replace your cart?" first

The rebuild reuses the restore code we already had for agent checkout links, so options, add-ons and availability are checked the same way everywhere.

What the server overrides

In shared mode, the app shows the sharer's address and doesn't let the payer change it. But the app is not the authority. When an order is placed with a share code, the server:

  • replaces the delivery address with the snapshot address, whatever the app sent
  • sets the contact name and number to the sharer's, so the rider calls the person who will receive the food
  • accepts online payment only and rejects cash on delivery with its own error code, the same rule as our gift orders where you send food to someone else
  • links the order to the share and the share to the order in the same transaction, so one link can't produce two orders

After the commit, the sharer gets a push saying their friend is paying, with a live tracking link.

The newer Go endpoint for placing orders doesn't implement shared carts yet. Laayo is moving from Laravel to Go route by route, and the Go handler hands the request to the Laravel one whenever a share code is present. In that kind of migration, every feature the new code doesn't know about needs an explicit fallback like this, not an assumption.

Privacy is a list of read paths

The payer must never see the sharer's phone number. The preview endpoint, which works without signing in, returns names, dishes, prices and the address text, and no phone number or coordinates.

The harder part comes after the order exists. The order belongs to the payer, so every customer-facing view of an order (tracking, running orders, order history, the order card inside chat) would show the delivery contact. Each of those views now blanks the contact number when the order came from a shared cart. Riders, restaurants and staff read the order directly and still see it, because they need to call.

"Never show X to Y" turned out not to be one check. It is a list of every place Y can read the data. During a migration with two backends, some of those reads are served by one and some by the other, so I went through the customer order reads in both the Laravel app and the Go service before the feature reached customers.

Codes people can read out loud

The link is the existing cart URL with a share parameter. That path was already registered as an app link on both platforms for agent checkout links, so no new universal link or app link configuration was needed.

const alphabet = "ABCDEFGHJKMNPQRSTUVWXYZ23456789" // no I, L, O, 0 or 1
 
func newCode() (string, error) {
	b := make([]byte, 8)
	for i := range b {
		n, err := rand.Int(rand.Reader, big.NewInt(int64(len(alphabet))))
		if err != nil {
			return "", err
		}
		b[i] = alphabet[n.Int64()]
	}
	return string(b), nil
}
const alphabet = "ABCDEFGHJKMNPQRSTUVWXYZ23456789" // no I, L, O, 0 or 1
 
func newCode() (string, error) {
	b := make([]byte, 8)
	for i := range b {
		n, err := rand.Int(rand.Reader, big.NewInt(int64(len(alphabet))))
		if err != nil {
			return "", err
		}
		b[i] = alphabet[n.Int64()]
	}
	return string(b), nil
}

Eight characters from a 31-character alphabet gives about 850 billion possible codes, and creating, previewing and opening links are all rate limited. Dropping the characters that look alike means a code can be read over the phone without anyone asking whether that was an O or a zero. Codes are also normalised and checked against the same alphabet before any database lookup, so junk input never reaches a query.

On the app side, the share sheet over Home and the shared-mode cart are built natively on both platforms from one written spec, with the same strings in English and Nepali.

Get new posts by email

One email when something new goes up. No tracking pixels, unsubscribe in one click.