
Product
Introducing Socket Fix for Safe, Automated Dependency Upgrades
Automatically fix and test dependency updates with socket fix—a new CLI tool that turns CVE alerts into safe, automated upgrades.
@stripe-elements/stripe-elements
Advanced tools
Maintainer | GitHub | Social |
---|---|---|
Hidetaka Okamoto | Hidetaka Okamoto | @hide__dev |
Masaki Hirano | hirano | @maki_saki |
Masahiko Sakakibara | rdlabo | @rdlabo |
<stripe-payment-sheet>
Provide a Stripe Card form like a iOS/Android payment sheet.
<stripe-element-modal>
Simple modal for <stripe-payment-sheet>
stripe-payment-request-button
(Beta) Payment Request button component
<div id="result"></div>
<stripe-element-modal open="true">
<stripe-payment-sheet
publishable-key="pk_test_xxxxx"
show-label="false"
intent-client-secret="pi-xxxxxx"
should-use-default-form-submit-action="false"
></stripe-payment-sheet>
</stripe-element-modal>
<script>
customElements.whenDefined('stripe-payment-sheet')
.then(() => {
const elements = document.getElementsByTagName('stripe-payment-sheet')
if (elements.length < 1) return;
const element = elements[0]
element.addEventListener('formSubmit', async props => {
const {
detail: { stripe, cardNumber, event },
} = props;
const result = await stripe.createPaymentMethod({
type: 'card',
card: cardNumber,
});
element.updateProgress('success');
const resultElement = document.getElementById('result')
resultElement.innerHTML = `<pre><code>${JSON.stringify(result,null,2)}</code></pre>`
});
})
</script>
const stripePublishableAPIKey = 'YOUR_STRIPE_PUBLISHABLE_API_KEY'
const form = document.getElementById('open-modal-form')
const resultElement = document.getElementById('result')
const errorMessage = document.getElementById('error-message')
const targetElement = document.getElementById('stripe');
const modalElement = document.createElement('stripe-element-modal');
/**
* Remove Mounted Stripe Elements when the modal has been closed
**/
customElements.whenDefined('stripe-element-modal')
.then(() => {
modalElement.addEventListener('close', () => {
modalElement.innerHTML = ''
})
})
async function launchStripePaymentSheet (paymentIntentClientSecret) {
if (!stripePublishableAPIKey) {
errorMessage.innerText = 'Stripe Publishable API Key is required'
return
}
if (!paymentIntentClientSecret) {
errorMessage.innerText = 'Payment Intent Client Secret is required'
return
}
/**
* Define and launch Web Components
**/
const stripeElement = document.createElement('stripe-payment-sheet');
modalElement.appendChild(stripeElement);
targetElement.appendChild(modalElement);
/**
* Wait for defining these components
**/
await customElements.whenDefined('stripe-element-modal')
await customElements.whenDefined('stripe-payment-sheet')
/**
* Load Stripe Client
**/
await stripeElement.initStripe(stripePublishableAPIKey)
/**
* Set the payment intent client secret
**/
stripeElement.setAttribute('intent-client-secret', paymentIntentClientSecret)
/**
* Disable default form submit event
**/
stripeElement.setAttribute('should-use-default-form-submit-action', false);
/**
* Set custom form submit event manually
**/
stripeElement.addEventListener('formSubmit', async props => {
const {
detail: { stripe, cardNumber, event },
} = props;
const result = await stripe.createPaymentMethod({
type: 'card',
card: cardNumber,
});
resultElement.innerHTML = `<pre><code>${JSON.stringify(result,null,2)}</code></pre>`
stripeElement.updateProgress('success');
await modalElement.closeModal()
});
/**
* Open modal
**/
modalElement.setAttribute('open', true)
})
npm install
npm start
To build the component for production, run:
npm run build
To run the unit tests for the components, run:
npm test
FAQs
Web component of Stripe elements
The npm package @stripe-elements/stripe-elements receives a total of 778 weekly downloads. As such, @stripe-elements/stripe-elements popularity was classified as not popular.
We found that @stripe-elements/stripe-elements demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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.
Product
Automatically fix and test dependency updates with socket fix—a new CLI tool that turns CVE alerts into safe, automated upgrades.
Security News
CISA denies CVE funding issues amid backlash over a new CVE foundation formed by board members, raising concerns about transparency and program governance.
Product
We’re excited to announce a powerful new capability in Socket: historical data and enhanced analytics.