2017-05-05 24 views
0

我將使用Payum Bundle和Symfony 3.2作爲我的項目之一。 支付系統相當複雜,因爲我有多個實體,每個實體都有一個或多個預定義的支付方式。 每個實體都有自己的憑證。因此,對於的exaple:Symfony Payum Bundle從數據庫獲取網關

實體1有Paypal和Strype 實體有2只貝寶

但對於貝寶證書的實體1和2是不同的。 對我來說,更好的管理方法是創建一個用於插入和編輯憑證的表單,並將它們全部存儲在數據庫中。

我看到Payum支持網關配置的數據庫存儲,但我無法正確配置symfony。

直到現在,實體和配置文件。

// /app/config/config.yml 
payum: 
    security: 
     token_storage: 
      AppBundle\Entity\PaymentToken: { doctrine: orm } 

    storages: 
     AppBundle\Entity\PaymentDetails: { doctrine: orm } 

Follwoing的Payum文檔我創建了folling實體,產生對數據庫中的表corrisponding:

<?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; 
} 

比我產生的實體,並堅持在我的數據庫白衣以下控制器:

/** 
    * @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"); 
    } 
} 

現在我的實體,我對數據庫中的數據,但是當我嘗試啓動payum transacion我在創作FO裏面的令牌收到此錯誤控制器:

/** 
    * @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()); 
    } 

錯誤500:Gateway「paypal」不存在。

這是我supposte becouse i'vent正確配置Payum通過數據庫上的Doctrine網關,但我找不到任何類型的文檔關於最後一個配置的問題。你貼

回答

0

一切看起來都不錯,除了配置的這部分

#app/config/config.yml 

payum: 
    dynamic_gateways: 
     sonata_admin: true 
     config_storage: 
      Acme\PaymentBundle\Entity\GatewayConfig: { doctrine: orm }