This reminds me of the quote:
"Poor Mexico, so far away from God. So lose to the United States."
The United States was obsessed with having a Pacific coast. It would not accept money as an alternative. At best America would simply offer more money to compensate Mexico if the territory is more valuable.
The only way Mexico could keep the West is to have a stronger military. If they discover California's gold, and the silver of Nevada and Colorado, and have decent leadership, then they could put in place policies which leads to a better outcome in the war. Otherwise the money will not be properly invested, and the only difference this makes is more Mexican settlers and landowners in the West when America takes over.
Not really. Even with, it would be hard for Mexico to beat the US in the demographics game, which means that Northern California is going to be anglo no matter what.
Mexico needs a big change early in its history (best if done before independence) for it to keep the whole of California. Read Arkanghelsks' "Por La Patria Viva Un Mexcio Fuerte", for a Mexico that will likely be able to do so (the TL is still not there yet).
If the change is during the Mexican American War, Mexico's best hopes are to drag the war long enough for Polk to be out of office, or accept an early peace under the terms proposed by Herrera in OTL a border at the 38th (his original proposal before the war) or 37th parallel (Santa Anna's proposal to Polk at the end of the war, which by then was no longer a possibility).
I find the border at the 38th parallel quite interesting (and is the one I used for my TL). It splits the San Francisco Bay in two and allows Mexico to keep all of OTL's Arizona, half of New Mexico, the confluence of the Gilla and Colorado Rivers, and a thin sliver of OTL's Utah (which includes St. George).
Under this border the US controls most of the gold (as they big fields lay north of the border), but Mexico controls the ports San Francisco & Monterrey Bay.