1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
from collections import namedtuple
try:
from django.db.models import get_model
except ImportError:
from django.apps import apps
get_model = apps.get_model
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.utils.translation import pgettext_lazy
PurchasedItem = namedtuple('PurchasedItem',
'name, quantity, price, currency, sku')
class PaymentStatus:
WAITING = 'waiting'
PREAUTH = 'preauth'
CONFIRMED = 'confirmed'
REJECTED = 'rejected'
REFUNDED = 'refunded'
ERROR = 'error'
INPUT = 'input'
CHOICES = [
(WAITING, pgettext_lazy('payment status', 'Waiting for confirmation')),
(PREAUTH, pgettext_lazy('payment status', 'Pre-authorized')),
(CONFIRMED, pgettext_lazy('payment status', 'Confirmed')),
(REJECTED, pgettext_lazy('payment status', 'Rejected')),
(REFUNDED, pgettext_lazy('payment status', 'Refunded')),
(ERROR, pgettext_lazy('payment status', 'Error')),
(INPUT, pgettext_lazy('payment status', 'Input'))]
class FraudStatus:
UNKNOWN = 'unknown'
ACCEPT = 'accept'
REJECT = 'reject'
REVIEW = 'review'
CHOICES = [
(UNKNOWN, pgettext_lazy('fraud status', 'Unknown')),
(ACCEPT, pgettext_lazy('fraud status', 'Passed')),
(REJECT, pgettext_lazy('fraud status', 'Rejected')),
(REVIEW, pgettext_lazy('fraud status', 'Review'))]
class RedirectNeeded(Exception):
pass
class PaymentError(Exception):
def __init__(self, message, code=None, gateway_message=None):
super(PaymentError, self).__init__(message)
self.code = code
self.gateway_message = gateway_message
class ExternalPostNeeded(Exception):
pass
def get_payment_model():
'''
Return the Payment model that is active in this project
'''
try:
app_label, model_name = settings.PAYMENT_MODEL.split('.')
except (ValueError, AttributeError):
raise ImproperlyConfigured('PAYMENT_MODEL must be of the form '
'"app_label.model_name"')
payment_model = get_model(app_label, model_name)
if payment_model is None:
msg = (
'PAYMENT_MODEL refers to model "%s" that has not been installed' %
settings.PAYMENT_MODEL)
raise ImproperlyConfigured(msg)
return payment_model
|