public override GNPurchaseOrder CreateOnSubmit(GNPurchaseOrder po) { po = base.CreateOnSubmit(po); if (po.Id == Guid.Empty) { po.Id = Guid.NewGuid(); } GNInvoice poInvoice = null; if (!string.IsNullOrEmpty(Request["invoiceId"])) { poInvoice = this.entityService.db.GNInvoices.Find(Guid.Parse(Request["invoiceId"])); po.PurchaseOrderInvoices.Add(new GNPurchaseOrderGNInvoice { Invoices_Id = poInvoice.Id, PurchaseOrders_Id = po.Id, TotalApplied = 0.0, CreatedBy = UserContact.Id, CreateDateTime = DateTime.Now }); po.GNAccountId = poInvoice.Account.Id; } return(po); }
public async Task <ActionResult> MakePayment(double paymentAmount) { double minPurchaseAmount = 0.0; var myProducts = this.db.GNProducts .Where(p => (p.AccountType.Id == UserContact.GNOrganization.Account.AccountType.Id && p.ProductType.Name != "STORAGE")); if (myProducts != null && myProducts.Count() != 0) { minPurchaseAmount = myProducts.Min(p => p.Price); } RedirectToRouteResult errorRedirectAction = RedirectToAction("MyBillingBuyCredits", "Account", new { paymentAmount = paymentAmount }); if (paymentAmount >= minPurchaseAmount) { InvoiceService invoiceService = new InvoiceService(this.db); GNInvoice invoice = await invoiceService.GetInvoiceForCurrentMonth(UserContact); string cancelUrl = Url.Action("MyBillingBuyCredits", "Account", new { paymentAmount = paymentAmount }, protocol: GetURLScheme()); return(await DoMakePayment(invoice, paymentAmount, cancelUrl, errorRedirectAction)); } else { errorRedirectAction.RouteValues["error"] = "Purchase Amount must be greater than or equal to $" + minPurchaseAmount; return(errorRedirectAction); } }
public override GNPurchaseOrder PopulateSelectLists(GNPurchaseOrder po = null) { po = base.PopulateSelectLists(po); if (po == null || po == default(GNPurchaseOrder)) { GNInvoice poInvoice = null; if (!string.IsNullOrEmpty(Request["invoiceId"])) { poInvoice = this.entityService.db.GNInvoices.Find(Guid.Parse(Request["invoiceId"])); } if (poInvoice != null) { po = new GNPurchaseOrder { StartDate = poInvoice.InvoiceStartDate, EndDate = poInvoice.InvoiceEndDate, Account = poInvoice.Account, GNAccountId = poInvoice.Account.Id }; } } else { po.Account = this.db.GNAccounts.Find(po.GNAccountId); } return(po); }
private async Task <int> CreateNewInvoices() { int result = 1; if (DateTime.Now.Day == DAY_TO_CREATE_INVOICES) { LogUtil.Info(logger, "CreateNewInvoices()..."); System.Console.WriteLine("\nCreateNewInvoices()..."); var db = new GNEntityModelContainer(); InvoiceService invoiceService = new InvoiceService(db); InvoiceDetailService invoiceDetailService = new InvoiceDetailService(db); TransactionService transactionService = new TransactionService(db); AccountService orgAccountService = new AccountService(db); foreach (var orgAccount in await orgAccountService.FindAll()) { try { LogUtil.Info(logger, "Account = " + orgAccount.Organization.Name); System.Console.WriteLine("\nAccount = " + orgAccount.Organization.Name); //get user contact GNContact userContact = orgAccount.AccountOwner; if (userContact == null) { userContact = db.GNContacts.Where(c => c.GNOrganizationId == orgAccount.Organization.Id).FirstOrDefault(); } if (userContact != null) { string thisCycle = String.Format("{0:yyyyMM}", DateTime.Now); GNInvoice newInvoiceMonth = invoiceService.GetInvoiceForDateTime(userContact, thisCycle); if (newInvoiceMonth == null) { newInvoiceMonth = await invoiceService.CreateInvoiceForCurrentMonth(userContact, orgAccount); } System.Console.WriteLine("\nInvoice for Cycle " + thisCycle + " for Organization " + orgAccount.Organization.Name + " is " + newInvoiceMonth.Id); LogUtil.Info(logger, "Invoice for Cycle " + thisCycle + " for Organization " + orgAccount.Organization.Name + " is " + newInvoiceMonth.Id); } } catch (Exception ex) { result = 0; LogUtil.Warn(logger, ex.Message, ex); System.Console.WriteLine(ex.Message); } } } return(result); }
// GET: PayPal/MakeInvoicePayment public async Task <ActionResult> MakeInvoicePayment(Guid invoiceId) { InvoiceService invoiceService = new InvoiceService(this.db); GNInvoice invoice = await invoiceService.Find(invoiceId); double paymentAmount = invoice.Balance; string cancelUrl = Url.Action("MyBillingBillDetail", "Account", new { id = invoice.Id }, protocol: GetURLScheme()); RedirectToRouteResult errorRedirectAction = RedirectToAction("MyBillingBillDetail", "Account", new { id = invoice.Id }); return(await DoMakePayment(invoice, paymentAmount, cancelUrl, errorRedirectAction)); }
public override string GetParentIdForEntityOnDelete(string id) { GNInvoice invoice = null; if (!string.IsNullOrEmpty(id)) { invoice = entityService.db.GNInvoiceDetails.Find(Guid.Parse(id)).Invoice; } if (invoice != null) { id = invoice.Id.ToString(); } return(id); }
private async Task <ActionResult> DoMakePayment(GNInvoice invoice, double paymentAmount, string cancelURL, RedirectToRouteResult errorRedirectAction) { SetExpressCheckoutResponseType ecResponse = null; try { CurrencyCodeType currencyUSD = (CurrencyCodeType)EnumUtils.GetValue("USD", typeof(CurrencyCodeType)); //define payment details List <PaymentDetailsType> paymentDetails = new List <PaymentDetailsType>() { new PaymentDetailsType { PaymentDetailsItem = new List <PaymentDetailsItemType>() { new PaymentDetailsItemType { Name = invoice.Name, Amount = new BasicAmountType(currencyUSD, Math.Round(paymentAmount, 2) + ""), Quantity = 1, ItemCategory = (ItemCategoryType)EnumUtils.GetValue("Physical", typeof(ItemCategoryType)) } }, PaymentAction = (PaymentActionCodeType)EnumUtils.GetValue("Sale", typeof(PaymentActionCodeType)), OrderTotal = new BasicAmountType(currencyUSD, (Math.Round(paymentAmount, 2) * 1) + "") } }; //define checkout request details SetExpressCheckoutReq expressCheckoutRequest = new SetExpressCheckoutReq() { SetExpressCheckoutRequest = new SetExpressCheckoutRequestType() { Version = "104.0", SetExpressCheckoutRequestDetails = new SetExpressCheckoutRequestDetailsType() { ReturnURL = Url.Action("PaymentSuccess", "PayPal", new { invoiceId = invoice.Id }, protocol: GetURLScheme()), CancelURL = cancelURL, PaymentDetails = paymentDetails } } }; //define sdk configuration Dictionary <string, string> sdkConfig = new Dictionary <string, string>(); sdkConfig.Add("mode", ConfigurationManager.AppSettings["paypal.mode"]); sdkConfig.Add("account1.apiUsername", ConfigurationManager.AppSettings["paypal.apiUsername"]); sdkConfig.Add("account1.apiPassword", ConfigurationManager.AppSettings["paypal.apiPassword"]); sdkConfig.Add("account1.apiSignature", ConfigurationManager.AppSettings["paypal.apiSignature"]); //instantiate PayPal API service and send Express Checkout Request PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService(sdkConfig); ecResponse = service.SetExpressCheckout(expressCheckoutRequest); } catch (Exception e) { LogUtil.Error(logger, "Error sending PayPal payment!!", e); } if (ecResponse != null && ecResponse.Ack.HasValue && ecResponse.Ack.Value.ToString() != "FAILURE" && ecResponse.Errors.Count == 0) { //redirect to PayPal if (ConfigurationManager.AppSettings["paypal.mode"] == "live") { string paypalURL = "https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=" + ecResponse.Token; return(RedirectPermanent(paypalURL)); } else { string paypalURL = "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=" + ecResponse.Token; return(RedirectPermanent(paypalURL)); } } else { errorRedirectAction.RouteValues["error"] = string.Join(",", ecResponse.Errors.Select(e => e.LongMessage).ToArray()); return(errorRedirectAction); } }
private async Task <int> ProcessStorageCarryOverFees() { int result = 1; if (DateTime.Now.Day == DAY_TO_PROCESS_STORAGE_CARRYOVER_FEES) { LogUtil.Info(logger, "ProcessStorageCarryOverFees()..."); System.Console.WriteLine("\nProcessStorageCarryOverFees()..."); var db = new GNEntityModelContainer(); InvoiceService invoiceService = new InvoiceService(db); InvoiceDetailService invoiceDetailService = new InvoiceDetailService(db); TransactionService transactionService = new TransactionService(db); AccountService orgAccountService = new AccountService(db); foreach (var orgAccount in await orgAccountService.FindAll()) { try { LogUtil.Info(logger, "Account = " + orgAccount.Organization.Name); System.Console.WriteLine("\nAccount = " + orgAccount.Organization.Name); //get user contact GNContact userContact = orgAccount.AccountOwner; if (userContact == null) { userContact = db.GNContacts.Where(c => c.GNOrganizationId == orgAccount.Organization.Id).FirstOrDefault(); } if (userContact != null) { //get last month invoice GNInvoice lastMonthInvoice = invoiceService.GetInvoiceForLastMonth(userContact); if (lastMonthInvoice != null) { string txnKey = "STORAGE_S3_CARRYOVER"; //get invoice to update GNInvoice invoiceToUpdate = null; if (lastMonthInvoice.Status != GNInvoice.InvoiceStatus.PAID.ToString() && lastMonthInvoice.Status != GNInvoice.InvoiceStatus.VOID.ToString()) { invoiceToUpdate = lastMonthInvoice; } else { invoiceToUpdate = await invoiceService.GetInvoiceForCurrentMonth(orgAccount.AccountOwner); } if (invoiceToUpdate != null) { //get storage carryover detail GNInvoiceDetail storageCarryOverInvoiceDetail = db.GNInvoiceDetails .Where(invd => (invd.GNInvoiceId == invoiceToUpdate.Id && invd.Description == txnKey)) .FirstOrDefault(); //add invoice detail, if missing if (storageCarryOverInvoiceDetail == null) { storageCarryOverInvoiceDetail = db.GNInvoiceDetails.Add(new GNInvoiceDetail { Id = Guid.NewGuid(), Description = txnKey, GNInvoiceId = invoiceToUpdate.Id, Quantity = 0.0, SubTotal = 0.0, DiscountAmount = orgAccount.DefaultDiscountAmount, DiscountType = orgAccount.DefaultDiscountType, Total = 0.0, UnitCost = 0.0, UnitPrice = 0.0, CreateDateTime = DateTime.Now, CreatedBy = orgAccount.AccountOwner.Id }); await db.SaveChangesAsync(); storageCarryOverInvoiceDetail = db.GNInvoiceDetails.Find(storageCarryOverInvoiceDetail.Id); } if (storageCarryOverInvoiceDetail != null) { //get txn count int txnCount = db.GNTransactions.Count(t => (t.GNInvoiceDetailId == storageCarryOverInvoiceDetail.Id && t.TransactionType.Name == txnKey)); if (txnCount == 0) { //get storage balance for month //all uploads minus all downloads up until end of last month var storageUsed = orgAccountService.CalcStorageUsed(orgAccount.Id, lastMonthInvoice.InvoiceEndDate.AddDays(1)); //get storage carryover product GNProduct storageCarryOverProduct = db.GNProducts.Where(p => p.Name == txnKey).FirstOrDefault(); //calc storage carryover cost var totalCarryOverCost = storageUsed * storageCarryOverProduct.Price; //add storage cost transaction string txnTypeKey = txnKey; string description = storageUsed + "GB"; double valueUsed = storageUsed; string valueUnits = "GB"; int updateResult = 0; GNTransaction txn = await transactionService.CreateTransaction( userContact, txnTypeKey, description, valueUsed, valueUnits, targetInvoice : invoiceToUpdate); if (txn != null) { updateResult = 1; } //update invoice totals //int updateResult = await invoiceDetailService.UpdateInvoiceDetailTotals( // invDetailToUpdate.Id, invDetailToUpdate.GNInvoiceId, invDetailToUpdate.Invoice.GNAccountId); LogUtil.Info(logger, "Update result = " + updateResult); System.Console.WriteLine("\nUpdate result = " + updateResult); } } } } } } catch (Exception ex) { result = 0; LogUtil.Warn(logger, ex.Message, ex); System.Console.WriteLine(ex.Message); } } } return(result); }