Skip to content

Commit

Permalink
Merge pull request #50 from PAYONE-GmbH/feature/PAYONE-78
Browse files Browse the repository at this point in the history
Add Shopware 6.2 compatibility.
  • Loading branch information
hreinberger authored Aug 11, 2020
2 parents 7209012 + 7c41451 commit 99d9da9
Show file tree
Hide file tree
Showing 101 changed files with 979 additions and 388 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
matrix:
operating-system: [ubuntu-latest]
php-versions: ['7.3', '7.4']
shopware-versions: ['v6.1.0', 'v6.1.1', 'v6.1.2', 'v6.1.3', 'v6.1.4', 'v6.1.5', 'v6.1.6', 'v6.2.0', 'v6.2.1', 'v6.2.2']
shopware-versions: ['v6.2.0', 'v6.2.1', 'v6.2.2', 'v6.2.3']
name: Shopware ${{ matrix.shopware-versions }} on PHP ${{ matrix.php-versions }}
services:
mysql:
Expand Down
4 changes: 2 additions & 2 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ phpstan:
dependencies:
- composer
script:
- git clone -b v6.1.0 https://github.com/shopware/development "${CI_PROJECT_DIR}/opt/shopware"
- git clone -b v6.2.0 https://github.com/shopware/development "${CI_PROJECT_DIR}/opt/shopware"
- mv ${CI_PROJECT_DIR}/opt /tmp/opt
- cp -r ${CI_PROJECT_DIR} /tmp/opt/shopware/custom/plugins/${CI_PROJECT_NAME}
- mv /tmp/opt ${CI_PROJECT_DIR}/opt
Expand Down Expand Up @@ -62,7 +62,7 @@ phpunit:
- composer
script:
- sudo apt-get update && sudo apt-get install default-mysql-client -y
- git clone -b v6.1.0 https://github.com/shopware/development "${CI_PROJECT_DIR}/opt/shopware"
- git clone -b v6.2.0 https://github.com/shopware/development "${CI_PROJECT_DIR}/opt/shopware"
- mv ${CI_PROJECT_DIR}/opt /tmp/opt
- cp -r ${CI_PROJECT_DIR} /tmp/opt/shopware/custom/plugins/${CI_PROJECT_NAME}
- mv /tmp/opt ${CI_PROJECT_DIR}/opt
Expand Down
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,15 @@ Bugfixes

Known Incompatibilities

* Backurlhandling in Shopware 6.2 is currently broken. If a customer gets redirected to their favorite payment method but decides to cancel and choose another one, no PAYONE payment methods are available. We're working on a fix to enable correct handling of this use case.
* Backurlhandling in Shopware 6.2 is currently broken. If a customer gets redirected to their favorite payment method but decides to cancel and choose another one, no PAYONE payment methods are available. We're working on a fix to enable correct handling of this use case.

# 1.1.1

New Features

* Enables the switch to PAYONE payment methods after ordering
* Multiple PAYONE transactions can now be handled in the administration per order

Maintenance

* Added compatibility for new status transitions in Shopware 6.2
11 changes: 11 additions & 0 deletions CHANGELOG_de-DE.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,15 @@ Bekannte Inkompatibilitäten

* Backurlhandling in Shopware 6.2 ist derzeit fehlerhaft. Wenn ein Kunde zu seiner bevorzugten Zahlungsmethode umgeleitet wird, sich aber entscheidet, zu stornieren und eine andere Zahlungsmethode zu wählen, stehen keine PAYONE-Zahlungsmethoden zur Verfügung. Wir arbeiten an einer Lösung, um eine korrekte Handhabung dieses Anwendungsfalles zu ermöglichen.

# 1.1.1

Neue Funktionen

* Ermöglicht den Wechsel auf PAYONE-Zahlungsarten nach der Bestellung
* In der Administration können mehrere PAYONE-Transaktionen innerhalb einer Bestellung eingezogen oder erstattet werden

Wartung

* Kompatibilität zu neuen Statusübergängen in Shopware 6.2 hergestellt

