Skip to content

Commit

Permalink
Merge branch 'feature/twint' into release-week-01
Browse files Browse the repository at this point in the history
  • Loading branch information
michielgerritsen committed Jan 10, 2024
2 parents 11839fc + 78bbfd9 commit 90c1304
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
34 changes: 23 additions & 11 deletions GraphQL/Resolver/General/MolliePaymentMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Magento\Quote\Api\Data\CartInterfaceFactory;
use Mollie\Api\Resources\Method;
use Mollie\Api\Resources\MethodCollection;
use Mollie\Payment\Config;
use Mollie\Payment\Service\Mollie\MethodParameters;
use Mollie\Payment\Service\Mollie\MollieApiClient;
Expand Down Expand Up @@ -52,7 +53,7 @@ public function __construct(
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
{
$amount = 10;
$currency = 'EUR';
$currency = null;

if (isset($args['input'], $args['input']['amount'])) {
$amount = $args['input']['amount'];
Expand All @@ -62,17 +63,8 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
$currency = $args['input']['currency'];
}

$parameters = [
'amount[value]' => number_format($amount, 2, '.', ''),
'amount[currency]' => $currency,
'resource' => 'orders',
'includeWallets' => 'applepay',
];

$parameters = $this->methodParameters->enhance($parameters, $this->cartFactory->create());
$storeId = $context->getExtensionAttributes()->getStore()->getId();
$mollieApiClient = $this->mollieApiClient->loadByStore($storeId);
$apiMethods = $mollieApiClient->methods->allActive($parameters);
$apiMethods = $this->getMethods($amount, $currency, $storeId);

$methods = [];
/** @var Method $method */
Expand All @@ -97,4 +89,24 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
'methods' => $methods,
];
}

public function getMethods(float $amount, ?string $currency, int $storeId): MethodCollection
{
$mollieApiClient = $this->mollieApiClient->loadByStore($storeId);

if ($currency === null) {
return $mollieApiClient->methods->allAvailable();
}

$parameters = [
'amount[value]' => number_format($amount, 2, '.', ''),
'amount[currency]' => $currency,
'resource' => 'orders',
'includeWallets' => 'applepay',
];

return $mollieApiClient->methods->allActive(
$this->methodParameters->enhance($parameters, $this->cartFactory->create())
);
}
}
10 changes: 2 additions & 8 deletions Helper/Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@ public function getMethods($testKey = null, $liveKey = null)
try {
$availableMethods = [];
$mollieApi = $this->mollieModel->loadMollieApi($testKey);
$methods = $mollieApi->methods->all([
'resource' => 'orders',
'includeWallets' => 'applepay',
]);
$methods = $mollieApi->methods->allAvailable();

foreach ($methods as $apiMethod) {
$availableMethods[] = ucfirst($apiMethod->id);
Expand Down Expand Up @@ -90,10 +87,7 @@ public function getMethods($testKey = null, $liveKey = null)
try {
$availableMethods = [];
$mollieApi = $this->mollieModel->loadMollieApi($liveKey);
$methods = $mollieApi->methods->all([
'resource' => 'orders',
'includeWallets' => 'applepay',
]);
$methods = $mollieApi->methods->allAvailable();

foreach ($methods as $apiMethod) {
$availableMethods[] = ucfirst($apiMethod->id);
Expand Down
2 changes: 1 addition & 1 deletion etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ input MollieTransactionInput {

input MolliePaymentMethodsInput {
amount: Float! = 10
currency: String! = EUR
currency: String = EUR
}

input MollieResetCartInput {
Expand Down

0 comments on commit 90c1304

Please sign in to comment.