Question

When querying Shopify transaction data (from the python api client) for transactions involving SagePay, we're receiving an error when the client attempts to parse the returned xml:

Error(Error('Unable to parse xml data: not well-formed (invalid token): line 24, column 7',),)

This appears to be being caused by the transaction/receipt element contents including an invalid xml tag name to indicate the 3D-secure status.

For instance:

<?xml version="1.0" encoding="UTF-8"?>
<transactions type="array">
  <transaction>
    <order-id type="integer">123456789</order-id>
    <amount type="decimal">123.45</amount>
    <status>success</status>
    <kind>sale</kind>
    <authorization>{-REDACTED-}</authorization>
    <created-at type="datetime">2012-01-01T01:01:01+00:00</created-at>
    <gateway>sage_pay_form</gateway>
    <id type="integer">123456789</id>
    <test type="boolean">false</test>
    <receipt>
      <VendorTxCode>123456789</VendorTxCode>
      <VPSTxId>{-REDACTED-}</VPSTxId>
      <Status>OK</Status>
      <StatusDetail>0000 : The Authorisation was Successful.</StatusDetail>
      <TxAuthNo>123456789</TxAuthNo>
      <AVSCV2>SECURITY CODE MATCH ONLY</AVSCV2>
      <AddressResult>NOTMATCHED</AddressResult>
      <PostCodeResult>NOTMATCHED</PostCodeResult>
      <CV2Result>MATCHED</CV2Result>
      <GiftAid>0</GiftAid>
      <3DSecureStatus>OK</3DSecureStatus>
      <CAVV>-REDACTED-</CAVV>
      <CardType>MC</CardType>
      <Last4Digits>1234</Last4Digits>
      <Amount>123.45</Amount>
    </receipt>
  </transaction>
</transactions>

As '3DSecureStatus' is not a valid xml element name, xml parsing fails.

We're currently not in a position to use the json api as the python api client doesn't support it.

Was it helpful?

Solution

Shopify will need to be fixed to not send an invalid XML element name. E.g. the element name could be prefixed with an underscore. I'll update here when that is done.

The lack of JSON support in the shopify python API is actually caused by the lack of support in pyactiveresource. I have sent JSON support patches upstream to activeresource which you could use. They seem to have been ignored due to lack of upstream activity.

UPDATE: Shopify has been fixed to not return XML with invalid element names. Instead it will prefix an invalid start character with an underscore in the element name.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top