1
00:00:07,090 --> 00:00:10,320
Everybody was going on this is Caleb with Debb slopes.

2
00:00:10,420 --> 00:00:15,370
And in this video we're going to go ahead and add to our Constans File.

3
00:00:15,400 --> 00:00:20,440
We're going to also create some enumerations to help us know what products we're talking about when

4
00:00:20,440 --> 00:00:25,360
we are doing this whether it's a meal or the hied adds non consumable product.

5
00:00:25,630 --> 00:00:30,640
And then we're also going to go ahead and set up another enumeration to help us determine the purchase

6
00:00:30,640 --> 00:00:35,570
status whether we purchase something whether something failed or whether it was restored.

7
00:00:35,650 --> 00:00:37,330
Then we're going to go ahead and write the function.

8
00:00:37,330 --> 00:00:41,670
You've been waiting for make purchase for item with product index.

9
00:00:41,710 --> 00:00:47,230
This function is going to basically make a request and it'll present the would you like to buy this

10
00:00:47,290 --> 00:00:54,110
item and then I'm going to have to show you how to set up your testing sandbox account and yeah.

11
00:00:54,130 --> 00:00:59,130
So let's go ahead and let's open up our project Let's get started right now.

12
00:00:59,140 --> 00:01:06,310
So right click on food Zyla create a new group called gnomes and Roona right click again and create

13
00:01:06,310 --> 00:01:07,720
a new file.

14
00:01:07,720 --> 00:01:11,810
Ok make it a swift file and we're going to call this product.

15
00:01:12,160 --> 00:01:12,830
OK.

16
00:01:13,180 --> 00:01:20,290
And just for now we're going to just say ENM product and we'll leave it like that.

17
00:01:20,290 --> 00:01:30,600
We're going to create another new file click swift file and this is going to be purchase status like

18
00:01:30,610 --> 00:01:32,380
so purchase status.

19
00:01:32,680 --> 00:01:34,660
And that's also going to be an enumeration.

20
00:01:34,660 --> 00:01:42,610
So Type in purchase status although I'm getting a ton of extra T's here and use some curly braces to

21
00:01:42,610 --> 00:01:44,900
go ahead and create that.

22
00:01:45,010 --> 00:01:53,050
Next we're going to go into our Constans file and we need to set up some identifiers one for our next

23
00:01:53,130 --> 00:01:53,800
and app purchase.

24
00:01:53,800 --> 00:01:55,820
But I'm going to go ahead and I'll.

25
00:01:55,840 --> 00:02:01,570
All right here and then I'll use that one when I create our hide ads non consumable purchase.

26
00:02:01,570 --> 00:02:09,630
But let's just go ahead and say let IAP hide ads ID.

27
00:02:10,150 --> 00:02:17,460
And that's going to be equal to a string com dot IAP course dot hide ads.

28
00:02:17,560 --> 00:02:17,960
OK.

29
00:02:17,980 --> 00:02:25,530
And you know what let's put a little comment here let's just say IAP identifiers.

30
00:02:25,870 --> 00:02:28,530
And now below let's do it again.

31
00:02:29,140 --> 00:02:31,720
This is going to be for notification

32
00:02:34,660 --> 00:02:35,730
identifiers.

33
00:02:35,800 --> 00:02:37,310
And let me explain myself here.

34
00:02:37,330 --> 00:02:43,600
We're going to use these identifiers as the name for notification center when you when you make a notification

35
00:02:43,600 --> 00:02:46,730
send or call you need to pass in a name for the notification.

36
00:02:47,020 --> 00:02:52,330
And these names are going to help us differentiate when we send a notification for a successful purchase

37
00:02:52,540 --> 00:02:56,450
for a successful restore or a fail.

38
00:02:56,470 --> 00:02:58,930
So let's go ahead and let's create three properties.

39
00:02:58,930 --> 00:03:01,800
One is going to be let IPs service.

40
00:03:01,960 --> 00:03:03,530
Well not all in caps sorry.

41
00:03:03,660 --> 00:03:10,180
IAP service purchase notification and we're going to just said that to be a string value of the same

42
00:03:10,180 --> 00:03:13,500
name and I'm going to go ahead and just copy this.

43
00:03:13,520 --> 00:03:14,520
Whoops.

44
00:03:14,920 --> 00:03:18,330
Select all and copy it and then paste it three times change.

45
00:03:18,350 --> 00:03:20,620
Purchased here to restore.

46
00:03:20,620 --> 00:03:21,700
Same with here.

47
00:03:21,790 --> 00:03:24,280
Purchase needs to be changed to restore.

48
00:03:24,430 --> 00:03:25,380
Then we're going to do.

49
00:03:25,390 --> 00:03:26,500
Failure.

50
00:03:27,450 --> 00:03:29,780
And failure.

51
00:03:30,420 --> 00:03:32,590
Make sure that you type at the same exact way.

52
00:03:32,640 --> 00:03:36,600
All right so now we have three ways to identify the different notifications.

53
00:03:36,610 --> 00:03:37,560
We're going to be using.

54
00:03:37,740 --> 00:03:39,840
And we're going to use those in just a little bit.

55
00:03:39,900 --> 00:03:44,990
But for now let's go ahead and let's think what we need to do for product.

56
00:03:45,120 --> 00:03:48,030
Now this is an enumeration meaning it doesn't.

57
00:03:48,930 --> 00:03:54,700
Meaning it doesn't have an explicit value or it can't hold an explicit value unless we tell it to.

58
00:03:54,870 --> 00:03:55,640
And we're going to.

59
00:03:55,650 --> 00:03:59,770
So go ahead and under product we're going to have it be of type int.

60
00:04:00,030 --> 00:04:06,570
It's going to subclass it and we're going to set two cases one case being meal and another case being

61
00:04:06,570 --> 00:04:07,520
hied adds.

62
00:04:07,530 --> 00:04:10,150
So go ahead and type case Neal.

63
00:04:10,200 --> 00:04:12,100
And that's going to be equal to zero.

64
00:04:12,270 --> 00:04:18,180
OK so we're going to be able to pass in a value and then that's going to be able to we're going to use

65
00:04:18,180 --> 00:04:25,660
this to pull out the proper index in our IAP service remember our set of string has one item.

66
00:04:25,680 --> 00:04:31,470
So we're not going to use the second index yet but eventually we're going to need to pass in two.

67
00:04:31,470 --> 00:04:36,030
And so one of them is going to have the index 0 and the other is going to have the index 1 and so we're

68
00:04:36,030 --> 00:04:39,560
using this as a way to call those specific values.

69
00:04:39,630 --> 00:04:41,780
Next call case.

70
00:04:41,860 --> 00:04:45,870
Hide ads and set that to be equal to 1 when it's there will use it.

71
00:04:45,880 --> 00:04:47,670
But we're not going to use it for now.

72
00:04:47,670 --> 00:04:53,510
So there is our enumeration that will help us to differentiate which product we're talking about next.

73
00:04:53,520 --> 00:04:57,930
Go ahead and head over to purchase status and this is what we're going to use basically just to help

74
00:04:57,930 --> 00:05:04,110
us determine a certain type of purchase whether it was purchased restored or failed.

75
00:05:04,110 --> 00:05:09,750
So go ahead and type case purchased case restored and case

76
00:05:12,190 --> 00:05:15,170
fail failed I failed typing failed.

77
00:05:15,180 --> 00:05:16,100
Ironic.

78
00:05:16,320 --> 00:05:16,640
Anyway.

79
00:05:16,650 --> 00:05:21,150
So we don't need to set an explicit type because we're just going to use these names as identifiers

80
00:05:21,150 --> 00:05:22,780
when we pass one in.

