Skip to content

Commit ad185ae

Browse files
author
Craig Christenson
committed
Adding sandbox support for Admin API
1 parent 738f2a7 commit ad185ae

3 files changed

Lines changed: 30 additions & 25 deletions

File tree

setup.py

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from distutils.core import setup
44
setup(
55
name="twocheckout",
6-
version='0.2.0',
6+
version='0.2.1',
77
description="2Checkout Python Library",
88
author="Craig Christenson",
99
author_email="christensoncraig@gmail.com",

test/test_twocheckout.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
}
2929

3030
EXAMPLE_SALE = {
31-
'sale_id': 4774380224
31+
'sale_id': 9093717691800
3232
}
3333

3434
EXAMPLE_COMMENT = {
@@ -62,7 +62,7 @@
6262

6363
EXAMPLE_AUTH = {
6464
'merchantOrderId': '123',
65-
'token': 'ZDBiNGFkYzMtZGIzNi00MDMwLWIwMTctNTAzOGFhOTU1ODJm',
65+
'token': 'NTQyZTQyOTMtNjA0Ni00NzM4LTkyNDItNjVlMmUzZTU2NTNj',
6666
'currency': 'USD',
6767
'total': '1.00',
6868
'billingAddr': {
@@ -82,14 +82,15 @@ def setUp(self):
8282
super(TwocheckoutTestCase, self).setUp()
8383

8484
twocheckout.Api.credentials({
85-
'username': 'APIuser1817037',
86-
'password': 'APIpass1817037'
85+
'username': 'testlibraryapi901248204',
86+
'password': 'testlibraryapi901248204PASS',
87+
'mode': 'sandbox'
8788
})
8889

8990
twocheckout.Api.auth_credentials({
90-
'private_key': '9999999',
91-
'seller_id': '532001',
92-
'mode': 'production'
91+
'private_key': 'BE632CB0-BB29-11E3-AFB6-D99C28100996',
92+
'seller_id': '901248204',
93+
'mode': 'sandbox'
9394
})
9495

9596
class SaleTest(TwocheckoutTestCase):
@@ -99,22 +100,22 @@ def setUp(self):
99100
def test_1_find_sale(self):
100101
try:
101102
sale = twocheckout.Sale.find(EXAMPLE_SALE)
102-
self.assertEqual(int(sale.sale_id), 4774380224)
103+
self.assertEqual(int(sale.sale_id), 9093717691800)
103104
except TwocheckoutError as error:
104105
self.assertEqual(error.message, "Unable to find record.")
105106

106107
def test_2_list_sale(self):
107-
params = {'pagesize': 3}
108+
params = {'pagesize': 2}
108109
list = twocheckout.Sale.list(params)
109-
self.assertEqual(len(list), 3)
110+
self.assertEqual(len(list), 2)
110111

111112
def test_3_refund_sale(self):
112113
try:
113114
sale = twocheckout.Sale.find(EXAMPLE_SALE)
114115
result = sale.refund(EXAMPLE_REFUND)
115116
self.assertEqual(result.message, "refund added to invoice")
116117
except TwocheckoutError as error:
117-
self.assertEqual(error.message, "Invoice too old to refund.")
118+
self.assertEqual(error.message, "Invoice was already refunded.")
118119

119120
def test_4_refund_invoice(self):
120121
try:
@@ -123,7 +124,7 @@ def test_4_refund_invoice(self):
123124
result = invoice.refund(EXAMPLE_REFUND)
124125
self.assertEqual(result.message, "refund added to invoice")
125126
except TwocheckoutError as error:
126-
self.assertEqual(error.message, "Invoice too old to refund.")
127+
self.assertEqual(error.message, "Invoice was already refunded.")
127128

128129
def test_5_refund_lineitem(self):
129130
try:
@@ -199,9 +200,9 @@ def test_4_delete(self):
199200
self.assertEqual(result.response_message, "Product successfully deleted.")
200201

201202
def test_5_list(self):
202-
params = {'pagesize': 3}
203+
params = {'pagesize': 2}
203204
list = twocheckout.Product.list(params)
204-
self.assertEqual(len(list), 3)
205+
self.assertEqual(len(list), 2)
205206

206207
class OptionTest(TwocheckoutTestCase):
207208
def setUp(self):
@@ -263,23 +264,23 @@ def setUp(self):
263264

264265
def test_1_retrieve(self):
265266
company = twocheckout.Company.retrieve()
266-
self.assertEqual(company.vendor_id, "1817037")
267+
self.assertEqual(company.vendor_id, "901248204")
267268

268269
class ContactTest(TwocheckoutTestCase):
269270
def setUp(self):
270271
super(ContactTest, self).setUp()
271272

272273
def test_1_create(self):
273274
contact = twocheckout.Contact.retrieve()
274-
self.assertEqual(contact.vendor_id, "1817037")
275+
self.assertEqual(contact.vendor_id, "901248204")
275276

276277
class PaymentTest(TwocheckoutTestCase):
277278
def setUp(self):
278279
super(PaymentTest, self).setUp()
279280

280281
def test_1_pending(self):
281282
payment = twocheckout.Payment.pending()
282-
self.assertEqual(payment.release_level, "100")
283+
self.assertEqual(payment.release_level, "300")
283284

284285
def test_2_list(self):
285286
payments = twocheckout.Payment.list()

twocheckout/api_request.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,14 @@ def set_opts(cls, method, params=None):
4949
else:
5050
username = cls.username
5151
password = cls.password
52+
if cls.mode == 'sandbox':
53+
passwd_url = 'https://sandbox.2checkout.com'
54+
else:
55+
passwd_url = 'https://www.2checkout.com'
5256
data = urllib.urlencode(params)
5357
password_manager = urllib2.HTTPPasswordMgrWithDefaultRealm()
5458
password_manager.add_password(
55-
None, 'https://www.2checkout.com', username, password
59+
None, passwd_url, username, password
5660
)
5761
auth_handler = urllib2.HTTPBasicAuthHandler(password_manager)
5862
opener = urllib2.build_opener(auth_handler)
@@ -76,12 +80,12 @@ def build_headers(cls, method):
7680

7781
@classmethod
7882
def build_url(cls, method):
83+
if cls.mode == 'sandbox':
84+
url = 'https://sandbox.2checkout.com'
85+
else:
86+
url = 'https://www.2checkout.com'
7987
if method == 'authService':
80-
if cls.mode == 'sandbox':
81-
url = 'https://sandbox.2checkout.com/checkout/api/'
82-
else:
83-
url = 'https://www.2checkout.com/checkout/api/'
84-
url += cls.version + '/' + cls.seller_id + '/rs/' + method
88+
url += '/checkout/api/' + cls.version + '/' + cls.seller_id + '/rs/' + method
8589
else:
86-
url = 'https://www.2checkout.com/api/' + method
90+
url += '/api/' + method
8791
return url

0 commit comments

Comments
 (0)