Building and Testing Your System ๐ ๏ธ
Now that you understand how the code works, let's get it running on your computer and test everything! We'll build and test locally first, then handle containerization and deployment in the next section.
Prerequisites โ
Before starting, make sure you have:
- All accounts set up (AWS, Stripe, EMQX)
- Python 3.9 or higher installed
- Visual Studio Code (VSCode) installed
- Git installed
- Your code cloned from GitHub
Quick Check
Run these commands in your terminal to verify your setup:
Part 1: Setting Up Your Development Environment ๐ป
1. Create Your Environment File
-
In your project folder, create a new file called
.env.local
: -
Add your configuration (replace with your actual values):
Keep It Secret!
Never commit your .env.local
file to Git! It should already be in .gitignore
.
2. Set Up Your Python Virtual Environment
Create and activate a virtual environment (open termninal in vs code):
Install dependencies:
Part 2: Testing Your System ๐งช
Let's test each component to make sure everything works!
1. Test Local API
-
Start the Flask application (you paste this into terminal and run the command):
-
In a new terminal, test the status endpoint:
You should see:
2. Test MQTT Connection ๐ก
- Install the Mosquitto MQTT client:
-
Subscribe to test messages:
-
Keep this terminal open to watch for messages!
3. Test Stripe Integration ๐ณ
- Install the Stripe CLI:
-
Login to Stripe CLI:
-
Forward webhooks to your local app:
-
Test payment flow:
a. Create a payment link by running this command:
curl -X POST http://localhost:5000/create-payment-link \ -H "Content-Type: application/json" \ -d '{"machine_id":"test123"}'
You'll get back a response that looks like this:
What is a Payment Link?
A Stripe Payment Link is a hosted payment page that lets customers securely make payments. On your arcade cabinet, players will scan a QR code that leads to this page. Learn more about Stripe Payment Links.
b. Copy the URL from the response and paste it into your web browser. You'll see Stripe's payment page, just like your arcade players will see when they scan the QR code!
c. Complete the test payment using these card details:
- Card number:
4242 4242 4242 4242
- Expiry: Any future date
- CVC: Any 3 digits
- ZIP: Any 5 digits
Test Cards
The
4242 4242 4242 4242
card number is a special test card that Stripe provides. It will always work in test mode but won't work in production. Perfect for testing! - Card number:
4. Verify Full Flow ๐
Time to test everything together! You'll need three terminal windows:
Now let's test the complete flow:
-
Create and use a payment link:
-
Complete the test payment in your browser
-
Watch Terminal 2 for the MQTT coinpulse message
-
Send a game over signal:
-
Watch Terminal 2 for the MQTT game over message
Troubleshooting Common Issues ๐ง
API Issues
- Can't start Flask: Check if port 5000 is already in use
- Environment variables: Make sure
.env.local
is in the right place - Import errors: Verify virtual environment is activated
MQTT Issues
- Connection refused: Check broker address and port
- Authentication failed: Verify username and password
- SSL/TLS errors: Make sure you have the correct CA certificate
Stripe Issues
- Invalid API key: Check your test API key in
.env.local
- Webhook errors: Ensure webhook forwarding is running
- Payment fails: Verify you're using the correct test card
Success Criteria โจ
Your local setup is working when you can:
- โ Get a successful response from the status endpoint
- โ Create a payment link
- โ Complete a test payment
- โ See the coinpulse MQTT message
- โ Send a game over signal
- โ See the game over MQTT message
Ready for Deployment!
Once you've verified all these steps, your system is working correctly and you're ready to move on to containerization and deployment!
Next Steps ๐
Once everything is tested and working:
- Save any test outputs you want to keep
- Stop all your test processes (Flask, Stripe CLI, MQTT subscriber)
- Make sure your changes are committed to Git
- Move on to the deployment section where we'll containerize and deploy your working code!