81
00:05:23,010 --> 00:05:27,440
We'll be able to basically switch through and do something based on which one was passed in.

82
00:05:27,450 --> 00:05:29,010
You'll see how we use that later.

83
00:05:29,010 --> 00:05:35,880
So now that we have these all set up we can go right one more very exciting function inside our IP service

84
00:05:35,880 --> 00:05:39,710
and it's going to let us actually make a legitimate purchase.

85
00:05:39,720 --> 00:05:42,430
So let's go ahead and let's set it up down here beneath.

86
00:05:42,450 --> 00:05:48,150
Product request and we're going to let me make some more space here so you can see and I'm going to

87
00:05:48,150 --> 00:05:51,030
zoom in a little bit make my font a tiny bit bigger.

88
00:05:51,050 --> 00:05:51,860
There we go.

89
00:05:52,110 --> 00:05:56,600
And this function is going to be called Make purchase for item with product index.

90
00:05:56,610 --> 00:06:04,770
So go ahead and type phunk make purchase or you know what I'm going to I'm going to attempt to purchase

91
00:06:04,770 --> 00:06:10,800
because that's a little better of language for this attempt to purchase for item with.

92
00:06:10,840 --> 00:06:19,320
And the princes will say product index of type product because remember we can use the raw value of

93
00:06:19,320 --> 00:06:24,960
the product which is either 0 or 1 as an index to pass in which is really neat.

94
00:06:24,960 --> 00:06:30,780
So then inside this function we're going to basically need to create two properties one to hold a product

95
00:06:31,110 --> 00:06:35,030
and another one to hold an instance of S-K payment.

96
00:06:35,040 --> 00:06:35,620
Okay.

97
00:06:35,880 --> 00:06:37,410
So go ahead and type let product

98
00:06:40,060 --> 00:06:47,940
and that's going to be equal to our products array k but we need to pull out a specific item at a specific

99
00:06:47,940 --> 00:06:48,630
index.

100
00:06:48,780 --> 00:06:50,410
Thankfully we have that.

101
00:06:50,430 --> 00:06:55,940
So right now we're going to pass in product index like so.

102
00:06:56,070 --> 00:07:01,920
And since it's of our enumeration we need to pull out the raw value of type int k which is either 0

103
00:07:01,920 --> 00:07:05,070
or 1 since we only have one item it's going to be zero.

104
00:07:05,190 --> 00:07:08,790
And that will give us the exact product we're trying to buy next.

105
00:07:08,790 --> 00:07:10,890
Let's go ahead and let's create a payment.

106
00:07:11,100 --> 00:07:16,140
And basically what this is going to allow us to do is to pass the product in and it's kind of like we're

107
00:07:16,140 --> 00:07:20,400
saying I want to buy this item and we're going to pass that into another function in just a moment.

108
00:07:20,400 --> 00:07:26,750
So Type let payment equals Eskay payment.

109
00:07:27,030 --> 00:07:32,910
And if you look you can pass in an S-K product well by darn it we have one let's pass in our product

110
00:07:32,910 --> 00:07:36,860
here that we just created thanks to our products.

111
00:07:37,320 --> 00:07:44,160
And now all we need to do is access something called the S-K payment queue and it's a queue of payment

112
00:07:44,160 --> 00:07:46,620
transactions to be processed by the AppStore.

113
00:07:46,740 --> 00:07:47,460
Super simple.

114
00:07:47,460 --> 00:07:52,910
So go ahead and type S-K payment queue and we want to access the default payment queue.

115
00:07:53,100 --> 00:07:55,080
It's an instance of payment queue.

116
00:07:55,230 --> 00:07:58,700
And then we're going to go ahead and type dot and check it out.

117
00:07:58,710 --> 00:08:04,500
We just type ad payment and we have a payment called S-K payment boom.

118
00:08:04,530 --> 00:08:09,870
So when we attempt to purchase it's going to pass in a product pass and a payment and add it to the

119
00:08:09,870 --> 00:08:10,710
S-K payment.

120
00:08:10,710 --> 00:08:12,060
Q This is pretty cool.

121
00:08:12,060 --> 00:08:13,560
We pass in the payment.

122
00:08:13,560 --> 00:08:20,250
It does some stuff and then it actually is going to call a delegate on a special protocol called S-K

123
00:08:20,310 --> 00:08:22,060
payment transaction observer.

124
00:08:22,290 --> 00:08:27,800
Similarly to how product request is called as soon as this product request comes back from the App Store.

125
00:08:28,440 --> 00:08:34,270
S.K. a function inside of S-K payment transaction observer is going to be called.

126
00:08:34,290 --> 00:08:38,580
And then we can tell you know we can tell our app what we want it to do.

127
00:08:38,580 --> 00:08:39,120
OK.

128
00:08:39,450 --> 00:08:41,110
So that's awesome.

129
00:08:41,280 --> 00:08:45,150
But we need to basically set it up so that we can utilize this S-K payment.

130
00:08:45,150 --> 00:08:51,390
Q And to do that we're going to go ahead and extend our IAP service so that we can conform to S.K. payment

131
00:08:51,390 --> 00:08:52,850
transaction observer.

132
00:08:52,890 --> 00:08:54,620
So let's make some more space here.

133
00:08:54,890 --> 00:09:02,520
An online 58 I'm going to say extension IAP service and we're going to conform to S.K. payment transaction

134
00:09:02,520 --> 00:09:03,370
observer.

135
00:09:03,500 --> 00:09:04,020
Okay.

136
00:09:04,170 --> 00:09:10,380
Now it says a set of methods that process transactions unlock purchased functionality and continue promoted

137
00:09:10,380 --> 00:09:11,830
in-app purchases.

138
00:09:11,850 --> 00:09:16,830
Press Enter give it some curly brackets and the function we're looking for here is called payment.

139
00:09:16,840 --> 00:09:19,590
Q updated transactions.

140
00:09:19,710 --> 00:09:20,330
Okay.

141
00:09:20,490 --> 00:09:23,810
So this is going to be called any time we purchase something.

142
00:09:23,890 --> 00:09:27,660
Time we have a failed transaction we restore a transaction.

143
00:09:27,660 --> 00:09:31,650
Payment is deferred or we're in the process of purchasing.

144
00:09:31,650 --> 00:09:34,760
We can do we can call a function on any of these.

145
00:09:34,770 --> 00:09:40,830
So press enter and we're going to dive into Well first we need to see if the error goes away if we've

146
00:09:40,830 --> 00:09:42,120
properly conformed.

147
00:09:42,180 --> 00:09:48,510
Looks like we have and what we need to do is we need to set up a switch to basically switch through

148
00:09:48,570 --> 00:09:49,590
all of those different things.

149
00:09:49,590 --> 00:09:54,550
I just said purchased failed restored deferred or purchasing.

150
00:09:54,870 --> 00:09:55,890
And it's really easy.

151
00:09:55,890 --> 00:09:59,970
So all we're going to do is we're going to look through all the transactions we have passed into our

152
00:09:59,970 --> 00:10:02,340
S-K payment queue which get returned here.

153
00:10:02,520 --> 00:10:03,210
Okay.

154
00:10:03,210 --> 00:10:07,680
We're going to cycle through all of them with a for loop and for each one we're going to switch through

155
00:10:07,740 --> 00:10:13,800
all of the potential cases and then for the matching case we can call a certain property or a function.

156
00:10:13,810 --> 00:10:19,030
So let's go ahead and call for transaction in transactions.

157
00:10:19,210 --> 00:10:23,610
We're going to write a switch and we're going to switch through a property in transactions so-called

158
00:10:23,620 --> 00:10:30,650
transaction transaction state and you'll see that S-K payment transaction state is actually an enumeration.

159
00:10:30,820 --> 00:10:34,510
And so what we can do is we can switch through all the potential cases that there are.

160
00:10:34,510 --> 00:10:37,760
So let's do the first one case dot purchased.

161
00:10:37,780 --> 00:10:40,730
That's the most common is that it will be successfully purchased.

162
00:10:40,900 --> 00:10:48,790
And for now we're just going to call break then we're going to call case let's do restored next and

163
00:10:48,790 --> 00:10:52,330
we'll just break next case failed.

164
00:10:53,430 --> 00:10:54,500
And break.

165
00:10:54,900 --> 00:11:04,410
Next case is deferred if payment is deferred then we'll call case and purchasing which is called when

166
00:11:04,680 --> 00:11:09,090
like you start the purchasing process OK which can be helpful for certain things.

167
00:11:09,510 --> 00:11:13,180
So now if I go ahead and build this it's going to say that we have no heirs.

168
00:11:13,290 --> 00:11:16,110
We have exhaustively gone through every potential case.

169
00:11:16,110 --> 00:11:20,630
There are only five cases in this transaction state so we're good.

170
00:11:20,640 --> 00:11:26,190
So basically what's going to happen is every time that we purchase and we are successful in purchasing

171
00:11:26,490 --> 00:11:29,040
it's going to call this here case that purchase.

172
00:11:29,040 --> 00:11:36,660
So for now I'm just going to use Debug print and I'm going to print out purchase was successful.

173
00:11:36,660 --> 00:11:37,280
All right.

174
00:11:37,620 --> 00:11:38,370
So that looks pretty good.

175
00:11:38,370 --> 00:11:40,170
And for now I'm just going to leave it at that.

176
00:11:40,170 --> 00:11:45,400
We'll we'll come back later and we'll set up some stuff for the purchase to happen.

177
00:11:45,600 --> 00:11:52,020
But you know what we need to actually tell it that our purchase is finished because right now it's returning

178
00:11:52,380 --> 00:11:57,930
and it's saying hey looks like it was good but we need to basically use our S-K payment cue to let it

179
00:11:57,930 --> 00:12:00,720
know that it's finished and that it can release that that transaction.

180
00:12:00,720 --> 00:12:04,710
So inside of case up purchased we're going to call S-K payment.

181
00:12:04,710 --> 00:12:06,030
Q Okay.

182
00:12:06,030 --> 00:12:08,450
And we're going to call that default to get the default payment.

183
00:12:08,460 --> 00:12:14,120
Q Then we're going to call a finished transaction and the transaction will just come from our for loop.

184
00:12:14,130 --> 00:12:22,210
So go ahead and type transaction and now the payment is officially finished it's notified.

185
00:12:22,220 --> 00:12:23,080
It's good to go.

186
00:12:23,090 --> 00:12:26,520
We can print purchase was successful and then we can break.

187
00:12:26,570 --> 00:12:27,800
Beautiful.

188
00:12:27,860 --> 00:12:28,720
I want to try it out.

189
00:12:28,850 --> 00:12:35,960
So in order to actually try attempt to purchase for item we need to go into our detail Visi because

190
00:12:35,960 --> 00:12:39,360
that's where our buy button is that's where we want to actually try this.

191
00:12:39,380 --> 00:12:40,280
Right.

192
00:12:40,340 --> 00:12:44,360
So we need to find a way to call our function and we can use our IP service.

193
00:12:44,360 --> 00:12:45,980
So in buy button was pressed.

194
00:12:45,980 --> 00:12:56,240
All we need to do is type IAP service instance WIPs instance dot attempt to purchase for item with product

195
00:12:56,270 --> 00:13:02,120
index and since we're using our enumeration we can just type dot meal because that's the index of the

196
00:13:02,120 --> 00:13:04,420
item we want to attempt to purchase.

