From 5b223d23cd7ff437f34773a2213e6a36df7b1eac Mon Sep 17 00:00:00 2001 From: Oliver Marks Date: Mon, 30 Jan 2017 22:39:15 +0000 Subject: [PATCH] new command works needs improvement, fix fixtures file thanks for pointing that out @mightyscollins --- .../commands/list_subscription_payments.py | 22 +++++++++++-------- mhackspace/subscriptions/payments.py | 12 +++++----- mhackspace/users/fixtures/groups.json | 3 +-- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/mhackspace/subscriptions/management/commands/list_subscription_payments.py b/mhackspace/subscriptions/management/commands/list_subscription_payments.py index 930cea4..fc575d6 100644 --- a/mhackspace/subscriptions/management/commands/list_subscription_payments.py +++ b/mhackspace/subscriptions/management/commands/list_subscription_payments.py @@ -16,14 +16,16 @@ class Command(BaseCommand): self.stdout.write( self.style.NOTICE( - '== Gocardless customers ==')) + '== Gocardless customer payments ==')) Payments.objects.all().delete() - for customer in provider.fetch_customers(): - self.stdout.write(str(dir(customer))) - self.stdout.write(str(customer)) - Payments.objects.create( + payment_objects = [] + for customer in provider.fetch_customers(): + # self.stdout.write(str(dir(customer))) + # self.stdout.write(str(customer)) + + payment_objects.append(Payments( user=None, user_reference=customer.get('user_id'), user_email=customer.get('email'), @@ -31,11 +33,13 @@ class Command(BaseCommand): amount=customer.get('amount'), type=Payments.lookup_payment_type(customer.get('payment_type')), date=customer.get('payment_date') - ) + )) # self.stdout.write(str(customer.email)) # self.stdout.write(str(dir(customer['email']()))) - # self.stdout.write( - # self.style.SUCCESS( - # '\t{reference} - {payment} - {status} - {email}'.format(**model_to_dict(subscriptions[-1])))) + self.stdout.write( + self.style.SUCCESS( + '\t{reference} - {amount} - {type} - {user_email}'.format(**model_to_dict(payment_objects[-1])))) + + Payments.objects.bulk_create(payment_objects) diff --git a/mhackspace/subscriptions/payments.py b/mhackspace/subscriptions/payments.py index d765a42..26ff92e 100644 --- a/mhackspace/subscriptions/payments.py +++ b/mhackspace/subscriptions/payments.py @@ -56,16 +56,16 @@ class gocardless_provider: merchant = gocardless.client.merchant() for customer in merchant.bills(): user = customer.user() - print(dir(customer)) - print(dir(customer.reference_fields)) - print(customer.reference_fields) - print(customer.payout_id) - print(customer.reference_fields.payout_id) + # print(dir(customer)) + # print(dir(customer.reference_fields)) + # print(customer.reference_fields) + # print(customer.payout_id) + # print(customer.reference_fields.payout_id) result = { 'user_id': user.id, 'email': user.email, 'status': customer.status, - 'payment_id': customer.source_id, + 'payment_id': customer.id, 'payment_type': customer.source_type, 'payment_date': customer.created_at, 'amount': customer.amount diff --git a/mhackspace/users/fixtures/groups.json b/mhackspace/users/fixtures/groups.json index ab3af61..7a946f2 100644 --- a/mhackspace/users/fixtures/groups.json +++ b/mhackspace/users/fixtures/groups.json @@ -1,2 +1 @@ -Postgres is up - continuing... -[{"model": "auth.group", "pk": 1, "fields": {"name": "members", "permissions": []}}] \ No newline at end of file +[{"model": "auth.group", "pk": 1, "fields": {"name": "members", "permissions": []}}]