/** * 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; }
/** * @covers \Magento\Cms\Block\Adminhtml\Block\Widget\Chooser::prepareElementHtml * @param string $elementValue * @param integer|null $modelBlockId * * @dataProvider prepareElementHtmlDataProvider */ public function testPrepareElementHtml($elementValue, $modelBlockId) { $elementId = 1; $uniqId = '126hj4h3j73hk7b347jhkl37gb34'; $sourceUrl = 'cms/block_widget/chooser/126hj4h3j73hk7b347jhkl37gb34'; $config = ['key1' => 'value1']; $fieldsetId = 2; $html = 'some html'; $title = 'some title'; $this->this->setConfig($config); $this->this->setFieldsetId($fieldsetId); $this->elementMock->expects($this->atLeastOnce())->method('getId')->willReturn($elementId); $this->mathRandomMock->expects($this->atLeastOnce())->method('getUniqueHash')->with($elementId)->willReturn($uniqId); $this->urlBuilderMock->expects($this->atLeastOnce())->method('getUrl')->with('cms/block_widget/chooser', ['uniq_id' => $uniqId])->willReturn($sourceUrl); $this->layoutMock->expects($this->atLeastOnce())->method('createBlock')->with('Magento\\Widget\\Block\\Adminhtml\\Widget\\Chooser')->willReturn($this->chooserMock); $this->chooserMock->expects($this->atLeastOnce())->method('setElement')->with($this->elementMock)->willReturnSelf(); $this->chooserMock->expects($this->atLeastOnce())->method('setConfig')->with($config)->willReturnSelf(); $this->chooserMock->expects($this->atLeastOnce())->method('setFieldsetId')->with($fieldsetId)->willReturnSelf(); $this->chooserMock->expects($this->atLeastOnce())->method('setSourceUrl')->with($sourceUrl)->willReturnSelf(); $this->chooserMock->expects($this->atLeastOnce())->method('setUniqId')->with($uniqId)->willReturnSelf(); $this->elementMock->expects($this->atLeastOnce())->method('getValue')->willReturn($elementValue); $this->blockFactoryMock->expects($this->any())->method('create')->willReturn($this->modelBlockMock); $this->modelBlockMock->expects($this->any())->method('load')->with($elementValue)->willReturnSelf(); $this->modelBlockMock->expects($this->any())->method('getId')->willReturn($modelBlockId); $this->modelBlockMock->expects($this->any())->method('getTitle')->willReturn($title); $this->chooserMock->expects($this->any())->method('setLabel')->with($title)->willReturnSelf(); $this->chooserMock->expects($this->atLeastOnce())->method('toHtml')->willReturn($html); $this->elementMock->expects($this->atLeastOnce())->method('setData')->with('after_element_html', $html)->willReturnSelf(); $this->assertEquals($this->elementMock, $this->this->prepareElementHtml($this->elementMock)); }
public function testGetFormKeyExists() { $this->sessionMock->expects($this->exactly(2))->method('getData')->with(FormKey::FORM_KEY)->will($this->returnValue('random_string')); $this->mathRandomMock->expects($this->never())->method('getRandomString'); $this->sessionMock->expects($this->never())->method('setData'); $this->assertEquals('random_string', $this->formKey->getFormKey()); }
/** * Retrieve Session Form Key * * @return string A 16 bit unique key for forms */ public function getFormKey() { if (!$this->session->getData(self::FORM_KEY)) { $this->session->setData(self::FORM_KEY, $this->mathRandom->getRandomString(16)); } return $this->session->getData(self::FORM_KEY); }
/** * Retrieve Session Form Key * * @return string A 16 bit unique key for forms */ public function getFormKey() { if (!$this->isPresent()) { $this->set($this->mathRandom->getRandomString(16)); } return $this->escaper->escapeHtmlAttr($this->session->getData(self::FORM_KEY)); }
protected function setUp() { $this->scopeConfigMock = $this->getMock('Magento\\Framework\\App\\Config\\ScopeConfigInterface'); $this->randomMock = $this->getMock('Magento\\Framework\\Math\\Random'); $this->randomMock->expects($this->any())->method('getUniqueHash')->with($this->equalTo('_'))->will($this->returnValue('unique_hash')); $this->objectManagerHelper = new ObjectManagerHelper($this); $this->minsaleqty = $this->objectManagerHelper->getObject('Magento\\CatalogInventory\\Helper\\Minsaleqty', ['scopeConfig' => $this->scopeConfigMock, 'mathRandom' => $this->randomMock]); }
public function testGetRandomString() { $expectedValue = 20; $expectedTestValue = 'test_value'; $this->mathRandom->expects($this->once())->method('getRandomString')->with($this->equalTo($expectedValue))->will($this->returnValue('test_value')); $result = $this->object->getRandomString($expectedValue); $this->assertEquals($expectedTestValue, $result); }
/** * 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; }
/** * @dataProvider afterLoadDataProvider */ public function testAfterLoad($value, $hashData, $expected) { $this->model->setValue($value); $index = 0; foreach ($hashData as $hash) { $this->mathRandomMock->expects($this->at($index))->method('getUniqueHash')->willReturn($hash); $index++; } $this->model->afterLoad(); $this->assertEquals($expected, $this->model->getValue()); }
public function testGetWidgetOptions() { $rand = rand(); $this->mathRandom->expects($this->any())->method('getUniqueHash')->with('id_')->willReturn('id_' . $rand); $saveVideoUrl = 'http://host/index.php/admin/catalog/product_gallery/upload/key/'; $saveRemoteVideoUrl = 'http://host/index.php/admin/product_video/product_gallery/retrieveImage/'; $this->urlBuilder->expects($this->exactly(2))->method('getUrl')->willReturnOnConsecutiveCalls($saveVideoUrl, $saveRemoteVideoUrl); $value = ['saveVideoUrl' => $saveVideoUrl, 'saveRemoteVideoUrl' => $saveRemoteVideoUrl, 'htmlId' => 'id_' . $rand]; $this->jsonEncoderMock->expects($this->once())->method('encode')->with($value)->willReturn(json_encode($value)); $this->block->getWidgetOptions(); }
protected function setUp() { $this->scopeConfigMock = $this->getMock('Magento\\Framework\\App\\Config\\ScopeConfigInterface'); $this->randomMock = $this->getMock('Magento\\Framework\\Math\\Random'); $this->randomMock->expects($this->any())->method('getUniqueHash')->with($this->equalTo('_'))->will($this->returnValue('unique_hash')); $groupManagement = $this->getMockBuilder('Magento\\Customer\\Api\\GroupManagementInterface')->setMethods(['getAllCustomersGroup'])->getMockForAbstractClass(); $allGroup = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\GroupInterface')->setMethods(['getId'])->getMockForAbstractClass(); $allGroup->expects($this->any())->method('getId')->will($this->returnValue(32000)); $groupManagement->expects($this->any())->method('getAllCustomersGroup')->will($this->returnValue($allGroup)); $this->objectManagerHelper = new ObjectManagerHelper($this); $this->minsaleqty = $this->objectManagerHelper->getObject('Magento\\CatalogInventory\\Helper\\Minsaleqty', ['scopeConfig' => $this->scopeConfigMock, 'mathRandom' => $this->randomMock, 'groupManagement' => $groupManagement]); }
public function setUp() { $this->setUpMock = $this->getMock('Magento\\Setup\\Module\\Setup', [], [], '', false); $this->dbAdapterMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', [], [], '', false); $this->setUpMock->expects($this->any())->method('getConnection')->will($this->returnValue($this->dbAdapterMock)); $this->setUpMock->expects($this->any())->method('getTable')->will($this->returnCallback(function ($table) { return $table; })); $this->randomMock = $this->getMock('Magento\\Framework\\Math\\Random'); $this->randomMock->expects($this->any())->method('getRandomString')->will($this->returnValue('salt')); $data = [AdminAccount::KEY_FIRST_NAME => 'John', AdminAccount::KEY_LAST_NAME => 'Doe', AdminAccount::KEY_EMAIL => '*****@*****.**', AdminAccount::KEY_PASSWORD => '123123q', AdminAccount::KEY_USERNAME => 'admin']; $this->adminAccount = new AdminAccount($this->setUpMock, $this->randomMock, $data); }
public function testRequestToken() { $request = new Object(); $secureTokenID = 'Sdj46hDokds09c8k2klaGJdKLl032ekR'; $this->transparent->expects($this->once())->method('buildBasicRequest')->willReturn($request); $this->transparent->expects($this->once())->method('fillCustomerContacts'); $this->transparent->expects($this->once())->method('getConfig')->willReturn($this->getMock('Magento\\Paypal\\Model\\PayflowConfig', [], [], '', false)); $this->transparent->expects($this->once())->method('postRequest')->willReturn(new Object()); $this->mathRandom->expects($this->once())->method('getUniqueHash')->willReturn($secureTokenID); $this->url->expects($this->exactly(3))->method('getUrl'); $quote = $this->getMock('Magento\\Quote\\Model\\Quote', [], [], '', false); $this->model->requestToken($quote); $this->assertEquals($secureTokenID, $request->getSecuretokenid()); }
/** * 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>"; }
/** * @param string $email * @param string $templateIdentifier * @param string $sender * @param int $storeId * @param int $customerId * @param string $hash */ protected function prepareInitiatePasswordReset($email, $templateIdentifier, $sender, $storeId, $customerId, $hash) { $websiteId = 1; $dateTime = date(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT); $customerData = ['key' => 'value']; $customerName = 'Customer Name'; $this->store->expects($this->once())->method('getWebsiteId')->willReturn($websiteId); $this->store->expects($this->any())->method('getId')->willReturn($storeId); $this->storeManager->expects($this->any())->method('getStore')->willReturn($this->store); $customer = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->getMock(); $customer->expects($this->any())->method('getEmail')->willReturn($email); $customer->expects($this->any())->method('getId')->willReturn($customerId); $customer->expects($this->any())->method('getStoreId')->willReturn($storeId); $this->customerRepository->expects($this->once())->method('get')->with($email, $websiteId)->willReturn($customer); $this->customerRepository->expects($this->once())->method('save')->with($customer)->willReturnSelf(); $this->random->expects($this->once())->method('getUniqueHash')->willReturn($hash); $this->customerViewHelper->expects($this->any())->method('getCustomerName')->with($customer)->willReturn($customerName); $this->customerSecure->expects($this->any())->method('setRpToken')->with($hash)->willReturnSelf(); $this->customerSecure->expects($this->any())->method('setRpTokenCreatedAt')->with($dateTime)->willReturnSelf(); $this->customerSecure->expects($this->any())->method('addData')->with($customerData)->willReturnSelf(); $this->customerSecure->expects($this->any())->method('setData')->with('name', $customerName)->willReturnSelf(); $this->customerRegistry->expects($this->any())->method('retrieveSecureData')->with($customerId)->willReturn($this->customerSecure); $this->dataObjectProcessor->expects($this->any())->method('buildOutputDataArray')->with($customer, '\\Magento\\Customer\\Api\\Data\\CustomerInterface')->willReturn($customerData); $this->prepareEmailSend($email, $templateIdentifier, $sender, $storeId, $customerName); }
/** * 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; }
/** * @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; }
public function testToHtmlMethodSetBmlData() { $isInCatalog = true; $paymentMethodCode = ''; $bmlMethodCode = ''; $hash = 'hash'; $this->shortcut->setIsInCatalogProduct($isInCatalog); $expressMethod = $this->getMockBuilder('Magento\\Paypal\\Model\\Express')->disableOriginalConstructor()->setMethods([])->getMock(); $expectedData = ['is_in_catalog_product' => $isInCatalog, 'shortcut_html_id' => $hash, 'checkout_url' => null, 'image_url' => 'https://www.paypalobjects.com/webstatic/en_US/i/buttons/ppcredit-logo-medium.png', 'additional_link_image' => ['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']]; $this->paypalShortcutHelperMock->expects($this->once())->method('validate')->with($paymentMethodCode, $isInCatalog)->will($this->returnValue(true)); $this->paymentHelperMock->expects($this->once())->method('getMethodInstance')->with($bmlMethodCode)->will($this->returnValue($expressMethod)); $expressMethod->expects($this->once())->method('isAvailable')->will($this->returnValue(true)); $this->randomMock->expects($this->once())->method('getUniqueHash')->with('ec_shortcut_bml_')->will($this->returnValue($hash)); $this->assertEmpty($this->shortcut->toHtml()); $this->assertContains($expectedData, $this->shortcut->getData()); }
public function testCreateAccountWithPasswordHashWithCustomerAddresses() { $websiteId = 1; $addressId = 2; $customerId = null; $storeId = 1; $hash = '4nj54lkj5jfi03j49f8bgujfgsd'; //Handle store $store = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock(); $store->expects($this->any())->method('getWebsiteId')->willReturn($websiteId); //Handle address - existing and non-existing. Non-Existing should return null when call getId method $existingAddress = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\AddressInterface')->disableOriginalConstructor()->getMock(); $nonExistingAddress = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\AddressInterface')->disableOriginalConstructor()->getMock(); //Ensure that existing address is not in use $this->addressRepository->expects($this->atLeastOnce())->method("save")->withConsecutive(array($this->logicalNot($this->identicalTo($existingAddress))), array($this->identicalTo($nonExistingAddress))); $existingAddress->expects($this->any())->method("getId")->willReturn($addressId); //Expects that id for existing address should be unset $existingAddress->expects($this->once())->method("setId")->with(null); //Handle Customer calls $customer = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->getMock(); $customer->expects($this->atLeastOnce())->method('getWebsiteId')->willReturn($websiteId); $customer->expects($this->atLeastOnce())->method('getStoreId')->willReturn($storeId); $customer->expects($this->any())->method("getId")->willReturn($customerId); //Return Customer from customer repositoryå $this->customerRepository->expects($this->atLeastOnce())->method('save')->willReturn($customer); $this->customerRepository->expects($this->once())->method('getById')->with($customerId)->willReturn($customer); $customerSecure = $this->getMockBuilder('Magento\\Customer\\Model\\Data\\CustomerSecure')->setMethods(['setRpToken', 'setRpTokenCreatedAt', 'getPasswordHash'])->disableOriginalConstructor()->getMock(); $customerSecure->expects($this->once())->method('setRpToken')->with($hash); $customerSecure->expects($this->any())->method('getPasswordHash')->willReturn($hash); $this->customerRegistry->expects($this->any())->method('retrieveSecureData')->with($customerId)->willReturn($customerSecure); $this->random->expects($this->once())->method('getUniqueHash')->willReturn($hash); $customer->expects($this->atLeastOnce())->method('getAddresses')->willReturn([$existingAddress, $nonExistingAddress]); $this->storeManager->expects($this->atLeastOnce())->method('getStore')->willReturn($store); $this->assertSame($customer, $this->accountManagement->createAccountWithPasswordHash($customer, $hash)); }
/** * 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; }
/** * Change encryption key * * @param string|null $key * @return null|string * @throws \Exception */ public function changeEncryptionKey($key = null) { // prepare new key, encryptor and new configuration segment if (!$this->writer->checkIfWritable()) { throw new \Exception(__('Deployment configuration file is not writable.')); } if (null === $key) { $key = md5($this->random->getRandomString(ConfigOptionsListConstants::STORE_KEY_RANDOM_STRING_SIZE)); } $this->encryptor->setNewKey($key); $encryptSegment = new ConfigData(ConfigFilePool::APP_ENV); $encryptSegment->set(ConfigOptionsListConstants::CONFIG_PATH_CRYPT_KEY, $this->encryptor->exportKeys()); $configData = [$encryptSegment->getFileKey() => $encryptSegment->getData()]; // update database and config.php $this->beginTransaction(); try { $this->_reEncryptSystemConfigurationValues(); $this->_reEncryptCreditCardNumbers(); $this->writer->saveConfig($configData); $this->commit(); return $key; } catch (\Exception $e) { $this->rollBack(); throw $e; } }
/** * 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; }
/** * @return string */ public function getPaymentDetailsId() { if ($this->isInMiniCart()) { return 'braintree_paypal_payment_details_minicart'; } else { return 'braintree_paypal_payment_details' . $this->mathRandom->getRandomString(5); } }
/** * 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; }
/** * Creates encryption key config data * @param array $data * @return ConfigData */ public function createCryptConfig(array $data) { $currentKey = $this->deploymentConfig->get(ConfigOptionsListConstants::CONFIG_PATH_CRYPT_KEY); $configData = new ConfigData(ConfigFilePool::APP_ENV); if (isset($data[ConfigOptionsListConstants::INPUT_KEY_ENCRYPTION_KEY])) { if ($currentKey !== null) { $key = $currentKey . "\n" . $data[ConfigOptionsListConstants::INPUT_KEY_ENCRYPTION_KEY]; } else { $key = $data[ConfigOptionsListConstants::INPUT_KEY_ENCRYPTION_KEY]; } $configData->set(ConfigOptionsListConstants::CONFIG_PATH_CRYPT_KEY, $key); } else { if ($currentKey === null) { $configData->set(ConfigOptionsListConstants::CONFIG_PATH_CRYPT_KEY, md5($this->random->getRandomString(ConfigOptionsListConstants::STORE_KEY_RANDOM_STRING_SIZE))); } } return $configData; }
public function testGetHtmlElementIdsShoppingCart() { $random = '_shopping_cart'; $this->mathRandomMock->expects($this->any())->method('getRandomString')->willReturn($random); $block = $this->objectManagerHelper->getObject('Magento\\Braintree\\Block\\PayPal\\Shortcut', ['mathRandom' => $this->mathRandomMock, 'data' => ['container' => new \Magento\Framework\Object(['module_name' => 'Magento_Checkout'])]]); $this->assertEquals('braintree_paypal_container_shopping_cart', $block->getContainerId()); $this->assertEquals('braintree_paypal_submit_form_shopping_cart', $block->getSubmitFormId()); $this->assertEquals('braintree_paypal_payment_method_nonce_shopping_cart', $block->getPaymentMethodNonceId()); $this->assertEquals('braintree_paypal_payment_details_shopping_cart', $block->getPaymentDetailsId()); }
/** * @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; }
public function testGetHtmlSuccessfulTimestamp() { $uniqueHash = 'H@$H'; $id = 3; $format = 'mm/dd/yyyy'; $yesterday = new \DateTime(); $yesterday->add(\DateInterval::createFromDateString('yesterday')); $tomorrow = new \DateTime(); $tomorrow->add(\DateInterval::createFromDateString('tomorrow')); $value = ['locale' => 'en_US', 'from' => $yesterday->getTimestamp(), 'to' => $tomorrow->getTimestamp()]; $this->mathRandomMock->expects($this->any())->method('getUniqueHash')->willReturn($uniqueHash); $this->columnMock->expects($this->once())->method('getHtmlId')->willReturn($id); $this->localeDateMock->expects($this->any())->method('getDateFormat')->willReturn($format); $this->columnMock->expects($this->any())->method('getTimezone')->willReturn(false); $this->localeResolverMock->expects($this->any())->method('getLocale')->willReturn('en_US'); $this->model->setColumn($this->columnMock); $this->model->setValue($value); $output = $this->model->getHtml(); $this->assertContains('id="' . $uniqueHash . '_from" value="' . $yesterday->getTimestamp(), $output); $this->assertContains('id="' . $uniqueHash . '_to" value="' . $tomorrow->getTimestamp(), $output); }
public function testExecute() { $selectedCategories = '1'; $isAnchorOnly = true; $hash = '7e6baeca2d76ca0efc3a299986d31bdc9cd796fb'; $content = 'block_content'; $this->request->expects($this->any())->method('getParam')->willReturnMap( [ ['selected', '', $selectedCategories], ['is_anchor_only', 0, $isAnchorOnly] ] ); $this->mathRandom->expects($this->once())->method('getUniqueHash')->with('categories')->willReturn($hash); $this->chooser->expects($this->once())->method('setUseMassaction')->with()->willReturnSelf(); $this->chooser->expects($this->once())->method('setId')->with($hash)->willReturnSelf(); $this->chooser->expects($this->once())->method('setIsAnchorOnly')->with($isAnchorOnly)->willReturnSelf(); $this->chooser->expects($this->once()) ->method('setSelectedCategories') ->with(explode(',', $selectedCategories)) ->willReturnSelf(); $this->chooser->expects($this->once())->method('toHtml')->willReturn($content); $this->layout->expects($this->once()) ->method('createBlock') ->with($this->blockClass) ->willReturn($this->chooser); $this->resultRaw->expects($this->once())->method('setContents')->with($content)->willReturnSelf(); $this->resultFactory->expects($this->once()) ->method('create') ->with(\Magento\Framework\Controller\ResultFactory::TYPE_RAW) ->willReturn($this->resultRaw); $this->context->expects($this->once())->method('getRequest')->willReturn($this->request); $this->context->expects($this->once())->method('getResultFactory')->willReturn($this->resultFactory); /** @var \Magento\Widget\Controller\Adminhtml\Widget\Instance\Categories $controller */ $this->controller = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this)) ->getObject( 'Magento\Widget\Controller\Adminhtml\Widget\Instance\Categories', [ 'context' => $this->context, 'mathRandom' => $this->mathRandom, 'layout' => $this->layout ] ); $this->assertSame($this->resultRaw, $this->controller->executeInternal()); }
public function testLoadByCustomerId() { $customerId = 1; $customerIdFieldName = 'customer_id'; $sharingCode = 'expected_sharing_code'; $this->eventDispatcher->expects($this->any())->method('dispatch'); $this->resource->expects($this->any())->method('getCustomerIdFieldName'); $this->resource->expects($this->once())->method('load')->with($this->logicalOr($this->wishlist, $customerId, $customerIdFieldName)); $this->mathRandom->expects($this->once())->method('getUniqueHash')->will($this->returnValue($sharingCode)); $this->assertInstanceOf('Magento\\Wishlist\\Model\\Wishlist', $this->wishlist->loadByCustomerId($customerId, true)); $this->assertEquals($customerId, $this->wishlist->getCustomerId()); $this->assertEquals($sharingCode, $this->wishlist->getSharingCode()); }