How to sell an electronic train ticket

We have been dealing with electric trains in Tutu for 17 years. You may have seen our schedule as a child or student. All this time we are asked when it will be possible to buy a ticket for the train of interest directly through the application. For 17 long years we have been waiting for the onset of a bright future, and it took half the planet to be quarantined for digital tickets to become much more in demand.

The reason is that no one has yet figured out how to sell them in such a way that:

  1. On the one hand – exactly the same price as at the checkout;
  2. On the other hand, to make sure that there is no abuse like “I see a controller two steps away – I buy a ticket”;
  3. Fast, convenient and reliable.

The third point has not yet grown together. Now I’ll tell you how cleverly this scheme already works. And I will say that I see all the prerequisites for making it convenient in the future.

Let’s walk through how a user buys and what happens on different systems during this process.

The usual tricky way without bugs

Step 1: ticket selection and payment. Everything is pretty simple and familiar here. Two of our mobile apps with timetables received “buy” buttons for the TsPPK trains (so far only the TsPPK, yes, that is, most of the Moscow directions).

The prices in the app are exactly the same as at the checkout. We use the same mechanisms that CPPC uses to sell tickets, it looks like some kind of internal technical API. It took a lot of tying around all this, because the ready-made libraries for both iOS and Android did not behave 100% stable. The difference between “almost never crashes” and “sometimes crashes” sometimes means code reverse engineering.

But let’s continue to buy a ticket:

Apple Pay and Google wallet were difficult for us on this project due to the features of the gateway. This story will be better told by my colleague later. Initially, we studied the possibility of transferring a customer to the official CPPK application. It was developed by the Movista company, which won the relevant tender. After a number of experiments, we decided that a lot of integration work is still better than changing the interface upon purchase.

Step 2: PD. Here we are in for the next surprise of incredible power: if you don’t need to fill in your full name and passport number at a regular checkout, then online you do. Yes, even for train tickets. The basis is the order of the Ministry of Transport No. 322.

Here proof:

E-ticket on a commuter train without seat provision contains the following mandatory information on the carriage of a passenger:
• railway stations (stopping points) of departure and destination;
• name of the carrier;
• train category;
• type of ticket;
• date of travel and (or) validity period;
• information about the passenger – last name, first name, patronymic * (or initials), name, series and number of the identity document;
• payment type.

3.4. When ordering an electronic ticket for a suburban train without providing seats, the passenger indicates the following information:
• railway stations (stopping points) of departure and destination;
• name of the carrier;
• train category;
• type of ticket;
• date of travel and (or) validity period;
• information about the passenger – last name, first name, patronymic * (or initials), name, series and number of the identity document;
• payment type.

As you might guess, this is where users get scared, and we’ve tried our best to reduce their hesitation. But in beta tests, there was a lot of dissatisfaction with the execution of this order.

If you think that after payment you have a ticket in your hands, then still not. You have a document in your hands that can become a ticket at the moment of activation at the turnstile at the station.

Therefore, step 3: go through the red turnstile. This is actually an extra step, but this is a security requirement: you must first buy a ticket, then go through the turnstile:

Red turnstiles are suitable (usually there are 1 or 2 at the stations of the Central Control Center) and green validators. At the top of the post, they are large, but usually they look like this:

What’s happening:

  1. You buy a ticket, we create a reservation on the server.
  2. You pay for a ticket, data is received from the gateway that the payment was successful.
  3. The CPPK sends a ticket and a base64 key to the phone, which is half of the key to activate this ticket.
  4. The other half of the key must be taken at the turnstile or validator. You go to the turnstile, scan the QR code on it.
  5. Further, a key is assembled from the two halves, which “opens” the ticket. You put your ticket to the turnstile and go through.


  • The turnstile has no logic for checking the QR code and the ticket at all. He simply shows his constantly changing parts of the key in the form of QR codes with station tags sewn there.
  • You don’t need the Internet to connect the halves of the key and get a ticket Everything happened almost immediately after the purchase, you received a ticket, and then everything is done offline on the phone inside the application – both its activation and its display.
  • The logic for showing the QR code and the logic for checking the ticket are different. The ticket is an ordinary paper ticket from the point of view of the turnstile – there is exactly the same key. From the passenger’s point of view, this is one action of bringing the phone to the turnstile.

