Introduce is_free plans with gateway-free checkout enrollment, require positive pricing for paid plans, and block duplicate category plus period combinations including free versus paid. Co-authored-by: Cursor <cursoragent@cursor.com>
146 lines
3.7 KiB
Go
146 lines
3.7 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
|
|
// SkipTotalCount skips the COUNT(*) query (used by CSV export batches).
|
|
SkipTotalCount bool
|
|
}
|
|
|
|
type PaymentListPage struct {
|
|
Items []Payment
|
|
Total int64
|
|
Limit int32
|
|
Offset int32
|
|
}
|
|
|
|
type CreatePaymentInput struct {
|
|
UserID int64
|
|
PlanID *int64
|
|
SubscriptionID *int64
|
|
Amount float64
|
|
Currency string
|
|
PaymentMethod *string
|
|
Nonce string
|
|
ExpiresAt *time.Time
|
|
}
|
|
|
|
// CreateAdminPaymentInput records an admin-panel payment as SUCCESS at the plan price
|
|
// (treated as charged for revenue/analytics; no gateway checkout).
|
|
type CreateAdminPaymentInput struct {
|
|
UserID int64
|
|
PlanID *int64
|
|
SubscriptionID int64
|
|
Amount float64
|
|
Currency string
|
|
PaymentMethod string
|
|
Nonce string
|
|
TransactionID *string
|
|
}
|
|
|
|
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,omitempty"`
|
|
SessionID string `json:"session_id,omitempty"`
|
|
PaymentURL string `json:"payment_url,omitempty"`
|
|
Amount float64 `json:"amount,omitempty"`
|
|
Currency string `json:"currency,omitempty"`
|
|
ExpiresAt string `json:"expires_at,omitempty"`
|
|
FreeEnrollment bool `json:"free_enrollment,omitempty"`
|
|
SubscriptionID int64 `json:"subscription_id,omitempty"`
|
|
}
|
|
|
|
type VerifyPaymentRequest struct {
|
|
SessionID string `json:"session_id"`
|
|
}
|
|
|
|
type PaymentWebhookData struct {
|
|
SessionID string
|
|
TransactionID string
|
|
Nonce string
|
|
TransactionStatus string
|
|
PaymentMethod string
|
|
TotalAmount float64
|
|
}
|