From 8a659c153e85e9a1a4f43cc761617e7c79d2aa93 Mon Sep 17 00:00:00 2001 From: PCoder Date: Thu, 19 Apr 2018 00:52:38 +0200 Subject: [PATCH] Set VM_ID metadata to the created subscription --- datacenterlight/tasks.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/datacenterlight/tasks.py b/datacenterlight/tasks.py index 67b00c5d..8c63c84c 100644 --- a/datacenterlight/tasks.py +++ b/datacenterlight/tasks.py @@ -18,6 +18,7 @@ from utils.hosting_utils import get_all_public_keys, get_or_create_vm_detail from utils.forms import UserBillingAddressForm from utils.mailer import BaseEmail from utils.models import BillingAddress +from utils.stripe_utils import StripeUtils logger = get_task_logger(__name__) @@ -102,6 +103,22 @@ def create_vm_task(self, vm_template_id, user, specs, template, order_id): ) logger.error(error_msg) + stripe_utils = StripeUtils() + result = stripe_utils.set_subscription_metadata( + subscription_id=hosting_order.subscription_id, + metadata={"VM_ID": str(vm_id)} + ) + stripe_subscription_obj = result.get('response_object') + if stripe_subscription_obj is not None: + emsg = "Could not update subscription metadata for {sub}".format( + sub=hosting_order.subscription_id + ) + logger.error(emsg) + if error_msg: + error_msg += emsg + else: + error_msg = emsg + vm = VirtualMachineSerializer(manager.get_vm(vm_id)).data context = {