forked from ungleich-public/dynamicweb
Use the stripe 16 object API: Stripe objects are not dicts, Customer.modify and no PaymentMethod.delete, apply the pinned API version
This commit is contained in:
parent
a864a4ea77
commit
9d4b6f3785
4 changed files with 11 additions and 9 deletions
|
|
@ -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 '',
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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']
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue