Skip to content
This repository has been archived by the owner on Jan 10, 2024. It is now read-only.

Commit

Permalink
Authorizenet backend cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
paluh committed Mar 15, 2012
1 parent 2b2538f commit f3161b5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
15 changes: 7 additions & 8 deletions satchless/contrib/payment/authorizenet_provider/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,16 @@ def get_billing_data(self, order):
return result

def confirm(self, order, typ=None):
v = order.paymentvariant.get_subtype_instance()
trans_type = self.capture and 'AUTH_CAPTURE' or 'AUTH_ONLY'
data = {
'card_num': v.cc_number,
'exp_date': v.cc_expiration,
'card_num': order.payment.cc_number,
'exp_date': order.payment.cc_expiration,
'amount': order.get_total().gross,
'invoice_num': order.pk,
'type': trans_type,
}
if v.cc_cvv2:
data['card_code'] = v.cc_cvv2
if order.payment.cc_cvv2:
data['card_code'] = order.payment.cc_cvv2
data.update(self.get_billing_data(order))
data.update(self.get_shipping_data(order))
data = dict((k, unidecode(v) if isinstance(v, unicode) else v)
Expand All @@ -85,9 +84,9 @@ def confirm(self, order, typ=None):
response = process_payment(data, {})
except urllib2.URLError:
raise PaymentFailure(ugettext("Could not connect to the gateway."))
v.cc_cvv2 = '' # Forget the CVV2 number immediately after the transaction
v.response = response
v.save()
order.payment.cc_cvv2 = '' # Forget the CVV2 number immediately after the transaction
order.payment.response = response
order.payment.save()
if not response.is_approved:
raise PaymentFailure(response.response_reason_text)

Expand Down
5 changes: 4 additions & 1 deletion satchless/contrib/payment/authorizenet_provider/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
from django.db import models
from django.utils.translation import ugettext_lazy as _

class AuthorizeNetPayment(models.Model):
from ...util.models import DeferredOneToOneField

class AuthorizeNetPaymentBase(models.Model):
cc_name = models.CharField(_('Name on Credit Card'), max_length=128)
cc_number = models.CharField(_('Card Number'), max_length=32)
cc_expiration = models.DateField(_('Exp. date'), null=True)
cc_cvv2 = models.CharField(_('CVV2 Security Number'), max_length=4)
response = models.ForeignKey(authorizenet.models.Response, null=True,
blank=True, editable=False)
order = DeferredOneToOneField('order', related_name='payment', editable=False)

class Meta:
abstract = True
Expand Down
5 changes: 5 additions & 0 deletions satchless/util/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ class DeferredForeignKey(DeferredField):
klass = models.ForeignKey


class DeferredOneToOneField(DeferredField):

klass = models.OneToOneField


class DeferredManyToManyField(DeferredField):

klass = models.ManyToManyField
Expand Down

0 comments on commit f3161b5

Please sign in to comment.