|
15 | 15 | from com.alipay.ams.api.response.pay.alipay_pay_response import AlipayPayResponse |
16 | 16 | from com.alipay.ams.api.default_alipay_client import DefaultAlipayClient |
17 | 17 |
|
18 | | -class EntryCodePaymentRequestTest(unittest.TestCase): |
19 | | - |
20 | | - def test_entry_code(self): |
21 | | - TEST_CLIENT_ID = 'T_385XSM502Y108602A' |
22 | | - script_dir = os.path.dirname(__file__) |
23 | | - with io.open(os.path.join(script_dir, '../private-pkcs1.pem'), encoding = 'utf-8') as pri, io.open(os.path.join(script_dir, '../public.pem'), encoding = 'utf-8') as pub: |
24 | | - PRIVATE_KEY = pri.read() |
25 | | - alipay_public_key = pub.read() |
26 | | - |
27 | | - |
28 | | - |
29 | | - |
30 | | - order = Order() |
31 | | - order.order_description = 'This is an order.' |
32 | | - order.order_amount = Amount('USD', 1231) |
33 | | - |
34 | | - merchant = Merchant() |
35 | | - merchant.reference_merchant_id = 'seller2322174590000' |
36 | | - merchant.merchant_mcc = '7011' |
37 | | - merchant.merchant_name = 'Some_Mer' |
38 | | - |
39 | | - store = Store() |
40 | | - store.store_mcc = '7011' |
41 | | - store.store_name = 'Some_Store' |
42 | | - store.reference_store_id = 'store232217459000011' |
43 | | - |
44 | | - merchant.store = store |
45 | | - order.merchant = merchant |
46 | | - |
47 | | - order.env = Env() |
48 | | - order.env.user_agent = "Mozilla/5.0 (iPhone; CPU iPhone OS 11_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15G77 NebulaSDK/1.8.100112 Nebula PSDType(1) AlipayDefined(nt:4G,ws:320|504|2.0) AliApp(AP/10.1.32.600) AlipayClient/10.1.32.600 Alipay Language/zh-Hans AlipayConnect" |
49 | | - |
50 | | - orderCodeReq = EntryCodePaymentRequest(payment_request_id=int(time.time()), order=order, currency="USD", amount_in_cents=1231, payment_notify_url='http://alipay.com/test') |
51 | | - |
52 | | - body = orderCodeReq.to_ams_json() |
53 | | - #print(body) |
54 | | - #print('-' * 120) |
55 | | - # |
56 | | - #DATA = body.encode('utf-8') |
57 | | - #requestTime = get_cur_iso8601_time() |
58 | | - # |
59 | | - #req = urllib.request.Request(url='https://open-na.alipay.com/ams/api/v1/payments/pay', data=DATA,method='POST') |
60 | | - #req.add_header("content-type","application/json; charset=UTF-8") |
61 | | - #req.add_header("client-id",TEST_CLIENT_ID) |
62 | | - #req.add_header("request-time",requestTime) |
63 | | - #req.add_header("signature","algorithm=RSA256,keyVersion=1,signature=" + sign(orderCodeReq.http_method.value, orderCodeReq.path, TEST_CLIENT_ID, requestTime, body, PRIVATE_KEY)) |
64 | | - # |
65 | | - #with urllib.request.urlopen(req) as f: |
66 | | - # #print(f.status) |
67 | | - # print(f.read().decode('utf-8')) |
68 | | - # print(f.headers) |
69 | | - |
70 | | - default_alipay_client = DefaultAlipayClient("https://open-na.alipay.com", TEST_CLIENT_ID, PRIVATE_KEY, alipay_public_key) |
71 | | - |
72 | | - rsp_body = default_alipay_client.execute(orderCodeReq) |
73 | | - |
74 | | - response = AlipayPayResponse(rsp_body) |
75 | | - |
76 | | - #print(rsp_body) |
77 | | - #print('-' * 120) |
78 | | - |
79 | | - def onF(response): |
80 | | - print('onF: ' + response.result.result_code) |
81 | | - |
82 | | - def onU(response): |
83 | | - print('onU: ' + response.result.result_code) |
84 | | - |
85 | | - def onS(response): |
86 | | - print("%s, %s" % (response.payment_id, response.redirect_action_form.redirect_url)) |
87 | | - self.assertIsNotNone(response.redirect_action_form.redirect_url) |
88 | | - |
89 | | - { |
90 | | - 'F': onF, |
91 | | - 'U': onU, |
92 | | - 'S': onS |
93 | | - }.get(response.result.result_status.value)(response) |
94 | | - |
95 | 18 |
|
| 19 | +class EntryCodePaymentRequestTest(unittest.TestCase): |
96 | 20 |
|
| 21 | + def test_entry_code(self): |
| 22 | + TEST_CLIENT_ID = 'T_385XSM502Y108602A' |
| 23 | + script_dir = os.path.dirname(__file__) |
| 24 | + with io.open(os.path.join(script_dir, '../private-pkcs1.pem'), encoding='utf-8') as pri, io.open( |
| 25 | + os.path.join(script_dir, '../public.pem'), encoding='utf-8') as pub: |
| 26 | + PRIVATE_KEY = pri.read() |
| 27 | + alipay_public_key = pub.read() |
| 28 | + |
| 29 | + order = Order() |
| 30 | + order.order_description = 'This is an order.' |
| 31 | + order.order_amount = Amount('USD', 1231) |
| 32 | + |
| 33 | + merchant = Merchant() |
| 34 | + merchant.reference_merchant_id = 'seller2322174590000' |
| 35 | + merchant.merchant_mcc = '7011' |
| 36 | + merchant.merchant_name = 'Some_Mer' |
| 37 | + |
| 38 | + store = Store() |
| 39 | + store.store_mcc = '7011' |
| 40 | + store.store_name = 'Some_Store' |
| 41 | + store.reference_store_id = 'store232217459000011' |
| 42 | + |
| 43 | + merchant.store = store |
| 44 | + order.merchant = merchant |
| 45 | + |
| 46 | + order.env = Env() |
| 47 | + order.env.user_agent = "Mozilla/5.0 (iPhone; CPU iPhone OS 11_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15G77 NebulaSDK/1.8.100112 Nebula PSDType(1) AlipayDefined(nt:4G,ws:320|504|2.0) AliApp(AP/10.1.32.600) AlipayClient/10.1.32.600 Alipay Language/zh-Hans AlipayConnect" |
| 48 | + |
| 49 | + orderCodeReq = EntryCodePaymentRequest(payment_request_id=int(time.time()), order=order, currency="USD", |
| 50 | + amount_in_cents=1231, payment_notify_url='http://alipay.com/test') |
| 51 | + |
| 52 | + body = orderCodeReq.to_ams_json() |
| 53 | + # print(body) |
| 54 | + # print('-' * 120) |
| 55 | + # |
| 56 | + # DATA = body.encode('utf-8') |
| 57 | + # requestTime = get_cur_iso8601_time() |
| 58 | + # |
| 59 | + # req = urllib.request.Request(url='https://open-na.alipay.com/ams/api/v1/payments/pay', data=DATA,method='POST') |
| 60 | + # req.add_header("content-type","application/json; charset=UTF-8") |
| 61 | + # req.add_header("client-id",TEST_CLIENT_ID) |
| 62 | + # req.add_header("request-time",requestTime) |
| 63 | + # req.add_header("signature","algorithm=RSA256,keyVersion=1,signature=" + sign(orderCodeReq.http_method.value, orderCodeReq.path, TEST_CLIENT_ID, requestTime, body, PRIVATE_KEY)) |
| 64 | + # |
| 65 | + # with urllib.request.urlopen(req) as f: |
| 66 | + # #print(f.status) |
| 67 | + # print(f.read().decode('utf-8')) |
| 68 | + # print(f.headers) |
| 69 | + |
| 70 | + default_alipay_client = DefaultAlipayClient("https://open-na.alipay.com", TEST_CLIENT_ID, PRIVATE_KEY, |
| 71 | + alipay_public_key) |
| 72 | + |
| 73 | + rsp_body = default_alipay_client.execute(orderCodeReq) |
| 74 | + |
| 75 | + response = AlipayPayResponse(rsp_body) |
| 76 | + |
| 77 | + # print(rsp_body) |
| 78 | + # print('-' * 120) |
| 79 | + |
| 80 | + def onF(response): |
| 81 | + print('onF: ' + response.result.result_code) |
| 82 | + |
| 83 | + def onU(response): |
| 84 | + print('onU: ' + response.result.result_code) |
| 85 | + |
| 86 | + def onS(response): |
| 87 | + print("%s, %s" % (response.payment_id, response.redirect_action_form.redirect_url)) |
| 88 | + self.assertIsNotNone(response.redirect_action_form.redirect_url) |
| 89 | + |
| 90 | + { |
| 91 | + 'F': onF, |
| 92 | + 'U': onU, |
| 93 | + 'S': onS |
| 94 | + }.get(response.result.result_status.value)(response) |
0 commit comments