This episode is for members only

Sign up to access "Build a Pay Once For Access App" right now.

Get started
Already a member? Sign in to continue
Playing
12. Updating a user member status

Transcript

00:00
So now that we're calling the correct method in here for this PaymentIntentSucceeded event within Stripe, all we need to do here is look the user up and update them to be a member. And of course, we're going to set that to true. Now before we do that, let's head over to the user model, which we've not touched yet.
00:19
And let's make sure we set the member column in here to fillable so we don't get any mass assignment errors. So the first thing is looking the user up. How are we going to do this?
00:29
Well, if we just take a look at the payload, we've got this user ID in here, but where does this live? Well, let's just follow this through so we can see. So we've got this data wrapper here.
00:40
Inside of this, we've got this object wrapper. And then if we come all the way down here and follow this along, then we go into, we come all the way down here, all the way down, we have metadata, which contains the user ID.
00:58
So what we can now do is look this user up. Now we could use find or we could use find or fail because if the user doesn't exist, we really do want to throw an exception here. And in here, we can again use a Laravel helper called ArrayGet.
01:14
So this array helper here just allows us to, if we pull that in, grab from that payload, which is an array, and then we can just use a dot notation here. So remember that was under data, object, metadata, and user underscore ID. So that will now just pass that through and we'll get a user in here of the person who
01:37
has just paid. So now what we need to do is say user update, and of course, pass through member as true. Now you could do anything in here. You could go ahead and send an email if you wanted to.
01:49
It's entirely up to you. In our case, we're just going to update this user. Okay, so we're going to go through the entire flow now. So if we just head over to our payment section, we of course have a huge amount of these payment
02:01
intents in here. But at the moment, this user is not a member. What we should now be able to do is head over to payments, go ahead and enter our card details and hit make a payment.
02:14
That's going to go ahead and redirect us back. The Stripe webhook will have been sent over to our app, and that should have updated that user to true. And of course, now we can head over to the member area.
02:29
And that's pretty much it. We've gone through the entire flow of making a payment, being redirected, the Stripe webhook coming in, finding that user from that payment intent that we set over on that payment index controller, and then of course, updating the user to become a member.
15 episodes1 hr 11 mins

Overview

Let's do payments right with the Stripe Payment Intent API, and build an app where customers can pay to access a members area.

We'll cover setting up a Payment Intent, process payments correctly with authorization, handle declines, and securely respond to a Stripe webhook to upgrade a member.

This course is for you if:

  • You want to process payments to upgrade customers for access
  • You need to learn how to properly process one-off payments with Stripe
  • You need a refresher on the Payment Intents API
Alex Garrett-Smith
Alex Garrett-Smith
Hey, I'm the founder of Codecourse!

Episode discussion

No comments, yet. Be the first!