Some of your terminology is confusing Train-2019. By "memory" do you mean iCloud storage? You cannot upgrade the memory in an iPhone.
As for the gift card, what kind is it? Certain cards can only be used for certain purposes. An iTunes & App Store card has to be redeemed to your account in order to have the funds available. This article explains the different kinds of cards Apple uses and has links on how to redeem them and what can be purchased with each kind. Click here --> What type of gift card do I have? - https://support.apple.com/HT204199
If this is a gift card which will add balance to your Apple ID then you can use it to pay for a storage upgrade subscription after redeeming it to your account. In fact it will be used automatically first.
How App Store and iTunes Store purchases are billed - https://support.apple.com/HT201359
"Which payment method is charged?
When you buy items or pay for subscriptions, Apple attempts to charge your payment methods in this order:
1. Apple attempts to use your Apple ID balance to cover the full amount.
2. If you don't have Apple ID balance or you don't have enough to cover the full amount, Apple attempts to charge your primary payment method. The primary payment method is at the top of the list in Settings on your iPhone. You can control which payment method is at the top of the list.
3. If there's a problem with the primary payment method, or if the primary payment method can't be charged for the full remaining amount, Apple attempts to charge your other payment methods in order from top to bottom. If none of them can be charged, Apple may try again.