Mhamdans17 commited on
Commit ·
e70dcc5
1
Parent(s): 6fee293
feat: add admin notification for new tenant and save customer info to send WA on webhook success
Browse files- controllers/auth_controller.go +2 -0
- controllers/order_controller.go +4 -2
- models/models.go +2 -0
- services/whatsapp.go +11 -0
controllers/auth_controller.go
CHANGED
|
@@ -337,6 +337,8 @@ func RegisterTenant(c *gin.Context) {
|
|
| 337 |
|
| 338 |
// Kirim Notifikasi OTP via WA secara async agar request HTTP cepat
|
| 339 |
go services.SendOtpWa(req.OwnerPhone, code)
|
|
|
|
|
|
|
| 340 |
|
| 341 |
c.JSON(http.StatusCreated, gin.H{
|
| 342 |
"status": "success",
|
|
|
|
| 337 |
|
| 338 |
// Kirim Notifikasi OTP via WA secara async agar request HTTP cepat
|
| 339 |
go services.SendOtpWa(req.OwnerPhone, code)
|
| 340 |
+
// Kirim Notifikasi ke Admin (085789599065) ada pendaftar baru
|
| 341 |
+
go services.SendNewRegistrationAdminWa("085789599065", req.CompanyName, req.OwnerName, req.OwnerEmail, req.OwnerPhone)
|
| 342 |
|
| 343 |
c.JSON(http.StatusCreated, gin.H{
|
| 344 |
"status": "success",
|
controllers/order_controller.go
CHANGED
|
@@ -498,6 +498,8 @@ func PayTripay(c *gin.Context) {
|
|
| 498 |
order.MidtransOrderID = tripayRes.Data.Reference // Simpan nomor referensi Tripay di midtrans_order_id demi kecocokan DB
|
| 499 |
order.MidtransToken = tripayRes.Data.CheckoutURL // Simpan checkout_url di midtrans_token demi kecocokan DB
|
| 500 |
order.PaymentMethod = "tripay"
|
|
|
|
|
|
|
| 501 |
config.DB.Save(&order)
|
| 502 |
|
| 503 |
// Kembalikan JSON yang kompatibel dengan format respons frontend agar tidak merusak UI kasir
|
|
@@ -608,8 +610,8 @@ func TripayWebhook(c *gin.Context) {
|
|
| 608 |
// Kirim Notifikasi WA struk belanja jika pembayaran berhasil
|
| 609 |
if order.PaymentStatus == "paid" && oldStatus != "paid" {
|
| 610 |
go func() {
|
| 611 |
-
custPhone
|
| 612 |
-
custName
|
| 613 |
if custName == "" {
|
| 614 |
custName = "Customer"
|
| 615 |
}
|
|
|
|
| 498 |
order.MidtransOrderID = tripayRes.Data.Reference // Simpan nomor referensi Tripay di midtrans_order_id demi kecocokan DB
|
| 499 |
order.MidtransToken = tripayRes.Data.CheckoutURL // Simpan checkout_url di midtrans_token demi kecocokan DB
|
| 500 |
order.PaymentMethod = "tripay"
|
| 501 |
+
order.CustomerName = req.CustomerName
|
| 502 |
+
order.CustomerPhone = req.CustomerPhone
|
| 503 |
config.DB.Save(&order)
|
| 504 |
|
| 505 |
// Kembalikan JSON yang kompatibel dengan format respons frontend agar tidak merusak UI kasir
|
|
|
|
| 610 |
// Kirim Notifikasi WA struk belanja jika pembayaran berhasil
|
| 611 |
if order.PaymentStatus == "paid" && oldStatus != "paid" {
|
| 612 |
go func() {
|
| 613 |
+
custPhone := order.CustomerPhone
|
| 614 |
+
custName := order.CustomerName
|
| 615 |
if custName == "" {
|
| 616 |
custName = "Customer"
|
| 617 |
}
|
models/models.go
CHANGED
|
@@ -110,6 +110,8 @@ type Order struct {
|
|
| 110 |
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
|
| 111 |
Company *Company `gorm:"foreignKey:CompanyID" json:"company,omitempty"`
|
| 112 |
Branch *Branch `gorm:"foreignKey:BranchID" json:"branch,omitempty"`
|
|
|
|
|
|
|
| 113 |
Items []OrderItem `gorm:"foreignKey:OrderID;constraint:OnDelete:CASCADE" json:"items"`
|
| 114 |
}
|
| 115 |
|
|
|
|
| 110 |
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
|
| 111 |
Company *Company `gorm:"foreignKey:CompanyID" json:"company,omitempty"`
|
| 112 |
Branch *Branch `gorm:"foreignKey:BranchID" json:"branch,omitempty"`
|
| 113 |
+
CustomerName string `gorm:"type:varchar(100)" json:"customer_name"`
|
| 114 |
+
CustomerPhone string `gorm:"type:varchar(50)" json:"customer_phone"`
|
| 115 |
Items []OrderItem `gorm:"foreignKey:OrderID;constraint:OnDelete:CASCADE" json:"items"`
|
| 116 |
}
|
| 117 |
|
services/whatsapp.go
CHANGED
|
@@ -173,6 +173,17 @@ func SendApprovalWa(phone string, storeName string, email string) bool {
|
|
| 173 |
return postFonnte(formattedPhone, message)
|
| 174 |
}
|
| 175 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
func postFonnte(target string, message string) bool {
|
| 177 |
// Gunakan http client bawaan Go dengan timeout 15 detik
|
| 178 |
client := &http.Client{Timeout: 15 * time.Second}
|
|
|
|
| 173 |
return postFonnte(formattedPhone, message)
|
| 174 |
}
|
| 175 |
|
| 176 |
+
func SendNewRegistrationAdminWa(adminPhone string, storeName string, ownerName string, email string, phone string) bool {
|
| 177 |
+
if config.GlobalConfig.FonnteToken == "" || adminPhone == "" {
|
| 178 |
+
return false
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
formattedPhone := formatPhone(adminPhone)
|
| 182 |
+
message := fmt.Sprintf("🚨 *PENDAFTARAN BARU XOGM GO* 🚨\n\nAda pendaftar baru yang menunggu persetujuan (approval) Anda:\n\n*Nama Toko / PT*: %s\n*Nama Owner*: %s\n*Email*: %s\n*No HP*: %s\n\nSilakan cek Dashboard Super Admin untuk menyetujui akun ini.", storeName, ownerName, email, phone)
|
| 183 |
+
|
| 184 |
+
return postFonnte(formattedPhone, message)
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
func postFonnte(target string, message string) bool {
|
| 188 |
// Gunakan http client bawaan Go dengan timeout 15 detik
|
| 189 |
client := &http.Client{Timeout: 15 * time.Second}
|