Skip to content

Commit

Permalink
PT-13115 - Add handling for cards without authentication system. Show…
Browse files Browse the repository at this point in the history
… message to the customer.
  • Loading branch information
DennisGarding committed Jun 22, 2023
1 parent 3332128 commit 24ec54e
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

/**
* (c) shopware AG <info@shopware.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace SwagPaymentPayPalUnified\Components\Services\ThreeDSecureResultChecker\Exception;

use Exception;

class ThreeDSecureCardHasNoAuthorization extends Exception
{
/**
* @param int $code
*/
public function __construct($code)
{
$message = 'Card has no 3D authentication system.';

parent::__construct($message, $code);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ final class ThreeDSecureExceptionDescription
*/
const STATUS_CODE___UNKNOWN = 1008;

/**
* The card has no authentication system (3DSecure)
*/
const STATUS_CODE_NO_3DSECURE = 1009;

private function __construct()
{
}
Expand Down Expand Up @@ -116,6 +121,8 @@ public static function getDescriptionByCode($code)
return 'System is unavailable at the time of the request. The 3D authentication system is not available.';
case self::STATUS_CODE___UNKNOWN:
return 'The 3D authentication system is not available.';
case self::STATUS_CODE_NO_3DSECURE:
return 'Card has no 3D authentication system.';
default:
return 'Code not Available.';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use SwagPaymentPayPalUnified\Components\Services\ThreeDSecureResultChecker\Exception\ThreeDSecureAuthorizationCanceledException;
use SwagPaymentPayPalUnified\Components\Services\ThreeDSecureResultChecker\Exception\ThreeDSecureAuthorizationFailedException;
use SwagPaymentPayPalUnified\Components\Services\ThreeDSecureResultChecker\Exception\ThreeDSecureAuthorizationRejectedException;
use SwagPaymentPayPalUnified\Components\Services\ThreeDSecureResultChecker\Exception\ThreeDSecureCardHasNoAuthorization;
use SwagPaymentPayPalUnified\Components\Services\ThreeDSecureResultChecker\Exception\ThreeDSecureExceptionDescription;
use SwagPaymentPayPalUnified\PayPalBundle\V2\Api\Order;
use SwagPaymentPayPalUnified\PayPalBundle\V2\Api\Order\PaymentSource;
Expand Down Expand Up @@ -148,7 +149,7 @@ private function getStatus(Order $payPalOrder)
$threeDSecure = $this->get3DSecure($payPalOrder);

if (!$threeDSecure instanceof ThreeDSecure) {
$threeDSecure = new ThreeDSecure();
throw new ThreeDSecureCardHasNoAuthorization(ThreeDSecureExceptionDescription::STATUS_CODE_NO_3DSECURE);
}

return new ThreeDSecureResultStatus(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use SwagPaymentPayPalUnified\Components\Services\ThreeDSecureResultChecker\Exception\ThreeDSecureAuthorizationCanceledException;
use SwagPaymentPayPalUnified\Components\Services\ThreeDSecureResultChecker\Exception\ThreeDSecureAuthorizationFailedException;
use SwagPaymentPayPalUnified\Components\Services\ThreeDSecureResultChecker\Exception\ThreeDSecureAuthorizationRejectedException;
use SwagPaymentPayPalUnified\Components\Services\ThreeDSecureResultChecker\Exception\ThreeDSecureCardHasNoAuthorization;
use SwagPaymentPayPalUnified\Components\Services\ThreeDSecureResultChecker\ThreeDSecureResultChecker;
use SwagPaymentPayPalUnified\Controllers\Frontend\AbstractPaypalPaymentController;
use SwagPaymentPayPalUnified\Controllers\Frontend\Exceptions\InstrumentDeclinedException;
Expand Down Expand Up @@ -174,6 +175,14 @@ public function captureAction()

$this->paymentControllerHelper->handleError($this, $redirectDataBuilder);

return;
} catch (ThreeDSecureCardHasNoAuthorization $hasNoAuthorizationException) {
$redirectDataBuilder = $this->redirectDataBuilderFactory->createRedirectDataBuilder()
->setCode($hasNoAuthorizationException->getCode())
->setException($hasNoAuthorizationException, 'captureAction: No ThreeDSecure');

$this->paymentControllerHelper->handleError($this, $redirectDataBuilder);

return;
} catch (Exception $exception) {
$redirectDataBuilder = $this->redirectDataBuilderFactory->createRedirectDataBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ error/threeDSecure/1001 = "The security check failed. Check your entries and try
error/threeDSecure/1002 = "The security check was rejected. Check your entries and try again"
error/threeDSecure/1003 = "It is currently not possible to complete the security check of your credit card. The system is not available. Please try again later or choose another payment method."
error/threeDSecure/1006 = "Your credit card has been declined. This decision is based on an automated data process. Please choose another payment method"
error/threeDSecure/1009 = "The payment could not be made because your card does not have an authentication procedure. Please use another card or select another payment method."
error/pui/phoneNumberError = "Please enter a valid phone number."
error/pui/birthdateError = "Please enter a valid date for your date of birth."
error/apm/code18 = "Sorry, we could not complete the payment, please contact the store manager."
Expand Down Expand Up @@ -56,6 +57,7 @@ error/threeDSecure/1001 = "Die Sicherheitsüberprüfung Ihrer Kreditkarte ist fe
error/threeDSecure/1002 = "Die Sicherheitsüberprüfung Ihrer Kreditkarte wurde abgelehnt. Überprüfen Sie Ihre Eingaben und versuchen Sie es erneut."
error/threeDSecure/1003 = "Es ist zur Zeit nicht möglich die Sicherheitsüberprüfung Ihrer Kreditkarte abzuschließen. Das System ist nicht erreichbar. Bitte versuchen Sie es später erneut oder wählen Sie eine andere Zahlungsart."
error/threeDSecure/1006 = "Ihre Kreditkarte wurde abgelehnt. Diese Entscheidung basiert auf einem automatisierten Datenverarbeitungsverfahren. Bitte wählen Sie eine andere Zahlungsart"
error/threeDSecure/1009 = "Die Zahlung konnte nicht durchgeführt werden, da ihre Karte nicht über ein Authentifizierungsverfahren verfügt. Bitte nehmen Sie eine andere Karte oder wählen Sie eine Andere Zahlungsart."
error/pui/phoneNumberError = "Bitte geben Sie eine gültige Telefonnummer an."
error/pui/birthdateError = "Bitte geben Sie einen gültiges Datum für ihr Geburtsdatum an."
error/apm/code18 = "Entschuldigung, die Zahlung konnte leider nicht abgeschlossen werden. Bitte kontaktieren Sie den Shopbetreiber."
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
|| $paypalUnifiedErrorCode === 1007
|| $paypalUnifiedErrorCode === 1008}
{include file='frontend/_includes/messages.tpl' type='error' content="{s name="error/threeDSecure/1003" namespace="frontend/paypal_unified/checkout/messages"}{/s}"}
{elseif $paypalUnifiedErrorCode === 1009}
{include file='frontend/_includes/messages.tpl' type='error' content="{s name="error/threeDSecure/1009" namespace="frontend/paypal_unified/checkout/messages"}{/s}"}
{else}
{* Unknown error *}
{include file='frontend/_includes/messages.tpl' type='error' content="{s name="error/unknown"}An unknown error occurred while processing the payment.{/s}"}
Expand Down
2 changes: 1 addition & 1 deletion Subscriber/AdvancedCreditDebitCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ private function createCardHolderData($userData)
return $cardHolderData;
}

$cardHolderData['contingencies'] = ['SCA_WHEN_REQUIRED'];
$cardHolderData['contingencies'] = ['SCA_ALWAYS'];

return $cardHolderData;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function testcheckStaus(Order $payPalOrder, $expectResult, $expectedExcep

if (\method_exists($this, 'expectExceptionMessageMatches')) {
$this->expectExceptionMessageMatches(
'/^.* REASON: ' . ThreeDSecureExceptionDescription::getDescriptionByCode($expectedExceptionCode) . '.*$/'
'/^.*' . ThreeDSecureExceptionDescription::getDescriptionByCode($expectedExceptionCode) . '.*$/'
);
}
}
Expand Down Expand Up @@ -183,6 +183,17 @@ public function checkStausTestDataProvider()
false,
ThreeDSecureExceptionDescription::STATUS_CODE___UNKNOWN,
];

yield 'Test case 14 No 3DSecure result' => [
$this->createPayPalOrder(
'ANY',
'ANY',
'ANY',
false
),
false,
ThreeDSecureExceptionDescription::STATUS_CODE_NO_3DSECURE,
];
}

/**
Expand Down Expand Up @@ -347,18 +358,21 @@ private function createPayPalOrderForPrivateMethods(
* @param string $enrollmentStatus
* @param string $authenticationStatus
* @param string $liabilityShift
* @param bool $has3DResult
*
* @return Order
*/
private function createPayPalOrder($enrollmentStatus, $authenticationStatus, $liabilityShift)
private function createPayPalOrder($enrollmentStatus, $authenticationStatus, $liabilityShift, $has3DResult = true)
{
$threeDSecure = new ThreeDSecure();
$threeDSecure->setEnrollmentStatus($enrollmentStatus);
$threeDSecure->setAuthenticationStatus($authenticationStatus);

$authenticationResult = new AuthenticationResult();
$authenticationResult->setLiabilityShift($liabilityShift);
$authenticationResult->setThreeDSecure($threeDSecure);
if ($has3DResult) {
$authenticationResult->setThreeDSecure($threeDSecure);
}

$card = new Card();
$card->setAuthenticationResult($authenticationResult);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,32 +150,45 @@ public function captureActionCheckThreeDSecureStatusTestDataProvider()
ThreeDSecureExceptionDescription::STATUS_CODE___UNKNOWN,
];

yield 'Test case 8 unknown status' => [
yield 'Test case 9 unknown status' => [
$this->createPayPalOrder(
'ANY',
'ANY',
'ANY'
),
ThreeDSecureExceptionDescription::STATUS_CODE_DEFAULT,
];

yield 'Test case 10 No 3DSecure result' => [
$this->createPayPalOrder(
'ANY',
'ANY',
'ANY',
false
),
ThreeDSecureExceptionDescription::STATUS_CODE_NO_3DSECURE,
];
}

/**
* @param string $enrollmentStatus
* @param string $authenticationStatus
* @param string $liabilityShift
* @param bool $has3DResult
*
* @return Order
*/
private function createPayPalOrder($enrollmentStatus, $authenticationStatus, $liabilityShift)
private function createPayPalOrder($enrollmentStatus, $authenticationStatus, $liabilityShift, $has3DResult = true)
{
$threeDSecure = new ThreeDSecure();
$threeDSecure->setEnrollmentStatus($enrollmentStatus);
$threeDSecure->setAuthenticationStatus($authenticationStatus);

$authenticationResult = new AuthenticationResult();
$authenticationResult->setLiabilityShift($liabilityShift);
$authenticationResult->setThreeDSecure($threeDSecure);
if ($has3DResult) {
$authenticationResult->setThreeDSecure($threeDSecure);
}

$card = new Card();
$card->setAuthenticationResult($authenticationResult);
Expand Down

0 comments on commit 24ec54e

Please sign in to comment.