/** * @return void * @throws \Exception */ public function execute() { $storeScope = \Magento\Store\Model\ScopeInterface::SCOPE_STORE; $data = $this->getRequest()->getParams(); /* Get temporary credentials from session. */ $request_token = []; $request_token['oauth_token'] = $this->scopeConfig->getValue('sama_twitterfeed/oauth/token', $storeScope); $request_token['oauth_token_secret'] = $this->scopeConfig->getValue('sama_twitterfeed/oauth/token_secret', $storeScope); /* If denied, bail. */ if (isset($data['denied'])) { throw new Exception("Twitter denied permission"); } /* If the oauth_token is not what we expect, bail. */ if (isset($data['oauth_token']) && $request_token['oauth_token'] !== $data['oauth_token']) { throw new Exception("Unexpected Oauth token"); } /* Create TwitteroAuth object with app key/secret and token key/secret from default phase */ $connection = new TwitterOAuth($this->_oAuthkey, $this->_oAuthsecret, $request_token['oauth_token'], $request_token['oauth_token_secret']); /* Request access tokens from twitter */ $access_token = $connection->oauth("oauth/access_token", array("oauth_verifier" => $data['oauth_verifier'])); /* If HTTP response is 200 continue otherwise send to connect page to retry */ if (200 == $connection->getLastHttpCode()) { $this->_objectManager->get('Magento\\Framework\\App\\MutableScopeConfig')->setValue('sama_twitterfeed/oauth/access_token', $access_token); $this->_objectManager->get('Magento\\Framework\\App\\MutableScopeConfig')->setValue('sama_twitterfeed/oauth/token_secret', null); $this->_objectManager->get('Magento\\Framework\\App\\MutableScopeConfig')->setValue('sama_twitterfeed/oauth/token', null); } else { throw new Exception("Twitter Oauth API status code: {$connection->getLastHttpCode()}"); } return; }
/** * @param array $queryParams * @return string */ public function getUrl(array $queryParams = []) { if (!$this->config->getValue('rss/config/active', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)) { return ''; } return $this->urlBuilder->getUrl('rss/feed/index', $queryParams); }
/** * @param \Magento\Sales\Model\Order\Shipment $shipment * @param RequestInterface $request * @return void * @throws \Magento\Framework\Exception\LocalizedException */ public function create(\Magento\Sales\Model\Order\Shipment $shipment, RequestInterface $request) { $order = $shipment->getOrder(); $carrier = $this->carrierFactory->create($order->getShippingMethod(true)->getCarrierCode()); if (!$carrier->isShippingLabelsAvailable()) { throw new \Magento\Framework\Exception\LocalizedException(__('Shipping labels is not available.')); } $shipment->setPackages($request->getParam('packages')); $response = $this->labelFactory->create()->requestToShipment($shipment); if ($response->hasErrors()) { throw new \Magento\Framework\Exception\LocalizedException(__($response->getErrors())); } if (!$response->hasInfo()) { throw new \Magento\Framework\Exception\LocalizedException(__('Response info is not exist.')); } $labelsContent = []; $trackingNumbers = []; $info = $response->getInfo(); foreach ($info as $inf) { if (!empty($inf['tracking_number']) && !empty($inf['label_content'])) { $labelsContent[] = $inf['label_content']; $trackingNumbers[] = $inf['tracking_number']; } } $outputPdf = $this->combineLabelsPdf($labelsContent); $shipment->setShippingLabel($outputPdf->render()); $carrierCode = $carrier->getCarrierCode(); $carrierTitle = $this->scopeConfig->getValue('carriers/' . $carrierCode . '/title', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $shipment->getStoreId()); if (!empty($trackingNumbers)) { $this->addTrackingNumbersToShipment($shipment, $trackingNumbers, $carrierCode, $carrierTitle); } }
/** * Check if RSS feed allowed * * @return bool */ public function isAllowed() { if ($this->config->getValue('rss/order/status', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)) { return true; } return false; }
/** * Check whether status notification is allowed * * @return bool */ public function isStatusNotificationAllow() { if ($this->_scopeConfig->getValue('rss/order/status_notified', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)) { return true; } return false; }
/** * Return whether the host from request is the backend host * @return bool */ public function isHostBackend() { $backendUrl = $this->configInterface->getValue(Store::XML_PATH_UNSECURE_BASE_URL, ScopeInterface::SCOPE_STORE); $backendHost = parse_url(trim($backendUrl), PHP_URL_HOST); $host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : ''; return (strcasecmp($backendHost, $host) === 0); }
/** * Return available payment methods * * @return array */ public function toOptionArray() { $methods = []; //default empty value $methods[] = ["value" => "", "label" => ""]; $accessToken = $this->scopeConfig->getValue(self::XML_PATH_ACCESS_TOKEN, \Magento\Store\Model\ScopeInterface::SCOPE_STORE); $clientId = $this->scopeConfig->getValue(self::XML_PATH_CLIENT_ID, \Magento\Store\Model\ScopeInterface::SCOPE_STORE); $clientSecret = $this->scopeConfig->getValue(self::XML_PATH_CLIENT_SECRET, \Magento\Store\Model\ScopeInterface::SCOPE_STORE); $meHelper = $this->coreHelper; if (empty($accessToken) && !$meHelper->isValidClientCredentials($clientId, $clientSecret)) { return $methods; } //if accessToken is empty uses clientId and clientSecret to obtain it if (empty($accessToken)) { $accessToken = $meHelper->getAccessToken(); } $country = $this->scopeConfig->getValue('payment/mercadopago/country', 'website', $this->_switcher->getWebsiteId()); $meHelper->log("Get payment methods by country... ", 'mercadopago'); $meHelper->log("API payment methods: " . "/v1/payment_methods?access_token=" . $accessToken, 'mercadopago'); $response = \MercadoPago_Core_Lib_RestClient::get('/sites/' . strtoupper($country) . '/payment_methods?marketplace=NONE'); $meHelper->log("API payment methods", 'mercadopago', $response); if (isset($response['error'])) { return $methods; } $response = $response['response']; foreach ($response as $m) { if (isset($m['id']) && $m['id'] != 'account_money') { $methods[] = ['value' => $m['id'], 'label' => __($m['name'])]; } } return $methods; }
/** * {inheritdoc} */ public function create(array $arguments = []) { if (WorkflowType::CLIENT_SIDE_COMPILATION === $this->scopeConfig->getValue(WorkflowType::CONFIG_NAME_PATH)) { return $this->objectManager->create(self::ENTITY_NAME, $arguments); } return $this->chainFactory->create($arguments); }
/** * {inheritdoc} */ public function create(array $arguments = []) { if (WorkflowType::CLIENT_SIDE_COMPILATION === $this->scopeConfig->getValue(WorkflowType::CONFIG_NAME_PATH)) { return $this->_objectManager->create('Magento\\Developer\\Model\\View\\Asset\\PreProcessor\\DeveloperChain', $arguments); } return $this->chainFactory->create($arguments); }
/** * Validate process * * @param \Magento\Framework\DataObject $object * @return bool * @throws \Magento\Framework\Exception\LocalizedException * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ public function validate($object) { $attributeCode = $this->getAttribute()->getName(); $postDataConfig = $object->getData('use_post_data_config') ?: []; $isUseConfig = in_array($attributeCode, $postDataConfig); if ($this->getAttribute()->getIsRequired()) { $attributeValue = $object->getData($attributeCode); if ($this->getAttribute()->isValueEmpty($attributeValue) && !$isUseConfig) { return false; } } if ($this->getAttribute()->getIsUnique()) { if (!$this->getAttribute()->getEntity()->checkAttributeUniqueValue($this->getAttribute(), $object)) { $label = $this->getAttribute()->getFrontend()->getLabel(); throw new \Magento\Framework\Exception\LocalizedException(__('The value of attribute "%1" must be unique.', $label)); } } if ($attributeCode == 'default_sort_by') { $available = $object->getData('available_sort_by') ?: []; $available = is_array($available) ? $available : explode(',', $available); $data = !in_array('default_sort_by', $postDataConfig) ? $object->getData($attributeCode) : $this->_scopeConfig->getValue("catalog/frontend/default_sort_by", \Magento\Store\Model\ScopeInterface::SCOPE_STORE); if (!in_array($data, $available) && !in_array('available_sort_by', $postDataConfig)) { throw new \Magento\Framework\Exception\LocalizedException(__('Default Product Listing Sort by does not exist in Available Product Listing Sort By.')); } } return true; }
/** * Validate data * * @return bool * @throws Exception * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ protected function _validate() { $sessionData = $_SESSION[self::VALIDATOR_KEY]; $validatorData = $this->_getSessionEnvironment(); if ($this->_scopeConfig->getValue(self::XML_PATH_USE_REMOTE_ADDR, $this->_scopeType) && $sessionData[self::VALIDATOR_REMOTE_ADDR_KEY] != $validatorData[self::VALIDATOR_REMOTE_ADDR_KEY]) { throw new Exception('Invalid session ' . self::VALIDATOR_REMOTE_ADDR_KEY . ' value.'); } if ($this->_scopeConfig->getValue(self::XML_PATH_USE_HTTP_VIA, $this->_scopeType) && $sessionData[self::VALIDATOR_HTTP_VIA_KEY] != $validatorData[self::VALIDATOR_HTTP_VIA_KEY]) { throw new Exception('Invalid session ' . self::VALIDATOR_HTTP_VIA_KEY . ' value.'); } $httpXForwardedKey = $sessionData[self::VALIDATOR_HTTP_X_FORWARDED_FOR_KEY]; $validatorXForwarded = $validatorData[self::VALIDATOR_HTTP_X_FORWARDED_FOR_KEY]; if ($this->_scopeConfig->getValue(self::XML_PATH_USE_X_FORWARDED, $this->_scopeType) && $httpXForwardedKey != $validatorXForwarded) { throw new Exception('Invalid session ' . self::VALIDATOR_HTTP_X_FORWARDED_FOR_KEY . ' value.'); } if ($this->_scopeConfig->getValue(self::XML_PATH_USE_USER_AGENT, $this->_scopeType) && $sessionData[self::VALIDATOR_HTTP_USER_AGENT_KEY] != $validatorData[self::VALIDATOR_HTTP_USER_AGENT_KEY]) { foreach ($this->_skippedAgentList as $agent) { if (preg_match('/' . $agent . '/iu', $validatorData[self::VALIDATOR_HTTP_USER_AGENT_KEY])) { return true; } } throw new Exception('Invalid session ' . self::VALIDATOR_HTTP_USER_AGENT_KEY . ' value.'); } return true; }
/** * @return true * @throws Exception */ public function setConfig() { $posId = $this->scopeConfig->getValue(Payupl::XML_PATH_POS_ID, 'store'); if ($posId) { $this->posId = $posId; } else { throw new Exception('POS ID is empty.'); } $keyMd5 = $this->scopeConfig->getValue(Payupl::XML_PATH_KEY_MD5, 'store'); if ($keyMd5) { $this->keyMd5 = $keyMd5; } else { throw new Exception('Key MD5 is empty.'); } $secondKeyMd5 = $this->scopeConfig->getValue(Payupl::XML_PATH_SECOND_KEY_MD5, 'store'); if ($secondKeyMd5) { $this->secondKeyMd5 = $secondKeyMd5; } else { throw new Exception('Second key MD5 is empty.'); } $posAuthKey = $this->scopeConfig->getValue(Payupl::XML_PATH_POS_AUTH_KEY, 'store'); if ($posAuthKey) { $this->posAuthKey = $posAuthKey; } else { throw new Exception('POS auth key is empty.'); } return true; }
/** * {@inheritdoc} */ public function getConfig() { $showHide = []; $enabled = $this->scopeConfiguration->getValue('sr_block_config/general/enabled', ScopeInterface::SCOPE_STORE); $showHide['show_hide_custom_block'] = $enabled ? true : false; return $showHide; }
public function sendNotification($data) { if (!$data) { return false; } $this->inlineTranslation->suspend(); try { $postObject = new \Magento\Framework\DataObject(); $postObject->setData($data); $error = false; $storeScope = \Magento\Store\Model\ScopeInterface::SCOPE_STORE; /* $from = [ 'name' => '', 'email' => '' ];*/ $email_template = $this->scopeConfig->getValue('cadou/email/template'); if (empty($email_template)) { $email_template = (string) 'cadou_email_template'; // this code we have mentioned in the email_templates.xml } $transport = $this->_transportBuilder->setTemplateIdentifier($email_template)->setTemplateOptions(['area' => \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE, 'store' => $this->storeManager->getDefaultStoreView()->getId()])->setTemplateVars(['data' => $postObject, 'subject' => $data['productname']])->setFrom($this->scopeConfig->getValue('contact/email/sender_email_identity', $storeScope))->addTo($data['email'], isset($data['fullname']) ? $data['fullname'] : $data['name'])->getTransport(); $transport->sendMessage(); $this->inlineTranslation->resume(); /*$this->messageManager->addSuccess( __('Thanks for contacting us with your comments and questions. We\'ll respond to you very soon.') );*/ return TRUE; } catch (\Exception $e) { $this->inlineTranslation->resume(); $this->messageManager->addError(__('We can\'t process your request right now. Sorry, that\'s all we know.' . $e->getMessage())); return FALSE; } }
/** * Return Links Section Title for order item * * @return string */ public function getLinksTitle() { if ($this->_purchasedLinks->getLinkSectionTitle()) { return $this->_purchasedLinks->getLinkSectionTitle(); } return $this->_scopeConfig->getValue(\Magento\Downloadable\Model\Link::XML_PATH_LINKS_TITLE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE); }
/** * @param string $currencyFrom * @param string $currencyTo * @param int $retry * @return float|null */ protected function _convert($currencyFrom, $currencyTo, $retry = 0) { $url = str_replace('{{CURRENCY_FROM}}', $currencyFrom, self::CURRENCY_CONVERTER_URL); $url = str_replace('{{CURRENCY_TO}}', $currencyTo, $url); try { sleep($this->_scopeConfig->getValue('currency/google/delay', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)); $response = $this->_httpClient->setUri($url)->setConfig(['timeout' => $this->_scopeConfig->getValue('currency/google/timeout', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)])->request('GET')->getBody(); $data = explode('bld>', $response); if (empty($data[1])) { $this->_messages[] = __('We can\'t retrieve a rate from %1.', $url); return null; } $data = explode($currencyTo, $data[1]); $rate = null; if (empty($data[0])) { $this->_messages[] = __('We can\'t retrieve a rate from %1.', $url); return null; } else { $rate = $data[0]; } return (double) $rate; } catch (\Exception $e) { if ($retry == 0) { $this->_convert($currencyFrom, $currencyTo, 1); } else { $this->_messages[] = __('We can\'t retrieve a rate from %1.', $url); } } }
/** * Retrieve information from payment configuration * * @param string $field * @param int|null $storeId * * @return mixed */ public function getValue($field, $storeId = null) { if ($this->methodCode === null || $this->pathPattern === null) { return null; } return $this->scopeConfig->getValue(sprintf($this->pathPattern, $this->methodCode, $field), ScopeInterface::SCOPE_STORE, $storeId); }
/** * Get partial payment maximal percent (0.00-1.00) * * @return float */ public function getWalletPartialPercent() { $result = $this->_scopeConfig->getValue('payment/praxigento_wallet/partial_percent'); $result *= 1; $result = $result < 0 || $result > 1 ? 0 : $result; return $result; }
/** * Return saved storage code * * @return int */ public function getCurrentStorageCode() { if (is_null($this->_currentStorage)) { $this->_currentStorage = (int) $this->config->getValue(\Magento\Core\Model\File\Storage::XML_PATH_STORAGE_MEDIA, 'default'); } return $this->_currentStorage; }
/** * @param mixed $schedule * @return void * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function scheduledUpdateCurrencyRates($schedule) { $importWarnings = []; if (!$this->_scopeConfig->getValue(self::IMPORT_ENABLE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE) || !$this->_scopeConfig->getValue(self::CRON_STRING_PATH, \Magento\Store\Model\ScopeInterface::SCOPE_STORE)) { return; } $errors = []; $rates = []; $service = $this->_scopeConfig->getValue(self::IMPORT_SERVICE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE); if ($service) { try { $importModel = $this->_importFactory->create($service); $rates = $importModel->fetchRates(); $errors = $importModel->getMessages(); } catch (\Exception $e) { $importWarnings[] = __('FATAL ERROR:') . ' ' . __('We can\'t initialize the import model.'); } } else { $importWarnings[] = __('FATAL ERROR:') . ' ' . __('Please specify the correct Import Service.'); } if (sizeof($errors) > 0) { foreach ($errors as $error) { $importWarnings[] = __('WARNING:') . ' ' . $error; } } if (sizeof($importWarnings) == 0) { $this->_currencyFactory->create()->saveRates($rates); } else { $this->inlineTranslation->suspend(); $this->_transportBuilder->setTemplateIdentifier($this->_scopeConfig->getValue(self::XML_PATH_ERROR_TEMPLATE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE))->setTemplateOptions(['area' => \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE, 'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID])->setTemplateVars(['warnings' => join("\n", $importWarnings)])->setFrom($this->_scopeConfig->getValue(self::XML_PATH_ERROR_IDENTITY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE))->addTo($this->_scopeConfig->getValue(self::XML_PATH_ERROR_RECIPIENT, \Magento\Store\Model\ScopeInterface::SCOPE_STORE)); $transport = $this->_transportBuilder->getTransport(); $transport->sendMessage(); $this->inlineTranslation->resume(); } }
/** * Get url for config settings where base url option can be changed * * @return string */ protected function _getConfigUrl() { $output = ''; $defaultUnsecure = $this->_config->getValue(\Magento\Store\Model\Store::XML_PATH_UNSECURE_BASE_URL, 'default'); $defaultSecure = $this->_config->getValue(\Magento\Store\Model\Store::XML_PATH_SECURE_BASE_URL, 'default'); if ($defaultSecure == \Magento\Store\Model\Store::BASE_URL_PLACEHOLDER || $defaultUnsecure == \Magento\Store\Model\Store::BASE_URL_PLACEHOLDER) { $output = $this->_urlBuilder->getUrl('adminhtml/system_config/edit', array('section' => 'web')); } else { /** @var $dataCollection \Magento\Core\Model\Resource\Config\Data\Collection */ $dataCollection = $this->_configValueFactory->create()->getCollection(); $dataCollection->addValueFilter(\Magento\Store\Model\Store::BASE_URL_PLACEHOLDER); /** @var $data \Magento\Framework\App\Config\ValueInterface */ foreach ($dataCollection as $data) { if ($data->getScope() == 'stores') { $code = $this->_storeManager->getStore($data->getScopeId())->getCode(); $output = $this->_urlBuilder->getUrl('adminhtml/system_config/edit', array('section' => 'web', 'store' => $code)); break; } elseif ($data->getScope() == 'websites') { $code = $this->_storeManager->getWebsite($data->getScopeId())->getCode(); $output = $this->_urlBuilder->getUrl('adminhtml/system_config/edit', array('section' => 'web', 'website' => $code)); break; } } } return $output; }
/** * Set status of link * * @param \Magento\Framework\Event\Observer $observer * @return $this * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function execute(\Magento\Framework\Event\Observer $observer) { $order = $observer->getEvent()->getOrder(); if (!$order->getId()) { //order not saved in the database return $this; } /* @var $order \Magento\Sales\Model\Order */ $status = ''; $linkStatuses = ['pending' => \Magento\Downloadable\Model\Link\Purchased\Item::LINK_STATUS_PENDING, 'expired' => \Magento\Downloadable\Model\Link\Purchased\Item::LINK_STATUS_EXPIRED, 'avail' => \Magento\Downloadable\Model\Link\Purchased\Item::LINK_STATUS_AVAILABLE, 'payment_pending' => \Magento\Downloadable\Model\Link\Purchased\Item::LINK_STATUS_PENDING_PAYMENT, 'payment_review' => \Magento\Downloadable\Model\Link\Purchased\Item::LINK_STATUS_PAYMENT_REVIEW]; $downloadableItemsStatuses = []; $orderItemStatusToEnable = $this->_scopeConfig->getValue(\Magento\Downloadable\Model\Link\Purchased\Item::XML_PATH_ORDER_ITEM_STATUS, ScopeInterface::SCOPE_STORE, $order->getStoreId()); if ($order->getState() == \Magento\Sales\Model\Order::STATE_HOLDED) { $status = $linkStatuses['pending']; } elseif ($order->isCanceled() || $order->getState() == \Magento\Sales\Model\Order::STATE_CLOSED || $order->getState() == \Magento\Sales\Model\Order::STATE_COMPLETE) { $expiredStatuses = [\Magento\Sales\Model\Order\Item::STATUS_CANCELED, \Magento\Sales\Model\Order\Item::STATUS_REFUNDED]; foreach ($order->getAllItems() as $item) { if ($item->getProductType() == \Magento\Downloadable\Model\Product\Type::TYPE_DOWNLOADABLE || $item->getRealProductType() == \Magento\Downloadable\Model\Product\Type::TYPE_DOWNLOADABLE) { if (in_array($item->getStatusId(), $expiredStatuses)) { $downloadableItemsStatuses[$item->getId()] = $linkStatuses['expired']; } else { $downloadableItemsStatuses[$item->getId()] = $linkStatuses['avail']; } } } } elseif ($order->getState() == \Magento\Sales\Model\Order::STATE_PENDING_PAYMENT) { $status = $linkStatuses['payment_pending']; } elseif ($order->getState() == \Magento\Sales\Model\Order::STATE_PAYMENT_REVIEW) { $status = $linkStatuses['payment_review']; } else { $availableStatuses = [$orderItemStatusToEnable, \Magento\Sales\Model\Order\Item::STATUS_INVOICED]; foreach ($order->getAllItems() as $item) { if ($item->getProductType() == \Magento\Downloadable\Model\Product\Type::TYPE_DOWNLOADABLE || $item->getRealProductType() == \Magento\Downloadable\Model\Product\Type::TYPE_DOWNLOADABLE) { if ($item->getStatusId() == \Magento\Sales\Model\Order\Item::STATUS_BACKORDERED && $orderItemStatusToEnable == \Magento\Sales\Model\Order\Item::STATUS_PENDING && !in_array(\Magento\Sales\Model\Order\Item::STATUS_BACKORDERED, $availableStatuses, true)) { $availableStatuses[] = \Magento\Sales\Model\Order\Item::STATUS_BACKORDERED; } if (in_array($item->getStatusId(), $availableStatuses)) { $downloadableItemsStatuses[$item->getId()] = $linkStatuses['avail']; } } } } if (!$downloadableItemsStatuses && $status) { foreach ($order->getAllItems() as $item) { if ($item->getProductType() == \Magento\Downloadable\Model\Product\Type::TYPE_DOWNLOADABLE || $item->getRealProductType() == \Magento\Downloadable\Model\Product\Type::TYPE_DOWNLOADABLE) { $downloadableItemsStatuses[$item->getId()] = $status; } } } if ($downloadableItemsStatuses) { $linkPurchased = $this->_createItemsCollection()->addFieldToFilter('order_item_id', ['in' => array_keys($downloadableItemsStatuses)]); foreach ($linkPurchased as $link) { if ($link->getStatus() != $linkStatuses['expired'] && !empty($downloadableItemsStatuses[$link->getOrderItemId()])) { $link->setStatus($downloadableItemsStatuses[$link->getOrderItemId()])->save(); } } } return $this; }
/** * Receives webhook events from Roadrunner */ public function execute() { $this->_logger->addDebug('paystandmagento/webhook/paystand endpoint was hit'); $body = @file_get_contents('php://input'); $json = json_decode($body); $this->_logger->addDebug(">>>>> body=" . print_r($body, TRUE)); if (isset($json->resource->meta->source) && $json->resource->meta->source == "magento 2") { $quoteId = $json->resource->meta->quote; $this->_logger->addDebug('magento 2 webhook identified with quote id = ' . $quoteId); $this->_order->loadByAttribute('quote_id', $quoteId); if (!empty($this->_order->getIncrementId())) { $this->_logger->addDebug('current order increment id = ' . $this->_order->getIncrementId()); $state = $this->_order->getState(); $this->_logger->addDebug('current order state = ' . $state); $status = $this->_order->getStatus(); $this->_logger->addDebug('current order status = ' . $status); $storeScope = \Magento\Store\Model\ScopeInterface::SCOPE_STORE; if ($this->scopeConfig->getValue(self::USE_SANDBOX, $storeScope)) { $base_url = 'https://api.paystand.co/v3'; } else { $base_url = 'https://api.paystand.com/v3'; } $url = $base_url . "/events/" . $json->id . "/verify"; $auth_header = array("x-publishable-key: " . $this->scopeConfig->getValue(self::PUBLISHABLE_KEY, $storeScope)); $curl = $this->buildCurl("POST", $url, json_encode($json), $auth_header); $response = $this->runCurl($curl); $this->_logger->addDebug("http_response_code is " . $this->http_response_code); if (FALSE !== $response && $this->http_response_code == 200) { if ($json->resource->object = "payment") { switch ($json->resource->status) { case 'posted': $state = 'pending'; $status = 'pending'; break; case 'paid': $state = 'processing'; $status = 'processing'; break; case 'failed': $state = 'closed'; $status = 'closed'; break; case 'canceled': $state = 'canceled'; $status = 'canceled'; break; } } $this->_order->setState($state); $this->_order->setStatus($status); $this->_order->save(); $this->_logger->addDebug('new order state = ' . $state); $this->_logger->addDebug('new order status = ' . $status); } else { $this->_logger->addDebug('event verify failed'); } } } }
/** * Retrieve connection name saved at config * * @return string */ public function getConfigConnectionName() { $connectionName = $this->_configuration->getValue(\Magento\MediaStorage\Model\File\Storage::XML_PATH_STORAGE_MEDIA_DATABASE, 'default'); if (empty($connectionName)) { $connectionName = self::CONNECTION_DEFAULT; } return $connectionName; }
/** * Set status 'invalidate' for blocks and other output caches * * @return $this */ public function afterSave() { $types = array_keys($this->_scopeConfig->getValue(self::XML_PATH_INVALID_CACHES, \Magento\Store\Model\ScopeInterface::SCOPE_STORE)); if ($this->isValueChanged()) { $this->_cacheTypeList->invalidate($types); } return $this; }
/** * Check if secure URLs are enabled. * * @param \Magento\Framework\Url\SecurityInfo $subject * @param callable $proceed * @param string $url * @return bool * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function aroundIsSecure(\Magento\Framework\Url\SecurityInfo $subject, \Closure $proceed, $url) { if ($this->scopeConfig->getValue(Store::XML_PATH_SECURE_IN_FRONTEND, StoreScopeInterface::SCOPE_STORE)) { return $proceed($url); } else { return false; } }
/** * Return key sorted shop item categories * @return array */ public function toOptionArray() { $country = $this->scopeConfig->getValue('payment/mercadopago/country'); if ($this->_countryOptions[$country]) { return $this->_countryOptions[$country]; } return null; }
/** * Retrieve connection name saved at config * * @return string */ public function getConfigConnectionName() { $connectionName = $this->_configuration->getValue(\Magento\Core\Model\File\Storage::XML_PATH_STORAGE_MEDIA_DATABASE, 'default'); if (empty($connectionName)) { $connectionName = 'default_setup'; } return $connectionName; }
/** * @inheritdoc */ protected function generateRelatedFile($relatedFileId, LocalInterface $asset) { $relatedAsset = parent::generateRelatedFile($relatedFileId, $asset); if ($this->hasRelatedPublishing || WorkflowType::CLIENT_SIDE_COMPILATION === $this->scopeConfig->getValue(WorkflowType::CONFIG_NAME_PATH)) { $this->assetPublisher->publish($relatedAsset); } return $relatedAsset; }
/** * Return config var * * @param string $key Var path key * @param int $storeId Store View Id * @return mixed */ public function getConfigData($key, $storeId = null) { if (!isset($this->_config[$key][$storeId])) { $value = $this->_scopeConfig->getValue('google/googleshopping/' . $key, \Magento\Framework\Store\ScopeInterface::SCOPE_STORE, $storeId); $this->_config[$key][$storeId] = $value; } return $this->_config[$key][$storeId]; }