private async Task <Tuple <IList <Merchant>, IList <Merchant> > > ProcessMerchantFileAsync(MemoryStream memoryStream)
        {
            IList <Merchant> lstImportedMerchants = null;

            Log.Info($"Importing data from {merchantFileType.ToString()}");
            MerchantFileProcessor merchantFileProcessor = MerchantProcessorFactory.GetMerchantFileProcessor(merchantFileName);

            if (merchantFileType == MerchantFileType.MasterCardAuth)
            {
                lstImportedMerchants = await Task.Run(() => merchantFileProcessor.ImportMasterCardAuthFile(memoryStream)).ConfigureAwait(false);
            }
            else if (merchantFileType == MerchantFileType.MasterCardClearing)
            {
                lstImportedMerchants = await Task.Run(() => merchantFileProcessor.ImportMasterCardClearingFile(memoryStream)).ConfigureAwait(false);
            }
            if (lstImportedMerchants == null || !lstImportedMerchants.Any())
            {
                throw new Exception($"Error in processing the {merchantFileType.ToString()} file.");
            }
            Log.Info($"Total unique records imported from {merchantFileType.ToString()} is {lstImportedMerchants.Count}");

            Log.Info($"Getting all merchants for provider {provider.Id} from db");
            merchantsInDb = await EarnRepository.Instance.GetMerchantsForProviderAsync(provider.Id).ConfigureAwait(false);

            Log.Info($"Got {merchantsInDb.Count()} merchant entries for provider {provider.Id} from db");

            Tuple <IList <Merchant>, IList <Merchant> > lstMerchants = await Task.Run(() => AddOrUpdateMerchant(lstImportedMerchants)).ConfigureAwait(false);

            return(lstMerchants);
        }
Exemplo n.º 2
0
        private async Task <Tuple <IList <Merchant>, IList <Merchant> > > ProcessMerchantFileAsync(MemoryStream memoryStream)
        {
            IList <Merchant>      importedMerchants     = null;
            MerchantFileProcessor merchantFileProcessor = MerchantProcessorFactory.GetMerchantFileProcessor(merchantFileName);

            importedMerchants = merchantFileProcessor.ImportAmexMidFile(memoryStream);

            if (importedMerchants == null || !importedMerchants.Any())
            {
                throw new Exception($"ProvisionAmexMidsJob: An error occurred while processing Amex import file - No Data");
            }

            Log.Info($"ProvisionAmexMidsJob: Getting all merchants for provider {provider.Id} from db");
            merchantsInDb = await EarnRepository.Instance.GetMerchantsForProviderAsync(provider.Id).ConfigureAwait(false);

            Log.Info($"ProvisionAmexMidsJob: Got {merchantsInDb.Count()} merchant entries for provider {provider.Id} from db");
            // list of merchants to add and merchants to update
            Tuple <IList <Merchant>, IList <Merchant> > sortedMerchants = AddOrUpdateMerchant(importedMerchants);

            return(sortedMerchants);
        }
Exemplo n.º 3
0
        private async Task <IList <Merchant> > ProcessMerchantFileAsync(MemoryStream memoryStream)
        {
            IList <Merchant>      lstImportedMerchants  = null;
            MerchantFileProcessor merchantFileProcessor = MerchantProcessorFactory.GetMerchantFileProcessor(merchantFileName);

            lstImportedMerchants = await Task.Run(() => merchantFileProcessor.ImportVisaMidFile(memoryStream)).ConfigureAwait(false);

            if (lstImportedMerchants == null || !lstImportedMerchants.Any())
            {
                throw new Exception($"Error in processing the visa mid file.");
            }
            Log.Info($"Total unique records imported from the visa mid file is {lstImportedMerchants.Count}");

            Log.Info($"Getting all merchants for provider {provider.Id} from db");
            merchantsInDb = await EarnRepository.Instance.GetMerchantsForProviderAsync(provider.Id).ConfigureAwait(false);

            Log.Info($"Got {merchantsInDb.Count()} merchant entries for provider {provider.Id} from db");

            IList <Merchant> lstMerchants = await Task.Run(() => UpdateVisaPayment(lstImportedMerchants)).ConfigureAwait(false);

            return(lstMerchants);
        }
        public async Task ExecuteAsync(ScheduledJobInfo scheduledJobInfo)
        {
            await ValidatePayload(scheduledJobInfo).ConfigureAwait(false);

            IDictionary <string, string> payload = scheduledJobInfo.JobPayload;
            string merchantFileName = payload[JobConstants.BlobName];
            string blobContainer    = payload[JobConstants.ContainerName];
            string providerId       = payload[JobConstants.ProviderId];

            MemoryStream ms = await GetMerchantsFromBlobAsync(merchantFileName, blobContainer).ConfigureAwait(false);

            MerchantFileProcessor             merchantFileProcessor = MerchantProcessorFactory.GetMerchantFileProcessor(merchantFileName);
            Tuple <string, IList <Merchant> > provisioningData      = merchantFileProcessor.ImportMasterCardProvisioningFile(ms);

            if (provisioningData == null)
            {
                throw new Exception("Error in processing the mastercard provisioning file. Unable to provision merchants");
            }

            string           masterCardMerchantsProvisioningDate = provisioningData.Item1;
            IList <Merchant> lstProvisionedMerchants             = provisioningData.Item2;

            if (lstProvisionedMerchants.Any())
            {
                //Update the provider with the MasterCard merchant provisioning file date info. This is needed
                //at the time of exporting the file back to MasterCard.
                if (provider.ExtendedAttributes == null)
                {
                    provider.ExtendedAttributes = new Dictionary <string, string>();
                }
                if (!provider.ExtendedAttributes.ContainsKey(MerchantConstants.MCProvisioningDate))
                {
                    provider.ExtendedAttributes.Add(MerchantConstants.MCProvisioningDate, masterCardMerchantsProvisioningDate);
                }
                else
                {
                    provider.ExtendedAttributes[MerchantConstants.MCProvisioningDate] = masterCardMerchantsProvisioningDate;
                }
                await EarnRepository.Instance.UpdateAsync <Provider>(new List <Provider> {
                    provider
                });

                Log.Info($"Updated the provider {providerId} with the MasterCard provisioning date");

                //Add the new merchants to db.
                //TODO: As of now, the code can handle only new merchant additions from the MC file.
                //Need to add support to handle updates and deletes

                foreach (Merchant merchant in lstProvisionedMerchants)
                {
                    merchant.Id         = Guid.NewGuid().ToString();
                    merchant.ProviderId = provider.Id;
                    GeoCodeMerchantLocation(merchant);
                    if (merchant.ExtendedAttributes == null)
                    {
                        merchant.ExtendedAttributes = new Dictionary <string, string>();
                    }
                    string masterCardId = MasterCardIdGenerator.GetUniqueId(provider, merchant, "P");
                    Log.Info($"Generated mastercardid {masterCardId} for merchant {merchant.Name}");
                    merchant.ExtendedAttributes.Add(MerchantConstants.MCID, masterCardId);
                }

                Log.Info($"Total Merchants to add to db {lstProvisionedMerchants.Count}");
                await EarnRepository.Instance.AddMerchantsInBatchAsync(lstProvisionedMerchants);

                Log.Info($"Successfully added {lstProvisionedMerchants.Count} merchants to db");

                scheduledJobInfo.JobCompletedTime = DateTime.UtcNow;
            }
            else
            {
                Log.Warn("Provisioning file from MasterCard has 0 merchants");
            }
        }