Skip to content

Commit

Permalink
[in_app_purchase_storekit] Remove OCMock (flutter#6862)
Browse files Browse the repository at this point in the history
Fixes flutter#149849

Also fixes the broken symlinking between test files.

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] page, which explains my
responsibilities.
- [x] I read and followed the [relevant style guides] and ran the
auto-formatter. (Unlike the flutter/flutter repo, the flutter/packages
repo does use `dart format`.)
- [x] I signed the [CLA].
- [x] The title of the PR starts with the name of the package surrounded
by square brackets, e.g. `[shared_preferences]`
- [x] I [linked to at least one issue that this PR fixes] in the
description above.
- [x] I updated `pubspec.yaml` with an appropriate new version according
to the [pub versioning philosophy], or this PR is [exempt from version
changes].
- [x] I updated `CHANGELOG.md` to add a description of the change,
[following repository CHANGELOG style], or this PR is [exempt from
CHANGELOG changes].
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/packages/blob/main/CONTRIBUTING.md
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md
[relevant style guides]:
https://github.com/flutter/packages/blob/main/CONTRIBUTING.md#style
[CLA]: https://cla.developers.google.com/
[Discord]:
https://github.com/flutter/flutter/blob/master/docs/contributing/Chat.md
[linked to at least one issue that this PR fixes]:
https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md#overview
[pub versioning philosophy]: https://dart.dev/tools/pub/versioning
[exempt from version changes]:
https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#version
[following repository CHANGELOG style]:
https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changelog-style
[exempt from CHANGELOG changes]:
https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changelog
[test-exempt]:
https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md#tests
  • Loading branch information
LouiseHsu authored Jun 22, 2024
1 parent 04d2572 commit 02e71b0
Show file tree
Hide file tree
Showing 32 changed files with 1,617 additions and 617 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
## 0.3.17

* Removes OCMock from tests.

## 0.3.16

* Converts main plugin class to Swift
* Converts main plugin class to Swift.

## 0.3.15

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
#endif
#import <Foundation/Foundation.h>
#import <StoreKit/StoreKit.h>
#import "FLTMethodChannelProtocol.h"

NS_ASSUME_NONNULL_BEGIN

API_AVAILABLE(ios(13))
API_UNAVAILABLE(tvos, macos, watchos)
@interface FIAPPaymentQueueDelegate : NSObject <SKPaymentQueueDelegate>
- (id)initWithMethodChannel:(FlutterMethodChannel *)methodChannel;
- (id)initWithMethodChannel:(id<FLTMethodChannelProtocol>)methodChannel;
@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@

@interface FIAPPaymentQueueDelegate ()

@property(strong, nonatomic, readonly) FlutterMethodChannel *callbackChannel;
// The designated Flutter method channel that handles if a transaction should be continued
@property(nonatomic, strong, readonly) id<FLTMethodChannelProtocol> callbackChannel;

@end

@implementation FIAPPaymentQueueDelegate

- (id)initWithMethodChannel:(FlutterMethodChannel *)methodChannel {
- (id)initWithMethodChannel:(id<FLTMethodChannelProtocol>)methodChannel {
self = [super init];
if (self) {
_callbackChannel = methodChannel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ @interface FIAPReceiptManager ()
// Gets the receipt file data from the location of the url. Can be nil if
// there is an error. This interface is defined so it can be stubbed for testing.
- (NSData *)getReceiptData:(NSURL *)url error:(NSError **)error;

// Gets the app store receipt url. Can be nil if
// there is an error. This property is defined so it can be stubbed for testing.
@property(nonatomic, readonly) NSURL *receiptURL;
@end

@implementation FIAPReceiptManager

- (NSString *)retrieveReceiptWithError:(FlutterError **)flutterError {
NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL];
NSURL *receiptURL = self.receiptURL;
if (!receiptURL) {
return nil;
}
Expand All @@ -43,4 +45,8 @@ - (NSData *)getReceiptData:(NSURL *)url error:(NSError **)error {
return [NSData dataWithContentsOfURL:url options:NSDataReadingMappedIfSafe error:error];
}

- (NSURL *)receiptURL {
return [[NSBundle mainBundle] appStoreReceiptURL];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#import <FLTRequestHandlerProtocol.h>
#import <Foundation/Foundation.h>
#import <StoreKit/StoreKit.h>

NS_ASSUME_NONNULL_BEGIN

typedef void (^ProductRequestCompletion)(SKProductsResponse *_Nullable response,
NSError *_Nullable errror);

@interface FIAPRequestHandler : NSObject
@interface FIAPRequestHandler : NSObject <FLTRequestHandlerProtocol>

- (instancetype)initWithRequest:(SKRequest *)request;
- (void)startProductRequestWithCompletionHandler:(ProductRequestCompletion)completion;

@end

// The default request handler that wraps FIAPRequestHandler
@interface DefaultRequestHandler : NSObject <FLTRequestHandlerProtocol>

// Initialize this wrapper with an instance of FIAPRequestHandler
- (instancetype)initWithRequestHandler:(FIAPRequestHandler *)handler;
@end
NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

@interface FIAPRequestHandler () <SKProductsRequestDelegate>

@property(copy, nonatomic) ProductRequestCompletion completion;
@property(strong, nonatomic) SKRequest *request;
@property(nonatomic, copy) ProductRequestCompletion completion;
@property(nonatomic, strong) SKRequest *request;

@end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,130 +5,16 @@
#import <Foundation/Foundation.h>
#import <StoreKit/StoreKit.h>
#import "FIATransactionCache.h"
#import "FLTPaymentQueueHandlerProtocol.h"
#import "FLTPaymentQueueProtocol.h"
#import "FLTTransactionCacheProtocol.h"

@class SKPaymentTransaction;

NS_ASSUME_NONNULL_BEGIN

typedef void (^TransactionsUpdated)(NSArray<SKPaymentTransaction *> *transactions);
typedef void (^TransactionsRemoved)(NSArray<SKPaymentTransaction *> *transactions);
typedef void (^RestoreTransactionFailed)(NSError *error);
typedef void (^RestoreCompletedTransactionsFinished)(void);
typedef BOOL (^ShouldAddStorePayment)(SKPayment *payment, SKProduct *product);
typedef void (^UpdatedDownloads)(NSArray<SKDownload *> *downloads);

@interface FIAPaymentQueueHandler : NSObject <SKPaymentTransactionObserver>

@property(NS_NONATOMIC_IOSONLY, weak, nullable) id<SKPaymentQueueDelegate> delegate API_AVAILABLE(
ios(13.0), macos(10.15), watchos(6.2));
@property(nonatomic, readonly, nullable)
SKStorefront *storefront API_AVAILABLE(ios(13.0), macos(10.15), watchos(6.2));

/// Creates a new FIAPaymentQueueHandler initialized with an empty
/// FIATransactionCache.
///
/// @param queue The SKPaymentQueue instance connected to the App Store and
/// responsible for processing transactions.
/// @param transactionsUpdated Callback method that is called each time the App
/// Store indicates transactions are updated.
/// @param transactionsRemoved Callback method that is called each time the App
/// Store indicates transactions are removed.
/// @param restoreTransactionFailed Callback method that is called each time
/// the App Store indicates transactions failed
/// to restore.
/// @param restoreCompletedTransactionsFinished Callback method that is called
/// each time the App Store
/// indicates restoring of
/// transactions has finished.
/// @param shouldAddStorePayment Callback method that is called each time an
/// in-app purchase has been initiated from the
/// App Store.
/// @param updatedDownloads Callback method that is called each time the App
/// Store indicates downloads are updated.
- (instancetype)initWithQueue:(nonnull SKPaymentQueue *)queue
transactionsUpdated:(nullable TransactionsUpdated)transactionsUpdated
transactionRemoved:(nullable TransactionsRemoved)transactionsRemoved
restoreTransactionFailed:(nullable RestoreTransactionFailed)restoreTransactionFailed
restoreCompletedTransactionsFinished:
(nullable RestoreCompletedTransactionsFinished)restoreCompletedTransactionsFinished
shouldAddStorePayment:(nullable ShouldAddStorePayment)shouldAddStorePayment
updatedDownloads:(nullable UpdatedDownloads)updatedDownloads
DEPRECATED_MSG_ATTRIBUTE(
"Use the "
"'initWithQueue:transactionsUpdated:transactionsRemoved:restoreTransactionsFinished:"
"shouldAddStorePayment:updatedDownloads:transactionCache:' message instead.");

/// Creates a new FIAPaymentQueueHandler.
///
/// The "transactionsUpdated", "transactionsRemoved" and "updatedDownloads"
/// callbacks are only called while actively observing transactions. To start
/// observing transactions send the "startObservingPaymentQueue" message.
/// Sending the "stopObservingPaymentQueue" message will stop actively
/// observing transactions. When transactions are not observed they are cached
/// to the "transactionCache" and will be delivered via the
/// "transactionsUpdated", "transactionsRemoved" and "updatedDownloads"
/// callbacks as soon as the "startObservingPaymentQueue" message arrives.
///
/// Note: cached transactions that are not processed when the application is
/// killed will be delivered again by the App Store as soon as the application
/// starts again.
///
/// @param queue The SKPaymentQueue instance connected to the App Store and
/// responsible for processing transactions.
/// @param transactionsUpdated Callback method that is called each time the App
/// Store indicates transactions are updated.
/// @param transactionsRemoved Callback method that is called each time the App
/// Store indicates transactions are removed.
/// @param restoreTransactionFailed Callback method that is called each time
/// the App Store indicates transactions failed
/// to restore.
/// @param restoreCompletedTransactionsFinished Callback method that is called
/// each time the App Store
/// indicates restoring of
/// transactions has finished.
/// @param shouldAddStorePayment Callback method that is called each time an
/// in-app purchase has been initiated from the
/// App Store.
/// @param updatedDownloads Callback method that is called each time the App
/// Store indicates downloads are updated.
/// @param transactionCache An empty [FIATransactionCache] instance that is
/// responsible for keeping track of transactions that
/// arrive when not actively observing transactions.
- (instancetype)initWithQueue:(nonnull SKPaymentQueue *)queue
transactionsUpdated:(nullable TransactionsUpdated)transactionsUpdated
transactionRemoved:(nullable TransactionsRemoved)transactionsRemoved
restoreTransactionFailed:(nullable RestoreTransactionFailed)restoreTransactionFailed
restoreCompletedTransactionsFinished:
(nullable RestoreCompletedTransactionsFinished)restoreCompletedTransactionsFinished
shouldAddStorePayment:(nullable ShouldAddStorePayment)shouldAddStorePayment
updatedDownloads:(nullable UpdatedDownloads)updatedDownloads
transactionCache:(nonnull FIATransactionCache *)transactionCache;
// Can throw exceptions if the transaction type is purchasing, should always used in a @try block.
- (void)finishTransaction:(nonnull SKPaymentTransaction *)transaction;
- (void)restoreTransactions:(nullable NSString *)applicationName;
- (void)presentCodeRedemptionSheet API_UNAVAILABLE(tvos, macos, watchos);
- (NSArray<SKPaymentTransaction *> *)getUnfinishedTransactions;

// This method needs to be called before any other methods.
- (void)startObservingPaymentQueue;
// Call this method when the Flutter app is no longer listening
- (void)stopObservingPaymentQueue;

// Appends a payment to the SKPaymentQueue.
//
// @param payment Payment object to be added to the payment queue.
// @return whether "addPayment" was successful.
- (BOOL)addPayment:(SKPayment *)payment;

// Displays the price consent sheet.
//
// The price consent sheet is only displayed when the following
// is true:
// - You have increased the price of the subscription in App Store Connect.
// - The subscriber has not yet responded to a price consent query.
// Otherwise the method has no effect.
- (void)showPriceConsentIfNeeded API_AVAILABLE(ios(13.4))API_UNAVAILABLE(tvos, macos, watchos);

@interface FIAPaymentQueueHandler
: NSObject <SKPaymentTransactionObserver, FLTPaymentQueueHandlerProtocol>
@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,34 @@ @interface FIAPaymentQueueHandler ()

/// The SKPaymentQueue instance connected to the App Store and responsible for processing
/// transactions.
@property(strong, nonatomic) SKPaymentQueue *queue;
@property(nonatomic, strong) SKPaymentQueue *queue;

/// Callback method that is called each time the App Store indicates transactions are updated.
@property(nullable, copy, nonatomic) TransactionsUpdated transactionsUpdated;
@property(nonatomic, nullable, copy) TransactionsUpdated transactionsUpdated;

/// Callback method that is called each time the App Store indicates transactions are removed.
@property(nullable, copy, nonatomic) TransactionsRemoved transactionsRemoved;
@property(nonatomic, nullable, copy) TransactionsRemoved transactionsRemoved;

/// Callback method that is called each time the App Store indicates transactions failed to restore.
@property(nullable, copy, nonatomic) RestoreTransactionFailed restoreTransactionFailed;
@property(nonatomic, nullable, copy) RestoreTransactionFailed restoreTransactionFailed;

/// Callback method that is called each time the App Store indicates restoring of transactions has
/// finished.
@property(nullable, copy, nonatomic)
@property(nonatomic, nullable, copy)
RestoreCompletedTransactionsFinished paymentQueueRestoreCompletedTransactionsFinished;

/// Callback method that is called each time an in-app purchase has been initiated from the App
/// Store.
@property(nullable, copy, nonatomic) ShouldAddStorePayment shouldAddStorePayment;
@property(nonatomic, nullable, copy) ShouldAddStorePayment shouldAddStorePayment;

/// Callback method that is called each time the App Store indicates downloads are updated.
@property(nullable, copy, nonatomic) UpdatedDownloads updatedDownloads;
@property(nonatomic, nullable, copy) UpdatedDownloads updatedDownloads;

/// The transaction cache responsible for caching transactions.
///
/// Keeps track of transactions that arrive when the Flutter client is not
/// actively observing for transactions.
@property(strong, nonatomic, nonnull) FIATransactionCache *transactionCache;
@property(nonatomic, strong, nonnull) FIATransactionCache *transactionCache;

/// Indicates if the Flutter client is observing transactions.
///
Expand All @@ -51,7 +51,9 @@ @interface FIAPaymentQueueHandler ()

@implementation FIAPaymentQueueHandler

- (instancetype)initWithQueue:(nonnull SKPaymentQueue *)queue
@synthesize delegate;

- (instancetype)initWithQueue:(nonnull id<FLTPaymentQueueProtocol>)queue
transactionsUpdated:(nullable TransactionsUpdated)transactionsUpdated
transactionRemoved:(nullable TransactionsRemoved)transactionsRemoved
restoreTransactionFailed:(nullable RestoreTransactionFailed)restoreTransactionFailed
Expand All @@ -66,18 +68,18 @@ - (instancetype)initWithQueue:(nonnull SKPaymentQueue *)queue
restoreCompletedTransactionsFinished:restoreCompletedTransactionsFinished
shouldAddStorePayment:shouldAddStorePayment
updatedDownloads:updatedDownloads
transactionCache:[[FIATransactionCache alloc] init]];
transactionCache:[[DefaultTransactionCache alloc] init]];
}

- (instancetype)initWithQueue:(nonnull SKPaymentQueue *)queue
- (instancetype)initWithQueue:(nonnull id<FLTPaymentQueueProtocol>)queue
transactionsUpdated:(nullable TransactionsUpdated)transactionsUpdated
transactionRemoved:(nullable TransactionsRemoved)transactionsRemoved
restoreTransactionFailed:(nullable RestoreTransactionFailed)restoreTransactionFailed
restoreCompletedTransactionsFinished:
(nullable RestoreCompletedTransactionsFinished)restoreCompletedTransactionsFinished
shouldAddStorePayment:(nullable ShouldAddStorePayment)shouldAddStorePayment
updatedDownloads:(nullable UpdatedDownloads)updatedDownloads
transactionCache:(nonnull FIATransactionCache *)transactionCache {
transactionCache:(nonnull id<FLTTransactionCacheProtocol>)transactionCache {
self = [super init];
if (self) {
_queue = queue;
Expand Down Expand Up @@ -170,7 +172,7 @@ - (void)presentCodeRedemptionSheet {
#endif

#if TARGET_OS_IOS
- (void)showPriceConsentIfNeeded {
- (void)showPriceConsentIfNeeded API_AVAILABLE(ios(13.4)) {
[self.queue showPriceConsentIfNeeded];
}
#endif
Expand Down Expand Up @@ -233,7 +235,7 @@ - (BOOL)paymentQueue:(SKPaymentQueue *)queue
return self.queue.transactions;
}

- (SKStorefront *)storefront {
- (SKStorefront *)storefront API_AVAILABLE(ios(13.0)) {
return self.queue.storefront;
}

Expand Down
Loading

0 comments on commit 02e71b0

Please sign in to comment.