Search code examples
phpopayo

SagePay XML basket


This is a quick one for anyone who knows sagepay or can spot what I cannot.

I have two baskets that get sent to sagepay:

This works:

<basket>
<agentId>vendor1</agentId> 
    <item>
        <description>Selling premier package</description>
        <quantity>1</quantity>
        <unitNetAmount>595</unitNetAmount>
        <unitTaxAmount>119.00</unitTaxAmount>
        <unitGrossAmount>714.00</unitGrossAmount>
        <totalGrossAmount>714.00</totalGrossAmount>
    </item>
</basket>

This comes back with a "Status Detail: 3021 : The Basket format is invalid." error?

<basket>
<agentId>vendor1</agentId> 
    <item>
        <description>Selling premier package</description>
        <quantity>1</quantity>
        <unitNetAmount>894</unitNetAmount>
        <unitTaxAmount>178.80</unitTaxAmount>
        <unitGrossAmount>1,072.80</unitGrossAmount>
        <totalGrossAmount>1,072.80</totalGrossAmount>
    </item>
</basket>

Can anyone spot why? :S

Thanks


Solution

  • I'll attempt to expand on Nathan's question/comment/answer as I just suffered from the same issue.

    When trying to implement SagePay's Server Integration method, I figured that the best place to start would be with their PHP demonstration source code as I suspect that Nathan did. Contained within are a number of classes for building up a basket and contacting SagePay through their API. Unfortunately it looks like there is fundamental flaw within how the BastketXML is exported resulting in what Nathan is describing above.

    Within /lib/classes/item.php you'll find on line 615:

    if (is_float($value))
    {
        $node = $basket->createElement($name, number_format($value, 2));
    }
    

    This relies upon local environment variables to format the number correctly whereas what's required by SagePay would be:

    if (is_float($value))
    {
        $node = $basket->createElement($name, number_format($value, 2, '.', ''));
    }