-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "PISHPS-265: remove ideal issuer dropdown (#743)"
This reverts commit 09ab3b4.
- Loading branch information
Vitalij Mik
committed
May 21, 2024
1 parent
8c86aaa
commit 253b494
Showing
30 changed files
with
862 additions
and
5 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
src/Controller/StoreApi/iDEAL/Response/IssuersResponse.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace Kiener\MolliePayments\Controller\StoreApi\iDEAL\Response; | ||
|
||
use Shopware\Core\Framework\Struct\ArrayStruct; | ||
use Shopware\Core\System\SalesChannel\StoreApiResponse; | ||
|
||
class IssuersResponse extends StoreApiResponse | ||
{ | ||
/** | ||
* @var ArrayStruct<mixed, mixed> | ||
*/ | ||
protected $object; | ||
|
||
|
||
/** | ||
* @param array<mixed> $terminals | ||
*/ | ||
public function __construct(array $terminals) | ||
{ | ||
$this->object = new ArrayStruct( | ||
[ | ||
'issuers' => $terminals, | ||
], | ||
'mollie_payments_ideal_issuers' | ||
); | ||
|
||
parent::__construct($this->object); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/Controller/StoreApi/iDEAL/Response/StoreIssuerResponse.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace Kiener\MolliePayments\Controller\StoreApi\iDEAL\Response; | ||
|
||
use Shopware\Core\Framework\Struct\ArrayStruct; | ||
use Shopware\Core\System\SalesChannel\StoreApiResponse; | ||
|
||
class StoreIssuerResponse extends StoreApiResponse | ||
{ | ||
/** | ||
* @var ArrayStruct<mixed, mixed> | ||
*/ | ||
protected $object; | ||
|
||
/** | ||
* @param bool $success | ||
*/ | ||
public function __construct(bool $success) | ||
{ | ||
$this->object = new ArrayStruct( | ||
[ | ||
'success' => $success, | ||
], | ||
'mollie_payments_ideal_issuer_stored' | ||
); | ||
|
||
parent::__construct($this->object); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<?php | ||
|
||
namespace Kiener\MolliePayments\Controller\StoreApi\iDEAL; | ||
|
||
use Kiener\MolliePayments\Controller\StoreApi\iDEAL\Response\IssuersResponse; | ||
use Kiener\MolliePayments\Controller\StoreApi\iDEAL\Response\StoreIssuerResponse; | ||
use Kiener\MolliePayments\Gateway\MollieGatewayInterface; | ||
use Kiener\MolliePayments\Handler\Method\iDealPayment; | ||
use Kiener\MolliePayments\Service\CustomerService; | ||
use Shopware\Core\Checkout\Customer\CustomerEntity; | ||
use Shopware\Core\Framework\Routing\Annotation\RouteScope; | ||
use Shopware\Core\System\SalesChannel\SalesChannelContext; | ||
use Shopware\Core\System\SalesChannel\StoreApiResponse; | ||
use Shopware\Storefront\Controller\StorefrontController; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
|
||
class iDealControllerBase | ||
{ | ||
/** | ||
* @var CustomerService | ||
*/ | ||
private $customerService; | ||
|
||
/** | ||
* @var MollieGatewayInterface | ||
*/ | ||
private $mollieGateway; | ||
|
||
|
||
/** | ||
* @param CustomerService $customerService | ||
* @param MollieGatewayInterface $mollieGateway | ||
*/ | ||
public function __construct(CustomerService $customerService, MollieGatewayInterface $mollieGateway) | ||
{ | ||
$this->customerService = $customerService; | ||
$this->mollieGateway = $mollieGateway; | ||
} | ||
|
||
|
||
/** | ||
* | ||
* @param SalesChannelContext $context | ||
* @return StoreApiResponse | ||
*/ | ||
public function getIssuers(SalesChannelContext $context): StoreApiResponse | ||
{ | ||
$this->mollieGateway->switchClient($context->getSalesChannelId()); | ||
|
||
$issuers = $this->mollieGateway->getIDealIssuers(); | ||
|
||
$issuerArray = []; | ||
|
||
foreach ($issuers as $issuer) { | ||
$issuerArray[] = [ | ||
'id' => $issuer->getId(), | ||
'name' => $issuer->getName(), | ||
'images' => [ | ||
'1x' => $issuer->getImage1x(), | ||
'2x' => $issuer->getImage2x(), | ||
'svg' => $issuer->getSvg(), | ||
], | ||
]; | ||
} | ||
|
||
return new IssuersResponse($issuerArray); | ||
} | ||
|
||
/** | ||
* | ||
* @param string $customerId | ||
* @param string $issuerId | ||
* @param SalesChannelContext $context | ||
* @throws \Exception | ||
* @return StoreApiResponse | ||
*/ | ||
public function saveIssuer(string $customerId, string $issuerId, SalesChannelContext $context): StoreApiResponse | ||
{ | ||
$customer = $this->customerService->getCustomer($customerId, $context->getContext()); | ||
|
||
if (!$customer instanceof CustomerEntity) { | ||
throw new \Exception('Customer with ID ' . $customerId . ' not found in Shopware'); | ||
} | ||
|
||
# if we have a "reset" value, then empty our stored issuer | ||
if ($issuerId === iDealPayment::ISSUER_RESET_VALUE) { | ||
$issuerId = ''; | ||
} | ||
|
||
$result = $this->customerService->setIDealIssuer( | ||
$customer, | ||
$issuerId, | ||
$context->getContext() | ||
); | ||
|
||
return new StoreIssuerResponse($result !== null); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
namespace Kiener\MolliePayments\Controller\Storefront\iDEAL; | ||
|
||
use Kiener\MolliePayments\Controller\Storefront\AbstractStoreFrontController; | ||
use Kiener\MolliePayments\Handler\Method\iDealPayment; | ||
use Kiener\MolliePayments\Service\CustomerService; | ||
use Shopware\Core\Checkout\Customer\CustomerEntity; | ||
use Shopware\Core\System\SalesChannel\SalesChannelContext; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
|
||
class iDealControllerBase extends AbstractStoreFrontController | ||
{ | ||
/** | ||
* @var CustomerService | ||
*/ | ||
private $customerService; | ||
|
||
|
||
/** | ||
* @param CustomerService $customerService | ||
*/ | ||
public function __construct(CustomerService $customerService) | ||
{ | ||
$this->customerService = $customerService; | ||
} | ||
|
||
/** | ||
* | ||
* @param SalesChannelContext $context | ||
* @param string $customerId | ||
* @param string $issuerId | ||
* | ||
* @return JsonResponse | ||
*/ | ||
public function storeIssuer(SalesChannelContext $context, string $customerId, string $issuerId): JsonResponse | ||
{ | ||
$result = null; | ||
|
||
# if we have a "reset" value, then empty our stored issuer | ||
if ($issuerId === iDealPayment::ISSUER_RESET_VALUE) { | ||
$issuerId = ''; | ||
} | ||
|
||
$customer = $this->customerService->getCustomer($customerId, $context->getContext()); | ||
|
||
if ($customer instanceof CustomerEntity) { | ||
$writtenEvent = $this->customerService->setIDealIssuer( | ||
$customer, | ||
$issuerId, | ||
$context->getContext() | ||
); | ||
|
||
$result = $writtenEvent->getErrors(); | ||
} | ||
|
||
return new JsonResponse([ | ||
'success' => (bool)$result, | ||
'customerId' => $customerId, | ||
'result' => $result, | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
|
||
namespace Kiener\MolliePayments\Gateway\Mollie\Model; | ||
|
||
class Issuer | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $id; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $name; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $image1x; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $image2x; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $svg; | ||
|
||
|
||
/** | ||
* @param string $id | ||
* @param string $name | ||
* @param string $image1x | ||
* @param string $image2x | ||
* @param string $svg | ||
*/ | ||
public function __construct(string $id, string $name, string $image1x, string $image2x, string $svg) | ||
{ | ||
$this->id = $id; | ||
$this->name = $name; | ||
$this->image1x = $image1x; | ||
$this->image2x = $image2x; | ||
$this->svg = $svg; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getId(): string | ||
{ | ||
return $this->id; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getName(): string | ||
{ | ||
return $this->name; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getImage1x(): string | ||
{ | ||
return $this->image1x; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getImage2x(): string | ||
{ | ||
return $this->image2x; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getSvg(): string | ||
{ | ||
return $this->svg; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.