Skip to content

Commit f4bc58f

Browse files
Chris Yangcyanglaz
andcommitted
# This is a combination of 6 commits.
# This is the 1st commit message: review fixes # This is the commit message #2: Update packages/in_app_purchase/ios/Classes/InAppPurchasePlugin.m review fix Co-Authored-By: cyanglaz <[email protected]> # This is the commit message #3: Update packages/in_app_purchase/ios/Classes/InAppPurchasePlugin.m Co-Authored-By: cyanglaz <[email protected]> # This is the commit message flutter#4: Update packages/in_app_purchase/ios/Classes/InAppPurchasePlugin.m review fix Co-Authored-By: cyanglaz <[email protected]> # This is the commit message flutter#5: Update packages/in_app_purchase/ios/Classes/InAppPurchasePlugin.m Co-Authored-By: cyanglaz <[email protected]> # This is the commit message flutter#6: Update packages/in_app_purchase/ios/Classes/InAppPurchasePlugin.m Co-Authored-By: cyanglaz <[email protected]>
1 parent 431cbc6 commit f4bc58f

File tree

4 files changed

+18
-42
lines changed

4 files changed

+18
-42
lines changed

packages/in_app_purchase/example/ios/in_app_purchase_pluginTests/InAppPurchasePluginTest.m

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ - (void)testAddPaymentFailure {
121121
}
122122
updatedDownloads:nil];
123123
[queue addTransactionObserver:self.plugin.paymentQueueHandler];
124-
self.plugin.paymentQueueHandler.testing = YES;
125124
[self.plugin handleMethodCall:call
126125
result:^(id r){
127126
}];
@@ -158,7 +157,6 @@ - (void)testAddPaymentSuccessWithMockQueue {
158157
}
159158
updatedDownloads:nil];
160159
[queue addTransactionObserver:self.plugin.paymentQueueHandler];
161-
self.plugin.paymentQueueHandler.testing = YES;
162160
[self.plugin handleMethodCall:call
163161
result:^(id r){
164162
}];

packages/in_app_purchase/ios/Classes/FIAPaymentQueueHandler.h

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
NS_ASSUME_NONNULL_BEGIN
99

10-
extern NSString *const TestingProductID;
11-
1210
typedef void (^TransactionsUpdated)(NSArray<SKPaymentTransaction *> *transactions);
1311
typedef void (^TransactionsRemoved)(NSArray<SKPaymentTransaction *> *transactions);
1412
typedef void (^RestoreTransactionFailed)(NSError *error);
@@ -29,17 +27,9 @@ typedef void (^UpdatedDownloads)(NSArray<SKDownload *> *downloads);
2927
shouldAddStorePayment:(nullable ShouldAddStorePayment)shouldAddStorePayment
3028
updatedDownloads:(nullable UpdatedDownloads)updatedDownloads;
3129
- (void)addPayment:(SKPayment *)payment;
32-
// Can throw exceptions, should always used in a @try block.
30+
// Can throw exceptions if the transaction type is purchasing, should always used in a @try block.
3331
- (void)finishTransaction:(SKPaymentTransaction *)transaction;
3432

35-
// Enable testing.
36-
37-
// Because payment object in transaction is not KVC, we cannot mock the payment object in the
38-
// transaction. So there is no easay way to create stubs and test the handler.
39-
// When set to true, we always this a constant TestingProductID as product ID
40-
// when storing and accessing the completion block from self.completionMap
41-
@property(assign, nonatomic) BOOL testing;
42-
4333
@end
4434

4535
NS_ASSUME_NONNULL_END

packages/in_app_purchase/ios/Classes/FIAPaymentQueueHandler.m

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
#import "FIAPaymentQueueHandler.h"
66

7-
NSString *const TestingProductID = @"testing";
8-
97
@interface FIAPaymentQueueHandler ()
108

119
@property(strong, nonatomic) SKPaymentQueue *queue;
@@ -46,21 +44,11 @@ - (instancetype)initWithQueue:(nonnull SKPaymentQueue *)queue
4644
}
4745

4846
- (void)addPayment:(SKPayment *)payment {
49-
NSString *productID = payment.productIdentifier;
50-
if (self.testing) {
51-
productID = TestingProductID;
52-
}
5347
[self.queue addPayment:payment];
5448
}
5549

5650
- (void)finishTransaction:(SKPaymentTransaction *)transaction {
57-
@try {
5851
[self.queue finishTransaction:transaction];
59-
} @catch (NSException *e) {
60-
// finish transaction will throw exception if the transaction type is purchasing. Raise the
61-
// exception so the InAppPurchasePlugin will get notified.
62-
[e raise];
63-
}
6452
}
6553

6654
#pragma mark - observing

packages/in_app_purchase/ios/Classes/InAppPurchasePlugin.m

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ - (void)handleProductRequestMethodCall:(FlutterMethodCall *)call result:(Flutter
134134
- (void)createPaymentWithProductID:(FlutterMethodCall *)call result:(FlutterResult)result {
135135
if (![call.arguments isKindOfClass:[NSString class]]) {
136136
result([FlutterError
137-
errorWithCode:@"storekit_invalide_argument"
137+
errorWithCode:@"storekit_invalid_argument"
138138
message:@"Argument type of createPaymentWithProductID is not a string."
139139
details:call.arguments]);
140140
return;
@@ -145,7 +145,7 @@ - (void)createPaymentWithProductID:(FlutterMethodCall *)call result:(FlutterResu
145145
result([FlutterError
146146
errorWithCode:@"storekit_product_not_found"
147147
message:@"Cannot find the product. To create a payment of a product, you must query "
148-
@"the product with SKProductRequestMaker.startProductRequest."
148+
@"the product with SKProductRequestMaker.startProductRequest first."
149149
details:call.arguments]);
150150
return;
151151
}
@@ -156,38 +156,37 @@ - (void)createPaymentWithProductID:(FlutterMethodCall *)call result:(FlutterResu
156156

157157
- (void)addPayment:(FlutterMethodCall *)call result:(FlutterResult)result {
158158
if (![call.arguments isKindOfClass:[NSDictionary class]]) {
159-
result([FlutterError errorWithCode:@"storekit_invalide_argument"
159+
result([FlutterError errorWithCode:@"storekit_invalid_argument"
160160
message:@"Argument type of addPayment is not a map"
161161
details:call.arguments]);
162162
return;
163163
}
164164
NSDictionary *paymentMap = (NSDictionary *)call.arguments;
165165
NSString *productID = [paymentMap objectForKey:@"productID"];
166166
SKPayment *payment = [self.paymentsCache objectForKey:productID];
167-
// User can use payment object with mutable = true and add simulatesAskToBuyInSandBox = true to
167+
// User can use payment object with usePaymentObject = true and add simulatesAskToBuyInSandBox = true to
168168
// test the payment flow.
169-
if (!payment || [paymentMap[@"mutable"] boolValue] == YES) {
169+
if (!payment || [paymentMap[@"usePaymentObject"] boolValue] == YES) {
170170
SKMutablePayment *mutablePayment = [[SKMutablePayment alloc] init];
171171
mutablePayment.productIdentifier = productID;
172172
NSNumber *quantity = [paymentMap objectForKey:@"quantity"];
173-
if (quantity) {
174-
mutablePayment.quantity = quantity.integerValue;
175-
}
173+
mutablePayment.quantity = quantity?quantity.integerValue:1;
176174
NSString *applicationUsername = [paymentMap objectForKey:@"applicationUsername"];
177175
mutablePayment.applicationUsername = applicationUsername;
178176
if (@available(iOS 8.3, *)) {
179177
mutablePayment.simulatesAskToBuyInSandbox =
180178
[[paymentMap objectForKey:@"simulatesAskToBuyInSandBox"] boolValue];
181179
}
182-
[self.paymentQueueHandler addPayment:payment];
180+
[self.paymentQueueHandler addPayment:mutablePayment];
183181
} else {
184182
[self.paymentQueueHandler addPayment:payment];
185183
}
184+
result(nil);
186185
}
187186

188187
- (void)finishTransaction:(FlutterMethodCall *)call result:(FlutterResult)result {
189188
if (![call.arguments isKindOfClass:[NSString class]]) {
190-
result([FlutterError errorWithCode:@"storekit_invalide_argument"
189+
result([FlutterError errorWithCode:@"storekit_invalid_argument"
191190
message:@"Argument type of finishTransaction is not a string."
192191
details:call.arguments]);
193192
return;
@@ -211,24 +210,25 @@ - (void)finishTransaction:(FlutterMethodCall *)call result:(FlutterResult)result
211210
details:e.description]);
212211
return;
213212
}
213+
result(nil);
214214
}
215215

216216
#pragma mark - delegates
217217

218218
- (void)handleTransactionsUpdated:(NSArray<SKPaymentTransaction *> *)transactions {
219219
NSMutableArray *maps = [NSMutableArray new];
220-
for (SKPaymentTransaction *transcation in transactions) {
221-
[maps addObject:[FIAObjectTranslator getMapFromSKPaymentTransaction:transcation]];
220+
for (SKPaymentTransaction *transaction in transactions) {
221+
[maps addObject:[FIAObjectTranslator getMapFromSKPaymentTransaction:transaction]];
222222
}
223-
[self.callbackChannel invokeMethod:@"updatedTransaction" arguments:maps];
223+
[self.callbackChannel invokeMethod:@"updatedTransactions" arguments:maps];
224224
}
225225

226226
- (void)handleTransactionsRemoved:(NSArray<SKPaymentTransaction *> *)transactions {
227227
NSMutableArray *maps = [NSMutableArray new];
228-
for (SKPaymentTransaction *transcation in transactions) {
229-
[maps addObject:[FIAObjectTranslator getMapFromSKPaymentTransaction:transcation]];
228+
for (SKPaymentTransaction *transaction in transactions) {
229+
[maps addObject:[FIAObjectTranslator getMapFromSKPaymentTransaction:transaction]];
230230
}
231-
[self.callbackChannel invokeMethod:@"removedTransaction" arguments:maps];
231+
[self.callbackChannel invokeMethod:@"removedTransactions" arguments:maps];
232232
}
233233

234234
- (void)handleTransactionRestoreFailed:(NSError *)error {
@@ -252,7 +252,7 @@ - (void)updatedDownloads:(NSArray<SKDownload *> *)downloads {
252252
}
253253

254254
- (BOOL)shouldAddStorePayment:(SKPayment *)payment product:(SKProduct *)product {
255-
// We alwasy return NO here. And we send the message to dart to process the payment; and we will
255+
// We always return NO here. And we send the message to dart to process the payment; and we will
256256
// have a incerpection method that deciding if the payment should be processed (implemented by the
257257
// programmer).
258258
[self.productsCache setObject:product forKey:product.productIdentifier];

0 commit comments

Comments
 (0)