Skip to content

Commit 82d4e57

Browse files
committed
Merge branch '1464-remove--migrate-away-from-legacy-connect-account-types'
2 parents 5cfa2e2 + 4191b3f commit 82d4e57

13 files changed

Lines changed: 523 additions & 16 deletions

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,5 @@ emails
5656
*.bk
5757
email-queue
5858
uploads/*
59+
*.deb
60+
stripe_listen.log

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ export FLASK_APP=subscribie
149149
export FLASK_DEBUG=1
150150
flask db upgrade
151151
flask initdb # (recommended- gives you some example data)
152+
# Note if using rye (no longer maintained) use:
153+
# rye sync --features test # to install test requirements
152154
```
153155

154156
The database file is called `data.db`. Note,

docs/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ You can find out more about how to install Hugo for your environment in our
88
[Getting started](https://www.docsy.dev/docs/getting-started/#prerequisites-and-installation) guide.
99

1010
On `Ubuntu Linux`? You can download from [Hugu Releases on GitHub](https://github.com/gohugoio/hugo/releases)
11-
e.g. `hugo_extended_0.105.0_linux-amd64.deb` then `sudo dpkg -i hugo_extended_0.105.0_linux-amd64.deb`
11+
e.g.
12+
13+
```shell
14+
wget https://github.com/gohugoio/hugo/releases/download/v0.105.0/hugo_extended_0.105.0_linux-amd64.deb && sudo dpkg -i hugo_extended_0.105.0_linux-amd64.deb
15+
```
1216

1317
> Remember, you must download/install the **extended** version.
1418

docs/content/en/docs/Architecture/testing.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,32 @@ Remember Stripe will give you a key valid for 90 days, if you get the following
8585
Error while authenticating with Stripe: Authorization failed, status=401
8686
```
8787

88+
#### Time machine webhook validation with Stripe Test Clocks
89+
90+
The following verifies that changes to the `application_fee_amount` get applied to future invoices generated by *existing* active Subscriptions. Such invoices are generated by the `subscription_cycle` billing reason.
91+
92+
This script creates an isolated Stripe Connected Account, provisions a Customer and Subscription attached to a time-frozen "Test Clock", and then advances the clock exactly one month into the future to force Stripe to generate a new recurring draft invoice.
93+
94+
**How to run the automated Test Clock simulation script:**
95+
96+
97+
1. Ensure your local Flask application is running (See [Quickstart without docker](https://github.com/Subscribie/subscribie?tab=readme-ov-file#quickstart-without-docker)).
98+
2. In a separate terminal, start the Stripe webhook forwarder as instructed above:
99+
```bash
100+
stripe listen --events checkout.session.completed,payment_intent.succeeded,payment_intent.payment_failed,invoice.created --forward-to 127.0.0.1:5000/stripe_webhook --forward-connect-to 127.0.0.1:5000/stripe_webhook
101+
```
102+
3. In a third terminal, activate your virtual environment and execute the simulation script:
103+
```bash
104+
. venv/bin/activate
105+
export PYTHONUNBUFFERED=1
106+
python test_stripe_clock.py
107+
```
108+
109+
Stripe takes **1-2 minutes** to compute a month of time in the background. Once the clock goes 'ready', Stripe will synchronously push the `invoice.created` webhook event to your local `<stripe listen>` broker.
110+
111+
If successful, the script will catch the webhook modification, printing:
112+
`[SUCCESS] End-to-End verified! Local webhook caught the 'draft' invoice and successfully injected application_fee_amount: x` (these may also be verified visually in the Stripe dashboard with test mode activated).
113+
88114
#### Bulk delete Stripe accounts
89115

90116
> **Warning**

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ dependencies = [
2020
"stripe",
2121
"GitPython",
2222
"pathlib",
23-
"pytest",
2423
"Flask-SQLAlchemy",
2524
"Flask-Migrate",
2625
"Flask-Babel",
@@ -59,3 +58,6 @@ allow-direct-references = true
5958

6059
[tool.hatch.build.targets.wheel]
6160
packages = ["./"]
61+
62+
[project.optional-dependencies]
63+
test = ["pytest"]

requirements-dev.lock

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
#
44
# last locked with the following flags:
55
# pre: false
6-
# features: []
6+
# features: ["test"]
77
# all-features: false
88
# with-sources: false
99
# generate-hashes: false
10+
# universal: false
1011

1112
-e file:.
1213
alembic==1.13.1

requirements.lock

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
#
44
# last locked with the following flags:
55
# pre: false
6-
# features: []
6+
# features: ["test"]
77
# all-features: false
88
# with-sources: false
99
# generate-hashes: false
10+
# universal: false
1011

1112
-e file:.
1213
alembic==1.13.1

start_stripe_listener.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env bash
2+
# start_stripe_listener.sh
3+
# Script to easily run stripe listen in the background for local development.
4+
5+
LOG_FILE="stripe_listen.log"
6+
PID_FILE=".stripe_listen.pid"
7+
8+
# Check if already running
9+
if [ -f "$PID_FILE" ]; then
10+
OLD_PID=$(cat "$PID_FILE")
11+
if ps -p $OLD_PID > /dev/null; then
12+
echo "Stripe listener is already running with PID $OLD_PID."
13+
echo "Stop it first with: ./stop_stripe_listener.sh"
14+
exit 1
15+
else
16+
# Process died but pid file remains, clean up
17+
rm "$PID_FILE"
18+
fi
19+
fi
20+
21+
echo "Starting Stripe CLI listener..."
22+
23+
# If STRIPE_TEST_SECRET_KEY is not in environment, fail and exit
24+
if [ -z "$STRIPE_TEST_SECRET_KEY" ]; then
25+
echo "STRIPE_TEST_SECRET_KEY is not set. Please set it in your environment."
26+
exit 1
27+
fi
28+
29+
# Run stripe listen in the background
30+
# We use nohup so that closing the terminal doesn't kill it
31+
nohup stripe listen \
32+
--api-key "${STRIPE_TEST_SECRET_KEY}" \
33+
--events checkout.session.completed,payment_intent.succeeded,payment_intent.payment_failed,invoice.created \
34+
--forward-to 127.0.0.1:5000/stripe_webhook \
35+
--forward-connect-to 127.0.0.1:5000/stripe_webhook > "$LOG_FILE" 2>&1 &
36+
37+
PID=$!
38+
echo $PID > "$PID_FILE"
39+
40+
echo "✅ Stripe listener started in background (PID: $PID)."
41+
echo "📁 Logs are being written to $LOG_FILE"
42+
echo "🛑 To stop, run: ./stop_stripe_listener.sh"
43+
echo ""
44+
echo "Note: If the logs in $LOG_FILE show 'Please authenticate', run 'stripe login' interactive to refresh your token."
45+
echo "To view the logs, run: tail -f $LOG_FILE"

stop_stripe_listener.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env bash
2+
# stop_stripe_listener.sh
3+
# Script to easily stop the stripe listener running in the background.
4+
5+
PID_FILE=".stripe_listen.pid"
6+
7+
if [ -f "$PID_FILE" ]; then
8+
PID=$(cat "$PID_FILE")
9+
if ps -p $PID > /dev/null; then
10+
echo "Stopping Stripe listener (PID: $PID)..."
11+
kill $PID
12+
rm "$PID_FILE"
13+
echo "✅ Stopped."
14+
fi
15+
else
16+
echo "Stripe listener not currently running (no $PID_FILE found)."
17+
fi

subscribie/blueprints/admin/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ def stripe_create_charge():
341341
amount=amount,
342342
currency=currency,
343343
payment_method_types=["card"],
344-
application_fee_amount=int(amount * 0.025),
344+
application_fee_amount=int(amount * 0.025) + 40,
345345
customer=customer,
346346
description=statement_descriptor_suffix,
347347
statement_descriptor_suffix=statement_descriptor_suffix,

0 commit comments

Comments
 (0)