我刚刚安装并配置了payum bundle 包。我有一个例外:

不支持Request 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扩展我的付款细节:)

10-05 19:54