Putting the following code before the call to StaticPopup_Hide should prevent the Popup from declining the invite:
for i=1, STATICPOPUP_NUMDIALOGS do
local dlg = _G["StaticPopup"..i]
if dlg.which == "PARTY_INVITE" then
dlg.inviteAccepted = 1
It loops through all StaticPopups and sets the inviteAccepted
flag for the one that is showing the invite message.