Пример #1
0
        public string RetrieveCheckOutTransaction(GridMPGSConfig mpgsConfig, CheckOutResponseUpdate responseUpdate)
        {
            try
            {
                LogInfo.Information($" {EnumExtensions.GetDescription(MPGSAPIResponse.HostedCheckoutRetrieveReceipt) + " orderId  " +  responseUpdate.MPGSOrderID} result {responseUpdate.Result} sessionId {responseUpdate.CheckOutSessionID}");

                GatewayApiConfig config = new GatewayApiConfig(mpgsConfig);

                if (responseUpdate.Result == MPGSAPIResponse.SUCCESS.ToString() || responseUpdate.Result == MPGSAPIResponse.CAPTURED.ToString())
                {
                    GatewayApiRequest gatewayApiRequest = new GatewayApiRequest(config)
                    {
                        ApiOperation = MPGSAPIOperation.RETRIEVE_ORDER.ToString(),

                        OrderId = responseUpdate.MPGSOrderID,

                        ApiMethod = GatewayApiClient.GET
                    };

                    gatewayApiRequest.buildOrderUrl();

                    GatewayApiClient gatewayApiClient = new GatewayApiClient(config);

                    string response = gatewayApiClient.SendTransaction(gatewayApiRequest);

                    LogInfo.Information($" {EnumExtensions.GetDescription(MPGSAPIResponse.HostedCheckoutRetrieveReceipt) + " " + response}");

                    //parse response

                    return(response);
                }
                else
                {
                    LogInfo.Error($"  {MPGSAPIResponse.Unsuccessful.ToString()+ ".  " + responseUpdate.Result}");

                    return(string.Empty);
                }
            }
            catch (Exception ex)
            {
                LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical));

                throw ex;
            }
        }
