使用payum symfony5付款

问题描述 投票:0回答:2

我尝试在 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('[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());           
    } 
}

这是 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->get('payum')->getStorage('Acme\PaymentBundle\Entity\Payment');
我该如何解决这个问题?

php symfony paypal payum
2个回答
1
投票

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

向“PayumController”类添加一个构造函数并自动装配“Payum\Core\Payum”,例如

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

然后当然将对

$this->get('payum')
的调用替换为
$this->payum


0
投票

美好的一天,

您是否成功获得 Symfony 5 项目并使用 Payum Bundle 运行?

我也遇到类似的问题,我可以去 Payum 等,但我得到了一个。网关等错误。

不支持请求捕获{model: Identity}。确保 “MyBundle\Entity\Account\Payum\PaymentDetails”的存储扩展 已注册到网关。确保存储查找方法 返回 ID 为“101”的实例。确保网关支持 请求并且有一个支持该请求的操作( 方法返回 true)。可能有bug,所以寻找相关的问题 在问题跟踪器上。

© www.soinside.com 2019 - 2024. All rights reserved.