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

# Simulare un pagamento su un conto virtuale

Scopri come testare la tua integrazione dei conti virtuali simulando pagamenti in entrata nell'ambiente Stage. Convalida i listener dei webhook e la logica di riconciliazione senza bonifici bancari reali.

Testare l'integrazione dei conti virtuali è un passaggio fondamentale prima di andare in produzione. Per facilitarlo, Localpayment mette a disposizione nell'**ambiente Stage** un endpoint di simulazione che ti consente di attivare un pagamento in entrata fittizio verso qualsiasi conto virtuale attivo.

Questa simulazione riproduce il comportamento di un vero trasferimento ACH locale e genera gli stessi aggiornamenti di stato interni e le stesse notifiche webhook che ti aspetteresti in produzione.

## Flusso della simulazione

1. **Crea un conto virtuale**: per prima cosa, genera un conto virtuale nell'ambiente Stage.
2. **Recupera lo stato del conto virtuale**: usa l'endpoint [Ottenere lo stato di un conto virtuale](https://docs.localpayment.com/it/reference/get-virtual-account-status.md) per confermare che il conto sia stato creato correttamente e ricavare dalla risposta il campo `beneficiary.bank.account.number`.
3. **Collega la simulazione**: nella richiesta di simulazione, usa il `beneficiary.bank.account.number` ottenuto al passaggio precedente per collegare il pagamento fittizio al conto corretto. Fornisci inoltre un `externalId` univoco: funge da ID del payin generato per questa transazione; usa un `externalId` diverso per ogni richiesta di simulazione. Devi anche includere il tuo **accountNumber** Localpayment (ID esercente) per identificare il conto esercente associato al pagamento simulato.
4. **Avvia la simulazione**: chiama l'endpoint [Simulare un pagamento su un conto virtuale](https://docs.localpayment.com/it/reference/simulate-payin-to-virtual-account.md).
5. **Ricevi il webhook**: Localpayment invierà un webhook `payin.completed` (o simile) al tuo endpoint configurato.
6. **Verifica lo stato**: usa l'API di stato della transazione per confermare che la transazione fittizia abbia raggiunto lo stato previsto.

***

## Dipendenze tecniche

