From 26731d439056ded5164f1ac3b8248568ec410548 Mon Sep 17 00:00:00 2001 From: nutcas3 Date: Fri, 24 Apr 2026 08:51:37 +0300 Subject: [PATCH] feat: Extract Stripe gateway types to separate file for improved code organization and maintainability - Move StripeGateway struct from stripe.go to types.go - Move PaymentRequest/PaymentResponse/CustomerResponse/RefundResponse/PaymentStatusResponse/WebhookEvent/InvoiceItem/InvoiceResponse structs to types.go - Remove encoding/json import from stripe.go (moved to types.go) - Remove PaymentRequest comment from types.go for consistency with other type definitions --- .../internal/payment/gateways/stripe.go | 78 ----------------- .../internal/payment/gateways/types.go | 83 +++++++++++++++++++ 2 files changed, 83 insertions(+), 78 deletions(-) create mode 100644 apps/api-server/internal/payment/gateways/types.go diff --git a/apps/api-server/internal/payment/gateways/stripe.go b/apps/api-server/internal/payment/gateways/stripe.go index a2f5cda..30caa29 100644 --- a/apps/api-server/internal/payment/gateways/stripe.go +++ b/apps/api-server/internal/payment/gateways/stripe.go @@ -2,7 +2,6 @@ package gateways import ( "context" - "encoding/json" "fmt" "net/http" "time" @@ -20,13 +19,6 @@ import ( "github.com/nutcas3/telecom-platform/apps/api-server/internal/payment" ) -// StripeGateway implements payment processing via Stripe -type StripeGateway struct { - secretKey string - webhookSecret string - client *http.Client -} - // NewStripeGateway creates a new Stripe payment gateway func NewStripeGateway(secretKey, webhookSecret string) *StripeGateway { stripe.Key = secretKey @@ -216,73 +208,3 @@ func (g *StripeGateway) CreateInvoice(ctx context.Context, customerID string, it CreatedAt: time.Unix(inv.Created, 0), }, nil } - -// PaymentRequest represents a payment request -type PaymentRequest struct { - SubscriberID uint `json:"subscriber_id"` - InvoiceID uint `json:"invoice_id"` - Amount float64 `json:"amount"` - Currency string `json:"currency"` - CustomerID string `json:"customer_id,omitempty"` - Description string `json:"description,omitempty"` -} - -// PaymentResponse represents a payment response -type PaymentResponse struct { - TransactionID string `json:"transaction_id"` - Status string `json:"status"` - ClientSecret string `json:"client_secret"` - Amount float64 `json:"amount"` - Currency string `json:"currency"` - CreatedAt time.Time `json:"created_at"` -} - -// CustomerResponse represents a customer creation response -type CustomerResponse struct { - CustomerID string `json:"customer_id"` - Email string `json:"email"` - Name string `json:"name"` - CreatedAt time.Time `json:"created_at"` -} - -// RefundResponse represents a refund response -type RefundResponse struct { - RefundID string `json:"refund_id"` - Amount float64 `json:"amount"` - Status string `json:"status"` - CreatedAt time.Time `json:"created_at"` -} - -// PaymentStatusResponse represents payment status response -type PaymentStatusResponse struct { - TransactionID string `json:"transaction_id"` - Status string `json:"status"` - Amount float64 `json:"amount"` - Currency string `json:"currency"` - CreatedAt time.Time `json:"created_at"` -} - -// WebhookEvent represents a webhook event -type WebhookEvent struct { - Type string `json:"type"` - EventID string `json:"event_id"` - Created time.Time `json:"created"` - Data json.RawMessage `json:"data"` -} - -// InvoiceItem represents an invoice line item -type InvoiceItem struct { - Description string `json:"description"` - Amount float64 `json:"amount"` - Currency string `json:"currency"` - Quantity int `json:"quantity"` -} - -// InvoiceResponse represents an invoice response -type InvoiceResponse struct { - InvoiceID string `json:"invoice_id"` - Status string `json:"status"` - Amount float64 `json:"amount"` - Currency string `json:"currency"` - CreatedAt time.Time `json:"created_at"` -} diff --git a/apps/api-server/internal/payment/gateways/types.go b/apps/api-server/internal/payment/gateways/types.go new file mode 100644 index 0000000..1c35c4b --- /dev/null +++ b/apps/api-server/internal/payment/gateways/types.go @@ -0,0 +1,83 @@ +package gateways + +import ( + "encoding/json" + "net/http" + "time" +) + +// StripeGateway implements payment processing via Stripe +type StripeGateway struct { + secretKey string + webhookSecret string + client *http.Client +} + +type PaymentRequest struct { + SubscriberID uint `json:"subscriber_id"` + InvoiceID uint `json:"invoice_id"` + Amount float64 `json:"amount"` + Currency string `json:"currency"` + CustomerID string `json:"customer_id,omitempty"` + Description string `json:"description,omitempty"` +} + +// PaymentResponse represents a payment response +type PaymentResponse struct { + TransactionID string `json:"transaction_id"` + Status string `json:"status"` + ClientSecret string `json:"client_secret"` + Amount float64 `json:"amount"` + Currency string `json:"currency"` + CreatedAt time.Time `json:"created_at"` +} + +// CustomerResponse represents a customer creation response +type CustomerResponse struct { + CustomerID string `json:"customer_id"` + Email string `json:"email"` + Name string `json:"name"` + CreatedAt time.Time `json:"created_at"` +} + +// RefundResponse represents a refund response +type RefundResponse struct { + RefundID string `json:"refund_id"` + Amount float64 `json:"amount"` + Status string `json:"status"` + CreatedAt time.Time `json:"created_at"` +} + +// PaymentStatusResponse represents payment status response +type PaymentStatusResponse struct { + TransactionID string `json:"transaction_id"` + Status string `json:"status"` + Amount float64 `json:"amount"` + Currency string `json:"currency"` + CreatedAt time.Time `json:"created_at"` +} + +// WebhookEvent represents a webhook event +type WebhookEvent struct { + Type string `json:"type"` + EventID string `json:"event_id"` + Created time.Time `json:"created"` + Data json.RawMessage `json:"data"` +} + +// InvoiceItem represents an invoice line item +type InvoiceItem struct { + Description string `json:"description"` + Amount float64 `json:"amount"` + Currency string `json:"currency"` + Quantity int `json:"quantity"` +} + +// InvoiceResponse represents an invoice response +type InvoiceResponse struct { + InvoiceID string `json:"invoice_id"` + Status string `json:"status"` + Amount float64 `json:"amount"` + Currency string `json:"currency"` + CreatedAt time.Time `json:"created_at"` +}