Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

500 error: Cannot assign null to property craft\\elements\\Address::$countryCode of type string #32

Open
robzor opened this issue May 25, 2023 · 8 comments

Comments

@robzor
Copy link

robzor commented May 25, 2023

Hi there, I'm getting a 500 error when trying to use the plugin, the pay popup will show but when I click 'Pay' I get the error.

I'm running Craft Pro 4.4.12 and Commerce 4.2.8, and this is on OSX Desktop in Chrome:

Template code:

            {{ craft.webPayments.button({
                cart: craft.commerce.carts.cart,
                onComplete: {
                    redirect: '/checkout/order={number}&success=true',
                },
            }) }}

500 error in console:

{
"name":"Exception",
"message":"Cannot assign null to property craft\\elements\\Address::$countryCode of type string",
"code":0,
"error":"Cannot assign null to property craft\\elements\\Address::$countryCode of type string",
"exception":"TypeError",
"file":"/website/vendor/ether/web-payments/src/services/StripeService.php",
"line":297,

"trace":[
{"file":"/website/vendor/ether/web-payments/src/controllers/StripeController.php",
"line":213,
"function":"setBillingAddress",
"class":"ether\\webpayments\\services\\StripeService",
"type":"->"},{
"function":"actionPay",
"class":"ether\\webpayments\\controllers\\StripeController",
"type":"->"}

If you need any more information please let me know! Thanks!

@alexjcollins
Copy link
Member

Thanks for sharing, let me see if I can recreate the problem, first. I'll come back to you if we need anything else.

@robzor
Copy link
Author

robzor commented Jun 5, 2023

Hi @alexjcollins sorry to nag, did you have any luck with this?

@alexjcollins
Copy link
Member

I haven't been able to replicate this on our local environment. I suspect that it's to do with your Countries & States settings (/commerce/store-settings/countries). The error suggests the country code for the billing address is being sent as null.

Before you hit the pay button, what does the cart look like in the Craft admin? Can you share a screenshot?

@robzor
Copy link
Author

robzor commented Jun 6, 2023

Hi @alexjcollins , the site only ships to the UK and we actually set this in our address fields in the checkout as well with:

{{ hiddenInput('countryCode', "GB") }}

Here's a screenshot of the cart:

CleanShot 2023-06-06 at 11 47 24

We also have this in our Store Settings:

CleanShot 2023-06-06 at 11 49 57

@ArtDepartmentRF
Copy link

I am experiencing the same issue while trying to integrate this plugin for the first time.

I have arrived at an understanding of what is causing the (my) issue. After the payment is submitted to Stripe a request is submitted to the endpoint /actions/web-payments/stripe/pay containing a token from Stripe in the payload. Below is an example from my test environment.

image

This includes an object "billing_details" which is utilised to set the order billing address if it's available initially:

$wp->setBillingAddress($order, $token, $name);

https://github.com/ethercreative/web-payments/blob/b7a8fbf44b84e2e740c6b137fc7219b280b9d3db/src/services/StripeService.php#L279C2-L315C3

As you can see from the screenshot the token from Stripe contains null for the country where the country code could be. Hence the error Cannot assign null to property craft\\elements\\Address::$countryCode of type string.

if (empty($address))
return;

Perhaps the above line needs to be amended or added to with an additional validation check, because whilst all the properties of the billing_details object are null this will not cause empty() to return true.

@Liamm3
Copy link

Liamm3 commented Jan 18, 2024

Is there any update on this? We are experiencing the same issue only when Apple Pay gets used.

@cole007
Copy link

cole007 commented Feb 14, 2024

Just to chip in that this seems to be the cause of an issue we are experiencing on completing web payments.
Has anyone got this working with Craft/Craft Commerce 4?

Cole

@Liamm3
Copy link

Liamm3 commented Feb 15, 2024

Just to chip in that this seems to be the cause of an issue we are experiencing on completing web payments. Has anyone got this working with Craft/Craft Commerce 4?

Cole

We weren't able to fix the issue using this plugin without editing the source code. Our solution is to use the commerce-stripe gateway directly and implement the express checkout element from Stripe (https://docs.stripe.com/elements/express-checkout-element).

Unfortunately, commerce-stripe has no option for using the express checkout element, so it needs to be implemented on your own. But I think using the express checkout element is the future way of doing this. I also made a thread on the commerce-stripe github page: craftcms/commerce-stripe#286

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants