Exemplo n.º 1
0
        public async Task <SocialTipResponse> Tip(SocialQueuedItem socialQueuedItem)
        {
            SocialTipResponse response = null;

            try
            {
                response = await _client.Tip(socialQueuedItem.SocialTipRequest, _secret).ConfigureAwait(false);

                if (response.Status == TransactionStatus.Queued)
                {
                    socialQueuedItem.TransactionId = response.TransactionId;
                    Enqueue(socialQueuedItem);
                }
            }
            catch (ApiException aex)
            {
                try
                {
                    response = JsonConvert.DeserializeObject <SocialTipResponse>(aex.Content);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);

                    response = new SocialTipResponse
                    {
                        Message       = "Duplicate transaction",
                        Status        = TransactionStatus.Error,
                        TransactionId = -1
                    };
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);

                response = new SocialTipResponse
                {
                    Message       = ex.Message,
                    Status        = TransactionStatus.Error,
                    TransactionId = -1
                };
            }

            if (response.Status != TransactionStatus.Queued)
            {
                await socialQueuedItem.Reply(
                    new SocialTipStatusResponse { Message = response.Message, Status = response.Status })
                .ConfigureAwait(false);

                ;
            }

            return(response);
        }