public async Task<IHttpActionResult> CreateOpportunity(BuyUserModelDto buyUserModelDto) { buyUserModelDto.CompanyId = User.Identity.GetUserId(); BuyUserStatusMessage status = new BuyUserStatusMessage(); string companyId = User.Identity.GetUserId(); string crmContactId = this.youfferContactService.GetMappingEntryByContactId(buyUserModelDto.UserId).ContactCRMId; string crmLeadId = this.youfferContactService.GetMappingEntryByContactId(buyUserModelDto.UserId).LeadId; ApplicationUserDto compantDet = this.youfferContactService.GetOrgCRMId(companyId); string crmOrgId = compantDet.CRMId; LeadModel leadModel = this.crmManagerService.GetLead(crmLeadId); OrganisationModel org = this.crmManagerService.GetOrganisation(companyId); if (buyUserModelDto.PurchasedFromCredit) { if (org.BillCountry.ToLower() == "india" && org.CreditBalance < 125) { status.IsSuccess = false; status.ErrorMessage = "You do not have sufficient credit."; status.CreditBalance = org.CreditBalance; status.CashBalance = org.CashBalance; return this.Ok(status); } else if (org.BillCountry.ToLower() != "india" && org.CreditBalance < 5) { status.IsSuccess = false; status.ErrorMessage = "You do not have sufficient credit."; status.CreditBalance = org.CreditBalance; status.CashBalance = org.CashBalance; return this.Ok(status); } } else if (buyUserModelDto.PurchasedFromCash) { if (org.BillCountry.ToLower() == "india" && org.CashBalance < 125) { status.IsSuccess = false; status.ErrorMessage = "You do not have sufficient cash."; status.CreditBalance = org.CreditBalance; status.CashBalance = org.CashBalance; return this.Ok(status); } else if (org.BillCountry.ToLower() != "india" && org.CashBalance < 5) { status.IsSuccess = false; status.ErrorMessage = "You do not have sufficient cash."; status.CreditBalance = org.CreditBalance; status.CashBalance = org.CashBalance; return this.Ok(status); } } status.IsSuccess = this.crmManagerService.AddOpportunity(buyUserModelDto); if (status.IsSuccess) { double price = Convert.ToDouble(buyUserModelDto.Amount); org.AnnualRevenue += price; if (buyUserModelDto.PurchasedFromCredit) { org.CreditBalance -= Convert.ToDecimal(price); leadModel.PurchasedWithCreditCount += 1; this.crmManagerService.UpdateLead(leadModel.Id, leadModel); } else if (buyUserModelDto.PurchasedFromCash) { org.CashBalance -= Convert.ToDecimal(price); } status.CreditBalance = org.CreditBalance; status.CashBalance = org.CashBalance; this.crmManagerService.UpdateOrganisation(buyUserModelDto.CompanyId, org); } return this.Ok(status); }
public async Task<IHttpActionResult> PaypalConfirmed(string token, string payerId, string id) { try { PaypalDetails paypalDetails = this.commonService.GetCache<PaypalDetails>(id); PaypalPayTransactionModel paymentTransaction = this.paymentService.GetPaypalPaymentId(Guid.Parse(id)); if (paymentTransaction == null) { return this.Redirect(string.Format(AppSettings.Get<string>("WebReturnURL"), paypalDetails.Domain, "Invalid request")); } string paymentId = paymentTransaction.PaymentId; if (string.IsNullOrWhiteSpace(paymentId)) { return this.Redirect(string.Format(AppSettings.Get<string>("WebReturnURL"), paypalDetails.Domain, "Can not proceed now, please try again.")); } var paymentExecution = new PaymentExecution { payer_id = payerId }; var payment = new Payment { id = paymentId }; var response = payment.Execute(this.Api, paymentExecution); if (response.state.ToLower() == "approved") { PaypalPaymentDetailsModel paymentDetail = new PaypalPaymentDetailsModel(); paymentDetail.TransactionId = paymentTransaction.Id; paymentDetail.PayerId = payerId; paymentDetail.Email = response.payer.payer_info.email; paymentDetail.FirstName = response.payer.payer_info.first_name; paymentDetail.LastName = response.payer.payer_info.last_name; paymentDetail.Address = response.payer.payer_info.shipping_address.line1 + " " + response.payer.payer_info.shipping_address.line2 + " " + response.payer.payer_info.shipping_address.state; paymentDetail.Status = response.payer.status; paymentDetail.IsComplete = true; paymentDetail.CreatedOn = DateTime.UtcNow; if (this.paymentService.CompletePaypalTransaction(paymentDetail)) { try { bool isSuccess = true; string crmContactId = this.youfferContactService.GetMappingEntryByContactId(paymentTransaction.ClientId).ContactCRMId; string crmLeadId = this.youfferContactService.GetMappingEntryByContactId(paymentTransaction.ClientId).LeadId; string crmOrgId = this.youfferContactService.GetOrgCRMId(paymentTransaction.CompanyId).CRMId; LeadModel leadModel = this.crmManagerService.GetLead(crmLeadId); decimal price = AppSettings.Get<decimal>(ConfigConstants.UserPrice); BuyUserModelDto buyUserModelDto = new BuyUserModelDto { CompanyId = paymentTransaction.CompanyId, UserId = paymentTransaction.ClientId, Interest = paymentTransaction.Need, Amount = price, PurchasedFromCash = false, PurchasedFromCredit = false }; isSuccess = this.crmManagerService.AddOpportunity(buyUserModelDto); ////return this.Redirect(string.Format(AppSettings.Get<string>("WebReturnURL"), "Payment Done")); return this.Redirect(string.Format(AppSettings.Get<string>("WebPaymentDone").ToString() + "?status=success", paypalDetails.Domain)); } catch (Exception ex) { this.LoggerService.LogException("PaymentController > G2SSuccess(while updating system for who purchased what): " + ex.StackTrace); } } } } catch (Exception ex) { this.LoggerService.LogException("PaypalConfirmed :- " + ex.Message); } ////return this.Redirect(string.Format(AppSettings.Get<string>("WebReturnURL"), "Payment Error found")); return this.Redirect(string.Format(AppSettings.Get<string>("WebPaymentDone").ToString() + "?status=error")); }
public async Task<IHttpActionResult> ReturnFrom2CO() { ////string companyId = User.Identity.GetUserId(); string companyId = HttpContext.Current.Request.Form["clientId"].ToString(); var success = HttpContext.Current.Request.Form["credit_card_processed"].ToString(); if (success.Equals("Y", StringComparison.InvariantCultureIgnoreCase)) { var guid = Guid.NewGuid(); bool result = this.paymentService.InsertPayPalTransaction(new PaypalPayTransactionModel { CreatedOn = DateTime.UtcNow, PaymentId = HttpContext.Current.Request.Form["order_number"].ToString(), PayToken = guid, IsPaymentDone = true, ClientId = HttpContext.Current.Request.Form["li_0_product_id"].ToString(), CompanyId = companyId, Need = HttpContext.Current.Request.Form["li_0_name"].ToString(), Amount = Convert.ToDecimal(HttpContext.Current.Request.Form["tPrice"]), IsPaypalTransaction = false }); if (result) { PaypalPayTransactionModel paymentTransaction = this.paymentService.GetPaypalPaymentId(guid, true); PaypalPaymentDetailsModel paymentDetail = new PaypalPaymentDetailsModel(); paymentDetail.TransactionId = paymentTransaction.Id; paymentDetail.PayerId = "2COpayer"; paymentDetail.Email = HttpContext.Current.Request.Form["email"].ToString(); paymentDetail.FirstName = HttpContext.Current.Request.Form["card_holder_name"].ToString(); paymentDetail.Address = HttpContext.Current.Request.Form["ship_street_address"].ToString() + " " + HttpContext.Current.Request.Form["ship_street_address2"].ToString() + " " + HttpContext.Current.Request.Form["ship_state"].ToString() + " " + HttpContext.Current.Request.Form["ship_city"].ToString() + " " + HttpContext.Current.Request.Form["ship_zip"].ToString() + " " + HttpContext.Current.Request.Form["ship_country"].ToString(); paymentDetail.Status = "SUCCESS"; paymentDetail.IsComplete = true; paymentDetail.CreatedOn = DateTime.UtcNow; if (this.paymentService.CompletePaypalTransaction(paymentDetail)) { try { bool isSuccess = true; BuyUserModelDto buyUserModelDto = new BuyUserModelDto { CompanyId = paymentTransaction.CompanyId, UserId = paymentTransaction.ClientId, Interest = paymentTransaction.Need, Amount = paymentTransaction.Amount, PurchasedFromCash = false, PurchasedFromCredit = false }; isSuccess = this.crmManagerService.AddOpportunity(buyUserModelDto); ////return this.Redirect(string.Format(AppSettings.Get<string>("WebReturnURL"), "Payment Done")); return this.Redirect(AppSettings.Get<string>("site_payment_url").ToString() + "?status=success"); } catch (Exception ex) { this.LoggerService.LogException("PaymentController > ReturnFrom2CO(while updating system after successfull payment): " + ex.StackTrace); } } } } return this.Redirect(AppSettings.Get<string>("site_payment_url").ToString() + "?status=error"); }
public async Task<IHttpActionResult> G2SSuccess() { G2SResponseModel response = new G2SResponseModel(); try { response = this.FillG2SResponse(Request.RequestUri.Query); try { this.UpdateInvoice(Convert.ToInt64(response.InvoiceId), InvoiceStatus.Success); } catch (Exception ex) { this.LoggerService.LogException("PaymentController > G2SSuccess(while updating invoice): " + ex.StackTrace); } this.paymentService.InsertG2SResponse(response); } catch (Exception ex) { this.LoggerService.LogException("PaymentController > G2SSuccess(while filling or inserting response): " + ex.StackTrace); response.UserId = HttpUtility.ParseQueryString(Request.RequestUri.Query).Get("customField1"); response.Interest = HttpUtility.ParseQueryString(Request.RequestUri.Query).Get("customField2"); response.CompanyId = HttpUtility.ParseQueryString(Request.RequestUri.Query).Get("customField3"); } try { bool isSuccess = true; decimal price = AppSettings.Get<decimal>(ConfigConstants.UserPrice); BuyUserModelDto buyUserModelDto = new BuyUserModelDto { CompanyId = response.CompanyId, UserId = response.UserId, Interest = response.Interest, Amount = price, PurchasedFromCash = false, PurchasedFromCredit = false }; isSuccess = this.crmManagerService.AddOpportunity(buyUserModelDto); } catch (Exception ex) { this.LoggerService.LogException("PaymentController > G2SSuccess(while updating system for who purchased what): " + ex.StackTrace); } return this.Redirect(AppSettings.Get<string>("site_payment_url").ToString() + "?status=success"); }