diff --git a/composer.json b/composer.json index 7813a37..5fafdc1 100644 --- a/composer.json +++ b/composer.json @@ -1,46 +1,46 @@ { - "name": "pagarme/ecommerce-module-core", - "description": "Core component for Pagar.me e-commerce platform modules.", - "license": "MIT", - "version": "2.6.0", - "authors": [ - { - "name":"Open Source Team" - } - ], - "type": "library", - "require": { - "php": ">=7.1", - "monolog/monolog": "<3", - "pagarme/pagarmecoreapi": "v5.6.5", - "ext-json": "*" - }, - "require-dev": { - "mockery/mockery": "1.2.4", - "nesbot/carbon": "1.39.0", - "ext-pdo": "*", - "phpunit/phpunit": "^5 | ^6 | ^7 | ^8 | ^9" - }, - "autoload": { - "psr-4": { - "Pagarme\\Core\\": "src", - "Pagarme\\Core\\Test\\": "tests", - "Pagarme\\Core\\Test\\Mock\\": "tests\\mock" - } - }, - "scripts": { - "post-install-cmd": [ - "cp 'hooks/pre-commit' '.git/hooks/pre-commit'" - ], - "post-update-cmd": [ - "cp 'hooks/pre-commit' '.git/hooks/pre-commit'" + "name": "pagarme/ecommerce-module-core", + "description": "Core component for Pagar.me e-commerce platform modules.", + "license": "MIT", + "version": "2.7.0", + "authors": [ + { + "name":"Open Source Team" + } ], - "tests": "vendor/bin/phpunit --colors=always", - "tests-coverage": "vendor/bin/phpunit --colors=always --coverage-html ./tests/report" - }, - "config": { - "allow-plugins": { - "kylekatarnls/update-helper": true + "type": "library", + "require": { + "php": ">=7.1", + "monolog/monolog": "<3", + "pagarme/pagarmecoreapi": "v5.6.6", + "ext-json": "*" + }, + "require-dev": { + "mockery/mockery": "1.2.4", + "nesbot/carbon": "1.39.0", + "ext-pdo": "*", + "phpunit/phpunit": "^5 | ^6 | ^7 | ^8 | ^9" + }, + "autoload": { + "psr-4": { + "Pagarme\\Core\\": "src", + "Pagarme\\Core\\Test\\": "tests", + "Pagarme\\Core\\Test\\Mock\\": "tests\\mock" + } + }, + "scripts": { + "post-install-cmd": [ + "cp 'hooks/pre-commit' '.git/hooks/pre-commit'" + ], + "post-update-cmd": [ + "cp 'hooks/pre-commit' '.git/hooks/pre-commit'" + ], + "tests": "vendor/bin/phpunit --colors=always", + "tests-coverage": "vendor/bin/phpunit --colors=always --coverage-html ./tests/report" + }, + "config": { + "allow-plugins": { + "kylekatarnls/update-helper": true + } } - } } diff --git a/src/Kernel/Repositories/OrderRepository.php b/src/Kernel/Repositories/OrderRepository.php index e05165d..8e65b13 100644 --- a/src/Kernel/Repositories/OrderRepository.php +++ b/src/Kernel/Repositories/OrderRepository.php @@ -23,7 +23,7 @@ protected function create(AbstractEntity &$object) $order = json_decode(json_encode($object)); $query = " - INSERT INTO $orderTable (`pagarme_id`, `code`, `status`) + INSERT INTO $orderTable (`pagarme_id`, `code`, `status`) VALUES ('{$order->pagarmeId}', '{$order->code}', '{$order->status}'); "; @@ -119,7 +119,7 @@ public function findByPlatformId($platformID) $orderTable = $this->db->getTable(AbstractDatabaseDecorator::TABLE_ORDER); $platformID = filter_var($platformID, FILTER_SANITIZE_SPECIAL_CHARS); $query = "SELECT * FROM `$orderTable` "; - $query .= "WHERE code = '{$platformID}';"; + $query .= "WHERE code = '{$platformID}' ORDER BY id DESC;"; $result = $this->db->fetch($query); @@ -136,4 +136,4 @@ public function listEntities($limit, $listDisabled) { // TODO: Implement listEntities() method. } -} \ No newline at end of file +} diff --git a/src/Kernel/Services/ChargeService.php b/src/Kernel/Services/ChargeService.php index 4c49543..e4c05fc 100644 --- a/src/Kernel/Services/ChargeService.php +++ b/src/Kernel/Services/ChargeService.php @@ -311,11 +311,20 @@ public function findChargeWithOutOrder($code) { $chargeRepository = new ChargeRepository(); - try { - return $chargeRepository->findChargeWithOutOrder($code); - } catch (Exception $exception) { - throw new Exception($exception, $exception->getCode()); - } + return $chargeRepository->findChargeWithOutOrder($code); + } + + /** + * @param $code + * + * @return Charge[] + * @throws \Exception + */ + public function findChargesByCode($code) + { + $chargeRepository = new ChargeRepository(); + + return $chargeRepository->findChargesByCode($code); } /** diff --git a/src/Kernel/ValueObjects/CardBrand.php b/src/Kernel/ValueObjects/CardBrand.php index 165e885..993ee78 100644 --- a/src/Kernel/ValueObjects/CardBrand.php +++ b/src/Kernel/ValueObjects/CardBrand.php @@ -26,6 +26,7 @@ final class CardBrand extends AbstractValueObject CONST SODEXO_PREMIUM = "SodexoPremium"; CONST SODEXO_REFEICAO = "SodexoRefeicao"; CONST SODEXO_COMBUSTIVEL = "SodexoCombustivel"; + CONST TICKET = "Ticket"; CONST VR = "VR"; CONST ALELO = "Alelo"; CONST BANESE = "Banese"; @@ -134,6 +135,11 @@ static public function sodexocombustivel() return new self(self::SODEXO_COMBUSTIVEL); } + static public function ticket() + { + return new self(self::TICKET); + } + static public function vr() { return new self(self::VR); @@ -172,13 +178,13 @@ protected function isEqual($object) } /** - * Specify data which should be serialized to JSON - * - * @link https://php.net/manual/en/jsonserializable.jsonserialize.php - * @return mixed data which can be serialized by json_encode, - * which is a value of any type other than a resource. - * @since 5.4.0 - */ + * Specify data which should be serialized to JSON + * + * @link https://php.net/manual/en/jsonserializable.jsonserialize.php + * @return mixed data which can be serialized by json_encode, + * which is a value of any type other than a resource. + * @since 5.4.0 + */ #[\ReturnTypeWillChange] public function jsonSerialize() { diff --git a/src/Middle/Model/Account.php b/src/Middle/Model/Account.php index b4f6129..6bcedd5 100644 --- a/src/Middle/Model/Account.php +++ b/src/Middle/Model/Account.php @@ -11,10 +11,6 @@ class Account extends ModelWithErrors { const ACCOUNT_DISABLED = 'accountDisabled'; - const DOMAIN_EMPTY = 'domainEmpty'; - - const DOMAIN_INCORRECT = 'domainIncorrect'; - const WEBHOOK_INCORRECT = 'webhookIncorrect'; const MULTIPAYMENTS_DISABLED = 'multiPaymentsDisabled'; @@ -242,7 +238,6 @@ public function setDebitCardSettings($debitCardSettings) public function validate($storeSettings = null) { $this->validateAccountEnabled(); - $this->validateDomain($storeSettings); $this->validateWebhooks($storeSettings); $this->validateMultiBuyer(); $this->validateMultiPayments(); @@ -265,34 +260,6 @@ private function validateAccountEnabled() } } - /** - * @param StoreSettings|null $storeSettings - * @return void - */ - private function validateDomain($storeSettings = null) - { - $domains = $this->getDomains(); - if (empty($domains) && (empty($storeSettings) || !$storeSettings->isSandbox())) { - $this->addError(self::DOMAIN_EMPTY); - return; - } - - if ($this->canNotValidateUrlSetting($storeSettings)) { - return; - } - - $siteUrls = $storeSettings->getStoreUrls(); - foreach ($domains as $domain) { - foreach ($siteUrls as $siteUrl) { - if (strpos($siteUrl, $domain) !== false) { - return; - } - } - } - - $this->addError(self::DOMAIN_INCORRECT); - } - /** * @param StoreSettings|null $storeSettings * @return void diff --git a/src/Middle/Model/Customer/Address.php b/src/Middle/Model/Customer/Address.php index 10c777a..e0609ca 100644 --- a/src/Middle/Model/Customer/Address.php +++ b/src/Middle/Model/Customer/Address.php @@ -93,15 +93,24 @@ public function getNumber() { return $this->number ?? ""; } - + public function getComplement() { return $this->complement ?? ""; } - + public function getLine1() { - $address = [$this->getNumber(), $this->getStreet(), $this->getNeighborhood()]; + if (!empty($this->getNumber())) { + $address[] = $this->getNumber(); + } + + $address[] = $this->getStreet(); + + if (!empty($this->getNeighborhood())) { + $address[] = $this->getNeighborhood(); + } + return implode(self::ADDRESS_SEPARATOR, $address); } diff --git a/src/Payment/Aggregates/Address.php b/src/Payment/Aggregates/Address.php index a692f65..5d313d8 100644 --- a/src/Payment/Aggregates/Address.php +++ b/src/Payment/Aggregates/Address.php @@ -78,8 +78,7 @@ public function setNumber($number) $this->number = substr($numberWithoutLineBreaks, 0, 15); - if (empty($this->number) && ($this->number === null || !is_numeric(trim($this->number)))) { - + if (empty(trim($this->number))) { $inputName = $this->i18n->getDashboard('number'); $message = $this->i18n->getDashboard( "The %s should not be empty!", @@ -107,14 +106,8 @@ public function getStreet() */ public function setStreet($street) { - $streetWithoutComma = str_replace( - self::ADDRESS_LINE_SEPARATOR, - '', - $street ?? '' - ); - $streetWithoutLineBreaks = StringFunctionsHelper::removeLineBreaks( - $streetWithoutComma + $street ); $this->street = substr($streetWithoutLineBreaks, 0, 64); @@ -137,7 +130,7 @@ public function setStreet($street) */ public function getNeighborhood() { - return $this->neighborhood; + return $this->neighborhood ?? ''; } /** @@ -159,17 +152,6 @@ public function setNeighborhood($neighborhood) $this->neighborhood = substr($neighborhoodWithoutLineBreaks, 0, 64); - if (empty($this->neighborhood)) { - - $inputName = $this->i18n->getDashboard('neighborhood'); - $message = $this->i18n->getDashboard( - "The %s should not be empty!", - $inputName - ); - - throw new \Exception($message, 400); - } - return $this; } @@ -289,12 +271,17 @@ public function setCountry($country) public function getLine1() { - $line = []; - $line[] = $this->getNumber(); + if ($this->getNumber()) { + $line[] = $this->getNumber(); + } + $line[] = $this->getStreet(); - $line[] = $this->getNeighborhood(); - return implode (self::ADDRESS_LINE_SEPARATOR, $line); + if ($this->getNeighborhood()) { + $line[] = $this->getNeighborhood(); + } + + return implode(self::ADDRESS_LINE_SEPARATOR, $line); } public function getLine2() @@ -334,21 +321,21 @@ public function setState($state) } /** - * Specify data which should be serialized to JSON - * @link https://php.net/manual/en/jsonserializable.jsonserialize.php - * @return string data which can be serialized by json_encode, - * which is a value of any type other than a resource. - * @since 5.4.0 - */ + * Specify data which should be serialized to JSON + * @link https://php.net/manual/en/jsonserializable.jsonserialize.php + * @return \stdClass data which can be serialized by json_encode, + * which is a value of any type other than a resource. + * @since 5.4.0 + */ #[\ReturnTypeWillChange] public function jsonSerialize() { $obj = new \stdClass(); - $obj->number = $this->number; $obj->street = $this->street; - $obj->neighborhood = $this->neighborhood; + $obj->number = $this->number; $obj->complement = $this->complement; + $obj->neighborhood = $this->neighborhood; $obj->zipCode = $this->zipCode; $obj->city = $this->city; $obj->state = $this->state; @@ -366,16 +353,16 @@ public function convertToSDKRequest() { $addressRequest = new CreateAddressRequest(); - $addressRequest->city = $this->getCity(); + $addressRequest->street = $this->getStreet(); + $addressRequest->number = $this->getNumber(); $addressRequest->complement = $this->getComplement(); - $addressRequest->country = $this->getCountry(); - $addressRequest->line1 = $this->getLine1(); - $addressRequest->line2 = $this->getLine2(); $addressRequest->neighborhood = $this->getNeighborhood(); - $addressRequest->number = $this->getNumber(); + $addressRequest->city = $this->getCity(); $addressRequest->state = $this->getState(); - $addressRequest->street = $this->getStreet(); + $addressRequest->country = $this->getCountry(); $addressRequest->zipCode = $this->getZipCode(); + $addressRequest->line1 = $this->getLine1(); + $addressRequest->line2 = $this->getLine2(); return $addressRequest; } diff --git a/src/Payment/Aggregates/Payments/GooglePayPayment.php b/src/Payment/Aggregates/Payments/GooglePayPayment.php index 08a47f2..93a37c7 100644 --- a/src/Payment/Aggregates/Payments/GooglePayPayment.php +++ b/src/Payment/Aggregates/Payments/GooglePayPayment.php @@ -18,6 +18,10 @@ final class GooglePayPayment extends AbstractPayment */ public $additionalInformation; + /** + * @var array $billingAddress + */ + public $billingAddress; /** * @return array @@ -27,6 +31,14 @@ public function getAdditionalInformation() return $this->additionalInformation; } + /** + * @param array $billingAddress + */ + public function setBillingAddress($billingAddress) + { + $this->billingAddress = $billingAddress; + } + /** * @param array $additionalInformation */ @@ -62,7 +74,7 @@ private function parseIntermediateSigningKey(&$payload) unset($payload['intermediateSigningKey']); unset($payload['intermediate_signing_key']['signedKey']); } - + private function parseSignedMessage(&$payload) { $payload['signed_message'] = $payload['signedMessage']; @@ -85,6 +97,11 @@ private function getStatementDescriptor() return $this->moduleConfig->getCardStatementDescriptor(); } + private function getBillingAddress() + { + return $this->billingAddress; + } + /** * @return CreateGooglePayPaymentRequest */ @@ -93,6 +110,8 @@ protected function convertToPrimitivePaymentRequest() $payload = new \stdClass(); $payload->type = "google_pay"; $payload->google_pay = $this->getGooglePayload(); - return new CreateGooglePayPaymentRequest($this->getStatementDescriptor(), $payload); + $card = new \stdClass(); + $card->billing_address = $this->getBillingAddress(); + return new CreateGooglePayPaymentRequest($this->getStatementDescriptor(), $payload, $card); } } diff --git a/src/Payment/Factories/AddressFactory.php b/src/Payment/Factories/AddressFactory.php index 7e8b440..7ada97b 100644 --- a/src/Payment/Factories/AddressFactory.php +++ b/src/Payment/Factories/AddressFactory.php @@ -14,8 +14,8 @@ public function createFromJson($json) $address->setStreet($data->street); $address->setNumber($data->number); - $address->setNeighborhood($data->neighborhood); $address->setComplement($data->complement); + $address->setNeighborhood($data->neighborhood); $address->setCity($data->city); $address->setState($data->state); $address->setZipCode($data->zipCode); @@ -23,4 +23,4 @@ public function createFromJson($json) return $address; } -} \ No newline at end of file +} diff --git a/src/Payment/Factories/PaymentFactory.php b/src/Payment/Factories/PaymentFactory.php index ac8231e..62e419e 100644 --- a/src/Payment/Factories/PaymentFactory.php +++ b/src/Payment/Factories/PaymentFactory.php @@ -311,7 +311,7 @@ private function createGooglePayPayments($data) if (!empty($value->additionalInformation)) { $payment->setAdditionalInformation($value->additionalInformation); } - + $payment->setBillingAddress($value->billing_address); $payment->setAmount($value->amount); $payments[] = $payment;