Overview
Aktivasi subscription terjadi saat admin menandai payment sebagai paid di Admin Dazo. Ini memicu serangkaian update: hitung expiry, merge features, update store status, sync covendor/CRM.
Flow Diagram
Admin klik "Paid" di Order/Payment page
│
▼
┌─────────────────────┐
│ 1. Validasi Payment │ ← Cek invoice + payment exists
└─────────┬───────────┘
│
▼
┌─────────────────────┐
│ 2. Hitung Expiry │ ← Parse duration "N Month|Year|Day"
│ (dari Package) │ × quantity dari invoice.plan
└─────────┬───────────┘
│
▼
┌─────────────────────┐
│ 3. Extend Expiry │ ← Jika same plan, extend dari expiry lama
│ (jika perlu) │ Jika beda plan, reset dari sekarang
└─────────┬───────────┘
│
▼
┌─────────────────────┐
│ 4. Merge Features │ ← package.features + addon.features
│ ke Store │ → store.features (array merge)
└─────────┬───────────┘
│
▼
┌─────────────────────┐
│ 5. Update Store │ ← status = 'active', plan, addon_plan,
│ │ expired_at, invoice_id
└─────────┬───────────┘
│
▼
┌─────────────────────┐
│ 6. Sync Covendor │ ← Update CovendorUser status (jika ada)
│ & CRM │ Aktivasi CRM workspace (jika addon CRM)
└─────────┬───────────┘
│
▼
┌─────────────────────┐
│ 7. Update Invoice │ ← status = 'paid', paid_at
│ & Payment │
└─────────────────────┘Detail Implementasi
File Utama
| File | Method | Peran |
|---|---|---|
OrderController.php | updatePayment($id) | Aktivasi dari halaman Order |
PaymentController.php | updatePayment($id) | Aktivasi dari halaman Payment |
CovendorOrderController.php | updatePayment($id) | Aktivasi covendor order |
CovendorPaymentController.php | updatePayment($id) | Aktivasi covendor payment |
Expiry Calculation
$duration = explode(' ', $package->duration); // ["1", "Month"]
$d_value = (int) $duration[0];
$d_satuan = $duration[1];
// Multiply by quantity
$quantity = $invoice->plan; // 1, 2, 3, ...
$total_months = $d_value * $quantity;
// Check if same plan → extend, else → reset
if ($store->plan === $package->name && $store->expired_at > now()) {
$expired_at = Carbon::parse($store->expired_at)->addMonths($total_months);
} else {
$expired_at = Carbon::now()->addMonths($total_months);
}Feature Merge
$package_features = $package->features ?? [];
$addon_features = [];
foreach ($invoice->addon_invoices as $addon_invoice) {
$addon = Addon::find($addon_invoice->addon_id);
if ($addon) {
$addon_features = array_merge($addon_features, $addon->features ?? []);
}
}
$store->features = array_unique(array_merge($package_features, $addon_features));Rollback (Unpaid)
Saat payment di-flip kembali ke unpaid:
- Cari invoice sebelumnya untuk store yang sama
- Ambil package dari invoice tersebut (
getRollbackPackage) - Restore store ke package sebelumnya
- Kurangi expiry sesuai durasi yang sudah di-add
- Revert CovendorUser status
- Revert CRM workspace status
Covendor Sync
Jika store terdaftar via covendor:
$covendorUser = CovendorUser::where('nohp', 'like', '%' . $user->wa . '%')->first();
if ($covendorUser) {
$covendorUser->status = 'active';
$covendorUser->save();
}CRM Activation
Jika invoice mengandung addon CRM:
CrmController::update_status()dipanggil- Buat
CrmWorkspacedi koneksicrm - Buat
CrmUserdi koneksicrm - Buat
CrmUserWorkspace(pivot) - Set
AddonStoreactive - Workspace expiry = +1 tahun