197
00:13:04,430 --> 00:13:09,380
I think we should try this but at this point we're going to have to build our project to a physical

198
00:13:09,380 --> 00:13:15,710
device in-app purchases work very inconsistently slash not really at all on simulators and so we're

199
00:13:15,710 --> 00:13:19,150
going to have to go ahead and build it to a physical device so you're going to have to plug one in over

200
00:13:19,150 --> 00:13:24,370
us beat in order to test it and let's do that now I'm going to build it to my phone.

201
00:13:24,380 --> 00:13:30,320
We're going to pull up in quick time here so that I can actually show my iPhone screen up on the screen

202
00:13:30,320 --> 00:13:35,960
here for you to see although I'm going to do one of the time because quick time likes to hijack the

203
00:13:35,990 --> 00:13:40,820
USP port not audio recording movie recording ok cool.

204
00:13:40,820 --> 00:13:41,450
There we go.

205
00:13:41,450 --> 00:13:43,140
So we're good to go there.

206
00:13:43,140 --> 00:13:44,560
That looks awesome.

207
00:13:44,900 --> 00:13:47,770
And let's go ahead and build and run it again.

208
00:13:48,760 --> 00:13:51,710
And then I need to show you how to set up our test account.

209
00:13:51,880 --> 00:13:52,450
OK.

210
00:13:52,660 --> 00:13:53,220
We're going to need.

211
00:13:53,290 --> 00:13:57,730
I didn't connect so that we can remember the e-mail for our sandbox user.

212
00:13:57,730 --> 00:14:02,020
And you know what it looks like our app has built successfully looking pretty good here.

213
00:14:02,260 --> 00:14:09,340
So go to users unrolls go to sandbox users as soon as it loads which can take a while.

214
00:14:09,490 --> 00:14:18,750
If your internet is slow 9:58 you do OK.

215
00:14:18,840 --> 00:14:23,840
Click on sandbox Tester's and the name we made was Mr. test one two three at gmail.

216
00:14:23,940 --> 00:14:25,590
So let's use that.

217
00:14:25,590 --> 00:14:26,040
All right.

218
00:14:26,040 --> 00:14:27,070
So check it out guys.

219
00:14:27,090 --> 00:14:27,960
What we're going to do.

220
00:14:27,990 --> 00:14:29,610
We're going to attempt to make a purchase.

221
00:14:29,610 --> 00:14:33,200
You can see the IAP products have loaded successfully.

222
00:14:33,210 --> 00:14:39,150
Let's go ahead and pull open salmon and let's try to buy this item for nine ninety nine when I tap the

223
00:14:39,150 --> 00:14:39,440
button.

224
00:14:39,430 --> 00:14:41,490
It's going to attempt a purchase.

225
00:14:41,520 --> 00:14:44,360
And let's go look at that function against we remember what it does.

226
00:14:44,480 --> 00:14:49,950
Passes in the product makes a payment with that product and adds it to the payment queue when the payment

227
00:14:49,950 --> 00:14:51,860
queue is good to go.

228
00:14:51,870 --> 00:14:57,030
If the purchase is successful it's going to finish the transaction and print purchase was successful.

229
00:14:57,390 --> 00:15:02,900
So let's go ahead and let's tap on that button and you don't need to show you my screen here don't I.

230
00:15:03,030 --> 00:15:06,920
I tapped on it and it says use existing Apple ID.

231
00:15:06,960 --> 00:15:07,500
OK.

232
00:15:07,710 --> 00:15:19,510
So we created an account and I S T our dot test 1 2 3 at gmail dot com GM.

233
00:15:19,920 --> 00:15:21,900
That's a capital it's hard to type with one hand.

234
00:15:22,200 --> 00:15:31,200
Gmail dot com our password was capital-T test test one two three exclamation mark.

235
00:15:31,200 --> 00:15:38,880
Now when I push by we need to see what what's going to happen here we pushed by and it's telling me

