Skip to content

Commit 51725be

Browse files
authored
Add payment example (#34)
* refactor: remove eslint and prettier * refactor: use deno as new formatter * docs(readme): add payment element example * chore: prepare for 1.0.4
1 parent a6064de commit 51725be

File tree

7 files changed

+85
-715
lines changed

7 files changed

+85
-715
lines changed

.eslintrc.js

Lines changed: 0 additions & 23 deletions
This file was deleted.

.prettierrc.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

README.md

Lines changed: 55 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,43 @@
22

33
# Vue Stripe.js
44

5-
Flexible and powerful Vue 3 components for Stripe. It's a glue between [Stripe.js](https://stripe.com/docs/js) and Vue component lifecycle.
5+
Flexible and powerful Vue 3 components for Stripe. It's a glue between
6+
[Stripe.js](https://stripe.com/docs/js) and Vue component lifecycle.
67

78
# Quickstart
89

910
### 1. Install
1011

1112
**npm**
13+
1214
```bash
1315
npm i vue-stripe-js @stripe/stripe-js
1416
```
1517

1618
**yarn**
19+
1720
```bash
1821
yarn add vue-stripe-js @stripe/stripe-js
1922
```
2023

2124
**pnpm**
25+
2226
```bash
2327
pnpm add vue-stripe-js @stripe/stripe-js
2428
```
2529

2630
### 2. Load Stripe.js
2731

2832
```ts
29-
import { loadStripe } from '@stripe/stripe-js'
30-
import { defineComponent, ref, onBeforeMount } from 'vue'
33+
import { loadStripe } from "@stripe/stripe-js"
34+
import { defineComponent, onBeforeMount, ref } from "vue"
3135

3236
export default defineComponent({
3337
// ...
3438
setup() {
3539
onBeforeMount(() => {
3640
const stripeLoaded = ref(false)
37-
const stripePromise = loadStripe('your_key')
41+
const stripePromise = loadStripe("your_key")
3842
stripePromise.then(() => {
3943
stripeLoaded.value = true
4044
})
@@ -43,15 +47,14 @@ export default defineComponent({
4347
})
4448
```
4549

46-
> Alternatively, you can load Stripe library by including script tag. Just make sure it's ready before your stripe components mount.
50+
> Alternatively, you can load Stripe library by including script tag. Just make
51+
> sure it's ready before your stripe components mount.
4752
4853
```
4954
<script src="https://js.stripe.com/v3/"></script>
5055
```
5156

52-
### 3. Use built-in components
53-
54-
Create card
57+
### 3. Card payment (default)
5558

5659
```vue
5760
<template>
@@ -136,9 +139,39 @@ export default defineComponent({
136139
</script>
137140
```
138141

139-
### 4. Use multiple components
142+
### 4. Payment element (requires backend)
143+
144+
1. Add server code by following
145+
[stripe guide](https://docs.stripe.com/payments/quickstart?lang=node)
146+
1. Grab `clientSecret` from the payment intent
147+
1. Pass it to `elements-options`
148+
149+
```vue
150+
<template>
151+
<StripeElements
152+
...
153+
:elements-options="elementsOptions"
154+
>
155+
<StripeElement
156+
type="payment"
157+
...
158+
/>
159+
</StripeElements>
160+
<template />
161+
```
162+
163+
```ts
164+
const elementsOptions = ref({
165+
clientSecret: "grab_it_from_payment_intent",
166+
// https://stripe.com/docs/js/elements_object/create#stripe_elements-options
167+
})
168+
```
169+
170+
#### It works!
171+
172+
<img width="840" alt="image" src="https://github.com/user-attachments/assets/0619f7b5-a70f-48a1-84c4-c75bf9fc6ded" />
140173

141-
Create multiple elements
174+
### 5. Use elements like lego
142175

143176
```vue
144177
<StripeElements
@@ -160,29 +193,6 @@ Create multiple elements
160193
</StripeElements>
161194
```
162195

163-
### 5. Be super flexible
164-
165-
You can even create multiple groups.
166-
167-
```vue
168-
<StripeElements
169-
v-slot="{ elements }"
170-
:stripe-key="stripeKey1"
171-
:instance-options="instanceOptions1"
172-
:elements-options="elementsOptions1"
173-
>
174-
<StripeElement :elements="elements" :options="cardOptions" />
175-
</StripeElements>
176-
<StripeElements
177-
v-slot="{ elements }"
178-
:stripe-key="stripeKey2"
179-
:instance-options="instanceOptions2"
180-
:elements-options="elementsOptions2"
181-
>
182-
<StripeElement type="iban" :elements="elements" :options="ibanOptions" />
183-
</StripeElements>
184-
```
185-
186196
# Types
187197

188198
```ts
@@ -199,10 +209,11 @@ import types {
199209

200210
## StripeElements.vue
201211

202-
Think of it as of individual group of elements. It creates stripe instance and elements object.
212+
Think of it as of individual group of elements. It creates stripe instance and
213+
elements object.
203214

204215
```js
205-
import { StripeElements } from 'vue-stripe-js'
216+
import { StripeElements } from "vue-stripe-js"
206217
```
207218

208219
### props
@@ -227,7 +238,8 @@ elementsOptions: {
227238

228239
### data
229240

230-
You can access `instance` and `elements` by adding ref to StripeElements component.
241+
You can access `instance` and `elements` by adding ref to StripeElements
242+
component.
231243

232244
```js
233245
// StripeElements.vue exposes
@@ -240,7 +252,8 @@ You can access `instance` and `elements` by adding ref to StripeElements compone
240252

241253
### default scoped slot
242254

243-
Elegant solution for props. Really handy because you can make stripe `instance` and `elements` objects available to all children without adding extra code.
255+
Elegant solution for props. Really handy because you can make stripe `instance`
256+
and `elements` objects available to all children without adding extra code.
244257

245258
```vue
246259
<!-- Cool, isn't it? -->
@@ -255,7 +268,7 @@ Elegant solution for props. Really handy because you can make stripe `instance`
255268
Universal and type agnostic component. Create any element supported by Stripe.
256269

257270
```js
258-
import { StripeElement } from 'vue-stripe-js'
271+
import { StripeElement } from "vue-stripe-js"
259272
```
260273

261274
### props
@@ -295,7 +308,8 @@ import { StripeElement } from 'vue-stripe-js'
295308

296309
### options
297310

298-
Element options are reactive. Recommendation: don't use v-model on `StripeElement`, instead pass value via options.
311+
Element options are reactive. Recommendation: don't use v-model on
312+
`StripeElement`, instead pass value via options.
299313

300314
```js
301315
setup() {
@@ -328,4 +342,5 @@ Following events are emitted on StripeElement
328342

329343
# Styles
330344

331-
No base style included. Main reason: overriding it isn't fun. Style as you wish via element options: [see details](https://stripe.com/docs/js/appendix/style).
345+
No base style included. Main reason: overriding it isn't fun. Style as you wish
346+
via element options: [see details](https://stripe.com/docs/js/appendix/style).

deno.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"fmt": {
3+
"lineWidth": 80,
4+
"indentWidth": 2,
5+
"semiColons": false
6+
}
7+
}
8+

package.json

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-stripe-js",
3-
"version": "1.0.3",
3+
"version": "1.0.4",
44
"description": "Vue 3 components for Stripe.js: Elements & Checkout",
55
"main": "./dist/vue-stripe.umd.js",
66
"module": "./dist/vue-stripe.es.js",
@@ -12,10 +12,7 @@
1212
}
1313
},
1414
"types": "./types/vue-stripe.d.ts",
15-
"files": [
16-
"dist",
17-
"types"
18-
],
15+
"files": ["dist", "types"],
1916
"repository": {
2017
"type": "git",
2118
"url": "git+https://github.com/ectoflow/vue-stripe-js.git"
@@ -46,18 +43,11 @@
4643
"@stripe/stripe-js": "^1.21.1",
4744
"@types/node": "^17.0.33",
4845
"@types/stripe": "^8.0.417",
49-
"@typescript-eslint/eslint-plugin": "^5.3.1",
50-
"@typescript-eslint/parser": "^5.3.1",
5146
"@vitejs/plugin-vue": "^2.3.3",
5247
"@vue/compiler-sfc": "^3.0.5",
5348
"@vuedx/typecheck": "^0.7.4",
5449
"@vuedx/typescript-plugin-vue": "^0.7.4",
55-
"eslint": "^8.2.0",
56-
"eslint-config-prettier": "^8.3.0",
57-
"eslint-plugin-prettier": "^4.0.0",
58-
"eslint-plugin-vue": "^8.0.3",
5950
"jest": "^27.3.1",
60-
"prettier": "^2.3.0",
6151
"typescript": "^4.1.3",
6252
"vite": "^2.6.14",
6353
"vue": "^3.2.21"

vue-stripe-js.code-workspace

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@
55
}
66
],
77
"settings": {
8-
// Vue
9-
"editor.defaultFormatter": "esbenp.prettier-vscode",
8+
"editor.defaultFormatter": "denoland.vscode-deno",
109
"editor.formatOnSave": true,
1110
"editor.formatOnPaste": false,
12-
"editor.codeActionsOnSave": {
13-
"source.fixAll.eslint": true
14-
},
15-
"eslint.alwaysShowStatus": true,
16-
"eslint.validate": ["javascript", "javascriptreact", "typescript", "vue"]
11+
"editor.rulers": [
12+
80
13+
],
14+
"editor.wordWrap": "on",
1715
}
1816
}

0 commit comments

Comments
 (0)