Skip to content
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

Implement provide/inject & use vite v6 #38

Open
wants to merge 37 commits into
base: main
Choose a base branch
from

Conversation

softbeehive
Copy link
Contributor

@softbeehive softbeehive commented Jan 6, 2025

Breaking changes

  • added "type": "module"
  • removed commonjs export
  • new types

Features

Payment Element by default

As Stripe evolves, now Payment is the recommended flow. It used to be Card. To let you upgrade without breaking the code: payment for new starters, card for legacy.

  • For starters
// This means Payment

<StripeElements>
  <StripeElement type="payment" />
</StripeElements>
  • Upgrade to v2.0.0 seamlessly
// This still means Card

<StripeElements v-slot="{ elements, instance }">
  <StripeElement />
</StripeElements>

Better examples

  • Payment
  • Card
  • Express Checkout
  • Legacy Card

Fixes

Added missing event listeners for

  • loaderror
  • loaderstart

Screenshot

image

@@ -62,10 +139,8 @@ export const createElement = (
if (!elementType) {
throw new Error(ERRORS.ELEMENT_TYPE_NOT_DEFINED)
}
const element = elements.create(elementType, options)
return element
return elements.create(elementType, options)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey folks 👋
this is Vue equivalent of react-stripe-js

I'm preparing a new major version but this typescript overload issue has been a blocker. I'm trying to type a generic function that creates Stripe Element using @stripe/stripe-js

Overloads of elements.create() are so specific I'm having hard time.

image
  • tried StripeElementType (union)
  • tried mapping element types and options StripeElementOptionsMap
  • tried generics

I'd like to avoid maintaining such map types, because stripe-js as a better source of truth for these types.

How do you recommend typing functions with such specific overloads?
@pololi-stripe
@bdaily-stripe
@alexlande-stripe

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example using generics, trying to narrow down elementType and options

export type StripeElementOptionsMap = {
  address: StripeAddressElementOptions
  affirmMessage: StripeAffirmMessageElementOptions
  afterpayClearpayMessage: StripeAfterpayClearpayMessageElementOptions
  auBankAccount: StripeAuBankAccountElementOptions
  card: StripeCardElementOptions
  cardCvc: StripeCardCvcElementOptions
  cardExpiry: StripeCardExpiryElementOptions
  ...
}
export const createElement = <T extends keyof StripeElementOptionsMap>(
  elements: StripeElements,
  elementType: T,
  options?: StripeElementOptionsMap[T],
) => {
  try {
    if (!elements) {
      throw new Error(ERRORS.ELEMENTS_NOT_DEFINED)
    }
    if (!elementType) {
      throw new Error(ERRORS.ELEMENT_TYPE_NOT_DEFINED)
    }
    const element = elements.create(elementType, options)
    return element
  } catch (error) {
    console.error(error)
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant