Beispiel #1
0
        private void HandleTicketResponse(ITicketResponse ticket)
        {
            _log.Info($"Ticket '{ticket.TicketId}' response is {ticket.Status}. Reason={ticket.Reason?.Message}");

            if (ticket.BetDetails != null && ticket.BetDetails.Any())
            {
                foreach (var betDetail in ticket.BetDetails)
                {
                    _log.Info($"Bet decline reason: '{betDetail.Reason?.Message}'.");
                    if (betDetail.SelectionDetails != null && betDetail.SelectionDetails.Any())
                    {
                        foreach (var selectionDetail in betDetail.SelectionDetails)
                        {
                            _log.Info($"Selection decline reason: '{selectionDetail.Reason?.Message}'.");
                        }
                    }
                }
            }

            if (ticket.Status == TicketAcceptance.Accepted)
            {
                //required only if 'explicit acking' is enabled in MTS admin
                ticket.Acknowledge();

                // handle ticket response

                //if for some reason we want to cancel ticket, this is how we can do it
                var ticketCancel = _factory.CreateTicketCancelBuilder().SetTicketId(ticket.TicketId).SetCode(TicketCancellationReason.BookmakerTechnicalIssue).BuildTicket();
                _mtsSdk.SendTicket(ticketCancel);
            }
        }
Beispiel #2
0
 /// <summary>
 /// Sets the original ticket and the ticket response
 /// </summary>
 /// <param name="ticket">The original ticket</param>
 /// <param name="ticketResponse">The ticket response from which the stake info will be used</param>
 /// <param name="newTicketId">The new reoffer ticket id</param>
 /// <returns>Returns the <see cref="ITicketReofferBuilder" /></returns>
 /// <remarks>Only tickets with exactly 1 bet are supported</remarks>
 public ITicketReofferBuilder Set(ITicket ticket, ITicketResponse ticketResponse, string newTicketId = null)
 {
     _ticket         = ticket;
     _ticketResponse = ticketResponse;
     _newTicketId    = newTicketId;
     return(this);
 }
Beispiel #3
0
        private void HandleTicketResponse(ITicketResponse ticketResponse)
        {
            _log.Info($"Ticket '{ticketResponse.TicketId}' response is {ticketResponse.Status}. Reason={ticketResponse.Reason?.Message}");
            if (ticketResponse.Status == TicketAcceptance.Accepted)
            {
                //required only if 'explicit acking' is enabled in MTS admin
                ticketResponse.Acknowledge();

                // handle ticket response

                //if for some reason we want to cancel ticket, this is how we can do it
                var ticketCancel = _factory.CreateTicketCancelBuilder().SetTicketId(ticketResponse.TicketId).SetCode(TicketCancellationReason.BookmakerTechnicalIssue).BuildTicket();
                _mtsSdk.SendTicket(ticketCancel);
            }
            else
            {
                // if the ticket was declined and response has reoffer, the reoffer or reoffer cancellation can be send
                // the reoffer or reoffer cancellation must be send before predefined timeout, or is automatically canceled
                if (ticketResponse.BetDetails.Any(a => a.Reoffer != null))
                {
                    if (ReofferShouldBeAccepted())
                    {
                        // ReSharper disable once RedundantArgumentDefaultValue
                        var reofferTicket = _factory.CreateTicketReofferBuilder().Set(_originalTicket, ticketResponse, null).BuildTicket();
                        _mtsSdk.SendTicket(reofferTicket);
                    }
                    else
                    {
                        var reofferCancel = _factory.CreateTicketReofferCancelBuilder().SetTicketId(ticketResponse.TicketId).BuildTicket();
                        _mtsSdk.SendTicket(reofferCancel);
                    }
                }
            }
        }
