1
00:00:00,330 --> 00:00:07,830
Beautiful, and once we're clear on what we need to do, let's go back to Strahm controller and let's

2
00:00:07,830 --> 00:00:09,900
start by importing the stripe.

3
00:00:10,200 --> 00:00:16,560
And you're not in order to avoid name collisions, want to go here with a stripe controller and make

4
00:00:16,560 --> 00:00:19,500
sure that I export the correct name as well.

5
00:00:19,830 --> 00:00:23,250
And that top I'm going to set up a stripe.

6
00:00:23,550 --> 00:00:26,670
It's going to be equal to requires that we're looking for a package.

7
00:00:27,090 --> 00:00:28,860
Name, of course, is Stripe.

8
00:00:29,190 --> 00:00:33,190
And and here we want to ride away past in our secretory.

9
00:00:33,540 --> 00:00:41,160
So we set up another set of parentheses and then we'll go with process that we and my variable name

10
00:00:41,160 --> 00:00:43,440
is Stripe on the Squawky.

11
00:00:43,830 --> 00:00:51,920
So that and the stripe underscore Anqi once that is in place inside of the strap controller.

12
00:00:51,930 --> 00:00:57,000
Like I said, we need to do two things we need to calculate or amount.

13
00:00:57,490 --> 00:01:03,540
And this is normally where we communicate with the database and I'll talk about it in the second and

14
00:01:03,540 --> 00:01:04,019
second.

15
00:01:04,319 --> 00:01:12,390
We want to send that amount, whatever is the total or amount to the stripe and we do that using the

16
00:01:12,390 --> 00:01:16,650
stripe, then payment intent and then dot create.

17
00:01:16,980 --> 00:01:23,040
So let's start here by just getting the values out of the rock, that body, which you can clearly see

18
00:01:23,040 --> 00:01:23,580
in the console.

19
00:01:23,580 --> 00:01:23,940
Correct.

20
00:01:24,240 --> 00:01:33,660
So we're looking for the purchase that total on the score amount and comma and shipping fee as well.

21
00:01:33,690 --> 00:01:39,630
So shipping underscore and fee and all of that is coming from that body.

22
00:01:39,930 --> 00:01:44,160
Before we send anything to the stripe, we'll set up some kind of functionality.

23
00:01:44,160 --> 00:01:50,700
In this case, she's going to be calculate or amount and as of this coming from their docks as far as

24
00:01:50,700 --> 00:01:51,210
the naming.

25
00:01:51,510 --> 00:01:56,790
So we're going to go and calculate or amount and this is going to be a function.

26
00:01:57,240 --> 00:02:02,100
Now, normally you'll communicate with your backend, with a database y.

27
00:02:02,100 --> 00:02:02,100
Why?

28
00:02:02,510 --> 00:02:08,310
Well, because you can manipulate these values on a fronton or just because Fronton says that, yes,

29
00:02:08,310 --> 00:02:15,540
the purchase is, I don't know, whatever this array of values and the ideas here and the prices here

30
00:02:15,840 --> 00:02:17,510
doesn't mean that it is correct.

31
00:02:18,090 --> 00:02:23,220
So you should always, always, when it comes to money, verify this with your own back.

32
00:02:23,240 --> 00:02:30,210
And now since this is just a demo project and we didn't set up our own database with the product and

33
00:02:30,210 --> 00:02:33,060
all that, of course we're not going to do that in our case.

34
00:02:33,970 --> 00:02:39,160
We'll just combine both powers will combine the total amount as well as the shipping fee.

35
00:02:39,550 --> 00:02:44,130
So this is going to give me the total amount for the purchase.

36
00:02:44,140 --> 00:02:44,560
Correct.

37
00:02:44,560 --> 00:02:51,370
But normally what you're going to do, you'll iterate over the list, you'll take the ideas, and then

38
00:02:51,370 --> 00:02:58,600
you'll communicate with a database and get back the correct prices, because, again, the user on the

39
00:02:58,600 --> 00:03:01,440
front end can easily manipulate with the values.

40
00:03:01,450 --> 00:03:05,710
But since we just have the demo project, we won't do that.

41
00:03:05,710 --> 00:03:13,240
In our case, we'll just go with return and we're returning total amount plus shipping.

42
00:03:13,720 --> 00:03:19,630
So this is going to give me the total for my purchase, correct, than.

43
00:03:20,650 --> 00:03:28,330
We want to go with Consed and I'm going to call this payment intent, and that is equal to a weight,

44
00:03:28,690 --> 00:03:33,680
that stripe, that's the variable name than payment intent.

45
00:03:34,060 --> 00:03:36,970
So payment intent than DOT.

46
00:03:37,240 --> 00:03:41,350
And we're looking for create method in the create method.

47
00:03:41,350 --> 00:03:48,820
We pass in object with the appropriate amount which we're going to set it equal to calculate or amount.

