Example #1
0
 /**
  * Post request into gateway
  *
  * @param DataObject $request
  * @param ConfigInterface $config
  *
  * @return DataObject
  * @throws \Zend_Http_Client_Exception
  */
 public function postRequest(DataObject $request, ConfigInterface $config)
 {
     $result = new DataObject();
     $clientConfig = ['maxredirects' => 5, 'timeout' => 30, 'verifypeer' => $config->getValue('verify_peer')];
     if ($config->getValue('use_proxy')) {
         $clientConfig['proxy'] = $config->getValue('proxy_host') . ':' . $config->getValue('proxy_port');
         $clientConfig['httpproxytunnel'] = true;
         $clientConfig['proxytype'] = CURLPROXY_HTTP;
     }
     /** @var ZendClient $client */
     $client = $this->httpClientFactory->create();
     $client->setUri((bool) $config->getValue('sandbox_flag') ? $config->getValue('transaction_url_test_mode') : $config->getValue('transaction_url'));
     $client->setConfig($clientConfig);
     $client->setMethod(\Zend_Http_Client::POST);
     $client->setParameterPost($request->getData());
     $client->setHeaders(['X-VPS-VIT-CLIENT-CERTIFICATION-ID' => '33baf5893fc2123d8b191d2d011b7fdc', 'X-VPS-Request-ID' => $this->mathRandom->getUniqueHash(), 'X-VPS-CLIENT-TIMEOUT' => 45]);
     $client->setUrlEncodeBody(false);
     try {
         $response = $client->request();
         $responseArray = [];
         parse_str(strstr($response->getBody(), 'RESULT'), $responseArray);
         $result->setData(array_change_key_case($responseArray, CASE_LOWER));
         $result->setData('result_code', $result->getData('result'));
     } catch (\Zend_Http_Client_Exception $e) {
         $result->addData(['response_code' => -1, 'response_reason_code' => $e->getCode(), 'response_reason_text' => $e->getMessage()]);
         throw $e;
     } finally {
         $this->logger->debug(['request' => $request->getData(), 'result' => $result->getData()], (array) $config->getValue('getDebugReplacePrivateDataKeys'), (bool) $config->getValue('debug'));
     }
     return $result;
 }
Example #2
0
 /**
  * Encode value to be used in \Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray
  *
  * @param array $value
  * @return array
  */
 protected function encodeArrayFieldValue(array $value)
 {
     $result = [];
     foreach ($value as $country => $creditCardType) {
         $resultId = $this->mathRandom->getUniqueHash('_');
         $result[$resultId] = ['country_id' => $country, 'cc_types' => $creditCardType];
     }
     return $result;
 }
Example #3
0
 /**
  * Render the chooser HTML
  * Target element should be set.
  *
  * @return string
  */
 protected function _toHtml()
 {
     if (empty($this->_targetElementId)) {
         return '';
     }
     $idSuffix = $this->mathRandom->getUniqueHash();
     /** @var \Magento\Framework\Data\Form $form */
     $form = $this->_formFactory->create();
     $dateFields = array('from' => __('From'), 'to' => __('To'));
     foreach ($dateFields as $key => $label) {
         $form->addField("{$key}_{$idSuffix}", 'date', array('format' => \Magento\Framework\Stdlib\DateTime::DATE_INTERNAL_FORMAT, 'label' => $label, 'image' => $this->getViewFileUrl('images/grid-cal.gif'), 'onchange' => "dateTimeChoose_{$idSuffix}()", 'value' => $this->_rangeValues[$key]));
     }
     return $form->toHtml() . "<script type=\"text/javascript\">\n            dateTimeChoose_{$idSuffix} = function() {\n                \$('{$this->_targetElementId}').value = " . "\$('from_{$idSuffix}').value + '{$this->_rangeDelimiter}' + \$('to_{$idSuffix}').value;\n            };\n            </script>";
 }
