Erlang DC 2013 – Using Erlang to Drive Mobile Payment Application by Jordan Wilberding

about a year and a half ago friend of mine and I who’s more business oriented but also has kind of a technological background we were we got together they were you know trying to deciding like what’s a what’s a pressing problem in the world that week installed and we happen to be at a bar and you know work that you know world hunger what was great you know I’m here stuff going on in Libya maybe we could do something there but they were like you know what it could be a real pain sometimes to order a beer and you know the more we thought about it and first world problems obviously but more we thought about it it actually is quite a pain to order a beer especially if you go to college bar or something like that I don’t know if we have any one college here still but you know sometimes you still frequent as far as in for time and I’m not going two fingers so yeah so you go to a bar he’ll it’s busy go to a club maybe you go to one of Nashville’s crazy parties and you want to order a beer and you’re trying to fight in mine you’re not a hot woman so the bartender doesn’t care about you and you end up waiting ten minutes just you know to shut some order maybe we’ll get the drink that you want and then you finally get in then you go try to find your friends where they now you just waste all this time while you’re looking at your phone because you would pretend like you’re doing something important and you know you do that the whole night then again of the night you you want to go pay and that’s you know like another 10 to 15 minutes yelling your game you get your bill realize you know there’s ten tricks on card in order and you know it’s it’s a huge hassle so so that’s that’s going to be the basic such as so first of all I’m going to go over what is we man exactly so wingman is obviously the application that you run on your phone it’s going to make order engineering so a little easier I’ll go into a little bit more details coming up then also i’m going to focus on the platform that I built the back end so basically there’s two parts going man you have the application that you’re on your phone but also this application has to move back into process giant orders process credit cards into like that also how many people here went to the girl who talked alright so if I’m happy to do the other half i guess one to the boot camp so i’ll try to appease both of you but I’m gonna show basically how you can I actually were running this app at barroca so this is kind of a real example of a you know back in erlang running in parochial so I’ll show kind of a quickly demo putting the app into Roku actually gonna need internet where’s this sorry alright all right okay finally finally all enough questions so what is me so basically you know like just you can think of this problem you know actually it is you know again put things in perspective this is an actual problem that occurs at many different levels so first of all you have alcohol companies right they want to get their branding out though they want to sell you as much alcohol as possible what you want to glad to consume assuming that is efficient and easy to do I still some of these slides from my business partner and so obviously as a customer you go to the bar you know it’s very difficult to get your truth you have to shout your drink what do you want to split the tab at the end of the night all these different things require you interacting with the bartender and very busy studying making very difficult to get a trick so why not be able to just you know order a drink on your phone once the order is ready you just walk up to a special spot at the bar that drinks waiting for you show the bartender who have done during that whole time you can stay with your friends you don’t have to just wait mine try to make conversation with you know sorta jocks and you know weirdos or whatever we’re not on work you guys go hearing but you know sometimes it can be unpleasant and you know again at the end of the night you know like wouldn’t it be nice if I can just leave the bar you know like whenever I want to and if I want another drink I don’t have to decide you know what do I really want to spend another 15 minutes waiting line to get a drink you don’t worry about that anymore bartenders I mean they’re facing the same ordeal is you right up there on the other side of the counter just people shouting at the mailing it then try and slip the money to get them a drink sooner and they’re trying to like you know hustle and bustle and at the same time they’re using this arcade system where you know let’s pretend you have two different groups one orders you know five margaritas and the couple gin tonics and other group orders you know a couple Janet onyx and maybe you know five you know copy Budweiser’s or

