I am not 100% sure, but I know you can buy it at the Ranger Park Entry station just outside St Mary Visitor Center. To enter the Park and make a right hand turn into the Visitor Center, you have to go through the Park Entry station. You can use credit card.
You can buy a pass for all Nat. Parks at the entrance station kiosk when you enter the park, right outside the V.C., not the V.C. itself. But f you enter the park too early or late, there may not be anone there.
Thanks! Your answer is awaiting moderation.