Example #4
0
 /**
  * Generate layout update xml
  *
  * @param string $container
  * @param string $templatePath
  * @return string
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function generateLayoutUpdateXml($container, $templatePath = '')
 {
     $templateFilename = $this->_viewFileSystem->getTemplateFileName($templatePath, ['area' => $this->getArea(), 'themeId' => $this->getThemeId(), 'module' => \Magento\Framework\View\Element\AbstractBlock::extractModuleName($this->getType())]);
     if (!$this->getId() && !$this->isCompleteToCreate() || $templatePath && !is_readable($templateFilename)) {
         return '';
     }
     $parameters = $this->getWidgetParameters();
     $xml = '<body><referenceContainer name="' . $container . '">';
     $template = '';
     if (isset($parameters['template'])) {
         unset($parameters['template']);
     }
     if ($templatePath) {
         $template = ' template="' . $templatePath . '"';
     }
     $hash = $this->mathRandom->getUniqueHash();
     $xml .= '<block class="' . $this->getType() . '" name="' . $hash . '"' . $template . '>';
     foreach ($parameters as $name => $value) {
         if ($name == 'conditions') {
             $name = 'conditions_encoded';
             $value = $this->conditionsHelper->encode($value);
         } elseif (is_array($value)) {
             $value = implode(',', $value);
         }
         if ($name && strlen((string) $value)) {
             $xml .= '<action method="setData">' . '<argument name="name" xsi:type="string">' . $name . '</argument>' . '<argument name="value" xsi:type="string">' . $this->_escaper->escapeHtml($value) . '</argument>' . '</action>';
         }
     }
     $xml .= '</block></referenceContainer></body>';
     return $xml;
 }
Example #5
0
 /**
  * Encode value to be used in \Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray
  *
  * @param array $value
  * @return array
  */
 protected function encodeArrayFieldValue(array $value)
 {
     $result = [];
     // first combine the ccTypes together
     $list = [];
     foreach ($value as $ccType => $items) {
         // sort on amount
         ksort($items);
         foreach ($items as $amount => $installment) {
             if (!isset($list[$installment][$amount])) {
                 $list[$installment][$amount] = [$ccType];
             } else {
                 $ccTypes = $list[$installment][$amount];
                 $ccTypes[] = $ccType;
                 $list[$installment][$amount] = $ccTypes;
             }
         }
     }
     // loop through combined ccTypes configuration and pre fill the items
     foreach ($list as $installment => $amounts) {
         foreach ($amounts as $amount => $ccTypes) {
             $resultId = $this->mathRandom->getUniqueHash('_');
             $result[$resultId] = ['amount' => $amount, 'cc_types' => $ccTypes, 'installments' => $installment];
         }
     }
     return $result;
 }
Example #6
0
 /**
  * @return \Magento\Framework\View\Element\AbstractBlock
  */
 protected function _beforeToHtml()
 {
     $result = parent::_beforeToHtml();
     /** @var \Magento\Paypal\Model\Config $config */
     $config = $this->_paypalConfigFactory->create();
     $config->setMethod($this->_paymentMethodCode);
     $isInCatalog = $this->getIsInCatalogProduct();
     if (!$this->_shortcutValidator->validate($this->_paymentMethodCode, $isInCatalog)) {
         $this->_shouldRender = false;
         return $result;
     }
     $quote = $isInCatalog || !$this->_checkoutSession ? null : $this->_checkoutSession->getQuote();
     // set misc data
     $this->setShortcutHtmlId($this->_mathRandom->getUniqueHash('ec_shortcut_'))->setCheckoutUrl($this->getUrl($this->_startAction));
     // use static image if in catalog
     if ($isInCatalog || null === $quote) {
         $this->setImageUrl($config->getExpressCheckoutShortcutImageUrl($this->_localeResolver->getLocale()));
     } else {
         /**@todo refactor checkout model. Move getCheckoutShortcutImageUrl to helper or separate model */
         $parameters = ['params' => ['quote' => $quote, 'config' => $config]];
         $checkoutModel = $this->_checkoutFactory->create($this->_checkoutType, $parameters);
         $this->setImageUrl($checkoutModel->getCheckoutShortcutImageUrl());
     }
     // ask whether to create a billing agreement
     $customerId = $this->currentCustomer->getCustomerId();
     // potential issue for caching
     if ($this->_paypalData->shouldAskToCreateBillingAgreement($config, $customerId)) {
         $this->setConfirmationUrl($this->getUrl($this->_startAction, [\Magento\Paypal\Model\Express\Checkout::PAYMENT_INFO_TRANSPORT_BILLING_AGREEMENT => 1]));
         $this->setConfirmationMessage(__('Would you like to sign a billing agreement to streamline further purchases with PayPal?'));
     }
     return $result;
 }
