2013-06-15 3 views
1

привет, мне было интересно, как показать сводку заказа в paypal с помощью JMSPaymentPaypalBundle?!JMSPaymentPaypalBundle blank order summary

советы ау будет очень цениться ..

вот мой paypalController код в случае необходимости

<?php 
namespace Splurgin\EventsBundle\Controller; 

use JMS\DiExtraBundle\Annotation as DI; 
use JMS\Payment\CoreBundle\Entity\Payment; 
use JMS\Payment\CoreBundle\PluginController\Result; 
use JMS\Payment\CoreBundle\Plugin\Exception\ActionRequiredException; 
use JMS\Payment\CoreBundle\Plugin\Exception\Action\VisitUrl; 
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; 
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; 
use Symfony\Component\HttpFoundation\RedirectResponse; 


class PaymentController 
{ 
    /** @DI\Inject */ 
    private $request; 

    /** @DI\Inject */ 
    private $router; 

    /** @DI\Inject("doctrine.orm.entity_manager") */ 
    private $em; 

    /** @DI\Inject("payment.plugin_controller") */ 
    private $ppc; 
    /** 
    * @DI\Inject("service_container") 
    * 
    */ 
    private $container; 
    /** 
    * @Template 
    */ 
    public function detailsAction($package) 
    { 
     // note this ticket at this point in inactive ... 
     $order = $this->container->get('ticket')->generateTicket($package); 
     $order = $this->em->getRepository('SplurginEventsBundle:SplurginEventTickets')->find($order); 
     $packageId = $order->getPackageId(); 
     $package = $this->em->getRepository('SplurginEventsBundle:SplurginEventPackages')->find($package); 
     $price = $package->getPrice(); 
     var_dump($price); 
     if($price == null){ 
      throw new \RuntimeException('Package was not found: '.$result->getReasonCode()); 
     } 

     $form = $this->getFormFactory()->create('jms_choose_payment_method', null, array(
      'amount' => $price, 
      'currency' => 'USD', 
      'default_method' => 'payment_paypal', // Optional 
      'predefined_data' => array(
       'paypal_express_checkout' => array(
        'return_url' => $this->router->generate('payment_complete', array(
         'order' => $order->getId(), 
        ), true), 
        'cancel_url' => $this->router->generate('payment_cancel', array(
         'order' => $order->getId(), 
        ), true) 
       ), 
      ), 
     )); 

     if ('POST' === $this->request->getMethod()) { 
      $form->bindRequest($this->request); 

      if ($form->isValid()) { 
       $this->ppc->createPaymentInstruction($instruction = $form->getData()); 

       $order->setPaymentInstruction($instruction); 
       $this->em->persist($order); 
       $this->em->flush($order); 

       return new RedirectResponse($this->router->generate('payment_complete', array(
        'order' => $order->getId(), 
       ))); 
      } 
     } 
     return array(
      'form' => $form->createView(), 
      'order'=>$order->getId(), 
     ); 
    } 


    /** @DI\LookupMethod("form.factory") */ 
    protected function getFormFactory() { } 



    /** 
    */ 
    public function completeAction($order) 
    { 
     $order = $this->em->getRepository('SplurginEventsBundle:SplurginEventTickets')->find($order); 

     $instruction = $order->getPaymentInstruction(); 
     if (null === $pendingTransaction = $instruction->getPendingTransaction()) { 
      $payment = $this->ppc->createPayment($instruction->getId(), $instruction->getAmount() - $instruction->getDepositedAmount()); 
     } else { 
      $payment = $pendingTransaction->getPayment(); 
     } 

     $result = $this->ppc->approveAndDeposit($payment->getId(), $payment->getTargetAmount()); 
     if (Result::STATUS_PENDING === $result->getStatus()) { 
      $ex = $result->getPluginException(); 

      if ($ex instanceof ActionRequiredException) { 
       $action = $ex->getAction(); 

       if ($action instanceof VisitUrl) { 
        return new RedirectResponse($action->getUrl()); 
       } 

       throw $ex; 
      } 
     } else if (Result::STATUS_SUCCESS !== $result->getStatus()) { 
      throw new \RuntimeException('Transaction was not successful: '.$result->getReasonCode()); 
     } 

    } 

    public function cancelAction($order) 
    { 
     die('cancel the payment'); 
    } 

} 
+1

почему вы инъекционные весь контейнер, если вам уже вводите свои зависимости один за другим (em, ...)? – nifr

+0

lol, im все еще работает над кодом .. это просто и старая переменная .. я буду перефактор кода, когда я сделал –

+0

, что будет показано в сводке вашего заказа? – nifr

ответ

2

я действительно не знаю, почему это не является частью документации, но пучок способен настройка параметров проверочные из коробки ...

вот как я сделал это

$form = $this->getFormFactory()->create('jms_choose_payment_method', null, array(
    'amount' => $price, 
    'currency' => 'USD', 
    'default_method' => 'payment_paypal', // Optional 
    'predefined_data' => array(
     'paypal_express_checkout' => array(
      'return_url' => $this->router->generate('payment_complete', array(
       'order' => $order->getId(), 
      ), true), 
      'cancel_url' => $this->router->generate('payment_cancel', array(
       'order' => $order->getId(), 
      ), true), 
      'checkout_params' => array(
       'L_PAYMENTREQUEST_0_NAME0' => 'event', 
       'L_PAYMENTREQUEST_0_DESC0' => 'some event that the user is trying to buy', 
       'L_PAYMENTREQUEST_0_AMT0'=> 6.00, // if you get 10413 , then visit the api errors documentation , this number should be the total amount (usually the same as the price) 
       // 'L_PAYMENTREQUEST_0_ITEMCATEGORY0'=> 'Digital', 
      ), 
     ), 

    ), 

)); 

кода ошибки можно найти here

SetExpressCheckout Запрос Поле here

я обеспечит запрос тянуть к документации, как только я могу .. :)

+0

Наконец-то я нашел правильный ответ !!! Я смотрел это очень долго, и ничего не нашел. Огромное спасибо!!! – Rey

+0

Как я могу отправить информацию о доставке? – Rey