|
4 | 4 |
|
5 | 5 |
|
6 | 6 | class Charge(Twocheckout): |
| 7 | + |
| 8 | + checkout_url = "https://www.2checkout.com/checkout/purchase" |
| 9 | + |
7 | 10 | def __init__(self, dict_): |
8 | 11 | super(self.__class__, self).__init__(dict_) |
9 | 12 |
|
10 | 13 | @classmethod |
11 | | - def form(cls, params=None): |
| 14 | + def mode(cls, mode): |
| 15 | + if mode == 'sandbox': |
| 16 | + Charge.checkout_url = 'https://sandbox.2checkout.com/checkout/purchase' |
| 17 | + else: |
| 18 | + Charge.checkout_url = 'https://www.2checkout.com/checkout/purchase' |
| 19 | + |
| 20 | + @classmethod |
| 21 | + def form(cls, params=None, text='Proceed to Checkout'): |
12 | 22 | if params is None: |
13 | 23 | params = dict() |
14 | | - form = "<form id=\"2checkout\" action=\"https://www.2checkout.com/checkout/purchase\" method=\"post\">\n" |
| 24 | + form = "<form id=\"2checkout\" action=\"" + Charge.checkout_url + "\" method=\"post\">" |
15 | 25 | for param in params: |
16 | | - form = form + "<input type=\"hidden\" name=\"" + param + "\" value=\"" + str(params[param]) + "\" />\n" |
17 | | - return form + "<input type=\"submit\" value=\"Proceed to Checkout\" />\n</form>\n" |
| 26 | + form = form + "<input type=\"hidden\" name=\"" + param + "\" value=\"" + str(params[param]) + "\" />" |
| 27 | + return form + "<input type=\"submit\" value=\"" + text + "\" /></form>" |
18 | 28 |
|
19 | 29 | @classmethod |
20 | | - def submit(cls, params=None): |
| 30 | + def submit(cls, params=None, text='Proceed to Checkout'): |
21 | 31 | if params is None: |
22 | 32 | params = dict() |
23 | | - form = "<form id=\"2checkout\" action=\"https://www.2checkout.com/checkout/purchase\" method=\"post\">\n" |
| 33 | + form = "<form id=\"2checkout\" action=\"" + Charge.checkout_url + "\" method=\"post\">" |
24 | 34 | for param in params: |
25 | | - form = form + "<input type=\"hidden\" name=\"" + param + "\" value=\"" + str(params[param]) + "\" />\n" |
26 | | - return form + "<input type=\"submit\" value=\"Proceed to Checkout\" />\n</form>\n" + \ |
27 | | - "<script type=\"text/javascript\">document.getElementById('2checkout').submit();</script>" |
| 35 | + form = form + "<input type=\"hidden\" name=\"" + param + "\" value=\"" + str(params[param]) + "\" />" |
| 36 | + return form + "<input type=\"submit\" value=\"" + text + "\" /></form>" + \ |
| 37 | + "<script type=\"text/javascript\">document.getElementById(\"2checkout\").submit();</script>" |
28 | 38 |
|
29 | 39 | @classmethod |
30 | | - def direct(cls, params=None): |
| 40 | + def direct(cls, params=None, text='Proceed to Checkout'): |
31 | 41 | if params is None: |
32 | 42 | params = dict() |
33 | | - form = "<form id=\"2checkout\" action=\"https://www.2checkout.com/checkout/purchase\" method=\"post\">\n" |
| 43 | + form = "<form id=\"2checkout\" action=\"" + Charge.checkout_url + "\" method=\"post\">" |
34 | 44 | for param in params: |
35 | | - form = form + "<input type=\"hidden\" name=\"" + param + "\" value=\"" + str(params[param]) + "\" />\n" |
36 | | - return form + "<input type=\"submit\" value=\"Proceed to Checkout\" />\n</form>\n" + \ |
37 | | - "<script src=\"https://www.2checkout.com/static/checkout/javascript/direct.min.js\"></script>" |
| 45 | + form = form + "<input type=\"hidden\" name=\"" + param + "\" value=\"" + str(params[param]) + "\" />" |
| 46 | + return form + "<input type=\"submit\" value=\"" + text + "\" /></form>" + \ |
| 47 | + "<script src=\"https://www.2checkout.com/static/checkout/javascript/direct.min.js\"></script>" |
38 | 48 |
|
39 | 49 | @classmethod |
40 | | - def link(cls, params=None, url="https://www.2checkout.com/checkout/purchase?"): |
| 50 | + def link(cls, params=None): |
| 51 | + url = Charge.checkout_url + '?' |
41 | 52 | if params is None: |
42 | 53 | params = dict() |
43 | 54 | param = urllib.urlencode(params) |
|
0 commit comments