0

Basically I am trying to add Google Checkout order processing (level 2 integration) into a CakePHP app using the Google Checkout PHP sample code.

I can successfully create carts and receive notifications sent from Google to my app, however it cannot acknowledge these properly.

The function in google's code to do this echo's this:

<?xml version="1.0" encoding="UTF-8" ?><notification-acknowledgment xmlns="http://checkout.google.com/schema/2" serial-number="119963104284921-00001-7" />

However Google Checkout receives that code like this:

<?xml version=1.0 encoding=UTF-8 ?><notification-acknowledgment xmlns="http://checkout.google.com/schema/2" serial-number=119963104284921-00001-7 />

I can't work out what is causing this, I don't think it has anything to do with Cake and I've disabled PHP short tags so I can use inline XML but this makes no difference.

If I remove the first < from the string, the function echo's the rest of the code correctly, leave it in and it brakes (obviously this also applies for the ? and closing > symbol too, I just cant't have all of them at once!).

I have been able to replicate this myself in attempt to remove any unseen stuff being done in the Google Code using the function below. It does exactly the same thing but is contained within a (Cake) controller and hard codes the variables.

public function blank($tags = null) {
    $schema = 'http://checkout.google.com/schema/2';
    $serial = '119963104284921-00001-7';
    if ($tags != null) {
        $acknowledgment = '<?xml version="1.0" encoding="UTF-8" ?'.'>'.'<notification-acknowledgment xmlns="'.$schema.' '.'serial-number="'.$serial.'" />';
    } else {
        $acknowledgment = '?xml version="1.0" encoding="UTF-8" ?>'.'<notification-acknowledgment xmlns="'.$schema.' '.'serial-number="'.$serial.'" />';
    }
    $this->set('_ack', $acknowledgment);
}

The IF statement is used to show the difference the < symbol makes.

Calling it with nothing ($tags == null) gives this output:

<?xml version="1.0" encoding="UTF-8" ?><notification-acknowledgment xmlns="http://checkout.google.com/schema/2" serial-number="119963104284921-00001-7" />

Source.

Calling it with any other value ($tags != null) gives this output:

<?xml version=1.0 encoding=UTF-8 ?><notification-acknowledgment xmlns="http://checkout.google.com/schema/2" serial-number=119963104284921-00001-7 />

Source.

My question (finally!) is, why does this happen? and how can I get it output the XML correctly?

Sorry if I've missed something really obvious, but I'd rather have it pointed out here than faff around getting nowhere for another day!

j0k
  • 22,600
  • 28
  • 79
  • 90
fenfe1
  • 71
  • 1
  • 6
  • BTW, security flaw. This URL: http://edge.atlantis.upsac.co.uk/ remove the PHP API viewer, I can see address details, postcodes and more. Few others too but for security I have not pointed. – TheBlackBenzKid Jan 30 '12 at 15:40

3 Answers3

0

this "problem" has to do with the PHP interpreter.

There are solutions but everything in View not in the Controlled.

//var
$questionmark = "?";
echo "<".$questionmark."xml version=\"1.0\" encoding=\"utf-8\"".$questionmark.">";
// separate
echo '<' . '?xml version="1.0" encoding="utf-8"?' . '>';
del_dan
  • 873
  • 1
  • 9
  • 16
  • Presumably to do this i'd have to get the XML echoed in the view? instead of where it is at the moment (inside Google's Sample Code, called by a controller)? – fenfe1 Jan 30 '12 at 20:57
  • The variables "$schema" and "$serial send them to View, and builds the xml in the View – del_dan Jan 30 '12 at 22:16
  • using this code in the view `'<' . '?xml version="1.0" encoding="utf-8"?' . '>'.'';` I still get incorrect code :( - `` – fenfe1 Jan 30 '12 at 22:53
  • No , its not outputting the double quotes on everything expect the xmlns statement. I.e. `version=1.0` should read `version="1.0"` – fenfe1 Jan 31 '12 at 01:02
  • trying to do a echo instead of saving in an Var – del_dan Jan 31 '12 at 07:34
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/7198/discussion-between-fenfe1-and-del-dan) – fenfe1 Jan 31 '12 at 14:05
0

You forgot to close the quotes on the xmlns attribute, that's the probable cause. Try this:

$acknowledgment = '<?xml version="1.0" encoding="UTF-8" ?'.'>'.'<notification-acknowledgment xmlns="'.$schema.'" '.'serial-number="'.$serial.'" />';
bfavaretto
  • 71,580
  • 16
  • 111
  • 150
  • I've updated the code but I still get broken XML, the links above should update but if not the version without a proper XML start tag gives this: `?xml version="1.0" encoding="UTF-8" ?>` and the one with gives this: `` – fenfe1 Jan 30 '12 at 17:32
0

Some XML parsers do not allow specifying the encoding in capital letters (e.g. UTF-8 is incorrect).

Try changing the encoding to "utf-8" to see if that fixes it.

Mihai Ionescu
  • 2,108
  • 1
  • 12
  • 15