mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
add order not found capture error message
This commit is contained in:
parent
a9e0cc0cf7
commit
1b9b206c14
3 changed files with 19 additions and 5 deletions
|
@ -78,19 +78,21 @@ class WcGateway extends WcGatewayBase implements WcGatewayInterface
|
|||
global $woocommerce;
|
||||
$wcOrder = new \WC_Order($orderId);
|
||||
|
||||
//ToDo: We need to fetch the order from paypal again to get it with the new status.
|
||||
|
||||
$order = $this->sessionHandler->order();
|
||||
$wcOrder->update_meta_data('_ppcp_paypal_order_id', $order->id());
|
||||
$wcOrder->update_meta_data('_ppcp_paypal_intent', $order->intent());
|
||||
|
||||
$errorMessage = null;
|
||||
if (!$order || !$order->status()->is(OrderStatus::APPROVED)) {
|
||||
$errorMessage = 'not approve yet';
|
||||
$errorMessage = __('The payment has not been approved yet.', 'woocommerce-paypal-gateway');
|
||||
}
|
||||
$errorMessage = null;
|
||||
if ($errorMessage) {
|
||||
wc_add_notice(__('Payment error:', 'woocommerce-paypal-gateway') . $errorMessage, 'error');
|
||||
$notice = sprintf(
|
||||
// translators %s is the message of the error.
|
||||
__('Payment error: %s', 'woocommerce-paypal-gateway'),
|
||||
$errorMessage
|
||||
);
|
||||
wc_add_notice( $notice, 'error');
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -123,6 +125,9 @@ class WcGateway extends WcGatewayBase implements WcGatewayInterface
|
|||
if ($result === 'INACCESSIBLE') {
|
||||
AuthorizeOrderActionNotice::displayMessage(AuthorizeOrderActionNotice::NO_INFO);
|
||||
}
|
||||
if ($result === 'NOT_FOUND') {
|
||||
AuthorizeOrderActionNotice::displayMessage(AuthorizeOrderActionNotice::NOT_FOUND);
|
||||
}
|
||||
|
||||
if ($result === 'ALREADY_CAPTURED') {
|
||||
if ($wcOrder->get_status() === 'on-hold') {
|
||||
|
|
|
@ -9,6 +9,7 @@ class AuthorizeOrderActionNotice
|
|||
const ALREADY_CAPTURED = 82;
|
||||
const FAILED = 83;
|
||||
const SUCCESS = 84;
|
||||
const NOT_FOUND = 85;
|
||||
|
||||
public function registerMessages(array $messages): array
|
||||
{
|
||||
|
@ -24,6 +25,10 @@ class AuthorizeOrderActionNotice
|
|||
'Failed to capture. Try again later.',
|
||||
'woocommerce-paypal-gateway'
|
||||
);
|
||||
$messages['shop_order'][self::NOT_FOUND] = __(
|
||||
'Could not find payment to process.',
|
||||
'woocommerce-paypal-gateway'
|
||||
);
|
||||
$messages['shop_order'][self::SUCCESS] = __(
|
||||
'Payment successfully captured.',
|
||||
'woocommerce-paypal-gateway'
|
||||
|
|
|
@ -17,6 +17,7 @@ class AuthorizedPaymentsProcessor
|
|||
public const ALREADY_CAPTURED = 'ALREADY_CAPTURED';
|
||||
public const FAILED = 'FAILED';
|
||||
public const INACCESSIBLE = 'INACCESSIBLE';
|
||||
public const NOT_FOUND = 'NOT_FOUND';
|
||||
private $orderEndpoint;
|
||||
private $paymentsEndpoint;
|
||||
|
||||
|
@ -35,6 +36,9 @@ class AuthorizedPaymentsProcessor
|
|||
try {
|
||||
$order = $this->getCurrentOrderInfo($orderId);
|
||||
} catch (Exception $exception) {
|
||||
if ($exception->getCode() === 404) {
|
||||
return self::NOT_FOUND;
|
||||
}
|
||||
return self::INACCESSIBLE;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue