Skip to content

Commit

Permalink
Merge branch 'cotton-patches-3-and-4'
Browse files Browse the repository at this point in the history
  • Loading branch information
DragonBe committed Sep 1, 2019
2 parents f725f7a + 874fed3 commit bce767c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
15 changes: 13 additions & 2 deletions src/Vies/CheckVatResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -363,16 +363,27 @@ public function populate($row): void

$requiredFields = ['countryCode', 'vatNumber', 'requestDate', 'valid'];
foreach ($requiredFields as $requiredField) {
if (! isset($row->$requiredField)) {
if (! isset($row->{$requiredField})) {
throw new InvalidArgumentException('Required field "' . $requiredField . '" is missing');
}
}

$requestDate = $row->requestDate;
if (! $row->requestDate instanceof DateTime) {
// prepare request date
$requestDate = date_create_from_format(
self::VIES_DATETIME_FORMAT,
$row->requestDate
);
// Need to set time to zero - otherwise datetime would use current system time (which is not the response time)
$requestDate->setTime(0, 0, 0, 0);
}

$this
// required parameters
->setCountryCode($row->countryCode)
->setVatNumber($row->vatNumber)
->setRequestDate($row->requestDate)
->setRequestDate($requestDate)
->setValid($row->valid)
// optional parameters
->setName($row->traderName ?? '---')
Expand Down
10 changes: 6 additions & 4 deletions src/Vies/Vies.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,12 @@ public function validateVat(
}

try {
$response = $this->getSoapClient()->__soapCall('checkVatApprox', [$requestParams]);
// Soap returns "yyyy-mm-dd+hh:mm" so we need to convert it
$response->requestDate = date_create_from_format('Y-m-d\+H:i', $response->requestDate);
return new CheckVatResponse($response);
return new CheckVatResponse(
$this->getSoapClient()->__soapCall(
'checkVatApprox',
[$requestParams]
)
);
} catch (SoapFault $e) {
$message = sprintf(
'Back-end VIES service cannot validate the VAT number "%s%s" at this moment. '
Expand Down

0 comments on commit bce767c

Please sign in to comment.