Resolve resinstatement processing

This commit is contained in:
Marty Ballard 2019-09-29 22:39:39 -05:00 коммит произвёл Scott Idler
Родитель cd267e8756
Коммит e01ec019c7
2 изменённых файлов: 34 добавлений и 1 удалений

Просмотреть файл

@ -238,6 +238,39 @@ def cancel_stripe_subscription_period_end(
raise e
@retry(
wait=wait_exponential(multiplier=1, min=1, max=8),
stop=stop_after_attempt(4),
reraise=True,
)
def reactivate_stripe_subscription(
subscription_id: str, idempotency_key: str
) -> Subscription:
"""
Set Stripe subscription to cancel at period end
:param subscription_id:
:param idempotency_key:
:return: Subscription
"""
try:
sub = Subscription.modify(
sid=subscription_id,
cancel_at_period_end=False,
idempotency_key=idempotency_key,
)
return sub
except (
InvalidRequestError,
APIConnectionError,
APIError,
RateLimitError,
IdempotencyError,
StripeErrorWithParamCode,
) as e:
logger.error("cancel sub error", error=str(e))
raise e
@retry(
wait=wait_exponential(multiplier=1, min=1, max=8),
stop=stop_after_attempt(4),

Просмотреть файл

@ -226,7 +226,7 @@ def reactivate_subscription(uid: str, sub_id: str) -> FlaskResponse:
for subscription in active_subscriptions:
if subscription["id"] == sub_id:
if subscription["cancel_at_period_end"]:
vendor.cancel_stripe_subscription_period_end(
vendor.reactivate_stripe_subscription(
sub_id, utils.get_indempotency_key()
)
return dict(message="Subscription reactivation was successful."), 200