Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call Talpa cancels as final step in permit ending #416

Merged
merged 1 commit into from
Nov 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions parking_permits/models/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,27 +578,10 @@ def cancel(self, cancel_reason, cancel_from_talpa=True):
logger.error(f"Order validation failed. Error = {e}")
return False

# Try to cancel subscription from Talpa as well
if cancel_from_talpa:
try:
self._cancel_talpa_subcription(customer_id)
except SubscriptionCancelError:
logger.warning(
"Talpa subscription cancelling failed. Continuing the cancel process.."
)

self.status = SubscriptionStatus.CANCELLED
self.cancel_reason = cancel_reason
self.save()

remaining_valid_order_subscriptions = Subscription.objects.filter(
order_items__order__talpa_order_id__exact=talpa_order_id,
status=SubscriptionStatus.CONFIRMED,
)
# Mark the order as cancelled if it has no active subscriptions left
if not remaining_valid_order_subscriptions.exists():
order.cancel(cancel_from_talpa=cancel_from_talpa)

# Create a refund for a remaining full month period, if it was charged already
if permit.end_time and permit.end_time - relativedelta(months=1) > tz.now():
logger.info(f"Creating Refund for permit {str(permit.id)}")
Expand All @@ -615,7 +598,24 @@ def cancel(self, cancel_reason, cancel_from_talpa=True):
)
logger.info(f"Refund for permit {str(permit.id)} created successfully")

logger.info(f"Subscription {self} cancelled successfully")
# Try to cancel subscription from Talpa as well
if cancel_from_talpa:
try:
self._cancel_talpa_subcription(customer_id)
except SubscriptionCancelError:
logger.warning(
"Talpa subscription cancelling failed. Continuing the cancel process.."
)

remaining_valid_order_subscriptions = Subscription.objects.filter(
order_items__order__talpa_order_id__exact=talpa_order_id,
status=SubscriptionStatus.CONFIRMED,
)
# Mark the order as cancelled if it has no active subscriptions left
if not remaining_valid_order_subscriptions.exists():
order.cancel(cancel_from_talpa=cancel_from_talpa)

logger.info(f"Subscription {self.talpa_subscription_id} cancelled successfully")
return True


Expand Down