Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Closed
3 changes: 3 additions & 0 deletions packages/in_app_purchase/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 0.3.4+2

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

new line after the version

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The diff seems odd, CHANGELOG probably needs to be re-based

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

## 0.3.4+1

* iOS: Fix the bug that `SKPaymentQueueWrapper.transactions` doesn't return all transactions.
Expand Down
15 changes: 9 additions & 6 deletions packages/in_app_purchase/ios/Classes/FIAPReceiptManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,21 @@ @implementation FIAPReceiptManager

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

- (NSData *)getReceiptData:(NSURL *)url {
return [NSData dataWithContentsOfURL:url];
- (NSData *)getReceiptData:(NSURL *)url error:(NSError **)error {
return [NSData dataWithContentsOfURL:url options:NSDataReadingMappedIfSafe error:error];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ class SKReceiptManager {
/// There are 2 ways to do so. Either validate locally or validate with App Store.
/// For more details on how to validate the receipt data, you can refer to Apple's document about [`About Receipt Validation`](https://developer.apple.com/library/archive/releasenotes/General/ValidateAppStoreReceipt/Introduction.html#//apple_ref/doc/uid/TP40010573-CH105-SW1).
/// If the receipt is invalid or missing, you can use [SKRequestMaker.startRefreshReceiptRequest] to request a new receipt.
static Future<String> retrieveReceiptData() {
return channel.invokeMethod<String>(
'-[InAppPurchasePlugin retrieveReceiptData:result:]');
static Future<String> retrieveReceiptData() async {
Comment thread
mklim marked this conversation as resolved.
try {
return await channel.invokeMethod<String>(
'-[InAppPurchasePlugin retrieveReceiptData:result:]');
} catch (_) {
rethrow;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why the catch and rethrow here? I think this behaves identically to how just returning the await would, since it's rethrowing everything.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reverted.

}
}
2 changes: 1 addition & 1 deletion packages/in_app_purchase/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: in_app_purchase
description: A Flutter plugin for in-app purchases. Exposes APIs for making in-app purchases through the App Store and Google Play.
homepage: https://github.com/flutter/plugins/tree/master/packages/in_app_purchase
version: 0.3.4+1
version: 0.3.4+2

dependencies:
async: ^2.0.8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:in_app_purchase/src/channel.dart';
import 'package:in_app_purchase/store_kit_wrappers.dart';
import 'package:test/test.dart' show TypeMatcher;
import 'sk_test_stub_objects.dart';

void main() {
Expand Down Expand Up @@ -76,6 +77,12 @@ void main() {
String receiptData = await SKReceiptManager.retrieveReceiptData();
expect(receiptData, 'receipt data');
});

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

group('sk_payment_queue', () {
Expand Down Expand Up @@ -128,11 +135,15 @@ class FakeIOSPlatform {
FakeIOSPlatform() {
channel.setMockMethodCallHandler(onMethodCall);
getProductRequestFailTest = false;
getReceiptFailTest = false;
}
// get product request
List startProductRequestParam;
bool getProductRequestFailTest;

// get receipt request
bool getReceiptFailTest;

// refresh receipt request
int refreshReceipt = 0;
Map refreshReceiptParam;
Expand Down Expand Up @@ -161,6 +172,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