Beispiel #4
0
        public static void Compare(ITicketResponse ticket, TicketResponseDTO dto)
        {
            Assert.IsTrue(ticket != null);
            Assert.IsTrue(dto != null);

            Assert.AreEqual(ticket.TicketId, dto.Result.TicketId);
            Assert.AreEqual(ticket.Status, MtsTicketHelper.Convert(dto.Result.Status));
            Assert.AreEqual(ticket.Signature, dto.Signature);
            Assert.AreEqual(ticket.ExchangeRate, dto.ExchangeRate);
            Assert.AreEqual(ticket.Version, dto.Version);

            Assert.AreEqual(ticket.Reason.Code, dto.Result.Reason.Code);
            Assert.AreEqual(ticket.Reason.Message, dto.Result.Reason.Message);
            Assert.IsNull(ticket.Reason.InternalMessage);

            if (ticket.BetDetails == null || !ticket.BetDetails.Any())
            {
                return;
            }

            for (var i = 0; i < ticket.BetDetails.Count(); i++)
            {
                var bd1 = ticket.BetDetails.ToList()[i];
                var bd2 = dto.Result.BetDetails.ToList()[i];
                Compare(bd1.Reason, bd2.Reason);
                Assert.AreEqual(bd1.BetId, bd2.BetId);
                if (bd1.AlternativeStake != null)
                {
                    Assert.AreEqual(bd1.AlternativeStake.Stake, bd2.AlternativeStake.Stake);
                }
                if (bd1.Reoffer != null)
                {
                    Assert.AreEqual(bd1.Reoffer.Stake, bd2.Reoffer.Stake);
                    Assert.AreEqual(bd1.Reoffer.Type, MtsTicketHelper.Convert(bd2.Reoffer.Type));
                }
                if (bd2.SelectionDetails != null && bd2.SelectionDetails.Any())
                {
                    for (var j = 0; j < bd2.SelectionDetails.Count(); j++)
                    {
                        Compare(bd1.SelectionDetails.ToList()[i].Reason, bd2.SelectionDetails.ToList()[i].Reason);
                        Assert.AreEqual(bd1.SelectionDetails.ToList()[i].SelectionIndex, bd2.SelectionDetails.ToList()[i].SelectionIndex);
                        if (bd2.SelectionDetails.ToList()[i].RejectionInfo != null)
                        {
                            Compare(bd1.SelectionDetails.ToList()[i].RejectionInfo, bd2.SelectionDetails.ToList()[i].RejectionInfo);
                        }
                    }
                }
            }
            Assert.IsFalse(string.IsNullOrEmpty(ticket.CorrelationId));
        }
Beispiel #5
0
        private void HandleTicketResponse(ITicketResponse ticketResponse)
        {
            _log.LogInformation($"Ticket '{ticketResponse.TicketId}' response is {ticketResponse.Status}. Reason={ticketResponse.Reason?.Message}");
            if (ticketResponse.Status == TicketAcceptance.Accepted)
            {
                //required only if 'explicit acking' is enabled in MTS admin
                ticketResponse.Acknowledge();

                // handle ticket response

                //if for some reason we want to cashout ticket, this is how we can do it
                var ticketCashout = _factory.CreateTicketCashoutBuilder().SetTicketId(ticketResponse.TicketId).SetCashoutStake(12932).BuildTicket();
                _mtsSdk.SendTicket(ticketCashout);
            }
        }
Beispiel #6
0
        /// <summary>
        /// Builds the reoffer ticket based on the original ticket and the ticket response
        /// </summary>
        /// <param name="builderFactory">A <see cref="SimpleBuilderFactory"/> used to construct entity builders</param>
        /// <param name="orgTicket">The original ticket</param>
        /// <param name="orgTicketResponse">The ticket response from which the stake info will be used</param>
        /// <param name="newTicketId">The new reoffer ticket id</param>
        /// <exception cref="ArgumentNullException">Ticket and TicketResponse are mandatory</exception>
        /// <returns>Returns the <see cref="ITicket"/> representing the reoffer</returns>
        /// <remarks>Only tickets with exactly 1 bet are supported</remarks>
        /// <exception cref="ArgumentException">Only tickets with exactly 1 bet are supported</exception>
        private static ITicket BuildReofferTicket(ISimpleBuilderFactory builderFactory, ITicket orgTicket, ITicketResponse orgTicketResponse, string newTicketId = null)
        {
            if (orgTicket == null)
            {
                throw new ArgumentNullException(nameof(orgTicket));
            }
            if (orgTicketResponse == null)
            {
                throw new ArgumentNullException(nameof(orgTicketResponse));
            }
            if (orgTicket.Bets.Count() != 1)
            {
                throw new ArgumentException("Only tickets with exactly 1 bet are supported.");
            }
            if (orgTicketResponse.BetDetails.Any(a => a.Reoffer == null))
            {
                throw new ArgumentException("Response bet details are missing Reoffer info.");
            }

            if (orgTicket.Bets.Count() == 1)
            {
                return(BuildReofferTicket(builderFactory, orgTicket, orgTicketResponse.BetDetails.First().Reoffer.Stake, newTicketId));
            }

            var reofferTicketBuilder = builderFactory.CreateTicketBuilder()
                                       .SetTicketId(string.IsNullOrEmpty(newTicketId) ? orgTicket.TicketId + "R" : newTicketId)
                                       .SetSender(orgTicket.Sender)
                                       .SetTestSource(orgTicket.TestSource)
                                       .SetReofferId(orgTicket.TicketId);

            if (orgTicket.LastMatchEndTime.HasValue)
            {
                reofferTicketBuilder.SetLastMatchEndTime(orgTicket.LastMatchEndTime.Value);
            }

            if (orgTicket.OddsChange.HasValue)
            {
                reofferTicketBuilder.SetOddsChange(orgTicket.OddsChange.Value);
            }

            foreach (var ticketBet in orgTicket.Bets)
            {
                var responseBetDetail = orgTicketResponse.BetDetails.First(f => f.BetId == ticketBet.Id);
                if (responseBetDetail == null)
                {
                    throw new ArgumentException($"Ticket response is missing a bet details for the bet {ticketBet.Id}");
                }
                var newBetBuilder = builderFactory.CreateBetBuilder()
                                    .SetBetId(ticketBet.Id + "R")
                                    .SetReofferRefId(ticketBet.Id);
                if (ticketBet.Stake.Type.HasValue)
                {
                    newBetBuilder.SetStake(responseBetDetail.Reoffer.Stake, ticketBet.Stake.Type.Value);
                }
                else
                {
                    newBetBuilder.SetStake(responseBetDetail.Reoffer.Stake);
                }
                if (ticketBet.SumOfWins > 0)
                {
                    newBetBuilder.SetSumOfWins(ticketBet.SumOfWins);
                }
                if (ticketBet.Bonus != null)
                {
                    newBetBuilder.SetBetBonus(ticketBet.Bonus.Value, ticketBet.Bonus.Mode, ticketBet.Bonus.Type);
                }
                foreach (var ticketBetSelection in ticketBet.Selections)
                {
                    newBetBuilder.AddSelection(ticketBetSelection);
                }
                foreach (var ticketBetSelectedSystem in ticketBet.SelectedSystems)
                {
                    newBetBuilder.AddSelectedSystem(ticketBetSelectedSystem);
                }
                reofferTicketBuilder.AddBet(newBetBuilder.Build());
            }
            return(reofferTicketBuilder.BuildTicket());
        }
