> For the complete documentation index, see [llms.txt](https://developer.magtek.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.magtek.com/sdks-and-tools/~/revisions/nmn8M5j6MNAqK22K3hFt/universal-sdk-documentation/java/appendices/appendix-c-emv-transaction-flow.md).

# Appendix C - EMV Transaction Flow

### Flow Chart

<figure><img src="https://4093728396-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fwjbnqo0srzj14AwQMHQM%2Fuploads%2FgteVm3IFGDVXuX6lm5MA%2Fc1flowchart.png?alt=media&amp;token=d4922c5a-aa44-45c8-98ab-a1d6d76a0210" alt=""><figcaption></figcaption></figure>

### Sample Flow Code <a href="#c.2_sample_flow_code" id="c.2_sample_flow_code"></a>

The following breaks out the EMV flow chart into code.

{% code overflow="wrap" %}

```
// #1

// Assign parameters.
List<PaymentMethod> paymentMethod = new ArrayList<PaymentMethod>(); paymentMethod.Add(PaymentMethod.MSR); 
paymentMethod.Add(PaymentMethod.Contact); 
paymentMethod.Add(PaymentMethod.Contactless);

Transaction transaction = new Transaction(); 
transaction.setAmount(“1.00”); 
transaction.setCashBack(“0.00”); 
transaction.setEMVOnly(true); 
transaction.setPaymentMethods(paymentMethod); 
transaction.setQuickChip(false);

// Start transaction.
boolean result = device.startTransaction(transaction);
```

{% endcode %}

{% code overflow="wrap" %}

```
// #2

@Override
public void OnEvent(EventType eventType, IData data)
{
        String message;
        
        switch (eventType);
                {
                        case EventType.DisplayMessage:
                        
                                // Get the message. 
                                if (data != NULL)
                                {
                                        message = data.StringValue();
                                }

                                break;
        }
}
```

{% endcode %}

{% code overflow="wrap" %}

```
// #3

@Override
public void OnEvent(EventType eventType, IData data)
{
        String message;

        switch (eventType);
                {
                        case EventType.InputRequest:
                                // Get the message.
                                message = data.StringValue();

                                // display/retrieve user selection.
                                . . .

                                // set status and selection result. 
                                IData selectionData = new 
                                IData; selectionData[0] = status; 
                                selectionData[1] = selection; 
                                device.sendSelection(data);

                                break;
                }
}
```

{% endcode %}

<pre data-overflow="wrap"><code>// #4

@Override
public void OnEvent(EventType eventType, IData data)
{
<strong>        byte[] ARQC = null;
</strong>
        switch (eventType);
                {
                        case EventType.AuthorizationRequest:
                                // #4a
                                // Forward ARQC to processor.
                                /* data[0..1] – ARQC length
                                data[2..n] – remainder contains the ARQC TLV object */

                                IData processorARPC;
                                procARPC.byteArray = sendForAuthorization(data.ByteArray());

                                // #4b
                                // Send authorization to device when not in QuickChip mode. 
                                if (transaction.QuickChip == false)
                                {
                                        device.sendAuthorization(procARPC.ByteArray());
                                }

                                break;
                }
}
</code></pre>

{% code overflow="wrap" %}

```
// #1

// Assign parameters.
List<PaymentMethod> paymentMethod = new ArrayList<PaymentMethod>(); paymentMethod.Add(PaymentMethod.MSR); paymentMethod.Add(PaymentMethod.Contact); paymentMethod.Add(PaymentMethod.Contactless);

Transaction transaction = new Transaction(); 
transaction.setAmount(“1.00”); 
transaction.setCashBack(“0.00”); 
transaction.setEMVOnly(true); 
transaction.setPaymentMethods(paymentMethod); 
transaction.setQuickChip(false);

// Start transaction.
boolean result = device.startTransaction(transaction);
```

{% endcode %}

<pre data-overflow="wrap"><code>// #2

@Override
public void OnEvent(EventType eventType, IData data)
{
<strong>        String message;
</strong>
        switch (eventType);
                {
                        case EventType.DisplayMessage:

                                // Get the message. 
                                if (data != NULL)
                                {
                                        message = data.StringValue();
                                }

                                break;
        }
}
</code></pre>

{% code overflow="wrap" %}

```
 // #3

@Override
public void OnEvent(EventType eventType, IData data)
{
        String message;

        switch (eventType);
                {
                        case EventType.InputRequest:
                                // Get the message.
                                message = data.StringValue();

                                // display/retrieve user selection.
                                . . .

                                // set status and selection result. 
                                IData selectionData = new IData; 
                                selectionData[0] = status; 
                                selectionData[1] = selection; 
                                device.sendSelection(data);

                                break;
                }
}
```

{% endcode %}

{% code overflow="wrap" %}

```
 // #4

@Override
public void OnEvent(EventType eventType, IData data)
{
    byte[] ARQC = null;

    switch (eventType);
        {
            case EventType.AuthorizationRequest:
                // #4a
                // Forward ARQC to processor.
                /* data[0..1] – ARQC length
                data[2..n] – remainder contains the ARQC TLV object */

                IData processorARPC;
                procARPC.byteArray = sendForAuthorization(data.ByteArray());

                // #4b
                // Send authorization to device when not in QuickChip mode. 
                if (transaction.QuickChip == false)
                {
                    device.sendAuthorization(procARPC.ByteArray());
                }
                
                break;
        }
}
```

{% endcode %}

{% code overflow="wrap" %}

```
 // #5

@Override
public void OnEvent(EventType eventType, IData data)
{
        String message;

        switch (eventType);
                {
                        case EventType.DisplayMessage:
                                // Display approval message. 
                                message = data.StringValue();

                                // A data size of 0 is an instruction to clear the display. 
                                if (data.StringValue().Length == 0)
                                {
                                        // Clear the UI display.
                                }

                                break;
                }
}
```

{% endcode %}

{% code overflow="wrap" %}

```
// #6

@Override
public void OnEvent(EventType eventType, IData data)
{
        String message;
        
        switch (eventType);
                {
                        case EventType.TransactionResult:
                                /* data[0]	– Signature Required data
                                [1..2] – Batch Data length
                                data[3..n] – remainder contains the Batch Data TLV object
                                */

                                // Parse the TLV from data[].
                                .
                                // Abstract Approval status from TLV tag “DFDF1A”.
                                .
                                // Abstract Signature Required status from TLV tag data[0].
                                .
                                break;
        }
}
```

{% endcode %}

### MSR Fallback Flow

The use case for an MSR fallback is when communication with the chip results in a terminated transaction and the TransactionStatus is reported as MSRFallback.

The host application will re-attempt the transaction. To invoke this use case, here are the following pre-requisites.

Pre-requisites:

* Device already configured for Device-Driven Fallback = Disabled.
* A card to cause the fallback. Example but not limited to a card with no applications programmed or a card with an application not configured on the device.

Scheme:

* \-->Host begins an initial transaction with PaymentMethod set to MSR+Chip+Contactless.
* <--Device responds with fail and with status of MSRFallback.
* \-->Host displays a message to use magstripe.
* \-->Host starts a transaction with PaymentMethod set to MSR.
* <--Device may respond with transaction canceled card read error.
* \-->Host displays a message each time the transaction fails until successful or until Host decides to end the transaction.
* <--Device sends the transaction result.

### **Begin initial transaction:**

<figure><img src="https://4093728396-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fwjbnqo0srzj14AwQMHQM%2Fuploads%2FblcckenuKDRZe9Jb3M7A%2Fbeginit.png?alt=media&amp;token=903ee7ab-7c80-4a83-8ec6-7b61fb528a9d" alt=""><figcaption></figcaption></figure>

### **Continue with Fallback transaction:**

<figure><img src="https://4093728396-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fwjbnqo0srzj14AwQMHQM%2Fuploads%2FDtUYbE5JA706P4DECfVi%2Ffallback.png?alt=media&amp;token=52e9b746-bfc1-49d9-b855-0894696394ce" alt=""><figcaption></figcaption></figure>

<br>


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://developer.magtek.com/sdks-and-tools/~/revisions/nmn8M5j6MNAqK22K3hFt/universal-sdk-documentation/java/appendices/appendix-c-emv-transaction-flow.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
