From 3e2fb946d323359ed940517f251c1d7bc3d4d2b7 Mon Sep 17 00:00:00 2001 From: AiAe Date: Thu, 3 Sep 2026 00:38:35 +0300 Subject: [PATCH 1/3] Make stripe redirect to site with transaction_id --- handlers/orders_stripe.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/handlers/orders_stripe.go b/handlers/orders_stripe.go index 7f7256f..5df0006 100644 --- a/handlers/orders_stripe.go +++ b/handlers/orders_stripe.go @@ -14,6 +14,7 @@ import ( "gorm.io/gorm" "io" "net/http" + "strings" "time" ) @@ -62,7 +63,7 @@ func InitiateStripeDonatorCheckoutSession(c *gin.Context) *APIError { }, }, Mode: stripe.String(string(getStripeCheckoutMode(body.Recurring))), - SuccessURL: stripe.String(config.Instance.Stripe.DonateRedirectUrl), + SuccessURL: stripe.String(getStripeSuccessURL(config.Instance.Stripe.DonateRedirectUrl)), AutomaticTax: &stripe.CheckoutSessionAutomaticTaxParams{Enabled: stripe.Bool(true)}, } @@ -298,7 +299,7 @@ func createStripeCheckoutSession(c *gin.Context, orders []*db.Order) *APIError { params := &stripe.CheckoutSessionParams{ LineItems: lineItems, Mode: stripe.String(string(stripe.CheckoutSessionModePayment)), - SuccessURL: stripe.String(config.Instance.Stripe.StorePaymentRedirectUrl), + SuccessURL: stripe.String(getStripeSuccessURL(config.Instance.Stripe.StorePaymentRedirectUrl)), AutomaticTax: &stripe.CheckoutSessionAutomaticTaxParams{Enabled: stripe.Bool(true)}, } @@ -328,6 +329,16 @@ func createStripeCheckoutSession(c *gin.Context, orders []*db.Order) *APIError { return nil } +func getStripeSuccessURL(redirectURL string) string { + separator := "?" + + if strings.Contains(redirectURL, "?") { + separator = "&" + } + + return fmt.Sprintf("%s%sorder_id=-1&transaction_id={CHECKOUT_SESSION_ID}", redirectURL, separator) +} + // Gets the donator price id for Stripe func getStripeDonatorPriceId(months int, isRecurring bool) string { if config.Instance.IsProduction { From fde83819b896f7656163b593de7f654e87d77594 Mon Sep 17 00:00:00 2001 From: AiAe Date: Thu, 3 Sep 2026 00:59:23 +0300 Subject: [PATCH 2/3] Add order id and transaction id to orders --- db/orders.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/db/orders.go b/db/orders.go index db58b04..7302fe8 100644 --- a/db/orders.go +++ b/db/orders.go @@ -3,9 +3,10 @@ package db import ( "errors" "fmt" + "time" + "github.com/Quaver/api2/enums" "gorm.io/gorm" - "time" ) type OrderStatus string @@ -18,8 +19,8 @@ const ( type Order struct { Id int `gorm:"column:id; PRIMARY_KEY" json:"id"` UserId int `gorm:"column:user_id" json:"user_id"` - OrderId int `gorm:"column:order_id" json:"-"` - TransactionId string `gorm:"column:transaction_id" json:"-"` + OrderId int `gorm:"column:order_id" json:"order_id"` + TransactionId string `gorm:"column:transaction_id" json:"transaction_id"` IPAddress string `gorm:"column:ip_address" json:"-"` ItemId OrderItemId `gorm:"column:item_id" json:"item_id"` Quantity int `gorm:"column:quantity" json:"quantity"` From 1f0108e66565b2712574f5a0b4e9dbb785029e29 Mon Sep 17 00:00:00 2001 From: AiAe Date: Thu, 3 Sep 2026 01:09:47 +0300 Subject: [PATCH 3/3] Add orders order by and pagination --- db/orders.go | 5 ++++- handlers/orders.go | 8 +++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/db/orders.go b/db/orders.go index 7302fe8..1adea85 100644 --- a/db/orders.go +++ b/db/orders.go @@ -255,7 +255,7 @@ func (order *Order) FinalizeUserAccentColor() error { } // GetUserOrders Gets a user's orders -func GetUserOrders(userId int) ([]*Order, error) { +func GetUserOrders(userId int, limit int, page int) ([]*Order, error) { var orders = make([]*Order, 0) result := SQL. @@ -263,6 +263,9 @@ func GetUserOrders(userId int) ([]*Order, error) { Preload("Item"). Preload("Subscription"). Where("orders.user_id = ? AND orders.status = ?", userId, "Completed"). + Order("orders.timestamp DESC"). + Limit(limit). + Offset(page * limit). Find(&orders) if result.Error != nil { diff --git a/handlers/orders.go b/handlers/orders.go index 066b518..68e48e4 100644 --- a/handlers/orders.go +++ b/handlers/orders.go @@ -82,7 +82,13 @@ func GetUserOrders(c *gin.Context) *APIError { return nil } - orders, err := db.GetUserOrders(user.Id) + page, err := strconv.Atoi(c.Query("page")) + + if err != nil { + page = 0 + } + + orders, err := db.GetUserOrders(user.Id, 10, page) if err != nil { return APIErrorServerError("Error retrieving orders from db", err)