Passa al contenuto principale

Stripe Checkout

Se crei Sessioni di pagamento Stripe sul tuo server, devi passare il click_id dal browser al tuo backend e includerlo come client_reference_id durante la creazione della sessione. Selgeo legge questo valore dal webhook Stripe e attribuisce la conversione al partner referente.

Versione API: v1

Implementazione

Passaggio 1: Leggere l'ID clic sul frontend

const clickId = __selgeo.getClickId();

Passaggio 2: Inviare l'ID clic al tuo backend

const clickId = __selgeo.getClickId();

const response = await fetch('/api/create-checkout', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ priceId: 'price_xxx', clickId: clickId }),
});

const { url } = await response.json();
window.location.href = url;

Passaggio 3: Passarlo come client_reference_id

const stripe = require('stripe')('sk_test_YOUR_STRIPE_KEY');

app.post('/api/create-checkout', async (req, res) => {
const { priceId, clickId } = req.body;
const session = await stripe.checkout.sessions.create({
mode: 'subscription',
line_items: [{ price: priceId, quantity: 1 }],
success_url: 'https://tuo-sito.com/success',
cancel_url: 'https://tuo-sito.com/cancel',
client_reference_id: clickId || undefined,
});
res.json({ url: session.url });
});
Passa undefined, non una stringa vuota

Se non c'è click_id, passa undefined (JavaScript), None (Python), o null (PHP). Non passare una stringa vuota.

Passaggi successivi