New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@power-elements/stripe-elements

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@power-elements/stripe-elements

Web Component wrapper for stripe elements

  • 2.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
454
decreased by-20.49%
Maintainers
1
Weekly downloads
 
Created
Source

Stripe Elements Web Components

Custom element wrappers for Stripe.js v3 Elements.

made with open-wc Published on webcomponents.org Published on npm Maintainability Test Coverage Release Contact me on Codementor

👨‍🎨 Live Demo 👀

🚚 Installation

You should make sure to load stripe.js on your app's index.html, as per Stripe's recommendation, before loading <stripe-elements>. If window.Stripe is not available when you load up the component, it will fail with a reasonably-polite console warning.

<script src="https://js.stripe.com/v3/"></script>
npm i -S @power-elements/stripe-elements

To pre-build, use Snowpack to build the modules to your app's web_modules directory. See below for usage examples.

npx snowpack

<stripe-elements> is a community project.


Elements

stripe-elements

Stripe.js v3 Card Elements, but it's a Web Component! Supports Shadow DOM.

👨‍🎨 Live Demo 👀

🧙‍♂️ Usage

If you prebuilt with Snowpack, load the module from your web_modules directory

<script type="module" src="/web_modules/@power-elements/stripe-elements/stripe-elements.js"></script>

Alternatively, load the module from the unpkg CDN

<script type="module" src="https://unpkg.com/@power-elements/stripe-elements/stripe-elements.js?module"></script>

Then you can add the element to your page.

<script type="module" src="https://unpkg.com/@power-elements/stripe-elements/stripe-elements.js?module"></script>
<stripe-elements id="stripe"
     action="/payment"
     publishable-key="pk_test_XXXXXXXXXXXXXXXXXXXXXXXX"
></stripe-elements>

See the demos for more comprehensive examples.

Styling

Stripe v3's 'Stripe Elements' are not custom elements, but rather forms hosted by stripe and injected into your page via an iFrame. When we refer to the 'Stripe Element' in this document, we are referring to the hosted Stripe form, not the <stripe-element> custom element. But when I mention the 'element', I mean the custom element.

When you apply CSS to the custom properties available, they're parsed and sent to Stripe, who should apply them to the Stripe Element they return in the iFrame.

  • base styles are inherited by all other variants.
  • complete styles are applied when the Stripe Element has valid input.
  • empty styles are applied when the Stripe Element has no user input.
  • invalid styles are applied when the Stripe Element has invalid input.

There are 11 properties for each state that you can set which will be read into the Stripe Element iFrame:

  • color
  • font-family
  • font-size
  • font-smoothing
  • font-variant
  • icon-color
  • line-height
  • letter-spacing
  • text-decoration
  • text-shadow
  • text-transform

Mixins: LitNotify, ReadOnlyPropertiesMixin

