Skip to content

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

}
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)
  }
}

@softbeehive softbeehive merged commit bb59f50 into main Jan 13, 2025
1 check passed
@softbeehive softbeehive deleted the feat/use-provide-inject branch January 13, 2025 08:59
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