craftcms / commerce-stripe

Stripe payment gateway for Craft Commerce
https://plugins.craftcms.com/commerce-stripe
MIT License
31 stars 48 forks source link

Allow access to instance of JS class on the HTML element #283

Closed nfourtythree closed 10 months ago

nfourtythree commented 10 months ago

Description

Currently the JS is setting the instance of the PaymentIntentsElements class into a data property on the element. This results in a value of [Object Object] meaning it is unusable to a developer.

This PR updates the code to simply add the instance directly to a property on the DOM node (using expando).

Meaning you are now able to access the instance and do something like the following:

document.querySelector('.stripe-payment-elements-form').handlerInstance.elements.update({
  appearance: {theme: 'night'}
});

Related issues

275