Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 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,7 @@
## 0.3.13

* Added new native tests for more complete test coverage.

## 0.3.12

* Converts `refreshReceipt()`, `startObservingPaymentQueue()`, `stopObservingPaymentQueue()`,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// 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.

#import <StoreKit/StoreKit.h>
#import "FIAPRequestHandler.h"
#import "InAppPurchasePlugin.h"

@interface InAppPurchasePlugin ()

// Holding strong references to FIAPRequestHandlers. Remove the handlers from the set after
// the request is finished.
@property(strong, nonatomic, readonly) NSMutableSet *requestHandlers;

// Callback channel to dart used for when a function from the transaction observer is triggered.
@property(strong, nonatomic) FlutterMethodChannel *transactionObserverCallbackChannel;

// Callback channel to dart used for when a function from the transaction observer is triggered.
@property(strong, nonatomic) FIAPRequestHandler * (^handlerFactory)(SKRequest *);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@property(strong, nonatomic) FIAPRequestHandler * (^handlerFactory)(SKRequest *);
@property(copy, nonatomic) FIAPRequestHandler * (^handlerFactory)(SKRequest *);

You want to use copy for blocks properties since that will force any resources on the stack to be copied to the heap ( https://stackoverflow.com/questions/4081831/how-to-store-blocks-in-properties-in-objective-c#comment11631504_4081903 )


// Convenience nitializer with dependancy injection
Comment thread
LouiseHsu marked this conversation as resolved.
Outdated
- (instancetype)initWithReceiptManager:(FIAPReceiptManager *)receiptManager
handlerFactory:(FIAPRequestHandler * (^)(SKRequest *))handlerFactory;

// Transaction observer methods
- (void)handleTransactionsUpdated:(NSArray<SKPaymentTransaction *> *)transactions;
- (void)handleTransactionsRemoved:(NSArray<SKPaymentTransaction *> *)transactions;
- (void)handleTransactionRestoreFailed:(NSError *)error;
- (void)restoreCompletedTransactionsFinished;
- (BOOL)shouldAddStorePayment:(SKPayment *)payment product:(SKProduct *)product;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,14 @@
#import "FIAPReceiptManager.h"
#import "FIAPRequestHandler.h"
#import "FIAPaymentQueueHandler.h"
#import "InAppPurchasePlugin+TestOnly.h"

@interface InAppPurchasePlugin ()

// Holding strong references to FIAPRequestHandlers. Remove the handlers from the set after
// the request is finished.
@property(strong, nonatomic, readonly) NSMutableSet *requestHandlers;

// After querying the product, the available products will be saved in the map to be used
// for purchase.
@property(strong, nonatomic, readonly) NSMutableDictionary *productsCache;

// Callback channel to dart used for when a function from the transaction observer is triggered.
@property(strong, nonatomic, readonly) FlutterMethodChannel *transactionObserverCallbackChannel;

// Callback channel to dart used for when a function from the payment queue delegate is triggered.
@property(strong, nonatomic, readonly) FlutterMethodChannel *paymentQueueDelegateCallbackChannel;
@property(strong, nonatomic, readonly) NSObject<FlutterPluginRegistrar> *registrar;
Expand Down Expand Up @@ -52,6 +46,16 @@ - (instancetype)initWithReceiptManager:(FIAPReceiptManager *)receiptManager {
_receiptManager = receiptManager;
_requestHandlers = [NSMutableSet new];
_productsCache = [NSMutableDictionary new];
_handlerFactory = ^FIAPRequestHandler *(SKRequest *request) {
return [[FIAPRequestHandler alloc] initWithRequest:request];
};
return self;
}

- (instancetype)initWithReceiptManager:(FIAPReceiptManager *)receiptManager
handlerFactory:(FIAPRequestHandler * (^)(SKRequest *))handlerFactory {
self = [self initWithReceiptManager:receiptManager];
_handlerFactory = handlerFactory;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_handlerFactory = handlerFactory;
_handlerFactory = [handlerFactory copy];

For the same reason mentioned above.

return self;
}

Expand Down Expand Up @@ -117,7 +121,7 @@ - (void)startProductRequestProductIdentifiers:(NSArray<NSString *> *)productIden
FlutterError *_Nullable))completion {
SKProductsRequest *request =
[self getProductRequestWithIdentifiers:[NSSet setWithArray:productIdentifiers]];
FIAPRequestHandler *handler = [[FIAPRequestHandler alloc] initWithRequest:request];
FIAPRequestHandler *handler = self.handlerFactory(request);
[self.requestHandlers addObject:handler];
__weak typeof(self) weakSelf = self;

Expand Down Expand Up @@ -282,6 +286,7 @@ - (void)refreshReceiptReceiptProperties:(nullable NSDictionary *)receiptProperti
message:error.localizedDescription
details:error.description];
completion(requestError);
return;
}
completion(nil);
[weakSelf.requestHandlers removeObject:handler];
Expand Down
Loading