<?php
namespace App\project\OfficeBrain\CustomBundle\OrderBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Symfony\Component\HttpFoundation\JsonResponse;
use App\project\OfficeBrain\CustomBundle\UserBundle\Form\ContactBookType;
use App\project\OfficeBrain\CustomBundle\UserBundle\Entity\ContactBook;
use App\OfficeBrain\Bundle\OrderBundle\Controller\OrderController as BaseOrderController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\DependencyInjection\ContainerInterface;
use App\OfficeBrain\Bundle\CoreBundle\Service\OBCommon;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use App\OfficeBrain\Bundle\CoreBundle\Service\SessionManager;
use App\OfficeBrain\Bundle\CoreBundle\Helper\Validation;
use App\OfficeBrain\Bundle\OrderBundle\Manager\Service\OrderService;
use App\OfficeBrain\Bundle\UserBundle\Manager\Service\UserService;
use App\OfficeBrain\Bundle\ProductBundle\Manager\Service\ProductDetailService;
use App\OfficeBrain\Bundle\CmsBundle\Manager\Service\CmsMediaLibraryService;
use App\OfficeBrain\Bundle\CoreBundle\Manager\Service\CoreService;
use App\OfficeBrain\Bundle\ShippingEstimatorBundle\Manager\Service\FedexShippingEstimatorService;
use App\OfficeBrain\Bundle\ShippingEstimatorBundle\Manager\Service\UPSShippingEstimatorService;
use App\OfficeBrain\Bundle\CmsBundle\Manager\Service\CmsThirdPartyService;
use App\project\OfficeBrain\CustomBundle\UserBundle\Manager\Service\ContactBookService;
use App\OfficeBrain\Bundle\QueueBundle\Manager\Service\ApiManager as QueueApiManager;
/**
*
*
* @Route("", defaults={"rule_service"="rule_charges"})
*/
class OrderController extends BaseOrderController
{
/**
*
* @author Employee Id: 5460
* To set member variables default value
* @return NULL
*
*
*/
public function __construct(ContainerInterface $container, OrderService $orderService, UserService $userService, ProductDetailService $productDetailService, CmsMediaLibraryService $cmsMediaLibraryService, CoreService $coreService, FedexShippingEstimatorService $fedexShippingEstimatorService, UPSShippingEstimatorService $upsShippingEstimatorService, CmsThirdPartyService $cmsThirdPartyService, ContactBookService $contactBookService, QueueApiManager $queueApiManager, RequestStack $requestStack, RouterInterface $router, ValidatorInterface $validatorInterface, SessionManager $sessionManager, Validation $validation)
{
parent::__construct($container, $orderService, $userService, $productDetailService, $cmsMediaLibraryService, $coreService, $fedexShippingEstimatorService, $upsShippingEstimatorService, $cmsThirdPartyService, $contactBookService, $queueApiManager, $requestStack, $router, $validatorInterface, $sessionManager, $validation);
$this->userContactBookManager = $contactBookService->getContactBookExtended();
}
/**
*
* @author Employee Id: 5460
* To unset member variables
* @return NULL
*/
public function __destruct()
{
parent::__destruct();
}
public function initAction(Request $request){
parent::initAction($request);
// $this->userContactBookManager = $this->serviceContainer->get('office_brain_user_contact_book_manager_custom');
$this->userContactBookManager = $this->userContactBookManager;
$this->tioryApiURL = $this->serviceContainer->getParameter('tiory_url'); //die;
//$this->tioryApiURL = 'https://arc1967.tiory.com/api/'; // Live
}
/**
* @author Employee Id: 4471
* Description : use to copy image for art work
* @param 1 : No paramater
* @return type : Ajax response in image successfully uploaded
* @throws Exception: Null
*
* @Route("/{_locale}/order-upload-artwork-from-gallery",
* name="office_brain_orderbundle_order_uploadartworkfromgallery",
* options={"expose"=true}
* )
* @Template()
* @Method({"POST"})
*/
public function uploadArtWorkFromGalleryAction(Request $request)
{
$this->initAction($request);
$logoId= $this->request->get('logoId');
$originalImageName= $this->request->get('imageName');
$imageUpload=$this->imageLibraryManager->copyMedia($this->mediaFilePath, $this->artworkFilePath ,$originalImageName,$originalImageName);
if($imageUpload != '')
{
$this->response['logoId']=$logoId;
$this->response['uploadedImageName']= $this->artworkFileURL.'/'.$imageUpload;
$this->response ['iconFileName'] = $this->artworkFileURL . '/' . $imageUpload;
/* code for replacing documents for related icons started */
$fileIconsAvailableFor = $this->serviceContainer->getParameter('file_icons_available_for');
$fileIconsBaseUrl = $this->serviceContainer->getParameter('file_icons_base_url');
if(isset($fileIconsAvailableFor) && is_array($fileIconsAvailableFor))
{
foreach($fileIconsAvailableFor as $fileIconsExtension)
{
if(strstr($imageUpload,$fileIconsExtension))
{
$imageUpload = str_replace('.','',$fileIconsExtension).'.png';
$this->response['iconFileName']= $fileIconsBaseUrl.$imageUpload;
}
}
}
/* code for replacing documents for related icons ended */
$this->response['status']='success';
$this->response['success_message']= $this->get('translator')->trans('order.print_position.artwork.upload_image_sucess');
}
else
{
$this->response['logoId']=$logoId;
$this->response['sucess']='error';
}
return new JsonResponse($this->response);
}
/**
* @author Employee Id: 4248
* Description : Use to add the new shipping address
*
* @Route("/{_locale}/order-add-address",
* name="office_brain_orderbundle_order_saveorderaddress",
* )
* @Method({"GET"})
* @Template("project/OfficeBrain/CustomBundle/OrderBundle/Order/addContactBook.html.twig")
*/
public function addContactBookAction(Request $request)
{
$this->initAction($request);
if( $this->userId==0){
if ($this->request->isXmlHttpRequest()) {
$this->responseArray['status'] = 'error';
$this->responseArray['error_type'] = 'loginError';
$this->responseArray['page_url'] = $this->generateUrl('office_brain_userbundle_login_login');
return new JsonResponse($this->responseArray);
}else{
return $this->redirect($this->generateUrl('office_brain_userbundle_login_login'));
}
$this->form = $this->createForm(new OrderAddGuestShippingType($this->coreManager, 'add'));
$this->form->handleRequest($this->request);
return $this->render('OfficeBrainOrderBundle:Order:addGuestContactBook.html.twig', array('contactBookForm' => $this->form->createView()));
}
else
{
$this->form = $this->createForm(new ContactBookType($this->serviceContainer,'order-add-address'), new ContactBook());
$this->form->handleRequest($this->request);
$this->responseArray['contactBookForm'] = $this->form->createView();
return $this->responseArray;
}
}
/**
* @author Employee Id: 410175
* Description : Use to render Shipping Address By Id
* @param 1 : No paramater
* @return type : Ajax response in view.
* @throws Exception: Null
*
* @Route("/{_locale}/order-get-shipping-address-by-id",
* name="office_brain_orderbundle_order_getshippingaddressbyid",
* options={"expose"=true}
* )
* @Template("OfficeBrainOrderBundle:Order:getShippingAddressById.html.twig")
* @Method({"GET"})
*/
public function getShippingAddressByIdAction(Request $request)
{
$this->initAction($request);
$this->response['result'] = $this->orderManager->getUserShippingAddresById();
$this->response['addressId'] = $this->request->get('contact_id',null);
return $this->response;
}
/**
* @author Employee Id: 4248
* Description : Use to add the new billing address
*
* @Route("/{_locale}/cheakout-add-billing-address",
* name="office_brain_orderbundle_order_addcheckoutshippingaddress",
* options={"expose"=true}
* )
* @Method({"GET"})
* @Template("project/OfficeBrain/CustomBundle/OrderBundle/Order/addCheckoutBillingAddress.html.twig")
*/
public function addCheckoutBillingAddressAction(Request $request)
{
$this->initAction($request);
if( $this->userId==0){
if ($this->request->isXmlHttpRequest()) {
$this->responseArray['error_type'] = 'loginError';
$this->responseArray['page_url'] = $this->generateUrl('office_brain_userbundle_login_login');
return new JsonResponse($this->responseArray);
}else{
return $this->redirect($this->generateUrl('office_brain_userbundle_login_login'));
}
}
else
{
// $this->form = $this->createForm(new ContactBookType($this->container), new ContactBook()); // symfony 4
$this->form = $this->createForm(ContactBookType::class, new ContactBook(), [
'container' => $this->serviceContainer,
]);
$this->form->handleRequest($this->request);
$this->responseArray['contactBookForm'] = $this->form->createView();
return $this->responseArray;
}
}
/**
* @author Employee Id: 4248
* Description : Use to edit the existing shipping address
*
* @Route("/{_locale}/checkout-shipping-edit-address/{contactBookId}",
* name="office_brain_orderbundle_order_editcheckoutshippingaddress",
* )
* @Method({"GET"})
* @Template("project/OfficeBrain/CustomBundle/OrderBundle/Order/editCheckoutShippingAddress.html.twig")
*/
public function editCheckoutShippingAddressAction(Request $request)
{
$this->initAction($request);
$contactBookId = $this->request->get('contactBookId');
$contactBookArray = $this->userContactBookManager->getSingleContactBook($contactBookId);
// $contactBookForm = $this->createForm(new ContactBookType($this->container), $contactBookArray); // symfony 4
$contactBookForm = $this->createForm(ContactBookType::class, $contactBookArray, [
'container' => $this->serviceContainer,
]);
if($contactBookArray->getCountryId()=='739')
{
$othercountry=1;
return array('contactBookForm'=> $contactBookForm->createView(),'contactBookId'=>$contactBookId,'othercountry'=>$othercountry);
}
return array ('contactBookForm' => $contactBookForm->createView (),'contactBookId' => $contactBookId);
}
/**
* @author Employee Id: 5429
* Description :My shipping address
*
* @Route("/{_locale}/order-view-my-address",
* name="office_brain_orderbundle_order_addressBook",
* )
* @Method({"GET"})
* @Template("project/OfficeBrain/CustomBundle/OrderBundle/Order/viewMyContactBook.html.twig")
*/
public function viewMyContactBookAction(Request $request)
{
$this->initAction($request);
$userId= $this->request->get('userId');
$type= $this->request->get('add-type');
$data['counter']= $this->request->get('counter');
$contactBookArray = $this->userContactBookManager->getMyAddressFromContactBook($userId,$type);
$data['contactBookArray']=$contactBookArray;
$data['addtype']=$type;
return $data;
}
/**
* @author Employee Id: 5429
* Description :My shipping address
*
* @Route("/{_locale}/order-view-my-address-ajax",
* name="office_brain_orderbundle_order_addressBook_ajax",options={"expose"=true}
* )
* @Method({"GET"})
* @Template("project/OfficeBrain/CustomBundle/OrderBundle/Order/viewMyContactBookAjax.html.twig")
*/
public function viewMyContactBookAjaxAction(Request $request)
{
$this->initAction($request);
$userId= $this->userId;
$type= $this->request->get('add-type');
$data['counter']= $this->request->get('counter');
$contactBookArray = $this->userContactBookManager->getMyAddressFromContactBook($userId,$type,1,$this->request->get('option'),$this->request->get('keywords'));
$data['contactBookArray']=$contactBookArray;
$data['addtype']=$type;
return $data;
}
/**
*
* @return json Response
*
* @Route("/{_locale}/cc-payment",
* name="officebrain_order_bundle_order_ccpayment",options={"expose"=true}
* )
*
*
*/
public function ccPaymentAction(Request $request)
{
$this->initAction($request);
$userId= $this->userId;
$data = array();
if ($this->request->isMethod('post')) {
$customerAccount = $this->request->get('account');
$invoiceNumber = $this->request->get('invoice');
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $this->tioryApiURL.'orderInvoiceDetailAPI',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => json_encode(array('customer_account' => $customerAccount,'invoice_number' => $invoiceNumber)),
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json'
),
));
$response = curl_exec($curl);
//print_r($response); die;
curl_close($curl);
$result = json_decode($response,true);
$accounts = array();
$data['no_rec_found']=true;
if(!$result['error']){
if(is_array($result['result'])){
$result = $result['result'];
$data['total_amount_due'] = (isset($result['total_amount_due'])) ? number_format($result['total_amount_due'],2) : 0.00;
$data['invoice_number'] = (isset($result['invoice_number'])) ? $result['invoice_number'] : '';
$data['customer_account'] = (isset($result['customer_account'])) ? $result['customer_account'] : '';
$data['first_name'] = (isset($result['first_name'])) ? $result['first_name'] : '';
$data['last_name'] = (isset($result['last_name'])) ? $result['last_name'] : '';
$data['company_name'] = (isset($result['company_name'])) ? $result['company_name'] : '';
$data['email'] = (isset($result['customer_email'])) ? $result['customer_email'] : '';
$data['city'] = (isset($result['city'])) ? $result['city'] : '';
$data['zipcode'] = (isset($result['zipcode'])) ? $result['zipcode'] : '';
$data['country'] = (isset($result['country'])) ? $result['country'] : '';
$data['state'] = (isset($result['state'])) ? $result['state'] : '';
$data['address_line1'] = (isset($result['address_line1'])) ? $result['address_line1'] : '';
//$data['url'] ="https://aakronruleuat.securepayments.cardpointe.com/pay?paymentType=cc&total=".$data['total_amount_due']."&invoice=".$data['invoice_number']."&customerId=".$data['customer_account']."&billFName=".$data['first_name']."&billLName=".$data['last_name']."&billCompany=".$data['company_name']."&billCity=".$data['city']."&tempBillState=".$data['state']."&billCountry=".$data['country']."&email=".$data['email']."&billZip=".$data['zipcode']."&billAddress1=".$data['address_line1'];
$data['url'] ="https://aakronruleuat.securepayments.cardpointe.com/pay?paymentType=cc&total=".$data['total_amount_due']."&invoice=".$data['invoice_number']."&customerId=".$data['customer_account']."&billCompany=".$data['company_name'];
$data['user_id']=$userId;
$data['no_rec_found']=false;
}
}
/*if($userId>0){
return $this->render('OfficeBrainCustomBundleOrderBundle:Order:ccPayment.html.twig', $data);
}else{
return $this->render('OfficeBrainCustomBundleOrderBundle:Order:ccPaymentload.html.twig', $data);
}*/
if($data['no_rec_found']){
return new JsonResponse(array('no_record_found'=>"Invoice not found"));
}else{
return new JsonResponse(array('payment_url'=>$data['url']));
}
}
die("Herere");
return array('user_id'=>$userId);
}
/**
*
* @return json Response
*
* @Route("/{_locale}/cc-payment-detail",
* name="officebrain_order_bundle_order_ccpaymentdetail",options={"expose"=true}
* )
*
*
*/
public function ccpaymentdetailAction(Request $request)
{
$this->initAction($request);
if(isset($_POST['json'])){
$content = json_decode($_POST['json'],true);
//$content = json_decode('{"paymentType":"CC","type":"Pay","ipAddress":"167.99.14.79","token":"9514245733035100","btnID":"submitBtn","baseTotal":"2.00","overallTotal":"2.00","debitType":"credit","invoice":"22800980","customerId":"37519","total":"2.00","existingCard":"N","number":"***5100","expirationDateMonth":"03","expirationDateYear":"2025","billCompany":"Aakronline","billFName":"John","billLName":"Doe","billAddress1":"Greenpark","billCity":"Alberta","billZip":"42001","billCountry":"US","email":"nilesgh@gmail.com","billState":"AL","cardType":"Mastercard","gatewayTransactionId":"263531149707","avsResponseCode":"Z","cvvResponseCode":"M","authCode":"PPS667","responseCode":"000","responseText":"Approval","responseProc":"RPCT","URL":"aakronruleuat.securepayments.cardpointe.com","merchantId":"855000000122","date":"2023-09-20 12:48:27"}',true);
$this->userManager = $this->get('office_brain_user_manager');
if(isset($content['gatewayTransactionId'])){
$userDetail = $this->userManager->getUserDetailByAccountNo($content['customerId']); //269625
$userId = $this->userId;
if($userId==0){
if($userDetail[0]!=null){
$userId = $userDetail[0]->getId();
}
}
$content['number'] = str_replace(' ','',$content['number']);
$cardName = strtolower(substr($content['cardType'],0,1));
$start = strlen($content['number'])-4;
$cardNumber = substr($content['number'],$start,4);
$this->orderManager->setPaymentData($content,$userId,json_encode($content));
$reqdata['paymentType'] = $content['paymentType'];
$reqdata['invoice'] = $content['invoice'];
$reqdata['customerId'] = $content['customerId'];
$reqdata['total'] = $content['total'];
$reqdata['gatewayTransactionId'] = $content['gatewayTransactionId'];
$reqdata['authCode'] = $content['authCode'];
$reqdata['date'] = $content['date'];
$reqdata['check_number'] = $cardName.$cardNumber;
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $this->tioryApiURL.'captureInvoicePaymentAPI',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => json_encode($reqdata),
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json'
),
));
$response = curl_exec($curl);
curl_close($curl);
}
}
die("Hook Done");
}
}