Beispiel #7
0
        public Task HandleTicketResponse(ITicketResponse ticket)
        {
            Task task = null;

            _log.Info($"Ticket '{ticket.TicketId}' response is {ticket.Status}. Reason={ticket.Reason?.Message}");

            if (ticket.BetDetails != null && ticket.BetDetails.Any())
            {
                foreach (var betDetail in ticket.BetDetails)
                {
                    _log.Info($"Bet decline reason: '{betDetail.Reason?.Message}'.");
                    if (betDetail.SelectionDetails != null && betDetail.SelectionDetails.Any())
                    {
                        foreach (var selectionDetail in betDetail.SelectionDetails)
                        {
                            _log.Info($"Selection decline reason: '{selectionDetail.Reason?.Message}'.");
                        }
                    }
                }

                var tkId = Convert.ToInt64(ticket.TicketId.Split('_')[1]);
                if (ticket.Status == TicketAcceptance.Accepted)
                {
                    //required only if 'explicit acking' is enabled in MTS admin
                    //ticket.Acknowledge();
                    //update ticket status in db
                    task = Task.Run(() =>
                    {
                        //int stat = (int)BetStatus.r;
                        int stat = (int)TicketStatus.running;
                        _ticketService.AcceptTicket(tkId, stat.ToString());
                    });
                    return(task);
                }
                else if (ticket.Status == TicketAcceptance.Rejected)
                {
                    //REOFFER
                    //// if the ticket was declined and response has reoffer, the reoffer or reoffer cancellation can be send
                    //// the reoffer or reoffer cancellation must be send before predefined timeout, or is automatically canceled
                    if (ticket.BetDetails.Any(a => a.Reoffer != null))
                    {
                        if (ReofferShouldBeAccepted(ticket.Reason.Code))
                        {
                            // ReSharper disable once RedundantArgumentDefaultValue
                            var reofferTicket = _factory.CreateTicketReofferBuilder().Set(mtsTicket, ticket, null).BuildTicket();
                            _mtsSdk.SendTicket(reofferTicket);
                            //
                        }
                        else
                        {
                            var reofferCancel = _factory.CreateTicketReofferCancelBuilder().SetTicketId(ticket.TicketId).BuildTicket();
                            _mtsSdk.SendTicket(reofferCancel);
                            //update ticket status in db
                            task = Task.Run(() =>
                            {
                                //int stat = (int)BetStatus.d;
                                int stat = (int)TicketStatus.refused;
                                //_ticketService.UpdateTicketStatus(tkId, stat.ToString());
                                _ticketService.RejectTicket(tkId, stat.ToString(), ticket.Reason.Code);
                            });
                            return(task);
                        }
                    }
                    else
                    {
                        if (ticket.Reason.Code == 101 || ticket.Reason.Code == 103 || ticket.Reason.Code == -101 || ticket.Reason.Code == -103)
                        {
                            ticket.Acknowledge();
                        }
                        //update ticket status in db
                        task = Task.Run(() =>
                        {
                            //int stat = (int)BetStatus.d;
                            int stat = (int)TicketStatus.refused;
                            //_ticketService.UpdateTicketStatus(tkId, stat.ToString());
                            _ticketService.RejectTicket(tkId, stat.ToString(), ticket.Reason.Code);
                        });
                        return(task);
                    }
                }
            }
            return(task);
        }