Skip to main content

Veritran Docs

Create a Configurable Transaction

See below for an example on how to build a login using configurable transactions. Keep in mind that, since transactions vary depending on the functionality you want to build and on the client's requirements, you might encounter different approaches on how to build a similar transaction.

Consider this scenario: You need to create a login transaction that decrypts a user's login information (that for security reasons is encrypted in the device), validates the information provided by the user against a data base, returns a status, but also saves every status that is not successful in the transaction log. For this transaction, you need to consume data provided by a third party and validate it with a REST service. You also need two Script actions. One for decrypting the user's information, and another one for saving the login status in the transaction log.

Prerequisites

For this example, it is contemplated the use of a REST service provided by a client or third-party. Make sure to have this information available before creating the transaction.

The REST service might already be created in your environment, or you might need to create it from scratch. In this example, you will learn how to use a REST service that is already created in the environment, but you can go to Create a REST Service for a Login Validation if you need to learn how to create it from scratch.

Create the Login Configurable Transaction
  1. Go to Global Logic > Transactions , click New Transaction and then select Configurable.

  2. Complete the Settings tab that opens by default to add information about the transaction you are building.

    1. Add a name to the transaction that represents its functionality, with its transaction code in the beginning to track it. Also, add a short description that helps you identify the purpose of your transaction. For this example, the name and description set are 1058_Validate_Login, Validates a user login. Keep in mind that, in Middleware, the transaction will appear with its transaction code and its description, so make sure to be as brief and accurate as possible.

      trx_middleware.png
    2. Add a unique 4-digit transaction code. The code set for this scenario is 1058.

      Important

      Codes are unique per product, which means you can have two transactions with the same code but set for different products.

    3. Select the product you are working on. For this example, chose the P1 product.

      Important

      Products are configured in Middleware and vary depending on the client's business structure and needs. Contact your admin to confirm the product you should be working on.

    4. In Timeout (seconds), enter the time in seconds that the platform will wait until it receives a response from the transaction. The default timeout is 30 seconds.

    5. In the Processing Message field, add the message that the user will see on screen while the transaction is being processed. This message shows if you do not set a custom processing message in the Loading Process screen of your app. The default message is Processing....

    6. Add tags to help identify and group your transactions by their functionality. Use simple tags you can remember easily the next time, since there is no autofill in this field. For this example, add the Login tag.

  3. First, set the output parameters on the Start node to begin the transaction flow. You need to retrieve the username and password for each client from the registers where this information is stored. Click the node, and then click Outputs > Add Output. Complete the information as follows:

    Inputparam_1.png
    Inputparam_2.png

    The username information is stored in register 3, and the password in register 4. Add these registers in the External variable field. Data type is string in both cases.

    Note

    Registers 3 (username) and 4 (password) are global for every project, and encrypt user's information for security reasons.

  4. Then, you have to decrypt the user and password received. Drag the Script action node from the Actions tab in the left menu into the canvas. In the Script Editor below, paste the following script that will decrypt the information:

    let trxInfo = VtNet.Host.getTransactionInfo();
    let terminalId = trxInfo[0];
    let seqNumber = trxInfo[1];
    let decryptedclientId =  VtNet.Host.decryptSession(user)[0];
    let decryptedclientKey = VtNet.Host.decryptTransaction(password, terminalId, seqNumber)[0];
    if((decryptedclientId == respuesta.username) && (decryptedclientKey == respuesta.password))

    Go to the right panel, and complete the Configuration, Input and Output tabs.

    • In Configuration, modify the label so that it reflects the Script's functionality. For this example, we set Decrypt.

    • In Inputs, we need to retrieve the username and password information from the Start node, so we need to consume the node's outputs set in step 3. Click Create from output and select the user and password parameters set in the Start node, as shown below:

      Caso_de_uso_1.gif
    • In Outputs, you need to obtain the decrypted username and password, and transfer them to the next node in the flow. Click Add Output and add a decryptedclientId and a decryptedclientKey string-type output to receive the username and password, respectively.

      Note

      These parameters' names match the parameters you are receiving in the script. You can modify the name both in the Script and in this step.

    • Finally, connect the Script node to the Start node.

      Caso_de_uso_2.gif
  5. In the left panel, click the Services tab and look for the REST service you are going to implement in this transaction. Drag the REST service into the canvas, and connect it to the Script node. In this step, the REST service receives the decrypted user information from the previous Script node and validates it.

    Note

    The steps below are based on a REST service already created in the environment. If you need to create the service from scratch, go to Create a REST Service for a Login Validation.

    Go to the right panel, and complete the Configuration, Input and Output tabs.

    • In Configuration, modify the label so that it reflects the service's functionality. For this example, set Srv Validate Login. Below the label, in the node, you see the service's name.

    • In the Inputs tab, click the user and password drop-down lists (which are query keys set when creating the REST service) and select the decryptedclientId and decryptedclientKey parameters from the Script node created in step 4.

      REST_inputs.gif
    • Outputs are retrieved automatically from the REST service's information, so they vary depending on the service created. Outputs are consumed by the End node, which will be explained in step 7.

  6. It is useful to log errors in Middleware whenever possible to track them in the transaction's log. To do this, create a new Script node and paste the following, modifying the transaction ID and the message displayed on the transaction log:

    if (status != 200) {
        VtNet.Host.log("DEBUG","TRX [ID]",'Status: '+status);
        VtNet.Host.setToken("91", "H99");
        VtNet.Host.setToken("79", "There was an error with the service");
        VtNet.Host.setResponseCode(true, "H99");                
        return;                                             
    }

    Then, go to the right panel and complete the Configuration, Inputs and Outputs tabs.

    • In Configuration, modify the label so that it reflects the Script's functionality. For this example, set Validate Status.

    • In Inputs, you need to retrieve the REST service's status. Click Create from output and select the status parameter from the REST node.

      Script_Inputs_Final.gif
    • This node does not require the configuration of outputs, since it saves the status on the transaction log and does not transfer data to the End node.

    • Finally, connect the Script node to the REST and End nodes to continue the transaction's flow.

  7. Lastly, the End node needs to receive information, as explained in step 5. You want to receive the user's email, full name, its ID and a response from the REST service. Go to the right panel and complete the Inputs tab.

    • In Inputs, click Create from output and select the mail, fullname, codrsp and iduser parameters from the REST node.

      Transaction_ready.png

    Important

    This data needs to be included in the REST service provided by the client or third-party, and is going to be automatically displayed as the REST service's outputs. Before making these connections, make sure this information is included in the service call.

  8. Click Save & continue to save your transaction, or click the down arrow and Save & close to save the transaction and go back to the Transactions page. Your transaction appears on the transactions list with the Pending publication status.

After creating or editing a transaction:

  • You can verify if there are any internal errors in its construction by checking the Errors tab in the left panel.

  • If there are no errors, you have to publish the transaction so that changes impact on Middleware and on your app. Read Publish and Run a Configurable Transaction.

  • You can run the published transaction to test its functionality. Read Publish and Run a Configurable Transaction.

  • You need to invoke the transaction from a process to integrate it in your app. Read Invoke a Transaction to learn more.

    Note

    If you edit a transaction that is already integrated in your app, you can skip this step.

Follow the steps below if you need to create a REST service from scratch and use it in step 5 in Create the Login Configurable Transaction. With this example, you can create a REST service, with information provided by the client or third party, to validate users' information.

  1. Go to the Services tab in the left panel and click Add Service.

  2. Add a name and description that represents the REST service functionality. For this scenario, set the Validate Login name. The service's name will appear on the node when dragged into the canvas. You can also add tags to group services. Click Next.

  3. Then, in the Method tab, complete the type of service (in this case, the type is GET) and add the URL provided by the client.

  4. In the same tab, add the query parameters you are sending to the service. For this scenario, set the keys user and password, which are both string parameters that will be added as your service's inputs when invoking it in a transaction. Click Next.

    Rest_method.png
  5. In the Settings tab, complete the body to format the received data and divide it into different outputs. In the example below, the outputs created for the REST service are: username, password, email, fullname, response code and user id.

    rest_body.png
  6. Click Summary to see your service's details and Confirm if you do not need to modify any field.

Once created, the service is available on the Services tab in the transactions editor left panel, and in Global Logic > External Services.