feat(gopay): support GoPay Plus checkout flow

This commit is contained in:
朴圣佑
2026-05-01 02:02:33 +08:00
committed by QLHazyCoder
parent 2eb913e00b
commit d851cc4d36
24 changed files with 3798 additions and 162 deletions
+23
View File
@@ -5,6 +5,7 @@
AU: ['au', 'aus', 'australia', '澳大利亚'],
DE: ['de', 'deu', 'germany', 'deutschland', '德国'],
FR: ['fr', 'fra', 'france', '法国'],
ID: ['id', 'indonesia', '印度尼西亚', '印尼'],
JP: ['jp', 'jpn', 'japan', '日本', '日本国'],
US: ['us', 'usa', 'united states', 'united states of america', 'america', '美国'],
};
@@ -76,6 +77,28 @@
},
},
],
ID: [
{
query: 'Jakarta Indonesia',
suggestionIndex: 1,
fallback: {
address1: 'Jalan M.H. Thamrin No. 1',
city: 'Jakarta',
region: 'DKI Jakarta',
postalCode: '10310',
},
},
{
query: 'Jakarta Selatan',
suggestionIndex: 1,
fallback: {
address1: 'Jalan Jenderal Sudirman Kav. 52-53',
city: 'Jakarta',
region: 'DKI Jakarta',
postalCode: '12190',
},
},
],
JP: [
{
query: 'Tokyo Marunouchi',
+22 -18
View File
@@ -30,26 +30,23 @@
{ id: 13, order: 130, key: 'platform-verify', title: '平台回调验证' },
];
const PLUS_GOPAY_STEP_DEFINITIONS = [
{ id: 1, order: 10, key: 'open-chatgpt', title: '打开 ChatGPT 官网' },
{ id: 2, order: 20, key: 'submit-signup-email', title: '注册并输入邮箱' },
{ id: 3, order: 30, key: 'fill-password', title: '填写密码并继续' },
{ id: 4, order: 40, key: 'fetch-signup-code', title: '获取注册验证码' },
{ id: 5, order: 50, key: 'fill-profile', title: '填写姓名和生日' },
{ id: 6, order: 60, key: 'plus-checkout-create', title: '打开 GoPay 订阅页' },
{ id: 7, order: 70, key: 'gopay-subscription-confirm', title: '等待 GoPay 订阅确认' },
{ id: 10, order: 100, key: 'oauth-login', title: '刷新 OAuth 并登录' },
{ id: 11, order: 110, key: 'fetch-login-code', title: '获取登录验证码' },
{ id: 12, order: 120, key: 'confirm-oauth', title: '自动确认 OAuth' },
{ id: 13, order: 130, key: 'platform-verify', title: '平台回调验证' },
];
const PLUS_PAYMENT_METHOD_GOPAY = 'gopay';
const PLUS_PAYMENT_STEP_KEY = 'paypal-approve';
function isPlusModeEnabled(options = {}) {
return Boolean(options?.plusModeEnabled || options?.plusMode);
}
function normalizePlusPaymentMethod(value = '') {
return String(value || '').trim().toLowerCase() === 'gopay' ? 'gopay' : 'paypal';
return String(value || '').trim().toLowerCase() === PLUS_PAYMENT_METHOD_GOPAY
? PLUS_PAYMENT_METHOD_GOPAY
: 'paypal';
}
function getPlusPaymentStepTitle(options = {}) {
return normalizePlusPaymentMethod(options?.plusPaymentMethod) === PLUS_PAYMENT_METHOD_GOPAY
? 'GoPay 手机验证与授权'
: 'PayPal 登录与授权';
}
function getModeStepDefinitions(options = {}) {
@@ -61,12 +58,18 @@
: PLUS_PAYPAL_STEP_DEFINITIONS;
}
function cloneSteps(steps = []) {
return steps.map((step) => ({ ...step }));
function cloneSteps(steps = [], options = {}) {
const plusModeEnabled = isPlusModeEnabled(options);
return steps.map((step) => ({
...step,
title: plusModeEnabled && step.key === PLUS_PAYMENT_STEP_KEY
? getPlusPaymentStepTitle(options)
: step.title,
}));
}
function getSteps(options = {}) {
return cloneSteps(getModeStepDefinitions(options));
return cloneSteps(getModeStepDefinitions(options), options);
}
function getAllSteps() {
@@ -101,7 +104,7 @@
function getStepById(id, options = {}) {
const numericId = Number(id);
const match = getModeStepDefinitions(options).find((step) => step.id === numericId);
return match ? { ...match } : null;
return match ? cloneSteps([match], options)[0] : null;
}
return {
@@ -112,6 +115,7 @@
PLUS_GOPAY_STEP_DEFINITIONS,
getAllSteps,
getLastStepId,
getPlusPaymentStepTitle,
getStepById,
getStepIds,
getSteps,