Skip to content

App Spotlight: IVU Loto App

We've previously highlighted some of our customer's Parse powered apps. Today, I'd like to talk about one of my own apps: IVU Loto App. It's a results tracker for the sales tax lottery that takes place semiweekly in Puerto Rico, and it is using Parse as its backend.

A couple of years ago, the Puerto Rico government launched a sales tax lottery program, IVU Loto, with the goal of increasing sales tax collection. When a customer makes a taxable purchase, they receive a lottery ticket as part of their sales receipt. Each ticket grants you an entry into the semiweekly IVU Loto drawing for prizes ranging from $1,000 to $25,000. The idea is that customers will demand their receipts in order to increase their chances, and this in turn will increase sales tax collection as businesses need to report a transaction in order to generate an IVU Loto entry.

Tracking dozens of receipts per week can get unwieldy, so I decided to make the process easier for customers by designing a mobile app that would let them track each entry as they received them, as well as stay on top of lottery results. The app had a few requirements:

  • Users need quick and easy access to the latest results.
  • They should be able to look up past results.
  • Users want to track their receipts and be notified if they win the lottery.
  • New results should be delivered as soon as possible.
  • It should be available in both English and Spanish.

I've built mobile apps and their corresponding custom backends before, but this time I wanted to focus on the app itself. By using Parse, I did not need to worry about setting up servers, allowing me to get started building a great, beautiful app right away. Needless to say, I was able to ship the app in a fraction of the time it would have taken me had I needed to set up any servers beforehand.

Access to Latest & Historical Results

Each drawing is stored in a Drawing class. Individual results for each drawing are saved to a Result class, and each has a pointer to the drawing they belong to. The app uses the following PFQuery to make sure all users have access to the latest results.

Query Used to Display Latest Results

// Inner query to fetch non-expired Drawings
PFQuery *innerQuery = [PFQuery queryWithClassName:@"Drawing"];
[innerQuery whereKey:@"createdAt" greaterThanOrEqualTo:cutoffDate];

// Final query obtains all Results that belong to a current Drawing
PFQuery *query = [PFQuery queryWithClassName:@"Result"];
[query whereKey:@"drawing" matchesQuery:innerQuery];
[query includeKey:@"drawing"];
[query orderByDescending:@"createdAt"];
[query addDescendingOrder:@"prize"];

By adjusting the cutoff date, limit, and skip on the Result query, the app can show past results, too.

As lottery results become available, they are added to my Parse app using the REST API. By using Cloud Code beforeSave triggers, I can make sure that no duplicate results are added to my database. An afterSave trigger checks if any of the users have a winning ticket, and if they do, a push notification is sent from Cloud Code.

Receipt Tracking and Winner Notifications

The entries for the IVU Loto drawings consist of two pairs of five character alphanumeric strings. When users add their entries to the app, a beforeSave trigger validates the entry. This includes checking for the presence of a valid entry, making sure that the receipt is associated with the current user only, and checking if the user had previously added the same entry.

If the receipt is saved successfully, we use an afterSave trigger to check if this entry belongs to a drawing that has already occurred. If that's the case, we send a push notification to the user to let them know about their winnings.

Send a Push Notification to this User

var query = new Parse.Query(Parse.Installation);
query.equalTo('user', Parse.User.current());

Parse.Push.send({
where: query,
data: {
alert: "Your P4A2R-8S16E entry was drawn as winner for the $25,000 prize on October 22, 2012!"
}
});

Localized New Results Notifications

When new drawing results are available, a push notification is sent to all users. Since the app is available in both English and Spanish, I need to make sure that the push notification is sent in the correct language. In order to do this, I track the user's preferred language in their PFInstallation. Users can also opt out of these "new result" notifications, but they still want to receive a notification if they have a winner. This preference is also stored in their PFInstallation object. This makes it very easy to send a targeted push notification in the correct language to just those users who are interested in receiving these updates.

Send a Push Notification to Users in Their Preferred Language

var queryEnglish = new Parse.Query(Parse.Installation);
queryEnglish.equalTo('newResults', true);
queryEnglish.equalTo('language', 'en');

Parse.Push.send({
where: queryEnglish,
data: {
alert: "New results for October 27, 2012 are now available."
}
});

var querySpanish = new Parse.Query(Parse.Installation);
querySpanish.equalTo('newResults', true);
querySpanish.equalTo('language', 'es');

Parse.Push.send({
where: querySpanish,
data: {
alert: "Los resultados para el 27 de octubre de 2012 ya están disponibles."
}
});

As you can see, Parse has made my life as a developer very easy. With Cloud Code, I can guarantee that all data being saved is valid. My users are kept engaged and are automatically notified of any prizes they've won. They upload thousands of new receipts each day, but I can rest assured that my app can handle the load thanks to Parse.

IVU Loto App is available on the iTunes App Store.