Expose GET /api/v1/admin/payments for filtered gateway transaction listing, constrain /admin/:id to integers so /admin/payments is not mistaken for an admin id, and grant payments.list_all to ADMIN. Co-authored-by: Cursor <cursoragent@cursor.com>
128 lines
3.0 KiB
Go
128 lines
3.0 KiB
Go
package domain
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
type PaymentStatus string
|
|
|
|
const (
|
|
PaymentStatusPending PaymentStatus = "PENDING"
|
|
PaymentStatusProcessing PaymentStatus = "PROCESSING"
|
|
PaymentStatusSuccess PaymentStatus = "SUCCESS"
|
|
PaymentStatusFailed PaymentStatus = "FAILED"
|
|
PaymentStatusCancelled PaymentStatus = "CANCELLED"
|
|
PaymentStatusExpired PaymentStatus = "EXPIRED"
|
|
)
|
|
|
|
type Payment struct {
|
|
ID int64
|
|
UserID int64
|
|
PlanID *int64
|
|
SubscriptionID *int64
|
|
SessionID *string
|
|
TransactionID *string
|
|
Nonce string
|
|
Amount float64
|
|
Currency string
|
|
PaymentMethod *string
|
|
Status string
|
|
PaymentURL *string
|
|
PaidAt *time.Time
|
|
ExpiresAt *time.Time
|
|
CreatedAt time.Time
|
|
UpdatedAt *time.Time
|
|
PlanName *string
|
|
PlanCategory *string
|
|
UserEmail *string
|
|
UserFirstName *string
|
|
UserLastName *string
|
|
}
|
|
|
|
// PaymentListFilter is used by admin payment listing.
|
|
type PaymentListFilter struct {
|
|
PaymentID *int64
|
|
UserID *int64
|
|
PlanID *int64
|
|
SubscriptionID *int64
|
|
Status *string
|
|
PaymentMethod *string
|
|
Currency *string
|
|
PlanCategory *string
|
|
Reference *string
|
|
CreatedFrom *time.Time
|
|
CreatedTo *time.Time
|
|
PaidFrom *time.Time
|
|
PaidTo *time.Time
|
|
MinAmount *float64
|
|
MaxAmount *float64
|
|
Limit int32
|
|
Offset int32
|
|
}
|
|
|
|
type PaymentListPage struct {
|
|
Items []Payment
|
|
Total int64
|
|
Limit int32
|
|
Offset int32
|
|
}
|
|
|
|
type CreatePaymentInput struct {
|
|
UserID int64
|
|
PlanID *int64
|
|
Amount float64
|
|
Currency string
|
|
PaymentMethod *string
|
|
Nonce string
|
|
ExpiresAt *time.Time
|
|
}
|
|
|
|
type PaymentProvider string
|
|
|
|
const (
|
|
PaymentProviderChapa PaymentProvider = "CHAPA"
|
|
PaymentProviderArifPay PaymentProvider = "ARIFPAY"
|
|
)
|
|
|
|
func ParsePaymentProvider(raw string) (PaymentProvider, error) {
|
|
switch strings.ToUpper(strings.TrimSpace(raw)) {
|
|
case string(PaymentProviderChapa):
|
|
return PaymentProviderChapa, nil
|
|
case string(PaymentProviderArifPay), "ARIF_PAY":
|
|
return PaymentProviderArifPay, nil
|
|
default:
|
|
return "", fmt.Errorf("unsupported payment provider %q", raw)
|
|
}
|
|
}
|
|
|
|
type InitiateSubscriptionPaymentRequest struct {
|
|
PlanID int64 `json:"plan_id" validate:"required"`
|
|
Phone string `json:"phone" validate:"required"`
|
|
Email string `json:"email" validate:"required,email"`
|
|
Provider PaymentProvider `json:"provider"`
|
|
}
|
|
|
|
type InitiateSubscriptionPaymentResponse struct {
|
|
PaymentID int64 `json:"payment_id"`
|
|
SessionID string `json:"session_id"`
|
|
PaymentURL string `json:"payment_url"`
|
|
Amount float64 `json:"amount"`
|
|
Currency string `json:"currency"`
|
|
ExpiresAt string `json:"expires_at"`
|
|
}
|
|
|
|
type VerifyPaymentRequest struct {
|
|
SessionID string `json:"session_id"`
|
|
}
|
|
|
|
type PaymentWebhookData struct {
|
|
SessionID string
|
|
TransactionID string
|
|
Nonce string
|
|
TransactionStatus string
|
|
PaymentMethod string
|
|
TotalAmount float64
|
|
}
|