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.3.1
  • Source
  • npm
  • Socket score

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

Stripe Elements Web Components

πŸ›‘βš›οΈπŸ”° Any Framework - One Stripe Integration. πŸ’°πŸ’΅πŸ’Έ

Published on npm Published on webcomponents.org made with open-wc 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.

<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
actionactionstringIf set, when Stripe returns the payment info (PaymentMethod, Source, or Token),
the element will POST JSON data to this URL with an object containing
a key equal to the value of the generate property.
billingDetailsstripe.BillingDetails{}billing_details object sent to create the payment representation. (optional)
brandbrandreadonlystringnullThe card brand detected by Stripe
cardcardreadonlystripe.elements.ElementnullThe Stripe card object.
DEPRECATED. Will be removed in a future version. use element instead
clientSecretclient-secretstringThe client_secret part of a Stripe PaymentIntent
completecompletereadonlybooleanfalseWhether the form is complete.
elementelementreadonlystripe.elements.ElementnullStripe element instance
elementselementsreadonlystripe.elements.ElementsnullStripe Elements instance
emptyemptyreadonlybooleantrueIf the form is empty.
errorerrorreadonlyError|stripe.ErrornullStripe or validation error
focusedfocusedreadonlybooleanfalseIf the element is focused.
generategenerate'payment-method'|'source'|'token'"source"Type of payment representation to generate.
hasErrorhas-errorreadonlybooleanfalseWhether the element has an error
DEPRECATED. Will be removed in a future version. Use error instead
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'.
invalidinvalidreadonlybooleanfalseWhether the form is invalid.
isCompleteis-completebooleanfalseWhether the form is complete.
DEPRECATED. Will be removed in a future version. use complete instead
isEmptyis-emptybooleantrueWhether the form is empty.
DEPRECATED. Will be removed in a future version. use empty instead
paymentMethodpayment-methodreadonlystripe.paymentMethod.PaymentMethodnullStripe PaymentMethod
paymentMethodDatastripe.PaymentMethodData{}Data passed to stripe.createPaymentMethod. (optional)
publishableKeypublishable-keystringStripe Publishable Key. EG. pk_test_XXXXXXXXXXXXXXXXXXXXXXXX
readyreadyreadonlybooleanfalseWhether the stripe element is ready to receive focus.
showErrorshow-errorbooleanfalseWhether to display the error message
sourcesourcereadonlystripe.SourcenullStripe Source
sourceDataSourceData{}Data passed to stripe.createSource. (optional)
stripestripereadonlystripe.StripenullStripe instance
stripeReadystripe-readybooleanfalseWhether the stripe element is ready to receive focus.
DEPRECATED. Will be removed in a future version. use ready instead.
tokentokenreadonlystripe.TokennullStripe Token
tokenDatastripe.TokenOptions{}Data passed to stripe.createToken. (optional)
valuevalueobject{}Prefilled values for form. Example {postalCode: '90210'}
Methods
MethodTypeDescription
blur(): voidBlurs the element.
createPaymentMethod(paymentMethodData?: PaymentMethodData | undefined): Promise<PaymentMethodResponse>Submit payment information to generate a paymentMethod
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
focus(): voidFocuses the element.
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.
submit(): Promise<PaymentMethodResponse | SourceResponse | TokenResponse>Generates a payment representation of the type specified by generate.
validate(): booleanChecks if the Stripe form is valid.
Events
EventDescription
changeStripe Element change event
errorThe validation error, or the error returned from stripe.com
payment-methodThe PaymentMethod received from stripe.com
readyStripe has been initialized and mounted
sourceThe Source received from stripe.com
stripe-errorDEPRECATED. Will be removed in a future major version. Use error instead
stripe-payment-methodDEPRECATED. Will be removed in a future major version. Use payment-method instead
stripe-readyDEPRECATED. Will be removed in a future major version. Use ready instead
stripe-sourceDEPRECATED. Will be removed in a future major version. Use source instead
stripe-tokenDEPRECATED. Will be removed in a future major version. Use token instead
successWhen a payment succeeds
tokenThe Token received from stripe.com
CSS Shadow Parts
PartDescription
errorcontainer for the error message
stripecontainer for the stripe element
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-borderborder property of the element container. Default 1px solid transparent
--stripe-elements-border-radiusborder radius of the element container. Default 4px
--stripe-elements-box-shadowbox shadow for the element container. Default 0 1px 3px 0 #e6ebf1
--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
--stripe-elements-transitiontransition property for the element container. Default box-shadow 150ms ease

stripe-payment-request

Custom element wrapper for Stripe.js v3 Payment Request Buttons.

πŸ‘¨β€πŸŽ¨ 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-payment-request.js"></script>

Alternatively, load the module from the unpkg CDN

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

Then you can add the element to your page.


<stripe-payment-request id="payment-request"
     publishable-key="pk_test_XXXXXXXXXXXXXXXXXXXXXXXX"
     generate="token"
     action="/charges"
     country="CA"
     currency="cad"
     amount="1000"
     label="Ten Bones"
     request-payer-name
     request-payer-email
     request-payer-phone
></stripe-payment-request>

See the demos for more comprehensive examples.

Mixins: ReadOnlyPropertiesMixin, LitNotify

Properties
PropertyAttributeModifiersTypeDefaultDescription
actionactionstringIf set, when Stripe returns the payment info (PaymentMethod, Source, or Token),
the element will POST JSON data to this URL with an object containing
a key equal to the value of the generate property.
amountamountnumberThe amount in the currency's subunit (e.g. cents, yen, etc.)
billingDetailsstripe.BillingDetails{}billing_details object sent to create the payment representation. (optional)
buttonThemebutton-theme'dark'|'light'|'light-outline'"dark"
buttonTypebutton-type'default'|'book'|'buy'|'donate'"default"
canMakePaymentcan-make-paymentreadonlyobject"undefined"Whether or not the device can make the payment request.
clientSecretclient-secretstringThe client_secret part of a Stripe PaymentIntent
countrycountrystringThe two-letter country code of your Stripe account (e.g., US)
currencycurrencystringThree character currency code (e.g., usd)
displayItemsdisplayItemsstripe.paymentRequest.DisplayItem[]An array of DisplayItem objects. These objects are shown as line items in the browser’s payment interface. Note that the sum of the line item amounts does not need to add up to the total amount above.
elementelementreadonlystripe.elements.ElementnullStripe element instance
elementselementsreadonlystripe.elements.ElementsnullStripe Elements instance
errorerrorreadonlyError|stripe.ErrornullStripe or validation error
focusedfocusedreadonlybooleanfalseIf the element is focused.
generategenerate'payment-method'|'source'|'token'"source"Type of payment representation to generate.
hasErrorhas-errorreadonlybooleanfalseWhether the element has an error
DEPRECATED. Will be removed in a future version. Use error instead
labellabelstringA name that the browser shows the customer in the payment interface.
paymentIntentpayment-intentreadonlystripe.paymentIntents.PaymentIntentnullStripe PaymentIntent
paymentMethodpayment-methodreadonlystripe.paymentMethod.PaymentMethodnullStripe PaymentMethod
paymentMethodDatastripe.PaymentMethodData{}Data passed to stripe.createPaymentMethod. (optional)
paymentRequestpayment-requeststripe.paymentRequest.StripePaymentRequestnullStripe PaymentRequest
pendingpendingbooleanfalseIf you might change the payment amount later (for example, after you have calcluated shipping costs), set this to true. Note that browsers treat this as a hint for how to display things, and not necessarily as something that will prevent submission.
publishableKeypublishable-keystringStripe Publishable Key. EG. pk_test_XXXXXXXXXXXXXXXXXXXXXXXX
readyreadyreadonlybooleanfalseWhether the stripe element is ready to receive focus.
requestPayerEmailrequest-payer-emailbooleanSee the requestPayerName option.
requestPayerNamerequest-payer-namebooleanBy default, the browserβ€˜s payment interface only asks the customer for actual payment information. A customer name can be collected by setting this option to true. This collected name will appears in the PaymentResponse object.

We highly recommend you collect at least one of name, email, or phone as this also results in collection of billing address for Apple Pay. The billing address can be used to perform address verification and block fraudulent payments. For all other payment methods, the billing address is automatically collected when available.
requestPayerPhonerequest-payer-phonebooleanSee the requestPayerName option.
requestShippingrequest-shippingbooleanCollect shipping address by setting this option to true. The address appears in the PaymentResponse.
You must also supply a valid [ShippingOptions] to the shippingOptions property. This can be up front at the time stripe.paymentRequest is called, or in response to a shippingaddresschange event using the updateWith callback.
shippingOptionsshippingOptionsstripe.paymentRequest.ShippingOption[]An array of ShippingOption objects. The first shipping option listed appears in the browser payment interface as the default option.
showErrorshow-errorbooleanfalseWhether to display the error message
sourcesourcereadonlystripe.SourcenullStripe Source
sourceDataSourceData{}Data passed to stripe.createSource. (optional)
stripestripereadonlystripe.StripenullStripe instance
stripeReadystripe-readybooleanfalseWhether the stripe element is ready to receive focus.
DEPRECATED. Will be removed in a future version. use ready instead.
tokentokenreadonlystripe.TokennullStripe Token
tokenDatastripe.TokenOptions{}Data passed to stripe.createToken. (optional)
Methods
MethodTypeDescription
blur(): voidBlurs the element.
focus(): voidFocuses the element.
reset(): voidResets and clears the stripe element.
Events
EventDescription
cancelWhen a payment request is cancelled
errorThe validation error, or the error returned from stripe.com
failWhen a payment request fails
payment-methodThe PaymentMethod received from stripe.com
readyStripe has been initialized and mounted
shippingaddresschangeWhen the user chooses a different shipping address
shippingoptionchangeWhen the user chooses a different shipping option
sourceThe Source received from stripe.com
stripe-errorDEPRECATED. Will be removed in a future major version. Use error instead
stripe-payment-methodDEPRECATED. Will be removed in a future major version. Use payment-method instead
stripe-readyDEPRECATED. Will be removed in a future major version. Use ready instead
stripe-sourceDEPRECATED. Will be removed in a future major version. Use source instead
stripe-tokenDEPRECATED. Will be removed in a future major version. Use token instead
successWhen a payment succeeds
tokenThe Token received from stripe.com
unsupportedWhen the element detects that the user agent cannot make a payment
CSS Shadow Parts
PartDescription
errorcontainer for the error message
stripecontainer for the stripe element
CSS Custom Properties
PropertyDescription
--stripe-payment-request-element-backgroundbackground property of the container element. Default white
--stripe-payment-request-element-min-widthmin-width property of the container element. Default 300px
--stripe-payment-request-element-paddingpadding property of the container element. Default 8px 12px

Keywords

FAQs

Package last updated on 08 Feb 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