Skip to content

Commit

Permalink
Release 2.4.0 (#141)
Browse files Browse the repository at this point in the history
Release 2.4.0
  • Loading branch information
RafaMelazzo authored Jan 29, 2024
2 parents d741193 + 4c37894 commit 83dddf8
Show file tree
Hide file tree
Showing 20 changed files with 494 additions and 65 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "pagarme/ecommerce-module-core",
"description": "Core component for Pagar.me e-commerce platform modules.",
"license": "MIT",
"version": "2.3.1",
"version": "2.4.0",
"authors": [
{
"name":"Open Source Team"
Expand All @@ -12,7 +12,7 @@
"require": {
"php": ">=7.1",
"monolog/monolog": "<3",
"pagarme/pagarmecoreapi": "v5.6.3",
"pagarme/pagarmecoreapi": "v5.6.4",
"ext-json": "*"
},
"require-dev": {
Expand Down
21 changes: 21 additions & 0 deletions src/Kernel/Aggregates/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ final class Configuration extends AbstractEntity
/** @var AddressAttributes */
private $addressAttributes;

/** @var bool */
private $allowNoAddress;

/** @var string */
private $cardStatementDescriptor;

Expand Down Expand Up @@ -178,6 +181,7 @@ final class Configuration extends AbstractEntity

public function __construct()
{
$this->allowNoAddress = false;
$this->saveCards = false;
$this->saveVoucherCards = false;
$this->multiBuyer = false;
Expand Down Expand Up @@ -641,6 +645,22 @@ protected function getAddressAttributes()
return $this->addressAttributes;
}

/**
* @return bool
*/
protected function getAllowNoAddress()
{
return $this->allowNoAddress;
}

/**
* @param bool $allowNoAddress
*/
public function setAllowNoAddress($allowNoAddress)
{
$this->allowNoAddress = $allowNoAddress;
}

/**
* @param AddressAttributes $addressAttributes
*/
Expand Down Expand Up @@ -804,6 +824,7 @@ public function jsonSerialize()
"merchantId" => $this->getMerchantId(),
"accountId" => $this->getAccountId(),
"addressAttributes" => $this->getAddressAttributes(),
"allowNoAddress" => $this->getAllowNoAddress(),
"keys" => $this->keys,
"cardOperation" => $this->cardOperation,
"installmentsEnabled" => $this->isInstallmentsEnabled(),
Expand Down
32 changes: 19 additions & 13 deletions src/Kernel/Factories/ConfigurationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function createFromJsonData($json)
$config->setBoletoCreditCardEnabled($data->boletoCreditCardEnabled);
$config->setTwoCreditCardsEnabled($data->twoCreditCardsEnabled);

if (empty($data->createOrder)){
if (empty($data->createOrder)) {
$data->createOrder = false;
}
$config->setCreateOrderEnabled($data->createOrder);
Expand Down Expand Up @@ -141,7 +141,7 @@ public function createFromJsonData($json)
$config->setHubEnvironment($data->hubEnvironment);
}

if (!empty($data->keys) ) {
if (!empty($data->keys)) {
if (!isset($data->publicKey)) {
$index = Configuration::KEY_PUBLIC;
$data->publicKey = $data->keys->$index;
Expand Down Expand Up @@ -188,7 +188,7 @@ public function createFromJsonData($json)
$config->setBoletoBankCode($data->boletoBankCode);
}
if (!empty($data->boletoDueDays)) {
$config->setBoletoDueDays((int) $data->boletoDueDays);
$config->setBoletoDueDays((int)$data->boletoDueDays);
}

if (!empty($data->saveCards)) {
Expand All @@ -215,7 +215,7 @@ public function createFromJsonData($json)
if (!empty($data->voucherConfig)) {
$config->setVoucherConfig(
(new VoucherConfigFactory)
->createFromDbData($data->voucherConfig)
->createFromDbData($data->voucherConfig)
);
}

Expand All @@ -232,6 +232,10 @@ public function createFromJsonData($json)
);
}

if (!empty($data->allowNoAddress)) {
$config->setAllowNoAddress($data->allowNoAddress);
}

if (!empty($data->marketplaceConfig)) {
$config->setMarketplaceConfig(
(new MarketplaceConfigFactory())
Expand All @@ -242,7 +246,7 @@ public function createFromJsonData($json)
return $config;
}

private function createCardConfigs($data,Configuration $config)
private function createCardConfigs($data, Configuration $config)
{
try {
foreach ($data->cardConfigs as $cardConfig) {
Expand All @@ -259,16 +263,18 @@ private function createCardConfigs($data,Configuration $config)
)
);
}
} catch (Exception $e) {}
} catch (Exception $e) {

}
}

private function createPublicKey($key)
{
try {
return new TestPublicKey($key);
} catch(\Exception $e) {
} catch (\Exception $e) {

} catch(\Throwable $e) {
} catch (\Throwable $e) {

}

Expand All @@ -279,17 +285,17 @@ private function createSecretKey($key)
{
try {
return new TestSecretKey($key);
} catch(\Exception $e) {
} catch (\Exception $e) {

} catch(\Throwable $e) {
} catch (\Throwable $e) {

}

try {
return new SecretKey($key);
} catch(\Exception $e) {
} catch (\Exception $e) {

} catch(\Throwable $e) {
} catch (\Throwable $e) {

}

Expand All @@ -298,7 +304,7 @@ private function createSecretKey($key)

/**
*
* @param array $dbData
* @param array $dbData
* @return AbstractEntity
*/
public function createFromDbData($dbData)
Expand Down
8 changes: 4 additions & 4 deletions src/Kernel/Log/BlurData.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ private function blurStringSensitiveData($value, $delimiter)
if (empty($value)) {
return '';
}
$displayed = substr($value, 0, $delimiter);
$blur = str_repeat("*", strlen($value) - $delimiter);
$displayed = mb_substr($value, 0, $delimiter);
$blur = str_repeat("*", mb_strlen($value) - $delimiter);
return $displayed . $blur;
}

Expand All @@ -47,8 +47,8 @@ private function blurStringSensitiveData($value, $delimiter)
*/
private function blurEmailSensitiveData($string)
{
$displayed = substr($string, 0, 3);
$final = substr($string, strpos($string, "@"));
$displayed = mb_substr($string, 0, 3);
$final = mb_substr($string, mb_strpos($string, "@"));
$result = "$displayed***$final";
return $result;
}
Expand Down
1 change: 1 addition & 0 deletions src/Kernel/Services/LocalizationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ final class LocalizationService
*
* @param mixed Variable num of params.
*/
// phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.NeedsInspection
public function getDashboard($string)
{
$numArgs = func_num_args();
Expand Down
6 changes: 4 additions & 2 deletions src/Kernel/Services/LogService.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function exception(\Exception $exception)
$logObject = $this->prepareObject($exception);
$code = ' | Exception code: ' . $exception->getCode();
$this->monolog->error($exception->getMessage() . $code, $logObject);

} catch (\Throwable $th) {
//throw $th;
}
Expand Down Expand Up @@ -187,7 +187,9 @@ private function blurSensitiveData($logObject)
}
}
return $logObject;
} catch (\Exception $e) {}
} catch (\Exception $e) {
$this->exception($e);
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Kernel/Services/OrderLogService.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function orderInfo($orderCode, $message, $sourceObject = null)
$orderMessage = "Order #$orderCode : $message";
parent::info($orderMessage, $sourceObject);
} catch (\Throwable $throwable) {

$this->orderException($throwable, $orderCode);
}
}

Expand Down
35 changes: 10 additions & 25 deletions src/Kernel/Services/OrderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,20 +243,18 @@ public function cancelAtPagarmeByPlatformOrder(PlatformOrderInterface $platformO
public function createOrderAtPagarme(PlatformOrderInterface $platformOrder)
{
try {
$orderInfo = $this->getOrderInfo($platformOrder);

$this->logService->orderInfo(
$platformOrder->getCode(),
'Creating order.',
$orderInfo
);

//set pending
$platformOrder->setState(OrderState::stateNew());
$platformOrder->setStatus(OrderStatus::pending());

//build PaymentOrder based on platformOrder
$paymentOrder = $this->extractPaymentOrderFromPlatformOrder($platformOrder);
$this->logService->orderInfo(
$platformOrder->getCode(),
'Creating order.',
$paymentOrder
);

$i18n = new LocalizationService();

Expand All @@ -270,13 +268,13 @@ public function createOrderAtPagarme(PlatformOrderInterface $platformOrder)
$this->logService->orderInfo(
$platformOrder->getCode(),
"Can't create order. - Force Create Order: {$forceCreateOrder} | Order or charge status failed",
$orderInfo
$paymentOrder
);

$charges = $this->createChargesFromResponse($response);
$errorMessages = $this->cancelChargesAtPagarme($charges);

$this->addChargeMessagesToLog($platformOrder, $orderInfo, $errorMessages);
$this->addChargeMessagesToLog($platformOrder, $paymentOrder, $errorMessages);

$this->persistListChargeFailed($response);

Expand Down Expand Up @@ -312,7 +310,7 @@ public function createOrderAtPagarme(PlatformOrderInterface $platformOrder)
$this->logService->orderInfo(
$platformOrder->getCode(),
"Can't create order. - Force Create Order: {$forceCreateOrder} | Order or charge status failed",
$orderInfo
$paymentOrder
);
$message = $i18n->getDashboard(
"Can't create payment. " .
Expand All @@ -326,7 +324,7 @@ public function createOrderAtPagarme(PlatformOrderInterface $platformOrder)
$this->logService->orderInfo(
$platformOrder->getCode(),
$e->getMessage(),
$orderInfo
$paymentOrder
);
$exceptionHandler = new ErrorExceptionHandler();
$paymentOrder = new PaymentOrder();
Expand Down Expand Up @@ -378,8 +376,6 @@ public function extractPaymentOrderFromPlatformOrder(
$order->addPayment($payment);
}

$orderInfo = $this->getOrderInfo($platformOrder);

/*
This block was commented out because this validation is still problematic in the woocommerce module.
TODO: we will need to make the module work with this code block.
Expand All @@ -404,7 +400,7 @@ public function extractPaymentOrderFromPlatformOrder(
$order->setCode($platformOrder->getCode());

$shipping = $platformOrder->getShipping();
if (!$shipping && $shipping !== null) {
if (!empty($shipping) && !empty($shipping->getAmount())) {
$order->setShipping($shipping);
}

Expand All @@ -416,17 +412,6 @@ public function extractPaymentOrderFromPlatformOrder(
return $order;
}

/**
* @param PlatformOrderInterface $platformOrder
* @return \stdClass
*/
public function getOrderInfo(PlatformOrderInterface $platformOrder)
{
$orderInfo = new \stdClass();
$orderInfo->grandTotal = $platformOrder->getGrandTotal();
return $orderInfo;
}

private function responseHasNoChargesOrFailed($response)
{
return !isset($response['status']) ||
Expand Down
7 changes: 5 additions & 2 deletions src/Middle/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@
*/
abstract class Client
{
const BASE_URI = 'https://hubapi.pagar.me/';
const DEFAULT_RESOURCE = 'core/v1';

public $client;

abstract public function getHubToken();
public function __construct()
public function __construct($resource = self::DEFAULT_RESOURCE)
{
Configuration::$basicAuthPassword = '';
Configuration::$BASEURI = 'https://hubapi.pagar.me/core/v1';
Configuration::$BASEURI = self::BASE_URI . $resource;
$this->client = $this->services();
}
private function auth()
Expand Down
28 changes: 28 additions & 0 deletions src/Middle/Proxy/TdsTokenProxy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Pagarme\Core\Middle\Proxy;

use Pagarme\Core\Middle\Client;

class TdsTokenProxy
{

private $client;

/**
* @param Client $auth
*/
public function __construct(Client $auth)
{
$this->client = $auth->services();
}

public function getTdsToken($environment, $accountId)
{
return $this->client->getTdsToken()->getToken(
$environment,
$accountId
);
}

}
2 changes: 1 addition & 1 deletion src/Payment/Aggregates/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public function getAddress()
/**
* @param Address $address
*/
public function setAddress(Address $address)
public function setAddress(?Address $address)
{
$this->address = $address;
}
Expand Down
Loading

0 comments on commit 83dddf8

Please sign in to comment.