Skip to content

Commit

Permalink
merged #84 - pin payments update
Browse files Browse the repository at this point in the history
  • Loading branch information
tuxcanfly committed Oct 4, 2013
1 parent 759966f commit 1a9e2f0
Show file tree
Hide file tree
Showing 19 changed files with 74 additions and 98 deletions.
Binary file removed billing/.DS_Store
Binary file not shown.
16 changes: 16 additions & 0 deletions billing/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from django.contrib import admin
import billing.models as billing_models

admin.site.register(billing_models.GCNewOrderNotification)
admin.site.register(billing_models.AuthorizeAIMResponse)
admin.site.register(billing_models.WorldPayResponse)
admin.site.register(billing_models.AmazonFPSResponse)


class PaylaneTransactionAdmin(admin.ModelAdmin):
list_display = ('customer_name', 'customer_email', 'transaction_date', 'amount', 'success', 'error_code')
list_filter = ('success',)
ordering = ('-transaction_date',)
search_fields = ['customer_name', 'customer_email']

admin.site.register(billing_models.PaylaneTransaction, PaylaneTransactionAdmin)
20 changes: 0 additions & 20 deletions billing/admin/__init__.py

This file was deleted.

11 changes: 0 additions & 11 deletions billing/admin/paylane_admin.py

This file was deleted.

8 changes: 4 additions & 4 deletions billing/forms/pin_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ def verify_mod10(ccnum):

