DengiOnline

2018-04-26 03:00:19

Algorithm for getting the request signing key

To form a key, you should use data that is sent within a request.

Example request: 

<request>
	<project>1290</project>
	<action>pay</action>
	<timestamp>20141021120912</timestamp>
	<params>
		<paysystem>2</paysystem>
		<account>9211234567</account>
		<amount>100</amount>
		<extra>
			<firstname>John</firstname>
			<lastname>Doe</lastname>
		</extra>
	</params>
</request>
  1. Collect the array of elements with text values: 

    project=1290
    action=pay
    timestamp=20141021120912
    paysystem=2
    account=9211234567
    amount=100
    firstname=John
    lastname=Doe
  2. Sort elements using ascending alphabetical order:

    account=9211234567
    action=pay
    amount=100
    firstname=John
    lastname=Doe
    paysystem=2
    project=1290
    timestamp=20141021120912
  3. Use the array data to form a signature string, which uses the ampersand sign (&) as a delimiter:

    account=9211234567&action=pay&amount=100&firstname=John&lastname=Doe&paysystem=2&project=1290&timestamp=20141021120912
  4. Append the "secret=private_key&" prefix to the existing string:

    secret=MyP@ssw0rd&account=9211234567&action=pay&amount=100&firstname=John&lastname=Doe&paysystem=2&project=1290&timestamp=20141021120912

    Attention! If there is a space inside a parameter, replace it with the '+' sign in the resulting strings, so that James Paul would be James+Paul.

     

  5. Calculate the hash value of the final string using the SHA-1 algorithm:

    sha1('secret=MyP@ssw0rd&account=9211234567&action=pay&amount=100&firstname=John&lastname=Doe&paysystem=2&project=1290&timestamp=20141021120912') = 583306e25ab10b056af7ad695dc0917b0320c3b6
  6. Use the hash value for the string parameter in the request:

    <request>
    	<project>1290</project>
    	<action>pay</action>
    	<timestamp>20141021120912</timestamp>
    	<params>
    		<paysystem>2</paysystem>
    		<account>9211234567</account>
    		<amount>100</amount>
    		<extra>
    			<firstname>John</firstname>
    			<lastname>Doe</lastname>
    		</extra>
    	</params>
    	<sign>583306e25ab10b056af7ad695dc0917b0320c3b6</sign>
    </request>