Abstract payment js to work in webform context

Also fixed a couple bugs in the js code.