mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
small refactor of /AuthorizedPaymentsProcessor
This commit is contained in:
parent
80b129c92d
commit
6b8ed27283
1 changed files with 4 additions and 19 deletions
|
@ -87,24 +87,22 @@ class AuthorizedPaymentsProcessor
|
|||
|
||||
private function areAuthorizationToCapture(Authorization ...$authorizations): bool
|
||||
{
|
||||
$alreadyCapturedAuthorizations = $this->authorizationsWithCapturedStatus(...$authorizations);
|
||||
|
||||
return count($alreadyCapturedAuthorizations) !== count($authorizations);
|
||||
return (bool) count($this->authorizationsToCapture(...$authorizations));
|
||||
}
|
||||
|
||||
private function captureAuthorizations(Authorization ...$authorizations)
|
||||
{
|
||||
$uncapturedAuthorizations = $this->authorizationsWithCreatedStatus(...$authorizations);
|
||||
|
||||
$uncapturedAuthorizations = $this->authorizationsToCapture(...$authorizations);
|
||||
foreach ($uncapturedAuthorizations as $authorization) {
|
||||
$this->paymentsEndpoint->capture($authorization->id());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Authorization ...$authorizations
|
||||
* @return Authorization[]
|
||||
*/
|
||||
private function authorizationsWithCreatedStatus(Authorization ...$authorizations): array
|
||||
private function authorizationsToCapture(Authorization ...$authorizations): array
|
||||
{
|
||||
return array_filter(
|
||||
$authorizations,
|
||||
|
@ -113,17 +111,4 @@ class AuthorizedPaymentsProcessor
|
|||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Authorization[]
|
||||
*/
|
||||
private function authorizationsWithCapturedStatus(Authorization ...$authorizations): array
|
||||
{
|
||||
return array_filter(
|
||||
$authorizations,
|
||||
static function (Authorization $authorization): bool {
|
||||
return $authorization->status()->is(AuthorizationStatus::CAPTURED);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue