Skip to content

[in_app_purchase] Convert refreshReceipt(), startObservingPaymentQueue(), stopObservingPaymentQueue(), registerPaymentQueueDelegate(), removePaymentQueueDelegate(), showPriceConsentIfNeeded() to Pigeon #6165

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.3.12

* Converts `refreshReceipt()`, `startObservingPaymentQueue()`, `stopObservingPaymentQueue()`,
`registerPaymentQueueDelegate()`, `removePaymentQueueDelegate()`, `showPriceConsentIfNeeded()` to pigeon.

## 0.3.11

* Fixes SKError.userInfo not being nullable.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,30 +87,6 @@ - (instancetype)initWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar
return self;
}

- (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result {
if ([@"-[InAppPurchasePlugin retrieveReceiptData:result:]" isEqualToString:call.method]) {
[self retrieveReceiptData:call result:result];
} else if ([@"-[InAppPurchasePlugin refreshReceipt:result:]" isEqualToString:call.method]) {
[self refreshReceipt:call result:result];
} else if ([@"-[SKPaymentQueue startObservingTransactionQueue]" isEqualToString:call.method]) {
[self startObservingPaymentQueue:result];
} else if ([@"-[SKPaymentQueue stopObservingTransactionQueue]" isEqualToString:call.method]) {
[self stopObservingPaymentQueue:result];
#if TARGET_OS_IOS
} else if ([@"-[SKPaymentQueue registerDelegate]" isEqualToString:call.method]) {
[self registerPaymentQueueDelegate:result];
#endif
} else if ([@"-[SKPaymentQueue removeDelegate]" isEqualToString:call.method]) {
[self removePaymentQueueDelegate:result];
#if TARGET_OS_IOS
} else if ([@"-[SKPaymentQueue showPriceConsentIfNeeded]" isEqualToString:call.method]) {
[self showPriceConsentIfNeeded:result];
#endif
} else {
result(FlutterMethodNotImplemented);
}
}

- (nullable NSNumber *)canMakePaymentsWithError:
(FlutterError *_Nullable __autoreleasing *_Nonnull)error {
return @([SKPaymentQueue canMakePayments]);
Expand Down Expand Up @@ -270,62 +246,61 @@ - (void)presentCodeRedemptionSheetWithError:
#endif
}

- (void)retrieveReceiptData:(FlutterMethodCall *)call result:(FlutterResult)result {
FlutterError *error = nil;
NSString *receiptData = [self.receiptManager retrieveReceiptWithError:&error];
if (error) {
result(error);
return;
- (nullable NSString *)retrieveReceiptDataWithError:
(FlutterError *_Nullable __autoreleasing *_Nonnull)error {
FlutterError *flutterError;
NSString *receiptData = [self.receiptManager retrieveReceiptWithError:&flutterError];
if (flutterError) {
*error = flutterError;
return nil;
}
result(receiptData);
return receiptData;
}

- (void)refreshReceipt:(FlutterMethodCall *)call result:(FlutterResult)result {
NSDictionary *arguments = call.arguments;
- (void)refreshReceiptReceiptProperties:(nullable NSDictionary *)receiptProperties
completion:(nonnull void (^)(FlutterError *_Nullable))completion {
SKReceiptRefreshRequest *request;
if (arguments) {
if (![arguments isKindOfClass:[NSDictionary class]]) {
result([FlutterError errorWithCode:@"storekit_invalid_argument"
message:@"Argument type of startRequest is not array"
details:call.arguments]);
return;
}
if (receiptProperties) {
// if recieptProperties is not null, this call is for testing.
NSMutableDictionary *properties = [NSMutableDictionary new];
properties[SKReceiptPropertyIsExpired] = arguments[@"isExpired"];
properties[SKReceiptPropertyIsRevoked] = arguments[@"isRevoked"];
properties[SKReceiptPropertyIsVolumePurchase] = arguments[@"isVolumePurchase"];
properties[SKReceiptPropertyIsExpired] = receiptProperties[@"isExpired"];
properties[SKReceiptPropertyIsRevoked] = receiptProperties[@"isRevoked"];
properties[SKReceiptPropertyIsVolumePurchase] = receiptProperties[@"isVolumePurchase"];
request = [self getRefreshReceiptRequest:properties];
} else {
request = [self getRefreshReceiptRequest:nil];
}

FIAPRequestHandler *handler = [[FIAPRequestHandler alloc] initWithRequest:request];
[self.requestHandlers addObject:handler];
__weak typeof(self) weakSelf = self;
[handler startProductRequestWithCompletionHandler:^(SKProductsResponse *_Nullable response,
NSError *_Nullable error) {
FlutterError *requestError;
if (error) {
result([FlutterError errorWithCode:@"storekit_refreshreceiptrequest_platform_error"
message:error.localizedDescription
details:error.description]);
return;
requestError = [FlutterError errorWithCode:@"storekit_refreshreceiptrequest_platform_error"
message:error.localizedDescription
details:error.description];
completion(requestError);
}
result(nil);
completion(nil);
[weakSelf.requestHandlers removeObject:handler];
}];
}

- (void)startObservingPaymentQueue:(FlutterResult)result {
- (void)startObservingPaymentQueueWithError:
(FlutterError *_Nullable __autoreleasing *_Nonnull)error {
[_paymentQueueHandler startObservingPaymentQueue];
result(nil);
}

- (void)stopObservingPaymentQueue:(FlutterResult)result {
- (void)stopObservingPaymentQueueWithError:
(FlutterError *_Nullable __autoreleasing *_Nonnull)error {
[_paymentQueueHandler stopObservingPaymentQueue];
result(nil);
}

- (void)registerPaymentQueueDelegateWithError:
(FlutterError *_Nullable __autoreleasing *_Nonnull)error {
#if TARGET_OS_IOS
- (void)registerPaymentQueueDelegate:(FlutterResult)result {
if (@available(iOS 13.0, *)) {
_paymentQueueDelegateCallbackChannel = [FlutterMethodChannel
methodChannelWithName:@"plugins.flutter.io/in_app_purchase_payment_queue_delegate"
Expand All @@ -335,27 +310,25 @@ - (void)registerPaymentQueueDelegate:(FlutterResult)result {
initWithMethodChannel:_paymentQueueDelegateCallbackChannel];
_paymentQueueHandler.delegate = _paymentQueueDelegate;
}
result(nil);
}
#endif
}

- (void)removePaymentQueueDelegate:(FlutterResult)result {
- (void)removePaymentQueueDelegateWithError:
(FlutterError *_Nullable __autoreleasing *_Nonnull)error {
if (@available(iOS 13.0, *)) {
_paymentQueueHandler.delegate = nil;
}
_paymentQueueDelegate = nil;
_paymentQueueDelegateCallbackChannel = nil;
result(nil);
}

- (void)showPriceConsentIfNeededWithError:(FlutterError *_Nullable __autoreleasing *_Nonnull)error {
#if TARGET_OS_IOS
- (void)showPriceConsentIfNeeded:(FlutterResult)result {
if (@available(iOS 13.4, *)) {
[_paymentQueueHandler showPriceConsentIfNeeded];
}
result(nil);
}
#endif
}

- (id)getNonNullValueFromDictionary:(NSDictionary *)dictionary forKey:(NSString *)key {
id value = dictionary[key];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Autogenerated from Pigeon (v16.0.4), do not edit directly.
// See also: https://pub.dev/packages/pigeon

Expand Down Expand Up @@ -271,6 +270,14 @@ NSObject<FlutterMessageCodec> *InAppPurchaseAPIGetCodec(void);
- (void)restoreTransactionsApplicationUserName:(nullable NSString *)applicationUserName
error:(FlutterError *_Nullable *_Nonnull)error;
- (void)presentCodeRedemptionSheetWithError:(FlutterError *_Nullable *_Nonnull)error;
- (nullable NSString *)retrieveReceiptDataWithError:(FlutterError *_Nullable *_Nonnull)error;
- (void)refreshReceiptReceiptProperties:(nullable NSDictionary<NSString *, id> *)receiptProperties
completion:(void (^)(FlutterError *_Nullable))completion;
- (void)startObservingPaymentQueueWithError:(FlutterError *_Nullable *_Nonnull)error;
- (void)stopObservingPaymentQueueWithError:(FlutterError *_Nullable *_Nonnull)error;
- (void)registerPaymentQueueDelegateWithError:(FlutterError *_Nullable *_Nonnull)error;
- (void)removePaymentQueueDelegateWithError:(FlutterError *_Nullable *_Nonnull)error;
- (void)showPriceConsentIfNeededWithError:(FlutterError *_Nullable *_Nonnull)error;
@end

extern void SetUpInAppPurchaseAPI(id<FlutterBinaryMessenger> binaryMessenger,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Autogenerated from Pigeon (v16.0.4), do not edit directly.
// See also: https://pub.dev/packages/pigeon

Expand Down Expand Up @@ -752,4 +751,147 @@ void SetUpInAppPurchaseAPI(id<FlutterBinaryMessenger> binaryMessenger,
[channel setMessageHandler:nil];
}
}
{
FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc]
initWithName:
@"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.retrieveReceiptData"
binaryMessenger:binaryMessenger
codec:InAppPurchaseAPIGetCodec()];
if (api) {
NSCAssert(
[api respondsToSelector:@selector(retrieveReceiptDataWithError:)],
@"InAppPurchaseAPI api (%@) doesn't respond to @selector(retrieveReceiptDataWithError:)",
api);
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
FlutterError *error;
NSString *output = [api retrieveReceiptDataWithError:&error];
callback(wrapResult(output, error));
}];
} else {
[channel setMessageHandler:nil];
}
}
{
FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc]
initWithName:
@"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.refreshReceipt"
binaryMessenger:binaryMessenger
codec:InAppPurchaseAPIGetCodec()];
if (api) {
NSCAssert([api respondsToSelector:@selector(refreshReceiptReceiptProperties:completion:)],
@"InAppPurchaseAPI api (%@) doesn't respond to "
@"@selector(refreshReceiptReceiptProperties:completion:)",
api);
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
NSArray *args = message;
NSDictionary<NSString *, id> *arg_receiptProperties = GetNullableObjectAtIndex(args, 0);
[api refreshReceiptReceiptProperties:arg_receiptProperties
completion:^(FlutterError *_Nullable error) {
callback(wrapResult(nil, error));
}];
}];
} else {
[channel setMessageHandler:nil];
}
}
{
FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc]
initWithName:@"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI."
@"startObservingPaymentQueue"
binaryMessenger:binaryMessenger
codec:InAppPurchaseAPIGetCodec()];
if (api) {
NSCAssert([api respondsToSelector:@selector(startObservingPaymentQueueWithError:)],
@"InAppPurchaseAPI api (%@) doesn't respond to "
@"@selector(startObservingPaymentQueueWithError:)",
api);
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
FlutterError *error;
[api startObservingPaymentQueueWithError:&error];
callback(wrapResult(nil, error));
}];
} else {
[channel setMessageHandler:nil];
}
}
{
FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc]
initWithName:@"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI."
@"stopObservingPaymentQueue"
binaryMessenger:binaryMessenger
codec:InAppPurchaseAPIGetCodec()];
if (api) {
NSCAssert([api respondsToSelector:@selector(stopObservingPaymentQueueWithError:)],
@"InAppPurchaseAPI api (%@) doesn't respond to "
@"@selector(stopObservingPaymentQueueWithError:)",
api);
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
FlutterError *error;
[api stopObservingPaymentQueueWithError:&error];
callback(wrapResult(nil, error));
}];
} else {
[channel setMessageHandler:nil];
}
}
{
FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc]
initWithName:@"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI."
@"registerPaymentQueueDelegate"
binaryMessenger:binaryMessenger
codec:InAppPurchaseAPIGetCodec()];
if (api) {
NSCAssert([api respondsToSelector:@selector(registerPaymentQueueDelegateWithError:)],
@"InAppPurchaseAPI api (%@) doesn't respond to "
@"@selector(registerPaymentQueueDelegateWithError:)",
api);
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
FlutterError *error;
[api registerPaymentQueueDelegateWithError:&error];
callback(wrapResult(nil, error));
}];
} else {
[channel setMessageHandler:nil];
}
}
{
FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc]
initWithName:@"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI."
@"removePaymentQueueDelegate"
binaryMessenger:binaryMessenger
codec:InAppPurchaseAPIGetCodec()];
if (api) {
NSCAssert([api respondsToSelector:@selector(removePaymentQueueDelegateWithError:)],
@"InAppPurchaseAPI api (%@) doesn't respond to "
@"@selector(removePaymentQueueDelegateWithError:)",
api);
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
FlutterError *error;
[api removePaymentQueueDelegateWithError:&error];
callback(wrapResult(nil, error));
}];
} else {
[channel setMessageHandler:nil];
}
}
{
FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc]
initWithName:@"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI."
@"showPriceConsentIfNeeded"
binaryMessenger:binaryMessenger
codec:InAppPurchaseAPIGetCodec()];
if (api) {
NSCAssert([api respondsToSelector:@selector(showPriceConsentIfNeededWithError:)],
@"InAppPurchaseAPI api (%@) doesn't respond to "
@"@selector(showPriceConsentIfNeededWithError:)",
api);
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
FlutterError *error;
[api showPriceConsentIfNeededWithError:&error];
callback(wrapResult(nil, error));
}];
} else {
[channel setMessageHandler:nil];
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
Expand Down
Loading