PHP code example of snowbaha / etransactions-bundle

1. Go to this page and download the library: Download snowbaha/etransactions-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');

/* Start to develop here. Best regards https://php-download.com/ */

    

snowbaha / etransactions-bundle example snippets



// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Snowbaha\EtransactionsBundle\SnowbahaEtransactionsBundle(),
    );
}

    /**
     * @Route("/initiate-payment/id-{id}", name="pay_online")
     * @Template()
     */
    public function payOnlineAction($id)
    {
        // ...
        $etransactions = $this->get('snowbaha.etransactions')
            ->init(99, 100, '[email protected]')
            ->setOptionnalFields(array(
                'PBX_ERREUR' => 'http://www.example.com/error'
            ))
        ;

        return $this->render('YOURBUNDLEBundle:Etransactions:pay_online.html.twig', array(
                    'paymentUrl' => $etransactions->getPaymentUrl(),
                    'fields' => $etransactions->getFields(),
                ));
    }

    // YOUR CONTROLLER
    /**
     * THIS ROUTE have to be public to allow the bank access, it is the URL you will provide to your account 
     * @Route("/payment/verification")
     * @param Request $request
     */
    public function paymentVerificationAction(Request $request)
    {
        // ...
         $responseBank = $this->get('snowbaha.etransactions')->responseBankServer($request);
        
        $id_order = (int)$responseBank['ref'];
        $Order = $this->get('app.provider.order')->getOneByID( $id_order );

        // Success
        if($responseBank['sucessPayment'] === true && !is_null($Order)) :

            $Order->setState("order.state.success_payment");
            $Order->setPaymentError(0);

            // Email notification
            $this->get('app.mailing.order')->sendNewOrderNotif($Order);

        elseif( !is_null($Order) ) :
            // Error
            $Order->setState('order.state.success_payment_error');
            $Order->setPaymentError($responseBank['error']);
        endif;

        //...
    }