예제 #1
0
        public Task Handle(RemoveCartEvent notification, CancellationToken cancellationToken)
        {
            try
            {
                RasvHubspotContact vId;
                if (!string.IsNullOrWhiteSpace(notification.CartDetail.HubspotUTK))
                {
                    vId = _hubSpotApi.Contact.GetByUserToken <RasvHubspotContact>(notification.CartDetail.HubspotUTK);
                }
                else
                {
                    User user = _userRepository.GetByAltId(notification.CartDetail.UserAltId);
                    vId = _hubSpotApi.Contact.GetByEmail <RasvHubspotContact>(user.Email);
                }

                HubspotCartTrack isNotAbandoned = _hubspotCartTrackRepository.GetByVId((long)vId.Id);
                _hubspotCartTrackRepository.DeleteHubspotCartTrack(new HubspotCartTrack
                {
                    Id = isNotAbandoned.Id,
                });
            }
            catch (Exception ex)
            {
                _logger.Log(LogCategory.Error, ex);
            }
            return(Task.FromResult(0));
        }
예제 #2
0
        public Task Handle(AbandonCartEvent notification, CancellationToken cancellationToken)
        {
            try
            {
                List <RasvHubspotContact> lstRasvHubspotContact = new List <RasvHubspotContact>();
                foreach (HubspotCartTrack item in notification.AbandonCart)
                {
                    RasvHubspotContact rasvHubspotContact = new RasvHubspotContact();
                    if (!string.IsNullOrWhiteSpace(item.EmailId) && item.EmailId.Contains("@"))
                    {
                        lstRasvHubspotContact.Add(new RasvHubspotContact
                        {
                            Email = item.EmailId,
                            KyazoongaCartAbandonment = "Yes"
                        });
                    }
                    else
                    {
                        var hubspotContact = _hubSpotApi.Contact.GetById <RasvHubspotContact>(item.HubspotVid);
                        if (hubspotContact != null)
                        {
                            lstRasvHubspotContact.Add(new RasvHubspotContact
                            {
                                Email = hubspotContact.Email,
                                KyazoongaCartAbandonment = "Yes"
                            });
                        }
                    }

                    HubspotCartTrack isNotAbandoned = _hubspotCartTrackRepository.GetByVId(item.HubspotVid);
                    if (isNotAbandoned != null)
                    {
                        _hubspotCartTrackRepository.DeleteHubspotCartTrack(new HubspotCartTrack
                        {
                            Id = isNotAbandoned.Id,
                        });
                    }
                }
                try
                {
                    _hubSpotApi.Contact.Batch(lstRasvHubspotContact);
                }
                catch (Exception ex)
                {
                }
            }
            catch (Exception ex)
            {
                _logger.Log(LogCategory.Error, ex);
            }
            return(Task.FromResult(0));
        }
