Symfony2 Payum Bundle - 请求 SecuredCaptureRequest{model : Payment} is not supported

标签 symfony payum

我刚刚安装并配置了 payum 包。我有一个异常(exception):

不支持请求 SecuredCaptureRequest{model: Payment}。

它发生在 PaymentController 的 preparePaypalExpressCheckoutPaymentAction 中重定向之后

Payum 配置:

payum:
    contexts:
        payment_with_paypal_express:
            storages:
                Service\Bundle\PaymentBundle\Entity\Payment:
                    doctrine:
                        driver: orm
            paypal_express_checkout_nvp:
                api:
                    options:
                        username:  %paypal.express.username%
                        password:  %paypal.express.password%
                        signature: %paypal.express.signature%
                        sandbox:   %paypal.express.sandbox%
    security:
        token_storage:
            Service\Bundle\PaymentBundle\Entity\PayumSecurityToken:
                doctrine:
                    driver: orm

支付 Controller :

class PaymentController extends HelperController
{
    public function preparePaypalExpressCheckoutPaymentAction()
    {
        $paymentName = 'payment_with_paypal_express';

        $storage = $this->get('payum')->getStorageForClass(
            'Service\Bundle\PaymentBundle\Entity\Payment',
            $paymentName
        );
        # ---- Set payment details below

        $package = $this->getPackageRepository()->loadOneByAliasAndDuration(Package::TYPE_SUBSCRIPTION,1);
        $accountPackages = new ArrayCollection();
        $accountPackages->add((new AccountPackage())->setPackage($package)->setQuantity(1));

        /**
         * @var Payment $payment
         */
        $payment = $storage->createModel();
        # Account must be set first, packages must be set before paid attribute
        $payment->setAccount($this->getAccount())
                ->setPackages($accountPackages)
                ->setPaid(false);

        # ---- Set payment details above

        $storage->updateModel($payment);

        $captureToken = $this->get('payum.security.token_factory')->createCaptureToken(
            $paymentName,
            $payment,
            'service_payment_done' // the route to redirect after capture;
        );

        $payment->setReturnUrl($captureToken->getTargetUrl())
                ->setCancelUrl($captureToken->getTargetUrl());

        $storage->updateModel($payment);

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

    public function paymentDoneAction(Request $request)
    {
        $token = $this->get('payum.security.http_request_verifier')->verify($request);

        $payment = $this->get('payum')->getPayment($token->getPaymentName());

        # $paymentDetails = $token->getDetails();

        $status = new BinaryMaskStatusRequest($token);

        $payment->execute($status);

        if ($status->isSuccess()) {
            $this->getUser()->addCredits(100);
            $this->get('session')->getFlashBag()->set(
                'notice',
                'Payment success. Credits were added'
            );
        }
        else if ($status->isPending()) {
            $this->get('session')->getFlashBag()->set(
                'notice',
                'Payment is still pending. Credits were not added'
            );
        }
        else {
            $this->get('session')->getFlashBag()->set('error', 'Payment failed');
        }

        return $this->redirect('service_home');
    }
}

有人有任何提示我做错了什么吗?在官方文档中,付款详细信息以对象/数组的形式呈现(有点令人困惑),但在我的 Controller 中我将其设为对象,有什么想法吗?

最佳答案

我解决了。忘记使用 Payum 中的 ArrayObject 扩展我的付款详细信息:)

关于Symfony2 Payum Bundle - 请求 SecuredCaptureRequest{model : Payment} is not supported,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24083690/

相关文章:

php - 在 Symfony2 中放置模型辅助函数的位置

php - 服务容器的生命周期有多长?

php - 难以使用 payum Bundle 管理数据

php - Sylius:添加新的 Payum 网关(Rabobank Omnikassa)

php - Payum自定义网关

security - Symfony2 http_basic 安全性拒绝有效凭据

php - Paypal REST API : Fulfill Order/Payment on Redirect URL or on Webhook call?

php - Symfony2 概念问题 : general bundles vs. 特定问题

symfony - Stripe 上无法识别的选项

symfony - Payum Paypal Rest config_path