API Reference
Welcome to the Artcade API documentation! This guide explains all the ways your code can talk to the arcade system. Let's make it fun! ๐ฎ
API Overview ๐
Your arcade API has four main endpoints:
- Check if everything's working (
/status
) - Create payment QR codes (
/create-payment-link
) - Process payments (
/addCredit
) - Handle game endings (
/gameover
)
Think of it Like a Restaurant
/status
is like checking if the restaurant is open/create-payment-link
is like creating a menu QR code/addCredit
is like processing a payment at the register/gameover
is like clearing a table for the next customer
Base URL ๐
Your API will be available at:
Finding Your URL
You'll get your specific URL when you set up API Gateway in AWS. It will look similar to:
Endpoints ๐ฏ
Check Status
Checks if your API is running properly.
Response
Create Payment Link
Creates a QR code payment link for your arcade cabinet.
Request Body
{
"machine_id": "your-machine-id",
"price_id": "price_xxxxxxxxxxxxx", // Optional
"quantity": 1 // Optional
}
Parameters
machine_id
(required): Your unique arcade cabinet IDprice_id
(optional): Stripe price ID for custom pricingquantity
(optional): Number of credits to purchase
Response
Creating a Payment Link
Process Payment
Handles Stripe webhook notifications when a payment succeeds.
Webhook Security
This endpoint is called by Stripe with a special signature. Don't call it directly!
Headers
Stripe-Signature
: Special code from Stripe to verify the webhook
Webhook Event
{
"type": "checkout.session.completed",
"data": {
"object": {
"metadata": {
"machine_id": "arcade123"
},
"amount_total": 100
}
}
}
Response
200 OK
: Payment processed successfully400 Bad Request
: Invalid webhook500 Error
: Processing failed
Game Over
Signals that a game has ended.
Request Body
Response
Sending Game Over
MQTT Messages ๐จ
Your API publishes these MQTT messages:
Coin Pulse Signal
Sent when credits should be added:
Game Over Signal
Sent when a game ends:
Testing Tips ๐งช
Test Cards
Use these Stripe test cards:
- Success:
4242 4242 4242 4242
- Decline:
4000 0000 0000 0002
- Error:
4000 0000 0000 9995
Test Card Details
- Use any future expiry date
- Any 3-digit CVC
- Any 5-digit ZIP code
Using Stripe CLI
Test webhooks locally:
-
Start webhook forwarding:
-
Trigger test events:
Error Handling ๐ง
Your API returns standard HTTP status codes:
200
: Everything worked400
: Something wrong with the request401
: Not authorized404
: Endpoint not found500
: Server error
Error responses look like:
Rate Limits ๐
Free tier limits:
- AWS Lambda: 1,000,000 requests/month
- EMQX: 1 GB traffic/month
- Stripe: No monthly limits
Stay Within Limits
- Monitor your usage in AWS Console
- Watch EMQX dashboard
- Check Stripe dashboard
Security Best Practices ๐
-
Never share:
- API keys
- Webhook secrets
- MQTT credentials
- AWS credentials
-
Always use:
- HTTPS endpoints
- Webhook signatures
- SSL/TLS for MQTT
- Environment variables
Need Help? ๐ค
If you run into problems:
-
Check the logs:
- AWS CloudWatch
- EMQX Dashboard
- Stripe Dashboard
-
Common issues:
- Wrong API URL
- Invalid credentials
- Network problems
- Rate limiting
Still Stuck?
- Check our Troubleshooting Guide
- Ask your teacher or mentor
- Review error messages
- Try test endpoints first
Next Steps ๐
Now that you understand the API:
- Test the status endpoint
- Create a test payment
- Monitor the results
- Try the game over signal