Skip to content

Commit

Permalink
Merge pull request #580 from Adyen/prepare-release
Browse files Browse the repository at this point in the history
Prepare release 4.2.1
  • Loading branch information
goran-stamenkovski-logeecom authored Dec 9, 2024
2 parents 507d0fe + fe9d288 commit 9ad6eaa
Show file tree
Hide file tree
Showing 25 changed files with 1,027 additions and 96 deletions.
10 changes: 9 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
}
],
"description": "Official Shopware 6 Plugin to connect to Payment Service Provider Adyen",
"version": "4.2.0",
"version": "4.2.1",
"type": "shopware-platform-plugin",
"license": "MIT",
"require": {
Expand Down Expand Up @@ -48,5 +48,13 @@
"allow-plugins": {
"symfony/*": true
}
},
"scripts": {
"post-install-cmd": [
"rm -f vendor/composer/installed.php"
],
"post-update-cmd": [
"rm -f vendor/composer/installed.php"
]
}
}
8 changes: 7 additions & 1 deletion src/AdyenPaymentShopware6.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@

namespace Adyen\Shopware;

use Adyen\Shopware\Entity\AdyenPayment\AdyenPaymentEntityDefinition;
use Adyen\Shopware\Entity\Notification\NotificationEntityDefinition;
use Adyen\Shopware\Entity\PaymentCapture\PaymentCaptureEntityDefinition;
use Adyen\Shopware\Entity\PaymentResponse\PaymentResponseEntityDefinition;
use Adyen\Shopware\Entity\PaymentStateData\PaymentStateDataEntityDefinition;
use Adyen\Shopware\Entity\Refund\RefundEntityDefinition;
use Adyen\Shopware\Handlers\KlarnaDebitRiskPaymentMethodHandler;
use Adyen\Shopware\PaymentMethods\KlarnaDebitRiskPaymentMethod;
use Adyen\Shopware\Service\ConfigurationService;
Expand Down Expand Up @@ -278,7 +281,10 @@ private function removePluginData(): void
$tables = [
NotificationEntityDefinition::ENTITY_NAME,
PaymentStateDataEntityDefinition::ENTITY_NAME,
PaymentResponseEntityDefinition::ENTITY_NAME
PaymentResponseEntityDefinition::ENTITY_NAME,
AdyenPaymentEntityDefinition::ENTITY_NAME,
PaymentCaptureEntityDefinition::ENTITY_NAME,
RefundEntityDefinition::ENTITY_NAME
];
$connection = $this->container->get(Connection::class);
foreach ($tables as $table) {
Expand Down
73 changes: 63 additions & 10 deletions src/Handlers/AbstractPaymentMethodHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,18 @@
use Adyen\AdyenException;
use Adyen\Client;
use Adyen\Model\Checkout\CheckoutPaymentMethod;
use Adyen\Model\Checkout\Company;
use Adyen\Model\Checkout\EncryptedOrderData;
use Adyen\Model\Checkout\LineItem;
use Adyen\Model\Checkout\PaymentRequest;
use Adyen\Shopware\Models\PaymentRequest as IntegrationPaymentRequest;
use Adyen\Model\Checkout\Address;
use Adyen\Model\Checkout\Amount;
use Adyen\Model\Checkout\BrowserInfo;
use Adyen\Model\Checkout\Name;
use Adyen\Model\Checkout\PaymentResponse;
use Adyen\Service\Checkout\PaymentsApi;
use Adyen\Shopware\PaymentMethods\RatepayDirectdebitPaymentMethod;
use Adyen\Shopware\PaymentMethods\RatepayPaymentMethod;
use Adyen\Shopware\Util\CheckoutStateDataValidator;
use Adyen\Shopware\Exception\PaymentCancelledException;
use Adyen\Shopware\Exception\PaymentFailedException;
Expand All @@ -46,6 +49,7 @@
use Adyen\Shopware\Service\PaymentStateDataService;
use Adyen\Shopware\Service\Repository\SalesChannelRepository;
use Adyen\Shopware\Util\Currency;
use Adyen\Shopware\Util\RatePayDeviceFingerprintParamsProvider;
use Psr\Log\LoggerInterface;
use Shopware\Core\Checkout\Order\Aggregate\OrderTransaction\OrderTransactionStateHandler;
use Shopware\Core\Checkout\Payment\Cart\AsyncPaymentTransactionStruct;
Expand Down Expand Up @@ -109,6 +113,11 @@ abstract class AbstractPaymentMethodHandler implements AsynchronousPaymentHandle
*/
protected CheckoutStateDataValidator $checkoutStateDataValidator;

/**
* @var RatePayDeviceFingerprintParamsProvider
*/
protected RatePayDeviceFingerprintParamsProvider $ratePayFingerprintParamsProvider;

/**
* @var PaymentStateDataService
*/
Expand Down Expand Up @@ -181,10 +190,11 @@ abstract class AbstractPaymentMethodHandler implements AsynchronousPaymentHandle
* AbstractPaymentMethodHandler constructor.
*
* @param OrdersService $ordersService
* @param ClientService $clientService
* @param ConfigurationService $configurationService
* @param ClientService $clientService
* @param Currency $currency
* @param CheckoutStateDataValidator $checkoutStateDataValidator
* @param RatePayDeviceFingerprintParamsProvider $ratePayFingerprintParamsProvider
* @param PaymentStateDataService $paymentStateDataService
* @param SalesChannelRepository $salesChannelRepository
* @param PaymentResponseHandler $paymentResponseHandler
Expand All @@ -203,6 +213,7 @@ public function __construct(
ClientService $clientService,
Currency $currency,
CheckoutStateDataValidator $checkoutStateDataValidator,
RatePayDeviceFingerprintParamsProvider $ratePayFingerprintParamsProvider,
PaymentStateDataService $paymentStateDataService,
SalesChannelRepository $salesChannelRepository,
PaymentResponseHandler $paymentResponseHandler,
Expand All @@ -220,6 +231,7 @@ public function __construct(
$this->currency = $currency;
$this->configurationService = $configurationService;
$this->checkoutStateDataValidator = $checkoutStateDataValidator;
$this->ratePayFingerprintParamsProvider = $ratePayFingerprintParamsProvider;
$this->paymentStateDataService = $paymentStateDataService;
$this->salesChannelRepository = $salesChannelRepository;
$this->paymentResponseHandler = $paymentResponseHandler;
Expand Down Expand Up @@ -280,6 +292,14 @@ public function pay(
*/
$stateData = $requestStateData ?? $storedStateData ?? [];

$companyName = $dataBag->get('companyName');
$registrationNumber = $dataBag->get('registrationNumber');

$billieData = [
'companyName' => $companyName,
'registrationNumber' => $registrationNumber,
];

/*
* If there are more than one stateData and /payments calls have been completed,
* check the remaining order amount for final /payments call.
Expand All @@ -292,14 +312,22 @@ public function pay(
$transaction,
$stateData,
$this->remainingAmount,
$this->orderRequestData
$this->orderRequestData,
$billieData
);
//make /payments call
$this->paymentsCall($salesChannelContext, $request, $transaction);
//Remove all state data if stored or from giftcard
if ($storedStateData) {
$this->paymentStateDataService->deletePaymentStateDataFromId($storedStateData['id']);
}

$paymentMethodType = $stateData['paymentMethod']['type'];
if ($paymentMethodType === RatepayPaymentMethod::RATEPAY_PAYMENT_METHOD_TYPE ||
$paymentMethodType === RatepayDirectdebitPaymentMethod::RATEPAY_DIRECTDEBIT_PAYMENT_METHOD_TYPE
) {
$this->ratePayFingerprintParamsProvider->clear();
}
}

$orderNumber = $transaction->getOrder()->getOrderNumber();
Expand Down Expand Up @@ -349,7 +377,11 @@ private function getReturnUrl(AsyncPaymentTransactionStruct $transaction): strin

return $this->symfonyRouter->generate(
'payment.adyen.proxy-finalize-transaction',
['_sw_payment_token' => $token, 'orderId' => $transaction->getOrder()->getId()],
[
'_sw_payment_token' => $token,
'orderId' => $transaction->getOrder()->getId(),
'transactionId' => $transaction->getOrderTransaction()->getId()
],
UrlGeneratorInterface::ABSOLUTE_URL
);
}
Expand Down Expand Up @@ -397,17 +429,17 @@ public function finalize(
* @param array $request
* @param int|null $partialAmount
* @param array|null $adyenOrderData
* @return PaymentRequest
* @return IntegrationPaymentRequest
*/
protected function preparePaymentsRequest(
SalesChannelContext $salesChannelContext,
AsyncPaymentTransactionStruct $transaction,
array $request = [],
?int $partialAmount = null,
?array $adyenOrderData = []
): PaymentRequest {
): IntegrationPaymentRequest {

$paymentRequest = new PaymentRequest($request);
$paymentRequest = new IntegrationPaymentRequest($request);

if (!empty($request['additionalData'])) {
$stateDataAdditionalData = $request['additionalData'];
Expand Down Expand Up @@ -591,6 +623,19 @@ protected function preparePaymentsRequest(
$paymentRequest->setShopperIP($shopperIp);
$paymentRequest->setShopperReference($shopperReference);

if (!empty($request['billieData'])) {
$billieData = $request['billieData'];

$companyName = $billieData['companyName'] ?? '';
$registrationNumber = $billieData['registrationNumber'] ?? '';

$company = new Company();
$company
->setRegistrationNumber($registrationNumber)
->setName($companyName);
$paymentRequest->setCompany($company);
}

//Building payment data
$amount = $partialAmount ?: $this->currency->sanitize(
$transaction->getOrder()->getPrice()->getTotalPrice(),
Expand All @@ -612,6 +657,12 @@ protected function preparePaymentsRequest(
$paymentRequest->setReturnUrl($transaction->getReturnUrl());
}

if ($paymentMethodType === RatepayPaymentMethod::RATEPAY_PAYMENT_METHOD_TYPE ||
$paymentMethodType === RatepayDirectdebitPaymentMethod::RATEPAY_DIRECTDEBIT_PAYMENT_METHOD_TYPE
) {
$paymentRequest->setDeviceFingerprint($this->ratePayFingerprintParamsProvider->getToken());
}

if (static::$isOpenInvoice) {
$orderLines = $transaction->getOrder()->getLineItems();
$lineItems = [];
Expand Down Expand Up @@ -718,9 +769,11 @@ private function getPaymentRequest(
$transaction,
$stateData,
$partialAmount,
$orderRequestData
$orderRequestData,
$billieData = []
) {
$transactionId = $transaction->getOrderTransaction()->getId();
$stateData['billieData'] = $billieData;
try {
$request = $this->preparePaymentsRequest(
$salesChannelContext,
Expand All @@ -746,13 +799,13 @@ private function getPaymentRequest(

/**
* @param SalesChannelContext $salesChannelContext
* @param PaymentRequest $request
* @param IntegrationPaymentRequest $request
* @param AsyncPaymentTransactionStruct $transaction
* @return void
*/
private function paymentsCall(
SalesChannelContext $salesChannelContext,
PaymentRequest $request,
IntegrationPaymentRequest $request,
AsyncPaymentTransactionStruct $transaction
): void {
$transactionId = $transaction->getOrderTransaction()->getId();
Expand Down
13 changes: 9 additions & 4 deletions src/Handlers/ResultHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,15 @@ public function processResult(
}

$result = $this->paymentResponseHandlerResult->createFromPaymentResponse($paymentResponse);

if ('RedirectShopper' === $result->getResultCode()) {
$requestResponse = $request->getMethod() === 'GET' ? $request->query->all() : $request->request->all();

$requestResponse = $request->getMethod() === 'GET' ? $request->query->all() : $request->request->all();

if ('RedirectShopper' === $result->getResultCode() ||
(
$salesChannelContext->getPaymentMethod()->getFormattedHandlerIdentifier() ===
'handler_adyen_bancontactmobilepaymentmethodhandler' &&
$requestResponse['redirectResult']
)
) {
$details = DataArrayValidator::getArrayOnlyWithApprovedKeys($requestResponse, [
self::PA_RES,
self::MD,
Expand Down
Loading

0 comments on commit 9ad6eaa

Please sign in to comment.