We will work on Apr 26th (Saturday) and will be off from Apr 30th (Wednesday) until May 2nd (Friday) for public holiday in our country

Commit 731bbdbc authored by acampos1916's avatar acampos1916

Fix for code smells

parent 1dc9d21c
...@@ -133,61 +133,64 @@ class VaultDetailsHandler implements HandlerInterface ...@@ -133,61 +133,64 @@ class VaultDetailsHandler implements HandlerInterface
*/ */
private function getVaultPaymentToken(array $response, $payment) private function getVaultPaymentToken(array $response, $payment)
{ {
$paymentToken = null;
if (!empty($response['additionalData'])) { if (empty($response['additionalData'])) {
$additionalData = $response['additionalData']; return null;
}
$additionalData = $response['additionalData'];
foreach (self::ADDITIONAL_DATA_ERRORS as $key => $errorMsg) { $paymentToken = null;
if (empty($additionalData[$key])) {
$this->adyenLogger->error($errorMsg); foreach (self::ADDITIONAL_DATA_ERRORS as $key => $errorMsg) {
return null; if (empty($additionalData[$key])) {
} $this->adyenLogger->error($errorMsg);
return null;
} }
}
try { try {
// Check if paymentToken exists already // Check if paymentToken exists already
$paymentToken = $this->paymentTokenManagement->getByGatewayToken($additionalData[self::RECURRING_DETAIL_REFERENCE], $paymentToken = $this->paymentTokenManagement->getByGatewayToken($additionalData[self::RECURRING_DETAIL_REFERENCE],
$payment->getMethodInstance()->getCode(), $payment->getOrder()->getCustomerId()); $payment->getMethodInstance()->getCode(), $payment->getOrder()->getCustomerId());
$paymentTokenSaveRequired = false; $paymentTokenSaveRequired = false;
// In case the payment token does not exist, create it based on the additionalData // In case the payment token does not exist, create it based on the additionalData
if (is_null($paymentToken)) { if (is_null($paymentToken)) {
/** @var PaymentTokenInterface $paymentToken */ /** @var PaymentTokenInterface $paymentToken */
$paymentToken = $this->paymentTokenFactory->create( $paymentToken = $this->paymentTokenFactory->create(
PaymentTokenFactoryInterface::TOKEN_TYPE_CREDIT_CARD PaymentTokenFactoryInterface::TOKEN_TYPE_CREDIT_CARD
); );
$paymentToken->setGatewayToken($additionalData[self::RECURRING_DETAIL_REFERENCE]); $paymentToken->setGatewayToken($additionalData[self::RECURRING_DETAIL_REFERENCE]);
if (strpos($additionalData[self::PAYMENT_METHOD], "paywithgoogle") !== false if (strpos($additionalData[self::PAYMENT_METHOD], "paywithgoogle") !== false
&& !empty($additionalData['paymentMethodVariant'])) { && !empty($additionalData['paymentMethodVariant'])) {
$additionalData[self::PAYMENT_METHOD] = $additionalData['paymentMethodVariant']; $additionalData[self::PAYMENT_METHOD] = $additionalData['paymentMethodVariant'];
$paymentToken->setIsVisible(false); $paymentToken->setIsVisible(false);
}
} else {
$paymentTokenSaveRequired = true;
} }
} else {
$paymentTokenSaveRequired = true;
}
$paymentToken->setExpiresAt($this->getExpirationDate($additionalData[self::EXPIRY_DATE])); $paymentToken->setExpiresAt($this->getExpirationDate($additionalData[self::EXPIRY_DATE]));
$details = [ $details = [
'type' => $additionalData[self::PAYMENT_METHOD], 'type' => $additionalData[self::PAYMENT_METHOD],
'maskedCC' => $additionalData[self::CARD_SUMMARY], 'maskedCC' => $additionalData[self::CARD_SUMMARY],
'expirationDate' => $additionalData[self::EXPIRY_DATE] 'expirationDate' => $additionalData[self::EXPIRY_DATE]
]; ];
$paymentToken->setTokenDetails(json_encode($details)); $paymentToken->setTokenDetails(json_encode($details));
// If the token is updated, it needs to be saved to keep the changes // If the token is updated, it needs to be saved to keep the changes
if ($paymentTokenSaveRequired) { if ($paymentTokenSaveRequired) {
$this->paymentTokenRepository->save($paymentToken); $this->paymentTokenRepository->save($paymentToken);
}
} catch (\Exception $e) {
$this->adyenLogger->error(print_r($e, true));
} }
} catch (\Exception $e) {
$this->adyenLogger->error(print_r($e, true));
} }
return $paymentToken; return $paymentToken;
...@@ -198,8 +201,10 @@ class VaultDetailsHandler implements HandlerInterface ...@@ -198,8 +201,10 @@ class VaultDetailsHandler implements HandlerInterface
* @return string * @return string
* @throws \Exception * @throws \Exception
*/ */
private function getExpirationDate($expirationDate) private
{ function getExpirationDate(
$expirationDate
) {
$expirationDate = explode('/', $expirationDate); $expirationDate = explode('/', $expirationDate);
//add leading zero to month //add leading zero to month
...@@ -226,8 +231,10 @@ class VaultDetailsHandler implements HandlerInterface ...@@ -226,8 +231,10 @@ class VaultDetailsHandler implements HandlerInterface
* @param InfoInterface $payment * @param InfoInterface $payment
* @return OrderPaymentExtensionInterface * @return OrderPaymentExtensionInterface
*/ */
private function getExtensionAttributes(InfoInterface $payment) private
{ function getExtensionAttributes(
InfoInterface $payment
) {
$extensionAttributes = $payment->getExtensionAttributes(); $extensionAttributes = $payment->getExtensionAttributes();
if (null === $extensionAttributes) { if (null === $extensionAttributes) {
$extensionAttributes = $this->paymentExtensionFactory->create(); $extensionAttributes = $this->paymentExtensionFactory->create();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment