"The Gift of the Magi" is set in an unnamed American city around the turn of the 20th century. Given that O. Henry did much of his writing in New York City (the title of the story collection The Four Million refers to the city's population in that era), it makes sense to suppose that "The Gift of the Magi" takes place there, too. At one point, Della compares herself to "A Coney Island chorus girl," referring to the Brooklyn neighborhood and its entertainment venues, which makes a New York setting very likely.
Though Della ventures into a few shops, the city doesn't feature prominently in the story, most of which takes place in Jim and Della's apartment. Their home is described in detail; Della flops on a "shabby little couch" in their "$8 per week" furnished flat that nearly "beggar[s] description." The flat is so cheap and ramshackle that its appearance is almost impossible to put into words. Indeed, Della can only view her reflection in the flat's cheap mirror because she's mastered the trick of angling herself just right in front of the strips of glass.
Jim and Della's environment reflects their economically disadvantaged status:
In the vestibule below was a letter-box into which no letter would go, and an electric button from which no mortal finger could coax a ring [...] [T]he letters of 'Dillingham' looked blurred, as though they were thinking of contracting to a modest and unassuming D."
Even basic accessories, like the mailbox and doorbell, don't work properly, underlining the fact that the Youngs are poor and apparently live in a building that's not well-maintained. Jim's distinguished-sounding middle name even looks "blurred," as if it doesn't fit his working-class lifestyle and wishes it could fade into the background.
Even the outdoors reflects the couple's poverty:
[Della] stood by the window and looked out dully at a grey cat walking a grey fence in a grey backyard. To-morrow would be Christmas Day, and she had only $1.87 with which to buy Jim a present.
The repetition of "grey" fits with Della's despair as she reflects on how little she has to spend. Her environment is colorless and unvarying, which reflects her limited options in life.
And yet, even though Jim and Della live in poverty, their shabby surroundings contrast with the atmosphere of domestic comfort and affection they enjoy when they're together:
But whenever James Dillingham Young came home and reached his flat above he was called “Jim” and greatly hugged by Mrs. James Dillingham Young, already introduced to you as Della.
And Della puts effort into making home as cozy as possible for Jim:
At 7 o'clock the coffee was made and the frying-pan was on the back of the stove hot and ready to cook the chops.
The narrator implies here that no matter how bedraggled their physical surroundings, the couple's genuine love for each other makes life not just bearable, but happy. "Mrs. James Dillingham Young" might be a more suitable name for a society lady than for Della—but even if the name is a bit pretentious, there's nothing fake about the affectionate welcome Jim finds when he enters the shabby flat. It also appears that Della has a finely honed evening routine so that supper can be cooked as soon as Jim gets home. Even if Della has spent her day haggling with neighborhood grocers, the couple generally has what they need, and tranquility and comfort reign within the walls of the flat.
It's also worth nothing that although the Youngs are clearly poor—Della meticulously scrimps and saves in order to get by, much less to buy Jim a present—they are able to subsist on Jim's $20-a-week income, apparently without Della being employed outside the home as well. So although the story doesn't discuss their social status in detail, readers can assume that while they're far from affluent, they don't belong to the most impoverished lower class, either.
Overall, the Youngs' happy marriage is a more prominent part of the setting than their marked poverty. This contrast also helps anticipate the ending of the story, when the couple's devoted love for each other is deemed more important than their wasted Christmas gifts.