If everything went well, then you will receive a ticket. If everything went badly (instead of the turnstile, you scanned his carefully stored photo from another station), you either get an invalid ticket (if you activated it with yesterday’s QR code, for example), or the ticket is not activated. By the way, the opportunity to get an invalid ticket made us think that it would be easy to reverse the library code.

Stayed last task: how can a controller check an e-ticket? After all, it visually does not differ from the screenshot of the exact same ticket! It turns out that the CPPK has found a solution that is close to an ingenious one: you need to open a ticket in the application and tap on it. The activated ticket will start rotating. It is assumed that this reliably protects the majority of the population from fakes in Photoshop.

Now let’s move on to the sweet stuff – bugs!

The red turnstile may not open. Just take it and not open up. Because something in his turnstile brains won’t fire in time. For example, protection that prevents you from passing through the same QR code to two turnstiles at once. The probability is very small, but there is. In this case, a tired grandfather, who is on duty at the station, will approach you. He has seen this hundreds of times and knows what it means to hesitate at the red turnstile. Check the ticket in the application (“Spinning? Spinning!”) And calmly let you pass.

The green validator on the platform may not work. This is Russia, not Japan, so here it can last longer than 3 minutes in total per year. In this case, you need to go to another validator, and he is on a different platform. The probability is also very low, but there is. An ordinary person is unlikely to face such a situation, but we tested it for a long time and fiercely, so we know.

If you scanned the QR code on the red turnstile at the time of the change in flow (when they tell you: “Go to another, here people get off the train”), you must go exactly through this one, otherwise you will cut the same code that is responsible for with one ticket you did not go through all the turnstiles at once. The neighboring one is not synchronized immediately. This means either half a minute of delay, or checking the ticket by the grandfather on duty. “Is it spinning? Spinning! ”

Small FAQ

– Can I buy an electronic ticket for a train from the metro?

Can. That’s why we made you buy on the escalator.

– If the connection is cut off after activating the ticket, will the ticket remain?

Yes. And it will spin.

– Do you need internet when the ticket is activated at the turnstile?

No, everything happens offline inside your phone software. You already have a ticket, it is simply decrypted.

– If I see a controller, it’s too late to rush about buying an electronic ticket, right?

Yes, if you do not have a QR code from the nearest station at hand. And knowing our mentality, it is not so completely sarcasm.

– Ha, what if I photographed him in the morning when passing through the turnstile?

Changes regularly within a few minutes.

– And if I understood the pattern of this code?

The coding algorithm changes at midnight, and the codes start to differ from the previous ones very dramatically.

– If I activate the ticket with the wrong QR code, then what?

Then you will have an invalid ticket that will refuse to spin. Or a ticket for the wrong date.

– How long is the e-ticket valid?

After activation, the ticket is valid until 03:00 of the next day. That is, you can scan it at the turnstile at 7 am and use it at 21. No problem.

– What if I get on the train at 00:01?

At the junction of dates, there is a Heisenbug in the ticket verification system (paper tickets too, that is, not in our stack), when the turnstiles may not respond to yesterday’s ticket. Processing is normal – you will need to call the turnstile on duty, who will look at the rotating ticket and let you through.

– What if I passed the turnstile at 2:59?

If in the second that passed between the activation of the ticket and the passage to the turnstile, the technical day ended, the issue must also be resolved through grandfather. He will endure everything.

Other tickets

We are negotiating with other carriers about selling tickets at the same prices as at the box office. In many directions there are no such difficulties with ticket activation, for example, on most Leningradskoye trains you can buy a ticket inside the train. Naturally, this creates a known vulnerability, and some compromise needs to be found that will suit everyone. But I’m afraid this is more of an area of ​​community work than development. Although if you have ideas, we will be happy to implement them.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *