handleObserverCallbacks method

  1. @visibleForTesting
Future handleObserverCallbacks(
  1. MethodCall call
)

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);
        return Future<void>(() {
          observer.updatedTransactions(transactions: transactions);
        });
      }
    case 'removedTransactions':
      {
        final List<SKPaymentTransactionWrapper> transactions =
            _getTransactionList(call.arguments);
        return Future<void>(() {
          observer.removedTransactions(transactions: transactions);
        });
      }
    case 'restoreCompletedTransactionsFailed':
      {
        SKError error =
            SKError.fromJson(Map<String, dynamic>.from(call.arguments));
        return Future<void>(() {
          observer.restoreCompletedTransactionsFailed(error: error);
        });
      }
    case 'paymentQueueRestoreCompletedTransactionsFinished':
      {
        return Future<void>(() {
          observer.paymentQueueRestoreCompletedTransactionsFinished();
        });
      }
    case 'shouldAddStorePayment':
      {
        SKPaymentWrapper payment =
            SKPaymentWrapper.fromJson(call.arguments['payment']);
        SKProductWrapper product =
            SKProductWrapper.fromJson(call.arguments['product']);
        return Future<void>(() {
          if (observer.shouldAddStorePayment(
                  payment: payment, product: product) ==
              true) {
            SKPaymentQueueWrapper().addPayment(payment);
          }
        });
      }
    default:
      break;
  }
  throw PlatformException(
      code: 'no_such_callback',
      message: 'Did not recognize the observer callback ${call.method}.');
}