# API Reference

This page provides a technical reference for the `redsys-tpv-business-lib` repositories. It lists the available methods, parameters, and return types for each feature.

## Common Types

`RepositoryResult<T>`

A generic sealed class wrapper for all asynchronous repository responses.

* `Success<T>`: Contains the result data (`val data: T`).
* `ConnectionError`: Indicates a network or service connection failure.
* `Cancelled`: Indicates the operation was cancelled by the user (`val message: String`).
* `ProtocolError`: Indicates an integration or data mapping error (`val type: ProtocolErrorType`, `val description: String?`).

## 1. InitializationRepository

**Purpose**: Manage TPV initialization and configuration.

### Methods

| Method                       | Description                        | Parameters         | Return Type                 |
| :--------------------------- | :--------------------------------- | :----------------- | :-------------------------- |
| `initTpv`                    | Initializes the TPV with the host. | None               | `RepositoryResult<TpvInfo>` |
| `getTpvInfoRepositoryResult` | Retrieves cached TPV information.  | None               | `RepositoryResult<TpvInfo>` |
| `saveTerminalInformation`    | Updates local terminal info.       | `tpvInfo: TpvInfo` | `Unit` (Suspend)            |

## 2. PaymentRepository

**Purpose**: Process card payments.

### Methods

| Method        | Description                  | Parameters                                                                                                                                                                                                                          | Return Type                       |
| :------------ | :--------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :-------------------------------- |
| `makePayment` | Performs a standard payment. | `amount: Money`<br />`tip: Money?`<br />`shiftInfo: ShiftInfo?`<br />`financialConditions: FinancialConditions?`<br />`proprietaryExtraData: ProprietaryExtraData?`<br />`language: LanguageIso6391?` | `RepositoryResult<PaymentResult>` |

`PaymentResult` (Sealed Interface)

* `Accepted(val data: Transaction)`
* `Denied(val data: Transaction)`
* `CardNotFound`

## 3. RefundRepository

**Purpose**: Process refunds.

### Methods

| Method                      | Description                      | Parameters                                                                                                                                        | Return Type                      |
| :-------------------------- | :------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------ | :------------------------------- |
| `makeRefund`                | Refund by original operation ID. | `operationId: String`<br />`amount: Money`<br />`proprietaryExtraData: ProprietaryExtraData?`<br />`language: LanguageIso6391?` | `RepositoryResult<RefundResult>` |
| `makeRefundReadingCard`     | Refund by ID, forcing card read. | `operationId: String`<br />`amount: Money`<br />`proprietaryExtraData: ProprietaryExtraData?`<br />`language: LanguageIso6391?` | `RepositoryResult<RefundResult>` |
| `makeRefundWithoutOriginal` | Refund without previous ID.      | `amount: Money`<br />`proprietaryExtraData: ProprietaryExtraData?`<br />`language: LanguageIso6391?`                                  | `RepositoryResult<RefundResult>` |

`RefundResult` (Sealed Interface)

* `Accepted(val data: Transaction)`
* `Denied(val data: Transaction)`
* `ExceededAmount`

## 4. PreauthorizationRepository

**Purpose**: Manage funds reservations.

### Methods

| Method                    | Description                | Parameters                                                                                                                                                                           | Return Type                                |
| :------------------------ | :------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :----------------------------------------- |
| `makePreauthorization`    | Create a new pre-auth.     | `amount: Money`<br />`shiftInfo: ShiftInfo?`<br />`proprietaryExtraData: ProprietaryExtraData?`<br />`language: LanguageIso6391?`                                  | `RepositoryResult<PreauthorizationResult>` |
| `confirmPreauthorization` | Confirm/Charge a pre-auth. | `amount: Money`<br />`operationId: String`<br />`shiftInfo: ShiftInfo?`<br />`proprietaryExtraData: ProprietaryExtraData?`<br />`language: LanguageIso6391?` | `RepositoryResult<PreauthorizationResult>` |
| `replacePreauthorization` | Update the amount.         | `amount: Money`<br />`operationId: String`<br />`shiftInfo: ShiftInfo?`<br />`proprietaryExtraData: ProprietaryExtraData?`<br />`language: LanguageIso6391?` | `RepositoryResult<PreauthorizationResult>` |
| `annulPreauthorization`   | Cancel the reservation.    | `operationId: String`<br />`language: LanguageIso6391?`                                                                                                                        | `RepositoryResult<PreauthorizationResult>` |

`PreauthorizationResult` (Sealed Interface)

* `Accepted(val data: Transaction)`
* `Denied(val data: Transaction)`

## 5. TransactionRepository

**Purpose**: Search historical transactions.

### Methods

| Method                     | Description                        | Parameters                                                                                                                                                                                            | Return Type                               |
| :------------------------- | :--------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------------------------------- |
| `getTransactions`          | Search transactions by date range. | `initDate: Date`<br />`endDate: Date`<br />`filter: TransactionFilter?`<br />`resultsFilter: TransactionResultsFilter?`                                                             | `RepositoryResult<GetTransactionsResult>` |
| `getTransactionsBySession` | Search by session.                 | `initDate: Date`<br />`endDate: Date`<br />`sessionDate: Date`<br />`sessionId: Int?`<br />`filter: TransactionFilter?`<br />`resultsFilter: TransactionResultsFilter?` | `RepositoryResult<GetTransactionsResult>` |

## 6. TotalsRepository

**Purpose**: Query accumulated totals.

### Methods

| Method                    | Description                         | Parameters                                                                         | Return Type                              |
| :------------------------ | :---------------------------------- | :--------------------------------------------------------------------------------- | :--------------------------------------- |
| `getSessions`             | Totals for all sessions on a date.  | `date: Date`<br />`wantBrandDetails: Boolean`                                | `RepositoryResult<TotalsResult>`         |
| `getSession`              | Totals for a specific session ID.   | `date: Date`<br />`sessionId: Int`<br />`wantBrandDetails: Boolean`    | `RepositoryResult<TotalsResult>`         |
| `getSessionsBetweenDates` | Totals for sessions in range.       | `initDate: Date`<br />`endDate: Date`<br />`wantBrandDetails: Boolean` | `RepositoryResult<TotalsResult>`         |
| `getLastSession`          | Totals for the last closed session. | `None`                                                                             | `RepositoryResult<GetLastSessionResult>` |
| `getShifts`               | Totals for all shifts on a date.    | `date: Date`<br />`wantBrandDetails: Boolean`                                | `RepositoryResult<TotalsResult>`         |
| `getShift`                | Totals for a specific shift ID.     | `date: Date`<br />`shiftId: String`<br />`wantBrandDetails: Boolean`   | `RepositoryResult<TotalsResult>`         |
| `getShiftBetweenDates`    | Totals for shifts in range.         | `initDate: Date`<br />`endDate: Date`<br />`wantBrandDetails: Boolean` | `RepositoryResult<TotalsResult>`         |

`TotalsResult` (Sealed Interface)

* `IncomingData(val data: TotalsModel)`
* `EmptyData`
* `WrongIdentifierError`

## 7. ShiftRepository and SessionRepository

**Purpose**: Manage operational periods.

### Methods

| Repository          | Method         | Parameters                      | Return Type                            |
| :------------------ | :------------- | :------------------------------ | :------------------------------------- |
| `ShiftRepository`   | `openShift`    | `number: Int`<br />`date: Date` | `RepositoryResult<Boolean>`            |
| `SessionRepository` | `closeSession` | `wantBrandDetails: Boolean`   | `RepositoryResult<CloseSessionResult>` |

## 8. PrinterRepository

**Purpose**: Control device printer.

### Methods

| Method               | Description             | Parameters                                                                               | Return Type                 |
| :------------------- | :---------------------- | :--------------------------------------------------------------------------------------- | :-------------------------- |
| `checkPaper`         | Check paper status.     | `None`                                                                                   | `RepositoryResult<Boolean>` |
| `printBitmap`        | Print a custom bitmap.  | `bitmap: Bitmap`                                                                         | `RepositoryResult<Boolean>` |
| `printDefaultTicket` | Print standard receipt. | `context: Context`<br />`headerIcon: Bitmap`<br />`transaction: Transaction` | `RepositoryResult<Boolean>` |

## 9. TicketDigitalRepository

**Purpose**: Manage digital receipts.

### Methods

| Method                | Description               | Parameters                                  | Return Type                                |
| :-------------------- | :------------------------ | :------------------------------------------ | :----------------------------------------- |
| `sendTicketDigital`   | Send receipt via email.   | `operId: String`<br />`email: String` | `RepositoryResult<TicketDigitalResult>`    |
| `getTicketDigitalURL` | Get receipt URL (for QR). | `operId: String`                            | `RepositoryResult<TicketDigitalUrlResult>` |

## 10. SettingsRepository and AuthRepository

**Purpose**: Configuration and Authentication.

### Methods

| Repository           | Method                        | Parameters                       | Return Type                    |
| :------------------- | :---------------------------- | :------------------------------- | :----------------------------- |
| `SettingsRepository` | `updateShowTransactionResult` | `showTransactionResult: Boolean` | `RepositoryResult<Boolean>`    |
| `SettingsRepository` | `updateLanguage`              | `language: LanguageIso6391`      | `RepositoryResult<Boolean>`    |
| `AuthRepository`     | `getToken`                    | `None`                           | `RepositoryResult<AuthResult>` |

## 11. APM Repositories (Bizum, Alipay, WeChat)

**Purpose**: Alternative Payment Methods.

### Methods

| Repository         | Method        | Parameters                                                                                                                                                                           | Return Type                         |
| :----------------- | :------------ | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------------------------- |
| `BizumRepository`  | `sendBizum`   | `amount: Money`<br />`phoneNumber: String`<br />`shiftInfo: ShiftInfo?`<br />`language: LanguageIso6391?`                                                          | `RepositoryResult<SendBizumResult>` |
| `AlipayRepository` | `makePayment` | `amount: Money`<br />`tip: Money`<br />`qrId: String`<br />`transactionName: String`<br />`qrIdType: QrIdType`<br />`languageIso6391: LanguageIso6391` | `RepositoryResult<AlipayResult>`    |
| `AlipayRepository` | `makeRefund`  | `amount: Money`<br />`originalOperationId: String`<br />`languageIso6391: LanguageIso6391`                                                                               | `RepositoryResult<AlipayResult>`    |
| `WeChatRepository` | `makePayment` | `amount: Money`<br />`tip: Money`<br />`qrId: String`<br />`transactionName: String?`<br />`languageIso6391: LanguageIso6391`                                | `RepositoryResult<WeChatResult>`    |
| `WeChatRepository` | `makeRefund`  | `amount: Money`<br />`originalOperationId: String`<br />`languageIso6391: LanguageIso6391`                                                                               | `RepositoryResult<WeChatResult>`    |