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.

Episode summary

In this episode, we're finishing up the workflow that lets a user become a member once they've successfully made a payment through Stripe. We start by making sure our app is set up to update the member status on the user model, making the column fillable to avoid assignment errors.

Next, we dig into the webhook payload sent by Stripe for a successful payment. We walk through the nested data to find where the user ID is stored—in the metadata inside the payment intent—and show how to reliably fetch it using Laravel's array helpers. This makes it super straightforward to look up the exact user who just completed the payment.

With the user in hand, we update their member status to true. There's a suggestion that you could do more here (like send a welcome email), but for now, we focus just on marking them as a member.

Finally, we test the entire flow: making a payment, handling the webhook, updating the user, and confirming everything works in the UI. By the end, you'll see how Stripe payments and your Laravel app can talk to each other to update user statuses automatically!

Episode discussion

No comments, yet. Be the first!