Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 3477be2

Browse files
authored
[in_app_purchase] Initialize SKError with correct data type (#4113)
1 parent 24febdf commit 3477be2

File tree

4 files changed

+74
-6
lines changed

4 files changed

+74
-6
lines changed

packages/in_app_purchase/in_app_purchase_ios/CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.1.2+1
2+
3+
* Fix wrong data type when cancelling user credentials dialog.
4+
15
## 0.1.2
26

37
* Added countryCode to the SKPriceLocaleWrapper.
@@ -12,7 +16,7 @@
1216

1317
## 0.1.0+2
1418

15-
* Changed the iOS payment queue handler in such a way that it only adds a listener to the `SKPaymentQueue` when there
19+
* Changed the iOS payment queue handler in such a way that it only adds a listener to the `SKPaymentQueue` when there
1620
is a listener to the Dart `purchaseStream`.
1721

1822
## 0.1.0+1

packages/in_app_purchase/in_app_purchase_ios/lib/src/store_kit_wrappers/sk_payment_queue_wrapper.dart

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class SKPaymentQueueWrapper {
6666
/// addTransactionObserver:]`](https://developer.apple.com/documentation/storekit/skpaymentqueue/1506042-addtransactionobserver?language=objc).
6767
void setTransactionObserver(SKTransactionObserverWrapper observer) {
6868
_observer = observer;
69-
channel.setMethodCallHandler(_handleObserverCallbacks);
69+
channel.setMethodCallHandler(handleObserverCallbacks);
7070
}
7171

7272
/// Instructs the iOS implementation to register a transaction observer and
@@ -208,8 +208,12 @@ class SKPaymentQueueWrapper {
208208
.invokeMethod<void>('-[SKPaymentQueue showPriceConsentIfNeeded]');
209209
}
210210

211-
// Triage a method channel call from the platform and triggers the correct observer method.
212-
Future<dynamic> _handleObserverCallbacks(MethodCall call) async {
211+
/// Triage a method channel call from the platform and triggers the correct observer method.
212+
///
213+
/// This method is public for testing purposes only and should not be used
214+
/// outside this class.
215+
@visibleForTesting
216+
Future<dynamic> handleObserverCallbacks(MethodCall call) async {
213217
assert(_observer != null,
214218
'[in_app_purchase]: (Fatal)The observer has not been set but we received a purchase transaction notification. Please ensure the observer has been set using `setTransactionObserver`. Make sure the observer is added right at the App Launch.');
215219
final SKTransactionObserverWrapper observer = _observer!;
@@ -232,7 +236,8 @@ class SKPaymentQueueWrapper {
232236
}
233237
case 'restoreCompletedTransactionsFailed':
234238
{
235-
SKError error = SKError.fromJson(call.arguments);
239+
SKError error =
240+
SKError.fromJson(Map<String, dynamic>.from(call.arguments));
236241
return Future<void>(() {
237242
observer.restoreCompletedTransactionsFailed(error: error);
238243
});

packages/in_app_purchase/in_app_purchase_ios/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: in_app_purchase_ios
22
description: An implementation for the iOS platform of the Flutter `in_app_purchase` plugin. This uses the iOS StoreKit Framework.
33
repository: https://github.com/flutter/plugins/tree/master/packages/in_app_purchase/in_app_purchase_ios
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+in_app_purchase%22
5-
version: 0.1.2
5+
version: 0.1.2+1
66

77
environment:
88
sdk: ">=2.12.0 <3.0.0"

packages/in_app_purchase/in_app_purchase_ios/test/store_kit_wrappers/sk_payment_queue_delegate_api_test.dart

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,65 @@ void main() {
6868
},
6969
);
7070
});
71+
72+
test(
73+
'handleObserverCallbacks should call SKTransactionObserverWrapper.restoreCompletedTransactionsFailed',
74+
() async {
75+
SKPaymentQueueWrapper queue = SKPaymentQueueWrapper();
76+
TestTransactionObserverWrapper testObserver =
77+
TestTransactionObserverWrapper();
78+
queue.setTransactionObserver(testObserver);
79+
80+
final arguments = <dynamic, dynamic>{
81+
'code': 100,
82+
'domain': 'domain',
83+
'userInfo': <String, dynamic>{'error': 'underlying_error'},
84+
};
85+
86+
await queue.handleObserverCallbacks(
87+
MethodCall('restoreCompletedTransactionsFailed', arguments),
88+
);
89+
90+
expect(
91+
testObserver.log,
92+
<Matcher>{
93+
equals('restoreCompletedTransactionsFailed'),
94+
},
95+
);
96+
});
97+
}
98+
99+
class TestTransactionObserverWrapper extends SKTransactionObserverWrapper {
100+
final List<String> log = <String>[];
101+
102+
@override
103+
void updatedTransactions(
104+
{required List<SKPaymentTransactionWrapper> transactions}) {
105+
log.add('updatedTransactions');
106+
}
107+
108+
@override
109+
void removedTransactions(
110+
{required List<SKPaymentTransactionWrapper> transactions}) {
111+
log.add('removedTransactions');
112+
}
113+
114+
@override
115+
void restoreCompletedTransactionsFailed({required SKError error}) {
116+
log.add('restoreCompletedTransactionsFailed');
117+
}
118+
119+
@override
120+
void paymentQueueRestoreCompletedTransactionsFinished() {
121+
log.add('paymentQueueRestoreCompletedTransactionsFinished');
122+
}
123+
124+
@override
125+
bool shouldAddStorePayment(
126+
{required SKPaymentWrapper payment, required SKProductWrapper product}) {
127+
log.add('shouldAddStorePayment');
128+
return false;
129+
}
71130
}
72131

73132
class TestPaymentQueueDelegate extends SKPaymentQueueDelegateWrapper {

0 commit comments

Comments
 (0)