taxjar-go
taxjar-go copied to clipboard
Fix `UpdateOrderParams` for allow updating dollar amount values to zero
Relevant issue: https://github.com/taxjar/taxjar-go/issues/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.