我正在开发一个电子商务网站。我想允许用户使用Paypal付款。所以我安装并配置了以下软件包:
"jms/security-extra-bundle": "dev-master",
"jms/payment-core-bundle": "master-dev",
"jms/di-extra-bundle": "1.7.0",
"jms/payment-paypal-bundle": "dev-master"
点击按钮付款时出现以下错误:
错误:在null
上调用成员函数getPendingTransaction()
$instruction = $commande->getPaymentInstruction();
if (null === $pendingTransaction = $instruction->getPendingTransaction()) {
$payment = $this->ppc->createPayment($instruction->getId(), $instruction->getAmount() - $instruction->getDepositedAmount());
} else {
$payment = $pendingTransaction->getPayment();
这是我的控制者:
/**
* @Route("/complete/{id}", name = "payment_complete")
*/
public function completeAction(Commandes $commande) // id of the order
{
$instruction = $commande->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());
}
// if successfull, i render my order validation template
return $this->render('FLYBookingsBundle:Post:validation.html.twig', array('commande' => $commande));
}
/** @DI\LookupMethod("form.factory") */
protected function getFormFactory()
{
}
/**
* @Route("/cancel", name = "payment_cancel")
*/
public function CancelAction()
{
$this->get('session')->getFlashBag()->add('info', 'Transaction annulée.');
return $this->redirect($this->generateUrl('yourTemplate'));
}
}
这是我的实体commandes:
<?php
namespace FLY\BookingsBundle\Entity;
use Application\Sonata\UserBundle\Entity\User;
use Doctrine\ORM\Mapping as ORM;
use JMS\Payment\CoreBundle\Entity\PaymentInstruction;
/**
* Commandes
*
* @ORM\Table("commandes")
* @ORM\Entity(repositoryClass="FLY\BookingsBundle\Entity\CommandesRepository")
*/
class Commandes
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="Application\Sonata\UserBundle\Entity\User", inversedBy="commandes")
* @ORM\JoinColumn(nullable=true)
*/
private $user;
/**
* @var boolean
*
* @ORM\Column(name="confirm", type="boolean")
*/
private $confirm;
/**
* @var \DateTime
*
* @ORM\Column(name="date", type="datetime")
*/
private $date;
/**
* @var integer
*
* @ORM\Column(name="reference", type="integer")
*/
private $reference;
/**
* @var array
*
* @ORM\Column(name="commande", type="array")
*/
private $commande;
/** * @ORM\OneToOne(targetEntity="JMS\Payment\CoreBundle\Entity\PaymentInstruction")
*/
private $paymentInstruction;
public function getPaymentInstruction()
{
return $this->paymentInstruction;
}
public function setPaymentInstruction(PaymentInstruction $instruction)
{
$this->paymentInstruction = $instruction;
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set confirm
*
* @param boolean $confirm
* @return Commandes
*/
public function setConfirm($confirm)
{
$this->confirm = $confirm;
return $this;
}
/**
* Get confirm
*
* @return boolean
*/
public function getConfirm()
{
return $this->confirm;
}
/**
* Set date
*
* @param \DateTime $date
* @return Commandes
*/
public function setDate($date)
{
$this->date = $date;
return $this;
}
/**
* Get date
*
* @return \DateTime
*/
public function getDate()
{
return $this->date;
}
/**
* Set reference
*
* @param integer $reference
* @return Commandes
*/
public function setReference($reference)
{
$this->reference = $reference;
return $this;
}
/**
* Get reference
*
* @return integer
*/
public function getReference()
{
return $this->reference;
}
/**
* Set commande
*
* @param array $order
* @return Commandes
*/
public function setCommande($commande)
{
$this->commande = $commande;
return $this;
}
/**
* Get commande
*
* @return array
*/
public function getCommande()
{
return $this->commande;
}
/**
* Set user
*
* @param \Application\Sonata\UserBundle\Entity\User $user
* @return Commandes
*/
public function setUser(\Application\Sonata\UserBundle\Entity\User $user = null)
{
$this->user = $user;
return $this;
}
/**
* Get user
*
* @return \Application\Sonata\UserBundle\Entity\User
*/
public function getUser()
{
return $this->user;
}
}
答案 0 :(得分:0)
不知道这些组件,
$instruction = $commande->getPaymentInstruction();
返回null,如果你在null上调用函数,则返回下一行:
$instruction->getPendingTransaction()