Example #7
0
 /**
  * Get the Secure Token from Paypal for TR
  *
  * @param Quote $quote
  *
  * @return DataObject
  * @throws \Exception
  */
 public function requestToken(Quote $quote)
 {
     $request = $this->transparent->buildBasicRequest();
     $request->setTrxtype(Payflowpro::TRXTYPE_AUTH_ONLY);
     $request->setVerbosity('HIGH');
     $request->setAmt(0);
     $request->setCreatesecuretoken('Y');
     $request->setSecuretokenid($this->mathRandom->getUniqueHash());
     $request->setReturnurl($this->url->getUrl('paypal/transparent/response'));
     $request->setErrorurl($this->url->getUrl('paypal/transparent/response'));
     $request->setCancelurl($this->url->getUrl('paypal/transparent/cancel'));
     $request->setDisablereceipt('TRUE');
     $request->setSilenttran('TRUE');
     $this->transparent->fillCustomerContacts($quote, $request);
     $result = $this->transparent->postRequest($request, $this->transparent->getConfig());
     return $result;
 }
Example #8
0
 /**
  * Encode value to be used in \Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray
  *
  * @param array $value
  * @return array
  */
 protected function encodeArrayFieldValue(array $value)
 {
     $result = [];
     foreach ($value as $groupId => $qty) {
         $resultId = $this->mathRandom->getUniqueHash('_');
         $result[$resultId] = ['customer_group_id' => $groupId, 'min_sale_qty' => $this->fixQty($qty)];
     }
     return $result;
 }
Example #9
0
 /**
  * @return string
  */
 protected function _toHtml()
 {
     $standard = $this->_paypalStandardFactory->create();
     $form = $this->_formFactory->create();
     $form->setAction($standard->getConfig()->getPaypalUrl())->setId('paypal_standard_checkout')->setName('paypal_standard_checkout')->setMethod('POST')->setUseContainer(true);
     foreach ($standard->getStandardCheckoutFormFields() as $field => $value) {
         $form->addField($field, 'hidden', array('name' => $field, 'value' => $value));
     }
     $idSuffix = $this->mathRandom->getUniqueHash();
     $submitButton = $this->_elementFactory->create('submit', array('data' => array('value' => __('Click here if you are not redirected within 10 seconds.'))));
     $id = "submit_to_paypal_button_{$idSuffix}";
     $submitButton->setId($id);
     $form->addElement($submitButton);
     $html = '<html><body>';
     $html .= __('You will be redirected to the PayPal website in a few seconds.');
     $html .= $form->toHtml();
     $html .= '<script type="text/javascript">document.getElementById("paypal_standard_checkout").submit();';
     $html .= '</script></body></html>';
     return $html;
 }
