Normalize ArifPay checkout payment URLs before returning.
Clean malformed provider paths (such as /checkout//{session_id}) so subscribe responses persist and return stable payment_url values.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
853bd730bb
commit
cd4e3b7811
|
|
@ -8,6 +8,8 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -167,7 +169,7 @@ func (s *ArifpayService) InitiateSubscriptionPayment(ctx context.Context, userID
|
||||||
}
|
}
|
||||||
|
|
||||||
sessionID := fmt.Sprintf("%v", data["sessionId"])
|
sessionID := fmt.Sprintf("%v", data["sessionId"])
|
||||||
paymentURL := fmt.Sprintf("%v", data["paymentUrl"])
|
paymentURL := normalizeExternalURL(fmt.Sprintf("%v", data["paymentUrl"]))
|
||||||
|
|
||||||
// Update payment with session info
|
// Update payment with session info
|
||||||
if err := s.paymentStore.UpdatePaymentSessionID(ctx, payment.ID, sessionID, paymentURL); err != nil {
|
if err := s.paymentStore.UpdatePaymentSessionID(ctx, payment.ID, sessionID, paymentURL); err != nil {
|
||||||
|
|
@ -184,6 +186,22 @@ func (s *ArifpayService) InitiateSubscriptionPayment(ctx context.Context, userID
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func normalizeExternalURL(raw string) string {
|
||||||
|
u, err := url.Parse(raw)
|
||||||
|
if err != nil {
|
||||||
|
return raw
|
||||||
|
}
|
||||||
|
if u.Path == "" {
|
||||||
|
return raw
|
||||||
|
}
|
||||||
|
cleaned := path.Clean(u.Path)
|
||||||
|
if strings.HasSuffix(u.Path, "/") && !strings.HasSuffix(cleaned, "/") {
|
||||||
|
cleaned += "/"
|
||||||
|
}
|
||||||
|
u.Path = cleaned
|
||||||
|
return u.String()
|
||||||
|
}
|
||||||
|
|
||||||
// ProcessPaymentWebhook handles the webhook callback from ArifPay
|
// ProcessPaymentWebhook handles the webhook callback from ArifPay
|
||||||
func (s *ArifpayService) ProcessPaymentWebhook(ctx context.Context, req domain.WebhookRequest) error {
|
func (s *ArifpayService) ProcessPaymentWebhook(ctx context.Context, req domain.WebhookRequest) error {
|
||||||
// ArifPay verify/webhook payloads are inconsistent: some responses include nonce, others only sessionId.
|
// ArifPay verify/webhook payloads are inconsistent: some responses include nonce, others only sessionId.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user