#nextplayerrr_python-sdk-service-pattern

1 messages ยท Page 1 of 1 (latest)

simple furnaceBOT
#

๐Ÿ‘‹ 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/1387390245170974792

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

spice gust
#
def generate_stripe_customer_id(first_name: str, last_name: str, email: str):
    client = StripeClient(api_key=key)
    stripe_customer = client.customers.create(
        name=first_name + " " + last_name,
        email=email,
    )
    stripe_customer_id = stripe_customer.id
    return stripe_customer_id
little hazel
#

hi there!

spice gust
#
  File "/Users/andremaytorena/Desktop/order-fulfillment-dashboard/backend/test.py", line 15, in <module>
    print(generate_stripe_customer_id("Julian", "Senti", "juliansenti98@gmail.com"))
  File "/Users/andremaytorena/Desktop/order-fulfillment-dashboard/backend/test.py", line 8, in generate_stripe_customer_id
    stripe_customer = client.customers.create(
TypeError: CustomerService.create() got an unexpected keyword argument 'name'```
#

Hey!

little hazel
spice gust
#

But it get the error I sent above

little hazel
#

the code you shared and the code I shared are quite different. the API key is directly set in teh API call itself:

client.customers.list(
    options={
        "api_key": "sk_test_...",
    }
)
spice gust
#

Ohh let me try that

#
def generate_stripe_customer_id(first_name: str, last_name: str, email: str):
    client = StripeClient(api_key=key)
    stripe_customer = client.customers.create(
        name=first_name + " " + last_name,
        email=email,
        options={
            "api_key": "sk_test...",
        }
    )
    stripe_customer_id = stripe_customer.id
    return stripe_customer_id```

So like this?
little hazel
#

I think so yes

#

but you need to replace sk_test with your real key

spice gust
#

yeah I have my real key i just retyped it in chat

#
  File "/Users/andremaytorena/Desktop/order-fulfillment-dashboard/backend/test.py", line 18, in <module>
    print(generate_stripe_customer_id("Julian", "Senti", "juliansenti98@gmail.com"))
  File "/Users/andremaytorena/Desktop/order-fulfillment-dashboard/backend/test.py", line 8, in generate_stripe_customer_id
    stripe_customer = client.customers.create(
TypeError: CustomerService.create() got an unexpected keyword argument 'name'```

But I still get this error, I also upgraded the pip stripe version to the latest
little hazel
#

can you try something simpler, like just client.customers.list() to see if it works?

spice gust
#

Yes that is working fine

#

It lists all of my customers

little hazel
#

and client.customers.create() (with no parameters)

spice gust
#

Checking one sec

#

Ok that worked

#

So I assume I'll need to then update the client and set the name and email?

little hazel
#

and now if you try with a hardcoded name? client.customers.create(name="test")?

spice gust
#

Checking that now

#

Same error, unexpected param

little hazel
#

which version of stripe-python are you using?

spice gust
#
Name: stripe
Version: 12.2.0```
little hazel
#

that's the latest version. not sure why you get that error. thinking...

simple furnaceBOT
brazen stump
#

Hi ๐Ÿ‘‹

I'm stepping in as my colleague needs to go soon

#

Can you try make two changes to your customer creatiion code? Can you try the following

customer = stripe.Customer.create(name="Testy Testface")
#

Oh sorry, that is using the older, resource pattern. Since you are instantiating the StripeClient class you will want to pass all your parameters in a dictionary.

customer = client.customer.create({'name': 'Test'})
spice gust
#

I see Iโ€™ll try that now

#

Ok perfect that worked, I assume all endpoints then follow the same structure using this new system?

brazen stump
#

We document the new shape of requests using this approach here

#

Slightly different. For requests that expect an ID as the first parameter, that is still separate.

#

For example

customer = client.customers.update(
  "cus_123",
  params={
    "description": "new description",
  }
)
spice gust
#

Ok I see, i'll begin changing the rest of my stripe endpoints and test for bugs

brazen stump
#

It can get a little confusing if you've used the older pattern for a long time (it trips me up often ๐Ÿ˜… )