Yes, a trade-in is often possible:
Apple Trade In - Apple
If purchasing online from Apple, you have the option to trade-in during the purchase process. If your device is eligible, you will see an estimate of its value. If you accept the estimated value, you will initially pay the full purchase price - and will be sent a shipping kit in which to return your old device for trade-in.
When your old device is received, the item will be assessed. If the item is accepted, with its condition matching that declared when initiating the trade-in, the credit card used to make your purchase will be refunded the value of the trade-in.
A trade-in does not have to be completed when purchasing a new device - but can be made at another time. In this situation, you will receive a gift card for the trade-in value. Again, the device will be inspected when returned - and if all is well, you receive the offered value.
When trading-in, if the item was not as described, you may be offered a lower value - or the item may be returned to you.