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.7
  • 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: 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.
billingDetailsBillingDetailsbilling_details object sent to create the payment representation. (optional)
brandbrandreadonlybrandTypenullThe card brand detected by Stripe
cardcardreadonlyElementnullThe Stripe card object.
DEPRECATED. Will be removed in a future version. use element instead
clientSecretclient-secretstringThe client_secret part of a Stripe PaymentIntent
completecompletereadonlyfalsefalseWhether the form is complete.
elementelementreadonlyElementnullStripe element instance
elementselementsreadonlyElementsnullStripe Elements instance
emptyemptyreadonlytruetrueIf the form is empty.
errorerrorreadonlyAmbiguousErrornullStripe or validation error
focusedfocusedreadonlyfalsefalseIf the element is focused.
generategeneratePaymentRepresentation"source"Type of payment representation to generate.
hasErrorhas-errorreadonlyfalsefalseWhether 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" | undefined"default"Stripe icon style.
invalidinvalidreadonlyfalsefalseWhether 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-methodreadonlyPaymentMethodnullStripe PaymentMethod
paymentMethodDataPaymentMethodDataData passed to stripe.createPaymentMethod. (optional)
publishableKeypublishable-keystringStripe Publishable Key. EG. pk_test_XXXXXXXXXXXXXXXXXXXXXXXX
readyreadyreadonlyfalsefalseWhether the stripe element is ready to receive focus.
showErrorshow-errorbooleanfalseWhether to display the error message
sourcesourcereadonlySourcenullStripe Source
sourceDataSourceOptionsData passed to stripe.createSource. (optional)
stripestripereadonlyStripenullStripe instance
stripeMountIdstringStripe.js mount point element id. Due to limitations in the Stripe.js library, this element must be connected to the document.
stripeReadystripe-readyreadonlyfalsefalseWhether the stripe element is ready to receive focus.
DEPRECATED. Will be removed in a future version. use ready instead.
tokentokenreadonlyTokennullStripe Token
tokenDataTokenOptionsData passed to stripe.createToken. (optional)
valuevaluestring | { [objectKey: string]: string; } | undefined{}Prefilled values for form.
Methods
MethodTypeDescription
blur(): voidBlurs the element.
createPaymentMethod(paymentMethodData?: PaymentMethodData): Promise<PaymentMethodResponse>Submit payment information to generate a paymentMethod
createSource(sourceData?: SourceOptions): Promise<SourceResponse>Submit payment information to generate a source
createToken(tokenData?: TokenOptions): Promise<TokenResponse>Submit payment information to generate a token
focus(): voidFocuses the element.
getRootNode{ (options?: GetRootNodeOptions | undefined): Node; (options?: GetRootNodeOptions | undefined): Node | ShadowRoot; (options?: GetRootNodeOptions | undefined): Node | ShadowRoot; }
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.
setReadOnlyProperties(props: { [s: string]: unknown; }): Promise<void>Set read-only properties
submit(): Promise<StripePaymentResponse>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
PropertyDefaultDescription
--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-border"1px solid transparent"border property of the element container
--stripe-elements-border-radius"4px"border radius of the element container
--stripe-elements-box-shadow"0 1px 3px 0 #e6ebf1"box shadow for the element container
--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-transition"box-shadow 150ms ease"transition property for the element container

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.)
billingDetailsBillingDetailsbilling_details object sent to create the payment representation. (optional)
buttonThemebutton-theme"dark" | "light" | "light-outline""dark"
buttonTypebutton-type"default" | "donate" | "buy" | undefined"default"
canMakePaymentcan-make-paymentreadonly{ applePay?: boolean | undefined; } | nullnullWhether or not the device can make the payment request.
clientSecretclient-secretstringThe client_secret part of a Stripe PaymentIntent
countrycountry"AF" | "AX" | "AL" | "DZ" | "AS" | "AD" | "AO" | "AI" | "AQ" | "AG" | "AR" | "AM" | "AW" | "AU" | "AT" | "AZ" | "BS" | "BH" | "BD" | "BB" | "BY" | "BE" | "BZ" | "BJ" | "BM" | "BT" | "BO" | ... 217 more ... | "ZW"The two-letter country code of your Stripe account
currencycurrencystringThree character currency code
displayItemsdisplayItemsDisplayItem[]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.
elementelementreadonlyElementnullStripe element instance
elementselementsreadonlyElementsnullStripe Elements instance
errorerrorreadonlyAmbiguousErrornullStripe or validation error
focusedfocusedreadonlyfalsefalseIf the element is focused.
generategeneratePaymentRepresentation"source"Type of payment representation to generate.
hasErrorhas-errorreadonlyfalsefalseWhether 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-intentreadonlyPaymentIntentnullStripe PaymentIntent
paymentMethodpayment-methodreadonlyPaymentMethodnullStripe PaymentMethod
paymentMethodDataPaymentMethodDataData passed to stripe.createPaymentMethod. (optional)
paymentRequestpayment-requestreadonlyStripePaymentRequestnullStripe 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
readyreadyreadonlyfalsefalseWhether 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.
shippingOptionsshippingOptionsShippingOption[]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
sourcesourcereadonlySourcenullStripe Source
sourceDataSourceOptionsData passed to stripe.createSource. (optional)
stripestripereadonlyStripenullStripe instance
stripeMountIdstringStripe.js mount point element id. Due to limitations in the Stripe.js library, this element must be connected to the document.
stripeReadystripe-readyreadonlyfalsefalseWhether the stripe element is ready to receive focus.
DEPRECATED. Will be removed in a future version. use ready instead.
tokentokenreadonlyTokennullStripe Token
tokenDataTokenOptionsData passed to stripe.createToken. (optional)
Methods
MethodTypeDescription
blur(): voidBlurs the element.
focus(): voidFocuses the element.
getRootNode{ (options?: GetRootNodeOptions | undefined): Node; (options?: GetRootNodeOptions | undefined): Node | ShadowRoot; (options?: GetRootNodeOptions | undefined): Node | ShadowRoot; }
reset(): voidResets and clears the stripe element.
setReadOnlyProperties(props: { [s: string]: unknown; }): Promise<void>Set read-only properties
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
PropertyDefaultDescription
--stripe-payment-request-element-background"white"background property of the container element
--stripe-payment-request-element-min-width"300px"min-width property of the container element
--stripe-payment-request-element-padding"8px 12px"padding property of the container element

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: 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.
billingDetailsBillingDetailsbilling_details object sent to create the payment representation. (optional)
brandreadonlybrandTypeThe card brand detected by Stripe
cardreadonlyElementThe Stripe card object.
DEPRECATED. Will be removed in a future version. use element instead
clientSecretclient-secretstringThe client_secret part of a Stripe PaymentIntent
completereadonlyfalsefalseWhether the form is complete.
elementelementreadonlyElementnullStripe element instance
elementselementsreadonlyElementsnullStripe Elements instance
emptyreadonlytruetrueIf the form is empty.
errorerrorreadonlyAmbiguousErrornullStripe or validation error
focusedfocusedreadonlyfalsefalseIf the element is focused.
generategeneratePaymentRepresentation"source"Type of payment representation to generate.
hasErrorhas-errorreadonlyfalsefalseWhether the element has an error
DEPRECATED. Will be removed in a future version. Use error instead
hideIconbooleanWhether to hide icons in the Stripe form.
hidePostalCodebooleanWhether or not to hide the postal code field.
Useful when you gather shipping info elsewhere.
iconStyle"solid" | "default" | undefinedStripe icon style.
invalidreadonlyfalsefalseWhether the form is invalid.
isCompletebooleanWhether the form is complete.
DEPRECATED. Will be removed in a future version. use complete instead
isEmptybooleanWhether the form is empty.
DEPRECATED. Will be removed in a future version. use empty instead
paymentMethodpayment-methodreadonlyPaymentMethodnullStripe PaymentMethod
paymentMethodDataPaymentMethodDataData passed to stripe.createPaymentMethod. (optional)
publishableKeypublishable-keystringStripe Publishable Key. EG. pk_test_XXXXXXXXXXXXXXXXXXXXXXXX
readyreadyreadonlyfalsefalseWhether the stripe element is ready to receive focus.
showErrorshow-errorbooleanfalseWhether to display the error message
sourcesourcereadonlySourcenullStripe Source
sourceDataSourceOptionsData passed to stripe.createSource. (optional)
stripestripereadonlyStripenullStripe instance
stripeMountIdstringStripe.js mount point element id. Due to limitations in the Stripe.js library, this element must be connected to the document.
stripeReadystripe-readyreadonlyfalsefalseWhether the stripe element is ready to receive focus.
DEPRECATED. Will be removed in a future version. use ready instead.
tokentokenreadonlyTokennullStripe Token
tokenDataTokenOptionsData passed to stripe.createToken. (optional)
valuestring | { [objectKey: string]: string; } | undefinedPrefilled values for form.
Methods
MethodTypeDescription
blur(): voidBlurs the element.
createPaymentMethod(paymentMethodData?: PaymentMethodData | undefined): Promise<PaymentMethodResponse>Submit payment information to generate a paymentMethod
createSource(sourceData?: SourceOptions | undefined): Promise<SourceResponse>Submit payment information to generate a source
createToken(tokenData?: TokenOptions | undefined): Promise<TokenResponse>Submit payment information to generate a token
focus(): voidFocuses the element.
getRootNode{ (options?: GetRootNodeOptions | undefined): Node; (options?: GetRootNodeOptions | undefined): Node | ShadowRoot; (options?: GetRootNodeOptions | undefined): Node | ShadowRoot; }
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.
setReadOnlyProperties(props: { [s: string]: unknown; }): Promise<void>Set read-only properties
submit(): Promise<StripePaymentResponse>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
PropertyDefaultDescription
--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-border"1px solid transparent"border property of the element container
--stripe-elements-border-radius"4px"border radius of the element container
--stripe-elements-box-shadow"0 1px 3px 0 #e6ebf1"box shadow for the element container
--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-transition"box-shadow 150ms ease"transition property for the element container

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.
amountnumberThe amount in the currency's subunit (e.g. cents, yen, etc.)
billingDetailsBillingDetailsbilling_details object sent to create the payment representation. (optional)
buttonTheme"dark" | "light" | "light-outline"
buttonType"default" | "donate" | "buy" | undefined
canMakePaymentreadonly{ applePay?: boolean | undefined; } | nullWhether or not the device can make the payment request.
clientSecretclient-secretstringThe client_secret part of a Stripe PaymentIntent
country"AF" | "AX" | "AL" | "DZ" | "AS" | "AD" | "AO" | "AI" | "AQ" | "AG" | "AR" | "AM" | "AW" | "AU" | "AT" | "AZ" | "BS" | "BH" | "BD" | "BB" | "BY" | "BE" | "BZ" | "BJ" | "BM" | "BT" | "BO" | ... 217 more ... | "ZW"The two-letter country code of your Stripe account
currencystringThree character currency code
displayItemsDisplayItem[]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.
elementelementreadonlyElementnullStripe element instance
elementselementsreadonlyElementsnullStripe Elements instance
errorerrorreadonlyAmbiguousErrornullStripe or validation error
focusedfocusedreadonlyfalsefalseIf the element is focused.
generategeneratePaymentRepresentation"source"Type of payment representation to generate.
hasErrorhas-errorreadonlyfalsefalseWhether the element has an error
DEPRECATED. Will be removed in a future version. Use error instead
labelstringA name that the browser shows the customer in the payment interface.
paymentIntentreadonlyPaymentIntentStripe PaymentIntent
paymentMethodpayment-methodreadonlyPaymentMethodnullStripe PaymentMethod
paymentMethodDataPaymentMethodDataData passed to stripe.createPaymentMethod. (optional)
paymentRequestreadonlyStripePaymentRequestStripe PaymentRequest
pendingbooleanIf 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
readyreadyreadonlyfalsefalseWhether the stripe element is ready to receive focus.
requestPayerEmailbooleanSee the requestPayerName option.
requestPayerNamebooleanBy 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.
requestPayerPhonebooleanSee the requestPayerName option.
requestShippingbooleanCollect 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.
shippingOptionsShippingOption[]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
sourcesourcereadonlySourcenullStripe Source
sourceDataSourceOptionsData passed to stripe.createSource. (optional)
stripestripereadonlyStripenullStripe instance
stripeMountIdstringStripe.js mount point element id. Due to limitations in the Stripe.js library, this element must be connected to the document.
stripeReadystripe-readyreadonlyfalsefalseWhether the stripe element is ready to receive focus.
DEPRECATED. Will be removed in a future version. use ready instead.
tokentokenreadonlyTokennullStripe Token
tokenDataTokenOptionsData passed to stripe.createToken. (optional)
Methods
MethodTypeDescription
blur(): voidBlurs the element.
focus(): voidFocuses the element.
getRootNode{ (options?: GetRootNodeOptions | undefined): Node; (options?: GetRootNodeOptions | undefined): Node | ShadowRoot; (options?: GetRootNodeOptions | undefined): Node | ShadowRoot; }
reset(): voidResets and clears the stripe element.
setReadOnlyProperties(props: { [s: string]: unknown; }): Promise<void>Set read-only properties
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
PropertyDefaultDescription
--stripe-payment-request-element-background"white"background property of the container element
--stripe-payment-request-element-min-width"300px"min-width property of the container element
--stripe-payment-request-element-padding"8px 12px"padding property of the container element

Keywords

FAQs

Package last updated on 22 Apr 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