> [!NOTE]
>
> **Requisito di sequenza**: non puoi simulare un pagamento per un conto che non è stato creato correttamente. Se la chiamata [Creare un conto virtuale](https://docs.localpayment.com/it/reference/create-virtual-account.md) non va a buon fine, il tentativo di simulazione restituirà un errore 404 Not Found.

***

## Esempi di codice (Stage)

Seleziona il tuo mercato di destinazione per vedere un esempio `curl` completo. Usa gli stessi dati del beneficiario forniti durante la creazione del conto virtuale e indica un `externalId` univoco per ogni richiesta di simulazione.

> [tab] Argentina
>
> ```bash theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
> curl --request POST \
>   --url https://api.stage.localpayment.com/api/simulate/va \
>   --header 'Authorization: Bearer {{access_token}}' \
>   --header 'accept: application/json' \
>   --header 'content-type: application/json' \
>   --data '
> {
>   "externalId": "de14bcf2-15ee-22e3-ab59-99c3fcba31e8",
>   "paymentMethod": {
>     "type": "BankTransfer",
>     "code": "1025",
>     "flow": "DIRECT"
>   },
>   "country": "ARG",
>   "currency": "ARS",
>   "amount": 100.00,
>   "accountNumber": "{{accountNumber}}",
>   "beneficiary": {
>     "type": "INDIVIDUAL",
>     "name": "Camilo",
>     "lastName": "Sabogal",
>     "fullName": "Camilo Sabogal",
>     "document": {
>       "type": "CUIT",
>       "id": "20314567894"
>     },
>     "bank": {
>       "account": {
>         "number": "3745135018378011718454"
>       }
>     }
>   },
>   "payer": {
>     "type": "INDIVIDUAL",
>     "name": "Carlos",
>     "lastName": "Mendez",
>     "fullName": "Carlos Mendez",
>     "document": {
>       "type": "CUIT",
>       "id": "20314567894"
>     },
>     "email": "carlos.mendez@email.com",
>     "bank": {
>       "name": "Banco Galicia",
>       "code": "007",
>       "account": {
>         "type": "CBU",
>         "number": "0070001200001234567890"
>       }
>     }
>   }
> }
> '
> ```

> [tab] Brasile
>
> ```bash theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
> curl --request POST \
>   --url https://api.stage.localpayment.com/api/simulate/va \
>   --header 'Authorization: Bearer {{access_token}}' \
>   --header 'accept: application/json' \
>   --header 'content-type: application/json' \
>   --data '
> {
>   "externalId": "0d55e796-bba6-4cf0-aead-8d9c1ed31044",
>   "paymentMethod": {
>     "type": "BankTransfer",
>     "code": "1350",
>     "flow": "DIRECT"
>   },
>   "country": "BRA",
>   "currency": "BRL",
>   "amount": 100.00,
>   "accountNumber": "{{accountNumber}}",
>   "beneficiary": {
>     "type": "INDIVIDUAL",
>     "name": "Rafael",
>     "lastName": "Oliveira",
>     "fullName": "Rafael Oliveira",
>     "document": {
>       "type": "CPF",
>       "id": "12345678909"
>     },
>     "bank": {
>       "account": {
>         "number": "00099999-8"
>       }
>     }
>   },
>   "payer": {
>     "type": "INDIVIDUAL",
>     "name": "Rafael",
>     "lastName": "Oliveira",
>     "fullName": "Rafael Oliveira",
>     "document": {
>       "type": "CPF",
>       "id": "12345678909"
>     },
>     "email": "rafael.oliveira@email.com",
>     "bank": {
>       "name": "Itau",
>       "code": "341",
>       "account": {
>         "number": "12345-6"
>       }
>     }
>   }
> }
> '
> ```

> [tab] Cile
>
> ```bash theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
> curl --request POST \
>   --url https://api.stage.localpayment.com/api/simulate/va \
>   --header 'Authorization: Bearer {{access_token}}' \
>   --header 'accept: application/json' \
>   --header 'content-type: application/json' \
>   --data '
> {
>   "externalId": "d2ffc771-2678-4dcc-8819-d446656a19f9",
>   "paymentMethod": {
>     "type": "BankTransfer",
>     "code": "2530",
>     "flow": "DIRECT"
>   },
>   "country": "CHL",
>   "currency": "CLP",
>   "amount": 100.00,
>   "accountNumber": "{{accountNumber}}",
>   "beneficiary": {
>     "type": "INDIVIDUAL",
>     "name": "Valentina",
>     "lastName": "Rojas",
>     "fullName": "Valentina Rojas",
>     "document": {
>       "type": "RUT",
>       "id": "123456789"
>     },
>     "bank": {
>       "account": {
>         "number": "00099999999"
>       }
>     }
>   },
>   "payer": {
>     "type": "INDIVIDUAL",
>     "name": "Valentina",
>     "lastName": "Rojas",
>     "fullName": "Valentina Rojas",
>     "document": {
>       "type": "RUT",
>       "id": "123456789"
>     },
>     "email": "valentina.rojas@email.com",
>     "bank": {
>       "name": "Banco de Chile",
>       "code": "001",
>       "account": {
>         "number": "00112345678"
>       }
>     }
>   }
> }
> '
> ```

> [tab] Colombia
>
> ```bash theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
> curl --request POST \
>   --url https://api.stage.localpayment.com/api/simulate/va \
>   --header 'Authorization: Bearer {{access_token}}' \
>   --header 'accept: application/json' \
>   --header 'content-type: application/json' \
>   --data '
> {
>   "externalId": "b3e14f73-8452-49b2-bf3c-b770774edfa8",
>   "paymentMethod": {
>     "type": "BankTransfer",
>     "code": "2006",
>     "flow": "DIRECT"
>   },
>   "country": "COL",
>   "currency": "COP",
>   "amount": 100.00,
>   "accountNumber": "{{accountNumber}}",
>   "beneficiary": {
>     "type": "INDIVIDUAL",
>     "name": "Andres",
>     "lastName": "Herrera",
>     "fullName": "Andres Herrera",
>     "document": {
>       "type": "CC",
>       "id": "1020456789"
>     },
>     "bank": {
>       "account": {
>         "number": "20099999999"
>       }
>     }
>   },
>   "payer": {
>     "type": "INDIVIDUAL",
>     "name": "Andres",
>     "lastName": "Herrera",
>     "fullName": "Andres Herrera",
>     "document": {
>       "type": "CC",
>       "id": "1020456789"
>     },
>     "email": "andres.herrera@email.com",
>     "bank": {
>       "name": "Bancolombia",
>       "code": "007",
>       "account": {
>         "number": "20012345678"
>       }
>     }
>   }
> }
> '
> ```

> [tab] Costa Rica (CRC)
>
> ```bash theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
> curl --request POST \
>   --url https://api.stage.localpayment.com/api/simulate/va \
>   --header 'Authorization: Bearer {{access_token}}' \
>   --header 'accept: application/json' \
>   --header 'content-type: application/json' \
>   --data '
> {
>   "externalId": "a1c2e3f4-5b6d-47a8-9c0e-1f2a3b4c5d6e",
>   "paymentMethod": {
>     "type": "BankTransfer",
>     "code": "1420",
>     "flow": "DIRECT"
>   },
>   "country": "CRI",
>   "currency": "CRC",
>   "amount": 100.00,
>   "accountNumber": "{{accountNumber}}",
>   "beneficiary": {
>     "type": "INDIVIDUAL",
>     "name": "Carlos",
>     "lastName": "Mendez",
>     "fullName": "Carlos Mendez",
>     "document": {
>       "type": "CI",
>       "id": "2-0456-0789"
>     },
>     "bank": {
>       "account": {
>         "number": "CR91090100000000125311"
>       }
>     }
>   },
>   "payer": {
>     "type": "INDIVIDUAL",
>     "name": "John",
>     "lastName": "Doe",
>     "fullName": "John Doe",
>     "document": {
>       "type": "CI",
>       "id": "01-0100-0001"
>     },
>     "email": "john.doe@email.com",
>     "bank": {
>       "name": "Banco Nacional de Costa Rica",
>       "code": "0151",
>       "account": {
>         "number": "CR99000000000000000003"
>       }
>     }
>   }
> }
> '
> ```

> [tab] Costa Rica (USD)
>
> ```bash theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
> curl --request POST \
>   --url https://api.stage.localpayment.com/api/simulate/va \
>   --header 'Authorization: Bearer {{access_token}}' \
>   --header 'accept: application/json' \
>   --header 'content-type: application/json' \
>   --data '
> {
>   "externalId": "b2d3f4a5-6c7e-48b9-a1d0-2f3b4c5d6e7f",
>   "paymentMethod": {
>     "type": "BankTransfer",
>     "code": "1421",
>     "flow": "DIRECT"
>   },
>   "country": "CRI",
>   "currency": "USD",
>   "amount": 100.00,
>   "accountNumber": "{{accountNumber}}",
>   "beneficiary": {
>     "type": "INDIVIDUAL",
>     "name": "Carlos",
>     "lastName": "Mendez",
>     "fullName": "Carlos Mendez",
>     "document": {
>       "type": "CI",
>       "id": "2-0456-0789"
>     },
>     "bank": {
>       "account": {
>         "number": "CR91090100000000125511"
>       }
>     }
>   },
>   "payer": {
>     "type": "INDIVIDUAL",
>     "name": "John",
>     "lastName": "Doe",
>     "fullName": "John Doe",
>     "document": {
>       "type": "CI",
>       "id": "01-0100-0001"
>     },
>     "email": "john.doe@email.com",
>     "bank": {
>       "name": "Banco Nacional de Costa Rica",
>       "code": "0151",
>       "account": {
>         "number": "CR99000000000000000002"
>       }
>     }
>   }
> }
> '
> ```

> [tab] Messico (SPEI)
>
> ```bash theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
> curl --request POST \
>   --url https://api.stage.localpayment.com/api/simulate/va \
>   --header 'Authorization: Bearer {{access_token}}' \
>   --header 'accept: application/json' \
>   --header 'content-type: application/json' \
>   --data '
> {
>   "externalId": "f059a032-9253-4607-9b8e-2948ed18d595",
>   "paymentMethod": {
>     "type": "BankTransfer",
>     "code": "1630",
>     "flow": "DIRECT"
>   },
>   "country": "MEX",
>   "currency": "MXN",
>   "amount": 100.00,
>   "accountNumber": "{{accountNumber}}",
>   "beneficiary": {
>     "type": "INDIVIDUAL",
>     "name": "Juan",
>     "lastName": "Perez",
>     "fullName": "Juan Perez",
>     "document": {
>       "type": "RFC",
>       "id": "PEPJ800101XXX"
>     },
>     "bank": {
>       "account": {
>         "number": "137424104400399999"
>       }
>     }
>   },
>   "payer": {
>     "type": "INDIVIDUAL",
>     "name": "Alejandra",
>     "lastName": "Guzman",
>     "fullName": "Alejandra Guzman",
>     "document": {
>       "type": "RFC",
>       "id": "KCWV771228TS4"
>     },
>     "email": "alejandra.guzman@email.com",
>     "bank": {
>       "name": "BanCoppel",
>       "code": "137",
>       "account": {
>         "type": "C",
>         "number": "137424104400310004"
>       }
>     }
>   }
> }
> '
> ```

> [tab] Messico (TEF)
>
> ```bash theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
> curl --request POST \
>   --url https://api.stage.localpayment.com/api/simulate/va \
>   --header 'Authorization: Bearer {{access_token}}' \
>   --header 'accept: application/json' \
>   --header 'content-type: application/json' \
>   --data '
> {
>   "externalId": "b8c924d1-3f7a-4e82-bc1d-9a06fe37510c",
>   "paymentMethod": {
>     "type": "BankTransfer",
>     "code": "1680",
>     "flow": "DIRECT"
>   },
>   "country": "MEX",
>   "currency": "MXN",
>   "amount": 100.00,
>   "accountNumber": "{{accountNumber}}",
>   "beneficiary": {
>     "type": "COMPANY",
>     "name": "Servicios Digitales México S.A.",
>     "document": {
>       "type": "RFC",
>       "id": "HEMJ900101ABC"
>     },
>     "bank": {
>       "account": {
>         "number": "000000000000000009"
>       }
>     }
>   },
>   "payer": {
>     "type": "COMPANY",
>     "name": "Juan",
>     "lastName": "Doe",
>     "fullName": "Juan Doe",
>     "document": {
>       "type": "RFC",
>       "id": "HEMJ900101ABC"
>     },
>     "email": "juan.doe@email.com",
>     "bank": {
>       "name": "BANCO INBURSA",
>       "code": "036",
>       "account": {
>         "type": "CLABE",
>         "number": "00000000000000000001"
>       }
>     }
>   }
> }
> '
> ```

> [tab] Perù
>
> ```bash theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
> curl --request POST \
>   --url https://api.stage.localpayment.com/api/simulate/va \
>   --header 'Authorization: Bearer {{access_token}}' \
>   --header 'accept: application/json' \
>   --header 'content-type: application/json' \
>   --data '
> {
>   "externalId": "e6807dd1-e910-41ea-9adc-b240a5509dd3",
>   "paymentMethod": {
>     "type": "BankTransfer",
>     "code": "6100",
>     "flow": "DIRECT"
>   },
>   "country": "PER",
>   "currency": "PEN",
>   "amount": 100.00,
>   "accountNumber": "{{accountNumber}}",
>   "beneficiary": {
>     "type": "INDIVIDUAL",
>     "name": "Lucia",
>     "lastName": "Torres",
>     "fullName": "Lucia Torres",
>     "document": {
>       "type": "DNI",
>       "id": "45678901"
>     },
>     "bank": {
>       "account": {
>         "number": "00219100111111100009"
>       }
>     }
>   },
>   "payer": {
>     "type": "INDIVIDUAL",
>     "name": "Lucia",
>     "lastName": "Torres",
>     "fullName": "Lucia Torres",
>     "document": {
>       "type": "DNI",
>       "id": "45678901"
>     },
>     "email": "lucia.torres@email.com",
>     "bank": {
>       "name": "BCP",
>       "code": "002",
>       "account": {
>         "number": "19400123456789"
>       }
>     }
>   }
> }
> '
> ```

***

## Esempio di notifica webhook

Dopo un'elaborazione riuscita, Localpayment invia un evento sincrono `payin.completed` al tuo endpoint configurato. Questa notifica segue la struttura `PayIn` standard di alto livello comune a tutti i prodotti di pagamento.

```json MEX (SPEI) theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
{
  "transactionType": "PayIn",
  "transactionFlow": null,
  "country": "MEX",
  "data": {
    "transactionType": "PayIn",
    "externalId": "f059a032-9253-4607-9b8e-2948ed18d595",
    "internalId": "5aced5da-40c1-4bec-85ff-c8cd1bcb4526",
    "paymentMethod": {
      "type": "BankTransfer",
      "code": "1630",
      "flow": "DIRECT"
    },
    "country": "MEX",
    "currency": "MXN",
    "amount": 100.00,
    "accountNumber": "{{accountNumber}}",
    "confirmed": {
      "currency": "MXN",
      "fxQuote": 1.0,
      "amount": 100.00
    },
    "beneficiary": {
      "type": "INDIVIDUAL",
      "name": "Juan",
      "lastName": "Perez",
      "fullName": "Juan Perez",
      "document": {
        "type": "RFC",
        "id": "PEPJ800101XXX"
      }
    },
    "payer": {
      "type": "INDIVIDUAL",
      "name": "Alejandra",
      "lastName": "Guzman",
      "fullName": "Alejandra Guzman",
      "document": {
        "type": "RFC",
        "id": "KCWV771228TS4"
      }
    },
    "status": {
      "code": "200",
      "description": "COMPLETED",
      "detail": "The payin was credited"
    },
    "date": {
      "creationDate": "2024-03-27T15:00:00Z",
      "processedDate": "2024-03-27T15:00:05Z"
    }
  }
}
```

```json MEX (TEF) theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
{
  "transactionType": "PayIn",
  "transactionFlow": null,
  "country": "MEX",
  "data": {
    "transactionType": "PayIn",
    "externalId": "b8c924d1-3f7a-4e82-bc1d-9a06fe37510c",
    "internalId": "e05fc3c3-f739-4393-b275-4a12f5a1af15",
    "paymentMethod": {
      "type": "BankTransfer",
      "code": "1680",
      "flow": "DIRECT"
    },
    "country": "MEX",
    "currency": "MXN",
    "amount": 1000.01,
    "accountNumber": "{{accountNumber}}",
    "confirmed": {
      "currency": "MXN",
      "fxQuote": 1,
      "amount": 1000.01
    },
    "beneficiary": {
      "type": "COMPANY",
      "name": "Servicios Digitales México S.A.",
      "document": {
        "type": "RFC",
        "id": "HEMJ900101ABC"
      },
      "bank": {
        "name": "Banco Central",
        "code": "001",
        "account": {
          "number": "000000000000000009"
        }
      }
    },
    "payer": {
      "type": "COMPANY",
      "name": "Juan",
      "lastName": "Doe",
      "fullName": "Juan Doe",
      "document": {
        "type": "RFC",
        "id": "HEMJ900101ABC"
      },
      "bank": {
        "name": "BANCO INBURSA",
        "code": "036",
        "account": {
          "type": "CLABE",
          "number": "00000000000000000001"
        }
      }
    },
    "status": {
      "code": "200",
      "description": "COMPLETED",
      "detail": "The payin was credited"
    },
    "date": {
      "creationDate": "2024-03-27T15:00:00Z",
      "processedDate": "2024-03-27T15:00:05Z"
    }
  }
}
```

***

## Risoluzione dei problemi

| Codice di errore | Possibile causa | Soluzione consigliata |
| :- | :- | :- |
| **400 Bad Request** | Identità del pagatore non valida o campi mancanti. | Assicurati che i dati del pagatore corrispondano alle informazioni del beneficiario usate durante la creazione del conto virtuale. |
| **404 Not Found** | L'`externalId` non corrisponde ad alcun conto virtuale attivo. | Prima di eseguire la simulazione, verifica che il conto virtuale sia stato creato correttamente in Stage. |
| **401 Unauthorized** | Token non valido o token di produzione. | Verifica di usare la chiave API dell'**ambiente Stage**. |
| **422 Unprocessable** | Importo o valuta non corrispondenti. | Verifica che la valuta corrisponda al `paymentMethod.code` selezionato. |

***

## Passaggi successivi

> [card] [Verificare lo stato](https://docs.localpayment.com/it/reference/get-transaction-status.md)
>
> Recupera gli aggiornamenti di stato in tempo reale per confermare l'avanzamento della transazione fittizia.

> [card] [Configurare i webhook](https://docs.localpayment.com/it/docs/webhooks.md)
>
> Convalida la logica del tuo listener con notifiche di successo reali.


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