Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 2.6.2 #377

Merged
merged 14 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions Api/SubscriptionApiInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
6 changes: 5 additions & 1 deletion Block/Payment/Info/BaseCardInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [];
}
Expand Down Expand Up @@ -65,7 +69,7 @@ private function getLastCharge()

return current($orderObject->getCharges());
}

/**
* @param mixed $orderService
* @param mixed $pagarmeId
Expand Down
6 changes: 6 additions & 0 deletions Concrete/Magento2CoreSetup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}

Expand Down
4 changes: 2 additions & 2 deletions Controller/Adminhtml/Invoices/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ public function execute()

$message = $this->messageFactory->create(
MessageInterface::TYPE_ERROR,
_("Unable to cancel invoice")
__("Unable to cancel invoice")
);

$invoice = $this->invoiceService->cancel($id);

if ($invoice['code'] == 200) {
$message = $this->messageFactory->create(
MessageInterface::TYPE_SUCCESS,
_("Invoice canceled.")
__("Invoice canceled.")
);
}

Expand Down
2 changes: 1 addition & 1 deletion Controller/Adminhtml/Plans/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
4 changes: 2 additions & 2 deletions Controller/Adminhtml/Subscriptions/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ public function execute()

$message = $this->messageFactory->create(
MessageInterface::TYPE_ERROR,
_("Unable to cancel subscription")
__("Unable to cancel subscription")
);

$subscription = $this->subscriptionService->cancel($id);

if ($subscription['code'] == 200) {
$message = $this->messageFactory->create(
MessageInterface::TYPE_SUCCESS,
_("Subscription deleted.")
__("Subscription deleted.")
);
}

Expand Down
42 changes: 7 additions & 35 deletions Model/Api/Subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

/**
Expand Down Expand Up @@ -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.
}
}
10 changes: 0 additions & 10 deletions Model/Notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,16 +206,6 @@ private function addDashSettingsMessages()
$noticesList = [
CoreAccount::ACCOUNT_DISABLED => __('Your account is <b>disabled</b> on Pagar.me Dash. '
. 'Please, contact our support team to enable it.'),
CoreAccount::DOMAIN_EMPTY => sprintf(
__('No <b>domain</b> registered on Pagar.me Dash. Please enter your website\'s domain on the <b>%s</b> '
. 'to be able to process payment in your store.'),
$this->buildDashLink($linkLabel, $linkAccount)
),
CoreAccount::DOMAIN_INCORRECT => sprintf(
__('The registered <b>domain</b> is different from the URL of your website. Please correct the '
. 'domain configured on the <b>%s</b> to be able to process payment in your store.'),
$this->buildDashLink($linkLabel, $linkAccount)
),
CoreAccount::WEBHOOK_INCORRECT => sprintf(
__('The URL for receiving <b>webhooks</b> registered in Pagar.me Dash is different from the URL of '
. 'your website. Please, <b>%s</b> to access the Hub and click the Delete > Confirm '
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) |
| <img src="https://avatars.githubusercontent.com/u/18008565" alt="robsoned avatar" width="120"/> | <img src="https://avatars.githubusercontent.com/u/1132274" alt="rafaelsiqueira avatar" width="120"/> |
|:-:|:-:|
| [robsoned](https://github.com/robsoned) | [rafaelsiqueira](https://github.com/rafaelsiqueira) |
99 changes: 99 additions & 0 deletions Test/Unit/Model/Api/SubscriptionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php

namespace Pagarme\Pagarme\Test\Unit\Model\Api;

use Exception;
use Magento\Framework\App\Area;
use Magento\Framework\App\State;
use Mockery;
use Pagarme\Pagarme\Test\Unit\BaseTest;
use Pagarme\Pagarme\Model\Api\Subscription;
use Pagarme\Core\Recurrence\Aggregates\Subscription as SubscriptionModel;

/**
* @runTestsInSeparateProcesses
* @preserveGlobalState disabled
*/
class SubscriptionTest extends BaseTest
{
public function testListShouldReturnAllSubscriptions()
{
$subscriptionServiceMock = Mockery::mock('overload:Pagarme\Core\Recurrence\Services\SubscriptionService');
$magento2CoreSetupMock = Mockery::mock('alias:Pagarme\Pagarme\Concrete\Magento2CoreSetup');
$magento2CoreSetupMock->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);
}
}
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
3 changes: 3 additions & 0 deletions etc/adminhtml/system/global.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,8 @@
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<config_path>pagarme_pagarme/global/sendmail</config_path>
</field>
<field id="partner_public_app_key" type="string">
<config_path>pagarme_pagarme/hub/partner_public_app_key</config_path>
</field>
</group>
</include>
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Pagarme_Pagarme" setup_version="2.6.1">
<module name="Pagarme_Pagarme" setup_version="2.6.2">
<sequence>
<module name="Magento_Sales" />
<module name="Magento_Payment" />
Expand Down
2 changes: 1 addition & 1 deletion view/frontend/templates/info/card.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* @var \Pagarme\Core\Kernel\Aggregates\Transaction $info
*/
$info = $this->getTransactionInfo();
$info = $block->getTransactionInfo();
if(empty($info)) {
return;
}
Expand Down
Loading