Skip to content

Commit

Permalink
Merge branch 'pt-12692/fix-virtual-urls' into 'master'
Browse files Browse the repository at this point in the history
PT-12692 - Fix virtual urls

See merge request shopware/5/services/swagpaymentpaypalunified!162
  • Loading branch information
mitelg committed Apr 8, 2022
2 parents f76a0b7 + c9cfd8a commit c52c843
Show file tree
Hide file tree
Showing 29 changed files with 350 additions and 246 deletions.
5 changes: 4 additions & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ default:
- php bin/console sw:firstrunwizard:disable
- php bin/console sw:admin:create --name="Demo" --email="[email protected]" --username="demo" --password="demo" --locale=de_DE -n
- touch recovery/install/data/install.lock
- cp -r custom/plugins/${PLUGIN_NAME}/Tests/config_gitlab.php config.php

.prepare_installation_script_install_shopware_make: &prepare_installation_script_install_shopware_make
- eval export DB_USER DB_PASSWORD DB_HOST DB_PORT DB_NAME SW_HOST SW_BASE_PATH
- make init
- cp -r custom/plugins/${PLUGIN_NAME}/Tests/config_gitlab.php config.php

.prepare_installation_script_install_plugin: &prepare_installation_script_install_plugin
- php bin/console sw:plugin:refresh
Expand Down Expand Up @@ -86,7 +88,7 @@ default:
- *entrypoint_script
- cd custom/plugins/${PLUGIN_NAME}
script:
- ../../../vendor/bin/phpunit -v --config="phpunit.xml.dist" --colors="never" --log-junit="${ARTIFACTS_ROOT}/test-log.junit.xml"
- ../../../vendor/bin/phpunit --stderr -v --config="phpunit.xml.dist" --colors="never" --log-junit="${ARTIFACTS_ROOT}/test-log.junit.xml"
artifacts:
paths:
- ${ARTIFACTS_ROOT}
Expand Down Expand Up @@ -158,6 +160,7 @@ Code Coverage:
script:
- php -d pcov.enabled="1" -d pcov.directory="${CI_PROJECT_DIR}" -d pcov.exclude='~(vendor|Tests)~'
../../../vendor/bin/phpunit
--stderr
--configuration="phpunit.xml.dist"
--colors="never"
--log-junit="${ARTIFACTS_ROOT}/phpunit.junit.xml"
Expand Down
101 changes: 72 additions & 29 deletions Controllers/Backend/PaypalUnified.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,16 @@
use Shopware\Components\Model\QueryBuilder;
use Shopware\Models\Order\Order;
use Shopware\Models\Order\Status;
use SwagPaymentPayPalUnified\Components\Backend\CaptureService;
use SwagPaymentPayPalUnified\Components\Backend\PaymentDetailsService;
use SwagPaymentPayPalUnified\Components\Backend\VoidService;
use SwagPaymentPayPalUnified\Components\Backend\ShopRegistrationService;
use SwagPaymentPayPalUnified\Components\ExceptionHandlerServiceInterface;
use SwagPaymentPayPalUnified\Components\PaymentMethodProviderInterface;
use SwagPaymentPayPalUnified\Components\PaymentStatus;
use SwagPaymentPayPalUnified\Components\Services\PaymentStatusService;
use SwagPaymentPayPalUnified\PayPalBundle\Resources\AuthorizationResource;
use SwagPaymentPayPalUnified\PayPalBundle\Resources\CaptureResource;
use SwagPaymentPayPalUnified\PayPalBundle\Resources\OrderResource;
use SwagPaymentPayPalUnified\PayPalBundle\Resources\RefundResource;
use SwagPaymentPayPalUnified\PayPalBundle\Resources\SaleResource;
use SwagPaymentPayPalUnified\PayPalBundle\Structs\Payment\SaleRefund;
use SwagPaymentPayPalUnified\PayPalBundle\Structs\Payment\Transactions\Amount;

