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

See demo here

Example cards
Card NumberCard TypeResponse
4788250000028291VISAValid
5454545454545454MasterCardValid
371449635398431American ExpressValid

More information, see CPS Test Conditions

API Options

Properties and events that can be used to interface with this Web Component.

Properties

PropertyAttributeTypeDefaultDescription
buttonRemoveddata-button-removedbooleanfalseButton Removed

Enable the button responsible for tokenise, enabled by default can be
set to false to allow for custom tokenise integration.
buttonTextdata-button-textstring"Pay Now"Button Text

The label for the button text when not in spinner state

Default option:
- Pay Now
configdata-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
configurableboolean
customThemedata-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
enumerableboolean
errorMessagedata-error-messagestring""Display a stripe related error message, ideal for server side errors when attempting transactions.
langdata-langstring""The language to use for the display text.
This will determine which translated text to display.
Default is 'en-US'.
paymentIntentAmountdata-payment-intent-amountanynull
paymentIntentCreateddata-payment-intent-createdanynullString 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
paymentIntentCurrencydata-payment-intent-currencystring"USD"
showTooltipshowTooltipbooleanfalse

Events

EventDescription
completeDispatch this event to the component when you've successfully completed a transaction or when the transaction has failed from your server.
errorHandle the human readable display of a Server Side error, and allow the user to change payment method. List of all stripe errors.
payloadDispatched when the payment is payment method has been provided
readyDispatched when the payment iframe has rendered successfully ready for input.
stripePaymentIntentPayloadDispatched when the payload is successfully retrieved from stripe sdk. Should be used to trigger sales/transactions processing.
userErrorHandle the human readable display of a Server Side error.

CSS Custom Properties

PropertyDescription
--borderControls the main theme colors for borders not contained within the iframe. (default: #E2E8EB)
--primaryControls the main theme colors for elements not contained within the iframe. (default: #032f61)