# Slim Pack: C# Integration

Integrating Get Central in a .NET environment is performed through **Platform Invocation Services (P/Invoke)**, allowing managed C# code to call the native Get Central library. This guide explains how to configure your project, declare the native functions, and execute a basic payment operation using the Slim Pack integration model.

This guide applies to **Slim Pack**.

## Requirements

Before you begin, ensure you have:

* **dllTpvpcLatente.dll** available at runtime
* All required native dependencies present in the same directory
* **Visual Studio** or another .NET-compatible IDE
* Project **Target Platform set to x86** (the library is 32-bit)

Failure to compile or run in x86 mode will result in a `BadImageFormatException`.

## C-Sharp Integration Process

The integration process consists of mapping the native library functions and invoking them from managed code. No XML is sent as a request; parameters are passed positionally, and the XML is returned as a response.

### Step 1: Declare Native Functions

Native functions are declared using the `DllImport` attribute. The library exposes a fixed set of entry points that must be mapped exactly.

**Library Initialization**

The following functions are used to initialize the library:

| Parameter     | Type   | Description                                                 |
| ------------- | ------ | ----------------------------------------------------------- |
| `cComercio`   | string | Merchant identifier assigned by the acquirer.       |
| `cTerminal`   | string | Terminal identifier associated with the PIN pad.            |
| `cClaveFirma` | string | Signature key assigned to the merchant and terminal.        |
| `cConfPuerto` | string | Communication port. Leave empty to use local configuration. |
| `cVersion`    | string | Protocol version. Leave empty to use the default version.   |

```csharp
[DllImport("dllTpvpcLatente.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
public static extern int fnDllIniTpvpcLatente(
    string cComercio,
    string cTerminal,
    string cClaveFirma,
    string cConfPuerto,
    string cVersion
);
```

**Payment Execution**

The following functions are used to execute a payment operation:

| Parameter     | Type          | Description                                       |
| ------------- | ------------- | ------------------------------------------------- |
| `cImporte`    | string        | Transaction amount in format `XXXXXXXXX.XX`.      |
| `cFactura`    | string        | Merchant reference for the transaction.           |
| `cTipoOper`   | string        | Operation type. For standard payments use `PAGO`. |
| `cXMLResp`    | StringBuilder | Buffer that receives the XML response.            |
| `iTamMaxResp` | int           | Maximum size of the response buffer.              |

```csharp
[DllImport("dllTpvpcLatente.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
public static extern int fnDllOperPinPad(
    string cImporte,
    string cFactura,
    string cTipoOper,
    StringBuilder cXMLResp,
    int iTamMaxResp
);
```

**Library Finalization**

The following functions are used to finalize the library:

| Parameter | Type | Description                        |
| --------- | ---- | ---------------------------------- |
| —         | —    | This function takes no parameters. |

```csharp
[DllImport("dllTpvpcLatente.dll", CallingConvention = CallingConvention.StdCall)]
public static extern int fnDllParaTpvpcLatente();
```

### Step 2: Initialize the Library

Before executing any transaction, the library must be initialized once per application lifecycle.

```csharp
int result = fnDllIniTpvpcLatente(
    "99999999",
    "00000001",
    "CLAVE123456",
    "",
    ""
);

if (result != 0)
{
    // Initialization failed. Do not proceed.
}
```

A return value of `0` indicates successful initialization.

### Step 3: Execute a Payment Operation

Once initialized, a standard card-present payment can be executed using `cTipoOper = "PAGO"`.

```csharp
StringBuilder xmlResponse = new StringBuilder(8192);

int result = fnDllOperPinPad(
    "1.00",
    "TEST0001",
    "PAGO",
    xmlResponse,
    xmlResponse.Capacity
);
```

When the function returns, the XML response buffer is populated with the transaction result.

### Step 4: Process the Response

The integer return value indicates only the technical execution status. The financial outcome must be determined by parsing the XML response.

A transaction is authorized only if the response contains:

```xml
<estado>F</estado>
<resultado>Autorizada</resultado>
```

Any other combination must be treated as a denied transaction.

### Step 5: Finalize the Library

When the application no longer needs to perform operations, the library should be finalized to release system resources.

```csharp
fnDllParaTpvpcLatente();
```

## Next Steps

After completing the C# integration, you can proceed with further implementation:

* To process standard payments, refer to the [Process a Single-Step Payment](/en/get-central/slim-pack-payment-guides/process-a-single-step-payment) guide.
* For details on generating and printing receipts, see the [Generate and Print Receipts](/en/get-central/slim-pack-payment-guides/generate-and-print-receipts) documentation.
* To implement subscription models, consult the [Handle Recurring Payments](/en/get-central/slim-pack-payment-guides/handle-recurring-payments) guide.
* For a complete reference of technical exit codes and host errors, refer to the [Result Codes and Errors](/en/get-central/slim-pack-reference/result-codes-and-errors) documentation.