diff --git a/rowers/braintreestuff.py b/rowers/braintreestuff.py index 92a10f28..b08dee2c 100644 --- a/rowers/braintreestuff.py +++ b/rowers/braintreestuff.py @@ -619,3 +619,19 @@ def get_transactions(start_date, end_date): # pragma: no cover def mocktest(rower): # pragma: no cover return '5' + +def cancel_braintree_subscriptions(gateway): + """ + Cancel all Braintree subscriptions for Rowers, ensuring they run to the end of the current billing period. + """ + rowers = Rower.objects.exclude(subscription_id__isnull=True) + for rower in rowers: + subscription_id = rower.subscription_id + try: + result = gateway.subscription.cancel(subscription_id) + if result.is_success: + print(f"✅ Subscription {subscription_id} for Rower {rower.id} will not renew.") + else: + print(f"❌ Failed to cancel subscription {subscription_id}: {result.message}") + except Exception as e: + print(f"🚨 Error processing subscription {subscription_id}: {e}") diff --git a/rowers/tests/testdata/testdata.tcx.gz b/rowers/tests/testdata/testdata.tcx.gz index 5cf0703c..a3ba1af5 100644 Binary files a/rowers/tests/testdata/testdata.tcx.gz and b/rowers/tests/testdata/testdata.tcx.gz differ