mirror of
https://github.com/rjNemo/rentease.git
synced 2026-06-11 05:06:52 +00:00
Upgrade Stripe SDK from v79 to v83 across the codebase. Update all imports to use github.com/stripe/stripe-go/v83 and refactor client usage to match the new API, including changes to PaymentIntents listing. Update documentation and plans to reference the new version. Remove references to the old version from go.mod and go.sum.
85 lines
2.3 KiB
Go
85 lines
2.3 KiB
Go
package booking
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"log/slog"
|
|
"testing"
|
|
|
|
"github.com/stripe/stripe-go/v83"
|
|
|
|
"github.com/rjNemo/rentease/internal/config"
|
|
)
|
|
|
|
func TestHandleChargeRefundedUpdatesAmount(t *testing.T) {
|
|
store := &mockStore{}
|
|
stripeID := "pi_123"
|
|
status := "succeeded"
|
|
_, _ = store.UpsertStripePayment(&Payment{
|
|
BookingID: 42,
|
|
Amount: 100,
|
|
PaymentMethod: config.PaymentMethod("Card"),
|
|
StripePaymentID: &stripeID,
|
|
StripeStatus: &status,
|
|
})
|
|
|
|
svc, err := NewService(slog.New(slog.DiscardHandler), store, nil, nil, nil)
|
|
if err != nil {
|
|
t.Fatalf("NewService returned error: %v", err)
|
|
}
|
|
|
|
charge := &stripe.Charge{
|
|
ID: "ch_123",
|
|
Amount: 10000,
|
|
AmountRefunded: 2500,
|
|
PaymentIntent: &stripe.PaymentIntent{ID: stripeID},
|
|
}
|
|
|
|
if err := svc.HandleChargeRefunded(context.Background(), charge); err != nil {
|
|
t.Fatalf("HandleChargeRefunded returned error: %v", err)
|
|
}
|
|
|
|
updated, err := store.FindStripePayment(stripeID)
|
|
if err != nil {
|
|
t.Fatalf("expected payment to be present: %v", err)
|
|
}
|
|
|
|
if updated.Amount != 75 {
|
|
t.Fatalf("expected amount 75, got %v", updated.Amount)
|
|
}
|
|
if updated.StripeStatus == nil || *updated.StripeStatus != "refunded" {
|
|
t.Fatalf("expected status refunded, got %v", updated.StripeStatus)
|
|
}
|
|
}
|
|
|
|
func TestHandleChargeRefundedUnknownPayment(t *testing.T) {
|
|
store := &mockStore{}
|
|
svc, _ := NewService(slog.New(slog.DiscardHandler), store, nil, nil, nil)
|
|
|
|
charge := &stripe.Charge{PaymentIntent: &stripe.PaymentIntent{ID: "pi_missing"}}
|
|
|
|
if err := svc.HandleChargeRefunded(context.Background(), charge); err != nil {
|
|
t.Fatalf("expected no error, got %v", err)
|
|
}
|
|
}
|
|
|
|
func TestHandleChargeRefundedStoreError(t *testing.T) {
|
|
store := &mockStore{}
|
|
stripeID := "pi_321"
|
|
status := "succeeded"
|
|
_, _ = store.UpsertStripePayment(&Payment{
|
|
BookingID: 1,
|
|
Amount: 10,
|
|
PaymentMethod: config.PaymentMethod("Card"),
|
|
StripePaymentID: &stripeID,
|
|
StripeStatus: &status,
|
|
})
|
|
store.err = errors.New("db error")
|
|
|
|
svc, _ := NewService(slog.New(slog.DiscardHandler), store, nil, nil, nil)
|
|
charge := &stripe.Charge{PaymentIntent: &stripe.PaymentIntent{ID: stripeID}}
|
|
|
|
if err := svc.HandleChargeRefunded(context.Background(), charge); err == nil {
|
|
t.Fatalf("expected error when store fails")
|
|
}
|
|
}
|