public async Task HandleAsync(SmartVoucherUsedEvent message)
        {
            var partner = await _partnerManagementClient.Partners.GetByIdAsync(message.PartnerId);

            var customer =
                (await _customerProfileClient.CustomerProfiles.GetByCustomerIdAsync(message.CustomerId.ToString(), true, true))?.Profile;
            var campaign = await _smartVouchersClient.CampaignsApi.GetByIdAsync(message.CampaignId);

            await _reportHelper.AddAsync(new TransactionReport()
            {
                Amount          = Money18.Create(message.Amount),
                Id              = Guid.NewGuid().ToString(),
                PartnerId       = message.PartnerId.ToString(),
                Timestamp       = message.Timestamp,
                Currency        = message.Currency,
                TransactionType = TxType,
                CampaignName    = campaign?.Name,
                Status          = VoucherStatus,
                CampaignId      = message.CampaignId,
                Vertical        = partner.BusinessVertical?.ToString(),
                SenderEmail     = customer?.Email,
                SenderName      = $"{customer?.FirstName} {customer?.LastName}",
                PartnerName     = partner?.Name,
                Info            = message.VoucherShortCode,
            });
        }
        public async Task HandleAsync(P2PTransferEvent msg)
        {
            // TODO: implement deduplication later

            var profiles = await _customerProfileClient.CustomerProfiles.GetByIdsAsync(
                new [] { msg.SenderCustomerId, msg.ReceiverCustomerId },
                true,
                true);

            var sender   = profiles.FirstOrDefault(p => p.CustomerId == msg.SenderCustomerId);
            var receiver = profiles.FirstOrDefault(p => p.CustomerId == msg.ReceiverCustomerId);

            await _reportHelper.AddAsync(
                new TransactionReport
            {
                Id                  = msg.TransactionId,
                Timestamp           = msg.Timestamp,
                Amount              = msg.Amount,
                TransactionType     = TxType,
                TransactionCategory = TxCategory.P2P.ToString(),
                SenderName          = $"{sender?.FirstName} {sender?.LastName}",
                SenderEmail         = sender?.Email,
                ReceiverName        = $"{receiver?.FirstName} {receiver?.LastName}",
                ReceiverEmail       = receiver?.Email,
            }
                );
        }