236
00:15:38,880 --> 00:15:42,180
I need to verify my Apple ID for in-app purchases.

237
00:15:42,180 --> 00:15:43,060
It's kind of annoying.

238
00:15:43,110 --> 00:15:44,430
You have to log in twice.

239
00:15:44,460 --> 00:15:45,530
Isn't that fun.

240
00:15:45,540 --> 00:15:51,360
So now I'm going to type Mr. dot test and see if I can do this a little faster this time.

241
00:15:51,360 --> 00:15:55,880
One two three at gmail dot com.

242
00:15:57,010 --> 00:16:05,570
And my password one two three exclamation mark so press OK and let's see what happens.

243
00:16:07,520 --> 00:16:12,010
We're waiting we're waiting.

244
00:16:12,010 --> 00:16:13,220
Nothing's happening yet.

245
00:16:13,240 --> 00:16:15,790
My internet is being very slow today.

246
00:16:15,880 --> 00:16:21,640
So you know what it looks like it might actually we might need to log into that account before we can

247
00:16:21,640 --> 00:16:22,840
actually make a purchase.

248
00:16:22,870 --> 00:16:25,910
So now that I'm logged in let's go and try it again by item.

249
00:16:26,200 --> 00:16:26,490
OK.

250
00:16:26,500 --> 00:16:28,480
So this is good this is what it should look like.

251
00:16:28,510 --> 00:16:30,240
You should have to enter your password.

252
00:16:30,280 --> 00:16:33,400
I guess the first time was just initializing the account.

253
00:16:33,400 --> 00:16:38,390
And now if I type in my password and I push OK watch what happens.

254
00:16:39,640 --> 00:16:44,370
We should get a pop up confirm your purchase and it's going to tell me to verify don't do it because

255
00:16:44,380 --> 00:16:48,390
once you verify it in iTunes then it locks it in as like a legit Apple ID.

256
00:16:48,460 --> 00:16:52,830
So don't do that but it says Do you want to buy one meal for 999 that's what we typed.

257
00:16:52,840 --> 00:16:53,940
We named meal.

258
00:16:53,980 --> 00:16:55,340
That's exactly right.

259
00:16:55,480 --> 00:17:00,620
So watch what happens when I push by.

260
00:17:00,700 --> 00:17:02,440
Is he going to do anything.

261
00:17:02,440 --> 00:17:03,910
Is it going to work is it going to work.

262
00:17:04,000 --> 00:17:07,280
Your purchase was successful.

263
00:17:07,750 --> 00:17:11,170
That is seriously the coolest thing.

264
00:17:11,170 --> 00:17:12,570
Oh my word.

265
00:17:12,580 --> 00:17:15,280
We printed what we didn't print.

266
00:17:15,310 --> 00:17:15,810
Interesting.

267
00:17:15,810 --> 00:17:20,020
So I wonder why it didn't print.

268
00:17:20,170 --> 00:17:22,000
We successfully paid

269
00:17:25,060 --> 00:17:28,490
and that's good but it appears that we did not successfully print.

270
00:17:28,510 --> 00:17:29,170
That's interesting.

271
00:17:29,170 --> 00:17:33,520
Let's try it again let's try to buy it because it's a consumable we should just be able to buy it over

272
00:17:33,520 --> 00:17:42,280
and over again oh interesting so it looks like it is showing up as a non consumable purchase.

273
00:17:42,280 --> 00:17:49,330
And it's not successfully making it to the purchased to the purchased payment.

274
00:17:49,340 --> 00:17:51,480
Q So let's figure out what the problem is here.

275
00:17:52,780 --> 00:17:58,600
Shoot what's going on oh you know what I realized what the problem is you know what.

276
00:17:58,770 --> 00:17:59,710
Let's see.

277
00:17:59,980 --> 00:18:00,240
Yeah.

