#116 More on Stripe and Webhooks


Continuing from Episode 114 and Episode 115, we look into adding listeners to Stripe's webhooks for tracking events occurring with customers, subscriptions and charges.
payments rails webhooks 16:31

Early Bird Pro Subscription Pricing!

From now until Mar 01, 2018, save on the Pro Membership!
Get the Pro Membership for $9.00 USD per month while you maintain an active subscription.

  • Student & Teacher
  • $9.00 / month
  • Valid School Email Required
  • Same Access as Pro
  • Subscribe Now
  • Pro Membership

    Early Bird until Mar 01, 2018

  • $9.00 $15.00 / month
  • Access to Pro Episodes
  • Invite to Slack Channel
  • Priority Episode Suggestions
  • Ad Free
  • Subscribe Now
  • Teams
  • starts at $75.00 / month
  • 5 Users Minimum
  • $15.00 / user / month
  • Same Access as Pro
  • Subscribe to Teams
there are turning to ah to add a turn around and reserve previous episode one fifteen break it to be born from the episode born fourteen or the strike management and in that episode we looked dead kids that were so scripted in in greece is writing in in this episode would you know look it was named for scribe blackhawks so that whenever charges come in or suspensions are cancelled would it'd be able to handle those appropriately then also display the charges that a user has occurred one of the awesome you to all these awarded to be using for those is the crop which allows exposing a local server be hiding matter far wall to the internet so that way we can accept incoming requests from scratch swept books into or local development of armor they would go into it so that with protests can stall and rock we think all of the rock h t t p we wanna was a record three thousand pseudo even see them we're fourteen know we have access to our application at this your help in there with its wanting to our local those ports we thousand and so with a rock climbing we even start up for males application that said now we're running or locals were three thousand and just you or l is fourteen to local sports we thousand so within a browser we kinda silly get to this your elk me can see better application is running so the easiest way that found to integrate with the tribe web books is with the strength of that jam basically what this gym is going to do is going to allow was it had all the web book events coming in from strike is going up or sit out there we can't read read based on the type of a bitch to a separate class so within our gym foul will add these tried that and jam you should run battle resort you will separate kitchen and within strike and are a few testing data going to go under the idiotic and then what books within the web books we want eddie in point that we want this in point the point to our local environment this case we're referencing are in a crock the dress then i just wanna give it a employee on to squander call this course i strive to the vet and then you're able to specify which event say you want to send the kids and all events or linkages since specific words like the charge failed or the charts succeeded but in our case just for now the disc in this and all of that's done so for each event whether it's a user being created this is gretchen cancelled or whatever the case then it's going to make a separate close to your application for each event so what we've created a rare event you click on it when we see the signing secret and this is a important game because this is going to verify that the event that's coming into our application is it that coming from stride and not some third party so will copy it as an elevated to our applications initial eyes are so within our can take initial oysters what they did the stripe or be filed the weekend is said in the strength of it or did they create the signing secret the men are signing key into more secrets gamble file so call the rails application that secrets men just couldn't call this the strike webb look secret maybe should it come down in tears secrecy of all file when you're greeted her credentials if you use in those a shanty shrine would look secret then back in their stride better be fall in that same configuration options and what they get paid we want to call the subscribe a week and has since something like a charge maybe college hard stock that has a plan ahead know any candidates around the charges so that the charge succeeded or if they charge failed in this block would get called if you wanted to do something specific making dinner and the full of bed in our case worse than a deal with anything that has to do with each are beginning a colleague know the block and this is just going to be our event if you wanna see what candidate is coming out of the event you just walk the event here or we can preserve is object they had all these events in our case and disconnected a surface object on what books for will create a new instance will pass an air vent in on the new it's as much as call the call method so within our ad for a grade a folder called services then another folder called web books and within their will have our chart the edges creator module you will call this or what books what did you will have a class called for someone or object is an echelon as we pass a rare event the event said the instance variable event the old t v event it's best then you know we have our call method within a year you would more to change everything in here so that comment that is good and all of the succeeded same failures you said we just want to run a case by the event hi and so when the charge that we double for some action or if the charge was failed do we do perform any different action so i just ate some private methods and these private met this or bennett be the charts exceeded and the charge failed and so when a triumph was succeeded we want to get what the charge was there with the event is a jason response it seems like these rather than gym is rendering this as an open shot said because of that we can suck call something like they did not object again or have been paid up object so we'll said charge equals to the evaded object we can find the users for by the user fine body and this time we want to find it by the strike by the this is coming by the charts customer we think radar new charge martinez said this to the user data charges this is kennedy a model that we have to create but it's good that says i'm certain things like the strike id the amount or the dollar amount that we could also source of the card information so we wanna find what are you sir charges where the strike baby is equal to the charge id and this is going to be the idea of the actual charge not the customer we can call first or create them by acorn for should create there we're creating the object of it is in exist by this charge of the mill we can just update some of the parameters so if we have our amount that we want to sort this is gonna be excess water the charged out around and also sort of a card brenda was used this baby excess water the charge to outsource in the source is going to be referencing to the card may we can call a friend and so forth so we can also added some other things like the current last for the expiration month and the expiration year with as we know or didn't need the strike by d really any need a user id because we had this relationship between charges in the teaser we're also going to need the amount or brand less for our next fresh month and a card here and so that the charge failed we came grab road charge again we can also grab our class meridian except this time we want to update our customer the expires at and so with the expires that we can set it to something like the kind of current and that's basically going to set their expiration to break down or if you just wanna make sure he came to mind is solved one hour or something like that and that's going to be sufficient as well then you're also did they need to clear out there's francisco to id the weekend said the state will do this on a charge failed you won't want to make sure that your handling it properly on the streisand as well with the number of failures you have your stripes description to fail on the very first time in to cancel the suspension then you would do something like that as but if he ever grace period for it maybe we try support multiple times over span of a few days they may know what to call on the charge failed but maybe the suspension cancelled whenever the user can solve these description or scrap cancel the subscription the cell within our criminal we all they will still a model integrated model charge and the attributes the user id is can it be an integer they were also wanna call index on those same way with the strike id it said this and it is a string or one recall index the mortgages passes some information about the charge so create the attribute of melt in it as a pitcher because stretches deal in cents on everything that will soar the car brand the car last for the card expiration much any card expiration year what's he wonders be should run the wheels to be my grade and if you haven't done so since we've made all the changes to the initial eyes are you all want to research wells application that said if you're a member when we set up for strep what book we entered into your al with the your eyes the striped such event so we will need to melt the strike been shared jesse get access to that controller and will melt it at that imported so well call melt in in the striped event in an engine will melt is at the end point before slash strike slash at the vet answer this might work under most circumstances wonder if you find a you getting a invalid authenticity took it the kid going to strike the vents forget how do you download the controller didn't create the fall hierarchy the same as it is on the strength of their website into your application think are these cable for action the verify authenticity took it all over at only go through all that trouble so instead of just add a comment is out and they create my own kind way of doing this so all of the events that are coming in are you pose request we know that they are hitting the employing these stripe slash of it he then does call this to a specific controller in our case i'm just gonna call this what books they know what has it to the event action so whenever a pause request comes in to strike event it said going to go to the blood looks controller and even catch it so where're app controllers had created the file called web looks good fuller this is going to be a class will call it the web books controller this is not for dinner from the application to troll or like we normally do it said we won in the air from the strength of a controller in the controller there were going to override it's the web hawk controller within your weekend and and are scared before action in in the verify the authenticity to look at this event is the exact same thing is copying down the controller from the strength of it with a controller in two or application except know if we ever had to update the strength of a jam that we don't have to worry about coming back in here and updating the controllers well it said with the inheritance which is going to be ultimate added are of little monkey bench here in this is going to work and so bad that are welcome and that's why i'll understand and in a quick little script the current user is ascribed then i'm going to be displayed table in the table is just what you would through the producer that charges he deftly would want off the wisest for your own network it to be good to be used as a lotta charges and this is gonna be a plus one queried leverage is in this case as an example you should be able to get the point and see the web folks working and don't forget to come into our user model and a user has many charges he may wanna call did had destroyed just in case of a user is deleted all their associated charges are as well man in charge of blondes sue the user so off camera i did that depicts a couple books and in this allies instead of a nationalized then under the web looks good collided has spoken of that has to be tilted wonder how will have this with a mission as with the correct code so you should be built on a few copy from there what records of texas changes that debate or application refreshed the you see that now or cable shows where we have our tragedy along with the amount and just some information about the card and cancelling your suspension still works and we says grabbing also works if we win fresh a few times you'll see that we're not getting any actual charges and so will finish up the episode within our suspensions controller within here we create a new subscription that could be some instances where maybe add some funky drops what's going on and this is causing any issue with the subscription so maybe it's doing double post or something like that and that's going to be a really bad thing if we're double creating this is gretchen which would then double charging user every month so one way they you're able to avoid that any create action better rapport we have an ash within a set that upgrade on and potency key and that thing is about those keys said it has to be a spring and it's something they can only use one time every twenty four hours or something so big and had to be careful in how you generate those and in reality we only need this key for this one user this one time it is sunny day you would use to protect the java script is calling a double closer something like that they not creating a double subscription and said religious air out on that second subscription because he on a good seat he was or be used so you can do something like a wells die cash god that they have some panic here from a show like the current user so we have our current user tried turning to so we're having a good weekend here that we would've said the expires at the something like one minute then we would call someone like kind out now i had to lie this is just going to return the pep talk the density be a string something like that's the will to set the key equal to that then for the i'm clumsy he you would just for for turkey so if within a minute the same key is used twice then it's not going to allow that seconds of scripture to be created however keep in mind that the user does have a card error or something and its are you going to have passed the step and then within the same in it if the user correct said that it's going to subtly tide of reuse at st pete so that has a jewish and one more to make sure they yours then but that's in he then deleting it down here to make sure you do that otherwise when the user does correct their credit card information maybe they have the wrong cbc your zip code or maybe their card was declined in there quickly tried another card then this will allow them to make another post annual regenerate and other key and some other things and may consider reading the nurses good chance greece's scribes controller me what they had something like able for action ought to make a user they had also enable for action to see if there even allowed to access the real action the two greece ascribe be degraded another before action in a private method to check that the user is not currently says ride somewhere for these descriptions are describes controller the sector would only ever be accessible to use your new squarely lol dead and again you can also create a bill for action year and calling private method that private method to check to make sure that the car user it is actually produce ascribed and allowed to and says what all that's all for this episode they keep watching