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

From Tests to Browser0:00

Over the last videos, we have written a lot of tests just to make sure that the payment process for a User is working as expected. And we have written some tests to make sure that there is this checkout overlay included inside our application, because this now comes from Pedal. And then we've also made sure that when we get a request from Pedal, that we're going to handle this properly and that there is a new User and we're going to send out a mail and there is a new purchase inside our database. And all of the tests are telling us that everything is working as expected. So this is already pretty good, but it's always a good idea to also test the whole process in the browser yourself, just to make sure that everything is working as expected.

Setting Up Local Tools0:35

So this is already pretty good, but it's always a good idea to also test the whole process in the browser yourself, just to make sure that everything is working as expected. And in order to do this now locally with our local application, there are a few things which we're going to need. So first, we're going to need a public URL so that the service Pedal can send us a request. And what I'm going to use here is a tool called Expose by BeyondCode, which just gives us this local tunnel here and this public secured URL, which we can use. And it also comes with this nice dashboard here where we can see all the requests that come into our application. And also by BeyondCode, I'm going to use Halo, which is an email tool for testing emails.

comes into our application. And also by BeyondCode, I'm going to use Halo, which is an email tool for testing emails. So all the emails that we're going to send out from our application will be catched by this Halo tool here. And we're going to see all the emails here because first we want to make sure that our email looks as expected, but we also want to make sure that we send out not really emails to our users, but we want to test them here. So this is also a nice tool by BeyondCode to check out. And then last, we also need to make sure that we're going to tell Pedal now, again, I'm here in the sandbox account for our courses, that after purchasing one of our courses,

Configuring Pedal Webhooks1:47

And then last, we also need to make sure that we're going to tell Pedal now, again, I'm here in the sandbox account for our courses, that after purchasing one of our courses, that a request should be sent to our webhooks endpoint. And let's set this up now for one of our products. I'm going to choose here level for beginners. And you can see I have already tested this with a different local URL. So we're going to change now this webhook URL, and we still need the webhooks endpoint. Now I'm going to bring in here this new URL, this new local tunnel to our application. We're making a POST request, and we also need two fields here, the email field. Here on the right side, you can define some additional fields here sent by Pedal.

We're making a POST request, and we also need two fields here, the email field. Here on the right side, you can define some additional fields here sent by Pedal. And we want the email, and we also want the name here. Let's test this. We should see a successful response. Yes, we do. So this means we can save this now. All right. And then also in our application database here, you can see we have our courses. We only have our testUser.

And then also in our application database here, you can see we have our courses. We only have our test User. And now we also have this one from the test webhook call, which we just made. So let's get rid of this one here. And we also have this one from the test webhook. So this was already working, but we want to test it again with the real process, through the real checkout overlay API. But now we can see that all those fields are empty now. And then we can check again after the real payment request if this also looks as expected. All right, let's go back to application, level up for beginners course.

Running a Test Purchase3:16

And then we can check again after the real payment request if this also looks as expected. All right, let's go back to application, level up for beginners course. And now we want to buy one of these courses. So this one here, and I'm going to use an email. This does not exist, but we don't care. And then I also have to, I'm going to define here a coupon code because this will be easier than always thinking about what the test credentials are for the credit card. So let's bring this in here, which I created before. So this is a coupon, which I created in pedal, which I can use multiple times for testing. And now we don't have to pay anything.

So this is a coupon, which I created in pedal, which I can use multiple times for testing. And now we don't have to pay anything. And now when we click checkout, again, we should see a request coming in. Maybe let's clear this so that we see the new request coming in. And now let's check this out. Okay, it looks good here. We also see that a request came in here. We also got a 200 response. This already looks good. Here we can again check all the information which we got, like what order, what product.

Verifying Webhook Results4:18

This already looks good. Here we can again check all the information which we got, like what order, what product did the User buy. Here we see the productId, which we have stored in our application, and also the signature, which we need in order to make sure that this request comes from pedal itself. All right, so this looks good. Let's also check the database. We should see a new User here. Let's refresh. Yes, here we have this new User.

Let's refresh. Yes, here we have this new User. That's good. We see the webhook call here with all the information from the payload, from the request, which is always good for debugging. And then we also should see now here a purchase course. User three has bought the course with the ID number one. User three is right, and let's check courses. Course number one is also level for beginners. Okay, cool.

Checking Emails in Halo5:02

Course number one is also level for beginners. Okay, cool. So this all worked. And last, we can also check out now Halo, and we can see that we have two emails here. The first one, again, is from testing the webhook, and now this is the one where we have purchased the course with my testUser here, and we see the email and the link for logging in. So this has also worked. All right, perfect. So we've now made sure that also through the browser as a user would purchase a course.

All right, perfect. So we've now made sure that also through the browser as a user would purchase a course that this process is also working. Of course, this was now just locally. I would always do this also when the application, when your platform is live, just to make sure that also there's everything working as expected. But yeah, it's good to see that the test that we wrote already helped us a lot to get into this process where we can really purchase a course through the browser. Great. Thank you.

Great. Thank you. Great.

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