-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
347 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
*.pyo | ||
*.pyc | ||
.installed.cfg | ||
bin | ||
develop-eggs | ||
dist | ||
downloads | ||
eggs | ||
parts | ||
src/*.egg-info | ||
lib | ||
lib64 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
""" | ||
Django settings for checkout_django_example project. | ||
For more information on this file, see | ||
https://docs.djangoproject.com/en/1.6/topics/settings/ | ||
For the full list of settings and their values, see | ||
https://docs.djangoproject.com/en/1.6/ref/settings/ | ||
""" | ||
|
||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...) | ||
import os | ||
BASE_DIR = os.path.dirname(os.path.dirname(__file__)) | ||
TEMPLATE_DIRS = os.path.join(BASE_DIR, 'templates/') | ||
|
||
# Quick-start development settings - unsuitable for production | ||
# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/ | ||
|
||
# SECURITY WARNING: keep the secret key used in production secret! | ||
SECRET_KEY = 'd1x_1g+jl!9aenji(k8mh--lqgs-*dh#&tygrq_5bfd14+06(x' | ||
|
||
# SECURITY WARNING: don't run with debug turned on in production! | ||
DEBUG = True | ||
|
||
TEMPLATE_DEBUG = True | ||
|
||
ALLOWED_HOSTS = [] | ||
|
||
|
||
# Application definition | ||
|
||
INSTALLED_APPS = ( | ||
'django.contrib.admin', | ||
'django.contrib.auth', | ||
'django.contrib.contenttypes', | ||
'django.contrib.sessions', | ||
'django.contrib.messages', | ||
'django.contrib.staticfiles', | ||
) | ||
|
||
MIDDLEWARE_CLASSES = ( | ||
'django.contrib.sessions.middleware.SessionMiddleware', | ||
'django.middleware.common.CommonMiddleware', | ||
'django.middleware.csrf.CsrfViewMiddleware', | ||
'django.contrib.auth.middleware.AuthenticationMiddleware', | ||
'django.contrib.messages.middleware.MessageMiddleware', | ||
'django.middleware.clickjacking.XFrameOptionsMiddleware', | ||
) | ||
|
||
ROOT_URLCONF = 'checkout_django_example.urls' | ||
|
||
WSGI_APPLICATION = 'checkout_django_example.wsgi.application' | ||
|
||
|
||
# Database | ||
# https://docs.djangoproject.com/en/1.6/ref/settings/#databases | ||
|
||
DATABASES = { | ||
'default': { | ||
'ENGINE': 'django.db.backends.sqlite3', | ||
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), | ||
} | ||
} | ||
|
||
# Internationalization | ||
# https://docs.djangoproject.com/en/1.6/topics/i18n/ | ||
|
||
LANGUAGE_CODE = 'en-us' | ||
|
||
TIME_ZONE = 'UTC' | ||
|
||
USE_I18N = True | ||
|
||
USE_L10N = True | ||
|
||
USE_TZ = True | ||
|
||
|
||
# Static files (CSS, JavaScript, Images) | ||
# https://docs.djangoproject.com/en/1.6/howto/static-files/ | ||
|
||
STATIC_URL = '/static/' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from django.conf.urls import patterns, include, url | ||
|
||
from django.contrib import admin | ||
admin.autodiscover() | ||
|
||
urlpatterns = patterns('', | ||
# Examples: | ||
# url(r'^$', 'checkout_django_example.views.home', name='home'), | ||
# url(r'^blog/', include('blog.urls')), | ||
|
||
url(r'^onsite/', 'checkoutapp.views.onsite'), | ||
url(r'^offsite/', 'checkoutapp.views.offsite'), | ||
url(r'^return/', 'checkoutapp.views.returnpayment'), | ||
url(r'^$', 'checkoutapp.views.index') | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
""" | ||
WSGI config for checkout_django_example project. | ||
It exposes the WSGI callable as a module-level variable named ``application``. | ||
For more information on this file, see | ||
https://docs.djangoproject.com/en/1.6/howto/deployment/wsgi/ | ||
""" | ||
|
||
import os | ||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "checkout_django_example.settings") | ||
|
||
from django.core.wsgi import get_wsgi_application | ||
application = get_wsgi_application() |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.contrib import admin | ||
|
||
# Register your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.db import models | ||
|
||
# Create your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
# -*- coding: utf-8 -*- | ||
import time | ||
from django.http import HttpResponse | ||
from django.shortcuts import render | ||
|
||
from checkout import ( | ||
Checkout, | ||
Contact, | ||
Payment, | ||
CheckoutException | ||
) | ||
|
||
|
||
def onsite(request): | ||
# Create a Contact object (Optional) | ||
contact = Contact( | ||
first_name='Matti', | ||
last_name='Meikäläinen', | ||
email='matti.meikalainen@gmail.com', | ||
address='Esimerkkikatu 123', | ||
postcode='01234', | ||
postoffice='Helsinki', | ||
country='FIN', | ||
phone='020123456', | ||
) | ||
# Create a Payment object | ||
payment = Payment( | ||
order_number=str(int(time.time())), | ||
reference_number='9999999', | ||
amount='200', | ||
delivery_date='20140606', | ||
message='Esimerkkimaksun kuvaus', | ||
currency='EUR', | ||
language='FI', | ||
content='1', | ||
return_url='https://www.esimerkkikauppa.fi/sv/return', | ||
cancel_url='https://www.esimerkkikauppa.fi/sv/cancel', | ||
delayed_url='https://www.esimerkkikauppa.fi/sv/delayed', | ||
reject_url='https://www.esimerkkikauppa.fi/sv/reject', | ||
contact=contact | ||
) | ||
# Create a Checkout object | ||
checkout = Checkout() | ||
# Fetch data for different payment providers for created payment | ||
data = checkout.get_onsite_button_data(payment) | ||
# Render with template | ||
return render(request, "onsite.html", { 'banks': data}) | ||
|
||
def offsite(request): | ||
# Create a Contact object (Optional) | ||
contact = Contact( | ||
first_name='Matti', | ||
last_name='Meikäläinen', | ||
email='matti.meikalainen@gmail.com', | ||
address='Esimerkkikatu 123', | ||
postcode='01234', | ||
postoffice='Helsinki', | ||
country='FIN', | ||
phone='020123456', | ||
) | ||
# Create a Payment object | ||
payment = Payment( | ||
order_number=str(int(time.time())), | ||
reference_number='9999999', | ||
amount='200', | ||
delivery_date='20140606', | ||
message='Esimerkkimaksun kuvaus', | ||
currency='EUR', | ||
language='FI', | ||
content='1', | ||
return_url='https://www.esimerkkikauppa.fi/sv/return', | ||
cancel_url='https://www.esimerkkikauppa.fi/sv/cancel', | ||
delayed_url='https://www.esimerkkikauppa.fi/sv/delayed', | ||
reject_url='https://www.esimerkkikauppa.fi/sv/reject', | ||
contact=contact | ||
) | ||
# Create a Checkout object | ||
checkout = Checkout() | ||
# Fetch data for different payment providers for created payment | ||
data = checkout.get_offsite_button_data(payment) | ||
# Render with template | ||
return render(request, "offsite.html", { 'formfields': data}) | ||
|
||
def returnpayment(request): | ||
# Create a Checkout object | ||
checkout = Checkout() | ||
params = request.GET | ||
if not checkout.validate_payment_return(params['MAC'], params['VERSION'], params['STAMP'], params['REFERENCE'], params['PAYMENT'], params['STATUS'], params['ALGORITHM']): | ||
return HttpResponse("MAC check failed") | ||
else: | ||
if params['STATUS'] in ["2", "5", "6", "8", "9", "10"]: | ||
return HttpResponse("Payment complete, status code: " + params['STATUS']) | ||
elif params['STATUS'] == "3": | ||
return HttpResponse("Payer chose delayed payment, status code: " + params['STATUS']) | ||
elif params['STATUS'] == "-1": | ||
return HttpResponse("Payment cancelled, status code: " + params['STATUS']) | ||
elif params['STATUS'] == "7": | ||
return HttpResponse("Manual activation requeired, status code: " + params['STATUS']) | ||
else: | ||
return HttpResponse("Unknown status code: " + params['STATUS']) | ||
|
||
def index(request): | ||
return render(request, "index.html") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/usr/bin/env python | ||
import os | ||
import sys | ||
|
||
if __name__ == "__main__": | ||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "checkout_django_example.settings") | ||
|
||
from django.core.management import execute_from_command_line | ||
|
||
execute_from_command_line(sys.argv) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!DOCTYPE html> | ||
<head> | ||
<title>Checkout Django example app</title> | ||
</head> | ||
<body> | ||
<h1>Checkout Django example</h1> | ||
<a href="onsite/">Onsite payment</a><br> | ||
<a href="offsite/">Offsite payment</a> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<html> | ||
<body> | ||
<form action='https://payment.checkout.fi/' method='post'> | ||
{% for fieldname, fieldvalue in formfields.items %} | ||
<input type='hidden' name='{{ fieldname }}' value='{{ fieldvalue }}'> | ||
{% endfor %} | ||
<input type='submit' value='Siirry maksusivulle'> | ||
</form> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> | ||
<html> | ||
<head> | ||
<title>Checkout maksudemo</title> | ||
<style type="text/css"> | ||
.C1 { | ||
width: 180px; | ||
height: 120px; | ||
border: 1pt solid #a0a0a0; | ||
display: block; | ||
float: left; | ||
margin: 7px; | ||
-moz-border-radius: 5px; | ||
-webkit-border-radius: 5px; | ||
border-radius: 5px; | ||
clear: none; | ||
padding: 0; | ||
} | ||
|
||
.C1:hover { | ||
background-color: #f0f0f0; | ||
border-color: black; | ||
} | ||
|
||
.C1 form { | ||
width: 180px; | ||
height: 120px; | ||
} | ||
|
||
.C1 form span { | ||
display: table-cell; | ||
vertical-align: middle; | ||
height: 92px; | ||
width: 180px; | ||
} | ||
|
||
.C1 form span input { | ||
margin-left: auto; | ||
margin-right: auto; | ||
display: block; | ||
border: 1pt solid #f2f2f2; | ||
-moz-border-radius: 5px; | ||
-webkit-border-radius: 5px; | ||
border-radius: 5px; | ||
padding: 5px; | ||
background-color: white; | ||
} | ||
|
||
.C1:hover form span input { | ||
border: 1pt solid black; | ||
} | ||
|
||
.C1 div { | ||
text-align: center; | ||
font-family: arial; | ||
font-size: 8pt; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<h1>Checkout API example</h1> | ||
<h2>Maksunapit verkkosivulle, suositeltu tapa / XML API, Recommended | ||
method</h2> | ||
|
||
{% for bank in banks %} | ||
<div class='C1'> | ||
<form action='{{ bank.url }}' method='post'> | ||
{% for fieldname, fieldvalue in bank.fields.items %} | ||
<input type='hidden' name='{{ fieldname }}' value='{{ fieldvalue }}'> | ||
{% endfor %} | ||
<span><input type='image' src='{{ bank.icon }}'> </span> | ||
<div> | ||
{{ bank.name }} | ||
</div> | ||
</form> | ||
</div> | ||
{% endfor %} | ||
<hr style='clear: both;'> | ||
</body> | ||
</html> | ||
|