# Migration zu Bestätigungstoken

Schließen Sie Zahlungen auf dem Server mithilfe eines ConfirmationToken anstelle einer PaymentMethod ab.

In diesem Leitfaden erfahren Sie, wie Sie Zahlungen auf dem Server abschließen, indem Sie ein [ConfirmationToken](https://docs.stripe.com/api/confirmation_tokens/object.md) anstelle einer [PaymentMethod](https://docs.stripe.com/api/payment_methods.md) verwenden, um von Ihrem Client erfasste Daten an Ihren Server zu übertragen.

Ein `ConfirmationToken` enthält eine Obermenge der auf einer `PaymentMethod` gefundenen Daten, wie zum Beispiel Versandinformationen, und ermöglicht neue Funktionen, während wir diese entwickeln.

## Bestätigungstoken erstellen [clientseitig]

Rufen Sie anstatt [stripe.createPaymentMethod](https://docs.stripe.com/js/payment_methods/create_payment_method_elements) den Parameter [stripe.createConfirmationToken](https://docs.stripe.com/js/confirmation_tokens/create_confirmation_token) auf, um ein `ConfirmationToken`-Objekt zu erstellen. Übergeben Sie dieses ConfirmationToken an den Server, um den PaymentIntent zu bestätigen.

Die Methode `stripe.createConfirmationToken` akzeptiert die gleichen Parameter wie `stripe.createPaymentMethod` (über [params.payment_method_data](https://docs.stripe.com/js/confirmation_tokens/create_confirmation_token#create_confirmation_token-options-params-payment_method_data)) sowie zusätzliche Parameter für [shipping](https://docs.stripe.com/js/confirmation_tokens/create_confirmation_token#create_confirmation_token-options-params-shipping) und die [return_url](https://docs.stripe.com/js/confirmation_tokens/create_confirmation_token#create_confirmation_token-options-params-return_url).

### Before

```javascript


if (error) {
  // This point is only reached if there's an immediate error when creating the PaymentMethod.
  // Show the error to your customer (for example, payment details incomplete)
  handleError(error);
  return;
}

// Create and confirm the PaymentIntent
const res = await fetch("/create-confirm-intent", {
  method: "POST",
  headers: {"Content-Type": "application/json"},
  body: JSON.stringify({
  }),
});
```

### After

```javascript

// Create the ConfirmationToken using the details collected by the Payment Element and additional shipping information. Provide shipping and return_url if you don't want to provide it when confirming the intent on the server
const {error, confirmationToken} = await stripe.createConfirmationToken({
  elements,
  params: {
    payment_method_data: {
       billing_details: {
         name: 'Jenny Rosen',
       }
    },
    // Remove shipping if you're collecting it using Address Element or don't require it
    shipping: {
      name: 'Jenny Rosen',
      address: {
        line1: '1234 Main Street',
        city: 'San Francisco',
        state: 'CA',
        country: 'US',
        postal_code: '94111',
      },
    },
    return_url: 'https://example.com/order/123/complete',
  }
});

if (error) {
  // This point is only reached if there's an immediate error when creating the ConfirmationToken.
  // Show the error to your customer (for example, payment details incomplete)
  handleError(error);
  return;
}

// Create and confirm the PaymentIntent
const res = await fetch("/create-confirm-intent", {
  method: "POST",
  headers: {"Content-Type": "application/json"},
  body: JSON.stringify({
    confirmationTokenId: confirmationToken.id,
  }),
});

```

## Zahlung erstellen und an Stripe übermitteln [serverseitig]

Sie übergeben nun das ConfirmationToken an den Server, um den [PaymentIntent](https://docs.stripe.com/api/payment_intents.md) zu bestätigen. Dies ersetzt die vorherige Methode, bei der Sie die [PaymentMethod](https://docs.stripe.com/api/payment_methods.md) übergeben haben. Die im `ConfirmationToken` gespeicherten Eigenschaften werden auf den Intent angewendet, wenn ihre ID dem Parameter [confirmation_token](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-confirmation_token) zum Zeitpunkt der Bestätigung zur Verfügung gestellt wird.

> Wenn Sie [shipping](https://docs.stripe.com/js/confirmation_tokens/create_confirmation_token#create_confirmation_token-options-params-shipping) und [return_url](https://docs.stripe.com/js/confirmation_tokens/create_confirmation_token#create_confirmation_token-options-params-return_url) bereits auf dem ConfirmationToken angeben, müssen Sie diese Felder nicht erneut angeben, wenn Sie den PaymentIntent bestätigen.

### Before

```javascript
app.post('/create-confirm-intent', async (req, res) => {
  try {
    const intent = await stripe.paymentIntents.create({
      confirm: true,
      amount: 1099,
      currency: 'usd',
      // In the latest version of the API, specifying the `automatic_payment_methods` parameter is optional because Stripe enables its functionality by default.
      automatic_payment_methods: {enabled: true},
      use_stripe_sdk: true,
    });
    res.json({
      client_secret: intent.client_secret,
      status: intent.status
    });
  } catch (err) {
    res.json({
      error: err
    })
  }
});

```

### After

```javascript
app.post('/create-confirm-intent', async (req, res) => {
  try {
    const intent = await stripe.paymentIntents.create({
      confirm: true,
      amount: 1099,
      currency: 'usd',
      // In the latest version of the API, specifying the `automatic_payment_methods` parameter is optional because Stripe enables its functionality by default.
      automatic_payment_methods: {enabled: true},
      use_stripe_sdk: true,
      // the ConfirmationToken ID sent by your client that already has the shipping, mandate_data, and return_url data
      confirmation_token: req.body.confirmationTokenId,
    });
    res.json({
      client_secret: intent.client_secret,
      status: intent.status
    });
  } catch (err) {
    res.json({
      error: err
    })
  }
});
```

Alle Parameter, die zum Zeitpunkt der Bestätigung direkt dem PaymentIntent oder SetupIntent zur Verfügung gestellt werden, wie zum Beispiel `shipping` überschreiben die entsprechenden Eigenschaften des ConfirmationToken.

## Optional: Bedingungsparameter setup_future_usage oder capture_method anhand der Zahlungsmethode festlegen

Mit einem [ConfirmationToken](https://docs.stripe.com/api/confirmation_tokens/object.md) haben wir zusätzliche Validierungen hinzugefügt. So stellen wir sicher, dass Ihre Client-Einstellungen mit Ihren Servereinstellungen übereinstimmen. Dies kann zu Konflikten mit Ihrer Integration führen, wenn Sie `setup_future_usage` oder `capture_method` als Bedingung für den `PaymentIntent` oder `SetupIntent` basierend auf der von Kunden/der Kundin gewählten Zahlungsmethode festlegen. Wenn Sie auf dieses Problem stoßen, gehen Sie bei Ihrer Integration folgendermaßen vor:

1. Stellen Sie `setup_future_usage` oder `capture_method` beim Instanziieren von Elements *nicht* ein.
2. Legen Sie `setup_future_usage` oder `capture_method` *nicht* für den übergeordneten Parameter des Intent fest (z.&nbsp;B. `paymentIntent.create({ setup_future_usage = ‘off_session’})`).
3. Legen Sie die Parameter `setup_future_usage` oder `capture_method` für jede der Zahlungsmethoden innerhalb des `payment_method_options`-Parameters des Intent fest. Beispiel:

```javascript
stripe.paymentIntents.create({
  amount: 100,
  currency: 'USD',
  payment_method_options: {
    card: {
      setup_future_usage:  'off_session',
      capture_method: 'manual'
    },
    ideal: {
      setup_future_usage:  'off_session'
    }
  }
});
```

## Siehe auch

- [Integration entwerfen](https://docs.stripe.com/payments/payment-element/design-an-integration.md)
