Vai al contenuto principale

Introduzione

L’integrazione di Dodo Payments con Slack ti consente di ricevere notifiche in tempo reale sui tuoi pagamenti direttamente nel tuo workspace Slack. Questa integrazione ti permette di rimanere aggiornato sullo stato dei tuoi pagamenti, monitorare le transazioni e gestire i tuoi pagamenti in modo più efficiente.
Questa integrazione utilizza il nostro portale di gestione dei webhook per trasformare automaticamente gli eventi webhook di Dodo Payments in messaggi compatibili con Slack. Non è necessaria alcuna codifica aggiuntiva: basta configurare il connettore e iniziare a ricevere notifiche.

Iniziare

1

Apri la Sezione Webhook

Vai alla sezione Webhook nel tuo dashboard di Dodo Payments. Clicca sul pulsante + Aggiungi Endpoint, quindi apri il menu a discesa dei webhook per rivelare altre integrazioni.
Dashboard di Dodo Payments che mostra il pulsante Aggiungi Endpoint e il menu a discesa delle integrazioni
2

Seleziona l'Integrazione Slack

Seleziona l’integrazione Slack e clicca su Collega il tuo workspace Slack.
Scheda di integrazione Slack e pulsante di collegamento
3

Concedi Permessi a Slack

Concedi i permessi necessari all’app Slack Incoming Webhooks affinché possa inviare messaggi nel tuo canale scelto.
Schermata dei permessi OAuth di Slack per l'app Incoming Webhooks
4

Personalizza il Codice di Trasformazione

Aggiungi o modifica il codice di trasformazione per personalizzare le tue notifiche Slack in base al tuo caso d’uso. Puoi utilizzare i modelli predefiniti o scrivere la tua logica.
Editor del codice di trasformazione per l'integrazione Slack
5

Testa e Crea

Testa il tuo codice di trasformazione con payload di eventi personalizzati o predefiniti. Una volta soddisfatto, clicca su Crea per attivare l’integrazione.
Testa la trasformazione e pulsante di creazione
6

Integrazione Completata!

🎉 Hai creato con successo l’integrazione Slack! I tuoi eventi di Dodo Payments verranno ora consegnati al tuo canale Slack selezionato in tempo reale.

Esempi di Codice di Trasformazione

Notifiche di Pagamento di Base

Questa trasformazione invia messaggi di testo semplici per eventi di pagamento:
payment_notifs.js
function handler(webhook) {
  switch (webhook.eventType) {
    case "payment.succeeded":
      webhook.payload = {
        text: `✅ Payment Successful\nAmount: $${(webhook.payload.data.total_amount / 100).toFixed(2)}\nCustomer: ${webhook.payload.data.customer.email}\nPayment ID: ${webhook.payload.data.payment_id}`
      };
      break;
      
    case "payment.failed":
      webhook.payload = {
        text: `❌ Payment Failed\nAmount: $${(webhook.payload.data.total_amount / 100).toFixed(2)}\nCustomer: ${webhook.payload.data.customer.email}\nReason: ${webhook.payload.data.error_message || 'Unknown'}`
      };
      break;
      
    case "payment.processing":
      webhook.payload = {
        text: `⏳ Payment Processing\nAmount: $${(webhook.payload.data.total_amount / 100).toFixed(2)}\nCustomer: ${webhook.payload.data.customer.email}`
      };
      break;
  }

  return webhook;
}

Notifiche di Abbonamento Ricche

Questa trasformazione crea messaggi Slack ricchi con allegati per eventi di abbonamento:
subscription_notifs.js
function handler(webhook) {
  switch (webhook.eventType) {
    case "subscription.active":
      webhook.payload = {
        attachments: [{
          color: "good",
          title: "🎉 Subscription Activated",
          fields: [
            {
              title: "Customer",
              value: webhook.payload.data.customer.email,
              short: true
            },
            {
              title: "Product ID",
              value: webhook.payload.data.product_id,
              short: true
            },
            {
              title: "Amount",
              value: `$${(webhook.payload.data.recurring_pre_tax_amount / 100).toFixed(2)}/${webhook.payload.data.payment_frequency_interval}`,
              short: true
            },
            {
              title: "Next Billing",
              value: new Date(webhook.payload.data.next_billing_date).toLocaleDateString(),
              short: true
            }
          ],
          footer: "Dodo Payments",
          ts: Math.floor(new Date(webhook.payload.timestamp).getTime() / 1000)
        }]
      };
      break;
      
    case "subscription.cancelled":
      webhook.payload = {
        attachments: [{
          color: "warning",
          title: "⚠️ Subscription Cancelled",
          fields: [
            {
              title: "Customer",
              value: webhook.payload.data.customer.email,
              short: true
            },
            {
              title: "Product ID",
              value: webhook.payload.data.product_id,
              short: true
            },
            {
              title: "Cancellation Date",
              value: new Date(webhook.payload.data.cancelled_at).toLocaleDateString(),
              short: true
            },
            {
              title: "Cancel at Next Billing",
              value: webhook.payload.data.cancel_at_next_billing_date ? "Yes" : "No",
              short: true
            }
          ],
          footer: "Dodo Payments",
          ts: Math.floor(new Date(webhook.payload.timestamp).getTime() / 1000)
        }]
      };
      break;
      
    case "subscription.renewed":
      webhook.payload = {
        attachments: [{
          color: "good",
          title: "🔄 Subscription Renewed",
          fields: [
            {
              title: "Customer",
              value: webhook.payload.data.customer.email,
              short: true
            },
            {
              title: "Product ID",
              value: webhook.payload.data.product_id,
              short: true
            },
            {
              title: "Amount",
              value: `$${(webhook.payload.data.recurring_pre_tax_amount / 100).toFixed(2)}`,
              short: true
            },
            {
              title: "Next Billing",
              value: new Date(webhook.payload.data.next_billing_date).toLocaleDateString(),
              short: true
            }
          ],
          footer: "Dodo Payments",
          ts: Math.floor(new Date(webhook.payload.timestamp).getTime() / 1000)
        }]
      };
      break;
  }

  return webhook;
}

