Stripe checkout #104411

Merged
Anna Sirota merged 61 commits from stripe into main 2024-06-17 18:08:41 +02:00
3 changed files with 43 additions and 5 deletions
Showing only changes of commit 854c06c801 - Show all commits

View File

@ -0,0 +1,30 @@
# Generated by Django 3.2.16 on 2024-06-10 08:52
import logging
from django.db import migrations
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
def create_missing_customers(apps, schema_editor):
Customer = apps.get_model('looper', 'Customer')
User = apps.get_model('users', 'User')
user_q = User.objects.filter(customer=None)
logger.info('%s accounts are missing a Customer records', user_q.count())
to_create = []
for user in user_q:
to_create.append(Customer(user_id=user.pk, billing_email=user.email))
if to_create:
Customer.objects.bulk_create(to_create)
class Migration(migrations.Migration):
dependencies = [
('users', '0010_user_confirmed_email_at'),
]
operations = [
migrations.RunPython(create_missing_customers, reverse_code=migrations.RunPython.noop),
]

View File

@ -211,8 +211,12 @@ class User(AbstractUser):
logger.warning('Deleting address records of user pk=%s', self.pk) logger.warning('Deleting address records of user pk=%s', self.pk)
looper.models.Address.objects.filter(user_id=self.pk).delete() looper.models.Address.objects.filter(user_id=self.pk).delete()
logger.warning('Deleting customer records of user pk=%s', self.pk) logger.warning('Anonymizing Customer record of user pk=%s', self.pk)
looper.models.Customer.objects.filter(user_id=self.pk).delete() looper.models.Customer.objects.exclude(user_id=None).filter(user_id=self.pk).update(
billing_email=f'{username}@example.com',
full_name='',
)
looper.models.GatewayCustomerId.objects.filter(user_id=self.pk).delete() looper.models.GatewayCustomerId.objects.filter(user_id=self.pk).delete()
subscriptions.models.TeamUsers.objects.filter(user_id=self.pk).delete() subscriptions.models.TeamUsers.objects.filter(user_id=self.pk).delete()

View File

@ -144,7 +144,7 @@ class TestTasks(TestCase):
f'Soft-deleting payment methods records of user pk={user.pk}', f'Soft-deleting payment methods records of user pk={user.pk}',
rf'Deleting payment method \d+ of user pk={user.pk} at the payment gateway', rf'Deleting payment method \d+ of user pk={user.pk} at the payment gateway',
f'Deleting address records of user pk={user.pk}', f'Deleting address records of user pk={user.pk}',
f'Deleting customer records of user pk={user.pk}', f'Anonymizing Customer record of user pk={user.pk}',
f'Anonymizing comments of user pk={user.pk}', f'Anonymizing comments of user pk={user.pk}',
f'Anonymizing likes of user pk={user.pk}', f'Anonymizing likes of user pk={user.pk}',
f'Deleting actions of user pk={user.pk}', f'Deleting actions of user pk={user.pk}',
@ -166,8 +166,12 @@ class TestTasks(TestCase):
self.assertEqual(user.full_name, '') self.assertEqual(user.full_name, '')
self.assertTrue(user.email.startswith('del')) self.assertTrue(user.email.startswith('del'))
self.assertTrue(user.email.endswith('@example.com')) self.assertTrue(user.email.endswith('@example.com'))
with self.assertRaises(User.customer.RelatedObjectDoesNotExist): user.customer.refresh_from_db()
user.customer self.assertTrue(user.customer.billing_email.startswith('del'), user.customer.billing_email)
self.assertTrue(
user.customer.billing_email.endswith('@example.com'), user.customer.billing_email
)
self.assertEqual(user.customer.full_name, '', user.customer.full_name)
self.assertEqual(user.address_set.count(), 0) self.assertEqual(user.address_set.count(), 0)
self.assertEqual(user.paymentmethod_set.first().recognisable_name, '') self.assertEqual(user.paymentmethod_set.first().recognisable_name, '')