feat: Square client dev mock for online payments and type additions
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -40,6 +40,10 @@ func (p *ProdClient) CreateCardOnFile(ctx context.Context, userID, cardToken str
|
|||||||
return nil, errors.New("square payments not yet configured — set SQUARE_ACCESS_TOKEN and SQUARE_LOCATION_ID in .env")
|
return nil, errors.New("square payments not yet configured — set SQUARE_ACCESS_TOKEN and SQUARE_LOCATION_ID in .env")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *ProdClient) CreateCardOnFileRaw(ctx context.Context, userID, cardNumber string, expMonth, expYear int, cvc string) (*CardOnFile, error) {
|
||||||
|
return nil, errors.New("square payments not yet configured — set SQUARE_ACCESS_TOKEN and SQUARE_LOCATION_ID in .env")
|
||||||
|
}
|
||||||
|
|
||||||
func (p *ProdClient) GetCardsOnFile(ctx context.Context, userID string) ([]CardOnFile, error) {
|
func (p *ProdClient) GetCardsOnFile(ctx context.Context, userID string) ([]CardOnFile, error) {
|
||||||
return nil, errors.New("square payments not yet configured — set SQUARE_ACCESS_TOKEN and SQUARE_LOCATION_ID in .env")
|
return nil, errors.New("square payments not yet configured — set SQUARE_ACCESS_TOKEN and SQUARE_LOCATION_ID in .env")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,6 +40,9 @@ func (d *devProdClient) RefundPayment(ctx context.Context, req RefundPaymentReq)
|
|||||||
func (d *devProdClient) CreateCardOnFile(ctx context.Context, userID, cardToken string) (*CardOnFile, error) {
|
func (d *devProdClient) CreateCardOnFile(ctx context.Context, userID, cardToken string) (*CardOnFile, error) {
|
||||||
return nil, fmt.Errorf("square payments not yet configured — set SQUARE_ACCESS_TOKEN and SQUARE_LOCATION_ID in .env")
|
return nil, fmt.Errorf("square payments not yet configured — set SQUARE_ACCESS_TOKEN and SQUARE_LOCATION_ID in .env")
|
||||||
}
|
}
|
||||||
|
func (d *devProdClient) CreateCardOnFileRaw(ctx context.Context, userID, cardNumber string, expMonth, expYear int, cvc string) (*CardOnFile, error) {
|
||||||
|
return nil, fmt.Errorf("square payments not yet configured — set SQUARE_ACCESS_TOKEN and SQUARE_LOCATION_ID in .env")
|
||||||
|
}
|
||||||
func (d *devProdClient) GetCardsOnFile(ctx context.Context, userID string) ([]CardOnFile, error) {
|
func (d *devProdClient) GetCardsOnFile(ctx context.Context, userID string) ([]CardOnFile, error) {
|
||||||
return nil, fmt.Errorf("square payments not yet configured — set SQUARE_ACCESS_TOKEN and SQUARE_LOCATION_ID in .env")
|
return nil, fmt.Errorf("square payments not yet configured — set SQUARE_ACCESS_TOKEN and SQUARE_LOCATION_ID in .env")
|
||||||
}
|
}
|
||||||
@@ -217,6 +220,39 @@ func (m *MockClient) CreateCardOnFile(ctx context.Context, userID, cardToken str
|
|||||||
return card, nil
|
return card, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *MockClient) CreateCardOnFileRaw(ctx context.Context, userID, cardNumber string, expMonth, expYear int, cvc string) (*CardOnFile, error) {
|
||||||
|
log.Printf("[SQUARE-MOCK] CreateCardOnFileRaw: user=%s", userID)
|
||||||
|
|
||||||
|
m.mu.Lock()
|
||||||
|
defer m.mu.Unlock()
|
||||||
|
|
||||||
|
if m.cards[userID] == nil {
|
||||||
|
m.cards[userID] = make(map[string]*CardOnFile)
|
||||||
|
}
|
||||||
|
|
||||||
|
cardID := fmt.Sprintf("mock_card_%d", time.Now().UnixNano())
|
||||||
|
last4 := cardNumber[len(cardNumber)-4:]
|
||||||
|
brands := map[string]string{"4": "VISA", "5": "MASTERCARD", "3": "AMEX", "6": "DISCOVER"}
|
||||||
|
brand := brands[string(cardNumber[0])]
|
||||||
|
if brand == "" {
|
||||||
|
brand = "VISA"
|
||||||
|
}
|
||||||
|
|
||||||
|
card := &CardOnFile{
|
||||||
|
ID: cardID,
|
||||||
|
CardID: "cfa_" + cardID,
|
||||||
|
Brand: brand,
|
||||||
|
Last4: last4,
|
||||||
|
ExpMonth: expMonth,
|
||||||
|
ExpYear: expYear,
|
||||||
|
Fingerprint: fmt.Sprintf("fp_%d", time.Now().UnixNano()),
|
||||||
|
IsDefault: len(m.cards[userID]) == 0,
|
||||||
|
}
|
||||||
|
m.cards[userID][cardID] = card
|
||||||
|
log.Printf("[SQUARE-MOCK] Card created: id=%s, brand=%s, last4=%s", cardID, card.Brand, card.Last4)
|
||||||
|
return card, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (m *MockClient) GetCardsOnFile(ctx context.Context, userID string) ([]CardOnFile, error) {
|
func (m *MockClient) GetCardsOnFile(ctx context.Context, userID string) ([]CardOnFile, error) {
|
||||||
log.Printf("[SQUARE-MOCK] GetCardsOnFile: user=%s", userID)
|
log.Printf("[SQUARE-MOCK] GetCardsOnFile: user=%s", userID)
|
||||||
|
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ type SquareClient interface {
|
|||||||
GetCheckout(ctx context.Context, checkoutID string) (*PaymentResult, error)
|
GetCheckout(ctx context.Context, checkoutID string) (*PaymentResult, error)
|
||||||
RefundPayment(ctx context.Context, req RefundPaymentReq) (*RefundResult, error)
|
RefundPayment(ctx context.Context, req RefundPaymentReq) (*RefundResult, error)
|
||||||
CreateCardOnFile(ctx context.Context, userID, cardToken string) (*CardOnFile, error)
|
CreateCardOnFile(ctx context.Context, userID, cardToken string) (*CardOnFile, error)
|
||||||
|
CreateCardOnFileRaw(ctx context.Context, userID, cardNumber string, expMonth, expYear int, cvc string) (*CardOnFile, error)
|
||||||
GetCardsOnFile(ctx context.Context, userID string) ([]CardOnFile, error)
|
GetCardsOnFile(ctx context.Context, userID string) ([]CardOnFile, error)
|
||||||
DeleteCardOnFile(ctx context.Context, cardID string) error
|
DeleteCardOnFile(ctx context.Context, cardID string) error
|
||||||
}
|
}
|
||||||
+3
-2
@@ -230,8 +230,9 @@ func main() {
|
|||||||
|
|
||||||
// User payment routes
|
// User payment routes
|
||||||
r.Post("/bookings/{id}/payment", payments.CreateBookingPayment)
|
r.Post("/bookings/{id}/payment", payments.CreateBookingPayment)
|
||||||
r.Get("/user/payment-methods", payments.GetUserPaymentMethods)
|
r.Get("/user/payment-methods", payments.GetUserPaymentMethods)
|
||||||
r.Delete("/user/payment-methods/{id}", payments.DeletePaymentMethod)
|
r.Post("/user/payment-methods", payments.CreatePaymentMethod)
|
||||||
|
r.Delete("/user/payment-methods/{id}", payments.DeletePaymentMethod)
|
||||||
r.Post("/bookings/{id}/tip", payments.CreateTipPayment)
|
r.Post("/bookings/{id}/tip", payments.CreateTipPayment)
|
||||||
r.Get("/bookings/{id}/payment-summary", payments.GetBookingPaymentSummary)
|
r.Get("/bookings/{id}/payment-summary", payments.GetBookingPaymentSummary)
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user