woocommerce / woocommerce-gateway-paypal-express-checkout

59 stars 64 forks source link

Trying to get property of non-object #561

Closed FritzHerbers closed 5 years ago

FritzHerbers commented 5 years ago

After upgrading to : WooCommerce PayPal Checkout Gateway: 1.6.11 WooCommerce: 3.5.7 WordPress: 5.1.1

Our customer reported she couldn't pay, but this can also be an issue of not having funds.

Having the following notices in debug.log:

[23-Apr-2019 07:48:45 UTC] PHP Notice: Trying to get property 'billing_address' of non-object in /var/www/prod/wp-content/plugins/woocommerce-gateway-paypal-express-checkout/includes/class-wc-gateway-ppec-checkout-handler.php on line 252 [23-Apr-2019 07:48:45 UTC] PHP Notice: Trying to get property 'first_name' of non-object in /var/www/prod/wp-content/plugins/woocommerce-gateway-paypal-express-checkout/includes/class-wc-gateway-ppec-checkout-handler.php on line 255 [23-Apr-2019 07:48:45 UTC] PHP Notice: Trying to get property 'last_name' of non-object in /var/www/prod/wp-content/plugins/woocommerce-gateway-paypal-express-checkout/includes/class-wc-gateway-ppec-checkout-handler.php on line 255 [23-Apr-2019 07:48:45 UTC] PHP Notice: Trying to get property 'business_name' of non-object in /var/www/prod/wp-content/plugins/woocommerce-gateway-paypal-express-checkout/includes/class-wc-gateway-ppec-checkout-handler.php on line 408

When there are issues I would prefer having an application error message than a PHP notice.

allendav commented 5 years ago

@marcinbot @v18 - is this the same as #549 ?

marcinbot commented 5 years ago

@allendav - No, it's a different issue. PayPal doesn't return the required billing info at all here. We could add a quick check that would get rid of the php warnings, but I don't think that'd handling it properly. I tried to reproduce this and checked the documentation for possible causes but no success.

@FritzHerbers - could you provide more information?

FritzHerbers commented 5 years ago

What PayPal extension settings are you using?

Require Billing Address: disabled Require Phone Number: enabled Payment Action: Sale Require Instant Payment: enabled Subtotal Mismatch Behavior: add another line

What type of product is being ordered - is it physical or virtual?

physical product

Did the customer confirm there were no funds available on her card?

Might be a handling problem within PayPal. We setup a PayPal invoice which got paid.

marcinbot commented 5 years ago

Thanks! We will keep looking into it and update here once it's fixed

FritzHerbers commented 5 years ago

We got this error a second time, again with a customer not having funds. I am not sure how to interprete the log, for me it looks likeWooCommerce tries to connect to PayPal to ask the status after a couple of minutes.

[20-May-2019 19:02:20 UTC] WC_Gateway_PPEC_Client::_process_response: acknowleged response body: Array
(
    [TOKEN] => XXXXXXX
    [SUCCESSPAGEREDIRECTREQUESTED] => false
    [TIMESTAMP] => 2019-05-20T19:02:20Z
    [CORRELATIONID] => bf6248f7be270
    [ACK] => Failure
    [VERSION] => 120.0
    [BUILD] => 52747458
    [L_ERRORCODE0] => 10486
    [L_SHORTMESSAGE0] => This transaction couldn't be completed.
    [L_LONGMESSAGE0] => This transaction couldn't be completed. Please redirect your customer to PayPal.
    [L_SEVERITYCODE0] => Error
)

[20-May-2019 19:14:40 UTC] WC_Gateway_PPEC_Client::_request: remote request to https://api-3t.paypal.com/nvp with params: Array
(
    [METHOD] => GetExpressCheckoutDetails
    [VERSION] => 120.0
    [TOKEN] => XXXXXXX
    [USER] => XXXXXXX
    [PWD] => XXXXXXX
    [SIGNATURE] => XXXXXXX
)

