Skip to content

Commit

Permalink
OMG-25752 - Truncate fields before sending to Shippo (#11)
Browse files Browse the repository at this point in the history
OMG-25752 - Truncate fields before sending to Shippo
  • Loading branch information
slavick authored Oct 24, 2024
2 parents 3ede812 + a240d6c commit ade2e9e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions client/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ func (c *Client) CreateAddress(input *models.AddressInput, shippoSubAccountID st
return nil, errors.New("nil input")
}

// Truncate phone to 50 characters to avoid Stripe API errors
if len(input.Phone) > 50 {
input.Phone = input.Phone[:50]
}

output := &models.Address{}
err := c.do(http.MethodPost, "/addresses/", input, output, c.subAccountHeader(shippoSubAccountID))
return output, err
Expand Down
11 changes: 11 additions & 0 deletions client/sub_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ func (c *Client) CreateSubAccount(input *models.SubAccountInput) (*models.SubAcc
return nil, errors.New("nil input")
}

// Truncate fields to avoid Stripe API errors
if len(input.FirstName) > 30 {
input.FirstName = input.FirstName[:30]
}
if len(input.LastName) > 30 {
input.LastName = input.LastName[:30]
}
if len(input.CompanyName) > 50 {
input.CompanyName = input.CompanyName[:50]
}

output := &models.SubAccount{}
err := c.doWithoutVersion(http.MethodPost, "/shippo-accounts", input, output, nil)
return output, err
Expand Down

0 comments on commit ade2e9e

Please sign in to comment.