From 69e959a0c8b3212b4b445b7260ad8c0435bfe02b Mon Sep 17 00:00:00 2001 From: Raymond Yee Date: Mon, 17 Sep 2012 14:55:28 -0700 Subject: [PATCH] fleshing out of payment.models.Account --- frontend/views.py | 16 +- ...st4__add_field_account_card_type__add_f.py | 270 ++++++++++++++++++ payment/models.py | 17 ++ 3 files changed, 301 insertions(+), 2 deletions(-) create mode 100644 payment/migrations/0011_auto__add_field_account_card_last4__add_field_account_card_type__add_f.py diff --git a/frontend/views.py b/frontend/views.py index 255f5c65..6eac16b8 100755 --- a/frontend/views.py +++ b/frontend/views.py @@ -775,8 +775,18 @@ class FundPledgeView(FormView): # create customer and charge id and then charge the customer customer = sc.create_customer(card=stripe_token, description=self.request.user.username, email=self.request.user.email) - account = Account(host = PAYMENT_HOST_STRIPE, account_id = customer.id) - account.user = self.request.user + + account = Account(host = PAYMENT_HOST_STRIPE, + account_id = customer.id, + card_last4 = customer.active_card.last4, + card_type = customer.active_card.type, + card_exp_month = customer.active_card.exp_month, + card_exp_year = customer.active_card.exp_year, + card_fingerprint = customer.active_card.fingerprint, + card_country = customer.active_card.country, + user = self.request.user + ) + account.save() charge = sc.create_charge(preapproval_amount, customer=customer, description="${0} for test / retain cc".format(preapproval_amount)) @@ -794,6 +804,8 @@ class FundPledgeView(FormView): self.transaction.pay_key = charge.id self.transaction.currency = 'USD' self.transaction.amount = preapproval_amount + self.transaction.date_payment = now() + self.transaction.status = TRANSACTION_STATUS_COMPLETE self.transaction.save() diff --git a/payment/migrations/0011_auto__add_field_account_card_last4__add_field_account_card_type__add_f.py b/payment/migrations/0011_auto__add_field_account_card_last4__add_field_account_card_type__add_f.py new file mode 100644 index 00000000..f86f8fb7 --- /dev/null +++ b/payment/migrations/0011_auto__add_field_account_card_last4__add_field_account_card_type__add_f.py @@ -0,0 +1,270 @@ +# -*- coding: utf-8 -*- +import datetime +from south.db import db +from south.v2 import SchemaMigration +from django.db import models + + +class Migration(SchemaMigration): + + def forwards(self, orm): + # Adding field 'Account.card_last4' + db.add_column('payment_account', 'card_last4', + self.gf('django.db.models.fields.CharField')(max_length=4, null=True), + keep_default=False) + + # Adding field 'Account.card_type' + db.add_column('payment_account', 'card_type', + self.gf('django.db.models.fields.CharField')(max_length=32, null=True), + keep_default=False) + + # Adding field 'Account.card_exp_month' + db.add_column('payment_account', 'card_exp_month', + self.gf('django.db.models.fields.IntegerField')(null=True), + keep_default=False) + + # Adding field 'Account.card_exp_year' + db.add_column('payment_account', 'card_exp_year', + self.gf('django.db.models.fields.IntegerField')(null=True), + keep_default=False) + + # Adding field 'Account.card_fingerprint' + db.add_column('payment_account', 'card_fingerprint', + self.gf('django.db.models.fields.CharField')(max_length=32, null=True), + keep_default=False) + + # Adding field 'Account.card_country' + db.add_column('payment_account', 'card_country', + self.gf('django.db.models.fields.CharField')(max_length=2, null=True), + keep_default=False) + + # Adding field 'Account.date_created' + db.add_column('payment_account', 'date_created', + self.gf('django.db.models.fields.DateTimeField')(auto_now=True, default=datetime.datetime(2012, 9, 17, 0, 0), blank=True), + keep_default=False) + + # Adding field 'Account.date_modified' + db.add_column('payment_account', 'date_modified', + self.gf('django.db.models.fields.DateTimeField')(auto_now=True, default=datetime.datetime(2012, 9, 17, 0, 0), blank=True), + keep_default=False) + + # Adding field 'Account.date_deactivated' + db.add_column('payment_account', 'date_deactivated', + self.gf('django.db.models.fields.DateTimeField')(null=True), + keep_default=False) + + + def backwards(self, orm): + # Deleting field 'Account.card_last4' + db.delete_column('payment_account', 'card_last4') + + # Deleting field 'Account.card_type' + db.delete_column('payment_account', 'card_type') + + # Deleting field 'Account.card_exp_month' + db.delete_column('payment_account', 'card_exp_month') + + # Deleting field 'Account.card_exp_year' + db.delete_column('payment_account', 'card_exp_year') + + # Deleting field 'Account.card_fingerprint' + db.delete_column('payment_account', 'card_fingerprint') + + # Deleting field 'Account.card_country' + db.delete_column('payment_account', 'card_country') + + # Deleting field 'Account.date_created' + db.delete_column('payment_account', 'date_created') + + # Deleting field 'Account.date_modified' + db.delete_column('payment_account', 'date_modified') + + # Deleting field 'Account.date_deactivated' + db.delete_column('payment_account', 'date_deactivated') + + + models = { + 'auth.group': { + 'Meta': {'object_name': 'Group'}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}), + 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}) + }, + 'auth.permission': { + 'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'}, + 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}) + }, + 'auth.user': { + 'Meta': {'object_name': 'User'}, + 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}), + 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), + 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), + 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), + 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}), + 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}), + 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'}) + }, + 'contenttypes.contenttype': { + 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"}, + 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}) + }, + 'core.campaign': { + 'Meta': {'object_name': 'Campaign'}, + 'activated': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}), + 'amazon_receiver': ('django.db.models.fields.CharField', [], {'max_length': '100', 'blank': 'True'}), + 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), + 'deadline': ('django.db.models.fields.DateTimeField', [], {}), + 'description': ('ckeditor.fields.RichTextField', [], {'null': 'True'}), + 'details': ('ckeditor.fields.RichTextField', [], {'null': 'True', 'blank': 'True'}), + 'edition': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'campaigns'", 'null': 'True', 'to': "orm['core.Edition']"}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'left': ('django.db.models.fields.DecimalField', [], {'null': 'True', 'max_digits': '14', 'decimal_places': '2'}), + 'license': ('django.db.models.fields.CharField', [], {'default': "'CC BY-NC-ND'", 'max_length': '255'}), + 'managers': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'campaigns'", 'symmetrical': 'False', 'to': "orm['auth.User']"}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '500', 'null': 'True'}), + 'paypal_receiver': ('django.db.models.fields.CharField', [], {'max_length': '100', 'blank': 'True'}), + 'status': ('django.db.models.fields.CharField', [], {'default': "'INITIALIZED'", 'max_length': '15', 'null': 'True'}), + 'target': ('django.db.models.fields.DecimalField', [], {'null': 'True', 'max_digits': '14', 'decimal_places': '2'}), + 'work': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'campaigns'", 'to': "orm['core.Work']"}) + }, + 'core.edition': { + 'Meta': {'object_name': 'Edition'}, + 'cover_image': ('django.db.models.fields.URLField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}), + 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'public_domain': ('django.db.models.fields.NullBooleanField', [], {'null': 'True', 'blank': 'True'}), + 'publication_date': ('django.db.models.fields.CharField', [], {'max_length': '50', 'null': 'True', 'blank': 'True'}), + 'publisher': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}), + 'title': ('django.db.models.fields.CharField', [], {'max_length': '1000'}), + 'unglued': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'work': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'editions'", 'null': 'True', 'to': "orm['core.Work']"}) + }, + 'core.premium': { + 'Meta': {'object_name': 'Premium'}, + 'amount': ('django.db.models.fields.DecimalField', [], {'max_digits': '10', 'decimal_places': '0'}), + 'campaign': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'premiums'", 'null': 'True', 'to': "orm['core.Campaign']"}), + 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), + 'description': ('django.db.models.fields.TextField', [], {'null': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'limit': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'type': ('django.db.models.fields.CharField', [], {'max_length': '2'}) + }, + 'core.work': { + 'Meta': {'ordering': "['title']", 'object_name': 'Work'}, + 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), + 'description': ('django.db.models.fields.TextField', [], {'default': "''", 'null': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'language': ('django.db.models.fields.CharField', [], {'default': "'en'", 'max_length': '2'}), + 'num_wishes': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'openlibrary_lookup': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}), + 'title': ('django.db.models.fields.CharField', [], {'max_length': '1000'}) + }, + 'payment.account': { + 'Meta': {'object_name': 'Account'}, + 'account_id': ('django.db.models.fields.CharField', [], {'max_length': '128', 'null': 'True'}), + 'card_country': ('django.db.models.fields.CharField', [], {'max_length': '2', 'null': 'True'}), + 'card_exp_month': ('django.db.models.fields.IntegerField', [], {'null': 'True'}), + 'card_exp_year': ('django.db.models.fields.IntegerField', [], {'null': 'True'}), + 'card_fingerprint': ('django.db.models.fields.CharField', [], {'max_length': '32', 'null': 'True'}), + 'card_last4': ('django.db.models.fields.CharField', [], {'max_length': '4', 'null': 'True'}), + 'card_type': ('django.db.models.fields.CharField', [], {'max_length': '32', 'null': 'True'}), + 'date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), + 'date_deactivated': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}), + 'date_modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), + 'host': ('django.db.models.fields.CharField', [], {'default': "'none'", 'max_length': '32'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'null': 'True'}) + }, + 'payment.credit': { + 'Meta': {'object_name': 'Credit'}, + 'balance': ('django.db.models.fields.DecimalField', [], {'default': "'0.00'", 'max_digits': '14', 'decimal_places': '2'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'last_activity': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), + 'pledged': ('django.db.models.fields.DecimalField', [], {'default': "'0.00'", 'max_digits': '14', 'decimal_places': '2'}), + 'user': ('django.db.models.fields.related.OneToOneField', [], {'related_name': "'credit'", 'unique': 'True', 'to': "orm['auth.User']"}) + }, + 'payment.creditlog': { + 'Meta': {'object_name': 'CreditLog'}, + 'action': ('django.db.models.fields.CharField', [], {'max_length': '16'}), + 'amount': ('django.db.models.fields.DecimalField', [], {'default': "'0.00'", 'max_digits': '14', 'decimal_places': '2'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'sent': ('django.db.models.fields.IntegerField', [], {'null': 'True'}), + 'timestamp': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), + 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'null': 'True'}) + }, + 'payment.paymentresponse': { + 'Meta': {'object_name': 'PaymentResponse'}, + 'api': ('django.db.models.fields.CharField', [], {'max_length': '64'}), + 'correlation_id': ('django.db.models.fields.CharField', [], {'max_length': '512', 'null': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'info': ('django.db.models.fields.CharField', [], {'max_length': '1024', 'null': 'True'}), + 'status': ('django.db.models.fields.CharField', [], {'max_length': '32', 'null': 'True'}), + 'timestamp': ('django.db.models.fields.CharField', [], {'max_length': '128', 'null': 'True'}), + 'transaction': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['payment.Transaction']"}) + }, + 'payment.receiver': { + 'Meta': {'object_name': 'Receiver'}, + 'amount': ('django.db.models.fields.DecimalField', [], {'default': "'0.00'", 'max_digits': '14', 'decimal_places': '2'}), + 'currency': ('django.db.models.fields.CharField', [], {'max_length': '10'}), + 'email': ('django.db.models.fields.CharField', [], {'max_length': '64'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'local_status': ('django.db.models.fields.CharField', [], {'max_length': '64', 'null': 'True'}), + 'primary': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'reason': ('django.db.models.fields.CharField', [], {'max_length': '64'}), + 'status': ('django.db.models.fields.CharField', [], {'max_length': '64'}), + 'transaction': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['payment.Transaction']"}), + 'txn_id': ('django.db.models.fields.CharField', [], {'max_length': '64'}) + }, + 'payment.sent': { + 'Meta': {'object_name': 'Sent'}, + 'amount': ('django.db.models.fields.DecimalField', [], {'default': "'0.00'", 'max_digits': '14', 'decimal_places': '2'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'timestamp': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), + 'user': ('django.db.models.fields.CharField', [], {'max_length': '32', 'null': 'True'}) + }, + 'payment.transaction': { + 'Meta': {'object_name': 'Transaction'}, + 'ack_dedication': ('django.db.models.fields.CharField', [], {'max_length': '140', 'null': 'True'}), + 'ack_name': ('django.db.models.fields.CharField', [], {'max_length': '64', 'null': 'True'}), + 'amount': ('django.db.models.fields.DecimalField', [], {'default': "'0.00'", 'max_digits': '14', 'decimal_places': '2'}), + 'anonymous': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'approved': ('django.db.models.fields.NullBooleanField', [], {'null': 'True', 'blank': 'True'}), + 'campaign': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['core.Campaign']", 'null': 'True'}), + 'currency': ('django.db.models.fields.CharField', [], {'default': "'USD'", 'max_length': '10', 'null': 'True'}), + 'date_authorized': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}), + 'date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), + 'date_executed': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}), + 'date_expired': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}), + 'date_modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), + 'date_payment': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}), + 'error': ('django.db.models.fields.CharField', [], {'max_length': '256', 'null': 'True'}), + 'execution': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'host': ('django.db.models.fields.CharField', [], {'default': "'none'", 'max_length': '32'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'local_status': ('django.db.models.fields.CharField', [], {'default': "'NONE'", 'max_length': '32', 'null': 'True'}), + 'max_amount': ('django.db.models.fields.DecimalField', [], {'default': "'0.00'", 'max_digits': '14', 'decimal_places': '2'}), + 'pay_key': ('django.db.models.fields.CharField', [], {'max_length': '128', 'null': 'True'}), + 'preapproval_key': ('django.db.models.fields.CharField', [], {'max_length': '128', 'null': 'True'}), + 'premium': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['core.Premium']", 'null': 'True'}), + 'reason': ('django.db.models.fields.CharField', [], {'max_length': '64', 'null': 'True'}), + 'receipt': ('django.db.models.fields.CharField', [], {'max_length': '256', 'null': 'True'}), + 'secret': ('django.db.models.fields.CharField', [], {'max_length': '64', 'null': 'True'}), + 'status': ('django.db.models.fields.CharField', [], {'default': "'None'", 'max_length': '32'}), + 'type': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'null': 'True'}) + } + } + + complete_apps = ['payment'] \ No newline at end of file diff --git a/payment/models.py b/payment/models.py index 58e3b70c..182d0e5c 100644 --- a/payment/models.py +++ b/payment/models.py @@ -16,6 +16,8 @@ logger = logging.getLogger(__name__) # c.id, c.amount, c.amount_refunded, c.currency, c.description, datetime.fromtimestamp(c.created, tz=utc), c.paid, # c.fee, c.disputed, c.amount_refunded, c.failure_message, # c.card.fingerprint, c.card.type, c.card.last4, c.card.exp_month, c.card.exp_year + +# promising fields class Transaction(models.Model): @@ -294,6 +296,21 @@ class Account(models.Model): host = models.CharField(default=PAYMENT_HOST_NONE, max_length=32, null=False) account_id = models.CharField(max_length=128, null=True) + # card related info + card_last4 = models.CharField(max_length=4, null=True) + + # Visa, American Express, MasterCard, Discover, JCB, Diners Club, or Unknown + card_type = models.CharField(max_length=32, null=True) + card_exp_month = models.IntegerField(null=True) + card_exp_year = models.IntegerField(null=True) + card_fingerprint = models.CharField(max_length=32, null=True) + card_country = models.CharField(max_length=2, null=True) + + # creation and last modified timestamps + date_created = models.DateTimeField(auto_now=True) + date_modified = models.DateTimeField(auto_now=True) + date_deactivated = models.DateTimeField(null=True) + # associated User user = models.ForeignKey(User, null=True)