تماشای این درس نیاز به اشتراک حرفه‌ای دارد.

Invoice For Setup0:00

Okay, let's see how we can generate invoices from within our Laravel app. So let's start with this invoiceFor method, which is similar to the one off charges we did in the last video. But if you take a look at the method signature, you'll see that there's no more paymentMethod. So we have to attach it to the user manually. So let's go ahead and do that. So let's grab this and it's going to our code. And let's go to our routes file. And let's just replace what we did here. I'll just comment it out with this new thing. So auth()->user(). Okay. And you can give it a product name. I'll just leave it to whatever's here. And let's say $15. And this should work the same way. But now we should be able to generate an invoice from within our Laravel app. So

Create Stripe Customer0:48

whatever's here. And let's say $15. And this should work the same way. But now we should be able to generate an invoice from within our Laravel app. So let's first make sure that that still works. And let's go ahead and do that charge. Sorry. And as you see, we get this error. It says user is not a Stripe customer yet. So like I said, we have to do this manually. So we can make use of the createAsStripeCustomer method. createAsStripeCustomer. Okay. And then we have to attach a payment method to that. So we can do that as well with the updateDefaultPaymentMethod. And we already have that coming through. So we can do requestPaymentMethod. Okay. So let's try that again. And let's see if it works this

payment method. And we already have that coming through. So we can do request payment method. Okay. So let's try that again. And let's see if it works this time. And it looks like it does. So let's check our backend. Check our payment here. There's a new one. And there it is. And now we have a customer associated with this. So let's check out our customers. And there's that new customer as well. So now let's take a look at how we can generate invoices from within our app. So if you scroll down the documentation here, you'll see we can make use of this invoices method right on the User. And there's also an example of displaying the invoice information in a table. So let's do that. So let's make a new menu

Invoices Page and Table2:34

invoices method right on the User. And there's also an example of displaying the invoice information in a table. So let's do that. So let's make a new menu item like we've been doing. So navigation. Let's make a new one here called invoices. And this should work for the subscription based charges as well. So invoices. Let's name it invoices. Okay. Let's go to our routes file. Let's grab this one. Let's name it invoices. Okay. And let's go ahead and duplicate one of the views and use it for the invoices table. And let's do PA6. And let's paste in that table that is here. Okay. And we also have to pass in the invoices from our routes file. So let's do that here. Let's say invoices is off User invoices. Okay. And that should work. Hopefully. See invoices here. Okay. And it's not styled.

Generate Invoice PDF3:40

routes file. So let's do that here. Let's say invoices is off user invoices. Okay. And that should work. Hopefully. See invoices here. Okay. And it's not styled but it should work. Or displays at least. Now we have to add the code to generate the PDF. And that is right underneath here. So we can just grab this, put it in our routes file. And you can change this if you want for vendor and product but that's fine for me. And now this should work and generate an invoice. So if we download this invoice we'll see a PDF that downloads. And here is the information about our charge. So like I said it should work for subscriptions as well. So let's log in with the other user that has a subscription with us. And let's see if it works as well.

Test Subscription Invoices4:47

well. So let's log in with the other User that has a subscription with us. And let's see if it works as well. Invoices. And there it is. $20. Should be $20 a month. And it should also have the period for which they are charged for. And there it is. So yeah really easy to generate invoices when you're using Cashier.

دوست دارید گاهی خبرهای Laracasts را ایمیل کنیم؟