Kembali ke Dashboard | API Docs QRIS
Buka Panduan WordPress & WooCommerce →
GOOGLE APPS SCRIPT & SHEETS INTEGRATION

Integrasi Zy-Pay di Google Apps Script & Sheets

Panduan lengkap otomatisasi pembuatan tagihan QRIS dan update status pembayaran LUNAS langsung di baris Google Sheets secara otomatis.

1. Bagaimana Alur Kerjanya? Apakah via Link Pembayaran?

Sangat mudah! Di Google Apps Script, alurnya adalah membuat tagihan via API, lalu memberikan Link Pembayaran resmi (public_payment_url) kepada pelanggan.

1

Order di Google Sheet

Data pelanggan dimasukkan ke Google Sheet (bisa dari Google Form atau input manual).

2

Klik "Buat Tagihan"

Script menjalankan UrlFetchApp.fetch() ke API Zy-Pay dan memperoleh public_payment_url.

3

Kirim Link ke Pembeli

Link pembayaran otomatis tertulis di Google Sheet dan bisa otomatis terkirim via WhatsApp / Email.

4

Auto Update LUNAS

Saat QRIS discan dan terbayar, Zy-Pay menembak Webhook ke Web App Apps Script, dan status baris Sheet otomatis jadi LUNAS.

Kelebihan Menggunakan Apps Script + Zy-Pay:
  • Tidak butuh sewa server/hosting! Google Apps Script berjalan 100% gratis di cloud Google.
  • Halaman pembayaran resmi Zy-Pay sudah dilengkapi pengecekan otomatis (auto-detect) sehingga pembeli tidak perlu kirim struk bukti transfer.

2. Rekomendasi Struktur Kolom di Google Sheets

Buka Google Sheets baru, dan buat judul kolom pada baris pertama (Baris 1):

Kolom Nama Kolom Keterangan Contoh Nilai
A ID Pesanan Nomor referensi atau order ORD-1001
B Nama Pelanggan Nama pembeli Budi Santoso
C WhatsApp / Email Kontak pelanggan 081234567890
D Nominal Tagihan Jumlah yang harus dibayar 25000
E Status Pembayaran Diisi otomatis oleh Webhook LUNAS / PENDING
F Link Pembayaran QRIS Diisi otomatis oleh Script https://cutiezy.id/zy-pay/pay.php?id=...
G ID Transaksi Zy-Pay ID referensi sistem untuk audit QRIS20260915123456ABCDEF

3. Script Generator Tagihan QRIS di Apps Script

Buka menu Ekstensi → Apps Script pada Google Sheets Anda, hapus kode lama, lalu paste script berikut:

Code.gs — Generator Tagihan
// KONFIGURASI ZY-PAY
const ZYPAY_CONFIG = {
  apiKey: "ak_your_api_key_di_dashboard_zypay", // Ambil dari menu API Keys QRIS
  createPaymentUrl: "https://cutiezy.id/zy-pay/api/v1/create-payment",
  expiryMinutes: 30, // masa berlaku pembayaran (menit)
  webhookUrl: "https://script.google.com/macros/s/AKfycb.../exec" // URL Web App Anda (diisi setelah Deploy)
};

/**
 * Fungsi utama membuat tagihan QRIS ke Zy-Pay
 */
function createZyPayInvoice(amount, description) {
  const payload = {
    amount: parseInt(amount, 10),
    description: description,
    expiry_minutes: ZYPAY_CONFIG.expiryMinutes,
    webhook_url: ZYPAY_CONFIG.webhookUrl
  };

  const options = {
    method: "post",
    contentType: "application/json",
    headers: {
      "X-API-Key": ZYPAY_CONFIG.apiKey
    },
    payload: JSON.stringify(payload),
    muteHttpExceptions: true
  };

  try {
    const response = UrlFetchApp.fetch(ZYPAY_CONFIG.createPaymentUrl, options);
    const result = JSON.parse(response.getContentText());

    if (result.success && result.data) {
      return {
        success: true,
        transactionId: result.data.transaction_id,
        paymentUrl: result.data.public_payment_url,
        totalAmount: result.data.total_amount,
        expiredAt: result.data.expired_at
      };
    } else {
      return {
        success: false,
        error: result.error || "Gagal membuat tagihan."
      };
    }
  } catch (err) {
    return {
      success: false,
      error: err.toString()
    };
  }
}

