Mhamdans17 commited on
Commit ·
e9ae501
1
Parent(s): bc89757
feat: set tripay timeout to 5 mins and return tripay amount for frontend display
Browse files- controllers/order_controller.go +7 -0
- services/tripay.go +7 -1
controllers/order_controller.go
CHANGED
|
@@ -502,6 +502,11 @@ func PayTripay(c *gin.Context) {
|
|
| 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
|
| 506 |
c.JSON(http.StatusOK, gin.H{
|
| 507 |
"order_id": order.ID,
|
|
@@ -513,6 +518,8 @@ func PayTripay(c *gin.Context) {
|
|
| 513 |
"payment_method": tripayRes.Data.PaymentMethod,
|
| 514 |
"payment_name": tripayRes.Data.PaymentName,
|
| 515 |
"total_amount": order.TotalAmount,
|
|
|
|
|
|
|
| 516 |
})
|
| 517 |
}
|
| 518 |
|
|
|
|
| 502 |
order.CustomerPhone = req.CustomerPhone
|
| 503 |
config.DB.Save(&order)
|
| 504 |
|
| 505 |
+
expTime := tripayRes.Data.ExpiredTime
|
| 506 |
+
if expTime == 0 {
|
| 507 |
+
expTime = time.Now().Add(5 * time.Minute).Unix()
|
| 508 |
+
}
|
| 509 |
+
|
| 510 |
// Kembalikan JSON yang kompatibel dengan format respons frontend agar tidak merusak UI kasir
|
| 511 |
c.JSON(http.StatusOK, gin.H{
|
| 512 |
"order_id": order.ID,
|
|
|
|
| 518 |
"payment_method": tripayRes.Data.PaymentMethod,
|
| 519 |
"payment_name": tripayRes.Data.PaymentName,
|
| 520 |
"total_amount": order.TotalAmount,
|
| 521 |
+
"tripay_amount": tripayRes.Data.Amount,
|
| 522 |
+
"expired_time": expTime,
|
| 523 |
})
|
| 524 |
}
|
| 525 |
|
services/tripay.go
CHANGED
|
@@ -32,6 +32,7 @@ type TripayCreateRequest struct {
|
|
| 32 |
CustomerEmail string `json:"customer_email"`
|
| 33 |
CustomerPhone string `json:"customer_phone"`
|
| 34 |
OrderItems []TripayItem `json:"order_items"`
|
|
|
|
| 35 |
Signature string `json:"signature"`
|
| 36 |
}
|
| 37 |
|
|
@@ -49,7 +50,8 @@ type TripayCreateResponse struct {
|
|
| 49 |
QrURL string `json:"qr_url"` // Untuk QRIS
|
| 50 |
QrString string `json:"qr_string"` // Untuk QRIS string raw
|
| 51 |
PaymentCode string `json:"payment_code"` // Untuk VA / Retail Outlet
|
| 52 |
-
Status string `json:"status"`
|
|
|
|
| 53 |
} `json:"data"`
|
| 54 |
}
|
| 55 |
|
|
@@ -161,6 +163,9 @@ func CreateTripayTransaction(
|
|
| 161 |
// Hitung signature (sama untuk semua method karena rumusnya hanya: merchantCode + merchantRef + amount)
|
| 162 |
signature := CalculateSignature(orderNumber, amount, mCode, privKey)
|
| 163 |
|
|
|
|
|
|
|
|
|
|
| 164 |
// Persiapkan payload request
|
| 165 |
payload := TripayCreateRequest{
|
| 166 |
Method: currentMethod,
|
|
@@ -170,6 +175,7 @@ func CreateTripayTransaction(
|
|
| 170 |
CustomerEmail: customerEmail,
|
| 171 |
CustomerPhone: customerPhone,
|
| 172 |
OrderItems: items,
|
|
|
|
| 173 |
Signature: signature,
|
| 174 |
}
|
| 175 |
|
|
|
|
| 32 |
CustomerEmail string `json:"customer_email"`
|
| 33 |
CustomerPhone string `json:"customer_phone"`
|
| 34 |
OrderItems []TripayItem `json:"order_items"`
|
| 35 |
+
ExpiredTime int64 `json:"expired_time"`
|
| 36 |
Signature string `json:"signature"`
|
| 37 |
}
|
| 38 |
|
|
|
|
| 50 |
QrURL string `json:"qr_url"` // Untuk QRIS
|
| 51 |
QrString string `json:"qr_string"` // Untuk QRIS string raw
|
| 52 |
PaymentCode string `json:"payment_code"` // Untuk VA / Retail Outlet
|
| 53 |
+
Status string `json:"status"` // UNPAID, PAID, EXPIRED, FAILED
|
| 54 |
+
ExpiredTime int64 `json:"expired_time"`
|
| 55 |
} `json:"data"`
|
| 56 |
}
|
| 57 |
|
|
|
|
| 163 |
// Hitung signature (sama untuk semua method karena rumusnya hanya: merchantCode + merchantRef + amount)
|
| 164 |
signature := CalculateSignature(orderNumber, amount, mCode, privKey)
|
| 165 |
|
| 166 |
+
// Waktu expired 5 menit dari sekarang (dikonversi ke UNIX timestamp sesuai dokumentasi Tripay)
|
| 167 |
+
expiredUnix := time.Now().Add(5 * time.Minute).Unix()
|
| 168 |
+
|
| 169 |
// Persiapkan payload request
|
| 170 |
payload := TripayCreateRequest{
|
| 171 |
Method: currentMethod,
|
|
|
|
| 175 |
CustomerEmail: customerEmail,
|
| 176 |
CustomerPhone: customerPhone,
|
| 177 |
OrderItems: items,
|
| 178 |
+
ExpiredTime: expiredUnix,
|
| 179 |
Signature: signature,
|
| 180 |
}
|
| 181 |
|