Balaam was a man who raises many questions for the Bible student. He was a soothsayer, yet he was able to predict the future of Israel. He listened to God's Word and faithfully proclaimed it, yet turned right around and led Israel into sin and judgment.
In verses 1-14 of chapter 22, Balak, king of Moab, is fearful of Israel passing by on her way to Canaan, and sends for Balaam. He asked Balaam to use his demonic magical powers to curse Israel while they were encamped in the plain of Moab. Balaam refused, and Balak's messengers went home and reported failure. However, Balak was not one to give up easily and sent princes more noble than the first, and promised Balaam wealth and honor if he would reconsider the matter of cursing the Jews.
This is what Satan always does. Once we have made the decision to obey God's Word, Satan will make every effort to get us to compromise our standards and change our decision to obey God.
God allowed Balaam to go with the princes of Balak, but only to test Balaam. It is here that the well-known episode with the angel and the ass takes place. The angel stood in Balaam's way, but the prophet did not see him. The ass did, and acted so strangely that Balaam smote her. When he saw the angel, he realized his mistake. In verse 32 God said, "Thy way is perverse," so there was no reason for Balaam to say, "If it displease thee, I will get me back again.".
Balaam was playing with God's will. Within his heart he was seeking his own will, wanting God to put His stamp of approval upon it. So he was actually testing God, seeing how far he could go.
The main lesson here is that we find the will of God and obey it, regardless of personal desires or subsequent circumstances. It is always dangerous to play with God's will!