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

Charging a Paddle Product0:00

Okay, let's take a look at how we can do single charges and also receipts. So we can make use of this charge method. But what I want to do is make use of this chargeProduct method and charge a product that we created on the Paddle backend. So let's go ahead and do that. Let's go into our Paddle backend. And as you see, I've already created a product here, Laravel ebook for $29. And we need the product ID. So let's go ahead and grab this. So depending on your product, in this case, it's just an ebook or a PDF download.

So let's go ahead and grab this. So depending on your product, in this case, it's just an ebook or a PDF download. You can also specify other things like generating a license key if your product is digital. But like I said, for this case, I just want the User to be able to download the ebook once they have paid for the product. So let's go ahead and do that. So I already have a route here for a charge. So let's do that. So let's go into our routes file and let's go into our charge here. And let me just paste in the ID.

Adding Charge Route and View0:53

So let's go into our routes file and let's go into our charge here. And let me just paste in the ID. And let's grab the code for a single charge. Just do this. And space that in here. And this is going to be charge. And this is the product ID. Okay. And in the view, we just have to put the paddle button in there. So let's do that.

And in the view, we just have to put the paddle button in there. So let's do that. And charge Blade PHP. Just replace this. And this should show the button. Undefined variable. So let's just say auth user here for the login user. Okay. And there's the button. And again, I have to enter my postalCode.

Testing Checkout with Coupon2:15

So let's see if we can use this coupon. So add a coupon, say free ebook, add a coupon. And it says our product is free. So my tunnel is still running with expose here. So the endpoint should be hit as well. So let's go ahead and complete this checkout and see if it works. Okay. So it says completed successfully. There is a new request to the webhook. And let's see if that was entered in our database.

Verifying Webhook and Records2:42

There is a new request to the webhook. And let's see if that was entered in our database. So in this case, it's not a subscription, but it should be in the receipts table. And there you see it here. Let's also check our Paddle back end. So let's go to customers, and there should be a new one here. Should be two for the one we did earlier and for this current one. Actually, it's not going to show in subscribers. It'll show in transactions. And there it is.

Displaying User Receipts3:36

So yeah, pretty easy to set up single charges and delivering your paid product to your customers. So let's also take a look at receipts, which we also took a look at for Stripe. Again, same process. Go down here. There's a section for receipts. So let's grab the receipts, pass it into the view, and then I'll put it in this table here. So I have a view for receipts. Let's just go ahead and pass that in here. So I'm going to say receipts, and it's going to be off userReceipts off userReceipts.

Fixing Receipts Retrieval Bug4:04

So I'm going to say receipts, and it's going to be off User receipts off User receipts. So in this case, there should be two. Actually, let me just dd this because I think there is a bug here or maybe just a typo in the documentation. So this should return a collection of receipts. So let me just dd this. Okay. But it's actually returning the relationship, which we don't want. Not sure if that's a typo or if it's a bug in the code.

But it's actually returning the relationship, which we don't want. Not sure if that's a typo or if it's a bug in the code. So receipts. Sorry, there should be a comma. Let's try it again. Okay. And you see it's the relationship here, and we don't want that. So it should just be receipts without the method signature. So let's see if we get the collection here. And we do.

So let's see if we get the collection here. And we do. So that's what we want. So let's pass that through. And now in our receipts.blade.php, we can just put the table in there. So let me just grab this from here, and that should display our receipts. So let me just paste that in, and we should have two. And this should be able to download our receipts properly. So let's give that a try. Okay.

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