# Accepting a payment (/global/en/docs/Terminal/CodeDevelopment/Accepting-a-payment)

## Accepting a payment

**Learn More**\
New to the PayExplorer Connect SDK? Here are some helpful resources:\
[PayExplorer Connect SDK API](doc-id:2b18ebc9)

The SDK supports sale, refund, reversal, and other operations.
This guide uses a standard payment (sale) to demonstrate the common Exchange flow: prepare parameters, start a request, and handle its result. Financial, device, and system operations can follow the same calling pattern, using the entry points, parameters, and business results in their API references.

### Transaction Flow

Use [Event Notification Services](doc-id:818d1b32) for progress feedback. Use [Abort Transaction](doc-id:5011e2c5) when interruption is needed and [Transaction Query](doc-id:c0b63f10) when the original request's status or result needs checking. Validate the implemented paths with the [Go-Live Checklist](doc-id:442040f5).

![](https://docs.newlandnpt.us/assets/_shared/8955fdd514b1/transaction-process.svg)

### Preparing Transaction Parameters

**API reference**
[PaymentParam Object](doc-id:789ff18e#payment-request)

A PaymentParam object should be created before initiating a transaction, with the key parameters properly configured:

- Amount (totalAmount): The transaction amount as a decimal string (e.g., "99.99").
- Currency (**currency**): Enum value. Three-letter currency code based on ISO 4217.
- Transaction Reference (**transactionReference**): A global order reference generated by the EPOS system.
- Other Optional Parameters: Tip amount, cashier information, product summary, etc., depending on business requirements.

```java
// Build a payment parameter object
PaymentParam paymentParam = PaymentParam.newBuilder()
    .transactionReference("12345678")
    .totalAmount("99.99")   
    .build();                    
```

### Start the Payment Exchange

Register callbacks and start the request with the prepared parameters. The SDK returns results asynchronously; save the Exchange ID to track the request.

```java
// Start the payment exchange with callback
RetailerManager.provideFinancialService()
        .newPaymentExchange(paymentParam)
        .startAsyncExchange(new Exchange.RetailerSDKCallback<PaymentResult>() {

            @Override
            public void onError(int code, String msg) {
                // Application logic: handle request/communication errors
            }

            @Override
            public void onResult(PaymentResult result) {
                handlePaymentResult(result);
            }
        });
```

> **WARN**
>
> The onError callback indicates that the request failed to be sent or processed by the SDK.\
> A completed transaction result is always returned through the result callback.\
> For detailed error definitions, see: [Error Codes](doc-id:27dda32e)

### Handling Transaction Results

**API reference**
[PaymentResult Object](doc-id:789ff18e#payment-response)

For every Exchange, first confirm completion, then determine the business outcome. If the result type exposes an end flag such as `endFlag` or `EndFlag`, `false` identifies an intermediate response and `true` identifies the final response. If no end flag is exposed, receiving a valid result callback completes that Exchange. Use the flag provided by the result type in the SDK version you use.

The SDK returns a PaymentResult object through the result callback. After confirming the final response, read the following fields to determine the payment outcome and retrieve transaction details:

- Transaction Status (**response**)  Indicates whether the transaction was successful.
- Response Reason (**responseReason**) Provides the detailed transaction outcome code, such as failure, cancellation, or pending.
- Additional Information (**additionalResponseInformation**) Additional information explaining the response reason.
- Transaction Amount (totalAmount) The actual transaction amount, expressed as a decimal string (for example, "99.99").
- Transaction Timestamp (**transactionDateTime**) The date and time when the transaction occurred.
- Other Optional Fields: Additional information may be available depending on the acquiring application implementation, such as issuer reference data (issuerReferenceData) and payment receipts (paymentReceipts).

```java
// Handle payment result returned from the SDK
private void handlePaymentResult(PaymentResult result) {
    // Skip null or intermediate responses.
    if (result == null || !result.isEndFlag()) {
        return;
    }
    // Check transaction status
    if (Response5Code.SUCC == result.getResponse()) {
        // Transaction succeeded
        String authorisationCode = result.getAuthorisationCode();
        // Application logic: update UI or record transaction
    } else {
        // Transaction failed, cancelled, or pending
        RetailerResultDetail1Code reason = result.getResponseReason();
        String responseInfo = result.getAdditionalResponseInformation();
        // Application logic: handle failure reason
    }
}
```

> **WARN**
>
> **Important**:
> After confirming the final response, the transaction is considered successful only when **response == SUCC**.