Skip to content

Commit 1c11001

Browse files
authored
[in_app_purchase] Convert refreshReceipt(), startObservingPaymentQueue(), stopObservingPaymentQueue(), registerPaymentQueueDelegate(), removePaymentQueueDelegate(), showPriceConsentIfNeeded() to Pigeon (#6165)
Part 3 of flutter/flutter#117910
1 parent 784190c commit 1c11001

19 files changed

+722
-304
lines changed

packages/in_app_purchase/in_app_purchase_storekit/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.3.12
2+
3+
* Converts `refreshReceipt()`, `startObservingPaymentQueue()`, `stopObservingPaymentQueue()`,
4+
`registerPaymentQueueDelegate()`, `removePaymentQueueDelegate()`, `showPriceConsentIfNeeded()` to pigeon.
5+
16
## 0.3.11
27

38
* Fixes SKError.userInfo not being nullable.

packages/in_app_purchase/in_app_purchase_storekit/darwin/Classes/InAppPurchasePlugin.m

Lines changed: 33 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -87,30 +87,6 @@ - (instancetype)initWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar
8787
return self;
8888
}
8989

90-
- (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result {
91-
if ([@"-[InAppPurchasePlugin retrieveReceiptData:result:]" isEqualToString:call.method]) {
92-
[self retrieveReceiptData:call result:result];
93-
} else if ([@"-[InAppPurchasePlugin refreshReceipt:result:]" isEqualToString:call.method]) {
94-
[self refreshReceipt:call result:result];
95-
} else if ([@"-[SKPaymentQueue startObservingTransactionQueue]" isEqualToString:call.method]) {
96-
[self startObservingPaymentQueue:result];
97-
} else if ([@"-[SKPaymentQueue stopObservingTransactionQueue]" isEqualToString:call.method]) {
98-
[self stopObservingPaymentQueue:result];
99-
#if TARGET_OS_IOS
100-
} else if ([@"-[SKPaymentQueue registerDelegate]" isEqualToString:call.method]) {
101-
[self registerPaymentQueueDelegate:result];
102-
#endif
103-
} else if ([@"-[SKPaymentQueue removeDelegate]" isEqualToString:call.method]) {
104-
[self removePaymentQueueDelegate:result];
105-
#if TARGET_OS_IOS
106-
} else if ([@"-[SKPaymentQueue showPriceConsentIfNeeded]" isEqualToString:call.method]) {
107-
[self showPriceConsentIfNeeded:result];
108-
#endif
109-
} else {
110-
result(FlutterMethodNotImplemented);
111-
}
112-
}
113-
11490
- (nullable NSNumber *)canMakePaymentsWithError:
11591
(FlutterError *_Nullable __autoreleasing *_Nonnull)error {
11692
return @([SKPaymentQueue canMakePayments]);
@@ -270,62 +246,61 @@ - (void)presentCodeRedemptionSheetWithError:
270246
#endif
271247
}
272248

273-
- (void)retrieveReceiptData:(FlutterMethodCall *)call result:(FlutterResult)result {
274-
FlutterError *error = nil;
275-
NSString *receiptData = [self.receiptManager retrieveReceiptWithError:&error];
276-
if (error) {
277-
result(error);
278-
return;
249+
- (nullable NSString *)retrieveReceiptDataWithError:
250+
(FlutterError *_Nullable __autoreleasing *_Nonnull)error {
251+
FlutterError *flutterError;
252+
NSString *receiptData = [self.receiptManager retrieveReceiptWithError:&flutterError];
253+
if (flutterError) {
254+
*error = flutterError;
255+
return nil;
279256
}
280-
result(receiptData);
257+
return receiptData;
281258
}
282259

283-
- (void)refreshReceipt:(FlutterMethodCall *)call result:(FlutterResult)result {
284-
NSDictionary *arguments = call.arguments;
260+
- (void)refreshReceiptReceiptProperties:(nullable NSDictionary *)receiptProperties
261+
completion:(nonnull void (^)(FlutterError *_Nullable))completion {
285262
SKReceiptRefreshRequest *request;
286-
if (arguments) {
287-
if (![arguments isKindOfClass:[NSDictionary class]]) {
288-
result([FlutterError errorWithCode:@"storekit_invalid_argument"
289-
message:@"Argument type of startRequest is not array"
290-
details:call.arguments]);
291-
return;
292-
}
263+
if (receiptProperties) {
264+
// if recieptProperties is not null, this call is for testing.
293265
NSMutableDictionary *properties = [NSMutableDictionary new];
294-
properties[SKReceiptPropertyIsExpired] = arguments[@"isExpired"];
295-
properties[SKReceiptPropertyIsRevoked] = arguments[@"isRevoked"];
296-
properties[SKReceiptPropertyIsVolumePurchase] = arguments[@"isVolumePurchase"];
266+
properties[SKReceiptPropertyIsExpired] = receiptProperties[@"isExpired"];
267+
properties[SKReceiptPropertyIsRevoked] = receiptProperties[@"isRevoked"];
268+
properties[SKReceiptPropertyIsVolumePurchase] = receiptProperties[@"isVolumePurchase"];
297269
request = [self getRefreshReceiptRequest:properties];
298270
} else {
299271
request = [self getRefreshReceiptRequest:nil];
300272
}
273+
301274
FIAPRequestHandler *handler = [[FIAPRequestHandler alloc] initWithRequest:request];
302275
[self.requestHandlers addObject:handler];
303276
__weak typeof(self) weakSelf = self;
304277
[handler startProductRequestWithCompletionHandler:^(SKProductsResponse *_Nullable response,
305278
NSError *_Nullable error) {
279+
FlutterError *requestError;
306280
if (error) {
307-
result([FlutterError errorWithCode:@"storekit_refreshreceiptrequest_platform_error"
308-
message:error.localizedDescription
309-
details:error.description]);
310-
return;
281+
requestError = [FlutterError errorWithCode:@"storekit_refreshreceiptrequest_platform_error"
282+
message:error.localizedDescription
283+
details:error.description];
284+
completion(requestError);
311285
}
312-
result(nil);
286+
completion(nil);
313287
[weakSelf.requestHandlers removeObject:handler];
314288
}];
315289
}
316290

317-
- (void)startObservingPaymentQueue:(FlutterResult)result {
291+
- (void)startObservingPaymentQueueWithError:
292+
(FlutterError *_Nullable __autoreleasing *_Nonnull)error {
318293
[_paymentQueueHandler startObservingPaymentQueue];
319-
result(nil);
320294
}
321295

322-
- (void)stopObservingPaymentQueue:(FlutterResult)result {
296+
- (void)stopObservingPaymentQueueWithError:
297+
(FlutterError *_Nullable __autoreleasing *_Nonnull)error {
323298
[_paymentQueueHandler stopObservingPaymentQueue];
324-
result(nil);
325299
}
326300

301+
- (void)registerPaymentQueueDelegateWithError:
302+
(FlutterError *_Nullable __autoreleasing *_Nonnull)error {
327303
#if TARGET_OS_IOS
328-
- (void)registerPaymentQueueDelegate:(FlutterResult)result {
329304
if (@available(iOS 13.0, *)) {
330305
_paymentQueueDelegateCallbackChannel = [FlutterMethodChannel
331306
methodChannelWithName:@"plugins.flutter.io/in_app_purchase_payment_queue_delegate"
@@ -335,27 +310,25 @@ - (void)registerPaymentQueueDelegate:(FlutterResult)result {
335310
initWithMethodChannel:_paymentQueueDelegateCallbackChannel];
336311
_paymentQueueHandler.delegate = _paymentQueueDelegate;
337312
}
338-
result(nil);
339-
}
340313
#endif
314+
}
341315

342-
- (void)removePaymentQueueDelegate:(FlutterResult)result {
316+
- (void)removePaymentQueueDelegateWithError:
317+
(FlutterError *_Nullable __autoreleasing *_Nonnull)error {
343318
if (@available(iOS 13.0, *)) {
344319
_paymentQueueHandler.delegate = nil;
345320
}
346321
_paymentQueueDelegate = nil;
347322
_paymentQueueDelegateCallbackChannel = nil;
348-
result(nil);
349323
}
350324

325+
- (void)showPriceConsentIfNeededWithError:(FlutterError *_Nullable __autoreleasing *_Nonnull)error {
351326
#if TARGET_OS_IOS
352-
- (void)showPriceConsentIfNeeded:(FlutterResult)result {
353327
if (@available(iOS 13.4, *)) {
354328
[_paymentQueueHandler showPriceConsentIfNeeded];
355329
}
356-
result(nil);
357-
}
358330
#endif
331+
}
359332

360333
- (id)getNonNullValueFromDictionary:(NSDictionary *)dictionary forKey:(NSString *)key {
361334
id value = dictionary[key];

packages/in_app_purchase/in_app_purchase_storekit/darwin/Classes/messages.g.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright 2013 The Flutter Authors. All rights reserved.
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
4-
54
// Autogenerated from Pigeon (v16.0.4), do not edit directly.
65
// See also: https://pub.dev/packages/pigeon
76

@@ -271,6 +270,14 @@ NSObject<FlutterMessageCodec> *InAppPurchaseAPIGetCodec(void);
271270
- (void)restoreTransactionsApplicationUserName:(nullable NSString *)applicationUserName
272271
error:(FlutterError *_Nullable *_Nonnull)error;
273272
- (void)presentCodeRedemptionSheetWithError:(FlutterError *_Nullable *_Nonnull)error;
273+
- (nullable NSString *)retrieveReceiptDataWithError:(FlutterError *_Nullable *_Nonnull)error;
274+
- (void)refreshReceiptReceiptProperties:(nullable NSDictionary<NSString *, id> *)receiptProperties
275+
completion:(void (^)(FlutterError *_Nullable))completion;
276+
- (void)startObservingPaymentQueueWithError:(FlutterError *_Nullable *_Nonnull)error;
277+
- (void)stopObservingPaymentQueueWithError:(FlutterError *_Nullable *_Nonnull)error;
278+
- (void)registerPaymentQueueDelegateWithError:(FlutterError *_Nullable *_Nonnull)error;
279+
- (void)removePaymentQueueDelegateWithError:(FlutterError *_Nullable *_Nonnull)error;
280+
- (void)showPriceConsentIfNeededWithError:(FlutterError *_Nullable *_Nonnull)error;
274281
@end
275282

276283
extern void SetUpInAppPurchaseAPI(id<FlutterBinaryMessenger> binaryMessenger,

packages/in_app_purchase/in_app_purchase_storekit/darwin/Classes/messages.g.m

Lines changed: 143 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright 2013 The Flutter Authors. All rights reserved.
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
4-
54
// Autogenerated from Pigeon (v16.0.4), do not edit directly.
65
// See also: https://pub.dev/packages/pigeon
76

@@ -752,4 +751,147 @@ void SetUpInAppPurchaseAPI(id<FlutterBinaryMessenger> binaryMessenger,
752751
[channel setMessageHandler:nil];
753752
}
754753
}
754+
{
755+
FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc]
756+
initWithName:
757+
@"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.retrieveReceiptData"
758+
binaryMessenger:binaryMessenger
759+
codec:InAppPurchaseAPIGetCodec()];
760+
if (api) {
761+
NSCAssert(
762+
[api respondsToSelector:@selector(retrieveReceiptDataWithError:)],
763+
@"InAppPurchaseAPI api (%@) doesn't respond to @selector(retrieveReceiptDataWithError:)",
764+
api);
765+
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
766+
FlutterError *error;
767+
NSString *output = [api retrieveReceiptDataWithError:&error];
768+
callback(wrapResult(output, error));
769+
}];
770+
} else {
771+
[channel setMessageHandler:nil];
772+
}
773+
}
774+
{
775+
FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc]
776+
initWithName:
777+
@"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.refreshReceipt"
778+
binaryMessenger:binaryMessenger
779+
codec:InAppPurchaseAPIGetCodec()];
780+
if (api) {
781+
NSCAssert([api respondsToSelector:@selector(refreshReceiptReceiptProperties:completion:)],
782+
@"InAppPurchaseAPI api (%@) doesn't respond to "
783+
@"@selector(refreshReceiptReceiptProperties:completion:)",
784+
api);
785+
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
786+
NSArray *args = message;
787+
NSDictionary<NSString *, id> *arg_receiptProperties = GetNullableObjectAtIndex(args, 0);
788+
[api refreshReceiptReceiptProperties:arg_receiptProperties
789+
completion:^(FlutterError *_Nullable error) {
790+
callback(wrapResult(nil, error));
791+
}];
792+
}];
793+
} else {
794+
[channel setMessageHandler:nil];
795+
}
796+
}
797+
{
798+
FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc]
799+
initWithName:@"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI."
800+
@"startObservingPaymentQueue"
801+
binaryMessenger:binaryMessenger
802+
codec:InAppPurchaseAPIGetCodec()];
803+
if (api) {
804+
NSCAssert([api respondsToSelector:@selector(startObservingPaymentQueueWithError:)],
805+
@"InAppPurchaseAPI api (%@) doesn't respond to "
806+
@"@selector(startObservingPaymentQueueWithError:)",
807+
api);
808+
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
809+
FlutterError *error;
810+
[api startObservingPaymentQueueWithError:&error];
811+
callback(wrapResult(nil, error));
812+
}];
813+
} else {
814+
[channel setMessageHandler:nil];
815+
}
816+
}
817+
{
818+
FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc]
819+
initWithName:@"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI."
820+
@"stopObservingPaymentQueue"
821+
binaryMessenger:binaryMessenger
822+
codec:InAppPurchaseAPIGetCodec()];
823+
if (api) {
824+
NSCAssert([api respondsToSelector:@selector(stopObservingPaymentQueueWithError:)],
825+
@"InAppPurchaseAPI api (%@) doesn't respond to "
826+
@"@selector(stopObservingPaymentQueueWithError:)",
827+
api);
828+
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
829+
FlutterError *error;
830+
[api stopObservingPaymentQueueWithError:&error];
831+
callback(wrapResult(nil, error));
832+
}];
833+
} else {
834+
[channel setMessageHandler:nil];
835+
}
836+
}
837+
{
838+
FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc]
839+
initWithName:@"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI."
840+
@"registerPaymentQueueDelegate"
841+
binaryMessenger:binaryMessenger
842+
codec:InAppPurchaseAPIGetCodec()];
843+
if (api) {
844+
NSCAssert([api respondsToSelector:@selector(registerPaymentQueueDelegateWithError:)],
845+
@"InAppPurchaseAPI api (%@) doesn't respond to "
846+
@"@selector(registerPaymentQueueDelegateWithError:)",
847+
api);
848+
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
849+
FlutterError *error;
850+
[api registerPaymentQueueDelegateWithError:&error];
851+
callback(wrapResult(nil, error));
852+
}];
853+
} else {
854+
[channel setMessageHandler:nil];
855+
}
856+
}
857+
{
858+
FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc]
859+
initWithName:@"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI."
860+
@"removePaymentQueueDelegate"
861+
binaryMessenger:binaryMessenger
862+
codec:InAppPurchaseAPIGetCodec()];
863+
if (api) {
864+
NSCAssert([api respondsToSelector:@selector(removePaymentQueueDelegateWithError:)],
865+
@"InAppPurchaseAPI api (%@) doesn't respond to "
866+
@"@selector(removePaymentQueueDelegateWithError:)",
867+
api);
868+
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
869+
FlutterError *error;
870+
[api removePaymentQueueDelegateWithError:&error];
871+
callback(wrapResult(nil, error));
872+
}];
873+
} else {
874+
[channel setMessageHandler:nil];
875+
}
876+
}
877+
{
878+
FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc]
879+
initWithName:@"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI."
880+
@"showPriceConsentIfNeeded"
881+
binaryMessenger:binaryMessenger
882+
codec:InAppPurchaseAPIGetCodec()];
883+
if (api) {
884+
NSCAssert([api respondsToSelector:@selector(showPriceConsentIfNeededWithError:)],
885+
@"InAppPurchaseAPI api (%@) doesn't respond to "
886+
@"@selector(showPriceConsentIfNeededWithError:)",
887+
api);
888+
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
889+
FlutterError *error;
890+
[api showPriceConsentIfNeededWithError:&error];
891+
callback(wrapResult(nil, error));
892+
}];
893+
} else {
894+
[channel setMessageHandler:nil];
895+
}
896+
}
755897
}

packages/in_app_purchase/in_app_purchase_storekit/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
buildConfiguration = "Debug"
2727
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
2828
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29-
shouldUseLaunchSchemeArgsEnv = "YES">
29+
shouldUseLaunchSchemeArgsEnv = "YES"
30+
codeCoverageEnabled = "YES">
3031
<MacroExpansion>
3132
<BuildableReference
3233
BuildableIdentifier = "primary"

0 commit comments

Comments
 (0)