mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Get wc customer id by removing prefix
This commit is contained in:
parent
78286b0542
commit
6ebe8d3171
1 changed files with 14 additions and 20 deletions
|
@ -12,8 +12,8 @@ namespace WooCommerce\PayPalCommerce\Webhooks\Handler;
|
|||
use Psr\Log\LoggerInterface;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Processor\AuthorizedPaymentsProcessor;
|
||||
|
||||
class VaultPaymentTokenCreated implements RequestHandler
|
||||
{
|
||||
class VaultPaymentTokenCreated implements RequestHandler {
|
||||
|
||||
/**
|
||||
* @var LoggerInterface
|
||||
*/
|
||||
|
@ -29,43 +29,37 @@ class VaultPaymentTokenCreated implements RequestHandler
|
|||
*/
|
||||
protected $authorized_payments_processor;
|
||||
|
||||
public function __construct(LoggerInterface $logger, string $prefix, AuthorizedPaymentsProcessor $authorized_payments_processor)
|
||||
{
|
||||
$this->logger = $logger;
|
||||
$this->prefix = $prefix;
|
||||
public function __construct( LoggerInterface $logger, string $prefix, AuthorizedPaymentsProcessor $authorized_payments_processor ) {
|
||||
$this->logger = $logger;
|
||||
$this->prefix = $prefix;
|
||||
$this->authorized_payments_processor = $authorized_payments_processor;
|
||||
}
|
||||
|
||||
public function event_types(): array
|
||||
{
|
||||
public function event_types(): array {
|
||||
return array(
|
||||
'VAULT.PAYMENT-TOKEN.CREATED',
|
||||
);
|
||||
}
|
||||
|
||||
public function responsible_for_request(\WP_REST_Request $request): bool
|
||||
{
|
||||
public function responsible_for_request( \WP_REST_Request $request ): bool {
|
||||
return in_array( $request['event_type'], $this->event_types(), true );
|
||||
}
|
||||
|
||||
public function handle_request(\WP_REST_Request $request): \WP_REST_Response
|
||||
{
|
||||
$response = array( 'success' => false );
|
||||
$webhook_id = (string) ( $request['id'] ?? '' );
|
||||
public function handle_request( \WP_REST_Request $request ): \WP_REST_Response {
|
||||
$response = array( 'success' => false );
|
||||
|
||||
$customer_id = $request['resource']['customer_id'] ?? '';
|
||||
if(!$customer_id) {
|
||||
$message = sprintf( 'No customer id for webhook event %s was found.', $webhook_id );
|
||||
if ( ! $customer_id ) {
|
||||
$message = 'No customer id was found.';
|
||||
$this->logger->warning( $message, array( 'request' => $request ) );
|
||||
$response['message'] = $message;
|
||||
return new \WP_REST_Response( $response );
|
||||
}
|
||||
|
||||
$customer_id_parts = explode('-', $customer_id);
|
||||
$wc_customer_id = (int) end($customer_id_parts);
|
||||
$this->authorized_payments_processor->capture_authorized_payments_for_customer($wc_customer_id);
|
||||
$wc_customer_id = (int) str_replace( $this->prefix, '', $customer_id );
|
||||
$this->authorized_payments_processor->capture_authorized_payments_for_customer( $wc_customer_id );
|
||||
|
||||
$response['success'] = true;
|
||||
return rest_ensure_response($response);
|
||||
return rest_ensure_response( $response );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue