-
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.
Extract Tpay Single Channel Pay-by-link as a separate payment method (#…
…238)
- Loading branch information
Showing
31 changed files
with
682 additions
and
55 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
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 Symfony\Component\DependencyInjection\Loader\Configurator; | ||
|
||
return static function(ContainerConfigurator $container): void { | ||
$container->import('form/**/*.php'); | ||
}; |
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,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Symfony\Component\DependencyInjection\Loader\Configurator; | ||
|
||
|
||
use CommerceWeavers\SyliusTpayPlugin\PayByLinkChannelPayment\Form\Type\GatewayConfigurationType; | ||
use CommerceWeavers\SyliusTpayPlugin\PayByLinkChannelPayment\Payum\Factory\GatewayFactory; | ||
|
||
return static function(ContainerConfigurator $container): void { | ||
$services = $container->services(); | ||
|
||
$services->set('commerce_weavers_sylius_tpay.pay_by_link_channel_payment.form.type.gateway_configuration', GatewayConfigurationType::class) | ||
->args([ | ||
service('translator'), | ||
]) | ||
->parent('commerce_weavers_sylius_tpay.form.type.abstract_tpay_gateway_configuration') | ||
->tag('sylius.gateway_configuration_type', ['label' => 'commerce_weavers_sylius_tpay.admin.gateway_name.tpay_channel_pbl', 'type' => GatewayFactory::NAME]) | ||
->tag('form.type') | ||
; | ||
}; |
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 Symfony\Component\DependencyInjection\Loader\Configurator; | ||
|
||
return static function(ContainerConfigurator $container): void { | ||
$container->import('payum/**/*.php'); | ||
}; |
24 changes: 24 additions & 0 deletions
24
config/services/pay_by_link_channel_payment/payum/action.php
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,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Symfony\Component\DependencyInjection\Loader\Configurator; | ||
|
||
use CommerceWeavers\SyliusTpayPlugin\PayByLinkChannelPayment\Payum\Action\CreatePayByLinkTransactionAction; | ||
use CommerceWeavers\SyliusTpayPlugin\PayByLinkChannelPayment\Payum\Factory\GatewayFactory; | ||
|
||
return static function(ContainerConfigurator $container): void { | ||
$services = $container->services(); | ||
|
||
$services->defaults() | ||
->public() | ||
; | ||
|
||
$services->set(CreatePayByLinkTransactionAction::class) | ||
->args([ | ||
service('commerce_weavers_sylius_tpay.tpay.factory.create_pay_by_link_payment_payload'), | ||
service('commerce_weavers_sylius_tpay.payum.factory.token.notify'), | ||
]) | ||
->tag('payum.action', ['factory' => GatewayFactory::NAME, 'alias' => 'cw.tpay_pbl.create_pay_by_link_channel_transaction']) | ||
; | ||
}; |
19 changes: 19 additions & 0 deletions
19
config/services/pay_by_link_channel_payment/payum/factory.php
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,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Symfony\Component\DependencyInjection\Loader\Configurator; | ||
|
||
use CommerceWeavers\SyliusTpayPlugin\PayByLinkChannelPayment\Payum\Factory\GatewayFactory; | ||
use Payum\Core\Bridge\Symfony\Builder\GatewayFactoryBuilder; | ||
|
||
return static function(ContainerConfigurator $container): void { | ||
$services = $container->services(); | ||
|
||
$services->set('commerce_weavers_sylius_tpay.pay_by_link_channel_payment.payum.factory.gateway', GatewayFactoryBuilder::class) | ||
->args([ | ||
GatewayFactory::class, | ||
]) | ||
->tag('payum.gateway_factory_builder', ['factory' => GatewayFactory::NAME]) | ||
; | ||
}; |
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,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace CommerceWeaversSyliusTpayMigrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
/** | ||
* Auto-generated Migration: Please modify to your needs! | ||
*/ | ||
final class Version20250120115438 extends AbstractMigration | ||
{ | ||
public function getDescription(): string | ||
{ | ||
return 'Migrate channel based tpay_pbl gateway to tpay_pbl_channel'; | ||
} | ||
|
||
public function up(Schema $schema): void | ||
{ | ||
$this->addSql(" | ||
UPDATE sylius_gateway_config | ||
SET | ||
gateway_name = 'tpay_pbl_channel', | ||
factory_name = 'tpay_pbl_channel' | ||
WHERE gateway_name = 'tpay_pbl' | ||
AND JSON_EXTRACT(config, '$.tpay_channel_id') IS NOT NULL | ||
"); | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
$this->addSql(" | ||
UPDATE sylius_gateway_config | ||
SET | ||
gateway_name = 'tpay_pbl', | ||
factory_name = 'tpay_pbl' | ||
WHERE gateway_name = 'tpay_pbl_channel' | ||
AND JSON_EXTRACT(config, '$.tpay_channel_id') IS NOT NULL | ||
"); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/PayByLinkChannelPayment/Form/Type/GatewayConfigurationType.php
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,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace CommerceWeavers\SyliusTpayPlugin\PayByLinkChannelPayment\Form\Type; | ||
|
||
use CommerceWeavers\SyliusTpayPlugin\Form\EventListener\DecryptGatewayConfigListenerInterface; | ||
use CommerceWeavers\SyliusTpayPlugin\Form\EventListener\EncryptGatewayConfigListenerInterface; | ||
use CommerceWeavers\SyliusTpayPlugin\Form\Type\AbstractTpayGatewayConfigurationType; | ||
use Symfony\Component\Form\Extension\Core\Type\TextType; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
use Symfony\Component\Validator\Constraints\NotBlank; | ||
|
||
final class GatewayConfigurationType extends AbstractTpayGatewayConfigurationType | ||
{ | ||
public function __construct( | ||
DecryptGatewayConfigListenerInterface $decryptGatewayConfigListener, | ||
EncryptGatewayConfigListenerInterface $encryptGatewayConfigListener, | ||
) { | ||
parent::__construct($decryptGatewayConfigListener, $encryptGatewayConfigListener); | ||
} | ||
|
||
public function buildForm(FormBuilderInterface $builder, array $options): void | ||
{ | ||
parent::buildForm($builder, $options); | ||
|
||
$builder | ||
->add( | ||
'tpay_channel_id', | ||
TextType::class, | ||
[ | ||
'empty_data' => '', | ||
'label' => 'commerce_weavers_sylius_tpay.admin.gateway_configuration.tpay_channel_id', | ||
'validation_groups' => ['sylius'], | ||
'constraints' => [ | ||
new NotBlank(allowNull: false, groups: ['sylius']), | ||
], | ||
'help' => 'commerce_weavers_sylius_tpay.admin.gateway_configuration.tpay_channel_id_help', | ||
'required' => false, | ||
], | ||
) | ||
; | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
src/PayByLinkChannelPayment/Payum/Action/CreatePayByLinkTransactionAction.php
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,70 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace CommerceWeavers\SyliusTpayPlugin\PayByLinkChannelPayment\Payum\Action; | ||
|
||
use CommerceWeavers\SyliusTpayPlugin\Model\PaymentDetails; | ||
use CommerceWeavers\SyliusTpayPlugin\Payum\Action\Api\BasePaymentAwareAction; | ||
use CommerceWeavers\SyliusTpayPlugin\Payum\Factory\Token\NotifyTokenFactoryInterface; | ||
use CommerceWeavers\SyliusTpayPlugin\Payum\Request\Api\CreateTransaction; | ||
use CommerceWeavers\SyliusTpayPlugin\Tpay\Factory\CreatePayByLinkPayloadFactoryInterface; | ||
use CommerceWeavers\SyliusTpayPlugin\Tpay\PaymentType; | ||
use Payum\Core\GatewayAwareInterface; | ||
use Payum\Core\GatewayAwareTrait; | ||
use Payum\Core\Reply\HttpRedirect; | ||
use Payum\Core\Request\Generic; | ||
use Sylius\Component\Core\Model\PaymentInterface; | ||
|
||
final class CreatePayByLinkTransactionAction extends BasePaymentAwareAction implements GatewayAwareInterface | ||
{ | ||
use GatewayAwareTrait; | ||
|
||
public function __construct( | ||
private readonly CreatePayByLinkPayloadFactoryInterface $createPayByLinkPayloadFactory, | ||
private readonly NotifyTokenFactoryInterface $notifyTokenFactory, | ||
) { | ||
parent::__construct(); | ||
} | ||
|
||
protected function doExecute(Generic $request, PaymentInterface $model, PaymentDetails $paymentDetails, string $gatewayName, string $localeCode): void | ||
{ | ||
$notifyToken = $this->notifyTokenFactory->create($model, $gatewayName, $localeCode); | ||
|
||
$this->do( | ||
fn () => $this->api->transactions()->createTransaction( | ||
$this->createPayByLinkPayloadFactory->createFrom($model, $notifyToken->getTargetUrl(), $localeCode), | ||
), | ||
onSuccess: function (array $response) use ($paymentDetails) { | ||
$paymentDetails->setTransactionId($response['transactionId']); | ||
$paymentDetails->setStatus($response['status']); | ||
$paymentDetails->setPaymentUrl($response['transactionPaymentUrl']); | ||
}, | ||
onFailure: fn () => $paymentDetails->setStatus(PaymentInterface::STATE_FAILED), | ||
); | ||
} | ||
|
||
protected function postExecute(PaymentInterface $model, PaymentDetails $paymentDetails, string $gatewayName, string $localeCode): void | ||
{ | ||
if ($paymentDetails->getPaymentUrl() !== null) { | ||
throw new HttpRedirect($paymentDetails->getPaymentUrl()); | ||
} | ||
} | ||
|
||
public function supports($request): bool | ||
{ | ||
if (!$request instanceof CreateTransaction) { | ||
return false; | ||
} | ||
|
||
$model = $request->getModel(); | ||
|
||
if (!$model instanceof PaymentInterface) { | ||
return false; | ||
} | ||
|
||
$paymentDetails = PaymentDetails::fromArray($model->getDetails()); | ||
|
||
return $paymentDetails->getType() === PaymentType::PAY_BY_LINK; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/PayByLinkChannelPayment/Payum/Factory/GatewayFactory.php
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,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace CommerceWeavers\SyliusTpayPlugin\PayByLinkChannelPayment\Payum\Factory; | ||
|
||
use CommerceWeavers\SyliusTpayPlugin\Payum\Factory\TpayGatewayFactory; | ||
|
||
final class GatewayFactory extends TpayGatewayFactory | ||
{ | ||
public const NAME = 'tpay_pbl_channel'; | ||
|
||
public function getName(): string | ||
{ | ||
return self::NAME; | ||
} | ||
} |
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.