#snicserr-invoice
1 messages ยท Page 1 of 1 (latest)
We are trying to create an invoice but we are getting a Invalid Object
function create_invoice_charge(Customer $customer, int $amount, string $currency, string $landCode, string $metadata, string $city, string $address, string $postalCode, string $name, string $phoneNumber, Source $sourceObject): Invoice
{
if ($landCode == "US" || $landCode == "GB") {
$companyName = "Cancelled ";
$companyNameDescription = "Cancelled subscription ";
} else {
$companyName = "Opzeggen ";
$companyNameDescription = "Opgezegd bedrijf ";
}
$price = Price::create([
'unit_amount' => $amount * 100,
'currency' => $currency,
'product_data' => [
'name' => $companyName . $metadata,
'metadata' => [
$companyNameDescription => $metadata
],
],
]);
InvoiceItem::create([
'customer' => $customer->id,
'price' => $price->id,
]);
return Invoice::create([
'default_source' => $sourceObject->id,
'customer' => $customer->id,
'metadata' => [
$companyName . $metadata,
],
'description' => $companyName . $metadata,
'auto_advance'=> true
]);
}
Everytime in the StackTace we get line 175 and that line is:
'product_data' => [
'name' => $companyName . $metadata,
'metadata' => [
$companyNameDescription => $metadata
],
],
So something is not right
RG is also the developer on this problem ๐
thanks, looking..
We've got the same code in C#, which is working. So that'd imply that the properties are correct. But once we do it with the PHP code above, it won't create an invoice\
do you have a request ID req_xxx. for that 400 error? it should be in the stack trace somewhere if you look for req_
Sure, one moment
or if not it will be in your Stripe dashboard; https://support.stripe.com/questions/finding-the-id-for-an-api-request
yep
my guess is your $metadata variable is null
so when you do [$companyNameDescription => $metadata] it's actually [$companyNameDescription => null] and that decomposes to a string instead of an object, I think(need to check that)
It looks like it holds a string value, but it still breaks
Maybe something to do with the key pair format?
yeah sorry, it's not because it's null.
for what it's worth this works fine
$foo = "key";
$bar = "value";
$price = \Stripe\Price::create([
'unit_amount' => 500,
'currency' => "usd",
'product_data' => [
'name' => "example price",
'metadata' => [
$foo => $bar
],
],
]);
so either you're not running the code you think you are(for example maybe you actually do 'metadata' => $companyName which is a common mistake and would give this error), or there's something in your $metadata that breaks the formatting of the POST data)so you might need to escape it)
do you have the req_xxx ID so I can have a look?
req_rqU6yo0MyBpRFw
You might be right on that one. Interesting thing is, we're getting "MijnOpzeggingen Basic Fit" as the metadata, which can't be right. If you look at the php code above, the if statement doesn't have an option to land that string value. Only:
$companyName = "Opzeggen ";
$companyNameDescription = "Opgezegd bedrijf ";
In our case, it should be "Opzeggen"
yes it really looks to me like you do 'metadata' => $someString and not 'metadata' => [$key => $value]
Maybe a cashe or something in that direction... we used the value "MijnOpzeggingen" earlier today
I don't see anything unusual in the raw POST (unit_amount=1900¤cy=EUR&product_data[name]=MijnOpzeggingen++Basic+Fit&product_data[metadata]=MijnOpzeggingen++Basic+Fit) so yeah, I really think it has to be something like the code you're running is passing a string and not an object, I'd add some logging/breakpoints and see exactly what it's doing, I can't replicate this using the type of code posted above so it has to be that you're running something different
yeah, we'll a deeper look into the values we're passing into it. This does clear a lot of things up though
I think we found it
^
We might've found it yeah. We were running different code from what we thought we were running. I think we'll be able to fix it from here. Thank you for your support!
great!
Have nice day @graceful bison, good luck with supporting others ๐ค
