withdrawCredits method

Future<UserWithdrawCreditsResponseData> withdrawCredits({
  1. required String key,
  2. required int amount,
  3. String? operationId,
})

Withdraws amount credits of the reward identified by key.

operationId makes the withdrawal idempotent.

Implementation

Future<UserWithdrawCreditsResponseData> withdrawCredits({
  required String key,
  required int amount,
  String? operationId,
}) async {
  final request = UserWithdrawCreditsRequest((b) => b
    ..key = key
    ..amount = amount
    ..operationId = operationId);
  final response = await _sdk._rewardsActions.withdrawCredits(
    appUserId: appUserId,
    xApiKey: _sdk.apiKey,
    userWithdrawCreditsRequest: request,
  );
  final body = response.data ??
      (throw StateError(
        'withdrawCredits: response body was empty for user $appUserId '
        'and reward key $key.',
      ));
  return body.data;
}