handleObserverCallbacks method
Triage a method channel call from the platform and triggers the correct observer method.
This method is public for testing purposes only and should not be used outside this class.
Implementation
@visibleForTesting
Future<dynamic> handleObserverCallbacks(MethodCall call) async {
assert(_observer != null,
'[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.');
final SKTransactionObserverWrapper observer = _observer!;
switch (call.method) {
case 'updatedTransactions':
{
final List<SKPaymentTransactionWrapper> transactions =
_getTransactionList(call.arguments as List<dynamic>);
return Future<void>(() {
observer.updatedTransactions(transactions: transactions);
});
}
case 'removedTransactions':
{
final List<SKPaymentTransactionWrapper> transactions =
_getTransactionList(call.arguments as List<dynamic>);
return Future<void>(() {
observer.removedTransactions(transactions: transactions);
});
}
case 'restoreCompletedTransactionsFailed':
{
final SKError error = SKError.fromJson(Map<String, dynamic>.from(
call.arguments as Map<dynamic, dynamic>));
return Future<void>(() {
observer.restoreCompletedTransactionsFailed(error: error);
});
}
case 'paymentQueueRestoreCompletedTransactionsFinished':
{
return Future<void>(() {
observer.paymentQueueRestoreCompletedTransactionsFinished();
});
}
case 'shouldAddStorePayment':
{
final Map<Object?, Object?> arguments =
call.arguments as Map<Object?, Object?>;
final SKPaymentWrapper payment = SKPaymentWrapper.fromJson(
(arguments['payment']! as Map<dynamic, dynamic>)
.cast<String, dynamic>());
final SKProductWrapper product = SKProductWrapper.fromJson(
(arguments['product']! as Map<dynamic, dynamic>)
.cast<String, dynamic>());
return Future<void>(() {
if (observer.shouldAddStorePayment(
payment: payment, product: product)) {
SKPaymentQueueWrapper().addPayment(payment);
}
});
}
default:
break;
}
throw PlatformException(
code: 'no_such_callback',
message: 'Did not recognize the observer callback ${call.method}.');
}