2020-07-15 10:27:40 +03:00
|
|
|
<?php
|
2020-08-31 11:12:46 +03:00
|
|
|
/**
|
|
|
|
* Helper class to determine how to proceed with an order depending on the 3d secure feedback.
|
|
|
|
*
|
|
|
|
* @package Inpsyde\PayPalCommerce\Button\Helper
|
|
|
|
*/
|
2020-07-15 10:27:40 +03:00
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Inpsyde\PayPalCommerce\Button\Helper;
|
|
|
|
|
2020-07-21 09:17:03 +03:00
|
|
|
use Inpsyde\PayPalCommerce\ApiClient\Entity\CardAuthenticationResult as AuthResult;
|
2020-07-15 10:27:40 +03:00
|
|
|
use Inpsyde\PayPalCommerce\ApiClient\Entity\Order;
|
|
|
|
|
2020-08-31 11:12:46 +03:00
|
|
|
/**
|
|
|
|
* Class ThreeDSecure
|
|
|
|
*/
|
2020-08-27 11:08:36 +03:00
|
|
|
class ThreeDSecure {
|
2020-07-15 10:27:40 +03:00
|
|
|
|
|
|
|
|
2020-08-27 11:08:36 +03:00
|
|
|
public const NO_DECISION = 0;
|
|
|
|
public const PROCCEED = 1;
|
|
|
|
public const REJECT = 2;
|
|
|
|
public const RETRY = 3;
|
2020-07-15 10:27:40 +03:00
|
|
|
|
2020-08-27 11:08:36 +03:00
|
|
|
/**
|
|
|
|
* Determine, how we proceed with a given order.
|
|
|
|
*
|
|
|
|
* @link https://developer.paypal.com/docs/business/checkout/add-capabilities/3d-secure/#authenticationresult
|
2020-08-31 11:12:46 +03:00
|
|
|
*
|
|
|
|
* @param Order $order The order for which the decission is needed.
|
|
|
|
*
|
2020-08-27 11:08:36 +03:00
|
|
|
* @return int
|
|
|
|
*/
|
2020-08-31 11:12:46 +03:00
|
|
|
public function proceed_with_order( Order $order ): int {
|
2020-08-27 11:08:36 +03:00
|
|
|
if ( ! $order->paymentSource() ) {
|
|
|
|
return self::NO_DECISION;
|
|
|
|
}
|
|
|
|
if ( ! $order->paymentSource()->card() ) {
|
|
|
|
return self::NO_DECISION;
|
|
|
|
}
|
|
|
|
if ( ! $order->paymentSource()->card()->authenticationResult() ) {
|
|
|
|
return self::NO_DECISION;
|
|
|
|
}
|
|
|
|
$result = $order->paymentSource()->card()->authenticationResult();
|
|
|
|
if ( $result->liabilityShift() === AuthResult::LIABILITY_SHIFT_POSSIBLE ) {
|
|
|
|
return self::PROCCEED;
|
|
|
|
}
|
2020-07-15 10:27:40 +03:00
|
|
|
|
2020-08-27 11:08:36 +03:00
|
|
|
if ( $result->liabilityShift() === AuthResult::LIABILITY_SHIFT_UNKNOWN ) {
|
|
|
|
return self::RETRY;
|
|
|
|
}
|
|
|
|
if ( $result->liabilityShift() === AuthResult::LIABILITY_SHIFT_NO ) {
|
2020-08-31 11:12:46 +03:00
|
|
|
return $this->no_liability_shift( $result );
|
2020-08-27 11:08:36 +03:00
|
|
|
}
|
|
|
|
return self::NO_DECISION;
|
|
|
|
}
|
2020-07-15 10:27:40 +03:00
|
|
|
|
2020-08-27 11:08:36 +03:00
|
|
|
/**
|
2020-08-31 11:12:46 +03:00
|
|
|
* Determines how to proceed depending on the Liability Shift.
|
|
|
|
*
|
|
|
|
* @param AuthResult $result The AuthResult object based on which we make the decision.
|
|
|
|
*
|
2020-08-27 11:08:36 +03:00
|
|
|
* @return int
|
|
|
|
*/
|
2020-08-31 11:12:46 +03:00
|
|
|
private function no_liability_shift( AuthResult $result ): int {
|
2020-07-15 10:27:40 +03:00
|
|
|
|
2020-08-27 11:08:36 +03:00
|
|
|
if (
|
|
|
|
$result->enrollmentStatus() === AuthResult::ENROLLMENT_STATUS_BYPASS
|
|
|
|
&& ! $result->authenticationResult()
|
|
|
|
) {
|
|
|
|
return self::PROCCEED;
|
|
|
|
}
|
|
|
|
if (
|
|
|
|
$result->enrollmentStatus() === AuthResult::ENROLLMENT_STATUS_UNAVAILABLE
|
|
|
|
&& ! $result->authenticationResult()
|
|
|
|
) {
|
|
|
|
return self::PROCCEED;
|
|
|
|
}
|
|
|
|
if (
|
|
|
|
$result->enrollmentStatus() === AuthResult::ENROLLMENT_STATUS_NO
|
|
|
|
&& ! $result->authenticationResult()
|
|
|
|
) {
|
|
|
|
return self::PROCCEED;
|
|
|
|
}
|
2020-07-15 10:27:40 +03:00
|
|
|
|
2020-08-27 11:08:36 +03:00
|
|
|
if ( $result->authenticationResult() === AuthResult::AUTHENTICATION_RESULT_REJECTED ) {
|
|
|
|
return self::REJECT;
|
|
|
|
}
|
2020-07-15 10:27:40 +03:00
|
|
|
|
2020-08-27 11:08:36 +03:00
|
|
|
if ( $result->authenticationResult() === AuthResult::AUTHENTICATION_RESULT_NO ) {
|
|
|
|
return self::REJECT;
|
|
|
|
}
|
2020-07-15 10:27:40 +03:00
|
|
|
|
2020-08-27 11:08:36 +03:00
|
|
|
if ( $result->authenticationResult() === AuthResult::AUTHENTICATION_RESULT_UNABLE ) {
|
|
|
|
return self::RETRY;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! $result->authenticationResult() ) {
|
|
|
|
return self::RETRY;
|
|
|
|
}
|
|
|
|
return self::NO_DECISION;
|
|
|
|
}
|
2020-07-15 10:27:40 +03:00
|
|
|
}
|