Skip to content

Commit

Permalink
Merge pull request #55 from pagarme/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
mauriciohaygert authored Oct 21, 2022
2 parents 3f6e5a2 + 990bd79 commit 759bf14
Show file tree
Hide file tree
Showing 17 changed files with 297 additions and 35 deletions.
2 changes: 1 addition & 1 deletion 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": "1.1.3",
"version": "1.1.4",
"authors": [
{
"name":"Open Source Team"
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 @@ -121,6 +121,9 @@ final class Configuration extends AbstractEntity
/** @var bool */
private $saveCards;

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

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

Expand Down Expand Up @@ -160,6 +163,7 @@ final class Configuration extends AbstractEntity
public function __construct()
{
$this->saveCards = false;
$this->saveVoucherCards = false;
$this->multiBuyer = false;
$this->cardConfigs = [];
$this->methodsInherited = [];
Expand Down Expand Up @@ -653,6 +657,22 @@ public function setSaveCards($saveCards)
$this->saveCards = $saveCards;
}

/**
* @return bool
*/
public function isSaveVoucherCards()
{
return $this->saveVoucherCards;
}

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

/**
* @return bool
*/
Expand Down Expand Up @@ -722,6 +742,7 @@ public function jsonSerialize()
"boletoEnabled" => $this->boletoEnabled,
"creditCardEnabled" => $this->creditCardEnabled,
"saveCards" => $this->isSaveCards(),
"saveVoucherCards" => $this->isSaveVoucherCards(),
"multiBuyer" => $this->isMultiBuyer(),
"twoCreditCardsEnabled" => $this->twoCreditCardsEnabled,
"boletoCreditCardEnabled" => $this->boletoCreditCardEnabled,
Expand Down
6 changes: 5 additions & 1 deletion src/Kernel/Factories/ConfigurationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public function createFromPostData($postData)
$cardConfig['installments_up_to'],
$cardConfig['installments_without_interest'],
$cardConfig['interest'],
$cardConfig['incremental_interest']
$cardConfig['incremental_interest'],
null
)
);
}
Expand Down Expand Up @@ -71,6 +72,9 @@ public function createFromJsonData($json)
}

$config->setAntifraudEnabled($antifraudEnabled);
if (isset($data->saveVoucherCards)) {
$config->setSaveVoucherCards($data->saveVoucherCards);
}
$config->setAntifraudMinAmount($antifraudMinAmount);
$config->setBoletoEnabled($data->boletoEnabled);
$config->setCreditCardEnabled($data->creditCardEnabled);
Expand Down
32 changes: 19 additions & 13 deletions src/Kernel/Factories/Configurations/VoucherConfigFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,25 @@ public function createFromDbData($data)
$voucherConfig->setSaveCards((bool) $data->saveCards);
}

