Skip to content
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
7976247
refactor: delete deno config - incompatible with vue sfc
softbeehive Jan 4, 2025
3098b39
refactor: remove vintage technology
softbeehive Jan 4, 2025
6285b94
refactor: upgrade vite
softbeehive Jan 4, 2025
efb5698
docs(license): use date range
softbeehive Jan 4, 2025
6a5a920
fix(formatting): use biome
softbeehive Jan 6, 2025
bbadbf1
refactor: use vite, clean up dev dependencies
softbeehive Jan 6, 2025
70feade
refactor: update vscode workspace
softbeehive Jan 6, 2025
27ae134
feat: add examples for Payment, Express Checkout, and Card
softbeehive Jan 6, 2025
c72d701
feat: implement provide/inject using composition api
softbeehive Jan 6, 2025
bd3d838
refactor: update github workflow for CI
softbeehive Jan 6, 2025
12bf741
chore: bump package version
softbeehive Jan 6, 2025
7b615a4
fix: use pnpm in github workflow
softbeehive Jan 6, 2025
8d0a933
refactor: import missing element types
softbeehive Jan 6, 2025
e59a4bc
feat: complete payment example for deferred flow
softbeehive Jan 6, 2025
aca033f
refactor: use tailwind to style examples
softbeehive Jan 7, 2025
e1620ce
chore(CardElementLegacy): this tests old integrations without type work
softbeehive Jan 10, 2025
f270a3f
chore: update dev dependencies
softbeehive Jan 10, 2025
6bb2bf7
refactor(tsconfig): sort json keys
softbeehive Jan 10, 2025
c9d05db
fix: typescript issues, forward element events to component
softbeehive Jan 10, 2025
b05d833
fix: typescript issues in examples
softbeehive Jan 10, 2025
0dfb0e8
refactor: update demo title
softbeehive Jan 10, 2025
58a34eb
fix: install stripe-js as dependency
softbeehive Jan 10, 2025
788d356
fix: resolve overload issues
softbeehive Jan 10, 2025
00d9e9a
refactor(examples): make code more readable
softbeehive Jan 10, 2025
834e3ea
refactor: use await in Card example
softbeehive Jan 11, 2025
30b3d83
docs: add readme for how to run demo
softbeehive Jan 11, 2025
15cd6ec
docs: update readme part 1
softbeehive Jan 11, 2025
4c3d823
refactor(examples): use correct links for options
softbeehive Jan 12, 2025
f6fd546
docs: add new quickstart, examples and more
softbeehive Jan 12, 2025
5d6f728
docs: set html syntax in some sections
softbeehive Jan 12, 2025
ea57f32
docs: add links to upgrade guide and older documentation
softbeehive Jan 12, 2025
c686bdc
docs: create upgrade guide
softbeehive Jan 12, 2025
2063017
refactor: improve examples readme
softbeehive Jan 12, 2025
4aac429
docs(readme): fix typo
softbeehive Jan 12, 2025
70d6712
docs: proofread upgrade guide
softbeehive Jan 12, 2025
8385628
docs(readme): update example for vue v3.2 - v3.4
softbeehive Jan 13, 2025
88d57df
refactor(examples): add important comment about vue 3.5
softbeehive Jan 13, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 22 additions & 20 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
name: Vue Stripe.js CI

on: [push, pull_request]
on:
pull_request:
push:
branches:
- main

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
ci:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [16.x]

steps:
- uses: actions/checkout@v2

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
- uses: actions/checkout@v4
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
node-version: ${{ matrix.node-version }}
version: 9

- name: Cache NPM
uses: actions/cache@v2
- name: Use Node.js
uses: actions/setup-node@v4
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-node-
node-version: 20
cache: 'pnpm'

- name: Install dependencies
run: yarn
run: pnpm install

- name: Unit Tests
run: yarn test
- name: Run CI
run: pnpm run ci
22 changes: 21 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
.DS_Store
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["Vue.volar"]
}
25 changes: 12 additions & 13 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
MIT License

