feat: ship Wave 5-6 multi-surface hygiene, optimization, and bug fixes
This commit is contained in:
parent
01ef3293cf
commit
66b6b45ba9
399 changed files with 17828 additions and 11330 deletions
|
|
@ -166,6 +166,27 @@ function getPaypleApiUrl(config: PaypleConfig, candidate: string | undefined, fa
|
|||
|
||||
// ── 파트너 인증 ───────────────────────────────────────
|
||||
|
||||
const PAYPLE_TIMEOUT_MS = 15_000
|
||||
const PAYPLE_BILLING_TIMEOUT_MS = 25_000
|
||||
|
||||
async function postPaypleJson(
|
||||
config: PaypleConfig,
|
||||
url: string,
|
||||
payload: Record<string, unknown>,
|
||||
timeoutMs = PAYPLE_TIMEOUT_MS,
|
||||
): Promise<Response> {
|
||||
return await fetch(url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Cache-Control': 'no-cache',
|
||||
'Referer': getReferer(config),
|
||||
},
|
||||
body: JSON.stringify(payload),
|
||||
signal: AbortSignal.timeout(timeoutMs),
|
||||
})
|
||||
}
|
||||
|
||||
export async function paypleAuth(
|
||||
config: PaypleConfig,
|
||||
options?: {
|
||||
|
|
@ -191,21 +212,23 @@ export async function paypleAuth(
|
|||
body['PCD_PAY_WORK'] = options.payWork
|
||||
}
|
||||
|
||||
const resp = await fetch(`${config.baseUrl}/php/auth.php`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Cache-Control': 'no-cache',
|
||||
'Referer': getReferer(config),
|
||||
},
|
||||
body: JSON.stringify(body),
|
||||
})
|
||||
const resp = await postPaypleJson(config, `${config.baseUrl}/php/auth.php`, body)
|
||||
|
||||
if (!resp.ok) {
|
||||
await resp.body?.cancel().catch(() => undefined)
|
||||
throw new Error(`Payple auth failed: HTTP ${resp.status}`)
|
||||
}
|
||||
|
||||
const data = await resp.json() as Record<string, string>
|
||||
let rawData: unknown
|
||||
try {
|
||||
rawData = await resp.json()
|
||||
} catch {
|
||||
throw new PaypleVerificationError('payple_auth_invalid_response')
|
||||
}
|
||||
if (!rawData || typeof rawData !== 'object' || Array.isArray(rawData)) {
|
||||
throw new PaypleVerificationError('payple_auth_invalid_response')
|
||||
}
|
||||
const data = rawData as Record<string, string>
|
||||
if (data['result'] !== 'success') {
|
||||
throw new Error(`Payple auth error: ${data['result_msg'] ?? data['cst_id'] ?? 'unknown'}`)
|
||||
}
|
||||
|
|
@ -245,14 +268,10 @@ export async function paypleBilling(
|
|||
|
||||
let resp: Response
|
||||
try {
|
||||
resp = await fetch(billingUrl, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Cache-Control': 'no-cache',
|
||||
'Referer': getReferer(config),
|
||||
},
|
||||
body: JSON.stringify({
|
||||
resp = await postPaypleJson(
|
||||
config,
|
||||
billingUrl,
|
||||
{
|
||||
PCD_CST_ID: auth.PCD_CST_ID,
|
||||
PCD_CUST_KEY: auth.PCD_CUST_KEY,
|
||||
PCD_AUTH_KEY: auth.PCD_AUTH_KEY,
|
||||
|
|
@ -262,19 +281,25 @@ export async function paypleBilling(
|
|||
PCD_PAY_TOTAL: String(params.amount),
|
||||
PCD_PAY_OID: params.orderId,
|
||||
PCD_SIMPLE_FLAG: 'Y',
|
||||
}),
|
||||
})
|
||||
},
|
||||
PAYPLE_BILLING_TIMEOUT_MS,
|
||||
)
|
||||
} catch {
|
||||
throw new PaypleBillingError('payple_billing_transport_unknown', false)
|
||||
}
|
||||
|
||||
if (!resp.ok) {
|
||||
await resp.body?.cancel().catch(() => undefined)
|
||||
throw new PaypleBillingError('payple_billing_http_unknown', false)
|
||||
}
|
||||
|
||||
let data: PaypleBillingResult
|
||||
try {
|
||||
data = await resp.json() as PaypleBillingResult
|
||||
const parsed = await resp.json() as unknown
|
||||
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
||||
throw new Error('non_object')
|
||||
}
|
||||
data = parsed as PaypleBillingResult
|
||||
} catch {
|
||||
throw new PaypleBillingError('payple_billing_response_unknown', false)
|
||||
}
|
||||
|
|
@ -296,32 +321,30 @@ export async function paypleCancel(
|
|||
refundTotal: number // 환불 금액
|
||||
}
|
||||
): Promise<PaypleCancelResult> {
|
||||
const resp = await fetch(`${config.baseUrl}/php/account/api/cPayCAct.php`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Cache-Control': 'no-cache',
|
||||
'Referer': getReferer(config),
|
||||
},
|
||||
body: JSON.stringify({
|
||||
PCD_CST_ID: auth.PCD_CST_ID,
|
||||
PCD_CUST_KEY: auth.PCD_CUST_KEY,
|
||||
PCD_AUTH_KEY: auth.PCD_AUTH_KEY,
|
||||
PCD_REFUND_KEY: config.refundKey,
|
||||
PCD_PAYCANCEL_FLAG: 'Y',
|
||||
PCD_PAY_OID: params.payOid,
|
||||
PCD_PAY_DATE: params.payDate,
|
||||
PCD_REFUND_TOTAL: String(params.refundTotal),
|
||||
}),
|
||||
const resp = await postPaypleJson(config, `${config.baseUrl}/php/account/api/cPayCAct.php`, {
|
||||
PCD_CST_ID: auth.PCD_CST_ID,
|
||||
PCD_CUST_KEY: auth.PCD_CUST_KEY,
|
||||
PCD_AUTH_KEY: auth.PCD_AUTH_KEY,
|
||||
PCD_REFUND_KEY: config.refundKey,
|
||||
PCD_PAYCANCEL_FLAG: 'Y',
|
||||
PCD_PAY_OID: params.payOid,
|
||||
PCD_PAY_DATE: params.payDate,
|
||||
PCD_REFUND_TOTAL: String(params.refundTotal),
|
||||
})
|
||||
|
||||
if (!resp.ok) {
|
||||
await resp.body?.cancel().catch(() => undefined)
|
||||
throw new Error(`Payple cancel failed: HTTP ${resp.status}`)
|
||||
}
|
||||
|
||||
const data = await resp.json() as PaypleCancelResult
|
||||
if (data.PCD_PAY_RST !== 'success') {
|
||||
throw new Error(`Payple cancel error: ${data.PCD_PAY_MSG} (${data.PCD_PAY_CODE})`)
|
||||
let data: PaypleCancelResult
|
||||
try {
|
||||
data = await resp.json() as PaypleCancelResult
|
||||
} catch {
|
||||
throw new Error('Payple cancel returned invalid JSON')
|
||||
}
|
||||
if (!data || typeof data !== 'object' || data.PCD_PAY_RST !== 'success') {
|
||||
throw new Error(`Payple cancel error: ${data?.PCD_PAY_MSG ?? 'unknown'} (${data?.PCD_PAY_CODE ?? 'unknown'})`)
|
||||
}
|
||||
|
||||
return data
|
||||
|
|
@ -337,28 +360,26 @@ export async function paypleDeleteBillingKey(
|
|||
const host = getPaypleApiUrl(config, auth.PCD_PAY_HOST, '/')
|
||||
const url = new URL('/php/cPayUser/api/cPayUserAct.php?ACT_=PUSERDEL', host).toString()
|
||||
|
||||
const resp = await fetch(url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Cache-Control': 'no-cache',
|
||||
'Referer': getReferer(config),
|
||||
},
|
||||
body: JSON.stringify({
|
||||
PCD_CST_ID: auth.PCD_CST_ID,
|
||||
PCD_CUST_KEY: auth.PCD_CUST_KEY,
|
||||
PCD_AUTH_KEY: auth.PCD_AUTH_KEY,
|
||||
PCD_PAYER_ID: payerId,
|
||||
}),
|
||||
const resp = await postPaypleJson(config, url, {
|
||||
PCD_CST_ID: auth.PCD_CST_ID,
|
||||
PCD_CUST_KEY: auth.PCD_CUST_KEY,
|
||||
PCD_AUTH_KEY: auth.PCD_AUTH_KEY,
|
||||
PCD_PAYER_ID: payerId,
|
||||
})
|
||||
|
||||
if (!resp.ok) {
|
||||
await resp.body?.cancel().catch(() => undefined)
|
||||
throw new Error(`Payple delete billing key failed: HTTP ${resp.status}`)
|
||||
}
|
||||
|
||||
const data = await resp.json() as { PCD_PAY_RST: string; PCD_PAY_MSG?: string }
|
||||
if (data.PCD_PAY_RST !== 'success') {
|
||||
throw new Error(`Payple delete billing key error: ${data.PCD_PAY_MSG ?? 'unknown'}`)
|
||||
let data: { PCD_PAY_RST?: string; PCD_PAY_MSG?: string }
|
||||
try {
|
||||
data = await resp.json() as { PCD_PAY_RST?: string; PCD_PAY_MSG?: string }
|
||||
} catch {
|
||||
throw new Error('Payple delete billing key returned invalid JSON')
|
||||
}
|
||||
if (!data || typeof data !== 'object' || data.PCD_PAY_RST !== 'success') {
|
||||
throw new Error(`Payple delete billing key error: ${data?.PCD_PAY_MSG ?? 'unknown'}`)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -390,14 +411,9 @@ export async function paypleLookupPayment(
|
|||
auth.PCD_PAY_URL,
|
||||
'/php/PayChkAct.php',
|
||||
)
|
||||
const resp = await fetch(lookupUrl, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Cache-Control': 'no-cache',
|
||||
'Referer': getReferer(config),
|
||||
},
|
||||
body: JSON.stringify({
|
||||
let resp: Response
|
||||
try {
|
||||
resp = await postPaypleJson(config, lookupUrl, {
|
||||
PCD_CST_ID: auth.PCD_CST_ID,
|
||||
PCD_CUST_KEY: auth.PCD_CUST_KEY,
|
||||
PCD_AUTH_KEY: auth.PCD_AUTH_KEY,
|
||||
|
|
@ -405,13 +421,25 @@ export async function paypleLookupPayment(
|
|||
PCD_PAY_TYPE: params.payType,
|
||||
PCD_PAY_OID: params.orderId,
|
||||
PCD_PAY_DATE: params.payDate,
|
||||
}),
|
||||
})
|
||||
})
|
||||
} catch {
|
||||
throw new PaypleVerificationError('payple_lookup_transport_failed')
|
||||
}
|
||||
|
||||
if (!resp.ok) {
|
||||
await resp.body?.cancel().catch(() => undefined)
|
||||
throw new PaypleVerificationError(`payple_lookup_http_${resp.status}`)
|
||||
}
|
||||
const data = await resp.json() as PayplePaymentLookupResult
|
||||
let data: PayplePaymentLookupResult
|
||||
try {
|
||||
const parsed = await resp.json() as unknown
|
||||
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
||||
throw new Error('non_object')
|
||||
}
|
||||
data = parsed as PayplePaymentLookupResult
|
||||
} catch {
|
||||
throw new PaypleVerificationError('payple_lookup_invalid_response')
|
||||
}
|
||||
if (
|
||||
data.PCD_PAY_RST !== 'success'
|
||||
|| data.PCD_PAY_CODE !== 'PCHK0000'
|
||||
|
|
@ -433,24 +461,30 @@ export async function paypleLookupBillingKey(
|
|||
}
|
||||
const host = getPaypleApiUrl(config, auth.PCD_PAY_HOST, '/')
|
||||
const url = new URL('/php/cPayUser/api/cPayUserAct.php?ACT_=PUSERINFO', host).toString()
|
||||
const resp = await fetch(url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Cache-Control': 'no-cache',
|
||||
'Referer': getReferer(config),
|
||||
},
|
||||
body: JSON.stringify({
|
||||
let resp: Response
|
||||
try {
|
||||
resp = await postPaypleJson(config, url, {
|
||||
PCD_CST_ID: auth.PCD_CST_ID,
|
||||
PCD_CUST_KEY: auth.PCD_CUST_KEY,
|
||||
PCD_AUTH_KEY: auth.PCD_AUTH_KEY,
|
||||
PCD_PAYER_ID: payerId,
|
||||
}),
|
||||
})
|
||||
})
|
||||
} catch {
|
||||
throw new PaypleVerificationError('payple_billing_key_lookup_transport_failed')
|
||||
}
|
||||
if (!resp.ok) {
|
||||
await resp.body?.cancel().catch(() => undefined)
|
||||
throw new PaypleVerificationError(`payple_billing_key_lookup_http_${resp.status}`)
|
||||
}
|
||||
return await resp.json() as PaypleBillingKeyLookupResult
|
||||
try {
|
||||
const parsed = await resp.json() as unknown
|
||||
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
||||
throw new Error('non_object')
|
||||
}
|
||||
return parsed as PaypleBillingKeyLookupResult
|
||||
} catch {
|
||||
throw new PaypleVerificationError('payple_billing_key_lookup_invalid_response')
|
||||
}
|
||||
}
|
||||
|
||||
export function parsePaypleTimestamp(value: string): Date {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue