#caturner81_api
1 messages ยท Page 1 of 1 (latest)
๐ Welcome to your new thread!
โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
๐ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1333916416616697877
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
Hi there
Howdy
Hm, I don't think you're missing anything
Using two separate calls to accomplish updating an address isn't fantastic given the correctness issues that would come up if a failure occurred between the two, we've now left a payment method in a weird state. Feels like the API is just sort of missing some functionality here, or isn't appropriately handling the difference between null and "I don't want to update this field"
I want to update it, and I want to update it to null doesn't seem to be something I can express with the API here.
Right, let me do a bit of testing on my end
Great, I appreciate the help
Sorry for the delay
I've been testing out with Ruby and was able to unset line2 with just empty single quotes; the resulting PM update returned line2: null
I don't see a PaymentMethod update request in your logs where an empty set of quotes was sent for line2. In req_1gaM3Z01sqwCN4, line2 wasn't passed at all; is there where you tried to send an empty set of quotes?
Hrmm, I'm really hoping I just didn't miss something in my testing... give me a sec to dig into this, I also thought someone on my team tried that earlier.
Ok, yeah, I think you're right, and quite sorry to have seemingly wasted your time. So an empty string is interpretted as setting that field to null it seems. Is that a common pattern in the Stripe API for setting string fields to null?
I have a bunch of places in my code where I update addresses and it sounds like I need to do that same pattern everywhere for addresses for sure.
Does that apply to new entities as well, or just updates? Do I need separate handling for updating addresses from creating them?
Basically right now I've got code that's converting from my internal Address type to Stripe SDK types
def to_stripe_customer_create_params(self) -> CustomerService.CreateParamsAddress:
"""Converts this Address to a Stripe API entity"""
address = CustomerService.CreateParamsAddress(
city=self.city,
country=self.country_code,
line1=self.line1,
postal_code=self.postal_code,
state=self.region,
)
if self.line2 is not None:
address["line2"] = self.line2
return address
def to_stripe_customer_update_params(self) -> CustomerService.UpdateParamsAddress:
"""Converts this Address to a Stripe API entity"""
address = CustomerService.UpdateParamsAddress(
city=self.city,
country=self.country_code,
line1=self.line1,
postal_code=self.postal_code,
state=self.region,
)
if self.line2 is not None:
address["line2"] = self.line2
return address
For the update to support this my code becomes:
address = CustomerService.UpdateParamsAddress(
city=self.city,
country=self.country_code,
line1=self.line1,
line2=self.line2 or "",
postal_code=self.postal_code,
state=self.region,
)
Trying to figure out whether I can safely follow that same pattern for the create as well
I suppose I can answer that question my self with a little experimentation.
It might be worth calling this out explicitly in your documentation, I only see reference to unsetting with that pattern for metadata.
Ah, good point
It looks like that should work. Passing an empty string for line2 if the PM already has a null value for line2 will not return an error; line2 will just remain null
Ok, looks like I have a path forward, sorry for just being wrong on my initial work on this.
No worries! Happy to help and listen here, it's what this channel's for ๐
Ok, so, the update customers endpoint does not seem to function in that way req_psbb2pnugj5t03
REQUEST:
{
"address": {
"city": "Boulder",
"country": "US",
"line1": "4946 Clubhouse Cir.",
"line2": "",
"postal_code": "80301",
"state": "CO"
},
"email": "test@test.com",
"name": "test"
}
RESPONSE:
{
"id": "cus_RfjRQtAHaiUol8",
"object": "customer",
"address": {
"city": "Boulder",
"country": "US",
"line1": "4946 Clubhouse Cir.",
"line2": "",
"postal_code": "80301",
"state": "CO"
},
...
Setting a previously non-null line2 to "" there yields an empty string response rather than null for customer billing address