One option if you purchased directly from Apple Store or online is to utilize the 14 day return policy: Returns & Refunds - Shopping Help - Apple
Other sellers have their own policy for returns.
If the phone is outside the return policy, it is also covered by warranty for 1 year in the U.S. and possibly longer elsewhere. iPhone Repair - Official Apple Support