diff --git a/src/MistoxWebsite.Server/Controllers/PaymentController.cs b/src/MistoxWebsite.Server/Controllers/PaymentController.cs index ba348c1..de9fe5f 100755 --- a/src/MistoxWebsite.Server/Controllers/PaymentController.cs +++ b/src/MistoxWebsite.Server/Controllers/PaymentController.cs @@ -1,12 +1,7 @@ -using Microsoft.AspNetCore.Cors; -using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc; using MistoxWebsite.Server.Controllers.Payment; using MistoxWebsite.Server.Services.DatabaseService; -using MistoxWebsite.Shared; -using Newtonsoft.Json; -using Stripe; -using Stripe.Climate; -using Stripe.Tax; +using MistoxWebsite.Server.Entities; namespace MistoxWebsite.Server.Controllers { [ApiController] @@ -24,7 +19,7 @@ namespace MistoxWebsite.Server.Controllers { public async Task GetPaymentKey( [FromQuery] string userID ) { string OrderNumber = Guid.NewGuid().ToString().Substring(0,10); - Shared.Account? acc = await _databaseService.GetAccount(userID); + Account? acc = await _databaseService.GetAccount(userID); if (acc != null) { List cart = await _databaseService.GetCart(acc); @@ -51,11 +46,11 @@ namespace MistoxWebsite.Server.Controllers { try { const string endpointSecret = "whsec_HCO7uv2BPIPmUPOiSg9tfwLZul8usCGG"; string body = await new StreamReader(Request.Body).ReadToEndAsync(); - Event e = EventUtility.ConstructEvent( body, Request.Headers["Stripe-Signature"], endpointSecret ); + Stripe.Event e = Stripe.EventUtility.ConstructEvent( body, Request.Headers["Stripe-Signature"], endpointSecret ); if( e.Type == "payment_intent.succeeded" ) { // Extract Data from payment confirm - PaymentIntent intent = (PaymentIntent)e.Data.Object; + Stripe.PaymentIntent intent = (Stripe.PaymentIntent)e.Data.Object; string orderNumber = ""; int userID = 0; List productIDs = new List(); @@ -84,7 +79,7 @@ namespace MistoxWebsite.Server.Controllers { } // Clear the cart - Shared.Account account = new Shared.Account{ + Account account = new() { ID = userID }; await _databaseService.ClearCart( account ); diff --git a/src/MistoxWebsite.Server/Controllers/PaymentMethods/IPayment.cs b/src/MistoxWebsite.Server/Controllers/PaymentMethods/IPayment.cs index b36973a..bcc9ec5 100644 --- a/src/MistoxWebsite.Server/Controllers/PaymentMethods/IPayment.cs +++ b/src/MistoxWebsite.Server/Controllers/PaymentMethods/IPayment.cs @@ -1,4 +1,4 @@ -using MistoxWebsite.Shared; +using MistoxWebsite.Server.Entities; namespace MistoxWebsite.Server.Controllers.Payment { diff --git a/src/MistoxWebsite.Server/Controllers/PaymentMethods/StripeIntents.cs b/src/MistoxWebsite.Server/Controllers/PaymentMethods/StripeIntents.cs index ee7f0f0..45aae9c 100644 --- a/src/MistoxWebsite.Server/Controllers/PaymentMethods/StripeIntents.cs +++ b/src/MistoxWebsite.Server/Controllers/PaymentMethods/StripeIntents.cs @@ -1,11 +1,6 @@ -using System; -using System.Collections; -using System.Collections.Generic; using MistoxWebsite.Server.Controllers.Payment; using MistoxWebsite.Server.Services.DatabaseService; -using MistoxWebsite.Shared; -using Stripe; -using Stripe.Tax; +using MistoxWebsite.Server.Entities; namespace MistoxWebsite.Server.Controllers { @@ -17,16 +12,16 @@ namespace MistoxWebsite.Server.Controllers { _databaseService = databaseService; } - public async Task<(bool, string)> Purchase(string OrderNumber, Shared.Account user, List cart) { + public async Task<(bool, string)> Purchase(string OrderNumber, Account user, List cart) { try { // build Recipt and calculate Tax - var options = new CalculationCreateOptions { + var options = new Stripe.Tax.CalculationCreateOptions { Currency = "usd", - CustomerDetails = new CalculationCustomerDetailsOptions { + CustomerDetails = new Stripe.Tax.CalculationCustomerDetailsOptions { AddressSource = "billing", }, Expand = new List() { "line_items" }, - LineItems = new List() + LineItems = new List() }; List prods = new List(); @@ -34,12 +29,12 @@ namespace MistoxWebsite.Server.Controllers { // Add items to receipt int subtotal = 0; foreach (Cart items in cart) { - Shared.Product? product = await _databaseService.GetProduct(items.ProductID); + Product? product = await _databaseService.GetProduct(items.ProductID); if (product != null) { prods.Add(product.ID); if (product != null) { subtotal += product.Cost; - options.LineItems.Add(new CalculationLineItemOptions { + options.LineItems.Add(new Stripe.Tax.CalculationLineItemOptions { Amount = product.Cost, TaxCode = "txcd_10201000", // Tax code for downloadable digital games Quantity = 1, @@ -51,8 +46,8 @@ namespace MistoxWebsite.Server.Controllers { } - var service = new CalculationService(); - Calculation result = service.Create(options); + var service = new Stripe.Tax.CalculationService(); + Stripe.Tax.Calculation result = service.Create(options); string csv = ""; foreach (int cur in prods) { @@ -60,7 +55,7 @@ namespace MistoxWebsite.Server.Controllers { } // Crate Payment Intent - PaymentIntentCreateOptions paymentIntent = new PaymentIntentCreateOptions() { + Stripe.PaymentIntentCreateOptions paymentIntent = new Stripe.PaymentIntentCreateOptions() { Amount = result.AmountTotal, Currency = "usd", Metadata = new Dictionary { @@ -73,8 +68,8 @@ namespace MistoxWebsite.Server.Controllers { StatementDescriptor = "Mistox.Net #" + OrderNumber }; - PaymentIntentService intentService = new PaymentIntentService(); - PaymentIntent x = await intentService.CreateAsync(paymentIntent); + Stripe.PaymentIntentService intentService = new Stripe.PaymentIntentService(); + Stripe.PaymentIntent x = await intentService.CreateAsync(paymentIntent); return (true, x.ClientSecret); } catch(Exception e) { diff --git a/src/MistoxWebsite.Server/Controllers/ProductController.cs b/src/MistoxWebsite.Server/Controllers/ProductController.cs index ff4d27a..a4d191f 100755 --- a/src/MistoxWebsite.Server/Controllers/ProductController.cs +++ b/src/MistoxWebsite.Server/Controllers/ProductController.cs @@ -1,9 +1,7 @@ using Microsoft.AspNetCore.Mvc; using MistoxWebsite.Server.Services.DatabaseService; -using MistoxWebsite.Shared; -using Newtonsoft.Json; +using MistoxWebsite.Server.Entities; using System.Security.Claims; -using System.Text; namespace MistoxWebsite.Server.Controllers { [ApiController] @@ -128,74 +126,6 @@ namespace MistoxWebsite.Server.Controllers { } } - DirObj RecursiveBuild( DirObj DirObj, string workingPath, List purchased ) { - - string[] files = Directory.GetFiles(workingPath); - string[] directories = Directory.GetDirectories(workingPath); - - List building = new List(); - - // Get File Names - Parallel.For( 0, files.Length, ( i ) => { - string fileName = files[i].Substring(workingPath.Length, files[i].Length - (workingPath.Length)); - building.Add( new DirObj { - Type = FileType.File, - Path = fileName - }); - } ); - - // Get Path Names - Parallel.For( 0, directories.Length, ( i ) => { - foreach( ReceiptProduct cur in purchased ) { - string dirName = directories[i].Substring(workingPath.Length, directories[i].Length - (workingPath.Length)); - if( contains( dirName, cur.product.URL ) ) { - DirObj dir = new DirObj { - Type = FileType.Directory, - Path = dirName, - }; - building.Add( dir ); - RecursiveBuild( dir, directories [i], purchased ); - } - } - } ); - - DirObj.Children = building.ToArray(); - - return DirObj; - } - - string _FolderRoot = "/home/downloads/"; - - [Route( "api/product/showdownloads" )] - [HttpPost] - public async Task ShowDownloads() { - try { - if( User.Identity != null && User.Identity.IsAuthenticated ) { - - List userClaims = User.Claims.ToList(); - int UserID = -1; - foreach( Claim claim in userClaims ) { - if( claim.Type == "ID" ) { - UserID = Convert.ToInt32( claim.Value ); - break; - } - } - - List purchased = await _databaseService.GetAllReceiptsJoinedToProduct( new Account{ ID = UserID } ); - - byte[] datapacket = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(RecursiveBuild(new DirObj { - Path = @"\", - Type = FileType.Directory, - }, _FolderRoot, purchased))); - - return new FileContentResult( datapacket, "text/html" ); - } - return Unauthorized(); - } catch { - return NotFound(); - } - } - bool contains( string outer, string inner ) { if ( outer.Length >= inner.Length ) { for ( int i=0; i