Skip to content

Commit

Permalink
Add support for saved cards (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
lchrusciel authored Oct 31, 2024
2 parents 76e8d3d + 588d39e commit 7124ebf
Show file tree
Hide file tree
Showing 78 changed files with 2,122 additions and 79 deletions.
25 changes: 25 additions & 0 deletions config/api_resources/credit_card.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'%commerce_weavers_sylius_tpay.model.credit_card.class%':
collectionOperations:
shop_get:
method: 'GET'
path: /shop/credit-cards
normalization_context:
groups:
- 'commerce_weavers_sylius_tpay:shop:credit_card:index'
itemOperations:
shop_get:
method: 'GET'
path: /shop/credit-cards/{id}
normalization_context:
groups:
- 'commerce_weavers_sylius_tpay:shop:credit_card:show'
shop_delete:
method: 'DELETE'
path: /shop/credit-cards/{id}
properties:
id:
identifier: true
tail:
writable: false
brand:
writable: false
1 change: 1 addition & 0 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

return static function(ContainerConfigurator $container): void {
$container->import('config/**/*.php');
$container->import('grid/*.yaml');

$parameters = $container->parameters();
$parameters
Expand Down
7 changes: 7 additions & 0 deletions config/config/sylius_template_events.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@
],
],
],
'cw.tpay.shop.account.credit_card.index.subcontent' => [
'blocks' => [
'commerce_weavers_sylius_tpay_scripts' => [
'template' => '@CommerceWeaversSyliusTpayPlugin/shop/account/credit_card/index/_subcontent.html.twig',
],
],
],
'sylius.shop.layout.javascripts' => [
'blocks' => [
'commerce_weavers_sylius_tpay_scripts' => [
Expand Down
25 changes: 25 additions & 0 deletions config/doctrine/CreditCard.orm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>

<doctrine-mapping
xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"
>
<mapped-superclass name="CommerceWeavers\SyliusTpayPlugin\Entity\CreditCard" table="cw_sylius_tpay_credt_card">
<id name="id" column="id" />

<field name="token" column="token" />
<field name="brand" column="brand" />
<field name="tail" column="tail" />

<field name="expirationDate" column="expiration_date" type="datetime" nullable="true" />

<many-to-one field="customer" target-entity="Sylius\Component\Core\Model\CustomerInterface">
<join-column name="customer_id" nullable="false" on-delete="CASCADE" />
</many-to-one>

<many-to-one field="channel" target-entity="Sylius\Component\Core\Model\ChannelInterface">
<join-column name="channel_id" nullable="false" on-delete="CASCADE" />
</many-to-one>
</mapped-superclass>
</doctrine-mapping>
39 changes: 39 additions & 0 deletions config/grid/credit_card.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
sylius_grid:
grids:
commerce_weavers_sylius_tpay_shop_account_credit_card:
driver:
name: doctrine/orm
options:
class: "%commerce_weavers_sylius_tpay.model.credit_card.class%"
repository:
method: createByCustomerListQueryBuilder
arguments:
- "expr:service('sylius.context.customer').getCustomer()"
- "expr:service('sylius.context.channel').getChannel()"
sorting:
expirationDate: desc
fields:
brand:
type: string
label: commerce_weavers_sylius_tpay.shop.credit_card.brand
sortable: ~
tail:
type: string
label: commerce_weavers_sylius_tpay.shop.credit_card.tail
sortable: ~
expirationDate:
type: datetime
label: commerce_weavers_sylius_tpay.shop.credit_card.expiration_date
sortable: ~
options:
format: m-Y
actions:
item:
delete:
type: delete
label: sylius.ui.delete
options:
link:
route: !php/const CommerceWeavers\SyliusTpayPlugin\Routing::SHOP_ACCOUNT_CREDIT_CARD_DELETE
parameters:
id: resource.id
32 changes: 32 additions & 0 deletions config/routes_shop.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,36 @@
->controller(DisplayWaitingForPaymentPage::class)
->methods([Request::METHOD_GET])
;

$routes->add(Routing::SHOP_ACCOUNT_CREDIT_CARD_INDEX, Routing::SHOP_ACCOUNT_CREDIT_CARD_INDEX_PATH)
->controller('commerce_weavers_sylius_tpay.controller.credit_card::indexAction')
->methods([Request::METHOD_GET])
->defaults([
'_sylius' => [
'template' => '@CommerceWeaversSyliusTpayPlugin/shop/account/credit_card/index.html.twig',
'section' => 'shop_account',
'grid' => 'commerce_weavers_sylius_tpay_shop_account_credit_card',
]
])
;

$routes->add(Routing::SHOP_ACCOUNT_CREDIT_CARD_DELETE, Routing::SHOP_ACCOUNT_CREDIT_CARD_DELETE_PATH)
->controller('commerce_weavers_sylius_tpay.controller.credit_card::deleteAction')
->methods([Request::METHOD_DELETE])
->requirements(['id' => '[0-9a-f]{8}-[0-9a-f]{4}-[1-6][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}'])
->defaults([
'_sylius' => [
'section' => 'shop_account',
'repository' => [
'method' => 'findOneByIdCustomerAndChannel',
'arguments' => [
'$id',
'expr:service(\'sylius.context.customer\').getCustomer()',
'expr:service(\'sylius.context.channel\').getChannel()',
],
],
'redirect' => Routing::SHOP_ACCOUNT_CREDIT_CARD_INDEX,
]
])
;
};
25 changes: 25 additions & 0 deletions config/serialization/CreditCard.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?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\Entity\CreditCard">
<attribute name="id">
<group>commerce_weavers_sylius_tpay:shop:credit_card:index</group>
<group>commerce_weavers_sylius_tpay:shop:credit_card:show</group>
</attribute>
<attribute name="brand">
<group>commerce_weavers_sylius_tpay:shop:credit_card:index</group>
<group>commerce_weavers_sylius_tpay:shop:credit_card:show</group>
</attribute>
<attribute name="tail">
<group>commerce_weavers_sylius_tpay:shop:credit_card:index</group>
<group>commerce_weavers_sylius_tpay:shop:credit_card:show</group>
</attribute>
<attribute name="expirationDate">
<group>commerce_weavers_sylius_tpay:shop:credit_card:index</group>
<group>commerce_weavers_sylius_tpay:shop:credit_card:show</group>
</attribute>
</class>
</serializer>
6 changes: 6 additions & 0 deletions config/serialization/Pay.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
<attribute name="encodedCardData">
<group>commerce_weavers_sylius_tpay:shop:order:pay</group>
</attribute>
<attribute name="saveCard">
<group>commerce_weavers_sylius_tpay:shop:order:pay</group>
</attribute>
<attribute name="savedCardId">
<group>commerce_weavers_sylius_tpay:shop:order:pay</group>
</attribute>
<attribute name="tpayChannelId">
<group>commerce_weavers_sylius_tpay:shop:order:pay</group>
</attribute>
Expand Down
6 changes: 6 additions & 0 deletions config/services/api/command.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use CommerceWeavers\SyliusTpayPlugin\Api\Command\PayByGooglePayHandler;
use CommerceWeavers\SyliusTpayPlugin\Api\Command\PayByLinkHandler;
use CommerceWeavers\SyliusTpayPlugin\Api\Command\PayByRedirectHandler;
use CommerceWeavers\SyliusTpayPlugin\Api\Command\PayBySavedCardHandler;
use CommerceWeavers\SyliusTpayPlugin\Api\Command\PayByVisaMobileHandler;
use CommerceWeavers\SyliusTpayPlugin\Api\Command\PayHandler;
use CommerceWeavers\SyliusTpayPlugin\Command\CancelLastPaymentHandler;
Expand Down Expand Up @@ -75,6 +76,11 @@
->tag('messenger.message_handler')
;

$services->set('commerce_weavers_sylius_tpay.api.command.pay_by_saved_card_handler', PayBySavedCardHandler::class)
->parent('commerce_weavers_sylius_tpay.api.command.abstract_pay_by_handler')
->tag('messenger.message_handler')
;

$services->set('commerce_weavers_sylius_tpay.api.command.pay_by_google_pay_handler', PayByGooglePayHandler::class)
->parent('commerce_weavers_sylius_tpay.api.command.abstract_pay_by_handler')
->tag('messenger.message_handler')
Expand Down
19 changes: 19 additions & 0 deletions config/services/api/doctrine.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use CommerceWeavers\SyliusTpayPlugin\Api\Doctrine\QueryCollectionExtension\CreditCardShopUserCollectionExtension;
use CommerceWeavers\SyliusTpayPlugin\Api\Doctrine\QueryItemExtension\CreditCardShopUserItemExtension;
use CommerceWeavers\SyliusTpayPlugin\Api\Doctrine\QueryItemExtension\OrderShopUserItemExtension;
use CommerceWeavers\SyliusTpayPlugin\Api\Doctrine\QueryItemExtension\OrderVisitorItemExtension;
use CommerceWeavers\SyliusTpayPlugin\Api\Doctrine\QueryItemExtension\Provider\AllowedOrderOperationsProvider;
use CommerceWeavers\SyliusTpayPlugin\Api\Doctrine\QueryItemExtension\Provider\AllowedOrderOperationsProviderInterface;
use Sylius\Bundle\ApiBundle\Context\UserContextInterface;
use Sylius\Component\Channel\Context\ChannelContextInterface;

return function(ContainerConfigurator $container): void {
$services = $container->services();
Expand All @@ -25,6 +28,22 @@
])
;

$services->set('commerce_weavers_sylius_tpay.api.doctrine.query_item_extension.credit_card_shop_user', CreditCardShopUserItemExtension::class)
->args([
service(UserContextInterface::class),
service(ChannelContextInterface::class),
])
->tag('api_platform.doctrine.orm.query_extension.item')
;

$services->set('commerce_weavers_sylius_tpay.api.doctrine.query_collection_extension.credit_card_shop_user', CreditCardShopUserCollectionExtension::class)
->args([
service(UserContextInterface::class),
service(ChannelContextInterface::class),
])
->tag('api_platform.doctrine.orm.query_extension.collection')
;

$services->set('commerce_weavers_sylius_tpay.api.doctrine.query_item_extension.order_visitor', OrderVisitorItemExtension::class)
->decorate(\Sylius\Bundle\ApiBundle\Doctrine\QueryItemExtension\OrderVisitorItemExtension::class)
->args([
Expand Down
10 changes: 10 additions & 0 deletions config/services/api/factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@

use CommerceWeavers\SyliusTpayPlugin\Api\Factory\NextCommand\PayByApplePayFactory;
use CommerceWeavers\SyliusTpayPlugin\Api\Factory\NextCommand\PayByBlikFactory;
use CommerceWeavers\SyliusTpayPlugin\Api\Factory\NextCommand\PayByCardAndSavedCardFactory;
use CommerceWeavers\SyliusTpayPlugin\Api\Factory\NextCommand\PayByCardFactory;
use CommerceWeavers\SyliusTpayPlugin\Api\Factory\NextCommand\PayByGooglePayFactory;
use CommerceWeavers\SyliusTpayPlugin\Api\Factory\NextCommand\PayByLinkFactory;
use CommerceWeavers\SyliusTpayPlugin\Api\Factory\NextCommand\PayByRedirectFactory;
use CommerceWeavers\SyliusTpayPlugin\Api\Factory\NextCommand\PayBySavedCardFactory;
use CommerceWeavers\SyliusTpayPlugin\Api\Factory\NextCommand\PayByVisaMobileFactory;
use CommerceWeavers\SyliusTpayPlugin\Api\Factory\NextCommandFactory;
use CommerceWeavers\SyliusTpayPlugin\Api\Factory\NextCommandFactoryInterface;
Expand All @@ -36,6 +38,14 @@
->tag('commerce_weavers_sylius_tpay.api.factory.next_command')
;

$services->set('commerce_weavers_sylius_tpay.api.factory.next_command.pay_by_saved_card', PayBySavedCardFactory::class)
->tag('commerce_weavers_sylius_tpay.api.factory.next_command')
;

$services->set('commerce_weavers_sylius_tpay.api.factory.next_command.pay_by_card_and_saved_card', PayByCardAndSavedCardFactory::class)
->tag('commerce_weavers_sylius_tpay.api.factory.next_command')
;

$services->set('commerce_weavers_sylius_tpay.api.factory.next_command.pay_by_google_pay', PayByGooglePayFactory::class)
->tag('commerce_weavers_sylius_tpay.api.factory.next_command')
;
Expand Down
18 changes: 18 additions & 0 deletions config/services/event_listener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use CommerceWeavers\SyliusTpayPlugin\ContextProvider\BankListContextProvider;
use CommerceWeavers\SyliusTpayPlugin\ContextProvider\RegulationsUrlContextProvider;
use CommerceWeavers\SyliusTpayPlugin\EventListener\AddCreditCardToAccountMenuEventListener;
use Sylius\Bundle\ShopBundle\Menu\AccountMenuBuilder;

return static function(ContainerConfigurator $container): void {
$services = $container->services();

$services->set(AddCreditCardToAccountMenuEventListener::class)
->tag('kernel.event_listener', ['event' => AccountMenuBuilder::EVENT_NAME, 'method' => '__invoke'])
;
};
15 changes: 15 additions & 0 deletions config/services/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use CommerceWeavers\SyliusTpayPlugin\EventListener\AddCreditCardToAccountMenuEventListener;
use CommerceWeavers\SyliusTpayPlugin\Form\DataTransformer\CardTypeDataTransformer;
use CommerceWeavers\SyliusTpayPlugin\Form\DataTransformer\VisaMobilePhoneDataTransformer;
use CommerceWeavers\SyliusTpayPlugin\Form\EventListener\AddSavedCreditCardsListener;
use CommerceWeavers\SyliusTpayPlugin\Form\EventListener\DecryptGatewayConfigListener;
use CommerceWeavers\SyliusTpayPlugin\Form\EventListener\EncryptGatewayConfigListener;
use CommerceWeavers\SyliusTpayPlugin\Form\EventListener\RemoveUnnecessaryPaymentDetailsFieldsListener;
Expand Down Expand Up @@ -49,6 +51,10 @@
$services->set(TpayPaymentDetailsType::class)
->args([
service('commerce_weavers_sylius_tpay.form.event_listener.remove_unnecessary_payment_details_fields'),
service('security.token_storage'),
service('translator'),
service('commerce_weavers_sylius_tpay.repository.credit_card'),
service('sylius.context.cart'),
])
->tag('form.type')
;
Expand All @@ -70,4 +76,13 @@
;

$services->set('commerce_weavers_sylius_tpay.form.event_listener.remove_unnecessary_payment_details_fields', RemoveUnnecessaryPaymentDetailsFieldsListener::class);

$services
->set('commerce_weavers_sylius_tpay.form.event_listener.add_saved_credit_cards', AddSavedCreditCardsListener::class)
->args([
service('security.token_storage'),
service('translator'),
service('commerce_weavers_sylius_tpay.repository.credit_card'),
])
;
};
12 changes: 12 additions & 0 deletions config/services/payum/action.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use CommerceWeavers\SyliusTpayPlugin\Payum\Action\Api\InitializeApplePayPaymentAction;
use CommerceWeavers\SyliusTpayPlugin\Payum\Action\Api\NotifyAction;
use CommerceWeavers\SyliusTpayPlugin\Payum\Action\Api\PayWithCardAction;
use CommerceWeavers\SyliusTpayPlugin\Payum\Action\Api\SaveCreditCardAction;
use CommerceWeavers\SyliusTpayPlugin\Payum\Action\CaptureAction;
use CommerceWeavers\SyliusTpayPlugin\Payum\Action\GetStatusAction;
use CommerceWeavers\SyliusTpayPlugin\Payum\Action\PartialRefundAction;
Expand Down Expand Up @@ -93,7 +94,18 @@
->tag('payum.action', ['factory' => TpayGatewayFactory::NAME, 'alias' => 'cw.tpay.notify'])
;

$services->set(SaveCreditCardAction::class)
->args([
service('commerce_weavers_sylius_tpay.factory.credit_card'),
service('commerce_weavers_sylius_tpay.repository.credit_card'),
])
->tag('payum.action', ['factory' => TpayGatewayFactory::NAME, 'alias' => 'cw.tpay.save_credit_card'])
;

$services->set(PayWithCardAction::class)
->args([
service('commerce_weavers_sylius_tpay.payum.mapper.pay_with_card_action'),
])
->tag('payum.action', ['factory' => TpayGatewayFactory::NAME, 'alias' => 'cw.tpay.pay_with_card'])
;

Expand Down
38 changes: 38 additions & 0 deletions config/services/payum/mapper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use CommerceWeavers\SyliusTpayPlugin\Payum\Action\Api\CreateApplePayTransactionAction;
use CommerceWeavers\SyliusTpayPlugin\Payum\Action\Api\CreateBlikLevelZeroTransactionAction;
use CommerceWeavers\SyliusTpayPlugin\Payum\Action\Api\CreateCardTransactionAction;
use CommerceWeavers\SyliusTpayPlugin\Payum\Action\Api\CreateGooglePayTransactionAction;
use CommerceWeavers\SyliusTpayPlugin\Payum\Action\Api\CreatePayByLinkTransactionAction;
use CommerceWeavers\SyliusTpayPlugin\Payum\Action\Api\CreateRedirectBasedTransactionAction;
use CommerceWeavers\SyliusTpayPlugin\Payum\Action\Api\CreateVisaMobileTransactionAction;
use CommerceWeavers\SyliusTpayPlugin\Payum\Action\Api\GetTpayTransactionsChannelsAction;
use CommerceWeavers\SyliusTpayPlugin\Payum\Action\Api\InitializeApplePayPaymentAction;
use CommerceWeavers\SyliusTpayPlugin\Payum\Action\Api\NotifyAction;
use CommerceWeavers\SyliusTpayPlugin\Payum\Action\Api\PayWithCardAction;
use CommerceWeavers\SyliusTpayPlugin\Payum\Action\Api\SaveCreditCardAction;
use CommerceWeavers\SyliusTpayPlugin\Payum\Action\CaptureAction;
use CommerceWeavers\SyliusTpayPlugin\Payum\Action\GetStatusAction;
use CommerceWeavers\SyliusTpayPlugin\Payum\Action\RefundAction;
use CommerceWeavers\SyliusTpayPlugin\Payum\Action\ResolveNextRouteAction;
use CommerceWeavers\SyliusTpayPlugin\Payum\Factory\TpayGatewayFactory;
use CommerceWeavers\SyliusTpayPlugin\Payum\Mapper\PayWithCardActionPayloadMapper;
use CommerceWeavers\SyliusTpayPlugin\Payum\Mapper\PayWithCardActionPayloadMapperInterface;

return static function(ContainerConfigurator $container): void {
$services = $container->services();
$services->defaults()
->public()
;

$services->set('commerce_weavers_sylius_tpay.payum.mapper.pay_with_card_action', PayWithCardActionPayloadMapper::class)
->args([
service('commerce_weavers_sylius_tpay.repository.credit_card'),
])
;
};
Loading

0 comments on commit 7124ebf

Please sign in to comment.