Skip to content

Commit

Permalink
Merge pull request vindi#115 from cedran/master
Browse files Browse the repository at this point in the history
fix: ASSINATURAS - ajuste na exibicao dos detalhes da assinatura
  • Loading branch information
cedran authored Aug 19, 2024
2 parents 435d923 + 7f8c777 commit fc2091c
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 9 deletions.
13 changes: 13 additions & 0 deletions Api/Data/SubscriptionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ interface SubscriptionInterface
const PLAN = 'plan';
const NEXT_BILLING_AT = 'next_billing_at';
const BILL_ID = 'bill_id';
const RESPONSE_DATA = 'response_data';

/**
* Get id
Expand Down Expand Up @@ -114,4 +115,16 @@ public function setNextBillingAt($nextBillingAt);

public function getBillId();
public function setBillId($billId);
/**
* Get response_data
* @return string|null
*/
public function getResponseData();

/**
* Set response_data
* @param string $responseData
* @return \Vindi\Payment\Api\Data\SubscriptionInterface
*/
public function setResponseData($responseData);
}
27 changes: 24 additions & 3 deletions Block/Adminhtml/Subscription/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Magento\Framework\Pricing\PriceCurrencyInterface;
use Vindi\Payment\Helper\Api;
use Vindi\Payment\Model\ResourceModel\SubscriptionOrder\CollectionFactory as SubscriptionOrderCollectionFactory;
use Vindi\Payment\Model\SubscriptionFactory;

/**
* Class View
Expand Down Expand Up @@ -44,13 +45,19 @@ class View extends Container
*/
protected $priceHelper;

/**
* @var SubscriptionFactory
*/
private $subscriptionFactory;

/**
* View constructor.
* @param Context $context
* @param Registry $registry
* @param SubscriptionOrderCollectionFactory $subscriptionsOrderCollectionFactory
* @param Api $api
* @param PriceCurrencyInterface $priceHelper
* @param SubscriptionFactory $subscriptionFactory
* @param array $data
*/
public function __construct(
Expand All @@ -59,13 +66,15 @@ public function __construct(
SubscriptionOrderCollectionFactory $subscriptionsOrderCollectionFactory,
Api $api,
PriceCurrencyInterface $priceHelper,
SubscriptionFactory $subscriptionFactory,
array $data = []
) {
parent::__construct($context, $data);
$this->api = $api;
$this->registry = $registry;
$this->subscriptionsOrderCollectionFactory = $subscriptionsOrderCollectionFactory;
$this->priceHelper = $priceHelper;
$this->subscriptionFactory = $subscriptionFactory;
}

/**
Expand Down Expand Up @@ -411,9 +420,21 @@ private function getSubscriptionData()
{
if ($this->subscriptions === null) {
$id = $this->registry->registry('vindi_payment_subscription_id');
$request = $this->api->request('subscriptions/'.$id, 'GET');
if (is_array($request) && array_key_exists('subscription', $request)) {
$this->subscriptions = $request['subscription'];

$subscriptionModel = $this->subscriptionFactory->create()->load($id);

$responseData = $subscriptionModel->getData('response_data');

if ($responseData) {
$this->subscriptions = json_decode($responseData, true);
} else {
$request = $this->api->request('subscriptions/'.$id, 'GET');
if (is_array($request) && array_key_exists('subscription', $request)) {
$this->subscriptions = $request['subscription'];

$subscriptionModel->setData('response_data', json_encode($this->subscriptions));
$subscriptionModel->save();
}
}
}

Expand Down
25 changes: 20 additions & 5 deletions Block/Subscription/Details.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Magento\Payment\Helper\Data as PaymentHelper;
use Vindi\Payment\Model\Config\Source\CardImages as CardImagesSource;
use Vindi\Payment\Model\Config\Source\Subscription\PaymentMethod as SourcePaymentMethod;
use Vindi\Payment\Model\SubscriptionFactory;

/**
* Class Details
Expand All @@ -41,6 +42,7 @@ class Details extends Template
private $paymentHelper;
private $paymentMethod;
private $creditCardTypeSource;
private $subscriptionFactory;

/**
* Details constructor.
Expand All @@ -58,6 +60,7 @@ class Details extends Template
* @param PaymentHelper $paymentHelper
* @param SourcePaymentMethod $paymentMethod
* @param CardImagesSource $creditCardTypeSource
* @param SubscriptionFactory $subscriptionFactory
* @param array $data
*/
public function __construct(
Expand All @@ -75,6 +78,7 @@ public function __construct(
PaymentHelper $paymentHelper,
SourcePaymentMethod $paymentMethod,
CardImagesSource $creditCardTypeSource,
SubscriptionFactory $subscriptionFactory,
array $data = []
) {
parent::__construct($context, $data);
Expand All @@ -91,6 +95,7 @@ public function __construct(
$this->paymentHelper = $paymentHelper;
$this->paymentMethod = $paymentMethod;
$this->creditCardTypeSource = $creditCardTypeSource;
$this->subscriptionFactory = $subscriptionFactory;
}

/**
Expand Down Expand Up @@ -569,11 +574,21 @@ private function getSubscriptionData()
{
if ($this->subscriptionData === null) {
$id = $this->getRequest()->getParam('id');
try {
$request = $this->api->request('subscriptions/' . $id, 'GET');
$this->subscriptionData = $request['subscription'] ?? [];
} catch (\Exception $e) {
$this->_redirect('vindi/subscription/index');

$subscriptionModel = $this->subscriptionFactory->create()->load($id);

$responseData = $subscriptionModel->getData('response_data');

if ($responseData) {
$this->subscriptionData = json_decode($responseData, true);
} else {
$request = $this->api->request('subscriptions/'.$id, 'GET');
if (is_array($request) && array_key_exists('subscription', $request)) {
$this->subscriptionData = $request['subscription'];

$subscriptionModel->setData('response_data', json_encode($this->subscriptionData));
$subscriptionModel->save();
}
}
}

Expand Down
19 changes: 19 additions & 0 deletions Model/Data/Subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,23 @@ public function setBillId($billId)
{
return $this->setData(self::BILL_ID, $billId);
}

/**
* Get response_data
* @return string|null
*/
public function getResponseData()
{
return $this->_get(self::RESPONSE_DATA);
}

/**
* Set response_data
* @param string $responseData
* @return SubscriptionInterface
*/
public function setResponseData($responseData)
{
return $this->setData(self::RESPONSE_DATA, $responseData);
}
}
2 changes: 2 additions & 0 deletions Model/Payment/AbstractMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,8 @@ protected function saveSubscriptionToDatabase(array $subscription, Order $order,
$data['next_billing_at'] = $nextBillingAt->format('Y-m-d H:i:s');
}

$data['response_data'] = json_encode($subscription);

try {
$this->connection->insert($tableName, $data);
} catch (\Exception $e) {
Expand Down
1 change: 1 addition & 0 deletions etc/db_schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<column name="customer_email" length="255" nullable="true" xsi:type="varchar" comment="Customer Email"/>
<column name="next_billing_at" xsi:type="datetime" nullable="true" comment="Next Billing Date" />
<column name="bill_id" nullable="true" xsi:type="int" comment="Bill ID"/>
<column name="response_data" xsi:type="text" nullable="true" comment="Subscription Response Data"/>
</table>
<table name="vindi_plans" resource="default" engine="innodb" comment="Vindi Plans Table">
<column xsi:type="int" name="entity_id" padding="10" unsigned="true" nullable="false" identity="true" comment="Entity ID"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<settings>
<buttons>
<button class="Vindi\Payment\Block\Adminhtml\Subscription\Edit\BackButton" name="back"/>
<button class="Vindi\Payment\Block\Adminhtml\Subscription\Edit\AdvancedEditing" name="advanced_editing"/>
<!-- <button class="Vindi\Payment\Block\Adminhtml\Subscription\Edit\AdvancedEditing" name="advanced_editing"/>-->
<button class="Vindi\Payment\Block\Adminhtml\Subscription\Edit\SaveChangesButton" name="save_and_continue"/>
</buttons>
<namespace>vindi_payment_subscription_form</namespace>
Expand Down

0 comments on commit fc2091c

Please sign in to comment.