Copyright (c) 2021 Oleksandr Bystrikov
Copyright (c) 2021 - present, Oleksandr Bystrikov

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
7 changes: 0 additions & 7 deletions babel.config.js

This file was deleted.

39 changes: 39 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
"vcs": {
"enabled": false,
"clientKind": "git",
"useIgnoreFile": false
},
"files": {
"ignoreUnknown": false,
"ignore": ["dist"]
},
"formatter": {
"enabled": true,
"indentStyle": "space",
"indentWidth": 2,
"lineWidth": 80
},
"organizeImports": {
"enabled": true
},
"linter": {
"enabled": true,
"rules": {
"recommended": true
}
},
"javascript": {
"formatter": {
"jsxQuoteStyle": "double",
"quoteProperties": "asNeeded",
"semicolons": "asNeeded",
"arrowParentheses": "always",
"bracketSpacing": true,
"bracketSameLine": false,
"quoteStyle": "double",
"attributePosition": "multiline"
}
}
}
8 changes: 0 additions & 8 deletions deno.json

This file was deleted.

85 changes: 85 additions & 0 deletions examples/CardElement.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<template>
<form @submit.prevent="handlePay">
<StripeElements
v-if="stripeLoaded"
class="py-3"
:stripe-key="publishableKey"
:instance-options="instanceOptions"
:elements-options="elementsOptions"
ref="elementsComponent"
>
<StripeElement
type="card"
:options="cardOptions"
ref="cardComponent"
/>
</StripeElements>
<button
class="w-full rounded-b bg-slate-600 px-3 py-2 text-sm font-semibold text-white hover:bg-slate-500"
>
Pay now
</button>
</form>
</template>

<script setup lang="ts">
import { loadStripe } from "@stripe/stripe-js"
import type {
StripeCardElement,
StripeCardElementOptions,
StripeConstructorOptions,
StripeElementsOptions,
} from "@stripe/stripe-js"
import { onBeforeMount, ref, useTemplateRef } from "vue"
import StripeElement from "../src/components/StripeElement.vue"
import StripeElements from "../src/components/StripeElements.vue"

const publishableKey = ref("pk_test_TYooMQauvdEDq54NiTphI7jx") // test key
const instanceOptions = ref<StripeConstructorOptions>({
// https://stripe.com/docs/js/initializing#init_stripe_js-options
})
const elementsOptions = ref<StripeElementsOptions>({
// https://stripe.com/docs/js/elements_object/create#stripe_elements-options
})
const cardOptions = ref<StripeCardElementOptions>({
style: {
base: {},
invalid: {},
},
// https://stripe.com/docs/stripe.js#element-options
})
const stripeLoaded = ref(false)

const elementsComponent = useTemplateRef("elementsComponent")
const cardComponent = useTemplateRef("cardComponent")

onBeforeMount(() => {
loadStripe(publishableKey.value).then(() => {
stripeLoaded.value = true
})
})

function handlePay() {
// You need to implement backend for creating PaymentIntent
// Learn more by reading https://docs.stripe.com/payments/card-element?lang=node
const stripeInstance = elementsComponent.value?.instance
const card = cardComponent.value?.stripeElement as StripeCardElement

// Let's skip to the point you got clientSecret
const clientSecret = "i_was_created_on_server"

stripeInstance
?.confirmCardPayment(clientSecret, {
payment_method: {
card,
},
})
.then((payload) => {
if (payload.error) {
console.error(payload.error)
} else {
console.log("Great success!")
}
})
}
</script>
39 changes: 28 additions & 11 deletions examples/CardOnly.vue → examples/CardElementLegacy.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,43 @@
<StripeElements
v-if="stripeLoaded"
v-slot="{ elements }"
ref="elms"
:stripe-key="stripeKey"
:instance-options="instanceOptions"
:elements-options="elementsOptions"
ref="elms"
class="py-3"
>
<StripeElement ref="card" :elements="elements" :options="cardOptions" />
<StripeElement
:elements="elements"
:options="cardOptions"
ref="card"
/>
</StripeElements>
<button type="button" @click="pay">Pay</button>
<button
type="button"
@click="pay"
class="w-full rounded-b bg-slate-600 px-3 py-2 text-sm font-semibold text-white hover:bg-slate-500"
>
Pay now
</button>
</template>

<script lang="ts">
import { defineComponent, ref, onBeforeMount } from 'vue'
import { loadStripe } from '@stripe/stripe-js'
import StripeElements from '../src/components/StripeElements.vue'
import StripeElement from '../src/components/StripeElement.vue'
import { loadStripe } from "@stripe/stripe-js"
import { defineComponent, onBeforeMount, ref } from "vue"
import StripeElement from "../src/components/StripeElement.vue"
import StripeElements from "../src/components/StripeElements.vue"

export default defineComponent({
name: 'CardOnly',
name: "CardElement",

components: {
StripeElements,
StripeElement,
},

setup() {
const stripeKey = ref('pk_test_TYooMQauvdEDq54NiTphI7jx') // test key
const stripeKey = ref("pk_test_TYooMQauvdEDq54NiTphI7jx") // test key
const instanceOptions = ref({
// https://stripe.com/docs/js/initializing#init_stripe_js-options
})
Expand All @@ -37,7 +48,7 @@ export default defineComponent({
const cardOptions = ref({
// https://stripe.com/docs/stripe.js#element-options
value: {
postalCode: '12345',
postalCode: "12345",
},
})
const stripeLoaded = ref(false)
Expand All @@ -64,10 +75,16 @@ export default defineComponent({

methods: {
pay() {
/*
WARNING:
legacy way to implement card payments,
for modern card example, see CardElement.vue
*/

// Get stripe element
const cardElement = this.card.stripeElement

// Access instance methods, e.g. createToken()
// "instance" means Stripe Instance or Stripe object
this.elms.instance.createToken(cardElement).then((result: object) => {
// Handle result.error or result.token
console.log(result)
Expand Down
51 changes: 51 additions & 0 deletions examples/DemoApp.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<template>
<div class="flex flex-col gap-y-12 container px-6 py-10 max-w-xl">
<h1 class="text-3xl font-semibold">Demo Vue Stripe.js</h1>

<section>
<h2 class="text-2xl font-semibold">Payment Element</h2>
<p class="pt-1 pb-6">Deferred flow -
<a
class="text-blue-700 hover:underline"
href="https://docs.stripe.com/payments/accept-a-payment-deferred?type=payment"
>read stripe guide</a>
</p>
<PaymentElementDeferred />
</section>

<section>
<h2 class="text-2xl font-semibold">Card Element</h2>
<p class="pt-1 pb-4">More recent example. Stripe recommends using Payment Element instead of the Card -
<a
class="text-blue-700 hover:underline"
href="https://docs.stripe.com/payments/card-element?lang=node"
>read stripe guide</a>
</p>
<CardElement />
</section>

<section>
<h2 class="text-2xl font-semibold">Card Element (Legacy)</h2>
<p class="pt-1 pb-4">How we implemented card payments a few years ago.</p>
<CardElementLegacy />
</section>

<section>
<h2 class="text-2xl font-semibold">Express Checkout Element</h2>
<p class="pt-1 pb-4">Use your publishable key and enable relevant payment methods, e.g. PayPal -
<a
class="text-blue-700 hover:underline"
href="https://docs.stripe.com/elements/express-checkout-element/accept-a-payment?lang=node"
>read stripe guide</a>
</p>
<ExpressCheckoutElement />
</section>
</div>
</template>

<script setup lang="ts">
import CardElement from "./CardElement.vue"
import CardElementLegacy from "./CardElementLegacy.vue"
import ExpressCheckoutElement from "./ExpressCheckoutElement.vue"
import PaymentElementDeferred from "./PaymentElementDeferred.vue"
</script>
Loading
Loading