stripe-ui
Allow your projects to take payments in as few lines of code possible.
Credit/Debit cards supported only.
Testing Credit Cards
Usage
This component requires no dependencies, use the <stripe-ui>
HTML custom element where you wish to display. Ensure to import the script on your page.
Consume the payload
event, which gets emitted when a valid payment method is chosen and completed by the user.
<stripe-ui data-config="{{ { "token": "", "api-key": "", "stripe-handle-payment-intent": "true/false" } }}"></stripe-ui>
<script src="https://uicomponent.live.pci.cavu-tech.com/payments.js"></script>
<script>
el = document.querySelector('stripe-ui')
function makePayment (nonce) {
fetch('https://example.com/checkout')
.then(response => response.json())
.then(result => {
// Pass the result through to the component.
// Expected format:
// {
// success: Boolean,
// verification: {
// status: String("processor_declined|processor_declined"),
// gatewayRejectionReason: String
// }
// }
el.dispatchEvent(new CustomEvent('complete', { detail: result }))
if (result.success) {
alert('Payment successful')
} else {
el.dataset.error = 'There was an error'
}
})
}
el.addEventListener('payload', function(event) {
console.log(event.detail)
// { nonce: "kz4r7k_7c2fsp_4qyf6q_wb5vmy_6y8", ... }
makePayment(event.detail.nonce)
})
</script>
Debugging
To view debugging in DevTools Console, enable the debug key on LocalStorage.
localStorage.debug = "stripe-ui:*"
Sandbox Example
Example cards
Card Number | Card Type | Response |
---|---|---|
4788250000028291 | VISA | Valid |
5454545454545454 | MasterCard | Valid |
371449635398431 | American Express | Valid |
More information, see CPS Test Conditions
API Options
Properties and events that can be used to interface with this Web Component.
Properties
Property | Attribute | Type | Default | Description |
---|---|---|---|---|
buttonRemoved | data-button-removed | boolean | false | Button Removed Enable the button responsible for tokenise, enabled by default can be set to false to allow for custom tokenise integration. |
buttonText | data-button-text | string | "Pay Now" | Button Text The label for the button text when not in spinner state Default option: - Pay Now |
config | data-config | { token: null; apiKey: null; stripeHandlePaymentIntent: boolean; paymentDescriptor: null; monitorApplicationId: null; monitorClientToken: null; environment: null; } | {"token":null,"apiKey":null,"stripeHandlePaymentIntent":false,"paymentDescriptor":null,"monitorApplicationId":null,"monitorClientToken":null,"environment":null} | Object that contains both stripe tokenization key token that authorizes to render a predefined payment iframe.And the API key api-key , e.g. "pk_test_51J0m3VAAlBjBPUKfRjyaWFl6HfvortTZgZX4ajrWf33c1ZY7xRXoFGHML9OqG700RTQVHcJLtn0rXXhQWh7AJ13T001c0YwmWF".As an integrator of this component, This object is returned from the paymentGateway/client-config payments api endpoint, via your server layer.Learn more about uiD's |
configurable | boolean | |||
customTheme | data-custom-theme | { colorPrimary: string; colorBackground: string; colorText: string; colorDanger: string; fontFamily: string; spacingUnit: string; borderRadius: string; } | Object that contains a simple appearance object, as defined in the Stripe Appearance API documentation linked below. Stripe Appearance API | |
enumerable | boolean | |||
errorMessage | data-error-message | string | "" | Display a stripe related error message, ideal for server side errors when attempting transactions. |
lang | data-lang | string | "" | The language to use for the display text. This will determine which translated text to display. Default is 'en-US'. |
paymentIntentAmount | data-payment-intent-amount | any | null | |
paymentIntentCreated | data-payment-intent-created | any | null | String tht should be updated by the Integrator to inform when a sale has been created and ready for paymentConfirmation. Accepts Status code in for the form of a String, eg. 200 |
paymentIntentCurrency | data-payment-intent-currency | string | "USD" | |
showTooltip | showTooltip | boolean | false |
Events
Event | Description |
---|---|
complete | Dispatch this event to the component when you've successfully completed a transaction or when the transaction has failed from your server. |
error | Handle the human readable display of a Server Side error, and allow the user to change payment method. List of all stripe errors. |
payload | Dispatched when the payment is payment method has been provided |
ready | Dispatched when the payment iframe has rendered successfully ready for input. |
stripePaymentIntentPayload | Dispatched when the payload is successfully retrieved from stripe sdk. Should be used to trigger sales/transactions processing. |
userError | Handle the human readable display of a Server Side error. |
CSS Custom Properties
Property | Description |
---|---|
--border | Controls the main theme colors for borders not contained within the iframe. (default: #E2E8EB) |
--primary | Controls the main theme colors for elements not contained within the iframe. (default: #032f61) |