/** * @param bool $result * * @dataProvider dataProviderForTestIsAvailable */ public function testIsAvailable($result) { $storeId = 15; $this->quoteMock->expects($this->once())->method('getStoreId')->willReturn($storeId); $this->scopeConfigMock->expects($this->once())->method('getValue')->with('payment/' . Stub::STUB_CODE . '/active', ScopeInterface::SCOPE_STORE, $storeId)->willReturn($result); $this->eventManagerMock->expects($this->once())->method('dispatch')->with($this->equalTo('payment_method_is_active'), $this->countOf(3)); $this->assertEquals($result, $this->payment->isAvailable($this->quoteMock)); }
/** * @param bool $isOneAvailable * @param string $instructionsOne * @param bool $isTwoAvailable * @param string $instructionsTwo * @param array $result * @dataProvider dataProviderGetConfig */ public function testGetConfig($isOneAvailable, $instructionsOne, $isTwoAvailable, $instructionsTwo, $result) { $this->methodOneMock->expects($this->once())->method('isAvailable')->willReturn($isOneAvailable); $this->methodOneMock->expects($this->any())->method('getInstructions')->willReturn($instructionsOne); $this->methodTwoMock->expects($this->once())->method('isAvailable')->willReturn($isTwoAvailable); $this->methodTwoMock->expects($this->any())->method('getInstructions')->willReturn($instructionsTwo); $this->assertEquals($result, $this->model->getConfig()); }
public function testAssignData() { $data = new DataObject(); $paymentInfo = $this->getMock(InfoInterface::class); $this->payment->setInfoInstance($paymentInfo); $eventData = [AbstractDataAssignObserver::METHOD_CODE => $this, AbstractDataAssignObserver::MODEL_CODE => $paymentInfo, AbstractDataAssignObserver::DATA_CODE => $data]; $this->eventManagerMock->expects(static::exactly(2))->method('dispatch')->willReturnMap([['payment_method_assign_data_' . Stub::STUB_CODE, $eventData], ['payment_method_assign_data', $eventData]]); $this->payment->assignData($data); }
public function isAvailable(\Magento\Quote\Api\Data\CartInterface $quote = null) { if ($quote && ($quote->getBaseGrandTotal() < $this->_minAmount || $this->_maxAmount && $quote->getBaseGrandTotal() > $this->_maxAmount)) { return false; } return parent::isAvailable($quote); }
/** * Retrieve config data value by field name * * @param string $fieldName * @return mixed */ protected function getMethodConfigData($fieldName) { if ($this->method instanceof TransparentInterface) { return $this->method->getConfigInterface()->getValue($fieldName); } return $this->method->getConfigData($fieldName); }
/** * Check whether payment method can be used * * @param CartInterface|null $quote * @return bool */ public function isAvailable($quote = null) { if ($quote === null) { return false; } return parent::isAvailable($quote) && $this->isCarrierAllowed($quote->getShippingAddress()->getShippingMethod()); }
/** * @param Context $context * @param Registry $registry * @param ExtensionAttributesFactory $extensionFactory * @param AttributeValueFactory $customAttributeFactory * @param Data $paymentData * @param ScopeConfigInterface $scopeConfig * @param Logger $logger * @param CoinGateMerchant $coingate * @param UrlInterface $urlBuilder * @param StoreManagerInterface $storeManager * @param AbstractResource|null $resource * @param AbstractDb|null $resourceCollection * @param array $data * @internal param ModuleListInterface $moduleList * @internal param TimezoneInterface $localeDate * @internal param CountryFactory $countryFactory * @internal param Http $response */ public function __construct(Context $context, Registry $registry, ExtensionAttributesFactory $extensionFactory, AttributeValueFactory $customAttributeFactory, Data $paymentData, ScopeConfigInterface $scopeConfig, Logger $logger, CoinGateMerchant $coingate, UrlInterface $urlBuilder, StoreManagerInterface $storeManager, AbstractResource $resource = null, AbstractDb $resourceCollection = null, array $data = array()) { parent::__construct($context, $registry, $extensionFactory, $customAttributeFactory, $paymentData, $scopeConfig, $logger, $resource, $resourceCollection, $data); $this->urlBuilder = $urlBuilder; $this->coingate = $coingate; $this->storeManager = $storeManager; $this->coingate->initialize(array('app_id' => $this->getConfigData('app_id'), 'api_key' => $this->getConfigData('api_key'), 'api_secret' => $this->getConfigData('api_secret'), 'mode' => $this->getConfigData('sandbox_mode') ? 'sandbox' : 'live', 'user_agent' => 'CoinGate - Magento 2 Extension v' . self::COINGATE_MAGENTO_VERSION)); }
/** * Assign data to info model instance * * @param mixed $data * @return \Magento\Payment\Model\Info */ public function assignData($data) { $result = parent::assignData($data); $key = self::TRANSPORT_BILLING_AGREEMENT_ID; $id = false; if (is_array($data) && isset($data[$key])) { $id = $data[$key]; } elseif ($data instanceof \Magento\Framework\Object && $data->getData($key)) { $id = $data->getData($key); } if ($id) { $info = $this->getInfoInstance(); $ba = $this->_agreementFactory->create()->load($id); if ($ba->getId() && $ba->getCustomerId() == $info->getQuote()->getCustomerId()) { $info->setAdditionalInformation($key, $id)->setAdditionalInformation(self::PAYMENT_INFO_REFERENCE_ID, $ba->getReferenceId()); } } return $result; }
public function capture(\Magento\Payment\Model\InfoInterface $payment, $amount) { parent::capture($payment, $amount); /* collect data */ assert($payment instanceof \Magento\Sales\Model\Order\Payment); /** @var \Magento\Sales\Model\Order $order */ $order = $payment->getOrder(); $orderId = $order->getId(); $customerId = $order->getCustomerId(); /* perform payment */ $req = new \Praxigento\Wallet\Service\Operation\Request\PayForSaleOrder(); $req->setCustomerId($customerId); $req->setOrderId($orderId); $req->setBaseAmountToPay($amount); $resp = $this->callOperation->payForSaleOrder($req); /* TODO: add transaction ID to payment */ $operId = $resp->getOperationId(); $payment->setTransactionId($operId); return $this; }
/** * Assign data to info model instance * * @param \Magento\Framework\DataObject $data * @return \Magento\Payment\Model\Info * @throws \Magento\Framework\Exception\LocalizedException */ public function assignData(\Magento\Framework\DataObject $data) { parent::assignData($data); $additionalData = $data->getData(PaymentInterface::KEY_ADDITIONAL_DATA); if (!is_array($additionalData) || !isset($additionalData[self::TRANSPORT_BILLING_AGREEMENT_ID])) { return $this; } $id = $additionalData[self::TRANSPORT_BILLING_AGREEMENT_ID]; if (!$id || !is_numeric($id)) { return $this; } $info = $this->getInfoInstance(); /** @var Agreement $ba */ $ba = $this->_agreementFactory->create(); $ba->load($id); if ($ba->getId() && $ba->getCustomerId() == $info->getQuote()->getCustomerId()) { $info->setAdditionalInformation(self::TRANSPORT_BILLING_AGREEMENT_ID, $id); $info->setAdditionalInformation(self::PAYMENT_INFO_REFERENCE_ID, $ba->getReferenceId()); } return $this; }
/** * Check whether payment method can be used * * @param \Magento\Sales\Model\Quote|null $quote * @return bool */ public function isAvailable($quote = null) { $storeId = $this->_storeManager->getStore($this->getStore())->getId(); /** @var \Magento\Paypal\Model\Config $config */ $config = $this->_configFactory->create()->setStoreId($storeId); if (\Magento\Payment\Model\Method\AbstractMethod::isAvailable($quote) && $config->isMethodAvailable($this->getCode())) { return true; } return false; }
/** * Assign corresponding data * * @param \Magento\Framework\DataObject|mixed $data * @return $this * @throws LocalizedException */ public function assignData(\Magento\Framework\DataObject $data) { parent::assignData($data); $infoInstance = $this->getInfoInstance(); $additionalData = $data->getData()['additional_data']; if (is_null($additionalData) || !array_key_exists('destination_customer', $additionalData)) { $additionalData['destination_customer'] = $this->config->getValue('payment/openpay/concentratorAccount'); } $infoInstance->setAdditionalInformation('destination_customer', $additionalData['destination_customer']); return $this; }
/** * Check payment method model * * @param \Magento\Payment\Model\Method\AbstractMethod|null $method * @return bool */ protected function _canUseMethod($method) { return $method && $this->paymentSpecification->isSatisfiedBy($method->getCode()) && parent::_canUseMethod($method); }
/** * Assign corresponding data * * @param \Magento\Framework\DataObject|mixed $data * @return $this * @throws LocalizedException */ public function assignData(\Magento\Framework\DataObject $data) { parent::assignData($data); $infoInstance = $this->getInfoInstance(); if (($s2p_method = $data->getSpMethod()) === null) { $s2p_method = $data->getAdditionalData('sp_method'); } if (($country_code = $data->getSelectedCountry()) === null) { $country_code = $data->getAdditionalData('selected_country'); } if (!empty($country_code)) { $country_code = strtoupper(trim($country_code)); } $configured_methods_instance = $this->_configuredMethods->create(); if (!$s2p_method or empty($country_code) or !($method_details = $configured_methods_instance->getConfiguredMethodDetails($s2p_method, ['country_code' => $country_code, 'only_active' => true]))) { // ob_start(); // var_dump( $data->getSpMethod() ); // var_dump( $data->getAdditionalData( 'sp_method' ) ); // var_dump( $s2p_method ); // var_dump( $country_code ); // if( isset( $method_details ) ) // var_dump( $method_details ); // $buf = ob_get_clean(); throw new LocalizedException(__('Please select a valid Smart2Pay method first.')); } $details_arr = array(); if (!empty($method_details[$country_code])) { $details_arr = $method_details[$country_code]; } elseif (!empty($method_details[Country::INTERNATIONAL_CODE])) { $details_arr = $method_details[Country::INTERNATIONAL_CODE]; } if (empty($details_arr) or !is_array($details_arr)) { throw new LocalizedException(__('Couldn\'t obtain Smart2Pay payment method details. Please retry.')); } $s2p_transaction = $this->_s2pTransaction->create(); $s2p_transaction->setMethodID($s2p_method)->setMerchantTransactionID('NOTSETYET_' . microtime(true)); $s2p_transaction->save(); $infoInstance->setAdditionalInformation('sp_method', $s2p_method); $infoInstance->setAdditionalInformation('sp_surcharge', isset($details_arr['surcharge']) ? $details_arr['surcharge'] : 0); $infoInstance->setAdditionalInformation('sp_fixed_amount', isset($details_arr['fixed_amount']) ? $details_arr['fixed_amount'] : 0); $infoInstance->setAdditionalInformation('sp_transaction', $s2p_transaction->getID()); return $this; }
/** * Is active * * @param int|null $storeId * @return bool */ public function isActive($storeId = null) { $pathStandardExpress = 'payment/' . Config::METHOD_WPS_EXPRESS . '/active'; $pathPaypalExpress = 'payment/' . Config::METHOD_WPP_EXPRESS . '/active'; return parent::isActive($storeId) || (bool) (int) $this->_scopeConfig->getValue($pathStandardExpress, ScopeInterface::SCOPE_STORE, $storeId) || (bool) (int) $this->_scopeConfig->getValue($pathPaypalExpress, ScopeInterface::SCOPE_STORE, $storeId); }
/** * Get config payment action, do nothing if status is pending * * @return string|null */ public function getConfigPaymentAction() { return $this->getConfigData('order_status') == 'pending' ? null : parent::getConfigPaymentAction(); }
/** * Check whether payment method can be used * * @param CartInterface|null $quote * @return bool */ public function isAvailable(\Magento\Quote\Api\Data\CartInterface $quote = null) { if ($quote === null) { return false; } return parent::isAvailable($quote) && $this->isCarrierAllowed($quote->getShippingAddress()->getShippingMethod()); }
public function refund(\Magento\Payment\Model\InfoInterface $payment, $amount) { return parent::refund($payment, $amount); }
/** * Check whether payment method can be used * * @param \Magento\Quote\Api\Data\CartInterface|\Magento\Quote\Model\Quote|null $quote * @return bool * @throws \Magento\Framework\Exception\LocalizedException */ public function isAvailable(\Magento\Quote\Api\Data\CartInterface $quote = null) { return AbstractMethod::isAvailable($quote) && $this->getConfig()->isMethodAvailable($this->getCode()); }
/** * * @param string $paymentAction * @param object $stateObject * * @return $this */ public function initialize($paymentAction, $stateObject) { $pre = __METHOD__ . " : "; pflog($pre . 'bof'); $stateObject->setState(\Magento\Sales\Model\Order::STATE_PENDING_PAYMENT); $stateObject->setStatus('pending_payment'); $stateObject->setIsNotified(false); return parent::initialize($paymentAction, $stateObject); // TODO: Change the autogenerated stub }
/** * @param CartInterface|null $quote * @return bool */ public function isAvailable(CartInterface $quote = null) { if (!parent::isAvailable($quote)) { return false; } $customer = $quote->getCustomer(); $openpayCards = $customer->getExtensionAttributes()->getOpenpayCard(); if (count($openpayCards) === 0) { return false; } $openpayConfigValues = $this->config->getValue('payment/openpay'); $chargeMinAmount = $openpayConfigValues['chargeMinAmount']; if ($chargeMinAmount > $quote->getGrandTotal()) { return false; } $currency = $quote->getCurrency()->getQuoteCurrencyCode(); $acceptedCurrencies = $this->getCurrenciesAccepted(); if (!in_array($currency, $acceptedCurrencies)) { return false; } return true; }
/** * @return $this * @throws \Magento\Framework\Exception\LocalizedException */ public function validate() { \Magento\Payment\Model\Method\AbstractMethod::validate(); return $this; }
/** * Check whether payment method can be used * * @param \Magento\Quote\Api\Data\CartInterface|null $quote * @return bool */ public function isAvailable(\Magento\Quote\Api\Data\CartInterface $quote = null) { if (is_null($quote)) { return parent::isAvailable(); } else { return parent::isAvailable($quote) && $this->isShippingMethodAllowed($quote->getShippingAddress()->getShippingMethod()) && $this->paytypeHelper->getAllForQuote($quote) !== []; } }
/** * Set transaction ID into creditmemo for informational purposes * @param \Magento\Sales\Model\Order\Creditmemo $creditmemo * @param \Magento\Sales\Model\Order\Payment $payment * @return \Magento\Payment\Model\Method\AbstractMethod */ public function processCreditmemo($creditmemo, $payment) { return \Magento\Payment\Model\Method\AbstractMethod::processCreditmemo($creditmemo, $payment); }
/** * Check whether there are CC types set in configuration * * @param \Magento\Quote\Api\Data\CartInterface|null $quote * @return bool */ public function isAvailable(\Magento\Quote\Api\Data\CartInterface $quote = null) { return $this->getConfigData('cctypes', $quote ? $quote->getStoreId() : null) && parent::isAvailable($quote); }
/** * @param Context $context * @param Registry $registry * @param ExtensionAttributesFactory $extensionFactory * @param AttributeValueFactory $customAttributeFactory * @param Data $paymentData * @param ScopeConfigInterface $scopeConfig * @param Logger $logger * @param UrlInterface $urlBuilder * @param StoreManagerInterface $storeManager * @param AbstractResource|null $resource * @param AbstractDb|null $resourceCollection * @param array $data * @internal param ModuleListInterface $moduleList * @internal param TimezoneInterface $localeDate * @internal param CountryFactory $countryFactory * @internal param Http $response */ public function __construct(Context $context, Registry $registry, ExtensionAttributesFactory $extensionFactory, AttributeValueFactory $customAttributeFactory, Data $paymentData, ScopeConfigInterface $scopeConfig, Logger $logger, UrlInterface $urlBuilder, StoreManagerInterface $storeManager, AbstractResource $resource = null, AbstractDb $resourceCollection = null, array $data = array()) { parent::__construct($context, $registry, $extensionFactory, $customAttributeFactory, $paymentData, $scopeConfig, $logger, $resource, $resourceCollection, $data); $this->urlBuilder = $urlBuilder; $this->storeManager = $storeManager; }
/** * Check whether there are CC types set in configuration * * @param \Magento\Quote\Api\Data\CartInterface|null $quote * @return bool */ public function isAvailable($quote = null) { return $this->getConfigData('cctypes', $quote ? $quote->getStoreId() : null) && parent::isAvailable($quote); }
/** * Assign data to info model instance * * @param array|\Magento\Framework\Object $data * @return \Magento\Payment\Model\Info */ public function assignData($data) { $result = parent::assignData($data); $key = ExpressCheckout::PAYMENT_INFO_TRANSPORT_BILLING_AGREEMENT; if (is_array($data)) { $this->getInfoInstance()->setAdditionalInformation($key, isset($data[$key]) ? $data[$key] : null); } elseif ($data instanceof \Magento\Framework\Object) { $this->getInfoInstance()->setAdditionalInformation($key, $data->getData($key)); } return $result; }
/** * Determines method's availability based on config data and quote amount * * @param \Magento\Quote\Api\Data\CartInterface|null $quote * @return bool */ public function isAvailable(\Magento\Quote\Api\Data\CartInterface $quote = null) { return parent::isAvailable($quote) && $this->getConfigHelper()->isMethodAvailable(); }
/** * Assign data to info model instance * * @param array|DataObject $data * @return $this */ public function assignData(DataObject $data) { parent::assignData($data); $details = array_filter($this->getCheckoutConfig()); $infoInstance = $this->getInfoInstance(); foreach ($details as $key => $value) { $infoInstance->setAdditionalInformation($key, $value); } return $this; }