mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-07 19:54:15 +08:00
return true when capturing payment successful. minimize db requests
This commit is contained in:
parent
39e14c7c25
commit
4f5b6950e0
1 changed files with 26 additions and 23 deletions
|
@ -90,15 +90,17 @@ class WcGateway extends WcGatewayBase
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function captureAuthorizedPayment(\WC_Order $wcOrder): void
|
public function captureAuthorizedPayment(\WC_Order $wcOrder): bool
|
||||||
{
|
{
|
||||||
$result = $this->authorizedPayments->process($wcOrder);
|
$result = $this->authorizedPayments->process($wcOrder);
|
||||||
|
|
||||||
if ($result === AuthorizedPaymentsProcessor::INACCESSIBLE) {
|
if ($result === AuthorizedPaymentsProcessor::INACCESSIBLE) {
|
||||||
$this->notice->displayMessage(AuthorizeOrderActionNotice::NO_INFO);
|
$this->notice->displayMessage(AuthorizeOrderActionNotice::NO_INFO);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
if ($result === AuthorizedPaymentsProcessor::NOT_FOUND) {
|
if ($result === AuthorizedPaymentsProcessor::NOT_FOUND) {
|
||||||
$this->notice->displayMessage(AuthorizeOrderActionNotice::NOT_FOUND);
|
$this->notice->displayMessage(AuthorizeOrderActionNotice::NOT_FOUND);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($result === AuthorizedPaymentsProcessor::ALREADY_CAPTURED) {
|
if ($result === AuthorizedPaymentsProcessor::ALREADY_CAPTURED) {
|
||||||
|
@ -109,32 +111,33 @@ class WcGateway extends WcGatewayBase
|
||||||
'woocommerce-paypal-gateway'
|
'woocommerce-paypal-gateway'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$wcOrder->update_status('processing');
|
$wcOrder->set_status('processing');
|
||||||
$wcOrder->update_meta_data(self::CAPTURED_META_KEY, 'true');
|
|
||||||
// TODO investigate why save has to be called
|
|
||||||
$wcOrder->save();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->notice->displayMessage(AuthorizeOrderActionNotice::ALREADY_CAPTURED);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($result === AuthorizedPaymentsProcessor::FAILED) {
|
|
||||||
$this->notice->displayMessage(AuthorizeOrderActionNotice::FAILED);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($result === AuthorizedPaymentsProcessor::SUCCESSFUL) {
|
|
||||||
$wcOrder->add_order_note(
|
|
||||||
__(
|
|
||||||
'Payment successfully captured.',
|
|
||||||
'woocommerce-paypal-gateway'
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
$wcOrder->update_status('processing');
|
|
||||||
$wcOrder->update_meta_data(self::CAPTURED_META_KEY, 'true');
|
$wcOrder->update_meta_data(self::CAPTURED_META_KEY, 'true');
|
||||||
$wcOrder->save();
|
$wcOrder->save();
|
||||||
|
$this->notice->displayMessage(AuthorizeOrderActionNotice::ALREADY_CAPTURED);
|
||||||
$this->notice->displayMessage(AuthorizeOrderActionNotice::SUCCESS);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if ($result !== AuthorizedPaymentsProcessor::SUCCESSFUL) {
|
||||||
|
$this->notice->displayMessage(AuthorizeOrderActionNotice::FAILED);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$wcOrder->add_order_note(
|
||||||
|
__(
|
||||||
|
'Payment successfully captured.',
|
||||||
|
'woocommerce-paypal-gateway'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$wcOrder->set_status('processing');
|
||||||
|
$wcOrder->update_meta_data(self::CAPTURED_META_KEY, 'true');
|
||||||
|
$wcOrder->save();
|
||||||
|
|
||||||
|
$this->notice->displayMessage(AuthorizeOrderActionNotice::SUCCESS);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue