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

Fix UpdateOrderParams for allow updating dollar amount values to zero #14

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

BrianLeishman
Copy link

Relevant issue: #13

This makes it possible to update dollar amounts of an order/transaction to zero.

⚠️ This is a breaking change! ⚠️

Normally I wouldn't request a breaking change at all, and this case we could get around that by create a new struct with the pointer versions and allowing someone to use either, but I feel since this is a bug, it's worth forcing the fix, otherwise (like in our case) failed transaction updates will go completely unnoticed.

I also added two helper functions, pulled straight from the AWS source for the same purpose:

https://github.com/aws/aws-sdk-go/blob/main/aws/convert_types.go

// Float64 returns a pointer to the float64 value passed in.
func Float64(v float64) *float64 {
	return &v
}

// Float64Value returns the value of the float64 pointer passed in or
// 0 if the pointer is nil.
func Float64Value(v *float64) float64 {
	if v != nil {
		return *v
	}
	return 0
}

These helper functions make it easier to switch between the pointer of a type and the value of the type, which looks like this (from the updated example file)

res5, err := client.UpdateOrder(taxjar.UpdateOrderParams{
	TransactionID: "13579-246810",
	Amount:        taxjar.Float64(152.72),
	Shipping:      taxjar.Float64(10),
	SalesTax:      taxjar.Float64(10.74),
	LineItems: []taxjar.OrderLineItem{
		{
			ID:                "1",
			Quantity:          1,
			ProductIdentifier: "12-34243-9",
			Description:       "Fuzzy Sweater",
			ProductTaxCode:    "20010",
			UnitPrice:         36.72,
			Discount:          5.51,
			SalesTax:          0,
		},
		{
			ID:                "2",
			Quantity:          1,
			ProductIdentifier: "12-34245-8",
			Description:       "TaxJar Designer T-shirt",
			ProductTaxCode:    "20010",
			UnitPrice:         111,
			SalesTax:          9.85,
		},
	},
})

This was tested in production via my fork already and I was able to confirm this fixed our issue.

@CLAassistant
Copy link

CLAassistant commented Nov 3, 2022

CLA assistant check
All committers have signed the CLA.

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

Successfully merging this pull request may close these issues.

None yet

2 participants