feat(gopay): support GoPay Plus checkout flow
This commit is contained in:
+22
-18
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user