|
|
@@ -1,13 +1,107 @@
|
|
|
1
|
+import datetime
|
|
|
2
|
+from xml.dom.minidom import Document
|
|
|
3
|
+
|
|
|
4
|
+from django.conf import settings
|
|
|
5
|
+
|
|
1
|
6
|
|
|
2
|
7
|
class Gateway(object):
|
|
3
|
8
|
|
|
4
|
|
- def pre_auth(self, request):
|
|
|
9
|
+ def __init__(self, client, password):
|
|
|
10
|
+ self._client = client
|
|
|
11
|
+ self._password = password
|
|
|
12
|
+
|
|
|
13
|
+ def do_request(self, request_xml):
|
|
5
|
14
|
pass
|
|
6
|
15
|
|
|
7
|
|
- def auth(self, request):
|
|
|
16
|
+ def create_xml_doc(self):
|
|
|
17
|
+
|
|
|
18
|
+
|
|
|
19
|
+ return doc
|
|
|
20
|
+
|
|
|
21
|
+ def auth(self, card_number, expiry_date, amount, currency, merchant_reference, start_date=None):
|
|
|
22
|
+ doc = Document()
|
|
|
23
|
+ req = doc.createElement('Request')
|
|
|
24
|
+ doc.appendChild(req)
|
|
|
25
|
+
|
|
|
26
|
+ auth = doc.createElement('Authentication')
|
|
|
27
|
+ req.appendChild(auth)
|
|
|
28
|
+
|
|
|
29
|
+ client = doc.createElement('client')
|
|
|
30
|
+ auth.appendChild(client)
|
|
|
31
|
+ client_text = doc.createTextNode(self._client)
|
|
|
32
|
+ client.appendChild(client_text)
|
|
|
33
|
+
|
|
|
34
|
+ pw = doc.createElement('password')
|
|
|
35
|
+ auth.appendChild(pw)
|
|
|
36
|
+ pw_text = doc.createTextNode(self._password)
|
|
|
37
|
+ pw.appendChild(pw_text)
|
|
|
38
|
+
|
|
|
39
|
+ txn = doc.createElement('Transaction')
|
|
|
40
|
+ req.appendChild(txn)
|
|
|
41
|
+ card_txn = doc.createElement('CardTxn')
|
|
|
42
|
+ txn.appendChild(card_txn)
|
|
|
43
|
+ card = doc.createElement('Card')
|
|
|
44
|
+ card_txn.appendChild(card)
|
|
|
45
|
+
|
|
|
46
|
+ pan = doc.createElement('pan')
|
|
|
47
|
+ card.appendChild(pan)
|
|
|
48
|
+ pan_text = doc.createTextNode(card_number)
|
|
|
49
|
+ pan.appendChild(pan_text)
|
|
|
50
|
+
|
|
|
51
|
+ expiry = doc.createElement('expirydate')
|
|
|
52
|
+ card.appendChild(expiry)
|
|
|
53
|
+ expiry_text = doc.createTextNode(expiry_date)
|
|
|
54
|
+ expiry.appendChild(expiry_text)
|
|
|
55
|
+
|
|
|
56
|
+ if start_date:
|
|
|
57
|
+ start = doc.createElement('startdate')
|
|
|
58
|
+ card.appendChild(start)
|
|
|
59
|
+ start_text = doc.createTextNode(start_date)
|
|
|
60
|
+ start.appendChild(start_text)
|
|
|
61
|
+
|
|
|
62
|
+ txn_details = doc.createElement('TxnDetails')
|
|
|
63
|
+ txn.appendChild(txn_details)
|
|
|
64
|
+
|
|
|
65
|
+ merchant = doc.createElement('merchantreference')
|
|
|
66
|
+ txn_details.appendChild(merchant)
|
|
|
67
|
+ merchant_text = doc.createTextNode(merchant_reference)
|
|
|
68
|
+ merchant.appendChild(merchant_text)
|
|
|
69
|
+
|
|
|
70
|
+ amount_ele = doc.createElement('amount')
|
|
|
71
|
+ txn_details.appendChild(amount_ele)
|
|
|
72
|
+ amount_text = doc.createTextNode(str(amount))
|
|
|
73
|
+ amount_ele.appendChild(amount_text)
|
|
|
74
|
+ amount_ele.setAttribute('currency', currency)
|
|
|
75
|
+
|
|
|
76
|
+ method = doc.createElement('method')
|
|
|
77
|
+ card_txn.appendChild(method)
|
|
|
78
|
+ method_text = doc.createTextNode('auth')
|
|
|
79
|
+ method.appendChild(method_text)
|
|
|
80
|
+
|
|
|
81
|
+ self.do_request(doc.toxml())
|
|
|
82
|
+
|
|
|
83
|
+ def pre(self, request):
|
|
8
|
84
|
pass
|
|
9
|
85
|
|
|
10
|
86
|
def refund(self, request):
|
|
11
|
87
|
pass
|
|
12
|
88
|
|
|
13
|
89
|
|
|
|
90
|
+class Adapter(object):
|
|
|
91
|
+ """
|
|
|
92
|
+ Responsible for dealing with oscar objects
|
|
|
93
|
+ """
|
|
|
94
|
+
|
|
|
95
|
+ def __init__(self):
|
|
|
96
|
+ self.gateway = Gateway(settings.OSCAR_DATACASH_CLIENT, settings.OSCAR_DATACASH_PASSWORD)
|
|
|
97
|
+
|
|
|
98
|
+ def auth(self, order_number, amount, bankcard, billing_address):
|
|
|
99
|
+ response = self.gateway.auth(pan=bankcard.pan,
|
|
|
100
|
+ expiry_date=bankcard.expiry_date,
|
|
|
101
|
+ merchant_reference=self.generate_merchant_reference(order_number))
|
|
|
102
|
+
|
|
|
103
|
+ def generate_merchant_reference(self, order_number):
|
|
|
104
|
+ return '%s_%s' % (order_number, datetime.datetime.now().microsecond)
|
|
|
105
|
+
|
|
|
106
|
+
|
|
|
107
|
+
|