diff --git a/datacenterlight/views.py b/datacenterlight/views.py index 5d67e4f2..f124b023 100644 --- a/datacenterlight/views.py +++ b/datacenterlight/views.py @@ -1032,7 +1032,8 @@ class OrderConfirmationView(DetailView, FormView): stripe_api_cus_id=stripe_api_cus_id, card_details_response=json.dumps(card_details_response), stripe_subscription_obj=json.dumps( - stripe_subscription_obj) if stripe_customer_obj else '', + stripe_subscription_obj.to_dict() + ) if stripe_customer_obj else '', stripe_onetime_charge=json.dumps( stripe_onetime_charge) if stripe_onetime_charge else '', gp_details=json.dumps(gp_details) if gp_details else '', diff --git a/hosting/models.py b/hosting/models.py index 306061a2..2331c3ee 100644 --- a/hosting/models.py +++ b/hosting/models.py @@ -385,7 +385,7 @@ class MonthlyHostingBill(AssignPermissionsMixin, models.Model): # response for an invoice description="" if item.description is None else item.description, discountable=item.discountable, - metadata=json.dumps(item.metadata), + metadata=json.dumps(item.metadata.to_dict()), period_start=datetime.utcfromtimestamp(item.period.start).replace(tzinfo=pytz.utc), period_end=datetime.utcfromtimestamp(item.period.end).replace(tzinfo=pytz.utc), proration=item.proration, quantity=item.quantity, diff --git a/membership/models.py b/membership/models.py index 657c0151..1d0e578b 100644 --- a/membership/models.py +++ b/membership/models.py @@ -288,7 +288,7 @@ class StripeCustomer(models.Model): stripe_data = stripe_utils.create_customer( id_payment_method, email, customer_name) if stripe_data.get('response_object'): - stripe_cus_id = stripe_data.get('response_object').get('id') + stripe_cus_id = stripe_data.get('response_object').id return stripe_cus_id else: return None @@ -313,7 +313,7 @@ class StripeCustomer(models.Model): stripe_utils = StripeUtils() stripe_data = stripe_utils.create_customer(token, email, user.name) if stripe_data.get('response_object'): - stripe_cus_id = stripe_data.get('response_object').get('id') + stripe_cus_id = stripe_data.get('response_object').id if hasattr(user, 'stripecustomer'): # User already had a Stripe account and we are here # because the account was deleted in dashboard diff --git a/utils/stripe_utils.py b/utils/stripe_utils.py index c258b8d0..c63f03c4 100644 --- a/utils/stripe_utils.py +++ b/utils/stripe_utils.py @@ -7,6 +7,7 @@ from django.conf import settings from datacenterlight.models import StripePlan stripe.api_key = settings.STRIPE_API_PRIVATE_KEY +stripe.api_version = settings.STRIPE_API_VERSION logger = logging.getLogger(__name__) @@ -91,8 +92,10 @@ class StripeUtils(object): customer=stripe_customer_id, ) if set_as_default: - customer.invoice_settings.default_payment_method = id_payment_method - customer.save() + stripe.Customer.modify( + stripe_customer_id, + invoice_settings={'default_payment_method': id_payment_method} + ) return True @handleStripeError @@ -101,9 +104,7 @@ class StripeUtils(object): if card_id.startswith("pm"): logger.debug("PaymentMethod %s detached %s" % (card_id, stripe_customer_id)) - pm = stripe.PaymentMethod.retrieve(card_id) stripe.PaymentMethod.detach(card_id) - pm.delete() else: logger.debug("card %s detached %s" % (card_id, stripe_customer_id)) card = customer.sources.retrieve(card_id) @@ -223,7 +224,7 @@ class StripeUtils(object): except stripe.InvalidRequestError: customer = self.create_customer(token, user.email, user.name) user.stripecustomer.stripe_id = customer.get( - 'response_object').get('id') + 'response_object').id user.stripecustomer.save() if type(customer) is dict: customer = customer['response_object']