class PinChargeForm(forms.ModelForm):
number = CardNumberField()
expiry_month = forms.IntegerField(min_value=1,
expiry_month = forms.IntegerField(min_value=1,
max_value=12,
widget=forms.NumberInput(attrs={'placeholder':'MM'}))
expiry_year = forms.IntegerField(min_value=date.today().year,
max_value=date.today().year+20,
expiry_year = forms.IntegerField(min_value=date.today().year,
max_value=date.today().year+20,
widget=forms.NumberInput(attrs={'placeholder':'YYYY'}))
cvc = forms.IntegerField(min_value=0, max_value=9999)
email = forms.EmailField()
Expand All @@ -55,7 +55,7 @@ def __init__(self, *args, **kwargs):
value = getattr(user, field, None)
if value:
self.fields[field].initial = value

def get_credit_card(self):
d = self.cleaned_data
d['month'] = d['expiry_month']
Expand Down
11 changes: 0 additions & 11 deletions billing/gateway.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os.path, pkgutil
from django.utils.importlib import import_module
from django.conf import settings
from .utils.credit_card import CardNotSupported
Expand Down Expand Up @@ -129,13 +128,3 @@ def get_gateway(gateway, *args, **kwargs):
# We either hit the cache or load our class object, let's return an instance
# of it.
return clazz(*args, **kwargs)

def list_gateways(active_only=False):
from billing import gateways
gateway_list = []
for member in get_module_names(gateways):
if member.find('_gateway') > 0:
gateway = member.replace('_gateway', '')
if not active_only or get_gateway(gateway):
gateway_list.append(gateway)
return gateway_list
5 changes: 1 addition & 4 deletions billing/gateways/pin_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
except ImportError:
from django.utils import simplejson as json

import pprint
import requests
from copy import copy
from django.conf import settings
Expand Down Expand Up @@ -34,7 +33,7 @@ def __init__(self):
try:
self.test_mode = settings.MERCHANT_TEST_MODE
mode = 'TEST' if self.test_mode else 'LIVE'
self.secret_key = settings.MERCHANT_SETTINGS["pin"][mode]['SECRET']
self.secret_key = settings.MERCHANT_SETTINGS["pin"]['SECRET']
self.endpoint = self.endpoints[mode]
except (AttributeError, KeyError):
raise GatewayNotConfigured("The '%s' gateway is not correctly "
Expand All @@ -55,8 +54,6 @@ def _pin_response(self, resp, signal_type, obj=None):
success = resp.get('success', False)
status, signal = SSIG[success]
signal.send(sender=self, type=signal_type, response=resp)
if settings.DEBUG:
pprint.pprint(resp)
return {'status': status, 'response': resp, 'obj': obj}

def _pin_base(self, money, options):
Expand Down
22 changes: 7 additions & 15 deletions billing/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
from django.conf import settings
from django.db import models
from billing.utils.modules import get_module_names, get_models

MODELS = getattr(settings, 'MERCHANT_MODELS', None)

# Magic to import all active models
for module_name in get_module_names(__name__):
gateway = module_name.replace('_models', '')
if not MODELS or gateway in MODELS:
module = __import__('%s.%s' % (__name__, module_name), fromlist="*")
for model in get_models(module):
if model._meta.app_label.startswith('models.'):
model._meta.app_label = __name__.split(".")[0]
globals()[model.__name__] = model
from authorize_models import AuthorizeAIMResponse
from gc_models import GCNewOrderNotification
from world_pay_models import WorldPayResponse
from eway_models import EwayResponse
from amazon_fps_models import AmazonFPSResponse
from paylane_models import PaylaneTransaction, PaylaneAuthorization
from pin_models import PinCard, PinCustomer, PinCharge
3 changes: 3 additions & 0 deletions billing/models/amazon_fps_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@ class AmazonFPSResponse(models.Model):

def __unicode__(self):
return "%s : %s" % (self.transactionId, self.statusCode)

class Meta:
app_label = __name__.split(".")[0]
3 changes: 3 additions & 0 deletions billing/models/authorize_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,6 @@ class AuthorizeAIMResponse(models.Model):
shipping_country = models.CharField(max_length=64, blank=True)

card_code_response = models.CharField(max_length='8', choices=CARD_CODE_RESPONSES, help_text=u'Card Code Verification response')

class Meta:
app_label = __name__.split(".")[0]
2 changes: 1 addition & 1 deletion billing/models/eway_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@


class EwayResponse(models.Model):
pass
pass
3 changes: 3 additions & 0 deletions billing/models/gc_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,6 @@ class GCNewOrderNotification(models.Model):

created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)

class Meta:
app_label = __name__.split(".")[0]
7 changes: 7 additions & 0 deletions billing/models/paylane_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,17 @@ class PaylaneTransaction(models.Model):
def __unicode__(self):
return u'Transaction for %s (%s)' % (self.customer_name, self.customer_email)

class Meta:
app_label = __name__.split(".")[0]


class PaylaneAuthorization(models.Model):
sale_authorization_id = models.BigIntegerField(db_index=True)
first_authorization = models.BooleanField(default=False)
transaction = models.OneToOneField(PaylaneTransaction)

def __unicode__(self):
return u'Authorization: %s' % (self.sale_authorization_id)

class Meta:
app_label = __name__.split(".")[0]
27 changes: 21 additions & 6 deletions billing/models/pin_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
else:
User = get_user_model()


class PinCard(models.Model):
token = models.CharField(max_length=32, db_index=True, editable=False)
display_number = models.CharField(max_length=20, editable=False)
Expand All @@ -26,20 +27,28 @@ class PinCard(models.Model):
def __unicode__(self):
return 'Card %s' % self.display_number

class Meta:
app_label = __name__.split(".")[0]


class PinCustomer(models.Model):
token = models.CharField(unique=True, max_length=32)
card = models.ForeignKey(PinCard, related_name='customers')
card = models.ForeignKey("billing.PinCard", related_name='customers')
email = models.EmailField()
created_at = models.DateTimeField()
user = models.OneToOneField(User, related_name='pin_customer', blank=True, null=True)

def __unicode__(self):
return 'Customer %s' % self.email

class Meta:
app_label = __name__.split(".")[0]


class PinCharge(models.Model):
token = models.CharField(unique=True, max_length=32, editable=False)
card = models.ForeignKey(PinCard, related_name='charges', editable=False)
customer = models.ForeignKey(PinCustomer, related_name='customers', null=True, blank=True, editable=False)
card = models.ForeignKey("billing.PinCard", related_name='charges', editable=False)
customer = models.ForeignKey("billing.PinCustomer", related_name='customers', null=True, blank=True, editable=False)
success = models.BooleanField()
amount = models.DecimalField(max_digits=16, decimal_places=2)
currency = models.CharField(max_length=3)
Expand All @@ -48,23 +57,29 @@ class PinCharge(models.Model):
ip_address = models.IPAddressField()
created_at = models.DateTimeField()
status_message = models.CharField(max_length=255)
error_message = models.CharField(max_length=255)
error_message = models.CharField(max_length=255, null=True, blank=True)
user = models.ForeignKey(User, related_name='pin_charges', blank=True, null=True)

def __unicode__(self):
return 'Charge %s' % self.email

class Meta:
app_label = __name__.split(".")[0]


class PinRefund(models.Model):
token = models.CharField(unique=True, max_length=32)
charge = models.ForeignKey(PinCharge, related_name='refunds')
charge = models.ForeignKey("billing.PinCharge", related_name='refunds')
success = models.BooleanField()
amount = models.DecimalField(max_digits=16, decimal_places=2)
currency = models.CharField(max_length=3)
created_at = models.DateTimeField()
status_message = models.CharField(max_length=255)
error_message = models.CharField(max_length=255)
error_message = models.CharField(max_length=255, null=True, blank=True)
user = models.ForeignKey(User, related_name='pin_refunds', blank=True, null=True)

def __unicode__(self):
return 'Refund %s' % self.charge.email

class Meta:
app_label = __name__.split(".")[0]
3 changes: 3 additions & 0 deletions billing/models/world_pay_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,6 @@ class WorldPayResponse(models.Model):

card_type = models.CharField(max_length=64, blank=True)
ip_address = models.IPAddressField(blank=True, null=True)

class Meta:
app_label = __name__.split(".")[0]
4 changes: 2 additions & 2 deletions billing/tests/eway_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ def testPaymentSuccessfulSignal(self):
def receive(sender, **kwargs):
received_signals.append(kwargs.get("signal"))

transaction_was_successful.connect(receive)
transaction_was_unsuccessful.connect(receive)

resp = self.merchant.purchase(1, self.credit_card,
options=fake_options)
self.assertEquals(received_signals, [transaction_was_successful])
self.assertEquals(received_signals, [transaction_was_unsuccessful])

def testPaymentUnSuccessfulSignal(self):
received_signals = []
Expand Down
22 changes: 0 additions & 22 deletions billing/utils/modules.py

This file was deleted.

4 changes: 2 additions & 2 deletions docs/offsite/stripe_integration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ Example:
from billing.integrations.stripe_integration import StripeIntegration

class StripeExampleIntegration(StripeIntegration):
def transaction(self, request):
class transaction(self, request):
# The token is received in the POST request
resp = self.gateway.purchase(100, request.POST["stripeToken"])
resp = self.stripe_gateway.purchase(100, request.POST["stripeToken"])
if resp["status"] == "SUCCESS":
# Redirect if the transaction is successful
...
Expand Down
1 change: 1 addition & 0 deletions example/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,4 @@
STATIC_ROOT = os.path.join(os.path.dirname(__file__), "static")
STATICFILES_FINDER = ("django.contrib.staticfiles.finders.FileSystemFinder",
"django.contrib.staticfiles.finders.AppDirectoriesFinder")
USE_TZ = True

0 comments on commit 1a9e2f0

Please sign in to comment.