diff --git a/Api/SubscriptionApiInterface.php b/Api/SubscriptionApiInterface.php index d060ce33..1f3586b6 100644 --- a/Api/SubscriptionApiInterface.php +++ b/Api/SubscriptionApiInterface.php @@ -11,14 +11,6 @@ interface SubscriptionApiInterface */ public function list(); - /** - * List product subscription - * - * @param string $customerId - * @return \Pagarme\Core\Recurrence\Interfaces\SubscriptionInterface[] - */ - public function listByCustomerId($customerId); - /** * Cancel subscription * diff --git a/Block/Payment/Info/BaseCardInfo.php b/Block/Payment/Info/BaseCardInfo.php index 2874e3ef..9945f6c3 100644 --- a/Block/Payment/Info/BaseCardInfo.php +++ b/Block/Payment/Info/BaseCardInfo.php @@ -20,6 +20,10 @@ abstract class BaseCardInfo extends Cc public function getTransactionInfo() { $charge = $this->getLastCharge(); + + if (empty($charge) || empty($charge->getLastTransaction())) { + return []; + } if ($charge->getLastTransaction()->getCardData() == null) { return []; } @@ -65,7 +69,7 @@ private function getLastCharge() return current($orderObject->getCharges()); } - + /** * @param mixed $orderService * @param mixed $pagarmeId diff --git a/Concrete/Magento2CoreSetup.php b/Concrete/Magento2CoreSetup.php index eb729e5d..05e78e8f 100644 --- a/Concrete/Magento2CoreSetup.php +++ b/Concrete/Magento2CoreSetup.php @@ -91,6 +91,12 @@ static public function getDatabaseAccessObject() static protected function getPlatformHubAppPublicAppKey() { + $objectManager = ObjectManager::getInstance(); + $config = $objectManager->get('Magento\Framework\App\Config\ScopeConfigInterface'); + $key = $config->getValue('pagarme_pagarme/hub/partner_public_app_key'); + if(!empty($key)) { + return $key; + } return '3470c63b-a233-4be0-9d2a-9ff56e349556'; } diff --git a/Controller/Adminhtml/Invoices/Delete.php b/Controller/Adminhtml/Invoices/Delete.php index c6631c0d..3617507e 100644 --- a/Controller/Adminhtml/Invoices/Delete.php +++ b/Controller/Adminhtml/Invoices/Delete.php @@ -64,7 +64,7 @@ public function execute() $message = $this->messageFactory->create( MessageInterface::TYPE_ERROR, - _("Unable to cancel invoice") + __("Unable to cancel invoice") ); $invoice = $this->invoiceService->cancel($id); @@ -72,7 +72,7 @@ public function execute() if ($invoice['code'] == 200) { $message = $this->messageFactory->create( MessageInterface::TYPE_SUCCESS, - _("Invoice canceled.") + __("Invoice canceled.") ); } diff --git a/Controller/Adminhtml/Plans/Delete.php b/Controller/Adminhtml/Plans/Delete.php index 4e14f799..5f06bae0 100644 --- a/Controller/Adminhtml/Plans/Delete.php +++ b/Controller/Adminhtml/Plans/Delete.php @@ -32,7 +32,7 @@ public function execute() $planService->delete($productId); - $message = $this->messageFactory->create('success', _("Plan deleted.")); + $message = $this->messageFactory->create('success', __("Plan deleted.")); $this->messageManager->addMessage($message); $this->_redirect('pagarme_pagarme/plans/index'); diff --git a/Controller/Adminhtml/Subscriptions/Delete.php b/Controller/Adminhtml/Subscriptions/Delete.php index 23f5368b..ed5e8c97 100644 --- a/Controller/Adminhtml/Subscriptions/Delete.php +++ b/Controller/Adminhtml/Subscriptions/Delete.php @@ -66,7 +66,7 @@ public function execute() $message = $this->messageFactory->create( MessageInterface::TYPE_ERROR, - _("Unable to cancel subscription") + __("Unable to cancel subscription") ); $subscription = $this->subscriptionService->cancel($id); @@ -74,7 +74,7 @@ public function execute() if ($subscription['code'] == 200) { $message = $this->messageFactory->create( MessageInterface::TYPE_SUCCESS, - _("Subscription deleted.") + __("Subscription deleted.") ); } diff --git a/Model/Api/Subscription.php b/Model/Api/Subscription.php index 3212193f..14b86a52 100644 --- a/Model/Api/Subscription.php +++ b/Model/Api/Subscription.php @@ -2,42 +2,25 @@ namespace Pagarme\Pagarme\Model\Api; -use Magento\Framework\Webapi\Rest\Request; -use Pagarme\Core\Kernel\Services\LocalizationService; -use Pagarme\Core\Kernel\Services\MoneyService; +use Magento\Framework\App\Area; +use Magento\Framework\App\State; use Pagarme\Core\Recurrence\Services\SubscriptionService; use Pagarme\Pagarme\Api\SubscriptionApiInterface; use Pagarme\Pagarme\Concrete\Magento2CoreSetup; class Subscription implements SubscriptionApiInterface { - - /** - * @var Request - */ - protected $request; /** * @var SubscriptionService */ protected $subscriptionService; - /** - * @var LocalizationService - */ - protected $i18n; - - /** - * @var MoneyService - */ - protected $moneyService; - - public function __construct(Request $request) + public function __construct(State $state) { - $this->request = $request; - Magento2CoreSetup::bootstrap(); - $this->i18n = new LocalizationService(); - $this->moneyService = new MoneyService(); - $this->subscriptionService = new SubscriptionService(); + if ($state->getAreaCode() === Area::AREA_WEBAPI_REST) { + Magento2CoreSetup::bootstrap(); + $this->subscriptionService = new SubscriptionService(); + } } /** @@ -69,15 +52,4 @@ public function cancel($id) ]; } } - - /** - * List product subscription - * - * @param string $customerId - * @return \Pagarme\Core\Recurrence\Interfaces\SubscriptionInterface[] - */ - public function listByCustomerId($customerId) - { - // TODO: Implement listByCustomerId() method. - } } diff --git a/Model/Notifications.php b/Model/Notifications.php index a55ffbc9..63c536ab 100644 --- a/Model/Notifications.php +++ b/Model/Notifications.php @@ -206,16 +206,6 @@ private function addDashSettingsMessages() $noticesList = [ CoreAccount::ACCOUNT_DISABLED => __('Your account is disabled on Pagar.me Dash. ' . 'Please, contact our support team to enable it.'), - CoreAccount::DOMAIN_EMPTY => sprintf( - __('No domain registered on Pagar.me Dash. Please enter your website\'s domain on the %s ' - . 'to be able to process payment in your store.'), - $this->buildDashLink($linkLabel, $linkAccount) - ), - CoreAccount::DOMAIN_INCORRECT => sprintf( - __('The registered domain is different from the URL of your website. Please correct the ' - . 'domain configured on the %s to be able to process payment in your store.'), - $this->buildDashLink($linkLabel, $linkAccount) - ), CoreAccount::WEBHOOK_INCORRECT => sprintf( __('The URL for receiving webhooks registered in Pagar.me Dash is different from the URL of ' . 'your website. Please, %s to access the Hub and click the Delete > Confirm ' diff --git a/README.md b/README.md index 0565732d..d47fc36e 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,6 @@ See in [releases](https://github.com/pagarme/magento2-module/releases) ## Contributors -| ![robsoned avatar](https://avatars.githubusercontent.com/u/18008565?v=4) | -|-------------------------------------------------------------------------------------- -| [robsoned](https://github.com/robsoned) | \ No newline at end of file +| robsoned avatar | rafaelsiqueira avatar | +|:-:|:-:| +| [robsoned](https://github.com/robsoned) | [rafaelsiqueira](https://github.com/rafaelsiqueira) | diff --git a/Test/Unit/Model/Api/SubscriptionTest.php b/Test/Unit/Model/Api/SubscriptionTest.php new file mode 100644 index 00000000..327fa682 --- /dev/null +++ b/Test/Unit/Model/Api/SubscriptionTest.php @@ -0,0 +1,99 @@ +shouldReceive('bootstrap') + ->andReturnSelf(); + + $subscriptionModel = new SubscriptionModel(); + $subscriptionModel->setId("123"); + $subscriptionModels = [$subscriptionModel]; + + $subscriptionServiceMock->shouldReceive('listAll') + ->andReturn($subscriptionModels); + + $stateMock = Mockery::mock(State::class); + $stateMock->shouldReceive('getAreaCode') + ->andReturn(Area::AREA_WEBAPI_REST); + + $subscription = new Subscription($stateMock); + + $expectedResult = json_decode(json_encode($subscriptionModels), true); + + $result = $subscription->list(); + + $this->assertSame($result, $expectedResult); + } + + public function testCancelShouldReturnSucessArray() + { + $subscriptionServiceMock = Mockery::mock('overload:Pagarme\Core\Recurrence\Services\SubscriptionService'); + $magento2CoreSetupMock = Mockery::mock('alias:Pagarme\Pagarme\Concrete\Magento2CoreSetup'); + $magento2CoreSetupMock->shouldReceive('bootstrap') + ->andReturnSelf(); + + $expectedResult = [ + "message" => 'Subscription canceled with success!', + "code" => 200 + ]; + $subscriptionServiceMock->shouldReceive('cancel') + ->andReturn($expectedResult); + + $stateMock = Mockery::mock(State::class); + $stateMock->shouldReceive('getAreaCode') + ->andReturn(Area::AREA_WEBAPI_REST); + + $subscription = new Subscription($stateMock); + + $id = '123'; + $result = $subscription->cancel($id); + + $this->assertSame($result, $expectedResult); + } + + public function testCancelShouldReturnErrorArray() + { + $subscriptionServiceMock = Mockery::mock('overload:Pagarme\Core\Recurrence\Services\SubscriptionService'); + $magento2CoreSetupMock = Mockery::mock('alias:Pagarme\Pagarme\Concrete\Magento2CoreSetup'); + $magento2CoreSetupMock->shouldReceive('bootstrap') + ->andReturnSelf(); + + $expectedResult = [ + "code" => 400, + "message" => 'Error while canceling subscription', + ]; + + $exception = new Exception('Error while canceling subscription', 400); + $subscriptionServiceMock->shouldReceive('cancel') + ->andThrow($exception); + + $stateMock = Mockery::mock(State::class); + $stateMock->shouldReceive('getAreaCode') + ->andReturn(Area::AREA_WEBAPI_REST); + + $subscription = new Subscription($stateMock); + + $id = '123'; + $result = $subscription->cancel($id); + + $this->assertSame($result, $expectedResult); + } +} diff --git a/composer.json b/composer.json index e3d1715c..12617e6d 100755 --- a/composer.json +++ b/composer.json @@ -1,12 +1,12 @@ { "name": "pagarme/pagarme-magento2-module", "license": "MIT", - "version": "2.6.1", + "version": "2.6.2", "type": "magento2-module", "description": "Magento 2 Module Pagar.me", "require": { "php": ">=7.1", - "pagarme/ecommerce-module-core": "2.7.0" + "pagarme/ecommerce-module-core": "2.7.1" }, "require-dev": { "phpunit/phpunit": "^5 | ^6 | ^7 | ^8 | ^9", diff --git a/etc/adminhtml/system/global.xml b/etc/adminhtml/system/global.xml index 6fc46ead..192231d2 100644 --- a/etc/adminhtml/system/global.xml +++ b/etc/adminhtml/system/global.xml @@ -48,5 +48,8 @@ Magento\Config\Model\Config\Source\Yesno pagarme_pagarme/global/sendmail + + pagarme_pagarme/hub/partner_public_app_key + diff --git a/etc/module.xml b/etc/module.xml index d3454704..12979025 100755 --- a/etc/module.xml +++ b/etc/module.xml @@ -9,7 +9,7 @@ */ --> - + diff --git a/view/frontend/templates/info/card.phtml b/view/frontend/templates/info/card.phtml index 28cb0f32..4381fe2e 100644 --- a/view/frontend/templates/info/card.phtml +++ b/view/frontend/templates/info/card.phtml @@ -2,7 +2,7 @@ /** * @var \Pagarme\Core\Kernel\Aggregates\Transaction $info */ - $info = $this->getTransactionInfo(); + $info = $block->getTransactionInfo(); if(empty($info)) { return; }