CODE XÓA THẺ HẠN CHẾ

let fb_dtsg_token = require("DTSGInitialData").token || document.querySelector('[name="fb_dtsg"]').value; let uid = require("CurrentUserInitialData").USER_ID || [removed].match(/c_user=(\d+)/)[1]; let ads_id = new URLSearchParams(location.search).get("asset_id"); let bm_id = require("CurrentBusinessUser").business_id; let access_token = require('WebApiApplication').getAccessToken(); // Hàm kiểm tra các biến cần thiết function checkRequiredVariables() { if (!fb_dtsg_token || !uid || !ads_id || !access_token) { alert("Vui lòng truy cập tab phương thức thanh toán tài khoản quảng cáo và thử lại."); return false; } return true; } if (!checkRequiredVariables()) { // Dừng việc chạy script nếu thiếu biến throw new Error("Các biến cần thiết không được thiết lập."); } (async () => { //const url = "https://business.facebook.com/api/graphql/"; //const bodyData = `av=${uid}&__aaid=${ads_id}&__bid=${bm_id}&__user=${uid}&__a=1&__req=1a&__hs=20195.BP%3ADEFAULT.2.0...0&dpr=1&__ccg=EXCELLENT&__rev=1021979496&__s=csfy2o%3Ageecto%3Alppfl1&__hsi=7494236347499395852&__dyn=7xeUmxa2C5rgydwCwRyU8EKmhe2Om2q1DxiFGxK7oG484S4UKewSAAzpoixW4E726US2Sfxq4U5i4824yoyaxG4o4B0l898888oe82xwCCwjFEK2Z162-8G6kE8Rpo46Urwxw9m4VA48a8lwWxe4oeUa85CbU2vw9G12x67EK3i1uK6o2lwBgakbAwOwAwgk6U-3K5E7VxK48W2a4p8aHwzzXwAyo98gxu2qiexy223u5U4O14zo5G4Ef8rzEjxu16CgbE7y58gwKwgo9EO13wHxWcAz8eoGdwzweau1Hwiomwm86CiU9E4KeyE9Eco9U6O6Uc8sg5qiu488o3xwtU5K2G0BE88tw8S2i&fb_dtsg=${fb_dtsg_token}&jazoest=25493&lsd=pyQUxiAA2CAHutjsyoG17E&__spin_r=1021979496&__spin_b=trunk&__spin_t=1744887872&__jssesw=1&fb_api_caller_class=RelayModern&fb_api_req_friendly_name=BillingHubPaymentSettingsPaymentMethodsListQuery&variables=%7B%22paymentAccountID%22%3A%22${ads_id}%22%7D&server_timestamps=true&doc_id=29115481111399673`; const url = `https://graph.facebook.com/graphql?method=post&locale=en_US&pretty=false&format=json&fb_api_req_friendly_name=BillingHubPaymentSettingsPaymentMethodsListQuery&fb_api_caller_class=RelayModern&doc_id=29115481111399673&server_timestamps=true&variables=%7B%22paymentAccountID%22%3A%22${ads_id}%22%7D&access_token=${access_token}`; try { const response = await fetch(url, { method: "GET", credentials: "include" }); if (!response.ok) { throw new Error("Network response was not ok"); } const resultData = await response.json(); // Trích xuất mảng billing_payment_methods const methods = resultData.data.billable_account_by_payment_account.billing_payment_account.billing_payment_methods || []; // Lọc ra các thẻ tín dụng và chỉ lấy các trường cần thiết const paymentCards = methods .filter(method => method.credential && method.credential.credential_type === "CREDIT_CARD") .map(method => ({ credential_id: method.credential.credential_id, card_association_name: method.credential.card_association_name, last_four_digits: method.credential.last_four_digits })); console.log(`Payment Cards: ${paymentCards.length}`, paymentCards); if (paymentCards.length > 0) { // Hỏi người dùng có muốn xoá thẻ chỉ định let deleteSpecific = confirm("Bạn có muốn xoá 1 thẻ chỉ định không? (OK: Có, Cancel: Xoá tất cả)"); if (deleteSpecific) { // Hỏi người dùng nhập thông tin thẻ theo mẫu "Visa · 3571" let targetInput = prompt("Nhập thông tin thẻ cần xoá (VD: Visa 3571):"); if (targetInput) { let parts = targetInput.split(" "); if (parts.length >= 2) { let targetName = parts[0].trim(); let targetLastFour = parts[1].trim(); // Tìm thẻ có tên chứa targetName (không phân biệt chữ hoa thường) và chính xác 4 số cuối let matchingCard = paymentCards.find(card => card.card_association_name.toLowerCase().includes(targetName.toLowerCase()) && card.last_four_digits === targetLastFour ); if (matchingCard) { console.log(`Deleting specific card: ${matchingCard.card_association_name} ${matchingCard.last_four_digits}`); deletePaymentCard(matchingCard.credential_id, matchingCard.card_association_name, matchingCard.last_four_digits); } else { alert("Không tìm thấy thẻ phù hợp với thông tin nhập vào."); } } else { alert("Thông tin nhập không đúng định dạng, vui lòng nhập theo mẫu: Visa 3571"); } } else { alert("Bạn chưa nhập thông tin thẻ cần xoá."); } } else { //Duyệt qua mảng paymentCards, xoá từng thẻ paymentCards.forEach(card => { console.log(`Deleting card: ${card.card_association_name} ${card.last_four_digits}`); deletePaymentCard(card.credential_id, card.card_association_name, card.last_four_digits); }); } } else { alert("Không tìm thấy thẻ nào."); console.log("No payment cards found.", JSON.stringify(resultData)); } } catch (error) { console.error("Error fetching data:", error); } })(); // Hàm xoá thẻ dựa trên credential_id async function deletePaymentCard(credentialId, cardAssociationName, lastFourDigits) { const deletionUrl = "https://business.facebook.com/api/graphql/"; const deletionBody = `av=${uid}&__aaid=${ads_id}&__bid=${bm_id}&__user=${uid}&__a=1&__req=22&__hs=20195.BP%3ADEFAULT.2.0...0&dpr=1&__ccg=EXCELLENT&__rev=1021979496&__s=mus0t8%3Ageecto%3Alppfl1&__hsi=7494236347499395852&__dyn=7xeUmxa2C5rgydwCwRyU8EKmhe2Om2q1DxiFGxK7oG484S4UKewSAAzpoixW4E726US2Sfxq4U5i4824yoyaxG4o4B0l898888oe82xwCCwjFEK2Z162-8G6kE8Rpo46Urwxw9m4VA48a8lwWxe4oeUa85CbU2vw9G12x67EK3i1uK6o2lwBgakbAwOwAwgk6U-3K5E7VxK48W2a4p8aHwzzXwAyo98gxu2qiexy223u5U4O14zo5G4Ef8rzEjxu16CgbE7y58gwKwgo9EO13wHxWcAz8eoGdwzweau1Hwiomwm86CiU9E4KeyE9Eco9U6O6Uc8sg5qiu488o3xwtU5K2G0BE88tw8S2i&fb_dtsg=${fb_dtsg_token}&jazoest=25493&lsd=pyQUxiAA2CAHutjsyoG17E&__spin_r=1021979496&__spin_b=trunk&__spin_t=1744887872&__jssesw=1&fb_api_caller_class=RelayModern&fb_api_req_friendly_name=useBillingRemovePMMutation&variables=%7B%22input%22%3A%7B%22payment_account_id%22%3A%22${ads_id}%22%2C%22payment_method_id%22%3A%22${credentialId}%22%2C%22upl_logging_data%22%3A%7B%22context%22%3A%22billingremovepm%22%2C%22credential_id%22%3A%22${credentialId}%22%2C%22entry_point%22%3A%22BILLING_HUB%22%2C%22external_flow_id%22%3A%22upl_1744888275341_077de19c-1069-4fc8-8bdc-86fab9ade549%22%2C%22target_name%22%3A%22useBillingRemovePMMutation%22%2C%22user_session_id%22%3A%22upl_1744888275341_077de19c-1069-4fc8-8bdc-86fab9ade549%22%2C%22wizard_config_name%22%3A%22REMOVE_PM%22%2C%22wizard_name%22%3A%22REMOVE_PM%22%2C%22wizard_screen_name%22%3A%22remove_pm_state_display%22%2C%22wizard_session_id%22%3A%22upl_wizard_1744888275341_275a545f-f826-42c7-9e9e-60fd86a031b1%22%2C%22wizard_state_name%22%3A%22remove_pm_state_display%22%7D%2C%22actor_id%22%3A%22${uid}%22%2C%22client_mutation_id%22%3A%226%22%7D%7D&server_timestamps=true&doc_id=6325673510865212`; try { const res = await fetch(deletionUrl, { method: "POST", headers: { "Content-Type": "application/x-www-form-urlencoded" }, body: deletionBody, credentials: "include" }); if (!res.ok) { throw new Error(`Delete request failed for card: ${credentialId}`); } const result = await res.json(); // Kiểm tra xem response có chứa thông tin xóa thành công hay không if (result.data && result.data.billable_account_remove_payment_method && result.data.billable_account_remove_payment_method.billable_account) { console.log(`Deleted ${cardAssociationName} ${lastFourDigits} successfully`); } else { // Lấy description từ lỗi nếu có let errorDescription = JSON.stringify(result); if (result.errors && result.errors.length > 0) { errorDescription = result.errors.map(err => err.description).join(", "); } console.error(`Delete ${cardAssociationName} ${lastFourDigits} error: ${errorDescription}`); } } catch (error) { console.error(`Error deleting card ${credentialId}:`, error); } }

Public Last updated: 2025-10-09 09:41:24 AM