If a digital gift card hasn't been redeemed, you can cancel it and get a refund up to 14 days from the date you bought it. Your gift cards are non-transferable to another person or Microsoft account.
Sign in to the gift card history page in your Microsoft account. If you end up on a gift card merchandise page, select Gift card history, sign in, then select Gift card history again.
Locate the gift card to cancel.
Select Cancel > Confirm to cancel the order and get a refund.
This applies to digital gift cards purchased online from Microsoft. It doesn't apply to physical gift cards purchased in a store, or to codes for products like Office or Xbox.