Commit 6f2791dc authored by Birin Sanchez's avatar Birin Sanchez
Browse files

When upgrading/downgrading bundle plan avoid a race condition between


WC and middleware by checking that the order is paid and the linked
subscription is active.
Signed-off-by: Birin Sanchez's avatarBirin Sanchez <birin.sanchez@puri.sm>
parent 5b55596c
Pipeline #17440 passed with stage
in 28 seconds
......@@ -133,8 +133,24 @@ def process_bundle_changes():
is_pending=True).order_by('-id')
for pending_change in pending_changes:
if order_paid(pending_change.new_order_id):
is_active = False
is_paid = order_paid(pending_change.new_order_id)
# Check if the subscription is active
subs = get_user_subscriptions(pending_change.user)
for sub in subs:
order_id = sub.get('parent_id', -1)
sub_status = sub.get('status', '')
if (
order_id == int(pending_change.new_order_id)
and sub_status == 'active'
):
is_active = True
break
# if subscription is active and order is paid we process the
# bundle change
if is_paid and is_active:
set_subscription_status(pending_change.old_subscription_id,
'cancelled')
forced_update(pending_change.user)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment