I'm going to use Payum Bundle with Symfony 3.2 for one of my project. The payment system is quite complex becouse i've multiple entities and everyone of them have one or more of the predefined payment methods. Every entity have his own credential. So for exaple:
Entity 1 have Paypal and Strype Entity 2 have Paypal only
But credentials for Paypal of the Entity 1 and 2 are different. The better way to manage that for me is to create a form for insert and edit the credentials and store all of them on database.
I see that Payum supports the database storage of the Gateway config but i'm not able to config symfony properly.
Following the entitities and config file untill now.
// /app/config/config.yml
payum:
security:
token_storage:
AppBundle\Entity\PaymentToken: { doctrine: orm }
storages:
AppBundle\Entity\PaymentDetails: { doctrine: orm }
Follwoing the Payum docs i've created the folling entity and generated the corrisponding table on database:
<?php
// AppBundle/Entity/GatewayConfig.php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Payum\Core\Model\GatewayConfig as BaseGatewayConfig;
/**
* @ORM\Table
* @ORM\Entity
*/
class GatewayConfig extends BaseGatewayConfig
{
/**
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*
* @var integer $id
*/
protected $id;
}
Than i've generated the entity and persisted on my database whit the following controller:
/**
* @Route("/testGateway", name="gateway")
*/
public function testGetawayCreationAction(){
$gatewayConfig = new GatewayConfig();
$gatewayConfig->setGatewayName('paypal');
$gatewayConfig->setFactoryName('paypal_express_checkout_nvp');
$gatewayConfig->setConfig(array(
'username' => 'MY COOL USERNAME',
'password' => 'MY COOL PASSWORD',
'signature' => 'MY ELEGANT SIGNATURE',
'sandbox' => true,
));
$em=$this->get('doctrine')->getManager();
$em->persist($gatewayConfig);
$em->flush();
return new Response("Gateway insered");
}
}
Now i've the entity , i've the data on the database but when i try to start a payum transacion i receive this error at creation of the token inside the following controller:
/**
* @Route("/doPayment", name="doPayment")
*/
public function prepareAction()
{
$gatewayName = 'paypal';
$storage = $this->get('payum')->getStorage('AppBundle\Entity\PaymentDetails');
$payment = $storage->create();
$payment->setNumber(uniqid());
$payment->setCurrencyCode('EUR');
$payment->setTotalAmount(123); // 1.23 EUR
$payment->setDescription('A description');
$payment->setClientId('anId');
$payment->setClientEmail('[email protected]');
$storage->update($payment);
$captureToken = $this->get('payum')->getTokenFactory()->createCaptureToken(
$gatewayName,
$payment,
'done' // the route to redirect after capture
);
return $this->redirect($captureToken->getTargetUrl());
}
Error 500: Gateway "paypal" does not exist.
This is i supposte becouse i'vent correctly configurated Payum to seach the gateway via Doctrine on the Database but i cant find any kind of docs about that last fase of configuration.