diff --git a/Concrete/Magento2PlatformOrderDecorator.php b/Concrete/Magento2PlatformOrderDecorator.php
index 5d2bb217..dfead032 100644
--- a/Concrete/Magento2PlatformOrderDecorator.php
+++ b/Concrete/Magento2PlatformOrderDecorator.php
@@ -41,6 +41,7 @@
use Pagarme\Core\Payment\ValueObjects\CustomerType;
use Pagarme\Core\Payment\ValueObjects\Phone;
use Pagarme\Core\Recurrence\Aggregates\Plan;
+use Pagarme\Core\Recurrence\Aggregates\Repetition;
use Pagarme\Core\Recurrence\Services\RecurrenceService;
use Pagarme\Pagarme\Helper\BuildChargeAddtionalInformationHelper;
use Pagarme\Pagarme\Helper\RecurrenceProductHelper;
@@ -55,6 +56,7 @@
use Pagarme\Core\Kernel\ValueObjects\TransactionType;
use Magento\Quote\Model\Quote;
use Pagarme\Pagarme\Helper\Marketplace\WebkulHelper;
+use Pagarme\Pagarme\Model\PagarmeConfigProvider;
class Magento2PlatformOrderDecorator extends AbstractPlatformOrderDecorator
{
@@ -72,12 +74,21 @@ class Magento2PlatformOrderDecorator extends AbstractPlatformOrderDecorator
* @var OrderService
*/
private $orderService;
+ /**
+ * @var PagarmeConfigProvider
+ */
+ private $config;
+ /**
+ * @var MoneyService
+ */
+ private $moneyService;
public function __construct()
{
$this->i18n = new LocalizationService();
$objectManager = ObjectManager::getInstance();
-
+ $this->moneyService = new MoneyService();
+ $this->config = $objectManager->get('Pagarme\Pagarme\Model\PagarmeConfigProvider');
$this->orderFactory = $objectManager->get('Magento\Sales\Model\Order');
$this->orderService = new OrderService();
parent::__construct();
@@ -624,9 +635,9 @@ private function getGuestCustomer($quote)
/** @return Item[] */
public function getItemCollection()
{
- $moneyService = new MoneyService();
$quote = $this->getQuote();
$itemCollection = $quote->getItemsCollection();
+ $hasSubscriptionItem = false;
$items = [];
foreach ($itemCollection as $quoteItem) {
//adjusting price.
@@ -649,7 +660,7 @@ public function getItemCollection()
$item = new Item;
$item->setAmount(
- $moneyService->floatToCents($price)
+ $this->moneyService->floatToCents($price)
);
if ($quoteItem->getProductId()) {
@@ -663,18 +674,53 @@ public function getItemCollection()
);
$item->setName($quoteItem->getName());
-
- $helper = new RecurrenceProductHelper();
- $selectedRepetition = $helper->getSelectedRepetition($quoteItem);
- $item->setSelectedOption($selectedRepetition);
-
- $this->setRecurrenceInfo($item, $quoteItem);
-
+ if ($this->getRecurrenceService()->getRecurrenceProductByProductId($quoteItem->getProductId())) {
+ $hasSubscriptionItem = true;
+ $helper = new RecurrenceProductHelper();
+ $selectedRepetition = $helper->getSelectedRepetition($quoteItem);
+ $item->setSelectedOption($selectedRepetition);
+ $this->setRecurrenceInfo($item, $quoteItem);
+ }
$items[] = $item;
}
+
+ if($hasSubscriptionItem) {
+ if($this->getPlatformOrder()->getShippingAmount() && $this->config->canAddShippingInItemsOnRecurrence()) {
+ $items[] = $this->addCustomItem(
+ $this->getPlatformOrder()->getShippingAmount(),
+ $this->getPlatformOrder()->getShippingDescription(),
+ $selectedRepetition
+ );
+ }
+ if($this->getPlatformOrder()->getBaseTaxAmount() && $this->config->canAddTaxInItemsOnRecurrence()) {
+ $items[] = $this->addCustomItem(
+ $this->getPlatformOrder()->getBaseTaxAmount(),
+ __("Taxs"),
+ $selectedRepetition
+ );
+ }
+ }
return $items;
}
+ private function addCustomItem($value, $name, $selectedRepetition)
+ {
+ $product = new Item();
+ $product->setName($name);
+ $product->setDescription($name);
+ $product->setQuantity(1);
+ $product->setCode(0);
+ $product->setSelectedOption($this->mountRepetition($value, $selectedRepetition));
+ $product->setType("subscription");
+ $product->setAmount($this->moneyService->floatToCents($value));
+ return $product;
+ }
+ private function mountRepetition($value, $selectedRepetition)
+ {
+ $selectedRepetition->setRecurrencePrice($this->moneyService->floatToCents($value));
+ return $selectedRepetition;
+ }
+
public function setRecurrenceInfo($item, $quoteItem)
{
$recurrenceService = $this->getRecurrenceService();
@@ -809,7 +855,6 @@ private function extractPaymentDataFromPagarmeDebit(
private function extractBasePaymentData($additionalInformation)
{
- $moneyService = new MoneyService();
$identifier = null;
$customerId = null;
$brand = null;
@@ -874,7 +919,6 @@ private function extractBasePaymentData($additionalInformation)
private function extractPaymentDataFromPagarmeTwoCreditCard($additionalInformation, &$paymentData, $payment)
{
- $moneyService = new MoneyService();
$indexes = ['first', 'second'];
foreach ($indexes as $index) {
$identifier = null;
@@ -918,11 +962,11 @@ private function extractPaymentDataFromPagarmeTwoCreditCard($additionalInformati
$index
);
- $amount = $moneyService->removeSeparators(
+ $amount = $this->moneyService->removeSeparators(
$additionalInformation["cc_{$index}_card_amount"]
);
- $newPaymentData->amount = $moneyService->floatToCents($amount / 100);
+ $newPaymentData->amount = $this->moneyService->floatToCents($amount / 100);
$newPaymentData->saveOnSuccess =
isset($additionalInformation["cc_savecard_{$index}"]) &&
$additionalInformation["cc_savecard_{$index}"] === '1';
@@ -988,7 +1032,6 @@ private function extractPaymentDataFromPagarmeBilletCreditcard(
&$paymentData,
$payment
) {
- $moneyService = new MoneyService();
$identifier = null;
$customerId = null;
@@ -1034,7 +1077,7 @@ private function extractPaymentDataFromPagarmeBilletCreditcard(
"",
$additionalInformation["cc_cc_amount"] ?? ''
);
- $newPaymentData->amount = $moneyService->floatToCents($amount / 100);
+ $newPaymentData->amount = $this->moneyService->floatToCents($amount / 100);
$creditCardDataIndex = AbstractCreditCardPayment::getBaseCode();
if (!isset($paymentData[$creditCardDataIndex])) {
@@ -1059,7 +1102,7 @@ private function extractPaymentDataFromPagarmeBilletCreditcard(
);
$newPaymentData->amount =
- $moneyService->floatToCents($amount / 100);
+ $this->moneyService->floatToCents($amount / 100);
$boletoDataIndex = BoletoPayment::getBaseCode();
if (!isset($paymentData[$boletoDataIndex])) {
@@ -1079,10 +1122,9 @@ private function extractPaymentDataFromPagarmeBillet(
&$paymentData,
$payment
) {
- $moneyService = new MoneyService();
$newPaymentData = new \stdClass();
$newPaymentData->amount =
- $moneyService->floatToCents($this->platformOrder->getGrandTotal());
+ $this->moneyService->floatToCents($this->platformOrder->getGrandTotal());
$boletoDataIndex = BoletoPayment::getBaseCode();
if (!isset($paymentData[$boletoDataIndex])) {
@@ -1104,10 +1146,9 @@ private function extractPaymentDataFromPagarmePix(
&$paymentData,
$payment
) {
- $moneyService = new MoneyService();
$newPaymentData = new \stdClass();
$newPaymentData->amount =
- $moneyService->floatToCents($this->platformOrder->getGrandTotal());
+ $this->moneyService->floatToCents($this->platformOrder->getGrandTotal());
$pixDataIndex = PixPayment::getBaseCode();
if (!isset($paymentData[$pixDataIndex])) {
@@ -1126,7 +1167,6 @@ private function extractPaymentDataFromPagarmePix(
public function getShipping()
{
- $moneyService = new MoneyService();
/** @var Shipping $shipping */
$shipping = null;
$quote = $this->getQuote();
@@ -1141,7 +1181,7 @@ public function getShipping()
$shipping = new Shipping();
$shipping->setAmount(
- $moneyService->floatToCents($platformShipping->getShippingAmount())
+ $this->moneyService->floatToCents($platformShipping->getShippingAmount())
);
$shipping->setDescription($platformShipping->getShippingDescription());
$shipping->setRecipientName($platformShipping->getName());
diff --git a/Model/PagarmeConfigProvider.php b/Model/PagarmeConfigProvider.php
index 63bab8f7..7fba0886 100644
--- a/Model/PagarmeConfigProvider.php
+++ b/Model/PagarmeConfigProvider.php
@@ -18,7 +18,9 @@ class PagarmeConfigProvider implements ConfigProviderInterface
/**
* Contains if the module is active or not
*/
- const XML_PATH_IS_GATEWAY_INTEGRATION_TYPE = 'pagarme_pagarme/global/is_gateway_integration_type';
+ const XML_PATH_IS_GATEWAY_INTEGRATION_TYPE = 'pagarme_pagarme/global/is_gateway_integration_type';
+ const XML_PATH_RECURRENCE_ADD_SHIPPING_IN_ITEMS = 'pagarme_pagarme/recurrence/add_shipping_in_items';
+ const XML_PATH_RECURRENCE_ADD_TAX_IN_ITEMS = 'pagarme_pagarme/recurrence/add_tax_in_items';
const XML_PATH_IS_ENABLE_SAVED_CARDS = 'payment/pagarme_creditcard/enabled_saved_cards';
const XML_PATH_SOFT_DESCRIPTION = 'payment/pagarme_creditcard/soft_description';
const XML_PATH_MAX_INSTALLMENT = 'payment/pagarme_creditcard/installments_number';
@@ -93,6 +95,21 @@ public function isGatewayIntegrationType()
);
}
+ public function canAddShippingInItemsOnRecurrence()
+ {
+ return $this->scopeConfig->getValue(
+ self::XML_PATH_RECURRENCE_ADD_SHIPPING_IN_ITEMS,
+ ScopeInterface::SCOPE_STORE
+ ) ?? false;
+ }
+ public function canAddTaxInItemsOnRecurrence()
+ {
+ return $this->scopeConfig->getValue(
+ self::XML_PATH_RECURRENCE_ADD_TAX_IN_ITEMS,
+ ScopeInterface::SCOPE_STORE
+ ) ?? false;
+ }
+
public function validateSoftDescription()
{
$isGatewayIntegrationType = $this->isGatewayIntegrationType();
diff --git a/etc/adminhtml/system/marketplace.xml b/etc/adminhtml/system/marketplace.xml
index 7704c321..7eaba6fe 100644
--- a/etc/adminhtml/system/marketplace.xml
+++ b/etc/adminhtml/system/marketplace.xml
@@ -96,8 +96,5 @@
1
-
- 1
-
diff --git a/etc/adminhtml/system/recurrence.xml b/etc/adminhtml/system/recurrence.xml
index 92b1eaa5..8aca4bf1 100644
--- a/etc/adminhtml/system/recurrence.xml
+++ b/etc/adminhtml/system/recurrence.xml
@@ -2,7 +2,7 @@
-
+
@@ -14,6 +14,9 @@
Magento\Config\Model\Config\Source\Yesno
pagarme_pagarme/recurrence/show_recurrence_currency_widget
+
+ 1
+
@@ -21,11 +24,17 @@
Allow to purchase recurrence products with simple products on the same shopping cart
Magento\Config\Model\Config\Source\Yesno
pagarme_pagarme/recurrence/purchase_recurrence_product_with_normal_product
+
+ 1
+
pagarme_pagarme/recurrence/conflict_recurrence_product_with_normal_product
+
+ 1
+
@@ -33,11 +42,17 @@
Allow to purchase more than one recurrence product on the same shopping cart
Magento\Config\Model\Config\Source\Yesno
pagarme_pagarme/recurrence/purchase_recurrence_product_with_recurrence_product
+
+ 1
+
pagarme_pagarme/recurrence/conflict_recurrence_product_with_recurrence_product
+
+ 1
+
@@ -45,9 +60,27 @@
With this option enabled, the module will decrease product stock with each recurrence cycle
Magento\Config\Model\Config\Source\Yesno
pagarme_pagarme/recurrence/decrease_stock
+
+ 1
+
+
+
+
+
+ Magento\Config\Model\Config\Source\Yesno
+ pagarme_pagarme/recurrence/add_shipping_in_items
+
+ 1
+
+
+
+
+
+ Magento\Config\Model\Config\Source\Yesno
+ pagarme_pagarme/recurrence/add_tax_in_items
+
+ 1
+
-
- 1
-
diff --git a/i18n/pt_BR.csv b/i18n/pt_BR.csv
index ff0d0ce0..bae4d001 100644
--- a/i18n/pt_BR.csv
+++ b/i18n/pt_BR.csv
@@ -15,7 +15,7 @@
"Multi-means Double Credit Card","Multimeios Dois Cartões de Crédito"
"Multi-means Credit Card and Boleto","Multimeios Cartão de Crédito e Boleto"
"Debit Card","Cartão de Débito"
-"Recurrence Settings (Beta)","Configurações de Recorrência (Beta)"
+"Recurrence Settings","Configurações de Recorrência"
"Show Recurrence Currency Widget","Mostrar Widget de Moeda de Recorrência"
"Conflict checkout message","Mensagem de Conflito do Checkout"
"Print Billet","Imprimir Boleto"
@@ -496,3 +496,6 @@
"Please, enter valid Name on Card","Por favor, digite um Nome no Cartão válido"
"Please, enter valid Expiration Date","Por favor, digite um Data de Validade válida"
"The cvv field must be a minimum length of 3 and a maximum length of 4.","O campo de cvv deve ter um tamanho mínimo de 3 e um tamanho máximo de 4."
+"Add shipping values in items","Realizar a cobrança do frete"
+"Add tax values in items","Realizar a cobrança das taxas"
+"Taxs","Taxas"