예제 #3
0
        public Task Handle(TransactionEvent notification, CancellationToken cancellationToken)
        {
            // TODO: XXX: HUB:
            // Needs to check its a RASV transaction then,
            // This needs to loop over all of the Transaction items and then send
            // YES for each of RIDES, BODYWORLDS fields if theyre in the transaction
            // fields have spaces replaced with _ in API calls
            // field - value
            // RMS Ride Pass Purchased - YES if present
            // RMS Bodyworlds Purchased - YES if present
            // RMS Ticket Type - Online Ticket Saver or RACV Member
            // RMS 2019 Ticket Date of Purchase - Date for Hubspot of purchase

            //IN case of multiple tickets do we need to send by comma separated
            try
            {
                if (notification.TransactionStatus == Contracts.Enums.TransactionStatus.UnderPayment)
                {
                    var contact = _hubSpotApi.Contact.GetByEmail <RasvHubspotContact>(notification.EmailId) ?? new RasvHubspotContact();
                    contact = _hubSpotApi.Contact.CreateOrUpdate(new RasvHubspotContact
                    {
                        //Id = contact.Id,
                        Email   = contact.Email ?? notification.EmailId,
                        ZipCode = notification.ZipCode
                    });

                    HubspotCartTrack hubspotCartTrack = _hubspotCartTrackRepository.GetByVId((long)contact.Id);
                    if (hubspotCartTrack == null)
                    {
                        _hubspotCartTrackRepository.SaveHubspotCartTrack(new HubspotCartTrack
                        {
                            HubspotVid = (long)contact.Id,
                            EmailId    = contact.Email ?? notification.EmailId,
                        });
                    }
                }
                else
                {
                    var orderConfirmation = _orderConfirmationProvider.Get(notification.TransactionId, false, Contracts.Enums.Channels.Website);

                    if (orderConfirmation.orderConfirmationSubContainer[0].Event.AltId.ToString().ToUpper() == "1F0257FA-EEA6-4469-A7BC-B878A215C8A9")
                    {
                        //orderConfirmation.Transaction.CreatedUtc = orderConfirmation.Transaction.CreatedUtc.AddHours(10);
                        bool    IsRMSRidePassPurchased   = false;
                        bool    IsRMSBodyworldsPurchased = false;
                        var     RMSTicketType            = new List <string>();
                        var     DealsRMSTicketType       = new List <string>();
                        decimal?TicketAmount             = 0;

                        if (orderConfirmation.orderConfirmationSubContainer[0].subEventContainer.Where(w => w.EventDetail.Id == 554440 || w.EventDetail.Id == 554402).Count() > 0)
                        {
                            RMSTicketType.Add("General Admission");
                            DealsRMSTicketType.Add("General Admission");
                            List <SubEventContainer> TransactionDetail = orderConfirmation.orderConfirmationSubContainer[0].subEventContainer.Where(w => w.EventDetail.Id == 554402 || w.EventDetail.Id == 554440).ToList();
                            TicketAmount += TransactionDetail[0].TransactionDetail.Sum(s => s.PricePerTicket * s.TotalTickets);
                        }
                        if (orderConfirmation.orderConfirmationSubContainer[0].subEventContainer.Where(w => w.EventDetail.Id == 554441 || w.EventDetail.Id == 554403).Count() > 0)
                        {
                            RMSTicketType.Add("RACV Member 2019");
                            DealsRMSTicketType.Add("RACV Member");
                            List <SubEventContainer> TransactionDetail = orderConfirmation.orderConfirmationSubContainer[0].subEventContainer.Where(w => w.EventDetail.Id == 554403 || w.EventDetail.Id == 554441).ToList();
                            TicketAmount += TransactionDetail[0].TransactionDetail.Sum(s => s.PricePerTicket * s.TotalTickets);
                        }

                        if (orderConfirmation.orderConfirmationSubContainer[0].subEventContainer.Where(w => w.EventDetail.Id == 554442 || w.EventDetail.Id == 554404).Count() > 0)
                        {
                            RMSTicketType.Add("After 5pm 2019");
                            DealsRMSTicketType.Add("After 5");
                            List <SubEventContainer> TransactionDetail = orderConfirmation.orderConfirmationSubContainer[0].subEventContainer.Where(w => w.EventDetail.Id == 554404 || w.EventDetail.Id == 554442).ToList();
                            TicketAmount += TransactionDetail[0].TransactionDetail.Sum(s => s.PricePerTicket * s.TotalTickets);
                        }

                        if (orderConfirmation.orderConfirmationSubContainer[0].subEventContainer.Where(w => w.EventDetail.Id == 554443 || w.EventDetail.Id == 554405).Count() > 0)
                        {
                            RMSTicketType.Add("Group Bookings 2019");
                            DealsRMSTicketType.Add("Group Bookings");
                            List <SubEventContainer> TransactionDetail = orderConfirmation.orderConfirmationSubContainer[0].subEventContainer.Where(w => w.EventDetail.Id == 554405 || w.EventDetail.Id == 554443).ToList();
                            TicketAmount += TransactionDetail[0].TransactionDetail.Sum(s => s.PricePerTicket * s.TotalTickets);
                        }

                        if (orderConfirmation.orderConfirmationSubContainer[0].subEventContainer.Where(w => w.EventDetail.Id == 554439 || w.EventDetail.Id == 554401).Count() > 0)
                        {
                            IsRMSRidePassPurchased = true;
                            RMSTicketType.Add("Ride Pass");
                            DealsRMSTicketType.Add("Ride Pass");
                        }

                        if (RMSTicketType.Any() || IsRMSBodyworldsPurchased || IsRMSRidePassPurchased)
                        {
                            var contact = _hubSpotApi.Contact.GetByEmail <RasvHubspotContact>(orderConfirmation.Transaction.EmailId) ?? new RasvHubspotContact();
                            //to set to AEST
                            orderConfirmation.Transaction.CreatedUtc = orderConfirmation.Transaction.CreatedUtc.AddHours(10);

                            var dateTimeOffset = new DateTimeOffset(new DateTime(orderConfirmation.Transaction.CreatedUtc.Year, orderConfirmation.Transaction.CreatedUtc.Month, orderConfirmation.Transaction.CreatedUtc.Day, 00, 00, 00, 00, DateTimeKind.Utc));
                            var unixDateTime   = dateTimeOffset.ToUnixTimeMilliseconds();

                            string rmsTicketPurchased = "";
                            rmsTicketPurchased = (string.IsNullOrWhiteSpace(contact.RMSTicketPurchased)) ? "2019" : contact.RMSTicketPurchased;
                            if (!rmsTicketPurchased.Contains("2019"))
                            {
                                rmsTicketPurchased = rmsTicketPurchased + ";2019";
                            }

                            string rmsRidePassPurchased = IsRMSRidePassPurchased ? "Yes" : "No";

                            rmsRidePassPurchased = (contact.RMSRidePassPurchased == "Yes") ? "Yes" : rmsRidePassPurchased;

                            if (!string.IsNullOrWhiteSpace(contact.RMSTicketType))
                            {
                                foreach (var item in contact.RMSTicketType.Split(";"))
                                {
                                    if (!RMSTicketType.Contains(item))
                                    {
                                        RMSTicketType.Add(item);
                                    }
                                }
                            }

                            string zipCode = "3032";
                            if (orderConfirmation.orderConfirmationSubContainer[0].subEventContainer[0].Zipcode != null)
                            {
                                zipCode = orderConfirmation.orderConfirmationSubContainer[0].subEventContainer[0].Zipcode.Postalcode.ToString();
                            }

                            contact = _hubSpotApi.Contact.CreateOrUpdate(new RasvHubspotContact
                            {
                                //Id = contact.Id,
                                Email = contact.Email ?? orderConfirmation.Transaction.EmailId,
                                RMS2019TicketDateOfPurchase = unixDateTime.ToString(),
                                RMSRidePassPurchased        = rmsRidePassPurchased,
                                RMSTicketPurchased          = rmsTicketPurchased,
                                ZipCode       = zipCode,
                                RMSTicketType = RMSTicketType.Any() ? string.Join(';', RMSTicketType) : null
                            });

                            try
                            {
                                //TicketAmount = (double?)(TicketAmount ?? (decimal?)0.0),
                                _hubSpotApi.Deal.Create <RasvHubspotDeal>(new RasvHubspotDeal
                                {
                                    //Pipeline = "75e28846-ad0d-4be2-a027-5e1da6590b98",
                                    Pipeline      = "ab6f7db4-8afc-4733-bb09-54c93a630403",
                                    Stage         = "b874331f-c417-422d-83eb-43773f08819a",
                                    Name          = orderConfirmation.Transaction.Id.ToString(),
                                    CloseDate     = unixDateTime.ToString(),
                                    RMSTicketType = string.Join(';', DealsRMSTicketType),
                                    Amount        = (double?)(orderConfirmation.Transaction.GrossTicketAmount ?? (decimal?)0.0),
                                    TicketAmount  = (double?)(TicketAmount ?? (decimal?)0.0),
                                    Associations  = new DealHubSpotAssociations
                                    {
                                        AssociatedContacts = new[] { (long)contact.Id }
                                    }
                                });
                            }
                            catch (Exception ex)
                            {
                                _logger.Log(LogCategory.Error, ex);
                            }

                            HubspotCartTrack isNotAbandoned = _hubspotCartTrackRepository.GetByVId((long)contact.Id);
                            if (isNotAbandoned != null)
                            {
                                _hubspotCartTrackRepository.DeleteHubspotCartTrack(new HubspotCartTrack
                                {
                                    Id = isNotAbandoned.Id,
                                });
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Log(LogCategory.Error, ex);
            }
            return(Task.FromResult(0));
        }
예제 #4
0
        public Task Handle(CartInfoEvent notification, CancellationToken cancellationToken)
        {
            // TODO: XXX: HUB: I dont think this has to do anything.
            // You should have the service look at transactions not completed (Status != Success)
            // within the abandonment period (~15 min)
            // Must also check the user doesnt have a different completed cart, because then this doesnt matter
            // The Abandonment is just YES / NO field named Kyazoonga Cart Abandonment (kyazoonga_cart_abandonment in the api)

            // will look when work on service
            try
            {
                bool   IsRMSRidePassPurchased     = false;
                bool   IsRMSBodyworldsPurchased   = false;
                string RMS2019TicketPlatformLogin = "******";
                var    RMSTicketType = new List <string>();

                if ((notification.CartDetail.EventDetailId.Where(w => w.EventDetailId == 554440).Count() > 0) || (notification.CartDetail.EventDetailId.Where(w => w.EventDetailId == 554402).Count() > 0))
                {
                    RMSTicketType.Add("General Admission");
                }

                if ((notification.CartDetail.EventDetailId.Where(w => w.EventDetailId == 554441).Count() > 0) || (notification.CartDetail.EventDetailId.Where(w => w.EventDetailId == 554403).Count() > 0))
                {
                    RMSTicketType.Add("RACV Member 2019");
                }

                if ((notification.CartDetail.EventDetailId.Where(w => w.EventDetailId == 554442).Count() > 0) || (notification.CartDetail.EventDetailId.Where(w => w.EventDetailId == 554404).Count() > 0))
                {
                    RMSTicketType.Add("After 5pm 2019");
                }

                if ((notification.CartDetail.EventDetailId.Where(w => w.EventDetailId == 554443).Count() > 0) || (notification.CartDetail.EventDetailId.Where(w => w.EventDetailId == 554405).Count() > 0))
                {
                    RMSTicketType.Add("Group Bookings 2019");
                }

                if ((notification.CartDetail.EventDetailId.Where(w => w.EventDetailId == 554439).Count() > 0) || (notification.CartDetail.EventDetailId.Where(w => w.EventDetailId == 554403).Count() > 0))
                {
                    IsRMSRidePassPurchased = true;
                    RMSTicketType.Add("Ride Pass");
                }

                if (RMSTicketType.Any() || IsRMSBodyworldsPurchased || IsRMSRidePassPurchased)
                {
                    RasvHubspotContact vId = null;
                    try
                    {
                        if (!string.IsNullOrWhiteSpace(notification.CartDetail.HubspotUTK) && string.IsNullOrWhiteSpace(notification.CartDetail.Email))
                        {
                            RMS2019TicketPlatformLogin = "******";
                            vId = _hubSpotApi.Contact.GetByUserToken <RasvHubspotContact>(notification.CartDetail.HubspotUTK);
                        }
                        else if (notification.CartDetail.UserAltId != new Guid())
                        {
                            RMS2019TicketPlatformLogin = "******";
                            User user = _userRepository.GetByAltId(notification.CartDetail.UserAltId);
                            vId = _hubSpotApi.Contact.GetByEmail <RasvHubspotContact>(user.Email);

                            if (!string.IsNullOrWhiteSpace(vId.RMS2019TicketPlatformLogin))
                            {
                                RMS2019TicketPlatformLogin = vId.RMS2019TicketPlatformLogin;
                            }

                            vId = _hubSpotApi.Contact.CreateOrUpdate(new RasvHubspotContact
                            {
                                Email = user.Email,
                                RMS2019TicketPlatformLogin = RMS2019TicketPlatformLogin,
                            });
                        }
                        else
                        {
                            RMS2019TicketPlatformLogin = "******";
                            vId = _hubSpotApi.Contact.GetByEmail <RasvHubspotContact>(notification.CartDetail.Email);
                            if (!string.IsNullOrWhiteSpace(vId.RMS2019TicketPlatformLogin))
                            {
                                RMS2019TicketPlatformLogin = vId.RMS2019TicketPlatformLogin;
                            }

                            vId = _hubSpotApi.Contact.CreateOrUpdate(new RasvHubspotContact
                            {
                                Email = notification.CartDetail.Email,
                                RMS2019TicketPlatformLogin  = RMS2019TicketPlatformLogin,
                                RMSNewsletterSubscriber2019 = notification.CartDetail.IsMailOpt ? "Yes" : "No",
                                RMSMarketingOptIn           = notification.CartDetail.IsMailOpt ? "Yes" : "No"
                            });
                        }
                    }
                    catch (Exception ex)
                    {
                        if (!string.IsNullOrWhiteSpace(notification.CartDetail.Email))
                        {
                            vId = _hubSpotApi.Contact.CreateOrUpdate(new RasvHubspotContact
                            {
                                Email     = notification.CartDetail.Email,
                                FirstName = notification.CartDetail.FirstName,
                                LastName  = notification.CartDetail.LastName,
                                Phone     = notification.CartDetail.Phone,
                                RMS2019TicketPlatformLogin  = "******",
                                RMSNewsletterSubscriber2019 = notification.CartDetail.IsMailOpt ? "Yes" : "No",
                                RMSMarketingOptIn           = notification.CartDetail.IsMailOpt ? "Yes" : "No"
                            });
                        }
                    }

                    if (vId != null)
                    {
                        HubspotCartTrack hubspotCartTrack = _hubspotCartTrackRepository.GetByVId((long)vId.Id);
                        if (hubspotCartTrack == null)
                        {
                            _hubspotCartTrackRepository.SaveHubspotCartTrack(new HubspotCartTrack
                            {
                                HubspotVid = (long)vId.Id,
                                EmailId    = !string.IsNullOrWhiteSpace(vId.Email) ? vId.Email : notification.CartDetail.HubspotUTK,
                            });
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Log(LogCategory.Error, ex);
            }
            return(Task.FromResult(0));
        }