diff --git a/background.js b/background.js
index cf59b2d..8b6e64d 100644
--- a/background.js
+++ b/background.js
@@ -239,6 +239,7 @@ const SUB2API_STEP1_RESPONSE_TIMEOUT_MS = 90000;
const SUB2API_STEP9_RESPONSE_TIMEOUT_MS = 120000;
const DEFAULT_SUB2API_URL = 'https://sub2api.hisence.fun/admin/accounts';
const DEFAULT_CODEX2API_URL = 'http://localhost:8080/admin/accounts';
+const DEFAULT_GPC_HELPER_API_URL = 'https://gopay.hwork.pro';
const DEFAULT_SUB2API_GROUP_NAME = 'codex';
const DEFAULT_SUB2API_PROXY_NAME = '';
const CONTRIBUTION_SOURCE_CPA = 'cpa';
@@ -603,7 +604,7 @@ const PERSISTED_SETTING_DEFAULTS = {
gopayPhone: '',
gopayOtp: '',
gopayPin: '',
- gopayHelperApiUrl: '',
+ gopayHelperApiUrl: DEFAULT_GPC_HELPER_API_URL,
gopayHelperCardKey: '',
gopayHelperPhoneNumber: '',
gopayHelperCountryCode: '+86',
@@ -2213,9 +2214,13 @@ function normalizePersistentSettingValue(key, value) {
? self.GoPayUtils.normalizeGoPayCountryCode(value)
: String(value || '+86').trim();
case 'gopayHelperApiUrl':
- return self.GoPayUtils?.normalizeGpcHelperBaseUrl
- ? self.GoPayUtils.normalizeGpcHelperBaseUrl(value)
- : String(value || '').trim().replace(/\/+$/g, '');
+ {
+ const defaultGpcHelperApiUrl = PERSISTED_SETTING_DEFAULTS.gopayHelperApiUrl
+ || (typeof DEFAULT_GPC_HELPER_API_URL !== 'undefined' ? DEFAULT_GPC_HELPER_API_URL : 'https://gopay.hwork.pro');
+ return self.GoPayUtils?.normalizeGpcHelperBaseUrl
+ ? self.GoPayUtils.normalizeGpcHelperBaseUrl(value || defaultGpcHelperApiUrl)
+ : String(value || defaultGpcHelperApiUrl).trim().replace(/\/+$/g, '');
+ }
case 'gopayHelperCardKey':
case 'gopayHelperReferenceId':
case 'gopayHelperGoPayGuid':
@@ -9387,13 +9392,13 @@ async function maybeSwitchIpProxyAfterAutoRunRoundSuccess(payload = {}) {
function resolveGpcHelperBaseUrl(apiUrl = '') {
if (self.GoPayUtils?.normalizeGpcHelperBaseUrl) {
- return self.GoPayUtils.normalizeGpcHelperBaseUrl(apiUrl);
+ return self.GoPayUtils.normalizeGpcHelperBaseUrl(apiUrl || DEFAULT_GPC_HELPER_API_URL);
}
- let normalized = String(apiUrl || '').trim().replace(/\/+$/g, '');
+ let normalized = String(apiUrl || DEFAULT_GPC_HELPER_API_URL).trim().replace(/\/+$/g, '');
normalized = normalized.replace(/\/api\/checkout\/start$/i, '');
normalized = normalized.replace(/\/api\/gopay\/(?:otp|pin)$/i, '');
normalized = normalized.replace(/\/api\/card\/balance(?:\?.*)?$/i, '');
- return normalized;
+ return normalized || DEFAULT_GPC_HELPER_API_URL;
}
function buildGpcCardBalanceRequestUrl(apiUrl = '', cardKey = '') {
@@ -9423,7 +9428,7 @@ function formatGpcCardBalancePayload(payload = {}) {
}
async function refreshGpcCardBalance(state = {}, options = {}) {
- const apiUrl = String(state?.gopayHelperApiUrl || '').trim();
+ const apiUrl = resolveGpcHelperBaseUrl(state?.gopayHelperApiUrl || DEFAULT_GPC_HELPER_API_URL);
const cardKey = String(state?.gopayHelperCardKey || state?.gpcCardKey || state?.cardKey || '').trim();
if (!apiUrl) {
throw new Error('缺少 GPC API 地址。');
diff --git a/background/steps/create-plus-checkout.js b/background/steps/create-plus-checkout.js
index e108a16..8e1b67b 100644
--- a/background/steps/create-plus-checkout.js
+++ b/background/steps/create-plus-checkout.js
@@ -7,6 +7,7 @@
const PLUS_PAYMENT_METHOD_PAYPAL = 'paypal';
const PLUS_PAYMENT_METHOD_GOPAY = 'gopay';
const PLUS_PAYMENT_METHOD_GPC_HELPER = 'gpc-helper';
+ const DEFAULT_GPC_HELPER_API_URL = 'https://gopay.hwork.pro';
function createPlusCheckoutCreateExecutor(deps = {}) {
const {
@@ -200,11 +201,11 @@
if (rootScope.GoPayUtils?.normalizeGpcHelperBaseUrl) {
return rootScope.GoPayUtils.normalizeGpcHelperBaseUrl(apiUrl);
}
- let normalized = String(apiUrl || '').trim().replace(/\/+$/g, '');
+ let normalized = String(apiUrl || DEFAULT_GPC_HELPER_API_URL).trim().replace(/\/+$/g, '');
normalized = normalized.replace(/\/api\/checkout\/start$/i, '');
normalized = normalized.replace(/\/api\/gopay\/(?:otp|pin)$/i, '');
normalized = normalized.replace(/\/api\/card\/balance(?:\?.*)?$/i, '');
- return normalized;
+ return normalized || DEFAULT_GPC_HELPER_API_URL;
}
function buildGpcHelperApiUrl(apiUrl = '', path = '') {
diff --git a/background/steps/fill-plus-checkout.js b/background/steps/fill-plus-checkout.js
index 62f4778..692b2dd 100644
--- a/background/steps/fill-plus-checkout.js
+++ b/background/steps/fill-plus-checkout.js
@@ -10,6 +10,7 @@
const PLUS_PAYMENT_METHOD_PAYPAL = 'paypal';
const PLUS_PAYMENT_METHOD_GOPAY = 'gopay';
const PLUS_PAYMENT_METHOD_GPC_HELPER = 'gpc-helper';
+ const DEFAULT_GPC_HELPER_API_URL = 'https://gopay.hwork.pro';
const PAYMENT_METHOD_CONFIGS = {
[PLUS_PAYMENT_METHOD_PAYPAL]: {
id: PLUS_PAYMENT_METHOD_PAYPAL,
@@ -111,11 +112,11 @@
if (rootScope.GoPayUtils?.normalizeGpcHelperBaseUrl) {
return rootScope.GoPayUtils.normalizeGpcHelperBaseUrl(apiUrl);
}
- let normalized = String(apiUrl || '').trim().replace(/\/+$/g, '');
+ let normalized = String(apiUrl || DEFAULT_GPC_HELPER_API_URL).trim().replace(/\/+$/g, '');
normalized = normalized.replace(/\/api\/checkout\/start$/i, '');
normalized = normalized.replace(/\/api\/gopay\/(?:otp|pin)$/i, '');
normalized = normalized.replace(/\/api\/card\/balance(?:\?.*)?$/i, '');
- return normalized;
+ return normalized || DEFAULT_GPC_HELPER_API_URL;
}
async function fetchJsonWithTimeout(url, options = {}, timeoutMs = 30000) {
diff --git a/gopay-utils.js b/gopay-utils.js
index a24ef8d..462f034 100644
--- a/gopay-utils.js
+++ b/gopay-utils.js
@@ -4,6 +4,7 @@
const PLUS_PAYMENT_METHOD_PAYPAL = 'paypal';
const PLUS_PAYMENT_METHOD_GOPAY = 'gopay';
const PLUS_PAYMENT_METHOD_GPC_HELPER = 'gpc-helper';
+ const DEFAULT_GPC_HELPER_API_URL = 'https://gopay.hwork.pro';
function normalizePlusPaymentMethod(value = '') {
const normalized = String(value || '').trim().toLowerCase();
@@ -46,15 +47,15 @@
}
function normalizeGpcHelperBaseUrl(apiUrl = '') {
- let normalized = String(apiUrl || '').trim();
+ let normalized = String(apiUrl || DEFAULT_GPC_HELPER_API_URL).trim();
if (!normalized) {
- return '';
+ return DEFAULT_GPC_HELPER_API_URL;
}
normalized = normalized.replace(/\/+$/g, '');
normalized = normalized.replace(/\/api\/checkout\/start$/i, '');
normalized = normalized.replace(/\/api\/gopay\/(?:otp|pin)$/i, '');
normalized = normalized.replace(/\/api\/card\/balance(?:\?.*)?$/i, '');
- return normalized;
+ return normalized || DEFAULT_GPC_HELPER_API_URL;
}
function buildGpcHelperApiUrl(apiUrl = '', path = '') {
@@ -194,6 +195,7 @@
return {
DEFAULT_GOPAY_COUNTRY_CODE,
+ DEFAULT_GPC_HELPER_API_URL,
PLUS_PAYMENT_METHOD_GPC_HELPER,
PLUS_PAYMENT_METHOD_GOPAY,
PLUS_PAYMENT_METHOD_PAYPAL,
diff --git a/sidepanel/sidepanel.html b/sidepanel/sidepanel.html
index 11bf79f..a80d989 100644
--- a/sidepanel/sidepanel.html
+++ b/sidepanel/sidepanel.html
@@ -279,10 +279,6 @@
-
- GPC API
-
-
GPC 卡密
diff --git a/sidepanel/sidepanel.js b/sidepanel/sidepanel.js
index 7ba4544..6e60951 100644
--- a/sidepanel/sidepanel.js
+++ b/sidepanel/sidepanel.js
@@ -478,6 +478,7 @@ const stepsList = document.querySelector('.steps-list');
const PLUS_PAYMENT_METHOD_PAYPAL = 'paypal';
const PLUS_PAYMENT_METHOD_GOPAY = 'gopay';
const PLUS_PAYMENT_METHOD_GPC_HELPER = 'gpc-helper';
+const DEFAULT_GPC_HELPER_API_URL = 'https://gopay.hwork.pro';
const DEFAULT_PLUS_PAYMENT_METHOD = PLUS_PAYMENT_METHOD_PAYPAL;
const SIGNUP_METHOD_EMAIL = 'email';
const SIGNUP_METHOD_PHONE = 'phone';
@@ -2773,6 +2774,9 @@ function applyCloudflareTempEmailSettingsState(state = {}) {
}
function collectSettingsPayload() {
+ const defaultGpcHelperApiUrl = typeof DEFAULT_GPC_HELPER_API_URL !== 'undefined'
+ ? DEFAULT_GPC_HELPER_API_URL
+ : 'https://gopay.hwork.pro';
const { domains, activeDomain } = getCloudflareDomainsFromState();
const selectedCloudflareDomain = normalizeCloudflareDomainValue(
!cloudflareDomainEditMode ? selectCfDomain.value : activeDomain
@@ -3303,10 +3307,10 @@ function collectSettingsPayload() {
? String(inputGoPayPin.value || '')
: String(latestState?.gopayPin || '')),
gopayHelperApiUrl: window.GoPayUtils?.normalizeGpcHelperBaseUrl
- ? window.GoPayUtils.normalizeGpcHelperBaseUrl(typeof inputGpcHelperApi !== 'undefined' && inputGpcHelperApi ? inputGpcHelperApi.value : latestState?.gopayHelperApiUrl)
+ ? window.GoPayUtils.normalizeGpcHelperBaseUrl(typeof inputGpcHelperApi !== 'undefined' && inputGpcHelperApi ? inputGpcHelperApi.value : (latestState?.gopayHelperApiUrl || defaultGpcHelperApiUrl))
: (typeof inputGpcHelperApi !== 'undefined' && inputGpcHelperApi
- ? String(inputGpcHelperApi.value || '').trim().replace(/\/+$/g, '')
- : String(latestState?.gopayHelperApiUrl || '').trim()),
+ ? String(inputGpcHelperApi.value || defaultGpcHelperApiUrl).trim().replace(/\/+$/g, '')
+ : String(latestState?.gopayHelperApiUrl || defaultGpcHelperApiUrl).trim()),
gopayHelperCardKey: typeof inputGpcHelperCardKey !== 'undefined' && inputGpcHelperCardKey
? String(inputGpcHelperCardKey.value || '').trim()
: String(latestState?.gopayHelperCardKey || '').trim(),
@@ -7044,7 +7048,7 @@ function updatePlusModeUI() {
}
if (typeof plusPaymentMethodCaption !== 'undefined' && plusPaymentMethodCaption) {
plusPaymentMethodCaption.textContent = method === gpcValue
- ? 'GPC API 订阅链路'
+ ? 'GPC 订阅链路'
: method === gopayValue
? 'GoPay 印尼订阅链路'
: 'PayPal 订阅链路';
@@ -7069,7 +7073,6 @@ function updatePlusModeUI() {
row.style.display = enabled && selectedMethod === paypalValue ? '' : 'none';
});
[
- typeof rowGpcHelperApi !== 'undefined' ? rowGpcHelperApi : null,
typeof rowGpcHelperCardKey !== 'undefined' ? rowGpcHelperCardKey : null,
typeof rowGpcHelperCountryCode !== 'undefined' ? rowGpcHelperCountryCode : null,
typeof rowGpcHelperPhone !== 'undefined' ? rowGpcHelperPhone : null,
@@ -7788,7 +7791,10 @@ function applySettingsState(state) {
selectPlusPaymentMethod.value = normalizePlusPaymentMethod(state?.plusPaymentMethod);
}
if (typeof inputGpcHelperApi !== 'undefined' && inputGpcHelperApi) {
- inputGpcHelperApi.value = state?.gopayHelperApiUrl || '';
+ const defaultGpcHelperApiUrl = typeof DEFAULT_GPC_HELPER_API_URL !== 'undefined'
+ ? DEFAULT_GPC_HELPER_API_URL
+ : 'https://gopay.hwork.pro';
+ inputGpcHelperApi.value = state?.gopayHelperApiUrl || defaultGpcHelperApiUrl;
}
if (typeof inputGpcHelperCardKey !== 'undefined' && inputGpcHelperCardKey) {
inputGpcHelperCardKey.value = state?.gopayHelperCardKey || '';
@@ -11204,7 +11210,7 @@ btnGpcHelperBalance?.addEventListener('click', async () => {
type: 'REFRESH_GPC_CARD_BALANCE',
source: 'sidepanel',
payload: {
- gopayHelperApiUrl: inputGpcHelperApi?.value || '',
+ gopayHelperApiUrl: inputGpcHelperApi?.value || DEFAULT_GPC_HELPER_API_URL,
gopayHelperCardKey: inputGpcHelperCardKey?.value || '',
gopayHelperCountryCode: selectGpcHelperCountryCode?.value || '+86',
reason: 'manual',
diff --git a/tests/background-account-history-settings.test.js b/tests/background-account-history-settings.test.js
index 0b4ca5d..b72c0c6 100644
--- a/tests/background-account-history-settings.test.js
+++ b/tests/background-account-history-settings.test.js
@@ -154,6 +154,7 @@ const self = {
};
const PERSISTED_SETTING_DEFAULTS = {
autoStepDelaySeconds: null,
+ gopayHelperApiUrl: 'https://gopay.hwork.pro',
mailProvider: '163',
};
function normalizePanelMode(value) { return value === 'sub2api' ? 'sub2api' : (value === 'codex2api' ? 'codex2api' : 'cpa'); }
@@ -191,6 +192,7 @@ return {
api.normalizePersistentSettingValue('gopayHelperApiUrl', ' https://gopay.hwork.pro/api/checkout/start '),
'https://gopay.hwork.pro'
);
+ assert.equal(api.normalizePersistentSettingValue('gopayHelperApiUrl', ''), 'https://gopay.hwork.pro');
assert.equal(api.normalizePersistentSettingValue('gopayHelperCardKey', ' card_123 '), 'card_123');
assert.equal(api.normalizePersistentSettingValue('gopayHelperCountryCode', ' 86 '), '+86');
assert.equal(api.normalizePersistentSettingValue('gopayHelperPhoneNumber', ' +86 138-0013-8000 '), '+8613800138000');
diff --git a/tests/gopay-utils.test.js b/tests/gopay-utils.test.js
index 0e08506..f5967a7 100644
--- a/tests/gopay-utils.test.js
+++ b/tests/gopay-utils.test.js
@@ -23,6 +23,12 @@ test('GoPay utils keeps GPC helper payment method distinct', () => {
test('GoPay utils builds GPC card balance URL from helper endpoints', () => {
const api = loadGoPayUtils();
+ assert.equal(api.DEFAULT_GPC_HELPER_API_URL, 'https://gopay.hwork.pro');
+ assert.equal(api.normalizeGpcHelperBaseUrl(''), 'https://gopay.hwork.pro');
+ assert.equal(
+ api.buildGpcHelperApiUrl('', '/api/checkout/start'),
+ 'https://gopay.hwork.pro/api/checkout/start'
+ );
assert.equal(
api.buildGpcCardBalanceUrl('http://localhost:18473/', ' card key/1 '),
'http://localhost:18473/api/card/balance?card_key=card%20key%2F1'
diff --git a/tests/sidepanel-plus-payment-method.test.js b/tests/sidepanel-plus-payment-method.test.js
index c81e807..ca141fc 100644
--- a/tests/sidepanel-plus-payment-method.test.js
+++ b/tests/sidepanel-plus-payment-method.test.js
@@ -204,7 +204,7 @@ return {
});
});
-test('sidepanel Plus UI shows GPC fields and purchase button only for GPC', () => {
+test('sidepanel Plus UI shows GPC fields and purchase button only for GPC without API input', () => {
const bundle = [
extractFunction('normalizePlusPaymentMethod'),
extractFunction('getSelectedPlusPaymentMethod'),
@@ -244,7 +244,7 @@ return {
assert.equal(api.rowPayPalAccount.style.display, 'none');
assert.equal(api.btnGpcCardKeyPurchase.style.display, '');
- assert.equal(api.rows.rowGpcHelperApi.style.display, '');
+ assert.equal(api.rows.rowGpcHelperApi.style.display, 'none');
assert.equal(api.rows.rowGpcHelperCardKey.style.display, '');
assert.equal(api.rows.rowGpcHelperPhone.style.display, '');
assert.match(api.plusPaymentMethodCaption.textContent, /GPC/);
diff --git a/tests/step-definitions-module.test.js b/tests/step-definitions-module.test.js
index d5ef80e..974b6c6 100644
--- a/tests/step-definitions-module.test.js
+++ b/tests/step-definitions-module.test.js
@@ -136,6 +136,8 @@ test('sidepanel html exposes Plus mode, PayPal, and GoPay settings', () => {
assert.match(html, /