foreach ($data->cardConfigs as $cardConfig) {
$brand = strtolower($cardConfig->brand);
$voucherConfig->addCardConfig(
new CardConfig(
$cardConfig->enabled,
CardBrand::$brand(),
$cardConfig->maxInstallment,
$cardConfig->maxInstallmentWithoutInterest,
$cardConfig->initialInterest,
$cardConfig->incrementalInterest,
$cardConfig->minValue
)
);
if (isset($data->saveVoucherCards)) {
$voucherConfig->setSaveVoucherCards((bool) $data->saveVoucherCards);
}

if (isset($data->cardConfigs)) {
foreach ($data->cardConfigs as $cardConfig) {
$brand = strtolower($cardConfig->brand);
$voucherConfig->addCardConfig(
new CardConfig(
$cardConfig->enabled,
CardBrand::$brand(),
$cardConfig->maxInstallment,
$cardConfig->maxInstallmentWithoutInterest,
$cardConfig->initialInterest,
$cardConfig->incrementalInterest,
$cardConfig->minValue
)
);
}
}

return $voucherConfig;
Expand Down
3 changes: 2 additions & 1 deletion src/Kernel/Factories/TransactionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ public function createFromPostData($postData)

if (isset($postData['card'])) {
$cardFactory = new SavedCardFactory();
$postData['card']['type'] = $transaction->getTransactionType()->getType();
$card = $cardFactory->createFromTransactionData($postData['card']);

$transaction->setCardData($card);
}

Expand Down Expand Up @@ -182,6 +182,7 @@ public function createFromDbData($dbData)
if (!empty($dbData['card_data']) && $dbData['card_data'] !== "null") {
$cardData = json_decode($dbData['card_data']);
$cardFactory = new SavedCardFactory();
$cardData->type = $transaction->getTransactionType()->getType();
$card = $cardFactory->createFromTransactionJson($cardData);

$transaction->setCardData($card);
Expand Down
103 changes: 101 additions & 2 deletions src/Kernel/Services/LogService.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function __construct($channelName, $addHost = false)
public function info($message, $sourceObject = null)
{
$logObject = $this->prepareObject($sourceObject);

$logObject = $this->blurSensitiveData($logObject);
$this->monolog->info($message, $logObject);
}

Expand Down Expand Up @@ -94,4 +94,103 @@ public function getPath()
{
return $this->path;
}
}

private function blurSensitiveData($data)
{
if (isset($data['data'])) {
if (isset($data['data']['customer'])) {
$data = $this->blurCustomer($data);
}
if (isset($data['data']['shipping'])) {
$data = $this->blurShipping($data);
}
if (isset($data['data']['payments'][0]['customer'])) {
$data = $this->blurPaymentCustomer($data);
}
if (isset($data['data']['charges'][0]['customer'])) {
$data = $this->blurChargeCustomer($data);
}
if (isset($data['data']['charges'][0]['last_transaction']['card']['billing_address'])) {
$data['data']['charges'][0]['last_transaction']['card']['billing_address'] = null;
}
if (isset($data['data']['payments'][0]['credit_card']['card']['billing_address'])) {
$data['data']['payments'][0]['credit_card']['card']['billing_address'] = null;
}
}
return $data;
}

private function blurStringSensitiveData($string, $delimiter){
$displayed = substr($string, 0, $delimiter);
$blur = str_repeat("*", strlen($string));
$blur = substr($blur, $delimiter);
$result = "$displayed $blur";
return $result;
}

private function blurEmailSensitiveData($string)
{
$displayed = substr($string, 0, 3);
$final = substr($string, strpos($string, "@"));
$result = "$displayed***$final";
return $result;
}

private function blurCustomer($data){
$data['data']['customer']['name'] = $this->blurStringSensitiveData($data['data']['customer']['name'], 5);
$data['data']['customer']['email'] = $this->blurEmailSensitiveData($data['data']['customer']['email']);
$data['data']['customer']['document'] = preg_replace('/\B[^@.]/', '*', $data['data']['customer']['document']);
$data['data']['customer']['phones'] = '***********';
$data['data']['customer']['address']['street'] = $this->blurStringSensitiveData($data['data']['customer']['address']['street'], 8);
$data['data']['customer']['address']['line_1'] = $this->blurStringSensitiveData($data['data']['customer']['address']['line_1'], 8);
$data['data']['customer']['address']['line_2'] = '***********';
$data['data']['customer']['address']['number'] = '***********';
$data['data']['customer']['address']['complement'] = '***********';
$data['data']['customer']['address']['zip_code'] = $this->blurStringSensitiveData($data['data']['customer']['address']['zip_code'], 5);
$data['data']['customer']['address']['neighborhood'] = '***********';
return $data;
}

private function blurShipping($data){
$data['data']['shipping']['recipient_name'] = $this->blurStringSensitiveData($data['data']['shipping']['recipient_name'], 5);
$data['data']['shipping']['recipient_phone'] = '***********';
$data['data']['shipping']['address']['street'] = $this->blurStringSensitiveData($data['data']['shipping']['address']['street'], 8);
$data['data']['shipping']['address']['line_1'] = $this->blurStringSensitiveData($data['data']['shipping']['address']['line_1'], 8);
$data['data']['shipping']['address']['line_2'] = '***********';
$data['data']['shipping']['address']['number'] = '***********';
$data['data']['shipping']['address']['complement'] = '***********';
$data['data']['shipping']['address']['zip_code'] = $this->blurStringSensitiveData($data['data']['shipping']['address']['zip_code'], 5);
$data['data']['shipping']['address']['neighborhood'] = '***********';
return $data;
}

private function blurPaymentCustomer($data){
$data['data']['payments'][0]['customer']['name'] = $this->blurStringSensitiveData($data['data']['payments'][0]['customer']['name'], 5);
$data['data']['payments'][0]['customer']['email'] = $this->blurEmailSensitiveData($data['data']['payments'][0]['customer']['email']);
$data['data']['payments'][0]['customer']['document'] = preg_replace('/\B[^@.]/', '*', $data['data']['payments'][0]['customer']['document']);
$data['data']['payments'][0]['customer']['phones'] = '***********';
$data['data']['payments'][0]['customer']['address']['street'] = $this->blurStringSensitiveData($data['data']['payments'][0]['customer']['address']['street'], 8);
$data['data']['payments'][0]['customer']['address']['line_1'] = $this->blurStringSensitiveData($data['data']['payments'][0]['customer']['address']['line_1'], 8);
$data['data']['payments'][0]['customer']['address']['line_2'] = '***********';
$data['data']['payments'][0]['customer']['address']['number'] = '***********';
$data['data']['payments'][0]['customer']['address']['complement'] = '***********';
$data['data']['payments'][0]['customer']['address']['zip_code'] = $this->blurStringSensitiveData($data['data']['payments'][0]['customer']['address']['zip_code'], 5);
$data['data']['payments'][0]['customer']['address']['neighborhood'] = '***********';
return $data;
}

private function blurChargeCustomer($data){
$data['data']['charges'][0]['customer']['name'] = $this->blurStringSensitiveData($data['data']['charges'][0]['customer']['name'], 5);
$data['data']['charges'][0]['customer']['email'] = $this->blurEmailSensitiveData($data['data']['charges'][0]['customer']['email']);
$data['data']['charges'][0]['customer']['document'] = preg_replace('/\B[^@.]/', '*', $data['data']['charges'][0]['customer']['document']);
$data['data']['charges'][0]['customer']['phones'] = '***********';
$data['data']['charges'][0]['customer']['address']['street'] = $this->blurStringSensitiveData($data['data']['charges'][0]['customer']['address']['street'], 8);
$data['data']['charges'][0]['customer']['address']['line_1'] = $this->blurStringSensitiveData($data['data']['charges'][0]['customer']['address']['line_1'], 8);
$data['data']['charges'][0]['customer']['address']['line_2'] = '***********';
$data['data']['charges'][0]['customer']['address']['number'] = '***********';
$data['data']['charges'][0]['customer']['address']['complement'] = '***********';
$data['data']['charges'][0]['customer']['address']['zip_code'] = $this->blurStringSensitiveData($data['data']['charges'][0]['customer']['address']['zip_code'], 5);
$data['data']['charges'][0]['customer']['address']['neighborhood'] = '***********';
return $data;
}
}
4 changes: 2 additions & 2 deletions src/Kernel/Services/OrderCreationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public function __construct(MundiAPIClient $mundiAPIClient)
*/
public function createOrder(
CreateOrderRequest $orderRequest,
$idempotencyKey,
$attempt = 1
$idempotencyKey,
$attempt = 1
) {
$shouldRetry = false;
$response = null;
Expand Down
5 changes: 4 additions & 1 deletion src/Kernel/Services/OrderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,9 @@ public function extractPaymentOrderFromPlatformOrder(

$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.
if (!$order->isPaymentSumCorrect()) {
$message = $i18n->getDashboard(
"The sum of payments is different than the order amount! " .
Expand All @@ -381,7 +384,7 @@ public function extractPaymentOrderFromPlatformOrder(
$orderInfo
);
throw new \Exception($message, 400);
}
}*/

$items = $platformOrder->getItemCollection();
foreach ($items as $item) {
Expand Down
21 changes: 21 additions & 0 deletions src/Kernel/ValueObjects/Configuration/VoucherConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class VoucherConfig extends AbstractValueObject
/** @var bool */
private $saveCards;

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

/** @var CardConfig[] */
private $cardConfigs;

Expand Down Expand Up @@ -100,6 +103,24 @@ public function setSaveCards($saveCards)
return $this;
}

/**
* @return bool
*/
public function isSaveVoucherCards()
{
return $this->saveVoucherCards;
}

/**
* @param bool $saveVoucherCards
* @return VoucherConfig
*/
public function setSaveVoucherCards($saveVoucherCards)
{
$this->saveVoucherCards = $saveVoucherCards;
return $this;
}

/**
*
* @param CardConfig $newCardConfig
Expand Down
4 changes: 3 additions & 1 deletion src/Payment/Aggregates/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,15 @@ private function blockOverPaymentAttempt(AbstractPayment $payment)
$currentAmount += $currentPayment->getAmount();
}

/*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.
if ($currentAmount > $this->amount) {
$message = $i18n->getDashboard(
"The sum of payments is greater than the order amount! " .
"Review the information and try again."
);
throw new \Exception($message, 400);
}
}*/
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Payment/Aggregates/Payments/NewVoucherPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function isSaveOnSuccess()
return false;
}

if (!MPSetup::getModuleConfiguration()->getVoucherConfig()->isSaveCards()) {
if (!MPSetup::getModuleConfiguration()->isSaveVoucherCards()) {
return false;
}

Expand Down
20 changes: 20 additions & 0 deletions src/Payment/Aggregates/SavedCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ final class SavedCard extends AbstractEntity
/** @var NumericString */
private $firstSixDigits;

/** @var NumericString */
private $type;

/** @var NumericString */
private $lastFourDigits;

Expand Down Expand Up @@ -61,6 +64,22 @@ public function setOwnerName($ownerName)
$this->ownerName = $ownerName;
}

/**
* @return NumericString
*/
public function getType()
{
return $this->type;
}

/**
* @param NumericString $type
*/
public function setType($type)
{
$this->type = $type;
}

/**
* @return NumericString
*/
Expand Down Expand Up @@ -139,6 +158,7 @@ public function jsonSerialize()
$obj->id = $this->getId();
$obj->pagarmeId = $this->getPagarmeId();
$obj->ownerId = $this->getOwnerId();
$obj->type = $this->getType();
$obj->ownerName = $this->getOwnerName();
$obj->firstSixDigits = $this->getFirstSixDigits();
$obj->lastFourDigits = $this->getLastFourDigits();
Expand Down
Loading

0 comments on commit 759bf14

Please sign in to comment.