-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Add attribute to retrieve available POS terminals
- Loading branch information
1 parent
ac30d84
commit 55b4289
Showing
7 changed files
with
150 additions
and
52 deletions.
There are no files selected for viewing
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
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,51 @@ | ||
<?php | ||
/* | ||
* Copyright Magmodules.eu. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Mollie\Payment\GraphQL\Resolver\Cart; | ||
|
||
use Magento\Framework\GraphQl\Config\Element\Field; | ||
use Magento\Framework\GraphQl\Query\ResolverInterface; | ||
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; | ||
use Mollie\Payment\Service\Mollie\AvailableTerminals; | ||
use Mollie\Payment\Service\Mollie\PointOfSaleAvailability; | ||
|
||
class AvailableTerminalsForMethod implements ResolverInterface | ||
{ | ||
/** | ||
* @var PointOfSaleAvailability | ||
*/ | ||
private $pointOfSaleAvailability; | ||
/** | ||
* @var AvailableTerminals | ||
*/ | ||
private $availableTerminals; | ||
|
||
public function __construct( | ||
PointOfSaleAvailability $pointOfSaleAvailability, | ||
AvailableTerminals $availableTerminals | ||
) { | ||
$this->pointOfSaleAvailability = $pointOfSaleAvailability; | ||
$this->availableTerminals = $availableTerminals; | ||
} | ||
|
||
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) | ||
{ | ||
$method = $value['code']; | ||
if ($method != 'mollie_methods_pointofsale' || !$context->getExtensionAttributes()->getIsCustomer()) { | ||
return []; | ||
} | ||
|
||
$storeId = (int)$context->getExtensionAttributes()->getStore()->getId(); | ||
$customerGroupId = $context->getExtensionAttributes()->getCustomerGroupId(); | ||
if (!$this->pointOfSaleAvailability->isAvailableForCustomerGroupId($customerGroupId, $storeId)) { | ||
return []; | ||
} | ||
|
||
return $this->availableTerminals->execute((int)$storeId); | ||
} | ||
} |
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 | ||
/* | ||
* Copyright Magmodules.eu. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Mollie\Payment\Service\Mollie; | ||
|
||
use Mollie\Api\Exceptions\ApiException; | ||
use Mollie\Api\Resources\Terminal; | ||
|
||
class AvailableTerminals | ||
{ | ||
/** | ||
* @var MollieApiClient | ||
*/ | ||
private $mollieApiClient; | ||
|
||
public function __construct( | ||
MollieApiClient $mollieApiClient | ||
) { | ||
$this->mollieApiClient = $mollieApiClient; | ||
} | ||
|
||
/** | ||
* @return array{ | ||
* id: string, | ||
* brand: string, | ||
* model: string, | ||
* serialNumber: string|null, | ||
* description: string | ||
* } | ||
*/ | ||
public function execute(int $storeId = null): array | ||
{ | ||
try { | ||
$mollieApiClient = $this->mollieApiClient->loadByStore($storeId); | ||
$terminals = $mollieApiClient->terminals->page(); | ||
} catch (ApiException $exception) { | ||
return []; | ||
} | ||
|
||
$output = []; | ||
/** @var Terminal $terminal */ | ||
foreach ($terminals as $terminal) { | ||
if (!$terminal->isActive()) { | ||
continue; | ||
} | ||
|
||
$output[] = [ | ||
'id' => $terminal->id, | ||
'brand' => $terminal->brand, | ||
'model' => $terminal->model, | ||
'serialNumber' => $terminal->serialNumber, | ||
'description' => $terminal->description, | ||
]; | ||
} | ||
|
||
return $output; | ||
} | ||
} |
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
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