Skip to content

Commit dda16e3

Browse files
committed
Change: Allow custom amounts for validation
1 parent 4e06912 commit dda16e3

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

lib/Checkdomain/TeleCash/IPG/API/Model/Payment.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ class Payment implements ElementInterface
1616
private $amount;
1717

1818
/**
19-
* @param string $hostedDataId
20-
* @param float $amount
19+
* @param string|null $hostedDataId
20+
* @param float|null $amount
2121
*/
22-
public function __construct($hostedDataId, $amount = null)
22+
public function __construct($hostedDataId = null, $amount = null)
2323
{
2424
$this->hostedDataId = $hostedDataId;
2525
$this->amount = $amount;
@@ -32,13 +32,16 @@ public function __construct($hostedDataId, $amount = null)
3232
*/
3333
public function getXML(\DOMDocument $document)
3434
{
35-
$xml = $document->createElement('ns1:Payment');
36-
$hostedDataId = $document->createElement('ns1:HostedDataID');
37-
$hostedDataId->textContent = $this->hostedDataId;
35+
$xml = $document->createElement('ns1:Payment');
3836

39-
$xml->appendChild($hostedDataId);
37+
if (!empty($this->hostedDataId)) {
38+
$hostedDataId = $document->createElement('ns1:HostedDataID');
39+
$hostedDataId->textContent = $this->hostedDataId;
4040

41-
if ($this->amount !== null) {
41+
$xml->appendChild($hostedDataId);
42+
}
43+
44+
if (!empty($this->amount)) {
4245
$amount = $document->createElement('ns1:ChargeTotal');
4346
$amount->textContent = $this->amount;
4447
$currency = $document->createElement('ns1:Currency');

lib/Checkdomain/TeleCash/IPG/API/Request/Action/Validate.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Checkdomain\TeleCash\IPG\API\Request\Action;
44

55
use Checkdomain\TeleCash\IPG\API\Model\CreditCardData;
6+
use Checkdomain\TeleCash\IPG\API\Model\Payment;
67
use Checkdomain\TeleCash\IPG\API\Request\Action;
78
use Checkdomain\TeleCash\IPG\API\Response\Error;
89
use Checkdomain\TeleCash\IPG\API\Response\Action\Validation;
@@ -17,14 +18,22 @@ class Validate extends Action
1718
/**
1819
* @param OrderService $service
1920
* @param CreditCardData $creditCardData
21+
* @param float $amount
2022
*/
21-
public function __construct(OrderService $service, CreditCardData $creditCardData)
23+
public function __construct(OrderService $service, CreditCardData $creditCardData, $amount = 1.0)
2224
{
2325
parent::__construct($service);
2426

2527
$xml = $this->document->createElement('ns2:Validate');
2628
$ccData = $creditCardData->getXML($this->document);
2729
$xml->appendChild($ccData);
30+
31+
if ($amount > 1.0) {
32+
$payment = new Payment(null, $amount);
33+
$paymentData = $payment->getXML($this->document);
34+
$xml->appendChild($paymentData);
35+
}
36+
2837
$this->element->getElementsByTagName('ns2:Action')->item(0)->appendChild($xml);
2938
}
3039

lib/Checkdomain/TeleCash/TeleCash.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,19 @@ public function setDebugMode($debug)
6565
*
6666
* @param string $ccNumber
6767
* @param string $ccValid
68+
* @param float $amount
6869
*
6970
* @return Response\Action\Validation|Response\Error
7071
* @throws \Exception
7172
*/
72-
public function validate($ccNumber, $ccValid)
73+
public function validate($ccNumber, $ccValid, $amount = 1.0)
7374
{
7475
$service = $this->getService();
7576

7677
$validMonth = substr($ccValid, 0, 2);
7778
$validYear = substr($ccValid, 3, 4);
7879
$ccData = new Model\CreditCardData($ccNumber, $validMonth, $validYear);
79-
$validateAction = new Request\Action\Validate($service, $ccData);
80+
$validateAction = new Request\Action\Validate($service, $ccData, $amount);
8081

8182
return $validateAction->validate();
8283
}

0 commit comments

Comments
 (0)