Skip to content

Instantly share code, notes, and snippets.

@medy36
Last active June 11, 2016 00:25
Show Gist options
  • Save medy36/22ed82a1749432a07579e913d3163872 to your computer and use it in GitHub Desktop.
Save medy36/22ed82a1749432a07579e913d3163872 to your computer and use it in GitHub Desktop.
<?php
/**
* Payment for package
*
* @Route("/{_locale}/checkout/package", defaults={"_locale"="fr"}, name="coralto_lbp_order_package")
* @Method("POST")
* @Template("")
*/
public function paymentAction(Request $request)
{
// PaymentOrder $order, $packphoto, $entity
$session = new Session();
$pack= $session->get('pack_session');
$em = $this->get('doctrine')->getEntityManager();
// var_dump($pack);
// die;
// array('order' => $order, 'packphoto' => $package, 'entity'=> $entity);
$order = $pack['order'];
$packphoto = $pack['packphoto'];
// $package = $em->getRepository('CoraltoLbpBundle:Packages')->find(1);
$package = $em->getRepository('CoraltoLbpBundle:Packages')->find(1);
// $order->addPackage($package);
$request = $this->get('request');
$router = $this->get('router');
$ppc = $this->get('payment.plugin_controller');
$confirm = new \StdClass();
$form = $this->createFormBuilder($confirm)
->setAction($this->generateUrl('coralto_lbp_order_package'))
// ->setMethod('POST')
->add('save', 'submit', array('label' => 'confirmer'))
->getForm();
// if ('POST' === $request->getMethod()) {
$form->handleRequest($request);
// var_dump($order);
// die;
if ($form->isValid()) {
$instruction = new PaymentInstruction($order->getAmount(), 978, 'sips');
$ppc->createPaymentInstruction($instruction);
$order->setPaymentInstruction($instruction);
$order_pack = new orderPackage();
$order_pack->setPaydAt(new \Datetime());
$order_pack->setOrderId($order);
$order_pack->setPackageId($packphoto);
// $order->addPackage($order_pack);
$order->setState(PaymentOrder::STATE_NEW);
// var_dump($order->getPackages()[0]);
// die;
$em->persist($order);
$em->persist($order_pack);
$em->flush();
return new RedirectResponse($router->generate('payment_gateway', array(
'id' => $order->getId(),
)));
}
// }
return array(
'pack' => $packphoto,
'order' => $order,
'form' => $form->createView()
);
}
<?php
namespace Coralto\PaymentBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use JMS\Payment\CoreBundle\Entity\PaymentInstruction;
/**
* PaymentOrder
*
* @ORM\Table()
* @ORM\Entity(repositoryClass="Coralto\PaymentBundle\Entity\PaymentOrderRepository")
*/
class PaymentOrder
{
const STATUS_NEW = "new";
const STATUS_DRAFT= "draft";
const STATUS_PENDING = "pending";
const STATUS_COMPLETE = "complete";
const STATUS_FINISHED = "finished";
const STATE_REFUSED = "refused";
const STATE_BANK_BAN = "bank_ban";
const STATE_FILTERED = "filtered";
const STATE_NEW = "new";
const STATE_APPROVED = "approved";
const STATE_FAILED = "failed";
const STATE_INVALID_FORMAT = "invalid_format";
const STATE_SERVER_ERROR = "server_error";
const STATE_CANCELED_BY_USER = "canceled_by_user";
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="amount", type="decimal")
*/
private $amount;
/**
* @var \DateTime
*
* @ORM\Column(name="payedAt", type="datetime")
*/
private $payedAt;
/**
* @ORM\OneToOne(targetEntity="JMS\Payment\CoreBundle\Entity\PaymentInstruction")
*/
private $paymentInstruction;
/**
* @var string
* @ORM\Column(name="state", type="string", length=20)
*/
protected $state;
/**
* @ORM\OneToMany(targetEntity="Coralto\LbpBundle\Entity\orderPackage", mappedBy="orderId", cascade={"persist"})
*/
private $packages;
public function __toString()
{
return (string)$this->id;
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set amount
*
* @param string $amount
* @return PaymentOrder
*/
public function setAmount($amount)
{
$this->amount = $amount;
return $this;
}
/**
* Get amount
*
* @return string
*/
public function getAmount()
{
return $this->amount;
}
/**
* Set payedAt
*
* @param \DateTime $payedAt
* @return PaymentOrder
*/
public function setPayedAt($payedAt)
{
$this->payedAt = $payedAt;
return $this;
}
/**
* Get payedAt
*
* @return \DateTime
*/
public function getPayedAt()
{
return $this->payedAt;
}
public function getPaymentInstruction()
{
return $this->paymentInstruction;
}
public function setPaymentInstruction(PaymentInstruction $instruction)
{
$this->paymentInstruction = $instruction;
return $this;
}
/**
* Constructor
*/
public function __construct()
{
$this->packages = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Set state
*
* @param string $state
* @return PaymentOrder
*/
public function setState($state)
{
$this->state = $state;
return $this;
}
/**
* Get state
*
* @return string
*/
public function getState()
{
return $this->state;
}
/**
* Add packages
*
* @param \Coralto\LbpBundle\Entity\order_package $packages
* @return PaymentOrder
*/
public function addPackage(\Coralto\LbpBundle\Entity\orderPackage $packages)
{
$this->packages[] = $packages;
return $this;
}
/**
* Remove packages
*
* @param \Coralto\LbpBundle\Entity\order_package $packages
*/
public function removePackage(\Coralto\LbpBundle\Entity\orderPackage $packages)
{
$this->packages->removeElement($packages);
}
/**
* Get packages
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getPackages()
{
return $this->packages;
}
}
<?php
namespace Coralto\LbpBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* order_package
*
* @ORM\Table()
* @ORM\Entity
*/
class orderPackage
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var \DateTime
*
* @ORM\Column(name="paydAt", type="datetime")
*/
private $paydAt;
/**
* @ORM\ManyToOne(targetEntity="Coralto\PaymentBundle\Entity\PaymentOrder")
*/
private $orderId;
/**
* @ORM\ManyToOne(targetEntity="Packages", cascade={"persist"})
*/
private $packageId;
public function __toString()
{
return (string)$this->id;
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set paydAt
*
* @param \DateTime $paydAt
* @return order_package
*/
public function setPaydAt($paydAt)
{
$this->paydAt = $paydAt;
return $this;
}
/**
* Get paydAt
*
* @return \DateTime
*/
public function getPaydAt()
{
return $this->paydAt;
}
/**
* Set orderId
*
* @param \Coralto\PaymentBundle\Entity\PaymentOrder $orderId
* @return order_package
*/
public function setOrderId(\Coralto\PaymentBundle\Entity\PaymentOrder $orderId = null)
{
$this->orderId = $orderId;
return $this;
}
/**
* Get orderId
*
* @return \Coralto\PaymentBundle\Entity\PaymentOrder
*/
public function getOrderId()
{
return $this->orderId;
}
/**
* Set packageId
*
* @param \Coralto\LbpBundle\Entity\Packages $packageId
* @return order_package
*/
public function setPackageId(\Coralto\LbpBundle\Entity\Packages $packageId = null)
{
$this->packageId = $packageId;
return $this;
}
/**
* Get packageId
*
* @return \Coralto\LbpBundle\Entity\Packages
*/
public function getPackageId()
{
return $this->packageId;
}
}
<?php
namespace Coralto\LbpBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Packages
*
* @ORM\Table()
* @ORM\Entity(repositoryClass="Coralto\LbpBundle\Entity\PackagesRepository")
*/
class Packages
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=255)
*/
private $name;
/**
* @var string
*
* @ORM\Column(name="type", type="string", length=64)
*/
private $type;
/**
* @var string
*
* @ORM\Column(name="description", type="string", length=255)
*/
private $description;
/**
* @var float
*
* @ORM\Column(name="price", type="float")
*/
private $price;
/**
* @ORM\OneToMany(targetEntity="PackageValue", mappedBy="package")
*/
protected $options;
/**
* @ORM\OneToMany(targetEntity="orderPackage", mappedBy="packageId", cascade={"persist"})
*/
private $orders;
public function __toString()
{
return $this->name;
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* @param string $name
* @return Packages
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set description
*
* @param string $description
* @return Packages
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* Get description
*
* @return string
*/
public function getDescription()
{
return $this->description;
}
/**
* Set price
*
* @param float $price
* @return Packages
*/
public function setPrice($price)
{
$this->price = $price;
return $this;
}
/**
* Get price
*
* @return float
*/
public function getPrice()
{
return $this->price;
}
/**
* Constructor
*/
public function __construct()
{
$this->packageValues = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Add options
*
* @param \Coralto\LbpBundle\Entity\PackageValue $options
* @return Packages
*/
public function addOption(\Coralto\LbpBundle\Entity\PackageValue $options)
{
$this->options[] = $options;
return $this;
}
/**
* Remove options
*
* @param \Coralto\LbpBundle\Entity\PackageValue $options
*/
public function removeOption(\Coralto\LbpBundle\Entity\PackageValue $options)
{
$this->options->removeElement($options);
}
/**
* Get options
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getOptions()
{
return $this->options;
}
/**
* Set type
*
* @param string $type
* @return Packages
*/
public function setType($type)
{
$this->type = $type;
return $this;
}
/**
* Get type
*
* @return string
*/
public function getType()
{
return $this->type;
}
/**
* Add orders
*
* @param \Coralto\LbpBundle\Entity\order_package $orders
* @return Packages
*/
public function addOrder(\Coralto\LbpBundle\Entity\order_package $orders)
{
$this->orders[] = $orders;
return $this;
}
/**
* Remove orders
*
* @param \Coralto\LbpBundle\Entity\order_package $orders
*/
public function removeOrder(\Coralto\LbpBundle\Entity\order_package $orders)
{
$this->orders->removeElement($orders);
}
/**
* Get orders
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getOrders()
{
return $this->orders;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment