/**
  * @return int|null
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 protected function _getDataAllowedMethods()
 {
     if (empty($this->_methods) && !empty($this->_request)) {
         $quote = $this->_helperCarrierData->getQuote();
         $shippingAddress = $quote->getShippingAddress();
         if (empty($shippingAddress)) {
             return null;
         }
         $postcode = $shippingAddress->getPostcode();
         try {
             $dimensions = $this->_helperCarrierData->getDimensions($this->_helperCarrierData->getAllItems($this->_request->getAllItems()));
         } catch (\Exception $e) {
             $this->_methods = self::INVALID_METHOD;
             return null;
         }
         $clientId = $this->_scopeConfig->getValue(\MercadoPago\Core\Helper\Data::XML_PATH_CLIENT_ID, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
         $clientSecret = $this->_scopeConfig->getValue(\MercadoPago\Core\Helper\Data::XML_PATH_CLIENT_SECRET, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
         $mp = $this->_mpHelper->getApiInstance($clientId, $clientSecret);
         $params = ["dimensions" => $dimensions, "zip_code" => $postcode];
         $freeMethod = $this->_helperCarrierData->getFreeMethod($this->_request);
         if (!empty($freeMethod)) {
             $params['free_method'] = $freeMethod;
         }
         $response = $mp->get("/shipping_options", $params);
         if ($response['status'] == 200) {
             $this->_methods = $response['response']['options'];
         } else {
             if (isset($response['response']['message'])) {
                 $this->_registry->register('mercadoenvios_msg', $response['response']['message']);
             }
             $this->_methods = self::INVALID_METHOD;
             $this->_helperCarrierData->log('Request params: ', $params);
             $this->_helperCarrierData->log('Error response API: ', $response);
         }
     }
     return $this->_methods;
 }
Exemplo n.º 2
0
 /**
  * Return array with data of payment in MP site
  *
  * @return array
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function postPago()
 {
     $client_id = $this->_scopeConfig->getValue(\MercadoPago\Core\Helper\Data::XML_PATH_CLIENT_ID, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
     $client_secret = $this->_scopeConfig->getValue(\MercadoPago\Core\Helper\Data::XML_PATH_CLIENT_SECRET, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
     $mp = $this->_helperData->getApiInstance($client_id, $client_secret);
     $pref = $this->makePreference();
     $this->_helperData->log("make array", 'mercadopago-standard.log', $pref);
     $response = $mp->create_preference($pref);
     $this->_helperData->log("create preference result", 'mercadopago-standard.log', $response);
     if ($response['status'] == 200 || $response['status'] == 201) {
         $payment = $response['response'];
         if ($this->_scopeConfig->getValue('payment/mercadopago_standard/sandbox_mode')) {
             $init_point = $payment['sandbox_init_point'];
         } else {
             $init_point = $payment['init_point'];
         }
         $array_assign = ["init_point" => $init_point, "type_checkout" => $this->getConfigData('type_checkout'), "iframe_width" => $this->getConfigData('iframe_width'), "iframe_height" => $this->getConfigData('iframe_height'), "banner_checkout" => $this->getConfigData('banner_checkout'), "status" => 201];
         $this->_helperData->log("Array preference ok", 'mercadopago-standard.log');
     } else {
         $array_assign = ["message" => __('An error has occurred. Please refresh the page.'), "json" => json_encode($response), "status" => 400];
         $this->_helperData->log("Array preference error", 'mercadopago-standard.log');
     }
     return $array_assign;
 }
Exemplo n.º 3
0
 /**
  * Saves to be used later by OCP
  *
  * @param $email
  *
  * @return bool|array
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function getOrCreateCustomer($email)
 {
     if (empty($email)) {
         return false;
     }
     //get access_token
     if (!$this->_accessToken) {
         $this->_accessToken = $this->_scopeConfig->getValue(\MercadoPago\Core\Helper\Data::XML_PATH_ACCESS_TOKEN);
     }
     $mp = $this->_helperData->getApiInstance($this->_accessToken);
     $customer = $mp->get("/v1/customers/search", ["email" => $email]);
     $this->_helperData->log("Response search customer", self::LOG_NAME, $customer);
     if ($customer['status'] == 200) {
         if ($customer['response']['paging']['total'] > 0) {
             return $customer['response']['results'][0];
         } else {
             $this->_helperData->log("Customer not found: " . $email, self::LOG_NAME);
             $customer = $mp->post("/v1/customers", ["email" => $email]);
             $this->_helperData->log("Response create customer", self::LOG_NAME, $customer);
             if ($customer['status'] == 201) {
                 return $customer['response'];
             } else {
                 return false;
             }
         }
     } else {
         return false;
     }
 }