# Zahlungsabsichten (https://dev.cosmospay.lat/docs/de/sdk/server/payment-intents/)

> Erstellen, abrufen, auflisten, bearbeiten, stornieren, löschen und validieren Sie Stellar-SEP-7-Zahlungsabsichten.

Eine Zahlungsabsicht repräsentiert eine Zahlung, die ein Nutzer leisten soll. Sie ist die zentrale Ressource der API und der Manager, zu dem Sie am häufigsten greifen werden.

`client.paymentIntents` verwaltet Stellar-SEP-7-Absichten. Es gibt zwei Arten:

- **`pay`-Absicht**: keine Quelle. Das Wallet des Zahlers wählt das Quellkonto.
  Erzeugt eine `web+stellar:pay?...`-URI + QR (kein XDR).
- **`tx`-Absicht**: Quelle bekannt. Erzeugt ein unsigniertes XDR + `web+stellar:tx?...`-
  URI + QR.

## Erstellen

```ts
import { Assets } from '@cosmosapp/pay_sdk';

// pay (no source)
const pay = await client.paymentIntents.createPay({
  destination: 'G...',          // required: payee (or an address-book name)
  amount: '10',                 // optional; omit for an open amount (donations)
  asset: Assets.USDC,           // typed asset → fills assetCode + verified issuer
  // assetCode: 'USDC', assetIssuer: 'G...',  // …or set them explicitly
  // omit asset entirely for native lumens (XLM)
  memo: '123456789',            // optional MEMO_ID (uint64), auto-generated if omitted
  msg: 'Order #24',             // optional, ≤ 300 chars, shown in the wallet
  callback: 'url:https://...',  // optional SEP-7 callback for the signed XDR
});

// tx (source known)
const tx = await client.paymentIntents.createTx({
  source: 'G...PAYER',          // required (extra vs pay)
  destination: 'G...MERCHANT',
  amount: '25.5',
});
console.log(tx.xdr, tx.uri, tx.qr);
```

> Beträge sind **Dezimalzeichenketten**, maximal 7 Dezimalstellen. Asset-Aussteller sind
> netzwerkspezifisch (Mainnet vs. Testnet).

## Abrufen / auflisten

```ts
const intent = await client.paymentIntents.fetch('pi_123');

const page = await client.paymentIntents.list({
  status: 'SUCCEEDED', // optional filter (PaymentIntentStatus)
  take: 50,            // page size, max 100, default 20
  skip: 0,             // offset
});
// page → { items: PaymentIntent[], total, take, skip }
```

## Aktualisieren / stornieren / löschen

```ts
await intent.edit({ reference: 'order_1234' }); // status / txHash / reference
await intent.cancel();                          // → status CANCELLED
await intent.delete();
// manager forms: client.paymentIntents.update(id, {...}) / .delete(id)
```

## Validieren (abschließen)

```ts
const outcome = await intent.validate('<txHash>');
// → { valid, status, reason, paymentIntent }
if (outcome.valid) console.log('settled', outcome.status);
// manager form: client.paymentIntents.validate(id, { txHash })
```

Die Validierung prüft den Transaktionserfolg + Ziel + Betrag + Memo, schließt den Status
serverseitig ab und löst den Webhook aus.

## Strukturzugriffe (an einem `PaymentIntent`)

`id`, `kind`, `status`, `network`, `source`, `destination`, `amount`, `asset`,
`assetIssuer`, `memo`, `msg`, `callback`, `xdr`, `uri`, `qr`, `txHash`,
`reference`, `createdAt`, `updatedAt`. Hilfsmethoden: `isTx`, `isPay`, `isSucceeded`,
`isPending`, `assetLabel` (`'XLM'` für nativ). Methoden: `fetch()`, `edit()`,
`validate(txHash)`, `cancel()`, `delete()`, `toJSON()`.

## Referenzen

- [PaymentIntent](https://dev.cosmospay.lat/docs/sdk/definitions/server/payment-intent/): Eine Stellar-SEP-7-Zahlungsabsicht
- [Assets](https://dev.cosmospay.lat/docs/sdk/web/assets-wallets-addresses/): Typed asset / wallet catalog or address helper.
- [TestnetAssets](https://dev.cosmospay.lat/docs/sdk/web/assets-wallets-addresses/): Typed asset / wallet catalog or address helper.
