# Ejemplos de integracion

## curl

```bash
curl -X POST http://localhost:3000/api/v1/payment-references \
  -H "Content-Type: application/json" \
  -H "x-api-key: test-api-key" \
  -H "Idempotency-Key: RECIBO-2026-000001" \
  -d '{"external_reference":"RECIBO-2026-000001","contract_number":"CONTRATO-123456","customer_name":"Juan Perez","amount":248.50,"currency":"MXN","description":"Pago de agua potable","due_date":"2026-07-15T23:59:59-06:00","period":"2026-06"}'
```

## JavaScript

```javascript
const response = await fetch('http://localhost:3000/api/v1/payment-references', {
  method: 'POST',
  headers: {
    'content-type': 'application/json',
    'x-api-key': process.env.PAYNET_API_KEY,
    'Idempotency-Key': 'RECIBO-2026-000001'
  },
  body: JSON.stringify({
    external_reference: 'RECIBO-2026-000001',
    contract_number: 'CONTRATO-123456',
    customer_name: 'Juan Perez',
    amount: 248.50,
    currency: 'MXN',
    description: 'Pago de agua potable',
    due_date: '2026-07-15T23:59:59-06:00',
    period: '2026-06'
  })
});
console.log(await response.json());
```

## PHP

```php
<?php
$payload = [
  "external_reference" => "RECIBO-2026-000001",
  "contract_number" => "CONTRATO-123456",
  "customer_name" => "Juan Perez",
  "amount" => 248.50,
  "currency" => "MXN",
  "description" => "Pago de agua potable",
  "due_date" => "2026-07-15T23:59:59-06:00",
  "period" => "2026-06"
];
$ch = curl_init("http://localhost:3000/api/v1/payment-references");
curl_setopt_array($ch, [
  CURLOPT_POST => true,
  CURLOPT_HTTPHEADER => [
    "Content-Type: application/json",
    "x-api-key: " . getenv("PAYNET_API_KEY"),
    "Idempotency-Key: RECIBO-2026-000001"
  ],
  CURLOPT_POSTFIELDS => json_encode($payload),
  CURLOPT_RETURNTRANSFER => true
]);
echo curl_exec($ch);
```

## C#

```csharp
using System.Net.Http.Headers;
using System.Text;

var client = new HttpClient();
client.DefaultRequestHeaders.Add("x-api-key", Environment.GetEnvironmentVariable("PAYNET_API_KEY"));
client.DefaultRequestHeaders.Add("Idempotency-Key", "RECIBO-2026-000001");

var json = """
{
  "external_reference": "RECIBO-2026-000001",
  "contract_number": "CONTRATO-123456",
  "customer_name": "Juan Perez",
  "amount": 248.50,
  "currency": "MXN",
  "description": "Pago de agua potable",
  "due_date": "2026-07-15T23:59:59-06:00",
  "period": "2026-06"
}
""";

var response = await client.PostAsync(
  "http://localhost:3000/api/v1/payment-references",
  new StringContent(json, Encoding.UTF8, "application/json")
);
Console.WriteLine(await response.Content.ReadAsStringAsync());
```

## Java

```java
HttpClient client = HttpClient.newHttpClient();
String body = """
{
  "external_reference": "RECIBO-2026-000001",
  "contract_number": "CONTRATO-123456",
  "customer_name": "Juan Perez",
  "amount": 248.50,
  "currency": "MXN",
  "description": "Pago de agua potable",
  "due_date": "2026-07-15T23:59:59-06:00",
  "period": "2026-06"
}
""";

HttpRequest request = HttpRequest.newBuilder()
  .uri(URI.create("http://localhost:3000/api/v1/payment-references"))
  .header("Content-Type", "application/json")
  .header("x-api-key", System.getenv("PAYNET_API_KEY"))
  .header("Idempotency-Key", "RECIBO-2026-000001")
  .POST(HttpRequest.BodyPublishers.ofString(body))
  .build();

HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
```
