public function appendToDom(\DOMNode $parent)
{
$node = $parent->appendChild(new \DOMElement('Card'));
// Append parameters.
$node->appendChild(new \DOMElement('CVV', $this['CVV']));
// Only one of the following field groups needs to be included; If more
// than one is present, they will be given the following order of
// precedence. To avoid unintended results only populate one field per
// transaction.
$cardData = ['MagneprintData' => false, 'EncryptedTrack2Data' => true, 'EncryptedTrack1Data' => true, 'EncryptedCardData' => true, 'Track2Data' => false, 'Track1Data' => false];
do {
foreach ($cardData as $field => $isEncrypted) {
if (!empty($this[$field])) {
$node->appendChild(new \DOMElement($field, strtoupper($this[$field])));
if ($isEncrypted) {
$node->appendChild(new \DOMElement('CardDataKeySerialNumber', strtoupper($this['CardDataKeySerialNumber'])));
$node->appendChild(new \DOMElement('EncryptedFormat', $this['EncryptedFormat']));
}
break 2;
}
}
if (!empty($this['CardNumber'])) {
$node->appendChild(new \DOMElement('CardNumber', $this['CardNumber']));
}
if (!empty($this['ExpirationMonth']) && !empty($this['ExpirationYear'])) {
$time = gmmktime(0, 0, 0, $this['ExpirationMonth'], 1, $this['ExpirationYear']);
$node->appendChild(new \DOMElement('ExpirationMonth', gmdate('m', $time)));
$node->appendChild(new \DOMElement('ExpirationYear', gmdate('y', $time)));
}
} while (false);
}