Add metadata (vm_id) to Stripe subscription

This commit is contained in:
PCoder 2017-10-28 20:25:18 +02:00
parent d2ae94327a
commit 2a59a3336b
2 changed files with 17 additions and 0 deletions

View file

@ -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.forms import UserBillingAddressForm
from utils.mailer import BaseEmail from utils.mailer import BaseEmail
from utils.models import BillingAddress from utils.models import BillingAddress
from utils.stripe_utils import StripeUtils
logger = get_task_logger(__name__) logger = get_task_logger(__name__)
@ -118,6 +119,10 @@ def create_vm_task(self, vm_template_id, user, specs, template,
# Associate an order with a stripe subscription # Associate an order with a stripe subscription
order.set_subscription_id(stripe_subscription_id, cc_details) order.set_subscription_id(stripe_subscription_id, cc_details)
stripe_utils = StripeUtils()
stripe_utils.set_subscription_meta_data(
stripe_subscription_id, {'ID': vm_id}
)
# If the Stripe payment succeeds, set order status approved # If the Stripe payment succeeds, set order status approved
order.set_approved() order.set_approved()

View file

@ -304,3 +304,15 @@ class StripeUtils(object):
cpu=cpu, cpu=cpu,
memory=memory, memory=memory,
disk_size=disk_size) disk_size=disk_size)
@handleStripeError
def set_subscription_meta_data(self, subscription_id, meta_data):
"""
Adds VM metadata to a subscription
:param subscription_id: Stripe identifier for the subscription
:param meta_data: A dict of meta data to be added
:return:
"""
subscription = stripe.Subscription.retrieve(subscription_id)
subscription.metadata = meta_data
subscription.save()