Skip to content

Commit

Permalink
Release 1.1.7
Browse files Browse the repository at this point in the history
  • Loading branch information
vttn committed Jul 3, 2020
1 parent 269a9fc commit db7a20e
Show file tree
Hide file tree
Showing 18 changed files with 145 additions and 109 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.1.7
- [WAL-8566] Promotions
- Code refactoring

# 1.1.6
- Disable sales channel selection on showcases
- Add product attributes to transaction payload
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@
"wallee/sdk": "2.1.*"
},
"type": "shopware-platform-plugin",
"version": "1.1.6"
"version": "1.1.7"
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
/**
* Class ConfigurationController
*
* This class handles web calls that are made via the WhiteLabelMachinePayment settings page.
* This class handles web calls that are made via the WalleePayment settings page.
*
* @package WalleePayment\Core\Api\Config\Controller
* @RouteScope(scopes={"api"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
ApiClient,
Model\CreationEntityState,
Model\EntityQuery,
Model\PaymentMethodConfiguration};
Model\PaymentMethodConfiguration,
Model\RestLanguage};
use WalleePayment\Core\{
Api\PaymentMethodConfiguration\Entity\PaymentMethodConfigurationEntity,
Api\PaymentMethodConfiguration\Entity\PaymentMethodConfigurationEntityDefinition,
Checkout\PaymentHandler\WalleePaymentHandler,
Settings\Service\SettingsService};
use WalleePayment\WalleePayment;
Expand Down Expand Up @@ -74,6 +76,9 @@ class PaymentMethodConfigurationService {
*/
private $mediaSerializer;

/**
* @var
*/
private $languages;

