-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from spryker-eco/feature/eco-1924/dev-sevensenders
Release 1.0.0
- Loading branch information
Showing
46 changed files
with
1,849 additions
and
3 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -7,4 +7,4 @@ | |
*.sublime-* | ||
*.AppleDouble | ||
*.AppleDB | ||
*.AppleDesktop | ||
*.AppleDesktop |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/** | ||
* MIT License | ||
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. | ||
* For full license information, please view the LICENSE file that was distributed with this source code. | ||
*/ |
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,15 @@ | ||
build: | ||
environment: | ||
php: | ||
version: 7.1 | ||
|
||
checks: | ||
php: | ||
code_rating: true | ||
|
||
filter: | ||
excluded_paths: | ||
- config/* | ||
- tests/* | ||
- src/Generated/* | ||
- src/Pyz/* |
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,47 @@ | ||
language: php | ||
|
||
notifications: | ||
email: false | ||
|
||
sudo: required | ||
|
||
matrix: | ||
fast_finish: true | ||
include: | ||
- php: 7.1 | ||
|
||
services: | ||
- postgresql | ||
- redis | ||
- rabbitmq | ||
|
||
addons: | ||
postgresql: 9.4 | ||
|
||
apt: | ||
packages: | ||
- graphviz | ||
|
||
hosts: | ||
- zed.de.spryker.test | ||
- www.de.spryker.test | ||
|
||
env: | ||
global: | ||
- APPLICATION_ENV=devtest | ||
- APPLICATION_STORE=DE | ||
- MODULE_DIR=module | ||
- SHOP_DIR=current | ||
- MODULE_NAME=sevensenders | ||
|
||
cache: | ||
directories: | ||
- $SHOP_DIR/current/vendor | ||
- $HOME/.composer/cache | ||
|
||
before_install: | ||
- echo "extension = redis.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini | ||
|
||
script: | ||
- git clone -b 0.1.1 https://github.com/spryker-eco/eco-ci.git ecoci | ||
- ./ecoci/build/travis.sh |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
namespace: Sevensenders | ||
|
||
include: | ||
- tests/SprykerEcoTest/Zed/Sevensenders | ||
|
||
paths: | ||
tests: tests | ||
support: . | ||
log: tests/_output | ||
data: tests/_data | ||
envs: tests/_envs | ||
|
||
settings: | ||
bootstrap: _bootstrap.php | ||
suite_class: \PHPUnit_Framework_TestSuite | ||
colors: true | ||
memory_limit: 1024M | ||
log: true | ||
|
||
coverage: | ||
enabled: true | ||
whitelist: | ||
include: | ||
- 'src/*' |
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,29 @@ | ||
{ | ||
"name": "spryker-eco/sevensenders", | ||
"description": "Sevensenders Module", | ||
"require": { | ||
"php": ">=7.1", | ||
"spryker/kernel": "^3.0.0", | ||
"spryker/guzzle": "^2.2.0", | ||
"spryker/oms": "^8.0.0", | ||
"spryker/customer": "^7.10.0", | ||
"spryker/mail": "^4.0.0" | ||
}, | ||
"require-dev": { | ||
"spryker/code-sniffer": "*", | ||
"spryker/monolog": "*", | ||
"spryker/queue": "*", | ||
"spryker/testify": "*" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"SprykerEco\\": "src/SprykerEco/" | ||
} | ||
}, | ||
"minimum-stability": "dev", | ||
"autoload-dev": { | ||
"psr-4": { | ||
"SprykerTest\\": "tests/SprykerEcoTest/" | ||
} | ||
} | ||
} |
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,3 @@ | ||
{ | ||
"defaultLevel": 5 | ||
} |
17 changes: 17 additions & 0 deletions
17
src/SprykerEco/Shared/Sevensenders/SevensendersConstants.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,17 @@ | ||
<?php | ||
|
||
/** | ||
* MIT License | ||
* For full license information, please view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace SprykerEco\Shared\Sevensenders; | ||
|
||
/** | ||
* Declares global environment configuration keys. Do not use it for other class constants. | ||
*/ | ||
interface SevensendersConstants | ||
{ | ||
public const API_URL = 'SEVENSENDERS:API_URL'; | ||
public const API_KEY = 'SEVENSENDERS:API_KEY'; | ||
} |
16 changes: 16 additions & 0 deletions
16
src/SprykerEco/Shared/Sevensenders/Transfer/sevensenders.transfer.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0"?> | ||
<transfers xmlns="http://xsd.spryker.com" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://static.spryker.com http://static.spryker.com/transfer-01.xsd"> | ||
|
||
<transfer name="SevensendersRequest"> | ||
<property name="payload" type="array"/> | ||
</transfer> | ||
|
||
<transfer name="SevensendersResponse"> | ||
<property name="requestPayload" type="string"/> | ||
<property name="responsePayload" type="string"/> | ||
<property name="status" type="int"/> | ||
<property name="status" type="int"/> | ||
</transfer> | ||
</transfers> |
22 changes: 22 additions & 0 deletions
22
src/SprykerEco/Zed/Sevensenders/Business/Api/Adapter/AdapterInterface.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,22 @@ | ||
<?php | ||
|
||
/** | ||
* MIT License | ||
* For full license information, please view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace SprykerEco\Zed\Sevensenders\Business\Api\Adapter; | ||
|
||
use Generated\Shared\Transfer\SevensendersRequestTransfer; | ||
use Generated\Shared\Transfer\SevensendersResponseTransfer; | ||
|
||
interface AdapterInterface | ||
{ | ||
/** | ||
* @param \Generated\Shared\Transfer\SevensendersRequestTransfer $transfer | ||
* @param string $resource | ||
* | ||
* @return \Generated\Shared\Transfer\SevensendersResponseTransfer | ||
*/ | ||
public function send(SevensendersRequestTransfer $transfer, string $resource): SevensendersResponseTransfer; | ||
} |
151 changes: 151 additions & 0 deletions
151
src/SprykerEco/Zed/Sevensenders/Business/Api/Adapter/SevensendersApiAdapter.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,151 @@ | ||
<?php | ||
|
||
/** | ||
* MIT License | ||
* For full license information, please view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace SprykerEco\Zed\Sevensenders\Business\Api\Adapter; | ||
|
||
use Generated\Shared\Transfer\SevensendersRequestTransfer; | ||
use Generated\Shared\Transfer\SevensendersResponseTransfer; | ||
use GuzzleHttp\Client; | ||
use GuzzleHttp\Exception\RequestException; | ||
use GuzzleHttp\RequestOptions; | ||
use SprykerEco\Zed\Sevensenders\Business\Exception\SevensendersApiBadCredentialsException; | ||
use SprykerEco\Zed\Sevensenders\Business\Exception\SevensendersApiHttpRequestException; | ||
use SprykerEco\Zed\Sevensenders\Dependency\Service\SevensendersToUtilEncodingServiceInterface; | ||
use SprykerEco\Zed\Sevensenders\SevensendersConfig; | ||
|
||
class SevensendersApiAdapter implements AdapterInterface | ||
{ | ||
protected const DEFAULT_TIMEOUT = 45; | ||
|
||
public const ORDER_RESOURCE = 'orders'; | ||
public const SHIPMENT_RESOURCE = 'shipments'; | ||
public const AUTH_RESOURCE = 'token'; | ||
|
||
protected const RESPONSE_KEY_TOKEN = 'token'; | ||
|
||
protected const REQUEST_KEY_ACCESS_KEY = 'access_key'; | ||
|
||
protected const DEFAULT_HEADERS = [ | ||
'Content-Type' => 'application/json', | ||
]; | ||
|
||
/** | ||
* @var \GuzzleHttp\Client | ||
*/ | ||
protected $client; | ||
|
||
/** | ||
* @var \SprykerEco\Zed\Sevensenders\SevensendersConfig | ||
*/ | ||
protected $config; | ||
|
||
/** | ||
* @var \SprykerEco\Zed\Sevensenders\Dependency\Service\SevensendersToUtilEncodingServiceInterface | ||
*/ | ||
protected $utilEncodingService; | ||
|
||
/** | ||
* @param \SprykerEco\Zed\Sevensenders\SevensendersConfig $config | ||
* @param \SprykerEco\Zed\Sevensenders\Dependency\Service\SevensendersToUtilEncodingServiceInterface $utilEncodingService | ||
*/ | ||
public function __construct(SevensendersConfig $config, SevensendersToUtilEncodingServiceInterface $utilEncodingService) | ||
{ | ||
$this->config = $config; | ||
$this->utilEncodingService = $utilEncodingService; | ||
$this->client = new Client([ | ||
RequestOptions::TIMEOUT => static::DEFAULT_TIMEOUT, | ||
]); | ||
} | ||
|
||
/** | ||
* @param \Generated\Shared\Transfer\SevensendersRequestTransfer $transfer | ||
* @param string $resource | ||
* | ||
* @throws \SprykerEco\Zed\Sevensenders\Business\Exception\SevensendersApiHttpRequestException | ||
* | ||
* @return \Generated\Shared\Transfer\SevensendersResponseTransfer | ||
*/ | ||
public function send(SevensendersRequestTransfer $transfer, string $resource): SevensendersResponseTransfer | ||
{ | ||
try { | ||
$options = $this->prepareOptions($transfer); | ||
$response = $this->client->post( | ||
$this->getUrl($resource), | ||
$options | ||
); | ||
} catch (RequestException $requestException) { | ||
throw new SevensendersApiHttpRequestException( | ||
$requestException->getMessage(), | ||
$requestException->getCode(), | ||
$requestException | ||
); | ||
} | ||
|
||
$responseTransfer = new SevensendersResponseTransfer(); | ||
$responseTransfer->setStatus($response->getStatusCode()); | ||
$responseTransfer->setRequestPayload($options[RequestOptions::BODY]); | ||
$responseTransfer->setResponsePayload($response->getBody()->getContents()); | ||
|
||
return $responseTransfer; | ||
} | ||
|
||
/** | ||
* @throws \SprykerEco\Zed\Sevensenders\Business\Exception\SevensendersApiBadCredentialsException | ||
* | ||
* @return string | ||
*/ | ||
protected function auth(): string | ||
{ | ||
$response = $this->utilEncodingService->decodeJson($this->client->post($this->getUrl(static::AUTH_RESOURCE), [ | ||
RequestOptions::BODY => $this->utilEncodingService->encodeJson([ | ||
static::REQUEST_KEY_ACCESS_KEY => $this->config->getApiKey(), | ||
]), | ||
])->getBody()->getContents()); | ||
|
||
if (!array_key_exists(static::RESPONSE_KEY_TOKEN, $response)) { | ||
throw new SevensendersApiBadCredentialsException('Bad credentials', 401); | ||
} | ||
|
||
return 'Bearer ' . $response[static::RESPONSE_KEY_TOKEN]; | ||
} | ||
|
||
/** | ||
* @param string $resource | ||
* | ||
* @return string | ||
*/ | ||
protected function getUrl(string $resource): string | ||
{ | ||
return $this->config->getApiUrl() . $resource; | ||
} | ||
|
||
/**i | ||
* | ||
* @param \Generated\Shared\Transfer\SevensendersRequestTransfer $transfer | ||
* | ||
* @return array | ||
*/ | ||
protected function prepareOptions(SevensendersRequestTransfer $transfer): array | ||
{ | ||
$options[RequestOptions::BODY] = $this->utilEncodingService->encodeJson($transfer->getPayload()); | ||
$options[RequestOptions::HEADERS] = $this->prepareHeaders(); | ||
|
||
return $options; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
protected function prepareHeaders(): array | ||
{ | ||
$auth = [ | ||
'Authorization' => $this->auth(), | ||
]; | ||
|
||
return array_merge(static::DEFAULT_HEADERS, $auth); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...SprykerEco/Zed/Sevensenders/Business/Exception/SevensendersApiBadCredentialsException.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,14 @@ | ||
<?php | ||
|
||
/** | ||
* MIT License | ||
* For full license information, please view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace SprykerEco\Zed\Sevensenders\Business\Exception; | ||
|
||
use Exception; | ||
|
||
class SevensendersApiBadCredentialsException extends Exception | ||
{ | ||
} |
14 changes: 14 additions & 0 deletions
14
src/SprykerEco/Zed/Sevensenders/Business/Exception/SevensendersApiHttpRequestException.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,14 @@ | ||
<?php | ||
|
||
/** | ||
* MIT License | ||
* For full license information, please view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace SprykerEco\Zed\Sevensenders\Business\Exception; | ||
|
||
use Exception; | ||
|
||
class SevensendersApiHttpRequestException extends Exception | ||
{ | ||
} |
Oops, something went wrong.