There are several reasons why you’d like to get your Merchant Code in Stripe, one of them being able to be eligible for HSA/FSA payments in the future if the MCC is 8099, which is a task your boss most probably assigned to you (as mine did). I’ll provide a step by step guide on how you can do this for your business (easy to follow and you’re no developer) or someone else’s (if you’re the dev).
If you want to know more about MCC, go here. It gets you relevant information on the MCC, although it is more helpful for your bosses or the business owner than to yourself.
You can find Stripe docs here and here.
First, get your Stripe Secret Key
Go to your API dashboard here. You should see something like this:
To be able to pull up the secret key, you will need to get the MFA code and validate your account through email as well, so make sure you can access those with your system administrator before you do this.
Then, save the key somewhere secure.
Step 2: Install the necessary packages
Packages
- Stripe
- dotenv
You can avoid the terminal installation below if you’re using an IDE like PyCharm that already handles the packages, just go to Settings → Project → Python interpreter and add these above. That’s it. Or just write the code and wait for the IDE to prompt the installation (the laziest way).
Installing Stripe
On the terminal, use these:
MacOS:
Brew install stripe
If you don’t have brew, install it here.
Windows:
pip install stripe
Linux:
pip3 install stripe
Or whatever package in Linux you use to install package.
Installing dotenv
This is an easy one, just do:
pip3 install python-dotenv
Or just install the package within PyCharm or any IDE you use like shown in the picture above.
Step 3: Access your MCC
If you’re the owner of the business and you want simplicity, follow the following: in order to see your MCC you just need to call your Secret API Key directly.
Be cautious that this is bad practice in a real dev environment and they won't encourage you to do that.
Use this code to access it:
import stripe
stripe.api_key = "sk_live_your_secret_key_here"
account = stripe.Account.retrieve()
print("Your MCC is:", account.business_profile["mcc"])
You will get the following output:
Best practice
In a real world scenario, you must store the secret key in an .env file or within AWS Secrets Manager (and retrieve it however you need, probably Lambda). I’ll show you how to do this using the .env file
- Create the .env file and that’s gonna be it, no other name after or before it, just .env
Use it like this, with no spaces in between:
STRIPE_SECRET_KEY=sk_live_secret_key
Save it in the same folder your .py file is
Then run this code in your IDE:
import os
from dotenv import load_dotenv
import stripe
#load environment variables from the .env file
load_dotenv()
#this retrieves the API key from the environment
stripe.api_key = os.getenv("STRIPE_SECRET_KEY") #don't change this for god's sake
#get your MCC right away
account = stripe.Account.retrieve()
print("Your MCC is:", account.business_profile["mcc"])
And there it it folks, your MCC will be shown just like the previous output screenshot.
Now, this is just basic level programming, your tech environment may treat it differently, but this code is the foundation of it. :)
Top comments (0)