Notifiche di Gestione delle Controversie

Questa trasformazione gestisce eventi di controversia con colori e urgenza appropriati:
dispute_notifs.js
function handler(webhook) {
  switch (webhook.eventType) {
    case "dispute.opened":
      webhook.payload = {
        attachments: [{
          color: "danger",
          title: "🚨 New Dispute Opened",
          fields: [
            {
              title: "Payment ID",
              value: webhook.payload.data.payment_id,
              short: true
            },
            {
              title: "Amount",
              value: `$${(webhook.payload.data.amount / 100).toFixed(2)}`,
              short: true
            },
            {
              title: "Status",
              value: webhook.payload.data.dispute_status,
              short: true
            },
            {
              title: "Stage",
              value: webhook.payload.data.dispute_stage,
              short: true
            },
            {
              title: "Remarks",
              value: webhook.payload.data.remarks || "No remarks",
              short: false
            }
          ],
          footer: "Dodo Payments - Action Required",
          ts: Math.floor(new Date(webhook.payload.timestamp).getTime() / 1000)
        }]
      };
      break;
      
    case "dispute.won":
      webhook.payload = {
        attachments: [{
          color: "good",
          title: "✅ Dispute Won",
          fields: [
            {
              title: "Payment ID",
              value: webhook.payload.data.payment_id,
              short: true
            },
            {
              title: "Amount",
              value: `$${(webhook.payload.data.amount / 100).toFixed(2)}`,
              short: true
            },
            {
              title: "Status",
              value: webhook.payload.data.dispute_status,
              short: true
            },
            {
              title: "Resolution",
              value: "Dispute resolved in your favor",
              short: false
            }
          ],
          footer: "Dodo Payments",
          ts: Math.floor(new Date(webhook.payload.timestamp).getTime() / 1000)
        }]
      };
      break;
      
    case "dispute.lost":
      webhook.payload = {
        attachments: [{
          color: "danger",
          title: "❌ Dispute Lost",
          fields: [
            {
              title: "Payment ID",
              value: webhook.payload.data.payment_id,
              short: true
            },
            {
              title: "Amount",
              value: `$${(webhook.payload.data.amount / 100).toFixed(2)}`,
              short: true
            },
            {
              title: "Status",
              value: webhook.payload.data.dispute_status,
              short: true
            },
            {
              title: "Impact",
              value: "Funds will be debited from your account",
              short: false
            }
          ],
          footer: "Dodo Payments - Review Required",
          ts: Math.floor(new Date(webhook.payload.timestamp).getTime() / 1000)
        }]
      };
      break;
  }

  return webhook;
}

Gestore Completo di Tutti gli Eventi

Questa trasformazione gestisce tutti i tipi di eventi con formattazione coerente:
all_events_notifs.js
function handler(webhook) {
  const event = webhook.payload.data;
  const timestamp = new Date(webhook.payload.timestamp).toLocaleString();
  
  let color, emoji, title, fields = [];
  
  switch (webhook.eventType) {
    case "payment.succeeded":
      color = "good";
      emoji = "✅";
      title = "Payment Successful";
      fields = [
        { title: "Amount", value: `$${(event.total_amount / 100).toFixed(2)}`, short: true },
        { title: "Customer", value: event.customer.email, short: true },
        { title: "Payment ID", value: event.payment_id, short: true },
        { title: "Method", value: event.payment_method || "Unknown", short: true }
      ];
      break;
      
    case "payment.failed":
      color = "danger";
      emoji = "❌";
      title = "Payment Failed";
      fields = [
        { title: "Amount", value: `$${(event.total_amount / 100).toFixed(2)}`, short: true },
        { title: "Customer", value: event.customer.email, short: true },
        { title: "Reason", value: event.error_message || "Unknown", short: false }
      ];
      break;
      
    case "subscription.active":
      color = "good";
      emoji = "🎉";
      title = "Subscription Activated";
      fields = [
        { title: "Customer", value: event.customer.email, short: true },
        { title: "Product ID", value: event.product_id, short: true },
        { title: "Amount", value: `$${(event.recurring_pre_tax_amount / 100).toFixed(2)}/${event.payment_frequency_interval}`, short: true },
        { title: "Next Billing", value: new Date(event.next_billing_date).toLocaleDateString(), short: true }
      ];
      break;
      
    case "subscription.cancelled":
      color = "warning";
      emoji = "⚠️";
      title = "Subscription Cancelled";
      fields = [
        { title: "Customer", value: event.customer.email, short: true },
        { title: "Product ID", value: event.product_id, short: true },
        { title: "Cancellation Date", value: new Date(event.cancelled_at).toLocaleDateString(), short: true },
        { title: "Cancel at Next Billing", value: event.cancel_at_next_billing_date ? "Yes" : "No", short: true }
      ];
      break;
      
    case "refund.succeeded":
      color = "good";
      emoji = "💰";
      title = "Refund Processed";
      fields = [
        { title: "Amount", value: `$${(event.amount / 100).toFixed(2)}`, short: true },
        { title: "Refund ID", value: event.refund_id, short: true },
        { title: "Payment ID", value: event.payment_id, short: true },
        { title: "Reason", value: event.reason || "Not specified", short: true }
      ];
      break;
      
    case "dispute.opened":
      color = "danger";
      emoji = "🚨";
      title = "New Dispute Opened";
      fields = [
        { title: "Payment ID", value: event.payment_id, short: true },
        { title: "Amount", value: `$${(event.amount / 100).toFixed(2)}`, short: true },
        { title: "Status", value: event.dispute_status, short: true },
        { title: "Stage", value: event.dispute_stage, short: true },
        { title: "Remarks", value: event.remarks || "No remarks", short: false }
      ];
      break;
      
    case "license_key.created":
      color = "good";
      emoji = "🔑";
      title = "License Key Created";
      fields = [
        { title: "License ID", value: event.id, short: true },
        { title: "Product ID", value: event.product_id, short: true },
        { title: "License Key", value: event.key.substring(0, 8) + "...", short: true },
        { title: "Expires", value: event.expires_at ? new Date(event.expires_at).toLocaleDateString() : "Never", short: true }
      ];
      break;
      
    default:
      // Handle any other events with a generic format
      color = "warning";
      emoji = "ℹ️";
      title = webhook.eventType.replace(/_/g, ' ').replace(/\b\w/g, l => l.toUpperCase());
      fields = [
        { title: "Event Type", value: webhook.eventType, short: true },
        { title: "Timestamp", value: timestamp, short: true }
      ];
  }
  
  webhook.payload = {
    attachments: [{
      color: color,
      title: `${emoji} ${title}`,
      fields: fields,
      footer: "Dodo Payments",
      ts: Math.floor(new Date(webhook.payload.timestamp).getTime() / 1000)
    }]
  };

  return webhook;
}

Migliori Pratiche

Per rendere efficaci le tue notifiche Slack:
  • Utilizza allegati di messaggi ricchi con colori, campi e formattazione per chiarezza e azionabilità.
  • Includi sempre dati chiave come importi, email dei clienti e ID per un’identificazione rapida.
  • Scegli colori che corrispondano al tipo di evento: verde (good) per il successo, rosso (danger) per controversie o fallimenti, giallo (warning) per cancellazioni e blu (#36a64f) per eventi informativi.
  • Aggiungi timestamp per aiutare a tracciare quando si è verificato ciascun evento.
Gestisci Dati Sensibili: Fai attenzione a non includere informazioni sensibili come chiavi di licenza complete o dati personali nei messaggi Slack. Considera di troncare o mascherare valori sensibili.

Risoluzione dei Problemi

  • Verifica che l’URL del webhook di Slack sia corretto e attivo
  • Controlla che il codice di trasformazione sia un JavaScript valido
  • Assicurati che i tipi di eventi selezionati siano attivati
  • Verifica che la tua app Slack abbia i permessi necessari
  • Controlla il portale di gestione dei webhook per i log degli errori di trasformazione
  • Verifica che la struttura del payload del webhook corrisponda al tuo codice di trasformazione
  • Testa il tuo codice di trasformazione con dati di esempio
  • Assicurati che tutti i campi richiesti siano presenti nel payload del webhook
  • Conferma che gli eventi che desideri ricevere siano abilitati nella tua configurazione del webhook di Dodo Payments
  • Controlla che i tipi di eventi siano selezionati nella configurazione del connettore Slack
  • Verifica che il tuo endpoint sia configurato correttamente per ricevere gli eventi