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-09-11 13:38:02 +03:00
|
|
|
const NO_DECISION = 0;
|
|
|
|
const PROCCEED = 1;
|
|
|
|
const REJECT = 2;
|
|
|
|
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-09-01 09:00:45 +03:00
|
|
|
if ( ! $order->payment_source() ) {
|
2020-08-27 11:08:36 +03:00
|
|
|
return self::NO_DECISION;
|
|
|
|
}
|
2020-09-01 09:00:45 +03:00
|
|
|
if ( ! $order->payment_source()->card() ) {
|
2020-08-27 11:08:36 +03:00
|
|
|
return self::NO_DECISION;
|
|
|
|
}
|
2020-09-01 09:00:45 +03:00
|
|
|
if ( ! $order->payment_source()->card()->authentication_result() ) {
|
2020-08-27 11:08:36 +03:00
|
|
|
return self::NO_DECISION;
|
|
|
|
}
|
2020-09-01 09:00:45 +03:00
|
|
|
$result = $order->payment_source()->card()->authentication_result();
|
|
|
|
if ( $result->liability_shift() === AuthResult::LIABILITY_SHIFT_POSSIBLE ) {
|
2020-08-27 11:08:36 +03:00
|
|
|
return self::PROCCEED;
|
|
|
|
}
|
2020-07-15 10:27:40 +03:00
|
|
|
|
2020-09-01 09:00:45 +03:00
|
|
|
if ( $result->liability_shift() === AuthResult::LIABILITY_SHIFT_UNKNOWN ) {
|
2020-08-27 11:08:36 +03:00
|
|
|
return self::RETRY;
|
|
|
|
}
|
2020-09-01 09:00:45 +03:00
|
|
|
if ( $result->liability_shift() === 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 (
|
2020-09-01 09:00:45 +03:00
|
|
|
$result->enrollment_status() === AuthResult::ENROLLMENT_STATUS_BYPASS
|
|
|
|
&& ! $result->authentication_result()
|
2020-08-27 11:08:36 +03:00
|
|
|
) {
|
|
|
|
return self::PROCCEED;
|
|
|
|
}
|
|
|
|
if (
|
2020-09-01 09:00:45 +03:00
|
|
|
$result->enrollment_status() === AuthResult::ENROLLMENT_STATUS_UNAVAILABLE
|
|
|
|
&& ! $result->authentication_result()
|
2020-08-27 11:08:36 +03:00
|
|
|
) {
|
|
|
|
return self::PROCCEED;
|
|
|
|
}
|
|
|
|
if (
|
2020-09-01 09:00:45 +03:00
|
|
|
$result->enrollment_status() === AuthResult::ENROLLMENT_STATUS_NO
|
|
|
|
&& ! $result->authentication_result()
|
2020-08-27 11:08:36 +03:00
|
|
|
) {
|
|
|
|
return self::PROCCEED;
|
|
|
|
}
|
2020-07-15 10:27:40 +03:00
|
|
|
|
2020-09-01 09:00:45 +03:00
|
|
|
if ( $result->authentication_result() === AuthResult::AUTHENTICATION_RESULT_REJECTED ) {
|
2020-08-27 11:08:36 +03:00
|
|
|
return self::REJECT;
|
|
|
|
}
|
2020-07-15 10:27:40 +03:00
|
|
|
|
2020-09-01 09:00:45 +03:00
|
|
|
if ( $result->authentication_result() === AuthResult::AUTHENTICATION_RESULT_NO ) {
|
2020-08-27 11:08:36 +03:00
|
|
|
return self::REJECT;
|
|
|
|
}
|
2020-07-15 10:27:40 +03:00
|
|
|
|
2020-09-01 09:00:45 +03:00
|
|
|
if ( $result->authentication_result() === AuthResult::AUTHENTICATION_RESULT_UNABLE ) {
|
2020-08-27 11:08:36 +03:00
|
|
|
return self::RETRY;
|
|
|
|
}
|
|
|
|
|
2020-09-01 09:00:45 +03:00
|
|
|
if ( ! $result->authentication_result() ) {
|
2020-08-27 11:08:36 +03:00
|
|
|
return self::RETRY;
|
|
|
|
}
|
|
|
|
return self::NO_DECISION;
|
|
|
|
}
|
2020-07-15 10:27:40 +03:00
|
|
|
}
|