Skip to content

Commit 02e71b0

Browse files
authored
[in_app_purchase_storekit] Remove OCMock (#6862)
Fixes flutter/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
1 parent 04d2572 commit 02e71b0

32 files changed

+1617
-617
lines changed

packages/in_app_purchase/in_app_purchase_storekit/CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
## 0.3.17
2+
3+
* Removes OCMock from tests.
4+
15
## 0.3.16
26

3-
* Converts main plugin class to Swift
7+
* Converts main plugin class to Swift.
48

59
## 0.3.15
610

packages/in_app_purchase/in_app_purchase_storekit/darwin/Classes/FIAPPaymentQueueDelegate.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@
99
#endif
1010
#import <Foundation/Foundation.h>
1111
#import <StoreKit/StoreKit.h>
12+
#import "FLTMethodChannelProtocol.h"
1213

1314
NS_ASSUME_NONNULL_BEGIN
1415

1516
API_AVAILABLE(ios(13))
1617
API_UNAVAILABLE(tvos, macos, watchos)
1718
@interface FIAPPaymentQueueDelegate : NSObject <SKPaymentQueueDelegate>
18-
- (id)initWithMethodChannel:(FlutterMethodChannel *)methodChannel;
19+
- (id)initWithMethodChannel:(id<FLTMethodChannelProtocol>)methodChannel;
1920
@end
2021

2122
NS_ASSUME_NONNULL_END

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77

88
@interface FIAPPaymentQueueDelegate ()
99

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

1213
@end
1314

1415
@implementation FIAPPaymentQueueDelegate
1516

16-
- (id)initWithMethodChannel:(FlutterMethodChannel *)methodChannel {
17+
- (id)initWithMethodChannel:(id<FLTMethodChannelProtocol>)methodChannel {
1718
self = [super init];
1819
if (self) {
1920
_callbackChannel = methodChannel;

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ @interface FIAPReceiptManager ()
1414
// Gets the receipt file data from the location of the url. Can be nil if
1515
// there is an error. This interface is defined so it can be stubbed for testing.
1616
- (NSData *)getReceiptData:(NSURL *)url error:(NSError **)error;
17-
17+
// Gets the app store receipt url. Can be nil if
18+
// there is an error. This property is defined so it can be stubbed for testing.
19+
@property(nonatomic, readonly) NSURL *receiptURL;
1820
@end
1921

2022
@implementation FIAPReceiptManager
2123

2224
- (NSString *)retrieveReceiptWithError:(FlutterError **)flutterError {
23-
NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL];
25+
NSURL *receiptURL = self.receiptURL;
2426
if (!receiptURL) {
2527
return nil;
2628
}
@@ -43,4 +45,8 @@ - (NSData *)getReceiptData:(NSURL *)url error:(NSError **)error {
4345
return [NSData dataWithContentsOfURL:url options:NSDataReadingMappedIfSafe error:error];
4446
}
4547

48+
- (NSURL *)receiptURL {
49+
return [[NSBundle mainBundle] appStoreReceiptURL];
50+
}
51+
4652
@end

packages/in_app_purchase/in_app_purchase_storekit/darwin/Classes/FIAPRequestHandler.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,23 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
#import <FLTRequestHandlerProtocol.h>
56
#import <Foundation/Foundation.h>
67
#import <StoreKit/StoreKit.h>
78

89
NS_ASSUME_NONNULL_BEGIN
910

10-
typedef void (^ProductRequestCompletion)(SKProductsResponse *_Nullable response,
11-
NSError *_Nullable errror);
12-
13-
@interface FIAPRequestHandler : NSObject
11+
@interface FIAPRequestHandler : NSObject <FLTRequestHandlerProtocol>
1412

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

1816
@end
1917

18+
// The default request handler that wraps FIAPRequestHandler
19+
@interface DefaultRequestHandler : NSObject <FLTRequestHandlerProtocol>
20+
21+
// Initialize this wrapper with an instance of FIAPRequestHandler
22+
- (instancetype)initWithRequestHandler:(FIAPRequestHandler *)handler;
23+
@end
2024
NS_ASSUME_NONNULL_END

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
@interface FIAPRequestHandler () <SKProductsRequestDelegate>
1111

12-
@property(copy, nonatomic) ProductRequestCompletion completion;
13-
@property(strong, nonatomic) SKRequest *request;
12+
@property(nonatomic, copy) ProductRequestCompletion completion;
13+
@property(nonatomic, strong) SKRequest *request;
1414

1515
@end
1616

packages/in_app_purchase/in_app_purchase_storekit/darwin/Classes/FIAPaymentQueueHandler.h

Lines changed: 5 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -5,130 +5,16 @@
55
#import <Foundation/Foundation.h>
66
#import <StoreKit/StoreKit.h>
77
#import "FIATransactionCache.h"
8+
#import "FLTPaymentQueueHandlerProtocol.h"
9+
#import "FLTPaymentQueueProtocol.h"
10+
#import "FLTTransactionCacheProtocol.h"
811

912
@class SKPaymentTransaction;
1013

1114
NS_ASSUME_NONNULL_BEGIN
1215

13-
typedef void (^TransactionsUpdated)(NSArray<SKPaymentTransaction *> *transactions);
14-
typedef void (^TransactionsRemoved)(NSArray<SKPaymentTransaction *> *transactions);
15-
typedef void (^RestoreTransactionFailed)(NSError *error);
16-
typedef void (^RestoreCompletedTransactionsFinished)(void);
17-
typedef BOOL (^ShouldAddStorePayment)(SKPayment *payment, SKProduct *product);
18-
typedef void (^UpdatedDownloads)(NSArray<SKDownload *> *downloads);
19-
20-
@interface FIAPaymentQueueHandler : NSObject <SKPaymentTransactionObserver>
21-
22-
@property(NS_NONATOMIC_IOSONLY, weak, nullable) id<SKPaymentQueueDelegate> delegate API_AVAILABLE(
23-
ios(13.0), macos(10.15), watchos(6.2));
24-
@property(nonatomic, readonly, nullable)
25-
SKStorefront *storefront API_AVAILABLE(ios(13.0), macos(10.15), watchos(6.2));
26-
27-
/// Creates a new FIAPaymentQueueHandler initialized with an empty
28-
/// FIATransactionCache.
29-
///
30-
/// @param queue The SKPaymentQueue instance connected to the App Store and
31-
/// responsible for processing transactions.
32-
/// @param transactionsUpdated Callback method that is called each time the App
33-
/// Store indicates transactions are updated.
34-
/// @param transactionsRemoved Callback method that is called each time the App
35-
/// Store indicates transactions are removed.
36-
/// @param restoreTransactionFailed Callback method that is called each time
37-
/// the App Store indicates transactions failed
38-
/// to restore.
39-
/// @param restoreCompletedTransactionsFinished Callback method that is called
40-
/// each time the App Store
41-
/// indicates restoring of
42-
/// transactions has finished.
43-
/// @param shouldAddStorePayment Callback method that is called each time an
44-
/// in-app purchase has been initiated from the
45-
/// App Store.
46-
/// @param updatedDownloads Callback method that is called each time the App
47-
/// Store indicates downloads are updated.
48-
- (instancetype)initWithQueue:(nonnull SKPaymentQueue *)queue
49-
transactionsUpdated:(nullable TransactionsUpdated)transactionsUpdated
50-
transactionRemoved:(nullable TransactionsRemoved)transactionsRemoved
51-
restoreTransactionFailed:(nullable RestoreTransactionFailed)restoreTransactionFailed
52-
restoreCompletedTransactionsFinished:
53-
(nullable RestoreCompletedTransactionsFinished)restoreCompletedTransactionsFinished
54-
shouldAddStorePayment:(nullable ShouldAddStorePayment)shouldAddStorePayment
55-
updatedDownloads:(nullable UpdatedDownloads)updatedDownloads
56-
DEPRECATED_MSG_ATTRIBUTE(
57-
"Use the "
58-
"'initWithQueue:transactionsUpdated:transactionsRemoved:restoreTransactionsFinished:"
59-
"shouldAddStorePayment:updatedDownloads:transactionCache:' message instead.");
60-
61-
/// Creates a new FIAPaymentQueueHandler.
62-
///
63-
/// The "transactionsUpdated", "transactionsRemoved" and "updatedDownloads"
64-
/// callbacks are only called while actively observing transactions. To start
65-
/// observing transactions send the "startObservingPaymentQueue" message.
66-
/// Sending the "stopObservingPaymentQueue" message will stop actively
67-
/// observing transactions. When transactions are not observed they are cached
68-
/// to the "transactionCache" and will be delivered via the
69-
/// "transactionsUpdated", "transactionsRemoved" and "updatedDownloads"
70-
/// callbacks as soon as the "startObservingPaymentQueue" message arrives.
71-
///
72-
/// Note: cached transactions that are not processed when the application is
73-
/// killed will be delivered again by the App Store as soon as the application
74-
/// starts again.
75-
///
76-
/// @param queue The SKPaymentQueue instance connected to the App Store and
77-
/// responsible for processing transactions.
78-
/// @param transactionsUpdated Callback method that is called each time the App
79-
/// Store indicates transactions are updated.
80-
/// @param transactionsRemoved Callback method that is called each time the App
81-
/// Store indicates transactions are removed.
82-
/// @param restoreTransactionFailed Callback method that is called each time
83-
/// the App Store indicates transactions failed
84-
/// to restore.
85-
/// @param restoreCompletedTransactionsFinished Callback method that is called
86-
/// each time the App Store
87-
/// indicates restoring of
88-
/// transactions has finished.
89-
/// @param shouldAddStorePayment Callback method that is called each time an
90-
/// in-app purchase has been initiated from the
91-
/// App Store.
92-
/// @param updatedDownloads Callback method that is called each time the App
93-
/// Store indicates downloads are updated.
94-
/// @param transactionCache An empty [FIATransactionCache] instance that is
95-
/// responsible for keeping track of transactions that
96-
/// arrive when not actively observing transactions.
97-
- (instancetype)initWithQueue:(nonnull SKPaymentQueue *)queue
98-
transactionsUpdated:(nullable TransactionsUpdated)transactionsUpdated
99-
transactionRemoved:(nullable TransactionsRemoved)transactionsRemoved
100-
restoreTransactionFailed:(nullable RestoreTransactionFailed)restoreTransactionFailed
101-
restoreCompletedTransactionsFinished:
102-
(nullable RestoreCompletedTransactionsFinished)restoreCompletedTransactionsFinished
103-
shouldAddStorePayment:(nullable ShouldAddStorePayment)shouldAddStorePayment
104-
updatedDownloads:(nullable UpdatedDownloads)updatedDownloads
105-
transactionCache:(nonnull FIATransactionCache *)transactionCache;
106-
// Can throw exceptions if the transaction type is purchasing, should always used in a @try block.
107-
- (void)finishTransaction:(nonnull SKPaymentTransaction *)transaction;
108-
- (void)restoreTransactions:(nullable NSString *)applicationName;
109-
- (void)presentCodeRedemptionSheet API_UNAVAILABLE(tvos, macos, watchos);
110-
- (NSArray<SKPaymentTransaction *> *)getUnfinishedTransactions;
111-
112-
// This method needs to be called before any other methods.
113-
- (void)startObservingPaymentQueue;
114-
// Call this method when the Flutter app is no longer listening
115-
- (void)stopObservingPaymentQueue;
116-
117-
// Appends a payment to the SKPaymentQueue.
118-
//
119-
// @param payment Payment object to be added to the payment queue.
120-
// @return whether "addPayment" was successful.
121-
- (BOOL)addPayment:(SKPayment *)payment;
122-
123-
// Displays the price consent sheet.
124-
//
125-
// The price consent sheet is only displayed when the following
126-
// is true:
127-
// - You have increased the price of the subscription in App Store Connect.
128-
// - The subscriber has not yet responded to a price consent query.
129-
// Otherwise the method has no effect.
130-
- (void)showPriceConsentIfNeeded API_AVAILABLE(ios(13.4))API_UNAVAILABLE(tvos, macos, watchos);
131-
16+
@interface FIAPaymentQueueHandler
17+
: NSObject <SKPaymentTransactionObserver, FLTPaymentQueueHandlerProtocol>
13218
@end
13319

13420
NS_ASSUME_NONNULL_END

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

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,34 @@ @interface FIAPaymentQueueHandler ()
1010

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

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

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

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

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

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

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

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

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

5252
@implementation FIAPaymentQueueHandler
5353

54-
- (instancetype)initWithQueue:(nonnull SKPaymentQueue *)queue
54+
@synthesize delegate;
55+
56+
- (instancetype)initWithQueue:(nonnull id<FLTPaymentQueueProtocol>)queue
5557
transactionsUpdated:(nullable TransactionsUpdated)transactionsUpdated
5658
transactionRemoved:(nullable TransactionsRemoved)transactionsRemoved
5759
restoreTransactionFailed:(nullable RestoreTransactionFailed)restoreTransactionFailed
@@ -66,18 +68,18 @@ - (instancetype)initWithQueue:(nonnull SKPaymentQueue *)queue
6668
restoreCompletedTransactionsFinished:restoreCompletedTransactionsFinished
6769
shouldAddStorePayment:shouldAddStorePayment
6870
updatedDownloads:updatedDownloads
69-
transactionCache:[[FIATransactionCache alloc] init]];
71+
transactionCache:[[DefaultTransactionCache alloc] init]];
7072
}
7173

72-
- (instancetype)initWithQueue:(nonnull SKPaymentQueue *)queue
74+
- (instancetype)initWithQueue:(nonnull id<FLTPaymentQueueProtocol>)queue
7375
transactionsUpdated:(nullable TransactionsUpdated)transactionsUpdated
7476
transactionRemoved:(nullable TransactionsRemoved)transactionsRemoved
7577
restoreTransactionFailed:(nullable RestoreTransactionFailed)restoreTransactionFailed
7678
restoreCompletedTransactionsFinished:
7779
(nullable RestoreCompletedTransactionsFinished)restoreCompletedTransactionsFinished
7880
shouldAddStorePayment:(nullable ShouldAddStorePayment)shouldAddStorePayment
7981
updatedDownloads:(nullable UpdatedDownloads)updatedDownloads
80-
transactionCache:(nonnull FIATransactionCache *)transactionCache {
82+
transactionCache:(nonnull id<FLTTransactionCacheProtocol>)transactionCache {
8183
self = [super init];
8284
if (self) {
8385
_queue = queue;
@@ -170,7 +172,7 @@ - (void)presentCodeRedemptionSheet {
170172
#endif
171173

172174
#if TARGET_OS_IOS
173-
- (void)showPriceConsentIfNeeded {
175+
- (void)showPriceConsentIfNeeded API_AVAILABLE(ios(13.4)) {
174176
[self.queue showPriceConsentIfNeeded];
175177
}
176178
#endif
@@ -233,7 +235,7 @@ - (BOOL)paymentQueue:(SKPaymentQueue *)queue
233235
return self.queue.transactions;
234236
}
235237

236-
- (SKStorefront *)storefront {
238+
- (SKStorefront *)storefront API_AVAILABLE(ios(13.0)) {
237239
return self.queue.storefront;
238240
}
239241

0 commit comments

Comments
 (0)