Q: What's a transaction manager ?
A: It is used to retrieve and save your transactions with a specific stockage method (ex: Doctrine, Redis, ...)
A transaction manager must implement the interface TransactionManagerInterface. This is a little exemple of manager working with Redis.
<?php
namespace MyBundle\Manager;
use IDCI\Bundle\PaymentBundle\Entity\Transaction;
use IDCI\Bundle\PaymentBundle\Exception\NoTransactionFoundException;
use Predis\Client;
class RedisTransactionManager implements TransactionManagerInterface
{
private $redis;
public function __construct(Client $redis)
{
$this->redis = $redis;
}
public function saveTransaction(Transaction $transaction)
{
$this->redis->set($transaction->getId(), serialize($transaction));
}
public function retrieveTransactionByUuid(string $transactionUuid): Transaction
{
$transaction = $this->redis->get($transactionUuid);
if (null === $transaction) {
throw new NoTransactionFoundException($transactionUuid);
}
return unserialize($transaction);
}
}
This method is called by the PaymentContext
In your configuration :
# services.yml
MyBundle\Manager\RedisTransactionManager:
arguments:
$redis: '@snc_redis.default'
IDCI\Bundle\PaymentBundle\Manager\TransactionManagerInterface: '@MyBundle\Manager\RedisTransactionManager'