mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
Stop searching for prefix in custom IDs
we are not creating such IDs for 2 years already
This commit is contained in:
parent
eb4418931a
commit
8979c9e605
14 changed files with 26 additions and 104 deletions
|
@ -184,8 +184,7 @@ return array(
|
||||||
$state = $container->get( 'onboarding.state' );
|
$state = $container->get( 'onboarding.state' );
|
||||||
$order_processor = $container->get( 'wcgateway.order-processor' );
|
$order_processor = $container->get( 'wcgateway.order-processor' );
|
||||||
$session_handler = $container->get( 'session.handler' );
|
$session_handler = $container->get( 'session.handler' );
|
||||||
$prefix = $container->get( 'api.prefix' );
|
return new EarlyOrderHandler( $state, $order_processor, $session_handler );
|
||||||
return new EarlyOrderHandler( $state, $order_processor, $session_handler, $prefix );
|
|
||||||
},
|
},
|
||||||
'button.endpoint.approve-order' => static function ( ContainerInterface $container ): ApproveOrderEndpoint {
|
'button.endpoint.approve-order' => static function ( ContainerInterface $container ): ApproveOrderEndpoint {
|
||||||
$request_data = $container->get( 'button.request-data' );
|
$request_data = $container->get( 'button.request-data' );
|
||||||
|
|
|
@ -15,15 +15,12 @@ use WooCommerce\PayPalCommerce\Onboarding\State;
|
||||||
use WooCommerce\PayPalCommerce\Session\SessionHandler;
|
use WooCommerce\PayPalCommerce\Session\SessionHandler;
|
||||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
|
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
|
||||||
use WooCommerce\PayPalCommerce\WcGateway\Processor\OrderProcessor;
|
use WooCommerce\PayPalCommerce\WcGateway\Processor\OrderProcessor;
|
||||||
use WooCommerce\PayPalCommerce\Webhooks\Handler\PrefixTrait;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class EarlyOrderHandler
|
* Class EarlyOrderHandler
|
||||||
*/
|
*/
|
||||||
class EarlyOrderHandler {
|
class EarlyOrderHandler {
|
||||||
|
|
||||||
use PrefixTrait;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The State.
|
* The State.
|
||||||
*
|
*
|
||||||
|
@ -51,19 +48,16 @@ class EarlyOrderHandler {
|
||||||
* @param State $state The State.
|
* @param State $state The State.
|
||||||
* @param OrderProcessor $order_processor The Order Processor.
|
* @param OrderProcessor $order_processor The Order Processor.
|
||||||
* @param SessionHandler $session_handler The Session Handler.
|
* @param SessionHandler $session_handler The Session Handler.
|
||||||
* @param string $prefix The Prefix.
|
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
State $state,
|
State $state,
|
||||||
OrderProcessor $order_processor,
|
OrderProcessor $order_processor,
|
||||||
SessionHandler $session_handler,
|
SessionHandler $session_handler
|
||||||
string $prefix
|
|
||||||
) {
|
) {
|
||||||
|
|
||||||
$this->state = $state;
|
$this->state = $state;
|
||||||
$this->order_processor = $order_processor;
|
$this->order_processor = $order_processor;
|
||||||
$this->session_handler = $session_handler;
|
$this->session_handler = $session_handler;
|
||||||
$this->prefix = $prefix;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -101,7 +95,7 @@ class EarlyOrderHandler {
|
||||||
$order_id = false;
|
$order_id = false;
|
||||||
foreach ( $order->purchase_units() as $purchase_unit ) {
|
foreach ( $order->purchase_units() as $purchase_unit ) {
|
||||||
if ( $purchase_unit->custom_id() === sanitize_text_field( wp_unslash( $_REQUEST['ppcp-resume-order'] ) ) ) {
|
if ( $purchase_unit->custom_id() === sanitize_text_field( wp_unslash( $_REQUEST['ppcp-resume-order'] ) ) ) {
|
||||||
$order_id = (int) $this->sanitize_custom_id( $purchase_unit->custom_id() );
|
$order_id = (int) $purchase_unit->custom_id();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( $order_id === $resume_order_id ) {
|
if ( $order_id === $resume_order_id ) {
|
||||||
|
|
|
@ -938,11 +938,9 @@ return array(
|
||||||
'wcgateway.endpoint.return-url' => static function ( ContainerInterface $container ) : ReturnUrlEndpoint {
|
'wcgateway.endpoint.return-url' => static function ( ContainerInterface $container ) : ReturnUrlEndpoint {
|
||||||
$gateway = $container->get( 'wcgateway.paypal-gateway' );
|
$gateway = $container->get( 'wcgateway.paypal-gateway' );
|
||||||
$endpoint = $container->get( 'api.endpoint.order' );
|
$endpoint = $container->get( 'api.endpoint.order' );
|
||||||
$prefix = $container->get( 'api.prefix' );
|
|
||||||
return new ReturnUrlEndpoint(
|
return new ReturnUrlEndpoint(
|
||||||
$gateway,
|
$gateway,
|
||||||
$endpoint,
|
$endpoint,
|
||||||
$prefix,
|
|
||||||
$container->get( 'session.handler' ),
|
$container->get( 'session.handler' ),
|
||||||
$container->get( 'woocommerce.logger.woocommerce' )
|
$container->get( 'woocommerce.logger.woocommerce' )
|
||||||
);
|
);
|
||||||
|
|
|
@ -15,14 +15,12 @@ use WooCommerce\PayPalCommerce\ApiClient\Entity\OrderStatus;
|
||||||
use WooCommerce\PayPalCommerce\Session\SessionHandler;
|
use WooCommerce\PayPalCommerce\Session\SessionHandler;
|
||||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\OXXO\OXXOGateway;
|
use WooCommerce\PayPalCommerce\WcGateway\Gateway\OXXO\OXXOGateway;
|
||||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
|
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
|
||||||
use WooCommerce\PayPalCommerce\Webhooks\Handler\PrefixTrait;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class ReturnUrlEndpoint
|
* Class ReturnUrlEndpoint
|
||||||
*/
|
*/
|
||||||
class ReturnUrlEndpoint {
|
class ReturnUrlEndpoint {
|
||||||
|
|
||||||
use PrefixTrait;
|
|
||||||
const ENDPOINT = 'ppc-return-url';
|
const ENDPOINT = 'ppc-return-url';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -58,20 +56,17 @@ class ReturnUrlEndpoint {
|
||||||
*
|
*
|
||||||
* @param PayPalGateway $gateway The PayPal Gateway.
|
* @param PayPalGateway $gateway The PayPal Gateway.
|
||||||
* @param OrderEndpoint $order_endpoint The Order Endpoint.
|
* @param OrderEndpoint $order_endpoint The Order Endpoint.
|
||||||
* @param string $prefix The prefix.
|
|
||||||
* @param SessionHandler $session_handler The session handler.
|
* @param SessionHandler $session_handler The session handler.
|
||||||
* @param LoggerInterface $logger The logger.
|
* @param LoggerInterface $logger The logger.
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
PayPalGateway $gateway,
|
PayPalGateway $gateway,
|
||||||
OrderEndpoint $order_endpoint,
|
OrderEndpoint $order_endpoint,
|
||||||
string $prefix,
|
|
||||||
SessionHandler $session_handler,
|
SessionHandler $session_handler,
|
||||||
LoggerInterface $logger
|
LoggerInterface $logger
|
||||||
) {
|
) {
|
||||||
$this->gateway = $gateway;
|
$this->gateway = $gateway;
|
||||||
$this->order_endpoint = $order_endpoint;
|
$this->order_endpoint = $order_endpoint;
|
||||||
$this->prefix = $prefix;
|
|
||||||
$this->session_handler = $session_handler;
|
$this->session_handler = $session_handler;
|
||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
}
|
}
|
||||||
|
@ -90,7 +85,7 @@ class ReturnUrlEndpoint {
|
||||||
// phpcs:enable WordPress.Security.NonceVerification.Recommended
|
// phpcs:enable WordPress.Security.NonceVerification.Recommended
|
||||||
$order = $this->order_endpoint->order( $token );
|
$order = $this->order_endpoint->order( $token );
|
||||||
|
|
||||||
$wc_order_id = $this->sanitize_custom_id( $order->purchase_units()[0]->custom_id() );
|
$wc_order_id = (int) $order->purchase_units()[0]->custom_id();
|
||||||
if ( ! $wc_order_id ) {
|
if ( ! $wc_order_id ) {
|
||||||
// We cannot finish processing here without WC order, but at least go into the continuation mode.
|
// We cannot finish processing here without WC order, but at least go into the continuation mode.
|
||||||
if ( $order->status()->is( OrderStatus::APPROVED )
|
if ( $order->status()->is( OrderStatus::APPROVED )
|
||||||
|
|
|
@ -82,12 +82,12 @@ return array(
|
||||||
$payment_token_factory = $container->get( 'vaulting.payment-token-factory' );
|
$payment_token_factory = $container->get( 'vaulting.payment-token-factory' );
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
new CheckoutOrderApproved( $logger, $prefix, $order_endpoint ),
|
new CheckoutOrderApproved( $logger, $order_endpoint ),
|
||||||
new CheckoutOrderCompleted( $logger, $prefix ),
|
new CheckoutOrderCompleted( $logger ),
|
||||||
new CheckoutPaymentApprovalReversed( $logger ),
|
new CheckoutPaymentApprovalReversed( $logger ),
|
||||||
new PaymentCaptureRefunded( $logger, $prefix ),
|
new PaymentCaptureRefunded( $logger ),
|
||||||
new PaymentCaptureReversed( $logger, $prefix ),
|
new PaymentCaptureReversed( $logger ),
|
||||||
new PaymentCaptureCompleted( $logger, $prefix, $order_endpoint ),
|
new PaymentCaptureCompleted( $logger, $order_endpoint ),
|
||||||
new VaultPaymentTokenCreated( $logger, $prefix, $authorized_payments_processor, $payment_token_factory ),
|
new VaultPaymentTokenCreated( $logger, $prefix, $authorized_payments_processor, $payment_token_factory ),
|
||||||
new VaultPaymentTokenDeleted( $logger ),
|
new VaultPaymentTokenDeleted( $logger ),
|
||||||
new PaymentCapturePending( $logger ),
|
new PaymentCapturePending( $logger ),
|
||||||
|
|
|
@ -20,7 +20,7 @@ use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\PayUponInvoiceGa
|
||||||
*/
|
*/
|
||||||
class CheckoutOrderApproved implements RequestHandler {
|
class CheckoutOrderApproved implements RequestHandler {
|
||||||
|
|
||||||
use PrefixTrait;
|
use RequestHandlerTrait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The logger.
|
* The logger.
|
||||||
|
@ -40,12 +40,10 @@ class CheckoutOrderApproved implements RequestHandler {
|
||||||
* CheckoutOrderApproved constructor.
|
* CheckoutOrderApproved constructor.
|
||||||
*
|
*
|
||||||
* @param LoggerInterface $logger The logger.
|
* @param LoggerInterface $logger The logger.
|
||||||
* @param string $prefix The prefix.
|
|
||||||
* @param OrderEndpoint $order_endpoint The order endpoint.
|
* @param OrderEndpoint $order_endpoint The order endpoint.
|
||||||
*/
|
*/
|
||||||
public function __construct( LoggerInterface $logger, string $prefix, OrderEndpoint $order_endpoint ) {
|
public function __construct( LoggerInterface $logger, OrderEndpoint $order_endpoint ) {
|
||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
$this->prefix = $prefix;
|
|
||||||
$this->order_endpoint = $order_endpoint;
|
$this->order_endpoint = $order_endpoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,13 +158,7 @@ class CheckoutOrderApproved implements RequestHandler {
|
||||||
return rest_ensure_response( $response );
|
return rest_ensure_response( $response );
|
||||||
}
|
}
|
||||||
|
|
||||||
$wc_order_ids = array_map(
|
$wc_order_ids = $custom_ids;
|
||||||
array(
|
|
||||||
$this,
|
|
||||||
'sanitize_custom_id',
|
|
||||||
),
|
|
||||||
$custom_ids
|
|
||||||
);
|
|
||||||
$args = array(
|
$args = array(
|
||||||
'post__in' => $wc_order_ids,
|
'post__in' => $wc_order_ids,
|
||||||
'limit' => -1,
|
'limit' => -1,
|
||||||
|
|
|
@ -19,7 +19,7 @@ use WP_REST_Response;
|
||||||
*/
|
*/
|
||||||
class CheckoutOrderCompleted implements RequestHandler {
|
class CheckoutOrderCompleted implements RequestHandler {
|
||||||
|
|
||||||
use PrefixTrait, RequestHandlerTrait;
|
use RequestHandlerTrait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The logger.
|
* The logger.
|
||||||
|
@ -32,11 +32,9 @@ class CheckoutOrderCompleted implements RequestHandler {
|
||||||
* CheckoutOrderCompleted constructor.
|
* CheckoutOrderCompleted constructor.
|
||||||
*
|
*
|
||||||
* @param LoggerInterface $logger The logger.
|
* @param LoggerInterface $logger The logger.
|
||||||
* @param string $prefix The prefix.
|
|
||||||
*/
|
*/
|
||||||
public function __construct( LoggerInterface $logger, string $prefix ) {
|
public function __construct( LoggerInterface $logger ) {
|
||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
$this->prefix = $prefix;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -18,7 +18,7 @@ use WP_REST_Response;
|
||||||
*/
|
*/
|
||||||
class CheckoutPaymentApprovalReversed implements RequestHandler {
|
class CheckoutPaymentApprovalReversed implements RequestHandler {
|
||||||
|
|
||||||
use RequestHandlerTrait, PrefixTrait;
|
use RequestHandlerTrait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The logger.
|
* The logger.
|
||||||
|
|
|
@ -22,7 +22,7 @@ use WP_REST_Response;
|
||||||
*/
|
*/
|
||||||
class PaymentCaptureCompleted implements RequestHandler {
|
class PaymentCaptureCompleted implements RequestHandler {
|
||||||
|
|
||||||
use PrefixTrait, TransactionIdHandlingTrait;
|
use TransactionIdHandlingTrait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The logger.
|
* The logger.
|
||||||
|
@ -42,16 +42,13 @@ class PaymentCaptureCompleted implements RequestHandler {
|
||||||
* PaymentCaptureCompleted constructor.
|
* PaymentCaptureCompleted constructor.
|
||||||
*
|
*
|
||||||
* @param LoggerInterface $logger The logger.
|
* @param LoggerInterface $logger The logger.
|
||||||
* @param string $prefix The prefix.
|
|
||||||
* @param OrderEndpoint $order_endpoint The order endpoint.
|
* @param OrderEndpoint $order_endpoint The order endpoint.
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
LoggerInterface $logger,
|
LoggerInterface $logger,
|
||||||
string $prefix,
|
|
||||||
OrderEndpoint $order_endpoint
|
OrderEndpoint $order_endpoint
|
||||||
) {
|
) {
|
||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
$this->prefix = $prefix;
|
|
||||||
$this->order_endpoint = $order_endpoint;
|
$this->order_endpoint = $order_endpoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,8 +92,7 @@ class PaymentCaptureCompleted implements RequestHandler {
|
||||||
return new WP_REST_Response( $response );
|
return new WP_REST_Response( $response );
|
||||||
}
|
}
|
||||||
|
|
||||||
$wc_order_id = isset( $resource['custom_id'] ) ?
|
$wc_order_id = isset( $resource['custom_id'] ) ? (string) $resource['custom_id'] : 0;
|
||||||
$this->sanitize_custom_id( (string) $resource['custom_id'] ) : 0;
|
|
||||||
if ( ! $wc_order_id ) {
|
if ( ! $wc_order_id ) {
|
||||||
$message = sprintf( 'No order for webhook event %s was found.', $webhook_id );
|
$message = sprintf( 'No order for webhook event %s was found.', $webhook_id );
|
||||||
$this->logger->warning( $message, array( 'request' => $request ) );
|
$this->logger->warning( $message, array( 'request' => $request ) );
|
||||||
|
|
|
@ -18,7 +18,7 @@ use WP_REST_Response;
|
||||||
*/
|
*/
|
||||||
class PaymentCapturePending implements RequestHandler {
|
class PaymentCapturePending implements RequestHandler {
|
||||||
|
|
||||||
use PrefixTrait;
|
use RequestHandlerTrait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The logger.
|
* The logger.
|
||||||
|
@ -68,7 +68,7 @@ class PaymentCapturePending implements RequestHandler {
|
||||||
public function handle_request( WP_REST_Request $request ): WP_REST_Response {
|
public function handle_request( WP_REST_Request $request ): WP_REST_Response {
|
||||||
$response = array( 'success' => false );
|
$response = array( 'success' => false );
|
||||||
$order_id = $request['resource'] !== null && isset( $request['resource']['custom_id'] )
|
$order_id = $request['resource'] !== null && isset( $request['resource']['custom_id'] )
|
||||||
? $this->sanitize_custom_id( $request['resource']['custom_id'] )
|
? $request['resource']['custom_id']
|
||||||
: 0;
|
: 0;
|
||||||
if ( ! $order_id ) {
|
if ( ! $order_id ) {
|
||||||
$message = sprintf(
|
$message = sprintf(
|
||||||
|
|
|
@ -20,7 +20,7 @@ use WP_REST_Response;
|
||||||
*/
|
*/
|
||||||
class PaymentCaptureRefunded implements RequestHandler {
|
class PaymentCaptureRefunded implements RequestHandler {
|
||||||
|
|
||||||
use PrefixTrait, TransactionIdHandlingTrait, RefundMetaTrait;
|
use TransactionIdHandlingTrait, RefundMetaTrait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The logger.
|
* The logger.
|
||||||
|
@ -33,11 +33,9 @@ class PaymentCaptureRefunded implements RequestHandler {
|
||||||
* PaymentCaptureRefunded constructor.
|
* PaymentCaptureRefunded constructor.
|
||||||
*
|
*
|
||||||
* @param LoggerInterface $logger The logger.
|
* @param LoggerInterface $logger The logger.
|
||||||
* @param string $prefix The prefix.
|
|
||||||
*/
|
*/
|
||||||
public function __construct( LoggerInterface $logger, string $prefix ) {
|
public function __construct( LoggerInterface $logger ) {
|
||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
$this->prefix = $prefix;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -70,7 +68,7 @@ class PaymentCaptureRefunded implements RequestHandler {
|
||||||
public function handle_request( WP_REST_Request $request ): WP_REST_Response {
|
public function handle_request( WP_REST_Request $request ): WP_REST_Response {
|
||||||
$response = array( 'success' => false );
|
$response = array( 'success' => false );
|
||||||
$order_id = isset( $request['resource']['custom_id'] ) ?
|
$order_id = isset( $request['resource']['custom_id'] ) ?
|
||||||
$this->sanitize_custom_id( $request['resource']['custom_id'] ) : 0;
|
$request['resource']['custom_id'] : 0;
|
||||||
$refund_id = (string) ( $request['resource']['id'] ?? '' );
|
$refund_id = (string) ( $request['resource']['id'] ?? '' );
|
||||||
if ( ! $order_id ) {
|
if ( ! $order_id ) {
|
||||||
$message = sprintf(
|
$message = sprintf(
|
||||||
|
|
|
@ -19,7 +19,7 @@ use Psr\Log\LoggerInterface;
|
||||||
*/
|
*/
|
||||||
class PaymentCaptureReversed implements RequestHandler {
|
class PaymentCaptureReversed implements RequestHandler {
|
||||||
|
|
||||||
use PrefixTrait;
|
use RequestHandlerTrait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The logger.
|
* The logger.
|
||||||
|
@ -32,11 +32,9 @@ class PaymentCaptureReversed implements RequestHandler {
|
||||||
* PaymentCaptureReversed constructor.
|
* PaymentCaptureReversed constructor.
|
||||||
*
|
*
|
||||||
* @param LoggerInterface $logger The logger.
|
* @param LoggerInterface $logger The logger.
|
||||||
* @param string $prefix The prefix.
|
|
||||||
*/
|
*/
|
||||||
public function __construct( LoggerInterface $logger, string $prefix ) {
|
public function __construct( LoggerInterface $logger ) {
|
||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
$this->prefix = $prefix;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -73,7 +71,7 @@ class PaymentCaptureReversed implements RequestHandler {
|
||||||
public function handle_request( \WP_REST_Request $request ): \WP_REST_Response {
|
public function handle_request( \WP_REST_Request $request ): \WP_REST_Response {
|
||||||
$response = array( 'success' => false );
|
$response = array( 'success' => false );
|
||||||
$order_id = isset( $request['resource']['custom_id'] ) ?
|
$order_id = isset( $request['resource']['custom_id'] ) ?
|
||||||
$this->sanitize_custom_id( $request['resource']['custom_id'] ) : 0;
|
$request['resource']['custom_id'] : 0;
|
||||||
if ( ! $order_id ) {
|
if ( ! $order_id ) {
|
||||||
$message = sprintf(
|
$message = sprintf(
|
||||||
// translators: %s is the PayPal webhook Id.
|
// translators: %s is the PayPal webhook Id.
|
||||||
|
|
|
@ -1,40 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* Trait which helps to remove the prefix of IDs.
|
|
||||||
*
|
|
||||||
* @package WooCommerce\PayPalCommerce\Webhooks\Handler
|
|
||||||
*/
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace WooCommerce\PayPalCommerce\Webhooks\Handler;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Trait PrefixTrait
|
|
||||||
*/
|
|
||||||
trait PrefixTrait {
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The prefix.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $prefix = '';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes the prefix from a given Id.
|
|
||||||
*
|
|
||||||
* @param string $custom_id The custom id.
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
private function sanitize_custom_id( string $custom_id ): int {
|
|
||||||
|
|
||||||
$id = $custom_id;
|
|
||||||
if ( strlen( $this->prefix ) > 0 && 0 === strpos( $id, $this->prefix ) ) {
|
|
||||||
$id = substr( $id, strlen( $this->prefix ) );
|
|
||||||
}
|
|
||||||
return (int) $id;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -45,13 +45,7 @@ trait RequestHandlerTrait {
|
||||||
* @return WC_Order[]
|
* @return WC_Order[]
|
||||||
*/
|
*/
|
||||||
protected function get_wc_orders_from_custom_ids( array $custom_ids ): array {
|
protected function get_wc_orders_from_custom_ids( array $custom_ids ): array {
|
||||||
$order_ids = array_map(
|
$order_ids = $custom_ids;
|
||||||
array(
|
|
||||||
$this,
|
|
||||||
'sanitize_custom_id',
|
|
||||||
),
|
|
||||||
$custom_ids
|
|
||||||
);
|
|
||||||
$args = array(
|
$args = array(
|
||||||
'post__in' => $order_ids,
|
'post__in' => $order_ids,
|
||||||
'limit' => -1,
|
'limit' => -1,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue