catrina
Posted on April 5, 2018
This year I am re-writing my previous payment solution (from PHP to .NET) and first on the project list is credit cards. We are using PayTrace and their client-side encryption as to not have to worry about PCI Compliance.
File Not Found
I'd gotten to the point where I had:
- a Pre-Payment model with all the fields needed to send via JSON
- method to request a token for sending (uses demo username and pass)
- a JS file to help scan credit cards using a USB device
- a test PEM file I downloaded from the PayTrace site
- PayTrace's third party JS library to encrypt card information and attach on form post
I load it all, scan card, hit submit, and I get this:
XML Parsing Error: no element found
This is appearing in the console of Inspector in Firefox. Turns out this a generic error Firefox throws out when it’s expecting a file but gets nothing.
My path’s are correct, but the “public_key.pem” file is not attaching to my post. The problem? MIME-type.
Making It Work
First, in Startup.cs, I needed to do this to add the MIME-type:
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
var provider = new FileExtensionContentTypeProvider();
provider.Mappings[".pem"] = "application/x-pem-file";
in the same function add this:
app.UseStaticFiles(); // For the wwwroot folder
app.UseStaticFiles(new StaticFileOptions()
{
FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot", "api-keys")),
RequestPath = new PathString("/api-keys"),
ContentTypeProvider = provider
});
Do NOT forget app.UseStaticFiles(); for your general wwwroot folder.
I dropped public_keys.pem in “api-keys” and done!
There seems something a bit off in this, so please correct me if you find it, but it's working for now!
Posted on April 5, 2018
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.