Skip to content

Commit

Permalink
Ignore errors when a capture has already occurred.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Mataya committed Jan 11, 2017
1 parent 4d8a3cb commit dcb5eec
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions middlewarehouse/consumers/capture/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"fmt"
"log"
"strings"

"github.com/FoxComm/highlander/middlewarehouse/models/activities"
"github.com/FoxComm/highlander/middlewarehouse/shared/phoenix"
Expand Down Expand Up @@ -38,9 +39,17 @@ func (h CaptureConsumer) Handler(message metamorphosis.AvroMessage) error {
return err
}
if err := h.phoenixClient.CapturePayment(capture); err != nil {
// If the order is already captured, we don't want to fail because it's
// possible that this was already captured by the customer.
if strings.Contains(err.Error(), "is not in Auth state") || strings.Contains(err.Error(), "has already been captured") {
log.Printf("Attempted to capture order %s that has already be captured", capture.ReferenceNumber)
return nil
}

log.Printf("Unable to capture payment with error: %s", err.Error())
return err
}

log.Printf("Successfully captured order %s", capture.ReferenceNumber)
return nil
}
2 changes: 1 addition & 1 deletion middlewarehouse/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ func main() {
log.Panicf("Failed to start middlewarehouse with error %s", err.Error())
}

port:= os.Getenv("PORT")
port := os.Getenv("PORT")
engine.Run(":" + port)
}

0 comments on commit dcb5eec

Please sign in to comment.