-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.py
More file actions
154 lines (142 loc) · 5.88 KB
/
test.py
File metadata and controls
154 lines (142 loc) · 5.88 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# -*- coding: utf-8 -*-
import datetime
import decimal
import urllib2
import urlparse
import mechanize
import payson_api
PAYSON_AGENT_ID = '1'
PAYSON_AGENT_KEY = 'fddb19ac-7470-42b6-a91d-072cb1495f0a'
return_url = "http://localhost/return_url"
cancel_url = "http://localhost/cancel_url"
receiver = payson_api.Receiver(email='testagent-1@payson.se',
firstName=u'Åke',
lastName=u'Öster',
amount=125,
primary=False)
def test_pay_transfer():
custom = ['list', 'of', 'custom', 'things', u'åäö']
api = payson_api.PaysonApi(PAYSON_AGENT_ID,
PAYSON_AGENT_KEY)
r = api.pay(returnUrl=return_url,
cancelUrl=cancel_url,
memo="test memo",
senderEmail='test-shopper@payson.se',
senderFirstName=u'Tester',
senderLastName=u'Räksmörgås',
receiverList=[receiver, ],
custom=custom,
fundingList=['BANK', 'CREDITCARD'],
localeCode='se',
currencyCode='SEK',
feesPayer='PRIMARYRECEIVER',
trackingId=u'ÅÄÖ',
guaranteeOffered='NO',
orderItemList=[payson_api.OrderItem('description item one',
1,
10,
5,
decimal.Decimal(0.25)),
payson_api.OrderItem('description item two',
2,
5,
10,
decimal.Decimal(0.25)), ])
assert r.token, r.responseEnvelope.errorList[0].message
assert isinstance(r.responseEnvelope.timestamp, datetime.datetime)
br = mechanize.Browser()
br.open(r.forward_pay_url)
br.select_form(nr=0)
br.form['QuickAgentCheckout1$rblPaymentMethod'] = ['SwedBank']
br.submit()
assert br.viewing_html()
try:
br.select_form(nr=0)
br.set_handle_redirect(False)
br.submit(name='btnAccept')
except urllib2.HTTPError, response:
location = response.hdrs.get('location')
try:
br.open(location)
except urllib2.HTTPError, response:
location = response.hdrs.get('location')
params = urlparse.parse_qs(location.split('?')[1])
assert 'token' in params, params
assert params['token'][0] == r.token, \
"%r != %r" % (params['token'], r.token)
finally:
br.set_handle_redirect(True)
r2 = api.payment_details(params['token'][0])
assert r2.success
assert r2.status == 'COMPLETED'
assert r2.custom == custom, custom
assert r2.trackingId == u'ÅÄÖ'
assert r2.receiverFee == decimal.Decimal('6.75')
def test_error():
api = payson_api.PaysonApi(PAYSON_AGENT_ID,
PAYSON_AGENT_KEY)
r = api.pay(returnUrl=return_url,
cancelUrl=cancel_url,
memo="test memo",
senderEmail='test-shopper@payson.se',
senderFirstName=u'Tester',
senderLastName=u'Räksmörgås',
receiverList=[receiver, ],
orderItemList=[payson_api.OrderItem('description item one',
1,
10,
5,
decimal.Decimal(0.25))])
assert not r.success
assert r.responseEnvelope.errorList[0].errorId == 590001
def test_pay_invoice():
api = payson_api.PaysonApi(PAYSON_AGENT_ID,
PAYSON_AGENT_KEY)
r = api.pay(returnUrl=return_url,
cancelUrl=cancel_url,
memo="test memo",
senderEmail='test-shopper@payson.se',
senderFirstName=u'Tester',
senderLastName=u'Räksmörgås',
receiverList=[receiver, ],
fundingList=['INVOICE', ],
orderItemList=[payson_api.OrderItem('description item one',
1,
10,
5,
decimal.Decimal(0.25)),
payson_api.OrderItem('description item two',
2,
5,
10,
decimal.Decimal(0.25)), ])
assert r.success, r.responseEnvelope.errorList[0].message
pnr = '230119-6412'
br = mechanize.Browser()
br.open(r.forward_pay_url)
br.select_form(nr=0)
br['QuickAgentCheckout1$txtSsn'] = pnr
br.submit()
try:
br.select_form(nr=0)
br.set_handle_redirect(False)
br.submit()
except urllib2.HTTPError, response:
location = response.hdrs.get('location')
params = urlparse.parse_qs(location.split('?')[1])
assert 'TOKEN' in params, params
assert params['TOKEN'][0] == r.token, \
"%r != %r" % (params['token'], r.token)
finally:
br.set_handle_redirect(True)
token = params['TOKEN'][0]
r2 = api.payment_details(token)
assert r2.success
assert r2.status == 'PENDING', r2.status
assert r2.invoiceStatus == 'ORDERCREATED', r2.invoiceStatus
assert r2.shippingAddress
assert api.payment_update(token, 'SHIPORDER')
r4 = api.payment_details(token)
assert r4.success
assert r4.status == 'PENDING', r4.status
assert r4.invoiceStatus == 'SHIPPED', r4.invoiceStatus