/**
Expand Down Expand Up @@ -176,7 +181,7 @@ private function disablePaymentMethodConfigurations(Context $context): void
$criteria = (new Criteria())
->addFilter(new EqualsFilter('state', CreationEntityState::ACTIVE));

$walleePaymentMethodConfigurationRepository = $this->container->get('wallee_payment_method_configuration.repository');
$walleePaymentMethodConfigurationRepository = $this->container->get(PaymentMethodConfigurationEntityDefinition::ENTITY_NAME . '.repository');

$paymentMethodConfigurationEntities = $walleePaymentMethodConfigurationRepository
->search($criteria, $context)
Expand Down Expand Up @@ -249,7 +254,7 @@ private function enablePaymentMethodConfigurations(Context $context): void
$this->upsertPaymentMethod($id, $paymentMethodConfiguration, $context);


$this->container->get('wallee_payment_method_configuration.repository')
$this->container->get(PaymentMethodConfigurationEntityDefinition::ENTITY_NAME . '.repository')
->upsert([$data], $context);
}
}
Expand Down Expand Up @@ -314,7 +319,7 @@ protected function getPaymentMethodConfigurationEntity(
new EqualsFilter('paymentMethodConfigurationId', $paymentMethodConfigurationId)
);

return $this->container->get('wallee_payment_method_configuration.repository')
return $this->container->get(PaymentMethodConfigurationEntityDefinition::ENTITY_NAME . '.repository')
->search($criteria, $context)
->getEntities()
->first();
Expand All @@ -326,6 +331,10 @@ protected function getPaymentMethodConfigurationEntity(
* @param string $id
* @param \Wallee\Sdk\Model\PaymentMethodConfiguration $paymentMethodConfiguration
* @param \Shopware\Core\Framework\Context $context
*
* @throws \Wallee\Sdk\ApiException
* @throws \Wallee\Sdk\Http\ConnectionException
* @throws \Wallee\Sdk\VersioningException
*/
protected function upsertPaymentMethod(
string $id,
Expand Down Expand Up @@ -359,20 +368,24 @@ protected function upsertPaymentMethod(
/**
* @param \Wallee\Sdk\Model\PaymentMethodConfiguration $paymentMethodConfiguration
* @param \Shopware\Core\Framework\Context $context
*
* @return array
* @throws \Wallee\Sdk\ApiException
* @throws \Wallee\Sdk\Http\ConnectionException
* @throws \Wallee\Sdk\VersioningException
*/
protected function getPaymentMethodConfigurationTranslation(PaymentMethodConfiguration $paymentMethodConfiguration, Context $context): array
{
$translations = [];
$languages = $this->getAvailableLanguages($context);
$locales = array_map(
$translations = [];
$availableLanguages = $this->getAvailableLanguages($context);
$locales = array_map(
function ($language) {
/**
* @var \Shopware\Core\System\Language\LanguageEntity $language
*/
return $language->getLocale()->getCode();
},
$languages->jsonSerialize()
$availableLanguages->jsonSerialize()
);
foreach ($locales as $locale) {
$translations[$locale] = [
Expand All @@ -394,48 +407,70 @@ protected function getAvailableLanguages(Context $context): LanguageCollection
]), $context)->getEntities();
}

protected function translate($translatedString, $locale)
/**
* @param array $translatedString
* @param string $locale
*
* @return string|null
* @throws \Wallee\Sdk\ApiException
* @throws \Wallee\Sdk\Http\ConnectionException
* @throws \Wallee\Sdk\VersioningException
*/
protected function translate(array $translatedString, string $locale): ?string
{
$translation = null;

if (isset($translatedString[$locale])) {
return $translatedString[$locale];
$translation = $translatedString[$locale];
}

$primaryLanguage = $this->findPrimaryLanguage($locale);
if ($primaryLanguage !== false && isset($translatedString[$primaryLanguage->getIetfCode()])) {
return $translatedString[$primaryLanguage->getIetfCode()];
}
if (is_null($translation)) {

$primaryLanguage = $this->findPrimaryLanguage($locale);
if (!is_null($primaryLanguage) && isset($translatedString[$primaryLanguage->getIetfCode()])) {
$translation = $translatedString[$primaryLanguage->getIetfCode()];
}

if (isset($translatedString['en-US'])) {
return $translatedString['en-US'];
if (is_null($translation) && isset($translatedString['en-US'])) {
$translation = $translatedString['en-US'];
}
}

return null;
return $translation;
}

/**
* Returns the primary language in the given group.
*
* @param string $code
* @return \Wallee\Sdk\Model\RestLanguage
* @param $code
*
* @return \Wallee\Sdk\Model\RestLanguage|null
* @throws \Wallee\Sdk\ApiException
* @throws \Wallee\Sdk\Http\ConnectionException
* @throws \Wallee\Sdk\VersioningException
*/
protected function findPrimaryLanguage($code)
protected function findPrimaryLanguage(string $code): ?RestLanguage
{
$code = substr($code, 0, 2);
foreach ($this->getLanguages() as $language) {
if ($language->getIso2Code() == $code && $language->getPrimaryOfGroup()) {
if (($language->getIso2Code() == $code) && $language->getPrimaryOfGroup()) {
return $language;
}
}
return false;
return null;
}

protected function getLanguages()
/**
*
* @return array
* @throws \Wallee\Sdk\ApiException
* @throws \Wallee\Sdk\Http\ConnectionException
* @throws \Wallee\Sdk\VersioningException
*/
protected function getLanguages(): array
{
if ($this->languages == null) {
$this->languages = $this
->apiClient
->getLanguageService()
->all();
if (is_null($this->languages)) {
$this->languages = $this->apiClient->getLanguageService()->all();
}
return $this->languages;
}
Expand Down
3 changes: 2 additions & 1 deletion src/Core/Api/Refund/Service/RefundService.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use WalleePayment\Core\{
Api\Refund\Entity\RefundEntity,
Api\Transaction\Entity\TransactionEntity,
Api\Transaction\Entity\TransactionEntityDefinition,
Settings\Service\SettingsService,
Util\Payload\RefundPayload};

Expand Down Expand Up @@ -102,7 +103,7 @@ public function create(Transaction $transaction, float $refundableAmount, Contex
*/
public function getTransactionEntityByTransactionId(int $transactionId, Context $context): TransactionEntity
{
return $this->container->get('wallee_transaction.repository')
return $this->container->get(TransactionEntityDefinition::ENTITY_NAME .'.repository')
->search(new Criteria(), $context)
->getEntities()
->getByTransactionId($transactionId);
Expand Down
5 changes: 3 additions & 2 deletions src/Core/Api/Transaction/Service/OrderMailService.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
System\SalesChannel\SalesChannelEntity};
use Symfony\Component\HttpFoundation\ParameterBag;
use WalleePayment\Core\Api\Transaction\Entity\TransactionEntity;
use WalleePayment\Core\Api\Transaction\Entity\TransactionEntityDefinition;

/**
* Class OrderMailService
Expand Down Expand Up @@ -114,7 +115,7 @@ public function send(string $orderId, Context $context, string $technicalName =
*/
protected function getTransactionEntityByOrderId(string $orderId, Context $context): TransactionEntity
{
return $this->container->get('wallee_transaction.repository')
return $this->container->get(TransactionEntityDefinition::ENTITY_NAME .'.repository')
->search(new Criteria([$orderId]), $context)
->get($orderId);
}
Expand Down Expand Up @@ -223,6 +224,6 @@ protected function getMailTemplate(OrderEntity $order, Context $context, string
*/
protected function markTransactionEntityConfirmationEmailAsSent(string $orderId, Context $context)
{
$this->container->get('wallee_transaction.repository')->upsert([['id' => $orderId, 'confirmationEmailSent' => true]], $context);
$this->container->get(TransactionEntityDefinition::ENTITY_NAME .'.repository')->upsert([['id' => $orderId, 'confirmationEmailSent' => true]], $context);
}
}
10 changes: 6 additions & 4 deletions src/Core/Api/Transaction/Service/TransactionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
use WalleePayment\Core\{
Api\OrderDeliveryState\Handler\OrderDeliveryStateHandler,
Api\Refund\Entity\RefundEntityCollection,
Api\Refund\Entity\RefundEntityDefinition,
Api\Transaction\Entity\TransactionEntity,
Api\Transaction\Entity\TransactionEntityDefinition,
Settings\Options\Integration,
Settings\Service\SettingsService,
Util\LocaleCodeProvider,
Expand Down Expand Up @@ -206,7 +208,7 @@ public function upsert(
];

$data = array_filter($data);
$this->container->get('wallee_transaction.repository')->upsert([$data], $context);
$this->container->get(TransactionEntityDefinition::ENTITY_NAME .'.repository')->upsert([$data], $context);

} catch (\Exception $exception) {
$this->logger->critical(__CLASS__ . ' : ' . __FUNCTION__ . ' : ' . $exception->getMessage());
Expand Down Expand Up @@ -265,7 +267,7 @@ private function getOrderEntity(string $orderId, Context $context): OrderEntity
*/
public function getByOrderId(string $orderId, Context $context): TransactionEntity
{
return $this->container->get('wallee_transaction.repository')
return $this->container->get(TransactionEntityDefinition::ENTITY_NAME .'.repository')
->search(new Criteria([$orderId]), $context)
->get($orderId);
}
Expand Down Expand Up @@ -295,7 +297,7 @@ public function read(int $transactionId, string $salesChannelId): Transaction
*/
public function getByTransactionId(int $transactionId, Context $context): ?TransactionEntity
{
return $this->container->get('wallee_transaction.repository')
return $this->container->get(TransactionEntityDefinition::ENTITY_NAME .'.repository')
->search((new Criteria())->addAssociations(['refunds']), $context)
->getEntities()
->getByTransactionId($transactionId);
Expand All @@ -310,7 +312,7 @@ public function getByTransactionId(int $transactionId, Context $context): ?Trans
*/
public function getRefundEntityCollectionByTransactionId(int $transactionId, Context $context): ?RefundEntityCollection
{
return $this->container->get('wallee_refund.repository')
return $this->container->get(RefundEntityDefinition::ENTITY_NAME .'.repository')
->search(new Criteria(), $context)
->getEntities()
->filterByTransactionId($transactionId);
Expand Down
4 changes: 2 additions & 2 deletions src/Core/Api/WebHooks/Controller/WebHookController.php
Original file line number Diff line number Diff line change
Expand Up @@ -451,9 +451,9 @@ private function unholdDelivery(string $orderId, Context $context)
/**
* @var OrderDeliveryStateHandler $orderDeliveryStateHandler
*/
$orderEntity = $this->getOrderEntity($orderId, $context);
$order = $this->getOrderEntity($orderId, $context);
$orderDeliveryStateHandler = $this->container->get(OrderDeliveryStateHandler::class);
$orderDeliveryStateHandler->unhold($orderEntity->getDeliveries()->last()->getId(), $context);
$orderDeliveryStateHandler->unhold($order->getDeliveries()->last()->getId(), $context);
} catch (\Exception $exception) {
$this->logger->critical($exception->getTraceAsString());
}
Expand Down
1 change: 0 additions & 1 deletion src/Core/Checkout/PaymentHandler/WalleePaymentHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ public function finalize(
':salesChannelName' => $salesChannelContext->getSalesChannel()->getName(),
]);
$this->logger->info($errorMessage);
//throw new CustomerCanceledAsyncPaymentException($transaction->getOrderTransaction()->getId());
}
}
}
9 changes: 9 additions & 0 deletions src/Core/Util/Exception/InvalidPayloadException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php declare(strict_types=1);


namespace WalleePayment\Core\Util\Exception;


class InvalidPayloadException extends \InvalidArgumentException{

}
16 changes: 8 additions & 8 deletions src/Core/Util/Payload/RefundPayload.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

namespace WalleePayment\Core\Util\Payload;


use Wallee\Sdk\{
Model\RefundCreate,
Model\RefundType,
Model\Transaction,
Model\TransactionState};
use WalleePayment\Core\Util\Exception\InvalidPayloadException;

/**
* Class RefundPayload
Expand All @@ -28,16 +28,16 @@ public function get(Transaction $transaction, float $amount): ?RefundCreate
($transaction->getState() == TransactionState::FULFILL) &&
($amount <= floatval($transaction->getAuthorizationAmount()))
) {
$refund = new RefundCreate();
$refund->setAmount($amount);
$refund->setTransaction($transaction->getId());
$refund->setMerchantReference($this->fixLength($transaction->getMerchantReference(), 100));
$refund->setExternalId($this->fixLength(uniqid('refund_', true), 100));
$refund = (new RefundCreate())
->setAmount($amount)
->setTransaction($transaction->getId())
->setMerchantReference($this->fixLength($transaction->getMerchantReference(), 100))
->setExternalId($this->fixLength(uniqid('refund_', true), 100))
/** @noinspection PhpParamsInspection */
$refund->setType(RefundType::MERCHANT_INITIATED_ONLINE);
->setType(RefundType::MERCHANT_INITIATED_ONLINE);
if (!$refund->valid()) {
$this->logger->critical('Refund payload invalid:', $refund->listInvalidProperties());
throw new \Exception('Refund payload invalid:' . json_encode($refund->listInvalidProperties()));
throw new InvalidPayloadException('Refund payload invalid:' . json_encode($refund->listInvalidProperties()));
}
return $refund;
}
Expand Down

0 comments on commit db7a20e

Please sign in to comment.