rivasalmir

Untitled

Sep 12th, 2019
178
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. namespace Ysa\Core\Model;
  4.  
  5. use PHPUnit\Runner\Exception;
  6. use Magento\Framework\Webapi\Soap\ClientFactory;
  7.  
  8. class Api extends \Magento\Framework\Model\AbstractModel
  9. {
  10.     const URI_SOAP_PRD      = "http://xml-hu.kaluahtours.com/webservice/jp/operations/";
  11.     const URI_SOAP_HML      = "https://xml-uat.bookingengine.es/webservice/jp/operations/";
  12.     const PASS_HML          = "MmeJwr8YK";
  13.     const PASS_PRD          = "Rentalcars2018";
  14.     const USER_HML          = "XML_Optur";
  15.     const USER_PRD          = "atendimento02@optur.com.br";
  16.     const LIFETIME          = 1000;
  17.     const CONNECTTIMEOUT    = 100;
  18.  
  19.     var $soapClientFactory;
  20.     var $environment =  false; // if true = prod else test enviroment
  21.     protected $_logger;
  22.  
  23.     public function __construct(
  24.         ClientFactory $soapClientFactory,
  25.         \Psr\Log\LoggerInterface $logger
  26.     )
  27.     {
  28.         $this->soapClientFactory = $soapClientFactory;
  29.         $this->_logger = $logger;
  30.     }
  31.  
  32.     public function requestCurlXML($post_string, $url_asmx)
  33.     {
  34.  
  35.         $this->_logger->info($post_string);
  36.  
  37.         try {
  38.             $soap_do = curl_init();
  39.             curl_setopt($soap_do, CURLOPT_URL,            $url_asmx );
  40.             curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, self::CONNECTTIMEOUT);
  41.             curl_setopt($soap_do, CURLOPT_TIMEOUT,        self::LIFETIME);
  42.             curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
  43.             curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);
  44.             curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false);
  45.             curl_setopt($soap_do, CURLOPT_POST,           true );
  46.             curl_setopt($soap_do, CURLOPT_ENCODING, '');
  47.             curl_setopt($soap_do, CURLOPT_POSTFIELDS,    $post_string);
  48.             curl_setopt($soap_do, CURLOPT_HTTPHEADER,     array('Content-Type: text/xml; charset=utf-8', 'Content-Length: '.strlen($post_string) ));
  49.  
  50.             $result    = curl_exec($soap_do);
  51.  
  52.             $this->_logger->info($result);
  53.  
  54.             return $result;
  55.  
  56.         }catch(Exception $e){
  57.  
  58.             $err = curl_error($soap_do);
  59.             return $e->getMessage();
  60.         }
  61.  
  62.         curl_close($soap_do);
  63.  
  64.     }
  65.  
  66.  
  67. }
RAW Paste Data