Skip to content

Instantly share code, notes, and snippets.

@onefriendaday
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save onefriendaday/56c7a8835697bd1376d2 to your computer and use it in GitHub Desktop.
Save onefriendaday/56c7a8835697bd1376d2 to your computer and use it in GitHub Desktop.
Callbacks in Xtech checkout
// Vars that needs to be set in order to work with pagseguro checkout process
var checkoutCallbacks = $.Callbacks();
var checkoutNoSubmit = false;
$('#onepage_checkoutform').submit(function(e){
// This calls the callback from ex. pagseguro.
checkoutCallbacks.fire('checkout');
// If the checkoutNoSubmit variable is set to false go and submit the form, otherwise prevent the form submit.
if (checkoutNoSubmit === false) {
// If the checkoutNoSubmit was set to false and pagseguro sets the creditCartToken input we will submit the form.
return true;
}else{
// If the checkoutNoSubmit is true we do not submit and wait for the pagseguro response in order to set the creditcard token.
e.preventDefault();
return false;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment