Automatic payment methods with the Stripe Payment Element
Tags: stripe, react, webdev, tutorial
Published: 2022-07-04 10:01:34

## Introduction

In the [first post](https://dev.to/stripe/accept-a-payment-with-vite-react-stripe-and-the-payment-element-4p1b) in this series, we learned how to use Vite, Rect Stripe, and the Payment Element to accept card and Bancontact payments. If you haven’t seen that post, you can read through it [here](https://dev.to/stripe/accept-a-payment-with-vite-react-stripe-and-the-payment-element-4p1b) or checkout and run the [main branch of the GitHub repo](https://github.com/matthewling-stripe/vite-react-stripe) to see the project in action.

In this post, we’ll see how to add additional payment methods in two ways:

* By specifying more payment methods when creating a Payment Intent
* By using Stripe’s [automatic payment methods](https://stripe.com/docs/payments/payment-methods/integration-options#checkout-payment-element)

### Follow along

The completed demo is available on [GitHub](https://github.com/matthewling-stripe/vite-react-stripe/tree/02-automatic-payment-methods) on the branch `02-automatic-payment-methods`. Once you have cloned the project, you can check out this branch using `git checkout 02-automatic-payment-methods` and run it as described in the README.

### Prerequisites

This demo was built using Node version `16.10.0`, and npm version `7.24.0`. You also need a basic understanding of React components, useState, useEffect, and a Stripe account which you can [sign up for here](https://dashboard.stripe.com/register).

### What you’ll learn

In this post you’ll learn how to automatically configure payment methods in your dashboard which will then be offered to your customers in the Payment Element without changing any code in your integration.

### Quick recap

The Payment Element is an embeddable UI component that allows your integration to: 

* Leverage more than 18 payment methods with a single integration
* Customize the look and feel of the element to match your design requirements
* Dynamically optimize the ordering and presentation of payment methods to increase conversion

And the focus of this post, the [Payment Element](https://stripe.com/docs/payments/payment-element), also supports [automatic payment methods](https://stripe.com/docs/payments/payment-methods/integration-options#checkout-payment-element). Which means your single integration can support more and more payment methods as we release them by simply toggling them on in your dashboard.

### Software stack

This project uses [Vite](https://vitejs.dev/) as a build and development server, React for a frontend framework, [React Stripe](https://stripe.com/docs/stripe-js/react) to accept payments, and the Payment Element to present and confirm payments on the frontend. You can read a deep dive end-to-end integration in the [first post here](https://dev.to/stripe/accept-a-payment-with-vite-react-stripe-and-the-payment-element-4p1b).

### Specifying payment methods explicitly

While explicitly specifying payment methods requires very little work — by changing the list of methods when creating a Payment Intent — it does require you to test and redeploy your backend code when that list changes. Here’s an example of explicit payment method declaration:

```javascript
const paymentIntent = await stripe.paymentIntents.create({
  amount: 1099,
  currency: 'eur',
  payment_method_types: [
    'bancontact',
    'card',
    'eps',
    'giropay',
    'ideal',
    'p24',
    'sepa_debit',
    'sofort',
  ],
});
```

Here we’re specifying lots of European payment methods that will be presented to customers in the EU.

Alternatively, if we use [automatic payment methods](https://stripe.com/docs/payments/payment-methods/integration-options#checkout-payment-element), we can instruct the Payment Intent and Payment Element to determine the set of payment methods by looking at your dashboard settings. Therefore you can simply enable payment methods with a click of a button, which means less technical maintenance of your integration. By lowering the complexity of your integration to add more methods, it will lead to:

* Increased conversion of your customers
* Larger addressable customer base due to local payment method support
* Access to digital wallets like Apple Pay and Google Pay for an optimized checkout experience

Here’s how we can specify automatic payment methods:

```javascript
  const paymentIntent = await stripe.paymentIntents.create({
    amount: 1099,
    currency: "eur",
    automatic_payment_methods: {
      enabled: true
    },
  });
```

### Dashboard settings

In the dashboard under Settings -> Payment methods, we can see all of the methods that are available to your Stripe account based on your country. Methods are grouped by cards, wallets, and bank redirects, and you can expand each method to read more about its details such as supported currencies. Turning payment methods on or off for your integration is as simple as a click of a button.

![Payment methods dashboard](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/syt554tcfw86d0jzz2hd.png)

If you enable more payment methods and then reload the page with the Payment Element, the element will automatically display those payment methods if they are available to the user.

### Testing

Stripe provides shortcut values for many payment method types that you can use in test mode. For example, to force a 3D Secure challenge, you can supply a card number of `4000002760003184`, and for a declined card payment you can use `4000000000000002`. Those values will be listed in the testing section of the particular method. For example, for Klarna, the test values are listed on the Klarna detail page. For bank redirect payment methods, we’ll be redirected to a Stripe hosted test page where we can pass or fail the payment.

### Conclusion

Using a single integration, the Payment Element lets you access the growing number of supported payment methods on Stripe. We’re excited to see what you build, so don’t hesitate to reach out and let us know about your work!

Subscribe to our feed to learn more from our series on using the Payment Element.

### About the author

![Matthew Ling](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c8rpgkqr91ivs8sxr73g.png) 

Matthew Ling ([@mattling_dev](@mattling_dev)) is a Developer Advocate at Stripe. Matt loves to tinker with new technology, adores Ruby and coffee and also moonlighted as a pro music photographer. His photo site is at [matthewling.com](https://matthewling.com) and developer site is at [mattling.dev](https://mattling.dev).

## Stay connected

In addition, you can stay up to date with Stripe in a few ways:

📣 Follow us on [Twitter](https://twitter.com/StripeDev)
💬 Join the official [Discord server](https://stripe.com/go/developer-chat)
📺 Subscribe to our [Youtube channel](https://www.youtube.com/StripeDevelopers)
📧 Sign up for the [Dev Digest](https://go.stripe.global/dev-digest)