/** * {@inheritdoc} */ public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context) { /** * Prepare database for install */ $setup->startSetup(); /** * PagSeguro Order Status */ $statuses = ['pagseguro_iniciado' => __('PagSeguro Iniciado'), 'pagseguro_aguardando_pagamento' => __('PagSeguro Aguardando Pagamento'), 'pagseguro_cancelada' => __('PagSeguro Cancelada'), 'pagseguro_chargeback_debitado' => __('PagSeguro Chargeback Debitado'), 'pagseguro_devolvida' => __('PagSeguro Devolvida'), 'pagseguro_disponivel' => __('PagSeguro Disponível'), 'pagseguro_em_analise' => __('PagSeguro Em Análise'), 'pagseguro_em_contestacao' => __('PagSeguro Em Contestação'), 'pagseguro_em_disputa' => __('PagSeguro Em Disputa'), 'pagseguro_paga' => __('PagSeguro Paga')]; foreach ($statuses as $code => $info) { $status[] = ['status' => $code, 'label' => $info]; $state[] = ['status' => $code, 'state' => 'new', 'is_default' => 0, 'visible_on_front' => '1']; } $setup->getConnection()->insertArray($setup->getTable('sales_order_status'), ['status', 'label'], $status); /** * PagSeguro Order State */ $state[0]['is_default'] = 1; $setup->getConnection()->insertArray($setup->getTable('sales_order_status_state'), ['status', 'state', 'is_default', 'visible_on_front'], $state); unset($data); /** * PagSeguro Store Reference */ $data[] = ['scope' => 'default', 'scope_id' => 0, 'path' => 'pagseguro/store/reference', 'value' => \UOL\PagSeguro\Helper\Data::generateStoreReference()]; $setup->getConnection()->insertArray($setup->getTable('core_config_data'), ['scope', 'scope_id', 'path', 'value'], $data); /** * Prepare database after install */ $setup->endSetup(); }
/** * Update status in Magento2 Order * * @return bool */ private function updateOrderStatus() { $this->_library->setEnvironment(); $this->_library->setCharset(); $this->_library->setLog(); $transaction = $this->getTransaction(); $order = $this->_order->get($this->_helperData->getReferenceDecryptOrderID($transaction->getReference())); $status = $this->_helperData->getStatusFromKey($transaction->getStatus()); if (!$this->compareStatus($status, $order->getStatus())) { $history = array('status' => $this->_history->setStatus($status), 'comment' => $this->_history->setComment('PagSeguro Notification')); $transactionCode = $transaction->getCode(); $orderId = $order->getId(); $order->setStatus($status); $order->setStatusHistories($history); $order->save(); $this->updateSalesOrderGridTransactionCode($orderId, $transactionCode); $this->updatePagSeguroOrdersTransactionCode($orderId, $transactionCode); } return true; }
/** * Get all transactions and orders and return builded data * * @return array */ public function request() { //load payments by date $this->getPagSeguroAbandoned(); if ($this->_PagSeguroPaymentList->getTransactions()) { foreach ($this->_PagSeguroPaymentList->getTransactions() as $payment) { date_default_timezone_set('UTC'); $order = \UOL\PagSeguro\Helper\Data::getReferenceDecryptOrderID($payment->getReference()); $order = $this->_order->load($order); if ($this->getStoreReference() == \UOL\PagSeguro\Helper\Data::getReferenceDecrypt($payment->getReference())) { if (!is_null($this->_session->getData('store_id'))) { array_push($this->_arrayPayments, $this->build($payment, $order)); } if ($order) { array_push($this->_arrayPayments, $this->build($payment, $order)); } } } } date_default_timezone_set($this->_timezone->getConfigTimezone()); return $this->_arrayPayments; }
/** * Get store reference from magento core_config_data * * @return string */ private function getOrderStoreReference() { return \UOL\PagSeguro\Helper\Data::getOrderStoreReference($this->_scopeConfig->getValue('pagseguro/store/reference'), $this->_order->getEntityId()); }
/** * Set the sender phone if it exist */ private function setSenderPhone() { $shipping = $this->getShippingData(); if (!empty($shipping['telephone'])) { $phone = \UOL\PagSeguro\Helper\Data::formatPhone($shipping['telephone']); $this->_paymentRequest->setSender()->setPhone()->withParameters($phone['areaCode'], $phone['number']); } }
/** * @param $payment * @return string */ protected function decryptReference($payment) { return \UOL\PagSeguro\Helper\Data::getReferenceDecrypt($payment->getReference()); }