Übersetzt mit www.DeepL.com/Translator (kostenlose Version)
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "payone-gmbh/shopware-6",
"type": "shopware-platform-plugin",
"description": "PAYONE Payment Plugin",
"version": "1.1.0",
"version": "1.1.1",
"license": "MIT",
"authors": [
{
Expand All @@ -17,15 +17,15 @@
"role": "Contributor"
}
],
"minimum-stability": "RC",
"minimum-stability": "stable",
"prefer-stable": true,
"require": {
"php": "^7.2",
"ext-curl": "*",
"ext-json": "*",
"shopware/core": "*",
"shopware/administration": "*",
"shopware/storefront": "*"
"shopware/core": "^6.2.0",
"shopware/administration": "^6.2.0",
"shopware/storefront": "^6.2.0"
},
"require-dev": {
"dms/phpunit-arraysubset-asserts": "^0.1.0",
Expand Down
39 changes: 12 additions & 27 deletions src/Components/DataHandler/Transaction/TransactionDataHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,23 @@ public function getPaymentTransactionByPayoneTransactionId(Context $context, int
return PaymentTransaction::fromOrderTransaction($transaction, $transaction->getOrder());
}

public function enhanceStatusWebhookData(PaymentTransaction $paymentTransaction, array $transactionData): array
public function getCustomFieldsFromWebhook(PaymentTransaction $paymentTransaction, array $transactionData): array
{
$data = $this->utf8EncodeRecursive($transactionData);
$newCustomFields = [];
$existingCustomFields = $paymentTransaction->getCustomFields() ?? [];

$customFields = $paymentTransaction->getCustomFields() ?? [];
$currentSequenceNumber = array_key_exists(CustomFieldInstaller::SEQUENCE_NUMBER, $customFields) ? $customFields[CustomFieldInstaller::SEQUENCE_NUMBER] : 0;
$data[CustomFieldInstaller::SEQUENCE_NUMBER] = max((int) $transactionData['sequencenumber'], $currentSequenceNumber);
$data[CustomFieldInstaller::TRANSACTION_STATE] = strtolower($transactionData['txaction']);
$data[CustomFieldInstaller::ALLOW_CAPTURE] = $this->shouldAllowCapture($paymentTransaction, $transactionData);
$data[CustomFieldInstaller::ALLOW_REFUND] = $this->shouldAllowRefund($paymentTransaction, $transactionData);
$currentSequenceNumber = array_key_exists(CustomFieldInstaller::SEQUENCE_NUMBER, $existingCustomFields) ? $existingCustomFields[CustomFieldInstaller::SEQUENCE_NUMBER] : 0;
$newCustomFields[CustomFieldInstaller::SEQUENCE_NUMBER] = max((int) $transactionData['sequencenumber'], $currentSequenceNumber);

if (in_array($data[CustomFieldInstaller::TRANSACTION_STATE], [TransactionStatusService::ACTION_PAID, TransactionStatusService::ACTION_COMPLETED])) {
$data[CustomFieldInstaller::CAPTURED_AMOUNT] = $this->getCapturedAmount($paymentTransaction, $transactionData);
$newCustomFields[CustomFieldInstaller::TRANSACTION_STATE] = strtolower($transactionData['txaction']);
$newCustomFields[CustomFieldInstaller::ALLOW_CAPTURE] = $this->shouldAllowCapture($paymentTransaction, $transactionData);
$newCustomFields[CustomFieldInstaller::ALLOW_REFUND] = $this->shouldAllowRefund($paymentTransaction, $transactionData);

if (in_array($newCustomFields[CustomFieldInstaller::TRANSACTION_STATE], [TransactionStatusService::ACTION_PAID, TransactionStatusService::ACTION_COMPLETED])) {
$newCustomFields[CustomFieldInstaller::CAPTURED_AMOUNT] = $this->getCapturedAmount($paymentTransaction, $transactionData);
}

return $data;
return $newCustomFields;
}

public function saveTransactionData(PaymentTransaction $transaction, Context $context, array $data): void
Expand Down Expand Up @@ -177,20 +178,4 @@ private function getHandlerIdentifier(PaymentTransaction $paymentTransaction): s

return $handlerClass;
}

private function utf8EncodeRecursive(array $transactionData): array
{
foreach ($transactionData as &$transactionValue) {
if (is_array($transactionValue)) {
$transactionValue = $this->utf8EncodeRecursive($transactionValue);

continue;
}

$transactionValue = utf8_encode($transactionValue);
}
unset($transactionValue);

return $transactionData;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface TransactionDataHandlerInterface
{
public function getPaymentTransactionByPayoneTransactionId(Context $context, int $payoneTransactionId): ?PaymentTransaction;

public function enhanceStatusWebhookData(PaymentTransaction $paymentTransaction, array $transactionData): array;
public function getCustomFieldsFromWebhook(PaymentTransaction $paymentTransaction, array $transactionData): array;

public function saveTransactionData(PaymentTransaction $transaction, Context $context, array $data): void;

Expand Down
60 changes: 60 additions & 0 deletions src/Components/Helper/OrderFetcher.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

declare(strict_types=1);

namespace PayonePayment\Components\Helper;

use Shopware\Core\Checkout\Order\OrderEntity;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Sorting\FieldSorting;
use Shopware\Core\Framework\Uuid\Uuid;

class OrderFetcher implements OrderFetcherInterface
{
/** @var EntityRepositoryInterface */
private $orderRepository;

public function __construct(EntityRepositoryInterface $orderRepository)
{
$this->orderRepository = $orderRepository;
}

public function getOrderById(string $orderId, Context $context): ?OrderEntity
{
if (mb_strlen($orderId, '8bit') === 16) {
$orderId = Uuid::fromBytesToHex($orderId);
}

$criteria = $this->getOrderCriteria();
$criteria->addFilter(new EqualsFilter('id', $orderId));

return $this->orderRepository->search($criteria, $context)->first();
}

private function getOrderCriteria(): Criteria
{
$criteria = new Criteria();
$criteria->addAssociation('transactions');
$criteria->addAssociation('transactions.stateMachineState');
$criteria->addAssociation('orderCustomer');
$criteria->addAssociation('addresses');
$criteria->addAssociation('addresses.salutation');
$criteria->addAssociation('addresses.country');
$criteria->addAssociation('deliveries');
$criteria->addAssociation('deliveries.shippingMethod');
$criteria->addAssociation('deliveries.positions');
$criteria->addAssociation('deliveries.positions.orderLineItem');
$criteria->addAssociation('deliveries.shippingOrderAddress');
$criteria->addAssociation('deliveries.shippingOrderAddress.country');
$criteria->addAssociation('deliveries.shippingOrderAddress.salutation');
$criteria->addAssociation('deliveries.shippingOrderAddress.country');
$criteria->addAssociation('lineItems');
$criteria->addAssociation('currency');
$criteria->addSorting(new FieldSorting('lineItems.createdAt'));

return $criteria;
}
}
13 changes: 13 additions & 0 deletions src/Components/Helper/OrderFetcherInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace PayonePayment\Components\Helper;

use Shopware\Core\Checkout\Order\OrderEntity;
use Shopware\Core\Framework\Context;

interface OrderFetcherInterface
{
public function getOrderById(string $orderId, Context $context): ?OrderEntity;
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ public function capture(ParameterBag $parameterBag, Context $context): JsonRespo
$this->updateTransactionData($parameterBag, (float) $parameterBag->get('amount'));
$this->saveOrderLineItemData($parameterBag->get('orderLines', []), $context);

$transitionName = StateMachineTransitionActions::ACTION_PAY_PARTIALLY;
$transitionName = StateMachineTransitionActions::ACTION_PAID_PARTIALLY;

if ($parameterBag->get('complete')) {
$transitionName = StateMachineTransitionActions::ACTION_PAY;
$transitionName = StateMachineTransitionActions::ACTION_PAID;
}

$this->transactionStatusService->transitionByName(
Expand Down
Loading

0 comments on commit 99d9da9

Please sign in to comment.