.. _SHA1: SHA-1 Request Authentication Method ############################################################ .. contents:: :local: .. role:: ex .. role:: code To generate request with SHA-1 authentication: #. :ref:`Generate Signature`, #. :ref:`Generate Request`. .. _sha1_signature_generation: SHA1 Signature Generation ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #. Concatenate all necessary parameters to String (also referred as a "signing string" or "signature base string"). Each API-command might have it's own list and order of parameters to concatenate in signing string. Check it in the description of ``control`` parameter for the relevant API-command with SHA-1 authentication. .. note:: Use minimal monetary units for amount (i.e. cent, penny etc. For amount of 0.94 USD value in signing string will be 94, for 10.15 USD value in signing string will be 1015) For example, parameters: .. code-block:: endpointid=1111 client_orderid=902B4FF5 amount=10.42 email=john.smith@gmail.com merchant_control=B17F59B4-A7DC-41B4-8FF9-37D986B43D20 will be concatenated to the string: .. code-block:: 1111902B4FF51042john.smith@gmail.comB17F59B4-A7DC-41B4-8FF9-37D986B43D20 #. Sign the received string using SHA-1: Java SHA-1 Generation Example: .. code-block:: java package com.Payneteasy; import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class HashTextTest { /** * @param args * @throws NoSuchAlgorithmException */ public static void main(String[] args) throws NoSuchAlgorithmException { System.out.println(sha1("test string to sha1")); } static String sha1(String input) throws NoSuchAlgorithmException { MessageDigest mDigest = MessageDigest.getInstance("SHA1"); byte[] result = mDigest.digest(input.getBytes(StandardCharsets.UTF_8)); StringBuilder sb = new StringBuilder(); for (byte b : result) { sb.append(Integer.toString((b & 0xff) + 0x100, 16).substring(1)); } return sb.toString(); } } JavaScript SHA-1 Generation Example .. code-block:: html Bash + openssl SHA-1 Generation Example .. code-block:: bash echo -n "test string to sha1" | openssl dgst -sha1 After that signature will look like this: .. code-block:: c6bdd88a78834ef4b863b088827a459f039e8257 .. _sha1_request_generation: SHA1 Request Generation ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ To make request use generated signature as the value of parameter ``control`` in request body. Example of Request: .. code-block:: Request method: POST Request URI: https://gate.payneteasy.com/paynet/api/v2/sale/1111 Body: client_orderid=902B4FF5&order_desc=Test Order Description&first_name=John&last_name=Smith&ssn=1267&birthday=19820115&address1=100 Main st&city=Seattle&state=WA&zip_code=98102&country=US&phone=+12063582043&cell_phone=+19023384543&amount=10.42&email=john.smith@gmail.com¤cy=USD&ipaddress=65.153.12.232&site_url=https://doc.payneteasy.com&credit_card_number=4538977399606732&card_printed_name=CARD HOLDER&expire_month=12&expire_year=2099&cvv2=123&purpose=user_account1&control=c6bdd88a78834ef4b863b088827a459f039e8257 Example of CURL Request: .. code-block:: curl --data " client_orderid=902B4FF5 &order_desc=Test Order Description &first_name=John &last_name=Smith &ssn=1267 &birthday=19820115 &address1=100 Main st &city=Seattle &state=WA &zip_code=98102 &country=US &phone=+12063582043 &cell_phone=+19023384543 &amount=10.42 &email=john.smith@gmail.com ¤cy=USD &ipaddress=65.153.12.232 &site_url=https://doc.payneteasy.com &credit_card_number=4538977399606732 &card_printed_name=CARD HOLDER &expire_month=12 &expire_year=2099 &cvv2=123 &purpose=user_account1 &control=c6bdd88a78834ef4b863b088827a459f039e8257 " https://gate.payneteasy.com/paynet/api/v2/sale/1111 SHA1 Status signature ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. raw:: html :file: ../../_static/examples/sha1_status_signature.html SHA1 Sale signature ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. raw:: html :file: ../../_static/examples/sha1_sale_signature.html SHA1 Callback signature ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. raw:: html :file: ../../_static/examples/sha1_callback_signature.html