From 0867641860ec7dfa548b4e3f0a23f0f0f4e122ba Mon Sep 17 00:00:00 2001 From: Jackie Munroe Date: Thu, 3 Oct 2019 08:25:29 -0700 Subject: [PATCH] Refactor subscription.py - Fix Plan nickname reference Updated reference to Plan nickname to use new formatter --- src/hub/vendor/subscription.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/hub/vendor/subscription.py b/src/hub/vendor/subscription.py index 3fedc0c..295349f 100644 --- a/src/hub/vendor/subscription.py +++ b/src/hub/vendor/subscription.py @@ -4,15 +4,22 @@ import json +from stripe import Product + from hub.vendor.abstract import AbstractStripeHubEvent from hub.routes.static import StaticRoutes from shared.log import get_logger +from shared.utils import format_plan_nickname logger = get_logger() class StripeSubscriptionCreated(AbstractStripeHubEvent): def run(self): + product = Product.retrieve(self.payload.data.plan.product) + nickname = format_plan_nickname( + product_name=product["name"], plan_interval=self.payload.data.plan.interval + ) data = self.create_data( customer_id=self.payload.data.object.id, subscription_created=self.payload.data.items.data[0].created, @@ -20,7 +27,7 @@ class StripeSubscriptionCreated(AbstractStripeHubEvent): current_period_end=self.payload.data.current_period_end, plan_amount=self.payload.data.plan.amount, plan_currency=self.payload.data.plan.currency, - plan_name=self.payload.data.plan.nickname, + plan_name=nickname, created=self.payload.data.object.created, ) logger.info("subscription created", data=data)