/**
* @extends Shopware_Controllers_Backend_Application<Order>
*/
class Shopware_Controllers_Backend_PaypalUnified extends Shopware_Controllers_Backend_Application
{
/**
Expand Down Expand Up @@ -53,13 +48,18 @@ class Shopware_Controllers_Backend_PaypalUnified extends Shopware_Controllers_Ba
'customer.email',
];

/**
* @var ShopRegistrationService
*/
private $registrationService;

/**
* {@inheritdoc}
*/
public function preDispatch()
{
$this->exceptionHandler = $this->container->get('paypal_unified.exception_handler_service');
$this->container->get('paypal_unified.backend.shop_registration_service')->registerShopById((int) $this->request->getParam('shopId'));
$this->registrationService = $this->container->get('paypal_unified.backend.shop_registration_service');

parent::preDispatch();
}
Expand All @@ -69,27 +69,34 @@ public function preDispatch()
* It first requests the payment details from the PayPal API and assigns the whole object
* to the response. Afterwards, it uses the paypal_unified.sales_history_builder_service service to
* parse the sales history. The sales history is also being assigned to the response.
*
* @return void
*/
public function paymentDetailsAction()
{
$this->registrationService->registerShopById((int) $this->request->getParam('shopId'));

$paymentId = $this->Request()->getParam('id');
$paymentMethodId = $this->Request()->getParam('paymentMethodId');
//For legacy orders, the payment id is the transactionId and not the temporaryId
$transactionId = $this->Request()->getParam('transactionId');

/** @var PaymentDetailsService $paymentDetailService */
$paymentDetailService = $this->get('paypal_unified.backend.payment_details_service');
$viewParameter = $paymentDetailService->getPaymentDetails($paymentId, $paymentMethodId, $transactionId);

$this->View()->assign($viewParameter);
}

/**
* @return void
*/
public function saleDetailsAction()
{
$this->registrationService->registerShopById((int) $this->request->getParam('shopId'));

$saleId = $this->Request()->getParam('id');
$view = $this->View();

/** @var SaleResource $saleResource */
$saleResource = $this->get('paypal_unified.sale_resource');

try {
Expand All @@ -105,12 +112,16 @@ public function saleDetailsAction()
}
}

/**
* @return void
*/
public function refundDetailsAction()
{
$this->registrationService->registerShopById((int) $this->request->getParam('shopId'));

$saleId = $this->Request()->getParam('id');
$view = $this->View();

/** @var RefundResource $refundResource */
$refundResource = $this->get('paypal_unified.refund_resource');

try {
Expand All @@ -126,12 +137,16 @@ public function refundDetailsAction()
}
}

/**
* @return void
*/
public function captureDetailsAction()
{
$this->registrationService->registerShopById((int) $this->request->getParam('shopId'));

$captureId = $this->Request()->getParam('id');
$view = $this->View();

/** @var CaptureResource $captureResource */
$captureResource = $this->get('paypal_unified.capture_resource');

try {
Expand All @@ -147,12 +162,16 @@ public function captureDetailsAction()
}
}

/**
* @return void
*/
public function authorizationDetailsAction()
{
$this->registrationService->registerShopById((int) $this->request->getParam('shopId'));

$authorizationId = $this->Request()->getParam('id');
$view = $this->View();

/** @var AuthorizationResource $authorizationResource */
$authorizationResource = $this->get('paypal_unified.authorization_resource');

try {
Expand All @@ -168,12 +187,16 @@ public function authorizationDetailsAction()
}
}

/**
* @return void
*/
public function orderDetailsAction()
{
$this->registrationService->registerShopById((int) $this->request->getParam('shopId'));

$orderId = $this->Request()->getParam('id');
$view = $this->View();

/** @var OrderResource $orderResource */
$orderResource = $this->get('paypal_unified.order_resource');

try {
Expand All @@ -189,8 +212,13 @@ public function orderDetailsAction()
}
}

/**
* @return void
*/
public function refundSaleAction()
{
$this->registrationService->registerShopById((int) $this->request->getParam('shopId'));

$saleId = $this->Request()->getParam('id');
$totalAmount = number_format($this->Request()->getParam('amount'), 2);
$invoiceNumber = $this->Request()->getParam('invoiceNumber');
Expand All @@ -209,9 +237,7 @@ public function refundSaleAction()
$refund->setAmount($amountStruct);
}

/** @var SaleResource $saleResource */
$saleResource = $this->get('paypal_unified.sale_resource');
/** @var PaymentStatusService $paymentStatusService */
$paymentStatusService = $this->get('paypal_unified.payment_status_service');

try {
Expand All @@ -236,64 +262,84 @@ public function refundSaleAction()
}
}

/**
* @return void
*/
public function captureOrderAction()
{
$this->registrationService->registerShopById((int) $this->request->getParam('shopId'));

$orderId = $this->Request()->getParam('id');
$amountToCapture = number_format($this->Request()->getParam('amount'), 2);
$currency = $this->Request()->getParam('currency');
$isFinal = (bool) $this->Request()->getParam('isFinal');

/** @var CaptureService $captureService */
$captureService = $this->get('paypal_unified.backend.capture_service');
$viewParameter = $captureService->captureOrder($orderId, $amountToCapture, $currency, $isFinal);

$this->View()->assign($viewParameter);
}

/**
* @return void
*/
public function captureAuthorizationAction()
{
$this->registrationService->registerShopById((int) $this->request->getParam('shopId'));

$authorizationId = $this->Request()->getParam('id');
$amountToCapture = number_format($this->Request()->getParam('amount'), 2);
$currency = $this->Request()->getParam('currency');
$isFinal = (bool) $this->Request()->getParam('isFinal');

/** @var CaptureService $captureService */
$captureService = $this->get('paypal_unified.backend.capture_service');
$viewParameter = $captureService->captureAuthorization($authorizationId, $amountToCapture, $currency, $isFinal);

$this->View()->assign($viewParameter);
}

/**
* @return void
*/
public function refundCaptureAction()
{
$this->registrationService->registerShopById((int) $this->request->getParam('shopId'));

$captureId = $this->Request()->getParam('id');
$totalAmount = number_format($this->Request()->getParam('amount'), 2);
$description = $this->Request()->getParam('note');
$currency = $this->Request()->getParam('currency');

/** @var CaptureService $captureService */
$captureService = $this->get('paypal_unified.backend.capture_service');
$viewParameter = $captureService->refundCapture($captureId, $totalAmount, $currency, $description);

$this->View()->assign($viewParameter);
}

/**
* @return void
*/
public function voidAuthorizationAction()
{
$this->registrationService->registerShopById((int) $this->request->getParam('shopId'));

$authorizationId = $this->Request()->getParam('id');

/** @var VoidService $voidService */
$voidService = $this->get('paypal_unified.backend.void_service');
$viewParameter = $voidService->voidAuthorization($authorizationId);

$this->View()->assign($viewParameter);
}

/**
* @return void
*/
public function voidOrderAction()
{
$this->registrationService->registerShopById((int) $this->request->getParam('shopId'));

$orderId = $this->Request()->getParam('id');

/** @var VoidService $voidService */
$voidService = $this->get('paypal_unified.backend.void_service');
$viewParameter = $voidService->voidOrder($orderId);

Expand Down Expand Up @@ -402,12 +448,7 @@ protected function getModelFields($model, $alias = null)
$fields = parent::getModelFields($model, $alias);

if ($model === $this->model) {
$fields = array_merge(
$fields,
[
'customer.email' => ['alias' => 'customer.email', 'type' => 'string'],
]
);
$fields['customer.email'] = ['alias' => 'customer.email', 'type' => 'string'];
}

return $fields;
Expand Down Expand Up @@ -454,6 +495,8 @@ private function prepareOrderQueryBuilder(QueryBuilder $builder)
/**
* Checks if one of the filter conditions is "search". If not, the filters were set by the filter panel
*
* @param array<array{property: string, operator: string|null, value: mixed, expression?: string}> $filters
*
* @return bool
*/
private function isFilterRequest(array $filters)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// {block name="backend/index/application"}
// {$smarty.block.parent}
// {namespace name="backend/paypal_unified/mixin/onboarding_helper"}
// {namespace name="backend/paypal_unified_settings/mixin/onboarding_helper"}
//
Ext.define('Shopware.apps.PaypalUnified.mixin.OnboardingHelper', {
onboardingHelper: {
Expand Down
2 changes: 1 addition & 1 deletion Subscriber/Backend.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function onLoadBackendIndex(ActionEventArgs $args)
$view->assign($nonceType, $this->nonceService->getBase64UrlEncodedRandomNonce());
}

$view->extendsTemplate('backend/paypal_unified/mixin/onboarding_helper.js');
$view->extendsTemplate('backend/paypal_unified_settings/mixin/onboarding_helper.js');
}
}

Expand Down
13 changes: 9 additions & 4 deletions Tests/Functional/Components/DependencyProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,29 @@
use Shopware\Components\DependencyInjection\Container;
use Shopware\Models\Shop\DetachedShop;
use SwagPaymentPayPalUnified\Components\DependencyProvider;
use SwagPaymentPayPalUnified\Tests\Functional\ContainerTrait;
use SwagPaymentPayPalUnified\Tests\Functional\ShopRegistrationTrait;

class DependencyProviderTest extends TestCase
{
use ContainerTrait;
use ShopRegistrationTrait;

public function testServiceAvailable()
{
static::assertSame(DependencyProvider::class, \get_class(Shopware()->Container()->get('paypal_unified.dependency_provider')));
static::assertSame(DependencyProvider::class, \get_class($this->getContainer()->get('paypal_unified.dependency_provider')));
}

public function testCanBeConstructed()
{
$dp = new DependencyProvider(Shopware()->Container());
$dp = new DependencyProvider($this->getContainer());

static::assertNotNull($dp);
}

public function testGetShopReturnShop()
{
$dp = new DependencyProvider(Shopware()->Container());
$dp = new DependencyProvider($this->getContainer());

static::assertInstanceOf(DetachedShop::class, $dp->getShop());
}
Expand All @@ -44,7 +49,7 @@ public function testGetShopReturnNull()

public function testGetModuleHasModule()
{
$dp = new DependencyProvider(Shopware()->Container());
$dp = new DependencyProvider($this->getContainer());

static::assertNotNull($dp->getModule('basket'));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@
use SwagPaymentPayPalUnified\PayPalBundle\V2\Api\Order\PurchaseUnit\Shipping\Name as ShippingName;
use SwagPaymentPayPalUnified\Tests\Functional\ContainerTrait;
use SwagPaymentPayPalUnified\Tests\Functional\DatabaseTestCaseTrait;
use SwagPaymentPayPalUnified\Tests\Functional\ShopRegistrationTrait;

class CustomerServiceTest extends TestCase
{
use DatabaseTestCaseTrait;
use ContainerTrait;
use ShopRegistrationTrait;

public function testServiceIsAvailable()
{
Expand Down
Loading

0 comments on commit c52c843

Please sign in to comment.