Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
@power-elements/stripe-elements
Advanced tools
<stripe-elements>
Custom element wrapper for Stripe.js v3 Elements that works in shadow DOM. Creates a card
element à la https://stripe.com/docs/elements
npm i -S @power-elements/stripe-elements
npx @pika/web
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>
Then you can add the element to your page.
<script type="module" src="/web_modules/@power-elements/stripe-elements/stripe-elements.js"></script>
<stripe-elements id="stripe" action="/payment"></stripe-elements>
<button id="submit" disabled>Submit</button>
<script>
submit.onclick = () => stripe.validate() && stripe.submit();
stripe.addEventListener('change', function onChange() {
button.disabled = !this.validate()
})
</script>
In a lit-html template
import { html, render } from '/web_modules/lit-html/lit-html.js';
import { PUBLISHABLE_KEY } from './config.js';
import '/web_modules/@power-elements/stripe-elements/stripe-elements.js';
const onChange = ({ target: { isComplete, hasError } }) => {
document.body.querySelector('button').disabled = !(isComplete && !hasError)
}
const onClick = () => document.getElementById('stripe').submit();
const template = html`
<button disabled @click="${onClick}">Get Token</button>
<stripe-elements id="stripe"
@stripe-change="${onChange}"
publishable-key="${PUBLISHABLE_KEY}"
action="/payment"
></stripe-elements>
`
render(template, document.body)
In a Polymer Template
<paper-input label="Stripe Publishable Key" value="{{key}}"></paper-input>
<stripe-elements id="stripe"
stripe-ready="{{ready}}"
publishable-key="[[key]]"
token="{{token}}"
></stripe-elements>
<paper-button id="submit"
disabled="[[!ready]]"
onclick="stripe.submit()">
Get Token
</paper-button>
<paper-toast
opened="[[token]]"
text="Token received for 💳 [[token.card.last4]]! 🤑"
></paper-toast>
A word about nomenclature before we list custom properties and mixins. Stripe v3
Introduces 'Stripe Elements'. These 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 mentions the 'element', I mean the custom element.
The following custom properties are available for styling the <stripe-elements>
component:
Custom property | Description | Default |
---|---|---|
--stripe-elements-width | Min-width of the element | 300px |
--stripe-elements-height | Min-width of the element | 50px |
--stripe-elements-element-padding | Padding for the element | 14px |
--stripe-elements-element-background | Background for the element | initial |
When you apply CSS to the custom properties below, 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:
--stripe-elements-base-color
--stripe-elements-base-font-family
--stripe-elements-base-font-size
--stripe-elements-base-font-smoothing
--stripe-elements-base-font-variant
--stripe-elements-base-icon-color
--stripe-elements-base-line-height
--stripe-elements-base-letter-spacing
--stripe-elements-base-text-decoration
--stripe-elements-base-text-shadow
--stripe-elements-base-text-transform
and likewise --stripe-elements-complete-color
, etc.
FAQs
Web Component wrapper for stripe elements
The npm package @power-elements/stripe-elements receives a total of 454 weekly downloads. As such, @power-elements/stripe-elements popularity was classified as not popular.
We found that @power-elements/stripe-elements demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.