Symfony2.8集成Payum Bundle

时间:2016-04-01 11:24:51

标签: symfony paypal payum

我在我的网站上使用PayumBundle进行paypal集成。 我已经设置了捆绑包,如中所述 https://github.com/Payum/PayumBundle/blob/master/Resources/doc/get_it_started.md

并为payum安装了paypal express checkout nvp extension。

这是我的控制者:

            $gatewayName = 'paypal-express-checkout-nvp';

            $storage = $this->get('payum')->getStorage(PaymentDetails::class);

            $details = $storage->create();
            $details['PAYMENTREQUEST_0_CURRENCYCODE'] = 'CHF';
            $details['PAYMENTREQUEST_0_AMT'] = $amount;
            $storage->update($details);

            $captureToken = $this->get('payum')->getTokenFactory()->createCaptureToken(
                $gatewayName, $details, 'payment_done'
            );

            return $this->redirect($captureToken->getTargetUrl());

这是配置文件:

payum:
  security:
    token_storage:
        MyBundle\Entity\PaymentToken: { doctrine: orm }

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

  gateways:
    paypal-express-checkout-nvp:
        factory: paypal_express_checkout
        username:  %paypal_user%
        password:  %paypal_password%
        signature: %paypal_signature%
        sandbox: true

然而,当我提交表格时,我收到以下错误“

 Catchable Fatal Error: Argument 3 passed to Payum\Paypal\ExpressCheckout\Nvp\Api::__construct() must be an instance of Http\Message\MessageFactory, null given, called in vendor/payum/paypal-express-checkout-nvp/Payum/Paypal/ExpressCheckout/Nvp/PaypalExpressCheckoutGatewayFactory.php on line 89 and defined in vendor/payum/paypal-express-checkout-nvp/Payum/Paypal/ExpressCheckout/Nvp/Api.php at 317

我看了一下PaypalExpressCheckoutGatewayFactory类,其中config在第89行的populateConfig函数中传递,

 return new Api($paypalConfig, $config['payum.http_client'], $config['httplug.message_factory']);

键'httplug.message_factory'没有在任何地方定义?

STACK TRACE:

 0 vendor/payum/paypal-express-checkout-nvp/Payum/Paypal/ExpressCheckout/Nvp/Api.php(317): Symfony\Component\Debug\ErrorHandler->handleError(4096, 'Argument 3 pass...', '...', 317, Array)
 1 vendor/payum/paypal-express-checkout-nvp/Payum/Paypal/ExpressCheckout/Nvp/PaypalExpressCheckoutGatewayFactory.php(89): Payum\Paypal\ExpressCheckout\Nvp\Api->__construct(Array, Object(Payum\Core\Bridge\Guzzle\HttpClient), NULL)
 2 [internal function]: Payum\Paypal\ExpressCheckout\Nvp\PaypalExpressCheckoutGatewayFactory->Payum\Paypal\ExpressCheckout\Nvp\{closure}(Object(Payum\Core\Bridge\Spl\ArrayObject))
 3 vendor/payum/core/Payum/Core/CoreGatewayFactory.php(123): call_user_func(Object(Closure), Object(Payum\Core\Bridge\Spl\ArrayObject))
 4 vendor/payum/core/Payum/Core/Bridge/Symfony/ContainerAwareCoreGatewayFactory.php(35): Payum\Core\CoreGatewayFactory->buildClosures(Object(Payum\Core\Bridge\Spl\ArrayObject))
 5 vendor/payum/core/Payum/Core/CoreGatewayFactory.php(40): Payum\Core\Bridge\Symfony\ContainerAwareCoreGatewayFactory->buildClosures(Object(Payum\Core\Bridge\Spl\ArrayObject))
 6 vendor/payum/core/Payum/Core/GatewayFactory.php(33): Payum\Core\CoreGatewayFactory->create(Array)
 7 vendor/payum/core/Payum/Core/PayumBuilder.php(422): Payum\Core\GatewayFactory->create(Array)
 8 app/cache/dev/appDevDebugProjectContainer.php(2209): Payum\Core\PayumBuilder->getPayum()
 9 vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Container.php(316): appDevDebugProjectContainer->getPayumService()
 10 vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php(391): Symfony\Component\DependencyInjection\Container->get('payum')
 11 src/zenpme/BusinessBundle/Controller/PaymentController.php(74): Symfony\Bundle\FrameworkBundle\Controller\Controller->get('payum')
 12 [internal function]: BusinessBundle\Controller\PaymentController->indexAction(Object(Symfony\Component\HttpFoundation\Request))
 13 vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php(139): call_user_func_array(Array, Array)
 14 vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php(62): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
 15 vendor/symfony/symfony/src/Symfony/Component/HttpKernel/DependencyInjection/ContainerAwareHttpKernel.php(69): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
 16 vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php(185): Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
 17 web/app_dev.php(30): Symfony\Component\HttpKernel\Kernel->handle(Object(Symfony\Component\HttpFoundation\Request))
 18 {main}

2 个答案:

答案 0 :(得分:0)

确保您payum/core版本至少为1.3

答案 1 :(得分:0)

我在Symfony3中遇到了同样的问题。 要解决此问题,请添加数组键=>值:

httplug.message_factory' => new GuzzleMessageFactory()

在PaypalExpressCheckoutGatewayFactory配置数组中。 我会尝试找到更好的解决方案并稍后更新帖子。

您还必须添加此使用声明:

use Http\Message\MessageFactory\GuzzleMessageFactory;

修改 我终于在没有更改库的情况下使用它,但实际上我不知道如何。我在我的服务器上安装了应用程序,然后安装了php composer.phar install -o并且它可以工作。

这是我的composer.json:

 "require": {
        "php": ">=5.5.9",
        "symfony/symfony": "3.0.*",
        "doctrine/orm": "^2.5",
        "doctrine/doctrine-bundle": "^1.6",
        "doctrine/doctrine-cache-bundle": "^1.2",
        "symfony/swiftmailer-bundle": "^2.3",
        "symfony/monolog-bundle": "^2.8",
        "sensio/distribution-bundle": "^5.0",
        "sensio/framework-extra-bundle": "^3.0.2",
        "incenteev/composer-parameter-handler": "^2.0",
        "beberlei/DoctrineExtensions": "^1.0",
        "payum/payum-bundle": "^2.0",
        "payum/paypal-express-checkout-nvp": "^1.3"
    },