Example #1
0
        public async Task <IActionResult> FetchChallengesAsync(
            EnumGame game            = EnumGame.None,
            EnumChallengeState state = EnumChallengeState.None,
            bool includeMatches      = false
            )
        {
            var fetchDoxatagsRequest = new FetchDoxatagsRequest();

            var fetchDoxatagsResponse = await _identityServiceClient.FetchDoxatagsAsync(fetchDoxatagsRequest);

            var fetchChallengePayoutsRequest = new FetchChallengePayoutsRequest();

            var fetchChallengePayoutsResponse = await _cashierServiceClient.FetchChallengePayoutsAsync(fetchChallengePayoutsRequest);

            var fetchChallengesRequest = new FetchChallengesRequest
            {
                Game           = game,
                State          = state,
                IncludeMatches = includeMatches
            };

            var fetchChallengesResponse = await _challengesServiceClient.FetchChallengesAsync(fetchChallengesRequest);

            return(this.Ok(ChallengeMapper.Map(fetchChallengesResponse.Challenges, fetchChallengePayoutsResponse.Payouts, fetchDoxatagsResponse.Doxatags)));
        }
Example #2
0
        public async Task <IActionResult> RegisterChallengeParticipantAsync(string challengeId)
        {
            var participantId = new ParticipantId();

            var findChallengeRequest = new FindChallengeRequest
            {
                ChallengeId = challengeId
            };

            var findChallengeResponse = await _challengesServiceClient.FindChallengeAsync(findChallengeRequest);

            var findPlayerGameCredentialRequest = new FindPlayerGameCredentialRequest
            {
                Game = findChallengeResponse.Challenge.Game
            };

            var findPlayerGameCredentialResponse = await _gameServiceClient.FindPlayerGameCredentialAsync(findPlayerGameCredentialRequest);

            var fetchDoxatagsRequest = new FetchDoxatagsRequest();

            var fetchDoxatagsResponse = await _identityServiceClient.FetchDoxatagsAsync(fetchDoxatagsRequest);

            var findChallengePayoutRequest = new FindChallengePayoutRequest
            {
                ChallengeId = challengeId
            };

            var challengePayoutResponse = await _cashierServiceClient.FindChallengePayoutAsync(findChallengePayoutRequest);

            var createTransactionRequest = new CreateTransactionRequest
            {
                Custom = new CustomTransaction
                {
                    Type     = EnumTransactionType.Charge,
                    Currency = challengePayoutResponse.Payout.EntryFee
                },
                Metadata =
                {
                    new Dictionary <string, string>
                    {
                        [nameof(ChallengeId)]   = challengeId,
                        [nameof(ParticipantId)] = participantId
                    }
                }
            };

            var createTransactionResponse = await _cashierServiceClient.CreateTransactionAsync(createTransactionRequest);

            try
            {
                var registerChallengeParticipantRequest = new RegisterChallengeParticipantRequest
                {
                    ChallengeId   = challengeId,
                    GamePlayerId  = findPlayerGameCredentialResponse.Credential.PlayerId,
                    ParticipantId = participantId
                };

                var participant = await _challengesServiceClient.RegisterChallengeParticipantAsync(registerChallengeParticipantRequest);

                return(this.Ok(ChallengeMapper.Map(challengePayoutResponse.Payout.ChallengeId, participant.Participant, fetchDoxatagsResponse.Doxatags)));
            }
            catch (RpcException exception)
            {
                var deleteTransactionRequest = new DeleteTransactionRequest
                {
                    TransactionId = createTransactionResponse.Transaction.Id
                };

                await _cashierServiceClient.DeleteTransactionAsync(deleteTransactionRequest);

                throw exception.Capture();
            }
        }