> ## 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.

# Bloccare un tasso di cambio

Bloccare un tasso di cambio ti permette di garantire il prezzo di conversione prima di eseguire una transazione, proteggendo te e i tuoi utenti dalle fluttuazioni del mercato tra la quotazione e l'esecuzione.

Tutti e tre i flussi (payin, payout e cambio massivo) seguono lo stesso schema in due passaggi:

1. **Ottieni una quotazione**: chiama l'[API di quotazione del cambio valuta](https://docs.localpayment.com/it/reference/currency-exchange-quote.md) specificando il tipo di operazione (`payin`, `payout` o `CurrencyExchange`). Riceverai un `exchangeRateToken` con un tasso garantito e una scadenza.
2. **Usa il token**: includi l'`exchangeRateToken` nella richiesta di payin, payout o cambio massivo. L'API applica automaticamente il tasso bloccato.

Le sezioni seguenti usano un payin come esempio, ma la struttura è simile per i payout e per il cambio massivo.

> [!WARNING]
>
> **Scadenza del tasso**
>
> Il tasso bloccato è garantito solo fino alla `expirationDate` del token. Se il token scade prima che tu invii la transazione, l'operazione userà il tasso di mercato di quel momento.

***

## Ottenere la quotazione di un payin

Usa questo flusso quando vuoi mostrare il tasso di cambio all'utente prima di incassare un pagamento.

### Passaggio 1: richiedere una quotazione

**Richiesta**

```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'
```

**Risposta**

```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"
    }
  ]
}
```

### Passaggio 2: inviare il payin con il token

**Richiesta**

```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
  }
}
'
```

**Risposta**

```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"
       }
     }]'
```

***

## Mostrare il tasso di cambio prima del checkout

Se stai creando un checkout e vuoi mostrare il tasso di cambio all'utente **prima che confermi il pagamento**, il flusso è il seguente:

1. L'utente seleziona un importo e una valuta.
2. Il tuo backend chiama l'[API di quotazione del cambio valuta](https://docs.localpayment.com/it/reference/currency-exchange-quote.md) e riceve il tasso nel parametro `exchangeRateToken`.
3. Il tuo frontend mostra: “Pagherai 10,000 ARS ≈ 8.37 USD (tasso: 0.000837)”
4. L'utente conferma.
5. Il tuo backend invia il payin con l'`exchangeRateToken` per applicare il tasso bloccato.

In questo modo il tasso che l'utente ha visto è quello applicato alla transazione, a condizione che tu invii la richiesta prima della `expirationDate` del token.

> [!NOTE]
>
> **Suggerimento di design:**
>
> Mostra la `expirationDate` nella tua interfaccia come conto alla rovescia (ad es. *“Tasso valido per 8 ore”*). In questo modo imposti le giuste aspettative e riduci i ticket di assistenza quando un tasso cambia tra una sessione e l'altra.


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