WEBVTT 00:01.620 --> 00:07.050 So we've created the necessary functions in our cards package to create a customer and subscribe the 00:07.050 --> 00:08.100 customer to a plan. 00:08.400 --> 00:14.870 So now let's updater create customer and subscribe to Plan Handler, which is in Handler's Dash APG. 00:14.920 --> 00:19.410 So let's update this so we can actually try to subscribe someone to a plan. 00:19.980 --> 00:24.660 So the first thing we're going to have to do obviously is the same sort of thing we did up here and 00:24.660 --> 00:26.170 that is create a card. 00:26.190 --> 00:30.080 So let me copy this code and this is from get payment intent. 00:30.390 --> 00:35.450 We need to create and set up our card package with the necessary values. 00:36.030 --> 00:40.310 So back down here, I'll do it right after this info log. 00:41.070 --> 00:42.630 So I create the card variable. 00:42.660 --> 00:46.980 Now, obviously, it's not payload currency because up here we call the data, so I'll just change that 00:47.010 --> 00:47.420 data. 00:50.700 --> 00:51.520 So we have a card. 00:51.960 --> 00:55.710 Now let's get our customer first, our customer. 00:55.710 --> 01:04.650 So Strib customer, a message and potentially an error all come from card dot, create customer. 01:05.220 --> 01:11.640 And that requires our payment method and that data payment method and it requires the email which is 01:11.640 --> 01:14.750 dated email, which we pulled rid to the adjacent file. 01:15.300 --> 01:20.880 So let's check for an error and we'll just copy this error checking code and paste it right here. 01:24.100 --> 01:26.110 So we have our customer, if everything went well. 01:26.140 --> 01:27.790 Now we need our subscription ID 01:30.640 --> 01:37.240 and potentially an hour and those come from KO'd Dot subscribed to plan and that takes a few parameters. 01:37.250 --> 01:40.690 It takes our straight customer, which we just got straight customer. 01:41.470 --> 01:43.840 It requires the plan data dump plan. 01:44.620 --> 01:51.430 It requires the email dated email, and it requires the last four digits data don't last for. 01:52.000 --> 01:55.440 And then we actually put card time, but we never actually bothered to get that. 01:55.450 --> 01:56.800 So I'll just pass an empty string. 01:57.340 --> 02:01.270 OK, and again, check for an error so I'll just paste. 02:01.270 --> 02:07.490 But I'd copied a moment ago and if everything went well, we should be able to go after info log print 02:07.540 --> 02:10.450 line and print out our subscription. 02:11.770 --> 02:17.530 So subscription ID is and then just subscription. 02:20.230 --> 02:24.550 And of course the last thing I need to do is just comment this line out because we actually declare 02:24.550 --> 02:26.980 a message variable up here on line 119. 02:27.550 --> 02:31.800 So I'll comment this and let's try running this. 02:31.810 --> 02:33.510 So make sure everything is stopped. 02:33.680 --> 02:34.240 Mike, stop. 02:34.510 --> 02:36.790 It is Mike start. 02:39.850 --> 02:40.460 And there we go. 02:40.480 --> 02:44.080 It's running now, we'll try running a transaction and it's not going to work. 02:44.080 --> 02:47.860 And I'm doing this quite deliberately because I want to show you the kinds of error messages you get 02:47.860 --> 02:48.640 back from Stripe's. 02:48.640 --> 02:55.990 So I'll clear the console and we'll go to the products menu and subscription and I'll clear the JavaScript 02:55.990 --> 02:58.590 console and I'll try doing something. 02:58.600 --> 03:09.220 So Sam Smith, Sam at Smith dot com, Sam Smith is the name on the card and our standard for two. 03:11.950 --> 03:17.650 And make this an expiry and give it some value here for the CVC and it's not going to work, but let's 03:17.650 --> 03:20.020 see what we get for a message back from strike. 03:23.070 --> 03:27.630 So we get an error over here unexpected, and that's to be expected because we're not doing really good 03:27.630 --> 03:29.160 air handling at this point. 03:29.590 --> 03:33.070 But let's go back and look at the console and you see you get a message here. 03:33.900 --> 03:37.650 So first of all, we have our printing out the values that we got from the JSON. 03:37.660 --> 03:38.330 So that works. 03:38.340 --> 03:39.600 And then we get an error here. 03:39.600 --> 03:41.850 Error request error from stripe status. 03:41.850 --> 03:43.650 Four hundred code resource missing. 03:44.190 --> 03:45.090 And on it goes. 03:45.090 --> 03:46.410 No such plan. 03:46.860 --> 03:52.560 Now, if we go back to our Web browser and we go to our products and we get them looking at test data 03:52.560 --> 03:57.720 and I bring it by Brons widget plan, what we actually copied and you may have noticed this, I did 03:57.720 --> 03:58.580 it quite deliberately. 03:58.590 --> 04:00.930 There's no copy button here next to this. 04:00.930 --> 04:05.980 And this is what we have in the database when in fact, what we want is this the price. 04:06.010 --> 04:14.670 So let me copy that and switch over to my database and look at widgets and let's change its plan from 04:14.670 --> 04:15.310 this product. 04:16.260 --> 04:24.660 So I'll select all delete and paste in the correct one, OK, and save that and go back to our Web browser 04:25.020 --> 04:25.900 and we'll try again. 04:25.920 --> 04:28.260 So products, subscriptions. 04:28.680 --> 04:33.450 And I'm going to go back to Stripe for a minute just to look at subscriptions. 04:33.630 --> 04:38.180 And if we go to, say, customers and look at subscriptions. 04:38.880 --> 04:41.220 So the most recent one is Jack Nimble. 04:41.750 --> 04:43.920 That's the most recent subscription that I have. 04:44.200 --> 04:48.210 Let's go subscribe at this point and we'll probably get a JavaScript error after the fact, but that 04:48.210 --> 04:48.750 doesn't matter. 04:48.840 --> 04:49.810 Fixed that up shortly. 04:50.640 --> 04:59.820 So this time we'll do Sam Smith again and Sam at Smith dot com, Sam Smith with a credit card. 05:06.330 --> 05:08.190 And now let's pay twenty dollars a month. 05:14.310 --> 05:16.170 So we got our response back. 05:16.290 --> 05:16.690 OK? 05:16.740 --> 05:20.280 And it kind of stopped at this point, nothing else happens because we're not telling it to do anything 05:20.280 --> 05:20.550 else. 05:20.910 --> 05:24.870 But if we go back to subscriptions and refresh this page. 05:27.830 --> 05:31.740 We should have a new subscription, Sam Smith there. 05:31.910 --> 05:35.050 We have actually subscribed a user to a plan. 05:36.140 --> 05:40.820 So as you can see the messages you get back from Stripe when something goes wrong are very good. 05:40.970 --> 05:50.030 For example, if I go back to my cards package, if, for example, I forgot to in this one, forgot 05:50.030 --> 05:54.140 to set my secret, you'll actually get a message back from Stripe, which is extremely readable and 05:54.140 --> 05:56.070 tells you exactly what went wrong. 05:56.600 --> 06:01.250 So if you're having trouble running transactions or whatever through strike, pay close attention to 06:01.250 --> 06:05.060 the error messages you get back from strike because they're extremely helpful. 06:05.750 --> 06:06.100 All right. 06:06.110 --> 06:06.950 We're a lot closer. 06:06.980 --> 06:08.600 We'll move on in the next lecture.