Skip to content

Commit

Permalink
First pypi release
Browse files Browse the repository at this point in the history
  • Loading branch information
nwolff committed Jul 4, 2018
1 parent 7bdf846 commit ee4b443
Show file tree
Hide file tree
Showing 13 changed files with 116 additions and 33 deletions.
23 changes: 23 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
language: python
matrix:
include:
- python: '3.5'
env: TOXENV=py35-django207-test
- python: '3.6'
env: TOXENV=py36-django207-test
- python: '3.5'
env: TOXENV=py35-django207-checkmigrations
- python: '3.5'
env: TOXENV=py35-django207-flake
install:
- pip install tox
script:
- tox
deploy:
provider: pypi
user: skioo
password:
secure: TLVygdPWAdjyqMpcQoNMUGfsf2OTouc2FygktGIkSH86jj4nwsHFEvELtscoNwXbDABWt6mC1k9zvTFCWrH718FQgoZmLZw59sWNNaXnYCmCgeU2lxOsg5V8D0bLVgV7bheJ9kPCa6tphaop8R+fmCQht50wWDhXS9AK51EucspffEL1OaUbShhteUkJXctadn+P3KaFWEJBGX+AJyCsCxtTYlN9EzHbil6SPpSddthiqiGSg3KBdxKeKlB+B4rP+e7PQGnEE4TPGS293DZDDo8yLzJi4YDtCpjQDuOxFMyWskzj21WlLMY5UW8rqMydMY/OTyfRdUYZXvcl9GGBFMc/ZgMsI5vcdCRbOMsBdOg1mMiuw6IWwuAAU0eNn10IE3E56AxiRDK4W8V7B5qTk60zHQbYb8K3nxXl8y+lFL0oy0EX/JwX8ECnb1Dpc+MWVawrAQAPAQuR/Y+JZhmycKwI0qxe3957HS1zeVgB3SMT62c+as1wvRu11o+DZfSn4qMq+QzjFpcQLqriSjPSzRGHO41py7leNRtyxBmnBFKzLkVCzNjRvgrrFn5i5YZnYmV826umQNh0khC7w3S5Eh46w1pfnfNlFcUUtEiapKZdXrJVaTgIYHa06acgjEFZMzXDUsFFRk4LTbIrV2zJq/td0X9F4foCnbbj6CvWSmg=
distribution: sdist bdist_wheel
on:
tags: true
11 changes: 4 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
django-netaxept-gateway
=======================

Tested on python 3.5 and django 2.0.4
Tested on python 3.5 and django 2.0.7


Installation
------------

pip install -e git+git://github.com/skioo/django-netaxept-gateway.git#egg=django-netaxept-gateway
pip install django-netaxept-gateway


Configuration
Expand All @@ -33,7 +33,7 @@ IMPORTANT

- Amounts are in smallest currenty unit. For instance one NOK is represented in netaxept as "100 NOK".

- Payment objects have a `success` field that indicated whether the payment was _registered_ without error, it says nothing about whether we got the money or not
- Payment objects have a `success` field that indicate whether the payment was _registered_ without error, it says nothing about whether we got the money or not
(To receive money the payment needs to go thru `auth` then `capture` , or thru `sale`).


Expand All @@ -49,7 +49,6 @@ API details: https://shop.nets.eu/web/partners/appi
Test card numbers: https://shop.nets.eu/web/partners/test-cards



Design
------

Expand All @@ -59,10 +58,8 @@ We don't allow payment registration with `autoSale` because it becomes very diff
TODO
----

- Unit tests that pass, and that cover most of the functionality.
- Unit tests
- On prod (where debug is turned off), errors in the admin after invoking the gateway are shown as a useless grey page.
- Store in the database the callback url requested by a payment.
- Store in the database that a payment requested-auto-auth.


To work on this code
Expand Down
5 changes: 4 additions & 1 deletion netaxept/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
__version__ = '0.0.1'
__version__ = '0.0.2'
__copyright__ = 'Copyright (c) 2018, skioo SA'
__license__ = 'MIT'
__URL__ = 'https://github.com/skioo/django-netaxept-gateway'
14 changes: 8 additions & 6 deletions netaxept/actions/payments.py → netaxept/actions.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import suds
from structlog import get_logger

from ..gateway import do_register, do_process
from ..models import Payment, Operation
from .gateway import do_register, do_process
from .models import Payment, Operation

logger = get_logger()

Expand Down Expand Up @@ -52,16 +52,18 @@ def register(order_number, amount, currency_code, redirect_url, description=None
amount=amount,
currency_code=currency_code,
order_number=order_number,
description=description
description=description,
redirect_url=redirect_url,
auto_auth=auto_auth
)
try:
response = do_register(
order_number=payment.order_number,
amount=payment.amount,
currency_code=payment.currency_code,
description=payment.description,
redirect_url=redirect_url,
auto_auth=auto_auth)
redirect_url=payment.redirect_url,
auto_auth=payment.auto_auth)
payment.transaction_id = response.TransactionId
payment.success = True
except suds.WebFault as e:
Expand Down Expand Up @@ -161,7 +163,7 @@ def credit(payment_id, amount=None):
def _handle_operation(operation):
try:
# XXX: Should read the response and not only rely on the REST exception.
response = do_process(
do_process(
transaction_id=operation.transaction_id,
operation=operation.operation,
amount=getattr(operation, 'amount', None),
Expand Down
Empty file removed netaxept/actions/__init__.py
Empty file.
12 changes: 6 additions & 6 deletions netaxept/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from django.urls import reverse
from django.utils.html import format_html

from .actions import payments
from . import actions
from .models import Payment, Operation


Expand Down Expand Up @@ -57,7 +57,7 @@ def auth_payment_form(request, payment_id):
if request.method == 'POST':
form = AuthPaymentForm(request.POST)
if form.is_valid():
result = payments.auth(
result = actions.auth(
payment_id=payment_id)
# As confirmation we take the user to the edit page of the auth operation.
return HttpResponseRedirect(reverse('admin:netaxept_operation_change', args=[result.id]))
Expand Down Expand Up @@ -85,7 +85,7 @@ def capture_payment_form(request, payment_id):
if request.method == 'POST':
form = CapturePaymentForm(request.POST)
if form.is_valid():
result = payments.capture(
result = actions.capture(
payment_id=payment_id,
amount=form.cleaned_data['amount'])
# As confirmation we take the user to the edit page of the capture operation.
Expand Down Expand Up @@ -114,7 +114,7 @@ def credit_payment_form(request, payment_id):
if request.method == 'POST':
form = CreditPaymentForm(request.POST)
if form.is_valid():
result = payments.credit(
result = actions.credit(
payment_id=payment_id,
amount=form.cleaned_data['amount'])
# As confirmation we take the user to the edit page of the credit operation.
Expand All @@ -136,8 +136,8 @@ def credit_payment_form(request, payment_id):
@admin.register(Payment)
class PaymentAdmin(admin.ModelAdmin):
date_hierarchy = 'created'
list_display = ['created', 'success', 'amount', 'currency_code', 'order_number', 'description', 'transaction_id',
operation_count]
list_display = ['created', 'success', 'amount', 'currency_code', 'order_number', 'description', 'redirect_url',
'transaction_id', operation_count]
search_fields = ['transaction_id', 'order_number', 'amount', 'description']
list_filter = ['success', 'currency_code']

Expand Down
25 changes: 25 additions & 0 deletions netaxept/migrations/0003_payment_authoauth_and_redirecturl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 2.0.4 on 2018-07-04 03:05

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('netaxept', '0002_auto_20180408_1151'),
]

operations = [
migrations.AddField(
model_name='payment',
name='auto_auth',
field=models.BooleanField(default=False),
preserve_default=False,
),
migrations.AddField(
model_name='payment',
name='redirect_url',
field=models.CharField(default='unknown', max_length=255),
preserve_default=False,
),
]
2 changes: 2 additions & 0 deletions netaxept/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class Payment(TransactionBase):
amount = models.PositiveIntegerField()
currency_code = models.CharField(max_length=3)
description = models.CharField(max_length=255, null=True, blank=True)
redirect_url = models.CharField(max_length=255)
auto_auth = models.BooleanField()

def __str__(self):
return '{} {} - {}'.format(self.amount, self.currency_code, self.transaction_id)
Expand Down
2 changes: 1 addition & 1 deletion netaxept/views/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from django.shortcuts import redirect, render

from netaxept.gateway import get_payment_terminal_url
from ..actions.payments import register
from ..actions import register


class PayForm(forms.Form):
Expand Down
11 changes: 9 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,28 @@
setup(
name='django-netaxept-gateway',
version=netaxept.__version__,
description='Integrate django with the netaxept payment service provider',
long_description='',
author='Nicholas Wolff',
author_email='nwolff@gmail.com',
url=netaxept.__URL__,
download_url='https://pypi.python.org/pypi/django-datatrans-gateway',
install_requires=[
'Django>=1.8',
'Django>=2.0',
'structlog',
'suds2',
'requests',
],
packages=[
'netaxept',
'netaxept.migrations',
'netaxept.actions',
'netaxept.views',
],
package_data={'netaxept': [
'templates/admin/netaxept/*.html',
'templates/netaxept/example/*.html',
]},
licence=netaxept.__license__,
classifiers=[
'Development Status :: 4 - Beta',
'Environment :: Web Environment',
Expand All @@ -30,6 +36,7 @@
'License :: OSI Approved :: BSD License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
],
)
Empty file removed tests/actions/__init__.py
Empty file.
23 changes: 13 additions & 10 deletions tests/actions/test_payments.py → tests/test_actions.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
from django.test import TestCase
from pytest import raises
from pytest import raises, mark

from netaxept.actions import payments
from netaxept.actions.payments import PaymentRegistrationNotCompleted
from netaxept import actions
from netaxept.actions import PaymentRegistrationNotCompleted
from netaxept.models import Payment


class PaymentTest(TestCase):

def test_invalid_state(self):
@mark.skip('because it tries to invoke the real netaxept gateway')
def test_a_successful_payment_can_go_on_thru_sale(self):
payment = Payment.objects.create(
transaction_id='1234567890',
order_number='an-order-number',
amount=100,
currency_code='NOK',
success=False)
with raises(PaymentRegistrationNotCompleted):
payments.sale(payment.id)
success=True,
auto_auth=False)
actions.sale(payment.id)

def test_valid_state(self):
def test_an_unsuccesful_payment_cannot_go_on_thru_sale(self):
payment = Payment.objects.create(
transaction_id='1234567890',
order_number='an-order-number',
amount=100,
currency_code='NOK',
success=True)
payments.sale(payment.id)
success=False,
auto_auth=False)
with raises(PaymentRegistrationNotCompleted):
actions.sale(payment.id)
21 changes: 21 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[tox]
envlist =
{py35,py36}-{django207}-test
py35-django202-{checkmigrations,flake,mypy}

[testenv]
basepython =
py35: python3.5
py36: python3.6
commands =
test: py.test tests
checkmigrations: ./manage.py makemigrations --check --dry-run
flake: flake8
deps =
django207: Django>=2.0.7,<2.1
structlog
suds2
requests
pytest-django
flake: flake8
mypy

0 comments on commit ee4b443

Please sign in to comment.