A developer refactors a payment system to use Stripe Checkout sessions instead of direct credential handling. The process includes updating Data Transfer Objects (DTOs), implementing event-based webhook handling, and creating a new service method to securely initiate hosted payment flows for reservation management.
Length 16:25
Captions English (Generated), Spanish (Auto-translated), French (Auto-translated), Korean (Auto-translated), Portuguese (Auto-translated), Vietnamese (Auto-translated) #stripe #coding #software development #typescript #backend #payment integration #webhooks #dto #nest.js #programming
0:00 All right, so in this section, I wanna show you the latest 0:03 recommended approach for accepting payments inside of Stripe. 0:08 Now, as you know, in this course, we originally are accepting 0:11 payments on our create reservation 0:15 DTO by passing in the charge DTO 0:18 directly with the user card details on the 0:22 request. Now, this is not the fully recommended flow 0:25 anymore as this leaks potential user-sensitive data, the 0:29 payment credentials over the wire. 0:32 And so while I do still want to keep the original implementation 0:36 around, 0:37 I do also want to show you the latest and greatest approach, which 0:41 is using Stripe checkout sessions, which 0:44 essentially is Stripe's hosted checkout flow 0:48 that allows us to enter in our payment details on 0:52 Stripe's hosted URL, and then what we do is set up 0:55 webhooks on our application to receive 0:58 updates from Stripe when events occur, like the user 1:02 successfully processed the payment, and that allows us to react to 1:07 the payment. And so in this section, we'll go ahead and implement this latest 1:11 payment flow using the latest Stripe 1:14 recommended practices with the Stripe hosted checkout session 1:18 and webhooks. So let's go ahead and get started with this. 1:22 Now, the first change that we'll make is by heading into our common 1:25 library, 1:26 and let's go into our common DTO directory where 1:31 we have our create charge. Now, of course, right now we know we're 1:34 accepting the credit card details as required. 1:38 Now what I wanna do is make this optional. 1:40 So we can still maintain our original flow to 1:44 process payment details directly. 1:47 However, this is no longer required. 1:49 If we don't pass this card, then we're gonna use the new 1:52 Stripe hosted checkout flow. And so we'll also 1:56 add the is optional decorator 2:00 and get rid of is defined here. So this is gonna make sure that the
The rest of the transcript is for members.
Sign in