示例#1
0
 /**
  * Return callback response with shipping options
  *
  * @param array $request
  * @return string
  * @throws \Exception
  */
 public function getShippingOptionsCallbackResponse(array $request)
 {
     $debugData = ['request' => $request, 'response' => []];
     try {
         // obtain addresses
         $this->_getApi();
         $address = $this->_api->prepareShippingOptionsCallbackAddress($request);
         $quoteAddress = $this->_quote->getShippingAddress();
         // compare addresses, calculate shipping rates and prepare response
         $options = [];
         if ($address && $quoteAddress && !$this->_quote->getIsVirtual()) {
             foreach ($address->getExportedKeys() as $key) {
                 $quoteAddress->setDataUsingMethod($key, $address->getData($key));
             }
             $quoteAddress->setCollectShippingRates(true);
             $this->totalsCollector->collectAddressTotals($this->_quote, $quoteAddress);
             $options = $this->_prepareShippingOptions($quoteAddress, false, true);
         }
         $response = $this->_api->setShippingOptions($options)->formatShippingOptionsCallback();
         // log request and response
         $debugData['response'] = $response;
         $this->_logger->debug(var_export($debugData, true));
         return $response;
     } catch (\Exception $e) {
         $this->_logger->debug(var_export($debugData, true));
         throw $e;
     }
 }
示例#2
0
 /**
  * Return callback response with shipping options
  *
  * @param array $request
  * @return string
  * @throws \Exception
  */
 public function getShippingOptionsCallbackResponse(array $request)
 {
     // prepare debug data
     $logger = $this->_logFactory->create(array('fileName' => 'payment_' . $this->_methodType . '.log'));
     $debugData = array('request' => $request, 'response' => array());
     try {
         // obtain addresses
         $this->_getApi();
         $address = $this->_api->prepareShippingOptionsCallbackAddress($request);
         $quoteAddress = $this->_quote->getShippingAddress();
         // compare addresses, calculate shipping rates and prepare response
         $options = array();
         if ($address && $quoteAddress && !$this->_quote->getIsVirtual()) {
             foreach ($address->getExportedKeys() as $key) {
                 $quoteAddress->setDataUsingMethod($key, $address->getData($key));
             }
             $quoteAddress->setCollectShippingRates(true)->collectTotals();
             $options = $this->_prepareShippingOptions($quoteAddress, false, true);
         }
         $response = $this->_api->setShippingOptions($options)->formatShippingOptionsCallback();
         // log request and response
         $debugData['response'] = $response;
         $logger->log($debugData);
         return $response;
     } catch (\Exception $e) {
         $logger->log($debugData);
         throw $e;
     }
 }