This episode is for members only

Sign up to access "Laravel Subscriptions" right now.

Get started
Already a member? Sign in to continue
Playing
19. Downloading invoices

Transcript

00:00
As you'd imagine with Laravel Cacher downloading an invoice is going to be pretty straightforward. This will be a PDF invoice which gets sent to the browser as a actual file so the user can download it. We don't really need to do too much work other than just hook everything up.
00:13
Okay so one thing that we didn't discuss about invoices is each of these has an ID. Let's just output this here really quickly just so we can see what this looks like. So let's say invoice ID and let's take a look at what this gives us. You can see here we've got this invoice ID which is the ID directly from Stripe. So that's come through to that object the ID value obviously
00:34
is decorating what comes back from Stripe and we now know what we need to send over to request a PDF invoice. Okay so let's get rid of that and let's go over to our subscription controller and we'll go ahead and create out a new method in here which will send the request through for the invoice. So with this we're going to need the request object because we're going to
00:55
need to identify each of these as the ID. So we'll get something like request invoice through which will be the ID we looked at earlier. So once again because the user is central to everything we're doing with that billable trait we can just use the download invoice method and we can pass through the invoice that we get through in the request. So what we can do now is just hook this
01:18
up with a route and we should be good. So let's go over to our web routes go ahead and duplicate one of these down we want to send a get request over to invoice and we'll send the invoice ID in the query string. Let's reference that invoice method and give that a name of subscription invoice. Okay all that we need to do now is hook this up so let's go back over to our anchor just here and
01:42
let's go ahead and provide the route. So the route here is subscription invoice and we want to pass the invoice through to the query string so let's create out an array here and just pass down the invoice ID. That should be what we need to do let's head over and try it out. So I'm going to click download here and yeah so it looks like there's a additional dependency that we need to actually
02:06
generate the pdf and that is the dom pdf package. So let's go ahead and pull that in first of all. So let's do a composer require on dom pdf dom pdf and once that's done which is clearly here used as a dependency we should be good to go. Okay let's head back over give this a refresh and there we go that's been downloaded. Now the better experience here would be to click back and then go ahead and
02:29
choose another one and there we go that gets downloaded. Let's take a look and see what it looks like. So let's hit download and let's try that again. Okay there we go so you can see it gives you the name of the company, the product that you're purchasing, all of the information that you need and there we go that is how we download invoices.
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!