mirror of
https://github.com/andwati/telecom-platform.git
synced 2026-10-24 05:32:16 +00:00
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
This commit is contained in:
@@ -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"`
|
||||
}
|
||||
|
||||
@@ -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"`
|
||||
}
|
||||
Reference in New Issue
Block a user