mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-08-31 06:52:50 +08:00
Introduce payment capture denied webhook (WIP)
This commit is contained in:
parent
abf61a14b8
commit
2b8281e0f4
3 changed files with 83 additions and 2 deletions
|
@ -20,6 +20,7 @@ use WooCommerce\PayPalCommerce\Webhooks\Endpoint\SimulationStateEndpoint;
|
|||
use WooCommerce\PayPalCommerce\Webhooks\Handler\CheckoutOrderApproved;
|
||||
use WooCommerce\PayPalCommerce\Webhooks\Handler\CheckoutOrderCompleted;
|
||||
use WooCommerce\PayPalCommerce\Webhooks\Handler\PaymentCaptureCompleted;
|
||||
use WooCommerce\PayPalCommerce\Webhooks\Handler\PaymentCaptureDenied;
|
||||
use WooCommerce\PayPalCommerce\Webhooks\Handler\PaymentCapturePending;
|
||||
use WooCommerce\PayPalCommerce\Webhooks\Handler\PaymentCaptureRefunded;
|
||||
use WooCommerce\PayPalCommerce\Webhooks\Handler\PaymentCaptureReversed;
|
||||
|
@ -80,6 +81,7 @@ return array(
|
|||
new VaultPaymentTokenCreated( $logger, $prefix, $authorized_payments_processor ),
|
||||
new VaultCreditCardCreated( $logger, $prefix ),
|
||||
new PaymentCapturePending( $logger ),
|
||||
new PaymentCaptureDenied($logger),
|
||||
);
|
||||
},
|
||||
|
||||
|
|
81
modules/ppcp-webhooks/src/Handler/PaymentCaptureDenied.php
Normal file
81
modules/ppcp-webhooks/src/Handler/PaymentCaptureDenied.php
Normal file
|
@ -0,0 +1,81 @@
|
|||
<?php
|
||||
/**
|
||||
* Handles the Webhook PAYMENT.CAPTURE.DENIED
|
||||
*
|
||||
* @package WooCommerce\PayPalCommerce\Webhooks\Handler
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Webhooks\Handler;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use WP_REST_Request;
|
||||
use WP_REST_Response;
|
||||
|
||||
class PaymentCaptureDenied implements RequestHandler
|
||||
{
|
||||
|
||||
/**
|
||||
* The logger.
|
||||
*
|
||||
* @var LoggerInterface
|
||||
*/
|
||||
protected $logger;
|
||||
|
||||
/**
|
||||
* PaymentCaptureDenied constructor.
|
||||
*
|
||||
* @param LoggerInterface $logger
|
||||
*/
|
||||
public function __construct(LoggerInterface $logger)
|
||||
{
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* The event types a handler handles.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function event_types(): array
|
||||
{
|
||||
return array( 'PAYMENT.CAPTURE.DENIED' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether a handler is responsible for a given request or not.
|
||||
*
|
||||
* @param \WP_REST_Request $request The request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function responsible_for_request(WP_REST_Request $request): bool
|
||||
{
|
||||
return in_array( $request['event_type'], $this->event_types(), true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Responsible for handling the request.
|
||||
*
|
||||
* @param \WP_REST_Request $request The request.
|
||||
*
|
||||
* @return WP_REST_Response
|
||||
*/
|
||||
public function handle_request(WP_REST_Request $request): WP_REST_Response
|
||||
{
|
||||
$response = array( 'success' => false );
|
||||
$resource = $request['resource'];
|
||||
if ( ! is_array( $resource ) ) {
|
||||
$message = 'Resource data not found in webhook request.';
|
||||
$this->logger->warning( $message, array( 'request' => $request ) );
|
||||
$response['message'] = $message;
|
||||
return new WP_REST_Response( $response );
|
||||
}
|
||||
|
||||
$this->logger->info( (string) wc_print_r( $resource, true ) );
|
||||
|
||||
$response['success'] = true;
|
||||
return new WP_REST_Response( $response );
|
||||
}
|
||||
}
|
|
@ -74,8 +74,6 @@ class PaymentCapturePending implements RequestHandler {
|
|||
return new WP_REST_Response( $response );
|
||||
}
|
||||
|
||||
$this->logger->info( (string) wc_print_r( $resource, true ) );
|
||||
|
||||
$order_id = isset( $request['resource']['custom_id'] )
|
||||
? $this->sanitize_custom_id( $request['resource']['custom_id'] )
|
||||
: 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue