Skip to content

Commit

Permalink
Add check to subscription webhook for already processed checkout event
Browse files Browse the repository at this point in the history
  • Loading branch information
StevenWeathers committed Mar 31, 2024
1 parent ef9dd6e commit 396e08e
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions internal/webhook/subscription/subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ func (s *Service) HandleWebhook() http.HandlerFunc {
w.WriteHeader(http.StatusInternalServerError)
return
}

// check and see if we've already handled the subscription checkout complete event before
_, subExistsErr := s.dataSvc.GetSubscriptionBySubscriptionID(ctx, cs.Subscription.ID)
if subExistsErr == nil {
logger.Error(fmt.Sprintf("Subscription %s checkout already processed, skipping.", cs.Subscription.ID),
zap.String("eventId", event.ID))
return
}

if cs.Subscription.Items == nil || cs.Subscription.Items.Data == nil || len(cs.Subscription.Items.Data) < 1 {
logger.Error("Error getting subscription item from event", zap.String("eventId", event.ID),
zap.String("sessionId", cs.ID))
Expand Down

0 comments on commit 396e08e

Please sign in to comment.