import { Type } from "@deenruv/core";
import { StripePluginOptions } from "./types";
/**
* @description
* Plugin to enable payments through [Stripe](https://stripe.com/docs) via the Payment Intents API.
*
* ## Requirements
*
* 1. You will need to create a Stripe account and get your secret key in the dashboard.
* 2. Create a webhook endpoint in the Stripe dashboard (Developers -> Webhooks, "Add an endpoint") which listens to the `payment_intent.succeeded`
* and `payment_intent.payment_failed` events. The URL should be `https://my-server.com/payments/stripe`, where
* `my-server.com` is the host of your Deenruv server. *Note:* for local development, you'll need to use
* the Stripe CLI to test your webhook locally. See the _local development_ section below.
* 3. Get the signing secret for the newly created webhook.
* 4. Install the Payments plugin and the Stripe Node library:
*
* `yarn add \@deenruv/payments-plugin stripe`
*
* or
*
* `npm install \@deenruv/payments-plugin stripe`
*
* ## Setup
*
* 1. Add the plugin to your DeenruvConfig `plugins` array:
* ```ts
* import { StripePlugin } from '\@deenruv/payments-plugin/package/stripe';
*
* // ...
*
* plugins: [
* StripePlugin.init({
* // This prevents different customers from using the same PaymentIntent
* storeCustomersInStripe: true,
* }),
* ]
* ````
* For all the plugin options, see the {@link StripePluginOptions} type.
* 2. Create a new PaymentMethod in the Admin UI, and select "Stripe payments" as the handler.
* 3. Set the webhook secret and API key in the PaymentMethod form.
*
* ## Storefront usage
*
* The plugin is designed to work with the [Custom payment flow](https://stripe.com/docs/payments/accept-a-payment?platform=web&ui=elements).
* In this flow, Stripe provides libraries which handle the payment UI and confirmation for you. You can install it in your storefront project
* with:
*
* ```shell
* yarn add \@stripe/stripe-js
* # or
* npm install \@stripe/stripe-js
* ```
*
* 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:
* 1. Create a "payment intent" on the server by executing the `createStripePaymentIntent` mutation which is exposed by this plugin.
* 2. Use the returned client secret to instantiate the Stripe Payment Element:
* ```ts
* import { Elements } from '\@stripe/react-stripe-js';
* import { loadStripe, Stripe } from '\@stripe/stripe-js';
* import { CheckoutForm } from './CheckoutForm';
*
* const stripePromise = getStripe('pk_test_....wr83u');
*
* type StripePaymentsProps = {
* clientSecret: string;
* orderCode: string;
* }
*
* export function StripePayments({ clientSecret, orderCode }: StripePaymentsProps) {
* const options = {
* // passing the client secret obtained from the server
* clientSecret,
* }
* return (
*