diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index 63f20cf32..51072f5ad 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -22,7 +22,7 @@ jobs: strategy: matrix: MYSQL_IMAGE: ["mysql:8.0", "mariadb:10.11"] - PLATFORM_BRANCH: ["v6.6.0.0", "trunk"] + PLATFORM_BRANCH: ["trunk"] PHP_VERSION: ["8.2", "8.3"] WITH_COMMERCIAL: [true, false] env: diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index c9c72938e..d57e1ae60 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -23,7 +23,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - PLATFORM_BRANCH: ["v6.6.0.0", "trunk"] + PLATFORM_BRANCH: ["trunk"] fail-fast: false steps: - name: Checkout SwagPayPal @@ -43,12 +43,6 @@ jobs: composer dump-autoload --dev -d "${GITHUB_WORKSPACE}/custom/plugins/SwagCmsExtensions" composer dump-autoload --dev -d "${GITHUB_WORKSPACE}/custom/plugins/SwagCommercial" sed -i 's|reportUnmatchedIgnoredErrors: true|reportUnmatchedIgnoredErrors: false|' ./phpstan.neon.dist - if [[ "${{ matrix.PLATFORM_BRANCH }}" == "v6.6.0.0" ]]; then - sed -i '/type_perfect/d' ./phpstan.neon.dist - sed -i '/narrow_return: true/d' ./phpstan.neon.dist - sed -i '/no_mixed: true/d' ./phpstan.neon.dist - sed -i '/null_over_false: true/d' ./phpstan.neon.dist - fi - run: | composer -d custom/plugins/${{ github.event.repository.name }} run phpstan diff --git a/src/Checkout/Payment/Handler/PlusPuiHandler.php b/src/Checkout/Payment/Handler/PlusPuiHandler.php deleted file mode 100644 index c35a6d4e9..000000000 --- a/src/Checkout/Payment/Handler/PlusPuiHandler.php +++ /dev/null @@ -1,306 +0,0 @@ - - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Swag\PayPal\Checkout\Payment\Handler; - -use Psr\Log\LoggerInterface; -use Shopware\Core\Checkout\Customer\CustomerEntity; -use Shopware\Core\Checkout\Order\Aggregate\OrderTransaction\OrderTransactionStateHandler; -use Shopware\Core\Checkout\Payment\Cart\AsyncPaymentTransactionStruct; -use Shopware\Core\Checkout\Payment\PaymentException; -use Shopware\Core\Framework\Context; -use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository; -use Shopware\Core\Framework\Log\Package; -use Shopware\Core\Framework\Validation\DataBag\RequestDataBag; -use Shopware\Core\System\SalesChannel\SalesChannelContext; -use Swag\PayPal\PaymentsApi\Patch\OrderNumberPatchBuilder; -use Swag\PayPal\PaymentsApi\Patch\PayerInfoPatchBuilder; -use Swag\PayPal\PaymentsApi\Patch\ShippingAddressPatchBuilder; -use Swag\PayPal\PaymentsApi\Patch\TransactionPatchBuilder; -use Swag\PayPal\RestApi\Exception\PayPalApiException; -use Swag\PayPal\RestApi\V1\Api\Patch; -use Swag\PayPal\RestApi\V1\Api\Payment; -use Swag\PayPal\RestApi\V1\Api\Payment\PaymentInstruction; -use Swag\PayPal\RestApi\V1\PaymentIntentV1; -use Swag\PayPal\RestApi\V1\PaymentStatusV1; -use Swag\PayPal\RestApi\V1\Resource\PaymentResource; -use Swag\PayPal\SwagPayPal; -use Symfony\Component\HttpFoundation\RedirectResponse; - -/** - * @deprecated tag:v10.0.0 - Will be removed without replacement. - */ -#[Package('checkout')] -class PlusPuiHandler -{ - public const PAYPAL_PAYMENT_ID_INPUT_NAME = 'paypalPaymentId'; - public const PAYPAL_PAYMENT_TOKEN_INPUT_NAME = 'paypalToken'; - - private PaymentResource $paymentResource; - - private EntityRepository $orderTransactionRepo; - - private OrderNumberPatchBuilder $orderNumberPatchBuilder; - - private TransactionPatchBuilder $transactionPatchBuilder; - - private PayerInfoPatchBuilder $payerInfoPatchBuilder; - - private ShippingAddressPatchBuilder $shippingAddressPatchBuilder; - - private OrderTransactionStateHandler $orderTransactionStateHandler; - - private LoggerInterface $logger; - - /** - * @internal - */ - public function __construct( - PaymentResource $paymentResource, - EntityRepository $orderTransactionRepo, - PayerInfoPatchBuilder $payerInfoPatchBuilder, - OrderNumberPatchBuilder $orderNumberPatchBuilder, - TransactionPatchBuilder $transactionPatchBuilder, - ShippingAddressPatchBuilder $shippingAddressPatchBuilder, - OrderTransactionStateHandler $orderTransactionStateHandler, - LoggerInterface $logger, - ) { - $this->paymentResource = $paymentResource; - $this->orderTransactionRepo = $orderTransactionRepo; - $this->orderNumberPatchBuilder = $orderNumberPatchBuilder; - $this->transactionPatchBuilder = $transactionPatchBuilder; - $this->payerInfoPatchBuilder = $payerInfoPatchBuilder; - $this->shippingAddressPatchBuilder = $shippingAddressPatchBuilder; - $this->orderTransactionStateHandler = $orderTransactionStateHandler; - $this->logger = $logger; - } - - public function handlePlusPayment( - AsyncPaymentTransactionStruct $transaction, - RequestDataBag $dataBag, - SalesChannelContext $salesChannelContext, - CustomerEntity $customer, - ): RedirectResponse { - $this->logger->debug('Started'); - $paypalPaymentId = $dataBag->get(self::PAYPAL_PAYMENT_ID_INPUT_NAME); - $paypalToken = $dataBag->get(self::PAYPAL_PAYMENT_TOKEN_INPUT_NAME); - $this->addPayPalTransactionId($transaction, $paypalPaymentId, $salesChannelContext->getContext(), $paypalToken); - - $patches = $this->transactionPatchBuilder->createTransactionPatch( - $transaction, - $salesChannelContext - ); - - $patches[] = $this->shippingAddressPatchBuilder->createShippingAddressPatch($transaction->getOrder()); - $patches[] = $this->payerInfoPatchBuilder->createPayerInfoPatch($transaction->getOrder()); - - $this->patchPayPalPayment( - $patches, - $paypalPaymentId, - $salesChannelContext->getSalesChannel()->getId(), - $transaction->getOrderTransaction()->getId() - ); - - return new RedirectResponse('plusPatched'); - } - - /** - * @throws PaymentException - */ - public function handleFinalizePayment( - AsyncPaymentTransactionStruct $transaction, - string $salesChannelId, - Context $context, - string $paymentId, - string $payerId, - string $partnerAttributionId, - ): void { - $this->logger->debug('Started'); - $transactionId = $transaction->getOrderTransaction()->getId(); - $orderNumber = $transaction->getOrder()->getOrderNumber(); - - try { - $response = $this->paymentResource->execute( - $payerId, - $paymentId, - $salesChannelId, - $partnerAttributionId - ); - } catch (PayPalApiException $e) { - $parameters = $e->getParameters(); - if (!isset($parameters['name']) || $parameters['name'] !== PayPalApiException::ERROR_CODE_DUPLICATE_ORDER_NUMBER) { - throw PaymentException::asyncFinalizeInterrupted( - $transactionId, - \sprintf('An error occurred during the communication with PayPal%s%s', \PHP_EOL, $e->getMessage()) - ); - } - - $this->logger->warning('Duplicate order number {orderNumber} detected. Retrying payment without order number.', ['orderNumber' => $orderNumber]); - - try { - $this->paymentResource->patch( - [ - $this->orderNumberPatchBuilder->createOrderNumberPatch(null), - ], - $paymentId, - $salesChannelId - ); - - $response = $this->paymentResource->execute( - $payerId, - $paymentId, - $salesChannelId, - $partnerAttributionId - ); - } catch (\Exception $e) { - throw PaymentException::asyncFinalizeInterrupted( - $transactionId, - \sprintf('An error occurred during the communication with PayPal%s%s', \PHP_EOL, $e->getMessage()) - ); - } - } catch (\Exception $e) { - throw PaymentException::asyncFinalizeInterrupted( - $transactionId, - \sprintf('An error occurred during the communication with PayPal%s%s', \PHP_EOL, $e->getMessage()) - ); - } - - $paymentState = $this->getPaymentState($response); - - // apply the payment status if it's completed by PayPal - if ($paymentState === PaymentStatusV1::PAYMENT_COMPLETED) { - $this->orderTransactionStateHandler->paid($transactionId, $context); - } - - if ($paymentState === PaymentStatusV1::PAYMENT_DENIED) { - $this->orderTransactionStateHandler->fail($transactionId, $context); - } - - $this->updateTransaction($response, $transactionId, $context); - } - - /** - * @param Patch[] $patches - * - * @throws PaymentException - */ - private function patchPayPalPayment( - array $patches, - string $paypalPaymentId, - string $salesChannelId, - string $orderTransactionId, - ): void { - try { - $this->paymentResource->patch($patches, $paypalPaymentId, $salesChannelId); - } catch (\Exception $e) { - throw PaymentException::asyncProcessInterrupted( - $orderTransactionId, - \sprintf('An error occurred during the communication with PayPal%s%s', \PHP_EOL, $e->getMessage()) - ); - } - } - - private function addPayPalTransactionId( - AsyncPaymentTransactionStruct $transaction, - string $paypalPaymentId, - Context $context, - ?string $paypalToken = null, - ): void { - $customFields = [ - SwagPayPal::ORDER_TRANSACTION_CUSTOM_FIELDS_PAYPAL_TRANSACTION_ID => $paypalPaymentId, - ]; - - if ($paypalToken !== null) { - $customFields[SwagPayPal::ORDER_TRANSACTION_CUSTOM_FIELDS_PAYPAL_TOKEN] = $paypalToken; - } - - $data = [ - 'id' => $transaction->getOrderTransaction()->getId(), - 'customFields' => $customFields, - ]; - $this->orderTransactionRepo->update([$data], $context); - } - - private function getPaymentState(Payment $payment): string - { - $intent = $payment->getIntent(); - $relatedResource = $payment->getTransactions()->first()?->getRelatedResources()->first(); - $paymentState = ''; - - if ($relatedResource === null) { - return $paymentState; - } - - switch ($intent) { - case PaymentIntentV1::SALE: - $sale = $relatedResource->getSale(); - if ($sale !== null) { - $paymentState = $sale->getState(); - } - - break; - case PaymentIntentV1::AUTHORIZE: - $authorization = $relatedResource->getAuthorization(); - if ($authorization !== null) { - $paymentState = $authorization->getState(); - } - - break; - case PaymentIntentV1::ORDER: - $order = $relatedResource->getOrder(); - if ($order !== null) { - $paymentState = $order->getState(); - } - - break; - } - - return $paymentState; - } - - private function updateTransaction(Payment $payment, string $transactionId, Context $context): void - { - $customFields = []; - - $paymentInstructions = $payment->getPaymentInstruction(); - if ($paymentInstructions !== null - && $paymentInstructions->getInstructionType() === PaymentInstruction::TYPE_INVOICE - ) { - $customFields[SwagPayPal::ORDER_TRANSACTION_CUSTOM_FIELDS_PAYPAL_PUI_INSTRUCTION] = $paymentInstructions; - } - - switch ($payment->getIntent()) { - case PaymentIntentV1::ORDER: - $resource = $payment->getTransactions()->first()?->getRelatedResources()->first()?->getOrder(); - - break; - case PaymentIntentV1::AUTHORIZE: - $resource = $payment->getTransactions()->first()?->getRelatedResources()->first()?->getAuthorization(); - - break; - case PaymentIntentV1::SALE: - $resource = $payment->getTransactions()->first()?->getRelatedResources()->first()?->getSale(); - - break; - default: - $resource = null; - } - - if ($resource !== null) { - $customFields[SwagPayPal::ORDER_TRANSACTION_CUSTOM_FIELDS_PAYPAL_RESOURCE_ID] = $resource->getId(); - } - - if (empty($customFields)) { - return; - } - - $this->orderTransactionRepo->update([[ - 'id' => $transactionId, - 'customFields' => $customFields, - ]], $context); - } -} diff --git a/src/Checkout/Payment/PayPalPaymentHandler.php b/src/Checkout/Payment/PayPalPaymentHandler.php index 4efed3118..92038a101 100644 --- a/src/Checkout/Payment/PayPalPaymentHandler.php +++ b/src/Checkout/Payment/PayPalPaymentHandler.php @@ -26,7 +26,6 @@ use Shopware\Core\System\SalesChannel\SalesChannelContext; use Shopware\Core\System\StateMachine\Aggregation\StateMachineState\StateMachineStateEntity; use Swag\PayPal\Checkout\Payment\Handler\PayPalHandler; -use Swag\PayPal\Checkout\Payment\Handler\PlusPuiHandler; use Swag\PayPal\Checkout\Payment\Method\AbstractPaymentMethodHandler; use Swag\PayPal\Checkout\Payment\Service\VaultTokenService; use Swag\PayPal\RestApi\PartnerAttributionId; @@ -38,22 +37,11 @@ class PayPalPaymentHandler implements AsynchronousPaymentHandlerInterface, RecurringPaymentHandlerInterface { public const PAYPAL_REQUEST_PARAMETER_CANCEL = 'cancel'; - public const PAYPAL_REQUEST_PARAMETER_PAYER_ID = 'PayerID'; public const PAYPAL_REQUEST_PARAMETER_PAYMENT_ID = 'paymentId'; public const PAYPAL_REQUEST_PARAMETER_TOKEN = 'token'; public const PAYPAL_EXPRESS_CHECKOUT_ID = 'isPayPalExpressCheckout'; public const PAYPAL_SMART_PAYMENT_BUTTONS_ID = 'isPayPalSpbCheckout'; - /** - * @deprecated tag:v10.0.0 - Will be removed without replacement. - */ - public const PAYPAL_PLUS_CHECKOUT_REQUEST_PARAMETER = 'isPayPalPlus'; - - /** - * @deprecated tag:v10.0.0 - Will be removed without replacement. - */ - public const PAYPAL_PLUS_CHECKOUT_ID = 'isPayPalPlusCheckout'; - public const FINALIZED_ORDER_TRANSACTION_STATES = [ OrderTransactionStates::STATE_PAID, OrderTransactionStates::STATE_AUTHORIZED, @@ -65,7 +53,6 @@ class PayPalPaymentHandler implements AsynchronousPaymentHandlerInterface, Recur public function __construct( private readonly OrderTransactionStateHandler $orderTransactionStateHandler, private readonly PayPalHandler $payPalHandler, - private readonly PlusPuiHandler $plusPuiHandler, private readonly EntityRepository $stateMachineStateRepository, private readonly LoggerInterface $logger, private readonly SettingsValidationServiceInterface $settingsValidationService, @@ -98,10 +85,6 @@ public function pay( return $this->payPalHandler->handlePreparedOrder($transaction, $dataBag, $salesChannelContext); } - if ($dataBag->getBoolean(self::PAYPAL_PLUS_CHECKOUT_ID)) { - return $this->plusPuiHandler->handlePlusPayment($transaction, $dataBag, $salesChannelContext, $customer); - } - return $this->payPalHandler->handlePayPalOrder($transaction, $dataBag, $salesChannelContext); } catch (PaymentException $e) { if ($e->getParameter('orderTransactionId') === null && method_exists($e, 'setOrderTransactionId')) { @@ -144,33 +127,10 @@ public function finalize( $this->settingsValidationService->validate($salesChannelContext->getSalesChannelId()); $salesChannelId = $salesChannelContext->getSalesChannel()->getId(); - $context = $salesChannelContext->getContext(); - - $paymentId = $request->query->get(self::PAYPAL_REQUEST_PARAMETER_PAYMENT_ID); - $isExpressCheckout = $request->query->getBoolean(self::PAYPAL_EXPRESS_CHECKOUT_ID); $isSPBCheckout = $request->query->getBoolean(self::PAYPAL_SMART_PAYMENT_BUTTONS_ID); - $isPlus = $request->query->getBoolean(self::PAYPAL_PLUS_CHECKOUT_REQUEST_PARAMETER); - - $partnerAttributionId = $this->getPartnerAttributionId($isExpressCheckout, $isSPBCheckout, $isPlus); - - if (\is_string($paymentId)) { - $payerId = $request->query->get(self::PAYPAL_REQUEST_PARAMETER_PAYER_ID); - if (!\is_string($payerId)) { - throw RoutingException::missingRequestParameter(self::PAYPAL_REQUEST_PARAMETER_PAYER_ID); - } - - $this->plusPuiHandler->handleFinalizePayment( - $transaction, - $salesChannelId, - $context, - $paymentId, - $payerId, - $partnerAttributionId - ); - - return; - } + + $partnerAttributionId = $this->getPartnerAttributionId($isExpressCheckout, $isSPBCheckout); $token = $request->query->get(self::PAYPAL_REQUEST_PARAMETER_TOKEN); if (!\is_string($token)) { @@ -216,7 +176,7 @@ public function captureRecurring(RecurringPaymentTransactionStruct $transaction, } } - private function getPartnerAttributionId(bool $isECS, bool $isSPB, bool $isPlus): string + private function getPartnerAttributionId(bool $isECS, bool $isSPB): string { if ($isECS) { return PartnerAttributionId::PAYPAL_EXPRESS_CHECKOUT; @@ -226,10 +186,6 @@ private function getPartnerAttributionId(bool $isECS, bool $isSPB, bool $isPlus) return PartnerAttributionId::SMART_PAYMENT_BUTTONS; } - if ($isPlus) { - return PartnerAttributionId::PAYPAL_PLUS; - } - return PartnerAttributionId::PAYPAL_CLASSIC; } diff --git a/src/Checkout/Plus/PlusData.php b/src/Checkout/Plus/PlusData.php deleted file mode 100644 index a22c05942..000000000 --- a/src/Checkout/Plus/PlusData.php +++ /dev/null @@ -1,100 +0,0 @@ - - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Swag\PayPal\Checkout\Plus; - -use Shopware\Core\Framework\Log\Package; -use Shopware\Core\Framework\Struct\Struct; - -/** - * @deprecated tag:v10.0.0 - Will be removed without replacement. - */ -#[Package('checkout')] -class PlusData extends Struct -{ - protected string $approvalUrl; - - protected string $customerCountryIso; - - protected string $mode; - - protected string $customerSelectedLanguage; - - protected string $paymentMethodId; - - protected string $paypalPaymentId; - - protected string $paypalToken; - - protected string $handlePaymentUrl; - - protected string $isEnabledParameterName; - - protected string $languageId; - - protected ?string $orderId = null; - - public function getApprovalUrl(): string - { - return $this->approvalUrl; - } - - public function getCustomerCountryIso(): string - { - return $this->customerCountryIso; - } - - public function getMode(): string - { - return $this->mode; - } - - public function getCustomerSelectedLanguage(): string - { - return $this->customerSelectedLanguage; - } - - public function getPaymentMethodId(): string - { - return $this->paymentMethodId; - } - - public function getPaypalPaymentId(): string - { - return $this->paypalPaymentId; - } - - public function getPaypalToken(): string - { - return $this->paypalToken; - } - - public function getHandlePaymentUrl(): string - { - return $this->handlePaymentUrl; - } - - public function getIsEnabledParameterName(): string - { - return $this->isEnabledParameterName; - } - - public function getLanguageId(): string - { - return $this->languageId; - } - - public function getOrderId(): ?string - { - return $this->orderId; - } - - public function setOrderId(?string $orderId): void - { - $this->orderId = $orderId; - } -} diff --git a/src/Checkout/Plus/PlusPaymentFinalizeController.php b/src/Checkout/Plus/PlusPaymentFinalizeController.php deleted file mode 100644 index 2a30a18de..000000000 --- a/src/Checkout/Plus/PlusPaymentFinalizeController.php +++ /dev/null @@ -1,176 +0,0 @@ - - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Swag\PayPal\Checkout\Plus; - -use Psr\Log\LoggerInterface; -use Shopware\Core\Checkout\Order\Aggregate\OrderTransaction\OrderTransactionEntity; -use Shopware\Core\Checkout\Order\Aggregate\OrderTransaction\OrderTransactionStateHandler; -use Shopware\Core\Checkout\Payment\Cart\AsyncPaymentTransactionStruct; -use Shopware\Core\Checkout\Payment\Cart\PaymentHandler\AsynchronousPaymentHandlerInterface; -use Shopware\Core\Checkout\Payment\PaymentException; -use Shopware\Core\Framework\Context; -use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository; -use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria; -use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter; -use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\MultiFilter; -use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\NotFilter; -use Shopware\Core\Framework\Log\Package; -use Shopware\Core\System\SalesChannel\SalesChannelContext; -use Swag\PayPal\Checkout\Payment\PayPalPaymentHandler; -use Swag\PayPal\SwagPayPal; -use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; -use Symfony\Component\HttpFoundation\RedirectResponse; -use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\Routing\Attribute\Route; -use Symfony\Component\Routing\RouterInterface; - -/** - * @deprecated tag:v10.0.0 - Will be removed without replacement. - */ -#[Package('checkout')] -class PlusPaymentFinalizeController extends AbstractController -{ - private RouterInterface $router; - - private EntityRepository $orderTransactionRepo; - - private AsynchronousPaymentHandlerInterface $paymentHandler; - - private OrderTransactionStateHandler $transactionStateHandler; - - private LoggerInterface $logger; - - /** - * @internal - */ - public function __construct( - EntityRepository $orderTransactionRepo, - AsynchronousPaymentHandlerInterface $paymentHandler, - OrderTransactionStateHandler $transactionStateHandler, - RouterInterface $router, - LoggerInterface $logger, - ) { - $this->orderTransactionRepo = $orderTransactionRepo; - $this->paymentHandler = $paymentHandler; - $this->transactionStateHandler = $transactionStateHandler; - $this->router = $router; - $this->logger = $logger; - } - - /** - * @throws PaymentException - */ - #[Route(path: '/paypal/plus/payment/finalize-transaction', name: 'payment.paypal.plus.finalize.transaction', methods: ['GET'], defaults: ['auth_required' => false, '_routeScope' => ['storefront']])] - public function finalizeTransaction(Request $request, SalesChannelContext $salesChannelContext): RedirectResponse - { - $token = $request->query->get('token'); - $this->logger->debug('Starting with token {token}.', ['token' => $token]); - - $criteria = new Criteria(); - $criteria->addAssociation('order'); - $criteria->addFilter( - new MultiFilter( - MultiFilter::CONNECTION_AND, - [ - new EqualsFilter( - \sprintf('customFields.%s', SwagPayPal::ORDER_TRANSACTION_CUSTOM_FIELDS_PAYPAL_TOKEN), - $token - ), - new NotFilter( - NotFilter::CONNECTION_AND, - [ - new EqualsFilter( - \sprintf('customFields.%s', SwagPayPal::ORDER_TRANSACTION_CUSTOM_FIELDS_PAYPAL_TOKEN), - null - ), - ] - ), - ] - ) - ); - - $context = $salesChannelContext->getContext(); - /** @var OrderTransactionEntity|null $orderTransaction */ - $orderTransaction = $this->orderTransactionRepo->search($criteria, $context)->getEntities()->first(); - - if ($orderTransaction === null) { - throw PaymentException::invalidTransaction(''); - } - $order = $orderTransaction->getOrder(); - - if ($order === null) { - throw PaymentException::invalidTransaction($orderTransaction->getId()); - } - - $paymentTransactionStruct = new AsyncPaymentTransactionStruct($orderTransaction, $order, ''); - - $orderId = $order->getId(); - $changedPayment = $request->query->getBoolean('changedPayment'); - $finishUrl = $this->router->generate('frontend.checkout.finish.page', [ - 'orderId' => $orderId, - PayPalPaymentHandler::PAYPAL_PLUS_CHECKOUT_ID => true, - 'changedPayment' => $changedPayment, - ]); - - try { - $this->logger->debug('Forwarding to payment handler.'); - $this->paymentHandler->finalize($paymentTransactionStruct, $request, $salesChannelContext); - } catch (PaymentException $paymentException) { - $this->logger->warning( - '{message}. Redirecting to confirm page.', - ['message' => $paymentException->getMessage(), 'error' => $paymentException] - ); - $finishUrl = $this->redirectToConfirmPageWorkflow( - $paymentException, - $context, - $orderId - ); - } - - return new RedirectResponse($finishUrl); - } - - /** - * @throws PaymentException - */ - private function redirectToConfirmPageWorkflow( - PaymentException $paymentException, - Context $context, - string $orderId, - ): string { - $transactionId = $paymentException->getParameter('orderTransactionId'); - - if (!$transactionId) { - throw PaymentException::invalidTransaction(''); - } - - $errorUrl = $this->router->generate('frontend.account.edit-order.page', ['orderId' => $orderId]); - - if ($paymentException->getErrorCode() === PaymentException::PAYMENT_CUSTOMER_CANCELED_EXTERNAL) { - $this->transactionStateHandler->cancel( - $transactionId, - $context - ); - $urlQuery = \parse_url($errorUrl, \PHP_URL_QUERY) ? '&' : '?'; - - return \sprintf('%s%serror-code=%s', $errorUrl, $urlQuery, $paymentException->getErrorCode()); - } - - $this->logger->error( - $paymentException->getMessage(), - ['orderTransactionId' => $transactionId, 'error' => $paymentException] - ); - $this->transactionStateHandler->fail( - $transactionId, - $context - ); - $urlQuery = \parse_url($errorUrl, \PHP_URL_QUERY) ? '&' : '?'; - - return \sprintf('%s%serror-code=%s', $errorUrl, $urlQuery, $paymentException->getErrorCode()); - } -} diff --git a/src/Checkout/Plus/PlusPaymentHandleController.php b/src/Checkout/Plus/PlusPaymentHandleController.php deleted file mode 100644 index ebca472fd..000000000 --- a/src/Checkout/Plus/PlusPaymentHandleController.php +++ /dev/null @@ -1,85 +0,0 @@ - - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Swag\PayPal\Checkout\Plus; - -use Shopware\Core\Checkout\Payment\SalesChannel\HandlePaymentMethodRouteResponse; -use Shopware\Core\Framework\Log\Package; -use Shopware\Core\Framework\Validation\DataBag\RequestDataBag; -use Shopware\Core\System\SalesChannel\Context\SalesChannelContextService; -use Shopware\Core\System\SalesChannel\SalesChannel\AbstractContextSwitchRoute; -use Shopware\Core\System\SalesChannel\SalesChannelContext; -use Shopware\Storefront\Controller\AccountOrderController; -use Shopware\Storefront\Controller\CheckoutController; -use Shopware\Storefront\Controller\StorefrontController; -use Symfony\Component\HttpFoundation\RedirectResponse; -use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpFoundation\RequestStack; -use Symfony\Component\Routing\Attribute\Route; - -/** - * @deprecated tag:v10.0.0 - Will be removed without replacement. - * - * @internal - */ -#[Package('checkout')] -class PlusPaymentHandleController extends StorefrontController -{ - private AbstractContextSwitchRoute $contextSwitchRoute; - - private AccountOrderController $accountOrderController; - - private CheckoutController $checkoutController; - - private RequestStack $requestStack; - - /** - * @internal - */ - public function __construct( - AbstractContextSwitchRoute $contextSwitchRoute, - AccountOrderController $accountOrderController, - CheckoutController $checkoutController, - RequestStack $requestStack, - ) { - $this->contextSwitchRoute = $contextSwitchRoute; - $this->accountOrderController = $accountOrderController; - $this->checkoutController = $checkoutController; - $this->requestStack = $requestStack; - } - - #[Route(path: '/paypal/plus/payment/handle', name: 'frontend.paypal.plus.handle', methods: ['POST'], defaults: ['XmlHttpRequest' => true, '_routeScope' => ['storefront']])] - public function handlePlusPayment(Request $request, SalesChannelContext $context): HandlePaymentMethodRouteResponse - { - $this->contextSwitchRoute->switchContext( - new RequestDataBag([SalesChannelContextService::LANGUAGE_ID => $request->request->getAlnum('languageId')]), - $context - ); - - $orderId = $request->request->getAlnum('orderId'); - if ($orderId) { - $response = $this->accountOrderController->updateOrder($orderId, $request, $context); - } else { - $response = $this->checkoutController->order(new RequestDataBag($request->request->all()), $context, $request); - } - - if ($response instanceof RedirectResponse) { - return new HandlePaymentMethodRouteResponse($response); - } - - $request = $this->requestStack->getCurrentRequest(); - if ($request === null) { - return new HandlePaymentMethodRouteResponse($this->redirectToRoute('frontend.checkout.confirm.page')); - } - - if ($orderId) { - return new HandlePaymentMethodRouteResponse($this->redirectToRoute('frontend.checkout.finish.page', ['orderId' => $orderId, 'changedPayment' => false, 'paymentFailed' => true])); - } - - return new HandlePaymentMethodRouteResponse($this->redirect($request->getRequestUri())); - } -} diff --git a/src/Checkout/Plus/PlusSubscriber.php b/src/Checkout/Plus/PlusSubscriber.php deleted file mode 100644 index 0b6d787d0..000000000 --- a/src/Checkout/Plus/PlusSubscriber.php +++ /dev/null @@ -1,224 +0,0 @@ - - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Swag\PayPal\Checkout\Plus; - -use Psr\Log\LoggerInterface; -use Shopware\Core\Checkout\Payment\PaymentMethodCollection; -use Shopware\Core\Checkout\Payment\PaymentMethodEntity; -use Shopware\Core\Framework\Log\Package; -use Shopware\Core\System\SalesChannel\SalesChannelContext; -use Shopware\Core\System\SystemConfig\SystemConfigService; -use Shopware\Storefront\Page\Account\Order\AccountEditOrderPage; -use Shopware\Storefront\Page\Account\Order\AccountEditOrderPageLoadedEvent; -use Shopware\Storefront\Page\Checkout\Confirm\CheckoutConfirmPage; -use Shopware\Storefront\Page\Checkout\Confirm\CheckoutConfirmPageLoadedEvent; -use Shopware\Storefront\Page\Checkout\Finish\CheckoutFinishPageLoadedEvent; -use Shopware\Storefront\Page\Page; -use Swag\PayPal\Checkout\Payment\PayPalPaymentHandler; -use Swag\PayPal\Checkout\Plus\Service\PlusDataService; -use Swag\PayPal\Setting\Exception\PayPalSettingsInvalidException; -use Swag\PayPal\Setting\Service\SettingsValidationServiceInterface; -use Swag\PayPal\Setting\Settings; -use Swag\PayPal\Util\PaymentMethodUtil; -use Symfony\Component\EventDispatcher\EventSubscriberInterface; -use Symfony\Contracts\Translation\TranslatorInterface; - -/** - * @deprecated tag:v10.0.0 - Will be removed without replacement. - * - * @internal - */ -#[Package('checkout')] -class PlusSubscriber implements EventSubscriberInterface -{ - public const PAYPAL_PLUS_DATA_EXTENSION_ID = 'payPalPlusData'; - - private SettingsValidationServiceInterface $settingsValidationService; - - private SystemConfigService $systemConfigService; - - private PlusDataService $plusDataService; - - private PaymentMethodUtil $paymentMethodUtil; - - private TranslatorInterface $translator; - - private LoggerInterface $logger; - - public function __construct( - SettingsValidationServiceInterface $settingsValidationService, - SystemConfigService $systemConfigService, - PlusDataService $plusDataService, - PaymentMethodUtil $paymentMethodUtil, - TranslatorInterface $translator, - LoggerInterface $logger, - ) { - $this->settingsValidationService = $settingsValidationService; - $this->systemConfigService = $systemConfigService; - $this->plusDataService = $plusDataService; - $this->paymentMethodUtil = $paymentMethodUtil; - $this->translator = $translator; - $this->logger = $logger; - } - - public static function getSubscribedEvents(): array - { - return [ - AccountEditOrderPageLoadedEvent::class => 'onAccountEditOrderLoaded', - CheckoutConfirmPageLoadedEvent::class => 'onCheckoutConfirmLoaded', - CheckoutFinishPageLoadedEvent::class => 'onCheckoutFinishLoaded', - ]; - } - - public function onAccountEditOrderLoaded(AccountEditOrderPageLoadedEvent $event): void - { - $salesChannelContext = $event->getSalesChannelContext(); - if (!$this->checkSettings($salesChannelContext, $event->getPage()->getPaymentMethods())) { - return; - } - - $this->logger->debug('Adding data'); - $page = $event->getPage(); - $plusData = $this->plusDataService->getPlusDataFromOrder($page->getOrder(), $salesChannelContext); - $this->addPlusExtension($plusData, $page, $salesChannelContext); - $this->logger->debug('Added data'); - } - - public function onCheckoutConfirmLoaded(CheckoutConfirmPageLoadedEvent $event): void - { - $isExpressCheckout = $event->getRequest()->query->getBoolean(PayPalPaymentHandler::PAYPAL_EXPRESS_CHECKOUT_ID); - if ($isExpressCheckout) { - return; - } - - $salesChannelContext = $event->getSalesChannelContext(); - if (!$this->checkSettings($salesChannelContext, $event->getPage()->getPaymentMethods())) { - return; - } - - $this->logger->debug('Adding data'); - $page = $event->getPage(); - $plusData = $this->plusDataService->getPlusData($page->getCart(), $salesChannelContext); - $this->addPlusExtension($plusData, $page, $salesChannelContext); - $this->logger->debug('Added data'); - } - - public function onCheckoutFinishLoaded(CheckoutFinishPageLoadedEvent $event): void - { - $isPlus = $event->getRequest()->query->getBoolean(PayPalPaymentHandler::PAYPAL_PLUS_CHECKOUT_ID); - if ($isPlus === false) { - return; - } - - $salesChannelContext = $event->getSalesChannelContext(); - - $salesChannelId = $salesChannelContext->getSalesChannelId(); - - try { - $this->settingsValidationService->validate($salesChannelId); - } catch (PayPalSettingsInvalidException $e) { - return; - } - - if (!$this->systemConfigService->getBool(Settings::PLUS_CHECKOUT_ENABLED, $salesChannelId) - || $this->systemConfigService->getString(Settings::MERCHANT_LOCATION, $salesChannelId) === Settings::MERCHANT_LOCATION_OTHER - ) { - return; - } - - $transactions = $event->getPage()->getOrder()->getTransactions(); - if ($transactions === null) { - return; - } - - $payPalPaymentId = $this->paymentMethodUtil->getPayPalPaymentMethodId($salesChannelContext->getContext()); - if ($payPalPaymentId === null) { - return; - } - - $transaction = $transactions->filterByPaymentMethodId($payPalPaymentId)->first(); - if ($transaction === null) { - return; - } - - $paymentMethod = $transaction->getPaymentMethod(); - if ($paymentMethod === null) { - return; - } - - $this->logger->debug('Changing payment method data'); - $this->changePaymentMethod($paymentMethod); - $this->logger->debug('Changed payment method data'); - } - - private function checkSettings(SalesChannelContext $salesChannelContext, PaymentMethodCollection $paymentMethods): bool - { - if (!$this->paymentMethodUtil->isPaypalPaymentMethodInSalesChannel($salesChannelContext, $paymentMethods)) { - return false; - } - - $salesChannelId = $salesChannelContext->getSalesChannelId(); - - try { - $this->settingsValidationService->validate($salesChannelId); - } catch (PayPalSettingsInvalidException $e) { - return false; - } - - if (!$this->systemConfigService->getBool(Settings::PLUS_CHECKOUT_ENABLED, $salesChannelId) - || $this->systemConfigService->getString(Settings::MERCHANT_LOCATION, $salesChannelId) === Settings::MERCHANT_LOCATION_OTHER - ) { - return false; - } - - return true; - } - - /** - * @param AccountEditOrderPage|CheckoutConfirmPage $page - */ - private function addPlusExtension( - ?PlusData $plusData, - Page $page, - SalesChannelContext $salesChannelContext, - ): void { - if ($plusData === null) { - return; - } - - $payPalPaymentId = $plusData->getPaymentMethodId(); - $payPalPaymentMethodFromCollection = $page->getPaymentMethods()->get($payPalPaymentId); - if ($payPalPaymentMethodFromCollection !== null) { - $this->changePaymentMethod($payPalPaymentMethodFromCollection); - } - - $currentSelectedPaymentMethod = $salesChannelContext->getPaymentMethod(); - if ($currentSelectedPaymentMethod->getId() !== $payPalPaymentId) { - return; - } - - $this->changePaymentMethod($currentSelectedPaymentMethod); - - $page->addExtension(self::PAYPAL_PLUS_DATA_EXTENSION_ID, $plusData); - } - - private function changePaymentMethod(PaymentMethodEntity $paymentMethod): void - { - $paymentMethod->addTranslated('name', $this->translator->trans('paypal.plus.paymentNameOverwrite')); - - $description = $paymentMethod->getTranslation('description'); - if ($description === null) { - $description = $paymentMethod->getDescription(); - } - - $paymentMethod->addTranslated( - 'description', - $description . ' ' . $this->translator->trans('paypal.plus.paymentDescriptionExtension') - ); - } -} diff --git a/src/Checkout/Plus/Service/PlusDataService.php b/src/Checkout/Plus/Service/PlusDataService.php deleted file mode 100644 index a31ece9ca..000000000 --- a/src/Checkout/Plus/Service/PlusDataService.php +++ /dev/null @@ -1,186 +0,0 @@ - - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Swag\PayPal\Checkout\Plus\Service; - -use Shopware\Core\Checkout\Cart\Cart; -use Shopware\Core\Checkout\Customer\CustomerEntity; -use Shopware\Core\Checkout\Order\OrderEntity; -use Shopware\Core\Checkout\Payment\Cart\AsyncPaymentTransactionStruct; -use Shopware\Core\Checkout\Payment\PaymentException; -use Shopware\Core\Framework\Context; -use Shopware\Core\Framework\Log\Package; -use Shopware\Core\System\SalesChannel\SalesChannelContext; -use Shopware\Core\System\SystemConfig\SystemConfigService; -use Swag\PayPal\Checkout\Payment\PayPalPaymentHandler; -use Swag\PayPal\Checkout\Plus\PlusData; -use Swag\PayPal\PaymentsApi\Builder\CartPaymentBuilderInterface; -use Swag\PayPal\PaymentsApi\Builder\OrderPaymentBuilderInterface; -use Swag\PayPal\RestApi\PartnerAttributionId; -use Swag\PayPal\RestApi\V1\Api\Payment; -use Swag\PayPal\RestApi\V1\Resource\PaymentResource; -use Swag\PayPal\Setting\Settings; -use Swag\PayPal\Util\LocaleCodeProvider; -use Swag\PayPal\Util\PaymentMethodUtil; -use Swag\PayPal\Util\PaymentTokenExtractor; -use Symfony\Component\Routing\Generator\UrlGeneratorInterface; -use Symfony\Component\Routing\RouterInterface; - -/** - * @deprecated tag:v10.0.0 - Will be removed without replacement. - */ -#[Package('checkout')] -class PlusDataService -{ - private RouterInterface $router; - - private CartPaymentBuilderInterface $cartPaymentBuilder; - - private OrderPaymentBuilderInterface $orderPaymentBuilder; - - private PaymentResource $paymentResource; - - private PaymentMethodUtil $paymentMethodUtil; - - private LocaleCodeProvider $localeCodeProvider; - - private SystemConfigService $systemConfigService; - - /** - * @internal - */ - public function __construct( - CartPaymentBuilderInterface $cartPaymentBuilder, - OrderPaymentBuilderInterface $orderPaymentBuilder, - PaymentResource $paymentResource, - RouterInterface $router, - PaymentMethodUtil $paymentMethodUtil, - LocaleCodeProvider $localeCodeProvider, - SystemConfigService $systemConfigService, - ) { - $this->cartPaymentBuilder = $cartPaymentBuilder; - $this->orderPaymentBuilder = $orderPaymentBuilder; - $this->paymentResource = $paymentResource; - $this->router = $router; - $this->paymentMethodUtil = $paymentMethodUtil; - $this->localeCodeProvider = $localeCodeProvider; - $this->systemConfigService = $systemConfigService; - } - - public function getPlusData( - Cart $cart, - SalesChannelContext $salesChannelContext, - ): ?PlusData { - $customer = $salesChannelContext->getCustomer(); - if ($customer === null) { - return null; - } - - $finishUrl = $this->createFinishUrl(); - $payment = $this->cartPaymentBuilder->getPayment($cart, $salesChannelContext, $finishUrl, false); - - return $this->getPlusDataFromPayment($payment, $salesChannelContext, $customer); - } - - public function getPlusDataFromOrder( - OrderEntity $order, - SalesChannelContext $salesChannelContext, - ): ?PlusData { - $customer = $salesChannelContext->getCustomer(); - if ($customer === null) { - return null; - } - - $transactions = $order->getTransactions(); - if ($transactions === null) { - throw PaymentException::invalidOrder($order->getId()); - } - - $firstTransaction = $transactions->first(); - if ($firstTransaction === null) { - throw PaymentException::invalidOrder($order->getId()); - } - - $finishUrl = $this->createFinishUrl(true); - $paymentTransaction = new AsyncPaymentTransactionStruct($firstTransaction, $order, $finishUrl); - $payment = $this->orderPaymentBuilder->getPayment($paymentTransaction, $salesChannelContext); - - $plusData = $this->getPlusDataFromPayment($payment, $salesChannelContext, $customer); - if ($plusData === null) { - return null; - } - - $plusData->setOrderId($order->getId()); - - return $plusData; - } - - private function createFinishUrl(bool $orderUpdate = false): string - { - return $this->router->generate( - 'payment.paypal.plus.finalize.transaction', - [ - PayPalPaymentHandler::PAYPAL_PLUS_CHECKOUT_REQUEST_PARAMETER => true, - 'changedPayment' => $orderUpdate, - ], - UrlGeneratorInterface::ABSOLUTE_URL - ); - } - - private function getPlusDataFromPayment( - Payment $payment, - SalesChannelContext $salesChannelContext, - CustomerEntity $customer, - ): ?PlusData { - try { - $response = $this->paymentResource->create( - $payment, - $salesChannelContext->getSalesChannel()->getId(), - PartnerAttributionId::PAYPAL_PLUS - ); - } catch (\Exception $e) { - return null; - } - - $context = $salesChannelContext->getContext(); - $payPalData = new PlusData(); - $payPalData->assign([ - 'approvalUrl' => $response->getLinks()->getAt(1)?->getHref(), - 'mode' => $this->systemConfigService->getBool(Settings::SANDBOX, $salesChannelContext->getSalesChannelId()) ? 'sandbox' : 'live', - 'customerSelectedLanguage' => $this->getPaymentWallLanguage($context), - 'paymentMethodId' => $this->paymentMethodUtil->getPayPalPaymentMethodId($context), - 'paypalPaymentId' => $response->getId(), - 'paypalToken' => PaymentTokenExtractor::extract($response), - 'handlePaymentUrl' => $this->router->generate('frontend.paypal.plus.handle'), - 'isEnabledParameterName' => PayPalPaymentHandler::PAYPAL_PLUS_CHECKOUT_ID, - 'languageId' => $salesChannelContext->getContext()->getLanguageId(), - ]); - $billingAddress = $customer->getDefaultBillingAddress(); - if ($billingAddress !== null) { - $country = $billingAddress->getCountry(); - if ($country !== null) { - $payPalData->assign(['customerCountryIso' => $country->getIso()]); - } - } - - return $payPalData; - } - - private function getPaymentWallLanguage(Context $context): string - { - $languageIso = $this->localeCodeProvider->getLocaleCodeFromContext($context); - - $plusLanguage = 'en_GB'; - // use english as default, use german if the locale is from german speaking country (de_DE, de_AT, etc) - // by now the PPP iFrame does not support other languages - if (\strncmp($languageIso, 'de-', 3) === 0) { - $plusLanguage = 'de_DE'; - } - - return $plusLanguage; - } -} diff --git a/src/PaymentsApi/Administration/PayPalPaymentController.php b/src/PaymentsApi/Administration/PayPalPaymentController.php index e752ab5db..7400c346c 100644 --- a/src/PaymentsApi/Administration/PayPalPaymentController.php +++ b/src/PaymentsApi/Administration/PayPalPaymentController.php @@ -18,21 +18,15 @@ use Swag\PayPal\PaymentsApi\Administration\Exception\RequiredParameterInvalidException; use Swag\PayPal\RestApi\Exception\PayPalApiException; use Swag\PayPal\RestApi\V1\Api\Capture; -use Swag\PayPal\RestApi\V1\Api\Common\Amount; -use Swag\PayPal\RestApi\V1\Api\DoVoid; use Swag\PayPal\RestApi\V1\Api\Payment; use Swag\PayPal\RestApi\V1\Api\Payment\Transaction\RelatedResource; -use Swag\PayPal\RestApi\V1\Api\Refund; use Swag\PayPal\RestApi\V1\Resource\AuthorizationResource; use Swag\PayPal\RestApi\V1\Resource\CaptureResource; use Swag\PayPal\RestApi\V1\Resource\OrdersResource; use Swag\PayPal\RestApi\V1\Resource\PaymentResource; use Swag\PayPal\RestApi\V1\Resource\SaleResource; -use Swag\PayPal\Util\PaymentStatusUtil; -use Swag\PayPal\Util\PriceFormatter; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\JsonResponse; -use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Attribute\Route; @@ -40,35 +34,6 @@ #[Route(defaults: ['_routeScope' => ['api']])] class PayPalPaymentController extends AbstractController { - /** - * @deprecated tag:v10.0.0 - will be removed without replacement - */ - public const REQUEST_PARAMETER_CURRENCY = 'currency'; - /** - * @deprecated tag:v10.0.0 - will be removed without replacement - */ - public const REQUEST_PARAMETER_REFUND_AMOUNT = 'refundAmount'; - /** - * @deprecated tag:v10.0.0 - will be removed without replacement - */ - public const REQUEST_PARAMETER_REFUND_INVOICE_NUMBER = 'refundInvoiceNumber'; - /** - * @deprecated tag:v10.0.0 - will be removed without replacement - */ - public const REQUEST_PARAMETER_CAPTURE_AMOUNT = 'captureAmount'; - /** - * @deprecated tag:v10.0.0 - will be removed without replacement - */ - public const REQUEST_PARAMETER_CAPTURE_IS_FINAL = 'captureIsFinal'; - /** - * @deprecated tag:v10.0.0 - will be removed without replacement - */ - public const REQUEST_PARAMETER_DESCRIPTION = 'description'; - /** - * @deprecated tag:v10.0.0 - will be removed without replacement - */ - public const REQUEST_PARAMETER_REASON = 'reason'; - /** * @internal */ @@ -78,9 +43,7 @@ public function __construct( private readonly AuthorizationResource $authorizationResource, private readonly OrdersResource $ordersResource, private readonly CaptureResource $captureResource, - private readonly PaymentStatusUtil $paymentStatusUtil, private readonly EntityRepository $orderRepository, - private readonly PriceFormatter $priceFormatter, ) { } @@ -194,222 +157,6 @@ public function resourceDetails(Context $context, string $resourceType, string $ return new JsonResponse($resource); } - /** - * @throws RequiredParameterInvalidException - * - * @deprecated tag:v10.0.0 - will be removed without replacement - */ - #[OA\Post( - path: '/api/_action/paypal/refund-payment/{resourceType}/{resourceId}/{orderId}', - operationId: 'paypalRefundPayment', - tags: ['Admin Api', 'PayPal'], - parameters: [ - new OA\Parameter( - parameter: 'resourceType', - name: 'resourceType', - in: 'path', - required: true, - schema: new OA\Schema(type: 'string', enum: [RelatedResource::AUTHORIZE, RelatedResource::ORDER]) - ), - new OA\Parameter( - parameter: 'resourceId', - name: 'resourceId', - in: 'path', - required: true, - schema: new OA\Schema(type: 'string') - ), - new OA\Parameter( - parameter: 'orderId', - name: 'orderId', - in: 'path', - required: true, - schema: new OA\Schema(type: 'string', pattern: '^[0-9a-f]{32}$') - ), - ], - responses: [new OA\Response( - response: Response::HTTP_OK, - description: 'Capture for the given resource', - content: new OA\JsonContent(ref: DoVoid::class) - )] - )] - #[Route(path: '/api/_action/paypal/refund-payment/{resourceType}/{resourceId}/{orderId}', name: 'api.action.paypal.refund_payment', methods: ['POST'], defaults: ['_acl' => ['order.editor']])] - public function refundPayment( - Request $request, - Context $context, - string $resourceType, - string $resourceId, - string $orderId, - ): JsonResponse { - $refund = $this->createRefund($request); - $salesChannelId = $this->getSalesChannelIdByOrderId($orderId, $context); - - switch ($resourceType) { - case RelatedResource::SALE: - $refundResponse = $this->saleResource->refund( - $resourceId, - $refund, - $salesChannelId - ); - $this->paymentStatusUtil->applyRefundStateToPayment($orderId, $refundResponse, $context); - - break; - case RelatedResource::CAPTURE: - $refundResponse = $this->captureResource->refund( - $resourceId, - $refund, - $salesChannelId - ); - $paymentResponse = $this->paymentResource->get($refundResponse->getParentPayment(), $salesChannelId); - $this->paymentStatusUtil->applyRefundStateToCapture($orderId, $refundResponse, $paymentResponse, $context); - - break; - default: - throw new RequiredParameterInvalidException('resourceType'); - } - - return new JsonResponse($refundResponse); - } - - /** - * @throws RequiredParameterInvalidException - * - * @deprecated tag:v10.0.0 - will be removed without replacement - */ - #[OA\Post( - path: '/api/_action/paypal/capture-payment/{resourceType}/{resourceId}/{orderId}', - operationId: 'paypalCapturePayment', - tags: ['Admin Api', 'PayPal'], - parameters: [ - new OA\Parameter( - parameter: 'resourceType', - name: 'resourceType', - in: 'path', - required: true, - schema: new OA\Schema(type: 'string', enum: [RelatedResource::AUTHORIZE, RelatedResource::ORDER]) - ), - new OA\Parameter( - parameter: 'resourceId', - name: 'resourceId', - in: 'path', - required: true, - schema: new OA\Schema(type: 'string') - ), - new OA\Parameter( - parameter: 'orderId', - name: 'orderId', - in: 'path', - required: true, - schema: new OA\Schema(type: 'string', pattern: '^[0-9a-f]{32}$') - ), - ], - responses: [new OA\Response( - response: Response::HTTP_OK, - description: 'Capture for the given resource', - content: new OA\JsonContent(ref: DoVoid::class) - )] - )] - #[Route(path: '/api/_action/paypal/capture-payment/{resourceType}/{resourceId}/{orderId}', name: 'api.action.paypal.catpure_payment', methods: ['POST'], defaults: ['_acl' => ['order.editor']])] - public function capturePayment( - Request $request, - Context $context, - string $resourceType, - string $resourceId, - string $orderId, - ): JsonResponse { - $capture = $this->createCapture($request); - - switch ($resourceType) { - case RelatedResource::AUTHORIZE: - $captureResponse = $this->authorizationResource->capture( - $resourceId, - $capture, - $this->getSalesChannelIdByOrderId($orderId, $context) - ); - - break; - case RelatedResource::ORDER: - $salesChannelId = $this->getSalesChannelIdByOrderId($orderId, $context); - $captureResponse = $this->ordersResource->capture($resourceId, $capture, $salesChannelId); - - break; - default: - throw new RequiredParameterInvalidException('resourceType'); - } - - $this->paymentStatusUtil->applyCaptureState($orderId, $captureResponse, $context); - - return new JsonResponse($captureResponse); - } - - /** - * @throws RequiredParameterInvalidException - * - * @deprecated tag:v10.0.0 - will be removed without replacement - */ - #[OA\Post( - path: '/api/_action/paypal/void-payment/{resourceType}/{resourceId}/{orderId}', - operationId: 'paypalVoidPayment', - tags: ['Admin Api', 'PayPal'], - parameters: [ - new OA\Parameter( - parameter: 'resourceType', - name: 'resourceType', - in: 'path', - required: true, - schema: new OA\Schema(type: 'string', enum: [RelatedResource::AUTHORIZE, RelatedResource::ORDER]) - ), - new OA\Parameter( - parameter: 'resourceId', - name: 'resourceId', - in: 'path', - required: true, - schema: new OA\Schema(type: 'string') - ), - new OA\Parameter( - parameter: 'orderId', - name: 'orderId', - in: 'path', - required: true, - schema: new OA\Schema(type: 'string', pattern: '^[0-9a-f]{32}$') - ), - ], - responses: [new OA\Response( - response: Response::HTTP_OK, - description: 'Voidance for the given resource', - content: new OA\JsonContent(ref: DoVoid::class) - )] - )] - #[Route(path: '/api/_action/paypal/void-payment/{resourceType}/{resourceId}/{orderId}', name: 'api.action.paypal.void_payment', methods: ['POST'], defaults: ['_acl' => ['order.editor']])] - public function voidPayment( - Context $context, - string $resourceType, - string $resourceId, - string $orderId, - ): JsonResponse { - switch ($resourceType) { - case RelatedResource::AUTHORIZE: - $voidResponse = $this->authorizationResource->void( - $resourceId, - $this->getSalesChannelIdByOrderId($orderId, $context) - ); - - break; - case RelatedResource::ORDER: - $voidResponse = $this->ordersResource->void( - $resourceId, - $this->getSalesChannelIdByOrderId($orderId, $context) - ); - - break; - default: - throw new RequiredParameterInvalidException('resourceType'); - } - - $this->paymentStatusUtil->applyVoidStateToOrder($orderId, $context); - - return new JsonResponse($voidResponse); - } - private function getSalesChannelIdByOrderId(string $orderId, Context $context): string { /** @var OrderEntity|null $order */ @@ -421,53 +168,4 @@ private function getSalesChannelIdByOrderId(string $orderId, Context $context): return $order->getSalesChannelId(); } - - private function createRefund(Request $request): Refund - { - $currency = $request->request->getAlpha(self::REQUEST_PARAMETER_CURRENCY); - $refundAmount = $this->priceFormatter->formatPrice((float) $request->request->get(self::REQUEST_PARAMETER_REFUND_AMOUNT), $currency); - $invoiceNumber = (string) $request->request->get(self::REQUEST_PARAMETER_REFUND_INVOICE_NUMBER, ''); - $description = (string) $request->request->get(self::REQUEST_PARAMETER_DESCRIPTION, ''); - $reason = (string) $request->request->get(self::REQUEST_PARAMETER_REASON, ''); - - $refund = new Refund(); - - if ($invoiceNumber !== '') { - $refund->setInvoiceNumber($invoiceNumber); - } - - if ($refundAmount !== '0.00') { - $amount = new Amount(); - $amount->setTotal($refundAmount); - $amount->setCurrency($currency); - - $refund->setAmount($amount); - } - - if ($description !== '') { - $refund->setDescription($description); - } - if ($reason !== '') { - $refund->setReason($reason); - } - - return $refund; - } - - private function createCapture(Request $request): Capture - { - $currency = $request->request->getAlpha(self::REQUEST_PARAMETER_CURRENCY); - $amountToCapture = $this->priceFormatter->formatPrice((float) $request->request->get(self::REQUEST_PARAMETER_CAPTURE_AMOUNT), $currency); - $isFinalCapture = $request->request->getBoolean(self::REQUEST_PARAMETER_CAPTURE_IS_FINAL, true); - - $capture = new Capture(); - $capture->setIsFinalCapture($isFinalCapture); - $amount = new Amount(); - $amount->setTotal($amountToCapture); - $amount->setCurrency($currency); - - $capture->setAmount($amount); - - return $capture; - } } diff --git a/src/Resources/app/administration/src/module/extension/sw-settings-payment/components/swag-paypal-overview-card/swag-paypal-overview-card.html.twig b/src/Resources/app/administration/src/module/extension/sw-settings-payment/components/swag-paypal-overview-card/swag-paypal-overview-card.html.twig index 14107d592..b63bb52f0 100644 --- a/src/Resources/app/administration/src/module/extension/sw-settings-payment/components/swag-paypal-overview-card/swag-paypal-overview-card.html.twig +++ b/src/Resources/app/administration/src/module/extension/sw-settings-payment/components/swag-paypal-overview-card/swag-paypal-overview-card.html.twig @@ -25,7 +25,6 @@ :isLoading="isLoading" showSettingsLink @on-save-settings="save" - @on-deactivate-paypal-plus="save" @on-change-loading="onChangeLoading" /> {% endblock %} diff --git a/src/Resources/app/administration/src/module/swag-paypal-payment/component/swag-paypal-payment-actions/extensions/swag-paypal-payment-action-capture/index.js b/src/Resources/app/administration/src/module/swag-paypal-payment/component/swag-paypal-payment-actions/extensions/swag-paypal-payment-action-capture/index.js deleted file mode 100644 index aec6a6a4a..000000000 --- a/src/Resources/app/administration/src/module/swag-paypal-payment/component/swag-paypal-payment-actions/extensions/swag-paypal-payment-action-capture/index.js +++ /dev/null @@ -1,114 +0,0 @@ -import template from './swag-paypal-payment-action-capture.html.twig'; - -const { Component } = Shopware; -const utils = Shopware.Utils; - -/** - * @deprecated tag:v10.0.0 - will be removed without replacement - */ -Component.register('swag-paypal-payment-action-capture', { - template, - - inject: ['SwagPayPalPaymentService'], - - mixins: [ - Shopware.Mixin.getByName('notification'), - ], - - props: { - paymentResource: { - type: Object, - required: true, - }, - - maxCaptureValue: { - type: Number, - required: true, - }, - - orderId: { - type: String, - required: true, - }, - }, - - data() { - return { - isFinalCapture: true, - captureValue: this.maxCaptureValue, - isLoading: true, - currency: this.paymentResource.transactions[0].amount.currency, - }; - }, - - computed: { - showHint() { - return this.isFinalCapture && this.captureValue !== this.maxCaptureValue; - }, - }, - - created() { - this.createdComponent(); - }, - - methods: { - createdComponent() { - this.isLoading = false; - }, - - capture() { - const captureAmount = this.captureValue; - const currency = this.currency; - const isFinalCapture = this.isFinalCapture; - const resourceType = this.paymentResource.intent; - const resourceId = this.getResourceId(this.paymentResource); - - this.isLoading = true; - this.SwagPayPalPaymentService.capturePayment( - this.orderId, - resourceType, - resourceId, - captureAmount, - currency, - isFinalCapture, - ).then(() => { - this.createNotificationSuccess({ - message: this.$tc('swag-paypal-payment.captureAction.successMessage'), - }); - this.isLoading = false; - this.$emit('modal-close'); - this.$nextTick(() => { - this.$router.replace(`${this.$route.path}?hash=${utils.createId()}`); - }); - }).catch((errorResponse) => { - try { - this.createNotificationError({ - message: `${errorResponse.response.data.errors[0].title}: ${ - errorResponse.response.data.errors[0].detail}`, - autoClose: false, - }); - } catch (e) { - this.createNotificationError({ - message: `${errorResponse.title}: ${errorResponse.message}`, - autoClose: false, - }); - } finally { - this.isLoading = false; - } - }); - }, - - getResourceId(paymentResource) { - let relatedResourceId = null; - paymentResource.transactions[0].related_resources.forEach((relatedResource) => { - if (relatedResource.authorization) { - relatedResourceId = relatedResource.authorization.id; - } - if (relatedResource.order) { - relatedResourceId = relatedResource.order.id; - } - }); - return relatedResourceId; - }, - }, -}); diff --git a/src/Resources/app/administration/src/module/swag-paypal-payment/component/swag-paypal-payment-actions/extensions/swag-paypal-payment-action-capture/swag-paypal-payment-action-capture.html.twig b/src/Resources/app/administration/src/module/swag-paypal-payment/component/swag-paypal-payment-actions/extensions/swag-paypal-payment-action-capture/swag-paypal-payment-action-capture.html.twig deleted file mode 100644 index 39f979e69..000000000 --- a/src/Resources/app/administration/src/module/swag-paypal-payment/component/swag-paypal-payment-actions/extensions/swag-paypal-payment-action-capture/swag-paypal-payment-action-capture.html.twig +++ /dev/null @@ -1,55 +0,0 @@ -{% block swag_paypal_payment_action_capture %} - - - {% block swag_paypal_payment_action_capture_max_amount %} - - {% endblock %} - - {% block swag_paypal_payment_action_capture_value %} - - - - {% endblock %} - - {% block swag_paypal_payment_action_capture_is_final_capture %} - - {% endblock %} - - {% block swag_paypal_payment_action_capture_hint %} - - {{ $tc('swag-paypal-payment.captureAction.isFinalHint') }} - - {% endblock %} - - {% block swag_paypal_payment_action_capture_submit_button %} - - {% endblock %} - - - -{% endblock %} diff --git a/src/Resources/app/administration/src/module/swag-paypal-payment/component/swag-paypal-payment-actions/extensions/swag-paypal-payment-action-refund/index.js b/src/Resources/app/administration/src/module/swag-paypal-payment/component/swag-paypal-payment-actions/extensions/swag-paypal-payment-action-refund/index.js deleted file mode 100644 index dbd1649ab..000000000 --- a/src/Resources/app/administration/src/module/swag-paypal-payment/component/swag-paypal-payment-actions/extensions/swag-paypal-payment-action-refund/index.js +++ /dev/null @@ -1,191 +0,0 @@ -import template from './swag-paypal-payment-action-refund.html.twig'; -import { CAPTURE_RESOURCE_TYPE, REFUNDED_STATE, SALE_RESOURCE_TYPE } from '../../swag-paypal-payment-consts'; - -const { Component, Filter } = Shopware; -const utils = Shopware.Utils; - -/** - * @deprecated tag:v10.0.0 - will be removed without replacement - */ -Component.register('swag-paypal-payment-action-refund', { - template, - - inject: ['SwagPayPalPaymentService'], - - mixins: [ - Shopware.Mixin.getByName('notification'), - ], - - props: { - paymentResource: { - type: Object, - required: true, - }, - - orderId: { - type: String, - required: true, - }, - }, - - data() { - return { - captures: [], - selectedCapture: {}, - existingRefunds: [], - refundAmount: 0, - refundableAmount: 0, - refundDescription: '', - refundReason: '', - refundInvoiceNumber: '', - isLoading: true, - selectedCaptureId: '', - }; - }, - - computed: { - dateFilter() { - return Filter.getByName('date'); - }, - }, - - created() { - this.createdComponent(); - }, - - methods: { - createdComponent() { - this.getRefundableCaptures(); - this.mapRefunds(); - this.selectedCaptureId = this.captures[0].id; - this.isLoading = false; - this.preserveCapture(); - this.refundAmount = Number(this.captures[0].refundableAmount); - }, - - getRefundableCaptures() { - const relatedResources = this.paymentResource.transactions[0].related_resources; - - this.captures = relatedResources.reduce((accumulator, relatedResource) => { - if (relatedResource.sale) { - const sale = relatedResource.sale; - - if (sale.state !== REFUNDED_STATE) { - accumulator.push(this.formatCapture(sale, SALE_RESOURCE_TYPE)); - } - } - - if (relatedResource.capture) { - const capture = relatedResource.capture; - - if (capture.state !== REFUNDED_STATE) { - accumulator.push(this.formatCapture(capture, CAPTURE_RESOURCE_TYPE)); - } - } - - if (relatedResource.refund) { - this.existingRefunds.push(relatedResource.refund); - } - - return accumulator; - }, this.captures); - }, - - formatCapture(resource, resourceType) { - const createDate = this.dateFilter(resource.create_time); - - return { - label: `${createDate} (${resource.amount.total} ${resource.amount.currency})` + - ` - ${resource.id} [${resource.state}]`, - id: resource.id, - refundableAmount: resource.amount.total, - currency: resource.amount.currency, - type: resourceType, - }; - }, - - mapRefunds() { - this.existingRefunds.forEach((refund) => { - const capture = this.captures.find((resource) => { - switch (resource.type) { - case CAPTURE_RESOURCE_TYPE: - return (refund.capture_id === resource.id); - case SALE_RESOURCE_TYPE: - return (refund.sale_id === resource.id); - default: - return false; - } - }); - - if (capture) { - let refundAmount = Number(refund.amount.total); - if (refundAmount < 0) { - refundAmount *= -1.0; - } - capture.refundableAmount -= refundAmount; - } - }); - }, - - preserveCapture() { - const capture = this.captures.find((selectedCapture) => { - return selectedCapture.id === this.selectedCaptureId; - }); - - this.selectedCapture = capture; - this.refundableAmount = Number(capture.refundableAmount); - this.refundAmount = Number(capture.refundableAmount); - }, - - refund() { - this.isLoading = true; - - let refundAmount = this.refundAmount; - const description = this.refundDescription; - const currency = this.selectedCapture.currency; - const resourceType = this.selectedCapture.type; - const resourceId = this.selectedCapture.id; - const reason = this.refundReason; - const invoiceNumber = this.refundInvoiceNumber; - - if (refundAmount === 0) { - refundAmount = this.refundableAmount; - } - - this.SwagPayPalPaymentService.refundPayment( - this.orderId, - resourceType, - resourceId, - refundAmount, - currency, - description, - reason, - invoiceNumber, - ).then(() => { - this.createNotificationSuccess({ - message: this.$tc('swag-paypal-payment.refundAction.successMessage'), - }); - this.isLoading = false; - this.$emit('modal-close'); - this.$nextTick(() => { - this.$router.replace(`${this.$route.path}?hash=${utils.createId()}`); - }); - }).catch((errorResponse) => { - try { - this.createNotificationError({ - message: `${errorResponse.response.data.errors[0].title}: ${ - errorResponse.response.data.errors[0].detail}`, - autoClose: false, - }); - } catch (e) { - this.createNotificationError({ - message: `${errorResponse.title}: ${errorResponse.message}`, - autoClose: false, - }); - } finally { - this.isLoading = false; - } - }); - }, - }, -}); diff --git a/src/Resources/app/administration/src/module/swag-paypal-payment/component/swag-paypal-payment-actions/extensions/swag-paypal-payment-action-refund/swag-paypal-payment-action-refund.html.twig b/src/Resources/app/administration/src/module/swag-paypal-payment/component/swag-paypal-payment-actions/extensions/swag-paypal-payment-action-refund/swag-paypal-payment-action-refund.html.twig deleted file mode 100644 index c2e9881c6..000000000 --- a/src/Resources/app/administration/src/module/swag-paypal-payment/component/swag-paypal-payment-actions/extensions/swag-paypal-payment-action-refund/swag-paypal-payment-action-refund.html.twig +++ /dev/null @@ -1,73 +0,0 @@ -{% block swag_paypal_payment_action_refund %} - - - {% block swag_paypal_payment_action_refund_invoice_select %} - - - - {% endblock %} - - {% block swag_paypal_payment_action_refund_invoice_number %} - - {% endblock %} - - {% block swag_paypal_payment_action_refund_reason %} - - {% endblock %} - - {% block swag_paypal_payment_action_refund_amount %} - - - - {% endblock %} - - {% block swag_paypal_payment_action_refund_description %} - - {% endblock %} - - {% block swag_paypal_payment_action_refund_confirm_button %} - - {% endblock %} - - - -{% endblock %} diff --git a/src/Resources/app/administration/src/module/swag-paypal-payment/component/swag-paypal-payment-actions/extensions/swag-paypal-payment-action-void/index.js b/src/Resources/app/administration/src/module/swag-paypal-payment/component/swag-paypal-payment-actions/extensions/swag-paypal-payment-action-void/index.js deleted file mode 100644 index 3b7d09156..000000000 --- a/src/Resources/app/administration/src/module/swag-paypal-payment/component/swag-paypal-payment-actions/extensions/swag-paypal-payment-action-void/index.js +++ /dev/null @@ -1,84 +0,0 @@ -import template from './swag-paypal-payment-action-void.html.twig'; - -const { Component } = Shopware; -const utils = Shopware.Utils; - -/** - * @deprecated tag:v10.0.0 - will be removed without replacement - */ -Component.register('swag-paypal-payment-action-void', { - template, - - inject: ['SwagPayPalPaymentService'], - - mixins: [ - Shopware.Mixin.getByName('notification'), - ], - - props: { - paymentResource: { - type: Object, - required: true, - }, - - orderId: { - type: String, - required: true, - }, - }, - - data() { - return { - isLoading: false, - }; - }, - - methods: { - voidPayment() { - this.isLoading = true; - const resourceType = this.paymentResource.intent; - const resourceId = this.getResourceId(); - const orderId = this.$route.params.id; - - this.SwagPayPalPaymentService.voidPayment(this.orderId, resourceType, resourceId, orderId).then(() => { - this.createNotificationSuccess({ - message: this.$tc('swag-paypal-payment.voidAction.successMessage'), - }); - this.isLoading = false; - this.closeModal(); - this.$nextTick(() => { - this.$router.replace(`${this.$route.path}?hash=${utils.createId()}`); - }); - }).catch((errorResponse) => { - try { - this.createNotificationError({ - message: `${errorResponse.response.data.errors[0].title}: ${ - errorResponse.response.data.errors[0].detail}`, - autoClose: false, - }); - } catch (e) { - this.createNotificationError({ - message: `${errorResponse.title}: ${errorResponse.message}`, - autoClose: false, - }); - } finally { - this.isLoading = false; - } - }); - }, - - getResourceId() { - const firstRelatedResource = this.paymentResource.transactions[0].related_resources[0]; - - if (firstRelatedResource.order) { - return firstRelatedResource.order.id; - } - - return firstRelatedResource.authorization.id; - }, - - closeModal() { - this.$emit('modal-close'); - }, - }, -}); diff --git a/src/Resources/app/administration/src/module/swag-paypal-payment/component/swag-paypal-payment-actions/extensions/swag-paypal-payment-action-void/swag-paypal-payment-action-void.html.twig b/src/Resources/app/administration/src/module/swag-paypal-payment/component/swag-paypal-payment-actions/extensions/swag-paypal-payment-action-void/swag-paypal-payment-action-void.html.twig deleted file mode 100644 index 0294b8d71..000000000 --- a/src/Resources/app/administration/src/module/swag-paypal-payment/component/swag-paypal-payment-actions/extensions/swag-paypal-payment-action-void/swag-paypal-payment-action-void.html.twig +++ /dev/null @@ -1,30 +0,0 @@ -{% block swag_paypal_paymemnt_action_void %} - - - {% block swag_paypal_paymemnt_action_void_headline %} -

