Setup Bitcoin Lightning (Strike API)
Overview
Customer clicks Buy with Bitcoin
│
▼
POST /strike/checkout
│ creates a Strike invoice + Lightning quote
▼
Redirect to /strike/pay/<invoice_id>
│
▼
┌────────────────────────────────────┐
│ Customer scans QR code / pays │
│ the Lightning invoice in wallet │
└───────────────┬────────────────────┘
│
├──▶ Browser polls /api/strike-invoice-status
│ and /api/check-strike-access
│
└──▶ POST /strike/webhook (Strike server-to-server)
│
├─ Verify signature
├─ Fetch invoice state from Strike
├─ Create user (if new)
├─ Grant product access
Developer Mode Steps
-
Create a new account on Strike and complete the onboarding / business verification steps. (You can also use an individual account but you must use real money for your test payments - only needs to be a few cents.)
-
In your Strike Dashboard, create a new API key for your project.
-
Select all the key scopes for Receiving payments and the permission under Webhook subscriptions.
-
Add your Strike API key to your local
.envfile underSTRIKE_API_KEY. -
Make sure your product is active in your database / admin area and has a valid
price_centsvalue, because Strike invoices are generated dynamically from the product record in this starter kit. -
If your product currency is
USD, this project will automatically convert the amount to the currency your Strike account uses. If your product uses another currency, that currency is sent to Strike as-is, so make sure it matches a currency your Strike account can invoice in. -
Start your Flask app locally as normal. In this project the local payment flow assumes the app is running on
localhost:5001.
Create the Strike Webhook in Developer Mode
This project comes with all the code necessary to ensure you will have a robust Strike webhook up-and-running fast. This is very important to ensure that the customer's payment has been completed successfully. But there are a few setup steps you still need to do.
First, create a WEBHOOK_SECRET which is an arbitrary string of alphanumeric characters - must be 50 characters maximum.
You can create this string with:
python -c "import secrets; print(secrets.token_hex(32))"
Then trim it to make sure its 50 characters or less and add WEBHOOK_SECRET to your .env file.
Now we need a public HTTPS URL that forwards to our local Flask app, because Strike cannot send webhooks directly to localhost.
The easiest way to do this is with ngrok: https://dashboard.ngrok.com/
In your dashboard side bar, under Universal Gateay, go to the domains section and create a new dev domain. (Ngrok provides one dev domain for free).
Next, we need to register this test domain with Strike.
In your project directory, go to the Flask shell with: flask shell.
Enter the following commands to complete the webhook registration process:
STRIKE_API_KEY = "your_api_key_here"
WEBHOOK_URL = "https://your-domain.ngrok-free.dev/strike/webhook"
WEBHOOK_SECRET = "your_50_char_secret_here"
response = requests.post("https://api.strike.me/v1/subscriptions", headers={"Authorization": f"Bearer
{STRIKE_API_KEY}", "Content-Type": "application/json"}, json={"webhookVersion": "v1", "url":
WEBHOOK_URL, "secret": WEBHOOK_SECRET, "enabled": True, "eventTypes": ["invoice.updated"]})
print(response.status_code, response.json())
Lastly ensure that the ngrok webhook tunnel is running with this command:
ngrok http --url=dust-hermit-persuaded.ngrok-free.dev 5001
Now you are ready to make test payments to test out your new Bitcoin Lightning payments flow!
Production Mode Steps
-
In your Render dashboard, add
STRIKE_API_KEYto the environment variables section using your production Strike API key. -
In your Render dashboard, add
STRIKE_WEBHOOK_SECRETto the environment variables section. -
Go to the Render shell area. Enter the same subscription commands you used in your local development environment.
BUT with the important difference: use your live domain instead of the ngrok test one. So in the case of PythonStarter it would be: https://pythonstarter.co/strike/webhook but make sure you use your own domain!
STRIKE_API_KEY = "your_api_key_here"
WEBHOOK_URL = "https://your-real-production-domain.co/strike/webhook"
WEBHOOK_SECRET = "your_50_char_secret_here"
response = requests.post("https://api.strike.me/v1/subscriptions", headers={"Authorization": f"Bearer
{STRIKE_API_KEY}", "Content-Type": "application/json"}, json={"webhookVersion": "v1", "url":
WEBHOOK_URL, "secret": WEBHOOK_SECRET, "enabled": True, "eventTypes": ["invoice.updated"]})
print(response.status_code, response.json())
If you want to be 100% sure you can also make test payments in your production environment. But if you are making real payments, make sure your change the amount in your Flask product admin area to only be a few cents.
Optional: if you want to keep local testing and production payments fully separate, use different Strike accounts or API keys for each environment. This project uses the same env var names in both places, so the separation is handled by where you store the values: local .env vs Render environment variables.