use \n for line endings instead of sometimes using \r\n. Fix up some inconsistent whitespace.
fix typo, make sure we save when promoting to merchant by URI
tighten up $source_uri code; add $on_behalf_of parameter
add tests, use more verbose if statements.