> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dodopayments.com/llms.txt
> Use this file to discover all available pages before exploring further.

# HubSpot

> Secara otomatis membuat dan memperbarui kontak, perusahaan, dan kesepakatan di HubSpot dari peristiwa Dodo Payments.

## Pendahuluan

Sinkronkan data pembayaran Anda langsung ke HubSpot CRM. Buat kontak dari pembayaran yang berhasil, lacak siklus hidup langganan, dan bangun profil pelanggan yang komprehensif—semuanya dipicu secara otomatis oleh peristiwa Dodo Payments.

<Info>
  Integrasi ini memerlukan akses admin HubSpot untuk mengonfigurasi cakupan OAuth dan izin API.
</Info>

## Memulai

<Steps>
  <Step title="Open the Webhook Section">
    Di dasbor Dodo Payments Anda, pergi ke <b>Webhooks → + Tambah Endpoint</b> dan perluas dropdown integrasi.

    <Frame>
      <img src="https://mintcdn.com/dodopayments/slbAEdrLLwKHfaRf/images/integrations/hubspot.png?fit=max&auto=format&n=slbAEdrLLwKHfaRf&q=85&s=73c4881df63edfb05bd24d804f01caab" alt="Tambah Endpoint dan dropdown integrasi" style={{ maxHeight: '500px', width: 'auto' }} width="1724" height="942" data-path="images/integrations/hubspot.png" />
    </Frame>
  </Step>

  <Step title="Select HubSpot">
    Pilih kartu integrasi <b>HubSpot</b>.
  </Step>

  <Step title="Connect HubSpot">
    Klik <b>Connect to HubSpot</b> dan otorisasi cakupan OAuth yang diperlukan.
  </Step>

  <Step title="Configure Transformation">
    Edit kode transformasi untuk memetakan data pembayaran ke objek CRM HubSpot.
  </Step>

  <Step title="Test & Create">
    Uji dengan payload sampel dan klik <b>Create</b> untuk mengaktifkan sinkronisasi.
  </Step>

  <Step title="Done!">
    🎉 Event pembayaran sekarang akan secara otomatis membuat/memperbarui catatan di CRM HubSpot Anda.
  </Step>
</Steps>

## Contoh Kode Transformasi

### Buat Kontak dari Pembayaran

```javascript create_contact.js icon="js" expandable theme={null}
function handler(webhook) {
  if (webhook.eventType === "payment.succeeded") {
    const p = webhook.payload.data;
    webhook.url = "https://api.hubapi.com/crm/v3/objects/contacts";
    webhook.payload = {
      properties: {
        email: p.customer.email,
        firstname: p.customer.name.split(' ')[0] || '',
        lastname: p.customer.name.split(' ').slice(1).join(' ') || '',
        phone: p.customer.phone || '',
        company: p.customer.company || '',
        amount: (p.total_amount / 100).toString(),
        payment_method: p.payment_method || '',
        currency: p.currency || 'USD'
      }
    };
  }
  return webhook;
}
```

### Perbarui Kontak dengan Langganan

```javascript update_contact.js icon="js" expandable theme={null}
function handler(webhook) {
  if (webhook.eventType === "subscription.active") {
    const s = webhook.payload.data;
    webhook.url = `https://api.hubapi.com/crm/v3/objects/contacts/${s.customer.customer_id}`;
    webhook.method = "PATCH";
    webhook.payload = {
      properties: {
        subscription_status: "active",
        subscription_amount: (s.recurring_pre_tax_amount / 100).toString(),
        subscription_frequency: s.payment_frequency_interval,
        next_billing_date: s.next_billing_date,
        product_id: s.product_id
      }
    };
  }
  return webhook;
}
```

### Buat Kesepakatan dari Pembayaran

```javascript create_deal.js icon="js" expandable theme={null}
function handler(webhook) {
  if (webhook.eventType === "payment.succeeded") {
    const p = webhook.payload.data;
    webhook.url = "https://api.hubapi.com/crm/v3/objects/deals";
    webhook.payload = {
      properties: {
        dealname: `Payment - ${p.customer.email}`,
        amount: (p.total_amount / 100).toString(),
        dealstage: "closedwon",
        closedate: new Date().toISOString(),
        hs_currency: p.currency || "USD"
      },
      associations: [
        {
          to: {
            id: p.customer.customer_id
          },
          types: [
            {
              associationCategory: "HUBSPOT_DEFINED",
              associationTypeId: 3
            }
          ]
        }
      ]
    };
  }
  return webhook;
}
```

## Tips

* Gunakan penjelajah API HubSpot untuk menguji pembuatan objek
* Pemetaan jumlah pembayaran ke bidang mata uang HubSpot
* Sertakan ID pelanggan untuk asosiasi yang tepat
* Atur tahap kesepakatan yang sesuai berdasarkan status pembayaran

## Pemecahan Masalah

<AccordionGroup>
  <Accordion title="Records not created in HubSpot">
    * Verifikasi cakupan OAuth mencakup izin tulis
    * Periksa bahwa properti HubSpot yang diperlukan ada
    * Pastikan email pelanggan valid dan unik
    * Tinjau batas laju API HubSpot
  </Accordion>

  <Accordion title="Transformation errors">
    * Validasi struktur JSON sesuai format API HubSpot
    * Periksa bahwa semua properti yang diperlukan disertakan
    * Pastikan nama properti cocok persis dengan nama bidang HubSpot
  </Accordion>
</AccordionGroup>
