{"id":365,"date":"2025-03-19T17:45:52","date_gmt":"2025-03-19T17:45:52","guid":{"rendered":"https:\/\/www.xigmagames.com\/metalhaven\/?page_id=365"},"modified":"2025-03-20T06:35:49","modified_gmt":"2025-03-20T06:35:49","slug":"gift-code","status":"publish","type":"page","link":"https:\/\/www.xigmagames.com\/metalhaven\/gift-code\/","title":{"rendered":"Redeem Gift"},"content":{"rendered":"    <div class=\"grc-container\">\n        <div class=\"grc-title\">Gift Code Center<\/div>\n\n        <input type=\"text\" id=\"user_id\" class=\"grc-input\" placeholder=\"Player ID\">\n        <button class=\"grc-button\" id=\"confirm_id\">Login<\/button>\n        <p id=\"user_info\" class=\"grc-note\">*Check your Player ID in-game through your Avatar.<\/p>\n\n        <!-- Player Profile Section -->\n        <div id=\"player_profile\">\n            <div class=\"profile-container\">\n                \n            <\/div>\n            <h3 id=\"player_name\">...<\/h3>\n            <p id=\"player_id\">ID: ...<\/p>\n        <\/div>\n\n        <!-- Redeem Section -->\n        <div id=\"redeem_section\">\n            <input type=\"text\" id=\"redeem_code\" class=\"grc-input\" placeholder=\"Enter Gift Code\">\n            <button class=\"grc-button\" id=\"redeem_btn\">Confirm<\/button>\n            <p id=\"redeem_result\" class=\"grc-note\">*Rewards will be sent to your in-game mail after redemption.<\/p>\n        <\/div>\n\n        <!-- Success Message Section -->\n        <div id=\"success_message\" class=\"success-message\" style=\"display: none;\">\n            Your gift has been delivered!\n        <\/div>\n    <\/div>\n\n    <script>\n        document.addEventListener(\"DOMContentLoaded\", function () {\n            const confirmBtn = document.getElementById(\"confirm_id\");\n            const redeemBtn = document.getElementById(\"redeem_btn\");\n            const profileName = document.getElementById(\"player_name\");\n            const profileId = document.getElementById(\"player_id\");\n            \/\/const profileFrame = document.getElementById(\"profile_frame\");\n            \/\/const profileIcon = document.getElementById(\"profile_icon\");\n            const profileBox = document.getElementById(\"player_profile\");\n            const redeemBox = document.getElementById(\"redeem_section\");\n            const redeemResult = document.getElementById(\"redeem_result\");\n            const successMessage = document.getElementById(\"success_message\");\n\n            confirmBtn.addEventListener(\"click\", function () {\n                const userId = document.getElementById(\"user_id\").value.trim();\n\n                if (!userId) {\n                    alert(\"Please enter a Player ID.\");\n                    return;\n                }\n\n                fetch(\"https:\/\/metalhaven-prod-server.xigmagames.com\/SystemMail\/FetchPlayerWithId\", {\n                    method: \"POST\",\n                    headers: { \"Content-Type\": \"application\/json\" },\n                    body: JSON.stringify({ id: userId })\n                })\n                .then(response => response.json())\n                .then(data => {\n                    if (data.success && data.data) {\n                        let profile = typeof data.data === 'string' ? JSON.parse(data.data) : data.data;\n\n                        profileName.innerText = profile.name || \"Unnamed Player\";\n                        profileId.innerText = \"ID: \" + (profile.id || \"N\/A\");\n\n                        profileBox.classList.add(\"fade-in\");\n                        redeemBox.classList.add(\"fade-in\");\n                        profileBox.style.display = \"block\";\n                        redeemBox.style.display = \"block\";\n\n                        \/\/if (profile.avatarUrl) profileIcon.src = profile.avatarUrl;\n                        \/\/if (profile.frameUrl) {\n                          \/\/  profileFrame.src = profile.frameUrl;\n                            \/\/profileFrame.style.display = \"block\";\n                        \/\/}\n\n                        sessionStorage.setItem(\"validUserId\", profile.id);\n\n                        \/\/ Animate out login form\n                        const userInput = document.getElementById(\"user_id\");\n                        userInput.classList.add(\"fade-out\");\n                        confirmBtn.classList.add(\"fade-out\");\n\n                        setTimeout(() => {\n                            userInput.style.display = \"none\";\n                            confirmBtn.style.display = \"none\";\n                        }, 400);\n                    } else {\n                        alert(data.message || \"Invalid Player ID.\");\n                    }\n                })\n                .catch(error => {\n                    console.error(\"[DEBUG] Fetch error:\", error);\n                    alert(\"Error validating player.\");\n                });\n            });\n\n            redeemBtn.addEventListener(\"click\", function () {\n                const redeemCode = document.getElementById(\"redeem_code\").value.trim();\n                const playerId = sessionStorage.getItem(\"validUserId\");\n\n                if (!redeemCode) {\n                    alert(\"Please enter a redeem code.\");\n                    return;\n                }\n\n                \/\/ Send redeem request to the server with updated request body format\n                fetch(\"https:\/\/metalhaven-prod-server.xigmagames.com\/SystemMail\/CollectGiftFromSite\", {\n                    method: \"POST\",\n                    headers: { \"Content-Type\": \"application\/json\" },\n                    body: JSON.stringify({\n                        \"PlayerId\": playerId,       \/\/ Correct player ID\n                        \"GiftCode\": redeemCode      \/\/ Correct gift code\n                    })\n                })\n                .then(response => response.json())\n                .then(data => {\n                    if (data.success) {\n                        \/\/ Hide everything else and show success message\n                        profileBox.style.display = \"none\";\n                        redeemBox.style.display = \"none\";\n                        successMessage.style.display = \"block\";\n                    } else {\n                        redeemResult.innerText = \"Redeem failed: \" + (data.message || \"Unknown error.\");\n                        redeemResult.style.color = \"#ff6666\"; \/\/ Red error color\n                        redeemResult.classList.add(\"fade-in\");\n                    }\n                })\n                .catch(error => {\n                    console.error(\"[DEBUG] Redeem request error:\", error);\n                    redeemResult.innerText = \"Error processing redeem code.\";\n                    redeemResult.style.color = \"#ff6666\"; \/\/ Red error color\n                    redeemResult.classList.add(\"fade-in\");\n                });\n            });\n        });\n    <\/script>\n    \n","protected":false},"excerpt":{"rendered":"<p>Gift Code Center Login *Check your Player ID in-game through your Avatar. &#8230; ID: &#8230; Confirm *Rewards will be sent to your in-game mail after redemption. Your gift has been delivered!<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-365","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.xigmagames.com\/metalhaven\/wp-json\/wp\/v2\/pages\/365","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xigmagames.com\/metalhaven\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.xigmagames.com\/metalhaven\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.xigmagames.com\/metalhaven\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xigmagames.com\/metalhaven\/wp-json\/wp\/v2\/comments?post=365"}],"version-history":[{"count":4,"href":"https:\/\/www.xigmagames.com\/metalhaven\/wp-json\/wp\/v2\/pages\/365\/revisions"}],"predecessor-version":[{"id":456,"href":"https:\/\/www.xigmagames.com\/metalhaven\/wp-json\/wp\/v2\/pages\/365\/revisions\/456"}],"wp:attachment":[{"href":"https:\/\/www.xigmagames.com\/metalhaven\/wp-json\/wp\/v2\/media?parent=365"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}