No, you cannot "buy" credits.
The only way that you earn credits is through working for wages in a job that is covered by Social Security or having net income from self-employment. You don't get credits for unearned income such as your pensions or interest or dividends from your savings and investments. You don't pay Social Security taxes on that kind of income even though you may have to pay income tax. If you work for a federal, state or local government agency that is not covered by Social Security, you don't pay Social Security tax and you don't earn credits for monthly benefits based on those earnings. If you pay Medicare tax on those earnings, you do earn credits toward qualifying for Medicare protection at age 65.