278
00:18:00,240 --> 00:18:05,460
So in order for any of this to work we need to set it up so that when this view controller or sorry

279
00:18:05,460 --> 00:18:09,490
when this class is initialized we need to set the payment queue.

280
00:18:09,840 --> 00:18:14,160
We need to add this class specifically to the payment queue.

281
00:18:14,190 --> 00:18:21,410
So go ahead and type in net and we're going to override the initialiser and call super in it like so.

282
00:18:21,570 --> 00:18:23,740
And then what we're going to do is call S-K payment.

283
00:18:23,770 --> 00:18:26,530
Q default.

284
00:18:26,790 --> 00:18:28,260
And we need to add an observer.

285
00:18:28,260 --> 00:18:32,370
This class needs to be observing all of the payments because otherwise we can't.

286
00:18:32,370 --> 00:18:37,520
And you'll notice it's asking for an observer of type S-K payment transaction observer.

287
00:18:37,620 --> 00:18:42,260
We've already conform to that protocol here so we can justifiably call self.

288
00:18:42,270 --> 00:18:43,400
That was the problem.

289
00:18:43,410 --> 00:18:48,720
So let's go ahead and let's reload let's let's build and run and we'll we'll check out to see if that

290
00:18:48,720 --> 00:18:50,000
fixed our issue.

291
00:18:50,980 --> 00:18:51,970
Here we go.

292
00:18:52,030 --> 00:18:55,210
And you know what we are not on the sim we are in quick time here.

293
00:18:55,210 --> 00:18:55,850
All right.

294
00:18:55,990 --> 00:18:56,500
Very cool.

295
00:18:56,500 --> 00:18:57,430
Here we go.

296
00:18:57,610 --> 00:19:05,680
Pull open this tap by item tapped by one meal your purchase was successful.

297
00:19:05,680 --> 00:19:08,490
Look it's printing purchase was successful.

298
00:19:08,500 --> 00:19:11,170
That's exactly right we can buy it over and over again.

299
00:19:11,290 --> 00:19:12,410
Your purchase was successful.

300
00:19:12,410 --> 00:19:17,410
Now it's able to recognize that this is a consumable purchase and every time we purchase it's going

301
00:19:17,410 --> 00:19:19,300
to print out purchase was successful.

302
00:19:19,300 --> 00:19:22,930
Guys we are successfully implementing consumable in-app purchases.

303
00:19:22,930 --> 00:19:25,400
That's all it takes based on this.

304
00:19:25,570 --> 00:19:32,080
You can use a variety of methods to tell other controllers that the purchase is successful like delegates

305
00:19:32,080 --> 00:19:33,850
or notifications or whatever.

306
00:19:33,850 --> 00:19:39,130
But guys the essence of this course for consumable purchases is basically finished.

307
00:19:39,160 --> 00:19:41,960
We have set up a consumable in-app purchases.

308
00:19:42,040 --> 00:19:43,560
We're going to keep making this better.

309
00:19:43,570 --> 00:19:44,440
Don't you worry.

310
00:19:44,440 --> 00:19:50,530
But for now this is a really really good start guys so we can now make consumable purchases but we need

311
00:19:50,530 --> 00:19:56,740
to start thinking about how we're going to notify controllers that we have successfully made purchases.

312
00:19:56,830 --> 00:20:01,810
How are we going to hide the ads for instance what are we going to do to hide the ads.

313
00:20:01,810 --> 00:20:06,430
How is it going to know that we have successfully made a purchase so we're going to do that in the next

314
00:20:06,730 --> 00:20:07,530
video.

315
00:20:07,750 --> 00:20:10,630
So let's get over there and let's start that now and really excited guys.

316
00:20:10,630 --> 00:20:12,390
This is looking so good.

317
00:20:12,400 --> 00:20:12,940
Awesome work.

318
00:20:12,940 --> 00:20:14,310
Let's head over there now.
