diff --git a/composer.json b/composer.json index 9219d50..0bb4aaf 100644 --- a/composer.json +++ b/composer.json @@ -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" @@ -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": { diff --git a/src/Kernel/Aggregates/Configuration.php b/src/Kernel/Aggregates/Configuration.php index 7447277..f31fdab 100644 --- a/src/Kernel/Aggregates/Configuration.php +++ b/src/Kernel/Aggregates/Configuration.php @@ -101,6 +101,9 @@ final class Configuration extends AbstractEntity /** @var AddressAttributes */ private $addressAttributes; + /** @var bool */ + private $allowNoAddress; + /** @var string */ private $cardStatementDescriptor; @@ -178,6 +181,7 @@ final class Configuration extends AbstractEntity public function __construct() { + $this->allowNoAddress = false; $this->saveCards = false; $this->saveVoucherCards = false; $this->multiBuyer = false; @@ -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 */ @@ -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(), diff --git a/src/Kernel/Factories/ConfigurationFactory.php b/src/Kernel/Factories/ConfigurationFactory.php index 445840c..3ff694d 100644 --- a/src/Kernel/Factories/ConfigurationFactory.php +++ b/src/Kernel/Factories/ConfigurationFactory.php @@ -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); @@ -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; @@ -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)) { @@ -215,7 +215,7 @@ public function createFromJsonData($json) if (!empty($data->voucherConfig)) { $config->setVoucherConfig( (new VoucherConfigFactory) - ->createFromDbData($data->voucherConfig) + ->createFromDbData($data->voucherConfig) ); } @@ -232,6 +232,10 @@ public function createFromJsonData($json) ); } + if (!empty($data->allowNoAddress)) { + $config->setAllowNoAddress($data->allowNoAddress); + } + if (!empty($data->marketplaceConfig)) { $config->setMarketplaceConfig( (new MarketplaceConfigFactory()) @@ -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) { @@ -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) { } @@ -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) { } @@ -298,7 +304,7 @@ private function createSecretKey($key) /** * - * @param array $dbData + * @param array $dbData * @return AbstractEntity */ public function createFromDbData($dbData) diff --git a/src/Kernel/Log/BlurData.php b/src/Kernel/Log/BlurData.php index 0510242..b577a63 100644 --- a/src/Kernel/Log/BlurData.php +++ b/src/Kernel/Log/BlurData.php @@ -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; } @@ -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; } diff --git a/src/Kernel/Services/LocalizationService.php b/src/Kernel/Services/LocalizationService.php index 6aa843e..0fa5af5 100644 --- a/src/Kernel/Services/LocalizationService.php +++ b/src/Kernel/Services/LocalizationService.php @@ -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(); diff --git a/src/Kernel/Services/LogService.php b/src/Kernel/Services/LogService.php index 39e3e6d..19e3085 100644 --- a/src/Kernel/Services/LogService.php +++ b/src/Kernel/Services/LogService.php @@ -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; } @@ -187,7 +187,9 @@ private function blurSensitiveData($logObject) } } return $logObject; - } catch (\Exception $e) {} + } catch (\Exception $e) { + $this->exception($e); + } } /** diff --git a/src/Kernel/Services/OrderLogService.php b/src/Kernel/Services/OrderLogService.php index 73ea0fc..600b412 100644 --- a/src/Kernel/Services/OrderLogService.php +++ b/src/Kernel/Services/OrderLogService.php @@ -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); } } diff --git a/src/Kernel/Services/OrderService.php b/src/Kernel/Services/OrderService.php index b100e80..ee1431e 100644 --- a/src/Kernel/Services/OrderService.php +++ b/src/Kernel/Services/OrderService.php @@ -243,13 +243,6 @@ 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()); @@ -257,6 +250,11 @@ public function createOrderAtPagarme(PlatformOrderInterface $platformOrder) //build PaymentOrder based on platformOrder $paymentOrder = $this->extractPaymentOrderFromPlatformOrder($platformOrder); + $this->logService->orderInfo( + $platformOrder->getCode(), + 'Creating order.', + $paymentOrder + ); $i18n = new LocalizationService(); @@ -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); @@ -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. " . @@ -326,7 +324,7 @@ public function createOrderAtPagarme(PlatformOrderInterface $platformOrder) $this->logService->orderInfo( $platformOrder->getCode(), $e->getMessage(), - $orderInfo + $paymentOrder ); $exceptionHandler = new ErrorExceptionHandler(); $paymentOrder = new PaymentOrder(); @@ -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. @@ -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); } @@ -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']) || diff --git a/src/Middle/Client.php b/src/Middle/Client.php index e464499..9943cc4 100644 --- a/src/Middle/Client.php +++ b/src/Middle/Client.php @@ -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() diff --git a/src/Middle/Proxy/TdsTokenProxy.php b/src/Middle/Proxy/TdsTokenProxy.php new file mode 100644 index 0000000..3f91f3d --- /dev/null +++ b/src/Middle/Proxy/TdsTokenProxy.php @@ -0,0 +1,28 @@ +client = $auth->services(); + } + + public function getTdsToken($environment, $accountId) + { + return $this->client->getTdsToken()->getToken( + $environment, + $accountId + ); + } + +} diff --git a/src/Payment/Aggregates/Customer.php b/src/Payment/Aggregates/Customer.php index 66c49c4..707110d 100644 --- a/src/Payment/Aggregates/Customer.php +++ b/src/Payment/Aggregates/Customer.php @@ -165,7 +165,7 @@ public function getAddress() /** * @param Address $address */ - public function setAddress(Address $address) + public function setAddress(?Address $address) { $this->address = $address; } diff --git a/src/Payment/Aggregates/Order.php b/src/Payment/Aggregates/Order.php index 5fba2ce..c78e285 100644 --- a/src/Payment/Aggregates/Order.php +++ b/src/Payment/Aggregates/Order.php @@ -2,6 +2,8 @@ namespace Pagarme\Core\Payment\Aggregates; +use Pagarme\Core\Payment\Aggregates\Payments\AbstractCreditCardPayment; +use Pagarme\Core\Payment\Aggregates\Payments\Authentication\AuthenticationStatusEnum; use PagarmeCoreApiLib\Models\CreateOrderRequest; use Pagarme\Core\Kernel\Abstractions\AbstractEntity; use Pagarme\Core\Kernel\Services\LocalizationService; @@ -119,6 +121,7 @@ public function getPayments() public function addPayment(AbstractPayment $payment) { $this->validatePaymentInvariants($payment); + $this->addAdditionalSettingsForPaymentInvariants($payment); $this->blockOverPaymentAttempt($payment); $payment->setOrder($this); @@ -235,6 +238,37 @@ private function validateSavedCreditCardPayment(SavedCreditCardPayment $payment) } } + /** + * @param AbstractPayment $payment + * @return void + */ + private function addAdditionalSettingsForPaymentInvariants(AbstractPayment $payment) + { + $parentClass = get_parent_class($payment); + + if ($parentClass === AbstractCreditCardPayment::class) { + $this->addThreeDSAntiFraudInfo($payment); + } + } + + /** + * @param AbstractCreditCardPayment $payment + * @return void + */ + private function addThreeDSAntiFraudInfo(AbstractCreditCardPayment $payment) + { + $authentication = $payment->getAuthentication(); + if (empty($authentication)) { + return; + } + + $antiFraudEnabled = true; + if (in_array($authentication->getStatus(), AuthenticationStatusEnum::doesNotNeedToUseAntifraudStatuses())) { + $antiFraudEnabled = false; + } + $this->setAntifraudEnabled($antiFraudEnabled); + } + /** * @return bool */ @@ -372,7 +406,7 @@ private function fixRoundedValuesInCharges(&$orderRequest){ } $orderSplitData = $this->getSplitData(); - + $wrongValuesPerRecipient = $this->getRecipientWrongValuesMap($orderRequest, $orderSplitData); if (!$wrongValuesPerRecipient){ @@ -380,7 +414,7 @@ private function fixRoundedValuesInCharges(&$orderRequest){ } $orderRequest = $this->fixRoundedValues($wrongValuesPerRecipient, $orderRequest); - + return $orderRequest; } @@ -395,7 +429,7 @@ private function getRecipientWrongValuesMap($orderRequest, $splitData){ $sellerId = $sellerData['pagarmeId']; $sellerCommission = $sellerData['commission']; - $map[$sellerId] = $sellerCommission; + $map[$sellerId] = $sellerCommission; } diff --git a/src/Payment/Aggregates/Payments/AbstractCreditCardPayment.php b/src/Payment/Aggregates/Payments/AbstractCreditCardPayment.php index 0383a24..c2fcf17 100644 --- a/src/Payment/Aggregates/Payments/AbstractCreditCardPayment.php +++ b/src/Payment/Aggregates/Payments/AbstractCreditCardPayment.php @@ -2,6 +2,7 @@ namespace Pagarme\Core\Payment\Aggregates\Payments; +use Pagarme\Core\Payment\Aggregates\Payments\Authentication\Authentication; use PagarmeCoreApiLib\Models\CreateCardRequest; use PagarmeCoreApiLib\Models\CreateCreditCardPaymentRequest; use Pagarme\Core\Kernel\Abstractions\AbstractModuleCoreSetup as MPSetup; @@ -12,6 +13,7 @@ use Pagarme\Core\Kernel\ValueObjects\CardBrand; use Pagarme\Core\Payment\ValueObjects\AbstractCardIdentifier; use Pagarme\Core\Payment\ValueObjects\PaymentMethod; +use PagarmeCoreApiLib\Models\CreatePaymentAuthenticationRequest; abstract class AbstractCreditCardPayment extends AbstractPayment { @@ -27,6 +29,8 @@ abstract class AbstractCreditCardPayment extends AbstractPayment protected $capture; /** @var AbstractCardIdentifier */ protected $identifier; + /** @var Authentication|null */ + protected $authentication; public function __construct() @@ -193,6 +197,31 @@ public function setBrand(CardBrand $brand) $this->brand = $brand; } + /** + * @return Authentication|null + */ + public function getAuthentication() + { + return $this->authentication; + } + + /** + * @param Authentication $authentication + * @return void + */ + public function setAuthentication($authentication) + { + $this->authentication = $authentication; + } + + /** + * @return CreatePaymentAuthenticationRequest + */ + public function getAuthenticationSDK() + { + return $this->authentication->convertToSDKRequest(); + } + #[\ReturnTypeWillChange] public function jsonSerialize() { @@ -203,6 +232,9 @@ public function jsonSerialize() $obj->statementDescriptor = $this->statementDescriptor; $obj->capture = $this->capture; $obj->identifier = $this->identifier; + if (!empty($this->authentication)) { + $obj->authentication = $this->authentication; + } return $obj; } @@ -231,6 +263,9 @@ protected function convertToPrimitivePaymentRequest() $cardRequest->installments = $this->getInstallments(); $cardRequest->recurrenceCycle = $this->getRecurrenceCycle(); $cardRequest->statementDescriptor = $this->getStatementDescriptor(); + if (!empty($this->getAuthentication())) { + $cardRequest->authentication = $this->getAuthenticationSDK(); + } return $cardRequest; } diff --git a/src/Payment/Aggregates/Payments/Authentication/Authentication.php b/src/Payment/Aggregates/Payments/Authentication/Authentication.php new file mode 100644 index 0000000..7ba150f --- /dev/null +++ b/src/Payment/Aggregates/Payments/Authentication/Authentication.php @@ -0,0 +1,137 @@ +type; + } + + /** + * @param string $type + * @return void + */ + public function setType(string $type) + { + $this->type = $type; + } + + /** + * @return ThreeDSecure + */ + public function getThreeDSecure() + { + return $this->threeDSecure; + } + + /** + * @param ThreeDSecure $threeDSecure + * @return void + */ + public function setThreeDSecure(ThreeDSecure $threeDSecure) + { + $this->threeDSecure = $threeDSecure; + } + + /** + * @return string + */ + public function getStatus() + { + return $this->status; + } + + /** + * @param string $status + * @return void + */ + public function setStatus(string $status) + { + $this->status = $status; + } + + /** + * @return CreateThreeDSecureRequest + */ + public function getThreeDSecureSDK() + { + return $this->threeDSecure->convertToSDKRequest(); + } + + /** + * @return CreatePaymentAuthenticationRequest + */ + public function convertToSDKRequest() + { + $authenticationRequest = new CreatePaymentAuthenticationRequest(); + $authenticationRequest->type = $this->getType(); + if (self::isThreeDSecureType($this)) { + $authenticationRequest->threedSecure = $this->getThreeDSecureSDK(); + } + return $authenticationRequest; + } + + /** + * @return mixed + */ + #[\ReturnTypeWillChange] + public function jsonSerialize() + { + $obj = parent::jsonSerialize(); + + $obj->type = $this->getType(); + $obj->transactionId = $this->getThreeDSecure(); + return $obj; + } + + /** + * @param stdClass $object + * @return self + */ + public static function createFromStdClass(stdClass $object) + { + $authentication = new self(); + $authentication->setType($object->type); + $authentication->setStatus($object->status); + if (self::isThreeDSecureType($authentication)) { + $authentication->setThreeDSecure(ThreeDSecure::createFromStdClass($object->threeDSecure)); + } + return $authentication; + } + + /** + * @param Authentication $authentication + * @return bool + */ + private static function isThreeDSecureType(Authentication $authentication) + { + return $authentication->getType() === ThreeDSecure::TYPE; + } +} diff --git a/src/Payment/Aggregates/Payments/Authentication/AuthenticationStatusEnum.php b/src/Payment/Aggregates/Payments/Authentication/AuthenticationStatusEnum.php new file mode 100644 index 0000000..831680c --- /dev/null +++ b/src/Payment/Aggregates/Payments/Authentication/AuthenticationStatusEnum.php @@ -0,0 +1,80 @@ +mpi; + } + + /** + * @param string $mpi + * @return void + */ + public function setMpi(string $mpi) + { + $this->mpi = $mpi; + } + + /** + * @return string + */ + public function getTransactionId() + { + return $this->transactionId; + } + + /** + * @param string $transactionId + * @return void + */ + public function setTransactionId(string $transactionId) + { + $this->transactionId = $transactionId; + } + + /** + * @return CreateThreeDSecureRequest + */ + public function convertToSDKRequest() + { + $threeDSecureRequest = new CreateThreeDSecureRequest(); + $threeDSecureRequest->mpi = $this->getMpi(); + $threeDSecureRequest->transactionId = $this->getTransactionId(); + + return $threeDSecureRequest; + } + + /** + * @return mixed + */ + #[\ReturnTypeWillChange] + public function jsonSerialize() + { + $obj = parent::jsonSerialize(); + + $obj->mpi = $this->getMpi(); + $obj->transactionId = $this->getTransactionId(); + return $obj; + } + + /** + * @param stdClass $object + * @return self + */ + public static function createFromStdClass(stdClass $object) + { + $threeDSecure = new self(); + $threeDSecure->setMpi($object->mpi); + $threeDSecure->setTransactionId($object->transactionId); + return $threeDSecure; + } +} diff --git a/src/Payment/Aggregates/Shipping.php b/src/Payment/Aggregates/Shipping.php index 5947ab2..9e2ce69 100644 --- a/src/Payment/Aggregates/Shipping.php +++ b/src/Payment/Aggregates/Shipping.php @@ -80,7 +80,7 @@ public function getAddress() /** * @param Address $address */ - public function setAddress(Address $address) + public function setAddress(?Address $address) { $this->address = $address; } @@ -119,7 +119,9 @@ public function convertToSDKRequest() $shippingRequest->recipientPhone = $this->getRecipientPhone() ->getFullNumber(); - $shippingRequest->address = $this->getAddress()->convertToSDKRequest(); + if ($this->getAddress() !== null) { + $shippingRequest->address = $this->getAddress()->convertToSDKRequest(); + } return $shippingRequest; } diff --git a/src/Payment/Factories/PaymentFactory.php b/src/Payment/Factories/PaymentFactory.php index d90cef2..312835a 100644 --- a/src/Payment/Factories/PaymentFactory.php +++ b/src/Payment/Factories/PaymentFactory.php @@ -7,8 +7,8 @@ use Pagarme\Core\Kernel\Services\InstallmentService; use Pagarme\Core\Kernel\ValueObjects\CardBrand; use Pagarme\Core\Kernel\ValueObjects\Id\CustomerId; -use Pagarme\Core\Payment\Aggregates\Customer; use Pagarme\Core\Payment\Aggregates\Payments\AbstractCreditCardPayment; +use Pagarme\Core\Payment\Aggregates\Payments\Authentication\Authentication; use Pagarme\Core\Payment\Aggregates\Payments\BoletoPayment; use Pagarme\Core\Payment\Aggregates\Payments\NewCreditCardPayment; use Pagarme\Core\Payment\Aggregates\Payments\NewDebitCardPayment; @@ -19,7 +19,6 @@ use Pagarme\Core\Payment\ValueObjects\BoletoBank; use Pagarme\Core\Payment\ValueObjects\CardId; use Pagarme\Core\Payment\ValueObjects\CardToken; -use Pagarme\Core\Payment\ValueObjects\CustomerType; use Pagarme\Core\Payment\ValueObjects\PaymentMethod; use Pagarme\Core\Payment\Aggregates\Payments\SavedDebitCardPayment; @@ -127,6 +126,9 @@ private function createBasePayments( $payment->setAmount($cardData->amount); $payment->setInstallments($cardData->installments); $payment->setRecurrenceCycle($cardData->recurrenceCycle ?? null); + if (!empty($cardData->authentication)) { + $payment->setAuthentication(Authentication::createFromStdClass($cardData->authentication)); + } //setting amount with interest if (strcmp($cardDataIndex, \Pagarme\Core\Kernel\ValueObjects\PaymentMethod::VOUCHER)) { diff --git a/src/Recurrence/Aggregates/Subscription.php b/src/Recurrence/Aggregates/Subscription.php index 9b68a15..cefa8aa 100644 --- a/src/Recurrence/Aggregates/Subscription.php +++ b/src/Recurrence/Aggregates/Subscription.php @@ -516,7 +516,7 @@ public function applyOrderStatusFromCharges() $this->setStatus(SubscriptionStatus::$currentStatus()); } } - + /** * @param ChargeInterface[] $charges */ @@ -635,7 +635,7 @@ private function setCardData(CreateSubscriptionRequest $subscriptionRequest) } $card = new CreateCardRequest(); - if ($this->getCustomer()->getAddress() != null) { + if ($this->getCustomer()->getAddress() !== null) { $card->billingAddress = $this->getCustomer()->getAddress()->convertToSDKRequest(); } diff --git a/src/Recurrence/Services/SubscriptionService.php b/src/Recurrence/Services/SubscriptionService.php index 208ffd3..ac21b25 100644 --- a/src/Recurrence/Services/SubscriptionService.php +++ b/src/Recurrence/Services/SubscriptionService.php @@ -54,17 +54,16 @@ public function createSubscriptionAtPagarme(PlatformOrderInterface $platformOrde { try { $orderService = new OrderService(); - $orderInfo = $orderService->getOrderInfo($platformOrder); - $this->logService->orderInfo( - $platformOrder->getCode(), - 'Creating order.', - $orderInfo - ); $this->setPlatformOrderPending($platformOrder); //build PaymentOrder based on platformOrder $order = $orderService->extractPaymentOrderFromPlatformOrder($platformOrder); + $this->logService->orderInfo( + $platformOrder->getCode(), + 'Creating order.', + $order + ); $subscription = $this->extractSubscriptionDataFromOrder($order); $this->setDiscountCycleSubscription($subscription, $platformOrder);