public static void InitiateTransferReversal(string transDateTime, string TransactionStan, string TransferReference)
        {
            var serviceBusTransferRequest = new ServiceBusTransferReversalRequestDto()
            {
                IsReversal                  = true,
                OriginalStan                = TransactionStan,
                PlatformReference           = TransferReference,
                OriginalTransactionDateTime = transDateTime
            };

            Console.WriteLine($"{DateTime.Now}--reversalobject--{JsonConvert.SerializeObject(serviceBusTransferRequest)}");

            var serviceBusCall = new ServiceBusManagement(AirtimeDomainAppsettingManager.GetAirtimeTransferQueueConnectionString()).PushToQueue(serviceBusTransferRequest, AirtimeDomainAppsettingManager.GetAirtimeQueueName());
        }
        public async Task <Result <Airtime> > BuyAirtime()
        {
            _logger.LogInformation($"Airtime log is working");

            string GlobalAccount = AppsettingsManager.GetConfig("GlobalAccount");
            // string Clientid = AppsettingsManager.GetConfig("ClientId");
            string Clientkey = AppsettingsManager.GetConfig("ClientKey");

            this.Narration = $"Airtime Recharge {this.ChannelId} {this.vendCode} {this.phoneNumber.Value}";

            var transferFunds = new TransferFunds(transferService, transferManager).Create(this, Narration, cif, GlobalAccount, DebitaccountNumber);

            await transferManager.InsertTransferTransaction(transferFunds);

            if (AirtimeDomainAppsettingManager.UseServiceBus())
            {
                var serviceBusTransferRequest = transferFunds.MapTo <ClientIntrabankRequest>();
                serviceBusTransferRequest.ClientKey = Clientkey;

                var serviceBusCall = new ServiceBusManagement(AirtimeDomainAppsettingManager.GetAirtimeTransferQueueConnectionString()).PushToQueue(serviceBusTransferRequest, AirtimeDomainAppsettingManager.GetAirtimeQueueName());
                ResponseStatus  = TransactionStatus.Processing.ToString();
                ResponseMessage = AirtimeValidationMessages.ConstantMessages.TransactionProcessing;
            }
            else
            {
                var transferResponse = transferFunds.ExecuteTransfer();

                //var transferResponse = new TransferResponse<TransferResult>()
                //{
                //    result = new TransferResult()
                //};

                //transferResponse.hasError = false;
                //transferResponse.result.Status = TransactionStatus.Success.ToString();

                if (transferResponse == null)
                {
                    ResponseStatus  = TransactionStatus.Failed.ToString();
                    ResponseMessage = AirtimeValidationMessages.ErrorMessages.TransferError;
                }
                else if (transferResponse.hasError == true)
                {
                    ResponseStatus = TransactionStatus.Failed.ToString();

                    if (transferResponse?.errorMessage?.ToString() == null)
                    {
                        string response = "";
                        foreach (var err in transferResponse.errorMessages)
                        {
                            response += err;
                        }
                        ResponseMessage = response;
                    }
                    else
                    {
                        ResponseMessage = transferResponse.errorMessage.ToString();
                    }
                }
                else
                {
                    if (transferResponse.result.Status == TransactionStatus.Success.ToString() || transferResponse.result.Status == TransactionStatus.Pending.ToString())
                    {
                        TransferReference = transferResponse?.result?.PlatformTransactionReference;
                        TransactionStan   = transferResponse?.result?.TransactionStan;
                        TransferNarration = transferResponse?.result?.Narration;

                        var AirtimeserviceResponse = SwitchAirtimeVendors(airtimeServices);

                        this.vendorId = AirtimeserviceResponse.ProccedByVendorId;

                        if (AirtimeserviceResponse.ResponseStatus == TransactionStatus.Success.ToString())
                        {
                            ResponseStatus             = TransactionStatus.Success.ToString();
                            ResponseMessage            = AirtimeValidationMessages.ConstantMessages.AirtimeTransactionSuccessful;
                            airtimeRequestStatus       = true;
                            transferFunds.IsSettlement = true;
                            var vendorDetails = this.Vendors.getSingleVendorAgent(int.Parse(AirtimeserviceResponse.ProccedByVendorId));

                            string SettlementNarration = $"Airtime Recharge {this.ChannelId} {this.vendCode} {this.phoneNumber.Value} {transferResponse.result.TransactionStan}";

                            TransferFunds.VendorSettlement(transferFunds, transferFunds.DateCreated.ToString(), vendorDetails.suspenseAccount, SettlementNarration);
                        }
                        else if (AirtimeserviceResponse.ResponseStatus == TransactionStatus.Pending.ToString())
                        {
                            ResponseStatus  = TransactionStatus.Pending.ToString();
                            ResponseMessage = AirtimeValidationMessages.ConstantMessages.TransactionProcessing;
                        }
                        else
                        {
                            ResponseStatus           = TransactionStatus.Failed.ToString();
                            ResponseMessage          = AirtimeserviceResponse?.ResponseMessage;
                            airtimeRequestStatus     = false;
                            transferFunds.IsReversal = true;
                            TransferFunds.InitiateTransferReversal(transferFunds.DateCreated.ToString(), transferResponse.result.TransactionStan, transferResponse.result.PlatformTransactionReference);
                        }
                    }
                    else
                    {
                        ResponseStatus       = transferResponse?.result?.Status.ToString();
                        ResponseMessage      = transferResponse?.result?.Message?.ToString();
                        airtimeRequestStatus = false;
                    }
                }
            }
            return(Result.Ok(this));
        }
