Automattic / woocommerce-subscriptions-core

Subscriptions core package for WooCommerce
Other
81 stars 29 forks source link

PHP error with PHP 8 when using PayPal Standard and taxes included in price #459

Open a-danae opened 1 year ago

a-danae commented 1 year ago

Describe the bug

PHP error when processing a subscription using PayPal Standard, PHP 8, and taxes included in the price.

Uncaught TypeError: Unsupported operand types: string + string in /data/www/gamekings.tv/public_html/wp-content/plugins/woocommerce-subscriptions/vendor/woocommerce/subscriptions-core/includes/gateways/paypal/includes/class-wcs-paypal-reference-transaction-api-request.php:290

This issue is reproducible under:

To Reproduce

Setting things up

  1. Set up a site using PHP 8
  2. Enable PayPal Standard in WooCommerce by adding the following to your theme's function.php add_filter( 'woocommerce_should_load_paypal_standard', '__return_true' );
  3. Go to WooCommerce -> Payments -> PayPal Standard
  4. Enter the details of your Business sandbox account (Find the creds of a sandbox account in the SS under the ID 10622, that should do the trick. Or create a developer account. Or ping me)
  5. Go to WooCommerce -> Settings -> General -> Enable taxes, and check off "Enable tax rates and calculations"
  6. Go to WooCommerce -> Settings -> Tax -> Tax options -> Prices entered with tax, select "Yes, I will enter prices inclusive of tax"
  7. Go to WooCommerce -> Settings -> Tax -> Standard rates, and add a rate for the US
  8. Go to WooCommerce -> Settings -> Shipping, and add a Zone for the US with a price
  9. Create a subscription product

Triggering the error

  1. As a shopper, add the subscription product to the cart
  2. Go to the checkout
  3. Select PayPal as the payment method
  4. Use a PayPal Personal sandbox account (Find the creds of a sandbox account in the SS under the ID 7042)
  5. Complete the checkout
  6. Notice the error in the logs

Renewing a subscription purchased under these settings should also trigger the error.

Expected behavior

No error must be triggered when purchasing a subscription with PayPal Standard.

Actual behavior

A PHP error is triggered when purchasing a subscription with PayPal Standard.

Product impact

Additional context