#bobclewell_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/1278440049607708714
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
Hello
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?
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
But I'm using your PHP API code.
I'd recommend finding the request ID within Stripe that is failing (https://support.stripe.com/questions/finding-the-id-for-an-api-request) and then we can look at that specific error
Did you read my full question?
Can you share the full stack trace of the error?
This code works in production. But it's like $customer->sources->create() is not valid in testing.
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()
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
So what is that $customer variable?
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.
No sorry that's not how the SDK nor our API works.
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.
Then for your next step I'd recommend logging out your $customer variable
It needs to be a Stripe instance
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.
If you are trying to create a Source here
ok. That make sense.
If it is a Customer instance then it will not work to try to use it to create a Source
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.
Next step is the same... log out that variable in your test environment
Yeah. That's fair. I'll do that now.
Are you there?
I've got a big Customer object for you.
Let me know when you are ready.
Sure I'm here
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
Can you show me your code for how that $customer gets initialized?
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.
What does your full code snippet look like?
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;
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;
}
ok. Thanks.
You are positive in your production code that it isn't $customer -> sources -> update()?
Unless I'm missing something that vastly changed in our SDK from long ago you would not be creating a Source here... would you would be doing is updating the Customer to set their source property and passing the Card Token like you are doing: https://docs.stripe.com/api/customers/update#update_customer-source
yep. Just searched my code base.
I mean, this is old code. From 2017, but it's always worked.
No sources -> update() it's sources -> create(). Since 2017.
Alright give me a min
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.
K
It is due to API Version
So starting in 2020-08-27 sources no longer is includable on the Customer object: https://docs.stripe.com/upgrades#2020-08-27
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
Or you can use versioning (https://docs.stripe.com/api/versioning) to use an older API version
(You likely just want to match the API Version of your prod account)
How do I find out what API version I'm using in prod?
You can look in your Dashboard at https://dashboard.stripe.com/workbench/overview
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?
Yep
Well you can't set the default to that version on your new account
If you want that you'd need to write into our Support team via https://support.stripe.com/contact/login and ask them to update the default version on your account
You can only set your default to the newest version from your Dashboard
You can't set it to an older version yourself
Gotcha.
But you can version your requests using the SDK
Sure, sorry for the confusion
I've been losing sleep over this for days.
Glad to have someone that finally took the time to dig into it for me.
Happy to help
Should this request be easy for the Support team? If I ask them straight up to make the change... or do they need context?
Hold on one sec
Okay actually I was able to do it for you
Try again now and let me know if it fixes things
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!!
๐
๐
Glad we got it fixed up