verifyOtp method

Verifies an OTP challenge and updates the authoritative session.

Implementation

@override
Future<InappifySdkResult<InappifyAuthenticationResult>> verifyOtp(
  InappifyOtpVerificationRequest request,
) async {
  final cancelled = _preCancelled<InappifyAuthenticationResult>(
    'verifyOtp',
    request.cancellation,
  );
  if (cancelled != null) return cancelled;
  return _run<InappifyAuthenticationResult>(
    'verifyOtp',
    action: () async {
      final previousCustomer = _customerInfo;
      final previousOfferings = _offerings;
      final raw = await _callSessionMutation(
        method: 'verifyOtp',
        positionalArguments: <Object?>[
          request.challengeId,
          request.code,
          if (request.cancellation != null) const <String, Object?>{},
        ],
        cancellation: request.cancellation,
        injectAbortSignal: request.cancellation != null,
        previousCustomer: previousCustomer,
        previousOfferings: previousOfferings,
      );
      _clearUnchangedSessionMirrors(previousCustomer, previousOfferings);
      final result = InappifyWebPayloadCodec.authentication(raw);
      _bridge.clearPendingCheckout();
      await _refreshCachedStateBestEffort(includeOfferings: true);
      return result;
    },
    cancellation: request.cancellation,
    mutationMayHaveCommitted: true,
  );
}