mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Merge pull request #922 from woocommerce/PCP-937-php-8.1-support
PHP 8.1 support
This commit is contained in:
commit
8bc53bf3cf
18 changed files with 76 additions and 55 deletions
|
@ -117,14 +117,15 @@ class SettingsPageAssets {
|
|||
}
|
||||
|
||||
$screen = get_current_screen();
|
||||
|
||||
$tab = filter_input( INPUT_GET, 'tab', FILTER_SANITIZE_STRING );
|
||||
$section = filter_input( INPUT_GET, 'section', FILTER_SANITIZE_STRING );
|
||||
|
||||
if ( ! 'woocommerce_page_wc-settings' === $screen->id ) {
|
||||
if ( $screen->id !== 'woocommerce_page_wc-settings' ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// phpcs:disable WordPress.Security.NonceVerification.Recommended
|
||||
$tab = wc_clean( wp_unslash( $_GET['tab'] ?? '' ) );
|
||||
$section = wc_clean( wp_unslash( $_GET['section'] ?? '' ) );
|
||||
// phpcs:enable WordPress.Security.NonceVerification.Recommended
|
||||
|
||||
return 'checkout' === $tab && 'ppcp-gateway' === $section;
|
||||
}
|
||||
|
||||
|
|
|
@ -275,7 +275,8 @@ class CardButtonGateway extends \WC_Payment_Gateway {
|
|||
* If customer has chosen change Subscription payment.
|
||||
*/
|
||||
if ( $this->subscription_helper->has_subscription( $order_id ) && $this->subscription_helper->is_subscription_change_payment() ) {
|
||||
$saved_paypal_payment = filter_input( INPUT_POST, 'saved_paypal_payment', FILTER_SANITIZE_STRING );
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Missing
|
||||
$saved_paypal_payment = wc_clean( wp_unslash( $_POST['saved_paypal_payment'] ?? '' ) );
|
||||
if ( $saved_paypal_payment ) {
|
||||
$wc_order->update_meta_data( 'payment_token_id', $saved_paypal_payment );
|
||||
$wc_order->save();
|
||||
|
|
|
@ -360,7 +360,8 @@ class CreditCardGateway extends \WC_Payment_Gateway_CC {
|
|||
/**
|
||||
* If customer has chosen a saved credit card payment.
|
||||
*/
|
||||
$saved_credit_card = filter_input( INPUT_POST, 'saved_credit_card', FILTER_SANITIZE_STRING );
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Missing
|
||||
$saved_credit_card = wc_clean( wp_unslash( $_POST['saved_credit_card'] ?? '' ) );
|
||||
if ( $saved_credit_card ) {
|
||||
try {
|
||||
$wc_order = $this->vaulted_credit_card_handler->handle_payment(
|
||||
|
|
|
@ -138,7 +138,8 @@ class OXXO {
|
|||
'add_meta_boxes',
|
||||
function( string $post_type ) {
|
||||
if ( $post_type === 'shop_order' ) {
|
||||
$post_id = filter_input( INPUT_GET, 'post', FILTER_SANITIZE_STRING );
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
$post_id = wc_clean( wp_unslash( $_GET['post'] ?? '' ) );
|
||||
$order = wc_get_order( $post_id );
|
||||
if ( is_a( $order, WC_Order::class ) && $order->get_payment_method() === OXXOGateway::ID ) {
|
||||
$payer_action = $order->get_meta( 'ppcp_oxxo_payer_action' );
|
||||
|
@ -182,7 +183,8 @@ class OXXO {
|
|||
return false;
|
||||
}
|
||||
|
||||
$billing_country = filter_input( INPUT_POST, 'country', FILTER_SANITIZE_STRING ) ?? null;
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Missing
|
||||
$billing_country = wc_clean( wp_unslash( $_POST['country'] ?? '' ) );
|
||||
if ( $billing_country && 'MX' !== $billing_country ) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -400,8 +400,8 @@ class PayPalGateway extends \WC_Payment_Gateway {
|
|||
);
|
||||
}
|
||||
|
||||
$funding_source = filter_input( INPUT_POST, 'ppcp-funding-source', FILTER_SANITIZE_STRING );
|
||||
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Missing
|
||||
$funding_source = wc_clean( wp_unslash( $_POST['ppcp-funding-source'] ?? '' ) );
|
||||
if ( 'card' !== $funding_source && $this->is_free_trial_order( $wc_order ) ) {
|
||||
$user_id = (int) $wc_order->get_customer_id();
|
||||
$tokens = $this->payment_token_repository->all_for_user_id( $user_id );
|
||||
|
@ -423,7 +423,8 @@ class PayPalGateway extends \WC_Payment_Gateway {
|
|||
* If customer has chosen change Subscription payment.
|
||||
*/
|
||||
if ( $this->subscription_helper->has_subscription( $order_id ) && $this->subscription_helper->is_subscription_change_payment() ) {
|
||||
$saved_paypal_payment = filter_input( INPUT_POST, 'saved_paypal_payment', FILTER_SANITIZE_STRING );
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Missing
|
||||
$saved_paypal_payment = wc_clean( wp_unslash( $_POST['saved_paypal_payment'] ?? '' ) );
|
||||
if ( $saved_paypal_payment ) {
|
||||
$wc_order->update_meta_data( 'payment_token_id', $saved_paypal_payment );
|
||||
$wc_order->save();
|
||||
|
|
|
@ -33,7 +33,8 @@ class FraudNetSessionId {
|
|||
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) {
|
||||
$pui_pay_for_order_session_id = filter_input( INPUT_POST, 'pui_pay_for_order_session_id', FILTER_SANITIZE_STRING );
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Missing
|
||||
$pui_pay_for_order_session_id = wc_clean( wp_unslash( $_POST['pui_pay_for_order_session_id'] ?? '' ) );
|
||||
if ( $pui_pay_for_order_session_id && '' !== $pui_pay_for_order_session_id ) {
|
||||
return $pui_pay_for_order_session_id;
|
||||
}
|
||||
|
|
|
@ -409,7 +409,8 @@ class PayUponInvoice {
|
|||
add_action(
|
||||
'woocommerce_after_checkout_validation',
|
||||
function( array $fields, WP_Error $errors ) {
|
||||
$payment_method = filter_input( INPUT_POST, 'payment_method', FILTER_SANITIZE_STRING );
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Missing
|
||||
$payment_method = wc_clean( wp_unslash( $_POST['payment_method'] ?? '' ) );
|
||||
if ( PayUponInvoiceGateway::ID !== $payment_method ) {
|
||||
return;
|
||||
}
|
||||
|
@ -418,12 +419,14 @@ class PayUponInvoice {
|
|||
$errors->add( 'validation', __( 'Billing country not available.', 'woocommerce-paypal-payments' ) );
|
||||
}
|
||||
|
||||
$birth_date = filter_input( INPUT_POST, 'billing_birth_date', FILTER_SANITIZE_STRING );
|
||||
if ( ( $birth_date && ! $this->checkout_helper->validate_birth_date( $birth_date ) ) || $birth_date === '' ) {
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Missing
|
||||
$birth_date = wc_clean( wp_unslash( $_POST['billing_birth_date'] ?? '' ) );
|
||||
if ( ( $birth_date && is_string( $birth_date ) && ! $this->checkout_helper->validate_birth_date( $birth_date ) ) || $birth_date === '' ) {
|
||||
$errors->add( 'validation', __( 'Invalid birth date.', 'woocommerce-paypal-payments' ) );
|
||||
}
|
||||
|
||||
$national_number = filter_input( INPUT_POST, 'billing_phone', FILTER_SANITIZE_STRING );
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Missing
|
||||
$national_number = wc_clean( wp_unslash( $_POST['billing_phone'] ?? '' ) );
|
||||
if ( ! $national_number ) {
|
||||
$errors->add( 'validation', __( 'Phone field cannot be empty.', 'woocommerce-paypal-payments' ) );
|
||||
}
|
||||
|
@ -484,18 +487,9 @@ class PayUponInvoice {
|
|||
add_action(
|
||||
'woocommerce_update_options_checkout_ppcp-pay-upon-invoice-gateway',
|
||||
function () {
|
||||
$customer_service_instructions = filter_input( INPUT_POST, 'woocommerce_ppcp-pay-upon-invoice-gateway_customer_service_instructions', FILTER_SANITIZE_STRING );
|
||||
if ( '' === $customer_service_instructions ) {
|
||||
$gateway_settings = get_option( 'woocommerce_ppcp-pay-upon-invoice-gateway_settings' );
|
||||
$gateway_enabled = $gateway_settings['enabled'] ?? '';
|
||||
if ( 'yes' === $gateway_enabled ) {
|
||||
$gateway_settings['enabled'] = 'no';
|
||||
update_option( 'woocommerce_ppcp-pay-upon-invoice-gateway_settings', $gateway_settings );
|
||||
|
||||
$redirect_url = admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=ppcp-pay-upon-invoice-gateway' );
|
||||
wp_safe_redirect( $redirect_url );
|
||||
exit;
|
||||
}
|
||||
$gateway = WC()->payment_gateways()->payment_gateways()[ PayUponInvoiceGateway::ID ];
|
||||
if ( $gateway && $gateway->get_option( 'customer_service_instructions' ) === '' ) {
|
||||
$gateway->update_option( 'enabled', 'no' );
|
||||
}
|
||||
}
|
||||
);
|
||||
|
@ -537,7 +531,8 @@ class PayUponInvoice {
|
|||
'add_meta_boxes',
|
||||
function( string $post_type ) {
|
||||
if ( $post_type === 'shop_order' ) {
|
||||
$post_id = filter_input( INPUT_GET, 'post', FILTER_SANITIZE_STRING );
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
$post_id = wc_clean( wp_unslash( $_GET['post'] ?? '' ) );
|
||||
$order = wc_get_order( $post_id );
|
||||
if ( is_a( $order, WC_Order::class ) && $order->get_payment_method() === PayUponInvoiceGateway::ID ) {
|
||||
$instructions = $order->get_meta( 'ppcp_ratepay_payment_instructions_payment_reference' );
|
||||
|
|
|
@ -202,10 +202,11 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
|
|||
* @return array
|
||||
*/
|
||||
public function process_payment( $order_id ) {
|
||||
$wc_order = wc_get_order( $order_id );
|
||||
$birth_date = filter_input( INPUT_POST, 'billing_birth_date', FILTER_SANITIZE_STRING ) ?? '';
|
||||
|
||||
$pay_for_order = filter_input( INPUT_GET, 'pay_for_order', FILTER_SANITIZE_STRING );
|
||||
$wc_order = wc_get_order( $order_id );
|
||||
// phpcs:disable WordPress.Security.NonceVerification.Missing
|
||||
$birth_date = wc_clean( wp_unslash( $_POST['billing_birth_date'] ?? '' ) );
|
||||
// phpcs:disable WordPress.Security.NonceVerification.Recommended
|
||||
$pay_for_order = wc_clean( wp_unslash( $_GET['pay_for_order'] ?? '' ) );
|
||||
if ( 'true' === $pay_for_order ) {
|
||||
if ( ! $this->checkout_helper->validate_birth_date( $birth_date ) ) {
|
||||
wc_add_notice( 'Invalid birth date.', 'error' );
|
||||
|
@ -215,7 +216,8 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
|
|||
}
|
||||
}
|
||||
|
||||
$phone_number = filter_input( INPUT_POST, 'billing_phone', FILTER_SANITIZE_STRING ) ?? '';
|
||||
$phone_number = wc_clean( wp_unslash( $_POST['billing_phone'] ?? '' ) );
|
||||
// phpcs:enable WordPress.Security.NonceVerification.Missing
|
||||
if ( $phone_number ) {
|
||||
$wc_order->set_billing_phone( $phone_number );
|
||||
$wc_order->save();
|
||||
|
|
|
@ -24,8 +24,12 @@ class PaymentSourceFactory {
|
|||
* @return PaymentSource
|
||||
*/
|
||||
public function from_wc_order( WC_Order $order, string $birth_date ) {
|
||||
$address = $order->get_address();
|
||||
$phone = filter_input( INPUT_POST, 'billing_phone', FILTER_SANITIZE_STRING ) ?? $address['phone'] ?: '';
|
||||
$address = $order->get_address();
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Missing
|
||||
$phone = wc_clean( wp_unslash( $_POST['billing_phone'] ?? '' ) );
|
||||
if ( ! $phone ) {
|
||||
$phone = $address['phone'] ?? '';
|
||||
}
|
||||
$phone_country_code = WC()->countries->get_country_calling_code( $address['country'] );
|
||||
$phone_country_code = is_array( $phone_country_code ) && ! empty( $phone_country_code ) ? $phone_country_code[0] : $phone_country_code;
|
||||
if ( is_string( $phone_country_code ) && '' !== $phone_country_code ) {
|
||||
|
|
|
@ -54,7 +54,8 @@ class PayUponInvoiceHelper {
|
|||
return false;
|
||||
}
|
||||
|
||||
$billing_country = filter_input( INPUT_POST, 'country', FILTER_SANITIZE_STRING ) ?? null;
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Missing
|
||||
$billing_country = wc_clean( wp_unslash( $_POST['country'] ?? '' ) );
|
||||
if ( $billing_country && 'DE' !== $billing_country ) {
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue