Skip to content
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

[in_app_purchase_storekit] Remove OCMock #6862

Merged
merged 56 commits into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
3f22950
init
LouiseHsu May 13, 2024
b3ae498
Merge remote-tracking branch 'upstream/main'
LouiseHsu May 15, 2024
750d5d6
wip
LouiseHsu May 29, 2024
60a1cfe
tests are passing
LouiseHsu Jun 4, 2024
07d1fa9
NOW tests are passing
LouiseHsu Jun 4, 2024
e055868
PaymentQueue tests
LouiseHsu Jun 4, 2024
27bc9dc
remove some incidental files
LouiseHsu Jun 4, 2024
86fe875
remove files 2
LouiseHsu Jun 4, 2024
f0440fa
.
LouiseHsu Jun 4, 2024
77821d0
.
LouiseHsu Jun 4, 2024
c4ba598
.
LouiseHsu Jun 4, 2024
4337a30
.
LouiseHsu Jun 5, 2024
3331f6b
Merge branch 'main' into remove-ocmock
LouiseHsu Jun 5, 2024
710f892
remove testing files
LouiseHsu Jun 5, 2024
dd54781
Merge branch 'remove-ocmock' of github.com:LouiseHsu/packages into re…
LouiseHsu Jun 5, 2024
a6f5c6b
formatting
LouiseHsu Jun 5, 2024
e8425f3
missing import for mac
LouiseHsu Jun 5, 2024
135e328
warnings
LouiseHsu Jun 5, 2024
3d43bb0
macos warnings
LouiseHsu Jun 5, 2024
eb6d45e
.
LouiseHsu Jun 5, 2024
04c733f
.
LouiseHsu Jun 5, 2024
0cb8821
remove ocmock from pods
LouiseHsu Jun 5, 2024
801d47f
clean up
LouiseHsu Jun 6, 2024
1fcbabd
.
LouiseHsu Jun 6, 2024
6911fc8
fix wonky symlinking in test files
LouiseHsu Jun 6, 2024
dc0a6d8
.
LouiseHsu Jun 6, 2024
714b3a1
license block 🤡
LouiseHsu Jun 6, 2024
4cd2042
Merge branch 'main' into remove-ocmock
LouiseHsu Jun 6, 2024
0044139
split up protocols, moved test implementations out of actual implemen…
LouiseHsu Jun 7, 2024
98e8058
Merge branch 'remove-ocmock' of github.com:LouiseHsu/packages into re…
LouiseHsu Jun 7, 2024
3bac1cb
adding missing stubs to methods
LouiseHsu Jun 7, 2024
1e02304
comments
LouiseHsu Jun 7, 2024
db34eb5
more comments
LouiseHsu Jun 7, 2024
f1f66e6
pr comments
LouiseHsu Jun 10, 2024
53a552e
properties, attributes
LouiseHsu Jun 10, 2024
3b19418
pr comments, renaming, format
LouiseHsu Jun 10, 2024
320d2d4
bunch of renaming, pr comments
LouiseHsu Jun 12, 2024
35202db
add comments, moved properties into class extensions
LouiseHsu Jun 13, 2024
074c303
more comments
LouiseHsu Jun 13, 2024
6eaed90
license, more comments
LouiseHsu Jun 13, 2024
147133c
boop pr comments
LouiseHsu Jun 14, 2024
0c06698
boop
LouiseHsu Jun 14, 2024
09719c9
renaming
LouiseHsu Jun 14, 2024
49d06b4
.
LouiseHsu Jun 17, 2024
f55e7a4
failing mac test
LouiseHsu Jun 17, 2024
2ae019f
so much renaming
LouiseHsu Jun 17, 2024
15b0b04
stubs and ///
LouiseHsu Jun 17, 2024
7a0cab6
properties
LouiseHsu Jun 17, 2024
cf656ec
format
LouiseHsu Jun 18, 2024
3e95cdc
format
LouiseHsu Jun 18, 2024
7a54cf9
.
LouiseHsu Jun 21, 2024
dc5499e
oopsies mac version
LouiseHsu Jun 21, 2024
ebd6bf1
remove extra symlnked files
LouiseHsu Jun 21, 2024
bb41e93
.
LouiseHsu Jun 21, 2024
d3f2479
.
LouiseHsu Jun 21, 2024
aed5b28
.
LouiseHsu Jun 21, 2024
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,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