2017-09-08 3 views
0

Ich versuche payum Zahlungsbündel in symfony 2.8Wie eine URL für den ersten Test von Payum Payment Bundle mit symfony2.8 erzeugen

Mein Endziel wurde Umgang mit der paypal Abonnement-Anwendung zu integrieren.

Ich habe die erste Einrichtung wie beschrieben here abgeschlossen.

Allerdings weiß ich nicht, wie man testet oder wo ich anfangen soll.

Es gibt public function prepareAction(), ich denke, zuerst sollte ich hier zugreifen.

Also habe ich in meinem route.yml

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

und in meinem Acme/PaymentBundle/Ressourcen/config.routing.yml

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

Dann versuchen Sie den Zugriff,

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

Allerdings zeigt es den Fehler so.

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

Ich bin sicher, dass dies im Zusammenhang mit meinem PaymentController.php

Ich denke, diese Fehler erscheinen in PaymentController.php ist, aber wie kann ich es beheben ??

'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('[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()); 
    } 
    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(), 
      ), 
     )); 
    } 

} 



} 

Antwort

1

In Ihrem Acme/PaymentBundle/Resources/config.routing.yml Sie müssen auch Ihre done Route definieren.

So könnte die Route Konfiguration folgendermaßen aussehen:

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

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

in Ihrer prepareAction Methode in der PaymentController.php Änderung Dann wird die Route getan:

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

ich nie das payum Bündel benutzt habe, aber ich Ich hoffe, das hilft.

Verwandte Themen