-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add: Transaction details for Validate and Sell
- Loading branch information
Showing
9 changed files
with
221 additions
and
25 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
lib/Checkdomain/TeleCash/IPG/API/Model/TransactionDetails.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
namespace Checkdomain\TeleCash\IPG\API\Model; | ||
|
||
class TransactionDetails implements ElementInterface | ||
{ | ||
/** | ||
* @var string $namespace | ||
*/ | ||
private $namespace; | ||
|
||
/** | ||
* @var string $comments | ||
*/ | ||
private $comments; | ||
|
||
/** | ||
* @var string $invoiceNumber | ||
*/ | ||
private $invoiceNumber; | ||
|
||
/** | ||
* TransactionDetails constructor. | ||
* | ||
* @param string $namespace | ||
* @param string $comments | ||
* @param string|null $invoiceNumber | ||
*/ | ||
public function __construct($namespace, $comments, $invoiceNumber = null) | ||
{ | ||
$this->namespace = $namespace; | ||
$this->comments = $comments; | ||
$this->invoiceNumber = $invoiceNumber; | ||
} | ||
|
||
/** | ||
* @param \DOMDocument $document | ||
* | ||
* @return \DOMElement | ||
*/ | ||
public function getXML(\DOMDocument $document) | ||
{ | ||
$xml = $document->createElement(sprintf('%s:TransactionDetails', $this->namespace)); | ||
|
||
$comments = $document->createElement('ns1:Comments'); | ||
$comments->textContent = $this->comments; | ||
|
||
$xml->appendChild($comments); | ||
|
||
if (!empty($this->invoiceNumber)) { | ||
$invoiceNumber = $document->createElement('ns1:InvoiceNumber'); | ||
$invoiceNumber->textContent = $this->invoiceNumber; | ||
|
||
$xml->appendChild($invoiceNumber); | ||
} | ||
|
||
return $xml; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
tests/Checkdomain/TeleCash/IPG/API/Model/TransactionDetailsTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
namespace Checkdomain\TeleCash\IPG\API\Model; | ||
|
||
/** | ||
* Test case for Payment | ||
* | ||
* @package Checkdomain\TeleCash\IPG\API\Model | ||
*/ | ||
class TransactionDetailsTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
|
||
/** | ||
* @param string $comments | ||
* @param string $invoiceNumber | ||
* | ||
* @dataProvider dataProvider | ||
*/ | ||
public function testXMLGeneration($comments, $invoiceNumber) | ||
{ | ||
$ccData = new TransactionDetails($comments, $invoiceNumber); | ||
$document = new \DOMDocument('1.0', 'UTF-8'); | ||
$xml = $ccData->getXML($document); | ||
$document->appendChild($xml); | ||
|
||
$elementPayment = $document->getElementsByTagName('ns2:TransactionDetails'); | ||
$this->assertEquals(1, $elementPayment->length, 'Expected element TransactionDetails not found'); | ||
|
||
$children = []; | ||
/** @var \DOMNode $child */ | ||
foreach ($elementPayment->item(0)->childNodes as $child) { | ||
$children[$child->nodeName] = $child->nodeValue; | ||
} | ||
|
||
$this->assertArrayHasKey('ns1:Comments', $children, 'Expected element Comments not found'); | ||
$this->assertEquals($comments, $children['ns1:Comments'], 'Comments data id did not match'); | ||
|
||
if ($invoiceNumber !== null) { | ||
$this->assertArrayHasKey('ns1:InvoiceNumber', $children, 'Expected element InvoiceNumber not found'); | ||
$this->assertEquals($invoiceNumber, $children['ns1:InvoiceNumber'], 'InvoiceNumber did not match'); | ||
} else { | ||
$this->assertArrayNotHasKey('ns1:InvoiceNumber', $children, 'Unexpected element InvoiceNumber was found'); | ||
} | ||
} | ||
|
||
/** | ||
* Provides some test values | ||
* | ||
* @return array | ||
*/ | ||
public function dataProvider() | ||
{ | ||
return [ | ||
['Testkommentar', null], | ||
['Testkommentar', '1234-TestTestTest'] | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.