# Migrer vers les API Intentions de paiement et Méthodes de paiement

Découvrez comment passer des API Sources et Tokens à l'API Payment Methods.

L’[API Payment&nbsp;Methods](https://docs.stripe.com/api/payment_methods.md) doit désormais être privilégiée aux API [Tokens](https://docs.stripe.com/api/tokens.md) et [Sources](https://docs.stripe.com/api/sources.md) pour permettre aux intégrations de collecter et de stocker des informations de paiement. Elle interagit avec l’[API Payment&nbsp;Intents](https://docs.stripe.com/payments/payment-intents.md) afin de créer des paiements pour une vaste palette de moyens de paiement.

We plan to turn off Sources API support for card payments. If you currently handle any card payment methods using the Sources API, you must migrate them to the Payment Intents API. We’ll send email communication with more information about the end of support for the Sources API.

## Migrate to the Payment Intents API

To migrate your integration, update your server and front end to use the [Payment Intents API](https://docs.stripe.com/api/payment_intents.md). Typical integration options include:

- Rediriger les clients vers [Stripe&nbsp;Checkout](https://docs.stripe.com/payments/checkout.md) pour votre tunnel de paiement.
- Utilisez le [Payment&nbsp;Element](https://docs.stripe.com/payments/payment-element.md) de Stripe sur votre propre page de paiement.
- Build a custom form and use the Stripe JS SDK to complete the payment.

If you use Checkout or the Payment Element, you can add and manage most payment methods from the Stripe Dashboard without making code changes.

For specific information about integrating a card payment method using the Payment Methods API, see the instructions for that payment method in [the payment methods documentation](https://docs.stripe.com/payments/payment-methods/overview.md). The following table provides a high-level comparison of the different payment types.

| Intégration ancienne | Stripe Checkout | Payment Element | Custom form |
| --- | --- | --- | --- |
|  | Faible complexité | Complexité moyenne | Complexité élevée |
| Create a Source on the front end or on the server. | Create a `CheckoutSession` on the server. | Create a `PaymentIntent` on the server. | Create a `PaymentIntent` on the server. |
| Authorize payment by loading a widget or redirecting to a third party. | Je n’en ai pas besoin | Pass the client secret to the front end and use the Stripe JS SDK to render a Payment Element to complete the payment. | Pass the client secret to the front end, use your own form to collect details from your customer, and complete the payment according to the payment method. |
| Confirm the source is chargeable and charge the Source. | Je n’en ai pas besoin | Je n’en ai pas besoin | Je n’en ai pas besoin |
| Confirm that the Charge succeeded asynchronously with the `charge.succeeded` webhook. | Confirm that the Checkout session succeeded with the `payment_intent.succeeded` webhook. | Confirm that the PaymentIntent succeeded with the `payment_intent.succeeded` webhook. | Confirm that the PaymentIntent succeeded with the `payment_intent.succeeded` webhook. |

> #### Continued use of Charge objects
> 
> A `PaymentIntent` object represents a payment in the new integration, and it creates a `Charge` when you confirm the payment on the front end. If you previously stored references to the `Charge`, you can continue to do so by fetching the `Charge` ID from the `PaymentIntent` after the customer completes the payment. However, we also recommend that you store the `PaymentIntent` ID.

### Vérification de l’état du paiement

Previously, your integration should have checked both the status of the `Source` and the status of the `Charge` after each API call. You no longer need to check two objects—you only need to check the status of the `PaymentIntent` or the `CheckoutSession` after you confirm it on the front end.

| payment_intent.status | Signification |
| --- | --- |
| `succeeded` | Le paiement a abouti. |
| `requires_payment_method` | Le paiement a échoué. |
| `requires_action` | The customer hasn’t completed authorizing the payment, possibly [due to a 3DS requirement](https://docs.stripe.com/payments/3d-secure/authentication-flow.md#check-status). |

Always confirm the status of the `PaymentIntent` by fetching it on your server or listening for the webhook events on your server. Don’t rely solely on the user returning to the `return_url` that’s provided when you confirm the `PaymentIntent`.

### Remboursements

You can call the Refunds API using the `PaymentIntent` ID instead of the `Charge` ID.

Alternatively, you can continue to call the Refunds API with the ID of the `Charge` that the `PaymentIntent` creates. You can get the ID of the `Charge` from the [latest_charge](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-latest_charge) property.

### Gestion des erreurs

Previously, you had to handle errors on the `Source`. With `PaymentIntents`, you instead check for errors on the `PaymentIntent` when it’s created and after the customer has authorized the payment. Most errors on the `PaymentIntent` are of `invalid_request_error` type, returned in an invalid request.

When you migrate your integration, keep in mind that `PaymentIntent` error codes can differ from the corresponding error codes for `Sources`.

### Webhooks

If you previously listened to `Source` events, you might need to update your integration to listen to events for other objects instead. The following table shows some examples.

| Old event | New Checkout event | New PaymentIntent event | Instructions spéciales |
| --- | --- | --- | --- |
| `source.chargeable` | Non applicable | Non applicable |  |
| `source.failed` | Non applicable | Non applicable |  |
| `source.canceled` | Non applicable | Non applicable |  |
| `charge.succeeded` | `checkout.session.completed` | `payment_intent.succeeded` | The `charge.succeeded` event is also sent, so you can continue listening for it instead of the others. |
| `charge.failed` | Non applicable&nbsp;: le client peut retenter le paiement au cours de la même session Checkout jusqu’à son [expiration](https://docs.stripe.com/api/checkout/sessions/create.md#create_checkout_session-expires_at), auquel cas vous recevez un événement `checkout.session.expired`. | `payment_intent.payment_failed` | The `charge.failed` event is also sent, so you can continue listening for it instead of the others. |
| `charge.dispute.created` | `charge.dispute.created` | `charge.dispute.created` |  |

## Transition to the Payment Methods API 

The main difference between the Payment Methods and Sources APIs is that Sources describes the transaction state through the [status](https://docs.stripe.com/api/sources/object.md#source_object-status) property. That means that each `Source` object must transition to a chargeable state before you can use it for a payment. By contrast, a `PaymentMethod` is stateless, relying on the PaymentIntent object to represent payment state.

> Le tableau suivant ne constitue pas une liste exhaustive des moyens de paiement. Si vous intégrez d’autres moyens de paiement à l’aide de l’API Sources, migrez-les également vers l’API Payment Methods.

| Flux | Payment Methods and Payment Intents APIs | Tokens or Sources with Charges APIs |
| --- | --- | --- |
| Cartes bancaires | [Paiements par carte](https://docs.stripe.com/payments/cards.md) | Obsolète |
| Prélèvement automatique ACH | [Prélèvements automatiques de comptes bancaires aux États-Unis](https://docs.stripe.com/payments/ach-direct-debit.md) | [Supported on Tokens](https://docs.stripe.com/ach-deprecated.md); Not supported on Sources |

Après avoir choisi l’API à intégrer, utilisez le [guide des moyens de paiement](https://stripe.com/payments/payment-methods-guide) pour déterminer les types de moyens de paiement à prendre en charge.

Ce guide présente des descriptions détaillées de chaque moyen de paiement et décrit les différences dans les flux client, ainsi que les [régions géographiques](https://stripe.com/payments/payment-methods-guide#payment-methods-fact-sheets) dans lesquelles ils sont le plus pertinents. Vous pouvez activer tous les moyens de paiement figurant dans le [Dashboard](https://dashboard.stripe.com/account/payments/settings). De manière générale, cette activation est instantanée et ne nécessite pas de contrats supplémentaires.

## Migrate saved Sources to PaymentMethods 

To continue using your existing customers’ credentials saved on `Sources` or on [cards created with the Charges API](https://docs.stripe.com/payments/charges-api.md), you must convert them to `PaymentMethods` using the [data migration tool in the Stripe Dashboard](https://dashboard.stripe.com/workbench/health/migrations).

To use a migrated `PaymentMethod` with the Payment Intents API, pass the `PaymentMethod` ID and the `Customer` ID when creating a `PaymentIntent`:

```curl
curl https://api.stripe.com/v1/payment_intents \
  -u "<<YOUR_SECRET_KEY>>:" \
  -d "automatic_payment_methods[enabled]=true" \
  -d amount=1099 \
  -d currency=usd \
  -d "customer={{CUSTOMER_ID}}" \
  -d "payment_method={{PAYMENTMETHOD_ID}}"
```

## See also

- [Guide des moyens de paiement](https://stripe.com/payments/payment-methods-guide)
- [Paiements Connect](https://docs.stripe.com/connect/charges.md)
- [Documentation de l’API Payment Methods](https://docs.stripe.com/api/payment_methods.md)
