-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make it possible to initialize an Apple Pay payment session via API (#…
…102)
- Loading branch information
Showing
32 changed files
with
615 additions
and
87 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,18 @@ | ||
<?xml version="1.0" ?> | ||
|
||
<serializer xmlns="http://symfony.com/schema/dic/serializer-mapping" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/serializer-mapping https://symfony.com/schema/dic/serializer-mapping/serializer-mapping-1.0.xsd" | ||
> | ||
<class name="CommerceWeavers\SyliusTpayPlugin\Api\Command\InitializeApplePaySession"> | ||
<attribute name="domainName"> | ||
<group>commerce_weavers_sylius_tpay:shop:order:payment:initialize_apple_pay_session</group> | ||
</attribute> | ||
<attribute name="displayName"> | ||
<group>commerce_weavers_sylius_tpay:shop:order:payment:initialize_apple_pay_session</group> | ||
</attribute> | ||
<attribute name="validationUrl"> | ||
<group>commerce_weavers_sylius_tpay:shop:order:payment:initialize_apple_pay_session</group> | ||
</attribute> | ||
</class> | ||
</serializer> |
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,15 @@ | ||
<?xml version="1.0" ?> | ||
|
||
<serializer xmlns="http://symfony.com/schema/dic/serializer-mapping" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/serializer-mapping https://symfony.com/schema/dic/serializer-mapping/serializer-mapping-1.0.xsd" | ||
> | ||
<class name="CommerceWeavers\SyliusTpayPlugin\Api\Command\InitializeApplePaySessionResult"> | ||
<attribute name="result"> | ||
<group>commerce_weavers_sylius_tpay:shop:order:payment:initialize_apple_pay_session_result</group> | ||
</attribute> | ||
<attribute name="session"> | ||
<group>commerce_weavers_sylius_tpay:shop:order:payment:initialize_apple_pay_session_result</group> | ||
</attribute> | ||
</class> | ||
</serializer> |
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
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,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace CommerceWeavers\SyliusTpayPlugin\Api\Command\Contract; | ||
|
||
interface PaymentIdAwareInterface | ||
{ | ||
public static function getPaymentIdPropertyName(): string; | ||
} |
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,9 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace CommerceWeavers\SyliusTpayPlugin\Api\Command\Exception; | ||
|
||
class OrderCannotBeFoundException extends \RuntimeException | ||
{ | ||
} |
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,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace CommerceWeavers\SyliusTpayPlugin\Api\Command; | ||
|
||
use CommerceWeavers\SyliusTpayPlugin\Api\Command\Contract\OrderTokenAwareInterface; | ||
|
||
final class InitializeApplePaySession implements OrderTokenAwareInterface | ||
{ | ||
public function __construct( | ||
public readonly string $orderToken, | ||
public readonly string $domainName, | ||
public readonly string $displayName, | ||
public readonly string $validationUrl, | ||
) { | ||
} | ||
|
||
public static function getOrderTokenPropertyName(): string | ||
{ | ||
return 'orderToken'; | ||
} | ||
} |
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,57 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace CommerceWeavers\SyliusTpayPlugin\Api\Command; | ||
|
||
use CommerceWeavers\SyliusTpayPlugin\Api\Command\Exception\OrderCannotBeFoundException; | ||
use CommerceWeavers\SyliusTpayPlugin\Payum\Factory\InitializeApplePayPaymentFactoryInterface; | ||
use Payum\Core\Bridge\Spl\ArrayObject; | ||
use Payum\Core\GatewayInterface; | ||
use Sylius\Component\Core\Repository\OrderRepositoryInterface; | ||
use Symfony\Component\Messenger\Attribute\AsMessageHandler; | ||
use Webmozart\Assert\Assert; | ||
|
||
#[AsMessageHandler] | ||
final class InitializeApplePaySessionHandler | ||
{ | ||
public function __construct( | ||
private readonly OrderRepositoryInterface $orderRepository, | ||
private readonly GatewayInterface $gateway, | ||
private readonly InitializeApplePayPaymentFactoryInterface $initializeApplePayPaymentFactory, | ||
) { | ||
} | ||
|
||
public function __invoke(InitializeApplePaySession $command): InitializeApplePaySessionResult | ||
{ | ||
$this->verifyOrderExist($command->orderToken); | ||
|
||
$this->gateway->execute( | ||
$this->initializeApplePayPaymentFactory->createNewWithModelAndOutput( | ||
new ArrayObject([ | ||
'domainName' => $command->domainName, | ||
'displayName' => $command->displayName, | ||
'validationUrl' => $command->validationUrl, | ||
]), | ||
$output = new ArrayObject(), | ||
), | ||
); | ||
|
||
Assert::string($output['result']); | ||
Assert::string($output['session']); | ||
|
||
return new InitializeApplePaySessionResult( | ||
$output['result'], | ||
$output['session'], | ||
); | ||
} | ||
|
||
private function verifyOrderExist(string $orderToken): void | ||
{ | ||
$order = $this->orderRepository->findOneByTokenValue($orderToken); | ||
|
||
if (null === $order) { | ||
throw new OrderCannotBeFoundException(sprintf('Order with token "%s" cannot be found.', $orderToken)); | ||
} | ||
} | ||
} |
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,14 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace CommerceWeavers\SyliusTpayPlugin\Api\Command; | ||
|
||
final class InitializeApplePaySessionResult | ||
{ | ||
public function __construct( | ||
public readonly string $result, | ||
public readonly string $session, | ||
) { | ||
} | ||
} |
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.