()
| 668 | } |
| 669 | |
| 670 | async function randomBillingByCountry() { |
| 671 | const country = String(getInputValue("billing-country-input") || "US").toUpperCase(); |
| 672 | setButtonLoading("random-billing-btn", "生成中...", true); |
| 673 | setRandomBillingHint("正在获取随机账单资料...", "info"); |
| 674 | try { |
| 675 | const data = await api.get(`/payment/random-billing?country=${encodeURIComponent(country)}`); |
| 676 | const profile = data?.profile || {}; |
| 677 | if (!profile || typeof profile !== "object") { |
| 678 | throw new Error("返回的账单资料格式无效"); |
| 679 | } |
| 680 | |
| 681 | fillBillingForm({ |
| 682 | billing_name: profile.billing_name || "", |
| 683 | country_code: profile.country_code || country, |
| 684 | currency: profile.currency || "", |
| 685 | address_line1: profile.address_line1 || "", |
| 686 | address_city: profile.address_city || "", |
| 687 | address_state: profile.address_state || "", |
| 688 | postal_code: profile.postal_code || "", |
| 689 | }); |
| 690 | |
| 691 | const source = String(profile.source || "unknown"); |
| 692 | let sourceLabel = "本地兜底"; |
| 693 | if (source === "meiguodizhi") sourceLabel = "meiguodizhi"; |
| 694 | if (source === "local_geo") sourceLabel = "本地生成"; |
| 695 | if (source === "local_geo_fallback") sourceLabel = "本地兜底"; |
| 696 | const fallbackReason = String(profile.fallback_reason || "").trim(); |
| 697 | const city = String(profile.address_city || "-"); |
| 698 | const state = String(profile.address_state || "-"); |
| 699 | const postal = String(profile.postal_code || "-"); |
| 700 | if ((source === "local_fallback" || source === "local_geo_fallback") && fallbackReason) { |
| 701 | setRandomBillingHint(`来源: ${sourceLabel} | ${city}, ${state}, ${postal} | 外部失败: ${fallbackReason}`, "error"); |
| 702 | toast.warning(`外部地址源不可用,已切换本地兜底:${fallbackReason}`); |
| 703 | } else { |
| 704 | setRandomBillingHint(`来源: ${sourceLabel} | ${city}, ${state}, ${postal}`, "success"); |
| 705 | toast.success(`已按 ${country} 随机填充账单资料(${sourceLabel})`); |
| 706 | } |
| 707 | } catch (error) { |
| 708 | setRandomBillingHint(`随机失败: ${formatErrorMessage(error)}`, "error"); |
| 709 | toast.error(`随机账单资料失败: ${formatErrorMessage(error)}`); |
| 710 | } finally { |
| 711 | setButtonLoading("random-billing-btn", "生成中...", false); |
| 712 | } |
| 713 | } |
| 714 | |
| 715 | function collectBillingFormData() { |
| 716 | const expiry = parseExpiryInput(getInputValue("card-expiry-input")); |
nothing calls this directly
no test coverage detected