matfish2 / vue-stripe

Vue.js 2 Stripe checkout component
https://www.npmjs.com/package/vue-stripe
MIT License
58 stars 18 forks source link

Multiple success broadcasts with multiple elements #37

Open mortocks opened 6 years ago

mortocks commented 6 years ago

When you have multiple elements on the page set to broadcast, the vue-stripe.success handler is called multiple times (once for each element on the page)

<stripe-checkout
              button-class="btn btn-primary"
              button="Product 1"
              :stripe-key="stripeKey"
              product="product"
              formId="PRODUCT_1"
              :options="PurchaseStripeOptions"
              on-success="broadcast">

<stripe-checkout
              button-class="btn btn-primary"
              button="Product 2"
              :stripe-key="stripeKey"
              product="product"
              formId="PRODUCT_2"
              :options="PurchaseStripeOptions"
              on-success="broadcast">

.....

mounted: function () {
    // Trigger stripe success callbacks
    Bus.$on('vue-stripe.success', payload => {
      console.log('vue-stripe.success', payload) // called twice
      switch (payload.formId) {
        case 'PRODUCT_1':
          console.log('PRODUCT_1')  // called twice
          break
        case 'PRODUCT_2':
          console.log('PRODUCT_2')  // called twice
          break
      }
    })
  },
....
asendari commented 6 years ago

Hello,

I've just try your bug.

On my side, I've include four time the checkout and I still receive two time the event.

Maybe my comment can help you to find the bug :D