> ## Documentation Index
> Fetch the complete documentation index at: https://docs.localpayment.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Fijar un tipo de cambio

Fijar un tipo de cambio te permite garantizar el precio de conversión antes de ejecutar una transacción, protegiéndote a ti y a tus usuarios de las fluctuaciones del mercado entre la cotización y la ejecución.

Los tres flujos: payins, payouts y cambio de divisas masivo: siguen el mismo patrón de dos pasos:

1. **Obtén una cotización**: llama a la [API de cotización de cambio de divisas](https://docs.localpayment.com/es/reference/currency-exchange-quote.md) especificando el tipo de operación (`payin`, `payout` o `CurrencyExchange`). Recibirá un `exchangeRateToken` con una tasa garantizada y un tiempo de vencimiento.
2. **Usa el token**: incluye el `exchangeRateToken` en tu solicitud de payin, payout o cambio de divisas masivo. La API aplica automáticamente la tasa fijada.

Las secciones siguientes usan un payin como ejemplo, pero la estructura es similar para los payouts y el cambio de divisas masivo.

> [!WARNING]
>
> **Vencimiento de la tasa**
>
> La tasa fijada solo está garantizada hasta el `expirationDate` del token. Si el token vence antes de que envíes la transacción, la operación utilizará la tasa de mercado de ese momento.

***

## Cotizar un payin

Utiliza este flujo cuando desees mostrar el tipo de cambio a tu usuario antes de cobrar un pago.

### Paso 1: solicitar una cotización

**Solicitud**

```bash curl theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
curl --request GET \
     --url 'https://api.stage.localpayment.com/api/fx/currency-exchange/payin?sourceCurrency=ARS&quoteCurrency=USD&accountNumber={{accountNumber}}&quoteAccountNumber={{accountNumber}}' \
     --header 'Authorization: Bearer <your_access_token>' \
     --header 'accept: application/json'
```

**Respuesta**

```json theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
{
  "exchangeRateToken": "5c3q89a7-f1bc-4ba5-a3b5-411ba0d144ca",
  "transactionType": "PayIn",
  "accountNumber": "{{accountNumber}}",
  "sourceCurrency": "ARS",
  "creationDate": "2024-12-27T21:33:32.6513692+00:00",
  "expirationDate": "2024-12-28T05:33:32.6513692+00:00",
  "quotes": [
    {
      "paymentMethodCode": "1005",
      "rate": 0.0008369108482392735,
      "quoteCurrency": "USD"
    },
    {
      "paymentMethodCode": "1023",
      "rate": 0.0008369108482392735,
      "quoteCurrency": "USD"
    },
    {
      "paymentMethodCode": "1000",
      "rate": 0.0008369108482392735,
      "quoteCurrency": "USD"
    }
  ]
}
```

### Paso 2: enviar el payin con el token

**Solicitud**

```bash curl theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
curl --request POST \
     --url https://api.stage.localpayment.com/api/payin/ \
     --header 'accept: application/json' \
     --header 'content-type: application/json' \
     --data '
{
  "paymentMethod": {
    "type": "CreditCard",
    "code": "1000",
    "flow": "DIRECT"
  },
  "externalId": "4423f38d-cc35-4ca9-8119-b9102059172d",
  "country": "ARG",
  "currency": "ARS",
  "amount": 100,
  "accountNumber": "{{accountNumber}}",
  "conceptCode": "0001",
  "comment": "APPROVED",
  "exchangeRateToken": "5c3q89a7-f1bc-4ba5-a3b5-411ba0d144ca,
  "merchant": {
    "type": "COMPANY",
    "name": "Company",
    "document": {
      "id": "3000091105",
      "type": "CUIT"
    }
  },
  "payer": {
    "type": "INDIVIDUAL",
    "name": "John",
    "lastname": "Doe",
    "document": {
      "id": "37993123",
      "type": "DNI"
    },
    "email": "john.doe@example.com",
    "phone": {
      "countryCode": "1",
      "areaCode": "11",
      "number": "98189123"
    },
    "bank": {
      "account": {
        "type": "C"
      }
    }
  },
  "metaData": {
    "1finalStatus": "APPROVED",
    "2finalStatus": "INPROGRESS"
  },
  "card": {
    "name": "APPRO",
    "number": "4970100000000055",
    "cvv": "123",
    "expirationMonth": "11",
    "expirationYear": "2029",
    "installments": 1,
    "save": false
  }
}
'
```

**Respuesta**

```json theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
{
  "transactionType": "PayIn",
  "externalId": "949e5683-4320-4129-bf0a-ea3b027b6cd1",
  "internalId": "22b29c98-92af-44bd-a164-1863ae2f1bb3",
  "paymentMethod": {
    "type": "CreditCard",
    "code": "1000",
    "flow": "DIRECT"
  },
  "country": "ARG",
  "currency": "ARS",
  "amount": 1002,
  "accountNumber": "{{accountNumber}}",
  "confirmed": {
    "currency": "ARS",
    "amount": 1002,
    "fxQuote": 1,
    "exchangeRateToken": null
  },
  "payment": {
    "installment": null,
    "currency": "ARS",
    "fxQuote": 1,
    "financingFee": 0,
    "amount": 1002
  },
  "localTaxes": [],
  "withHoldings": [],
  "fees": {
    "description": "Fee",
    "currency": "ARS",
    "fxSource": 210.8,
    "fxQuote": 1,
    "amount": 13.02,
    "account": "{{accountNumber}}"
  },
  "status": {
    "code": "103",
    "description": "APPROVED",
    "detail": "The payin was confirmed but not credited yet"
  },
  "ticket": null,
  "qr": null,
  "beneficiary": null,
  "merchant": {
    "type": "COMPANY",
    "name": "Company"
  },
  "payer": {
    "type": "INDIVIDUAL",
    "name": "John",
    "lastname": "Doe",
    "document": {
      "id": "37895247",
      "type": "DNI"
    },
    "email": "john.doe@example.com",
    "phone": {
      "countryCode": "1",
      "areaCode": "11",
      "number": "98789632"
    },
    "address": null,
    "birthdate": null,
    "nationality": null
  },
  "intermediaries": [],
  "wireInstructions": null,
  "date": {
    "creationDate": "2024-05-19T19:02:44.018+00:00",
    "processedDate": "2024-05-19T19:02:44.799618",
    "expirationDate": "0001-01-01T00:00:00"
  },
  "card": {
    "token": "N66a0BVHGJY/oCwOyl/CbxIJ5DmCINWeir9PY9gxVGI=",
    "bin": "402670",
    "brand": "VISA",
    "country": "RS",
    "name": "John Doe",
    "last4": "3263",
    "expirationYear": 2029,
    "expirationMonth": 9
  },
  "errors": []
}
```

```bash curl theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
curl --request POST \
     --url https://api.stage.localpayment.com/api/payout/ \
     --header 'Authorization: Bearer <your_access_token>' \
     --header 'Content-Type: application/json' \
     --data '[{
       "externalId": "3b7e91a0-2c4d-4f83-a1b2-d05143e2238a",
       "country": "ARG",
       "currency": "ARS",
       "amount": 10000,
       "accountNumber": "{{accountNumber}}",
       "exchangeRateToken": "8f2d14b3-c4ea-4912-b7a1-922cd1e255fb",
       "paymentMethod": {
         "type": "BankTransfer",
         "code": "1005",
         "flow": "DIRECT"
       }
     }]'
```

***

## Mostrar el tipo de cambio antes del checkout

Si estás creando un checkout y deseas mostrar el tipo de cambio a tu usuario **antes de que confirme el pago**, este es el flujo:

1. El usuario selecciona una cantidad y una divisa.
2. Tu backend llama a la [API de cotización de cambio de divisas](https://docs.localpayment.com/es/reference/currency-exchange-quote.md)  y recibe la tasa en el parámetro `exchangeRateToken`.
3. Tu frontend muestra: "Tú pagarás 10,000 ARS ≈ 8.37 USD (tasa: 0.000837)"
4. El usuario confirma.
5. Tu backend envía el payin con el `exchangeRateToken`  para aplicar la tasa fijada.

Esto garantiza que la tasa que vio tu usuario sea la tasa aplicada a la transacción, siempre que la envíes antes del `expirationDate` del token.

> [!NOTE]
>
> **Consejo de diseño:**
>
> Muestra el `expirationDate` en tu interfaz como una cuenta regresiva (p. ej., *"Tasa válida por 8 horas"*). Esto establece la expectativa correcta y reduce los tickets de soporte cuando una tasa cambia entre sesiones.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.