Mhamdans17 commited on
Commit ·
9ae6db1
1
Parent(s): c4bc006
feat: add outbound proxy support for Tripay API requests
Browse files- config/config.go +2 -0
- services/tripay.go +16 -1
config/config.go
CHANGED
|
@@ -14,6 +14,7 @@ type Config struct {
|
|
| 14 |
TripayAPIKey string
|
| 15 |
TripayPrivateKey string
|
| 16 |
TripayIsProduction bool
|
|
|
|
| 17 |
AppPort int
|
| 18 |
Port string // Hugging Face Spaces port (default 7860)
|
| 19 |
AppBaseURL string
|
|
@@ -40,6 +41,7 @@ func LoadConfig() {
|
|
| 40 |
TripayAPIKey: getEnv("TRIPAY_API_KEY", ""),
|
| 41 |
TripayPrivateKey: getEnv("TRIPAY_PRIVATE_KEY", ""),
|
| 42 |
TripayIsProduction: getEnvBool("TRIPAY_IS_PRODUCTION", true),
|
|
|
|
| 43 |
AppPort: getEnvInt("APP_PORT", 8003),
|
| 44 |
Port: getEnv("PORT", "7860"), // Default port Hugging Face Spaces
|
| 45 |
AppBaseURL: getEnv("APP_BASE_URL", "http://localhost:8003"),
|
|
|
|
| 14 |
TripayAPIKey string
|
| 15 |
TripayPrivateKey string
|
| 16 |
TripayIsProduction bool
|
| 17 |
+
TripayProxyURL string
|
| 18 |
AppPort int
|
| 19 |
Port string // Hugging Face Spaces port (default 7860)
|
| 20 |
AppBaseURL string
|
|
|
|
| 41 |
TripayAPIKey: getEnv("TRIPAY_API_KEY", ""),
|
| 42 |
TripayPrivateKey: getEnv("TRIPAY_PRIVATE_KEY", ""),
|
| 43 |
TripayIsProduction: getEnvBool("TRIPAY_IS_PRODUCTION", true),
|
| 44 |
+
TripayProxyURL: getEnv("TRIPAY_PROXY_URL", ""),
|
| 45 |
AppPort: getEnvInt("APP_PORT", 8003),
|
| 46 |
Port: getEnv("PORT", "7860"), // Default port Hugging Face Spaces
|
| 47 |
AppBaseURL: getEnv("APP_BASE_URL", "http://localhost:8003"),
|
services/tripay.go
CHANGED
|
@@ -10,6 +10,7 @@ import (
|
|
| 10 |
"io"
|
| 11 |
"log"
|
| 12 |
"net/http"
|
|
|
|
| 13 |
"time"
|
| 14 |
|
| 15 |
"service-warungpos-go/config"
|
|
@@ -116,7 +117,21 @@ func CreateTripayTransaction(
|
|
| 116 |
apiURL := getTripayBaseURL() + "/transaction/create"
|
| 117 |
log.Printf("[TRIPAY] Mengirim request tagihan ke: %s", apiURL)
|
| 118 |
|
| 119 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
req, err := http.NewRequest("POST", apiURL, bytes.NewBuffer(jsonBytes))
|
| 121 |
if err != nil {
|
| 122 |
return nil, fmt.Errorf("gagal membuat http request: %v", err)
|
|
|
|
| 10 |
"io"
|
| 11 |
"log"
|
| 12 |
"net/http"
|
| 13 |
+
"net/url"
|
| 14 |
"time"
|
| 15 |
|
| 16 |
"service-warungpos-go/config"
|
|
|
|
| 117 |
apiURL := getTripayBaseURL() + "/transaction/create"
|
| 118 |
log.Printf("[TRIPAY] Mengirim request tagihan ke: %s", apiURL)
|
| 119 |
|
| 120 |
+
transport := &http.Transport{}
|
| 121 |
+
if config.GlobalConfig.TripayProxyURL != "" {
|
| 122 |
+
proxyURL, err := url.Parse(config.GlobalConfig.TripayProxyURL)
|
| 123 |
+
if err == nil {
|
| 124 |
+
transport.Proxy = http.ProxyURL(proxyURL)
|
| 125 |
+
log.Printf("[TRIPAY] Menggunakan proxy outbound: %s", config.GlobalConfig.TripayProxyURL)
|
| 126 |
+
} else {
|
| 127 |
+
log.Printf("[TRIPAY] Gagal memproses format proxy URL: %v", err)
|
| 128 |
+
}
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
client := &http.Client{
|
| 132 |
+
Transport: transport,
|
| 133 |
+
Timeout: 15 * time.Second,
|
| 134 |
+
}
|
| 135 |
req, err := http.NewRequest("POST", apiURL, bytes.NewBuffer(jsonBytes))
|
| 136 |
if err != nil {
|
| 137 |
return nil, fmt.Errorf("gagal membuat http request: %v", err)
|