[20-May-2019 19:14:41 UTC] WC_Gateway_PPEC_Client::_process_response: acknowleged response body: Array
(
    [TOKEN] => XXXXXXX
    [BILLINGAGREEMENTACCEPTEDSTATUS] => 0
    [CHECKOUTSTATUS] => PaymentActionNotInitiated
    [TIMESTAMP] => 2019-05-20T19:14:41Z
    [CORRELATIONID] => 275013786b525
    [ACK] => Success
    [VERSION] => 120.0
    [BUILD] => 52747458

    [PAYMENTREQUESTINFO_0_ERRORCODE] => 0
)

[20-May-2019 19:14:41 UTC] PHP Notice:  Trying to get property 'billing_address' of non-object in /var/www/prod/slhprod/wp-content/plugins/woocommerce-gateway-paypal-express-checkout/includes/class-wc-gateway-ppec-checkout-handler.php on line 252
[20-May-2019 19:14:41 UTC] PHP Notice:  Trying to get property 'first_name' of non-object in /var/www/prod/slhprod/wp-content/plugins/woocommerce-gateway-paypal-express-checkout/includes/class-wc-gateway-ppec-checkout-handler.php on line 255
[20-May-2019 19:14:41 UTC] PHP Notice:  Trying to get property 'last_name' of non-object in /var/www/prod/slhprod/wp-content/plugins/woocommerce-gateway-paypal-express-checkout/includes/class-wc-gateway-ppec-checkout-handler.php on line 255
[20-May-2019 19:14:41 UTC] PHP Notice:  Trying to get property 'business_name' of non-object in /var/www/prod/slhprod/wp-content/plugins/woocommerce-gateway-paypal-express-checkout/includes/class-wc-gateway-ppec-checkout-handler.php on line 408
[20-May-2019 19:14:59 UTC] WC_Gateway_PPEC_Client::_request: remote request to https://api-3t.paypal.com/nvp with params: Array
(
    [METHOD] => GetExpressCheckoutDetails
    [VERSION] => 120.0
    [TOKEN] => XXXXXXX
    [USER] => XXXXXXX
    [PWD] => XXXXXXX
    [SIGNATURE] => XXXXXXX
)

[20-May-2019 19:15:00 UTC] WC_Gateway_PPEC_Client::_process_response: acknowleged response body: Array
(
    [TOKEN] => XXXXXXX
    [BILLINGAGREEMENTACCEPTEDSTATUS] => 0
    [CHECKOUTSTATUS] => PaymentActionNotInitiated
    [TIMESTAMP] => 2019-05-20T19:15:00Z
    [CORRELATIONID] => 2eacb53a94b85
    [ACK] => Success
    [VERSION] => 120.0
    [BUILD] => 52747458

    [PAYMENTREQUESTINFO_0_ERRORCODE] => 0
)

[20-May-2019 19:15:00 UTC] PHP Notice:  Trying to get property 'business_name' of non-object in /var/www/prod/slhprod/wp-content/plugins/woocommerce-gateway-paypal-express-checkout/includes/class-wc-gateway-ppec-checkout-handler.php on line 408
[20-May-2019 19:15:06 UTC] WC_Gateway_PPEC_Client::_request: remote request to https://api-3t.paypal.com/nvp with params: Array
(
    [METHOD] => GetExpressCheckoutDetails
    [VERSION] => 120.0
    [TOKEN] => XXXXXXX
    [USER] => XXXXXXX
    [PWD] => XXXXXXX
    [SIGNATURE] => XXXXXXX
)

[20-May-2019 19:15:07 UTC] WC_Gateway_PPEC_Client::_process_response: acknowleged response body: Array
(
    [TOKEN] => XXXXXXX
    [BILLINGAGREEMENTACCEPTEDSTATUS] => 0
    [CHECKOUTSTATUS] => PaymentActionNotInitiated
    [TIMESTAMP] => 2019-05-20T19:15:07Z
    [CORRELATIONID] => 75f7f1c19fc7f
    [ACK] => Success
    [VERSION] => 120.0
    [BUILD] => 52747458

    [PAYMENTREQUESTINFO_0_ERRORCODE] => 0
)

