Skip to content

Commit 104bfe4

Browse files
chore: wip
1 parent c8fccfb commit 104bfe4

File tree

3 files changed

+77
-6
lines changed

3 files changed

+77
-6
lines changed

storage/framework/core/components/stripe/components.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ declare module 'vue' {
99
export interface GlobalComponents {
1010
Checkout: typeof import('./src/components/Checkout.vue')['default']
1111
OneTimePayment: typeof import('./src/components/OneTimePayment.vue')['default']
12+
PaymentSection: typeof import('./src/components/PaymentSection.vue')['default']
1213
RouterLink: typeof import('vue-router')['RouterLink']
1314
RouterView: typeof import('vue-router')['RouterView']
1415
Starport: typeof import('vue-starport')['Starport']

storage/framework/core/components/stripe/src/components/Subscription.vue

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,7 @@ async function loadElements() {
7272
7373
async function handleSubmit() {
7474
if (stripe && elements) {
75-
const { error } = await stripe.confirmPayment({
76-
elements,
77-
confirmParams: {
78-
return_url: props.redirectUrl, // Redirect URL after payment
79-
},
80-
})
75+
const { error } = await stripe.confirmPayment({ elements, redirect: 'if_required' })
8176
}
8277
}
8378
</script>
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import type { UserModel } from '../../../../orm/src/models/User'
2+
import { stripe } from '..'
3+
4+
export const paymentIntent: any = (() => {
5+
function stripeId(user: any): string {
6+
return user.stripe_id
7+
}
8+
9+
function hasStripeId(user: any): boolean {
10+
return user.stripe_id !== null || user.stripe_id !== undefined
11+
}
12+
13+
function createStripeCustomer(user: any, options: any = {}): Promise<any> {
14+
if (hasStripeId(user)) {
15+
throw new Error('Customer already created')
16+
}
17+
18+
if (!options.name && user.stripeName) {
19+
options.name = stripeName(user)
20+
}
21+
22+
if (!options.email && user.stripeEmail) {
23+
options.email = stripeEmail(user)
24+
}
25+
26+
if (!options.phone && user.stripePhone) {
27+
options.phone = stripePhone(user)
28+
}
29+
30+
if (!options.address && user.stripeAddress) {
31+
options.address = stripeAddress(user)
32+
}
33+
34+
if (!options.preferred_locales && user.stripePreferredLocales) {
35+
options.preferred_locales = stripePreferredLocales(user)
36+
}
37+
38+
if (!options.metadata && user.stripeMetadata) {
39+
options.metadata = stripeMetadata(user)
40+
}
41+
42+
// Here we will create the customer instance on Stripe and store the ID of the
43+
// user from Stripe. This ID will correspond with the Stripe user instances
44+
// and allow us to retrieve users from Stripe later when we need to work.
45+
return stripe.customer.create(options).then((customer: any) => {
46+
return user.update({ stripe_id: customer.id })
47+
})
48+
}
49+
50+
function stripeName(user: any): string {
51+
return user.name || ''
52+
}
53+
54+
function stripeEmail(user: any): string {
55+
return user.email || ''
56+
}
57+
58+
function stripePhone(user: any): string {
59+
return user.phone || ''
60+
}
61+
62+
function stripeAddress(user: any): string {
63+
return user.address || null
64+
}
65+
66+
function stripePreferredLocales(user: any): string {
67+
return user.preferred_locales || []
68+
}
69+
70+
function stripeMetadata(user: any): string {
71+
return user.metadata || {}
72+
}
73+
74+
return { stripeId, hasStripeId, createStripeCustomer }
75+
})()

0 commit comments

Comments
 (0)