Properties
PropertyAttributeModifiersTypeDefaultDescription
actionactionStringThe URL to the form action. Example '/charges'.
If blank or undefined will not submit charges immediately.
billingDetailsstripe.BillingDetails
brandbrandreadonlyStringnullThe card brand detected by Stripe
cardcardreadonlystripe.ElementnullThe Stripe card object.
elementelementreadonlystripe.elements.ElementnullStripe element instance
elementselementsreadonlystripe.elements.ElementsnullStripe Elements instance
errorerrorreadonlyError|stripe.ErrornullStripe or validation error
hasErrorhas-errorreadonlyBooleanfalseWhether the element has an error
hideIconhide-iconBooleanfalseWhether to hide icons in the Stripe form.
hidePostalCodehide-postal-codeBooleanfalseWhether or not to hide the postal code field.
Useful when you gather shipping info elsewhere.
iconStyleicon-style'solid'|'default'"default"Stripe icon style. 'solid' or 'default'.
isCompleteis-completeBooleanfalseIf the form is complete.
isEmptyis-emptyBooleantrueIf the form is empty.
publishableKeypublishable-keyStringStripe Publishable Key. EG. pk_test_XXXXXXXXXXXXXXXXXXXXXXXX
showErrorshow-errorbooleanfalseWhether to display the error message
sourcesourcereadonlystripe.SourcenullStripe Source
sourceData{ owner: stripe.OwnerData }Data passed to stripe.createSource. (optional)
stripestripereadonlystripe.StripenullStripe instance
stripeMountreadonlyElementStripe Element mount point
stripeReadystripe-readyBooleanfalseIf the stripe element is ready to receive focus.
tokentokenreadonlystripe.TokennullStripe Token
tokenDatastripe.TokenOptionsData passed to stripe.createToken. (optional)
valuevalueObject{}Prefilled values for form. Example {postalCode: '90210'}
Methods
MethodTypeDescription
createSource(sourceData?: { owner: OwnerInfo; } | undefined): Promise<SourceResponse>Submit payment information to generate a source
createToken(tokenData?: TokenData): Promise<TokenResponse>Submit payment information to generate a token
isPotentiallyValid(): BooleanChecks for potential validity. A potentially valid form is one that is not empty, not complete and has no error. A validated form also counts as potentially valid.
reset(): voidResets the Stripe card.
validate(): BooleanChecks if the Stripe form is valid.
Events
EventDescription
brand-changedThe new value of brand
card-changedThe new value of card
error-changedThe new value of error
has-error-changedThe new value of has-error
is-complete-changedThe new value of is-complete
is-empty-changedThe new value of is-empty
payment-intent-changedThe new value of payment-intent
payment-method-changedThe new value of payment-method
publishable-key-changedThe new value of publishable-key
source-changedThe new value of source
stripe-changeStripe Element change event
stripe-errorThe validation error, or the error returned from stripe.com
stripe-payment-intentThe PaymentIntent received from stripe.com
stripe-payment-methodThe PaymentMethod received from stripe.com
stripe-readyStripe has been initialized and mounted
stripe-ready-changedThe new value of stripe-ready
stripe-sourceThe Source received from stripe.com
stripe-tokenThe Token received from stripe.com
token-changedThe new value of token
CSS Custom Properties
PropertyDescription
--stripe-elements-base-colorcolor property for the element in its base state
--stripe-elements-base-font-familyfont-family property for the element in its base state
--stripe-elements-base-font-sizefont-size property for the element in its base state
--stripe-elements-base-font-smoothingfont-smoothing property for the element in its base state
--stripe-elements-base-font-variantfont-variant property for the element in its base state
--stripe-elements-base-icon-coloricon-color property for the element in its base state
--stripe-elements-base-letter-spacingletter-spacing property for the element in its base state
--stripe-elements-base-line-heightline-height property for the element in its base state
--stripe-elements-base-text-decorationtext-decoration property for the element in its base state
--stripe-elements-base-text-shadowtext-shadow property for the element in its base state
--stripe-elements-base-text-transformtext-transform property for the element in its base state
--stripe-elements-complete-colorcolor property for the element in its complete state
--stripe-elements-complete-font-familyfont-family property for the element in its complete state
--stripe-elements-complete-font-sizefont-size property for the element in its complete state
--stripe-elements-complete-font-smoothingfont-smoothing property for the element in its complete state
--stripe-elements-complete-font-variantfont-variant property for the element in its complete state
--stripe-elements-complete-icon-coloricon-color property for the element in its complete state
--stripe-elements-complete-letter-spacingletter-spacing property for the element in its complete state
--stripe-elements-complete-line-heightline-height property for the element in its complete state
--stripe-elements-complete-text-decorationtext-decoration property for the element in its complete state
--stripe-elements-complete-text-shadowtext-shadow property for the element in its complete state
--stripe-elements-complete-text-transformtext-transform property for the element in its complete state
--stripe-elements-empty-colorcolor property for the element in its empty state
--stripe-elements-empty-font-familyfont-family property for the element in its empty state
--stripe-elements-empty-font-sizefont-size property for the element in its empty state
--stripe-elements-empty-font-smoothingfont-smoothing property for the element in its empty state
--stripe-elements-empty-font-variantfont-variant property for the element in its empty state
--stripe-elements-empty-icon-coloricon-color property for the element in its empty state
--stripe-elements-empty-letter-spacingletter-spacing property for the element in its empty state
--stripe-elements-empty-line-heightline-height property for the element in its empty state
--stripe-elements-empty-text-decorationtext-decoration property for the element in its empty state
--stripe-elements-empty-text-shadowtext-shadow property for the element in its empty state
--stripe-elements-empty-text-transformtext-transform property for the element in its empty state
--stripe-elements-invalid-colorcolor property for the element in its invalid state
--stripe-elements-invalid-font-familyfont-family property for the element in its invalid state
--stripe-elements-invalid-font-sizefont-size property for the element in its invalid state
--stripe-elements-invalid-font-smoothingfont-smoothing property for the element in its invalid state
--stripe-elements-invalid-font-variantfont-variant property for the element in its invalid state
--stripe-elements-invalid-icon-coloricon-color property for the element in its invalid state
--stripe-elements-invalid-letter-spacingletter-spacing property for the element in its invalid state
--stripe-elements-invalid-line-heightline-height property for the element in its invalid state
--stripe-elements-invalid-text-decorationtext-decoration property for the element in its invalid state
--stripe-elements-invalid-text-shadowtext-shadow property for the element in its invalid state
--stripe-elements-invalid-text-transformtext-transform property for the element in its invalid state

Keywords

FAQs

Package last updated on 19 Jan 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc