私は電子商取引のウェブサイトを開発しています。ユーザーが 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'));
}
}
これは私のエンティティコマンドです:
<?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;
}
}