-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Release 1.0.0 #1
Merged
alex-galych
merged 29 commits into
feature/eco-1924/master-sevensenders
from
feature/eco-1924/dev-sevensenders
Oct 18, 2018
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
6ffd85f
ECO-1924 Add composer.json
vhrychenko 76802d0
ECO-1924 Default adapters and module files
vhrychenko f8425eb
ECO-1924 Update adapters
vhrychenko c122309
ECO-1924 Add order handler skeleton + interface
vhrychenko cf07ea8
ECO-1924 Auth and shipment handlers
vhrychenko a0364fc
ECO-1924 Create shipment and order mappers
vhrychenko bcee535
ECO-1924 Create propel scheme
vhrychenko 8efc925
ECO-1924 Update propel scheme
vhrychenko 95491dc
ECO-1924 Update propel scheme
vhrychenko 6a4ad59
ECO-1924 Updates
vhrychenko 63c67f1
ECO-1924 Token helper / auth helper updates
vhrychenko e988f0b
ECO-1924 CI
vhrychenko ba23561
ECO-1924 Update CI
vhrychenko 8832d40
ECO-1924 Update scrutinizer
vhrychenko 18aafad
ECO-1924 Update handlers
vhrychenko 40beb85
ECO-1924 Add config
vhrychenko 3e1a11a
ECO-1924 Update auth logic and order handler
vhrychenko 1b35f6f
ECO-1924 Update shipping handler
vhrychenko d671e63
ECO-1924 EM and refactor handlers
vhrychenko 36ddd9a
ECO-1924 Update oms
vhrychenko d95c1a8
ECO-1924 Tests + licenses
vhrychenko 95b8ee6
ECO-1924 Update composer.josn
vhrychenko 11bea3b
ECO-1924 Update end of lines
vhrychenko 68c8631
ECO-1924 Add util encoding service
vhrychenko e7ae5e0
ECO-1924 Remove table for token
vhrychenko 9ee002b
ECO-1924 Return array and fix tests
vhrychenko 86c250f
ECO-1924 Return array|null
vhrychenko d8154f9
eco-1924 Update address mapper
vhrychenko 130634d
eco-1924 fix customer email value
vhrychenko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that is not how psr-4 works. please check other modules on the proper changes for it. |
||
"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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move 401 to constant |
||
} | ||
|
||
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is not how psr-4 works!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've already known it. I should change my branches quickly and I couldn't find the right way earlier