something wanted to be nice if when they’re making those student tonics they can make all four of those at the same time to process one order independent than the other order independently and so we’re developing a tablet application that allows them to pen streamline this whole process as well and and also you know bartenders they want to make tips right they wanted like the mourners of a process and workers that they filled the more tips they get up you now the same thing is for bars obviously the more bars sell the more money they make but also there’s another significant factor here where we save ours money and that is in our transaction fees so what we do that’s kind of different is that we assume people go to multiple bar and this is generally true right you like giving your present one bar a man of you know me with another group of different Barnes throughout the whole nine and so what we do is instead of charging criticar transaction fee to the bars we we actually eat that feed because what happens is instead of like having to charge your card at each individual bar you just have one charge at the end of the night so if you amortize that across all the different bars you know you’re paying like you know maybe I five and ten cents for the privilege of using our app to buy a shrink that actually pays with a credit card fees in total assuming that you only charge the card once at the end of the night instead of charging in all the different parts that you go to and so we eat that for you that’s a fee that the bar is a Tang anymore so they’re automatically saving money by you using your app furthermore we know you know exactly how to target users we have like very specific demographics we know when you order drink when you don’t so we can serve a very specific app you can put a special you know like by two tricks get one free and either the user clicks on it use that or they don’t and you can you do this with advertising so you can have some you can provide an ad and if they use that then you link up the paper that ad at that time and again you know the bars can know like if they run different specials on different nights which ones are working which type of crowd to the attracting what kind of drinks are they serving and they can find all these different things out you know this feels you know all the way back so that you know how do they do kind of like predictive ordering for like what do they need to keep in stock on certain nights or certain days of the year you can look across this longitudinally and we end up you’re not being able to sell the data back to them and that’s where we start making my so we let them use our part for free by the end of today have access to the analytics you know they come to us we can process them insurance um each hearts and everything so everyone’s happy right people are drinking more I mean everyone knows that right I’m thinking once you have a problem so so now we have a what we call Patrian app that’s what you use on your phone and then we have a vendor app as well which is kind of you know both like what the bar users is and also the bartenders so now I’m going to talk about the core so a nice thing about this court and the reason I’m kind of giving this talk you know which is not a big sales pitch to go trade is that this is kind of I’m trying to make this more of a general payment platform so you can think of this problem in many different contexts for instance everyone who’s ever gone to starbucks you probably see you know people that now have the starbucks application with can go they can scan the phone now think of an independent coffee shop wanted to do that it’s relatively similar to you know buying a drink at a bar and so instead of like you know having to order on your phone which you could also do we could just simply replace out the QR code and create something very similar to what starbucks provides but for independent coffee shops and in doing so the backend system is completely the same instead of ordering barrier ordering coffee and so I prepare to try to create this platform to be you know something that could be generalized and used for different types of situations so where someone can you know focus more on the idea and kind of the interface of like whatever their phone application is going to be and then you can use this unified back and platform and in doing so it’s not open source yet I actually told some people by today it would be open source but it’s going to be about a week from today just because I’m still in a grad student stuff it’s not easy to play so so the end of the day I hope actually other people pick this up and use it for different kinds of uses I mean I’ve come up with like 10 you know just you know past talking with people and so with that said here’s kind of the the architecture so as you can see we have we use phonegap I don’t know if anyone here is used phonegap i’d recommend probably not using it it was I wasn’t the best decision but you know when you have people that are working basically for free you know we utilized and maximize the work that workers that we do have so we basically support I phones and Android comments on but it also technically supports on these other things and then we also have a web application for vendors and that’s actually ruby on rails but then we have a restful interface and this is implemented using webbing web machine and I call this my web and web app these are the three major apps so you have the web man web app which you know web machine kind of processes the restful interface we can utilize it whatever we want that pasta

wingman DB which would base my couch TV the reason I chose that was was very easy to set this up on a single server but you know like once we started growing and got things while working together it’s very easy to switch that out just use clouded which I’ll actually show when I go through the vocalizing position things and then edges heavy like a simple idioms app as well that covers like payment stuff and urban airship actually yeah so so this is the three main apps that you know again I position state wingman was you know you probably understand like the wee man helps you have bars and stuff blah blah never love the name but it’s kind of stuff around so I’m sorry for that alright so I’m going to go ahead and start kind of this is going to be kind of like a demo step through code kind of thing kind of a high level this is my no means is going to let you know teach you necessarily how to take this platform we use it right away but hopefully it’ll give you an understanding of the general flow so once this is released you can go through it modify to your own needs speaker people see that okay so here’s the code already kind of pre build things so you know rebar get Babs already did that case the internet didn’t work and then you would also run a remark compile yeah it’s already compiled one quick thing for so for this initial demo I’m just running couchdb locally so this is scott GV all right so to start it just have a simple start script okay it started and again the the interface is a restful interface so I just used curl I’m I guess I should show you what I’m doing so so this is the JSON diamond be providing to the API and actually I’ll just run a person so again this is you know base not JSON very simple this may not even be yeah I think this is pretty much the latest it’s pretty close so you know you have yours your idea in the aim credit card it’s not a real credit card obviously so i’m going to go ahead and this is going to be a post and it’s to the users API which i’ll address in a second but hopefully this works it works we have a response okay so so again i’m using web machines so this is Heather handle this is defined and dispatches com there okay so i can go ahead and open that up actually so as you can see the dispatch basically defines how to handle however actually it’s me this one is it defines basically how to parse the URL or whatever you’re handing so again if you look at what I provided it was just slash users so it’s going to use though the wingman web users resource that’s the finding right here it’s going to be using that early module to process it so I can go here and you got web oisin kind of provides a basic framework so one thing I do want to know quickly for this first example is the database calls this book or two so this is basically guess this isn’t the most efficient but I basically started a simple instance of a database connection each time and this is calling up the user database and I can go ahead and actually show that so and I’m going to be going back in here later on to show how to use it with about it but for now actually this is set up to use that or actually no this isn’t the old one okay whatever so so this is basically you know you start your server and let me give it the user is database and so we just you know create a simple bit of this function here going back okay so like you love your database and again you know this is just kind of a simple thing that’s defined by by the web machine so you get our document we

parse it out we get the user ID here we set the ID because this is going to be storing couch so everything in couch has an underscore ID and we just set that as the user ID we get the password we hash it we set their tab 20 get the credit cards encrypt them and then we created and then we do a few simple sanitization things like we remove the password because you’re no reason to send that back to the user and we send them back the response so so as you can see like this is kind of the response oops so it’s probably complaining sitter is netflix yeah so that was the response so that’s a basically creating user now I can actually go into couch TV go into my users table or user database I guess is what they call it and you can see my user here so couchdb I don’t know if anyone’s ever used it but it’s been nice because you can actually go in here and like you could edit it if you wanted to change things you can see the credit card here has been encrypted and CouchDB doesn’t quite understand what that means so it just gives like really long list of binary integers okay so we have the password set now let’s go ahead and login or people with me so far and I’m not going back quick but I mean this is probably easier that way all right so we’re going to go ahead and use the pro command along in sure this breaks everything I’m going to be upset idea actually before I do that though so Logan is very simple you provide a password and so you can see this is in the forum user / ID / law game which also show in the dispatch again ok that’s the headers um so yeah so I’ll go ahead and go to the dispatcher end so this is the login so again goes on the forum users / ID and the ID here means like we can parse it out when we go to parse the URL and login and that’s going to use the wingman about users login resource very explicit naming convention so again it’s kind of it’s going to be a simple post so you know we get password try to validate the password which carrots done if it’s good return yay it’s not bad in this case hopefully was yay and it was and as you can see we also generated a key and this is basically going to be your session fee so we can go again in the database and look at kind of what happened so I refresh here this should now get a key value so so now we have a key value can use that key value of our session and this is just something that you know we modified the user object for me so that’s cool that worked now that we have a key I’m going to actually go back to shark man so the next thing we’re going to do is submit in order in order to do that now that we have a key we actually have to provide that as part of our chase on request this is and over cool so being put our order I can go ahead and show what that looks like so I won’t bore you with going to the dispatch again but again so just processing orders pretty simple in this case we verified you the alchy we set a date I’m in a modified a time and that’s basically because the server and the client be interacting so after you submit disorder the tablet application which is kind of another part of this will see that there’s a new order once the party started I’ll change the staff so fewer I’m not going to go into all those details but again you know this is just you know pretty simple just a few commands and we’ve created any order I guess I can go over the doing man DB create just so you can see the database part of it really quickly so I already went over appended a supervisor how it started going here so this is the basic database interface

