From a6a6e7e957cf03d4fb6b8094d30e91e3bd613a5e Mon Sep 17 00:00:00 2001 From: Samuel Clay Date: Mon, 22 Mar 2021 10:25:14 -0400 Subject: [PATCH] Updating Stripe email when updating user email. --- apps/profile/forms.py | 8 +------- apps/profile/models.py | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/apps/profile/forms.py b/apps/profile/forms.py index 1244eb22a..c4f74bf5c 100644 --- a/apps/profile/forms.py +++ b/apps/profile/forms.py @@ -177,13 +177,7 @@ class AccountSettingsForm(forms.Form): social_profile.save() - if self.user.email != email: - self.user.email = email - self.user.save() - - sp = MSocialProfile.get_user(self.user.pk) - sp.email = email - sp.save() + self.user.profile.update_email(email) if old_password or new_password: change_password(self.user, old_password, new_password) diff --git a/apps/profile/models.py b/apps/profile/models.py index e603d7a44..5d334d599 100644 --- a/apps/profile/models.py +++ b/apps/profile/models.py @@ -501,6 +501,30 @@ class Profile(models.Model): return ipn[0].payer_email + def update_email(self, new_email): + from apps.social.models import MSocialProfile + + if self.user.email == new_email: + return + + self.user.email = new_email + self.user.save() + + sp = MSocialProfile.get_user(self.user.pk) + sp.email = new_email + sp.save() + + if self.stripe_id: + stripe_customer = self.stripe_customer() + stripe_customer.update({'email': new_email}) + stripe_customer.save() + + def stripe_customer(self): + if self.stripe_id: + stripe.api_key = settings.STRIPE_SECRET + stripe_customer = stripe.Customer.retrieve(self.stripe_id) + return stripe_customer + def activate_ios_premium(self, transaction_identifier=None, amount=36): payments = PaymentHistory.objects.filter(user=self.user, payment_identifier=transaction_identifier,