PHP code example of kptive / payment-sips-bundle
1. Go to this page and download the library: Download kptive/payment-sips-bundle library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once ('vendor/autoload.php' );
kptive / payment-sips-bundle example snippets bash
$ php composer.phar
php
public function registerBundles ()
{
$bundles = array (
new JMS\Payment\CoreBundle\JMSPaymentCoreBundle(),
new Kptive\PaymentSipsBundle\KptivePaymentSipsBundle(),
);
}
php
namespace Acme \PaymentBundle \Entity ;
use Doctrine \ORM \Mapping as ORM ;
use JMS \Payment \CoreBundle \Entity \PaymentInstruction ;
class Order
{
private $id;
private $paymentInstruction;
private $amount;
private $payedAt;
public function getId ()
{
return $this ->id;
}
public function getAmount ()
{
return $this ->amount;
}
public function getPaymentInstruction ()
{
return $this ->paymentInstruction;
}
public function setPaymentInstruction (PaymentInstruction $instruction)
{
$this ->paymentInstruction = $instruction;
return $this ;
}
public function getPayedAt ()
{
return $this ->payedAt;
}
public function setPayedAt ($payedAt)
{
$this ->payedAt = $payedAt;
return $this ;
}
php
namespace Acme \PaymentBundle \Controller ;
use Sensio \Bundle \FrameworkExtraBundle \Configuration \Route ;
use Sensio \Bundle \FrameworkExtraBundle \Configuration \Template ;
use Symfony \Component \HttpFoundation \RedirectResponse ;
use Symfony \Bundle \FrameworkBundle \Controller \Controller ;
use JMS \Payment \CoreBundle \Entity \PaymentInstruction ;
use Acme \PaymentBundle \Entity \Order ;
class CheckoutController extends Controller
{
public function detailsAction (Order $order)
{
$request = $this ->get('request' );
$em = $this ->get('doctrine' )->getEntityManager();
$router = $this ->get('router' );
$ppc = $this ->get('payment.plugin_controller' );
$confirm = new \StdClass();
$form = $this ->createFormBuilder($confirm)
->add('save' , 'submit' , array ('label' => 'confirmer' ))
->getForm();
if ('POST' === $request->getMethod()) {
$form->handleRequest($request);
if ($form->isValid()) {
$instruction = new PaymentInstruction($order->getAmount(), 978 , 'sips' );
$ppc->createPaymentInstruction($instruction);
$order->setPaymentInstruction($instruction);
$em->persist($order);
$em->flush($order);
return new RedirectResponse($router->generate('payment_gateway' , array (
'id' => $order->getId(),
)));
}
}
return array (
'order' => $order,
'form' => $form->createView()
);
}
}
php
public function sipsGatewayAction (Order $order)
{
$client = $this ->get('kptive_payment_sips.client' );
$config = array (
'amount' => $order->getAmount() * 100 ,
'order_id' => $order->getId(),
);
$sips = $client->request($config);
return array ('sips' => $sips);
}
php
public function completeAction (Request $request)
{
$data = $request->request->get('DATA' );
$em = $this ->get('doctrine' )->getEntityManager();
$client = $this ->get('kptive_payment_sips.client' );
$response = $client->handleResponseData($data);
$order = $em->getRepository('KsPaymentBundle:Order' )->find($response['order_id' ]);
$instruction = $order->getPaymentInstruction();
$result = $this ->get('kptive_payment_sips.return_handler' )->handle($instruction, $response);
return array ('order' => $order);
}
php
namespace Acme \PaymentBundle \EventListener ;
use Doctrine \ORM \EntityManager ;
use JMS \Payment \CoreBundle \PluginController \Event \PaymentStateChangeEvent ;
use JMS \Payment \CoreBundle \Model \PaymentInterface ;
class PaymentListener
{
protected $entityManager;
public function __construct (EntityManager $entityManager)
{
$this ->entityManager = $entityManager;
}
public function onPaymentStateChange (PaymentStateChangeEvent $event)
{
if (PaymentInterface::STATE_DEPOSITED === $event->getNewState()) {
$order = $this
->entityManager
->getRepository('AcmePaymentBundle:Order' )
->findOneBy(array ('paymentInstruction' => $event->getPaymentInstruction()));
$order->setPayedAt(new \DateTime());
$this ->entityManager->persist($order);
$this ->entityManager->flush();
}
}
}