web-next: /restore-items cobra por SumUp (1€/ítem) en vez de PD
- Nuevo servicio de pago `restore-item` (getRestoreItemPrice default 1€, fulfill SOAP `.item restore <recover_id> <char>`). Al pulsar "Recuperar" se crea un checkout de SumUp y al pagar se ejecuta el restore. - Se quita el descuento de 100 PD y el gate "No tienes PD suficientes". - La búsqueda sigue igual (gratis, cooldown 8h, Turnstile). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -3,8 +3,7 @@ import { setRequestLocale } from 'next-intl/server'
|
||||
import { redirect } from '@/i18n/navigation'
|
||||
import { getSession } from '@/lib/session'
|
||||
import { getGameCharacters } from '@/lib/characters'
|
||||
import { getDPointsBalance } from '@/lib/dpoints'
|
||||
import { RESTORE_ITEM_PD } from '@/lib/restore-items'
|
||||
import { getRestoreItemPrice } from '@/lib/prices'
|
||||
import { PageShell } from '@/components/PageShell'
|
||||
import { ServiceBox } from '@/components/ServiceBox'
|
||||
import { RestoreItemsForm } from '@/components/RestoreItemsForm'
|
||||
@@ -21,7 +20,7 @@ export default async function RestoreItemsPage({ params }: { params: Promise<{ l
|
||||
if (!session.bnetId) redirect({ href: '/login', locale })
|
||||
if (!session.username) redirect({ href: '/select-account', locale })
|
||||
|
||||
const [chars, balance] = await Promise.all([getGameCharacters(session.accountId!), getDPointsBalance(session.accountId!)])
|
||||
const [chars, price] = await Promise.all([getGameCharacters(session.accountId!), getRestoreItemPrice()])
|
||||
|
||||
return (
|
||||
<PageShell title="Recuperar ítems">
|
||||
@@ -51,12 +50,9 @@ export default async function RestoreItemsPage({ params }: { params: Promise<{ l
|
||||
<div className="centered">
|
||||
<br />
|
||||
<br />
|
||||
<p>Cada ítem requiere <span>{RESTORE_ITEM_PD}</span> <span className="yellow-info">PD</span></p>
|
||||
<p>Cada ítem requiere <span>{price}</span> <span className="yellow-info">€</span> (SumUp)</p>
|
||||
<br />
|
||||
<RestoreItemsForm
|
||||
characters={chars.map((c) => ({ name: c.name, classCss: c.classCss }))}
|
||||
canAfford={balance >= RESTORE_ITEM_PD}
|
||||
/>
|
||||
<RestoreItemsForm characters={chars.map((c) => ({ name: c.name, classCss: c.classCss }))} price={price} />
|
||||
</div>
|
||||
</ServiceBox>
|
||||
</PageShell>
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
import { getSession } from '@/lib/session'
|
||||
import { restoreItem } from '@/lib/restore-items'
|
||||
|
||||
/** Restaura un ítem borrado (cuesta 100 PD). */
|
||||
export async function POST(request: Request) {
|
||||
const session = await getSession()
|
||||
if (!session.accountId || !session.username) {
|
||||
return Response.json({ success: false, error: 'notAuthenticated' }, { status: 401 })
|
||||
}
|
||||
let body: Record<string, unknown> = {}
|
||||
try {
|
||||
body = await request.json()
|
||||
} catch {
|
||||
return Response.json({ success: false, error: 'invalidRequest' }, { status: 400 })
|
||||
}
|
||||
return Response.json(await restoreItem(session.accountId, String(body.character ?? '').trim(), Number(body.recoverId)))
|
||||
}
|
||||
@@ -32,7 +32,7 @@ function itemsError(error?: string, minutes?: number): string {
|
||||
}
|
||||
}
|
||||
|
||||
export function RestoreItemsForm({ characters, canAfford }: { characters: CharOption[]; canAfford: boolean }) {
|
||||
export function RestoreItemsForm({ characters, price }: { characters: CharOption[]; price: number }) {
|
||||
const [character, setCharacter] = useState('')
|
||||
const [captcha, setCaptcha] = useState('')
|
||||
const [captchaKey, setCaptchaKey] = useState(0)
|
||||
@@ -40,14 +40,6 @@ export function RestoreItemsForm({ characters, canAfford }: { characters: CharOp
|
||||
const [items, setItems] = useState<DeletedItem[] | null>(null)
|
||||
const [message, setMessage] = useState<{ ok: boolean; text: string } | null>(null)
|
||||
|
||||
if (!canAfford) {
|
||||
return (
|
||||
<div id="char-selection">
|
||||
<span>No tienes PD suficientes</span>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
async function search(e: React.FormEvent<HTMLFormElement>) {
|
||||
e.preventDefault()
|
||||
if (busy || !character) return
|
||||
@@ -78,26 +70,25 @@ export function RestoreItemsForm({ characters, canAfford }: { characters: CharOp
|
||||
|
||||
async function restore(item: DeletedItem) {
|
||||
if (busy) return
|
||||
if (!window.confirm(`¿Recuperar "${item.name}" por 100 PD?`)) return
|
||||
if (!window.confirm(`¿Recuperar "${item.name}" por ${price} € (SumUp)?`)) return
|
||||
setBusy(true)
|
||||
setMessage(null)
|
||||
try {
|
||||
const res = await fetch('/api/character/restore-items/restore', {
|
||||
const res = await fetch('/api/character/restore-item/checkout', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
credentials: 'same-origin',
|
||||
body: JSON.stringify({ character, recoverId: item.recoverId }),
|
||||
body: JSON.stringify({ character, recover_id: String(item.recoverId), provider: 'sumup' }),
|
||||
})
|
||||
const data: { success?: boolean; error?: string } = await res.json()
|
||||
if (data.success) {
|
||||
setItems((prev) => (prev ? prev.filter((i) => i.recoverId !== item.recoverId) : prev))
|
||||
setMessage({ ok: true, text: `¡"${item.name}" recuperado! Se han descontado 100 PD.` })
|
||||
} else {
|
||||
setMessage({ ok: false, text: itemsError(data.error) })
|
||||
const data: { success?: boolean; url?: string; error?: string; message?: string } = await res.json()
|
||||
if (data.success && data.url) {
|
||||
window.location.assign(data.url) // checkout de SumUp
|
||||
return
|
||||
}
|
||||
setMessage({ ok: false, text: data.message || itemsError(data.error) })
|
||||
setBusy(false)
|
||||
} catch {
|
||||
setMessage({ ok: false, text: itemsError() })
|
||||
} finally {
|
||||
setBusy(false)
|
||||
}
|
||||
}
|
||||
@@ -139,7 +130,7 @@ export function RestoreItemsForm({ characters, canAfford }: { characters: CharOp
|
||||
</td>
|
||||
<td className="real-info-box">
|
||||
<button type="button" className="restore-item-button" value={it.recoverId} data-char={character} onClick={() => restore(it)} disabled={busy}>
|
||||
Recuperar (100 PD)
|
||||
Recuperar ({price} €)
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
getChangeFactionPrice,
|
||||
getLevelUpPrice,
|
||||
getTransferPrice,
|
||||
getRestoreItemPrice,
|
||||
goldPriceFor,
|
||||
} from './prices'
|
||||
|
||||
@@ -86,6 +87,14 @@ export const PAID_SERVICES: Record<string, PaidServiceConfig> = {
|
||||
fulfill: (c, m) => sendGoldByMail(c, Number(m.gold_amount)),
|
||||
extraFields: ['gold_amount'],
|
||||
},
|
||||
// Recuperar un ítem borrado (por SumUp): al pagar se ejecuta `.item restore`.
|
||||
'restore-item': {
|
||||
price: () => getRestoreItemPrice(),
|
||||
productName: (c, m) => `Recuperar ítem #${m.recover_id} de ${c}`,
|
||||
fulfill: (c, m) =>
|
||||
/^\d+$/.test(String(m.recover_id ?? '')) ? soapFulfill(`.item restore ${m.recover_id} ${c}`) : Promise.resolve(false),
|
||||
extraFields: ['recover_id'],
|
||||
},
|
||||
transfer: {
|
||||
price: () => getTransferPrice(),
|
||||
productName: (c, m) => `Transferir ${c} a la cuenta ${m.destination_account}`,
|
||||
|
||||
@@ -16,6 +16,7 @@ export const getChangeRacePrice = () => priceFrom('home_changeraceprice', 10.0)
|
||||
export const getChangeFactionPrice = () => priceFrom('home_changefactionprice', 10.0)
|
||||
export const getLevelUpPrice = () => priceFrom('home_levelupprice', 10.0)
|
||||
export const getTransferPrice = () => priceFrom('home_transferprice', 10.0)
|
||||
export const getRestoreItemPrice = () => priceFrom('home_restoreitemprice', 1.0)
|
||||
|
||||
export interface GoldOption {
|
||||
gold_amount: number
|
||||
|
||||
@@ -7,11 +7,10 @@ import { getGameCharacters } from './characters'
|
||||
* Recuperar ítems (/restore-items): usa el sistema de recuperación de AzerothCore
|
||||
* por SOAP. `.item restore list <char>` lista los ítems borrados recuperables (el
|
||||
* core aplica las condiciones: calidad Raro+, equipable, se liga al recoger,
|
||||
* borrado < 7 días). `.item restore <recoverId> <char>` restaura uno. Cada
|
||||
* restauración cuesta **100 PD**. La consulta tiene cooldown de 8 h por personaje.
|
||||
* borrado < 7 días). La consulta tiene cooldown de 8 h por personaje. La restauración
|
||||
* de cada ítem se paga por **SumUp** (servicio `restore-item`, ejecuta `.item restore`).
|
||||
*/
|
||||
|
||||
export const RESTORE_ITEM_PD = 100
|
||||
const SEARCH_COOLDOWN_MS = 8 * 60 * 60 * 1000
|
||||
const SAFE_NAME = /^[A-Za-z]{1,12}$/
|
||||
|
||||
@@ -74,39 +73,3 @@ export async function listDeletedItems(accountId: number, character: string): Pr
|
||||
.catch(() => {})
|
||||
return { success: true, items: parseRecoverList(soap) }
|
||||
}
|
||||
|
||||
export interface RestoreResult {
|
||||
success: boolean
|
||||
error?: string
|
||||
name?: string
|
||||
}
|
||||
|
||||
/** Restaura un ítem borrado (cuesta 100 PD; reembolsa si el SOAP falla). */
|
||||
export async function restoreItem(accountId: number, character: string, recoverId: number): Promise<RestoreResult> {
|
||||
if (!(await ownsCharacter(accountId, character))) return { success: false, error: 'characterNotOwned' }
|
||||
if (!Number.isInteger(recoverId) || recoverId <= 0) return { success: false, error: 'invalidRequest' }
|
||||
|
||||
// Cobra 100 PD de forma atómica.
|
||||
let charged = false
|
||||
try {
|
||||
const [res] = await db(DB.default).query(
|
||||
'UPDATE home_api_points SET dp = dp - ? WHERE accountID = ? AND dp >= ?',
|
||||
[RESTORE_ITEM_PD, accountId, RESTORE_ITEM_PD],
|
||||
)
|
||||
// @ts-expect-error affectedRows
|
||||
charged = res.affectedRows === 1
|
||||
} catch {
|
||||
return { success: false, error: 'genericError' }
|
||||
}
|
||||
if (!charged) return { success: false, error: 'insufficientPoints' }
|
||||
|
||||
const soap = await executeSoapCommand(`.item restore ${recoverId} ${character}`)
|
||||
if (soap === null) {
|
||||
await db(DB.default)
|
||||
.query('UPDATE home_api_points SET dp = dp + ? WHERE accountID = ?', [RESTORE_ITEM_PD, accountId])
|
||||
.catch(() => {})
|
||||
return { success: false, error: 'soapError' }
|
||||
}
|
||||
|
||||
return { success: true }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user