Refactor payment source to handle arbitrary types

This commit is contained in:
Emili Castells Guasch 2023-10-20 12:54:00 +02:00
parent 99d05ca44d
commit 518a1f4e4e
13 changed files with 59 additions and 287 deletions

View file

@ -144,10 +144,10 @@ class ApproveOrderEndpoint implements EndpointInterface {
$order = $this->api_endpoint->order( $data['order_id'] );
if ( $order->payment_source() && $order->payment_source()->card() ) {
if ( $order->payment_source() && $order->payment_source()->name() === 'card' ) {
if ( $this->settings->has( 'disable_cards' ) ) {
$disabled_cards = (array) $this->settings->get( 'disable_cards' );
$card = strtolower( $order->payment_source()->card()->brand() );
$card = strtolower( $order->payment_source()->properties()->brand ?? '' );
if ( 'master_card' === $card ) {
$card = 'mastercard';
}

View file

@ -115,7 +115,7 @@ trait ContextTrait {
}
$source = $order->payment_source();
if ( $source && $source->card() ) {
if ( $source && $source->name() === 'card' ) {
return false; // Ignore for DCC.
}

View file

@ -52,14 +52,14 @@ class ThreeDSecure {
if ( ! $order->payment_source() ) {
return self::NO_DECISION;
}
if ( ! $order->payment_source()->card() ) {
if ( ! $order->payment_source()->properties()->brand ?? '' ) {
return self::NO_DECISION;
}
if ( ! $order->payment_source()->card()->authentication_result() ) {
if ( ! $order->payment_source()->properties()->authentication_result ?? '' ) {
return self::NO_DECISION;
}
$result = $order->payment_source()->card()->authentication_result();
$result = $order->payment_source()->properties()->authentication_result;
$this->logger->info( '3DS authentication result: ' . wc_print_r( $result->to_array(), true ) );
if ( $result->liability_shift() === AuthResult::LIABILITY_SHIFT_POSSIBLE ) {