Example #10
0
 /**
  * @return string
  */
 public function getHtml()
 {
     $htmlId = $this->mathRandom->getUniqueHash($this->_getHtmlId());
     $format = $this->_localeDate->getDateFormat(\IntlDateFormatter::SHORT);
     $html = '<div class="range" id="' . $htmlId . '_range"><div class="range-line date">' . '<input type="text" name="' . $this->_getHtmlName() . '[from]" id="' . $htmlId . '_from"' . ' value="' . $this->getEscapedValue('from') . '" class="admin__control-text input-text no-changes" placeholder="' . __('From') . '" ' . $this->getUiId('filter', $this->_getHtmlName(), 'from') . '/>' . '</div>';
     $html .= '<div class="range-line date">' . '<input type="text" name="' . $this->_getHtmlName() . '[to]" id="' . $htmlId . '_to"' . ' value="' . $this->getEscapedValue('to') . '" class="input-text admin__control-text no-changes" placeholder="' . __('To') . '" ' . $this->getUiId('filter', $this->_getHtmlName(), 'to') . '/>' . '</div></div>';
     $html .= '<input type="hidden" name="' . $this->_getHtmlName() . '[locale]"' . ' value="' . $this->localeResolver->getLocale() . '"/>';
     $html .= '<script>
         require(["jquery", "mage/calendar"], function($){
             $("#' . $htmlId . '_range").dateRange({
                 dateFormat: "' . $format . '",
                     buttonText: "' . $this->escapeHtml(__('Date selector')) . '",
                 from: {
                     id: "' . $htmlId . '_from"
                 },
                 to: {
                     id: "' . $htmlId . '_to"
                 }
             })
         });
     </script>';
     return $html;
 }
Example #11
0
 /**
  * @return string
  */
 public function getHtml()
 {
     $htmlId = $this->mathRandom->getUniqueHash($this->_getHtmlId());
     $format = $this->_localeDate->getDateFormat(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT);
     $html = '<div class="range" id="' . $htmlId . '_range"><div class="range-line date">' . '<input type="text" name="' . $this->_getHtmlName() . '[from]" id="' . $htmlId . '_from"' . ' value="' . $this->getEscapedValue('from') . '" class="input-text no-changes" placeholder="' . __('From') . '" ' . $this->getUiId('filter', $this->_getHtmlName(), 'from') . '/>' . '</div>';
     $html .= '<div class="range-line date">' . '<input type="text" name="' . $this->_getHtmlName() . '[to]" id="' . $htmlId . '_to"' . ' value="' . $this->getEscapedValue('to') . '" class="input-text no-changes" placeholder="' . __('To') . '" ' . $this->getUiId('filter', $this->_getHtmlName(), 'to') . '/>' . '</div></div>';
     $html .= '<input type="hidden" name="' . $this->_getHtmlName() . '[locale]"' . ' value="' . $this->_localeResolver->getLocaleCode() . '"/>';
     $html .= '<script type="text/javascript">
         require(["jquery", "mage/calendar"], function($){
             $("#' . $htmlId . '_range").dateRange({
                 dateFormat: "' . $format . '",
                 buttonImage: "' . $this->getViewFileUrl('images/grid-cal.gif') . '",
                     buttonText: "' . $this->escapeHtml(__('Date selector')) . '",
                 from: {
                     id: "' . $htmlId . '_from"
                 },
                 to: {
                     id: "' . $htmlId . '_to"
                 }
             })
         });
     </script>';
     return $html;
 }
Example #12
0
 /**
  * @return \Magento\Framework\View\Element\AbstractBlock
  */
 protected function _beforeToHtml()
 {
     $result = parent::_beforeToHtml();
     $isInCatalog = $this->getIsInCatalogProduct();
     if (!$this->_shortcutValidator->validate($this->_paymentMethodCode, $isInCatalog)) {
         $this->_shouldRender = false;
         return $result;
     }
     /** @var \Magento\Paypal\Model\Express $method */
     $method = $this->_paymentData->getMethodInstance($this->_bmlMethodCode);
     if (!$method->isAvailable()) {
         $this->_shouldRender = false;
         return $result;
     }
     $this->setShortcutHtmlId($this->_mathRandom->getUniqueHash('ec_shortcut_bml_'))->setCheckoutUrl($this->getUrl($this->_startAction))->setImageUrl(self::SHORTCUT_IMAGE)->setAdditionalLinkImage(['href' => 'https://www.securecheckout.billmelater.com/paycapture-content/' . 'fetch?hash=AU826TU8&content=/bmlweb/ppwpsiw.html', 'src' => 'https://www.paypalobjects.com/webstatic/en_US/btn/btn_bml_text.png']);
     return $result;
 }
