Mhamdans17 commited on
Commit ·
236d19a
1
Parent(s): e06ef8c
feat: add TripayPaymentMethod field in Setting table for dynamic payment channel configuration
Browse files- controllers/auth_controller.go +6 -5
- controllers/order_controller.go +2 -2
- models/models.go +1 -0
- services/tripay.go +16 -8
controllers/auth_controller.go
CHANGED
|
@@ -48,11 +48,12 @@ func SeedDefaultSetting() {
|
|
| 48 |
config.DB.Model(&models.Setting{}).Count(&count)
|
| 49 |
if count == 0 {
|
| 50 |
setting := models.Setting{
|
| 51 |
-
ID:
|
| 52 |
-
TripayMerchantCode:
|
| 53 |
-
TripayAPIKey:
|
| 54 |
-
TripayPrivateKey:
|
| 55 |
-
TripayProxyURL:
|
|
|
|
| 56 |
}
|
| 57 |
if err := config.DB.Create(&setting).Error; err != nil {
|
| 58 |
log.Printf("[SEED] Gagal membuat default setting: %v", err)
|
|
|
|
| 48 |
config.DB.Model(&models.Setting{}).Count(&count)
|
| 49 |
if count == 0 {
|
| 50 |
setting := models.Setting{
|
| 51 |
+
ID: 1,
|
| 52 |
+
TripayMerchantCode: config.GlobalConfig.TripayMerchantCode,
|
| 53 |
+
TripayAPIKey: config.GlobalConfig.TripayAPIKey,
|
| 54 |
+
TripayPrivateKey: config.GlobalConfig.TripayPrivateKey,
|
| 55 |
+
TripayProxyURL: config.GlobalConfig.TripayProxyURL,
|
| 56 |
+
TripayPaymentMethod: "QRISC",
|
| 57 |
}
|
| 58 |
if err := config.DB.Create(&setting).Error; err != nil {
|
| 59 |
log.Printf("[SEED] Gagal membuat default setting: %v", err)
|
controllers/order_controller.go
CHANGED
|
@@ -478,11 +478,11 @@ func PayTripay(c *gin.Context) {
|
|
| 478 |
})
|
| 479 |
}
|
| 480 |
|
| 481 |
-
// Request Tripay Transaction (Default
|
| 482 |
tripayRes, err := services.CreateTripayTransaction(
|
| 483 |
order.OrderNumber,
|
| 484 |
order.TotalAmount,
|
| 485 |
-
"
|
| 486 |
req.CustomerName,
|
| 487 |
req.CustomerEmail,
|
| 488 |
req.CustomerPhone,
|
|
|
|
| 478 |
})
|
| 479 |
}
|
| 480 |
|
| 481 |
+
// Request Tripay Transaction (Default diambil secara dinamis dari database)
|
| 482 |
tripayRes, err := services.CreateTripayTransaction(
|
| 483 |
order.OrderNumber,
|
| 484 |
order.TotalAmount,
|
| 485 |
+
"",
|
| 486 |
req.CustomerName,
|
| 487 |
req.CustomerEmail,
|
| 488 |
req.CustomerPhone,
|
models/models.go
CHANGED
|
@@ -138,5 +138,6 @@ type Setting struct {
|
|
| 138 |
TripayAPIKey string `gorm:"type:text" json:"tripay_api_key"`
|
| 139 |
TripayPrivateKey string `gorm:"type:text" json:"tripay_private_key"`
|
| 140 |
TripayProxyURL string `gorm:"type:text" json:"tripay_proxy_url"`
|
|
|
|
| 141 |
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
|
| 142 |
}
|
|
|
|
| 138 |
TripayAPIKey string `gorm:"type:text" json:"tripay_api_key"`
|
| 139 |
TripayPrivateKey string `gorm:"type:text" json:"tripay_private_key"`
|
| 140 |
TripayProxyURL string `gorm:"type:text" json:"tripay_proxy_url"`
|
| 141 |
+
TripayPaymentMethod string `gorm:"type:varchar(50);default:'QRIS'" json:"tripay_payment_method"`
|
| 142 |
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
|
| 143 |
}
|
services/tripay.go
CHANGED
|
@@ -88,10 +88,20 @@ func CreateTripayTransaction(
|
|
| 88 |
items []TripayItem,
|
| 89 |
companyID uint,
|
| 90 |
) (*TripayCreateResponse, error) {
|
| 91 |
-
//
|
| 92 |
-
|
| 93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
}
|
|
|
|
| 95 |
if customerName == "" {
|
| 96 |
customerName = "Customer"
|
| 97 |
}
|
|
@@ -102,10 +112,6 @@ func CreateTripayTransaction(
|
|
| 102 |
customerPhone = "081234567890"
|
| 103 |
}
|
| 104 |
|
| 105 |
-
// Load global Tripay settings dari database (ID = 1)
|
| 106 |
-
var setting models.Setting
|
| 107 |
-
config.DB.First(&setting, 1)
|
| 108 |
-
|
| 109 |
mCode := setting.TripayMerchantCode
|
| 110 |
if mCode == "" {
|
| 111 |
mCode = config.GlobalConfig.TripayMerchantCode
|
|
@@ -140,10 +146,12 @@ func CreateTripayTransaction(
|
|
| 140 |
Timeout: 15 * time.Second,
|
| 141 |
}
|
| 142 |
|
| 143 |
-
// Buat daftar metode pembayaran yang akan dicoba (
|
| 144 |
methodsToTry := []string{paymentMethod}
|
| 145 |
if paymentMethod == "QRIS" {
|
| 146 |
methodsToTry = append(methodsToTry, "QRISC")
|
|
|
|
|
|
|
| 147 |
}
|
| 148 |
|
| 149 |
var lastError error
|
|
|
|
| 88 |
items []TripayItem,
|
| 89 |
companyID uint,
|
| 90 |
) (*TripayCreateResponse, error) {
|
| 91 |
+
// Load global Tripay settings dari database (ID = 1)
|
| 92 |
+
var setting models.Setting
|
| 93 |
+
config.DB.First(&setting, 1)
|
| 94 |
+
|
| 95 |
+
// Ambil paymentMethod secara dinamis dari database jika parameter input kosong atau default "QRIS"
|
| 96 |
+
dbPayMethod := setting.TripayPaymentMethod
|
| 97 |
+
if paymentMethod == "" || paymentMethod == "QRIS" {
|
| 98 |
+
if dbPayMethod != "" {
|
| 99 |
+
paymentMethod = dbPayMethod
|
| 100 |
+
} else {
|
| 101 |
+
paymentMethod = "QRIS"
|
| 102 |
+
}
|
| 103 |
}
|
| 104 |
+
|
| 105 |
if customerName == "" {
|
| 106 |
customerName = "Customer"
|
| 107 |
}
|
|
|
|
| 112 |
customerPhone = "081234567890"
|
| 113 |
}
|
| 114 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
mCode := setting.TripayMerchantCode
|
| 116 |
if mCode == "" {
|
| 117 |
mCode = config.GlobalConfig.TripayMerchantCode
|
|
|
|
| 146 |
Timeout: 15 * time.Second,
|
| 147 |
}
|
| 148 |
|
| 149 |
+
// Buat daftar metode pembayaran yang akan dicoba (mendukung fallback dua arah antara QRIS dan QRISC)
|
| 150 |
methodsToTry := []string{paymentMethod}
|
| 151 |
if paymentMethod == "QRIS" {
|
| 152 |
methodsToTry = append(methodsToTry, "QRISC")
|
| 153 |
+
} else if paymentMethod == "QRISC" {
|
| 154 |
+
methodsToTry = append(methodsToTry, "QRIS")
|
| 155 |
}
|
| 156 |
|
| 157 |
var lastError error
|