【问题标题】:payment with payum symfony5使用 payum symfony5 付款
【发布时间】:2021-07-17 19:44:56
【问题描述】:

我尝试在 symfony5 中申请使用 paypal 付款,但它返回错误。我按照以下说明操作:https://github.com/Payum/PayumBundle/blob/master/Resources/doc/get_it_started.md 但我不知道它们是否适合 symfony5。我有这个控制器:

<?php

namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Payum\Core\Model\Payment;
use Payum\Core\Reply\HttpRedirect;
use Payum\Core\Reply\HttpResponse;
use Payum\Core\Request\Capture;

class PayumController extends AbstractController
{
    /**
     * @Route("/payum", name="payum")
     */
    public function index() 
    {
        
        $gatewayName = 'offline';
        
        $storage = $this->get('payum')->getStorage('Acme\PaymentBundle\Entity\Payment');
        
        $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());           
    } 
}

这是 services.yaml

parameters:

services:
    # default configuration for services in *this* file
    _defaults:
        autowire: true      # Automatically injects dependencies in your services.
        autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.

    # makes classes in src/ available to be used as services
    # this creates a service per class whose id is the fully-qualified class name
    App\:
        resource: '../src/'
        exclude:
            - '../src/DependencyInjection/'
            - '../src/Entity/'
            - '../src/Kernel.php'
            - '../src/Tests/'

    # controllers are imported separately to make sure services can be injected
    # as action arguments even if you don't extend any base controller class
    App\Controller\:
        resource: '../src/Controller/'
        tags: ['controller.service_arguments']

    # add more service definitions when explicit configuration is needed
    # please note that last definitions always *replace* previous ones

它返回了我的错误:

Service "payum" not found: even though it exists in the app's container, the container inside "App\Controller\PayumController" is a smaller service locator that only knows about the "doctrine", "form.factory", "http_kernel", "parameter_bag", "request_stack", "router", "security.authorization_checker", "security.csrf.token_manager", "security.token_storage", "serializer", "session" and "twig" services. Try using dependency injection instead.

在线:$storage = $this-&gt;get('payum')-&gt;getStorage('Acme\PaymentBundle\Entity\Payment'); 我该如何解决这个问题?

【问题讨论】:

    标签: php symfony paypal payum


    【解决方案1】:

    我知道这已经几个月了,但它可能会帮助其他人找到这个问题。

    将构造函数添加到您的“PayumController”类并自动连接“Payum\Core\Payum”,例如

    public function __construct(Payum\Core\Payum $payum)
    {
      $this->payum = $payum;
    }
    

    然后当然用$this-&gt;payum替换对$this-&gt;get('payum')的调用

    【讨论】:

      猜你喜欢
      • 2014-12-10
      • 2014-06-27
      • 2014-05-22
      • 1970-01-01
      • 2023-04-01
      • 2018-04-27
      • 2016-04-26
      • 2014-06-10
      • 2015-06-26
      相关资源
      最近更新 更多