Example #13
0
 /**
  * @return \Magento\Framework\View\Element\AbstractBlock
  */
 protected function _beforeToHtml()
 {
     $result = parent::_beforeToHtml();
     $isInCatalog = $this->getIsInCatalogProduct();
     if (!$this->_shortcutValidator->validate($this->_paymentMethodCode, $isInCatalog)) {
         $this->_shouldRender = false;
         return $result;
     }
     $quote = $isInCatalog || !$this->_checkoutSession ? null : $this->_checkoutSession->getQuote();
     // set misc data
     $this->setShortcutHtmlId($this->_mathRandom->getUniqueHash('ec_shortcut_'))->setCheckoutUrl($this->getUrl($this->_startAction));
     // use static image if in catalog
     if ($isInCatalog || null === $quote) {
         $this->setImageUrl($this->config->getExpressCheckoutShortcutImageUrl($this->_localeResolver->getLocale()));
     } else {
         /**@todo refactor checkout model. Move getCheckoutShortcutImageUrl to helper or separate model */
         $parameters = ['params' => ['quote' => $quote, 'config' => $this->config]];
         $checkoutModel = $this->_checkoutFactory->create($this->_checkoutType, $parameters);
         $this->setImageUrl($checkoutModel->getCheckoutShortcutImageUrl());
     }
     return $result;
 }
Example #14
0
 /**
  * Build request for getting token
  *
  * @param \Magento\Sales\Model\Order\Payment $payment
  * @return \Magento\Framework\DataObject
  */
 protected function _buildTokenRequest(\Magento\Sales\Model\Order\Payment $payment)
 {
     $request = $this->buildBasicRequest();
     $request->setCreatesecuretoken('Y')->setSecuretokenid($this->mathRandom->getUniqueHash())->setTrxtype($this->_getTrxTokenType());
     $order = $payment->getOrder();
     $request->setAmt(sprintf('%.2F', $order->getBaseTotalDue()))->setCurrency($order->getBaseCurrencyCode());
     $this->addRequestOrderInfo($request, $order);
     $request = $this->fillCustomerContacts($order, $request);
     //pass store Id to request
     $request->setData('USER1', $order->getStoreId());
     $request->setData('USER2', $this->_getSecureSilentPostHash($payment));
     return $request;
 }
Example #15
0
 /**
  * Generates random code for subscription confirmation
  *
  * @return string
  */
 protected function _generateRandomCode()
 {
     return $this->mathRandom->getUniqueHash();
 }
Example #16
0
 /**
  * Generate unique token for reset password confirmation link
  *
  * @return string
  */
 public function generateResetPasswordLinkToken()
 {
     return $this->mathRandom->getUniqueHash();
 }
Example #17
0
 /**
  * Retrieve sharing code (random string)
  *
  * @return string
  */
 protected function _getSharingRandomCode()
 {
     return $this->mathRandom->getUniqueHash();
 }
 /**
  * {@inheritdoc}
  */
 public function createCustomerWithPasswordHash(\Magento\Customer\Service\V1\Data\CustomerDetails $customerDetails, $hash, $redirectUrl = '')
 {
     $customer = $customerDetails->getCustomer();
     // This logic allows an existing customer to be added to a different store.  No new account is created.
     // The plan is to move this logic into a new method called something like 'registerAccountWithStore'
     if ($customer->getId()) {
         $customerModel = $this->customerRegistry->retrieve($customer->getId());
         $websiteId = $customerModel->getWebsiteId();
         if ($this->isCustomerInStore($websiteId, $customer->getStoreId())) {
             throw new InputException('Customer already exists in this store.');
         }
         // Reuse existing password
         $hash = $this->converter->getCustomerModel($customer->getId())->getPasswordHash();
     }
     // Make sure we have a storeId to associate this customer with.
     if (!$customer->getStoreId()) {
         if ($customer->getWebsiteId()) {
             $storeId = $this->storeManager->getWebsite($customer->getWebsiteId())->getDefaultStore()->getId();
         } else {
             $storeId = $this->storeManager->getStore()->getId();
         }
         $customer = $this->customerBuilder->populate($customer)->setStoreId($storeId)->create();
     }
     try {
         $customerId = $this->saveCustomer($customer, $hash);
     } catch (\Magento\Customer\Exception $e) {
         if ($e->getCode() === CustomerModel::EXCEPTION_EMAIL_EXISTS) {
             throw new InputMismatchException('Customer with the same email already exists in associated website.');
         }
         throw $e;
     }
     $this->customerAddressService->saveAddresses($customerId, $customerDetails->getAddresses());
     $customerModel = $this->customerRegistry->retrieve($customerId);
     $newLinkToken = $this->mathRandom->getUniqueHash();
     $customerModel->changeResetPasswordLinkToken($newLinkToken);
     $this->_sendEmailConfirmation($customerModel, $customer, $redirectUrl);
     return $this->converter->createCustomerFromModel($customerModel);
 }
