Skip to content
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

Feature/eco 1924/master sevensenders #2

Merged
merged 30 commits into from
Oct 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
6ffd85f
ECO-1924 Add composer.json
vhrychenko Aug 14, 2018
76802d0
ECO-1924 Default adapters and module files
vhrychenko Aug 15, 2018
f8425eb
ECO-1924 Update adapters
vhrychenko Aug 15, 2018
c122309
ECO-1924 Add order handler skeleton + interface
vhrychenko Aug 15, 2018
cf07ea8
ECO-1924 Auth and shipment handlers
vhrychenko Aug 15, 2018
a0364fc
ECO-1924 Create shipment and order mappers
vhrychenko Aug 15, 2018
bcee535
ECO-1924 Create propel scheme
vhrychenko Aug 16, 2018
8efc925
ECO-1924 Update propel scheme
vhrychenko Aug 16, 2018
95491dc
ECO-1924 Update propel scheme
vhrychenko Aug 16, 2018
6a4ad59
ECO-1924 Updates
vhrychenko Aug 20, 2018
63c67f1
ECO-1924 Token helper / auth helper updates
vhrychenko Aug 20, 2018
e988f0b
ECO-1924 CI
vhrychenko Aug 21, 2018
ba23561
ECO-1924 Update CI
vhrychenko Aug 21, 2018
8832d40
ECO-1924 Update scrutinizer
vhrychenko Aug 21, 2018
18aafad
ECO-1924 Update handlers
vhrychenko Aug 22, 2018
40beb85
ECO-1924 Add config
vhrychenko Aug 22, 2018
3e1a11a
ECO-1924 Update auth logic and order handler
vhrychenko Aug 22, 2018
1b35f6f
ECO-1924 Update shipping handler
vhrychenko Aug 22, 2018
d671e63
ECO-1924 EM and refactor handlers
vhrychenko Aug 23, 2018
36ddd9a
ECO-1924 Update oms
vhrychenko Aug 23, 2018
d95c1a8
ECO-1924 Tests + licenses
vhrychenko Aug 28, 2018
95b8ee6
ECO-1924 Update composer.josn
vhrychenko Aug 28, 2018
11bea3b
ECO-1924 Update end of lines
vhrychenko Aug 28, 2018
68c8631
ECO-1924 Add util encoding service
vhrychenko Aug 29, 2018
e7ae5e0
ECO-1924 Remove table for token
vhrychenko Aug 29, 2018
9ee002b
ECO-1924 Return array and fix tests
vhrychenko Aug 29, 2018
86c250f
ECO-1924 Return array|null
vhrychenko Aug 29, 2018
d8154f9
eco-1924 Update address mapper
vhrychenko Oct 10, 2018
130634d
eco-1924 fix customer email value
vhrychenko Oct 10, 2018
1f8a791
Merge pull request #1 from spryker-eco/feature/eco-1924/dev-sevensenders
alex-galych Oct 18, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
*.sublime-*
*.AppleDouble
*.AppleDB
*.AppleDesktop
*.AppleDesktop
2 changes: 1 addition & 1 deletion .license
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.
*/
15 changes: 15 additions & 0 deletions .scrutinizer.yml
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/*
47 changes: 47 additions & 0 deletions .travis.yml
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
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2018 SPRYKER SYSTEMS GMBH
Copyright (c) 2016-present Spryker Systems GmbH

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
24 changes: 24 additions & 0 deletions codeception.yml
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/*'
29 changes: 29 additions & 0 deletions composer.json
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/"
}
}
}
3 changes: 3 additions & 0 deletions phpstan.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"defaultLevel": 5
}
17 changes: 17 additions & 0 deletions src/SprykerEco/Shared/Sevensenders/SevensendersConstants.php
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';
}
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>
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;
}
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);
}
}
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
{
}
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
{
}
Loading