Skip to content

Commit

Permalink
Merge pull request #583 from Adyen/develop-3
Browse files Browse the repository at this point in the history
Release version 3.17.1
  • Loading branch information
goran-stamenkovski-logeecom authored Dec 9, 2024
2 parents 82df7c4 + 41e80d5 commit 80a00c8
Show file tree
Hide file tree
Showing 30 changed files with 1,019 additions and 98 deletions.
14 changes: 11 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
}
],
"description": "Official Shopware 6 Plugin to connect to Payment Service Provider Adyen",
"version": "3.17.0",
"version": "3.17.1",
"type": "shopware-platform-plugin",
"license": "MIT",
"require": {
"shopware/core": "~6.4.0 || ~6.5.0",
"shopware/storefront": "~6.4.0 || ~6.5.0",
"shopware/core": "~6.4.11 || ~6.5.0",
"shopware/storefront": "~6.4.11 || ~6.5.0",
"adyen/php-api-library": "^17.5.0",
"adyen/php-webhook-module": "0.8.0",
"ext-json": "*"
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 @@ -318,7 +321,10 @@ private function removePluginData()
$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
68 changes: 60 additions & 8 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 @@ -112,6 +116,11 @@ abstract class AbstractPaymentMethodHandler implements AsynchronousPaymentHandle
*/
protected $checkoutStateDataValidator;

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

/**
* @var PaymentStateDataService
*/
Expand Down Expand Up @@ -203,6 +212,7 @@ public function __construct(
ClientService $clientService,
Currency $currency,
CheckoutStateDataValidator $checkoutStateDataValidator,
RatePayDeviceFingerprintParamsProvider $ratePayFingerprintParamsProvider,
PaymentStateDataService $paymentStateDataService,
SalesChannelRepository $salesChannelRepository,
PaymentResponseHandler $paymentResponseHandler,
Expand All @@ -220,6 +230,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 +291,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 +311,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 +376,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 @@ -393,17 +424,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 @@ -587,6 +618,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 @@ -602,6 +646,12 @@ protected function preparePaymentsRequest(
$paymentRequest->setMerchantAccount(
$this->configurationService->getMerchantAccount($salesChannelContext->getSalesChannel()->getId())
);
if ($paymentMethodType === RatepayPaymentMethod::RATEPAY_PAYMENT_METHOD_TYPE ||
$paymentMethodType === RatepayDirectdebitPaymentMethod::RATEPAY_DIRECTDEBIT_PAYMENT_METHOD_TYPE
) {
$paymentRequest->setDeviceFingerprint($this->ratePayFingerprintParamsProvider->getToken());
}

if ($paymentMethodType === 'bcmc_mobile') {
$paymentRequest->setReturnUrl($this->getReturnUrl($transaction));
} else {
Expand Down Expand Up @@ -719,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 @@ -747,7 +799,7 @@ private function getPaymentRequest(

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 80a00c8

Please sign in to comment.