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,