public async Task <String> UpdatePayment(IncidentPaymentRequest paymentRequest) { Services.Log.Info("Incident Payment Update Request [API]"); string responseText; stranddContext context = new stranddContext(); //Retrieve Incident Incident updateIncident = await(from r in context.Incidents where (r.Id == paymentRequest.IncidentGUID) select r).FirstOrDefaultAsync(); //Find the Incident to Edit and return Bad Response if not found if (updateIncident != null) { string guidnew = Guid.NewGuid().ToString(); //Check for Submitted Payment Amount Payment newPayment = new Payment { Id = guidnew, PaymentPlatform = paymentRequest.PaymentMethod, PlatformPaymentID = guidnew, Amount = paymentRequest.PaymentAmount, Fees = -1, ProviderUserID = IncidentInfo.GetProviderID(paymentRequest.IncidentGUID), Status = "Admin-Entered", BuyerName = "NONE", BuyerEmail = "NONE", BuyerPhone = "NONE", Currency = "INR", AuthenticationCode = "NONE", IncidentGUID = paymentRequest.IncidentGUID }; if (paymentRequest.PaymentMethod == "PAYMENT-CASH") { newPayment.PaymentPlatform = "Cash Payment (Admin)"; newPayment.Status = "PAYMENT-CASH"; } if (paymentRequest.PaymentMethod == "PAYMENT-FAIL") { newPayment.PaymentPlatform = "Payment Failure (Admin)"; newPayment.Status = "PAYMENT-FAIL"; } if (paymentRequest.PaymentAmount == 0) { newPayment.Amount = -1; } //Save record context.Payments.Add(newPayment); await context.SaveChangesAsync(); responseText = "Incident [" + updateIncident.Id + "] Payment Status Updated"; Services.Log.Info(responseText); //Notify Particular Connected User through SignalR IHubContext hubContext = Services.GetRealtime <IncidentHub>(); hubContext.Clients.Group(updateIncident.ProviderUserID).updateMobileClientStatus(newPayment.GetCustomerPushObject()); Services.Log.Info("Mobile Client [" + updateIncident.ProviderUserID + "] Status Update Payload Sent"); //Web Client Notifications hubContext.Clients.All.saveNewPayment(newPayment); Services.Log.Info("Connected Clients Updated"); //Return Successful Response return(responseText); } else { // Return Failed Response responseText = "Incident [" + paymentRequest.IncidentGUID + "] is not found in the system"; Services.Log.Warn(responseText); return(responseText); } }
public async Task <HttpResponseMessage> InstamojoWebHookReceiver(InstamojoWebhookRequest request) { Services.Log.Info("Instamojo Webhook Request"); string incidentPropertyName = WebConfigurationManager.AppSettings["RZ_InstamojoIncidentDataField"]; //var customFieldsObject = JsonConvert.DeserializeObject<InstamojoCustomFields>(request.Custom_Fields); //var parsedIncidentGUID = customFieldsObject.Field_25373.value; Services.Log.Info(incidentPropertyName); Services.Log.Info(request.Custom_Fields); JObject customFieldSetObj = JObject.Parse(request.Custom_Fields); Services.Log.Info(customFieldSetObj.ToString()); JObject customFieldInstanceObj = (JObject)customFieldSetObj[incidentPropertyName]; Services.Log.Info(customFieldInstanceObj.ToString()); string parsedIncidentGUID = customFieldInstanceObj["value"].ToString(); Services.Log.Info(parsedIncidentGUID); // Set the Payment Platform. string nameInstamojo = "Instamojo"; Payment newPayment = new Payment() { Id = Guid.NewGuid().ToString(), PlatformPaymentID = request.Payment_ID, Status = request.Status, BuyerName = request.Buyer_Name, BuyerEmail = request.Buyer, BuyerPhone = request.Buyer_Phone, Currency = request.Currency, Amount = request.Amount, Fees = request.Fees, AuthenticationCode = request.MAC, PaymentPlatform = nameInstamojo, IncidentGUID = parsedIncidentGUID, ProviderUserID = IncidentInfo.GetProviderID(parsedIncidentGUID) }; stranddContext context = new stranddContext(); context.Payments.Add(newPayment); await context.SaveChangesAsync(); //Initiating Hub Context Microsoft.AspNet.SignalR.IHubContext hubContext = Services.GetRealtime <IncidentHub>(); if (newPayment.ProviderUserID == "NO INCIDENT - NO PROVIDER ID") { Services.Log.Warn("New Instamojo Payment Received - No Incident"); } else if (newPayment.ProviderUserID == "INCIDENT NOT FOUND - NO PROVIDER ID") { Services.Log.Warn("New Instamojo Payment Received - No Found Incident"); } else if (newPayment.ProviderUserID == "NO ASSOCIATED USER") { Services.Log.Warn("New Instamojo Payment Received - No Associated User"); } else { Services.Log.Info("New Instamojo Payment Received from User [" + newPayment.ProviderUserID + "]"); //Notify Particular Connected User through SignalR hubContext.Clients.Group(newPayment.ProviderUserID).updateMobileClientStatus(newPayment.GetCustomerPushObject()); Services.Log.Info("Mobile Client [" + newPayment.ProviderUserID + "] Status Update Payload Sent"); SendGridController.SendIncidentPaymentReceiptEmail(newPayment, Services); } //Web Client Notifications hubContext.Clients.All.saveNewPayment(newPayment); Services.Log.Info("Connected Clients Updated"); return(this.Request.CreateResponse(HttpStatusCode.Created)); }