Skip to content

Commit f6fd546

Browse files
committed
docs: add new quickstart, examples and more
1 parent 4c3d823 commit f6fd546

File tree

2 files changed

+90
-39
lines changed

2 files changed

+90
-39
lines changed

README.md

Lines changed: 90 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
Vue 3 components for Stripe. Build advanced payment integrations quickly. Easy to start, friendly DX, minimal abstractions, and full control. It's a glue between Stripe.js and Vue component lifecycle.
1111

12-
# Quickstart
12+
## Quickstart ⚡️
1313

1414
### 1. Install
1515

@@ -21,8 +21,8 @@ npm i vue-stripe-js @stripe/stripe-js
2121

2222
```vue
2323
<script setup lang="ts">
24-
import { loadStripe } from "@stripe/stripe-js"
2524
import { onBeforeMount, ref } from "vue"
25+
import { loadStripe } from "@stripe/stripe-js"
2626
import type { Stripe } from "@stripe/stripe-js"
2727
2828
const publishableKey = ref('')
@@ -34,20 +34,23 @@ onBeforeMount(async() => {
3434
</script>
3535
```
3636

37-
Alternatively, include a script tag. Make sure Stripe.js is loaded before you mount vue components.
37+
Alternatively, include a script tag. Make sure Stripe.js is loaded before you mount Vue components.
3838

3939
```html
4040
<script src="https://js.stripe.com/v3/"></script>
4141
```
4242

4343
### 3. Payment Element
4444

45-
This example is based on – [deferred payment guide](https://docs.stripe.com/payments/accept-a-payment-deferred?type=payment)
45+
Based on – [deferred payment guide](https://docs.stripe.com/payments/accept-a-payment-deferred?type=payment)
46+
4647
```vue
4748
<template>
48-
<form @submit.prevent="handleSubmit">
49+
<form
50+
v-if="stripeLoaded"
51+
@submit.prevent="handleSubmit"
52+
>
4953
<StripeElements
50-
v-if="stripeLoaded"
5154
:stripe-key="stripeKey"
5255
:instance-options="stripeOptions"
5356
:elements-options="elementsOptions"
@@ -68,10 +71,9 @@ This example is based on – [deferred payment guide](https://docs.stripe.com/pa
6871
</template>
6972
7073
<script setup lang="ts">
71-
import StripeElements from "vue-stripe-js"
72-
import StripeElement from "vue-stripe-js"
73-
import { loadStripe } from "@stripe/stripe-js"
7474
import { onBeforeMount, ref, useTemplateRef } from "vue"
75+
import { loadStripe } from "@stripe/stripe-js"
76+
import { StripeElements, StripeElement } from "vue-stripe-js"
7577
7678
import type {
7779
StripeElementsOptionsMode,
@@ -86,13 +88,13 @@ const elementsOptions = ref<StripeElementsOptionsMode>({
8688
// https://stripe.com/docs/js/elements_object/create#stripe_elements-options
8789
mode: "payment",
8890
amount: 1099,
89-
currency: "eur",
91+
currency: "usd",
9092
appearance: {
9193
theme: "flat",
9294
},
9395
})
9496
const paymentElementOptions = ref<StripePaymentElementOptions>({
95-
// https://stripe.com/docs/stripe.js#element-options
97+
// https://docs.stripe.com/js/elements_object/create_payment_element#payment_element_create-options
9698
})
9799
const stripeLoaded = ref(false)
98100
const clientSecret = ref("")
@@ -141,38 +143,65 @@ async function handleSubmit() {
141143
142144
```
143145

144-
### 4. Payment element (requires backend)
146+
## Examples 🌿
147+
148+
Thanks to the Provider Pattern used in Stripe Elements, you get minimalist tools with full access to Stripe.js methods and properties. This results in better developer experience (DX), simpler code, and fewer bugs.
149+
150+
These examples use Vue Composition API and TypeScript.
145151

146-
1. Add server code by following
147-
[stripe guide](https://docs.stripe.com/payments/quickstart?lang=node)
148-
1. Grab `clientSecret` from the payment intent
149-
1. Pass it to `elements-options`
152+
- [All](examples/)
153+
- [Payment](examples/PaymentElementDeferred.vue)
154+
- [Card](examples/CardElement.vue)
155+
- [Express Checkout](examples/ExpressCheckoutElement.vue)
156+
157+
#### Screenshot
158+
159+
![Vue Stripe.js demo screenshot](examples/demo/demo_screenshort.png)
160+
161+
## Advanced integration 🏗️
162+
163+
All features of Stripe.js are available in two components. The benefits of Vue solution: element is created and destroyed automatically, options are reactive, event listeners are attached to StripeElement. Simple and future-proof.
164+
165+
🥇 **Most important property is type** 🥇
150166

151167
```vue
152-
<template>
153-
<StripeElements
154-
...
155-
:elements-options="elementsOptions"
156-
>
157-
<StripeElement
158-
type="payment"
159-
...
160-
/>
161-
</StripeElements>
162-
<template />
168+
<StripeElements>
169+
<StripeElement type="payment" />
170+
</StripeElements>
163171
```
164172

173+
Available types
165174
```ts
166-
const elementsOptions = ref({
167-
clientSecret: "grab_it_from_payment_intent",
168-
// https://stripe.com/docs/js/elements_object/create#stripe_elements-options
169-
})
175+
type StripeElementType =
176+
| 'address'
177+
| 'affirmMessage'
178+
| 'afterpayClearpayMessage'
179+
| 'auBankAccount'
180+
| 'card'
181+
| 'cardNumber'
182+
| 'cardExpiry'
183+
| 'cardCvc'
184+
| 'currencySelector'
185+
| 'epsBank'
186+
| 'expressCheckout'
187+
| 'fpxBank'
188+
| 'iban'
189+
| 'idealBank'
190+
| 'p24Bank'
191+
| 'payment'
192+
| 'paymentMethodMessaging'
193+
| 'paymentRequestButton'
194+
| 'linkAuthentication'
195+
| 'shippingAddress'
196+
| 'issuingCardNumberDisplay'
197+
| 'issuingCardCvcDisplay'
198+
| 'issuingCardExpiryDisplay'
199+
| 'issuingCardPinDisplay'
200+
| 'issuingCardCopyButton'
201+
202+
// Check actual element types in @stripe/stripe-js
170203
```
171204

172-
#### It works!
173-
174-
<img width="840" alt="image" src="https://github.com/user-attachments/assets/0619f7b5-a70f-48a1-84c4-c75bf9fc6ded" />
175-
176205
## Events
177206

178207
```vue
@@ -186,9 +215,31 @@ Following events are emitted on StripeElement
186215
- blur
187216
- click
188217
- escape
189-
-
218+
- loaderror
219+
- loaderstart
220+
221+
222+
## Styling
223+
224+
Apply classes to components
190225

191-
## Style elements
226+
```vue
227+
<StripeElements class="border">
228+
<StripeElement class="p-4" type="card" :options="cardOptions" />
229+
</StripeElements>
230+
```
192231

193-
No base style included. Main reason: overriding it isn't fun. Style as you wish
194-
via element options: [see details](https://stripe.com/docs/js/appendix/style).
232+
Style element via options - [read documentation](https://stripe.com/docs/js/appendix/style)
233+
234+
```ts
235+
const cardOptions = ref<StripeCardElementOptions>({
236+
style: {
237+
base: {
238+
iconColor: "green",
239+
},
240+
invalid: {
241+
iconColor: "red",
242+
},
243+
},
244+
})
245+
```

examples/demo/demo_screenshort.png

66.3 KB
Loading

0 commit comments

Comments
 (0)