{{ $tc('swag-paypal-payment.voidAction.confirm.message') }}

- {% endblock %} - - - - -
-{% endblock %} diff --git a/src/Resources/app/administration/src/module/swag-paypal-payment/component/swag-paypal-payment-actions/index.js b/src/Resources/app/administration/src/module/swag-paypal-payment/component/swag-paypal-payment-actions/index.js deleted file mode 100644 index 047e5299d..000000000 --- a/src/Resources/app/administration/src/module/swag-paypal-payment/component/swag-paypal-payment-actions/index.js +++ /dev/null @@ -1,153 +0,0 @@ -import template from './swag-paypal-payment-actions.html.twig'; -import './swag-paypal-payment-actions.scss'; -import './extensions/swag-paypal-payment-action-capture'; -import './extensions/swag-paypal-payment-action-refund'; -import './extensions/swag-paypal-payment-action-void'; -import { - CANCELLED_STATE, - CAPTURED_STATE, - COMPLETED_STATE, - FAILED_STATE, - VOIDED_STATE, -} from './swag-paypal-payment-consts'; - -const { Component } = Shopware; - -/** - * @deprecated tag:v10.0.0 - will be removed without replacement - */ -Component.register('swag-paypal-payment-actions', { - template, - - inject: [ - 'acl', - ], - - props: { - paymentResource: { - type: Object, - required: true, - }, - - orderId: { - type: String, - required: true, - }, - }, - - data() { - return { - modalType: '', - refundableAmount: 0, - captureableAmount: 0, - showVoidButton: false, - relatedResources: null, - }; - }, - - created() { - this.createdComponent(); - }, - - methods: { - createdComponent() { - this.relatedResources = this.paymentResource.transactions[0].related_resources; - this.setPaymentActionAmounts(); - this.setShowVoidButton(); - this.captureableAmount = this.formatAmount(this.captureableAmount); - this.refundableAmount = this.formatAmount(this.refundableAmount); - }, - - spawnModal(modalType) { - this.modalType = modalType; - }, - - closeModal() { - this.modalType = ''; - }, - - setPaymentActionAmounts() { - if (!this.relatedResources) { - return; - } - - this.relatedResources.forEach((relatedResource) => { - if (relatedResource.authorization) { - if (relatedResource.authorization.state !== COMPLETED_STATE) { - this.captureableAmount += Number(relatedResource.authorization.amount.total); - } - } - - if (relatedResource.order) { - if (relatedResource.order.state !== COMPLETED_STATE) { - this.captureableAmount += Number(relatedResource.order.amount.total); - } - } - - if (relatedResource.sale) { - this.refundableAmount += Number(relatedResource.sale.amount.total); - } - - if (relatedResource.capture) { - const captureAmount = Number(relatedResource.capture.amount.total); - this.captureableAmount -= captureAmount; - this.refundableAmount += captureAmount; - } - - if (relatedResource.refund) { - if (relatedResource.refund.state !== FAILED_STATE - && relatedResource.refund.state !== CANCELLED_STATE - ) { - let refund = Number(relatedResource.refund.amount.total); - if (refund > 0) { - refund *= -1.0; - } - this.refundableAmount += refund; - } - } - }); - }, - - setShowVoidButton() { - if (!this.relatedResources) { - return; - } - - const firstRelatedResource = this.relatedResources[0]; - - if (!firstRelatedResource) { - return; - } - - const nonVoidAbleStates = [VOIDED_STATE, CAPTURED_STATE, COMPLETED_STATE]; - - if (firstRelatedResource.sale) { - return; - } - - if (firstRelatedResource.order) { - const order = firstRelatedResource.order; - if (nonVoidAbleStates.includes(order.state)) { - this.captureableAmount = 0; - return; - } - - this.showVoidButton = true; - } - - if (firstRelatedResource.authorization) { - const authorization = firstRelatedResource.authorization; - if (nonVoidAbleStates.includes(authorization.state)) { - this.captureableAmount = 0; - return; - } - - this.showVoidButton = true; - } - }, - - formatAmount(value) { - return Number(`${Math.round(`${value}e2`)}e-2`); - }, - }, -}); diff --git a/src/Resources/app/administration/src/module/swag-paypal-payment/component/swag-paypal-payment-actions/swag-paypal-payment-actions.html.twig b/src/Resources/app/administration/src/module/swag-paypal-payment/component/swag-paypal-payment-actions/swag-paypal-payment-actions.html.twig deleted file mode 100644 index 9b85b3b7a..000000000 --- a/src/Resources/app/administration/src/module/swag-paypal-payment/component/swag-paypal-payment-actions/swag-paypal-payment-actions.html.twig +++ /dev/null @@ -1,72 +0,0 @@ -{% block swag_paypal_payment_actions %} -
-
-
- - {% block swag_paypal_payment_actions_void %} - - {{ $tc('swag-paypal-payment.buttons.label.void') }} - - {% endblock %} - - {% block swag_paypal_payment_actions_capture %} - - {{ $tc('swag-paypal-payment.buttons.label.capture') }} - - {% endblock %} -
- - {% block swag_paypal_payment_actions_refund %} - - {{ $tc('swag-paypal-payment.buttons.label.refund') }} - - {% endblock %} - -
- - {% block swag_paypal_payment_actions_modal %} - {% block swag_paypal_payment_actions_modal_capture %} - - {% endblock %} - - {% block swag_paypal_payment_actions_modal_refund %} - - {% endblock %} - - {% block swag_paypal_payment_actions_modal_void %} - - {% endblock %} - {% endblock %} -
-{% endblock %} diff --git a/src/Resources/app/administration/src/module/swag-paypal-payment/component/swag-paypal-payment-actions/swag-paypal-payment-actions.scss b/src/Resources/app/administration/src/module/swag-paypal-payment/component/swag-paypal-payment-actions/swag-paypal-payment-actions.scss deleted file mode 100644 index 11d651d2a..000000000 --- a/src/Resources/app/administration/src/module/swag-paypal-payment/component/swag-paypal-payment-actions/swag-paypal-payment-actions.scss +++ /dev/null @@ -1,12 +0,0 @@ -.swag-paypal-payment-actions__button-container { - display: flex; - justify-content: space-between; -} - -.swag-paypal-payment-actions__authorize-button-group { - display: flex; - - .sw-button:not(:last-child) { - margin-right: 10px; - } -} diff --git a/src/Resources/app/administration/src/module/swag-paypal-payment/component/swag-paypal-payment-actions/swag-paypal-payment-consts.js b/src/Resources/app/administration/src/module/swag-paypal-payment/component/swag-paypal-payment-actions/swag-paypal-payment-consts.js deleted file mode 100644 index a8ac986c8..000000000 --- a/src/Resources/app/administration/src/module/swag-paypal-payment/component/swag-paypal-payment-actions/swag-paypal-payment-consts.js +++ /dev/null @@ -1,21 +0,0 @@ -export const REFUNDED_STATE = 'refunded'; -export const VOIDED_STATE = 'voided'; -export const CAPTURED_STATE = 'captured'; -export const COMPLETED_STATE = 'completed'; -export const CAPTURE_RESOURCE_TYPE = 'capture'; -export const SALE_RESOURCE_TYPE = 'sale'; -export const FAILED_STATE = 'failed'; -export const DENIED_STATE = 'denied'; -export const CANCELLED_STATE = 'cancelled'; - -export default { - REFUNDED_STATE, - VOIDED_STATE, - CAPTURED_STATE, - COMPLETED_STATE, - CAPTURE_RESOURCE_TYPE, - SALE_RESOURCE_TYPE, - FAILED_STATE, - DENIED_STATE, - CANCELLED_STATE, -}; diff --git a/src/Resources/app/administration/src/module/swag-paypal-payment/component/swag-paypal-payment-details-v1/swag-paypal-payment-details-v1.html.twig b/src/Resources/app/administration/src/module/swag-paypal-payment/component/swag-paypal-payment-details-v1/swag-paypal-payment-details-v1.html.twig index 346c4102d..502a79291 100644 --- a/src/Resources/app/administration/src/module/swag-paypal-payment/component/swag-paypal-payment-details-v1/swag-paypal-payment-details-v1.html.twig +++ b/src/Resources/app/administration/src/module/swag-paypal-payment/component/swag-paypal-payment-details-v1/swag-paypal-payment-details-v1.html.twig @@ -6,12 +6,6 @@ >