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

transactionRequest errors on array of lineItems #332

Open
Critter opened this issue Aug 26, 2018 · 5 comments
Open

transactionRequest errors on array of lineItems #332

Critter opened this issue Aug 26, 2018 · 5 comments

Comments

@Critter
Copy link

Critter commented Aug 26, 2018

I didn't know where else to ask this.

The schema says that transactionRequestType takes
<xs:element name="lineItems" type="anet:ArrayOfLineItem" minOccurs="0"/>
an array of lineItem.

The example on the documention site only shows 1 item being passed in.

"lineItems": {
    "lineItem": {
        "itemId": "1",
        "name": "vase",
        "description": "Cannes logo",
        "quantity": "18",
        "unitPrice": "45.00"
    }
}

Wouldn't an array of lineitems be like this:

"lineItems": [
        {
          "lineItem": {
            "itemId": "10077",
            "name": "Fake name for something",
            "description": "dog.com",
            "quantity": 1,
            "unitPrice": "399.00"
          }
        },
        {
          "lineItem": {
            "itemId": "10077",
            "name": "fake name for something",
            "description": "cat.com",
            "quantity": 1,
            "unitPrice": "399.00"
          }
        }
      ]

This throws back an error saying that lineItems is an invalid element.

I'm creating my lineItems like this:

public function getLineItems()
{
	$result = [];
	foreach ($this->lineItems as $lineitem) {
		$arr = array(
			"lineItem" => array(
				"itemId" => $lineitem->itemId,
				"name" => mb_strimwidth($lineitem->name,0,31,''),
				"description" => $lineitem->description,
				"quantity" => $lineitem->quantity,
				"unitPrice" => $lineitem->unitPrice
			)
		);
		$result[] = $arr;
	}
	return $result;
}

and using them in my request like this:

public function generatePaymentRequest()
{
  $result = array(
    "createTransactionRequest" => array(
      "merchantAuthentication" => array(
        "name" => $this->authnet->name,
        "transactionKey" => $this->authnet->transactionkey
      ),
      "refId" => $this->refId,
      "transactionRequest" => array(
        "transactionType" => $this->transactionType,
        "amount" => $this->amount,
        "profile" => array(
          "customerProfileId" => $this->customerProfileId,
          "paymentProfile" => array(
            "paymentProfileId" => $this->paymentProfileId
          ),
        ),
        "lineItems" => $this->getLineItems() <-----<
      ),
    )
  );
  return json_encode($result);
}
@gnongsie
Copy link
Contributor

Hi @Critter

Can you refer to this issue #116 ? It might have the answer you are looking for.

@Critter
Copy link
Author

Critter commented Aug 27, 2018

I was hopeful, but I'm still having issues.

This is a valid request according to the docs. I've run this with my data, and it's created a 2-lined order

{
  "createTransactionRequest": {
    "merchantAuthentication": {
      "name": "zzzzzzz",
      "transactionKey": "zzzzzzz"
    },
    "refId": "xnumber-ref",
    "transactionRequest": {
      "transactionType": "authCaptureTransaction",
      "amount": 798,
      "profile": {
        "customerProfileId": "8675309",
        "paymentProfile": {
          "paymentProfileId": "48595683"
        }
      },
      "lineItems": {
        "lineItem" : {
          "itemId": "10077",
          "name": "Yearly Subscription",
          "description": "dog.com",
          "quantity": 1,
          "unitPrice": "399.00"
        },
        "lineItem" : {
          "itemId": "10077",
          "name": "Yearly Subscription",
          "description": "cat.com",
          "quantity": 1,
          "unitPrice": "399.00"
        }
      }
    }
  }
}

The problem is, is that it's not valid JSON, if you try to validate it you get a SyntaxError: Duplicate key 'lineItem' on line 25

validated JSON would have the lineitems like this:

{
  "createTransactionRequest": {
    "merchantAuthentication": {
      "name": "zzzzzzz",
      "transactionKey": "zzzzzzz"
    },
    "refId": "xnumber-ref",
    "transactionRequest": {
      "transactionType": "authCaptureTransaction",
      "amount": 798,
      "profile": {
        "customerProfileId": "8675309",
        "paymentProfile": {
          "paymentProfileId": "48595683"
        }
      },
      "lineItems": [
        {
          "itemId": "10077",
          "name": "Yearly Subscription",
          "description": "dog.com",
          "quantity": 1,
          "unitPrice": "399.00"
        },
        {
          "itemId": "10077",
          "name": "Yearly Subscription",
          "description": "cat.com",
          "quantity": 1,
          "unitPrice": "399.00"
        }
      ]
    }
  }
}

@gnongsie
Copy link
Contributor

I agree that this is not valid JSON, depending on the validator you used. We have taken certain liberties with the JSON validation to ensure that this works in our context.

@ashtru ashtru added the awaiting-reply Issues awaiting reply from developer label Aug 28, 2018
@Critter
Copy link
Author

Critter commented Aug 29, 2018

Something should reflect this somewhere, though, no? Or at least the JSON example should show more than 1 lineitem since it doesn't match with the schema.

@gnongsie
Copy link
Contributor

Thank you for the suggestion. I'll relay that information to the relevant team to have it documented in some way so that developers are not inconvenienced.

@chsriniv9 chsriniv9 removed the awaiting-reply Issues awaiting reply from developer label Oct 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

5 participants