WC_REST_Paypal_Standard_Controller::validate_shipping_callback_request
Validate the shipping callback request.
Метод класса: WC_REST_Paypal_Standard_Controller{}
Хуков нет.
Возвращает
true|false. True if the request is valid, false otherwise.
Использование
$WC_REST_Paypal_Standard_Controller = new WC_REST_Paypal_Standard_Controller(); $WC_REST_Paypal_Standard_Controller->validate_shipping_callback_request( $request );
- $request(WP_REST_Request) (обязательный)
- .
Список изменений
| С версии 10.6.0 | Введена. |
Код WC_REST_Paypal_Standard_Controller::validate_shipping_callback_request() WC REST Paypal Standard Controller::validate shipping callback request WC 10.5.2
public function validate_shipping_callback_request( WP_REST_Request $request ) { // phpcs:ignore Squiz.Commenting.FunctionComment.IncorrectTypeHint
$token = $request->get_param( 'token' );
if ( empty( $token ) ) {
return false;
}
$purchase_units = $request->get_param( 'purchase_units' );
if ( empty( $purchase_units ) || empty( $purchase_units[0]['custom_id'] ) ) {
return false;
}
$order = PayPalHelper::get_wc_order_from_paypal_custom_id( $purchase_units[0]['custom_id'] );
if ( ! $order ) {
return false;
}
// If shipping callback token is not stored in order meta, return true for this order as the token is not generated for the original order.
// We will not validate the token if the order did not generate a token in the create order request.
// This is done to prevent orders created before the shipping callback token feature was introduced from being blocked from updating their shipping details.
if ( ! $order->meta_exists( PayPalConstants::PAYPAL_ORDER_META_SHIPPING_CALLBACK_TOKEN ) ) {
return true;
}
$shipping_callback_token = $order->get_meta( PayPalConstants::PAYPAL_ORDER_META_SHIPPING_CALLBACK_TOKEN, true );
if ( empty( $shipping_callback_token ) || ! hash_equals( $token, $shipping_callback_token ) ) {
return false;
}
return true;
}