Skip to content

Commit

Permalink
Move error check into condition
Browse files Browse the repository at this point in the history
  • Loading branch information
mraerino committed Sep 9, 2019
1 parent b2178c7 commit b448bb2
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions api/payments.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,16 +205,16 @@ func (a *API) PaymentCreate(w http.ResponseWriter, r *http.Request) error {
tr.InvoiceNumber = invoiceNumber
order.PaymentProcessor = provider.Name()

if pendingErr, ok := err.(*payments.PaymentPendingError); ok {
tr.Status = models.PendingState
tr.ProviderMetadata = pendingErr.Metadata()
tx.Create(tr)
tx.Save(order)
tx.Commit()
return sendJSON(w, 200, tr)
}

if err != nil {
if pendingErr, ok := err.(*payments.PaymentPendingError); ok {
tr.Status = models.PendingState
tr.ProviderMetadata = pendingErr.Metadata()
tx.Create(tr)
tx.Save(order)
tx.Commit()
return sendJSON(w, 200, tr)
}

tr.FailureCode = strconv.FormatInt(http.StatusInternalServerError, 10)
tr.FailureDescription = err.Error()
tr.Status = models.FailedState
Expand Down

0 comments on commit b448bb2

Please sign in to comment.