eerste set wijzigingen
This commit is contained in:
@@ -418,35 +418,72 @@ def create_subscription(rower, data):
|
||||
|
||||
return False, 0 # pragma: no cover
|
||||
|
||||
|
||||
def cancel_subscription(rower, id):
|
||||
themessages = []
|
||||
errormessages = []
|
||||
|
||||
# 1. Fetch subscription first so we can read paid_through_date
|
||||
try:
|
||||
_ = gateway.subscription.cancel(id)
|
||||
themessages.append("Subscription canceled")
|
||||
except: # pragma: no cover
|
||||
subscription = gateway.subscription.find(id)
|
||||
paid_through = subscription.paid_through_date # may be None
|
||||
except Exception:
|
||||
errormessages.append(
|
||||
"We could not find the subscription record in our customer database."
|
||||
" We have notified the site owner, who will contact you.")
|
||||
" We have notified the site owner, who will contact you."
|
||||
)
|
||||
|
||||
name = '{f} {l}'.format(f=rower.user.first_name,
|
||||
l=rower.user.last_name)
|
||||
name = f"{rower.user.first_name} {rower.user.last_name}"
|
||||
|
||||
_ = myqueue(queuehigh,
|
||||
handle_send_email_failed_cancel,
|
||||
name, rower.user.email, rower.user.username, id)
|
||||
_ = myqueue(
|
||||
queuehigh,
|
||||
handle_send_email_failed_cancel,
|
||||
name,
|
||||
rower.user.email,
|
||||
rower.user.username,
|
||||
id,
|
||||
)
|
||||
|
||||
return False, themessages, errormessages
|
||||
|
||||
# 2. Attempt cancellation
|
||||
try:
|
||||
_ = gateway.subscription.cancel(id)
|
||||
themessages.append("Subscription canceled")
|
||||
except Exception: # pragma: no cover
|
||||
errormessages.append(
|
||||
"We could not find the subscription record in our customer database."
|
||||
" We have notified the site owner, who will contact you."
|
||||
)
|
||||
|
||||
name = f"{rower.user.first_name} {rower.user.last_name}"
|
||||
|
||||
_ = myqueue(
|
||||
queuehigh,
|
||||
handle_send_email_failed_cancel,
|
||||
name,
|
||||
rower.user.email,
|
||||
rower.user.username,
|
||||
id,
|
||||
)
|
||||
|
||||
return False, themessages, errormessages
|
||||
|
||||
# 3. Update rower object (using paid_through_date)
|
||||
basicplans = PaidPlan.objects.filter(price=0, paymentprocessor='braintree')
|
||||
rower.paidplan = basicplans[0]
|
||||
|
||||
# teamplanexpires stays "now" (as you had it)
|
||||
rower.teamplanexpires = timezone.now()
|
||||
rower.planexpires = timezone.now()
|
||||
|
||||
# planexpires becomes the user's real, fully paid end date
|
||||
# fallback = now() if Braintree somehow returns None
|
||||
rower.planexpires = paid_through or timezone.now()
|
||||
|
||||
rower.clubsize = 0
|
||||
rower.rowerplan = 'basic'
|
||||
rower.subscription_id = None
|
||||
rower.save()
|
||||
|
||||
themessages.append("Your plan was reset to basic")
|
||||
|
||||
return True, themessages, errormessages
|
||||
|
||||
Reference in New Issue
Block a user