diff --git a/assets/stylesheets/front/style.css b/assets/stylesheets/front/style.css
index f62b6fcf..5a37e942 100644
--- a/assets/stylesheets/front/style.css
+++ b/assets/stylesheets/front/style.css
@@ -151,7 +151,6 @@
width: 100%;
height: 100%;
overflow: auto;
- background-color: rgb(0, 0, 0);
background-color: rgba(0, 0, 0, 0.4);
}
@@ -165,7 +164,7 @@
#challengeIframe {
display: none;
- width: 500px;
+ width: 500px;
height: 600px;
border: 0;
}
diff --git a/languages/woo-pagarme-payments-pt_BR.mo b/languages/woo-pagarme-payments-pt_BR.mo
index 289215b4..e099d11e 100644
Binary files a/languages/woo-pagarme-payments-pt_BR.mo and b/languages/woo-pagarme-payments-pt_BR.mo differ
diff --git a/languages/woo-pagarme-payments-pt_BR.po b/languages/woo-pagarme-payments-pt_BR.po
index 8d3c8b48..c67d5079 100644
--- a/languages/woo-pagarme-payments-pt_BR.po
+++ b/languages/woo-pagarme-payments-pt_BR.po
@@ -5,7 +5,7 @@ msgstr ""
"Project-Id-Version: WooCommerce Pagar.me Payments 1.0\n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/woo-pagarme-payments\n"
"POT-Creation-Date: 2018-06-22 13:58-0300\n"
-"PO-Revision-Date: 2024-05-07 10:10-0300\n"
+"PO-Revision-Date: 2024-05-08 14:18-0300\n"
"Last-Translator: Pagar.me\n"
"Language-Team: \n"
"Language: pt_BR\n"
@@ -1312,8 +1312,8 @@ msgstr "Habilitar 3DS"
msgid "Minimum value for 3DS authentication"
msgstr "Valor mínimo para autenticação 3DS"
-msgid "Failed to generate Token for 3ds, try again."
-msgstr "Falha ao gerar Token para 3ds, tente novamente."
+msgid "Failed to generate Token for 3DS, try again."
+msgstr "Falha ao gerar Token para 3DS, tente novamente."
msgid "There was a problem finding the email."
msgstr "Ocorreu um problema ao encontrar o e-mail."
diff --git a/src/Block/Checkout/Form/Card.php b/src/Block/Checkout/Form/Card.php
index 4bc42813..9ca802ba 100644
--- a/src/Block/Checkout/Form/Card.php
+++ b/src/Block/Checkout/Form/Card.php
@@ -26,7 +26,7 @@
class Card extends Gateway
{
const INVALID_CARD_ERROR_MESSAGE = 'This card number is invalid.';
-
+
/**
* @var string
*/
@@ -55,7 +55,7 @@ public function enqueue_scripts($scripts = null, $deps = [])
self::getLocalizeScriptArgs()
);
}
-
+
/**
* @param int $sequence
* @return $this
@@ -204,7 +204,7 @@ public static function getCardErrorsMessagesTranslated()
'card: Tokenize timeout' =>
__('Tokenization timeout.', 'woo-pagarme-payments'),
'fail_get_token' =>
- __('Failed to generate Token for 3ds, try again.', 'woo-pagarme-payments'),
+ __('Failed to generate Token for 3DS, try again.', 'woo-pagarme-payments'),
'fail_get_email' =>
__('There was a problem finding the email.', 'woo-pagarme-payments'),
'fail_get_billing_address' =>
diff --git a/src/Concrete/WoocommercePlatformOrderDecorator.php b/src/Concrete/WoocommercePlatformOrderDecorator.php
index 26fb025e..f4624f70 100644
--- a/src/Concrete/WoocommercePlatformOrderDecorator.php
+++ b/src/Concrete/WoocommercePlatformOrderDecorator.php
@@ -2,39 +2,42 @@
namespace Woocommerce\Pagarme\Concrete;
-use stdClass;
-use WC_Order;
-use Woocommerce\Pagarme\Model\Order;
-use Woocommerce\Pagarme\Helper\Utils;
-use Woocommerce\Pagarme\Model\Config;
-use Pagarme\Core\Payment\Aggregates\Item;
+use Exception;
+use Pagarme\Core\Kernel\Abstractions\AbstractPlatformOrderDecorator;
use Pagarme\Core\Kernel\Aggregates\Charge;
+use Pagarme\Core\Kernel\Interfaces\PlatformInvoiceInterface;
+use Pagarme\Core\Kernel\Services\LocalizationService;
use Pagarme\Core\Kernel\Services\LogService;
-use Pagarme\Core\Payment\Aggregates\Address;
-use Pagarme\Core\Payment\ValueObjects\Phone;
-use Pagarme\Core\Payment\Aggregates\Customer;
-use Pagarme\Core\Payment\Aggregates\Shipping;
use Pagarme\Core\Kernel\Services\MoneyService;
use Pagarme\Core\Kernel\Services\OrderService;
use Pagarme\Core\Kernel\ValueObjects\Id\OrderId;
use Pagarme\Core\Kernel\ValueObjects\OrderState;
use Pagarme\Core\Kernel\ValueObjects\OrderStatus;
+use Pagarme\Core\Payment\Aggregates\Address;
+use Pagarme\Core\Payment\Aggregates\Customer;
+use Pagarme\Core\Payment\Aggregates\Item;
+use Pagarme\Core\Payment\Aggregates\Payments\AbstractCreditCardPayment;
+use Pagarme\Core\Payment\Aggregates\Payments\AbstractPayment;
+use Pagarme\Core\Payment\Aggregates\Payments\BoletoPayment;
+use Pagarme\Core\Payment\Aggregates\Payments\NewDebitCardPayment;
+use Pagarme\Core\Payment\Aggregates\Payments\NewVoucherPayment;
+use Pagarme\Core\Payment\Aggregates\Payments\PixPayment;
+use Pagarme\Core\Payment\Aggregates\Shipping;
use Pagarme\Core\Payment\Factories\PaymentFactory;
-use Pagarme\Core\Payment\ValueObjects\CustomerType;
-use Pagarme\Core\Kernel\Services\LocalizationService;
+use Pagarme\Core\Payment\Repositories\CustomerRepository as CoreCustomerRepository;
use Pagarme\Core\Payment\ValueObjects\CustomerPhones;
+use Pagarme\Core\Payment\ValueObjects\CustomerType;
+use Pagarme\Core\Payment\ValueObjects\Phone;
use Pagarme\Core\Recurrence\Services\RecurrenceService;
-use Pagarme\Core\Payment\Aggregates\Payments\PixPayment;
-use Woocommerce\Pagarme\Model\Payment as WCModelPayment;
+use stdClass;
+use Throwable;
+use WC_Customer;
+use WC_Order;
+use Woocommerce\Pagarme\Helper\Utils;
+use Woocommerce\Pagarme\Model\Config;
use Woocommerce\Pagarme\Model\Customer as PagarmeCustomer;
-use Pagarme\Core\Payment\Aggregates\Payments\BoletoPayment;
-use Pagarme\Core\Kernel\Interfaces\PlatformInvoiceInterface;
-use Pagarme\Core\Payment\Aggregates\Payments\AbstractPayment;
-use Pagarme\Core\Payment\Aggregates\Payments\NewVoucherPayment;
-use Pagarme\Core\Payment\Aggregates\Payments\NewDebitCardPayment;
-use Pagarme\Core\Kernel\Abstractions\AbstractPlatformOrderDecorator;
-use Pagarme\Core\Payment\Aggregates\Payments\AbstractCreditCardPayment;
-use Pagarme\Core\Payment\Repositories\CustomerRepository as CoreCustomerRepository;
+use Woocommerce\Pagarme\Model\Order;
+use Woocommerce\Pagarme\Model\Payment as WCModelPayment;
class WoocommercePlatformOrderDecorator extends AbstractPlatformOrderDecorator
{
@@ -56,19 +59,19 @@ class WoocommercePlatformOrderDecorator extends AbstractPlatformOrderDecorator
public function __construct($formData = null, $paymentMethod = null)
{
- $this->i18n = new LocalizationService();
- $this->formData = $formData;
+ $this->i18n = new LocalizationService();
+ $this->formData = $formData;
$this->paymentMethod = $this->formatPaymentMethod($paymentMethod);
- $this->orderService = new OrderService();
+ $this->orderService = new OrderService();
parent::__construct();
}
private function formatPaymentMethod($paymentMethod)
{
- if(empty($paymentMethod)){
+ if (empty($paymentMethod)) {
return "";
}
- $paymentMethodParts = explode('_', $paymentMethod);
+ $paymentMethodParts = explode('_', $paymentMethod);
$formatedPaymentMethod = '';
foreach ($paymentMethodParts as $part) {
@@ -98,14 +101,14 @@ public function setStateAfterLog(OrderState $state)
public function getState()
{
$statusToState = [
- 'pending' => 'stateNew',
- 'paid' => 'complete',
- 'pending_payment' => 'pending_payment',
- 'failed' => 'closed',
- 'processing' => 'processing',
- 'on_hold' => 'holded',
- 'canceled' => 'canceled',
- 'refunded' => 'complete',
+ 'pending' => 'stateNew',
+ 'paid' => 'complete',
+ 'pending_payment' => 'pending_payment',
+ 'failed' => 'closed',
+ 'processing' => 'processing',
+ 'on_hold' => 'holded',
+ 'canceled' => 'canceled',
+ 'refunded' => 'complete',
'authentication_required' => 'processing'
];
@@ -121,7 +124,7 @@ private function getWoocommerceStatusFromCoreStatus($coreStatus)
{
$coreToWoocommerceStatus = array(
'canceled' => 'cancelled',
- 'pending' => 'on-hold'
+ 'pending' => 'on-hold'
);
return array_key_exists($coreStatus, $coreToWoocommerceStatus) ?
@@ -132,7 +135,7 @@ private function getCoreStatusFromWoocommerceStatus($woocommerceStatus)
{
$woocommerceToCoreStatus = array(
'cancelled' => 'canceled',
- 'on-hold' => 'pending'
+ 'on-hold' => 'pending'
);
return array_key_exists($woocommerceStatus, $woocommerceToCoreStatus) ?
@@ -141,11 +144,12 @@ private function getCoreStatusFromWoocommerceStatus($woocommerceStatus)
public function setStatusAfterLog(OrderStatus $status)
{
- $log = new LogService('Order', true);
- $stringCoreStatus = $status->getStatus();
+ $log = new LogService('Order', true);
+ $stringCoreStatus = $status->getStatus();
$stringWoocommerceStatus = $this->getWoocommerceStatusFromCoreStatus($stringCoreStatus);
if ($this->getPlatformOrder()->get_status() === 'completed') {
$log->info('Impediment to change the order status to ' . $status->getStatus() . '. Order is complete.');
+
return;
}
$order = new Order($this->getPlatformOrder()->get_id());
@@ -159,7 +163,8 @@ public function setStatusAfterLog(OrderStatus $status)
public function getStatus()
{
$woocommerceStatus = $this->getPlatformOrder()->get_status();
- $coreStatus = $this->getCoreStatusFromWoocommerceStatus($woocommerceStatus);
+ $coreStatus = $this->getCoreStatusFromWoocommerceStatus($woocommerceStatus);
+
return $coreStatus;
}
@@ -171,6 +176,7 @@ public function loadByIncrementId($incrementId)
/**
* @param string $message
+ *
* @return bool
*/
public function sendEmail($message)
@@ -181,6 +187,7 @@ public function sendEmail($message)
/**
* @param OrderStatus $orderStatus
+ *
* @return string
*/
public function getStatusLabel(OrderStatus $orderStatus)
@@ -200,6 +207,7 @@ protected function addMPHistoryComment($message, $notifyCustomer = false)
/**
* @param string $name
* @param string $value
+ *
* @return void
*/
public function setAdditionalInformation($name, $value)
@@ -209,6 +217,7 @@ public function setAdditionalInformation($name, $value)
/**
* @param Charge[] $charges
+ *
* @return array[['key' => value]]
*/
public function extractAdditionalChargeInformation(array $charges)
@@ -255,12 +264,14 @@ public function getBaseTaxAmount()
public function getTotalPaid()
{
$platformOrder = $this->getPlatformOrder();
+
return $platformOrder->is_paid() ? $platformOrder->get_total() : 0;
}
public function getTotalDue()
{
$platformOrder = $this->getPlatformOrder();
+
return !$platformOrder->is_paid() ? $platformOrder->get_total() : 0;
}
@@ -404,7 +415,7 @@ public function getCustomer()
if (!empty($this->customer)) {
return $this->customer;
}
-
+
$customerId = get_current_user_id();
if (!empty($this->getPlatformOrder()->get_user_id())) {
$customerId = $this->getPlatformOrder()->get_user_id() ?? null;
@@ -412,16 +423,19 @@ public function getCustomer()
if (!empty($customerId)) {
$customer = $this->getRegisteredCustomer($customerId);
$this->setCustomer($customer);
+
return $customer;
}
$customer = $this->getGuestCustomer();
$this->setCustomer($customer);
+
return $customer;
}
/**
* @param Customer $customer
+ *
* @return void
*/
public function setCustomer($customer)
@@ -431,22 +445,23 @@ public function setCustomer($customer)
/**
* @param PagarmeCustomer $pagarmeCustomer
+ *
* @return Customer
- * @throws \Exception
+ * @throws Exception
*/
private function getRegisteredCustomer($woocommerceCustomerId)
{
$order = new Order($this->getPlatformOrder()->get_id());
- $address = Utils::build_customer_address_from_order($order);
+ $address = Utils::build_customer_address_from_order($order);
$document = Utils::build_document_from_order($order);
- $phones = Utils::build_customer_phones_from_order($order);
- if(empty($document['value'])) {
- $customerPlatform = new \WC_Customer($woocommerceCustomerId);
+ $phones = Utils::build_customer_phones_from_order($order);
+ if (empty($document['value'])) {
+ $customerPlatform = new WC_Customer($woocommerceCustomerId);
$document['value'] = $customerPlatform->get_meta("billing_cpf") ??
- $customerPlatform->get_meta("billing_cnpj");
+ $customerPlatform->get_meta("billing_cnpj");
}
- $homeNumber = $phones["home_phone"]["complete_phone"];
+ $homeNumber = $phones["home_phone"]["complete_phone"];
$mobileNumber = $phones["mobile_phone"]["complete_phone"];
$customerRepository = new CoreCustomerRepository();
@@ -475,7 +490,7 @@ private function getRegisteredCustomer($woocommerceCustomerId)
$customer->setDocument($cleanDocument);
$customer->setType(CustomerType::individual());
- $homePhone = new Phone($homeNumber);
+ $homePhone = new Phone($homeNumber);
$mobilePhone = new Phone($mobileNumber);
$customer->setPhones(
@@ -491,17 +506,17 @@ private function getRegisteredCustomer($woocommerceCustomerId)
/**
* @return Customer
- * @throws \Exception
+ * @throws Exception
*/
private function getGuestCustomer()
{
$order = new Order($this->getPlatformOrder()->get_id());
- $address = Utils::build_customer_address_from_order($order);
+ $address = Utils::build_customer_address_from_order($order);
$document = Utils::build_document_from_order($order);
- $phones = Utils::build_customer_phones_from_order($order);
+ $phones = Utils::build_customer_phones_from_order($order);
- $homeNumber = $phones["home_phone"]["complete_phone"];
+ $homeNumber = $phones["home_phone"]["complete_phone"];
$mobileNumber = $phones["mobile_phone"]["complete_phone"];
$fullName = "{$order->billing_first_name} {$order->billing_last_name}";
@@ -524,7 +539,7 @@ private function getGuestCustomer()
$customer->setDocument($cleanDocument);
$customer->setType(CustomerType::individual());
- $homePhone = new Phone($homeNumber);
+ $homePhone = new Phone($homeNumber);
$mobilePhone = new Phone($mobileNumber);
$customer->setPhones(
@@ -540,14 +555,14 @@ private function getGuestCustomer()
/** @return Item[] */
public function getItemCollection()
{
- $moneyService = new MoneyService();
+ $moneyService = new MoneyService();
$itemCollection = $this->getPlatformOrder()->get_items();
foreach ($itemCollection as $woocommerceItem) {
//adjusting price.
$woocommerceProduct = $woocommerceItem->get_product();
- $price = $woocommerceProduct->get_price();
- $price = $price > 0 ? $price : "0.01";
+ $price = $woocommerceProduct->get_price();
+ $price = $price > 0 ? $price : "0.01";
if ($price === null) {
continue;
@@ -563,7 +578,7 @@ public function getItemCollection()
}
$itemQuantity = absint($woocommerceItem['qty']);
- $itemName = sanitize_title($woocommerceItem['name']);
+ $itemName = sanitize_title($woocommerceItem['name']);
$item->setQuantity($itemQuantity);
$item->setDescription(
@@ -574,6 +589,7 @@ public function getItemCollection()
$items[] = $item;
}
+
return $items;
}
@@ -600,10 +616,10 @@ public function getPaymentMethodCollection()
$payments = $this->getPaymentCollection();
if (empty($payments)) {
- $payment = new WCModelPayment($this->formData['payment_method']);
+ $payment = new WCModelPayment($this->formData['payment_method']);
$pagarmeCustomer = $this->getCustomer();
- $customer = new stdClass();
+ $customer = new stdClass();
$customer->id = $pagarmeCustomer->getPagarmeId() ?
$pagarmeCustomer->getPagarmeId()->getValue() : null;
@@ -622,25 +638,26 @@ public function getPaymentMethodCollection()
$paymentMethods = $paymentFactory->createFromJson(
json_encode($paymentData)
);
+
return $paymentMethods;
}
private function isBilletAndCreditCardPayment()
{
- $firstPaymentMethod = $this->paymentInformation[0]['payment_method'];
+ $firstPaymentMethod = $this->paymentInformation[0]['payment_method'];
$secondPaymentMethod = $this->paymentInformation[1]['payment_method'];
return ($firstPaymentMethod === 'boleto' && $secondPaymentMethod === 'credit_card')
- || ($firstPaymentMethod === 'credit_card' && $secondPaymentMethod === 'boleto');
+ || ($firstPaymentMethod === 'credit_card' && $secondPaymentMethod === 'boleto');
}
private function isTwoCreditCardPayment()
{
- $firstPaymentMethod = $this->paymentInformation[0]['payment_method'];
+ $firstPaymentMethod = $this->paymentInformation[0]['payment_method'];
$secondPaymentMethod = $this->paymentInformation[1]['payment_method'];
return $firstPaymentMethod === 'credit_card' &&
- $secondPaymentMethod === 'credit_card';
+ $secondPaymentMethod === 'credit_card';
}
private function isBilletPayment()
@@ -650,6 +667,7 @@ private function isBilletPayment()
}
$payment = $this->paymentInformation[0];
+
return $payment['payment_method'] === 'boleto';
}
@@ -660,6 +678,7 @@ private function isCreditCardPayment()
}
$payment = $this->paymentInformation[0];
+
return $payment['payment_method'] === 'credit_card';
}
@@ -670,6 +689,7 @@ private function isPixPayment()
}
$payment = $this->paymentInformation[0];
+
return $payment['payment_method'] === 'pix';
}
@@ -680,6 +700,7 @@ private function isVoucherPayment()
}
$payment = $this->paymentInformation[0];
+
return $payment['payment_method'] === 'voucher';
}
@@ -727,15 +748,15 @@ private function extractPaymentDataFromCreditCard(
if (!empty($this->formData['authentication'])) {
$authenticationFormData = $this->formData['authentication'];
- $authentication = new stdClass();
- $authentication->type = 'threed_secure';
+ $authentication = new stdClass();
+ $authentication->type = 'threed_secure';
$authentication->status = $authenticationFormData['trans_status'];
- $threeDSecure = new stdClass();
- $threeDSecure->mpi = 'pagarme';
+ $threeDSecure = new stdClass();
+ $threeDSecure->mpi = 'pagarme';
$threeDSecure->transactionId = $authenticationFormData['tds_server_trans_id'];
- $authentication->threeDSecure = $threeDSecure;
+ $authentication->threeDSecure = $threeDSecure;
$newPaymentData->authentication = $authentication;
}
@@ -781,15 +802,15 @@ private function extractBasePaymentData()
$customerId = $this->getCustomer()->getPagarmeId() ?
$this->getCustomer()->getPagarmeId()->getValue() : null;
- $brand = $this->formData["brand"];
+ $brand = $this->formData["brand"];
- $newPaymentData = new \stdClass();
- $newPaymentData->customerId = $customerId;
- $newPaymentData->brand = $brand;
- $newPaymentData->identifier = $identifier;
- $newPaymentData->installments = intval($this->formData["installments"]);
+ $newPaymentData = new stdClass();
+ $newPaymentData->customerId = $customerId;
+ $newPaymentData->brand = $brand;
+ $newPaymentData->identifier = $identifier;
+ $newPaymentData->installments = intval($this->formData["installments"]);
$newPaymentData->recurrenceCycle = $this->formData["recurrence_cycle"] ?? null;
- $newPaymentData->saveOnSuccess =
+ $newPaymentData->saveOnSuccess =
isset($this->formData["save_credit_card"]);
$amount = isset($this->formData["card_order_value"]) ?
@@ -814,7 +835,7 @@ private function extractBasePaymentData()
private function extractPaymentDataFromTwoCreditCards(&$paymentData)
{
$moneyService = new MoneyService();
- $indexes = ['', '2'];
+ $indexes = ['', '2'];
foreach ($indexes as $index) {
$identifier = null;
$customerId = $this->getCustomer()->getPagarmeId() ?
@@ -823,20 +844,20 @@ private function extractPaymentDataFromTwoCreditCards(&$paymentData)
$brand = null;
try {
$brand = strtolower($this->formData["brand{$index}"]);
- } catch (\Throwable $e) {
+ } catch (Throwable $e) {
}
$cardTokenFlag = empty($index) ? "pagarmetoken1" : "pagarmetoken2";
- $identifier = $this->formData[$cardTokenFlag];
+ $identifier = $this->formData[$cardTokenFlag];
if (empty($identifier) && isset($this->formData["card_id{$index}"])) {
$identifier = $this->formData["card_id{$index}"];
}
- $newPaymentData = new \stdClass();
- $newPaymentData->customerId = $customerId;
- $newPaymentData->identifier = $identifier;
- $newPaymentData->brand = $brand;
+ $newPaymentData = new stdClass();
+ $newPaymentData->customerId = $customerId;
+ $newPaymentData->identifier = $identifier;
+ $newPaymentData->brand = $brand;
$newPaymentData->installments = intval($this->formData["installments{$index}"]);
@@ -880,25 +901,25 @@ private function extractMultibuyerData(
$order = new Order($this->getPlatformOrder()->get_id());
$fields = [
- "multicustomer_{$paymentMethod}[name]" => "name",
- "multicustomer_{$paymentMethod}[email]" => "email",
- "multicustomer_{$paymentMethod}[cpf]" => "document",
- "multicustomer_{$paymentMethod}[street]" => "street",
- "multicustomer_{$paymentMethod}[number]" => "number",
+ "multicustomer_{$paymentMethod}[name]" => "name",
+ "multicustomer_{$paymentMethod}[email]" => "email",
+ "multicustomer_{$paymentMethod}[cpf]" => "document",
+ "multicustomer_{$paymentMethod}[street]" => "street",
+ "multicustomer_{$paymentMethod}[number]" => "number",
"multicustomer_{$paymentMethod}[neighborhood]" => "neighborhood",
- "multicustomer_{$paymentMethod}[complement]" => "complement",
- "multicustomer_{$paymentMethod}[city]" => "city",
- "multicustomer_{$paymentMethod}[state]" => "state",
- "multicustomer_{$paymentMethod}[zip_code]" => "zipCode"
+ "multicustomer_{$paymentMethod}[complement]" => "complement",
+ "multicustomer_{$paymentMethod}[city]" => "city",
+ "multicustomer_{$paymentMethod}[state]" => "state",
+ "multicustomer_{$paymentMethod}[zip_code]" => "zipCode"
];
- $multibuyer = new \stdClass();
+ $multibuyer = new stdClass();
- $phones = Utils::build_customer_phones_from_order($order);
- $homeNumber = $phones["home_phone"]["complete_phone"];
+ $phones = Utils::build_customer_phones_from_order($order);
+ $homeNumber = $phones["home_phone"]["complete_phone"];
$mobileNumber = $phones["mobile_phone"]["complete_phone"];
- $multibuyer->homePhone = $homeNumber;
+ $multibuyer->homePhone = $homeNumber;
$multibuyer->mobilePhone = $mobileNumber;
foreach ($fields as $key => $attribute) {
@@ -921,14 +942,14 @@ private function extractMultibuyerData(
private function extractPaymentDataFromBilletCreditcard(&$paymentData)
{
$moneyService = new MoneyService();
- $identifier = null;
- $customerId = $this->getCustomer()->getPagarmeId() ?
+ $identifier = null;
+ $customerId = $this->getCustomer()->getPagarmeId() ?
$this->getCustomer()->getPagarmeId()->getValue() : null;
$brand = null;
try {
$brand = strtolower($this->formData["brand"]);
- } catch (\Throwable $e) {
+ } catch (Throwable $e) {
}
$identifier = $this->formData['pagarmetoken1'];
@@ -937,10 +958,10 @@ private function extractPaymentDataFromBilletCreditcard(&$paymentData)
$identifier = $this->formData["card_id"];
}
- $newPaymentData = new \stdClass();
- $newPaymentData->identifier = $identifier;
- $newPaymentData->customerId = $customerId;
- $newPaymentData->brand = $brand;
+ $newPaymentData = new stdClass();
+ $newPaymentData->identifier = $identifier;
+ $newPaymentData->customerId = $customerId;
+ $newPaymentData->brand = $brand;
$newPaymentData->installments = intval($this->formData['installments']);
$newPaymentData->saveOnSuccess =
@@ -969,7 +990,7 @@ private function extractPaymentDataFromBilletCreditcard(&$paymentData)
//boleto
- $newPaymentData = new \stdClass();
+ $newPaymentData = new stdClass();
$amount = str_replace(
['.', ','],
@@ -996,9 +1017,9 @@ private function extractPaymentDataFromBilletCreditcard(&$paymentData)
private function extractPaymentDataFromBillet(&$paymentData)
{
- $moneyService = new MoneyService();
+ $moneyService = new MoneyService();
$billetDataIndex = BoletoPayment::getBaseCode();
- $newPaymentData = (object) $this->paymentInformation[0][$billetDataIndex];
+ $newPaymentData = (object) $this->paymentInformation[0][$billetDataIndex];
$amount = isset($this->formData["billet_value"]) ?
$this->formData["billet_value"] : $this->getGrandTotal();
@@ -1019,8 +1040,8 @@ private function extractPaymentDataFromBillet(&$paymentData)
private function extractPaymentDataFromPix(&$paymentData)
{
- $moneyService = new MoneyService();
- $newPaymentData = new \stdClass();
+ $moneyService = new MoneyService();
+ $newPaymentData = new stdClass();
$amount = $this->getGrandTotal();
@@ -1047,19 +1068,19 @@ private function extractPaymentDataFromVoucher(&$paymentData)
if (!$identifier) {
$identifier = $this->formData["card_id"];
}
- $newPaymentData = new \stdClass();
- $newPaymentData->customerId = $this->getCustomer()->getPagarmeId() ?
+ $newPaymentData = new stdClass();
+ $newPaymentData->customerId = $this->getCustomer()->getPagarmeId() ?
$this->getCustomer()->getPagarmeId()->getValue() : null;
- $newPaymentData->identifier = $identifier;
- $newPaymentData->brand = strtolower($this->formData["brand"]);
- $newPaymentData->installments = (int)1;
- $amount = isset($this->formData["card_order_value"]) ?
+ $newPaymentData->identifier = $identifier;
+ $newPaymentData->brand = strtolower($this->formData["brand"]);
+ $newPaymentData->installments = (int) 1;
+ $amount = isset($this->formData["card_order_value"]) ?
$this->formData["card_order_value"] :
$this->getGrandTotal() - $this->getBaseTaxAmount();
- $amount = number_format($amount, 2, '.', '');
- $amount = str_replace('.', '', $amount);
- $amount = str_replace(',', '', $amount);
- $newPaymentData->amount = $amount;
+ $amount = number_format($amount, 2, '.', '');
+ $amount = str_replace('.', '', $amount);
+ $amount = str_replace(',', '', $amount);
+ $newPaymentData->amount = $amount;
if ($this->formData["enable_multicustomers_voucher"]) {
$newPaymentData->customer = $this->extractMultibuyerData(
@@ -1067,7 +1088,7 @@ private function extractPaymentDataFromVoucher(&$paymentData)
);
}
- $voucherDataIndex = NewVoucherPayment::getBaseCode();
+ $voucherDataIndex = NewVoucherPayment::getBaseCode();
$newPaymentData->saveOnSuccess =
isset($this->formData["save_credit_card"]);
if (!isset($paymentData[$voucherDataIndex])) {
@@ -1075,6 +1096,7 @@ private function extractPaymentDataFromVoucher(&$paymentData)
}
$paymentData[$voucherDataIndex][] = $newPaymentData;
+
return $voucherDataIndex;
}
@@ -1126,6 +1148,28 @@ protected function getAddress($platformAddress)
return $address;
}
+ private function fieldNotSet($requiredField, $platformAddress)
+ {
+ $fieldIsNotSet = !array_key_exists($requiredField, $platformAddress)
+ || empty($platformAddress[$requiredField]);
+
+ if ($requiredField === 'number') {
+ $fieldIsNotSet = !array_key_exists($requiredField, $platformAddress)
+ || (
+ empty($platformAddress[$requiredField])
+ && (
+ $platformAddress[$requiredField] === null
+ || !is_numeric(trim($platformAddress[$requiredField]))
+ )
+ );
+ }
+
+ return $fieldIsNotSet;
+ }
+
+ /**
+ * @throws Exception
+ */
private function validateAddressFields($platformAddress)
{
$requiredFields = [
@@ -1139,24 +1183,10 @@ private function validateAddressFields($platformAddress)
];
foreach ($requiredFields as $requiredField) {
- $fieldIsNotSet = !array_key_exists($requiredField, $platformAddress)
- || empty($platformAddress[$requiredField]);
-
- if ($requiredField === 'number') {
- $fieldIsNotSet = !array_key_exists($requiredField, $platformAddress)
- || (
- empty($platformAddress[$requiredField])
- && (
- $platformAddress[$requiredField] === null
- || !is_numeric(trim($platformAddress[$requiredField]))
- )
- );
- }
-
- if ($fieldIsNotSet) {
- $message = "Missing $requiredField in customer address";
+ if ($this->fieldNotSet($requiredField, $platformAddress)) {
+ $message = "Missing $requiredField in customer address";
$ExceptionMessage = $this->i18n->getDashboard($message);
- $exception = new \Exception($ExceptionMessage);
+ $exception = new Exception($ExceptionMessage);
$log = new LogService('Order', true);
$log->exception($exception);
diff --git a/vendor/pagarme/ecommerce-module-core/src/Payment/Aggregates/Customer.php b/vendor/pagarme/ecommerce-module-core/src/Payment/Aggregates/Customer.php
index 707110df..eff97c21 100644
--- a/vendor/pagarme/ecommerce-module-core/src/Payment/Aggregates/Customer.php
+++ b/vendor/pagarme/ecommerce-module-core/src/Payment/Aggregates/Customer.php
@@ -2,12 +2,14 @@
namespace Pagarme\Core\Payment\Aggregates;
-use PagarmeCoreApiLib\Models\CreateCustomerRequest;
+use Exception;
use Pagarme\Core\Kernel\Abstractions\AbstractEntity;
use Pagarme\Core\Kernel\Services\LocalizationService;
use Pagarme\Core\Payment\Interfaces\ConvertibleToSDKRequestsInterface;
use Pagarme\Core\Payment\ValueObjects\CustomerPhones;
use Pagarme\Core\Payment\ValueObjects\CustomerType;
+use PagarmeCoreApiLib\Models\CreateCustomerRequest;
+use stdClass;
final class Customer extends AbstractEntity implements ConvertibleToSDKRequestsInterface
{
@@ -77,8 +79,9 @@ public function getEmail()
/**
* @param string $email
+ *
* @return Customer
- * @throws \Exception
+ * @throws Exception
*/
public function setEmail($email)
{
@@ -117,8 +120,9 @@ public function getDocument()
/**
* @param string $document
+ *
* @return Customer
- * @throws \Exception
+ * @throws Exception
*/
public function setDocument($document)
{
@@ -127,12 +131,12 @@ public function setDocument($document)
if (empty($this->document) && empty($this->getPagarmeId())) {
$inputName = $this->i18n->getDashboard('document');
- $message = $this->i18n->getDashboard(
+ $message = $this->i18n->getDashboard(
"The %s should not be empty!",
$inputName
);
- throw new \Exception($message, 400);
+ throw new Exception($message, 400);
}
return $this;
@@ -171,28 +175,28 @@ public function setAddress(?Address $address)
}
/**
- * 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()
{
- $obj = new \stdClass();
+ $obj = new stdClass();
$code = $this->code;
if ($code !== null) {
$obj->code = $code;
}
- $obj->name = $this->name;
- $obj->email = $this->email;
- $obj->phones = $this->phones;
- $obj->document = $this->document;
- $obj->type = $this->type;
- $obj->address = $this->address;
+ $obj->name = $this->name;
+ $obj->email = $this->email;
+ $obj->phones = $this->phones;
+ $obj->document = $this->document;
+ $obj->type = $this->type;
+ $obj->address = $this->address;
$obj->pagarmeId = $this->getPagarmeId();
return $obj;
@@ -203,22 +207,25 @@ public function getTypeValue()
if ($this->getType() !== null) {
return $this->getType()->getType();
}
+
return null;
}
public function getAddressToSDK()
{
if ($this->getAddress() !== null) {
- return $this->getAddress()->convertToSDKRequest();
+ return $this->getAddress()->convertToSDKRequest();
}
+
return null;
}
public function getPhonesToSDK()
{
if ($this->getPhones() !== null) {
- return $this->getPhones()->convertToSDKRequest();
+ return $this->getPhones()->convertToSDKRequest();
}
+
return null;
}
@@ -226,13 +233,13 @@ public function convertToSDKRequest()
{
$customerRequest = new CreateCustomerRequest();
- $customerRequest->code = $this->getCode();
- $customerRequest->name = $this->getName();
- $customerRequest->email = $this->getEmail();
+ $customerRequest->code = $this->getCode();
+ $customerRequest->name = $this->getName();
+ $customerRequest->email = $this->getEmail();
$customerRequest->document = $this->getDocument();
- $customerRequest->type = $this->getTypeValue();
- $customerRequest->address = $this->getAddressToSDK();
- $customerRequest->phones = $this->getPhonesToSDK();
+ $customerRequest->type = $this->getTypeValue();
+ $customerRequest->address = $this->getAddressToSDK();
+ $customerRequest->phones = $this->getPhonesToSDK();
return $customerRequest;
}
@@ -245,7 +252,7 @@ private function validateEmail($email)
"email"
);
- throw new \Exception($message, 400);
+ throw new Exception($message, 400);
}
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
@@ -254,7 +261,7 @@ private function validateEmail($email)
"email"
);
- throw new \Exception($message, 400);
+ throw new Exception($message, 400);
}
}