Advertisement
Guest User

Untitled

a guest
Jul 10th, 2014
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.55 KB | None | 0 0
  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')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement