Fixed payment namespacing
This commit is contained in:
@@ -1,12 +1,7 @@
|
|||||||
using Microsoft.AspNetCore.Cors;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using MistoxWebsite.Server.Controllers.Payment;
|
using MistoxWebsite.Server.Controllers.Payment;
|
||||||
using MistoxWebsite.Server.Services.DatabaseService;
|
using MistoxWebsite.Server.Services.DatabaseService;
|
||||||
using MistoxWebsite.Shared;
|
using MistoxWebsite.Server.Entities;
|
||||||
using Newtonsoft.Json;
|
|
||||||
using Stripe;
|
|
||||||
using Stripe.Climate;
|
|
||||||
using Stripe.Tax;
|
|
||||||
|
|
||||||
namespace MistoxWebsite.Server.Controllers {
|
namespace MistoxWebsite.Server.Controllers {
|
||||||
[ApiController]
|
[ApiController]
|
||||||
@@ -24,7 +19,7 @@ namespace MistoxWebsite.Server.Controllers {
|
|||||||
public async Task<string> GetPaymentKey( [FromQuery] string userID ) {
|
public async Task<string> GetPaymentKey( [FromQuery] string userID ) {
|
||||||
|
|
||||||
string OrderNumber = Guid.NewGuid().ToString().Substring(0,10);
|
string OrderNumber = Guid.NewGuid().ToString().Substring(0,10);
|
||||||
Shared.Account? acc = await _databaseService.GetAccount(userID);
|
Account? acc = await _databaseService.GetAccount(userID);
|
||||||
if (acc != null) {
|
if (acc != null) {
|
||||||
List<Cart> cart = await _databaseService.GetCart(acc);
|
List<Cart> cart = await _databaseService.GetCart(acc);
|
||||||
|
|
||||||
@@ -51,11 +46,11 @@ namespace MistoxWebsite.Server.Controllers {
|
|||||||
try {
|
try {
|
||||||
const string endpointSecret = "whsec_HCO7uv2BPIPmUPOiSg9tfwLZul8usCGG";
|
const string endpointSecret = "whsec_HCO7uv2BPIPmUPOiSg9tfwLZul8usCGG";
|
||||||
string body = await new StreamReader(Request.Body).ReadToEndAsync();
|
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" ) {
|
if( e.Type == "payment_intent.succeeded" ) {
|
||||||
|
|
||||||
// Extract Data from payment confirm
|
// Extract Data from payment confirm
|
||||||
PaymentIntent intent = (PaymentIntent)e.Data.Object;
|
Stripe.PaymentIntent intent = (Stripe.PaymentIntent)e.Data.Object;
|
||||||
string orderNumber = "";
|
string orderNumber = "";
|
||||||
int userID = 0;
|
int userID = 0;
|
||||||
List<int> productIDs = new List<int>();
|
List<int> productIDs = new List<int>();
|
||||||
@@ -84,7 +79,7 @@ namespace MistoxWebsite.Server.Controllers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Clear the cart
|
// Clear the cart
|
||||||
Shared.Account account = new Shared.Account{
|
Account account = new() {
|
||||||
ID = userID
|
ID = userID
|
||||||
};
|
};
|
||||||
await _databaseService.ClearCart( account );
|
await _databaseService.ClearCart( account );
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using MistoxWebsite.Shared;
|
using MistoxWebsite.Server.Entities;
|
||||||
|
|
||||||
namespace MistoxWebsite.Server.Controllers.Payment {
|
namespace MistoxWebsite.Server.Controllers.Payment {
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,6 @@
|
|||||||
using System;
|
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using MistoxWebsite.Server.Controllers.Payment;
|
using MistoxWebsite.Server.Controllers.Payment;
|
||||||
using MistoxWebsite.Server.Services.DatabaseService;
|
using MistoxWebsite.Server.Services.DatabaseService;
|
||||||
using MistoxWebsite.Shared;
|
using MistoxWebsite.Server.Entities;
|
||||||
using Stripe;
|
|
||||||
using Stripe.Tax;
|
|
||||||
|
|
||||||
namespace MistoxWebsite.Server.Controllers {
|
namespace MistoxWebsite.Server.Controllers {
|
||||||
|
|
||||||
@@ -17,16 +12,16 @@ namespace MistoxWebsite.Server.Controllers {
|
|||||||
_databaseService = databaseService;
|
_databaseService = databaseService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<(bool, string)> Purchase(string OrderNumber, Shared.Account user, List<Cart> cart) {
|
public async Task<(bool, string)> Purchase(string OrderNumber, Account user, List<Cart> cart) {
|
||||||
try {
|
try {
|
||||||
// build Recipt and calculate Tax
|
// build Recipt and calculate Tax
|
||||||
var options = new CalculationCreateOptions {
|
var options = new Stripe.Tax.CalculationCreateOptions {
|
||||||
Currency = "usd",
|
Currency = "usd",
|
||||||
CustomerDetails = new CalculationCustomerDetailsOptions {
|
CustomerDetails = new Stripe.Tax.CalculationCustomerDetailsOptions {
|
||||||
AddressSource = "billing",
|
AddressSource = "billing",
|
||||||
},
|
},
|
||||||
Expand = new List<string>() { "line_items" },
|
Expand = new List<string>() { "line_items" },
|
||||||
LineItems = new List<CalculationLineItemOptions>()
|
LineItems = new List<Stripe.Tax.CalculationLineItemOptions>()
|
||||||
};
|
};
|
||||||
|
|
||||||
List<int> prods = new List<int>();
|
List<int> prods = new List<int>();
|
||||||
@@ -34,12 +29,12 @@ namespace MistoxWebsite.Server.Controllers {
|
|||||||
// Add items to receipt
|
// Add items to receipt
|
||||||
int subtotal = 0;
|
int subtotal = 0;
|
||||||
foreach (Cart items in cart) {
|
foreach (Cart items in cart) {
|
||||||
Shared.Product? product = await _databaseService.GetProduct(items.ProductID);
|
Product? product = await _databaseService.GetProduct(items.ProductID);
|
||||||
if (product != null) {
|
if (product != null) {
|
||||||
prods.Add(product.ID);
|
prods.Add(product.ID);
|
||||||
if (product != null) {
|
if (product != null) {
|
||||||
subtotal += product.Cost;
|
subtotal += product.Cost;
|
||||||
options.LineItems.Add(new CalculationLineItemOptions {
|
options.LineItems.Add(new Stripe.Tax.CalculationLineItemOptions {
|
||||||
Amount = product.Cost,
|
Amount = product.Cost,
|
||||||
TaxCode = "txcd_10201000", // Tax code for downloadable digital games
|
TaxCode = "txcd_10201000", // Tax code for downloadable digital games
|
||||||
Quantity = 1,
|
Quantity = 1,
|
||||||
@@ -51,8 +46,8 @@ namespace MistoxWebsite.Server.Controllers {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var service = new CalculationService();
|
var service = new Stripe.Tax.CalculationService();
|
||||||
Calculation result = service.Create(options);
|
Stripe.Tax.Calculation result = service.Create(options);
|
||||||
|
|
||||||
string csv = "";
|
string csv = "";
|
||||||
foreach (int cur in prods) {
|
foreach (int cur in prods) {
|
||||||
@@ -60,7 +55,7 @@ namespace MistoxWebsite.Server.Controllers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Crate Payment Intent
|
// Crate Payment Intent
|
||||||
PaymentIntentCreateOptions paymentIntent = new PaymentIntentCreateOptions() {
|
Stripe.PaymentIntentCreateOptions paymentIntent = new Stripe.PaymentIntentCreateOptions() {
|
||||||
Amount = result.AmountTotal,
|
Amount = result.AmountTotal,
|
||||||
Currency = "usd",
|
Currency = "usd",
|
||||||
Metadata = new Dictionary<string, string> {
|
Metadata = new Dictionary<string, string> {
|
||||||
@@ -73,8 +68,8 @@ namespace MistoxWebsite.Server.Controllers {
|
|||||||
StatementDescriptor = "Mistox.Net #" + OrderNumber
|
StatementDescriptor = "Mistox.Net #" + OrderNumber
|
||||||
};
|
};
|
||||||
|
|
||||||
PaymentIntentService intentService = new PaymentIntentService();
|
Stripe.PaymentIntentService intentService = new Stripe.PaymentIntentService();
|
||||||
PaymentIntent x = await intentService.CreateAsync(paymentIntent);
|
Stripe.PaymentIntent x = await intentService.CreateAsync(paymentIntent);
|
||||||
|
|
||||||
return (true, x.ClientSecret);
|
return (true, x.ClientSecret);
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using MistoxWebsite.Server.Services.DatabaseService;
|
using MistoxWebsite.Server.Services.DatabaseService;
|
||||||
using MistoxWebsite.Shared;
|
using MistoxWebsite.Server.Entities;
|
||||||
using Newtonsoft.Json;
|
|
||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace MistoxWebsite.Server.Controllers {
|
namespace MistoxWebsite.Server.Controllers {
|
||||||
[ApiController]
|
[ApiController]
|
||||||
@@ -128,74 +126,6 @@ namespace MistoxWebsite.Server.Controllers {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DirObj RecursiveBuild( DirObj DirObj, string workingPath, List<ReceiptProduct> purchased ) {
|
|
||||||
|
|
||||||
string[] files = Directory.GetFiles(workingPath);
|
|
||||||
string[] directories = Directory.GetDirectories(workingPath);
|
|
||||||
|
|
||||||
List<DirObj> building = new List<DirObj>();
|
|
||||||
|
|
||||||
// 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<IActionResult> ShowDownloads() {
|
|
||||||
try {
|
|
||||||
if( User.Identity != null && User.Identity.IsAuthenticated ) {
|
|
||||||
|
|
||||||
List<Claim> userClaims = User.Claims.ToList();
|
|
||||||
int UserID = -1;
|
|
||||||
foreach( Claim claim in userClaims ) {
|
|
||||||
if( claim.Type == "ID" ) {
|
|
||||||
UserID = Convert.ToInt32( claim.Value );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
List<ReceiptProduct> 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 ) {
|
bool contains( string outer, string inner ) {
|
||||||
if ( outer.Length >= inner.Length ) {
|
if ( outer.Length >= inner.Length ) {
|
||||||
for ( int i=0; i<outer.Length-inner.Length; i++ ) {
|
for ( int i=0; i<outer.Length-inner.Length; i++ ) {
|
||||||
@@ -221,10 +151,10 @@ namespace MistoxWebsite.Server.Controllers {
|
|||||||
if ( contains( Product, product.URL ) ) {
|
if ( contains( Product, product.URL ) ) {
|
||||||
Receipt? receipt = await _databaseService.GetReceipt(user, product);
|
Receipt? receipt = await _databaseService.GetReceipt(user, product);
|
||||||
if( receipt != null ) {
|
if( receipt != null ) {
|
||||||
FileStream fileStream = new FileStream(_FolderRoot + Product, FileMode.Open, FileAccess.Read);
|
//FileStream fileStream = new FileStream(_FolderRoot + Product, FileMode.Open, FileAccess.Read);
|
||||||
return new FileStreamResult( fileStream, "application/octet-stream" ) {
|
//return new FileStreamResult( fileStream, "application/octet-stream" ) {
|
||||||
FileDownloadName = fileStream.Name
|
// FileDownloadName = fileStream.Name
|
||||||
};
|
//};
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user