/**
  * Set configuration value sponsor_id based on current credentials
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function setSponsor()
 {
     $this->coreHelper->log("Sponsor_id: " . $this->scopeConfig->getValue('payment/mercadopago/sponsor_id'), self::LOG_NAME);
     $sponsorId = "";
     $this->coreHelper->log("Valid user test", self::LOG_NAME);
     $accessToken = $this->scopeConfig->getValue(\MercadoPago\Core\Helper\Data::XML_PATH_ACCESS_TOKEN);
     $this->coreHelper->log("Get access_token: " . $accessToken, self::LOG_NAME);
     if (!$accessToken) {
         return;
     }
     $mp = $this->coreHelper->getApiInstance($accessToken);
     $user = $mp->get("/users/me");
     $this->coreHelper->log("API Users response", self::LOG_NAME, $user);
     if ($user['status'] == 200 && !in_array("test_user", $user['response']['tags'])) {
         $sponsors = ['MLA' => 186172525, 'MLB' => 186175129, 'MLM' => 186175064, 'MCO' => 206959966, 'MLC' => 206959756, 'MLV' => 206960619, 'MPE' => 217178514];
         $countryCode = $user['response']['site_id'];
         if (isset($sponsors[$countryCode])) {
             $sponsorId = $sponsors[$countryCode];
         } else {
             $sponsorId = '';
         }
         $this->coreHelper->log("Sponsor id set", self::LOG_NAME, $sponsorId);
     }
     $this->_saveWebsiteConfig('payment/mercadopago/sponsor_id', $sponsorId);
     $this->coreHelper->log("Sponsor saved", self::LOG_NAME, $sponsorId);
 }
Example #2
0
 /**
  * Check if an applied coupon is valid
  *
  * @param $id
  *
  * @return array
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function validCoupon($id)
 {
     if (!$this->_accessToken) {
         $this->_accessToken = $this->_scopeConfig->getValue(self::XML_PATH_ACCESS_TOKEN, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
     }
     $mp = $this->_coreHelper->getApiInstance($this->_accessToken);
     $params = array("transaction_amount" => $this->getAmount(), "payer_email" => $this->getEmailCustomer(), "coupon_code" => $id);
     $details_discount = $mp->get("/discount_campaigns", $params);
     //add value on return api discount
     $details_discount['response']['transaction_amount'] = $params['transaction_amount'];
     $details_discount['response']['params'] = $params;
     return $details_discount;
 }