5. Webhook Receiver (Update Status LUNAS Otomatis)

Agar saat pembeli scan QRIS, baris di Google Sheets Anda otomatis berubah jadi "LUNAS", kita pasang fungsi doPost(e) di Apps Script.

Code.gs — Webhook doPost(e)
/**
 * Webhook Receiver: Ditembak oleh Zy-Pay saat QRIS dibayar
 */
function doPost(e) {
  try {
    const rawData = e.postData.contents;
    const data = JSON.parse(rawData);

    const trxId = data.transaction_id;
    const status = (data.status || "").toLowerCase();

    if (trxId && status === "paid") {
      const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
      const lastRow = sheet.getLastRow();

      // Cari baris yang memiliki ID Transaksi cocok di Kolom G
      for (let r = 2; r <= lastRow; r++) {
        const rowTrxId = sheet.getRange(r, 7).getValue().toString().trim();

        if (rowTrxId === trxId) {
          // Update Status jadi LUNAS di Kolom E
          const statusCell = sheet.getRange(r, 5);
          statusCell.setValue("LUNAS");
          statusCell.setBackground("#dcfce7"); // Warna hijau muda
          statusCell.setFontColor("#166534");

          // Kirim notifikasi email/WA konfirmasi pembayaran lunas
          const nama = sheet.getRange(r, 2).getValue();
          const kontak = sheet.getRange(r, 3).getValue();
          Logger.log(`Pesanan untuk ${nama} telah LUNAS!`);
          break;
        }
      }
    }

    return ContentService.createTextOutput(JSON.stringify({ status: "success" }))
      .setMimeType(ContentService.MimeType.JSON);

  } catch (error) {
    return ContentService.createTextOutput(JSON.stringify({ status: "error", message: error.toString() }))
      .setMimeType(ContentService.MimeType.JSON);
  }
}

Cara Deploy Web App di Google Apps Script:

  1. Di editor Apps Script, klik tombol biru Deploy → New deployment di kanan atas.
  2. Klik ikon gerigi ⚙️ di samping "Select type", lalu pilih Web app.
  3. Isi deskripsi: Zy-Pay QRIS Webhook.
  4. Pada Execute as: pilih Me (email Anda).
  5. Pada Who has access: pilih Anyone (Wajib, agar server Zy-Pay dapat mengirim data).
  6. Klik Deploy, lalu salin URL Web App yang didapat.
  7. Paste URL tersebut pada variabel webhookUrl di konfigurasi script Anda.

6. Mengirim Link Pembayaran Otomatis via Email & WhatsApp

Anda dapat menambahkan fungsi pengiriman otomatis ke pembeli begitu link pembayaran terbentuk:

Code.gs — Kirim Email & WhatsApp Otomatis
/**
 * Mengirim link tagihan ke email pembeli
 */
function kirimEmailTagihan(email, nama, totalBayar, linkBayar) {
  const subject = `Tagihan Pembayaran QRIS - ${nama}`;
  const htmlBody = `
    <div style="font-family: Arial, sans-serif; padding: 20px; color: #333;">
      <h2 style="color: #21759b;">Halo, ${nama}!</h2>
      <p>Terima kasih atas pesanan Anda. Total tagihan Anda adalah:</p>
      <h3 style="color: #107c41;">Rp ${parseInt(totalBayar, 10).toLocaleString('id-ID')}</h3>
      <p>Silakan klik tombol di bawah untuk membayar melalui QRIS (BCA, Mandiri, GoPay, OVO, ShopeePay, DANA):</p>
      <p>
        <a href="${linkBayar}" style="background: #2563eb; color: #fff; padding: 12px 24px; text-decoration: none; border-radius: 8px; font-weight: bold; display: inline-block;">
          Bayar Sekarang via QRIS →
        </a>
      </p>
      <p style="font-size: 12px; color: #777;">Link ini memiliki batas waktu pembayaran. Harap segera diselesaikan.</p>
    </div>
  `;

  MailApp.sendEmail({
    to: email,
    subject: subject,
    htmlBody: htmlBody
  });
}