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
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
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