48
00:03:49,120 --> 00:03:56,950
And yes, as a sign of course you can invoke your total amount plus shipping fee directly in the object,

49
00:03:57,280 --> 00:03:59,050
or you can set up here a variable.

50
00:03:59,350 --> 00:04:04,930
The idea is that normally you'll do more things in this calculate or amount.

51
00:04:05,140 --> 00:04:07,480
So let's invoke, calculate or amount.

52
00:04:07,660 --> 00:04:11,640
This is going to get us a total and then we need to provide the currency.

53
00:04:12,400 --> 00:04:18,660
So we're going to go here with currency and we're looking for you as the let's save it.

54
00:04:18,940 --> 00:04:27,220
And as far as the response, I'm going to go with Araz Dodgson and here let's set up a object and let's

55
00:04:27,220 --> 00:04:28,510
call this client secret.

56
00:04:28,510 --> 00:04:29,590
And this is important.

57
00:04:30,010 --> 00:04:35,210
Make sure that the name is exactly the same, because otherwise the front end is not going to work.

58
00:04:35,230 --> 00:04:40,330
So clients record is equal to payment intent, not intent.

59
00:04:40,810 --> 00:04:44,890
And then date and client underscore secret.

60
00:04:45,180 --> 00:04:46,240
Let's save it.

61
00:04:46,510 --> 00:04:47,740
Let's refresh.

62
00:04:48,580 --> 00:04:54,700
And then, if everything is correct, should be able to pay once the dust khadraoui.

63
00:04:55,180 --> 00:05:00,760
Now I want to go back to the server and I want to show you the responses we're getting back.

64
00:05:01,180 --> 00:05:08,410
So we get this massive, massive object with ID, with the amount, and you can read the rest of the

65
00:05:08,410 --> 00:05:08,960
property.

66
00:05:09,250 --> 00:05:15,460
Now, the one that we want to send back to the front end is that client underscore secret.

67
00:05:15,790 --> 00:05:23,470
And once we have all of this in place, then like I said from the front end, we can actually pay with

68
00:05:23,470 --> 00:05:23,880
a card.

69
00:05:24,220 --> 00:05:30,100
So when it comes to server, we're only responsible for that middle step where we do two things.

70
00:05:30,100 --> 00:05:37,930
First, we communicate with our own back end to make sure that the prices for the items are correct.

71
00:05:38,110 --> 00:05:42,670
So we're not relying on the Front-End front that can manipulate these values.

72
00:05:42,910 --> 00:05:48,790
And you definitely don't want to sell the item for one dollar if the price actually is a hundred dollars.

73
00:05:49,120 --> 00:05:53,980
So in here, you set up some kind of functionality, whether that is a function, whether that has multiple

74
00:05:53,980 --> 00:05:57,880
functions where you get the correct prices for the items.

75
00:05:58,030 --> 00:06:00,640
And second, you calculate the total amount.

76
00:06:01,120 --> 00:06:07,120
Now, once you have the amount, then you can go with DOT creates a stripe payment, intent, dot,

77
00:06:07,360 --> 00:06:10,610
create method and you pass in amount.

78
00:06:10,990 --> 00:06:12,940
So this is going to be the total amount.

79
00:06:13,090 --> 00:06:19,240
And yes, it's going to be in a sense, since the currency is in dollars, then we're waiting for a

80
00:06:19,240 --> 00:06:19,820
response.

81
00:06:19,840 --> 00:06:23,830
That's why we have here a wait and line to the client.

82
00:06:23,920 --> 00:06:31,390
We send back the client secret, however you call this property and land on the front end will be able

83
00:06:31,390 --> 00:06:33,090
to complete the transaction.

84
00:06:33,460 --> 00:06:38,260
So if you go to localhost three thousand, the test card number is this one.

85
00:06:38,440 --> 00:06:39,670
That's copy and paste.

86
00:06:40,090 --> 00:06:43,190
And here you just come up with some dummy dollars.

87
00:06:43,240 --> 00:06:48,310
Just remember your past in the future date when it comes to expiration.

88
00:06:48,700 --> 00:06:55,890
So in this case, I'm going to go with two and twenty two and here I can provide some dummy values.

89
00:06:56,320 --> 00:07:01,090
So let me go here with zero three and zero three we can pay.

90
00:07:01,510 --> 00:07:03,790
And if everything is correct, yep.

91
00:07:04,120 --> 00:07:05,890
We see payments exceeded.

92
00:07:06,160 --> 00:07:10,750
We click here and once we navigate the dashboard you'll see the payment.

93
00:07:10,750 --> 00:07:15,010
Four hundred twenty dollars and ninety seven cents.

94
00:07:15,430 --> 00:07:17,530
Hopefully everything was clear.

95
00:07:17,740 --> 00:07:22,540
And now you know how to set up functionality to accept payments with stripe.

