Skip to content

Commit

Permalink
RC1 : implement #7 #15 #17
Browse files Browse the repository at this point in the history
  • Loading branch information
baptiste-dulac committed Oct 24, 2019
1 parent 83c2492 commit a91998e
Show file tree
Hide file tree
Showing 23 changed files with 632 additions and 705 deletions.
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions DependencyInjection/Configuration.php
@@ -0,0 +1,45 @@
<?php

namespace Lone\SystempayBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

class Configuration implements ConfigurationInterface
{

public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder('systempay');
$treeBuilder
->getRootNode()
->children()
->scalarNode('hash_method')->end()
->scalarNode('key_dev')->defaultNull()->end()
->scalarNode('key_prod')->defaultNull()->end()
->arrayNode('vads')->children()
->scalarNode('debug')->defaultValue('ON')->end()
->scalarNode('site_id')->isRequired()->defaultValue('xxxxx')->end()
->scalarNode('url_return')->isRequired()->defaultValue('https://xxxx.xxxx')->end()
->scalarNode('return_mode')->defaultValue('POST')->end()
->scalarNode('ctx_mode')->defaultValue('TEST')->end()
->scalarNode('page_action')->defaultValue('PAYMENT')->end()
->scalarNode('action_mode')->defaultValue('INTERACTIVE')->end()
->scalarNode('payment_config')->defaultValue('SINGLE')->end()
->scalarNode('version')->defaultValue('V2')->end()
->scalarNode('language')->defaultValue('fr')->end()
->end()
->end()
;

/**
* Do not change the following values
* page_action: PAYMENT
* action_mode: INTERACTIVE
* payment_config: SINGLE
* version: V2
**/

return $treeBuilder;
}
}
37 changes: 37 additions & 0 deletions DependencyInjection/LoneSystempayExtension.php
@@ -0,0 +1,37 @@
<?php

namespace Lone\SystempayBundle\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\ConfigurableExtension;
use Symfony\Component\DependencyInjection\Loader;

class LoneSystempayExtension extends ConfigurableExtension
{

protected function loadInternal(array $mergedConfig, ContainerBuilder $container)
{
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');

$this->setConfigAsParameter($mergedConfig, $container);
}

private function setConfigAsParameter(array $config, ContainerBuilder $container, string $prefix = null) {
foreach ($config as $field => $value) {
if (is_array($value)) {
$this->setConfigAsParameter($value, $container, $field);
} else {
$key = sprintf('%s.%s%s', $this->getAlias(), $prefix ? $prefix.'.' : '', $field);
$container->setParameter($key, $value);
}
}
}

function getAlias()
{
return 'systempay';
}

}
175 changes: 175 additions & 0 deletions Entity/AbstractTransaction.php
@@ -0,0 +1,175 @@
<?php

namespace Lone\SystempayBundle\Entity;

use Lone\SystempayBundle\Model\TransactionStatus;
use \DateTime;
use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\HasLifecycleCallbacks()
*/
abstract class AbstractTransaction
{
/**
* @var
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;

/**
* @var string
* @ORM\Column(name="systempay_transaction_id", length=10, type="string")
*/
protected $systempayTransactionId;

/**
* @var string
* @ORM\Column(name="systempay_transaction_id", type="string", nullable=true)
*/
protected $transactionUuid;

/**
* @var string
* @ORM\Column(name="status_code", type="string", length=255, nullable=true)
*/
protected $status = TransactionStatus::PENDING;

/**
* @var int
* @ORM\Column(name="amount", type="integer")
*/
protected $amount;

/**
* @var int
* @ORM\Column(name="currency", type="integer")
*/
protected $currency;

/**
* @var DateTime
* @ORM\Column(name="created_at", type="datetime")
*/
protected $createdAt;

/**
* @var DateTime
* @ORM\Column(name="updated_at", type="datetime")
*/
protected $updatedAt;

/**
* @var string
* @ORM\Column(name="log_response", type="text", nullable=true)
*/
protected $logResponse;

/**
* @var bool
* @ORM\Column(name="paid", type="boolean")
*/
protected $paid = false;

/**
* @var bool
* @ORM\Column(name="refunded", type="boolean")
*/
protected $refunded = false;

/**
* Create a new transaction, default currency is 978 => EUR.
* @param int $amount
* @param int $currency
*/
public function __construct(string $systempayTransactionId, int $amount, int $currency = 978)
{
$this->systempayTransactionId = $systempayTransactionId;
$this->amount = $amount;
$this->currency = $currency;
}

/**
* @ORM\PrePersist()
* @ORM\PreUpdate()
*/
public function updateTimestamps() {
if (!$this->createdAt) {
$this->createdAt = new DateTime();
}
$this->updatedAt = new DateTime();
}

public function amount(): int
{
return $this->amount;
}

public function createdAt(): DateTime
{
return $this->createdAt;
}

public function currency(): int
{
return $this->currency;
}

public function id(): ?int
{
return $this->id;
}

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

public function setLogResponse($logResponse)
{
$this->logResponse = $logResponse;
}

public function paid(): bool
{
return $this->paid;
}

public function pay(): void
{
$this->paid = true;
}

public function refunded(): bool
{
return $this->refunded;
}

public function refund(): void
{
$this->refunded = true;
}

public function getStatus(): string
{
return $this->status;
}

public function changeStatus(string $status)
{
$this->status = $status;
}

public function updatedAt(): DateTime
{
return $this->updatedAt;
}

public function systempayTransactionId(): ?string
{
return $this->systempayTransactionId;
}

}
18 changes: 18 additions & 0 deletions LoneSystempayBundle.php
@@ -0,0 +1,18 @@
<?php

namespace Lone\SystempayBundle;

use Lone\SystempayBundle\DependencyInjection\LoneSystempayExtension;
use Symfony\Component\HttpKernel\Bundle\Bundle;

class LoneSystempayBundle extends Bundle {

public function getContainerExtension()
{
if (null === $this->extension) {
$this->extension = new LoneSystempayExtension();
}
return $this->extension;
}

}
7 changes: 7 additions & 0 deletions Model/AbstractCustomer.php
@@ -0,0 +1,7 @@
<?php

namespace Lone\SystemPayBundle\Model;

class AbstractCustomer {
// TODO : Implement customer
}
7 changes: 7 additions & 0 deletions Model/AbstractOrder.php
@@ -0,0 +1,7 @@
<?php

namespace Lone\SystempayBundle\Model;

class AbstractOrder {
// TODO : implement abstract order
}
10 changes: 10 additions & 0 deletions Model/PaymentStatus.php
@@ -0,0 +1,10 @@
<?php

namespace Lone\SystempayBundle\Model;

class PaymentStatus {

const AUTHORISED = 'authorised';
const REFUNDED = 'refunded';

}
10 changes: 10 additions & 0 deletions Model/TransactionStatus.php
@@ -0,0 +1,10 @@
<?php

namespace Lone\SystempayBundle\Model;

class TransactionStatus {

const PENDING = 'pending';
const PAID = 'paid';

}

0 comments on commit a91998e

Please sign in to comment.