CarlRaymond / jquery.cardswipe

jQuery plugin for magnetic card readers
MIT License
115 stars 49 forks source link

Updating The Success Callback after initialization #34

Closed ggarza5 closed 4 years ago

ggarza5 commented 4 years ago

I am trying to change set jquery.cardwipe's success handler at a point after initialization so that I can capture some local variables within the handler and post them to my server upon successful swipe. However, I am having trouble updating it.

Cardswipe is initialized like so (in appStore.js): $.cardswipe({ firstLineOnly: false, parsers: [ "visa", "mastercard", "amex", "discover", "generic" ], success: appStore.goodScan, error: appStore.badScan });

With appstore (in appStore.js): const appStore = observable({ station: null, route: 'categories', goodScan(data) { console.log('A card was read successfully.'); }, badScan(err) { console.error('card read error', err); }, });

I have tried (in pages/page.js, where pages is a directory in appStore.js's directory): this.props.appStore.goodScan = (cardData) => {/Code/}, this.setState({this.props.appStore.goodScan: (cardData) => {/Code/}, $.cardswipe.success = (cardData) => {/Code/}

Is there a proper way to update the handler?

I am new to React, so sorry if this is a React fundamental point that I am missing. Thank you so much for your help Gabriel

ggarza5 commented 4 years ago

Figured it out. Just had to wrap the appStore object attribute function with an external function reference. Then, updating the appStore attribute was properly updated through the reference. Cheers