[20-May-2019 19:15:07 UTC] PHP Notice:  Trying to get property 'billing_address' of non-object in /var/www/prod/slhprod/wp-content/plugins/woocommerce-gateway-paypal-express-checkout/includes/class-wc-gateway-ppec-checkout-handler.php on line 252
[20-May-2019 19:15:07 UTC] PHP Notice:  Trying to get property 'first_name' of non-object in /var/www/prod/slhprod/wp-content/plugins/woocommerce-gateway-paypal-express-checkout/includes/class-wc-gateway-ppec-checkout-handler.php on line 255
[20-May-2019 19:15:07 UTC] PHP Notice:  Trying to get property 'last_name' of non-object in /var/www/prod/slhprod/wp-content/plugins/woocommerce-gateway-paypal-express-checkout/includes/class-wc-gateway-ppec-checkout-handler.php on line 255
[20-May-2019 19:15:07 UTC] PHP Notice:  Trying to get property 'business_name' of non-object in /var/www/prod/slhprod/wp-content/plugins/woocommerce-gateway-paypal-express-checkout/includes/class-wc-gateway-ppec-checkout-handler.php on line 408
[20-May-2019 19:15:46 UTC] PHP Notice:  Trying to get property 'ID' of non-object in /var/www/prod/slhprod/wp-content/plugins/super-socializer/inc/social_sharing.php on line 52
[20-May-2019 20:18:23 UTC] WC_Gateway_PPEC_Client::_request: remote request to https://api-3t.paypal.com/nvp with params: Array
(
    [METHOD] => GetExpressCheckoutDetails
    [VERSION] => 120.0
    [TOKEN] => XXXXXXX
    [USER] => XXXXXXX
    [PWD] => XXXXXXX
    [SIGNATURE] => XXXXXXX
)

[20-May-2019 20:18:25 UTC] WC_Gateway_PPEC_Client::_process_response: acknowleged response body: Array
(
    [TOKEN] => XXXXXXX
    [BILLINGAGREEMENTACCEPTEDSTATUS] => 0
    [CHECKOUTSTATUS] => PaymentActionNotInitiated
    [TIMESTAMP] => 2019-05-20T20:18:25Z
    [CORRELATIONID] => c43c068a18730
    [ACK] => Success
    [VERSION] => 120.0
    [BUILD] => 52747458

    [PAYMENTREQUESTINFO_0_ERRORCODE] => 0
)

[20-May-2019 20:18:25 UTC] PHP Notice:  Trying to get property 'billing_address' of non-object in /var/www/prod/slhprod/wp-content/plugins/woocommerce-gateway-paypal-express-checkout/includes/class-wc-gateway-ppec-checkout-handler.php on line 252
[20-May-2019 20:18:25 UTC] PHP Notice:  Trying to get property 'first_name' of non-object in /var/www/prod/slhprod/wp-content/plugins/woocommerce-gateway-paypal-express-checkout/includes/class-wc-gateway-ppec-checkout-handler.php on line 255
[20-May-2019 20:18:25 UTC] PHP Notice:  Trying to get property 'last_name' of non-object in /var/www/prod/slhprod/wp-content/plugins/woocommerce-gateway-paypal-express-checkout/includes/class-wc-gateway-ppec-checkout-handler.php on line 255
[20-May-2019 20:18:25 UTC] PHP Notice:  Trying to get property 'business_name' of non-object in /var/www/prod/slhprod/wp-content/plugins/woocommerce-gateway-paypal-express-checkout/includes/class-wc-gateway-ppec-checkout-handler.php on line 408
[20-May-2019 20:18:33 UTC] WC_Gateway_PPEC_Client::_request: remote request to https://api-3t.paypal.com/nvp with params: Array
(
    [METHOD] => GetExpressCheckoutDetails
    [VERSION] => 120.0
    [TOKEN] => XXXXXXX
    [USER] => XXXXXXX
    [PWD] => XXXXXXX
    [SIGNATURE] => XXXXXXX
)

[20-May-2019 20:18:34 UTC] WC_Gateway_PPEC_Client::_process_response: acknowleged response body: Array
(
    [TOKEN] => XXXXXXX
    [BILLINGAGREEMENTACCEPTEDSTATUS] => 0
    [CHECKOUTSTATUS] => PaymentActionNotInitiated
    [TIMESTAMP] => 2019-05-20T20:18:34Z
    [CORRELATIONID] => 400085e795eb8
    [ACK] => Success
    [VERSION] => 120.0
    [BUILD] => 52747458

    [PAYMENTREQUESTINFO_0_ERRORCODE] => 0
)

[20-May-2019 20:18:34 UTC] PHP Notice:  Trying to get property 'business_name' of non-object in /var/www/prod/slhprod/wp-content/plugins/woocommerce-gateway-paypal-express-checkout/includes/class-wc-gateway-ppec-checkout-handler.php on line 408
[20-May-2019 20:18:51 UTC] WC_Gateway_PPEC_Client::_request: remote request to https://api-3t.paypal.com/nvp with params: Array
(
    [METHOD] => GetExpressCheckoutDetails
    [VERSION] => 120.0
    [TOKEN] => XXXXXXX
    [USER] => XXXXXXX
    [PWD] => XXXXXXX
    [SIGNATURE] => XXXXXXX
)

[20-May-2019 20:18:53 UTC] WC_Gateway_PPEC_Client::_process_response: acknowleged response body: Array
(
    [TOKEN] => XXXXXXX
    [BILLINGAGREEMENTACCEPTEDSTATUS] => 0
    [CHECKOUTSTATUS] => PaymentActionNotInitiated
    [TIMESTAMP] => 2019-05-20T20:18:53Z
    [CORRELATIONID] => b0a3ae06d0341
    [ACK] => Success
    [VERSION] => 120.0
    [BUILD] => 52747458

    [PAYMENTREQUESTINFO_0_ERRORCODE] => 0
)

[20-May-2019 20:18:53 UTC] PHP Notice:  Trying to get property 'billing_address' of non-object in /var/www/prod/slhprod/wp-content/plugins/woocommerce-gateway-paypal-express-checkout/includes/class-wc-gateway-ppec-checkout-handler.php on line 252
[20-May-2019 20:18:53 UTC] PHP Notice:  Trying to get property 'first_name' of non-object in /var/www/prod/slhprod/wp-content/plugins/woocommerce-gateway-paypal-express-checkout/includes/class-wc-gateway-ppec-checkout-handler.php on line 255
[20-May-2019 20:18:53 UTC] PHP Notice:  Trying to get property 'last_name' of non-object in /var/www/prod/slhprod/wp-content/plugins/woocommerce-gateway-paypal-express-checkout/includes/class-wc-gateway-ppec-checkout-handler.php on line 255
[20-May-2019 20:18:53 UTC] PHP Notice:  Trying to get property 'business_name' of non-object in /var/www/prod/slhprod/wp-content/plugins/woocommerce-gateway-paypal-express-checkout/includes/class-wc-gateway-ppec-checkout-handler.php on line 408
marcinbot commented 5 years ago

Thanks for the logs @FritzHerbers! Looks like the payment failed on the customer side, but PayPal API still returned a success response to us. I think we should treat it as an error in this case and not process the order.

I'll reopen this issue and we will have a look.

dechov commented 5 years ago

I managed to reproduce by triggering the 10486 error, which redirects to PayPal (see https://github.com/woocommerce/woocommerce-gateway-paypal-express-checkout/issues/320#issuecomment-400101341), and then going straight to /checkout (neither proceeding nor cancelling from PayPal, i.e. no woo-return-* query param).

(Note: to force that error, pass 'AMT' => '104.86' [doc] in get_do_express_checkout_params, with "Negative Testing" enabled in the settings for the PayPal sandbox account configured in the gateway.)

The session is set upon redirect (and that's why the checkout fields are being replaced, previously triggering those notices), which is not something I think we should be changing.

I was starting to think that since those conditions are outside the typical flow and the consequences don't seem bad (now that the change in https://github.com/woocommerce/woocommerce-gateway-paypal-express-checkout/pull/567 is released), there's nothing more that we need to do. That may not be the case however: the experience is still broken, since upon clicking "Continue to Payment" the customer is shown validation errors for billing fields that weren't being displayed. I'll see if I can find some simple fix here.

There's another broken case I ran into that might be more challenging to fix: when checking out from the Checkout screen and being redirected, going back via the Back button to the Checkout screen results in a cached page, the loading of which triggers AJAX loading of the payment section fragment but results in a broken state (no submit or PayPal buttons).