Skip to content

Commit

Permalink
ASW-0 Merge branch 'release-3.7.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
davemeteor committed May 4, 2022
2 parents 776913d + 88b1364 commit b5bb983
Show file tree
Hide file tree
Showing 9 changed files with 205 additions and 48 deletions.
1 change: 0 additions & 1 deletion Components/Adyen/PaymentMethodService.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use AdyenPayment\Session\CustomerNumberProviderInterface;
use Psr\Log\LoggerInterface;


/** @TODO - Cleanup the public const (unify the services) and create unit tests */
final class PaymentMethodService implements PaymentMethodServiceInterface
{
Expand Down
11 changes: 5 additions & 6 deletions Controllers/Frontend/AdyenConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@
use AdyenPayment\Serializer\PaymentMeanCollectionSerializer;
use AdyenPayment\Shopware\Serializer\SwPaymentMeanCollectionSerializer;

class Shopware_Controllers_Frontend_AdyenConfig extends Enlight_Controller_Action
class Shopware_Controllers_Frontend_AdyenConfig extends Shopware_Controllers_Frontend_Checkout
{
private DataConversion $dataConversion;
private Configuration $configuration;
private EnrichedPaymentMeanProviderInterface $enrichedPaymentMeanProvider;
private PaymentMeanCollectionSerializer $paymentMeanCollectionSerializer;
private Shopware_Components_Modules $modules;
private Enlight_Components_Session_Namespace $session;

public function preDispatch(): void
{
Expand All @@ -27,7 +26,6 @@ public function preDispatch(): void
$this->enrichedPaymentMeanProvider = $this->get(EnrichedPaymentMeanProvider::class);
$this->paymentMeanCollectionSerializer = $this->get(SwPaymentMeanCollectionSerializer::class);
$this->modules = $this->get('modules');
$this->session = Shopware()->Session();
}

public function indexAction(): void
Expand All @@ -42,18 +40,19 @@ public function indexAction(): void
PaymentMeanCollection::createFromShopwareArray($admin->sGetPaymentMeans())
);

$sBasket = $this->session->sOrderVariables['sBasket'];
$sBasket = $this->getBasket();

$shop = Shopware()->Shop();
$orderCurrency = $shop->getCurrency();

$adyenConfig = [
'status' => 'success',
'shopLocale' => $this->dataConversion->getISO3166FromLocale($shop->getLocale()->getLocale()),
'clientKey' => $this->configuration->getClientKey($shop),
'environment' => $this->configuration->getEnvironment($shop),
'enrichedPaymentMethods' => ($this->paymentMeanCollectionSerializer)($enrichedPaymentMethods),
'adyenOrderTotal' => $sBasket['sAmount'],
'adyenOrderCurrency' => $sBasket['sCurrencyName']
'adyenOrderTotal' => round($sBasket['sAmount'], 2),
'adyenOrderCurrency' => $sBasket['sCurrencyName'] ?? $orderCurrency
];

$this->Response()->setBody(
Expand Down
48 changes: 28 additions & 20 deletions Resources/frontend/js/jquery.adyen-payment-selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,26 +198,7 @@
setConfig: function () {
var me = this;

$.ajax({
method: 'GET',
async: false,
dataType: 'json',
url: me.opts.adyenConfigAjaxUrl,
success: function (response) {
if (response['status'] === 'success') {
me.opts.shopLocale = response['shopLocale'];
me.opts.adyenClientKey = response['clientKey'];
me.opts.adyenEnvironment = response['environment'];
me.opts.enrichedPaymentMethods = response['enrichedPaymentMethods'];
me.opts.adyenOrderTotal = response['adyenOrderTotal'];
me.opts.adyenOrderCurrency = response['adyenOrderCurrency'];
} else {
me.addAdyenError(response['content']);
}

$.loadingIndicator.close();
}
});
me.fetchAdyenConfig();

var adyenPaymentMethodsResponse = me.opts.enrichedPaymentMethods.reduce(
function (rawAdyen, enrichedPaymentMethod) {
Expand All @@ -240,6 +221,30 @@
};
me.saveAdyenConfigInSession(me.adyenConfiguration);
},
fetchAdyenConfig: function () {
var me = this;

return $.ajax({
method: 'GET',
async: false,
dataType: 'json',
url: me.opts.adyenConfigAjaxUrl,
success: function (response) {
if (response['status'] === 'success') {
me.opts.shopLocale = response['shopLocale'];
me.opts.adyenClientKey = response['clientKey'];
me.opts.adyenEnvironment = response['environment'];
me.opts.enrichedPaymentMethods = response['enrichedPaymentMethods'];
me.opts.adyenOrderTotal = response['adyenOrderTotal'];
me.opts.adyenOrderCurrency = response['adyenOrderCurrency'];
} else {
me.addAdyenError(response['content']);
}

$.loadingIndicator.close();
}
});
},
getCurrentComponentId: function (selectedPaymentElementId) {
return 'component-' + selectedPaymentElementId;
},
Expand Down Expand Up @@ -278,10 +283,13 @@
var adyenCheckoutData = me.__buildCheckoutComponentData(paymentMethod);

if (this.__isApplePayPaymentMethod(paymentMethod)) {
me.setConfig();
me.setPaymentSession(me.__buildMinimalState(paymentMethod));
adyenCheckoutData = me.__buildCheckoutComponentData(paymentMethod);
}

if ('paywithgoogle' === paymentMethod.adyenType) {
me.setConfig();
me.setPaymentSession(me.__buildMinimalState(paymentMethod));
me.handleComponentPayWithGoogle();
return;
Expand Down
7 changes: 3 additions & 4 deletions Shopware/Serializer/SwPaymentMeanSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@

use AdyenPayment\Models\Payment\PaymentMean;
use AdyenPayment\Serializer\PaymentMeanSerializer;
use AdyenPayment\Utils\Sanitize;

final class SwPaymentMeanSerializer implements PaymentMeanSerializer
{
public function __invoke(PaymentMean $paymentMean): array
{
return [
$paymentMean->getId() => array_replace($paymentMean->getRaw(), [
'name' => Sanitize::escape($paymentMean->getValue('name')),
'description' => Sanitize::escape($paymentMean->getValue('description')),
'additionaldescription' => Sanitize::escapeWithQuotes($paymentMean->getValue('additionaldescription')),
'name' => $paymentMean->getValue('name'),
'description' => $paymentMean->getValue('description'),
'additionaldescription' => $paymentMean->getValue('additionaldescription'),
]),
];
}
Expand Down
5 changes: 0 additions & 5 deletions Utils/Sanitize.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,4 @@ public static function escape(string $raw): string
{
return htmlspecialchars($raw, ENT_NOQUOTES);
}

public static function escapeWithQuotes(string $raw): string
{
return htmlspecialchars($raw, ENT_QUOTES);
}
}
12 changes: 11 additions & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<label>Adyen Shopware Plugin</label>
<label lang="de">Adyen Shopware Plugin</label>
<version>3.5.0</version>
<version>3.7.0</version>
<copyright>Adyen</copyright>
<author>Adyen</author>
<link>https://adyen.com</link>
Expand Down Expand Up @@ -317,4 +317,14 @@
* functionality to remove stored payment methods / tokens
</changes>
</changelog>
<changelog version="3.7.0">
<changes lang="en">
* Apple Pay amount mismatch issue is solved (issue occured on change shipping/payment where basket was being miscalculated).
* Removed html sanitizing on checkout (using json response instead of html data attribute), so design can be tweaked on payment method.
</changes>
<changes lang="de">
* Das Problem mit der Nichtübereinstimmung des Apple Pay-Betrags wurde behoben (das Problem trat bei der Änderung des Versands/der Zahlung auf, bei der der Warenkorb falsch berechnet wurde).
* HTML-Bereinigung beim Checkout entfernt (unter Verwendung von JSON-Antwort anstelle des HTML-Datenattributs), sodass das Design an der Zahlungsmethode angepasst werden kann.
</changes>
</changelog>
</plugin>
155 changes: 155 additions & 0 deletions tests/Unit/Shopware/Controllers/Frontend/CheckoutTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
<?php

declare(strict_types=1);

namespace AdyenPayment\Tests\Unit\Shopware\Controllers\Frontend;

use Doctrine\DBAL\ForwardCompatibility\DriverStatement;
use Enlight_Template_Manager;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;
use Shopware\Components\Cart\BasketHelper;
use Shopware\Components\Cart\BasketHelperInterface;
use Shopware\Components\Cart\BasketQueryHelperInterface;
use Shopware\Components\Cart\ProportionalTaxCalculatorInterface;
use Shopware\Components\Cart\Struct\DiscountContext;
use Shopware\Components\Cart\Struct\Price;
use Shopware\Components\CSRFGetProtectionAware;
use Shopware\Models\Shop\Currency;
use Shopware\Models\Shop\Shop;
use Symfony\Component\DependencyInjection\Container;

class CheckoutTest extends TestCase
{
use ProphecyTrait;

// private MockObject $checkoutController;
// private Container $container;
/** @var ObjectProphecy|\sAdmin */
private $admin;
/** @var ObjectProphecy|\sBasket */
private $basket;
/** @var \Enlight_Components_Session_Namespace|ObjectProphecy */
private $session;
/** @var ObjectProphecy|Container */
private $container;
/** @var Enlight_Template_Manager|ObjectProphecy */
private $engine;
/** @var \Enlight_View_Default */
private $view;
private $checkoutController;


protected function setUp(): void
{
$this->admin = $this->prophesize(\sAdmin::class);
$this->basket = $this->prophesize(\sBasket::class);
$this->session = $this->prophesize(\Enlight_Components_Session_Namespace::class);
$this->container = $this->prophesize(Container::class);
$this->engine = $this->prophesize(Enlight_Template_Manager::class);
$this->view = new \Enlight_View_Default($this->engine->reveal());
$this->checkoutController = new MockCheckout();
}

/** @test */
public function it_is_csrf_get_protection_aware(): void
{
$this->assertInstanceOf(CSRFGetProtectionAware::class, $this->checkoutController);
}

/** @test */
public function it_returns_complete_basket_data_to_view(): void
{
$this->markTestIncomplete();
// $this->view->setScope(['test']);
// $this->view->assign('sUserData', ['additional' => ['countryShipping' => null]]);

$this->checkoutController->setAdyenMockProperties(
$this->admin->reveal(),
$this->basket->reveal(),
$this->session->reveal(),
$this->container->reveal(),
// $this->view
);

$countryList = [ $country = [
"id" => 2,
"name" => "Deutschland",
"iso" => "DE",
"en" => "GERMANY",
"description" => "",
"position" => 1,
"active" => true,
"iso3" => "DEU",
"taxFree" => false,
"taxFreeForVatId" => false,
"vatIdCheck" => false,
"displayStateSelection" => false,
"requiresStateSelection" => false,
"allowShipping" => true,
"states" => [],
"areaId" => 1,
"attributes" => [],
"countryname" => "Deutschland",
"countryiso" => "DE",
"countryen" => "GERMANY",
"taxfree" => false,
"taxfree_ustid" => false,
"taxfree_ustid_checked" => false,
"display_state_in_registration" => false,
"force_state_in_registration" => false,
"areaID" => 1,
"allow_shipping" => true,
"flag" => false
]];

$this->admin->sGetCountryList()->willReturn($countryList);
// $this->admin->sGetCountryList()->shouldBeCalledOnce();

$shop = new Shop();
$currency = new Currency();
$currency->setCurrency('EUR');
$currency->setFactor(2);
$shop->setCurrency($currency);
$shop = $this->container->get('shop')->willReturn($shop);

$positions = [
new Price(
(float) $price = ($endPrice = 121.00) * ($quantity = 2),
(float) $netPrice = ($netPrice = 100.00 * $quantity),
(float) $taxRate = 21.0,
null
)
];
$basketHelper = $this->prophesize(BasketHelperInterface::class);
$basketHelper->getPositionPrices(Argument::cetera())->willReturn($positions);
$positions = $this->container->get(BasketHelperInterface::class)->willReturn($basketHelper);

$proportionalTaxCalculator = $this->prophesize(ProportionalTaxCalculatorInterface::class);
$taxCalculator = $this->container->get('shopware.cart.proportional_tax_calculator')
->willReturn($proportionalTaxCalculator);
$proportionalTaxCalculator->hasDifferentTaxes(Argument::cetera())
->willReturn(true);

$configComponent = $this->prophesize(\Shopware_Components_Config::class);
$config = $this->container->get(\Shopware_Components_Config::class)
->willReturn($configComponent);

$basketResult = $this->checkoutController->getBasket();
}
}

class MockCheckout extends \Shopware_Controllers_Frontend_Checkout
{

public function setAdyenMockProperties($admin, $basket, $session, $container, $view): void
{
$this->admin = $admin;
$this->basket = $basket;
$this->session = $session;
$this->container = $container;
$this->view = $view;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ public function it_can_serialize_html(): void
$id => [
'id' => $id,
'source' => $source,
'name' => '&lt;some-tag&gt; a name&lt;/some-tag&gt; "quoted"',
'description' => "description and&lt;a href='test'&gt;a link&lt;/a&gt;",
'additionaldescription' => 'additional &lt;div&gt;a div&lt;/div&gt; and &lt;a href=&#039;test&#039;&gt;link&lt;/a&gt;',
'name' => '<some-tag> a name</some-tag> "quoted"',
'description' => "description and<a href='test'>a link</a>",
'additionaldescription' => "additional <div>a div</div> and <a href='test'>link</a>",
],
], $result);
}
Expand Down
8 changes: 0 additions & 8 deletions tests/Unit/Utils/SanitizeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,4 @@ public function it_can_escape_without_quotes(): void

$this->assertEquals("&lt;a href='test'&gt;Test&lt;/a&gt;", $result);
}

/** @test */
public function it_can_escape_with_quotes(): void
{
$result = Sanitize::escapeWithQuotes("<a href='test'>Test</a>");

$this->assertEquals('&lt;a href=&#039;test&#039;&gt;Test&lt;/a&gt;', $result);
}
}

0 comments on commit b5bb983

Please sign in to comment.