My understanding is that a "rain check" is a slip of paper given to attendees at a baseball game when the game is "rained out" after the fans have arrived and paid their entry fee but before some point in the game (6 innings) where the "win" would be given to the currently leading team.  The slip entitles the holder to attend a later game by the "home team".  See, for example, [Bloomsburry](https://www.bloomsbury-international.com/student-ezone/idiom-of-the-week/1677-take-a-rain-check/).

The term "take a rain check" became a metaphor for saying you cannot accept an invitation now but you would like to at a later date.  It was further metaphorized to be a semi-polite way to turn down an invitation.