mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
Extract is_voidable_authorization
This commit is contained in:
parent
b33e6b6ba2
commit
b0396489c9
3 changed files with 17 additions and 25 deletions
|
@ -61,6 +61,16 @@ class Authorization {
|
||||||
return $this->authorization_status;
|
return $this->authorization_status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether the authorization can be voided.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function is_voidable(): bool {
|
||||||
|
return $this->authorization_status->is( AuthorizationStatus::CREATED ) ||
|
||||||
|
$this->authorization_status->is( AuthorizationStatus::PENDING );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the object as array.
|
* Returns the object as array.
|
||||||
*
|
*
|
||||||
|
|
|
@ -206,7 +206,9 @@ trait ProcessPaymentTrait {
|
||||||
|
|
||||||
$voidable_authorizations = array_filter(
|
$voidable_authorizations = array_filter(
|
||||||
$payments->authorizations(),
|
$payments->authorizations(),
|
||||||
array( $this, 'is_voidable_authorization' )
|
function ( Authorization $authorization ): bool {
|
||||||
|
return $authorization->is_voidable();
|
||||||
|
}
|
||||||
);
|
);
|
||||||
if ( ! $voidable_authorizations ) {
|
if ( ! $voidable_authorizations ) {
|
||||||
throw new RuntimeException( 'No voidable authorizations.' );
|
throw new RuntimeException( 'No voidable authorizations.' );
|
||||||
|
@ -346,15 +348,4 @@ trait ProcessPaymentTrait {
|
||||||
* @return Environment
|
* @return Environment
|
||||||
*/
|
*/
|
||||||
abstract protected function environment(): Environment;
|
abstract protected function environment(): Environment;
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks whether the authorization can be voided.
|
|
||||||
*
|
|
||||||
* @param Authorization $authorization The authorization to check.
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
private function is_voidable_authorization( Authorization $authorization ): bool {
|
|
||||||
return $authorization->status()->is( AuthorizationStatus::CREATED ) ||
|
|
||||||
$authorization->status()->is( AuthorizationStatus::PENDING );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,7 +127,9 @@ class RefundProcessor {
|
||||||
case self::REFUND_MODE_VOID:
|
case self::REFUND_MODE_VOID:
|
||||||
$voidable_authorizations = array_filter(
|
$voidable_authorizations = array_filter(
|
||||||
$payments->authorizations(),
|
$payments->authorizations(),
|
||||||
array( $this, 'is_voidable_authorization' )
|
function ( Authorization $authorization ): bool {
|
||||||
|
return $authorization->is_voidable();
|
||||||
|
}
|
||||||
);
|
);
|
||||||
if ( ! $voidable_authorizations ) {
|
if ( ! $voidable_authorizations ) {
|
||||||
throw new RuntimeException( 'No voidable authorizations.' );
|
throw new RuntimeException( 'No voidable authorizations.' );
|
||||||
|
@ -163,7 +165,7 @@ class RefundProcessor {
|
||||||
$authorizations = $payments->authorizations();
|
$authorizations = $payments->authorizations();
|
||||||
if ( $authorizations ) {
|
if ( $authorizations ) {
|
||||||
foreach ( $authorizations as $authorization ) {
|
foreach ( $authorizations as $authorization ) {
|
||||||
if ( $this->is_voidable_authorization( $authorization ) ) {
|
if ( $authorization->is_voidable() ) {
|
||||||
return self::REFUND_MODE_VOID;
|
return self::REFUND_MODE_VOID;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -175,15 +177,4 @@ class RefundProcessor {
|
||||||
|
|
||||||
return self::REFUND_MODE_UNKNOWN;
|
return self::REFUND_MODE_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks whether the authorization can be voided.
|
|
||||||
*
|
|
||||||
* @param Authorization $authorization The authorization to check.
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
private function is_voidable_authorization( Authorization $authorization ): bool {
|
|
||||||
return $authorization->status()->is( AuthorizationStatus::CREATED ) ||
|
|
||||||
$authorization->status()->is( AuthorizationStatus::PENDING );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue