StripePlugin
Plugin to enable payments through Stripe via the Payment Intents API.
Requirements
-
You will need to create a Stripe account and get your secret key in the dashboard.
-
Create a webhook endpoint in the Stripe dashboard (Developers -> Webhooks, "Add an endpoint") which listens to the
payment_intent.succeededandpayment_intent.payment_failedevents. The URL should behttps://my-server.com/payments/stripe, wheremy-server.comis the host of your Vendure server. Note: for local development, you'll need to use the Stripe CLI to test your webhook locally. See the local development section below. -
Get the signing secret for the newly created webhook.
-
Install the Payments plugin and the Stripe Node library:
yarn add @vendure/payments-plugin stripeor
npm install @vendure/payments-plugin stripe
Setup
- Add the plugin to your VendureConfig
pluginsarray: For all the plugin options, see the StripePluginOptions type. - Create a new PaymentMethod in the Admin UI, and select "Stripe payments" as the handler.
- Set the webhook secret and API key in the PaymentMethod form.
Storefront usage
The plugin is designed to work with the Custom payment flow. In this flow, Stripe provides libraries which handle the payment UI and confirmation for you. You can install it in your storefront project with:
If you are using React, you should also consider installing @stripe/react-stripe-js, which is a wrapper around Stripe Elements.
The high-level workflow is:
- Create a "payment intent" on the server by executing the
createStripePaymentIntentmutation which is exposed by this plugin. - Use the returned client secret to instantiate the Stripe Payment Element:
- Once the form is submitted and Stripe processes the payment, the webhook takes care of updating the order without additional action
in the storefront. As in the code above, the customer will be redirected to
/checkout/confirmation/${orderCode}.
A full working storefront example of the Stripe integration can be found in the Remix Starter repo
Local development
- Download & install the Stripe CLI: https://stripe.com/docs/stripe-cli
- From your Stripe dashboard, go to Developers -> Webhooks and click "Add an endpoint" and follow the instructions under "Test in a local environment".
- The Stripe CLI command will look like
- The Stripe CLI will create a webhook signing secret you can then use in your config of the StripePlugin.
options
StripePluginOptionsinit
(options: StripePluginOptions) => Type<StripePlugin>Initialize the Stripe payment plugin
Configuration options for the Stripe payments plugin.
storeCustomersInStripe
booleanfalseIf set to true, a Customer object will be created in Stripe - if
it doesn't already exist - for authenticated users, which prevents payment methods attached to other Customers
to be used with the same PaymentIntent. This is done by adding a custom field to the Customer entity to store
the Stripe customer ID, so switching this on will require a database migration / synchronization.
metadata
( injector: Injector, ctx: RequestContext, order: Order, ) => Stripe.MetadataParam | Promise<Stripe.MetadataParam>v1.9.7Attach extra metadata to Stripe payment intent creation call.
Example
Note: If the paymentIntentCreateParams is also used and returns a metadata key, then the values
returned by both functions will be merged.
paymentIntentCreateParams
( injector: Injector, ctx: RequestContext, order: Order, ) => AdditionalPaymentIntentCreateParams | Promise<AdditionalPaymentIntentCreateParams>v2.1.0Provide additional parameters to the Stripe payment intent creation. By default,
the plugin will already pass the amount, currency, customer and automatic_payment_methods: { enabled: true } parameters.
For example, if you want to provide a description for the payment intent, you can do so like this:
Example
requestOptions
( injector: Injector, ctx: RequestContext, order: Order, ) => AdditionalRequestOptions | Promise<AdditionalRequestOptions>v3.1.0Provide additional options to the Stripe payment intent creation. By default,
the plugin will already pass the idempotencyKey parameter.
For example, if you want to provide a stripeAccount for the payment intent, you can do so like this:
Example
customerCreateParams
( injector: Injector, ctx: RequestContext, order: Order, ) => AdditionalCustomerCreateParams | Promise<AdditionalCustomerCreateParams>v2.1.0Provide additional parameters to the Stripe customer creation. By default,
the plugin will already pass the email and name parameters.
For example, if you want to provide an address for the customer:
Example
skipPaymentIntentsWithoutExpectedMetadata
booleanIf your Stripe account also generates payment intents which are independent of Vendure orders, you can set this
to true to skip processing those payment intents.