【发布时间】:2017-10-03 18:19:41
【问题描述】:
我将在我的一个项目中使用带有 Symfony 3.2 的 Payum Bundle。 支付系统非常复杂,因为我有多个实体,每个实体都有一种或多种预定义的支付方式。 每个实体都有自己的凭证。例如:
实体 1 拥有 Paypal 和 Strype 实体 2 只有 Paypal
但实体 1 和 2 的 Paypal 凭据不同。 对我来说,更好的管理方法是创建一个用于插入和编辑凭据的表单,并将它们全部存储在数据库中。
我看到 Payum 支持网关配置的数据库存储,但我无法正确配置 symfony。
一直关注实体和配置文件。
// /app/config/config.yml
payum:
security:
token_storage:
AppBundle\Entity\PaymentToken: { doctrine: orm }
storages:
AppBundle\Entity\PaymentDetails: { doctrine: orm }
按照 Payum 文档,我创建了以下实体并在数据库中生成了对应的表:
<?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 交易时,我在以下控制器内创建令牌时收到此错误:
/**
* @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('foo@example.com');
$storage->update($payment);
$captureToken = $this->get('payum')->getTokenFactory()->createCaptureToken(
$gatewayName,
$payment,
'done' // the route to redirect after capture
);
return $this->redirect($captureToken->getTargetUrl());
}
错误 500:网关“paypal”不存在。
我认为这是因为我没有正确配置 Payum 以通过数据库上的 Doctrine 搜索网关,但我找不到任何关于最后一次配置的文档。
【问题讨论】:
标签: php symfony paypal doctrine-orm payum