WEBVTT 00:01.890 --> 00:08.580 So I'm sure you've noticed this already, but this payment succeeded function, this method is not going 00:08.580 --> 00:15.030 to be able to be used for both the virtual terminal and for buying products simply because we have this 00:15.030 --> 00:16.290 line right here on line. 00:16.290 --> 00:18.330 Forty three in payment succeeded. 00:18.660 --> 00:24.000 And that's widget ID because of course we don't have a widget ID on the virtual terminal that's just 00:24.000 --> 00:27.850 used for making a credit card transaction of pretty much any sort. 00:28.410 --> 00:34.440 So that means we're probably going to have to have two handlers, one for virtual terminal and one for 00:34.440 --> 00:35.400 buying a widget. 00:36.210 --> 00:44.570 Now it seems to me that all of this everything from pretty much well past form all the way down to about 00:44.760 --> 00:47.430 here where we get the expiry year. 00:47.880 --> 00:49.320 We're going to have to do that twice. 00:49.320 --> 00:52.100 And I'm not a big fan of code duplication. 00:52.110 --> 00:53.790 So let's simplify this. 00:56.880 --> 01:01.690 By making a new function that does all this stuff for us and then we can reuse it as many times as we 01:01.690 --> 01:02.070 need to. 01:02.820 --> 01:08.940 So I'm going to come up here just before the payment succeeded function and I'm going to create a new 01:08.940 --> 01:15.030 type because I think it's simpler and it will certainly make calling things a lot simpler if we take 01:15.030 --> 01:20.280 all of this kind of information, first name, last name, email and so on and so forth, and put that 01:20.280 --> 01:22.910 at its own type and then we can pass a single variable. 01:23.310 --> 01:29.760 So I'm going to call that type transaction data and it will be a struggle. 01:30.840 --> 01:41.730 And we'll give it some members first name, which will be a string last name to also be a string email 01:42.330 --> 01:46.950 string and then payment intent 01:49.770 --> 01:53.510 I.D. And I'm going to call it payment intented because that's what it is. 01:53.520 --> 01:55.500 It's not the true payment content itself. 01:55.670 --> 02:06.000 That's also a street payment method ID which will which will also be a string then the amount payment 02:06.120 --> 02:07.680 amount and that will be in it. 02:09.510 --> 02:11.160 We're also going to be the payment currency, 02:15.090 --> 02:28.050 which will be a string the last four digits, which will also be a string the expiry month, which is 02:30.090 --> 02:34.860 the expiry year which will be attached and the bank return to. 02:44.250 --> 02:45.490 Which will be a strength. 02:46.410 --> 02:53.010 OK, so that'll be our type no, we'll create a function that I can call from both of the two handlers 02:53.010 --> 02:58.110 that will handle actually charging a credit card or handling the posted data after we charge a credit 02:58.110 --> 02:58.350 card. 02:58.950 --> 03:03.690 So it'll be a function with the receiver of application pointed to application. 03:04.020 --> 03:07.770 And I'll call this get transaction data. 03:09.030 --> 03:11.390 And it's going to take only one parameter. 03:11.400 --> 03:16.890 And that will be our request because that's all I really need, which is a pointer to a request. 03:17.850 --> 03:24.300 And it will return transaction data, the type we just created and potentially an error. 03:25.530 --> 03:29.620 OK, so scroll this up and give ourselves some room. 03:30.840 --> 03:35.910 First thing I'll do is create an empty variable var and I'll call it taxand data for transaction data 03:35.910 --> 03:37.340 of type transaction data. 03:39.070 --> 03:45.630 Then I'll pass the form and I can just actually want to split the screen here and scroll down a bit 03:46.290 --> 03:49.700 and get this information so I can copy and paste just to save some typing. 03:50.490 --> 03:54.990 So we'll pass the form the request and we're not going to return. 03:54.990 --> 04:00.270 Nothing will return to some data and the error which is error. 04:03.350 --> 04:09.650 And after that, I'll actually grab the information now I can grab the posted data right here, all 04:09.650 --> 04:12.170 of this, but not including would you do? 04:12.620 --> 04:13.610 I'm going to cut it out of that 04:16.430 --> 04:18.500 and we'll fix this function up after the fact. 04:20.480 --> 04:21.790 So I get my data. 04:21.800 --> 04:26.420 And, of course, you might want to put some validation in here, maybe have another function that validate 04:26.420 --> 04:32.620 your data, returns a boolean and don't go any further and get transaction data if you don't have this 04:32.630 --> 04:33.770 necessary information. 04:33.770 --> 04:36.560 But I'll leave that as an exercise for you because it's not very difficult. 04:36.590 --> 04:45.080 OK, now I'm also going to at this point, since I have the amount, we're in this function right there, 04:46.250 --> 04:53.330 this is where I will actually turn the amount from a or the payment amount from a string to an end, 04:53.330 --> 04:54.290 because that's what I need it to be. 04:54.440 --> 04:55.580 So I might as well do that right now. 04:56.600 --> 05:03.570 Then I can grab all of this information card right down to here and cut it out. 05:03.620 --> 05:08.870 So this is information that I'm going to be doing every time I process a transaction or create my card 05:08.870 --> 05:13.610 variable, get my payment in, get my payment method and then get the information from the payment method. 05:13.620 --> 05:20.060 So I'll cut that out of there and I'll paste that right in here and I'll have to fix my returns. 05:20.060 --> 05:22.150 So I'll grab the return from this error. 05:22.160 --> 05:26.900 Check up here and put it down here and down here. 05:29.840 --> 05:31.800 And now that I have all this information. 05:34.090 --> 05:39.730 I can create or populate my tax and data variable and declare it at the top of this function, and data 05:40.420 --> 05:45.720 will now be equal to transaction data and I'll populate all of its fields. 05:46.000 --> 05:48.370 First name will be first name. 05:50.320 --> 05:54.250 Last name will be last name from the forum post. 05:54.940 --> 05:56.470 Scroll up a bit and give us some room. 05:59.350 --> 06:00.790 Email will be email. 06:03.360 --> 06:09.420 Payment intented will be our payment content right there. 06:12.560 --> 06:15.110 Payment methods will be our payment method. 06:21.280 --> 06:24.730 The payment amount will be amount, which is a it. 06:26.980 --> 06:30.820 Our payment currency will be our payment currency. 06:35.310 --> 06:38.700 The last four digits will be last for. 06:41.320 --> 06:50.500 Expiry month will be cast to an end expiry month because remember, that comes as you sixty four expiry 06:50.500 --> 06:53.260 year will be expiry year. 06:57.140 --> 06:59.990 And the bank return code, I'll have to find that. 07:02.480 --> 07:12.350 Right there, PPI charges, data index, zero I.D. So now we have that and all we have to do at this 07:12.350 --> 07:25.310 point is safe return to sanity or data and know, OK, so now we have this function that we can use 07:25.310 --> 07:26.240 wherever we need to. 07:26.270 --> 07:27.290 So let's give it a comment. 07:33.470 --> 07:37.220 Gets transaction data from post and strength. 07:38.390 --> 07:41.920 OK, so we have lots of errors to fix now, but none of that is terribly difficult. 07:43.790 --> 07:44.780 So we'll just scroll down. 07:44.780 --> 07:45.740 The payment succeeded. 07:49.280 --> 07:51.950 And all we really need to do is we've got to get our widget. 07:52.190 --> 07:53.730 We'll use this one for payments. 07:53.750 --> 07:56.380 Payment succeeded will be the handler for buying a widget. 07:56.390 --> 07:59.690 So we'll leave the widget ID bit here on line one of five. 07:59.870 --> 08:06.400 But all we need to do now is create a variable, which I'll call text and data and potentially an error. 08:06.620 --> 08:11.270 And those are assigned the value of from app get transaction data. 08:11.540 --> 08:16.690 And we handed our request, which is ah, and we'll check for an error. 08:18.020 --> 08:21.110 So I'll just copy and paste this error code right here. 08:23.200 --> 08:27.560 And at this point, it's just a matter of fixing up the errors and deleting things we don't need. 08:27.830 --> 08:38.120 So I'll close this so we have more room and this becomes text and data, first name and text and data, 08:40.160 --> 08:43.710 last name and text and data, email. 08:44.460 --> 08:49.880 Now, obviously, you could just pass transaction data, right, to save customer and simplify this 08:49.880 --> 08:50.810 and pass one argument. 08:51.230 --> 08:58.970 But this is simple enough and we still need our customer I.D., but our transaction becomes we don't 08:58.970 --> 09:00.940 need this convert to an amount anymore. 09:02.510 --> 09:05.300 This becomes text and data data about. 09:10.030 --> 09:14.740 Payment amount, and this becomes tax and data payment currency. 09:20.570 --> 09:24.740 And this is tax and data the last for. 09:28.180 --> 09:31.240 And this becomes tax and data expiry month 09:34.540 --> 09:35.650 and expiry year. 09:43.070 --> 09:44.510 And the bank return code. 09:50.860 --> 09:52.960 Payment intented, I don't know what they're. 09:55.090 --> 09:55.630 There we go 09:58.540 --> 10:01.090 to some data, the data that 10:04.000 --> 10:05.200 came at intented. 10:08.510 --> 10:17.260 Antioxidant data, the payment methodology that transactionally stays, are stateside, stays as to 10:17.750 --> 10:27.380 so now we have our transaction and down here when we create an order, this becomes tax and data payment 10:27.380 --> 10:27.920 amount. 10:33.350 --> 10:39.560 And what changes at this point is we're not going to be passing a map string interface to the session 10:39.560 --> 10:40.100 anymore. 10:40.130 --> 10:46.630 Instead, we'll just past hour or text and data so all of this goes away. 10:52.620 --> 11:01.830 And a receipt becomes tax and data, which means we need to go register that type in may not go, so 11:01.830 --> 11:08.190 I'll just change this from a map string interface to transaction data. 11:10.170 --> 11:15.430 And of course, since we're registering it, we have to give it the curly brackets that's in Mingo. 11:16.290 --> 11:17.790 So back to Handler's. 11:17.790 --> 11:19.110 Is there anything else we need to do? 11:19.380 --> 11:20.180 There it is. 11:20.730 --> 11:24.930 So we'll get rid of the word should here because we're now writing it to the session. 11:26.250 --> 11:27.870 So that's pretty good. 11:27.900 --> 11:33.390 Now, the last thing will have to change, of course, is back in our template where we have a receipt 11:33.390 --> 11:33.900 page. 11:33.930 --> 11:37.550 We can't read things from index data because that doesn't exist anymore. 11:37.950 --> 11:42.960 So instead, all we do to make it simple by declaring a variable. 11:46.620 --> 11:55.250 Which I'll call Dollar Sign Texan, and that's a sign the value of index is not data I'll look for. 11:56.970 --> 11:59.100 I will have to put that in the data variable shortly. 11:59.100 --> 12:04.050 But let's just change this first so this becomes a dollar sign. 12:06.180 --> 12:09.450 And I called it payment intent. 12:09.790 --> 12:13.610 I guess that's that's what our transaction data type. 12:14.280 --> 12:17.550 And this is dollar sign. 12:20.700 --> 12:21.750 First name. 12:24.970 --> 12:27.940 Dollar sign and last name. 12:31.190 --> 12:35.690 Dollar sign to send email with capitally. 12:38.640 --> 12:44.280 Payment method becomes dollar sign, scientism payment method ID. 12:48.300 --> 12:55.380 And this is dollar sign, tax and payment amount unless format that has currency since we wrote that 12:55.380 --> 12:58.320 function a while ago, format, currency. 12:59.400 --> 13:03.130 That's the function that's available to our templates that we defined quite some time ago. 13:03.150 --> 13:08.570 Now, the currency dollar sign Texan. 13:11.700 --> 13:13.710 Payment currency. 13:17.430 --> 13:20.640 Dollar sign and last for. 13:24.470 --> 13:29.010 All our sovereignty and not thank return. 13:29.040 --> 13:29.610 Code. 13:33.160 --> 13:40.660 Dollar sign and dot expiry month and expiring expiry month. 13:44.770 --> 13:48.340 And dollar signs and expiry year. 13:48.760 --> 13:56.230 OK, back to our handlers to get the correct type into what we're passing to this template, and that, 13:56.230 --> 13:57.900 of course, is the receipt page. 13:58.210 --> 14:00.850 So this gets changed. 14:01.030 --> 14:05.410 We're still looking for a receipt, but we're not converting it or casting it to a map string interface 14:06.100 --> 14:09.280 or casting it to a transaction data. 14:11.410 --> 14:19.420 And we'll just call this Texan now, we'll create our data type, which is a map data will be assigned 14:19.420 --> 14:24.430 a value of make a map string interface. 14:27.220 --> 14:30.610 And we simply put that in the map, put it on the map. 14:30.610 --> 14:36.890 So data and we're looking for direction equals accept. 14:40.680 --> 14:42.810 And that should do it unless we have some typos. 14:42.840 --> 14:47.520 So let's start or stop our applications or I'll say it's not running now, so make start. 14:51.790 --> 14:53.770 There goes a comp. That's a good sign. 14:54.100 --> 14:56.900 Let's go back to our Web browser, reload this page. 14:56.960 --> 15:00.280 Make sure it's current and we'll make this one. 15:01.150 --> 15:12.520 Dick Grayson, Dick at Grayson, dot com, Dick Grayson and our standard credit card number 15:16.300 --> 15:21.390 zero seven, say twenty eight and some CDC. 15:22.240 --> 15:24.670 And if we get everything right, this should still work. 15:29.980 --> 15:35.980 And it does, and the payment amount is formatted properly and everything looks great, so the next 15:35.980 --> 15:42.130 step, of course, is to go back to our handlers and write one that's specific for virtual terminal, 15:42.130 --> 15:46.230 because the one we have here, which is called Peyman, succeeded. 15:46.240 --> 15:46.940 That won't work. 15:46.960 --> 15:51.000 We don't have a widget ID and actually don't have first name and last name. 15:51.010 --> 15:53.030 So we'll have to make that change as well. 15:53.230 --> 15:57.160 And those are pretty straightforward changes and we'll take care of them in the next lecture.