Skip to content

Commit

Permalink
Merge pull request #50 from omniva-baltic/Develop
Browse files Browse the repository at this point in the history
Develop from v1.0.15
  • Loading branch information
markakk authored Jan 18, 2024
2 parents 784f1cb + 84169d5 commit 668466b
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [1.0.16] - Fixes
- fixed server URl change
- improved server URL management

## [1.0.15] - Improvements
- changed to use local envelope scheme

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "mijora/omniva-api",
"description": "Omniva API wrapper",
"type": "library",
"version": "1.0.15",
"version": "1.0.16",
"authors": [
{
"name": "Modestas",
Expand Down
67 changes: 59 additions & 8 deletions src/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ class Request
/*
* @var string
*/
private $api_url = 'https://edixml.post.ee';
private $api_url_domain = 'https://edixml.post.ee';

/*
* @var string
*/
private $api_url_path = '/epmx/services/messagesService.wsdl';

/*
* Debuging
Expand All @@ -47,7 +52,7 @@ public function __construct($username, $password, $api_url = 'https://edixml.pos
$this->helper = new Helper();
$this->username = $username;
$this->password = $password;
$this->api_url = $api_url;
$this->setApiUrlDomain($api_url);
$this->debug = $debug;
}

Expand All @@ -59,15 +64,61 @@ public function getUsername()
return $this->username;
}

/*
* @return string
*/
private function getPassword()
{
return $this->password;
}

/*
* @param string $urlDomain
*/
public function setApiUrlDomain($urlDomain)
{
$this->api_url_domain = $urlDomain;
return $this;
}

/*
* @return string
*/
public function getApiUrlDomain()
{
return $this->api_url_domain;
}

/*
* @param string $urlPath
*/
public function setApiUrlPath($urlPath)
{
$this->api_url_path = $urlPath;
return $this;
}

/*
* @param string $url
*/
public function setApiUrl($url)
{
$this->api_url = $url;
$parsedUrl = parse_url($url);

$this->setApiUrlDomain($parsedUrl['scheme'] . '://' . $parsedUrl['host']);
$this->setApiUrlPath($parsedUrl['path']);

return $this;
}

/*
* @return string
*/
public function getApiUrl()
{
return $this->api_url_domain . $this->api_url_path;
}

/*
* @param string $request
* @return array
Expand All @@ -80,7 +131,7 @@ public function call($request)
try {
$barcodes = array();
$errors = array();
$url = $this->api_url . "/epmx/services/messagesService.wsdl";
$url = $this->getApiUrl();

$xmlResponse = $this->make_call($xml, $url);
$xml = $this->convert_response_to_xml($xmlResponse);
Expand Down Expand Up @@ -175,7 +226,7 @@ private function build_request_xml($request)
<soapenv:Header/>
<soapenv:Body>
<xsd:businessToClientMsgRequest>
<partner>' . $this->username . '</partner>';
<partner>' . $this->getUsername() . '</partner>';
$xml .= preg_replace("/<\\?xml.*\\?>/", '', $request, 1);
$xml .= '
</xsd:businessToClientMsgRequest>
Expand Down Expand Up @@ -264,7 +315,7 @@ public function get_labels($barcodes)
<soapenv:Header/>
<soapenv:Body>
<xsd:addrcardMsgRequest>
<partner>' . $this->username . '</partner>
<partner>' . $this->getUsername() . '</partner>
<sendAddressCardTo>response</sendAddressCardTo>
<barcodes>
' . $barcodeXML . '
Expand All @@ -275,7 +326,7 @@ public function get_labels($barcodes)

try {
$errors = array();
$url = $this->api_url . "/epmx/services/messagesService.wsdl";
$url = $this->getApiUrl();

$xmlResponse = $this->make_call($xml, $url);

Expand Down Expand Up @@ -314,7 +365,7 @@ public function get_labels($barcodes)
*/
public function getTracking()
{
$url = $this->api_url . '/epteavitus/events/from/' . date("c", strtotime("-1 week +1 day")) . '/for-client-code/' . $this->username;
$url = $this->getApiUrlDomain() . '/epteavitus/events/from/' . date("c", strtotime("-1 week +1 day")) . '/for-client-code/' . $this->getUsername();

$xmlResponse = $this->make_call(false, $url);

Expand Down
4 changes: 2 additions & 2 deletions src/Shipment/Shipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ class Shipment
*/
private $request;

public function setAuth($username, $password)
public function setAuth($username, $password, $api_url = 'https://edixml.post.ee', $debug = false)
{
$this->request = new Request($username, $password);
$this->request = new Request($username, $password, $api_url, $debug);
}

/**
Expand Down

0 comments on commit 668466b

Please sign in to comment.