Example #3
0
        public async Task HandleAsync(SmartVoucherSoldEvent message)
        {
            var partner = await _partnerManagementClient.Partners.GetByIdAsync(message.PartnerId);

            var customer =
                (await _customerProfileClient.CustomerProfiles.GetByCustomerIdAsync(message.CustomerId.ToString(), true, true))?.Profile;
            var campaign = await _smartVouchersClient.CampaignsApi.GetByIdAsync(message.CampaignId);

            var receiverEmail = partner.Locations.Count == 1 ? partner.Locations.First()?.ContactPerson?.Email : null;

            await _reportHelper.AddAsync(new TransactionReport
            {
                Amount          = Money18.Create(message.Amount),
                Id              = message.PaymentRequestId,
                PartnerId       = message.PartnerId.ToString(),
                Timestamp       = message.Timestamp,
                Vertical        = partner.BusinessVertical?.ToString(),
                Info            = message.VoucherShortCode,
                Currency        = message.Currency,
                TransactionType = TxType,
                SenderEmail     = customer?.Email,
                SenderName      = $"{customer?.FirstName} {customer?.LastName}",
                CampaignName    = campaign?.Name,
                Status          = VoucherStatus,
                CampaignId      = message.CampaignId,
                PartnerName     = partner?.Name,
                ReceiverName    = partner?.Name,
                ReceiverEmail   = receiverEmail,
            });
        }
        public async Task HandleAsync(ReferralStakeReservedEvent msg)
        {
            // TODO: implement deduplication later

            var campaign = await _campaignClient.History.GetEarnRuleByIdAsync(Guid.Parse(msg.CampaignId));

            if (campaign.ErrorCode != CampaignServiceErrorCodes.EntityNotFound)
            {
                _log.Warning("Campaign not found for bonus event",
                             context: new { customerId = msg.CustomerId, error = campaign.ErrorCode.ToString() });
            }

            var senderResponse = await _customerProfileClient.CustomerProfiles.GetByCustomerIdAsync(msg.CustomerId);

            var sender = senderResponse?.Profile;

            var condition = campaign.Conditions?.FirstOrDefault(c => c.Id == msg.CampaignId);
            var vertical  = await _verticalResolver.ResolveVerticalAsync(condition?.Type);

            string info = null;

            if (!string.IsNullOrWhiteSpace(msg.ReferralId))
            {
                var referralInfo = await _referralInfoFetcher.FetchReferralInfoAsync(msg.ReferralId);

                if (referralInfo != null)
                {
                    info = $"Staking amount reserved for referring {referralInfo.Email}";
                }
            }

            await _reportHelper.AddAsync(
                new TransactionReport
            {
                Id              = msg.ReferralId,
                Timestamp       = msg.Timestamp,
                Amount          = msg.Amount,
                Vertical        = vertical.ToString(),
                Status          = TxStatus.Reserved.ToString(),
                TransactionType = TxType,
                CampaignName    = campaign.Name,
                Info            = info,
                SenderName      = $"{sender?.FirstName} {sender?.LastName}",
                SenderEmail     = sender?.Email,
                CampaignId      = Guid.Parse(msg.CampaignId),
            }
                );
        }
        public async Task HandleAsync(PartnersPaymentTokensReservedEvent msg)
        {
            // TODO: implement deduplication later

            var senderResponse = await _customerProfileClient.CustomerProfiles.GetByCustomerIdAsync(msg.CustomerId);

            var sender = senderResponse?.Profile;

            string partnerName            = null;
            LocationDetailsModel location = null;

            if (!string.IsNullOrWhiteSpace(msg.LocationId))
            {
                if (Guid.TryParse(msg.LocationId, out var locId))
                {
                    var partner = await _partnerManagementClient.Partners.GetByLocationIdAsync(locId);

                    partnerName = partner?.Name;
                    location    = partner?.Locations.FirstOrDefault(l => l.Id == locId);
                }
                else
                {
                    _log.Warning($"Couldn't parse location id {msg.LocationId} as GUID");
                }
            }

            await _reportHelper.AddAsync(
                new TransactionReport
            {
                Id                      = msg.PaymentRequestId,
                Timestamp               = msg.Timestamp,
                TransactionType         = TxType,
                Status                  = TxStatus.Reserved.ToString(),
                Vertical                = Vertical.Hospitality.ToString(),
                TransactionCategory     = TxCategory.Redemption.ToString(),
                Amount                  = msg.Amount,
                SenderName              = $"{sender?.FirstName} {sender?.LastName}",
                SenderEmail             = sender?.Email,
                ReceiverName            = partnerName,
                LocationInfo            = location?.Name,
                LocationExternalId      = location?.ExternalId,
                LocationIntegrationCode = location?.AccountingIntegrationCode,
            }
                );
        }
        public async Task HandleAsync(TransferToExternalProcessedEvent msg)
        {
            // TODO: implement deduplication later

            var senderResponse = await _customerProfileClient.CustomerProfiles.GetByCustomerIdAsync(msg.CustomerId);

            var sender = senderResponse?.Profile;

            await _reportHelper.AddAsync(
                new TransactionReport
            {
                Id              = msg.OperationId,
                Timestamp       = DateTime.UtcNow,
                Amount          = msg.Amount,
                TransactionType = TxType,
                Vertical        = Vertical.LoyaltySystem.ToString(),
                Status          = TxStatus.Completed.ToString(),
                SenderName      = $"{sender?.FirstName} {sender?.LastName}",
                SenderEmail     = sender?.Email,
            }
                );
        }
        public async Task HandleAsync(VoucherTokensReservedEvent msg)
        {
            var senderResponse = await _customerProfileClient.CustomerProfiles.GetByCustomerIdAsync(msg.CustomerId.ToString());

            var sender = senderResponse?.Profile;

            await _reportHelper.AddAsync(
                new TransactionReport
            {
                Id                  = msg.TransferId.ToString(),
                Timestamp           = msg.Timestamp,
                Amount              = msg.Amount,
                TransactionType     = TxType,
                Vertical            = Vertical.Retail.ToString(),
                TransactionCategory = TxCategory.Redemption.ToString(),
                Status              = TxStatus.Reserved.ToString(),
                SenderName          = $"{sender?.FirstName} {sender?.LastName}",
                SenderEmail         = sender?.Email,
                ReceiverName        = ReceiverName,
            }
                );
        }
        public async Task HandleAsync(PaymentTransferTokensReservedEvent msg)
        {
            // TODO: implement deduplication later
            var senderResponse = await _customerProfileClient.CustomerProfiles.GetByCustomerIdAsync(msg.CustomerId);

            var sender = senderResponse?.Profile;

            await _reportHelper.AddAsync(
                new TransactionReport
            {
                Id                  = msg.TransferId,
                Timestamp           = msg.Timestamp,
                TransactionType     = TxType,
                Status              = TxStatus.Reserved.ToString(),
                Vertical            = Vertical.RealEstate.ToString(),
                TransactionCategory = TxCategory.Redemption.ToString(),
                Amount              = msg.Amount,
                SenderName          = $"{sender?.FirstName} {sender?.LastName}",
                SenderEmail         = sender?.Email,
                ReceiverName        = ReceiverName,
                LocationInfo        = msg.LocationCode,
            }
                );
        }
        public async Task HandleAsync(BonusReceivedEvent msg)
        {
            // TODO: implement deduplication later

            var profileResponse = await _customerProfileClient.CustomerProfiles.GetByCustomerIdAsync(
                msg.CustomerId,
                true,
                true);

            if (profileResponse.ErrorCode != CustomerProfileErrorCodes.None)
            {
                _log.Warning("Couldn't fetch customer profile from CP",
                             context: new { customerId = msg.CustomerId, error = profileResponse.ErrorCode.ToString() });

                return;
            }

            var profile = profileResponse.Profile;

            ConditionModel condition = null;
            var            campaign  = await _campaignClient.History.GetEarnRuleByIdAsync(msg.CampaignId);

            if (campaign.ErrorCode == CampaignServiceErrorCodes.EntityNotFound)
            {
                _log.Warning("Campaign not found for bonus event",
                             context: new { customerId = msg.CustomerId, error = campaign.ErrorCode.ToString() });
            }
            else
            {
                condition = campaign.Conditions.FirstOrDefault(c => c.Id == msg.ConditionId.ToString());

                if (condition == null && msg.BonusType != CampaignLevelBonusType)
                {
                    _log.Warning("Campaign does not contain the condition",
                                 context: new { campaignId = msg.CampaignId, conditionId = msg.ConditionId });
                }
            }

            Vertical vertical;

            if (!string.IsNullOrWhiteSpace(msg.LocationCode))
            {
                vertical = Vertical.RealEstate;
            }
            else if (!string.IsNullOrWhiteSpace(msg.PartnerId))
            {
                vertical = Vertical.Hospitality;
            }
            else
            {
                vertical = await _verticalResolver.ResolveVerticalAsync(condition?.Type);
            }

            string info = null;

            if (!string.IsNullOrWhiteSpace(msg.ReferralId))
            {
                var referralInfo = await _referralInfoFetcher.FetchReferralInfoAsync(msg.ReferralId);

                if (referralInfo != null)
                {
                    info = $"Referral bonus for {referralInfo.Email}";
                }
            }

            if (!string.IsNullOrWhiteSpace(condition?.TypeDisplayName))
            {
                info = info == null
                    ? condition?.TypeDisplayName
                    : $"{info} ({condition.TypeDisplayName})";
            }

            await _reportHelper.AddAsync(new TransactionReport
            {
                Id                  = msg.TransactionId,
                Timestamp           = msg.Timestamp,
                Amount              = msg.Amount,
                TransactionType     = TxType,
                Vertical            = vertical.ToString(),
                TransactionCategory = TxCategory.Earning.ToString(),
                CampaignName        = campaign.Name,
                Info                = info,
                ReceiverName        = $"{profile.FirstName} {profile.LastName}",
                ReceiverEmail       = profile.Email,
                CampaignId          = msg.CampaignId,
            }
                                         );
        }