Skip to content

Commit dcb5eec

Browse files
author
Jeff Mataya
committed
Ignore errors when a capture has already occurred.
1 parent 4d8a3cb commit dcb5eec

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

middlewarehouse/consumers/capture/consumer.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"fmt"
55
"log"
6+
"strings"
67

78
"github.com/FoxComm/highlander/middlewarehouse/models/activities"
89
"github.com/FoxComm/highlander/middlewarehouse/shared/phoenix"
@@ -38,9 +39,17 @@ func (h CaptureConsumer) Handler(message metamorphosis.AvroMessage) error {
3839
return err
3940
}
4041
if err := h.phoenixClient.CapturePayment(capture); err != nil {
42+
// If the order is already captured, we don't want to fail because it's
43+
// possible that this was already captured by the customer.
44+
if strings.Contains(err.Error(), "is not in Auth state") || strings.Contains(err.Error(), "has already been captured") {
45+
log.Printf("Attempted to capture order %s that has already be captured", capture.ReferenceNumber)
46+
return nil
47+
}
48+
4149
log.Printf("Unable to capture payment with error: %s", err.Error())
4250
return err
4351
}
4452

53+
log.Printf("Successfully captured order %s", capture.ReferenceNumber)
4554
return nil
4655
}

middlewarehouse/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@ func main() {
3535
log.Panicf("Failed to start middlewarehouse with error %s", err.Error())
3636
}
3737

38-
port:= os.Getenv("PORT")
38+
port := os.Getenv("PORT")
3939
engine.Run(":" + port)
4040
}

0 commit comments

Comments
 (0)