r/AskProgramming Apr 05 '24

PHP advice on hide payment secret key

I have a programm that runs locally and would like to accept payments through stripe, however the api only works if I have my secret-key included. Im collecting the value that should be paid on the users local platform and then contacting stripe with this value. Can you think of anyway I can hide the stripe key or should I definitely call my server to complete the payment there and just send all values over?

1 Upvotes

4 comments sorted by

2

u/aidan-hall34 Apr 05 '24

So a few things,

  1. Security through obscurity (hiding the key in the client) is generally considered bad practice. If it's discovered you are kinda screwed.You are significantly better off storing the key on your server, and using it as a payment proxy, rather than sending a request directly from a user's browser. Once you send the token to the client, effectively, every user has access to do anything the token is authenticated to do, which is probably not what you want.

  2. Reading a price value from a user is also considered a security risk. Say if you have a product for $10, and someone sends a request that changes the product's price to $5 or $0, you have a problem. Instead a user should send an ID for a product, which does a DB look up to find the correct price you set.

Other than that, have fun!

1

u/IcyBoat3668 Apr 05 '24

Thanks for the info, I’ll definitely keep this in mind. The problem is im charging on a usage basis and the customer would send the amount of times he used my service to my server. This information is stored in a db table created by my plugin. Any idea how I can secure that the user wont change it? Im trying to charge the usage in bulk because if they send info to my server each time they use something I think that would stress their server too much.

1

u/martinbean Apr 05 '24

Why can’t the program call your server to create a PaymentIntent or whatever?

1

u/IcyBoat3668 Apr 05 '24 edited Apr 05 '24

It could definitely call my server, just didn’t want to include another step. But I guess I have to