You can do that easily from the recovery system.
Boot to recovery partition (Reboot, holding Command-R)
Erase the partition, using Disk Utility
Reinstall macOS.
Or, if you are just returning for refund, or exchange, you can just stop at erasing the partition.
Apple, as part of a refurb, would wipe and restore the macOS, anyway.