#bobclewell_api

1 messages ยท Page 1 of 1 (latest)

cedar sirenBOT
#

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

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

wise palm
#

Hello

quartz dawn
#

Here's the full question again, without the limitations placed on my by StripeBot...

#

I'm getting an error when trying to add a testing card using our new account (CC Distribution - Acct ID: acct_1PfmFLHFGI0hzOXM) when that account is in test mode and I'm using the Test Mode API Keys.

Through our criterion.com checkout interface I go through our normal "Add a Credit Card" modal form. When I do this, the criterion.com user gets added to our new account in Test Mode as a customer, and I can see that customer in the Stripe admin, but a failure occurs when adding the testing card to that new customer. Therefore, the credit card info never appears in our database, and the new Stripe customer in the Stripe admin doesn't have a credit card. Which, in turn, means I can't complete the checkout process.

I think I've isolated it to an API call. The 500 error I see in my server response is "Call to a member function create() on null." The related code in our application is:

$customer->sources->create()

..where $customer is an instance of the Stripe customer.

I'm using version v8.12.0 Stripe PHP API library (from July 2022), which is the same code that we are running without errors in production.

Is it not possible to add cards, via this API, in test mode, even though creating the customer worked? Or, is there a setting on our account that is not allowing this? Or, is there some other problem I could be missing?

wise palm
#

Are you seeing an error in your Stripe logs?

#

The 500 error you mentioned is your own error from your server

#

So that doesn't really help

quartz dawn
#

But I'm using your PHP API code.

wise palm
quartz dawn
#

Did you read my full question?

wise palm
#

Can you share the full stack trace of the error?

quartz dawn
#

This code works in production. But it's like $customer->sources->create() is not valid in testing.

wise palm
#

Yeah but that isn't our code. Like our SDK doesn't do $customer -> sources -> create()

#

Our PHP library would do something like $stripe -> sources -> create()

#

So what is that $customer variable?

quartz dawn
#

an instance of the stripe customer.

#

Which DOES get created in our Stripe Customer table, on our Stripe acct in testing mode.

#

So the code works to create the customer, but then fails to create the payment source (card)... but on production this works fine.

wise palm
#

No sorry that's not how the SDK nor our API works.

quartz dawn
#

So, I'm telling you this code works fine in production, but I'm trying to test it with a new Stripe Account, and its failing.

wise palm
#

Then for your next step I'd recommend logging out your $customer variable

#

It needs to be a Stripe instance

quartz dawn
#

It seems to me that it would be an issue with the new Account. Or our old account works in ways that the new Account doesn't.

wise palm
#

If you are trying to create a Source here

quartz dawn
#

ok. That make sense.

wise palm
#

If it is a Customer instance then it will not work to try to use it to create a Source

quartz dawn
#

But the fix to this should not be a code update on my end.

#

Because it works in production.

#

The only variation is the new Stripe account.

wise palm
#

Next step is the same... log out that variable in your test environment

quartz dawn
#

Yeah. That's fair. I'll do that now.

quartz dawn
#

Are you there?

#

I've got a big Customer object for you.

#

Let me know when you are ready.

wise palm
#

Sure I'm here

quartz dawn
#

looks like it got cutoff at around 200 lines, but I have the full object if you need it.

#

that's what I'm calling sources->create() on

wise palm
#

Can you show me your code for how that $customer gets initialized?

quartz dawn
#

and that customer get created with this code...

            $customer = \Stripe\Customer::create([
                'email' => $user->email,
            ]);
#

which I know works, and interacts with our Stripe testing account, because I see the email address there, in Test Mode.

wise palm
#

What does your full code snippet look like?

quartz dawn
#
    protected function userToCustomer(User $user): Customer
    {
        if (! $user->stripe_customer_id) {
            $customer = Customer::create([
                'email' => $user->email,
            ]);

            $user->stripe_customer_id = $customer->id;
            $user->save();
        } else {
            $customer = Customer::retrieve($user->stripe_customer_id);
        }

        return $customer;
    }
#

and I'm including the Stripe library in the file...

use Stripe\Customer;

wise palm
#

Okay and the next part?

#

Where you call sources -> create()?

quartz dawn
#
    public function getCreditCard(Request $request, User $user): CreditCard
    {
         ...
         $card = $this->addCardToCustomer($customer, $data['stripetoken']);
         ...
    }



    protected function addCardToCustomer(Customer $customer, string $ccToken): Card
    {
        // dd($customer);  // my debug data dump is here
        $card = $customer->sources->create([
            'card' => $ccToken,
        ]);

        return $card;
    }
wise palm
#

Yep

#

One sec, checking on something

quartz dawn
#

ok. Thanks.

wise palm
#

You are positive in your production code that it isn't $customer -> sources -> update()?

quartz dawn
#

yep. Just searched my code base.

cedar sirenBOT
quartz dawn
#

I mean, this is old code. From 2017, but it's always worked.

#

No sources -> update() it's sources -> create(). Since 2017.

wise palm
#

Alright give me a min

quartz dawn
#

and like I said, it's working fine in prod.

#

My suspicion is that recently there's been a change, where $customer -> sources -> create() doesn't work any more in Test Mode.

#

Or, there's some setting in our new account that doesn't allow that, and it needs to be changed.

wise palm
#

K

#

It is due to API Version

#

So that is why you are seeing that error -- it isn't returned in your Customer instance

#

You either need to expand sources when you retrieve the Customer

#

(You likely just want to match the API Version of your prod account)

quartz dawn
#

How do I find out what API version I'm using in prod?

wise palm
quartz dawn
#

Yep. I see we are still using the 2019-05-16 version on the old account, which is prod.

#

So if I set my new account to that version, I should be good, right?

wise palm
#

Yep

#

Well you can't set the default to that version on your new account

#

You can only set your default to the newest version from your Dashboard

#

You can't set it to an older version yourself

quartz dawn
#

Gotcha.

wise palm
#

But you can version your requests using the SDK

quartz dawn
#

I'll reach out to get the default changed.

#

Thanks a ton!!!!

wise palm
#

Sure, sorry for the confusion

quartz dawn
#

I've been losing sleep over this for days.

#

Glad to have someone that finally took the time to dig into it for me.

wise palm
#

Happy to help

quartz dawn
#

Should this request be easy for the Support team? If I ask them straight up to make the change... or do they need context?

wise palm
#

Hold on one sec

quartz dawn
#

ok

#

I want to keep my message short and sweet, if possible. ๐Ÿ™‚

wise palm
#

Okay actually I was able to do it for you

#

Try again now and let me know if it fixes things

quartz dawn
#

oh, cool.

#

one sec.

#

I see it in my Dev dashboard area... nice, nice... OK, let me test.

#

oh. Actually, I need to revert my debug code.

#

YES!!

#

๐Ÿ™ Thanks again!!

wise palm
#

๐ŸŽ‰

quartz dawn
#

๐Ÿ˜†

wise palm
#

Glad we got it fixed up

quartz dawn
#

one more quick thing.

#

Do you know if there's an easy way to output a Discord thread?

wise palm
#

Not aware of one, no.

#

Think just copying the URL to refer back to

quartz dawn
#

Oh, yeah. I see that.

#

This won't disappear?

wise palm
#

No it won't

#

The thread will close

#

But you can still refer to it

quartz dawn
#

Awesome. Thanks again!

#

Now I need to go celebrate!