From Form to XML

Well, I say this only once: please, guys, stay on topic. :slight_smile:

Debbie, I’m sorry to say that Anthony gave you the answer and it is an answer that works, whether you like it or not. At least, with the information we have.

Definitely, to send the credit card information to them in XML, they gave you an ASP example. You only need to find the equivalent functions in PHP but the XML will be included in that code they gave you.

For the receiving part, when they’ve answered you letting you know if the transaction has gone through or not, and the details, you do need to use an object.

And, sorry, I know that you stayed late to try to figure out the answer but if you never used XML, you’re not going to learn this in just a few hours of Google…not a few days. So take it easy.

Yet, it is something that you have to do yourself, and need to learn it and understand it if you want to be able to apply it (here or in any other project).

I quite understand the feeling of having to face a new challenge of learning OOP programming. I started with procedural programming languages and had to take that step too (in my time, it was PASCAL, COBOL and QBASIC).

An object is only a list of properties and methods (=functions) directly associated to the object itself. I’ll put an example.

A person is an object. It has properties: brown hair, blue eyes, two legs…
and it has methods: it can drink, run, eat…

In OOP (and PHP), you create an object by defining it and giving it its basics properties and values and methods (functions)

So I will create an object in PHP. You do so by creating a class


<?php
class person {
     public $eye_color;
     public $hair_color;
     public $number_of_legs;
     public $gender;

  public function __construct($eyes, $hair, $legs, $gender)  
  {
    $this->eye_color = $eyes;                 
    $this->hair_color = $hair;                  
    $this->number_of_legs=$legs;
    $this->gender=$gender; 
 }



     public function running($origin, $destination){
            //code here for the function running

     }

    public function eating($food){
      // code here for the function eating
   }
}
?>

But this is just a model. After that, when I use it I want to create my own person and personalize it to my needs (maybe, he will have brown eyes?

So I need a copy of the first person created and have access to it so I can change and manipulate its properties (change the eye color, or the hair color, or the gender, or maybe he lost one leg…

As I said, I need a copy of the first person and keep the info in a variable, so I have access to it



$myNewPerson = new person('brown','blonde','1','female');
   

And after that, I can get to all the information I need and change it or simply display it. To view one of the values of the person I created and display it


<?php echo $myNewPerson->hair; ?>

will output ‘blonde’ because that’s the value I gave it.

The example Anthony gives you is the same: you have a bit of XML that list some users.

An XML document needs a root document, an element that opens at the very beginning and closes at the very bottom (in HTML the root element is html)

<root>
  <users>
    <user name="anthony" id="1" />
    <user name="debbie" id="2" />
  </users>
</root>

In this XML, the root element is called root, and it has a node named users with two user children.

If you want to have access to it in a PHP fashion, then you need to transform it into PHP, and that’s newSimpleXML does for you. It will transform the XML you received from the payment gateway into something that you can manipulate with PHP.

And you don’t need to write the class and create it. It’s already done.

I hope that you can understand this. Else, I don’t know how to explain it :slight_smile: