public function testGetInstructionsSetInformation() { $this->assertNull($this->_instructions->getInstructions()); $testInstruction = 'second test'; $this->_info->setAdditionalInformation('instructions', $testInstruction); $this->assertEquals($testInstruction, $this->_instructions->getInstructions()); }
public function testGetInstruction() { $methodInstance = $this->getMockBuilder('Magento\\Payment\\Model\\MethodInterface')->getMockForAbstractClass(); $methodInstance->expects($this->once())->method('getConfigData')->with('instructions')->willReturn('get the instruction here'); $this->_info->expects($this->once())->method('getAdditionalInformation')->with('instructions')->willReturn(false); $this->_info->expects($this->once())->method('getMethodInstance')->willReturn($methodInstance); $this->assertEquals('get the instruction here', $this->_instructions->getInstructions()); }
public function testGetInstruction() { $methodInstance = $this->getMock('Magento\\Payment\\Model\\MethodInterface', ['getConfigData', 'getCode', 'getFormBlockType', 'getTitle'], [], '', false); $methodInstance->expects($this->once())->method('getConfigData')->with('instructions')->willReturn('get the instruction here'); $this->_info->expects($this->once())->method('getAdditionalInformation')->with('instructions')->willReturn(false); $this->_info->expects($this->once())->method('getMethodInstance')->willReturn($methodInstance); $this->assertEquals('get the instruction here', $this->_instructions->getInstructions()); }
public function testHasAdditionalInformation() { $this->assertFalse($this->info->hasAdditionalInformation()); $data = ['key1' => 'data1', 'key2' => 'data2']; $this->info->setAdditionalInformation($data); $this->assertFalse($this->info->hasAdditionalInformation('key3')); $this->assertTrue($this->info->hasAdditionalInformation('key2')); $this->assertTrue($this->info->hasAdditionalInformation()); }
/** * Format price with currency sign * @param \Magento\Payment\Model\Info $payment * @param float $amount * @return string */ protected function _formatPrice($payment, $amount) { return $payment->getOrder()->getBaseCurrency()->formatTxt($amount); }
/** * Perform the payment review * * @param \Magento\Payment\Model\Info $payment * @param string $action * @return bool */ public function reviewPayment(\Magento\Payment\Model\Info $payment, $action) { $api = $this->getApi()->setTransactionId($payment->getLastTransId()); // check whether the review is still needed $api->callGetTransactionDetails(); $this->importPaymentInfo($api, $payment); if (!$this->getInfo()->isPaymentReviewRequired($payment)) { return false; } // perform the review action $api->setAction($action)->callManagePendingTransactionStatus(); $api->callGetTransactionDetails(); $this->importPaymentInfo($api, $payment); return true; }
/** * Before object save manipulations * * @return $this */ protected function _beforeSave() { parent::_beforeSave(); if (!$this->getParentId() && $this->getOrder()) { $this->setParentId($this->getOrder()->getId()); } return $this; }
/** * Submit RP to the gateway * * @param RecurringPayment $payment * @param PaymentInfo $paymentInfo * @return void */ public function submit(RecurringPayment $payment, PaymentInfo $paymentInfo) { $token = $paymentInfo->getAdditionalInformation(PayPalExpress\Checkout::PAYMENT_INFO_TRANSPORT_TOKEN); $payment->setToken($token); $api = $this->_paymentMethod->getApi(); \Magento\Framework\Object\Mapper::accumulateByMap($payment, $api, array('token', 'subscriber_name', 'start_datetime', 'internal_reference_id', 'schedule_description', 'suspension_threshold', 'bill_failed_later', 'period_unit', 'period_frequency', 'period_max_cycles', 'billing_amount' => 'amount', 'trial_period_unit', 'trial_period_frequency', 'trial_period_max_cycles', 'trial_billing_amount', 'currency_code', 'shipping_amount', 'tax_amount', 'init_amount', 'init_may_fail')); $api->callCreateRecurringPayment(); $payment->setReferenceId($api->getRecurringPaymentId()); if ($api->getIsPaymentActive()) { $payment->setState(States::ACTIVE); } elseif ($api->getIsPaymentPending()) { $payment->setState(States::PENDING); } }
/** * Retrieve payment method model object * * @return \Magento\Payment\Model\MethodInterface */ public function getMethodInstance() { $method = parent::getMethodInstance(); $method->setStore($this->getQuote()->getStore()->getStoreId()); return $method; }
/** * Remove all cards from payment instance * * @return $this */ public function flushCards() { $this->_cards = array(); $this->_payment->setAdditionalInformation(self::CARDS_NAMESPACE, null); return $this; }
public function testInitAdditionalInformationWithUnserialize() { $data = serialize(['key1' => 'data1', 'key2' => 'data2']); $this->info->setData('additional_information', $data); $this->assertEquals(unserialize($data), $this->info->getAdditionalInformation()); }
/** * Returns request object with needed data for API request to PayPal to get form URL. * * @param \Magento\Payment\Model\Info $payment * @return \Magento\Paypal\Model\Hostedpro\Request */ protected function _buildFormUrlRequest(\Magento\Payment\Model\Info $payment) { $request = $this->_buildBasicRequest()->setOrder($payment->getOrder())->setPaymentMethod($this); return $request; }
/** * Render payment information block * * @param Info $info * @param int $storeId * @return string * @throws \Exception */ public function getInfoBlockHtml(Info $info, $storeId) { $initialEnvironmentInfo = $this->_appEmulation->startEnvironmentEmulation($storeId); try { // Retrieve specified view block from appropriate design package (depends on emulated store) $paymentBlock = $info->getBlockMock() ?: $this->getInfoBlock($info); $paymentBlock->setArea(\Magento\Framework\App\Area::AREA_FRONTEND)->setIsSecureMode(true); $paymentBlock->getMethod()->setStore($storeId); $paymentBlockHtml = $paymentBlock->toHtml(); } catch (\Exception $exception) { $this->_appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo); throw $exception; } $this->_appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo); return $paymentBlockHtml; }
/** * @param \Magento\Framework\Model\Context $context * @param \Magento\Framework\Registry $registry * @param \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory * @param \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory * @param \Magento\Payment\Helper\Data $paymentData * @param \Magento\Framework\Encryption\EncryptorInterface $encryptor * @param \Magento\Sales\Model\Service\OrderFactory $serviceOrderFactory * @param Payment\TransactionFactory $transactionFactory * @param \Magento\Sales\Model\Resource\Order\Payment\Transaction\CollectionFactory $transactionCollectionFactory * @param \Magento\Store\Model\StoreManagerInterface $storeManager * @param PriceCurrencyInterface $priceCurrency * @param \Magento\Framework\Model\Resource\AbstractResource $resource * @param \Magento\Framework\Data\Collection\Db $resourceCollection * @param array $data * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory, \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory, \Magento\Payment\Helper\Data $paymentData, \Magento\Framework\Encryption\EncryptorInterface $encryptor, \Magento\Sales\Model\Service\OrderFactory $serviceOrderFactory, \Magento\Sales\Model\Order\Payment\TransactionFactory $transactionFactory, \Magento\Sales\Model\Resource\Order\Payment\Transaction\CollectionFactory $transactionCollectionFactory, \Magento\Store\Model\StoreManagerInterface $storeManager, PriceCurrencyInterface $priceCurrency, \Magento\Framework\Model\Resource\AbstractResource $resource = null, \Magento\Framework\Data\Collection\Db $resourceCollection = null, array $data = []) { $this->priceCurrency = $priceCurrency; $this->_serviceOrderFactory = $serviceOrderFactory; $this->_transactionFactory = $transactionFactory; $this->_transactionCollectionFactory = $transactionCollectionFactory; $this->_storeManager = $storeManager; parent::__construct($context, $registry, $extensionFactory, $customAttributeFactory, $paymentData, $encryptor, $resource, $resourceCollection, $data); }
/** * Process exceptions for gateway action with a lot of transactions * * @param \Magento\Payment\Model\Info $payment * @param string $messages * @param bool $isSuccessfulTransactions * @return void * @throws \Magento\Framework\Model\Exception */ protected function _processFailureMultitransactionAction($payment, $messages, $isSuccessfulTransactions) { if ($isSuccessfulTransactions) { $messages[] = __('Gateway actions are locked because the gateway cannot complete ' . 'one or more of the transactions. ' . 'Please log in to your Authorize.Net account to manually resolve the issue(s).'); /** * If there is successful transactions we can not to cancel order but * have to save information about processed transactions in order`s comments and disable * opportunity to voiding\capturing\refunding in future. Current order and payment will not be saved because we have to * load new order object and set information into this object. */ $currentOrderId = $payment->getOrder()->getId(); $copyOrder = $this->_orderFactory->create()->load($currentOrderId); $copyOrder->getPayment()->setAdditionalInformation($this->_isGatewayActionsLockedKey, 1); foreach ($messages as $message) { $copyOrder->addStatusHistoryComment($message); } $copyOrder->save(); } throw new \Magento\Framework\Model\Exception($this->_authorizenetData->convertMessagesToMessage($messages)); }
/** * Render info item * * @param array $keys * @param \Magento\Payment\Model\Info $payment * @param bool $labelValuesOnly * @return array */ protected function _getFullInfo(array $keys, \Magento\Payment\Model\Info $payment, $labelValuesOnly) { $result = array(); foreach ($keys as $key) { if (!isset($this->_paymentMapFull[$key])) { $this->_paymentMapFull[$key] = array(); } if (!isset($this->_paymentMapFull[$key]['label'])) { if (!$payment->hasAdditionalInformation($key)) { $this->_paymentMapFull[$key]['label'] = false; $this->_paymentMapFull[$key]['value'] = false; } else { $value = $payment->getAdditionalInformation($key); $this->_paymentMapFull[$key]['label'] = $this->_getLabel($key); $this->_paymentMapFull[$key]['value'] = $this->_getValue($value, $key); } } if (!empty($this->_paymentMapFull[$key]['value'])) { if ($labelValuesOnly) { $result[$this->_paymentMapFull[$key]['label']] = $this->_paymentMapFull[$key]['value']; } else { $result[$key] = $this->_paymentMapFull[$key]; } } } return $result; }
/** * Retrieve payment information block * * @param Info $info * @param \Magento\Framework\View\LayoutInterface $layout * @return Template */ public function getInfoBlock(Info $info, LayoutInterface $layout = null) { $layout = $layout ?: $this->_layout; $blockType = $info->getMethodInstance()->getInfoBlockType(); $block = $layout->createBlock($blockType); $block->setInfo($info); return $block; }