Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions packages/in_app_purchase/in_app_purchase_ios/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.1.0+3

* iOS: Fix treating missing App Store receipt as an exception.

## 0.1.0+2

* Changed the iOS payment queue handler in such a way that it only adds a listener to the SKPaymentQueue when there
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ - (instancetype)initWithMap:(NSDictionary *)map {

@implementation FIAPReceiptManagerStub : FIAPReceiptManager

- (NSData *)getReceiptData:(NSURL *)url {
- (NSData *)getReceiptData:(NSURL *)url error:(NSError **)error {
NSString *originalString = [NSString stringWithFormat:@"test"];
return [[NSData alloc] initWithBase64EncodedString:originalString options:kNilOptions];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,22 @@ @implementation FIAPReceiptManager

- (NSString *)retrieveReceiptWithError:(FlutterError **)error {
NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL];
NSData *receipt = [self getReceiptData:receiptURL];
NSError *err;
Comment thread
renefloor marked this conversation as resolved.
Outdated
NSData *receipt = [self getReceiptData:receiptURL error:&err];
if (err) {
Comment thread
renefloor marked this conversation as resolved.
Outdated
*error = [FlutterError errorWithCode:[[NSString alloc] initWithFormat:@"%li", (long)err.code]
Comment thread
renefloor marked this conversation as resolved.
Outdated
message:err.domain
details:err.userInfo];
return nil;
}
if (!receipt) {
*error = [FlutterError errorWithCode:@"storekit_no_receipt"
message:@"Cannot find receipt for the current main bundle."
details:nil];
Comment thread
renefloor marked this conversation as resolved.
return nil;
}
return [receipt base64EncodedStringWithOptions:kNilOptions];
}

- (NSData *)getReceiptData:(NSURL *)url {
return [NSData dataWithContentsOfURL:url];
- (NSData *)getReceiptData:(NSURL *)url error:(NSError **)error {
Comment thread
renefloor marked this conversation as resolved.
return [NSData dataWithContentsOfURL:url options:NSDataReadingMappedIfSafe error:error];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@ class InAppPurchaseIosPlatformAddition extends InAppPurchasePlatformAddition {
/// If no results, a `null` value is returned.
Future<PurchaseVerificationData?> refreshPurchaseVerificationData() async {
await SKRequestMaker().startRefreshReceiptRequest();
final String? receipt = await SKReceiptManager.retrieveReceiptData();
if (receipt == null) {
try {
String receipt = await SKReceiptManager.retrieveReceiptData();
return PurchaseVerificationData(
localVerificationData: receipt,
serverVerificationData: receipt,
source: kIAPSource);
} catch (e) {
print(
'Something is wrong while fetching the receipt, this normally happens when the app is '
'running on a simulator: $e');
return null;
}
return PurchaseVerificationData(
localVerificationData: receipt,
serverVerificationData: receipt,
source: kIAPSource);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ void main() {
expect(fakeIOSPlatform.refreshReceiptParam,
<String, dynamic>{"isExpired": true});
});

test('should get null receipt if any exceptions are raised', () async {
fakeIOSPlatform.getReceiptFailTest = true;
expect(() async => SKReceiptManager.retrieveReceiptData(),
throwsA(TypeMatcher<PlatformException>()));
});
});

group('sk_receipt_manager', () {
Expand Down Expand Up @@ -166,6 +172,9 @@ class FakeIOSPlatform {
bool getProductRequestFailTest = false;
bool testReturnNull = false;

// get receipt request
bool getReceiptFailTest = false;

// refresh receipt request
int refreshReceipt = 0;
late Map<String, dynamic> refreshReceiptParam;
Expand Down Expand Up @@ -201,6 +210,9 @@ class FakeIOSPlatform {
return Future<void>.sync(() {});
// receipt manager
case '-[InAppPurchasePlugin retrieveReceiptData:result:]':
if (getReceiptFailTest) {
throw ("some arbitrary error");
}
return Future<String>.value('receipt data');
// payment queue
case '-[SKPaymentQueue canMakePayments:]':
Expand Down