Prev | Current Page 607 | Next

Emilian Balanescu and Cristian Darie

"Beginning PHP and MySQL E-Commerce: From Novice to Professional, Second Edition"

..
$document_root = $xml_card_data->appendChild($document_root);
}
For reading the XML document, you can use the DOMDocument object, but in the ExtractXml() method, we
preferred to use a new and unique feature of PHP 5 called SimpleXML. Although less complex and powerful than
DOMDocument, the SimpleXML extension makes parsing XML data a piece of cake by transforming it into a data
structure you can simply iterate through:
// Extract information from XML credit card data
private function ExtractXml($decryptedData)
{
$xml = simplexml_load_string($decryptedData);
$this->_mCardHolder = (string) $xml->CardHolder;
$this->_mCardNumber = (string) $xml->CardNumber;
$this->_mIssueDate = (string) $xml->IssueDate;
$this->_mExpiryDate = (string) $xml->ExpiryDate;
$this->_mIssueNumber = (string) $xml->IssueNumber;
$this->_mCardType = (string) $xml->CardType;
}
The EncryptData() method starts by using the CreateXml() method to package the details supplied in the
SecureCard constructor into XML format:
// Encrypts the XML credit card data
private function EncryptData()
{
// Put data into XML doc
$this->CreateXml();
CHAPTER 16 ?–  MANAGING CUSTOMER DETAILS 497
Next, the XML string contained in the resultant XML document is encrypted into a single string and stored in the
$_mEncryptedData member:
// Encrypt data
$this->_mEncryptedData =
SymmetricCrypt::Encrypt($this->_mXmlCardData->saveXML());
Finally, the $_mIsEncrypted flag is set to true to indicate that the credit card data has been encrypted:
// Set encrypted flag
$this->_mIsEncrypted = true;
}
The DecryptData() method gets the XML credit card data from its encrypted form, decrypts it, and populates
class attributes with the ExtractXml() method:
// Decrypts XML credit card data
private function DecryptData()
{
// Decrypt data
$decrypted_data = SymmetricCrypt::Decrypt($this->_mEncryptedData);
// Extract data from XML
$this->ExtractXml($decrypted_data);
// Set decrypted flag
$this->_mIsDecrypted = true;
}
Next, we define a few properties for the class.


Pages:
595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619
centrum medyczne Poker strategia koluszki galanteria hotelowa agencja detektywistyczna