Skip to content

Commit

Permalink
fix: line item name (#84)
Browse files Browse the repository at this point in the history
* Slice line item name

* add changeset
  • Loading branch information
peelar committed Feb 1, 2024
1 parent 8e65ded commit 4b26f36
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/modern-news-cheat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"saleor-app-authorize-net": patch
---

Fixed the bug with Authorize.net returning errors when the line item name is longer than the db field restrictions. The app will now slice the name.
6 changes: 4 additions & 2 deletions src/modules/authorize-net/authorize-transaction-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,16 @@ export const authorizeTransaction = {
): AuthorizeNet.APIContracts.ArrayOfLineItem {
const lineItems = fragment.lines.map((line) => {
const lineItem = new ApiContracts.LineItemType();
// todo: refactoring idea: create our own type-safe factories of AuthorizeNet types that respect the db field requirements, e.g. max length
lineItem.setItemId(line.id.slice(0, 31)); // Authorize.net only allows 31 characters for this field.

if (line.__typename === "CheckoutLine") {
lineItem.setName(line.checkoutVariant.product.name);
lineItem.setName(line.checkoutVariant.product.name.slice(0, 31)); // Authorize.net only allows 31 characters for this field.
}

if (line.__typename === "OrderLine") {
lineItem.setName(line.orderVariant?.product.name);
invariant(line.orderVariant, "Order variant is missing from order line.");
lineItem.setName(line.orderVariant.product.name.slice(0, 31)); // Authorize.net only allows 31 characters for this field.
}

lineItem.setQuantity(line.quantity);
Expand Down

0 comments on commit 4b26f36

Please sign in to comment.