> For the complete documentation index, see [llms.txt](https://docs.verifone.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.verifone.com/psdk-latest/psdk-user-guide-and-training/psdk-training-videos/application-flow.md).

# Application Flow

{% embed url="<https://vimeo.com/1132591200/b191846d0a>" %}

**Transcript**:

I'll explain the flow first, and then we will see in diagrams and code how this looks like.

<figure><img src="/files/BWNGGRhGEs9RPcJib7JK" alt=""><figcaption></figcaption></figure>

First, create an instance of PSDK, the primary object that establishes the connection between the POS app and the payment app.

Second, create a Commerce Listener object, and register it with the Payment SDK.

Third, set up the connection between PSDK and the Payment Application.

Fourth, obtain the TransactionManager object from the PaymentSDK.

Then perform the login operation. Once successful, initiate the transaction. When this is ready we can begin the payment. Note that as the payment starts, the Payment Application takes over the device, displaying all the screens needed to complete the transaction. After the transaction is complete the control will shift back to the POS application where you can close the session, from there you can start a session, start a payment, close the session and repeat the process as many times as you need. In the end of the business day, you can log out.

The initial connection as well as the login and logout processes tend to occur once a day. In the time between login and logout, multiple transaction sessions can be carried out using the same device.

<figure><img src="/files/EmePvFKu3z0BuM4wRhg4" alt=""><figcaption></figcaption></figure>

Let's examine a diagram of the transaction flow. Pay attention to the different states. You can initiate a payment only if you are in a Login State and a Session Open State. If you try to start a payment without doing the first two, it will not work.

Now let's review the steps: you begin by creating the PSDK object. We then need to get the Transaction Manager and perform a login. Once that is successful, you can initiate the transaction session, and start the payment. For the end of day we simply end the session, and log out.

Let's see how we can make a simple sale transaction.

<figure><img src="/files/WIOe7CJ1KGfVQFAzdErA" alt=""><figcaption></figcaption></figure>

We need three classes: the PaymentSDK, the Transaction Manager and the Commerce Listener.

First we need to create the PSDK object. Once that is done, you can use initialize from values to connect your app with the payment application.

The outcome of this event will be known to us through the handle status callback from the Commerce Listener class.

Once you know that the connection establishment was successful, we need to get the Transaction Manager object.

When that is ready, we need to perform a log in.

The outcome of this operation will be known to us through a Commerce Listener class known as "handleTransactionEvent".

Once the login is successful, we start a session, and the outcome of this will be known to us through another "handleTransactionEvent" class.

Once the start Session is successful, we can start the payment, which will then give full control to the payment application in the device. When the transaction is complete you will know the outcome through the "handle payment completed event" class from CommerceListener.

So for each event the CommerceListener class will let you know the result of the operation.

This is the flow in which you need to call the different methods to make a transaction.

<figure><img src="/files/QNiAeNfjyAYdxtqIpsQz" alt=""><figcaption></figcaption></figure>

Let's see how it looks like in Kotlin. First, we initialize the PSDK object through the PSDK Init and use the initializefromvalues method, which uses two parameters. The first one is the CommerceListenerAdapter where the CommerceListener object is registered. This allows callbacks for every event.

The second parameter provides information on the device's IP address. If you are performing an On Device integration this will be a loopback address, 127 0 0 1. However, if you are building an Off Device integration the IP address of your device needs to be added here. Finally, the success of the connection can be verified using the handlestatus method from the CommerceListener class.

<figure><img src="/files/SLe8LEE6UDHZadxee9ux" alt=""><figcaption></figcaption></figure>

Once the connection is successful, we do a Login using Loginwithcredentials. You will be able to know the outcome of the event through the handleTransactionEvent from the CommerceListener class.

<figure><img src="/files/WLAOWdM3cOxCBf575JT1" alt=""><figcaption></figcaption></figure>

Once the Login is successful, we start a Session using startsession API and we will learn the outcome from the handleTransactionEvent from CommerceListener.

<figure><img src="/files/Ku3tJQmMiX5RSHIEb47n" alt=""><figcaption></figcaption></figure>

Once the start session is successful, we start the payment. You will be informed about the outcome through the handlePaymentCompletedEvent from the CommerceListener. Remember that throughout the payment process, control is under the payment application. However, once the outcome reaches the POS, it will resume control. In the POS app, you can end the session and start a new one. Finally, you can proceed to log out.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.verifone.com/psdk-latest/psdk-user-guide-and-training/psdk-training-videos/application-flow.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
