Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into sshin/stripe-2
Browse files Browse the repository at this point in the history
  • Loading branch information
suejung-sentry committed Jan 16, 2025
2 parents 969f83f + 162b8ca commit 3f335c5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
25.1.10
25.1.16
17 changes: 15 additions & 2 deletions src/services/account/useCreateStripeSetupIntent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { useQuery } from '@tanstack/react-query'
import { z } from 'zod'

import Api from 'shared/api'
import { NetworkErrorObject, Provider } from 'shared/api/helpers'
import {
NetworkErrorObject,
Provider,
rejectNetworkError,
} from 'shared/api/helpers'

export const CreateStripeSetupIntentSchema = z.object({
createStripeSetupIntent: z.object({
Expand Down Expand Up @@ -70,13 +74,22 @@ export function useCreateStripeSetupIntent({
createStripeSetupIntent({ provider, owner, signal }).then((res) => {
const parsedRes = CreateStripeSetupIntentSchema.safeParse(res.data)
if (!parsedRes.success) {
return Promise.reject({
return rejectNetworkError({
status: 404,
error: parsedRes.error,
data: {},
dev: 'useStripeSetupIntent - 404 failed to parse',
} satisfies NetworkErrorObject)
}

const error = parsedRes.data.createStripeSetupIntent.error
if (error?.__typename) {
return Promise.reject({
error: error.__typename,
message: 'Error creating setup intent',
})
}

return parsedRes.data.createStripeSetupIntent
}),
...opts,
Expand Down
11 changes: 6 additions & 5 deletions src/services/account/useUpdatePaymentMethod.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useElements, useStripe } from '@stripe/react-stripe-js'
import { PaymentElement, useElements, useStripe } from '@stripe/react-stripe-js'
import { useMutation, useQueryClient } from '@tanstack/react-query'

import config from 'config'
Expand All @@ -11,17 +11,20 @@ import { useCreateStripeSetupIntent } from './useCreateStripeSetupIntent'
interface useUpdatePaymentMethodProps {
provider: Provider
owner: string
name?: string
email?: string
}

interface useUpdatePaymentMethodReturn {
reset: () => void
error: null | Error
isLoading: boolean
mutate: (variables: any, data: any) => void
mutate: (
variables: typeof PaymentElement,
data?: { onSuccess?: () => void }
) => void
data: undefined | unknown
}

function getPathAccountDetails({
provider,
owner,
Expand All @@ -35,7 +38,6 @@ function getPathAccountDetails({
export function useUpdatePaymentMethod({
provider,
owner,
name,
email,
}: useUpdatePaymentMethodProps): useUpdatePaymentMethodReturn {
const stripe = useStripe()
Expand All @@ -60,7 +62,6 @@ export function useUpdatePaymentMethod({
payment_method_data: {
// eslint-disable-next-line camelcase
billing_details: {
name: name,
email: email,
},
},
Expand Down

0 comments on commit 3f335c5

Please sign in to comment.