-
Notifications
You must be signed in to change notification settings - Fork 382
feat(vue): Add Billing buttons #6680
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
62c50de
feat(vue,astro): Add Billing buttons
panteliselef 1563197
add tests
panteliselef 86b0d3b
mark as experimental
panteliselef faa409c
add changeset
panteliselef 5224ca1
skip astro tests
panteliselef 070e816
add experimental tags
panteliselef 183001f
fix lint
panteliselef 2fdb49b
rename the test
panteliselef 7264ec5
Merge branch 'refs/heads/main' into elef/com-1112-ga-billing-buttons-…
panteliselef 64ef49a
remove astro
panteliselef 7e21cd1
Merge branch 'main' into elef/com-1112-vue-only
panteliselef File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@clerk/vue': minor | ||
--- | ||
|
||
Expose billing buttons as experimental |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
integration/templates/vue-vite/src/views/billing/CheckoutBtn.vue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<template> | ||
<main> | ||
<SignedIn> | ||
<CheckoutButton | ||
planId="cplan_2wMjqdlza0hTJc4HLCoBwAiExhF" | ||
planPeriod="month" | ||
> | ||
Checkout Now | ||
</CheckoutButton> | ||
</SignedIn> | ||
</main> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { SignedIn } from '@clerk/vue'; | ||
import { CheckoutButton } from '@clerk/vue/experimental'; | ||
</script> |
9 changes: 9 additions & 0 deletions
9
integration/templates/vue-vite/src/views/billing/PlanDetailsBtn.vue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<template> | ||
<main> | ||
<PlanDetailsButton planId="cplan_2wMjqdlza0hTJc4HLCoBwAiExhF"> Plan details </PlanDetailsButton> | ||
</main> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { PlanDetailsButton } from '@clerk/vue/experimental'; | ||
</script> |
9 changes: 9 additions & 0 deletions
9
integration/templates/vue-vite/src/views/billing/SubscriptionDetailsBtn.vue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<template> | ||
<main> | ||
<SubscriptionDetailsButton> Subscription details </SubscriptionDetailsButton> | ||
</main> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { SubscriptionDetailsButton } from '@clerk/vue/experimental'; | ||
</script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<script setup lang="ts"> | ||
import { useAttrs, useSlots } from 'vue'; | ||
import type { __experimental_CheckoutButtonProps } from '@clerk/types'; | ||
import { useClerk } from '../composables/useClerk'; | ||
import { useAuth } from '../composables/useAuth'; | ||
import { assertSingleChild, normalizeWithDefaultValue } from '../utils'; | ||
|
||
const props = defineProps<__experimental_CheckoutButtonProps>(); | ||
|
||
const clerk = useClerk(); | ||
const { userId, orgId } = useAuth(); | ||
const slots = useSlots(); | ||
const attrs = useAttrs(); | ||
|
||
// Authentication checks - similar to React implementation | ||
if (userId.value === null) { | ||
throw new Error('Ensure that `<CheckoutButton />` is rendered inside a `<SignedIn />` component.'); | ||
} | ||
|
||
if (orgId.value === null && props.for === 'organization') { | ||
throw new Error('Wrap `<CheckoutButton for="organization" />` with a check for an active organization.'); | ||
} | ||
|
||
function getChildComponent() { | ||
const children = normalizeWithDefaultValue(slots.default?.({}), 'Checkout'); | ||
return assertSingleChild(children, 'CheckoutButton'); | ||
} | ||
wobsoriano marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
function clickHandler() { | ||
if (!clerk.value) { | ||
return; | ||
} | ||
|
||
return clerk.value.__internal_openCheckout({ | ||
planId: props.planId, | ||
planPeriod: props.planPeriod, | ||
for: props.for, | ||
onSubscriptionComplete: props.onSubscriptionComplete, | ||
newSubscriptionRedirectUrl: props.newSubscriptionRedirectUrl, | ||
...props.checkoutProps, | ||
}); | ||
} | ||
</script> | ||
|
||
<template> | ||
<component | ||
:is="getChildComponent" | ||
v-bind="attrs" | ||
@click="clickHandler" | ||
> | ||
<slot /> | ||
</component> | ||
wobsoriano marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</template> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<script setup lang="ts"> | ||
import { useAttrs, useSlots } from 'vue'; | ||
import type { __experimental_PlanDetailsButtonProps } from '@clerk/types'; | ||
import { useClerk } from '../composables/useClerk'; | ||
import { assertSingleChild, normalizeWithDefaultValue } from '../utils'; | ||
|
||
const props = defineProps<__experimental_PlanDetailsButtonProps>(); | ||
|
||
const clerk = useClerk(); | ||
const slots = useSlots(); | ||
const attrs = useAttrs(); | ||
|
||
function getChildComponent() { | ||
const children = normalizeWithDefaultValue(slots.default?.({}), 'Plan details'); | ||
return assertSingleChild(children, 'PlanDetailsButton'); | ||
} | ||
|
||
function clickHandler() { | ||
if (!clerk.value) { | ||
return; | ||
} | ||
|
||
return clerk.value.__internal_openPlanDetails({ | ||
plan: props.plan, | ||
planId: props.planId, | ||
initialPlanPeriod: props.initialPlanPeriod, | ||
...props.planDetailsProps, | ||
} as __experimental_PlanDetailsButtonProps); | ||
} | ||
</script> | ||
|
||
<template> | ||
<component | ||
:is="getChildComponent" | ||
v-bind="attrs" | ||
@click="clickHandler" | ||
> | ||
<slot /> | ||
</component> | ||
wobsoriano marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</template> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<script setup lang="ts"> | ||
import { useAttrs, useSlots } from 'vue'; | ||
import type { __experimental_SubscriptionDetailsButtonProps } from '@clerk/types'; | ||
import { useClerk } from '../composables/useClerk'; | ||
import { useAuth } from '../composables/useAuth'; | ||
import { assertSingleChild, normalizeWithDefaultValue } from '../utils'; | ||
|
||
const props = defineProps<__experimental_SubscriptionDetailsButtonProps>(); | ||
|
||
const clerk = useClerk(); | ||
const { userId, orgId } = useAuth(); | ||
const slots = useSlots(); | ||
const attrs = useAttrs(); | ||
|
||
wobsoriano marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Authentication checks - similar to React implementation | ||
if (userId.value === null) { | ||
throw new Error('Ensure that `<SubscriptionDetailsButton />` is rendered inside a `<SignedIn />` component.'); | ||
} | ||
|
||
if (orgId.value === null && props.for === 'organization') { | ||
throw new Error('Wrap `<SubscriptionDetailsButton for="organization" />` with a check for an active organization.'); | ||
} | ||
|
||
function getChildComponent() { | ||
const children = normalizeWithDefaultValue(slots.default?.({}), 'Subscription details'); | ||
return assertSingleChild(children, 'SubscriptionDetailsButton'); | ||
} | ||
wobsoriano marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
function clickHandler() { | ||
if (!clerk.value) { | ||
return; | ||
} | ||
|
||
return clerk.value.__internal_openSubscriptionDetails({ | ||
for: props.for, | ||
onSubscriptionCancel: props.onSubscriptionCancel, | ||
...props.subscriptionDetailsProps, | ||
}); | ||
} | ||
</script> | ||
|
||
<template> | ||
<component | ||
:is="getChildComponent" | ||
v-bind="attrs" | ||
@click="clickHandler" | ||
> | ||
<slot /> | ||
</component> | ||
</template> | ||
wobsoriano marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* @experimental | ||
* These components and their prop types are unstable and may change in future releases. | ||
* They are part of Clerk's Billing feature which is available under public beta. | ||
*/ | ||
export { default as SubscriptionDetailsButton } from './components/SubscriptionDetailsButton.vue'; | ||
|
||
/** | ||
* @experimental | ||
* These components and their prop types are unstable and may change in future releases. | ||
* They are part of Clerk's Billing feature which is available under public beta. | ||
*/ | ||
export { default as CheckoutButton } from './components/CheckoutButton.vue'; | ||
|
||
/** | ||
* @experimental | ||
* These components and their prop types are unstable and may change in future releases. | ||
* They are part of Clerk's Billing feature which is available under public beta. | ||
*/ | ||
export { default as PlanDetailsButton } from './components/PlanDetailsButton.vue'; | ||
|
||
export type { | ||
/** | ||
* @experimental | ||
* These components and their prop types are unstable and may change in future releases. | ||
* They are part of Clerk's Billing feature which is available under public beta. | ||
*/ | ||
__experimental_SubscriptionDetailsButtonProps as SubscriptionDetailsButtonProps, | ||
/** | ||
* @experimental | ||
* These components and their prop types are unstable and may change in future releases. | ||
* They are part of Clerk's Billing feature which is available under public beta. | ||
*/ | ||
__experimental_CheckoutButtonProps as CheckoutButtonProps, | ||
/** | ||
* @experimental | ||
* These components and their prop types are unstable and may change in future releases. | ||
* They are part of Clerk's Billing feature which is available under public beta. | ||
*/ | ||
__experimental_PlanDetailsButtonProps as PlanDetailsButtonProps, | ||
} from '@clerk/types'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.