@@ -88,18 +88,7 @@ - (instancetype)initWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar
88
88
}
89
89
90
90
- (void )handleMethodCall : (FlutterMethodCall *)call result : (FlutterResult)result {
91
- if ([@" -[InAppPurchasePlugin startProductRequest:result:]" isEqualToString: call.method]) {
92
- [self handleProductRequestMethodCall: call result: result];
93
- } else if ([@" -[InAppPurchasePlugin finishTransaction:result:]" isEqualToString: call.method]) {
94
- [self finishTransaction: call result: result];
95
- } else if ([@" -[InAppPurchasePlugin restoreTransactions:result:]" isEqualToString: call.method]) {
96
- [self restoreTransactions: call result: result];
97
- #if TARGET_OS_IOS
98
- } else if ([@" -[InAppPurchasePlugin presentCodeRedemptionSheet:result:]"
99
- isEqualToString: call.method]) {
100
- [self presentCodeRedemptionSheet: call result: result];
101
- #endif
102
- } else if ([@" -[InAppPurchasePlugin retrieveReceiptData:result:]" isEqualToString: call.method]) {
91
+ if ([@" -[InAppPurchasePlugin retrieveReceiptData:result:]" isEqualToString: call.method]) {
103
92
[self retrieveReceiptData: call result: result];
104
93
} else if ([@" -[InAppPurchasePlugin refreshReceipt:result:]" isEqualToString: call.method]) {
105
94
[self refreshReceipt: call result: result];
@@ -147,38 +136,38 @@ - (nullable SKStorefrontMessage *)storefrontWithError:(FlutterError *_Nullable *
147
136
return [FIAObjectTranslator convertStorefrontToPigeon: storefront];
148
137
}
149
138
150
- - (void )handleProductRequestMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result {
151
- if (![call.arguments isKindOfClass: [NSArray class ]]) {
152
- result ([FlutterError errorWithCode: @" storekit_invalid_argument"
153
- message: @" Argument type of startRequest is not array"
154
- details: call.arguments]);
155
- return ;
156
- }
157
- NSArray *productIdentifiers = (NSArray *)call.arguments ;
139
+ - (void )startProductRequestProductIdentifiers:(NSArray <NSString *> *)productIdentifiers
140
+ completion:(void (^)(SKProductsResponseMessage *_Nullable,
141
+ FlutterError *_Nullable))completion {
158
142
SKProductsRequest *request =
159
143
[self getProductRequestWithIdentifiers: [NSSet setWithArray: productIdentifiers]];
160
144
FIAPRequestHandler *handler = [[FIAPRequestHandler alloc ] initWithRequest: request];
161
145
[self .requestHandlers addObject: handler];
162
146
__weak typeof (self) weakSelf = self;
147
+
163
148
[handler startProductRequestWithCompletionHandler: ^(SKProductsResponse *_Nullable response,
164
- NSError *_Nullable error) {
165
- if (error) {
166
- result ([FlutterError errorWithCode: @" storekit_getproductrequest_platform_error"
167
- message: error.localizedDescription
168
- details: error.description]);
149
+ NSError *_Nullable startProductRequestError) {
150
+ FlutterError *error = nil ;
151
+ if (startProductRequestError != nil ) {
152
+ error = [FlutterError errorWithCode: @" storekit_getproductrequest_platform_error"
153
+ message: startProductRequestError.localizedDescription
154
+ details: startProductRequestError.description];
155
+ completion (nil , error);
169
156
return ;
170
157
}
171
158
if (!response) {
172
- result ([FlutterError errorWithCode: @" storekit_platform_no_response"
173
- message: @" Failed to get SKProductResponse in startRequest "
174
- @" call. Error occured on iOS platform"
175
- details: call.arguments]);
159
+ error = [FlutterError errorWithCode: @" storekit_platform_no_response"
160
+ message: @" Failed to get SKProductResponse in startRequest "
161
+ @" call. Error occured on iOS platform"
162
+ details: productIdentifiers];
163
+ completion (nil , error);
176
164
return ;
177
165
}
178
166
for (SKProduct *product in response.products ) {
179
167
[self .productsCache setObject: product forKey: product.productIdentifier];
180
168
}
181
- result ([FIAObjectTranslator getMapFromSKProductsResponse: response]);
169
+
170
+ completion ([FIAObjectTranslator convertProductsResponseToPigeon: response], error);
182
171
[weakSelf.requestHandlers removeObject: handler];
183
172
}];
184
173
}
@@ -240,16 +229,10 @@ - (void)addPaymentPaymentMap:(nonnull NSDictionary *)paymentMap
240
229
}
241
230
}
242
231
243
- - (void )finishTransaction:(FlutterMethodCall *)call result:(FlutterResult)result {
244
- if (![call.arguments isKindOfClass: [NSDictionary class ]]) {
245
- result ([FlutterError errorWithCode: @" storekit_invalid_argument"
246
- message: @" Argument type of finishTransaction is not a Dictionary"
247
- details: call.arguments]);
248
- return ;
249
- }
250
- NSDictionary *paymentMap = (NSDictionary *)call.arguments ;
251
- NSString *transactionIdentifier = [paymentMap objectForKey: @" transactionIdentifier" ];
252
- NSString *productIdentifier = [paymentMap objectForKey: @" productIdentifier" ];
232
+ - (void )finishTransactionFinishMap:(nonnull NSDictionary <NSString *, NSString *> *)finishMap
233
+ error:(FlutterError *_Nullable __autoreleasing *_Nonnull)error {
234
+ NSString *transactionIdentifier = [finishMap objectForKey: @" transactionIdentifier" ];
235
+ NSString *productIdentifier = [finishMap objectForKey: @" productIdentifier" ];
253
236
254
237
NSArray <SKPaymentTransaction *> *pendingTransactions =
255
238
[self .paymentQueueHandler getUnfinishedTransactions ];
@@ -265,35 +248,27 @@ - (void)finishTransaction:(FlutterMethodCall *)call result:(FlutterResult)result
265
248
@try {
266
249
[self .paymentQueueHandler finishTransaction: transaction];
267
250
} @catch (NSException *e) {
268
- result ( [FlutterError errorWithCode: @" storekit_finish_transaction_exception"
269
- message: e.name
270
- details: e.description]) ;
251
+ *error = [FlutterError errorWithCode: @" storekit_finish_transaction_exception"
252
+ message: e.name
253
+ details: e.description];
271
254
return ;
272
255
}
273
256
}
274
257
}
275
-
276
- result (nil );
277
258
}
278
259
279
- - (void )restoreTransactions:(FlutterMethodCall *)call result:(FlutterResult)result {
280
- if (call.arguments && ![call.arguments isKindOfClass: [NSString class ]]) {
281
- result ([FlutterError
282
- errorWithCode: @" storekit_invalid_argument"
283
- message: @" Argument is not nil and the type of finishTransaction is not a string."
284
- details: call.arguments]);
285
- return ;
286
- }
287
- [self .paymentQueueHandler restoreTransactions: call.arguments];
288
- result (nil );
260
+ - (void )restoreTransactionsApplicationUserName:(nullable NSString *)applicationUserName
261
+ error:(FlutterError *_Nullable __autoreleasing *_Nonnull)
262
+ error {
263
+ [self .paymentQueueHandler restoreTransactions: applicationUserName];
289
264
}
290
265
266
+ - (void )presentCodeRedemptionSheetWithError:
267
+ (FlutterError *_Nullable __autoreleasing *_Nonnull)error {
291
268
#if TARGET_OS_IOS
292
- - (void )presentCodeRedemptionSheet:(FlutterMethodCall *)call result:(FlutterResult)result {
293
269
[self .paymentQueueHandler presentCodeRedemptionSheet ];
294
- result (nil );
295
- }
296
270
#endif
271
+ }
297
272
298
273
- (void )retrieveReceiptData:(FlutterMethodCall *)call result:(FlutterResult)result {
299
274
FlutterError *error = nil ;
0 commit comments