payum symfony 2 bundle - basic configuration - sto

2019-08-23 23:18发布

问题:

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

回答1:

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.