diff --git a/Api/Data/SubscribInterface.php b/Api/Data/SubscribInterface.php index fa7128d..88fb89e 100644 --- a/Api/Data/SubscribInterface.php +++ b/Api/Data/SubscribInterface.php @@ -51,7 +51,7 @@ public function getId(); /** * Set SubscriptionId * - * @param string $SubscriptionId + * @param string $SubscriptionId * @return $this */ public function setSubscriptionId($SubscriptionId); @@ -59,7 +59,7 @@ public function setSubscriptionId($SubscriptionId); /** * Set Status * - * @param string $status + * @param string $status * @return $this */ public function setStatus($status); @@ -67,7 +67,7 @@ public function setStatus($status); /** * Set Value * - * @param string $value + * @param string $value * @return $this */ public function setValue($value); @@ -75,7 +75,7 @@ public function setValue($value); /** * Set Crated At * - * @param int $nextChargeAt + * @param int $nextChargeAt * @return $this */ public function setNextChargeAt($nextChargeAt); @@ -83,7 +83,7 @@ public function setNextChargeAt($nextChargeAt); /** * Set ID * - * @param int $id + * @param int $id * @return $this */ public function setId($id); diff --git a/Block/Adminhtml/Plan/Edit.php b/Block/Adminhtml/Plan/Edit.php deleted file mode 100644 index 4031725..0000000 --- a/Block/Adminhtml/Plan/Edit.php +++ /dev/null @@ -1,98 +0,0 @@ -_coreRegistry = $registry; - parent::__construct($context, $data); - } - - /** - * Plan edit block - * - * @return void - */ - protected function _construct() - { - $this->_objectId = 'entity_id'; - $this->_blockGroup = 'Razorpay_Subscription'; - $this->_controller = 'adminhtml_plan'; - - parent::_construct(); - - if ($this->_isAllowedAction('Razorpay_Subscription::plan_save')) { - $this->buttonList->update('save', 'label', __('Save Plan')); - $this->buttonList->add( - 'saveandcontinue', - [ - 'label' => __('Save and Continue Edit'), - 'class' => 'save', - 'data_attribute' => [ - 'mage-init' => [ - 'button' => ['event' => 'saveAndContinueEdit', 'target' => '#edit_form'], - ], - ] - ], - -100 - ); - } else { - $this->buttonList->remove('save'); - } - - } - - /** - * Get header with Plan name - * - * @return \Magento\Framework\Phrase - */ - public function getHeaderText() - { - if ($this->_coreRegistry->registry('subscribed_plan')->getId()) { - return __("Edit Plan '%1'", $this->escapeHtml($this->_coreRegistry->registry('subscribed_plan')->getName())); - } else { - return __('New Plan'); - } - } - - /** - * Check permission for passed action - * - * @param string $resourceId - * @return bool - */ - protected function _isAllowedAction($resourceId) - { - return $this->_authorization->isAllowed($resourceId); - } - - /** - * Getter of url for "Save and Continue" button - * tab_id will be replaced by desired by JS later - * - * @return string - */ - protected function _getSaveAndContinueUrl() - { - return $this->getUrl('subscribed/*/save', ['_current' => true, 'back' => 'edit', 'active_tab' => '']); - } -} \ No newline at end of file diff --git a/Block/Adminhtml/Plan/Edit/Button/Generic.php b/Block/Adminhtml/Plan/Edit/Button/Generic.php new file mode 100644 index 0000000..4e3c9aa --- /dev/null +++ b/Block/Adminhtml/Plan/Edit/Button/Generic.php @@ -0,0 +1,37 @@ +context = $context; + } + + /** + * @return mixed + */ + public function getEntityId() + { + return $this->context->getRequest()->getParam('entity_id'); + } + + /** + * @param $route + * @param $params + * @return mixed + */ + public function getUrl($route = '', $params = []) + { + return $this->context->getUrlBuilder()->getUrl($route, $params); + } +} diff --git a/Block/Adminhtml/Plan/Edit/Button/Save.php b/Block/Adminhtml/Plan/Edit/Button/Save.php new file mode 100644 index 0000000..db0de15 --- /dev/null +++ b/Block/Adminhtml/Plan/Edit/Button/Save.php @@ -0,0 +1,26 @@ + __('Save'), + 'class' => 'save primary', + 'data_attribute' => [ + 'mage-init' => ['button' => ['event' => 'save']], + 'form-role' => 'save', + ], + 'sort_order' => 90, + ]; + } +} \ No newline at end of file diff --git a/Block/Adminhtml/Plan/Edit/Form.php b/Block/Adminhtml/Plan/Edit/Form.php deleted file mode 100644 index 499ac08..0000000 --- a/Block/Adminhtml/Plan/Edit/Form.php +++ /dev/null @@ -1,196 +0,0 @@ -_systemStore = $systemStore; - $this->_status = $status; - $this->_productList = $productList; - parent::__construct($context, $registry, $formFactory, $data); - } - - /** - * Init form - * - * @return void - */ - protected function _construct() - { - parent::_construct(); - $this->setId('plan_form'); - $this->setTitle(__('Plan Information')); - } - - /** - * Prepare form - * - * @return $this - */ - protected function _prepareForm() - { - /** @var \Razorpay\Subscription\Model\Plans $model */ - $model = $this->_coreRegistry->registry('subscribed_plan'); - - /** @var \Magento\Framework\Data\Form $form */ - $form = $this->_formFactory->create( - ['data' => ['id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post']] - ); - - $form->setHtmlIdPrefix('plan_'); - - $fieldset = $form->addFieldset( - 'base_fieldset', - ['legend' => __('Plan Details'), 'class' => 'fieldset-wide'] - ); - - if ($model->getId()) { - $fieldset->addField('entity_id', 'hidden', ['name' => 'entity_id']); - $readonly = true; - }else { $readonly=false;} - - $fieldset->addField( - 'plan_name', - 'text', - ['name' => 'plan_name', 'label' => __('Plan Name'), 'title' => __('Plan Name'), 'required' => true,'disabled'=>$readonly] - ); - - $fieldset->addField( - 'plan_desc', - 'textarea', - ['name' => 'plan_desc', 'label' => __('Plan Description'), 'title' => __('Plan Description'), 'required' => true,'disabled'=>$readonly] - ); - // product List - Dropdown - $productList = $this->_productList->toOptionArray(); - - $fieldset->addField( - 'magento_product_id', - 'select', - ['name' => 'magento_product_id', 'label' => __('Select Product'), 'title' => __('Select Product'), 'required' => true, 'values' => $productList,'disabled'=>$readonly] - ); - $fieldset->addField( - 'plan_bill_amount', - 'text', - ['name' => 'plan_bill_amount', 'label' => __('Billing Amount'), 'title' => __('Billing Amount'), 'required' => true,'disabled'=>$readonly,'class'=> 'required-entry validate-number'] - ); - $fieldset->addField( - 'plan_interval', - 'text', - ['name' => 'plan_interval', 'label' => __('Billing Frequency'), 'title' => __('Billing Frequency'), 'required' => true,'disabled'=>$readonly,'class'=> 'required-entry validate-digits'] - ); - - $fieldset->addField( - 'plan_type', 'select', array( - 'label' => 'Interval', - 'name' => 'plan_type', - 'class' => 'required-entry', - 'onchange' => 'checkSelectedItem(this.value)', - 'values' => array( - array( - 'value' => '', - 'label' => 'Please Select', - ), - array( - 'value' => 'daily', - 'label' => 'Daily', - ), - array( - 'value' => 'weekly', - 'label' => 'Weekly', - ), - array( - 'value' => 'monthly', - 'label' => 'Monthly', - ), - array( - 'value' => 'yearly', - 'label' => 'Yearly', - ) - ), - 'required'=>true, - 'disabled'=>$readonly - ) - )->setAfterElementHtml(" - "); - - $fieldset->addField( - 'plan_bill_cycle', - 'text', - ['name' => 'plan_bill_cycle', 'label' => __('No. of Billing Cycles'), 'title' => __('No. of Billing Cycles'), 'required' => true,'disabled'=>$readonly,'class'=> 'required-entry validate-digits'] - ); - if (!$model->getId()) { - $model->setData('plan_trial', '0'); - } - $fieldset->addField( - 'plan_trial', - 'text', - ['name' => 'plan_trial', 'label' => __('Trial Days'), 'title' => __('Trial Days'),'note' => 'Default is 0. The subscription starts immediately after the authorization payment','disabled'=>$readonly,'class'=> 'validate-digits'] - ); - $fieldset->addField( - 'plan_addons', - 'text', - ['name' => 'plan_addons', 'label' => __('Add-On Amount (Optional)'), 'title' => __('Add-On Amount (Optional)'),'disabled'=>$readonly,'class'=> 'validate-number'] - ); - // Status - Dropdown - if (!$model->getId()) { - $model->setStatus('1'); // Enable status when adding a Plan - } - $statuses = $this->_status->toOptionArray(); - $fieldset->addField( - 'plan_status', - 'select', - ['name' => 'plan_status', 'label' => __('Status'), 'title' => __('Status'), 'required' => true, 'values' => $statuses] - ); - $form->setValues($model->getData()); - $form->setUseContainer(true); - $this->setForm($form); - - return parent::_prepareForm(); - } -} diff --git a/Block/Adminhtml/Subscription/Edit.php b/Block/Adminhtml/Subscription/Edit.php index 3731c55..14d2450 100644 --- a/Block/Adminhtml/Subscription/Edit.php +++ b/Block/Adminhtml/Subscription/Edit.php @@ -1,8 +1,8 @@ _coreRegistry = $registry; parent::__construct($context, $data); } - + /** * Department edit block * @@ -36,30 +36,25 @@ protected function _construct() $this->_objectId = 'entity_id'; $this->_blockGroup = 'Razorpay_Subscription'; $this->_controller = 'adminhtml_subscription'; - + parent::_construct(); - - if ($this->_isAllowedAction('Razorpay_Subscription::subscription_upgrade')) { + + if ($this->_isAllowedAction('Razorpay_Subscription::subscription_save')) { $this->buttonList->update('save', 'label', __('Save Subscription')); - $this->buttonList->add( - 'saveandcontinue', - [ - 'label' => __('Save and Continue Edit'), - 'class' => 'save', - 'data_attribute' => [ - 'mage-init' => [ - 'button' => ['event' => 'saveAndContinueEdit', 'target' => '#edit_form'], - ], - ] - ], - -100 + + $this->buttonList->remove('back'); + $data = array( + 'label' => 'Back', + 'onclick' => 'setLocation(\'' . $this->getUrl('subscribed/index/index/') . '\')', + 'class' => 'back' ); + $this->buttonList->add('back', $data); } else { $this->buttonList->remove('save'); } - + } - + /** * Get header with Department name * @@ -73,18 +68,18 @@ public function getHeaderText() return __('New Subscription'); } } - + /** * Check permission for passed action * - * @param string $resourceId + * @param string $resourceId * @return bool */ protected function _isAllowedAction($resourceId) { return $this->_authorization->isAllowed($resourceId); } - + /** * Getter of url for "Save and Continue" button * tab_id will be replaced by desired by JS later @@ -93,6 +88,6 @@ protected function _isAllowedAction($resourceId) */ protected function _getSaveAndContinueUrl() { - return $this->getUrl('subscribed/*/upgrade', ['_current' => true, 'back' => 'edit', 'active_tab' => '']); + return $this->getUrl('subscribed/*/save', ['_current' => true, 'back' => 'edit', 'active_tab' => '']); } } \ No newline at end of file diff --git a/Block/Adminhtml/Subscription/Edit/Form.php b/Block/Adminhtml/Subscription/Edit/Form.php index b3c1d83..e517488 100644 --- a/Block/Adminhtml/Subscription/Edit/Form.php +++ b/Block/Adminhtml/Subscription/Edit/Form.php @@ -1,16 +1,16 @@ _systemStore = $systemStore; parent::__construct($context, $registry, $formFactory, $data); } - + /** * Init form * @@ -37,10 +37,10 @@ public function __construct( protected function _construct() { parent::_construct(); - $this->setId('department_form'); - $this->setTitle(__('Department Information')); + $this->setId('subscription_form'); + $this->setTitle(__('Subscription Information')); } - + /** * Prepare form * @@ -48,41 +48,109 @@ protected function _construct() */ protected function _prepareForm() { - /** @var \Maxime\Jobs\Model\Department $model */ + $subscriptionInfo = $this->getLayout()->createBlock( + 'Razorpay\Subscription\Block\View')->getSubscrib(); + $subscriptionInfo['s_id'] = $this->_request->getParam('subscription_id'); + + $plans = $this->getLayout()->createBlock('Razorpay\Subscription\Block\Edit')->getPlans($subscriptionInfo['product_id']); + $pending = $this->getLayout()->createBlock('Razorpay\Subscription\Block\Edit')->pendingUpdate(); + $readonly = !empty($pending) ? true : false; + + foreach($plans as $option){ + $options[] = ["value" => $option['plan_id'],"label" => $option['plan_name']]; + } + + /** @var \Razorpay\Subscription\Model\Subscriptions $model */ $model = $this->_coreRegistry->registry('subscribed_subscription'); - + /** @var \Magento\Framework\Data\Form $form */ $form = $this->_formFactory->create( ['data' => ['id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post']] ); - - $form->setHtmlIdPrefix('department_'); - + + $form->setHtmlIdPrefix('subscription_'); + $fieldset = $form->addFieldset( 'base_fieldset', - ['legend' => __('General Information'), 'class' => 'fieldset-wide'] + ['legend' => __('Subscription Details'), 'class' => 'fieldset-wide'] ); - + if ($model->getId()) { $fieldset->addField('entity_id', 'hidden', ['name' => 'entity_id']); } - + $fieldset->addField('s_id', 'hidden', ['name' => 's_id']); + + $fieldset->addField( + 'subscription_id', + 'text', + ['name' => 'subscription_id', 'label' => __('Subscription Id'), 'title' => __('Subscription Id'), 'required' => true,'disabled'=>true] + ); + + $fieldset->addField( + 'razorpay_customer_id', + 'text', + ['name' => 'razorpay_customer_id', 'label' => __('Customer Id'), 'title' => __('Customer Id'), 'required' => true,'disabled'=>true] + ); + $fieldset->addField( + 'plan_id', + 'select', + ['name' => 'plan_id', 'label' => __('Select Plan'), 'title' => __('Select Plan'), 'required' => true,'values' => $options,'disabled'=>$readonly] + ); + $fieldset->addField( + 'plan_name', + 'text', + ['name' => 'plan_name', 'label' => __('Plan Name'), 'title' => __('Plan Name'), 'required' => true,'disabled'=>true] + ); + $fieldset->addField( + 'plan_type', + 'text', + ['name' => 'plan_type', 'label' => __('Plan Type'), 'title' => __('Plan Type'), 'required' => true,'disabled'=>true] + ); + $fieldset->addField( + 'value', + 'text', + ['name' => 'value', 'label' => __('Product Name'), 'title' => __('Product Name'), 'required' => true,'disabled'=>true] + ); $fieldset->addField( - 'name', + 'status', 'text', - ['name' => 'name', 'label' => __('Department Name'), 'title' => __('Department Name'), 'required' => true] + ['name' => 'status', 'label' => __('Status'), 'title' => __('Status'), 'required' => true,'disabled'=>true] ); - $fieldset->addField( - 'description', - 'textarea', - ['name' => 'description', 'label' => __('Department Description'), 'title' => __('Department Description'), 'required' => true] + 'total_count', + 'text', + ['name' => 'total_count', 'label' => __('Total Count'), 'title' => __('Total Count'), 'required' => true,'disabled'=>true] + ); + $fieldset->addField( + 'paid_count', + 'text', + ['name' => 'paid_count', 'label' => __('Paid Count'), 'title' => __('Paid Count'), 'required' => true,'disabled'=>true] + ); + $fieldset->addField( + 'subscription_created_at', + 'text', + ['name' => 'subscription_created_at', 'label' => __('Created At'), 'title' => __('Created At'), 'required' => true,'disabled'=>true] + ); + $fieldset->addField( + 'next_charge_at', + 'text', + ['name' => 'next_charge_at', 'label' => __('Next Charge At'), 'title' => __('Next Charge At'), 'required' => true,'disabled'=>true] + ); + $fieldset->addField( + 'start_at', + 'text', + ['name' => 'start_at', 'label' => __('Start At'), 'title' => __('Start At'), 'required' => true,'disabled'=>true] + ); + $fieldset->addField( + 'end_at', + 'text', + ['name' => 'end_at', 'label' => __('End At'), 'title' => __('End At'), 'required' => true,'disabled'=>true] ); - - $form->setValues($model->getData()); + + $form->setValues($subscriptionInfo); $form->setUseContainer(true); $this->setForm($form); - + return parent::_prepareForm(); } -} +} \ No newline at end of file diff --git a/Block/Display.php b/Block/Display.php index 86abbdc..5e01498 100644 --- a/Block/Display.php +++ b/Block/Display.php @@ -23,24 +23,23 @@ class Display extends Template /** * Constructor - * @param Context $context - * @param \Magento\Customer\Model\Session $customerSession - * @param SubscribCollectionFactory $subscribCollectionFactory + * + * @param Context $context + * @param \Magento\Customer\Model\Session $customerSession + * @param SubscribCollectionFactory $subscribCollectionFactory * @param \Magento\Framework\App\ResourceConnection $Resource - * @param \Magento\Framework\Module\Dir\Reader $moduleReader - * @param array $data + * @param \Magento\Framework\Module\Dir\Reader $moduleReader + * @param array $data */ public function __construct( Context $context, \Magento\Customer\Model\Session $customerSession, SubscribCollectionFactory $subscribCollectionFactory, \Magento\Framework\App\ResourceConnection $Resource, - \Magento\Framework\Module\Dir\Reader $moduleReader, \Psr\Log\LoggerInterface $logger, \Magento\Framework\UrlInterface $urlInterface, array $data = [] - ) { $this->_subscribCollectionFactory = $subscribCollectionFactory; $this->_resource = $Resource; @@ -65,9 +64,9 @@ protected function filterOrder() $this->catalog_product_entity_varchar_table = $this->getTable("catalog_product_entity"); $this->getSelect() - ->join(array('pid' => $this->catalog_product_entity_varchar_table), $this->catalog_product_entity_table . '.entity_id= pid.entity_id', - - ); + ->join( + array('pid' => $this->catalog_product_entity_varchar_table), $this->catalog_product_entity_table . '.entity_id= pid.entity_id', + ); } public function getSubscribs() @@ -84,13 +83,17 @@ public function getSubscribs() $second_table_name = $this->_resource->getTableName('catalog_product_entity_varchar'); $third_table_name = $this->_resource->getTableName('eav_attribute'); - $subscribCollection->getSelect()->joinLeft(array('second' => $second_table_name), - 'main_table.product_id = second.entity_id', - array('second.value')); + $subscribCollection->getSelect()->joinLeft( + array('second' => $second_table_name), + 'main_table.product_id = second.entity_id', + array('second.value') + ); - $subscribCollection->getSelect()->joinLeft(array('third' => $third_table_name), - 'third.attribute_id = second.attribute_id', - array('third.attribute_id as attribute_id')); + $subscribCollection->getSelect()->joinLeft( + array('third' => $third_table_name), + 'third.attribute_id = second.attribute_id', + array('third.attribute_id as attribute_id') + ); $subscribCollection->getSelect()->where("third.attribute_code='name' and second.entity_id=main_table.product_id"); $subscribCollection->getSelect()->where("main_table.magento_user_id=".$customerId); @@ -104,7 +107,8 @@ public function getSubscribs() /** * For a given subscrib, returns its url - * @param Subscrib $subscrib + * + * @param Subscrib $subscrib * @return string */ @@ -124,21 +128,21 @@ protected function _prepareLayout() $subscribCollection = $this->_subscribCollectionFactory->create(); try{ - parent::_prepareLayout(); - if ($this->getSubscribs()) { - $pager = $this->getLayout()->createBlock( - \Magento\Theme\Block\Html\Pager::class, - 'razorpaysubscription.customer.index' - )->setCollection( - $this->getSubscribs() - ); - $this->setChild('pager', $pager); - $this->getSubscribs()->load(); + parent::_prepareLayout(); + if ($this->getSubscribs()) { + $pager = $this->getLayout()->createBlock( + \Magento\Theme\Block\Html\Pager::class, + 'razorpaysubscription.customer.index' + )->setCollection( + $this->getSubscribs() + ); + $this->setChild('pager', $pager); + $this->getSubscribs()->load(); + } + return $this; + }catch(\Exception $e){ + $this->logger->info("Exception subscription paging: {$e->getMessage()}"); } - return $this; - }catch(\Exception $e){ - $this->logger->info("Exception subscription paging: {$e->getMessage()}"); - } } /** @@ -153,7 +157,8 @@ public function getPagerHtml() /** * For a given subscrib, returns its url - * @param Subscrib $subscrib + * + * @param Subscrib $subscrib * @return string */ public function editSubscribUrl( @@ -163,5 +168,5 @@ public function editSubscribUrl( return $this->urlInterface->getUrl() ."razorpaysubscription/subscrib/edit/id/{$subscrib->getSubscriptionId()}"; } - + } diff --git a/Block/Edit.php b/Block/Edit.php index 01bd61f..3979dfd 100644 --- a/Block/Edit.php +++ b/Block/Edit.php @@ -17,18 +17,21 @@ class Edit extends Template { /** * Core registry + * * @var Registry */ protected $_coreRegistry; /** * Subscrib + * * @var null|Subscrib */ protected $_subscrib = null; /** * SubscribCollectionFactory + * * @var null|SubscribFactory */ protected $_planCollectionFactory = null; @@ -43,10 +46,11 @@ class Edit extends Template protected $_resource; /** * Constructor - * @param Context $context - * @param Registry $coreRegistry + * + * @param Context $context + * @param Registry $coreRegistry * @param SubscribFactory $SubscribCollectionFactory - * @param array $data + * @param array $data */ public function __construct( Context $context, @@ -67,6 +71,7 @@ public function __construct( /** * fetch current plan + * * @return array */ public function getCurrentPlan() @@ -76,11 +81,13 @@ public function getCurrentPlan() $planCollection = $this->_planCollectionFactory->create(); $second_table_name = $this->_resource->getTableName('razorpay_subscriptions'); - $planCollection->getSelect()->joinLeft(array('second' => $second_table_name), - 'main_table.entity_id = second.plan_entity_id'); + $planCollection->getSelect()->joinLeft( + array('second' => $second_table_name), + 'main_table.entity_id = second.plan_entity_id' + ); $planCollection->addFieldToFilter('main_table.entity_id', $planArr['plan_entity_id']); - $planCollection->addFieldToFilter('second.subscription_id',$this->getSubscriptionId()); + $planCollection->addFieldToFilter('second.subscription_id', $this->getSubscriptionId()); $singleData= $planCollection->getFirstItem(); $data = $singleData->getData(); return $data; @@ -88,12 +95,14 @@ public function getCurrentPlan() /** * fetch all plans + * * @return array */ public function getPlans($productId) { $planCollection = $this->_planCollectionFactory->create(); $planCollection->addFieldToFilter('magento_product_id', $productId); + $planCollection->addFieldToFilter('plan_status', 1); $data = $planCollection->getData(); return $data; @@ -101,6 +110,7 @@ public function getPlans($productId) /** * Retrieves the entity id from the registry + * * @return int */ public function getSubscriptionId() @@ -112,6 +122,7 @@ public function getSubscriptionId() /** * Retrieves the subscription Id + * * @return string */ public function getSubscription() @@ -140,7 +151,7 @@ public function pendingUpdate() { $_objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $self = $_objectManager->create('Razorpay\Subscription\Model\SubscriptionPaymentMethod'); - $subscriptionInvoices = $this->_subscription->pendingUpdate($this->getSubscriptionId(), $self->rzp) ; + $subscriptionInvoices = $this->_subscription->pendingUpdate($this->getSubscriptionId(), $self->rzp); return $subscriptionInvoices ; } } diff --git a/Block/View.php b/Block/View.php index fb59e07..9682bb0 100644 --- a/Block/View.php +++ b/Block/View.php @@ -19,18 +19,21 @@ class View extends Template { /** * Core registry + * * @var Registry */ protected $_coreRegistry; /** * Subscrib + * * @var null|Subscrib */ protected $_subscrib = null; /** * SubscribCollectionFactory + * * @var null|SubscribFactory */ protected $_subscribFactory = null; @@ -45,13 +48,14 @@ class View extends Template /** * Constructor - * @param Context $context - * @param Registry $coreRegistry - * @param SubscribFactory $subscribFactory + * + * @param Context $context + * @param Registry $coreRegistry + * @param SubscribFactory $subscribFactory * @param SubscribCollectionFactory $subscribCollectionFactory - * @param ResourceConnection $Resource - * @param Subscription $subscription - * @param array $data + * @param ResourceConnection $Resource + * @param Subscription $subscription + * @param array $data */ public function __construct( Context $context, @@ -72,6 +76,7 @@ public function __construct( /** * Lazy loads the requested subscrib + * * @return Subscrib * @throws LocalizedException */ @@ -86,29 +91,41 @@ public function getSubscrib() $six_table_name = $this->_resource->getTableName('sales_invoice'); $seventh_table_name = $this->_resource->getTableName('razorpay_plans'); - $subscribCollection->getSelect()->joinLeft(array('second' => $second_table_name), + $subscribCollection->getSelect()->joinLeft( + array('second' => $second_table_name), 'main_table.product_id = second.entity_id', - array('second.value')); + array('second.value') + ); - $subscribCollection->getSelect()->joinLeft(array('third' => $third_table_name), + $subscribCollection->getSelect()->joinLeft( + array('third' => $third_table_name), 'third.attribute_id = second.attribute_id', - array('third.attribute_id as attribute_id')); + array('third.attribute_id as attribute_id') + ); - $subscribCollection->getSelect()->joinLeft(array('fourth' => $fourth_table_name), + $subscribCollection->getSelect()->joinLeft( + array('fourth' => $fourth_table_name), 'main_table.product_id = fourth.entity_id', - array('fourth.sku')); + array('fourth.sku') + ); - $subscribCollection->getSelect()->joinLeft(array('five' => $fiveth_table_name), + $subscribCollection->getSelect()->joinLeft( + array('five' => $fiveth_table_name), 'main_table.subscription_id = five.rzp_order_id', - array('five.increment_order_id')); + array('five.increment_order_id') + ); - $subscribCollection->getSelect()->joinLeft(array('six' => $six_table_name), + $subscribCollection->getSelect()->joinLeft( + array('six' => $six_table_name), 'six.transaction_id = five.rzp_payment_id', - array('six.subtotal','six.grand_total','six.total_qty','six.store_currency_code','six.base_shipping_amount')); + array('six.subtotal','six.grand_total','six.total_qty','six.store_currency_code','six.base_shipping_amount') + ); - $subscribCollection->getSelect()->joinLeft(array('seven' => $seventh_table_name), + $subscribCollection->getSelect()->joinLeft( + array('seven' => $seventh_table_name), 'main_table.plan_entity_id = seven.entity_id', - array('seven.plan_id','seven.plan_type','seven.plan_name')); + array('seven.plan_id','seven.plan_type','seven.plan_name') + ); $subscribCollection->getSelect()->where("third.attribute_code='name' and second.entity_id=main_table.product_id"); @@ -121,6 +138,7 @@ public function getSubscrib() /** * Retrieves the subscrib id from the registry + * * @return int */ protected function _getSubscribId() @@ -153,7 +171,7 @@ public function getSubscriptionInvoice() $_objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $self = $_objectManager->create('Razorpay\Subscription\Model\SubscriptionPaymentMethod'); - $subscriptionInvoices = $this->_subscription->fetchSubscriptionInvoice($singleData->getSubscriptionId(), $self->rzp) ; + $subscriptionInvoices = $this->_subscription->fetchSubscriptionInvoice($singleData->getSubscriptionId(), $self->rzp); return $subscriptionInvoices ; } diff --git a/CHANGELOG.md b/CHANGELOG.md index 6cc49e8..a4cf3e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,15 @@ # Change Log +## [1.0.1] - 2021-12-29 + +### Added + +- Sorting plan and subscription list with entity_id [#46](https://github.com/razorpay/subscriptions-magento-plugin/pull/46) +- Add webhook events for failed payments [#37](https://github.com/razorpay/subscriptions-magento-plugin/pull/37) +- Rebuilt plan creation in admin [#41](https://github.com/razorpay/subscriptions-magento-plugin/pull/41) +- Added edit subscription for admin [#35](https://github.com/razorpay/subscriptions-magento-plugin/pull/35) + ## [1.0.0] - 2021-12-29 ### Added diff --git a/Controller/Adminhtml/Index/Index.php b/Controller/Adminhtml/Index/Index.php index 5754df2..86912a0 100755 --- a/Controller/Adminhtml/Index/Index.php +++ b/Controller/Adminhtml/Index/Index.php @@ -9,6 +9,7 @@ /** * Class Index + * * @package Razorpay\Grid\Controller\Adminhtml\Index */ class Index extends Action @@ -21,7 +22,7 @@ class Index extends Action /** * Constructor * - * @param \Magento\Backend\App\Action\Context $context + * @param \Magento\Backend\App\Action\Context $context * @param \Magento\Framework\View\Result\PageFactory $rawFactory */ public function __construct(Context $context, PageFactory $rawFactory) diff --git a/Controller/Adminhtml/Plan/Edit.php b/Controller/Adminhtml/Plan/Edit.php index 35b88ab..d648b8f 100644 --- a/Controller/Adminhtml/Plan/Edit.php +++ b/Controller/Adminhtml/Plan/Edit.php @@ -23,10 +23,10 @@ class Edit extends Action protected $_model; /** - * @param Action\Context $context + * @param Action\Context $context * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory - * @param \Magento\Framework\Registry $registry - * @param \Razorpay\Subscription\Model\Plans $model + * @param \Magento\Framework\Registry $registry + * @param \Razorpay\Subscription\Model\Plans $model */ public function __construct( Action\Context $context, @@ -56,7 +56,9 @@ protected function _isAllowed() protected function _initAction() { // load layout, set active menu and breadcrumbs - /** @var \Magento\Backend\Model\View\Result\Page $resultPage */ + /** + * @var \Magento\Backend\Model\View\Result\Page $resultPage +*/ $resultPage = $this->_resultPageFactory->create(); $resultPage->setActiveMenu('Razorpay_Subscription::rzp_subscriptions') ->addBreadcrumb(__('Plan'), __('Plan')) @@ -67,7 +69,7 @@ protected function _initAction() /** * Edit Plan * - * @return \Magento\Backend\Model\View\Result\Page|\Magento\Backend\Model\View\Result\Redirect + * @return \Magento\Backend\Model\View\Result\Page|\Magento\Backend\Model\View\Result\Redirect * @SuppressWarnings(PHPMD.NPathComplexity) */ public function execute() @@ -80,7 +82,9 @@ public function execute() $model->load($id); if (!$model->getId()) { $this->messageManager->addError(__('This plan not exists.')); - /** \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + /** + * \Magento\Backend\Model\View\Result\Redirect $resultRedirect +*/ $resultRedirect = $this->resultRedirectFactory->create(); return $resultRedirect->setPath('*/*/'); @@ -94,7 +98,9 @@ public function execute() $this->_coreRegistry->register('subscribed_plan', $model); - /** @var \Magento\Backend\Model\View\Result\Page $resultPage */ + /** + * @var \Magento\Backend\Model\View\Result\Page $resultPage +*/ $resultPage = $this->_initAction(); $resultPage->addBreadcrumb( $id ? __('Edit Plan') : __('New Plan'), diff --git a/Controller/Adminhtml/Plan/Index.php b/Controller/Adminhtml/Plan/Index.php index d618544..ccc69fc 100644 --- a/Controller/Adminhtml/Plan/Index.php +++ b/Controller/Adminhtml/Plan/Index.php @@ -15,7 +15,7 @@ class Index extends Action protected $resultPageFactory; /** - * @param Context $context + * @param Context $context * @param PageFactory $resultPageFactory */ public function __construct( @@ -33,7 +33,9 @@ public function __construct( */ public function execute() { - /** @var \Magento\Backend\Model\View\Result\Page $resultPage */ + /** + * @var \Magento\Backend\Model\View\Result\Page $resultPage +*/ $resultPage = $this->resultPageFactory->create(); $resultPage->setActiveMenu('Razorpay_Subscription::rzp_subscriptions'); $resultPage->addBreadcrumb(__('Plans'), __('Plans')); diff --git a/Controller/Adminhtml/Plan/MassDisable.php b/Controller/Adminhtml/Plan/MassDisable.php index 420028d..dd9a2f4 100644 --- a/Controller/Adminhtml/Plan/MassDisable.php +++ b/Controller/Adminhtml/Plan/MassDisable.php @@ -20,8 +20,8 @@ class MassDisable extends \Magento\Backend\App\Action /** - * @param Context $context - * @param Filter $filter + * @param Context $context + * @param Filter $filter * @param CollectionFactory $collectionFactory */ public function __construct(Context $context, Filter $filter, CollectionFactory $collectionFactory) @@ -42,13 +42,15 @@ public function execute() $collection = $this->filter->getCollection($this->collectionFactory->create()); $collectionSize = $collection->getSize(); foreach ($collection as $item) { - $item->setData('plan_status',0); + $item->setData('plan_status', 0); $item->save(); } $this->messageManager->addSuccess(__('A total of %1 record(s) have been Disabled.', $collectionSize)); - /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + /** + * @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect +*/ $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); return $resultRedirect->setPath('*/*/'); } diff --git a/Controller/Adminhtml/Plan/MassEnable.php b/Controller/Adminhtml/Plan/MassEnable.php index d756f56..85b67ea 100644 --- a/Controller/Adminhtml/Plan/MassEnable.php +++ b/Controller/Adminhtml/Plan/MassEnable.php @@ -20,8 +20,8 @@ class MassEnable extends \Magento\Backend\App\Action /** - * @param Context $context - * @param Filter $filter + * @param Context $context + * @param Filter $filter * @param CollectionFactory $collectionFactory */ public function __construct(Context $context, Filter $filter, CollectionFactory $collectionFactory) @@ -41,13 +41,15 @@ public function execute() $collection = $this->filter->getCollection($this->collectionFactory->create()); $collectionSize = $collection->getSize(); foreach ($collection as $item) { - $item->setData('plan_status',1); + $item->setData('plan_status', 1); $item->save(); } $this->messageManager->addSuccess(__('A total of %1 record(s) have been Enabled.', $collectionSize)); - /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + /** + * @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect +*/ $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); return $resultRedirect->setPath('*/*/'); } diff --git a/Controller/Adminhtml/Plan/NewAction.php b/Controller/Adminhtml/Plan/NewAction.php index 7098764..12e4fbc 100644 --- a/Controller/Adminhtml/Plan/NewAction.php +++ b/Controller/Adminhtml/Plan/NewAction.php @@ -11,7 +11,7 @@ class NewAction extends Action protected $_resultForwardFactory; /** - * @param \Magento\Backend\App\Action\Context $context + * @param \Magento\Backend\App\Action\Context $context * @param \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory */ public function __construct( @@ -37,7 +37,9 @@ protected function _isAllowed() */ public function execute() { - /** @var \Magento\Backend\Model\View\Result\Forward $resultForward */ + /** + * @var \Magento\Backend\Model\View\Result\Forward $resultForward +*/ $resultForward = $this->_resultForwardFactory->create(); return $resultForward->forward('edit'); } diff --git a/Controller/Adminhtml/Plan/Save.php b/Controller/Adminhtml/Plan/Save.php index 85f57e7..c39b778 100644 --- a/Controller/Adminhtml/Plan/Save.php +++ b/Controller/Adminhtml/Plan/Save.php @@ -1,37 +1,42 @@ _model = $model; - $this->_storeManager = $storeManager; - - - + \Magento\Framework\App\Action\Context $context, + \Magento\Customer\Model\Session $customerSession, + \Magento\Checkout\Model\Session $checkoutSession, + \Razorpay\Magento\Model\Config $config, + \Magento\Store\Model\StoreManagerInterface $storeManager, + \Psr\Log\LoggerInterface $logger + ) + { + parent::__construct( + $context, + $customerSession, + $checkoutSession, + $config + ); + $this->storeManager = $storeManager; + $this->logger = $logger; + $this->config = $config; } - + /** * {@inheritdoc} */ @@ -39,7 +44,7 @@ protected function _isAllowed() { return $this->_authorization->isAllowed('Razorpay_Subscription::plan_save'); } - + /** * Save action * @@ -47,86 +52,90 @@ protected function _isAllowed() */ public function execute() { - $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); - $connection = $objectManager->get('Magento\Framework\App\ResourceConnection')->getConnection('\Magento\Framework\App\ResourceConnection::DEFAULT_CONNECTION'); - $key_id = $connection->fetchAll("SELECT * FROM core_config_data WHERE `path` LIKE 'payment/razorpay/key_id'"); - $key_secret = $connection->fetchAll("SELECT * FROM core_config_data WHERE `path` LIKE 'payment/razorpay/key_secret'"); - - $rzpId = $key_id[0]['value']; - $rzpSecret = $key_secret[0]['value']; - $rzp = new Api($rzpId, $rzpSecret); - - - $data = $this->getRequest()->getPostValue(); - /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ - $resultRedirect = $this->resultRedirectFactory->create(); - if ($data) { - /** @var \Razorpay\Subscription\Model\Plans $model */ - $model = $this->_model; - - $id = $this->getRequest()->getParam('id'); - $plan_bill_amount = $this->getRequest()->getParam('plan_bill_amount'); - - $checkPlanData = $objectManager->get('Razorpay\Subscription\Model\Plans') - ->getCollection() - ->addFieldToFilter('magento_product_id', $this->getRequest()->getParam('magento_product_id')) - ->addFieldToFilter('plan_type', $this->getRequest()->getParam('plan_type')) - ->addFieldToFilter('plan_interval', $this->getRequest()->getParam('plan_interval')) - ->addFieldToFilter('plan_bill_cycle', $this->getRequest()->getParam('plan_bill_cycle')) - ->addFieldToFilter('plan_bill_amount', $this->getRequest()->getParam('plan_bill_amount')) - ->addFieldToFilter('plan_trial', $this->getRequest()->getParam('plan_trial')) - ->getData(); - - if ($checkPlanData) { - $this->messageManager->addError(__('Plan already exists')); - } else { - $planData = [ - "period" => $this->getRequest()->getParam('plan_type'), - "interval" => $this->getRequest()->getParam('plan_interval'),//(int) $product->getRazorpaySubscriptionIntervalCount(), - "item" => [ - "name" => $this->getRequest()->getParam('plan_name'), - "amount" => (int)(number_format($plan_bill_amount * 100, 0, ".", "")), - "currency" => $this->_storeManager->getStore()->getCurrentCurrency()->getCode(), - "description" => $this->getRequest()->getParam('plan_desc') - ], - "notes" => [ - "source" => "magento" - ] - ]; - - $createplan = $rzp->plan->create($planData); - $plan_id = array('plan_id' => $createplan->id); - - if ($id) { - $model->load($id); - } + $this->logger->info("-------------------Plan creation------------------"); + + try { + $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); + + $data = $this->getRequest()->getPostValue(); + + /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultRedirectFactory->create(); + if ($data) { + if ($data["entity_id"]) { + + //edit part for status change + $plan = $objectManager->create('Razorpay\Subscription\Model\Plans')->load($data["entity_id"]); - $model->setData(array_merge($plan_id, $data)); + $plan->setPlanStatus($this->getRequest()->getParam('plan_status')) + ->save(); + $this->logger->info("Plan update successfully"); + $this->messageManager->addSuccess(__('Plan update successfully')); + return $resultRedirect->setPath('*/*/index'); - $this->_eventManager->dispatch( - 'subscribed_plan_prepare_save', - ['plans' => $model, 'request' => $this->getRequest()] - ); + } else { + $this->logger->info("Checking for existing plan"); + $checkPlanData = $objectManager->get('Razorpay\Subscription\Model\Plans') + ->getCollection() + ->addFieldToFilter('plan_type', $this->getRequest()->getParam('plan_type')) + ->addFieldToFilter('magento_product_id', $this->getRequest()->getParam('magento_product_id')) + ->addFieldToFilter('plan_interval', $this->getRequest()->getParam('plan_interval')) + ->addFieldToFilter('plan_bill_cycle', $this->getRequest()->getParam('plan_bill_cycle')) + ->addFieldToFilter('plan_bill_amount', $this->getRequest()->getParam('plan_bill_amount')) + ->getData(); - try { - $model->save(); - $this->messageManager->addSuccess(__('Plan saved')); - $this->_getSession()->setFormData(false); - if ($this->getRequest()->getParam('back')) { - return $resultRedirect->setPath('*/*/edit', ['id' => $model->getId(), '_current' => true]); + if ($checkPlanData) { + $this->logger->info("Plan already exists"); + $this->messageManager->addError(__('Plan already exists')); + } else { + $this->logger->info("Creating new plan "); + $planData = [ + "period" => $this->getRequest()->getParam('plan_type'), + "interval" => $this->getRequest()->getParam('plan_interval'), + "item" => [ + "name" => $this->getRequest()->getParam('plan_name'), + "amount" => (int)(number_format($this->getRequest()->getParam('plan_bill_amount') * 100, 0, ".", "")), + "currency" => $this->storeManager->getStore()->getCurrentCurrency()->getCode(), + "description" => $this->getRequest()->getParam('plan_desc') + ], + "notes" => [ + "source" => "magento-subscription" + ] + ]; + + $planResponse = $this->rzp->plan->create($planData); + + $plan = $objectManager->create('Razorpay\Subscription\Model\Plans'); + $plan->setPlanName($this->getRequest()->getParam('plan_name')) + ->setPlanId($planResponse->id) + ->setPlanDesc($this->getRequest()->getParam('plan_desc')) + ->setMagentoProductId($this->getRequest()->getParam('magento_product_id')) + ->setPlanBillAmount($this->getRequest()->getParam('plan_bill_amount')) + ->setPlanInterval($this->getRequest()->getParam('plan_interval')) + ->setPlanType($this->getRequest()->getParam('plan_type')) + ->setPlanBillCycle($this->getRequest()->getParam('plan_bill_cycle')) + ->setPlanTrial($this->getRequest()->getParam('plan_trial')) + ->setPlanAddons($this->getRequest()->getParam('plan_addons')) + ->setPlanStatus($this->getRequest()->getParam('plan_status')) + ->save(); + + $this->logger->info("Plan saved successfully"); + $this->messageManager->addSuccess(__('Plan saved successfully')); + return $resultRedirect->setPath('*/*/index'); } - return $resultRedirect->setPath('*/*/'); - } catch (\Magento\Framework\Exception\LocalizedException $e) { - $this->messageManager->addError($e->getMessage()); - } catch (\RuntimeException $e) { - $this->messageManager->addError($e->getMessage()); - } catch (\Exception $e) { - $this->messageManager->addException($e, __('Something went wrong while saving the plan')); + } } - $this->_getSession()->setFormData($data); - return $resultRedirect->setPath('*/*/edit', ['entity_id' => $this->getRequest()->getParam('id')]); + + } catch (\Magento\Framework\Exception\LocalizedException $e) { + $this->logger->info("Plan error localized exception: {$e->getMessge()}"); + $this->messageManager->addError($e->getMessage()); + } catch (\RuntimeException $e) { + $this->logger->info("Plan error run time exception: {$e->getMessge()}"); + $this->messageManager->addError($e->getMessage()); + } catch (\Exception $e) { + $this->logger->info("Plan error: {$e->getMessge()}"); + $this->messageManager->addException($e, __('Something went wrong while saving the plan')); } - return $resultRedirect->setPath('*/*/'); } } diff --git a/Controller/Adminhtml/Subscription/Cancel.php b/Controller/Adminhtml/Subscription/Cancel.php index 8d92778..4b7eedc 100644 --- a/Controller/Adminhtml/Subscription/Cancel.php +++ b/Controller/Adminhtml/Subscription/Cancel.php @@ -64,8 +64,8 @@ class Cancel extends BaseController protected $checkoutSession; /** - * @param Context $context - * @param Filter $filter + * @param Context $context + * @param Filter $filter * @param CollectionFactory $collectionFactory */ public function __construct( @@ -78,8 +78,7 @@ public function __construct( \Magento\Backend\Helper\Data $backendHelper, \Razorpay\Subscription\Helper\Subscription $subscription, \Magento\Framework\Message\ManagerInterface $messageManager - ) - { + ) { $this->filter = $filter; $this->collectionFactory = $collectionFactory; parent::__construct( @@ -109,14 +108,14 @@ public function execute() try { $id = $this->getRequest()->getParam('subscription_id'); $entity_id = $this->getRequest()->getParam('id'); - if($id){ + if($id) { $updateBy = 'admin'; $this->subscription->cancelSubscription($id, $this->rzp, $updateBy); $this->messageManager->addSuccess(__('Subscription has been cancelled.')); $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); - if($entity_id){ + if($entity_id) { return $resultRedirect->setPath('subscribed/subscription/view/subscription_id/'.$id.'/id/'.$entity_id); } return $resultRedirect->setPath('subscribed/index/index'); diff --git a/Controller/Adminhtml/Subscription/Edit.php b/Controller/Adminhtml/Subscription/Edit.php index cc0cc90..42bc255 100644 --- a/Controller/Adminhtml/Subscription/Edit.php +++ b/Controller/Adminhtml/Subscription/Edit.php @@ -1,27 +1,29 @@ _resultPageFactory->create(); - $resultPage->setActiveMenu('Magento_Sales::sales') + $resultPage->setActiveMenu('Razorpay_Subscription::rzp_subscriptions') ->addBreadcrumb(__('Subscription'), __('Subscription')) ->addBreadcrumb(__('Manage Subscriptions'), __('Manage Subscriptions')); return $resultPage; } - + /** * Edit Department * @@ -72,27 +74,28 @@ protected function _initAction() */ public function execute() { + $this->_coreRegistry->register(self::REGISTRY_KEY_POST_ID, $this->_request->getParam('id')); $id = $this->getRequest()->getParam('id'); $model = $this->_model; - + if ($id) { $model->load($id); if (!$model->getId()) { $this->messageManager->addError(__('This subscription not exists.')); /** \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultRedirectFactory->create(); - + return $resultRedirect->setPath('*/*/'); } } - + $data = $this->_getSession()->getFormData(true); if (!empty($data)) { $model->setData($data); } - + $this->_coreRegistry->register('subscribed_subscription', $model); - + /** @var \Magento\Backend\Model\View\Result\Page $resultPage */ $resultPage = $this->_initAction(); $resultPage->addBreadcrumb( diff --git a/Controller/Adminhtml/Subscription/Index.php b/Controller/Adminhtml/Subscription/Index.php index 298723e..d2b5b0e 100644 --- a/Controller/Adminhtml/Subscription/Index.php +++ b/Controller/Adminhtml/Subscription/Index.php @@ -14,7 +14,9 @@ class Index extends Subscription */ public function execute() { - /** @var \Magento\Backend\Model\View\Result\Page $resultPage */ + /** + * @var \Magento\Backend\Model\View\Result\Page $resultPage +*/ $resultPage = $this->_resultPageFactory->create(); $resultPage->setActiveMenu('Razorpay_Subscription::rzp_subscriptions'); $resultPage->addBreadcrumb(__('Jobs'), __('Jobs')); diff --git a/Controller/Adminhtml/Subscription/MassCancel.php b/Controller/Adminhtml/Subscription/MassCancel.php index 30b7a27..7439e41 100644 --- a/Controller/Adminhtml/Subscription/MassCancel.php +++ b/Controller/Adminhtml/Subscription/MassCancel.php @@ -64,8 +64,8 @@ class MassCancel extends BaseController protected $checkoutSession; /** - * @param Context $context - * @param Filter $filter + * @param Context $context + * @param Filter $filter * @param CollectionFactory $collectionFactory */ public function __construct( @@ -78,8 +78,7 @@ public function __construct( \Magento\Backend\Helper\Data $backendHelper, \Razorpay\Subscription\Helper\Subscription $subscription, \Magento\Framework\Message\ManagerInterface $messageManager - ) - { + ) { $this->filter = $filter; $this->collectionFactory = $collectionFactory; parent::__construct( diff --git a/Controller/Adminhtml/Subscription/MassPause.php b/Controller/Adminhtml/Subscription/MassPause.php index d2888ba..21e7857 100644 --- a/Controller/Adminhtml/Subscription/MassPause.php +++ b/Controller/Adminhtml/Subscription/MassPause.php @@ -64,8 +64,8 @@ class MassPause extends BaseController protected $checkoutSession; /** - * @param Context $context - * @param Filter $filter + * @param Context $context + * @param Filter $filter * @param CollectionFactory $collectionFactory */ public function __construct( @@ -78,8 +78,7 @@ public function __construct( \Magento\Backend\Helper\Data $backendHelper, \Razorpay\Subscription\Helper\Subscription $subscription, \Magento\Framework\Message\ManagerInterface $messageManager - ) - { + ) { $this->filter = $filter; $this->collectionFactory = $collectionFactory; parent::__construct( diff --git a/Controller/Adminhtml/Subscription/MassResume.php b/Controller/Adminhtml/Subscription/MassResume.php index 376386d..62ec396 100644 --- a/Controller/Adminhtml/Subscription/MassResume.php +++ b/Controller/Adminhtml/Subscription/MassResume.php @@ -64,8 +64,8 @@ class MassResume extends BaseController protected $checkoutSession; /** - * @param Context $context - * @param Filter $filter + * @param Context $context + * @param Filter $filter * @param CollectionFactory $collectionFactory */ public function __construct( @@ -78,8 +78,7 @@ public function __construct( \Magento\Backend\Helper\Data $backendHelper, \Razorpay\Subscription\Helper\Subscription $subscription, \Magento\Framework\Message\ManagerInterface $messageManager - ) - { + ) { $this->filter = $filter; $this->collectionFactory = $collectionFactory; parent::__construct( diff --git a/Controller/Adminhtml/Subscription/NewAction.php b/Controller/Adminhtml/Subscription/NewAction.php index fd04d4e..746501f 100644 --- a/Controller/Adminhtml/Subscription/NewAction.php +++ b/Controller/Adminhtml/Subscription/NewAction.php @@ -11,7 +11,7 @@ class NewAction extends Action protected $_resultForwardFactory; /** - * @param \Magento\Backend\App\Action\Context $context + * @param \Magento\Backend\App\Action\Context $context * @param \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory */ public function __construct( @@ -37,7 +37,9 @@ protected function _isAllowed() */ public function execute() { - /** @var \Magento\Backend\Model\View\Result\Forward $resultForward */ + /** + * @var \Magento\Backend\Model\View\Result\Forward $resultForward +*/ $resultForward = $this->_resultForwardFactory->create(); return $resultForward->forward('edit'); } diff --git a/Controller/Adminhtml/Subscription/Pause.php b/Controller/Adminhtml/Subscription/Pause.php index 6702580..4fb9189 100644 --- a/Controller/Adminhtml/Subscription/Pause.php +++ b/Controller/Adminhtml/Subscription/Pause.php @@ -64,8 +64,8 @@ class Pause extends BaseController protected $checkoutSession; /** - * @param Context $context - * @param Filter $filter + * @param Context $context + * @param Filter $filter * @param CollectionFactory $collectionFactory */ public function __construct( @@ -78,8 +78,7 @@ public function __construct( \Magento\Backend\Helper\Data $backendHelper, \Razorpay\Subscription\Helper\Subscription $subscription, \Magento\Framework\Message\ManagerInterface $messageManager - ) - { + ) { $this->filter = $filter; $this->collectionFactory = $collectionFactory; parent::__construct( @@ -109,14 +108,14 @@ public function execute() try { $id = $this->getRequest()->getParam('subscription_id'); $entity_id = $this->getRequest()->getParam('id'); - if($id){ + if($id) { $updateBy = 'admin'; $this->subscription->pauseSubscription($id, $this->rzp, $updateBy); $this->messageManager->addSuccess(__('Subscription has been paused.')); $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); - if($entity_id){ + if($entity_id) { return $resultRedirect->setPath('subscribed/subscription/view/subscription_id/'.$id.'/id/'.$entity_id); } return $resultRedirect->setPath('subscribed/index/index'); diff --git a/Controller/Adminhtml/Subscription/Resume.php b/Controller/Adminhtml/Subscription/Resume.php index fcd779d..7804a73 100644 --- a/Controller/Adminhtml/Subscription/Resume.php +++ b/Controller/Adminhtml/Subscription/Resume.php @@ -64,8 +64,8 @@ class Resume extends BaseController protected $checkoutSession; /** - * @param Context $context - * @param Filter $filter + * @param Context $context + * @param Filter $filter * @param CollectionFactory $collectionFactory */ public function __construct( @@ -78,8 +78,7 @@ public function __construct( \Magento\Backend\Helper\Data $backendHelper, \Razorpay\Subscription\Helper\Subscription $subscription, \Magento\Framework\Message\ManagerInterface $messageManager - ) - { + ) { $this->filter = $filter; $this->collectionFactory = $collectionFactory; parent::__construct( @@ -109,14 +108,14 @@ public function execute() try { $id = $this->getRequest()->getParam('subscription_id'); $entity_id = $this->getRequest()->getParam('id'); - if($id){ + if($id) { $updateBy = 'admin'; $this->subscription->resumeSubscription($id, $this->rzp, $updateBy); $this->messageManager->addSuccess(__('Subscription has been resumed.')); $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); - if($entity_id){ + if($entity_id) { return $resultRedirect->setPath('subscribed/subscription/view/subscription_id/'.$id.'/id/'.$entity_id); } return $resultRedirect->setPath('subscribed/index/index'); diff --git a/Controller/Adminhtml/Subscription/Save.php b/Controller/Adminhtml/Subscription/Save.php new file mode 100644 index 0000000..4e4881c --- /dev/null +++ b/Controller/Adminhtml/Subscription/Save.php @@ -0,0 +1,103 @@ +_model = $model; + } + + /** + * {@inheritdoc} + **/ + protected function _isAllowed() + { + return $this->_authorization->isAllowed('Razorpay_Subscription::subscription_save'); + } + + /** + * Save action + * @return \Magento\Framework\Controller\ResultInterface + * */ + public function execute() + { + $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); + + /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultRedirectFactory->create(); + + $data = $this->getRequest()->getPostValue(); + if ($data) { + /** @var \Razorpay\Subscription\Model\Subscrib $model */ + $model = $this->_model; + $id = $this->getRequest()->getParam('entity_id'); + $subscriptionId = $this->getRequest()->getParam('s_id'); + + if ($id) { + $model->load($id); + } + + unset($data['entity_id']); + unset($data['form_key']); + unset($data['s_id']); + + $planData = $objectManager->get('Razorpay\Subscription\Model\Plans') + ->getCollection() + ->addFieldToFilter('plan_id', $data['plan_id']) + ->getFirstItem() + ->getData(); + + try { + + $entity_id = $planData['entity_id']; + $data['schedule_change_at'] = 'cycle_end'; + + $connection = $objectManager->get('Magento\Framework\App\ResourceConnection')->getConnection('\Magento\Framework\App\ResourceConnection::DEFAULT_CONNECTION'); + $key_id = $connection->fetchAll("SELECT * FROM core_config_data WHERE `path` LIKE 'payment/razorpay/key_id'"); + $key_secret = $connection->fetchAll("SELECT * FROM core_config_data WHERE `path` LIKE 'payment/razorpay/key_secret'"); + + $rzpId = $key_id[0]['value']; + $rzpSecret = $key_secret[0]['value']; + $rzp = new Api($rzpId, $rzpSecret); + + $subscriptionResponse = $rzp->subscription->fetch($subscriptionId)->update($data); + $subscription = $objectManager->create('Razorpay\Subscription\Model\Subscriptions'); + $postUpdate = $subscription->load($subscriptionId, 'subscription_id'); + $postUpdate->setPlanEntityId($entity_id); + $postUpdate->save(); + + $this->messageManager->addSuccess(__("Subscription updated")); + + $this->_getSession()->setFormData(false); + + return $resultRedirect->setPath('subscribed/index/index/'); + } catch (\Exception $e) { + $this->messageManager->addErrorMessage(__($e->getMessage())); + return $resultRedirect->setPath('subscribed/index/index/'); + } + + $this->_getSession()->setFormData($data); + return $resultRedirect->setPath('*/*/edit', ['entity_id' => $this->getRequest()->getParam('id')]); + } + return $resultRedirect->setPath('*/*/'); + } + +} \ No newline at end of file diff --git a/Controller/Adminhtml/Subscription/Upgrade.php b/Controller/Adminhtml/Subscription/Upgrade.php index 1e38fe7..a5a0b26 100644 --- a/Controller/Adminhtml/Subscription/Upgrade.php +++ b/Controller/Adminhtml/Subscription/Upgrade.php @@ -12,14 +12,13 @@ class Upgrade extends Action protected $_model; /** - * @param Action\Context $context + * @param Action\Context $context * @param \Maxime\Jobs\Model\Department $model **/ public function __construct( Action\Context $context, \Razorpay\Subscription\Model\Subscrib $model - ) - { + ) { parent::__construct($context); $this->_model = $model; } @@ -34,17 +33,22 @@ protected function _isAllowed() /** * Save action + * * @return \Magento\Framework\Controller\ResultInterface * */ public function execute() { $data = $this->getRequest()->getPostValue(); - /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + /** + * @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect +*/ $resultRedirect = $this->resultRedirectFactory->create(); if ($data) { - /** @var \Maxime\Jobs\Model\Department $model */ + /** + * @var \Maxime\Jobs\Model\Department $model +*/ $model = $this->_model; $id = $this->getRequest()->getParam('id'); diff --git a/Controller/Adminhtml/Subscription/View.php b/Controller/Adminhtml/Subscription/View.php index a04708d..621a13c 100644 --- a/Controller/Adminhtml/Subscription/View.php +++ b/Controller/Adminhtml/Subscription/View.php @@ -15,6 +15,7 @@ class View extends Action /** * Core registry + * * @var Registry */ protected $coreRegistry; @@ -25,8 +26,8 @@ class View extends Action protected $resultPageFactory; /** - * @param Context $context - * @param Registry $coreRegistry + * @param Context $context + * @param Registry $coreRegistry * @param PageFactory $resultPageFactory * * @codeCoverageIgnore @@ -46,6 +47,7 @@ public function __construct( /** * Saves the blog id to the register and renders the page + * * @return Page * @throws LocalizedException */ diff --git a/Controller/Customer/CancelSubscription.php b/Controller/Customer/CancelSubscription.php index 0847331..b1059d0 100644 --- a/Controller/Customer/CancelSubscription.php +++ b/Controller/Customer/CancelSubscription.php @@ -28,15 +28,14 @@ class CancelSubscription extends BaseController private $subscription; /** - * @param \Magento\Framework\App\Action\Context $context - * @param \Magento\Customer\Model\Session $customerSession - * @param \Magento\Checkout\Model\Session $checkoutSession + * @param \Magento\Framework\App\Action\Context $context + * @param \Magento\Customer\Model\Session $customerSession + * @param \Magento\Checkout\Model\Session $checkoutSession * @param \Magento\Razorpay\Model\Config\Payment $razorpayConfig - * @param \Magento\Framework\App\CacheInterface $cache - * @param \Psr\Log\LoggerInterface $logger + * @param \Magento\Framework\App\CacheInterface $cache + * @param \Psr\Log\LoggerInterface $logger */ public function __construct( - \Magento\Framework\App\Action\Context $context, \Magento\Customer\Model\Session $customerSession, \Magento\Checkout\Model\Session $checkoutSession, @@ -45,14 +44,12 @@ public function __construct( \Razorpay\Subscription\Helper\Subscription $subscription, \Psr\Log\LoggerInterface $logger, \Magento\Framework\Message\ManagerInterface $messageManager - ) - { + ) { parent::__construct( $context, $customerSession, $checkoutSession, $config - ); $this->messageManager = $messageManager; $this->config = $config; diff --git a/Controller/Customer/Index.php b/Controller/Customer/Index.php index 5823e0b..c01aac6 100644 --- a/Controller/Customer/Index.php +++ b/Controller/Customer/Index.php @@ -16,7 +16,7 @@ class Index extends Action protected $resultPageFactory; /** - * @param Context $context + * @param Context $context * @param PageFactory $resultPageFactory * * @codeCoverageIgnore @@ -32,6 +32,7 @@ public function __construct(Context $context,PageFactory $resultPageFactory) /** * Prints the blog from informed order id + * * @return Page * @throws LocalizedException */ diff --git a/Controller/Customer/MassCancelSubscription.php b/Controller/Customer/MassCancelSubscription.php index 746c1f3..5b9907b 100644 --- a/Controller/Customer/MassCancelSubscription.php +++ b/Controller/Customer/MassCancelSubscription.php @@ -28,15 +28,14 @@ class MassCancelSubscription extends BaseController private $subscription; /** - * @param \Magento\Framework\App\Action\Context $context - * @param \Magento\Customer\Model\Session $customerSession - * @param \Magento\Checkout\Model\Session $checkoutSession + * @param \Magento\Framework\App\Action\Context $context + * @param \Magento\Customer\Model\Session $customerSession + * @param \Magento\Checkout\Model\Session $checkoutSession * @param \Magento\Razorpay\Model\Config\Payment $razorpayConfig - * @param \Magento\Framework\App\CacheInterface $cache - * @param \Psr\Log\LoggerInterface $logger + * @param \Magento\Framework\App\CacheInterface $cache + * @param \Psr\Log\LoggerInterface $logger */ public function __construct( - \Magento\Framework\App\Action\Context $context, \Magento\Customer\Model\Session $customerSession, \Magento\Checkout\Model\Session $checkoutSession, @@ -45,14 +44,12 @@ public function __construct( \Razorpay\Subscription\Helper\Subscription $subscription, \Psr\Log\LoggerInterface $logger, \Magento\Framework\Message\ManagerInterface $messageManager - ) - { + ) { parent::__construct( $context, $customerSession, $checkoutSession, $config - ); $this->messageManager = $messageManager; $this->config = $config; @@ -73,9 +70,9 @@ public function execute() $updateBy = 'customer'; foreach ($orders as $order) { - $subscriptionData = $this->getSubscription($order); - if($subscriptionData['status'] != "created" || $subscriptionData['status'] != "cancelled"){ - $this->subscription->cancelSubscription($subscriptionData['subscription_id'], $this->rzp, $updateBy); + $subscriptionData = $this->getSubscription($order); + if($subscriptionData['status'] != "created" || $subscriptionData['status'] != "cancelled") { + $this->subscription->cancelSubscription($subscriptionData['subscription_id'], $this->rzp, $updateBy); } } @@ -83,7 +80,7 @@ public function execute() return $this->_redirect('razorpaysubscription/customer/index/'); } catch (\Exception $e) { $this->messageManager->addErrorMessage(__($e->getMessage())); - return $this->_redirect('razorpaysubscription/customer/index/'); + return $this->_redirect('razorpaysubscription/customer/index/'); } } diff --git a/Controller/Customer/MassPauseSubscription.php b/Controller/Customer/MassPauseSubscription.php index c7ee3fc..7ea8203 100644 --- a/Controller/Customer/MassPauseSubscription.php +++ b/Controller/Customer/MassPauseSubscription.php @@ -28,15 +28,14 @@ class MassPauseSubscription extends BaseController private $subscription; /** - * @param \Magento\Framework\App\Action\Context $context - * @param \Magento\Customer\Model\Session $customerSession - * @param \Magento\Checkout\Model\Session $checkoutSession + * @param \Magento\Framework\App\Action\Context $context + * @param \Magento\Customer\Model\Session $customerSession + * @param \Magento\Checkout\Model\Session $checkoutSession * @param \Magento\Razorpay\Model\Config\Payment $razorpayConfig - * @param \Magento\Framework\App\CacheInterface $cache - * @param \Psr\Log\LoggerInterface $logger + * @param \Magento\Framework\App\CacheInterface $cache + * @param \Psr\Log\LoggerInterface $logger */ public function __construct( - \Magento\Framework\App\Action\Context $context, \Magento\Customer\Model\Session $customerSession, \Magento\Checkout\Model\Session $checkoutSession, @@ -45,14 +44,12 @@ public function __construct( \Razorpay\Subscription\Helper\Subscription $subscription, \Psr\Log\LoggerInterface $logger, \Magento\Framework\Message\ManagerInterface $messageManager - ) - { + ) { parent::__construct( $context, $customerSession, $checkoutSession, $config - ); $this->messageManager = $messageManager; $this->config = $config; @@ -73,9 +70,9 @@ public function execute() $updateBy = 'customer'; foreach ($orders as $order) { - $subscriptionData = $this->getSubscription($order); - if($subscriptionData['status'] == "active"){ - $this->subscription->pauseSubscription($subscriptionData['subscription_id'], $this->rzp, $updateBy); + $subscriptionData = $this->getSubscription($order); + if($subscriptionData['status'] == "active") { + $this->subscription->pauseSubscription($subscriptionData['subscription_id'], $this->rzp, $updateBy); } } @@ -83,7 +80,7 @@ public function execute() return $this->_redirect('razorpaysubscription/customer/index/'); } catch (\Exception $e) { $this->messageManager->addErrorMessage(__($e->getMessage())); - return $this->_redirect('razorpaysubscription/customer/index/'); + return $this->_redirect('razorpaysubscription/customer/index/'); } } diff --git a/Controller/Customer/MassResumeSubscription.php b/Controller/Customer/MassResumeSubscription.php index f4881a2..d047f68 100644 --- a/Controller/Customer/MassResumeSubscription.php +++ b/Controller/Customer/MassResumeSubscription.php @@ -28,15 +28,14 @@ class MassResumeSubscription extends BaseController private $subscription; /** - * @param \Magento\Framework\App\Action\Context $context - * @param \Magento\Customer\Model\Session $customerSession - * @param \Magento\Checkout\Model\Session $checkoutSession + * @param \Magento\Framework\App\Action\Context $context + * @param \Magento\Customer\Model\Session $customerSession + * @param \Magento\Checkout\Model\Session $checkoutSession * @param \Magento\Razorpay\Model\Config\Payment $razorpayConfig - * @param \Magento\Framework\App\CacheInterface $cache - * @param \Psr\Log\LoggerInterface $logger + * @param \Magento\Framework\App\CacheInterface $cache + * @param \Psr\Log\LoggerInterface $logger */ public function __construct( - \Magento\Framework\App\Action\Context $context, \Magento\Customer\Model\Session $customerSession, \Magento\Checkout\Model\Session $checkoutSession, @@ -45,14 +44,12 @@ public function __construct( \Razorpay\Subscription\Helper\Subscription $subscription, \Psr\Log\LoggerInterface $logger, \Magento\Framework\Message\ManagerInterface $messageManager - ) - { + ) { parent::__construct( $context, $customerSession, $checkoutSession, $config - ); $this->messageManager = $messageManager; $this->config = $config; @@ -73,9 +70,9 @@ public function execute() $updateBy = 'customer'; foreach ($orders as $order) { - $subscriptionData = $this->getSubscription($order); - if($subscriptionData['status'] == "paused"){ - $this->subscription->resumeSubscription($subscriptionData['subscription_id'], $this->rzp, $updateBy); + $subscriptionData = $this->getSubscription($order); + if($subscriptionData['status'] == "paused") { + $this->subscription->resumeSubscription($subscriptionData['subscription_id'], $this->rzp, $updateBy); } } @@ -83,7 +80,7 @@ public function execute() return $this->_redirect('razorpaysubscription/customer/index/'); } catch (\Exception $e) { $this->messageManager->addErrorMessage(__($e->getMessage())); - return $this->_redirect('razorpaysubscription/customer/index/'); + return $this->_redirect('razorpaysubscription/customer/index/'); } } diff --git a/Controller/Customer/PauseSubscription.php b/Controller/Customer/PauseSubscription.php index b5d920d..7ba1d48 100644 --- a/Controller/Customer/PauseSubscription.php +++ b/Controller/Customer/PauseSubscription.php @@ -28,15 +28,14 @@ class PauseSubscription extends BaseController private $subscription; /** - * @param \Magento\Framework\App\Action\Context $context - * @param \Magento\Customer\Model\Session $customerSession - * @param \Magento\Checkout\Model\Session $checkoutSession + * @param \Magento\Framework\App\Action\Context $context + * @param \Magento\Customer\Model\Session $customerSession + * @param \Magento\Checkout\Model\Session $checkoutSession * @param \Magento\Razorpay\Model\Config\Payment $razorpayConfig - * @param \Magento\Framework\App\CacheInterface $cache - * @param \Psr\Log\LoggerInterface $logger + * @param \Magento\Framework\App\CacheInterface $cache + * @param \Psr\Log\LoggerInterface $logger */ public function __construct( - \Magento\Framework\App\Action\Context $context, \Magento\Customer\Model\Session $customerSession, \Magento\Checkout\Model\Session $checkoutSession, @@ -45,14 +44,12 @@ public function __construct( \Razorpay\Subscription\Helper\Subscription $subscription, \Psr\Log\LoggerInterface $logger, \Magento\Framework\Message\ManagerInterface $messageManager - ) - { + ) { parent::__construct( $context, $customerSession, $checkoutSession, $config - ); $this->messageManager = $messageManager; $this->config = $config; diff --git a/Controller/Customer/ResumeSubscription.php b/Controller/Customer/ResumeSubscription.php index 296bb73..b0b8573 100644 --- a/Controller/Customer/ResumeSubscription.php +++ b/Controller/Customer/ResumeSubscription.php @@ -28,15 +28,14 @@ class ResumeSubscription extends BaseController private $subscription; /** - * @param \Magento\Framework\App\Action\Context $context - * @param \Magento\Customer\Model\Session $customerSession - * @param \Magento\Checkout\Model\Session $checkoutSession + * @param \Magento\Framework\App\Action\Context $context + * @param \Magento\Customer\Model\Session $customerSession + * @param \Magento\Checkout\Model\Session $checkoutSession * @param \Magento\Razorpay\Model\Config\Payment $razorpayConfig - * @param \Magento\Framework\App\CacheInterface $cache - * @param \Psr\Log\LoggerInterface $logger + * @param \Magento\Framework\App\CacheInterface $cache + * @param \Psr\Log\LoggerInterface $logger */ public function __construct( - \Magento\Framework\App\Action\Context $context, \Magento\Customer\Model\Session $customerSession, \Magento\Checkout\Model\Session $checkoutSession, @@ -45,14 +44,12 @@ public function __construct( \Razorpay\Subscription\Helper\Subscription $subscription, \Psr\Log\LoggerInterface $logger, \Magento\Framework\Message\ManagerInterface $messageManager - ) - { + ) { parent::__construct( $context, $customerSession, $checkoutSession, $config - ); $this->messageManager = $messageManager; $this->config = $config; diff --git a/Controller/Subscrib/Edit.php b/Controller/Subscrib/Edit.php index 355c576..6b78c6c 100644 --- a/Controller/Subscrib/Edit.php +++ b/Controller/Subscrib/Edit.php @@ -15,6 +15,7 @@ class Edit extends Action /** * Core registry + * * @var Registry */ protected $_coreRegistry; @@ -25,8 +26,8 @@ class Edit extends Action protected $_resultPageFactory; /** - * @param Context $context - * @param Registry $coreRegistry + * @param Context $context + * @param Registry $coreRegistry * @param PageFactory $resultPageFactory * * @codeCoverageIgnore @@ -47,6 +48,7 @@ public function __construct( /** * Saves the blog id to the register and renders the page + * * @return Page * @throws LocalizedException */ diff --git a/Controller/Subscrib/FormPost.php b/Controller/Subscrib/FormPost.php index 9241b52..6386024 100644 --- a/Controller/Subscrib/FormPost.php +++ b/Controller/Subscrib/FormPost.php @@ -31,26 +31,27 @@ class FormPost extends BaseController /** * SubscribCollectionFactory + * * @var null|SubscribFactory */ protected $_subscribCollectionFactory = null; /** * PlanCollectionFactory + * * @var null|PlanFactory */ protected $_planCollectionFactory = null; /** - * @param \Magento\Framework\App\Action\Context $context - * @param \Magento\Customer\Model\Session $customerSession - * @param \Magento\Checkout\Model\Session $checkoutSession + * @param \Magento\Framework\App\Action\Context $context + * @param \Magento\Customer\Model\Session $customerSession + * @param \Magento\Checkout\Model\Session $checkoutSession * @param \Magento\Razorpay\Model\Config\Payment $razorpayConfig - * @param \Magento\Framework\App\CacheInterface $cache - * @param \Psr\Log\LoggerInterface $logger + * @param \Magento\Framework\App\CacheInterface $cache + * @param \Psr\Log\LoggerInterface $logger */ public function __construct( - \Magento\Framework\App\Action\Context $context, \Magento\Customer\Model\Session $customerSession, \Magento\Checkout\Model\Session $checkoutSession, @@ -61,14 +62,12 @@ public function __construct( PlanCollectionFactory $planCollectionFactory, SubscribCollectionFactory $subscribCollectionFactory, \Magento\Framework\Message\ManagerInterface $messageManager - ) - { + ) { parent::__construct( $context, $customerSession, $checkoutSession, $config - ); $this->messageManager = $messageManager; $this->config = $config; @@ -95,17 +94,17 @@ public function execute() return $this->_redirect('customer/account/login'); } - if($this->planValidate($subscriptionId, $plan['magento_product_id'])){ - $postValues['entity_id'] = $plan['entity_id']; - $postValues['schedule_change_at'] = 'cycle_end'; - $this->subscription->editSubscription($subscriptionId, $postValues, $this->rzp); - $this->messageManager->addSuccess(__("Subscription updated successfully!")); + if($this->planValidate($subscriptionId, $plan['magento_product_id'])) { + $postValues['entity_id'] = $plan['entity_id']; + $postValues['schedule_change_at'] = 'cycle_end'; + $this->subscription->editSubscription($subscriptionId, $postValues, $this->rzp); + $this->messageManager->addSuccess(__("Subscription updated successfully!")); } return $this->_redirect('razorpaysubscription/customer/index/'); } catch (\Exception $e) { $this->messageManager->addErrorMessage(__($e->getMessage())); - return $this->_redirect('razorpaysubscription/customer/index/'); + return $this->_redirect('razorpaysubscription/customer/index/'); } } @@ -119,11 +118,11 @@ protected function planValidate($subscriptionId, $productId) $singleData= $subscribCollection->getFirstItem(); $data = $singleData->getData(); - if(count($data)==0){ - return $response; + if(count($data)==0) { + return $response; } - if($data['product_id']==$productId){ + if($data['product_id']==$productId) { $response = true; } diff --git a/Controller/Subscrib/View.php b/Controller/Subscrib/View.php index 40f5ed3..85ee4bf 100644 --- a/Controller/Subscrib/View.php +++ b/Controller/Subscrib/View.php @@ -15,6 +15,7 @@ class View extends Action /** * Core registry + * * @var Registry */ protected $_coreRegistry; @@ -25,8 +26,8 @@ class View extends Action protected $_resultPageFactory; /** - * @param Context $context - * @param Registry $coreRegistry + * @param Context $context + * @param Registry $coreRegistry * @param PageFactory $resultPageFactory * * @codeCoverageIgnore @@ -46,6 +47,7 @@ public function __construct( /** * Saves the blog id to the register and renders the page + * * @return Page * @throws LocalizedException */ diff --git a/Controller/Subscription/SubscriptionOrder.php b/Controller/Subscription/SubscriptionOrder.php index f579ecc..4f5c558 100644 --- a/Controller/Subscription/SubscriptionOrder.php +++ b/Controller/Subscription/SubscriptionOrder.php @@ -6,6 +6,7 @@ use Razorpay\Magento\Controller\BaseController; use Razorpay\Magento\Model\PaymentMethod; use Razorpay\Subscription\Helper\Subscription; +use Magento\Framework\HTTP\PhpEnvironment\Request; class SubscriptionOrder extends BaseController { @@ -46,15 +47,21 @@ class SubscriptionOrder extends BaseController * @var CheckoutSession */ protected $checkoutSession; + /** + * @var Request + */ + protected $request; + /** - * @param \Magento\Framework\App\Action\Context $context - * @param \Magento\Customer\Model\Session $customerSession - * @param \Magento\Checkout\Model\Session $checkoutSession - * @param \Magento\Razorpay\Model\Config\Payment $razorpayConfig - * @param \Magento\Framework\App\CacheInterface $cache + * @param \Magento\Framework\App\Action\Context $context + * @param \Magento\Customer\Model\Session $customerSession + * @param \Magento\Checkout\Model\Session $checkoutSession + * @param \Magento\Razorpay\Model\Config\Payment $razorpayConfig + * @param \Magento\Framework\App\CacheInterface $cache * @param \Magento\Sales\Api\OrderRepositoryInterface $orderRepository - * @param \Psr\Log\LoggerInterface $logger + * @param \Psr\Log\LoggerInterface $logger + * @param Request $request */ public function __construct( \Magento\Framework\App\Action\Context $context, @@ -66,7 +73,8 @@ public function __construct( \Magento\Framework\App\CacheInterface $cache, \Magento\Sales\Api\OrderRepositoryInterface $orderRepository, \Razorpay\Subscription\Helper\Subscription $subscription, - \Psr\Log\LoggerInterface $logger + \Psr\Log\LoggerInterface $logger, + Request $request ) { parent::__construct( $context, @@ -74,7 +82,7 @@ public function __construct( $checkoutSession, $config ); - + $this->request = $request; $this->config = $config; $this->cartManagement = $cartManagement; $this->customerSession = $customerSession; @@ -89,27 +97,26 @@ public function __construct( public function execute() { + + $post = $this->getRequest()->getPost(); try{ $receiptId = $this->getQuote()->getId(); - if(empty($_POST['error']) === false) - { + if(empty($post['error']) === false) { $this->messageManager->addError(__('Payment Failed')); return $this->_redirect('checkout/cart'); } - if (isset($_POST['order_check'])) - { - if (empty($this->cache->load("quote_processing_".$receiptId)) === false) - { + if (isset($post['order_check'])) { + if (empty($this->cache->load("quote_processing_".$receiptId)) === false) { $responseContent = [ 'success' => true, 'order_id' => false, 'parameters' => [] ]; - # fetch the related sales order and verify the payment ID with rzp payment id - # To avoid duplicate order entry for same quote + // fetch the related sales order and verify the payment ID with rzp payment id + // To avoid duplicate order entry for same quote $collection = $this->_objectManager->get('Magento\Sales\Model\Order') ->getCollection() ->addFieldToSelect('entity_id') @@ -118,10 +125,11 @@ public function execute() $salesOrder = $collection->getData(); - if (empty($salesOrder['entity_id']) === false) - { - $this->logger->info("Razorpay inside order already processed with webhook quoteID:" . $receiptId - ." and OrderID:".$salesOrder['entity_id']); + if (empty($salesOrder['entity_id']) === false) { + $this->logger->info( + "Razorpay inside order already processed with webhook quoteID:" . $receiptId + ." and OrderID:".$salesOrder['entity_id'] + ); $this->checkoutSession ->setLastQuoteId($this->getQuote()->getId()) @@ -141,8 +149,7 @@ public function execute() } else { - if(empty($receiptId) === false) - { + if(empty($receiptId) === false) { //set the chache to stop webhook processing $this->cache->save("started", "quote_Front_processing_$receiptId", ["razorpay"], 30); @@ -155,8 +162,10 @@ public function execute() } else { - $this->logger->info("Razorpay order already processed with quoteID:" . $this->checkoutSession - ->getLastQuoteId()); + $this->logger->info( + "Razorpay order already processed with quoteID:" . $this->checkoutSession + ->getLastQuoteId() + ); $responseContent = [ 'success' => true, @@ -174,8 +183,7 @@ public function execute() return $response; } - if(isset($_POST['razorpay_payment_id'])) - { + if(isset($post['razorpay_payment_id'])) { $this->getQuote()->getPayment()->setMethod(PaymentMethod::METHOD_CODE); try @@ -195,7 +203,7 @@ public function execute() } else { - if (empty($_POST['email']) === true) { + if (empty($post['email']) === true) { $this->logger->info("Email field is required"); $responseContent = [ @@ -206,7 +214,7 @@ public function execute() $code = 200; } else { $paymentAction = $this->config->getPaymentAction(); - $this->customerSession->setCustomerEmailAddress($_POST['email']); + $this->customerSession->setCustomerEmailAddress($post['email']); $responseContent = [ 'message' => 'Unable to create your order. Please contact support.', diff --git a/Helper/Subscription.php b/Helper/Subscription.php index 598de06..10f2e42 100644 --- a/Helper/Subscription.php +++ b/Helper/Subscription.php @@ -45,8 +45,9 @@ public function __construct(Product $product, LoggerInterface $logger, Cart $ca /** * This function is used to create subscription for the user - * @param $quote - * @param $rzp + * + * @param $quote + * @param $rzp * @return mixed * @throws \Exception */ @@ -77,7 +78,7 @@ public function createSubscription($quote, $rzp) $subscriptionData["start_at"] = strtotime("+{$planData['plan_trial']} days"); } $items = $item = []; - if ($quote->getShippingAddress()->getShippingAmount()) { + if ($quote->getShippingAddress()->getShippingAmount() && $quote->getShippingAddress()->getShippingAmount() > 0) { $item["item"] = [ "name" => "Shipping charges", "amount" => (int)(number_format($quote->getShippingAddress()->getShippingAmount() * 100, 0, ".", "")), @@ -96,7 +97,7 @@ public function createSubscription($quote, $rzp) ->setSubscriptionId($subscriptionResponse->id) ->setRazorpayCustomerId($subscriptionResponse->customer_id) ->setmagentoUserId($quote->getCustomerId()) - ->setProductId( $planData['magento_product_id']) + ->setProductId($planData['magento_product_id']) ->setQuoteId($quote->getId()) ->setStatus($subscriptionResponse->status) ->setTotalCount($subscriptionResponse->total_count) @@ -151,7 +152,8 @@ public function fetchPlanId($quote) /** * This function gets the product details from quotes - * @param $quote + * + * @param $quote * @return array */ public function getPlanIdFromQuote($quote) @@ -165,8 +167,9 @@ public function getPlanIdFromQuote($quote) /** * This functions creates customers in razorpay - * @param $quote - * @param $rzp + * + * @param $quote + * @param $rzp * @return mixed * @throws \Exception */ @@ -203,7 +206,8 @@ public function getCustomerId($quote, $rzp) /** * This function get the merchant preferences from razorpay dashboard - * @param $apiKey + * + * @param $apiKey * @return array */ public function getMerchantPreferences($apiKey) @@ -233,8 +237,8 @@ public function getMerchantPreferences($apiKey) } /** - * @param $cartItems - * @param $validateTo + * @param $cartItems + * @param $validateTo * @return bool */ public function validateIsASubscriptionProduct($cartItems, $validateTo) @@ -263,8 +267,9 @@ public function validateIsASubscriptionProduct($cartItems, $validateTo) /** * Cancel subscription - * @param $id - * @param $rzp + * + * @param $id + * @param $rzp * @throws \Exception */ public function cancelSubscription($id, $rzp, $updateBy) @@ -284,7 +289,8 @@ public function cancelSubscription($id, $rzp, $updateBy) /** * Pause Subscription - * @param $id + * + * @param $id * @return array */ public function pauseSubscription($id, $rzp, $updateBy) @@ -304,7 +310,8 @@ public function pauseSubscription($id, $rzp, $updateBy) /** * Resume Subscription - * @param $id + * + * @param $id * @return array */ public function resumeSubscription($id, $rzp, $updateBy) @@ -324,10 +331,12 @@ public function resumeSubscription($id, $rzp, $updateBy) /** * Fetch all Subscription invoices - * @param $subscriptionId + * + * @param $subscriptionId * @return array */ - public function fetchSubscriptionInvoice($subscriptionId, $rzp){ + public function fetchSubscriptionInvoice($subscriptionId, $rzp) + { $subscriptionResponse = $rzp->invoice->all(["subscription_id"=>$subscriptionId]); @@ -335,7 +344,7 @@ public function fetchSubscriptionInvoice($subscriptionId, $rzp){ $subscription = $this->objectManagement->create('Razorpay\Subscription\Model\Subscriptions'); $postUpdate = $subscription->load($subscriptionId, 'subscription_id'); - if($subscriptionResponse->count > $postUpdate->getPaidCount()){ + if($subscriptionResponse->count > $postUpdate->getPaidCount()) { $postUpdate->setRemainingCount($postUpdate->getTotalCount() - $subscriptionResponse->count); $postUpdate->setPaidCount($subscriptionResponse->count); $postUpdate->setNextChargeAt($subscriptionResponse->items[0]['billing_end']); @@ -346,7 +355,8 @@ public function fetchSubscriptionInvoice($subscriptionId, $rzp){ /** * Edit Subscription - * @param $subscriptionId + * + * @param $subscriptionId * @return array */ public function editSubscription($subscriptionId, $attributes, $rzp) @@ -361,13 +371,14 @@ public function editSubscription($subscriptionId, $attributes, $rzp) $postUpdate->save(); }catch(\Error $e){ - throw new \Exception( $e->getMessage() ); + throw new \Exception($e->getMessage()); } } /** * Fetch pending updates - * @param $subscriptionId + * + * @param $subscriptionId * @return array */ public function pendingUpdate($subscriptionId, $rzp) @@ -375,13 +386,14 @@ public function pendingUpdate($subscriptionId, $rzp) try{ $subscriptionResponse = $rzp->subscription->fetch($subscriptionId)->pendingUpdate(); return $subscriptionResponse; - }catch(Error $e){ + }catch(Error $e){ return []; } } /** * Checking if subscription is active or not in payment setting + * * @return bool */ public function isSubscriptionActive() diff --git a/Helper/SubscriptionWebhook.php b/Helper/SubscriptionWebhook.php index dfd7e2b..201b6fc 100644 --- a/Helper/SubscriptionWebhook.php +++ b/Helper/SubscriptionWebhook.php @@ -58,7 +58,8 @@ public function __construct($logger) /** * Processing subscription charge event - * @param $data + * + * @param $data * @return int|void * @throws \Magento\Framework\Exception\LocalizedException */ @@ -95,7 +96,7 @@ public function processSubscriptionCharged($data) $orderLinkCollection->setWebhookFirstNotifiedAt(time()) ->setWebhookCount($orderLink['webhook_count'] + 1) ->save(); - exit; + return; } $webhookWaitTime = $this->_config->getConfigData(Config::WEBHOOK_WAIT_TIME) ?? 300; @@ -108,7 +109,7 @@ public function processSubscriptionCharged($data) ->save(); header('Status: 409 Conflict, too early for processing', true, 409); - exit; + return; } // checking if payment id is null hen processing same quote for order else creating new order @@ -284,7 +285,8 @@ public function processSubscriptionAction($data) $rzpSubscriptionId = $data['payload']['subscription']['entity']['id']; $quoteId = $data['payload']['subscription']['entity']['notes']['magento_quote_id']; $webHookSource = $data['payload']['subscription']['entity']['notes']['source']; - + $status = $data['payload']['subscription']['entity']['status']; + if (empty($quoteId)) { $this->_logger->info("Razorpay Subscription Webhook: Quote ID not set for Razorpay subscription id(:$rzpSubscriptionId)"); return; @@ -292,26 +294,13 @@ public function processSubscriptionAction($data) // Process only if its from magento source if ($webHookSource == "magento-subscription") { - - switch ($data['event']) { - case 'subscription.paused': - $status = 'paused'; - break; - - case 'subscription.resumed': - $status = 'active'; - break; - - case 'subscription.cancelled': - $status = 'cancelled'; - break; - } - $subscription = $this->_objectManagement->create('Razorpay\Subscription\Model\Subscriptions'); $postUpdate = $subscription->load($rzpSubscriptionId, 'subscription_id'); $postUpdate->setStatus($status); - $postUpdate->setCancelBy('Razorpay'); - $postUpdate->save(); + if($status == "cancelled"){ + $postUpdate->setCancelBy('Razorpay'); + } + $postUpdate->save(); $this->_logger->info("Razorpay Subscription Webhook Processed successfully for Razorpay subscriptionId(:$rzpSubscriptionId)"); } @@ -350,14 +339,16 @@ protected function getQuoteObject($post, $quoteId) $customer = $customer->loadByEmail($email); //if quote billing address doesn't contains address, set it as customer default billing address - if ((empty($quote->getBillingAddress()->getFirstname()) === true) and - (empty($customer->getEntityId()) === false)) { + if ((empty($quote->getBillingAddress()->getFirstname()) === true) + and (empty($customer->getEntityId()) === false) + ) { $quote->getBillingAddress()->setCustomerAddressId($customer->getDefaultBillingAddress()['id']); } //If need to insert new customer as guest - if ((empty($customer->getEntityId()) === true) or - (empty($quote->getBillingAddress()->getCustomerId()) === true)) { + if ((empty($customer->getEntityId()) === true) + or (empty($quote->getBillingAddress()->getCustomerId()) === true) + ) { $quote->setCustomerFirstname($firstName); $quote->setCustomerLastname($lastName); $quote->setCustomerEmail($email); @@ -382,8 +373,9 @@ protected function getQuoteObject($post, $quoteId) * Fetch the related sales order and verify * the payment ID with rzp payment id * To avoid duplicate order entry for same quote - * @param $quoteId - * @param $paymentId + * + * @param $quoteId + * @param $paymentId * @return bool */ protected function verifyPaymentIdTowardsOrder($quoteId, $paymentId): bool @@ -409,9 +401,9 @@ protected function verifyPaymentIdTowardsOrder($quoteId, $paymentId): bool } /** - * @param $data - * @param $subscriptionData - * @param $quote + * @param $data + * @param $subscriptionData + * @param $quote * @return array */ protected function createNewOrderData($data, $subscriptionData, $quote): array @@ -450,9 +442,10 @@ protected function createNewOrderData($data, $subscriptionData, $quote): array /** * creating new order from quote - * @param $quote - * @param $amount - * @param $paymentId + * + * @param $quote + * @param $amount + * @param $paymentId * @return mixed */ protected function createOrderFromQuote($quote, $amount, $paymentId) diff --git a/Logger/SubscriptionLogger.php b/Logger/SubscriptionLogger.php index feec8d4..d5c5447 100755 --- a/Logger/SubscriptionLogger.php +++ b/Logger/SubscriptionLogger.php @@ -11,17 +11,20 @@ class SubscriptionLogger extends \Magento\Framework\Logger\Handler\Base { /** * Logging level + * * @var int */ protected $loggerType = \Monolog\Logger::INFO; /** * File name + * * @var string */ public $fileName = ''; /** * File name + * * @var string */ public $cutomfileName = 'NO_PATH'; diff --git a/Model/Plans.php b/Model/Plans.php index f5ce507..6118c4a 100755 --- a/Model/Plans.php +++ b/Model/Plans.php @@ -1,5 +1,4 @@ _init(\Razorpay\Subscription\Model\ResourceModel\Plans::class); } - public function getEnableStatus() { + public function getEnableStatus() + { return 1; } - - public function getDisableStatus() { + + public function getDisableStatus() + { return 0; } - + public function getAvailableStatuses() { - return [$this->getDisableStatus() => __('Disabled'), $this->getEnableStatus() => __('Enabled')]; + return [ + $this->getEnableStatus() => __('Enabled'), + $this->getDisableStatus() => __('Disabled') + ]; } } diff --git a/Model/ResourceModel/Plans/CollectionFactory.php b/Model/ResourceModel/Plans/CollectionFactory.php index 02e1e56..4c07876 100644 --- a/Model/ResourceModel/Plans/CollectionFactory.php +++ b/Model/ResourceModel/Plans/CollectionFactory.php @@ -21,7 +21,7 @@ class CollectionFactory * Factory constructor * * @param \Magento\Framework\ObjectManagerInterface $objectManager - * @param string $instanceName + * @param string $instanceName */ public function __construct(\Magento\Framework\ObjectManagerInterface $objectManager, $instanceName = '\\Razorpay\\Subscription\\Model\\ResourceModel\\Plans\\Collection') { @@ -32,7 +32,7 @@ public function __construct(\Magento\Framework\ObjectManagerInterface $objectMan /** * Create class instance with specified parameters * - * @param array $data + * @param array $data * @return \Razorpay\Subscription\Model\ResourceModel\Plans\Collection */ public function create(array $data = array()) diff --git a/Model/ResourceModel/Subscrib.php b/Model/ResourceModel/Subscrib.php index a6e1eb6..ab9c204 100644 --- a/Model/ResourceModel/Subscrib.php +++ b/Model/ResourceModel/Subscrib.php @@ -6,6 +6,7 @@ /** * Class Subscrib + * * @package Razorpay\Subscription\Model\ResourceModel */ class Subscrib extends AbstractDb diff --git a/Model/ResourceModel/Subscrib/Collection.php b/Model/ResourceModel/Subscrib/Collection.php index 448e8f6..d821854 100755 --- a/Model/ResourceModel/Subscrib/Collection.php +++ b/Model/ResourceModel/Subscrib/Collection.php @@ -6,6 +6,7 @@ /** * Class Collection + * * @package Razorpay\Subscription\Model\ResourceModel\Subscrib */ class Collection extends AbstractCollection @@ -25,6 +26,7 @@ class Collection extends AbstractCollection /** * Define resource model + * * @return void */ protected function _construct() diff --git a/Model/Source/Plan/PlanInterval.php b/Model/Source/Plan/PlanInterval.php new file mode 100644 index 0000000..52a72a5 --- /dev/null +++ b/Model/Source/Plan/PlanInterval.php @@ -0,0 +1,38 @@ + 'yearly', + 'label' => 'Year(s)', + ], + [ + 'value' => 'monthly', + 'label' => 'Month(s)', + ], + [ + 'value' => 'weekly', + 'label' => 'Week(s)', + ], + [ + 'value' => 'daily', + 'label' => 'Day(s)', + ] + ]; + } +} + + diff --git a/Model/Source/Plan/ProductList.php b/Model/Source/Plan/ProductList.php new file mode 100644 index 0000000..5d775e4 --- /dev/null +++ b/Model/Source/Plan/ProductList.php @@ -0,0 +1,36 @@ +collectionFactory = $collectionFactory; + } + + public function toOptionArray() + { + $options= []; + $collection = $this->collectionFactory->create() + ->addAttributeToSelect('*') + ->addAttributeToFilter('type_id',array('in' => array('simple','configurable'))); + + foreach ($collection as $category) { + $options[] = [ + 'label' => $category->getName(), + 'value' => $category->getId(), + ]; + } + return $options; + } +} + diff --git a/Model/Source/ProductList.php b/Model/Source/ProductList.php index e735637..b3d94d9 100644 --- a/Model/Source/ProductList.php +++ b/Model/Source/ProductList.php @@ -22,7 +22,7 @@ public function toOptionArray() $options[] = ['label' => '-- Please Select --', 'value' => '']; $collection = $this->collectionFactory->create() ->addAttributeToSelect('*') - ->addAttributeToFilter('type_id', array('in' => array('simple','configurable'))); + ->addAttributeToFilter('type_id', array('in' => array('simple','configurable'))); foreach ($collection as $category) { $options[] = [ diff --git a/Model/Subscrib.php b/Model/Subscrib.php index 11e98de..bcbbd4b 100755 --- a/Model/Subscrib.php +++ b/Model/Subscrib.php @@ -8,6 +8,7 @@ /** * Class Subscrib + * * @package Razorpay\Subscription\Model */ class Subscrib extends AbstractModel implements SubscribInterface, IdentityInterface @@ -71,6 +72,7 @@ public function getId() /** * Return identities + * * @return string[] */ public function getIdentities() @@ -81,7 +83,7 @@ public function getIdentities() /** * Set SubscriptionId * - * @param string $SubscriptionId + * @param string $SubscriptionId * @return $this */ public function setSubscriptionId($SubscriptionId) @@ -92,7 +94,7 @@ public function setSubscriptionId($SubscriptionId) /** * Set Status * - * @param string $Status + * @param string $Status * @return $this */ public function setStatus($status) @@ -103,7 +105,7 @@ public function setStatus($status) /** * Set Value * - * @param string $value + * @param string $value * @return $this */ public function setValue($value) @@ -114,7 +116,7 @@ public function setValue($value) /** * Set Next Charge At * - * @param string $nextChargeAt + * @param string $nextChargeAt * @return $this */ public function setNextChargeAt($nextChargeAt) @@ -125,7 +127,7 @@ public function setNextChargeAt($nextChargeAt) /** * Set ID * - * @param int $id + * @param int $id * @return $this */ public function setId($id) diff --git a/Model/SubscriptionConfig.php b/Model/SubscriptionConfig.php index bfa3329..ac5d252 100644 --- a/Model/SubscriptionConfig.php +++ b/Model/SubscriptionConfig.php @@ -42,7 +42,7 @@ public function __construct( /** * Retrieve information from payment configuration * - * @param string $field + * @param string $field * @param null|string $storeId * * @return mixed @@ -59,7 +59,7 @@ public function getConfigData($field, $storeId = null) } /** - * @param int $storeId + * @param int $storeId * @return $this */ public function setStoreId($storeId) @@ -71,8 +71,8 @@ public function setStoreId($storeId) /** * Set information from payment configuration * - * @param string $field - * @param string $value + * @param string $field + * @param string $value * @param null|string $storeId * * @return mixed diff --git a/Model/SubscriptionPaymentMethod.php b/Model/SubscriptionPaymentMethod.php index f4fd260..c400fe9 100644 --- a/Model/SubscriptionPaymentMethod.php +++ b/Model/SubscriptionPaymentMethod.php @@ -8,9 +8,11 @@ use Razorpay\Api\Api; use Razorpay\Magento\Model\Config; + /** * Class SubscriptionPaymentMethod - * @package Razorpay\Magento\Model + * + * @package Razorpay\Magento\Model * @SuppressWarnings(PHPMD.TooManyFields) * @SuppressWarnings(PHPMD.CouplingBetweenObjects) * @SuppressWarnings(PHPMD.ExcessiveClassComplexity) @@ -94,22 +96,22 @@ class SubscriptionPaymentMethod extends \Magento\Payment\Model\Method\AbstractMe protected $orderRepository; /** - * @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\App\Config\ScopeConfigInterface $scopeConfig - * @param \Magento\Payment\Model\Method\Logger $logger - * @param \Razorpay\Magento\Model\Config $config - * @param \Magento\Framework\App\RequestInterface $request - * @param TransactionCollectionFactory $salesTransactionCollectionFactory - * @param \Magento\Framework\App\ProductMetadataInterface $productMetaData - * @param \Magento\Directory\Model\RegionFactory $regionFactory - * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource - * @param \Magento\Sales\Api\OrderRepositoryInterface $orderRepository - * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection - * @param array $data + * @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\App\Config\ScopeConfigInterface $scopeConfig + * @param \Magento\Payment\Model\Method\Logger $logger + * @param \Razorpay\Magento\Model\Config $config + * @param \Magento\Framework\App\RequestInterface $request + * @param TransactionCollectionFactory $salesTransactionCollectionFactory + * @param \Magento\Framework\App\ProductMetadataInterface $productMetaData + * @param \Magento\Directory\Model\RegionFactory $regionFactory + * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource + * @param \Magento\Sales\Api\OrderRepositoryInterface $orderRepository + * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection + * @param array $data * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -185,8 +187,8 @@ public function validate() /** * Authorizes specified amount * - * @param InfoInterface $payment - * @param string $amount + * @param InfoInterface $payment + * @param string $amount * @return $this * @throws LocalizedException */ @@ -194,7 +196,9 @@ public function authorize(InfoInterface $payment, $amount) { try { - /** @var \Magento\Sales\Model\Order\Payment $payment */ + /** + * @var \Magento\Sales\Model\Order\Payment $payment +*/ $order = $payment->getOrder(); $orderId = $order->getIncrementId(); @@ -205,18 +209,16 @@ public function authorize(InfoInterface $payment, $amount) //validate RzpOrderamount with quote/order amount before signature $orderAmount = (int) (number_format($order->getGrandTotal() * 100, 0, ".", "")); - if((empty($request) === true) and (isset($_POST['razorpay_signature']) === true)) - { + if((empty($request) === true) and (isset($request['razorpay_signature']) === true)) { //set request data based on redirect flow $request['paymentMethod']['additional_data'] = [ - 'rzp_payment_id' => $_POST['razorpay_payment_id'], - 'rzp_order_id' => $_POST['razorpay_order_id'], - 'rzp_signature' => $_POST['razorpay_signature'] + 'rzp_payment_id' => $request['razorpay_payment_id'], + 'rzp_order_id' => $request['razorpay_order_id'], + 'rzp_signature' => $request['razorpay_signature'] ]; } - if(empty($request['payload']['payment']['entity']['id']) === false) - { + if(empty($request['payload']['payment']['entity']['id']) === false) { $payment_id = $request['payload']['payment']['entity']['id']; $rzp_order_id = $request['payload']['subscription']['entity']['id']; @@ -230,18 +232,19 @@ public function authorize(InfoInterface $payment, $amount) $payment_id = $request['paymentMethod']['additional_data']['rzp_payment_id']; $rzp_order_id = $this->order->getOrderId(); - if ($orderAmount !== $this->order->getRazorpayOrderAmount()) - { + if ($orderAmount !== $this->order->getRazorpayOrderAmount()) { $rzpOrderAmount = $order->getOrderCurrency()->formatTxt(number_format($this->order->getRazorpayOrderAmount() / 100, 2, ".", "")); throw new LocalizedException(__("Cart order amount = %1 doesn't match with amount paid = %2", $order->getOrderCurrency()->formatTxt($order->getGrandTotal()), $rzpOrderAmount)); } - $this->validateSignature([ + $this->validateSignature( + [ 'razorpay_payment_id' => $payment_id, 'razorpay_subscription_id' => $rzp_order_id, 'razorpay_signature' => $request['paymentMethod']['additional_data']['rzp_signature'] - ]); + ] + ); } @@ -267,8 +270,8 @@ public function authorize(InfoInterface $payment, $amount) /** * Capture specified amount with authorization * - * @param InfoInterface $payment - * @param string $amount + * @param InfoInterface $payment + * @param string $amount * @return $this */ @@ -316,13 +319,11 @@ protected function updatePaymentNote($paymentId, $order, $rzpSubscriptionId, $is $orderLink = $orderLinkCollection->getData(); - if (empty($orderLink['entity_id']) === false) - { + if (empty($orderLink['entity_id']) === false) { $orderLinkCollection->setRzpPaymentId($paymentId) ->setIncrementOrderId($order->getIncrementId()); - if ($isWebhookCall) - { + if ($isWebhookCall) { $orderLinkCollection->setByWebhook(true)->save(); } else @@ -335,8 +336,7 @@ protected function updatePaymentNote($paymentId, $order, $rzpSubscriptionId, $is $subscriptionCollection = $_objectManager->get('Razorpay\Subscription\Model\Subscriptions') ->getCollection() ->addFilter('subscription_id', $rzpSubscriptionId) - ->getFirstItem() - ; + ->getFirstItem(); $subscriptionData = $subscriptionCollection->getData(); if (!empty($subscriptionData)) { @@ -352,17 +352,16 @@ protected function updatePaymentNote($paymentId, $order, $rzpSubscriptionId, $is $productId = $item->getProduct()->getId(); } - if ($isWebhookCall) - { + if ($isWebhookCall) { $subscriptionOrderMapping->setByWebhook(true); } else { $subscriptionOrderMapping->setByFrontend(true); $productObject = $_objectManager->get('Magento\Catalog\Model\Product')->load($productId); - if($productObject){ + if($productObject) { /* @var Magento\Catalog\Model\Product $productObject */ - if($productObject->getRazorpaySubscriptionTrial()){ + if($productObject->getRazorpaySubscriptionTrial()) { $subscriptionOrderMapping->setIsTrialOrder(true); } } @@ -399,7 +398,8 @@ protected function validateSignature($request) /** * [validateWebhookSignature Used in case of webhook request for payment auth] - * @param array $post + * + * @param array $post * @return [type] */ public function validateWebhookSignature(array $post) @@ -431,7 +431,7 @@ protected function getChannel() /** * Retrieve information from payment configuration * - * @param string $field + * @param string $field * @param int|string|null|\Magento\Store\Model\Store $storeId * * @return mixed diff --git a/Model/SubscriptionWebhookEvents.php b/Model/SubscriptionWebhookEvents.php index a62793d..a2c50ad 100644 --- a/Model/SubscriptionWebhookEvents.php +++ b/Model/SubscriptionWebhookEvents.php @@ -17,20 +17,35 @@ public function toOptionArray() foreach ($webhookEvent->toOptionArray() as $value){ array_push($events, $value); } - array_push($events,[ - 'value' => "subscription.charged", - 'label' => __('subscription.charged') - ]); - - array_push($events,[ - 'value' => "subscription.paused", - 'label' => __('subscription.paused') - ]); - - array_push($events,[ - 'value' => "subscription.cancelled", - 'label' => __('subscription.cancelled') - ]); + $subscriptionEvents = [ + [ + 'value' => "subscription.charged", + 'label' => __('subscription.charged') + ], + [ + 'value' => "subscription.paused", + 'label' => __('subscription.paused') + ], + [ + 'value' => "subscription.resumed", + 'label' => __('subscription.resumed') + ], + [ + 'value' => "subscription.cancelled", + 'label' => __('subscription.cancelled') + ], + [ + 'value' => "subscription.pending", + 'label' => __('subscription.pending') + ], + [ + 'value' => "subscription.halted", + 'label' => __('subscription.halted') + ] + ]; + foreach ($subscriptionEvents as $value){ + array_push($events, $value); + } return $events; } } diff --git a/Observer/CheckoutCartProductAddAfterObserver.php b/Observer/CheckoutCartProductAddAfterObserver.php index 0616a8e..ade5471 100644 --- a/Observer/CheckoutCartProductAddAfterObserver.php +++ b/Observer/CheckoutCartProductAddAfterObserver.php @@ -25,17 +25,16 @@ class CheckoutCartProductAddAfterObserver implements ObserverInterface private $objectManagement; /** - * @param \Magento\Store\Model\StoreManagerInterface $storeManager - * @param \Magento\Framework\App\RequestInterface $request + * @param \Magento\Store\Model\StoreManagerInterface $storeManager + * @param \Magento\Framework\App\RequestInterface $request * @param \Magento\Framework\Serialize\SerializerInterface $serializer - * @param \Psr\Log\LoggerInterface $logger + * @param \Psr\Log\LoggerInterface $logger */ public function __construct( \Magento\Framework\App\RequestInterface $request, \Magento\Framework\Serialize\SerializerInterface $serializer, \Psr\Log\LoggerInterface $logger - ) - { + ) { $this->request = $request; $this->serializer = $serializer; $this->logger = $logger; @@ -44,7 +43,7 @@ public function __construct( } /** - * @param EventObserver $observer + * @param EventObserver $observer * @return void */ public function execute(EventObserver $observer) @@ -52,7 +51,7 @@ public function execute(EventObserver $observer) /* @var \Magento\Quote\Model\Quote\Item $item */ $item = $observer->getQuoteItem(); $additionalOptions = array(); - if ($additionalOption = $item->getOptionByCode('additional_options')){ + if ($additionalOption = $item->getOptionByCode('additional_options')) { $additionalOptions = $this->serializer->unserialize($additionalOption->getValue()); } @@ -61,8 +60,7 @@ public function execute(EventObserver $observer) $this->logger->info($planId); - if($paymentOption == "subscription" ) - { + if($paymentOption == "subscription" ) { $planData = $this->objectManagement->get('Razorpay\Subscription\Model\Plans') ->getCollection() ->addFieldToSelect("plan_bill_amount", "price") @@ -72,7 +70,7 @@ public function execute(EventObserver $observer) ->getFirstItem() ->getData(); - if(!empty($planData)){ + if(!empty($planData)) { $item->setCustomPrice($planData["price"]); $item->setOriginalCustomPrice($planData["price"]); $item->getProduct()->setIsSuperMode(true); @@ -85,13 +83,14 @@ public function execute(EventObserver $observer) ]; - if(count($additionalOptions) > 0) - { - $item->addOption(array( + if(count($additionalOptions) > 0) { + $item->addOption( + array( 'product_id' => $item->getProductId(), 'code' => 'additional_options', 'value' => $this->serializer->serialize($additionalOptions) - )); + ) + ); } } diff --git a/Observer/OrderPlaceSaveAfterObserver.php b/Observer/OrderPlaceSaveAfterObserver.php index 53c8943..c4693a8 100644 --- a/Observer/OrderPlaceSaveAfterObserver.php +++ b/Observer/OrderPlaceSaveAfterObserver.php @@ -50,15 +50,16 @@ public function execute(Observer $observer) $order = $observer->getOrder(); - /** @var Payment $payment */ + /** + * @var Payment $payment +*/ $payment = $order->getPayment(); $paymentMethod = $payment->getMethodInstance(); $code = $paymentMethod->getCode(); - if($code === SubscriptionPaymentMethod::METHOD_CODE) - { + if($code === SubscriptionPaymentMethod::METHOD_CODE) { $this->updateOrderLinkStatus($payment); } @@ -102,8 +103,7 @@ private function updateOrderLinkStatus(Payment $payment) $orderLink = $orderLinkCollection->getData(); - if (empty($orderLink['entity_id']) === false) - { + if (empty($orderLink['entity_id']) === false) { $orderLinkCollection->setOrderId($order->getEntityId()) ->setOrderPlaced(true) ->save(); diff --git a/Observer/PaymentMethodActiveObserver.php b/Observer/PaymentMethodActiveObserver.php index a0888c9..182c2a0 100644 --- a/Observer/PaymentMethodActiveObserver.php +++ b/Observer/PaymentMethodActiveObserver.php @@ -43,8 +43,7 @@ public function __construct( ProductRepositoryInterface $productRepository, Cart $cart, ManagerInterface $messageManager - ) - { + ) { $this->logger = $logger; $this->productRepository = $productRepository; $this->subscriptionHelper = $subscriptionHelper; @@ -53,7 +52,7 @@ public function __construct( } /** - * @param Observer $observer + * @param Observer $observer * @return void */ public function execute(Observer $observer) @@ -62,7 +61,7 @@ public function execute(Observer $observer) $code = $observer->getEvent()->getMethodInstance()->getCode(); $quote = $this->cart->getQuote(); - if ( $this->cart->getQuote()->getItemsCount() > 1) { + if ($this->cart->getQuote()->getItemsCount() > 1) { $this->disablePaymentMethod($result, SubscriptionPaymentMethod::METHOD_CODE, $code); } else { /* @var \Magento\Quote\Model\Quote $quote */ @@ -88,6 +87,7 @@ public function execute(Observer $observer) /** * Disabling the payment method + * * @param $result * @param $paymentMethod * @param $methodCode @@ -95,7 +95,7 @@ public function execute(Observer $observer) public function disablePaymentMethod($result, $paymentMethod, $methodCode) { $this->logger->info("-------------disabling $paymentMethod ---------------------"); - if( $methodCode == $paymentMethod) { + if($methodCode == $paymentMethod) { $result->setData('is_available', false); } } diff --git a/Observer/RestrictRecurringProductToCartObserver.php b/Observer/RestrictRecurringProductToCartObserver.php index 48146f8..e910944 100644 --- a/Observer/RestrictRecurringProductToCartObserver.php +++ b/Observer/RestrictRecurringProductToCartObserver.php @@ -46,8 +46,7 @@ public function __construct( Product $product, LoggerInterface $logger, Subscription $subscriptionHelper - ) - { + ) { $this->messageManager = $messageManager; $this->cart = $cart; $this->logger = $logger; @@ -82,15 +81,15 @@ public function execute(Observer $observer) } /** - * @param $allCartItems - * @param $cartItemsCount - * @param $validateTo + * @param $allCartItems + * @param $cartItemsCount + * @param $validateTo * @return string */ private function verifyProductInCart($allCartItems, $cartItemsCount, $validateTo): string { $message = ""; - if($this->subscriptionHelper->validateIsASubscriptionProduct($allCartItems, $validateTo)){ + if($this->subscriptionHelper->validateIsASubscriptionProduct($allCartItems, $validateTo)) { $message = "You cannot have regular products and subscriptions product in your shopping cart"; } else if($cartItemsCount >= 1 && $this->paymentType != "oneTime") { $message = "You can only have 1 recurring subscription product in your shopping cart at a time."; diff --git a/Plugin/CsrfValidatorSkip.php b/Plugin/CsrfValidatorSkip.php index 16e6388..e713db1 100644 --- a/Plugin/CsrfValidatorSkip.php +++ b/Plugin/CsrfValidatorSkip.php @@ -5,9 +5,9 @@ class CsrfValidatorSkip { /** * @param \Magento\Framework\App\Request\CsrfValidator $subject - * @param \Closure $proceed - * @param \Magento\Framework\App\RequestInterface $request - * @param \Magento\Framework\App\ActionInterface $action + * @param \Closure $proceed + * @param \Magento\Framework\App\RequestInterface $request + * @param \Magento\Framework\App\ActionInterface $action */ public function aroundValidate( $subject, diff --git a/Setup/UpgradeData.php b/Setup/UpgradeData.php index 45ba08f..d6c5f00 100644 --- a/Setup/UpgradeData.php +++ b/Setup/UpgradeData.php @@ -37,8 +37,8 @@ public function __construct( \Magento\Eav\Model\Entity\TypeFactory $eavTypeFactory, \Magento\Eav\Model\Entity\Attribute\SetFactory $attributeSetFactory, \Magento\Eav\Model\ResourceModel\Entity\Attribute\Group\CollectionFactory $groupCollectionFactory, - EavSetupFactory $eavSetupFactory) - { + EavSetupFactory $eavSetupFactory + ) { $this->eavSetupFactory = $eavSetupFactory; $this->eavTypeFactory = $eavTypeFactory; $this->attributeSetFactory = $attributeSetFactory; @@ -54,7 +54,8 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface } - public function installEntities($setup){ + public function installEntities($setup) + { $groupName = 'Subscriptions by Razorpay'; @@ -95,7 +96,7 @@ public function installEntities($setup){ $eavSetup->addAttribute(Product::ENTITY, $attributeCode, $attribute); } - $this->sortGroup($groupName,11); + $this->sortGroup($groupName, 11); } private function sortGroup($attributeGroupName, $order) diff --git a/Setup/UpgradeSchema.php b/Setup/UpgradeSchema.php index 9965065..bffa8b0 100755 --- a/Setup/UpgradeSchema.php +++ b/Setup/UpgradeSchema.php @@ -10,20 +10,28 @@ use Razorpay\Subscription\Model\ResourceModel\Plans; use Razorpay\Subscription\Model\ResourceModel\Subscriptions; use Razorpay\Subscription\Model\ResourceModel\SubscriptionsOrderMapping; - -class UpgradeSchema implements UpgradeSchemaInterface +/** + * @UpgradeSchema to update the current db with subscription + **/ +class UpgradeSchema implements UpgradeSchemaInterface { - public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context){ + /** + * @upgrade database and create table + **/ + public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context) + { $setup->startSetup(); $this->createPlanTable($setup); $this->createSubscriptionTable($setup); $this->createSubscriptionOrderMappingTable($setup); - $setup->endSetup(); } - - private function createPlanTable($setup){ +/** + * @createPlanTable create plan table + **/ + private function createPlanTable($setup) + { $table = $setup->getConnection()->newTable($setup->getTable(Plans::TABLE_NAME)); $table @@ -76,7 +84,7 @@ private function createPlanTable($setup){ 'comment' => 'Razorpay Plan Description' ] ) - ->addColumn( + ->addColumn( 'plan_type', Table::TYPE_TEXT, 30, @@ -164,17 +172,17 @@ private function createPlanTable($setup){ ) ->addIndex( 'plan_product', - ['plan_id', 'plan_type','magento_product_id','plan_name'], + ['plan_id', 'plan_type', 'magento_product_id', 'plan_name'], [ 'type' => AdapterInterface::INDEX_TYPE_INDEX, ] - ) - ; + ); $setup->getConnection()->createTable($table); - } - +/** + * @createSubscriptionTable - subsription record + **/ private function createSubscriptionTable($setup) { $table = $setup->getConnection()->newTable($setup->getTable(Subscriptions::TABLE_NAME)); @@ -366,32 +374,32 @@ private function createSubscriptionTable($setup) ) ->addIndex( 'subscription_status', - ['subscription_id','status'], + ['subscription_id', 'status'], [ 'type' => AdapterInterface::INDEX_TYPE_INDEX, ] ) ->addIndex( 'product_id', - ['subscription_id','product_id'], + ['subscription_id', 'product_id'], [ 'type' => AdapterInterface::INDEX_TYPE_INDEX, ] ) ->addIndex( 'subscription_user', - ['subscription_id','razorpay_customer_id','magento_user_id'], + ['subscription_id', 'razorpay_customer_id', 'magento_user_id'], [ 'type' => AdapterInterface::INDEX_TYPE_INDEX, ] - ) - ; + ); $setup->getConnection()->createTable($table); - } - - public function createSubscriptionOrderMappingTable($setup) + /** + * @createSubscriptionOrderMappingTable mapping order and subscription + */ + public function createSubscriptionOrderMappingTable($setup) { $table = $setup->getConnection()->newTable($setup->getTable(SubscriptionsOrderMapping::TABLE_NAME)); @@ -481,14 +489,12 @@ public function createSubscriptionOrderMappingTable($setup) ) ->addIndex( 'order_details', - ['is_trial_order','increment_order_id','rzp_payment_id'], + ['is_trial_order', 'increment_order_id', 'rzp_payment_id'], [ 'type' => AdapterInterface::INDEX_TYPE_INDEX, 'nullable' => false, ] - ) - ; + ); $setup->getConnection()->createTable($table); - } } diff --git a/Ui/Component/Listing/Column/Actions.php b/Ui/Component/Listing/Column/Actions.php index 3f4d794..5577217 100644 --- a/Ui/Component/Listing/Column/Actions.php +++ b/Ui/Component/Listing/Column/Actions.php @@ -13,8 +13,11 @@ class Actions extends Column */ private $urlBuilder; - /** Url Path */ + /** + * Url Path +*/ const SUBSCRIPTION_VIEW_URL_PATH = 'subscribed/subscription/view'; + const SUBSCRIPTION_EDIT_URL_PATH = 'subscribed/subscription/edit'; const CANCEL_URL_PATH = 'subscribed/subscription/cancel'; const PAUSE_URL_PATH = 'subscribed/subscription/pause'; const RESUME_URL_PATH = 'subscribed/subscription/resume'; @@ -24,8 +27,8 @@ public function __construct( UiComponentFactory $uiComponentFactory, array $components = array(), UrlInterface $urlBuilder, - array $data = array()) - { + array $data = array() + ) { parent::__construct($context, $uiComponentFactory, $components, $data); $this->urlBuilder = $urlBuilder; } @@ -33,7 +36,7 @@ public function __construct( /** * Prepare Data Source * - * @param array $dataSource + * @param array $dataSource * @return void */ public function prepareDataSource(array $dataSource) @@ -47,6 +50,15 @@ public function prepareDataSource(array $dataSource) 'label' => __('View'), '__disableTmpl' => true, ]; + + if($item['status'] == 'active'){ + $item[$name]['edit'] = [ + 'href' => $this->urlBuilder->getUrl(self::SUBSCRIPTION_EDIT_URL_PATH, ['subscription_id' => strip_tags($item['subscription_id']),'id' => $item['entity_id']]), + 'label' => __('Edit'), + '__disableTmpl' => true, + ]; + } + $item[$name]['pause'] = [ 'href' => $this->urlBuilder->getUrl(self::PAUSE_URL_PATH, ['subscription_id' => strip_tags($item['subscription_id'])]), 'label' => __('Pause'), diff --git a/Ui/Component/Listing/Column/PlanActions.php b/Ui/Component/Listing/Column/PlanActions.php index a26a173..a746bd3 100644 --- a/Ui/Component/Listing/Column/PlanActions.php +++ b/Ui/Component/Listing/Column/PlanActions.php @@ -21,11 +21,11 @@ class PlanActions extends Column protected $urlBuilder; /** - * @param ContextInterface $context + * @param ContextInterface $context * @param UiComponentFactory $uiComponentFactory - * @param UrlInterface $urlBuilder - * @param array $components - * @param array $data + * @param UrlInterface $urlBuilder + * @param array $components + * @param array $data */ public function __construct( ContextInterface $context, @@ -41,7 +41,7 @@ public function __construct( /** * Prepare Data Source * - * @param array $dataSource + * @param array $dataSource * @return array */ public function prepareDataSource(array $dataSource) diff --git a/Ui/Component/Listing/Column/SubscriptionView.php b/Ui/Component/Listing/Column/SubscriptionView.php index 139ae32..ca110f6 100644 --- a/Ui/Component/Listing/Column/SubscriptionView.php +++ b/Ui/Component/Listing/Column/SubscriptionView.php @@ -13,7 +13,9 @@ class SubscriptionView extends Column */ private $urlBuilder; - /** Url Path */ + /** + * Url Path +*/ const SUBSCRIPTION_VIEW_URL_PATH = 'subscribed/subscription/view'; public function __construct( @@ -21,8 +23,8 @@ public function __construct( UiComponentFactory $uiComponentFactory, array $components = array(), UrlInterface $urlBuilder, - array $data = array()) - { + array $data = array() + ) { parent::__construct($context, $uiComponentFactory, $components, $data); $this->urlBuilder = $urlBuilder; } @@ -30,7 +32,7 @@ public function __construct( /** * Prepare Data Source * - * @param array $dataSource + * @param array $dataSource * @return void */ public function prepareDataSource(array $dataSource) diff --git a/Ui/DataProvider/Plan/Collection.php b/Ui/DataProvider/Plan/Collection.php index f20f47a..7408f89 100755 --- a/Ui/DataProvider/Plan/Collection.php +++ b/Ui/DataProvider/Plan/Collection.php @@ -6,6 +6,7 @@ /** * Class Collection + * * @package MageDigest\Grid\Ui\DataProvider\Category\Listing */ class Collection extends SearchResult @@ -18,17 +19,17 @@ class Collection extends SearchResult protected function _initSelect() { - $this->getSelect()->joinLeft( + $this->getSelect()->joinLeft( ['secondTable' => $this->getTable('catalog_product_entity_varchar')], 'main_table.magento_product_id = secondTable.entity_id', ['value'] ); - $this->getSelect()->joinLeft( + $this->getSelect()->joinLeft( ['thirdTable' => $this->getTable('eav_attribute')], 'thirdTable.attribute_id = secondTable.attribute_id', ['attribute_id'] ); - $this->getSelect()->where("thirdTable.attribute_code='name' and secondTable.entity_id=main_table.magento_product_id"); + $this->getSelect()->where("thirdTable.attribute_code='name' and secondTable.entity_id=main_table.magento_product_id"); parent::_initSelect(); $this->addFilterToMap('entity_id', 'main_table.entity_id'); } diff --git a/Ui/DataProvider/Plan/ListingDataProvider.php b/Ui/DataProvider/Plan/ListingDataProvider.php index f99140b..36dfad5 100644 --- a/Ui/DataProvider/Plan/ListingDataProvider.php +++ b/Ui/DataProvider/Plan/ListingDataProvider.php @@ -4,6 +4,7 @@ /** * Class ListingDataProvider + * * @package Razorpay\Subscription\Ui\DataProvider\Reviews */ class ListingDataProvider extends \Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider diff --git a/Ui/DataProvider/Plan/PlanDataProvider.php b/Ui/DataProvider/Plan/PlanDataProvider.php new file mode 100644 index 0000000..7b3b745 --- /dev/null +++ b/Ui/DataProvider/Plan/PlanDataProvider.php @@ -0,0 +1,50 @@ +collection = $planCollectionFactory->create(); + parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data); + } + + /** + * Get data + * + * @return array + */ + public function getData() + { + if (!empty($this->loadedData)) { + return $this->loadedData; + } + + $items = $this->collection->getItems(); + foreach ($items as $page) { + $rec = $page->getData(); + $rec['readonly'] = true; + $this->loadedData[$page->getId()] = $rec; + } + return $this->loadedData; + } +} diff --git a/Ui/DataProvider/Subscriptions/Collection.php b/Ui/DataProvider/Subscriptions/Collection.php index d88d7aa..915d024 100755 --- a/Ui/DataProvider/Subscriptions/Collection.php +++ b/Ui/DataProvider/Subscriptions/Collection.php @@ -6,6 +6,7 @@ /** * Class Collection + * * @package MageDigest\Grid\Ui\DataProvider\Category\Listing */ class Collection extends SearchResult diff --git a/Ui/DataProvider/Subscriptions/ListingDataProvider.php b/Ui/DataProvider/Subscriptions/ListingDataProvider.php index 72711f9..fc11432 100644 --- a/Ui/DataProvider/Subscriptions/ListingDataProvider.php +++ b/Ui/DataProvider/Subscriptions/ListingDataProvider.php @@ -4,6 +4,7 @@ /** * Class ListingDataProvider + * * @package Razorpay\Subscription\Ui\DataProvider\Reviews */ class ListingDataProvider extends \Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider diff --git a/etc/di.xml b/etc/di.xml index d4017af..5d75066 100755 --- a/etc/di.xml +++ b/etc/di.xml @@ -61,6 +61,12 @@ + + + RazorpaySubscriptionLogger + + + @@ -83,7 +89,7 @@ PlanGridFilterPool - + @@ -93,7 +99,7 @@ - + @@ -102,7 +108,7 @@ - + diff --git a/view/adminhtml/layout/subscribed_plan_edit.xml b/view/adminhtml/layout/subscribed_plan_edit.xml index 72cb73e..e363452 100644 --- a/view/adminhtml/layout/subscribed_plan_edit.xml +++ b/view/adminhtml/layout/subscribed_plan_edit.xml @@ -3,7 +3,7 @@ - + - \ No newline at end of file + diff --git a/view/adminhtml/layout/subscribed_subscription_edit.xml b/view/adminhtml/layout/subscribed_subscription_edit.xml index 3e3105e..1e4e2a0 100644 --- a/view/adminhtml/layout/subscribed_subscription_edit.xml +++ b/view/adminhtml/layout/subscribed_subscription_edit.xml @@ -1,2 +1,2 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/view/adminhtml/templates/subscription_order_details_view.phtml b/view/adminhtml/templates/subscription_order_details_view.phtml index afd4097..b462ed8 100644 --- a/view/adminhtml/templates/subscription_order_details_view.phtml +++ b/view/adminhtml/templates/subscription_order_details_view.phtml @@ -6,7 +6,7 @@ $subscriptionDetails = $block->fetchSubscriptionOrderDetails(); ?> - + diff --git a/view/adminhtml/templates/subscription_view.phtml b/view/adminhtml/templates/subscription_view.phtml index 6860e14..f7701d3 100644 --- a/view/adminhtml/templates/subscription_view.phtml +++ b/view/adminhtml/templates/subscription_view.phtml @@ -1,4 +1,6 @@ - + getSubscrib(); @@ -12,19 +14,19 @@ $invoices = $block->getSubscriptionInvoice(); Back + if ($subscriptionInfo['status'] != 'paused') : ?> - + - +