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 have been 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 such as โ€œI see a controller at two steps - 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 application are exactly the same as in the checkout. We use the same mechanisms that CPPK uses to sell tickets, it looks like some kind of internal technical API. It took a lot of tying around all this, because ready-made libraries for both iOS and Android did not behave 100% stable. The difference between "almost never crashes" and "sometimes crashes" sometimes means creating more technological wrappers.



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 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's a proof :

:



  • ( ) ;
  • ;
  • ;
  • ;
  • () ;
  • โ€” , , * ( ), , , ;
  • .


3.4. :



  • ( ) ;
  • ;
  • ;
  • ;
  • () ;
  • โ€” , , * ( ), , , ;
  • .


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 (usually 1 or 2 of them at CPPK stations) and green validators fit. At the top of the post, they are large, but usually they look like this:







What happens:



  1. You buy a ticket, we create a reservation on the server.
  2. You pay for the ticket, the 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.


Important :



  • 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 marks 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.
  • QR- โ€” . โ€” . .


If everything went well, then you will receive a ticket. If everything went badly (instead of a 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.



The last task remains : how can the controller check the electronic 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 close to an ingenious: 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.







We added re-activation in case you get off at the station along the way.



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 go off 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 I 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. 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 revolving ticket and let you through.



- And 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 is over, 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 must 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.



All Articles