嗨,我想知道如何使用 JMSPaymentPaypalBundle 在贝宝中显示订单摘要?!
任何提示将不胜感激..
这是我的 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');
}
}