SHOW:
|
|
- or go back to the newest paste.
1 | def get_liqpay_sign(payment_data, action): | |
2 | import base64 | |
3 | import hashlib | |
4 | ||
5 | """ | |
6 | action == 'to_send' when use sign for submit form to PB | |
7 | action == 'to_validate' when use sign to validate PB response | |
8 | """ | |
9 | ||
10 | str_for_sign = '' | |
11 | ||
12 | if action == "to_send": | |
13 | keys_for_sign = ['private_key', 'amount', 'currency', 'public_key', | |
14 | 'order_id', 'type', 'description', 'result_url', | |
15 | 'server_url'] | |
16 | elif action == "to_validate": | |
17 | keys_for_sign = ['private_key', 'amount', 'currency', 'public_key', | |
18 | 'order_id', 'type', 'description', 'status', | |
19 | 'transaction_id', 'sender_phone'] | |
20 | ||
21 | for key in keys_for_sign: | |
22 | str_for_sign += str(payment_data[key]) | |
23 | ||
24 | result = base64.b64encode( | |
25 | hashlib.sha1(str_for_sign).digest() | |
26 | ) | |
27 | return result | |
28 | ||
29 | ||
30 | ---- | |
31 | ||
32 | payment_data = { | |
33 | "public_key": merchant_data.get("merchant_id"), | |
34 | "private_key": merchant_data.get("merchant_sign"), | |
35 | "amount": temp_order.pay_total(), | |
36 | "currency": temp_order.currency, | |
37 | "order_id": temp_order.id, | |
38 | "type": "buy", | |
39 | "order": temp_order, | |
40 | "description": "Oplata zakaza #%s" % temp_order.number, | |
41 | "result_url": result_url, | |
42 | "server_url": server_url, | |
43 | } | |
44 | ||
45 | - | signature = get_liqpay_sign(payment_data, 'to_send') |
45 | + | signature = get_liqpay_sign(payment_data, 'to_send') |
46 | ||
47 | ------ | |
48 | ||
49 | Такая вот у меня форма: | |
50 | ||
51 | <html> | |
52 | <body> | |
53 | <p>Перенаправляем на оплату...</p> | |
54 | ||
55 | <form method="POST" action="https://www.liqpay.com/api/pay"> | |
56 | <input type="hidden" name="public_key" value="{{ payment_data.public_key }}" /> | |
57 | <input type="hidden" name="amount" value="{{ payment_data.amount|stringformat:"1.2f" }}" /> | |
58 | <input type="hidden" name="currency" value="{{ payment_data.currency }}" /> | |
59 | <input type="hidden" name="description" value="{{ payment_data.description }}" /> | |
60 | <input type="hidden" name="order_id" value="{{ payment_data.order_id }}" /> | |
61 | <input type="hidden" name="result_url" value="{{ payment_data.result_url }}" /> | |
62 | <input type="hidden" name="server_url" value="{{ payment_data.server_url }}" /> | |
63 | <input type="hidden" name="type" value="{{ payment_data.type }}" /> | |
64 | <input type="hidden" name="signature" value="{{ signature }}" /> | |
65 | <input type="hidden" name="language" value="ru" /> | |
66 | </form> | |
67 | ||
68 | <script type="text/javascript"> | |
69 | var form = document.querySelectorAll('form'); | |
70 | form[0].submit(); | |
71 | </script> | |
72 | </body> | |
73 | </html> |