Skip to content

Commit

Permalink
Add remaining payum configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
liszkapawel committed Feb 19, 2024
1 parent 2ebed29 commit dc88ace
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 24 deletions.
6 changes: 4 additions & 2 deletions config/services.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?xml version="1.0" encoding="UTF-8" ?>
<?xml version="1.0" encoding="UTF-8"?>

<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<imports>
<import resource="services/**/*.xml"/>
</imports>
Expand Down
9 changes: 5 additions & 4 deletions config/services/form.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<?xml version="1.0" encoding="UTF-8"?>

<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>

<defaults public="true" autoconfigure="false" autowire="false"/>
<defaults public="true"/>

<service id="bitbag.imoje_plugin.form.type.gateway_configuration" class="BitBag\SyliusImojePlugin\Form\Type\ImojeGatewayConfigurationType">
<tag name="sylius.gateway_configuration_type" type="imoje" label="bitbag.imoje_plugin.gateway_label"/>
<tag name="form.type"/>
</service>

</services>
</container>
9 changes: 4 additions & 5 deletions config/services/gateway_factory.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<?xml version="1.0" encoding="UTF-8"?>

<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>

<defaults public="true" autoconfigure="false" autowire="false"/>

<service id="bitbag.imoje_plugin.gateway_factory" class="Payum\Core\Bridge\Symfony\Builder\GatewayFactoryBuilder">
<argument>BitBag\SyliusImojePlugin\ImojeGatewayFactory</argument>
<tag name="payum.gateway_factory_builder" factory="imoje"/>
</service>

</services>
</container>
41 changes: 41 additions & 0 deletions src/Api/ImojeApi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

namespace BitBag\SyliusImojePlugin\Api;

class ImojeApi implements ImojeApiInterface
{
public function __construct(
private readonly string $environment,
private readonly string $merchantId,
private readonly string $serviceId,
private readonly string $serviceKey,
private readonly string $authorizationToken,
) {}

public function getApiUrl(): string
{
return $this->environment === 'production' ? self::PRODUCTION_PAYWALL_URL : self::SANDBOX_PAYWALL_URL;
}

public function getMerchantId(): string
{
return $this->merchantId;
}

public function getServiceId(): string
{
return $this->serviceId;
}

public function getServiceKey(): string
{
return $this->serviceKey;
}

public function getAuthorizationToken(): string
{
return $this->authorizationToken;
}
}
31 changes: 31 additions & 0 deletions src/Api/ImojeApiInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace BitBag\SyliusImojePlugin\Api;

interface ImojeApiInterface
{
public const SANDBOX_ENVIRONMENT = 'sandbox';
public const PRODUCTION_ENVIRONMENT = 'production';

public const SANDBOX_PAYWALL_URL = 'https://sandbox.paywall.imoje.pl/payment';
public const PRODUCTION_PAYWALL_URL = 'https://paywall.imoje.pl/payment';

public const NEW_STATUS = 'new';
public const PENDING_STATUS = 'pending';
public const SETTLED_STATUS = 'settled';
public const REJECTED_STATUS = 'rejected';
public const CANCELLED_STATUS = 'cancelled';

public const HASHING_ALGORITHM = 'sha256';

public function getApiUrl(): string;

public function getMerchantId(): string;

public function getServiceId(): string;

public function getServiceKey(): string;

public function getAuthorizationToken(): string;

}
6 changes: 3 additions & 3 deletions src/Form/Type/ImojeGatewayConfigurationType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace BitBag\SyliusImojePlugin\Form\Type;

use BitBag\SyliusImojePlugin\Bridge\ImojeBridgeInterface;
use BitBag\SyliusImojePlugin\Api\ImojeApiInterface;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
Expand All @@ -18,8 +18,8 @@ public function buildForm(FormBuilderInterface $builder, array $options)
$builder
->add('environment', ChoiceType::class, [
'choices' => [
'bitbag.imoje_plugin.configuration.production' => ImojeBridgeInterface::PRODUCTION_ENVIRONMENT,
'bitbag.imoje_plugin.configuration.sandbox' => ImojeBridgeInterface::SANDBOX_ENVIRONMENT,
'bitbag.imoje_plugin.configuration.production' => ImojeApiInterface::PRODUCTION_ENVIRONMENT,
'bitbag.imoje_plugin.configuration.sandbox' => ImojeApiInterface::SANDBOX_ENVIRONMENT,
],
'label' => 'bitbag.imoje_plugin.configuration.environment'
]
Expand Down
21 changes: 11 additions & 10 deletions src/ImojeGatewayFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

namespace BitBag\SyliusImojePlugin;

use BitBag\SyliusImojePlugin\Bridge\ImojeBridgeInterface;
use BitBag\SyliusImojePlugin\Api\ImojeApi;
use BitBag\SyliusImojePlugin\Api\ImojeApiInterface;
use Payum\Core\Bridge\Spl\ArrayObject;
use Payum\Core\GatewayFactory;

Expand All @@ -21,7 +22,7 @@ protected function populateConfig(ArrayObject $config): void

if (false === (bool) $config['payum.api']) {
$config['payum.default_options'] = [
'environment' => ImojeBridgeInterface::SANDBOX_ENVIRONMENT,
'environment' => ImojeApiInterface::SANDBOX_ENVIRONMENT,
'merchant_id' => '',
'service_id' => '',
'service_key' => '',
Expand All @@ -31,16 +32,16 @@ protected function populateConfig(ArrayObject $config): void

$config['payum.required_options'] = ['environment', 'merchant_id', 'service_id', 'service_key', 'authorization_token'];

$config['payum.api'] = static function (ArrayObject $config): array {
$config['payum.api'] = function (ArrayObject $config) {
$config->validateNotEmpty($config['payum.required_options']);

return [
'environment' => $config['environment'],
'merchant_id' => $config['merchant_id'],
'service_id' => $config['service_id'],
'service_key' => $config['service_key'],
'authorization_token' => $config['authorization_token'],
];
return new ImojeApi(
$config['environment'],
$config['merchant_id'],
$config['service_id'],
$config['service_key'],
$config['authorization_token'],
);
};
}
}
Expand Down
9 changes: 9 additions & 0 deletions translations/messages.en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
bitbag:
imoje_plugin:
configuration:
production: Production
sandbox: Sandbox
merchant_id: Merchant ID
service_id: Service ID
service_key: Service key
authorization_token: Authorization token

0 comments on commit dc88ace

Please sign in to comment.