Yimaru-BackEnd/internal/domain/payment.go
Yared Yemane 7a4253edf4 Add explicit payment provider selection for subscriptions.
Require the client to choose CHAPA or ARIFPAY in the subscription checkout request body and route payment initiation and verification through the matching provider.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-26 04:18:24 -07:00

96 lines
2.3 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
}
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
}