Example #1
0
 /**
  * Forced fetch reports action
  *
  * @return void
  * @throws \Magento\Framework\Model\Exception
  */
 public function execute()
 {
     try {
         $reports = $this->_settlementFactory->create();
         /* @var $reports \Magento\Paypal\Model\Report\Settlement */
         $credentials = $reports->getSftpCredentials();
         if (empty($credentials)) {
             throw new \Magento\Framework\Model\Exception(__('We found nothing to fetch because of an empty configuration.'));
         }
         foreach ($credentials as $config) {
             try {
                 $fetched = $reports->fetchAndSave(\Magento\Paypal\Model\Report\Settlement::createConnection($config));
                 $this->messageManager->addSuccess(__("We fetched %1 report rows from '%2@%3'.", $fetched, $config['username'], $config['hostname']));
             } catch (\Exception $e) {
                 $this->messageManager->addError(__("We couldn't fetch reports from '%1@%2'.", $config['username'], $config['hostname']));
                 $this->_logger->logException($e);
             }
         }
     } catch (\Magento\Framework\Model\Exception $e) {
         $this->messageManager->addError($e->getMessage());
     } catch (\Exception $e) {
         $this->_logger->logException($e);
     }
     $this->_redirect('*/*/index');
 }
Example #2
0
 /**
  * Forced fetch reports action
  *
  * @return \Magento\Backend\Model\View\Result\Redirect
  */
 public function execute()
 {
     try {
         $reports = $this->_settlementFactory->create();
         /* @var $reports \Magento\Paypal\Model\Report\Settlement */
         $credentials = $reports->getSftpCredentials();
         if (empty($credentials)) {
             throw new \Magento\Framework\Exception\LocalizedException(__('We found nothing to fetch because of an empty configuration.'));
         }
         foreach ($credentials as $config) {
             try {
                 $fetched = $reports->fetchAndSave(\Magento\Paypal\Model\Report\Settlement::createConnection($config));
                 $this->messageManager->addSuccess(__('We fetched %1 report rows from "%2@%3."', $fetched, $config['username'], $config['hostname']));
             } catch (\Exception $e) {
                 $this->messageManager->addError(__('We can\'t fetch reports from "%1@%2."', $config['username'], $config['hostname']));
                 $this->_logger->critical($e);
             }
         }
     } catch (\Magento\Framework\Exception\LocalizedException $e) {
         $this->messageManager->addError($e->getMessage());
     } catch (\Exception $e) {
         $this->_logger->critical($e);
     }
     /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
     $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
     return $resultRedirect->setPath('*/*/index');
 }
 /**
  * Goes to reports.paypal.com and fetches Settlement reports.
  *
  * @return void
  */
 public function execute()
 {
     try {
         /** @var \Magento\Paypal\Model\Report\Settlement $reports */
         $reports = $this->_settlementFactory->create();
         /* @var $reports \Magento\Paypal\Model\Report\Settlement */
         $credentials = $reports->getSftpCredentials(true);
         foreach ($credentials as $config) {
             try {
                 $reports->fetchAndSave(\Magento\Paypal\Model\Report\Settlement::createConnection($config));
             } catch (\Exception $e) {
                 $this->_logger->critical($e);
             }
         }
     } catch (\Exception $e) {
         $this->_logger->critical($e);
     }
 }
Example #4
0
 /**
  * Prepare read-only data and group it by fieldsets
  *
  * @return $this
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 protected function _prepareForm()
 {
     /* @var $model \Magento\Paypal\Model\Report\Settlement\Row */
     $model = $this->_coreRegistry->registry('current_transaction');
     $fieldsets = ['reference_fieldset' => ['fields' => ['transaction_id' => ['label' => $this->_settlement->getFieldLabel('transaction_id')], 'invoice_id' => ['label' => $this->_settlement->getFieldLabel('invoice_id')], 'paypal_reference_id' => ['label' => $this->_settlement->getFieldLabel('paypal_reference_id')], 'paypal_reference_id_type' => ['label' => $this->_settlement->getFieldLabel('paypal_reference_id_type'), 'value' => $model->getReferenceType($model->getData('paypal_reference_id_type'))], 'custom_field' => ['label' => $this->_settlement->getFieldLabel('custom_field')]], 'legend' => __('Reference Information')], 'transaction_fieldset' => ['fields' => ['transaction_event_code' => ['label' => $this->_settlement->getFieldLabel('transaction_event_code'), 'value' => sprintf('%s (%s)', $model->getData('transaction_event_code'), $model->getTransactionEvent($model->getData('transaction_event_code')))], 'transaction_initiation_date' => ['label' => $this->_settlement->getFieldLabel('transaction_initiation_date'), 'value' => $this->formatDate($model->getData('transaction_initiation_date'), \IntlDateFormatter::MEDIUM, true)], 'transaction_completion_date' => ['label' => $this->_settlement->getFieldLabel('transaction_completion_date'), 'value' => $this->formatDate($model->getData('transaction_completion_date'), \IntlDateFormatter::MEDIUM, true)], 'transaction_debit_or_credit' => ['label' => $this->_settlement->getFieldLabel('transaction_debit_or_credit'), 'value' => $model->getDebitCreditText($model->getData('transaction_debit_or_credit'))], 'gross_transaction_amount' => ['label' => $this->_settlement->getFieldLabel('gross_transaction_amount'), 'value' => $this->_localeCurrency->getCurrency($model->getData('gross_transaction_currency'))->toCurrency($model->getData('gross_transaction_amount'))]], 'legend' => __('Transaction Information')], 'fee_fieldset' => ['fields' => ['fee_debit_or_credit' => ['label' => $this->_settlement->getFieldLabel('fee_debit_or_credit'), 'value' => $model->getDebitCreditText($model->getCastedAmount('fee_debit_or_credit'))], 'fee_amount' => ['label' => $this->_settlement->getFieldLabel('fee_amount'), 'value' => $this->_localeCurrency->getCurrency($model->getData('fee_currency'))->toCurrency($model->getCastedAmount('fee_amount'))]], 'legend' => __('PayPal Fee Information')]];
     /** @var \Magento\Framework\Data\Form $form */
     $form = $this->_formFactory->create();
     foreach ($fieldsets as $key => $data) {
         $fieldset = $form->addFieldset($key, ['legend' => $data['legend']]);
         foreach ($data['fields'] as $id => $info) {
             $fieldset->addField($id, 'label', ['name' => $id, 'label' => $info['label'], 'title' => $info['label'], 'value' => isset($info['value']) ? $info['value'] : $model->getData($id)]);
         }
     }
     $this->setForm($form);
     return parent::_prepareForm();
 }
 /**
  * @param array $config
  * @expectedException \InvalidArgumentException
  * @dataProvider createConnectionExceptionDataProvider
  */
 public function testCreateConnectionException($config)
 {
     \Magento\Paypal\Model\Report\Settlement::createConnection($config);
 }
Example #6
0
 /**
  * Check if report with same account and report date already fetched
  *
  * @param \Magento\Paypal\Model\Report\Settlement $report
  * @param string $accountId
  * @param string $reportDate
  * @return $this
  */
 public function loadByAccountAndDate(\Magento\Paypal\Model\Report\Settlement $report, $accountId, $reportDate)
 {
     $adapter = $this->_getReadAdapter();
     $select = $adapter->select()->from($this->getMainTable())->where('account_id = :account_id')->where('report_date = :report_date');
     $data = $adapter->fetchRow($select, array(':account_id' => $accountId, ':report_date' => $reportDate));
     if ($data) {
         $report->addData($data);
     }
     return $this;
 }
Example #7
0
 /**
  * Check if report with same account and report date already fetched
  *
  * @param \Magento\Paypal\Model\Report\Settlement $report
  * @param string $accountId
  * @param string $reportDate
  * @return $this
  */
 public function loadByAccountAndDate(\Magento\Paypal\Model\Report\Settlement $report, $accountId, $reportDate)
 {
     $connection = $this->getConnection();
     $select = $connection->select()->from($this->getMainTable())->where('account_id = :account_id')->where('report_date = :report_date');
     $data = $connection->fetchRow($select, [':account_id' => $accountId, ':report_date' => $reportDate]);
     if ($data) {
         $report->addData($data);
     }
     return $this;
 }