diff --git a/Api/Data/Agreements.php b/Api/Data/Agreements.php index 5b5c83c..1a4930a 100644 --- a/Api/Data/Agreements.php +++ b/Api/Data/Agreements.php @@ -18,6 +18,7 @@ namespace Dotpay\Payment\Api\Data; +use Dotpay\Exception\Resource\ApiException; use Dotpay\Resource\Payment; use Dotpay\Resource\Channel\Request; use Dotpay\Model\Configuration; @@ -59,14 +60,19 @@ public function __construct($sellerId, $testMode, $amount, $currency, $language) */ public function get() { - if ($this->agreementsData === null) { - $config = new Configuration(DOTPAY_MODNAME); - $config->setTestMode($this->request->isTestMode()); - $paymentApi = new Payment($config, new Curl()); - $infoStructure = $paymentApi->getChannelListForRequest($this->request); - $this->agreementsData = $infoStructure->getUniversalAgreements(); + try { + if ($this->agreementsData === null) { + $config = new Configuration(DOTPAY_MODNAME); + $config->setTestMode($this->request->isTestMode()); + $paymentApi = new Payment($config, new Curl()); + $infoStructure = $paymentApi->getChannelListForRequest($this->request); + $this->agreementsData = $infoStructure->getUniversalAgreements(); + } + } + catch (ApiException $e) + { + return []; } - return $this->agreementsData; } diff --git a/Api/Data/OrderInterface.php b/Api/Data/OrderInterface.php index 79f6e02..9e0e8c1 100644 --- a/Api/Data/OrderInterface.php +++ b/Api/Data/OrderInterface.php @@ -37,4 +37,9 @@ interface OrderInterface * Id of status canceled. */ const STATUS_CANCELED = 'dotpay_canceled'; + + /** + * Id of status possible duplication. + */ + const STATUS_DUPLICATE = 'dotpay_duplicate'; } diff --git a/Api/Data/OrderRetryPaymentInterface.php b/Api/Data/OrderRetryPaymentInterface.php new file mode 100644 index 0000000..6e1491f --- /dev/null +++ b/Api/Data/OrderRetryPaymentInterface.php @@ -0,0 +1,125 @@ + + * @copyright Dotpay + * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) + */ + +namespace Dotpay\Payment\Api\Data; + +/** + * Interface of card brand model. + */ +interface OrderRetryPaymentInterface +{ + /** + * Column name of brand id in database. + */ + const LINK_ID = 'entity_id'; + + /** + * Column name of brand name in database. + */ + const ORDER_ID = 'order_id'; + + /** + * Column name of brand logo in database. + */ + const URL = 'url'; + + /** + * Column name of brand logo in database. + */ + const TOKEN = 'token'; + + /** + * Return id of card brand. + * + * @return int + */ + public function getId(); + + /** + * Set id of card brand. + * + * @param int $id id of card brand + * + * @return $this + */ + public function setId($id); + + /** + * Return name of card brand. + * + * @return string + */ + public function getOrderId(); + + /** + * Set name of card brand. + * + * @param string $orderId Name of card brand + * + * @return $this + */ + public function setOrderId($orderId); + + /** + * Return url of card brand's logo. + * + * @return string + */ + public function getUrl(); + + /** + * Set url of card brand's logo. + * + * @param string $url Url of card brand + * + * @return $this + */ + public function setUrl($url); + + /** + * Return url of card brand's logo. + * + * @return string + */ + public function getToken(); + + /** + * Set url of card brand's logo. + * + * @param string $token Url of card brand + * + * @return $this + */ + public function setToken($token); + + /** + * Return url of card brand's logo. + * + * @return string + */ + public function getCreatedAt(); + + /** + * Set url of card brand's logo. + * + * @param string $createdAt Url of card brand + * + * @return $this + */ + public function setCreatedAt($createdAt); +} diff --git a/Block/Adminhtml/Order/View/RetryPayment.php b/Block/Adminhtml/Order/View/RetryPayment.php new file mode 100644 index 0000000..9037c63 --- /dev/null +++ b/Block/Adminhtml/Order/View/RetryPayment.php @@ -0,0 +1,88 @@ +_orderRetryPaymentFactory = $orderRetryPaymentFactory; + parent::__construct($context, $registry, $adminHelper, $data); + } + + public function getRetryPayments() + { + $collection = $this->_orderRetryPaymentFactory->create()->getCollection()->addFieldToFilter('order_id', $this->getOrder()->getEntityId()); + return $collection; + } + + public function getSaveUrl() + { + return $this->getUrl("dotpay/order_retryPayment/save", ["order_id" => $this->getOrder()->getEntityId()]); + } + + public function getDeleteUrl($id) + { + return $this->getUrl("dotpay/order_retryPayment/delete", ["id" => $id]); + } + + public function canRetry() + { + $status = $this->getOrder()->getStatus(); + if( + $status === OrderInterface::STATUS_PENDING + && count($this->getRetryPayments()) < 1 + ) + return true; + + return false; + } + + public function canDelete() + { + $status = $this->getOrder()->getStatus(); + if( + $status === OrderInterface::STATUS_PENDING + ) + return true; + + return false; + } + + public function canShowBlock() + { + $status = $this->getOrder()->getStatus(); + if(in_array($status, [OrderInterface::STATUS_PENDING, OrderInterface::STATUS_CANCELED, OrderInterface::STATUS_COMPLETE, OrderInterface::STATUS_DUPLICATE])) + return true; + + $statuses = $this->getOrder()->getAllStatusHistory(); + foreach($statuses as $status) + { + if(in_array($status->getStatus(), [OrderInterface::STATUS_PENDING, OrderInterface::STATUS_CANCELED, OrderInterface::STATUS_COMPLETE, OrderInterface::STATUS_DUPLICATE])) + return true; + } + return false; + } +} \ No newline at end of file diff --git a/Controller/Adminhtml/Order/RetryPayment.php b/Controller/Adminhtml/Order/RetryPayment.php new file mode 100644 index 0000000..9931c4a --- /dev/null +++ b/Controller/Adminhtml/Order/RetryPayment.php @@ -0,0 +1,131 @@ +context = $context; + $this->customerSession = $customerSession; + $this->checkoutSession = $checkoutSession; + $this->coreRegistry = $coreRegistry; + $this->resultPageFactory = $resultPageFactory; + $this->objectManager = $context->getObjectManager(); + $this->orderRepository = $orderRepository; + $this->urlHelper = $urlHelper; + $this->configHelper = $configHelper; + + parent::__construct($context); + + Loader::load( + new Parser(Bootstrap::getMainDir().'/di.xml') + ); + + $this->config = Configuration::createFromData($configHelper); + } + + /** + * Initialize order model instance + * + * @return \Magento\Sales\Api\Data\OrderInterface|false + */ + protected function _initOrder($id) + { + try { + $order = $this->orderRepository->get($id); + } catch (NoSuchEntityException $e) { + $this->messageManager->addError(__('This order no longer exists.')); + $this->_actionFlag->set('', self::FLAG_NO_DISPATCH, true); + return false; + } catch (InputException $e) { + $this->messageManager->addError(__('This order no longer exists.')); + $this->_actionFlag->set('', self::FLAG_NO_DISPATCH, true); + return false; + } + return $order; + } +} \ No newline at end of file diff --git a/Controller/Adminhtml/Order/RetryPayment/Delete.php b/Controller/Adminhtml/Order/RetryPayment/Delete.php new file mode 100644 index 0000000..b754f2c --- /dev/null +++ b/Controller/Adminhtml/Order/RetryPayment/Delete.php @@ -0,0 +1,51 @@ +getRequest()->getParam('id'); + $orderId = 0; + try { + $curl = new Curl(); + + $sellerResource = new SellerResource($this->config, $curl); + + $links = $this->_objectManager->get(OrderRetryPayment::class)->getCollection()->addFieldToFilter('entity_id', array('eq' => $id))->load(); + if($links->getSize() == 1) + { + $link = $links->fetchItem(); + $seller = Seller::createFromConfiguration($this->config); + $ret = $sellerResource->deletePaymentLink($seller, $link->getToken()); + $orderId = $link->getOrderId(); + $link->delete(); + $this->messageManager->addSuccessMessage(__('Payment link deleted successfully')); + } + + } catch(\Exception $e) { + $this->messageManager->addErrorMessage(__('Payment link could not be deleted')); + } + $path = 'sales/order/view'; + $pathParams = ['order_id' => $orderId]; + return $this->resultRedirectFactory->create()->setPath($path, $pathParams); + + } +} \ No newline at end of file diff --git a/Controller/Adminhtml/Order/RetryPayment/Save.php b/Controller/Adminhtml/Order/RetryPayment/Save.php new file mode 100644 index 0000000..2aa4b97 --- /dev/null +++ b/Controller/Adminhtml/Order/RetryPayment/Save.php @@ -0,0 +1,63 @@ +_initOrder($this->getRequest()->getParam('order_id')); + $sellerResource = new SellerResource($this->config, $curl); + $paymentLink = PaymentLink::createFromData(new \Dotpay\Payment\Helper\Data\PaymentLink($order)); + $paymentLink->setUrl($this->urlHelper->getBackUrl()); + $paymentLink->setUrlc($this->urlHelper->getNotificationUrl()); + $locale = strstr($this->_localeResolver->getLocale(), "_", true); + $paymentLink->setLanguage($locale); + $seller = Seller::createFromConfiguration($this->config); + $link = $sellerResource->getNewPaymentLink($seller, $paymentLink); + $chk = hash('sha256', $this->config->getPin().$link['token']); + $url = $link['payment_url'] . "&chk=" . $chk; + $this->_objectManager->create(OrderRetryPayment::class) + ->setOrderId($order->getEntityId()) + ->setUrl($url) + ->setToken($link['token']) + ->save(); + $this->messageManager->addSuccessMessage(__('Payment link generated successfully')); + } catch(\Exception $e) { + exit; + $this->messageManager->addErrorMessage(__('Payment link could not be created')); + } + + $path = 'sales/order/view'; + $pathParams = ['order_id' => $order->getEntityId()]; + return $this->resultRedirectFactory->create()->setPath($path, $pathParams); + } + + protected function _isAllowed() + { + return true; + } +} diff --git a/Controller/Payment/Confirm.php b/Controller/Payment/Confirm.php index aa35a74..9565d86 100644 --- a/Controller/Payment/Confirm.php +++ b/Controller/Payment/Confirm.php @@ -24,6 +24,7 @@ use Dotpay\Model\Operation; use Dotpay\Model\Notification; use Dotpay\Model\Payment; +use Dotpay\Payment\Api\Data\OrderInterface; use Dotpay\Processor\Confirmation; use Dotpay\Tool\Curl; use Dotpay\Resource\Payment as PaymentResource; @@ -189,6 +190,10 @@ public function makePaymentFn(Operation $operation) ] ) === true ) { + if($operation->getStatus() === Operation::STATUS_COMPLETE) { + $order->addStatusToHistory($this->configHelper->getStatusDuplicated(), __('The payment has been confirmed twice - check for possible duplicated payment'), false); + $order->save(); + } return true; } diff --git a/Helper/Data/Configuration.php b/Helper/Data/Configuration.php index 0751100..2fce80f 100644 --- a/Helper/Data/Configuration.php +++ b/Helper/Data/Configuration.php @@ -149,6 +149,11 @@ public function getStatusCanceled() return $this->getData('payment/dotpay_main/status_canceled'); } + public function getStatusDuplicated() + { + return $this->getData('payment/dotpay_main/status_duplicated'); + } + public function getOcVisible() { return $this->getData('payment/dotpay_oc/active'); diff --git a/Helper/Data/Customer.php b/Helper/Data/Customer.php index 7e9f628..80938e1 100644 --- a/Helper/Data/Customer.php +++ b/Helper/Data/Customer.php @@ -31,22 +31,20 @@ class Customer implements CustomerProviderInterface private $customer; /** - * @var \Dotpay\Payment\Helper\Locale Locale helper providing data about locality + * @var \Magento\Sales\Model\Order */ - protected $localeHeper; + private $order; /** * Initialize the provider. * - * @param \Magento\Customer\Model\Session $customerSession - * @param \Dotpay\Payment\Helper\Locale $localeHelper + * @param \Magento\Sales\Model\Order $order Magento order object */ public function __construct( - \Magento\Customer\Model\Session $customerSession, - \Dotpay\Payment\Helper\Locale $localeHelper + \Magento\Sales\Model\Order $order ) { - $this->customer = $customerSession->getCustomer(); - $this->localeHeper = $localeHelper; + $this->order = $order; + $this->customer = $order->getCustomer(); } /** @@ -66,7 +64,7 @@ public function getId() */ public function getEmail() { - $this->customer->getEmail(); + return $this->order->getCustomerEmail(); } /** @@ -76,7 +74,7 @@ public function getEmail() */ public function getFirstName() { - return $this->customer->getFirstname(); + return $this->order->getBillingAddress()->getFirstname(); } /** @@ -86,7 +84,7 @@ public function getFirstName() */ public function getLastName() { - return $this->customer->getLastname(); + return $this->order->getBillingAddress()->getLastname(); } /** @@ -96,7 +94,7 @@ public function getLastName() */ public function getStreet() { - $streetOriginal = $this->customer->getDefaultBillingAddress()->getStreet(); + $streetOriginal = $this->order->getBillingAddress()->getStreet(); $streetData = is_array($streetOriginal) ? implode(' ', $streetOriginal) : $streetOriginal; return $streetData; @@ -119,7 +117,7 @@ public function getBuildingNumber() */ public function getPostCode() { - return $this->customer->getDefaultBillingAddress()->getPostcode(); + return $this->order->getBillingAddress()->getPostcode(); } /** @@ -129,7 +127,7 @@ public function getPostCode() */ public function getCity() { - return $this->customer->getDefaultBillingAddress()->getCity(); + return $this->order->getBillingAddress()->getCity(); } /** @@ -139,7 +137,9 @@ public function getCity() */ public function getCountry() { - return $this->customer->getDefaultBillingAddress()->getCountryId(); + $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); + $country = $objectManager->create('\Magento\Directory\Model\Country')->load($this->order->getBillingAddress()->getCountryId())->getData('iso3_code'); + return $country; } /** @@ -149,7 +149,8 @@ public function getCountry() */ public function getPhone() { - return $this->customer->getDefaultBillingAddress()->getTelephone(); + //return ""; + return $this->order->getShippingAddress()->getTelephone(); } /** @@ -159,7 +160,7 @@ public function getPhone() */ public function getLanguage() { - return $this->localeHeper->getLanguage(); + return 'pl'; } /** @@ -169,10 +170,11 @@ public function getLanguage() */ public function isAddressAvailable() { + //return false; return $this->getStreet() !== '' - && $this->postCode !== '' - && $this->city !== '' - && $this->country !== '' - && $this->phone !== ''; + && $this->getPostCode() !== '' + && $this->getCity() !== '' + && $this->getCountry() !== '' + && $this->getPhone() !== ''; } } diff --git a/Helper/Data/PaymentLink.php b/Helper/Data/PaymentLink.php new file mode 100644 index 0000000..19451f9 --- /dev/null +++ b/Helper/Data/PaymentLink.php @@ -0,0 +1,102 @@ + + * @copyright Dotpay + * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) + */ + +namespace Dotpay\Payment\Helper\Data; + +use Dotpay\Model\Payer; +use Dotpay\Provider\PaymentLinkProviderInterface; + +/** + * Provider of payment link data. + */ +class PaymentLink implements PaymentLinkProviderInterface +{ + + /** + * @var \Magento\Sales\Model\Order $order Magento order object + */ + private $order = null; + + /** + * Initialize the provider. + * + * @param \Magento\Sales\Model\Order $order Magento order object + */ + public function __construct( + \Magento\Sales\Model\Order $order + ) { + $this->order = $order; + } + + /** + * @inheritDoc + */ + public function getType() + { + return 0; + } + + /** + * @inheritDoc + */ + public function getAmount() + { + return round($this->order->getGrandTotal(), 2); + } + + /** + * @inheritDoc + */ + public function getCurrency() + { + return $this->order->getOrderCurrencyCode(); + } + + /** + * @inheritDoc + */ + public function getControl() + { + return $this->order->getEntityId(); + } + + /** + * @inheritDoc + */ + public function getDescription() + { + return __('Order ID: %1', $this->order->getRealOrderId())."/".$this->getControl()."/".__('RE'); + } + + /** + * @inheritDoc + */ + public function getPayer() + { + return new Customer($this->order); + } + + /** + * @inheritDoc + */ + public function getIgnoreLastPaymentChannel() + { + return 1; + } + +} \ No newline at end of file diff --git a/Model/OrderRetryPayment.php b/Model/OrderRetryPayment.php new file mode 100644 index 0000000..8070e6c --- /dev/null +++ b/Model/OrderRetryPayment.php @@ -0,0 +1,117 @@ + + * @copyright Dotpay + * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) + */ + +namespace Dotpay\Payment\Model; + +use Dotpay\Payment\Api\Data\OrderRetryPaymentInterface; +use Magento\Framework\Model\AbstractModel; +use Magento\Framework\DataObject\IdentityInterface; + +/** + * Model of credit card's brand + */ +class OrderRetryPayment extends AbstractModel implements OrderRetryPaymentInterface, IdentityInterface +{ + /** + * Identifier of cache tag. + */ + const CACHE_TAG = 'dotpay_order_retry_payment'; + + /** + * Pseudoconstructor for binding model with its resource. + */ + protected function _construct() + { + $this->_init('Dotpay\Payment\Model\Resource\OrderRetryPayment'); + } + + /** + * Return list of identities. + * + * @return array + */ + public function getIdentities() + { + return [self::CACHE_TAG.'_'.$this->getId()]; + } + + /** + * @inheritDoc + */ + public function getOrderId() + { + return $this->getData(self::ORDER_ID); + } + + /** + * @inheritDoc + */ + public function setOrderId($orderId) + { + return $this->setData(self::ORDER_ID, $orderId); + } + + /** + * @inheritDoc + */ + public function getUrl() + { + return $this->getData(self::URL); + } + + /** + * @inheritDoc + */ + public function setUrl($url) + { + return $this->setData(self::URL, $url); + } + + /** + * @inheritDoc + */ + public function getToken() + { + return $this->getData(self::TOKEN); + } + + /** + * @inheritDoc + */ + public function setToken($token) + { + return $this->setData(self::TOKEN, $token); + } + + /** + * @inheritDoc + */ + public function getCreatedAt() + { + return ""; + } + + /** + * @inheritDoc + */ + public function setCreatedAt($createdAt) + { + return $this;//->setData(self::ORDER_ID, $orderId); + } + +} diff --git a/Model/Resource/OrderRetryPayment.php b/Model/Resource/OrderRetryPayment.php new file mode 100644 index 0000000..1db19a6 --- /dev/null +++ b/Model/Resource/OrderRetryPayment.php @@ -0,0 +1,35 @@ + + * @copyright Dotpay + * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) + */ + +namespace Dotpay\Payment\Model\Resource; + +use Magento\Framework\Model\ResourceModel\Db\AbstractDb; + +/** + * Resource model of saved credit cards brand. + */ +class OrderRetryPayment extends AbstractDb +{ + /** + * Pseudoconstructor with initialization of the model. + */ + protected function _construct() + { + $this->_init('dotpay_order_retry_payments', 'entity_id'); + } +} diff --git a/Model/Resource/OrderRetryPayment/Collection.php b/Model/Resource/OrderRetryPayment/Collection.php new file mode 100644 index 0000000..fdc641d --- /dev/null +++ b/Model/Resource/OrderRetryPayment/Collection.php @@ -0,0 +1,43 @@ + + * @copyright Dotpay + * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) + */ + +namespace Dotpay\Payment\Model\Resource\OrderRetryPayment; + +use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection; + +/** + * Collection of card brands. + */ +class Collection extends AbstractCollection +{ + /** + * @var string Name of column with identifier of saved card brands + */ + protected $_idFieldName = 'entity_id'; + + /** + * Pseudoconstructor with initialization of the collection. + */ + protected function _construct() + { + $this->_init( + 'Dotpay\Payment\Model\OrderRetryPayment', + 'Dotpay\Payment\Model\Resource\OrderRetryPayment' + ); + } +} diff --git a/Setup/InstallData.php b/Setup/InstallData.php index bd64947..3f71562 100644 --- a/Setup/InstallData.php +++ b/Setup/InstallData.php @@ -43,6 +43,7 @@ public function install( OrderInterface::STATUS_PENDING => __('Dotpay payment pending'), OrderInterface::STATUS_COMPLETE => __('Dotpay payment complete'), OrderInterface::STATUS_CANCELED => __('Dotpay payment canceled'), + OrderInterface::STATUS_DUPLICATE => __('Dotpay payment possible duplicate'), ]; $statusData = []; foreach ($availableStatuses as $code => $label) { @@ -73,6 +74,11 @@ public function install( 'state' => \Magento\Sales\Model\Order::STATE_PROCESSING, 'is_default' => 1, 'visible_on_front' => 1, + ], [ + 'status' => OrderInterface::STATUS_DUPLICATE, + 'state' => \Magento\Sales\Model\Order::STATE_PROCESSING, + 'is_default' => 1, + 'visible_on_front' => 1, ], [ 'status' => OrderInterface::STATUS_CANCELED, 'state' => \Magento\Sales\Model\Order::STATE_PENDING_PAYMENT, diff --git a/Setup/InstallSchema.php b/Setup/InstallSchema.php index eba825b..e68e7d0 100644 --- a/Setup/InstallSchema.php +++ b/Setup/InstallSchema.php @@ -43,6 +43,7 @@ public function install( $this->installCardBrandsTable($installer); $this->installCreditCardsTable($installer); $this->installInstructionsTable($installer); + $this->installRetryPaymentsTable($installer); $installer->endSetup(); } @@ -156,4 +157,31 @@ private function installInstructionsTable(\Magento\Framework\Setup\SchemaSetupIn $installer->getConnection()->createTable($table); } + + private function installRetryPaymentsTable(\Magento\Framework\Setup\SchemaSetupInterface $installer) + { + $table = $installer->getConnection() + ->newTable($installer->getTable('dotpay_order_retry_payments')) + ->addColumn('entity_id', Table::TYPE_INTEGER, 10, ['identity' => true, 'unsigned' => true, + 'nullable' => false, 'primary' => true, ], 'Payment id') + ->addColumn('order_id', Table::TYPE_INTEGER, 10, ['nullable' => true, 'unsigned' => true], 'Id of the order') + ->addColumn('url', Table::TYPE_TEXT, 255, ['nullable' => true], 'Payment url') + ->addColumn('token', Table::TYPE_TEXT, 255, ['nullable' => true], 'Request token') + ->addColumn('created_date', Table::TYPE_DATETIME, null, ['nullable' => true], 'Date when link was created') + ->addForeignKey( + $installer->getFkName( + 'dotpay_order_retry_payments', + 'entity_id', + 'sales_order', + 'order_id' + ), + 'order_id', + $installer->getTable('sales_order'), + 'entity_id', + \Magento\Framework\DB\Ddl\Table::ACTION_SET_NULL + ) + ->setComment('Retry payment links generated for orders'); + + $installer->getConnection()->createTable($table); + } } diff --git a/Setup/UninstallSchema.php b/Setup/UninstallSchema.php index 77be4d7..fef78b1 100644 --- a/Setup/UninstallSchema.php +++ b/Setup/UninstallSchema.php @@ -39,6 +39,7 @@ public function uninstall( $connection->dropTable($connection->getTableName('dotpay_credit_cards')); $connection->dropTable($connection->getTableName('dotpay_card_brands')); $connection->dropTable($connection->getTableName('dotpay_instructions')); + $connection->dropTable($connection->getTableName('dotpay_order_retry_payments')); $setup->endSetup(); } diff --git a/Setup/UpgradeSchema.php b/Setup/UpgradeSchema.php new file mode 100644 index 0000000..2dc2afb --- /dev/null +++ b/Setup/UpgradeSchema.php @@ -0,0 +1,71 @@ + + * @copyright Dotpay + * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) + */ + +namespace Dotpay\Payment\Setup; + +use Magento\Framework\Setup\ModuleContextInterface; +use Magento\Framework\Setup\UpgradeSchemaInterface; +use Magento\Framework\DB\Ddl\Table; +use Magento\Framework\Setup\SchemaSetupInterface; + + /** + * Upgrade of required database schema during upgrading of the payment module. + */ +class UpgradeSchema implements UpgradeSchemaInterface +{ + /** + * Upgrades DB schema for a module. + * + * @param \Magento\Framework\Setup\SchemaSetupInterface $setup + * @param \Magento\Framework\Setup\ModuleContextInterface $context + */ + public function upgrade( SchemaSetupInterface $setup, ModuleContextInterface $context ) { + $installer = $setup; + + $installer->startSetup(); + + if(version_compare($context->getVersion(), '1.0.9.2', '<')) { + + $table = $installer->getConnection() + ->newTable($installer->getTable('dotpay_order_retry_payments')) + ->addColumn('entity_id', Table::TYPE_INTEGER, 10, ['identity' => true, 'unsigned' => true, + 'nullable' => false, 'primary' => true, ], 'Payment id') + ->addColumn('order_id', Table::TYPE_INTEGER, 10, ['nullable' => true, 'unsigned' => true], 'Id of the order') + ->addColumn('url', Table::TYPE_TEXT, 255, ['nullable' => true], 'Payment url') + ->addColumn('token', Table::TYPE_TEXT, 255, ['nullable' => true], 'Request token') + ->addColumn('created_date', Table::TYPE_DATETIME, null, ['nullable' => true], 'Date when link was created') + ->addForeignKey( + $installer->getFkName( + 'dotpay_order_retry_payments', + 'entity_id', + 'sales_order', + 'order_id' + ), + 'order_id', + $installer->getTable('sales_order'), + 'entity_id', + \Magento\Framework\DB\Ddl\Table::ACTION_SET_NULL + ) + ->setComment('Retry payment links generated for orders'); + + $installer->getConnection()->createTable($table); + } + + $installer->endSetup(); + } +} diff --git a/composer.json b/composer.json index c056532..c4c7b4a 100755 --- a/composer.json +++ b/composer.json @@ -14,11 +14,11 @@ "magento/module-backend": ">=100.1", "magento/module-directory": ">=100.1", "magento/framework": ">=100.1", - "dotpay/PHP-SDK": ">=1.0.11" + "dotpay/PHP-SDK": ">=1.0.13" }, "homepage": "www.dotpay.pl", "type": "magento2-module", - "version": "1.0.9.1", + "version": "1.0.11", "license": [ "GPL-3.0" ], "autoload": { "files": [ "registration.php" ], diff --git a/etc/adminhtml/routes.xml b/etc/adminhtml/routes.xml new file mode 100644 index 0000000..db47232 --- /dev/null +++ b/etc/adminhtml/routes.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/etc/adminhtml/system/advanced.xml b/etc/adminhtml/system/advanced.xml index 64f9a35..f782503 100755 --- a/etc/adminhtml/system/advanced.xml +++ b/etc/adminhtml/system/advanced.xml @@ -37,7 +37,13 @@ payment/dotpay_main/status_canceled - + + + Dotpay\Payment\Model\Config\Source\Order\Status + payment/dotpay_main/status_duplicated + + + Magento\Config\Model\Config\Source\Yesno payment/dotpay_main/show_shortcut diff --git a/etc/config.xml b/etc/config.xml index db66703..a911b27 100755 --- a/etc/config.xml +++ b/etc/config.xml @@ -23,9 +23,10 @@ dotpay_pending dotpay_complete dotpay_canceled + status_duplicated 1 - + 0 DotpayOcAdapter One Click card payments diff --git a/etc/module.xml b/etc/module.xml index a3165ea..44d8c75 100755 --- a/etc/module.xml +++ b/etc/module.xml @@ -1,7 +1,7 @@ - + diff --git a/i18n/pl_PL.csv b/i18n/pl_PL.csv index 628bbc0..6b0f3a5 100644 --- a/i18n/pl_PL.csv +++ b/i18n/pl_PL.csv @@ -1,5 +1,6 @@ "BLIK via Dotpay","BLIK przez Dotpay" -"Card payments", "Płatność kartą" +"Card payments","Płatność kartą" +"One Click card payments","One Click płatność kartą" "Credit card via Dotpay","Karty płatnicze przez Dotpay" "Masterpass via Dotpay","Masterpass przez Dotpay" "Credit card (One Click) via Dotpay","Płatności One Click przez Dotpay" @@ -156,3 +157,13 @@ "One Click card payments via Dotpay","Płatność 1 click kartą dzięki Dotpay" "Acceptance Mark","Zaakceptuj wymagane zgody" "Pay using","Zapłać za pomocą" +"Dotpay payment possible duplicate","Płatność Dotpay prawdopodobnie zduplikowana" +"Payment link generated successfully","Link płatności wygenerowany poprawnie" +"Payment link could not be created","Wystąpił błąd podczas generowania linku" +"Payment link deleted successfully","Link płatności usunięty" +"Payment link could not be deleted","Wystąpił błąd podczas usuwania linku" +"Generate payment link","Wygeneruj nowy link płatności" +"You can generate a payment link for this order and send it to the customer","Możesz wygenerować link płatniczy do tego zamówienia i wysłać go do Klienta" +"Action","Akcja" +"delete","usuń" +"Generate payment link","Wygenruj link do płatności" diff --git a/view/adminhtml/layout/sales_order_view.xml b/view/adminhtml/layout/sales_order_view.xml new file mode 100644 index 0000000..1122fe2 --- /dev/null +++ b/view/adminhtml/layout/sales_order_view.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/view/adminhtml/templates/order/view/retrypayment.phtml b/view/adminhtml/templates/order/view/retrypayment.phtml new file mode 100644 index 0000000..dcf5fcd --- /dev/null +++ b/view/adminhtml/templates/order/view/retrypayment.phtml @@ -0,0 +1,35 @@ +canShowBlock()) : ?> +
+
+ +
+ getRetryPayments()) : ?> + canRetry()) : ?> + + + + + + + + + getRetryPayments() as $payment) : ?> + + + + + + + + + +
URL
+
getUrl(); ?>
+
canDelete()) : ?>
+ + + canRetry()) : ?> +
+ + + diff --git a/view/adminhtml/web/retrypayment.css b/view/adminhtml/web/retrypayment.css new file mode 100644 index 0000000..7ace357 --- /dev/null +++ b/view/adminhtml/web/retrypayment.css @@ -0,0 +1,8 @@ +.select-all { + -webkit-touch-callout: all; /* iOS Safari */ + -webkit-user-select: all; /* Safari */ + -khtml-user-select: all; /* Konqueror HTML */ + -moz-user-select: all; /* Firefox */ + -ms-user-select: all; /* Internet Explorer/Edge */ + user-select: all; /* Chrome and Opera */ +} diff --git a/view/frontend/web/template/payment/oc-form.html b/view/frontend/web/template/payment/oc-form.html index beb0bed..a00c0a2 100755 --- a/view/frontend/web/template/payment/oc-form.html +++ b/view/frontend/web/template/payment/oc-form.html @@ -29,7 +29,7 @@ - +