I need to configure the payum bundle in order to let clients process paypal payments.
I just followed the getting started official recomendations, but need to configure something more, I guess (maybe I am missing to configure the storage for PaymentDetails somewhere).
my config files are as follows:
**app/config.yml**
doctrine:
orm:
auto_generate_proxy_classes: true
entity_managers:
default:
mappings:
WebsiteDeviceBundle: ~
WebsiteOnePageBundle: ~
payum:
is_bundle: false
type: xml
dir: %kernel.root_dir%/../vendor/payum/payum/src/Payum/Core/Bridge/Doctrine/Resources/mapping
prefix: Payum\Core\Model
payum:
security:
token_storage:
Website\Bundle\DeviceBundle\Entity\PaymentToken: { doctrine: orm }
storages:
Website\Bundle\DeviceBundle\Entity\PaymentDetails: { doctrine: orm }
contexts:
express_euro:
paypal_express_checkout_nvp:
username: ''
password: ''
signature: ''
sandbox: true
this is my controller action to start the payment process
public function prepareAction(){
$paymentName = 'express_euro';
$storage = $this->get('payum')->getStorage('Website\DeviceBundle\Entity\PaymentDetails');
$order = $storage->createModel();
$order->setNumber(uniqid());
$order->setCurrencyCode('EUR');
$order->setTotalAmount($this->view['user']->money);
$order->setDescrizione('annual account subscription');
$order->setUser($this->view['user']->getId());
$order->setCreatedAt(new \DateTime());
$order->setClientEmail($this->view['user']->getEmail());
$storage->updateModel($order);
$captureToken = $this->get('payum.security.token_storage')->createCaptureToken(
$paymentName,
$order,
'done' // the route to redirect after capture;
);
return $this->redirect($captureToken->getTargetUrl());
}
and this is PaymentDetails class
<?php
namespace Website\Bundle\DeviceBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Payum\Core\Model\ArrayObject;
/**
* PaymentDetails
*
* #ORM\Table(name="PaymentDetails", indexes={#ORM\Index(name="user", columns={"user"})})
* #ORM\Entity(repositoryClass="Website\Bundle\DeviceBundle\Entity\PaymentsDetailsRepository")
*/
class PaymentDetails extends ArrayObject
{
/**
* #var string
*
* #ORM\Column(name="currency_code", type="string", length=255, nullable=false)
*/
private $currencyCode;
/**
* #var string
*
* #ORM\Column(name="description", type="text", nullable=true)
*/
private $description;
/**
* #var \DateTime
*
* #ORM\Column(name="created_at", type="datetime", nullable=true)
*/
private $createdAt;
/**
* #var integer
*
* #ORM\Column(name="number", type="integer", nullable=false)
*/
private $number;
/**
* #var integer
*
* #ORM\Column(name="total_amount", type="integer", nullable=false)
*/
private $totalAmount;
/**
* #var string
*
* #ORM\Column(name="client_email", type="text", nullable=false)
*/
private $clientEmail;
/**
* #var integer
*
* #ORM\Column(name="id", type="bigint")
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* #var \Website\Bundle\DeviceBundle\Entity\Users
*
* #ORM\ManyToOne(targetEntity="Website\Bundle\DeviceBundle\Entity\Users")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="user", referencedColumnName="id")
* })
*/
private $user;
and the error it comes when I GET the doneAction() url, is this
A storage for model Website\DeviceBundle\Entity\PaymentDetails was not registered. There are storages for next models: Website\Bundle\DeviceBundle\Entity\PaymentDetails.
any helps or suggestions?
thank you in advance
just changed this line
$storage = $this->get('payum')->getStorage('Website\DeviceBundle\Entity\PaymentDetails');
into
$storage = $this->get('payum')->getStorage('Website\Bundle\DeviceBundle\Entity\PaymentDetails');
and now it works.
Related
My service (a console command) is receiving the IRI strings as arguments (I have this requirement, instead using the ids, that would be way more simple). So I have injected the ApiPlatform's IriConverter to my service, but when I call its getItemFromIri method I'm getting this error:
The token storage contains no authentication token. One possible reason may be that there is no firewall configured for this URL.
My Service:
use ApiPlatform\Core\Api\IriConverterInterface;
....
$context= []; // don't know what to include here
$iri= '/api/v4/files/448';
$file = $this->iriConverter->getItemFromIri($iri, $context);
My security.yml
firewalls:
apiV4:
pattern: ^/api/v4
stateless: true
fos_oauth: true
My Class
/**
* File
* #ApiResource(
* attributes={
* "normalization_context"={"groups"={"fileUpload"}}
* },
* collectionOperations = {
* "get",
* "post" ={
* "method"="POST",
* "path"="/files",
* "controller"= UploadFileAction::class,
* "defaults"={"_api_receive"=false},
* }
* }
* )
*
* #ORM\Table(name="UploadedFile")
*
*/
class File
{
/**
* #var int
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
* #Groups({"fileUpload"})
*/
private $id;
/**
* #var string
* #Assert\NotBlank
* #ORM\Column(name="name", type="string", length=255)
* #Groups({"fileUpload"})
*/
private $name;
....
I am using fosElastica for populate at elasticsearch. I have a two entity, that entities relationship together.
But I couldn't populate and show category name in products index. How can I to do?
Entity/AirportCodes.php
/**
* #var string $AirportCode
*
* #ORM\Column(name="AirportCode", type="string", length=3)
* #ORM\OneToOne(targetEntity="XXXBundle\Entity\AirportCodesTrans")
* #ORM\JoinColumn(name="AirportCode", referencedColumnName="airport_code", nullable=false)
*/
private $airportCode;
Services.yml
example-connect:
properties:
AirportCode: { type: text, analyzer: autocomplete }
AirportSlug: ~
CountryCode: ~
CityCode: ~
persistence:
driver: orm
model: XXXBundle\Entity\AirportCodes
identifier: AirportCode
provider: ~
finder: ~
Entity/AirportCodesTrans
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string $AirportCode
*
* #ORM\Column(name="airport_code", type="string", length=3)
*/
private $airportCode;
/**
* #var string $lang
*
* #ORM\Column(name="lang", type="string", length=3)
*/
private $lang;
/**
* #var string $name
*
* #ORM\Column(name="name", type="string", length=255)
*/
private $name;
config.yml
vich_uploader:
db_driver: orm
mappings:
media_image:
uri_prefix: '%uploads_dir%'
upload_destination: '%kernel.root_dir%/../web/uploads/images'
namer: Vich\UploaderBundle\Naming\OrignameNamer
Entity:
/**
* Media
* #Vich\Uploadable
* #ORM\Table(name="medias")
* #ORM\Entity(repositoryClass="AppBundle\Repository\MediaRepository")
*/
class Media
{
use TimestampableEntity;
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #ORM\Column(type="string", length=255, nullable=true)
* #var string
*/
private $imageName;
/**
* #Vich\UploadableField(mapping="media_image", fileNameProperty="imageName", mimeType="mimeType", size="size")
* #var File
*/
private $imageFile;
/**
* #var string
*
* #ORM\Column(name="mime_type", type="string", length=20, nullable=true)
*/
private $mimeType;
/**
* #var string
*
* #ORM\Column(name="size", type="integer", nullable=true)
*/
private $size;
When I enable namer, I am getting this error:
Any ideas why?
The (custom-)namer should be registered as a service and referred to by its service name.
You can see the default (long) configuration together with a list of namer services provided by VichUploaderBundle in the example below:
vich_uploader:
# [..]
mappings:
product_image_file:
# [..]
namer:
# one of: vich_uploader.namer_{uniqid,origname,property,hash}
service: vich_uploader.namer_origname
For reference, here are all namer services as listed by the command bin/console debug:container:
vich_uploader.namer_base64 Vich\UploaderBundle\Naming\Base64Namer
vich_uploader.namer_directory_property Vich\UploaderBundle\Naming\PropertyDirectoryNamer
vich_uploader.namer_hash Vich\UploaderBundle\Naming\HashNamer
vich_uploader.namer_origname Vich\UploaderBundle\Naming\OrignameNamer
vich_uploader.namer_property Vich\UploaderBundle\Naming\PropertyNamer
vich_uploader.namer_uniqid Vich\UploaderBundle\Naming\niqidNamer
Here some context information: I'm building a Symfony2 application with Doctrine2 and FOSRestBundle.
My problem: I want to be able to create a parent with his children with just one JSON and one database access.
My JSON looks like this:
{
"name": "TEST_NAME",
"info": "TEST_INFO",
"cmts": [
{
"cmt": "CMT1",
"info": "INFO1"
},
{
"cmt": "CMT2",
"info": "INFO2"
},
{
"cmt": "CMT3",
"info": "INFO3"
}
]
}
Here is my TEST entity:
<?php
namespace App\Bundle\DemoBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Test
*
* #ORM\Table(name="Test")
* #ORM\Entity(repositoryClass="App\Bundle\DemoBundle\Entity\TestRepository")
*/
class Test
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=255)
* #Assert\NotBlank()
*/
private $name;
/**
* #var string
*
* #ORM\Column(name="info", type="string", length=255, nullable=true)
*/
private $info;
/**
* #ORM\OneToMany(targetEntity="TestCmt", mappedBy="test", fetch="EAGER", orphanRemoval=true, cascade={"merge", "remove", "persist"})
*/
protected $cmts;
/**
* Constructor
*/
public function __construct()
{
$this->cmts = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Add cmts
*
* #param \App\Bundle\DemoBundle\Entity\TestCmt $cmts
* #return Test
*/
public function addCmt(\App\Bundle\DemoBundle\Entity\TestCmt $cmts)
{
$this->cmts[] = $cmts;
return $this;
}
/**
* Remove cmts
*
* #param \App\Bundle\DemoBundle\Entity\TestCmt $cmts
*/
public function removeCmt(\App\Bundle\DemoBundle\Entity\TestCmt $cmts)
{
$this->cmts->removeElement($cmts);
}
/**
* Get cmts
*
* #return \Doctrine\Common\Collections\Collection
*/
public function getCmts()
{
return $this->cmts;
}
// other getters/setters...
}
And my TESTCMT entity:
<?php
namespace App\Bundle\DemoBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* TestCmt
*
* #ORM\Table(name="TestCmt")
* #ORM\Entity(repositoryClass="App\Bundle\DemoBundle\Entity\TestCmtRepository")
*/
class TestCmt
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="cmt", type="string", length=255)
*/
private $cmt;
/**
* #var string
*
* #ORM\Column(name="info", type="string", length=255, nullable=true)
*/
private $info;
/**
* #var Test
*
* #ORM\ManyToOne(targetEntity="Test", inversedBy="cmts")
* #ORM\JoinColumn(name="test_id", referencedColumnName="id")
**/
private $test;
/**
* Set test
*
* #param \App\Bundle\DemoBundle\Entity\Test $test
* #return TestCmt
*/
public function setTest(\App\Bundle\DemoBundle\Entity\Test $test = null)
{
$this->test = $test;
return $this;
}
/**
* Get test
*
* #return \App\Bundle\DemoBundle\Entity\Test
*/
public function getTest()
{
return $this->test;
}
}
And finaly my postTestAction():
public function postTestAction(Request $request)
{
$entity = $this->deserialize($request, 'App\DemoBundle\Entity\Test');
$em = $this->getDoctrine()->getManager();
$em->persist($entity);
$em->flush();
return $entity;
}
When I send the JSON, TEST and TESTCMTs are created. Nevertheless, all "test_id" from the created TESTCMTs are "null"... And that's my problem!
EDIT: with SQL Server Profiler, I can see that Doctrine make that Transact SQL request:
INSERT INTO TESTCMT (test_id, cmt, info) VALUES (null, 'CMT', 'INFO')
I don't know why Doctrine can't send the test_id... TEST is created before TESTCMT, so "test_id" should be reachable for Doctrine to create the associate TESTCMTs.
Can someone helped me to fix it? :)
Remove #ORM\GeneratedValue(strategy="AUTO") and it won't let the DB generate a new id for the Entity
I making a RESTful app with Symfony and FOSRestBundle. FOSRestBundle uses JMS Serializer to serialize data to json format. I have everything working with one little issue.
This is my Entity class
/**
* Post
*
* #ORM\Table()
* #ORM\Entity(repositoryClass="Tomalo\AdminBundle\Entity\PostRepository")
* #ExclusionPolicy("none")
*/
class Post
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="content", type="text")
* #Assert\NotBlank()
*/
private $content;
/**
* #var float
*
* #ORM\Column(name="lat", type="float")
* #Assert\NotBlank()
*/
private $lat;
/**
* #var float
*
* #ORM\Column(name="lon", type="float")
* #Assert\NotBlank()
*/
private $lon;
/**
* #var \DateTime
*
* #ORM\Column(name="date", type="datetime")
*/
private $date;
/**
* #var string
*
* #ORM\Column(name="sign", type="string", length=50, nullable=true)
* #Expose
*/
private $sign;
/**
* #var integer
*
* #ORM\Column(name="status", type="integer")
*/
private $status=0;
/**
* #var integer
*
* #ORM\Column(name="points", type="integer")
*/
private $points=0;
/**
* #var string
*
* #ORM\Column(name="uuid", type="string", length=43)
* #Assert\NotBlank()
* #Exclude
*/
private $uuid;
private $owner;
//get/set method continue
and this is json I get:
{
"id": 5,
"content": "zxcvzxcvzxc",
"lat": 37.422005,
"lon": -122.084095,
"date": "2013-05-20T05:06:57+0100",
"status": 0,
"points": 0,
"owner": 0
}
In my entity $uuid is the only property haveing #Exclude annotation and is not there as expected but there is $sign property missing as well. As You see I put #Expose annotation to $sign but changed nothing. I tried using #ExclusionPolicy("all") and expose all except for uuid but I'm getting
Warning: json_encode(): recursion detected in E:\workspace\htdocs\tomalo\vendor\jms\serializer\src\JMS\Serializer\JsonSerializationVisitor.php line 29
I found some information as it is some php bug
any idea what is wrong and how to fix it?
You can serialize nulls as empty strings. Guess it help you a bit
$context = new SerializationContext();
$context->setSerializeNull(true);
$objectData = $serializer->serialize($object, 'json', $context);
For FOSRestBundle you can define it in settings
fos_rest:
view:
serialize_null: true
forgottenbas'es solution for FOSRestBundle didn't work for me. I have found a solution here https://github.com/FriendsOfSymfony/FOSRestBundle/pull/480
Use serializer section in your config, not view:
fos_rest:
serializer:
serialize_null: true