繁体   English   中英

如何使用symfony2.8为Payum Payment Bundle的首次测试生成URL

[英]How to generate a url for the first test of Payum Payment Bundle with symfony2.8

我正在尝试将Payum付款包集成到symfony 2.8中

我的最终目标是处理Paypal订阅应用程序。

我已经按照此处所述完成了第一次设置。

但是我不知道如何测试或从哪里开始。

public function prepareAction() ,我想首先应该在这里访问。

所以我把我的route.yml

acme_payment:
    resource: "@AcmePaymentBundle/Resources/config/routing.yml"
    prefix:   /payment

并在我的Acme / PaymentBundle / Resources / config.routing.yml中

acme_payment_prepare:
    path:     /prepare
    defaults: { _controller: AcmePaymentBundle:Payment:prepare }

然后尝试访问,

http://localhost/myapp/web/app_dev.php/payment/prepare

但是它显示了这样的错误。

Unable to generate a URL for the named route "done" as such route does not exist.

我确定这与我的PaymentController.php有关

我认为此错误出现在PaymentController.php中,但是我该如何解决?

'done' // the route to redirect after capture

<?php


namespace Acme\PaymentBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

use Payum\Core\Request\GetHumanStatus;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;

class PaymentController extends Controller 
{
   public function prepareAction()
    {
        $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());
    }
    public function doneAction(Request $request)
    {
        $token = $this->get('payum')->getHttpRequestVerifier()->verify($request);

        $gateway = $this->get('payum')->getGateway($token->getGatewayName());

        // you can invalidate the token. The url could not be requested any more.
        // $this->get('payum')->getHttpRequestVerifier()->invalidate($token);

        // Once you have token you can get the model from the storage directly.
        //$identity = $token->getDetails();
        //$payment = $this->get('payum')->getStorage($identity->getClass())->find($identity);

        // or Payum can fetch the model for you while executing a request (Preferred).
        $gateway->execute($status = new GetHumanStatus($token));
        $payment = $status->getFirstModel();

        // you have order and payment status
        // so you can do whatever you want for example you can just print status and payment details.

        return new JsonResponse(array(
            'status' => $status->getValue(),
            'payment' => array(
                'total_amount' => $payment->getTotalAmount(),
                'currency_code' => $payment->getCurrencyCode(),
                'details' => $payment->getDetails(),
            ),
        ));
    }

}



}

Acme/PaymentBundle/Resources/config.routing.yml还需要定义done路线。

因此,路由配置可能如下所示:

acme_payment_prepare:
    path:     /prepare
    defaults: { _controller: AcmePaymentBundle:Payment:prepare }

acme_payment_done:
    path:     /done
    defaults: { _controller: AcmePaymentBundle:Payment:done }   

然后在PaymentController.php prepareAction方法内部,更改完成的路线:

$captureToken = $this->get('payum')->getTokenFactory()->createCaptureToken(
    $gatewayName,
    $payment,
    'acme_payment_done' // NOTE: I replaced `done` with `acme_payment_done`
 );

我从未使用过payum捆绑包,但希望能有所帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM