How we created a flexible way to view Square Cash payments offline.
Written by Alan Paulin.
When building version 2.9 of the Square Cash app, we ran across an interesting challenge. The app was fetching payment objects from our server that needed to be displayed to the user. This basically involved choosing a template for each payment and formatting the data. For simplicity, let’s say that the data included a date, an amount, and recipient name, and it needed to produce a displayable string like: “You sent $20 to Erin Hills at 3:00 pm.”
We first considered baking the logic and templates into the app, but that would have resulted in an inflexible system where we’d need to launch a new version of the app to pick up a change. Old versions would be stuck presenting payments incorrectly, and the logic would need to be duplicated in each supported platform (iOS and Android). Our engineering velocity would diminish tremendously.
For a long time, we solved this issue by having the server return fully presented data rather than raw data. This achieved flexibility but at the price of some big drawbacks. The most significant issue was that the app needed a network connection and needed to constantly ask for the presented view of a payment (since the presented data is time sensitive). This resulted in excessive data usage and the lag could introduce staleness. As we worked towards the ability to view payments offline, we knew this approach was no longer viable.
recipient_name: “Erin Hills”
date : “2016-01-19T15:00:00Z”
description: “You sent $20 to Erin Hills at 3:00 pm”
description: “You sent $20 to Erin Hills yesterday”
description: “You donated $20 to Wikipedia yesterday. No goods or services were provided in exchange for this contribution.”