Example #19
0
 /**
  * Generate Request ID
  *
  * @return string
  */
 protected function getRequestId()
 {
     return $this->mathRandom->getUniqueHash();
 }
Example #20
0
 /**
  * Initialize quote identifier before save
  *
  * @return $this
  */
 public function beforeSave()
 {
     parent::beforeSave();
     $this->setMaskedId($this->randomDataGenerator->getUniqueHash());
     return $this;
 }
 /**
  * {@inheritdoc}
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function createAccountWithPasswordHash(CustomerInterface $customer, $hash, $redirectUrl = '')
 {
     // This logic allows an existing customer to be added to a different store.  No new account is created.
     // The plan is to move this logic into a new method called something like 'registerAccountWithStore'
     if ($customer->getId()) {
         $customer = $this->customerRepository->get($customer->getEmail());
         $websiteId = $customer->getWebsiteId();
         if ($this->isCustomerInStore($websiteId, $customer->getStoreId())) {
             throw new InputException(__('This customer already exists in this store.'));
         }
         // Existing password hash will be used from secured customer data registry when saving customer
     }
     // Make sure we have a storeId to associate this customer with.
     if (!$customer->getStoreId()) {
         if ($customer->getWebsiteId()) {
             $storeId = $this->storeManager->getWebsite($customer->getWebsiteId())->getDefaultStore()->getId();
         } else {
             $storeId = $this->storeManager->getStore()->getId();
         }
         $customer->setStoreId($storeId);
     }
     // Update 'created_in' value with actual store name
     if ($customer->getId() === null) {
         $storeName = $this->storeManager->getStore($customer->getStoreId())->getName();
         $customer->setCreatedIn($storeName);
     }
     $customerAddresses = $customer->getAddresses() ?: [];
     $customer->setAddresses(null);
     try {
         // If customer exists existing hash will be used by Repository
         $customer = $this->customerRepository->save($customer, $hash);
     } catch (AlreadyExistsException $e) {
         throw new InputMismatchException(__('A customer with the same email already exists in an associated website.'));
     } catch (LocalizedException $e) {
         throw $e;
     }
     try {
         foreach ($customerAddresses as $address) {
             $address->setCustomerId($customer->getId());
             $this->addressRepository->save($address);
         }
     } catch (InputException $e) {
         $this->customerRepository->delete($customer);
         throw $e;
     }
     $customer = $this->customerRepository->getById($customer->getId());
     $newLinkToken = $this->mathRandom->getUniqueHash();
     $this->changeResetPasswordLinkToken($customer, $newLinkToken);
     $this->sendEmailConfirmation($customer, $redirectUrl);
     return $customer;
 }
Example #22
0
 /**
  * Submit a recurring payment right after an order is placed
  *
  * @return void
  * @throws \Exception
  */
 public function submit()
 {
     $this->_getResource()->beginTransaction();
     try {
         $this->setInternalReferenceId($this->mathRandom->getUniqueHash('temporary-'));
         $this->save();
         $this->setInternalReferenceId($this->mathRandom->getUniqueHash($this->getId() . '-'));
         $this->getManager()->submit($this, $this->getQuote()->getPayment());
         $this->save();
         $this->_getResource()->commit();
     } catch (\Exception $e) {
         $this->_getResource()->rollBack();
         throw $e;
     }
 }