Cara membuat web host manager sendiri V8 fitur Integrasi Pembayaran Otomatis

Me Nime Id
Please wait 0 seconds...
Scroll Down and click on Go to Link for destination
Congrats! Link is Generated

 Oke! Kita tambahkan fitur Integrasi Pembayaran Otomatis ke WHM Custom menggunakan Tripay sebagai payment gateway.

Fitur yang Akan Dibuat:

  • Reseller bisa membeli paket hosting secara otomatis.
  • Pembayaran melalui Tripay (QRIS, OVO, Dana, ShopeePay, dll.).
  • Sistem otomatis aktifkan akun setelah pembayaran berhasil.
  • Admin bisa melihat daftar transaksi & status pembayaran.

1️⃣ Buat Akun di Tripay & Dapatkan API Key

  1. Daftar di Tripay
  2. Dapatkan API Key di menu Pengaturan API.
  3. Simpan API Key untuk digunakan di kode nanti.

2️⃣ Tambahkan Tabel Transaksi di Database

📌 Jalankan SQL ini untuk menyimpan transaksi

CREATE TABLE transactions (
    id INT AUTO_INCREMENT PRIMARY KEY,
    reseller_id INT NOT NULL,
    amount DECIMAL(10,2) NOT NULL,
    payment_method VARCHAR(50) NOT NULL,
    reference VARCHAR(100) UNIQUE NOT NULL,
    status ENUM('pending', 'paid', 'failed') DEFAULT 'pending',
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

📌 Setiap transaksi akan memiliki status: pending, paid, atau failed.


3️⃣ Buat Halaman Pembayaran

📌 File reseller/payment.php

<?php
session_start();
include '../includes/config.php';

if (!isset($_SESSION['reseller_id'])) {
    header("Location: login.php");
    exit;
}

$reseller_id = $_SESSION['reseller_id'];

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $amount = $_POST['amount'];
    $payment_method = $_POST['payment_method'];
    $api_key = "API_KEY_TRIPAY"; // Ganti dengan API Key dari Tripay

    // Generate Reference ID unik
    $reference = "INV-" . time();

    // Simpan transaksi ke database
    $stmt = $conn->prepare("INSERT INTO transactions (reseller_id, amount, payment_method, reference) VALUES (?, ?, ?, ?)");
    $stmt->bind_param("idss", $reseller_id, $amount, $payment_method, $reference);
    $stmt->execute();

    // Kirim permintaan pembayaran ke Tripay
    $curl = curl_init();
    curl_setopt_array($curl, [
        CURLOPT_URL => "https://tripay.co.id/api/transaction/create",
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_POST => true,
        CURLOPT_POSTFIELDS => json_encode([
            'method' => $payment_method,
            'merchant_ref' => $reference,
            'amount' => $amount,
            'customer_name' => "Reseller-$reseller_id",
            'customer_email' => "reseller$@email.com",
        ]),
        CURLOPT_HTTPHEADER => [
            "Authorization: Bearer $api_key",
            "Content-Type: application/json"
        ],
    ]);

    $response = curl_exec($curl);
    curl_close($curl);

    $result = json_decode($response, true);

    if ($result['success']) {
        header("Location: " . $result['data']['checkout_url']);
        exit;
    } else {
        echo "Gagal membuat pembayaran.";
    }
}
?>
<h2>Pilih Paket & Pembayaran</h2>
<form method="post">
    <select name="amount" required>
        <option value="50000">Paket Reseller - 50K</option>
        <option value="100000">Paket Reseller - 100K</option>
    </select>
    <br>
    <select name="payment_method" required>
        <option value="QRIS">QRIS (Dana, OVO, ShopeePay)</option>
        <option value="BANK">Transfer Bank</option>
    </select>
    <br>
    <button type="submit">Bayar Sekarang</button>
</form>

📌 Reseller bisa memilih paket & metode pembayaran, lalu diarahkan ke Tripay!


4️⃣ Buat Webhook untuk Update Status Pembayaran

📌 File tripay_webhook.php

<?php
include 'includes/config.php';

$api_key = "API_KEY_TRIPAY"; // Ganti dengan API Key Tripay

$json = file_get_contents("php://input");
$data = json_decode($json, true);

if ($data['status'] === 'PAID') {
    $reference = $data['merchant_ref'];

    // Update status transaksi
    $stmt = $conn->prepare("UPDATE transactions SET status='paid' WHERE reference=?");
    $stmt->bind_param("s", $reference);
    $stmt->execute();

    // Tambah kuota akun reseller setelah bayar
    $stmt = $conn->prepare("UPDATE resellers SET max_clients = max_clients + 5 WHERE id = (SELECT reseller_id FROM transactions WHERE reference=?)");
    $stmt->bind_param("s", $reference);
    $stmt->execute();
}
?>

📌 Tripay akan mengirim data ke tripay_webhook.php saat pembayaran berhasil!


5️⃣ Tambahkan Webhook di Tripay

  1. Buka Dashboard Tripay → Pengaturan API
  2. Tambahkan URL Webhook:
    https://yourdomain.com/tripay_webhook.php
    
  3. Setel mode "Sandbox" untuk testing.

🔥 Sekarang WHM Custom Sudah Bisa Pembayaran Otomatis!

Reseller bisa bayar via QRIS, OVO, Dana, dll.
Akun otomatis aktif setelah pembayaran berhasil.
Admin bisa melihat daftar transaksi.

Posting Komentar

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.