Skip to content

Commit

Permalink
Merge pull request #92 from mundipagg/develop
Browse files Browse the repository at this point in the history
Merge Develop into Master
  • Loading branch information
GabrielDeveloper committed Oct 1, 2019
2 parents 3b52e73 + b3cdcce commit d4edf0e
Show file tree
Hide file tree
Showing 16 changed files with 102 additions and 35 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "mundipagg/ecommerce-module-core",
"license": "MIT",
"version": "1.10.7",
"version": "1.10.8",
"authors":[
{
"name":"MundiPagg Embeddables Team",
Expand Down
14 changes: 7 additions & 7 deletions src/Kernel/Aggregates/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ final class Configuration extends AbstractEntity
private $saveCards;

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

/** @var RecurrenceConfig */
private $recurrenceConfig;
Expand All @@ -124,7 +124,7 @@ final class Configuration extends AbstractEntity
public function __construct()
{
$this->saveCards = false;
$this->multiBuyer = false;
$this->multibuyer = false;
$this->cardConfigs = [];
$this->methodsInherited = [];

Expand Down Expand Up @@ -511,15 +511,15 @@ public function setSaveCards($saveCards)
*/
public function isMultiBuyer()
{
return $this->multiBuyer;
return $this->multibuyer;
}

/**
* @param bool $multiBuyer
* @param bool $multibuyer
*/
public function setMultiBuyer($multiBuyer)
public function setMultiBuyer($multibuyer)
{
$this->multiBuyer = $multiBuyer;
$this->multibuyer = $multibuyer;
}

/**
Expand All @@ -539,7 +539,7 @@ public function jsonSerialize()
"boletoEnabled" => $this->boletoEnabled,
"creditCardEnabled" => $this->creditCardEnabled,
"saveCards" => $this->isSaveCards(),
"multiBuyer" => $this->isMultiBuyer(),
"multibuyer" => $this->isMultiBuyer(),
"twoCreditCardsEnabled" => $this->twoCreditCardsEnabled,
"boletoCreditCardEnabled" => $this->boletoCreditCardEnabled,
"testMode" => $this->testMode,
Expand Down
39 changes: 36 additions & 3 deletions src/Kernel/Factories/ChargeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
use Mundipagg\Core\Payment\Repositories\CustomerRepository;
use Throwable;

/**
* Class ChargeFactory
* @package Mundipagg\Core\Kernel\Factories
*/
class ChargeFactory implements FactoryInterface
{
/**
Expand Down Expand Up @@ -119,6 +123,10 @@ public function createFromDbData($dbData)
return $charge;
}

/**
* @param $dbData
* @return array
*/
private function extractTransactionsFromDbData($dbData)
{
$transactions = [];
Expand Down Expand Up @@ -158,8 +166,8 @@ private function extractTransactionsFromDbData($dbData)
'acquirer_auth_code' => $tranAcquirerAuthCode[$index],
'acquirer_message' => $tranAcquirerMessage[$index],
'created_at' => $tranCreatedAt[$index],
'boleto_url' => $tranBoletoUrl[$index],
'card_data' => $tranCardData[$index]
'boleto_url' => $this->treatBoletoUrl($tranBoletoUrl, $index),
'card_data' => $this->treatCardData($tranCardData, $index)
];
$transactions[] = $transaction;
}
Expand All @@ -168,4 +176,29 @@ private function extractTransactionsFromDbData($dbData)
return $transactions;
}

}
/**
* @param array $carData
* @param int $index
* @return string|null
*/
private function treatCardData(array $tranCardData, $index)
{
if (!isset($tranCardData[$index])) {
return null;
}
return $tranCardData[$index];
}

/**
* @param array $tranBoletoUrl
* @param int $index
* @return string|null
*/
private function treatBoletoUrl(array $tranBoletoUrl, $index)
{
if (!isset($tranBoletoUrl[$index])) {
return null;
}
return $tranBoletoUrl[$index];
}
}
4 changes: 2 additions & 2 deletions src/Kernel/Factories/ConfigurationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ public function createFromJsonData($json)
$config->setSaveCards($data->saveCards);
}

if (isset($data->multiBuyer)) {
$config->setMultiBuyer($data->multiBuyer);
if (isset($data->multibuyer)) {
$config->setMultiBuyer($data->multibuyer);
}

if (isset($data->recurrenceConfig)) {
Expand Down
3 changes: 3 additions & 0 deletions src/Kernel/Services/MoneyService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Mundipagg\Core\Kernel\Services;

use Mundipagg\Core\Kernel\Exceptions\InvalidParamException;

final class MoneyService
{
/**
Expand All @@ -25,6 +27,7 @@ public function centsToFloat($amount)
*/
public function floatToCents($amount)
{
$amount = (float) $amount;
if (!is_float($amount)) {
throw new InvalidParamException("Amount should be a float!", $amount);
}
Expand Down
27 changes: 25 additions & 2 deletions src/Kernel/Services/OrderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ public function createOrderAtMundipagg(PlatformOrderInterface $platformOrder)
$apiService = new APIService();
$response = $apiService->createOrder($order);

if (isset($response['status']) && $response['status'] == 'failed') {
if ($this->checkResponseStatus($response)) {
$i18n = new LocalizationService();
$message = $i18n->getDashboard("Can't create order");
$message = $i18n->getDashboard("Can't create order.");

throw new \Exception($message, 400);
}
Expand Down Expand Up @@ -267,4 +267,27 @@ private function getOrderInfo(PlatformOrderInterface $platformOrder)
$orderInfo->grandTotal = $platformOrder->getGrandTotal();
return $orderInfo;
}

/**
* @param $response
* @return boolean
*/
private function checkResponseStatus($response)
{
if (
!isset($response['status']) ||
!isset($response['charges']) ||
$response['status'] == 'failed'
) {
return false;
}

foreach ($response['charges'] as $charge) {
if (isset($charge['status']) && $charge['status'] == 'failed') {
return false;
}
}

return;
}
}
2 changes: 2 additions & 0 deletions src/Kernel/ValueObjects/AbstractValidString.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ abstract class AbstractValidString extends AbstractValueObject

public function __construct($value)
{
$value = (string) $value;

if (!is_string($value)) {
throw new InvalidParamException("Value should be a string!", $value);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Maintenance/Assets/integrityData

Large diffs are not rendered by default.

22 changes: 14 additions & 8 deletions src/Payment/Aggregates/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,14 @@ public function getNumber()
*/
public function setNumber($number)
{
$this->number = str_replace(
$numberWithoutComma = str_replace(
self::ADDRESS_LINE_SEPARATOR,
'',
$number
);

$this->number = substr($numberWithoutComma, 0, 15);

if (empty($this->number)) {

$inputName = $this->i18n->getDashboard('number');
Expand Down Expand Up @@ -100,12 +102,14 @@ public function getStreet()
*/
public function setStreet($street)
{
$this->street = str_replace(
$streetWithoutComma = str_replace(
self::ADDRESS_LINE_SEPARATOR,
'',
$street
);

$this->street = substr($streetWithoutComma, 0, 64);

if (empty($this->street)) {

$inputName = $this->i18n->getDashboard('street');
Expand Down Expand Up @@ -135,12 +139,14 @@ public function getNeighborhood()
*/
public function setNeighborhood($neighborhood)
{
$this->neighborhood = str_replace(
$neighborhoodWithoutComma = str_replace(
self::ADDRESS_LINE_SEPARATOR,
'',
$neighborhood
);

$this->neighborhood = substr($neighborhoodWithoutComma, 0, 64);

if (empty($this->neighborhood)) {

$inputName = $this->i18n->getDashboard('neighborhood');
Expand Down Expand Up @@ -169,7 +175,7 @@ public function getComplement()
*/
public function setComplement($complement)
{
$this->complement = $complement;
$this->complement = substr($complement, 0, 64);
return $this;
}

Expand All @@ -187,7 +193,7 @@ public function getZipCode()
*/
public function setZipCode($zipCode)
{
$this->zipCode = $zipCode;
$this->zipCode = substr($zipCode, 0, 16);
return $this;
}

Expand All @@ -206,7 +212,7 @@ public function getCity()
*/
public function setCity($city)
{
$this->city = $city;
$this->city = substr($city, 0, 64);

if (empty($this->city)) {

Expand Down Expand Up @@ -237,7 +243,7 @@ public function getCountry()
*/
public function setCountry($country)
{
$this->country = $country;
$this->country = substr($country, 0, 2);

if (empty($this->country)) {

Expand Down Expand Up @@ -283,7 +289,7 @@ public function getState()
*/
public function setState($state)
{
$this->state = $state;
$this->state = substr($state, 0, 2);

if (empty($this->state)) {

Expand Down
6 changes: 3 additions & 3 deletions src/Payment/Aggregates/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function getCode()
*/
public function setCode($code)
{
$this->code = $code;
$this->code = substr($code, 0, 52);
}

/**
Expand Down Expand Up @@ -82,7 +82,7 @@ public function getEmail()
*/
public function setEmail($email)
{
$this->email = $email;
$this->email = substr($email, 0, 64);

if (empty($this->email)) {

Expand Down Expand Up @@ -128,7 +128,7 @@ public function getDocument()
*/
public function setDocument($document)
{
$this->document = $document;
$this->document = substr($document, 0, 16);

if (empty($this->document)) {

Expand Down
4 changes: 2 additions & 2 deletions src/Payment/Aggregates/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function getCode()

public function setCode($code)
{
$this->code = $code;
$this->code = substr($code, 0, 52);
}

/**
Expand All @@ -45,7 +45,7 @@ public function getDescription()
*/
public function setDescription($description)
{
$this->description = $description;
$this->description = substr($description, 0, 256);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Payment/Aggregates/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function getCode()
*/
public function setCode($code)
{
$this->code = $code;
$this->code = substr($code, 0, 52);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Payment/Aggregates/Shipping.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function getDescription()
*/
public function setDescription($description)
{
$this->description = $description;
$this->description = substr($description, 0, 64);
}

/**
Expand All @@ -50,7 +50,7 @@ public function getRecipientName()
*/
public function setRecipientName($recipientName)
{
$this->recipientName = $recipientName;
$this->recipientName = substr($recipientName, 0, 64);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Payment/Repositories/CustomerRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function findByMundipaggId(AbstractValidString $mundipaggId)

if ($result->num_rows > 0) {
$factory = new CustomerFactory();
$customer = $factory->createFromDbData($result->row);
$customer = $factory->createFromDbData(end($result->rows));

return $customer;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Payment/ValueObjects/CustomerPhones.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ private function setHome(Phone $home)

private function setMobile(Phone $mobile)
{
$this->mobile = $mobile;
$this->mobile = $mobile;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Payment/ValueObjects/Phone.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __construct($phone)

$this->countryCode = new NumericString(55);
$this->areaCode = new NumericString(substr($phone, 0, 2));
$this->number = new NumericString(substr($phone, 2));
$this->number = new NumericString(substr($phone, 2, 12));
}

/**
Expand Down

0 comments on commit d4edf0e

Please sign in to comment.