Esempio n. 3
0
        public async Task <Result <Data> > BuyData()
        {
            var dataPackage = _DataPackages.getDatapackage(this.PackageId);

            if (dataPackage != null)
            {
                string GlobalAccount = AppsettingsManager.GetConfig("GlobalAccount");
                // string Clientid = AppsettingsManager.GetConfig("AirtimeClientID");
                string Clientkey = AppsettingsManager.GetConfig("ClientKey");

                amount = dataPackage.amount;

                this.Narration = $"Data Recharge {this.ChannelId} {dataPackage.Biller.Name} {this.phoneNumber.Value}";

                var transferFunds = new TransferFunds(transferService, transferManager).Create(this, Narration, cif, GlobalAccount, DebitAccountNumber);

                var transferfundjson = new StringContent(JsonConvert.SerializeObject(transferFunds).ToString());

                await transferManager.InsertTransferTransaction(transferFunds);

                if (AirtimeDomainAppsettingManager.UseServiceBus())
                {
                    var serviceBusTransferRequest = transferFunds.MapTo <ClientIntrabankRequest>();
                    serviceBusTransferRequest.ClientKey = Clientkey;

                    var serviceBusCall = new ServiceBusManagement(AirtimeDomainAppsettingManager.GetAirtimeTransferQueueConnectionString()).PushToQueue(serviceBusTransferRequest, AirtimeDomainAppsettingManager.GetAirtimeQueueName());
                    ResponseStatus  = PaymentSharedKernels.Models.Enums.TransactionStatus.Processing.ToString();
                    ResponseMessage = AirtimeValidationMessages.ConstantMessages.TransactionProcessing;
                }
                else
                {
                    var transferResponse = transferFunds.ExecuteTransfer();


                    if (transferResponse == null)
                    {
                        ResponseStatus  = TransactionStatus.Failed.ToString();
                        ResponseMessage = AirtimeValidationMessages.ErrorMessages.TransferError;
                    }
                    else if (transferResponse.hasError == true)
                    {
                        ResponseStatus = TransactionStatus.Failed.ToString();

                        if (transferResponse?.errorMessage?.ToString() == null)
                        {
                            string response = "";
                            foreach (var err in transferResponse.errorMessages)
                            {
                                response += err;
                            }
                            ResponseMessage = response;
                        }
                        else
                        {
                            ResponseMessage = transferResponse.errorMessage.ToString();
                        }
                    }
                    else
                    {
                        if (transferResponse.result.Status == TransactionStatus.Success.ToString() || transferResponse.result.Status == PaymentSharedKernels.Models.Enums.TransactionStatus.Pending.ToString())
                        {
                            TransferReference = transferResponse?.result?.PlatformTransactionReference;
                            TransactionStan   = transferResponse?.result?.TransactionStan;
                            TransferNarration = transferResponse?.result?.Narration;

                            var AirtimeserviceResponse = SwitchDataVendors(airtimeServices);
                            this.vendorId = int.Parse(AirtimeserviceResponse.ProccedByVendorId);

                            if (AirtimeserviceResponse.ResponseStatus == TransactionStatus.Success.ToString())
                            {
                                ResponseStatus             = TransactionStatus.Success.ToString();
                                ResponseMessage            = AirtimeValidationMessages.ConstantMessages.DataTransactionSuccessful;
                                DataRequestStatus          = true;
                                transferFunds.IsSettlement = true;

                                var vendorDetails = this.Vendors.getSingleVendorAgent(int.Parse(AirtimeserviceResponse.ProccedByVendorId));

                                string SettlementNarration = $"Data Recharge {this.ChannelId} {this._DataPackages.Biller.Name} {this.phoneNumber.Value} {transferResponse.result.TransactionStan}";

                                TransferFunds.VendorSettlement(transferFunds, transferFunds.DateCreated.ToString(), vendorDetails.suspenseAccount, SettlementNarration);
                            }
                            else
                            {
                                ResponseStatus           = TransactionStatus.Failed.ToString();
                                ResponseMessage          = AirtimeserviceResponse?.ResponseMessage;
                                DataRequestStatus        = false;
                                transferFunds.IsReversal = true;
                                TransferFunds.InitiateTransferReversal(transferFunds.DateCreated.ToString(), transferResponse.result.TransactionStan, transferResponse.result.PlatformTransactionReference);
                            }
                        }
                        else
                        {
                            ResponseStatus    = transferResponse?.result?.Status?.ToString();
                            ResponseMessage   = transferResponse?.result?.Message?.ToString();
                            DataRequestStatus = false;
                        }
                    }
                }
            }
            else
            {
                ResponseStatus  = TransactionStatus.Failed.ToString();
                ResponseMessage = AirtimeValidationMessages.ErrorMessages.InvalidDataPackageId;
                vendorId        = 0;
            }

            return(Result.Ok(this));
        }