Пример #2
0
        public async Task <int> ProcessSuccessTransaction(CheckOutResponseUpdate updateRequest)
        {
            try
            {
                OrderDataAccess _orderAccess = new OrderDataAccess(_iconfiguration);

                DatabaseResponse sourceTyeResponse = new DatabaseResponse();

                sourceTyeResponse = await _orderAccess.GetSourceTypeByMPGSSOrderId(updateRequest.MPGSOrderID);

                if (sourceTyeResponse.ResponseCode == (int)DbReturnValue.RecordExists)
                {
                    if (((OrderSource)sourceTyeResponse.Results).SourceType == CheckOutType.ChangeRequest.ToString())
                    {
                        var details = await _messageQueueDataAccess.GetMessageDetails(updateRequest.MPGSOrderID);

                        if (details != null)
                        {
                            MessageBodyForCR msgBody = new MessageBodyForCR();

                            string topicName = string.Empty, pushResult = string.Empty;

                            try
                            {
                                Dictionary <string, string> attribute = new Dictionary <string, string>();

                                msgBody = await _messageQueueDataAccess.GetMessageBodyByChangeRequest(details.ChangeRequestID);

                                DatabaseResponse changeRequestTypeResponse = await _orderAccess.GetChangeRequestTypeFromID(details.ChangeRequestID);

                                if (((string)changeRequestTypeResponse.Results) == NotificationEvent.ReplaceSIM.ToString())
                                {
                                    if (msgBody.SlotDate != null)
                                    {
                                        CustomerDetails customer = new CustomerDetails
                                        {
                                            Name                  = msgBody.Name,
                                            DeliveryEmail         = msgBody.Email,
                                            ShippingContactNumber = msgBody.ShippingContactNumber,
                                            OrderNumber           = msgBody.OrderNumber,
                                            SlotDate              = msgBody.SlotDate ?? DateTime.Now,
                                            SlotFromTime          = msgBody.SlotFromTime ?? DateTime.Now.TimeOfDay,
                                            SlotToTime            = msgBody.SlotToTime ?? DateTime.Now.TimeOfDay
                                        };

                                        string status = await SendOrderSuccessSMSNotification(customer, NotificationEvent.ReplaceSIM.ToString());
                                    }
                                }

                                if (details.RequestTypeID == (int)Core.Enums.RequestType.ReplaceSIM)
                                {
                                    topicName = ConfigHelper.GetValueByKey(ConfigKey.SNS_Topic_ChangeRequest.GetDescription(), _iconfiguration).Results.ToString().Trim();
                                    attribute.Add(EventTypeString.EventType, Core.Enums.RequestType.ReplaceSIM.GetDescription());
                                    pushResult = await _messageQueueDataAccess.PublishMessageToMessageQueue(topicName, msgBody, attribute);
                                }
                                if (pushResult.Trim().ToUpper() == "OK")
                                {
                                    MessageQueueRequest queueRequest = new MessageQueueRequest
                                    {
                                        Source           = Source.ChangeRequest,
                                        NumberOfRetries  = 1,
                                        SNSTopic         = topicName,
                                        CreatedOn        = DateTime.Now,
                                        LastTriedOn      = DateTime.Now,
                                        PublishedOn      = DateTime.Now,
                                        MessageAttribute = Core.Enums.RequestType.ReplaceSIM.GetDescription(),
                                        MessageBody      = JsonConvert.SerializeObject(msgBody),
                                        Status           = 1
                                    };
                                    await _messageQueueDataAccess.InsertMessageInMessageQueueRequest(queueRequest);
                                }
                                else
                                {
                                    MessageQueueRequest queueRequest = new MessageQueueRequest
                                    {
                                        Source           = Source.ChangeRequest,
                                        NumberOfRetries  = 1,
                                        SNSTopic         = topicName,
                                        CreatedOn        = DateTime.Now,
                                        LastTriedOn      = DateTime.Now,
                                        PublishedOn      = DateTime.Now,
                                        MessageAttribute = Core.Enums.RequestType.ReplaceSIM.GetDescription(),
                                        MessageBody      = JsonConvert.SerializeObject(msgBody),
                                        Status           = 0
                                    };
                                    await _messageQueueDataAccess.InsertMessageInMessageQueueRequest(queueRequest);
                                }
                            }
                            catch (Exception ex)
                            {
                                LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical));
                                MessageQueueRequestException queueRequest = new MessageQueueRequestException
                                {
                                    Source                                      = Source.ChangeRequest,
                                    NumberOfRetries                             = 1,
                                    SNSTopic                                    = string.IsNullOrWhiteSpace(topicName) ? null : topicName,
                                    CreatedOn                                   = DateTime.Now,
                                    LastTriedOn                                 = DateTime.Now,
                                    PublishedOn                                 = DateTime.Now,
                                    MessageAttribute                            = Core.Enums.RequestType.ReplaceSIM.GetDescription().ToString(),
                                    MessageBody                                 = msgBody != null?JsonConvert.SerializeObject(msgBody) : null,
                                                                      Status    = 0,
                                                                      Remark    = "Error Occured in ProcessSuccessTransaction",
                                                                      Exception = new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical)
                                };

                                await _messageQueueDataAccess.InsertMessageInMessageQueueRequestException(queueRequest);
                            }
                        }

                        return(3);
                    }

                    else if (((OrderSource)sourceTyeResponse.Results).SourceType == CheckOutType.Orders.ToString())
                    {
                        try
                        {
                            LogInfo.Information("Calling SendEmailNotification");
                            string emailStatus = await SendEmailNotification(updateRequest.MPGSOrderID, ((OrderSource)sourceTyeResponse.Results).SourceID);

                            LogInfo.Information("Email Send status for : " + emailStatus);
                        }

                        catch (Exception ex)
                        {
                            LogInfo.Information("Email Send failed");
                            LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical));
                        }

                        ProcessOrderQueueMessage(((OrderSource)sourceTyeResponse.Results).SourceID);

                        BuddyHelper buddyHelper = new BuddyHelper(_iconfiguration, _messageQueueDataAccess);

                        // Proess VAS bundles added to Order

                        DatabaseResponse getVASToProcessResponse = await _orderAccess.GetOrderedVASesToProcess(((OrderSource)sourceTyeResponse.Results).SourceID);

                        LogInfo.Information("Processing VASes for Order:" + ((OrderSource)sourceTyeResponse.Results).SourceID);

                        if (getVASToProcessResponse.ResponseCode == (int)DbReturnValue.RecordExists && getVASToProcessResponse.Results != null)
                        {
                            List <VasToProcess> vasListToProcess = (List <VasToProcess>)getVASToProcessResponse.Results;

                            LogInfo.Information(" VAS list to Process for Order:" + +((OrderSource)sourceTyeResponse.Results).SourceID + " - " + JsonConvert.SerializeObject(vasListToProcess));

                            DatabaseResponse customerResponse = await _orderAccess.GetCustomerIdFromOrderId(((OrderSource)sourceTyeResponse.Results).SourceID);

                            if (customerResponse != null && customerResponse.ResponseCode == (int)DbReturnValue.RecordExists)
                            {
                                int customerID = ((OrderCustomer)customerResponse.Results).CustomerId;

                                foreach (VasToProcess vas in vasListToProcess)
                                {
                                    BuyVASStatus vasProcessStatus = await buddyHelper.ProcessVas(customerID, vas.MobileNumber, vas.BundleID, 1);
                                }
                            }
                        }

                        return(3); // not buddy plan; MQ send
                    }

                    else if (((OrderSource)sourceTyeResponse.Results).SourceType == CheckOutType.AccountInvoices.ToString())
                    {
                        //send invoice queue message

                        ProcessAccountInvoiceQueueMessage(((OrderSource)sourceTyeResponse.Results).SourceID);

                        return(3);
                    }

                    else
                    {
                        return(5); // incorrect CheckOutType, no chance to reach here, but just to do
                                   //returnn from all code path, because in all of the above I need to keep CheckOutType check
                    }
                }

                else
                {
                    // unable to get sourcetype form db

                    return(4);
                }
            }
            catch (Exception ex)
            {
                LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical));
                return(0);
            }
        }
Пример #3
0
        public async void ProcessPayment(WebhookNotificationModel notification)
        {
            try
            {
                string json = JsonConvert.SerializeObject(notification);

                LogInfo.Information($"Webhooks notification model {json}");

                WebhookDataAccess _webhookAccess = new WebhookDataAccess(_iconfiguration);

                DatabaseResponse webhookLogUpdatedatabaseResponse = _webhookAccess.UpdateMPGSWebhookNotification(notification);

                // epoch


                System.IO.File.WriteAllText($@"{GatewayApiConfig.WEBHOOKS_NOTIFICATION_FOLDER}/WebHookNotifications_{notification.Timestamp}.json", json);


                CheckOutResponseUpdate updateRequest = new CheckOutResponseUpdate {
                    MPGSOrderID = notification.Order.Id, Result = notification.Order.Status
                };

                OrderDataAccess _orderAccess = new OrderDataAccess(_iconfiguration);

                //update checkout details

                // DatabaseResponse updateCheckoutDetailsResponse = await _orderAccess.UpdateCheckOutResponse(updateRequest);

                // retrieve transaction details from MPGS

                DatabaseResponse configResponse = await _orderAccess.GetConfiguration(ConfiType.MPGS.ToString());

                PaymentHelper gatewayHelper = new PaymentHelper();

                GridMPGSConfig gatewayConfig = gatewayHelper.GetGridMPGSConfig((List <Dictionary <string, string> >)configResponse.Results);

                //Direct capture MID config

                DatabaseResponse configDirectResponse = await _orderAccess.GetConfiguration(ConfiType.MPGSDirect.ToString());

                GridMPGSDirectMIDConfig gatewayDirectConfig = gatewayHelper.GetGridMPGSDirectMerchant((List <Dictionary <string, string> >)configDirectResponse.Results);

                gatewayConfig = gatewayHelper.GetGridMPGSCombinedConfig(gatewayConfig, gatewayDirectConfig);

                // Direct capture MID config end

                TransactionRetrieveResponseOperation transactionResponse = new TransactionRetrieveResponseOperation();

                string receipt = gatewayHelper.RetrieveCheckOutTransaction(gatewayConfig, updateRequest);

                transactionResponse = gatewayHelper.GetPaymentTransaction(receipt);

                if (webhookLogUpdatedatabaseResponse != null && webhookLogUpdatedatabaseResponse.Results != null)
                {
                    DatabaseResponse paymentMethodResponse = await _orderAccess.GetPaymentMethodToken((int)webhookLogUpdatedatabaseResponse.Results);

                    PaymentMethod paymentMethod = new PaymentMethod();

                    paymentMethod = (PaymentMethod)paymentMethodResponse.Results;

                    transactionResponse.TrasactionResponse.CardType = paymentMethod.CardType;

                    transactionResponse.TrasactionResponse.CardHolderName = paymentMethod.CardHolderName;

                    transactionResponse.TrasactionResponse.Token = paymentMethod.Token;
                }

                DatabaseResponse paymentProcessingRespose = new DatabaseResponse();

                paymentProcessingRespose = await _orderAccess.UpdateCheckOutReceipt(transactionResponse.TrasactionResponse);

                DatabaseResponse updatePaymentResponse = await _orderAccess.UpdatePaymentResponse(updateRequest.MPGSOrderID, receipt);

                if (paymentProcessingRespose.ResponseCode == (int)DbReturnValue.TransactionSuccess)
                {
                    LogInfo.Information(EnumExtensions.GetDescription(DbReturnValue.TransactionSuccess));

                    QMHelper qMHelper = new QMHelper(_iconfiguration, _messageQueueDataAccess);

                    int processResult = await qMHelper.ProcessSuccessTransaction(updateRequest);

                    if (processResult == 1)
                    {
                        LogInfo.Information(EnumExtensions.GetDescription(CommonErrors.PaymentProcessed));
                    }
                    else if (processResult == 2)
                    {
                        LogInfo.Warning(EnumExtensions.GetDescription(CommonErrors.PaymentProcessed));
                    }
                    else if (processResult == 3)
                    {
                        LogInfo.Warning(EnumExtensions.GetDescription(CommonErrors.PaymentProcessed) + ". " + EnumExtensions.GetDescription(CommonErrors.MQSent));
                    }

                    else if (processResult == 4)
                    {
                        LogInfo.Warning(EnumExtensions.GetDescription(CommonErrors.PaymentProcessed) + ". But while processing Buddy/MQ/EML/SMS " + EnumExtensions.GetDescription(CommonErrors.SourceTypeNotFound) + " for MPGSOrderID" + updateRequest.MPGSOrderID);
                    }

                    else if (processResult == 5)
                    {
                        LogInfo.Warning(EnumExtensions.GetDescription(CommonErrors.PaymentProcessed) + ". But while processing Buddy/MQ/EML/SMS " + EnumExtensions.GetDescription(CommonErrors.InvalidCheckoutType) + " for MPGSOrderID" + updateRequest.MPGSOrderID);
                    }

                    else
                    {
                        // entry for exceptions from QM Helper, but need to send payment success message to UI as payment already processed
                        LogInfo.Warning(EnumExtensions.GetDescription(CommonErrors.PaymentProcessed) + ". But while processing MQ/EML/SMS " + EnumExtensions.GetDescription(CommonErrors.SystemExceptionAfterPayment) + " for MPGSOrderID" + updateRequest.MPGSOrderID);
                    }
                }

                else
                {
                    LogInfo.Warning(EnumExtensions.GetDescription(DbReturnValue.TransactionFailed));
                }
            }
            catch (Exception ex)
            {
                LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical));
            }
        }