Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Continuous Order Number #46

Closed
biilmann opened this issue Apr 8, 2017 · 5 comments
Closed

Continuous Order Number #46

biilmann opened this issue Apr 8, 2017 · 5 comments

Comments

@biilmann
Copy link
Member

biilmann commented Apr 8, 2017

For accounting reasons we need a continuous order number for each sale, that we can use in invoices.

We'll still keep the UUID for each order (since it's useful for linking to the order when handling anonymous orders), but introduce and incrementing field as well.

@biilmann
Copy link
Member Author

biilmann commented Apr 8, 2017

Should only be set when the payment goes through

@brycekahle
Copy link
Contributor

Allow searching by this order number as well.

@rybit rybit modified the milestone: smashing-launch Aug 11, 2017
@brycekahle
Copy link
Contributor

Fixed in #86

@mraerino
Copy link
Member

mraerino commented Sep 5, 2019

While going through the code I noticed this can still happen.

E.g. when a transaction is failing, the invoice number is increased anyways.
https://github.com/netlify/gocommerce/blob/master/api/payments.go#L159-L177

	invoiceNumber, err := models.NextInvoiceNumber(tx, order.InstanceID)
	if err != nil {
		tx.Rollback()
		return internalServerError("We failed to generate a valid invoice ID, please try again later: %v", err)
	}

	tr := models.NewTransaction(order)
	processorID, err := charge(params.Amount, params.Currency, order, invoiceNumber)
	tr.ProcessorID = processorID
	tr.InvoiceNumber = invoiceNumber

	if err != nil {
		tr.FailureCode = strconv.FormatInt(http.StatusInternalServerError, 10)
		tr.FailureDescription = err.Error()
		tr.Status = models.FailedState
		tx.Create(tr)
		tx.Commit()
		return internalServerError("There was an error charging your card: %v", err).WithInternalError(err)
	}

The error case should rollback the invoice id. And the transaction should probably not get one if failed.

@mraerino mraerino reopened this Sep 5, 2019
@mraerino
Copy link
Member

Fixed by #182

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants