Skip to content

Commit

Permalink
🐛 Fix bug OptOutXmlParser
Browse files Browse the repository at this point in the history
  • Loading branch information
fanirytonio authored and Doelia committed Dec 3, 2019
1 parent bcf1960 commit 1e3db11
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/Esendex/Parser/OptOutXmlParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Copyright (c) 2019, Commify Ltd.
* All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
Expand All @@ -13,7 +13,7 @@
* * Neither the name of Commify nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Expand All @@ -32,6 +32,7 @@
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause
* @link https://github.com/esendex/esendex-php-sdk
*/

namespace Esendex\Parser;

use Esendex\Model\OptOut;
Expand All @@ -53,16 +54,16 @@ public function parseOptOut($optOut)
$result->from($optOut->from);
$result->accountReference($optOut->accountreference);
$result->receivedAt($this->parseDateTime($optOut->receivedat));

return $result;
}

public function parsePostResponse($xml)
{
$response = simplexml_load_string($xml);
return $this->parseOptOut($response->optout);
}

public function encodePostRequest($accountReference, $phoneNumber)
{
if (strlen($phoneNumber) < 1)
Expand All @@ -76,27 +77,28 @@ public function encodePostRequest($accountReference, $phoneNumber)

$child = $doc->addChild("from");
$child->phonenumber = $phoneNumber;

return $doc->asXML();
}

public function parseMultipleResult($xml)
{
$response = simplexml_load_string($xml);
$optOuts = array();
foreach($response->optout as $optOut)
{
foreach ($response->optout as $optOut) {
$parsedOptOut = $this->parseOptOut($optOut);
$optOuts[] = $parsedOptOut;
$optOuts[] = $parsedOptOut;
}

$result = new OptOutsPage($response["startindex"], $response["totalcount"], $optOuts);
return $result;

return $result;
}

private function parseDateTime($value)
{
return \DateTime::createFromFormat(\DateTime::ISO8601, $value);
$array = (array) $value;
$date = $array[0];
return new \DateTime($date);
}
}

0 comments on commit 1e3db11

Please sign in to comment.