Ir al contenido

Inicio rápido

El camino más corto desde cero hasta un pago completado. Se asume que ya tiene una clave pública y al menos una wallet de liquidación configurada.

Ventana de terminal
npm install stablezact-pay
import { useState } from 'react';
import { StablezactPayment } from 'stablezact-pay';
import 'stablezact-pay/dist/style.css';
export default function Checkout() {
const [open, setOpen] = useState(false);
return (
<>
<button onClick={() => setOpen(true)}>Pay with crypto</button>
<StablezactPayment
isOpen={open}
onClose={() => setOpen(false)}
publicKey="pk_your_public_key"
apiUrl="https://hub.stablezact.com"
config={{
amount: 49.99,
currency: 'USDC',
customerEmail: 'customer@example.com',
}}
onSuccess={(paymentId, txHash) => {
// The customer has submitted. Do not fulfil here. See step 3.
console.log('submitted', paymentId, txHash);
}}
onError={(error) => console.error(error)}
/>
</>
);
}

¿No usa React? El mismo flujo en JavaScript simple:

const stablezact = new StablezactVanilla({
publicKey: 'pk_your_public_key',
apiUrl: 'https://hub.stablezact.com',
theme: 'light',
});
document.getElementById('payButton').addEventListener('click', () => {
stablezact.open(
{ amount: 49.99, customerEmail: 'customer@example.com', merchantName: 'Your Store' },
{
onSuccess: (paymentId, txHash) => console.log('submitted', paymentId, txHash),
onError: (error) => console.error(error),
}
);
});

Confirme desde su backend, donde el navegador no puede falsificar la respuesta:

Ventana de terminal
curl https://hub.stablezact.com/api/v1/payments/PAYMENT_UUID/status \
-H "X-Public-Key: pk_your_public_key"

Lea outcome:

{ "payment": { "outcome": "paid", "isFinal": true } }

paid significa que el dinero del cliente ha llegado y puede completar el pedido. Los otros dos valores son pending y failed. Esa es toda la regla, y es la misma sin importar cómo haya pagado el cliente.

Mejor aún, deje que se lo avisemos nosotros: consulte Webhooks.