actually school most of this from Tristan so it’s broken you’d like them so yep so we have a create defined here it’s going to you know a simple chance server implementation so we can see where it’s implemented so so hard to scroll in in Texas okay here we go so this is really simple I mean the nice thing about using JSON again is that I can basically just use it for Beethoven throw out the couch and now we’re done so that’s all this does so couch being safe boom again we’re running couch to be locally but as you see like later on we’ll be using cloud it all this code still stays the same everything still works great it’s going to be cool all right so so we did that so let’s actually run the command or I guess we can do the next finish actually when I go back to the order show that actually happened so here’s the orders here’s your are submitted there’s three trains you can have this nice interface you can look at different things blah ok and actually now that I’m here so as part of this process what would happen is you know the bartender would you know say the order is completed then you go pick it up and then in doing so once the order is completed like your tab your tab would get adjusted but since I’m not going not stimulating that right now I’m just going to go ahead and manually edit the tab so I can show a pain alright so now we have a tab $39 so I don’t know if that’s the actual cause let’s close it up all right so all right so let’s go ahead and actually sewer again so so this is what the payment looks like you specify the user ID the amount card index is basically you have your credit cards on file this is the first card on file is zero with Carter pile payment method currently we support off net which is US base in ogon which is european-based we actually have someone running this over in ultram i should i guess i should also mention while i’m doing this is that currently we’re doing most of our testing in pittsburgh is there anyone for Pittsburgh good with you’re a liar um well that’s watery so uh actually it’s because it’s in the oakland area of pittsburgh which is for Carnegie Mellon and fit universities so it’s just just and also the person i’m working with these from local schools actually so we have kind of a number of people to work with there oh ok so I modify that and then just go in rough days cool so that was approved actually I’m going to step through the code really cook for that one too so again this is again it’s pretty simple authorized the key I was in the as part of the post go ahead and like extract like we basically just check there’s a card index or not if there is and we use it on file otherwise you can also provide the credit card information directly someone doesn’t want to store credit card you can just provide that that’s just a different group of the post go ahead and if we do a bunch of some stuff behind the ground actually process the order use the payment method in this case it’s been use the pay module it’s very simple checks which payment provider we using this case often and this is one of the things you have to clean up right now it’s actually using like so PHP things I just haven’t had time to implement it correctly because often is really kind of weird for whatever reason so I used their provided PhD thing and call it from a shelf man which is really really horrible but it’s worth so far but I certainly don’t release that so that’s like just one of the last few things I’m going to do this before this gets released and then you just you know process response codes any case this sexual isn’t the actual code then I’m writing right now I have it always return true because of my fake credit card or have actually gone through so fact that did go through though because I faked it I can actually able to refresh this and my tab is now 0 that’s the way it gets torn up but it works may not look pretty okay so now we did that let’s see let’s go ahead and

for roku why’s it all right Tristan I’m using your product all right okay so this is actually it’s actually very simple to go from inner line application or group of applications and to get to get it work so what I’m going to do is here so go ahead and kill this again sorry okay so one major thing you have to do is create a thing called a proc file and that’s basically the only new thing you have to create besides to get information and that’s really simple all this is going for the people that didn’t see the Viroqua talk is telling propre how to run your application so as you can see it’s just telling it Tehran start on that stage and that’s basically the only thing you have to do the next step is to it has to be like karoku expects everything to be a hit repository and in general dislike I already have minded get but since i’m trying to show cool things will go ahead and just make our own git repository so getting it obviously makes a new different posit ori i had all the files and i just do an initial commit now for the Heroku part I just run Roku login how am i doing for time by the way okay all right so i logged in now if this is the only kind of curling specific part there’s a state called a bill pack and all this does is once you upload your application I basically told to Roku that you know this is a special application use a separate bill pack and this bill pack actually is just a bunch of scripts and who knows what that no understands how to take an early nap and get it to run on Heroku and so now that I’ve set that there’s a another step what I do in Tristan’s presentation he showed how to set a postgres but i’m using cloud it again kind of the hosted version of couch TV so by running this i am adding an instance of clouded automatically to my karoku instance which washer on a second i should also note that all these things i’m glad our free tom / like this again for the people have missed the Heroku talk to host the very simple application like this that’s basically free assembly using one guy know which is like one computing resource and cloud it has a free version that allows you to use a very small database begun all right so that got added ok the next thing I’m going to do is I’m actually going to go to karoku and so I can create mine databases really sure so there it is so as you can see cloud it has been added as an atom I click on it and it’s going to basically come up with the standard futon interface and so I just need to create a couple databases so I have I users database rule now I have my orders databases normal i have the database for establishments but i’m not going to that part for now ok cool so got that set up the other thing i need to do now before i give like put my coat on and roku is I needed to tell Miroku to use this new cloudy interface instead of using cash TV locally in fact a baby technically possible be very difficult to run couchdb locally on her over Winston’s so I run berroco config and it gives me back the clouded URL and you can see here like coated in this is the kind of the username from the password and the address for my clouded distance and then I’m going to go ahead and modify my database to use it was that yeah but that’s going to give me I need to write that parser too yeah that’s like another on my pic final schools so yeah this is ugly I know like you can just you can actually get the URL directly parse out you know the specific user name of the password in the URL and I even have the regex to do it i just have it I mean it’s good when I give talks

because people learn exactly what not to do in case people are wondering this like okay server equals application get end and those are things that are just setting config file so that can ask what the defaults are and you know I could also have probably set it there but just doing instead okay good all right so I’m going to have to commit that change before I can load it again all right so final step is to actually just push it to the record hopefully see as it starts going through you can see the build pack is on packaging it’s going to run rebar some stuff that’s going to get my packages it’s going to notice the automatically compile things and all that good stuff so it’s actually pretty cool after this runs we should basically be up and done you see ya that’s wearing my file it knows what I specified that you know launching was just running my started sh you show us that oh I did not so this is just like a one-liner girl command again for people have missed the early talk to the essential thing here is you have to put no shell I don’t know why but if you have it it’ll automatically your process why is that Tristan you know basically just steal this music perverts okay so so that’s also i mean the other thing is like I said the Deaf strike because rebar by default puts it in the Ducks folder so that’s about the only other thing you keep it out I specify my config oh it’s a pretty standard one liner for starting an application okay so that’s so good looks like everything started so this is my this is not my url so I’m actually going to copy this and to make things a little easier I because of like I don’t know what is going to be named ahead of time I’m just going to go ahead and set it as a bash variable and sheet so I’m basically running the exact same commands that I was running locally before but now this is actually going to be talking to Heroku so again I mean I’m sure you understand bash so it’s actually using the hose hopefully it works damn it let’s see air connection failed picture reviews so I did run into this before copy everything right yes you can afford here is this SL nice from here pearl well I mean that’s not the issue though it’s actually connecting right so here you see the connection felt this is happening in the database itself so I had issue with this earlier it seemed to be kind of hit or miss i don’t know if it’s something with heroku but listening article is failed okay you’re not parsing it would get in that’s as not just living a double check to make sure we are but oh no that ports were the club yeah let’s your shed data so I honestly felt like I tried this

like five times and like three times i work in two times it in it it’s maybe close all think she considered if you have problems can I talk to Tristan but I don’t work at club I don’t think it’s about ok miss and I are friends ok anyways normally that would work I don’t waste your time debugging it so go back to talk say that if you actually you know if you want to use the app on your in Pittsburgh sometime it’s me man AAP kaam wingmen hgp commas are you taken and we could have come up with a better name so it is what it is again I’m going to be open sourcing this in about a week if you want to know more about it just send me an email and i’ll be able to be sure to keep you updated and you know questions but i’ll just give it here is on communities and again like you can go to the App Store on either your android phone or iphone and just search for a wingman patron and that’s the user end application and that’s it