-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from logeecom/PISYL-267/implement-sylius-api
Add support for Sylius API
- Loading branch information
Showing
5 changed files
with
137 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SyliusMolliePlugin\Action\ApiPlatform; | ||
|
||
use Sylius\Bundle\PayumBundle\Model\GatewayConfigInterface; | ||
use Sylius\Component\Core\Model\PaymentInterface; | ||
use Sylius\Component\Core\Model\PaymentMethodInterface; | ||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; | ||
use Sylius\Component\Core\Model\OrderInterface; | ||
|
||
class MolliePayment | ||
{ | ||
private const MOLLIE_PAYMENT_METHOD_NAME = 'mollie'; | ||
|
||
/** @var UrlGeneratorInterface */ | ||
private $urlGenerator; | ||
|
||
/** | ||
* MolliePayment constructor | ||
*/ | ||
public function __construct( | ||
UrlGeneratorInterface $urlGenerator) | ||
{ | ||
$this->urlGenerator = $urlGenerator; | ||
} | ||
|
||
/** | ||
* @param PaymentMethodInterface $paymentMethod | ||
* | ||
* @return bool | ||
*/ | ||
public function supports(PaymentMethodInterface $paymentMethod): bool | ||
{ | ||
/** @var GatewayConfigInterface $gatewayConfig */ | ||
$gatewayConfig = $paymentMethod->getGatewayConfig(); | ||
|
||
return $gatewayConfig->getFactoryName() === self::MOLLIE_PAYMENT_METHOD_NAME; | ||
} | ||
|
||
/** | ||
* @param PaymentInterface $payment | ||
* | ||
* @return array | ||
*/ | ||
public function provideConfiguration(PaymentInterface $payment): array | ||
{ | ||
/** @var OrderInterface $order */ | ||
$order = $payment->getOrder(); | ||
|
||
$details = $payment->getDetails(); | ||
$methodName = $details['molliePaymentMethods'] ?? null; | ||
|
||
if (!$methodName) { | ||
if (isset($details['metadata']['molliePaymentMethods'])) { | ||
$methodName = $details['metadata']['molliePaymentMethods']; | ||
} | ||
} | ||
|
||
$redirectUrl = $this->urlGenerator->generate('sylius_mollie_plugin_payum', [], UrlGeneratorInterface::ABSOLUTE_URL); | ||
$webhookUrl = $this->urlGenerator->generate('sylius_mollie_plugin_payment_webhook', [], UrlGeneratorInterface::ABSOLUTE_URL); | ||
$redirectUrl .= '?orderId=' . $order->getId(); | ||
$webhookUrl .= '?orderId=' . $order->getId(); | ||
|
||
return [ | ||
"method" => $methodName, | ||
"issuer" => isset($details['selected_issuer']) ? $details['selected_issuer'] : null, | ||
"cardToken" => isset($details['metadata']['cartToken']) ? $details['metadata']['cartToken'] : null, | ||
"amount" => isset($details['amount']) ? $details['amount'] : null, | ||
"customerId" => isset($details['customerId']) ? $details['customerId'] : null, | ||
"description" => isset($details['description']) ? $details['description'] : null, | ||
"redirectUrl" => $redirectUrl, | ||
"webhookUrl" => $webhookUrl, | ||
"metadata" => isset($details['metadata']) ? $details['metadata'] : null, | ||
"locale" => isset($details['locale']) ? $details['locale'] : 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
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