This episode is for members only

Sign up to access "Laravel Subscriptions" right now.

Get started
Already a member? Sign in to continue
Playing
09. Allowing promo codes

Transcript

00:00
So in this episode I'm going to show you how to enable promotion codes within checkout, but I'm going to show you the process of me digging through the code to find out how this
00:09
actually works and how it gets sent over to Stripe. So let's start with the easy thing, to allow promotional codes we just use the allow promotion codes method before we go ahead and hit the checkout and that will go ahead and enable this for us. Let's take a look at just what this looks like and then we'll go ahead and dig into the code. So let's click on any of the subscriptions
00:31
here and you can see that this is enabled the promotion code section and you can set them up directly within your Stripe account under your product catalog. So you can go over to coupons, you can add a coupon, set the name and then you can give that to the users to use with your checkout. Okay so ignoring that then for now let's look at the process of digging into how this actually
00:54
works so we can find out what else we can do with cash here without really looking at the docs. Okay so a little bit earlier we dived into the billable trait and we dived into the manager's subscriptions trait as part of this as well. We know that we're using this new subscription method to go ahead and create a subscription, this has returned to us a subscription builder.
01:16
So if we look inside of this subscription builder you'll see that we have that allow promotion codes method just here. What this is doing is it's setting a property within this builder to true. So the allow promotion codes builder is setting this to true. Now if we look for this inside of this file you can see that it doesn't actually exist. It exists within this
01:38
checkout builder. Now where does checkout builder come from? Well it comes from when we call the checkout method. So let's go back over to our subscription builder and let's look at that checkout method that we used earlier. So this does a couple of checks, checks about trials which we're going to look at later and then builds up a payload which gets sent over to Stripe. So all of this data
02:01
gets sent over to Stripe and this returns a checkout customer which returns to us if we just have a look in here a checkout builder. So you just want to follow the code through to see what's going on behind the scenes and if you have a very specific requirement something you need to send over to Stripe this will help you out as well. So if we open up the checkout builder and we look
02:22
inside of here you'll find allow promotional codes which if we just have a look here within this payload to create this goes ahead and passes this through. It's going to send all of this data over to the Stripe API so that will be handled for you. Now this checkout method also we have a bunch of session options and customer options as well. So as an example what you could do is you could
02:48
pass through any of the details about your customer in this second option here. So for example we could pass in the email address of the customer so we can access that via the user here and we could grab their email address. Let's look at the difference that's made because that's probably the most important part about this. So if we do this you can see that my email here has been pre-filled
03:11
you can pre-fill a name and address any of the information that you need to send over. So I'll leave that in there as a reference remember these are the customer options and these are the session options. So now you know how to allow promotion codes specifically but also dig into the code to find out what else you can do really without looking at the dots.
26 episodes2 hrs 38 mins

Overview

Learn to start accepting subscriptions with Laravel and build a solid foundation for your next application. In fact, it’s exactly how we do things here on Codecourse!

Even if you’re completely new to Laravel, by the end of this course you’ll have a platform where customers can purchase subscriptions and gain access to restricted areas of your application.

We’ll also cover managing subscriptions, cancellations, invoices, giving customers trial periods — and more.

Alex Garrett-Smith
Alex Garrett-Smith
Hey, I'm the founder of Codecourse!

Episode discussion

No comments, yet. Be the first!