#Karli-customer-update

1 messages ยท Page 1 of 1 (latest)

scarlet lynx
#

Hi there, I'm not sure if this is documented anywhere but it is expected. If you update an address, you must re-pass in any information you want to keep from the previous address.

swift warren
#

Just before calling $customer->save(), the output of $customer->address is:
=> Stripe\StripeObject {#4090 city: null, country: "US", line1: "line 1 address", line2: null, postal_code: null, state: "AZ", }
So all the fields are still filled.

scarlet lynx
#

Sure that is because you are updating your local variable, right?

#

Not updating the Address within Stripe?

swift warren
#

yes, update only done on local variabel

#

so save() only sends dirty fields of changed StripeObject?

scarlet lynx
#

I don't know what save() does... that is your own code

#

What is the definition of that function?

swift warren
#

$customer is Stripe\Customer object, so no, it is not my own code. The definition is here: \Stripe\ApiOperations\Update::save

scarlet lynx
#

Can you provide the customer ID for the customer that you are updating?

#

I'd like to take a look at something

swift warren
#

it is in test mode: cus_LeaWTVSt39465O

minor crag
#

Hi there sorry for the delay. Give me a moment to check

#

Looks like the country and line 1 fields are still on that Customer object

swift warren
#

Hi, no problem! ๐Ÿ™‚

#

I did some more digging as well. The save() method uses: $params = $this->serializeParameters(); to get fields that need changing, this in turn looks into \Stripe\StripeObject::$_values, which is only populated when \Stripe\StripeObject::updateAttributes or \Stripe\StripeObject::__set are called. So indeed, looks like if I do not call set on all the address fields, that already existed, they will be excluded from the API request and hence will be removed. It was a bit surprising, but I guess I have to live with it ๐Ÿ™‚

minor crag
#

Ah I see

#

Glad you got to the bottom of it!

swift warren
#

Anyway, I guess, I should use more of that non-legacy style of the API, so I won't run into problems like that ๐Ÿ˜›